]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.14.4-201405252047.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.14.4-201405252047.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b89a739..e289b9b 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,14 +51,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 @@ -69,9 +75,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 @@ -80,6 +88,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 @@ -92,32 +101,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 @@ -125,12 +142,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 @@ -145,14 +165,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 @@ -162,14 +182,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 @@ -185,6 +206,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 @@ -194,6 +217,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -203,7 +227,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 @@ -213,8 +242,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 @@ -224,6 +257,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 @@ -235,13 +269,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 @@ -249,9 +287,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 7116fda..d8ed6e8 100644
239 --- a/Documentation/kernel-parameters.txt
240 +++ b/Documentation/kernel-parameters.txt
241 @@ -1084,6 +1084,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 @@ -2080,6 +2084,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 @@ -2347,6 +2355,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 d7c07fd..1ad8228 100644
291 --- a/Makefile
292 +++ b/Makefile
293 @@ -244,8 +244,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294
295 HOSTCC = gcc
296 HOSTCXX = g++
297 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
298 -HOSTCXXFLAGS = -O2
299 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
300 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
301 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
302
303 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305 @@ -423,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
306 # Rules shared between *config targets and build targets
307
308 # Basic helpers built in scripts/
309 -PHONY += scripts_basic
310 -scripts_basic:
311 +PHONY += scripts_basic gcc-plugins
312 +scripts_basic: gcc-plugins
313 $(Q)$(MAKE) $(build)=scripts/basic
314 $(Q)rm -f .tmp_quiet_recordmcount
315
316 @@ -585,6 +586,72 @@ else
317 KBUILD_CFLAGS += -O2
318 endif
319
320 +ifndef DISABLE_PAX_PLUGINS
321 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
322 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
323 +else
324 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
325 +endif
326 +ifneq ($(PLUGINCC),)
327 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
328 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
329 +endif
330 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
331 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
332 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
333 +endif
334 +ifdef CONFIG_KALLOCSTAT_PLUGIN
335 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
336 +endif
337 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
338 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
339 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
340 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
341 +endif
342 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
343 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
344 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
345 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
346 +endif
347 +endif
348 +ifdef CONFIG_CHECKER_PLUGIN
349 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
350 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
351 +endif
352 +endif
353 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
354 +ifdef CONFIG_PAX_SIZE_OVERFLOW
355 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
356 +endif
357 +ifdef CONFIG_PAX_LATENT_ENTROPY
358 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
359 +endif
360 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
361 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
362 +endif
363 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
364 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
365 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
366 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
367 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
368 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
369 +ifeq ($(KBUILD_EXTMOD),)
370 +gcc-plugins:
371 + $(Q)$(MAKE) $(build)=tools/gcc
372 +else
373 +gcc-plugins: ;
374 +endif
375 +else
376 +gcc-plugins:
377 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
378 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
379 +else
380 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
381 +endif
382 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
383 +endif
384 +endif
385 +
386 include $(srctree)/arch/$(SRCARCH)/Makefile
387
388 ifdef CONFIG_READABLE_ASM
389 @@ -779,7 +846,7 @@ export mod_sign_cmd
390
391
392 ifeq ($(KBUILD_EXTMOD),)
393 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
394 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
395
396 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
397 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
398 @@ -828,6 +895,8 @@ endif
399
400 # The actual objects are generated when descending,
401 # make sure no implicit rule kicks in
402 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
403 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
404 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
405
406 # Handle descending into subdirectories listed in $(vmlinux-dirs)
407 @@ -837,7 +906,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
408 # Error messages still appears in the original language
409
410 PHONY += $(vmlinux-dirs)
411 -$(vmlinux-dirs): prepare scripts
412 +$(vmlinux-dirs): gcc-plugins prepare scripts
413 $(Q)$(MAKE) $(build)=$@
414
415 define filechk_kernel.release
416 @@ -880,10 +949,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
417
418 archprepare: archheaders archscripts prepare1 scripts_basic
419
420 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 prepare0: archprepare FORCE
423 $(Q)$(MAKE) $(build)=.
424
425 # All the preparing..
426 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
427 prepare: prepare0
428
429 # Generate some files
430 @@ -991,6 +1063,8 @@ all: modules
431 # using awk while concatenating to the final file.
432
433 PHONY += modules
434 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
435 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
436 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
437 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
438 @$(kecho) ' Building modules, stage 2.';
439 @@ -1006,7 +1080,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
440
441 # Target to prepare building external modules
442 PHONY += modules_prepare
443 -modules_prepare: prepare scripts
444 +modules_prepare: gcc-plugins prepare scripts
445
446 # Target to install modules
447 PHONY += modules_install
448 @@ -1072,7 +1146,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
449 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
450 signing_key.priv signing_key.x509 x509.genkey \
451 extra_certificates signing_key.x509.keyid \
452 - signing_key.x509.signer
453 + signing_key.x509.signer \
454 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
455 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
456 + tools/gcc/randomize_layout_seed.h
457
458 # clean - Delete most, but leave enough to build external modules
459 #
460 @@ -1112,6 +1189,7 @@ distclean: mrproper
461 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
462 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
463 -o -name '.*.rej' \
464 + -o -name '.*.rej' -o -name '*.so' \
465 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
466 -type f -print | xargs rm -f
467
468 @@ -1273,6 +1351,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 @@ -1412,17 +1492,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 @@ -1432,11 +1516,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 44298ad..29a20c0 100644
855 --- a/arch/arm/Kconfig
856 +++ b/arch/arm/Kconfig
857 @@ -1862,7 +1862,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 @@ -2125,6 +2125,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 62d2cb5..09d45e3 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 @@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
952 smp_mb();
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 +
990 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
991 "1: ldrex %0, [%3]\n"
992 " add %0, %0, %4\n"
993 " strex %1, %0, [%3]\n"
994 @@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
995
996 prefetchw(&v->counter);
997 __asm__ __volatile__("@ atomic_sub\n"
998 +"1: ldrex %1, [%3]\n"
999 +" subs %0, %1, %4\n"
1000 +
1001 +#ifdef CONFIG_PAX_REFCOUNT
1002 +" bvc 3f\n"
1003 +"2: bkpt 0xf103\n"
1004 +"3:\n"
1005 +#endif
1006 +
1007 +" strex %1, %0, [%3]\n"
1008 +" teq %1, #0\n"
1009 +" bne 1b"
1010 +
1011 +#ifdef CONFIG_PAX_REFCOUNT
1012 +"\n4:\n"
1013 + _ASM_EXTABLE(2b, 4b)
1014 +#endif
1015 +
1016 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1017 + : "r" (&v->counter), "Ir" (i)
1018 + : "cc");
1019 +}
1020 +
1021 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1022 +{
1023 + unsigned long tmp;
1024 + int result;
1025 +
1026 + prefetchw(&v->counter);
1027 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1028 "1: ldrex %0, [%3]\n"
1029 " sub %0, %0, %4\n"
1030 " strex %1, %0, [%3]\n"
1031 @@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1032 smp_mb();
1033
1034 __asm__ __volatile__("@ atomic_sub_return\n"
1035 -"1: ldrex %0, [%3]\n"
1036 -" sub %0, %0, %4\n"
1037 +"1: ldrex %1, [%3]\n"
1038 +" subs %0, %1, %4\n"
1039 +
1040 +#ifdef CONFIG_PAX_REFCOUNT
1041 +" bvc 3f\n"
1042 +" mov %0, %1\n"
1043 +"2: bkpt 0xf103\n"
1044 +"3:\n"
1045 +#endif
1046 +
1047 " strex %1, %0, [%3]\n"
1048 " teq %1, #0\n"
1049 " bne 1b"
1050 +
1051 +#ifdef CONFIG_PAX_REFCOUNT
1052 +"\n4:\n"
1053 + _ASM_EXTABLE(2b, 4b)
1054 +#endif
1055 +
1056 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1057 : "r" (&v->counter), "Ir" (i)
1058 : "cc");
1059 @@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1060 return oldval;
1061 }
1062
1063 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1064 +{
1065 + unsigned long oldval, res;
1066 +
1067 + smp_mb();
1068 +
1069 + do {
1070 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1071 + "ldrex %1, [%3]\n"
1072 + "mov %0, #0\n"
1073 + "teq %1, %4\n"
1074 + "strexeq %0, %5, [%3]\n"
1075 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1076 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1077 + : "cc");
1078 + } while (res);
1079 +
1080 + smp_mb();
1081 +
1082 + return oldval;
1083 +}
1084 +
1085 #else /* ARM_ARCH_6 */
1086
1087 #ifdef CONFIG_SMP
1088 @@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1089
1090 return val;
1091 }
1092 +
1093 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1094 +{
1095 + return atomic_add_return(i, v);
1096 +}
1097 +
1098 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1099 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1100 +{
1101 + (void) atomic_add_return(i, v);
1102 +}
1103
1104 static inline int atomic_sub_return(int i, atomic_t *v)
1105 {
1106 @@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1107 return val;
1108 }
1109 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1110 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1111 +{
1112 + (void) atomic_sub_return(i, v);
1113 +}
1114
1115 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1116 {
1117 @@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1118 return ret;
1119 }
1120
1121 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1122 +{
1123 + return atomic_cmpxchg(v, old, new);
1124 +}
1125 +
1126 #endif /* __LINUX_ARM_ARCH__ */
1127
1128 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1129 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1130 +{
1131 + return xchg(&v->counter, new);
1132 +}
1133
1134 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1135 {
1136 @@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1137 }
1138
1139 #define atomic_inc(v) atomic_add(1, v)
1140 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1141 +{
1142 + atomic_add_unchecked(1, v);
1143 +}
1144 #define atomic_dec(v) atomic_sub(1, v)
1145 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1146 +{
1147 + atomic_sub_unchecked(1, v);
1148 +}
1149
1150 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1151 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1152 +{
1153 + return atomic_add_return_unchecked(1, v) == 0;
1154 +}
1155 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1156 #define atomic_inc_return(v) (atomic_add_return(1, v))
1157 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1158 +{
1159 + return atomic_add_return_unchecked(1, v);
1160 +}
1161 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1162 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1163
1164 @@ -221,6 +410,14 @@ typedef struct {
1165 long long counter;
1166 } atomic64_t;
1167
1168 +#ifdef CONFIG_PAX_REFCOUNT
1169 +typedef struct {
1170 + long long counter;
1171 +} atomic64_unchecked_t;
1172 +#else
1173 +typedef atomic64_t atomic64_unchecked_t;
1174 +#endif
1175 +
1176 #define ATOMIC64_INIT(i) { (i) }
1177
1178 #ifdef CONFIG_ARM_LPAE
1179 @@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1180 return result;
1181 }
1182
1183 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1184 +{
1185 + long long result;
1186 +
1187 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1188 +" ldrd %0, %H0, [%1]"
1189 + : "=&r" (result)
1190 + : "r" (&v->counter), "Qo" (v->counter)
1191 + );
1192 +
1193 + return result;
1194 +}
1195 +
1196 static inline void atomic64_set(atomic64_t *v, long long i)
1197 {
1198 __asm__ __volatile__("@ atomic64_set\n"
1199 @@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1200 : "r" (&v->counter), "r" (i)
1201 );
1202 }
1203 +
1204 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1205 +{
1206 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1207 +" strd %2, %H2, [%1]"
1208 + : "=Qo" (v->counter)
1209 + : "r" (&v->counter), "r" (i)
1210 + );
1211 +}
1212 #else
1213 static inline long long atomic64_read(const atomic64_t *v)
1214 {
1215 @@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1216 return result;
1217 }
1218
1219 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1220 +{
1221 + long long result;
1222 +
1223 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1224 +" ldrexd %0, %H0, [%1]"
1225 + : "=&r" (result)
1226 + : "r" (&v->counter), "Qo" (v->counter)
1227 + );
1228 +
1229 + return result;
1230 +}
1231 +
1232 static inline void atomic64_set(atomic64_t *v, long long i)
1233 {
1234 long long tmp;
1235 @@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1236 : "r" (&v->counter), "r" (i)
1237 : "cc");
1238 }
1239 +
1240 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1241 +{
1242 + long long tmp;
1243 +
1244 + prefetchw(&v->counter);
1245 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1246 +"1: ldrexd %0, %H0, [%2]\n"
1247 +" strexd %0, %3, %H3, [%2]\n"
1248 +" teq %0, #0\n"
1249 +" bne 1b"
1250 + : "=&r" (tmp), "=Qo" (v->counter)
1251 + : "r" (&v->counter), "r" (i)
1252 + : "cc");
1253 +}
1254 #endif
1255
1256 static inline void atomic64_add(long long i, atomic64_t *v)
1257 @@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1258 __asm__ __volatile__("@ atomic64_add\n"
1259 "1: ldrexd %0, %H0, [%3]\n"
1260 " adds %Q0, %Q0, %Q4\n"
1261 +" adcs %R0, %R0, %R4\n"
1262 +
1263 +#ifdef CONFIG_PAX_REFCOUNT
1264 +" bvc 3f\n"
1265 +"2: bkpt 0xf103\n"
1266 +"3:\n"
1267 +#endif
1268 +
1269 +" strexd %1, %0, %H0, [%3]\n"
1270 +" teq %1, #0\n"
1271 +" bne 1b"
1272 +
1273 +#ifdef CONFIG_PAX_REFCOUNT
1274 +"\n4:\n"
1275 + _ASM_EXTABLE(2b, 4b)
1276 +#endif
1277 +
1278 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1279 + : "r" (&v->counter), "r" (i)
1280 + : "cc");
1281 +}
1282 +
1283 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1284 +{
1285 + long long result;
1286 + unsigned long tmp;
1287 +
1288 + prefetchw(&v->counter);
1289 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1290 +"1: ldrexd %0, %H0, [%3]\n"
1291 +" adds %Q0, %Q0, %Q4\n"
1292 " adc %R0, %R0, %R4\n"
1293 " strexd %1, %0, %H0, [%3]\n"
1294 " teq %1, #0\n"
1295 @@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1296 __asm__ __volatile__("@ atomic64_add_return\n"
1297 "1: ldrexd %0, %H0, [%3]\n"
1298 " adds %Q0, %Q0, %Q4\n"
1299 +" adcs %R0, %R0, %R4\n"
1300 +
1301 +#ifdef CONFIG_PAX_REFCOUNT
1302 +" bvc 3f\n"
1303 +" mov %0, %1\n"
1304 +" mov %H0, %H1\n"
1305 +"2: bkpt 0xf103\n"
1306 +"3:\n"
1307 +#endif
1308 +
1309 +" strexd %1, %0, %H0, [%3]\n"
1310 +" teq %1, #0\n"
1311 +" bne 1b"
1312 +
1313 +#ifdef CONFIG_PAX_REFCOUNT
1314 +"\n4:\n"
1315 + _ASM_EXTABLE(2b, 4b)
1316 +#endif
1317 +
1318 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1319 + : "r" (&v->counter), "r" (i)
1320 + : "cc");
1321 +
1322 + smp_mb();
1323 +
1324 + return result;
1325 +}
1326 +
1327 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1328 +{
1329 + long long result;
1330 + unsigned long tmp;
1331 +
1332 + smp_mb();
1333 +
1334 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1335 +"1: ldrexd %0, %H0, [%3]\n"
1336 +" adds %Q0, %Q0, %Q4\n"
1337 " adc %R0, %R0, %R4\n"
1338 " strexd %1, %0, %H0, [%3]\n"
1339 " teq %1, #0\n"
1340 @@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1341 __asm__ __volatile__("@ atomic64_sub\n"
1342 "1: ldrexd %0, %H0, [%3]\n"
1343 " subs %Q0, %Q0, %Q4\n"
1344 +" sbcs %R0, %R0, %R4\n"
1345 +
1346 +#ifdef CONFIG_PAX_REFCOUNT
1347 +" bvc 3f\n"
1348 +"2: bkpt 0xf103\n"
1349 +"3:\n"
1350 +#endif
1351 +
1352 +" strexd %1, %0, %H0, [%3]\n"
1353 +" teq %1, #0\n"
1354 +" bne 1b"
1355 +
1356 +#ifdef CONFIG_PAX_REFCOUNT
1357 +"\n4:\n"
1358 + _ASM_EXTABLE(2b, 4b)
1359 +#endif
1360 +
1361 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1362 + : "r" (&v->counter), "r" (i)
1363 + : "cc");
1364 +}
1365 +
1366 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1367 +{
1368 + long long result;
1369 + unsigned long tmp;
1370 +
1371 + prefetchw(&v->counter);
1372 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1373 +"1: ldrexd %0, %H0, [%3]\n"
1374 +" subs %Q0, %Q0, %Q4\n"
1375 " sbc %R0, %R0, %R4\n"
1376 " strexd %1, %0, %H0, [%3]\n"
1377 " teq %1, #0\n"
1378 @@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1379 __asm__ __volatile__("@ atomic64_sub_return\n"
1380 "1: ldrexd %0, %H0, [%3]\n"
1381 " subs %Q0, %Q0, %Q4\n"
1382 -" sbc %R0, %R0, %R4\n"
1383 +" sbcs %R0, %R0, %R4\n"
1384 +
1385 +#ifdef CONFIG_PAX_REFCOUNT
1386 +" bvc 3f\n"
1387 +" mov %0, %1\n"
1388 +" mov %H0, %H1\n"
1389 +"2: bkpt 0xf103\n"
1390 +"3:\n"
1391 +#endif
1392 +
1393 " strexd %1, %0, %H0, [%3]\n"
1394 " teq %1, #0\n"
1395 " bne 1b"
1396 +
1397 +#ifdef CONFIG_PAX_REFCOUNT
1398 +"\n4:\n"
1399 + _ASM_EXTABLE(2b, 4b)
1400 +#endif
1401 +
1402 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1403 : "r" (&v->counter), "r" (i)
1404 : "cc");
1405
1406 - smp_mb();
1407 -
1408 return result;
1409 }
1410
1411 @@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1412 return oldval;
1413 }
1414
1415 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1416 + long long new)
1417 +{
1418 + long long oldval;
1419 + unsigned long res;
1420 +
1421 + smp_mb();
1422 +
1423 + do {
1424 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1425 + "ldrexd %1, %H1, [%3]\n"
1426 + "mov %0, #0\n"
1427 + "teq %1, %4\n"
1428 + "teqeq %H1, %H4\n"
1429 + "strexdeq %0, %5, %H5, [%3]"
1430 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1431 + : "r" (&ptr->counter), "r" (old), "r" (new)
1432 + : "cc");
1433 + } while (res);
1434 +
1435 + smp_mb();
1436 +
1437 + return oldval;
1438 +}
1439 +
1440 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1441 {
1442 long long result;
1443 @@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1444 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1445 {
1446 long long result;
1447 - unsigned long tmp;
1448 + u64 tmp;
1449
1450 smp_mb();
1451
1452 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1453 -"1: ldrexd %0, %H0, [%3]\n"
1454 -" subs %Q0, %Q0, #1\n"
1455 -" sbc %R0, %R0, #0\n"
1456 +"1: ldrexd %1, %H1, [%3]\n"
1457 +" subs %Q0, %Q1, #1\n"
1458 +" sbcs %R0, %R1, #0\n"
1459 +
1460 +#ifdef CONFIG_PAX_REFCOUNT
1461 +" bvc 3f\n"
1462 +" mov %Q0, %Q1\n"
1463 +" mov %R0, %R1\n"
1464 +"2: bkpt 0xf103\n"
1465 +"3:\n"
1466 +#endif
1467 +
1468 " teq %R0, #0\n"
1469 -" bmi 2f\n"
1470 +" bmi 4f\n"
1471 " strexd %1, %0, %H0, [%3]\n"
1472 " teq %1, #0\n"
1473 " bne 1b\n"
1474 -"2:"
1475 +"4:\n"
1476 +
1477 +#ifdef CONFIG_PAX_REFCOUNT
1478 + _ASM_EXTABLE(2b, 4b)
1479 +#endif
1480 +
1481 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1482 : "r" (&v->counter)
1483 : "cc");
1484 @@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1485 " teq %0, %5\n"
1486 " teqeq %H0, %H5\n"
1487 " moveq %1, #0\n"
1488 -" beq 2f\n"
1489 +" beq 4f\n"
1490 " adds %Q0, %Q0, %Q6\n"
1491 -" adc %R0, %R0, %R6\n"
1492 +" adcs %R0, %R0, %R6\n"
1493 +
1494 +#ifdef CONFIG_PAX_REFCOUNT
1495 +" bvc 3f\n"
1496 +"2: bkpt 0xf103\n"
1497 +"3:\n"
1498 +#endif
1499 +
1500 " strexd %2, %0, %H0, [%4]\n"
1501 " teq %2, #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" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1511 : "r" (&v->counter), "r" (u), "r" (a)
1512 : "cc");
1513 @@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1514
1515 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1516 #define atomic64_inc(v) atomic64_add(1LL, (v))
1517 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1518 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1519 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1520 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1521 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1522 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1523 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1524 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1525 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1526 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1527 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1528 index 75fe66b..ba3dee4 100644
1529 --- a/arch/arm/include/asm/cache.h
1530 +++ b/arch/arm/include/asm/cache.h
1531 @@ -4,8 +4,10 @@
1532 #ifndef __ASMARM_CACHE_H
1533 #define __ASMARM_CACHE_H
1534
1535 +#include <linux/const.h>
1536 +
1537 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1538 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1539 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1540
1541 /*
1542 * Memory returned by kmalloc() may be used for DMA, so we must make
1543 @@ -24,5 +26,6 @@
1544 #endif
1545
1546 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1547 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1548
1549 #endif
1550 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1551 index 8b8b616..d973d24 100644
1552 --- a/arch/arm/include/asm/cacheflush.h
1553 +++ b/arch/arm/include/asm/cacheflush.h
1554 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1555 void (*dma_unmap_area)(const void *, size_t, int);
1556
1557 void (*dma_flush_range)(const void *, const void *);
1558 -};
1559 +} __no_const;
1560
1561 /*
1562 * Select the calling method
1563 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1564 index 5233151..87a71fa 100644
1565 --- a/arch/arm/include/asm/checksum.h
1566 +++ b/arch/arm/include/asm/checksum.h
1567 @@ -37,7 +37,19 @@ __wsum
1568 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1569
1570 __wsum
1571 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1572 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1573 +
1574 +static inline __wsum
1575 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1576 +{
1577 + __wsum ret;
1578 + pax_open_userland();
1579 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1580 + pax_close_userland();
1581 + return ret;
1582 +}
1583 +
1584 +
1585
1586 /*
1587 * Fold a partial checksum without adding pseudo headers
1588 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1589 index df2fbba..63fe3e1 100644
1590 --- a/arch/arm/include/asm/cmpxchg.h
1591 +++ b/arch/arm/include/asm/cmpxchg.h
1592 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1593
1594 #define xchg(ptr,x) \
1595 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1596 +#define xchg_unchecked(ptr,x) \
1597 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1598
1599 #include <asm-generic/cmpxchg-local.h>
1600
1601 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1602 index 6ddbe44..b5e38b1 100644
1603 --- a/arch/arm/include/asm/domain.h
1604 +++ b/arch/arm/include/asm/domain.h
1605 @@ -48,18 +48,37 @@
1606 * Domain types
1607 */
1608 #define DOMAIN_NOACCESS 0
1609 -#define DOMAIN_CLIENT 1
1610 #ifdef CONFIG_CPU_USE_DOMAINS
1611 +#define DOMAIN_USERCLIENT 1
1612 +#define DOMAIN_KERNELCLIENT 1
1613 #define DOMAIN_MANAGER 3
1614 +#define DOMAIN_VECTORS DOMAIN_USER
1615 #else
1616 +
1617 +#ifdef CONFIG_PAX_KERNEXEC
1618 #define DOMAIN_MANAGER 1
1619 +#define DOMAIN_KERNEXEC 3
1620 +#else
1621 +#define DOMAIN_MANAGER 1
1622 +#endif
1623 +
1624 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1625 +#define DOMAIN_USERCLIENT 0
1626 +#define DOMAIN_UDEREF 1
1627 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1628 +#else
1629 +#define DOMAIN_USERCLIENT 1
1630 +#define DOMAIN_VECTORS DOMAIN_USER
1631 +#endif
1632 +#define DOMAIN_KERNELCLIENT 1
1633 +
1634 #endif
1635
1636 #define domain_val(dom,type) ((type) << (2*(dom)))
1637
1638 #ifndef __ASSEMBLY__
1639
1640 -#ifdef CONFIG_CPU_USE_DOMAINS
1641 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1642 static inline void set_domain(unsigned val)
1643 {
1644 asm volatile(
1645 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1646 isb();
1647 }
1648
1649 -#define modify_domain(dom,type) \
1650 - do { \
1651 - struct thread_info *thread = current_thread_info(); \
1652 - unsigned int domain = thread->cpu_domain; \
1653 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1654 - thread->cpu_domain = domain | domain_val(dom, type); \
1655 - set_domain(thread->cpu_domain); \
1656 - } while (0)
1657 -
1658 +extern void modify_domain(unsigned int dom, unsigned int type);
1659 #else
1660 static inline void set_domain(unsigned val) { }
1661 static inline void modify_domain(unsigned dom, unsigned type) { }
1662 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1663 index f4b46d3..abc9b2b 100644
1664 --- a/arch/arm/include/asm/elf.h
1665 +++ b/arch/arm/include/asm/elf.h
1666 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1667 the loader. We need to make sure that it is out of the way of the program
1668 that it will "exec", and that there is sufficient room for the brk. */
1669
1670 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1671 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1672 +
1673 +#ifdef CONFIG_PAX_ASLR
1674 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1675 +
1676 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1677 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1678 +#endif
1679
1680 /* When the program starts, a1 contains a pointer to a function to be
1681 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1682 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1683 extern void elf_set_personality(const struct elf32_hdr *);
1684 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1685
1686 -struct mm_struct;
1687 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1688 -#define arch_randomize_brk arch_randomize_brk
1689 -
1690 #ifdef CONFIG_MMU
1691 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1692 struct linux_binprm;
1693 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1694 index de53547..52b9a28 100644
1695 --- a/arch/arm/include/asm/fncpy.h
1696 +++ b/arch/arm/include/asm/fncpy.h
1697 @@ -81,7 +81,9 @@
1698 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1699 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1700 \
1701 + pax_open_kernel(); \
1702 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1703 + pax_close_kernel(); \
1704 flush_icache_range((unsigned long)(dest_buf), \
1705 (unsigned long)(dest_buf) + (size)); \
1706 \
1707 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1708 index 2aff798..099eb15 100644
1709 --- a/arch/arm/include/asm/futex.h
1710 +++ b/arch/arm/include/asm/futex.h
1711 @@ -45,6 +45,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1712 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1713 return -EFAULT;
1714
1715 + pax_open_userland();
1716 +
1717 smp_mb();
1718 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1719 "1: ldrex %1, [%4]\n"
1720 @@ -60,6 +62,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1721 : "cc", "memory");
1722 smp_mb();
1723
1724 + pax_close_userland();
1725 +
1726 *uval = val;
1727 return ret;
1728 }
1729 @@ -90,6 +94,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1730 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1731 return -EFAULT;
1732
1733 + pax_open_userland();
1734 +
1735 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1736 "1: " TUSER(ldr) " %1, [%4]\n"
1737 " teq %1, %2\n"
1738 @@ -100,6 +106,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1739 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1740 : "cc", "memory");
1741
1742 + pax_close_userland();
1743 +
1744 *uval = val;
1745 return ret;
1746 }
1747 @@ -122,6 +130,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1748 return -EFAULT;
1749
1750 pagefault_disable(); /* implies preempt_disable() */
1751 + pax_open_userland();
1752
1753 switch (op) {
1754 case FUTEX_OP_SET:
1755 @@ -143,6 +152,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1756 ret = -ENOSYS;
1757 }
1758
1759 + pax_close_userland();
1760 pagefault_enable(); /* subsumes preempt_enable() */
1761
1762 if (!ret) {
1763 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1764 index 83eb2f7..ed77159 100644
1765 --- a/arch/arm/include/asm/kmap_types.h
1766 +++ b/arch/arm/include/asm/kmap_types.h
1767 @@ -4,6 +4,6 @@
1768 /*
1769 * This is the "bare minimum". AIO seems to require this.
1770 */
1771 -#define KM_TYPE_NR 16
1772 +#define KM_TYPE_NR 17
1773
1774 #endif
1775 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1776 index 9e614a1..3302cca 100644
1777 --- a/arch/arm/include/asm/mach/dma.h
1778 +++ b/arch/arm/include/asm/mach/dma.h
1779 @@ -22,7 +22,7 @@ struct dma_ops {
1780 int (*residue)(unsigned int, dma_t *); /* optional */
1781 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1782 const char *type;
1783 -};
1784 +} __do_const;
1785
1786 struct dma_struct {
1787 void *addr; /* single DMA address */
1788 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1789 index f98c7f3..e5c626d 100644
1790 --- a/arch/arm/include/asm/mach/map.h
1791 +++ b/arch/arm/include/asm/mach/map.h
1792 @@ -23,17 +23,19 @@ struct map_desc {
1793
1794 /* types 0-3 are defined in asm/io.h */
1795 enum {
1796 - MT_UNCACHED = 4,
1797 - MT_CACHECLEAN,
1798 - MT_MINICLEAN,
1799 + MT_UNCACHED_RW = 4,
1800 + MT_CACHECLEAN_RO,
1801 + MT_MINICLEAN_RO,
1802 MT_LOW_VECTORS,
1803 MT_HIGH_VECTORS,
1804 - MT_MEMORY_RWX,
1805 + __MT_MEMORY_RWX,
1806 MT_MEMORY_RW,
1807 - MT_ROM,
1808 - MT_MEMORY_RWX_NONCACHED,
1809 + MT_MEMORY_RX,
1810 + MT_ROM_RX,
1811 + MT_MEMORY_RW_NONCACHED,
1812 + MT_MEMORY_RX_NONCACHED,
1813 MT_MEMORY_RW_DTCM,
1814 - MT_MEMORY_RWX_ITCM,
1815 + MT_MEMORY_RX_ITCM,
1816 MT_MEMORY_RW_SO,
1817 MT_MEMORY_DMA_READY,
1818 };
1819 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1820 index f94784f..9a09a4a 100644
1821 --- a/arch/arm/include/asm/outercache.h
1822 +++ b/arch/arm/include/asm/outercache.h
1823 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1824 #endif
1825 void (*set_debug)(unsigned long);
1826 void (*resume)(void);
1827 -};
1828 +} __no_const;
1829
1830 extern struct outer_cache_fns outer_cache;
1831
1832 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1833 index 4355f0e..cd9168e 100644
1834 --- a/arch/arm/include/asm/page.h
1835 +++ b/arch/arm/include/asm/page.h
1836 @@ -23,6 +23,7 @@
1837
1838 #else
1839
1840 +#include <linux/compiler.h>
1841 #include <asm/glue.h>
1842
1843 /*
1844 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1845 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1846 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1847 unsigned long vaddr, struct vm_area_struct *vma);
1848 -};
1849 +} __no_const;
1850
1851 #ifdef MULTI_USER
1852 extern struct cpu_user_fns cpu_user;
1853 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1854 index 78a7793..e3dc06c 100644
1855 --- a/arch/arm/include/asm/pgalloc.h
1856 +++ b/arch/arm/include/asm/pgalloc.h
1857 @@ -17,6 +17,7 @@
1858 #include <asm/processor.h>
1859 #include <asm/cacheflush.h>
1860 #include <asm/tlbflush.h>
1861 +#include <asm/system_info.h>
1862
1863 #define check_pgt_cache() do { } while (0)
1864
1865 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1866 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1867 }
1868
1869 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1870 +{
1871 + pud_populate(mm, pud, pmd);
1872 +}
1873 +
1874 #else /* !CONFIG_ARM_LPAE */
1875
1876 /*
1877 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1878 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1879 #define pmd_free(mm, pmd) do { } while (0)
1880 #define pud_populate(mm,pmd,pte) BUG()
1881 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1882
1883 #endif /* CONFIG_ARM_LPAE */
1884
1885 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1886 __free_page(pte);
1887 }
1888
1889 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1890 +{
1891 +#ifdef CONFIG_ARM_LPAE
1892 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1893 +#else
1894 + if (addr & SECTION_SIZE)
1895 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1896 + else
1897 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1898 +#endif
1899 + flush_pmd_entry(pmdp);
1900 +}
1901 +
1902 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1903 pmdval_t prot)
1904 {
1905 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1906 static inline void
1907 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1908 {
1909 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1910 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1911 }
1912 #define pmd_pgtable(pmd) pmd_page(pmd)
1913
1914 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1915 index 5cfba15..f415e1a 100644
1916 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1917 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1918 @@ -20,12 +20,15 @@
1919 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1920 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1921 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1922 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1923 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1924 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1925 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1926 +
1927 /*
1928 * - section
1929 */
1930 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1931 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1932 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1933 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1934 @@ -37,6 +40,7 @@
1935 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1936 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1937 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1938 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1939
1940 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1941 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1942 @@ -66,6 +70,7 @@
1943 * - extended small page/tiny page
1944 */
1945 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1946 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1947 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1948 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1949 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1950 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1951 index 219ac88..73ec32a 100644
1952 --- a/arch/arm/include/asm/pgtable-2level.h
1953 +++ b/arch/arm/include/asm/pgtable-2level.h
1954 @@ -126,6 +126,9 @@
1955 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1956 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1957
1958 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1959 +#define L_PTE_PXN (_AT(pteval_t, 0))
1960 +
1961 /*
1962 * These are the memory types, defined to be compatible with
1963 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1964 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1965 index 626989f..9d67a33 100644
1966 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1967 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1968 @@ -75,6 +75,7 @@
1969 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1970 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1971 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1972 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1973 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1974
1975 /*
1976 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1977 index 85c60ad..b0bbd7e 100644
1978 --- a/arch/arm/include/asm/pgtable-3level.h
1979 +++ b/arch/arm/include/asm/pgtable-3level.h
1980 @@ -82,6 +82,7 @@
1981 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1982 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1983 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1984 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1985 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1986 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1987 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1988 @@ -95,6 +96,7 @@
1989 /*
1990 * To be used in assembly code with the upper page attributes.
1991 */
1992 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1993 #define L_PTE_XN_HIGH (1 << (54 - 32))
1994 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1995
1996 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1997 index 7d59b52..27a12f8 100644
1998 --- a/arch/arm/include/asm/pgtable.h
1999 +++ b/arch/arm/include/asm/pgtable.h
2000 @@ -33,6 +33,9 @@
2001 #include <asm/pgtable-2level.h>
2002 #endif
2003
2004 +#define ktla_ktva(addr) (addr)
2005 +#define ktva_ktla(addr) (addr)
2006 +
2007 /*
2008 * Just any arbitrary offset to the start of the vmalloc VM area: the
2009 * current 8MB value just means that there will be a 8MB "hole" after the
2010 @@ -48,6 +51,9 @@
2011 #define LIBRARY_TEXT_START 0x0c000000
2012
2013 #ifndef __ASSEMBLY__
2014 +extern pteval_t __supported_pte_mask;
2015 +extern pmdval_t __supported_pmd_mask;
2016 +
2017 extern void __pte_error(const char *file, int line, pte_t);
2018 extern void __pmd_error(const char *file, int line, pmd_t);
2019 extern void __pgd_error(const char *file, int line, pgd_t);
2020 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2021 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2022 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2023
2024 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2025 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2026 +
2027 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2028 +#include <asm/domain.h>
2029 +#include <linux/thread_info.h>
2030 +#include <linux/preempt.h>
2031 +
2032 +static inline int test_domain(int domain, int domaintype)
2033 +{
2034 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2035 +}
2036 +#endif
2037 +
2038 +#ifdef CONFIG_PAX_KERNEXEC
2039 +static inline unsigned long pax_open_kernel(void) {
2040 +#ifdef CONFIG_ARM_LPAE
2041 + /* TODO */
2042 +#else
2043 + preempt_disable();
2044 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2045 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2046 +#endif
2047 + return 0;
2048 +}
2049 +
2050 +static inline unsigned long pax_close_kernel(void) {
2051 +#ifdef CONFIG_ARM_LPAE
2052 + /* TODO */
2053 +#else
2054 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2055 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2056 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2057 + preempt_enable_no_resched();
2058 +#endif
2059 + return 0;
2060 +}
2061 +#else
2062 +static inline unsigned long pax_open_kernel(void) { return 0; }
2063 +static inline unsigned long pax_close_kernel(void) { return 0; }
2064 +#endif
2065 +
2066 /*
2067 * This is the lowest virtual address we can permit any user space
2068 * mapping to be mapped at. This is particularly important for
2069 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2070 /*
2071 * The pgprot_* and protection_map entries will be fixed up in runtime
2072 * to include the cachable and bufferable bits based on memory policy,
2073 - * as well as any architecture dependent bits like global/ASID and SMP
2074 - * shared mapping bits.
2075 + * as well as any architecture dependent bits like global/ASID, PXN,
2076 + * and SMP shared mapping bits.
2077 */
2078 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2079
2080 @@ -262,7 +310,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2081 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2082 {
2083 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2084 - L_PTE_NONE | L_PTE_VALID;
2085 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2086 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2087 return pte;
2088 }
2089 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2090 index c4ae171..ea0c0c2 100644
2091 --- a/arch/arm/include/asm/psci.h
2092 +++ b/arch/arm/include/asm/psci.h
2093 @@ -29,7 +29,7 @@ struct psci_operations {
2094 int (*cpu_off)(struct psci_power_state state);
2095 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2096 int (*migrate)(unsigned long cpuid);
2097 -};
2098 +} __no_const;
2099
2100 extern struct psci_operations psci_ops;
2101 extern struct smp_operations psci_smp_ops;
2102 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2103 index 22a3b9b..7f214ee 100644
2104 --- a/arch/arm/include/asm/smp.h
2105 +++ b/arch/arm/include/asm/smp.h
2106 @@ -112,7 +112,7 @@ struct smp_operations {
2107 int (*cpu_disable)(unsigned int cpu);
2108 #endif
2109 #endif
2110 -};
2111 +} __no_const;
2112
2113 /*
2114 * set platform specific SMP operations
2115 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2116 index 71a06b2..8bb9ae1 100644
2117 --- a/arch/arm/include/asm/thread_info.h
2118 +++ b/arch/arm/include/asm/thread_info.h
2119 @@ -88,9 +88,9 @@ struct thread_info {
2120 .flags = 0, \
2121 .preempt_count = INIT_PREEMPT_COUNT, \
2122 .addr_limit = KERNEL_DS, \
2123 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2124 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2125 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2126 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2127 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2128 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2129 .restart_block = { \
2130 .fn = do_no_restart_syscall, \
2131 }, \
2132 @@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2133 #define TIF_SYSCALL_AUDIT 9
2134 #define TIF_SYSCALL_TRACEPOINT 10
2135 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2136 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2137 +/* within 8 bits of TIF_SYSCALL_TRACE
2138 + * to meet flexible second operand requirements
2139 + */
2140 +#define TIF_GRSEC_SETXID 12
2141 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2142 #define TIF_USING_IWMMXT 17
2143 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2144 #define TIF_RESTORE_SIGMASK 20
2145 @@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2146 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2147 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2148 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2149 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2150
2151 /* Checks for any syscall work in entry-common.S */
2152 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2153 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2154 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2155
2156 /*
2157 * Change these and you break ASM code in entry-common.S
2158 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2159 index 72abdc5..35acac1 100644
2160 --- a/arch/arm/include/asm/uaccess.h
2161 +++ b/arch/arm/include/asm/uaccess.h
2162 @@ -18,6 +18,7 @@
2163 #include <asm/domain.h>
2164 #include <asm/unified.h>
2165 #include <asm/compiler.h>
2166 +#include <asm/pgtable.h>
2167
2168 #if __LINUX_ARM_ARCH__ < 6
2169 #include <asm-generic/uaccess-unaligned.h>
2170 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2171 static inline void set_fs(mm_segment_t fs)
2172 {
2173 current_thread_info()->addr_limit = fs;
2174 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2175 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2176 }
2177
2178 #define segment_eq(a,b) ((a) == (b))
2179
2180 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2181 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2182 +
2183 +static inline void pax_open_userland(void)
2184 +{
2185 +
2186 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2187 + if (segment_eq(get_fs(), USER_DS)) {
2188 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2189 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2190 + }
2191 +#endif
2192 +
2193 +}
2194 +
2195 +static inline void pax_close_userland(void)
2196 +{
2197 +
2198 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2199 + if (segment_eq(get_fs(), USER_DS)) {
2200 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2201 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2202 + }
2203 +#endif
2204 +
2205 +}
2206 +
2207 #define __addr_ok(addr) ({ \
2208 unsigned long flag; \
2209 __asm__("cmp %2, %0; movlo %0, #0" \
2210 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2211
2212 #define get_user(x,p) \
2213 ({ \
2214 + int __e; \
2215 might_fault(); \
2216 - __get_user_check(x,p); \
2217 + pax_open_userland(); \
2218 + __e = __get_user_check(x,p); \
2219 + pax_close_userland(); \
2220 + __e; \
2221 })
2222
2223 extern int __put_user_1(void *, unsigned int);
2224 @@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2225
2226 #define put_user(x,p) \
2227 ({ \
2228 + int __e; \
2229 might_fault(); \
2230 - __put_user_check(x,p); \
2231 + pax_open_userland(); \
2232 + __e = __put_user_check(x,p); \
2233 + pax_close_userland(); \
2234 + __e; \
2235 })
2236
2237 #else /* CONFIG_MMU */
2238 @@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2239
2240 #endif /* CONFIG_MMU */
2241
2242 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2243 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2244
2245 #define user_addr_max() \
2246 @@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2247 #define __get_user(x,ptr) \
2248 ({ \
2249 long __gu_err = 0; \
2250 + pax_open_userland(); \
2251 __get_user_err((x),(ptr),__gu_err); \
2252 + pax_close_userland(); \
2253 __gu_err; \
2254 })
2255
2256 #define __get_user_error(x,ptr,err) \
2257 ({ \
2258 + pax_open_userland(); \
2259 __get_user_err((x),(ptr),err); \
2260 + pax_close_userland(); \
2261 (void) 0; \
2262 })
2263
2264 @@ -319,13 +360,17 @@ do { \
2265 #define __put_user(x,ptr) \
2266 ({ \
2267 long __pu_err = 0; \
2268 + pax_open_userland(); \
2269 __put_user_err((x),(ptr),__pu_err); \
2270 + pax_close_userland(); \
2271 __pu_err; \
2272 })
2273
2274 #define __put_user_error(x,ptr,err) \
2275 ({ \
2276 + pax_open_userland(); \
2277 __put_user_err((x),(ptr),err); \
2278 + pax_close_userland(); \
2279 (void) 0; \
2280 })
2281
2282 @@ -425,11 +470,44 @@ do { \
2283
2284
2285 #ifdef CONFIG_MMU
2286 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2287 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2288 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2289 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2290 +
2291 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2292 +{
2293 + unsigned long ret;
2294 +
2295 + check_object_size(to, n, false);
2296 + pax_open_userland();
2297 + ret = ___copy_from_user(to, from, n);
2298 + pax_close_userland();
2299 + return ret;
2300 +}
2301 +
2302 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2303 +{
2304 + unsigned long ret;
2305 +
2306 + check_object_size(from, n, true);
2307 + pax_open_userland();
2308 + ret = ___copy_to_user(to, from, n);
2309 + pax_close_userland();
2310 + return ret;
2311 +}
2312 +
2313 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2314 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2315 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2316 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2317 +
2318 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2319 +{
2320 + unsigned long ret;
2321 + pax_open_userland();
2322 + ret = ___clear_user(addr, n);
2323 + pax_close_userland();
2324 + return ret;
2325 +}
2326 +
2327 #else
2328 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2329 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2330 @@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2331
2332 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2333 {
2334 + if ((long)n < 0)
2335 + return n;
2336 +
2337 if (access_ok(VERIFY_READ, from, n))
2338 n = __copy_from_user(to, from, n);
2339 else /* security hole - plug it */
2340 @@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2341
2342 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2343 {
2344 + if ((long)n < 0)
2345 + return n;
2346 +
2347 if (access_ok(VERIFY_WRITE, to, n))
2348 n = __copy_to_user(to, from, n);
2349 return n;
2350 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2351 index 5af0ed1..cea83883 100644
2352 --- a/arch/arm/include/uapi/asm/ptrace.h
2353 +++ b/arch/arm/include/uapi/asm/ptrace.h
2354 @@ -92,7 +92,7 @@
2355 * ARMv7 groups of PSR bits
2356 */
2357 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2358 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2359 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2360 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2361 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2362
2363 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2364 index 85e664b..419a1cd 100644
2365 --- a/arch/arm/kernel/armksyms.c
2366 +++ b/arch/arm/kernel/armksyms.c
2367 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2368
2369 /* networking */
2370 EXPORT_SYMBOL(csum_partial);
2371 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2372 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2373 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2374 EXPORT_SYMBOL(__csum_ipv6_magic);
2375
2376 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2377 #ifdef CONFIG_MMU
2378 EXPORT_SYMBOL(copy_page);
2379
2380 -EXPORT_SYMBOL(__copy_from_user);
2381 -EXPORT_SYMBOL(__copy_to_user);
2382 -EXPORT_SYMBOL(__clear_user);
2383 +EXPORT_SYMBOL(___copy_from_user);
2384 +EXPORT_SYMBOL(___copy_to_user);
2385 +EXPORT_SYMBOL(___clear_user);
2386
2387 EXPORT_SYMBOL(__get_user_1);
2388 EXPORT_SYMBOL(__get_user_2);
2389 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2390 index 1879e8d..b2207fc 100644
2391 --- a/arch/arm/kernel/entry-armv.S
2392 +++ b/arch/arm/kernel/entry-armv.S
2393 @@ -47,6 +47,87 @@
2394 9997:
2395 .endm
2396
2397 + .macro pax_enter_kernel
2398 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2399 + @ make aligned space for saved DACR
2400 + sub sp, sp, #8
2401 + @ save regs
2402 + stmdb sp!, {r1, r2}
2403 + @ read DACR from cpu_domain into r1
2404 + mov r2, sp
2405 + @ assume 8K pages, since we have to split the immediate in two
2406 + bic r2, r2, #(0x1fc0)
2407 + bic r2, r2, #(0x3f)
2408 + ldr r1, [r2, #TI_CPU_DOMAIN]
2409 + @ store old DACR on stack
2410 + str r1, [sp, #8]
2411 +#ifdef CONFIG_PAX_KERNEXEC
2412 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2413 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2414 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2415 +#endif
2416 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2417 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2418 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2419 +#endif
2420 + @ write r1 to current_thread_info()->cpu_domain
2421 + str r1, [r2, #TI_CPU_DOMAIN]
2422 + @ write r1 to DACR
2423 + mcr p15, 0, r1, c3, c0, 0
2424 + @ instruction sync
2425 + instr_sync
2426 + @ restore regs
2427 + ldmia sp!, {r1, r2}
2428 +#endif
2429 + .endm
2430 +
2431 + .macro pax_open_userland
2432 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2433 + @ save regs
2434 + stmdb sp!, {r0, r1}
2435 + @ read DACR from cpu_domain into r1
2436 + mov r0, sp
2437 + @ assume 8K pages, since we have to split the immediate in two
2438 + bic r0, r0, #(0x1fc0)
2439 + bic r0, r0, #(0x3f)
2440 + ldr r1, [r0, #TI_CPU_DOMAIN]
2441 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2442 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2443 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2444 + @ write r1 to current_thread_info()->cpu_domain
2445 + str r1, [r0, #TI_CPU_DOMAIN]
2446 + @ write r1 to DACR
2447 + mcr p15, 0, r1, c3, c0, 0
2448 + @ instruction sync
2449 + instr_sync
2450 + @ restore regs
2451 + ldmia sp!, {r0, r1}
2452 +#endif
2453 + .endm
2454 +
2455 + .macro pax_close_userland
2456 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2457 + @ save regs
2458 + stmdb sp!, {r0, r1}
2459 + @ read DACR from cpu_domain into r1
2460 + mov r0, sp
2461 + @ assume 8K pages, since we have to split the immediate in two
2462 + bic r0, r0, #(0x1fc0)
2463 + bic r0, r0, #(0x3f)
2464 + ldr r1, [r0, #TI_CPU_DOMAIN]
2465 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2466 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2467 + @ write r1 to current_thread_info()->cpu_domain
2468 + str r1, [r0, #TI_CPU_DOMAIN]
2469 + @ write r1 to DACR
2470 + mcr p15, 0, r1, c3, c0, 0
2471 + @ instruction sync
2472 + instr_sync
2473 + @ restore regs
2474 + ldmia sp!, {r0, r1}
2475 +#endif
2476 + .endm
2477 +
2478 .macro pabt_helper
2479 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2480 #ifdef MULTI_PABORT
2481 @@ -89,11 +170,15 @@
2482 * Invalid mode handlers
2483 */
2484 .macro inv_entry, reason
2485 +
2486 + pax_enter_kernel
2487 +
2488 sub sp, sp, #S_FRAME_SIZE
2489 ARM( stmib sp, {r1 - lr} )
2490 THUMB( stmia sp, {r0 - r12} )
2491 THUMB( str sp, [sp, #S_SP] )
2492 THUMB( str lr, [sp, #S_LR] )
2493 +
2494 mov r1, #\reason
2495 .endm
2496
2497 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2498 .macro svc_entry, stack_hole=0
2499 UNWIND(.fnstart )
2500 UNWIND(.save {r0 - pc} )
2501 +
2502 + pax_enter_kernel
2503 +
2504 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2505 +
2506 #ifdef CONFIG_THUMB2_KERNEL
2507 SPFIX( str r0, [sp] ) @ temporarily saved
2508 SPFIX( mov r0, sp )
2509 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2510 ldmia r0, {r3 - r5}
2511 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2512 mov r6, #-1 @ "" "" "" ""
2513 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2514 + @ offset sp by 8 as done in pax_enter_kernel
2515 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2516 +#else
2517 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2518 +#endif
2519 SPFIX( addeq r2, r2, #4 )
2520 str r3, [sp, #-4]! @ save the "real" r0 copied
2521 @ from the exception stack
2522 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2523 .macro usr_entry
2524 UNWIND(.fnstart )
2525 UNWIND(.cantunwind ) @ don't unwind the user space
2526 +
2527 + pax_enter_kernel_user
2528 +
2529 sub sp, sp, #S_FRAME_SIZE
2530 ARM( stmib sp, {r1 - r12} )
2531 THUMB( stmia sp, {r0 - r12} )
2532 @@ -416,7 +513,9 @@ __und_usr:
2533 tst r3, #PSR_T_BIT @ Thumb mode?
2534 bne __und_usr_thumb
2535 sub r4, r2, #4 @ ARM instr at LR - 4
2536 + pax_open_userland
2537 1: ldrt r0, [r4]
2538 + pax_close_userland
2539 ARM_BE8(rev r0, r0) @ little endian instruction
2540
2541 @ r0 = 32-bit ARM instruction which caused the exception
2542 @@ -450,11 +549,15 @@ __und_usr_thumb:
2543 */
2544 .arch armv6t2
2545 #endif
2546 + pax_open_userland
2547 2: ldrht r5, [r4]
2548 + pax_close_userland
2549 ARM_BE8(rev16 r5, r5) @ little endian instruction
2550 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2551 blo __und_usr_fault_16 @ 16bit undefined instruction
2552 + pax_open_userland
2553 3: ldrht r0, [r2]
2554 + pax_close_userland
2555 ARM_BE8(rev16 r0, r0) @ little endian instruction
2556 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2557 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2558 @@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2559 */
2560 .pushsection .fixup, "ax"
2561 .align 2
2562 -4: mov pc, r9
2563 +4: pax_close_userland
2564 + mov pc, r9
2565 .popsection
2566 .pushsection __ex_table,"a"
2567 .long 1b, 4b
2568 @@ -694,7 +798,7 @@ ENTRY(__switch_to)
2569 THUMB( str lr, [ip], #4 )
2570 ldr r4, [r2, #TI_TP_VALUE]
2571 ldr r5, [r2, #TI_TP_VALUE + 4]
2572 -#ifdef CONFIG_CPU_USE_DOMAINS
2573 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2574 ldr r6, [r2, #TI_CPU_DOMAIN]
2575 #endif
2576 switch_tls r1, r4, r5, r3, r7
2577 @@ -703,7 +807,7 @@ ENTRY(__switch_to)
2578 ldr r8, =__stack_chk_guard
2579 ldr r7, [r7, #TSK_STACK_CANARY]
2580 #endif
2581 -#ifdef CONFIG_CPU_USE_DOMAINS
2582 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2583 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2584 #endif
2585 mov r5, r0
2586 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2587 index a2dcafd..1048b5a 100644
2588 --- a/arch/arm/kernel/entry-common.S
2589 +++ b/arch/arm/kernel/entry-common.S
2590 @@ -10,18 +10,46 @@
2591
2592 #include <asm/unistd.h>
2593 #include <asm/ftrace.h>
2594 +#include <asm/domain.h>
2595 #include <asm/unwind.h>
2596
2597 +#include "entry-header.S"
2598 +
2599 #ifdef CONFIG_NEED_RET_TO_USER
2600 #include <mach/entry-macro.S>
2601 #else
2602 .macro arch_ret_to_user, tmp1, tmp2
2603 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2604 + @ save regs
2605 + stmdb sp!, {r1, r2}
2606 + @ read DACR from cpu_domain into r1
2607 + mov r2, sp
2608 + @ assume 8K pages, since we have to split the immediate in two
2609 + bic r2, r2, #(0x1fc0)
2610 + bic r2, r2, #(0x3f)
2611 + ldr r1, [r2, #TI_CPU_DOMAIN]
2612 +#ifdef CONFIG_PAX_KERNEXEC
2613 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2614 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2615 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2616 +#endif
2617 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2618 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2619 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2620 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2621 +#endif
2622 + @ write r1 to current_thread_info()->cpu_domain
2623 + str r1, [r2, #TI_CPU_DOMAIN]
2624 + @ write r1 to DACR
2625 + mcr p15, 0, r1, c3, c0, 0
2626 + @ instruction sync
2627 + instr_sync
2628 + @ restore regs
2629 + ldmia sp!, {r1, r2}
2630 +#endif
2631 .endm
2632 #endif
2633
2634 -#include "entry-header.S"
2635 -
2636 -
2637 .align 5
2638 /*
2639 * This is the fast syscall return path. We do as little as
2640 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2641 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2642 #endif
2643
2644 + /*
2645 + * do this here to avoid a performance hit of wrapping the code above
2646 + * that directly dereferences userland to parse the SWI instruction
2647 + */
2648 + pax_enter_kernel_user
2649 +
2650 adr tbl, sys_call_table @ load syscall table pointer
2651
2652 #if defined(CONFIG_OABI_COMPAT)
2653 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2654 index 39f89fb..d612bd9 100644
2655 --- a/arch/arm/kernel/entry-header.S
2656 +++ b/arch/arm/kernel/entry-header.S
2657 @@ -184,6 +184,60 @@
2658 msr cpsr_c, \rtemp @ switch back to the SVC mode
2659 .endm
2660
2661 + .macro pax_enter_kernel_user
2662 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2663 + @ save regs
2664 + stmdb sp!, {r0, r1}
2665 + @ read DACR from cpu_domain into r1
2666 + mov r0, sp
2667 + @ assume 8K pages, since we have to split the immediate in two
2668 + bic r0, r0, #(0x1fc0)
2669 + bic r0, r0, #(0x3f)
2670 + ldr r1, [r0, #TI_CPU_DOMAIN]
2671 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2672 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2673 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2674 +#endif
2675 +#ifdef CONFIG_PAX_KERNEXEC
2676 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2677 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2678 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2679 +#endif
2680 + @ write r1 to current_thread_info()->cpu_domain
2681 + str r1, [r0, #TI_CPU_DOMAIN]
2682 + @ write r1 to DACR
2683 + mcr p15, 0, r1, c3, c0, 0
2684 + @ instruction sync
2685 + instr_sync
2686 + @ restore regs
2687 + ldmia sp!, {r0, r1}
2688 +#endif
2689 + .endm
2690 +
2691 + .macro pax_exit_kernel
2692 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2693 + @ save regs
2694 + stmdb sp!, {r0, r1}
2695 + @ read old DACR from stack into r1
2696 + ldr r1, [sp, #(8 + S_SP)]
2697 + sub r1, r1, #8
2698 + ldr r1, [r1]
2699 +
2700 + @ write r1 to current_thread_info()->cpu_domain
2701 + mov r0, sp
2702 + @ assume 8K pages, since we have to split the immediate in two
2703 + bic r0, r0, #(0x1fc0)
2704 + bic r0, r0, #(0x3f)
2705 + str r1, [r0, #TI_CPU_DOMAIN]
2706 + @ write r1 to DACR
2707 + mcr p15, 0, r1, c3, c0, 0
2708 + @ instruction sync
2709 + instr_sync
2710 + @ restore regs
2711 + ldmia sp!, {r0, r1}
2712 +#endif
2713 + .endm
2714 +
2715 #ifndef CONFIG_THUMB2_KERNEL
2716 .macro svc_exit, rpsr, irq = 0
2717 .if \irq != 0
2718 @@ -203,6 +257,9 @@
2719 blne trace_hardirqs_off
2720 #endif
2721 .endif
2722 +
2723 + pax_exit_kernel
2724 +
2725 msr spsr_cxsf, \rpsr
2726 #if defined(CONFIG_CPU_V6)
2727 ldr r0, [sp]
2728 @@ -266,6 +323,9 @@
2729 blne trace_hardirqs_off
2730 #endif
2731 .endif
2732 +
2733 + pax_exit_kernel
2734 +
2735 ldr lr, [sp, #S_SP] @ top of the stack
2736 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2737 clrex @ clear the exclusive monitor
2738 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2739 index 918875d..cd5fa27 100644
2740 --- a/arch/arm/kernel/fiq.c
2741 +++ b/arch/arm/kernel/fiq.c
2742 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2743 void *base = vectors_page;
2744 unsigned offset = FIQ_OFFSET;
2745
2746 + pax_open_kernel();
2747 memcpy(base + offset, start, length);
2748 + pax_close_kernel();
2749 +
2750 if (!cache_is_vipt_nonaliasing())
2751 flush_icache_range((unsigned long)base + offset, offset +
2752 length);
2753 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2754 index f5f381d..a6f36a1 100644
2755 --- a/arch/arm/kernel/head.S
2756 +++ b/arch/arm/kernel/head.S
2757 @@ -437,7 +437,7 @@ __enable_mmu:
2758 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2759 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2760 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2761 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2762 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2763 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2764 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2765 #endif
2766 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2767 index 45e4781..8eac93d 100644
2768 --- a/arch/arm/kernel/module.c
2769 +++ b/arch/arm/kernel/module.c
2770 @@ -38,12 +38,39 @@
2771 #endif
2772
2773 #ifdef CONFIG_MMU
2774 -void *module_alloc(unsigned long size)
2775 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2776 {
2777 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2778 + return NULL;
2779 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2780 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2781 + GFP_KERNEL, prot, NUMA_NO_NODE,
2782 __builtin_return_address(0));
2783 }
2784 +
2785 +void *module_alloc(unsigned long size)
2786 +{
2787 +
2788 +#ifdef CONFIG_PAX_KERNEXEC
2789 + return __module_alloc(size, PAGE_KERNEL);
2790 +#else
2791 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2792 +#endif
2793 +
2794 +}
2795 +
2796 +#ifdef CONFIG_PAX_KERNEXEC
2797 +void module_free_exec(struct module *mod, void *module_region)
2798 +{
2799 + module_free(mod, module_region);
2800 +}
2801 +EXPORT_SYMBOL(module_free_exec);
2802 +
2803 +void *module_alloc_exec(unsigned long size)
2804 +{
2805 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2806 +}
2807 +EXPORT_SYMBOL(module_alloc_exec);
2808 +#endif
2809 #endif
2810
2811 int
2812 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2813 index 07314af..c46655c 100644
2814 --- a/arch/arm/kernel/patch.c
2815 +++ b/arch/arm/kernel/patch.c
2816 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2817 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2818 int size;
2819
2820 + pax_open_kernel();
2821 if (thumb2 && __opcode_is_thumb16(insn)) {
2822 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2823 size = sizeof(u16);
2824 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2825 *(u32 *)addr = insn;
2826 size = sizeof(u32);
2827 }
2828 + pax_close_kernel();
2829
2830 flush_icache_range((uintptr_t)(addr),
2831 (uintptr_t)(addr) + size);
2832 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2833 index 92f7b15..7048500 100644
2834 --- a/arch/arm/kernel/process.c
2835 +++ b/arch/arm/kernel/process.c
2836 @@ -217,6 +217,7 @@ void machine_power_off(void)
2837
2838 if (pm_power_off)
2839 pm_power_off();
2840 + BUG();
2841 }
2842
2843 /*
2844 @@ -230,7 +231,7 @@ void machine_power_off(void)
2845 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2846 * to use. Implementing such co-ordination would be essentially impossible.
2847 */
2848 -void machine_restart(char *cmd)
2849 +__noreturn void machine_restart(char *cmd)
2850 {
2851 local_irq_disable();
2852 smp_send_stop();
2853 @@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2854
2855 show_regs_print_info(KERN_DEFAULT);
2856
2857 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2858 - print_symbol("LR is at %s\n", regs->ARM_lr);
2859 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2860 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2861 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2862 "sp : %08lx ip : %08lx fp : %08lx\n",
2863 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2864 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2865 return 0;
2866 }
2867
2868 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2869 -{
2870 - unsigned long range_end = mm->brk + 0x02000000;
2871 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2872 -}
2873 -
2874 #ifdef CONFIG_MMU
2875 #ifdef CONFIG_KUSER_HELPERS
2876 /*
2877 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2878
2879 static int __init gate_vma_init(void)
2880 {
2881 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2882 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2883 return 0;
2884 }
2885 arch_initcall(gate_vma_init);
2886 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2887
2888 const char *arch_vma_name(struct vm_area_struct *vma)
2889 {
2890 - return is_gate_vma(vma) ? "[vectors]" :
2891 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2892 - "[sigpage]" : NULL;
2893 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2894 }
2895
2896 -static struct page *signal_page;
2897 -extern struct page *get_signal_page(void);
2898 -
2899 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2900 {
2901 struct mm_struct *mm = current->mm;
2902 - unsigned long addr;
2903 - int ret;
2904 -
2905 - if (!signal_page)
2906 - signal_page = get_signal_page();
2907 - if (!signal_page)
2908 - return -ENOMEM;
2909
2910 down_write(&mm->mmap_sem);
2911 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2912 - if (IS_ERR_VALUE(addr)) {
2913 - ret = addr;
2914 - goto up_fail;
2915 - }
2916 -
2917 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2918 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2919 - &signal_page);
2920 -
2921 - if (ret == 0)
2922 - mm->context.sigpage = addr;
2923 -
2924 - up_fail:
2925 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2926 up_write(&mm->mmap_sem);
2927 - return ret;
2928 + return 0;
2929 }
2930 #endif
2931 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2932 index 4693188..4596c5e 100644
2933 --- a/arch/arm/kernel/psci.c
2934 +++ b/arch/arm/kernel/psci.c
2935 @@ -24,7 +24,7 @@
2936 #include <asm/opcodes-virt.h>
2937 #include <asm/psci.h>
2938
2939 -struct psci_operations psci_ops;
2940 +struct psci_operations psci_ops __read_only;
2941
2942 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2943
2944 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2945 index 0dd3b79..e018f64 100644
2946 --- a/arch/arm/kernel/ptrace.c
2947 +++ b/arch/arm/kernel/ptrace.c
2948 @@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2949 return current_thread_info()->syscall;
2950 }
2951
2952 +#ifdef CONFIG_GRKERNSEC_SETXID
2953 +extern void gr_delayed_cred_worker(void);
2954 +#endif
2955 +
2956 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2957 {
2958 current_thread_info()->syscall = scno;
2959
2960 +#ifdef CONFIG_GRKERNSEC_SETXID
2961 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2962 + gr_delayed_cred_worker();
2963 +#endif
2964 +
2965 /* Do the secure computing check first; failures should be fast. */
2966 if (secure_computing(scno) == -1)
2967 return -1;
2968 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2969 index 1e8b030..37c3022 100644
2970 --- a/arch/arm/kernel/setup.c
2971 +++ b/arch/arm/kernel/setup.c
2972 @@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2973 unsigned int elf_hwcap __read_mostly;
2974 EXPORT_SYMBOL(elf_hwcap);
2975
2976 +pteval_t __supported_pte_mask __read_only;
2977 +pmdval_t __supported_pmd_mask __read_only;
2978
2979 #ifdef MULTI_CPU
2980 -struct processor processor __read_mostly;
2981 +struct processor processor __read_only;
2982 #endif
2983 #ifdef MULTI_TLB
2984 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2985 +struct cpu_tlb_fns cpu_tlb __read_only;
2986 #endif
2987 #ifdef MULTI_USER
2988 -struct cpu_user_fns cpu_user __read_mostly;
2989 +struct cpu_user_fns cpu_user __read_only;
2990 #endif
2991 #ifdef MULTI_CACHE
2992 -struct cpu_cache_fns cpu_cache __read_mostly;
2993 +struct cpu_cache_fns cpu_cache __read_only;
2994 #endif
2995 #ifdef CONFIG_OUTER_CACHE
2996 -struct outer_cache_fns outer_cache __read_mostly;
2997 +struct outer_cache_fns outer_cache __read_only;
2998 EXPORT_SYMBOL(outer_cache);
2999 #endif
3000
3001 @@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3002 asm("mrc p15, 0, %0, c0, c1, 4"
3003 : "=r" (mmfr0));
3004 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3005 - (mmfr0 & 0x000000f0) >= 0x00000030)
3006 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3007 cpu_arch = CPU_ARCH_ARMv7;
3008 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3009 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3010 + __supported_pte_mask |= L_PTE_PXN;
3011 + __supported_pmd_mask |= PMD_PXNTABLE;
3012 + }
3013 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3014 (mmfr0 & 0x000000f0) == 0x00000020)
3015 cpu_arch = CPU_ARCH_ARMv6;
3016 else
3017 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3018 index 04d6388..5115238 100644
3019 --- a/arch/arm/kernel/signal.c
3020 +++ b/arch/arm/kernel/signal.c
3021 @@ -23,8 +23,6 @@
3022
3023 extern const unsigned long sigreturn_codes[7];
3024
3025 -static unsigned long signal_return_offset;
3026 -
3027 #ifdef CONFIG_CRUNCH
3028 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3029 {
3030 @@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3031 * except when the MPU has protected the vectors
3032 * page from PL0
3033 */
3034 - retcode = mm->context.sigpage + signal_return_offset +
3035 - (idx << 2) + thumb;
3036 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3037 } else
3038 #endif
3039 {
3040 @@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3041 } while (thread_flags & _TIF_WORK_MASK);
3042 return 0;
3043 }
3044 -
3045 -struct page *get_signal_page(void)
3046 -{
3047 - unsigned long ptr;
3048 - unsigned offset;
3049 - struct page *page;
3050 - void *addr;
3051 -
3052 - page = alloc_pages(GFP_KERNEL, 0);
3053 -
3054 - if (!page)
3055 - return NULL;
3056 -
3057 - addr = page_address(page);
3058 -
3059 - /* Give the signal return code some randomness */
3060 - offset = 0x200 + (get_random_int() & 0x7fc);
3061 - signal_return_offset = offset;
3062 -
3063 - /*
3064 - * Copy signal return handlers into the vector page, and
3065 - * set sigreturn to be a pointer to these.
3066 - */
3067 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3068 -
3069 - ptr = (unsigned long)addr + offset;
3070 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3071 -
3072 - return page;
3073 -}
3074 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3075 index b7b4c86..47c4f77 100644
3076 --- a/arch/arm/kernel/smp.c
3077 +++ b/arch/arm/kernel/smp.c
3078 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3079
3080 static DECLARE_COMPLETION(cpu_running);
3081
3082 -static struct smp_operations smp_ops;
3083 +static struct smp_operations smp_ops __read_only;
3084
3085 void __init smp_set_ops(struct smp_operations *ops)
3086 {
3087 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3088 index 7a3be1d..b00c7de 100644
3089 --- a/arch/arm/kernel/tcm.c
3090 +++ b/arch/arm/kernel/tcm.c
3091 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3092 .virtual = ITCM_OFFSET,
3093 .pfn = __phys_to_pfn(ITCM_OFFSET),
3094 .length = 0,
3095 - .type = MT_MEMORY_RWX_ITCM,
3096 + .type = MT_MEMORY_RX_ITCM,
3097 }
3098 };
3099
3100 @@ -267,7 +267,9 @@ no_dtcm:
3101 start = &__sitcm_text;
3102 end = &__eitcm_text;
3103 ram = &__itcm_start;
3104 + pax_open_kernel();
3105 memcpy(start, ram, itcm_code_sz);
3106 + pax_close_kernel();
3107 pr_debug("CPU ITCM: copied code from %p - %p\n",
3108 start, end);
3109 itcm_present = true;
3110 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3111 index 172ee18..ce4ec3d 100644
3112 --- a/arch/arm/kernel/traps.c
3113 +++ b/arch/arm/kernel/traps.c
3114 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3115 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3116 {
3117 #ifdef CONFIG_KALLSYMS
3118 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3119 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3120 #else
3121 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3122 #endif
3123 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3124 static int die_owner = -1;
3125 static unsigned int die_nest_count;
3126
3127 +extern void gr_handle_kernel_exploit(void);
3128 +
3129 static unsigned long oops_begin(void)
3130 {
3131 int cpu;
3132 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3133 panic("Fatal exception in interrupt");
3134 if (panic_on_oops)
3135 panic("Fatal exception");
3136 +
3137 + gr_handle_kernel_exploit();
3138 +
3139 if (signr)
3140 do_exit(signr);
3141 }
3142 @@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3143 * The user helper at 0xffff0fe0 must be used instead.
3144 * (see entry-armv.S for details)
3145 */
3146 + pax_open_kernel();
3147 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3148 + pax_close_kernel();
3149 }
3150 return 0;
3151
3152 @@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3153 kuser_init(vectors_base);
3154
3155 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3156 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3157 +
3158 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3159 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3160 +#endif
3161 +
3162 #else /* ifndef CONFIG_CPU_V7M */
3163 /*
3164 * on V7-M there is no need to copy the vector table to a dedicated
3165 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3166 index 7bcee5c..e2f3249 100644
3167 --- a/arch/arm/kernel/vmlinux.lds.S
3168 +++ b/arch/arm/kernel/vmlinux.lds.S
3169 @@ -8,7 +8,11 @@
3170 #include <asm/thread_info.h>
3171 #include <asm/memory.h>
3172 #include <asm/page.h>
3173 -
3174 +
3175 +#ifdef CONFIG_PAX_KERNEXEC
3176 +#include <asm/pgtable.h>
3177 +#endif
3178 +
3179 #define PROC_INFO \
3180 . = ALIGN(4); \
3181 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3182 @@ -34,7 +38,7 @@
3183 #endif
3184
3185 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3186 - defined(CONFIG_GENERIC_BUG)
3187 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3188 #define ARM_EXIT_KEEP(x) x
3189 #define ARM_EXIT_DISCARD(x)
3190 #else
3191 @@ -90,6 +94,11 @@ SECTIONS
3192 _text = .;
3193 HEAD_TEXT
3194 }
3195 +
3196 +#ifdef CONFIG_PAX_KERNEXEC
3197 + . = ALIGN(1<<SECTION_SHIFT);
3198 +#endif
3199 +
3200 .text : { /* Real text segment */
3201 _stext = .; /* Text and read-only data */
3202 __exception_text_start = .;
3203 @@ -112,6 +121,8 @@ SECTIONS
3204 ARM_CPU_KEEP(PROC_INFO)
3205 }
3206
3207 + _etext = .; /* End of text section */
3208 +
3209 RO_DATA(PAGE_SIZE)
3210
3211 . = ALIGN(4);
3212 @@ -142,7 +153,9 @@ SECTIONS
3213
3214 NOTES
3215
3216 - _etext = .; /* End of text and rodata section */
3217 +#ifdef CONFIG_PAX_KERNEXEC
3218 + . = ALIGN(1<<SECTION_SHIFT);
3219 +#endif
3220
3221 #ifndef CONFIG_XIP_KERNEL
3222 . = ALIGN(PAGE_SIZE);
3223 @@ -220,6 +233,11 @@ SECTIONS
3224 . = PAGE_OFFSET + TEXT_OFFSET;
3225 #else
3226 __init_end = .;
3227 +
3228 +#ifdef CONFIG_PAX_KERNEXEC
3229 + . = ALIGN(1<<SECTION_SHIFT);
3230 +#endif
3231 +
3232 . = ALIGN(THREAD_SIZE);
3233 __data_loc = .;
3234 #endif
3235 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3236 index bd18bb8..87ede26 100644
3237 --- a/arch/arm/kvm/arm.c
3238 +++ b/arch/arm/kvm/arm.c
3239 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3240 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3241
3242 /* The VMID used in the VTTBR */
3243 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3244 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3245 static u8 kvm_next_vmid;
3246 static DEFINE_SPINLOCK(kvm_vmid_lock);
3247
3248 @@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3249 */
3250 static bool need_new_vmid_gen(struct kvm *kvm)
3251 {
3252 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3253 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3254 }
3255
3256 /**
3257 @@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3258
3259 /* First user of a new VMID generation? */
3260 if (unlikely(kvm_next_vmid == 0)) {
3261 - atomic64_inc(&kvm_vmid_gen);
3262 + atomic64_inc_unchecked(&kvm_vmid_gen);
3263 kvm_next_vmid = 1;
3264
3265 /*
3266 @@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3267 kvm_call_hyp(__kvm_flush_vm_context);
3268 }
3269
3270 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3271 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3272 kvm->arch.vmid = kvm_next_vmid;
3273 kvm_next_vmid++;
3274
3275 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3276 index 14a0d98..7771a7d 100644
3277 --- a/arch/arm/lib/clear_user.S
3278 +++ b/arch/arm/lib/clear_user.S
3279 @@ -12,14 +12,14 @@
3280
3281 .text
3282
3283 -/* Prototype: int __clear_user(void *addr, size_t sz)
3284 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3285 * Purpose : clear some user memory
3286 * Params : addr - user memory address to clear
3287 * : sz - number of bytes to clear
3288 * Returns : number of bytes NOT cleared
3289 */
3290 ENTRY(__clear_user_std)
3291 -WEAK(__clear_user)
3292 +WEAK(___clear_user)
3293 stmfd sp!, {r1, lr}
3294 mov r2, #0
3295 cmp r1, #4
3296 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3297 USER( strnebt r2, [r0])
3298 mov r0, #0
3299 ldmfd sp!, {r1, pc}
3300 -ENDPROC(__clear_user)
3301 +ENDPROC(___clear_user)
3302 ENDPROC(__clear_user_std)
3303
3304 .pushsection .fixup,"ax"
3305 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3306 index 66a477a..bee61d3 100644
3307 --- a/arch/arm/lib/copy_from_user.S
3308 +++ b/arch/arm/lib/copy_from_user.S
3309 @@ -16,7 +16,7 @@
3310 /*
3311 * Prototype:
3312 *
3313 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3314 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3315 *
3316 * Purpose:
3317 *
3318 @@ -84,11 +84,11 @@
3319
3320 .text
3321
3322 -ENTRY(__copy_from_user)
3323 +ENTRY(___copy_from_user)
3324
3325 #include "copy_template.S"
3326
3327 -ENDPROC(__copy_from_user)
3328 +ENDPROC(___copy_from_user)
3329
3330 .pushsection .fixup,"ax"
3331 .align 0
3332 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3333 index 6ee2f67..d1cce76 100644
3334 --- a/arch/arm/lib/copy_page.S
3335 +++ b/arch/arm/lib/copy_page.S
3336 @@ -10,6 +10,7 @@
3337 * ASM optimised string functions
3338 */
3339 #include <linux/linkage.h>
3340 +#include <linux/const.h>
3341 #include <asm/assembler.h>
3342 #include <asm/asm-offsets.h>
3343 #include <asm/cache.h>
3344 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3345 index d066df6..df28194 100644
3346 --- a/arch/arm/lib/copy_to_user.S
3347 +++ b/arch/arm/lib/copy_to_user.S
3348 @@ -16,7 +16,7 @@
3349 /*
3350 * Prototype:
3351 *
3352 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3353 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3354 *
3355 * Purpose:
3356 *
3357 @@ -88,11 +88,11 @@
3358 .text
3359
3360 ENTRY(__copy_to_user_std)
3361 -WEAK(__copy_to_user)
3362 +WEAK(___copy_to_user)
3363
3364 #include "copy_template.S"
3365
3366 -ENDPROC(__copy_to_user)
3367 +ENDPROC(___copy_to_user)
3368 ENDPROC(__copy_to_user_std)
3369
3370 .pushsection .fixup,"ax"
3371 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3372 index 7d08b43..f7ca7ea 100644
3373 --- a/arch/arm/lib/csumpartialcopyuser.S
3374 +++ b/arch/arm/lib/csumpartialcopyuser.S
3375 @@ -57,8 +57,8 @@
3376 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3377 */
3378
3379 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3380 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3381 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3382 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3383
3384 #include "csumpartialcopygeneric.S"
3385
3386 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3387 index 5306de3..aed6d03 100644
3388 --- a/arch/arm/lib/delay.c
3389 +++ b/arch/arm/lib/delay.c
3390 @@ -28,7 +28,7 @@
3391 /*
3392 * Default to the loop-based delay implementation.
3393 */
3394 -struct arm_delay_ops arm_delay_ops = {
3395 +struct arm_delay_ops arm_delay_ops __read_only = {
3396 .delay = __loop_delay,
3397 .const_udelay = __loop_const_udelay,
3398 .udelay = __loop_udelay,
3399 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3400 index 3e58d71..029817c 100644
3401 --- a/arch/arm/lib/uaccess_with_memcpy.c
3402 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3403 @@ -136,7 +136,7 @@ out:
3404 }
3405
3406 unsigned long
3407 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3408 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3409 {
3410 /*
3411 * This test is stubbed out of the main function above to keep
3412 @@ -190,7 +190,7 @@ out:
3413 return n;
3414 }
3415
3416 -unsigned long __clear_user(void __user *addr, unsigned long n)
3417 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3418 {
3419 /* See rational for this in __copy_to_user() above. */
3420 if (n < 64)
3421 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3422 index f7ca97b..3d7e719 100644
3423 --- a/arch/arm/mach-at91/setup.c
3424 +++ b/arch/arm/mach-at91/setup.c
3425 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3426
3427 desc->pfn = __phys_to_pfn(base);
3428 desc->length = length;
3429 - desc->type = MT_MEMORY_RWX_NONCACHED;
3430 + desc->type = MT_MEMORY_RW_NONCACHED;
3431
3432 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3433 base, length, desc->virtual);
3434 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3435 index f3407a5..bd4256f 100644
3436 --- a/arch/arm/mach-kirkwood/common.c
3437 +++ b/arch/arm/mach-kirkwood/common.c
3438 @@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3439 clk_gate_ops.disable(hw);
3440 }
3441
3442 -static struct clk_ops clk_gate_fn_ops;
3443 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3444 +{
3445 + return clk_gate_ops.is_enabled(hw);
3446 +}
3447 +
3448 +static struct clk_ops clk_gate_fn_ops = {
3449 + .enable = clk_gate_fn_enable,
3450 + .disable = clk_gate_fn_disable,
3451 + .is_enabled = clk_gate_fn_is_enabled,
3452 +};
3453
3454 static struct clk __init *clk_register_gate_fn(struct device *dev,
3455 const char *name,
3456 @@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3457 gate_fn->fn_en = fn_en;
3458 gate_fn->fn_dis = fn_dis;
3459
3460 - /* ops is the gate ops, but with our enable/disable functions */
3461 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3462 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3463 - clk_gate_fn_ops = clk_gate_ops;
3464 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3465 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3466 - }
3467 -
3468 clk = clk_register(dev, &gate_fn->gate.hw);
3469
3470 if (IS_ERR(clk))
3471 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3472 index aead77a..a2253fa 100644
3473 --- a/arch/arm/mach-omap2/board-n8x0.c
3474 +++ b/arch/arm/mach-omap2/board-n8x0.c
3475 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3476 }
3477 #endif
3478
3479 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3480 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3481 .late_init = n8x0_menelaus_late_init,
3482 };
3483
3484 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3485 index ab43755..ccfa231 100644
3486 --- a/arch/arm/mach-omap2/gpmc.c
3487 +++ b/arch/arm/mach-omap2/gpmc.c
3488 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3489 };
3490
3491 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3492 -static struct irq_chip gpmc_irq_chip;
3493 static int gpmc_irq_start;
3494
3495 static struct resource gpmc_mem_root;
3496 @@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3497
3498 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3499
3500 +static struct irq_chip gpmc_irq_chip = {
3501 + .name = "gpmc",
3502 + .irq_startup = gpmc_irq_noop_ret,
3503 + .irq_enable = gpmc_irq_enable,
3504 + .irq_disable = gpmc_irq_disable,
3505 + .irq_shutdown = gpmc_irq_noop,
3506 + .irq_ack = gpmc_irq_noop,
3507 + .irq_mask = gpmc_irq_noop,
3508 + .irq_unmask = gpmc_irq_noop,
3509 +
3510 +};
3511 +
3512 static int gpmc_setup_irq(void)
3513 {
3514 int i;
3515 @@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3516 return gpmc_irq_start;
3517 }
3518
3519 - gpmc_irq_chip.name = "gpmc";
3520 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3521 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3522 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3523 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3524 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3525 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3526 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3527 -
3528 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3529 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3530
3531 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3532 index 667915d..2ee1219 100644
3533 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3534 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3535 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3536 int (*finish_suspend)(unsigned long cpu_state);
3537 void (*resume)(void);
3538 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3539 -};
3540 +} __no_const;
3541
3542 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3543 static struct powerdomain *mpuss_pd;
3544 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3545 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3546 {}
3547
3548 -struct cpu_pm_ops omap_pm_ops = {
3549 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3550 .finish_suspend = default_finish_suspend,
3551 .resume = dummy_cpu_resume,
3552 .scu_prepare = dummy_scu_prepare,
3553 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3554 index 3664562..72f85c6 100644
3555 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3556 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3557 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3558 return NOTIFY_OK;
3559 }
3560
3561 -static struct notifier_block __refdata irq_hotplug_notifier = {
3562 +static struct notifier_block irq_hotplug_notifier = {
3563 .notifier_call = irq_cpu_hotplug_notify,
3564 };
3565
3566 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3567 index 01ef59d..32ae28a8 100644
3568 --- a/arch/arm/mach-omap2/omap_device.c
3569 +++ b/arch/arm/mach-omap2/omap_device.c
3570 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3571 struct platform_device __init *omap_device_build(const char *pdev_name,
3572 int pdev_id,
3573 struct omap_hwmod *oh,
3574 - void *pdata, int pdata_len)
3575 + const void *pdata, int pdata_len)
3576 {
3577 struct omap_hwmod *ohs[] = { oh };
3578
3579 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3580 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3581 int pdev_id,
3582 struct omap_hwmod **ohs,
3583 - int oh_cnt, void *pdata,
3584 + int oh_cnt, const void *pdata,
3585 int pdata_len)
3586 {
3587 int ret = -ENOMEM;
3588 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3589 index 78c02b3..c94109a 100644
3590 --- a/arch/arm/mach-omap2/omap_device.h
3591 +++ b/arch/arm/mach-omap2/omap_device.h
3592 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3593 /* Core code interface */
3594
3595 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3596 - struct omap_hwmod *oh, void *pdata,
3597 + struct omap_hwmod *oh, const void *pdata,
3598 int pdata_len);
3599
3600 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3601 struct omap_hwmod **oh, int oh_cnt,
3602 - void *pdata, int pdata_len);
3603 + const void *pdata, int pdata_len);
3604
3605 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3606 struct omap_hwmod **ohs, int oh_cnt);
3607 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3608 index 66c60fe..c78950d 100644
3609 --- a/arch/arm/mach-omap2/omap_hwmod.c
3610 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3611 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3612 int (*init_clkdm)(struct omap_hwmod *oh);
3613 void (*update_context_lost)(struct omap_hwmod *oh);
3614 int (*get_context_lost)(struct omap_hwmod *oh);
3615 -};
3616 +} __no_const;
3617
3618 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3619 -static struct omap_hwmod_soc_ops soc_ops;
3620 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3621
3622 /* omap_hwmod_list contains all registered struct omap_hwmods */
3623 static LIST_HEAD(omap_hwmod_list);
3624 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3625 index 95fee54..cfa9cf1 100644
3626 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3627 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3628 @@ -10,6 +10,7 @@
3629
3630 #include <linux/kernel.h>
3631 #include <linux/init.h>
3632 +#include <asm/pgtable.h>
3633
3634 #include "powerdomain.h"
3635
3636 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3637
3638 void __init am43xx_powerdomains_init(void)
3639 {
3640 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3641 + pax_open_kernel();
3642 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3643 + pax_close_kernel();
3644 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3645 pwrdm_register_pwrdms(powerdomains_am43xx);
3646 pwrdm_complete_init();
3647 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3648 index d15c7bb..b2d1f0c 100644
3649 --- a/arch/arm/mach-omap2/wd_timer.c
3650 +++ b/arch/arm/mach-omap2/wd_timer.c
3651 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3652 struct omap_hwmod *oh;
3653 char *oh_name = "wd_timer2";
3654 char *dev_name = "omap_wdt";
3655 - struct omap_wd_timer_platform_data pdata;
3656 + static struct omap_wd_timer_platform_data pdata = {
3657 + .read_reset_sources = prm_read_reset_sources
3658 + };
3659
3660 if (!cpu_class_is_omap2() || of_have_populated_dt())
3661 return 0;
3662 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3663 return -EINVAL;
3664 }
3665
3666 - pdata.read_reset_sources = prm_read_reset_sources;
3667 -
3668 pdev = omap_device_build(dev_name, id, oh, &pdata,
3669 sizeof(struct omap_wd_timer_platform_data));
3670 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3671 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3672 index b82dcae..44ee5b6 100644
3673 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3674 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3675 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3676 bool entered_lp2 = false;
3677
3678 if (tegra_pending_sgi())
3679 - ACCESS_ONCE(abort_flag) = true;
3680 + ACCESS_ONCE_RW(abort_flag) = true;
3681
3682 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3683
3684 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3685 index 2dea8b5..6499da2 100644
3686 --- a/arch/arm/mach-ux500/setup.h
3687 +++ b/arch/arm/mach-ux500/setup.h
3688 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3689 .type = MT_DEVICE, \
3690 }
3691
3692 -#define __MEM_DEV_DESC(x, sz) { \
3693 - .virtual = IO_ADDRESS(x), \
3694 - .pfn = __phys_to_pfn(x), \
3695 - .length = sz, \
3696 - .type = MT_MEMORY_RWX, \
3697 -}
3698 -
3699 extern struct smp_operations ux500_smp_ops;
3700 extern void ux500_cpu_die(unsigned int cpu);
3701
3702 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3703 index ca8ecde..58ba893 100644
3704 --- a/arch/arm/mm/Kconfig
3705 +++ b/arch/arm/mm/Kconfig
3706 @@ -446,6 +446,7 @@ config CPU_32v5
3707
3708 config CPU_32v6
3709 bool
3710 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3711 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3712
3713 config CPU_32v6K
3714 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3715
3716 config CPU_USE_DOMAINS
3717 bool
3718 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3719 help
3720 This option enables or disables the use of domain switching
3721 via the set_fs() function.
3722 @@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3723 config KUSER_HELPERS
3724 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3725 default y
3726 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3727 help
3728 Warning: disabling this option may break user programs.
3729
3730 @@ -811,7 +814,7 @@ config KUSER_HELPERS
3731 See Documentation/arm/kernel_user_helpers.txt for details.
3732
3733 However, the fixed address nature of these helpers can be used
3734 - by ROP (return orientated programming) authors when creating
3735 + by ROP (Return Oriented Programming) authors when creating
3736 exploits.
3737
3738 If all of the binaries and libraries which run on your platform
3739 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3740 index 9240364..a2b8cf3 100644
3741 --- a/arch/arm/mm/alignment.c
3742 +++ b/arch/arm/mm/alignment.c
3743 @@ -212,10 +212,12 @@ union offset_union {
3744 #define __get16_unaligned_check(ins,val,addr) \
3745 do { \
3746 unsigned int err = 0, v, a = addr; \
3747 + pax_open_userland(); \
3748 __get8_unaligned_check(ins,v,a,err); \
3749 val = v << ((BE) ? 8 : 0); \
3750 __get8_unaligned_check(ins,v,a,err); \
3751 val |= v << ((BE) ? 0 : 8); \
3752 + pax_close_userland(); \
3753 if (err) \
3754 goto fault; \
3755 } while (0)
3756 @@ -229,6 +231,7 @@ union offset_union {
3757 #define __get32_unaligned_check(ins,val,addr) \
3758 do { \
3759 unsigned int err = 0, v, a = addr; \
3760 + pax_open_userland(); \
3761 __get8_unaligned_check(ins,v,a,err); \
3762 val = v << ((BE) ? 24 : 0); \
3763 __get8_unaligned_check(ins,v,a,err); \
3764 @@ -237,6 +240,7 @@ union offset_union {
3765 val |= v << ((BE) ? 8 : 16); \
3766 __get8_unaligned_check(ins,v,a,err); \
3767 val |= v << ((BE) ? 0 : 24); \
3768 + pax_close_userland(); \
3769 if (err) \
3770 goto fault; \
3771 } while (0)
3772 @@ -250,6 +254,7 @@ union offset_union {
3773 #define __put16_unaligned_check(ins,val,addr) \
3774 do { \
3775 unsigned int err = 0, v = val, a = addr; \
3776 + pax_open_userland(); \
3777 __asm__( FIRST_BYTE_16 \
3778 ARM( "1: "ins" %1, [%2], #1\n" ) \
3779 THUMB( "1: "ins" %1, [%2]\n" ) \
3780 @@ -269,6 +274,7 @@ union offset_union {
3781 " .popsection\n" \
3782 : "=r" (err), "=&r" (v), "=&r" (a) \
3783 : "0" (err), "1" (v), "2" (a)); \
3784 + pax_close_userland(); \
3785 if (err) \
3786 goto fault; \
3787 } while (0)
3788 @@ -282,6 +288,7 @@ union offset_union {
3789 #define __put32_unaligned_check(ins,val,addr) \
3790 do { \
3791 unsigned int err = 0, v = val, a = addr; \
3792 + pax_open_userland(); \
3793 __asm__( FIRST_BYTE_32 \
3794 ARM( "1: "ins" %1, [%2], #1\n" ) \
3795 THUMB( "1: "ins" %1, [%2]\n" ) \
3796 @@ -311,6 +318,7 @@ union offset_union {
3797 " .popsection\n" \
3798 : "=r" (err), "=&r" (v), "=&r" (a) \
3799 : "0" (err), "1" (v), "2" (a)); \
3800 + pax_close_userland(); \
3801 if (err) \
3802 goto fault; \
3803 } while (0)
3804 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3805 index 7abde2c..9df495f 100644
3806 --- a/arch/arm/mm/cache-l2x0.c
3807 +++ b/arch/arm/mm/cache-l2x0.c
3808 @@ -46,7 +46,7 @@ struct l2x0_of_data {
3809 void (*setup)(const struct device_node *, u32 *, u32 *);
3810 void (*save)(void);
3811 struct outer_cache_fns outer_cache;
3812 -};
3813 +} __do_const;
3814
3815 static bool of_init = false;
3816
3817 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3818 index 6eb97b3..ac509f6 100644
3819 --- a/arch/arm/mm/context.c
3820 +++ b/arch/arm/mm/context.c
3821 @@ -43,7 +43,7 @@
3822 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3823
3824 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3825 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3826 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3827 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3828
3829 static DEFINE_PER_CPU(atomic64_t, active_asids);
3830 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3831 {
3832 static u32 cur_idx = 1;
3833 u64 asid = atomic64_read(&mm->context.id);
3834 - u64 generation = atomic64_read(&asid_generation);
3835 + u64 generation = atomic64_read_unchecked(&asid_generation);
3836
3837 if (asid != 0 && is_reserved_asid(asid)) {
3838 /*
3839 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3840 */
3841 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3842 if (asid == NUM_USER_ASIDS) {
3843 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3844 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3845 &asid_generation);
3846 flush_context(cpu);
3847 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3848 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3849 cpu_set_reserved_ttbr0();
3850
3851 asid = atomic64_read(&mm->context.id);
3852 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3853 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3854 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3855 goto switch_mm_fastpath;
3856
3857 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3858 /* Check that our ASID belongs to the current generation. */
3859 asid = atomic64_read(&mm->context.id);
3860 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3861 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3862 asid = new_context(mm, cpu);
3863 atomic64_set(&mm->context.id, asid);
3864 }
3865 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3866 index eb8830a..5360ce7 100644
3867 --- a/arch/arm/mm/fault.c
3868 +++ b/arch/arm/mm/fault.c
3869 @@ -25,6 +25,7 @@
3870 #include <asm/system_misc.h>
3871 #include <asm/system_info.h>
3872 #include <asm/tlbflush.h>
3873 +#include <asm/sections.h>
3874
3875 #include "fault.h"
3876
3877 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3878 if (fixup_exception(regs))
3879 return;
3880
3881 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3882 + if (addr < TASK_SIZE) {
3883 + if (current->signal->curr_ip)
3884 + 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),
3885 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3886 + else
3887 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3888 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3889 + }
3890 +#endif
3891 +
3892 +#ifdef CONFIG_PAX_KERNEXEC
3893 + if ((fsr & FSR_WRITE) &&
3894 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3895 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3896 + {
3897 + if (current->signal->curr_ip)
3898 + 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),
3899 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3900 + else
3901 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3902 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3903 + }
3904 +#endif
3905 +
3906 /*
3907 * No handler, we'll have to terminate things with extreme prejudice.
3908 */
3909 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3910 }
3911 #endif
3912
3913 +#ifdef CONFIG_PAX_PAGEEXEC
3914 + if (fsr & FSR_LNX_PF) {
3915 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3916 + do_group_exit(SIGKILL);
3917 + }
3918 +#endif
3919 +
3920 tsk->thread.address = addr;
3921 tsk->thread.error_code = fsr;
3922 tsk->thread.trap_no = 14;
3923 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3924 }
3925 #endif /* CONFIG_MMU */
3926
3927 +#ifdef CONFIG_PAX_PAGEEXEC
3928 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3929 +{
3930 + long i;
3931 +
3932 + printk(KERN_ERR "PAX: bytes at PC: ");
3933 + for (i = 0; i < 20; i++) {
3934 + unsigned char c;
3935 + if (get_user(c, (__force unsigned char __user *)pc+i))
3936 + printk(KERN_CONT "?? ");
3937 + else
3938 + printk(KERN_CONT "%02x ", c);
3939 + }
3940 + printk("\n");
3941 +
3942 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3943 + for (i = -1; i < 20; i++) {
3944 + unsigned long c;
3945 + if (get_user(c, (__force unsigned long __user *)sp+i))
3946 + printk(KERN_CONT "???????? ");
3947 + else
3948 + printk(KERN_CONT "%08lx ", c);
3949 + }
3950 + printk("\n");
3951 +}
3952 +#endif
3953 +
3954 /*
3955 * First Level Translation Fault Handler
3956 *
3957 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3958 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3959 struct siginfo info;
3960
3961 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3962 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3963 + if (current->signal->curr_ip)
3964 + 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),
3965 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3966 + else
3967 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3968 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3969 + goto die;
3970 + }
3971 +#endif
3972 +
3973 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3974 return;
3975
3976 +die:
3977 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3978 inf->name, fsr, addr);
3979
3980 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3981 ifsr_info[nr].name = name;
3982 }
3983
3984 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
3985 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3986 +
3987 asmlinkage void __exception
3988 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3989 {
3990 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3991 struct siginfo info;
3992 + unsigned long pc = instruction_pointer(regs);
3993 +
3994 + if (user_mode(regs)) {
3995 + unsigned long sigpage = current->mm->context.sigpage;
3996 +
3997 + if (sigpage <= pc && pc < sigpage + 7*4) {
3998 + if (pc < sigpage + 3*4)
3999 + sys_sigreturn(regs);
4000 + else
4001 + sys_rt_sigreturn(regs);
4002 + return;
4003 + }
4004 + if (pc == 0xffff0f60UL) {
4005 + /*
4006 + * PaX: __kuser_cmpxchg64 emulation
4007 + */
4008 + // TODO
4009 + //regs->ARM_pc = regs->ARM_lr;
4010 + //return;
4011 + }
4012 + if (pc == 0xffff0fa0UL) {
4013 + /*
4014 + * PaX: __kuser_memory_barrier emulation
4015 + */
4016 + // dmb(); implied by the exception
4017 + regs->ARM_pc = regs->ARM_lr;
4018 + return;
4019 + }
4020 + if (pc == 0xffff0fc0UL) {
4021 + /*
4022 + * PaX: __kuser_cmpxchg emulation
4023 + */
4024 + // TODO
4025 + //long new;
4026 + //int op;
4027 +
4028 + //op = FUTEX_OP_SET << 28;
4029 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4030 + //regs->ARM_r0 = old != new;
4031 + //regs->ARM_pc = regs->ARM_lr;
4032 + //return;
4033 + }
4034 + if (pc == 0xffff0fe0UL) {
4035 + /*
4036 + * PaX: __kuser_get_tls emulation
4037 + */
4038 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4039 + regs->ARM_pc = regs->ARM_lr;
4040 + return;
4041 + }
4042 + }
4043 +
4044 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4045 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4046 + if (current->signal->curr_ip)
4047 + 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),
4048 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4049 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4050 + else
4051 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4052 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4053 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4054 + goto die;
4055 + }
4056 +#endif
4057 +
4058 +#ifdef CONFIG_PAX_REFCOUNT
4059 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4060 + unsigned int bkpt;
4061 +
4062 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4063 + current->thread.error_code = ifsr;
4064 + current->thread.trap_no = 0;
4065 + pax_report_refcount_overflow(regs);
4066 + fixup_exception(regs);
4067 + return;
4068 + }
4069 + }
4070 +#endif
4071
4072 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4073 return;
4074
4075 +die:
4076 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4077 inf->name, ifsr, addr);
4078
4079 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4080 index cf08bdf..772656c 100644
4081 --- a/arch/arm/mm/fault.h
4082 +++ b/arch/arm/mm/fault.h
4083 @@ -3,6 +3,7 @@
4084
4085 /*
4086 * Fault status register encodings. We steal bit 31 for our own purposes.
4087 + * Set when the FSR value is from an instruction fault.
4088 */
4089 #define FSR_LNX_PF (1 << 31)
4090 #define FSR_WRITE (1 << 11)
4091 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4092 }
4093 #endif
4094
4095 +/* valid for LPAE and !LPAE */
4096 +static inline int is_xn_fault(unsigned int fsr)
4097 +{
4098 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4099 +}
4100 +
4101 +static inline int is_domain_fault(unsigned int fsr)
4102 +{
4103 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4104 +}
4105 +
4106 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4107 unsigned long search_exception_table(unsigned long addr);
4108
4109 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4110 index 804d615..fcec50a 100644
4111 --- a/arch/arm/mm/init.c
4112 +++ b/arch/arm/mm/init.c
4113 @@ -30,6 +30,8 @@
4114 #include <asm/setup.h>
4115 #include <asm/tlb.h>
4116 #include <asm/fixmap.h>
4117 +#include <asm/system_info.h>
4118 +#include <asm/cp15.h>
4119
4120 #include <asm/mach/arch.h>
4121 #include <asm/mach/map.h>
4122 @@ -625,7 +627,46 @@ void free_initmem(void)
4123 {
4124 #ifdef CONFIG_HAVE_TCM
4125 extern char __tcm_start, __tcm_end;
4126 +#endif
4127
4128 +#ifdef CONFIG_PAX_KERNEXEC
4129 + unsigned long addr;
4130 + pgd_t *pgd;
4131 + pud_t *pud;
4132 + pmd_t *pmd;
4133 + int cpu_arch = cpu_architecture();
4134 + unsigned int cr = get_cr();
4135 +
4136 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4137 + /* make pages tables, etc before .text NX */
4138 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4139 + pgd = pgd_offset_k(addr);
4140 + pud = pud_offset(pgd, addr);
4141 + pmd = pmd_offset(pud, addr);
4142 + __section_update(pmd, addr, PMD_SECT_XN);
4143 + }
4144 + /* make init NX */
4145 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4146 + pgd = pgd_offset_k(addr);
4147 + pud = pud_offset(pgd, addr);
4148 + pmd = pmd_offset(pud, addr);
4149 + __section_update(pmd, addr, PMD_SECT_XN);
4150 + }
4151 + /* make kernel code/rodata RX */
4152 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4153 + pgd = pgd_offset_k(addr);
4154 + pud = pud_offset(pgd, addr);
4155 + pmd = pmd_offset(pud, addr);
4156 +#ifdef CONFIG_ARM_LPAE
4157 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4158 +#else
4159 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4160 +#endif
4161 + }
4162 + }
4163 +#endif
4164 +
4165 +#ifdef CONFIG_HAVE_TCM
4166 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4167 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4168 #endif
4169 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4170 index f9c32ba..8540068 100644
4171 --- a/arch/arm/mm/ioremap.c
4172 +++ b/arch/arm/mm/ioremap.c
4173 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4174 unsigned int mtype;
4175
4176 if (cached)
4177 - mtype = MT_MEMORY_RWX;
4178 + mtype = MT_MEMORY_RX;
4179 else
4180 - mtype = MT_MEMORY_RWX_NONCACHED;
4181 + mtype = MT_MEMORY_RX_NONCACHED;
4182
4183 return __arm_ioremap_caller(phys_addr, size, mtype,
4184 __builtin_return_address(0));
4185 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4186 index 5e85ed3..b10a7ed 100644
4187 --- a/arch/arm/mm/mmap.c
4188 +++ b/arch/arm/mm/mmap.c
4189 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4190 struct vm_area_struct *vma;
4191 int do_align = 0;
4192 int aliasing = cache_is_vipt_aliasing();
4193 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4194 struct vm_unmapped_area_info info;
4195
4196 /*
4197 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4198 if (len > TASK_SIZE)
4199 return -ENOMEM;
4200
4201 +#ifdef CONFIG_PAX_RANDMMAP
4202 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4203 +#endif
4204 +
4205 if (addr) {
4206 if (do_align)
4207 addr = COLOUR_ALIGN(addr, pgoff);
4208 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4209 addr = PAGE_ALIGN(addr);
4210
4211 vma = find_vma(mm, addr);
4212 - if (TASK_SIZE - len >= addr &&
4213 - (!vma || addr + len <= vma->vm_start))
4214 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4215 return addr;
4216 }
4217
4218 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4219 info.high_limit = TASK_SIZE;
4220 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4221 info.align_offset = pgoff << PAGE_SHIFT;
4222 + info.threadstack_offset = offset;
4223 return vm_unmapped_area(&info);
4224 }
4225
4226 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4227 unsigned long addr = addr0;
4228 int do_align = 0;
4229 int aliasing = cache_is_vipt_aliasing();
4230 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4231 struct vm_unmapped_area_info info;
4232
4233 /*
4234 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4235 return addr;
4236 }
4237
4238 +#ifdef CONFIG_PAX_RANDMMAP
4239 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4240 +#endif
4241 +
4242 /* requesting a specific address */
4243 if (addr) {
4244 if (do_align)
4245 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4246 else
4247 addr = PAGE_ALIGN(addr);
4248 vma = find_vma(mm, addr);
4249 - if (TASK_SIZE - len >= addr &&
4250 - (!vma || addr + len <= vma->vm_start))
4251 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4252 return addr;
4253 }
4254
4255 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4256 info.high_limit = mm->mmap_base;
4257 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4258 info.align_offset = pgoff << PAGE_SHIFT;
4259 + info.threadstack_offset = offset;
4260 addr = vm_unmapped_area(&info);
4261
4262 /*
4263 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4264 {
4265 unsigned long random_factor = 0UL;
4266
4267 +#ifdef CONFIG_PAX_RANDMMAP
4268 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4269 +#endif
4270 +
4271 /* 8 bits of randomness in 20 address space bits */
4272 if ((current->flags & PF_RANDOMIZE) &&
4273 !(current->personality & ADDR_NO_RANDOMIZE))
4274 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4275
4276 if (mmap_is_legacy()) {
4277 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4278 +
4279 +#ifdef CONFIG_PAX_RANDMMAP
4280 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4281 + mm->mmap_base += mm->delta_mmap;
4282 +#endif
4283 +
4284 mm->get_unmapped_area = arch_get_unmapped_area;
4285 } else {
4286 mm->mmap_base = mmap_base(random_factor);
4287 +
4288 +#ifdef CONFIG_PAX_RANDMMAP
4289 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4290 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4291 +#endif
4292 +
4293 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4294 }
4295 }
4296 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4297 index b68c6b2..f66c492 100644
4298 --- a/arch/arm/mm/mmu.c
4299 +++ b/arch/arm/mm/mmu.c
4300 @@ -39,6 +39,22 @@
4301 #include "mm.h"
4302 #include "tcm.h"
4303
4304 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4305 +void modify_domain(unsigned int dom, unsigned int type)
4306 +{
4307 + struct thread_info *thread = current_thread_info();
4308 + unsigned int domain = thread->cpu_domain;
4309 + /*
4310 + * DOMAIN_MANAGER might be defined to some other value,
4311 + * use the arch-defined constant
4312 + */
4313 + domain &= ~domain_val(dom, 3);
4314 + thread->cpu_domain = domain | domain_val(dom, type);
4315 + set_domain(thread->cpu_domain);
4316 +}
4317 +EXPORT_SYMBOL(modify_domain);
4318 +#endif
4319 +
4320 /*
4321 * empty_zero_page is a special page that is used for
4322 * zero-initialized data and COW.
4323 @@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4324 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4325 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4326
4327 -static struct mem_type mem_types[] = {
4328 +#ifdef CONFIG_PAX_KERNEXEC
4329 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4330 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4331 +#else
4332 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4333 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4334 +#endif
4335 +
4336 +static struct mem_type mem_types[] __read_only = {
4337 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4338 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4339 L_PTE_SHARED,
4340 @@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4341 .prot_sect = PROT_SECT_DEVICE,
4342 .domain = DOMAIN_IO,
4343 },
4344 - [MT_UNCACHED] = {
4345 + [MT_UNCACHED_RW] = {
4346 .prot_pte = PROT_PTE_DEVICE,
4347 .prot_l1 = PMD_TYPE_TABLE,
4348 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4349 .domain = DOMAIN_IO,
4350 },
4351 - [MT_CACHECLEAN] = {
4352 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4353 + [MT_CACHECLEAN_RO] = {
4354 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4355 .domain = DOMAIN_KERNEL,
4356 },
4357 #ifndef CONFIG_ARM_LPAE
4358 - [MT_MINICLEAN] = {
4359 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4360 + [MT_MINICLEAN_RO] = {
4361 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4362 .domain = DOMAIN_KERNEL,
4363 },
4364 #endif
4365 @@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4366 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4367 L_PTE_RDONLY,
4368 .prot_l1 = PMD_TYPE_TABLE,
4369 - .domain = DOMAIN_USER,
4370 + .domain = DOMAIN_VECTORS,
4371 },
4372 [MT_HIGH_VECTORS] = {
4373 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4374 L_PTE_USER | L_PTE_RDONLY,
4375 .prot_l1 = PMD_TYPE_TABLE,
4376 - .domain = DOMAIN_USER,
4377 + .domain = DOMAIN_VECTORS,
4378 },
4379 - [MT_MEMORY_RWX] = {
4380 + [__MT_MEMORY_RWX] = {
4381 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4382 .prot_l1 = PMD_TYPE_TABLE,
4383 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4384 @@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4385 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4386 .domain = DOMAIN_KERNEL,
4387 },
4388 - [MT_ROM] = {
4389 - .prot_sect = PMD_TYPE_SECT,
4390 + [MT_MEMORY_RX] = {
4391 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4392 + .prot_l1 = PMD_TYPE_TABLE,
4393 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4394 + .domain = DOMAIN_KERNEL,
4395 + },
4396 + [MT_ROM_RX] = {
4397 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4398 .domain = DOMAIN_KERNEL,
4399 },
4400 - [MT_MEMORY_RWX_NONCACHED] = {
4401 + [MT_MEMORY_RW_NONCACHED] = {
4402 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4403 L_PTE_MT_BUFFERABLE,
4404 .prot_l1 = PMD_TYPE_TABLE,
4405 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4406 .domain = DOMAIN_KERNEL,
4407 },
4408 + [MT_MEMORY_RX_NONCACHED] = {
4409 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4410 + L_PTE_MT_BUFFERABLE,
4411 + .prot_l1 = PMD_TYPE_TABLE,
4412 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4413 + .domain = DOMAIN_KERNEL,
4414 + },
4415 [MT_MEMORY_RW_DTCM] = {
4416 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4417 L_PTE_XN,
4418 @@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4419 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4420 .domain = DOMAIN_KERNEL,
4421 },
4422 - [MT_MEMORY_RWX_ITCM] = {
4423 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4424 + [MT_MEMORY_RX_ITCM] = {
4425 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4426 .prot_l1 = PMD_TYPE_TABLE,
4427 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4428 .domain = DOMAIN_KERNEL,
4429 },
4430 [MT_MEMORY_RW_SO] = {
4431 @@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4432 * Mark cache clean areas and XIP ROM read only
4433 * from SVC mode and no access from userspace.
4434 */
4435 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4436 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4437 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4438 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4439 +#ifdef CONFIG_PAX_KERNEXEC
4440 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4441 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4442 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4443 +#endif
4444 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4445 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4446 #endif
4447
4448 if (is_smp()) {
4449 @@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4450 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4451 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4452 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4453 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4454 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4455 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4456 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4457 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4458 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4459 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4460 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4461 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4462 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4463 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4464 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4465 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4466 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4467 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4468 }
4469 }
4470
4471 @@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4472 if (cpu_arch >= CPU_ARCH_ARMv6) {
4473 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4474 /* Non-cacheable Normal is XCB = 001 */
4475 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4476 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4477 + PMD_SECT_BUFFERED;
4478 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4479 PMD_SECT_BUFFERED;
4480 } else {
4481 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4482 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4483 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4484 + PMD_SECT_TEX(1);
4485 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4486 PMD_SECT_TEX(1);
4487 }
4488 } else {
4489 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4490 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4491 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4492 }
4493
4494 #ifdef CONFIG_ARM_LPAE
4495 @@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4496 vecs_pgprot |= PTE_EXT_AF;
4497 #endif
4498
4499 + user_pgprot |= __supported_pte_mask;
4500 +
4501 for (i = 0; i < 16; i++) {
4502 pteval_t v = pgprot_val(protection_map[i]);
4503 protection_map[i] = __pgprot(v | user_pgprot);
4504 @@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4505
4506 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4507 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4508 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4509 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4510 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4511 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4512 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4513 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4514 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4515 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4516 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4517 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4518 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4519 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4520 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4521 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4522
4523 switch (cp->pmd) {
4524 case PMD_SECT_WT:
4525 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4526 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4527 break;
4528 case PMD_SECT_WB:
4529 case PMD_SECT_WBWA:
4530 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4531 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4532 break;
4533 }
4534 pr_info("Memory policy: %sData cache %s\n",
4535 @@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4536 return;
4537 }
4538
4539 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4540 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4541 md->virtual >= PAGE_OFFSET &&
4542 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4543 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4544 @@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4545 * called function. This means you can't use any function or debugging
4546 * method which may touch any device, otherwise the kernel _will_ crash.
4547 */
4548 +
4549 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4550 +
4551 static void __init devicemaps_init(const struct machine_desc *mdesc)
4552 {
4553 struct map_desc map;
4554 unsigned long addr;
4555 - void *vectors;
4556
4557 - /*
4558 - * Allocate the vector page early.
4559 - */
4560 - vectors = early_alloc(PAGE_SIZE * 2);
4561 -
4562 - early_trap_init(vectors);
4563 + early_trap_init(&vectors);
4564
4565 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4566 pmd_clear(pmd_off_k(addr));
4567 @@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4568 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4569 map.virtual = MODULES_VADDR;
4570 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4571 - map.type = MT_ROM;
4572 + map.type = MT_ROM_RX;
4573 create_mapping(&map);
4574 #endif
4575
4576 @@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4577 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4578 map.virtual = FLUSH_BASE;
4579 map.length = SZ_1M;
4580 - map.type = MT_CACHECLEAN;
4581 + map.type = MT_CACHECLEAN_RO;
4582 create_mapping(&map);
4583 #endif
4584 #ifdef FLUSH_BASE_MINICACHE
4585 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4586 map.virtual = FLUSH_BASE_MINICACHE;
4587 map.length = SZ_1M;
4588 - map.type = MT_MINICLEAN;
4589 + map.type = MT_MINICLEAN_RO;
4590 create_mapping(&map);
4591 #endif
4592
4593 @@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4594 * location (0xffff0000). If we aren't using high-vectors, also
4595 * create a mapping at the low-vectors virtual address.
4596 */
4597 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4598 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4599 map.virtual = 0xffff0000;
4600 map.length = PAGE_SIZE;
4601 #ifdef CONFIG_KUSER_HELPERS
4602 @@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4603 static void __init map_lowmem(void)
4604 {
4605 struct memblock_region *reg;
4606 +#ifndef CONFIG_PAX_KERNEXEC
4607 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4608 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4609 +#endif
4610
4611 /* Map all the lowmem memory banks. */
4612 for_each_memblock(memory, reg) {
4613 @@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4614 if (start >= end)
4615 break;
4616
4617 +#ifdef CONFIG_PAX_KERNEXEC
4618 + map.pfn = __phys_to_pfn(start);
4619 + map.virtual = __phys_to_virt(start);
4620 + map.length = end - start;
4621 +
4622 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4623 + struct map_desc kernel;
4624 + struct map_desc initmap;
4625 +
4626 + /* when freeing initmem we will make this RW */
4627 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4628 + initmap.virtual = (unsigned long)__init_begin;
4629 + initmap.length = _sdata - __init_begin;
4630 + initmap.type = __MT_MEMORY_RWX;
4631 + create_mapping(&initmap);
4632 +
4633 + /* when freeing initmem we will make this RX */
4634 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4635 + kernel.virtual = (unsigned long)_stext;
4636 + kernel.length = __init_begin - _stext;
4637 + kernel.type = __MT_MEMORY_RWX;
4638 + create_mapping(&kernel);
4639 +
4640 + if (map.virtual < (unsigned long)_stext) {
4641 + map.length = (unsigned long)_stext - map.virtual;
4642 + map.type = __MT_MEMORY_RWX;
4643 + create_mapping(&map);
4644 + }
4645 +
4646 + map.pfn = __phys_to_pfn(__pa(_sdata));
4647 + map.virtual = (unsigned long)_sdata;
4648 + map.length = end - __pa(_sdata);
4649 + }
4650 +
4651 + map.type = MT_MEMORY_RW;
4652 + create_mapping(&map);
4653 +#else
4654 if (end < kernel_x_start || start >= kernel_x_end) {
4655 map.pfn = __phys_to_pfn(start);
4656 map.virtual = __phys_to_virt(start);
4657 map.length = end - start;
4658 - map.type = MT_MEMORY_RWX;
4659 + map.type = __MT_MEMORY_RWX;
4660
4661 create_mapping(&map);
4662 } else {
4663 @@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4664 map.pfn = __phys_to_pfn(kernel_x_start);
4665 map.virtual = __phys_to_virt(kernel_x_start);
4666 map.length = kernel_x_end - kernel_x_start;
4667 - map.type = MT_MEMORY_RWX;
4668 + map.type = __MT_MEMORY_RWX;
4669
4670 create_mapping(&map);
4671
4672 @@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4673 create_mapping(&map);
4674 }
4675 }
4676 +#endif
4677 }
4678 }
4679
4680 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4681 index 5b217f4..c23f40e 100644
4682 --- a/arch/arm/plat-iop/setup.c
4683 +++ b/arch/arm/plat-iop/setup.c
4684 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4685 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4686 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4687 .length = IOP3XX_PERIPHERAL_SIZE,
4688 - .type = MT_UNCACHED,
4689 + .type = MT_UNCACHED_RW,
4690 },
4691 };
4692
4693 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4694 index a5bc92d..0bb4730 100644
4695 --- a/arch/arm/plat-omap/sram.c
4696 +++ b/arch/arm/plat-omap/sram.c
4697 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4698 * Looks like we need to preserve some bootloader code at the
4699 * beginning of SRAM for jumping to flash for reboot to work...
4700 */
4701 + pax_open_kernel();
4702 memset_io(omap_sram_base + omap_sram_skip, 0,
4703 omap_sram_size - omap_sram_skip);
4704 + pax_close_kernel();
4705 }
4706 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4707 index ce6d763..cfea917 100644
4708 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4709 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4710 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4711 int (*started)(unsigned ch);
4712 int (*flush)(unsigned ch);
4713 int (*stop)(unsigned ch);
4714 -};
4715 +} __no_const;
4716
4717 extern void *samsung_dmadev_get_ops(void);
4718 extern void *s3c_dma_get_ops(void);
4719 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4720 index 6c0f684..5faea9d 100644
4721 --- a/arch/arm64/include/asm/uaccess.h
4722 +++ b/arch/arm64/include/asm/uaccess.h
4723 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4724 flag; \
4725 })
4726
4727 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4728 #define access_ok(type, addr, size) __range_ok(addr, size)
4729 #define user_addr_max get_fs
4730
4731 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4732 index c3a58a1..78fbf54 100644
4733 --- a/arch/avr32/include/asm/cache.h
4734 +++ b/arch/avr32/include/asm/cache.h
4735 @@ -1,8 +1,10 @@
4736 #ifndef __ASM_AVR32_CACHE_H
4737 #define __ASM_AVR32_CACHE_H
4738
4739 +#include <linux/const.h>
4740 +
4741 #define L1_CACHE_SHIFT 5
4742 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4743 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4744
4745 /*
4746 * Memory returned by kmalloc() may be used for DMA, so we must make
4747 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4748 index d232888..87c8df1 100644
4749 --- a/arch/avr32/include/asm/elf.h
4750 +++ b/arch/avr32/include/asm/elf.h
4751 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4752 the loader. We need to make sure that it is out of the way of the program
4753 that it will "exec", and that there is sufficient room for the brk. */
4754
4755 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4756 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4757
4758 +#ifdef CONFIG_PAX_ASLR
4759 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4760 +
4761 +#define PAX_DELTA_MMAP_LEN 15
4762 +#define PAX_DELTA_STACK_LEN 15
4763 +#endif
4764
4765 /* This yields a mask that user programs can use to figure out what
4766 instruction set this CPU supports. This could be done in user space,
4767 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4768 index 479330b..53717a8 100644
4769 --- a/arch/avr32/include/asm/kmap_types.h
4770 +++ b/arch/avr32/include/asm/kmap_types.h
4771 @@ -2,9 +2,9 @@
4772 #define __ASM_AVR32_KMAP_TYPES_H
4773
4774 #ifdef CONFIG_DEBUG_HIGHMEM
4775 -# define KM_TYPE_NR 29
4776 +# define KM_TYPE_NR 30
4777 #else
4778 -# define KM_TYPE_NR 14
4779 +# define KM_TYPE_NR 15
4780 #endif
4781
4782 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4783 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4784 index 0eca933..eb78c7b 100644
4785 --- a/arch/avr32/mm/fault.c
4786 +++ b/arch/avr32/mm/fault.c
4787 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4788
4789 int exception_trace = 1;
4790
4791 +#ifdef CONFIG_PAX_PAGEEXEC
4792 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4793 +{
4794 + unsigned long i;
4795 +
4796 + printk(KERN_ERR "PAX: bytes at PC: ");
4797 + for (i = 0; i < 20; i++) {
4798 + unsigned char c;
4799 + if (get_user(c, (unsigned char *)pc+i))
4800 + printk(KERN_CONT "???????? ");
4801 + else
4802 + printk(KERN_CONT "%02x ", c);
4803 + }
4804 + printk("\n");
4805 +}
4806 +#endif
4807 +
4808 /*
4809 * This routine handles page faults. It determines the address and the
4810 * problem, and then passes it off to one of the appropriate routines.
4811 @@ -176,6 +193,16 @@ bad_area:
4812 up_read(&mm->mmap_sem);
4813
4814 if (user_mode(regs)) {
4815 +
4816 +#ifdef CONFIG_PAX_PAGEEXEC
4817 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4818 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4819 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4820 + do_group_exit(SIGKILL);
4821 + }
4822 + }
4823 +#endif
4824 +
4825 if (exception_trace && printk_ratelimit())
4826 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4827 "sp %08lx ecr %lu\n",
4828 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4829 index 568885a..f8008df 100644
4830 --- a/arch/blackfin/include/asm/cache.h
4831 +++ b/arch/blackfin/include/asm/cache.h
4832 @@ -7,6 +7,7 @@
4833 #ifndef __ARCH_BLACKFIN_CACHE_H
4834 #define __ARCH_BLACKFIN_CACHE_H
4835
4836 +#include <linux/const.h>
4837 #include <linux/linkage.h> /* for asmlinkage */
4838
4839 /*
4840 @@ -14,7 +15,7 @@
4841 * Blackfin loads 32 bytes for cache
4842 */
4843 #define L1_CACHE_SHIFT 5
4844 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4845 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4846 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4847
4848 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4849 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4850 index aea2718..3639a60 100644
4851 --- a/arch/cris/include/arch-v10/arch/cache.h
4852 +++ b/arch/cris/include/arch-v10/arch/cache.h
4853 @@ -1,8 +1,9 @@
4854 #ifndef _ASM_ARCH_CACHE_H
4855 #define _ASM_ARCH_CACHE_H
4856
4857 +#include <linux/const.h>
4858 /* Etrax 100LX have 32-byte cache-lines. */
4859 -#define L1_CACHE_BYTES 32
4860 #define L1_CACHE_SHIFT 5
4861 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4862
4863 #endif /* _ASM_ARCH_CACHE_H */
4864 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4865 index 7caf25d..ee65ac5 100644
4866 --- a/arch/cris/include/arch-v32/arch/cache.h
4867 +++ b/arch/cris/include/arch-v32/arch/cache.h
4868 @@ -1,11 +1,12 @@
4869 #ifndef _ASM_CRIS_ARCH_CACHE_H
4870 #define _ASM_CRIS_ARCH_CACHE_H
4871
4872 +#include <linux/const.h>
4873 #include <arch/hwregs/dma.h>
4874
4875 /* A cache-line is 32 bytes. */
4876 -#define L1_CACHE_BYTES 32
4877 #define L1_CACHE_SHIFT 5
4878 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4879
4880 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4881
4882 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4883 index b86329d..6709906 100644
4884 --- a/arch/frv/include/asm/atomic.h
4885 +++ b/arch/frv/include/asm/atomic.h
4886 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4887 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4888 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4889
4890 +#define atomic64_read_unchecked(v) atomic64_read(v)
4891 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4892 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4893 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4894 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4895 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4896 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4897 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4898 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4899 +
4900 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4901 {
4902 int c, old;
4903 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4904 index 2797163..c2a401d 100644
4905 --- a/arch/frv/include/asm/cache.h
4906 +++ b/arch/frv/include/asm/cache.h
4907 @@ -12,10 +12,11 @@
4908 #ifndef __ASM_CACHE_H
4909 #define __ASM_CACHE_H
4910
4911 +#include <linux/const.h>
4912
4913 /* bytes per L1 cache line */
4914 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4915 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4916 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4917
4918 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4919 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4920 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4921 index 43901f2..0d8b865 100644
4922 --- a/arch/frv/include/asm/kmap_types.h
4923 +++ b/arch/frv/include/asm/kmap_types.h
4924 @@ -2,6 +2,6 @@
4925 #ifndef _ASM_KMAP_TYPES_H
4926 #define _ASM_KMAP_TYPES_H
4927
4928 -#define KM_TYPE_NR 17
4929 +#define KM_TYPE_NR 18
4930
4931 #endif
4932 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4933 index 836f147..4cf23f5 100644
4934 --- a/arch/frv/mm/elf-fdpic.c
4935 +++ b/arch/frv/mm/elf-fdpic.c
4936 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4937 {
4938 struct vm_area_struct *vma;
4939 struct vm_unmapped_area_info info;
4940 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4941
4942 if (len > TASK_SIZE)
4943 return -ENOMEM;
4944 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4945 if (addr) {
4946 addr = PAGE_ALIGN(addr);
4947 vma = find_vma(current->mm, addr);
4948 - if (TASK_SIZE - len >= addr &&
4949 - (!vma || addr + len <= vma->vm_start))
4950 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4951 goto success;
4952 }
4953
4954 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4955 info.high_limit = (current->mm->start_stack - 0x00200000);
4956 info.align_mask = 0;
4957 info.align_offset = 0;
4958 + info.threadstack_offset = offset;
4959 addr = vm_unmapped_area(&info);
4960 if (!(addr & ~PAGE_MASK))
4961 goto success;
4962 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4963 index f4ca594..adc72fd6 100644
4964 --- a/arch/hexagon/include/asm/cache.h
4965 +++ b/arch/hexagon/include/asm/cache.h
4966 @@ -21,9 +21,11 @@
4967 #ifndef __ASM_CACHE_H
4968 #define __ASM_CACHE_H
4969
4970 +#include <linux/const.h>
4971 +
4972 /* Bytes per L1 cache line */
4973 -#define L1_CACHE_SHIFT (5)
4974 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4975 +#define L1_CACHE_SHIFT 5
4976 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4977
4978 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4979 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4980 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4981 index 0c8e553..112d734 100644
4982 --- a/arch/ia64/Kconfig
4983 +++ b/arch/ia64/Kconfig
4984 @@ -544,6 +544,7 @@ source "drivers/sn/Kconfig"
4985 config KEXEC
4986 bool "kexec system call"
4987 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4988 + depends on !GRKERNSEC_KMEM
4989 help
4990 kexec is a system call that implements the ability to shutdown your
4991 current kernel, and to start another kernel. It is like a reboot
4992 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4993 index 6e6fe18..a6ae668 100644
4994 --- a/arch/ia64/include/asm/atomic.h
4995 +++ b/arch/ia64/include/asm/atomic.h
4996 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4997 #define atomic64_inc(v) atomic64_add(1, (v))
4998 #define atomic64_dec(v) atomic64_sub(1, (v))
4999
5000 +#define atomic64_read_unchecked(v) atomic64_read(v)
5001 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5002 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5003 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5004 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5005 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5006 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5007 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5008 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5009 +
5010 /* Atomic operations are already serializing */
5011 #define smp_mb__before_atomic_dec() barrier()
5012 #define smp_mb__after_atomic_dec() barrier()
5013 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5014 index 988254a..e1ee885 100644
5015 --- a/arch/ia64/include/asm/cache.h
5016 +++ b/arch/ia64/include/asm/cache.h
5017 @@ -1,6 +1,7 @@
5018 #ifndef _ASM_IA64_CACHE_H
5019 #define _ASM_IA64_CACHE_H
5020
5021 +#include <linux/const.h>
5022
5023 /*
5024 * Copyright (C) 1998-2000 Hewlett-Packard Co
5025 @@ -9,7 +10,7 @@
5026
5027 /* Bytes per L1 (data) cache line. */
5028 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5029 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5030 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5031
5032 #ifdef CONFIG_SMP
5033 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5034 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5035 index 5a83c5c..4d7f553 100644
5036 --- a/arch/ia64/include/asm/elf.h
5037 +++ b/arch/ia64/include/asm/elf.h
5038 @@ -42,6 +42,13 @@
5039 */
5040 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5041
5042 +#ifdef CONFIG_PAX_ASLR
5043 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5044 +
5045 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5046 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5047 +#endif
5048 +
5049 #define PT_IA_64_UNWIND 0x70000001
5050
5051 /* IA-64 relocations: */
5052 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5053 index 5767cdf..7462574 100644
5054 --- a/arch/ia64/include/asm/pgalloc.h
5055 +++ b/arch/ia64/include/asm/pgalloc.h
5056 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5057 pgd_val(*pgd_entry) = __pa(pud);
5058 }
5059
5060 +static inline void
5061 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5062 +{
5063 + pgd_populate(mm, pgd_entry, pud);
5064 +}
5065 +
5066 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5067 {
5068 return quicklist_alloc(0, GFP_KERNEL, NULL);
5069 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5070 pud_val(*pud_entry) = __pa(pmd);
5071 }
5072
5073 +static inline void
5074 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5075 +{
5076 + pud_populate(mm, pud_entry, pmd);
5077 +}
5078 +
5079 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5080 {
5081 return quicklist_alloc(0, GFP_KERNEL, NULL);
5082 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5083 index 7935115..c0eca6a 100644
5084 --- a/arch/ia64/include/asm/pgtable.h
5085 +++ b/arch/ia64/include/asm/pgtable.h
5086 @@ -12,7 +12,7 @@
5087 * David Mosberger-Tang <davidm@hpl.hp.com>
5088 */
5089
5090 -
5091 +#include <linux/const.h>
5092 #include <asm/mman.h>
5093 #include <asm/page.h>
5094 #include <asm/processor.h>
5095 @@ -142,6 +142,17 @@
5096 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5097 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5098 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5099 +
5100 +#ifdef CONFIG_PAX_PAGEEXEC
5101 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5102 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5103 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5104 +#else
5105 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5106 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5107 +# define PAGE_COPY_NOEXEC PAGE_COPY
5108 +#endif
5109 +
5110 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5111 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5112 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5113 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5114 index 45698cd..e8e2dbc 100644
5115 --- a/arch/ia64/include/asm/spinlock.h
5116 +++ b/arch/ia64/include/asm/spinlock.h
5117 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5118 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5119
5120 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5121 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5122 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5123 }
5124
5125 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5126 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5127 index 449c8c0..3d4b1e9 100644
5128 --- a/arch/ia64/include/asm/uaccess.h
5129 +++ b/arch/ia64/include/asm/uaccess.h
5130 @@ -70,6 +70,7 @@
5131 && ((segment).seg == KERNEL_DS.seg \
5132 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5133 })
5134 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5135 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5136
5137 /*
5138 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5139 static inline unsigned long
5140 __copy_to_user (void __user *to, const void *from, unsigned long count)
5141 {
5142 + if (count > INT_MAX)
5143 + return count;
5144 +
5145 + if (!__builtin_constant_p(count))
5146 + check_object_size(from, count, true);
5147 +
5148 return __copy_user(to, (__force void __user *) from, count);
5149 }
5150
5151 static inline unsigned long
5152 __copy_from_user (void *to, const void __user *from, unsigned long count)
5153 {
5154 + if (count > INT_MAX)
5155 + return count;
5156 +
5157 + if (!__builtin_constant_p(count))
5158 + check_object_size(to, count, false);
5159 +
5160 return __copy_user((__force void __user *) to, from, count);
5161 }
5162
5163 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5164 ({ \
5165 void __user *__cu_to = (to); \
5166 const void *__cu_from = (from); \
5167 - long __cu_len = (n); \
5168 + unsigned long __cu_len = (n); \
5169 \
5170 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5171 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5172 + if (!__builtin_constant_p(n)) \
5173 + check_object_size(__cu_from, __cu_len, true); \
5174 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5175 + } \
5176 __cu_len; \
5177 })
5178
5179 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5180 ({ \
5181 void *__cu_to = (to); \
5182 const void __user *__cu_from = (from); \
5183 - long __cu_len = (n); \
5184 + unsigned long __cu_len = (n); \
5185 \
5186 __chk_user_ptr(__cu_from); \
5187 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5188 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5189 + if (!__builtin_constant_p(n)) \
5190 + check_object_size(__cu_to, __cu_len, false); \
5191 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5192 + } \
5193 __cu_len; \
5194 })
5195
5196 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5197 index 24603be..948052d 100644
5198 --- a/arch/ia64/kernel/module.c
5199 +++ b/arch/ia64/kernel/module.c
5200 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5201 void
5202 module_free (struct module *mod, void *module_region)
5203 {
5204 - if (mod && mod->arch.init_unw_table &&
5205 - module_region == mod->module_init) {
5206 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5207 unw_remove_unwind_table(mod->arch.init_unw_table);
5208 mod->arch.init_unw_table = NULL;
5209 }
5210 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5211 }
5212
5213 static inline int
5214 +in_init_rx (const struct module *mod, uint64_t addr)
5215 +{
5216 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5217 +}
5218 +
5219 +static inline int
5220 +in_init_rw (const struct module *mod, uint64_t addr)
5221 +{
5222 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5223 +}
5224 +
5225 +static inline int
5226 in_init (const struct module *mod, uint64_t addr)
5227 {
5228 - return addr - (uint64_t) mod->module_init < mod->init_size;
5229 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5230 +}
5231 +
5232 +static inline int
5233 +in_core_rx (const struct module *mod, uint64_t addr)
5234 +{
5235 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5236 +}
5237 +
5238 +static inline int
5239 +in_core_rw (const struct module *mod, uint64_t addr)
5240 +{
5241 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5242 }
5243
5244 static inline int
5245 in_core (const struct module *mod, uint64_t addr)
5246 {
5247 - return addr - (uint64_t) mod->module_core < mod->core_size;
5248 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5249 }
5250
5251 static inline int
5252 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5253 break;
5254
5255 case RV_BDREL:
5256 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5257 + if (in_init_rx(mod, val))
5258 + val -= (uint64_t) mod->module_init_rx;
5259 + else if (in_init_rw(mod, val))
5260 + val -= (uint64_t) mod->module_init_rw;
5261 + else if (in_core_rx(mod, val))
5262 + val -= (uint64_t) mod->module_core_rx;
5263 + else if (in_core_rw(mod, val))
5264 + val -= (uint64_t) mod->module_core_rw;
5265 break;
5266
5267 case RV_LTV:
5268 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5269 * addresses have been selected...
5270 */
5271 uint64_t gp;
5272 - if (mod->core_size > MAX_LTOFF)
5273 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5274 /*
5275 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5276 * at the end of the module.
5277 */
5278 - gp = mod->core_size - MAX_LTOFF / 2;
5279 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5280 else
5281 - gp = mod->core_size / 2;
5282 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5283 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5284 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5285 mod->arch.gp = gp;
5286 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5287 }
5288 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5289 index ab33328..f39506c 100644
5290 --- a/arch/ia64/kernel/palinfo.c
5291 +++ b/arch/ia64/kernel/palinfo.c
5292 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5293 return NOTIFY_OK;
5294 }
5295
5296 -static struct notifier_block __refdata palinfo_cpu_notifier =
5297 +static struct notifier_block palinfo_cpu_notifier =
5298 {
5299 .notifier_call = palinfo_cpu_callback,
5300 .priority = 0,
5301 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5302 index 41e33f8..65180b2a 100644
5303 --- a/arch/ia64/kernel/sys_ia64.c
5304 +++ b/arch/ia64/kernel/sys_ia64.c
5305 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5306 unsigned long align_mask = 0;
5307 struct mm_struct *mm = current->mm;
5308 struct vm_unmapped_area_info info;
5309 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5310
5311 if (len > RGN_MAP_LIMIT)
5312 return -ENOMEM;
5313 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5314 if (REGION_NUMBER(addr) == RGN_HPAGE)
5315 addr = 0;
5316 #endif
5317 +
5318 +#ifdef CONFIG_PAX_RANDMMAP
5319 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5320 + addr = mm->free_area_cache;
5321 + else
5322 +#endif
5323 +
5324 if (!addr)
5325 addr = TASK_UNMAPPED_BASE;
5326
5327 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5328 info.high_limit = TASK_SIZE;
5329 info.align_mask = align_mask;
5330 info.align_offset = 0;
5331 + info.threadstack_offset = offset;
5332 return vm_unmapped_area(&info);
5333 }
5334
5335 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5336 index 84f8a52..7c76178 100644
5337 --- a/arch/ia64/kernel/vmlinux.lds.S
5338 +++ b/arch/ia64/kernel/vmlinux.lds.S
5339 @@ -192,7 +192,7 @@ SECTIONS {
5340 /* Per-cpu data: */
5341 . = ALIGN(PERCPU_PAGE_SIZE);
5342 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5343 - __phys_per_cpu_start = __per_cpu_load;
5344 + __phys_per_cpu_start = per_cpu_load;
5345 /*
5346 * ensure percpu data fits
5347 * into percpu page size
5348 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5349 index 7225dad..2a7c8256 100644
5350 --- a/arch/ia64/mm/fault.c
5351 +++ b/arch/ia64/mm/fault.c
5352 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5353 return pte_present(pte);
5354 }
5355
5356 +#ifdef CONFIG_PAX_PAGEEXEC
5357 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5358 +{
5359 + unsigned long i;
5360 +
5361 + printk(KERN_ERR "PAX: bytes at PC: ");
5362 + for (i = 0; i < 8; i++) {
5363 + unsigned int c;
5364 + if (get_user(c, (unsigned int *)pc+i))
5365 + printk(KERN_CONT "???????? ");
5366 + else
5367 + printk(KERN_CONT "%08x ", c);
5368 + }
5369 + printk("\n");
5370 +}
5371 +#endif
5372 +
5373 # define VM_READ_BIT 0
5374 # define VM_WRITE_BIT 1
5375 # define VM_EXEC_BIT 2
5376 @@ -151,8 +168,21 @@ retry:
5377 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5378 goto bad_area;
5379
5380 - if ((vma->vm_flags & mask) != mask)
5381 + if ((vma->vm_flags & mask) != mask) {
5382 +
5383 +#ifdef CONFIG_PAX_PAGEEXEC
5384 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5385 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5386 + goto bad_area;
5387 +
5388 + up_read(&mm->mmap_sem);
5389 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5390 + do_group_exit(SIGKILL);
5391 + }
5392 +#endif
5393 +
5394 goto bad_area;
5395 + }
5396
5397 /*
5398 * If for any reason at all we couldn't handle the fault, make
5399 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5400 index 68232db..6ca80af 100644
5401 --- a/arch/ia64/mm/hugetlbpage.c
5402 +++ b/arch/ia64/mm/hugetlbpage.c
5403 @@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5404 unsigned long pgoff, unsigned long flags)
5405 {
5406 struct vm_unmapped_area_info info;
5407 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5408
5409 if (len > RGN_MAP_LIMIT)
5410 return -ENOMEM;
5411 @@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5412 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5413 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5414 info.align_offset = 0;
5415 + info.threadstack_offset = offset;
5416 return vm_unmapped_area(&info);
5417 }
5418
5419 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5420 index 25c3502..560dae7 100644
5421 --- a/arch/ia64/mm/init.c
5422 +++ b/arch/ia64/mm/init.c
5423 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5424 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5425 vma->vm_end = vma->vm_start + PAGE_SIZE;
5426 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5427 +
5428 +#ifdef CONFIG_PAX_PAGEEXEC
5429 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5430 + vma->vm_flags &= ~VM_EXEC;
5431 +
5432 +#ifdef CONFIG_PAX_MPROTECT
5433 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5434 + vma->vm_flags &= ~VM_MAYEXEC;
5435 +#endif
5436 +
5437 + }
5438 +#endif
5439 +
5440 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5441 down_write(&current->mm->mmap_sem);
5442 if (insert_vm_struct(current->mm, vma)) {
5443 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5444 index 40b3ee9..8c2c112 100644
5445 --- a/arch/m32r/include/asm/cache.h
5446 +++ b/arch/m32r/include/asm/cache.h
5447 @@ -1,8 +1,10 @@
5448 #ifndef _ASM_M32R_CACHE_H
5449 #define _ASM_M32R_CACHE_H
5450
5451 +#include <linux/const.h>
5452 +
5453 /* L1 cache line size */
5454 #define L1_CACHE_SHIFT 4
5455 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5456 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5457
5458 #endif /* _ASM_M32R_CACHE_H */
5459 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5460 index 82abd15..d95ae5d 100644
5461 --- a/arch/m32r/lib/usercopy.c
5462 +++ b/arch/m32r/lib/usercopy.c
5463 @@ -14,6 +14,9 @@
5464 unsigned long
5465 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5466 {
5467 + if ((long)n < 0)
5468 + return n;
5469 +
5470 prefetch(from);
5471 if (access_ok(VERIFY_WRITE, to, n))
5472 __copy_user(to,from,n);
5473 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5474 unsigned long
5475 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5476 {
5477 + if ((long)n < 0)
5478 + return n;
5479 +
5480 prefetchw(to);
5481 if (access_ok(VERIFY_READ, from, n))
5482 __copy_user_zeroing(to,from,n);
5483 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5484 index 0395c51..5f26031 100644
5485 --- a/arch/m68k/include/asm/cache.h
5486 +++ b/arch/m68k/include/asm/cache.h
5487 @@ -4,9 +4,11 @@
5488 #ifndef __ARCH_M68K_CACHE_H
5489 #define __ARCH_M68K_CACHE_H
5490
5491 +#include <linux/const.h>
5492 +
5493 /* bytes per L1 cache line */
5494 #define L1_CACHE_SHIFT 4
5495 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5496 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5497
5498 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5499
5500 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5501 index 0424315..defcca9 100644
5502 --- a/arch/metag/mm/hugetlbpage.c
5503 +++ b/arch/metag/mm/hugetlbpage.c
5504 @@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5505 info.high_limit = TASK_SIZE;
5506 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5507 info.align_offset = 0;
5508 + info.threadstack_offset = 0;
5509 return vm_unmapped_area(&info);
5510 }
5511
5512 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5513 index 4efe96a..60e8699 100644
5514 --- a/arch/microblaze/include/asm/cache.h
5515 +++ b/arch/microblaze/include/asm/cache.h
5516 @@ -13,11 +13,12 @@
5517 #ifndef _ASM_MICROBLAZE_CACHE_H
5518 #define _ASM_MICROBLAZE_CACHE_H
5519
5520 +#include <linux/const.h>
5521 #include <asm/registers.h>
5522
5523 #define L1_CACHE_SHIFT 5
5524 /* word-granular cache in microblaze */
5525 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5526 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5527
5528 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5529
5530 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5531 index 95fa1f1..56a6fa2 100644
5532 --- a/arch/mips/Kconfig
5533 +++ b/arch/mips/Kconfig
5534 @@ -2298,6 +2298,7 @@ source "kernel/Kconfig.preempt"
5535
5536 config KEXEC
5537 bool "Kexec system call"
5538 + depends on !GRKERNSEC_KMEM
5539 help
5540 kexec is a system call that implements the ability to shutdown your
5541 current kernel, and to start another kernel. It is like a reboot
5542 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5543 index 02f2444..506969c 100644
5544 --- a/arch/mips/cavium-octeon/dma-octeon.c
5545 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5546 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5547 if (dma_release_from_coherent(dev, order, vaddr))
5548 return;
5549
5550 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5551 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5552 }
5553
5554 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5555 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5556 index 7eed2f2..c4e385d 100644
5557 --- a/arch/mips/include/asm/atomic.h
5558 +++ b/arch/mips/include/asm/atomic.h
5559 @@ -21,15 +21,39 @@
5560 #include <asm/cmpxchg.h>
5561 #include <asm/war.h>
5562
5563 +#ifdef CONFIG_GENERIC_ATOMIC64
5564 +#include <asm-generic/atomic64.h>
5565 +#endif
5566 +
5567 #define ATOMIC_INIT(i) { (i) }
5568
5569 +#ifdef CONFIG_64BIT
5570 +#define _ASM_EXTABLE(from, to) \
5571 +" .section __ex_table,\"a\"\n" \
5572 +" .dword " #from ", " #to"\n" \
5573 +" .previous\n"
5574 +#else
5575 +#define _ASM_EXTABLE(from, to) \
5576 +" .section __ex_table,\"a\"\n" \
5577 +" .word " #from ", " #to"\n" \
5578 +" .previous\n"
5579 +#endif
5580 +
5581 /*
5582 * atomic_read - read atomic variable
5583 * @v: pointer of type atomic_t
5584 *
5585 * Atomically reads the value of @v.
5586 */
5587 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5588 +static inline int atomic_read(const atomic_t *v)
5589 +{
5590 + return (*(volatile const int *) &v->counter);
5591 +}
5592 +
5593 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5594 +{
5595 + return (*(volatile const int *) &v->counter);
5596 +}
5597
5598 /*
5599 * atomic_set - set atomic variable
5600 @@ -38,7 +62,15 @@
5601 *
5602 * Atomically sets the value of @v to @i.
5603 */
5604 -#define atomic_set(v, i) ((v)->counter = (i))
5605 +static inline void atomic_set(atomic_t *v, int i)
5606 +{
5607 + v->counter = i;
5608 +}
5609 +
5610 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5611 +{
5612 + v->counter = i;
5613 +}
5614
5615 /*
5616 * atomic_add - add integer to atomic variable
5617 @@ -47,7 +79,67 @@
5618 *
5619 * Atomically adds @i to @v.
5620 */
5621 -static __inline__ void atomic_add(int i, atomic_t * v)
5622 +static __inline__ void atomic_add(int i, atomic_t *v)
5623 +{
5624 + int temp;
5625 +
5626 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5627 + __asm__ __volatile__(
5628 + " .set mips3 \n"
5629 + "1: ll %0, %1 # atomic_add \n"
5630 +#ifdef CONFIG_PAX_REFCOUNT
5631 + /* Exception on overflow. */
5632 + "2: add %0, %2 \n"
5633 +#else
5634 + " addu %0, %2 \n"
5635 +#endif
5636 + " sc %0, %1 \n"
5637 + " beqzl %0, 1b \n"
5638 +#ifdef CONFIG_PAX_REFCOUNT
5639 + "3: \n"
5640 + _ASM_EXTABLE(2b, 3b)
5641 +#endif
5642 + " .set mips0 \n"
5643 + : "=&r" (temp), "+m" (v->counter)
5644 + : "Ir" (i));
5645 + } else if (kernel_uses_llsc) {
5646 + __asm__ __volatile__(
5647 + " .set mips3 \n"
5648 + "1: ll %0, %1 # atomic_add \n"
5649 +#ifdef CONFIG_PAX_REFCOUNT
5650 + /* Exception on overflow. */
5651 + "2: add %0, %2 \n"
5652 +#else
5653 + " addu %0, %2 \n"
5654 +#endif
5655 + " sc %0, %1 \n"
5656 + " beqz %0, 1b \n"
5657 +#ifdef CONFIG_PAX_REFCOUNT
5658 + "3: \n"
5659 + _ASM_EXTABLE(2b, 3b)
5660 +#endif
5661 + " .set mips0 \n"
5662 + : "=&r" (temp), "+m" (v->counter)
5663 + : "Ir" (i));
5664 + } else {
5665 + unsigned long flags;
5666 +
5667 + raw_local_irq_save(flags);
5668 + __asm__ __volatile__(
5669 +#ifdef CONFIG_PAX_REFCOUNT
5670 + /* Exception on overflow. */
5671 + "1: add %0, %1 \n"
5672 + "2: \n"
5673 + _ASM_EXTABLE(1b, 2b)
5674 +#else
5675 + " addu %0, %1 \n"
5676 +#endif
5677 + : "+r" (v->counter) : "Ir" (i));
5678 + raw_local_irq_restore(flags);
5679 + }
5680 +}
5681 +
5682 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5683 {
5684 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5685 int temp;
5686 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5687 *
5688 * Atomically subtracts @i from @v.
5689 */
5690 -static __inline__ void atomic_sub(int i, atomic_t * v)
5691 +static __inline__ void atomic_sub(int i, atomic_t *v)
5692 +{
5693 + int temp;
5694 +
5695 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5696 + __asm__ __volatile__(
5697 + " .set mips3 \n"
5698 + "1: ll %0, %1 # atomic64_sub \n"
5699 +#ifdef CONFIG_PAX_REFCOUNT
5700 + /* Exception on overflow. */
5701 + "2: sub %0, %2 \n"
5702 +#else
5703 + " subu %0, %2 \n"
5704 +#endif
5705 + " sc %0, %1 \n"
5706 + " beqzl %0, 1b \n"
5707 +#ifdef CONFIG_PAX_REFCOUNT
5708 + "3: \n"
5709 + _ASM_EXTABLE(2b, 3b)
5710 +#endif
5711 + " .set mips0 \n"
5712 + : "=&r" (temp), "+m" (v->counter)
5713 + : "Ir" (i));
5714 + } else if (kernel_uses_llsc) {
5715 + __asm__ __volatile__(
5716 + " .set mips3 \n"
5717 + "1: ll %0, %1 # atomic64_sub \n"
5718 +#ifdef CONFIG_PAX_REFCOUNT
5719 + /* Exception on overflow. */
5720 + "2: sub %0, %2 \n"
5721 +#else
5722 + " subu %0, %2 \n"
5723 +#endif
5724 + " sc %0, %1 \n"
5725 + " beqz %0, 1b \n"
5726 +#ifdef CONFIG_PAX_REFCOUNT
5727 + "3: \n"
5728 + _ASM_EXTABLE(2b, 3b)
5729 +#endif
5730 + " .set mips0 \n"
5731 + : "=&r" (temp), "+m" (v->counter)
5732 + : "Ir" (i));
5733 + } else {
5734 + unsigned long flags;
5735 +
5736 + raw_local_irq_save(flags);
5737 + __asm__ __volatile__(
5738 +#ifdef CONFIG_PAX_REFCOUNT
5739 + /* Exception on overflow. */
5740 + "1: sub %0, %1 \n"
5741 + "2: \n"
5742 + _ASM_EXTABLE(1b, 2b)
5743 +#else
5744 + " subu %0, %1 \n"
5745 +#endif
5746 + : "+r" (v->counter) : "Ir" (i));
5747 + raw_local_irq_restore(flags);
5748 + }
5749 +}
5750 +
5751 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5752 {
5753 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5754 int temp;
5755 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5756 /*
5757 * Same as above, but return the result value
5758 */
5759 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5760 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5761 +{
5762 + int result;
5763 + int temp;
5764 +
5765 + smp_mb__before_llsc();
5766 +
5767 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5768 + __asm__ __volatile__(
5769 + " .set mips3 \n"
5770 + "1: ll %1, %2 # atomic_add_return \n"
5771 +#ifdef CONFIG_PAX_REFCOUNT
5772 + "2: add %0, %1, %3 \n"
5773 +#else
5774 + " addu %0, %1, %3 \n"
5775 +#endif
5776 + " sc %0, %2 \n"
5777 + " beqzl %0, 1b \n"
5778 +#ifdef CONFIG_PAX_REFCOUNT
5779 + " b 4f \n"
5780 + " .set noreorder \n"
5781 + "3: b 5f \n"
5782 + " move %0, %1 \n"
5783 + " .set reorder \n"
5784 + _ASM_EXTABLE(2b, 3b)
5785 +#endif
5786 + "4: addu %0, %1, %3 \n"
5787 +#ifdef CONFIG_PAX_REFCOUNT
5788 + "5: \n"
5789 +#endif
5790 + " .set mips0 \n"
5791 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5792 + : "Ir" (i));
5793 + } else if (kernel_uses_llsc) {
5794 + __asm__ __volatile__(
5795 + " .set mips3 \n"
5796 + "1: ll %1, %2 # atomic_add_return \n"
5797 +#ifdef CONFIG_PAX_REFCOUNT
5798 + "2: add %0, %1, %3 \n"
5799 +#else
5800 + " addu %0, %1, %3 \n"
5801 +#endif
5802 + " sc %0, %2 \n"
5803 + " bnez %0, 4f \n"
5804 + " b 1b \n"
5805 +#ifdef CONFIG_PAX_REFCOUNT
5806 + " .set noreorder \n"
5807 + "3: b 5f \n"
5808 + " move %0, %1 \n"
5809 + " .set reorder \n"
5810 + _ASM_EXTABLE(2b, 3b)
5811 +#endif
5812 + "4: addu %0, %1, %3 \n"
5813 +#ifdef CONFIG_PAX_REFCOUNT
5814 + "5: \n"
5815 +#endif
5816 + " .set mips0 \n"
5817 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5818 + : "Ir" (i));
5819 + } else {
5820 + unsigned long flags;
5821 +
5822 + raw_local_irq_save(flags);
5823 + __asm__ __volatile__(
5824 + " lw %0, %1 \n"
5825 +#ifdef CONFIG_PAX_REFCOUNT
5826 + /* Exception on overflow. */
5827 + "1: add %0, %2 \n"
5828 +#else
5829 + " addu %0, %2 \n"
5830 +#endif
5831 + " sw %0, %1 \n"
5832 +#ifdef CONFIG_PAX_REFCOUNT
5833 + /* Note: Dest reg is not modified on overflow */
5834 + "2: \n"
5835 + _ASM_EXTABLE(1b, 2b)
5836 +#endif
5837 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5838 + raw_local_irq_restore(flags);
5839 + }
5840 +
5841 + smp_llsc_mb();
5842 +
5843 + return result;
5844 +}
5845 +
5846 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5847 {
5848 int result;
5849
5850 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5851 return result;
5852 }
5853
5854 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5855 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5856 +{
5857 + int result;
5858 + int temp;
5859 +
5860 + smp_mb__before_llsc();
5861 +
5862 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5863 + __asm__ __volatile__(
5864 + " .set mips3 \n"
5865 + "1: ll %1, %2 # atomic_sub_return \n"
5866 +#ifdef CONFIG_PAX_REFCOUNT
5867 + "2: sub %0, %1, %3 \n"
5868 +#else
5869 + " subu %0, %1, %3 \n"
5870 +#endif
5871 + " sc %0, %2 \n"
5872 + " beqzl %0, 1b \n"
5873 +#ifdef CONFIG_PAX_REFCOUNT
5874 + " b 4f \n"
5875 + " .set noreorder \n"
5876 + "3: b 5f \n"
5877 + " move %0, %1 \n"
5878 + " .set reorder \n"
5879 + _ASM_EXTABLE(2b, 3b)
5880 +#endif
5881 + "4: subu %0, %1, %3 \n"
5882 +#ifdef CONFIG_PAX_REFCOUNT
5883 + "5: \n"
5884 +#endif
5885 + " .set mips0 \n"
5886 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5887 + : "Ir" (i), "m" (v->counter)
5888 + : "memory");
5889 + } else if (kernel_uses_llsc) {
5890 + __asm__ __volatile__(
5891 + " .set mips3 \n"
5892 + "1: ll %1, %2 # atomic_sub_return \n"
5893 +#ifdef CONFIG_PAX_REFCOUNT
5894 + "2: sub %0, %1, %3 \n"
5895 +#else
5896 + " subu %0, %1, %3 \n"
5897 +#endif
5898 + " sc %0, %2 \n"
5899 + " bnez %0, 4f \n"
5900 + " b 1b \n"
5901 +#ifdef CONFIG_PAX_REFCOUNT
5902 + " .set noreorder \n"
5903 + "3: b 5f \n"
5904 + " move %0, %1 \n"
5905 + " .set reorder \n"
5906 + _ASM_EXTABLE(2b, 3b)
5907 +#endif
5908 + "4: subu %0, %1, %3 \n"
5909 +#ifdef CONFIG_PAX_REFCOUNT
5910 + "5: \n"
5911 +#endif
5912 + " .set mips0 \n"
5913 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5914 + : "Ir" (i));
5915 + } else {
5916 + unsigned long flags;
5917 +
5918 + raw_local_irq_save(flags);
5919 + __asm__ __volatile__(
5920 + " lw %0, %1 \n"
5921 +#ifdef CONFIG_PAX_REFCOUNT
5922 + /* Exception on overflow. */
5923 + "1: sub %0, %2 \n"
5924 +#else
5925 + " subu %0, %2 \n"
5926 +#endif
5927 + " sw %0, %1 \n"
5928 +#ifdef CONFIG_PAX_REFCOUNT
5929 + /* Note: Dest reg is not modified on overflow */
5930 + "2: \n"
5931 + _ASM_EXTABLE(1b, 2b)
5932 +#endif
5933 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5934 + raw_local_irq_restore(flags);
5935 + }
5936 +
5937 + smp_llsc_mb();
5938 +
5939 + return result;
5940 +}
5941 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5942 {
5943 int result;
5944
5945 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5946 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5947 * The function returns the old value of @v minus @i.
5948 */
5949 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5950 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5951 {
5952 int result;
5953
5954 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5955 return result;
5956 }
5957
5958 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5959 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5960 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5961 +{
5962 + return cmpxchg(&v->counter, old, new);
5963 +}
5964 +
5965 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5966 + int new)
5967 +{
5968 + return cmpxchg(&(v->counter), old, new);
5969 +}
5970 +
5971 +static inline int atomic_xchg(atomic_t *v, int new)
5972 +{
5973 + return xchg(&v->counter, new);
5974 +}
5975 +
5976 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5977 +{
5978 + return xchg(&(v->counter), new);
5979 +}
5980
5981 /**
5982 * __atomic_add_unless - add unless the number is a given value
5983 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5984
5985 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5986 #define atomic_inc_return(v) atomic_add_return(1, (v))
5987 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5988 +{
5989 + return atomic_add_return_unchecked(1, v);
5990 +}
5991
5992 /*
5993 * atomic_sub_and_test - subtract value from variable and test result
5994 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5995 * other cases.
5996 */
5997 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5998 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5999 +{
6000 + return atomic_add_return_unchecked(1, v) == 0;
6001 +}
6002
6003 /*
6004 * atomic_dec_and_test - decrement by 1 and test
6005 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6006 * Atomically increments @v by 1.
6007 */
6008 #define atomic_inc(v) atomic_add(1, (v))
6009 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6010 +{
6011 + atomic_add_unchecked(1, v);
6012 +}
6013
6014 /*
6015 * atomic_dec - decrement and test
6016 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6017 * Atomically decrements @v by 1.
6018 */
6019 #define atomic_dec(v) atomic_sub(1, (v))
6020 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6021 +{
6022 + atomic_sub_unchecked(1, v);
6023 +}
6024
6025 /*
6026 * atomic_add_negative - add and test if negative
6027 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6028 * @v: pointer of type atomic64_t
6029 *
6030 */
6031 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6032 +static inline long atomic64_read(const atomic64_t *v)
6033 +{
6034 + return (*(volatile const long *) &v->counter);
6035 +}
6036 +
6037 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6038 +{
6039 + return (*(volatile const long *) &v->counter);
6040 +}
6041
6042 /*
6043 * atomic64_set - set atomic variable
6044 * @v: pointer of type atomic64_t
6045 * @i: required value
6046 */
6047 -#define atomic64_set(v, i) ((v)->counter = (i))
6048 +static inline void atomic64_set(atomic64_t *v, long i)
6049 +{
6050 + v->counter = i;
6051 +}
6052 +
6053 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6054 +{
6055 + v->counter = i;
6056 +}
6057
6058 /*
6059 * atomic64_add - add integer to atomic variable
6060 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6061 *
6062 * Atomically adds @i to @v.
6063 */
6064 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6065 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6066 +{
6067 + long temp;
6068 +
6069 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6070 + __asm__ __volatile__(
6071 + " .set mips3 \n"
6072 + "1: lld %0, %1 # atomic64_add \n"
6073 +#ifdef CONFIG_PAX_REFCOUNT
6074 + /* Exception on overflow. */
6075 + "2: dadd %0, %2 \n"
6076 +#else
6077 + " daddu %0, %2 \n"
6078 +#endif
6079 + " scd %0, %1 \n"
6080 + " beqzl %0, 1b \n"
6081 +#ifdef CONFIG_PAX_REFCOUNT
6082 + "3: \n"
6083 + _ASM_EXTABLE(2b, 3b)
6084 +#endif
6085 + " .set mips0 \n"
6086 + : "=&r" (temp), "+m" (v->counter)
6087 + : "Ir" (i));
6088 + } else if (kernel_uses_llsc) {
6089 + __asm__ __volatile__(
6090 + " .set mips3 \n"
6091 + "1: lld %0, %1 # atomic64_add \n"
6092 +#ifdef CONFIG_PAX_REFCOUNT
6093 + /* Exception on overflow. */
6094 + "2: dadd %0, %2 \n"
6095 +#else
6096 + " daddu %0, %2 \n"
6097 +#endif
6098 + " scd %0, %1 \n"
6099 + " beqz %0, 1b \n"
6100 +#ifdef CONFIG_PAX_REFCOUNT
6101 + "3: \n"
6102 + _ASM_EXTABLE(2b, 3b)
6103 +#endif
6104 + " .set mips0 \n"
6105 + : "=&r" (temp), "+m" (v->counter)
6106 + : "Ir" (i));
6107 + } else {
6108 + unsigned long flags;
6109 +
6110 + raw_local_irq_save(flags);
6111 + __asm__ __volatile__(
6112 +#ifdef CONFIG_PAX_REFCOUNT
6113 + /* Exception on overflow. */
6114 + "1: dadd %0, %1 \n"
6115 + "2: \n"
6116 + _ASM_EXTABLE(1b, 2b)
6117 +#else
6118 + " daddu %0, %1 \n"
6119 +#endif
6120 + : "+r" (v->counter) : "Ir" (i));
6121 + raw_local_irq_restore(flags);
6122 + }
6123 +}
6124 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6125 {
6126 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6127 long temp;
6128 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6129 *
6130 * Atomically subtracts @i from @v.
6131 */
6132 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6133 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6134 +{
6135 + long temp;
6136 +
6137 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6138 + __asm__ __volatile__(
6139 + " .set mips3 \n"
6140 + "1: lld %0, %1 # atomic64_sub \n"
6141 +#ifdef CONFIG_PAX_REFCOUNT
6142 + /* Exception on overflow. */
6143 + "2: dsub %0, %2 \n"
6144 +#else
6145 + " dsubu %0, %2 \n"
6146 +#endif
6147 + " scd %0, %1 \n"
6148 + " beqzl %0, 1b \n"
6149 +#ifdef CONFIG_PAX_REFCOUNT
6150 + "3: \n"
6151 + _ASM_EXTABLE(2b, 3b)
6152 +#endif
6153 + " .set mips0 \n"
6154 + : "=&r" (temp), "+m" (v->counter)
6155 + : "Ir" (i));
6156 + } else if (kernel_uses_llsc) {
6157 + __asm__ __volatile__(
6158 + " .set mips3 \n"
6159 + "1: lld %0, %1 # atomic64_sub \n"
6160 +#ifdef CONFIG_PAX_REFCOUNT
6161 + /* Exception on overflow. */
6162 + "2: dsub %0, %2 \n"
6163 +#else
6164 + " dsubu %0, %2 \n"
6165 +#endif
6166 + " scd %0, %1 \n"
6167 + " beqz %0, 1b \n"
6168 +#ifdef CONFIG_PAX_REFCOUNT
6169 + "3: \n"
6170 + _ASM_EXTABLE(2b, 3b)
6171 +#endif
6172 + " .set mips0 \n"
6173 + : "=&r" (temp), "+m" (v->counter)
6174 + : "Ir" (i));
6175 + } else {
6176 + unsigned long flags;
6177 +
6178 + raw_local_irq_save(flags);
6179 + __asm__ __volatile__(
6180 +#ifdef CONFIG_PAX_REFCOUNT
6181 + /* Exception on overflow. */
6182 + "1: dsub %0, %1 \n"
6183 + "2: \n"
6184 + _ASM_EXTABLE(1b, 2b)
6185 +#else
6186 + " dsubu %0, %1 \n"
6187 +#endif
6188 + : "+r" (v->counter) : "Ir" (i));
6189 + raw_local_irq_restore(flags);
6190 + }
6191 +}
6192 +
6193 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6194 {
6195 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6196 long temp;
6197 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6198 /*
6199 * Same as above, but return the result value
6200 */
6201 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6202 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6203 +{
6204 + long result;
6205 + long temp;
6206 +
6207 + smp_mb__before_llsc();
6208 +
6209 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6210 + __asm__ __volatile__(
6211 + " .set mips3 \n"
6212 + "1: lld %1, %2 # atomic64_add_return \n"
6213 +#ifdef CONFIG_PAX_REFCOUNT
6214 + "2: dadd %0, %1, %3 \n"
6215 +#else
6216 + " daddu %0, %1, %3 \n"
6217 +#endif
6218 + " scd %0, %2 \n"
6219 + " beqzl %0, 1b \n"
6220 +#ifdef CONFIG_PAX_REFCOUNT
6221 + " b 4f \n"
6222 + " .set noreorder \n"
6223 + "3: b 5f \n"
6224 + " move %0, %1 \n"
6225 + " .set reorder \n"
6226 + _ASM_EXTABLE(2b, 3b)
6227 +#endif
6228 + "4: daddu %0, %1, %3 \n"
6229 +#ifdef CONFIG_PAX_REFCOUNT
6230 + "5: \n"
6231 +#endif
6232 + " .set mips0 \n"
6233 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6234 + : "Ir" (i));
6235 + } else if (kernel_uses_llsc) {
6236 + __asm__ __volatile__(
6237 + " .set mips3 \n"
6238 + "1: lld %1, %2 # atomic64_add_return \n"
6239 +#ifdef CONFIG_PAX_REFCOUNT
6240 + "2: dadd %0, %1, %3 \n"
6241 +#else
6242 + " daddu %0, %1, %3 \n"
6243 +#endif
6244 + " scd %0, %2 \n"
6245 + " bnez %0, 4f \n"
6246 + " b 1b \n"
6247 +#ifdef CONFIG_PAX_REFCOUNT
6248 + " .set noreorder \n"
6249 + "3: b 5f \n"
6250 + " move %0, %1 \n"
6251 + " .set reorder \n"
6252 + _ASM_EXTABLE(2b, 3b)
6253 +#endif
6254 + "4: daddu %0, %1, %3 \n"
6255 +#ifdef CONFIG_PAX_REFCOUNT
6256 + "5: \n"
6257 +#endif
6258 + " .set mips0 \n"
6259 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6260 + : "Ir" (i), "m" (v->counter)
6261 + : "memory");
6262 + } else {
6263 + unsigned long flags;
6264 +
6265 + raw_local_irq_save(flags);
6266 + __asm__ __volatile__(
6267 + " ld %0, %1 \n"
6268 +#ifdef CONFIG_PAX_REFCOUNT
6269 + /* Exception on overflow. */
6270 + "1: dadd %0, %2 \n"
6271 +#else
6272 + " daddu %0, %2 \n"
6273 +#endif
6274 + " sd %0, %1 \n"
6275 +#ifdef CONFIG_PAX_REFCOUNT
6276 + /* Note: Dest reg is not modified on overflow */
6277 + "2: \n"
6278 + _ASM_EXTABLE(1b, 2b)
6279 +#endif
6280 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6281 + raw_local_irq_restore(flags);
6282 + }
6283 +
6284 + smp_llsc_mb();
6285 +
6286 + return result;
6287 +}
6288 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6289 {
6290 long result;
6291
6292 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6293 return result;
6294 }
6295
6296 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6297 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6298 +{
6299 + long result;
6300 + long temp;
6301 +
6302 + smp_mb__before_llsc();
6303 +
6304 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6305 + long temp;
6306 +
6307 + __asm__ __volatile__(
6308 + " .set mips3 \n"
6309 + "1: lld %1, %2 # atomic64_sub_return \n"
6310 +#ifdef CONFIG_PAX_REFCOUNT
6311 + "2: dsub %0, %1, %3 \n"
6312 +#else
6313 + " dsubu %0, %1, %3 \n"
6314 +#endif
6315 + " scd %0, %2 \n"
6316 + " beqzl %0, 1b \n"
6317 +#ifdef CONFIG_PAX_REFCOUNT
6318 + " b 4f \n"
6319 + " .set noreorder \n"
6320 + "3: b 5f \n"
6321 + " move %0, %1 \n"
6322 + " .set reorder \n"
6323 + _ASM_EXTABLE(2b, 3b)
6324 +#endif
6325 + "4: dsubu %0, %1, %3 \n"
6326 +#ifdef CONFIG_PAX_REFCOUNT
6327 + "5: \n"
6328 +#endif
6329 + " .set mips0 \n"
6330 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6331 + : "Ir" (i), "m" (v->counter)
6332 + : "memory");
6333 + } else if (kernel_uses_llsc) {
6334 + __asm__ __volatile__(
6335 + " .set mips3 \n"
6336 + "1: lld %1, %2 # atomic64_sub_return \n"
6337 +#ifdef CONFIG_PAX_REFCOUNT
6338 + "2: dsub %0, %1, %3 \n"
6339 +#else
6340 + " dsubu %0, %1, %3 \n"
6341 +#endif
6342 + " scd %0, %2 \n"
6343 + " bnez %0, 4f \n"
6344 + " b 1b \n"
6345 +#ifdef CONFIG_PAX_REFCOUNT
6346 + " .set noreorder \n"
6347 + "3: b 5f \n"
6348 + " move %0, %1 \n"
6349 + " .set reorder \n"
6350 + _ASM_EXTABLE(2b, 3b)
6351 +#endif
6352 + "4: dsubu %0, %1, %3 \n"
6353 +#ifdef CONFIG_PAX_REFCOUNT
6354 + "5: \n"
6355 +#endif
6356 + " .set mips0 \n"
6357 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6358 + : "Ir" (i), "m" (v->counter)
6359 + : "memory");
6360 + } else {
6361 + unsigned long flags;
6362 +
6363 + raw_local_irq_save(flags);
6364 + __asm__ __volatile__(
6365 + " ld %0, %1 \n"
6366 +#ifdef CONFIG_PAX_REFCOUNT
6367 + /* Exception on overflow. */
6368 + "1: dsub %0, %2 \n"
6369 +#else
6370 + " dsubu %0, %2 \n"
6371 +#endif
6372 + " sd %0, %1 \n"
6373 +#ifdef CONFIG_PAX_REFCOUNT
6374 + /* Note: Dest reg is not modified on overflow */
6375 + "2: \n"
6376 + _ASM_EXTABLE(1b, 2b)
6377 +#endif
6378 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6379 + raw_local_irq_restore(flags);
6380 + }
6381 +
6382 + smp_llsc_mb();
6383 +
6384 + return result;
6385 +}
6386 +
6387 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6388 {
6389 long result;
6390
6391 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6392 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6393 * The function returns the old value of @v minus @i.
6394 */
6395 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6396 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6397 {
6398 long result;
6399
6400 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6401 return result;
6402 }
6403
6404 -#define atomic64_cmpxchg(v, o, n) \
6405 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6406 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6407 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6408 +{
6409 + return cmpxchg(&v->counter, old, new);
6410 +}
6411 +
6412 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6413 + long new)
6414 +{
6415 + return cmpxchg(&(v->counter), old, new);
6416 +}
6417 +
6418 +static inline long atomic64_xchg(atomic64_t *v, long new)
6419 +{
6420 + return xchg(&v->counter, new);
6421 +}
6422 +
6423 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6424 +{
6425 + return xchg(&(v->counter), new);
6426 +}
6427
6428 /**
6429 * atomic64_add_unless - add unless the number is a given value
6430 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6431
6432 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6433 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6434 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6435
6436 /*
6437 * atomic64_sub_and_test - subtract value from variable and test result
6438 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6439 * other cases.
6440 */
6441 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6442 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6443
6444 /*
6445 * atomic64_dec_and_test - decrement by 1 and test
6446 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6447 * Atomically increments @v by 1.
6448 */
6449 #define atomic64_inc(v) atomic64_add(1, (v))
6450 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6451
6452 /*
6453 * atomic64_dec - decrement and test
6454 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6455 * Atomically decrements @v by 1.
6456 */
6457 #define atomic64_dec(v) atomic64_sub(1, (v))
6458 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6459
6460 /*
6461 * atomic64_add_negative - add and test if negative
6462 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6463 index b4db69f..8f3b093 100644
6464 --- a/arch/mips/include/asm/cache.h
6465 +++ b/arch/mips/include/asm/cache.h
6466 @@ -9,10 +9,11 @@
6467 #ifndef _ASM_CACHE_H
6468 #define _ASM_CACHE_H
6469
6470 +#include <linux/const.h>
6471 #include <kmalloc.h>
6472
6473 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6474 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6475 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6476
6477 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6478 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6479 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6480 index d414405..6bb4ba2 100644
6481 --- a/arch/mips/include/asm/elf.h
6482 +++ b/arch/mips/include/asm/elf.h
6483 @@ -398,13 +398,16 @@ extern const char *__elf_platform;
6484 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6485 #endif
6486
6487 +#ifdef CONFIG_PAX_ASLR
6488 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6489 +
6490 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6491 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6492 +#endif
6493 +
6494 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6495 struct linux_binprm;
6496 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6497 int uses_interp);
6498
6499 -struct mm_struct;
6500 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6501 -#define arch_randomize_brk arch_randomize_brk
6502 -
6503 #endif /* _ASM_ELF_H */
6504 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6505 index c1f6afa..38cc6e9 100644
6506 --- a/arch/mips/include/asm/exec.h
6507 +++ b/arch/mips/include/asm/exec.h
6508 @@ -12,6 +12,6 @@
6509 #ifndef _ASM_EXEC_H
6510 #define _ASM_EXEC_H
6511
6512 -extern unsigned long arch_align_stack(unsigned long sp);
6513 +#define arch_align_stack(x) ((x) & ~0xfUL)
6514
6515 #endif /* _ASM_EXEC_H */
6516 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6517 index 9e8ef59..1139d6b 100644
6518 --- a/arch/mips/include/asm/hw_irq.h
6519 +++ b/arch/mips/include/asm/hw_irq.h
6520 @@ -10,7 +10,7 @@
6521
6522 #include <linux/atomic.h>
6523
6524 -extern atomic_t irq_err_count;
6525 +extern atomic_unchecked_t irq_err_count;
6526
6527 /*
6528 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6529 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6530 index d44622c..64990d2 100644
6531 --- a/arch/mips/include/asm/local.h
6532 +++ b/arch/mips/include/asm/local.h
6533 @@ -12,15 +12,25 @@ typedef struct
6534 atomic_long_t a;
6535 } local_t;
6536
6537 +typedef struct {
6538 + atomic_long_unchecked_t a;
6539 +} local_unchecked_t;
6540 +
6541 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6542
6543 #define local_read(l) atomic_long_read(&(l)->a)
6544 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6545 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6546 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6547
6548 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6549 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6550 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6551 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6552 #define local_inc(l) atomic_long_inc(&(l)->a)
6553 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6554 #define local_dec(l) atomic_long_dec(&(l)->a)
6555 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6556
6557 /*
6558 * Same as above, but return the result value
6559 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6560 return result;
6561 }
6562
6563 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6564 +{
6565 + unsigned long result;
6566 +
6567 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6568 + unsigned long temp;
6569 +
6570 + __asm__ __volatile__(
6571 + " .set mips3 \n"
6572 + "1:" __LL "%1, %2 # local_add_return \n"
6573 + " addu %0, %1, %3 \n"
6574 + __SC "%0, %2 \n"
6575 + " beqzl %0, 1b \n"
6576 + " addu %0, %1, %3 \n"
6577 + " .set mips0 \n"
6578 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6579 + : "Ir" (i), "m" (l->a.counter)
6580 + : "memory");
6581 + } else if (kernel_uses_llsc) {
6582 + unsigned long temp;
6583 +
6584 + __asm__ __volatile__(
6585 + " .set mips3 \n"
6586 + "1:" __LL "%1, %2 # local_add_return \n"
6587 + " addu %0, %1, %3 \n"
6588 + __SC "%0, %2 \n"
6589 + " beqz %0, 1b \n"
6590 + " addu %0, %1, %3 \n"
6591 + " .set mips0 \n"
6592 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6593 + : "Ir" (i), "m" (l->a.counter)
6594 + : "memory");
6595 + } else {
6596 + unsigned long flags;
6597 +
6598 + local_irq_save(flags);
6599 + result = l->a.counter;
6600 + result += i;
6601 + l->a.counter = result;
6602 + local_irq_restore(flags);
6603 + }
6604 +
6605 + return result;
6606 +}
6607 +
6608 static __inline__ long local_sub_return(long i, local_t * l)
6609 {
6610 unsigned long result;
6611 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6612
6613 #define local_cmpxchg(l, o, n) \
6614 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6615 +#define local_cmpxchg_unchecked(l, o, n) \
6616 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6617 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6618
6619 /**
6620 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6621 index 5e08bcc..cfedefc 100644
6622 --- a/arch/mips/include/asm/page.h
6623 +++ b/arch/mips/include/asm/page.h
6624 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6625 #ifdef CONFIG_CPU_MIPS32
6626 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6627 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6628 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6629 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6630 #else
6631 typedef struct { unsigned long long pte; } pte_t;
6632 #define pte_val(x) ((x).pte)
6633 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6634 index b336037..5b874cc 100644
6635 --- a/arch/mips/include/asm/pgalloc.h
6636 +++ b/arch/mips/include/asm/pgalloc.h
6637 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6638 {
6639 set_pud(pud, __pud((unsigned long)pmd));
6640 }
6641 +
6642 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6643 +{
6644 + pud_populate(mm, pud, pmd);
6645 +}
6646 #endif
6647
6648 /*
6649 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6650 index 008324d..f67c239 100644
6651 --- a/arch/mips/include/asm/pgtable.h
6652 +++ b/arch/mips/include/asm/pgtable.h
6653 @@ -20,6 +20,9 @@
6654 #include <asm/io.h>
6655 #include <asm/pgtable-bits.h>
6656
6657 +#define ktla_ktva(addr) (addr)
6658 +#define ktva_ktla(addr) (addr)
6659 +
6660 struct mm_struct;
6661 struct vm_area_struct;
6662
6663 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6664 index 25da651..ae2a259 100644
6665 --- a/arch/mips/include/asm/smtc_proc.h
6666 +++ b/arch/mips/include/asm/smtc_proc.h
6667 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6668
6669 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6670
6671 -extern atomic_t smtc_fpu_recoveries;
6672 +extern atomic_unchecked_t smtc_fpu_recoveries;
6673
6674 #endif /* __ASM_SMTC_PROC_H */
6675 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6676 index 24846f9..61c49f0 100644
6677 --- a/arch/mips/include/asm/thread_info.h
6678 +++ b/arch/mips/include/asm/thread_info.h
6679 @@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6680 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6681 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6682 #define TIF_32BIT_FPREGS 27 /* 32-bit floating point registers */
6683 +/* li takes a 32bit immediate */
6684 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6685 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6686
6687 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6688 @@ -134,13 +136,14 @@ static inline struct thread_info *current_thread_info(void)
6689 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6690 #define _TIF_32BIT_FPREGS (1<<TIF_32BIT_FPREGS)
6691 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6692 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6693
6694 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6695 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6696 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6697
6698 /* work to do in syscall_trace_leave() */
6699 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6700 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6701 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6702
6703 /* work to do on interrupt/exception return */
6704 #define _TIF_WORK_MASK \
6705 @@ -148,7 +151,7 @@ static inline struct thread_info *current_thread_info(void)
6706 /* work to do on any return to u-space */
6707 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6708 _TIF_WORK_SYSCALL_EXIT | \
6709 - _TIF_SYSCALL_TRACEPOINT)
6710 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6711
6712 /*
6713 * We stash processor id into a COP0 register to retrieve it fast
6714 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6715 index f3fa375..3af6637 100644
6716 --- a/arch/mips/include/asm/uaccess.h
6717 +++ b/arch/mips/include/asm/uaccess.h
6718 @@ -128,6 +128,7 @@ extern u64 __ua_limit;
6719 __ok == 0; \
6720 })
6721
6722 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6723 #define access_ok(type, addr, size) \
6724 likely(__access_ok((addr), (size), __access_mask))
6725
6726 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6727 index 1188e00..41cf144 100644
6728 --- a/arch/mips/kernel/binfmt_elfn32.c
6729 +++ b/arch/mips/kernel/binfmt_elfn32.c
6730 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6731 #undef ELF_ET_DYN_BASE
6732 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6733
6734 +#ifdef CONFIG_PAX_ASLR
6735 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6736 +
6737 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6738 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6739 +#endif
6740 +
6741 #include <asm/processor.h>
6742 #include <linux/module.h>
6743 #include <linux/elfcore.h>
6744 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6745 index 7faf5f2..f3d3cf4 100644
6746 --- a/arch/mips/kernel/binfmt_elfo32.c
6747 +++ b/arch/mips/kernel/binfmt_elfo32.c
6748 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6749 #undef ELF_ET_DYN_BASE
6750 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6751
6752 +#ifdef CONFIG_PAX_ASLR
6753 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6754 +
6755 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6756 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6757 +#endif
6758 +
6759 #include <asm/processor.h>
6760
6761 /*
6762 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6763 index 2b91fe8..fe4f6b4 100644
6764 --- a/arch/mips/kernel/i8259.c
6765 +++ b/arch/mips/kernel/i8259.c
6766 @@ -205,7 +205,7 @@ spurious_8259A_irq:
6767 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6768 spurious_irq_mask |= irqmask;
6769 }
6770 - atomic_inc(&irq_err_count);
6771 + atomic_inc_unchecked(&irq_err_count);
6772 /*
6773 * Theoretically we do not have to handle this IRQ,
6774 * but in Linux this does not cause problems and is
6775 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6776 index 44a1f79..2bd6aa3 100644
6777 --- a/arch/mips/kernel/irq-gt641xx.c
6778 +++ b/arch/mips/kernel/irq-gt641xx.c
6779 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6780 }
6781 }
6782
6783 - atomic_inc(&irq_err_count);
6784 + atomic_inc_unchecked(&irq_err_count);
6785 }
6786
6787 void __init gt641xx_irq_init(void)
6788 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6789 index d1fea7a..2e591b0 100644
6790 --- a/arch/mips/kernel/irq.c
6791 +++ b/arch/mips/kernel/irq.c
6792 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6793 printk("unexpected IRQ # %d\n", irq);
6794 }
6795
6796 -atomic_t irq_err_count;
6797 +atomic_unchecked_t irq_err_count;
6798
6799 int arch_show_interrupts(struct seq_file *p, int prec)
6800 {
6801 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6802 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6803 return 0;
6804 }
6805
6806 asmlinkage void spurious_interrupt(void)
6807 {
6808 - atomic_inc(&irq_err_count);
6809 + atomic_inc_unchecked(&irq_err_count);
6810 }
6811
6812 void __init init_IRQ(void)
6813 @@ -110,7 +110,10 @@ void __init init_IRQ(void)
6814 #endif
6815 }
6816
6817 +
6818 #ifdef DEBUG_STACKOVERFLOW
6819 +extern void gr_handle_kernel_exploit(void);
6820 +
6821 static inline void check_stack_overflow(void)
6822 {
6823 unsigned long sp;
6824 @@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6825 printk("do_IRQ: stack overflow: %ld\n",
6826 sp - sizeof(struct thread_info));
6827 dump_stack();
6828 + gr_handle_kernel_exploit();
6829 }
6830 }
6831 #else
6832 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6833 index 6ae540e..b7396dc 100644
6834 --- a/arch/mips/kernel/process.c
6835 +++ b/arch/mips/kernel/process.c
6836 @@ -562,15 +562,3 @@ unsigned long get_wchan(struct task_struct *task)
6837 out:
6838 return pc;
6839 }
6840 -
6841 -/*
6842 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6843 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6844 - */
6845 -unsigned long arch_align_stack(unsigned long sp)
6846 -{
6847 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6848 - sp -= get_random_int() & ~PAGE_MASK;
6849 -
6850 - return sp & ALMASK;
6851 -}
6852 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6853 index 7da9b76..21578be 100644
6854 --- a/arch/mips/kernel/ptrace.c
6855 +++ b/arch/mips/kernel/ptrace.c
6856 @@ -658,6 +658,10 @@ long arch_ptrace(struct task_struct *child, long request,
6857 return ret;
6858 }
6859
6860 +#ifdef CONFIG_GRKERNSEC_SETXID
6861 +extern void gr_delayed_cred_worker(void);
6862 +#endif
6863 +
6864 /*
6865 * Notification of system call entry/exit
6866 * - triggered by current->work.syscall_trace
6867 @@ -674,6 +678,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6868 tracehook_report_syscall_entry(regs))
6869 ret = -1;
6870
6871 +#ifdef CONFIG_GRKERNSEC_SETXID
6872 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6873 + gr_delayed_cred_worker();
6874 +#endif
6875 +
6876 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6877 trace_sys_enter(regs, regs->regs[2]);
6878
6879 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6880 index 07fc524..b9d7f28 100644
6881 --- a/arch/mips/kernel/reset.c
6882 +++ b/arch/mips/kernel/reset.c
6883 @@ -13,6 +13,7 @@
6884 #include <linux/reboot.h>
6885
6886 #include <asm/reboot.h>
6887 +#include <asm/bug.h>
6888
6889 /*
6890 * Urgs ... Too many MIPS machines to handle this in a generic way.
6891 @@ -29,16 +30,19 @@ void machine_restart(char *command)
6892 {
6893 if (_machine_restart)
6894 _machine_restart(command);
6895 + BUG();
6896 }
6897
6898 void machine_halt(void)
6899 {
6900 if (_machine_halt)
6901 _machine_halt();
6902 + BUG();
6903 }
6904
6905 void machine_power_off(void)
6906 {
6907 if (pm_power_off)
6908 pm_power_off();
6909 + BUG();
6910 }
6911 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6912 index c10aa84..9ec2e60 100644
6913 --- a/arch/mips/kernel/smtc-proc.c
6914 +++ b/arch/mips/kernel/smtc-proc.c
6915 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6916
6917 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6918
6919 -atomic_t smtc_fpu_recoveries;
6920 +atomic_unchecked_t smtc_fpu_recoveries;
6921
6922 static int smtc_proc_show(struct seq_file *m, void *v)
6923 {
6924 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6925 for(i = 0; i < NR_CPUS; i++)
6926 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6927 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6928 - atomic_read(&smtc_fpu_recoveries));
6929 + atomic_read_unchecked(&smtc_fpu_recoveries));
6930 return 0;
6931 }
6932
6933 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
6934 smtc_cpu_stats[i].selfipis = 0;
6935 }
6936
6937 - atomic_set(&smtc_fpu_recoveries, 0);
6938 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6939
6940 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6941 }
6942 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6943 index dfc1b91..11a2c07 100644
6944 --- a/arch/mips/kernel/smtc.c
6945 +++ b/arch/mips/kernel/smtc.c
6946 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6947 }
6948 smtc_ipi_qdump();
6949 printk("%d Recoveries of \"stolen\" FPU\n",
6950 - atomic_read(&smtc_fpu_recoveries));
6951 + atomic_read_unchecked(&smtc_fpu_recoveries));
6952 }
6953
6954
6955 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6956 index c24ad5f..9983ab2 100644
6957 --- a/arch/mips/kernel/sync-r4k.c
6958 +++ b/arch/mips/kernel/sync-r4k.c
6959 @@ -20,8 +20,8 @@
6960 #include <asm/mipsregs.h>
6961
6962 static atomic_t count_start_flag = ATOMIC_INIT(0);
6963 -static atomic_t count_count_start = ATOMIC_INIT(0);
6964 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6965 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6966 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6967 static atomic_t count_reference = ATOMIC_INIT(0);
6968
6969 #define COUNTON 100
6970 @@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
6971
6972 for (i = 0; i < NR_LOOPS; i++) {
6973 /* slaves loop on '!= 2' */
6974 - while (atomic_read(&count_count_start) != 1)
6975 + while (atomic_read_unchecked(&count_count_start) != 1)
6976 mb();
6977 - atomic_set(&count_count_stop, 0);
6978 + atomic_set_unchecked(&count_count_stop, 0);
6979 smp_wmb();
6980
6981 /* this lets the slaves write their count register */
6982 - atomic_inc(&count_count_start);
6983 + atomic_inc_unchecked(&count_count_start);
6984
6985 /*
6986 * Everyone initialises count in the last loop:
6987 @@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
6988 /*
6989 * Wait for all slaves to leave the synchronization point:
6990 */
6991 - while (atomic_read(&count_count_stop) != 1)
6992 + while (atomic_read_unchecked(&count_count_stop) != 1)
6993 mb();
6994 - atomic_set(&count_count_start, 0);
6995 + atomic_set_unchecked(&count_count_start, 0);
6996 smp_wmb();
6997 - atomic_inc(&count_count_stop);
6998 + atomic_inc_unchecked(&count_count_stop);
6999 }
7000 /* Arrange for an interrupt in a short while */
7001 write_c0_compare(read_c0_count() + COUNTON);
7002 @@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7003 initcount = atomic_read(&count_reference);
7004
7005 for (i = 0; i < NR_LOOPS; i++) {
7006 - atomic_inc(&count_count_start);
7007 - while (atomic_read(&count_count_start) != 2)
7008 + atomic_inc_unchecked(&count_count_start);
7009 + while (atomic_read_unchecked(&count_count_start) != 2)
7010 mb();
7011
7012 /*
7013 @@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7014 if (i == NR_LOOPS-1)
7015 write_c0_count(initcount);
7016
7017 - atomic_inc(&count_count_stop);
7018 - while (atomic_read(&count_count_stop) != 2)
7019 + atomic_inc_unchecked(&count_count_stop);
7020 + while (atomic_read_unchecked(&count_count_stop) != 2)
7021 mb();
7022 }
7023 /* Arrange for an interrupt in a short while */
7024 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7025 index e0b4996..6b43ce7 100644
7026 --- a/arch/mips/kernel/traps.c
7027 +++ b/arch/mips/kernel/traps.c
7028 @@ -691,7 +691,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7029 siginfo_t info;
7030
7031 prev_state = exception_enter();
7032 - die_if_kernel("Integer overflow", regs);
7033 + if (unlikely(!user_mode(regs))) {
7034 +
7035 +#ifdef CONFIG_PAX_REFCOUNT
7036 + if (fixup_exception(regs)) {
7037 + pax_report_refcount_overflow(regs);
7038 + exception_exit(prev_state);
7039 + return;
7040 + }
7041 +#endif
7042 +
7043 + die("Integer overflow", regs);
7044 + }
7045
7046 info.si_code = FPE_INTOVF;
7047 info.si_signo = SIGFPE;
7048 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7049 index becc42b..9e43d4b 100644
7050 --- a/arch/mips/mm/fault.c
7051 +++ b/arch/mips/mm/fault.c
7052 @@ -28,6 +28,23 @@
7053 #include <asm/highmem.h> /* For VMALLOC_END */
7054 #include <linux/kdebug.h>
7055
7056 +#ifdef CONFIG_PAX_PAGEEXEC
7057 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7058 +{
7059 + unsigned long i;
7060 +
7061 + printk(KERN_ERR "PAX: bytes at PC: ");
7062 + for (i = 0; i < 5; i++) {
7063 + unsigned int c;
7064 + if (get_user(c, (unsigned int *)pc+i))
7065 + printk(KERN_CONT "???????? ");
7066 + else
7067 + printk(KERN_CONT "%08x ", c);
7068 + }
7069 + printk("\n");
7070 +}
7071 +#endif
7072 +
7073 /*
7074 * This routine handles page faults. It determines the address,
7075 * and the problem, and then passes it off to one of the appropriate
7076 @@ -199,6 +216,14 @@ bad_area:
7077 bad_area_nosemaphore:
7078 /* User mode accesses just cause a SIGSEGV */
7079 if (user_mode(regs)) {
7080 +
7081 +#ifdef CONFIG_PAX_PAGEEXEC
7082 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7083 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7084 + do_group_exit(SIGKILL);
7085 + }
7086 +#endif
7087 +
7088 tsk->thread.cp0_badvaddr = address;
7089 tsk->thread.error_code = write;
7090 #if 0
7091 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7092 index f1baadd..5472dca 100644
7093 --- a/arch/mips/mm/mmap.c
7094 +++ b/arch/mips/mm/mmap.c
7095 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7096 struct vm_area_struct *vma;
7097 unsigned long addr = addr0;
7098 int do_color_align;
7099 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7100 struct vm_unmapped_area_info info;
7101
7102 if (unlikely(len > TASK_SIZE))
7103 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7104 do_color_align = 1;
7105
7106 /* requesting a specific address */
7107 +
7108 +#ifdef CONFIG_PAX_RANDMMAP
7109 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7110 +#endif
7111 +
7112 if (addr) {
7113 if (do_color_align)
7114 addr = COLOUR_ALIGN(addr, pgoff);
7115 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7116 addr = PAGE_ALIGN(addr);
7117
7118 vma = find_vma(mm, addr);
7119 - if (TASK_SIZE - len >= addr &&
7120 - (!vma || addr + len <= vma->vm_start))
7121 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7122 return addr;
7123 }
7124
7125 info.length = len;
7126 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7127 info.align_offset = pgoff << PAGE_SHIFT;
7128 + info.threadstack_offset = offset;
7129
7130 if (dir == DOWN) {
7131 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7132 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7133 {
7134 unsigned long random_factor = 0UL;
7135
7136 +#ifdef CONFIG_PAX_RANDMMAP
7137 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7138 +#endif
7139 +
7140 if (current->flags & PF_RANDOMIZE) {
7141 random_factor = get_random_int();
7142 random_factor = random_factor << PAGE_SHIFT;
7143 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7144
7145 if (mmap_is_legacy()) {
7146 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7147 +
7148 +#ifdef CONFIG_PAX_RANDMMAP
7149 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7150 + mm->mmap_base += mm->delta_mmap;
7151 +#endif
7152 +
7153 mm->get_unmapped_area = arch_get_unmapped_area;
7154 } else {
7155 mm->mmap_base = mmap_base(random_factor);
7156 +
7157 +#ifdef CONFIG_PAX_RANDMMAP
7158 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7159 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7160 +#endif
7161 +
7162 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7163 }
7164 }
7165
7166 -static inline unsigned long brk_rnd(void)
7167 -{
7168 - unsigned long rnd = get_random_int();
7169 -
7170 - rnd = rnd << PAGE_SHIFT;
7171 - /* 8MB for 32bit, 256MB for 64bit */
7172 - if (TASK_IS_32BIT_ADDR)
7173 - rnd = rnd & 0x7ffffful;
7174 - else
7175 - rnd = rnd & 0xffffffful;
7176 -
7177 - return rnd;
7178 -}
7179 -
7180 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7181 -{
7182 - unsigned long base = mm->brk;
7183 - unsigned long ret;
7184 -
7185 - ret = PAGE_ALIGN(base + brk_rnd());
7186 -
7187 - if (ret < mm->brk)
7188 - return mm->brk;
7189 -
7190 - return ret;
7191 -}
7192 -
7193 int __virt_addr_valid(const volatile void *kaddr)
7194 {
7195 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7196 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7197 index 59cccd9..f39ac2f 100644
7198 --- a/arch/mips/pci/pci-octeon.c
7199 +++ b/arch/mips/pci/pci-octeon.c
7200 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7201
7202
7203 static struct pci_ops octeon_pci_ops = {
7204 - octeon_read_config,
7205 - octeon_write_config,
7206 + .read = octeon_read_config,
7207 + .write = octeon_write_config,
7208 };
7209
7210 static struct resource octeon_pci_mem_resource = {
7211 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7212 index 5e36c33..eb4a17b 100644
7213 --- a/arch/mips/pci/pcie-octeon.c
7214 +++ b/arch/mips/pci/pcie-octeon.c
7215 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7216 }
7217
7218 static struct pci_ops octeon_pcie0_ops = {
7219 - octeon_pcie0_read_config,
7220 - octeon_pcie0_write_config,
7221 + .read = octeon_pcie0_read_config,
7222 + .write = octeon_pcie0_write_config,
7223 };
7224
7225 static struct resource octeon_pcie0_mem_resource = {
7226 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7227 };
7228
7229 static struct pci_ops octeon_pcie1_ops = {
7230 - octeon_pcie1_read_config,
7231 - octeon_pcie1_write_config,
7232 + .read = octeon_pcie1_read_config,
7233 + .write = octeon_pcie1_write_config,
7234 };
7235
7236 static struct resource octeon_pcie1_mem_resource = {
7237 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7238 };
7239
7240 static struct pci_ops octeon_dummy_ops = {
7241 - octeon_dummy_read_config,
7242 - octeon_dummy_write_config,
7243 + .read = octeon_dummy_read_config,
7244 + .write = octeon_dummy_write_config,
7245 };
7246
7247 static struct resource octeon_dummy_mem_resource = {
7248 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7249 index a2358b4..7cead4f 100644
7250 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7251 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7252 @@ -187,9 +187,9 @@ void
7253 cont_nmi_dump(void)
7254 {
7255 #ifndef REAL_NMI_SIGNAL
7256 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7257 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7258
7259 - atomic_inc(&nmied_cpus);
7260 + atomic_inc_unchecked(&nmied_cpus);
7261 #endif
7262 /*
7263 * Only allow 1 cpu to proceed
7264 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7265 udelay(10000);
7266 }
7267 #else
7268 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7269 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7270 #endif
7271
7272 /*
7273 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7274 index a046b30..6799527 100644
7275 --- a/arch/mips/sni/rm200.c
7276 +++ b/arch/mips/sni/rm200.c
7277 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7278 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7279 spurious_irq_mask |= irqmask;
7280 }
7281 - atomic_inc(&irq_err_count);
7282 + atomic_inc_unchecked(&irq_err_count);
7283 /*
7284 * Theoretically we do not have to handle this IRQ,
7285 * but in Linux this does not cause problems and is
7286 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7287 index 41e873b..34d33a7 100644
7288 --- a/arch/mips/vr41xx/common/icu.c
7289 +++ b/arch/mips/vr41xx/common/icu.c
7290 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7291
7292 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7293
7294 - atomic_inc(&irq_err_count);
7295 + atomic_inc_unchecked(&irq_err_count);
7296
7297 return -1;
7298 }
7299 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7300 index ae0e4ee..e8f0692 100644
7301 --- a/arch/mips/vr41xx/common/irq.c
7302 +++ b/arch/mips/vr41xx/common/irq.c
7303 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7304 irq_cascade_t *cascade;
7305
7306 if (irq >= NR_IRQS) {
7307 - atomic_inc(&irq_err_count);
7308 + atomic_inc_unchecked(&irq_err_count);
7309 return;
7310 }
7311
7312 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7313 ret = cascade->get_irq(irq);
7314 irq = ret;
7315 if (ret < 0)
7316 - atomic_inc(&irq_err_count);
7317 + atomic_inc_unchecked(&irq_err_count);
7318 else
7319 irq_dispatch(irq);
7320 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7321 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7322 index 967d144..db12197 100644
7323 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7324 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7325 @@ -11,12 +11,14 @@
7326 #ifndef _ASM_PROC_CACHE_H
7327 #define _ASM_PROC_CACHE_H
7328
7329 +#include <linux/const.h>
7330 +
7331 /* L1 cache */
7332
7333 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7334 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7335 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7336 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7337 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7338 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7339
7340 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7341 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7342 index bcb5df2..84fabd2 100644
7343 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7344 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7345 @@ -16,13 +16,15 @@
7346 #ifndef _ASM_PROC_CACHE_H
7347 #define _ASM_PROC_CACHE_H
7348
7349 +#include <linux/const.h>
7350 +
7351 /*
7352 * L1 cache
7353 */
7354 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7355 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7356 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7357 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7358 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7359 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7360
7361 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7362 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7363 index 4ce7a01..449202a 100644
7364 --- a/arch/openrisc/include/asm/cache.h
7365 +++ b/arch/openrisc/include/asm/cache.h
7366 @@ -19,11 +19,13 @@
7367 #ifndef __ASM_OPENRISC_CACHE_H
7368 #define __ASM_OPENRISC_CACHE_H
7369
7370 +#include <linux/const.h>
7371 +
7372 /* FIXME: How can we replace these with values from the CPU...
7373 * they shouldn't be hard-coded!
7374 */
7375
7376 -#define L1_CACHE_BYTES 16
7377 #define L1_CACHE_SHIFT 4
7378 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7379
7380 #endif /* __ASM_OPENRISC_CACHE_H */
7381 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7382 index 472886c..00e7df9 100644
7383 --- a/arch/parisc/include/asm/atomic.h
7384 +++ b/arch/parisc/include/asm/atomic.h
7385 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7386 return dec;
7387 }
7388
7389 +#define atomic64_read_unchecked(v) atomic64_read(v)
7390 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7391 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7392 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7393 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7394 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7395 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7396 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7397 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7398 +
7399 #endif /* !CONFIG_64BIT */
7400
7401
7402 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7403 index 47f11c7..3420df2 100644
7404 --- a/arch/parisc/include/asm/cache.h
7405 +++ b/arch/parisc/include/asm/cache.h
7406 @@ -5,6 +5,7 @@
7407 #ifndef __ARCH_PARISC_CACHE_H
7408 #define __ARCH_PARISC_CACHE_H
7409
7410 +#include <linux/const.h>
7411
7412 /*
7413 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7414 @@ -15,13 +16,13 @@
7415 * just ruin performance.
7416 */
7417 #ifdef CONFIG_PA20
7418 -#define L1_CACHE_BYTES 64
7419 #define L1_CACHE_SHIFT 6
7420 #else
7421 -#define L1_CACHE_BYTES 32
7422 #define L1_CACHE_SHIFT 5
7423 #endif
7424
7425 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7426 +
7427 #ifndef __ASSEMBLY__
7428
7429 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7430 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7431 index 3391d06..c23a2cc 100644
7432 --- a/arch/parisc/include/asm/elf.h
7433 +++ b/arch/parisc/include/asm/elf.h
7434 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7435
7436 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7437
7438 +#ifdef CONFIG_PAX_ASLR
7439 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7440 +
7441 +#define PAX_DELTA_MMAP_LEN 16
7442 +#define PAX_DELTA_STACK_LEN 16
7443 +#endif
7444 +
7445 /* This yields a mask that user programs can use to figure out what
7446 instruction set this CPU supports. This could be done in user space,
7447 but it's not easy, and we've already done it here. */
7448 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7449 index f213f5b..0af3e8e 100644
7450 --- a/arch/parisc/include/asm/pgalloc.h
7451 +++ b/arch/parisc/include/asm/pgalloc.h
7452 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7453 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7454 }
7455
7456 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7457 +{
7458 + pgd_populate(mm, pgd, pmd);
7459 +}
7460 +
7461 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7462 {
7463 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7464 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7465 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7466 #define pmd_free(mm, x) do { } while (0)
7467 #define pgd_populate(mm, pmd, pte) BUG()
7468 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7469
7470 #endif
7471
7472 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7473 index 22b89d1..ce34230 100644
7474 --- a/arch/parisc/include/asm/pgtable.h
7475 +++ b/arch/parisc/include/asm/pgtable.h
7476 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7477 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7478 #define PAGE_COPY PAGE_EXECREAD
7479 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7480 +
7481 +#ifdef CONFIG_PAX_PAGEEXEC
7482 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7483 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7484 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7485 +#else
7486 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7487 +# define PAGE_COPY_NOEXEC PAGE_COPY
7488 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7489 +#endif
7490 +
7491 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7492 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7493 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7494 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7495 index 4006964..fcb3cc2 100644
7496 --- a/arch/parisc/include/asm/uaccess.h
7497 +++ b/arch/parisc/include/asm/uaccess.h
7498 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7499 const void __user *from,
7500 unsigned long n)
7501 {
7502 - int sz = __compiletime_object_size(to);
7503 + size_t sz = __compiletime_object_size(to);
7504 int ret = -EFAULT;
7505
7506 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7507 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7508 ret = __copy_from_user(to, from, n);
7509 else
7510 copy_from_user_overflow();
7511 diff --git a/arch/parisc/include/uapi/asm/resource.h b/arch/parisc/include/uapi/asm/resource.h
7512 index 8b06343..090483c 100644
7513 --- a/arch/parisc/include/uapi/asm/resource.h
7514 +++ b/arch/parisc/include/uapi/asm/resource.h
7515 @@ -1,7 +1,6 @@
7516 #ifndef _ASM_PARISC_RESOURCE_H
7517 #define _ASM_PARISC_RESOURCE_H
7518
7519 -#define _STK_LIM_MAX 10 * _STK_LIM
7520 #include <asm-generic/resource.h>
7521
7522 #endif
7523 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7524 index 50dfafc..b9fc230 100644
7525 --- a/arch/parisc/kernel/module.c
7526 +++ b/arch/parisc/kernel/module.c
7527 @@ -98,16 +98,38 @@
7528
7529 /* three functions to determine where in the module core
7530 * or init pieces the location is */
7531 +static inline int in_init_rx(struct module *me, void *loc)
7532 +{
7533 + return (loc >= me->module_init_rx &&
7534 + loc < (me->module_init_rx + me->init_size_rx));
7535 +}
7536 +
7537 +static inline int in_init_rw(struct module *me, void *loc)
7538 +{
7539 + return (loc >= me->module_init_rw &&
7540 + loc < (me->module_init_rw + me->init_size_rw));
7541 +}
7542 +
7543 static inline int in_init(struct module *me, void *loc)
7544 {
7545 - return (loc >= me->module_init &&
7546 - loc <= (me->module_init + me->init_size));
7547 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7548 +}
7549 +
7550 +static inline int in_core_rx(struct module *me, void *loc)
7551 +{
7552 + return (loc >= me->module_core_rx &&
7553 + loc < (me->module_core_rx + me->core_size_rx));
7554 +}
7555 +
7556 +static inline int in_core_rw(struct module *me, void *loc)
7557 +{
7558 + return (loc >= me->module_core_rw &&
7559 + loc < (me->module_core_rw + me->core_size_rw));
7560 }
7561
7562 static inline int in_core(struct module *me, void *loc)
7563 {
7564 - return (loc >= me->module_core &&
7565 - loc <= (me->module_core + me->core_size));
7566 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7567 }
7568
7569 static inline int in_local(struct module *me, void *loc)
7570 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7571 }
7572
7573 /* align things a bit */
7574 - me->core_size = ALIGN(me->core_size, 16);
7575 - me->arch.got_offset = me->core_size;
7576 - me->core_size += gots * sizeof(struct got_entry);
7577 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7578 + me->arch.got_offset = me->core_size_rw;
7579 + me->core_size_rw += gots * sizeof(struct got_entry);
7580
7581 - me->core_size = ALIGN(me->core_size, 16);
7582 - me->arch.fdesc_offset = me->core_size;
7583 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7584 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7585 + me->arch.fdesc_offset = me->core_size_rw;
7586 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7587
7588 me->arch.got_max = gots;
7589 me->arch.fdesc_max = fdescs;
7590 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7591
7592 BUG_ON(value == 0);
7593
7594 - got = me->module_core + me->arch.got_offset;
7595 + got = me->module_core_rw + me->arch.got_offset;
7596 for (i = 0; got[i].addr; i++)
7597 if (got[i].addr == value)
7598 goto out;
7599 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7600 #ifdef CONFIG_64BIT
7601 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7602 {
7603 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7604 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7605
7606 if (!value) {
7607 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7608 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7609
7610 /* Create new one */
7611 fdesc->addr = value;
7612 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7613 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7614 return (Elf_Addr)fdesc;
7615 }
7616 #endif /* CONFIG_64BIT */
7617 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7618
7619 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7620 end = table + sechdrs[me->arch.unwind_section].sh_size;
7621 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7622 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7623
7624 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7625 me->arch.unwind_section, table, end, gp);
7626 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7627 index b7cadc4..bf4a32d 100644
7628 --- a/arch/parisc/kernel/sys_parisc.c
7629 +++ b/arch/parisc/kernel/sys_parisc.c
7630 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7631 unsigned long task_size = TASK_SIZE;
7632 int do_color_align, last_mmap;
7633 struct vm_unmapped_area_info info;
7634 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7635
7636 if (len > task_size)
7637 return -ENOMEM;
7638 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7639 goto found_addr;
7640 }
7641
7642 +#ifdef CONFIG_PAX_RANDMMAP
7643 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7644 +#endif
7645 +
7646 if (addr) {
7647 if (do_color_align && last_mmap)
7648 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7649 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7650 info.high_limit = mmap_upper_limit();
7651 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7652 info.align_offset = shared_align_offset(last_mmap, pgoff);
7653 + info.threadstack_offset = offset;
7654 addr = vm_unmapped_area(&info);
7655
7656 found_addr:
7657 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7658 unsigned long addr = addr0;
7659 int do_color_align, last_mmap;
7660 struct vm_unmapped_area_info info;
7661 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7662
7663 #ifdef CONFIG_64BIT
7664 /* This should only ever run for 32-bit processes. */
7665 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7666 }
7667
7668 /* requesting a specific address */
7669 +#ifdef CONFIG_PAX_RANDMMAP
7670 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7671 +#endif
7672 +
7673 if (addr) {
7674 if (do_color_align && last_mmap)
7675 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7676 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7677 info.high_limit = mm->mmap_base;
7678 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7679 info.align_offset = shared_align_offset(last_mmap, pgoff);
7680 + info.threadstack_offset = offset;
7681 addr = vm_unmapped_area(&info);
7682 if (!(addr & ~PAGE_MASK))
7683 goto found_addr;
7684 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7685 mm->mmap_legacy_base = mmap_legacy_base();
7686 mm->mmap_base = mmap_upper_limit();
7687
7688 +#ifdef CONFIG_PAX_RANDMMAP
7689 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7690 + mm->mmap_legacy_base += mm->delta_mmap;
7691 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7692 + }
7693 +#endif
7694 +
7695 if (mmap_is_legacy()) {
7696 mm->mmap_base = mm->mmap_legacy_base;
7697 mm->get_unmapped_area = arch_get_unmapped_area;
7698 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7699 index 1cd1d0c..44ec918 100644
7700 --- a/arch/parisc/kernel/traps.c
7701 +++ b/arch/parisc/kernel/traps.c
7702 @@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7703
7704 down_read(&current->mm->mmap_sem);
7705 vma = find_vma(current->mm,regs->iaoq[0]);
7706 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7707 - && (vma->vm_flags & VM_EXEC)) {
7708 -
7709 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7710 fault_address = regs->iaoq[0];
7711 fault_space = regs->iasq[0];
7712
7713 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7714 index 9d08c71..e2b4d20 100644
7715 --- a/arch/parisc/mm/fault.c
7716 +++ b/arch/parisc/mm/fault.c
7717 @@ -15,6 +15,7 @@
7718 #include <linux/sched.h>
7719 #include <linux/interrupt.h>
7720 #include <linux/module.h>
7721 +#include <linux/unistd.h>
7722
7723 #include <asm/uaccess.h>
7724 #include <asm/traps.h>
7725 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7726 static unsigned long
7727 parisc_acctyp(unsigned long code, unsigned int inst)
7728 {
7729 - if (code == 6 || code == 16)
7730 + if (code == 6 || code == 7 || code == 16)
7731 return VM_EXEC;
7732
7733 switch (inst & 0xf0000000) {
7734 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7735 }
7736 #endif
7737
7738 +#ifdef CONFIG_PAX_PAGEEXEC
7739 +/*
7740 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7741 + *
7742 + * returns 1 when task should be killed
7743 + * 2 when rt_sigreturn trampoline was detected
7744 + * 3 when unpatched PLT trampoline was detected
7745 + */
7746 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7747 +{
7748 +
7749 +#ifdef CONFIG_PAX_EMUPLT
7750 + int err;
7751 +
7752 + do { /* PaX: unpatched PLT emulation */
7753 + unsigned int bl, depwi;
7754 +
7755 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7756 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7757 +
7758 + if (err)
7759 + break;
7760 +
7761 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7762 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7763 +
7764 + err = get_user(ldw, (unsigned int *)addr);
7765 + err |= get_user(bv, (unsigned int *)(addr+4));
7766 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7767 +
7768 + if (err)
7769 + break;
7770 +
7771 + if (ldw == 0x0E801096U &&
7772 + bv == 0xEAC0C000U &&
7773 + ldw2 == 0x0E881095U)
7774 + {
7775 + unsigned int resolver, map;
7776 +
7777 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7778 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7779 + if (err)
7780 + break;
7781 +
7782 + regs->gr[20] = instruction_pointer(regs)+8;
7783 + regs->gr[21] = map;
7784 + regs->gr[22] = resolver;
7785 + regs->iaoq[0] = resolver | 3UL;
7786 + regs->iaoq[1] = regs->iaoq[0] + 4;
7787 + return 3;
7788 + }
7789 + }
7790 + } while (0);
7791 +#endif
7792 +
7793 +#ifdef CONFIG_PAX_EMUTRAMP
7794 +
7795 +#ifndef CONFIG_PAX_EMUSIGRT
7796 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7797 + return 1;
7798 +#endif
7799 +
7800 + do { /* PaX: rt_sigreturn emulation */
7801 + unsigned int ldi1, ldi2, bel, nop;
7802 +
7803 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7804 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7805 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7806 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7807 +
7808 + if (err)
7809 + break;
7810 +
7811 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7812 + ldi2 == 0x3414015AU &&
7813 + bel == 0xE4008200U &&
7814 + nop == 0x08000240U)
7815 + {
7816 + regs->gr[25] = (ldi1 & 2) >> 1;
7817 + regs->gr[20] = __NR_rt_sigreturn;
7818 + regs->gr[31] = regs->iaoq[1] + 16;
7819 + regs->sr[0] = regs->iasq[1];
7820 + regs->iaoq[0] = 0x100UL;
7821 + regs->iaoq[1] = regs->iaoq[0] + 4;
7822 + regs->iasq[0] = regs->sr[2];
7823 + regs->iasq[1] = regs->sr[2];
7824 + return 2;
7825 + }
7826 + } while (0);
7827 +#endif
7828 +
7829 + return 1;
7830 +}
7831 +
7832 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7833 +{
7834 + unsigned long i;
7835 +
7836 + printk(KERN_ERR "PAX: bytes at PC: ");
7837 + for (i = 0; i < 5; i++) {
7838 + unsigned int c;
7839 + if (get_user(c, (unsigned int *)pc+i))
7840 + printk(KERN_CONT "???????? ");
7841 + else
7842 + printk(KERN_CONT "%08x ", c);
7843 + }
7844 + printk("\n");
7845 +}
7846 +#endif
7847 +
7848 int fixup_exception(struct pt_regs *regs)
7849 {
7850 const struct exception_table_entry *fix;
7851 @@ -210,8 +321,33 @@ retry:
7852
7853 good_area:
7854
7855 - if ((vma->vm_flags & acc_type) != acc_type)
7856 + if ((vma->vm_flags & acc_type) != acc_type) {
7857 +
7858 +#ifdef CONFIG_PAX_PAGEEXEC
7859 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7860 + (address & ~3UL) == instruction_pointer(regs))
7861 + {
7862 + up_read(&mm->mmap_sem);
7863 + switch (pax_handle_fetch_fault(regs)) {
7864 +
7865 +#ifdef CONFIG_PAX_EMUPLT
7866 + case 3:
7867 + return;
7868 +#endif
7869 +
7870 +#ifdef CONFIG_PAX_EMUTRAMP
7871 + case 2:
7872 + return;
7873 +#endif
7874 +
7875 + }
7876 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7877 + do_group_exit(SIGKILL);
7878 + }
7879 +#endif
7880 +
7881 goto bad_area;
7882 + }
7883
7884 /*
7885 * If for any reason at all we couldn't handle the fault, make
7886 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7887 index 957bf34..3430cc8 100644
7888 --- a/arch/powerpc/Kconfig
7889 +++ b/arch/powerpc/Kconfig
7890 @@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7891 config KEXEC
7892 bool "kexec system call"
7893 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7894 + depends on !GRKERNSEC_KMEM
7895 help
7896 kexec is a system call that implements the ability to shutdown your
7897 current kernel, and to start another kernel. It is like a reboot
7898 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7899 index e3b1d41..8e81edf 100644
7900 --- a/arch/powerpc/include/asm/atomic.h
7901 +++ b/arch/powerpc/include/asm/atomic.h
7902 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7903 return t1;
7904 }
7905
7906 +#define atomic64_read_unchecked(v) atomic64_read(v)
7907 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7908 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7909 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7910 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7911 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7912 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7913 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7914 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7915 +
7916 #endif /* __powerpc64__ */
7917
7918 #endif /* __KERNEL__ */
7919 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7920 index ed0afc1..0332825 100644
7921 --- a/arch/powerpc/include/asm/cache.h
7922 +++ b/arch/powerpc/include/asm/cache.h
7923 @@ -3,6 +3,7 @@
7924
7925 #ifdef __KERNEL__
7926
7927 +#include <linux/const.h>
7928
7929 /* bytes per L1 cache line */
7930 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7931 @@ -22,7 +23,7 @@
7932 #define L1_CACHE_SHIFT 7
7933 #endif
7934
7935 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7936 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7937
7938 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7939
7940 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7941 index 935b5e7..7001d2d 100644
7942 --- a/arch/powerpc/include/asm/elf.h
7943 +++ b/arch/powerpc/include/asm/elf.h
7944 @@ -28,8 +28,19 @@
7945 the loader. We need to make sure that it is out of the way of the program
7946 that it will "exec", and that there is sufficient room for the brk. */
7947
7948 -extern unsigned long randomize_et_dyn(unsigned long base);
7949 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7950 +#define ELF_ET_DYN_BASE (0x20000000)
7951 +
7952 +#ifdef CONFIG_PAX_ASLR
7953 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7954 +
7955 +#ifdef __powerpc64__
7956 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7957 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7958 +#else
7959 +#define PAX_DELTA_MMAP_LEN 15
7960 +#define PAX_DELTA_STACK_LEN 15
7961 +#endif
7962 +#endif
7963
7964 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7965
7966 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7967 (0x7ff >> (PAGE_SHIFT - 12)) : \
7968 (0x3ffff >> (PAGE_SHIFT - 12)))
7969
7970 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7971 -#define arch_randomize_brk arch_randomize_brk
7972 -
7973 -
7974 #ifdef CONFIG_SPU_BASE
7975 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7976 #define NT_SPU 1
7977 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7978 index 8196e9c..d83a9f3 100644
7979 --- a/arch/powerpc/include/asm/exec.h
7980 +++ b/arch/powerpc/include/asm/exec.h
7981 @@ -4,6 +4,6 @@
7982 #ifndef _ASM_POWERPC_EXEC_H
7983 #define _ASM_POWERPC_EXEC_H
7984
7985 -extern unsigned long arch_align_stack(unsigned long sp);
7986 +#define arch_align_stack(x) ((x) & ~0xfUL)
7987
7988 #endif /* _ASM_POWERPC_EXEC_H */
7989 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7990 index 5acabbd..7ea14fa 100644
7991 --- a/arch/powerpc/include/asm/kmap_types.h
7992 +++ b/arch/powerpc/include/asm/kmap_types.h
7993 @@ -10,7 +10,7 @@
7994 * 2 of the License, or (at your option) any later version.
7995 */
7996
7997 -#define KM_TYPE_NR 16
7998 +#define KM_TYPE_NR 17
7999
8000 #endif /* __KERNEL__ */
8001 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8002 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8003 index b8da913..60b608a 100644
8004 --- a/arch/powerpc/include/asm/local.h
8005 +++ b/arch/powerpc/include/asm/local.h
8006 @@ -9,15 +9,26 @@ typedef struct
8007 atomic_long_t a;
8008 } local_t;
8009
8010 +typedef struct
8011 +{
8012 + atomic_long_unchecked_t a;
8013 +} local_unchecked_t;
8014 +
8015 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8016
8017 #define local_read(l) atomic_long_read(&(l)->a)
8018 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8019 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8020 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8021
8022 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8023 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8024 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8025 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8026 #define local_inc(l) atomic_long_inc(&(l)->a)
8027 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8028 #define local_dec(l) atomic_long_dec(&(l)->a)
8029 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8030
8031 static __inline__ long local_add_return(long a, local_t *l)
8032 {
8033 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8034
8035 return t;
8036 }
8037 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8038
8039 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8040
8041 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8042
8043 return t;
8044 }
8045 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8046
8047 static __inline__ long local_inc_return(local_t *l)
8048 {
8049 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8050
8051 #define local_cmpxchg(l, o, n) \
8052 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8053 +#define local_cmpxchg_unchecked(l, o, n) \
8054 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8055 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8056
8057 /**
8058 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8059 index 8565c25..2865190 100644
8060 --- a/arch/powerpc/include/asm/mman.h
8061 +++ b/arch/powerpc/include/asm/mman.h
8062 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8063 }
8064 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8065
8066 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8067 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8068 {
8069 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8070 }
8071 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8072 index 32e4e21..62afb12 100644
8073 --- a/arch/powerpc/include/asm/page.h
8074 +++ b/arch/powerpc/include/asm/page.h
8075 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8076 * and needs to be executable. This means the whole heap ends
8077 * up being executable.
8078 */
8079 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8080 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8081 +#define VM_DATA_DEFAULT_FLAGS32 \
8082 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8083 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8084
8085 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8086 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8087 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8088 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8089 #endif
8090
8091 +#define ktla_ktva(addr) (addr)
8092 +#define ktva_ktla(addr) (addr)
8093 +
8094 #ifndef CONFIG_PPC_BOOK3S_64
8095 /*
8096 * Use the top bit of the higher-level page table entries to indicate whether
8097 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8098 index 88693ce..ac6f9ab 100644
8099 --- a/arch/powerpc/include/asm/page_64.h
8100 +++ b/arch/powerpc/include/asm/page_64.h
8101 @@ -153,15 +153,18 @@ do { \
8102 * stack by default, so in the absence of a PT_GNU_STACK program header
8103 * we turn execute permission off.
8104 */
8105 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8106 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8107 +#define VM_STACK_DEFAULT_FLAGS32 \
8108 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8109 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8110
8111 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8112 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8113
8114 +#ifndef CONFIG_PAX_PAGEEXEC
8115 #define VM_STACK_DEFAULT_FLAGS \
8116 (is_32bit_task() ? \
8117 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8118 +#endif
8119
8120 #include <asm-generic/getorder.h>
8121
8122 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8123 index 4b0be20..c15a27d 100644
8124 --- a/arch/powerpc/include/asm/pgalloc-64.h
8125 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8126 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8127 #ifndef CONFIG_PPC_64K_PAGES
8128
8129 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8130 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8131
8132 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8133 {
8134 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8135 pud_set(pud, (unsigned long)pmd);
8136 }
8137
8138 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8139 +{
8140 + pud_populate(mm, pud, pmd);
8141 +}
8142 +
8143 #define pmd_populate(mm, pmd, pte_page) \
8144 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8145 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8146 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8147 #endif
8148
8149 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8150 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8151
8152 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8153 pte_t *pte)
8154 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8155 index 3ebb188..e17dddf 100644
8156 --- a/arch/powerpc/include/asm/pgtable.h
8157 +++ b/arch/powerpc/include/asm/pgtable.h
8158 @@ -2,6 +2,7 @@
8159 #define _ASM_POWERPC_PGTABLE_H
8160 #ifdef __KERNEL__
8161
8162 +#include <linux/const.h>
8163 #ifndef __ASSEMBLY__
8164 #include <linux/mmdebug.h>
8165 #include <asm/processor.h> /* For TASK_SIZE */
8166 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8167 index 4aad413..85d86bf 100644
8168 --- a/arch/powerpc/include/asm/pte-hash32.h
8169 +++ b/arch/powerpc/include/asm/pte-hash32.h
8170 @@ -21,6 +21,7 @@
8171 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8172 #define _PAGE_USER 0x004 /* usermode access allowed */
8173 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8174 +#define _PAGE_EXEC _PAGE_GUARDED
8175 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8176 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8177 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8178 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8179 index ce17815..c5574cc 100644
8180 --- a/arch/powerpc/include/asm/reg.h
8181 +++ b/arch/powerpc/include/asm/reg.h
8182 @@ -249,6 +249,7 @@
8183 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8184 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8185 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8186 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8187 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8188 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8189 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8190 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8191 index 084e080..9415a3d 100644
8192 --- a/arch/powerpc/include/asm/smp.h
8193 +++ b/arch/powerpc/include/asm/smp.h
8194 @@ -51,7 +51,7 @@ struct smp_ops_t {
8195 int (*cpu_disable)(void);
8196 void (*cpu_die)(unsigned int nr);
8197 int (*cpu_bootable)(unsigned int nr);
8198 -};
8199 +} __no_const;
8200
8201 extern void smp_send_debugger_break(void);
8202 extern void start_secondary_resume(void);
8203 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8204 index b034ecd..af7e31f 100644
8205 --- a/arch/powerpc/include/asm/thread_info.h
8206 +++ b/arch/powerpc/include/asm/thread_info.h
8207 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8208 #if defined(CONFIG_PPC64)
8209 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8210 #endif
8211 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8212 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8213
8214 /* as above, but as bit values */
8215 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8216 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8217 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8218 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8219 #define _TIF_NOHZ (1<<TIF_NOHZ)
8220 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8221 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8222 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8223 - _TIF_NOHZ)
8224 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8225
8226 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8227 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8228 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8229 index 9485b43..3bd3c16 100644
8230 --- a/arch/powerpc/include/asm/uaccess.h
8231 +++ b/arch/powerpc/include/asm/uaccess.h
8232 @@ -58,6 +58,7 @@
8233
8234 #endif
8235
8236 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8237 #define access_ok(type, addr, size) \
8238 (__chk_user_ptr(addr), \
8239 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8240 @@ -318,52 +319,6 @@ do { \
8241 extern unsigned long __copy_tofrom_user(void __user *to,
8242 const void __user *from, unsigned long size);
8243
8244 -#ifndef __powerpc64__
8245 -
8246 -static inline unsigned long copy_from_user(void *to,
8247 - const void __user *from, unsigned long n)
8248 -{
8249 - unsigned long over;
8250 -
8251 - if (access_ok(VERIFY_READ, from, n))
8252 - return __copy_tofrom_user((__force void __user *)to, from, n);
8253 - if ((unsigned long)from < TASK_SIZE) {
8254 - over = (unsigned long)from + n - TASK_SIZE;
8255 - return __copy_tofrom_user((__force void __user *)to, from,
8256 - n - over) + over;
8257 - }
8258 - return n;
8259 -}
8260 -
8261 -static inline unsigned long copy_to_user(void __user *to,
8262 - const void *from, unsigned long n)
8263 -{
8264 - unsigned long over;
8265 -
8266 - if (access_ok(VERIFY_WRITE, to, n))
8267 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8268 - if ((unsigned long)to < TASK_SIZE) {
8269 - over = (unsigned long)to + n - TASK_SIZE;
8270 - return __copy_tofrom_user(to, (__force void __user *)from,
8271 - n - over) + over;
8272 - }
8273 - return n;
8274 -}
8275 -
8276 -#else /* __powerpc64__ */
8277 -
8278 -#define __copy_in_user(to, from, size) \
8279 - __copy_tofrom_user((to), (from), (size))
8280 -
8281 -extern unsigned long copy_from_user(void *to, const void __user *from,
8282 - unsigned long n);
8283 -extern unsigned long copy_to_user(void __user *to, const void *from,
8284 - unsigned long n);
8285 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8286 - unsigned long n);
8287 -
8288 -#endif /* __powerpc64__ */
8289 -
8290 static inline unsigned long __copy_from_user_inatomic(void *to,
8291 const void __user *from, unsigned long n)
8292 {
8293 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8294 if (ret == 0)
8295 return 0;
8296 }
8297 +
8298 + if (!__builtin_constant_p(n))
8299 + check_object_size(to, n, false);
8300 +
8301 return __copy_tofrom_user((__force void __user *)to, from, n);
8302 }
8303
8304 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8305 if (ret == 0)
8306 return 0;
8307 }
8308 +
8309 + if (!__builtin_constant_p(n))
8310 + check_object_size(from, n, true);
8311 +
8312 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8313 }
8314
8315 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8316 return __copy_to_user_inatomic(to, from, size);
8317 }
8318
8319 +#ifndef __powerpc64__
8320 +
8321 +static inline unsigned long __must_check copy_from_user(void *to,
8322 + const void __user *from, unsigned long n)
8323 +{
8324 + unsigned long over;
8325 +
8326 + if ((long)n < 0)
8327 + return n;
8328 +
8329 + if (access_ok(VERIFY_READ, from, n)) {
8330 + if (!__builtin_constant_p(n))
8331 + check_object_size(to, n, false);
8332 + return __copy_tofrom_user((__force void __user *)to, from, n);
8333 + }
8334 + if ((unsigned long)from < TASK_SIZE) {
8335 + over = (unsigned long)from + n - TASK_SIZE;
8336 + if (!__builtin_constant_p(n - over))
8337 + check_object_size(to, n - over, false);
8338 + return __copy_tofrom_user((__force void __user *)to, from,
8339 + n - over) + over;
8340 + }
8341 + return n;
8342 +}
8343 +
8344 +static inline unsigned long __must_check copy_to_user(void __user *to,
8345 + const void *from, unsigned long n)
8346 +{
8347 + unsigned long over;
8348 +
8349 + if ((long)n < 0)
8350 + return n;
8351 +
8352 + if (access_ok(VERIFY_WRITE, to, n)) {
8353 + if (!__builtin_constant_p(n))
8354 + check_object_size(from, n, true);
8355 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8356 + }
8357 + if ((unsigned long)to < TASK_SIZE) {
8358 + over = (unsigned long)to + n - TASK_SIZE;
8359 + if (!__builtin_constant_p(n))
8360 + check_object_size(from, n - over, true);
8361 + return __copy_tofrom_user(to, (__force void __user *)from,
8362 + n - over) + over;
8363 + }
8364 + return n;
8365 +}
8366 +
8367 +#else /* __powerpc64__ */
8368 +
8369 +#define __copy_in_user(to, from, size) \
8370 + __copy_tofrom_user((to), (from), (size))
8371 +
8372 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8373 +{
8374 + if ((long)n < 0 || n > INT_MAX)
8375 + return n;
8376 +
8377 + if (!__builtin_constant_p(n))
8378 + check_object_size(to, n, false);
8379 +
8380 + if (likely(access_ok(VERIFY_READ, from, n)))
8381 + n = __copy_from_user(to, from, n);
8382 + else
8383 + memset(to, 0, n);
8384 + return n;
8385 +}
8386 +
8387 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8388 +{
8389 + if ((long)n < 0 || n > INT_MAX)
8390 + return n;
8391 +
8392 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8393 + if (!__builtin_constant_p(n))
8394 + check_object_size(from, n, true);
8395 + n = __copy_to_user(to, from, n);
8396 + }
8397 + return n;
8398 +}
8399 +
8400 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8401 + unsigned long n);
8402 +
8403 +#endif /* __powerpc64__ */
8404 +
8405 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8406
8407 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8408 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8409 index fcc9a89..07be2bb 100644
8410 --- a/arch/powerpc/kernel/Makefile
8411 +++ b/arch/powerpc/kernel/Makefile
8412 @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8413 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8414 endif
8415
8416 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8417 +
8418 obj-y := cputable.o ptrace.o syscalls.o \
8419 irq.o align.o signal_32.o pmc.o vdso.o \
8420 process.o systbl.o idle.o \
8421 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8422 index 063b65d..7a26e9d 100644
8423 --- a/arch/powerpc/kernel/exceptions-64e.S
8424 +++ b/arch/powerpc/kernel/exceptions-64e.S
8425 @@ -771,6 +771,7 @@ storage_fault_common:
8426 std r14,_DAR(r1)
8427 std r15,_DSISR(r1)
8428 addi r3,r1,STACK_FRAME_OVERHEAD
8429 + bl .save_nvgprs
8430 mr r4,r14
8431 mr r5,r15
8432 ld r14,PACA_EXGEN+EX_R14(r13)
8433 @@ -779,8 +780,7 @@ storage_fault_common:
8434 cmpdi r3,0
8435 bne- 1f
8436 b .ret_from_except_lite
8437 -1: bl .save_nvgprs
8438 - mr r5,r3
8439 +1: mr r5,r3
8440 addi r3,r1,STACK_FRAME_OVERHEAD
8441 ld r4,_DAR(r1)
8442 bl .bad_page_fault
8443 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8444 index 38d5073..f00af8d 100644
8445 --- a/arch/powerpc/kernel/exceptions-64s.S
8446 +++ b/arch/powerpc/kernel/exceptions-64s.S
8447 @@ -1584,10 +1584,10 @@ handle_page_fault:
8448 11: ld r4,_DAR(r1)
8449 ld r5,_DSISR(r1)
8450 addi r3,r1,STACK_FRAME_OVERHEAD
8451 + bl .save_nvgprs
8452 bl .do_page_fault
8453 cmpdi r3,0
8454 beq+ 12f
8455 - bl .save_nvgprs
8456 mr r5,r3
8457 addi r3,r1,STACK_FRAME_OVERHEAD
8458 lwz r4,_DAR(r1)
8459 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8460 index 1d0848b..d74685f 100644
8461 --- a/arch/powerpc/kernel/irq.c
8462 +++ b/arch/powerpc/kernel/irq.c
8463 @@ -447,6 +447,8 @@ void migrate_irqs(void)
8464 }
8465 #endif
8466
8467 +extern void gr_handle_kernel_exploit(void);
8468 +
8469 static inline void check_stack_overflow(void)
8470 {
8471 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8472 @@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8473 printk("do_IRQ: stack overflow: %ld\n",
8474 sp - sizeof(struct thread_info));
8475 dump_stack();
8476 + gr_handle_kernel_exploit();
8477 }
8478 #endif
8479 }
8480 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8481 index 6cff040..74ac5d1 100644
8482 --- a/arch/powerpc/kernel/module_32.c
8483 +++ b/arch/powerpc/kernel/module_32.c
8484 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8485 me->arch.core_plt_section = i;
8486 }
8487 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8488 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8489 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8490 return -ENOEXEC;
8491 }
8492
8493 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8494
8495 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8496 /* Init, or core PLT? */
8497 - if (location >= mod->module_core
8498 - && location < mod->module_core + mod->core_size)
8499 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8500 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8501 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8502 - else
8503 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8504 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8505 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8506 + else {
8507 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8508 + return ~0UL;
8509 + }
8510
8511 /* Find this entry, or if that fails, the next avail. entry */
8512 while (entry->jump[0]) {
8513 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8514 }
8515 #ifdef CONFIG_DYNAMIC_FTRACE
8516 module->arch.tramp =
8517 - do_plt_call(module->module_core,
8518 + do_plt_call(module->module_core_rx,
8519 (unsigned long)ftrace_caller,
8520 sechdrs, module);
8521 #endif
8522 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8523 index 31d0215..206af70 100644
8524 --- a/arch/powerpc/kernel/process.c
8525 +++ b/arch/powerpc/kernel/process.c
8526 @@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8527 * Lookup NIP late so we have the best change of getting the
8528 * above info out without failing
8529 */
8530 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8531 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8532 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8533 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8534 #endif
8535 show_stack(current, (unsigned long *) regs->gpr[1]);
8536 if (!user_mode(regs))
8537 @@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8538 newsp = stack[0];
8539 ip = stack[STACK_FRAME_LR_SAVE];
8540 if (!firstframe || ip != lr) {
8541 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8542 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8543 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8544 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8545 - printk(" (%pS)",
8546 + printk(" (%pA)",
8547 (void *)current->ret_stack[curr_frame].ret);
8548 curr_frame--;
8549 }
8550 @@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8551 struct pt_regs *regs = (struct pt_regs *)
8552 (sp + STACK_FRAME_OVERHEAD);
8553 lr = regs->link;
8554 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8555 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8556 regs->trap, (void *)regs->nip, (void *)lr);
8557 firstframe = 1;
8558 }
8559 @@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8560 mtspr(SPRN_CTRLT, ctrl);
8561 }
8562 #endif /* CONFIG_PPC64 */
8563 -
8564 -unsigned long arch_align_stack(unsigned long sp)
8565 -{
8566 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8567 - sp -= get_random_int() & ~PAGE_MASK;
8568 - return sp & ~0xf;
8569 -}
8570 -
8571 -static inline unsigned long brk_rnd(void)
8572 -{
8573 - unsigned long rnd = 0;
8574 -
8575 - /* 8MB for 32bit, 1GB for 64bit */
8576 - if (is_32bit_task())
8577 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8578 - else
8579 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8580 -
8581 - return rnd << PAGE_SHIFT;
8582 -}
8583 -
8584 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8585 -{
8586 - unsigned long base = mm->brk;
8587 - unsigned long ret;
8588 -
8589 -#ifdef CONFIG_PPC_STD_MMU_64
8590 - /*
8591 - * If we are using 1TB segments and we are allowed to randomise
8592 - * the heap, we can put it above 1TB so it is backed by a 1TB
8593 - * segment. Otherwise the heap will be in the bottom 1TB
8594 - * which always uses 256MB segments and this may result in a
8595 - * performance penalty.
8596 - */
8597 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8598 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8599 -#endif
8600 -
8601 - ret = PAGE_ALIGN(base + brk_rnd());
8602 -
8603 - if (ret < mm->brk)
8604 - return mm->brk;
8605 -
8606 - return ret;
8607 -}
8608 -
8609 -unsigned long randomize_et_dyn(unsigned long base)
8610 -{
8611 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8612 -
8613 - if (ret < base)
8614 - return base;
8615 -
8616 - return ret;
8617 -}
8618 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8619 index 2e3d2bf..35df241 100644
8620 --- a/arch/powerpc/kernel/ptrace.c
8621 +++ b/arch/powerpc/kernel/ptrace.c
8622 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8623 return ret;
8624 }
8625
8626 +#ifdef CONFIG_GRKERNSEC_SETXID
8627 +extern void gr_delayed_cred_worker(void);
8628 +#endif
8629 +
8630 /*
8631 * We must return the syscall number to actually look up in the table.
8632 * This can be -1L to skip running any syscall at all.
8633 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8634
8635 secure_computing_strict(regs->gpr[0]);
8636
8637 +#ifdef CONFIG_GRKERNSEC_SETXID
8638 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8639 + gr_delayed_cred_worker();
8640 +#endif
8641 +
8642 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8643 tracehook_report_syscall_entry(regs))
8644 /*
8645 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8646 {
8647 int step;
8648
8649 +#ifdef CONFIG_GRKERNSEC_SETXID
8650 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8651 + gr_delayed_cred_worker();
8652 +#endif
8653 +
8654 audit_syscall_exit(regs);
8655
8656 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8657 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8658 index 4e47db6..6dcc96e 100644
8659 --- a/arch/powerpc/kernel/signal_32.c
8660 +++ b/arch/powerpc/kernel/signal_32.c
8661 @@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8662 /* Save user registers on the stack */
8663 frame = &rt_sf->uc.uc_mcontext;
8664 addr = frame;
8665 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8666 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8667 sigret = 0;
8668 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8669 } else {
8670 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8671 index d501dc4..e5a0de0 100644
8672 --- a/arch/powerpc/kernel/signal_64.c
8673 +++ b/arch/powerpc/kernel/signal_64.c
8674 @@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8675 current->thread.fp_state.fpscr = 0;
8676
8677 /* Set up to return from userspace. */
8678 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8679 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8680 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8681 } else {
8682 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8683 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8684 index 33cd7a0..d615344 100644
8685 --- a/arch/powerpc/kernel/traps.c
8686 +++ b/arch/powerpc/kernel/traps.c
8687 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8688 return flags;
8689 }
8690
8691 +extern void gr_handle_kernel_exploit(void);
8692 +
8693 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8694 int signr)
8695 {
8696 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8697 panic("Fatal exception in interrupt");
8698 if (panic_on_oops)
8699 panic("Fatal exception");
8700 +
8701 + gr_handle_kernel_exploit();
8702 +
8703 do_exit(signr);
8704 }
8705
8706 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8707 index 094e45c..d82b848 100644
8708 --- a/arch/powerpc/kernel/vdso.c
8709 +++ b/arch/powerpc/kernel/vdso.c
8710 @@ -35,6 +35,7 @@
8711 #include <asm/vdso.h>
8712 #include <asm/vdso_datapage.h>
8713 #include <asm/setup.h>
8714 +#include <asm/mman.h>
8715
8716 #undef DEBUG
8717
8718 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8719 vdso_base = VDSO32_MBASE;
8720 #endif
8721
8722 - current->mm->context.vdso_base = 0;
8723 + current->mm->context.vdso_base = ~0UL;
8724
8725 /* vDSO has a problem and was disabled, just don't "enable" it for the
8726 * process
8727 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8728 vdso_base = get_unmapped_area(NULL, vdso_base,
8729 (vdso_pages << PAGE_SHIFT) +
8730 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8731 - 0, 0);
8732 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8733 if (IS_ERR_VALUE(vdso_base)) {
8734 rc = vdso_base;
8735 goto fail_mmapsem;
8736 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8737 index 3cf541a..ab2d825 100644
8738 --- a/arch/powerpc/kvm/powerpc.c
8739 +++ b/arch/powerpc/kvm/powerpc.c
8740 @@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8741 }
8742 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8743
8744 -int kvm_arch_init(void *opaque)
8745 +int kvm_arch_init(const void *opaque)
8746 {
8747 return 0;
8748 }
8749 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8750 index 5eea6f3..5d10396 100644
8751 --- a/arch/powerpc/lib/usercopy_64.c
8752 +++ b/arch/powerpc/lib/usercopy_64.c
8753 @@ -9,22 +9,6 @@
8754 #include <linux/module.h>
8755 #include <asm/uaccess.h>
8756
8757 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8758 -{
8759 - if (likely(access_ok(VERIFY_READ, from, n)))
8760 - n = __copy_from_user(to, from, n);
8761 - else
8762 - memset(to, 0, n);
8763 - return n;
8764 -}
8765 -
8766 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8767 -{
8768 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8769 - n = __copy_to_user(to, from, n);
8770 - return n;
8771 -}
8772 -
8773 unsigned long copy_in_user(void __user *to, const void __user *from,
8774 unsigned long n)
8775 {
8776 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8777 return n;
8778 }
8779
8780 -EXPORT_SYMBOL(copy_from_user);
8781 -EXPORT_SYMBOL(copy_to_user);
8782 EXPORT_SYMBOL(copy_in_user);
8783
8784 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8785 index 51ab9e7..7d3c78b 100644
8786 --- a/arch/powerpc/mm/fault.c
8787 +++ b/arch/powerpc/mm/fault.c
8788 @@ -33,6 +33,10 @@
8789 #include <linux/magic.h>
8790 #include <linux/ratelimit.h>
8791 #include <linux/context_tracking.h>
8792 +#include <linux/slab.h>
8793 +#include <linux/pagemap.h>
8794 +#include <linux/compiler.h>
8795 +#include <linux/unistd.h>
8796
8797 #include <asm/firmware.h>
8798 #include <asm/page.h>
8799 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8800 }
8801 #endif
8802
8803 +#ifdef CONFIG_PAX_PAGEEXEC
8804 +/*
8805 + * PaX: decide what to do with offenders (regs->nip = fault address)
8806 + *
8807 + * returns 1 when task should be killed
8808 + */
8809 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8810 +{
8811 + return 1;
8812 +}
8813 +
8814 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8815 +{
8816 + unsigned long i;
8817 +
8818 + printk(KERN_ERR "PAX: bytes at PC: ");
8819 + for (i = 0; i < 5; i++) {
8820 + unsigned int c;
8821 + if (get_user(c, (unsigned int __user *)pc+i))
8822 + printk(KERN_CONT "???????? ");
8823 + else
8824 + printk(KERN_CONT "%08x ", c);
8825 + }
8826 + printk("\n");
8827 +}
8828 +#endif
8829 +
8830 /*
8831 * Check whether the instruction at regs->nip is a store using
8832 * an update addressing form which will update r1.
8833 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8834 * indicate errors in DSISR but can validly be set in SRR1.
8835 */
8836 if (trap == 0x400)
8837 - error_code &= 0x48200000;
8838 + error_code &= 0x58200000;
8839 else
8840 is_write = error_code & DSISR_ISSTORE;
8841 #else
8842 @@ -378,7 +409,7 @@ good_area:
8843 * "undefined". Of those that can be set, this is the only
8844 * one which seems bad.
8845 */
8846 - if (error_code & 0x10000000)
8847 + if (error_code & DSISR_GUARDED)
8848 /* Guarded storage error. */
8849 goto bad_area;
8850 #endif /* CONFIG_8xx */
8851 @@ -393,7 +424,7 @@ good_area:
8852 * processors use the same I/D cache coherency mechanism
8853 * as embedded.
8854 */
8855 - if (error_code & DSISR_PROTFAULT)
8856 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8857 goto bad_area;
8858 #endif /* CONFIG_PPC_STD_MMU */
8859
8860 @@ -483,6 +514,23 @@ bad_area:
8861 bad_area_nosemaphore:
8862 /* User mode accesses cause a SIGSEGV */
8863 if (user_mode(regs)) {
8864 +
8865 +#ifdef CONFIG_PAX_PAGEEXEC
8866 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8867 +#ifdef CONFIG_PPC_STD_MMU
8868 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8869 +#else
8870 + if (is_exec && regs->nip == address) {
8871 +#endif
8872 + switch (pax_handle_fetch_fault(regs)) {
8873 + }
8874 +
8875 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8876 + do_group_exit(SIGKILL);
8877 + }
8878 + }
8879 +#endif
8880 +
8881 _exception(SIGSEGV, regs, code, address);
8882 goto bail;
8883 }
8884 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8885 index cb8bdbe..cde4bc7 100644
8886 --- a/arch/powerpc/mm/mmap.c
8887 +++ b/arch/powerpc/mm/mmap.c
8888 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8889 return sysctl_legacy_va_layout;
8890 }
8891
8892 -static unsigned long mmap_rnd(void)
8893 +static unsigned long mmap_rnd(struct mm_struct *mm)
8894 {
8895 unsigned long rnd = 0;
8896
8897 +#ifdef CONFIG_PAX_RANDMMAP
8898 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8899 +#endif
8900 +
8901 if (current->flags & PF_RANDOMIZE) {
8902 /* 8MB for 32bit, 1GB for 64bit */
8903 if (is_32bit_task())
8904 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8905 return rnd << PAGE_SHIFT;
8906 }
8907
8908 -static inline unsigned long mmap_base(void)
8909 +static inline unsigned long mmap_base(struct mm_struct *mm)
8910 {
8911 unsigned long gap = rlimit(RLIMIT_STACK);
8912
8913 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8914 else if (gap > MAX_GAP)
8915 gap = MAX_GAP;
8916
8917 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8918 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8919 }
8920
8921 /*
8922 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8923 */
8924 if (mmap_is_legacy()) {
8925 mm->mmap_base = TASK_UNMAPPED_BASE;
8926 +
8927 +#ifdef CONFIG_PAX_RANDMMAP
8928 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8929 + mm->mmap_base += mm->delta_mmap;
8930 +#endif
8931 +
8932 mm->get_unmapped_area = arch_get_unmapped_area;
8933 } else {
8934 - mm->mmap_base = mmap_base();
8935 + mm->mmap_base = mmap_base(mm);
8936 +
8937 +#ifdef CONFIG_PAX_RANDMMAP
8938 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8939 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8940 +#endif
8941 +
8942 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8943 }
8944 }
8945 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8946 index b0c75cc..ef7fb93 100644
8947 --- a/arch/powerpc/mm/slice.c
8948 +++ b/arch/powerpc/mm/slice.c
8949 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8950 if ((mm->task_size - len) < addr)
8951 return 0;
8952 vma = find_vma(mm, addr);
8953 - return (!vma || (addr + len) <= vma->vm_start);
8954 + return check_heap_stack_gap(vma, addr, len, 0);
8955 }
8956
8957 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8958 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8959 info.align_offset = 0;
8960
8961 addr = TASK_UNMAPPED_BASE;
8962 +
8963 +#ifdef CONFIG_PAX_RANDMMAP
8964 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8965 + addr += mm->delta_mmap;
8966 +#endif
8967 +
8968 while (addr < TASK_SIZE) {
8969 info.low_limit = addr;
8970 if (!slice_scan_available(addr, available, 1, &addr))
8971 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8972 if (fixed && addr > (mm->task_size - len))
8973 return -ENOMEM;
8974
8975 +#ifdef CONFIG_PAX_RANDMMAP
8976 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8977 + addr = 0;
8978 +#endif
8979 +
8980 /* If hint, make sure it matches our alignment restrictions */
8981 if (!fixed && addr) {
8982 addr = _ALIGN_UP(addr, 1ul << pshift);
8983 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8984 index 4278acf..67fd0e6 100644
8985 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8986 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8987 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8988 }
8989
8990 static struct pci_ops scc_pciex_pci_ops = {
8991 - scc_pciex_read_config,
8992 - scc_pciex_write_config,
8993 + .read = scc_pciex_read_config,
8994 + .write = scc_pciex_write_config,
8995 };
8996
8997 static void pciex_clear_intr_all(unsigned int __iomem *base)
8998 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8999 index 9098692..3d54cd1 100644
9000 --- a/arch/powerpc/platforms/cell/spufs/file.c
9001 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9002 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9003 return VM_FAULT_NOPAGE;
9004 }
9005
9006 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9007 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9008 unsigned long address,
9009 - void *buf, int len, int write)
9010 + void *buf, size_t len, int write)
9011 {
9012 struct spu_context *ctx = vma->vm_file->private_data;
9013 unsigned long offset = address - vma->vm_start;
9014 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9015 index 1d47061..0714963 100644
9016 --- a/arch/s390/include/asm/atomic.h
9017 +++ b/arch/s390/include/asm/atomic.h
9018 @@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9019 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9020 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9021
9022 +#define atomic64_read_unchecked(v) atomic64_read(v)
9023 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9024 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9025 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9026 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9027 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9028 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9029 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9030 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9031 +
9032 #define smp_mb__before_atomic_dec() smp_mb()
9033 #define smp_mb__after_atomic_dec() smp_mb()
9034 #define smp_mb__before_atomic_inc() smp_mb()
9035 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9036 index 4d7ccac..d03d0ad 100644
9037 --- a/arch/s390/include/asm/cache.h
9038 +++ b/arch/s390/include/asm/cache.h
9039 @@ -9,8 +9,10 @@
9040 #ifndef __ARCH_S390_CACHE_H
9041 #define __ARCH_S390_CACHE_H
9042
9043 -#define L1_CACHE_BYTES 256
9044 +#include <linux/const.h>
9045 +
9046 #define L1_CACHE_SHIFT 8
9047 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9048 #define NET_SKB_PAD 32
9049
9050 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9051 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9052 index 78f4f87..598ce39 100644
9053 --- a/arch/s390/include/asm/elf.h
9054 +++ b/arch/s390/include/asm/elf.h
9055 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9056 the loader. We need to make sure that it is out of the way of the program
9057 that it will "exec", and that there is sufficient room for the brk. */
9058
9059 -extern unsigned long randomize_et_dyn(unsigned long base);
9060 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9061 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9062 +
9063 +#ifdef CONFIG_PAX_ASLR
9064 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9065 +
9066 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9067 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9068 +#endif
9069
9070 /* This yields a mask that user programs can use to figure out what
9071 instruction set this CPU supports. */
9072 @@ -222,9 +228,6 @@ struct linux_binprm;
9073 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9074 int arch_setup_additional_pages(struct linux_binprm *, int);
9075
9076 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9077 -#define arch_randomize_brk arch_randomize_brk
9078 -
9079 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9080
9081 #endif
9082 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9083 index c4a93d6..4d2a9b4 100644
9084 --- a/arch/s390/include/asm/exec.h
9085 +++ b/arch/s390/include/asm/exec.h
9086 @@ -7,6 +7,6 @@
9087 #ifndef __ASM_EXEC_H
9088 #define __ASM_EXEC_H
9089
9090 -extern unsigned long arch_align_stack(unsigned long sp);
9091 +#define arch_align_stack(x) ((x) & ~0xfUL)
9092
9093 #endif /* __ASM_EXEC_H */
9094 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9095 index 79330af..254cf37 100644
9096 --- a/arch/s390/include/asm/uaccess.h
9097 +++ b/arch/s390/include/asm/uaccess.h
9098 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9099 __range_ok((unsigned long)(addr), (size)); \
9100 })
9101
9102 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9103 #define access_ok(type, addr, size) __access_ok(addr, size)
9104
9105 /*
9106 @@ -245,6 +246,10 @@ static inline unsigned long __must_check
9107 copy_to_user(void __user *to, const void *from, unsigned long n)
9108 {
9109 might_fault();
9110 +
9111 + if ((long)n < 0)
9112 + return n;
9113 +
9114 return __copy_to_user(to, from, n);
9115 }
9116
9117 @@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9118 static inline unsigned long __must_check
9119 __copy_from_user(void *to, const void __user *from, unsigned long n)
9120 {
9121 + if ((long)n < 0)
9122 + return n;
9123 +
9124 return uaccess.copy_from_user(n, from, to);
9125 }
9126
9127 @@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9128 static inline unsigned long __must_check
9129 copy_from_user(void *to, const void __user *from, unsigned long n)
9130 {
9131 - unsigned int sz = __compiletime_object_size(to);
9132 + size_t sz = __compiletime_object_size(to);
9133
9134 might_fault();
9135 - if (unlikely(sz != -1 && sz < n)) {
9136 +
9137 + if ((long)n < 0)
9138 + return n;
9139 +
9140 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9141 copy_from_user_overflow();
9142 return n;
9143 }
9144 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9145 index b89b591..fd9609d 100644
9146 --- a/arch/s390/kernel/module.c
9147 +++ b/arch/s390/kernel/module.c
9148 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9149
9150 /* Increase core size by size of got & plt and set start
9151 offsets for got and plt. */
9152 - me->core_size = ALIGN(me->core_size, 4);
9153 - me->arch.got_offset = me->core_size;
9154 - me->core_size += me->arch.got_size;
9155 - me->arch.plt_offset = me->core_size;
9156 - me->core_size += me->arch.plt_size;
9157 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9158 + me->arch.got_offset = me->core_size_rw;
9159 + me->core_size_rw += me->arch.got_size;
9160 + me->arch.plt_offset = me->core_size_rx;
9161 + me->core_size_rx += me->arch.plt_size;
9162 return 0;
9163 }
9164
9165 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9166 if (info->got_initialized == 0) {
9167 Elf_Addr *gotent;
9168
9169 - gotent = me->module_core + me->arch.got_offset +
9170 + gotent = me->module_core_rw + me->arch.got_offset +
9171 info->got_offset;
9172 *gotent = val;
9173 info->got_initialized = 1;
9174 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9175 rc = apply_rela_bits(loc, val, 0, 64, 0);
9176 else if (r_type == R_390_GOTENT ||
9177 r_type == R_390_GOTPLTENT) {
9178 - val += (Elf_Addr) me->module_core - loc;
9179 + val += (Elf_Addr) me->module_core_rw - loc;
9180 rc = apply_rela_bits(loc, val, 1, 32, 1);
9181 }
9182 break;
9183 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9184 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9185 if (info->plt_initialized == 0) {
9186 unsigned int *ip;
9187 - ip = me->module_core + me->arch.plt_offset +
9188 + ip = me->module_core_rx + me->arch.plt_offset +
9189 info->plt_offset;
9190 #ifndef CONFIG_64BIT
9191 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9192 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9193 val - loc + 0xffffUL < 0x1ffffeUL) ||
9194 (r_type == R_390_PLT32DBL &&
9195 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9196 - val = (Elf_Addr) me->module_core +
9197 + val = (Elf_Addr) me->module_core_rx +
9198 me->arch.plt_offset +
9199 info->plt_offset;
9200 val += rela->r_addend - loc;
9201 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9202 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9203 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9204 val = val + rela->r_addend -
9205 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9206 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9207 if (r_type == R_390_GOTOFF16)
9208 rc = apply_rela_bits(loc, val, 0, 16, 0);
9209 else if (r_type == R_390_GOTOFF32)
9210 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9211 break;
9212 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9213 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9214 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9215 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9216 rela->r_addend - loc;
9217 if (r_type == R_390_GOTPC)
9218 rc = apply_rela_bits(loc, val, 1, 32, 0);
9219 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9220 index dd14532..1dfc145 100644
9221 --- a/arch/s390/kernel/process.c
9222 +++ b/arch/s390/kernel/process.c
9223 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9224 }
9225 return 0;
9226 }
9227 -
9228 -unsigned long arch_align_stack(unsigned long sp)
9229 -{
9230 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9231 - sp -= get_random_int() & ~PAGE_MASK;
9232 - return sp & ~0xf;
9233 -}
9234 -
9235 -static inline unsigned long brk_rnd(void)
9236 -{
9237 - /* 8MB for 32bit, 1GB for 64bit */
9238 - if (is_32bit_task())
9239 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9240 - else
9241 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9242 -}
9243 -
9244 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9245 -{
9246 - unsigned long ret;
9247 -
9248 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9249 - return (ret > mm->brk) ? ret : mm->brk;
9250 -}
9251 -
9252 -unsigned long randomize_et_dyn(unsigned long base)
9253 -{
9254 - unsigned long ret;
9255 -
9256 - if (!(current->flags & PF_RANDOMIZE))
9257 - return base;
9258 - ret = PAGE_ALIGN(base + brk_rnd());
9259 - return (ret > base) ? ret : base;
9260 -}
9261 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9262 index 9b436c2..54fbf0a 100644
9263 --- a/arch/s390/mm/mmap.c
9264 +++ b/arch/s390/mm/mmap.c
9265 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9266 */
9267 if (mmap_is_legacy()) {
9268 mm->mmap_base = mmap_base_legacy();
9269 +
9270 +#ifdef CONFIG_PAX_RANDMMAP
9271 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9272 + mm->mmap_base += mm->delta_mmap;
9273 +#endif
9274 +
9275 mm->get_unmapped_area = arch_get_unmapped_area;
9276 } else {
9277 mm->mmap_base = mmap_base();
9278 +
9279 +#ifdef CONFIG_PAX_RANDMMAP
9280 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9281 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9282 +#endif
9283 +
9284 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9285 }
9286 }
9287 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9288 */
9289 if (mmap_is_legacy()) {
9290 mm->mmap_base = mmap_base_legacy();
9291 +
9292 +#ifdef CONFIG_PAX_RANDMMAP
9293 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9294 + mm->mmap_base += mm->delta_mmap;
9295 +#endif
9296 +
9297 mm->get_unmapped_area = s390_get_unmapped_area;
9298 } else {
9299 mm->mmap_base = mmap_base();
9300 +
9301 +#ifdef CONFIG_PAX_RANDMMAP
9302 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9303 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9304 +#endif
9305 +
9306 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9307 }
9308 }
9309 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9310 index ae3d59f..f65f075 100644
9311 --- a/arch/score/include/asm/cache.h
9312 +++ b/arch/score/include/asm/cache.h
9313 @@ -1,7 +1,9 @@
9314 #ifndef _ASM_SCORE_CACHE_H
9315 #define _ASM_SCORE_CACHE_H
9316
9317 +#include <linux/const.h>
9318 +
9319 #define L1_CACHE_SHIFT 4
9320 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9321 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9322
9323 #endif /* _ASM_SCORE_CACHE_H */
9324 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9325 index f9f3cd5..58ff438 100644
9326 --- a/arch/score/include/asm/exec.h
9327 +++ b/arch/score/include/asm/exec.h
9328 @@ -1,6 +1,6 @@
9329 #ifndef _ASM_SCORE_EXEC_H
9330 #define _ASM_SCORE_EXEC_H
9331
9332 -extern unsigned long arch_align_stack(unsigned long sp);
9333 +#define arch_align_stack(x) (x)
9334
9335 #endif /* _ASM_SCORE_EXEC_H */
9336 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9337 index a1519ad3..e8ac1ff 100644
9338 --- a/arch/score/kernel/process.c
9339 +++ b/arch/score/kernel/process.c
9340 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9341
9342 return task_pt_regs(task)->cp0_epc;
9343 }
9344 -
9345 -unsigned long arch_align_stack(unsigned long sp)
9346 -{
9347 - return sp;
9348 -}
9349 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9350 index ef9e555..331bd29 100644
9351 --- a/arch/sh/include/asm/cache.h
9352 +++ b/arch/sh/include/asm/cache.h
9353 @@ -9,10 +9,11 @@
9354 #define __ASM_SH_CACHE_H
9355 #ifdef __KERNEL__
9356
9357 +#include <linux/const.h>
9358 #include <linux/init.h>
9359 #include <cpu/cache.h>
9360
9361 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9362 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9363
9364 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9365
9366 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9367 index 6777177..cb5e44f 100644
9368 --- a/arch/sh/mm/mmap.c
9369 +++ b/arch/sh/mm/mmap.c
9370 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9371 struct mm_struct *mm = current->mm;
9372 struct vm_area_struct *vma;
9373 int do_colour_align;
9374 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9375 struct vm_unmapped_area_info info;
9376
9377 if (flags & MAP_FIXED) {
9378 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9379 if (filp || (flags & MAP_SHARED))
9380 do_colour_align = 1;
9381
9382 +#ifdef CONFIG_PAX_RANDMMAP
9383 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9384 +#endif
9385 +
9386 if (addr) {
9387 if (do_colour_align)
9388 addr = COLOUR_ALIGN(addr, pgoff);
9389 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9390 addr = PAGE_ALIGN(addr);
9391
9392 vma = find_vma(mm, addr);
9393 - if (TASK_SIZE - len >= addr &&
9394 - (!vma || addr + len <= vma->vm_start))
9395 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9396 return addr;
9397 }
9398
9399 info.flags = 0;
9400 info.length = len;
9401 - info.low_limit = TASK_UNMAPPED_BASE;
9402 + info.low_limit = mm->mmap_base;
9403 info.high_limit = TASK_SIZE;
9404 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9405 info.align_offset = pgoff << PAGE_SHIFT;
9406 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9407 struct mm_struct *mm = current->mm;
9408 unsigned long addr = addr0;
9409 int do_colour_align;
9410 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9411 struct vm_unmapped_area_info info;
9412
9413 if (flags & MAP_FIXED) {
9414 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9415 if (filp || (flags & MAP_SHARED))
9416 do_colour_align = 1;
9417
9418 +#ifdef CONFIG_PAX_RANDMMAP
9419 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9420 +#endif
9421 +
9422 /* requesting a specific address */
9423 if (addr) {
9424 if (do_colour_align)
9425 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9426 addr = PAGE_ALIGN(addr);
9427
9428 vma = find_vma(mm, addr);
9429 - if (TASK_SIZE - len >= addr &&
9430 - (!vma || addr + len <= vma->vm_start))
9431 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9432 return addr;
9433 }
9434
9435 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9436 VM_BUG_ON(addr != -ENOMEM);
9437 info.flags = 0;
9438 info.low_limit = TASK_UNMAPPED_BASE;
9439 +
9440 +#ifdef CONFIG_PAX_RANDMMAP
9441 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9442 + info.low_limit += mm->delta_mmap;
9443 +#endif
9444 +
9445 info.high_limit = TASK_SIZE;
9446 addr = vm_unmapped_area(&info);
9447 }
9448 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9449 index be56a24..443328f 100644
9450 --- a/arch/sparc/include/asm/atomic_64.h
9451 +++ b/arch/sparc/include/asm/atomic_64.h
9452 @@ -14,18 +14,40 @@
9453 #define ATOMIC64_INIT(i) { (i) }
9454
9455 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9456 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9457 +{
9458 + return v->counter;
9459 +}
9460 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9461 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9462 +{
9463 + return v->counter;
9464 +}
9465
9466 #define atomic_set(v, i) (((v)->counter) = i)
9467 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9468 +{
9469 + v->counter = i;
9470 +}
9471 #define atomic64_set(v, i) (((v)->counter) = i)
9472 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9473 +{
9474 + v->counter = i;
9475 +}
9476
9477 extern void atomic_add(int, atomic_t *);
9478 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9479 extern void atomic64_add(long, atomic64_t *);
9480 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9481 extern void atomic_sub(int, atomic_t *);
9482 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9483 extern void atomic64_sub(long, atomic64_t *);
9484 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9485
9486 extern int atomic_add_ret(int, atomic_t *);
9487 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9488 extern long atomic64_add_ret(long, atomic64_t *);
9489 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9490 extern int atomic_sub_ret(int, atomic_t *);
9491 extern long atomic64_sub_ret(long, atomic64_t *);
9492
9493 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9494 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9495
9496 #define atomic_inc_return(v) atomic_add_ret(1, v)
9497 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9498 +{
9499 + return atomic_add_ret_unchecked(1, v);
9500 +}
9501 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9502 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9503 +{
9504 + return atomic64_add_ret_unchecked(1, v);
9505 +}
9506
9507 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9508 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9509
9510 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9511 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9512 +{
9513 + return atomic_add_ret_unchecked(i, v);
9514 +}
9515 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9516 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9517 +{
9518 + return atomic64_add_ret_unchecked(i, v);
9519 +}
9520
9521 /*
9522 * atomic_inc_and_test - increment and test
9523 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9524 * other cases.
9525 */
9526 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9527 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9528 +{
9529 + return atomic_inc_return_unchecked(v) == 0;
9530 +}
9531 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9532
9533 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9534 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9535 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9536
9537 #define atomic_inc(v) atomic_add(1, v)
9538 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9539 +{
9540 + atomic_add_unchecked(1, v);
9541 +}
9542 #define atomic64_inc(v) atomic64_add(1, v)
9543 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9544 +{
9545 + atomic64_add_unchecked(1, v);
9546 +}
9547
9548 #define atomic_dec(v) atomic_sub(1, v)
9549 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9550 +{
9551 + atomic_sub_unchecked(1, v);
9552 +}
9553 #define atomic64_dec(v) atomic64_sub(1, v)
9554 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9555 +{
9556 + atomic64_sub_unchecked(1, v);
9557 +}
9558
9559 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9560 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9561
9562 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9563 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9564 +{
9565 + return cmpxchg(&v->counter, old, new);
9566 +}
9567 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9568 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9569 +{
9570 + return xchg(&v->counter, new);
9571 +}
9572
9573 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9574 {
9575 - int c, old;
9576 + int c, old, new;
9577 c = atomic_read(v);
9578 for (;;) {
9579 - if (unlikely(c == (u)))
9580 + if (unlikely(c == u))
9581 break;
9582 - old = atomic_cmpxchg((v), c, c + (a));
9583 +
9584 + asm volatile("addcc %2, %0, %0\n"
9585 +
9586 +#ifdef CONFIG_PAX_REFCOUNT
9587 + "tvs %%icc, 6\n"
9588 +#endif
9589 +
9590 + : "=r" (new)
9591 + : "0" (c), "ir" (a)
9592 + : "cc");
9593 +
9594 + old = atomic_cmpxchg(v, c, new);
9595 if (likely(old == c))
9596 break;
9597 c = old;
9598 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9599 #define atomic64_cmpxchg(v, o, n) \
9600 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9601 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9602 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9603 +{
9604 + return xchg(&v->counter, new);
9605 +}
9606
9607 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9608 {
9609 - long c, old;
9610 + long c, old, new;
9611 c = atomic64_read(v);
9612 for (;;) {
9613 - if (unlikely(c == (u)))
9614 + if (unlikely(c == u))
9615 break;
9616 - old = atomic64_cmpxchg((v), c, c + (a));
9617 +
9618 + asm volatile("addcc %2, %0, %0\n"
9619 +
9620 +#ifdef CONFIG_PAX_REFCOUNT
9621 + "tvs %%xcc, 6\n"
9622 +#endif
9623 +
9624 + : "=r" (new)
9625 + : "0" (c), "ir" (a)
9626 + : "cc");
9627 +
9628 + old = atomic64_cmpxchg(v, c, new);
9629 if (likely(old == c))
9630 break;
9631 c = old;
9632 }
9633 - return c != (u);
9634 + return c != u;
9635 }
9636
9637 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9638 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9639 index 5bb6991..5c2132e 100644
9640 --- a/arch/sparc/include/asm/cache.h
9641 +++ b/arch/sparc/include/asm/cache.h
9642 @@ -7,10 +7,12 @@
9643 #ifndef _SPARC_CACHE_H
9644 #define _SPARC_CACHE_H
9645
9646 +#include <linux/const.h>
9647 +
9648 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9649
9650 #define L1_CACHE_SHIFT 5
9651 -#define L1_CACHE_BYTES 32
9652 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9653
9654 #ifdef CONFIG_SPARC32
9655 #define SMP_CACHE_BYTES_SHIFT 5
9656 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9657 index a24e41f..47677ff 100644
9658 --- a/arch/sparc/include/asm/elf_32.h
9659 +++ b/arch/sparc/include/asm/elf_32.h
9660 @@ -114,6 +114,13 @@ typedef struct {
9661
9662 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9663
9664 +#ifdef CONFIG_PAX_ASLR
9665 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9666 +
9667 +#define PAX_DELTA_MMAP_LEN 16
9668 +#define PAX_DELTA_STACK_LEN 16
9669 +#endif
9670 +
9671 /* This yields a mask that user programs can use to figure out what
9672 instruction set this cpu supports. This can NOT be done in userspace
9673 on Sparc. */
9674 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9675 index 370ca1e..d4f4a98 100644
9676 --- a/arch/sparc/include/asm/elf_64.h
9677 +++ b/arch/sparc/include/asm/elf_64.h
9678 @@ -189,6 +189,13 @@ typedef struct {
9679 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9680 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9681
9682 +#ifdef CONFIG_PAX_ASLR
9683 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9684 +
9685 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9686 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9687 +#endif
9688 +
9689 extern unsigned long sparc64_elf_hwcap;
9690 #define ELF_HWCAP sparc64_elf_hwcap
9691
9692 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9693 index 9b1c36d..209298b 100644
9694 --- a/arch/sparc/include/asm/pgalloc_32.h
9695 +++ b/arch/sparc/include/asm/pgalloc_32.h
9696 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9697 }
9698
9699 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9700 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9701
9702 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9703 unsigned long address)
9704 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9705 index bcfe063..b333142 100644
9706 --- a/arch/sparc/include/asm/pgalloc_64.h
9707 +++ b/arch/sparc/include/asm/pgalloc_64.h
9708 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9709 }
9710
9711 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9712 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9713
9714 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9715 {
9716 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9717 index 59ba6f6..4518128 100644
9718 --- a/arch/sparc/include/asm/pgtable.h
9719 +++ b/arch/sparc/include/asm/pgtable.h
9720 @@ -5,4 +5,8 @@
9721 #else
9722 #include <asm/pgtable_32.h>
9723 #endif
9724 +
9725 +#define ktla_ktva(addr) (addr)
9726 +#define ktva_ktla(addr) (addr)
9727 +
9728 #endif
9729 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9730 index 502f632..da1917f 100644
9731 --- a/arch/sparc/include/asm/pgtable_32.h
9732 +++ b/arch/sparc/include/asm/pgtable_32.h
9733 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9734 #define PAGE_SHARED SRMMU_PAGE_SHARED
9735 #define PAGE_COPY SRMMU_PAGE_COPY
9736 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9737 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9738 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9739 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9740 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9741
9742 /* Top-level page directory - dummy used by init-mm.
9743 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9744
9745 /* xwr */
9746 #define __P000 PAGE_NONE
9747 -#define __P001 PAGE_READONLY
9748 -#define __P010 PAGE_COPY
9749 -#define __P011 PAGE_COPY
9750 +#define __P001 PAGE_READONLY_NOEXEC
9751 +#define __P010 PAGE_COPY_NOEXEC
9752 +#define __P011 PAGE_COPY_NOEXEC
9753 #define __P100 PAGE_READONLY
9754 #define __P101 PAGE_READONLY
9755 #define __P110 PAGE_COPY
9756 #define __P111 PAGE_COPY
9757
9758 #define __S000 PAGE_NONE
9759 -#define __S001 PAGE_READONLY
9760 -#define __S010 PAGE_SHARED
9761 -#define __S011 PAGE_SHARED
9762 +#define __S001 PAGE_READONLY_NOEXEC
9763 +#define __S010 PAGE_SHARED_NOEXEC
9764 +#define __S011 PAGE_SHARED_NOEXEC
9765 #define __S100 PAGE_READONLY
9766 #define __S101 PAGE_READONLY
9767 #define __S110 PAGE_SHARED
9768 diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
9769 index 0f9e945..a949e55 100644
9770 --- a/arch/sparc/include/asm/pgtable_64.h
9771 +++ b/arch/sparc/include/asm/pgtable_64.h
9772 @@ -71,6 +71,23 @@
9773
9774 #include <linux/sched.h>
9775
9776 +extern unsigned long sparc64_valid_addr_bitmap[];
9777 +
9778 +/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
9779 +static inline bool __kern_addr_valid(unsigned long paddr)
9780 +{
9781 + if ((paddr >> MAX_PHYS_ADDRESS_BITS) != 0UL)
9782 + return false;
9783 + return test_bit(paddr >> ILOG2_4MB, sparc64_valid_addr_bitmap);
9784 +}
9785 +
9786 +static inline bool kern_addr_valid(unsigned long addr)
9787 +{
9788 + unsigned long paddr = __pa(addr);
9789 +
9790 + return __kern_addr_valid(paddr);
9791 +}
9792 +
9793 /* Entries per page directory level. */
9794 #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
9795 #define PTRS_PER_PMD (1UL << PMD_BITS)
9796 @@ -79,9 +96,12 @@
9797 /* Kernel has a separate 44bit address space. */
9798 #define FIRST_USER_ADDRESS 0
9799
9800 -#define pte_ERROR(e) __builtin_trap()
9801 -#define pmd_ERROR(e) __builtin_trap()
9802 -#define pgd_ERROR(e) __builtin_trap()
9803 +#define pmd_ERROR(e) \
9804 + pr_err("%s:%d: bad pmd %p(%016lx) seen at (%pS)\n", \
9805 + __FILE__, __LINE__, &(e), pmd_val(e), __builtin_return_address(0))
9806 +#define pgd_ERROR(e) \
9807 + pr_err("%s:%d: bad pgd %p(%016lx) seen at (%pS)\n", \
9808 + __FILE__, __LINE__, &(e), pgd_val(e), __builtin_return_address(0))
9809
9810 #endif /* !(__ASSEMBLY__) */
9811
9812 @@ -633,7 +653,7 @@ static inline unsigned long pmd_large(pmd_t pmd)
9813 {
9814 pte_t pte = __pte(pmd_val(pmd));
9815
9816 - return (pte_val(pte) & _PAGE_PMD_HUGE) && pte_present(pte);
9817 + return pte_val(pte) & _PAGE_PMD_HUGE;
9818 }
9819
9820 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
9821 @@ -719,20 +739,6 @@ static inline pmd_t pmd_mkwrite(pmd_t pmd)
9822 return __pmd(pte_val(pte));
9823 }
9824
9825 -static inline pmd_t pmd_mknotpresent(pmd_t pmd)
9826 -{
9827 - unsigned long mask;
9828 -
9829 - if (tlb_type == hypervisor)
9830 - mask = _PAGE_PRESENT_4V;
9831 - else
9832 - mask = _PAGE_PRESENT_4U;
9833 -
9834 - pmd_val(pmd) &= ~mask;
9835 -
9836 - return pmd;
9837 -}
9838 -
9839 static inline pmd_t pmd_mksplitting(pmd_t pmd)
9840 {
9841 pte_t pte = __pte(pmd_val(pmd));
9842 @@ -757,6 +763,20 @@ static inline int pmd_present(pmd_t pmd)
9843
9844 #define pmd_none(pmd) (!pmd_val(pmd))
9845
9846 +/* pmd_bad() is only called on non-trans-huge PMDs. Our encoding is
9847 + * very simple, it's just the physical address. PTE tables are of
9848 + * size PAGE_SIZE so make sure the sub-PAGE_SIZE bits are clear and
9849 + * the top bits outside of the range of any physical address size we
9850 + * support are clear as well. We also validate the physical itself.
9851 + */
9852 +#define pmd_bad(pmd) ((pmd_val(pmd) & ~PAGE_MASK) || \
9853 + !__kern_addr_valid(pmd_val(pmd)))
9854 +
9855 +#define pud_none(pud) (!pud_val(pud))
9856 +
9857 +#define pud_bad(pud) ((pud_val(pud) & ~PAGE_MASK) || \
9858 + !__kern_addr_valid(pud_val(pud)))
9859 +
9860 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
9861 extern void set_pmd_at(struct mm_struct *mm, unsigned long addr,
9862 pmd_t *pmdp, pmd_t pmd);
9863 @@ -790,10 +810,7 @@ static inline unsigned long __pmd_page(pmd_t pmd)
9864 #define pud_page_vaddr(pud) \
9865 ((unsigned long) __va(pud_val(pud)))
9866 #define pud_page(pud) virt_to_page((void *)pud_page_vaddr(pud))
9867 -#define pmd_bad(pmd) (0)
9868 #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0UL)
9869 -#define pud_none(pud) (!pud_val(pud))
9870 -#define pud_bad(pud) (0)
9871 #define pud_present(pud) (pud_val(pud) != 0U)
9872 #define pud_clear(pudp) (pud_val(*(pudp)) = 0UL)
9873
9874 @@ -893,6 +910,10 @@ extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
9875 extern void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,
9876 pmd_t *pmd);
9877
9878 +#define __HAVE_ARCH_PMDP_INVALIDATE
9879 +extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
9880 + pmd_t *pmdp);
9881 +
9882 #define __HAVE_ARCH_PGTABLE_DEPOSIT
9883 extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
9884 pgtable_t pgtable);
9885 @@ -919,18 +940,6 @@ extern unsigned long pte_file(pte_t);
9886 extern pte_t pgoff_to_pte(unsigned long);
9887 #define PTE_FILE_MAX_BITS (64UL - PAGE_SHIFT - 1UL)
9888
9889 -extern unsigned long sparc64_valid_addr_bitmap[];
9890 -
9891 -/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
9892 -static inline bool kern_addr_valid(unsigned long addr)
9893 -{
9894 - unsigned long paddr = __pa(addr);
9895 -
9896 - if ((paddr >> 41UL) != 0UL)
9897 - return false;
9898 - return test_bit(paddr >> 22, sparc64_valid_addr_bitmap);
9899 -}
9900 -
9901 extern int page_in_phys_avail(unsigned long paddr);
9902
9903 /*
9904 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9905 index 79da178..c2eede8 100644
9906 --- a/arch/sparc/include/asm/pgtsrmmu.h
9907 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9908 @@ -115,6 +115,11 @@
9909 SRMMU_EXEC | SRMMU_REF)
9910 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9911 SRMMU_EXEC | SRMMU_REF)
9912 +
9913 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9914 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9915 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9916 +
9917 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9918 SRMMU_DIRTY | SRMMU_REF)
9919
9920 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9921 index 9689176..63c18ea 100644
9922 --- a/arch/sparc/include/asm/spinlock_64.h
9923 +++ b/arch/sparc/include/asm/spinlock_64.h
9924 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9925
9926 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9927
9928 -static void inline arch_read_lock(arch_rwlock_t *lock)
9929 +static inline void arch_read_lock(arch_rwlock_t *lock)
9930 {
9931 unsigned long tmp1, tmp2;
9932
9933 __asm__ __volatile__ (
9934 "1: ldsw [%2], %0\n"
9935 " brlz,pn %0, 2f\n"
9936 -"4: add %0, 1, %1\n"
9937 +"4: addcc %0, 1, %1\n"
9938 +
9939 +#ifdef CONFIG_PAX_REFCOUNT
9940 +" tvs %%icc, 6\n"
9941 +#endif
9942 +
9943 " cas [%2], %0, %1\n"
9944 " cmp %0, %1\n"
9945 " bne,pn %%icc, 1b\n"
9946 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9947 " .previous"
9948 : "=&r" (tmp1), "=&r" (tmp2)
9949 : "r" (lock)
9950 - : "memory");
9951 + : "memory", "cc");
9952 }
9953
9954 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9955 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9956 {
9957 int tmp1, tmp2;
9958
9959 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9960 "1: ldsw [%2], %0\n"
9961 " brlz,a,pn %0, 2f\n"
9962 " mov 0, %0\n"
9963 -" add %0, 1, %1\n"
9964 +" addcc %0, 1, %1\n"
9965 +
9966 +#ifdef CONFIG_PAX_REFCOUNT
9967 +" tvs %%icc, 6\n"
9968 +#endif
9969 +
9970 " cas [%2], %0, %1\n"
9971 " cmp %0, %1\n"
9972 " bne,pn %%icc, 1b\n"
9973 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9974 return tmp1;
9975 }
9976
9977 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9978 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9979 {
9980 unsigned long tmp1, tmp2;
9981
9982 __asm__ __volatile__(
9983 "1: lduw [%2], %0\n"
9984 -" sub %0, 1, %1\n"
9985 +" subcc %0, 1, %1\n"
9986 +
9987 +#ifdef CONFIG_PAX_REFCOUNT
9988 +" tvs %%icc, 6\n"
9989 +#endif
9990 +
9991 " cas [%2], %0, %1\n"
9992 " cmp %0, %1\n"
9993 " bne,pn %%xcc, 1b\n"
9994 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9995 : "memory");
9996 }
9997
9998 -static void inline arch_write_lock(arch_rwlock_t *lock)
9999 +static inline void arch_write_lock(arch_rwlock_t *lock)
10000 {
10001 unsigned long mask, tmp1, tmp2;
10002
10003 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10004 : "memory");
10005 }
10006
10007 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10008 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10009 {
10010 __asm__ __volatile__(
10011 " stw %%g0, [%0]"
10012 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10013 : "memory");
10014 }
10015
10016 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10017 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10018 {
10019 unsigned long mask, tmp1, tmp2, result;
10020
10021 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10022 index 96efa7a..16858bf 100644
10023 --- a/arch/sparc/include/asm/thread_info_32.h
10024 +++ b/arch/sparc/include/asm/thread_info_32.h
10025 @@ -49,6 +49,8 @@ struct thread_info {
10026 unsigned long w_saved;
10027
10028 struct restart_block restart_block;
10029 +
10030 + unsigned long lowest_stack;
10031 };
10032
10033 /*
10034 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10035 index a5f01ac..703b554 100644
10036 --- a/arch/sparc/include/asm/thread_info_64.h
10037 +++ b/arch/sparc/include/asm/thread_info_64.h
10038 @@ -63,6 +63,8 @@ struct thread_info {
10039 struct pt_regs *kern_una_regs;
10040 unsigned int kern_una_insn;
10041
10042 + unsigned long lowest_stack;
10043 +
10044 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10045 };
10046
10047 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10048 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10049 /* flag bit 4 is available */
10050 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10051 -/* flag bit 6 is available */
10052 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10053 #define TIF_32BIT 7 /* 32-bit binary */
10054 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10055 #define TIF_SECCOMP 9 /* secure computing */
10056 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10057 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10058 +
10059 /* NOTE: Thread flags >= 12 should be ones we have no interest
10060 * in using in assembly, else we can't use the mask as
10061 * an immediate value in instructions such as andcc.
10062 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10063 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10064 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10065 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10066 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10067
10068 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10069 _TIF_DO_NOTIFY_RESUME_MASK | \
10070 _TIF_NEED_RESCHED)
10071 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10072
10073 +#define _TIF_WORK_SYSCALL \
10074 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10075 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10076 +
10077 +
10078 /*
10079 * Thread-synchronous status.
10080 *
10081 diff --git a/arch/sparc/include/asm/tsb.h b/arch/sparc/include/asm/tsb.h
10082 index 2230f80..90916f9 100644
10083 --- a/arch/sparc/include/asm/tsb.h
10084 +++ b/arch/sparc/include/asm/tsb.h
10085 @@ -171,7 +171,8 @@ extern struct tsb_phys_patch_entry __tsb_phys_patch, __tsb_phys_patch_end;
10086 andcc REG1, REG2, %g0; \
10087 be,pt %xcc, 700f; \
10088 sethi %hi(4 * 1024 * 1024), REG2; \
10089 - andn REG1, REG2, REG1; \
10090 + brgez,pn REG1, FAIL_LABEL; \
10091 + andn REG1, REG2, REG1; \
10092 and VADDR, REG2, REG2; \
10093 brlz,pt REG1, PTE_LABEL; \
10094 or REG1, REG2, REG1; \
10095 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10096 index 0167d26..767bb0c 100644
10097 --- a/arch/sparc/include/asm/uaccess.h
10098 +++ b/arch/sparc/include/asm/uaccess.h
10099 @@ -1,5 +1,6 @@
10100 #ifndef ___ASM_SPARC_UACCESS_H
10101 #define ___ASM_SPARC_UACCESS_H
10102 +
10103 #if defined(__sparc__) && defined(__arch64__)
10104 #include <asm/uaccess_64.h>
10105 #else
10106 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10107 index 53a28dd..50c38c3 100644
10108 --- a/arch/sparc/include/asm/uaccess_32.h
10109 +++ b/arch/sparc/include/asm/uaccess_32.h
10110 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10111
10112 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10113 {
10114 - if (n && __access_ok((unsigned long) to, n))
10115 + if ((long)n < 0)
10116 + return n;
10117 +
10118 + if (n && __access_ok((unsigned long) to, n)) {
10119 + if (!__builtin_constant_p(n))
10120 + check_object_size(from, n, true);
10121 return __copy_user(to, (__force void __user *) from, n);
10122 - else
10123 + } else
10124 return n;
10125 }
10126
10127 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10128 {
10129 + if ((long)n < 0)
10130 + return n;
10131 +
10132 + if (!__builtin_constant_p(n))
10133 + check_object_size(from, n, true);
10134 +
10135 return __copy_user(to, (__force void __user *) from, n);
10136 }
10137
10138 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10139 {
10140 - if (n && __access_ok((unsigned long) from, n))
10141 + if ((long)n < 0)
10142 + return n;
10143 +
10144 + if (n && __access_ok((unsigned long) from, n)) {
10145 + if (!__builtin_constant_p(n))
10146 + check_object_size(to, n, false);
10147 return __copy_user((__force void __user *) to, from, n);
10148 - else
10149 + } else
10150 return n;
10151 }
10152
10153 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10154 {
10155 + if ((long)n < 0)
10156 + return n;
10157 +
10158 return __copy_user((__force void __user *) to, from, n);
10159 }
10160
10161 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10162 index ad7e178..c9e7423 100644
10163 --- a/arch/sparc/include/asm/uaccess_64.h
10164 +++ b/arch/sparc/include/asm/uaccess_64.h
10165 @@ -10,6 +10,7 @@
10166 #include <linux/compiler.h>
10167 #include <linux/string.h>
10168 #include <linux/thread_info.h>
10169 +#include <linux/kernel.h>
10170 #include <asm/asi.h>
10171 #include <asm/spitfire.h>
10172 #include <asm-generic/uaccess-unaligned.h>
10173 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10174 static inline unsigned long __must_check
10175 copy_from_user(void *to, const void __user *from, unsigned long size)
10176 {
10177 - unsigned long ret = ___copy_from_user(to, from, size);
10178 + unsigned long ret;
10179
10180 + if ((long)size < 0 || size > INT_MAX)
10181 + return size;
10182 +
10183 + if (!__builtin_constant_p(size))
10184 + check_object_size(to, size, false);
10185 +
10186 + ret = ___copy_from_user(to, from, size);
10187 if (unlikely(ret))
10188 ret = copy_from_user_fixup(to, from, size);
10189
10190 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10191 static inline unsigned long __must_check
10192 copy_to_user(void __user *to, const void *from, unsigned long size)
10193 {
10194 - unsigned long ret = ___copy_to_user(to, from, size);
10195 + unsigned long ret;
10196
10197 + if ((long)size < 0 || size > INT_MAX)
10198 + return size;
10199 +
10200 + if (!__builtin_constant_p(size))
10201 + check_object_size(from, size, true);
10202 +
10203 + ret = ___copy_to_user(to, from, size);
10204 if (unlikely(ret))
10205 ret = copy_to_user_fixup(to, from, size);
10206 return ret;
10207 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10208 index d15cc17..d0ae796 100644
10209 --- a/arch/sparc/kernel/Makefile
10210 +++ b/arch/sparc/kernel/Makefile
10211 @@ -4,7 +4,7 @@
10212 #
10213
10214 asflags-y := -ansi
10215 -ccflags-y := -Werror
10216 +#ccflags-y := -Werror
10217
10218 extra-y := head_$(BITS).o
10219
10220 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10221 index 510baec..9ff2607 100644
10222 --- a/arch/sparc/kernel/process_32.c
10223 +++ b/arch/sparc/kernel/process_32.c
10224 @@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10225
10226 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10227 r->psr, r->pc, r->npc, r->y, print_tainted());
10228 - printk("PC: <%pS>\n", (void *) r->pc);
10229 + printk("PC: <%pA>\n", (void *) r->pc);
10230 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10231 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10232 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10233 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10234 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10235 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10236 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10237 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10238
10239 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10240 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10241 @@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10242 rw = (struct reg_window32 *) fp;
10243 pc = rw->ins[7];
10244 printk("[%08lx : ", pc);
10245 - printk("%pS ] ", (void *) pc);
10246 + printk("%pA ] ", (void *) pc);
10247 fp = rw->ins[6];
10248 } while (++count < 16);
10249 printk("\n");
10250 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10251 index d7b4967..2edf827 100644
10252 --- a/arch/sparc/kernel/process_64.c
10253 +++ b/arch/sparc/kernel/process_64.c
10254 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10255 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10256 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10257 if (regs->tstate & TSTATE_PRIV)
10258 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10259 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10260 }
10261
10262 void show_regs(struct pt_regs *regs)
10263 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10264
10265 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10266 regs->tpc, regs->tnpc, regs->y, print_tainted());
10267 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10268 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10269 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10270 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10271 regs->u_regs[3]);
10272 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10273 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10274 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10275 regs->u_regs[15]);
10276 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10277 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10278 show_regwindow(regs);
10279 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10280 }
10281 @@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10282 ((tp && tp->task) ? tp->task->pid : -1));
10283
10284 if (gp->tstate & TSTATE_PRIV) {
10285 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10286 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10287 (void *) gp->tpc,
10288 (void *) gp->o7,
10289 (void *) gp->i7,
10290 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10291 index 79cc0d1..ec62734 100644
10292 --- a/arch/sparc/kernel/prom_common.c
10293 +++ b/arch/sparc/kernel/prom_common.c
10294 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10295
10296 unsigned int prom_early_allocated __initdata;
10297
10298 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10299 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10300 .nextprop = prom_common_nextprop,
10301 .getproplen = prom_getproplen,
10302 .getproperty = prom_getproperty,
10303 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10304 index c13c9f2..d572c34 100644
10305 --- a/arch/sparc/kernel/ptrace_64.c
10306 +++ b/arch/sparc/kernel/ptrace_64.c
10307 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10308 return ret;
10309 }
10310
10311 +#ifdef CONFIG_GRKERNSEC_SETXID
10312 +extern void gr_delayed_cred_worker(void);
10313 +#endif
10314 +
10315 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10316 {
10317 int ret = 0;
10318 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10319 if (test_thread_flag(TIF_NOHZ))
10320 user_exit();
10321
10322 +#ifdef CONFIG_GRKERNSEC_SETXID
10323 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10324 + gr_delayed_cred_worker();
10325 +#endif
10326 +
10327 if (test_thread_flag(TIF_SYSCALL_TRACE))
10328 ret = tracehook_report_syscall_entry(regs);
10329
10330 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10331 if (test_thread_flag(TIF_NOHZ))
10332 user_exit();
10333
10334 +#ifdef CONFIG_GRKERNSEC_SETXID
10335 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10336 + gr_delayed_cred_worker();
10337 +#endif
10338 +
10339 audit_syscall_exit(regs);
10340
10341 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10342 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10343 index b085311..6f885f7 100644
10344 --- a/arch/sparc/kernel/smp_64.c
10345 +++ b/arch/sparc/kernel/smp_64.c
10346 @@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10347 extern unsigned long xcall_flush_dcache_page_spitfire;
10348
10349 #ifdef CONFIG_DEBUG_DCFLUSH
10350 -extern atomic_t dcpage_flushes;
10351 -extern atomic_t dcpage_flushes_xcall;
10352 +extern atomic_unchecked_t dcpage_flushes;
10353 +extern atomic_unchecked_t dcpage_flushes_xcall;
10354 #endif
10355
10356 static inline void __local_flush_dcache_page(struct page *page)
10357 @@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10358 return;
10359
10360 #ifdef CONFIG_DEBUG_DCFLUSH
10361 - atomic_inc(&dcpage_flushes);
10362 + atomic_inc_unchecked(&dcpage_flushes);
10363 #endif
10364
10365 this_cpu = get_cpu();
10366 @@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10367 xcall_deliver(data0, __pa(pg_addr),
10368 (u64) pg_addr, cpumask_of(cpu));
10369 #ifdef CONFIG_DEBUG_DCFLUSH
10370 - atomic_inc(&dcpage_flushes_xcall);
10371 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10372 #endif
10373 }
10374 }
10375 @@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10376 preempt_disable();
10377
10378 #ifdef CONFIG_DEBUG_DCFLUSH
10379 - atomic_inc(&dcpage_flushes);
10380 + atomic_inc_unchecked(&dcpage_flushes);
10381 #endif
10382 data0 = 0;
10383 pg_addr = page_address(page);
10384 @@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10385 xcall_deliver(data0, __pa(pg_addr),
10386 (u64) pg_addr, cpu_online_mask);
10387 #ifdef CONFIG_DEBUG_DCFLUSH
10388 - atomic_inc(&dcpage_flushes_xcall);
10389 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10390 #endif
10391 }
10392 __local_flush_dcache_page(page);
10393 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10394 index 3a8d184..49498a8 100644
10395 --- a/arch/sparc/kernel/sys_sparc_32.c
10396 +++ b/arch/sparc/kernel/sys_sparc_32.c
10397 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10398 if (len > TASK_SIZE - PAGE_SIZE)
10399 return -ENOMEM;
10400 if (!addr)
10401 - addr = TASK_UNMAPPED_BASE;
10402 + addr = current->mm->mmap_base;
10403
10404 info.flags = 0;
10405 info.length = len;
10406 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10407 index beb0b5a..5a153f7 100644
10408 --- a/arch/sparc/kernel/sys_sparc_64.c
10409 +++ b/arch/sparc/kernel/sys_sparc_64.c
10410 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10411 struct vm_area_struct * vma;
10412 unsigned long task_size = TASK_SIZE;
10413 int do_color_align;
10414 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10415 struct vm_unmapped_area_info info;
10416
10417 if (flags & MAP_FIXED) {
10418 /* We do not accept a shared mapping if it would violate
10419 * cache aliasing constraints.
10420 */
10421 - if ((flags & MAP_SHARED) &&
10422 + if ((filp || (flags & MAP_SHARED)) &&
10423 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10424 return -EINVAL;
10425 return addr;
10426 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10427 if (filp || (flags & MAP_SHARED))
10428 do_color_align = 1;
10429
10430 +#ifdef CONFIG_PAX_RANDMMAP
10431 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10432 +#endif
10433 +
10434 if (addr) {
10435 if (do_color_align)
10436 addr = COLOR_ALIGN(addr, pgoff);
10437 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10438 addr = PAGE_ALIGN(addr);
10439
10440 vma = find_vma(mm, addr);
10441 - if (task_size - len >= addr &&
10442 - (!vma || addr + len <= vma->vm_start))
10443 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10444 return addr;
10445 }
10446
10447 info.flags = 0;
10448 info.length = len;
10449 - info.low_limit = TASK_UNMAPPED_BASE;
10450 + info.low_limit = mm->mmap_base;
10451 info.high_limit = min(task_size, VA_EXCLUDE_START);
10452 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10453 info.align_offset = pgoff << PAGE_SHIFT;
10454 + info.threadstack_offset = offset;
10455 addr = vm_unmapped_area(&info);
10456
10457 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10458 VM_BUG_ON(addr != -ENOMEM);
10459 info.low_limit = VA_EXCLUDE_END;
10460 +
10461 +#ifdef CONFIG_PAX_RANDMMAP
10462 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10463 + info.low_limit += mm->delta_mmap;
10464 +#endif
10465 +
10466 info.high_limit = task_size;
10467 addr = vm_unmapped_area(&info);
10468 }
10469 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10470 unsigned long task_size = STACK_TOP32;
10471 unsigned long addr = addr0;
10472 int do_color_align;
10473 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10474 struct vm_unmapped_area_info info;
10475
10476 /* This should only ever run for 32-bit processes. */
10477 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10478 /* We do not accept a shared mapping if it would violate
10479 * cache aliasing constraints.
10480 */
10481 - if ((flags & MAP_SHARED) &&
10482 + if ((filp || (flags & MAP_SHARED)) &&
10483 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10484 return -EINVAL;
10485 return addr;
10486 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10487 if (filp || (flags & MAP_SHARED))
10488 do_color_align = 1;
10489
10490 +#ifdef CONFIG_PAX_RANDMMAP
10491 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10492 +#endif
10493 +
10494 /* requesting a specific address */
10495 if (addr) {
10496 if (do_color_align)
10497 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10498 addr = PAGE_ALIGN(addr);
10499
10500 vma = find_vma(mm, addr);
10501 - if (task_size - len >= addr &&
10502 - (!vma || addr + len <= vma->vm_start))
10503 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10504 return addr;
10505 }
10506
10507 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10508 info.high_limit = mm->mmap_base;
10509 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10510 info.align_offset = pgoff << PAGE_SHIFT;
10511 + info.threadstack_offset = offset;
10512 addr = vm_unmapped_area(&info);
10513
10514 /*
10515 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10516 VM_BUG_ON(addr != -ENOMEM);
10517 info.flags = 0;
10518 info.low_limit = TASK_UNMAPPED_BASE;
10519 +
10520 +#ifdef CONFIG_PAX_RANDMMAP
10521 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10522 + info.low_limit += mm->delta_mmap;
10523 +#endif
10524 +
10525 info.high_limit = STACK_TOP32;
10526 addr = vm_unmapped_area(&info);
10527 }
10528 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10529 EXPORT_SYMBOL(get_fb_unmapped_area);
10530
10531 /* Essentially the same as PowerPC. */
10532 -static unsigned long mmap_rnd(void)
10533 +static unsigned long mmap_rnd(struct mm_struct *mm)
10534 {
10535 unsigned long rnd = 0UL;
10536
10537 +#ifdef CONFIG_PAX_RANDMMAP
10538 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10539 +#endif
10540 +
10541 if (current->flags & PF_RANDOMIZE) {
10542 unsigned long val = get_random_int();
10543 if (test_thread_flag(TIF_32BIT))
10544 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10545
10546 void arch_pick_mmap_layout(struct mm_struct *mm)
10547 {
10548 - unsigned long random_factor = mmap_rnd();
10549 + unsigned long random_factor = mmap_rnd(mm);
10550 unsigned long gap;
10551
10552 /*
10553 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10554 gap == RLIM_INFINITY ||
10555 sysctl_legacy_va_layout) {
10556 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10557 +
10558 +#ifdef CONFIG_PAX_RANDMMAP
10559 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10560 + mm->mmap_base += mm->delta_mmap;
10561 +#endif
10562 +
10563 mm->get_unmapped_area = arch_get_unmapped_area;
10564 } else {
10565 /* We know it's 32-bit */
10566 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10567 gap = (task_size / 6 * 5);
10568
10569 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10570 +
10571 +#ifdef CONFIG_PAX_RANDMMAP
10572 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10573 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10574 +#endif
10575 +
10576 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10577 }
10578 }
10579 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10580 index 33a17e7..d87fb1f 100644
10581 --- a/arch/sparc/kernel/syscalls.S
10582 +++ b/arch/sparc/kernel/syscalls.S
10583 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10584 #endif
10585 .align 32
10586 1: ldx [%g6 + TI_FLAGS], %l5
10587 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10588 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10589 be,pt %icc, rtrap
10590 nop
10591 call syscall_trace_leave
10592 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10593
10594 srl %i3, 0, %o3 ! IEU0
10595 srl %i2, 0, %o2 ! IEU0 Group
10596 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10597 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10598 bne,pn %icc, linux_syscall_trace32 ! CTI
10599 mov %i0, %l5 ! IEU1
10600 5: call %l7 ! CTI Group brk forced
10601 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10602
10603 mov %i3, %o3 ! IEU1
10604 mov %i4, %o4 ! IEU0 Group
10605 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10606 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10607 bne,pn %icc, linux_syscall_trace ! CTI Group
10608 mov %i0, %l5 ! IEU0
10609 2: call %l7 ! CTI Group brk forced
10610 @@ -223,7 +223,7 @@ ret_sys_call:
10611
10612 cmp %o0, -ERESTART_RESTARTBLOCK
10613 bgeu,pn %xcc, 1f
10614 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10615 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10616 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10617
10618 2:
10619 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10620 index 6629829..036032d 100644
10621 --- a/arch/sparc/kernel/traps_32.c
10622 +++ b/arch/sparc/kernel/traps_32.c
10623 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10624 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10625 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10626
10627 +extern void gr_handle_kernel_exploit(void);
10628 +
10629 void die_if_kernel(char *str, struct pt_regs *regs)
10630 {
10631 static int die_counter;
10632 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10633 count++ < 30 &&
10634 (((unsigned long) rw) >= PAGE_OFFSET) &&
10635 !(((unsigned long) rw) & 0x7)) {
10636 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10637 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10638 (void *) rw->ins[7]);
10639 rw = (struct reg_window32 *)rw->ins[6];
10640 }
10641 }
10642 printk("Instruction DUMP:");
10643 instruction_dump ((unsigned long *) regs->pc);
10644 - if(regs->psr & PSR_PS)
10645 + if(regs->psr & PSR_PS) {
10646 + gr_handle_kernel_exploit();
10647 do_exit(SIGKILL);
10648 + }
10649 do_exit(SIGSEGV);
10650 }
10651
10652 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10653 index 4ced92f..965eeed 100644
10654 --- a/arch/sparc/kernel/traps_64.c
10655 +++ b/arch/sparc/kernel/traps_64.c
10656 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10657 i + 1,
10658 p->trapstack[i].tstate, p->trapstack[i].tpc,
10659 p->trapstack[i].tnpc, p->trapstack[i].tt);
10660 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10661 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10662 }
10663 }
10664
10665 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10666
10667 lvl -= 0x100;
10668 if (regs->tstate & TSTATE_PRIV) {
10669 +
10670 +#ifdef CONFIG_PAX_REFCOUNT
10671 + if (lvl == 6)
10672 + pax_report_refcount_overflow(regs);
10673 +#endif
10674 +
10675 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10676 die_if_kernel(buffer, regs);
10677 }
10678 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10679 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10680 {
10681 char buffer[32];
10682 -
10683 +
10684 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10685 0, lvl, SIGTRAP) == NOTIFY_STOP)
10686 return;
10687
10688 +#ifdef CONFIG_PAX_REFCOUNT
10689 + if (lvl == 6)
10690 + pax_report_refcount_overflow(regs);
10691 +#endif
10692 +
10693 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10694
10695 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10696 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10697 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10698 printk("%s" "ERROR(%d): ",
10699 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10700 - printk("TPC<%pS>\n", (void *) regs->tpc);
10701 + printk("TPC<%pA>\n", (void *) regs->tpc);
10702 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10703 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10704 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10705 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10706 smp_processor_id(),
10707 (type & 0x1) ? 'I' : 'D',
10708 regs->tpc);
10709 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10710 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10711 panic("Irrecoverable Cheetah+ parity error.");
10712 }
10713
10714 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10715 smp_processor_id(),
10716 (type & 0x1) ? 'I' : 'D',
10717 regs->tpc);
10718 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10719 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10720 }
10721
10722 struct sun4v_error_entry {
10723 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10724 /*0x38*/u64 reserved_5;
10725 };
10726
10727 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10728 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10729 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10730 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10731
10732 static const char *sun4v_err_type_to_str(u8 type)
10733 {
10734 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10735 }
10736
10737 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10738 - int cpu, const char *pfx, atomic_t *ocnt)
10739 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10740 {
10741 u64 *raw_ptr = (u64 *) ent;
10742 u32 attrs;
10743 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10744
10745 show_regs(regs);
10746
10747 - if ((cnt = atomic_read(ocnt)) != 0) {
10748 - atomic_set(ocnt, 0);
10749 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10750 + atomic_set_unchecked(ocnt, 0);
10751 wmb();
10752 printk("%s: Queue overflowed %d times.\n",
10753 pfx, cnt);
10754 @@ -2046,7 +2057,7 @@ out:
10755 */
10756 void sun4v_resum_overflow(struct pt_regs *regs)
10757 {
10758 - atomic_inc(&sun4v_resum_oflow_cnt);
10759 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10760 }
10761
10762 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10763 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10764 /* XXX Actually even this can make not that much sense. Perhaps
10765 * XXX we should just pull the plug and panic directly from here?
10766 */
10767 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10768 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10769 }
10770
10771 unsigned long sun4v_err_itlb_vaddr;
10772 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10773
10774 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10775 regs->tpc, tl);
10776 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10777 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10778 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10779 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10780 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10781 (void *) regs->u_regs[UREG_I7]);
10782 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10783 "pte[%lx] error[%lx]\n",
10784 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10785
10786 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10787 regs->tpc, tl);
10788 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10789 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10790 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10791 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10792 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10793 (void *) regs->u_regs[UREG_I7]);
10794 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10795 "pte[%lx] error[%lx]\n",
10796 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10797 fp = (unsigned long)sf->fp + STACK_BIAS;
10798 }
10799
10800 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10801 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10802 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10803 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10804 int index = tsk->curr_ret_stack;
10805 if (tsk->ret_stack && index >= graph) {
10806 pc = tsk->ret_stack[index - graph].ret;
10807 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10808 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10809 graph++;
10810 }
10811 }
10812 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10813 return (struct reg_window *) (fp + STACK_BIAS);
10814 }
10815
10816 +extern void gr_handle_kernel_exploit(void);
10817 +
10818 void die_if_kernel(char *str, struct pt_regs *regs)
10819 {
10820 static int die_counter;
10821 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10822 while (rw &&
10823 count++ < 30 &&
10824 kstack_valid(tp, (unsigned long) rw)) {
10825 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10826 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10827 (void *) rw->ins[7]);
10828
10829 rw = kernel_stack_up(rw);
10830 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10831 }
10832 user_instruction_dump ((unsigned int __user *) regs->tpc);
10833 }
10834 - if (regs->tstate & TSTATE_PRIV)
10835 + if (regs->tstate & TSTATE_PRIV) {
10836 + gr_handle_kernel_exploit();
10837 do_exit(SIGKILL);
10838 + }
10839 do_exit(SIGSEGV);
10840 }
10841 EXPORT_SYMBOL(die_if_kernel);
10842 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10843 index 3c1a7cb..9046547 100644
10844 --- a/arch/sparc/kernel/unaligned_64.c
10845 +++ b/arch/sparc/kernel/unaligned_64.c
10846 @@ -166,17 +166,23 @@ static unsigned long *fetch_reg_addr(unsigned int reg, struct pt_regs *regs)
10847 unsigned long compute_effective_address(struct pt_regs *regs,
10848 unsigned int insn, unsigned int rd)
10849 {
10850 + int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
10851 unsigned int rs1 = (insn >> 14) & 0x1f;
10852 unsigned int rs2 = insn & 0x1f;
10853 - int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
10854 + unsigned long addr;
10855
10856 if (insn & 0x2000) {
10857 maybe_flush_windows(rs1, 0, rd, from_kernel);
10858 - return (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
10859 + addr = (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
10860 } else {
10861 maybe_flush_windows(rs1, rs2, rd, from_kernel);
10862 - return (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
10863 + addr = (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
10864 }
10865 +
10866 + if (!from_kernel && test_thread_flag(TIF_32BIT))
10867 + addr &= 0xffffffff;
10868 +
10869 + return addr;
10870 }
10871
10872 /* This is just to make gcc think die_if_kernel does return... */
10873 @@ -289,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10874 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10875
10876 if (__ratelimit(&ratelimit)) {
10877 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10878 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10879 regs->tpc, (void *) regs->tpc);
10880 }
10881 }
10882 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10883 index dbe119b..089c7c1 100644
10884 --- a/arch/sparc/lib/Makefile
10885 +++ b/arch/sparc/lib/Makefile
10886 @@ -2,7 +2,7 @@
10887 #
10888
10889 asflags-y := -ansi -DST_DIV0=0x02
10890 -ccflags-y := -Werror
10891 +#ccflags-y := -Werror
10892
10893 lib-$(CONFIG_SPARC32) += ashrdi3.o
10894 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10895 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10896 index 85c233d..68500e0 100644
10897 --- a/arch/sparc/lib/atomic_64.S
10898 +++ b/arch/sparc/lib/atomic_64.S
10899 @@ -17,7 +17,12 @@
10900 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10901 BACKOFF_SETUP(%o2)
10902 1: lduw [%o1], %g1
10903 - add %g1, %o0, %g7
10904 + addcc %g1, %o0, %g7
10905 +
10906 +#ifdef CONFIG_PAX_REFCOUNT
10907 + tvs %icc, 6
10908 +#endif
10909 +
10910 cas [%o1], %g1, %g7
10911 cmp %g1, %g7
10912 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10913 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10914 2: BACKOFF_SPIN(%o2, %o3, 1b)
10915 ENDPROC(atomic_add)
10916
10917 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10918 + BACKOFF_SETUP(%o2)
10919 +1: lduw [%o1], %g1
10920 + add %g1, %o0, %g7
10921 + cas [%o1], %g1, %g7
10922 + cmp %g1, %g7
10923 + bne,pn %icc, 2f
10924 + nop
10925 + retl
10926 + nop
10927 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10928 +ENDPROC(atomic_add_unchecked)
10929 +
10930 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10931 BACKOFF_SETUP(%o2)
10932 1: lduw [%o1], %g1
10933 - sub %g1, %o0, %g7
10934 + subcc %g1, %o0, %g7
10935 +
10936 +#ifdef CONFIG_PAX_REFCOUNT
10937 + tvs %icc, 6
10938 +#endif
10939 +
10940 cas [%o1], %g1, %g7
10941 cmp %g1, %g7
10942 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10943 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10944 2: BACKOFF_SPIN(%o2, %o3, 1b)
10945 ENDPROC(atomic_sub)
10946
10947 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10948 + BACKOFF_SETUP(%o2)
10949 +1: lduw [%o1], %g1
10950 + sub %g1, %o0, %g7
10951 + cas [%o1], %g1, %g7
10952 + cmp %g1, %g7
10953 + bne,pn %icc, 2f
10954 + nop
10955 + retl
10956 + nop
10957 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10958 +ENDPROC(atomic_sub_unchecked)
10959 +
10960 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10961 BACKOFF_SETUP(%o2)
10962 1: lduw [%o1], %g1
10963 - add %g1, %o0, %g7
10964 + addcc %g1, %o0, %g7
10965 +
10966 +#ifdef CONFIG_PAX_REFCOUNT
10967 + tvs %icc, 6
10968 +#endif
10969 +
10970 cas [%o1], %g1, %g7
10971 cmp %g1, %g7
10972 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10973 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10974 2: BACKOFF_SPIN(%o2, %o3, 1b)
10975 ENDPROC(atomic_add_ret)
10976
10977 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10978 + BACKOFF_SETUP(%o2)
10979 +1: lduw [%o1], %g1
10980 + addcc %g1, %o0, %g7
10981 + cas [%o1], %g1, %g7
10982 + cmp %g1, %g7
10983 + bne,pn %icc, 2f
10984 + add %g7, %o0, %g7
10985 + sra %g7, 0, %o0
10986 + retl
10987 + nop
10988 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10989 +ENDPROC(atomic_add_ret_unchecked)
10990 +
10991 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10992 BACKOFF_SETUP(%o2)
10993 1: lduw [%o1], %g1
10994 - sub %g1, %o0, %g7
10995 + subcc %g1, %o0, %g7
10996 +
10997 +#ifdef CONFIG_PAX_REFCOUNT
10998 + tvs %icc, 6
10999 +#endif
11000 +
11001 cas [%o1], %g1, %g7
11002 cmp %g1, %g7
11003 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11004 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11005 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11006 BACKOFF_SETUP(%o2)
11007 1: ldx [%o1], %g1
11008 - add %g1, %o0, %g7
11009 + addcc %g1, %o0, %g7
11010 +
11011 +#ifdef CONFIG_PAX_REFCOUNT
11012 + tvs %xcc, 6
11013 +#endif
11014 +
11015 casx [%o1], %g1, %g7
11016 cmp %g1, %g7
11017 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11018 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11019 2: BACKOFF_SPIN(%o2, %o3, 1b)
11020 ENDPROC(atomic64_add)
11021
11022 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11023 + BACKOFF_SETUP(%o2)
11024 +1: ldx [%o1], %g1
11025 + addcc %g1, %o0, %g7
11026 + casx [%o1], %g1, %g7
11027 + cmp %g1, %g7
11028 + bne,pn %xcc, 2f
11029 + nop
11030 + retl
11031 + nop
11032 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11033 +ENDPROC(atomic64_add_unchecked)
11034 +
11035 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11036 BACKOFF_SETUP(%o2)
11037 1: ldx [%o1], %g1
11038 - sub %g1, %o0, %g7
11039 + subcc %g1, %o0, %g7
11040 +
11041 +#ifdef CONFIG_PAX_REFCOUNT
11042 + tvs %xcc, 6
11043 +#endif
11044 +
11045 casx [%o1], %g1, %g7
11046 cmp %g1, %g7
11047 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11048 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11049 2: BACKOFF_SPIN(%o2, %o3, 1b)
11050 ENDPROC(atomic64_sub)
11051
11052 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11053 + BACKOFF_SETUP(%o2)
11054 +1: ldx [%o1], %g1
11055 + subcc %g1, %o0, %g7
11056 + casx [%o1], %g1, %g7
11057 + cmp %g1, %g7
11058 + bne,pn %xcc, 2f
11059 + nop
11060 + retl
11061 + nop
11062 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11063 +ENDPROC(atomic64_sub_unchecked)
11064 +
11065 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11066 BACKOFF_SETUP(%o2)
11067 1: ldx [%o1], %g1
11068 - add %g1, %o0, %g7
11069 + addcc %g1, %o0, %g7
11070 +
11071 +#ifdef CONFIG_PAX_REFCOUNT
11072 + tvs %xcc, 6
11073 +#endif
11074 +
11075 casx [%o1], %g1, %g7
11076 cmp %g1, %g7
11077 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11078 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11079 2: BACKOFF_SPIN(%o2, %o3, 1b)
11080 ENDPROC(atomic64_add_ret)
11081
11082 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11083 + BACKOFF_SETUP(%o2)
11084 +1: ldx [%o1], %g1
11085 + addcc %g1, %o0, %g7
11086 + casx [%o1], %g1, %g7
11087 + cmp %g1, %g7
11088 + bne,pn %xcc, 2f
11089 + add %g7, %o0, %g7
11090 + mov %g7, %o0
11091 + retl
11092 + nop
11093 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11094 +ENDPROC(atomic64_add_ret_unchecked)
11095 +
11096 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11097 BACKOFF_SETUP(%o2)
11098 1: ldx [%o1], %g1
11099 - sub %g1, %o0, %g7
11100 + subcc %g1, %o0, %g7
11101 +
11102 +#ifdef CONFIG_PAX_REFCOUNT
11103 + tvs %xcc, 6
11104 +#endif
11105 +
11106 casx [%o1], %g1, %g7
11107 cmp %g1, %g7
11108 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11109 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11110 index 323335b..ed85ea2 100644
11111 --- a/arch/sparc/lib/ksyms.c
11112 +++ b/arch/sparc/lib/ksyms.c
11113 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11114
11115 /* Atomic counter implementation. */
11116 EXPORT_SYMBOL(atomic_add);
11117 +EXPORT_SYMBOL(atomic_add_unchecked);
11118 EXPORT_SYMBOL(atomic_add_ret);
11119 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11120 EXPORT_SYMBOL(atomic_sub);
11121 +EXPORT_SYMBOL(atomic_sub_unchecked);
11122 EXPORT_SYMBOL(atomic_sub_ret);
11123 EXPORT_SYMBOL(atomic64_add);
11124 +EXPORT_SYMBOL(atomic64_add_unchecked);
11125 EXPORT_SYMBOL(atomic64_add_ret);
11126 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11127 EXPORT_SYMBOL(atomic64_sub);
11128 +EXPORT_SYMBOL(atomic64_sub_unchecked);
11129 EXPORT_SYMBOL(atomic64_sub_ret);
11130 EXPORT_SYMBOL(atomic64_dec_if_positive);
11131
11132 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11133 index 30c3ecc..736f015 100644
11134 --- a/arch/sparc/mm/Makefile
11135 +++ b/arch/sparc/mm/Makefile
11136 @@ -2,7 +2,7 @@
11137 #
11138
11139 asflags-y := -ansi
11140 -ccflags-y := -Werror
11141 +#ccflags-y := -Werror
11142
11143 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11144 obj-y += fault_$(BITS).o
11145 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11146 index 59dbd46..1dd7f5e 100644
11147 --- a/arch/sparc/mm/fault_32.c
11148 +++ b/arch/sparc/mm/fault_32.c
11149 @@ -21,6 +21,9 @@
11150 #include <linux/perf_event.h>
11151 #include <linux/interrupt.h>
11152 #include <linux/kdebug.h>
11153 +#include <linux/slab.h>
11154 +#include <linux/pagemap.h>
11155 +#include <linux/compiler.h>
11156
11157 #include <asm/page.h>
11158 #include <asm/pgtable.h>
11159 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11160 return safe_compute_effective_address(regs, insn);
11161 }
11162
11163 +#ifdef CONFIG_PAX_PAGEEXEC
11164 +#ifdef CONFIG_PAX_DLRESOLVE
11165 +static void pax_emuplt_close(struct vm_area_struct *vma)
11166 +{
11167 + vma->vm_mm->call_dl_resolve = 0UL;
11168 +}
11169 +
11170 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11171 +{
11172 + unsigned int *kaddr;
11173 +
11174 + vmf->page = alloc_page(GFP_HIGHUSER);
11175 + if (!vmf->page)
11176 + return VM_FAULT_OOM;
11177 +
11178 + kaddr = kmap(vmf->page);
11179 + memset(kaddr, 0, PAGE_SIZE);
11180 + kaddr[0] = 0x9DE3BFA8U; /* save */
11181 + flush_dcache_page(vmf->page);
11182 + kunmap(vmf->page);
11183 + return VM_FAULT_MAJOR;
11184 +}
11185 +
11186 +static const struct vm_operations_struct pax_vm_ops = {
11187 + .close = pax_emuplt_close,
11188 + .fault = pax_emuplt_fault
11189 +};
11190 +
11191 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11192 +{
11193 + int ret;
11194 +
11195 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11196 + vma->vm_mm = current->mm;
11197 + vma->vm_start = addr;
11198 + vma->vm_end = addr + PAGE_SIZE;
11199 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11200 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11201 + vma->vm_ops = &pax_vm_ops;
11202 +
11203 + ret = insert_vm_struct(current->mm, vma);
11204 + if (ret)
11205 + return ret;
11206 +
11207 + ++current->mm->total_vm;
11208 + return 0;
11209 +}
11210 +#endif
11211 +
11212 +/*
11213 + * PaX: decide what to do with offenders (regs->pc = fault address)
11214 + *
11215 + * returns 1 when task should be killed
11216 + * 2 when patched PLT trampoline was detected
11217 + * 3 when unpatched PLT trampoline was detected
11218 + */
11219 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11220 +{
11221 +
11222 +#ifdef CONFIG_PAX_EMUPLT
11223 + int err;
11224 +
11225 + do { /* PaX: patched PLT emulation #1 */
11226 + unsigned int sethi1, sethi2, jmpl;
11227 +
11228 + err = get_user(sethi1, (unsigned int *)regs->pc);
11229 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11230 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11231 +
11232 + if (err)
11233 + break;
11234 +
11235 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11236 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11237 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11238 + {
11239 + unsigned int addr;
11240 +
11241 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11242 + addr = regs->u_regs[UREG_G1];
11243 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11244 + regs->pc = addr;
11245 + regs->npc = addr+4;
11246 + return 2;
11247 + }
11248 + } while (0);
11249 +
11250 + do { /* PaX: patched PLT emulation #2 */
11251 + unsigned int ba;
11252 +
11253 + err = get_user(ba, (unsigned int *)regs->pc);
11254 +
11255 + if (err)
11256 + break;
11257 +
11258 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11259 + unsigned int addr;
11260 +
11261 + if ((ba & 0xFFC00000U) == 0x30800000U)
11262 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11263 + else
11264 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11265 + regs->pc = addr;
11266 + regs->npc = addr+4;
11267 + return 2;
11268 + }
11269 + } while (0);
11270 +
11271 + do { /* PaX: patched PLT emulation #3 */
11272 + unsigned int sethi, bajmpl, nop;
11273 +
11274 + err = get_user(sethi, (unsigned int *)regs->pc);
11275 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11276 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11277 +
11278 + if (err)
11279 + break;
11280 +
11281 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11282 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11283 + nop == 0x01000000U)
11284 + {
11285 + unsigned int addr;
11286 +
11287 + addr = (sethi & 0x003FFFFFU) << 10;
11288 + regs->u_regs[UREG_G1] = addr;
11289 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11290 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11291 + else
11292 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11293 + regs->pc = addr;
11294 + regs->npc = addr+4;
11295 + return 2;
11296 + }
11297 + } while (0);
11298 +
11299 + do { /* PaX: unpatched PLT emulation step 1 */
11300 + unsigned int sethi, ba, nop;
11301 +
11302 + err = get_user(sethi, (unsigned int *)regs->pc);
11303 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11304 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11305 +
11306 + if (err)
11307 + break;
11308 +
11309 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11310 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11311 + nop == 0x01000000U)
11312 + {
11313 + unsigned int addr, save, call;
11314 +
11315 + if ((ba & 0xFFC00000U) == 0x30800000U)
11316 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11317 + else
11318 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11319 +
11320 + err = get_user(save, (unsigned int *)addr);
11321 + err |= get_user(call, (unsigned int *)(addr+4));
11322 + err |= get_user(nop, (unsigned int *)(addr+8));
11323 + if (err)
11324 + break;
11325 +
11326 +#ifdef CONFIG_PAX_DLRESOLVE
11327 + if (save == 0x9DE3BFA8U &&
11328 + (call & 0xC0000000U) == 0x40000000U &&
11329 + nop == 0x01000000U)
11330 + {
11331 + struct vm_area_struct *vma;
11332 + unsigned long call_dl_resolve;
11333 +
11334 + down_read(&current->mm->mmap_sem);
11335 + call_dl_resolve = current->mm->call_dl_resolve;
11336 + up_read(&current->mm->mmap_sem);
11337 + if (likely(call_dl_resolve))
11338 + goto emulate;
11339 +
11340 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11341 +
11342 + down_write(&current->mm->mmap_sem);
11343 + if (current->mm->call_dl_resolve) {
11344 + call_dl_resolve = current->mm->call_dl_resolve;
11345 + up_write(&current->mm->mmap_sem);
11346 + if (vma)
11347 + kmem_cache_free(vm_area_cachep, vma);
11348 + goto emulate;
11349 + }
11350 +
11351 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11352 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11353 + up_write(&current->mm->mmap_sem);
11354 + if (vma)
11355 + kmem_cache_free(vm_area_cachep, vma);
11356 + return 1;
11357 + }
11358 +
11359 + if (pax_insert_vma(vma, call_dl_resolve)) {
11360 + up_write(&current->mm->mmap_sem);
11361 + kmem_cache_free(vm_area_cachep, vma);
11362 + return 1;
11363 + }
11364 +
11365 + current->mm->call_dl_resolve = call_dl_resolve;
11366 + up_write(&current->mm->mmap_sem);
11367 +
11368 +emulate:
11369 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11370 + regs->pc = call_dl_resolve;
11371 + regs->npc = addr+4;
11372 + return 3;
11373 + }
11374 +#endif
11375 +
11376 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11377 + if ((save & 0xFFC00000U) == 0x05000000U &&
11378 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11379 + nop == 0x01000000U)
11380 + {
11381 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11382 + regs->u_regs[UREG_G2] = addr + 4;
11383 + addr = (save & 0x003FFFFFU) << 10;
11384 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11385 + regs->pc = addr;
11386 + regs->npc = addr+4;
11387 + return 3;
11388 + }
11389 + }
11390 + } while (0);
11391 +
11392 + do { /* PaX: unpatched PLT emulation step 2 */
11393 + unsigned int save, call, nop;
11394 +
11395 + err = get_user(save, (unsigned int *)(regs->pc-4));
11396 + err |= get_user(call, (unsigned int *)regs->pc);
11397 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11398 + if (err)
11399 + break;
11400 +
11401 + if (save == 0x9DE3BFA8U &&
11402 + (call & 0xC0000000U) == 0x40000000U &&
11403 + nop == 0x01000000U)
11404 + {
11405 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11406 +
11407 + regs->u_regs[UREG_RETPC] = regs->pc;
11408 + regs->pc = dl_resolve;
11409 + regs->npc = dl_resolve+4;
11410 + return 3;
11411 + }
11412 + } while (0);
11413 +#endif
11414 +
11415 + return 1;
11416 +}
11417 +
11418 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11419 +{
11420 + unsigned long i;
11421 +
11422 + printk(KERN_ERR "PAX: bytes at PC: ");
11423 + for (i = 0; i < 8; i++) {
11424 + unsigned int c;
11425 + if (get_user(c, (unsigned int *)pc+i))
11426 + printk(KERN_CONT "???????? ");
11427 + else
11428 + printk(KERN_CONT "%08x ", c);
11429 + }
11430 + printk("\n");
11431 +}
11432 +#endif
11433 +
11434 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11435 int text_fault)
11436 {
11437 @@ -229,6 +503,24 @@ good_area:
11438 if (!(vma->vm_flags & VM_WRITE))
11439 goto bad_area;
11440 } else {
11441 +
11442 +#ifdef CONFIG_PAX_PAGEEXEC
11443 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11444 + up_read(&mm->mmap_sem);
11445 + switch (pax_handle_fetch_fault(regs)) {
11446 +
11447 +#ifdef CONFIG_PAX_EMUPLT
11448 + case 2:
11449 + case 3:
11450 + return;
11451 +#endif
11452 +
11453 + }
11454 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11455 + do_group_exit(SIGKILL);
11456 + }
11457 +#endif
11458 +
11459 /* Allow reads even for write-only mappings */
11460 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11461 goto bad_area;
11462 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11463 index 69bb818..3542236 100644
11464 --- a/arch/sparc/mm/fault_64.c
11465 +++ b/arch/sparc/mm/fault_64.c
11466 @@ -22,6 +22,9 @@
11467 #include <linux/kdebug.h>
11468 #include <linux/percpu.h>
11469 #include <linux/context_tracking.h>
11470 +#include <linux/slab.h>
11471 +#include <linux/pagemap.h>
11472 +#include <linux/compiler.h>
11473
11474 #include <asm/page.h>
11475 #include <asm/pgtable.h>
11476 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11477 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11478 regs->tpc);
11479 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11480 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11481 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11482 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11483 dump_stack();
11484 unhandled_fault(regs->tpc, current, regs);
11485 @@ -96,38 +99,51 @@ static unsigned int get_user_insn(unsigned long tpc)
11486 pte_t *ptep, pte;
11487 unsigned long pa;
11488 u32 insn = 0;
11489 - unsigned long pstate;
11490
11491 - if (pgd_none(*pgdp))
11492 - goto outret;
11493 + if (pgd_none(*pgdp) || unlikely(pgd_bad(*pgdp)))
11494 + goto out;
11495 pudp = pud_offset(pgdp, tpc);
11496 - if (pud_none(*pudp))
11497 - goto outret;
11498 - pmdp = pmd_offset(pudp, tpc);
11499 - if (pmd_none(*pmdp))
11500 - goto outret;
11501 + if (pud_none(*pudp) || unlikely(pud_bad(*pudp)))
11502 + goto out;
11503
11504 /* This disables preemption for us as well. */
11505 - __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
11506 - __asm__ __volatile__("wrpr %0, %1, %%pstate"
11507 - : : "r" (pstate), "i" (PSTATE_IE));
11508 - ptep = pte_offset_map(pmdp, tpc);
11509 - pte = *ptep;
11510 - if (!pte_present(pte))
11511 - goto out;
11512 + local_irq_disable();
11513
11514 - pa = (pte_pfn(pte) << PAGE_SHIFT);
11515 - pa += (tpc & ~PAGE_MASK);
11516 + pmdp = pmd_offset(pudp, tpc);
11517 + if (pmd_none(*pmdp) || unlikely(pmd_bad(*pmdp)))
11518 + goto out_irq_enable;
11519
11520 - /* Use phys bypass so we don't pollute dtlb/dcache. */
11521 - __asm__ __volatile__("lduwa [%1] %2, %0"
11522 - : "=r" (insn)
11523 - : "r" (pa), "i" (ASI_PHYS_USE_EC));
11524 +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
11525 + if (pmd_trans_huge(*pmdp)) {
11526 + if (pmd_trans_splitting(*pmdp))
11527 + goto out_irq_enable;
11528
11529 + pa = pmd_pfn(*pmdp) << PAGE_SHIFT;
11530 + pa += tpc & ~HPAGE_MASK;
11531 +
11532 + /* Use phys bypass so we don't pollute dtlb/dcache. */
11533 + __asm__ __volatile__("lduwa [%1] %2, %0"
11534 + : "=r" (insn)
11535 + : "r" (pa), "i" (ASI_PHYS_USE_EC));
11536 + } else
11537 +#endif
11538 + {
11539 + ptep = pte_offset_map(pmdp, tpc);
11540 + pte = *ptep;
11541 + if (pte_present(pte)) {
11542 + pa = (pte_pfn(pte) << PAGE_SHIFT);
11543 + pa += (tpc & ~PAGE_MASK);
11544 +
11545 + /* Use phys bypass so we don't pollute dtlb/dcache. */
11546 + __asm__ __volatile__("lduwa [%1] %2, %0"
11547 + : "=r" (insn)
11548 + : "r" (pa), "i" (ASI_PHYS_USE_EC));
11549 + }
11550 + pte_unmap(ptep);
11551 + }
11552 +out_irq_enable:
11553 + local_irq_enable();
11554 out:
11555 - pte_unmap(ptep);
11556 - __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
11557 -outret:
11558 return insn;
11559 }
11560
11561 @@ -153,7 +169,8 @@ show_signal_msg(struct pt_regs *regs, int sig, int code,
11562 }
11563
11564 static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11565 - unsigned int insn, int fault_code)
11566 + unsigned long fault_addr, unsigned int insn,
11567 + int fault_code)
11568 {
11569 unsigned long addr;
11570 siginfo_t info;
11571 @@ -161,10 +178,18 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11572 info.si_code = code;
11573 info.si_signo = sig;
11574 info.si_errno = 0;
11575 - if (fault_code & FAULT_CODE_ITLB)
11576 + if (fault_code & FAULT_CODE_ITLB) {
11577 addr = regs->tpc;
11578 - else
11579 - addr = compute_effective_address(regs, insn, 0);
11580 + } else {
11581 + /* If we were able to probe the faulting instruction, use it
11582 + * to compute a precise fault address. Otherwise use the fault
11583 + * time provided address which may only have page granularity.
11584 + */
11585 + if (insn)
11586 + addr = compute_effective_address(regs, insn, 0);
11587 + else
11588 + addr = fault_addr;
11589 + }
11590 info.si_addr = (void __user *) addr;
11591 info.si_trapno = 0;
11592
11593 @@ -239,7 +264,7 @@ static void __kprobes do_kernel_fault(struct pt_regs *regs, int si_code,
11594 /* The si_code was set to make clear whether
11595 * this was a SEGV_MAPERR or SEGV_ACCERR fault.
11596 */
11597 - do_fault_siginfo(si_code, SIGSEGV, regs, insn, fault_code);
11598 + do_fault_siginfo(si_code, SIGSEGV, regs, address, insn, fault_code);
11599 return;
11600 }
11601
11602 @@ -271,6 +296,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11603 show_regs(regs);
11604 }
11605
11606 +#ifdef CONFIG_PAX_PAGEEXEC
11607 +#ifdef CONFIG_PAX_DLRESOLVE
11608 +static void pax_emuplt_close(struct vm_area_struct *vma)
11609 +{
11610 + vma->vm_mm->call_dl_resolve = 0UL;
11611 +}
11612 +
11613 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11614 +{
11615 + unsigned int *kaddr;
11616 +
11617 + vmf->page = alloc_page(GFP_HIGHUSER);
11618 + if (!vmf->page)
11619 + return VM_FAULT_OOM;
11620 +
11621 + kaddr = kmap(vmf->page);
11622 + memset(kaddr, 0, PAGE_SIZE);
11623 + kaddr[0] = 0x9DE3BFA8U; /* save */
11624 + flush_dcache_page(vmf->page);
11625 + kunmap(vmf->page);
11626 + return VM_FAULT_MAJOR;
11627 +}
11628 +
11629 +static const struct vm_operations_struct pax_vm_ops = {
11630 + .close = pax_emuplt_close,
11631 + .fault = pax_emuplt_fault
11632 +};
11633 +
11634 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11635 +{
11636 + int ret;
11637 +
11638 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11639 + vma->vm_mm = current->mm;
11640 + vma->vm_start = addr;
11641 + vma->vm_end = addr + PAGE_SIZE;
11642 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11643 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11644 + vma->vm_ops = &pax_vm_ops;
11645 +
11646 + ret = insert_vm_struct(current->mm, vma);
11647 + if (ret)
11648 + return ret;
11649 +
11650 + ++current->mm->total_vm;
11651 + return 0;
11652 +}
11653 +#endif
11654 +
11655 +/*
11656 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11657 + *
11658 + * returns 1 when task should be killed
11659 + * 2 when patched PLT trampoline was detected
11660 + * 3 when unpatched PLT trampoline was detected
11661 + */
11662 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11663 +{
11664 +
11665 +#ifdef CONFIG_PAX_EMUPLT
11666 + int err;
11667 +
11668 + do { /* PaX: patched PLT emulation #1 */
11669 + unsigned int sethi1, sethi2, jmpl;
11670 +
11671 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11672 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11673 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11674 +
11675 + if (err)
11676 + break;
11677 +
11678 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11679 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11680 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11681 + {
11682 + unsigned long addr;
11683 +
11684 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11685 + addr = regs->u_regs[UREG_G1];
11686 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11687 +
11688 + if (test_thread_flag(TIF_32BIT))
11689 + addr &= 0xFFFFFFFFUL;
11690 +
11691 + regs->tpc = addr;
11692 + regs->tnpc = addr+4;
11693 + return 2;
11694 + }
11695 + } while (0);
11696 +
11697 + do { /* PaX: patched PLT emulation #2 */
11698 + unsigned int ba;
11699 +
11700 + err = get_user(ba, (unsigned int *)regs->tpc);
11701 +
11702 + if (err)
11703 + break;
11704 +
11705 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11706 + unsigned long addr;
11707 +
11708 + if ((ba & 0xFFC00000U) == 0x30800000U)
11709 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11710 + else
11711 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11712 +
11713 + if (test_thread_flag(TIF_32BIT))
11714 + addr &= 0xFFFFFFFFUL;
11715 +
11716 + regs->tpc = addr;
11717 + regs->tnpc = addr+4;
11718 + return 2;
11719 + }
11720 + } while (0);
11721 +
11722 + do { /* PaX: patched PLT emulation #3 */
11723 + unsigned int sethi, bajmpl, nop;
11724 +
11725 + err = get_user(sethi, (unsigned int *)regs->tpc);
11726 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11727 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11728 +
11729 + if (err)
11730 + break;
11731 +
11732 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11733 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11734 + nop == 0x01000000U)
11735 + {
11736 + unsigned long addr;
11737 +
11738 + addr = (sethi & 0x003FFFFFU) << 10;
11739 + regs->u_regs[UREG_G1] = addr;
11740 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11741 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11742 + else
11743 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11744 +
11745 + if (test_thread_flag(TIF_32BIT))
11746 + addr &= 0xFFFFFFFFUL;
11747 +
11748 + regs->tpc = addr;
11749 + regs->tnpc = addr+4;
11750 + return 2;
11751 + }
11752 + } while (0);
11753 +
11754 + do { /* PaX: patched PLT emulation #4 */
11755 + unsigned int sethi, mov1, call, mov2;
11756 +
11757 + err = get_user(sethi, (unsigned int *)regs->tpc);
11758 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11759 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11760 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11761 +
11762 + if (err)
11763 + break;
11764 +
11765 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11766 + mov1 == 0x8210000FU &&
11767 + (call & 0xC0000000U) == 0x40000000U &&
11768 + mov2 == 0x9E100001U)
11769 + {
11770 + unsigned long addr;
11771 +
11772 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11773 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11774 +
11775 + if (test_thread_flag(TIF_32BIT))
11776 + addr &= 0xFFFFFFFFUL;
11777 +
11778 + regs->tpc = addr;
11779 + regs->tnpc = addr+4;
11780 + return 2;
11781 + }
11782 + } while (0);
11783 +
11784 + do { /* PaX: patched PLT emulation #5 */
11785 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11786 +
11787 + err = get_user(sethi, (unsigned int *)regs->tpc);
11788 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11789 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11790 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11791 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11792 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11793 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11794 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11795 +
11796 + if (err)
11797 + break;
11798 +
11799 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11800 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11801 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11802 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11803 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11804 + sllx == 0x83287020U &&
11805 + jmpl == 0x81C04005U &&
11806 + nop == 0x01000000U)
11807 + {
11808 + unsigned long addr;
11809 +
11810 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11811 + regs->u_regs[UREG_G1] <<= 32;
11812 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11813 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11814 + regs->tpc = addr;
11815 + regs->tnpc = addr+4;
11816 + return 2;
11817 + }
11818 + } while (0);
11819 +
11820 + do { /* PaX: patched PLT emulation #6 */
11821 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11822 +
11823 + err = get_user(sethi, (unsigned int *)regs->tpc);
11824 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11825 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11826 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11827 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11828 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11829 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11830 +
11831 + if (err)
11832 + break;
11833 +
11834 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11835 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11836 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11837 + sllx == 0x83287020U &&
11838 + (or & 0xFFFFE000U) == 0x8A116000U &&
11839 + jmpl == 0x81C04005U &&
11840 + nop == 0x01000000U)
11841 + {
11842 + unsigned long addr;
11843 +
11844 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11845 + regs->u_regs[UREG_G1] <<= 32;
11846 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11847 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11848 + regs->tpc = addr;
11849 + regs->tnpc = addr+4;
11850 + return 2;
11851 + }
11852 + } while (0);
11853 +
11854 + do { /* PaX: unpatched PLT emulation step 1 */
11855 + unsigned int sethi, ba, nop;
11856 +
11857 + err = get_user(sethi, (unsigned int *)regs->tpc);
11858 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11859 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11860 +
11861 + if (err)
11862 + break;
11863 +
11864 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11865 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11866 + nop == 0x01000000U)
11867 + {
11868 + unsigned long addr;
11869 + unsigned int save, call;
11870 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11871 +
11872 + if ((ba & 0xFFC00000U) == 0x30800000U)
11873 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11874 + else
11875 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11876 +
11877 + if (test_thread_flag(TIF_32BIT))
11878 + addr &= 0xFFFFFFFFUL;
11879 +
11880 + err = get_user(save, (unsigned int *)addr);
11881 + err |= get_user(call, (unsigned int *)(addr+4));
11882 + err |= get_user(nop, (unsigned int *)(addr+8));
11883 + if (err)
11884 + break;
11885 +
11886 +#ifdef CONFIG_PAX_DLRESOLVE
11887 + if (save == 0x9DE3BFA8U &&
11888 + (call & 0xC0000000U) == 0x40000000U &&
11889 + nop == 0x01000000U)
11890 + {
11891 + struct vm_area_struct *vma;
11892 + unsigned long call_dl_resolve;
11893 +
11894 + down_read(&current->mm->mmap_sem);
11895 + call_dl_resolve = current->mm->call_dl_resolve;
11896 + up_read(&current->mm->mmap_sem);
11897 + if (likely(call_dl_resolve))
11898 + goto emulate;
11899 +
11900 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11901 +
11902 + down_write(&current->mm->mmap_sem);
11903 + if (current->mm->call_dl_resolve) {
11904 + call_dl_resolve = current->mm->call_dl_resolve;
11905 + up_write(&current->mm->mmap_sem);
11906 + if (vma)
11907 + kmem_cache_free(vm_area_cachep, vma);
11908 + goto emulate;
11909 + }
11910 +
11911 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11912 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11913 + up_write(&current->mm->mmap_sem);
11914 + if (vma)
11915 + kmem_cache_free(vm_area_cachep, vma);
11916 + return 1;
11917 + }
11918 +
11919 + if (pax_insert_vma(vma, call_dl_resolve)) {
11920 + up_write(&current->mm->mmap_sem);
11921 + kmem_cache_free(vm_area_cachep, vma);
11922 + return 1;
11923 + }
11924 +
11925 + current->mm->call_dl_resolve = call_dl_resolve;
11926 + up_write(&current->mm->mmap_sem);
11927 +
11928 +emulate:
11929 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11930 + regs->tpc = call_dl_resolve;
11931 + regs->tnpc = addr+4;
11932 + return 3;
11933 + }
11934 +#endif
11935 +
11936 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11937 + if ((save & 0xFFC00000U) == 0x05000000U &&
11938 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11939 + nop == 0x01000000U)
11940 + {
11941 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11942 + regs->u_regs[UREG_G2] = addr + 4;
11943 + addr = (save & 0x003FFFFFU) << 10;
11944 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11945 +
11946 + if (test_thread_flag(TIF_32BIT))
11947 + addr &= 0xFFFFFFFFUL;
11948 +
11949 + regs->tpc = addr;
11950 + regs->tnpc = addr+4;
11951 + return 3;
11952 + }
11953 +
11954 + /* PaX: 64-bit PLT stub */
11955 + err = get_user(sethi1, (unsigned int *)addr);
11956 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11957 + err |= get_user(or1, (unsigned int *)(addr+8));
11958 + err |= get_user(or2, (unsigned int *)(addr+12));
11959 + err |= get_user(sllx, (unsigned int *)(addr+16));
11960 + err |= get_user(add, (unsigned int *)(addr+20));
11961 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11962 + err |= get_user(nop, (unsigned int *)(addr+28));
11963 + if (err)
11964 + break;
11965 +
11966 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11967 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11968 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11969 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11970 + sllx == 0x89293020U &&
11971 + add == 0x8A010005U &&
11972 + jmpl == 0x89C14000U &&
11973 + nop == 0x01000000U)
11974 + {
11975 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11976 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11977 + regs->u_regs[UREG_G4] <<= 32;
11978 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11979 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11980 + regs->u_regs[UREG_G4] = addr + 24;
11981 + addr = regs->u_regs[UREG_G5];
11982 + regs->tpc = addr;
11983 + regs->tnpc = addr+4;
11984 + return 3;
11985 + }
11986 + }
11987 + } while (0);
11988 +
11989 +#ifdef CONFIG_PAX_DLRESOLVE
11990 + do { /* PaX: unpatched PLT emulation step 2 */
11991 + unsigned int save, call, nop;
11992 +
11993 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11994 + err |= get_user(call, (unsigned int *)regs->tpc);
11995 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11996 + if (err)
11997 + break;
11998 +
11999 + if (save == 0x9DE3BFA8U &&
12000 + (call & 0xC0000000U) == 0x40000000U &&
12001 + nop == 0x01000000U)
12002 + {
12003 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12004 +
12005 + if (test_thread_flag(TIF_32BIT))
12006 + dl_resolve &= 0xFFFFFFFFUL;
12007 +
12008 + regs->u_regs[UREG_RETPC] = regs->tpc;
12009 + regs->tpc = dl_resolve;
12010 + regs->tnpc = dl_resolve+4;
12011 + return 3;
12012 + }
12013 + } while (0);
12014 +#endif
12015 +
12016 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12017 + unsigned int sethi, ba, nop;
12018 +
12019 + err = get_user(sethi, (unsigned int *)regs->tpc);
12020 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12021 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12022 +
12023 + if (err)
12024 + break;
12025 +
12026 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
12027 + (ba & 0xFFF00000U) == 0x30600000U &&
12028 + nop == 0x01000000U)
12029 + {
12030 + unsigned long addr;
12031 +
12032 + addr = (sethi & 0x003FFFFFU) << 10;
12033 + regs->u_regs[UREG_G1] = addr;
12034 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12035 +
12036 + if (test_thread_flag(TIF_32BIT))
12037 + addr &= 0xFFFFFFFFUL;
12038 +
12039 + regs->tpc = addr;
12040 + regs->tnpc = addr+4;
12041 + return 2;
12042 + }
12043 + } while (0);
12044 +
12045 +#endif
12046 +
12047 + return 1;
12048 +}
12049 +
12050 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12051 +{
12052 + unsigned long i;
12053 +
12054 + printk(KERN_ERR "PAX: bytes at PC: ");
12055 + for (i = 0; i < 8; i++) {
12056 + unsigned int c;
12057 + if (get_user(c, (unsigned int *)pc+i))
12058 + printk(KERN_CONT "???????? ");
12059 + else
12060 + printk(KERN_CONT "%08x ", c);
12061 + }
12062 + printk("\n");
12063 +}
12064 +#endif
12065 +
12066 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12067 {
12068 enum ctx_state prev_state = exception_enter();
12069 @@ -344,6 +829,29 @@ retry:
12070 if (!vma)
12071 goto bad_area;
12072
12073 +#ifdef CONFIG_PAX_PAGEEXEC
12074 + /* PaX: detect ITLB misses on non-exec pages */
12075 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12076 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12077 + {
12078 + if (address != regs->tpc)
12079 + goto good_area;
12080 +
12081 + up_read(&mm->mmap_sem);
12082 + switch (pax_handle_fetch_fault(regs)) {
12083 +
12084 +#ifdef CONFIG_PAX_EMUPLT
12085 + case 2:
12086 + case 3:
12087 + return;
12088 +#endif
12089 +
12090 + }
12091 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12092 + do_group_exit(SIGKILL);
12093 + }
12094 +#endif
12095 +
12096 /* Pure DTLB misses do not tell us whether the fault causing
12097 * load/store/atomic was a write or not, it only says that there
12098 * was no match. So in such a case we (carefully) read the
12099 @@ -525,7 +1033,7 @@ do_sigbus:
12100 * Send a sigbus, regardless of whether we were in kernel
12101 * or user mode.
12102 */
12103 - do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, insn, fault_code);
12104 + do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, address, insn, fault_code);
12105
12106 /* Kernel mode? Handle exceptions or die */
12107 if (regs->tstate & TSTATE_PRIV)
12108 diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c
12109 index c4d3da6..1aed043 100644
12110 --- a/arch/sparc/mm/gup.c
12111 +++ b/arch/sparc/mm/gup.c
12112 @@ -73,7 +73,7 @@ static int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long addr,
12113 struct page *head, *page, *tail;
12114 int refs;
12115
12116 - if (!pmd_large(pmd))
12117 + if (!(pmd_val(pmd) & _PAGE_VALID))
12118 return 0;
12119
12120 if (write && !pmd_write(pmd))
12121 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12122 index 9bd9ce8..dc84852 100644
12123 --- a/arch/sparc/mm/hugetlbpage.c
12124 +++ b/arch/sparc/mm/hugetlbpage.c
12125 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12126 unsigned long addr,
12127 unsigned long len,
12128 unsigned long pgoff,
12129 - unsigned long flags)
12130 + unsigned long flags,
12131 + unsigned long offset)
12132 {
12133 + struct mm_struct *mm = current->mm;
12134 unsigned long task_size = TASK_SIZE;
12135 struct vm_unmapped_area_info info;
12136
12137 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12138
12139 info.flags = 0;
12140 info.length = len;
12141 - info.low_limit = TASK_UNMAPPED_BASE;
12142 + info.low_limit = mm->mmap_base;
12143 info.high_limit = min(task_size, VA_EXCLUDE_START);
12144 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12145 info.align_offset = 0;
12146 + info.threadstack_offset = offset;
12147 addr = vm_unmapped_area(&info);
12148
12149 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12150 VM_BUG_ON(addr != -ENOMEM);
12151 info.low_limit = VA_EXCLUDE_END;
12152 +
12153 +#ifdef CONFIG_PAX_RANDMMAP
12154 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12155 + info.low_limit += mm->delta_mmap;
12156 +#endif
12157 +
12158 info.high_limit = task_size;
12159 addr = vm_unmapped_area(&info);
12160 }
12161 @@ -55,7 +64,8 @@ static unsigned long
12162 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12163 const unsigned long len,
12164 const unsigned long pgoff,
12165 - const unsigned long flags)
12166 + const unsigned long flags,
12167 + const unsigned long offset)
12168 {
12169 struct mm_struct *mm = current->mm;
12170 unsigned long addr = addr0;
12171 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12172 info.high_limit = mm->mmap_base;
12173 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12174 info.align_offset = 0;
12175 + info.threadstack_offset = offset;
12176 addr = vm_unmapped_area(&info);
12177
12178 /*
12179 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12180 VM_BUG_ON(addr != -ENOMEM);
12181 info.flags = 0;
12182 info.low_limit = TASK_UNMAPPED_BASE;
12183 +
12184 +#ifdef CONFIG_PAX_RANDMMAP
12185 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12186 + info.low_limit += mm->delta_mmap;
12187 +#endif
12188 +
12189 info.high_limit = STACK_TOP32;
12190 addr = vm_unmapped_area(&info);
12191 }
12192 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12193 struct mm_struct *mm = current->mm;
12194 struct vm_area_struct *vma;
12195 unsigned long task_size = TASK_SIZE;
12196 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12197
12198 if (test_thread_flag(TIF_32BIT))
12199 task_size = STACK_TOP32;
12200 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12201 return addr;
12202 }
12203
12204 +#ifdef CONFIG_PAX_RANDMMAP
12205 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12206 +#endif
12207 +
12208 if (addr) {
12209 addr = ALIGN(addr, HPAGE_SIZE);
12210 vma = find_vma(mm, addr);
12211 - if (task_size - len >= addr &&
12212 - (!vma || addr + len <= vma->vm_start))
12213 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12214 return addr;
12215 }
12216 if (mm->get_unmapped_area == arch_get_unmapped_area)
12217 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12218 - pgoff, flags);
12219 + pgoff, flags, offset);
12220 else
12221 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12222 - pgoff, flags);
12223 + pgoff, flags, offset);
12224 }
12225
12226 pte_t *huge_pte_alloc(struct mm_struct *mm,
12227 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12228 index eafbc65..5a8070d 100644
12229 --- a/arch/sparc/mm/init_64.c
12230 +++ b/arch/sparc/mm/init_64.c
12231 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12232 int num_kernel_image_mappings;
12233
12234 #ifdef CONFIG_DEBUG_DCFLUSH
12235 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12236 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12237 #ifdef CONFIG_SMP
12238 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12239 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12240 #endif
12241 #endif
12242
12243 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12244 {
12245 BUG_ON(tlb_type == hypervisor);
12246 #ifdef CONFIG_DEBUG_DCFLUSH
12247 - atomic_inc(&dcpage_flushes);
12248 + atomic_inc_unchecked(&dcpage_flushes);
12249 #endif
12250
12251 #ifdef DCACHE_ALIASING_POSSIBLE
12252 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
12253
12254 #ifdef CONFIG_DEBUG_DCFLUSH
12255 seq_printf(m, "DCPageFlushes\t: %d\n",
12256 - atomic_read(&dcpage_flushes));
12257 + atomic_read_unchecked(&dcpage_flushes));
12258 #ifdef CONFIG_SMP
12259 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12260 - atomic_read(&dcpage_flushes_xcall));
12261 + atomic_read_unchecked(&dcpage_flushes_xcall));
12262 #endif /* CONFIG_SMP */
12263 #endif /* CONFIG_DEBUG_DCFLUSH */
12264 }
12265 diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
12266 index b12cb5e..b89aba2 100644
12267 --- a/arch/sparc/mm/tlb.c
12268 +++ b/arch/sparc/mm/tlb.c
12269 @@ -134,7 +134,7 @@ no_cache_flush:
12270
12271 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
12272 static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
12273 - pmd_t pmd, bool exec)
12274 + pmd_t pmd)
12275 {
12276 unsigned long end;
12277 pte_t *pte;
12278 @@ -142,8 +142,11 @@ static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
12279 pte = pte_offset_map(&pmd, vaddr);
12280 end = vaddr + HPAGE_SIZE;
12281 while (vaddr < end) {
12282 - if (pte_val(*pte) & _PAGE_VALID)
12283 + if (pte_val(*pte) & _PAGE_VALID) {
12284 + bool exec = pte_exec(*pte);
12285 +
12286 tlb_batch_add_one(mm, vaddr, exec);
12287 + }
12288 pte++;
12289 vaddr += PAGE_SIZE;
12290 }
12291 @@ -177,19 +180,30 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,
12292 }
12293
12294 if (!pmd_none(orig)) {
12295 - pte_t orig_pte = __pte(pmd_val(orig));
12296 - bool exec = pte_exec(orig_pte);
12297 -
12298 addr &= HPAGE_MASK;
12299 if (pmd_trans_huge(orig)) {
12300 + pte_t orig_pte = __pte(pmd_val(orig));
12301 + bool exec = pte_exec(orig_pte);
12302 +
12303 tlb_batch_add_one(mm, addr, exec);
12304 tlb_batch_add_one(mm, addr + REAL_HPAGE_SIZE, exec);
12305 } else {
12306 - tlb_batch_pmd_scan(mm, addr, orig, exec);
12307 + tlb_batch_pmd_scan(mm, addr, orig);
12308 }
12309 }
12310 }
12311
12312 +void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
12313 + pmd_t *pmdp)
12314 +{
12315 + pmd_t entry = *pmdp;
12316 +
12317 + pmd_val(entry) &= ~_PAGE_VALID;
12318 +
12319 + set_pmd_at(vma->vm_mm, address, pmdp, entry);
12320 + flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
12321 +}
12322 +
12323 void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
12324 pgtable_t pgtable)
12325 {
12326 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12327 index b3692ce..e4517c9 100644
12328 --- a/arch/tile/Kconfig
12329 +++ b/arch/tile/Kconfig
12330 @@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
12331
12332 config KEXEC
12333 bool "kexec system call"
12334 + depends on !GRKERNSEC_KMEM
12335 ---help---
12336 kexec is a system call that implements the ability to shutdown your
12337 current kernel, and to start another kernel. It is like a reboot
12338 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12339 index ad220ee..2f537b3 100644
12340 --- a/arch/tile/include/asm/atomic_64.h
12341 +++ b/arch/tile/include/asm/atomic_64.h
12342 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12343
12344 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12345
12346 +#define atomic64_read_unchecked(v) atomic64_read(v)
12347 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12348 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12349 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12350 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12351 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12352 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12353 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12354 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12355 +
12356 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12357 #define smp_mb__before_atomic_dec() smp_mb()
12358 #define smp_mb__after_atomic_dec() smp_mb()
12359 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12360 index 6160761..00cac88 100644
12361 --- a/arch/tile/include/asm/cache.h
12362 +++ b/arch/tile/include/asm/cache.h
12363 @@ -15,11 +15,12 @@
12364 #ifndef _ASM_TILE_CACHE_H
12365 #define _ASM_TILE_CACHE_H
12366
12367 +#include <linux/const.h>
12368 #include <arch/chip.h>
12369
12370 /* bytes per L1 data cache line */
12371 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12372 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12373 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12374
12375 /* bytes per L2 cache line */
12376 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12377 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12378 index b6cde32..c0cb736 100644
12379 --- a/arch/tile/include/asm/uaccess.h
12380 +++ b/arch/tile/include/asm/uaccess.h
12381 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12382 const void __user *from,
12383 unsigned long n)
12384 {
12385 - int sz = __compiletime_object_size(to);
12386 + size_t sz = __compiletime_object_size(to);
12387
12388 - if (likely(sz == -1 || sz >= n))
12389 + if (likely(sz == (size_t)-1 || sz >= n))
12390 n = _copy_from_user(to, from, n);
12391 else
12392 copy_from_user_overflow();
12393 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12394 index 0cb3bba..7338b2d 100644
12395 --- a/arch/tile/mm/hugetlbpage.c
12396 +++ b/arch/tile/mm/hugetlbpage.c
12397 @@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12398 info.high_limit = TASK_SIZE;
12399 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12400 info.align_offset = 0;
12401 + info.threadstack_offset = 0;
12402 return vm_unmapped_area(&info);
12403 }
12404
12405 @@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12406 info.high_limit = current->mm->mmap_base;
12407 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12408 info.align_offset = 0;
12409 + info.threadstack_offset = 0;
12410 addr = vm_unmapped_area(&info);
12411
12412 /*
12413 diff --git a/arch/um/Makefile b/arch/um/Makefile
12414 index 36e658a..71a5c5a 100644
12415 --- a/arch/um/Makefile
12416 +++ b/arch/um/Makefile
12417 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12418 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12419 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12420
12421 +ifdef CONSTIFY_PLUGIN
12422 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12423 +endif
12424 +
12425 #This will adjust *FLAGS accordingly to the platform.
12426 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12427
12428 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12429 index 19e1bdd..3665b77 100644
12430 --- a/arch/um/include/asm/cache.h
12431 +++ b/arch/um/include/asm/cache.h
12432 @@ -1,6 +1,7 @@
12433 #ifndef __UM_CACHE_H
12434 #define __UM_CACHE_H
12435
12436 +#include <linux/const.h>
12437
12438 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12439 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12440 @@ -12,6 +13,6 @@
12441 # define L1_CACHE_SHIFT 5
12442 #endif
12443
12444 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12445 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12446
12447 #endif
12448 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12449 index 2e0a6b1..a64d0f5 100644
12450 --- a/arch/um/include/asm/kmap_types.h
12451 +++ b/arch/um/include/asm/kmap_types.h
12452 @@ -8,6 +8,6 @@
12453
12454 /* No more #include "asm/arch/kmap_types.h" ! */
12455
12456 -#define KM_TYPE_NR 14
12457 +#define KM_TYPE_NR 15
12458
12459 #endif
12460 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12461 index 5ff53d9..5850cdf 100644
12462 --- a/arch/um/include/asm/page.h
12463 +++ b/arch/um/include/asm/page.h
12464 @@ -14,6 +14,9 @@
12465 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12466 #define PAGE_MASK (~(PAGE_SIZE-1))
12467
12468 +#define ktla_ktva(addr) (addr)
12469 +#define ktva_ktla(addr) (addr)
12470 +
12471 #ifndef __ASSEMBLY__
12472
12473 struct page;
12474 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12475 index 0032f92..cd151e0 100644
12476 --- a/arch/um/include/asm/pgtable-3level.h
12477 +++ b/arch/um/include/asm/pgtable-3level.h
12478 @@ -58,6 +58,7 @@
12479 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12480 #define pud_populate(mm, pud, pmd) \
12481 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12482 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12483
12484 #ifdef CONFIG_64BIT
12485 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12486 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12487 index eecc414..48adb87 100644
12488 --- a/arch/um/kernel/process.c
12489 +++ b/arch/um/kernel/process.c
12490 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12491 return 2;
12492 }
12493
12494 -/*
12495 - * Only x86 and x86_64 have an arch_align_stack().
12496 - * All other arches have "#define arch_align_stack(x) (x)"
12497 - * in their asm/system.h
12498 - * As this is included in UML from asm-um/system-generic.h,
12499 - * we can use it to behave as the subarch does.
12500 - */
12501 -#ifndef arch_align_stack
12502 -unsigned long arch_align_stack(unsigned long sp)
12503 -{
12504 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12505 - sp -= get_random_int() % 8192;
12506 - return sp & ~0xf;
12507 -}
12508 -#endif
12509 -
12510 unsigned long get_wchan(struct task_struct *p)
12511 {
12512 unsigned long stack_page, sp, ip;
12513 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12514 index ad8f795..2c7eec6 100644
12515 --- a/arch/unicore32/include/asm/cache.h
12516 +++ b/arch/unicore32/include/asm/cache.h
12517 @@ -12,8 +12,10 @@
12518 #ifndef __UNICORE_CACHE_H__
12519 #define __UNICORE_CACHE_H__
12520
12521 -#define L1_CACHE_SHIFT (5)
12522 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12523 +#include <linux/const.h>
12524 +
12525 +#define L1_CACHE_SHIFT 5
12526 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12527
12528 /*
12529 * Memory returned by kmalloc() may be used for DMA, so we must make
12530 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12531 index 0af5250..59f9597 100644
12532 --- a/arch/x86/Kconfig
12533 +++ b/arch/x86/Kconfig
12534 @@ -126,7 +126,7 @@ config X86
12535 select RTC_LIB
12536 select HAVE_DEBUG_STACKOVERFLOW
12537 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12538 - select HAVE_CC_STACKPROTECTOR
12539 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12540
12541 config INSTRUCTION_DECODER
12542 def_bool y
12543 @@ -251,7 +251,7 @@ config X86_HT
12544
12545 config X86_32_LAZY_GS
12546 def_bool y
12547 - depends on X86_32 && !CC_STACKPROTECTOR
12548 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12549
12550 config ARCH_HWEIGHT_CFLAGS
12551 string
12552 @@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
12553
12554 menuconfig HYPERVISOR_GUEST
12555 bool "Linux guest support"
12556 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12557 ---help---
12558 Say Y here to enable options for running Linux under various hyper-
12559 visors. This option enables basic hypervisor detection and platform
12560 @@ -1111,7 +1112,7 @@ choice
12561
12562 config NOHIGHMEM
12563 bool "off"
12564 - depends on !X86_NUMAQ
12565 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12566 ---help---
12567 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12568 However, the address space of 32-bit x86 processors is only 4
12569 @@ -1148,7 +1149,7 @@ config NOHIGHMEM
12570
12571 config HIGHMEM4G
12572 bool "4GB"
12573 - depends on !X86_NUMAQ
12574 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12575 ---help---
12576 Select this if you have a 32-bit processor and between 1 and 4
12577 gigabytes of physical RAM.
12578 @@ -1201,7 +1202,7 @@ config PAGE_OFFSET
12579 hex
12580 default 0xB0000000 if VMSPLIT_3G_OPT
12581 default 0x80000000 if VMSPLIT_2G
12582 - default 0x78000000 if VMSPLIT_2G_OPT
12583 + default 0x70000000 if VMSPLIT_2G_OPT
12584 default 0x40000000 if VMSPLIT_1G
12585 default 0xC0000000
12586 depends on X86_32
12587 @@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
12588
12589 config KEXEC
12590 bool "kexec system call"
12591 + depends on !GRKERNSEC_KMEM
12592 ---help---
12593 kexec is a system call that implements the ability to shutdown your
12594 current kernel, and to start another kernel. It is like a reboot
12595 @@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
12596
12597 config PHYSICAL_ALIGN
12598 hex "Alignment value to which kernel should be aligned"
12599 - default "0x200000"
12600 + default "0x1000000"
12601 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12602 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12603 range 0x2000 0x1000000 if X86_32
12604 range 0x200000 0x1000000 if X86_64
12605 ---help---
12606 @@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
12607 If unsure, say N.
12608
12609 config COMPAT_VDSO
12610 - def_bool y
12611 + def_bool n
12612 prompt "Compat VDSO support"
12613 depends on X86_32 || IA32_EMULATION
12614 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12615 ---help---
12616 Map the 32-bit VDSO to the predictable old-style address too.
12617
12618 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12619 index f3aaf23..a1d3c49 100644
12620 --- a/arch/x86/Kconfig.cpu
12621 +++ b/arch/x86/Kconfig.cpu
12622 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12623
12624 config X86_F00F_BUG
12625 def_bool y
12626 - depends on M586MMX || M586TSC || M586 || M486
12627 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12628
12629 config X86_INVD_BUG
12630 def_bool y
12631 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12632
12633 config X86_ALIGNMENT_16
12634 def_bool y
12635 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12636 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12637
12638 config X86_INTEL_USERCOPY
12639 def_bool y
12640 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12641 # generates cmov.
12642 config X86_CMOV
12643 def_bool y
12644 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12645 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12646
12647 config X86_MINIMUM_CPU_FAMILY
12648 int
12649 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12650 index 321a52c..3d51a5e 100644
12651 --- a/arch/x86/Kconfig.debug
12652 +++ b/arch/x86/Kconfig.debug
12653 @@ -84,7 +84,7 @@ config X86_PTDUMP
12654 config DEBUG_RODATA
12655 bool "Write protect kernel read-only data structures"
12656 default y
12657 - depends on DEBUG_KERNEL
12658 + depends on DEBUG_KERNEL && BROKEN
12659 ---help---
12660 Mark the kernel read-only data as write-protected in the pagetables,
12661 in order to catch accidental (and incorrect) writes to such const
12662 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12663
12664 config DEBUG_SET_MODULE_RONX
12665 bool "Set loadable kernel module data as NX and text as RO"
12666 - depends on MODULES
12667 + depends on MODULES && BROKEN
12668 ---help---
12669 This option helps catch unintended modifications to loadable
12670 kernel module's text and read-only data. It also prevents execution
12671 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12672 index 0dd99ea..4a63d82 100644
12673 --- a/arch/x86/Makefile
12674 +++ b/arch/x86/Makefile
12675 @@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12676 # CPU-specific tuning. Anything which can be shared with UML should go here.
12677 include $(srctree)/arch/x86/Makefile_32.cpu
12678 KBUILD_CFLAGS += $(cflags-y)
12679 -
12680 - # temporary until string.h is fixed
12681 - KBUILD_CFLAGS += -ffreestanding
12682 else
12683 BITS := 64
12684 UTS_MACHINE := x86_64
12685 @@ -112,6 +109,9 @@ else
12686 KBUILD_CFLAGS += -maccumulate-outgoing-args
12687 endif
12688
12689 +# temporary until string.h is fixed
12690 +KBUILD_CFLAGS += -ffreestanding
12691 +
12692 # Make sure compiler does not have buggy stack-protector support.
12693 ifdef CONFIG_CC_STACKPROTECTOR
12694 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12695 @@ -269,3 +269,12 @@ define archhelp
12696 echo ' FDINITRD=file initrd for the booted kernel'
12697 echo ' kvmconfig - Enable additional options for guest kernel support'
12698 endef
12699 +
12700 +define OLD_LD
12701 +
12702 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12703 +*** Please upgrade your binutils to 2.18 or newer
12704 +endef
12705 +
12706 +archprepare:
12707 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12708 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12709 index 878df7e..a803913 100644
12710 --- a/arch/x86/boot/Makefile
12711 +++ b/arch/x86/boot/Makefile
12712 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12713 # ---------------------------------------------------------------------------
12714
12715 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12716 +ifdef CONSTIFY_PLUGIN
12717 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12718 +endif
12719 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12720 GCOV_PROFILE := n
12721
12722 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12723 index 878e4b9..20537ab 100644
12724 --- a/arch/x86/boot/bitops.h
12725 +++ b/arch/x86/boot/bitops.h
12726 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12727 u8 v;
12728 const u32 *p = (const u32 *)addr;
12729
12730 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12731 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12732 return v;
12733 }
12734
12735 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12736
12737 static inline void set_bit(int nr, void *addr)
12738 {
12739 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12740 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12741 }
12742
12743 #endif /* BOOT_BITOPS_H */
12744 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12745 index 50f8c5e..4f84fff 100644
12746 --- a/arch/x86/boot/boot.h
12747 +++ b/arch/x86/boot/boot.h
12748 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12749 static inline u16 ds(void)
12750 {
12751 u16 seg;
12752 - asm("movw %%ds,%0" : "=rm" (seg));
12753 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12754 return seg;
12755 }
12756
12757 @@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12758 static inline int memcmp(const void *s1, const void *s2, size_t len)
12759 {
12760 u8 diff;
12761 - asm("repe; cmpsb; setnz %0"
12762 + asm volatile("repe; cmpsb; setnz %0"
12763 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12764 return diff;
12765 }
12766 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12767 index 0fcd913..3bb5c42 100644
12768 --- a/arch/x86/boot/compressed/Makefile
12769 +++ b/arch/x86/boot/compressed/Makefile
12770 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12771 KBUILD_CFLAGS += -mno-mmx -mno-sse
12772 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12773 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12774 +ifdef CONSTIFY_PLUGIN
12775 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12776 +endif
12777
12778 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12779 GCOV_PROFILE := n
12780 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12781 index a53440e..c3dbf1e 100644
12782 --- a/arch/x86/boot/compressed/efi_stub_32.S
12783 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12784 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12785 * parameter 2, ..., param n. To make things easy, we save the return
12786 * address of efi_call_phys in a global variable.
12787 */
12788 - popl %ecx
12789 - movl %ecx, saved_return_addr(%edx)
12790 - /* get the function pointer into ECX*/
12791 - popl %ecx
12792 - movl %ecx, efi_rt_function_ptr(%edx)
12793 + popl saved_return_addr(%edx)
12794 + popl efi_rt_function_ptr(%edx)
12795
12796 /*
12797 * 3. Call the physical function.
12798 */
12799 - call *%ecx
12800 + call *efi_rt_function_ptr(%edx)
12801
12802 /*
12803 * 4. Balance the stack. And because EAX contain the return value,
12804 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12805 1: popl %edx
12806 subl $1b, %edx
12807
12808 - movl efi_rt_function_ptr(%edx), %ecx
12809 - pushl %ecx
12810 + pushl efi_rt_function_ptr(%edx)
12811
12812 /*
12813 * 10. Push the saved return address onto the stack and return.
12814 */
12815 - movl saved_return_addr(%edx), %ecx
12816 - pushl %ecx
12817 - ret
12818 + jmpl *saved_return_addr(%edx)
12819 ENDPROC(efi_call_phys)
12820 .previous
12821
12822 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12823 index f45ab7a..ebc015f 100644
12824 --- a/arch/x86/boot/compressed/head_32.S
12825 +++ b/arch/x86/boot/compressed/head_32.S
12826 @@ -119,10 +119,10 @@ preferred_addr:
12827 addl %eax, %ebx
12828 notl %eax
12829 andl %eax, %ebx
12830 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12831 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12832 jge 1f
12833 #endif
12834 - movl $LOAD_PHYSICAL_ADDR, %ebx
12835 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12836 1:
12837
12838 /* Target address to relocate to for decompression */
12839 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12840 index b10fa66..5ee0472 100644
12841 --- a/arch/x86/boot/compressed/head_64.S
12842 +++ b/arch/x86/boot/compressed/head_64.S
12843 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12844 addl %eax, %ebx
12845 notl %eax
12846 andl %eax, %ebx
12847 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12848 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12849 jge 1f
12850 #endif
12851 - movl $LOAD_PHYSICAL_ADDR, %ebx
12852 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12853 1:
12854
12855 /* Target address to relocate to for decompression */
12856 @@ -268,10 +268,10 @@ preferred_addr:
12857 addq %rax, %rbp
12858 notq %rax
12859 andq %rax, %rbp
12860 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12861 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12862 jge 1f
12863 #endif
12864 - movq $LOAD_PHYSICAL_ADDR, %rbp
12865 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12866 1:
12867
12868 /* Target address to relocate to for decompression */
12869 @@ -363,8 +363,8 @@ gdt:
12870 .long gdt
12871 .word 0
12872 .quad 0x0000000000000000 /* NULL descriptor */
12873 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12874 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12875 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12876 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12877 .quad 0x0080890000000000 /* TS descriptor */
12878 .quad 0x0000000000000000 /* TS continued */
12879 gdt_end:
12880 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12881 index 196eaf3..c96716d 100644
12882 --- a/arch/x86/boot/compressed/misc.c
12883 +++ b/arch/x86/boot/compressed/misc.c
12884 @@ -218,7 +218,7 @@ void __putstr(const char *s)
12885
12886 void *memset(void *s, int c, size_t n)
12887 {
12888 - int i;
12889 + size_t i;
12890 char *ss = s;
12891
12892 for (i = 0; i < n; i++)
12893 @@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12894 * Calculate the delta between where vmlinux was linked to load
12895 * and where it was actually loaded.
12896 */
12897 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12898 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12899 if (!delta) {
12900 debug_putstr("No relocation needed... ");
12901 return;
12902 @@ -347,7 +347,7 @@ static void parse_elf(void *output)
12903 Elf32_Ehdr ehdr;
12904 Elf32_Phdr *phdrs, *phdr;
12905 #endif
12906 - void *dest;
12907 + void *dest, *prev;
12908 int i;
12909
12910 memcpy(&ehdr, output, sizeof(ehdr));
12911 @@ -374,13 +374,16 @@ static void parse_elf(void *output)
12912 case PT_LOAD:
12913 #ifdef CONFIG_RELOCATABLE
12914 dest = output;
12915 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12916 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12917 #else
12918 dest = (void *)(phdr->p_paddr);
12919 #endif
12920 memcpy(dest,
12921 output + phdr->p_offset,
12922 phdr->p_filesz);
12923 + if (i)
12924 + memset(prev, 0xff, dest - prev);
12925 + prev = dest + phdr->p_filesz;
12926 break;
12927 default: /* Ignore other PT_* */ break;
12928 }
12929 @@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
12930 error("Destination address too large");
12931 #endif
12932 #ifndef CONFIG_RELOCATABLE
12933 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12934 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12935 error("Wrong destination address");
12936 #endif
12937
12938 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12939 index 100a9a1..bb3bdb0 100644
12940 --- a/arch/x86/boot/cpucheck.c
12941 +++ b/arch/x86/boot/cpucheck.c
12942 @@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12943 u32 ecx = MSR_K7_HWCR;
12944 u32 eax, edx;
12945
12946 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12947 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12948 eax &= ~(1 << 15);
12949 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12950 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12951
12952 get_cpuflags(); /* Make sure it really did something */
12953 err = check_cpuflags();
12954 @@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12955 u32 ecx = MSR_VIA_FCR;
12956 u32 eax, edx;
12957
12958 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12959 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12960 eax |= (1<<1)|(1<<7);
12961 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12962 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12963
12964 set_bit(X86_FEATURE_CX8, cpu.flags);
12965 err = check_cpuflags();
12966 @@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12967 u32 eax, edx;
12968 u32 level = 1;
12969
12970 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12971 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12972 - asm("cpuid"
12973 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12974 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12975 + asm volatile("cpuid"
12976 : "+a" (level), "=d" (cpu.flags[0])
12977 : : "ecx", "ebx");
12978 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12979 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12980
12981 err = check_cpuflags();
12982 }
12983 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12984 index ec3b8ba..6a0db1f 100644
12985 --- a/arch/x86/boot/header.S
12986 +++ b/arch/x86/boot/header.S
12987 @@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12988 # single linked list of
12989 # struct setup_data
12990
12991 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12992 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12993
12994 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12995 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12996 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12997 +#else
12998 #define VO_INIT_SIZE (VO__end - VO__text)
12999 +#endif
13000 #if ZO_INIT_SIZE > VO_INIT_SIZE
13001 #define INIT_SIZE ZO_INIT_SIZE
13002 #else
13003 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13004 index db75d07..8e6d0af 100644
13005 --- a/arch/x86/boot/memory.c
13006 +++ b/arch/x86/boot/memory.c
13007 @@ -19,7 +19,7 @@
13008
13009 static int detect_memory_e820(void)
13010 {
13011 - int count = 0;
13012 + unsigned int count = 0;
13013 struct biosregs ireg, oreg;
13014 struct e820entry *desc = boot_params.e820_map;
13015 static struct e820entry buf; /* static so it is zeroed */
13016 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13017 index 11e8c6e..fdbb1ed 100644
13018 --- a/arch/x86/boot/video-vesa.c
13019 +++ b/arch/x86/boot/video-vesa.c
13020 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
13021
13022 boot_params.screen_info.vesapm_seg = oreg.es;
13023 boot_params.screen_info.vesapm_off = oreg.di;
13024 + boot_params.screen_info.vesapm_size = oreg.cx;
13025 }
13026
13027 /*
13028 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13029 index 43eda28..5ab5fdb 100644
13030 --- a/arch/x86/boot/video.c
13031 +++ b/arch/x86/boot/video.c
13032 @@ -96,7 +96,7 @@ static void store_mode_params(void)
13033 static unsigned int get_entry(void)
13034 {
13035 char entry_buf[4];
13036 - int i, len = 0;
13037 + unsigned int i, len = 0;
13038 int key;
13039 unsigned int v;
13040
13041 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13042 index 9105655..41779c1 100644
13043 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
13044 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13045 @@ -8,6 +8,8 @@
13046 * including this sentence is retained in full.
13047 */
13048
13049 +#include <asm/alternative-asm.h>
13050 +
13051 .extern crypto_ft_tab
13052 .extern crypto_it_tab
13053 .extern crypto_fl_tab
13054 @@ -70,6 +72,8 @@
13055 je B192; \
13056 leaq 32(r9),r9;
13057
13058 +#define ret pax_force_retaddr; ret
13059 +
13060 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13061 movq r1,r2; \
13062 movq r3,r4; \
13063 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13064 index 477e9d7..c92c7d8 100644
13065 --- a/arch/x86/crypto/aesni-intel_asm.S
13066 +++ b/arch/x86/crypto/aesni-intel_asm.S
13067 @@ -31,6 +31,7 @@
13068
13069 #include <linux/linkage.h>
13070 #include <asm/inst.h>
13071 +#include <asm/alternative-asm.h>
13072
13073 #ifdef __x86_64__
13074 .data
13075 @@ -205,7 +206,7 @@ enc: .octa 0x2
13076 * num_initial_blocks = b mod 4
13077 * encrypt the initial num_initial_blocks blocks and apply ghash on
13078 * the ciphertext
13079 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13080 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13081 * are clobbered
13082 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13083 */
13084 @@ -214,8 +215,8 @@ enc: .octa 0x2
13085 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13086 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13087 mov arg7, %r10 # %r10 = AAD
13088 - mov arg8, %r12 # %r12 = aadLen
13089 - mov %r12, %r11
13090 + mov arg8, %r15 # %r15 = aadLen
13091 + mov %r15, %r11
13092 pxor %xmm\i, %xmm\i
13093 _get_AAD_loop\num_initial_blocks\operation:
13094 movd (%r10), \TMP1
13095 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13096 psrldq $4, %xmm\i
13097 pxor \TMP1, %xmm\i
13098 add $4, %r10
13099 - sub $4, %r12
13100 + sub $4, %r15
13101 jne _get_AAD_loop\num_initial_blocks\operation
13102 cmp $16, %r11
13103 je _get_AAD_loop2_done\num_initial_blocks\operation
13104 - mov $16, %r12
13105 + mov $16, %r15
13106 _get_AAD_loop2\num_initial_blocks\operation:
13107 psrldq $4, %xmm\i
13108 - sub $4, %r12
13109 - cmp %r11, %r12
13110 + sub $4, %r15
13111 + cmp %r11, %r15
13112 jne _get_AAD_loop2\num_initial_blocks\operation
13113 _get_AAD_loop2_done\num_initial_blocks\operation:
13114 movdqa SHUF_MASK(%rip), %xmm14
13115 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13116 * num_initial_blocks = b mod 4
13117 * encrypt the initial num_initial_blocks blocks and apply ghash on
13118 * the ciphertext
13119 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13120 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13121 * are clobbered
13122 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13123 */
13124 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13125 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13126 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13127 mov arg7, %r10 # %r10 = AAD
13128 - mov arg8, %r12 # %r12 = aadLen
13129 - mov %r12, %r11
13130 + mov arg8, %r15 # %r15 = aadLen
13131 + mov %r15, %r11
13132 pxor %xmm\i, %xmm\i
13133 _get_AAD_loop\num_initial_blocks\operation:
13134 movd (%r10), \TMP1
13135 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13136 psrldq $4, %xmm\i
13137 pxor \TMP1, %xmm\i
13138 add $4, %r10
13139 - sub $4, %r12
13140 + sub $4, %r15
13141 jne _get_AAD_loop\num_initial_blocks\operation
13142 cmp $16, %r11
13143 je _get_AAD_loop2_done\num_initial_blocks\operation
13144 - mov $16, %r12
13145 + mov $16, %r15
13146 _get_AAD_loop2\num_initial_blocks\operation:
13147 psrldq $4, %xmm\i
13148 - sub $4, %r12
13149 - cmp %r11, %r12
13150 + sub $4, %r15
13151 + cmp %r11, %r15
13152 jne _get_AAD_loop2\num_initial_blocks\operation
13153 _get_AAD_loop2_done\num_initial_blocks\operation:
13154 movdqa SHUF_MASK(%rip), %xmm14
13155 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13156 *
13157 *****************************************************************************/
13158 ENTRY(aesni_gcm_dec)
13159 - push %r12
13160 + push %r15
13161 push %r13
13162 push %r14
13163 mov %rsp, %r14
13164 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13165 */
13166 sub $VARIABLE_OFFSET, %rsp
13167 and $~63, %rsp # align rsp to 64 bytes
13168 - mov %arg6, %r12
13169 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
13170 + mov %arg6, %r15
13171 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
13172 movdqa SHUF_MASK(%rip), %xmm2
13173 PSHUFB_XMM %xmm2, %xmm13
13174
13175 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13176 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13177 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13178 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13179 - mov %r13, %r12
13180 - and $(3<<4), %r12
13181 + mov %r13, %r15
13182 + and $(3<<4), %r15
13183 jz _initial_num_blocks_is_0_decrypt
13184 - cmp $(2<<4), %r12
13185 + cmp $(2<<4), %r15
13186 jb _initial_num_blocks_is_1_decrypt
13187 je _initial_num_blocks_is_2_decrypt
13188 _initial_num_blocks_is_3_decrypt:
13189 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13190 sub $16, %r11
13191 add %r13, %r11
13192 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13193 - lea SHIFT_MASK+16(%rip), %r12
13194 - sub %r13, %r12
13195 + lea SHIFT_MASK+16(%rip), %r15
13196 + sub %r13, %r15
13197 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13198 # (%r13 is the number of bytes in plaintext mod 16)
13199 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13200 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13201 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13202
13203 movdqa %xmm1, %xmm2
13204 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13205 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13206 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13207 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13208 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13209 pand %xmm1, %xmm2
13210 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13211 sub $1, %r13
13212 jne _less_than_8_bytes_left_decrypt
13213 _multiple_of_16_bytes_decrypt:
13214 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
13215 - shl $3, %r12 # convert into number of bits
13216 - movd %r12d, %xmm15 # len(A) in %xmm15
13217 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
13218 + shl $3, %r15 # convert into number of bits
13219 + movd %r15d, %xmm15 # len(A) in %xmm15
13220 shl $3, %arg4 # len(C) in bits (*128)
13221 MOVQ_R64_XMM %arg4, %xmm1
13222 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13223 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13224 mov %r14, %rsp
13225 pop %r14
13226 pop %r13
13227 - pop %r12
13228 + pop %r15
13229 + pax_force_retaddr
13230 ret
13231 ENDPROC(aesni_gcm_dec)
13232
13233 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13234 * poly = x^128 + x^127 + x^126 + x^121 + 1
13235 ***************************************************************************/
13236 ENTRY(aesni_gcm_enc)
13237 - push %r12
13238 + push %r15
13239 push %r13
13240 push %r14
13241 mov %rsp, %r14
13242 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13243 #
13244 sub $VARIABLE_OFFSET, %rsp
13245 and $~63, %rsp
13246 - mov %arg6, %r12
13247 - movdqu (%r12), %xmm13
13248 + mov %arg6, %r15
13249 + movdqu (%r15), %xmm13
13250 movdqa SHUF_MASK(%rip), %xmm2
13251 PSHUFB_XMM %xmm2, %xmm13
13252
13253 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13254 movdqa %xmm13, HashKey(%rsp)
13255 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13256 and $-16, %r13
13257 - mov %r13, %r12
13258 + mov %r13, %r15
13259
13260 # Encrypt first few blocks
13261
13262 - and $(3<<4), %r12
13263 + and $(3<<4), %r15
13264 jz _initial_num_blocks_is_0_encrypt
13265 - cmp $(2<<4), %r12
13266 + cmp $(2<<4), %r15
13267 jb _initial_num_blocks_is_1_encrypt
13268 je _initial_num_blocks_is_2_encrypt
13269 _initial_num_blocks_is_3_encrypt:
13270 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13271 sub $16, %r11
13272 add %r13, %r11
13273 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13274 - lea SHIFT_MASK+16(%rip), %r12
13275 - sub %r13, %r12
13276 + lea SHIFT_MASK+16(%rip), %r15
13277 + sub %r13, %r15
13278 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13279 # (%r13 is the number of bytes in plaintext mod 16)
13280 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13281 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13282 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13283 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13284 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13285 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13286 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13287 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13288 movdqa SHUF_MASK(%rip), %xmm10
13289 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13290 sub $1, %r13
13291 jne _less_than_8_bytes_left_encrypt
13292 _multiple_of_16_bytes_encrypt:
13293 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13294 - shl $3, %r12
13295 - movd %r12d, %xmm15 # len(A) in %xmm15
13296 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13297 + shl $3, %r15
13298 + movd %r15d, %xmm15 # len(A) in %xmm15
13299 shl $3, %arg4 # len(C) in bits (*128)
13300 MOVQ_R64_XMM %arg4, %xmm1
13301 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13302 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13303 mov %r14, %rsp
13304 pop %r14
13305 pop %r13
13306 - pop %r12
13307 + pop %r15
13308 + pax_force_retaddr
13309 ret
13310 ENDPROC(aesni_gcm_enc)
13311
13312 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13313 pxor %xmm1, %xmm0
13314 movaps %xmm0, (TKEYP)
13315 add $0x10, TKEYP
13316 + pax_force_retaddr
13317 ret
13318 ENDPROC(_key_expansion_128)
13319 ENDPROC(_key_expansion_256a)
13320 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13321 shufps $0b01001110, %xmm2, %xmm1
13322 movaps %xmm1, 0x10(TKEYP)
13323 add $0x20, TKEYP
13324 + pax_force_retaddr
13325 ret
13326 ENDPROC(_key_expansion_192a)
13327
13328 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13329
13330 movaps %xmm0, (TKEYP)
13331 add $0x10, TKEYP
13332 + pax_force_retaddr
13333 ret
13334 ENDPROC(_key_expansion_192b)
13335
13336 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13337 pxor %xmm1, %xmm2
13338 movaps %xmm2, (TKEYP)
13339 add $0x10, TKEYP
13340 + pax_force_retaddr
13341 ret
13342 ENDPROC(_key_expansion_256b)
13343
13344 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13345 #ifndef __x86_64__
13346 popl KEYP
13347 #endif
13348 + pax_force_retaddr
13349 ret
13350 ENDPROC(aesni_set_key)
13351
13352 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13353 popl KLEN
13354 popl KEYP
13355 #endif
13356 + pax_force_retaddr
13357 ret
13358 ENDPROC(aesni_enc)
13359
13360 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13361 AESENC KEY STATE
13362 movaps 0x70(TKEYP), KEY
13363 AESENCLAST KEY STATE
13364 + pax_force_retaddr
13365 ret
13366 ENDPROC(_aesni_enc1)
13367
13368 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13369 AESENCLAST KEY STATE2
13370 AESENCLAST KEY STATE3
13371 AESENCLAST KEY STATE4
13372 + pax_force_retaddr
13373 ret
13374 ENDPROC(_aesni_enc4)
13375
13376 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13377 popl KLEN
13378 popl KEYP
13379 #endif
13380 + pax_force_retaddr
13381 ret
13382 ENDPROC(aesni_dec)
13383
13384 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13385 AESDEC KEY STATE
13386 movaps 0x70(TKEYP), KEY
13387 AESDECLAST KEY STATE
13388 + pax_force_retaddr
13389 ret
13390 ENDPROC(_aesni_dec1)
13391
13392 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13393 AESDECLAST KEY STATE2
13394 AESDECLAST KEY STATE3
13395 AESDECLAST KEY STATE4
13396 + pax_force_retaddr
13397 ret
13398 ENDPROC(_aesni_dec4)
13399
13400 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13401 popl KEYP
13402 popl LEN
13403 #endif
13404 + pax_force_retaddr
13405 ret
13406 ENDPROC(aesni_ecb_enc)
13407
13408 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13409 popl KEYP
13410 popl LEN
13411 #endif
13412 + pax_force_retaddr
13413 ret
13414 ENDPROC(aesni_ecb_dec)
13415
13416 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13417 popl LEN
13418 popl IVP
13419 #endif
13420 + pax_force_retaddr
13421 ret
13422 ENDPROC(aesni_cbc_enc)
13423
13424 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13425 popl LEN
13426 popl IVP
13427 #endif
13428 + pax_force_retaddr
13429 ret
13430 ENDPROC(aesni_cbc_dec)
13431
13432 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13433 mov $1, TCTR_LOW
13434 MOVQ_R64_XMM TCTR_LOW INC
13435 MOVQ_R64_XMM CTR TCTR_LOW
13436 + pax_force_retaddr
13437 ret
13438 ENDPROC(_aesni_inc_init)
13439
13440 @@ -2579,6 +2598,7 @@ _aesni_inc:
13441 .Linc_low:
13442 movaps CTR, IV
13443 PSHUFB_XMM BSWAP_MASK IV
13444 + pax_force_retaddr
13445 ret
13446 ENDPROC(_aesni_inc)
13447
13448 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13449 .Lctr_enc_ret:
13450 movups IV, (IVP)
13451 .Lctr_enc_just_ret:
13452 + pax_force_retaddr
13453 ret
13454 ENDPROC(aesni_ctr_enc)
13455
13456 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13457 pxor INC, STATE4
13458 movdqu STATE4, 0x70(OUTP)
13459
13460 + pax_force_retaddr
13461 ret
13462 ENDPROC(aesni_xts_crypt8)
13463
13464 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13465 index 246c670..466e2d6 100644
13466 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13467 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13468 @@ -21,6 +21,7 @@
13469 */
13470
13471 #include <linux/linkage.h>
13472 +#include <asm/alternative-asm.h>
13473
13474 .file "blowfish-x86_64-asm.S"
13475 .text
13476 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13477 jnz .L__enc_xor;
13478
13479 write_block();
13480 + pax_force_retaddr
13481 ret;
13482 .L__enc_xor:
13483 xor_block();
13484 + pax_force_retaddr
13485 ret;
13486 ENDPROC(__blowfish_enc_blk)
13487
13488 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13489
13490 movq %r11, %rbp;
13491
13492 + pax_force_retaddr
13493 ret;
13494 ENDPROC(blowfish_dec_blk)
13495
13496 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13497
13498 popq %rbx;
13499 popq %rbp;
13500 + pax_force_retaddr
13501 ret;
13502
13503 .L__enc_xor4:
13504 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13505
13506 popq %rbx;
13507 popq %rbp;
13508 + pax_force_retaddr
13509 ret;
13510 ENDPROC(__blowfish_enc_blk_4way)
13511
13512 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13513 popq %rbx;
13514 popq %rbp;
13515
13516 + pax_force_retaddr
13517 ret;
13518 ENDPROC(blowfish_dec_blk_4way)
13519 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13520 index ce71f92..1dce7ec 100644
13521 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13522 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13523 @@ -16,6 +16,7 @@
13524 */
13525
13526 #include <linux/linkage.h>
13527 +#include <asm/alternative-asm.h>
13528
13529 #define CAMELLIA_TABLE_BYTE_LEN 272
13530
13531 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13532 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13533 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13534 %rcx, (%r9));
13535 + pax_force_retaddr
13536 ret;
13537 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13538
13539 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13540 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13541 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13542 %rax, (%r9));
13543 + pax_force_retaddr
13544 ret;
13545 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13546
13547 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13548 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13549 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13550
13551 + pax_force_retaddr
13552 ret;
13553
13554 .align 8
13555 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13556 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13557 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13558
13559 + pax_force_retaddr
13560 ret;
13561
13562 .align 8
13563 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13564 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13565 %xmm8, %rsi);
13566
13567 + pax_force_retaddr
13568 ret;
13569 ENDPROC(camellia_ecb_enc_16way)
13570
13571 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13572 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13573 %xmm8, %rsi);
13574
13575 + pax_force_retaddr
13576 ret;
13577 ENDPROC(camellia_ecb_dec_16way)
13578
13579 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13580 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13581 %xmm8, %rsi);
13582
13583 + pax_force_retaddr
13584 ret;
13585 ENDPROC(camellia_cbc_dec_16way)
13586
13587 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13588 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13589 %xmm8, %rsi);
13590
13591 + pax_force_retaddr
13592 ret;
13593 ENDPROC(camellia_ctr_16way)
13594
13595 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13596 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13597 %xmm8, %rsi);
13598
13599 + pax_force_retaddr
13600 ret;
13601 ENDPROC(camellia_xts_crypt_16way)
13602
13603 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13604 index 0e0b886..5a3123c 100644
13605 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13606 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13607 @@ -11,6 +11,7 @@
13608 */
13609
13610 #include <linux/linkage.h>
13611 +#include <asm/alternative-asm.h>
13612
13613 #define CAMELLIA_TABLE_BYTE_LEN 272
13614
13615 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13616 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13617 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13618 %rcx, (%r9));
13619 + pax_force_retaddr
13620 ret;
13621 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13622
13623 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13624 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13625 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13626 %rax, (%r9));
13627 + pax_force_retaddr
13628 ret;
13629 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13630
13631 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13632 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13633 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13634
13635 + pax_force_retaddr
13636 ret;
13637
13638 .align 8
13639 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13640 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13641 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13642
13643 + pax_force_retaddr
13644 ret;
13645
13646 .align 8
13647 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13648
13649 vzeroupper;
13650
13651 + pax_force_retaddr
13652 ret;
13653 ENDPROC(camellia_ecb_enc_32way)
13654
13655 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13656
13657 vzeroupper;
13658
13659 + pax_force_retaddr
13660 ret;
13661 ENDPROC(camellia_ecb_dec_32way)
13662
13663 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13664
13665 vzeroupper;
13666
13667 + pax_force_retaddr
13668 ret;
13669 ENDPROC(camellia_cbc_dec_32way)
13670
13671 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13672
13673 vzeroupper;
13674
13675 + pax_force_retaddr
13676 ret;
13677 ENDPROC(camellia_ctr_32way)
13678
13679 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13680
13681 vzeroupper;
13682
13683 + pax_force_retaddr
13684 ret;
13685 ENDPROC(camellia_xts_crypt_32way)
13686
13687 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13688 index 310319c..db3d7b5 100644
13689 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13690 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13691 @@ -21,6 +21,7 @@
13692 */
13693
13694 #include <linux/linkage.h>
13695 +#include <asm/alternative-asm.h>
13696
13697 .file "camellia-x86_64-asm_64.S"
13698 .text
13699 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13700 enc_outunpack(mov, RT1);
13701
13702 movq RRBP, %rbp;
13703 + pax_force_retaddr
13704 ret;
13705
13706 .L__enc_xor:
13707 enc_outunpack(xor, RT1);
13708
13709 movq RRBP, %rbp;
13710 + pax_force_retaddr
13711 ret;
13712 ENDPROC(__camellia_enc_blk)
13713
13714 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13715 dec_outunpack();
13716
13717 movq RRBP, %rbp;
13718 + pax_force_retaddr
13719 ret;
13720 ENDPROC(camellia_dec_blk)
13721
13722 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13723
13724 movq RRBP, %rbp;
13725 popq %rbx;
13726 + pax_force_retaddr
13727 ret;
13728
13729 .L__enc2_xor:
13730 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13731
13732 movq RRBP, %rbp;
13733 popq %rbx;
13734 + pax_force_retaddr
13735 ret;
13736 ENDPROC(__camellia_enc_blk_2way)
13737
13738 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13739
13740 movq RRBP, %rbp;
13741 movq RXOR, %rbx;
13742 + pax_force_retaddr
13743 ret;
13744 ENDPROC(camellia_dec_blk_2way)
13745 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13746 index c35fd5d..2d8c7db 100644
13747 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13748 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13749 @@ -24,6 +24,7 @@
13750 */
13751
13752 #include <linux/linkage.h>
13753 +#include <asm/alternative-asm.h>
13754
13755 .file "cast5-avx-x86_64-asm_64.S"
13756
13757 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13758 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13759 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13760
13761 + pax_force_retaddr
13762 ret;
13763 ENDPROC(__cast5_enc_blk16)
13764
13765 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13766 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13767 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13768
13769 + pax_force_retaddr
13770 ret;
13771
13772 .L__skip_dec:
13773 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13774 vmovdqu RR4, (6*4*4)(%r11);
13775 vmovdqu RL4, (7*4*4)(%r11);
13776
13777 + pax_force_retaddr
13778 ret;
13779 ENDPROC(cast5_ecb_enc_16way)
13780
13781 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13782 vmovdqu RR4, (6*4*4)(%r11);
13783 vmovdqu RL4, (7*4*4)(%r11);
13784
13785 + pax_force_retaddr
13786 ret;
13787 ENDPROC(cast5_ecb_dec_16way)
13788
13789 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13790 * %rdx: src
13791 */
13792
13793 - pushq %r12;
13794 + pushq %r14;
13795
13796 movq %rsi, %r11;
13797 - movq %rdx, %r12;
13798 + movq %rdx, %r14;
13799
13800 vmovdqu (0*16)(%rdx), RL1;
13801 vmovdqu (1*16)(%rdx), RR1;
13802 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13803 call __cast5_dec_blk16;
13804
13805 /* xor with src */
13806 - vmovq (%r12), RX;
13807 + vmovq (%r14), RX;
13808 vpshufd $0x4f, RX, RX;
13809 vpxor RX, RR1, RR1;
13810 - vpxor 0*16+8(%r12), RL1, RL1;
13811 - vpxor 1*16+8(%r12), RR2, RR2;
13812 - vpxor 2*16+8(%r12), RL2, RL2;
13813 - vpxor 3*16+8(%r12), RR3, RR3;
13814 - vpxor 4*16+8(%r12), RL3, RL3;
13815 - vpxor 5*16+8(%r12), RR4, RR4;
13816 - vpxor 6*16+8(%r12), RL4, RL4;
13817 + vpxor 0*16+8(%r14), RL1, RL1;
13818 + vpxor 1*16+8(%r14), RR2, RR2;
13819 + vpxor 2*16+8(%r14), RL2, RL2;
13820 + vpxor 3*16+8(%r14), RR3, RR3;
13821 + vpxor 4*16+8(%r14), RL3, RL3;
13822 + vpxor 5*16+8(%r14), RR4, RR4;
13823 + vpxor 6*16+8(%r14), RL4, RL4;
13824
13825 vmovdqu RR1, (0*16)(%r11);
13826 vmovdqu RL1, (1*16)(%r11);
13827 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13828 vmovdqu RR4, (6*16)(%r11);
13829 vmovdqu RL4, (7*16)(%r11);
13830
13831 - popq %r12;
13832 + popq %r14;
13833
13834 + pax_force_retaddr
13835 ret;
13836 ENDPROC(cast5_cbc_dec_16way)
13837
13838 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13839 * %rcx: iv (big endian, 64bit)
13840 */
13841
13842 - pushq %r12;
13843 + pushq %r14;
13844
13845 movq %rsi, %r11;
13846 - movq %rdx, %r12;
13847 + movq %rdx, %r14;
13848
13849 vpcmpeqd RTMP, RTMP, RTMP;
13850 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13851 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13852 call __cast5_enc_blk16;
13853
13854 /* dst = src ^ iv */
13855 - vpxor (0*16)(%r12), RR1, RR1;
13856 - vpxor (1*16)(%r12), RL1, RL1;
13857 - vpxor (2*16)(%r12), RR2, RR2;
13858 - vpxor (3*16)(%r12), RL2, RL2;
13859 - vpxor (4*16)(%r12), RR3, RR3;
13860 - vpxor (5*16)(%r12), RL3, RL3;
13861 - vpxor (6*16)(%r12), RR4, RR4;
13862 - vpxor (7*16)(%r12), RL4, RL4;
13863 + vpxor (0*16)(%r14), RR1, RR1;
13864 + vpxor (1*16)(%r14), RL1, RL1;
13865 + vpxor (2*16)(%r14), RR2, RR2;
13866 + vpxor (3*16)(%r14), RL2, RL2;
13867 + vpxor (4*16)(%r14), RR3, RR3;
13868 + vpxor (5*16)(%r14), RL3, RL3;
13869 + vpxor (6*16)(%r14), RR4, RR4;
13870 + vpxor (7*16)(%r14), RL4, RL4;
13871 vmovdqu RR1, (0*16)(%r11);
13872 vmovdqu RL1, (1*16)(%r11);
13873 vmovdqu RR2, (2*16)(%r11);
13874 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13875 vmovdqu RR4, (6*16)(%r11);
13876 vmovdqu RL4, (7*16)(%r11);
13877
13878 - popq %r12;
13879 + popq %r14;
13880
13881 + pax_force_retaddr
13882 ret;
13883 ENDPROC(cast5_ctr_16way)
13884 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13885 index e3531f8..e123f35 100644
13886 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13887 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13888 @@ -24,6 +24,7 @@
13889 */
13890
13891 #include <linux/linkage.h>
13892 +#include <asm/alternative-asm.h>
13893 #include "glue_helper-asm-avx.S"
13894
13895 .file "cast6-avx-x86_64-asm_64.S"
13896 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13897 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13898 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13899
13900 + pax_force_retaddr
13901 ret;
13902 ENDPROC(__cast6_enc_blk8)
13903
13904 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13905 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13906 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13907
13908 + pax_force_retaddr
13909 ret;
13910 ENDPROC(__cast6_dec_blk8)
13911
13912 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13913
13914 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13915
13916 + pax_force_retaddr
13917 ret;
13918 ENDPROC(cast6_ecb_enc_8way)
13919
13920 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13921
13922 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13923
13924 + pax_force_retaddr
13925 ret;
13926 ENDPROC(cast6_ecb_dec_8way)
13927
13928 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13929 * %rdx: src
13930 */
13931
13932 - pushq %r12;
13933 + pushq %r14;
13934
13935 movq %rsi, %r11;
13936 - movq %rdx, %r12;
13937 + movq %rdx, %r14;
13938
13939 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13940
13941 call __cast6_dec_blk8;
13942
13943 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13944 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13945
13946 - popq %r12;
13947 + popq %r14;
13948
13949 + pax_force_retaddr
13950 ret;
13951 ENDPROC(cast6_cbc_dec_8way)
13952
13953 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13954 * %rcx: iv (little endian, 128bit)
13955 */
13956
13957 - pushq %r12;
13958 + pushq %r14;
13959
13960 movq %rsi, %r11;
13961 - movq %rdx, %r12;
13962 + movq %rdx, %r14;
13963
13964 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13965 RD2, RX, RKR, RKM);
13966
13967 call __cast6_enc_blk8;
13968
13969 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13970 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13971
13972 - popq %r12;
13973 + popq %r14;
13974
13975 + pax_force_retaddr
13976 ret;
13977 ENDPROC(cast6_ctr_8way)
13978
13979 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13980 /* dst <= regs xor IVs(in dst) */
13981 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13982
13983 + pax_force_retaddr
13984 ret;
13985 ENDPROC(cast6_xts_enc_8way)
13986
13987 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13988 /* dst <= regs xor IVs(in dst) */
13989 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13990
13991 + pax_force_retaddr
13992 ret;
13993 ENDPROC(cast6_xts_dec_8way)
13994 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13995 index dbc4339..de6e120 100644
13996 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13997 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13998 @@ -45,6 +45,7 @@
13999
14000 #include <asm/inst.h>
14001 #include <linux/linkage.h>
14002 +#include <asm/alternative-asm.h>
14003
14004 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14005
14006 @@ -312,6 +313,7 @@ do_return:
14007 popq %rsi
14008 popq %rdi
14009 popq %rbx
14010 + pax_force_retaddr
14011 ret
14012
14013 ################################################################
14014 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14015 index 185fad4..ff4cd36 100644
14016 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14017 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14018 @@ -18,6 +18,7 @@
14019
14020 #include <linux/linkage.h>
14021 #include <asm/inst.h>
14022 +#include <asm/alternative-asm.h>
14023
14024 .data
14025
14026 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14027 psrlq $1, T2
14028 pxor T2, T1
14029 pxor T1, DATA
14030 + pax_force_retaddr
14031 ret
14032 ENDPROC(__clmul_gf128mul_ble)
14033
14034 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14035 call __clmul_gf128mul_ble
14036 PSHUFB_XMM BSWAP DATA
14037 movups DATA, (%rdi)
14038 + pax_force_retaddr
14039 ret
14040 ENDPROC(clmul_ghash_mul)
14041
14042 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14043 PSHUFB_XMM BSWAP DATA
14044 movups DATA, (%rdi)
14045 .Lupdate_just_ret:
14046 + pax_force_retaddr
14047 ret
14048 ENDPROC(clmul_ghash_update)
14049 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14050 index 9279e0b..c4b3d2c 100644
14051 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14052 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14053 @@ -1,4 +1,5 @@
14054 #include <linux/linkage.h>
14055 +#include <asm/alternative-asm.h>
14056
14057 # enter salsa20_encrypt_bytes
14058 ENTRY(salsa20_encrypt_bytes)
14059 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14060 add %r11,%rsp
14061 mov %rdi,%rax
14062 mov %rsi,%rdx
14063 + pax_force_retaddr
14064 ret
14065 # bytesatleast65:
14066 ._bytesatleast65:
14067 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14068 add %r11,%rsp
14069 mov %rdi,%rax
14070 mov %rsi,%rdx
14071 + pax_force_retaddr
14072 ret
14073 ENDPROC(salsa20_keysetup)
14074
14075 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14076 add %r11,%rsp
14077 mov %rdi,%rax
14078 mov %rsi,%rdx
14079 + pax_force_retaddr
14080 ret
14081 ENDPROC(salsa20_ivsetup)
14082 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14083 index 2f202f4..d9164d6 100644
14084 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14085 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14086 @@ -24,6 +24,7 @@
14087 */
14088
14089 #include <linux/linkage.h>
14090 +#include <asm/alternative-asm.h>
14091 #include "glue_helper-asm-avx.S"
14092
14093 .file "serpent-avx-x86_64-asm_64.S"
14094 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14095 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14096 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14097
14098 + pax_force_retaddr
14099 ret;
14100 ENDPROC(__serpent_enc_blk8_avx)
14101
14102 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14103 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14104 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14105
14106 + pax_force_retaddr
14107 ret;
14108 ENDPROC(__serpent_dec_blk8_avx)
14109
14110 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14111
14112 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14113
14114 + pax_force_retaddr
14115 ret;
14116 ENDPROC(serpent_ecb_enc_8way_avx)
14117
14118 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14119
14120 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14121
14122 + pax_force_retaddr
14123 ret;
14124 ENDPROC(serpent_ecb_dec_8way_avx)
14125
14126 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14127
14128 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14129
14130 + pax_force_retaddr
14131 ret;
14132 ENDPROC(serpent_cbc_dec_8way_avx)
14133
14134 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14135
14136 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14137
14138 + pax_force_retaddr
14139 ret;
14140 ENDPROC(serpent_ctr_8way_avx)
14141
14142 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14143 /* dst <= regs xor IVs(in dst) */
14144 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14145
14146 + pax_force_retaddr
14147 ret;
14148 ENDPROC(serpent_xts_enc_8way_avx)
14149
14150 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14151 /* dst <= regs xor IVs(in dst) */
14152 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14153
14154 + pax_force_retaddr
14155 ret;
14156 ENDPROC(serpent_xts_dec_8way_avx)
14157 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14158 index b222085..abd483c 100644
14159 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
14160 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14161 @@ -15,6 +15,7 @@
14162 */
14163
14164 #include <linux/linkage.h>
14165 +#include <asm/alternative-asm.h>
14166 #include "glue_helper-asm-avx2.S"
14167
14168 .file "serpent-avx2-asm_64.S"
14169 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
14170 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14171 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14172
14173 + pax_force_retaddr
14174 ret;
14175 ENDPROC(__serpent_enc_blk16)
14176
14177 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
14178 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14179 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14180
14181 + pax_force_retaddr
14182 ret;
14183 ENDPROC(__serpent_dec_blk16)
14184
14185 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14186
14187 vzeroupper;
14188
14189 + pax_force_retaddr
14190 ret;
14191 ENDPROC(serpent_ecb_enc_16way)
14192
14193 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14194
14195 vzeroupper;
14196
14197 + pax_force_retaddr
14198 ret;
14199 ENDPROC(serpent_ecb_dec_16way)
14200
14201 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14202
14203 vzeroupper;
14204
14205 + pax_force_retaddr
14206 ret;
14207 ENDPROC(serpent_cbc_dec_16way)
14208
14209 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14210
14211 vzeroupper;
14212
14213 + pax_force_retaddr
14214 ret;
14215 ENDPROC(serpent_ctr_16way)
14216
14217 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14218
14219 vzeroupper;
14220
14221 + pax_force_retaddr
14222 ret;
14223 ENDPROC(serpent_xts_enc_16way)
14224
14225 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14226
14227 vzeroupper;
14228
14229 + pax_force_retaddr
14230 ret;
14231 ENDPROC(serpent_xts_dec_16way)
14232 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14233 index acc066c..1559cc4 100644
14234 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14235 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14236 @@ -25,6 +25,7 @@
14237 */
14238
14239 #include <linux/linkage.h>
14240 +#include <asm/alternative-asm.h>
14241
14242 .file "serpent-sse2-x86_64-asm_64.S"
14243 .text
14244 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14245 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14246 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14247
14248 + pax_force_retaddr
14249 ret;
14250
14251 .L__enc_xor8:
14252 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14253 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14254
14255 + pax_force_retaddr
14256 ret;
14257 ENDPROC(__serpent_enc_blk_8way)
14258
14259 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14260 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14261 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14262
14263 + pax_force_retaddr
14264 ret;
14265 ENDPROC(serpent_dec_blk_8way)
14266 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14267 index a410950..9dfe7ad 100644
14268 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14269 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14270 @@ -29,6 +29,7 @@
14271 */
14272
14273 #include <linux/linkage.h>
14274 +#include <asm/alternative-asm.h>
14275
14276 #define CTX %rdi // arg1
14277 #define BUF %rsi // arg2
14278 @@ -75,9 +76,9 @@
14279
14280 push %rbx
14281 push %rbp
14282 - push %r12
14283 + push %r14
14284
14285 - mov %rsp, %r12
14286 + mov %rsp, %r14
14287 sub $64, %rsp # allocate workspace
14288 and $~15, %rsp # align stack
14289
14290 @@ -99,11 +100,12 @@
14291 xor %rax, %rax
14292 rep stosq
14293
14294 - mov %r12, %rsp # deallocate workspace
14295 + mov %r14, %rsp # deallocate workspace
14296
14297 - pop %r12
14298 + pop %r14
14299 pop %rbp
14300 pop %rbx
14301 + pax_force_retaddr
14302 ret
14303
14304 ENDPROC(\name)
14305 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14306 index 642f156..51a513c 100644
14307 --- a/arch/x86/crypto/sha256-avx-asm.S
14308 +++ b/arch/x86/crypto/sha256-avx-asm.S
14309 @@ -49,6 +49,7 @@
14310
14311 #ifdef CONFIG_AS_AVX
14312 #include <linux/linkage.h>
14313 +#include <asm/alternative-asm.h>
14314
14315 ## assume buffers not aligned
14316 #define VMOVDQ vmovdqu
14317 @@ -460,6 +461,7 @@ done_hash:
14318 popq %r13
14319 popq %rbp
14320 popq %rbx
14321 + pax_force_retaddr
14322 ret
14323 ENDPROC(sha256_transform_avx)
14324
14325 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14326 index 9e86944..3795e6a 100644
14327 --- a/arch/x86/crypto/sha256-avx2-asm.S
14328 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14329 @@ -50,6 +50,7 @@
14330
14331 #ifdef CONFIG_AS_AVX2
14332 #include <linux/linkage.h>
14333 +#include <asm/alternative-asm.h>
14334
14335 ## assume buffers not aligned
14336 #define VMOVDQ vmovdqu
14337 @@ -720,6 +721,7 @@ done_hash:
14338 popq %r12
14339 popq %rbp
14340 popq %rbx
14341 + pax_force_retaddr
14342 ret
14343 ENDPROC(sha256_transform_rorx)
14344
14345 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14346 index f833b74..8c62a9e 100644
14347 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14348 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14349 @@ -47,6 +47,7 @@
14350 ########################################################################
14351
14352 #include <linux/linkage.h>
14353 +#include <asm/alternative-asm.h>
14354
14355 ## assume buffers not aligned
14356 #define MOVDQ movdqu
14357 @@ -471,6 +472,7 @@ done_hash:
14358 popq %rbp
14359 popq %rbx
14360
14361 + pax_force_retaddr
14362 ret
14363 ENDPROC(sha256_transform_ssse3)
14364
14365 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14366 index 974dde9..a823ff9 100644
14367 --- a/arch/x86/crypto/sha512-avx-asm.S
14368 +++ b/arch/x86/crypto/sha512-avx-asm.S
14369 @@ -49,6 +49,7 @@
14370
14371 #ifdef CONFIG_AS_AVX
14372 #include <linux/linkage.h>
14373 +#include <asm/alternative-asm.h>
14374
14375 .text
14376
14377 @@ -364,6 +365,7 @@ updateblock:
14378 mov frame_RSPSAVE(%rsp), %rsp
14379
14380 nowork:
14381 + pax_force_retaddr
14382 ret
14383 ENDPROC(sha512_transform_avx)
14384
14385 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14386 index 568b961..ed20c37 100644
14387 --- a/arch/x86/crypto/sha512-avx2-asm.S
14388 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14389 @@ -51,6 +51,7 @@
14390
14391 #ifdef CONFIG_AS_AVX2
14392 #include <linux/linkage.h>
14393 +#include <asm/alternative-asm.h>
14394
14395 .text
14396
14397 @@ -678,6 +679,7 @@ done_hash:
14398
14399 # Restore Stack Pointer
14400 mov frame_RSPSAVE(%rsp), %rsp
14401 + pax_force_retaddr
14402 ret
14403 ENDPROC(sha512_transform_rorx)
14404
14405 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14406 index fb56855..6edd768 100644
14407 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14408 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14409 @@ -48,6 +48,7 @@
14410 ########################################################################
14411
14412 #include <linux/linkage.h>
14413 +#include <asm/alternative-asm.h>
14414
14415 .text
14416
14417 @@ -363,6 +364,7 @@ updateblock:
14418 mov frame_RSPSAVE(%rsp), %rsp
14419
14420 nowork:
14421 + pax_force_retaddr
14422 ret
14423 ENDPROC(sha512_transform_ssse3)
14424
14425 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14426 index 0505813..b067311 100644
14427 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14428 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14429 @@ -24,6 +24,7 @@
14430 */
14431
14432 #include <linux/linkage.h>
14433 +#include <asm/alternative-asm.h>
14434 #include "glue_helper-asm-avx.S"
14435
14436 .file "twofish-avx-x86_64-asm_64.S"
14437 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14438 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14439 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14440
14441 + pax_force_retaddr
14442 ret;
14443 ENDPROC(__twofish_enc_blk8)
14444
14445 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14446 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14447 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14448
14449 + pax_force_retaddr
14450 ret;
14451 ENDPROC(__twofish_dec_blk8)
14452
14453 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14454
14455 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14456
14457 + pax_force_retaddr
14458 ret;
14459 ENDPROC(twofish_ecb_enc_8way)
14460
14461 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14462
14463 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14464
14465 + pax_force_retaddr
14466 ret;
14467 ENDPROC(twofish_ecb_dec_8way)
14468
14469 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14470 * %rdx: src
14471 */
14472
14473 - pushq %r12;
14474 + pushq %r14;
14475
14476 movq %rsi, %r11;
14477 - movq %rdx, %r12;
14478 + movq %rdx, %r14;
14479
14480 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14481
14482 call __twofish_dec_blk8;
14483
14484 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14485 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14486
14487 - popq %r12;
14488 + popq %r14;
14489
14490 + pax_force_retaddr
14491 ret;
14492 ENDPROC(twofish_cbc_dec_8way)
14493
14494 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14495 * %rcx: iv (little endian, 128bit)
14496 */
14497
14498 - pushq %r12;
14499 + pushq %r14;
14500
14501 movq %rsi, %r11;
14502 - movq %rdx, %r12;
14503 + movq %rdx, %r14;
14504
14505 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14506 RD2, RX0, RX1, RY0);
14507
14508 call __twofish_enc_blk8;
14509
14510 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14511 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14512
14513 - popq %r12;
14514 + popq %r14;
14515
14516 + pax_force_retaddr
14517 ret;
14518 ENDPROC(twofish_ctr_8way)
14519
14520 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14521 /* dst <= regs xor IVs(in dst) */
14522 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14523
14524 + pax_force_retaddr
14525 ret;
14526 ENDPROC(twofish_xts_enc_8way)
14527
14528 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14529 /* dst <= regs xor IVs(in dst) */
14530 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14531
14532 + pax_force_retaddr
14533 ret;
14534 ENDPROC(twofish_xts_dec_8way)
14535 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14536 index 1c3b7ce..02f578d 100644
14537 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14538 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14539 @@ -21,6 +21,7 @@
14540 */
14541
14542 #include <linux/linkage.h>
14543 +#include <asm/alternative-asm.h>
14544
14545 .file "twofish-x86_64-asm-3way.S"
14546 .text
14547 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14548 popq %r13;
14549 popq %r14;
14550 popq %r15;
14551 + pax_force_retaddr
14552 ret;
14553
14554 .L__enc_xor3:
14555 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14556 popq %r13;
14557 popq %r14;
14558 popq %r15;
14559 + pax_force_retaddr
14560 ret;
14561 ENDPROC(__twofish_enc_blk_3way)
14562
14563 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14564 popq %r13;
14565 popq %r14;
14566 popq %r15;
14567 + pax_force_retaddr
14568 ret;
14569 ENDPROC(twofish_dec_blk_3way)
14570 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14571 index a039d21..524b8b2 100644
14572 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14573 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14574 @@ -22,6 +22,7 @@
14575
14576 #include <linux/linkage.h>
14577 #include <asm/asm-offsets.h>
14578 +#include <asm/alternative-asm.h>
14579
14580 #define a_offset 0
14581 #define b_offset 4
14582 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14583
14584 popq R1
14585 movq $1,%rax
14586 + pax_force_retaddr
14587 ret
14588 ENDPROC(twofish_enc_blk)
14589
14590 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14591
14592 popq R1
14593 movq $1,%rax
14594 + pax_force_retaddr
14595 ret
14596 ENDPROC(twofish_dec_blk)
14597 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14598 index d21ff89..6da8e6e 100644
14599 --- a/arch/x86/ia32/ia32_aout.c
14600 +++ b/arch/x86/ia32/ia32_aout.c
14601 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14602 unsigned long dump_start, dump_size;
14603 struct user32 dump;
14604
14605 + memset(&dump, 0, sizeof(dump));
14606 +
14607 fs = get_fs();
14608 set_fs(KERNEL_DS);
14609 has_dumped = 1;
14610 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14611 index 2206757..85cbcfa 100644
14612 --- a/arch/x86/ia32/ia32_signal.c
14613 +++ b/arch/x86/ia32/ia32_signal.c
14614 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14615 if (__get_user(set.sig[0], &frame->sc.oldmask)
14616 || (_COMPAT_NSIG_WORDS > 1
14617 && __copy_from_user((((char *) &set.sig) + 4),
14618 - &frame->extramask,
14619 + frame->extramask,
14620 sizeof(frame->extramask))))
14621 goto badframe;
14622
14623 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14624 sp -= frame_size;
14625 /* Align the stack pointer according to the i386 ABI,
14626 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14627 - sp = ((sp + 4) & -16ul) - 4;
14628 + sp = ((sp - 12) & -16ul) - 4;
14629 return (void __user *) sp;
14630 }
14631
14632 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14633 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14634 sigreturn);
14635 else
14636 - restorer = &frame->retcode;
14637 + restorer = frame->retcode;
14638 }
14639
14640 put_user_try {
14641 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14642 * These are actually not used anymore, but left because some
14643 * gdb versions depend on them as a marker.
14644 */
14645 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14646 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14647 } put_user_catch(err);
14648
14649 if (err)
14650 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14651 0xb8,
14652 __NR_ia32_rt_sigreturn,
14653 0x80cd,
14654 - 0,
14655 + 0
14656 };
14657
14658 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14659 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14660
14661 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14662 restorer = ksig->ka.sa.sa_restorer;
14663 + else if (current->mm->context.vdso)
14664 + /* Return stub is in 32bit vsyscall page */
14665 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14666 else
14667 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14668 - rt_sigreturn);
14669 + restorer = frame->retcode;
14670 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14671
14672 /*
14673 * Not actually used anymore, but left because some gdb
14674 * versions need it.
14675 */
14676 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14677 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14678 } put_user_catch(err);
14679
14680 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14681 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14682 index 4299eb0..c0687a7 100644
14683 --- a/arch/x86/ia32/ia32entry.S
14684 +++ b/arch/x86/ia32/ia32entry.S
14685 @@ -15,8 +15,10 @@
14686 #include <asm/irqflags.h>
14687 #include <asm/asm.h>
14688 #include <asm/smap.h>
14689 +#include <asm/pgtable.h>
14690 #include <linux/linkage.h>
14691 #include <linux/err.h>
14692 +#include <asm/alternative-asm.h>
14693
14694 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14695 #include <linux/elf-em.h>
14696 @@ -62,12 +64,12 @@
14697 */
14698 .macro LOAD_ARGS32 offset, _r9=0
14699 .if \_r9
14700 - movl \offset+16(%rsp),%r9d
14701 + movl \offset+R9(%rsp),%r9d
14702 .endif
14703 - movl \offset+40(%rsp),%ecx
14704 - movl \offset+48(%rsp),%edx
14705 - movl \offset+56(%rsp),%esi
14706 - movl \offset+64(%rsp),%edi
14707 + movl \offset+RCX(%rsp),%ecx
14708 + movl \offset+RDX(%rsp),%edx
14709 + movl \offset+RSI(%rsp),%esi
14710 + movl \offset+RDI(%rsp),%edi
14711 movl %eax,%eax /* zero extension */
14712 .endm
14713
14714 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14715 ENDPROC(native_irq_enable_sysexit)
14716 #endif
14717
14718 + .macro pax_enter_kernel_user
14719 + pax_set_fptr_mask
14720 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14721 + call pax_enter_kernel_user
14722 +#endif
14723 + .endm
14724 +
14725 + .macro pax_exit_kernel_user
14726 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14727 + call pax_exit_kernel_user
14728 +#endif
14729 +#ifdef CONFIG_PAX_RANDKSTACK
14730 + pushq %rax
14731 + pushq %r11
14732 + call pax_randomize_kstack
14733 + popq %r11
14734 + popq %rax
14735 +#endif
14736 + .endm
14737 +
14738 + .macro pax_erase_kstack
14739 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14740 + call pax_erase_kstack
14741 +#endif
14742 + .endm
14743 +
14744 /*
14745 * 32bit SYSENTER instruction entry.
14746 *
14747 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14748 CFI_REGISTER rsp,rbp
14749 SWAPGS_UNSAFE_STACK
14750 movq PER_CPU_VAR(kernel_stack), %rsp
14751 - addq $(KERNEL_STACK_OFFSET),%rsp
14752 - /*
14753 - * No need to follow this irqs on/off section: the syscall
14754 - * disabled irqs, here we enable it straight after entry:
14755 - */
14756 - ENABLE_INTERRUPTS(CLBR_NONE)
14757 movl %ebp,%ebp /* zero extension */
14758 pushq_cfi $__USER32_DS
14759 /*CFI_REL_OFFSET ss,0*/
14760 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14761 CFI_REL_OFFSET rsp,0
14762 pushfq_cfi
14763 /*CFI_REL_OFFSET rflags,0*/
14764 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14765 - CFI_REGISTER rip,r10
14766 + orl $X86_EFLAGS_IF,(%rsp)
14767 + GET_THREAD_INFO(%r11)
14768 + movl TI_sysenter_return(%r11), %r11d
14769 + CFI_REGISTER rip,r11
14770 pushq_cfi $__USER32_CS
14771 /*CFI_REL_OFFSET cs,0*/
14772 movl %eax, %eax
14773 - pushq_cfi %r10
14774 + pushq_cfi %r11
14775 CFI_REL_OFFSET rip,0
14776 pushq_cfi %rax
14777 cld
14778 SAVE_ARGS 0,1,0
14779 + pax_enter_kernel_user
14780 +
14781 +#ifdef CONFIG_PAX_RANDKSTACK
14782 + pax_erase_kstack
14783 +#endif
14784 +
14785 + /*
14786 + * No need to follow this irqs on/off section: the syscall
14787 + * disabled irqs, here we enable it straight after entry:
14788 + */
14789 + ENABLE_INTERRUPTS(CLBR_NONE)
14790 /* no need to do an access_ok check here because rbp has been
14791 32bit zero extended */
14792 +
14793 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14794 + addq pax_user_shadow_base,%rbp
14795 + ASM_PAX_OPEN_USERLAND
14796 +#endif
14797 +
14798 ASM_STAC
14799 1: movl (%rbp),%ebp
14800 _ASM_EXTABLE(1b,ia32_badarg)
14801 ASM_CLAC
14802 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14803 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14804 +
14805 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14806 + ASM_PAX_CLOSE_USERLAND
14807 +#endif
14808 +
14809 + GET_THREAD_INFO(%r11)
14810 + orl $TS_COMPAT,TI_status(%r11)
14811 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14812 CFI_REMEMBER_STATE
14813 jnz sysenter_tracesys
14814 cmpq $(IA32_NR_syscalls-1),%rax
14815 @@ -162,15 +209,18 @@ sysenter_do_call:
14816 sysenter_dispatch:
14817 call *ia32_sys_call_table(,%rax,8)
14818 movq %rax,RAX-ARGOFFSET(%rsp)
14819 + GET_THREAD_INFO(%r11)
14820 DISABLE_INTERRUPTS(CLBR_NONE)
14821 TRACE_IRQS_OFF
14822 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14823 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14824 jnz sysexit_audit
14825 sysexit_from_sys_call:
14826 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14827 + pax_exit_kernel_user
14828 + pax_erase_kstack
14829 + andl $~TS_COMPAT,TI_status(%r11)
14830 /* clear IF, that popfq doesn't enable interrupts early */
14831 - andl $~0x200,EFLAGS-R11(%rsp)
14832 - movl RIP-R11(%rsp),%edx /* User %eip */
14833 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14834 + movl RIP(%rsp),%edx /* User %eip */
14835 CFI_REGISTER rip,rdx
14836 RESTORE_ARGS 0,24,0,0,0,0
14837 xorq %r8,%r8
14838 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
14839 movl %eax,%esi /* 2nd arg: syscall number */
14840 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14841 call __audit_syscall_entry
14842 +
14843 + pax_erase_kstack
14844 +
14845 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14846 cmpq $(IA32_NR_syscalls-1),%rax
14847 ja ia32_badsys
14848 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14849 .endm
14850
14851 .macro auditsys_exit exit
14852 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14853 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14854 jnz ia32_ret_from_sys_call
14855 TRACE_IRQS_ON
14856 ENABLE_INTERRUPTS(CLBR_NONE)
14857 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14858 1: setbe %al /* 1 if error, 0 if not */
14859 movzbl %al,%edi /* zero-extend that into %edi */
14860 call __audit_syscall_exit
14861 + GET_THREAD_INFO(%r11)
14862 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14863 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14864 DISABLE_INTERRUPTS(CLBR_NONE)
14865 TRACE_IRQS_OFF
14866 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14867 + testl %edi,TI_flags(%r11)
14868 jz \exit
14869 CLEAR_RREGS -ARGOFFSET
14870 jmp int_with_check
14871 @@ -237,7 +291,7 @@ sysexit_audit:
14872
14873 sysenter_tracesys:
14874 #ifdef CONFIG_AUDITSYSCALL
14875 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14876 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14877 jz sysenter_auditsys
14878 #endif
14879 SAVE_REST
14880 @@ -249,6 +303,9 @@ sysenter_tracesys:
14881 RESTORE_REST
14882 cmpq $(IA32_NR_syscalls-1),%rax
14883 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14884 +
14885 + pax_erase_kstack
14886 +
14887 jmp sysenter_do_call
14888 CFI_ENDPROC
14889 ENDPROC(ia32_sysenter_target)
14890 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14891 ENTRY(ia32_cstar_target)
14892 CFI_STARTPROC32 simple
14893 CFI_SIGNAL_FRAME
14894 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14895 + CFI_DEF_CFA rsp,0
14896 CFI_REGISTER rip,rcx
14897 /*CFI_REGISTER rflags,r11*/
14898 SWAPGS_UNSAFE_STACK
14899 movl %esp,%r8d
14900 CFI_REGISTER rsp,r8
14901 movq PER_CPU_VAR(kernel_stack),%rsp
14902 + SAVE_ARGS 8*6,0,0
14903 + pax_enter_kernel_user
14904 +
14905 +#ifdef CONFIG_PAX_RANDKSTACK
14906 + pax_erase_kstack
14907 +#endif
14908 +
14909 /*
14910 * No need to follow this irqs on/off section: the syscall
14911 * disabled irqs and here we enable it straight after entry:
14912 */
14913 ENABLE_INTERRUPTS(CLBR_NONE)
14914 - SAVE_ARGS 8,0,0
14915 movl %eax,%eax /* zero extension */
14916 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14917 movq %rcx,RIP-ARGOFFSET(%rsp)
14918 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14919 /* no need to do an access_ok check here because r8 has been
14920 32bit zero extended */
14921 /* hardware stack frame is complete now */
14922 +
14923 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14924 + ASM_PAX_OPEN_USERLAND
14925 + movq pax_user_shadow_base,%r8
14926 + addq RSP-ARGOFFSET(%rsp),%r8
14927 +#endif
14928 +
14929 ASM_STAC
14930 1: movl (%r8),%r9d
14931 _ASM_EXTABLE(1b,ia32_badarg)
14932 ASM_CLAC
14933 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14934 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14935 +
14936 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14937 + ASM_PAX_CLOSE_USERLAND
14938 +#endif
14939 +
14940 + GET_THREAD_INFO(%r11)
14941 + orl $TS_COMPAT,TI_status(%r11)
14942 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14943 CFI_REMEMBER_STATE
14944 jnz cstar_tracesys
14945 cmpq $IA32_NR_syscalls-1,%rax
14946 @@ -319,13 +395,16 @@ cstar_do_call:
14947 cstar_dispatch:
14948 call *ia32_sys_call_table(,%rax,8)
14949 movq %rax,RAX-ARGOFFSET(%rsp)
14950 + GET_THREAD_INFO(%r11)
14951 DISABLE_INTERRUPTS(CLBR_NONE)
14952 TRACE_IRQS_OFF
14953 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14954 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14955 jnz sysretl_audit
14956 sysretl_from_sys_call:
14957 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14958 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14959 + pax_exit_kernel_user
14960 + pax_erase_kstack
14961 + andl $~TS_COMPAT,TI_status(%r11)
14962 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14963 movl RIP-ARGOFFSET(%rsp),%ecx
14964 CFI_REGISTER rip,rcx
14965 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14966 @@ -352,7 +431,7 @@ sysretl_audit:
14967
14968 cstar_tracesys:
14969 #ifdef CONFIG_AUDITSYSCALL
14970 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14971 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14972 jz cstar_auditsys
14973 #endif
14974 xchgl %r9d,%ebp
14975 @@ -366,11 +445,19 @@ cstar_tracesys:
14976 xchgl %ebp,%r9d
14977 cmpq $(IA32_NR_syscalls-1),%rax
14978 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14979 +
14980 + pax_erase_kstack
14981 +
14982 jmp cstar_do_call
14983 END(ia32_cstar_target)
14984
14985 ia32_badarg:
14986 ASM_CLAC
14987 +
14988 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14989 + ASM_PAX_CLOSE_USERLAND
14990 +#endif
14991 +
14992 movq $-EFAULT,%rax
14993 jmp ia32_sysret
14994 CFI_ENDPROC
14995 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14996 CFI_REL_OFFSET rip,RIP-RIP
14997 PARAVIRT_ADJUST_EXCEPTION_FRAME
14998 SWAPGS
14999 - /*
15000 - * No need to follow this irqs on/off section: the syscall
15001 - * disabled irqs and here we enable it straight after entry:
15002 - */
15003 - ENABLE_INTERRUPTS(CLBR_NONE)
15004 movl %eax,%eax
15005 pushq_cfi %rax
15006 cld
15007 /* note the registers are not zero extended to the sf.
15008 this could be a problem. */
15009 SAVE_ARGS 0,1,0
15010 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15011 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15012 + pax_enter_kernel_user
15013 +
15014 +#ifdef CONFIG_PAX_RANDKSTACK
15015 + pax_erase_kstack
15016 +#endif
15017 +
15018 + /*
15019 + * No need to follow this irqs on/off section: the syscall
15020 + * disabled irqs and here we enable it straight after entry:
15021 + */
15022 + ENABLE_INTERRUPTS(CLBR_NONE)
15023 + GET_THREAD_INFO(%r11)
15024 + orl $TS_COMPAT,TI_status(%r11)
15025 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15026 jnz ia32_tracesys
15027 cmpq $(IA32_NR_syscalls-1),%rax
15028 ja ia32_badsys
15029 @@ -442,6 +536,9 @@ ia32_tracesys:
15030 RESTORE_REST
15031 cmpq $(IA32_NR_syscalls-1),%rax
15032 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15033 +
15034 + pax_erase_kstack
15035 +
15036 jmp ia32_do_call
15037 END(ia32_syscall)
15038
15039 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15040 index 8e0ceec..af13504 100644
15041 --- a/arch/x86/ia32/sys_ia32.c
15042 +++ b/arch/x86/ia32/sys_ia32.c
15043 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15044 */
15045 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15046 {
15047 - typeof(ubuf->st_uid) uid = 0;
15048 - typeof(ubuf->st_gid) gid = 0;
15049 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
15050 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
15051 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15052 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15053 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15054 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15055 index 372231c..51b537d 100644
15056 --- a/arch/x86/include/asm/alternative-asm.h
15057 +++ b/arch/x86/include/asm/alternative-asm.h
15058 @@ -18,6 +18,45 @@
15059 .endm
15060 #endif
15061
15062 +#ifdef KERNEXEC_PLUGIN
15063 + .macro pax_force_retaddr_bts rip=0
15064 + btsq $63,\rip(%rsp)
15065 + .endm
15066 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15067 + .macro pax_force_retaddr rip=0, reload=0
15068 + btsq $63,\rip(%rsp)
15069 + .endm
15070 + .macro pax_force_fptr ptr
15071 + btsq $63,\ptr
15072 + .endm
15073 + .macro pax_set_fptr_mask
15074 + .endm
15075 +#endif
15076 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15077 + .macro pax_force_retaddr rip=0, reload=0
15078 + .if \reload
15079 + pax_set_fptr_mask
15080 + .endif
15081 + orq %r12,\rip(%rsp)
15082 + .endm
15083 + .macro pax_force_fptr ptr
15084 + orq %r12,\ptr
15085 + .endm
15086 + .macro pax_set_fptr_mask
15087 + movabs $0x8000000000000000,%r12
15088 + .endm
15089 +#endif
15090 +#else
15091 + .macro pax_force_retaddr rip=0, reload=0
15092 + .endm
15093 + .macro pax_force_fptr ptr
15094 + .endm
15095 + .macro pax_force_retaddr_bts rip=0
15096 + .endm
15097 + .macro pax_set_fptr_mask
15098 + .endm
15099 +#endif
15100 +
15101 .macro altinstruction_entry orig alt feature orig_len alt_len
15102 .long \orig - .
15103 .long \alt - .
15104 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15105 index 0a3f9c9..c9d081d 100644
15106 --- a/arch/x86/include/asm/alternative.h
15107 +++ b/arch/x86/include/asm/alternative.h
15108 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15109 ".pushsection .discard,\"aw\",@progbits\n" \
15110 DISCARD_ENTRY(1) \
15111 ".popsection\n" \
15112 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15113 + ".pushsection .altinstr_replacement, \"a\"\n" \
15114 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15115 ".popsection"
15116
15117 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15118 DISCARD_ENTRY(1) \
15119 DISCARD_ENTRY(2) \
15120 ".popsection\n" \
15121 - ".pushsection .altinstr_replacement, \"ax\"\n" \
15122 + ".pushsection .altinstr_replacement, \"a\"\n" \
15123 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15124 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15125 ".popsection"
15126 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15127 index 1d2091a..f5074c1 100644
15128 --- a/arch/x86/include/asm/apic.h
15129 +++ b/arch/x86/include/asm/apic.h
15130 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15131
15132 #ifdef CONFIG_X86_LOCAL_APIC
15133
15134 -extern unsigned int apic_verbosity;
15135 +extern int apic_verbosity;
15136 extern int local_apic_timer_c2_ok;
15137
15138 extern int disable_apic;
15139 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15140 index 20370c6..a2eb9b0 100644
15141 --- a/arch/x86/include/asm/apm.h
15142 +++ b/arch/x86/include/asm/apm.h
15143 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15144 __asm__ __volatile__(APM_DO_ZERO_SEGS
15145 "pushl %%edi\n\t"
15146 "pushl %%ebp\n\t"
15147 - "lcall *%%cs:apm_bios_entry\n\t"
15148 + "lcall *%%ss:apm_bios_entry\n\t"
15149 "setc %%al\n\t"
15150 "popl %%ebp\n\t"
15151 "popl %%edi\n\t"
15152 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15153 __asm__ __volatile__(APM_DO_ZERO_SEGS
15154 "pushl %%edi\n\t"
15155 "pushl %%ebp\n\t"
15156 - "lcall *%%cs:apm_bios_entry\n\t"
15157 + "lcall *%%ss:apm_bios_entry\n\t"
15158 "setc %%bl\n\t"
15159 "popl %%ebp\n\t"
15160 "popl %%edi\n\t"
15161 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15162 index b17f4f4..9620151 100644
15163 --- a/arch/x86/include/asm/atomic.h
15164 +++ b/arch/x86/include/asm/atomic.h
15165 @@ -23,7 +23,18 @@
15166 */
15167 static inline int atomic_read(const atomic_t *v)
15168 {
15169 - return (*(volatile int *)&(v)->counter);
15170 + return (*(volatile const int *)&(v)->counter);
15171 +}
15172 +
15173 +/**
15174 + * atomic_read_unchecked - read atomic variable
15175 + * @v: pointer of type atomic_unchecked_t
15176 + *
15177 + * Atomically reads the value of @v.
15178 + */
15179 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15180 +{
15181 + return (*(volatile const int *)&(v)->counter);
15182 }
15183
15184 /**
15185 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
15186 }
15187
15188 /**
15189 + * atomic_set_unchecked - set atomic variable
15190 + * @v: pointer of type atomic_unchecked_t
15191 + * @i: required value
15192 + *
15193 + * Atomically sets the value of @v to @i.
15194 + */
15195 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15196 +{
15197 + v->counter = i;
15198 +}
15199 +
15200 +/**
15201 * atomic_add - add integer to atomic variable
15202 * @i: integer value to add
15203 * @v: pointer of type atomic_t
15204 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
15205 */
15206 static inline void atomic_add(int i, atomic_t *v)
15207 {
15208 - asm volatile(LOCK_PREFIX "addl %1,%0"
15209 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15210 +
15211 +#ifdef CONFIG_PAX_REFCOUNT
15212 + "jno 0f\n"
15213 + LOCK_PREFIX "subl %1,%0\n"
15214 + "int $4\n0:\n"
15215 + _ASM_EXTABLE(0b, 0b)
15216 +#endif
15217 +
15218 + : "+m" (v->counter)
15219 + : "ir" (i));
15220 +}
15221 +
15222 +/**
15223 + * atomic_add_unchecked - add integer to atomic variable
15224 + * @i: integer value to add
15225 + * @v: pointer of type atomic_unchecked_t
15226 + *
15227 + * Atomically adds @i to @v.
15228 + */
15229 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15230 +{
15231 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
15232 : "+m" (v->counter)
15233 : "ir" (i));
15234 }
15235 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
15236 */
15237 static inline void atomic_sub(int i, atomic_t *v)
15238 {
15239 - asm volatile(LOCK_PREFIX "subl %1,%0"
15240 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15241 +
15242 +#ifdef CONFIG_PAX_REFCOUNT
15243 + "jno 0f\n"
15244 + LOCK_PREFIX "addl %1,%0\n"
15245 + "int $4\n0:\n"
15246 + _ASM_EXTABLE(0b, 0b)
15247 +#endif
15248 +
15249 + : "+m" (v->counter)
15250 + : "ir" (i));
15251 +}
15252 +
15253 +/**
15254 + * atomic_sub_unchecked - subtract integer from atomic variable
15255 + * @i: integer value to subtract
15256 + * @v: pointer of type atomic_unchecked_t
15257 + *
15258 + * Atomically subtracts @i from @v.
15259 + */
15260 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15261 +{
15262 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
15263 : "+m" (v->counter)
15264 : "ir" (i));
15265 }
15266 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15267 */
15268 static inline int atomic_sub_and_test(int i, atomic_t *v)
15269 {
15270 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15271 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15272 }
15273
15274 /**
15275 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15276 */
15277 static inline void atomic_inc(atomic_t *v)
15278 {
15279 - asm volatile(LOCK_PREFIX "incl %0"
15280 + asm volatile(LOCK_PREFIX "incl %0\n"
15281 +
15282 +#ifdef CONFIG_PAX_REFCOUNT
15283 + "jno 0f\n"
15284 + LOCK_PREFIX "decl %0\n"
15285 + "int $4\n0:\n"
15286 + _ASM_EXTABLE(0b, 0b)
15287 +#endif
15288 +
15289 + : "+m" (v->counter));
15290 +}
15291 +
15292 +/**
15293 + * atomic_inc_unchecked - increment atomic variable
15294 + * @v: pointer of type atomic_unchecked_t
15295 + *
15296 + * Atomically increments @v by 1.
15297 + */
15298 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15299 +{
15300 + asm volatile(LOCK_PREFIX "incl %0\n"
15301 : "+m" (v->counter));
15302 }
15303
15304 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15305 */
15306 static inline void atomic_dec(atomic_t *v)
15307 {
15308 - asm volatile(LOCK_PREFIX "decl %0"
15309 + asm volatile(LOCK_PREFIX "decl %0\n"
15310 +
15311 +#ifdef CONFIG_PAX_REFCOUNT
15312 + "jno 0f\n"
15313 + LOCK_PREFIX "incl %0\n"
15314 + "int $4\n0:\n"
15315 + _ASM_EXTABLE(0b, 0b)
15316 +#endif
15317 +
15318 + : "+m" (v->counter));
15319 +}
15320 +
15321 +/**
15322 + * atomic_dec_unchecked - decrement atomic variable
15323 + * @v: pointer of type atomic_unchecked_t
15324 + *
15325 + * Atomically decrements @v by 1.
15326 + */
15327 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15328 +{
15329 + asm volatile(LOCK_PREFIX "decl %0\n"
15330 : "+m" (v->counter));
15331 }
15332
15333 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15334 */
15335 static inline int atomic_dec_and_test(atomic_t *v)
15336 {
15337 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15338 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15339 }
15340
15341 /**
15342 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15343 */
15344 static inline int atomic_inc_and_test(atomic_t *v)
15345 {
15346 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15347 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15348 +}
15349 +
15350 +/**
15351 + * atomic_inc_and_test_unchecked - increment and test
15352 + * @v: pointer of type atomic_unchecked_t
15353 + *
15354 + * Atomically increments @v by 1
15355 + * and returns true if the result is zero, or false for all
15356 + * other cases.
15357 + */
15358 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15359 +{
15360 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15361 }
15362
15363 /**
15364 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15365 */
15366 static inline int atomic_add_negative(int i, atomic_t *v)
15367 {
15368 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15369 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15370 }
15371
15372 /**
15373 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15374 */
15375 static inline int atomic_add_return(int i, atomic_t *v)
15376 {
15377 + return i + xadd_check_overflow(&v->counter, i);
15378 +}
15379 +
15380 +/**
15381 + * atomic_add_return_unchecked - add integer and return
15382 + * @i: integer value to add
15383 + * @v: pointer of type atomic_unchecked_t
15384 + *
15385 + * Atomically adds @i to @v and returns @i + @v
15386 + */
15387 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15388 +{
15389 return i + xadd(&v->counter, i);
15390 }
15391
15392 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15393 }
15394
15395 #define atomic_inc_return(v) (atomic_add_return(1, v))
15396 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15397 +{
15398 + return atomic_add_return_unchecked(1, v);
15399 +}
15400 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15401
15402 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15403 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15404 +{
15405 + return cmpxchg(&v->counter, old, new);
15406 +}
15407 +
15408 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15409 {
15410 return cmpxchg(&v->counter, old, new);
15411 }
15412 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15413 return xchg(&v->counter, new);
15414 }
15415
15416 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15417 +{
15418 + return xchg(&v->counter, new);
15419 +}
15420 +
15421 /**
15422 * __atomic_add_unless - add unless the number is already a given value
15423 * @v: pointer of type atomic_t
15424 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15425 * Atomically adds @a to @v, so long as @v was not already @u.
15426 * Returns the old value of @v.
15427 */
15428 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15429 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15430 {
15431 - int c, old;
15432 + int c, old, new;
15433 c = atomic_read(v);
15434 for (;;) {
15435 - if (unlikely(c == (u)))
15436 + if (unlikely(c == u))
15437 break;
15438 - old = atomic_cmpxchg((v), c, c + (a));
15439 +
15440 + asm volatile("addl %2,%0\n"
15441 +
15442 +#ifdef CONFIG_PAX_REFCOUNT
15443 + "jno 0f\n"
15444 + "subl %2,%0\n"
15445 + "int $4\n0:\n"
15446 + _ASM_EXTABLE(0b, 0b)
15447 +#endif
15448 +
15449 + : "=r" (new)
15450 + : "0" (c), "ir" (a));
15451 +
15452 + old = atomic_cmpxchg(v, c, new);
15453 if (likely(old == c))
15454 break;
15455 c = old;
15456 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15457 }
15458
15459 /**
15460 + * atomic_inc_not_zero_hint - increment if not null
15461 + * @v: pointer of type atomic_t
15462 + * @hint: probable value of the atomic before the increment
15463 + *
15464 + * This version of atomic_inc_not_zero() gives a hint of probable
15465 + * value of the atomic. This helps processor to not read the memory
15466 + * before doing the atomic read/modify/write cycle, lowering
15467 + * number of bus transactions on some arches.
15468 + *
15469 + * Returns: 0 if increment was not done, 1 otherwise.
15470 + */
15471 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15472 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15473 +{
15474 + int val, c = hint, new;
15475 +
15476 + /* sanity test, should be removed by compiler if hint is a constant */
15477 + if (!hint)
15478 + return __atomic_add_unless(v, 1, 0);
15479 +
15480 + do {
15481 + asm volatile("incl %0\n"
15482 +
15483 +#ifdef CONFIG_PAX_REFCOUNT
15484 + "jno 0f\n"
15485 + "decl %0\n"
15486 + "int $4\n0:\n"
15487 + _ASM_EXTABLE(0b, 0b)
15488 +#endif
15489 +
15490 + : "=r" (new)
15491 + : "0" (c));
15492 +
15493 + val = atomic_cmpxchg(v, c, new);
15494 + if (val == c)
15495 + return 1;
15496 + c = val;
15497 + } while (c);
15498 +
15499 + return 0;
15500 +}
15501 +
15502 +/**
15503 * atomic_inc_short - increment of a short integer
15504 * @v: pointer to type int
15505 *
15506 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15507 #endif
15508
15509 /* These are x86-specific, used by some header files */
15510 -#define atomic_clear_mask(mask, addr) \
15511 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15512 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15513 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15514 +{
15515 + asm volatile(LOCK_PREFIX "andl %1,%0"
15516 + : "+m" (v->counter)
15517 + : "r" (~(mask))
15518 + : "memory");
15519 +}
15520
15521 -#define atomic_set_mask(mask, addr) \
15522 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15523 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15524 - : "memory")
15525 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15526 +{
15527 + asm volatile(LOCK_PREFIX "andl %1,%0"
15528 + : "+m" (v->counter)
15529 + : "r" (~(mask))
15530 + : "memory");
15531 +}
15532 +
15533 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15534 +{
15535 + asm volatile(LOCK_PREFIX "orl %1,%0"
15536 + : "+m" (v->counter)
15537 + : "r" (mask)
15538 + : "memory");
15539 +}
15540 +
15541 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15542 +{
15543 + asm volatile(LOCK_PREFIX "orl %1,%0"
15544 + : "+m" (v->counter)
15545 + : "r" (mask)
15546 + : "memory");
15547 +}
15548
15549 /* Atomic operations are already serializing on x86 */
15550 #define smp_mb__before_atomic_dec() barrier()
15551 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15552 index b154de7..bf18a5a 100644
15553 --- a/arch/x86/include/asm/atomic64_32.h
15554 +++ b/arch/x86/include/asm/atomic64_32.h
15555 @@ -12,6 +12,14 @@ typedef struct {
15556 u64 __aligned(8) counter;
15557 } atomic64_t;
15558
15559 +#ifdef CONFIG_PAX_REFCOUNT
15560 +typedef struct {
15561 + u64 __aligned(8) counter;
15562 +} atomic64_unchecked_t;
15563 +#else
15564 +typedef atomic64_t atomic64_unchecked_t;
15565 +#endif
15566 +
15567 #define ATOMIC64_INIT(val) { (val) }
15568
15569 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15570 @@ -37,21 +45,31 @@ typedef struct {
15571 ATOMIC64_DECL_ONE(sym##_386)
15572
15573 ATOMIC64_DECL_ONE(add_386);
15574 +ATOMIC64_DECL_ONE(add_unchecked_386);
15575 ATOMIC64_DECL_ONE(sub_386);
15576 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15577 ATOMIC64_DECL_ONE(inc_386);
15578 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15579 ATOMIC64_DECL_ONE(dec_386);
15580 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15581 #endif
15582
15583 #define alternative_atomic64(f, out, in...) \
15584 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15585
15586 ATOMIC64_DECL(read);
15587 +ATOMIC64_DECL(read_unchecked);
15588 ATOMIC64_DECL(set);
15589 +ATOMIC64_DECL(set_unchecked);
15590 ATOMIC64_DECL(xchg);
15591 ATOMIC64_DECL(add_return);
15592 +ATOMIC64_DECL(add_return_unchecked);
15593 ATOMIC64_DECL(sub_return);
15594 +ATOMIC64_DECL(sub_return_unchecked);
15595 ATOMIC64_DECL(inc_return);
15596 +ATOMIC64_DECL(inc_return_unchecked);
15597 ATOMIC64_DECL(dec_return);
15598 +ATOMIC64_DECL(dec_return_unchecked);
15599 ATOMIC64_DECL(dec_if_positive);
15600 ATOMIC64_DECL(inc_not_zero);
15601 ATOMIC64_DECL(add_unless);
15602 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15603 }
15604
15605 /**
15606 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15607 + * @p: pointer to type atomic64_unchecked_t
15608 + * @o: expected value
15609 + * @n: new value
15610 + *
15611 + * Atomically sets @v to @n if it was equal to @o and returns
15612 + * the old value.
15613 + */
15614 +
15615 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15616 +{
15617 + return cmpxchg64(&v->counter, o, n);
15618 +}
15619 +
15620 +/**
15621 * atomic64_xchg - xchg atomic64 variable
15622 * @v: pointer to type atomic64_t
15623 * @n: value to assign
15624 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15625 }
15626
15627 /**
15628 + * atomic64_set_unchecked - set atomic64 variable
15629 + * @v: pointer to type atomic64_unchecked_t
15630 + * @n: value to assign
15631 + *
15632 + * Atomically sets the value of @v to @n.
15633 + */
15634 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15635 +{
15636 + unsigned high = (unsigned)(i >> 32);
15637 + unsigned low = (unsigned)i;
15638 + alternative_atomic64(set, /* no output */,
15639 + "S" (v), "b" (low), "c" (high)
15640 + : "eax", "edx", "memory");
15641 +}
15642 +
15643 +/**
15644 * atomic64_read - read atomic64 variable
15645 * @v: pointer to type atomic64_t
15646 *
15647 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15648 }
15649
15650 /**
15651 + * atomic64_read_unchecked - read atomic64 variable
15652 + * @v: pointer to type atomic64_unchecked_t
15653 + *
15654 + * Atomically reads the value of @v and returns it.
15655 + */
15656 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15657 +{
15658 + long long r;
15659 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15660 + return r;
15661 + }
15662 +
15663 +/**
15664 * atomic64_add_return - add and return
15665 * @i: integer value to add
15666 * @v: pointer to type atomic64_t
15667 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15668 return i;
15669 }
15670
15671 +/**
15672 + * atomic64_add_return_unchecked - add and return
15673 + * @i: integer value to add
15674 + * @v: pointer to type atomic64_unchecked_t
15675 + *
15676 + * Atomically adds @i to @v and returns @i + *@v
15677 + */
15678 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15679 +{
15680 + alternative_atomic64(add_return_unchecked,
15681 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15682 + ASM_NO_INPUT_CLOBBER("memory"));
15683 + return i;
15684 +}
15685 +
15686 /*
15687 * Other variants with different arithmetic operators:
15688 */
15689 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15690 return a;
15691 }
15692
15693 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15694 +{
15695 + long long a;
15696 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15697 + "S" (v) : "memory", "ecx");
15698 + return a;
15699 +}
15700 +
15701 static inline long long atomic64_dec_return(atomic64_t *v)
15702 {
15703 long long a;
15704 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15705 }
15706
15707 /**
15708 + * atomic64_add_unchecked - add integer to atomic64 variable
15709 + * @i: integer value to add
15710 + * @v: pointer to type atomic64_unchecked_t
15711 + *
15712 + * Atomically adds @i to @v.
15713 + */
15714 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15715 +{
15716 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15717 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15718 + ASM_NO_INPUT_CLOBBER("memory"));
15719 + return i;
15720 +}
15721 +
15722 +/**
15723 * atomic64_sub - subtract the atomic64 variable
15724 * @i: integer value to subtract
15725 * @v: pointer to type atomic64_t
15726 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15727 index 46e9052..ae45136 100644
15728 --- a/arch/x86/include/asm/atomic64_64.h
15729 +++ b/arch/x86/include/asm/atomic64_64.h
15730 @@ -18,7 +18,19 @@
15731 */
15732 static inline long atomic64_read(const atomic64_t *v)
15733 {
15734 - return (*(volatile long *)&(v)->counter);
15735 + return (*(volatile const long *)&(v)->counter);
15736 +}
15737 +
15738 +/**
15739 + * atomic64_read_unchecked - read atomic64 variable
15740 + * @v: pointer of type atomic64_unchecked_t
15741 + *
15742 + * Atomically reads the value of @v.
15743 + * Doesn't imply a read memory barrier.
15744 + */
15745 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15746 +{
15747 + return (*(volatile const long *)&(v)->counter);
15748 }
15749
15750 /**
15751 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15752 }
15753
15754 /**
15755 + * atomic64_set_unchecked - set atomic64 variable
15756 + * @v: pointer to type atomic64_unchecked_t
15757 + * @i: required value
15758 + *
15759 + * Atomically sets the value of @v to @i.
15760 + */
15761 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15762 +{
15763 + v->counter = i;
15764 +}
15765 +
15766 +/**
15767 * atomic64_add - add integer to atomic64 variable
15768 * @i: integer value to add
15769 * @v: pointer to type atomic64_t
15770 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15771 */
15772 static inline void atomic64_add(long i, atomic64_t *v)
15773 {
15774 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15775 +
15776 +#ifdef CONFIG_PAX_REFCOUNT
15777 + "jno 0f\n"
15778 + LOCK_PREFIX "subq %1,%0\n"
15779 + "int $4\n0:\n"
15780 + _ASM_EXTABLE(0b, 0b)
15781 +#endif
15782 +
15783 + : "=m" (v->counter)
15784 + : "er" (i), "m" (v->counter));
15785 +}
15786 +
15787 +/**
15788 + * atomic64_add_unchecked - add integer to atomic64 variable
15789 + * @i: integer value to add
15790 + * @v: pointer to type atomic64_unchecked_t
15791 + *
15792 + * Atomically adds @i to @v.
15793 + */
15794 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15795 +{
15796 asm volatile(LOCK_PREFIX "addq %1,%0"
15797 : "=m" (v->counter)
15798 : "er" (i), "m" (v->counter));
15799 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15800 */
15801 static inline void atomic64_sub(long i, atomic64_t *v)
15802 {
15803 - asm volatile(LOCK_PREFIX "subq %1,%0"
15804 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15805 +
15806 +#ifdef CONFIG_PAX_REFCOUNT
15807 + "jno 0f\n"
15808 + LOCK_PREFIX "addq %1,%0\n"
15809 + "int $4\n0:\n"
15810 + _ASM_EXTABLE(0b, 0b)
15811 +#endif
15812 +
15813 + : "=m" (v->counter)
15814 + : "er" (i), "m" (v->counter));
15815 +}
15816 +
15817 +/**
15818 + * atomic64_sub_unchecked - subtract the atomic64 variable
15819 + * @i: integer value to subtract
15820 + * @v: pointer to type atomic64_unchecked_t
15821 + *
15822 + * Atomically subtracts @i from @v.
15823 + */
15824 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15825 +{
15826 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15827 : "=m" (v->counter)
15828 : "er" (i), "m" (v->counter));
15829 }
15830 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15831 */
15832 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15833 {
15834 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15835 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15836 }
15837
15838 /**
15839 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15840 */
15841 static inline void atomic64_inc(atomic64_t *v)
15842 {
15843 + asm volatile(LOCK_PREFIX "incq %0\n"
15844 +
15845 +#ifdef CONFIG_PAX_REFCOUNT
15846 + "jno 0f\n"
15847 + LOCK_PREFIX "decq %0\n"
15848 + "int $4\n0:\n"
15849 + _ASM_EXTABLE(0b, 0b)
15850 +#endif
15851 +
15852 + : "=m" (v->counter)
15853 + : "m" (v->counter));
15854 +}
15855 +
15856 +/**
15857 + * atomic64_inc_unchecked - increment atomic64 variable
15858 + * @v: pointer to type atomic64_unchecked_t
15859 + *
15860 + * Atomically increments @v by 1.
15861 + */
15862 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15863 +{
15864 asm volatile(LOCK_PREFIX "incq %0"
15865 : "=m" (v->counter)
15866 : "m" (v->counter));
15867 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15868 */
15869 static inline void atomic64_dec(atomic64_t *v)
15870 {
15871 - asm volatile(LOCK_PREFIX "decq %0"
15872 + asm volatile(LOCK_PREFIX "decq %0\n"
15873 +
15874 +#ifdef CONFIG_PAX_REFCOUNT
15875 + "jno 0f\n"
15876 + LOCK_PREFIX "incq %0\n"
15877 + "int $4\n0:\n"
15878 + _ASM_EXTABLE(0b, 0b)
15879 +#endif
15880 +
15881 + : "=m" (v->counter)
15882 + : "m" (v->counter));
15883 +}
15884 +
15885 +/**
15886 + * atomic64_dec_unchecked - decrement atomic64 variable
15887 + * @v: pointer to type atomic64_t
15888 + *
15889 + * Atomically decrements @v by 1.
15890 + */
15891 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15892 +{
15893 + asm volatile(LOCK_PREFIX "decq %0\n"
15894 : "=m" (v->counter)
15895 : "m" (v->counter));
15896 }
15897 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15898 */
15899 static inline int atomic64_dec_and_test(atomic64_t *v)
15900 {
15901 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15902 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15903 }
15904
15905 /**
15906 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15907 */
15908 static inline int atomic64_inc_and_test(atomic64_t *v)
15909 {
15910 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15911 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15912 }
15913
15914 /**
15915 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15916 */
15917 static inline int atomic64_add_negative(long i, atomic64_t *v)
15918 {
15919 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15920 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15921 }
15922
15923 /**
15924 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15925 */
15926 static inline long atomic64_add_return(long i, atomic64_t *v)
15927 {
15928 + return i + xadd_check_overflow(&v->counter, i);
15929 +}
15930 +
15931 +/**
15932 + * atomic64_add_return_unchecked - add and return
15933 + * @i: integer value to add
15934 + * @v: pointer to type atomic64_unchecked_t
15935 + *
15936 + * Atomically adds @i to @v and returns @i + @v
15937 + */
15938 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15939 +{
15940 return i + xadd(&v->counter, i);
15941 }
15942
15943 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15944 }
15945
15946 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15947 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15948 +{
15949 + return atomic64_add_return_unchecked(1, v);
15950 +}
15951 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15952
15953 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15954 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15955 return cmpxchg(&v->counter, old, new);
15956 }
15957
15958 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15959 +{
15960 + return cmpxchg(&v->counter, old, new);
15961 +}
15962 +
15963 static inline long atomic64_xchg(atomic64_t *v, long new)
15964 {
15965 return xchg(&v->counter, new);
15966 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15967 */
15968 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15969 {
15970 - long c, old;
15971 + long c, old, new;
15972 c = atomic64_read(v);
15973 for (;;) {
15974 - if (unlikely(c == (u)))
15975 + if (unlikely(c == u))
15976 break;
15977 - old = atomic64_cmpxchg((v), c, c + (a));
15978 +
15979 + asm volatile("add %2,%0\n"
15980 +
15981 +#ifdef CONFIG_PAX_REFCOUNT
15982 + "jno 0f\n"
15983 + "sub %2,%0\n"
15984 + "int $4\n0:\n"
15985 + _ASM_EXTABLE(0b, 0b)
15986 +#endif
15987 +
15988 + : "=r" (new)
15989 + : "0" (c), "ir" (a));
15990 +
15991 + old = atomic64_cmpxchg(v, c, new);
15992 if (likely(old == c))
15993 break;
15994 c = old;
15995 }
15996 - return c != (u);
15997 + return c != u;
15998 }
15999
16000 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16001 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16002 index 9fc1af7..fc71228 100644
16003 --- a/arch/x86/include/asm/bitops.h
16004 +++ b/arch/x86/include/asm/bitops.h
16005 @@ -49,7 +49,7 @@
16006 * a mask operation on a byte.
16007 */
16008 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16009 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16010 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16011 #define CONST_MASK(nr) (1 << ((nr) & 7))
16012
16013 /**
16014 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16015 */
16016 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16017 {
16018 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16019 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16020 }
16021
16022 /**
16023 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16024 */
16025 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16026 {
16027 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16028 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16029 }
16030
16031 /**
16032 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16033 */
16034 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16035 {
16036 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16037 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16038 }
16039
16040 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16041 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16042 *
16043 * Undefined if no bit exists, so code should check against 0 first.
16044 */
16045 -static inline unsigned long __ffs(unsigned long word)
16046 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16047 {
16048 asm("rep; bsf %1,%0"
16049 : "=r" (word)
16050 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
16051 *
16052 * Undefined if no zero exists, so code should check against ~0UL first.
16053 */
16054 -static inline unsigned long ffz(unsigned long word)
16055 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16056 {
16057 asm("rep; bsf %1,%0"
16058 : "=r" (word)
16059 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
16060 *
16061 * Undefined if no set bit exists, so code should check against 0 first.
16062 */
16063 -static inline unsigned long __fls(unsigned long word)
16064 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16065 {
16066 asm("bsr %1,%0"
16067 : "=r" (word)
16068 @@ -436,7 +436,7 @@ static inline int ffs(int x)
16069 * set bit if value is nonzero. The last (most significant) bit is
16070 * at position 32.
16071 */
16072 -static inline int fls(int x)
16073 +static inline int __intentional_overflow(-1) fls(int x)
16074 {
16075 int r;
16076
16077 @@ -478,7 +478,7 @@ static inline int fls(int x)
16078 * at position 64.
16079 */
16080 #ifdef CONFIG_X86_64
16081 -static __always_inline int fls64(__u64 x)
16082 +static __always_inline long fls64(__u64 x)
16083 {
16084 int bitpos = -1;
16085 /*
16086 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16087 index 4fa687a..60f2d39 100644
16088 --- a/arch/x86/include/asm/boot.h
16089 +++ b/arch/x86/include/asm/boot.h
16090 @@ -6,10 +6,15 @@
16091 #include <uapi/asm/boot.h>
16092
16093 /* Physical address where kernel should be loaded. */
16094 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16095 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16096 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16097 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16098
16099 +#ifndef __ASSEMBLY__
16100 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
16101 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16102 +#endif
16103 +
16104 /* Minimum kernel alignment, as a power of two */
16105 #ifdef CONFIG_X86_64
16106 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16107 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16108 index 48f99f1..d78ebf9 100644
16109 --- a/arch/x86/include/asm/cache.h
16110 +++ b/arch/x86/include/asm/cache.h
16111 @@ -5,12 +5,13 @@
16112
16113 /* L1 cache line size */
16114 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16115 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16116 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16117
16118 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16119 +#define __read_only __attribute__((__section__(".data..read_only")))
16120
16121 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16122 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16123 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16124
16125 #ifdef CONFIG_X86_VSMP
16126 #ifdef CONFIG_SMP
16127 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16128 index 9863ee3..4a1f8e1 100644
16129 --- a/arch/x86/include/asm/cacheflush.h
16130 +++ b/arch/x86/include/asm/cacheflush.h
16131 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16132 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16133
16134 if (pg_flags == _PGMT_DEFAULT)
16135 - return -1;
16136 + return ~0UL;
16137 else if (pg_flags == _PGMT_WC)
16138 return _PAGE_CACHE_WC;
16139 else if (pg_flags == _PGMT_UC_MINUS)
16140 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16141 index cb4c73b..c473c29 100644
16142 --- a/arch/x86/include/asm/calling.h
16143 +++ b/arch/x86/include/asm/calling.h
16144 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16145 #define RSP 152
16146 #define SS 160
16147
16148 -#define ARGOFFSET R11
16149 -#define SWFRAME ORIG_RAX
16150 +#define ARGOFFSET R15
16151
16152 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16153 - subq $9*8+\addskip, %rsp
16154 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16155 - movq_cfi rdi, 8*8
16156 - movq_cfi rsi, 7*8
16157 - movq_cfi rdx, 6*8
16158 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16159 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16160 + movq_cfi rdi, RDI
16161 + movq_cfi rsi, RSI
16162 + movq_cfi rdx, RDX
16163
16164 .if \save_rcx
16165 - movq_cfi rcx, 5*8
16166 + movq_cfi rcx, RCX
16167 .endif
16168
16169 - movq_cfi rax, 4*8
16170 + movq_cfi rax, RAX
16171
16172 .if \save_r891011
16173 - movq_cfi r8, 3*8
16174 - movq_cfi r9, 2*8
16175 - movq_cfi r10, 1*8
16176 - movq_cfi r11, 0*8
16177 + movq_cfi r8, R8
16178 + movq_cfi r9, R9
16179 + movq_cfi r10, R10
16180 + movq_cfi r11, R11
16181 .endif
16182
16183 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16184 + movq_cfi r12, R12
16185 +#endif
16186 +
16187 .endm
16188
16189 -#define ARG_SKIP (9*8)
16190 +#define ARG_SKIP ORIG_RAX
16191
16192 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16193 rstor_r8910=1, rstor_rdx=1
16194 +
16195 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16196 + movq_cfi_restore R12, r12
16197 +#endif
16198 +
16199 .if \rstor_r11
16200 - movq_cfi_restore 0*8, r11
16201 + movq_cfi_restore R11, r11
16202 .endif
16203
16204 .if \rstor_r8910
16205 - movq_cfi_restore 1*8, r10
16206 - movq_cfi_restore 2*8, r9
16207 - movq_cfi_restore 3*8, r8
16208 + movq_cfi_restore R10, r10
16209 + movq_cfi_restore R9, r9
16210 + movq_cfi_restore R8, r8
16211 .endif
16212
16213 .if \rstor_rax
16214 - movq_cfi_restore 4*8, rax
16215 + movq_cfi_restore RAX, rax
16216 .endif
16217
16218 .if \rstor_rcx
16219 - movq_cfi_restore 5*8, rcx
16220 + movq_cfi_restore RCX, rcx
16221 .endif
16222
16223 .if \rstor_rdx
16224 - movq_cfi_restore 6*8, rdx
16225 + movq_cfi_restore RDX, rdx
16226 .endif
16227
16228 - movq_cfi_restore 7*8, rsi
16229 - movq_cfi_restore 8*8, rdi
16230 + movq_cfi_restore RSI, rsi
16231 + movq_cfi_restore RDI, rdi
16232
16233 - .if ARG_SKIP+\addskip > 0
16234 - addq $ARG_SKIP+\addskip, %rsp
16235 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16236 + .if ORIG_RAX+\addskip > 0
16237 + addq $ORIG_RAX+\addskip, %rsp
16238 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16239 .endif
16240 .endm
16241
16242 - .macro LOAD_ARGS offset, skiprax=0
16243 - movq \offset(%rsp), %r11
16244 - movq \offset+8(%rsp), %r10
16245 - movq \offset+16(%rsp), %r9
16246 - movq \offset+24(%rsp), %r8
16247 - movq \offset+40(%rsp), %rcx
16248 - movq \offset+48(%rsp), %rdx
16249 - movq \offset+56(%rsp), %rsi
16250 - movq \offset+64(%rsp), %rdi
16251 + .macro LOAD_ARGS skiprax=0
16252 + movq R11(%rsp), %r11
16253 + movq R10(%rsp), %r10
16254 + movq R9(%rsp), %r9
16255 + movq R8(%rsp), %r8
16256 + movq RCX(%rsp), %rcx
16257 + movq RDX(%rsp), %rdx
16258 + movq RSI(%rsp), %rsi
16259 + movq RDI(%rsp), %rdi
16260 .if \skiprax
16261 .else
16262 - movq \offset+72(%rsp), %rax
16263 + movq RAX(%rsp), %rax
16264 .endif
16265 .endm
16266
16267 -#define REST_SKIP (6*8)
16268 -
16269 .macro SAVE_REST
16270 - subq $REST_SKIP, %rsp
16271 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16272 - movq_cfi rbx, 5*8
16273 - movq_cfi rbp, 4*8
16274 - movq_cfi r12, 3*8
16275 - movq_cfi r13, 2*8
16276 - movq_cfi r14, 1*8
16277 - movq_cfi r15, 0*8
16278 + movq_cfi rbx, RBX
16279 + movq_cfi rbp, RBP
16280 +
16281 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16282 + movq_cfi r12, R12
16283 +#endif
16284 +
16285 + movq_cfi r13, R13
16286 + movq_cfi r14, R14
16287 + movq_cfi r15, R15
16288 .endm
16289
16290 .macro RESTORE_REST
16291 - movq_cfi_restore 0*8, r15
16292 - movq_cfi_restore 1*8, r14
16293 - movq_cfi_restore 2*8, r13
16294 - movq_cfi_restore 3*8, r12
16295 - movq_cfi_restore 4*8, rbp
16296 - movq_cfi_restore 5*8, rbx
16297 - addq $REST_SKIP, %rsp
16298 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16299 + movq_cfi_restore R15, r15
16300 + movq_cfi_restore R14, r14
16301 + movq_cfi_restore R13, r13
16302 +
16303 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16304 + movq_cfi_restore R12, r12
16305 +#endif
16306 +
16307 + movq_cfi_restore RBP, rbp
16308 + movq_cfi_restore RBX, rbx
16309 .endm
16310
16311 .macro SAVE_ALL
16312 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16313 index f50de69..2b0a458 100644
16314 --- a/arch/x86/include/asm/checksum_32.h
16315 +++ b/arch/x86/include/asm/checksum_32.h
16316 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16317 int len, __wsum sum,
16318 int *src_err_ptr, int *dst_err_ptr);
16319
16320 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16321 + int len, __wsum sum,
16322 + int *src_err_ptr, int *dst_err_ptr);
16323 +
16324 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16325 + int len, __wsum sum,
16326 + int *src_err_ptr, int *dst_err_ptr);
16327 +
16328 /*
16329 * Note: when you get a NULL pointer exception here this means someone
16330 * passed in an incorrect kernel address to one of these functions.
16331 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16332
16333 might_sleep();
16334 stac();
16335 - ret = csum_partial_copy_generic((__force void *)src, dst,
16336 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16337 len, sum, err_ptr, NULL);
16338 clac();
16339
16340 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16341 might_sleep();
16342 if (access_ok(VERIFY_WRITE, dst, len)) {
16343 stac();
16344 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16345 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16346 len, sum, NULL, err_ptr);
16347 clac();
16348 return ret;
16349 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16350 index d47786a..2d8883e 100644
16351 --- a/arch/x86/include/asm/cmpxchg.h
16352 +++ b/arch/x86/include/asm/cmpxchg.h
16353 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16354 __compiletime_error("Bad argument size for cmpxchg");
16355 extern void __xadd_wrong_size(void)
16356 __compiletime_error("Bad argument size for xadd");
16357 +extern void __xadd_check_overflow_wrong_size(void)
16358 + __compiletime_error("Bad argument size for xadd_check_overflow");
16359 extern void __add_wrong_size(void)
16360 __compiletime_error("Bad argument size for add");
16361 +extern void __add_check_overflow_wrong_size(void)
16362 + __compiletime_error("Bad argument size for add_check_overflow");
16363
16364 /*
16365 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16366 @@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16367 __ret; \
16368 })
16369
16370 +#ifdef CONFIG_PAX_REFCOUNT
16371 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16372 + ({ \
16373 + __typeof__ (*(ptr)) __ret = (arg); \
16374 + switch (sizeof(*(ptr))) { \
16375 + case __X86_CASE_L: \
16376 + asm volatile (lock #op "l %0, %1\n" \
16377 + "jno 0f\n" \
16378 + "mov %0,%1\n" \
16379 + "int $4\n0:\n" \
16380 + _ASM_EXTABLE(0b, 0b) \
16381 + : "+r" (__ret), "+m" (*(ptr)) \
16382 + : : "memory", "cc"); \
16383 + break; \
16384 + case __X86_CASE_Q: \
16385 + asm volatile (lock #op "q %q0, %1\n" \
16386 + "jno 0f\n" \
16387 + "mov %0,%1\n" \
16388 + "int $4\n0:\n" \
16389 + _ASM_EXTABLE(0b, 0b) \
16390 + : "+r" (__ret), "+m" (*(ptr)) \
16391 + : : "memory", "cc"); \
16392 + break; \
16393 + default: \
16394 + __ ## op ## _check_overflow_wrong_size(); \
16395 + } \
16396 + __ret; \
16397 + })
16398 +#else
16399 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16400 +#endif
16401 +
16402 /*
16403 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16404 * Since this is generally used to protect other memory information, we
16405 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16406 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16407 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16408
16409 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16410 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16411 +
16412 #define __add(ptr, inc, lock) \
16413 ({ \
16414 __typeof__ (*(ptr)) __ret = (inc); \
16415 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16416 index 59c6c40..5e0b22c 100644
16417 --- a/arch/x86/include/asm/compat.h
16418 +++ b/arch/x86/include/asm/compat.h
16419 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16420 typedef u32 compat_uint_t;
16421 typedef u32 compat_ulong_t;
16422 typedef u64 __attribute__((aligned(4))) compat_u64;
16423 -typedef u32 compat_uptr_t;
16424 +typedef u32 __user compat_uptr_t;
16425
16426 struct compat_timespec {
16427 compat_time_t tv_sec;
16428 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16429 index 5f12968..a383517 100644
16430 --- a/arch/x86/include/asm/cpufeature.h
16431 +++ b/arch/x86/include/asm/cpufeature.h
16432 @@ -203,7 +203,7 @@
16433 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16434 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16435 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16436 -
16437 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16438
16439 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16440 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16441 @@ -211,7 +211,7 @@
16442 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16443 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16444 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16445 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16446 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16447 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16448 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16449 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16450 @@ -358,6 +358,7 @@ extern const char * const x86_power_flags[32];
16451 #undef cpu_has_centaur_mcr
16452 #define cpu_has_centaur_mcr 0
16453
16454 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16455 #endif /* CONFIG_X86_64 */
16456
16457 #if __GNUC__ >= 4
16458 @@ -410,7 +411,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16459
16460 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16461 t_warn:
16462 - warn_pre_alternatives();
16463 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16464 + warn_pre_alternatives();
16465 return false;
16466 #endif
16467
16468 @@ -430,7 +432,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16469 ".section .discard,\"aw\",@progbits\n"
16470 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16471 ".previous\n"
16472 - ".section .altinstr_replacement,\"ax\"\n"
16473 + ".section .altinstr_replacement,\"a\"\n"
16474 "3: movb $1,%0\n"
16475 "4:\n"
16476 ".previous\n"
16477 @@ -467,7 +469,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16478 " .byte 2b - 1b\n" /* src len */
16479 " .byte 4f - 3f\n" /* repl len */
16480 ".previous\n"
16481 - ".section .altinstr_replacement,\"ax\"\n"
16482 + ".section .altinstr_replacement,\"a\"\n"
16483 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16484 "4:\n"
16485 ".previous\n"
16486 @@ -500,7 +502,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16487 ".section .discard,\"aw\",@progbits\n"
16488 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16489 ".previous\n"
16490 - ".section .altinstr_replacement,\"ax\"\n"
16491 + ".section .altinstr_replacement,\"a\"\n"
16492 "3: movb $0,%0\n"
16493 "4:\n"
16494 ".previous\n"
16495 @@ -514,7 +516,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16496 ".section .discard,\"aw\",@progbits\n"
16497 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16498 ".previous\n"
16499 - ".section .altinstr_replacement,\"ax\"\n"
16500 + ".section .altinstr_replacement,\"a\"\n"
16501 "5: movb $1,%0\n"
16502 "6:\n"
16503 ".previous\n"
16504 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16505 index 50d033a..37deb26 100644
16506 --- a/arch/x86/include/asm/desc.h
16507 +++ b/arch/x86/include/asm/desc.h
16508 @@ -4,6 +4,7 @@
16509 #include <asm/desc_defs.h>
16510 #include <asm/ldt.h>
16511 #include <asm/mmu.h>
16512 +#include <asm/pgtable.h>
16513
16514 #include <linux/smp.h>
16515 #include <linux/percpu.h>
16516 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16517
16518 desc->type = (info->read_exec_only ^ 1) << 1;
16519 desc->type |= info->contents << 2;
16520 + desc->type |= info->seg_not_present ^ 1;
16521
16522 desc->s = 1;
16523 desc->dpl = 0x3;
16524 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16525 }
16526
16527 extern struct desc_ptr idt_descr;
16528 -extern gate_desc idt_table[];
16529 -extern struct desc_ptr debug_idt_descr;
16530 -extern gate_desc debug_idt_table[];
16531 -
16532 -struct gdt_page {
16533 - struct desc_struct gdt[GDT_ENTRIES];
16534 -} __attribute__((aligned(PAGE_SIZE)));
16535 -
16536 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16537 +extern gate_desc idt_table[IDT_ENTRIES];
16538 +extern const struct desc_ptr debug_idt_descr;
16539 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16540
16541 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16542 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16543 {
16544 - return per_cpu(gdt_page, cpu).gdt;
16545 + return cpu_gdt_table[cpu];
16546 }
16547
16548 #ifdef CONFIG_X86_64
16549 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16550 unsigned long base, unsigned dpl, unsigned flags,
16551 unsigned short seg)
16552 {
16553 - gate->a = (seg << 16) | (base & 0xffff);
16554 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16555 + gate->gate.offset_low = base;
16556 + gate->gate.seg = seg;
16557 + gate->gate.reserved = 0;
16558 + gate->gate.type = type;
16559 + gate->gate.s = 0;
16560 + gate->gate.dpl = dpl;
16561 + gate->gate.p = 1;
16562 + gate->gate.offset_high = base >> 16;
16563 }
16564
16565 #endif
16566 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16567
16568 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16569 {
16570 + pax_open_kernel();
16571 memcpy(&idt[entry], gate, sizeof(*gate));
16572 + pax_close_kernel();
16573 }
16574
16575 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16576 {
16577 + pax_open_kernel();
16578 memcpy(&ldt[entry], desc, 8);
16579 + pax_close_kernel();
16580 }
16581
16582 static inline void
16583 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16584 default: size = sizeof(*gdt); break;
16585 }
16586
16587 + pax_open_kernel();
16588 memcpy(&gdt[entry], desc, size);
16589 + pax_close_kernel();
16590 }
16591
16592 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16593 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16594
16595 static inline void native_load_tr_desc(void)
16596 {
16597 + pax_open_kernel();
16598 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16599 + pax_close_kernel();
16600 }
16601
16602 static inline void native_load_gdt(const struct desc_ptr *dtr)
16603 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16604 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16605 unsigned int i;
16606
16607 + pax_open_kernel();
16608 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16609 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16610 + pax_close_kernel();
16611 }
16612
16613 #define _LDT_empty(info) \
16614 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16615 preempt_enable();
16616 }
16617
16618 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16619 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16620 {
16621 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16622 }
16623 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16624 }
16625
16626 #ifdef CONFIG_X86_64
16627 -static inline void set_nmi_gate(int gate, void *addr)
16628 +static inline void set_nmi_gate(int gate, const void *addr)
16629 {
16630 gate_desc s;
16631
16632 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16633 #endif
16634
16635 #ifdef CONFIG_TRACING
16636 -extern struct desc_ptr trace_idt_descr;
16637 -extern gate_desc trace_idt_table[];
16638 +extern const struct desc_ptr trace_idt_descr;
16639 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16640 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16641 {
16642 write_idt_entry(trace_idt_table, entry, gate);
16643 }
16644
16645 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16646 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16647 unsigned dpl, unsigned ist, unsigned seg)
16648 {
16649 gate_desc s;
16650 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16651 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16652 #endif
16653
16654 -static inline void _set_gate(int gate, unsigned type, void *addr,
16655 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16656 unsigned dpl, unsigned ist, unsigned seg)
16657 {
16658 gate_desc s;
16659 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16660 #define set_intr_gate(n, addr) \
16661 do { \
16662 BUG_ON((unsigned)n > 0xFF); \
16663 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16664 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16665 __KERNEL_CS); \
16666 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16667 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16668 0, 0, __KERNEL_CS); \
16669 } while (0)
16670
16671 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16672 /*
16673 * This routine sets up an interrupt gate at directory privilege level 3.
16674 */
16675 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16676 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16677 {
16678 BUG_ON((unsigned)n > 0xFF);
16679 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16680 }
16681
16682 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16683 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16684 {
16685 BUG_ON((unsigned)n > 0xFF);
16686 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16687 }
16688
16689 -static inline void set_trap_gate(unsigned int n, void *addr)
16690 +static inline void set_trap_gate(unsigned int n, const void *addr)
16691 {
16692 BUG_ON((unsigned)n > 0xFF);
16693 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16694 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16695 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16696 {
16697 BUG_ON((unsigned)n > 0xFF);
16698 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16699 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16700 }
16701
16702 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16703 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16704 {
16705 BUG_ON((unsigned)n > 0xFF);
16706 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16707 }
16708
16709 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16710 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16711 {
16712 BUG_ON((unsigned)n > 0xFF);
16713 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16714 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16715 else
16716 load_idt((const struct desc_ptr *)&idt_descr);
16717 }
16718 +
16719 +#ifdef CONFIG_X86_32
16720 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16721 +{
16722 + struct desc_struct d;
16723 +
16724 + if (likely(limit))
16725 + limit = (limit - 1UL) >> PAGE_SHIFT;
16726 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16727 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16728 +}
16729 +#endif
16730 +
16731 #endif /* _ASM_X86_DESC_H */
16732 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16733 index 278441f..b95a174 100644
16734 --- a/arch/x86/include/asm/desc_defs.h
16735 +++ b/arch/x86/include/asm/desc_defs.h
16736 @@ -31,6 +31,12 @@ struct desc_struct {
16737 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16738 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16739 };
16740 + struct {
16741 + u16 offset_low;
16742 + u16 seg;
16743 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16744 + unsigned offset_high: 16;
16745 + } gate;
16746 };
16747 } __attribute__((packed));
16748
16749 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16750 index ced283a..ffe04cc 100644
16751 --- a/arch/x86/include/asm/div64.h
16752 +++ b/arch/x86/include/asm/div64.h
16753 @@ -39,7 +39,7 @@
16754 __mod; \
16755 })
16756
16757 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16758 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16759 {
16760 union {
16761 u64 v64;
16762 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16763 index 9c999c1..3860cb8 100644
16764 --- a/arch/x86/include/asm/elf.h
16765 +++ b/arch/x86/include/asm/elf.h
16766 @@ -243,7 +243,25 @@ extern int force_personality32;
16767 the loader. We need to make sure that it is out of the way of the program
16768 that it will "exec", and that there is sufficient room for the brk. */
16769
16770 +#ifdef CONFIG_PAX_SEGMEXEC
16771 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16772 +#else
16773 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16774 +#endif
16775 +
16776 +#ifdef CONFIG_PAX_ASLR
16777 +#ifdef CONFIG_X86_32
16778 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16779 +
16780 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16781 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16782 +#else
16783 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16784 +
16785 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16786 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16787 +#endif
16788 +#endif
16789
16790 /* This yields a mask that user programs can use to figure out what
16791 instruction set this CPU supports. This could be done in user space,
16792 @@ -296,16 +314,12 @@ do { \
16793
16794 #define ARCH_DLINFO \
16795 do { \
16796 - if (vdso_enabled) \
16797 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16798 - (unsigned long)current->mm->context.vdso); \
16799 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16800 } while (0)
16801
16802 #define ARCH_DLINFO_X32 \
16803 do { \
16804 - if (vdso_enabled) \
16805 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16806 - (unsigned long)current->mm->context.vdso); \
16807 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16808 } while (0)
16809
16810 #define AT_SYSINFO 32
16811 @@ -320,7 +334,7 @@ else \
16812
16813 #endif /* !CONFIG_X86_32 */
16814
16815 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16816 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16817
16818 #define VDSO_ENTRY \
16819 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16820 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16821 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16822 #define compat_arch_setup_additional_pages syscall32_setup_pages
16823
16824 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16825 -#define arch_randomize_brk arch_randomize_brk
16826 -
16827 /*
16828 * True on X86_32 or when emulating IA32 on X86_64
16829 */
16830 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16831 index 77a99ac..39ff7f5 100644
16832 --- a/arch/x86/include/asm/emergency-restart.h
16833 +++ b/arch/x86/include/asm/emergency-restart.h
16834 @@ -1,6 +1,6 @@
16835 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16836 #define _ASM_X86_EMERGENCY_RESTART_H
16837
16838 -extern void machine_emergency_restart(void);
16839 +extern void machine_emergency_restart(void) __noreturn;
16840
16841 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16842 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16843 index d3d7469..677ef72 100644
16844 --- a/arch/x86/include/asm/floppy.h
16845 +++ b/arch/x86/include/asm/floppy.h
16846 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16847 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16848 } fd_routine[] = {
16849 {
16850 - request_dma,
16851 - free_dma,
16852 - get_dma_residue,
16853 - dma_mem_alloc,
16854 - hard_dma_setup
16855 + ._request_dma = request_dma,
16856 + ._free_dma = free_dma,
16857 + ._get_dma_residue = get_dma_residue,
16858 + ._dma_mem_alloc = dma_mem_alloc,
16859 + ._dma_setup = hard_dma_setup
16860 },
16861 {
16862 - vdma_request_dma,
16863 - vdma_nop,
16864 - vdma_get_dma_residue,
16865 - vdma_mem_alloc,
16866 - vdma_dma_setup
16867 + ._request_dma = vdma_request_dma,
16868 + ._free_dma = vdma_nop,
16869 + ._get_dma_residue = vdma_get_dma_residue,
16870 + ._dma_mem_alloc = vdma_mem_alloc,
16871 + ._dma_setup = vdma_dma_setup
16872 }
16873 };
16874
16875 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16876 index cea1c76..6c0d79b 100644
16877 --- a/arch/x86/include/asm/fpu-internal.h
16878 +++ b/arch/x86/include/asm/fpu-internal.h
16879 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16880 #define user_insn(insn, output, input...) \
16881 ({ \
16882 int err; \
16883 + pax_open_userland(); \
16884 asm volatile(ASM_STAC "\n" \
16885 - "1:" #insn "\n\t" \
16886 + "1:" \
16887 + __copyuser_seg \
16888 + #insn "\n\t" \
16889 "2: " ASM_CLAC "\n" \
16890 ".section .fixup,\"ax\"\n" \
16891 "3: movl $-1,%[err]\n" \
16892 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16893 _ASM_EXTABLE(1b, 3b) \
16894 : [err] "=r" (err), output \
16895 : "0"(0), input); \
16896 + pax_close_userland(); \
16897 err; \
16898 })
16899
16900 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16901 "fnclex\n\t"
16902 "emms\n\t"
16903 "fildl %P[addr]" /* set F?P to defined value */
16904 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16905 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16906 }
16907
16908 return fpu_restore_checking(&tsk->thread.fpu);
16909 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16910 index b4c1f54..e290c08 100644
16911 --- a/arch/x86/include/asm/futex.h
16912 +++ b/arch/x86/include/asm/futex.h
16913 @@ -12,6 +12,7 @@
16914 #include <asm/smap.h>
16915
16916 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16917 + typecheck(u32 __user *, uaddr); \
16918 asm volatile("\t" ASM_STAC "\n" \
16919 "1:\t" insn "\n" \
16920 "2:\t" ASM_CLAC "\n" \
16921 @@ -20,15 +21,16 @@
16922 "\tjmp\t2b\n" \
16923 "\t.previous\n" \
16924 _ASM_EXTABLE(1b, 3b) \
16925 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16926 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16927 : "i" (-EFAULT), "0" (oparg), "1" (0))
16928
16929 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16930 + typecheck(u32 __user *, uaddr); \
16931 asm volatile("\t" ASM_STAC "\n" \
16932 "1:\tmovl %2, %0\n" \
16933 "\tmovl\t%0, %3\n" \
16934 "\t" insn "\n" \
16935 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16936 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16937 "\tjnz\t1b\n" \
16938 "3:\t" ASM_CLAC "\n" \
16939 "\t.section .fixup,\"ax\"\n" \
16940 @@ -38,7 +40,7 @@
16941 _ASM_EXTABLE(1b, 4b) \
16942 _ASM_EXTABLE(2b, 4b) \
16943 : "=&a" (oldval), "=&r" (ret), \
16944 - "+m" (*uaddr), "=&r" (tem) \
16945 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16946 : "r" (oparg), "i" (-EFAULT), "1" (0))
16947
16948 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16949 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16950
16951 pagefault_disable();
16952
16953 + pax_open_userland();
16954 switch (op) {
16955 case FUTEX_OP_SET:
16956 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16957 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16958 break;
16959 case FUTEX_OP_ADD:
16960 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16961 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16962 uaddr, oparg);
16963 break;
16964 case FUTEX_OP_OR:
16965 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16966 default:
16967 ret = -ENOSYS;
16968 }
16969 + pax_close_userland();
16970
16971 pagefault_enable();
16972
16973 diff --git a/arch/x86/include/asm/hugetlb.h b/arch/x86/include/asm/hugetlb.h
16974 index a809121..68c0539 100644
16975 --- a/arch/x86/include/asm/hugetlb.h
16976 +++ b/arch/x86/include/asm/hugetlb.h
16977 @@ -52,6 +52,7 @@ static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
16978 static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
16979 unsigned long addr, pte_t *ptep)
16980 {
16981 + ptep_clear_flush(vma, addr, ptep);
16982 }
16983
16984 static inline int huge_pte_none(pte_t pte)
16985 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16986 index 67d69b8..50e4b77 100644
16987 --- a/arch/x86/include/asm/hw_irq.h
16988 +++ b/arch/x86/include/asm/hw_irq.h
16989 @@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16990 extern void enable_IO_APIC(void);
16991
16992 /* Statistics */
16993 -extern atomic_t irq_err_count;
16994 -extern atomic_t irq_mis_count;
16995 +extern atomic_unchecked_t irq_err_count;
16996 +extern atomic_unchecked_t irq_mis_count;
16997
16998 /* EISA */
16999 extern void eisa_set_level_irq(unsigned int irq);
17000 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17001 index a203659..9889f1c 100644
17002 --- a/arch/x86/include/asm/i8259.h
17003 +++ b/arch/x86/include/asm/i8259.h
17004 @@ -62,7 +62,7 @@ struct legacy_pic {
17005 void (*init)(int auto_eoi);
17006 int (*irq_pending)(unsigned int irq);
17007 void (*make_irq)(unsigned int irq);
17008 -};
17009 +} __do_const;
17010
17011 extern struct legacy_pic *legacy_pic;
17012 extern struct legacy_pic null_legacy_pic;
17013 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17014 index 91d9c69..dfae7d0 100644
17015 --- a/arch/x86/include/asm/io.h
17016 +++ b/arch/x86/include/asm/io.h
17017 @@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17018 "m" (*(volatile type __force *)addr) barrier); }
17019
17020 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17021 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17022 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17023 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17024 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17025
17026 build_mmio_read(__readb, "b", unsigned char, "=q", )
17027 -build_mmio_read(__readw, "w", unsigned short, "=r", )
17028 -build_mmio_read(__readl, "l", unsigned int, "=r", )
17029 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17030 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17031
17032 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17033 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17034 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17035 return ioremap_nocache(offset, size);
17036 }
17037
17038 -extern void iounmap(volatile void __iomem *addr);
17039 +extern void iounmap(const volatile void __iomem *addr);
17040
17041 extern void set_iounmap_nonlazy(void);
17042
17043 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
17044
17045 #include <linux/vmalloc.h>
17046
17047 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17048 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17049 +{
17050 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17051 +}
17052 +
17053 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17054 +{
17055 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17056 +}
17057 +
17058 /*
17059 * Convert a virtual cached pointer to an uncached pointer
17060 */
17061 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17062 index bba3cf8..06bc8da 100644
17063 --- a/arch/x86/include/asm/irqflags.h
17064 +++ b/arch/x86/include/asm/irqflags.h
17065 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17066 sti; \
17067 sysexit
17068
17069 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
17070 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17071 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
17072 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17073 +
17074 #else
17075 #define INTERRUPT_RETURN iret
17076 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17077 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17078 index 9454c16..e4100e3 100644
17079 --- a/arch/x86/include/asm/kprobes.h
17080 +++ b/arch/x86/include/asm/kprobes.h
17081 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17082 #define RELATIVEJUMP_SIZE 5
17083 #define RELATIVECALL_OPCODE 0xe8
17084 #define RELATIVE_ADDR_SIZE 4
17085 -#define MAX_STACK_SIZE 64
17086 -#define MIN_STACK_SIZE(ADDR) \
17087 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17088 - THREAD_SIZE - (unsigned long)(ADDR))) \
17089 - ? (MAX_STACK_SIZE) \
17090 - : (((unsigned long)current_thread_info()) + \
17091 - THREAD_SIZE - (unsigned long)(ADDR)))
17092 +#define MAX_STACK_SIZE 64UL
17093 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17094
17095 #define flush_insn_slot(p) do { } while (0)
17096
17097 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17098 index 4ad6560..75c7bdd 100644
17099 --- a/arch/x86/include/asm/local.h
17100 +++ b/arch/x86/include/asm/local.h
17101 @@ -10,33 +10,97 @@ typedef struct {
17102 atomic_long_t a;
17103 } local_t;
17104
17105 +typedef struct {
17106 + atomic_long_unchecked_t a;
17107 +} local_unchecked_t;
17108 +
17109 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17110
17111 #define local_read(l) atomic_long_read(&(l)->a)
17112 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17113 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17114 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17115
17116 static inline void local_inc(local_t *l)
17117 {
17118 - asm volatile(_ASM_INC "%0"
17119 + asm volatile(_ASM_INC "%0\n"
17120 +
17121 +#ifdef CONFIG_PAX_REFCOUNT
17122 + "jno 0f\n"
17123 + _ASM_DEC "%0\n"
17124 + "int $4\n0:\n"
17125 + _ASM_EXTABLE(0b, 0b)
17126 +#endif
17127 +
17128 + : "+m" (l->a.counter));
17129 +}
17130 +
17131 +static inline void local_inc_unchecked(local_unchecked_t *l)
17132 +{
17133 + asm volatile(_ASM_INC "%0\n"
17134 : "+m" (l->a.counter));
17135 }
17136
17137 static inline void local_dec(local_t *l)
17138 {
17139 - asm volatile(_ASM_DEC "%0"
17140 + asm volatile(_ASM_DEC "%0\n"
17141 +
17142 +#ifdef CONFIG_PAX_REFCOUNT
17143 + "jno 0f\n"
17144 + _ASM_INC "%0\n"
17145 + "int $4\n0:\n"
17146 + _ASM_EXTABLE(0b, 0b)
17147 +#endif
17148 +
17149 + : "+m" (l->a.counter));
17150 +}
17151 +
17152 +static inline void local_dec_unchecked(local_unchecked_t *l)
17153 +{
17154 + asm volatile(_ASM_DEC "%0\n"
17155 : "+m" (l->a.counter));
17156 }
17157
17158 static inline void local_add(long i, local_t *l)
17159 {
17160 - asm volatile(_ASM_ADD "%1,%0"
17161 + asm volatile(_ASM_ADD "%1,%0\n"
17162 +
17163 +#ifdef CONFIG_PAX_REFCOUNT
17164 + "jno 0f\n"
17165 + _ASM_SUB "%1,%0\n"
17166 + "int $4\n0:\n"
17167 + _ASM_EXTABLE(0b, 0b)
17168 +#endif
17169 +
17170 + : "+m" (l->a.counter)
17171 + : "ir" (i));
17172 +}
17173 +
17174 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
17175 +{
17176 + asm volatile(_ASM_ADD "%1,%0\n"
17177 : "+m" (l->a.counter)
17178 : "ir" (i));
17179 }
17180
17181 static inline void local_sub(long i, local_t *l)
17182 {
17183 - asm volatile(_ASM_SUB "%1,%0"
17184 + asm volatile(_ASM_SUB "%1,%0\n"
17185 +
17186 +#ifdef CONFIG_PAX_REFCOUNT
17187 + "jno 0f\n"
17188 + _ASM_ADD "%1,%0\n"
17189 + "int $4\n0:\n"
17190 + _ASM_EXTABLE(0b, 0b)
17191 +#endif
17192 +
17193 + : "+m" (l->a.counter)
17194 + : "ir" (i));
17195 +}
17196 +
17197 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17198 +{
17199 + asm volatile(_ASM_SUB "%1,%0\n"
17200 : "+m" (l->a.counter)
17201 : "ir" (i));
17202 }
17203 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17204 */
17205 static inline int local_sub_and_test(long i, local_t *l)
17206 {
17207 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17208 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17209 }
17210
17211 /**
17212 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17213 */
17214 static inline int local_dec_and_test(local_t *l)
17215 {
17216 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17217 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17218 }
17219
17220 /**
17221 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17222 */
17223 static inline int local_inc_and_test(local_t *l)
17224 {
17225 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17226 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17227 }
17228
17229 /**
17230 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17231 */
17232 static inline int local_add_negative(long i, local_t *l)
17233 {
17234 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17235 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17236 }
17237
17238 /**
17239 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17240 static inline long local_add_return(long i, local_t *l)
17241 {
17242 long __i = i;
17243 + asm volatile(_ASM_XADD "%0, %1\n"
17244 +
17245 +#ifdef CONFIG_PAX_REFCOUNT
17246 + "jno 0f\n"
17247 + _ASM_MOV "%0,%1\n"
17248 + "int $4\n0:\n"
17249 + _ASM_EXTABLE(0b, 0b)
17250 +#endif
17251 +
17252 + : "+r" (i), "+m" (l->a.counter)
17253 + : : "memory");
17254 + return i + __i;
17255 +}
17256 +
17257 +/**
17258 + * local_add_return_unchecked - add and return
17259 + * @i: integer value to add
17260 + * @l: pointer to type local_unchecked_t
17261 + *
17262 + * Atomically adds @i to @l and returns @i + @l
17263 + */
17264 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17265 +{
17266 + long __i = i;
17267 asm volatile(_ASM_XADD "%0, %1;"
17268 : "+r" (i), "+m" (l->a.counter)
17269 : : "memory");
17270 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17271
17272 #define local_cmpxchg(l, o, n) \
17273 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17274 +#define local_cmpxchg_unchecked(l, o, n) \
17275 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17276 /* Always has a lock prefix */
17277 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17278
17279 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17280 new file mode 100644
17281 index 0000000..2bfd3ba
17282 --- /dev/null
17283 +++ b/arch/x86/include/asm/mman.h
17284 @@ -0,0 +1,15 @@
17285 +#ifndef _X86_MMAN_H
17286 +#define _X86_MMAN_H
17287 +
17288 +#include <uapi/asm/mman.h>
17289 +
17290 +#ifdef __KERNEL__
17291 +#ifndef __ASSEMBLY__
17292 +#ifdef CONFIG_X86_32
17293 +#define arch_mmap_check i386_mmap_check
17294 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17295 +#endif
17296 +#endif
17297 +#endif
17298 +
17299 +#endif /* X86_MMAN_H */
17300 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17301 index 5f55e69..e20bfb1 100644
17302 --- a/arch/x86/include/asm/mmu.h
17303 +++ b/arch/x86/include/asm/mmu.h
17304 @@ -9,7 +9,7 @@
17305 * we put the segment information here.
17306 */
17307 typedef struct {
17308 - void *ldt;
17309 + struct desc_struct *ldt;
17310 int size;
17311
17312 #ifdef CONFIG_X86_64
17313 @@ -18,7 +18,19 @@ typedef struct {
17314 #endif
17315
17316 struct mutex lock;
17317 - void *vdso;
17318 + unsigned long vdso;
17319 +
17320 +#ifdef CONFIG_X86_32
17321 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17322 + unsigned long user_cs_base;
17323 + unsigned long user_cs_limit;
17324 +
17325 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17326 + cpumask_t cpu_user_cs_mask;
17327 +#endif
17328 +
17329 +#endif
17330 +#endif
17331 } mm_context_t;
17332
17333 #ifdef CONFIG_SMP
17334 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17335 index be12c53..4d24039 100644
17336 --- a/arch/x86/include/asm/mmu_context.h
17337 +++ b/arch/x86/include/asm/mmu_context.h
17338 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17339
17340 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17341 {
17342 +
17343 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17344 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17345 + unsigned int i;
17346 + pgd_t *pgd;
17347 +
17348 + pax_open_kernel();
17349 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17350 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17351 + set_pgd_batched(pgd+i, native_make_pgd(0));
17352 + pax_close_kernel();
17353 + }
17354 +#endif
17355 +
17356 #ifdef CONFIG_SMP
17357 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17358 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17359 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17360 struct task_struct *tsk)
17361 {
17362 unsigned cpu = smp_processor_id();
17363 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17364 + int tlbstate = TLBSTATE_OK;
17365 +#endif
17366
17367 if (likely(prev != next)) {
17368 #ifdef CONFIG_SMP
17369 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17370 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17371 +#endif
17372 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17373 this_cpu_write(cpu_tlbstate.active_mm, next);
17374 #endif
17375 cpumask_set_cpu(cpu, mm_cpumask(next));
17376
17377 /* Re-load page tables */
17378 +#ifdef CONFIG_PAX_PER_CPU_PGD
17379 + pax_open_kernel();
17380 +
17381 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17382 + if (static_cpu_has(X86_FEATURE_PCID))
17383 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17384 + else
17385 +#endif
17386 +
17387 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17388 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17389 + pax_close_kernel();
17390 + 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));
17391 +
17392 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17393 + if (static_cpu_has(X86_FEATURE_PCID)) {
17394 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17395 + u64 descriptor[2];
17396 + descriptor[0] = PCID_USER;
17397 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17398 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17399 + descriptor[0] = PCID_KERNEL;
17400 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17401 + }
17402 + } else {
17403 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17404 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17405 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17406 + else
17407 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17408 + }
17409 + } else
17410 +#endif
17411 +
17412 + load_cr3(get_cpu_pgd(cpu, kernel));
17413 +#else
17414 load_cr3(next->pgd);
17415 +#endif
17416
17417 /* Stop flush ipis for the previous mm */
17418 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17419 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17420 /* Load the LDT, if the LDT is different: */
17421 if (unlikely(prev->context.ldt != next->context.ldt))
17422 load_LDT_nolock(&next->context);
17423 +
17424 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17425 + if (!(__supported_pte_mask & _PAGE_NX)) {
17426 + smp_mb__before_clear_bit();
17427 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17428 + smp_mb__after_clear_bit();
17429 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17430 + }
17431 +#endif
17432 +
17433 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17434 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17435 + prev->context.user_cs_limit != next->context.user_cs_limit))
17436 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17437 +#ifdef CONFIG_SMP
17438 + else if (unlikely(tlbstate != TLBSTATE_OK))
17439 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17440 +#endif
17441 +#endif
17442 +
17443 }
17444 + else {
17445 +
17446 +#ifdef CONFIG_PAX_PER_CPU_PGD
17447 + pax_open_kernel();
17448 +
17449 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17450 + if (static_cpu_has(X86_FEATURE_PCID))
17451 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17452 + else
17453 +#endif
17454 +
17455 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17456 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17457 + pax_close_kernel();
17458 + 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));
17459 +
17460 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17461 + if (static_cpu_has(X86_FEATURE_PCID)) {
17462 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17463 + u64 descriptor[2];
17464 + descriptor[0] = PCID_USER;
17465 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17466 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17467 + descriptor[0] = PCID_KERNEL;
17468 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17469 + }
17470 + } else {
17471 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17472 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17473 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17474 + else
17475 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17476 + }
17477 + } else
17478 +#endif
17479 +
17480 + load_cr3(get_cpu_pgd(cpu, kernel));
17481 +#endif
17482 +
17483 #ifdef CONFIG_SMP
17484 - else {
17485 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17486 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17487
17488 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17489 * tlb flush IPI delivery. We must reload CR3
17490 * to make sure to use no freed page tables.
17491 */
17492 +
17493 +#ifndef CONFIG_PAX_PER_CPU_PGD
17494 load_cr3(next->pgd);
17495 +#endif
17496 +
17497 load_LDT_nolock(&next->context);
17498 +
17499 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17500 + if (!(__supported_pte_mask & _PAGE_NX))
17501 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17502 +#endif
17503 +
17504 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17505 +#ifdef CONFIG_PAX_PAGEEXEC
17506 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17507 +#endif
17508 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17509 +#endif
17510 +
17511 }
17512 +#endif
17513 }
17514 -#endif
17515 }
17516
17517 #define activate_mm(prev, next) \
17518 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17519 index e3b7819..b257c64 100644
17520 --- a/arch/x86/include/asm/module.h
17521 +++ b/arch/x86/include/asm/module.h
17522 @@ -5,6 +5,7 @@
17523
17524 #ifdef CONFIG_X86_64
17525 /* X86_64 does not define MODULE_PROC_FAMILY */
17526 +#define MODULE_PROC_FAMILY ""
17527 #elif defined CONFIG_M486
17528 #define MODULE_PROC_FAMILY "486 "
17529 #elif defined CONFIG_M586
17530 @@ -57,8 +58,20 @@
17531 #error unknown processor family
17532 #endif
17533
17534 -#ifdef CONFIG_X86_32
17535 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17536 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17537 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17538 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17539 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17540 +#else
17541 +#define MODULE_PAX_KERNEXEC ""
17542 #endif
17543
17544 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17545 +#define MODULE_PAX_UDEREF "UDEREF "
17546 +#else
17547 +#define MODULE_PAX_UDEREF ""
17548 +#endif
17549 +
17550 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17551 +
17552 #endif /* _ASM_X86_MODULE_H */
17553 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17554 index 86f9301..b365cda 100644
17555 --- a/arch/x86/include/asm/nmi.h
17556 +++ b/arch/x86/include/asm/nmi.h
17557 @@ -40,11 +40,11 @@ struct nmiaction {
17558 nmi_handler_t handler;
17559 unsigned long flags;
17560 const char *name;
17561 -};
17562 +} __do_const;
17563
17564 #define register_nmi_handler(t, fn, fg, n, init...) \
17565 ({ \
17566 - static struct nmiaction init fn##_na = { \
17567 + static const struct nmiaction init fn##_na = { \
17568 .handler = (fn), \
17569 .name = (n), \
17570 .flags = (fg), \
17571 @@ -52,7 +52,7 @@ struct nmiaction {
17572 __register_nmi_handler((t), &fn##_na); \
17573 })
17574
17575 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17576 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17577
17578 void unregister_nmi_handler(unsigned int, const char *);
17579
17580 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17581 index 775873d..de5f0304 100644
17582 --- a/arch/x86/include/asm/page.h
17583 +++ b/arch/x86/include/asm/page.h
17584 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17585 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17586
17587 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17588 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17589
17590 #define __boot_va(x) __va(x)
17591 #define __boot_pa(x) __pa(x)
17592 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17593 index 0f1ddee..e2fc3d1 100644
17594 --- a/arch/x86/include/asm/page_64.h
17595 +++ b/arch/x86/include/asm/page_64.h
17596 @@ -7,9 +7,9 @@
17597
17598 /* duplicated to the one in bootmem.h */
17599 extern unsigned long max_pfn;
17600 -extern unsigned long phys_base;
17601 +extern const unsigned long phys_base;
17602
17603 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17604 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17605 {
17606 unsigned long y = x - __START_KERNEL_map;
17607
17608 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17609 index cd6e1610..70f4418 100644
17610 --- a/arch/x86/include/asm/paravirt.h
17611 +++ b/arch/x86/include/asm/paravirt.h
17612 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17613 return (pmd_t) { ret };
17614 }
17615
17616 -static inline pmdval_t pmd_val(pmd_t pmd)
17617 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17618 {
17619 pmdval_t ret;
17620
17621 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17622 val);
17623 }
17624
17625 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17626 +{
17627 + pgdval_t val = native_pgd_val(pgd);
17628 +
17629 + if (sizeof(pgdval_t) > sizeof(long))
17630 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17631 + val, (u64)val >> 32);
17632 + else
17633 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17634 + val);
17635 +}
17636 +
17637 static inline void pgd_clear(pgd_t *pgdp)
17638 {
17639 set_pgd(pgdp, __pgd(0));
17640 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17641 pv_mmu_ops.set_fixmap(idx, phys, flags);
17642 }
17643
17644 +#ifdef CONFIG_PAX_KERNEXEC
17645 +static inline unsigned long pax_open_kernel(void)
17646 +{
17647 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17648 +}
17649 +
17650 +static inline unsigned long pax_close_kernel(void)
17651 +{
17652 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17653 +}
17654 +#else
17655 +static inline unsigned long pax_open_kernel(void) { return 0; }
17656 +static inline unsigned long pax_close_kernel(void) { return 0; }
17657 +#endif
17658 +
17659 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17660
17661 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17662 @@ -906,7 +933,7 @@ extern void default_banner(void);
17663
17664 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17665 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17666 -#define PARA_INDIRECT(addr) *%cs:addr
17667 +#define PARA_INDIRECT(addr) *%ss:addr
17668 #endif
17669
17670 #define INTERRUPT_RETURN \
17671 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17672 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17673 CLBR_NONE, \
17674 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17675 +
17676 +#define GET_CR0_INTO_RDI \
17677 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17678 + mov %rax,%rdi
17679 +
17680 +#define SET_RDI_INTO_CR0 \
17681 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17682 +
17683 +#define GET_CR3_INTO_RDI \
17684 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17685 + mov %rax,%rdi
17686 +
17687 +#define SET_RDI_INTO_CR3 \
17688 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17689 +
17690 #endif /* CONFIG_X86_32 */
17691
17692 #endif /* __ASSEMBLY__ */
17693 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17694 index 7549b8b..f0edfda 100644
17695 --- a/arch/x86/include/asm/paravirt_types.h
17696 +++ b/arch/x86/include/asm/paravirt_types.h
17697 @@ -84,7 +84,7 @@ struct pv_init_ops {
17698 */
17699 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17700 unsigned long addr, unsigned len);
17701 -};
17702 +} __no_const __no_randomize_layout;
17703
17704
17705 struct pv_lazy_ops {
17706 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17707 void (*enter)(void);
17708 void (*leave)(void);
17709 void (*flush)(void);
17710 -};
17711 +} __no_randomize_layout;
17712
17713 struct pv_time_ops {
17714 unsigned long long (*sched_clock)(void);
17715 unsigned long long (*steal_clock)(int cpu);
17716 unsigned long (*get_tsc_khz)(void);
17717 -};
17718 +} __no_const __no_randomize_layout;
17719
17720 struct pv_cpu_ops {
17721 /* hooks for various privileged instructions */
17722 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17723
17724 void (*start_context_switch)(struct task_struct *prev);
17725 void (*end_context_switch)(struct task_struct *next);
17726 -};
17727 +} __no_const __no_randomize_layout;
17728
17729 struct pv_irq_ops {
17730 /*
17731 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17732 #ifdef CONFIG_X86_64
17733 void (*adjust_exception_frame)(void);
17734 #endif
17735 -};
17736 +} __no_randomize_layout;
17737
17738 struct pv_apic_ops {
17739 #ifdef CONFIG_X86_LOCAL_APIC
17740 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17741 unsigned long start_eip,
17742 unsigned long start_esp);
17743 #endif
17744 -};
17745 +} __no_const __no_randomize_layout;
17746
17747 struct pv_mmu_ops {
17748 unsigned long (*read_cr2)(void);
17749 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17750 struct paravirt_callee_save make_pud;
17751
17752 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17753 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17754 #endif /* PAGETABLE_LEVELS == 4 */
17755 #endif /* PAGETABLE_LEVELS >= 3 */
17756
17757 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17758 an mfn. We can tell which is which from the index. */
17759 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17760 phys_addr_t phys, pgprot_t flags);
17761 -};
17762 +
17763 +#ifdef CONFIG_PAX_KERNEXEC
17764 + unsigned long (*pax_open_kernel)(void);
17765 + unsigned long (*pax_close_kernel)(void);
17766 +#endif
17767 +
17768 +} __no_randomize_layout;
17769
17770 struct arch_spinlock;
17771 #ifdef CONFIG_SMP
17772 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17773 struct pv_lock_ops {
17774 struct paravirt_callee_save lock_spinning;
17775 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17776 -};
17777 +} __no_randomize_layout;
17778
17779 /* This contains all the paravirt structures: we get a convenient
17780 * number for each function using the offset which we use to indicate
17781 - * what to patch. */
17782 + * what to patch.
17783 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17784 + */
17785 +
17786 struct paravirt_patch_template {
17787 struct pv_init_ops pv_init_ops;
17788 struct pv_time_ops pv_time_ops;
17789 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17790 struct pv_apic_ops pv_apic_ops;
17791 struct pv_mmu_ops pv_mmu_ops;
17792 struct pv_lock_ops pv_lock_ops;
17793 -};
17794 +} __no_randomize_layout;
17795
17796 extern struct pv_info pv_info;
17797 extern struct pv_init_ops pv_init_ops;
17798 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17799 index c4412e9..90e88c5 100644
17800 --- a/arch/x86/include/asm/pgalloc.h
17801 +++ b/arch/x86/include/asm/pgalloc.h
17802 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17803 pmd_t *pmd, pte_t *pte)
17804 {
17805 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17806 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17807 +}
17808 +
17809 +static inline void pmd_populate_user(struct mm_struct *mm,
17810 + pmd_t *pmd, pte_t *pte)
17811 +{
17812 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17813 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17814 }
17815
17816 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17817
17818 #ifdef CONFIG_X86_PAE
17819 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17820 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17821 +{
17822 + pud_populate(mm, pudp, pmd);
17823 +}
17824 #else /* !CONFIG_X86_PAE */
17825 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17826 {
17827 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17828 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17829 }
17830 +
17831 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17832 +{
17833 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17834 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17835 +}
17836 #endif /* CONFIG_X86_PAE */
17837
17838 #if PAGETABLE_LEVELS > 3
17839 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17840 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17841 }
17842
17843 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17844 +{
17845 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17846 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17847 +}
17848 +
17849 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17850 {
17851 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17852 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17853 index 0d193e2..bf59aeb 100644
17854 --- a/arch/x86/include/asm/pgtable-2level.h
17855 +++ b/arch/x86/include/asm/pgtable-2level.h
17856 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17857
17858 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17859 {
17860 + pax_open_kernel();
17861 *pmdp = pmd;
17862 + pax_close_kernel();
17863 }
17864
17865 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17866 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17867 index 81bb91b..9392125 100644
17868 --- a/arch/x86/include/asm/pgtable-3level.h
17869 +++ b/arch/x86/include/asm/pgtable-3level.h
17870 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17871
17872 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17873 {
17874 + pax_open_kernel();
17875 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17876 + pax_close_kernel();
17877 }
17878
17879 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17880 {
17881 + pax_open_kernel();
17882 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17883 + pax_close_kernel();
17884 }
17885
17886 /*
17887 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17888 index bbc8b12..f228861 100644
17889 --- a/arch/x86/include/asm/pgtable.h
17890 +++ b/arch/x86/include/asm/pgtable.h
17891 @@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17892
17893 #ifndef __PAGETABLE_PUD_FOLDED
17894 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17895 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17896 #define pgd_clear(pgd) native_pgd_clear(pgd)
17897 #endif
17898
17899 @@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17900
17901 #define arch_end_context_switch(prev) do {} while(0)
17902
17903 +#define pax_open_kernel() native_pax_open_kernel()
17904 +#define pax_close_kernel() native_pax_close_kernel()
17905 #endif /* CONFIG_PARAVIRT */
17906
17907 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17908 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17909 +
17910 +#ifdef CONFIG_PAX_KERNEXEC
17911 +static inline unsigned long native_pax_open_kernel(void)
17912 +{
17913 + unsigned long cr0;
17914 +
17915 + preempt_disable();
17916 + barrier();
17917 + cr0 = read_cr0() ^ X86_CR0_WP;
17918 + BUG_ON(cr0 & X86_CR0_WP);
17919 + write_cr0(cr0);
17920 + return cr0 ^ X86_CR0_WP;
17921 +}
17922 +
17923 +static inline unsigned long native_pax_close_kernel(void)
17924 +{
17925 + unsigned long cr0;
17926 +
17927 + cr0 = read_cr0() ^ X86_CR0_WP;
17928 + BUG_ON(!(cr0 & X86_CR0_WP));
17929 + write_cr0(cr0);
17930 + barrier();
17931 + preempt_enable_no_resched();
17932 + return cr0 ^ X86_CR0_WP;
17933 +}
17934 +#else
17935 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17936 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17937 +#endif
17938 +
17939 /*
17940 * The following only work if pte_present() is true.
17941 * Undefined behaviour if not..
17942 */
17943 +static inline int pte_user(pte_t pte)
17944 +{
17945 + return pte_val(pte) & _PAGE_USER;
17946 +}
17947 +
17948 static inline int pte_dirty(pte_t pte)
17949 {
17950 return pte_flags(pte) & _PAGE_DIRTY;
17951 @@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17952 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17953 }
17954
17955 +static inline unsigned long pgd_pfn(pgd_t pgd)
17956 +{
17957 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17958 +}
17959 +
17960 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17961
17962 static inline int pmd_large(pmd_t pte)
17963 @@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17964 return pte_clear_flags(pte, _PAGE_RW);
17965 }
17966
17967 +static inline pte_t pte_mkread(pte_t pte)
17968 +{
17969 + return __pte(pte_val(pte) | _PAGE_USER);
17970 +}
17971 +
17972 static inline pte_t pte_mkexec(pte_t pte)
17973 {
17974 - return pte_clear_flags(pte, _PAGE_NX);
17975 +#ifdef CONFIG_X86_PAE
17976 + if (__supported_pte_mask & _PAGE_NX)
17977 + return pte_clear_flags(pte, _PAGE_NX);
17978 + else
17979 +#endif
17980 + return pte_set_flags(pte, _PAGE_USER);
17981 +}
17982 +
17983 +static inline pte_t pte_exprotect(pte_t pte)
17984 +{
17985 +#ifdef CONFIG_X86_PAE
17986 + if (__supported_pte_mask & _PAGE_NX)
17987 + return pte_set_flags(pte, _PAGE_NX);
17988 + else
17989 +#endif
17990 + return pte_clear_flags(pte, _PAGE_USER);
17991 }
17992
17993 static inline pte_t pte_mkdirty(pte_t pte)
17994 @@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17995 #endif
17996
17997 #ifndef __ASSEMBLY__
17998 +
17999 +#ifdef CONFIG_PAX_PER_CPU_PGD
18000 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18001 +enum cpu_pgd_type {kernel = 0, user = 1};
18002 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18003 +{
18004 + return cpu_pgd[cpu][type];
18005 +}
18006 +#endif
18007 +
18008 #include <linux/mm_types.h>
18009 #include <linux/mmdebug.h>
18010 #include <linux/log2.h>
18011 @@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18012 * Currently stuck as a macro due to indirect forward reference to
18013 * linux/mmzone.h's __section_mem_map_addr() definition:
18014 */
18015 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18016 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18017
18018 /* Find an entry in the second-level page table.. */
18019 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18020 @@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18021 * Currently stuck as a macro due to indirect forward reference to
18022 * linux/mmzone.h's __section_mem_map_addr() definition:
18023 */
18024 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18025 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18026
18027 /* to find an entry in a page-table-directory. */
18028 static inline unsigned long pud_index(unsigned long address)
18029 @@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18030
18031 static inline int pgd_bad(pgd_t pgd)
18032 {
18033 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18034 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18035 }
18036
18037 static inline int pgd_none(pgd_t pgd)
18038 @@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
18039 * pgd_offset() returns a (pgd_t *)
18040 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18041 */
18042 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18043 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18044 +
18045 +#ifdef CONFIG_PAX_PER_CPU_PGD
18046 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18047 +#endif
18048 +
18049 /*
18050 * a shortcut which implies the use of the kernel's pgd, instead
18051 * of a process's
18052 @@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
18053 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18054 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18055
18056 +#ifdef CONFIG_X86_32
18057 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18058 +#else
18059 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18060 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18061 +
18062 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18063 +#ifdef __ASSEMBLY__
18064 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
18065 +#else
18066 +extern unsigned long pax_user_shadow_base;
18067 +extern pgdval_t clone_pgd_mask;
18068 +#endif
18069 +#endif
18070 +
18071 +#endif
18072 +
18073 #ifndef __ASSEMBLY__
18074
18075 extern int direct_gbpages;
18076 @@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18077 * dst and src can be on the same page, but the range must not overlap,
18078 * and must not cross a page boundary.
18079 */
18080 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18081 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18082 {
18083 - memcpy(dst, src, count * sizeof(pgd_t));
18084 + pax_open_kernel();
18085 + while (count--)
18086 + *dst++ = *src++;
18087 + pax_close_kernel();
18088 }
18089
18090 +#ifdef CONFIG_PAX_PER_CPU_PGD
18091 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18092 +#endif
18093 +
18094 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18095 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18096 +#else
18097 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18098 +#endif
18099 +
18100 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18101 static inline int page_level_shift(enum pg_level level)
18102 {
18103 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18104 index 9ee3221..b979c6b 100644
18105 --- a/arch/x86/include/asm/pgtable_32.h
18106 +++ b/arch/x86/include/asm/pgtable_32.h
18107 @@ -25,9 +25,6 @@
18108 struct mm_struct;
18109 struct vm_area_struct;
18110
18111 -extern pgd_t swapper_pg_dir[1024];
18112 -extern pgd_t initial_page_table[1024];
18113 -
18114 static inline void pgtable_cache_init(void) { }
18115 static inline void check_pgt_cache(void) { }
18116 void paging_init(void);
18117 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18118 # include <asm/pgtable-2level.h>
18119 #endif
18120
18121 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18122 +extern pgd_t initial_page_table[PTRS_PER_PGD];
18123 +#ifdef CONFIG_X86_PAE
18124 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18125 +#endif
18126 +
18127 #if defined(CONFIG_HIGHPTE)
18128 #define pte_offset_map(dir, address) \
18129 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18130 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18131 /* Clear a kernel PTE and flush it from the TLB */
18132 #define kpte_clear_flush(ptep, vaddr) \
18133 do { \
18134 + pax_open_kernel(); \
18135 pte_clear(&init_mm, (vaddr), (ptep)); \
18136 + pax_close_kernel(); \
18137 __flush_tlb_one((vaddr)); \
18138 } while (0)
18139
18140 #endif /* !__ASSEMBLY__ */
18141
18142 +#define HAVE_ARCH_UNMAPPED_AREA
18143 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18144 +
18145 /*
18146 * kern_addr_valid() is (1) for FLATMEM and (0) for
18147 * SPARSEMEM and DISCONTIGMEM
18148 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18149 index ed5903b..c7fe163 100644
18150 --- a/arch/x86/include/asm/pgtable_32_types.h
18151 +++ b/arch/x86/include/asm/pgtable_32_types.h
18152 @@ -8,7 +8,7 @@
18153 */
18154 #ifdef CONFIG_X86_PAE
18155 # include <asm/pgtable-3level_types.h>
18156 -# define PMD_SIZE (1UL << PMD_SHIFT)
18157 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18158 # define PMD_MASK (~(PMD_SIZE - 1))
18159 #else
18160 # include <asm/pgtable-2level_types.h>
18161 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18162 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18163 #endif
18164
18165 +#ifdef CONFIG_PAX_KERNEXEC
18166 +#ifndef __ASSEMBLY__
18167 +extern unsigned char MODULES_EXEC_VADDR[];
18168 +extern unsigned char MODULES_EXEC_END[];
18169 +#endif
18170 +#include <asm/boot.h>
18171 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18172 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18173 +#else
18174 +#define ktla_ktva(addr) (addr)
18175 +#define ktva_ktla(addr) (addr)
18176 +#endif
18177 +
18178 #define MODULES_VADDR VMALLOC_START
18179 #define MODULES_END VMALLOC_END
18180 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18181 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18182 index e22c1db..23a625a 100644
18183 --- a/arch/x86/include/asm/pgtable_64.h
18184 +++ b/arch/x86/include/asm/pgtable_64.h
18185 @@ -16,10 +16,14 @@
18186
18187 extern pud_t level3_kernel_pgt[512];
18188 extern pud_t level3_ident_pgt[512];
18189 +extern pud_t level3_vmalloc_start_pgt[512];
18190 +extern pud_t level3_vmalloc_end_pgt[512];
18191 +extern pud_t level3_vmemmap_pgt[512];
18192 +extern pud_t level2_vmemmap_pgt[512];
18193 extern pmd_t level2_kernel_pgt[512];
18194 extern pmd_t level2_fixmap_pgt[512];
18195 -extern pmd_t level2_ident_pgt[512];
18196 -extern pgd_t init_level4_pgt[];
18197 +extern pmd_t level2_ident_pgt[512*2];
18198 +extern pgd_t init_level4_pgt[512];
18199
18200 #define swapper_pg_dir init_level4_pgt
18201
18202 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18203
18204 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18205 {
18206 + pax_open_kernel();
18207 *pmdp = pmd;
18208 + pax_close_kernel();
18209 }
18210
18211 static inline void native_pmd_clear(pmd_t *pmd)
18212 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18213
18214 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18215 {
18216 + pax_open_kernel();
18217 *pudp = pud;
18218 + pax_close_kernel();
18219 }
18220
18221 static inline void native_pud_clear(pud_t *pud)
18222 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18223
18224 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18225 {
18226 + pax_open_kernel();
18227 + *pgdp = pgd;
18228 + pax_close_kernel();
18229 +}
18230 +
18231 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18232 +{
18233 *pgdp = pgd;
18234 }
18235
18236 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18237 index c883bf7..19970b3 100644
18238 --- a/arch/x86/include/asm/pgtable_64_types.h
18239 +++ b/arch/x86/include/asm/pgtable_64_types.h
18240 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
18241 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18242 #define MODULES_END _AC(0xffffffffff000000, UL)
18243 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18244 +#define MODULES_EXEC_VADDR MODULES_VADDR
18245 +#define MODULES_EXEC_END MODULES_END
18246 +
18247 +#define ktla_ktva(addr) (addr)
18248 +#define ktva_ktla(addr) (addr)
18249
18250 #define EARLY_DYNAMIC_PAGE_TABLES 64
18251
18252 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18253 index 94e40f1..ebd03e4 100644
18254 --- a/arch/x86/include/asm/pgtable_types.h
18255 +++ b/arch/x86/include/asm/pgtable_types.h
18256 @@ -16,13 +16,12 @@
18257 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18258 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18259 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18260 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18261 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18262 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18263 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18264 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18265 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18266 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18267 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18268 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18269 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18270 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18271
18272 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18273 @@ -40,7 +39,6 @@
18274 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18275 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18276 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18277 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18278 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18279 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18280 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18281 @@ -87,8 +85,10 @@
18282
18283 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18284 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18285 -#else
18286 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18287 #define _PAGE_NX (_AT(pteval_t, 0))
18288 +#else
18289 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18290 #endif
18291
18292 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18293 @@ -147,6 +147,9 @@
18294 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18295 _PAGE_ACCESSED)
18296
18297 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18298 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18299 +
18300 #define __PAGE_KERNEL_EXEC \
18301 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18302 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18303 @@ -157,7 +160,7 @@
18304 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18305 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18306 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18307 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18308 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18309 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18310 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18311 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18312 @@ -219,8 +222,8 @@
18313 * bits are combined, this will alow user to access the high address mapped
18314 * VDSO in the presence of CONFIG_COMPAT_VDSO
18315 */
18316 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18317 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
18318 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18319 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18320 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18321 #endif
18322
18323 @@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18324 {
18325 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18326 }
18327 +#endif
18328
18329 +#if PAGETABLE_LEVELS == 3
18330 +#include <asm-generic/pgtable-nopud.h>
18331 +#endif
18332 +
18333 +#if PAGETABLE_LEVELS == 2
18334 +#include <asm-generic/pgtable-nopmd.h>
18335 +#endif
18336 +
18337 +#ifndef __ASSEMBLY__
18338 #if PAGETABLE_LEVELS > 3
18339 typedef struct { pudval_t pud; } pud_t;
18340
18341 @@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18342 return pud.pud;
18343 }
18344 #else
18345 -#include <asm-generic/pgtable-nopud.h>
18346 -
18347 static inline pudval_t native_pud_val(pud_t pud)
18348 {
18349 return native_pgd_val(pud.pgd);
18350 @@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18351 return pmd.pmd;
18352 }
18353 #else
18354 -#include <asm-generic/pgtable-nopmd.h>
18355 -
18356 static inline pmdval_t native_pmd_val(pmd_t pmd)
18357 {
18358 return native_pgd_val(pmd.pud.pgd);
18359 @@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18360
18361 extern pteval_t __supported_pte_mask;
18362 extern void set_nx(void);
18363 -extern int nx_enabled;
18364
18365 #define pgprot_writecombine pgprot_writecombine
18366 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18367 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18368 index c8b0519..fd29e73 100644
18369 --- a/arch/x86/include/asm/preempt.h
18370 +++ b/arch/x86/include/asm/preempt.h
18371 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18372 */
18373 static __always_inline bool __preempt_count_dec_and_test(void)
18374 {
18375 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18376 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18377 }
18378
18379 /*
18380 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18381 index fdedd38..95c02c2 100644
18382 --- a/arch/x86/include/asm/processor.h
18383 +++ b/arch/x86/include/asm/processor.h
18384 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18385 /* Index into per_cpu list: */
18386 u16 cpu_index;
18387 u32 microcode;
18388 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18389 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18390
18391 #define X86_VENDOR_INTEL 0
18392 #define X86_VENDOR_CYRIX 1
18393 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18394 : "memory");
18395 }
18396
18397 +/* invpcid (%rdx),%rax */
18398 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18399 +
18400 +#define INVPCID_SINGLE_ADDRESS 0UL
18401 +#define INVPCID_SINGLE_CONTEXT 1UL
18402 +#define INVPCID_ALL_GLOBAL 2UL
18403 +#define INVPCID_ALL_MONGLOBAL 3UL
18404 +
18405 +#define PCID_KERNEL 0UL
18406 +#define PCID_USER 1UL
18407 +#define PCID_NOFLUSH (1UL << 63)
18408 +
18409 static inline void load_cr3(pgd_t *pgdir)
18410 {
18411 - write_cr3(__pa(pgdir));
18412 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18413 }
18414
18415 #ifdef CONFIG_X86_32
18416 @@ -283,7 +295,7 @@ struct tss_struct {
18417
18418 } ____cacheline_aligned;
18419
18420 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18421 +extern struct tss_struct init_tss[NR_CPUS];
18422
18423 /*
18424 * Save the original ist values for checking stack pointers during debugging
18425 @@ -470,6 +482,7 @@ struct thread_struct {
18426 unsigned short ds;
18427 unsigned short fsindex;
18428 unsigned short gsindex;
18429 + unsigned short ss;
18430 #endif
18431 #ifdef CONFIG_X86_32
18432 unsigned long ip;
18433 @@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
18434 extern unsigned long mmu_cr4_features;
18435 extern u32 *trampoline_cr4_features;
18436
18437 -static inline void set_in_cr4(unsigned long mask)
18438 -{
18439 - unsigned long cr4;
18440 -
18441 - mmu_cr4_features |= mask;
18442 - if (trampoline_cr4_features)
18443 - *trampoline_cr4_features = mmu_cr4_features;
18444 - cr4 = read_cr4();
18445 - cr4 |= mask;
18446 - write_cr4(cr4);
18447 -}
18448 -
18449 -static inline void clear_in_cr4(unsigned long mask)
18450 -{
18451 - unsigned long cr4;
18452 -
18453 - mmu_cr4_features &= ~mask;
18454 - if (trampoline_cr4_features)
18455 - *trampoline_cr4_features = mmu_cr4_features;
18456 - cr4 = read_cr4();
18457 - cr4 &= ~mask;
18458 - write_cr4(cr4);
18459 -}
18460 +extern void set_in_cr4(unsigned long mask);
18461 +extern void clear_in_cr4(unsigned long mask);
18462
18463 typedef struct {
18464 unsigned long seg;
18465 @@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
18466 */
18467 #define TASK_SIZE PAGE_OFFSET
18468 #define TASK_SIZE_MAX TASK_SIZE
18469 +
18470 +#ifdef CONFIG_PAX_SEGMEXEC
18471 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18472 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18473 +#else
18474 #define STACK_TOP TASK_SIZE
18475 -#define STACK_TOP_MAX STACK_TOP
18476 +#endif
18477 +
18478 +#define STACK_TOP_MAX TASK_SIZE
18479
18480 #define INIT_THREAD { \
18481 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18482 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18483 .vm86_info = NULL, \
18484 .sysenter_cs = __KERNEL_CS, \
18485 .io_bitmap_ptr = NULL, \
18486 @@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18487 */
18488 #define INIT_TSS { \
18489 .x86_tss = { \
18490 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18491 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18492 .ss0 = __KERNEL_DS, \
18493 .ss1 = __KERNEL_CS, \
18494 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18495 @@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18496 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18497
18498 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18499 -#define KSTK_TOP(info) \
18500 -({ \
18501 - unsigned long *__ptr = (unsigned long *)(info); \
18502 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18503 -})
18504 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18505
18506 /*
18507 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18508 @@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18509 #define task_pt_regs(task) \
18510 ({ \
18511 struct pt_regs *__regs__; \
18512 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18513 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18514 __regs__ - 1; \
18515 })
18516
18517 @@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18518 /*
18519 * User space process size. 47bits minus one guard page.
18520 */
18521 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18522 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18523
18524 /* This decides where the kernel will search for a free chunk of vm
18525 * space during mmap's.
18526 */
18527 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18528 - 0xc0000000 : 0xFFFFe000)
18529 + 0xc0000000 : 0xFFFFf000)
18530
18531 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18532 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18533 @@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18534 #define STACK_TOP_MAX TASK_SIZE_MAX
18535
18536 #define INIT_THREAD { \
18537 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18538 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18539 }
18540
18541 #define INIT_TSS { \
18542 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18543 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18544 }
18545
18546 /*
18547 @@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18548 */
18549 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18550
18551 +#ifdef CONFIG_PAX_SEGMEXEC
18552 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18553 +#endif
18554 +
18555 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18556
18557 /* Get/set a process' ability to use the timestamp counter instruction */
18558 @@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18559 return 0;
18560 }
18561
18562 -extern unsigned long arch_align_stack(unsigned long sp);
18563 +#define arch_align_stack(x) ((x) & ~0xfUL)
18564 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18565
18566 void default_idle(void);
18567 @@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18568 #define xen_set_default_idle 0
18569 #endif
18570
18571 -void stop_this_cpu(void *dummy);
18572 +void stop_this_cpu(void *dummy) __noreturn;
18573 void df_debug(struct pt_regs *regs, long error_code);
18574 #endif /* _ASM_X86_PROCESSOR_H */
18575 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18576 index 14fd6fd..6740420 100644
18577 --- a/arch/x86/include/asm/ptrace.h
18578 +++ b/arch/x86/include/asm/ptrace.h
18579 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18580 }
18581
18582 /*
18583 - * user_mode_vm(regs) determines whether a register set came from user mode.
18584 + * user_mode(regs) determines whether a register set came from user mode.
18585 * This is true if V8086 mode was enabled OR if the register set was from
18586 * protected mode with RPL-3 CS value. This tricky test checks that with
18587 * one comparison. Many places in the kernel can bypass this full check
18588 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18589 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18590 + * be used.
18591 */
18592 -static inline int user_mode(struct pt_regs *regs)
18593 +static inline int user_mode_novm(struct pt_regs *regs)
18594 {
18595 #ifdef CONFIG_X86_32
18596 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18597 #else
18598 - return !!(regs->cs & 3);
18599 + return !!(regs->cs & SEGMENT_RPL_MASK);
18600 #endif
18601 }
18602
18603 -static inline int user_mode_vm(struct pt_regs *regs)
18604 +static inline int user_mode(struct pt_regs *regs)
18605 {
18606 #ifdef CONFIG_X86_32
18607 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18608 USER_RPL;
18609 #else
18610 - return user_mode(regs);
18611 + return user_mode_novm(regs);
18612 #endif
18613 }
18614
18615 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18616 #ifdef CONFIG_X86_64
18617 static inline bool user_64bit_mode(struct pt_regs *regs)
18618 {
18619 + unsigned long cs = regs->cs & 0xffff;
18620 #ifndef CONFIG_PARAVIRT
18621 /*
18622 * On non-paravirt systems, this is the only long mode CPL 3
18623 * selector. We do not allow long mode selectors in the LDT.
18624 */
18625 - return regs->cs == __USER_CS;
18626 + return cs == __USER_CS;
18627 #else
18628 /* Headers are too twisted for this to go in paravirt.h. */
18629 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18630 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18631 #endif
18632 }
18633
18634 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18635 * Traps from the kernel do not save sp and ss.
18636 * Use the helper function to retrieve sp.
18637 */
18638 - if (offset == offsetof(struct pt_regs, sp) &&
18639 - regs->cs == __KERNEL_CS)
18640 - return kernel_stack_pointer(regs);
18641 + if (offset == offsetof(struct pt_regs, sp)) {
18642 + unsigned long cs = regs->cs & 0xffff;
18643 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18644 + return kernel_stack_pointer(regs);
18645 + }
18646 #endif
18647 return *(unsigned long *)((unsigned long)regs + offset);
18648 }
18649 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18650 index 9c6b890..5305f53 100644
18651 --- a/arch/x86/include/asm/realmode.h
18652 +++ b/arch/x86/include/asm/realmode.h
18653 @@ -22,16 +22,14 @@ struct real_mode_header {
18654 #endif
18655 /* APM/BIOS reboot */
18656 u32 machine_real_restart_asm;
18657 -#ifdef CONFIG_X86_64
18658 u32 machine_real_restart_seg;
18659 -#endif
18660 };
18661
18662 /* This must match data at trampoline_32/64.S */
18663 struct trampoline_header {
18664 #ifdef CONFIG_X86_32
18665 u32 start;
18666 - u16 gdt_pad;
18667 + u16 boot_cs;
18668 u16 gdt_limit;
18669 u32 gdt_base;
18670 #else
18671 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18672 index a82c4f1..ac45053 100644
18673 --- a/arch/x86/include/asm/reboot.h
18674 +++ b/arch/x86/include/asm/reboot.h
18675 @@ -6,13 +6,13 @@
18676 struct pt_regs;
18677
18678 struct machine_ops {
18679 - void (*restart)(char *cmd);
18680 - void (*halt)(void);
18681 - void (*power_off)(void);
18682 + void (* __noreturn restart)(char *cmd);
18683 + void (* __noreturn halt)(void);
18684 + void (* __noreturn power_off)(void);
18685 void (*shutdown)(void);
18686 void (*crash_shutdown)(struct pt_regs *);
18687 - void (*emergency_restart)(void);
18688 -};
18689 + void (* __noreturn emergency_restart)(void);
18690 +} __no_const;
18691
18692 extern struct machine_ops machine_ops;
18693
18694 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18695 index 8f7866a..e442f20 100644
18696 --- a/arch/x86/include/asm/rmwcc.h
18697 +++ b/arch/x86/include/asm/rmwcc.h
18698 @@ -3,7 +3,34 @@
18699
18700 #ifdef CC_HAVE_ASM_GOTO
18701
18702 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18703 +#ifdef CONFIG_PAX_REFCOUNT
18704 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18705 +do { \
18706 + asm_volatile_goto (fullop \
18707 + ";jno 0f\n" \
18708 + fullantiop \
18709 + ";int $4\n0:\n" \
18710 + _ASM_EXTABLE(0b, 0b) \
18711 + ";j" cc " %l[cc_label]" \
18712 + : : "m" (var), ## __VA_ARGS__ \
18713 + : "memory" : cc_label); \
18714 + return 0; \
18715 +cc_label: \
18716 + return 1; \
18717 +} while (0)
18718 +#else
18719 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18720 +do { \
18721 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18722 + : : "m" (var), ## __VA_ARGS__ \
18723 + : "memory" : cc_label); \
18724 + return 0; \
18725 +cc_label: \
18726 + return 1; \
18727 +} while (0)
18728 +#endif
18729 +
18730 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18731 do { \
18732 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18733 : : "m" (var), ## __VA_ARGS__ \
18734 @@ -13,15 +40,46 @@ cc_label: \
18735 return 1; \
18736 } while (0)
18737
18738 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18739 - __GEN_RMWcc(op " " arg0, var, cc)
18740 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18741 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18742
18743 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18744 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18745 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18746 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18747 +
18748 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18749 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18750 +
18751 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18752 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18753
18754 #else /* !CC_HAVE_ASM_GOTO */
18755
18756 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18757 +#ifdef CONFIG_PAX_REFCOUNT
18758 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18759 +do { \
18760 + char c; \
18761 + asm volatile (fullop \
18762 + ";jno 0f\n" \
18763 + fullantiop \
18764 + ";int $4\n0:\n" \
18765 + _ASM_EXTABLE(0b, 0b) \
18766 + "; set" cc " %1" \
18767 + : "+m" (var), "=qm" (c) \
18768 + : __VA_ARGS__ : "memory"); \
18769 + return c != 0; \
18770 +} while (0)
18771 +#else
18772 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18773 +do { \
18774 + char c; \
18775 + asm volatile (fullop "; set" cc " %1" \
18776 + : "+m" (var), "=qm" (c) \
18777 + : __VA_ARGS__ : "memory"); \
18778 + return c != 0; \
18779 +} while (0)
18780 +#endif
18781 +
18782 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18783 do { \
18784 char c; \
18785 asm volatile (fullop "; set" cc " %1" \
18786 @@ -30,11 +88,17 @@ do { \
18787 return c != 0; \
18788 } while (0)
18789
18790 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18791 - __GEN_RMWcc(op " " arg0, var, cc)
18792 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18793 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18794 +
18795 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18796 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18797 +
18798 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18799 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18800
18801 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18802 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18803 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18804 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18805
18806 #endif /* CC_HAVE_ASM_GOTO */
18807
18808 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18809 index cad82c9..2e5c5c1 100644
18810 --- a/arch/x86/include/asm/rwsem.h
18811 +++ b/arch/x86/include/asm/rwsem.h
18812 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18813 {
18814 asm volatile("# beginning down_read\n\t"
18815 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18816 +
18817 +#ifdef CONFIG_PAX_REFCOUNT
18818 + "jno 0f\n"
18819 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18820 + "int $4\n0:\n"
18821 + _ASM_EXTABLE(0b, 0b)
18822 +#endif
18823 +
18824 /* adds 0x00000001 */
18825 " jns 1f\n"
18826 " call call_rwsem_down_read_failed\n"
18827 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18828 "1:\n\t"
18829 " mov %1,%2\n\t"
18830 " add %3,%2\n\t"
18831 +
18832 +#ifdef CONFIG_PAX_REFCOUNT
18833 + "jno 0f\n"
18834 + "sub %3,%2\n"
18835 + "int $4\n0:\n"
18836 + _ASM_EXTABLE(0b, 0b)
18837 +#endif
18838 +
18839 " jle 2f\n\t"
18840 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18841 " jnz 1b\n\t"
18842 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18843 long tmp;
18844 asm volatile("# beginning down_write\n\t"
18845 LOCK_PREFIX " xadd %1,(%2)\n\t"
18846 +
18847 +#ifdef CONFIG_PAX_REFCOUNT
18848 + "jno 0f\n"
18849 + "mov %1,(%2)\n"
18850 + "int $4\n0:\n"
18851 + _ASM_EXTABLE(0b, 0b)
18852 +#endif
18853 +
18854 /* adds 0xffff0001, returns the old value */
18855 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18856 /* was the active mask 0 before? */
18857 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18858 long tmp;
18859 asm volatile("# beginning __up_read\n\t"
18860 LOCK_PREFIX " xadd %1,(%2)\n\t"
18861 +
18862 +#ifdef CONFIG_PAX_REFCOUNT
18863 + "jno 0f\n"
18864 + "mov %1,(%2)\n"
18865 + "int $4\n0:\n"
18866 + _ASM_EXTABLE(0b, 0b)
18867 +#endif
18868 +
18869 /* subtracts 1, returns the old value */
18870 " jns 1f\n\t"
18871 " call call_rwsem_wake\n" /* expects old value in %edx */
18872 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18873 long tmp;
18874 asm volatile("# beginning __up_write\n\t"
18875 LOCK_PREFIX " xadd %1,(%2)\n\t"
18876 +
18877 +#ifdef CONFIG_PAX_REFCOUNT
18878 + "jno 0f\n"
18879 + "mov %1,(%2)\n"
18880 + "int $4\n0:\n"
18881 + _ASM_EXTABLE(0b, 0b)
18882 +#endif
18883 +
18884 /* subtracts 0xffff0001, returns the old value */
18885 " jns 1f\n\t"
18886 " call call_rwsem_wake\n" /* expects old value in %edx */
18887 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18888 {
18889 asm volatile("# beginning __downgrade_write\n\t"
18890 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18891 +
18892 +#ifdef CONFIG_PAX_REFCOUNT
18893 + "jno 0f\n"
18894 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18895 + "int $4\n0:\n"
18896 + _ASM_EXTABLE(0b, 0b)
18897 +#endif
18898 +
18899 /*
18900 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18901 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18902 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18903 */
18904 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18905 {
18906 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18907 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18908 +
18909 +#ifdef CONFIG_PAX_REFCOUNT
18910 + "jno 0f\n"
18911 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18912 + "int $4\n0:\n"
18913 + _ASM_EXTABLE(0b, 0b)
18914 +#endif
18915 +
18916 : "+m" (sem->count)
18917 : "er" (delta));
18918 }
18919 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18920 */
18921 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18922 {
18923 - return delta + xadd(&sem->count, delta);
18924 + return delta + xadd_check_overflow(&sem->count, delta);
18925 }
18926
18927 #endif /* __KERNEL__ */
18928 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18929 index 6f1c3a8..7744f19 100644
18930 --- a/arch/x86/include/asm/segment.h
18931 +++ b/arch/x86/include/asm/segment.h
18932 @@ -64,10 +64,15 @@
18933 * 26 - ESPFIX small SS
18934 * 27 - per-cpu [ offset to per-cpu data area ]
18935 * 28 - stack_canary-20 [ for stack protector ]
18936 - * 29 - unused
18937 - * 30 - unused
18938 + * 29 - PCI BIOS CS
18939 + * 30 - PCI BIOS DS
18940 * 31 - TSS for double fault handler
18941 */
18942 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18943 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18944 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18945 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18946 +
18947 #define GDT_ENTRY_TLS_MIN 6
18948 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18949
18950 @@ -79,6 +84,8 @@
18951
18952 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18953
18954 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18955 +
18956 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18957
18958 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18959 @@ -104,6 +111,12 @@
18960 #define __KERNEL_STACK_CANARY 0
18961 #endif
18962
18963 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18964 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18965 +
18966 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18967 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18968 +
18969 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18970
18971 /*
18972 @@ -141,7 +154,7 @@
18973 */
18974
18975 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18976 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18977 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18978
18979
18980 #else
18981 @@ -165,6 +178,8 @@
18982 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18983 #define __USER32_DS __USER_DS
18984
18985 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18986 +
18987 #define GDT_ENTRY_TSS 8 /* needs two entries */
18988 #define GDT_ENTRY_LDT 10 /* needs two entries */
18989 #define GDT_ENTRY_TLS_MIN 12
18990 @@ -173,6 +188,8 @@
18991 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18992 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18993
18994 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18995 +
18996 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18997 #define FS_TLS 0
18998 #define GS_TLS 1
18999 @@ -180,12 +197,14 @@
19000 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19001 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19002
19003 -#define GDT_ENTRIES 16
19004 +#define GDT_ENTRIES 17
19005
19006 #endif
19007
19008 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19009 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19010 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19011 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19012 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19013 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19014 #ifndef CONFIG_PARAVIRT
19015 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19016 {
19017 unsigned long __limit;
19018 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19019 - return __limit + 1;
19020 + return __limit;
19021 }
19022
19023 #endif /* !__ASSEMBLY__ */
19024 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19025 index 8d3120f..352b440 100644
19026 --- a/arch/x86/include/asm/smap.h
19027 +++ b/arch/x86/include/asm/smap.h
19028 @@ -25,11 +25,40 @@
19029
19030 #include <asm/alternative-asm.h>
19031
19032 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19033 +#define ASM_PAX_OPEN_USERLAND \
19034 + 661: jmp 663f; \
19035 + .pushsection .altinstr_replacement, "a" ; \
19036 + 662: pushq %rax; nop; \
19037 + .popsection ; \
19038 + .pushsection .altinstructions, "a" ; \
19039 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19040 + .popsection ; \
19041 + call __pax_open_userland; \
19042 + popq %rax; \
19043 + 663:
19044 +
19045 +#define ASM_PAX_CLOSE_USERLAND \
19046 + 661: jmp 663f; \
19047 + .pushsection .altinstr_replacement, "a" ; \
19048 + 662: pushq %rax; nop; \
19049 + .popsection; \
19050 + .pushsection .altinstructions, "a" ; \
19051 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19052 + .popsection; \
19053 + call __pax_close_userland; \
19054 + popq %rax; \
19055 + 663:
19056 +#else
19057 +#define ASM_PAX_OPEN_USERLAND
19058 +#define ASM_PAX_CLOSE_USERLAND
19059 +#endif
19060 +
19061 #ifdef CONFIG_X86_SMAP
19062
19063 #define ASM_CLAC \
19064 661: ASM_NOP3 ; \
19065 - .pushsection .altinstr_replacement, "ax" ; \
19066 + .pushsection .altinstr_replacement, "a" ; \
19067 662: __ASM_CLAC ; \
19068 .popsection ; \
19069 .pushsection .altinstructions, "a" ; \
19070 @@ -38,7 +67,7 @@
19071
19072 #define ASM_STAC \
19073 661: ASM_NOP3 ; \
19074 - .pushsection .altinstr_replacement, "ax" ; \
19075 + .pushsection .altinstr_replacement, "a" ; \
19076 662: __ASM_STAC ; \
19077 .popsection ; \
19078 .pushsection .altinstructions, "a" ; \
19079 @@ -56,6 +85,37 @@
19080
19081 #include <asm/alternative.h>
19082
19083 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
19084 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19085 +
19086 +extern void __pax_open_userland(void);
19087 +static __always_inline unsigned long pax_open_userland(void)
19088 +{
19089 +
19090 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19091 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19092 + :
19093 + : [open] "i" (__pax_open_userland)
19094 + : "memory", "rax");
19095 +#endif
19096 +
19097 + return 0;
19098 +}
19099 +
19100 +extern void __pax_close_userland(void);
19101 +static __always_inline unsigned long pax_close_userland(void)
19102 +{
19103 +
19104 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19105 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19106 + :
19107 + : [close] "i" (__pax_close_userland)
19108 + : "memory", "rax");
19109 +#endif
19110 +
19111 + return 0;
19112 +}
19113 +
19114 #ifdef CONFIG_X86_SMAP
19115
19116 static __always_inline void clac(void)
19117 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19118 index 8cd27e0..7f05ec8 100644
19119 --- a/arch/x86/include/asm/smp.h
19120 +++ b/arch/x86/include/asm/smp.h
19121 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19122 /* cpus sharing the last level cache: */
19123 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19124 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19125 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19126 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19127
19128 static inline struct cpumask *cpu_sibling_mask(int cpu)
19129 {
19130 @@ -78,7 +78,7 @@ struct smp_ops {
19131
19132 void (*send_call_func_ipi)(const struct cpumask *mask);
19133 void (*send_call_func_single_ipi)(int cpu);
19134 -};
19135 +} __no_const;
19136
19137 /* Globals due to paravirt */
19138 extern void set_cpu_sibling_map(int cpu);
19139 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19140 extern int safe_smp_processor_id(void);
19141
19142 #elif defined(CONFIG_X86_64_SMP)
19143 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19144 -
19145 -#define stack_smp_processor_id() \
19146 -({ \
19147 - struct thread_info *ti; \
19148 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19149 - ti->cpu; \
19150 -})
19151 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19152 +#define stack_smp_processor_id() raw_smp_processor_id()
19153 #define safe_smp_processor_id() smp_processor_id()
19154
19155 #endif
19156 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19157 index 0f62f54..cb5d0dd 100644
19158 --- a/arch/x86/include/asm/spinlock.h
19159 +++ b/arch/x86/include/asm/spinlock.h
19160 @@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19161 static inline void arch_read_lock(arch_rwlock_t *rw)
19162 {
19163 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19164 +
19165 +#ifdef CONFIG_PAX_REFCOUNT
19166 + "jno 0f\n"
19167 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19168 + "int $4\n0:\n"
19169 + _ASM_EXTABLE(0b, 0b)
19170 +#endif
19171 +
19172 "jns 1f\n"
19173 "call __read_lock_failed\n\t"
19174 "1:\n"
19175 @@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19176 static inline void arch_write_lock(arch_rwlock_t *rw)
19177 {
19178 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19179 +
19180 +#ifdef CONFIG_PAX_REFCOUNT
19181 + "jno 0f\n"
19182 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19183 + "int $4\n0:\n"
19184 + _ASM_EXTABLE(0b, 0b)
19185 +#endif
19186 +
19187 "jz 1f\n"
19188 "call __write_lock_failed\n\t"
19189 "1:\n"
19190 @@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19191
19192 static inline void arch_read_unlock(arch_rwlock_t *rw)
19193 {
19194 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19195 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19196 +
19197 +#ifdef CONFIG_PAX_REFCOUNT
19198 + "jno 0f\n"
19199 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19200 + "int $4\n0:\n"
19201 + _ASM_EXTABLE(0b, 0b)
19202 +#endif
19203 +
19204 :"+m" (rw->lock) : : "memory");
19205 }
19206
19207 static inline void arch_write_unlock(arch_rwlock_t *rw)
19208 {
19209 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19210 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19211 +
19212 +#ifdef CONFIG_PAX_REFCOUNT
19213 + "jno 0f\n"
19214 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19215 + "int $4\n0:\n"
19216 + _ASM_EXTABLE(0b, 0b)
19217 +#endif
19218 +
19219 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19220 }
19221
19222 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19223 index 6a99859..03cb807 100644
19224 --- a/arch/x86/include/asm/stackprotector.h
19225 +++ b/arch/x86/include/asm/stackprotector.h
19226 @@ -47,7 +47,7 @@
19227 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19228 */
19229 #define GDT_STACK_CANARY_INIT \
19230 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19231 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19232
19233 /*
19234 * Initialize the stackprotector canary value.
19235 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19236
19237 static inline void load_stack_canary_segment(void)
19238 {
19239 -#ifdef CONFIG_X86_32
19240 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19241 asm volatile ("mov %0, %%gs" : : "r" (0));
19242 #endif
19243 }
19244 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19245 index 70bbe39..4ae2bd4 100644
19246 --- a/arch/x86/include/asm/stacktrace.h
19247 +++ b/arch/x86/include/asm/stacktrace.h
19248 @@ -11,28 +11,20 @@
19249
19250 extern int kstack_depth_to_print;
19251
19252 -struct thread_info;
19253 +struct task_struct;
19254 struct stacktrace_ops;
19255
19256 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19257 - unsigned long *stack,
19258 - unsigned long bp,
19259 - const struct stacktrace_ops *ops,
19260 - void *data,
19261 - unsigned long *end,
19262 - int *graph);
19263 +typedef unsigned long walk_stack_t(struct task_struct *task,
19264 + void *stack_start,
19265 + unsigned long *stack,
19266 + unsigned long bp,
19267 + const struct stacktrace_ops *ops,
19268 + void *data,
19269 + unsigned long *end,
19270 + int *graph);
19271
19272 -extern unsigned long
19273 -print_context_stack(struct thread_info *tinfo,
19274 - unsigned long *stack, unsigned long bp,
19275 - const struct stacktrace_ops *ops, void *data,
19276 - unsigned long *end, int *graph);
19277 -
19278 -extern unsigned long
19279 -print_context_stack_bp(struct thread_info *tinfo,
19280 - unsigned long *stack, unsigned long bp,
19281 - const struct stacktrace_ops *ops, void *data,
19282 - unsigned long *end, int *graph);
19283 +extern walk_stack_t print_context_stack;
19284 +extern walk_stack_t print_context_stack_bp;
19285
19286 /* Generic stack tracer with callbacks */
19287
19288 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19289 void (*address)(void *data, unsigned long address, int reliable);
19290 /* On negative return stop dumping */
19291 int (*stack)(void *data, char *name);
19292 - walk_stack_t walk_stack;
19293 + walk_stack_t *walk_stack;
19294 };
19295
19296 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19297 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19298 index d7f3b3b..3cc39f1 100644
19299 --- a/arch/x86/include/asm/switch_to.h
19300 +++ b/arch/x86/include/asm/switch_to.h
19301 @@ -108,7 +108,7 @@ do { \
19302 "call __switch_to\n\t" \
19303 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19304 __switch_canary \
19305 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19306 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19307 "movq %%rax,%%rdi\n\t" \
19308 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19309 "jnz ret_from_fork\n\t" \
19310 @@ -119,7 +119,7 @@ do { \
19311 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19312 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19313 [_tif_fork] "i" (_TIF_FORK), \
19314 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19315 + [thread_info] "m" (current_tinfo), \
19316 [current_task] "m" (current_task) \
19317 __switch_canary_iparam \
19318 : "memory", "cc" __EXTRA_CLOBBER)
19319 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19320 index e1940c0..ac50dd8 100644
19321 --- a/arch/x86/include/asm/thread_info.h
19322 +++ b/arch/x86/include/asm/thread_info.h
19323 @@ -10,6 +10,7 @@
19324 #include <linux/compiler.h>
19325 #include <asm/page.h>
19326 #include <asm/types.h>
19327 +#include <asm/percpu.h>
19328
19329 /*
19330 * low level task data that entry.S needs immediate access to
19331 @@ -23,7 +24,6 @@ struct exec_domain;
19332 #include <linux/atomic.h>
19333
19334 struct thread_info {
19335 - struct task_struct *task; /* main task structure */
19336 struct exec_domain *exec_domain; /* execution domain */
19337 __u32 flags; /* low level flags */
19338 __u32 status; /* thread synchronous flags */
19339 @@ -32,19 +32,13 @@ struct thread_info {
19340 mm_segment_t addr_limit;
19341 struct restart_block restart_block;
19342 void __user *sysenter_return;
19343 -#ifdef CONFIG_X86_32
19344 - unsigned long previous_esp; /* ESP of the previous stack in
19345 - case of nested (IRQ) stacks
19346 - */
19347 - __u8 supervisor_stack[0];
19348 -#endif
19349 + unsigned long lowest_stack;
19350 unsigned int sig_on_uaccess_error:1;
19351 unsigned int uaccess_err:1; /* uaccess failed */
19352 };
19353
19354 -#define INIT_THREAD_INFO(tsk) \
19355 +#define INIT_THREAD_INFO \
19356 { \
19357 - .task = &tsk, \
19358 .exec_domain = &default_exec_domain, \
19359 .flags = 0, \
19360 .cpu = 0, \
19361 @@ -55,7 +49,7 @@ struct thread_info {
19362 }, \
19363 }
19364
19365 -#define init_thread_info (init_thread_union.thread_info)
19366 +#define init_thread_info (init_thread_union.stack)
19367 #define init_stack (init_thread_union.stack)
19368
19369 #else /* !__ASSEMBLY__ */
19370 @@ -95,6 +89,7 @@ struct thread_info {
19371 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19372 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19373 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19374 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19375
19376 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19377 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19378 @@ -118,17 +113,18 @@ struct thread_info {
19379 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19380 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19381 #define _TIF_X32 (1 << TIF_X32)
19382 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19383
19384 /* work to do in syscall_trace_enter() */
19385 #define _TIF_WORK_SYSCALL_ENTRY \
19386 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19387 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19388 - _TIF_NOHZ)
19389 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19390
19391 /* work to do in syscall_trace_leave() */
19392 #define _TIF_WORK_SYSCALL_EXIT \
19393 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19394 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19395 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19396
19397 /* work to do on interrupt/exception return */
19398 #define _TIF_WORK_MASK \
19399 @@ -139,7 +135,7 @@ struct thread_info {
19400 /* work to do on any return to user space */
19401 #define _TIF_ALLWORK_MASK \
19402 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19403 - _TIF_NOHZ)
19404 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19405
19406 /* Only used for 64 bit */
19407 #define _TIF_DO_NOTIFY_MASK \
19408 @@ -153,6 +149,23 @@ struct thread_info {
19409 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19410 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19411
19412 +#ifdef __ASSEMBLY__
19413 +/* how to get the thread information struct from ASM */
19414 +#define GET_THREAD_INFO(reg) \
19415 + mov PER_CPU_VAR(current_tinfo), reg
19416 +
19417 +/* use this one if reg already contains %esp */
19418 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19419 +#else
19420 +/* how to get the thread information struct from C */
19421 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19422 +
19423 +static __always_inline struct thread_info *current_thread_info(void)
19424 +{
19425 + return this_cpu_read_stable(current_tinfo);
19426 +}
19427 +#endif
19428 +
19429 #ifdef CONFIG_X86_32
19430
19431 #define STACK_WARN (THREAD_SIZE/8)
19432 @@ -169,31 +182,10 @@ struct thread_info {
19433 sp; \
19434 })
19435
19436 -/* how to get the thread information struct from C */
19437 -static inline struct thread_info *current_thread_info(void)
19438 -{
19439 - return (struct thread_info *)
19440 - (current_stack_pointer & ~(THREAD_SIZE - 1));
19441 -}
19442 -
19443 -#else /* !__ASSEMBLY__ */
19444 -
19445 -/* how to get the thread information struct from ASM */
19446 -#define GET_THREAD_INFO(reg) \
19447 - movl $-THREAD_SIZE, reg; \
19448 - andl %esp, reg
19449 -
19450 -/* use this one if reg already contains %esp */
19451 -#define GET_THREAD_INFO_WITH_ESP(reg) \
19452 - andl $-THREAD_SIZE, reg
19453 -
19454 #endif
19455
19456 #else /* X86_32 */
19457
19458 -#include <asm/percpu.h>
19459 -#define KERNEL_STACK_OFFSET (5*8)
19460 -
19461 /*
19462 * macros/functions for gaining access to the thread information structure
19463 * preempt_count needs to be 1 initially, until the scheduler is functional.
19464 @@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
19465 #ifndef __ASSEMBLY__
19466 DECLARE_PER_CPU(unsigned long, kernel_stack);
19467
19468 -static inline struct thread_info *current_thread_info(void)
19469 -{
19470 - struct thread_info *ti;
19471 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19472 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19473 - return ti;
19474 -}
19475 -
19476 -#else /* !__ASSEMBLY__ */
19477 -
19478 -/* how to get the thread information struct from ASM */
19479 -#define GET_THREAD_INFO(reg) \
19480 - movq PER_CPU_VAR(kernel_stack),reg ; \
19481 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19482 -
19483 -/*
19484 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19485 - * a certain register (to be used in assembler memory operands).
19486 - */
19487 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19488 -
19489 +/* how to get the current stack pointer from C */
19490 +register unsigned long current_stack_pointer asm("rsp") __used;
19491 #endif
19492
19493 #endif /* !X86_32 */
19494 @@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19495 extern void arch_task_cache_init(void);
19496 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19497 extern void arch_release_task_struct(struct task_struct *tsk);
19498 +
19499 +#define __HAVE_THREAD_FUNCTIONS
19500 +#define task_thread_info(task) (&(task)->tinfo)
19501 +#define task_stack_page(task) ((task)->stack)
19502 +#define setup_thread_stack(p, org) do {} while (0)
19503 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19504 +
19505 #endif
19506 #endif /* _ASM_X86_THREAD_INFO_H */
19507 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19508 index 04905bf..49203ca 100644
19509 --- a/arch/x86/include/asm/tlbflush.h
19510 +++ b/arch/x86/include/asm/tlbflush.h
19511 @@ -17,18 +17,44 @@
19512
19513 static inline void __native_flush_tlb(void)
19514 {
19515 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19516 + u64 descriptor[2];
19517 +
19518 + descriptor[0] = PCID_KERNEL;
19519 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19520 + return;
19521 + }
19522 +
19523 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19524 + if (static_cpu_has(X86_FEATURE_PCID)) {
19525 + unsigned int cpu = raw_get_cpu();
19526 +
19527 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19528 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19529 + raw_put_cpu_no_resched();
19530 + return;
19531 + }
19532 +#endif
19533 +
19534 native_write_cr3(native_read_cr3());
19535 }
19536
19537 static inline void __native_flush_tlb_global_irq_disabled(void)
19538 {
19539 - unsigned long cr4;
19540 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19541 + u64 descriptor[2];
19542
19543 - cr4 = native_read_cr4();
19544 - /* clear PGE */
19545 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19546 - /* write old PGE again and flush TLBs */
19547 - native_write_cr4(cr4);
19548 + descriptor[0] = PCID_KERNEL;
19549 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19550 + } else {
19551 + unsigned long cr4;
19552 +
19553 + cr4 = native_read_cr4();
19554 + /* clear PGE */
19555 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19556 + /* write old PGE again and flush TLBs */
19557 + native_write_cr4(cr4);
19558 + }
19559 }
19560
19561 static inline void __native_flush_tlb_global(void)
19562 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19563
19564 static inline void __native_flush_tlb_single(unsigned long addr)
19565 {
19566 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19567 + u64 descriptor[2];
19568 +
19569 + descriptor[0] = PCID_KERNEL;
19570 + descriptor[1] = addr;
19571 +
19572 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19573 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19574 + if (addr < TASK_SIZE_MAX)
19575 + descriptor[1] += pax_user_shadow_base;
19576 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19577 + }
19578 +
19579 + descriptor[0] = PCID_USER;
19580 + descriptor[1] = addr;
19581 +#endif
19582 +
19583 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19584 + return;
19585 + }
19586 +
19587 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19588 + if (static_cpu_has(X86_FEATURE_PCID)) {
19589 + unsigned int cpu = raw_get_cpu();
19590 +
19591 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19592 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19593 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19594 + raw_put_cpu_no_resched();
19595 +
19596 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19597 + addr += pax_user_shadow_base;
19598 + }
19599 +#endif
19600 +
19601 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19602 }
19603
19604 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19605 index 0d592e0..f58a222 100644
19606 --- a/arch/x86/include/asm/uaccess.h
19607 +++ b/arch/x86/include/asm/uaccess.h
19608 @@ -7,6 +7,7 @@
19609 #include <linux/compiler.h>
19610 #include <linux/thread_info.h>
19611 #include <linux/string.h>
19612 +#include <linux/spinlock.h>
19613 #include <asm/asm.h>
19614 #include <asm/page.h>
19615 #include <asm/smap.h>
19616 @@ -29,7 +30,12 @@
19617
19618 #define get_ds() (KERNEL_DS)
19619 #define get_fs() (current_thread_info()->addr_limit)
19620 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19621 +void __set_fs(mm_segment_t x);
19622 +void set_fs(mm_segment_t x);
19623 +#else
19624 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19625 +#endif
19626
19627 #define segment_eq(a, b) ((a).seg == (b).seg)
19628
19629 @@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19630 * checks that the pointer is in the user space range - after calling
19631 * this function, memory access functions may still return -EFAULT.
19632 */
19633 -#define access_ok(type, addr, size) \
19634 - likely(!__range_not_ok(addr, size, user_addr_max()))
19635 +extern int _cond_resched(void);
19636 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19637 +#define access_ok(type, addr, size) \
19638 +({ \
19639 + long __size = size; \
19640 + unsigned long __addr = (unsigned long)addr; \
19641 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19642 + unsigned long __end_ao = __addr + __size - 1; \
19643 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19644 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19645 + while(__addr_ao <= __end_ao) { \
19646 + char __c_ao; \
19647 + __addr_ao += PAGE_SIZE; \
19648 + if (__size > PAGE_SIZE) \
19649 + _cond_resched(); \
19650 + if (__get_user(__c_ao, (char __user *)__addr)) \
19651 + break; \
19652 + if (type != VERIFY_WRITE) { \
19653 + __addr = __addr_ao; \
19654 + continue; \
19655 + } \
19656 + if (__put_user(__c_ao, (char __user *)__addr)) \
19657 + break; \
19658 + __addr = __addr_ao; \
19659 + } \
19660 + } \
19661 + __ret_ao; \
19662 +})
19663
19664 /*
19665 * The exception table consists of pairs of addresses relative to the
19666 @@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19667 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19668 __chk_user_ptr(ptr); \
19669 might_fault(); \
19670 + pax_open_userland(); \
19671 asm volatile("call __get_user_%P3" \
19672 : "=a" (__ret_gu), "=r" (__val_gu) \
19673 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19674 (x) = (__typeof__(*(ptr))) __val_gu; \
19675 + pax_close_userland(); \
19676 __ret_gu; \
19677 })
19678
19679 @@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19680 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19681 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19682
19683 -
19684 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19685 +#define __copyuser_seg "gs;"
19686 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19687 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19688 +#else
19689 +#define __copyuser_seg
19690 +#define __COPYUSER_SET_ES
19691 +#define __COPYUSER_RESTORE_ES
19692 +#endif
19693
19694 #ifdef CONFIG_X86_32
19695 #define __put_user_asm_u64(x, addr, err, errret) \
19696 asm volatile(ASM_STAC "\n" \
19697 - "1: movl %%eax,0(%2)\n" \
19698 - "2: movl %%edx,4(%2)\n" \
19699 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19700 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19701 "3: " ASM_CLAC "\n" \
19702 ".section .fixup,\"ax\"\n" \
19703 "4: movl %3,%0\n" \
19704 @@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19705
19706 #define __put_user_asm_ex_u64(x, addr) \
19707 asm volatile(ASM_STAC "\n" \
19708 - "1: movl %%eax,0(%1)\n" \
19709 - "2: movl %%edx,4(%1)\n" \
19710 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19711 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19712 "3: " ASM_CLAC "\n" \
19713 _ASM_EXTABLE_EX(1b, 2b) \
19714 _ASM_EXTABLE_EX(2b, 3b) \
19715 @@ -257,7 +299,8 @@ extern void __put_user_8(void);
19716 __typeof__(*(ptr)) __pu_val; \
19717 __chk_user_ptr(ptr); \
19718 might_fault(); \
19719 - __pu_val = x; \
19720 + __pu_val = (x); \
19721 + pax_open_userland(); \
19722 switch (sizeof(*(ptr))) { \
19723 case 1: \
19724 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19725 @@ -275,6 +318,7 @@ extern void __put_user_8(void);
19726 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19727 break; \
19728 } \
19729 + pax_close_userland(); \
19730 __ret_pu; \
19731 })
19732
19733 @@ -355,8 +399,10 @@ do { \
19734 } while (0)
19735
19736 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19737 +do { \
19738 + pax_open_userland(); \
19739 asm volatile(ASM_STAC "\n" \
19740 - "1: mov"itype" %2,%"rtype"1\n" \
19741 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19742 "2: " ASM_CLAC "\n" \
19743 ".section .fixup,\"ax\"\n" \
19744 "3: mov %3,%0\n" \
19745 @@ -364,8 +410,10 @@ do { \
19746 " jmp 2b\n" \
19747 ".previous\n" \
19748 _ASM_EXTABLE(1b, 3b) \
19749 - : "=r" (err), ltype(x) \
19750 - : "m" (__m(addr)), "i" (errret), "0" (err))
19751 + : "=r" (err), ltype (x) \
19752 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19753 + pax_close_userland(); \
19754 +} while (0)
19755
19756 #define __get_user_size_ex(x, ptr, size) \
19757 do { \
19758 @@ -389,7 +437,7 @@ do { \
19759 } while (0)
19760
19761 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19762 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19763 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19764 "2:\n" \
19765 _ASM_EXTABLE_EX(1b, 2b) \
19766 : ltype(x) : "m" (__m(addr)))
19767 @@ -406,13 +454,24 @@ do { \
19768 int __gu_err; \
19769 unsigned long __gu_val; \
19770 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19771 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19772 + (x) = (__typeof__(*(ptr)))__gu_val; \
19773 __gu_err; \
19774 })
19775
19776 /* FIXME: this hack is definitely wrong -AK */
19777 struct __large_struct { unsigned long buf[100]; };
19778 -#define __m(x) (*(struct __large_struct __user *)(x))
19779 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19780 +#define ____m(x) \
19781 +({ \
19782 + unsigned long ____x = (unsigned long)(x); \
19783 + if (____x < pax_user_shadow_base) \
19784 + ____x += pax_user_shadow_base; \
19785 + (typeof(x))____x; \
19786 +})
19787 +#else
19788 +#define ____m(x) (x)
19789 +#endif
19790 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19791
19792 /*
19793 * Tell gcc we read from memory instead of writing: this is because
19794 @@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
19795 * aliasing issues.
19796 */
19797 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19798 +do { \
19799 + pax_open_userland(); \
19800 asm volatile(ASM_STAC "\n" \
19801 - "1: mov"itype" %"rtype"1,%2\n" \
19802 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19803 "2: " ASM_CLAC "\n" \
19804 ".section .fixup,\"ax\"\n" \
19805 "3: mov %3,%0\n" \
19806 @@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
19807 ".previous\n" \
19808 _ASM_EXTABLE(1b, 3b) \
19809 : "=r"(err) \
19810 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19811 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19812 + pax_close_userland(); \
19813 +} while (0)
19814
19815 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19816 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19817 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19818 "2:\n" \
19819 _ASM_EXTABLE_EX(1b, 2b) \
19820 : : ltype(x), "m" (__m(addr)))
19821 @@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
19822 */
19823 #define uaccess_try do { \
19824 current_thread_info()->uaccess_err = 0; \
19825 + pax_open_userland(); \
19826 stac(); \
19827 barrier();
19828
19829 #define uaccess_catch(err) \
19830 clac(); \
19831 + pax_close_userland(); \
19832 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19833 } while (0)
19834
19835 @@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
19836 * On error, the variable @x is set to zero.
19837 */
19838
19839 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19840 +#define __get_user(x, ptr) get_user((x), (ptr))
19841 +#else
19842 #define __get_user(x, ptr) \
19843 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19844 +#endif
19845
19846 /**
19847 * __put_user: - Write a simple value into user space, with less checking.
19848 @@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
19849 * Returns zero on success, or -EFAULT on error.
19850 */
19851
19852 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19853 +#define __put_user(x, ptr) put_user((x), (ptr))
19854 +#else
19855 #define __put_user(x, ptr) \
19856 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19857 +#endif
19858
19859 #define __get_user_unaligned __get_user
19860 #define __put_user_unaligned __put_user
19861 @@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
19862 #define get_user_ex(x, ptr) do { \
19863 unsigned long __gue_val; \
19864 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19865 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19866 + (x) = (__typeof__(*(ptr)))__gue_val; \
19867 } while (0)
19868
19869 #define put_user_try uaccess_try
19870 @@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
19871 __typeof__(ptr) __uval = (uval); \
19872 __typeof__(*(ptr)) __old = (old); \
19873 __typeof__(*(ptr)) __new = (new); \
19874 + pax_open_userland(); \
19875 switch (size) { \
19876 case 1: \
19877 { \
19878 asm volatile("\t" ASM_STAC "\n" \
19879 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19880 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19881 "2:\t" ASM_CLAC "\n" \
19882 "\t.section .fixup, \"ax\"\n" \
19883 "3:\tmov %3, %0\n" \
19884 "\tjmp 2b\n" \
19885 "\t.previous\n" \
19886 _ASM_EXTABLE(1b, 3b) \
19887 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19888 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19889 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19890 : "memory" \
19891 ); \
19892 @@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
19893 case 2: \
19894 { \
19895 asm volatile("\t" ASM_STAC "\n" \
19896 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19897 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19898 "2:\t" ASM_CLAC "\n" \
19899 "\t.section .fixup, \"ax\"\n" \
19900 "3:\tmov %3, %0\n" \
19901 "\tjmp 2b\n" \
19902 "\t.previous\n" \
19903 _ASM_EXTABLE(1b, 3b) \
19904 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19905 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19906 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19907 : "memory" \
19908 ); \
19909 @@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
19910 case 4: \
19911 { \
19912 asm volatile("\t" ASM_STAC "\n" \
19913 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19914 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19915 "2:\t" ASM_CLAC "\n" \
19916 "\t.section .fixup, \"ax\"\n" \
19917 "3:\tmov %3, %0\n" \
19918 "\tjmp 2b\n" \
19919 "\t.previous\n" \
19920 _ASM_EXTABLE(1b, 3b) \
19921 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19922 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19923 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19924 : "memory" \
19925 ); \
19926 @@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
19927 __cmpxchg_wrong_size(); \
19928 \
19929 asm volatile("\t" ASM_STAC "\n" \
19930 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19931 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19932 "2:\t" ASM_CLAC "\n" \
19933 "\t.section .fixup, \"ax\"\n" \
19934 "3:\tmov %3, %0\n" \
19935 "\tjmp 2b\n" \
19936 "\t.previous\n" \
19937 _ASM_EXTABLE(1b, 3b) \
19938 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19939 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19940 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19941 : "memory" \
19942 ); \
19943 @@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
19944 default: \
19945 __cmpxchg_wrong_size(); \
19946 } \
19947 + pax_close_userland(); \
19948 *__uval = __old; \
19949 __ret; \
19950 })
19951 @@ -636,17 +711,6 @@ extern struct movsl_mask {
19952
19953 #define ARCH_HAS_NOCACHE_UACCESS 1
19954
19955 -#ifdef CONFIG_X86_32
19956 -# include <asm/uaccess_32.h>
19957 -#else
19958 -# include <asm/uaccess_64.h>
19959 -#endif
19960 -
19961 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19962 - unsigned n);
19963 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19964 - unsigned n);
19965 -
19966 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19967 # define copy_user_diag __compiletime_error
19968 #else
19969 @@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19970 extern void copy_user_diag("copy_from_user() buffer size is too small")
19971 copy_from_user_overflow(void);
19972 extern void copy_user_diag("copy_to_user() buffer size is too small")
19973 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19974 +copy_to_user_overflow(void);
19975
19976 #undef copy_user_diag
19977
19978 @@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19979
19980 extern void
19981 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19982 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19983 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19984 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19985
19986 #else
19987 @@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19988
19989 #endif
19990
19991 +#ifdef CONFIG_X86_32
19992 +# include <asm/uaccess_32.h>
19993 +#else
19994 +# include <asm/uaccess_64.h>
19995 +#endif
19996 +
19997 static inline unsigned long __must_check
19998 copy_from_user(void *to, const void __user *from, unsigned long n)
19999 {
20000 - int sz = __compiletime_object_size(to);
20001 + size_t sz = __compiletime_object_size(to);
20002
20003 might_fault();
20004
20005 @@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20006 * case, and do only runtime checking for non-constant sizes.
20007 */
20008
20009 - if (likely(sz < 0 || sz >= n))
20010 - n = _copy_from_user(to, from, n);
20011 - else if(__builtin_constant_p(n))
20012 - copy_from_user_overflow();
20013 - else
20014 - __copy_from_user_overflow(sz, n);
20015 + if (likely(sz != (size_t)-1 && sz < n)) {
20016 + if(__builtin_constant_p(n))
20017 + copy_from_user_overflow();
20018 + else
20019 + __copy_from_user_overflow(sz, n);
20020 + } if (access_ok(VERIFY_READ, from, n))
20021 + n = __copy_from_user(to, from, n);
20022 + else if ((long)n > 0)
20023 + memset(to, 0, n);
20024
20025 return n;
20026 }
20027 @@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20028 static inline unsigned long __must_check
20029 copy_to_user(void __user *to, const void *from, unsigned long n)
20030 {
20031 - int sz = __compiletime_object_size(from);
20032 + size_t sz = __compiletime_object_size(from);
20033
20034 might_fault();
20035
20036 /* See the comment in copy_from_user() above. */
20037 - if (likely(sz < 0 || sz >= n))
20038 - n = _copy_to_user(to, from, n);
20039 - else if(__builtin_constant_p(n))
20040 - copy_to_user_overflow();
20041 - else
20042 - __copy_to_user_overflow(sz, n);
20043 + if (likely(sz != (size_t)-1 && sz < n)) {
20044 + if(__builtin_constant_p(n))
20045 + copy_to_user_overflow();
20046 + else
20047 + __copy_to_user_overflow(sz, n);
20048 + } else if (access_ok(VERIFY_WRITE, to, n))
20049 + n = __copy_to_user(to, from, n);
20050
20051 return n;
20052 }
20053 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20054 index 3c03a5d..1071638 100644
20055 --- a/arch/x86/include/asm/uaccess_32.h
20056 +++ b/arch/x86/include/asm/uaccess_32.h
20057 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20058 static __always_inline unsigned long __must_check
20059 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20060 {
20061 + if ((long)n < 0)
20062 + return n;
20063 +
20064 + check_object_size(from, n, true);
20065 +
20066 if (__builtin_constant_p(n)) {
20067 unsigned long ret;
20068
20069 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20070 __copy_to_user(void __user *to, const void *from, unsigned long n)
20071 {
20072 might_fault();
20073 +
20074 return __copy_to_user_inatomic(to, from, n);
20075 }
20076
20077 static __always_inline unsigned long
20078 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20079 {
20080 + if ((long)n < 0)
20081 + return n;
20082 +
20083 /* Avoid zeroing the tail if the copy fails..
20084 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20085 * but as the zeroing behaviour is only significant when n is not
20086 @@ -137,6 +146,12 @@ static __always_inline unsigned long
20087 __copy_from_user(void *to, const void __user *from, unsigned long n)
20088 {
20089 might_fault();
20090 +
20091 + if ((long)n < 0)
20092 + return n;
20093 +
20094 + check_object_size(to, n, false);
20095 +
20096 if (__builtin_constant_p(n)) {
20097 unsigned long ret;
20098
20099 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20100 const void __user *from, unsigned long n)
20101 {
20102 might_fault();
20103 +
20104 + if ((long)n < 0)
20105 + return n;
20106 +
20107 if (__builtin_constant_p(n)) {
20108 unsigned long ret;
20109
20110 @@ -181,7 +200,10 @@ static __always_inline unsigned long
20111 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20112 unsigned long n)
20113 {
20114 - return __copy_from_user_ll_nocache_nozero(to, from, n);
20115 + if ((long)n < 0)
20116 + return n;
20117 +
20118 + return __copy_from_user_ll_nocache_nozero(to, from, n);
20119 }
20120
20121 #endif /* _ASM_X86_UACCESS_32_H */
20122 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20123 index 12a26b9..206c200 100644
20124 --- a/arch/x86/include/asm/uaccess_64.h
20125 +++ b/arch/x86/include/asm/uaccess_64.h
20126 @@ -10,6 +10,9 @@
20127 #include <asm/alternative.h>
20128 #include <asm/cpufeature.h>
20129 #include <asm/page.h>
20130 +#include <asm/pgtable.h>
20131 +
20132 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
20133
20134 /*
20135 * Copy To/From Userspace
20136 @@ -17,14 +20,14 @@
20137
20138 /* Handles exceptions in both to and from, but doesn't do access_ok */
20139 __must_check unsigned long
20140 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20141 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20142 __must_check unsigned long
20143 -copy_user_generic_string(void *to, const void *from, unsigned len);
20144 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20145 __must_check unsigned long
20146 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20147 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20148
20149 static __always_inline __must_check unsigned long
20150 -copy_user_generic(void *to, const void *from, unsigned len)
20151 +copy_user_generic(void *to, const void *from, unsigned long len)
20152 {
20153 unsigned ret;
20154
20155 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20156 }
20157
20158 __must_check unsigned long
20159 -copy_in_user(void __user *to, const void __user *from, unsigned len);
20160 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
20161
20162 static __always_inline __must_check
20163 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20164 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20165 {
20166 - int ret = 0;
20167 + size_t sz = __compiletime_object_size(dst);
20168 + unsigned ret = 0;
20169 +
20170 + if (size > INT_MAX)
20171 + return size;
20172 +
20173 + check_object_size(dst, size, false);
20174 +
20175 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20176 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20177 + return size;
20178 +#endif
20179 +
20180 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20181 + if(__builtin_constant_p(size))
20182 + copy_from_user_overflow();
20183 + else
20184 + __copy_from_user_overflow(sz, size);
20185 + return size;
20186 + }
20187
20188 if (!__builtin_constant_p(size))
20189 - return copy_user_generic(dst, (__force void *)src, size);
20190 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20191 switch (size) {
20192 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20193 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20194 ret, "b", "b", "=q", 1);
20195 return ret;
20196 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20197 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20198 ret, "w", "w", "=r", 2);
20199 return ret;
20200 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20201 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20202 ret, "l", "k", "=r", 4);
20203 return ret;
20204 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20205 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20206 ret, "q", "", "=r", 8);
20207 return ret;
20208 case 10:
20209 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20210 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20211 ret, "q", "", "=r", 10);
20212 if (unlikely(ret))
20213 return ret;
20214 __get_user_asm(*(u16 *)(8 + (char *)dst),
20215 - (u16 __user *)(8 + (char __user *)src),
20216 + (const u16 __user *)(8 + (const char __user *)src),
20217 ret, "w", "w", "=r", 2);
20218 return ret;
20219 case 16:
20220 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20221 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20222 ret, "q", "", "=r", 16);
20223 if (unlikely(ret))
20224 return ret;
20225 __get_user_asm(*(u64 *)(8 + (char *)dst),
20226 - (u64 __user *)(8 + (char __user *)src),
20227 + (const u64 __user *)(8 + (const char __user *)src),
20228 ret, "q", "", "=r", 8);
20229 return ret;
20230 default:
20231 - return copy_user_generic(dst, (__force void *)src, size);
20232 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20233 }
20234 }
20235
20236 static __always_inline __must_check
20237 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
20238 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20239 {
20240 might_fault();
20241 return __copy_from_user_nocheck(dst, src, size);
20242 }
20243
20244 static __always_inline __must_check
20245 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20246 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20247 {
20248 - int ret = 0;
20249 + size_t sz = __compiletime_object_size(src);
20250 + unsigned ret = 0;
20251 +
20252 + if (size > INT_MAX)
20253 + return size;
20254 +
20255 + check_object_size(src, size, true);
20256 +
20257 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20258 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20259 + return size;
20260 +#endif
20261 +
20262 + if (unlikely(sz != (size_t)-1 && sz < size)) {
20263 + if(__builtin_constant_p(size))
20264 + copy_to_user_overflow();
20265 + else
20266 + __copy_to_user_overflow(sz, size);
20267 + return size;
20268 + }
20269
20270 if (!__builtin_constant_p(size))
20271 - return copy_user_generic((__force void *)dst, src, size);
20272 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20273 switch (size) {
20274 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20275 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20276 ret, "b", "b", "iq", 1);
20277 return ret;
20278 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20279 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20280 ret, "w", "w", "ir", 2);
20281 return ret;
20282 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20283 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20284 ret, "l", "k", "ir", 4);
20285 return ret;
20286 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20287 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20288 ret, "q", "", "er", 8);
20289 return ret;
20290 case 10:
20291 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20292 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20293 ret, "q", "", "er", 10);
20294 if (unlikely(ret))
20295 return ret;
20296 asm("":::"memory");
20297 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20298 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20299 ret, "w", "w", "ir", 2);
20300 return ret;
20301 case 16:
20302 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20303 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20304 ret, "q", "", "er", 16);
20305 if (unlikely(ret))
20306 return ret;
20307 asm("":::"memory");
20308 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20309 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20310 ret, "q", "", "er", 8);
20311 return ret;
20312 default:
20313 - return copy_user_generic((__force void *)dst, src, size);
20314 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20315 }
20316 }
20317
20318 static __always_inline __must_check
20319 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20320 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20321 {
20322 might_fault();
20323 return __copy_to_user_nocheck(dst, src, size);
20324 }
20325
20326 static __always_inline __must_check
20327 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20328 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20329 {
20330 - int ret = 0;
20331 + unsigned ret = 0;
20332
20333 might_fault();
20334 +
20335 + if (size > INT_MAX)
20336 + return size;
20337 +
20338 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20339 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20340 + return size;
20341 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20342 + return size;
20343 +#endif
20344 +
20345 if (!__builtin_constant_p(size))
20346 - return copy_user_generic((__force void *)dst,
20347 - (__force void *)src, size);
20348 + return copy_user_generic((__force_kernel void *)____m(dst),
20349 + (__force_kernel const void *)____m(src), size);
20350 switch (size) {
20351 case 1: {
20352 u8 tmp;
20353 - __get_user_asm(tmp, (u8 __user *)src,
20354 + __get_user_asm(tmp, (const u8 __user *)src,
20355 ret, "b", "b", "=q", 1);
20356 if (likely(!ret))
20357 __put_user_asm(tmp, (u8 __user *)dst,
20358 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20359 }
20360 case 2: {
20361 u16 tmp;
20362 - __get_user_asm(tmp, (u16 __user *)src,
20363 + __get_user_asm(tmp, (const u16 __user *)src,
20364 ret, "w", "w", "=r", 2);
20365 if (likely(!ret))
20366 __put_user_asm(tmp, (u16 __user *)dst,
20367 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20368
20369 case 4: {
20370 u32 tmp;
20371 - __get_user_asm(tmp, (u32 __user *)src,
20372 + __get_user_asm(tmp, (const u32 __user *)src,
20373 ret, "l", "k", "=r", 4);
20374 if (likely(!ret))
20375 __put_user_asm(tmp, (u32 __user *)dst,
20376 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20377 }
20378 case 8: {
20379 u64 tmp;
20380 - __get_user_asm(tmp, (u64 __user *)src,
20381 + __get_user_asm(tmp, (const u64 __user *)src,
20382 ret, "q", "", "=r", 8);
20383 if (likely(!ret))
20384 __put_user_asm(tmp, (u64 __user *)dst,
20385 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20386 return ret;
20387 }
20388 default:
20389 - return copy_user_generic((__force void *)dst,
20390 - (__force void *)src, size);
20391 + return copy_user_generic((__force_kernel void *)____m(dst),
20392 + (__force_kernel const void *)____m(src), size);
20393 }
20394 }
20395
20396 -static __must_check __always_inline int
20397 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20398 +static __must_check __always_inline unsigned long
20399 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20400 {
20401 return __copy_from_user_nocheck(dst, src, size);
20402 }
20403
20404 -static __must_check __always_inline int
20405 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20406 +static __must_check __always_inline unsigned long
20407 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20408 {
20409 return __copy_to_user_nocheck(dst, src, size);
20410 }
20411
20412 -extern long __copy_user_nocache(void *dst, const void __user *src,
20413 - unsigned size, int zerorest);
20414 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20415 + unsigned long size, int zerorest);
20416
20417 -static inline int
20418 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20419 +static inline unsigned long
20420 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20421 {
20422 might_fault();
20423 +
20424 + if (size > INT_MAX)
20425 + return size;
20426 +
20427 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20428 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20429 + return size;
20430 +#endif
20431 +
20432 return __copy_user_nocache(dst, src, size, 1);
20433 }
20434
20435 -static inline int
20436 +static inline unsigned long
20437 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20438 - unsigned size)
20439 + unsigned long size)
20440 {
20441 + if (size > INT_MAX)
20442 + return size;
20443 +
20444 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20445 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20446 + return size;
20447 +#endif
20448 +
20449 return __copy_user_nocache(dst, src, size, 0);
20450 }
20451
20452 unsigned long
20453 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20454 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20455
20456 #endif /* _ASM_X86_UACCESS_64_H */
20457 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20458 index 5b238981..77fdd78 100644
20459 --- a/arch/x86/include/asm/word-at-a-time.h
20460 +++ b/arch/x86/include/asm/word-at-a-time.h
20461 @@ -11,7 +11,7 @@
20462 * and shift, for example.
20463 */
20464 struct word_at_a_time {
20465 - const unsigned long one_bits, high_bits;
20466 + unsigned long one_bits, high_bits;
20467 };
20468
20469 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20470 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20471 index e45e4da..44e8572 100644
20472 --- a/arch/x86/include/asm/x86_init.h
20473 +++ b/arch/x86/include/asm/x86_init.h
20474 @@ -129,7 +129,7 @@ struct x86_init_ops {
20475 struct x86_init_timers timers;
20476 struct x86_init_iommu iommu;
20477 struct x86_init_pci pci;
20478 -};
20479 +} __no_const;
20480
20481 /**
20482 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20483 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20484 void (*setup_percpu_clockev)(void);
20485 void (*early_percpu_clock_init)(void);
20486 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20487 -};
20488 +} __no_const;
20489
20490 struct timespec;
20491
20492 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20493 void (*save_sched_clock_state)(void);
20494 void (*restore_sched_clock_state)(void);
20495 void (*apic_post_init)(void);
20496 -};
20497 +} __no_const;
20498
20499 struct pci_dev;
20500 struct msi_msg;
20501 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20502 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20503 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20504 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20505 -};
20506 +} __no_const;
20507
20508 struct IO_APIC_route_entry;
20509 struct io_apic_irq_attr;
20510 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20511 unsigned int destination, int vector,
20512 struct io_apic_irq_attr *attr);
20513 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20514 -};
20515 +} __no_const;
20516
20517 extern struct x86_init_ops x86_init;
20518 extern struct x86_cpuinit_ops x86_cpuinit;
20519 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20520 index 3e276eb..2eb3c30 100644
20521 --- a/arch/x86/include/asm/xen/page.h
20522 +++ b/arch/x86/include/asm/xen/page.h
20523 @@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20524 extern struct page *m2p_find_override(unsigned long mfn);
20525 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20526
20527 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20528 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20529 {
20530 unsigned long mfn;
20531
20532 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20533 index 6c1d741..39e6ecf 100644
20534 --- a/arch/x86/include/asm/xsave.h
20535 +++ b/arch/x86/include/asm/xsave.h
20536 @@ -80,8 +80,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20537 if (unlikely(err))
20538 return -EFAULT;
20539
20540 + pax_open_userland();
20541 __asm__ __volatile__(ASM_STAC "\n"
20542 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20543 + "1:"
20544 + __copyuser_seg
20545 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20546 "2: " ASM_CLAC "\n"
20547 ".section .fixup,\"ax\"\n"
20548 "3: movl $-1,%[err]\n"
20549 @@ -91,18 +94,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20550 : [err] "=r" (err)
20551 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20552 : "memory");
20553 + pax_close_userland();
20554 return err;
20555 }
20556
20557 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20558 {
20559 int err;
20560 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20561 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20562 u32 lmask = mask;
20563 u32 hmask = mask >> 32;
20564
20565 + pax_open_userland();
20566 __asm__ __volatile__(ASM_STAC "\n"
20567 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20568 + "1:"
20569 + __copyuser_seg
20570 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20571 "2: " ASM_CLAC "\n"
20572 ".section .fixup,\"ax\"\n"
20573 "3: movl $-1,%[err]\n"
20574 @@ -112,6 +119,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20575 : [err] "=r" (err)
20576 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20577 : "memory"); /* memory required? */
20578 + pax_close_userland();
20579 return err;
20580 }
20581
20582 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20583 index bbae024..e1528f9 100644
20584 --- a/arch/x86/include/uapi/asm/e820.h
20585 +++ b/arch/x86/include/uapi/asm/e820.h
20586 @@ -63,7 +63,7 @@ struct e820map {
20587 #define ISA_START_ADDRESS 0xa0000
20588 #define ISA_END_ADDRESS 0x100000
20589
20590 -#define BIOS_BEGIN 0x000a0000
20591 +#define BIOS_BEGIN 0x000c0000
20592 #define BIOS_END 0x00100000
20593
20594 #define BIOS_ROM_BASE 0xffe00000
20595 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20596 index 7b0a55a..ad115bf 100644
20597 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20598 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20599 @@ -49,7 +49,6 @@
20600 #define EFLAGS 144
20601 #define RSP 152
20602 #define SS 160
20603 -#define ARGOFFSET R11
20604 #endif /* __ASSEMBLY__ */
20605
20606 /* top of stack page */
20607 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20608 index cb648c8..91cb07e 100644
20609 --- a/arch/x86/kernel/Makefile
20610 +++ b/arch/x86/kernel/Makefile
20611 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20612 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20613 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20614 obj-y += probe_roms.o
20615 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20616 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20617 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20618 obj-y += syscall_$(BITS).o
20619 obj-$(CONFIG_X86_64) += vsyscall_64.o
20620 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20621 index 1dac942..19c8b0c 100644
20622 --- a/arch/x86/kernel/acpi/boot.c
20623 +++ b/arch/x86/kernel/acpi/boot.c
20624 @@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20625 * If your system is blacklisted here, but you find that acpi=force
20626 * works for you, please contact linux-acpi@vger.kernel.org
20627 */
20628 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20629 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20630 /*
20631 * Boxes that need ACPI disabled
20632 */
20633 @@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20634 };
20635
20636 /* second table for DMI checks that should run after early-quirks */
20637 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20638 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20639 /*
20640 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20641 * which includes some code which overrides all temperature
20642 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20643 index 3a2ae4c..9db31d6 100644
20644 --- a/arch/x86/kernel/acpi/sleep.c
20645 +++ b/arch/x86/kernel/acpi/sleep.c
20646 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20647 #else /* CONFIG_64BIT */
20648 #ifdef CONFIG_SMP
20649 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20650 +
20651 + pax_open_kernel();
20652 early_gdt_descr.address =
20653 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20654 + pax_close_kernel();
20655 +
20656 initial_gs = per_cpu_offset(smp_processor_id());
20657 #endif
20658 initial_code = (unsigned long)wakeup_long64;
20659 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20660 index 665c6b7..eae4d56 100644
20661 --- a/arch/x86/kernel/acpi/wakeup_32.S
20662 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20663 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20664 # and restore the stack ... but you need gdt for this to work
20665 movl saved_context_esp, %esp
20666
20667 - movl %cs:saved_magic, %eax
20668 - cmpl $0x12345678, %eax
20669 + cmpl $0x12345678, saved_magic
20670 jne bogus_magic
20671
20672 # jump to place where we left off
20673 - movl saved_eip, %eax
20674 - jmp *%eax
20675 + jmp *(saved_eip)
20676
20677 bogus_magic:
20678 jmp bogus_magic
20679 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20680 index df94598..f3b29bf 100644
20681 --- a/arch/x86/kernel/alternative.c
20682 +++ b/arch/x86/kernel/alternative.c
20683 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20684 */
20685 for (a = start; a < end; a++) {
20686 instr = (u8 *)&a->instr_offset + a->instr_offset;
20687 +
20688 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20689 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20690 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20691 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20692 +#endif
20693 +
20694 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20695 BUG_ON(a->replacementlen > a->instrlen);
20696 BUG_ON(a->instrlen > sizeof(insnbuf));
20697 @@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20698 for (poff = start; poff < end; poff++) {
20699 u8 *ptr = (u8 *)poff + *poff;
20700
20701 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20702 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20703 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20704 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20705 +#endif
20706 +
20707 if (!*poff || ptr < text || ptr >= text_end)
20708 continue;
20709 /* turn DS segment override prefix into lock prefix */
20710 - if (*ptr == 0x3e)
20711 + if (*ktla_ktva(ptr) == 0x3e)
20712 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20713 }
20714 mutex_unlock(&text_mutex);
20715 @@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20716 for (poff = start; poff < end; poff++) {
20717 u8 *ptr = (u8 *)poff + *poff;
20718
20719 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20720 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20721 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20722 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20723 +#endif
20724 +
20725 if (!*poff || ptr < text || ptr >= text_end)
20726 continue;
20727 /* turn lock prefix into DS segment override prefix */
20728 - if (*ptr == 0xf0)
20729 + if (*ktla_ktva(ptr) == 0xf0)
20730 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20731 }
20732 mutex_unlock(&text_mutex);
20733 @@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20734
20735 BUG_ON(p->len > MAX_PATCH_LEN);
20736 /* prep the buffer with the original instructions */
20737 - memcpy(insnbuf, p->instr, p->len);
20738 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20739 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20740 (unsigned long)p->instr, p->len);
20741
20742 @@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20743 if (!uniproc_patched || num_possible_cpus() == 1)
20744 free_init_pages("SMP alternatives",
20745 (unsigned long)__smp_locks,
20746 - (unsigned long)__smp_locks_end);
20747 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20748 #endif
20749
20750 apply_paravirt(__parainstructions, __parainstructions_end);
20751 @@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20752 * instructions. And on the local CPU you need to be protected again NMI or MCE
20753 * handlers seeing an inconsistent instruction while you patch.
20754 */
20755 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20756 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20757 size_t len)
20758 {
20759 unsigned long flags;
20760 local_irq_save(flags);
20761 - memcpy(addr, opcode, len);
20762 +
20763 + pax_open_kernel();
20764 + memcpy(ktla_ktva(addr), opcode, len);
20765 sync_core();
20766 + pax_close_kernel();
20767 +
20768 local_irq_restore(flags);
20769 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20770 that causes hangs on some VIA CPUs. */
20771 @@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20772 */
20773 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20774 {
20775 - unsigned long flags;
20776 - char *vaddr;
20777 + unsigned char *vaddr = ktla_ktva(addr);
20778 struct page *pages[2];
20779 - int i;
20780 + size_t i;
20781
20782 if (!core_kernel_text((unsigned long)addr)) {
20783 - pages[0] = vmalloc_to_page(addr);
20784 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20785 + pages[0] = vmalloc_to_page(vaddr);
20786 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20787 } else {
20788 - pages[0] = virt_to_page(addr);
20789 + pages[0] = virt_to_page(vaddr);
20790 WARN_ON(!PageReserved(pages[0]));
20791 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20792 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20793 }
20794 BUG_ON(!pages[0]);
20795 - local_irq_save(flags);
20796 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20797 - if (pages[1])
20798 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20799 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20800 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20801 - clear_fixmap(FIX_TEXT_POKE0);
20802 - if (pages[1])
20803 - clear_fixmap(FIX_TEXT_POKE1);
20804 - local_flush_tlb();
20805 - sync_core();
20806 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20807 - that causes hangs on some VIA CPUs. */
20808 + text_poke_early(addr, opcode, len);
20809 for (i = 0; i < len; i++)
20810 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20811 - local_irq_restore(flags);
20812 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20813 return addr;
20814 }
20815
20816 @@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20817 if (likely(!bp_patching_in_progress))
20818 return 0;
20819
20820 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20821 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20822 return 0;
20823
20824 /* set up the specified breakpoint handler */
20825 @@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20826 */
20827 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20828 {
20829 - unsigned char int3 = 0xcc;
20830 + const unsigned char int3 = 0xcc;
20831
20832 bp_int3_handler = handler;
20833 bp_int3_addr = (u8 *)addr + sizeof(int3);
20834 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20835 index 7f26c9a..694544e 100644
20836 --- a/arch/x86/kernel/apic/apic.c
20837 +++ b/arch/x86/kernel/apic/apic.c
20838 @@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20839 /*
20840 * Debug level, exported for io_apic.c
20841 */
20842 -unsigned int apic_verbosity;
20843 +int apic_verbosity;
20844
20845 int pic_mode;
20846
20847 @@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20848 apic_write(APIC_ESR, 0);
20849 v = apic_read(APIC_ESR);
20850 ack_APIC_irq();
20851 - atomic_inc(&irq_err_count);
20852 + atomic_inc_unchecked(&irq_err_count);
20853
20854 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20855 smp_processor_id(), v);
20856 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20857 index 2c621a6..fa2b1ae 100644
20858 --- a/arch/x86/kernel/apic/apic_flat_64.c
20859 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20860 @@ -154,7 +154,7 @@ static int flat_probe(void)
20861 return 1;
20862 }
20863
20864 -static struct apic apic_flat = {
20865 +static struct apic apic_flat __read_only = {
20866 .name = "flat",
20867 .probe = flat_probe,
20868 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20869 @@ -268,7 +268,7 @@ static int physflat_probe(void)
20870 return 0;
20871 }
20872
20873 -static struct apic apic_physflat = {
20874 +static struct apic apic_physflat __read_only = {
20875
20876 .name = "physical flat",
20877 .probe = physflat_probe,
20878 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20879 index 191ce75..2db6d63 100644
20880 --- a/arch/x86/kernel/apic/apic_noop.c
20881 +++ b/arch/x86/kernel/apic/apic_noop.c
20882 @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20883 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20884 }
20885
20886 -struct apic apic_noop = {
20887 +struct apic apic_noop __read_only = {
20888 .name = "noop",
20889 .probe = noop_probe,
20890 .acpi_madt_oem_check = NULL,
20891 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20892 index d50e364..543bee3 100644
20893 --- a/arch/x86/kernel/apic/bigsmp_32.c
20894 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20895 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20896 return dmi_bigsmp;
20897 }
20898
20899 -static struct apic apic_bigsmp = {
20900 +static struct apic apic_bigsmp __read_only = {
20901
20902 .name = "bigsmp",
20903 .probe = probe_bigsmp,
20904 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20905 index c552247..587a316 100644
20906 --- a/arch/x86/kernel/apic/es7000_32.c
20907 +++ b/arch/x86/kernel/apic/es7000_32.c
20908 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20909 return ret && es7000_apic_is_cluster();
20910 }
20911
20912 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20913 -static struct apic __refdata apic_es7000_cluster = {
20914 +static struct apic apic_es7000_cluster __read_only = {
20915
20916 .name = "es7000",
20917 .probe = probe_es7000,
20918 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20919 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20920 };
20921
20922 -static struct apic __refdata apic_es7000 = {
20923 +static struct apic apic_es7000 __read_only = {
20924
20925 .name = "es7000",
20926 .probe = probe_es7000,
20927 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20928 index 6ad4658..38a7b5c 100644
20929 --- a/arch/x86/kernel/apic/io_apic.c
20930 +++ b/arch/x86/kernel/apic/io_apic.c
20931 @@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20932 }
20933 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20934
20935 -void lock_vector_lock(void)
20936 +void lock_vector_lock(void) __acquires(vector_lock)
20937 {
20938 /* Used to the online set of cpus does not change
20939 * during assign_irq_vector.
20940 @@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20941 raw_spin_lock(&vector_lock);
20942 }
20943
20944 -void unlock_vector_lock(void)
20945 +void unlock_vector_lock(void) __releases(vector_lock)
20946 {
20947 raw_spin_unlock(&vector_lock);
20948 }
20949 @@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20950 ack_APIC_irq();
20951 }
20952
20953 -atomic_t irq_mis_count;
20954 +atomic_unchecked_t irq_mis_count;
20955
20956 #ifdef CONFIG_GENERIC_PENDING_IRQ
20957 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20958 @@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20959 * at the cpu.
20960 */
20961 if (!(v & (1 << (i & 0x1f)))) {
20962 - atomic_inc(&irq_mis_count);
20963 + atomic_inc_unchecked(&irq_mis_count);
20964
20965 eoi_ioapic_irq(irq, cfg);
20966 }
20967 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20968 index 1e42e8f..daacf44 100644
20969 --- a/arch/x86/kernel/apic/numaq_32.c
20970 +++ b/arch/x86/kernel/apic/numaq_32.c
20971 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20972 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20973 }
20974
20975 -/* Use __refdata to keep false positive warning calm. */
20976 -static struct apic __refdata apic_numaq = {
20977 +static struct apic apic_numaq __read_only = {
20978
20979 .name = "NUMAQ",
20980 .probe = probe_numaq,
20981 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20982 index eb35ef9..f184a21 100644
20983 --- a/arch/x86/kernel/apic/probe_32.c
20984 +++ b/arch/x86/kernel/apic/probe_32.c
20985 @@ -72,7 +72,7 @@ static int probe_default(void)
20986 return 1;
20987 }
20988
20989 -static struct apic apic_default = {
20990 +static struct apic apic_default __read_only = {
20991
20992 .name = "default",
20993 .probe = probe_default,
20994 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20995 index 00146f9..5e299b8 100644
20996 --- a/arch/x86/kernel/apic/summit_32.c
20997 +++ b/arch/x86/kernel/apic/summit_32.c
20998 @@ -485,7 +485,7 @@ void setup_summit(void)
20999 }
21000 #endif
21001
21002 -static struct apic apic_summit = {
21003 +static struct apic apic_summit __read_only = {
21004
21005 .name = "summit",
21006 .probe = probe_summit,
21007 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21008 index cac85ee..01fa741 100644
21009 --- a/arch/x86/kernel/apic/x2apic_cluster.c
21010 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
21011 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21012 return notifier_from_errno(err);
21013 }
21014
21015 -static struct notifier_block __refdata x2apic_cpu_notifier = {
21016 +static struct notifier_block x2apic_cpu_notifier = {
21017 .notifier_call = update_clusterinfo,
21018 };
21019
21020 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21021 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21022 }
21023
21024 -static struct apic apic_x2apic_cluster = {
21025 +static struct apic apic_x2apic_cluster __read_only = {
21026
21027 .name = "cluster x2apic",
21028 .probe = x2apic_cluster_probe,
21029 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21030 index de231e3..1d1b2ee 100644
21031 --- a/arch/x86/kernel/apic/x2apic_phys.c
21032 +++ b/arch/x86/kernel/apic/x2apic_phys.c
21033 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21034 return apic == &apic_x2apic_phys;
21035 }
21036
21037 -static struct apic apic_x2apic_phys = {
21038 +static struct apic apic_x2apic_phys __read_only = {
21039
21040 .name = "physical x2apic",
21041 .probe = x2apic_phys_probe,
21042 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21043 index d263b13..963258b 100644
21044 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
21045 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21046 @@ -350,7 +350,7 @@ static int uv_probe(void)
21047 return apic == &apic_x2apic_uv_x;
21048 }
21049
21050 -static struct apic __refdata apic_x2apic_uv_x = {
21051 +static struct apic apic_x2apic_uv_x __read_only = {
21052
21053 .name = "UV large system",
21054 .probe = uv_probe,
21055 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21056 index 3ab0343..814c4787 100644
21057 --- a/arch/x86/kernel/apm_32.c
21058 +++ b/arch/x86/kernel/apm_32.c
21059 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21060 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21061 * even though they are called in protected mode.
21062 */
21063 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21064 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21065 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21066
21067 static const char driver_version[] = "1.16ac"; /* no spaces */
21068 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21069 BUG_ON(cpu != 0);
21070 gdt = get_cpu_gdt_table(cpu);
21071 save_desc_40 = gdt[0x40 / 8];
21072 +
21073 + pax_open_kernel();
21074 gdt[0x40 / 8] = bad_bios_desc;
21075 + pax_close_kernel();
21076
21077 apm_irq_save(flags);
21078 APM_DO_SAVE_SEGS;
21079 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21080 &call->esi);
21081 APM_DO_RESTORE_SEGS;
21082 apm_irq_restore(flags);
21083 +
21084 + pax_open_kernel();
21085 gdt[0x40 / 8] = save_desc_40;
21086 + pax_close_kernel();
21087 +
21088 put_cpu();
21089
21090 return call->eax & 0xff;
21091 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21092 BUG_ON(cpu != 0);
21093 gdt = get_cpu_gdt_table(cpu);
21094 save_desc_40 = gdt[0x40 / 8];
21095 +
21096 + pax_open_kernel();
21097 gdt[0x40 / 8] = bad_bios_desc;
21098 + pax_close_kernel();
21099
21100 apm_irq_save(flags);
21101 APM_DO_SAVE_SEGS;
21102 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21103 &call->eax);
21104 APM_DO_RESTORE_SEGS;
21105 apm_irq_restore(flags);
21106 +
21107 + pax_open_kernel();
21108 gdt[0x40 / 8] = save_desc_40;
21109 + pax_close_kernel();
21110 +
21111 put_cpu();
21112 return error;
21113 }
21114 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
21115 * code to that CPU.
21116 */
21117 gdt = get_cpu_gdt_table(0);
21118 +
21119 + pax_open_kernel();
21120 set_desc_base(&gdt[APM_CS >> 3],
21121 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21122 set_desc_base(&gdt[APM_CS_16 >> 3],
21123 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21124 set_desc_base(&gdt[APM_DS >> 3],
21125 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21126 + pax_close_kernel();
21127
21128 proc_create("apm", 0, NULL, &apm_file_ops);
21129
21130 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21131 index 9f6b934..cf5ffb3 100644
21132 --- a/arch/x86/kernel/asm-offsets.c
21133 +++ b/arch/x86/kernel/asm-offsets.c
21134 @@ -32,6 +32,8 @@ void common(void) {
21135 OFFSET(TI_flags, thread_info, flags);
21136 OFFSET(TI_status, thread_info, status);
21137 OFFSET(TI_addr_limit, thread_info, addr_limit);
21138 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21139 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21140
21141 BLANK();
21142 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21143 @@ -52,8 +54,26 @@ void common(void) {
21144 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21145 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21146 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21147 +
21148 +#ifdef CONFIG_PAX_KERNEXEC
21149 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21150 #endif
21151
21152 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21153 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21154 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21155 +#ifdef CONFIG_X86_64
21156 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21157 +#endif
21158 +#endif
21159 +
21160 +#endif
21161 +
21162 + BLANK();
21163 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21164 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21165 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21166 +
21167 #ifdef CONFIG_XEN
21168 BLANK();
21169 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21170 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21171 index e7c798b..2b2019b 100644
21172 --- a/arch/x86/kernel/asm-offsets_64.c
21173 +++ b/arch/x86/kernel/asm-offsets_64.c
21174 @@ -77,6 +77,7 @@ int main(void)
21175 BLANK();
21176 #undef ENTRY
21177
21178 + DEFINE(TSS_size, sizeof(struct tss_struct));
21179 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21180 BLANK();
21181
21182 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21183 index 7fd54f0..0691410 100644
21184 --- a/arch/x86/kernel/cpu/Makefile
21185 +++ b/arch/x86/kernel/cpu/Makefile
21186 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21187 CFLAGS_REMOVE_perf_event.o = -pg
21188 endif
21189
21190 -# Make sure load_percpu_segment has no stackprotector
21191 -nostackp := $(call cc-option, -fno-stack-protector)
21192 -CFLAGS_common.o := $(nostackp)
21193 -
21194 obj-y := intel_cacheinfo.o scattered.o topology.o
21195 obj-y += proc.o capflags.o powerflags.o common.o
21196 obj-y += rdrand.o
21197 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21198 index c67ffa6..f41fbbf 100644
21199 --- a/arch/x86/kernel/cpu/amd.c
21200 +++ b/arch/x86/kernel/cpu/amd.c
21201 @@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21202 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21203 {
21204 /* AMD errata T13 (order #21922) */
21205 - if ((c->x86 == 6)) {
21206 + if (c->x86 == 6) {
21207 /* Duron Rev A0 */
21208 if (c->x86_model == 3 && c->x86_mask == 0)
21209 size = 64;
21210 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21211 index 8e28bf2..bf5c0d2 100644
21212 --- a/arch/x86/kernel/cpu/common.c
21213 +++ b/arch/x86/kernel/cpu/common.c
21214 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
21215
21216 static const struct cpu_dev *this_cpu = &default_cpu;
21217
21218 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21219 -#ifdef CONFIG_X86_64
21220 - /*
21221 - * We need valid kernel segments for data and code in long mode too
21222 - * IRET will check the segment types kkeil 2000/10/28
21223 - * Also sysret mandates a special GDT layout
21224 - *
21225 - * TLS descriptors are currently at a different place compared to i386.
21226 - * Hopefully nobody expects them at a fixed place (Wine?)
21227 - */
21228 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21229 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21230 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21231 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21232 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21233 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21234 -#else
21235 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21236 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21237 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21238 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21239 - /*
21240 - * Segments used for calling PnP BIOS have byte granularity.
21241 - * They code segments and data segments have fixed 64k limits,
21242 - * the transfer segment sizes are set at run time.
21243 - */
21244 - /* 32-bit code */
21245 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21246 - /* 16-bit code */
21247 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21248 - /* 16-bit data */
21249 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21250 - /* 16-bit data */
21251 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21252 - /* 16-bit data */
21253 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21254 - /*
21255 - * The APM segments have byte granularity and their bases
21256 - * are set at run time. All have 64k limits.
21257 - */
21258 - /* 32-bit code */
21259 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21260 - /* 16-bit code */
21261 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21262 - /* data */
21263 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21264 -
21265 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21266 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21267 - GDT_STACK_CANARY_INIT
21268 -#endif
21269 -} };
21270 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21271 -
21272 static int __init x86_xsave_setup(char *s)
21273 {
21274 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21275 @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21276 }
21277 }
21278
21279 +#ifdef CONFIG_X86_64
21280 +static __init int setup_disable_pcid(char *arg)
21281 +{
21282 + setup_clear_cpu_cap(X86_FEATURE_PCID);
21283 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21284 +
21285 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21286 + if (clone_pgd_mask != ~(pgdval_t)0UL)
21287 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21288 +#endif
21289 +
21290 + return 1;
21291 +}
21292 +__setup("nopcid", setup_disable_pcid);
21293 +
21294 +static void setup_pcid(struct cpuinfo_x86 *c)
21295 +{
21296 + if (!cpu_has(c, X86_FEATURE_PCID)) {
21297 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
21298 +
21299 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21300 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
21301 + pax_open_kernel();
21302 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21303 + pax_close_kernel();
21304 + printk("PAX: slow and weak UDEREF enabled\n");
21305 + } else
21306 + printk("PAX: UDEREF disabled\n");
21307 +#endif
21308 +
21309 + return;
21310 + }
21311 +
21312 + printk("PAX: PCID detected\n");
21313 + set_in_cr4(X86_CR4_PCIDE);
21314 +
21315 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21316 + pax_open_kernel();
21317 + clone_pgd_mask = ~(pgdval_t)0UL;
21318 + pax_close_kernel();
21319 + if (pax_user_shadow_base)
21320 + printk("PAX: weak UDEREF enabled\n");
21321 + else {
21322 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21323 + printk("PAX: strong UDEREF enabled\n");
21324 + }
21325 +#endif
21326 +
21327 + if (cpu_has(c, X86_FEATURE_INVPCID))
21328 + printk("PAX: INVPCID detected\n");
21329 +}
21330 +#endif
21331 +
21332 /*
21333 * Some CPU features depend on higher CPUID levels, which may not always
21334 * be available due to CPUID level capping or broken virtualization
21335 @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21336 {
21337 struct desc_ptr gdt_descr;
21338
21339 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21340 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21341 gdt_descr.size = GDT_SIZE - 1;
21342 load_gdt(&gdt_descr);
21343 /* Reload the per-cpu base */
21344 @@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21345 setup_smep(c);
21346 setup_smap(c);
21347
21348 +#ifdef CONFIG_X86_64
21349 + setup_pcid(c);
21350 +#endif
21351 +
21352 /*
21353 * The vendor-specific functions might have changed features.
21354 * Now we do "generic changes."
21355 @@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21356 /* Filter out anything that depends on CPUID levels we don't have */
21357 filter_cpuid_features(c, true);
21358
21359 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21360 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21361 +#endif
21362 +
21363 /* If the model name is still unset, do table lookup. */
21364 if (!c->x86_model_id[0]) {
21365 const char *p;
21366 @@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
21367 }
21368 __setup("clearcpuid=", setup_disablecpuid);
21369
21370 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21371 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21372 +
21373 #ifdef CONFIG_X86_64
21374 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21375 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21376 - (unsigned long) debug_idt_table };
21377 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21378 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21379
21380 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21381 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21382 @@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
21383 EXPORT_PER_CPU_SYMBOL(current_task);
21384
21385 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21386 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21387 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21388 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21389
21390 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21391 @@ -1245,7 +1254,7 @@ void cpu_init(void)
21392 load_ucode_ap();
21393
21394 cpu = stack_smp_processor_id();
21395 - t = &per_cpu(init_tss, cpu);
21396 + t = init_tss + cpu;
21397 oist = &per_cpu(orig_ist, cpu);
21398
21399 #ifdef CONFIG_NUMA
21400 @@ -1280,7 +1289,6 @@ void cpu_init(void)
21401 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21402 barrier();
21403
21404 - x86_configure_nx();
21405 enable_x2apic();
21406
21407 /*
21408 @@ -1332,7 +1340,7 @@ void cpu_init(void)
21409 {
21410 int cpu = smp_processor_id();
21411 struct task_struct *curr = current;
21412 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21413 + struct tss_struct *t = init_tss + cpu;
21414 struct thread_struct *thread = &curr->thread;
21415
21416 show_ucode_info_early();
21417 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21418 index 0641113..06f5ba4 100644
21419 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21420 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21421 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21422 };
21423
21424 #ifdef CONFIG_AMD_NB
21425 +static struct attribute *default_attrs_amd_nb[] = {
21426 + &type.attr,
21427 + &level.attr,
21428 + &coherency_line_size.attr,
21429 + &physical_line_partition.attr,
21430 + &ways_of_associativity.attr,
21431 + &number_of_sets.attr,
21432 + &size.attr,
21433 + &shared_cpu_map.attr,
21434 + &shared_cpu_list.attr,
21435 + NULL,
21436 + NULL,
21437 + NULL,
21438 + NULL
21439 +};
21440 +
21441 static struct attribute **amd_l3_attrs(void)
21442 {
21443 static struct attribute **attrs;
21444 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21445
21446 n = ARRAY_SIZE(default_attrs);
21447
21448 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21449 - n += 2;
21450 -
21451 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21452 - n += 1;
21453 -
21454 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21455 - if (attrs == NULL)
21456 - return attrs = default_attrs;
21457 -
21458 - for (n = 0; default_attrs[n]; n++)
21459 - attrs[n] = default_attrs[n];
21460 + attrs = default_attrs_amd_nb;
21461
21462 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21463 attrs[n++] = &cache_disable_0.attr;
21464 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21465 .default_attrs = default_attrs,
21466 };
21467
21468 +#ifdef CONFIG_AMD_NB
21469 +static struct kobj_type ktype_cache_amd_nb = {
21470 + .sysfs_ops = &sysfs_ops,
21471 + .default_attrs = default_attrs_amd_nb,
21472 +};
21473 +#endif
21474 +
21475 static struct kobj_type ktype_percpu_entry = {
21476 .sysfs_ops = &sysfs_ops,
21477 };
21478 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21479 return retval;
21480 }
21481
21482 +#ifdef CONFIG_AMD_NB
21483 + amd_l3_attrs();
21484 +#endif
21485 +
21486 for (i = 0; i < num_cache_leaves; i++) {
21487 + struct kobj_type *ktype;
21488 +
21489 this_object = INDEX_KOBJECT_PTR(cpu, i);
21490 this_object->cpu = cpu;
21491 this_object->index = i;
21492
21493 this_leaf = CPUID4_INFO_IDX(cpu, i);
21494
21495 - ktype_cache.default_attrs = default_attrs;
21496 + ktype = &ktype_cache;
21497 #ifdef CONFIG_AMD_NB
21498 if (this_leaf->base.nb)
21499 - ktype_cache.default_attrs = amd_l3_attrs();
21500 + ktype = &ktype_cache_amd_nb;
21501 #endif
21502 retval = kobject_init_and_add(&(this_object->kobj),
21503 - &ktype_cache,
21504 + ktype,
21505 per_cpu(ici_cache_kobject, cpu),
21506 "index%1lu", i);
21507 if (unlikely(retval)) {
21508 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21509 index 4d5419b..95f11bb 100644
21510 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21511 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21512 @@ -45,6 +45,7 @@
21513 #include <asm/processor.h>
21514 #include <asm/mce.h>
21515 #include <asm/msr.h>
21516 +#include <asm/local.h>
21517
21518 #include "mce-internal.h"
21519
21520 @@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21521 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21522 m->cs, m->ip);
21523
21524 - if (m->cs == __KERNEL_CS)
21525 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21526 print_symbol("{%s}", m->ip);
21527 pr_cont("\n");
21528 }
21529 @@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21530
21531 #define PANIC_TIMEOUT 5 /* 5 seconds */
21532
21533 -static atomic_t mce_paniced;
21534 +static atomic_unchecked_t mce_paniced;
21535
21536 static int fake_panic;
21537 -static atomic_t mce_fake_paniced;
21538 +static atomic_unchecked_t mce_fake_paniced;
21539
21540 /* Panic in progress. Enable interrupts and wait for final IPI */
21541 static void wait_for_panic(void)
21542 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21543 /*
21544 * Make sure only one CPU runs in machine check panic
21545 */
21546 - if (atomic_inc_return(&mce_paniced) > 1)
21547 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21548 wait_for_panic();
21549 barrier();
21550
21551 @@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21552 console_verbose();
21553 } else {
21554 /* Don't log too much for fake panic */
21555 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21556 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21557 return;
21558 }
21559 /* First print corrected ones that are still unlogged */
21560 @@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21561 if (!fake_panic) {
21562 if (panic_timeout == 0)
21563 panic_timeout = mca_cfg.panic_timeout;
21564 - panic(msg);
21565 + panic("%s", msg);
21566 } else
21567 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21568 }
21569 @@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21570 * might have been modified by someone else.
21571 */
21572 rmb();
21573 - if (atomic_read(&mce_paniced))
21574 + if (atomic_read_unchecked(&mce_paniced))
21575 wait_for_panic();
21576 if (!mca_cfg.monarch_timeout)
21577 goto out;
21578 @@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21579 }
21580
21581 /* Call the installed machine check handler for this CPU setup. */
21582 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21583 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21584 unexpected_machine_check;
21585
21586 /*
21587 @@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21588 return;
21589 }
21590
21591 + pax_open_kernel();
21592 machine_check_vector = do_machine_check;
21593 + pax_close_kernel();
21594
21595 __mcheck_cpu_init_generic();
21596 __mcheck_cpu_init_vendor(c);
21597 @@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21598 */
21599
21600 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21601 -static int mce_chrdev_open_count; /* #times opened */
21602 +static local_t mce_chrdev_open_count; /* #times opened */
21603 static int mce_chrdev_open_exclu; /* already open exclusive? */
21604
21605 static int mce_chrdev_open(struct inode *inode, struct file *file)
21606 @@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21607 spin_lock(&mce_chrdev_state_lock);
21608
21609 if (mce_chrdev_open_exclu ||
21610 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21611 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21612 spin_unlock(&mce_chrdev_state_lock);
21613
21614 return -EBUSY;
21615 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21616
21617 if (file->f_flags & O_EXCL)
21618 mce_chrdev_open_exclu = 1;
21619 - mce_chrdev_open_count++;
21620 + local_inc(&mce_chrdev_open_count);
21621
21622 spin_unlock(&mce_chrdev_state_lock);
21623
21624 @@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21625 {
21626 spin_lock(&mce_chrdev_state_lock);
21627
21628 - mce_chrdev_open_count--;
21629 + local_dec(&mce_chrdev_open_count);
21630 mce_chrdev_open_exclu = 0;
21631
21632 spin_unlock(&mce_chrdev_state_lock);
21633 @@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21634
21635 for (i = 0; i < mca_cfg.banks; i++) {
21636 struct mce_bank *b = &mce_banks[i];
21637 - struct device_attribute *a = &b->attr;
21638 + device_attribute_no_const *a = &b->attr;
21639
21640 sysfs_attr_init(&a->attr);
21641 a->attr.name = b->attrname;
21642 @@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21643 static void mce_reset(void)
21644 {
21645 cpu_missing = 0;
21646 - atomic_set(&mce_fake_paniced, 0);
21647 + atomic_set_unchecked(&mce_fake_paniced, 0);
21648 atomic_set(&mce_executing, 0);
21649 atomic_set(&mce_callin, 0);
21650 atomic_set(&global_nwo, 0);
21651 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21652 index a304298..49b6d06 100644
21653 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21654 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21655 @@ -10,6 +10,7 @@
21656 #include <asm/processor.h>
21657 #include <asm/mce.h>
21658 #include <asm/msr.h>
21659 +#include <asm/pgtable.h>
21660
21661 /* By default disabled */
21662 int mce_p5_enabled __read_mostly;
21663 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21664 if (!cpu_has(c, X86_FEATURE_MCE))
21665 return;
21666
21667 + pax_open_kernel();
21668 machine_check_vector = pentium_machine_check;
21669 + pax_close_kernel();
21670 /* Make sure the vector pointer is visible before we enable MCEs: */
21671 wmb();
21672
21673 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21674 index 7dc5564..1273569 100644
21675 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21676 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21677 @@ -9,6 +9,7 @@
21678 #include <asm/processor.h>
21679 #include <asm/mce.h>
21680 #include <asm/msr.h>
21681 +#include <asm/pgtable.h>
21682
21683 /* Machine check handler for WinChip C6: */
21684 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21685 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21686 {
21687 u32 lo, hi;
21688
21689 + pax_open_kernel();
21690 machine_check_vector = winchip_machine_check;
21691 + pax_close_kernel();
21692 /* Make sure the vector pointer is visible before we enable MCEs: */
21693 wmb();
21694
21695 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21696 index 15c9876..0a43909 100644
21697 --- a/arch/x86/kernel/cpu/microcode/core.c
21698 +++ b/arch/x86/kernel/cpu/microcode/core.c
21699 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21700 return NOTIFY_OK;
21701 }
21702
21703 -static struct notifier_block __refdata mc_cpu_notifier = {
21704 +static struct notifier_block mc_cpu_notifier = {
21705 .notifier_call = mc_cpu_callback,
21706 };
21707
21708 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21709 index a276fa7..e66810f 100644
21710 --- a/arch/x86/kernel/cpu/microcode/intel.c
21711 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21712 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21713
21714 static int get_ucode_user(void *to, const void *from, size_t n)
21715 {
21716 - return copy_from_user(to, from, n);
21717 + return copy_from_user(to, (const void __force_user *)from, n);
21718 }
21719
21720 static enum ucode_state
21721 request_microcode_user(int cpu, const void __user *buf, size_t size)
21722 {
21723 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21724 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21725 }
21726
21727 static void microcode_fini_cpu(int cpu)
21728 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21729 index f961de9..8a9d332 100644
21730 --- a/arch/x86/kernel/cpu/mtrr/main.c
21731 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21732 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21733 u64 size_or_mask, size_and_mask;
21734 static bool mtrr_aps_delayed_init;
21735
21736 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21737 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21738
21739 const struct mtrr_ops *mtrr_if;
21740
21741 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21742 index df5e41f..816c719 100644
21743 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21744 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21745 @@ -25,7 +25,7 @@ struct mtrr_ops {
21746 int (*validate_add_page)(unsigned long base, unsigned long size,
21747 unsigned int type);
21748 int (*have_wrcomb)(void);
21749 -};
21750 +} __do_const;
21751
21752 extern int generic_get_free_region(unsigned long base, unsigned long size,
21753 int replace_reg);
21754 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21755 index 79f9f84..38ace52 100644
21756 --- a/arch/x86/kernel/cpu/perf_event.c
21757 +++ b/arch/x86/kernel/cpu/perf_event.c
21758 @@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21759 pr_info("no hardware sampling interrupt available.\n");
21760 }
21761
21762 -static struct attribute_group x86_pmu_format_group = {
21763 +static attribute_group_no_const x86_pmu_format_group = {
21764 .name = "format",
21765 .attrs = NULL,
21766 };
21767 @@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21768 NULL,
21769 };
21770
21771 -static struct attribute_group x86_pmu_events_group = {
21772 +static attribute_group_no_const x86_pmu_events_group = {
21773 .name = "events",
21774 .attrs = events_attr,
21775 };
21776 @@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21777 if (idx > GDT_ENTRIES)
21778 return 0;
21779
21780 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21781 + desc = get_cpu_gdt_table(smp_processor_id());
21782 }
21783
21784 return get_desc_base(desc + idx);
21785 @@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21786 break;
21787
21788 perf_callchain_store(entry, frame.return_address);
21789 - fp = frame.next_frame;
21790 + fp = (const void __force_user *)frame.next_frame;
21791 }
21792 }
21793
21794 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21795 index 639d128..e92d7e5 100644
21796 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21797 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21798 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21799 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21800 {
21801 struct attribute **attrs;
21802 - struct attribute_group *attr_group;
21803 + attribute_group_no_const *attr_group;
21804 int i = 0, j;
21805
21806 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21807 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21808 index aa333d9..f9db700 100644
21809 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21810 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21811 @@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21812 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21813
21814 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21815 - u64 capabilities;
21816 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21817
21818 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21819 - x86_pmu.intel_cap.capabilities = capabilities;
21820 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21821 + x86_pmu.intel_cap.capabilities = capabilities;
21822 }
21823
21824 intel_ds_init();
21825 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21826 index 5ad35ad..e0a3960 100644
21827 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21828 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21829 @@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21830 NULL,
21831 };
21832
21833 -static struct attribute_group rapl_pmu_events_group = {
21834 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21835 .name = "events",
21836 .attrs = NULL, /* patched at runtime */
21837 };
21838 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21839 index 047f540..afdeba0 100644
21840 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21841 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21842 @@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21843 static int __init uncore_type_init(struct intel_uncore_type *type)
21844 {
21845 struct intel_uncore_pmu *pmus;
21846 - struct attribute_group *attr_group;
21847 + attribute_group_no_const *attr_group;
21848 struct attribute **attrs;
21849 int i, j;
21850
21851 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21852 index a80ab71..4089da5 100644
21853 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21854 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21855 @@ -498,7 +498,7 @@ struct intel_uncore_box {
21856 struct uncore_event_desc {
21857 struct kobj_attribute attr;
21858 const char *config;
21859 -};
21860 +} __do_const;
21861
21862 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21863 { \
21864 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21865 index 7d9481c..99c7e4b 100644
21866 --- a/arch/x86/kernel/cpuid.c
21867 +++ b/arch/x86/kernel/cpuid.c
21868 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21869 return notifier_from_errno(err);
21870 }
21871
21872 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21873 +static struct notifier_block cpuid_class_cpu_notifier =
21874 {
21875 .notifier_call = cpuid_class_cpu_callback,
21876 };
21877 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21878 index a57902e..ebaae2a 100644
21879 --- a/arch/x86/kernel/crash.c
21880 +++ b/arch/x86/kernel/crash.c
21881 @@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21882 {
21883 #ifdef CONFIG_X86_32
21884 struct pt_regs fixed_regs;
21885 -#endif
21886
21887 -#ifdef CONFIG_X86_32
21888 - if (!user_mode_vm(regs)) {
21889 + if (!user_mode(regs)) {
21890 crash_fixup_ss_esp(&fixed_regs, regs);
21891 regs = &fixed_regs;
21892 }
21893 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21894 index afa64ad..dce67dd 100644
21895 --- a/arch/x86/kernel/crash_dump_64.c
21896 +++ b/arch/x86/kernel/crash_dump_64.c
21897 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21898 return -ENOMEM;
21899
21900 if (userbuf) {
21901 - if (copy_to_user(buf, vaddr + offset, csize)) {
21902 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21903 iounmap(vaddr);
21904 return -EFAULT;
21905 }
21906 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21907 index f6dfd93..892ade4 100644
21908 --- a/arch/x86/kernel/doublefault.c
21909 +++ b/arch/x86/kernel/doublefault.c
21910 @@ -12,7 +12,7 @@
21911
21912 #define DOUBLEFAULT_STACKSIZE (1024)
21913 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21914 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21915 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21916
21917 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21918
21919 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21920 unsigned long gdt, tss;
21921
21922 native_store_gdt(&gdt_desc);
21923 - gdt = gdt_desc.address;
21924 + gdt = (unsigned long)gdt_desc.address;
21925
21926 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21927
21928 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21929 /* 0x2 bit is always set */
21930 .flags = X86_EFLAGS_SF | 0x2,
21931 .sp = STACK_START,
21932 - .es = __USER_DS,
21933 + .es = __KERNEL_DS,
21934 .cs = __KERNEL_CS,
21935 .ss = __KERNEL_DS,
21936 - .ds = __USER_DS,
21937 + .ds = __KERNEL_DS,
21938 .fs = __KERNEL_PERCPU,
21939
21940 .__cr3 = __pa_nodebug(swapper_pg_dir),
21941 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21942 index d9c12d3..7858b62 100644
21943 --- a/arch/x86/kernel/dumpstack.c
21944 +++ b/arch/x86/kernel/dumpstack.c
21945 @@ -2,6 +2,9 @@
21946 * Copyright (C) 1991, 1992 Linus Torvalds
21947 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21948 */
21949 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21950 +#define __INCLUDED_BY_HIDESYM 1
21951 +#endif
21952 #include <linux/kallsyms.h>
21953 #include <linux/kprobes.h>
21954 #include <linux/uaccess.h>
21955 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21956 static void
21957 print_ftrace_graph_addr(unsigned long addr, void *data,
21958 const struct stacktrace_ops *ops,
21959 - struct thread_info *tinfo, int *graph)
21960 + struct task_struct *task, int *graph)
21961 {
21962 - struct task_struct *task;
21963 unsigned long ret_addr;
21964 int index;
21965
21966 if (addr != (unsigned long)return_to_handler)
21967 return;
21968
21969 - task = tinfo->task;
21970 index = task->curr_ret_stack;
21971
21972 if (!task->ret_stack || index < *graph)
21973 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21974 static inline void
21975 print_ftrace_graph_addr(unsigned long addr, void *data,
21976 const struct stacktrace_ops *ops,
21977 - struct thread_info *tinfo, int *graph)
21978 + struct task_struct *task, int *graph)
21979 { }
21980 #endif
21981
21982 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21983 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21984 */
21985
21986 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21987 - void *p, unsigned int size, void *end)
21988 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21989 {
21990 - void *t = tinfo;
21991 if (end) {
21992 if (p < end && p >= (end-THREAD_SIZE))
21993 return 1;
21994 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21995 }
21996
21997 unsigned long
21998 -print_context_stack(struct thread_info *tinfo,
21999 +print_context_stack(struct task_struct *task, void *stack_start,
22000 unsigned long *stack, unsigned long bp,
22001 const struct stacktrace_ops *ops, void *data,
22002 unsigned long *end, int *graph)
22003 {
22004 struct stack_frame *frame = (struct stack_frame *)bp;
22005
22006 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22007 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22008 unsigned long addr;
22009
22010 addr = *stack;
22011 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22012 } else {
22013 ops->address(data, addr, 0);
22014 }
22015 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22016 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22017 }
22018 stack++;
22019 }
22020 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22021 EXPORT_SYMBOL_GPL(print_context_stack);
22022
22023 unsigned long
22024 -print_context_stack_bp(struct thread_info *tinfo,
22025 +print_context_stack_bp(struct task_struct *task, void *stack_start,
22026 unsigned long *stack, unsigned long bp,
22027 const struct stacktrace_ops *ops, void *data,
22028 unsigned long *end, int *graph)
22029 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22030 struct stack_frame *frame = (struct stack_frame *)bp;
22031 unsigned long *ret_addr = &frame->return_address;
22032
22033 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22034 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22035 unsigned long addr = *ret_addr;
22036
22037 if (!__kernel_text_address(addr))
22038 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22039 ops->address(data, addr, 1);
22040 frame = frame->next_frame;
22041 ret_addr = &frame->return_address;
22042 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22043 + print_ftrace_graph_addr(addr, data, ops, task, graph);
22044 }
22045
22046 return (unsigned long)frame;
22047 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22048 static void print_trace_address(void *data, unsigned long addr, int reliable)
22049 {
22050 touch_nmi_watchdog();
22051 - printk(data);
22052 + printk("%s", (char *)data);
22053 printk_stack_address(addr, reliable);
22054 }
22055
22056 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
22057 }
22058 EXPORT_SYMBOL_GPL(oops_begin);
22059
22060 +extern void gr_handle_kernel_exploit(void);
22061 +
22062 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22063 {
22064 if (regs && kexec_should_crash(current))
22065 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22066 panic("Fatal exception in interrupt");
22067 if (panic_on_oops)
22068 panic("Fatal exception");
22069 - do_exit(signr);
22070 +
22071 + gr_handle_kernel_exploit();
22072 +
22073 + do_group_exit(signr);
22074 }
22075
22076 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22077 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22078 print_modules();
22079 show_regs(regs);
22080 #ifdef CONFIG_X86_32
22081 - if (user_mode_vm(regs)) {
22082 + if (user_mode(regs)) {
22083 sp = regs->sp;
22084 ss = regs->ss & 0xffff;
22085 } else {
22086 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22087 unsigned long flags = oops_begin();
22088 int sig = SIGSEGV;
22089
22090 - if (!user_mode_vm(regs))
22091 + if (!user_mode(regs))
22092 report_bug(regs->ip, regs);
22093
22094 if (__die(str, regs, err))
22095 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22096 index f2a1770..10fa52d 100644
22097 --- a/arch/x86/kernel/dumpstack_32.c
22098 +++ b/arch/x86/kernel/dumpstack_32.c
22099 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22100 bp = stack_frame(task, regs);
22101
22102 for (;;) {
22103 - struct thread_info *context;
22104 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22105
22106 - context = (struct thread_info *)
22107 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
22108 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
22109 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22110
22111 - stack = (unsigned long *)context->previous_esp;
22112 - if (!stack)
22113 + if (stack_start == task_stack_page(task))
22114 break;
22115 + stack = *(unsigned long **)stack_start;
22116 if (ops->stack(data, "IRQ") < 0)
22117 break;
22118 touch_nmi_watchdog();
22119 @@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
22120 int i;
22121
22122 show_regs_print_info(KERN_EMERG);
22123 - __show_regs(regs, !user_mode_vm(regs));
22124 + __show_regs(regs, !user_mode(regs));
22125
22126 /*
22127 * When in-kernel, we also print out the stack and code at the
22128 * time of the fault..
22129 */
22130 - if (!user_mode_vm(regs)) {
22131 + if (!user_mode(regs)) {
22132 unsigned int code_prologue = code_bytes * 43 / 64;
22133 unsigned int code_len = code_bytes;
22134 unsigned char c;
22135 u8 *ip;
22136 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22137
22138 pr_emerg("Stack:\n");
22139 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22140
22141 pr_emerg("Code:");
22142
22143 - ip = (u8 *)regs->ip - code_prologue;
22144 + ip = (u8 *)regs->ip - code_prologue + cs_base;
22145 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22146 /* try starting at IP */
22147 - ip = (u8 *)regs->ip;
22148 + ip = (u8 *)regs->ip + cs_base;
22149 code_len = code_len - code_prologue + 1;
22150 }
22151 for (i = 0; i < code_len; i++, ip++) {
22152 @@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
22153 pr_cont(" Bad EIP value.");
22154 break;
22155 }
22156 - if (ip == (u8 *)regs->ip)
22157 + if (ip == (u8 *)regs->ip + cs_base)
22158 pr_cont(" <%02x>", c);
22159 else
22160 pr_cont(" %02x", c);
22161 @@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
22162 {
22163 unsigned short ud2;
22164
22165 + ip = ktla_ktva(ip);
22166 if (ip < PAGE_OFFSET)
22167 return 0;
22168 if (probe_kernel_address((unsigned short *)ip, ud2))
22169 @@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
22170
22171 return ud2 == 0x0b0f;
22172 }
22173 +
22174 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22175 +void pax_check_alloca(unsigned long size)
22176 +{
22177 + unsigned long sp = (unsigned long)&sp, stack_left;
22178 +
22179 + /* all kernel stacks are of the same size */
22180 + stack_left = sp & (THREAD_SIZE - 1);
22181 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22182 +}
22183 +EXPORT_SYMBOL(pax_check_alloca);
22184 +#endif
22185 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22186 index addb207..921706b 100644
22187 --- a/arch/x86/kernel/dumpstack_64.c
22188 +++ b/arch/x86/kernel/dumpstack_64.c
22189 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22190 unsigned long *irq_stack_end =
22191 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22192 unsigned used = 0;
22193 - struct thread_info *tinfo;
22194 int graph = 0;
22195 unsigned long dummy;
22196 + void *stack_start;
22197
22198 if (!task)
22199 task = current;
22200 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22201 * current stack address. If the stacks consist of nested
22202 * exceptions
22203 */
22204 - tinfo = task_thread_info(task);
22205 for (;;) {
22206 char *id;
22207 unsigned long *estack_end;
22208 +
22209 estack_end = in_exception_stack(cpu, (unsigned long)stack,
22210 &used, &id);
22211
22212 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22213 if (ops->stack(data, id) < 0)
22214 break;
22215
22216 - bp = ops->walk_stack(tinfo, stack, bp, ops,
22217 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
22218 data, estack_end, &graph);
22219 ops->stack(data, "<EOE>");
22220 /*
22221 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22222 * second-to-last pointer (index -2 to end) in the
22223 * exception stack:
22224 */
22225 + if ((u16)estack_end[-1] != __KERNEL_DS)
22226 + goto out;
22227 stack = (unsigned long *) estack_end[-2];
22228 continue;
22229 }
22230 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22231 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
22232 if (ops->stack(data, "IRQ") < 0)
22233 break;
22234 - bp = ops->walk_stack(tinfo, stack, bp,
22235 + bp = ops->walk_stack(task, irq_stack, stack, bp,
22236 ops, data, irq_stack_end, &graph);
22237 /*
22238 * We link to the next stack (which would be
22239 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22240 /*
22241 * This handles the process stack:
22242 */
22243 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22244 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22245 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22246 +out:
22247 put_cpu();
22248 }
22249 EXPORT_SYMBOL(dump_trace);
22250 @@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
22251
22252 return ud2 == 0x0b0f;
22253 }
22254 +
22255 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22256 +void pax_check_alloca(unsigned long size)
22257 +{
22258 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22259 + unsigned cpu, used;
22260 + char *id;
22261 +
22262 + /* check the process stack first */
22263 + stack_start = (unsigned long)task_stack_page(current);
22264 + stack_end = stack_start + THREAD_SIZE;
22265 + if (likely(stack_start <= sp && sp < stack_end)) {
22266 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
22267 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22268 + return;
22269 + }
22270 +
22271 + cpu = get_cpu();
22272 +
22273 + /* check the irq stacks */
22274 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22275 + stack_start = stack_end - IRQ_STACK_SIZE;
22276 + if (stack_start <= sp && sp < stack_end) {
22277 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22278 + put_cpu();
22279 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22280 + return;
22281 + }
22282 +
22283 + /* check the exception stacks */
22284 + used = 0;
22285 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22286 + stack_start = stack_end - EXCEPTION_STKSZ;
22287 + if (stack_end && stack_start <= sp && sp < stack_end) {
22288 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22289 + put_cpu();
22290 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
22291 + return;
22292 + }
22293 +
22294 + put_cpu();
22295 +
22296 + /* unknown stack */
22297 + BUG();
22298 +}
22299 +EXPORT_SYMBOL(pax_check_alloca);
22300 +#endif
22301 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22302 index 988c00a..4f673b6 100644
22303 --- a/arch/x86/kernel/e820.c
22304 +++ b/arch/x86/kernel/e820.c
22305 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22306
22307 static void early_panic(char *msg)
22308 {
22309 - early_printk(msg);
22310 - panic(msg);
22311 + early_printk("%s", msg);
22312 + panic("%s", msg);
22313 }
22314
22315 static int userdef __initdata;
22316 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22317 index 01d1c18..8073693 100644
22318 --- a/arch/x86/kernel/early_printk.c
22319 +++ b/arch/x86/kernel/early_printk.c
22320 @@ -7,6 +7,7 @@
22321 #include <linux/pci_regs.h>
22322 #include <linux/pci_ids.h>
22323 #include <linux/errno.h>
22324 +#include <linux/sched.h>
22325 #include <asm/io.h>
22326 #include <asm/processor.h>
22327 #include <asm/fcntl.h>
22328 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22329 index a2a4f46..6cab058 100644
22330 --- a/arch/x86/kernel/entry_32.S
22331 +++ b/arch/x86/kernel/entry_32.S
22332 @@ -177,13 +177,153 @@
22333 /*CFI_REL_OFFSET gs, PT_GS*/
22334 .endm
22335 .macro SET_KERNEL_GS reg
22336 +
22337 +#ifdef CONFIG_CC_STACKPROTECTOR
22338 movl $(__KERNEL_STACK_CANARY), \reg
22339 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22340 + movl $(__USER_DS), \reg
22341 +#else
22342 + xorl \reg, \reg
22343 +#endif
22344 +
22345 movl \reg, %gs
22346 .endm
22347
22348 #endif /* CONFIG_X86_32_LAZY_GS */
22349
22350 -.macro SAVE_ALL
22351 +.macro pax_enter_kernel
22352 +#ifdef CONFIG_PAX_KERNEXEC
22353 + call pax_enter_kernel
22354 +#endif
22355 +.endm
22356 +
22357 +.macro pax_exit_kernel
22358 +#ifdef CONFIG_PAX_KERNEXEC
22359 + call pax_exit_kernel
22360 +#endif
22361 +.endm
22362 +
22363 +#ifdef CONFIG_PAX_KERNEXEC
22364 +ENTRY(pax_enter_kernel)
22365 +#ifdef CONFIG_PARAVIRT
22366 + pushl %eax
22367 + pushl %ecx
22368 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22369 + mov %eax, %esi
22370 +#else
22371 + mov %cr0, %esi
22372 +#endif
22373 + bts $16, %esi
22374 + jnc 1f
22375 + mov %cs, %esi
22376 + cmp $__KERNEL_CS, %esi
22377 + jz 3f
22378 + ljmp $__KERNEL_CS, $3f
22379 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22380 +2:
22381 +#ifdef CONFIG_PARAVIRT
22382 + mov %esi, %eax
22383 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22384 +#else
22385 + mov %esi, %cr0
22386 +#endif
22387 +3:
22388 +#ifdef CONFIG_PARAVIRT
22389 + popl %ecx
22390 + popl %eax
22391 +#endif
22392 + ret
22393 +ENDPROC(pax_enter_kernel)
22394 +
22395 +ENTRY(pax_exit_kernel)
22396 +#ifdef CONFIG_PARAVIRT
22397 + pushl %eax
22398 + pushl %ecx
22399 +#endif
22400 + mov %cs, %esi
22401 + cmp $__KERNEXEC_KERNEL_CS, %esi
22402 + jnz 2f
22403 +#ifdef CONFIG_PARAVIRT
22404 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22405 + mov %eax, %esi
22406 +#else
22407 + mov %cr0, %esi
22408 +#endif
22409 + btr $16, %esi
22410 + ljmp $__KERNEL_CS, $1f
22411 +1:
22412 +#ifdef CONFIG_PARAVIRT
22413 + mov %esi, %eax
22414 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22415 +#else
22416 + mov %esi, %cr0
22417 +#endif
22418 +2:
22419 +#ifdef CONFIG_PARAVIRT
22420 + popl %ecx
22421 + popl %eax
22422 +#endif
22423 + ret
22424 +ENDPROC(pax_exit_kernel)
22425 +#endif
22426 +
22427 + .macro pax_erase_kstack
22428 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22429 + call pax_erase_kstack
22430 +#endif
22431 + .endm
22432 +
22433 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22434 +/*
22435 + * ebp: thread_info
22436 + */
22437 +ENTRY(pax_erase_kstack)
22438 + pushl %edi
22439 + pushl %ecx
22440 + pushl %eax
22441 +
22442 + mov TI_lowest_stack(%ebp), %edi
22443 + mov $-0xBEEF, %eax
22444 + std
22445 +
22446 +1: mov %edi, %ecx
22447 + and $THREAD_SIZE_asm - 1, %ecx
22448 + shr $2, %ecx
22449 + repne scasl
22450 + jecxz 2f
22451 +
22452 + cmp $2*16, %ecx
22453 + jc 2f
22454 +
22455 + mov $2*16, %ecx
22456 + repe scasl
22457 + jecxz 2f
22458 + jne 1b
22459 +
22460 +2: cld
22461 + mov %esp, %ecx
22462 + sub %edi, %ecx
22463 +
22464 + cmp $THREAD_SIZE_asm, %ecx
22465 + jb 3f
22466 + ud2
22467 +3:
22468 +
22469 + shr $2, %ecx
22470 + rep stosl
22471 +
22472 + mov TI_task_thread_sp0(%ebp), %edi
22473 + sub $128, %edi
22474 + mov %edi, TI_lowest_stack(%ebp)
22475 +
22476 + popl %eax
22477 + popl %ecx
22478 + popl %edi
22479 + ret
22480 +ENDPROC(pax_erase_kstack)
22481 +#endif
22482 +
22483 +.macro __SAVE_ALL _DS
22484 cld
22485 PUSH_GS
22486 pushl_cfi %fs
22487 @@ -206,7 +346,7 @@
22488 CFI_REL_OFFSET ecx, 0
22489 pushl_cfi %ebx
22490 CFI_REL_OFFSET ebx, 0
22491 - movl $(__USER_DS), %edx
22492 + movl $\_DS, %edx
22493 movl %edx, %ds
22494 movl %edx, %es
22495 movl $(__KERNEL_PERCPU), %edx
22496 @@ -214,6 +354,15 @@
22497 SET_KERNEL_GS %edx
22498 .endm
22499
22500 +.macro SAVE_ALL
22501 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22502 + __SAVE_ALL __KERNEL_DS
22503 + pax_enter_kernel
22504 +#else
22505 + __SAVE_ALL __USER_DS
22506 +#endif
22507 +.endm
22508 +
22509 .macro RESTORE_INT_REGS
22510 popl_cfi %ebx
22511 CFI_RESTORE ebx
22512 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22513 popfl_cfi
22514 jmp syscall_exit
22515 CFI_ENDPROC
22516 -END(ret_from_fork)
22517 +ENDPROC(ret_from_fork)
22518
22519 ENTRY(ret_from_kernel_thread)
22520 CFI_STARTPROC
22521 @@ -344,7 +493,15 @@ ret_from_intr:
22522 andl $SEGMENT_RPL_MASK, %eax
22523 #endif
22524 cmpl $USER_RPL, %eax
22525 +
22526 +#ifdef CONFIG_PAX_KERNEXEC
22527 + jae resume_userspace
22528 +
22529 + pax_exit_kernel
22530 + jmp resume_kernel
22531 +#else
22532 jb resume_kernel # not returning to v8086 or userspace
22533 +#endif
22534
22535 ENTRY(resume_userspace)
22536 LOCKDEP_SYS_EXIT
22537 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22538 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22539 # int/exception return?
22540 jne work_pending
22541 - jmp restore_all
22542 -END(ret_from_exception)
22543 + jmp restore_all_pax
22544 +ENDPROC(ret_from_exception)
22545
22546 #ifdef CONFIG_PREEMPT
22547 ENTRY(resume_kernel)
22548 @@ -369,7 +526,7 @@ need_resched:
22549 jz restore_all
22550 call preempt_schedule_irq
22551 jmp need_resched
22552 -END(resume_kernel)
22553 +ENDPROC(resume_kernel)
22554 #endif
22555 CFI_ENDPROC
22556 /*
22557 @@ -403,30 +560,45 @@ sysenter_past_esp:
22558 /*CFI_REL_OFFSET cs, 0*/
22559 /*
22560 * Push current_thread_info()->sysenter_return to the stack.
22561 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22562 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22563 */
22564 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22565 + pushl_cfi $0
22566 CFI_REL_OFFSET eip, 0
22567
22568 pushl_cfi %eax
22569 SAVE_ALL
22570 + GET_THREAD_INFO(%ebp)
22571 + movl TI_sysenter_return(%ebp),%ebp
22572 + movl %ebp,PT_EIP(%esp)
22573 ENABLE_INTERRUPTS(CLBR_NONE)
22574
22575 /*
22576 * Load the potential sixth argument from user stack.
22577 * Careful about security.
22578 */
22579 + movl PT_OLDESP(%esp),%ebp
22580 +
22581 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22582 + mov PT_OLDSS(%esp),%ds
22583 +1: movl %ds:(%ebp),%ebp
22584 + push %ss
22585 + pop %ds
22586 +#else
22587 cmpl $__PAGE_OFFSET-3,%ebp
22588 jae syscall_fault
22589 ASM_STAC
22590 1: movl (%ebp),%ebp
22591 ASM_CLAC
22592 +#endif
22593 +
22594 movl %ebp,PT_EBP(%esp)
22595 _ASM_EXTABLE(1b,syscall_fault)
22596
22597 GET_THREAD_INFO(%ebp)
22598
22599 +#ifdef CONFIG_PAX_RANDKSTACK
22600 + pax_erase_kstack
22601 +#endif
22602 +
22603 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22604 jnz sysenter_audit
22605 sysenter_do_call:
22606 @@ -441,12 +613,24 @@ sysenter_do_call:
22607 testl $_TIF_ALLWORK_MASK, %ecx
22608 jne sysexit_audit
22609 sysenter_exit:
22610 +
22611 +#ifdef CONFIG_PAX_RANDKSTACK
22612 + pushl_cfi %eax
22613 + movl %esp, %eax
22614 + call pax_randomize_kstack
22615 + popl_cfi %eax
22616 +#endif
22617 +
22618 + pax_erase_kstack
22619 +
22620 /* if something modifies registers it must also disable sysexit */
22621 movl PT_EIP(%esp), %edx
22622 movl PT_OLDESP(%esp), %ecx
22623 xorl %ebp,%ebp
22624 TRACE_IRQS_ON
22625 1: mov PT_FS(%esp), %fs
22626 +2: mov PT_DS(%esp), %ds
22627 +3: mov PT_ES(%esp), %es
22628 PTGS_TO_GS
22629 ENABLE_INTERRUPTS_SYSEXIT
22630
22631 @@ -463,6 +647,9 @@ sysenter_audit:
22632 movl %eax,%edx /* 2nd arg: syscall number */
22633 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22634 call __audit_syscall_entry
22635 +
22636 + pax_erase_kstack
22637 +
22638 pushl_cfi %ebx
22639 movl PT_EAX(%esp),%eax /* reload syscall number */
22640 jmp sysenter_do_call
22641 @@ -488,10 +675,16 @@ sysexit_audit:
22642
22643 CFI_ENDPROC
22644 .pushsection .fixup,"ax"
22645 -2: movl $0,PT_FS(%esp)
22646 +4: movl $0,PT_FS(%esp)
22647 + jmp 1b
22648 +5: movl $0,PT_DS(%esp)
22649 + jmp 1b
22650 +6: movl $0,PT_ES(%esp)
22651 jmp 1b
22652 .popsection
22653 - _ASM_EXTABLE(1b,2b)
22654 + _ASM_EXTABLE(1b,4b)
22655 + _ASM_EXTABLE(2b,5b)
22656 + _ASM_EXTABLE(3b,6b)
22657 PTGS_TO_GS_EX
22658 ENDPROC(ia32_sysenter_target)
22659
22660 @@ -506,6 +699,11 @@ ENTRY(system_call)
22661 pushl_cfi %eax # save orig_eax
22662 SAVE_ALL
22663 GET_THREAD_INFO(%ebp)
22664 +
22665 +#ifdef CONFIG_PAX_RANDKSTACK
22666 + pax_erase_kstack
22667 +#endif
22668 +
22669 # system call tracing in operation / emulation
22670 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22671 jnz syscall_trace_entry
22672 @@ -524,6 +722,15 @@ syscall_exit:
22673 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22674 jne syscall_exit_work
22675
22676 +restore_all_pax:
22677 +
22678 +#ifdef CONFIG_PAX_RANDKSTACK
22679 + movl %esp, %eax
22680 + call pax_randomize_kstack
22681 +#endif
22682 +
22683 + pax_erase_kstack
22684 +
22685 restore_all:
22686 TRACE_IRQS_IRET
22687 restore_all_notrace:
22688 @@ -580,14 +787,34 @@ ldt_ss:
22689 * compensating for the offset by changing to the ESPFIX segment with
22690 * a base address that matches for the difference.
22691 */
22692 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22693 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22694 mov %esp, %edx /* load kernel esp */
22695 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22696 mov %dx, %ax /* eax: new kernel esp */
22697 sub %eax, %edx /* offset (low word is 0) */
22698 +#ifdef CONFIG_SMP
22699 + movl PER_CPU_VAR(cpu_number), %ebx
22700 + shll $PAGE_SHIFT_asm, %ebx
22701 + addl $cpu_gdt_table, %ebx
22702 +#else
22703 + movl $cpu_gdt_table, %ebx
22704 +#endif
22705 shr $16, %edx
22706 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22707 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22708 +
22709 +#ifdef CONFIG_PAX_KERNEXEC
22710 + mov %cr0, %esi
22711 + btr $16, %esi
22712 + mov %esi, %cr0
22713 +#endif
22714 +
22715 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22716 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22717 +
22718 +#ifdef CONFIG_PAX_KERNEXEC
22719 + bts $16, %esi
22720 + mov %esi, %cr0
22721 +#endif
22722 +
22723 pushl_cfi $__ESPFIX_SS
22724 pushl_cfi %eax /* new kernel esp */
22725 /* Disable interrupts, but do not irqtrace this section: we
22726 @@ -616,20 +843,18 @@ work_resched:
22727 movl TI_flags(%ebp), %ecx
22728 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22729 # than syscall tracing?
22730 - jz restore_all
22731 + jz restore_all_pax
22732 testb $_TIF_NEED_RESCHED, %cl
22733 jnz work_resched
22734
22735 work_notifysig: # deal with pending signals and
22736 # notify-resume requests
22737 + movl %esp, %eax
22738 #ifdef CONFIG_VM86
22739 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22740 - movl %esp, %eax
22741 jne work_notifysig_v86 # returning to kernel-space or
22742 # vm86-space
22743 1:
22744 -#else
22745 - movl %esp, %eax
22746 #endif
22747 TRACE_IRQS_ON
22748 ENABLE_INTERRUPTS(CLBR_NONE)
22749 @@ -650,7 +875,7 @@ work_notifysig_v86:
22750 movl %eax, %esp
22751 jmp 1b
22752 #endif
22753 -END(work_pending)
22754 +ENDPROC(work_pending)
22755
22756 # perform syscall exit tracing
22757 ALIGN
22758 @@ -658,11 +883,14 @@ syscall_trace_entry:
22759 movl $-ENOSYS,PT_EAX(%esp)
22760 movl %esp, %eax
22761 call syscall_trace_enter
22762 +
22763 + pax_erase_kstack
22764 +
22765 /* What it returned is what we'll actually use. */
22766 cmpl $(NR_syscalls), %eax
22767 jnae syscall_call
22768 jmp syscall_exit
22769 -END(syscall_trace_entry)
22770 +ENDPROC(syscall_trace_entry)
22771
22772 # perform syscall exit tracing
22773 ALIGN
22774 @@ -675,21 +903,25 @@ syscall_exit_work:
22775 movl %esp, %eax
22776 call syscall_trace_leave
22777 jmp resume_userspace
22778 -END(syscall_exit_work)
22779 +ENDPROC(syscall_exit_work)
22780 CFI_ENDPROC
22781
22782 RING0_INT_FRAME # can't unwind into user space anyway
22783 syscall_fault:
22784 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22785 + push %ss
22786 + pop %ds
22787 +#endif
22788 ASM_CLAC
22789 GET_THREAD_INFO(%ebp)
22790 movl $-EFAULT,PT_EAX(%esp)
22791 jmp resume_userspace
22792 -END(syscall_fault)
22793 +ENDPROC(syscall_fault)
22794
22795 syscall_badsys:
22796 movl $-ENOSYS,PT_EAX(%esp)
22797 jmp resume_userspace
22798 -END(syscall_badsys)
22799 +ENDPROC(syscall_badsys)
22800 CFI_ENDPROC
22801 /*
22802 * End of kprobes section
22803 @@ -705,8 +937,15 @@ END(syscall_badsys)
22804 * normal stack and adjusts ESP with the matching offset.
22805 */
22806 /* fixup the stack */
22807 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22808 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22809 +#ifdef CONFIG_SMP
22810 + movl PER_CPU_VAR(cpu_number), %ebx
22811 + shll $PAGE_SHIFT_asm, %ebx
22812 + addl $cpu_gdt_table, %ebx
22813 +#else
22814 + movl $cpu_gdt_table, %ebx
22815 +#endif
22816 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22817 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22818 shl $16, %eax
22819 addl %esp, %eax /* the adjusted stack pointer */
22820 pushl_cfi $__KERNEL_DS
22821 @@ -759,7 +998,7 @@ vector=vector+1
22822 .endr
22823 2: jmp common_interrupt
22824 .endr
22825 -END(irq_entries_start)
22826 +ENDPROC(irq_entries_start)
22827
22828 .previous
22829 END(interrupt)
22830 @@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22831 pushl_cfi $do_coprocessor_error
22832 jmp error_code
22833 CFI_ENDPROC
22834 -END(coprocessor_error)
22835 +ENDPROC(coprocessor_error)
22836
22837 ENTRY(simd_coprocessor_error)
22838 RING0_INT_FRAME
22839 @@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22840 .section .altinstructions,"a"
22841 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22842 .previous
22843 -.section .altinstr_replacement,"ax"
22844 +.section .altinstr_replacement,"a"
22845 663: pushl $do_simd_coprocessor_error
22846 664:
22847 .previous
22848 @@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22849 #endif
22850 jmp error_code
22851 CFI_ENDPROC
22852 -END(simd_coprocessor_error)
22853 +ENDPROC(simd_coprocessor_error)
22854
22855 ENTRY(device_not_available)
22856 RING0_INT_FRAME
22857 @@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22858 pushl_cfi $do_device_not_available
22859 jmp error_code
22860 CFI_ENDPROC
22861 -END(device_not_available)
22862 +ENDPROC(device_not_available)
22863
22864 #ifdef CONFIG_PARAVIRT
22865 ENTRY(native_iret)
22866 iret
22867 _ASM_EXTABLE(native_iret, iret_exc)
22868 -END(native_iret)
22869 +ENDPROC(native_iret)
22870
22871 ENTRY(native_irq_enable_sysexit)
22872 sti
22873 sysexit
22874 -END(native_irq_enable_sysexit)
22875 +ENDPROC(native_irq_enable_sysexit)
22876 #endif
22877
22878 ENTRY(overflow)
22879 @@ -872,7 +1111,7 @@ ENTRY(overflow)
22880 pushl_cfi $do_overflow
22881 jmp error_code
22882 CFI_ENDPROC
22883 -END(overflow)
22884 +ENDPROC(overflow)
22885
22886 ENTRY(bounds)
22887 RING0_INT_FRAME
22888 @@ -881,7 +1120,7 @@ ENTRY(bounds)
22889 pushl_cfi $do_bounds
22890 jmp error_code
22891 CFI_ENDPROC
22892 -END(bounds)
22893 +ENDPROC(bounds)
22894
22895 ENTRY(invalid_op)
22896 RING0_INT_FRAME
22897 @@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22898 pushl_cfi $do_invalid_op
22899 jmp error_code
22900 CFI_ENDPROC
22901 -END(invalid_op)
22902 +ENDPROC(invalid_op)
22903
22904 ENTRY(coprocessor_segment_overrun)
22905 RING0_INT_FRAME
22906 @@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22907 pushl_cfi $do_coprocessor_segment_overrun
22908 jmp error_code
22909 CFI_ENDPROC
22910 -END(coprocessor_segment_overrun)
22911 +ENDPROC(coprocessor_segment_overrun)
22912
22913 ENTRY(invalid_TSS)
22914 RING0_EC_FRAME
22915 @@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22916 pushl_cfi $do_invalid_TSS
22917 jmp error_code
22918 CFI_ENDPROC
22919 -END(invalid_TSS)
22920 +ENDPROC(invalid_TSS)
22921
22922 ENTRY(segment_not_present)
22923 RING0_EC_FRAME
22924 @@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22925 pushl_cfi $do_segment_not_present
22926 jmp error_code
22927 CFI_ENDPROC
22928 -END(segment_not_present)
22929 +ENDPROC(segment_not_present)
22930
22931 ENTRY(stack_segment)
22932 RING0_EC_FRAME
22933 @@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22934 pushl_cfi $do_stack_segment
22935 jmp error_code
22936 CFI_ENDPROC
22937 -END(stack_segment)
22938 +ENDPROC(stack_segment)
22939
22940 ENTRY(alignment_check)
22941 RING0_EC_FRAME
22942 @@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22943 pushl_cfi $do_alignment_check
22944 jmp error_code
22945 CFI_ENDPROC
22946 -END(alignment_check)
22947 +ENDPROC(alignment_check)
22948
22949 ENTRY(divide_error)
22950 RING0_INT_FRAME
22951 @@ -940,7 +1179,7 @@ ENTRY(divide_error)
22952 pushl_cfi $do_divide_error
22953 jmp error_code
22954 CFI_ENDPROC
22955 -END(divide_error)
22956 +ENDPROC(divide_error)
22957
22958 #ifdef CONFIG_X86_MCE
22959 ENTRY(machine_check)
22960 @@ -950,7 +1189,7 @@ ENTRY(machine_check)
22961 pushl_cfi machine_check_vector
22962 jmp error_code
22963 CFI_ENDPROC
22964 -END(machine_check)
22965 +ENDPROC(machine_check)
22966 #endif
22967
22968 ENTRY(spurious_interrupt_bug)
22969 @@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22970 pushl_cfi $do_spurious_interrupt_bug
22971 jmp error_code
22972 CFI_ENDPROC
22973 -END(spurious_interrupt_bug)
22974 +ENDPROC(spurious_interrupt_bug)
22975 /*
22976 * End of kprobes section
22977 */
22978 @@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22979
22980 ENTRY(mcount)
22981 ret
22982 -END(mcount)
22983 +ENDPROC(mcount)
22984
22985 ENTRY(ftrace_caller)
22986 cmpl $0, function_trace_stop
22987 @@ -1103,7 +1342,7 @@ ftrace_graph_call:
22988 .globl ftrace_stub
22989 ftrace_stub:
22990 ret
22991 -END(ftrace_caller)
22992 +ENDPROC(ftrace_caller)
22993
22994 ENTRY(ftrace_regs_caller)
22995 pushf /* push flags before compare (in cs location) */
22996 @@ -1207,7 +1446,7 @@ trace:
22997 popl %ecx
22998 popl %eax
22999 jmp ftrace_stub
23000 -END(mcount)
23001 +ENDPROC(mcount)
23002 #endif /* CONFIG_DYNAMIC_FTRACE */
23003 #endif /* CONFIG_FUNCTION_TRACER */
23004
23005 @@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
23006 popl %ecx
23007 popl %eax
23008 ret
23009 -END(ftrace_graph_caller)
23010 +ENDPROC(ftrace_graph_caller)
23011
23012 .globl return_to_handler
23013 return_to_handler:
23014 @@ -1291,15 +1530,18 @@ error_code:
23015 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23016 REG_TO_PTGS %ecx
23017 SET_KERNEL_GS %ecx
23018 - movl $(__USER_DS), %ecx
23019 + movl $(__KERNEL_DS), %ecx
23020 movl %ecx, %ds
23021 movl %ecx, %es
23022 +
23023 + pax_enter_kernel
23024 +
23025 TRACE_IRQS_OFF
23026 movl %esp,%eax # pt_regs pointer
23027 call *%edi
23028 jmp ret_from_exception
23029 CFI_ENDPROC
23030 -END(page_fault)
23031 +ENDPROC(page_fault)
23032
23033 /*
23034 * Debug traps and NMI can happen at the one SYSENTER instruction
23035 @@ -1342,7 +1584,7 @@ debug_stack_correct:
23036 call do_debug
23037 jmp ret_from_exception
23038 CFI_ENDPROC
23039 -END(debug)
23040 +ENDPROC(debug)
23041
23042 /*
23043 * NMI is doubly nasty. It can happen _while_ we're handling
23044 @@ -1380,6 +1622,9 @@ nmi_stack_correct:
23045 xorl %edx,%edx # zero error code
23046 movl %esp,%eax # pt_regs pointer
23047 call do_nmi
23048 +
23049 + pax_exit_kernel
23050 +
23051 jmp restore_all_notrace
23052 CFI_ENDPROC
23053
23054 @@ -1416,12 +1661,15 @@ nmi_espfix_stack:
23055 FIXUP_ESPFIX_STACK # %eax == %esp
23056 xorl %edx,%edx # zero error code
23057 call do_nmi
23058 +
23059 + pax_exit_kernel
23060 +
23061 RESTORE_REGS
23062 lss 12+4(%esp), %esp # back to espfix stack
23063 CFI_ADJUST_CFA_OFFSET -24
23064 jmp irq_return
23065 CFI_ENDPROC
23066 -END(nmi)
23067 +ENDPROC(nmi)
23068
23069 ENTRY(int3)
23070 RING0_INT_FRAME
23071 @@ -1434,14 +1682,14 @@ ENTRY(int3)
23072 call do_int3
23073 jmp ret_from_exception
23074 CFI_ENDPROC
23075 -END(int3)
23076 +ENDPROC(int3)
23077
23078 ENTRY(general_protection)
23079 RING0_EC_FRAME
23080 pushl_cfi $do_general_protection
23081 jmp error_code
23082 CFI_ENDPROC
23083 -END(general_protection)
23084 +ENDPROC(general_protection)
23085
23086 #ifdef CONFIG_KVM_GUEST
23087 ENTRY(async_page_fault)
23088 @@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
23089 pushl_cfi $do_async_page_fault
23090 jmp error_code
23091 CFI_ENDPROC
23092 -END(async_page_fault)
23093 +ENDPROC(async_page_fault)
23094 #endif
23095
23096 /*
23097 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23098 index 1e96c36..3ff710a 100644
23099 --- a/arch/x86/kernel/entry_64.S
23100 +++ b/arch/x86/kernel/entry_64.S
23101 @@ -59,6 +59,8 @@
23102 #include <asm/context_tracking.h>
23103 #include <asm/smap.h>
23104 #include <linux/err.h>
23105 +#include <asm/pgtable.h>
23106 +#include <asm/alternative-asm.h>
23107
23108 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23109 #include <linux/elf-em.h>
23110 @@ -80,8 +82,9 @@
23111 #ifdef CONFIG_DYNAMIC_FTRACE
23112
23113 ENTRY(function_hook)
23114 + pax_force_retaddr
23115 retq
23116 -END(function_hook)
23117 +ENDPROC(function_hook)
23118
23119 /* skip is set if stack has been adjusted */
23120 .macro ftrace_caller_setup skip=0
23121 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
23122 #endif
23123
23124 GLOBAL(ftrace_stub)
23125 + pax_force_retaddr
23126 retq
23127 -END(ftrace_caller)
23128 +ENDPROC(ftrace_caller)
23129
23130 ENTRY(ftrace_regs_caller)
23131 /* Save the current flags before compare (in SS location)*/
23132 @@ -191,7 +195,7 @@ ftrace_restore_flags:
23133 popfq
23134 jmp ftrace_stub
23135
23136 -END(ftrace_regs_caller)
23137 +ENDPROC(ftrace_regs_caller)
23138
23139
23140 #else /* ! CONFIG_DYNAMIC_FTRACE */
23141 @@ -212,6 +216,7 @@ ENTRY(function_hook)
23142 #endif
23143
23144 GLOBAL(ftrace_stub)
23145 + pax_force_retaddr
23146 retq
23147
23148 trace:
23149 @@ -225,12 +230,13 @@ trace:
23150 #endif
23151 subq $MCOUNT_INSN_SIZE, %rdi
23152
23153 + pax_force_fptr ftrace_trace_function
23154 call *ftrace_trace_function
23155
23156 MCOUNT_RESTORE_FRAME
23157
23158 jmp ftrace_stub
23159 -END(function_hook)
23160 +ENDPROC(function_hook)
23161 #endif /* CONFIG_DYNAMIC_FTRACE */
23162 #endif /* CONFIG_FUNCTION_TRACER */
23163
23164 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
23165
23166 MCOUNT_RESTORE_FRAME
23167
23168 + pax_force_retaddr
23169 retq
23170 -END(ftrace_graph_caller)
23171 +ENDPROC(ftrace_graph_caller)
23172
23173 GLOBAL(return_to_handler)
23174 subq $24, %rsp
23175 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
23176 movq 8(%rsp), %rdx
23177 movq (%rsp), %rax
23178 addq $24, %rsp
23179 + pax_force_fptr %rdi
23180 jmp *%rdi
23181 +ENDPROC(return_to_handler)
23182 #endif
23183
23184
23185 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
23186 ENDPROC(native_usergs_sysret64)
23187 #endif /* CONFIG_PARAVIRT */
23188
23189 + .macro ljmpq sel, off
23190 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23191 + .byte 0x48; ljmp *1234f(%rip)
23192 + .pushsection .rodata
23193 + .align 16
23194 + 1234: .quad \off; .word \sel
23195 + .popsection
23196 +#else
23197 + pushq $\sel
23198 + pushq $\off
23199 + lretq
23200 +#endif
23201 + .endm
23202 +
23203 + .macro pax_enter_kernel
23204 + pax_set_fptr_mask
23205 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23206 + call pax_enter_kernel
23207 +#endif
23208 + .endm
23209 +
23210 + .macro pax_exit_kernel
23211 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23212 + call pax_exit_kernel
23213 +#endif
23214 +
23215 + .endm
23216 +
23217 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23218 +ENTRY(pax_enter_kernel)
23219 + pushq %rdi
23220 +
23221 +#ifdef CONFIG_PARAVIRT
23222 + PV_SAVE_REGS(CLBR_RDI)
23223 +#endif
23224 +
23225 +#ifdef CONFIG_PAX_KERNEXEC
23226 + GET_CR0_INTO_RDI
23227 + bts $16,%rdi
23228 + jnc 3f
23229 + mov %cs,%edi
23230 + cmp $__KERNEL_CS,%edi
23231 + jnz 2f
23232 +1:
23233 +#endif
23234 +
23235 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23236 + 661: jmp 111f
23237 + .pushsection .altinstr_replacement, "a"
23238 + 662: ASM_NOP2
23239 + .popsection
23240 + .pushsection .altinstructions, "a"
23241 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23242 + .popsection
23243 + GET_CR3_INTO_RDI
23244 + cmp $0,%dil
23245 + jnz 112f
23246 + mov $__KERNEL_DS,%edi
23247 + mov %edi,%ss
23248 + jmp 111f
23249 +112: cmp $1,%dil
23250 + jz 113f
23251 + ud2
23252 +113: sub $4097,%rdi
23253 + bts $63,%rdi
23254 + SET_RDI_INTO_CR3
23255 + mov $__UDEREF_KERNEL_DS,%edi
23256 + mov %edi,%ss
23257 +111:
23258 +#endif
23259 +
23260 +#ifdef CONFIG_PARAVIRT
23261 + PV_RESTORE_REGS(CLBR_RDI)
23262 +#endif
23263 +
23264 + popq %rdi
23265 + pax_force_retaddr
23266 + retq
23267 +
23268 +#ifdef CONFIG_PAX_KERNEXEC
23269 +2: ljmpq __KERNEL_CS,1b
23270 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
23271 +4: SET_RDI_INTO_CR0
23272 + jmp 1b
23273 +#endif
23274 +ENDPROC(pax_enter_kernel)
23275 +
23276 +ENTRY(pax_exit_kernel)
23277 + pushq %rdi
23278 +
23279 +#ifdef CONFIG_PARAVIRT
23280 + PV_SAVE_REGS(CLBR_RDI)
23281 +#endif
23282 +
23283 +#ifdef CONFIG_PAX_KERNEXEC
23284 + mov %cs,%rdi
23285 + cmp $__KERNEXEC_KERNEL_CS,%edi
23286 + jz 2f
23287 + GET_CR0_INTO_RDI
23288 + bts $16,%rdi
23289 + jnc 4f
23290 +1:
23291 +#endif
23292 +
23293 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23294 + 661: jmp 111f
23295 + .pushsection .altinstr_replacement, "a"
23296 + 662: ASM_NOP2
23297 + .popsection
23298 + .pushsection .altinstructions, "a"
23299 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23300 + .popsection
23301 + mov %ss,%edi
23302 + cmp $__UDEREF_KERNEL_DS,%edi
23303 + jnz 111f
23304 + GET_CR3_INTO_RDI
23305 + cmp $0,%dil
23306 + jz 112f
23307 + ud2
23308 +112: add $4097,%rdi
23309 + bts $63,%rdi
23310 + SET_RDI_INTO_CR3
23311 + mov $__KERNEL_DS,%edi
23312 + mov %edi,%ss
23313 +111:
23314 +#endif
23315 +
23316 +#ifdef CONFIG_PARAVIRT
23317 + PV_RESTORE_REGS(CLBR_RDI);
23318 +#endif
23319 +
23320 + popq %rdi
23321 + pax_force_retaddr
23322 + retq
23323 +
23324 +#ifdef CONFIG_PAX_KERNEXEC
23325 +2: GET_CR0_INTO_RDI
23326 + btr $16,%rdi
23327 + jnc 4f
23328 + ljmpq __KERNEL_CS,3f
23329 +3: SET_RDI_INTO_CR0
23330 + jmp 1b
23331 +4: ud2
23332 + jmp 4b
23333 +#endif
23334 +ENDPROC(pax_exit_kernel)
23335 +#endif
23336 +
23337 + .macro pax_enter_kernel_user
23338 + pax_set_fptr_mask
23339 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23340 + call pax_enter_kernel_user
23341 +#endif
23342 + .endm
23343 +
23344 + .macro pax_exit_kernel_user
23345 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23346 + call pax_exit_kernel_user
23347 +#endif
23348 +#ifdef CONFIG_PAX_RANDKSTACK
23349 + pushq %rax
23350 + pushq %r11
23351 + call pax_randomize_kstack
23352 + popq %r11
23353 + popq %rax
23354 +#endif
23355 + .endm
23356 +
23357 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23358 +ENTRY(pax_enter_kernel_user)
23359 + pushq %rdi
23360 + pushq %rbx
23361 +
23362 +#ifdef CONFIG_PARAVIRT
23363 + PV_SAVE_REGS(CLBR_RDI)
23364 +#endif
23365 +
23366 + 661: jmp 111f
23367 + .pushsection .altinstr_replacement, "a"
23368 + 662: ASM_NOP2
23369 + .popsection
23370 + .pushsection .altinstructions, "a"
23371 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23372 + .popsection
23373 + GET_CR3_INTO_RDI
23374 + cmp $1,%dil
23375 + jnz 4f
23376 + sub $4097,%rdi
23377 + bts $63,%rdi
23378 + SET_RDI_INTO_CR3
23379 + jmp 3f
23380 +111:
23381 +
23382 + GET_CR3_INTO_RDI
23383 + mov %rdi,%rbx
23384 + add $__START_KERNEL_map,%rbx
23385 + sub phys_base(%rip),%rbx
23386 +
23387 +#ifdef CONFIG_PARAVIRT
23388 + cmpl $0, pv_info+PARAVIRT_enabled
23389 + jz 1f
23390 + pushq %rdi
23391 + i = 0
23392 + .rept USER_PGD_PTRS
23393 + mov i*8(%rbx),%rsi
23394 + mov $0,%sil
23395 + lea i*8(%rbx),%rdi
23396 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23397 + i = i + 1
23398 + .endr
23399 + popq %rdi
23400 + jmp 2f
23401 +1:
23402 +#endif
23403 +
23404 + i = 0
23405 + .rept USER_PGD_PTRS
23406 + movb $0,i*8(%rbx)
23407 + i = i + 1
23408 + .endr
23409 +
23410 +2: SET_RDI_INTO_CR3
23411 +
23412 +#ifdef CONFIG_PAX_KERNEXEC
23413 + GET_CR0_INTO_RDI
23414 + bts $16,%rdi
23415 + SET_RDI_INTO_CR0
23416 +#endif
23417 +
23418 +3:
23419 +
23420 +#ifdef CONFIG_PARAVIRT
23421 + PV_RESTORE_REGS(CLBR_RDI)
23422 +#endif
23423 +
23424 + popq %rbx
23425 + popq %rdi
23426 + pax_force_retaddr
23427 + retq
23428 +4: ud2
23429 +ENDPROC(pax_enter_kernel_user)
23430 +
23431 +ENTRY(pax_exit_kernel_user)
23432 + pushq %rdi
23433 + pushq %rbx
23434 +
23435 +#ifdef CONFIG_PARAVIRT
23436 + PV_SAVE_REGS(CLBR_RDI)
23437 +#endif
23438 +
23439 + GET_CR3_INTO_RDI
23440 + 661: jmp 1f
23441 + .pushsection .altinstr_replacement, "a"
23442 + 662: ASM_NOP2
23443 + .popsection
23444 + .pushsection .altinstructions, "a"
23445 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23446 + .popsection
23447 + cmp $0,%dil
23448 + jnz 3f
23449 + add $4097,%rdi
23450 + bts $63,%rdi
23451 + SET_RDI_INTO_CR3
23452 + jmp 2f
23453 +1:
23454 +
23455 + mov %rdi,%rbx
23456 +
23457 +#ifdef CONFIG_PAX_KERNEXEC
23458 + GET_CR0_INTO_RDI
23459 + btr $16,%rdi
23460 + jnc 3f
23461 + SET_RDI_INTO_CR0
23462 +#endif
23463 +
23464 + add $__START_KERNEL_map,%rbx
23465 + sub phys_base(%rip),%rbx
23466 +
23467 +#ifdef CONFIG_PARAVIRT
23468 + cmpl $0, pv_info+PARAVIRT_enabled
23469 + jz 1f
23470 + i = 0
23471 + .rept USER_PGD_PTRS
23472 + mov i*8(%rbx),%rsi
23473 + mov $0x67,%sil
23474 + lea i*8(%rbx),%rdi
23475 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23476 + i = i + 1
23477 + .endr
23478 + jmp 2f
23479 +1:
23480 +#endif
23481 +
23482 + i = 0
23483 + .rept USER_PGD_PTRS
23484 + movb $0x67,i*8(%rbx)
23485 + i = i + 1
23486 + .endr
23487 +2:
23488 +
23489 +#ifdef CONFIG_PARAVIRT
23490 + PV_RESTORE_REGS(CLBR_RDI)
23491 +#endif
23492 +
23493 + popq %rbx
23494 + popq %rdi
23495 + pax_force_retaddr
23496 + retq
23497 +3: ud2
23498 +ENDPROC(pax_exit_kernel_user)
23499 +#endif
23500 +
23501 + .macro pax_enter_kernel_nmi
23502 + pax_set_fptr_mask
23503 +
23504 +#ifdef CONFIG_PAX_KERNEXEC
23505 + GET_CR0_INTO_RDI
23506 + bts $16,%rdi
23507 + jc 110f
23508 + SET_RDI_INTO_CR0
23509 + or $2,%ebx
23510 +110:
23511 +#endif
23512 +
23513 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23514 + 661: jmp 111f
23515 + .pushsection .altinstr_replacement, "a"
23516 + 662: ASM_NOP2
23517 + .popsection
23518 + .pushsection .altinstructions, "a"
23519 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23520 + .popsection
23521 + GET_CR3_INTO_RDI
23522 + cmp $0,%dil
23523 + jz 111f
23524 + sub $4097,%rdi
23525 + or $4,%ebx
23526 + bts $63,%rdi
23527 + SET_RDI_INTO_CR3
23528 + mov $__UDEREF_KERNEL_DS,%edi
23529 + mov %edi,%ss
23530 +111:
23531 +#endif
23532 + .endm
23533 +
23534 + .macro pax_exit_kernel_nmi
23535 +#ifdef CONFIG_PAX_KERNEXEC
23536 + btr $1,%ebx
23537 + jnc 110f
23538 + GET_CR0_INTO_RDI
23539 + btr $16,%rdi
23540 + SET_RDI_INTO_CR0
23541 +110:
23542 +#endif
23543 +
23544 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23545 + btr $2,%ebx
23546 + jnc 111f
23547 + GET_CR3_INTO_RDI
23548 + add $4097,%rdi
23549 + bts $63,%rdi
23550 + SET_RDI_INTO_CR3
23551 + mov $__KERNEL_DS,%edi
23552 + mov %edi,%ss
23553 +111:
23554 +#endif
23555 + .endm
23556 +
23557 + .macro pax_erase_kstack
23558 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23559 + call pax_erase_kstack
23560 +#endif
23561 + .endm
23562 +
23563 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23564 +ENTRY(pax_erase_kstack)
23565 + pushq %rdi
23566 + pushq %rcx
23567 + pushq %rax
23568 + pushq %r11
23569 +
23570 + GET_THREAD_INFO(%r11)
23571 + mov TI_lowest_stack(%r11), %rdi
23572 + mov $-0xBEEF, %rax
23573 + std
23574 +
23575 +1: mov %edi, %ecx
23576 + and $THREAD_SIZE_asm - 1, %ecx
23577 + shr $3, %ecx
23578 + repne scasq
23579 + jecxz 2f
23580 +
23581 + cmp $2*8, %ecx
23582 + jc 2f
23583 +
23584 + mov $2*8, %ecx
23585 + repe scasq
23586 + jecxz 2f
23587 + jne 1b
23588 +
23589 +2: cld
23590 + mov %esp, %ecx
23591 + sub %edi, %ecx
23592 +
23593 + cmp $THREAD_SIZE_asm, %rcx
23594 + jb 3f
23595 + ud2
23596 +3:
23597 +
23598 + shr $3, %ecx
23599 + rep stosq
23600 +
23601 + mov TI_task_thread_sp0(%r11), %rdi
23602 + sub $256, %rdi
23603 + mov %rdi, TI_lowest_stack(%r11)
23604 +
23605 + popq %r11
23606 + popq %rax
23607 + popq %rcx
23608 + popq %rdi
23609 + pax_force_retaddr
23610 + ret
23611 +ENDPROC(pax_erase_kstack)
23612 +#endif
23613
23614 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23615 #ifdef CONFIG_TRACE_IRQFLAGS
23616 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23617 .endm
23618
23619 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23620 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23621 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23622 jnc 1f
23623 TRACE_IRQS_ON_DEBUG
23624 1:
23625 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23626 movq \tmp,R11+\offset(%rsp)
23627 .endm
23628
23629 - .macro FAKE_STACK_FRAME child_rip
23630 - /* push in order ss, rsp, eflags, cs, rip */
23631 - xorl %eax, %eax
23632 - pushq_cfi $__KERNEL_DS /* ss */
23633 - /*CFI_REL_OFFSET ss,0*/
23634 - pushq_cfi %rax /* rsp */
23635 - CFI_REL_OFFSET rsp,0
23636 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23637 - /*CFI_REL_OFFSET rflags,0*/
23638 - pushq_cfi $__KERNEL_CS /* cs */
23639 - /*CFI_REL_OFFSET cs,0*/
23640 - pushq_cfi \child_rip /* rip */
23641 - CFI_REL_OFFSET rip,0
23642 - pushq_cfi %rax /* orig rax */
23643 - .endm
23644 -
23645 - .macro UNFAKE_STACK_FRAME
23646 - addq $8*6, %rsp
23647 - CFI_ADJUST_CFA_OFFSET -(6*8)
23648 - .endm
23649 -
23650 /*
23651 * initial frame state for interrupts (and exceptions without error code)
23652 */
23653 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23654 /* save partial stack frame */
23655 .macro SAVE_ARGS_IRQ
23656 cld
23657 - /* start from rbp in pt_regs and jump over */
23658 - movq_cfi rdi, (RDI-RBP)
23659 - movq_cfi rsi, (RSI-RBP)
23660 - movq_cfi rdx, (RDX-RBP)
23661 - movq_cfi rcx, (RCX-RBP)
23662 - movq_cfi rax, (RAX-RBP)
23663 - movq_cfi r8, (R8-RBP)
23664 - movq_cfi r9, (R9-RBP)
23665 - movq_cfi r10, (R10-RBP)
23666 - movq_cfi r11, (R11-RBP)
23667 + /* start from r15 in pt_regs and jump over */
23668 + movq_cfi rdi, RDI
23669 + movq_cfi rsi, RSI
23670 + movq_cfi rdx, RDX
23671 + movq_cfi rcx, RCX
23672 + movq_cfi rax, RAX
23673 + movq_cfi r8, R8
23674 + movq_cfi r9, R9
23675 + movq_cfi r10, R10
23676 + movq_cfi r11, R11
23677 + movq_cfi r12, R12
23678
23679 /* Save rbp so that we can unwind from get_irq_regs() */
23680 - movq_cfi rbp, 0
23681 + movq_cfi rbp, RBP
23682
23683 /* Save previous stack value */
23684 movq %rsp, %rsi
23685
23686 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23687 - testl $3, CS-RBP(%rsi)
23688 + movq %rsp,%rdi /* arg1 for handler */
23689 + testb $3, CS(%rsi)
23690 je 1f
23691 SWAPGS
23692 /*
23693 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23694 0x06 /* DW_OP_deref */, \
23695 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23696 0x22 /* DW_OP_plus */
23697 +
23698 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23699 + testb $3, CS(%rdi)
23700 + jnz 1f
23701 + pax_enter_kernel
23702 + jmp 2f
23703 +1: pax_enter_kernel_user
23704 +2:
23705 +#else
23706 + pax_enter_kernel
23707 +#endif
23708 +
23709 /* We entered an interrupt context - irqs are off: */
23710 TRACE_IRQS_OFF
23711 .endm
23712 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23713 js 1f /* negative -> in kernel */
23714 SWAPGS
23715 xorl %ebx,%ebx
23716 -1: ret
23717 +1:
23718 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23719 + testb $3, CS+8(%rsp)
23720 + jnz 1f
23721 + pax_enter_kernel
23722 + jmp 2f
23723 +1: pax_enter_kernel_user
23724 +2:
23725 +#else
23726 + pax_enter_kernel
23727 +#endif
23728 + pax_force_retaddr
23729 + ret
23730 CFI_ENDPROC
23731 -END(save_paranoid)
23732 +ENDPROC(save_paranoid)
23733 +
23734 +ENTRY(save_paranoid_nmi)
23735 + XCPT_FRAME 1 RDI+8
23736 + cld
23737 + movq_cfi rdi, RDI+8
23738 + movq_cfi rsi, RSI+8
23739 + movq_cfi rdx, RDX+8
23740 + movq_cfi rcx, RCX+8
23741 + movq_cfi rax, RAX+8
23742 + movq_cfi r8, R8+8
23743 + movq_cfi r9, R9+8
23744 + movq_cfi r10, R10+8
23745 + movq_cfi r11, R11+8
23746 + movq_cfi rbx, RBX+8
23747 + movq_cfi rbp, RBP+8
23748 + movq_cfi r12, R12+8
23749 + movq_cfi r13, R13+8
23750 + movq_cfi r14, R14+8
23751 + movq_cfi r15, R15+8
23752 + movl $1,%ebx
23753 + movl $MSR_GS_BASE,%ecx
23754 + rdmsr
23755 + testl %edx,%edx
23756 + js 1f /* negative -> in kernel */
23757 + SWAPGS
23758 + xorl %ebx,%ebx
23759 +1: pax_enter_kernel_nmi
23760 + pax_force_retaddr
23761 + ret
23762 + CFI_ENDPROC
23763 +ENDPROC(save_paranoid_nmi)
23764 .popsection
23765
23766 /*
23767 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23768
23769 RESTORE_REST
23770
23771 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23772 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23773 jz 1f
23774
23775 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23776 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23777 jmp ret_from_sys_call # go to the SYSRET fastpath
23778
23779 1:
23780 - subq $REST_SKIP, %rsp # leave space for volatiles
23781 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23782 movq %rbp, %rdi
23783 call *%rbx
23784 movl $0, RAX(%rsp)
23785 RESTORE_REST
23786 jmp int_ret_from_sys_call
23787 CFI_ENDPROC
23788 -END(ret_from_fork)
23789 +ENDPROC(ret_from_fork)
23790
23791 /*
23792 * System call entry. Up to 6 arguments in registers are supported.
23793 @@ -593,7 +1059,7 @@ END(ret_from_fork)
23794 ENTRY(system_call)
23795 CFI_STARTPROC simple
23796 CFI_SIGNAL_FRAME
23797 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23798 + CFI_DEF_CFA rsp,0
23799 CFI_REGISTER rip,rcx
23800 /*CFI_REGISTER rflags,r11*/
23801 SWAPGS_UNSAFE_STACK
23802 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23803
23804 movq %rsp,PER_CPU_VAR(old_rsp)
23805 movq PER_CPU_VAR(kernel_stack),%rsp
23806 + SAVE_ARGS 8*6,0
23807 + pax_enter_kernel_user
23808 +
23809 +#ifdef CONFIG_PAX_RANDKSTACK
23810 + pax_erase_kstack
23811 +#endif
23812 +
23813 /*
23814 * No need to follow this irqs off/on section - it's straight
23815 * and short:
23816 */
23817 ENABLE_INTERRUPTS(CLBR_NONE)
23818 - SAVE_ARGS 8,0
23819 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23820 movq %rcx,RIP-ARGOFFSET(%rsp)
23821 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23822 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23823 + GET_THREAD_INFO(%rcx)
23824 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23825 jnz tracesys
23826 system_call_fastpath:
23827 #if __SYSCALL_MASK == ~0
23828 @@ -639,10 +1112,13 @@ sysret_check:
23829 LOCKDEP_SYS_EXIT
23830 DISABLE_INTERRUPTS(CLBR_NONE)
23831 TRACE_IRQS_OFF
23832 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23833 + GET_THREAD_INFO(%rcx)
23834 + movl TI_flags(%rcx),%edx
23835 andl %edi,%edx
23836 jnz sysret_careful
23837 CFI_REMEMBER_STATE
23838 + pax_exit_kernel_user
23839 + pax_erase_kstack
23840 /*
23841 * sysretq will re-enable interrupts:
23842 */
23843 @@ -701,6 +1177,9 @@ auditsys:
23844 movq %rax,%rsi /* 2nd arg: syscall number */
23845 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23846 call __audit_syscall_entry
23847 +
23848 + pax_erase_kstack
23849 +
23850 LOAD_ARGS 0 /* reload call-clobbered registers */
23851 jmp system_call_fastpath
23852
23853 @@ -722,7 +1201,7 @@ sysret_audit:
23854 /* Do syscall tracing */
23855 tracesys:
23856 #ifdef CONFIG_AUDITSYSCALL
23857 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23858 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23859 jz auditsys
23860 #endif
23861 SAVE_REST
23862 @@ -730,12 +1209,15 @@ tracesys:
23863 FIXUP_TOP_OF_STACK %rdi
23864 movq %rsp,%rdi
23865 call syscall_trace_enter
23866 +
23867 + pax_erase_kstack
23868 +
23869 /*
23870 * Reload arg registers from stack in case ptrace changed them.
23871 * We don't reload %rax because syscall_trace_enter() returned
23872 * the value it wants us to use in the table lookup.
23873 */
23874 - LOAD_ARGS ARGOFFSET, 1
23875 + LOAD_ARGS 1
23876 RESTORE_REST
23877 #if __SYSCALL_MASK == ~0
23878 cmpq $__NR_syscall_max,%rax
23879 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23880 andl %edi,%edx
23881 jnz int_careful
23882 andl $~TS_COMPAT,TI_status(%rcx)
23883 - jmp retint_swapgs
23884 + pax_exit_kernel_user
23885 + pax_erase_kstack
23886 + jmp retint_swapgs_pax
23887
23888 /* Either reschedule or signal or syscall exit tracking needed. */
23889 /* First do a reschedule test. */
23890 @@ -811,7 +1295,7 @@ int_restore_rest:
23891 TRACE_IRQS_OFF
23892 jmp int_with_check
23893 CFI_ENDPROC
23894 -END(system_call)
23895 +ENDPROC(system_call)
23896
23897 .macro FORK_LIKE func
23898 ENTRY(stub_\func)
23899 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23900 DEFAULT_FRAME 0 8 /* offset 8: return address */
23901 call sys_\func
23902 RESTORE_TOP_OF_STACK %r11, 8
23903 - ret $REST_SKIP /* pop extended registers */
23904 + pax_force_retaddr
23905 + ret
23906 CFI_ENDPROC
23907 -END(stub_\func)
23908 +ENDPROC(stub_\func)
23909 .endm
23910
23911 .macro FIXED_FRAME label,func
23912 @@ -836,9 +1321,10 @@ ENTRY(\label)
23913 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23914 call \func
23915 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23916 + pax_force_retaddr
23917 ret
23918 CFI_ENDPROC
23919 -END(\label)
23920 +ENDPROC(\label)
23921 .endm
23922
23923 FORK_LIKE clone
23924 @@ -846,19 +1332,6 @@ END(\label)
23925 FORK_LIKE vfork
23926 FIXED_FRAME stub_iopl, sys_iopl
23927
23928 -ENTRY(ptregscall_common)
23929 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23930 - RESTORE_TOP_OF_STACK %r11, 8
23931 - movq_cfi_restore R15+8, r15
23932 - movq_cfi_restore R14+8, r14
23933 - movq_cfi_restore R13+8, r13
23934 - movq_cfi_restore R12+8, r12
23935 - movq_cfi_restore RBP+8, rbp
23936 - movq_cfi_restore RBX+8, rbx
23937 - ret $REST_SKIP /* pop extended registers */
23938 - CFI_ENDPROC
23939 -END(ptregscall_common)
23940 -
23941 ENTRY(stub_execve)
23942 CFI_STARTPROC
23943 addq $8, %rsp
23944 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23945 RESTORE_REST
23946 jmp int_ret_from_sys_call
23947 CFI_ENDPROC
23948 -END(stub_execve)
23949 +ENDPROC(stub_execve)
23950
23951 /*
23952 * sigreturn is special because it needs to restore all registers on return.
23953 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23954 RESTORE_REST
23955 jmp int_ret_from_sys_call
23956 CFI_ENDPROC
23957 -END(stub_rt_sigreturn)
23958 +ENDPROC(stub_rt_sigreturn)
23959
23960 #ifdef CONFIG_X86_X32_ABI
23961 ENTRY(stub_x32_rt_sigreturn)
23962 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23963 RESTORE_REST
23964 jmp int_ret_from_sys_call
23965 CFI_ENDPROC
23966 -END(stub_x32_rt_sigreturn)
23967 +ENDPROC(stub_x32_rt_sigreturn)
23968
23969 ENTRY(stub_x32_execve)
23970 CFI_STARTPROC
23971 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23972 RESTORE_REST
23973 jmp int_ret_from_sys_call
23974 CFI_ENDPROC
23975 -END(stub_x32_execve)
23976 +ENDPROC(stub_x32_execve)
23977
23978 #endif
23979
23980 @@ -952,7 +1425,7 @@ vector=vector+1
23981 2: jmp common_interrupt
23982 .endr
23983 CFI_ENDPROC
23984 -END(irq_entries_start)
23985 +ENDPROC(irq_entries_start)
23986
23987 .previous
23988 END(interrupt)
23989 @@ -969,8 +1442,8 @@ END(interrupt)
23990 /* 0(%rsp): ~(interrupt number) */
23991 .macro interrupt func
23992 /* reserve pt_regs for scratch regs and rbp */
23993 - subq $ORIG_RAX-RBP, %rsp
23994 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23995 + subq $ORIG_RAX, %rsp
23996 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23997 SAVE_ARGS_IRQ
23998 call \func
23999 .endm
24000 @@ -997,14 +1470,14 @@ ret_from_intr:
24001
24002 /* Restore saved previous stack */
24003 popq %rsi
24004 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24005 - leaq ARGOFFSET-RBP(%rsi), %rsp
24006 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24007 + movq %rsi, %rsp
24008 CFI_DEF_CFA_REGISTER rsp
24009 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24010 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24011
24012 exit_intr:
24013 GET_THREAD_INFO(%rcx)
24014 - testl $3,CS-ARGOFFSET(%rsp)
24015 + testb $3,CS-ARGOFFSET(%rsp)
24016 je retint_kernel
24017
24018 /* Interrupt came from user space */
24019 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
24020 * The iretq could re-enable interrupts:
24021 */
24022 DISABLE_INTERRUPTS(CLBR_ANY)
24023 + pax_exit_kernel_user
24024 +retint_swapgs_pax:
24025 TRACE_IRQS_IRETQ
24026 SWAPGS
24027 jmp restore_args
24028
24029 retint_restore_args: /* return to kernel space */
24030 DISABLE_INTERRUPTS(CLBR_ANY)
24031 + pax_exit_kernel
24032 + pax_force_retaddr (RIP-ARGOFFSET)
24033 /*
24034 * The iretq could re-enable interrupts:
24035 */
24036 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
24037 #endif
24038
24039 CFI_ENDPROC
24040 -END(common_interrupt)
24041 +ENDPROC(common_interrupt)
24042 /*
24043 * End of kprobes section
24044 */
24045 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
24046 interrupt \do_sym
24047 jmp ret_from_intr
24048 CFI_ENDPROC
24049 -END(\sym)
24050 +ENDPROC(\sym)
24051 .endm
24052
24053 #ifdef CONFIG_TRACING
24054 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
24055 call \do_sym
24056 jmp error_exit /* %ebx: no swapgs flag */
24057 CFI_ENDPROC
24058 -END(\sym)
24059 +ENDPROC(\sym)
24060 .endm
24061
24062 .macro paranoidzeroentry sym do_sym
24063 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
24064 call \do_sym
24065 jmp paranoid_exit /* %ebx: no swapgs flag */
24066 CFI_ENDPROC
24067 -END(\sym)
24068 +ENDPROC(\sym)
24069 .endm
24070
24071 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24072 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24073 .macro paranoidzeroentry_ist sym do_sym ist
24074 ENTRY(\sym)
24075 INTR_FRAME
24076 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
24077 TRACE_IRQS_OFF_DEBUG
24078 movq %rsp,%rdi /* pt_regs pointer */
24079 xorl %esi,%esi /* no error code */
24080 +#ifdef CONFIG_SMP
24081 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24082 + lea init_tss(%r13), %r13
24083 +#else
24084 + lea init_tss(%rip), %r13
24085 +#endif
24086 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24087 call \do_sym
24088 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24089 jmp paranoid_exit /* %ebx: no swapgs flag */
24090 CFI_ENDPROC
24091 -END(\sym)
24092 +ENDPROC(\sym)
24093 .endm
24094
24095 .macro errorentry sym do_sym
24096 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
24097 call \do_sym
24098 jmp error_exit /* %ebx: no swapgs flag */
24099 CFI_ENDPROC
24100 -END(\sym)
24101 +ENDPROC(\sym)
24102 .endm
24103
24104 #ifdef CONFIG_TRACING
24105 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
24106 call \do_sym
24107 jmp paranoid_exit /* %ebx: no swapgs flag */
24108 CFI_ENDPROC
24109 -END(\sym)
24110 +ENDPROC(\sym)
24111 .endm
24112
24113 zeroentry divide_error do_divide_error
24114 @@ -1336,9 +1819,10 @@ gs_change:
24115 2: mfence /* workaround */
24116 SWAPGS
24117 popfq_cfi
24118 + pax_force_retaddr
24119 ret
24120 CFI_ENDPROC
24121 -END(native_load_gs_index)
24122 +ENDPROC(native_load_gs_index)
24123
24124 _ASM_EXTABLE(gs_change,bad_gs)
24125 .section .fixup,"ax"
24126 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
24127 CFI_DEF_CFA_REGISTER rsp
24128 CFI_ADJUST_CFA_OFFSET -8
24129 decl PER_CPU_VAR(irq_count)
24130 + pax_force_retaddr
24131 ret
24132 CFI_ENDPROC
24133 -END(do_softirq_own_stack)
24134 +ENDPROC(do_softirq_own_stack)
24135
24136 #ifdef CONFIG_XEN
24137 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
24138 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24139 decl PER_CPU_VAR(irq_count)
24140 jmp error_exit
24141 CFI_ENDPROC
24142 -END(xen_do_hypervisor_callback)
24143 +ENDPROC(xen_do_hypervisor_callback)
24144
24145 /*
24146 * Hypervisor uses this for application faults while it executes.
24147 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
24148 SAVE_ALL
24149 jmp error_exit
24150 CFI_ENDPROC
24151 -END(xen_failsafe_callback)
24152 +ENDPROC(xen_failsafe_callback)
24153
24154 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24155 xen_hvm_callback_vector xen_evtchn_do_upcall
24156 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
24157 DEFAULT_FRAME
24158 DISABLE_INTERRUPTS(CLBR_NONE)
24159 TRACE_IRQS_OFF_DEBUG
24160 - testl %ebx,%ebx /* swapgs needed? */
24161 + testl $1,%ebx /* swapgs needed? */
24162 jnz paranoid_restore
24163 - testl $3,CS(%rsp)
24164 + testb $3,CS(%rsp)
24165 jnz paranoid_userspace
24166 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24167 + pax_exit_kernel
24168 + TRACE_IRQS_IRETQ 0
24169 + SWAPGS_UNSAFE_STACK
24170 + RESTORE_ALL 8
24171 + pax_force_retaddr_bts
24172 + jmp irq_return
24173 +#endif
24174 paranoid_swapgs:
24175 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24176 + pax_exit_kernel_user
24177 +#else
24178 + pax_exit_kernel
24179 +#endif
24180 TRACE_IRQS_IRETQ 0
24181 SWAPGS_UNSAFE_STACK
24182 RESTORE_ALL 8
24183 jmp irq_return
24184 paranoid_restore:
24185 + pax_exit_kernel
24186 TRACE_IRQS_IRETQ_DEBUG 0
24187 RESTORE_ALL 8
24188 + pax_force_retaddr_bts
24189 jmp irq_return
24190 paranoid_userspace:
24191 GET_THREAD_INFO(%rcx)
24192 @@ -1557,7 +2057,7 @@ paranoid_schedule:
24193 TRACE_IRQS_OFF
24194 jmp paranoid_userspace
24195 CFI_ENDPROC
24196 -END(paranoid_exit)
24197 +ENDPROC(paranoid_exit)
24198
24199 /*
24200 * Exception entry point. This expects an error code/orig_rax on the stack.
24201 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
24202 movq_cfi r14, R14+8
24203 movq_cfi r15, R15+8
24204 xorl %ebx,%ebx
24205 - testl $3,CS+8(%rsp)
24206 + testb $3,CS+8(%rsp)
24207 je error_kernelspace
24208 error_swapgs:
24209 SWAPGS
24210 error_sti:
24211 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24212 + testb $3, CS+8(%rsp)
24213 + jnz 1f
24214 + pax_enter_kernel
24215 + jmp 2f
24216 +1: pax_enter_kernel_user
24217 +2:
24218 +#else
24219 + pax_enter_kernel
24220 +#endif
24221 TRACE_IRQS_OFF
24222 + pax_force_retaddr
24223 ret
24224
24225 /*
24226 @@ -1616,7 +2127,7 @@ bstep_iret:
24227 movq %rcx,RIP+8(%rsp)
24228 jmp error_swapgs
24229 CFI_ENDPROC
24230 -END(error_entry)
24231 +ENDPROC(error_entry)
24232
24233
24234 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24235 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
24236 DISABLE_INTERRUPTS(CLBR_NONE)
24237 TRACE_IRQS_OFF
24238 GET_THREAD_INFO(%rcx)
24239 - testl %eax,%eax
24240 + testl $1,%eax
24241 jne retint_kernel
24242 LOCKDEP_SYS_EXIT_IRQ
24243 movl TI_flags(%rcx),%edx
24244 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
24245 jnz retint_careful
24246 jmp retint_swapgs
24247 CFI_ENDPROC
24248 -END(error_exit)
24249 +ENDPROC(error_exit)
24250
24251 /*
24252 * Test if a given stack is an NMI stack or not.
24253 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
24254 * If %cs was not the kernel segment, then the NMI triggered in user
24255 * space, which means it is definitely not nested.
24256 */
24257 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24258 + je 1f
24259 cmpl $__KERNEL_CS, 16(%rsp)
24260 jne first_nmi
24261 -
24262 +1:
24263 /*
24264 * Check the special variable on the stack to see if NMIs are
24265 * executing.
24266 @@ -1730,8 +2243,7 @@ nested_nmi:
24267
24268 1:
24269 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24270 - leaq -1*8(%rsp), %rdx
24271 - movq %rdx, %rsp
24272 + subq $8, %rsp
24273 CFI_ADJUST_CFA_OFFSET 1*8
24274 leaq -10*8(%rsp), %rdx
24275 pushq_cfi $__KERNEL_DS
24276 @@ -1749,6 +2261,7 @@ nested_nmi_out:
24277 CFI_RESTORE rdx
24278
24279 /* No need to check faults here */
24280 +# pax_force_retaddr_bts
24281 INTERRUPT_RETURN
24282
24283 CFI_RESTORE_STATE
24284 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
24285 subq $ORIG_RAX-R15, %rsp
24286 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24287 /*
24288 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24289 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24290 * as we should not be calling schedule in NMI context.
24291 * Even with normal interrupts enabled. An NMI should not be
24292 * setting NEED_RESCHED or anything that normal interrupts and
24293 * exceptions might do.
24294 */
24295 - call save_paranoid
24296 + call save_paranoid_nmi
24297 DEFAULT_FRAME 0
24298
24299 /*
24300 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
24301 * NMI itself takes a page fault, the page fault that was preempted
24302 * will read the information from the NMI page fault and not the
24303 * origin fault. Save it off and restore it if it changes.
24304 - * Use the r12 callee-saved register.
24305 + * Use the r13 callee-saved register.
24306 */
24307 - movq %cr2, %r12
24308 + movq %cr2, %r13
24309
24310 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24311 movq %rsp,%rdi
24312 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
24313
24314 /* Did the NMI take a page fault? Restore cr2 if it did */
24315 movq %cr2, %rcx
24316 - cmpq %rcx, %r12
24317 + cmpq %rcx, %r13
24318 je 1f
24319 - movq %r12, %cr2
24320 + movq %r13, %cr2
24321 1:
24322
24323 - testl %ebx,%ebx /* swapgs needed? */
24324 + testl $1,%ebx /* swapgs needed? */
24325 jnz nmi_restore
24326 nmi_swapgs:
24327 SWAPGS_UNSAFE_STACK
24328 nmi_restore:
24329 + pax_exit_kernel_nmi
24330 /* Pop the extra iret frame at once */
24331 RESTORE_ALL 6*8
24332 + testb $3, 8(%rsp)
24333 + jnz 1f
24334 + pax_force_retaddr_bts
24335 +1:
24336
24337 /* Clear the NMI executing stack variable */
24338 movq $0, 5*8(%rsp)
24339 jmp irq_return
24340 CFI_ENDPROC
24341 -END(nmi)
24342 +ENDPROC(nmi)
24343
24344 ENTRY(ignore_sysret)
24345 CFI_STARTPROC
24346 mov $-ENOSYS,%eax
24347 sysret
24348 CFI_ENDPROC
24349 -END(ignore_sysret)
24350 +ENDPROC(ignore_sysret)
24351
24352 /*
24353 * End of kprobes section
24354 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24355 index 1ffc32d..e52c745 100644
24356 --- a/arch/x86/kernel/ftrace.c
24357 +++ b/arch/x86/kernel/ftrace.c
24358 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24359 {
24360 unsigned char replaced[MCOUNT_INSN_SIZE];
24361
24362 + ip = ktla_ktva(ip);
24363 +
24364 /*
24365 * Note: Due to modules and __init, code can
24366 * disappear and change, we need to protect against faulting
24367 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24368 unsigned char old[MCOUNT_INSN_SIZE];
24369 int ret;
24370
24371 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24372 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24373
24374 ftrace_update_func = ip;
24375 /* Make sure the breakpoints see the ftrace_update_func update */
24376 @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24377 * kernel identity mapping to modify code.
24378 */
24379 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24380 - ip = (unsigned long)__va(__pa_symbol(ip));
24381 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24382
24383 return probe_kernel_write((void *)ip, val, size);
24384 }
24385 @@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
24386 unsigned char replaced[MCOUNT_INSN_SIZE];
24387 unsigned char brk = BREAKPOINT_INSTRUCTION;
24388
24389 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24390 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24391 return -EFAULT;
24392
24393 /* Make sure it is what we expect it to be */
24394 @@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
24395 return ret;
24396
24397 fail_update:
24398 - probe_kernel_write((void *)ip, &old_code[0], 1);
24399 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
24400 goto out;
24401 }
24402
24403 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24404 index 85126cc..1bbce17 100644
24405 --- a/arch/x86/kernel/head64.c
24406 +++ b/arch/x86/kernel/head64.c
24407 @@ -67,12 +67,12 @@ again:
24408 pgd = *pgd_p;
24409
24410 /*
24411 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24412 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24413 + * The use of __early_va rather than __va here is critical:
24414 + * __va would point us back into the dynamic
24415 * range and we might end up looping forever...
24416 */
24417 if (pgd)
24418 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24419 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24420 else {
24421 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24422 reset_early_page_tables();
24423 @@ -82,13 +82,13 @@ again:
24424 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24425 for (i = 0; i < PTRS_PER_PUD; i++)
24426 pud_p[i] = 0;
24427 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24428 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24429 }
24430 pud_p += pud_index(address);
24431 pud = *pud_p;
24432
24433 if (pud)
24434 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24435 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24436 else {
24437 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24438 reset_early_page_tables();
24439 @@ -98,7 +98,7 @@ again:
24440 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24441 for (i = 0; i < PTRS_PER_PMD; i++)
24442 pmd_p[i] = 0;
24443 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24444 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24445 }
24446 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24447 pmd_p[pmd_index(address)] = pmd;
24448 @@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24449 if (console_loglevel == 10)
24450 early_printk("Kernel alive\n");
24451
24452 - clear_page(init_level4_pgt);
24453 /* set init_level4_pgt kernel high mapping*/
24454 init_level4_pgt[511] = early_level4_pgt[511];
24455
24456 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24457 index f36bd42..56ee1534 100644
24458 --- a/arch/x86/kernel/head_32.S
24459 +++ b/arch/x86/kernel/head_32.S
24460 @@ -26,6 +26,12 @@
24461 /* Physical address */
24462 #define pa(X) ((X) - __PAGE_OFFSET)
24463
24464 +#ifdef CONFIG_PAX_KERNEXEC
24465 +#define ta(X) (X)
24466 +#else
24467 +#define ta(X) ((X) - __PAGE_OFFSET)
24468 +#endif
24469 +
24470 /*
24471 * References to members of the new_cpu_data structure.
24472 */
24473 @@ -55,11 +61,7 @@
24474 * and small than max_low_pfn, otherwise will waste some page table entries
24475 */
24476
24477 -#if PTRS_PER_PMD > 1
24478 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24479 -#else
24480 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24481 -#endif
24482 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24483
24484 /* Number of possible pages in the lowmem region */
24485 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24486 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24487 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24488
24489 /*
24490 + * Real beginning of normal "text" segment
24491 + */
24492 +ENTRY(stext)
24493 +ENTRY(_stext)
24494 +
24495 +/*
24496 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24497 * %esi points to the real-mode code as a 32-bit pointer.
24498 * CS and DS must be 4 GB flat segments, but we don't depend on
24499 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24500 * can.
24501 */
24502 __HEAD
24503 +
24504 +#ifdef CONFIG_PAX_KERNEXEC
24505 + jmp startup_32
24506 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24507 +.fill PAGE_SIZE-5,1,0xcc
24508 +#endif
24509 +
24510 ENTRY(startup_32)
24511 movl pa(stack_start),%ecx
24512
24513 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24514 2:
24515 leal -__PAGE_OFFSET(%ecx),%esp
24516
24517 +#ifdef CONFIG_SMP
24518 + movl $pa(cpu_gdt_table),%edi
24519 + movl $__per_cpu_load,%eax
24520 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24521 + rorl $16,%eax
24522 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24523 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24524 + movl $__per_cpu_end - 1,%eax
24525 + subl $__per_cpu_start,%eax
24526 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24527 +#endif
24528 +
24529 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24530 + movl $NR_CPUS,%ecx
24531 + movl $pa(cpu_gdt_table),%edi
24532 +1:
24533 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24534 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24535 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24536 + addl $PAGE_SIZE_asm,%edi
24537 + loop 1b
24538 +#endif
24539 +
24540 +#ifdef CONFIG_PAX_KERNEXEC
24541 + movl $pa(boot_gdt),%edi
24542 + movl $__LOAD_PHYSICAL_ADDR,%eax
24543 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24544 + rorl $16,%eax
24545 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24546 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24547 + rorl $16,%eax
24548 +
24549 + ljmp $(__BOOT_CS),$1f
24550 +1:
24551 +
24552 + movl $NR_CPUS,%ecx
24553 + movl $pa(cpu_gdt_table),%edi
24554 + addl $__PAGE_OFFSET,%eax
24555 +1:
24556 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24557 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24558 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24559 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24560 + rorl $16,%eax
24561 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24562 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24563 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24564 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24565 + rorl $16,%eax
24566 + addl $PAGE_SIZE_asm,%edi
24567 + loop 1b
24568 +#endif
24569 +
24570 /*
24571 * Clear BSS first so that there are no surprises...
24572 */
24573 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24574 movl %eax, pa(max_pfn_mapped)
24575
24576 /* Do early initialization of the fixmap area */
24577 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24578 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24579 +#ifdef CONFIG_COMPAT_VDSO
24580 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24581 +#else
24582 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24583 +#endif
24584 #else /* Not PAE */
24585
24586 page_pde_offset = (__PAGE_OFFSET >> 20);
24587 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24588 movl %eax, pa(max_pfn_mapped)
24589
24590 /* Do early initialization of the fixmap area */
24591 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24592 - movl %eax,pa(initial_page_table+0xffc)
24593 +#ifdef CONFIG_COMPAT_VDSO
24594 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24595 +#else
24596 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24597 +#endif
24598 #endif
24599
24600 #ifdef CONFIG_PARAVIRT
24601 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24602 cmpl $num_subarch_entries, %eax
24603 jae bad_subarch
24604
24605 - movl pa(subarch_entries)(,%eax,4), %eax
24606 - subl $__PAGE_OFFSET, %eax
24607 - jmp *%eax
24608 + jmp *pa(subarch_entries)(,%eax,4)
24609
24610 bad_subarch:
24611 WEAK(lguest_entry)
24612 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24613 __INITDATA
24614
24615 subarch_entries:
24616 - .long default_entry /* normal x86/PC */
24617 - .long lguest_entry /* lguest hypervisor */
24618 - .long xen_entry /* Xen hypervisor */
24619 - .long default_entry /* Moorestown MID */
24620 + .long ta(default_entry) /* normal x86/PC */
24621 + .long ta(lguest_entry) /* lguest hypervisor */
24622 + .long ta(xen_entry) /* Xen hypervisor */
24623 + .long ta(default_entry) /* Moorestown MID */
24624 num_subarch_entries = (. - subarch_entries) / 4
24625 .previous
24626 #else
24627 @@ -354,6 +426,7 @@ default_entry:
24628 movl pa(mmu_cr4_features),%eax
24629 movl %eax,%cr4
24630
24631 +#ifdef CONFIG_X86_PAE
24632 testb $X86_CR4_PAE, %al # check if PAE is enabled
24633 jz enable_paging
24634
24635 @@ -382,6 +455,9 @@ default_entry:
24636 /* Make changes effective */
24637 wrmsr
24638
24639 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24640 +#endif
24641 +
24642 enable_paging:
24643
24644 /*
24645 @@ -449,14 +525,20 @@ is486:
24646 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24647 movl %eax,%ss # after changing gdt.
24648
24649 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24650 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24651 movl %eax,%ds
24652 movl %eax,%es
24653
24654 movl $(__KERNEL_PERCPU), %eax
24655 movl %eax,%fs # set this cpu's percpu
24656
24657 +#ifdef CONFIG_CC_STACKPROTECTOR
24658 movl $(__KERNEL_STACK_CANARY),%eax
24659 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24660 + movl $(__USER_DS),%eax
24661 +#else
24662 + xorl %eax,%eax
24663 +#endif
24664 movl %eax,%gs
24665
24666 xorl %eax,%eax # Clear LDT
24667 @@ -512,8 +594,11 @@ setup_once:
24668 * relocation. Manually set base address in stack canary
24669 * segment descriptor.
24670 */
24671 - movl $gdt_page,%eax
24672 + movl $cpu_gdt_table,%eax
24673 movl $stack_canary,%ecx
24674 +#ifdef CONFIG_SMP
24675 + addl $__per_cpu_load,%ecx
24676 +#endif
24677 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24678 shrl $16, %ecx
24679 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24680 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24681 cmpl $2,(%esp) # X86_TRAP_NMI
24682 je is_nmi # Ignore NMI
24683
24684 - cmpl $2,%ss:early_recursion_flag
24685 + cmpl $1,%ss:early_recursion_flag
24686 je hlt_loop
24687 incl %ss:early_recursion_flag
24688
24689 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24690 pushl (20+6*4)(%esp) /* trapno */
24691 pushl $fault_msg
24692 call printk
24693 -#endif
24694 call dump_stack
24695 +#endif
24696 hlt_loop:
24697 hlt
24698 jmp hlt_loop
24699 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24700 /* This is the default interrupt "handler" :-) */
24701 ALIGN
24702 ignore_int:
24703 - cld
24704 #ifdef CONFIG_PRINTK
24705 + cmpl $2,%ss:early_recursion_flag
24706 + je hlt_loop
24707 + incl %ss:early_recursion_flag
24708 + cld
24709 pushl %eax
24710 pushl %ecx
24711 pushl %edx
24712 @@ -617,9 +705,6 @@ ignore_int:
24713 movl $(__KERNEL_DS),%eax
24714 movl %eax,%ds
24715 movl %eax,%es
24716 - cmpl $2,early_recursion_flag
24717 - je hlt_loop
24718 - incl early_recursion_flag
24719 pushl 16(%esp)
24720 pushl 24(%esp)
24721 pushl 32(%esp)
24722 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24723 /*
24724 * BSS section
24725 */
24726 -__PAGE_ALIGNED_BSS
24727 - .align PAGE_SIZE
24728 #ifdef CONFIG_X86_PAE
24729 +.section .initial_pg_pmd,"a",@progbits
24730 initial_pg_pmd:
24731 .fill 1024*KPMDS,4,0
24732 #else
24733 +.section .initial_page_table,"a",@progbits
24734 ENTRY(initial_page_table)
24735 .fill 1024,4,0
24736 #endif
24737 +.section .initial_pg_fixmap,"a",@progbits
24738 initial_pg_fixmap:
24739 .fill 1024,4,0
24740 +.section .empty_zero_page,"a",@progbits
24741 ENTRY(empty_zero_page)
24742 .fill 4096,1,0
24743 +.section .swapper_pg_dir,"a",@progbits
24744 ENTRY(swapper_pg_dir)
24745 +#ifdef CONFIG_X86_PAE
24746 + .fill 4,8,0
24747 +#else
24748 .fill 1024,4,0
24749 +#endif
24750
24751 /*
24752 * This starts the data section.
24753 */
24754 #ifdef CONFIG_X86_PAE
24755 -__PAGE_ALIGNED_DATA
24756 - /* Page-aligned for the benefit of paravirt? */
24757 - .align PAGE_SIZE
24758 +.section .initial_page_table,"a",@progbits
24759 ENTRY(initial_page_table)
24760 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24761 # if KPMDS == 3
24762 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24763 # error "Kernel PMDs should be 1, 2 or 3"
24764 # endif
24765 .align PAGE_SIZE /* needs to be page-sized too */
24766 +
24767 +#ifdef CONFIG_PAX_PER_CPU_PGD
24768 +ENTRY(cpu_pgd)
24769 + .rept 2*NR_CPUS
24770 + .fill 4,8,0
24771 + .endr
24772 +#endif
24773 +
24774 #endif
24775
24776 .data
24777 .balign 4
24778 ENTRY(stack_start)
24779 - .long init_thread_union+THREAD_SIZE
24780 + .long init_thread_union+THREAD_SIZE-8
24781
24782 __INITRODATA
24783 int_msg:
24784 @@ -727,7 +825,7 @@ fault_msg:
24785 * segment size, and 32-bit linear address value:
24786 */
24787
24788 - .data
24789 +.section .rodata,"a",@progbits
24790 .globl boot_gdt_descr
24791 .globl idt_descr
24792
24793 @@ -736,7 +834,7 @@ fault_msg:
24794 .word 0 # 32 bit align gdt_desc.address
24795 boot_gdt_descr:
24796 .word __BOOT_DS+7
24797 - .long boot_gdt - __PAGE_OFFSET
24798 + .long pa(boot_gdt)
24799
24800 .word 0 # 32-bit align idt_desc.address
24801 idt_descr:
24802 @@ -747,7 +845,7 @@ idt_descr:
24803 .word 0 # 32 bit align gdt_desc.address
24804 ENTRY(early_gdt_descr)
24805 .word GDT_ENTRIES*8-1
24806 - .long gdt_page /* Overwritten for secondary CPUs */
24807 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24808
24809 /*
24810 * The boot_gdt must mirror the equivalent in setup.S and is
24811 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24812 .align L1_CACHE_BYTES
24813 ENTRY(boot_gdt)
24814 .fill GDT_ENTRY_BOOT_CS,8,0
24815 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24816 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24817 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24818 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24819 +
24820 + .align PAGE_SIZE_asm
24821 +ENTRY(cpu_gdt_table)
24822 + .rept NR_CPUS
24823 + .quad 0x0000000000000000 /* NULL descriptor */
24824 + .quad 0x0000000000000000 /* 0x0b reserved */
24825 + .quad 0x0000000000000000 /* 0x13 reserved */
24826 + .quad 0x0000000000000000 /* 0x1b reserved */
24827 +
24828 +#ifdef CONFIG_PAX_KERNEXEC
24829 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24830 +#else
24831 + .quad 0x0000000000000000 /* 0x20 unused */
24832 +#endif
24833 +
24834 + .quad 0x0000000000000000 /* 0x28 unused */
24835 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24836 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24837 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24838 + .quad 0x0000000000000000 /* 0x4b reserved */
24839 + .quad 0x0000000000000000 /* 0x53 reserved */
24840 + .quad 0x0000000000000000 /* 0x5b reserved */
24841 +
24842 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24843 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24844 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24845 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24846 +
24847 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24848 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24849 +
24850 + /*
24851 + * Segments used for calling PnP BIOS have byte granularity.
24852 + * The code segments and data segments have fixed 64k limits,
24853 + * the transfer segment sizes are set at run time.
24854 + */
24855 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24856 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24857 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24858 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24859 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24860 +
24861 + /*
24862 + * The APM segments have byte granularity and their bases
24863 + * are set at run time. All have 64k limits.
24864 + */
24865 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24866 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24867 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24868 +
24869 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24870 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24871 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24872 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24873 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24874 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24875 +
24876 + /* Be sure this is zeroed to avoid false validations in Xen */
24877 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24878 + .endr
24879 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24880 index a468c0a..c7dec74 100644
24881 --- a/arch/x86/kernel/head_64.S
24882 +++ b/arch/x86/kernel/head_64.S
24883 @@ -20,6 +20,8 @@
24884 #include <asm/processor-flags.h>
24885 #include <asm/percpu.h>
24886 #include <asm/nops.h>
24887 +#include <asm/cpufeature.h>
24888 +#include <asm/alternative-asm.h>
24889
24890 #ifdef CONFIG_PARAVIRT
24891 #include <asm/asm-offsets.h>
24892 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24893 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24894 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24895 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24896 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24897 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24898 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24899 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24900 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24901 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24902
24903 .text
24904 __HEAD
24905 @@ -89,11 +97,24 @@ startup_64:
24906 * Fixup the physical addresses in the page table
24907 */
24908 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24909 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24910 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24911 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24912 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24913 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24914
24915 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24916 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24917 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24918 +#ifndef CONFIG_XEN
24919 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24920 +#endif
24921 +
24922 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24923 +
24924 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24925 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24926
24927 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24928 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24929
24930 /*
24931 * Set up the identity mapping for the switchover. These
24932 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24933 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24934 1:
24935
24936 - /* Enable PAE mode and PGE */
24937 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24938 + /* Enable PAE mode and PSE/PGE */
24939 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24940 movq %rcx, %cr4
24941
24942 /* Setup early boot stage 4 level pagetables. */
24943 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24944 movl $MSR_EFER, %ecx
24945 rdmsr
24946 btsl $_EFER_SCE, %eax /* Enable System Call */
24947 - btl $20,%edi /* No Execute supported? */
24948 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24949 jnc 1f
24950 btsl $_EFER_NX, %eax
24951 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24952 +#ifndef CONFIG_EFI
24953 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24954 +#endif
24955 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24956 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24957 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24958 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24959 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24960 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24961 1: wrmsr /* Make changes effective */
24962
24963 /* Setup cr0 */
24964 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24965 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24966 * address given in m16:64.
24967 */
24968 + pax_set_fptr_mask
24969 movq initial_code(%rip),%rax
24970 pushq $0 # fake return address to stop unwinder
24971 pushq $__KERNEL_CS # set correct cs
24972 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24973 .quad INIT_PER_CPU_VAR(irq_stack_union)
24974
24975 GLOBAL(stack_start)
24976 - .quad init_thread_union+THREAD_SIZE-8
24977 + .quad init_thread_union+THREAD_SIZE-16
24978 .word 0
24979 __FINITDATA
24980
24981 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24982 call dump_stack
24983 #ifdef CONFIG_KALLSYMS
24984 leaq early_idt_ripmsg(%rip),%rdi
24985 - movq 40(%rsp),%rsi # %rip again
24986 + movq 88(%rsp),%rsi # %rip again
24987 call __print_symbol
24988 #endif
24989 #endif /* EARLY_PRINTK */
24990 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24991 early_recursion_flag:
24992 .long 0
24993
24994 + .section .rodata,"a",@progbits
24995 #ifdef CONFIG_EARLY_PRINTK
24996 early_idt_msg:
24997 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24998 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24999 NEXT_PAGE(early_dynamic_pgts)
25000 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25001
25002 - .data
25003 + .section .rodata,"a",@progbits
25004
25005 -#ifndef CONFIG_XEN
25006 NEXT_PAGE(init_level4_pgt)
25007 - .fill 512,8,0
25008 -#else
25009 -NEXT_PAGE(init_level4_pgt)
25010 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25011 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25012 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25013 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
25014 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25015 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
25016 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25017 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25018 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25019 .org init_level4_pgt + L4_START_KERNEL*8, 0
25020 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25021 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25022
25023 +#ifdef CONFIG_PAX_PER_CPU_PGD
25024 +NEXT_PAGE(cpu_pgd)
25025 + .rept 2*NR_CPUS
25026 + .fill 512,8,0
25027 + .endr
25028 +#endif
25029 +
25030 NEXT_PAGE(level3_ident_pgt)
25031 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25032 +#ifdef CONFIG_XEN
25033 .fill 511, 8, 0
25034 +#else
25035 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25036 + .fill 510,8,0
25037 +#endif
25038 +
25039 +NEXT_PAGE(level3_vmalloc_start_pgt)
25040 + .fill 512,8,0
25041 +
25042 +NEXT_PAGE(level3_vmalloc_end_pgt)
25043 + .fill 512,8,0
25044 +
25045 +NEXT_PAGE(level3_vmemmap_pgt)
25046 + .fill L3_VMEMMAP_START,8,0
25047 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25048 +
25049 NEXT_PAGE(level2_ident_pgt)
25050 - /* Since I easily can, map the first 1G.
25051 + /* Since I easily can, map the first 2G.
25052 * Don't set NX because code runs from these pages.
25053 */
25054 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25055 -#endif
25056 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25057
25058 NEXT_PAGE(level3_kernel_pgt)
25059 .fill L3_START_KERNEL,8,0
25060 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
25061 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25062 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25063
25064 +NEXT_PAGE(level2_vmemmap_pgt)
25065 + .fill 512,8,0
25066 +
25067 NEXT_PAGE(level2_kernel_pgt)
25068 /*
25069 * 512 MB kernel mapping. We spend a full page on this pagetable
25070 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
25071 NEXT_PAGE(level2_fixmap_pgt)
25072 .fill 506,8,0
25073 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25074 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25075 - .fill 5,8,0
25076 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25077 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25078 + .fill 4,8,0
25079
25080 NEXT_PAGE(level1_fixmap_pgt)
25081 .fill 512,8,0
25082
25083 +NEXT_PAGE(level1_vsyscall_pgt)
25084 + .fill 512,8,0
25085 +
25086 #undef PMDS
25087
25088 - .data
25089 + .align PAGE_SIZE
25090 +ENTRY(cpu_gdt_table)
25091 + .rept NR_CPUS
25092 + .quad 0x0000000000000000 /* NULL descriptor */
25093 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25094 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
25095 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
25096 + .quad 0x00cffb000000ffff /* __USER32_CS */
25097 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25098 + .quad 0x00affb000000ffff /* __USER_CS */
25099 +
25100 +#ifdef CONFIG_PAX_KERNEXEC
25101 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25102 +#else
25103 + .quad 0x0 /* unused */
25104 +#endif
25105 +
25106 + .quad 0,0 /* TSS */
25107 + .quad 0,0 /* LDT */
25108 + .quad 0,0,0 /* three TLS descriptors */
25109 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
25110 + /* asm/segment.h:GDT_ENTRIES must match this */
25111 +
25112 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25113 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25114 +#else
25115 + .quad 0x0 /* unused */
25116 +#endif
25117 +
25118 + /* zero the remaining page */
25119 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25120 + .endr
25121 +
25122 .align 16
25123 .globl early_gdt_descr
25124 early_gdt_descr:
25125 .word GDT_ENTRIES*8-1
25126 early_gdt_descr_base:
25127 - .quad INIT_PER_CPU_VAR(gdt_page)
25128 + .quad cpu_gdt_table
25129
25130 ENTRY(phys_base)
25131 /* This must match the first entry in level2_kernel_pgt */
25132 .quad 0x0000000000000000
25133
25134 #include "../../x86/xen/xen-head.S"
25135 -
25136 - __PAGE_ALIGNED_BSS
25137 +
25138 + .section .rodata,"a",@progbits
25139 NEXT_PAGE(empty_zero_page)
25140 .skip PAGE_SIZE
25141 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25142 index 05fd74f..c3548b1 100644
25143 --- a/arch/x86/kernel/i386_ksyms_32.c
25144 +++ b/arch/x86/kernel/i386_ksyms_32.c
25145 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25146 EXPORT_SYMBOL(cmpxchg8b_emu);
25147 #endif
25148
25149 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
25150 +
25151 /* Networking helper routines. */
25152 EXPORT_SYMBOL(csum_partial_copy_generic);
25153 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25154 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25155
25156 EXPORT_SYMBOL(__get_user_1);
25157 EXPORT_SYMBOL(__get_user_2);
25158 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25159 EXPORT_SYMBOL(___preempt_schedule_context);
25160 #endif
25161 #endif
25162 +
25163 +#ifdef CONFIG_PAX_KERNEXEC
25164 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25165 +#endif
25166 +
25167 +#ifdef CONFIG_PAX_PER_CPU_PGD
25168 +EXPORT_SYMBOL(cpu_pgd);
25169 +#endif
25170 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25171 index d5dd808..b6432cf 100644
25172 --- a/arch/x86/kernel/i387.c
25173 +++ b/arch/x86/kernel/i387.c
25174 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25175 static inline bool interrupted_user_mode(void)
25176 {
25177 struct pt_regs *regs = get_irq_regs();
25178 - return regs && user_mode_vm(regs);
25179 + return regs && user_mode(regs);
25180 }
25181
25182 /*
25183 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25184 index 2e977b5..5f2c273 100644
25185 --- a/arch/x86/kernel/i8259.c
25186 +++ b/arch/x86/kernel/i8259.c
25187 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25188 static void make_8259A_irq(unsigned int irq)
25189 {
25190 disable_irq_nosync(irq);
25191 - io_apic_irqs &= ~(1<<irq);
25192 + io_apic_irqs &= ~(1UL<<irq);
25193 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25194 i8259A_chip.name);
25195 enable_irq(irq);
25196 @@ -209,7 +209,7 @@ spurious_8259A_irq:
25197 "spurious 8259A interrupt: IRQ%d.\n", irq);
25198 spurious_irq_mask |= irqmask;
25199 }
25200 - atomic_inc(&irq_err_count);
25201 + atomic_inc_unchecked(&irq_err_count);
25202 /*
25203 * Theoretically we do not have to handle this IRQ,
25204 * but in Linux this does not cause problems and is
25205 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
25206 /* (slave's support for AEOI in flat mode is to be investigated) */
25207 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25208
25209 + pax_open_kernel();
25210 if (auto_eoi)
25211 /*
25212 * In AEOI mode we just have to mask the interrupt
25213 * when acking.
25214 */
25215 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
25216 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25217 else
25218 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25219 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25220 + pax_close_kernel();
25221
25222 udelay(100); /* wait for 8259A to initialize */
25223
25224 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25225 index a979b5b..1d6db75 100644
25226 --- a/arch/x86/kernel/io_delay.c
25227 +++ b/arch/x86/kernel/io_delay.c
25228 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25229 * Quirk table for systems that misbehave (lock up, etc.) if port
25230 * 0x80 is used:
25231 */
25232 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25233 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25234 {
25235 .callback = dmi_io_delay_0xed_port,
25236 .ident = "Compaq Presario V6000",
25237 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25238 index 4ddaf66..49d5c18 100644
25239 --- a/arch/x86/kernel/ioport.c
25240 +++ b/arch/x86/kernel/ioport.c
25241 @@ -6,6 +6,7 @@
25242 #include <linux/sched.h>
25243 #include <linux/kernel.h>
25244 #include <linux/capability.h>
25245 +#include <linux/security.h>
25246 #include <linux/errno.h>
25247 #include <linux/types.h>
25248 #include <linux/ioport.h>
25249 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25250 return -EINVAL;
25251 if (turn_on && !capable(CAP_SYS_RAWIO))
25252 return -EPERM;
25253 +#ifdef CONFIG_GRKERNSEC_IO
25254 + if (turn_on && grsec_disable_privio) {
25255 + gr_handle_ioperm();
25256 + return -ENODEV;
25257 + }
25258 +#endif
25259
25260 /*
25261 * If it's the first ioperm() call in this thread's lifetime, set the
25262 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25263 * because the ->io_bitmap_max value must match the bitmap
25264 * contents:
25265 */
25266 - tss = &per_cpu(init_tss, get_cpu());
25267 + tss = init_tss + get_cpu();
25268
25269 if (turn_on)
25270 bitmap_clear(t->io_bitmap_ptr, from, num);
25271 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25272 if (level > old) {
25273 if (!capable(CAP_SYS_RAWIO))
25274 return -EPERM;
25275 +#ifdef CONFIG_GRKERNSEC_IO
25276 + if (grsec_disable_privio) {
25277 + gr_handle_iopl();
25278 + return -ENODEV;
25279 + }
25280 +#endif
25281 }
25282 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25283 t->iopl = level << 12;
25284 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25285 index d99f31d..1c0f466 100644
25286 --- a/arch/x86/kernel/irq.c
25287 +++ b/arch/x86/kernel/irq.c
25288 @@ -21,7 +21,7 @@
25289 #define CREATE_TRACE_POINTS
25290 #include <asm/trace/irq_vectors.h>
25291
25292 -atomic_t irq_err_count;
25293 +atomic_unchecked_t irq_err_count;
25294
25295 /* Function pointer for generic interrupt vector handling */
25296 void (*x86_platform_ipi_callback)(void) = NULL;
25297 @@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25298 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
25299 seq_printf(p, " Machine check polls\n");
25300 #endif
25301 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25302 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25303 #if defined(CONFIG_X86_IO_APIC)
25304 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25305 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25306 #endif
25307 return 0;
25308 }
25309 @@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25310
25311 u64 arch_irq_stat(void)
25312 {
25313 - u64 sum = atomic_read(&irq_err_count);
25314 + u64 sum = atomic_read_unchecked(&irq_err_count);
25315 return sum;
25316 }
25317
25318 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25319 index d7fcbed..96e715a 100644
25320 --- a/arch/x86/kernel/irq_32.c
25321 +++ b/arch/x86/kernel/irq_32.c
25322 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25323
25324 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25325
25326 +extern void gr_handle_kernel_exploit(void);
25327 +
25328 int sysctl_panic_on_stackoverflow __read_mostly;
25329
25330 /* Debugging check for stack overflow: is there less than 1KB free? */
25331 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25332 __asm__ __volatile__("andl %%esp,%0" :
25333 "=r" (sp) : "0" (THREAD_SIZE - 1));
25334
25335 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25336 + return sp < STACK_WARN;
25337 }
25338
25339 static void print_stack_overflow(void)
25340 {
25341 printk(KERN_WARNING "low stack detected by irq handler\n");
25342 dump_stack();
25343 + gr_handle_kernel_exploit();
25344 if (sysctl_panic_on_stackoverflow)
25345 panic("low stack detected by irq handler - check messages\n");
25346 }
25347 @@ -59,8 +62,8 @@ static inline void print_stack_overflow(void) { }
25348 * per-CPU IRQ handling contexts (thread information and stack)
25349 */
25350 union irq_ctx {
25351 - struct thread_info tinfo;
25352 - u32 stack[THREAD_SIZE/sizeof(u32)];
25353 + unsigned long previous_esp;
25354 + u32 stack[THREAD_SIZE/sizeof(u32)];
25355 } __attribute__((aligned(THREAD_SIZE)));
25356
25357 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
25358 @@ -80,10 +83,9 @@ static void call_on_stack(void *func, void *stack)
25359 static inline int
25360 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25361 {
25362 - union irq_ctx *curctx, *irqctx;
25363 + union irq_ctx *irqctx;
25364 u32 *isp, arg1, arg2;
25365
25366 - curctx = (union irq_ctx *) current_thread_info();
25367 irqctx = __this_cpu_read(hardirq_ctx);
25368
25369 /*
25370 @@ -92,13 +94,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25371 * handler) we can't do that and just have to keep using the
25372 * current stack (which is the irq stack already after all)
25373 */
25374 - if (unlikely(curctx == irqctx))
25375 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
25376 return 0;
25377
25378 /* build the stack frame on the IRQ stack */
25379 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25380 - irqctx->tinfo.task = curctx->tinfo.task;
25381 - irqctx->tinfo.previous_esp = current_stack_pointer;
25382 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25383 + irqctx->previous_esp = current_stack_pointer;
25384 +
25385 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25386 + __set_fs(MAKE_MM_SEG(0));
25387 +#endif
25388
25389 if (unlikely(overflow))
25390 call_on_stack(print_stack_overflow, isp);
25391 @@ -110,6 +115,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25392 : "0" (irq), "1" (desc), "2" (isp),
25393 "D" (desc->handle_irq)
25394 : "memory", "cc", "ecx");
25395 +
25396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25397 + __set_fs(current_thread_info()->addr_limit);
25398 +#endif
25399 +
25400 return 1;
25401 }
25402
25403 @@ -118,48 +128,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25404 */
25405 void irq_ctx_init(int cpu)
25406 {
25407 - union irq_ctx *irqctx;
25408 -
25409 if (per_cpu(hardirq_ctx, cpu))
25410 return;
25411
25412 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25413 - THREADINFO_GFP,
25414 - THREAD_SIZE_ORDER));
25415 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25416 - irqctx->tinfo.cpu = cpu;
25417 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25418 -
25419 - per_cpu(hardirq_ctx, cpu) = irqctx;
25420 -
25421 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25422 - THREADINFO_GFP,
25423 - THREAD_SIZE_ORDER));
25424 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25425 - irqctx->tinfo.cpu = cpu;
25426 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25427 -
25428 - per_cpu(softirq_ctx, cpu) = irqctx;
25429 -
25430 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25431 - cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
25432 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25433 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25434 }
25435
25436 void do_softirq_own_stack(void)
25437 {
25438 - struct thread_info *curctx;
25439 union irq_ctx *irqctx;
25440 u32 *isp;
25441
25442 - curctx = current_thread_info();
25443 irqctx = __this_cpu_read(softirq_ctx);
25444 - irqctx->tinfo.task = curctx->task;
25445 - irqctx->tinfo.previous_esp = current_stack_pointer;
25446 + irqctx->previous_esp = current_stack_pointer;
25447
25448 /* build the stack frame on the softirq stack */
25449 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25450 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25451 +
25452 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25453 + __set_fs(MAKE_MM_SEG(0));
25454 +#endif
25455
25456 call_on_stack(__do_softirq, isp);
25457 +
25458 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25459 + __set_fs(current_thread_info()->addr_limit);
25460 +#endif
25461 +
25462 }
25463
25464 bool handle_irq(unsigned irq, struct pt_regs *regs)
25465 @@ -173,7 +169,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25466 if (unlikely(!desc))
25467 return false;
25468
25469 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25470 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25471 if (unlikely(overflow))
25472 print_stack_overflow();
25473 desc->handle_irq(irq, desc);
25474 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25475 index 4d1c746..55a22d6 100644
25476 --- a/arch/x86/kernel/irq_64.c
25477 +++ b/arch/x86/kernel/irq_64.c
25478 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25479 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25480 EXPORT_PER_CPU_SYMBOL(irq_regs);
25481
25482 +extern void gr_handle_kernel_exploit(void);
25483 +
25484 int sysctl_panic_on_stackoverflow;
25485
25486 /*
25487 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25488 u64 estack_top, estack_bottom;
25489 u64 curbase = (u64)task_stack_page(current);
25490
25491 - if (user_mode_vm(regs))
25492 + if (user_mode(regs))
25493 return;
25494
25495 if (regs->sp >= curbase + sizeof(struct thread_info) +
25496 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25497 irq_stack_top, irq_stack_bottom,
25498 estack_top, estack_bottom);
25499
25500 + gr_handle_kernel_exploit();
25501 +
25502 if (sysctl_panic_on_stackoverflow)
25503 panic("low stack detected by irq handler - check messages\n");
25504 #endif
25505 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25506 index 26d5a55..a01160a 100644
25507 --- a/arch/x86/kernel/jump_label.c
25508 +++ b/arch/x86/kernel/jump_label.c
25509 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25510 * Jump label is enabled for the first time.
25511 * So we expect a default_nop...
25512 */
25513 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25514 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25515 != 0))
25516 bug_at((void *)entry->code, __LINE__);
25517 } else {
25518 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25519 * ...otherwise expect an ideal_nop. Otherwise
25520 * something went horribly wrong.
25521 */
25522 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25523 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25524 != 0))
25525 bug_at((void *)entry->code, __LINE__);
25526 }
25527 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25528 * are converting the default nop to the ideal nop.
25529 */
25530 if (init) {
25531 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25532 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25533 bug_at((void *)entry->code, __LINE__);
25534 } else {
25535 code.jump = 0xe9;
25536 code.offset = entry->target -
25537 (entry->code + JUMP_LABEL_NOP_SIZE);
25538 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25539 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25540 bug_at((void *)entry->code, __LINE__);
25541 }
25542 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25543 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25544 index 7ec1d5f..5a7d130 100644
25545 --- a/arch/x86/kernel/kgdb.c
25546 +++ b/arch/x86/kernel/kgdb.c
25547 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25548 #ifdef CONFIG_X86_32
25549 switch (regno) {
25550 case GDB_SS:
25551 - if (!user_mode_vm(regs))
25552 + if (!user_mode(regs))
25553 *(unsigned long *)mem = __KERNEL_DS;
25554 break;
25555 case GDB_SP:
25556 - if (!user_mode_vm(regs))
25557 + if (!user_mode(regs))
25558 *(unsigned long *)mem = kernel_stack_pointer(regs);
25559 break;
25560 case GDB_GS:
25561 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25562 bp->attr.bp_addr = breakinfo[breakno].addr;
25563 bp->attr.bp_len = breakinfo[breakno].len;
25564 bp->attr.bp_type = breakinfo[breakno].type;
25565 - info->address = breakinfo[breakno].addr;
25566 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25567 + info->address = ktla_ktva(breakinfo[breakno].addr);
25568 + else
25569 + info->address = breakinfo[breakno].addr;
25570 info->len = breakinfo[breakno].len;
25571 info->type = breakinfo[breakno].type;
25572 val = arch_install_hw_breakpoint(bp);
25573 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25574 case 'k':
25575 /* clear the trace bit */
25576 linux_regs->flags &= ~X86_EFLAGS_TF;
25577 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25578 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25579
25580 /* set the trace bit if we're stepping */
25581 if (remcomInBuffer[0] == 's') {
25582 linux_regs->flags |= X86_EFLAGS_TF;
25583 - atomic_set(&kgdb_cpu_doing_single_step,
25584 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25585 raw_smp_processor_id());
25586 }
25587
25588 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25589
25590 switch (cmd) {
25591 case DIE_DEBUG:
25592 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25593 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25594 if (user_mode(regs))
25595 return single_step_cont(regs, args);
25596 break;
25597 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25598 #endif /* CONFIG_DEBUG_RODATA */
25599
25600 bpt->type = BP_BREAKPOINT;
25601 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25602 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25603 BREAK_INSTR_SIZE);
25604 if (err)
25605 return err;
25606 - err = probe_kernel_write((char *)bpt->bpt_addr,
25607 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25608 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25609 #ifdef CONFIG_DEBUG_RODATA
25610 if (!err)
25611 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25612 return -EBUSY;
25613 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25614 BREAK_INSTR_SIZE);
25615 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25616 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25617 if (err)
25618 return err;
25619 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25620 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25621 if (mutex_is_locked(&text_mutex))
25622 goto knl_write;
25623 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25624 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25625 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25626 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25627 goto knl_write;
25628 return err;
25629 knl_write:
25630 #endif /* CONFIG_DEBUG_RODATA */
25631 - return probe_kernel_write((char *)bpt->bpt_addr,
25632 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25633 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25634 }
25635
25636 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25637 index 79a3f96..6ba030a 100644
25638 --- a/arch/x86/kernel/kprobes/core.c
25639 +++ b/arch/x86/kernel/kprobes/core.c
25640 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25641 s32 raddr;
25642 } __packed *insn;
25643
25644 - insn = (struct __arch_relative_insn *)from;
25645 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25646 +
25647 + pax_open_kernel();
25648 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25649 insn->op = op;
25650 + pax_close_kernel();
25651 }
25652
25653 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25654 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25655 kprobe_opcode_t opcode;
25656 kprobe_opcode_t *orig_opcodes = opcodes;
25657
25658 - if (search_exception_tables((unsigned long)opcodes))
25659 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25660 return 0; /* Page fault may occur on this address. */
25661
25662 retry:
25663 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25664 * for the first byte, we can recover the original instruction
25665 * from it and kp->opcode.
25666 */
25667 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25668 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25669 buf[0] = kp->opcode;
25670 - return (unsigned long)buf;
25671 + return ktva_ktla((unsigned long)buf);
25672 }
25673
25674 /*
25675 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25676 /* Another subsystem puts a breakpoint, failed to recover */
25677 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25678 return 0;
25679 + pax_open_kernel();
25680 memcpy(dest, insn.kaddr, insn.length);
25681 + pax_close_kernel();
25682
25683 #ifdef CONFIG_X86_64
25684 if (insn_rip_relative(&insn)) {
25685 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25686 return 0;
25687 }
25688 disp = (u8 *) dest + insn_offset_displacement(&insn);
25689 + pax_open_kernel();
25690 *(s32 *) disp = (s32) newdisp;
25691 + pax_close_kernel();
25692 }
25693 #endif
25694 return insn.length;
25695 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25696 * nor set current_kprobe, because it doesn't use single
25697 * stepping.
25698 */
25699 - regs->ip = (unsigned long)p->ainsn.insn;
25700 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25701 preempt_enable_no_resched();
25702 return;
25703 }
25704 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25705 regs->flags &= ~X86_EFLAGS_IF;
25706 /* single step inline if the instruction is an int3 */
25707 if (p->opcode == BREAKPOINT_INSTRUCTION)
25708 - regs->ip = (unsigned long)p->addr;
25709 + regs->ip = ktla_ktva((unsigned long)p->addr);
25710 else
25711 - regs->ip = (unsigned long)p->ainsn.insn;
25712 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25713 }
25714
25715 /*
25716 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25717 setup_singlestep(p, regs, kcb, 0);
25718 return 1;
25719 }
25720 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25721 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25722 /*
25723 * The breakpoint instruction was removed right
25724 * after we hit it. Another cpu has removed
25725 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25726 " movq %rax, 152(%rsp)\n"
25727 RESTORE_REGS_STRING
25728 " popfq\n"
25729 +#ifdef KERNEXEC_PLUGIN
25730 + " btsq $63,(%rsp)\n"
25731 +#endif
25732 #else
25733 " pushf\n"
25734 SAVE_REGS_STRING
25735 @@ -779,7 +789,7 @@ static void __kprobes
25736 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25737 {
25738 unsigned long *tos = stack_addr(regs);
25739 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25740 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25741 unsigned long orig_ip = (unsigned long)p->addr;
25742 kprobe_opcode_t *insn = p->ainsn.insn;
25743
25744 @@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25745 struct die_args *args = data;
25746 int ret = NOTIFY_DONE;
25747
25748 - if (args->regs && user_mode_vm(args->regs))
25749 + if (args->regs && user_mode(args->regs))
25750 return ret;
25751
25752 switch (val) {
25753 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25754 index 898160b..758cde8 100644
25755 --- a/arch/x86/kernel/kprobes/opt.c
25756 +++ b/arch/x86/kernel/kprobes/opt.c
25757 @@ -79,6 +79,7 @@ found:
25758 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25759 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25760 {
25761 + pax_open_kernel();
25762 #ifdef CONFIG_X86_64
25763 *addr++ = 0x48;
25764 *addr++ = 0xbf;
25765 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25766 *addr++ = 0xb8;
25767 #endif
25768 *(unsigned long *)addr = val;
25769 + pax_close_kernel();
25770 }
25771
25772 asm (
25773 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25774 * Verify if the address gap is in 2GB range, because this uses
25775 * a relative jump.
25776 */
25777 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25778 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25779 if (abs(rel) > 0x7fffffff)
25780 return -ERANGE;
25781
25782 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25783 op->optinsn.size = ret;
25784
25785 /* Copy arch-dep-instance from template */
25786 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25787 + pax_open_kernel();
25788 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25789 + pax_close_kernel();
25790
25791 /* Set probe information */
25792 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25793
25794 /* Set probe function call */
25795 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25796 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25797
25798 /* Set returning jmp instruction at the tail of out-of-line buffer */
25799 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25800 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25801 (u8 *)op->kp.addr + op->optinsn.size);
25802
25803 flush_icache_range((unsigned long) buf,
25804 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25805 WARN_ON(kprobe_disabled(&op->kp));
25806
25807 /* Backup instructions which will be replaced by jump address */
25808 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25809 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25810 RELATIVE_ADDR_SIZE);
25811
25812 insn_buf[0] = RELATIVEJUMP_OPCODE;
25813 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25814 /* This kprobe is really able to run optimized path. */
25815 op = container_of(p, struct optimized_kprobe, kp);
25816 /* Detour through copied instructions */
25817 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25818 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25819 if (!reenter)
25820 reset_current_kprobe();
25821 preempt_enable_no_resched();
25822 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25823 index c2bedae..25e7ab6 100644
25824 --- a/arch/x86/kernel/ksysfs.c
25825 +++ b/arch/x86/kernel/ksysfs.c
25826 @@ -184,7 +184,7 @@ out:
25827
25828 static struct kobj_attribute type_attr = __ATTR_RO(type);
25829
25830 -static struct bin_attribute data_attr = {
25831 +static bin_attribute_no_const data_attr __read_only = {
25832 .attr = {
25833 .name = "data",
25834 .mode = S_IRUGO,
25835 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25836 index af1d14a..81ae763 100644
25837 --- a/arch/x86/kernel/ldt.c
25838 +++ b/arch/x86/kernel/ldt.c
25839 @@ -20,6 +20,8 @@
25840 #include <asm/mmu_context.h>
25841 #include <asm/syscalls.h>
25842
25843 +int sysctl_ldt16 = 0;
25844 +
25845 #ifdef CONFIG_SMP
25846 static void flush_ldt(void *current_mm)
25847 {
25848 @@ -66,13 +68,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25849 if (reload) {
25850 #ifdef CONFIG_SMP
25851 preempt_disable();
25852 - load_LDT(pc);
25853 + load_LDT_nolock(pc);
25854 if (!cpumask_equal(mm_cpumask(current->mm),
25855 cpumask_of(smp_processor_id())))
25856 smp_call_function(flush_ldt, current->mm, 1);
25857 preempt_enable();
25858 #else
25859 - load_LDT(pc);
25860 + load_LDT_nolock(pc);
25861 #endif
25862 }
25863 if (oldsize) {
25864 @@ -94,7 +96,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25865 return err;
25866
25867 for (i = 0; i < old->size; i++)
25868 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25869 + write_ldt_entry(new->ldt, i, old->ldt + i);
25870 return 0;
25871 }
25872
25873 @@ -115,6 +117,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25874 retval = copy_ldt(&mm->context, &old_mm->context);
25875 mutex_unlock(&old_mm->context.lock);
25876 }
25877 +
25878 + if (tsk == current) {
25879 + mm->context.vdso = 0;
25880 +
25881 +#ifdef CONFIG_X86_32
25882 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25883 + mm->context.user_cs_base = 0UL;
25884 + mm->context.user_cs_limit = ~0UL;
25885 +
25886 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25887 + cpus_clear(mm->context.cpu_user_cs_mask);
25888 +#endif
25889 +
25890 +#endif
25891 +#endif
25892 +
25893 + }
25894 +
25895 return retval;
25896 }
25897
25898 @@ -229,12 +249,19 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25899 }
25900 }
25901
25902 +#ifdef CONFIG_PAX_SEGMEXEC
25903 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25904 + error = -EINVAL;
25905 + goto out_unlock;
25906 + }
25907 +#endif
25908 +
25909 /*
25910 * On x86-64 we do not support 16-bit segments due to
25911 * IRET leaking the high bits of the kernel stack address.
25912 */
25913 #ifdef CONFIG_X86_64
25914 - if (!ldt_info.seg_32bit) {
25915 + if (!ldt_info.seg_32bit && !sysctl_ldt16) {
25916 error = -EINVAL;
25917 goto out_unlock;
25918 }
25919 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25920 index 1667b1d..16492c5 100644
25921 --- a/arch/x86/kernel/machine_kexec_32.c
25922 +++ b/arch/x86/kernel/machine_kexec_32.c
25923 @@ -25,7 +25,7 @@
25924 #include <asm/cacheflush.h>
25925 #include <asm/debugreg.h>
25926
25927 -static void set_idt(void *newidt, __u16 limit)
25928 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25929 {
25930 struct desc_ptr curidt;
25931
25932 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25933 }
25934
25935
25936 -static void set_gdt(void *newgdt, __u16 limit)
25937 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25938 {
25939 struct desc_ptr curgdt;
25940
25941 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25942 }
25943
25944 control_page = page_address(image->control_code_page);
25945 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25946 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25947
25948 relocate_kernel_ptr = control_page;
25949 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25950 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25951 index 18be189..4a9fe40 100644
25952 --- a/arch/x86/kernel/module.c
25953 +++ b/arch/x86/kernel/module.c
25954 @@ -43,15 +43,60 @@ do { \
25955 } while (0)
25956 #endif
25957
25958 -void *module_alloc(unsigned long size)
25959 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25960 {
25961 - if (PAGE_ALIGN(size) > MODULES_LEN)
25962 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25963 return NULL;
25964 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25965 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25966 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25967 NUMA_NO_NODE, __builtin_return_address(0));
25968 }
25969
25970 +void *module_alloc(unsigned long size)
25971 +{
25972 +
25973 +#ifdef CONFIG_PAX_KERNEXEC
25974 + return __module_alloc(size, PAGE_KERNEL);
25975 +#else
25976 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25977 +#endif
25978 +
25979 +}
25980 +
25981 +#ifdef CONFIG_PAX_KERNEXEC
25982 +#ifdef CONFIG_X86_32
25983 +void *module_alloc_exec(unsigned long size)
25984 +{
25985 + struct vm_struct *area;
25986 +
25987 + if (size == 0)
25988 + return NULL;
25989 +
25990 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25991 + return area ? area->addr : NULL;
25992 +}
25993 +EXPORT_SYMBOL(module_alloc_exec);
25994 +
25995 +void module_free_exec(struct module *mod, void *module_region)
25996 +{
25997 + vunmap(module_region);
25998 +}
25999 +EXPORT_SYMBOL(module_free_exec);
26000 +#else
26001 +void module_free_exec(struct module *mod, void *module_region)
26002 +{
26003 + module_free(mod, module_region);
26004 +}
26005 +EXPORT_SYMBOL(module_free_exec);
26006 +
26007 +void *module_alloc_exec(unsigned long size)
26008 +{
26009 + return __module_alloc(size, PAGE_KERNEL_RX);
26010 +}
26011 +EXPORT_SYMBOL(module_alloc_exec);
26012 +#endif
26013 +#endif
26014 +
26015 #ifdef CONFIG_X86_32
26016 int apply_relocate(Elf32_Shdr *sechdrs,
26017 const char *strtab,
26018 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26019 unsigned int i;
26020 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26021 Elf32_Sym *sym;
26022 - uint32_t *location;
26023 + uint32_t *plocation, location;
26024
26025 DEBUGP("Applying relocate section %u to %u\n",
26026 relsec, sechdrs[relsec].sh_info);
26027 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26028 /* This is where to make the change */
26029 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26030 - + rel[i].r_offset;
26031 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26032 + location = (uint32_t)plocation;
26033 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26034 + plocation = ktla_ktva((void *)plocation);
26035 /* This is the symbol it is referring to. Note that all
26036 undefined symbols have been resolved. */
26037 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26038 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26039 switch (ELF32_R_TYPE(rel[i].r_info)) {
26040 case R_386_32:
26041 /* We add the value into the location given */
26042 - *location += sym->st_value;
26043 + pax_open_kernel();
26044 + *plocation += sym->st_value;
26045 + pax_close_kernel();
26046 break;
26047 case R_386_PC32:
26048 /* Add the value, subtract its position */
26049 - *location += sym->st_value - (uint32_t)location;
26050 + pax_open_kernel();
26051 + *plocation += sym->st_value - location;
26052 + pax_close_kernel();
26053 break;
26054 default:
26055 pr_err("%s: Unknown relocation: %u\n",
26056 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26057 case R_X86_64_NONE:
26058 break;
26059 case R_X86_64_64:
26060 + pax_open_kernel();
26061 *(u64 *)loc = val;
26062 + pax_close_kernel();
26063 break;
26064 case R_X86_64_32:
26065 + pax_open_kernel();
26066 *(u32 *)loc = val;
26067 + pax_close_kernel();
26068 if (val != *(u32 *)loc)
26069 goto overflow;
26070 break;
26071 case R_X86_64_32S:
26072 + pax_open_kernel();
26073 *(s32 *)loc = val;
26074 + pax_close_kernel();
26075 if ((s64)val != *(s32 *)loc)
26076 goto overflow;
26077 break;
26078 case R_X86_64_PC32:
26079 val -= (u64)loc;
26080 + pax_open_kernel();
26081 *(u32 *)loc = val;
26082 + pax_close_kernel();
26083 +
26084 #if 0
26085 if ((s64)val != *(s32 *)loc)
26086 goto overflow;
26087 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26088 index 05266b5..3432443 100644
26089 --- a/arch/x86/kernel/msr.c
26090 +++ b/arch/x86/kernel/msr.c
26091 @@ -37,6 +37,7 @@
26092 #include <linux/notifier.h>
26093 #include <linux/uaccess.h>
26094 #include <linux/gfp.h>
26095 +#include <linux/grsecurity.h>
26096
26097 #include <asm/processor.h>
26098 #include <asm/msr.h>
26099 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26100 int err = 0;
26101 ssize_t bytes = 0;
26102
26103 +#ifdef CONFIG_GRKERNSEC_KMEM
26104 + gr_handle_msr_write();
26105 + return -EPERM;
26106 +#endif
26107 +
26108 if (count % 8)
26109 return -EINVAL; /* Invalid chunk size */
26110
26111 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26112 err = -EBADF;
26113 break;
26114 }
26115 +#ifdef CONFIG_GRKERNSEC_KMEM
26116 + gr_handle_msr_write();
26117 + return -EPERM;
26118 +#endif
26119 if (copy_from_user(&regs, uregs, sizeof regs)) {
26120 err = -EFAULT;
26121 break;
26122 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26123 return notifier_from_errno(err);
26124 }
26125
26126 -static struct notifier_block __refdata msr_class_cpu_notifier = {
26127 +static struct notifier_block msr_class_cpu_notifier = {
26128 .notifier_call = msr_class_cpu_callback,
26129 };
26130
26131 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26132 index 6fcb49c..5b3f4ff 100644
26133 --- a/arch/x86/kernel/nmi.c
26134 +++ b/arch/x86/kernel/nmi.c
26135 @@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
26136 return handled;
26137 }
26138
26139 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26140 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26141 {
26142 struct nmi_desc *desc = nmi_to_desc(type);
26143 unsigned long flags;
26144 @@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26145 * event confuses some handlers (kdump uses this flag)
26146 */
26147 if (action->flags & NMI_FLAG_FIRST)
26148 - list_add_rcu(&action->list, &desc->head);
26149 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26150 else
26151 - list_add_tail_rcu(&action->list, &desc->head);
26152 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26153
26154 spin_unlock_irqrestore(&desc->lock, flags);
26155 return 0;
26156 @@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26157 if (!strcmp(n->name, name)) {
26158 WARN(in_nmi(),
26159 "Trying to free NMI (%s) from NMI context!\n", n->name);
26160 - list_del_rcu(&n->list);
26161 + pax_list_del_rcu((struct list_head *)&n->list);
26162 break;
26163 }
26164 }
26165 @@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
26166 dotraplinkage notrace __kprobes void
26167 do_nmi(struct pt_regs *regs, long error_code)
26168 {
26169 +
26170 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26171 + if (!user_mode(regs)) {
26172 + unsigned long cs = regs->cs & 0xFFFF;
26173 + unsigned long ip = ktva_ktla(regs->ip);
26174 +
26175 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26176 + regs->ip = ip;
26177 + }
26178 +#endif
26179 +
26180 nmi_nesting_preprocess(regs);
26181
26182 nmi_enter();
26183 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26184 index 6d9582e..f746287 100644
26185 --- a/arch/x86/kernel/nmi_selftest.c
26186 +++ b/arch/x86/kernel/nmi_selftest.c
26187 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26188 {
26189 /* trap all the unknown NMIs we may generate */
26190 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26191 - __initdata);
26192 + __initconst);
26193 }
26194
26195 static void __init cleanup_nmi_testsuite(void)
26196 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26197 unsigned long timeout;
26198
26199 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26200 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26201 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26202 nmi_fail = FAILURE;
26203 return;
26204 }
26205 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26206 index bbb6c73..24a58ef 100644
26207 --- a/arch/x86/kernel/paravirt-spinlocks.c
26208 +++ b/arch/x86/kernel/paravirt-spinlocks.c
26209 @@ -8,7 +8,7 @@
26210
26211 #include <asm/paravirt.h>
26212
26213 -struct pv_lock_ops pv_lock_ops = {
26214 +struct pv_lock_ops pv_lock_ops __read_only = {
26215 #ifdef CONFIG_SMP
26216 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26217 .unlock_kick = paravirt_nop,
26218 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26219 index 1b10af8..45bfbec 100644
26220 --- a/arch/x86/kernel/paravirt.c
26221 +++ b/arch/x86/kernel/paravirt.c
26222 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
26223 {
26224 return x;
26225 }
26226 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26227 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26228 +#endif
26229
26230 void __init default_banner(void)
26231 {
26232 @@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26233
26234 if (opfunc == NULL)
26235 /* If there's no function, patch it with a ud2a (BUG) */
26236 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26237 - else if (opfunc == _paravirt_nop)
26238 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26239 + else if (opfunc == (void *)_paravirt_nop)
26240 /* If the operation is a nop, then nop the callsite */
26241 ret = paravirt_patch_nop();
26242
26243 /* identity functions just return their single argument */
26244 - else if (opfunc == _paravirt_ident_32)
26245 + else if (opfunc == (void *)_paravirt_ident_32)
26246 ret = paravirt_patch_ident_32(insnbuf, len);
26247 - else if (opfunc == _paravirt_ident_64)
26248 + else if (opfunc == (void *)_paravirt_ident_64)
26249 ret = paravirt_patch_ident_64(insnbuf, len);
26250 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26251 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26252 + ret = paravirt_patch_ident_64(insnbuf, len);
26253 +#endif
26254
26255 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26256 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26257 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26258 if (insn_len > len || start == NULL)
26259 insn_len = len;
26260 else
26261 - memcpy(insnbuf, start, insn_len);
26262 + memcpy(insnbuf, ktla_ktva(start), insn_len);
26263
26264 return insn_len;
26265 }
26266 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26267 return this_cpu_read(paravirt_lazy_mode);
26268 }
26269
26270 -struct pv_info pv_info = {
26271 +struct pv_info pv_info __read_only = {
26272 .name = "bare hardware",
26273 .paravirt_enabled = 0,
26274 .kernel_rpl = 0,
26275 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
26276 #endif
26277 };
26278
26279 -struct pv_init_ops pv_init_ops = {
26280 +struct pv_init_ops pv_init_ops __read_only = {
26281 .patch = native_patch,
26282 };
26283
26284 -struct pv_time_ops pv_time_ops = {
26285 +struct pv_time_ops pv_time_ops __read_only = {
26286 .sched_clock = native_sched_clock,
26287 .steal_clock = native_steal_clock,
26288 };
26289
26290 -__visible struct pv_irq_ops pv_irq_ops = {
26291 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
26292 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26293 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26294 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26295 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26296 #endif
26297 };
26298
26299 -__visible struct pv_cpu_ops pv_cpu_ops = {
26300 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26301 .cpuid = native_cpuid,
26302 .get_debugreg = native_get_debugreg,
26303 .set_debugreg = native_set_debugreg,
26304 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
26305 .end_context_switch = paravirt_nop,
26306 };
26307
26308 -struct pv_apic_ops pv_apic_ops = {
26309 +struct pv_apic_ops pv_apic_ops __read_only= {
26310 #ifdef CONFIG_X86_LOCAL_APIC
26311 .startup_ipi_hook = paravirt_nop,
26312 #endif
26313 };
26314
26315 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26316 +#ifdef CONFIG_X86_32
26317 +#ifdef CONFIG_X86_PAE
26318 +/* 64-bit pagetable entries */
26319 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26320 +#else
26321 /* 32-bit pagetable entries */
26322 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26323 +#endif
26324 #else
26325 /* 64-bit pagetable entries */
26326 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26327 #endif
26328
26329 -struct pv_mmu_ops pv_mmu_ops = {
26330 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26331
26332 .read_cr2 = native_read_cr2,
26333 .write_cr2 = native_write_cr2,
26334 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26335 .make_pud = PTE_IDENT,
26336
26337 .set_pgd = native_set_pgd,
26338 + .set_pgd_batched = native_set_pgd_batched,
26339 #endif
26340 #endif /* PAGETABLE_LEVELS >= 3 */
26341
26342 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26343 },
26344
26345 .set_fixmap = native_set_fixmap,
26346 +
26347 +#ifdef CONFIG_PAX_KERNEXEC
26348 + .pax_open_kernel = native_pax_open_kernel,
26349 + .pax_close_kernel = native_pax_close_kernel,
26350 +#endif
26351 +
26352 };
26353
26354 EXPORT_SYMBOL_GPL(pv_time_ops);
26355 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26356 index 299d493..2ccb0ee 100644
26357 --- a/arch/x86/kernel/pci-calgary_64.c
26358 +++ b/arch/x86/kernel/pci-calgary_64.c
26359 @@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
26360 tce_space = be64_to_cpu(readq(target));
26361 tce_space = tce_space & TAR_SW_BITS;
26362
26363 - tce_space = tce_space & (~specified_table_size);
26364 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26365 info->tce_space = (u64 *)__va(tce_space);
26366 }
26367 }
26368 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26369 index 35ccf75..7a15747 100644
26370 --- a/arch/x86/kernel/pci-iommu_table.c
26371 +++ b/arch/x86/kernel/pci-iommu_table.c
26372 @@ -2,7 +2,7 @@
26373 #include <asm/iommu_table.h>
26374 #include <linux/string.h>
26375 #include <linux/kallsyms.h>
26376 -
26377 +#include <linux/sched.h>
26378
26379 #define DEBUG 1
26380
26381 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26382 index 6c483ba..d10ce2f 100644
26383 --- a/arch/x86/kernel/pci-swiotlb.c
26384 +++ b/arch/x86/kernel/pci-swiotlb.c
26385 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26386 void *vaddr, dma_addr_t dma_addr,
26387 struct dma_attrs *attrs)
26388 {
26389 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26390 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26391 }
26392
26393 static struct dma_map_ops swiotlb_dma_ops = {
26394 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26395 index ca7f0d5..8996469 100644
26396 --- a/arch/x86/kernel/preempt.S
26397 +++ b/arch/x86/kernel/preempt.S
26398 @@ -3,12 +3,14 @@
26399 #include <asm/dwarf2.h>
26400 #include <asm/asm.h>
26401 #include <asm/calling.h>
26402 +#include <asm/alternative-asm.h>
26403
26404 ENTRY(___preempt_schedule)
26405 CFI_STARTPROC
26406 SAVE_ALL
26407 call preempt_schedule
26408 RESTORE_ALL
26409 + pax_force_retaddr
26410 ret
26411 CFI_ENDPROC
26412
26413 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26414 SAVE_ALL
26415 call preempt_schedule_context
26416 RESTORE_ALL
26417 + pax_force_retaddr
26418 ret
26419 CFI_ENDPROC
26420
26421 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26422 index 3fb8d95..254dc51 100644
26423 --- a/arch/x86/kernel/process.c
26424 +++ b/arch/x86/kernel/process.c
26425 @@ -36,7 +36,8 @@
26426 * section. Since TSS's are completely CPU-local, we want them
26427 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26428 */
26429 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26430 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26431 +EXPORT_SYMBOL(init_tss);
26432
26433 #ifdef CONFIG_X86_64
26434 static DEFINE_PER_CPU(unsigned char, is_idle);
26435 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26436 task_xstate_cachep =
26437 kmem_cache_create("task_xstate", xstate_size,
26438 __alignof__(union thread_xstate),
26439 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26440 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26441 }
26442
26443 /*
26444 @@ -105,7 +106,7 @@ void exit_thread(void)
26445 unsigned long *bp = t->io_bitmap_ptr;
26446
26447 if (bp) {
26448 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26449 + struct tss_struct *tss = init_tss + get_cpu();
26450
26451 t->io_bitmap_ptr = NULL;
26452 clear_thread_flag(TIF_IO_BITMAP);
26453 @@ -125,6 +126,9 @@ void flush_thread(void)
26454 {
26455 struct task_struct *tsk = current;
26456
26457 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26458 + loadsegment(gs, 0);
26459 +#endif
26460 flush_ptrace_hw_breakpoint(tsk);
26461 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26462 drop_init_fpu(tsk);
26463 @@ -271,7 +275,7 @@ static void __exit_idle(void)
26464 void exit_idle(void)
26465 {
26466 /* idle loop has pid 0 */
26467 - if (current->pid)
26468 + if (task_pid_nr(current))
26469 return;
26470 __exit_idle();
26471 }
26472 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26473 return ret;
26474 }
26475 #endif
26476 -void stop_this_cpu(void *dummy)
26477 +__noreturn void stop_this_cpu(void *dummy)
26478 {
26479 local_irq_disable();
26480 /*
26481 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26482 }
26483 early_param("idle", idle_setup);
26484
26485 -unsigned long arch_align_stack(unsigned long sp)
26486 +#ifdef CONFIG_PAX_RANDKSTACK
26487 +void pax_randomize_kstack(struct pt_regs *regs)
26488 {
26489 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26490 - sp -= get_random_int() % 8192;
26491 - return sp & ~0xf;
26492 -}
26493 + struct thread_struct *thread = &current->thread;
26494 + unsigned long time;
26495
26496 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26497 -{
26498 - unsigned long range_end = mm->brk + 0x02000000;
26499 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26500 -}
26501 + if (!randomize_va_space)
26502 + return;
26503 +
26504 + if (v8086_mode(regs))
26505 + return;
26506
26507 + rdtscl(time);
26508 +
26509 + /* P4 seems to return a 0 LSB, ignore it */
26510 +#ifdef CONFIG_MPENTIUM4
26511 + time &= 0x3EUL;
26512 + time <<= 2;
26513 +#elif defined(CONFIG_X86_64)
26514 + time &= 0xFUL;
26515 + time <<= 4;
26516 +#else
26517 + time &= 0x1FUL;
26518 + time <<= 3;
26519 +#endif
26520 +
26521 + thread->sp0 ^= time;
26522 + load_sp0(init_tss + smp_processor_id(), thread);
26523 +
26524 +#ifdef CONFIG_X86_64
26525 + this_cpu_write(kernel_stack, thread->sp0);
26526 +#endif
26527 +}
26528 +#endif
26529 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26530 index 0de43e9..056b840 100644
26531 --- a/arch/x86/kernel/process_32.c
26532 +++ b/arch/x86/kernel/process_32.c
26533 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26534 unsigned long thread_saved_pc(struct task_struct *tsk)
26535 {
26536 return ((unsigned long *)tsk->thread.sp)[3];
26537 +//XXX return tsk->thread.eip;
26538 }
26539
26540 void __show_regs(struct pt_regs *regs, int all)
26541 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26542 unsigned long sp;
26543 unsigned short ss, gs;
26544
26545 - if (user_mode_vm(regs)) {
26546 + if (user_mode(regs)) {
26547 sp = regs->sp;
26548 ss = regs->ss & 0xffff;
26549 - gs = get_user_gs(regs);
26550 } else {
26551 sp = kernel_stack_pointer(regs);
26552 savesegment(ss, ss);
26553 - savesegment(gs, gs);
26554 }
26555 + gs = get_user_gs(regs);
26556
26557 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26558 (u16)regs->cs, regs->ip, regs->flags,
26559 - smp_processor_id());
26560 + raw_smp_processor_id());
26561 print_symbol("EIP is at %s\n", regs->ip);
26562
26563 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26564 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26565 int copy_thread(unsigned long clone_flags, unsigned long sp,
26566 unsigned long arg, struct task_struct *p)
26567 {
26568 - struct pt_regs *childregs = task_pt_regs(p);
26569 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26570 struct task_struct *tsk;
26571 int err;
26572
26573 p->thread.sp = (unsigned long) childregs;
26574 p->thread.sp0 = (unsigned long) (childregs+1);
26575 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26576
26577 if (unlikely(p->flags & PF_KTHREAD)) {
26578 /* kernel thread */
26579 memset(childregs, 0, sizeof(struct pt_regs));
26580 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26581 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26582 - childregs->ds = __USER_DS;
26583 - childregs->es = __USER_DS;
26584 + savesegment(gs, childregs->gs);
26585 + childregs->ds = __KERNEL_DS;
26586 + childregs->es = __KERNEL_DS;
26587 childregs->fs = __KERNEL_PERCPU;
26588 childregs->bx = sp; /* function */
26589 childregs->bp = arg;
26590 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26591 struct thread_struct *prev = &prev_p->thread,
26592 *next = &next_p->thread;
26593 int cpu = smp_processor_id();
26594 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26595 + struct tss_struct *tss = init_tss + cpu;
26596 fpu_switch_t fpu;
26597
26598 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26599 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26600 */
26601 lazy_save_gs(prev->gs);
26602
26603 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26604 + __set_fs(task_thread_info(next_p)->addr_limit);
26605 +#endif
26606 +
26607 /*
26608 * Load the per-thread Thread-Local Storage descriptor.
26609 */
26610 @@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26611 */
26612 arch_end_context_switch(next_p);
26613
26614 + this_cpu_write(current_task, next_p);
26615 + this_cpu_write(current_tinfo, &next_p->tinfo);
26616 +
26617 /*
26618 * Restore %gs if needed (which is common)
26619 */
26620 @@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26621
26622 switch_fpu_finish(next_p, fpu);
26623
26624 - this_cpu_write(current_task, next_p);
26625 -
26626 return prev_p;
26627 }
26628
26629 @@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26630 } while (count++ < 16);
26631 return 0;
26632 }
26633 -
26634 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26635 index 9c0280f..5bbb1c0 100644
26636 --- a/arch/x86/kernel/process_64.c
26637 +++ b/arch/x86/kernel/process_64.c
26638 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26639 struct pt_regs *childregs;
26640 struct task_struct *me = current;
26641
26642 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26643 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26644 childregs = task_pt_regs(p);
26645 p->thread.sp = (unsigned long) childregs;
26646 p->thread.usersp = me->thread.usersp;
26647 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26648 set_tsk_thread_flag(p, TIF_FORK);
26649 p->thread.fpu_counter = 0;
26650 p->thread.io_bitmap_ptr = NULL;
26651 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26652 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26653 savesegment(es, p->thread.es);
26654 savesegment(ds, p->thread.ds);
26655 + savesegment(ss, p->thread.ss);
26656 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26657 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26658
26659 if (unlikely(p->flags & PF_KTHREAD)) {
26660 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26661 struct thread_struct *prev = &prev_p->thread;
26662 struct thread_struct *next = &next_p->thread;
26663 int cpu = smp_processor_id();
26664 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26665 + struct tss_struct *tss = init_tss + cpu;
26666 unsigned fsindex, gsindex;
26667 fpu_switch_t fpu;
26668
26669 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26670 if (unlikely(next->ds | prev->ds))
26671 loadsegment(ds, next->ds);
26672
26673 + savesegment(ss, prev->ss);
26674 + if (unlikely(next->ss != prev->ss))
26675 + loadsegment(ss, next->ss);
26676
26677 /* We must save %fs and %gs before load_TLS() because
26678 * %fs and %gs may be cleared by load_TLS().
26679 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26680 prev->usersp = this_cpu_read(old_rsp);
26681 this_cpu_write(old_rsp, next->usersp);
26682 this_cpu_write(current_task, next_p);
26683 + this_cpu_write(current_tinfo, &next_p->tinfo);
26684
26685 /*
26686 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26687 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26688 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26689 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26690
26691 - this_cpu_write(kernel_stack,
26692 - (unsigned long)task_stack_page(next_p) +
26693 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26694 + this_cpu_write(kernel_stack, next->sp0);
26695
26696 /*
26697 * Now maybe reload the debug registers and handle I/O bitmaps
26698 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26699 if (!p || p == current || p->state == TASK_RUNNING)
26700 return 0;
26701 stack = (unsigned long)task_stack_page(p);
26702 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26703 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26704 return 0;
26705 fp = *(u64 *)(p->thread.sp);
26706 do {
26707 - if (fp < (unsigned long)stack ||
26708 - fp >= (unsigned long)stack+THREAD_SIZE)
26709 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26710 return 0;
26711 ip = *(u64 *)(fp+8);
26712 if (!in_sched_functions(ip))
26713 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26714 index 7461f50..1334029 100644
26715 --- a/arch/x86/kernel/ptrace.c
26716 +++ b/arch/x86/kernel/ptrace.c
26717 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26718 {
26719 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26720 unsigned long sp = (unsigned long)&regs->sp;
26721 - struct thread_info *tinfo;
26722
26723 - if (context == (sp & ~(THREAD_SIZE - 1)))
26724 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26725 return sp;
26726
26727 - tinfo = (struct thread_info *)context;
26728 - if (tinfo->previous_esp)
26729 - return tinfo->previous_esp;
26730 + sp = *(unsigned long *)context;
26731 + if (sp)
26732 + return sp;
26733
26734 return (unsigned long)regs;
26735 }
26736 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26737 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26738 {
26739 int i;
26740 - int dr7 = 0;
26741 + unsigned long dr7 = 0;
26742 struct arch_hw_breakpoint *info;
26743
26744 for (i = 0; i < HBP_NUM; i++) {
26745 @@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26746 unsigned long addr, unsigned long data)
26747 {
26748 int ret;
26749 - unsigned long __user *datap = (unsigned long __user *)data;
26750 + unsigned long __user *datap = (__force unsigned long __user *)data;
26751
26752 switch (request) {
26753 /* read the word at location addr in the USER area. */
26754 @@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26755 if ((int) addr < 0)
26756 return -EIO;
26757 ret = do_get_thread_area(child, addr,
26758 - (struct user_desc __user *)data);
26759 + (__force struct user_desc __user *) data);
26760 break;
26761
26762 case PTRACE_SET_THREAD_AREA:
26763 if ((int) addr < 0)
26764 return -EIO;
26765 ret = do_set_thread_area(child, addr,
26766 - (struct user_desc __user *)data, 0);
26767 + (__force struct user_desc __user *) data, 0);
26768 break;
26769 #endif
26770
26771 @@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26772
26773 #ifdef CONFIG_X86_64
26774
26775 -static struct user_regset x86_64_regsets[] __read_mostly = {
26776 +static user_regset_no_const x86_64_regsets[] __read_only = {
26777 [REGSET_GENERAL] = {
26778 .core_note_type = NT_PRSTATUS,
26779 .n = sizeof(struct user_regs_struct) / sizeof(long),
26780 @@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26781 #endif /* CONFIG_X86_64 */
26782
26783 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26784 -static struct user_regset x86_32_regsets[] __read_mostly = {
26785 +static user_regset_no_const x86_32_regsets[] __read_only = {
26786 [REGSET_GENERAL] = {
26787 .core_note_type = NT_PRSTATUS,
26788 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26789 @@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26790 */
26791 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26792
26793 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26794 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26795 {
26796 #ifdef CONFIG_X86_64
26797 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26798 @@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26799 memset(info, 0, sizeof(*info));
26800 info->si_signo = SIGTRAP;
26801 info->si_code = si_code;
26802 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26803 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26804 }
26805
26806 void user_single_step_siginfo(struct task_struct *tsk,
26807 @@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26808 # define IS_IA32 0
26809 #endif
26810
26811 +#ifdef CONFIG_GRKERNSEC_SETXID
26812 +extern void gr_delayed_cred_worker(void);
26813 +#endif
26814 +
26815 /*
26816 * We must return the syscall number to actually look up in the table.
26817 * This can be -1L to skip running any syscall at all.
26818 @@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26819
26820 user_exit();
26821
26822 +#ifdef CONFIG_GRKERNSEC_SETXID
26823 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26824 + gr_delayed_cred_worker();
26825 +#endif
26826 +
26827 /*
26828 * If we stepped into a sysenter/syscall insn, it trapped in
26829 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26830 @@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26831 */
26832 user_exit();
26833
26834 +#ifdef CONFIG_GRKERNSEC_SETXID
26835 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26836 + gr_delayed_cred_worker();
26837 +#endif
26838 +
26839 audit_syscall_exit(regs);
26840
26841 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26842 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26843 index 2f355d2..e75ed0a 100644
26844 --- a/arch/x86/kernel/pvclock.c
26845 +++ b/arch/x86/kernel/pvclock.c
26846 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26847 reset_hung_task_detector();
26848 }
26849
26850 -static atomic64_t last_value = ATOMIC64_INIT(0);
26851 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26852
26853 void pvclock_resume(void)
26854 {
26855 - atomic64_set(&last_value, 0);
26856 + atomic64_set_unchecked(&last_value, 0);
26857 }
26858
26859 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26860 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26861 * updating at the same time, and one of them could be slightly behind,
26862 * making the assumption that last_value always go forward fail to hold.
26863 */
26864 - last = atomic64_read(&last_value);
26865 + last = atomic64_read_unchecked(&last_value);
26866 do {
26867 if (ret < last)
26868 return last;
26869 - last = atomic64_cmpxchg(&last_value, last, ret);
26870 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26871 } while (unlikely(last != ret));
26872
26873 return ret;
26874 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26875 index c752cb4..866c432 100644
26876 --- a/arch/x86/kernel/reboot.c
26877 +++ b/arch/x86/kernel/reboot.c
26878 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26879
26880 void __noreturn machine_real_restart(unsigned int type)
26881 {
26882 +
26883 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26884 + struct desc_struct *gdt;
26885 +#endif
26886 +
26887 local_irq_disable();
26888
26889 /*
26890 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26891
26892 /* Jump to the identity-mapped low memory code */
26893 #ifdef CONFIG_X86_32
26894 - asm volatile("jmpl *%0" : :
26895 +
26896 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26897 + gdt = get_cpu_gdt_table(smp_processor_id());
26898 + pax_open_kernel();
26899 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26900 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26901 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26902 + loadsegment(ds, __KERNEL_DS);
26903 + loadsegment(es, __KERNEL_DS);
26904 + loadsegment(ss, __KERNEL_DS);
26905 +#endif
26906 +#ifdef CONFIG_PAX_KERNEXEC
26907 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26908 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26909 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26910 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26911 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26912 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26913 +#endif
26914 + pax_close_kernel();
26915 +#endif
26916 +
26917 + asm volatile("ljmpl *%0" : :
26918 "rm" (real_mode_header->machine_real_restart_asm),
26919 "a" (type));
26920 #else
26921 @@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26922 * try to force a triple fault and then cycle between hitting the keyboard
26923 * controller and doing that
26924 */
26925 -static void native_machine_emergency_restart(void)
26926 +static void __noreturn native_machine_emergency_restart(void)
26927 {
26928 int i;
26929 int attempt = 0;
26930 @@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26931 #endif
26932 }
26933
26934 -static void __machine_emergency_restart(int emergency)
26935 +static void __noreturn __machine_emergency_restart(int emergency)
26936 {
26937 reboot_emergency = emergency;
26938 machine_ops.emergency_restart();
26939 }
26940
26941 -static void native_machine_restart(char *__unused)
26942 +static void __noreturn native_machine_restart(char *__unused)
26943 {
26944 pr_notice("machine restart\n");
26945
26946 @@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26947 __machine_emergency_restart(0);
26948 }
26949
26950 -static void native_machine_halt(void)
26951 +static void __noreturn native_machine_halt(void)
26952 {
26953 /* Stop other cpus and apics */
26954 machine_shutdown();
26955 @@ -618,7 +645,7 @@ static void native_machine_halt(void)
26956 stop_this_cpu(NULL);
26957 }
26958
26959 -static void native_machine_power_off(void)
26960 +static void __noreturn native_machine_power_off(void)
26961 {
26962 if (pm_power_off) {
26963 if (!reboot_force)
26964 @@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26965 }
26966 /* A fallback in case there is no PM info available */
26967 tboot_shutdown(TB_SHUTDOWN_HALT);
26968 + unreachable();
26969 }
26970
26971 -struct machine_ops machine_ops = {
26972 +struct machine_ops machine_ops __read_only = {
26973 .power_off = native_machine_power_off,
26974 .shutdown = native_machine_shutdown,
26975 .emergency_restart = native_machine_emergency_restart,
26976 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26977 index c8e41e9..64049ef 100644
26978 --- a/arch/x86/kernel/reboot_fixups_32.c
26979 +++ b/arch/x86/kernel/reboot_fixups_32.c
26980 @@ -57,7 +57,7 @@ struct device_fixup {
26981 unsigned int vendor;
26982 unsigned int device;
26983 void (*reboot_fixup)(struct pci_dev *);
26984 -};
26985 +} __do_const;
26986
26987 /*
26988 * PCI ids solely used for fixups_table go here
26989 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26990 index 3fd2c69..a444264 100644
26991 --- a/arch/x86/kernel/relocate_kernel_64.S
26992 +++ b/arch/x86/kernel/relocate_kernel_64.S
26993 @@ -96,8 +96,7 @@ relocate_kernel:
26994
26995 /* jump to identity mapped page */
26996 addq $(identity_mapped - relocate_kernel), %r8
26997 - pushq %r8
26998 - ret
26999 + jmp *%r8
27000
27001 identity_mapped:
27002 /* set return address to 0 if not preserving context */
27003 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27004 index ce72964..be8aea7 100644
27005 --- a/arch/x86/kernel/setup.c
27006 +++ b/arch/x86/kernel/setup.c
27007 @@ -110,6 +110,7 @@
27008 #include <asm/mce.h>
27009 #include <asm/alternative.h>
27010 #include <asm/prom.h>
27011 +#include <asm/boot.h>
27012
27013 /*
27014 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27015 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27016 #endif
27017
27018
27019 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27020 -__visible unsigned long mmu_cr4_features;
27021 +#ifdef CONFIG_X86_64
27022 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27023 +#elif defined(CONFIG_X86_PAE)
27024 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27025 #else
27026 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27027 +__visible unsigned long mmu_cr4_features __read_only;
27028 #endif
27029
27030 +void set_in_cr4(unsigned long mask)
27031 +{
27032 + unsigned long cr4 = read_cr4();
27033 +
27034 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27035 + return;
27036 +
27037 + pax_open_kernel();
27038 + mmu_cr4_features |= mask;
27039 + pax_close_kernel();
27040 +
27041 + if (trampoline_cr4_features)
27042 + *trampoline_cr4_features = mmu_cr4_features;
27043 + cr4 |= mask;
27044 + write_cr4(cr4);
27045 +}
27046 +EXPORT_SYMBOL(set_in_cr4);
27047 +
27048 +void clear_in_cr4(unsigned long mask)
27049 +{
27050 + unsigned long cr4 = read_cr4();
27051 +
27052 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27053 + return;
27054 +
27055 + pax_open_kernel();
27056 + mmu_cr4_features &= ~mask;
27057 + pax_close_kernel();
27058 +
27059 + if (trampoline_cr4_features)
27060 + *trampoline_cr4_features = mmu_cr4_features;
27061 + cr4 &= ~mask;
27062 + write_cr4(cr4);
27063 +}
27064 +EXPORT_SYMBOL(clear_in_cr4);
27065 +
27066 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27067 int bootloader_type, bootloader_version;
27068
27069 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27070 * area (640->1Mb) as ram even though it is not.
27071 * take them out.
27072 */
27073 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27074 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27075
27076 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27077 }
27078 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27079 /* called before trim_bios_range() to spare extra sanitize */
27080 static void __init e820_add_kernel_range(void)
27081 {
27082 - u64 start = __pa_symbol(_text);
27083 + u64 start = __pa_symbol(ktla_ktva(_text));
27084 u64 size = __pa_symbol(_end) - start;
27085
27086 /*
27087 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27088
27089 void __init setup_arch(char **cmdline_p)
27090 {
27091 +#ifdef CONFIG_X86_32
27092 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27093 +#else
27094 memblock_reserve(__pa_symbol(_text),
27095 (unsigned long)__bss_stop - (unsigned long)_text);
27096 +#endif
27097
27098 early_reserve_initrd();
27099
27100 @@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
27101
27102 if (!boot_params.hdr.root_flags)
27103 root_mountflags &= ~MS_RDONLY;
27104 - init_mm.start_code = (unsigned long) _text;
27105 - init_mm.end_code = (unsigned long) _etext;
27106 + init_mm.start_code = ktla_ktva((unsigned long) _text);
27107 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
27108 init_mm.end_data = (unsigned long) _edata;
27109 init_mm.brk = _brk_end;
27110
27111 - code_resource.start = __pa_symbol(_text);
27112 - code_resource.end = __pa_symbol(_etext)-1;
27113 - data_resource.start = __pa_symbol(_etext);
27114 + code_resource.start = __pa_symbol(ktla_ktva(_text));
27115 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27116 + data_resource.start = __pa_symbol(_sdata);
27117 data_resource.end = __pa_symbol(_edata)-1;
27118 bss_resource.start = __pa_symbol(__bss_start);
27119 bss_resource.end = __pa_symbol(__bss_stop)-1;
27120 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27121 index 5cdff03..80fa283 100644
27122 --- a/arch/x86/kernel/setup_percpu.c
27123 +++ b/arch/x86/kernel/setup_percpu.c
27124 @@ -21,19 +21,17 @@
27125 #include <asm/cpu.h>
27126 #include <asm/stackprotector.h>
27127
27128 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27129 +#ifdef CONFIG_SMP
27130 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27131 EXPORT_PER_CPU_SYMBOL(cpu_number);
27132 +#endif
27133
27134 -#ifdef CONFIG_X86_64
27135 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27136 -#else
27137 -#define BOOT_PERCPU_OFFSET 0
27138 -#endif
27139
27140 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27141 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27142
27143 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27144 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27145 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27146 };
27147 EXPORT_SYMBOL(__per_cpu_offset);
27148 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27149 {
27150 #ifdef CONFIG_NEED_MULTIPLE_NODES
27151 pg_data_t *last = NULL;
27152 - unsigned int cpu;
27153 + int cpu;
27154
27155 for_each_possible_cpu(cpu) {
27156 int node = early_cpu_to_node(cpu);
27157 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27158 {
27159 #ifdef CONFIG_X86_32
27160 struct desc_struct gdt;
27161 + unsigned long base = per_cpu_offset(cpu);
27162
27163 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27164 - 0x2 | DESCTYPE_S, 0x8);
27165 - gdt.s = 1;
27166 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27167 + 0x83 | DESCTYPE_S, 0xC);
27168 write_gdt_entry(get_cpu_gdt_table(cpu),
27169 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27170 #endif
27171 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27172 /* alrighty, percpu areas up and running */
27173 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27174 for_each_possible_cpu(cpu) {
27175 +#ifdef CONFIG_CC_STACKPROTECTOR
27176 +#ifdef CONFIG_X86_32
27177 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
27178 +#endif
27179 +#endif
27180 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27181 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27182 per_cpu(cpu_number, cpu) = cpu;
27183 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27184 */
27185 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27186 #endif
27187 +#ifdef CONFIG_CC_STACKPROTECTOR
27188 +#ifdef CONFIG_X86_32
27189 + if (!cpu)
27190 + per_cpu(stack_canary.canary, cpu) = canary;
27191 +#endif
27192 +#endif
27193 /*
27194 * Up to this point, the boot CPU has been using .init.data
27195 * area. Reload any changed state for the boot CPU.
27196 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27197 index 9e5de68..16c53cb 100644
27198 --- a/arch/x86/kernel/signal.c
27199 +++ b/arch/x86/kernel/signal.c
27200 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27201 * Align the stack pointer according to the i386 ABI,
27202 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27203 */
27204 - sp = ((sp + 4) & -16ul) - 4;
27205 + sp = ((sp - 12) & -16ul) - 4;
27206 #else /* !CONFIG_X86_32 */
27207 sp = round_down(sp, 16) - 8;
27208 #endif
27209 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27210 }
27211
27212 if (current->mm->context.vdso)
27213 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27214 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27215 else
27216 - restorer = &frame->retcode;
27217 + restorer = (void __user *)&frame->retcode;
27218 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27219 restorer = ksig->ka.sa.sa_restorer;
27220
27221 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27222 * reasons and because gdb uses it as a signature to notice
27223 * signal handler stack frames.
27224 */
27225 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27226 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27227
27228 if (err)
27229 return -EFAULT;
27230 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27231 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27232
27233 /* Set up to return from userspace. */
27234 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27235 + if (current->mm->context.vdso)
27236 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27237 + else
27238 + restorer = (void __user *)&frame->retcode;
27239 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27240 restorer = ksig->ka.sa.sa_restorer;
27241 put_user_ex(restorer, &frame->pretcode);
27242 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27243 * reasons and because gdb uses it as a signature to notice
27244 * signal handler stack frames.
27245 */
27246 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27247 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27248 } put_user_catch(err);
27249
27250 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27251 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27252 {
27253 int usig = signr_convert(ksig->sig);
27254 sigset_t *set = sigmask_to_save();
27255 - compat_sigset_t *cset = (compat_sigset_t *) set;
27256 + sigset_t sigcopy;
27257 + compat_sigset_t *cset;
27258 +
27259 + sigcopy = *set;
27260 +
27261 + cset = (compat_sigset_t *) &sigcopy;
27262
27263 /* Set up the stack frame */
27264 if (is_ia32_frame()) {
27265 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27266 } else if (is_x32_frame()) {
27267 return x32_setup_rt_frame(ksig, cset, regs);
27268 } else {
27269 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
27270 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27271 }
27272 }
27273
27274 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27275 index 7c3a5a6..f0a8961 100644
27276 --- a/arch/x86/kernel/smp.c
27277 +++ b/arch/x86/kernel/smp.c
27278 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27279
27280 __setup("nonmi_ipi", nonmi_ipi_setup);
27281
27282 -struct smp_ops smp_ops = {
27283 +struct smp_ops smp_ops __read_only = {
27284 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27285 .smp_prepare_cpus = native_smp_prepare_cpus,
27286 .smp_cpus_done = native_smp_cpus_done,
27287 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27288 index a32da80..30c97f1 100644
27289 --- a/arch/x86/kernel/smpboot.c
27290 +++ b/arch/x86/kernel/smpboot.c
27291 @@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
27292
27293 enable_start_cpu0 = 0;
27294
27295 -#ifdef CONFIG_X86_32
27296 - /* switch away from the initial page table */
27297 - load_cr3(swapper_pg_dir);
27298 - __flush_tlb_all();
27299 -#endif
27300 -
27301 /* otherwise gcc will move up smp_processor_id before the cpu_init */
27302 barrier();
27303 +
27304 + /* switch away from the initial page table */
27305 +#ifdef CONFIG_PAX_PER_CPU_PGD
27306 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27307 + __flush_tlb_all();
27308 +#elif defined(CONFIG_X86_32)
27309 + load_cr3(swapper_pg_dir);
27310 + __flush_tlb_all();
27311 +#endif
27312 +
27313 /*
27314 * Check TSC synchronization with the BP:
27315 */
27316 @@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27317 alternatives_enable_smp();
27318
27319 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27320 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27321 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27322 per_cpu(current_task, cpu) = idle;
27323 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27324
27325 #ifdef CONFIG_X86_32
27326 /* Stack for startup_32 can be just as for start_secondary onwards */
27327 @@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27328 #else
27329 clear_tsk_thread_flag(idle, TIF_FORK);
27330 initial_gs = per_cpu_offset(cpu);
27331 - per_cpu(kernel_stack, cpu) =
27332 - (unsigned long)task_stack_page(idle) -
27333 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27334 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27335 #endif
27336 +
27337 + pax_open_kernel();
27338 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27339 + pax_close_kernel();
27340 +
27341 initial_code = (unsigned long)start_secondary;
27342 stack_start = idle->thread.sp;
27343
27344 @@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27345 /* the FPU context is blank, nobody can own it */
27346 __cpu_disable_lazy_restore(cpu);
27347
27348 +#ifdef CONFIG_PAX_PER_CPU_PGD
27349 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27350 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27351 + KERNEL_PGD_PTRS);
27352 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27353 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27354 + KERNEL_PGD_PTRS);
27355 +#endif
27356 +
27357 err = do_boot_cpu(apicid, cpu, tidle);
27358 if (err) {
27359 pr_debug("do_boot_cpu failed %d\n", err);
27360 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27361 index 9b4d51d..5d28b58 100644
27362 --- a/arch/x86/kernel/step.c
27363 +++ b/arch/x86/kernel/step.c
27364 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27365 struct desc_struct *desc;
27366 unsigned long base;
27367
27368 - seg &= ~7UL;
27369 + seg >>= 3;
27370
27371 mutex_lock(&child->mm->context.lock);
27372 - if (unlikely((seg >> 3) >= child->mm->context.size))
27373 + if (unlikely(seg >= child->mm->context.size))
27374 addr = -1L; /* bogus selector, access would fault */
27375 else {
27376 desc = child->mm->context.ldt + seg;
27377 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27378 addr += base;
27379 }
27380 mutex_unlock(&child->mm->context.lock);
27381 - }
27382 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27383 + addr = ktla_ktva(addr);
27384
27385 return addr;
27386 }
27387 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27388 unsigned char opcode[15];
27389 unsigned long addr = convert_ip_to_linear(child, regs);
27390
27391 + if (addr == -EINVAL)
27392 + return 0;
27393 +
27394 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27395 for (i = 0; i < copied; i++) {
27396 switch (opcode[i]) {
27397 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27398 new file mode 100644
27399 index 0000000..5877189
27400 --- /dev/null
27401 +++ b/arch/x86/kernel/sys_i386_32.c
27402 @@ -0,0 +1,189 @@
27403 +/*
27404 + * This file contains various random system calls that
27405 + * have a non-standard calling sequence on the Linux/i386
27406 + * platform.
27407 + */
27408 +
27409 +#include <linux/errno.h>
27410 +#include <linux/sched.h>
27411 +#include <linux/mm.h>
27412 +#include <linux/fs.h>
27413 +#include <linux/smp.h>
27414 +#include <linux/sem.h>
27415 +#include <linux/msg.h>
27416 +#include <linux/shm.h>
27417 +#include <linux/stat.h>
27418 +#include <linux/syscalls.h>
27419 +#include <linux/mman.h>
27420 +#include <linux/file.h>
27421 +#include <linux/utsname.h>
27422 +#include <linux/ipc.h>
27423 +#include <linux/elf.h>
27424 +
27425 +#include <linux/uaccess.h>
27426 +#include <linux/unistd.h>
27427 +
27428 +#include <asm/syscalls.h>
27429 +
27430 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27431 +{
27432 + unsigned long pax_task_size = TASK_SIZE;
27433 +
27434 +#ifdef CONFIG_PAX_SEGMEXEC
27435 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27436 + pax_task_size = SEGMEXEC_TASK_SIZE;
27437 +#endif
27438 +
27439 + if (flags & MAP_FIXED)
27440 + if (len > pax_task_size || addr > pax_task_size - len)
27441 + return -EINVAL;
27442 +
27443 + return 0;
27444 +}
27445 +
27446 +/*
27447 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27448 + */
27449 +static unsigned long get_align_mask(void)
27450 +{
27451 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27452 + return 0;
27453 +
27454 + if (!(current->flags & PF_RANDOMIZE))
27455 + return 0;
27456 +
27457 + return va_align.mask;
27458 +}
27459 +
27460 +unsigned long
27461 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27462 + unsigned long len, unsigned long pgoff, unsigned long flags)
27463 +{
27464 + struct mm_struct *mm = current->mm;
27465 + struct vm_area_struct *vma;
27466 + unsigned long pax_task_size = TASK_SIZE;
27467 + struct vm_unmapped_area_info info;
27468 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27469 +
27470 +#ifdef CONFIG_PAX_SEGMEXEC
27471 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27472 + pax_task_size = SEGMEXEC_TASK_SIZE;
27473 +#endif
27474 +
27475 + pax_task_size -= PAGE_SIZE;
27476 +
27477 + if (len > pax_task_size)
27478 + return -ENOMEM;
27479 +
27480 + if (flags & MAP_FIXED)
27481 + return addr;
27482 +
27483 +#ifdef CONFIG_PAX_RANDMMAP
27484 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27485 +#endif
27486 +
27487 + if (addr) {
27488 + addr = PAGE_ALIGN(addr);
27489 + if (pax_task_size - len >= addr) {
27490 + vma = find_vma(mm, addr);
27491 + if (check_heap_stack_gap(vma, addr, len, offset))
27492 + return addr;
27493 + }
27494 + }
27495 +
27496 + info.flags = 0;
27497 + info.length = len;
27498 + info.align_mask = filp ? get_align_mask() : 0;
27499 + info.align_offset = pgoff << PAGE_SHIFT;
27500 + info.threadstack_offset = offset;
27501 +
27502 +#ifdef CONFIG_PAX_PAGEEXEC
27503 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27504 + info.low_limit = 0x00110000UL;
27505 + info.high_limit = mm->start_code;
27506 +
27507 +#ifdef CONFIG_PAX_RANDMMAP
27508 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27509 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27510 +#endif
27511 +
27512 + if (info.low_limit < info.high_limit) {
27513 + addr = vm_unmapped_area(&info);
27514 + if (!IS_ERR_VALUE(addr))
27515 + return addr;
27516 + }
27517 + } else
27518 +#endif
27519 +
27520 + info.low_limit = mm->mmap_base;
27521 + info.high_limit = pax_task_size;
27522 +
27523 + return vm_unmapped_area(&info);
27524 +}
27525 +
27526 +unsigned long
27527 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27528 + const unsigned long len, const unsigned long pgoff,
27529 + const unsigned long flags)
27530 +{
27531 + struct vm_area_struct *vma;
27532 + struct mm_struct *mm = current->mm;
27533 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27534 + struct vm_unmapped_area_info info;
27535 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27536 +
27537 +#ifdef CONFIG_PAX_SEGMEXEC
27538 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27539 + pax_task_size = SEGMEXEC_TASK_SIZE;
27540 +#endif
27541 +
27542 + pax_task_size -= PAGE_SIZE;
27543 +
27544 + /* requested length too big for entire address space */
27545 + if (len > pax_task_size)
27546 + return -ENOMEM;
27547 +
27548 + if (flags & MAP_FIXED)
27549 + return addr;
27550 +
27551 +#ifdef CONFIG_PAX_PAGEEXEC
27552 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27553 + goto bottomup;
27554 +#endif
27555 +
27556 +#ifdef CONFIG_PAX_RANDMMAP
27557 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27558 +#endif
27559 +
27560 + /* requesting a specific address */
27561 + if (addr) {
27562 + addr = PAGE_ALIGN(addr);
27563 + if (pax_task_size - len >= addr) {
27564 + vma = find_vma(mm, addr);
27565 + if (check_heap_stack_gap(vma, addr, len, offset))
27566 + return addr;
27567 + }
27568 + }
27569 +
27570 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27571 + info.length = len;
27572 + info.low_limit = PAGE_SIZE;
27573 + info.high_limit = mm->mmap_base;
27574 + info.align_mask = filp ? get_align_mask() : 0;
27575 + info.align_offset = pgoff << PAGE_SHIFT;
27576 + info.threadstack_offset = offset;
27577 +
27578 + addr = vm_unmapped_area(&info);
27579 + if (!(addr & ~PAGE_MASK))
27580 + return addr;
27581 + VM_BUG_ON(addr != -ENOMEM);
27582 +
27583 +bottomup:
27584 + /*
27585 + * A failed mmap() very likely causes application failure,
27586 + * so fall back to the bottom-up function here. This scenario
27587 + * can happen with large stack limits and large mmap()
27588 + * allocations.
27589 + */
27590 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27591 +}
27592 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27593 index 30277e2..5664a29 100644
27594 --- a/arch/x86/kernel/sys_x86_64.c
27595 +++ b/arch/x86/kernel/sys_x86_64.c
27596 @@ -81,8 +81,8 @@ out:
27597 return error;
27598 }
27599
27600 -static void find_start_end(unsigned long flags, unsigned long *begin,
27601 - unsigned long *end)
27602 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27603 + unsigned long *begin, unsigned long *end)
27604 {
27605 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27606 unsigned long new_begin;
27607 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27608 *begin = new_begin;
27609 }
27610 } else {
27611 - *begin = current->mm->mmap_legacy_base;
27612 + *begin = mm->mmap_legacy_base;
27613 *end = TASK_SIZE;
27614 }
27615 }
27616 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27617 struct vm_area_struct *vma;
27618 struct vm_unmapped_area_info info;
27619 unsigned long begin, end;
27620 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27621
27622 if (flags & MAP_FIXED)
27623 return addr;
27624
27625 - find_start_end(flags, &begin, &end);
27626 + find_start_end(mm, flags, &begin, &end);
27627
27628 if (len > end)
27629 return -ENOMEM;
27630
27631 +#ifdef CONFIG_PAX_RANDMMAP
27632 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27633 +#endif
27634 +
27635 if (addr) {
27636 addr = PAGE_ALIGN(addr);
27637 vma = find_vma(mm, addr);
27638 - if (end - len >= addr &&
27639 - (!vma || addr + len <= vma->vm_start))
27640 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27641 return addr;
27642 }
27643
27644 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27645 info.high_limit = end;
27646 info.align_mask = filp ? get_align_mask() : 0;
27647 info.align_offset = pgoff << PAGE_SHIFT;
27648 + info.threadstack_offset = offset;
27649 return vm_unmapped_area(&info);
27650 }
27651
27652 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27653 struct mm_struct *mm = current->mm;
27654 unsigned long addr = addr0;
27655 struct vm_unmapped_area_info info;
27656 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27657
27658 /* requested length too big for entire address space */
27659 if (len > TASK_SIZE)
27660 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27661 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27662 goto bottomup;
27663
27664 +#ifdef CONFIG_PAX_RANDMMAP
27665 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27666 +#endif
27667 +
27668 /* requesting a specific address */
27669 if (addr) {
27670 addr = PAGE_ALIGN(addr);
27671 vma = find_vma(mm, addr);
27672 - if (TASK_SIZE - len >= addr &&
27673 - (!vma || addr + len <= vma->vm_start))
27674 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27675 return addr;
27676 }
27677
27678 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27679 info.high_limit = mm->mmap_base;
27680 info.align_mask = filp ? get_align_mask() : 0;
27681 info.align_offset = pgoff << PAGE_SHIFT;
27682 + info.threadstack_offset = offset;
27683 addr = vm_unmapped_area(&info);
27684 if (!(addr & ~PAGE_MASK))
27685 return addr;
27686 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27687 index 91a4496..bb87552 100644
27688 --- a/arch/x86/kernel/tboot.c
27689 +++ b/arch/x86/kernel/tboot.c
27690 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27691
27692 void tboot_shutdown(u32 shutdown_type)
27693 {
27694 - void (*shutdown)(void);
27695 + void (* __noreturn shutdown)(void);
27696
27697 if (!tboot_enabled())
27698 return;
27699 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27700
27701 switch_to_tboot_pt();
27702
27703 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27704 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27705 shutdown();
27706
27707 /* should not reach here */
27708 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27709 return -ENODEV;
27710 }
27711
27712 -static atomic_t ap_wfs_count;
27713 +static atomic_unchecked_t ap_wfs_count;
27714
27715 static int tboot_wait_for_aps(int num_aps)
27716 {
27717 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27718 {
27719 switch (action) {
27720 case CPU_DYING:
27721 - atomic_inc(&ap_wfs_count);
27722 + atomic_inc_unchecked(&ap_wfs_count);
27723 if (num_online_cpus() == 1)
27724 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27725 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27726 return NOTIFY_BAD;
27727 break;
27728 }
27729 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27730
27731 tboot_create_trampoline();
27732
27733 - atomic_set(&ap_wfs_count, 0);
27734 + atomic_set_unchecked(&ap_wfs_count, 0);
27735 register_hotcpu_notifier(&tboot_cpu_notifier);
27736
27737 #ifdef CONFIG_DEBUG_FS
27738 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27739 index 24d3c91..d06b473 100644
27740 --- a/arch/x86/kernel/time.c
27741 +++ b/arch/x86/kernel/time.c
27742 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27743 {
27744 unsigned long pc = instruction_pointer(regs);
27745
27746 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27747 + if (!user_mode(regs) && in_lock_functions(pc)) {
27748 #ifdef CONFIG_FRAME_POINTER
27749 - return *(unsigned long *)(regs->bp + sizeof(long));
27750 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27751 #else
27752 unsigned long *sp =
27753 (unsigned long *)kernel_stack_pointer(regs);
27754 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27755 * or above a saved flags. Eflags has bits 22-31 zero,
27756 * kernel addresses don't.
27757 */
27758 +
27759 +#ifdef CONFIG_PAX_KERNEXEC
27760 + return ktla_ktva(sp[0]);
27761 +#else
27762 if (sp[0] >> 22)
27763 return sp[0];
27764 if (sp[1] >> 22)
27765 return sp[1];
27766 #endif
27767 +
27768 +#endif
27769 }
27770 return pc;
27771 }
27772 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27773 index f7fec09..9991981 100644
27774 --- a/arch/x86/kernel/tls.c
27775 +++ b/arch/x86/kernel/tls.c
27776 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27777 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27778 return -EINVAL;
27779
27780 +#ifdef CONFIG_PAX_SEGMEXEC
27781 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27782 + return -EINVAL;
27783 +#endif
27784 +
27785 set_tls_desc(p, idx, &info, 1);
27786
27787 return 0;
27788 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27789
27790 if (kbuf)
27791 info = kbuf;
27792 - else if (__copy_from_user(infobuf, ubuf, count))
27793 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27794 return -EFAULT;
27795 else
27796 info = infobuf;
27797 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27798 index 1c113db..287b42e 100644
27799 --- a/arch/x86/kernel/tracepoint.c
27800 +++ b/arch/x86/kernel/tracepoint.c
27801 @@ -9,11 +9,11 @@
27802 #include <linux/atomic.h>
27803
27804 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27805 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27806 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27807 (unsigned long) trace_idt_table };
27808
27809 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27810 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27811 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27812
27813 static int trace_irq_vector_refcount;
27814 static DEFINE_MUTEX(irq_vector_mutex);
27815 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27816 index 57409f6..e2c17e1 100644
27817 --- a/arch/x86/kernel/traps.c
27818 +++ b/arch/x86/kernel/traps.c
27819 @@ -66,7 +66,7 @@
27820 #include <asm/proto.h>
27821
27822 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27823 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27824 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27825 #else
27826 #include <asm/processor-flags.h>
27827 #include <asm/setup.h>
27828 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27829 #endif
27830
27831 /* Must be page-aligned because the real IDT is used in a fixmap. */
27832 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27833 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27834
27835 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27836 EXPORT_SYMBOL_GPL(used_vectors);
27837 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27838 }
27839
27840 static int __kprobes
27841 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27842 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27843 struct pt_regs *regs, long error_code)
27844 {
27845 #ifdef CONFIG_X86_32
27846 - if (regs->flags & X86_VM_MASK) {
27847 + if (v8086_mode(regs)) {
27848 /*
27849 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27850 * On nmi (interrupt 2), do_trap should not be called.
27851 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27852 return -1;
27853 }
27854 #endif
27855 - if (!user_mode(regs)) {
27856 + if (!user_mode_novm(regs)) {
27857 if (!fixup_exception(regs)) {
27858 tsk->thread.error_code = error_code;
27859 tsk->thread.trap_nr = trapnr;
27860 +
27861 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27862 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27863 + str = "PAX: suspicious stack segment fault";
27864 +#endif
27865 +
27866 die(str, regs, error_code);
27867 }
27868 +
27869 +#ifdef CONFIG_PAX_REFCOUNT
27870 + if (trapnr == X86_TRAP_OF)
27871 + pax_report_refcount_overflow(regs);
27872 +#endif
27873 +
27874 return 0;
27875 }
27876
27877 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27878 }
27879
27880 static void __kprobes
27881 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27882 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27883 long error_code, siginfo_t *info)
27884 {
27885 struct task_struct *tsk = current;
27886 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27887 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27888 printk_ratelimit()) {
27889 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27890 - tsk->comm, tsk->pid, str,
27891 + tsk->comm, task_pid_nr(tsk), str,
27892 regs->ip, regs->sp, error_code);
27893 print_vma_addr(" in ", regs->ip);
27894 pr_cont("\n");
27895 @@ -273,7 +285,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27896 conditional_sti(regs);
27897
27898 #ifdef CONFIG_X86_32
27899 - if (regs->flags & X86_VM_MASK) {
27900 + if (v8086_mode(regs)) {
27901 local_irq_enable();
27902 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27903 goto exit;
27904 @@ -281,18 +293,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27905 #endif
27906
27907 tsk = current;
27908 - if (!user_mode(regs)) {
27909 + if (!user_mode_novm(regs)) {
27910 if (fixup_exception(regs))
27911 goto exit;
27912
27913 tsk->thread.error_code = error_code;
27914 tsk->thread.trap_nr = X86_TRAP_GP;
27915 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27916 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27917 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27918 +
27919 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27920 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27921 + die("PAX: suspicious general protection fault", regs, error_code);
27922 + else
27923 +#endif
27924 +
27925 die("general protection fault", regs, error_code);
27926 + }
27927 goto exit;
27928 }
27929
27930 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27931 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27932 + struct mm_struct *mm = tsk->mm;
27933 + unsigned long limit;
27934 +
27935 + down_write(&mm->mmap_sem);
27936 + limit = mm->context.user_cs_limit;
27937 + if (limit < TASK_SIZE) {
27938 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27939 + up_write(&mm->mmap_sem);
27940 + return;
27941 + }
27942 + up_write(&mm->mmap_sem);
27943 + }
27944 +#endif
27945 +
27946 tsk->thread.error_code = error_code;
27947 tsk->thread.trap_nr = X86_TRAP_GP;
27948
27949 @@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27950 /* It's safe to allow irq's after DR6 has been saved */
27951 preempt_conditional_sti(regs);
27952
27953 - if (regs->flags & X86_VM_MASK) {
27954 + if (v8086_mode(regs)) {
27955 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27956 X86_TRAP_DB);
27957 preempt_conditional_cli(regs);
27958 @@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27959 * We already checked v86 mode above, so we can check for kernel mode
27960 * by just checking the CPL of CS.
27961 */
27962 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27963 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27964 tsk->thread.debugreg6 &= ~DR_STEP;
27965 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27966 regs->flags &= ~X86_EFLAGS_TF;
27967 @@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27968 return;
27969 conditional_sti(regs);
27970
27971 - if (!user_mode_vm(regs))
27972 + if (!user_mode(regs))
27973 {
27974 if (!fixup_exception(regs)) {
27975 task->thread.error_code = error_code;
27976 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27977 index cfbe99f..a6e8fa7 100644
27978 --- a/arch/x86/kernel/tsc.c
27979 +++ b/arch/x86/kernel/tsc.c
27980 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27981 */
27982 smp_wmb();
27983
27984 - ACCESS_ONCE(c2n->head) = data;
27985 + ACCESS_ONCE_RW(c2n->head) = data;
27986 }
27987
27988 /*
27989 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27990 index 2ed8459..7cf329f 100644
27991 --- a/arch/x86/kernel/uprobes.c
27992 +++ b/arch/x86/kernel/uprobes.c
27993 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27994 int ret = NOTIFY_DONE;
27995
27996 /* We are only interested in userspace traps */
27997 - if (regs && !user_mode_vm(regs))
27998 + if (regs && !user_mode(regs))
27999 return NOTIFY_DONE;
28000
28001 switch (val) {
28002 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28003
28004 if (ncopied != rasize) {
28005 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28006 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28007 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28008
28009 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28010 }
28011 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28012 index b9242ba..50c5edd 100644
28013 --- a/arch/x86/kernel/verify_cpu.S
28014 +++ b/arch/x86/kernel/verify_cpu.S
28015 @@ -20,6 +20,7 @@
28016 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28017 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28018 * arch/x86/kernel/head_32.S: processor startup
28019 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28020 *
28021 * verify_cpu, returns the status of longmode and SSE in register %eax.
28022 * 0: Success 1: Failure
28023 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28024 index e8edcf5..27f9344 100644
28025 --- a/arch/x86/kernel/vm86_32.c
28026 +++ b/arch/x86/kernel/vm86_32.c
28027 @@ -44,6 +44,7 @@
28028 #include <linux/ptrace.h>
28029 #include <linux/audit.h>
28030 #include <linux/stddef.h>
28031 +#include <linux/grsecurity.h>
28032
28033 #include <asm/uaccess.h>
28034 #include <asm/io.h>
28035 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28036 do_exit(SIGSEGV);
28037 }
28038
28039 - tss = &per_cpu(init_tss, get_cpu());
28040 + tss = init_tss + get_cpu();
28041 current->thread.sp0 = current->thread.saved_sp0;
28042 current->thread.sysenter_cs = __KERNEL_CS;
28043 load_sp0(tss, &current->thread);
28044 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28045
28046 if (tsk->thread.saved_sp0)
28047 return -EPERM;
28048 +
28049 +#ifdef CONFIG_GRKERNSEC_VM86
28050 + if (!capable(CAP_SYS_RAWIO)) {
28051 + gr_handle_vm86();
28052 + return -EPERM;
28053 + }
28054 +#endif
28055 +
28056 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28057 offsetof(struct kernel_vm86_struct, vm86plus) -
28058 sizeof(info.regs));
28059 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28060 int tmp;
28061 struct vm86plus_struct __user *v86;
28062
28063 +#ifdef CONFIG_GRKERNSEC_VM86
28064 + if (!capable(CAP_SYS_RAWIO)) {
28065 + gr_handle_vm86();
28066 + return -EPERM;
28067 + }
28068 +#endif
28069 +
28070 tsk = current;
28071 switch (cmd) {
28072 case VM86_REQUEST_IRQ:
28073 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28074 tsk->thread.saved_fs = info->regs32->fs;
28075 tsk->thread.saved_gs = get_user_gs(info->regs32);
28076
28077 - tss = &per_cpu(init_tss, get_cpu());
28078 + tss = init_tss + get_cpu();
28079 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28080 if (cpu_has_sep)
28081 tsk->thread.sysenter_cs = 0;
28082 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28083 goto cannot_handle;
28084 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28085 goto cannot_handle;
28086 - intr_ptr = (unsigned long __user *) (i << 2);
28087 + intr_ptr = (__force unsigned long __user *) (i << 2);
28088 if (get_user(segoffs, intr_ptr))
28089 goto cannot_handle;
28090 if ((segoffs >> 16) == BIOSSEG)
28091 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28092 index da6b35a..977e9cf 100644
28093 --- a/arch/x86/kernel/vmlinux.lds.S
28094 +++ b/arch/x86/kernel/vmlinux.lds.S
28095 @@ -26,6 +26,13 @@
28096 #include <asm/page_types.h>
28097 #include <asm/cache.h>
28098 #include <asm/boot.h>
28099 +#include <asm/segment.h>
28100 +
28101 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28102 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28103 +#else
28104 +#define __KERNEL_TEXT_OFFSET 0
28105 +#endif
28106
28107 #undef i386 /* in case the preprocessor is a 32bit one */
28108
28109 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28110
28111 PHDRS {
28112 text PT_LOAD FLAGS(5); /* R_E */
28113 +#ifdef CONFIG_X86_32
28114 + module PT_LOAD FLAGS(5); /* R_E */
28115 +#endif
28116 +#ifdef CONFIG_XEN
28117 + rodata PT_LOAD FLAGS(5); /* R_E */
28118 +#else
28119 + rodata PT_LOAD FLAGS(4); /* R__ */
28120 +#endif
28121 data PT_LOAD FLAGS(6); /* RW_ */
28122 -#ifdef CONFIG_X86_64
28123 + init.begin PT_LOAD FLAGS(6); /* RW_ */
28124 #ifdef CONFIG_SMP
28125 percpu PT_LOAD FLAGS(6); /* RW_ */
28126 #endif
28127 + text.init PT_LOAD FLAGS(5); /* R_E */
28128 + text.exit PT_LOAD FLAGS(5); /* R_E */
28129 init PT_LOAD FLAGS(7); /* RWE */
28130 -#endif
28131 note PT_NOTE FLAGS(0); /* ___ */
28132 }
28133
28134 SECTIONS
28135 {
28136 #ifdef CONFIG_X86_32
28137 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28138 - phys_startup_32 = startup_32 - LOAD_OFFSET;
28139 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28140 #else
28141 - . = __START_KERNEL;
28142 - phys_startup_64 = startup_64 - LOAD_OFFSET;
28143 + . = __START_KERNEL;
28144 #endif
28145
28146 /* Text and read-only data */
28147 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
28148 - _text = .;
28149 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28150 /* bootstrapping code */
28151 +#ifdef CONFIG_X86_32
28152 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28153 +#else
28154 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28155 +#endif
28156 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28157 + _text = .;
28158 HEAD_TEXT
28159 . = ALIGN(8);
28160 _stext = .;
28161 @@ -104,13 +124,47 @@ SECTIONS
28162 IRQENTRY_TEXT
28163 *(.fixup)
28164 *(.gnu.warning)
28165 - /* End of text section */
28166 - _etext = .;
28167 } :text = 0x9090
28168
28169 - NOTES :text :note
28170 + . += __KERNEL_TEXT_OFFSET;
28171
28172 - EXCEPTION_TABLE(16) :text = 0x9090
28173 +#ifdef CONFIG_X86_32
28174 + . = ALIGN(PAGE_SIZE);
28175 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28176 +
28177 +#ifdef CONFIG_PAX_KERNEXEC
28178 + MODULES_EXEC_VADDR = .;
28179 + BYTE(0)
28180 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28181 + . = ALIGN(HPAGE_SIZE) - 1;
28182 + MODULES_EXEC_END = .;
28183 +#endif
28184 +
28185 + } :module
28186 +#endif
28187 +
28188 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28189 + /* End of text section */
28190 + BYTE(0)
28191 + _etext = . - __KERNEL_TEXT_OFFSET;
28192 + }
28193 +
28194 +#ifdef CONFIG_X86_32
28195 + . = ALIGN(PAGE_SIZE);
28196 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28197 + . = ALIGN(PAGE_SIZE);
28198 + *(.empty_zero_page)
28199 + *(.initial_pg_fixmap)
28200 + *(.initial_pg_pmd)
28201 + *(.initial_page_table)
28202 + *(.swapper_pg_dir)
28203 + } :rodata
28204 +#endif
28205 +
28206 + . = ALIGN(PAGE_SIZE);
28207 + NOTES :rodata :note
28208 +
28209 + EXCEPTION_TABLE(16) :rodata
28210
28211 #if defined(CONFIG_DEBUG_RODATA)
28212 /* .text should occupy whole number of pages */
28213 @@ -122,16 +176,20 @@ SECTIONS
28214
28215 /* Data */
28216 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28217 +
28218 +#ifdef CONFIG_PAX_KERNEXEC
28219 + . = ALIGN(HPAGE_SIZE);
28220 +#else
28221 + . = ALIGN(PAGE_SIZE);
28222 +#endif
28223 +
28224 /* Start of data section */
28225 _sdata = .;
28226
28227 /* init_task */
28228 INIT_TASK_DATA(THREAD_SIZE)
28229
28230 -#ifdef CONFIG_X86_32
28231 - /* 32 bit has nosave before _edata */
28232 NOSAVE_DATA
28233 -#endif
28234
28235 PAGE_ALIGNED_DATA(PAGE_SIZE)
28236
28237 @@ -172,12 +230,19 @@ SECTIONS
28238 #endif /* CONFIG_X86_64 */
28239
28240 /* Init code and data - will be freed after init */
28241 - . = ALIGN(PAGE_SIZE);
28242 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28243 + BYTE(0)
28244 +
28245 +#ifdef CONFIG_PAX_KERNEXEC
28246 + . = ALIGN(HPAGE_SIZE);
28247 +#else
28248 + . = ALIGN(PAGE_SIZE);
28249 +#endif
28250 +
28251 __init_begin = .; /* paired with __init_end */
28252 - }
28253 + } :init.begin
28254
28255 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28256 +#ifdef CONFIG_SMP
28257 /*
28258 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28259 * output PHDR, so the next output section - .init.text - should
28260 @@ -186,12 +251,27 @@ SECTIONS
28261 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28262 #endif
28263
28264 - INIT_TEXT_SECTION(PAGE_SIZE)
28265 -#ifdef CONFIG_X86_64
28266 - :init
28267 -#endif
28268 + . = ALIGN(PAGE_SIZE);
28269 + init_begin = .;
28270 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28271 + VMLINUX_SYMBOL(_sinittext) = .;
28272 + INIT_TEXT
28273 + VMLINUX_SYMBOL(_einittext) = .;
28274 + . = ALIGN(PAGE_SIZE);
28275 + } :text.init
28276
28277 - INIT_DATA_SECTION(16)
28278 + /*
28279 + * .exit.text is discard at runtime, not link time, to deal with
28280 + * references from .altinstructions and .eh_frame
28281 + */
28282 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28283 + EXIT_TEXT
28284 + . = ALIGN(16);
28285 + } :text.exit
28286 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28287 +
28288 + . = ALIGN(PAGE_SIZE);
28289 + INIT_DATA_SECTION(16) :init
28290
28291 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28292 __x86_cpu_dev_start = .;
28293 @@ -262,19 +342,12 @@ SECTIONS
28294 }
28295
28296 . = ALIGN(8);
28297 - /*
28298 - * .exit.text is discard at runtime, not link time, to deal with
28299 - * references from .altinstructions and .eh_frame
28300 - */
28301 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28302 - EXIT_TEXT
28303 - }
28304
28305 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28306 EXIT_DATA
28307 }
28308
28309 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28310 +#ifndef CONFIG_SMP
28311 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28312 #endif
28313
28314 @@ -293,16 +366,10 @@ SECTIONS
28315 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28316 __smp_locks = .;
28317 *(.smp_locks)
28318 - . = ALIGN(PAGE_SIZE);
28319 __smp_locks_end = .;
28320 + . = ALIGN(PAGE_SIZE);
28321 }
28322
28323 -#ifdef CONFIG_X86_64
28324 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28325 - NOSAVE_DATA
28326 - }
28327 -#endif
28328 -
28329 /* BSS */
28330 . = ALIGN(PAGE_SIZE);
28331 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28332 @@ -318,6 +385,7 @@ SECTIONS
28333 __brk_base = .;
28334 . += 64 * 1024; /* 64k alignment slop space */
28335 *(.brk_reservation) /* areas brk users have reserved */
28336 + . = ALIGN(HPAGE_SIZE);
28337 __brk_limit = .;
28338 }
28339
28340 @@ -344,13 +412,12 @@ SECTIONS
28341 * for the boot processor.
28342 */
28343 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28344 -INIT_PER_CPU(gdt_page);
28345 INIT_PER_CPU(irq_stack_union);
28346
28347 /*
28348 * Build-time check on the image size:
28349 */
28350 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28351 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28352 "kernel image bigger than KERNEL_IMAGE_SIZE");
28353
28354 #ifdef CONFIG_SMP
28355 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28356 index 1f96f93..6f29be7 100644
28357 --- a/arch/x86/kernel/vsyscall_64.c
28358 +++ b/arch/x86/kernel/vsyscall_64.c
28359 @@ -56,15 +56,13 @@
28360 DEFINE_VVAR(int, vgetcpu_mode);
28361 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
28362
28363 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28364 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28365
28366 static int __init vsyscall_setup(char *str)
28367 {
28368 if (str) {
28369 if (!strcmp("emulate", str))
28370 vsyscall_mode = EMULATE;
28371 - else if (!strcmp("native", str))
28372 - vsyscall_mode = NATIVE;
28373 else if (!strcmp("none", str))
28374 vsyscall_mode = NONE;
28375 else
28376 @@ -101,7 +99,7 @@ void update_vsyscall(struct timekeeper *tk)
28377 vdata->monotonic_time_sec = tk->xtime_sec
28378 + tk->wall_to_monotonic.tv_sec;
28379 vdata->monotonic_time_snsec = tk->xtime_nsec
28380 - + (tk->wall_to_monotonic.tv_nsec
28381 + + ((u64)tk->wall_to_monotonic.tv_nsec
28382 << tk->shift);
28383 while (vdata->monotonic_time_snsec >=
28384 (((u64)NSEC_PER_SEC) << tk->shift)) {
28385 @@ -323,8 +321,7 @@ do_ret:
28386 return true;
28387
28388 sigsegv:
28389 - force_sig(SIGSEGV, current);
28390 - return true;
28391 + do_group_exit(SIGKILL);
28392 }
28393
28394 /*
28395 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
28396 extern char __vvar_page;
28397 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28398
28399 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28400 - vsyscall_mode == NATIVE
28401 - ? PAGE_KERNEL_VSYSCALL
28402 - : PAGE_KERNEL_VVAR);
28403 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28404 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28405 (unsigned long)VSYSCALL_START);
28406
28407 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28408 index 04068192..4d75aa6 100644
28409 --- a/arch/x86/kernel/x8664_ksyms_64.c
28410 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28411 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28412 EXPORT_SYMBOL(copy_user_generic_unrolled);
28413 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28414 EXPORT_SYMBOL(__copy_user_nocache);
28415 -EXPORT_SYMBOL(_copy_from_user);
28416 -EXPORT_SYMBOL(_copy_to_user);
28417
28418 EXPORT_SYMBOL(copy_page);
28419 EXPORT_SYMBOL(clear_page);
28420 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28421 EXPORT_SYMBOL(___preempt_schedule_context);
28422 #endif
28423 #endif
28424 +
28425 +#ifdef CONFIG_PAX_PER_CPU_PGD
28426 +EXPORT_SYMBOL(cpu_pgd);
28427 +#endif
28428 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28429 index e48b674..a451dd9 100644
28430 --- a/arch/x86/kernel/x86_init.c
28431 +++ b/arch/x86/kernel/x86_init.c
28432 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28433 static void default_nmi_init(void) { };
28434 static int default_i8042_detect(void) { return 1; };
28435
28436 -struct x86_platform_ops x86_platform = {
28437 +struct x86_platform_ops x86_platform __read_only = {
28438 .calibrate_tsc = native_calibrate_tsc,
28439 .get_wallclock = mach_get_cmos_time,
28440 .set_wallclock = mach_set_rtc_mmss,
28441 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28442 EXPORT_SYMBOL_GPL(x86_platform);
28443
28444 #if defined(CONFIG_PCI_MSI)
28445 -struct x86_msi_ops x86_msi = {
28446 +struct x86_msi_ops x86_msi __read_only = {
28447 .setup_msi_irqs = native_setup_msi_irqs,
28448 .compose_msi_msg = native_compose_msi_msg,
28449 .teardown_msi_irq = native_teardown_msi_irq,
28450 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28451 }
28452 #endif
28453
28454 -struct x86_io_apic_ops x86_io_apic_ops = {
28455 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28456 .init = native_io_apic_init_mappings,
28457 .read = native_io_apic_read,
28458 .write = native_io_apic_write,
28459 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28460 index a4b451c..8dfe1ad 100644
28461 --- a/arch/x86/kernel/xsave.c
28462 +++ b/arch/x86/kernel/xsave.c
28463 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28464
28465 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28466 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28467 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28468 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28469
28470 if (!use_xsave())
28471 return err;
28472
28473 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28474 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28475
28476 /*
28477 * Read the xstate_bv which we copied (directly from the cpu or
28478 * from the state in task struct) to the user buffers.
28479 */
28480 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28481 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28482
28483 /*
28484 * For legacy compatible, we always set FP/SSE bits in the bit
28485 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28486 */
28487 xstate_bv |= XSTATE_FPSSE;
28488
28489 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28490 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28491
28492 return err;
28493 }
28494 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28495 {
28496 int err;
28497
28498 + buf = (struct xsave_struct __user *)____m(buf);
28499 if (use_xsave())
28500 err = xsave_user(buf);
28501 else if (use_fxsr())
28502 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28503 */
28504 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28505 {
28506 + buf = (void __user *)____m(buf);
28507 if (use_xsave()) {
28508 if ((unsigned long)buf % 64 || fx_only) {
28509 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28510 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28511 index c697625..a032162 100644
28512 --- a/arch/x86/kvm/cpuid.c
28513 +++ b/arch/x86/kvm/cpuid.c
28514 @@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28515 struct kvm_cpuid2 *cpuid,
28516 struct kvm_cpuid_entry2 __user *entries)
28517 {
28518 - int r;
28519 + int r, i;
28520
28521 r = -E2BIG;
28522 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28523 goto out;
28524 r = -EFAULT;
28525 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28526 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28527 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28528 goto out;
28529 + for (i = 0; i < cpuid->nent; ++i) {
28530 + struct kvm_cpuid_entry2 cpuid_entry;
28531 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28532 + goto out;
28533 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28534 + }
28535 vcpu->arch.cpuid_nent = cpuid->nent;
28536 kvm_apic_set_version(vcpu);
28537 kvm_x86_ops->cpuid_update(vcpu);
28538 @@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28539 struct kvm_cpuid2 *cpuid,
28540 struct kvm_cpuid_entry2 __user *entries)
28541 {
28542 - int r;
28543 + int r, i;
28544
28545 r = -E2BIG;
28546 if (cpuid->nent < vcpu->arch.cpuid_nent)
28547 goto out;
28548 r = -EFAULT;
28549 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28550 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28551 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28552 goto out;
28553 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28554 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28555 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28556 + goto out;
28557 + }
28558 return 0;
28559
28560 out:
28561 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28562 index 9736529..ab4f54c 100644
28563 --- a/arch/x86/kvm/lapic.c
28564 +++ b/arch/x86/kvm/lapic.c
28565 @@ -55,7 +55,7 @@
28566 #define APIC_BUS_CYCLE_NS 1
28567
28568 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28569 -#define apic_debug(fmt, arg...)
28570 +#define apic_debug(fmt, arg...) do {} while (0)
28571
28572 #define APIC_LVT_NUM 6
28573 /* 14 is the version for Xeon and Pentium 8.4.8*/
28574 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28575 index cba218a..1cc1bed 100644
28576 --- a/arch/x86/kvm/paging_tmpl.h
28577 +++ b/arch/x86/kvm/paging_tmpl.h
28578 @@ -331,7 +331,7 @@ retry_walk:
28579 if (unlikely(kvm_is_error_hva(host_addr)))
28580 goto error;
28581
28582 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28583 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28584 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28585 goto error;
28586 walker->ptep_user[walker->level - 1] = ptep_user;
28587 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28588 index 2de1bc0..22251ee 100644
28589 --- a/arch/x86/kvm/svm.c
28590 +++ b/arch/x86/kvm/svm.c
28591 @@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28592 int cpu = raw_smp_processor_id();
28593
28594 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28595 +
28596 + pax_open_kernel();
28597 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28598 + pax_close_kernel();
28599 +
28600 load_TR_desc();
28601 }
28602
28603 @@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28604 #endif
28605 #endif
28606
28607 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28608 + __set_fs(current_thread_info()->addr_limit);
28609 +#endif
28610 +
28611 reload_tss(vcpu);
28612
28613 local_irq_disable();
28614 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28615 index 3927528..fc19971 100644
28616 --- a/arch/x86/kvm/vmx.c
28617 +++ b/arch/x86/kvm/vmx.c
28618 @@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28619 #endif
28620 }
28621
28622 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28623 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28624 {
28625 vmcs_writel(field, vmcs_readl(field) & ~mask);
28626 }
28627
28628 -static void vmcs_set_bits(unsigned long field, u32 mask)
28629 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28630 {
28631 vmcs_writel(field, vmcs_readl(field) | mask);
28632 }
28633 @@ -1585,7 +1585,11 @@ static void reload_tss(void)
28634 struct desc_struct *descs;
28635
28636 descs = (void *)gdt->address;
28637 +
28638 + pax_open_kernel();
28639 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28640 + pax_close_kernel();
28641 +
28642 load_TR_desc();
28643 }
28644
28645 @@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28646 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28647 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28648
28649 +#ifdef CONFIG_PAX_PER_CPU_PGD
28650 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28651 +#endif
28652 +
28653 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28654 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28655 vmx->loaded_vmcs->cpu = cpu;
28656 @@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28657 * reads and returns guest's timestamp counter "register"
28658 * guest_tsc = host_tsc + tsc_offset -- 21.3
28659 */
28660 -static u64 guest_read_tsc(void)
28661 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28662 {
28663 u64 host_tsc, tsc_offset;
28664
28665 @@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28666 if (!cpu_has_vmx_flexpriority())
28667 flexpriority_enabled = 0;
28668
28669 - if (!cpu_has_vmx_tpr_shadow())
28670 - kvm_x86_ops->update_cr8_intercept = NULL;
28671 + if (!cpu_has_vmx_tpr_shadow()) {
28672 + pax_open_kernel();
28673 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28674 + pax_close_kernel();
28675 + }
28676
28677 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28678 kvm_disable_largepages();
28679 @@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28680 if (!cpu_has_vmx_apicv())
28681 enable_apicv = 0;
28682
28683 + pax_open_kernel();
28684 if (enable_apicv)
28685 - kvm_x86_ops->update_cr8_intercept = NULL;
28686 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28687 else {
28688 - kvm_x86_ops->hwapic_irr_update = NULL;
28689 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28690 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28691 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28692 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28693 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28694 }
28695 + pax_close_kernel();
28696
28697 if (nested)
28698 nested_vmx_setup_ctls_msrs();
28699 @@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28700
28701 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28702 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28703 +
28704 +#ifndef CONFIG_PAX_PER_CPU_PGD
28705 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28706 +#endif
28707
28708 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28709 #ifdef CONFIG_X86_64
28710 @@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28711 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28712 vmx->host_idt_base = dt.address;
28713
28714 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28715 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28716
28717 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28718 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28719 @@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28720 "jmp 2f \n\t"
28721 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28722 "2: "
28723 +
28724 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28725 + "ljmp %[cs],$3f\n\t"
28726 + "3: "
28727 +#endif
28728 +
28729 /* Save guest registers, load host registers, keep flags */
28730 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28731 "pop %0 \n\t"
28732 @@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28733 #endif
28734 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28735 [wordsize]"i"(sizeof(ulong))
28736 +
28737 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28738 + ,[cs]"i"(__KERNEL_CS)
28739 +#endif
28740 +
28741 : "cc", "memory"
28742 #ifdef CONFIG_X86_64
28743 , "rax", "rbx", "rdi", "rsi"
28744 @@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28745 if (debugctlmsr)
28746 update_debugctlmsr(debugctlmsr);
28747
28748 -#ifndef CONFIG_X86_64
28749 +#ifdef CONFIG_X86_32
28750 /*
28751 * The sysexit path does not restore ds/es, so we must set them to
28752 * a reasonable value ourselves.
28753 @@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28754 * may be executed in interrupt context, which saves and restore segments
28755 * around it, nullifying its effect.
28756 */
28757 - loadsegment(ds, __USER_DS);
28758 - loadsegment(es, __USER_DS);
28759 + loadsegment(ds, __KERNEL_DS);
28760 + loadsegment(es, __KERNEL_DS);
28761 + loadsegment(ss, __KERNEL_DS);
28762 +
28763 +#ifdef CONFIG_PAX_KERNEXEC
28764 + loadsegment(fs, __KERNEL_PERCPU);
28765 +#endif
28766 +
28767 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28768 + __set_fs(current_thread_info()->addr_limit);
28769 +#endif
28770 +
28771 #endif
28772
28773 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28774 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28775 index 2b85784..ad70e19 100644
28776 --- a/arch/x86/kvm/x86.c
28777 +++ b/arch/x86/kvm/x86.c
28778 @@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28779 {
28780 struct kvm *kvm = vcpu->kvm;
28781 int lm = is_long_mode(vcpu);
28782 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28783 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28784 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28785 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28786 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28787 : kvm->arch.xen_hvm_config.blob_size_32;
28788 u32 page_num = data & ~PAGE_MASK;
28789 @@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28790 if (n < msr_list.nmsrs)
28791 goto out;
28792 r = -EFAULT;
28793 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28794 + goto out;
28795 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28796 num_msrs_to_save * sizeof(u32)))
28797 goto out;
28798 @@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28799 };
28800 #endif
28801
28802 -int kvm_arch_init(void *opaque)
28803 +int kvm_arch_init(const void *opaque)
28804 {
28805 int r;
28806 struct kvm_x86_ops *ops = opaque;
28807 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28808 index ad1fb5f..fe30b66 100644
28809 --- a/arch/x86/lguest/boot.c
28810 +++ b/arch/x86/lguest/boot.c
28811 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28812 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28813 * Launcher to reboot us.
28814 */
28815 -static void lguest_restart(char *reason)
28816 +static __noreturn void lguest_restart(char *reason)
28817 {
28818 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28819 + BUG();
28820 }
28821
28822 /*G:050
28823 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28824 index 00933d5..3a64af9 100644
28825 --- a/arch/x86/lib/atomic64_386_32.S
28826 +++ b/arch/x86/lib/atomic64_386_32.S
28827 @@ -48,6 +48,10 @@ BEGIN(read)
28828 movl (v), %eax
28829 movl 4(v), %edx
28830 RET_ENDP
28831 +BEGIN(read_unchecked)
28832 + movl (v), %eax
28833 + movl 4(v), %edx
28834 +RET_ENDP
28835 #undef v
28836
28837 #define v %esi
28838 @@ -55,6 +59,10 @@ BEGIN(set)
28839 movl %ebx, (v)
28840 movl %ecx, 4(v)
28841 RET_ENDP
28842 +BEGIN(set_unchecked)
28843 + movl %ebx, (v)
28844 + movl %ecx, 4(v)
28845 +RET_ENDP
28846 #undef v
28847
28848 #define v %esi
28849 @@ -70,6 +78,20 @@ RET_ENDP
28850 BEGIN(add)
28851 addl %eax, (v)
28852 adcl %edx, 4(v)
28853 +
28854 +#ifdef CONFIG_PAX_REFCOUNT
28855 + jno 0f
28856 + subl %eax, (v)
28857 + sbbl %edx, 4(v)
28858 + int $4
28859 +0:
28860 + _ASM_EXTABLE(0b, 0b)
28861 +#endif
28862 +
28863 +RET_ENDP
28864 +BEGIN(add_unchecked)
28865 + addl %eax, (v)
28866 + adcl %edx, 4(v)
28867 RET_ENDP
28868 #undef v
28869
28870 @@ -77,6 +99,24 @@ RET_ENDP
28871 BEGIN(add_return)
28872 addl (v), %eax
28873 adcl 4(v), %edx
28874 +
28875 +#ifdef CONFIG_PAX_REFCOUNT
28876 + into
28877 +1234:
28878 + _ASM_EXTABLE(1234b, 2f)
28879 +#endif
28880 +
28881 + movl %eax, (v)
28882 + movl %edx, 4(v)
28883 +
28884 +#ifdef CONFIG_PAX_REFCOUNT
28885 +2:
28886 +#endif
28887 +
28888 +RET_ENDP
28889 +BEGIN(add_return_unchecked)
28890 + addl (v), %eax
28891 + adcl 4(v), %edx
28892 movl %eax, (v)
28893 movl %edx, 4(v)
28894 RET_ENDP
28895 @@ -86,6 +126,20 @@ RET_ENDP
28896 BEGIN(sub)
28897 subl %eax, (v)
28898 sbbl %edx, 4(v)
28899 +
28900 +#ifdef CONFIG_PAX_REFCOUNT
28901 + jno 0f
28902 + addl %eax, (v)
28903 + adcl %edx, 4(v)
28904 + int $4
28905 +0:
28906 + _ASM_EXTABLE(0b, 0b)
28907 +#endif
28908 +
28909 +RET_ENDP
28910 +BEGIN(sub_unchecked)
28911 + subl %eax, (v)
28912 + sbbl %edx, 4(v)
28913 RET_ENDP
28914 #undef v
28915
28916 @@ -96,6 +150,27 @@ BEGIN(sub_return)
28917 sbbl $0, %edx
28918 addl (v), %eax
28919 adcl 4(v), %edx
28920 +
28921 +#ifdef CONFIG_PAX_REFCOUNT
28922 + into
28923 +1234:
28924 + _ASM_EXTABLE(1234b, 2f)
28925 +#endif
28926 +
28927 + movl %eax, (v)
28928 + movl %edx, 4(v)
28929 +
28930 +#ifdef CONFIG_PAX_REFCOUNT
28931 +2:
28932 +#endif
28933 +
28934 +RET_ENDP
28935 +BEGIN(sub_return_unchecked)
28936 + negl %edx
28937 + negl %eax
28938 + sbbl $0, %edx
28939 + addl (v), %eax
28940 + adcl 4(v), %edx
28941 movl %eax, (v)
28942 movl %edx, 4(v)
28943 RET_ENDP
28944 @@ -105,6 +180,20 @@ RET_ENDP
28945 BEGIN(inc)
28946 addl $1, (v)
28947 adcl $0, 4(v)
28948 +
28949 +#ifdef CONFIG_PAX_REFCOUNT
28950 + jno 0f
28951 + subl $1, (v)
28952 + sbbl $0, 4(v)
28953 + int $4
28954 +0:
28955 + _ASM_EXTABLE(0b, 0b)
28956 +#endif
28957 +
28958 +RET_ENDP
28959 +BEGIN(inc_unchecked)
28960 + addl $1, (v)
28961 + adcl $0, 4(v)
28962 RET_ENDP
28963 #undef v
28964
28965 @@ -114,6 +203,26 @@ BEGIN(inc_return)
28966 movl 4(v), %edx
28967 addl $1, %eax
28968 adcl $0, %edx
28969 +
28970 +#ifdef CONFIG_PAX_REFCOUNT
28971 + into
28972 +1234:
28973 + _ASM_EXTABLE(1234b, 2f)
28974 +#endif
28975 +
28976 + movl %eax, (v)
28977 + movl %edx, 4(v)
28978 +
28979 +#ifdef CONFIG_PAX_REFCOUNT
28980 +2:
28981 +#endif
28982 +
28983 +RET_ENDP
28984 +BEGIN(inc_return_unchecked)
28985 + movl (v), %eax
28986 + movl 4(v), %edx
28987 + addl $1, %eax
28988 + adcl $0, %edx
28989 movl %eax, (v)
28990 movl %edx, 4(v)
28991 RET_ENDP
28992 @@ -123,6 +232,20 @@ RET_ENDP
28993 BEGIN(dec)
28994 subl $1, (v)
28995 sbbl $0, 4(v)
28996 +
28997 +#ifdef CONFIG_PAX_REFCOUNT
28998 + jno 0f
28999 + addl $1, (v)
29000 + adcl $0, 4(v)
29001 + int $4
29002 +0:
29003 + _ASM_EXTABLE(0b, 0b)
29004 +#endif
29005 +
29006 +RET_ENDP
29007 +BEGIN(dec_unchecked)
29008 + subl $1, (v)
29009 + sbbl $0, 4(v)
29010 RET_ENDP
29011 #undef v
29012
29013 @@ -132,6 +255,26 @@ BEGIN(dec_return)
29014 movl 4(v), %edx
29015 subl $1, %eax
29016 sbbl $0, %edx
29017 +
29018 +#ifdef CONFIG_PAX_REFCOUNT
29019 + into
29020 +1234:
29021 + _ASM_EXTABLE(1234b, 2f)
29022 +#endif
29023 +
29024 + movl %eax, (v)
29025 + movl %edx, 4(v)
29026 +
29027 +#ifdef CONFIG_PAX_REFCOUNT
29028 +2:
29029 +#endif
29030 +
29031 +RET_ENDP
29032 +BEGIN(dec_return_unchecked)
29033 + movl (v), %eax
29034 + movl 4(v), %edx
29035 + subl $1, %eax
29036 + sbbl $0, %edx
29037 movl %eax, (v)
29038 movl %edx, 4(v)
29039 RET_ENDP
29040 @@ -143,6 +286,13 @@ BEGIN(add_unless)
29041 adcl %edx, %edi
29042 addl (v), %eax
29043 adcl 4(v), %edx
29044 +
29045 +#ifdef CONFIG_PAX_REFCOUNT
29046 + into
29047 +1234:
29048 + _ASM_EXTABLE(1234b, 2f)
29049 +#endif
29050 +
29051 cmpl %eax, %ecx
29052 je 3f
29053 1:
29054 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29055 1:
29056 addl $1, %eax
29057 adcl $0, %edx
29058 +
29059 +#ifdef CONFIG_PAX_REFCOUNT
29060 + into
29061 +1234:
29062 + _ASM_EXTABLE(1234b, 2f)
29063 +#endif
29064 +
29065 movl %eax, (v)
29066 movl %edx, 4(v)
29067 movl $1, %eax
29068 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29069 movl 4(v), %edx
29070 subl $1, %eax
29071 sbbl $0, %edx
29072 +
29073 +#ifdef CONFIG_PAX_REFCOUNT
29074 + into
29075 +1234:
29076 + _ASM_EXTABLE(1234b, 1f)
29077 +#endif
29078 +
29079 js 1f
29080 movl %eax, (v)
29081 movl %edx, 4(v)
29082 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29083 index f5cc9eb..51fa319 100644
29084 --- a/arch/x86/lib/atomic64_cx8_32.S
29085 +++ b/arch/x86/lib/atomic64_cx8_32.S
29086 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29087 CFI_STARTPROC
29088
29089 read64 %ecx
29090 + pax_force_retaddr
29091 ret
29092 CFI_ENDPROC
29093 ENDPROC(atomic64_read_cx8)
29094
29095 +ENTRY(atomic64_read_unchecked_cx8)
29096 + CFI_STARTPROC
29097 +
29098 + read64 %ecx
29099 + pax_force_retaddr
29100 + ret
29101 + CFI_ENDPROC
29102 +ENDPROC(atomic64_read_unchecked_cx8)
29103 +
29104 ENTRY(atomic64_set_cx8)
29105 CFI_STARTPROC
29106
29107 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29108 cmpxchg8b (%esi)
29109 jne 1b
29110
29111 + pax_force_retaddr
29112 ret
29113 CFI_ENDPROC
29114 ENDPROC(atomic64_set_cx8)
29115
29116 +ENTRY(atomic64_set_unchecked_cx8)
29117 + CFI_STARTPROC
29118 +
29119 +1:
29120 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
29121 + * are atomic on 586 and newer */
29122 + cmpxchg8b (%esi)
29123 + jne 1b
29124 +
29125 + pax_force_retaddr
29126 + ret
29127 + CFI_ENDPROC
29128 +ENDPROC(atomic64_set_unchecked_cx8)
29129 +
29130 ENTRY(atomic64_xchg_cx8)
29131 CFI_STARTPROC
29132
29133 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29134 cmpxchg8b (%esi)
29135 jne 1b
29136
29137 + pax_force_retaddr
29138 ret
29139 CFI_ENDPROC
29140 ENDPROC(atomic64_xchg_cx8)
29141
29142 -.macro addsub_return func ins insc
29143 -ENTRY(atomic64_\func\()_return_cx8)
29144 +.macro addsub_return func ins insc unchecked=""
29145 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29146 CFI_STARTPROC
29147 SAVE ebp
29148 SAVE ebx
29149 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29150 movl %edx, %ecx
29151 \ins\()l %esi, %ebx
29152 \insc\()l %edi, %ecx
29153 +
29154 +.ifb \unchecked
29155 +#ifdef CONFIG_PAX_REFCOUNT
29156 + into
29157 +2:
29158 + _ASM_EXTABLE(2b, 3f)
29159 +#endif
29160 +.endif
29161 +
29162 LOCK_PREFIX
29163 cmpxchg8b (%ebp)
29164 jne 1b
29165 -
29166 -10:
29167 movl %ebx, %eax
29168 movl %ecx, %edx
29169 +
29170 +.ifb \unchecked
29171 +#ifdef CONFIG_PAX_REFCOUNT
29172 +3:
29173 +#endif
29174 +.endif
29175 +
29176 RESTORE edi
29177 RESTORE esi
29178 RESTORE ebx
29179 RESTORE ebp
29180 + pax_force_retaddr
29181 ret
29182 CFI_ENDPROC
29183 -ENDPROC(atomic64_\func\()_return_cx8)
29184 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29185 .endm
29186
29187 addsub_return add add adc
29188 addsub_return sub sub sbb
29189 +addsub_return add add adc _unchecked
29190 +addsub_return sub sub sbb _unchecked
29191
29192 -.macro incdec_return func ins insc
29193 -ENTRY(atomic64_\func\()_return_cx8)
29194 +.macro incdec_return func ins insc unchecked=""
29195 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29196 CFI_STARTPROC
29197 SAVE ebx
29198
29199 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29200 movl %edx, %ecx
29201 \ins\()l $1, %ebx
29202 \insc\()l $0, %ecx
29203 +
29204 +.ifb \unchecked
29205 +#ifdef CONFIG_PAX_REFCOUNT
29206 + into
29207 +2:
29208 + _ASM_EXTABLE(2b, 3f)
29209 +#endif
29210 +.endif
29211 +
29212 LOCK_PREFIX
29213 cmpxchg8b (%esi)
29214 jne 1b
29215
29216 -10:
29217 movl %ebx, %eax
29218 movl %ecx, %edx
29219 +
29220 +.ifb \unchecked
29221 +#ifdef CONFIG_PAX_REFCOUNT
29222 +3:
29223 +#endif
29224 +.endif
29225 +
29226 RESTORE ebx
29227 + pax_force_retaddr
29228 ret
29229 CFI_ENDPROC
29230 -ENDPROC(atomic64_\func\()_return_cx8)
29231 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29232 .endm
29233
29234 incdec_return inc add adc
29235 incdec_return dec sub sbb
29236 +incdec_return inc add adc _unchecked
29237 +incdec_return dec sub sbb _unchecked
29238
29239 ENTRY(atomic64_dec_if_positive_cx8)
29240 CFI_STARTPROC
29241 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29242 movl %edx, %ecx
29243 subl $1, %ebx
29244 sbb $0, %ecx
29245 +
29246 +#ifdef CONFIG_PAX_REFCOUNT
29247 + into
29248 +1234:
29249 + _ASM_EXTABLE(1234b, 2f)
29250 +#endif
29251 +
29252 js 2f
29253 LOCK_PREFIX
29254 cmpxchg8b (%esi)
29255 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29256 movl %ebx, %eax
29257 movl %ecx, %edx
29258 RESTORE ebx
29259 + pax_force_retaddr
29260 ret
29261 CFI_ENDPROC
29262 ENDPROC(atomic64_dec_if_positive_cx8)
29263 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29264 movl %edx, %ecx
29265 addl %ebp, %ebx
29266 adcl %edi, %ecx
29267 +
29268 +#ifdef CONFIG_PAX_REFCOUNT
29269 + into
29270 +1234:
29271 + _ASM_EXTABLE(1234b, 3f)
29272 +#endif
29273 +
29274 LOCK_PREFIX
29275 cmpxchg8b (%esi)
29276 jne 1b
29277 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29278 CFI_ADJUST_CFA_OFFSET -8
29279 RESTORE ebx
29280 RESTORE ebp
29281 + pax_force_retaddr
29282 ret
29283 4:
29284 cmpl %edx, 4(%esp)
29285 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29286 xorl %ecx, %ecx
29287 addl $1, %ebx
29288 adcl %edx, %ecx
29289 +
29290 +#ifdef CONFIG_PAX_REFCOUNT
29291 + into
29292 +1234:
29293 + _ASM_EXTABLE(1234b, 3f)
29294 +#endif
29295 +
29296 LOCK_PREFIX
29297 cmpxchg8b (%esi)
29298 jne 1b
29299 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29300 movl $1, %eax
29301 3:
29302 RESTORE ebx
29303 + pax_force_retaddr
29304 ret
29305 CFI_ENDPROC
29306 ENDPROC(atomic64_inc_not_zero_cx8)
29307 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29308 index e78b8ee..7e173a8 100644
29309 --- a/arch/x86/lib/checksum_32.S
29310 +++ b/arch/x86/lib/checksum_32.S
29311 @@ -29,7 +29,8 @@
29312 #include <asm/dwarf2.h>
29313 #include <asm/errno.h>
29314 #include <asm/asm.h>
29315 -
29316 +#include <asm/segment.h>
29317 +
29318 /*
29319 * computes a partial checksum, e.g. for TCP/UDP fragments
29320 */
29321 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29322
29323 #define ARGBASE 16
29324 #define FP 12
29325 -
29326 -ENTRY(csum_partial_copy_generic)
29327 +
29328 +ENTRY(csum_partial_copy_generic_to_user)
29329 CFI_STARTPROC
29330 +
29331 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29332 + pushl_cfi %gs
29333 + popl_cfi %es
29334 + jmp csum_partial_copy_generic
29335 +#endif
29336 +
29337 +ENTRY(csum_partial_copy_generic_from_user)
29338 +
29339 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29340 + pushl_cfi %gs
29341 + popl_cfi %ds
29342 +#endif
29343 +
29344 +ENTRY(csum_partial_copy_generic)
29345 subl $4,%esp
29346 CFI_ADJUST_CFA_OFFSET 4
29347 pushl_cfi %edi
29348 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29349 jmp 4f
29350 SRC(1: movw (%esi), %bx )
29351 addl $2, %esi
29352 -DST( movw %bx, (%edi) )
29353 +DST( movw %bx, %es:(%edi) )
29354 addl $2, %edi
29355 addw %bx, %ax
29356 adcl $0, %eax
29357 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29358 SRC(1: movl (%esi), %ebx )
29359 SRC( movl 4(%esi), %edx )
29360 adcl %ebx, %eax
29361 -DST( movl %ebx, (%edi) )
29362 +DST( movl %ebx, %es:(%edi) )
29363 adcl %edx, %eax
29364 -DST( movl %edx, 4(%edi) )
29365 +DST( movl %edx, %es:4(%edi) )
29366
29367 SRC( movl 8(%esi), %ebx )
29368 SRC( movl 12(%esi), %edx )
29369 adcl %ebx, %eax
29370 -DST( movl %ebx, 8(%edi) )
29371 +DST( movl %ebx, %es:8(%edi) )
29372 adcl %edx, %eax
29373 -DST( movl %edx, 12(%edi) )
29374 +DST( movl %edx, %es:12(%edi) )
29375
29376 SRC( movl 16(%esi), %ebx )
29377 SRC( movl 20(%esi), %edx )
29378 adcl %ebx, %eax
29379 -DST( movl %ebx, 16(%edi) )
29380 +DST( movl %ebx, %es:16(%edi) )
29381 adcl %edx, %eax
29382 -DST( movl %edx, 20(%edi) )
29383 +DST( movl %edx, %es:20(%edi) )
29384
29385 SRC( movl 24(%esi), %ebx )
29386 SRC( movl 28(%esi), %edx )
29387 adcl %ebx, %eax
29388 -DST( movl %ebx, 24(%edi) )
29389 +DST( movl %ebx, %es:24(%edi) )
29390 adcl %edx, %eax
29391 -DST( movl %edx, 28(%edi) )
29392 +DST( movl %edx, %es:28(%edi) )
29393
29394 lea 32(%esi), %esi
29395 lea 32(%edi), %edi
29396 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29397 shrl $2, %edx # This clears CF
29398 SRC(3: movl (%esi), %ebx )
29399 adcl %ebx, %eax
29400 -DST( movl %ebx, (%edi) )
29401 +DST( movl %ebx, %es:(%edi) )
29402 lea 4(%esi), %esi
29403 lea 4(%edi), %edi
29404 dec %edx
29405 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29406 jb 5f
29407 SRC( movw (%esi), %cx )
29408 leal 2(%esi), %esi
29409 -DST( movw %cx, (%edi) )
29410 +DST( movw %cx, %es:(%edi) )
29411 leal 2(%edi), %edi
29412 je 6f
29413 shll $16,%ecx
29414 SRC(5: movb (%esi), %cl )
29415 -DST( movb %cl, (%edi) )
29416 +DST( movb %cl, %es:(%edi) )
29417 6: addl %ecx, %eax
29418 adcl $0, %eax
29419 7:
29420 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29421
29422 6001:
29423 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29424 - movl $-EFAULT, (%ebx)
29425 + movl $-EFAULT, %ss:(%ebx)
29426
29427 # zero the complete destination - computing the rest
29428 # is too much work
29429 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29430
29431 6002:
29432 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29433 - movl $-EFAULT,(%ebx)
29434 + movl $-EFAULT,%ss:(%ebx)
29435 jmp 5000b
29436
29437 .previous
29438
29439 + pushl_cfi %ss
29440 + popl_cfi %ds
29441 + pushl_cfi %ss
29442 + popl_cfi %es
29443 popl_cfi %ebx
29444 CFI_RESTORE ebx
29445 popl_cfi %esi
29446 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29447 popl_cfi %ecx # equivalent to addl $4,%esp
29448 ret
29449 CFI_ENDPROC
29450 -ENDPROC(csum_partial_copy_generic)
29451 +ENDPROC(csum_partial_copy_generic_to_user)
29452
29453 #else
29454
29455 /* Version for PentiumII/PPro */
29456
29457 #define ROUND1(x) \
29458 + nop; nop; nop; \
29459 SRC(movl x(%esi), %ebx ) ; \
29460 addl %ebx, %eax ; \
29461 - DST(movl %ebx, x(%edi) ) ;
29462 + DST(movl %ebx, %es:x(%edi)) ;
29463
29464 #define ROUND(x) \
29465 + nop; nop; nop; \
29466 SRC(movl x(%esi), %ebx ) ; \
29467 adcl %ebx, %eax ; \
29468 - DST(movl %ebx, x(%edi) ) ;
29469 + DST(movl %ebx, %es:x(%edi)) ;
29470
29471 #define ARGBASE 12
29472 -
29473 -ENTRY(csum_partial_copy_generic)
29474 +
29475 +ENTRY(csum_partial_copy_generic_to_user)
29476 CFI_STARTPROC
29477 +
29478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29479 + pushl_cfi %gs
29480 + popl_cfi %es
29481 + jmp csum_partial_copy_generic
29482 +#endif
29483 +
29484 +ENTRY(csum_partial_copy_generic_from_user)
29485 +
29486 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29487 + pushl_cfi %gs
29488 + popl_cfi %ds
29489 +#endif
29490 +
29491 +ENTRY(csum_partial_copy_generic)
29492 pushl_cfi %ebx
29493 CFI_REL_OFFSET ebx, 0
29494 pushl_cfi %edi
29495 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29496 subl %ebx, %edi
29497 lea -1(%esi),%edx
29498 andl $-32,%edx
29499 - lea 3f(%ebx,%ebx), %ebx
29500 + lea 3f(%ebx,%ebx,2), %ebx
29501 testl %esi, %esi
29502 jmp *%ebx
29503 1: addl $64,%esi
29504 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29505 jb 5f
29506 SRC( movw (%esi), %dx )
29507 leal 2(%esi), %esi
29508 -DST( movw %dx, (%edi) )
29509 +DST( movw %dx, %es:(%edi) )
29510 leal 2(%edi), %edi
29511 je 6f
29512 shll $16,%edx
29513 5:
29514 SRC( movb (%esi), %dl )
29515 -DST( movb %dl, (%edi) )
29516 +DST( movb %dl, %es:(%edi) )
29517 6: addl %edx, %eax
29518 adcl $0, %eax
29519 7:
29520 .section .fixup, "ax"
29521 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29522 - movl $-EFAULT, (%ebx)
29523 + movl $-EFAULT, %ss:(%ebx)
29524 # zero the complete destination (computing the rest is too much work)
29525 movl ARGBASE+8(%esp),%edi # dst
29526 movl ARGBASE+12(%esp),%ecx # len
29527 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29528 rep; stosb
29529 jmp 7b
29530 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29531 - movl $-EFAULT, (%ebx)
29532 + movl $-EFAULT, %ss:(%ebx)
29533 jmp 7b
29534 .previous
29535
29536 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29537 + pushl_cfi %ss
29538 + popl_cfi %ds
29539 + pushl_cfi %ss
29540 + popl_cfi %es
29541 +#endif
29542 +
29543 popl_cfi %esi
29544 CFI_RESTORE esi
29545 popl_cfi %edi
29546 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29547 CFI_RESTORE ebx
29548 ret
29549 CFI_ENDPROC
29550 -ENDPROC(csum_partial_copy_generic)
29551 +ENDPROC(csum_partial_copy_generic_to_user)
29552
29553 #undef ROUND
29554 #undef ROUND1
29555 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29556 index f2145cf..cea889d 100644
29557 --- a/arch/x86/lib/clear_page_64.S
29558 +++ b/arch/x86/lib/clear_page_64.S
29559 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29560 movl $4096/8,%ecx
29561 xorl %eax,%eax
29562 rep stosq
29563 + pax_force_retaddr
29564 ret
29565 CFI_ENDPROC
29566 ENDPROC(clear_page_c)
29567 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29568 movl $4096,%ecx
29569 xorl %eax,%eax
29570 rep stosb
29571 + pax_force_retaddr
29572 ret
29573 CFI_ENDPROC
29574 ENDPROC(clear_page_c_e)
29575 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29576 leaq 64(%rdi),%rdi
29577 jnz .Lloop
29578 nop
29579 + pax_force_retaddr
29580 ret
29581 CFI_ENDPROC
29582 .Lclear_page_end:
29583 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29584
29585 #include <asm/cpufeature.h>
29586
29587 - .section .altinstr_replacement,"ax"
29588 + .section .altinstr_replacement,"a"
29589 1: .byte 0xeb /* jmp <disp8> */
29590 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29591 2: .byte 0xeb /* jmp <disp8> */
29592 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29593 index 1e572c5..2a162cd 100644
29594 --- a/arch/x86/lib/cmpxchg16b_emu.S
29595 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29596 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29597
29598 popf
29599 mov $1, %al
29600 + pax_force_retaddr
29601 ret
29602
29603 not_same:
29604 popf
29605 xor %al,%al
29606 + pax_force_retaddr
29607 ret
29608
29609 CFI_ENDPROC
29610 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29611 index 176cca6..e0d658e 100644
29612 --- a/arch/x86/lib/copy_page_64.S
29613 +++ b/arch/x86/lib/copy_page_64.S
29614 @@ -9,6 +9,7 @@ copy_page_rep:
29615 CFI_STARTPROC
29616 movl $4096/8, %ecx
29617 rep movsq
29618 + pax_force_retaddr
29619 ret
29620 CFI_ENDPROC
29621 ENDPROC(copy_page_rep)
29622 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29623 CFI_ADJUST_CFA_OFFSET 2*8
29624 movq %rbx, (%rsp)
29625 CFI_REL_OFFSET rbx, 0
29626 - movq %r12, 1*8(%rsp)
29627 - CFI_REL_OFFSET r12, 1*8
29628 + movq %r13, 1*8(%rsp)
29629 + CFI_REL_OFFSET r13, 1*8
29630
29631 movl $(4096/64)-5, %ecx
29632 .p2align 4
29633 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29634 movq 0x8*4(%rsi), %r9
29635 movq 0x8*5(%rsi), %r10
29636 movq 0x8*6(%rsi), %r11
29637 - movq 0x8*7(%rsi), %r12
29638 + movq 0x8*7(%rsi), %r13
29639
29640 prefetcht0 5*64(%rsi)
29641
29642 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29643 movq %r9, 0x8*4(%rdi)
29644 movq %r10, 0x8*5(%rdi)
29645 movq %r11, 0x8*6(%rdi)
29646 - movq %r12, 0x8*7(%rdi)
29647 + movq %r13, 0x8*7(%rdi)
29648
29649 leaq 64 (%rsi), %rsi
29650 leaq 64 (%rdi), %rdi
29651 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29652 movq 0x8*4(%rsi), %r9
29653 movq 0x8*5(%rsi), %r10
29654 movq 0x8*6(%rsi), %r11
29655 - movq 0x8*7(%rsi), %r12
29656 + movq 0x8*7(%rsi), %r13
29657
29658 movq %rax, 0x8*0(%rdi)
29659 movq %rbx, 0x8*1(%rdi)
29660 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29661 movq %r9, 0x8*4(%rdi)
29662 movq %r10, 0x8*5(%rdi)
29663 movq %r11, 0x8*6(%rdi)
29664 - movq %r12, 0x8*7(%rdi)
29665 + movq %r13, 0x8*7(%rdi)
29666
29667 leaq 64(%rdi), %rdi
29668 leaq 64(%rsi), %rsi
29669 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29670
29671 movq (%rsp), %rbx
29672 CFI_RESTORE rbx
29673 - movq 1*8(%rsp), %r12
29674 - CFI_RESTORE r12
29675 + movq 1*8(%rsp), %r13
29676 + CFI_RESTORE r13
29677 addq $2*8, %rsp
29678 CFI_ADJUST_CFA_OFFSET -2*8
29679 + pax_force_retaddr
29680 ret
29681 .Lcopy_page_end:
29682 CFI_ENDPROC
29683 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29684
29685 #include <asm/cpufeature.h>
29686
29687 - .section .altinstr_replacement,"ax"
29688 + .section .altinstr_replacement,"a"
29689 1: .byte 0xeb /* jmp <disp8> */
29690 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29691 2:
29692 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29693 index dee945d..a84067b 100644
29694 --- a/arch/x86/lib/copy_user_64.S
29695 +++ b/arch/x86/lib/copy_user_64.S
29696 @@ -18,31 +18,7 @@
29697 #include <asm/alternative-asm.h>
29698 #include <asm/asm.h>
29699 #include <asm/smap.h>
29700 -
29701 -/*
29702 - * By placing feature2 after feature1 in altinstructions section, we logically
29703 - * implement:
29704 - * If CPU has feature2, jmp to alt2 is used
29705 - * else if CPU has feature1, jmp to alt1 is used
29706 - * else jmp to orig is used.
29707 - */
29708 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29709 -0:
29710 - .byte 0xe9 /* 32bit jump */
29711 - .long \orig-1f /* by default jump to orig */
29712 -1:
29713 - .section .altinstr_replacement,"ax"
29714 -2: .byte 0xe9 /* near jump with 32bit immediate */
29715 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29716 -3: .byte 0xe9 /* near jump with 32bit immediate */
29717 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29718 - .previous
29719 -
29720 - .section .altinstructions,"a"
29721 - altinstruction_entry 0b,2b,\feature1,5,5
29722 - altinstruction_entry 0b,3b,\feature2,5,5
29723 - .previous
29724 - .endm
29725 +#include <asm/pgtable.h>
29726
29727 .macro ALIGN_DESTINATION
29728 #ifdef FIX_ALIGNMENT
29729 @@ -70,52 +46,6 @@
29730 #endif
29731 .endm
29732
29733 -/* Standard copy_to_user with segment limit checking */
29734 -ENTRY(_copy_to_user)
29735 - CFI_STARTPROC
29736 - GET_THREAD_INFO(%rax)
29737 - movq %rdi,%rcx
29738 - addq %rdx,%rcx
29739 - jc bad_to_user
29740 - cmpq TI_addr_limit(%rax),%rcx
29741 - ja bad_to_user
29742 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29743 - copy_user_generic_unrolled,copy_user_generic_string, \
29744 - copy_user_enhanced_fast_string
29745 - CFI_ENDPROC
29746 -ENDPROC(_copy_to_user)
29747 -
29748 -/* Standard copy_from_user with segment limit checking */
29749 -ENTRY(_copy_from_user)
29750 - CFI_STARTPROC
29751 - GET_THREAD_INFO(%rax)
29752 - movq %rsi,%rcx
29753 - addq %rdx,%rcx
29754 - jc bad_from_user
29755 - cmpq TI_addr_limit(%rax),%rcx
29756 - ja bad_from_user
29757 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29758 - copy_user_generic_unrolled,copy_user_generic_string, \
29759 - copy_user_enhanced_fast_string
29760 - CFI_ENDPROC
29761 -ENDPROC(_copy_from_user)
29762 -
29763 - .section .fixup,"ax"
29764 - /* must zero dest */
29765 -ENTRY(bad_from_user)
29766 -bad_from_user:
29767 - CFI_STARTPROC
29768 - movl %edx,%ecx
29769 - xorl %eax,%eax
29770 - rep
29771 - stosb
29772 -bad_to_user:
29773 - movl %edx,%eax
29774 - ret
29775 - CFI_ENDPROC
29776 -ENDPROC(bad_from_user)
29777 - .previous
29778 -
29779 /*
29780 * copy_user_generic_unrolled - memory copy with exception handling.
29781 * This version is for CPUs like P4 that don't have efficient micro
29782 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29783 */
29784 ENTRY(copy_user_generic_unrolled)
29785 CFI_STARTPROC
29786 + ASM_PAX_OPEN_USERLAND
29787 ASM_STAC
29788 cmpl $8,%edx
29789 jb 20f /* less then 8 bytes, go to byte copy loop */
29790 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29791 jnz 21b
29792 23: xor %eax,%eax
29793 ASM_CLAC
29794 + ASM_PAX_CLOSE_USERLAND
29795 + pax_force_retaddr
29796 ret
29797
29798 .section .fixup,"ax"
29799 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29800 */
29801 ENTRY(copy_user_generic_string)
29802 CFI_STARTPROC
29803 + ASM_PAX_OPEN_USERLAND
29804 ASM_STAC
29805 cmpl $8,%edx
29806 jb 2f /* less than 8 bytes, go to byte copy loop */
29807 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29808 movsb
29809 xorl %eax,%eax
29810 ASM_CLAC
29811 + ASM_PAX_CLOSE_USERLAND
29812 + pax_force_retaddr
29813 ret
29814
29815 .section .fixup,"ax"
29816 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29817 */
29818 ENTRY(copy_user_enhanced_fast_string)
29819 CFI_STARTPROC
29820 + ASM_PAX_OPEN_USERLAND
29821 ASM_STAC
29822 movl %edx,%ecx
29823 1: rep
29824 movsb
29825 xorl %eax,%eax
29826 ASM_CLAC
29827 + ASM_PAX_CLOSE_USERLAND
29828 + pax_force_retaddr
29829 ret
29830
29831 .section .fixup,"ax"
29832 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29833 index 6a4f43c..c70fb52 100644
29834 --- a/arch/x86/lib/copy_user_nocache_64.S
29835 +++ b/arch/x86/lib/copy_user_nocache_64.S
29836 @@ -8,6 +8,7 @@
29837
29838 #include <linux/linkage.h>
29839 #include <asm/dwarf2.h>
29840 +#include <asm/alternative-asm.h>
29841
29842 #define FIX_ALIGNMENT 1
29843
29844 @@ -16,6 +17,7 @@
29845 #include <asm/thread_info.h>
29846 #include <asm/asm.h>
29847 #include <asm/smap.h>
29848 +#include <asm/pgtable.h>
29849
29850 .macro ALIGN_DESTINATION
29851 #ifdef FIX_ALIGNMENT
29852 @@ -49,6 +51,16 @@
29853 */
29854 ENTRY(__copy_user_nocache)
29855 CFI_STARTPROC
29856 +
29857 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29858 + mov pax_user_shadow_base,%rcx
29859 + cmp %rcx,%rsi
29860 + jae 1f
29861 + add %rcx,%rsi
29862 +1:
29863 +#endif
29864 +
29865 + ASM_PAX_OPEN_USERLAND
29866 ASM_STAC
29867 cmpl $8,%edx
29868 jb 20f /* less then 8 bytes, go to byte copy loop */
29869 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29870 jnz 21b
29871 23: xorl %eax,%eax
29872 ASM_CLAC
29873 + ASM_PAX_CLOSE_USERLAND
29874 sfence
29875 + pax_force_retaddr
29876 ret
29877
29878 .section .fixup,"ax"
29879 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29880 index 2419d5f..fe52d0e 100644
29881 --- a/arch/x86/lib/csum-copy_64.S
29882 +++ b/arch/x86/lib/csum-copy_64.S
29883 @@ -9,6 +9,7 @@
29884 #include <asm/dwarf2.h>
29885 #include <asm/errno.h>
29886 #include <asm/asm.h>
29887 +#include <asm/alternative-asm.h>
29888
29889 /*
29890 * Checksum copy with exception handling.
29891 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29892 CFI_ADJUST_CFA_OFFSET 7*8
29893 movq %rbx, 2*8(%rsp)
29894 CFI_REL_OFFSET rbx, 2*8
29895 - movq %r12, 3*8(%rsp)
29896 - CFI_REL_OFFSET r12, 3*8
29897 + movq %r15, 3*8(%rsp)
29898 + CFI_REL_OFFSET r15, 3*8
29899 movq %r14, 4*8(%rsp)
29900 CFI_REL_OFFSET r14, 4*8
29901 movq %r13, 5*8(%rsp)
29902 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29903 movl %edx, %ecx
29904
29905 xorl %r9d, %r9d
29906 - movq %rcx, %r12
29907 + movq %rcx, %r15
29908
29909 - shrq $6, %r12
29910 + shrq $6, %r15
29911 jz .Lhandle_tail /* < 64 */
29912
29913 clc
29914
29915 /* main loop. clear in 64 byte blocks */
29916 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29917 - /* r11: temp3, rdx: temp4, r12 loopcnt */
29918 + /* r11: temp3, rdx: temp4, r15 loopcnt */
29919 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29920 .p2align 4
29921 .Lloop:
29922 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29923 adcq %r14, %rax
29924 adcq %r13, %rax
29925
29926 - decl %r12d
29927 + decl %r15d
29928
29929 dest
29930 movq %rbx, (%rsi)
29931 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29932 .Lende:
29933 movq 2*8(%rsp), %rbx
29934 CFI_RESTORE rbx
29935 - movq 3*8(%rsp), %r12
29936 - CFI_RESTORE r12
29937 + movq 3*8(%rsp), %r15
29938 + CFI_RESTORE r15
29939 movq 4*8(%rsp), %r14
29940 CFI_RESTORE r14
29941 movq 5*8(%rsp), %r13
29942 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29943 CFI_RESTORE rbp
29944 addq $7*8, %rsp
29945 CFI_ADJUST_CFA_OFFSET -7*8
29946 + pax_force_retaddr
29947 ret
29948 CFI_RESTORE_STATE
29949
29950 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29951 index 7609e0e..b449b98 100644
29952 --- a/arch/x86/lib/csum-wrappers_64.c
29953 +++ b/arch/x86/lib/csum-wrappers_64.c
29954 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29955 len -= 2;
29956 }
29957 }
29958 + pax_open_userland();
29959 stac();
29960 - isum = csum_partial_copy_generic((__force const void *)src,
29961 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29962 dst, len, isum, errp, NULL);
29963 clac();
29964 + pax_close_userland();
29965 if (unlikely(*errp))
29966 goto out_err;
29967
29968 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29969 }
29970
29971 *errp = 0;
29972 + pax_open_userland();
29973 stac();
29974 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29975 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29976 len, isum, NULL, errp);
29977 clac();
29978 + pax_close_userland();
29979 return ret;
29980 }
29981 EXPORT_SYMBOL(csum_partial_copy_to_user);
29982 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29983 index a451235..1daa956 100644
29984 --- a/arch/x86/lib/getuser.S
29985 +++ b/arch/x86/lib/getuser.S
29986 @@ -33,17 +33,40 @@
29987 #include <asm/thread_info.h>
29988 #include <asm/asm.h>
29989 #include <asm/smap.h>
29990 +#include <asm/segment.h>
29991 +#include <asm/pgtable.h>
29992 +#include <asm/alternative-asm.h>
29993 +
29994 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29995 +#define __copyuser_seg gs;
29996 +#else
29997 +#define __copyuser_seg
29998 +#endif
29999
30000 .text
30001 ENTRY(__get_user_1)
30002 CFI_STARTPROC
30003 +
30004 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30005 GET_THREAD_INFO(%_ASM_DX)
30006 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30007 jae bad_get_user
30008 ASM_STAC
30009 -1: movzbl (%_ASM_AX),%edx
30010 +
30011 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30012 + mov pax_user_shadow_base,%_ASM_DX
30013 + cmp %_ASM_DX,%_ASM_AX
30014 + jae 1234f
30015 + add %_ASM_DX,%_ASM_AX
30016 +1234:
30017 +#endif
30018 +
30019 +#endif
30020 +
30021 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
30022 xor %eax,%eax
30023 ASM_CLAC
30024 + pax_force_retaddr
30025 ret
30026 CFI_ENDPROC
30027 ENDPROC(__get_user_1)
30028 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30029 ENTRY(__get_user_2)
30030 CFI_STARTPROC
30031 add $1,%_ASM_AX
30032 +
30033 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30034 jc bad_get_user
30035 GET_THREAD_INFO(%_ASM_DX)
30036 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30037 jae bad_get_user
30038 ASM_STAC
30039 -2: movzwl -1(%_ASM_AX),%edx
30040 +
30041 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30042 + mov pax_user_shadow_base,%_ASM_DX
30043 + cmp %_ASM_DX,%_ASM_AX
30044 + jae 1234f
30045 + add %_ASM_DX,%_ASM_AX
30046 +1234:
30047 +#endif
30048 +
30049 +#endif
30050 +
30051 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30052 xor %eax,%eax
30053 ASM_CLAC
30054 + pax_force_retaddr
30055 ret
30056 CFI_ENDPROC
30057 ENDPROC(__get_user_2)
30058 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30059 ENTRY(__get_user_4)
30060 CFI_STARTPROC
30061 add $3,%_ASM_AX
30062 +
30063 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30064 jc bad_get_user
30065 GET_THREAD_INFO(%_ASM_DX)
30066 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30067 jae bad_get_user
30068 ASM_STAC
30069 -3: movl -3(%_ASM_AX),%edx
30070 +
30071 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30072 + mov pax_user_shadow_base,%_ASM_DX
30073 + cmp %_ASM_DX,%_ASM_AX
30074 + jae 1234f
30075 + add %_ASM_DX,%_ASM_AX
30076 +1234:
30077 +#endif
30078 +
30079 +#endif
30080 +
30081 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
30082 xor %eax,%eax
30083 ASM_CLAC
30084 + pax_force_retaddr
30085 ret
30086 CFI_ENDPROC
30087 ENDPROC(__get_user_4)
30088 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30089 GET_THREAD_INFO(%_ASM_DX)
30090 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30091 jae bad_get_user
30092 +
30093 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30094 + mov pax_user_shadow_base,%_ASM_DX
30095 + cmp %_ASM_DX,%_ASM_AX
30096 + jae 1234f
30097 + add %_ASM_DX,%_ASM_AX
30098 +1234:
30099 +#endif
30100 +
30101 ASM_STAC
30102 4: movq -7(%_ASM_AX),%rdx
30103 xor %eax,%eax
30104 ASM_CLAC
30105 + pax_force_retaddr
30106 ret
30107 #else
30108 add $7,%_ASM_AX
30109 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30110 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30111 jae bad_get_user_8
30112 ASM_STAC
30113 -4: movl -7(%_ASM_AX),%edx
30114 -5: movl -3(%_ASM_AX),%ecx
30115 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
30116 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30117 xor %eax,%eax
30118 ASM_CLAC
30119 + pax_force_retaddr
30120 ret
30121 #endif
30122 CFI_ENDPROC
30123 @@ -113,6 +175,7 @@ bad_get_user:
30124 xor %edx,%edx
30125 mov $(-EFAULT),%_ASM_AX
30126 ASM_CLAC
30127 + pax_force_retaddr
30128 ret
30129 CFI_ENDPROC
30130 END(bad_get_user)
30131 @@ -124,6 +187,7 @@ bad_get_user_8:
30132 xor %ecx,%ecx
30133 mov $(-EFAULT),%_ASM_AX
30134 ASM_CLAC
30135 + pax_force_retaddr
30136 ret
30137 CFI_ENDPROC
30138 END(bad_get_user_8)
30139 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30140 index 54fcffe..7be149e 100644
30141 --- a/arch/x86/lib/insn.c
30142 +++ b/arch/x86/lib/insn.c
30143 @@ -20,8 +20,10 @@
30144
30145 #ifdef __KERNEL__
30146 #include <linux/string.h>
30147 +#include <asm/pgtable_types.h>
30148 #else
30149 #include <string.h>
30150 +#define ktla_ktva(addr) addr
30151 #endif
30152 #include <asm/inat.h>
30153 #include <asm/insn.h>
30154 @@ -53,8 +55,8 @@
30155 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30156 {
30157 memset(insn, 0, sizeof(*insn));
30158 - insn->kaddr = kaddr;
30159 - insn->next_byte = kaddr;
30160 + insn->kaddr = ktla_ktva(kaddr);
30161 + insn->next_byte = ktla_ktva(kaddr);
30162 insn->x86_64 = x86_64 ? 1 : 0;
30163 insn->opnd_bytes = 4;
30164 if (x86_64)
30165 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30166 index 05a95e7..326f2fa 100644
30167 --- a/arch/x86/lib/iomap_copy_64.S
30168 +++ b/arch/x86/lib/iomap_copy_64.S
30169 @@ -17,6 +17,7 @@
30170
30171 #include <linux/linkage.h>
30172 #include <asm/dwarf2.h>
30173 +#include <asm/alternative-asm.h>
30174
30175 /*
30176 * override generic version in lib/iomap_copy.c
30177 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30178 CFI_STARTPROC
30179 movl %edx,%ecx
30180 rep movsd
30181 + pax_force_retaddr
30182 ret
30183 CFI_ENDPROC
30184 ENDPROC(__iowrite32_copy)
30185 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30186 index 56313a3..0db417e 100644
30187 --- a/arch/x86/lib/memcpy_64.S
30188 +++ b/arch/x86/lib/memcpy_64.S
30189 @@ -24,7 +24,7 @@
30190 * This gets patched over the unrolled variant (below) via the
30191 * alternative instructions framework:
30192 */
30193 - .section .altinstr_replacement, "ax", @progbits
30194 + .section .altinstr_replacement, "a", @progbits
30195 .Lmemcpy_c:
30196 movq %rdi, %rax
30197 movq %rdx, %rcx
30198 @@ -33,6 +33,7 @@
30199 rep movsq
30200 movl %edx, %ecx
30201 rep movsb
30202 + pax_force_retaddr
30203 ret
30204 .Lmemcpy_e:
30205 .previous
30206 @@ -44,11 +45,12 @@
30207 * This gets patched over the unrolled variant (below) via the
30208 * alternative instructions framework:
30209 */
30210 - .section .altinstr_replacement, "ax", @progbits
30211 + .section .altinstr_replacement, "a", @progbits
30212 .Lmemcpy_c_e:
30213 movq %rdi, %rax
30214 movq %rdx, %rcx
30215 rep movsb
30216 + pax_force_retaddr
30217 ret
30218 .Lmemcpy_e_e:
30219 .previous
30220 @@ -136,6 +138,7 @@ ENTRY(memcpy)
30221 movq %r9, 1*8(%rdi)
30222 movq %r10, -2*8(%rdi, %rdx)
30223 movq %r11, -1*8(%rdi, %rdx)
30224 + pax_force_retaddr
30225 retq
30226 .p2align 4
30227 .Lless_16bytes:
30228 @@ -148,6 +151,7 @@ ENTRY(memcpy)
30229 movq -1*8(%rsi, %rdx), %r9
30230 movq %r8, 0*8(%rdi)
30231 movq %r9, -1*8(%rdi, %rdx)
30232 + pax_force_retaddr
30233 retq
30234 .p2align 4
30235 .Lless_8bytes:
30236 @@ -161,6 +165,7 @@ ENTRY(memcpy)
30237 movl -4(%rsi, %rdx), %r8d
30238 movl %ecx, (%rdi)
30239 movl %r8d, -4(%rdi, %rdx)
30240 + pax_force_retaddr
30241 retq
30242 .p2align 4
30243 .Lless_3bytes:
30244 @@ -179,6 +184,7 @@ ENTRY(memcpy)
30245 movb %cl, (%rdi)
30246
30247 .Lend:
30248 + pax_force_retaddr
30249 retq
30250 CFI_ENDPROC
30251 ENDPROC(memcpy)
30252 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30253 index 65268a6..dd1de11 100644
30254 --- a/arch/x86/lib/memmove_64.S
30255 +++ b/arch/x86/lib/memmove_64.S
30256 @@ -202,14 +202,16 @@ ENTRY(memmove)
30257 movb (%rsi), %r11b
30258 movb %r11b, (%rdi)
30259 13:
30260 + pax_force_retaddr
30261 retq
30262 CFI_ENDPROC
30263
30264 - .section .altinstr_replacement,"ax"
30265 + .section .altinstr_replacement,"a"
30266 .Lmemmove_begin_forward_efs:
30267 /* Forward moving data. */
30268 movq %rdx, %rcx
30269 rep movsb
30270 + pax_force_retaddr
30271 retq
30272 .Lmemmove_end_forward_efs:
30273 .previous
30274 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30275 index 2dcb380..2eb79fe 100644
30276 --- a/arch/x86/lib/memset_64.S
30277 +++ b/arch/x86/lib/memset_64.S
30278 @@ -16,7 +16,7 @@
30279 *
30280 * rax original destination
30281 */
30282 - .section .altinstr_replacement, "ax", @progbits
30283 + .section .altinstr_replacement, "a", @progbits
30284 .Lmemset_c:
30285 movq %rdi,%r9
30286 movq %rdx,%rcx
30287 @@ -30,6 +30,7 @@
30288 movl %edx,%ecx
30289 rep stosb
30290 movq %r9,%rax
30291 + pax_force_retaddr
30292 ret
30293 .Lmemset_e:
30294 .previous
30295 @@ -45,13 +46,14 @@
30296 *
30297 * rax original destination
30298 */
30299 - .section .altinstr_replacement, "ax", @progbits
30300 + .section .altinstr_replacement, "a", @progbits
30301 .Lmemset_c_e:
30302 movq %rdi,%r9
30303 movb %sil,%al
30304 movq %rdx,%rcx
30305 rep stosb
30306 movq %r9,%rax
30307 + pax_force_retaddr
30308 ret
30309 .Lmemset_e_e:
30310 .previous
30311 @@ -118,6 +120,7 @@ ENTRY(__memset)
30312
30313 .Lende:
30314 movq %r10,%rax
30315 + pax_force_retaddr
30316 ret
30317
30318 CFI_RESTORE_STATE
30319 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30320 index c9f2d9b..e7fd2c0 100644
30321 --- a/arch/x86/lib/mmx_32.c
30322 +++ b/arch/x86/lib/mmx_32.c
30323 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30324 {
30325 void *p;
30326 int i;
30327 + unsigned long cr0;
30328
30329 if (unlikely(in_interrupt()))
30330 return __memcpy(to, from, len);
30331 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30332 kernel_fpu_begin();
30333
30334 __asm__ __volatile__ (
30335 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30336 - " prefetch 64(%0)\n"
30337 - " prefetch 128(%0)\n"
30338 - " prefetch 192(%0)\n"
30339 - " prefetch 256(%0)\n"
30340 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30341 + " prefetch 64(%1)\n"
30342 + " prefetch 128(%1)\n"
30343 + " prefetch 192(%1)\n"
30344 + " prefetch 256(%1)\n"
30345 "2: \n"
30346 ".section .fixup, \"ax\"\n"
30347 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30348 + "3: \n"
30349 +
30350 +#ifdef CONFIG_PAX_KERNEXEC
30351 + " movl %%cr0, %0\n"
30352 + " movl %0, %%eax\n"
30353 + " andl $0xFFFEFFFF, %%eax\n"
30354 + " movl %%eax, %%cr0\n"
30355 +#endif
30356 +
30357 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30358 +
30359 +#ifdef CONFIG_PAX_KERNEXEC
30360 + " movl %0, %%cr0\n"
30361 +#endif
30362 +
30363 " jmp 2b\n"
30364 ".previous\n"
30365 _ASM_EXTABLE(1b, 3b)
30366 - : : "r" (from));
30367 + : "=&r" (cr0) : "r" (from) : "ax");
30368
30369 for ( ; i > 5; i--) {
30370 __asm__ __volatile__ (
30371 - "1: prefetch 320(%0)\n"
30372 - "2: movq (%0), %%mm0\n"
30373 - " movq 8(%0), %%mm1\n"
30374 - " movq 16(%0), %%mm2\n"
30375 - " movq 24(%0), %%mm3\n"
30376 - " movq %%mm0, (%1)\n"
30377 - " movq %%mm1, 8(%1)\n"
30378 - " movq %%mm2, 16(%1)\n"
30379 - " movq %%mm3, 24(%1)\n"
30380 - " movq 32(%0), %%mm0\n"
30381 - " movq 40(%0), %%mm1\n"
30382 - " movq 48(%0), %%mm2\n"
30383 - " movq 56(%0), %%mm3\n"
30384 - " movq %%mm0, 32(%1)\n"
30385 - " movq %%mm1, 40(%1)\n"
30386 - " movq %%mm2, 48(%1)\n"
30387 - " movq %%mm3, 56(%1)\n"
30388 + "1: prefetch 320(%1)\n"
30389 + "2: movq (%1), %%mm0\n"
30390 + " movq 8(%1), %%mm1\n"
30391 + " movq 16(%1), %%mm2\n"
30392 + " movq 24(%1), %%mm3\n"
30393 + " movq %%mm0, (%2)\n"
30394 + " movq %%mm1, 8(%2)\n"
30395 + " movq %%mm2, 16(%2)\n"
30396 + " movq %%mm3, 24(%2)\n"
30397 + " movq 32(%1), %%mm0\n"
30398 + " movq 40(%1), %%mm1\n"
30399 + " movq 48(%1), %%mm2\n"
30400 + " movq 56(%1), %%mm3\n"
30401 + " movq %%mm0, 32(%2)\n"
30402 + " movq %%mm1, 40(%2)\n"
30403 + " movq %%mm2, 48(%2)\n"
30404 + " movq %%mm3, 56(%2)\n"
30405 ".section .fixup, \"ax\"\n"
30406 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30407 + "3:\n"
30408 +
30409 +#ifdef CONFIG_PAX_KERNEXEC
30410 + " movl %%cr0, %0\n"
30411 + " movl %0, %%eax\n"
30412 + " andl $0xFFFEFFFF, %%eax\n"
30413 + " movl %%eax, %%cr0\n"
30414 +#endif
30415 +
30416 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30417 +
30418 +#ifdef CONFIG_PAX_KERNEXEC
30419 + " movl %0, %%cr0\n"
30420 +#endif
30421 +
30422 " jmp 2b\n"
30423 ".previous\n"
30424 _ASM_EXTABLE(1b, 3b)
30425 - : : "r" (from), "r" (to) : "memory");
30426 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30427
30428 from += 64;
30429 to += 64;
30430 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30431 static void fast_copy_page(void *to, void *from)
30432 {
30433 int i;
30434 + unsigned long cr0;
30435
30436 kernel_fpu_begin();
30437
30438 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30439 * but that is for later. -AV
30440 */
30441 __asm__ __volatile__(
30442 - "1: prefetch (%0)\n"
30443 - " prefetch 64(%0)\n"
30444 - " prefetch 128(%0)\n"
30445 - " prefetch 192(%0)\n"
30446 - " prefetch 256(%0)\n"
30447 + "1: prefetch (%1)\n"
30448 + " prefetch 64(%1)\n"
30449 + " prefetch 128(%1)\n"
30450 + " prefetch 192(%1)\n"
30451 + " prefetch 256(%1)\n"
30452 "2: \n"
30453 ".section .fixup, \"ax\"\n"
30454 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30455 + "3: \n"
30456 +
30457 +#ifdef CONFIG_PAX_KERNEXEC
30458 + " movl %%cr0, %0\n"
30459 + " movl %0, %%eax\n"
30460 + " andl $0xFFFEFFFF, %%eax\n"
30461 + " movl %%eax, %%cr0\n"
30462 +#endif
30463 +
30464 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30465 +
30466 +#ifdef CONFIG_PAX_KERNEXEC
30467 + " movl %0, %%cr0\n"
30468 +#endif
30469 +
30470 " jmp 2b\n"
30471 ".previous\n"
30472 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30473 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30474
30475 for (i = 0; i < (4096-320)/64; i++) {
30476 __asm__ __volatile__ (
30477 - "1: prefetch 320(%0)\n"
30478 - "2: movq (%0), %%mm0\n"
30479 - " movntq %%mm0, (%1)\n"
30480 - " movq 8(%0), %%mm1\n"
30481 - " movntq %%mm1, 8(%1)\n"
30482 - " movq 16(%0), %%mm2\n"
30483 - " movntq %%mm2, 16(%1)\n"
30484 - " movq 24(%0), %%mm3\n"
30485 - " movntq %%mm3, 24(%1)\n"
30486 - " movq 32(%0), %%mm4\n"
30487 - " movntq %%mm4, 32(%1)\n"
30488 - " movq 40(%0), %%mm5\n"
30489 - " movntq %%mm5, 40(%1)\n"
30490 - " movq 48(%0), %%mm6\n"
30491 - " movntq %%mm6, 48(%1)\n"
30492 - " movq 56(%0), %%mm7\n"
30493 - " movntq %%mm7, 56(%1)\n"
30494 + "1: prefetch 320(%1)\n"
30495 + "2: movq (%1), %%mm0\n"
30496 + " movntq %%mm0, (%2)\n"
30497 + " movq 8(%1), %%mm1\n"
30498 + " movntq %%mm1, 8(%2)\n"
30499 + " movq 16(%1), %%mm2\n"
30500 + " movntq %%mm2, 16(%2)\n"
30501 + " movq 24(%1), %%mm3\n"
30502 + " movntq %%mm3, 24(%2)\n"
30503 + " movq 32(%1), %%mm4\n"
30504 + " movntq %%mm4, 32(%2)\n"
30505 + " movq 40(%1), %%mm5\n"
30506 + " movntq %%mm5, 40(%2)\n"
30507 + " movq 48(%1), %%mm6\n"
30508 + " movntq %%mm6, 48(%2)\n"
30509 + " movq 56(%1), %%mm7\n"
30510 + " movntq %%mm7, 56(%2)\n"
30511 ".section .fixup, \"ax\"\n"
30512 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30513 + "3:\n"
30514 +
30515 +#ifdef CONFIG_PAX_KERNEXEC
30516 + " movl %%cr0, %0\n"
30517 + " movl %0, %%eax\n"
30518 + " andl $0xFFFEFFFF, %%eax\n"
30519 + " movl %%eax, %%cr0\n"
30520 +#endif
30521 +
30522 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30523 +
30524 +#ifdef CONFIG_PAX_KERNEXEC
30525 + " movl %0, %%cr0\n"
30526 +#endif
30527 +
30528 " jmp 2b\n"
30529 ".previous\n"
30530 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30531 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30532
30533 from += 64;
30534 to += 64;
30535 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30536 static void fast_copy_page(void *to, void *from)
30537 {
30538 int i;
30539 + unsigned long cr0;
30540
30541 kernel_fpu_begin();
30542
30543 __asm__ __volatile__ (
30544 - "1: prefetch (%0)\n"
30545 - " prefetch 64(%0)\n"
30546 - " prefetch 128(%0)\n"
30547 - " prefetch 192(%0)\n"
30548 - " prefetch 256(%0)\n"
30549 + "1: prefetch (%1)\n"
30550 + " prefetch 64(%1)\n"
30551 + " prefetch 128(%1)\n"
30552 + " prefetch 192(%1)\n"
30553 + " prefetch 256(%1)\n"
30554 "2: \n"
30555 ".section .fixup, \"ax\"\n"
30556 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30557 + "3: \n"
30558 +
30559 +#ifdef CONFIG_PAX_KERNEXEC
30560 + " movl %%cr0, %0\n"
30561 + " movl %0, %%eax\n"
30562 + " andl $0xFFFEFFFF, %%eax\n"
30563 + " movl %%eax, %%cr0\n"
30564 +#endif
30565 +
30566 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30567 +
30568 +#ifdef CONFIG_PAX_KERNEXEC
30569 + " movl %0, %%cr0\n"
30570 +#endif
30571 +
30572 " jmp 2b\n"
30573 ".previous\n"
30574 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30575 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30576
30577 for (i = 0; i < 4096/64; i++) {
30578 __asm__ __volatile__ (
30579 - "1: prefetch 320(%0)\n"
30580 - "2: movq (%0), %%mm0\n"
30581 - " movq 8(%0), %%mm1\n"
30582 - " movq 16(%0), %%mm2\n"
30583 - " movq 24(%0), %%mm3\n"
30584 - " movq %%mm0, (%1)\n"
30585 - " movq %%mm1, 8(%1)\n"
30586 - " movq %%mm2, 16(%1)\n"
30587 - " movq %%mm3, 24(%1)\n"
30588 - " movq 32(%0), %%mm0\n"
30589 - " movq 40(%0), %%mm1\n"
30590 - " movq 48(%0), %%mm2\n"
30591 - " movq 56(%0), %%mm3\n"
30592 - " movq %%mm0, 32(%1)\n"
30593 - " movq %%mm1, 40(%1)\n"
30594 - " movq %%mm2, 48(%1)\n"
30595 - " movq %%mm3, 56(%1)\n"
30596 + "1: prefetch 320(%1)\n"
30597 + "2: movq (%1), %%mm0\n"
30598 + " movq 8(%1), %%mm1\n"
30599 + " movq 16(%1), %%mm2\n"
30600 + " movq 24(%1), %%mm3\n"
30601 + " movq %%mm0, (%2)\n"
30602 + " movq %%mm1, 8(%2)\n"
30603 + " movq %%mm2, 16(%2)\n"
30604 + " movq %%mm3, 24(%2)\n"
30605 + " movq 32(%1), %%mm0\n"
30606 + " movq 40(%1), %%mm1\n"
30607 + " movq 48(%1), %%mm2\n"
30608 + " movq 56(%1), %%mm3\n"
30609 + " movq %%mm0, 32(%2)\n"
30610 + " movq %%mm1, 40(%2)\n"
30611 + " movq %%mm2, 48(%2)\n"
30612 + " movq %%mm3, 56(%2)\n"
30613 ".section .fixup, \"ax\"\n"
30614 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30615 + "3:\n"
30616 +
30617 +#ifdef CONFIG_PAX_KERNEXEC
30618 + " movl %%cr0, %0\n"
30619 + " movl %0, %%eax\n"
30620 + " andl $0xFFFEFFFF, %%eax\n"
30621 + " movl %%eax, %%cr0\n"
30622 +#endif
30623 +
30624 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30625 +
30626 +#ifdef CONFIG_PAX_KERNEXEC
30627 + " movl %0, %%cr0\n"
30628 +#endif
30629 +
30630 " jmp 2b\n"
30631 ".previous\n"
30632 _ASM_EXTABLE(1b, 3b)
30633 - : : "r" (from), "r" (to) : "memory");
30634 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30635
30636 from += 64;
30637 to += 64;
30638 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30639 index f6d13ee..d789440 100644
30640 --- a/arch/x86/lib/msr-reg.S
30641 +++ b/arch/x86/lib/msr-reg.S
30642 @@ -3,6 +3,7 @@
30643 #include <asm/dwarf2.h>
30644 #include <asm/asm.h>
30645 #include <asm/msr.h>
30646 +#include <asm/alternative-asm.h>
30647
30648 #ifdef CONFIG_X86_64
30649 /*
30650 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30651 movl %edi, 28(%r10)
30652 popq_cfi %rbp
30653 popq_cfi %rbx
30654 + pax_force_retaddr
30655 ret
30656 3:
30657 CFI_RESTORE_STATE
30658 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30659 index fc6ba17..d4d989d 100644
30660 --- a/arch/x86/lib/putuser.S
30661 +++ b/arch/x86/lib/putuser.S
30662 @@ -16,7 +16,9 @@
30663 #include <asm/errno.h>
30664 #include <asm/asm.h>
30665 #include <asm/smap.h>
30666 -
30667 +#include <asm/segment.h>
30668 +#include <asm/pgtable.h>
30669 +#include <asm/alternative-asm.h>
30670
30671 /*
30672 * __put_user_X
30673 @@ -30,57 +32,125 @@
30674 * as they get called from within inline assembly.
30675 */
30676
30677 -#define ENTER CFI_STARTPROC ; \
30678 - GET_THREAD_INFO(%_ASM_BX)
30679 -#define EXIT ASM_CLAC ; \
30680 - ret ; \
30681 +#define ENTER CFI_STARTPROC
30682 +#define EXIT ASM_CLAC ; \
30683 + pax_force_retaddr ; \
30684 + ret ; \
30685 CFI_ENDPROC
30686
30687 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30688 +#define _DEST %_ASM_CX,%_ASM_BX
30689 +#else
30690 +#define _DEST %_ASM_CX
30691 +#endif
30692 +
30693 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30694 +#define __copyuser_seg gs;
30695 +#else
30696 +#define __copyuser_seg
30697 +#endif
30698 +
30699 .text
30700 ENTRY(__put_user_1)
30701 ENTER
30702 +
30703 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30704 + GET_THREAD_INFO(%_ASM_BX)
30705 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30706 jae bad_put_user
30707 ASM_STAC
30708 -1: movb %al,(%_ASM_CX)
30709 +
30710 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30711 + mov pax_user_shadow_base,%_ASM_BX
30712 + cmp %_ASM_BX,%_ASM_CX
30713 + jb 1234f
30714 + xor %ebx,%ebx
30715 +1234:
30716 +#endif
30717 +
30718 +#endif
30719 +
30720 +1: __copyuser_seg movb %al,(_DEST)
30721 xor %eax,%eax
30722 EXIT
30723 ENDPROC(__put_user_1)
30724
30725 ENTRY(__put_user_2)
30726 ENTER
30727 +
30728 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30729 + GET_THREAD_INFO(%_ASM_BX)
30730 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30731 sub $1,%_ASM_BX
30732 cmp %_ASM_BX,%_ASM_CX
30733 jae bad_put_user
30734 ASM_STAC
30735 -2: movw %ax,(%_ASM_CX)
30736 +
30737 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30738 + mov pax_user_shadow_base,%_ASM_BX
30739 + cmp %_ASM_BX,%_ASM_CX
30740 + jb 1234f
30741 + xor %ebx,%ebx
30742 +1234:
30743 +#endif
30744 +
30745 +#endif
30746 +
30747 +2: __copyuser_seg movw %ax,(_DEST)
30748 xor %eax,%eax
30749 EXIT
30750 ENDPROC(__put_user_2)
30751
30752 ENTRY(__put_user_4)
30753 ENTER
30754 +
30755 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30756 + GET_THREAD_INFO(%_ASM_BX)
30757 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30758 sub $3,%_ASM_BX
30759 cmp %_ASM_BX,%_ASM_CX
30760 jae bad_put_user
30761 ASM_STAC
30762 -3: movl %eax,(%_ASM_CX)
30763 +
30764 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30765 + mov pax_user_shadow_base,%_ASM_BX
30766 + cmp %_ASM_BX,%_ASM_CX
30767 + jb 1234f
30768 + xor %ebx,%ebx
30769 +1234:
30770 +#endif
30771 +
30772 +#endif
30773 +
30774 +3: __copyuser_seg movl %eax,(_DEST)
30775 xor %eax,%eax
30776 EXIT
30777 ENDPROC(__put_user_4)
30778
30779 ENTRY(__put_user_8)
30780 ENTER
30781 +
30782 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30783 + GET_THREAD_INFO(%_ASM_BX)
30784 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30785 sub $7,%_ASM_BX
30786 cmp %_ASM_BX,%_ASM_CX
30787 jae bad_put_user
30788 ASM_STAC
30789 -4: mov %_ASM_AX,(%_ASM_CX)
30790 +
30791 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30792 + mov pax_user_shadow_base,%_ASM_BX
30793 + cmp %_ASM_BX,%_ASM_CX
30794 + jb 1234f
30795 + xor %ebx,%ebx
30796 +1234:
30797 +#endif
30798 +
30799 +#endif
30800 +
30801 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30802 #ifdef CONFIG_X86_32
30803 -5: movl %edx,4(%_ASM_CX)
30804 +5: __copyuser_seg movl %edx,4(_DEST)
30805 #endif
30806 xor %eax,%eax
30807 EXIT
30808 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30809 index 1cad221..de671ee 100644
30810 --- a/arch/x86/lib/rwlock.S
30811 +++ b/arch/x86/lib/rwlock.S
30812 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30813 FRAME
30814 0: LOCK_PREFIX
30815 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30816 +
30817 +#ifdef CONFIG_PAX_REFCOUNT
30818 + jno 1234f
30819 + LOCK_PREFIX
30820 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30821 + int $4
30822 +1234:
30823 + _ASM_EXTABLE(1234b, 1234b)
30824 +#endif
30825 +
30826 1: rep; nop
30827 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30828 jne 1b
30829 LOCK_PREFIX
30830 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30831 +
30832 +#ifdef CONFIG_PAX_REFCOUNT
30833 + jno 1234f
30834 + LOCK_PREFIX
30835 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30836 + int $4
30837 +1234:
30838 + _ASM_EXTABLE(1234b, 1234b)
30839 +#endif
30840 +
30841 jnz 0b
30842 ENDFRAME
30843 + pax_force_retaddr
30844 ret
30845 CFI_ENDPROC
30846 END(__write_lock_failed)
30847 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30848 FRAME
30849 0: LOCK_PREFIX
30850 READ_LOCK_SIZE(inc) (%__lock_ptr)
30851 +
30852 +#ifdef CONFIG_PAX_REFCOUNT
30853 + jno 1234f
30854 + LOCK_PREFIX
30855 + READ_LOCK_SIZE(dec) (%__lock_ptr)
30856 + int $4
30857 +1234:
30858 + _ASM_EXTABLE(1234b, 1234b)
30859 +#endif
30860 +
30861 1: rep; nop
30862 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30863 js 1b
30864 LOCK_PREFIX
30865 READ_LOCK_SIZE(dec) (%__lock_ptr)
30866 +
30867 +#ifdef CONFIG_PAX_REFCOUNT
30868 + jno 1234f
30869 + LOCK_PREFIX
30870 + READ_LOCK_SIZE(inc) (%__lock_ptr)
30871 + int $4
30872 +1234:
30873 + _ASM_EXTABLE(1234b, 1234b)
30874 +#endif
30875 +
30876 js 0b
30877 ENDFRAME
30878 + pax_force_retaddr
30879 ret
30880 CFI_ENDPROC
30881 END(__read_lock_failed)
30882 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30883 index 5dff5f0..cadebf4 100644
30884 --- a/arch/x86/lib/rwsem.S
30885 +++ b/arch/x86/lib/rwsem.S
30886 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30887 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30888 CFI_RESTORE __ASM_REG(dx)
30889 restore_common_regs
30890 + pax_force_retaddr
30891 ret
30892 CFI_ENDPROC
30893 ENDPROC(call_rwsem_down_read_failed)
30894 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30895 movq %rax,%rdi
30896 call rwsem_down_write_failed
30897 restore_common_regs
30898 + pax_force_retaddr
30899 ret
30900 CFI_ENDPROC
30901 ENDPROC(call_rwsem_down_write_failed)
30902 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30903 movq %rax,%rdi
30904 call rwsem_wake
30905 restore_common_regs
30906 -1: ret
30907 +1: pax_force_retaddr
30908 + ret
30909 CFI_ENDPROC
30910 ENDPROC(call_rwsem_wake)
30911
30912 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30913 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30914 CFI_RESTORE __ASM_REG(dx)
30915 restore_common_regs
30916 + pax_force_retaddr
30917 ret
30918 CFI_ENDPROC
30919 ENDPROC(call_rwsem_downgrade_wake)
30920 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30921 index a63efd6..8149fbe 100644
30922 --- a/arch/x86/lib/thunk_64.S
30923 +++ b/arch/x86/lib/thunk_64.S
30924 @@ -8,6 +8,7 @@
30925 #include <linux/linkage.h>
30926 #include <asm/dwarf2.h>
30927 #include <asm/calling.h>
30928 +#include <asm/alternative-asm.h>
30929
30930 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30931 .macro THUNK name, func, put_ret_addr_in_rdi=0
30932 @@ -15,11 +16,11 @@
30933 \name:
30934 CFI_STARTPROC
30935
30936 - /* this one pushes 9 elems, the next one would be %rIP */
30937 - SAVE_ARGS
30938 + /* this one pushes 15+1 elems, the next one would be %rIP */
30939 + SAVE_ARGS 8
30940
30941 .if \put_ret_addr_in_rdi
30942 - movq_cfi_restore 9*8, rdi
30943 + movq_cfi_restore RIP, rdi
30944 .endif
30945
30946 call \func
30947 @@ -38,8 +39,9 @@
30948
30949 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30950 CFI_STARTPROC
30951 - SAVE_ARGS
30952 + SAVE_ARGS 8
30953 restore:
30954 - RESTORE_ARGS
30955 + RESTORE_ARGS 1,8
30956 + pax_force_retaddr
30957 ret
30958 CFI_ENDPROC
30959 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30960 index e2f5e21..4b22130 100644
30961 --- a/arch/x86/lib/usercopy_32.c
30962 +++ b/arch/x86/lib/usercopy_32.c
30963 @@ -42,11 +42,13 @@ do { \
30964 int __d0; \
30965 might_fault(); \
30966 __asm__ __volatile__( \
30967 + __COPYUSER_SET_ES \
30968 ASM_STAC "\n" \
30969 "0: rep; stosl\n" \
30970 " movl %2,%0\n" \
30971 "1: rep; stosb\n" \
30972 "2: " ASM_CLAC "\n" \
30973 + __COPYUSER_RESTORE_ES \
30974 ".section .fixup,\"ax\"\n" \
30975 "3: lea 0(%2,%0,4),%0\n" \
30976 " jmp 2b\n" \
30977 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30978
30979 #ifdef CONFIG_X86_INTEL_USERCOPY
30980 static unsigned long
30981 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30982 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30983 {
30984 int d0, d1;
30985 __asm__ __volatile__(
30986 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30987 " .align 2,0x90\n"
30988 "3: movl 0(%4), %%eax\n"
30989 "4: movl 4(%4), %%edx\n"
30990 - "5: movl %%eax, 0(%3)\n"
30991 - "6: movl %%edx, 4(%3)\n"
30992 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30993 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30994 "7: movl 8(%4), %%eax\n"
30995 "8: movl 12(%4),%%edx\n"
30996 - "9: movl %%eax, 8(%3)\n"
30997 - "10: movl %%edx, 12(%3)\n"
30998 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30999 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31000 "11: movl 16(%4), %%eax\n"
31001 "12: movl 20(%4), %%edx\n"
31002 - "13: movl %%eax, 16(%3)\n"
31003 - "14: movl %%edx, 20(%3)\n"
31004 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31005 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31006 "15: movl 24(%4), %%eax\n"
31007 "16: movl 28(%4), %%edx\n"
31008 - "17: movl %%eax, 24(%3)\n"
31009 - "18: movl %%edx, 28(%3)\n"
31010 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31011 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31012 "19: movl 32(%4), %%eax\n"
31013 "20: movl 36(%4), %%edx\n"
31014 - "21: movl %%eax, 32(%3)\n"
31015 - "22: movl %%edx, 36(%3)\n"
31016 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31017 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31018 "23: movl 40(%4), %%eax\n"
31019 "24: movl 44(%4), %%edx\n"
31020 - "25: movl %%eax, 40(%3)\n"
31021 - "26: movl %%edx, 44(%3)\n"
31022 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31023 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31024 "27: movl 48(%4), %%eax\n"
31025 "28: movl 52(%4), %%edx\n"
31026 - "29: movl %%eax, 48(%3)\n"
31027 - "30: movl %%edx, 52(%3)\n"
31028 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31029 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31030 "31: movl 56(%4), %%eax\n"
31031 "32: movl 60(%4), %%edx\n"
31032 - "33: movl %%eax, 56(%3)\n"
31033 - "34: movl %%edx, 60(%3)\n"
31034 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31035 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31036 " addl $-64, %0\n"
31037 " addl $64, %4\n"
31038 " addl $64, %3\n"
31039 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31040 " shrl $2, %0\n"
31041 " andl $3, %%eax\n"
31042 " cld\n"
31043 + __COPYUSER_SET_ES
31044 "99: rep; movsl\n"
31045 "36: movl %%eax, %0\n"
31046 "37: rep; movsb\n"
31047 "100:\n"
31048 + __COPYUSER_RESTORE_ES
31049 + ".section .fixup,\"ax\"\n"
31050 + "101: lea 0(%%eax,%0,4),%0\n"
31051 + " jmp 100b\n"
31052 + ".previous\n"
31053 + _ASM_EXTABLE(1b,100b)
31054 + _ASM_EXTABLE(2b,100b)
31055 + _ASM_EXTABLE(3b,100b)
31056 + _ASM_EXTABLE(4b,100b)
31057 + _ASM_EXTABLE(5b,100b)
31058 + _ASM_EXTABLE(6b,100b)
31059 + _ASM_EXTABLE(7b,100b)
31060 + _ASM_EXTABLE(8b,100b)
31061 + _ASM_EXTABLE(9b,100b)
31062 + _ASM_EXTABLE(10b,100b)
31063 + _ASM_EXTABLE(11b,100b)
31064 + _ASM_EXTABLE(12b,100b)
31065 + _ASM_EXTABLE(13b,100b)
31066 + _ASM_EXTABLE(14b,100b)
31067 + _ASM_EXTABLE(15b,100b)
31068 + _ASM_EXTABLE(16b,100b)
31069 + _ASM_EXTABLE(17b,100b)
31070 + _ASM_EXTABLE(18b,100b)
31071 + _ASM_EXTABLE(19b,100b)
31072 + _ASM_EXTABLE(20b,100b)
31073 + _ASM_EXTABLE(21b,100b)
31074 + _ASM_EXTABLE(22b,100b)
31075 + _ASM_EXTABLE(23b,100b)
31076 + _ASM_EXTABLE(24b,100b)
31077 + _ASM_EXTABLE(25b,100b)
31078 + _ASM_EXTABLE(26b,100b)
31079 + _ASM_EXTABLE(27b,100b)
31080 + _ASM_EXTABLE(28b,100b)
31081 + _ASM_EXTABLE(29b,100b)
31082 + _ASM_EXTABLE(30b,100b)
31083 + _ASM_EXTABLE(31b,100b)
31084 + _ASM_EXTABLE(32b,100b)
31085 + _ASM_EXTABLE(33b,100b)
31086 + _ASM_EXTABLE(34b,100b)
31087 + _ASM_EXTABLE(35b,100b)
31088 + _ASM_EXTABLE(36b,100b)
31089 + _ASM_EXTABLE(37b,100b)
31090 + _ASM_EXTABLE(99b,101b)
31091 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
31092 + : "1"(to), "2"(from), "0"(size)
31093 + : "eax", "edx", "memory");
31094 + return size;
31095 +}
31096 +
31097 +static unsigned long
31098 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31099 +{
31100 + int d0, d1;
31101 + __asm__ __volatile__(
31102 + " .align 2,0x90\n"
31103 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31104 + " cmpl $67, %0\n"
31105 + " jbe 3f\n"
31106 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31107 + " .align 2,0x90\n"
31108 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31109 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31110 + "5: movl %%eax, 0(%3)\n"
31111 + "6: movl %%edx, 4(%3)\n"
31112 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31113 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31114 + "9: movl %%eax, 8(%3)\n"
31115 + "10: movl %%edx, 12(%3)\n"
31116 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31117 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31118 + "13: movl %%eax, 16(%3)\n"
31119 + "14: movl %%edx, 20(%3)\n"
31120 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31121 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31122 + "17: movl %%eax, 24(%3)\n"
31123 + "18: movl %%edx, 28(%3)\n"
31124 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31125 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31126 + "21: movl %%eax, 32(%3)\n"
31127 + "22: movl %%edx, 36(%3)\n"
31128 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31129 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31130 + "25: movl %%eax, 40(%3)\n"
31131 + "26: movl %%edx, 44(%3)\n"
31132 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31133 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31134 + "29: movl %%eax, 48(%3)\n"
31135 + "30: movl %%edx, 52(%3)\n"
31136 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31137 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31138 + "33: movl %%eax, 56(%3)\n"
31139 + "34: movl %%edx, 60(%3)\n"
31140 + " addl $-64, %0\n"
31141 + " addl $64, %4\n"
31142 + " addl $64, %3\n"
31143 + " cmpl $63, %0\n"
31144 + " ja 1b\n"
31145 + "35: movl %0, %%eax\n"
31146 + " shrl $2, %0\n"
31147 + " andl $3, %%eax\n"
31148 + " cld\n"
31149 + "99: rep; "__copyuser_seg" movsl\n"
31150 + "36: movl %%eax, %0\n"
31151 + "37: rep; "__copyuser_seg" movsb\n"
31152 + "100:\n"
31153 ".section .fixup,\"ax\"\n"
31154 "101: lea 0(%%eax,%0,4),%0\n"
31155 " jmp 100b\n"
31156 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31157 int d0, d1;
31158 __asm__ __volatile__(
31159 " .align 2,0x90\n"
31160 - "0: movl 32(%4), %%eax\n"
31161 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31162 " cmpl $67, %0\n"
31163 " jbe 2f\n"
31164 - "1: movl 64(%4), %%eax\n"
31165 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31166 " .align 2,0x90\n"
31167 - "2: movl 0(%4), %%eax\n"
31168 - "21: movl 4(%4), %%edx\n"
31169 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31170 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31171 " movl %%eax, 0(%3)\n"
31172 " movl %%edx, 4(%3)\n"
31173 - "3: movl 8(%4), %%eax\n"
31174 - "31: movl 12(%4),%%edx\n"
31175 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31176 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31177 " movl %%eax, 8(%3)\n"
31178 " movl %%edx, 12(%3)\n"
31179 - "4: movl 16(%4), %%eax\n"
31180 - "41: movl 20(%4), %%edx\n"
31181 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31182 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31183 " movl %%eax, 16(%3)\n"
31184 " movl %%edx, 20(%3)\n"
31185 - "10: movl 24(%4), %%eax\n"
31186 - "51: movl 28(%4), %%edx\n"
31187 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31188 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31189 " movl %%eax, 24(%3)\n"
31190 " movl %%edx, 28(%3)\n"
31191 - "11: movl 32(%4), %%eax\n"
31192 - "61: movl 36(%4), %%edx\n"
31193 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31194 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31195 " movl %%eax, 32(%3)\n"
31196 " movl %%edx, 36(%3)\n"
31197 - "12: movl 40(%4), %%eax\n"
31198 - "71: movl 44(%4), %%edx\n"
31199 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31200 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31201 " movl %%eax, 40(%3)\n"
31202 " movl %%edx, 44(%3)\n"
31203 - "13: movl 48(%4), %%eax\n"
31204 - "81: movl 52(%4), %%edx\n"
31205 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31206 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31207 " movl %%eax, 48(%3)\n"
31208 " movl %%edx, 52(%3)\n"
31209 - "14: movl 56(%4), %%eax\n"
31210 - "91: movl 60(%4), %%edx\n"
31211 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31212 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31213 " movl %%eax, 56(%3)\n"
31214 " movl %%edx, 60(%3)\n"
31215 " addl $-64, %0\n"
31216 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31217 " shrl $2, %0\n"
31218 " andl $3, %%eax\n"
31219 " cld\n"
31220 - "6: rep; movsl\n"
31221 + "6: rep; "__copyuser_seg" movsl\n"
31222 " movl %%eax,%0\n"
31223 - "7: rep; movsb\n"
31224 + "7: rep; "__copyuser_seg" movsb\n"
31225 "8:\n"
31226 ".section .fixup,\"ax\"\n"
31227 "9: lea 0(%%eax,%0,4),%0\n"
31228 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31229
31230 __asm__ __volatile__(
31231 " .align 2,0x90\n"
31232 - "0: movl 32(%4), %%eax\n"
31233 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31234 " cmpl $67, %0\n"
31235 " jbe 2f\n"
31236 - "1: movl 64(%4), %%eax\n"
31237 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31238 " .align 2,0x90\n"
31239 - "2: movl 0(%4), %%eax\n"
31240 - "21: movl 4(%4), %%edx\n"
31241 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31242 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31243 " movnti %%eax, 0(%3)\n"
31244 " movnti %%edx, 4(%3)\n"
31245 - "3: movl 8(%4), %%eax\n"
31246 - "31: movl 12(%4),%%edx\n"
31247 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31248 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31249 " movnti %%eax, 8(%3)\n"
31250 " movnti %%edx, 12(%3)\n"
31251 - "4: movl 16(%4), %%eax\n"
31252 - "41: movl 20(%4), %%edx\n"
31253 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31254 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31255 " movnti %%eax, 16(%3)\n"
31256 " movnti %%edx, 20(%3)\n"
31257 - "10: movl 24(%4), %%eax\n"
31258 - "51: movl 28(%4), %%edx\n"
31259 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31260 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31261 " movnti %%eax, 24(%3)\n"
31262 " movnti %%edx, 28(%3)\n"
31263 - "11: movl 32(%4), %%eax\n"
31264 - "61: movl 36(%4), %%edx\n"
31265 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31266 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31267 " movnti %%eax, 32(%3)\n"
31268 " movnti %%edx, 36(%3)\n"
31269 - "12: movl 40(%4), %%eax\n"
31270 - "71: movl 44(%4), %%edx\n"
31271 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31272 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31273 " movnti %%eax, 40(%3)\n"
31274 " movnti %%edx, 44(%3)\n"
31275 - "13: movl 48(%4), %%eax\n"
31276 - "81: movl 52(%4), %%edx\n"
31277 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31278 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31279 " movnti %%eax, 48(%3)\n"
31280 " movnti %%edx, 52(%3)\n"
31281 - "14: movl 56(%4), %%eax\n"
31282 - "91: movl 60(%4), %%edx\n"
31283 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31284 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31285 " movnti %%eax, 56(%3)\n"
31286 " movnti %%edx, 60(%3)\n"
31287 " addl $-64, %0\n"
31288 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31289 " shrl $2, %0\n"
31290 " andl $3, %%eax\n"
31291 " cld\n"
31292 - "6: rep; movsl\n"
31293 + "6: rep; "__copyuser_seg" movsl\n"
31294 " movl %%eax,%0\n"
31295 - "7: rep; movsb\n"
31296 + "7: rep; "__copyuser_seg" movsb\n"
31297 "8:\n"
31298 ".section .fixup,\"ax\"\n"
31299 "9: lea 0(%%eax,%0,4),%0\n"
31300 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31301
31302 __asm__ __volatile__(
31303 " .align 2,0x90\n"
31304 - "0: movl 32(%4), %%eax\n"
31305 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31306 " cmpl $67, %0\n"
31307 " jbe 2f\n"
31308 - "1: movl 64(%4), %%eax\n"
31309 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31310 " .align 2,0x90\n"
31311 - "2: movl 0(%4), %%eax\n"
31312 - "21: movl 4(%4), %%edx\n"
31313 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31314 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31315 " movnti %%eax, 0(%3)\n"
31316 " movnti %%edx, 4(%3)\n"
31317 - "3: movl 8(%4), %%eax\n"
31318 - "31: movl 12(%4),%%edx\n"
31319 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31320 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31321 " movnti %%eax, 8(%3)\n"
31322 " movnti %%edx, 12(%3)\n"
31323 - "4: movl 16(%4), %%eax\n"
31324 - "41: movl 20(%4), %%edx\n"
31325 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31326 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31327 " movnti %%eax, 16(%3)\n"
31328 " movnti %%edx, 20(%3)\n"
31329 - "10: movl 24(%4), %%eax\n"
31330 - "51: movl 28(%4), %%edx\n"
31331 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31332 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31333 " movnti %%eax, 24(%3)\n"
31334 " movnti %%edx, 28(%3)\n"
31335 - "11: movl 32(%4), %%eax\n"
31336 - "61: movl 36(%4), %%edx\n"
31337 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31338 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31339 " movnti %%eax, 32(%3)\n"
31340 " movnti %%edx, 36(%3)\n"
31341 - "12: movl 40(%4), %%eax\n"
31342 - "71: movl 44(%4), %%edx\n"
31343 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31344 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31345 " movnti %%eax, 40(%3)\n"
31346 " movnti %%edx, 44(%3)\n"
31347 - "13: movl 48(%4), %%eax\n"
31348 - "81: movl 52(%4), %%edx\n"
31349 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31350 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31351 " movnti %%eax, 48(%3)\n"
31352 " movnti %%edx, 52(%3)\n"
31353 - "14: movl 56(%4), %%eax\n"
31354 - "91: movl 60(%4), %%edx\n"
31355 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31356 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31357 " movnti %%eax, 56(%3)\n"
31358 " movnti %%edx, 60(%3)\n"
31359 " addl $-64, %0\n"
31360 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31361 " shrl $2, %0\n"
31362 " andl $3, %%eax\n"
31363 " cld\n"
31364 - "6: rep; movsl\n"
31365 + "6: rep; "__copyuser_seg" movsl\n"
31366 " movl %%eax,%0\n"
31367 - "7: rep; movsb\n"
31368 + "7: rep; "__copyuser_seg" movsb\n"
31369 "8:\n"
31370 ".section .fixup,\"ax\"\n"
31371 "9: lea 0(%%eax,%0,4),%0\n"
31372 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31373 */
31374 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31375 unsigned long size);
31376 -unsigned long __copy_user_intel(void __user *to, const void *from,
31377 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31378 + unsigned long size);
31379 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31380 unsigned long size);
31381 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31382 const void __user *from, unsigned long size);
31383 #endif /* CONFIG_X86_INTEL_USERCOPY */
31384
31385 /* Generic arbitrary sized copy. */
31386 -#define __copy_user(to, from, size) \
31387 +#define __copy_user(to, from, size, prefix, set, restore) \
31388 do { \
31389 int __d0, __d1, __d2; \
31390 __asm__ __volatile__( \
31391 + set \
31392 " cmp $7,%0\n" \
31393 " jbe 1f\n" \
31394 " movl %1,%0\n" \
31395 " negl %0\n" \
31396 " andl $7,%0\n" \
31397 " subl %0,%3\n" \
31398 - "4: rep; movsb\n" \
31399 + "4: rep; "prefix"movsb\n" \
31400 " movl %3,%0\n" \
31401 " shrl $2,%0\n" \
31402 " andl $3,%3\n" \
31403 " .align 2,0x90\n" \
31404 - "0: rep; movsl\n" \
31405 + "0: rep; "prefix"movsl\n" \
31406 " movl %3,%0\n" \
31407 - "1: rep; movsb\n" \
31408 + "1: rep; "prefix"movsb\n" \
31409 "2:\n" \
31410 + restore \
31411 ".section .fixup,\"ax\"\n" \
31412 "5: addl %3,%0\n" \
31413 " jmp 2b\n" \
31414 @@ -538,14 +650,14 @@ do { \
31415 " negl %0\n" \
31416 " andl $7,%0\n" \
31417 " subl %0,%3\n" \
31418 - "4: rep; movsb\n" \
31419 + "4: rep; "__copyuser_seg"movsb\n" \
31420 " movl %3,%0\n" \
31421 " shrl $2,%0\n" \
31422 " andl $3,%3\n" \
31423 " .align 2,0x90\n" \
31424 - "0: rep; movsl\n" \
31425 + "0: rep; "__copyuser_seg"movsl\n" \
31426 " movl %3,%0\n" \
31427 - "1: rep; movsb\n" \
31428 + "1: rep; "__copyuser_seg"movsb\n" \
31429 "2:\n" \
31430 ".section .fixup,\"ax\"\n" \
31431 "5: addl %3,%0\n" \
31432 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31433 {
31434 stac();
31435 if (movsl_is_ok(to, from, n))
31436 - __copy_user(to, from, n);
31437 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31438 else
31439 - n = __copy_user_intel(to, from, n);
31440 + n = __generic_copy_to_user_intel(to, from, n);
31441 clac();
31442 return n;
31443 }
31444 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31445 {
31446 stac();
31447 if (movsl_is_ok(to, from, n))
31448 - __copy_user(to, from, n);
31449 + __copy_user(to, from, n, __copyuser_seg, "", "");
31450 else
31451 - n = __copy_user_intel((void __user *)to,
31452 - (const void *)from, n);
31453 + n = __generic_copy_from_user_intel(to, from, n);
31454 clac();
31455 return n;
31456 }
31457 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31458 if (n > 64 && cpu_has_xmm2)
31459 n = __copy_user_intel_nocache(to, from, n);
31460 else
31461 - __copy_user(to, from, n);
31462 + __copy_user(to, from, n, __copyuser_seg, "", "");
31463 #else
31464 - __copy_user(to, from, n);
31465 + __copy_user(to, from, n, __copyuser_seg, "", "");
31466 #endif
31467 clac();
31468 return n;
31469 }
31470 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31471
31472 -/**
31473 - * copy_to_user: - Copy a block of data into user space.
31474 - * @to: Destination address, in user space.
31475 - * @from: Source address, in kernel space.
31476 - * @n: Number of bytes to copy.
31477 - *
31478 - * Context: User context only. This function may sleep.
31479 - *
31480 - * Copy data from kernel space to user space.
31481 - *
31482 - * Returns number of bytes that could not be copied.
31483 - * On success, this will be zero.
31484 - */
31485 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31486 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31487 +void __set_fs(mm_segment_t x)
31488 {
31489 - if (access_ok(VERIFY_WRITE, to, n))
31490 - n = __copy_to_user(to, from, n);
31491 - return n;
31492 + switch (x.seg) {
31493 + case 0:
31494 + loadsegment(gs, 0);
31495 + break;
31496 + case TASK_SIZE_MAX:
31497 + loadsegment(gs, __USER_DS);
31498 + break;
31499 + case -1UL:
31500 + loadsegment(gs, __KERNEL_DS);
31501 + break;
31502 + default:
31503 + BUG();
31504 + }
31505 }
31506 -EXPORT_SYMBOL(_copy_to_user);
31507 +EXPORT_SYMBOL(__set_fs);
31508
31509 -/**
31510 - * copy_from_user: - Copy a block of data from user space.
31511 - * @to: Destination address, in kernel space.
31512 - * @from: Source address, in user space.
31513 - * @n: Number of bytes to copy.
31514 - *
31515 - * Context: User context only. This function may sleep.
31516 - *
31517 - * Copy data from user space to kernel space.
31518 - *
31519 - * Returns number of bytes that could not be copied.
31520 - * On success, this will be zero.
31521 - *
31522 - * If some data could not be copied, this function will pad the copied
31523 - * data to the requested size using zero bytes.
31524 - */
31525 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31526 +void set_fs(mm_segment_t x)
31527 {
31528 - if (access_ok(VERIFY_READ, from, n))
31529 - n = __copy_from_user(to, from, n);
31530 - else
31531 - memset(to, 0, n);
31532 - return n;
31533 + current_thread_info()->addr_limit = x;
31534 + __set_fs(x);
31535 }
31536 -EXPORT_SYMBOL(_copy_from_user);
31537 +EXPORT_SYMBOL(set_fs);
31538 +#endif
31539 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31540 index c905e89..01ab928 100644
31541 --- a/arch/x86/lib/usercopy_64.c
31542 +++ b/arch/x86/lib/usercopy_64.c
31543 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31544 might_fault();
31545 /* no memory constraint because it doesn't change any memory gcc knows
31546 about */
31547 + pax_open_userland();
31548 stac();
31549 asm volatile(
31550 " testq %[size8],%[size8]\n"
31551 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31552 _ASM_EXTABLE(0b,3b)
31553 _ASM_EXTABLE(1b,2b)
31554 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31555 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31556 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31557 [zero] "r" (0UL), [eight] "r" (8UL));
31558 clac();
31559 + pax_close_userland();
31560 return size;
31561 }
31562 EXPORT_SYMBOL(__clear_user);
31563 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31564 }
31565 EXPORT_SYMBOL(clear_user);
31566
31567 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31568 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31569 {
31570 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31571 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31572 - }
31573 - return len;
31574 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31575 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31576 + return len;
31577 }
31578 EXPORT_SYMBOL(copy_in_user);
31579
31580 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31581 * it is not necessary to optimize tail handling.
31582 */
31583 __visible unsigned long
31584 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31585 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31586 {
31587 char c;
31588 unsigned zero_len;
31589
31590 + clac();
31591 + pax_close_userland();
31592 for (; len; --len, to++) {
31593 if (__get_user_nocheck(c, from++, sizeof(char)))
31594 break;
31595 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31596 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31597 if (__put_user_nocheck(c, to++, sizeof(char)))
31598 break;
31599 - clac();
31600 return len;
31601 }
31602 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31603 index 6a19ad9..1c48f9a 100644
31604 --- a/arch/x86/mm/Makefile
31605 +++ b/arch/x86/mm/Makefile
31606 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31607 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31608
31609 obj-$(CONFIG_MEMTEST) += memtest.o
31610 +
31611 +quote:="
31612 +obj-$(CONFIG_X86_64) += uderef_64.o
31613 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31614 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31615 index 903ec1e..c4166b2 100644
31616 --- a/arch/x86/mm/extable.c
31617 +++ b/arch/x86/mm/extable.c
31618 @@ -6,12 +6,24 @@
31619 static inline unsigned long
31620 ex_insn_addr(const struct exception_table_entry *x)
31621 {
31622 - return (unsigned long)&x->insn + x->insn;
31623 + unsigned long reloc = 0;
31624 +
31625 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31626 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31627 +#endif
31628 +
31629 + return (unsigned long)&x->insn + x->insn + reloc;
31630 }
31631 static inline unsigned long
31632 ex_fixup_addr(const struct exception_table_entry *x)
31633 {
31634 - return (unsigned long)&x->fixup + x->fixup;
31635 + unsigned long reloc = 0;
31636 +
31637 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31638 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31639 +#endif
31640 +
31641 + return (unsigned long)&x->fixup + x->fixup + reloc;
31642 }
31643
31644 int fixup_exception(struct pt_regs *regs)
31645 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31646 unsigned long new_ip;
31647
31648 #ifdef CONFIG_PNPBIOS
31649 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31650 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31651 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31652 extern u32 pnp_bios_is_utter_crap;
31653 pnp_bios_is_utter_crap = 1;
31654 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31655 i += 4;
31656 p->fixup -= i;
31657 i += 4;
31658 +
31659 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31660 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31661 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31662 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31663 +#endif
31664 +
31665 }
31666 }
31667
31668 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31669 index a10c8c7..35a5abb 100644
31670 --- a/arch/x86/mm/fault.c
31671 +++ b/arch/x86/mm/fault.c
31672 @@ -14,11 +14,18 @@
31673 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31674 #include <linux/prefetch.h> /* prefetchw */
31675 #include <linux/context_tracking.h> /* exception_enter(), ... */
31676 +#include <linux/unistd.h>
31677 +#include <linux/compiler.h>
31678
31679 #include <asm/traps.h> /* dotraplinkage, ... */
31680 #include <asm/pgalloc.h> /* pgd_*(), ... */
31681 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31682 #include <asm/fixmap.h> /* VSYSCALL_START */
31683 +#include <asm/tlbflush.h>
31684 +
31685 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31686 +#include <asm/stacktrace.h>
31687 +#endif
31688
31689 #define CREATE_TRACE_POINTS
31690 #include <asm/trace/exceptions.h>
31691 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31692 int ret = 0;
31693
31694 /* kprobe_running() needs smp_processor_id() */
31695 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31696 + if (kprobes_built_in() && !user_mode(regs)) {
31697 preempt_disable();
31698 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31699 ret = 1;
31700 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31701 return !instr_lo || (instr_lo>>1) == 1;
31702 case 0x00:
31703 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31704 - if (probe_kernel_address(instr, opcode))
31705 + if (user_mode(regs)) {
31706 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31707 + return 0;
31708 + } else if (probe_kernel_address(instr, opcode))
31709 return 0;
31710
31711 *prefetch = (instr_lo == 0xF) &&
31712 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31713 while (instr < max_instr) {
31714 unsigned char opcode;
31715
31716 - if (probe_kernel_address(instr, opcode))
31717 + if (user_mode(regs)) {
31718 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31719 + break;
31720 + } else if (probe_kernel_address(instr, opcode))
31721 break;
31722
31723 instr++;
31724 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31725 force_sig_info(si_signo, &info, tsk);
31726 }
31727
31728 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31729 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31730 +#endif
31731 +
31732 +#ifdef CONFIG_PAX_EMUTRAMP
31733 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31734 +#endif
31735 +
31736 +#ifdef CONFIG_PAX_PAGEEXEC
31737 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31738 +{
31739 + pgd_t *pgd;
31740 + pud_t *pud;
31741 + pmd_t *pmd;
31742 +
31743 + pgd = pgd_offset(mm, address);
31744 + if (!pgd_present(*pgd))
31745 + return NULL;
31746 + pud = pud_offset(pgd, address);
31747 + if (!pud_present(*pud))
31748 + return NULL;
31749 + pmd = pmd_offset(pud, address);
31750 + if (!pmd_present(*pmd))
31751 + return NULL;
31752 + return pmd;
31753 +}
31754 +#endif
31755 +
31756 DEFINE_SPINLOCK(pgd_lock);
31757 LIST_HEAD(pgd_list);
31758
31759 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31760 for (address = VMALLOC_START & PMD_MASK;
31761 address >= TASK_SIZE && address < FIXADDR_TOP;
31762 address += PMD_SIZE) {
31763 +
31764 +#ifdef CONFIG_PAX_PER_CPU_PGD
31765 + unsigned long cpu;
31766 +#else
31767 struct page *page;
31768 +#endif
31769
31770 spin_lock(&pgd_lock);
31771 +
31772 +#ifdef CONFIG_PAX_PER_CPU_PGD
31773 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31774 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31775 + pmd_t *ret;
31776 +
31777 + ret = vmalloc_sync_one(pgd, address);
31778 + if (!ret)
31779 + break;
31780 + pgd = get_cpu_pgd(cpu, kernel);
31781 +#else
31782 list_for_each_entry(page, &pgd_list, lru) {
31783 + pgd_t *pgd;
31784 spinlock_t *pgt_lock;
31785 pmd_t *ret;
31786
31787 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31788 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31789
31790 spin_lock(pgt_lock);
31791 - ret = vmalloc_sync_one(page_address(page), address);
31792 + pgd = page_address(page);
31793 +#endif
31794 +
31795 + ret = vmalloc_sync_one(pgd, address);
31796 +
31797 +#ifndef CONFIG_PAX_PER_CPU_PGD
31798 spin_unlock(pgt_lock);
31799 +#endif
31800
31801 if (!ret)
31802 break;
31803 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31804 * an interrupt in the middle of a task switch..
31805 */
31806 pgd_paddr = read_cr3();
31807 +
31808 +#ifdef CONFIG_PAX_PER_CPU_PGD
31809 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31810 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31811 +#endif
31812 +
31813 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31814 if (!pmd_k)
31815 return -1;
31816 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31817 * happen within a race in page table update. In the later
31818 * case just flush:
31819 */
31820 - pgd = pgd_offset(current->active_mm, address);
31821 +
31822 pgd_ref = pgd_offset_k(address);
31823 if (pgd_none(*pgd_ref))
31824 return -1;
31825
31826 +#ifdef CONFIG_PAX_PER_CPU_PGD
31827 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31828 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31829 + if (pgd_none(*pgd)) {
31830 + set_pgd(pgd, *pgd_ref);
31831 + arch_flush_lazy_mmu_mode();
31832 + } else {
31833 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31834 + }
31835 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31836 +#else
31837 + pgd = pgd_offset(current->active_mm, address);
31838 +#endif
31839 +
31840 if (pgd_none(*pgd)) {
31841 set_pgd(pgd, *pgd_ref);
31842 arch_flush_lazy_mmu_mode();
31843 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31844 static int is_errata100(struct pt_regs *regs, unsigned long address)
31845 {
31846 #ifdef CONFIG_X86_64
31847 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31848 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31849 return 1;
31850 #endif
31851 return 0;
31852 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31853 }
31854
31855 static const char nx_warning[] = KERN_CRIT
31856 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31857 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31858
31859 static void
31860 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31861 @@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31862 if (!oops_may_print())
31863 return;
31864
31865 - if (error_code & PF_INSTR) {
31866 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31867 unsigned int level;
31868
31869 pte_t *pte = lookup_address(address, &level);
31870
31871 if (pte && pte_present(*pte) && !pte_exec(*pte))
31872 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31873 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31874 }
31875
31876 +#ifdef CONFIG_PAX_KERNEXEC
31877 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31878 + if (current->signal->curr_ip)
31879 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31880 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31881 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31882 + else
31883 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31884 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31885 + }
31886 +#endif
31887 +
31888 printk(KERN_ALERT "BUG: unable to handle kernel ");
31889 if (address < PAGE_SIZE)
31890 printk(KERN_CONT "NULL pointer dereference");
31891 @@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31892 return;
31893 }
31894 #endif
31895 +
31896 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31897 + if (pax_is_fetch_fault(regs, error_code, address)) {
31898 +
31899 +#ifdef CONFIG_PAX_EMUTRAMP
31900 + switch (pax_handle_fetch_fault(regs)) {
31901 + case 2:
31902 + return;
31903 + }
31904 +#endif
31905 +
31906 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31907 + do_group_exit(SIGKILL);
31908 + }
31909 +#endif
31910 +
31911 /* Kernel addresses are always protection faults: */
31912 if (address >= TASK_SIZE)
31913 error_code |= PF_PROT;
31914 @@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31915 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31916 printk(KERN_ERR
31917 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31918 - tsk->comm, tsk->pid, address);
31919 + tsk->comm, task_pid_nr(tsk), address);
31920 code = BUS_MCEERR_AR;
31921 }
31922 #endif
31923 @@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31924 return 1;
31925 }
31926
31927 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31928 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31929 +{
31930 + pte_t *pte;
31931 + pmd_t *pmd;
31932 + spinlock_t *ptl;
31933 + unsigned char pte_mask;
31934 +
31935 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31936 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31937 + return 0;
31938 +
31939 + /* PaX: it's our fault, let's handle it if we can */
31940 +
31941 + /* PaX: take a look at read faults before acquiring any locks */
31942 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31943 + /* instruction fetch attempt from a protected page in user mode */
31944 + up_read(&mm->mmap_sem);
31945 +
31946 +#ifdef CONFIG_PAX_EMUTRAMP
31947 + switch (pax_handle_fetch_fault(regs)) {
31948 + case 2:
31949 + return 1;
31950 + }
31951 +#endif
31952 +
31953 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31954 + do_group_exit(SIGKILL);
31955 + }
31956 +
31957 + pmd = pax_get_pmd(mm, address);
31958 + if (unlikely(!pmd))
31959 + return 0;
31960 +
31961 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31962 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31963 + pte_unmap_unlock(pte, ptl);
31964 + return 0;
31965 + }
31966 +
31967 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31968 + /* write attempt to a protected page in user mode */
31969 + pte_unmap_unlock(pte, ptl);
31970 + return 0;
31971 + }
31972 +
31973 +#ifdef CONFIG_SMP
31974 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31975 +#else
31976 + if (likely(address > get_limit(regs->cs)))
31977 +#endif
31978 + {
31979 + set_pte(pte, pte_mkread(*pte));
31980 + __flush_tlb_one(address);
31981 + pte_unmap_unlock(pte, ptl);
31982 + up_read(&mm->mmap_sem);
31983 + return 1;
31984 + }
31985 +
31986 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31987 +
31988 + /*
31989 + * PaX: fill DTLB with user rights and retry
31990 + */
31991 + __asm__ __volatile__ (
31992 + "orb %2,(%1)\n"
31993 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31994 +/*
31995 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31996 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31997 + * page fault when examined during a TLB load attempt. this is true not only
31998 + * for PTEs holding a non-present entry but also present entries that will
31999 + * raise a page fault (such as those set up by PaX, or the copy-on-write
32000 + * mechanism). in effect it means that we do *not* need to flush the TLBs
32001 + * for our target pages since their PTEs are simply not in the TLBs at all.
32002 +
32003 + * the best thing in omitting it is that we gain around 15-20% speed in the
32004 + * fast path of the page fault handler and can get rid of tracing since we
32005 + * can no longer flush unintended entries.
32006 + */
32007 + "invlpg (%0)\n"
32008 +#endif
32009 + __copyuser_seg"testb $0,(%0)\n"
32010 + "xorb %3,(%1)\n"
32011 + :
32012 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32013 + : "memory", "cc");
32014 + pte_unmap_unlock(pte, ptl);
32015 + up_read(&mm->mmap_sem);
32016 + return 1;
32017 +}
32018 +#endif
32019 +
32020 /*
32021 * Handle a spurious fault caused by a stale TLB entry.
32022 *
32023 @@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
32024 static inline int
32025 access_error(unsigned long error_code, struct vm_area_struct *vma)
32026 {
32027 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32028 + return 1;
32029 +
32030 if (error_code & PF_WRITE) {
32031 /* write, present and write, not present: */
32032 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32033 @@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32034 if (error_code & PF_USER)
32035 return false;
32036
32037 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32038 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32039 return false;
32040
32041 return true;
32042 @@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32043 tsk = current;
32044 mm = tsk->mm;
32045
32046 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32047 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32048 + if (!search_exception_tables(regs->ip)) {
32049 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32050 + bad_area_nosemaphore(regs, error_code, address);
32051 + return;
32052 + }
32053 + if (address < pax_user_shadow_base) {
32054 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32055 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32056 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32057 + } else
32058 + address -= pax_user_shadow_base;
32059 + }
32060 +#endif
32061 +
32062 /*
32063 * Detect and handle instructions that would cause a page fault for
32064 * both a tracked kernel page and a userspace page.
32065 @@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32066 * User-mode registers count as a user access even for any
32067 * potential system fault or CPU buglet:
32068 */
32069 - if (user_mode_vm(regs)) {
32070 + if (user_mode(regs)) {
32071 local_irq_enable();
32072 error_code |= PF_USER;
32073 flags |= FAULT_FLAG_USER;
32074 @@ -1162,6 +1386,11 @@ retry:
32075 might_sleep();
32076 }
32077
32078 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32079 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32080 + return;
32081 +#endif
32082 +
32083 vma = find_vma(mm, address);
32084 if (unlikely(!vma)) {
32085 bad_area(regs, error_code, address);
32086 @@ -1173,18 +1402,24 @@ retry:
32087 bad_area(regs, error_code, address);
32088 return;
32089 }
32090 - if (error_code & PF_USER) {
32091 - /*
32092 - * Accessing the stack below %sp is always a bug.
32093 - * The large cushion allows instructions like enter
32094 - * and pusha to work. ("enter $65535, $31" pushes
32095 - * 32 pointers and then decrements %sp by 65535.)
32096 - */
32097 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32098 - bad_area(regs, error_code, address);
32099 - return;
32100 - }
32101 + /*
32102 + * Accessing the stack below %sp is always a bug.
32103 + * The large cushion allows instructions like enter
32104 + * and pusha to work. ("enter $65535, $31" pushes
32105 + * 32 pointers and then decrements %sp by 65535.)
32106 + */
32107 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32108 + bad_area(regs, error_code, address);
32109 + return;
32110 }
32111 +
32112 +#ifdef CONFIG_PAX_SEGMEXEC
32113 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32114 + bad_area(regs, error_code, address);
32115 + return;
32116 + }
32117 +#endif
32118 +
32119 if (unlikely(expand_stack(vma, address))) {
32120 bad_area(regs, error_code, address);
32121 return;
32122 @@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32123 exception_exit(prev_state);
32124 }
32125 #endif /* CONFIG_TRACING */
32126 +
32127 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32128 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32129 +{
32130 + struct mm_struct *mm = current->mm;
32131 + unsigned long ip = regs->ip;
32132 +
32133 + if (v8086_mode(regs))
32134 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32135 +
32136 +#ifdef CONFIG_PAX_PAGEEXEC
32137 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32138 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32139 + return true;
32140 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32141 + return true;
32142 + return false;
32143 + }
32144 +#endif
32145 +
32146 +#ifdef CONFIG_PAX_SEGMEXEC
32147 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32148 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32149 + return true;
32150 + return false;
32151 + }
32152 +#endif
32153 +
32154 + return false;
32155 +}
32156 +#endif
32157 +
32158 +#ifdef CONFIG_PAX_EMUTRAMP
32159 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32160 +{
32161 + int err;
32162 +
32163 + do { /* PaX: libffi trampoline emulation */
32164 + unsigned char mov, jmp;
32165 + unsigned int addr1, addr2;
32166 +
32167 +#ifdef CONFIG_X86_64
32168 + if ((regs->ip + 9) >> 32)
32169 + break;
32170 +#endif
32171 +
32172 + err = get_user(mov, (unsigned char __user *)regs->ip);
32173 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32174 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32175 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32176 +
32177 + if (err)
32178 + break;
32179 +
32180 + if (mov == 0xB8 && jmp == 0xE9) {
32181 + regs->ax = addr1;
32182 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32183 + return 2;
32184 + }
32185 + } while (0);
32186 +
32187 + do { /* PaX: gcc trampoline emulation #1 */
32188 + unsigned char mov1, mov2;
32189 + unsigned short jmp;
32190 + unsigned int addr1, addr2;
32191 +
32192 +#ifdef CONFIG_X86_64
32193 + if ((regs->ip + 11) >> 32)
32194 + break;
32195 +#endif
32196 +
32197 + err = get_user(mov1, (unsigned char __user *)regs->ip);
32198 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32199 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32200 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32201 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32202 +
32203 + if (err)
32204 + break;
32205 +
32206 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32207 + regs->cx = addr1;
32208 + regs->ax = addr2;
32209 + regs->ip = addr2;
32210 + return 2;
32211 + }
32212 + } while (0);
32213 +
32214 + do { /* PaX: gcc trampoline emulation #2 */
32215 + unsigned char mov, jmp;
32216 + unsigned int addr1, addr2;
32217 +
32218 +#ifdef CONFIG_X86_64
32219 + if ((regs->ip + 9) >> 32)
32220 + break;
32221 +#endif
32222 +
32223 + err = get_user(mov, (unsigned char __user *)regs->ip);
32224 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32225 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32226 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32227 +
32228 + if (err)
32229 + break;
32230 +
32231 + if (mov == 0xB9 && jmp == 0xE9) {
32232 + regs->cx = addr1;
32233 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32234 + return 2;
32235 + }
32236 + } while (0);
32237 +
32238 + return 1; /* PaX in action */
32239 +}
32240 +
32241 +#ifdef CONFIG_X86_64
32242 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32243 +{
32244 + int err;
32245 +
32246 + do { /* PaX: libffi trampoline emulation */
32247 + unsigned short mov1, mov2, jmp1;
32248 + unsigned char stcclc, jmp2;
32249 + unsigned long addr1, addr2;
32250 +
32251 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32252 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32253 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32254 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32255 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32256 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32257 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32258 +
32259 + if (err)
32260 + break;
32261 +
32262 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32263 + regs->r11 = addr1;
32264 + regs->r10 = addr2;
32265 + if (stcclc == 0xF8)
32266 + regs->flags &= ~X86_EFLAGS_CF;
32267 + else
32268 + regs->flags |= X86_EFLAGS_CF;
32269 + regs->ip = addr1;
32270 + return 2;
32271 + }
32272 + } while (0);
32273 +
32274 + do { /* PaX: gcc trampoline emulation #1 */
32275 + unsigned short mov1, mov2, jmp1;
32276 + unsigned char jmp2;
32277 + unsigned int addr1;
32278 + unsigned long addr2;
32279 +
32280 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32281 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32282 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32283 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32284 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32285 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32286 +
32287 + if (err)
32288 + break;
32289 +
32290 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32291 + regs->r11 = addr1;
32292 + regs->r10 = addr2;
32293 + regs->ip = addr1;
32294 + return 2;
32295 + }
32296 + } while (0);
32297 +
32298 + do { /* PaX: gcc trampoline emulation #2 */
32299 + unsigned short mov1, mov2, jmp1;
32300 + unsigned char jmp2;
32301 + unsigned long addr1, addr2;
32302 +
32303 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32304 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32305 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32306 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32307 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32308 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32309 +
32310 + if (err)
32311 + break;
32312 +
32313 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32314 + regs->r11 = addr1;
32315 + regs->r10 = addr2;
32316 + regs->ip = addr1;
32317 + return 2;
32318 + }
32319 + } while (0);
32320 +
32321 + return 1; /* PaX in action */
32322 +}
32323 +#endif
32324 +
32325 +/*
32326 + * PaX: decide what to do with offenders (regs->ip = fault address)
32327 + *
32328 + * returns 1 when task should be killed
32329 + * 2 when gcc trampoline was detected
32330 + */
32331 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32332 +{
32333 + if (v8086_mode(regs))
32334 + return 1;
32335 +
32336 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32337 + return 1;
32338 +
32339 +#ifdef CONFIG_X86_32
32340 + return pax_handle_fetch_fault_32(regs);
32341 +#else
32342 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32343 + return pax_handle_fetch_fault_32(regs);
32344 + else
32345 + return pax_handle_fetch_fault_64(regs);
32346 +#endif
32347 +}
32348 +#endif
32349 +
32350 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32351 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32352 +{
32353 + long i;
32354 +
32355 + printk(KERN_ERR "PAX: bytes at PC: ");
32356 + for (i = 0; i < 20; i++) {
32357 + unsigned char c;
32358 + if (get_user(c, (unsigned char __force_user *)pc+i))
32359 + printk(KERN_CONT "?? ");
32360 + else
32361 + printk(KERN_CONT "%02x ", c);
32362 + }
32363 + printk("\n");
32364 +
32365 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32366 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32367 + unsigned long c;
32368 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32369 +#ifdef CONFIG_X86_32
32370 + printk(KERN_CONT "???????? ");
32371 +#else
32372 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32373 + printk(KERN_CONT "???????? ???????? ");
32374 + else
32375 + printk(KERN_CONT "???????????????? ");
32376 +#endif
32377 + } else {
32378 +#ifdef CONFIG_X86_64
32379 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32380 + printk(KERN_CONT "%08x ", (unsigned int)c);
32381 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32382 + } else
32383 +#endif
32384 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32385 + }
32386 + }
32387 + printk("\n");
32388 +}
32389 +#endif
32390 +
32391 +/**
32392 + * probe_kernel_write(): safely attempt to write to a location
32393 + * @dst: address to write to
32394 + * @src: pointer to the data that shall be written
32395 + * @size: size of the data chunk
32396 + *
32397 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32398 + * happens, handle that and return -EFAULT.
32399 + */
32400 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32401 +{
32402 + long ret;
32403 + mm_segment_t old_fs = get_fs();
32404 +
32405 + set_fs(KERNEL_DS);
32406 + pagefault_disable();
32407 + pax_open_kernel();
32408 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32409 + pax_close_kernel();
32410 + pagefault_enable();
32411 + set_fs(old_fs);
32412 +
32413 + return ret ? -EFAULT : 0;
32414 +}
32415 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32416 index 207d9aef..69030980 100644
32417 --- a/arch/x86/mm/gup.c
32418 +++ b/arch/x86/mm/gup.c
32419 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32420 addr = start;
32421 len = (unsigned long) nr_pages << PAGE_SHIFT;
32422 end = start + len;
32423 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32424 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32425 (void __user *)start, len)))
32426 return 0;
32427
32428 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32429 goto slow_irqon;
32430 #endif
32431
32432 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32433 + (void __user *)start, len)))
32434 + return 0;
32435 +
32436 /*
32437 * XXX: batch / limit 'nr', to avoid large irq off latency
32438 * needs some instrumenting to determine the common sizes used by
32439 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32440 index 4500142..53a363c 100644
32441 --- a/arch/x86/mm/highmem_32.c
32442 +++ b/arch/x86/mm/highmem_32.c
32443 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32444 idx = type + KM_TYPE_NR*smp_processor_id();
32445 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32446 BUG_ON(!pte_none(*(kmap_pte-idx)));
32447 +
32448 + pax_open_kernel();
32449 set_pte(kmap_pte-idx, mk_pte(page, prot));
32450 + pax_close_kernel();
32451 +
32452 arch_flush_lazy_mmu_mode();
32453
32454 return (void *)vaddr;
32455 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32456 index 8c9f647..57cb402 100644
32457 --- a/arch/x86/mm/hugetlbpage.c
32458 +++ b/arch/x86/mm/hugetlbpage.c
32459 @@ -90,23 +90,24 @@ int pmd_huge_support(void)
32460 #ifdef CONFIG_HUGETLB_PAGE
32461 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32462 unsigned long addr, unsigned long len,
32463 - unsigned long pgoff, unsigned long flags)
32464 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32465 {
32466 struct hstate *h = hstate_file(file);
32467 struct vm_unmapped_area_info info;
32468 -
32469 +
32470 info.flags = 0;
32471 info.length = len;
32472 info.low_limit = current->mm->mmap_legacy_base;
32473 info.high_limit = TASK_SIZE;
32474 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32475 info.align_offset = 0;
32476 + info.threadstack_offset = offset;
32477 return vm_unmapped_area(&info);
32478 }
32479
32480 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32481 unsigned long addr0, unsigned long len,
32482 - unsigned long pgoff, unsigned long flags)
32483 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32484 {
32485 struct hstate *h = hstate_file(file);
32486 struct vm_unmapped_area_info info;
32487 @@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32488 info.high_limit = current->mm->mmap_base;
32489 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32490 info.align_offset = 0;
32491 + info.threadstack_offset = offset;
32492 addr = vm_unmapped_area(&info);
32493
32494 /*
32495 @@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32496 VM_BUG_ON(addr != -ENOMEM);
32497 info.flags = 0;
32498 info.low_limit = TASK_UNMAPPED_BASE;
32499 +
32500 +#ifdef CONFIG_PAX_RANDMMAP
32501 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32502 + info.low_limit += current->mm->delta_mmap;
32503 +#endif
32504 +
32505 info.high_limit = TASK_SIZE;
32506 addr = vm_unmapped_area(&info);
32507 }
32508 @@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32509 struct hstate *h = hstate_file(file);
32510 struct mm_struct *mm = current->mm;
32511 struct vm_area_struct *vma;
32512 + unsigned long pax_task_size = TASK_SIZE;
32513 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32514
32515 if (len & ~huge_page_mask(h))
32516 return -EINVAL;
32517 - if (len > TASK_SIZE)
32518 +
32519 +#ifdef CONFIG_PAX_SEGMEXEC
32520 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32521 + pax_task_size = SEGMEXEC_TASK_SIZE;
32522 +#endif
32523 +
32524 + pax_task_size -= PAGE_SIZE;
32525 +
32526 + if (len > pax_task_size)
32527 return -ENOMEM;
32528
32529 if (flags & MAP_FIXED) {
32530 @@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32531 return addr;
32532 }
32533
32534 +#ifdef CONFIG_PAX_RANDMMAP
32535 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32536 +#endif
32537 +
32538 if (addr) {
32539 addr = ALIGN(addr, huge_page_size(h));
32540 vma = find_vma(mm, addr);
32541 - if (TASK_SIZE - len >= addr &&
32542 - (!vma || addr + len <= vma->vm_start))
32543 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32544 return addr;
32545 }
32546 if (mm->get_unmapped_area == arch_get_unmapped_area)
32547 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32548 - pgoff, flags);
32549 + pgoff, flags, offset);
32550 else
32551 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32552 - pgoff, flags);
32553 + pgoff, flags, offset);
32554 }
32555 #endif /* CONFIG_HUGETLB_PAGE */
32556
32557 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32558 index f971306..e83e0f6 100644
32559 --- a/arch/x86/mm/init.c
32560 +++ b/arch/x86/mm/init.c
32561 @@ -4,6 +4,7 @@
32562 #include <linux/swap.h>
32563 #include <linux/memblock.h>
32564 #include <linux/bootmem.h> /* for max_low_pfn */
32565 +#include <linux/tboot.h>
32566
32567 #include <asm/cacheflush.h>
32568 #include <asm/e820.h>
32569 @@ -17,6 +18,8 @@
32570 #include <asm/proto.h>
32571 #include <asm/dma.h> /* for MAX_DMA_PFN */
32572 #include <asm/microcode.h>
32573 +#include <asm/desc.h>
32574 +#include <asm/bios_ebda.h>
32575
32576 #include "mm_internal.h"
32577
32578 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32579 early_ioremap_page_table_range_init();
32580 #endif
32581
32582 +#ifdef CONFIG_PAX_PER_CPU_PGD
32583 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32584 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32585 + KERNEL_PGD_PTRS);
32586 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32587 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32588 + KERNEL_PGD_PTRS);
32589 + load_cr3(get_cpu_pgd(0, kernel));
32590 +#else
32591 load_cr3(swapper_pg_dir);
32592 +#endif
32593 +
32594 __flush_tlb_all();
32595
32596 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32597 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32598 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32599 * mmio resources as well as potential bios/acpi data regions.
32600 */
32601 +
32602 +#ifdef CONFIG_GRKERNSEC_KMEM
32603 +static unsigned int ebda_start __read_only;
32604 +static unsigned int ebda_end __read_only;
32605 +#endif
32606 +
32607 int devmem_is_allowed(unsigned long pagenr)
32608 {
32609 - if (pagenr < 256)
32610 +#ifdef CONFIG_GRKERNSEC_KMEM
32611 + /* allow BDA */
32612 + if (!pagenr)
32613 return 1;
32614 + /* allow EBDA */
32615 + if (pagenr >= ebda_start && pagenr < ebda_end)
32616 + return 1;
32617 + /* if tboot is in use, allow access to its hardcoded serial log range */
32618 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32619 + return 1;
32620 +#else
32621 + if (!pagenr)
32622 + return 1;
32623 +#ifdef CONFIG_VM86
32624 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32625 + return 1;
32626 +#endif
32627 +#endif
32628 +
32629 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32630 + return 1;
32631 +#ifdef CONFIG_GRKERNSEC_KMEM
32632 + /* throw out everything else below 1MB */
32633 + if (pagenr <= 256)
32634 + return 0;
32635 +#endif
32636 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32637 return 0;
32638 if (!page_is_ram(pagenr))
32639 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32640 #endif
32641 }
32642
32643 +#ifdef CONFIG_GRKERNSEC_KMEM
32644 +static inline void gr_init_ebda(void)
32645 +{
32646 + unsigned int ebda_addr;
32647 + unsigned int ebda_size = 0;
32648 +
32649 + ebda_addr = get_bios_ebda();
32650 + if (ebda_addr) {
32651 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32652 + ebda_size <<= 10;
32653 + }
32654 + if (ebda_addr && ebda_size) {
32655 + ebda_start = ebda_addr >> PAGE_SHIFT;
32656 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32657 + } else {
32658 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32659 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32660 + }
32661 +}
32662 +#else
32663 +static inline void gr_init_ebda(void) { }
32664 +#endif
32665 +
32666 void free_initmem(void)
32667 {
32668 +#ifdef CONFIG_PAX_KERNEXEC
32669 +#ifdef CONFIG_X86_32
32670 + /* PaX: limit KERNEL_CS to actual size */
32671 + unsigned long addr, limit;
32672 + struct desc_struct d;
32673 + int cpu;
32674 +#else
32675 + pgd_t *pgd;
32676 + pud_t *pud;
32677 + pmd_t *pmd;
32678 + unsigned long addr, end;
32679 +#endif
32680 +#endif
32681 +
32682 + gr_init_ebda();
32683 +
32684 +#ifdef CONFIG_PAX_KERNEXEC
32685 +#ifdef CONFIG_X86_32
32686 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32687 + limit = (limit - 1UL) >> PAGE_SHIFT;
32688 +
32689 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32690 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32691 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32692 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32693 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32694 + }
32695 +
32696 + /* PaX: make KERNEL_CS read-only */
32697 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32698 + if (!paravirt_enabled())
32699 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32700 +/*
32701 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32702 + pgd = pgd_offset_k(addr);
32703 + pud = pud_offset(pgd, addr);
32704 + pmd = pmd_offset(pud, addr);
32705 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32706 + }
32707 +*/
32708 +#ifdef CONFIG_X86_PAE
32709 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32710 +/*
32711 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32712 + pgd = pgd_offset_k(addr);
32713 + pud = pud_offset(pgd, addr);
32714 + pmd = pmd_offset(pud, addr);
32715 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32716 + }
32717 +*/
32718 +#endif
32719 +
32720 +#ifdef CONFIG_MODULES
32721 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32722 +#endif
32723 +
32724 +#else
32725 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32726 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32727 + pgd = pgd_offset_k(addr);
32728 + pud = pud_offset(pgd, addr);
32729 + pmd = pmd_offset(pud, addr);
32730 + if (!pmd_present(*pmd))
32731 + continue;
32732 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32733 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32734 + else
32735 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32736 + }
32737 +
32738 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32739 + end = addr + KERNEL_IMAGE_SIZE;
32740 + for (; addr < end; addr += PMD_SIZE) {
32741 + pgd = pgd_offset_k(addr);
32742 + pud = pud_offset(pgd, addr);
32743 + pmd = pmd_offset(pud, addr);
32744 + if (!pmd_present(*pmd))
32745 + continue;
32746 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32747 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32748 + }
32749 +#endif
32750 +
32751 + flush_tlb_all();
32752 +#endif
32753 +
32754 free_init_pages("unused kernel",
32755 (unsigned long)(&__init_begin),
32756 (unsigned long)(&__init_end));
32757 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32758 index e395048..cd38278 100644
32759 --- a/arch/x86/mm/init_32.c
32760 +++ b/arch/x86/mm/init_32.c
32761 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32762 bool __read_mostly __vmalloc_start_set = false;
32763
32764 /*
32765 - * Creates a middle page table and puts a pointer to it in the
32766 - * given global directory entry. This only returns the gd entry
32767 - * in non-PAE compilation mode, since the middle layer is folded.
32768 - */
32769 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32770 -{
32771 - pud_t *pud;
32772 - pmd_t *pmd_table;
32773 -
32774 -#ifdef CONFIG_X86_PAE
32775 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32776 - pmd_table = (pmd_t *)alloc_low_page();
32777 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32778 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32779 - pud = pud_offset(pgd, 0);
32780 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32781 -
32782 - return pmd_table;
32783 - }
32784 -#endif
32785 - pud = pud_offset(pgd, 0);
32786 - pmd_table = pmd_offset(pud, 0);
32787 -
32788 - return pmd_table;
32789 -}
32790 -
32791 -/*
32792 * Create a page table and place a pointer to it in a middle page
32793 * directory entry:
32794 */
32795 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32796 pte_t *page_table = (pte_t *)alloc_low_page();
32797
32798 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32799 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32800 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32801 +#else
32802 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32803 +#endif
32804 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32805 }
32806
32807 return pte_offset_kernel(pmd, 0);
32808 }
32809
32810 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32811 +{
32812 + pud_t *pud;
32813 + pmd_t *pmd_table;
32814 +
32815 + pud = pud_offset(pgd, 0);
32816 + pmd_table = pmd_offset(pud, 0);
32817 +
32818 + return pmd_table;
32819 +}
32820 +
32821 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32822 {
32823 int pgd_idx = pgd_index(vaddr);
32824 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32825 int pgd_idx, pmd_idx;
32826 unsigned long vaddr;
32827 pgd_t *pgd;
32828 + pud_t *pud;
32829 pmd_t *pmd;
32830 pte_t *pte = NULL;
32831 unsigned long count = page_table_range_init_count(start, end);
32832 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32833 pgd = pgd_base + pgd_idx;
32834
32835 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32836 - pmd = one_md_table_init(pgd);
32837 - pmd = pmd + pmd_index(vaddr);
32838 + pud = pud_offset(pgd, vaddr);
32839 + pmd = pmd_offset(pud, vaddr);
32840 +
32841 +#ifdef CONFIG_X86_PAE
32842 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32843 +#endif
32844 +
32845 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32846 pmd++, pmd_idx++) {
32847 pte = page_table_kmap_check(one_page_table_init(pmd),
32848 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32849 }
32850 }
32851
32852 -static inline int is_kernel_text(unsigned long addr)
32853 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32854 {
32855 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32856 - return 1;
32857 - return 0;
32858 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32859 + end <= ktla_ktva((unsigned long)_stext)) &&
32860 + (start >= ktla_ktva((unsigned long)_einittext) ||
32861 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32862 +
32863 +#ifdef CONFIG_ACPI_SLEEP
32864 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32865 +#endif
32866 +
32867 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32868 + return 0;
32869 + return 1;
32870 }
32871
32872 /*
32873 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32874 unsigned long last_map_addr = end;
32875 unsigned long start_pfn, end_pfn;
32876 pgd_t *pgd_base = swapper_pg_dir;
32877 - int pgd_idx, pmd_idx, pte_ofs;
32878 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32879 unsigned long pfn;
32880 pgd_t *pgd;
32881 + pud_t *pud;
32882 pmd_t *pmd;
32883 pte_t *pte;
32884 unsigned pages_2m, pages_4k;
32885 @@ -291,8 +295,13 @@ repeat:
32886 pfn = start_pfn;
32887 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32888 pgd = pgd_base + pgd_idx;
32889 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32890 - pmd = one_md_table_init(pgd);
32891 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32892 + pud = pud_offset(pgd, 0);
32893 + pmd = pmd_offset(pud, 0);
32894 +
32895 +#ifdef CONFIG_X86_PAE
32896 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32897 +#endif
32898
32899 if (pfn >= end_pfn)
32900 continue;
32901 @@ -304,14 +313,13 @@ repeat:
32902 #endif
32903 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32904 pmd++, pmd_idx++) {
32905 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32906 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32907
32908 /*
32909 * Map with big pages if possible, otherwise
32910 * create normal page tables:
32911 */
32912 if (use_pse) {
32913 - unsigned int addr2;
32914 pgprot_t prot = PAGE_KERNEL_LARGE;
32915 /*
32916 * first pass will use the same initial
32917 @@ -322,11 +330,7 @@ repeat:
32918 _PAGE_PSE);
32919
32920 pfn &= PMD_MASK >> PAGE_SHIFT;
32921 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32922 - PAGE_OFFSET + PAGE_SIZE-1;
32923 -
32924 - if (is_kernel_text(addr) ||
32925 - is_kernel_text(addr2))
32926 + if (is_kernel_text(address, address + PMD_SIZE))
32927 prot = PAGE_KERNEL_LARGE_EXEC;
32928
32929 pages_2m++;
32930 @@ -343,7 +347,7 @@ repeat:
32931 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32932 pte += pte_ofs;
32933 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32934 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32935 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32936 pgprot_t prot = PAGE_KERNEL;
32937 /*
32938 * first pass will use the same initial
32939 @@ -351,7 +355,7 @@ repeat:
32940 */
32941 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32942
32943 - if (is_kernel_text(addr))
32944 + if (is_kernel_text(address, address + PAGE_SIZE))
32945 prot = PAGE_KERNEL_EXEC;
32946
32947 pages_4k++;
32948 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32949
32950 pud = pud_offset(pgd, va);
32951 pmd = pmd_offset(pud, va);
32952 - if (!pmd_present(*pmd))
32953 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32954 break;
32955
32956 /* should not be large page here */
32957 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32958
32959 static void __init pagetable_init(void)
32960 {
32961 - pgd_t *pgd_base = swapper_pg_dir;
32962 -
32963 - permanent_kmaps_init(pgd_base);
32964 + permanent_kmaps_init(swapper_pg_dir);
32965 }
32966
32967 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32968 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32969 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32970
32971 /* user-defined highmem size */
32972 @@ -787,10 +789,10 @@ void __init mem_init(void)
32973 ((unsigned long)&__init_end -
32974 (unsigned long)&__init_begin) >> 10,
32975
32976 - (unsigned long)&_etext, (unsigned long)&_edata,
32977 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32978 + (unsigned long)&_sdata, (unsigned long)&_edata,
32979 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32980
32981 - (unsigned long)&_text, (unsigned long)&_etext,
32982 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32983 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32984
32985 /*
32986 @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32987 if (!kernel_set_to_readonly)
32988 return;
32989
32990 + start = ktla_ktva(start);
32991 pr_debug("Set kernel text: %lx - %lx for read write\n",
32992 start, start+size);
32993
32994 @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32995 if (!kernel_set_to_readonly)
32996 return;
32997
32998 + start = ktla_ktva(start);
32999 pr_debug("Set kernel text: %lx - %lx for read only\n",
33000 start, start+size);
33001
33002 @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
33003 unsigned long start = PFN_ALIGN(_text);
33004 unsigned long size = PFN_ALIGN(_etext) - start;
33005
33006 + start = ktla_ktva(start);
33007 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33008 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33009 size >> 10);
33010 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33011 index f35c66c..84b95ef 100644
33012 --- a/arch/x86/mm/init_64.c
33013 +++ b/arch/x86/mm/init_64.c
33014 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33015 * around without checking the pgd every time.
33016 */
33017
33018 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33019 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33020 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33021
33022 int force_personality32;
33023 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33024
33025 for (address = start; address <= end; address += PGDIR_SIZE) {
33026 const pgd_t *pgd_ref = pgd_offset_k(address);
33027 +
33028 +#ifdef CONFIG_PAX_PER_CPU_PGD
33029 + unsigned long cpu;
33030 +#else
33031 struct page *page;
33032 +#endif
33033
33034 if (pgd_none(*pgd_ref))
33035 continue;
33036
33037 spin_lock(&pgd_lock);
33038 +
33039 +#ifdef CONFIG_PAX_PER_CPU_PGD
33040 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33041 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33042 +
33043 + if (pgd_none(*pgd))
33044 + set_pgd(pgd, *pgd_ref);
33045 + else
33046 + BUG_ON(pgd_page_vaddr(*pgd)
33047 + != pgd_page_vaddr(*pgd_ref));
33048 + pgd = pgd_offset_cpu(cpu, kernel, address);
33049 +#else
33050 list_for_each_entry(page, &pgd_list, lru) {
33051 pgd_t *pgd;
33052 spinlock_t *pgt_lock;
33053 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33054 /* the pgt_lock only for Xen */
33055 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33056 spin_lock(pgt_lock);
33057 +#endif
33058
33059 if (pgd_none(*pgd))
33060 set_pgd(pgd, *pgd_ref);
33061 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33062 BUG_ON(pgd_page_vaddr(*pgd)
33063 != pgd_page_vaddr(*pgd_ref));
33064
33065 +#ifndef CONFIG_PAX_PER_CPU_PGD
33066 spin_unlock(pgt_lock);
33067 +#endif
33068 +
33069 }
33070 spin_unlock(&pgd_lock);
33071 }
33072 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33073 {
33074 if (pgd_none(*pgd)) {
33075 pud_t *pud = (pud_t *)spp_getpage();
33076 - pgd_populate(&init_mm, pgd, pud);
33077 + pgd_populate_kernel(&init_mm, pgd, pud);
33078 if (pud != pud_offset(pgd, 0))
33079 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33080 pud, pud_offset(pgd, 0));
33081 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33082 {
33083 if (pud_none(*pud)) {
33084 pmd_t *pmd = (pmd_t *) spp_getpage();
33085 - pud_populate(&init_mm, pud, pmd);
33086 + pud_populate_kernel(&init_mm, pud, pmd);
33087 if (pmd != pmd_offset(pud, 0))
33088 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33089 pmd, pmd_offset(pud, 0));
33090 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33091 pmd = fill_pmd(pud, vaddr);
33092 pte = fill_pte(pmd, vaddr);
33093
33094 + pax_open_kernel();
33095 set_pte(pte, new_pte);
33096 + pax_close_kernel();
33097
33098 /*
33099 * It's enough to flush this one mapping.
33100 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33101 pgd = pgd_offset_k((unsigned long)__va(phys));
33102 if (pgd_none(*pgd)) {
33103 pud = (pud_t *) spp_getpage();
33104 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33105 - _PAGE_USER));
33106 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33107 }
33108 pud = pud_offset(pgd, (unsigned long)__va(phys));
33109 if (pud_none(*pud)) {
33110 pmd = (pmd_t *) spp_getpage();
33111 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33112 - _PAGE_USER));
33113 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33114 }
33115 pmd = pmd_offset(pud, phys);
33116 BUG_ON(!pmd_none(*pmd));
33117 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33118 prot);
33119
33120 spin_lock(&init_mm.page_table_lock);
33121 - pud_populate(&init_mm, pud, pmd);
33122 + pud_populate_kernel(&init_mm, pud, pmd);
33123 spin_unlock(&init_mm.page_table_lock);
33124 }
33125 __flush_tlb_all();
33126 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33127 page_size_mask);
33128
33129 spin_lock(&init_mm.page_table_lock);
33130 - pgd_populate(&init_mm, pgd, pud);
33131 + pgd_populate_kernel(&init_mm, pgd, pud);
33132 spin_unlock(&init_mm.page_table_lock);
33133 pgd_changed = true;
33134 }
33135 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
33136 static struct vm_area_struct gate_vma = {
33137 .vm_start = VSYSCALL_START,
33138 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
33139 - .vm_page_prot = PAGE_READONLY_EXEC,
33140 - .vm_flags = VM_READ | VM_EXEC
33141 + .vm_page_prot = PAGE_READONLY,
33142 + .vm_flags = VM_READ
33143 };
33144
33145 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33146 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
33147
33148 const char *arch_vma_name(struct vm_area_struct *vma)
33149 {
33150 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33151 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33152 return "[vdso]";
33153 if (vma == &gate_vma)
33154 return "[vsyscall]";
33155 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33156 index 7b179b4..6bd17777 100644
33157 --- a/arch/x86/mm/iomap_32.c
33158 +++ b/arch/x86/mm/iomap_32.c
33159 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33160 type = kmap_atomic_idx_push();
33161 idx = type + KM_TYPE_NR * smp_processor_id();
33162 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33163 +
33164 + pax_open_kernel();
33165 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33166 + pax_close_kernel();
33167 +
33168 arch_flush_lazy_mmu_mode();
33169
33170 return (void *)vaddr;
33171 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33172 index 799580c..72f9fe0 100644
33173 --- a/arch/x86/mm/ioremap.c
33174 +++ b/arch/x86/mm/ioremap.c
33175 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
33176 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
33177 int is_ram = page_is_ram(pfn);
33178
33179 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
33180 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
33181 return NULL;
33182 WARN_ON_ONCE(is_ram);
33183 }
33184 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
33185 *
33186 * Caller must ensure there is only one unmapping for the same pointer.
33187 */
33188 -void iounmap(volatile void __iomem *addr)
33189 +void iounmap(const volatile void __iomem *addr)
33190 {
33191 struct vm_struct *p, *o;
33192
33193 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33194
33195 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33196 if (page_is_ram(start >> PAGE_SHIFT))
33197 +#ifdef CONFIG_HIGHMEM
33198 + if ((start >> PAGE_SHIFT) < max_low_pfn)
33199 +#endif
33200 return __va(phys);
33201
33202 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33203 @@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33204 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33205 {
33206 if (page_is_ram(phys >> PAGE_SHIFT))
33207 +#ifdef CONFIG_HIGHMEM
33208 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
33209 +#endif
33210 return;
33211
33212 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33213 @@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
33214 early_param("early_ioremap_debug", early_ioremap_debug_setup);
33215
33216 static __initdata int after_paging_init;
33217 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33218 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33219
33220 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33221 {
33222 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33223 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
33224
33225 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33226 - memset(bm_pte, 0, sizeof(bm_pte));
33227 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
33228 + pmd_populate_user(&init_mm, pmd, bm_pte);
33229
33230 /*
33231 * The boot-ioremap range spans multiple pmds, for which
33232 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33233 index d87dd6d..bf3fa66 100644
33234 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
33235 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33236 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33237 * memory (e.g. tracked pages)? For now, we need this to avoid
33238 * invoking kmemcheck for PnP BIOS calls.
33239 */
33240 - if (regs->flags & X86_VM_MASK)
33241 + if (v8086_mode(regs))
33242 return false;
33243 - if (regs->cs != __KERNEL_CS)
33244 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33245 return false;
33246
33247 pte = kmemcheck_pte_lookup(address);
33248 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33249 index 25e7e13..1964579 100644
33250 --- a/arch/x86/mm/mmap.c
33251 +++ b/arch/x86/mm/mmap.c
33252 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33253 * Leave an at least ~128 MB hole with possible stack randomization.
33254 */
33255 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33256 -#define MAX_GAP (TASK_SIZE/6*5)
33257 +#define MAX_GAP (pax_task_size/6*5)
33258
33259 static int mmap_is_legacy(void)
33260 {
33261 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33262 return rnd << PAGE_SHIFT;
33263 }
33264
33265 -static unsigned long mmap_base(void)
33266 +static unsigned long mmap_base(struct mm_struct *mm)
33267 {
33268 unsigned long gap = rlimit(RLIMIT_STACK);
33269 + unsigned long pax_task_size = TASK_SIZE;
33270 +
33271 +#ifdef CONFIG_PAX_SEGMEXEC
33272 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33273 + pax_task_size = SEGMEXEC_TASK_SIZE;
33274 +#endif
33275
33276 if (gap < MIN_GAP)
33277 gap = MIN_GAP;
33278 else if (gap > MAX_GAP)
33279 gap = MAX_GAP;
33280
33281 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33282 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33283 }
33284
33285 /*
33286 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33287 * does, but not when emulating X86_32
33288 */
33289 -static unsigned long mmap_legacy_base(void)
33290 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33291 {
33292 - if (mmap_is_ia32())
33293 + if (mmap_is_ia32()) {
33294 +
33295 +#ifdef CONFIG_PAX_SEGMEXEC
33296 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33297 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33298 + else
33299 +#endif
33300 +
33301 return TASK_UNMAPPED_BASE;
33302 - else
33303 + } else
33304 return TASK_UNMAPPED_BASE + mmap_rnd();
33305 }
33306
33307 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33308 */
33309 void arch_pick_mmap_layout(struct mm_struct *mm)
33310 {
33311 - mm->mmap_legacy_base = mmap_legacy_base();
33312 - mm->mmap_base = mmap_base();
33313 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33314 + mm->mmap_base = mmap_base(mm);
33315 +
33316 +#ifdef CONFIG_PAX_RANDMMAP
33317 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33318 + mm->mmap_legacy_base += mm->delta_mmap;
33319 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33320 + }
33321 +#endif
33322
33323 if (mmap_is_legacy()) {
33324 mm->mmap_base = mm->mmap_legacy_base;
33325 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33326 index 0057a7a..95c7edd 100644
33327 --- a/arch/x86/mm/mmio-mod.c
33328 +++ b/arch/x86/mm/mmio-mod.c
33329 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33330 break;
33331 default:
33332 {
33333 - unsigned char *ip = (unsigned char *)instptr;
33334 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33335 my_trace->opcode = MMIO_UNKNOWN_OP;
33336 my_trace->width = 0;
33337 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33338 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33339 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33340 void __iomem *addr)
33341 {
33342 - static atomic_t next_id;
33343 + static atomic_unchecked_t next_id;
33344 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33345 /* These are page-unaligned. */
33346 struct mmiotrace_map map = {
33347 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33348 .private = trace
33349 },
33350 .phys = offset,
33351 - .id = atomic_inc_return(&next_id)
33352 + .id = atomic_inc_return_unchecked(&next_id)
33353 };
33354 map.map_id = trace->id;
33355
33356 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33357 ioremap_trace_core(offset, size, addr);
33358 }
33359
33360 -static void iounmap_trace_core(volatile void __iomem *addr)
33361 +static void iounmap_trace_core(const volatile void __iomem *addr)
33362 {
33363 struct mmiotrace_map map = {
33364 .phys = 0,
33365 @@ -328,7 +328,7 @@ not_enabled:
33366 }
33367 }
33368
33369 -void mmiotrace_iounmap(volatile void __iomem *addr)
33370 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33371 {
33372 might_sleep();
33373 if (is_enabled()) /* recheck and proper locking in *_core() */
33374 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33375 index 27aa0455..0eb1406 100644
33376 --- a/arch/x86/mm/numa.c
33377 +++ b/arch/x86/mm/numa.c
33378 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33379 return true;
33380 }
33381
33382 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33383 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33384 {
33385 unsigned long uninitialized_var(pfn_align);
33386 int i, nid;
33387 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33388 index 461bc82..4e091a3 100644
33389 --- a/arch/x86/mm/pageattr-test.c
33390 +++ b/arch/x86/mm/pageattr-test.c
33391 @@ -35,7 +35,7 @@ enum {
33392
33393 static int pte_testbit(pte_t pte)
33394 {
33395 - return pte_flags(pte) & _PAGE_UNUSED1;
33396 + return pte_flags(pte) & _PAGE_CPA_TEST;
33397 }
33398
33399 struct split_state {
33400 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33401 index a348868..3c64310 100644
33402 --- a/arch/x86/mm/pageattr.c
33403 +++ b/arch/x86/mm/pageattr.c
33404 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33405 */
33406 #ifdef CONFIG_PCI_BIOS
33407 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33408 - pgprot_val(forbidden) |= _PAGE_NX;
33409 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33410 #endif
33411
33412 /*
33413 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33414 * Does not cover __inittext since that is gone later on. On
33415 * 64bit we do not enforce !NX on the low mapping
33416 */
33417 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33418 - pgprot_val(forbidden) |= _PAGE_NX;
33419 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33420 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33421
33422 +#ifdef CONFIG_DEBUG_RODATA
33423 /*
33424 * The .rodata section needs to be read-only. Using the pfn
33425 * catches all aliases.
33426 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33427 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33428 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33429 pgprot_val(forbidden) |= _PAGE_RW;
33430 +#endif
33431
33432 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33433 /*
33434 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33435 }
33436 #endif
33437
33438 +#ifdef CONFIG_PAX_KERNEXEC
33439 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33440 + pgprot_val(forbidden) |= _PAGE_RW;
33441 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33442 + }
33443 +#endif
33444 +
33445 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33446
33447 return prot;
33448 @@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33449 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33450 {
33451 /* change init_mm */
33452 + pax_open_kernel();
33453 set_pte_atomic(kpte, pte);
33454 +
33455 #ifdef CONFIG_X86_32
33456 if (!SHARED_KERNEL_PMD) {
33457 +
33458 +#ifdef CONFIG_PAX_PER_CPU_PGD
33459 + unsigned long cpu;
33460 +#else
33461 struct page *page;
33462 +#endif
33463
33464 +#ifdef CONFIG_PAX_PER_CPU_PGD
33465 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33466 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33467 +#else
33468 list_for_each_entry(page, &pgd_list, lru) {
33469 - pgd_t *pgd;
33470 + pgd_t *pgd = (pgd_t *)page_address(page);
33471 +#endif
33472 +
33473 pud_t *pud;
33474 pmd_t *pmd;
33475
33476 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33477 + pgd += pgd_index(address);
33478 pud = pud_offset(pgd, address);
33479 pmd = pmd_offset(pud, address);
33480 set_pte_atomic((pte_t *)pmd, pte);
33481 }
33482 }
33483 #endif
33484 + pax_close_kernel();
33485 }
33486
33487 static int
33488 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33489 index 6574388..87e9bef 100644
33490 --- a/arch/x86/mm/pat.c
33491 +++ b/arch/x86/mm/pat.c
33492 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33493
33494 if (!entry) {
33495 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33496 - current->comm, current->pid, start, end - 1);
33497 + current->comm, task_pid_nr(current), start, end - 1);
33498 return -EINVAL;
33499 }
33500
33501 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33502
33503 while (cursor < to) {
33504 if (!devmem_is_allowed(pfn)) {
33505 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33506 - current->comm, from, to - 1);
33507 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33508 + current->comm, from, to - 1, cursor);
33509 return 0;
33510 }
33511 cursor += PAGE_SIZE;
33512 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33513 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33514 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33515 "for [mem %#010Lx-%#010Lx]\n",
33516 - current->comm, current->pid,
33517 + current->comm, task_pid_nr(current),
33518 cattr_name(flags),
33519 base, (unsigned long long)(base + size-1));
33520 return -EINVAL;
33521 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33522 flags = lookup_memtype(paddr);
33523 if (want_flags != flags) {
33524 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33525 - current->comm, current->pid,
33526 + current->comm, task_pid_nr(current),
33527 cattr_name(want_flags),
33528 (unsigned long long)paddr,
33529 (unsigned long long)(paddr + size - 1),
33530 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33531 free_memtype(paddr, paddr + size);
33532 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33533 " for [mem %#010Lx-%#010Lx], got %s\n",
33534 - current->comm, current->pid,
33535 + current->comm, task_pid_nr(current),
33536 cattr_name(want_flags),
33537 (unsigned long long)paddr,
33538 (unsigned long long)(paddr + size - 1),
33539 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33540 index 415f6c4..d319983 100644
33541 --- a/arch/x86/mm/pat_rbtree.c
33542 +++ b/arch/x86/mm/pat_rbtree.c
33543 @@ -160,7 +160,7 @@ success:
33544
33545 failure:
33546 printk(KERN_INFO "%s:%d conflicting memory types "
33547 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33548 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33549 end, cattr_name(found_type), cattr_name(match->type));
33550 return -EBUSY;
33551 }
33552 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33553 index 9f0614d..92ae64a 100644
33554 --- a/arch/x86/mm/pf_in.c
33555 +++ b/arch/x86/mm/pf_in.c
33556 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33557 int i;
33558 enum reason_type rv = OTHERS;
33559
33560 - p = (unsigned char *)ins_addr;
33561 + p = (unsigned char *)ktla_ktva(ins_addr);
33562 p += skip_prefix(p, &prf);
33563 p += get_opcode(p, &opcode);
33564
33565 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33566 struct prefix_bits prf;
33567 int i;
33568
33569 - p = (unsigned char *)ins_addr;
33570 + p = (unsigned char *)ktla_ktva(ins_addr);
33571 p += skip_prefix(p, &prf);
33572 p += get_opcode(p, &opcode);
33573
33574 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33575 struct prefix_bits prf;
33576 int i;
33577
33578 - p = (unsigned char *)ins_addr;
33579 + p = (unsigned char *)ktla_ktva(ins_addr);
33580 p += skip_prefix(p, &prf);
33581 p += get_opcode(p, &opcode);
33582
33583 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33584 struct prefix_bits prf;
33585 int i;
33586
33587 - p = (unsigned char *)ins_addr;
33588 + p = (unsigned char *)ktla_ktva(ins_addr);
33589 p += skip_prefix(p, &prf);
33590 p += get_opcode(p, &opcode);
33591 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33592 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33593 struct prefix_bits prf;
33594 int i;
33595
33596 - p = (unsigned char *)ins_addr;
33597 + p = (unsigned char *)ktla_ktva(ins_addr);
33598 p += skip_prefix(p, &prf);
33599 p += get_opcode(p, &opcode);
33600 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33601 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33602 index c96314a..433b127 100644
33603 --- a/arch/x86/mm/pgtable.c
33604 +++ b/arch/x86/mm/pgtable.c
33605 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33606 list_del(&page->lru);
33607 }
33608
33609 -#define UNSHARED_PTRS_PER_PGD \
33610 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33611 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33612 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33613
33614 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33615 +{
33616 + unsigned int count = USER_PGD_PTRS;
33617
33618 + if (!pax_user_shadow_base)
33619 + return;
33620 +
33621 + while (count--)
33622 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33623 +}
33624 +#endif
33625 +
33626 +#ifdef CONFIG_PAX_PER_CPU_PGD
33627 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33628 +{
33629 + unsigned int count = USER_PGD_PTRS;
33630 +
33631 + while (count--) {
33632 + pgd_t pgd;
33633 +
33634 +#ifdef CONFIG_X86_64
33635 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33636 +#else
33637 + pgd = *src++;
33638 +#endif
33639 +
33640 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33641 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33642 +#endif
33643 +
33644 + *dst++ = pgd;
33645 + }
33646 +
33647 +}
33648 +#endif
33649 +
33650 +#ifdef CONFIG_X86_64
33651 +#define pxd_t pud_t
33652 +#define pyd_t pgd_t
33653 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33654 +#define pgtable_pxd_page_ctor(page) true
33655 +#define pgtable_pxd_page_dtor(page)
33656 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33657 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33658 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33659 +#define PYD_SIZE PGDIR_SIZE
33660 +#else
33661 +#define pxd_t pmd_t
33662 +#define pyd_t pud_t
33663 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33664 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33665 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33666 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33667 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33668 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33669 +#define PYD_SIZE PUD_SIZE
33670 +#endif
33671 +
33672 +#ifdef CONFIG_PAX_PER_CPU_PGD
33673 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33674 +static inline void pgd_dtor(pgd_t *pgd) {}
33675 +#else
33676 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33677 {
33678 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33679 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33680 pgd_list_del(pgd);
33681 spin_unlock(&pgd_lock);
33682 }
33683 +#endif
33684
33685 /*
33686 * List of all pgd's needed for non-PAE so it can invalidate entries
33687 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33688 * -- nyc
33689 */
33690
33691 -#ifdef CONFIG_X86_PAE
33692 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33693 /*
33694 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33695 * updating the top-level pagetable entries to guarantee the
33696 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33697 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33698 * and initialize the kernel pmds here.
33699 */
33700 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33701 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33702
33703 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33704 {
33705 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33706 */
33707 flush_tlb_mm(mm);
33708 }
33709 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33710 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33711 #else /* !CONFIG_X86_PAE */
33712
33713 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33714 -#define PREALLOCATED_PMDS 0
33715 +#define PREALLOCATED_PXDS 0
33716
33717 #endif /* CONFIG_X86_PAE */
33718
33719 -static void free_pmds(pmd_t *pmds[])
33720 +static void free_pxds(pxd_t *pxds[])
33721 {
33722 int i;
33723
33724 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33725 - if (pmds[i]) {
33726 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33727 - free_page((unsigned long)pmds[i]);
33728 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33729 + if (pxds[i]) {
33730 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33731 + free_page((unsigned long)pxds[i]);
33732 }
33733 }
33734
33735 -static int preallocate_pmds(pmd_t *pmds[])
33736 +static int preallocate_pxds(pxd_t *pxds[])
33737 {
33738 int i;
33739 bool failed = false;
33740
33741 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33742 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33743 - if (!pmd)
33744 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33745 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33746 + if (!pxd)
33747 failed = true;
33748 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33749 - free_page((unsigned long)pmd);
33750 - pmd = NULL;
33751 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33752 + free_page((unsigned long)pxd);
33753 + pxd = NULL;
33754 failed = true;
33755 }
33756 - pmds[i] = pmd;
33757 + pxds[i] = pxd;
33758 }
33759
33760 if (failed) {
33761 - free_pmds(pmds);
33762 + free_pxds(pxds);
33763 return -ENOMEM;
33764 }
33765
33766 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33767 * preallocate which never got a corresponding vma will need to be
33768 * freed manually.
33769 */
33770 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33771 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33772 {
33773 int i;
33774
33775 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33776 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33777 pgd_t pgd = pgdp[i];
33778
33779 if (pgd_val(pgd) != 0) {
33780 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33781 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33782
33783 - pgdp[i] = native_make_pgd(0);
33784 + set_pgd(pgdp + i, native_make_pgd(0));
33785
33786 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33787 - pmd_free(mm, pmd);
33788 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33789 + pxd_free(mm, pxd);
33790 }
33791 }
33792 }
33793
33794 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33795 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33796 {
33797 - pud_t *pud;
33798 + pyd_t *pyd;
33799 int i;
33800
33801 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33802 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33803 return;
33804
33805 - pud = pud_offset(pgd, 0);
33806 -
33807 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33808 - pmd_t *pmd = pmds[i];
33809 +#ifdef CONFIG_X86_64
33810 + pyd = pyd_offset(mm, 0L);
33811 +#else
33812 + pyd = pyd_offset(pgd, 0L);
33813 +#endif
33814
33815 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33816 + pxd_t *pxd = pxds[i];
33817 if (i >= KERNEL_PGD_BOUNDARY)
33818 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33819 - sizeof(pmd_t) * PTRS_PER_PMD);
33820 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33821 + sizeof(pxd_t) * PTRS_PER_PMD);
33822
33823 - pud_populate(mm, pud, pmd);
33824 + pyd_populate(mm, pyd, pxd);
33825 }
33826 }
33827
33828 pgd_t *pgd_alloc(struct mm_struct *mm)
33829 {
33830 pgd_t *pgd;
33831 - pmd_t *pmds[PREALLOCATED_PMDS];
33832 + pxd_t *pxds[PREALLOCATED_PXDS];
33833
33834 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33835
33836 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33837
33838 mm->pgd = pgd;
33839
33840 - if (preallocate_pmds(pmds) != 0)
33841 + if (preallocate_pxds(pxds) != 0)
33842 goto out_free_pgd;
33843
33844 if (paravirt_pgd_alloc(mm) != 0)
33845 - goto out_free_pmds;
33846 + goto out_free_pxds;
33847
33848 /*
33849 * Make sure that pre-populating the pmds is atomic with
33850 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33851 spin_lock(&pgd_lock);
33852
33853 pgd_ctor(mm, pgd);
33854 - pgd_prepopulate_pmd(mm, pgd, pmds);
33855 + pgd_prepopulate_pxd(mm, pgd, pxds);
33856
33857 spin_unlock(&pgd_lock);
33858
33859 return pgd;
33860
33861 -out_free_pmds:
33862 - free_pmds(pmds);
33863 +out_free_pxds:
33864 + free_pxds(pxds);
33865 out_free_pgd:
33866 free_page((unsigned long)pgd);
33867 out:
33868 @@ -313,7 +380,7 @@ out:
33869
33870 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33871 {
33872 - pgd_mop_up_pmds(mm, pgd);
33873 + pgd_mop_up_pxds(mm, pgd);
33874 pgd_dtor(pgd);
33875 paravirt_pgd_free(mm, pgd);
33876 free_page((unsigned long)pgd);
33877 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33878 index a69bcb8..19068ab 100644
33879 --- a/arch/x86/mm/pgtable_32.c
33880 +++ b/arch/x86/mm/pgtable_32.c
33881 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33882 return;
33883 }
33884 pte = pte_offset_kernel(pmd, vaddr);
33885 +
33886 + pax_open_kernel();
33887 if (pte_val(pteval))
33888 set_pte_at(&init_mm, vaddr, pte, pteval);
33889 else
33890 pte_clear(&init_mm, vaddr, pte);
33891 + pax_close_kernel();
33892
33893 /*
33894 * It's enough to flush this one mapping.
33895 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33896 index e666cbb..61788c45 100644
33897 --- a/arch/x86/mm/physaddr.c
33898 +++ b/arch/x86/mm/physaddr.c
33899 @@ -10,7 +10,7 @@
33900 #ifdef CONFIG_X86_64
33901
33902 #ifdef CONFIG_DEBUG_VIRTUAL
33903 -unsigned long __phys_addr(unsigned long x)
33904 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33905 {
33906 unsigned long y = x - __START_KERNEL_map;
33907
33908 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33909 #else
33910
33911 #ifdef CONFIG_DEBUG_VIRTUAL
33912 -unsigned long __phys_addr(unsigned long x)
33913 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33914 {
33915 unsigned long phys_addr = x - PAGE_OFFSET;
33916 /* VMALLOC_* aren't constants */
33917 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33918 index 90555bf..f5f1828 100644
33919 --- a/arch/x86/mm/setup_nx.c
33920 +++ b/arch/x86/mm/setup_nx.c
33921 @@ -5,8 +5,10 @@
33922 #include <asm/pgtable.h>
33923 #include <asm/proto.h>
33924
33925 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33926 static int disable_nx;
33927
33928 +#ifndef CONFIG_PAX_PAGEEXEC
33929 /*
33930 * noexec = on|off
33931 *
33932 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33933 return 0;
33934 }
33935 early_param("noexec", noexec_setup);
33936 +#endif
33937 +
33938 +#endif
33939
33940 void x86_configure_nx(void)
33941 {
33942 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33943 if (cpu_has_nx && !disable_nx)
33944 __supported_pte_mask |= _PAGE_NX;
33945 else
33946 +#endif
33947 __supported_pte_mask &= ~_PAGE_NX;
33948 }
33949
33950 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33951 index dd8dda1..9e9b0f6 100644
33952 --- a/arch/x86/mm/tlb.c
33953 +++ b/arch/x86/mm/tlb.c
33954 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
33955 BUG();
33956 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33957 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33958 +
33959 +#ifndef CONFIG_PAX_PER_CPU_PGD
33960 load_cr3(swapper_pg_dir);
33961 +#endif
33962 +
33963 }
33964 }
33965 EXPORT_SYMBOL_GPL(leave_mm);
33966 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33967 new file mode 100644
33968 index 0000000..dace51c
33969 --- /dev/null
33970 +++ b/arch/x86/mm/uderef_64.c
33971 @@ -0,0 +1,37 @@
33972 +#include <linux/mm.h>
33973 +#include <asm/pgtable.h>
33974 +#include <asm/uaccess.h>
33975 +
33976 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33977 +/* PaX: due to the special call convention these functions must
33978 + * - remain leaf functions under all configurations,
33979 + * - never be called directly, only dereferenced from the wrappers.
33980 + */
33981 +void __pax_open_userland(void)
33982 +{
33983 + unsigned int cpu;
33984 +
33985 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33986 + return;
33987 +
33988 + cpu = raw_get_cpu();
33989 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33990 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33991 + raw_put_cpu_no_resched();
33992 +}
33993 +EXPORT_SYMBOL(__pax_open_userland);
33994 +
33995 +void __pax_close_userland(void)
33996 +{
33997 + unsigned int cpu;
33998 +
33999 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
34000 + return;
34001 +
34002 + cpu = raw_get_cpu();
34003 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34004 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34005 + raw_put_cpu_no_resched();
34006 +}
34007 +EXPORT_SYMBOL(__pax_close_userland);
34008 +#endif
34009 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34010 index 0149575..f746de8 100644
34011 --- a/arch/x86/net/bpf_jit.S
34012 +++ b/arch/x86/net/bpf_jit.S
34013 @@ -9,6 +9,7 @@
34014 */
34015 #include <linux/linkage.h>
34016 #include <asm/dwarf2.h>
34017 +#include <asm/alternative-asm.h>
34018
34019 /*
34020 * Calling convention :
34021 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
34022 jle bpf_slow_path_word
34023 mov (SKBDATA,%rsi),%eax
34024 bswap %eax /* ntohl() */
34025 + pax_force_retaddr
34026 ret
34027
34028 sk_load_half:
34029 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
34030 jle bpf_slow_path_half
34031 movzwl (SKBDATA,%rsi),%eax
34032 rol $8,%ax # ntohs()
34033 + pax_force_retaddr
34034 ret
34035
34036 sk_load_byte:
34037 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
34038 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34039 jle bpf_slow_path_byte
34040 movzbl (SKBDATA,%rsi),%eax
34041 + pax_force_retaddr
34042 ret
34043
34044 /**
34045 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
34046 movzbl (SKBDATA,%rsi),%ebx
34047 and $15,%bl
34048 shl $2,%bl
34049 + pax_force_retaddr
34050 ret
34051
34052 /* rsi contains offset and can be scratched */
34053 @@ -109,6 +114,7 @@ bpf_slow_path_word:
34054 js bpf_error
34055 mov -12(%rbp),%eax
34056 bswap %eax
34057 + pax_force_retaddr
34058 ret
34059
34060 bpf_slow_path_half:
34061 @@ -117,12 +123,14 @@ bpf_slow_path_half:
34062 mov -12(%rbp),%ax
34063 rol $8,%ax
34064 movzwl %ax,%eax
34065 + pax_force_retaddr
34066 ret
34067
34068 bpf_slow_path_byte:
34069 bpf_slow_path_common(1)
34070 js bpf_error
34071 movzbl -12(%rbp),%eax
34072 + pax_force_retaddr
34073 ret
34074
34075 bpf_slow_path_byte_msh:
34076 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
34077 and $15,%al
34078 shl $2,%al
34079 xchg %eax,%ebx
34080 + pax_force_retaddr
34081 ret
34082
34083 #define sk_negative_common(SIZE) \
34084 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
34085 sk_negative_common(4)
34086 mov (%rax), %eax
34087 bswap %eax
34088 + pax_force_retaddr
34089 ret
34090
34091 bpf_slow_path_half_neg:
34092 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
34093 mov (%rax),%ax
34094 rol $8,%ax
34095 movzwl %ax,%eax
34096 + pax_force_retaddr
34097 ret
34098
34099 bpf_slow_path_byte_neg:
34100 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
34101 .globl sk_load_byte_negative_offset
34102 sk_negative_common(1)
34103 movzbl (%rax), %eax
34104 + pax_force_retaddr
34105 ret
34106
34107 bpf_slow_path_byte_msh_neg:
34108 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
34109 and $15,%al
34110 shl $2,%al
34111 xchg %eax,%ebx
34112 + pax_force_retaddr
34113 ret
34114
34115 bpf_error:
34116 @@ -197,4 +210,5 @@ bpf_error:
34117 xor %eax,%eax
34118 mov -8(%rbp),%rbx
34119 leaveq
34120 + pax_force_retaddr
34121 ret
34122 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34123 index 4ed75dd..3cf24f0b 100644
34124 --- a/arch/x86/net/bpf_jit_comp.c
34125 +++ b/arch/x86/net/bpf_jit_comp.c
34126 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34127 return ptr + len;
34128 }
34129
34130 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34131 +#define MAX_INSTR_CODE_SIZE 96
34132 +#else
34133 +#define MAX_INSTR_CODE_SIZE 64
34134 +#endif
34135 +
34136 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
34137
34138 #define EMIT1(b1) EMIT(b1, 1)
34139 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
34140 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
34141 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
34142 +
34143 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34144 +/* original constant will appear in ecx */
34145 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
34146 +do { \
34147 + /* mov ecx, randkey */ \
34148 + EMIT1(0xb9); \
34149 + EMIT(_key, 4); \
34150 + /* xor ecx, randkey ^ off */ \
34151 + EMIT2(0x81, 0xf1); \
34152 + EMIT((_key) ^ (_off), 4); \
34153 +} while (0)
34154 +
34155 +#define EMIT1_off32(b1, _off) \
34156 +do { \
34157 + switch (b1) { \
34158 + case 0x05: /* add eax, imm32 */ \
34159 + case 0x2d: /* sub eax, imm32 */ \
34160 + case 0x25: /* and eax, imm32 */ \
34161 + case 0x0d: /* or eax, imm32 */ \
34162 + case 0xb8: /* mov eax, imm32 */ \
34163 + case 0x35: /* xor eax, imm32 */ \
34164 + case 0x3d: /* cmp eax, imm32 */ \
34165 + case 0xa9: /* test eax, imm32 */ \
34166 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34167 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
34168 + break; \
34169 + case 0xbb: /* mov ebx, imm32 */ \
34170 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34171 + /* mov ebx, ecx */ \
34172 + EMIT2(0x89, 0xcb); \
34173 + break; \
34174 + case 0xbe: /* mov esi, imm32 */ \
34175 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34176 + /* mov esi, ecx */ \
34177 + EMIT2(0x89, 0xce); \
34178 + break; \
34179 + case 0xe8: /* call rel imm32, always to known funcs */ \
34180 + EMIT1(b1); \
34181 + EMIT(_off, 4); \
34182 + break; \
34183 + case 0xe9: /* jmp rel imm32 */ \
34184 + EMIT1(b1); \
34185 + EMIT(_off, 4); \
34186 + /* prevent fall-through, we're not called if off = 0 */ \
34187 + EMIT(0xcccccccc, 4); \
34188 + EMIT(0xcccccccc, 4); \
34189 + break; \
34190 + default: \
34191 + BUILD_BUG(); \
34192 + } \
34193 +} while (0)
34194 +
34195 +#define EMIT2_off32(b1, b2, _off) \
34196 +do { \
34197 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
34198 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
34199 + EMIT(randkey, 4); \
34200 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
34201 + EMIT((_off) - randkey, 4); \
34202 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
34203 + DILUTE_CONST_SEQUENCE(_off, randkey); \
34204 + /* imul eax, ecx */ \
34205 + EMIT3(0x0f, 0xaf, 0xc1); \
34206 + } else { \
34207 + BUILD_BUG(); \
34208 + } \
34209 +} while (0)
34210 +#else
34211 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
34212 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
34213 +#endif
34214
34215 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
34216 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
34217 @@ -91,6 +168,24 @@ do { \
34218 #define X86_JBE 0x76
34219 #define X86_JA 0x77
34220
34221 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34222 +#define APPEND_FLOW_VERIFY() \
34223 +do { \
34224 + /* mov ecx, randkey */ \
34225 + EMIT1(0xb9); \
34226 + EMIT(randkey, 4); \
34227 + /* cmp ecx, randkey */ \
34228 + EMIT2(0x81, 0xf9); \
34229 + EMIT(randkey, 4); \
34230 + /* jz after 8 int 3s */ \
34231 + EMIT2(0x74, 0x08); \
34232 + EMIT(0xcccccccc, 4); \
34233 + EMIT(0xcccccccc, 4); \
34234 +} while (0)
34235 +#else
34236 +#define APPEND_FLOW_VERIFY() do { } while (0)
34237 +#endif
34238 +
34239 #define EMIT_COND_JMP(op, offset) \
34240 do { \
34241 if (is_near(offset)) \
34242 @@ -98,6 +193,7 @@ do { \
34243 else { \
34244 EMIT2(0x0f, op + 0x10); \
34245 EMIT(offset, 4); /* jxx .+off32 */ \
34246 + APPEND_FLOW_VERIFY(); \
34247 } \
34248 } while (0)
34249
34250 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
34251 return -1;
34252 }
34253
34254 -struct bpf_binary_header {
34255 - unsigned int pages;
34256 - /* Note : for security reasons, bpf code will follow a randomly
34257 - * sized amount of int3 instructions
34258 - */
34259 - u8 image[];
34260 -};
34261 -
34262 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34263 +/* Note : for security reasons, bpf code will follow a randomly
34264 + * sized amount of int3 instructions
34265 + */
34266 +static u8 *bpf_alloc_binary(unsigned int proglen,
34267 u8 **image_ptr)
34268 {
34269 unsigned int sz, hole;
34270 - struct bpf_binary_header *header;
34271 + u8 *header;
34272
34273 /* Most of BPF filters are really small,
34274 * but if some of them fill a page, allow at least
34275 * 128 extra bytes to insert a random section of int3
34276 */
34277 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34278 - header = module_alloc(sz);
34279 + sz = round_up(proglen + 128, PAGE_SIZE);
34280 + header = module_alloc_exec(sz);
34281 if (!header)
34282 return NULL;
34283
34284 + pax_open_kernel();
34285 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34286 + pax_close_kernel();
34287
34288 - header->pages = sz / PAGE_SIZE;
34289 - hole = sz - (proglen + sizeof(*header));
34290 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34291
34292 /* insert a random number of int3 instructions before BPF code */
34293 - *image_ptr = &header->image[prandom_u32() % hole];
34294 + *image_ptr = &header[prandom_u32() % hole];
34295 return header;
34296 }
34297
34298 void bpf_jit_compile(struct sk_filter *fp)
34299 {
34300 - u8 temp[64];
34301 + u8 temp[MAX_INSTR_CODE_SIZE];
34302 u8 *prog;
34303 unsigned int proglen, oldproglen = 0;
34304 int ilen, i;
34305 int t_offset, f_offset;
34306 u8 t_op, f_op, seen = 0, pass;
34307 u8 *image = NULL;
34308 - struct bpf_binary_header *header = NULL;
34309 + u8 *header = NULL;
34310 u8 *func;
34311 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34312 unsigned int cleanup_addr; /* epilogue code offset */
34313 unsigned int *addrs;
34314 const struct sock_filter *filter = fp->insns;
34315 int flen = fp->len;
34316 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34317 + unsigned int randkey;
34318 +#endif
34319
34320 if (!bpf_jit_enable)
34321 return;
34322 @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34323 return;
34324
34325 /* Before first pass, make a rough estimation of addrs[]
34326 - * each bpf instruction is translated to less than 64 bytes
34327 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34328 */
34329 for (proglen = 0, i = 0; i < flen; i++) {
34330 - proglen += 64;
34331 + proglen += MAX_INSTR_CODE_SIZE;
34332 addrs[i] = proglen;
34333 }
34334 cleanup_addr = proglen; /* epilogue address */
34335 @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34336 for (i = 0; i < flen; i++) {
34337 unsigned int K = filter[i].k;
34338
34339 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34340 + randkey = prandom_u32();
34341 +#endif
34342 +
34343 switch (filter[i].code) {
34344 case BPF_S_ALU_ADD_X: /* A += X; */
34345 seen |= SEEN_XREG;
34346 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34347 case BPF_S_ALU_MUL_K: /* A *= K */
34348 if (is_imm8(K))
34349 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34350 - else {
34351 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34352 - EMIT(K, 4);
34353 - }
34354 + else
34355 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34356 break;
34357 case BPF_S_ALU_DIV_X: /* A /= X; */
34358 seen |= SEEN_XREG;
34359 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34360 break;
34361 }
34362 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34363 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34364 + DILUTE_CONST_SEQUENCE(K, randkey);
34365 +#else
34366 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34367 +#endif
34368 EMIT2(0xf7, 0xf1); /* div %ecx */
34369 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34370 break;
34371 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34372 if (K == 1)
34373 break;
34374 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34375 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34376 + DILUTE_CONST_SEQUENCE(K, randkey);
34377 +#else
34378 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34379 +#endif
34380 EMIT2(0xf7, 0xf1); /* div %ecx */
34381 break;
34382 case BPF_S_ALU_AND_X:
34383 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34384 if (is_imm8(K)) {
34385 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34386 } else {
34387 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34388 - EMIT(K, 4);
34389 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34390 }
34391 } else {
34392 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34393 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34394 if (unlikely(proglen + ilen > oldproglen)) {
34395 pr_err("bpb_jit_compile fatal error\n");
34396 kfree(addrs);
34397 - module_free(NULL, header);
34398 + module_free_exec(NULL, image);
34399 return;
34400 }
34401 + pax_open_kernel();
34402 memcpy(image + proglen, temp, ilen);
34403 + pax_close_kernel();
34404 }
34405 proglen += ilen;
34406 addrs[i] = proglen;
34407 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34408
34409 if (image) {
34410 bpf_flush_icache(header, image + proglen);
34411 - set_memory_ro((unsigned long)header, header->pages);
34412 fp->bpf_func = (void *)image;
34413 }
34414 out:
34415 @@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34416 {
34417 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34418 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34419 - struct bpf_binary_header *header = (void *)addr;
34420
34421 - set_memory_rw(addr, header->pages);
34422 - module_free(NULL, header);
34423 + set_memory_rw(addr, 1);
34424 + module_free_exec(NULL, (void *)addr);
34425 kfree(fp);
34426 }
34427
34428 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34429 index 5d04be5..2beeaa2 100644
34430 --- a/arch/x86/oprofile/backtrace.c
34431 +++ b/arch/x86/oprofile/backtrace.c
34432 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34433 struct stack_frame_ia32 *fp;
34434 unsigned long bytes;
34435
34436 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34437 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34438 if (bytes != 0)
34439 return NULL;
34440
34441 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34442 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34443
34444 oprofile_add_trace(bufhead[0].return_address);
34445
34446 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34447 struct stack_frame bufhead[2];
34448 unsigned long bytes;
34449
34450 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34451 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34452 if (bytes != 0)
34453 return NULL;
34454
34455 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34456 {
34457 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34458
34459 - if (!user_mode_vm(regs)) {
34460 + if (!user_mode(regs)) {
34461 unsigned long stack = kernel_stack_pointer(regs);
34462 if (depth)
34463 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34464 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34465 index 6890d84..1dad1f1 100644
34466 --- a/arch/x86/oprofile/nmi_int.c
34467 +++ b/arch/x86/oprofile/nmi_int.c
34468 @@ -23,6 +23,7 @@
34469 #include <asm/nmi.h>
34470 #include <asm/msr.h>
34471 #include <asm/apic.h>
34472 +#include <asm/pgtable.h>
34473
34474 #include "op_counter.h"
34475 #include "op_x86_model.h"
34476 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34477 if (ret)
34478 return ret;
34479
34480 - if (!model->num_virt_counters)
34481 - model->num_virt_counters = model->num_counters;
34482 + if (!model->num_virt_counters) {
34483 + pax_open_kernel();
34484 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34485 + pax_close_kernel();
34486 + }
34487
34488 mux_init(ops);
34489
34490 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34491 index 50d86c0..7985318 100644
34492 --- a/arch/x86/oprofile/op_model_amd.c
34493 +++ b/arch/x86/oprofile/op_model_amd.c
34494 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34495 num_counters = AMD64_NUM_COUNTERS;
34496 }
34497
34498 - op_amd_spec.num_counters = num_counters;
34499 - op_amd_spec.num_controls = num_counters;
34500 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34501 + pax_open_kernel();
34502 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34503 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34504 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34505 + pax_close_kernel();
34506
34507 return 0;
34508 }
34509 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34510 index d90528e..0127e2b 100644
34511 --- a/arch/x86/oprofile/op_model_ppro.c
34512 +++ b/arch/x86/oprofile/op_model_ppro.c
34513 @@ -19,6 +19,7 @@
34514 #include <asm/msr.h>
34515 #include <asm/apic.h>
34516 #include <asm/nmi.h>
34517 +#include <asm/pgtable.h>
34518
34519 #include "op_x86_model.h"
34520 #include "op_counter.h"
34521 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34522
34523 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34524
34525 - op_arch_perfmon_spec.num_counters = num_counters;
34526 - op_arch_perfmon_spec.num_controls = num_counters;
34527 + pax_open_kernel();
34528 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34529 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34530 + pax_close_kernel();
34531 }
34532
34533 static int arch_perfmon_init(struct oprofile_operations *ignore)
34534 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34535 index 71e8a67..6a313bb 100644
34536 --- a/arch/x86/oprofile/op_x86_model.h
34537 +++ b/arch/x86/oprofile/op_x86_model.h
34538 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34539 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34540 struct op_msrs const * const msrs);
34541 #endif
34542 -};
34543 +} __do_const;
34544
34545 struct op_counter_config;
34546
34547 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34548 index 84b9d67..260e5ff 100644
34549 --- a/arch/x86/pci/intel_mid_pci.c
34550 +++ b/arch/x86/pci/intel_mid_pci.c
34551 @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34552 pr_info("Intel MID platform detected, using MID PCI ops\n");
34553 pci_mmcfg_late_init();
34554 pcibios_enable_irq = intel_mid_pci_irq_enable;
34555 - pci_root_ops = intel_mid_pci_ops;
34556 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34557 pci_soc_mode = 1;
34558 /* Continue with standard init */
34559 return 1;
34560 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34561 index 372e9b8..e775a6c 100644
34562 --- a/arch/x86/pci/irq.c
34563 +++ b/arch/x86/pci/irq.c
34564 @@ -50,7 +50,7 @@ struct irq_router {
34565 struct irq_router_handler {
34566 u16 vendor;
34567 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34568 -};
34569 +} __do_const;
34570
34571 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34572 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34573 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34574 return 0;
34575 }
34576
34577 -static __initdata struct irq_router_handler pirq_routers[] = {
34578 +static __initconst const struct irq_router_handler pirq_routers[] = {
34579 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34580 { PCI_VENDOR_ID_AL, ali_router_probe },
34581 { PCI_VENDOR_ID_ITE, ite_router_probe },
34582 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34583 static void __init pirq_find_router(struct irq_router *r)
34584 {
34585 struct irq_routing_table *rt = pirq_table;
34586 - struct irq_router_handler *h;
34587 + const struct irq_router_handler *h;
34588
34589 #ifdef CONFIG_PCI_BIOS
34590 if (!rt->signature) {
34591 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34592 return 0;
34593 }
34594
34595 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34596 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34597 {
34598 .callback = fix_broken_hp_bios_irq9,
34599 .ident = "HP Pavilion N5400 Series Laptop",
34600 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34601 index c77b24a..c979855 100644
34602 --- a/arch/x86/pci/pcbios.c
34603 +++ b/arch/x86/pci/pcbios.c
34604 @@ -79,7 +79,7 @@ union bios32 {
34605 static struct {
34606 unsigned long address;
34607 unsigned short segment;
34608 -} bios32_indirect = { 0, __KERNEL_CS };
34609 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34610
34611 /*
34612 * Returns the entry point for the given service, NULL on error
34613 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34614 unsigned long length; /* %ecx */
34615 unsigned long entry; /* %edx */
34616 unsigned long flags;
34617 + struct desc_struct d, *gdt;
34618
34619 local_irq_save(flags);
34620 - __asm__("lcall *(%%edi); cld"
34621 +
34622 + gdt = get_cpu_gdt_table(smp_processor_id());
34623 +
34624 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34625 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34626 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34627 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34628 +
34629 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34630 : "=a" (return_code),
34631 "=b" (address),
34632 "=c" (length),
34633 "=d" (entry)
34634 : "0" (service),
34635 "1" (0),
34636 - "D" (&bios32_indirect));
34637 + "D" (&bios32_indirect),
34638 + "r"(__PCIBIOS_DS)
34639 + : "memory");
34640 +
34641 + pax_open_kernel();
34642 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34643 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34644 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34645 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34646 + pax_close_kernel();
34647 +
34648 local_irq_restore(flags);
34649
34650 switch (return_code) {
34651 - case 0:
34652 - return address + entry;
34653 - case 0x80: /* Not present */
34654 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34655 - return 0;
34656 - default: /* Shouldn't happen */
34657 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34658 - service, return_code);
34659 + case 0: {
34660 + int cpu;
34661 + unsigned char flags;
34662 +
34663 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34664 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34665 + printk(KERN_WARNING "bios32_service: not valid\n");
34666 return 0;
34667 + }
34668 + address = address + PAGE_OFFSET;
34669 + length += 16UL; /* some BIOSs underreport this... */
34670 + flags = 4;
34671 + if (length >= 64*1024*1024) {
34672 + length >>= PAGE_SHIFT;
34673 + flags |= 8;
34674 + }
34675 +
34676 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34677 + gdt = get_cpu_gdt_table(cpu);
34678 + pack_descriptor(&d, address, length, 0x9b, flags);
34679 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34680 + pack_descriptor(&d, address, length, 0x93, flags);
34681 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34682 + }
34683 + return entry;
34684 + }
34685 + case 0x80: /* Not present */
34686 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34687 + return 0;
34688 + default: /* Shouldn't happen */
34689 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34690 + service, return_code);
34691 + return 0;
34692 }
34693 }
34694
34695 static struct {
34696 unsigned long address;
34697 unsigned short segment;
34698 -} pci_indirect = { 0, __KERNEL_CS };
34699 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34700
34701 -static int pci_bios_present;
34702 +static int pci_bios_present __read_only;
34703
34704 static int check_pcibios(void)
34705 {
34706 @@ -131,11 +174,13 @@ static int check_pcibios(void)
34707 unsigned long flags, pcibios_entry;
34708
34709 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34710 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34711 + pci_indirect.address = pcibios_entry;
34712
34713 local_irq_save(flags);
34714 - __asm__(
34715 - "lcall *(%%edi); cld\n\t"
34716 + __asm__("movw %w6, %%ds\n\t"
34717 + "lcall *%%ss:(%%edi); cld\n\t"
34718 + "push %%ss\n\t"
34719 + "pop %%ds\n\t"
34720 "jc 1f\n\t"
34721 "xor %%ah, %%ah\n"
34722 "1:"
34723 @@ -144,7 +189,8 @@ static int check_pcibios(void)
34724 "=b" (ebx),
34725 "=c" (ecx)
34726 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34727 - "D" (&pci_indirect)
34728 + "D" (&pci_indirect),
34729 + "r" (__PCIBIOS_DS)
34730 : "memory");
34731 local_irq_restore(flags);
34732
34733 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34734
34735 switch (len) {
34736 case 1:
34737 - __asm__("lcall *(%%esi); cld\n\t"
34738 + __asm__("movw %w6, %%ds\n\t"
34739 + "lcall *%%ss:(%%esi); cld\n\t"
34740 + "push %%ss\n\t"
34741 + "pop %%ds\n\t"
34742 "jc 1f\n\t"
34743 "xor %%ah, %%ah\n"
34744 "1:"
34745 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34746 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34747 "b" (bx),
34748 "D" ((long)reg),
34749 - "S" (&pci_indirect));
34750 + "S" (&pci_indirect),
34751 + "r" (__PCIBIOS_DS));
34752 /*
34753 * Zero-extend the result beyond 8 bits, do not trust the
34754 * BIOS having done it:
34755 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34756 *value &= 0xff;
34757 break;
34758 case 2:
34759 - __asm__("lcall *(%%esi); cld\n\t"
34760 + __asm__("movw %w6, %%ds\n\t"
34761 + "lcall *%%ss:(%%esi); cld\n\t"
34762 + "push %%ss\n\t"
34763 + "pop %%ds\n\t"
34764 "jc 1f\n\t"
34765 "xor %%ah, %%ah\n"
34766 "1:"
34767 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34768 : "1" (PCIBIOS_READ_CONFIG_WORD),
34769 "b" (bx),
34770 "D" ((long)reg),
34771 - "S" (&pci_indirect));
34772 + "S" (&pci_indirect),
34773 + "r" (__PCIBIOS_DS));
34774 /*
34775 * Zero-extend the result beyond 16 bits, do not trust the
34776 * BIOS having done it:
34777 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34778 *value &= 0xffff;
34779 break;
34780 case 4:
34781 - __asm__("lcall *(%%esi); cld\n\t"
34782 + __asm__("movw %w6, %%ds\n\t"
34783 + "lcall *%%ss:(%%esi); cld\n\t"
34784 + "push %%ss\n\t"
34785 + "pop %%ds\n\t"
34786 "jc 1f\n\t"
34787 "xor %%ah, %%ah\n"
34788 "1:"
34789 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34790 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34791 "b" (bx),
34792 "D" ((long)reg),
34793 - "S" (&pci_indirect));
34794 + "S" (&pci_indirect),
34795 + "r" (__PCIBIOS_DS));
34796 break;
34797 }
34798
34799 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34800
34801 switch (len) {
34802 case 1:
34803 - __asm__("lcall *(%%esi); cld\n\t"
34804 + __asm__("movw %w6, %%ds\n\t"
34805 + "lcall *%%ss:(%%esi); cld\n\t"
34806 + "push %%ss\n\t"
34807 + "pop %%ds\n\t"
34808 "jc 1f\n\t"
34809 "xor %%ah, %%ah\n"
34810 "1:"
34811 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34812 "c" (value),
34813 "b" (bx),
34814 "D" ((long)reg),
34815 - "S" (&pci_indirect));
34816 + "S" (&pci_indirect),
34817 + "r" (__PCIBIOS_DS));
34818 break;
34819 case 2:
34820 - __asm__("lcall *(%%esi); cld\n\t"
34821 + __asm__("movw %w6, %%ds\n\t"
34822 + "lcall *%%ss:(%%esi); cld\n\t"
34823 + "push %%ss\n\t"
34824 + "pop %%ds\n\t"
34825 "jc 1f\n\t"
34826 "xor %%ah, %%ah\n"
34827 "1:"
34828 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34829 "c" (value),
34830 "b" (bx),
34831 "D" ((long)reg),
34832 - "S" (&pci_indirect));
34833 + "S" (&pci_indirect),
34834 + "r" (__PCIBIOS_DS));
34835 break;
34836 case 4:
34837 - __asm__("lcall *(%%esi); cld\n\t"
34838 + __asm__("movw %w6, %%ds\n\t"
34839 + "lcall *%%ss:(%%esi); cld\n\t"
34840 + "push %%ss\n\t"
34841 + "pop %%ds\n\t"
34842 "jc 1f\n\t"
34843 "xor %%ah, %%ah\n"
34844 "1:"
34845 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34846 "c" (value),
34847 "b" (bx),
34848 "D" ((long)reg),
34849 - "S" (&pci_indirect));
34850 + "S" (&pci_indirect),
34851 + "r" (__PCIBIOS_DS));
34852 break;
34853 }
34854
34855 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34856
34857 DBG("PCI: Fetching IRQ routing table... ");
34858 __asm__("push %%es\n\t"
34859 + "movw %w8, %%ds\n\t"
34860 "push %%ds\n\t"
34861 "pop %%es\n\t"
34862 - "lcall *(%%esi); cld\n\t"
34863 + "lcall *%%ss:(%%esi); cld\n\t"
34864 "pop %%es\n\t"
34865 + "push %%ss\n\t"
34866 + "pop %%ds\n"
34867 "jc 1f\n\t"
34868 "xor %%ah, %%ah\n"
34869 "1:"
34870 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34871 "1" (0),
34872 "D" ((long) &opt),
34873 "S" (&pci_indirect),
34874 - "m" (opt)
34875 + "m" (opt),
34876 + "r" (__PCIBIOS_DS)
34877 : "memory");
34878 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34879 if (ret & 0xff00)
34880 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34881 {
34882 int ret;
34883
34884 - __asm__("lcall *(%%esi); cld\n\t"
34885 + __asm__("movw %w5, %%ds\n\t"
34886 + "lcall *%%ss:(%%esi); cld\n\t"
34887 + "push %%ss\n\t"
34888 + "pop %%ds\n"
34889 "jc 1f\n\t"
34890 "xor %%ah, %%ah\n"
34891 "1:"
34892 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34893 : "0" (PCIBIOS_SET_PCI_HW_INT),
34894 "b" ((dev->bus->number << 8) | dev->devfn),
34895 "c" ((irq << 8) | (pin + 10)),
34896 - "S" (&pci_indirect));
34897 + "S" (&pci_indirect),
34898 + "r" (__PCIBIOS_DS));
34899 return !(ret & 0xff00);
34900 }
34901 EXPORT_SYMBOL(pcibios_set_irq_routing);
34902 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34903 index 9ee3491..872192f 100644
34904 --- a/arch/x86/platform/efi/efi_32.c
34905 +++ b/arch/x86/platform/efi/efi_32.c
34906 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34907 {
34908 struct desc_ptr gdt_descr;
34909
34910 +#ifdef CONFIG_PAX_KERNEXEC
34911 + struct desc_struct d;
34912 +#endif
34913 +
34914 local_irq_save(efi_rt_eflags);
34915
34916 load_cr3(initial_page_table);
34917 __flush_tlb_all();
34918
34919 +#ifdef CONFIG_PAX_KERNEXEC
34920 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34921 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34922 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34923 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34924 +#endif
34925 +
34926 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34927 gdt_descr.size = GDT_SIZE - 1;
34928 load_gdt(&gdt_descr);
34929 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34930 {
34931 struct desc_ptr gdt_descr;
34932
34933 +#ifdef CONFIG_PAX_KERNEXEC
34934 + struct desc_struct d;
34935 +
34936 + memset(&d, 0, sizeof d);
34937 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34938 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34939 +#endif
34940 +
34941 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34942 gdt_descr.size = GDT_SIZE - 1;
34943 load_gdt(&gdt_descr);
34944
34945 +#ifdef CONFIG_PAX_PER_CPU_PGD
34946 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34947 +#else
34948 load_cr3(swapper_pg_dir);
34949 +#endif
34950 +
34951 __flush_tlb_all();
34952
34953 local_irq_restore(efi_rt_eflags);
34954 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34955 index 666b74a..673d88f 100644
34956 --- a/arch/x86/platform/efi/efi_64.c
34957 +++ b/arch/x86/platform/efi/efi_64.c
34958 @@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
34959 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34960 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34961 }
34962 +
34963 +#ifdef CONFIG_PAX_PER_CPU_PGD
34964 + load_cr3(swapper_pg_dir);
34965 +#endif
34966 +
34967 __flush_tlb_all();
34968 }
34969
34970 @@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
34971 for (pgd = 0; pgd < n_pgds; pgd++)
34972 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34973 kfree(save_pgd);
34974 +
34975 +#ifdef CONFIG_PAX_PER_CPU_PGD
34976 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34977 +#endif
34978 +
34979 __flush_tlb_all();
34980 local_irq_restore(efi_flags);
34981 early_code_mapping_set_exec(0);
34982 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34983 index fbe66e6..eae5e38 100644
34984 --- a/arch/x86/platform/efi/efi_stub_32.S
34985 +++ b/arch/x86/platform/efi/efi_stub_32.S
34986 @@ -6,7 +6,9 @@
34987 */
34988
34989 #include <linux/linkage.h>
34990 +#include <linux/init.h>
34991 #include <asm/page_types.h>
34992 +#include <asm/segment.h>
34993
34994 /*
34995 * efi_call_phys(void *, ...) is a function with variable parameters.
34996 @@ -20,7 +22,7 @@
34997 * service functions will comply with gcc calling convention, too.
34998 */
34999
35000 -.text
35001 +__INIT
35002 ENTRY(efi_call_phys)
35003 /*
35004 * 0. The function can only be called in Linux kernel. So CS has been
35005 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
35006 * The mapping of lower virtual memory has been created in prelog and
35007 * epilog.
35008 */
35009 - movl $1f, %edx
35010 - subl $__PAGE_OFFSET, %edx
35011 - jmp *%edx
35012 +#ifdef CONFIG_PAX_KERNEXEC
35013 + movl $(__KERNEXEC_EFI_DS), %edx
35014 + mov %edx, %ds
35015 + mov %edx, %es
35016 + mov %edx, %ss
35017 + addl $2f,(1f)
35018 + ljmp *(1f)
35019 +
35020 +__INITDATA
35021 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
35022 +.previous
35023 +
35024 +2:
35025 + subl $2b,(1b)
35026 +#else
35027 + jmp 1f-__PAGE_OFFSET
35028 1:
35029 +#endif
35030
35031 /*
35032 * 2. Now on the top of stack is the return
35033 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35034 * parameter 2, ..., param n. To make things easy, we save the return
35035 * address of efi_call_phys in a global variable.
35036 */
35037 - popl %edx
35038 - movl %edx, saved_return_addr
35039 - /* get the function pointer into ECX*/
35040 - popl %ecx
35041 - movl %ecx, efi_rt_function_ptr
35042 - movl $2f, %edx
35043 - subl $__PAGE_OFFSET, %edx
35044 - pushl %edx
35045 + popl (saved_return_addr)
35046 + popl (efi_rt_function_ptr)
35047
35048 /*
35049 * 3. Clear PG bit in %CR0.
35050 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35051 /*
35052 * 5. Call the physical function.
35053 */
35054 - jmp *%ecx
35055 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
35056
35057 -2:
35058 /*
35059 * 6. After EFI runtime service returns, control will return to
35060 * following instruction. We'd better readjust stack pointer first.
35061 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35062 movl %cr0, %edx
35063 orl $0x80000000, %edx
35064 movl %edx, %cr0
35065 - jmp 1f
35066 -1:
35067 +
35068 /*
35069 * 8. Now restore the virtual mode from flat mode by
35070 * adding EIP with PAGE_OFFSET.
35071 */
35072 - movl $1f, %edx
35073 - jmp *%edx
35074 +#ifdef CONFIG_PAX_KERNEXEC
35075 + movl $(__KERNEL_DS), %edx
35076 + mov %edx, %ds
35077 + mov %edx, %es
35078 + mov %edx, %ss
35079 + ljmp $(__KERNEL_CS),$1f
35080 +#else
35081 + jmp 1f+__PAGE_OFFSET
35082 +#endif
35083 1:
35084
35085 /*
35086 * 9. Balance the stack. And because EAX contain the return value,
35087 * we'd better not clobber it.
35088 */
35089 - leal efi_rt_function_ptr, %edx
35090 - movl (%edx), %ecx
35091 - pushl %ecx
35092 + pushl (efi_rt_function_ptr)
35093
35094 /*
35095 - * 10. Push the saved return address onto the stack and return.
35096 + * 10. Return to the saved return address.
35097 */
35098 - leal saved_return_addr, %edx
35099 - movl (%edx), %ecx
35100 - pushl %ecx
35101 - ret
35102 + jmpl *(saved_return_addr)
35103 ENDPROC(efi_call_phys)
35104 .previous
35105
35106 -.data
35107 +__INITDATA
35108 saved_return_addr:
35109 .long 0
35110 efi_rt_function_ptr:
35111 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35112 index 88073b1..1cc2f53 100644
35113 --- a/arch/x86/platform/efi/efi_stub_64.S
35114 +++ b/arch/x86/platform/efi/efi_stub_64.S
35115 @@ -7,6 +7,7 @@
35116 */
35117
35118 #include <linux/linkage.h>
35119 +#include <asm/alternative-asm.h>
35120
35121 #define SAVE_XMM \
35122 mov %rsp, %rax; \
35123 @@ -77,6 +78,7 @@ ENTRY(efi_call0)
35124 RESTORE_PGT
35125 addq $32, %rsp
35126 RESTORE_XMM
35127 + pax_force_retaddr 0, 1
35128 ret
35129 ENDPROC(efi_call0)
35130
35131 @@ -89,6 +91,7 @@ ENTRY(efi_call1)
35132 RESTORE_PGT
35133 addq $32, %rsp
35134 RESTORE_XMM
35135 + pax_force_retaddr 0, 1
35136 ret
35137 ENDPROC(efi_call1)
35138
35139 @@ -101,6 +104,7 @@ ENTRY(efi_call2)
35140 RESTORE_PGT
35141 addq $32, %rsp
35142 RESTORE_XMM
35143 + pax_force_retaddr 0, 1
35144 ret
35145 ENDPROC(efi_call2)
35146
35147 @@ -114,6 +118,7 @@ ENTRY(efi_call3)
35148 RESTORE_PGT
35149 addq $32, %rsp
35150 RESTORE_XMM
35151 + pax_force_retaddr 0, 1
35152 ret
35153 ENDPROC(efi_call3)
35154
35155 @@ -128,6 +133,7 @@ ENTRY(efi_call4)
35156 RESTORE_PGT
35157 addq $32, %rsp
35158 RESTORE_XMM
35159 + pax_force_retaddr 0, 1
35160 ret
35161 ENDPROC(efi_call4)
35162
35163 @@ -143,6 +149,7 @@ ENTRY(efi_call5)
35164 RESTORE_PGT
35165 addq $48, %rsp
35166 RESTORE_XMM
35167 + pax_force_retaddr 0, 1
35168 ret
35169 ENDPROC(efi_call5)
35170
35171 @@ -161,6 +168,7 @@ ENTRY(efi_call6)
35172 RESTORE_PGT
35173 addq $48, %rsp
35174 RESTORE_XMM
35175 + pax_force_retaddr 0, 1
35176 ret
35177 ENDPROC(efi_call6)
35178
35179 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35180 index 1bbedc4..eb795b5 100644
35181 --- a/arch/x86/platform/intel-mid/intel-mid.c
35182 +++ b/arch/x86/platform/intel-mid/intel-mid.c
35183 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35184 {
35185 };
35186
35187 -static void intel_mid_reboot(void)
35188 +static void __noreturn intel_mid_reboot(void)
35189 {
35190 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35191 + BUG();
35192 }
35193
35194 static unsigned long __init intel_mid_calibrate_tsc(void)
35195 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35196 index d6ee929..3637cb5 100644
35197 --- a/arch/x86/platform/olpc/olpc_dt.c
35198 +++ b/arch/x86/platform/olpc/olpc_dt.c
35199 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35200 return res;
35201 }
35202
35203 -static struct of_pdt_ops prom_olpc_ops __initdata = {
35204 +static struct of_pdt_ops prom_olpc_ops __initconst = {
35205 .nextprop = olpc_dt_nextprop,
35206 .getproplen = olpc_dt_getproplen,
35207 .getproperty = olpc_dt_getproperty,
35208 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35209 index 424f4c9..f2a2988 100644
35210 --- a/arch/x86/power/cpu.c
35211 +++ b/arch/x86/power/cpu.c
35212 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
35213 static void fix_processor_context(void)
35214 {
35215 int cpu = smp_processor_id();
35216 - struct tss_struct *t = &per_cpu(init_tss, cpu);
35217 -#ifdef CONFIG_X86_64
35218 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
35219 - tss_desc tss;
35220 -#endif
35221 + struct tss_struct *t = init_tss + cpu;
35222 +
35223 set_tss_desc(cpu, t); /*
35224 * This just modifies memory; should not be
35225 * necessary. But... This is necessary, because
35226 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
35227 */
35228
35229 #ifdef CONFIG_X86_64
35230 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35231 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35232 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35233 -
35234 syscall_init(); /* This sets MSR_*STAR and related */
35235 #endif
35236 load_TR_desc(); /* This does ltr */
35237 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35238 index bad628a..a102610 100644
35239 --- a/arch/x86/realmode/init.c
35240 +++ b/arch/x86/realmode/init.c
35241 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35242 __va(real_mode_header->trampoline_header);
35243
35244 #ifdef CONFIG_X86_32
35245 - trampoline_header->start = __pa_symbol(startup_32_smp);
35246 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35247 +
35248 +#ifdef CONFIG_PAX_KERNEXEC
35249 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35250 +#endif
35251 +
35252 + trampoline_header->boot_cs = __BOOT_CS;
35253 trampoline_header->gdt_limit = __BOOT_DS + 7;
35254 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35255 #else
35256 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35257 *trampoline_cr4_features = read_cr4();
35258
35259 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35260 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35261 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35262 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35263 #endif
35264 }
35265 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35266 index 3497f14..cc73b92 100644
35267 --- a/arch/x86/realmode/rm/Makefile
35268 +++ b/arch/x86/realmode/rm/Makefile
35269 @@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35270
35271 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35272 -I$(srctree)/arch/x86/boot
35273 +ifdef CONSTIFY_PLUGIN
35274 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35275 +endif
35276 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35277 GCOV_PROFILE := n
35278 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35279 index a28221d..93c40f1 100644
35280 --- a/arch/x86/realmode/rm/header.S
35281 +++ b/arch/x86/realmode/rm/header.S
35282 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35283 #endif
35284 /* APM/BIOS reboot */
35285 .long pa_machine_real_restart_asm
35286 -#ifdef CONFIG_X86_64
35287 +#ifdef CONFIG_X86_32
35288 + .long __KERNEL_CS
35289 +#else
35290 .long __KERNEL32_CS
35291 #endif
35292 END(real_mode_header)
35293 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35294 index 48ddd76..c26749f 100644
35295 --- a/arch/x86/realmode/rm/trampoline_32.S
35296 +++ b/arch/x86/realmode/rm/trampoline_32.S
35297 @@ -24,6 +24,12 @@
35298 #include <asm/page_types.h>
35299 #include "realmode.h"
35300
35301 +#ifdef CONFIG_PAX_KERNEXEC
35302 +#define ta(X) (X)
35303 +#else
35304 +#define ta(X) (pa_ ## X)
35305 +#endif
35306 +
35307 .text
35308 .code16
35309
35310 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35311
35312 cli # We should be safe anyway
35313
35314 - movl tr_start, %eax # where we need to go
35315 -
35316 movl $0xA5A5A5A5, trampoline_status
35317 # write marker for master knows we're running
35318
35319 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35320 movw $1, %dx # protected mode (PE) bit
35321 lmsw %dx # into protected mode
35322
35323 - ljmpl $__BOOT_CS, $pa_startup_32
35324 + ljmpl *(trampoline_header)
35325
35326 .section ".text32","ax"
35327 .code32
35328 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35329 .balign 8
35330 GLOBAL(trampoline_header)
35331 tr_start: .space 4
35332 - tr_gdt_pad: .space 2
35333 + tr_boot_cs: .space 2
35334 tr_gdt: .space 6
35335 END(trampoline_header)
35336
35337 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35338 index dac7b20..72dbaca 100644
35339 --- a/arch/x86/realmode/rm/trampoline_64.S
35340 +++ b/arch/x86/realmode/rm/trampoline_64.S
35341 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35342 movl %edx, %gs
35343
35344 movl pa_tr_cr4, %eax
35345 + andl $~X86_CR4_PCIDE, %eax
35346 movl %eax, %cr4 # Enable PAE mode
35347
35348 # Setup trampoline 4 level pagetables
35349 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35350 wrmsr
35351
35352 # Enable paging and in turn activate Long Mode
35353 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35354 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35355 movl %eax, %cr0
35356
35357 /*
35358 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35359 index 9e7e147..25a4158 100644
35360 --- a/arch/x86/realmode/rm/wakeup_asm.S
35361 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35362 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35363 lgdtl pmode_gdt
35364
35365 /* This really couldn't... */
35366 - movl pmode_entry, %eax
35367 movl pmode_cr0, %ecx
35368 movl %ecx, %cr0
35369 - ljmpl $__KERNEL_CS, $pa_startup_32
35370 - /* -> jmp *%eax in trampoline_32.S */
35371 +
35372 + ljmpl *pmode_entry
35373 #else
35374 jmp trampoline_start
35375 #endif
35376 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35377 index e812034..c747134 100644
35378 --- a/arch/x86/tools/Makefile
35379 +++ b/arch/x86/tools/Makefile
35380 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35381
35382 $(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
35383
35384 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35385 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35386 hostprogs-y += relocs
35387 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35388 relocs: $(obj)/relocs
35389 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35390 index cfbdbdb..1aa763c 100644
35391 --- a/arch/x86/tools/relocs.c
35392 +++ b/arch/x86/tools/relocs.c
35393 @@ -1,5 +1,7 @@
35394 /* This is included from relocs_32/64.c */
35395
35396 +#include "../../../include/generated/autoconf.h"
35397 +
35398 #define ElfW(type) _ElfW(ELF_BITS, type)
35399 #define _ElfW(bits, type) __ElfW(bits, type)
35400 #define __ElfW(bits, type) Elf##bits##_##type
35401 @@ -11,6 +13,7 @@
35402 #define Elf_Sym ElfW(Sym)
35403
35404 static Elf_Ehdr ehdr;
35405 +static Elf_Phdr *phdr;
35406
35407 struct relocs {
35408 uint32_t *offset;
35409 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35410 }
35411 }
35412
35413 +static void read_phdrs(FILE *fp)
35414 +{
35415 + unsigned int i;
35416 +
35417 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35418 + if (!phdr) {
35419 + die("Unable to allocate %d program headers\n",
35420 + ehdr.e_phnum);
35421 + }
35422 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35423 + die("Seek to %d failed: %s\n",
35424 + ehdr.e_phoff, strerror(errno));
35425 + }
35426 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35427 + die("Cannot read ELF program headers: %s\n",
35428 + strerror(errno));
35429 + }
35430 + for(i = 0; i < ehdr.e_phnum; i++) {
35431 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35432 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35433 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35434 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35435 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35436 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35437 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35438 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35439 + }
35440 +
35441 +}
35442 +
35443 static void read_shdrs(FILE *fp)
35444 {
35445 - int i;
35446 + unsigned int i;
35447 Elf_Shdr shdr;
35448
35449 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35450 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35451
35452 static void read_strtabs(FILE *fp)
35453 {
35454 - int i;
35455 + unsigned int i;
35456 for (i = 0; i < ehdr.e_shnum; i++) {
35457 struct section *sec = &secs[i];
35458 if (sec->shdr.sh_type != SHT_STRTAB) {
35459 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35460
35461 static void read_symtabs(FILE *fp)
35462 {
35463 - int i,j;
35464 + unsigned int i,j;
35465 for (i = 0; i < ehdr.e_shnum; i++) {
35466 struct section *sec = &secs[i];
35467 if (sec->shdr.sh_type != SHT_SYMTAB) {
35468 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35469 }
35470
35471
35472 -static void read_relocs(FILE *fp)
35473 +static void read_relocs(FILE *fp, int use_real_mode)
35474 {
35475 - int i,j;
35476 + unsigned int i,j;
35477 + uint32_t base;
35478 +
35479 for (i = 0; i < ehdr.e_shnum; i++) {
35480 struct section *sec = &secs[i];
35481 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35482 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35483 die("Cannot read symbol table: %s\n",
35484 strerror(errno));
35485 }
35486 + base = 0;
35487 +
35488 +#ifdef CONFIG_X86_32
35489 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35490 + if (phdr[j].p_type != PT_LOAD )
35491 + continue;
35492 + 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)
35493 + continue;
35494 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35495 + break;
35496 + }
35497 +#endif
35498 +
35499 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35500 Elf_Rel *rel = &sec->reltab[j];
35501 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35502 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35503 rel->r_info = elf_xword_to_cpu(rel->r_info);
35504 #if (SHT_REL_TYPE == SHT_RELA)
35505 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35506 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35507
35508 static void print_absolute_symbols(void)
35509 {
35510 - int i;
35511 + unsigned int i;
35512 const char *format;
35513
35514 if (ELF_BITS == 64)
35515 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35516 for (i = 0; i < ehdr.e_shnum; i++) {
35517 struct section *sec = &secs[i];
35518 char *sym_strtab;
35519 - int j;
35520 + unsigned int j;
35521
35522 if (sec->shdr.sh_type != SHT_SYMTAB) {
35523 continue;
35524 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35525
35526 static void print_absolute_relocs(void)
35527 {
35528 - int i, printed = 0;
35529 + unsigned int i, printed = 0;
35530 const char *format;
35531
35532 if (ELF_BITS == 64)
35533 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35534 struct section *sec_applies, *sec_symtab;
35535 char *sym_strtab;
35536 Elf_Sym *sh_symtab;
35537 - int j;
35538 + unsigned int j;
35539 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35540 continue;
35541 }
35542 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35543 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35544 Elf_Sym *sym, const char *symname))
35545 {
35546 - int i;
35547 + unsigned int i;
35548 /* Walk through the relocations */
35549 for (i = 0; i < ehdr.e_shnum; i++) {
35550 char *sym_strtab;
35551 Elf_Sym *sh_symtab;
35552 struct section *sec_applies, *sec_symtab;
35553 - int j;
35554 + unsigned int j;
35555 struct section *sec = &secs[i];
35556
35557 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35558 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35559 {
35560 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35561 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35562 + char *sym_strtab = sec->link->link->strtab;
35563 +
35564 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35565 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35566 + return 0;
35567 +
35568 +#ifdef CONFIG_PAX_KERNEXEC
35569 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35570 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35571 + return 0;
35572 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35573 + return 0;
35574 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35575 + return 0;
35576 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35577 + return 0;
35578 +#endif
35579
35580 switch (r_type) {
35581 case R_386_NONE:
35582 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35583
35584 static void emit_relocs(int as_text, int use_real_mode)
35585 {
35586 - int i;
35587 + unsigned int i;
35588 int (*write_reloc)(uint32_t, FILE *) = write32;
35589 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35590 const char *symname);
35591 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35592 {
35593 regex_init(use_real_mode);
35594 read_ehdr(fp);
35595 + read_phdrs(fp);
35596 read_shdrs(fp);
35597 read_strtabs(fp);
35598 read_symtabs(fp);
35599 - read_relocs(fp);
35600 + read_relocs(fp, use_real_mode);
35601 if (ELF_BITS == 64)
35602 percpu_init();
35603 if (show_absolute_syms) {
35604 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35605 index 80ffa5b..a33bd15 100644
35606 --- a/arch/x86/um/tls_32.c
35607 +++ b/arch/x86/um/tls_32.c
35608 @@ -260,7 +260,7 @@ out:
35609 if (unlikely(task == current &&
35610 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35611 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35612 - "without flushed TLS.", current->pid);
35613 + "without flushed TLS.", task_pid_nr(current));
35614 }
35615
35616 return 0;
35617 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35618 index fd14be1..e3c79c0 100644
35619 --- a/arch/x86/vdso/Makefile
35620 +++ b/arch/x86/vdso/Makefile
35621 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35622 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35623 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35624
35625 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35626 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35627 GCOV_PROFILE := n
35628
35629 #
35630 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35631 index d6bfb87..a75c5f7 100644
35632 --- a/arch/x86/vdso/vdso32-setup.c
35633 +++ b/arch/x86/vdso/vdso32-setup.c
35634 @@ -25,6 +25,7 @@
35635 #include <asm/tlbflush.h>
35636 #include <asm/vdso.h>
35637 #include <asm/proto.h>
35638 +#include <asm/mman.h>
35639
35640 enum {
35641 VDSO_DISABLED = 0,
35642 @@ -41,6 +42,7 @@ enum {
35643 #ifdef CONFIG_X86_64
35644 #define vdso_enabled sysctl_vsyscall32
35645 #define arch_setup_additional_pages syscall32_setup_pages
35646 +extern int sysctl_ldt16;
35647 #endif
35648
35649 /*
35650 @@ -226,7 +228,7 @@ static inline void map_compat_vdso(int map)
35651 void enable_sep_cpu(void)
35652 {
35653 int cpu = get_cpu();
35654 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
35655 + struct tss_struct *tss = init_tss + cpu;
35656
35657 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35658 put_cpu();
35659 @@ -249,7 +251,7 @@ static int __init gate_vma_init(void)
35660 gate_vma.vm_start = FIXADDR_USER_START;
35661 gate_vma.vm_end = FIXADDR_USER_END;
35662 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35663 - gate_vma.vm_page_prot = __P101;
35664 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35665
35666 return 0;
35667 }
35668 @@ -330,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35669 if (compat)
35670 addr = VDSO_HIGH_BASE;
35671 else {
35672 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35673 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35674 if (IS_ERR_VALUE(addr)) {
35675 ret = addr;
35676 goto up_fail;
35677 }
35678 }
35679
35680 - current->mm->context.vdso = (void *)addr;
35681 + current->mm->context.vdso = addr;
35682
35683 if (compat_uses_vma || !compat) {
35684 /*
35685 @@ -353,11 +355,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35686 }
35687
35688 current_thread_info()->sysenter_return =
35689 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35690 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35691
35692 up_fail:
35693 if (ret)
35694 - current->mm->context.vdso = NULL;
35695 + current->mm->context.vdso = 0;
35696
35697 up_write(&mm->mmap_sem);
35698
35699 @@ -380,6 +382,13 @@ static struct ctl_table abi_table2[] = {
35700 .mode = 0644,
35701 .proc_handler = proc_dointvec
35702 },
35703 + {
35704 + .procname = "ldt16",
35705 + .data = &sysctl_ldt16,
35706 + .maxlen = sizeof(int),
35707 + .mode = 0644,
35708 + .proc_handler = proc_dointvec
35709 + },
35710 {}
35711 };
35712
35713 @@ -404,8 +413,14 @@ __initcall(ia32_binfmt_init);
35714
35715 const char *arch_vma_name(struct vm_area_struct *vma)
35716 {
35717 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35718 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35719 return "[vdso]";
35720 +
35721 +#ifdef CONFIG_PAX_SEGMEXEC
35722 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35723 + return "[vdso]";
35724 +#endif
35725 +
35726 return NULL;
35727 }
35728
35729 @@ -415,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35730 * Check to see if the corresponding task was created in compat vdso
35731 * mode.
35732 */
35733 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35734 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35735 return &gate_vma;
35736 return NULL;
35737 }
35738 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35739 index 431e875..cbb23f3 100644
35740 --- a/arch/x86/vdso/vma.c
35741 +++ b/arch/x86/vdso/vma.c
35742 @@ -16,8 +16,6 @@
35743 #include <asm/vdso.h>
35744 #include <asm/page.h>
35745
35746 -unsigned int __read_mostly vdso_enabled = 1;
35747 -
35748 extern char vdso_start[], vdso_end[];
35749 extern unsigned short vdso_sync_cpuid;
35750
35751 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35752 * unaligned here as a result of stack start randomization.
35753 */
35754 addr = PAGE_ALIGN(addr);
35755 - addr = align_vdso_addr(addr);
35756
35757 return addr;
35758 }
35759 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35760 unsigned size)
35761 {
35762 struct mm_struct *mm = current->mm;
35763 - unsigned long addr;
35764 + unsigned long addr = 0;
35765 int ret;
35766
35767 - if (!vdso_enabled)
35768 - return 0;
35769 -
35770 down_write(&mm->mmap_sem);
35771 +
35772 +#ifdef CONFIG_PAX_RANDMMAP
35773 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35774 +#endif
35775 +
35776 addr = vdso_addr(mm->start_stack, size);
35777 + addr = align_vdso_addr(addr);
35778 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35779 if (IS_ERR_VALUE(addr)) {
35780 ret = addr;
35781 goto up_fail;
35782 }
35783
35784 - current->mm->context.vdso = (void *)addr;
35785 + mm->context.vdso = addr;
35786
35787 ret = install_special_mapping(mm, addr, size,
35788 VM_READ|VM_EXEC|
35789 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35790 pages);
35791 - if (ret) {
35792 - current->mm->context.vdso = NULL;
35793 - goto up_fail;
35794 - }
35795 + if (ret)
35796 + mm->context.vdso = 0;
35797
35798 up_fail:
35799 up_write(&mm->mmap_sem);
35800 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35801 vdsox32_size);
35802 }
35803 #endif
35804 -
35805 -static __init int vdso_setup(char *s)
35806 -{
35807 - vdso_enabled = simple_strtoul(s, NULL, 0);
35808 - return 0;
35809 -}
35810 -__setup("vdso=", vdso_setup);
35811 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35812 index 01b9026..1e476df 100644
35813 --- a/arch/x86/xen/Kconfig
35814 +++ b/arch/x86/xen/Kconfig
35815 @@ -9,6 +9,7 @@ config XEN
35816 select XEN_HAVE_PVMMU
35817 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35818 depends on X86_TSC
35819 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35820 help
35821 This is the Linux Xen port. Enabling this will allow the
35822 kernel to boot in a paravirtualized environment under the
35823 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35824 index 201d09a..e4723e5 100644
35825 --- a/arch/x86/xen/enlighten.c
35826 +++ b/arch/x86/xen/enlighten.c
35827 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35828
35829 struct shared_info xen_dummy_shared_info;
35830
35831 -void *xen_initial_gdt;
35832 -
35833 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35834 __read_mostly int xen_have_vector_callback;
35835 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35836 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35837 {
35838 unsigned long va = dtr->address;
35839 unsigned int size = dtr->size + 1;
35840 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35841 - unsigned long frames[pages];
35842 + unsigned long frames[65536 / PAGE_SIZE];
35843 int f;
35844
35845 /*
35846 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35847 {
35848 unsigned long va = dtr->address;
35849 unsigned int size = dtr->size + 1;
35850 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35851 - unsigned long frames[pages];
35852 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35853 int f;
35854
35855 /*
35856 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35857 * 8-byte entries, or 16 4k pages..
35858 */
35859
35860 - BUG_ON(size > 65536);
35861 + BUG_ON(size > GDT_SIZE);
35862 BUG_ON(va & ~PAGE_MASK);
35863
35864 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35865 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35866 return 0;
35867 }
35868
35869 -static void set_xen_basic_apic_ops(void)
35870 +static void __init set_xen_basic_apic_ops(void)
35871 {
35872 apic->read = xen_apic_read;
35873 apic->write = xen_apic_write;
35874 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35875 #endif
35876 };
35877
35878 -static void xen_reboot(int reason)
35879 +static __noreturn void xen_reboot(int reason)
35880 {
35881 struct sched_shutdown r = { .reason = reason };
35882
35883 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35884 - BUG();
35885 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35886 + BUG();
35887 }
35888
35889 -static void xen_restart(char *msg)
35890 +static __noreturn void xen_restart(char *msg)
35891 {
35892 xen_reboot(SHUTDOWN_reboot);
35893 }
35894
35895 -static void xen_emergency_restart(void)
35896 +static __noreturn void xen_emergency_restart(void)
35897 {
35898 xen_reboot(SHUTDOWN_reboot);
35899 }
35900
35901 -static void xen_machine_halt(void)
35902 +static __noreturn void xen_machine_halt(void)
35903 {
35904 xen_reboot(SHUTDOWN_poweroff);
35905 }
35906
35907 -static void xen_machine_power_off(void)
35908 +static __noreturn void xen_machine_power_off(void)
35909 {
35910 if (pm_power_off)
35911 pm_power_off();
35912 @@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
35913 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35914
35915 /* Work out if we support NX */
35916 - x86_configure_nx();
35917 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35918 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35919 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35920 + unsigned l, h;
35921 +
35922 + __supported_pte_mask |= _PAGE_NX;
35923 + rdmsr(MSR_EFER, l, h);
35924 + l |= EFER_NX;
35925 + wrmsr(MSR_EFER, l, h);
35926 + }
35927 +#endif
35928
35929 /* Get mfn list */
35930 xen_build_dynamic_phys_to_machine();
35931 @@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
35932
35933 machine_ops = xen_machine_ops;
35934
35935 - /*
35936 - * The only reliable way to retain the initial address of the
35937 - * percpu gdt_page is to remember it here, so we can go and
35938 - * mark it RW later, when the initial percpu area is freed.
35939 - */
35940 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35941 -
35942 xen_smp_init();
35943
35944 #ifdef CONFIG_ACPI_NUMA
35945 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35946 index 2423ef0..4f6fb5b 100644
35947 --- a/arch/x86/xen/mmu.c
35948 +++ b/arch/x86/xen/mmu.c
35949 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35950 return val;
35951 }
35952
35953 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35954 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35955 {
35956 if (val & _PAGE_PRESENT) {
35957 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35958 @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35959 /* L3_k[510] -> level2_kernel_pgt
35960 * L3_i[511] -> level2_fixmap_pgt */
35961 convert_pfn_mfn(level3_kernel_pgt);
35962 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35963 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35964 + convert_pfn_mfn(level3_vmemmap_pgt);
35965 }
35966 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35967 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35968 @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35969 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35970 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35971 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35972 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35973 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35974 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35975 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35976 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35977 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35978 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35979 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35980
35981 @@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
35982 pv_mmu_ops.set_pud = xen_set_pud;
35983 #if PAGETABLE_LEVELS == 4
35984 pv_mmu_ops.set_pgd = xen_set_pgd;
35985 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35986 #endif
35987
35988 /* This will work as long as patching hasn't happened yet
35989 @@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35990 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35991 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35992 .set_pgd = xen_set_pgd_hyper,
35993 + .set_pgd_batched = xen_set_pgd_hyper,
35994
35995 .alloc_pud = xen_alloc_pmd_init,
35996 .release_pud = xen_release_pmd_init,
35997 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35998 index a18eadd..2e2f10e 100644
35999 --- a/arch/x86/xen/smp.c
36000 +++ b/arch/x86/xen/smp.c
36001 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
36002
36003 if (xen_pv_domain()) {
36004 if (!xen_feature(XENFEAT_writable_page_tables))
36005 - /* We've switched to the "real" per-cpu gdt, so make
36006 - * sure the old memory can be recycled. */
36007 - make_lowmem_page_readwrite(xen_initial_gdt);
36008 -
36009 #ifdef CONFIG_X86_32
36010 /*
36011 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
36012 * expects __USER_DS
36013 */
36014 - loadsegment(ds, __USER_DS);
36015 - loadsegment(es, __USER_DS);
36016 + loadsegment(ds, __KERNEL_DS);
36017 + loadsegment(es, __KERNEL_DS);
36018 #endif
36019
36020 xen_filter_cpu_maps();
36021 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36022 #ifdef CONFIG_X86_32
36023 /* Note: PVH is not yet supported on x86_32. */
36024 ctxt->user_regs.fs = __KERNEL_PERCPU;
36025 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
36026 + savesegment(gs, ctxt->user_regs.gs);
36027 #endif
36028 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
36029
36030 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36031 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
36032 ctxt->flags = VGCF_IN_KERNEL;
36033 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
36034 - ctxt->user_regs.ds = __USER_DS;
36035 - ctxt->user_regs.es = __USER_DS;
36036 + ctxt->user_regs.ds = __KERNEL_DS;
36037 + ctxt->user_regs.es = __KERNEL_DS;
36038 ctxt->user_regs.ss = __KERNEL_DS;
36039
36040 xen_copy_trap_info(ctxt->trap_ctxt);
36041 @@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
36042 int rc;
36043
36044 per_cpu(current_task, cpu) = idle;
36045 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
36046 #ifdef CONFIG_X86_32
36047 irq_ctx_init(cpu);
36048 #else
36049 clear_tsk_thread_flag(idle, TIF_FORK);
36050 - per_cpu(kernel_stack, cpu) =
36051 - (unsigned long)task_stack_page(idle) -
36052 - KERNEL_STACK_OFFSET + THREAD_SIZE;
36053 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36054 #endif
36055 xen_setup_runstate_info(cpu);
36056 xen_setup_timer(cpu);
36057 @@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36058
36059 void __init xen_smp_init(void)
36060 {
36061 - smp_ops = xen_smp_ops;
36062 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36063 xen_fill_possible_map();
36064 }
36065
36066 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36067 index 33ca6e4..0ded929 100644
36068 --- a/arch/x86/xen/xen-asm_32.S
36069 +++ b/arch/x86/xen/xen-asm_32.S
36070 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
36071 ESP_OFFSET=4 # bytes pushed onto stack
36072
36073 /*
36074 - * Store vcpu_info pointer for easy access. Do it this way to
36075 - * avoid having to reload %fs
36076 + * Store vcpu_info pointer for easy access.
36077 */
36078 #ifdef CONFIG_SMP
36079 - GET_THREAD_INFO(%eax)
36080 - movl %ss:TI_cpu(%eax), %eax
36081 - movl %ss:__per_cpu_offset(,%eax,4), %eax
36082 - mov %ss:xen_vcpu(%eax), %eax
36083 + push %fs
36084 + mov $(__KERNEL_PERCPU), %eax
36085 + mov %eax, %fs
36086 + mov PER_CPU_VAR(xen_vcpu), %eax
36087 + pop %fs
36088 #else
36089 movl %ss:xen_vcpu, %eax
36090 #endif
36091 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36092 index 485b695..fda3e7c 100644
36093 --- a/arch/x86/xen/xen-head.S
36094 +++ b/arch/x86/xen/xen-head.S
36095 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
36096 #ifdef CONFIG_X86_32
36097 mov %esi,xen_start_info
36098 mov $init_thread_union+THREAD_SIZE,%esp
36099 +#ifdef CONFIG_SMP
36100 + movl $cpu_gdt_table,%edi
36101 + movl $__per_cpu_load,%eax
36102 + movw %ax,__KERNEL_PERCPU + 2(%edi)
36103 + rorl $16,%eax
36104 + movb %al,__KERNEL_PERCPU + 4(%edi)
36105 + movb %ah,__KERNEL_PERCPU + 7(%edi)
36106 + movl $__per_cpu_end - 1,%eax
36107 + subl $__per_cpu_start,%eax
36108 + movw %ax,__KERNEL_PERCPU + 0(%edi)
36109 +#endif
36110 #else
36111 mov %rsi,xen_start_info
36112 mov $init_thread_union+THREAD_SIZE,%rsp
36113 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36114 index 1cb6f4c..9981524 100644
36115 --- a/arch/x86/xen/xen-ops.h
36116 +++ b/arch/x86/xen/xen-ops.h
36117 @@ -10,8 +10,6 @@
36118 extern const char xen_hypervisor_callback[];
36119 extern const char xen_failsafe_callback[];
36120
36121 -extern void *xen_initial_gdt;
36122 -
36123 struct trap_info;
36124 void xen_copy_trap_info(struct trap_info *traps);
36125
36126 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36127 index 525bd3d..ef888b1 100644
36128 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
36129 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36130 @@ -119,9 +119,9 @@
36131 ----------------------------------------------------------------------*/
36132
36133 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36134 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36135 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36136 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36137 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36138
36139 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36140 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36141 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36142 index 2f33760..835e50a 100644
36143 --- a/arch/xtensa/variants/fsf/include/variant/core.h
36144 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
36145 @@ -11,6 +11,7 @@
36146 #ifndef _XTENSA_CORE_H
36147 #define _XTENSA_CORE_H
36148
36149 +#include <linux/const.h>
36150
36151 /****************************************************************************
36152 Parameters Useful for Any Code, USER or PRIVILEGED
36153 @@ -112,9 +113,9 @@
36154 ----------------------------------------------------------------------*/
36155
36156 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36157 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36158 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36159 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36160 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36161
36162 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36163 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36164 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36165 index af00795..2bb8105 100644
36166 --- a/arch/xtensa/variants/s6000/include/variant/core.h
36167 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
36168 @@ -11,6 +11,7 @@
36169 #ifndef _XTENSA_CORE_CONFIGURATION_H
36170 #define _XTENSA_CORE_CONFIGURATION_H
36171
36172 +#include <linux/const.h>
36173
36174 /****************************************************************************
36175 Parameters Useful for Any Code, USER or PRIVILEGED
36176 @@ -118,9 +119,9 @@
36177 ----------------------------------------------------------------------*/
36178
36179 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36180 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36181 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36182 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36183 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36184
36185 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36186 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36187 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
36188 index 4e491d9..c8e18e4 100644
36189 --- a/block/blk-cgroup.c
36190 +++ b/block/blk-cgroup.c
36191 @@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
36192 static struct cgroup_subsys_state *
36193 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36194 {
36195 - static atomic64_t id_seq = ATOMIC64_INIT(0);
36196 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
36197 struct blkcg *blkcg;
36198
36199 if (!parent_css) {
36200 @@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36201
36202 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
36203 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
36204 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
36205 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
36206 done:
36207 spin_lock_init(&blkcg->lock);
36208 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
36209 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36210 index 1855bf5..af12b06 100644
36211 --- a/block/blk-iopoll.c
36212 +++ b/block/blk-iopoll.c
36213 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
36214 }
36215 EXPORT_SYMBOL(blk_iopoll_complete);
36216
36217 -static void blk_iopoll_softirq(struct softirq_action *h)
36218 +static __latent_entropy void blk_iopoll_softirq(void)
36219 {
36220 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36221 int rearm = 0, budget = blk_iopoll_budget;
36222 diff --git a/block/blk-map.c b/block/blk-map.c
36223 index ae4ae10..c470b8d 100644
36224 --- a/block/blk-map.c
36225 +++ b/block/blk-map.c
36226 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36227 if (!len || !kbuf)
36228 return -EINVAL;
36229
36230 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36231 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36232 if (do_copy)
36233 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36234 else
36235 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36236 index 57790c1..5e988dd 100644
36237 --- a/block/blk-softirq.c
36238 +++ b/block/blk-softirq.c
36239 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36240 * Softirq action handler - move entries to local list and loop over them
36241 * while passing them to the queue registered handler.
36242 */
36243 -static void blk_done_softirq(struct softirq_action *h)
36244 +static __latent_entropy void blk_done_softirq(void)
36245 {
36246 struct list_head *cpu_list, local_list;
36247
36248 diff --git a/block/bsg.c b/block/bsg.c
36249 index 420a5a9..23834aa 100644
36250 --- a/block/bsg.c
36251 +++ b/block/bsg.c
36252 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36253 struct sg_io_v4 *hdr, struct bsg_device *bd,
36254 fmode_t has_write_perm)
36255 {
36256 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36257 + unsigned char *cmdptr;
36258 +
36259 if (hdr->request_len > BLK_MAX_CDB) {
36260 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36261 if (!rq->cmd)
36262 return -ENOMEM;
36263 - }
36264 + cmdptr = rq->cmd;
36265 + } else
36266 + cmdptr = tmpcmd;
36267
36268 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36269 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36270 hdr->request_len))
36271 return -EFAULT;
36272
36273 + if (cmdptr != rq->cmd)
36274 + memcpy(rq->cmd, cmdptr, hdr->request_len);
36275 +
36276 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36277 if (blk_verify_command(rq->cmd, has_write_perm))
36278 return -EPERM;
36279 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36280 index fbd5a67..f24fd95 100644
36281 --- a/block/compat_ioctl.c
36282 +++ b/block/compat_ioctl.c
36283 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36284 cgc = compat_alloc_user_space(sizeof(*cgc));
36285 cgc32 = compat_ptr(arg);
36286
36287 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36288 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36289 get_user(data, &cgc32->buffer) ||
36290 put_user(compat_ptr(data), &cgc->buffer) ||
36291 copy_in_user(&cgc->buflen, &cgc32->buflen,
36292 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36293 err |= __get_user(f->spec1, &uf->spec1);
36294 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36295 err |= __get_user(name, &uf->name);
36296 - f->name = compat_ptr(name);
36297 + f->name = (void __force_kernel *)compat_ptr(name);
36298 if (err) {
36299 err = -EFAULT;
36300 goto out;
36301 diff --git a/block/genhd.c b/block/genhd.c
36302 index 791f419..89f21c4 100644
36303 --- a/block/genhd.c
36304 +++ b/block/genhd.c
36305 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36306
36307 /*
36308 * Register device numbers dev..(dev+range-1)
36309 - * range must be nonzero
36310 + * Noop if @range is zero.
36311 * The hash chain is sorted on range, so that subranges can override.
36312 */
36313 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36314 struct kobject *(*probe)(dev_t, int *, void *),
36315 int (*lock)(dev_t, void *), void *data)
36316 {
36317 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
36318 + if (range)
36319 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
36320 }
36321
36322 EXPORT_SYMBOL(blk_register_region);
36323
36324 +/* undo blk_register_region(), noop if @range is zero */
36325 void blk_unregister_region(dev_t devt, unsigned long range)
36326 {
36327 - kobj_unmap(bdev_map, devt, range);
36328 + if (range)
36329 + kobj_unmap(bdev_map, devt, range);
36330 }
36331
36332 EXPORT_SYMBOL(blk_unregister_region);
36333 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36334 index dc51f46..d5446a8 100644
36335 --- a/block/partitions/efi.c
36336 +++ b/block/partitions/efi.c
36337 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36338 if (!gpt)
36339 return NULL;
36340
36341 + if (!le32_to_cpu(gpt->num_partition_entries))
36342 + return NULL;
36343 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36344 + if (!pte)
36345 + return NULL;
36346 +
36347 count = le32_to_cpu(gpt->num_partition_entries) *
36348 le32_to_cpu(gpt->sizeof_partition_entry);
36349 - if (!count)
36350 - return NULL;
36351 - pte = kmalloc(count, GFP_KERNEL);
36352 - if (!pte)
36353 - return NULL;
36354 -
36355 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36356 (u8 *) pte, count) < count) {
36357 kfree(pte);
36358 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36359 index 2648797..92ed21f 100644
36360 --- a/block/scsi_ioctl.c
36361 +++ b/block/scsi_ioctl.c
36362 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36363 return put_user(0, p);
36364 }
36365
36366 -static int sg_get_timeout(struct request_queue *q)
36367 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36368 {
36369 return jiffies_to_clock_t(q->sg_timeout);
36370 }
36371 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36372 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36373 struct sg_io_hdr *hdr, fmode_t mode)
36374 {
36375 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36376 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36377 + unsigned char *cmdptr;
36378 +
36379 + if (rq->cmd != rq->__cmd)
36380 + cmdptr = rq->cmd;
36381 + else
36382 + cmdptr = tmpcmd;
36383 +
36384 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36385 return -EFAULT;
36386 +
36387 + if (cmdptr != rq->cmd)
36388 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36389 +
36390 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36391 return -EPERM;
36392
36393 @@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36394 int err;
36395 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36396 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36397 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36398 + unsigned char *cmdptr;
36399
36400 if (!sic)
36401 return -EINVAL;
36402 @@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36403 */
36404 err = -EFAULT;
36405 rq->cmd_len = cmdlen;
36406 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36407 +
36408 + if (rq->cmd != rq->__cmd)
36409 + cmdptr = rq->cmd;
36410 + else
36411 + cmdptr = tmpcmd;
36412 +
36413 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36414 goto error;
36415
36416 + if (rq->cmd != cmdptr)
36417 + memcpy(rq->cmd, cmdptr, cmdlen);
36418 +
36419 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36420 goto error;
36421
36422 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36423 index 7bdd61b..afec999 100644
36424 --- a/crypto/cryptd.c
36425 +++ b/crypto/cryptd.c
36426 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36427
36428 struct cryptd_blkcipher_request_ctx {
36429 crypto_completion_t complete;
36430 -};
36431 +} __no_const;
36432
36433 struct cryptd_hash_ctx {
36434 struct crypto_shash *child;
36435 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36436
36437 struct cryptd_aead_request_ctx {
36438 crypto_completion_t complete;
36439 -};
36440 +} __no_const;
36441
36442 static void cryptd_queue_worker(struct work_struct *work);
36443
36444 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36445 index 309d345..1632720 100644
36446 --- a/crypto/pcrypt.c
36447 +++ b/crypto/pcrypt.c
36448 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36449 int ret;
36450
36451 pinst->kobj.kset = pcrypt_kset;
36452 - ret = kobject_add(&pinst->kobj, NULL, name);
36453 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36454 if (!ret)
36455 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36456
36457 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36458 index 15dddc1..b61cf0c 100644
36459 --- a/drivers/acpi/acpica/hwxfsleep.c
36460 +++ b/drivers/acpi/acpica/hwxfsleep.c
36461 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36462 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36463
36464 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36465 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36466 - acpi_hw_extended_sleep},
36467 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36468 - acpi_hw_extended_wake_prep},
36469 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36470 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36471 + .extended_function = acpi_hw_extended_sleep},
36472 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36473 + .extended_function = acpi_hw_extended_wake_prep},
36474 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36475 + .extended_function = acpi_hw_extended_wake}
36476 };
36477
36478 /*
36479 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36480 index e5bcd91..74f050d 100644
36481 --- a/drivers/acpi/apei/apei-internal.h
36482 +++ b/drivers/acpi/apei/apei-internal.h
36483 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36484 struct apei_exec_ins_type {
36485 u32 flags;
36486 apei_exec_ins_func_t run;
36487 -};
36488 +} __do_const;
36489
36490 struct apei_exec_context {
36491 u32 ip;
36492 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36493 index dab7cb7..f0d2994 100644
36494 --- a/drivers/acpi/apei/ghes.c
36495 +++ b/drivers/acpi/apei/ghes.c
36496 @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36497 const struct acpi_hest_generic *generic,
36498 const struct acpi_generic_status *estatus)
36499 {
36500 - static atomic_t seqno;
36501 + static atomic_unchecked_t seqno;
36502 unsigned int curr_seqno;
36503 char pfx_seq[64];
36504
36505 @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36506 else
36507 pfx = KERN_ERR;
36508 }
36509 - curr_seqno = atomic_inc_return(&seqno);
36510 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36511 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36512 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36513 pfx_seq, generic->header.source_id);
36514 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36515 index a83e3c6..c3d617f 100644
36516 --- a/drivers/acpi/bgrt.c
36517 +++ b/drivers/acpi/bgrt.c
36518 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36519 if (!bgrt_image)
36520 return -ENODEV;
36521
36522 - bin_attr_image.private = bgrt_image;
36523 - bin_attr_image.size = bgrt_image_size;
36524 + pax_open_kernel();
36525 + *(void **)&bin_attr_image.private = bgrt_image;
36526 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36527 + pax_close_kernel();
36528
36529 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36530 if (!bgrt_kobj)
36531 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36532 index afec452..c5d8b96 100644
36533 --- a/drivers/acpi/blacklist.c
36534 +++ b/drivers/acpi/blacklist.c
36535 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36536 u32 is_critical_error;
36537 };
36538
36539 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36540 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36541
36542 /*
36543 * POLICY: If *anything* doesn't work, put it on the blacklist.
36544 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36545 return 0;
36546 }
36547
36548 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36549 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36550 {
36551 .callback = dmi_disable_osi_vista,
36552 .ident = "Fujitsu Siemens",
36553 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36554 index c68e724..e863008 100644
36555 --- a/drivers/acpi/custom_method.c
36556 +++ b/drivers/acpi/custom_method.c
36557 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36558 struct acpi_table_header table;
36559 acpi_status status;
36560
36561 +#ifdef CONFIG_GRKERNSEC_KMEM
36562 + return -EPERM;
36563 +#endif
36564 +
36565 if (!(*ppos)) {
36566 /* parse the table header to get the table length */
36567 if (count <= sizeof(struct acpi_table_header))
36568 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36569 index 3dca36d..abaf070 100644
36570 --- a/drivers/acpi/processor_idle.c
36571 +++ b/drivers/acpi/processor_idle.c
36572 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36573 {
36574 int i, count = CPUIDLE_DRIVER_STATE_START;
36575 struct acpi_processor_cx *cx;
36576 - struct cpuidle_state *state;
36577 + cpuidle_state_no_const *state;
36578 struct cpuidle_driver *drv = &acpi_idle_driver;
36579
36580 if (!pr->flags.power_setup_done)
36581 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36582 index 91a32ce..d77fcaf 100644
36583 --- a/drivers/acpi/sysfs.c
36584 +++ b/drivers/acpi/sysfs.c
36585 @@ -425,11 +425,11 @@ static u32 num_counters;
36586 static struct attribute **all_attrs;
36587 static u32 acpi_gpe_count;
36588
36589 -static struct attribute_group interrupt_stats_attr_group = {
36590 +static attribute_group_no_const interrupt_stats_attr_group = {
36591 .name = "interrupts",
36592 };
36593
36594 -static struct kobj_attribute *counter_attrs;
36595 +static kobj_attribute_no_const *counter_attrs;
36596
36597 static void delete_gpe_attr_array(void)
36598 {
36599 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36600 index 36605ab..6ef6d4b 100644
36601 --- a/drivers/ata/libahci.c
36602 +++ b/drivers/ata/libahci.c
36603 @@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36604 }
36605 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36606
36607 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36608 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36609 struct ata_taskfile *tf, int is_cmd, u16 flags,
36610 unsigned long timeout_msec)
36611 {
36612 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36613 index 0a79c54..c1b92ed 100644
36614 --- a/drivers/ata/libata-core.c
36615 +++ b/drivers/ata/libata-core.c
36616 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36617 static void ata_dev_xfermask(struct ata_device *dev);
36618 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36619
36620 -atomic_t ata_print_id = ATOMIC_INIT(0);
36621 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36622
36623 struct ata_force_param {
36624 const char *name;
36625 @@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36626 struct ata_port *ap;
36627 unsigned int tag;
36628
36629 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36630 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36631 ap = qc->ap;
36632
36633 qc->flags = 0;
36634 @@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36635 struct ata_port *ap;
36636 struct ata_link *link;
36637
36638 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36639 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36640 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36641 ap = qc->ap;
36642 link = qc->dev->link;
36643 @@ -5993,6 +5993,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36644 return;
36645
36646 spin_lock(&lock);
36647 + pax_open_kernel();
36648
36649 for (cur = ops->inherits; cur; cur = cur->inherits) {
36650 void **inherit = (void **)cur;
36651 @@ -6006,8 +6007,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36652 if (IS_ERR(*pp))
36653 *pp = NULL;
36654
36655 - ops->inherits = NULL;
36656 + *(struct ata_port_operations **)&ops->inherits = NULL;
36657
36658 + pax_close_kernel();
36659 spin_unlock(&lock);
36660 }
36661
36662 @@ -6200,7 +6202,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36663
36664 /* give ports names and add SCSI hosts */
36665 for (i = 0; i < host->n_ports; i++) {
36666 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36667 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36668 host->ports[i]->local_port_no = i + 1;
36669 }
36670
36671 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36672 index ef8567d..8bdbd03 100644
36673 --- a/drivers/ata/libata-scsi.c
36674 +++ b/drivers/ata/libata-scsi.c
36675 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36676
36677 if (rc)
36678 return rc;
36679 - ap->print_id = atomic_inc_return(&ata_print_id);
36680 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36681 return 0;
36682 }
36683 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36684 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36685 index 45b5ab3..98446b8 100644
36686 --- a/drivers/ata/libata.h
36687 +++ b/drivers/ata/libata.h
36688 @@ -53,7 +53,7 @@ enum {
36689 ATA_DNXFER_QUIET = (1 << 31),
36690 };
36691
36692 -extern atomic_t ata_print_id;
36693 +extern atomic_unchecked_t ata_print_id;
36694 extern int atapi_passthru16;
36695 extern int libata_fua;
36696 extern int libata_noacpi;
36697 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36698 index 73492dd..ca2bff5 100644
36699 --- a/drivers/ata/pata_arasan_cf.c
36700 +++ b/drivers/ata/pata_arasan_cf.c
36701 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36702 /* Handle platform specific quirks */
36703 if (quirk) {
36704 if (quirk & CF_BROKEN_PIO) {
36705 - ap->ops->set_piomode = NULL;
36706 + pax_open_kernel();
36707 + *(void **)&ap->ops->set_piomode = NULL;
36708 + pax_close_kernel();
36709 ap->pio_mask = 0;
36710 }
36711 if (quirk & CF_BROKEN_MWDMA)
36712 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36713 index f9b983a..887b9d8 100644
36714 --- a/drivers/atm/adummy.c
36715 +++ b/drivers/atm/adummy.c
36716 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36717 vcc->pop(vcc, skb);
36718 else
36719 dev_kfree_skb_any(skb);
36720 - atomic_inc(&vcc->stats->tx);
36721 + atomic_inc_unchecked(&vcc->stats->tx);
36722
36723 return 0;
36724 }
36725 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36726 index 62a7607..cc4be104 100644
36727 --- a/drivers/atm/ambassador.c
36728 +++ b/drivers/atm/ambassador.c
36729 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36730 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36731
36732 // VC layer stats
36733 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36734 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36735
36736 // free the descriptor
36737 kfree (tx_descr);
36738 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36739 dump_skb ("<<<", vc, skb);
36740
36741 // VC layer stats
36742 - atomic_inc(&atm_vcc->stats->rx);
36743 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36744 __net_timestamp(skb);
36745 // end of our responsibility
36746 atm_vcc->push (atm_vcc, skb);
36747 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36748 } else {
36749 PRINTK (KERN_INFO, "dropped over-size frame");
36750 // should we count this?
36751 - atomic_inc(&atm_vcc->stats->rx_drop);
36752 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36753 }
36754
36755 } else {
36756 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36757 }
36758
36759 if (check_area (skb->data, skb->len)) {
36760 - atomic_inc(&atm_vcc->stats->tx_err);
36761 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36762 return -ENOMEM; // ?
36763 }
36764
36765 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36766 index 0e3f8f9..765a7a5 100644
36767 --- a/drivers/atm/atmtcp.c
36768 +++ b/drivers/atm/atmtcp.c
36769 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36770 if (vcc->pop) vcc->pop(vcc,skb);
36771 else dev_kfree_skb(skb);
36772 if (dev_data) return 0;
36773 - atomic_inc(&vcc->stats->tx_err);
36774 + atomic_inc_unchecked(&vcc->stats->tx_err);
36775 return -ENOLINK;
36776 }
36777 size = skb->len+sizeof(struct atmtcp_hdr);
36778 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36779 if (!new_skb) {
36780 if (vcc->pop) vcc->pop(vcc,skb);
36781 else dev_kfree_skb(skb);
36782 - atomic_inc(&vcc->stats->tx_err);
36783 + atomic_inc_unchecked(&vcc->stats->tx_err);
36784 return -ENOBUFS;
36785 }
36786 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36787 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36788 if (vcc->pop) vcc->pop(vcc,skb);
36789 else dev_kfree_skb(skb);
36790 out_vcc->push(out_vcc,new_skb);
36791 - atomic_inc(&vcc->stats->tx);
36792 - atomic_inc(&out_vcc->stats->rx);
36793 + atomic_inc_unchecked(&vcc->stats->tx);
36794 + atomic_inc_unchecked(&out_vcc->stats->rx);
36795 return 0;
36796 }
36797
36798 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36799 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36800 read_unlock(&vcc_sklist_lock);
36801 if (!out_vcc) {
36802 - atomic_inc(&vcc->stats->tx_err);
36803 + atomic_inc_unchecked(&vcc->stats->tx_err);
36804 goto done;
36805 }
36806 skb_pull(skb,sizeof(struct atmtcp_hdr));
36807 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36808 __net_timestamp(new_skb);
36809 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36810 out_vcc->push(out_vcc,new_skb);
36811 - atomic_inc(&vcc->stats->tx);
36812 - atomic_inc(&out_vcc->stats->rx);
36813 + atomic_inc_unchecked(&vcc->stats->tx);
36814 + atomic_inc_unchecked(&out_vcc->stats->rx);
36815 done:
36816 if (vcc->pop) vcc->pop(vcc,skb);
36817 else dev_kfree_skb(skb);
36818 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36819 index b1955ba..b179940 100644
36820 --- a/drivers/atm/eni.c
36821 +++ b/drivers/atm/eni.c
36822 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36823 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36824 vcc->dev->number);
36825 length = 0;
36826 - atomic_inc(&vcc->stats->rx_err);
36827 + atomic_inc_unchecked(&vcc->stats->rx_err);
36828 }
36829 else {
36830 length = ATM_CELL_SIZE-1; /* no HEC */
36831 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36832 size);
36833 }
36834 eff = length = 0;
36835 - atomic_inc(&vcc->stats->rx_err);
36836 + atomic_inc_unchecked(&vcc->stats->rx_err);
36837 }
36838 else {
36839 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36840 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36841 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36842 vcc->dev->number,vcc->vci,length,size << 2,descr);
36843 length = eff = 0;
36844 - atomic_inc(&vcc->stats->rx_err);
36845 + atomic_inc_unchecked(&vcc->stats->rx_err);
36846 }
36847 }
36848 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36849 @@ -767,7 +767,7 @@ rx_dequeued++;
36850 vcc->push(vcc,skb);
36851 pushed++;
36852 }
36853 - atomic_inc(&vcc->stats->rx);
36854 + atomic_inc_unchecked(&vcc->stats->rx);
36855 }
36856 wake_up(&eni_dev->rx_wait);
36857 }
36858 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36859 PCI_DMA_TODEVICE);
36860 if (vcc->pop) vcc->pop(vcc,skb);
36861 else dev_kfree_skb_irq(skb);
36862 - atomic_inc(&vcc->stats->tx);
36863 + atomic_inc_unchecked(&vcc->stats->tx);
36864 wake_up(&eni_dev->tx_wait);
36865 dma_complete++;
36866 }
36867 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36868 index b41c948..a002b17 100644
36869 --- a/drivers/atm/firestream.c
36870 +++ b/drivers/atm/firestream.c
36871 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36872 }
36873 }
36874
36875 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36876 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36877
36878 fs_dprintk (FS_DEBUG_TXMEM, "i");
36879 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36880 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36881 #endif
36882 skb_put (skb, qe->p1 & 0xffff);
36883 ATM_SKB(skb)->vcc = atm_vcc;
36884 - atomic_inc(&atm_vcc->stats->rx);
36885 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36886 __net_timestamp(skb);
36887 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36888 atm_vcc->push (atm_vcc, skb);
36889 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36890 kfree (pe);
36891 }
36892 if (atm_vcc)
36893 - atomic_inc(&atm_vcc->stats->rx_drop);
36894 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36895 break;
36896 case 0x1f: /* Reassembly abort: no buffers. */
36897 /* Silently increment error counter. */
36898 if (atm_vcc)
36899 - atomic_inc(&atm_vcc->stats->rx_drop);
36900 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36901 break;
36902 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36903 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36904 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36905 index 204814e..cede831 100644
36906 --- a/drivers/atm/fore200e.c
36907 +++ b/drivers/atm/fore200e.c
36908 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36909 #endif
36910 /* check error condition */
36911 if (*entry->status & STATUS_ERROR)
36912 - atomic_inc(&vcc->stats->tx_err);
36913 + atomic_inc_unchecked(&vcc->stats->tx_err);
36914 else
36915 - atomic_inc(&vcc->stats->tx);
36916 + atomic_inc_unchecked(&vcc->stats->tx);
36917 }
36918 }
36919
36920 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36921 if (skb == NULL) {
36922 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36923
36924 - atomic_inc(&vcc->stats->rx_drop);
36925 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36926 return -ENOMEM;
36927 }
36928
36929 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36930
36931 dev_kfree_skb_any(skb);
36932
36933 - atomic_inc(&vcc->stats->rx_drop);
36934 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36935 return -ENOMEM;
36936 }
36937
36938 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36939
36940 vcc->push(vcc, skb);
36941 - atomic_inc(&vcc->stats->rx);
36942 + atomic_inc_unchecked(&vcc->stats->rx);
36943
36944 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36945
36946 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36947 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36948 fore200e->atm_dev->number,
36949 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36950 - atomic_inc(&vcc->stats->rx_err);
36951 + atomic_inc_unchecked(&vcc->stats->rx_err);
36952 }
36953 }
36954
36955 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36956 goto retry_here;
36957 }
36958
36959 - atomic_inc(&vcc->stats->tx_err);
36960 + atomic_inc_unchecked(&vcc->stats->tx_err);
36961
36962 fore200e->tx_sat++;
36963 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36964 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36965 index aa6be26..f70a785 100644
36966 --- a/drivers/atm/he.c
36967 +++ b/drivers/atm/he.c
36968 @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36969
36970 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36971 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36972 - atomic_inc(&vcc->stats->rx_drop);
36973 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36974 goto return_host_buffers;
36975 }
36976
36977 @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36978 RBRQ_LEN_ERR(he_dev->rbrq_head)
36979 ? "LEN_ERR" : "",
36980 vcc->vpi, vcc->vci);
36981 - atomic_inc(&vcc->stats->rx_err);
36982 + atomic_inc_unchecked(&vcc->stats->rx_err);
36983 goto return_host_buffers;
36984 }
36985
36986 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36987 vcc->push(vcc, skb);
36988 spin_lock(&he_dev->global_lock);
36989
36990 - atomic_inc(&vcc->stats->rx);
36991 + atomic_inc_unchecked(&vcc->stats->rx);
36992
36993 return_host_buffers:
36994 ++pdus_assembled;
36995 @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36996 tpd->vcc->pop(tpd->vcc, tpd->skb);
36997 else
36998 dev_kfree_skb_any(tpd->skb);
36999 - atomic_inc(&tpd->vcc->stats->tx_err);
37000 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
37001 }
37002 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
37003 return;
37004 @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37005 vcc->pop(vcc, skb);
37006 else
37007 dev_kfree_skb_any(skb);
37008 - atomic_inc(&vcc->stats->tx_err);
37009 + atomic_inc_unchecked(&vcc->stats->tx_err);
37010 return -EINVAL;
37011 }
37012
37013 @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37014 vcc->pop(vcc, skb);
37015 else
37016 dev_kfree_skb_any(skb);
37017 - atomic_inc(&vcc->stats->tx_err);
37018 + atomic_inc_unchecked(&vcc->stats->tx_err);
37019 return -EINVAL;
37020 }
37021 #endif
37022 @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37023 vcc->pop(vcc, skb);
37024 else
37025 dev_kfree_skb_any(skb);
37026 - atomic_inc(&vcc->stats->tx_err);
37027 + atomic_inc_unchecked(&vcc->stats->tx_err);
37028 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37029 return -ENOMEM;
37030 }
37031 @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37032 vcc->pop(vcc, skb);
37033 else
37034 dev_kfree_skb_any(skb);
37035 - atomic_inc(&vcc->stats->tx_err);
37036 + atomic_inc_unchecked(&vcc->stats->tx_err);
37037 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37038 return -ENOMEM;
37039 }
37040 @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37041 __enqueue_tpd(he_dev, tpd, cid);
37042 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37043
37044 - atomic_inc(&vcc->stats->tx);
37045 + atomic_inc_unchecked(&vcc->stats->tx);
37046
37047 return 0;
37048 }
37049 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
37050 index 1dc0519..1aadaf7 100644
37051 --- a/drivers/atm/horizon.c
37052 +++ b/drivers/atm/horizon.c
37053 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37054 {
37055 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37056 // VC layer stats
37057 - atomic_inc(&vcc->stats->rx);
37058 + atomic_inc_unchecked(&vcc->stats->rx);
37059 __net_timestamp(skb);
37060 // end of our responsibility
37061 vcc->push (vcc, skb);
37062 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37063 dev->tx_iovec = NULL;
37064
37065 // VC layer stats
37066 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37067 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37068
37069 // free the skb
37070 hrz_kfree_skb (skb);
37071 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37072 index 1bdf104..9dc44b1 100644
37073 --- a/drivers/atm/idt77252.c
37074 +++ b/drivers/atm/idt77252.c
37075 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37076 else
37077 dev_kfree_skb(skb);
37078
37079 - atomic_inc(&vcc->stats->tx);
37080 + atomic_inc_unchecked(&vcc->stats->tx);
37081 }
37082
37083 atomic_dec(&scq->used);
37084 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37085 if ((sb = dev_alloc_skb(64)) == NULL) {
37086 printk("%s: Can't allocate buffers for aal0.\n",
37087 card->name);
37088 - atomic_add(i, &vcc->stats->rx_drop);
37089 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37090 break;
37091 }
37092 if (!atm_charge(vcc, sb->truesize)) {
37093 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37094 card->name);
37095 - atomic_add(i - 1, &vcc->stats->rx_drop);
37096 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37097 dev_kfree_skb(sb);
37098 break;
37099 }
37100 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37101 ATM_SKB(sb)->vcc = vcc;
37102 __net_timestamp(sb);
37103 vcc->push(vcc, sb);
37104 - atomic_inc(&vcc->stats->rx);
37105 + atomic_inc_unchecked(&vcc->stats->rx);
37106
37107 cell += ATM_CELL_PAYLOAD;
37108 }
37109 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37110 "(CDC: %08x)\n",
37111 card->name, len, rpp->len, readl(SAR_REG_CDC));
37112 recycle_rx_pool_skb(card, rpp);
37113 - atomic_inc(&vcc->stats->rx_err);
37114 + atomic_inc_unchecked(&vcc->stats->rx_err);
37115 return;
37116 }
37117 if (stat & SAR_RSQE_CRC) {
37118 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37119 recycle_rx_pool_skb(card, rpp);
37120 - atomic_inc(&vcc->stats->rx_err);
37121 + atomic_inc_unchecked(&vcc->stats->rx_err);
37122 return;
37123 }
37124 if (skb_queue_len(&rpp->queue) > 1) {
37125 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37126 RXPRINTK("%s: Can't alloc RX skb.\n",
37127 card->name);
37128 recycle_rx_pool_skb(card, rpp);
37129 - atomic_inc(&vcc->stats->rx_err);
37130 + atomic_inc_unchecked(&vcc->stats->rx_err);
37131 return;
37132 }
37133 if (!atm_charge(vcc, skb->truesize)) {
37134 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37135 __net_timestamp(skb);
37136
37137 vcc->push(vcc, skb);
37138 - atomic_inc(&vcc->stats->rx);
37139 + atomic_inc_unchecked(&vcc->stats->rx);
37140
37141 return;
37142 }
37143 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37144 __net_timestamp(skb);
37145
37146 vcc->push(vcc, skb);
37147 - atomic_inc(&vcc->stats->rx);
37148 + atomic_inc_unchecked(&vcc->stats->rx);
37149
37150 if (skb->truesize > SAR_FB_SIZE_3)
37151 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37152 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37153 if (vcc->qos.aal != ATM_AAL0) {
37154 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37155 card->name, vpi, vci);
37156 - atomic_inc(&vcc->stats->rx_drop);
37157 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37158 goto drop;
37159 }
37160
37161 if ((sb = dev_alloc_skb(64)) == NULL) {
37162 printk("%s: Can't allocate buffers for AAL0.\n",
37163 card->name);
37164 - atomic_inc(&vcc->stats->rx_err);
37165 + atomic_inc_unchecked(&vcc->stats->rx_err);
37166 goto drop;
37167 }
37168
37169 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37170 ATM_SKB(sb)->vcc = vcc;
37171 __net_timestamp(sb);
37172 vcc->push(vcc, sb);
37173 - atomic_inc(&vcc->stats->rx);
37174 + atomic_inc_unchecked(&vcc->stats->rx);
37175
37176 drop:
37177 skb_pull(queue, 64);
37178 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37179
37180 if (vc == NULL) {
37181 printk("%s: NULL connection in send().\n", card->name);
37182 - atomic_inc(&vcc->stats->tx_err);
37183 + atomic_inc_unchecked(&vcc->stats->tx_err);
37184 dev_kfree_skb(skb);
37185 return -EINVAL;
37186 }
37187 if (!test_bit(VCF_TX, &vc->flags)) {
37188 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37189 - atomic_inc(&vcc->stats->tx_err);
37190 + atomic_inc_unchecked(&vcc->stats->tx_err);
37191 dev_kfree_skb(skb);
37192 return -EINVAL;
37193 }
37194 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37195 break;
37196 default:
37197 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37198 - atomic_inc(&vcc->stats->tx_err);
37199 + atomic_inc_unchecked(&vcc->stats->tx_err);
37200 dev_kfree_skb(skb);
37201 return -EINVAL;
37202 }
37203
37204 if (skb_shinfo(skb)->nr_frags != 0) {
37205 printk("%s: No scatter-gather yet.\n", card->name);
37206 - atomic_inc(&vcc->stats->tx_err);
37207 + atomic_inc_unchecked(&vcc->stats->tx_err);
37208 dev_kfree_skb(skb);
37209 return -EINVAL;
37210 }
37211 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37212
37213 err = queue_skb(card, vc, skb, oam);
37214 if (err) {
37215 - atomic_inc(&vcc->stats->tx_err);
37216 + atomic_inc_unchecked(&vcc->stats->tx_err);
37217 dev_kfree_skb(skb);
37218 return err;
37219 }
37220 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37221 skb = dev_alloc_skb(64);
37222 if (!skb) {
37223 printk("%s: Out of memory in send_oam().\n", card->name);
37224 - atomic_inc(&vcc->stats->tx_err);
37225 + atomic_inc_unchecked(&vcc->stats->tx_err);
37226 return -ENOMEM;
37227 }
37228 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37229 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37230 index 4217f29..88f547a 100644
37231 --- a/drivers/atm/iphase.c
37232 +++ b/drivers/atm/iphase.c
37233 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37234 status = (u_short) (buf_desc_ptr->desc_mode);
37235 if (status & (RX_CER | RX_PTE | RX_OFL))
37236 {
37237 - atomic_inc(&vcc->stats->rx_err);
37238 + atomic_inc_unchecked(&vcc->stats->rx_err);
37239 IF_ERR(printk("IA: bad packet, dropping it");)
37240 if (status & RX_CER) {
37241 IF_ERR(printk(" cause: packet CRC error\n");)
37242 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37243 len = dma_addr - buf_addr;
37244 if (len > iadev->rx_buf_sz) {
37245 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37246 - atomic_inc(&vcc->stats->rx_err);
37247 + atomic_inc_unchecked(&vcc->stats->rx_err);
37248 goto out_free_desc;
37249 }
37250
37251 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37252 ia_vcc = INPH_IA_VCC(vcc);
37253 if (ia_vcc == NULL)
37254 {
37255 - atomic_inc(&vcc->stats->rx_err);
37256 + atomic_inc_unchecked(&vcc->stats->rx_err);
37257 atm_return(vcc, skb->truesize);
37258 dev_kfree_skb_any(skb);
37259 goto INCR_DLE;
37260 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37261 if ((length > iadev->rx_buf_sz) || (length >
37262 (skb->len - sizeof(struct cpcs_trailer))))
37263 {
37264 - atomic_inc(&vcc->stats->rx_err);
37265 + atomic_inc_unchecked(&vcc->stats->rx_err);
37266 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37267 length, skb->len);)
37268 atm_return(vcc, skb->truesize);
37269 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37270
37271 IF_RX(printk("rx_dle_intr: skb push");)
37272 vcc->push(vcc,skb);
37273 - atomic_inc(&vcc->stats->rx);
37274 + atomic_inc_unchecked(&vcc->stats->rx);
37275 iadev->rx_pkt_cnt++;
37276 }
37277 INCR_DLE:
37278 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37279 {
37280 struct k_sonet_stats *stats;
37281 stats = &PRIV(_ia_dev[board])->sonet_stats;
37282 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37283 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37284 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37285 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37286 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37287 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37288 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37289 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37290 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37291 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37292 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37293 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37294 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37295 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37296 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37297 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37298 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37299 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37300 }
37301 ia_cmds.status = 0;
37302 break;
37303 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37304 if ((desc == 0) || (desc > iadev->num_tx_desc))
37305 {
37306 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37307 - atomic_inc(&vcc->stats->tx);
37308 + atomic_inc_unchecked(&vcc->stats->tx);
37309 if (vcc->pop)
37310 vcc->pop(vcc, skb);
37311 else
37312 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37313 ATM_DESC(skb) = vcc->vci;
37314 skb_queue_tail(&iadev->tx_dma_q, skb);
37315
37316 - atomic_inc(&vcc->stats->tx);
37317 + atomic_inc_unchecked(&vcc->stats->tx);
37318 iadev->tx_pkt_cnt++;
37319 /* Increment transaction counter */
37320 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37321
37322 #if 0
37323 /* add flow control logic */
37324 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37325 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37326 if (iavcc->vc_desc_cnt > 10) {
37327 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37328 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37329 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37330 index fa7d701..1e404c7 100644
37331 --- a/drivers/atm/lanai.c
37332 +++ b/drivers/atm/lanai.c
37333 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37334 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37335 lanai_endtx(lanai, lvcc);
37336 lanai_free_skb(lvcc->tx.atmvcc, skb);
37337 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37338 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37339 }
37340
37341 /* Try to fill the buffer - don't call unless there is backlog */
37342 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37343 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37344 __net_timestamp(skb);
37345 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37346 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37347 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37348 out:
37349 lvcc->rx.buf.ptr = end;
37350 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37351 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37352 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37353 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37354 lanai->stats.service_rxnotaal5++;
37355 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37356 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37357 return 0;
37358 }
37359 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37360 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37361 int bytes;
37362 read_unlock(&vcc_sklist_lock);
37363 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37364 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37365 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37366 lvcc->stats.x.aal5.service_trash++;
37367 bytes = (SERVICE_GET_END(s) * 16) -
37368 (((unsigned long) lvcc->rx.buf.ptr) -
37369 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37370 }
37371 if (s & SERVICE_STREAM) {
37372 read_unlock(&vcc_sklist_lock);
37373 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37374 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37375 lvcc->stats.x.aal5.service_stream++;
37376 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37377 "PDU on VCI %d!\n", lanai->number, vci);
37378 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37379 return 0;
37380 }
37381 DPRINTK("got rx crc error on vci %d\n", vci);
37382 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37383 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37384 lvcc->stats.x.aal5.service_rxcrc++;
37385 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37386 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37387 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37388 index 9587e95..b45c5cb 100644
37389 --- a/drivers/atm/nicstar.c
37390 +++ b/drivers/atm/nicstar.c
37391 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37392 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37393 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37394 card->index);
37395 - atomic_inc(&vcc->stats->tx_err);
37396 + atomic_inc_unchecked(&vcc->stats->tx_err);
37397 dev_kfree_skb_any(skb);
37398 return -EINVAL;
37399 }
37400 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37401 if (!vc->tx) {
37402 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37403 card->index);
37404 - atomic_inc(&vcc->stats->tx_err);
37405 + atomic_inc_unchecked(&vcc->stats->tx_err);
37406 dev_kfree_skb_any(skb);
37407 return -EINVAL;
37408 }
37409 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37410 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37411 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37412 card->index);
37413 - atomic_inc(&vcc->stats->tx_err);
37414 + atomic_inc_unchecked(&vcc->stats->tx_err);
37415 dev_kfree_skb_any(skb);
37416 return -EINVAL;
37417 }
37418
37419 if (skb_shinfo(skb)->nr_frags != 0) {
37420 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37421 - atomic_inc(&vcc->stats->tx_err);
37422 + atomic_inc_unchecked(&vcc->stats->tx_err);
37423 dev_kfree_skb_any(skb);
37424 return -EINVAL;
37425 }
37426 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37427 }
37428
37429 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37430 - atomic_inc(&vcc->stats->tx_err);
37431 + atomic_inc_unchecked(&vcc->stats->tx_err);
37432 dev_kfree_skb_any(skb);
37433 return -EIO;
37434 }
37435 - atomic_inc(&vcc->stats->tx);
37436 + atomic_inc_unchecked(&vcc->stats->tx);
37437
37438 return 0;
37439 }
37440 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37441 printk
37442 ("nicstar%d: Can't allocate buffers for aal0.\n",
37443 card->index);
37444 - atomic_add(i, &vcc->stats->rx_drop);
37445 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37446 break;
37447 }
37448 if (!atm_charge(vcc, sb->truesize)) {
37449 RXPRINTK
37450 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37451 card->index);
37452 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37453 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37454 dev_kfree_skb_any(sb);
37455 break;
37456 }
37457 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37458 ATM_SKB(sb)->vcc = vcc;
37459 __net_timestamp(sb);
37460 vcc->push(vcc, sb);
37461 - atomic_inc(&vcc->stats->rx);
37462 + atomic_inc_unchecked(&vcc->stats->rx);
37463 cell += ATM_CELL_PAYLOAD;
37464 }
37465
37466 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37467 if (iovb == NULL) {
37468 printk("nicstar%d: Out of iovec buffers.\n",
37469 card->index);
37470 - atomic_inc(&vcc->stats->rx_drop);
37471 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37472 recycle_rx_buf(card, skb);
37473 return;
37474 }
37475 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37476 small or large buffer itself. */
37477 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37478 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37479 - atomic_inc(&vcc->stats->rx_err);
37480 + atomic_inc_unchecked(&vcc->stats->rx_err);
37481 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37482 NS_MAX_IOVECS);
37483 NS_PRV_IOVCNT(iovb) = 0;
37484 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37485 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37486 card->index);
37487 which_list(card, skb);
37488 - atomic_inc(&vcc->stats->rx_err);
37489 + atomic_inc_unchecked(&vcc->stats->rx_err);
37490 recycle_rx_buf(card, skb);
37491 vc->rx_iov = NULL;
37492 recycle_iov_buf(card, iovb);
37493 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37494 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37495 card->index);
37496 which_list(card, skb);
37497 - atomic_inc(&vcc->stats->rx_err);
37498 + atomic_inc_unchecked(&vcc->stats->rx_err);
37499 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37500 NS_PRV_IOVCNT(iovb));
37501 vc->rx_iov = NULL;
37502 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37503 printk(" - PDU size mismatch.\n");
37504 else
37505 printk(".\n");
37506 - atomic_inc(&vcc->stats->rx_err);
37507 + atomic_inc_unchecked(&vcc->stats->rx_err);
37508 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37509 NS_PRV_IOVCNT(iovb));
37510 vc->rx_iov = NULL;
37511 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37512 /* skb points to a small buffer */
37513 if (!atm_charge(vcc, skb->truesize)) {
37514 push_rxbufs(card, skb);
37515 - atomic_inc(&vcc->stats->rx_drop);
37516 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37517 } else {
37518 skb_put(skb, len);
37519 dequeue_sm_buf(card, skb);
37520 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37521 ATM_SKB(skb)->vcc = vcc;
37522 __net_timestamp(skb);
37523 vcc->push(vcc, skb);
37524 - atomic_inc(&vcc->stats->rx);
37525 + atomic_inc_unchecked(&vcc->stats->rx);
37526 }
37527 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37528 struct sk_buff *sb;
37529 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37530 if (len <= NS_SMBUFSIZE) {
37531 if (!atm_charge(vcc, sb->truesize)) {
37532 push_rxbufs(card, sb);
37533 - atomic_inc(&vcc->stats->rx_drop);
37534 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37535 } else {
37536 skb_put(sb, len);
37537 dequeue_sm_buf(card, sb);
37538 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37539 ATM_SKB(sb)->vcc = vcc;
37540 __net_timestamp(sb);
37541 vcc->push(vcc, sb);
37542 - atomic_inc(&vcc->stats->rx);
37543 + atomic_inc_unchecked(&vcc->stats->rx);
37544 }
37545
37546 push_rxbufs(card, skb);
37547 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37548
37549 if (!atm_charge(vcc, skb->truesize)) {
37550 push_rxbufs(card, skb);
37551 - atomic_inc(&vcc->stats->rx_drop);
37552 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37553 } else {
37554 dequeue_lg_buf(card, skb);
37555 #ifdef NS_USE_DESTRUCTORS
37556 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37557 ATM_SKB(skb)->vcc = vcc;
37558 __net_timestamp(skb);
37559 vcc->push(vcc, skb);
37560 - atomic_inc(&vcc->stats->rx);
37561 + atomic_inc_unchecked(&vcc->stats->rx);
37562 }
37563
37564 push_rxbufs(card, sb);
37565 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37566 printk
37567 ("nicstar%d: Out of huge buffers.\n",
37568 card->index);
37569 - atomic_inc(&vcc->stats->rx_drop);
37570 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37571 recycle_iovec_rx_bufs(card,
37572 (struct iovec *)
37573 iovb->data,
37574 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37575 card->hbpool.count++;
37576 } else
37577 dev_kfree_skb_any(hb);
37578 - atomic_inc(&vcc->stats->rx_drop);
37579 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37580 } else {
37581 /* Copy the small buffer to the huge buffer */
37582 sb = (struct sk_buff *)iov->iov_base;
37583 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37584 #endif /* NS_USE_DESTRUCTORS */
37585 __net_timestamp(hb);
37586 vcc->push(vcc, hb);
37587 - atomic_inc(&vcc->stats->rx);
37588 + atomic_inc_unchecked(&vcc->stats->rx);
37589 }
37590 }
37591
37592 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37593 index e3fb496..d9646bf 100644
37594 --- a/drivers/atm/solos-pci.c
37595 +++ b/drivers/atm/solos-pci.c
37596 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37597 }
37598 atm_charge(vcc, skb->truesize);
37599 vcc->push(vcc, skb);
37600 - atomic_inc(&vcc->stats->rx);
37601 + atomic_inc_unchecked(&vcc->stats->rx);
37602 break;
37603
37604 case PKT_STATUS:
37605 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37606 vcc = SKB_CB(oldskb)->vcc;
37607
37608 if (vcc) {
37609 - atomic_inc(&vcc->stats->tx);
37610 + atomic_inc_unchecked(&vcc->stats->tx);
37611 solos_pop(vcc, oldskb);
37612 } else {
37613 dev_kfree_skb_irq(oldskb);
37614 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37615 index 0215934..ce9f5b1 100644
37616 --- a/drivers/atm/suni.c
37617 +++ b/drivers/atm/suni.c
37618 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37619
37620
37621 #define ADD_LIMITED(s,v) \
37622 - atomic_add((v),&stats->s); \
37623 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37624 + atomic_add_unchecked((v),&stats->s); \
37625 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37626
37627
37628 static void suni_hz(unsigned long from_timer)
37629 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37630 index 5120a96..e2572bd 100644
37631 --- a/drivers/atm/uPD98402.c
37632 +++ b/drivers/atm/uPD98402.c
37633 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37634 struct sonet_stats tmp;
37635 int error = 0;
37636
37637 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37638 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37639 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37640 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37641 if (zero && !error) {
37642 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37643
37644
37645 #define ADD_LIMITED(s,v) \
37646 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37647 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37648 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37649 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37650 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37651 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37652
37653
37654 static void stat_event(struct atm_dev *dev)
37655 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37656 if (reason & uPD98402_INT_PFM) stat_event(dev);
37657 if (reason & uPD98402_INT_PCO) {
37658 (void) GET(PCOCR); /* clear interrupt cause */
37659 - atomic_add(GET(HECCT),
37660 + atomic_add_unchecked(GET(HECCT),
37661 &PRIV(dev)->sonet_stats.uncorr_hcs);
37662 }
37663 if ((reason & uPD98402_INT_RFO) &&
37664 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37665 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37666 uPD98402_INT_LOS),PIMR); /* enable them */
37667 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37668 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37669 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37670 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37671 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37672 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37673 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37674 return 0;
37675 }
37676
37677 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37678 index 969c3c2..9b72956 100644
37679 --- a/drivers/atm/zatm.c
37680 +++ b/drivers/atm/zatm.c
37681 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37682 }
37683 if (!size) {
37684 dev_kfree_skb_irq(skb);
37685 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37686 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37687 continue;
37688 }
37689 if (!atm_charge(vcc,skb->truesize)) {
37690 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37691 skb->len = size;
37692 ATM_SKB(skb)->vcc = vcc;
37693 vcc->push(vcc,skb);
37694 - atomic_inc(&vcc->stats->rx);
37695 + atomic_inc_unchecked(&vcc->stats->rx);
37696 }
37697 zout(pos & 0xffff,MTA(mbx));
37698 #if 0 /* probably a stupid idea */
37699 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37700 skb_queue_head(&zatm_vcc->backlog,skb);
37701 break;
37702 }
37703 - atomic_inc(&vcc->stats->tx);
37704 + atomic_inc_unchecked(&vcc->stats->tx);
37705 wake_up(&zatm_vcc->tx_wait);
37706 }
37707
37708 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37709 index 59dc808..f10c74e 100644
37710 --- a/drivers/base/bus.c
37711 +++ b/drivers/base/bus.c
37712 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37713 return -EINVAL;
37714
37715 mutex_lock(&subsys->p->mutex);
37716 - list_add_tail(&sif->node, &subsys->p->interfaces);
37717 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37718 if (sif->add_dev) {
37719 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37720 while ((dev = subsys_dev_iter_next(&iter)))
37721 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37722 subsys = sif->subsys;
37723
37724 mutex_lock(&subsys->p->mutex);
37725 - list_del_init(&sif->node);
37726 + pax_list_del_init((struct list_head *)&sif->node);
37727 if (sif->remove_dev) {
37728 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37729 while ((dev = subsys_dev_iter_next(&iter)))
37730 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37731 index 25798db..15f130e 100644
37732 --- a/drivers/base/devtmpfs.c
37733 +++ b/drivers/base/devtmpfs.c
37734 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37735 if (!thread)
37736 return 0;
37737
37738 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37739 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37740 if (err)
37741 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37742 else
37743 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37744 *err = sys_unshare(CLONE_NEWNS);
37745 if (*err)
37746 goto out;
37747 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37748 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37749 if (*err)
37750 goto out;
37751 - sys_chdir("/.."); /* will traverse into overmounted root */
37752 - sys_chroot(".");
37753 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37754 + sys_chroot((char __force_user *)".");
37755 complete(&setup_done);
37756 while (1) {
37757 spin_lock(&req_lock);
37758 diff --git a/drivers/base/node.c b/drivers/base/node.c
37759 index bc9f43b..29703b8 100644
37760 --- a/drivers/base/node.c
37761 +++ b/drivers/base/node.c
37762 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37763 struct node_attr {
37764 struct device_attribute attr;
37765 enum node_states state;
37766 -};
37767 +} __do_const;
37768
37769 static ssize_t show_node_state(struct device *dev,
37770 struct device_attribute *attr, char *buf)
37771 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37772 index bfb8955..4ebff34 100644
37773 --- a/drivers/base/power/domain.c
37774 +++ b/drivers/base/power/domain.c
37775 @@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37776
37777 if (dev->power.subsys_data->domain_data) {
37778 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37779 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
37780 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37781 if (clear_td)
37782 - gpd_data->td = (struct gpd_timing_data){ 0 };
37783 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37784
37785 if (--gpd_data->refcount == 0) {
37786 dev->power.subsys_data->domain_data = NULL;
37787 @@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37788 {
37789 struct cpuidle_driver *cpuidle_drv;
37790 struct gpd_cpu_data *cpu_data;
37791 - struct cpuidle_state *idle_state;
37792 + cpuidle_state_no_const *idle_state;
37793 int ret = 0;
37794
37795 if (IS_ERR_OR_NULL(genpd) || state < 0)
37796 @@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37797 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37798 {
37799 struct gpd_cpu_data *cpu_data;
37800 - struct cpuidle_state *idle_state;
37801 + cpuidle_state_no_const *idle_state;
37802 int ret = 0;
37803
37804 if (IS_ERR_OR_NULL(genpd))
37805 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37806 index 03e089a..0e9560c 100644
37807 --- a/drivers/base/power/sysfs.c
37808 +++ b/drivers/base/power/sysfs.c
37809 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37810 return -EIO;
37811 }
37812 }
37813 - return sprintf(buf, p);
37814 + return sprintf(buf, "%s", p);
37815 }
37816
37817 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37818 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37819 index 2d56f41..8830f19 100644
37820 --- a/drivers/base/power/wakeup.c
37821 +++ b/drivers/base/power/wakeup.c
37822 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37823 * They need to be modified together atomically, so it's better to use one
37824 * atomic variable to hold them both.
37825 */
37826 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37827 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37828
37829 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37830 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37831
37832 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37833 {
37834 - unsigned int comb = atomic_read(&combined_event_count);
37835 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37836
37837 *cnt = (comb >> IN_PROGRESS_BITS);
37838 *inpr = comb & MAX_IN_PROGRESS;
37839 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37840 ws->start_prevent_time = ws->last_time;
37841
37842 /* Increment the counter of events in progress. */
37843 - cec = atomic_inc_return(&combined_event_count);
37844 + cec = atomic_inc_return_unchecked(&combined_event_count);
37845
37846 trace_wakeup_source_activate(ws->name, cec);
37847 }
37848 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37849 * Increment the counter of registered wakeup events and decrement the
37850 * couter of wakeup events in progress simultaneously.
37851 */
37852 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37853 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37854 trace_wakeup_source_deactivate(ws->name, cec);
37855
37856 split_counters(&cnt, &inpr);
37857 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37858 index e8d11b6..7b1b36f 100644
37859 --- a/drivers/base/syscore.c
37860 +++ b/drivers/base/syscore.c
37861 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37862 void register_syscore_ops(struct syscore_ops *ops)
37863 {
37864 mutex_lock(&syscore_ops_lock);
37865 - list_add_tail(&ops->node, &syscore_ops_list);
37866 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37867 mutex_unlock(&syscore_ops_lock);
37868 }
37869 EXPORT_SYMBOL_GPL(register_syscore_ops);
37870 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37871 void unregister_syscore_ops(struct syscore_ops *ops)
37872 {
37873 mutex_lock(&syscore_ops_lock);
37874 - list_del(&ops->node);
37875 + pax_list_del((struct list_head *)&ops->node);
37876 mutex_unlock(&syscore_ops_lock);
37877 }
37878 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37879 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37880 index 036e8ab..6221dec 100644
37881 --- a/drivers/block/cciss.c
37882 +++ b/drivers/block/cciss.c
37883 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37884 while (!list_empty(&h->reqQ)) {
37885 c = list_entry(h->reqQ.next, CommandList_struct, list);
37886 /* can't do anything if fifo is full */
37887 - if ((h->access.fifo_full(h))) {
37888 + if ((h->access->fifo_full(h))) {
37889 dev_warn(&h->pdev->dev, "fifo full\n");
37890 break;
37891 }
37892 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37893 h->Qdepth--;
37894
37895 /* Tell the controller execute command */
37896 - h->access.submit_command(h, c);
37897 + h->access->submit_command(h, c);
37898
37899 /* Put job onto the completed Q */
37900 addQ(&h->cmpQ, c);
37901 @@ -3447,17 +3447,17 @@ startio:
37902
37903 static inline unsigned long get_next_completion(ctlr_info_t *h)
37904 {
37905 - return h->access.command_completed(h);
37906 + return h->access->command_completed(h);
37907 }
37908
37909 static inline int interrupt_pending(ctlr_info_t *h)
37910 {
37911 - return h->access.intr_pending(h);
37912 + return h->access->intr_pending(h);
37913 }
37914
37915 static inline long interrupt_not_for_us(ctlr_info_t *h)
37916 {
37917 - return ((h->access.intr_pending(h) == 0) ||
37918 + return ((h->access->intr_pending(h) == 0) ||
37919 (h->interrupts_enabled == 0));
37920 }
37921
37922 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37923 u32 a;
37924
37925 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37926 - return h->access.command_completed(h);
37927 + return h->access->command_completed(h);
37928
37929 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37930 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37931 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37932 trans_support & CFGTBL_Trans_use_short_tags);
37933
37934 /* Change the access methods to the performant access methods */
37935 - h->access = SA5_performant_access;
37936 + h->access = &SA5_performant_access;
37937 h->transMethod = CFGTBL_Trans_Performant;
37938
37939 return;
37940 @@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37941 if (prod_index < 0)
37942 return -ENODEV;
37943 h->product_name = products[prod_index].product_name;
37944 - h->access = *(products[prod_index].access);
37945 + h->access = products[prod_index].access;
37946
37947 if (cciss_board_disabled(h)) {
37948 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37949 @@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37950 }
37951
37952 /* make sure the board interrupts are off */
37953 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37954 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37955 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37956 if (rc)
37957 goto clean2;
37958 @@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37959 * fake ones to scoop up any residual completions.
37960 */
37961 spin_lock_irqsave(&h->lock, flags);
37962 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37963 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37964 spin_unlock_irqrestore(&h->lock, flags);
37965 free_irq(h->intr[h->intr_mode], h);
37966 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37967 @@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37968 dev_info(&h->pdev->dev, "Board READY.\n");
37969 dev_info(&h->pdev->dev,
37970 "Waiting for stale completions to drain.\n");
37971 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37972 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37973 msleep(10000);
37974 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37975 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37976
37977 rc = controller_reset_failed(h->cfgtable);
37978 if (rc)
37979 @@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37980 cciss_scsi_setup(h);
37981
37982 /* Turn the interrupts on so we can service requests */
37983 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37984 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37985
37986 /* Get the firmware version */
37987 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37988 @@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37989 kfree(flush_buf);
37990 if (return_code != IO_OK)
37991 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37992 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37993 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37994 free_irq(h->intr[h->intr_mode], h);
37995 }
37996
37997 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37998 index 7fda30e..2f27946 100644
37999 --- a/drivers/block/cciss.h
38000 +++ b/drivers/block/cciss.h
38001 @@ -101,7 +101,7 @@ struct ctlr_info
38002 /* information about each logical volume */
38003 drive_info_struct *drv[CISS_MAX_LUN];
38004
38005 - struct access_method access;
38006 + struct access_method *access;
38007
38008 /* queue and queue Info */
38009 struct list_head reqQ;
38010 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
38011 }
38012
38013 static struct access_method SA5_access = {
38014 - SA5_submit_command,
38015 - SA5_intr_mask,
38016 - SA5_fifo_full,
38017 - SA5_intr_pending,
38018 - SA5_completed,
38019 + .submit_command = SA5_submit_command,
38020 + .set_intr_mask = SA5_intr_mask,
38021 + .fifo_full = SA5_fifo_full,
38022 + .intr_pending = SA5_intr_pending,
38023 + .command_completed = SA5_completed,
38024 };
38025
38026 static struct access_method SA5B_access = {
38027 - SA5_submit_command,
38028 - SA5B_intr_mask,
38029 - SA5_fifo_full,
38030 - SA5B_intr_pending,
38031 - SA5_completed,
38032 + .submit_command = SA5_submit_command,
38033 + .set_intr_mask = SA5B_intr_mask,
38034 + .fifo_full = SA5_fifo_full,
38035 + .intr_pending = SA5B_intr_pending,
38036 + .command_completed = SA5_completed,
38037 };
38038
38039 static struct access_method SA5_performant_access = {
38040 - SA5_submit_command,
38041 - SA5_performant_intr_mask,
38042 - SA5_fifo_full,
38043 - SA5_performant_intr_pending,
38044 - SA5_performant_completed,
38045 + .submit_command = SA5_submit_command,
38046 + .set_intr_mask = SA5_performant_intr_mask,
38047 + .fifo_full = SA5_fifo_full,
38048 + .intr_pending = SA5_performant_intr_pending,
38049 + .command_completed = SA5_performant_completed,
38050 };
38051
38052 struct board_type {
38053 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
38054 index 2b94403..fd6ad1f 100644
38055 --- a/drivers/block/cpqarray.c
38056 +++ b/drivers/block/cpqarray.c
38057 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38058 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38059 goto Enomem4;
38060 }
38061 - hba[i]->access.set_intr_mask(hba[i], 0);
38062 + hba[i]->access->set_intr_mask(hba[i], 0);
38063 if (request_irq(hba[i]->intr, do_ida_intr,
38064 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38065 {
38066 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38067 add_timer(&hba[i]->timer);
38068
38069 /* Enable IRQ now that spinlock and rate limit timer are set up */
38070 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38071 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38072
38073 for(j=0; j<NWD; j++) {
38074 struct gendisk *disk = ida_gendisk[i][j];
38075 @@ -694,7 +694,7 @@ DBGINFO(
38076 for(i=0; i<NR_PRODUCTS; i++) {
38077 if (board_id == products[i].board_id) {
38078 c->product_name = products[i].product_name;
38079 - c->access = *(products[i].access);
38080 + c->access = products[i].access;
38081 break;
38082 }
38083 }
38084 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38085 hba[ctlr]->intr = intr;
38086 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38087 hba[ctlr]->product_name = products[j].product_name;
38088 - hba[ctlr]->access = *(products[j].access);
38089 + hba[ctlr]->access = products[j].access;
38090 hba[ctlr]->ctlr = ctlr;
38091 hba[ctlr]->board_id = board_id;
38092 hba[ctlr]->pci_dev = NULL; /* not PCI */
38093 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38094
38095 while((c = h->reqQ) != NULL) {
38096 /* Can't do anything if we're busy */
38097 - if (h->access.fifo_full(h) == 0)
38098 + if (h->access->fifo_full(h) == 0)
38099 return;
38100
38101 /* Get the first entry from the request Q */
38102 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38103 h->Qdepth--;
38104
38105 /* Tell the controller to do our bidding */
38106 - h->access.submit_command(h, c);
38107 + h->access->submit_command(h, c);
38108
38109 /* Get onto the completion Q */
38110 addQ(&h->cmpQ, c);
38111 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38112 unsigned long flags;
38113 __u32 a,a1;
38114
38115 - istat = h->access.intr_pending(h);
38116 + istat = h->access->intr_pending(h);
38117 /* Is this interrupt for us? */
38118 if (istat == 0)
38119 return IRQ_NONE;
38120 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38121 */
38122 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38123 if (istat & FIFO_NOT_EMPTY) {
38124 - while((a = h->access.command_completed(h))) {
38125 + while((a = h->access->command_completed(h))) {
38126 a1 = a; a &= ~3;
38127 if ((c = h->cmpQ) == NULL)
38128 {
38129 @@ -1448,11 +1448,11 @@ static int sendcmd(
38130 /*
38131 * Disable interrupt
38132 */
38133 - info_p->access.set_intr_mask(info_p, 0);
38134 + info_p->access->set_intr_mask(info_p, 0);
38135 /* Make sure there is room in the command FIFO */
38136 /* Actually it should be completely empty at this time. */
38137 for (i = 200000; i > 0; i--) {
38138 - temp = info_p->access.fifo_full(info_p);
38139 + temp = info_p->access->fifo_full(info_p);
38140 if (temp != 0) {
38141 break;
38142 }
38143 @@ -1465,7 +1465,7 @@ DBG(
38144 /*
38145 * Send the cmd
38146 */
38147 - info_p->access.submit_command(info_p, c);
38148 + info_p->access->submit_command(info_p, c);
38149 complete = pollcomplete(ctlr);
38150
38151 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38152 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38153 * we check the new geometry. Then turn interrupts back on when
38154 * we're done.
38155 */
38156 - host->access.set_intr_mask(host, 0);
38157 + host->access->set_intr_mask(host, 0);
38158 getgeometry(ctlr);
38159 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38160 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38161
38162 for(i=0; i<NWD; i++) {
38163 struct gendisk *disk = ida_gendisk[ctlr][i];
38164 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38165 /* Wait (up to 2 seconds) for a command to complete */
38166
38167 for (i = 200000; i > 0; i--) {
38168 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
38169 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
38170 if (done == 0) {
38171 udelay(10); /* a short fixed delay */
38172 } else
38173 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38174 index be73e9d..7fbf140 100644
38175 --- a/drivers/block/cpqarray.h
38176 +++ b/drivers/block/cpqarray.h
38177 @@ -99,7 +99,7 @@ struct ctlr_info {
38178 drv_info_t drv[NWD];
38179 struct proc_dir_entry *proc;
38180
38181 - struct access_method access;
38182 + struct access_method *access;
38183
38184 cmdlist_t *reqQ;
38185 cmdlist_t *cmpQ;
38186 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38187 index 0e06f0c..c47b81d 100644
38188 --- a/drivers/block/drbd/drbd_int.h
38189 +++ b/drivers/block/drbd/drbd_int.h
38190 @@ -582,7 +582,7 @@ struct drbd_epoch {
38191 struct drbd_tconn *tconn;
38192 struct list_head list;
38193 unsigned int barrier_nr;
38194 - atomic_t epoch_size; /* increased on every request added. */
38195 + atomic_unchecked_t epoch_size; /* increased on every request added. */
38196 atomic_t active; /* increased on every req. added, and dec on every finished. */
38197 unsigned long flags;
38198 };
38199 @@ -1022,7 +1022,7 @@ struct drbd_conf {
38200 unsigned int al_tr_number;
38201 int al_tr_cycle;
38202 wait_queue_head_t seq_wait;
38203 - atomic_t packet_seq;
38204 + atomic_unchecked_t packet_seq;
38205 unsigned int peer_seq;
38206 spinlock_t peer_seq_lock;
38207 unsigned int minor;
38208 @@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38209 char __user *uoptval;
38210 int err;
38211
38212 - uoptval = (char __user __force *)optval;
38213 + uoptval = (char __force_user *)optval;
38214
38215 set_fs(KERNEL_DS);
38216 if (level == SOL_SOCKET)
38217 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
38218 index 89c497c..9c736ae 100644
38219 --- a/drivers/block/drbd/drbd_interval.c
38220 +++ b/drivers/block/drbd/drbd_interval.c
38221 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
38222 }
38223
38224 static const struct rb_augment_callbacks augment_callbacks = {
38225 - augment_propagate,
38226 - augment_copy,
38227 - augment_rotate,
38228 + .propagate = augment_propagate,
38229 + .copy = augment_copy,
38230 + .rotate = augment_rotate,
38231 };
38232
38233 /**
38234 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38235 index 929468e..7d934eb 100644
38236 --- a/drivers/block/drbd/drbd_main.c
38237 +++ b/drivers/block/drbd/drbd_main.c
38238 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
38239 p->sector = sector;
38240 p->block_id = block_id;
38241 p->blksize = blksize;
38242 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38243 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38244 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
38245 }
38246
38247 @@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
38248 return -EIO;
38249 p->sector = cpu_to_be64(req->i.sector);
38250 p->block_id = (unsigned long)req;
38251 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38252 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38253 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
38254 if (mdev->state.conn >= C_SYNC_SOURCE &&
38255 mdev->state.conn <= C_PAUSED_SYNC_T)
38256 @@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
38257 {
38258 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
38259
38260 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
38261 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
38262 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
38263 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
38264 kfree(tconn->current_epoch);
38265
38266 idr_destroy(&tconn->volumes);
38267 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38268 index c706d50..5e1b472 100644
38269 --- a/drivers/block/drbd/drbd_nl.c
38270 +++ b/drivers/block/drbd/drbd_nl.c
38271 @@ -3440,7 +3440,7 @@ out:
38272
38273 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38274 {
38275 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38276 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38277 struct sk_buff *msg;
38278 struct drbd_genlmsghdr *d_out;
38279 unsigned seq;
38280 @@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38281 return;
38282 }
38283
38284 - seq = atomic_inc_return(&drbd_genl_seq);
38285 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38286 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38287 if (!msg)
38288 goto failed;
38289 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38290 index d073305..4998fea 100644
38291 --- a/drivers/block/drbd/drbd_receiver.c
38292 +++ b/drivers/block/drbd/drbd_receiver.c
38293 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
38294 {
38295 int err;
38296
38297 - atomic_set(&mdev->packet_seq, 0);
38298 + atomic_set_unchecked(&mdev->packet_seq, 0);
38299 mdev->peer_seq = 0;
38300
38301 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
38302 @@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38303 do {
38304 next_epoch = NULL;
38305
38306 - epoch_size = atomic_read(&epoch->epoch_size);
38307 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38308
38309 switch (ev & ~EV_CLEANUP) {
38310 case EV_PUT:
38311 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38312 rv = FE_DESTROYED;
38313 } else {
38314 epoch->flags = 0;
38315 - atomic_set(&epoch->epoch_size, 0);
38316 + atomic_set_unchecked(&epoch->epoch_size, 0);
38317 /* atomic_set(&epoch->active, 0); is already zero */
38318 if (rv == FE_STILL_LIVE)
38319 rv = FE_RECYCLED;
38320 @@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38321 conn_wait_active_ee_empty(tconn);
38322 drbd_flush(tconn);
38323
38324 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
38325 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38326 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38327 if (epoch)
38328 break;
38329 @@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38330 }
38331
38332 epoch->flags = 0;
38333 - atomic_set(&epoch->epoch_size, 0);
38334 + atomic_set_unchecked(&epoch->epoch_size, 0);
38335 atomic_set(&epoch->active, 0);
38336
38337 spin_lock(&tconn->epoch_lock);
38338 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
38339 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38340 list_add(&epoch->list, &tconn->current_epoch->list);
38341 tconn->current_epoch = epoch;
38342 tconn->epochs++;
38343 @@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38344
38345 err = wait_for_and_update_peer_seq(mdev, peer_seq);
38346 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
38347 - atomic_inc(&tconn->current_epoch->epoch_size);
38348 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
38349 err2 = drbd_drain_block(mdev, pi->size);
38350 if (!err)
38351 err = err2;
38352 @@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38353
38354 spin_lock(&tconn->epoch_lock);
38355 peer_req->epoch = tconn->current_epoch;
38356 - atomic_inc(&peer_req->epoch->epoch_size);
38357 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38358 atomic_inc(&peer_req->epoch->active);
38359 spin_unlock(&tconn->epoch_lock);
38360
38361 @@ -4345,7 +4345,7 @@ struct data_cmd {
38362 int expect_payload;
38363 size_t pkt_size;
38364 int (*fn)(struct drbd_tconn *, struct packet_info *);
38365 -};
38366 +} __do_const;
38367
38368 static struct data_cmd drbd_cmd_handler[] = {
38369 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38370 @@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
38371 if (!list_empty(&tconn->current_epoch->list))
38372 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
38373 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38374 - atomic_set(&tconn->current_epoch->epoch_size, 0);
38375 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
38376 tconn->send.seen_any_write_yet = false;
38377
38378 conn_info(tconn, "Connection closed\n");
38379 @@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
38380 struct asender_cmd {
38381 size_t pkt_size;
38382 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
38383 -};
38384 +} __do_const;
38385
38386 static struct asender_cmd asender_tbl[] = {
38387 [P_PING] = { 0, got_Ping },
38388 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38389 index 66e8c3b..9b68dd9 100644
38390 --- a/drivers/block/loop.c
38391 +++ b/drivers/block/loop.c
38392 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38393
38394 file_start_write(file);
38395 set_fs(get_ds());
38396 - bw = file->f_op->write(file, buf, len, &pos);
38397 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38398 set_fs(old_fs);
38399 file_end_write(file);
38400 if (likely(bw == len))
38401 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38402 index 091b9ea..f5428f8 100644
38403 --- a/drivers/block/null_blk.c
38404 +++ b/drivers/block/null_blk.c
38405 @@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38406 return 0;
38407 }
38408
38409 -static struct blk_mq_ops null_mq_ops = {
38410 - .queue_rq = null_queue_rq,
38411 - .map_queue = blk_mq_map_queue,
38412 +static struct blk_mq_ops null_mq_single_ops = {
38413 + .queue_rq = null_queue_rq,
38414 + .map_queue = blk_mq_map_queue,
38415 .init_hctx = null_init_hctx,
38416 .complete = null_softirq_done_fn,
38417 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
38418 + .free_hctx = blk_mq_free_single_hw_queue,
38419 +};
38420 +
38421 +static struct blk_mq_ops null_mq_per_node_ops = {
38422 + .queue_rq = null_queue_rq,
38423 + .map_queue = blk_mq_map_queue,
38424 + .init_hctx = null_init_hctx,
38425 + .alloc_hctx = null_alloc_hctx,
38426 + .free_hctx = null_free_hctx,
38427 };
38428
38429 static struct blk_mq_reg null_mq_reg = {
38430 - .ops = &null_mq_ops,
38431 + .ops = &null_mq_single_ops,
38432 .queue_depth = 64,
38433 .cmd_size = sizeof(struct nullb_cmd),
38434 .flags = BLK_MQ_F_SHOULD_MERGE,
38435 @@ -521,13 +531,8 @@ static int null_add_dev(void)
38436 null_mq_reg.queue_depth = hw_queue_depth;
38437 null_mq_reg.nr_hw_queues = submit_queues;
38438
38439 - if (use_per_node_hctx) {
38440 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38441 - null_mq_reg.ops->free_hctx = null_free_hctx;
38442 - } else {
38443 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38444 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38445 - }
38446 + if (use_per_node_hctx)
38447 + null_mq_reg.ops = &null_mq_per_node_ops;
38448
38449 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38450 } else if (queue_mode == NULL_Q_BIO) {
38451 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38452 index a2af73d..c0b8f61 100644
38453 --- a/drivers/block/pktcdvd.c
38454 +++ b/drivers/block/pktcdvd.c
38455 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38456
38457 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38458 {
38459 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38460 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38461 }
38462
38463 /*
38464 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38465 return -EROFS;
38466 }
38467 pd->settings.fp = ti.fp;
38468 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38469 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38470
38471 if (ti.nwa_v) {
38472 pd->nwa = be32_to_cpu(ti.next_writable);
38473 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38474 index e5565fb..71be10b4 100644
38475 --- a/drivers/block/smart1,2.h
38476 +++ b/drivers/block/smart1,2.h
38477 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38478 }
38479
38480 static struct access_method smart4_access = {
38481 - smart4_submit_command,
38482 - smart4_intr_mask,
38483 - smart4_fifo_full,
38484 - smart4_intr_pending,
38485 - smart4_completed,
38486 + .submit_command = smart4_submit_command,
38487 + .set_intr_mask = smart4_intr_mask,
38488 + .fifo_full = smart4_fifo_full,
38489 + .intr_pending = smart4_intr_pending,
38490 + .command_completed = smart4_completed,
38491 };
38492
38493 /*
38494 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38495 }
38496
38497 static struct access_method smart2_access = {
38498 - smart2_submit_command,
38499 - smart2_intr_mask,
38500 - smart2_fifo_full,
38501 - smart2_intr_pending,
38502 - smart2_completed,
38503 + .submit_command = smart2_submit_command,
38504 + .set_intr_mask = smart2_intr_mask,
38505 + .fifo_full = smart2_fifo_full,
38506 + .intr_pending = smart2_intr_pending,
38507 + .command_completed = smart2_completed,
38508 };
38509
38510 /*
38511 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38512 }
38513
38514 static struct access_method smart2e_access = {
38515 - smart2e_submit_command,
38516 - smart2e_intr_mask,
38517 - smart2e_fifo_full,
38518 - smart2e_intr_pending,
38519 - smart2e_completed,
38520 + .submit_command = smart2e_submit_command,
38521 + .set_intr_mask = smart2e_intr_mask,
38522 + .fifo_full = smart2e_fifo_full,
38523 + .intr_pending = smart2e_intr_pending,
38524 + .command_completed = smart2e_completed,
38525 };
38526
38527 /*
38528 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38529 }
38530
38531 static struct access_method smart1_access = {
38532 - smart1_submit_command,
38533 - smart1_intr_mask,
38534 - smart1_fifo_full,
38535 - smart1_intr_pending,
38536 - smart1_completed,
38537 + .submit_command = smart1_submit_command,
38538 + .set_intr_mask = smart1_intr_mask,
38539 + .fifo_full = smart1_fifo_full,
38540 + .intr_pending = smart1_intr_pending,
38541 + .command_completed = smart1_completed,
38542 };
38543 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38544 index f038dba..bb74c08 100644
38545 --- a/drivers/bluetooth/btwilink.c
38546 +++ b/drivers/bluetooth/btwilink.c
38547 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38548
38549 static int bt_ti_probe(struct platform_device *pdev)
38550 {
38551 - static struct ti_st *hst;
38552 + struct ti_st *hst;
38553 struct hci_dev *hdev;
38554 int err;
38555
38556 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38557 index 8a3aff7..d7538c2 100644
38558 --- a/drivers/cdrom/cdrom.c
38559 +++ b/drivers/cdrom/cdrom.c
38560 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38561 ENSURE(reset, CDC_RESET);
38562 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38563 cdi->mc_flags = 0;
38564 - cdo->n_minors = 0;
38565 cdi->options = CDO_USE_FFLAGS;
38566
38567 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38568 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38569 else
38570 cdi->cdda_method = CDDA_OLD;
38571
38572 - if (!cdo->generic_packet)
38573 - cdo->generic_packet = cdrom_dummy_generic_packet;
38574 + if (!cdo->generic_packet) {
38575 + pax_open_kernel();
38576 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38577 + pax_close_kernel();
38578 + }
38579
38580 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38581 mutex_lock(&cdrom_mutex);
38582 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38583 if (cdi->exit)
38584 cdi->exit(cdi);
38585
38586 - cdi->ops->n_minors--;
38587 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38588 }
38589
38590 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38591 */
38592 nr = nframes;
38593 do {
38594 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38595 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38596 if (cgc.buffer)
38597 break;
38598
38599 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38600 struct cdrom_device_info *cdi;
38601 int ret;
38602
38603 - ret = scnprintf(info + *pos, max_size - *pos, header);
38604 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38605 if (!ret)
38606 return 1;
38607
38608 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38609 index 51e75ad..39c4c76 100644
38610 --- a/drivers/cdrom/gdrom.c
38611 +++ b/drivers/cdrom/gdrom.c
38612 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38613 .audio_ioctl = gdrom_audio_ioctl,
38614 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38615 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38616 - .n_minors = 1,
38617 };
38618
38619 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38620 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38621 index 1386749..5430258 100644
38622 --- a/drivers/char/Kconfig
38623 +++ b/drivers/char/Kconfig
38624 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38625
38626 config DEVKMEM
38627 bool "/dev/kmem virtual device support"
38628 - default y
38629 + default n
38630 + depends on !GRKERNSEC_KMEM
38631 help
38632 Say Y here if you want to support the /dev/kmem device. The
38633 /dev/kmem device is rarely used, but can be used for certain
38634 @@ -577,6 +578,7 @@ config DEVPORT
38635 bool
38636 depends on !M68K
38637 depends on ISA || PCI
38638 + depends on !GRKERNSEC_KMEM
38639 default y
38640
38641 source "drivers/s390/char/Kconfig"
38642 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38643 index a48e05b..6bac831 100644
38644 --- a/drivers/char/agp/compat_ioctl.c
38645 +++ b/drivers/char/agp/compat_ioctl.c
38646 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38647 return -ENOMEM;
38648 }
38649
38650 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38651 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38652 sizeof(*usegment) * ureserve.seg_count)) {
38653 kfree(usegment);
38654 kfree(ksegment);
38655 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38656 index 1b19239..963967b 100644
38657 --- a/drivers/char/agp/frontend.c
38658 +++ b/drivers/char/agp/frontend.c
38659 @@ -731,6 +731,7 @@ static int agpioc_info_wrap(struct agp_file_private *priv, void __user *arg)
38660
38661 agp_copy_info(agp_bridge, &kerninfo);
38662
38663 + memset(&userinfo, 0, sizeof(userinfo));
38664 userinfo.version.major = kerninfo.version.major;
38665 userinfo.version.minor = kerninfo.version.minor;
38666 userinfo.bridge_id = kerninfo.device->vendor |
38667 @@ -819,7 +820,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38668 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38669 return -EFAULT;
38670
38671 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38672 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38673 return -EFAULT;
38674
38675 client = agp_find_client_by_pid(reserve.pid);
38676 @@ -849,7 +850,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38677 if (segment == NULL)
38678 return -ENOMEM;
38679
38680 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38681 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38682 sizeof(struct agp_segment) * reserve.seg_count)) {
38683 kfree(segment);
38684 return -EFAULT;
38685 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38686 index 4f94375..413694e 100644
38687 --- a/drivers/char/genrtc.c
38688 +++ b/drivers/char/genrtc.c
38689 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38690 switch (cmd) {
38691
38692 case RTC_PLL_GET:
38693 + memset(&pll, 0, sizeof(pll));
38694 if (get_rtc_pll(&pll))
38695 return -EINVAL;
38696 else
38697 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38698 index d5d4cd8..22d561d 100644
38699 --- a/drivers/char/hpet.c
38700 +++ b/drivers/char/hpet.c
38701 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38702 }
38703
38704 static int
38705 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38706 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38707 struct hpet_info *info)
38708 {
38709 struct hpet_timer __iomem *timer;
38710 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38711 index 86fe45c..c0ea948 100644
38712 --- a/drivers/char/hw_random/intel-rng.c
38713 +++ b/drivers/char/hw_random/intel-rng.c
38714 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38715
38716 if (no_fwh_detect)
38717 return -ENODEV;
38718 - printk(warning);
38719 + printk("%s", warning);
38720 return -EBUSY;
38721 }
38722
38723 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38724 index ec4e10f..f2a763b 100644
38725 --- a/drivers/char/ipmi/ipmi_msghandler.c
38726 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38727 @@ -420,7 +420,7 @@ struct ipmi_smi {
38728 struct proc_dir_entry *proc_dir;
38729 char proc_dir_name[10];
38730
38731 - atomic_t stats[IPMI_NUM_STATS];
38732 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38733
38734 /*
38735 * run_to_completion duplicate of smb_info, smi_info
38736 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38737
38738
38739 #define ipmi_inc_stat(intf, stat) \
38740 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38741 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38742 #define ipmi_get_stat(intf, stat) \
38743 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38744 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38745
38746 static int is_lan_addr(struct ipmi_addr *addr)
38747 {
38748 @@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38749 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38750 init_waitqueue_head(&intf->waitq);
38751 for (i = 0; i < IPMI_NUM_STATS; i++)
38752 - atomic_set(&intf->stats[i], 0);
38753 + atomic_set_unchecked(&intf->stats[i], 0);
38754
38755 intf->proc_dir = NULL;
38756
38757 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38758 index 03f4189..e79f5e0 100644
38759 --- a/drivers/char/ipmi/ipmi_si_intf.c
38760 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38761 @@ -280,7 +280,7 @@ struct smi_info {
38762 unsigned char slave_addr;
38763
38764 /* Counters and things for the proc filesystem. */
38765 - atomic_t stats[SI_NUM_STATS];
38766 + atomic_unchecked_t stats[SI_NUM_STATS];
38767
38768 struct task_struct *thread;
38769
38770 @@ -289,9 +289,9 @@ struct smi_info {
38771 };
38772
38773 #define smi_inc_stat(smi, stat) \
38774 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38775 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38776 #define smi_get_stat(smi, stat) \
38777 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38778 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38779
38780 #define SI_MAX_PARMS 4
38781
38782 @@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
38783 atomic_set(&new_smi->req_events, 0);
38784 new_smi->run_to_completion = 0;
38785 for (i = 0; i < SI_NUM_STATS; i++)
38786 - atomic_set(&new_smi->stats[i], 0);
38787 + atomic_set_unchecked(&new_smi->stats[i], 0);
38788
38789 new_smi->interrupt_disabled = 1;
38790 atomic_set(&new_smi->stop_operation, 0);
38791 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38792 index 92c5937..1be4e4d 100644
38793 --- a/drivers/char/mem.c
38794 +++ b/drivers/char/mem.c
38795 @@ -18,6 +18,7 @@
38796 #include <linux/raw.h>
38797 #include <linux/tty.h>
38798 #include <linux/capability.h>
38799 +#include <linux/security.h>
38800 #include <linux/ptrace.h>
38801 #include <linux/device.h>
38802 #include <linux/highmem.h>
38803 @@ -36,6 +37,10 @@
38804
38805 #define DEVPORT_MINOR 4
38806
38807 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38808 +extern const struct file_operations grsec_fops;
38809 +#endif
38810 +
38811 static inline unsigned long size_inside_page(unsigned long start,
38812 unsigned long size)
38813 {
38814 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38815
38816 while (cursor < to) {
38817 if (!devmem_is_allowed(pfn)) {
38818 +#ifdef CONFIG_GRKERNSEC_KMEM
38819 + gr_handle_mem_readwrite(from, to);
38820 +#else
38821 printk(KERN_INFO
38822 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38823 current->comm, from, to);
38824 +#endif
38825 return 0;
38826 }
38827 cursor += PAGE_SIZE;
38828 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38829 }
38830 return 1;
38831 }
38832 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38833 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38834 +{
38835 + return 0;
38836 +}
38837 #else
38838 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38839 {
38840 @@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38841
38842 while (count > 0) {
38843 unsigned long remaining;
38844 + char *temp;
38845
38846 sz = size_inside_page(p, count);
38847
38848 @@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38849 if (!ptr)
38850 return -EFAULT;
38851
38852 - remaining = copy_to_user(buf, ptr, sz);
38853 +#ifdef CONFIG_PAX_USERCOPY
38854 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38855 + if (!temp) {
38856 + unxlate_dev_mem_ptr(p, ptr);
38857 + return -ENOMEM;
38858 + }
38859 + memcpy(temp, ptr, sz);
38860 +#else
38861 + temp = ptr;
38862 +#endif
38863 +
38864 + remaining = copy_to_user(buf, temp, sz);
38865 +
38866 +#ifdef CONFIG_PAX_USERCOPY
38867 + kfree(temp);
38868 +#endif
38869 +
38870 unxlate_dev_mem_ptr(p, ptr);
38871 if (remaining)
38872 return -EFAULT;
38873 @@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38874 size_t count, loff_t *ppos)
38875 {
38876 unsigned long p = *ppos;
38877 - ssize_t low_count, read, sz;
38878 + ssize_t low_count, read, sz, err = 0;
38879 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38880 - int err = 0;
38881
38882 read = 0;
38883 if (p < (unsigned long) high_memory) {
38884 @@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38885 }
38886 #endif
38887 while (low_count > 0) {
38888 + char *temp;
38889 +
38890 sz = size_inside_page(p, low_count);
38891
38892 /*
38893 @@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38894 */
38895 kbuf = xlate_dev_kmem_ptr((char *)p);
38896
38897 - if (copy_to_user(buf, kbuf, sz))
38898 +#ifdef CONFIG_PAX_USERCOPY
38899 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38900 + if (!temp)
38901 + return -ENOMEM;
38902 + memcpy(temp, kbuf, sz);
38903 +#else
38904 + temp = kbuf;
38905 +#endif
38906 +
38907 + err = copy_to_user(buf, temp, sz);
38908 +
38909 +#ifdef CONFIG_PAX_USERCOPY
38910 + kfree(temp);
38911 +#endif
38912 +
38913 + if (err)
38914 return -EFAULT;
38915 buf += sz;
38916 p += sz;
38917 @@ -821,6 +868,9 @@ static const struct memdev {
38918 #ifdef CONFIG_PRINTK
38919 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38920 #endif
38921 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38922 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38923 +#endif
38924 };
38925
38926 static int memory_open(struct inode *inode, struct file *filp)
38927 @@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
38928 continue;
38929
38930 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38931 - NULL, devlist[minor].name);
38932 + NULL, "%s", devlist[minor].name);
38933 }
38934
38935 return tty_init();
38936 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38937 index 9df78e2..01ba9ae 100644
38938 --- a/drivers/char/nvram.c
38939 +++ b/drivers/char/nvram.c
38940 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38941
38942 spin_unlock_irq(&rtc_lock);
38943
38944 - if (copy_to_user(buf, contents, tmp - contents))
38945 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38946 return -EFAULT;
38947
38948 *ppos = i;
38949 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38950 index 8320abd..ec48108 100644
38951 --- a/drivers/char/pcmcia/synclink_cs.c
38952 +++ b/drivers/char/pcmcia/synclink_cs.c
38953 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38954
38955 if (debug_level >= DEBUG_LEVEL_INFO)
38956 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38957 - __FILE__, __LINE__, info->device_name, port->count);
38958 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38959
38960 - WARN_ON(!port->count);
38961 + WARN_ON(!atomic_read(&port->count));
38962
38963 if (tty_port_close_start(port, tty, filp) == 0)
38964 goto cleanup;
38965 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38966 cleanup:
38967 if (debug_level >= DEBUG_LEVEL_INFO)
38968 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38969 - tty->driver->name, port->count);
38970 + tty->driver->name, atomic_read(&port->count));
38971 }
38972
38973 /* Wait until the transmitter is empty.
38974 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38975
38976 if (debug_level >= DEBUG_LEVEL_INFO)
38977 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38978 - __FILE__, __LINE__, tty->driver->name, port->count);
38979 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38980
38981 /* If port is closing, signal caller to try again */
38982 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38983 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38984 goto cleanup;
38985 }
38986 spin_lock(&port->lock);
38987 - port->count++;
38988 + atomic_inc(&port->count);
38989 spin_unlock(&port->lock);
38990 spin_unlock_irqrestore(&info->netlock, flags);
38991
38992 - if (port->count == 1) {
38993 + if (atomic_read(&port->count) == 1) {
38994 /* 1st open on this device, init hardware */
38995 retval = startup(info, tty);
38996 if (retval < 0)
38997 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38998 unsigned short new_crctype;
38999
39000 /* return error if TTY interface open */
39001 - if (info->port.count)
39002 + if (atomic_read(&info->port.count))
39003 return -EBUSY;
39004
39005 switch (encoding)
39006 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
39007
39008 /* arbitrate between network and tty opens */
39009 spin_lock_irqsave(&info->netlock, flags);
39010 - if (info->port.count != 0 || info->netcount != 0) {
39011 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39012 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39013 spin_unlock_irqrestore(&info->netlock, flags);
39014 return -EBUSY;
39015 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39016 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
39017
39018 /* return error if TTY interface open */
39019 - if (info->port.count)
39020 + if (atomic_read(&info->port.count))
39021 return -EBUSY;
39022
39023 if (cmd != SIOCWANDEV)
39024 diff --git a/drivers/char/random.c b/drivers/char/random.c
39025 index 429b75b..a7f4145 100644
39026 --- a/drivers/char/random.c
39027 +++ b/drivers/char/random.c
39028 @@ -270,10 +270,17 @@
39029 /*
39030 * Configuration information
39031 */
39032 +#ifdef CONFIG_GRKERNSEC_RANDNET
39033 +#define INPUT_POOL_SHIFT 14
39034 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
39035 +#define OUTPUT_POOL_SHIFT 12
39036 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
39037 +#else
39038 #define INPUT_POOL_SHIFT 12
39039 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
39040 #define OUTPUT_POOL_SHIFT 10
39041 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
39042 +#endif
39043 #define SEC_XFER_SIZE 512
39044 #define EXTRACT_SIZE 10
39045
39046 @@ -284,9 +291,6 @@
39047 /*
39048 * To allow fractional bits to be tracked, the entropy_count field is
39049 * denominated in units of 1/8th bits.
39050 - *
39051 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39052 - * credit_entropy_bits() needs to be 64 bits wide.
39053 */
39054 #define ENTROPY_SHIFT 3
39055 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39056 @@ -361,12 +365,19 @@ static struct poolinfo {
39057 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
39058 int tap1, tap2, tap3, tap4, tap5;
39059 } poolinfo_table[] = {
39060 +#ifdef CONFIG_GRKERNSEC_RANDNET
39061 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
39062 + { S(512), 411, 308, 208, 104, 1 },
39063 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
39064 + { S(128), 104, 76, 51, 25, 1 },
39065 +#else
39066 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
39067 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
39068 { S(128), 104, 76, 51, 25, 1 },
39069 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
39070 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
39071 { S(32), 26, 19, 14, 7, 1 },
39072 +#endif
39073 #if 0
39074 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
39075 { S(2048), 1638, 1231, 819, 411, 1 },
39076 @@ -433,9 +444,9 @@ struct entropy_store {
39077 };
39078
39079 static void push_to_pool(struct work_struct *work);
39080 -static __u32 input_pool_data[INPUT_POOL_WORDS];
39081 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39082 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39083 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39084 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39085 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39086
39087 static struct entropy_store input_pool = {
39088 .poolinfo = &poolinfo_table[0],
39089 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
39090 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
39091 }
39092
39093 - ACCESS_ONCE(r->input_rotate) = input_rotate;
39094 - ACCESS_ONCE(r->add_ptr) = i;
39095 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
39096 + ACCESS_ONCE_RW(r->add_ptr) = i;
39097 smp_wmb();
39098
39099 if (out)
39100 @@ -632,7 +643,7 @@ retry:
39101 /* The +2 corresponds to the /4 in the denominator */
39102
39103 do {
39104 - unsigned int anfrac = min(pnfrac, pool_size/2);
39105 + u64 anfrac = min(pnfrac, pool_size/2);
39106 unsigned int add =
39107 ((pool_size - entropy_count)*anfrac*3) >> s;
39108
39109 @@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39110
39111 extract_buf(r, tmp);
39112 i = min_t(int, nbytes, EXTRACT_SIZE);
39113 - if (copy_to_user(buf, tmp, i)) {
39114 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39115 ret = -EFAULT;
39116 break;
39117 }
39118 @@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
39119 #include <linux/sysctl.h>
39120
39121 static int min_read_thresh = 8, min_write_thresh;
39122 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
39123 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
39124 static int max_write_thresh = INPUT_POOL_WORDS * 32;
39125 static char sysctl_bootid[16];
39126
39127 @@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
39128 static int proc_do_uuid(struct ctl_table *table, int write,
39129 void __user *buffer, size_t *lenp, loff_t *ppos)
39130 {
39131 - struct ctl_table fake_table;
39132 + ctl_table_no_const fake_table;
39133 unsigned char buf[64], tmp_uuid[16], *uuid;
39134
39135 uuid = table->data;
39136 @@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39137 static int proc_do_entropy(ctl_table *table, int write,
39138 void __user *buffer, size_t *lenp, loff_t *ppos)
39139 {
39140 - ctl_table fake_table;
39141 + ctl_table_no_const fake_table;
39142 int entropy_count;
39143
39144 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39145 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39146 index 7cc1fe22..b602d6b 100644
39147 --- a/drivers/char/sonypi.c
39148 +++ b/drivers/char/sonypi.c
39149 @@ -54,6 +54,7 @@
39150
39151 #include <asm/uaccess.h>
39152 #include <asm/io.h>
39153 +#include <asm/local.h>
39154
39155 #include <linux/sonypi.h>
39156
39157 @@ -490,7 +491,7 @@ static struct sonypi_device {
39158 spinlock_t fifo_lock;
39159 wait_queue_head_t fifo_proc_list;
39160 struct fasync_struct *fifo_async;
39161 - int open_count;
39162 + local_t open_count;
39163 int model;
39164 struct input_dev *input_jog_dev;
39165 struct input_dev *input_key_dev;
39166 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39167 static int sonypi_misc_release(struct inode *inode, struct file *file)
39168 {
39169 mutex_lock(&sonypi_device.lock);
39170 - sonypi_device.open_count--;
39171 + local_dec(&sonypi_device.open_count);
39172 mutex_unlock(&sonypi_device.lock);
39173 return 0;
39174 }
39175 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39176 {
39177 mutex_lock(&sonypi_device.lock);
39178 /* Flush input queue on first open */
39179 - if (!sonypi_device.open_count)
39180 + if (!local_read(&sonypi_device.open_count))
39181 kfifo_reset(&sonypi_device.fifo);
39182 - sonypi_device.open_count++;
39183 + local_inc(&sonypi_device.open_count);
39184 mutex_unlock(&sonypi_device.lock);
39185
39186 return 0;
39187 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39188 index b9a57fa..5bb9e38 100644
39189 --- a/drivers/char/tpm/tpm_acpi.c
39190 +++ b/drivers/char/tpm/tpm_acpi.c
39191 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39192 virt = acpi_os_map_memory(start, len);
39193 if (!virt) {
39194 kfree(log->bios_event_log);
39195 + log->bios_event_log = NULL;
39196 printk("%s: ERROR - Unable to map memory\n", __func__);
39197 return -EIO;
39198 }
39199
39200 - memcpy_fromio(log->bios_event_log, virt, len);
39201 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39202
39203 acpi_os_unmap_memory(virt, len);
39204 return 0;
39205 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39206 index 59f7cb2..bac8b6d 100644
39207 --- a/drivers/char/tpm/tpm_eventlog.c
39208 +++ b/drivers/char/tpm/tpm_eventlog.c
39209 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39210 event = addr;
39211
39212 if ((event->event_type == 0 && event->event_size == 0) ||
39213 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39214 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39215 return NULL;
39216
39217 return addr;
39218 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39219 return NULL;
39220
39221 if ((event->event_type == 0 && event->event_size == 0) ||
39222 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39223 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39224 return NULL;
39225
39226 (*pos)++;
39227 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39228 int i;
39229
39230 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39231 - seq_putc(m, data[i]);
39232 + if (!seq_putc(m, data[i]))
39233 + return -EFAULT;
39234
39235 return 0;
39236 }
39237 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39238 index 6928d09..ff6abe8 100644
39239 --- a/drivers/char/virtio_console.c
39240 +++ b/drivers/char/virtio_console.c
39241 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39242 if (to_user) {
39243 ssize_t ret;
39244
39245 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39246 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39247 if (ret)
39248 return -EFAULT;
39249 } else {
39250 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39251 if (!port_has_data(port) && !port->host_connected)
39252 return 0;
39253
39254 - return fill_readbuf(port, ubuf, count, true);
39255 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39256 }
39257
39258 static int wait_port_writable(struct port *port, bool nonblock)
39259 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39260 index 57a078e..c17cde8 100644
39261 --- a/drivers/clk/clk-composite.c
39262 +++ b/drivers/clk/clk-composite.c
39263 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39264 struct clk *clk;
39265 struct clk_init_data init;
39266 struct clk_composite *composite;
39267 - struct clk_ops *clk_composite_ops;
39268 + clk_ops_no_const *clk_composite_ops;
39269
39270 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39271 if (!composite) {
39272 diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
39273 index 5983a26..65d5f46 100644
39274 --- a/drivers/clk/socfpga/clk.c
39275 +++ b/drivers/clk/socfpga/clk.c
39276 @@ -22,6 +22,7 @@
39277 #include <linux/clk-provider.h>
39278 #include <linux/io.h>
39279 #include <linux/of.h>
39280 +#include <asm/pgtable.h>
39281
39282 /* Clock Manager offsets */
39283 #define CLKMGR_CTRL 0x0
39284 @@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
39285 streq(clk_name, "periph_pll") ||
39286 streq(clk_name, "sdram_pll")) {
39287 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39288 - clk_pll_ops.enable = clk_gate_ops.enable;
39289 - clk_pll_ops.disable = clk_gate_ops.disable;
39290 + pax_open_kernel();
39291 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39292 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39293 + pax_close_kernel();
39294 }
39295
39296 clk = clk_register(NULL, &socfpga_clk->hw.hw);
39297 @@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
39298 return parent_rate / div;
39299 }
39300
39301 -static struct clk_ops gateclk_ops = {
39302 +static clk_ops_no_const gateclk_ops __read_only = {
39303 .recalc_rate = socfpga_clk_recalc_rate,
39304 .get_parent = socfpga_clk_get_parent,
39305 .set_parent = socfpga_clk_set_parent,
39306 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39307 index 18448a7..d5fad43 100644
39308 --- a/drivers/cpufreq/acpi-cpufreq.c
39309 +++ b/drivers/cpufreq/acpi-cpufreq.c
39310 @@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39311 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39312 per_cpu(acfreq_data, cpu) = data;
39313
39314 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39315 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39316 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39317 + pax_open_kernel();
39318 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39319 + pax_close_kernel();
39320 + }
39321
39322 result = acpi_processor_register_performance(data->acpi_data, cpu);
39323 if (result)
39324 @@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39325 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39326 break;
39327 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39328 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39329 + pax_open_kernel();
39330 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39331 + pax_close_kernel();
39332 break;
39333 default:
39334 break;
39335 @@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
39336 if (!msrs)
39337 return;
39338
39339 - acpi_cpufreq_driver.boost_supported = true;
39340 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39341 + pax_open_kernel();
39342 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39343 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39344 + pax_close_kernel();
39345 get_online_cpus();
39346
39347 /* Force all MSRs to the same value */
39348 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39349 index 199b52b..e3503bb 100644
39350 --- a/drivers/cpufreq/cpufreq.c
39351 +++ b/drivers/cpufreq/cpufreq.c
39352 @@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39353 #endif
39354
39355 mutex_lock(&cpufreq_governor_mutex);
39356 - list_del(&governor->governor_list);
39357 + pax_list_del(&governor->governor_list);
39358 mutex_unlock(&cpufreq_governor_mutex);
39359 return;
39360 }
39361 @@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39362 return NOTIFY_OK;
39363 }
39364
39365 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39366 +static struct notifier_block cpufreq_cpu_notifier = {
39367 .notifier_call = cpufreq_cpu_callback,
39368 };
39369
39370 @@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
39371 return 0;
39372
39373 write_lock_irqsave(&cpufreq_driver_lock, flags);
39374 - cpufreq_driver->boost_enabled = state;
39375 + pax_open_kernel();
39376 + *(bool *)&cpufreq_driver->boost_enabled = state;
39377 + pax_close_kernel();
39378 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39379
39380 ret = cpufreq_driver->set_boost(state);
39381 if (ret) {
39382 write_lock_irqsave(&cpufreq_driver_lock, flags);
39383 - cpufreq_driver->boost_enabled = !state;
39384 + pax_open_kernel();
39385 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39386 + pax_close_kernel();
39387 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39388
39389 pr_err("%s: Cannot %s BOOST\n", __func__,
39390 @@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39391
39392 pr_debug("trying to register driver %s\n", driver_data->name);
39393
39394 - if (driver_data->setpolicy)
39395 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39396 + if (driver_data->setpolicy) {
39397 + pax_open_kernel();
39398 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39399 + pax_close_kernel();
39400 + }
39401
39402 write_lock_irqsave(&cpufreq_driver_lock, flags);
39403 if (cpufreq_driver) {
39404 @@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39405 * Check if driver provides function to enable boost -
39406 * if not, use cpufreq_boost_set_sw as default
39407 */
39408 - if (!cpufreq_driver->set_boost)
39409 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39410 + if (!cpufreq_driver->set_boost) {
39411 + pax_open_kernel();
39412 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39413 + pax_close_kernel();
39414 + }
39415
39416 ret = cpufreq_sysfs_create_file(&boost.attr);
39417 if (ret) {
39418 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39419 index ba43991..23858ffb 100644
39420 --- a/drivers/cpufreq/cpufreq_governor.c
39421 +++ b/drivers/cpufreq/cpufreq_governor.c
39422 @@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39423 struct dbs_data *dbs_data;
39424 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39425 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39426 - struct od_ops *od_ops = NULL;
39427 + const struct od_ops *od_ops = NULL;
39428 struct od_dbs_tuners *od_tuners = NULL;
39429 struct cs_dbs_tuners *cs_tuners = NULL;
39430 struct cpu_dbs_common_info *cpu_cdbs;
39431 @@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39432
39433 if ((cdata->governor == GOV_CONSERVATIVE) &&
39434 (!policy->governor->initialized)) {
39435 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39436 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39437
39438 cpufreq_register_notifier(cs_ops->notifier_block,
39439 CPUFREQ_TRANSITION_NOTIFIER);
39440 @@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39441
39442 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39443 (policy->governor->initialized == 1)) {
39444 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39445 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39446
39447 cpufreq_unregister_notifier(cs_ops->notifier_block,
39448 CPUFREQ_TRANSITION_NOTIFIER);
39449 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39450 index bfb9ae1..e1d3a7e 100644
39451 --- a/drivers/cpufreq/cpufreq_governor.h
39452 +++ b/drivers/cpufreq/cpufreq_governor.h
39453 @@ -205,7 +205,7 @@ struct common_dbs_data {
39454 void (*exit)(struct dbs_data *dbs_data);
39455
39456 /* Governor specific ops, see below */
39457 - void *gov_ops;
39458 + const void *gov_ops;
39459 };
39460
39461 /* Governor Per policy data */
39462 @@ -225,7 +225,7 @@ struct od_ops {
39463 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39464 unsigned int freq_next, unsigned int relation);
39465 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39466 -};
39467 +} __no_const;
39468
39469 struct cs_ops {
39470 struct notifier_block *notifier_block;
39471 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39472 index 18d4091..434be15 100644
39473 --- a/drivers/cpufreq/cpufreq_ondemand.c
39474 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39475 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39476
39477 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39478
39479 -static struct od_ops od_ops = {
39480 +static struct od_ops od_ops __read_only = {
39481 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39482 .powersave_bias_target = generic_powersave_bias_target,
39483 .freq_increase = dbs_freq_increase,
39484 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39485 (struct cpufreq_policy *, unsigned int, unsigned int),
39486 unsigned int powersave_bias)
39487 {
39488 - od_ops.powersave_bias_target = f;
39489 + pax_open_kernel();
39490 + *(void **)&od_ops.powersave_bias_target = f;
39491 + pax_close_kernel();
39492 od_set_powersave_bias(powersave_bias);
39493 }
39494 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39495
39496 void od_unregister_powersave_bias_handler(void)
39497 {
39498 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39499 + pax_open_kernel();
39500 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39501 + pax_close_kernel();
39502 od_set_powersave_bias(0);
39503 }
39504 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39505 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39506 index 2cd36b9..8f07fae 100644
39507 --- a/drivers/cpufreq/intel_pstate.c
39508 +++ b/drivers/cpufreq/intel_pstate.c
39509 @@ -124,10 +124,10 @@ struct pstate_funcs {
39510 struct cpu_defaults {
39511 struct pstate_adjust_policy pid_policy;
39512 struct pstate_funcs funcs;
39513 -};
39514 +} __do_const;
39515
39516 static struct pstate_adjust_policy pid_params;
39517 -static struct pstate_funcs pstate_funcs;
39518 +static struct pstate_funcs *pstate_funcs;
39519
39520 struct perf_limits {
39521 int no_turbo;
39522 @@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39523
39524 cpu->pstate.current_pstate = pstate;
39525
39526 - pstate_funcs.set(cpu, pstate);
39527 + pstate_funcs->set(cpu, pstate);
39528 }
39529
39530 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39531 @@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39532 {
39533 sprintf(cpu->name, "Intel 2nd generation core");
39534
39535 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39536 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39537 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39538 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39539 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39540 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39541
39542 - if (pstate_funcs.get_vid)
39543 - pstate_funcs.get_vid(cpu);
39544 + if (pstate_funcs->get_vid)
39545 + pstate_funcs->get_vid(cpu);
39546
39547 /*
39548 * goto max pstate so we don't slow up boot if we are built-in if we are
39549 @@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
39550 rdmsrl(MSR_IA32_APERF, aperf);
39551 rdmsrl(MSR_IA32_MPERF, mperf);
39552
39553 - if (!pstate_funcs.get_max() ||
39554 - !pstate_funcs.get_min() ||
39555 - !pstate_funcs.get_turbo())
39556 + if (!pstate_funcs->get_max() ||
39557 + !pstate_funcs->get_min() ||
39558 + !pstate_funcs->get_turbo())
39559 return -ENODEV;
39560
39561 rdmsrl(MSR_IA32_APERF, tmp);
39562 @@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
39563 return 0;
39564 }
39565
39566 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39567 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39568 {
39569 pid_params.sample_rate_ms = policy->sample_rate_ms;
39570 pid_params.p_gain_pct = policy->p_gain_pct;
39571 @@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39572
39573 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39574 {
39575 - pstate_funcs.get_max = funcs->get_max;
39576 - pstate_funcs.get_min = funcs->get_min;
39577 - pstate_funcs.get_turbo = funcs->get_turbo;
39578 - pstate_funcs.set = funcs->set;
39579 - pstate_funcs.get_vid = funcs->get_vid;
39580 + pstate_funcs = funcs;
39581 }
39582
39583 #if IS_ENABLED(CONFIG_ACPI)
39584 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39585 index 3d1cba9..0ab21d2 100644
39586 --- a/drivers/cpufreq/p4-clockmod.c
39587 +++ b/drivers/cpufreq/p4-clockmod.c
39588 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39589 case 0x0F: /* Core Duo */
39590 case 0x16: /* Celeron Core */
39591 case 0x1C: /* Atom */
39592 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39593 + pax_open_kernel();
39594 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39595 + pax_close_kernel();
39596 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39597 case 0x0D: /* Pentium M (Dothan) */
39598 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39599 + pax_open_kernel();
39600 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39601 + pax_close_kernel();
39602 /* fall through */
39603 case 0x09: /* Pentium M (Banias) */
39604 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39605 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39606
39607 /* on P-4s, the TSC runs with constant frequency independent whether
39608 * throttling is active or not. */
39609 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39610 + pax_open_kernel();
39611 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39612 + pax_close_kernel();
39613
39614 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39615 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39616 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39617 index 724ffbd..f06aaaa 100644
39618 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39619 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39620 @@ -18,14 +18,12 @@
39621 #include <asm/head.h>
39622 #include <asm/timer.h>
39623
39624 -static struct cpufreq_driver *cpufreq_us3_driver;
39625 -
39626 struct us3_freq_percpu_info {
39627 struct cpufreq_frequency_table table[4];
39628 };
39629
39630 /* Indexed by cpu number. */
39631 -static struct us3_freq_percpu_info *us3_freq_table;
39632 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39633
39634 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39635 * in the Safari config register.
39636 @@ -156,18 +154,28 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39637
39638 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39639 {
39640 - if (cpufreq_us3_driver) {
39641 - cpufreq_frequency_table_put_attr(policy->cpu);
39642 - us3_freq_target(policy, 0);
39643 - }
39644 + cpufreq_frequency_table_put_attr(policy->cpu);
39645 + us3_freq_target(policy, 0);
39646
39647 return 0;
39648 }
39649
39650 +static int __init us3_freq_init(void);
39651 +static void __exit us3_freq_exit(void);
39652 +
39653 +static struct cpufreq_driver cpufreq_us3_driver = {
39654 + .init = us3_freq_cpu_init,
39655 + .verify = cpufreq_generic_frequency_table_verify,
39656 + .target_index = us3_freq_target,
39657 + .get = us3_freq_get,
39658 + .exit = us3_freq_cpu_exit,
39659 + .name = "UltraSPARC-III",
39660 +
39661 +};
39662 +
39663 static int __init us3_freq_init(void)
39664 {
39665 unsigned long manuf, impl, ver;
39666 - int ret;
39667
39668 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39669 return -ENODEV;
39670 @@ -180,55 +188,15 @@ static int __init us3_freq_init(void)
39671 (impl == CHEETAH_IMPL ||
39672 impl == CHEETAH_PLUS_IMPL ||
39673 impl == JAGUAR_IMPL ||
39674 - impl == PANTHER_IMPL)) {
39675 - struct cpufreq_driver *driver;
39676 -
39677 - ret = -ENOMEM;
39678 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39679 - if (!driver)
39680 - goto err_out;
39681 -
39682 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39683 - GFP_KERNEL);
39684 - if (!us3_freq_table)
39685 - goto err_out;
39686 -
39687 - driver->init = us3_freq_cpu_init;
39688 - driver->verify = cpufreq_generic_frequency_table_verify;
39689 - driver->target_index = us3_freq_target;
39690 - driver->get = us3_freq_get;
39691 - driver->exit = us3_freq_cpu_exit;
39692 - strcpy(driver->name, "UltraSPARC-III");
39693 -
39694 - cpufreq_us3_driver = driver;
39695 - ret = cpufreq_register_driver(driver);
39696 - if (ret)
39697 - goto err_out;
39698 -
39699 - return 0;
39700 -
39701 -err_out:
39702 - if (driver) {
39703 - kfree(driver);
39704 - cpufreq_us3_driver = NULL;
39705 - }
39706 - kfree(us3_freq_table);
39707 - us3_freq_table = NULL;
39708 - return ret;
39709 - }
39710 + impl == PANTHER_IMPL))
39711 + return cpufreq_register_driver(&cpufreq_us3_driver);
39712
39713 return -ENODEV;
39714 }
39715
39716 static void __exit us3_freq_exit(void)
39717 {
39718 - if (cpufreq_us3_driver) {
39719 - cpufreq_unregister_driver(cpufreq_us3_driver);
39720 - kfree(cpufreq_us3_driver);
39721 - cpufreq_us3_driver = NULL;
39722 - kfree(us3_freq_table);
39723 - us3_freq_table = NULL;
39724 - }
39725 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39726 }
39727
39728 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39729 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39730 index 4e1daca..e707b61 100644
39731 --- a/drivers/cpufreq/speedstep-centrino.c
39732 +++ b/drivers/cpufreq/speedstep-centrino.c
39733 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39734 !cpu_has(cpu, X86_FEATURE_EST))
39735 return -ENODEV;
39736
39737 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39738 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39739 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39740 + pax_open_kernel();
39741 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39742 + pax_close_kernel();
39743 + }
39744
39745 if (policy->cpu != 0)
39746 return -ENODEV;
39747 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39748 index 06dbe7c..c2c8671 100644
39749 --- a/drivers/cpuidle/driver.c
39750 +++ b/drivers/cpuidle/driver.c
39751 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39752
39753 static void poll_idle_init(struct cpuidle_driver *drv)
39754 {
39755 - struct cpuidle_state *state = &drv->states[0];
39756 + cpuidle_state_no_const *state = &drv->states[0];
39757
39758 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39759 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39760 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39761 index ca89412..a7b9c49 100644
39762 --- a/drivers/cpuidle/governor.c
39763 +++ b/drivers/cpuidle/governor.c
39764 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39765 mutex_lock(&cpuidle_lock);
39766 if (__cpuidle_find_governor(gov->name) == NULL) {
39767 ret = 0;
39768 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39769 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39770 if (!cpuidle_curr_governor ||
39771 cpuidle_curr_governor->rating < gov->rating)
39772 cpuidle_switch_governor(gov);
39773 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39774 index e918b6d..f87ea80 100644
39775 --- a/drivers/cpuidle/sysfs.c
39776 +++ b/drivers/cpuidle/sysfs.c
39777 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39778 NULL
39779 };
39780
39781 -static struct attribute_group cpuidle_attr_group = {
39782 +static attribute_group_no_const cpuidle_attr_group = {
39783 .attrs = cpuidle_default_attrs,
39784 .name = "cpuidle",
39785 };
39786 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39787 index 12fea3e..1e28f47 100644
39788 --- a/drivers/crypto/hifn_795x.c
39789 +++ b/drivers/crypto/hifn_795x.c
39790 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39791 MODULE_PARM_DESC(hifn_pll_ref,
39792 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39793
39794 -static atomic_t hifn_dev_number;
39795 +static atomic_unchecked_t hifn_dev_number;
39796
39797 #define ACRYPTO_OP_DECRYPT 0
39798 #define ACRYPTO_OP_ENCRYPT 1
39799 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39800 goto err_out_disable_pci_device;
39801
39802 snprintf(name, sizeof(name), "hifn%d",
39803 - atomic_inc_return(&hifn_dev_number)-1);
39804 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39805
39806 err = pci_request_regions(pdev, name);
39807 if (err)
39808 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39809 index a0b2f7e..1b6f028 100644
39810 --- a/drivers/devfreq/devfreq.c
39811 +++ b/drivers/devfreq/devfreq.c
39812 @@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39813 goto err_out;
39814 }
39815
39816 - list_add(&governor->node, &devfreq_governor_list);
39817 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39818
39819 list_for_each_entry(devfreq, &devfreq_list, node) {
39820 int ret = 0;
39821 @@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39822 }
39823 }
39824
39825 - list_del(&governor->node);
39826 + pax_list_del((struct list_head *)&governor->node);
39827 err_out:
39828 mutex_unlock(&devfreq_list_lock);
39829
39830 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39831 index 2e7b394..1371a64 100644
39832 --- a/drivers/dma/sh/shdma-base.c
39833 +++ b/drivers/dma/sh/shdma-base.c
39834 @@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39835 schan->slave_id = -EINVAL;
39836 }
39837
39838 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39839 - sdev->desc_size, GFP_KERNEL);
39840 + schan->desc = kcalloc(sdev->desc_size,
39841 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39842 if (!schan->desc) {
39843 ret = -ENOMEM;
39844 goto edescalloc;
39845 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39846 index 0d765c0..60b7480 100644
39847 --- a/drivers/dma/sh/shdmac.c
39848 +++ b/drivers/dma/sh/shdmac.c
39849 @@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39850 return ret;
39851 }
39852
39853 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39854 +static struct notifier_block sh_dmae_nmi_notifier = {
39855 .notifier_call = sh_dmae_nmi_handler,
39856
39857 /* Run before NMI debug handler and KGDB */
39858 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39859 index 592af5f..bb1d583 100644
39860 --- a/drivers/edac/edac_device.c
39861 +++ b/drivers/edac/edac_device.c
39862 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39863 */
39864 int edac_device_alloc_index(void)
39865 {
39866 - static atomic_t device_indexes = ATOMIC_INIT(0);
39867 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39868
39869 - return atomic_inc_return(&device_indexes) - 1;
39870 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39871 }
39872 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39873
39874 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39875 index b335c6a..db65b44 100644
39876 --- a/drivers/edac/edac_mc_sysfs.c
39877 +++ b/drivers/edac/edac_mc_sysfs.c
39878 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39879 struct dev_ch_attribute {
39880 struct device_attribute attr;
39881 int channel;
39882 -};
39883 +} __do_const;
39884
39885 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39886 struct dev_ch_attribute dev_attr_legacy_##_name = \
39887 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39888 }
39889
39890 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39891 + pax_open_kernel();
39892 if (mci->get_sdram_scrub_rate) {
39893 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39894 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39895 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39896 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39897 }
39898 if (mci->set_sdram_scrub_rate) {
39899 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39900 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39901 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39902 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39903 }
39904 + pax_close_kernel();
39905 err = device_create_file(&mci->dev,
39906 &dev_attr_sdram_scrub_rate);
39907 if (err) {
39908 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39909 index 2cf44b4d..6dd2dc7 100644
39910 --- a/drivers/edac/edac_pci.c
39911 +++ b/drivers/edac/edac_pci.c
39912 @@ -29,7 +29,7 @@
39913
39914 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39915 static LIST_HEAD(edac_pci_list);
39916 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39917 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39918
39919 /*
39920 * edac_pci_alloc_ctl_info
39921 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39922 */
39923 int edac_pci_alloc_index(void)
39924 {
39925 - return atomic_inc_return(&pci_indexes) - 1;
39926 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39927 }
39928 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39929
39930 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39931 index e8658e4..22746d6 100644
39932 --- a/drivers/edac/edac_pci_sysfs.c
39933 +++ b/drivers/edac/edac_pci_sysfs.c
39934 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39935 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39936 static int edac_pci_poll_msec = 1000; /* one second workq period */
39937
39938 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39939 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39940 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39941 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39942
39943 static struct kobject *edac_pci_top_main_kobj;
39944 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39945 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39946 void *value;
39947 ssize_t(*show) (void *, char *);
39948 ssize_t(*store) (void *, const char *, size_t);
39949 -};
39950 +} __do_const;
39951
39952 /* Set of show/store abstract level functions for PCI Parity object */
39953 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39954 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39955 edac_printk(KERN_CRIT, EDAC_PCI,
39956 "Signaled System Error on %s\n",
39957 pci_name(dev));
39958 - atomic_inc(&pci_nonparity_count);
39959 + atomic_inc_unchecked(&pci_nonparity_count);
39960 }
39961
39962 if (status & (PCI_STATUS_PARITY)) {
39963 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39964 "Master Data Parity Error on %s\n",
39965 pci_name(dev));
39966
39967 - atomic_inc(&pci_parity_count);
39968 + atomic_inc_unchecked(&pci_parity_count);
39969 }
39970
39971 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39972 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39973 "Detected Parity Error on %s\n",
39974 pci_name(dev));
39975
39976 - atomic_inc(&pci_parity_count);
39977 + atomic_inc_unchecked(&pci_parity_count);
39978 }
39979 }
39980
39981 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39982 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39983 "Signaled System Error on %s\n",
39984 pci_name(dev));
39985 - atomic_inc(&pci_nonparity_count);
39986 + atomic_inc_unchecked(&pci_nonparity_count);
39987 }
39988
39989 if (status & (PCI_STATUS_PARITY)) {
39990 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39991 "Master Data Parity Error on "
39992 "%s\n", pci_name(dev));
39993
39994 - atomic_inc(&pci_parity_count);
39995 + atomic_inc_unchecked(&pci_parity_count);
39996 }
39997
39998 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39999 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40000 "Detected Parity Error on %s\n",
40001 pci_name(dev));
40002
40003 - atomic_inc(&pci_parity_count);
40004 + atomic_inc_unchecked(&pci_parity_count);
40005 }
40006 }
40007 }
40008 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
40009 if (!check_pci_errors)
40010 return;
40011
40012 - before_count = atomic_read(&pci_parity_count);
40013 + before_count = atomic_read_unchecked(&pci_parity_count);
40014
40015 /* scan all PCI devices looking for a Parity Error on devices and
40016 * bridges.
40017 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
40018 /* Only if operator has selected panic on PCI Error */
40019 if (edac_pci_get_panic_on_pe()) {
40020 /* If the count is different 'after' from 'before' */
40021 - if (before_count != atomic_read(&pci_parity_count))
40022 + if (before_count != atomic_read_unchecked(&pci_parity_count))
40023 panic("EDAC: PCI Parity Error");
40024 }
40025 }
40026 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
40027 index 51b7e3a..aa8a3e8 100644
40028 --- a/drivers/edac/mce_amd.h
40029 +++ b/drivers/edac/mce_amd.h
40030 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
40031 bool (*mc0_mce)(u16, u8);
40032 bool (*mc1_mce)(u16, u8);
40033 bool (*mc2_mce)(u16, u8);
40034 -};
40035 +} __no_const;
40036
40037 void amd_report_gart_errors(bool);
40038 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
40039 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
40040 index 57ea7f4..af06b76 100644
40041 --- a/drivers/firewire/core-card.c
40042 +++ b/drivers/firewire/core-card.c
40043 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
40044 const struct fw_card_driver *driver,
40045 struct device *device)
40046 {
40047 - static atomic_t index = ATOMIC_INIT(-1);
40048 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
40049
40050 - card->index = atomic_inc_return(&index);
40051 + card->index = atomic_inc_return_unchecked(&index);
40052 card->driver = driver;
40053 card->device = device;
40054 card->current_tlabel = 0;
40055 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40056
40057 void fw_core_remove_card(struct fw_card *card)
40058 {
40059 - struct fw_card_driver dummy_driver = dummy_driver_template;
40060 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
40061
40062 card->driver->update_phy_reg(card, 4,
40063 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40064 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40065 index 2c6d5e1..a2cca6b 100644
40066 --- a/drivers/firewire/core-device.c
40067 +++ b/drivers/firewire/core-device.c
40068 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40069 struct config_rom_attribute {
40070 struct device_attribute attr;
40071 u32 key;
40072 -};
40073 +} __do_const;
40074
40075 static ssize_t show_immediate(struct device *dev,
40076 struct device_attribute *dattr, char *buf)
40077 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40078 index eb6935c..3cc2bfa 100644
40079 --- a/drivers/firewire/core-transaction.c
40080 +++ b/drivers/firewire/core-transaction.c
40081 @@ -38,6 +38,7 @@
40082 #include <linux/timer.h>
40083 #include <linux/types.h>
40084 #include <linux/workqueue.h>
40085 +#include <linux/sched.h>
40086
40087 #include <asm/byteorder.h>
40088
40089 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40090 index c98764a..551b520 100644
40091 --- a/drivers/firewire/core.h
40092 +++ b/drivers/firewire/core.h
40093 @@ -111,6 +111,7 @@ struct fw_card_driver {
40094
40095 int (*stop_iso)(struct fw_iso_context *ctx);
40096 };
40097 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40098
40099 void fw_card_initialize(struct fw_card *card,
40100 const struct fw_card_driver *driver, struct device *device);
40101 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40102 index 8db6632..9bbc8ca 100644
40103 --- a/drivers/firewire/ohci.c
40104 +++ b/drivers/firewire/ohci.c
40105 @@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
40106 be32_to_cpu(ohci->next_header));
40107 }
40108
40109 +#ifndef CONFIG_GRKERNSEC
40110 if (param_remote_dma) {
40111 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40112 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40113 }
40114 +#endif
40115
40116 spin_unlock_irq(&ohci->lock);
40117
40118 @@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40119 unsigned long flags;
40120 int n, ret = 0;
40121
40122 +#ifndef CONFIG_GRKERNSEC
40123 if (param_remote_dma)
40124 return 0;
40125 +#endif
40126
40127 /*
40128 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40129 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40130 index 94a58a0..f5eba42 100644
40131 --- a/drivers/firmware/dmi-id.c
40132 +++ b/drivers/firmware/dmi-id.c
40133 @@ -16,7 +16,7 @@
40134 struct dmi_device_attribute{
40135 struct device_attribute dev_attr;
40136 int field;
40137 -};
40138 +} __do_const;
40139 #define to_dmi_dev_attr(_dev_attr) \
40140 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40141
40142 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40143 index 17afc51..0ef90cd 100644
40144 --- a/drivers/firmware/dmi_scan.c
40145 +++ b/drivers/firmware/dmi_scan.c
40146 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40147 if (buf == NULL)
40148 return -1;
40149
40150 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40151 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40152
40153 dmi_unmap(buf);
40154 return 0;
40155 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40156 index 1491dd4..aa910db 100644
40157 --- a/drivers/firmware/efi/cper.c
40158 +++ b/drivers/firmware/efi/cper.c
40159 @@ -41,12 +41,12 @@
40160 */
40161 u64 cper_next_record_id(void)
40162 {
40163 - static atomic64_t seq;
40164 + static atomic64_unchecked_t seq;
40165
40166 - if (!atomic64_read(&seq))
40167 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
40168 + if (!atomic64_read_unchecked(&seq))
40169 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40170
40171 - return atomic64_inc_return(&seq);
40172 + return atomic64_inc_return_unchecked(&seq);
40173 }
40174 EXPORT_SYMBOL_GPL(cper_next_record_id);
40175
40176 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40177 index 4753bac..02861a2 100644
40178 --- a/drivers/firmware/efi/efi.c
40179 +++ b/drivers/firmware/efi/efi.c
40180 @@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
40181 };
40182
40183 static struct efivars generic_efivars;
40184 -static struct efivar_operations generic_ops;
40185 +static efivar_operations_no_const generic_ops __read_only;
40186
40187 static int generic_ops_register(void)
40188 {
40189 - generic_ops.get_variable = efi.get_variable;
40190 - generic_ops.set_variable = efi.set_variable;
40191 - generic_ops.get_next_variable = efi.get_next_variable;
40192 - generic_ops.query_variable_store = efi_query_variable_store;
40193 + pax_open_kernel();
40194 + *(void **)&generic_ops.get_variable = efi.get_variable;
40195 + *(void **)&generic_ops.set_variable = efi.set_variable;
40196 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40197 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40198 + pax_close_kernel();
40199
40200 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40201 }
40202 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40203 index 3dc2482..7bd2f61 100644
40204 --- a/drivers/firmware/efi/efivars.c
40205 +++ b/drivers/firmware/efi/efivars.c
40206 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40207 static int
40208 create_efivars_bin_attributes(void)
40209 {
40210 - struct bin_attribute *attr;
40211 + bin_attribute_no_const *attr;
40212 int error;
40213
40214 /* new_var */
40215 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40216 index 2a90ba6..07f3733 100644
40217 --- a/drivers/firmware/google/memconsole.c
40218 +++ b/drivers/firmware/google/memconsole.c
40219 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
40220 if (!found_memconsole())
40221 return -ENODEV;
40222
40223 - memconsole_bin_attr.size = memconsole_length;
40224 + pax_open_kernel();
40225 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40226 + pax_close_kernel();
40227
40228 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40229
40230 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40231 index 1e98a98..b444372 100644
40232 --- a/drivers/gpio/gpio-em.c
40233 +++ b/drivers/gpio/gpio-em.c
40234 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40235 struct em_gio_priv *p;
40236 struct resource *io[2], *irq[2];
40237 struct gpio_chip *gpio_chip;
40238 - struct irq_chip *irq_chip;
40239 + irq_chip_no_const *irq_chip;
40240 const char *name = dev_name(&pdev->dev);
40241 int ret;
40242
40243 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40244 index f5bf3c3..7baaa59 100644
40245 --- a/drivers/gpio/gpio-ich.c
40246 +++ b/drivers/gpio/gpio-ich.c
40247 @@ -71,7 +71,7 @@ struct ichx_desc {
40248 /* Some chipsets have quirks, let these use their own request/get */
40249 int (*request)(struct gpio_chip *chip, unsigned offset);
40250 int (*get)(struct gpio_chip *chip, unsigned offset);
40251 -};
40252 +} __do_const;
40253
40254 static struct {
40255 spinlock_t lock;
40256 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40257 index ca76ce7..68b384b 100644
40258 --- a/drivers/gpio/gpio-rcar.c
40259 +++ b/drivers/gpio/gpio-rcar.c
40260 @@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40261 struct gpio_rcar_priv *p;
40262 struct resource *io, *irq;
40263 struct gpio_chip *gpio_chip;
40264 - struct irq_chip *irq_chip;
40265 + irq_chip_no_const *irq_chip;
40266 const char *name = dev_name(&pdev->dev);
40267 int ret;
40268
40269 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40270 index 9902732..64b62dd 100644
40271 --- a/drivers/gpio/gpio-vr41xx.c
40272 +++ b/drivers/gpio/gpio-vr41xx.c
40273 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
40274 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40275 maskl, pendl, maskh, pendh);
40276
40277 - atomic_inc(&irq_err_count);
40278 + atomic_inc_unchecked(&irq_err_count);
40279
40280 return -EINVAL;
40281 }
40282 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40283 index 3b7d32d..05c2f74 100644
40284 --- a/drivers/gpu/drm/drm_crtc.c
40285 +++ b/drivers/gpu/drm/drm_crtc.c
40286 @@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40287 goto done;
40288 }
40289
40290 - if (copy_to_user(&enum_ptr[copied].name,
40291 + if (copy_to_user(enum_ptr[copied].name,
40292 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40293 ret = -EFAULT;
40294 goto done;
40295 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40296 index 345be03..158368d 100644
40297 --- a/drivers/gpu/drm/drm_drv.c
40298 +++ b/drivers/gpu/drm/drm_drv.c
40299 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
40300 /**
40301 * Copy and IOCTL return string to user space
40302 */
40303 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
40304 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
40305 {
40306 int len;
40307
40308 @@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
40309 struct drm_file *file_priv = filp->private_data;
40310 struct drm_device *dev;
40311 const struct drm_ioctl_desc *ioctl = NULL;
40312 - drm_ioctl_t *func;
40313 + drm_ioctl_no_const_t func;
40314 unsigned int nr = DRM_IOCTL_NR(cmd);
40315 int retcode = -EINVAL;
40316 char stack_kdata[128];
40317 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40318 index 7f2af9a..1561914 100644
40319 --- a/drivers/gpu/drm/drm_fops.c
40320 +++ b/drivers/gpu/drm/drm_fops.c
40321 @@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
40322 if (drm_device_is_unplugged(dev))
40323 return -ENODEV;
40324
40325 - if (!dev->open_count++)
40326 + if (local_inc_return(&dev->open_count) == 1)
40327 need_setup = 1;
40328 mutex_lock(&dev->struct_mutex);
40329 old_imapping = inode->i_mapping;
40330 @@ -127,7 +127,7 @@ err_undo:
40331 iput(container_of(dev->dev_mapping, struct inode, i_data));
40332 dev->dev_mapping = old_mapping;
40333 mutex_unlock(&dev->struct_mutex);
40334 - dev->open_count--;
40335 + local_dec(&dev->open_count);
40336 return retcode;
40337 }
40338 EXPORT_SYMBOL(drm_open);
40339 @@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
40340
40341 mutex_lock(&drm_global_mutex);
40342
40343 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40344 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40345
40346 if (dev->driver->preclose)
40347 dev->driver->preclose(dev, file_priv);
40348 @@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
40349 * Begin inline drm_release
40350 */
40351
40352 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40353 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40354 task_pid_nr(current),
40355 (long)old_encode_dev(file_priv->minor->device),
40356 - dev->open_count);
40357 + local_read(&dev->open_count));
40358
40359 /* Release any auth tokens that might point to this file_priv,
40360 (do that under the drm_global_mutex) */
40361 @@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
40362 * End inline drm_release
40363 */
40364
40365 - if (!--dev->open_count) {
40366 + if (local_dec_and_test(&dev->open_count)) {
40367 retcode = drm_lastclose(dev);
40368 if (drm_device_is_unplugged(dev))
40369 drm_put_dev(dev);
40370 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40371 index 3d2e91c..d31c4c9 100644
40372 --- a/drivers/gpu/drm/drm_global.c
40373 +++ b/drivers/gpu/drm/drm_global.c
40374 @@ -36,7 +36,7 @@
40375 struct drm_global_item {
40376 struct mutex mutex;
40377 void *object;
40378 - int refcount;
40379 + atomic_t refcount;
40380 };
40381
40382 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40383 @@ -49,7 +49,7 @@ void drm_global_init(void)
40384 struct drm_global_item *item = &glob[i];
40385 mutex_init(&item->mutex);
40386 item->object = NULL;
40387 - item->refcount = 0;
40388 + atomic_set(&item->refcount, 0);
40389 }
40390 }
40391
40392 @@ -59,7 +59,7 @@ void drm_global_release(void)
40393 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40394 struct drm_global_item *item = &glob[i];
40395 BUG_ON(item->object != NULL);
40396 - BUG_ON(item->refcount != 0);
40397 + BUG_ON(atomic_read(&item->refcount) != 0);
40398 }
40399 }
40400
40401 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40402 struct drm_global_item *item = &glob[ref->global_type];
40403
40404 mutex_lock(&item->mutex);
40405 - if (item->refcount == 0) {
40406 + if (atomic_read(&item->refcount) == 0) {
40407 item->object = kzalloc(ref->size, GFP_KERNEL);
40408 if (unlikely(item->object == NULL)) {
40409 ret = -ENOMEM;
40410 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40411 goto out_err;
40412
40413 }
40414 - ++item->refcount;
40415 + atomic_inc(&item->refcount);
40416 ref->object = item->object;
40417 mutex_unlock(&item->mutex);
40418 return 0;
40419 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40420 struct drm_global_item *item = &glob[ref->global_type];
40421
40422 mutex_lock(&item->mutex);
40423 - BUG_ON(item->refcount == 0);
40424 + BUG_ON(atomic_read(&item->refcount) == 0);
40425 BUG_ON(ref->object != item->object);
40426 - if (--item->refcount == 0) {
40427 + if (atomic_dec_and_test(&item->refcount)) {
40428 ref->release(ref);
40429 item->object = NULL;
40430 }
40431 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40432 index 7473035..a48b9c5 100644
40433 --- a/drivers/gpu/drm/drm_info.c
40434 +++ b/drivers/gpu/drm/drm_info.c
40435 @@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40436 struct drm_local_map *map;
40437 struct drm_map_list *r_list;
40438
40439 - /* Hardcoded from _DRM_FRAME_BUFFER,
40440 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40441 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40442 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40443 + static const char * const types[] = {
40444 + [_DRM_FRAME_BUFFER] = "FB",
40445 + [_DRM_REGISTERS] = "REG",
40446 + [_DRM_SHM] = "SHM",
40447 + [_DRM_AGP] = "AGP",
40448 + [_DRM_SCATTER_GATHER] = "SG",
40449 + [_DRM_CONSISTENT] = "PCI"};
40450 const char *type;
40451 int i;
40452
40453 @@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40454 map = r_list->map;
40455 if (!map)
40456 continue;
40457 - if (map->type < 0 || map->type > 5)
40458 + if (map->type >= ARRAY_SIZE(types))
40459 type = "??";
40460 else
40461 type = types[map->type];
40462 @@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40463 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40464 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40465 vma->vm_flags & VM_IO ? 'i' : '-',
40466 +#ifdef CONFIG_GRKERNSEC_HIDESYM
40467 + 0);
40468 +#else
40469 vma->vm_pgoff);
40470 +#endif
40471
40472 #if defined(__i386__)
40473 pgprot = pgprot_val(vma->vm_page_prot);
40474 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40475 index 2f4c4343..dd12cd2 100644
40476 --- a/drivers/gpu/drm/drm_ioc32.c
40477 +++ b/drivers/gpu/drm/drm_ioc32.c
40478 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40479 request = compat_alloc_user_space(nbytes);
40480 if (!access_ok(VERIFY_WRITE, request, nbytes))
40481 return -EFAULT;
40482 - list = (struct drm_buf_desc *) (request + 1);
40483 + list = (struct drm_buf_desc __user *) (request + 1);
40484
40485 if (__put_user(count, &request->count)
40486 || __put_user(list, &request->list))
40487 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40488 request = compat_alloc_user_space(nbytes);
40489 if (!access_ok(VERIFY_WRITE, request, nbytes))
40490 return -EFAULT;
40491 - list = (struct drm_buf_pub *) (request + 1);
40492 + list = (struct drm_buf_pub __user *) (request + 1);
40493
40494 if (__put_user(count, &request->count)
40495 || __put_user(list, &request->list))
40496 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40497 return 0;
40498 }
40499
40500 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40501 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40502 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40503 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40504 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40505 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40506 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40507 {
40508 unsigned int nr = DRM_IOCTL_NR(cmd);
40509 - drm_ioctl_compat_t *fn;
40510 int ret;
40511
40512 /* Assume that ioctls without an explicit compat routine will just
40513 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40514 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40515 return drm_ioctl(filp, cmd, arg);
40516
40517 - fn = drm_compat_ioctls[nr];
40518 -
40519 - if (fn != NULL)
40520 - ret = (*fn) (filp, cmd, arg);
40521 + if (drm_compat_ioctls[nr] != NULL)
40522 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40523 else
40524 ret = drm_ioctl(filp, cmd, arg);
40525
40526 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40527 index 98a33c580..8fd1c2b 100644
40528 --- a/drivers/gpu/drm/drm_stub.c
40529 +++ b/drivers/gpu/drm/drm_stub.c
40530 @@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
40531
40532 drm_device_set_unplugged(dev);
40533
40534 - if (dev->open_count == 0) {
40535 + if (local_read(&dev->open_count) == 0) {
40536 drm_put_dev(dev);
40537 }
40538 mutex_unlock(&drm_global_mutex);
40539 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40540 index c22c309..ae758c3 100644
40541 --- a/drivers/gpu/drm/drm_sysfs.c
40542 +++ b/drivers/gpu/drm/drm_sysfs.c
40543 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40544 */
40545 int drm_sysfs_device_add(struct drm_minor *minor)
40546 {
40547 - char *minor_str;
40548 + const char *minor_str;
40549 int r;
40550
40551 if (minor->type == DRM_MINOR_CONTROL)
40552 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40553 index d4d16ed..8fb0b51 100644
40554 --- a/drivers/gpu/drm/i810/i810_drv.h
40555 +++ b/drivers/gpu/drm/i810/i810_drv.h
40556 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40557 int page_flipping;
40558
40559 wait_queue_head_t irq_queue;
40560 - atomic_t irq_received;
40561 - atomic_t irq_emitted;
40562 + atomic_unchecked_t irq_received;
40563 + atomic_unchecked_t irq_emitted;
40564
40565 int front_offset;
40566 } drm_i810_private_t;
40567 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40568 index b2b46c5..feb9fe7 100644
40569 --- a/drivers/gpu/drm/i915/i915_debugfs.c
40570 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
40571 @@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40572 I915_READ(GTIMR));
40573 }
40574 seq_printf(m, "Interrupts received: %d\n",
40575 - atomic_read(&dev_priv->irq_received));
40576 + atomic_read_unchecked(&dev_priv->irq_received));
40577 for_each_ring(ring, dev_priv, i) {
40578 if (INTEL_INFO(dev)->gen >= 6) {
40579 seq_printf(m,
40580 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40581 index 15a74f9..4278889 100644
40582 --- a/drivers/gpu/drm/i915/i915_dma.c
40583 +++ b/drivers/gpu/drm/i915/i915_dma.c
40584 @@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40585 bool can_switch;
40586
40587 spin_lock(&dev->count_lock);
40588 - can_switch = (dev->open_count == 0);
40589 + can_switch = (local_read(&dev->open_count) == 0);
40590 spin_unlock(&dev->count_lock);
40591 return can_switch;
40592 }
40593 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40594 index df77e20..d3fda9f 100644
40595 --- a/drivers/gpu/drm/i915/i915_drv.h
40596 +++ b/drivers/gpu/drm/i915/i915_drv.h
40597 @@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
40598 drm_dma_handle_t *status_page_dmah;
40599 struct resource mch_res;
40600
40601 - atomic_t irq_received;
40602 + atomic_unchecked_t irq_received;
40603
40604 /* protects the irq masks */
40605 spinlock_t irq_lock;
40606 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40607 index d269ecf..6d857bc 100644
40608 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40609 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40610 @@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40611
40612 static int
40613 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40614 - int count)
40615 + unsigned int count)
40616 {
40617 - int i;
40618 + unsigned int i;
40619 unsigned relocs_total = 0;
40620 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40621
40622 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40623 index 3c59584..500f2e9 100644
40624 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40625 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40626 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40627 (unsigned long)request);
40628 }
40629
40630 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40631 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40632 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40633 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40634 [DRM_I915_GETPARAM] = compat_i915_getparam,
40635 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40636 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40637 {
40638 unsigned int nr = DRM_IOCTL_NR(cmd);
40639 - drm_ioctl_compat_t *fn = NULL;
40640 int ret;
40641
40642 if (nr < DRM_COMMAND_BASE)
40643 return drm_compat_ioctl(filp, cmd, arg);
40644
40645 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40646 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40647 -
40648 - if (fn != NULL)
40649 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40650 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40651 ret = (*fn) (filp, cmd, arg);
40652 - else
40653 + } else
40654 ret = drm_ioctl(filp, cmd, arg);
40655
40656 return ret;
40657 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40658 index d554169..f4426bb 100644
40659 --- a/drivers/gpu/drm/i915/i915_irq.c
40660 +++ b/drivers/gpu/drm/i915/i915_irq.c
40661 @@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40662 int pipe;
40663 u32 pipe_stats[I915_MAX_PIPES];
40664
40665 - atomic_inc(&dev_priv->irq_received);
40666 + atomic_inc_unchecked(&dev_priv->irq_received);
40667
40668 while (true) {
40669 iir = I915_READ(VLV_IIR);
40670 @@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40671 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40672 irqreturn_t ret = IRQ_NONE;
40673
40674 - atomic_inc(&dev_priv->irq_received);
40675 + atomic_inc_unchecked(&dev_priv->irq_received);
40676
40677 /* We get interrupts on unclaimed registers, so check for this before we
40678 * do any I915_{READ,WRITE}. */
40679 @@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40680 uint32_t tmp = 0;
40681 enum pipe pipe;
40682
40683 - atomic_inc(&dev_priv->irq_received);
40684 + atomic_inc_unchecked(&dev_priv->irq_received);
40685
40686 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40687 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40688 @@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40689 {
40690 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40691
40692 - atomic_set(&dev_priv->irq_received, 0);
40693 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40694
40695 I915_WRITE(HWSTAM, 0xeffe);
40696
40697 @@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40698 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40699 int pipe;
40700
40701 - atomic_set(&dev_priv->irq_received, 0);
40702 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40703
40704 /* VLV magic */
40705 I915_WRITE(VLV_IMR, 0);
40706 @@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40707 struct drm_i915_private *dev_priv = dev->dev_private;
40708 int pipe;
40709
40710 - atomic_set(&dev_priv->irq_received, 0);
40711 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40712
40713 I915_WRITE(GEN8_MASTER_IRQ, 0);
40714 POSTING_READ(GEN8_MASTER_IRQ);
40715 @@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40716 if (!dev_priv)
40717 return;
40718
40719 - atomic_set(&dev_priv->irq_received, 0);
40720 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40721
40722 I915_WRITE(GEN8_MASTER_IRQ, 0);
40723
40724 @@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40725 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40726 int pipe;
40727
40728 - atomic_set(&dev_priv->irq_received, 0);
40729 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40730
40731 for_each_pipe(pipe)
40732 I915_WRITE(PIPESTAT(pipe), 0);
40733 @@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40734 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40735 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40736
40737 - atomic_inc(&dev_priv->irq_received);
40738 + atomic_inc_unchecked(&dev_priv->irq_received);
40739
40740 iir = I915_READ16(IIR);
40741 if (iir == 0)
40742 @@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40743 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40744 int pipe;
40745
40746 - atomic_set(&dev_priv->irq_received, 0);
40747 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40748
40749 if (I915_HAS_HOTPLUG(dev)) {
40750 I915_WRITE(PORT_HOTPLUG_EN, 0);
40751 @@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40752 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40753 int pipe, ret = IRQ_NONE;
40754
40755 - atomic_inc(&dev_priv->irq_received);
40756 + atomic_inc_unchecked(&dev_priv->irq_received);
40757
40758 iir = I915_READ(IIR);
40759 do {
40760 @@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40761 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40762 int pipe;
40763
40764 - atomic_set(&dev_priv->irq_received, 0);
40765 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40766
40767 I915_WRITE(PORT_HOTPLUG_EN, 0);
40768 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40769 @@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40770 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40771 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40772
40773 - atomic_inc(&dev_priv->irq_received);
40774 + atomic_inc_unchecked(&dev_priv->irq_received);
40775
40776 iir = I915_READ(IIR);
40777
40778 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40779 index 9b8a7c7..60f6003 100644
40780 --- a/drivers/gpu/drm/i915/intel_display.c
40781 +++ b/drivers/gpu/drm/i915/intel_display.c
40782 @@ -10776,13 +10776,13 @@ struct intel_quirk {
40783 int subsystem_vendor;
40784 int subsystem_device;
40785 void (*hook)(struct drm_device *dev);
40786 -};
40787 +} __do_const;
40788
40789 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40790 struct intel_dmi_quirk {
40791 void (*hook)(struct drm_device *dev);
40792 const struct dmi_system_id (*dmi_id_list)[];
40793 -};
40794 +} __do_const;
40795
40796 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40797 {
40798 @@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40799 return 1;
40800 }
40801
40802 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40803 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40804 {
40805 - .dmi_id_list = &(const struct dmi_system_id[]) {
40806 - {
40807 - .callback = intel_dmi_reverse_brightness,
40808 - .ident = "NCR Corporation",
40809 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40810 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40811 - },
40812 - },
40813 - { } /* terminating entry */
40814 + .callback = intel_dmi_reverse_brightness,
40815 + .ident = "NCR Corporation",
40816 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40817 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40818 },
40819 + },
40820 + { } /* terminating entry */
40821 +};
40822 +
40823 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40824 + {
40825 + .dmi_id_list = &intel_dmi_quirks_table,
40826 .hook = quirk_invert_brightness,
40827 },
40828 };
40829 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40830 index fe45321..836fdca 100644
40831 --- a/drivers/gpu/drm/mga/mga_drv.h
40832 +++ b/drivers/gpu/drm/mga/mga_drv.h
40833 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40834 u32 clear_cmd;
40835 u32 maccess;
40836
40837 - atomic_t vbl_received; /**< Number of vblanks received. */
40838 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40839 wait_queue_head_t fence_queue;
40840 - atomic_t last_fence_retired;
40841 + atomic_unchecked_t last_fence_retired;
40842 u32 next_fence_to_post;
40843
40844 unsigned int fb_cpp;
40845 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40846 index 86b4bb8..ae237ad 100644
40847 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40848 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40849 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40850 return 0;
40851 }
40852
40853 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40854 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40855 [DRM_MGA_INIT] = compat_mga_init,
40856 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40857 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40858 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40859 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40860 {
40861 unsigned int nr = DRM_IOCTL_NR(cmd);
40862 - drm_ioctl_compat_t *fn = NULL;
40863 int ret;
40864
40865 if (nr < DRM_COMMAND_BASE)
40866 return drm_compat_ioctl(filp, cmd, arg);
40867
40868 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40869 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40870 -
40871 - if (fn != NULL)
40872 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40873 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40874 ret = (*fn) (filp, cmd, arg);
40875 - else
40876 + } else
40877 ret = drm_ioctl(filp, cmd, arg);
40878
40879 return ret;
40880 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40881 index 1b071b8..de8601a 100644
40882 --- a/drivers/gpu/drm/mga/mga_irq.c
40883 +++ b/drivers/gpu/drm/mga/mga_irq.c
40884 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40885 if (crtc != 0)
40886 return 0;
40887
40888 - return atomic_read(&dev_priv->vbl_received);
40889 + return atomic_read_unchecked(&dev_priv->vbl_received);
40890 }
40891
40892
40893 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40894 /* VBLANK interrupt */
40895 if (status & MGA_VLINEPEN) {
40896 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40897 - atomic_inc(&dev_priv->vbl_received);
40898 + atomic_inc_unchecked(&dev_priv->vbl_received);
40899 drm_handle_vblank(dev, 0);
40900 handled = 1;
40901 }
40902 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40903 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40904 MGA_WRITE(MGA_PRIMEND, prim_end);
40905
40906 - atomic_inc(&dev_priv->last_fence_retired);
40907 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40908 wake_up(&dev_priv->fence_queue);
40909 handled = 1;
40910 }
40911 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40912 * using fences.
40913 */
40914 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40915 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40916 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40917 - *sequence) <= (1 << 23)));
40918
40919 *sequence = cur_fence;
40920 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40921 index 4c3feaa..26391ce 100644
40922 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40923 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40924 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40925 struct bit_table {
40926 const char id;
40927 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40928 -};
40929 +} __no_const;
40930
40931 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40932
40933 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40934 index 23ca7a5..b6c955d 100644
40935 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40936 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40937 @@ -97,7 +97,6 @@ struct nouveau_drm {
40938 struct drm_global_reference mem_global_ref;
40939 struct ttm_bo_global_ref bo_global_ref;
40940 struct ttm_bo_device bdev;
40941 - atomic_t validate_sequence;
40942 int (*move)(struct nouveau_channel *,
40943 struct ttm_buffer_object *,
40944 struct ttm_mem_reg *, struct ttm_mem_reg *);
40945 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40946 index c1a7e5a..38b8539 100644
40947 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40948 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40949 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40950 unsigned long arg)
40951 {
40952 unsigned int nr = DRM_IOCTL_NR(cmd);
40953 - drm_ioctl_compat_t *fn = NULL;
40954 + drm_ioctl_compat_t fn = NULL;
40955 int ret;
40956
40957 if (nr < DRM_COMMAND_BASE)
40958 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40959 index d45d50d..72a5dd2 100644
40960 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40961 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40962 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40963 }
40964
40965 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40966 - nouveau_vram_manager_init,
40967 - nouveau_vram_manager_fini,
40968 - nouveau_vram_manager_new,
40969 - nouveau_vram_manager_del,
40970 - nouveau_vram_manager_debug
40971 + .init = nouveau_vram_manager_init,
40972 + .takedown = nouveau_vram_manager_fini,
40973 + .get_node = nouveau_vram_manager_new,
40974 + .put_node = nouveau_vram_manager_del,
40975 + .debug = nouveau_vram_manager_debug
40976 };
40977
40978 static int
40979 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40980 }
40981
40982 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40983 - nouveau_gart_manager_init,
40984 - nouveau_gart_manager_fini,
40985 - nouveau_gart_manager_new,
40986 - nouveau_gart_manager_del,
40987 - nouveau_gart_manager_debug
40988 + .init = nouveau_gart_manager_init,
40989 + .takedown = nouveau_gart_manager_fini,
40990 + .get_node = nouveau_gart_manager_new,
40991 + .put_node = nouveau_gart_manager_del,
40992 + .debug = nouveau_gart_manager_debug
40993 };
40994
40995 #include <core/subdev/vm/nv04.h>
40996 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40997 }
40998
40999 const struct ttm_mem_type_manager_func nv04_gart_manager = {
41000 - nv04_gart_manager_init,
41001 - nv04_gart_manager_fini,
41002 - nv04_gart_manager_new,
41003 - nv04_gart_manager_del,
41004 - nv04_gart_manager_debug
41005 + .init = nv04_gart_manager_init,
41006 + .takedown = nv04_gart_manager_fini,
41007 + .get_node = nv04_gart_manager_new,
41008 + .put_node = nv04_gart_manager_del,
41009 + .debug = nv04_gart_manager_debug
41010 };
41011
41012 int
41013 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
41014 index 471347e..5adc6b9 100644
41015 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
41016 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
41017 @@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
41018 bool can_switch;
41019
41020 spin_lock(&dev->count_lock);
41021 - can_switch = (dev->open_count == 0);
41022 + can_switch = (local_read(&dev->open_count) == 0);
41023 spin_unlock(&dev->count_lock);
41024 return can_switch;
41025 }
41026 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
41027 index eb89653..613cf71 100644
41028 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
41029 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
41030 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
41031 int ret;
41032
41033 mutex_lock(&qdev->async_io_mutex);
41034 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41035 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41036 if (qdev->last_sent_io_cmd > irq_num) {
41037 if (intr)
41038 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41039 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41040 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41041 else
41042 ret = wait_event_timeout(qdev->io_cmd_event,
41043 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41044 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41045 /* 0 is timeout, just bail the "hw" has gone away */
41046 if (ret <= 0)
41047 goto out;
41048 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
41049 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41050 }
41051 outb(val, addr);
41052 qdev->last_sent_io_cmd = irq_num + 1;
41053 if (intr)
41054 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41055 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41056 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41057 else
41058 ret = wait_event_timeout(qdev->io_cmd_event,
41059 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41060 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41061 out:
41062 if (ret > 0)
41063 ret = 0;
41064 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41065 index c3c2bbd..bc3c0fb 100644
41066 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41067 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41068 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41069 struct drm_info_node *node = (struct drm_info_node *) m->private;
41070 struct qxl_device *qdev = node->minor->dev->dev_private;
41071
41072 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41073 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41074 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41075 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41076 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41077 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41078 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41079 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41080 seq_printf(m, "%d\n", qdev->irq_received_error);
41081 return 0;
41082 }
41083 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41084 index 36ed40b..0397633 100644
41085 --- a/drivers/gpu/drm/qxl/qxl_drv.h
41086 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
41087 @@ -290,10 +290,10 @@ struct qxl_device {
41088 unsigned int last_sent_io_cmd;
41089
41090 /* interrupt handling */
41091 - atomic_t irq_received;
41092 - atomic_t irq_received_display;
41093 - atomic_t irq_received_cursor;
41094 - atomic_t irq_received_io_cmd;
41095 + atomic_unchecked_t irq_received;
41096 + atomic_unchecked_t irq_received_display;
41097 + atomic_unchecked_t irq_received_cursor;
41098 + atomic_unchecked_t irq_received_io_cmd;
41099 unsigned irq_received_error;
41100 wait_queue_head_t display_event;
41101 wait_queue_head_t cursor_event;
41102 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41103 index 0bb86e6..d41416d 100644
41104 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
41105 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
41106 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41107
41108 /* TODO copy slow path code from i915 */
41109 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
41110 - 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);
41111 + 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);
41112
41113 {
41114 struct qxl_drawable *draw = fb_cmd;
41115 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41116 struct drm_qxl_reloc reloc;
41117
41118 if (copy_from_user(&reloc,
41119 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41120 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41121 sizeof(reloc))) {
41122 ret = -EFAULT;
41123 goto out_free_bos;
41124 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41125
41126 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41127
41128 - struct drm_qxl_command *commands =
41129 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41130 + struct drm_qxl_command __user *commands =
41131 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41132
41133 - if (copy_from_user(&user_cmd, &commands[cmd_num],
41134 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41135 sizeof(user_cmd)))
41136 return -EFAULT;
41137
41138 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41139 index 28f84b4..fb3e224 100644
41140 --- a/drivers/gpu/drm/qxl/qxl_irq.c
41141 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
41142 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41143
41144 pending = xchg(&qdev->ram_header->int_pending, 0);
41145
41146 - atomic_inc(&qdev->irq_received);
41147 + atomic_inc_unchecked(&qdev->irq_received);
41148
41149 if (pending & QXL_INTERRUPT_DISPLAY) {
41150 - atomic_inc(&qdev->irq_received_display);
41151 + atomic_inc_unchecked(&qdev->irq_received_display);
41152 wake_up_all(&qdev->display_event);
41153 qxl_queue_garbage_collect(qdev, false);
41154 }
41155 if (pending & QXL_INTERRUPT_CURSOR) {
41156 - atomic_inc(&qdev->irq_received_cursor);
41157 + atomic_inc_unchecked(&qdev->irq_received_cursor);
41158 wake_up_all(&qdev->cursor_event);
41159 }
41160 if (pending & QXL_INTERRUPT_IO_CMD) {
41161 - atomic_inc(&qdev->irq_received_io_cmd);
41162 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41163 wake_up_all(&qdev->io_cmd_event);
41164 }
41165 if (pending & QXL_INTERRUPT_ERROR) {
41166 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41167 init_waitqueue_head(&qdev->io_cmd_event);
41168 INIT_WORK(&qdev->client_monitors_config_work,
41169 qxl_client_monitors_config_work_func);
41170 - atomic_set(&qdev->irq_received, 0);
41171 - atomic_set(&qdev->irq_received_display, 0);
41172 - atomic_set(&qdev->irq_received_cursor, 0);
41173 - atomic_set(&qdev->irq_received_io_cmd, 0);
41174 + atomic_set_unchecked(&qdev->irq_received, 0);
41175 + atomic_set_unchecked(&qdev->irq_received_display, 0);
41176 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41177 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41178 qdev->irq_received_error = 0;
41179 ret = drm_irq_install(qdev->ddev);
41180 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41181 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41182 index c7e7e65..7dddd4d 100644
41183 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
41184 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41185 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41186 }
41187 }
41188
41189 -static struct vm_operations_struct qxl_ttm_vm_ops;
41190 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41191 static const struct vm_operations_struct *ttm_vm_ops;
41192
41193 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41194 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41195 return r;
41196 if (unlikely(ttm_vm_ops == NULL)) {
41197 ttm_vm_ops = vma->vm_ops;
41198 + pax_open_kernel();
41199 qxl_ttm_vm_ops = *ttm_vm_ops;
41200 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41201 + pax_close_kernel();
41202 }
41203 vma->vm_ops = &qxl_ttm_vm_ops;
41204 return 0;
41205 @@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41206 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41207 {
41208 #if defined(CONFIG_DEBUG_FS)
41209 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41210 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41211 - unsigned i;
41212 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41213 + {
41214 + .name = "qxl_mem_mm",
41215 + .show = &qxl_mm_dump_table,
41216 + },
41217 + {
41218 + .name = "qxl_surf_mm",
41219 + .show = &qxl_mm_dump_table,
41220 + }
41221 + };
41222
41223 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41224 - if (i == 0)
41225 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41226 - else
41227 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41228 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41229 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41230 - qxl_mem_types_list[i].driver_features = 0;
41231 - if (i == 0)
41232 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41233 - else
41234 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41235 + pax_open_kernel();
41236 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41237 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41238 + pax_close_kernel();
41239
41240 - }
41241 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41242 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41243 #else
41244 return 0;
41245 #endif
41246 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41247 index 59459fe..be26b31 100644
41248 --- a/drivers/gpu/drm/r128/r128_cce.c
41249 +++ b/drivers/gpu/drm/r128/r128_cce.c
41250 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41251
41252 /* GH: Simple idle check.
41253 */
41254 - atomic_set(&dev_priv->idle_count, 0);
41255 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41256
41257 /* We don't support anything other than bus-mastering ring mode,
41258 * but the ring can be in either AGP or PCI space for the ring
41259 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41260 index 5bf3f5f..7000661 100644
41261 --- a/drivers/gpu/drm/r128/r128_drv.h
41262 +++ b/drivers/gpu/drm/r128/r128_drv.h
41263 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
41264 int is_pci;
41265 unsigned long cce_buffers_offset;
41266
41267 - atomic_t idle_count;
41268 + atomic_unchecked_t idle_count;
41269
41270 int page_flipping;
41271 int current_page;
41272 u32 crtc_offset;
41273 u32 crtc_offset_cntl;
41274
41275 - atomic_t vbl_received;
41276 + atomic_unchecked_t vbl_received;
41277
41278 u32 color_fmt;
41279 unsigned int front_offset;
41280 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41281 index b0d0fd3..a6fbbe4 100644
41282 --- a/drivers/gpu/drm/r128/r128_ioc32.c
41283 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
41284 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41285 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41286 }
41287
41288 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
41289 +drm_ioctl_compat_t r128_compat_ioctls[] = {
41290 [DRM_R128_INIT] = compat_r128_init,
41291 [DRM_R128_DEPTH] = compat_r128_depth,
41292 [DRM_R128_STIPPLE] = compat_r128_stipple,
41293 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41294 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41295 {
41296 unsigned int nr = DRM_IOCTL_NR(cmd);
41297 - drm_ioctl_compat_t *fn = NULL;
41298 int ret;
41299
41300 if (nr < DRM_COMMAND_BASE)
41301 return drm_compat_ioctl(filp, cmd, arg);
41302
41303 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
41304 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41305 -
41306 - if (fn != NULL)
41307 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
41308 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41309 ret = (*fn) (filp, cmd, arg);
41310 - else
41311 + } else
41312 ret = drm_ioctl(filp, cmd, arg);
41313
41314 return ret;
41315 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41316 index c2ae496..30b5993 100644
41317 --- a/drivers/gpu/drm/r128/r128_irq.c
41318 +++ b/drivers/gpu/drm/r128/r128_irq.c
41319 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41320 if (crtc != 0)
41321 return 0;
41322
41323 - return atomic_read(&dev_priv->vbl_received);
41324 + return atomic_read_unchecked(&dev_priv->vbl_received);
41325 }
41326
41327 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41328 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41329 /* VBLANK interrupt */
41330 if (status & R128_CRTC_VBLANK_INT) {
41331 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41332 - atomic_inc(&dev_priv->vbl_received);
41333 + atomic_inc_unchecked(&dev_priv->vbl_received);
41334 drm_handle_vblank(dev, 0);
41335 return IRQ_HANDLED;
41336 }
41337 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41338 index e806dac..f81d32f 100644
41339 --- a/drivers/gpu/drm/r128/r128_state.c
41340 +++ b/drivers/gpu/drm/r128/r128_state.c
41341 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41342
41343 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41344 {
41345 - if (atomic_read(&dev_priv->idle_count) == 0)
41346 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41347 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41348 else
41349 - atomic_set(&dev_priv->idle_count, 0);
41350 + atomic_set_unchecked(&dev_priv->idle_count, 0);
41351 }
41352
41353 #endif
41354 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41355 index 4a85bb6..aaea819 100644
41356 --- a/drivers/gpu/drm/radeon/mkregtable.c
41357 +++ b/drivers/gpu/drm/radeon/mkregtable.c
41358 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41359 regex_t mask_rex;
41360 regmatch_t match[4];
41361 char buf[1024];
41362 - size_t end;
41363 + long end;
41364 int len;
41365 int done = 0;
41366 int r;
41367 unsigned o;
41368 struct offset *offset;
41369 char last_reg_s[10];
41370 - int last_reg;
41371 + unsigned long last_reg;
41372
41373 if (regcomp
41374 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41375 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41376 index 044bc98..50ced9b 100644
41377 --- a/drivers/gpu/drm/radeon/radeon_device.c
41378 +++ b/drivers/gpu/drm/radeon/radeon_device.c
41379 @@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41380 bool can_switch;
41381
41382 spin_lock(&dev->count_lock);
41383 - can_switch = (dev->open_count == 0);
41384 + can_switch = (local_read(&dev->open_count) == 0);
41385 spin_unlock(&dev->count_lock);
41386 return can_switch;
41387 }
41388 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41389 index dafd812..1bf20c7 100644
41390 --- a/drivers/gpu/drm/radeon/radeon_drv.h
41391 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
41392 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
41393
41394 /* SW interrupt */
41395 wait_queue_head_t swi_queue;
41396 - atomic_t swi_emitted;
41397 + atomic_unchecked_t swi_emitted;
41398 int vblank_crtc;
41399 uint32_t irq_enable_reg;
41400 uint32_t r500_disp_irq_reg;
41401 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41402 index bdb0f93..5ff558f 100644
41403 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41404 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41405 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41406 request = compat_alloc_user_space(sizeof(*request));
41407 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41408 || __put_user(req32.param, &request->param)
41409 - || __put_user((void __user *)(unsigned long)req32.value,
41410 + || __put_user((unsigned long)req32.value,
41411 &request->value))
41412 return -EFAULT;
41413
41414 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41415 #define compat_radeon_cp_setparam NULL
41416 #endif /* X86_64 || IA64 */
41417
41418 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41419 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41420 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41421 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41422 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41423 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41424 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41425 {
41426 unsigned int nr = DRM_IOCTL_NR(cmd);
41427 - drm_ioctl_compat_t *fn = NULL;
41428 int ret;
41429
41430 if (nr < DRM_COMMAND_BASE)
41431 return drm_compat_ioctl(filp, cmd, arg);
41432
41433 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41434 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41435 -
41436 - if (fn != NULL)
41437 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41438 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41439 ret = (*fn) (filp, cmd, arg);
41440 - else
41441 + } else
41442 ret = drm_ioctl(filp, cmd, arg);
41443
41444 return ret;
41445 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41446 index 244b19b..c19226d 100644
41447 --- a/drivers/gpu/drm/radeon/radeon_irq.c
41448 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
41449 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41450 unsigned int ret;
41451 RING_LOCALS;
41452
41453 - atomic_inc(&dev_priv->swi_emitted);
41454 - ret = atomic_read(&dev_priv->swi_emitted);
41455 + atomic_inc_unchecked(&dev_priv->swi_emitted);
41456 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41457
41458 BEGIN_RING(4);
41459 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41460 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41461 drm_radeon_private_t *dev_priv =
41462 (drm_radeon_private_t *) dev->dev_private;
41463
41464 - atomic_set(&dev_priv->swi_emitted, 0);
41465 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41466 init_waitqueue_head(&dev_priv->swi_queue);
41467
41468 dev->max_vblank_count = 0x001fffff;
41469 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41470 index 956ab7f..fbd36d8 100644
41471 --- a/drivers/gpu/drm/radeon/radeon_state.c
41472 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41473 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41474 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41475 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41476
41477 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41478 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41479 sarea_priv->nbox * sizeof(depth_boxes[0])))
41480 return -EFAULT;
41481
41482 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41483 {
41484 drm_radeon_private_t *dev_priv = dev->dev_private;
41485 drm_radeon_getparam_t *param = data;
41486 - int value;
41487 + int value = 0;
41488
41489 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41490
41491 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41492 index 040a2a1..eae4e54 100644
41493 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41494 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41495 @@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41496 man->size = size >> PAGE_SHIFT;
41497 }
41498
41499 -static struct vm_operations_struct radeon_ttm_vm_ops;
41500 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41501 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41502
41503 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41504 @@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41505 }
41506 if (unlikely(ttm_vm_ops == NULL)) {
41507 ttm_vm_ops = vma->vm_ops;
41508 + pax_open_kernel();
41509 radeon_ttm_vm_ops = *ttm_vm_ops;
41510 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41511 + pax_close_kernel();
41512 }
41513 vma->vm_ops = &radeon_ttm_vm_ops;
41514 return 0;
41515 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41516 index 9336006..ce78aa7 100644
41517 --- a/drivers/gpu/drm/tegra/dc.c
41518 +++ b/drivers/gpu/drm/tegra/dc.c
41519 @@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41520 }
41521
41522 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41523 - dc->debugfs_files[i].data = dc;
41524 + *(void **)&dc->debugfs_files[i].data = dc;
41525
41526 err = drm_debugfs_create_files(dc->debugfs_files,
41527 ARRAY_SIZE(debugfs_files),
41528 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41529 index d452faab..f8cbc6a 100644
41530 --- a/drivers/gpu/drm/tegra/dsi.c
41531 +++ b/drivers/gpu/drm/tegra/dsi.c
41532 @@ -53,7 +53,7 @@ struct tegra_dsi {
41533 struct clk *clk_lp;
41534 struct clk *clk;
41535
41536 - struct drm_info_list *debugfs_files;
41537 + drm_info_list_no_const *debugfs_files;
41538 struct drm_minor *minor;
41539 struct dentry *debugfs;
41540
41541 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41542 index 6928015..c9853e7 100644
41543 --- a/drivers/gpu/drm/tegra/hdmi.c
41544 +++ b/drivers/gpu/drm/tegra/hdmi.c
41545 @@ -59,7 +59,7 @@ struct tegra_hdmi {
41546 bool stereo;
41547 bool dvi;
41548
41549 - struct drm_info_list *debugfs_files;
41550 + drm_info_list_no_const *debugfs_files;
41551 struct drm_minor *minor;
41552 struct dentry *debugfs;
41553 };
41554 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41555 index c58eba33..83c2728 100644
41556 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41557 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41558 @@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41559 }
41560
41561 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41562 - ttm_bo_man_init,
41563 - ttm_bo_man_takedown,
41564 - ttm_bo_man_get_node,
41565 - ttm_bo_man_put_node,
41566 - ttm_bo_man_debug
41567 + .init = ttm_bo_man_init,
41568 + .takedown = ttm_bo_man_takedown,
41569 + .get_node = ttm_bo_man_get_node,
41570 + .put_node = ttm_bo_man_put_node,
41571 + .debug = ttm_bo_man_debug
41572 };
41573 EXPORT_SYMBOL(ttm_bo_manager_func);
41574 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41575 index dbc2def..0a9f710 100644
41576 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41577 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41578 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41579 zone->glob = glob;
41580 glob->zone_kernel = zone;
41581 ret = kobject_init_and_add(
41582 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41583 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41584 if (unlikely(ret != 0)) {
41585 kobject_put(&zone->kobj);
41586 return ret;
41587 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41588 zone->glob = glob;
41589 glob->zone_dma32 = zone;
41590 ret = kobject_init_and_add(
41591 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41592 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41593 if (unlikely(ret != 0)) {
41594 kobject_put(&zone->kobj);
41595 return ret;
41596 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41597 index 863bef9..cba15cf 100644
41598 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41599 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41600 @@ -391,9 +391,9 @@ out:
41601 static unsigned long
41602 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41603 {
41604 - static atomic_t start_pool = ATOMIC_INIT(0);
41605 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41606 unsigned i;
41607 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41608 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41609 struct ttm_page_pool *pool;
41610 int shrink_pages = sc->nr_to_scan;
41611 unsigned long freed = 0;
41612 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41613 index dbadd49..1b7457b 100644
41614 --- a/drivers/gpu/drm/udl/udl_fb.c
41615 +++ b/drivers/gpu/drm/udl/udl_fb.c
41616 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41617 fb_deferred_io_cleanup(info);
41618 kfree(info->fbdefio);
41619 info->fbdefio = NULL;
41620 - info->fbops->fb_mmap = udl_fb_mmap;
41621 }
41622
41623 pr_warn("released /dev/fb%d user=%d count=%d\n",
41624 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41625 index ad02732..144f5ed 100644
41626 --- a/drivers/gpu/drm/via/via_drv.h
41627 +++ b/drivers/gpu/drm/via/via_drv.h
41628 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41629 typedef uint32_t maskarray_t[5];
41630
41631 typedef struct drm_via_irq {
41632 - atomic_t irq_received;
41633 + atomic_unchecked_t irq_received;
41634 uint32_t pending_mask;
41635 uint32_t enable_mask;
41636 wait_queue_head_t irq_queue;
41637 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41638 struct timeval last_vblank;
41639 int last_vblank_valid;
41640 unsigned usec_per_vblank;
41641 - atomic_t vbl_received;
41642 + atomic_unchecked_t vbl_received;
41643 drm_via_state_t hc_state;
41644 char pci_buf[VIA_PCI_BUF_SIZE];
41645 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41646 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41647 index 1319433..a993b0c 100644
41648 --- a/drivers/gpu/drm/via/via_irq.c
41649 +++ b/drivers/gpu/drm/via/via_irq.c
41650 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41651 if (crtc != 0)
41652 return 0;
41653
41654 - return atomic_read(&dev_priv->vbl_received);
41655 + return atomic_read_unchecked(&dev_priv->vbl_received);
41656 }
41657
41658 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41659 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41660
41661 status = VIA_READ(VIA_REG_INTERRUPT);
41662 if (status & VIA_IRQ_VBLANK_PENDING) {
41663 - atomic_inc(&dev_priv->vbl_received);
41664 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41665 + atomic_inc_unchecked(&dev_priv->vbl_received);
41666 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41667 do_gettimeofday(&cur_vblank);
41668 if (dev_priv->last_vblank_valid) {
41669 dev_priv->usec_per_vblank =
41670 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41671 dev_priv->last_vblank = cur_vblank;
41672 dev_priv->last_vblank_valid = 1;
41673 }
41674 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41675 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41676 DRM_DEBUG("US per vblank is: %u\n",
41677 dev_priv->usec_per_vblank);
41678 }
41679 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41680
41681 for (i = 0; i < dev_priv->num_irqs; ++i) {
41682 if (status & cur_irq->pending_mask) {
41683 - atomic_inc(&cur_irq->irq_received);
41684 + atomic_inc_unchecked(&cur_irq->irq_received);
41685 wake_up(&cur_irq->irq_queue);
41686 handled = 1;
41687 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41688 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41689 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41690 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41691 masks[irq][4]));
41692 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41693 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41694 } else {
41695 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41696 (((cur_irq_sequence =
41697 - atomic_read(&cur_irq->irq_received)) -
41698 + atomic_read_unchecked(&cur_irq->irq_received)) -
41699 *sequence) <= (1 << 23)));
41700 }
41701 *sequence = cur_irq_sequence;
41702 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41703 }
41704
41705 for (i = 0; i < dev_priv->num_irqs; ++i) {
41706 - atomic_set(&cur_irq->irq_received, 0);
41707 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41708 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41709 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41710 init_waitqueue_head(&cur_irq->irq_queue);
41711 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41712 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41713 case VIA_IRQ_RELATIVE:
41714 irqwait->request.sequence +=
41715 - atomic_read(&cur_irq->irq_received);
41716 + atomic_read_unchecked(&cur_irq->irq_received);
41717 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41718 case VIA_IRQ_ABSOLUTE:
41719 break;
41720 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41721 index 0783155..b29e18e 100644
41722 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41723 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41724 @@ -437,7 +437,7 @@ struct vmw_private {
41725 * Fencing and IRQs.
41726 */
41727
41728 - atomic_t marker_seq;
41729 + atomic_unchecked_t marker_seq;
41730 wait_queue_head_t fence_queue;
41731 wait_queue_head_t fifo_queue;
41732 int fence_queue_waiters; /* Protected by hw_mutex */
41733 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41734 index 6ccd993..618d592 100644
41735 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41736 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41737 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41738 (unsigned int) min,
41739 (unsigned int) fifo->capabilities);
41740
41741 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41742 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41743 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41744 vmw_marker_queue_init(&fifo->marker_queue);
41745 return vmw_fifo_send_fence(dev_priv, &dummy);
41746 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41747 if (reserveable)
41748 iowrite32(bytes, fifo_mem +
41749 SVGA_FIFO_RESERVED);
41750 - return fifo_mem + (next_cmd >> 2);
41751 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41752 } else {
41753 need_bounce = true;
41754 }
41755 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41756
41757 fm = vmw_fifo_reserve(dev_priv, bytes);
41758 if (unlikely(fm == NULL)) {
41759 - *seqno = atomic_read(&dev_priv->marker_seq);
41760 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41761 ret = -ENOMEM;
41762 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41763 false, 3*HZ);
41764 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41765 }
41766
41767 do {
41768 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41769 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41770 } while (*seqno == 0);
41771
41772 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41773 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41774 index b1273e8..9c274fd 100644
41775 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41776 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41777 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41778 }
41779
41780 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41781 - vmw_gmrid_man_init,
41782 - vmw_gmrid_man_takedown,
41783 - vmw_gmrid_man_get_node,
41784 - vmw_gmrid_man_put_node,
41785 - vmw_gmrid_man_debug
41786 + .init = vmw_gmrid_man_init,
41787 + .takedown = vmw_gmrid_man_takedown,
41788 + .get_node = vmw_gmrid_man_get_node,
41789 + .put_node = vmw_gmrid_man_put_node,
41790 + .debug = vmw_gmrid_man_debug
41791 };
41792 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41793 index 47b7094..698ba09 100644
41794 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41795 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41796 @@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41797 int ret;
41798
41799 num_clips = arg->num_clips;
41800 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41801 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41802
41803 if (unlikely(num_clips == 0))
41804 return 0;
41805 @@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41806 int ret;
41807
41808 num_clips = arg->num_clips;
41809 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41810 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41811
41812 if (unlikely(num_clips == 0))
41813 return 0;
41814 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41815 index 0c42376..6febe77 100644
41816 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41817 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41818 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41819 * emitted. Then the fence is stale and signaled.
41820 */
41821
41822 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41823 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41824 > VMW_FENCE_WRAP);
41825
41826 return ret;
41827 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41828
41829 if (fifo_idle)
41830 down_read(&fifo_state->rwsem);
41831 - signal_seq = atomic_read(&dev_priv->marker_seq);
41832 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41833 ret = 0;
41834
41835 for (;;) {
41836 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41837 index 8a8725c2..afed796 100644
41838 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41839 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41840 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41841 while (!vmw_lag_lt(queue, us)) {
41842 spin_lock(&queue->lock);
41843 if (list_empty(&queue->head))
41844 - seqno = atomic_read(&dev_priv->marker_seq);
41845 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41846 else {
41847 marker = list_first_entry(&queue->head,
41848 struct vmw_marker, head);
41849 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41850 index ec0ae2d..dc0780b 100644
41851 --- a/drivers/gpu/vga/vga_switcheroo.c
41852 +++ b/drivers/gpu/vga/vga_switcheroo.c
41853 @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41854
41855 /* this version is for the case where the power switch is separate
41856 to the device being powered down. */
41857 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41858 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41859 {
41860 /* copy over all the bus versions */
41861 if (dev->bus && dev->bus->pm) {
41862 @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41863 return ret;
41864 }
41865
41866 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41867 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41868 {
41869 /* copy over all the bus versions */
41870 if (dev->bus && dev->bus->pm) {
41871 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41872 index cc32a6f..02a4b1c 100644
41873 --- a/drivers/hid/hid-core.c
41874 +++ b/drivers/hid/hid-core.c
41875 @@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41876
41877 int hid_add_device(struct hid_device *hdev)
41878 {
41879 - static atomic_t id = ATOMIC_INIT(0);
41880 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41881 int ret;
41882
41883 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41884 @@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
41885 /* XXX hack, any other cleaner solution after the driver core
41886 * is converted to allow more than 20 bytes as the device name? */
41887 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41888 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41889 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41890
41891 hid_debug_register(hdev, dev_name(&hdev->dev));
41892 ret = device_add(&hdev->dev);
41893 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41894 index c13fb5b..55a3802 100644
41895 --- a/drivers/hid/hid-wiimote-debug.c
41896 +++ b/drivers/hid/hid-wiimote-debug.c
41897 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41898 else if (size == 0)
41899 return -EIO;
41900
41901 - if (copy_to_user(u, buf, size))
41902 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41903 return -EFAULT;
41904
41905 *off += size;
41906 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41907 index cedc6da..2c3da2a 100644
41908 --- a/drivers/hid/uhid.c
41909 +++ b/drivers/hid/uhid.c
41910 @@ -47,7 +47,7 @@ struct uhid_device {
41911 struct mutex report_lock;
41912 wait_queue_head_t report_wait;
41913 atomic_t report_done;
41914 - atomic_t report_id;
41915 + atomic_unchecked_t report_id;
41916 struct uhid_event report_buf;
41917 };
41918
41919 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41920
41921 spin_lock_irqsave(&uhid->qlock, flags);
41922 ev->type = UHID_FEATURE;
41923 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41924 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41925 ev->u.feature.rnum = rnum;
41926 ev->u.feature.rtype = report_type;
41927
41928 @@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41929 spin_lock_irqsave(&uhid->qlock, flags);
41930
41931 /* id for old report; drop it silently */
41932 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41933 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41934 goto unlock;
41935 if (atomic_read(&uhid->report_done))
41936 goto unlock;
41937 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41938 index 69ea36f..8dbf4bb 100644
41939 --- a/drivers/hv/channel.c
41940 +++ b/drivers/hv/channel.c
41941 @@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41942 int ret = 0;
41943 int t;
41944
41945 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41946 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41947 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41948 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41949
41950 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41951 if (ret)
41952 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41953 index bcb4950..61dba6c 100644
41954 --- a/drivers/hv/hv.c
41955 +++ b/drivers/hv/hv.c
41956 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41957 u64 output_address = (output) ? virt_to_phys(output) : 0;
41958 u32 output_address_hi = output_address >> 32;
41959 u32 output_address_lo = output_address & 0xFFFFFFFF;
41960 - void *hypercall_page = hv_context.hypercall_page;
41961 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41962
41963 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41964 "=a"(hv_status_lo) : "d" (control_hi),
41965 @@ -154,7 +154,7 @@ int hv_init(void)
41966 /* See if the hypercall page is already set */
41967 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41968
41969 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41970 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41971
41972 if (!virtaddr)
41973 goto cleanup;
41974 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41975 index 7e17a54..a50a33d 100644
41976 --- a/drivers/hv/hv_balloon.c
41977 +++ b/drivers/hv/hv_balloon.c
41978 @@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41979
41980 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41981 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41982 -static atomic_t trans_id = ATOMIC_INIT(0);
41983 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41984
41985 static int dm_ring_size = (5 * PAGE_SIZE);
41986
41987 @@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41988 pr_info("Memory hot add failed\n");
41989
41990 dm->state = DM_INITIALIZED;
41991 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41992 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41993 vmbus_sendpacket(dm->dev->channel, &resp,
41994 sizeof(struct dm_hot_add_response),
41995 (unsigned long)NULL,
41996 @@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41997 memset(&status, 0, sizeof(struct dm_status));
41998 status.hdr.type = DM_STATUS_REPORT;
41999 status.hdr.size = sizeof(struct dm_status);
42000 - status.hdr.trans_id = atomic_inc_return(&trans_id);
42001 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42002
42003 /*
42004 * The host expects the guest to report free memory.
42005 @@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
42006 * send the status. This can happen if we were interrupted
42007 * after we picked our transaction ID.
42008 */
42009 - if (status.hdr.trans_id != atomic_read(&trans_id))
42010 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42011 return;
42012
42013 vmbus_sendpacket(dm->dev->channel, &status,
42014 @@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
42015 */
42016
42017 do {
42018 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42019 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42020 ret = vmbus_sendpacket(dm_device.dev->channel,
42021 bl_resp,
42022 bl_resp->hdr.size,
42023 @@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42024
42025 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42026 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42027 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
42028 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42029 resp.hdr.size = sizeof(struct dm_unballoon_response);
42030
42031 vmbus_sendpacket(dm_device.dev->channel, &resp,
42032 @@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42033 memset(&version_req, 0, sizeof(struct dm_version_request));
42034 version_req.hdr.type = DM_VERSION_REQUEST;
42035 version_req.hdr.size = sizeof(struct dm_version_request);
42036 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42037 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42038 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42039 version_req.is_last_attempt = 1;
42040
42041 @@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
42042 memset(&version_req, 0, sizeof(struct dm_version_request));
42043 version_req.hdr.type = DM_VERSION_REQUEST;
42044 version_req.hdr.size = sizeof(struct dm_version_request);
42045 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42046 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42047 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42048 version_req.is_last_attempt = 0;
42049
42050 @@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
42051 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42052 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42053 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42054 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42055 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42056
42057 cap_msg.caps.cap_bits.balloon = 1;
42058 cap_msg.caps.cap_bits.hot_add = 1;
42059 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42060 index e055176..c22ff1f 100644
42061 --- a/drivers/hv/hyperv_vmbus.h
42062 +++ b/drivers/hv/hyperv_vmbus.h
42063 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
42064 struct vmbus_connection {
42065 enum vmbus_connect_state conn_state;
42066
42067 - atomic_t next_gpadl_handle;
42068 + atomic_unchecked_t next_gpadl_handle;
42069
42070 /*
42071 * Represents channel interrupts. Each bit position represents a
42072 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42073 index 077bb1b..d433d74 100644
42074 --- a/drivers/hv/vmbus_drv.c
42075 +++ b/drivers/hv/vmbus_drv.c
42076 @@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42077 {
42078 int ret = 0;
42079
42080 - static atomic_t device_num = ATOMIC_INIT(0);
42081 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42082
42083 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42084 - atomic_inc_return(&device_num));
42085 + atomic_inc_return_unchecked(&device_num));
42086
42087 child_device_obj->device.bus = &hv_bus;
42088 child_device_obj->device.parent = &hv_acpi_dev->dev;
42089 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42090 index 579bdf9..75118b5 100644
42091 --- a/drivers/hwmon/acpi_power_meter.c
42092 +++ b/drivers/hwmon/acpi_power_meter.c
42093 @@ -116,7 +116,7 @@ struct sensor_template {
42094 struct device_attribute *devattr,
42095 const char *buf, size_t count);
42096 int index;
42097 -};
42098 +} __do_const;
42099
42100 /* Averaging interval */
42101 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42102 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42103 struct sensor_template *attrs)
42104 {
42105 struct device *dev = &resource->acpi_dev->dev;
42106 - struct sensor_device_attribute *sensors =
42107 + sensor_device_attribute_no_const *sensors =
42108 &resource->sensors[resource->num_sensors];
42109 int res = 0;
42110
42111 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42112 index 3288f13..71cfb4e 100644
42113 --- a/drivers/hwmon/applesmc.c
42114 +++ b/drivers/hwmon/applesmc.c
42115 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42116 {
42117 struct applesmc_node_group *grp;
42118 struct applesmc_dev_attr *node;
42119 - struct attribute *attr;
42120 + attribute_no_const *attr;
42121 int ret, i;
42122
42123 for (grp = groups; grp->format; grp++) {
42124 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42125 index ae208f6..48b6c5b 100644
42126 --- a/drivers/hwmon/asus_atk0110.c
42127 +++ b/drivers/hwmon/asus_atk0110.c
42128 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42129 struct atk_sensor_data {
42130 struct list_head list;
42131 struct atk_data *data;
42132 - struct device_attribute label_attr;
42133 - struct device_attribute input_attr;
42134 - struct device_attribute limit1_attr;
42135 - struct device_attribute limit2_attr;
42136 + device_attribute_no_const label_attr;
42137 + device_attribute_no_const input_attr;
42138 + device_attribute_no_const limit1_attr;
42139 + device_attribute_no_const limit2_attr;
42140 char label_attr_name[ATTR_NAME_SIZE];
42141 char input_attr_name[ATTR_NAME_SIZE];
42142 char limit1_attr_name[ATTR_NAME_SIZE];
42143 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42144 static struct device_attribute atk_name_attr =
42145 __ATTR(name, 0444, atk_name_show, NULL);
42146
42147 -static void atk_init_attribute(struct device_attribute *attr, char *name,
42148 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42149 sysfs_show_func show)
42150 {
42151 sysfs_attr_init(&attr->attr);
42152 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42153 index bbb0b0d..9fe1332 100644
42154 --- a/drivers/hwmon/coretemp.c
42155 +++ b/drivers/hwmon/coretemp.c
42156 @@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42157 return NOTIFY_OK;
42158 }
42159
42160 -static struct notifier_block coretemp_cpu_notifier __refdata = {
42161 +static struct notifier_block coretemp_cpu_notifier = {
42162 .notifier_call = coretemp_cpu_callback,
42163 };
42164
42165 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42166 index 632f1dc..57e6a58 100644
42167 --- a/drivers/hwmon/ibmaem.c
42168 +++ b/drivers/hwmon/ibmaem.c
42169 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
42170 struct aem_rw_sensor_template *rw)
42171 {
42172 struct device *dev = &data->pdev->dev;
42173 - struct sensor_device_attribute *sensors = data->sensors;
42174 + sensor_device_attribute_no_const *sensors = data->sensors;
42175 int err;
42176
42177 /* Set up read-only sensors */
42178 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42179 index 708081b..fe2d4ab 100644
42180 --- a/drivers/hwmon/iio_hwmon.c
42181 +++ b/drivers/hwmon/iio_hwmon.c
42182 @@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42183 {
42184 struct device *dev = &pdev->dev;
42185 struct iio_hwmon_state *st;
42186 - struct sensor_device_attribute *a;
42187 + sensor_device_attribute_no_const *a;
42188 int ret, i;
42189 int in_i = 1, temp_i = 1, curr_i = 1;
42190 enum iio_chan_type type;
42191 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42192 index 38d5a63..cf2c2ea 100644
42193 --- a/drivers/hwmon/nct6775.c
42194 +++ b/drivers/hwmon/nct6775.c
42195 @@ -944,10 +944,10 @@ static struct attribute_group *
42196 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42197 int repeat)
42198 {
42199 - struct attribute_group *group;
42200 + attribute_group_no_const *group;
42201 struct sensor_device_attr_u *su;
42202 - struct sensor_device_attribute *a;
42203 - struct sensor_device_attribute_2 *a2;
42204 + sensor_device_attribute_no_const *a;
42205 + sensor_device_attribute_2_no_const *a2;
42206 struct attribute **attrs;
42207 struct sensor_device_template **t;
42208 int i, count;
42209 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42210 index 291d11f..3f0dbbd 100644
42211 --- a/drivers/hwmon/pmbus/pmbus_core.c
42212 +++ b/drivers/hwmon/pmbus/pmbus_core.c
42213 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42214 return 0;
42215 }
42216
42217 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42218 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42219 const char *name,
42220 umode_t mode,
42221 ssize_t (*show)(struct device *dev,
42222 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42223 dev_attr->store = store;
42224 }
42225
42226 -static void pmbus_attr_init(struct sensor_device_attribute *a,
42227 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42228 const char *name,
42229 umode_t mode,
42230 ssize_t (*show)(struct device *dev,
42231 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42232 u16 reg, u8 mask)
42233 {
42234 struct pmbus_boolean *boolean;
42235 - struct sensor_device_attribute *a;
42236 + sensor_device_attribute_no_const *a;
42237
42238 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42239 if (!boolean)
42240 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42241 bool update, bool readonly)
42242 {
42243 struct pmbus_sensor *sensor;
42244 - struct device_attribute *a;
42245 + device_attribute_no_const *a;
42246
42247 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42248 if (!sensor)
42249 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42250 const char *lstring, int index)
42251 {
42252 struct pmbus_label *label;
42253 - struct device_attribute *a;
42254 + device_attribute_no_const *a;
42255
42256 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42257 if (!label)
42258 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42259 index 97cd45a..ac54d8b 100644
42260 --- a/drivers/hwmon/sht15.c
42261 +++ b/drivers/hwmon/sht15.c
42262 @@ -169,7 +169,7 @@ struct sht15_data {
42263 int supply_uv;
42264 bool supply_uv_valid;
42265 struct work_struct update_supply_work;
42266 - atomic_t interrupt_handled;
42267 + atomic_unchecked_t interrupt_handled;
42268 };
42269
42270 /**
42271 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42272 ret = gpio_direction_input(data->pdata->gpio_data);
42273 if (ret)
42274 return ret;
42275 - atomic_set(&data->interrupt_handled, 0);
42276 + atomic_set_unchecked(&data->interrupt_handled, 0);
42277
42278 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42279 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42280 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42281 /* Only relevant if the interrupt hasn't occurred. */
42282 - if (!atomic_read(&data->interrupt_handled))
42283 + if (!atomic_read_unchecked(&data->interrupt_handled))
42284 schedule_work(&data->read_work);
42285 }
42286 ret = wait_event_timeout(data->wait_queue,
42287 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42288
42289 /* First disable the interrupt */
42290 disable_irq_nosync(irq);
42291 - atomic_inc(&data->interrupt_handled);
42292 + atomic_inc_unchecked(&data->interrupt_handled);
42293 /* Then schedule a reading work struct */
42294 if (data->state != SHT15_READING_NOTHING)
42295 schedule_work(&data->read_work);
42296 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42297 * If not, then start the interrupt again - care here as could
42298 * have gone low in meantime so verify it hasn't!
42299 */
42300 - atomic_set(&data->interrupt_handled, 0);
42301 + atomic_set_unchecked(&data->interrupt_handled, 0);
42302 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42303 /* If still not occurred or another handler was scheduled */
42304 if (gpio_get_value(data->pdata->gpio_data)
42305 - || atomic_read(&data->interrupt_handled))
42306 + || atomic_read_unchecked(&data->interrupt_handled))
42307 return;
42308 }
42309
42310 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42311 index 38944e9..ae9e5ed 100644
42312 --- a/drivers/hwmon/via-cputemp.c
42313 +++ b/drivers/hwmon/via-cputemp.c
42314 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42315 return NOTIFY_OK;
42316 }
42317
42318 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42319 +static struct notifier_block via_cputemp_cpu_notifier = {
42320 .notifier_call = via_cputemp_cpu_callback,
42321 };
42322
42323 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42324 index 41fc683..a39cfea 100644
42325 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
42326 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42327 @@ -43,7 +43,7 @@
42328 extern struct i2c_adapter amd756_smbus;
42329
42330 static struct i2c_adapter *s4882_adapter;
42331 -static struct i2c_algorithm *s4882_algo;
42332 +static i2c_algorithm_no_const *s4882_algo;
42333
42334 /* Wrapper access functions for multiplexed SMBus */
42335 static DEFINE_MUTEX(amd756_lock);
42336 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42337 index 721f7eb..0fd2a09 100644
42338 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
42339 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42340 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42341 /* usb layer */
42342
42343 /* Send command to device, and get response. */
42344 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42345 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42346 {
42347 int ret = 0;
42348 int actual;
42349 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42350 index b170bdf..3c76427 100644
42351 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42352 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42353 @@ -41,7 +41,7 @@
42354 extern struct i2c_adapter *nforce2_smbus;
42355
42356 static struct i2c_adapter *s4985_adapter;
42357 -static struct i2c_algorithm *s4985_algo;
42358 +static i2c_algorithm_no_const *s4985_algo;
42359
42360 /* Wrapper access functions for multiplexed SMBus */
42361 static DEFINE_MUTEX(nforce2_lock);
42362 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42363 index 80b47e8..1a6040d9 100644
42364 --- a/drivers/i2c/i2c-dev.c
42365 +++ b/drivers/i2c/i2c-dev.c
42366 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42367 break;
42368 }
42369
42370 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42371 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42372 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42373 if (IS_ERR(rdwr_pa[i].buf)) {
42374 res = PTR_ERR(rdwr_pa[i].buf);
42375 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42376 index 0b510ba..4fbb5085 100644
42377 --- a/drivers/ide/ide-cd.c
42378 +++ b/drivers/ide/ide-cd.c
42379 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42380 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42381 if ((unsigned long)buf & alignment
42382 || blk_rq_bytes(rq) & q->dma_pad_mask
42383 - || object_is_on_stack(buf))
42384 + || object_starts_on_stack(buf))
42385 drive->dma = 0;
42386 }
42387 }
42388 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42389 index acc911a..8700c3c 100644
42390 --- a/drivers/iio/industrialio-core.c
42391 +++ b/drivers/iio/industrialio-core.c
42392 @@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42393 }
42394
42395 static
42396 -int __iio_device_attr_init(struct device_attribute *dev_attr,
42397 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42398 const char *postfix,
42399 struct iio_chan_spec const *chan,
42400 ssize_t (*readfunc)(struct device *dev,
42401 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42402 index c323917..6ddea8b 100644
42403 --- a/drivers/infiniband/core/cm.c
42404 +++ b/drivers/infiniband/core/cm.c
42405 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42406
42407 struct cm_counter_group {
42408 struct kobject obj;
42409 - atomic_long_t counter[CM_ATTR_COUNT];
42410 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42411 };
42412
42413 struct cm_counter_attribute {
42414 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42415 struct ib_mad_send_buf *msg = NULL;
42416 int ret;
42417
42418 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42419 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42420 counter[CM_REQ_COUNTER]);
42421
42422 /* Quick state check to discard duplicate REQs. */
42423 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42424 if (!cm_id_priv)
42425 return;
42426
42427 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42428 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42429 counter[CM_REP_COUNTER]);
42430 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42431 if (ret)
42432 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42433 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42434 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42435 spin_unlock_irq(&cm_id_priv->lock);
42436 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42437 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42438 counter[CM_RTU_COUNTER]);
42439 goto out;
42440 }
42441 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42442 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42443 dreq_msg->local_comm_id);
42444 if (!cm_id_priv) {
42445 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42446 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42447 counter[CM_DREQ_COUNTER]);
42448 cm_issue_drep(work->port, work->mad_recv_wc);
42449 return -EINVAL;
42450 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42451 case IB_CM_MRA_REP_RCVD:
42452 break;
42453 case IB_CM_TIMEWAIT:
42454 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42455 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42456 counter[CM_DREQ_COUNTER]);
42457 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42458 goto unlock;
42459 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42460 cm_free_msg(msg);
42461 goto deref;
42462 case IB_CM_DREQ_RCVD:
42463 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42464 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42465 counter[CM_DREQ_COUNTER]);
42466 goto unlock;
42467 default:
42468 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42469 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42470 cm_id_priv->msg, timeout)) {
42471 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42472 - atomic_long_inc(&work->port->
42473 + atomic_long_inc_unchecked(&work->port->
42474 counter_group[CM_RECV_DUPLICATES].
42475 counter[CM_MRA_COUNTER]);
42476 goto out;
42477 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42478 break;
42479 case IB_CM_MRA_REQ_RCVD:
42480 case IB_CM_MRA_REP_RCVD:
42481 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42482 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42483 counter[CM_MRA_COUNTER]);
42484 /* fall through */
42485 default:
42486 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42487 case IB_CM_LAP_IDLE:
42488 break;
42489 case IB_CM_MRA_LAP_SENT:
42490 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42491 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42492 counter[CM_LAP_COUNTER]);
42493 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42494 goto unlock;
42495 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42496 cm_free_msg(msg);
42497 goto deref;
42498 case IB_CM_LAP_RCVD:
42499 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42500 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42501 counter[CM_LAP_COUNTER]);
42502 goto unlock;
42503 default:
42504 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42505 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42506 if (cur_cm_id_priv) {
42507 spin_unlock_irq(&cm.lock);
42508 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42509 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42510 counter[CM_SIDR_REQ_COUNTER]);
42511 goto out; /* Duplicate message. */
42512 }
42513 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42514 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42515 msg->retries = 1;
42516
42517 - atomic_long_add(1 + msg->retries,
42518 + atomic_long_add_unchecked(1 + msg->retries,
42519 &port->counter_group[CM_XMIT].counter[attr_index]);
42520 if (msg->retries)
42521 - atomic_long_add(msg->retries,
42522 + atomic_long_add_unchecked(msg->retries,
42523 &port->counter_group[CM_XMIT_RETRIES].
42524 counter[attr_index]);
42525
42526 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42527 }
42528
42529 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42530 - atomic_long_inc(&port->counter_group[CM_RECV].
42531 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42532 counter[attr_id - CM_ATTR_ID_OFFSET]);
42533
42534 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42535 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42536 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42537
42538 return sprintf(buf, "%ld\n",
42539 - atomic_long_read(&group->counter[cm_attr->index]));
42540 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42541 }
42542
42543 static const struct sysfs_ops cm_counter_ops = {
42544 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42545 index 9f5ad7c..588cd84 100644
42546 --- a/drivers/infiniband/core/fmr_pool.c
42547 +++ b/drivers/infiniband/core/fmr_pool.c
42548 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42549
42550 struct task_struct *thread;
42551
42552 - atomic_t req_ser;
42553 - atomic_t flush_ser;
42554 + atomic_unchecked_t req_ser;
42555 + atomic_unchecked_t flush_ser;
42556
42557 wait_queue_head_t force_wait;
42558 };
42559 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42560 struct ib_fmr_pool *pool = pool_ptr;
42561
42562 do {
42563 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42564 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42565 ib_fmr_batch_release(pool);
42566
42567 - atomic_inc(&pool->flush_ser);
42568 + atomic_inc_unchecked(&pool->flush_ser);
42569 wake_up_interruptible(&pool->force_wait);
42570
42571 if (pool->flush_function)
42572 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42573 }
42574
42575 set_current_state(TASK_INTERRUPTIBLE);
42576 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42577 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42578 !kthread_should_stop())
42579 schedule();
42580 __set_current_state(TASK_RUNNING);
42581 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42582 pool->dirty_watermark = params->dirty_watermark;
42583 pool->dirty_len = 0;
42584 spin_lock_init(&pool->pool_lock);
42585 - atomic_set(&pool->req_ser, 0);
42586 - atomic_set(&pool->flush_ser, 0);
42587 + atomic_set_unchecked(&pool->req_ser, 0);
42588 + atomic_set_unchecked(&pool->flush_ser, 0);
42589 init_waitqueue_head(&pool->force_wait);
42590
42591 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42592 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42593 }
42594 spin_unlock_irq(&pool->pool_lock);
42595
42596 - serial = atomic_inc_return(&pool->req_ser);
42597 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42598 wake_up_process(pool->thread);
42599
42600 if (wait_event_interruptible(pool->force_wait,
42601 - atomic_read(&pool->flush_ser) - serial >= 0))
42602 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42603 return -EINTR;
42604
42605 return 0;
42606 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42607 } else {
42608 list_add_tail(&fmr->list, &pool->dirty_list);
42609 if (++pool->dirty_len >= pool->dirty_watermark) {
42610 - atomic_inc(&pool->req_ser);
42611 + atomic_inc_unchecked(&pool->req_ser);
42612 wake_up_process(pool->thread);
42613 }
42614 }
42615 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42616 index 41b1195..27971a0 100644
42617 --- a/drivers/infiniband/hw/cxgb4/mem.c
42618 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42619 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42620 int err;
42621 struct fw_ri_tpte tpt;
42622 u32 stag_idx;
42623 - static atomic_t key;
42624 + static atomic_unchecked_t key;
42625
42626 if (c4iw_fatal_error(rdev))
42627 return -EIO;
42628 @@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42629 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42630 rdev->stats.stag.max = rdev->stats.stag.cur;
42631 mutex_unlock(&rdev->stats.lock);
42632 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42633 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42634 }
42635 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42636 __func__, stag_state, type, pdid, stag_idx);
42637 diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42638 index 644c2c7..ecf0879 100644
42639 --- a/drivers/infiniband/hw/ipath/ipath_dma.c
42640 +++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42641 @@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42642 }
42643
42644 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42645 - ipath_mapping_error,
42646 - ipath_dma_map_single,
42647 - ipath_dma_unmap_single,
42648 - ipath_dma_map_page,
42649 - ipath_dma_unmap_page,
42650 - ipath_map_sg,
42651 - ipath_unmap_sg,
42652 - ipath_sg_dma_address,
42653 - ipath_sg_dma_len,
42654 - ipath_sync_single_for_cpu,
42655 - ipath_sync_single_for_device,
42656 - ipath_dma_alloc_coherent,
42657 - ipath_dma_free_coherent
42658 + .mapping_error = ipath_mapping_error,
42659 + .map_single = ipath_dma_map_single,
42660 + .unmap_single = ipath_dma_unmap_single,
42661 + .map_page = ipath_dma_map_page,
42662 + .unmap_page = ipath_dma_unmap_page,
42663 + .map_sg = ipath_map_sg,
42664 + .unmap_sg = ipath_unmap_sg,
42665 + .dma_address = ipath_sg_dma_address,
42666 + .dma_len = ipath_sg_dma_len,
42667 + .sync_single_for_cpu = ipath_sync_single_for_cpu,
42668 + .sync_single_for_device = ipath_sync_single_for_device,
42669 + .alloc_coherent = ipath_dma_alloc_coherent,
42670 + .free_coherent = ipath_dma_free_coherent
42671 };
42672 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42673 index 79b3dbc..96e5fcc 100644
42674 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42675 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42676 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42677 struct ib_atomic_eth *ateth;
42678 struct ipath_ack_entry *e;
42679 u64 vaddr;
42680 - atomic64_t *maddr;
42681 + atomic64_unchecked_t *maddr;
42682 u64 sdata;
42683 u32 rkey;
42684 u8 next;
42685 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42686 IB_ACCESS_REMOTE_ATOMIC)))
42687 goto nack_acc_unlck;
42688 /* Perform atomic OP and save result. */
42689 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42690 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42691 sdata = be64_to_cpu(ateth->swap_data);
42692 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42693 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42694 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42695 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42696 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42697 be64_to_cpu(ateth->compare_data),
42698 sdata);
42699 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42700 index 1f95bba..9530f87 100644
42701 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42702 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42703 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42704 unsigned long flags;
42705 struct ib_wc wc;
42706 u64 sdata;
42707 - atomic64_t *maddr;
42708 + atomic64_unchecked_t *maddr;
42709 enum ib_wc_status send_status;
42710
42711 /*
42712 @@ -382,11 +382,11 @@ again:
42713 IB_ACCESS_REMOTE_ATOMIC)))
42714 goto acc_err;
42715 /* Perform atomic OP and save result. */
42716 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42717 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42718 sdata = wqe->wr.wr.atomic.compare_add;
42719 *(u64 *) sqp->s_sge.sge.vaddr =
42720 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42721 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42722 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42723 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42724 sdata, wqe->wr.wr.atomic.swap);
42725 goto send_comp;
42726 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42727 index f2a3f48..673ec79 100644
42728 --- a/drivers/infiniband/hw/mlx4/mad.c
42729 +++ b/drivers/infiniband/hw/mlx4/mad.c
42730 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42731
42732 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42733 {
42734 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42735 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42736 cpu_to_be64(0xff00000000000000LL);
42737 }
42738
42739 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42740 index 25b2cdf..099ff97 100644
42741 --- a/drivers/infiniband/hw/mlx4/mcg.c
42742 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42743 @@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42744 {
42745 char name[20];
42746
42747 - atomic_set(&ctx->tid, 0);
42748 + atomic_set_unchecked(&ctx->tid, 0);
42749 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42750 ctx->mcg_wq = create_singlethread_workqueue(name);
42751 if (!ctx->mcg_wq)
42752 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42753 index a230683..3723f2d 100644
42754 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42755 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42756 @@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42757 struct list_head mcg_mgid0_list;
42758 struct workqueue_struct *mcg_wq;
42759 struct mlx4_ib_demux_pv_ctx **tun;
42760 - atomic_t tid;
42761 + atomic_unchecked_t tid;
42762 int flushing; /* flushing the work queue */
42763 };
42764
42765 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42766 index 9d3e5c1..6f166df 100644
42767 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42768 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42769 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42770 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42771 }
42772
42773 -int mthca_QUERY_FW(struct mthca_dev *dev)
42774 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42775 {
42776 struct mthca_mailbox *mailbox;
42777 u32 *outbox;
42778 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42779 CMD_TIME_CLASS_B);
42780 }
42781
42782 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42783 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42784 int num_mtt)
42785 {
42786 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42787 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42788 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42789 }
42790
42791 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42792 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42793 int eq_num)
42794 {
42795 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42796 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42797 CMD_TIME_CLASS_B);
42798 }
42799
42800 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42801 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42802 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42803 void *in_mad, void *response_mad)
42804 {
42805 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42806 index 87897b9..7e79542 100644
42807 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42808 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42809 @@ -692,7 +692,7 @@ err_close:
42810 return err;
42811 }
42812
42813 -static int mthca_setup_hca(struct mthca_dev *dev)
42814 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42815 {
42816 int err;
42817
42818 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42819 index ed9a989..6aa5dc2 100644
42820 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42821 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42822 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42823 * through the bitmaps)
42824 */
42825
42826 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42827 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42828 {
42829 int o;
42830 int m;
42831 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42832 return key;
42833 }
42834
42835 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42836 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42837 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42838 {
42839 struct mthca_mailbox *mailbox;
42840 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42841 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42842 }
42843
42844 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42845 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42846 u64 *buffer_list, int buffer_size_shift,
42847 int list_len, u64 iova, u64 total_size,
42848 u32 access, struct mthca_mr *mr)
42849 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42850 index 42dde06..1257310 100644
42851 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42852 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42853 @@ -764,7 +764,7 @@ unlock:
42854 return 0;
42855 }
42856
42857 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42858 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42859 {
42860 struct mthca_dev *dev = to_mdev(ibcq->device);
42861 struct mthca_cq *cq = to_mcq(ibcq);
42862 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42863 index 353c7b0..c6ce921 100644
42864 --- a/drivers/infiniband/hw/nes/nes.c
42865 +++ b/drivers/infiniband/hw/nes/nes.c
42866 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42867 LIST_HEAD(nes_adapter_list);
42868 static LIST_HEAD(nes_dev_list);
42869
42870 -atomic_t qps_destroyed;
42871 +atomic_unchecked_t qps_destroyed;
42872
42873 static unsigned int ee_flsh_adapter;
42874 static unsigned int sysfs_nonidx_addr;
42875 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42876 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42877 struct nes_adapter *nesadapter = nesdev->nesadapter;
42878
42879 - atomic_inc(&qps_destroyed);
42880 + atomic_inc_unchecked(&qps_destroyed);
42881
42882 /* Free the control structures */
42883
42884 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42885 index 33cc589..3bd6538 100644
42886 --- a/drivers/infiniband/hw/nes/nes.h
42887 +++ b/drivers/infiniband/hw/nes/nes.h
42888 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42889 extern unsigned int wqm_quanta;
42890 extern struct list_head nes_adapter_list;
42891
42892 -extern atomic_t cm_connects;
42893 -extern atomic_t cm_accepts;
42894 -extern atomic_t cm_disconnects;
42895 -extern atomic_t cm_closes;
42896 -extern atomic_t cm_connecteds;
42897 -extern atomic_t cm_connect_reqs;
42898 -extern atomic_t cm_rejects;
42899 -extern atomic_t mod_qp_timouts;
42900 -extern atomic_t qps_created;
42901 -extern atomic_t qps_destroyed;
42902 -extern atomic_t sw_qps_destroyed;
42903 +extern atomic_unchecked_t cm_connects;
42904 +extern atomic_unchecked_t cm_accepts;
42905 +extern atomic_unchecked_t cm_disconnects;
42906 +extern atomic_unchecked_t cm_closes;
42907 +extern atomic_unchecked_t cm_connecteds;
42908 +extern atomic_unchecked_t cm_connect_reqs;
42909 +extern atomic_unchecked_t cm_rejects;
42910 +extern atomic_unchecked_t mod_qp_timouts;
42911 +extern atomic_unchecked_t qps_created;
42912 +extern atomic_unchecked_t qps_destroyed;
42913 +extern atomic_unchecked_t sw_qps_destroyed;
42914 extern u32 mh_detected;
42915 extern u32 mh_pauses_sent;
42916 extern u32 cm_packets_sent;
42917 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42918 extern u32 cm_packets_received;
42919 extern u32 cm_packets_dropped;
42920 extern u32 cm_packets_retrans;
42921 -extern atomic_t cm_listens_created;
42922 -extern atomic_t cm_listens_destroyed;
42923 +extern atomic_unchecked_t cm_listens_created;
42924 +extern atomic_unchecked_t cm_listens_destroyed;
42925 extern u32 cm_backlog_drops;
42926 -extern atomic_t cm_loopbacks;
42927 -extern atomic_t cm_nodes_created;
42928 -extern atomic_t cm_nodes_destroyed;
42929 -extern atomic_t cm_accel_dropped_pkts;
42930 -extern atomic_t cm_resets_recvd;
42931 -extern atomic_t pau_qps_created;
42932 -extern atomic_t pau_qps_destroyed;
42933 +extern atomic_unchecked_t cm_loopbacks;
42934 +extern atomic_unchecked_t cm_nodes_created;
42935 +extern atomic_unchecked_t cm_nodes_destroyed;
42936 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42937 +extern atomic_unchecked_t cm_resets_recvd;
42938 +extern atomic_unchecked_t pau_qps_created;
42939 +extern atomic_unchecked_t pau_qps_destroyed;
42940
42941 extern u32 int_mod_timer_init;
42942 extern u32 int_mod_cq_depth_256;
42943 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42944 index 9c9f2f5..2559190 100644
42945 --- a/drivers/infiniband/hw/nes/nes_cm.c
42946 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42947 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42948 u32 cm_packets_retrans;
42949 u32 cm_packets_created;
42950 u32 cm_packets_received;
42951 -atomic_t cm_listens_created;
42952 -atomic_t cm_listens_destroyed;
42953 +atomic_unchecked_t cm_listens_created;
42954 +atomic_unchecked_t cm_listens_destroyed;
42955 u32 cm_backlog_drops;
42956 -atomic_t cm_loopbacks;
42957 -atomic_t cm_nodes_created;
42958 -atomic_t cm_nodes_destroyed;
42959 -atomic_t cm_accel_dropped_pkts;
42960 -atomic_t cm_resets_recvd;
42961 +atomic_unchecked_t cm_loopbacks;
42962 +atomic_unchecked_t cm_nodes_created;
42963 +atomic_unchecked_t cm_nodes_destroyed;
42964 +atomic_unchecked_t cm_accel_dropped_pkts;
42965 +atomic_unchecked_t cm_resets_recvd;
42966
42967 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42968 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42969 @@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42970 /* instance of function pointers for client API */
42971 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42972 static struct nes_cm_ops nes_cm_api = {
42973 - mini_cm_accelerated,
42974 - mini_cm_listen,
42975 - mini_cm_del_listen,
42976 - mini_cm_connect,
42977 - mini_cm_close,
42978 - mini_cm_accept,
42979 - mini_cm_reject,
42980 - mini_cm_recv_pkt,
42981 - mini_cm_dealloc_core,
42982 - mini_cm_get,
42983 - mini_cm_set
42984 + .accelerated = mini_cm_accelerated,
42985 + .listen = mini_cm_listen,
42986 + .stop_listener = mini_cm_del_listen,
42987 + .connect = mini_cm_connect,
42988 + .close = mini_cm_close,
42989 + .accept = mini_cm_accept,
42990 + .reject = mini_cm_reject,
42991 + .recv_pkt = mini_cm_recv_pkt,
42992 + .destroy_cm_core = mini_cm_dealloc_core,
42993 + .get = mini_cm_get,
42994 + .set = mini_cm_set
42995 };
42996
42997 static struct nes_cm_core *g_cm_core;
42998
42999 -atomic_t cm_connects;
43000 -atomic_t cm_accepts;
43001 -atomic_t cm_disconnects;
43002 -atomic_t cm_closes;
43003 -atomic_t cm_connecteds;
43004 -atomic_t cm_connect_reqs;
43005 -atomic_t cm_rejects;
43006 +atomic_unchecked_t cm_connects;
43007 +atomic_unchecked_t cm_accepts;
43008 +atomic_unchecked_t cm_disconnects;
43009 +atomic_unchecked_t cm_closes;
43010 +atomic_unchecked_t cm_connecteds;
43011 +atomic_unchecked_t cm_connect_reqs;
43012 +atomic_unchecked_t cm_rejects;
43013
43014 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43015 {
43016 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43017 kfree(listener);
43018 listener = NULL;
43019 ret = 0;
43020 - atomic_inc(&cm_listens_destroyed);
43021 + atomic_inc_unchecked(&cm_listens_destroyed);
43022 } else {
43023 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43024 }
43025 @@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43026 cm_node->rem_mac);
43027
43028 add_hte_node(cm_core, cm_node);
43029 - atomic_inc(&cm_nodes_created);
43030 + atomic_inc_unchecked(&cm_nodes_created);
43031
43032 return cm_node;
43033 }
43034 @@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43035 }
43036
43037 atomic_dec(&cm_core->node_cnt);
43038 - atomic_inc(&cm_nodes_destroyed);
43039 + atomic_inc_unchecked(&cm_nodes_destroyed);
43040 nesqp = cm_node->nesqp;
43041 if (nesqp) {
43042 nesqp->cm_node = NULL;
43043 @@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43044
43045 static void drop_packet(struct sk_buff *skb)
43046 {
43047 - atomic_inc(&cm_accel_dropped_pkts);
43048 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43049 dev_kfree_skb_any(skb);
43050 }
43051
43052 @@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43053 {
43054
43055 int reset = 0; /* whether to send reset in case of err.. */
43056 - atomic_inc(&cm_resets_recvd);
43057 + atomic_inc_unchecked(&cm_resets_recvd);
43058 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43059 " refcnt=%d\n", cm_node, cm_node->state,
43060 atomic_read(&cm_node->ref_count));
43061 @@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43062 rem_ref_cm_node(cm_node->cm_core, cm_node);
43063 return NULL;
43064 }
43065 - atomic_inc(&cm_loopbacks);
43066 + atomic_inc_unchecked(&cm_loopbacks);
43067 loopbackremotenode->loopbackpartner = cm_node;
43068 loopbackremotenode->tcp_cntxt.rcv_wscale =
43069 NES_CM_DEFAULT_RCV_WND_SCALE;
43070 @@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43071 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43072 else {
43073 rem_ref_cm_node(cm_core, cm_node);
43074 - atomic_inc(&cm_accel_dropped_pkts);
43075 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
43076 dev_kfree_skb_any(skb);
43077 }
43078 break;
43079 @@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43080
43081 if ((cm_id) && (cm_id->event_handler)) {
43082 if (issue_disconn) {
43083 - atomic_inc(&cm_disconnects);
43084 + atomic_inc_unchecked(&cm_disconnects);
43085 cm_event.event = IW_CM_EVENT_DISCONNECT;
43086 cm_event.status = disconn_status;
43087 cm_event.local_addr = cm_id->local_addr;
43088 @@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43089 }
43090
43091 if (issue_close) {
43092 - atomic_inc(&cm_closes);
43093 + atomic_inc_unchecked(&cm_closes);
43094 nes_disconnect(nesqp, 1);
43095
43096 cm_id->provider_data = nesqp;
43097 @@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43098
43099 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43100 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43101 - atomic_inc(&cm_accepts);
43102 + atomic_inc_unchecked(&cm_accepts);
43103
43104 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43105 netdev_refcnt_read(nesvnic->netdev));
43106 @@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43107 struct nes_cm_core *cm_core;
43108 u8 *start_buff;
43109
43110 - atomic_inc(&cm_rejects);
43111 + atomic_inc_unchecked(&cm_rejects);
43112 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43113 loopback = cm_node->loopbackpartner;
43114 cm_core = cm_node->cm_core;
43115 @@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43116 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43117 ntohs(laddr->sin_port));
43118
43119 - atomic_inc(&cm_connects);
43120 + atomic_inc_unchecked(&cm_connects);
43121 nesqp->active_conn = 1;
43122
43123 /* cache the cm_id in the qp */
43124 @@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43125 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43126 return err;
43127 }
43128 - atomic_inc(&cm_listens_created);
43129 + atomic_inc_unchecked(&cm_listens_created);
43130 }
43131
43132 cm_id->add_ref(cm_id);
43133 @@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43134
43135 if (nesqp->destroyed)
43136 return;
43137 - atomic_inc(&cm_connecteds);
43138 + atomic_inc_unchecked(&cm_connecteds);
43139 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43140 " local port 0x%04X. jiffies = %lu.\n",
43141 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43142 @@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43143
43144 cm_id->add_ref(cm_id);
43145 ret = cm_id->event_handler(cm_id, &cm_event);
43146 - atomic_inc(&cm_closes);
43147 + atomic_inc_unchecked(&cm_closes);
43148 cm_event.event = IW_CM_EVENT_CLOSE;
43149 cm_event.status = 0;
43150 cm_event.provider_data = cm_id->provider_data;
43151 @@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43152 return;
43153 cm_id = cm_node->cm_id;
43154
43155 - atomic_inc(&cm_connect_reqs);
43156 + atomic_inc_unchecked(&cm_connect_reqs);
43157 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43158 cm_node, cm_id, jiffies);
43159
43160 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43161 return;
43162 cm_id = cm_node->cm_id;
43163
43164 - atomic_inc(&cm_connect_reqs);
43165 + atomic_inc_unchecked(&cm_connect_reqs);
43166 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43167 cm_node, cm_id, jiffies);
43168
43169 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43170 index 4166452..fc952c3 100644
43171 --- a/drivers/infiniband/hw/nes/nes_mgt.c
43172 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
43173 @@ -40,8 +40,8 @@
43174 #include "nes.h"
43175 #include "nes_mgt.h"
43176
43177 -atomic_t pau_qps_created;
43178 -atomic_t pau_qps_destroyed;
43179 +atomic_unchecked_t pau_qps_created;
43180 +atomic_unchecked_t pau_qps_destroyed;
43181
43182 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43183 {
43184 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43185 {
43186 struct sk_buff *skb;
43187 unsigned long flags;
43188 - atomic_inc(&pau_qps_destroyed);
43189 + atomic_inc_unchecked(&pau_qps_destroyed);
43190
43191 /* Free packets that have not yet been forwarded */
43192 /* Lock is acquired by skb_dequeue when removing the skb */
43193 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43194 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43195 skb_queue_head_init(&nesqp->pau_list);
43196 spin_lock_init(&nesqp->pau_lock);
43197 - atomic_inc(&pau_qps_created);
43198 + atomic_inc_unchecked(&pau_qps_created);
43199 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43200 }
43201
43202 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43203 index 49eb511..a774366 100644
43204 --- a/drivers/infiniband/hw/nes/nes_nic.c
43205 +++ b/drivers/infiniband/hw/nes/nes_nic.c
43206 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43207 target_stat_values[++index] = mh_detected;
43208 target_stat_values[++index] = mh_pauses_sent;
43209 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43210 - target_stat_values[++index] = atomic_read(&cm_connects);
43211 - target_stat_values[++index] = atomic_read(&cm_accepts);
43212 - target_stat_values[++index] = atomic_read(&cm_disconnects);
43213 - target_stat_values[++index] = atomic_read(&cm_connecteds);
43214 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43215 - target_stat_values[++index] = atomic_read(&cm_rejects);
43216 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43217 - target_stat_values[++index] = atomic_read(&qps_created);
43218 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43219 - target_stat_values[++index] = atomic_read(&qps_destroyed);
43220 - target_stat_values[++index] = atomic_read(&cm_closes);
43221 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43222 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43223 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43224 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43225 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43226 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43227 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43228 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43229 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43230 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43231 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43232 target_stat_values[++index] = cm_packets_sent;
43233 target_stat_values[++index] = cm_packets_bounced;
43234 target_stat_values[++index] = cm_packets_created;
43235 target_stat_values[++index] = cm_packets_received;
43236 target_stat_values[++index] = cm_packets_dropped;
43237 target_stat_values[++index] = cm_packets_retrans;
43238 - target_stat_values[++index] = atomic_read(&cm_listens_created);
43239 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43240 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43241 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43242 target_stat_values[++index] = cm_backlog_drops;
43243 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
43244 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
43245 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43246 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43247 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43248 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43249 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43250 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43251 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43252 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43253 target_stat_values[++index] = nesadapter->free_4kpbl;
43254 target_stat_values[++index] = nesadapter->free_256pbl;
43255 target_stat_values[++index] = int_mod_timer_init;
43256 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43257 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43258 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43259 - target_stat_values[++index] = atomic_read(&pau_qps_created);
43260 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43261 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43262 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43263 }
43264
43265 /**
43266 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43267 index eb62461..2b7fc71 100644
43268 --- a/drivers/infiniband/hw/nes/nes_verbs.c
43269 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
43270 @@ -46,9 +46,9 @@
43271
43272 #include <rdma/ib_umem.h>
43273
43274 -atomic_t mod_qp_timouts;
43275 -atomic_t qps_created;
43276 -atomic_t sw_qps_destroyed;
43277 +atomic_unchecked_t mod_qp_timouts;
43278 +atomic_unchecked_t qps_created;
43279 +atomic_unchecked_t sw_qps_destroyed;
43280
43281 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43282
43283 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43284 if (init_attr->create_flags)
43285 return ERR_PTR(-EINVAL);
43286
43287 - atomic_inc(&qps_created);
43288 + atomic_inc_unchecked(&qps_created);
43289 switch (init_attr->qp_type) {
43290 case IB_QPT_RC:
43291 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43292 @@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43293 struct iw_cm_event cm_event;
43294 int ret = 0;
43295
43296 - atomic_inc(&sw_qps_destroyed);
43297 + atomic_inc_unchecked(&sw_qps_destroyed);
43298 nesqp->destroyed = 1;
43299
43300 /* Blow away the connection if it exists. */
43301 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43302 index 1946101..09766d2 100644
43303 --- a/drivers/infiniband/hw/qib/qib.h
43304 +++ b/drivers/infiniband/hw/qib/qib.h
43305 @@ -52,6 +52,7 @@
43306 #include <linux/kref.h>
43307 #include <linux/sched.h>
43308 #include <linux/kthread.h>
43309 +#include <linux/slab.h>
43310
43311 #include "qib_common.h"
43312 #include "qib_verbs.h"
43313 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43314 index 24c41ba..102d71f 100644
43315 --- a/drivers/input/gameport/gameport.c
43316 +++ b/drivers/input/gameport/gameport.c
43317 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43318 */
43319 static void gameport_init_port(struct gameport *gameport)
43320 {
43321 - static atomic_t gameport_no = ATOMIC_INIT(0);
43322 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43323
43324 __module_get(THIS_MODULE);
43325
43326 mutex_init(&gameport->drv_mutex);
43327 device_initialize(&gameport->dev);
43328 dev_set_name(&gameport->dev, "gameport%lu",
43329 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
43330 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43331 gameport->dev.bus = &gameport_bus;
43332 gameport->dev.release = gameport_release_port;
43333 if (gameport->parent)
43334 diff --git a/drivers/input/input.c b/drivers/input/input.c
43335 index 1c4c0db..6f7abe3 100644
43336 --- a/drivers/input/input.c
43337 +++ b/drivers/input/input.c
43338 @@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
43339 */
43340 struct input_dev *input_allocate_device(void)
43341 {
43342 - static atomic_t input_no = ATOMIC_INIT(0);
43343 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43344 struct input_dev *dev;
43345
43346 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43347 @@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
43348 INIT_LIST_HEAD(&dev->node);
43349
43350 dev_set_name(&dev->dev, "input%ld",
43351 - (unsigned long) atomic_inc_return(&input_no) - 1);
43352 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43353
43354 __module_get(THIS_MODULE);
43355 }
43356 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43357 index 4a95b22..874c182 100644
43358 --- a/drivers/input/joystick/sidewinder.c
43359 +++ b/drivers/input/joystick/sidewinder.c
43360 @@ -30,6 +30,7 @@
43361 #include <linux/kernel.h>
43362 #include <linux/module.h>
43363 #include <linux/slab.h>
43364 +#include <linux/sched.h>
43365 #include <linux/input.h>
43366 #include <linux/gameport.h>
43367 #include <linux/jiffies.h>
43368 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43369 index 603fe0d..f63decc 100644
43370 --- a/drivers/input/joystick/xpad.c
43371 +++ b/drivers/input/joystick/xpad.c
43372 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43373
43374 static int xpad_led_probe(struct usb_xpad *xpad)
43375 {
43376 - static atomic_t led_seq = ATOMIC_INIT(0);
43377 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43378 long led_no;
43379 struct xpad_led *led;
43380 struct led_classdev *led_cdev;
43381 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43382 if (!led)
43383 return -ENOMEM;
43384
43385 - led_no = (long)atomic_inc_return(&led_seq) - 1;
43386 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43387
43388 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43389 led->xpad = xpad;
43390 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43391 index e204f26..8459f15 100644
43392 --- a/drivers/input/misc/ims-pcu.c
43393 +++ b/drivers/input/misc/ims-pcu.c
43394 @@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43395
43396 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43397 {
43398 - static atomic_t device_no = ATOMIC_INIT(0);
43399 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43400
43401 const struct ims_pcu_device_info *info;
43402 u8 device_id;
43403 @@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43404 }
43405
43406 /* Device appears to be operable, complete initialization */
43407 - pcu->device_no = atomic_inc_return(&device_no) - 1;
43408 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43409
43410 error = ims_pcu_setup_backlight(pcu);
43411 if (error)
43412 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43413 index 2f0b39d..7370f13 100644
43414 --- a/drivers/input/mouse/psmouse.h
43415 +++ b/drivers/input/mouse/psmouse.h
43416 @@ -116,7 +116,7 @@ struct psmouse_attribute {
43417 ssize_t (*set)(struct psmouse *psmouse, void *data,
43418 const char *buf, size_t count);
43419 bool protect;
43420 -};
43421 +} __do_const;
43422 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43423
43424 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43425 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43426 index b604564..3f14ae4 100644
43427 --- a/drivers/input/mousedev.c
43428 +++ b/drivers/input/mousedev.c
43429 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43430
43431 spin_unlock_irq(&client->packet_lock);
43432
43433 - if (copy_to_user(buffer, data, count))
43434 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
43435 return -EFAULT;
43436
43437 return count;
43438 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43439 index 8f4c4ab..5fc8a45 100644
43440 --- a/drivers/input/serio/serio.c
43441 +++ b/drivers/input/serio/serio.c
43442 @@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
43443 */
43444 static void serio_init_port(struct serio *serio)
43445 {
43446 - static atomic_t serio_no = ATOMIC_INIT(0);
43447 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43448
43449 __module_get(THIS_MODULE);
43450
43451 @@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
43452 mutex_init(&serio->drv_mutex);
43453 device_initialize(&serio->dev);
43454 dev_set_name(&serio->dev, "serio%ld",
43455 - (long)atomic_inc_return(&serio_no) - 1);
43456 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
43457 serio->dev.bus = &serio_bus;
43458 serio->dev.release = serio_release_port;
43459 serio->dev.groups = serio_device_attr_groups;
43460 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43461 index c9a02fe..0debc75 100644
43462 --- a/drivers/input/serio/serio_raw.c
43463 +++ b/drivers/input/serio/serio_raw.c
43464 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43465
43466 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43467 {
43468 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
43469 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43470 struct serio_raw *serio_raw;
43471 int err;
43472
43473 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43474 }
43475
43476 snprintf(serio_raw->name, sizeof(serio_raw->name),
43477 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43478 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43479 kref_init(&serio_raw->kref);
43480 INIT_LIST_HEAD(&serio_raw->client_list);
43481 init_waitqueue_head(&serio_raw->wait);
43482 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43483 index e5555fc..937986d 100644
43484 --- a/drivers/iommu/iommu.c
43485 +++ b/drivers/iommu/iommu.c
43486 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43487 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43488 {
43489 bus_register_notifier(bus, &iommu_bus_nb);
43490 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43491 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43492 }
43493
43494 /**
43495 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43496 index 228632c9..edfe331 100644
43497 --- a/drivers/iommu/irq_remapping.c
43498 +++ b/drivers/iommu/irq_remapping.c
43499 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43500 void panic_if_irq_remap(const char *msg)
43501 {
43502 if (irq_remapping_enabled)
43503 - panic(msg);
43504 + panic("%s", msg);
43505 }
43506
43507 static void ir_ack_apic_edge(struct irq_data *data)
43508 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43509
43510 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43511 {
43512 - chip->irq_print_chip = ir_print_prefix;
43513 - chip->irq_ack = ir_ack_apic_edge;
43514 - chip->irq_eoi = ir_ack_apic_level;
43515 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43516 + pax_open_kernel();
43517 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43518 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43519 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43520 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43521 + pax_close_kernel();
43522 }
43523
43524 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43525 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43526 index 341c601..e5f407e 100644
43527 --- a/drivers/irqchip/irq-gic.c
43528 +++ b/drivers/irqchip/irq-gic.c
43529 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43530 * Supported arch specific GIC irq extension.
43531 * Default make them NULL.
43532 */
43533 -struct irq_chip gic_arch_extn = {
43534 +irq_chip_no_const gic_arch_extn = {
43535 .irq_eoi = NULL,
43536 .irq_mask = NULL,
43537 .irq_unmask = NULL,
43538 @@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43539 chained_irq_exit(chip, desc);
43540 }
43541
43542 -static struct irq_chip gic_chip = {
43543 +static irq_chip_no_const gic_chip __read_only = {
43544 .name = "GIC",
43545 .irq_mask = gic_mask_irq,
43546 .irq_unmask = gic_unmask_irq,
43547 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43548 index 8777065..a4a9967 100644
43549 --- a/drivers/irqchip/irq-renesas-irqc.c
43550 +++ b/drivers/irqchip/irq-renesas-irqc.c
43551 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43552 struct irqc_priv *p;
43553 struct resource *io;
43554 struct resource *irq;
43555 - struct irq_chip *irq_chip;
43556 + irq_chip_no_const *irq_chip;
43557 const char *name = dev_name(&pdev->dev);
43558 int ret;
43559 int k;
43560 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43561 index ac6f72b..81150f2 100644
43562 --- a/drivers/isdn/capi/capi.c
43563 +++ b/drivers/isdn/capi/capi.c
43564 @@ -81,8 +81,8 @@ struct capiminor {
43565
43566 struct capi20_appl *ap;
43567 u32 ncci;
43568 - atomic_t datahandle;
43569 - atomic_t msgid;
43570 + atomic_unchecked_t datahandle;
43571 + atomic_unchecked_t msgid;
43572
43573 struct tty_port port;
43574 int ttyinstop;
43575 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43576 capimsg_setu16(s, 2, mp->ap->applid);
43577 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43578 capimsg_setu8 (s, 5, CAPI_RESP);
43579 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43580 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43581 capimsg_setu32(s, 8, mp->ncci);
43582 capimsg_setu16(s, 12, datahandle);
43583 }
43584 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43585 mp->outbytes -= len;
43586 spin_unlock_bh(&mp->outlock);
43587
43588 - datahandle = atomic_inc_return(&mp->datahandle);
43589 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43590 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43591 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43592 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43593 capimsg_setu16(skb->data, 2, mp->ap->applid);
43594 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43595 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43596 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43597 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43598 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43599 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43600 capimsg_setu16(skb->data, 16, len); /* Data length */
43601 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43602 index c44950d..10ac276 100644
43603 --- a/drivers/isdn/gigaset/bas-gigaset.c
43604 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43605 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43606
43607
43608 static const struct gigaset_ops gigops = {
43609 - gigaset_write_cmd,
43610 - gigaset_write_room,
43611 - gigaset_chars_in_buffer,
43612 - gigaset_brkchars,
43613 - gigaset_init_bchannel,
43614 - gigaset_close_bchannel,
43615 - gigaset_initbcshw,
43616 - gigaset_freebcshw,
43617 - gigaset_reinitbcshw,
43618 - gigaset_initcshw,
43619 - gigaset_freecshw,
43620 - gigaset_set_modem_ctrl,
43621 - gigaset_baud_rate,
43622 - gigaset_set_line_ctrl,
43623 - gigaset_isoc_send_skb,
43624 - gigaset_isoc_input,
43625 + .write_cmd = gigaset_write_cmd,
43626 + .write_room = gigaset_write_room,
43627 + .chars_in_buffer = gigaset_chars_in_buffer,
43628 + .brkchars = gigaset_brkchars,
43629 + .init_bchannel = gigaset_init_bchannel,
43630 + .close_bchannel = gigaset_close_bchannel,
43631 + .initbcshw = gigaset_initbcshw,
43632 + .freebcshw = gigaset_freebcshw,
43633 + .reinitbcshw = gigaset_reinitbcshw,
43634 + .initcshw = gigaset_initcshw,
43635 + .freecshw = gigaset_freecshw,
43636 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43637 + .baud_rate = gigaset_baud_rate,
43638 + .set_line_ctrl = gigaset_set_line_ctrl,
43639 + .send_skb = gigaset_isoc_send_skb,
43640 + .handle_input = gigaset_isoc_input,
43641 };
43642
43643 /* bas_gigaset_init
43644 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43645 index 600c79b..3752bab 100644
43646 --- a/drivers/isdn/gigaset/interface.c
43647 +++ b/drivers/isdn/gigaset/interface.c
43648 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43649 }
43650 tty->driver_data = cs;
43651
43652 - ++cs->port.count;
43653 + atomic_inc(&cs->port.count);
43654
43655 - if (cs->port.count == 1) {
43656 + if (atomic_read(&cs->port.count) == 1) {
43657 tty_port_tty_set(&cs->port, tty);
43658 cs->port.low_latency = 1;
43659 }
43660 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43661
43662 if (!cs->connected)
43663 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43664 - else if (!cs->port.count)
43665 + else if (!atomic_read(&cs->port.count))
43666 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43667 - else if (!--cs->port.count)
43668 + else if (!atomic_dec_return(&cs->port.count))
43669 tty_port_tty_set(&cs->port, NULL);
43670
43671 mutex_unlock(&cs->mutex);
43672 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43673 index 8c91fd5..14f13ce 100644
43674 --- a/drivers/isdn/gigaset/ser-gigaset.c
43675 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43676 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43677 }
43678
43679 static const struct gigaset_ops ops = {
43680 - gigaset_write_cmd,
43681 - gigaset_write_room,
43682 - gigaset_chars_in_buffer,
43683 - gigaset_brkchars,
43684 - gigaset_init_bchannel,
43685 - gigaset_close_bchannel,
43686 - gigaset_initbcshw,
43687 - gigaset_freebcshw,
43688 - gigaset_reinitbcshw,
43689 - gigaset_initcshw,
43690 - gigaset_freecshw,
43691 - gigaset_set_modem_ctrl,
43692 - gigaset_baud_rate,
43693 - gigaset_set_line_ctrl,
43694 - gigaset_m10x_send_skb, /* asyncdata.c */
43695 - gigaset_m10x_input, /* asyncdata.c */
43696 + .write_cmd = gigaset_write_cmd,
43697 + .write_room = gigaset_write_room,
43698 + .chars_in_buffer = gigaset_chars_in_buffer,
43699 + .brkchars = gigaset_brkchars,
43700 + .init_bchannel = gigaset_init_bchannel,
43701 + .close_bchannel = gigaset_close_bchannel,
43702 + .initbcshw = gigaset_initbcshw,
43703 + .freebcshw = gigaset_freebcshw,
43704 + .reinitbcshw = gigaset_reinitbcshw,
43705 + .initcshw = gigaset_initcshw,
43706 + .freecshw = gigaset_freecshw,
43707 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43708 + .baud_rate = gigaset_baud_rate,
43709 + .set_line_ctrl = gigaset_set_line_ctrl,
43710 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43711 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43712 };
43713
43714
43715 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43716 index d0a41cb..b953e50 100644
43717 --- a/drivers/isdn/gigaset/usb-gigaset.c
43718 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43719 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43720 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43721 memcpy(cs->hw.usb->bchars, buf, 6);
43722 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43723 - 0, 0, &buf, 6, 2000);
43724 + 0, 0, buf, 6, 2000);
43725 }
43726
43727 static void gigaset_freebcshw(struct bc_state *bcs)
43728 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43729 }
43730
43731 static const struct gigaset_ops ops = {
43732 - gigaset_write_cmd,
43733 - gigaset_write_room,
43734 - gigaset_chars_in_buffer,
43735 - gigaset_brkchars,
43736 - gigaset_init_bchannel,
43737 - gigaset_close_bchannel,
43738 - gigaset_initbcshw,
43739 - gigaset_freebcshw,
43740 - gigaset_reinitbcshw,
43741 - gigaset_initcshw,
43742 - gigaset_freecshw,
43743 - gigaset_set_modem_ctrl,
43744 - gigaset_baud_rate,
43745 - gigaset_set_line_ctrl,
43746 - gigaset_m10x_send_skb,
43747 - gigaset_m10x_input,
43748 + .write_cmd = gigaset_write_cmd,
43749 + .write_room = gigaset_write_room,
43750 + .chars_in_buffer = gigaset_chars_in_buffer,
43751 + .brkchars = gigaset_brkchars,
43752 + .init_bchannel = gigaset_init_bchannel,
43753 + .close_bchannel = gigaset_close_bchannel,
43754 + .initbcshw = gigaset_initbcshw,
43755 + .freebcshw = gigaset_freebcshw,
43756 + .reinitbcshw = gigaset_reinitbcshw,
43757 + .initcshw = gigaset_initcshw,
43758 + .freecshw = gigaset_freecshw,
43759 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43760 + .baud_rate = gigaset_baud_rate,
43761 + .set_line_ctrl = gigaset_set_line_ctrl,
43762 + .send_skb = gigaset_m10x_send_skb,
43763 + .handle_input = gigaset_m10x_input,
43764 };
43765
43766 /*
43767 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43768 index 4d9b195..455075c 100644
43769 --- a/drivers/isdn/hardware/avm/b1.c
43770 +++ b/drivers/isdn/hardware/avm/b1.c
43771 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43772 }
43773 if (left) {
43774 if (t4file->user) {
43775 - if (copy_from_user(buf, dp, left))
43776 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43777 return -EFAULT;
43778 } else {
43779 memcpy(buf, dp, left);
43780 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43781 }
43782 if (left) {
43783 if (config->user) {
43784 - if (copy_from_user(buf, dp, left))
43785 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43786 return -EFAULT;
43787 } else {
43788 memcpy(buf, dp, left);
43789 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43790 index 9bb12ba..d4262f7 100644
43791 --- a/drivers/isdn/i4l/isdn_common.c
43792 +++ b/drivers/isdn/i4l/isdn_common.c
43793 @@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43794 } else
43795 return -EINVAL;
43796 case IIOCDBGVAR:
43797 + if (!capable(CAP_SYS_RAWIO))
43798 + return -EPERM;
43799 if (arg) {
43800 if (copy_to_user(argp, &dev, sizeof(ulong)))
43801 return -EFAULT;
43802 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43803 index 91d5730..336523e 100644
43804 --- a/drivers/isdn/i4l/isdn_concap.c
43805 +++ b/drivers/isdn/i4l/isdn_concap.c
43806 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43807 }
43808
43809 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43810 - &isdn_concap_dl_data_req,
43811 - &isdn_concap_dl_connect_req,
43812 - &isdn_concap_dl_disconn_req
43813 + .data_req = &isdn_concap_dl_data_req,
43814 + .connect_req = &isdn_concap_dl_connect_req,
43815 + .disconn_req = &isdn_concap_dl_disconn_req
43816 };
43817
43818 /* The following should better go into a dedicated source file such that
43819 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43820 index 3c5f249..5fac4d0 100644
43821 --- a/drivers/isdn/i4l/isdn_tty.c
43822 +++ b/drivers/isdn/i4l/isdn_tty.c
43823 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43824
43825 #ifdef ISDN_DEBUG_MODEM_OPEN
43826 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43827 - port->count);
43828 + atomic_read(&port->count));
43829 #endif
43830 - port->count++;
43831 + atomic_inc(&port->count);
43832 port->tty = tty;
43833 /*
43834 * Start up serial port
43835 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43836 #endif
43837 return;
43838 }
43839 - if ((tty->count == 1) && (port->count != 1)) {
43840 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43841 /*
43842 * Uh, oh. tty->count is 1, which means that the tty
43843 * structure will be freed. Info->count should always
43844 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43845 * serial port won't be shutdown.
43846 */
43847 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43848 - "info->count is %d\n", port->count);
43849 - port->count = 1;
43850 + "info->count is %d\n", atomic_read(&port->count));
43851 + atomic_set(&port->count, 1);
43852 }
43853 - if (--port->count < 0) {
43854 + if (atomic_dec_return(&port->count) < 0) {
43855 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43856 - info->line, port->count);
43857 - port->count = 0;
43858 + info->line, atomic_read(&port->count));
43859 + atomic_set(&port->count, 0);
43860 }
43861 - if (port->count) {
43862 + if (atomic_read(&port->count)) {
43863 #ifdef ISDN_DEBUG_MODEM_OPEN
43864 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43865 #endif
43866 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43867 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43868 return;
43869 isdn_tty_shutdown(info);
43870 - port->count = 0;
43871 + atomic_set(&port->count, 0);
43872 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43873 port->tty = NULL;
43874 wake_up_interruptible(&port->open_wait);
43875 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43876 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43877 modem_info *info = &dev->mdm.info[i];
43878
43879 - if (info->port.count == 0)
43880 + if (atomic_read(&info->port.count) == 0)
43881 continue;
43882 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43883 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43884 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43885 index e2d4e58..40cd045 100644
43886 --- a/drivers/isdn/i4l/isdn_x25iface.c
43887 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43888 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43889
43890
43891 static struct concap_proto_ops ix25_pops = {
43892 - &isdn_x25iface_proto_new,
43893 - &isdn_x25iface_proto_del,
43894 - &isdn_x25iface_proto_restart,
43895 - &isdn_x25iface_proto_close,
43896 - &isdn_x25iface_xmit,
43897 - &isdn_x25iface_receive,
43898 - &isdn_x25iface_connect_ind,
43899 - &isdn_x25iface_disconn_ind
43900 + .proto_new = &isdn_x25iface_proto_new,
43901 + .proto_del = &isdn_x25iface_proto_del,
43902 + .restart = &isdn_x25iface_proto_restart,
43903 + .close = &isdn_x25iface_proto_close,
43904 + .encap_and_xmit = &isdn_x25iface_xmit,
43905 + .data_ind = &isdn_x25iface_receive,
43906 + .connect_ind = &isdn_x25iface_connect_ind,
43907 + .disconn_ind = &isdn_x25iface_disconn_ind
43908 };
43909
43910 /* error message helper function */
43911 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43912 index 53d487f..cae33fe 100644
43913 --- a/drivers/isdn/icn/icn.c
43914 +++ b/drivers/isdn/icn/icn.c
43915 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43916 if (count > len)
43917 count = len;
43918 if (user) {
43919 - if (copy_from_user(msg, buf, count))
43920 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43921 return -EFAULT;
43922 } else
43923 memcpy(msg, buf, count);
43924 @@ -1155,7 +1155,7 @@ icn_command(isdn_ctrl *c, icn_card *card)
43925 ulong a;
43926 ulong flags;
43927 int i;
43928 - char cbuf[60];
43929 + char cbuf[80];
43930 isdn_ctrl cmd;
43931 icn_cdef cdef;
43932 char __user *arg;
43933 @@ -1309,7 +1309,6 @@ icn_command(isdn_ctrl *c, icn_card *card)
43934 break;
43935 if ((c->arg & 255) < ICN_BCH) {
43936 char *p;
43937 - char dial[50];
43938 char dcode[4];
43939
43940 a = c->arg;
43941 @@ -1321,10 +1320,10 @@ icn_command(isdn_ctrl *c, icn_card *card)
43942 } else
43943 /* Normal Dial */
43944 strcpy(dcode, "CAL");
43945 - strcpy(dial, p);
43946 - sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43947 - dcode, dial, c->parm.setup.si1,
43948 - c->parm.setup.si2, c->parm.setup.eazmsn);
43949 + snprintf(cbuf, sizeof(cbuf),
43950 + "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43951 + dcode, p, c->parm.setup.si1,
43952 + c->parm.setup.si2, c->parm.setup.eazmsn);
43953 i = icn_writecmd(cbuf, strlen(cbuf), 0, card);
43954 }
43955 break;
43956 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43957 index a4f05c5..1433bc5 100644
43958 --- a/drivers/isdn/mISDN/dsp_cmx.c
43959 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43960 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43961 static u16 dsp_count; /* last sample count */
43962 static int dsp_count_valid; /* if we have last sample count */
43963
43964 -void
43965 +void __intentional_overflow(-1)
43966 dsp_cmx_send(void *arg)
43967 {
43968 struct dsp_conf *conf;
43969 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43970 index d93e245..e7ece6b 100644
43971 --- a/drivers/leds/leds-clevo-mail.c
43972 +++ b/drivers/leds/leds-clevo-mail.c
43973 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43974 * detected as working, but in reality it is not) as low as
43975 * possible.
43976 */
43977 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43978 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43979 {
43980 .callback = clevo_mail_led_dmi_callback,
43981 .ident = "Clevo D410J",
43982 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43983 index 5b8f938..b73d657 100644
43984 --- a/drivers/leds/leds-ss4200.c
43985 +++ b/drivers/leds/leds-ss4200.c
43986 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43987 * detected as working, but in reality it is not) as low as
43988 * possible.
43989 */
43990 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43991 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43992 {
43993 .callback = ss4200_led_dmi_callback,
43994 .ident = "Intel SS4200-E",
43995 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43996 index 0bf1e4e..b4bf44e 100644
43997 --- a/drivers/lguest/core.c
43998 +++ b/drivers/lguest/core.c
43999 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
44000 * The end address needs +1 because __get_vm_area allocates an
44001 * extra guard page, so we need space for that.
44002 */
44003 +
44004 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44005 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44006 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44007 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44008 +#else
44009 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44010 VM_ALLOC, switcher_addr, switcher_addr
44011 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44012 +#endif
44013 +
44014 if (!switcher_vma) {
44015 err = -ENOMEM;
44016 printk("lguest: could not map switcher pages high\n");
44017 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
44018 * Now the Switcher is mapped at the right address, we can't fail!
44019 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44020 */
44021 - memcpy(switcher_vma->addr, start_switcher_text,
44022 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44023 end_switcher_text - start_switcher_text);
44024
44025 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44026 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44027 index bfb39bb..08a603b 100644
44028 --- a/drivers/lguest/page_tables.c
44029 +++ b/drivers/lguest/page_tables.c
44030 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44031 /*:*/
44032
44033 #ifdef CONFIG_X86_PAE
44034 -static void release_pmd(pmd_t *spmd)
44035 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44036 {
44037 /* If the entry's not present, there's nothing to release. */
44038 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44039 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44040 index 922a1ac..9dd0c2a 100644
44041 --- a/drivers/lguest/x86/core.c
44042 +++ b/drivers/lguest/x86/core.c
44043 @@ -59,7 +59,7 @@ static struct {
44044 /* Offset from where switcher.S was compiled to where we've copied it */
44045 static unsigned long switcher_offset(void)
44046 {
44047 - return switcher_addr - (unsigned long)start_switcher_text;
44048 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44049 }
44050
44051 /* This cpu's struct lguest_pages (after the Switcher text page) */
44052 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44053 * These copies are pretty cheap, so we do them unconditionally: */
44054 /* Save the current Host top-level page directory.
44055 */
44056 +
44057 +#ifdef CONFIG_PAX_PER_CPU_PGD
44058 + pages->state.host_cr3 = read_cr3();
44059 +#else
44060 pages->state.host_cr3 = __pa(current->mm->pgd);
44061 +#endif
44062 +
44063 /*
44064 * Set up the Guest's page tables to see this CPU's pages (and no
44065 * other CPU's pages).
44066 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44067 * compiled-in switcher code and the high-mapped copy we just made.
44068 */
44069 for (i = 0; i < IDT_ENTRIES; i++)
44070 - default_idt_entries[i] += switcher_offset();
44071 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44072
44073 /*
44074 * Set up the Switcher's per-cpu areas.
44075 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44076 * it will be undisturbed when we switch. To change %cs and jump we
44077 * need this structure to feed to Intel's "lcall" instruction.
44078 */
44079 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44080 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44081 lguest_entry.segment = LGUEST_CS;
44082
44083 /*
44084 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44085 index 40634b0..4f5855e 100644
44086 --- a/drivers/lguest/x86/switcher_32.S
44087 +++ b/drivers/lguest/x86/switcher_32.S
44088 @@ -87,6 +87,7 @@
44089 #include <asm/page.h>
44090 #include <asm/segment.h>
44091 #include <asm/lguest.h>
44092 +#include <asm/processor-flags.h>
44093
44094 // We mark the start of the code to copy
44095 // It's placed in .text tho it's never run here
44096 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44097 // Changes type when we load it: damn Intel!
44098 // For after we switch over our page tables
44099 // That entry will be read-only: we'd crash.
44100 +
44101 +#ifdef CONFIG_PAX_KERNEXEC
44102 + mov %cr0, %edx
44103 + xor $X86_CR0_WP, %edx
44104 + mov %edx, %cr0
44105 +#endif
44106 +
44107 movl $(GDT_ENTRY_TSS*8), %edx
44108 ltr %dx
44109
44110 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44111 // Let's clear it again for our return.
44112 // The GDT descriptor of the Host
44113 // Points to the table after two "size" bytes
44114 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44115 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44116 // Clear "used" from type field (byte 5, bit 2)
44117 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44118 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44119 +
44120 +#ifdef CONFIG_PAX_KERNEXEC
44121 + mov %cr0, %eax
44122 + xor $X86_CR0_WP, %eax
44123 + mov %eax, %cr0
44124 +#endif
44125
44126 // Once our page table's switched, the Guest is live!
44127 // The Host fades as we run this final step.
44128 @@ -295,13 +309,12 @@ deliver_to_host:
44129 // I consulted gcc, and it gave
44130 // These instructions, which I gladly credit:
44131 leal (%edx,%ebx,8), %eax
44132 - movzwl (%eax),%edx
44133 - movl 4(%eax), %eax
44134 - xorw %ax, %ax
44135 - orl %eax, %edx
44136 + movl 4(%eax), %edx
44137 + movw (%eax), %dx
44138 // Now the address of the handler's in %edx
44139 // We call it now: its "iret" drops us home.
44140 - jmp *%edx
44141 + ljmp $__KERNEL_CS, $1f
44142 +1: jmp *%edx
44143
44144 // Every interrupt can come to us here
44145 // But we must truly tell each apart.
44146 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44147 index 7ef7461..5a09dac 100644
44148 --- a/drivers/md/bcache/closure.h
44149 +++ b/drivers/md/bcache/closure.h
44150 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44151 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44152 struct workqueue_struct *wq)
44153 {
44154 - BUG_ON(object_is_on_stack(cl));
44155 + BUG_ON(object_starts_on_stack(cl));
44156 closure_set_ip(cl);
44157 cl->fn = fn;
44158 cl->wq = wq;
44159 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44160 index 4195a01..42527ac 100644
44161 --- a/drivers/md/bitmap.c
44162 +++ b/drivers/md/bitmap.c
44163 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44164 chunk_kb ? "KB" : "B");
44165 if (bitmap->storage.file) {
44166 seq_printf(seq, ", file: ");
44167 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44168 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44169 }
44170
44171 seq_printf(seq, "\n");
44172 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44173 index 5152142..623d141 100644
44174 --- a/drivers/md/dm-ioctl.c
44175 +++ b/drivers/md/dm-ioctl.c
44176 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44177 cmd == DM_LIST_VERSIONS_CMD)
44178 return 0;
44179
44180 - if ((cmd == DM_DEV_CREATE_CMD)) {
44181 + if (cmd == DM_DEV_CREATE_CMD) {
44182 if (!*param->name) {
44183 DMWARN("name not supplied when creating device");
44184 return -EINVAL;
44185 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44186 index 7dfdb5c..4caada6 100644
44187 --- a/drivers/md/dm-raid1.c
44188 +++ b/drivers/md/dm-raid1.c
44189 @@ -40,7 +40,7 @@ enum dm_raid1_error {
44190
44191 struct mirror {
44192 struct mirror_set *ms;
44193 - atomic_t error_count;
44194 + atomic_unchecked_t error_count;
44195 unsigned long error_type;
44196 struct dm_dev *dev;
44197 sector_t offset;
44198 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44199 struct mirror *m;
44200
44201 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44202 - if (!atomic_read(&m->error_count))
44203 + if (!atomic_read_unchecked(&m->error_count))
44204 return m;
44205
44206 return NULL;
44207 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44208 * simple way to tell if a device has encountered
44209 * errors.
44210 */
44211 - atomic_inc(&m->error_count);
44212 + atomic_inc_unchecked(&m->error_count);
44213
44214 if (test_and_set_bit(error_type, &m->error_type))
44215 return;
44216 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44217 struct mirror *m = get_default_mirror(ms);
44218
44219 do {
44220 - if (likely(!atomic_read(&m->error_count)))
44221 + if (likely(!atomic_read_unchecked(&m->error_count)))
44222 return m;
44223
44224 if (m-- == ms->mirror)
44225 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44226 {
44227 struct mirror *default_mirror = get_default_mirror(m->ms);
44228
44229 - return !atomic_read(&default_mirror->error_count);
44230 + return !atomic_read_unchecked(&default_mirror->error_count);
44231 }
44232
44233 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44234 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44235 */
44236 if (likely(region_in_sync(ms, region, 1)))
44237 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44238 - else if (m && atomic_read(&m->error_count))
44239 + else if (m && atomic_read_unchecked(&m->error_count))
44240 m = NULL;
44241
44242 if (likely(m))
44243 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44244 }
44245
44246 ms->mirror[mirror].ms = ms;
44247 - atomic_set(&(ms->mirror[mirror].error_count), 0);
44248 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44249 ms->mirror[mirror].error_type = 0;
44250 ms->mirror[mirror].offset = offset;
44251
44252 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44253 */
44254 static char device_status_char(struct mirror *m)
44255 {
44256 - if (!atomic_read(&(m->error_count)))
44257 + if (!atomic_read_unchecked(&(m->error_count)))
44258 return 'A';
44259
44260 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44261 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44262 index 28a9012..9c0f6a5 100644
44263 --- a/drivers/md/dm-stats.c
44264 +++ b/drivers/md/dm-stats.c
44265 @@ -382,7 +382,7 @@ do_sync_free:
44266 synchronize_rcu_expedited();
44267 dm_stat_free(&s->rcu_head);
44268 } else {
44269 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44270 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44271 call_rcu(&s->rcu_head, dm_stat_free);
44272 }
44273 return 0;
44274 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44275 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44276 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44277 ));
44278 - ACCESS_ONCE(last->last_sector) = end_sector;
44279 - ACCESS_ONCE(last->last_rw) = bi_rw;
44280 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
44281 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44282 }
44283
44284 rcu_read_lock();
44285 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44286 index d1600d2..4c3af3a 100644
44287 --- a/drivers/md/dm-stripe.c
44288 +++ b/drivers/md/dm-stripe.c
44289 @@ -21,7 +21,7 @@ struct stripe {
44290 struct dm_dev *dev;
44291 sector_t physical_start;
44292
44293 - atomic_t error_count;
44294 + atomic_unchecked_t error_count;
44295 };
44296
44297 struct stripe_c {
44298 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44299 kfree(sc);
44300 return r;
44301 }
44302 - atomic_set(&(sc->stripe[i].error_count), 0);
44303 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44304 }
44305
44306 ti->private = sc;
44307 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44308 DMEMIT("%d ", sc->stripes);
44309 for (i = 0; i < sc->stripes; i++) {
44310 DMEMIT("%s ", sc->stripe[i].dev->name);
44311 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44312 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44313 'D' : 'A';
44314 }
44315 buffer[i] = '\0';
44316 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44317 */
44318 for (i = 0; i < sc->stripes; i++)
44319 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44320 - atomic_inc(&(sc->stripe[i].error_count));
44321 - if (atomic_read(&(sc->stripe[i].error_count)) <
44322 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
44323 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44324 DM_IO_ERROR_THRESHOLD)
44325 schedule_work(&sc->trigger_event);
44326 }
44327 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44328 index 6a7f2b8..fea0bde 100644
44329 --- a/drivers/md/dm-table.c
44330 +++ b/drivers/md/dm-table.c
44331 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
44332 static int open_dev(struct dm_dev_internal *d, dev_t dev,
44333 struct mapped_device *md)
44334 {
44335 - static char *_claim_ptr = "I belong to device-mapper";
44336 + static char _claim_ptr[] = "I belong to device-mapper";
44337 struct block_device *bdev;
44338
44339 int r;
44340 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44341 if (!dev_size)
44342 return 0;
44343
44344 - if ((start >= dev_size) || (start + len > dev_size)) {
44345 + if ((start >= dev_size) || (len > dev_size - start)) {
44346 DMWARN("%s: %s too small for target: "
44347 "start=%llu, len=%llu, dev_size=%llu",
44348 dm_device_name(ti->table->md), bdevname(bdev, b),
44349 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44350 index b086a94..74cb67e 100644
44351 --- a/drivers/md/dm-thin-metadata.c
44352 +++ b/drivers/md/dm-thin-metadata.c
44353 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44354 {
44355 pmd->info.tm = pmd->tm;
44356 pmd->info.levels = 2;
44357 - pmd->info.value_type.context = pmd->data_sm;
44358 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44359 pmd->info.value_type.size = sizeof(__le64);
44360 pmd->info.value_type.inc = data_block_inc;
44361 pmd->info.value_type.dec = data_block_dec;
44362 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44363
44364 pmd->bl_info.tm = pmd->tm;
44365 pmd->bl_info.levels = 1;
44366 - pmd->bl_info.value_type.context = pmd->data_sm;
44367 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44368 pmd->bl_info.value_type.size = sizeof(__le64);
44369 pmd->bl_info.value_type.inc = data_block_inc;
44370 pmd->bl_info.value_type.dec = data_block_dec;
44371 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44372 index 8c53b09..f1fb2b0 100644
44373 --- a/drivers/md/dm.c
44374 +++ b/drivers/md/dm.c
44375 @@ -185,9 +185,9 @@ struct mapped_device {
44376 /*
44377 * Event handling.
44378 */
44379 - atomic_t event_nr;
44380 + atomic_unchecked_t event_nr;
44381 wait_queue_head_t eventq;
44382 - atomic_t uevent_seq;
44383 + atomic_unchecked_t uevent_seq;
44384 struct list_head uevent_list;
44385 spinlock_t uevent_lock; /* Protect access to uevent_list */
44386
44387 @@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
44388 spin_lock_init(&md->deferred_lock);
44389 atomic_set(&md->holders, 1);
44390 atomic_set(&md->open_count, 0);
44391 - atomic_set(&md->event_nr, 0);
44392 - atomic_set(&md->uevent_seq, 0);
44393 + atomic_set_unchecked(&md->event_nr, 0);
44394 + atomic_set_unchecked(&md->uevent_seq, 0);
44395 INIT_LIST_HEAD(&md->uevent_list);
44396 spin_lock_init(&md->uevent_lock);
44397
44398 @@ -2043,7 +2043,7 @@ static void event_callback(void *context)
44399
44400 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44401
44402 - atomic_inc(&md->event_nr);
44403 + atomic_inc_unchecked(&md->event_nr);
44404 wake_up(&md->eventq);
44405 }
44406
44407 @@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44408
44409 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44410 {
44411 - return atomic_add_return(1, &md->uevent_seq);
44412 + return atomic_add_return_unchecked(1, &md->uevent_seq);
44413 }
44414
44415 uint32_t dm_get_event_nr(struct mapped_device *md)
44416 {
44417 - return atomic_read(&md->event_nr);
44418 + return atomic_read_unchecked(&md->event_nr);
44419 }
44420
44421 int dm_wait_event(struct mapped_device *md, int event_nr)
44422 {
44423 return wait_event_interruptible(md->eventq,
44424 - (event_nr != atomic_read(&md->event_nr)));
44425 + (event_nr != atomic_read_unchecked(&md->event_nr)));
44426 }
44427
44428 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44429 diff --git a/drivers/md/md.c b/drivers/md/md.c
44430 index 4ad5cc4..0f19664 100644
44431 --- a/drivers/md/md.c
44432 +++ b/drivers/md/md.c
44433 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44434 * start build, activate spare
44435 */
44436 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44437 -static atomic_t md_event_count;
44438 +static atomic_unchecked_t md_event_count;
44439 void md_new_event(struct mddev *mddev)
44440 {
44441 - atomic_inc(&md_event_count);
44442 + atomic_inc_unchecked(&md_event_count);
44443 wake_up(&md_event_waiters);
44444 }
44445 EXPORT_SYMBOL_GPL(md_new_event);
44446 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44447 */
44448 static void md_new_event_inintr(struct mddev *mddev)
44449 {
44450 - atomic_inc(&md_event_count);
44451 + atomic_inc_unchecked(&md_event_count);
44452 wake_up(&md_event_waiters);
44453 }
44454
44455 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44456 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44457 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44458 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44459 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44460 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44461
44462 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44463 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44464 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44465 else
44466 sb->resync_offset = cpu_to_le64(0);
44467
44468 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44469 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44470
44471 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44472 sb->size = cpu_to_le64(mddev->dev_sectors);
44473 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44474 static ssize_t
44475 errors_show(struct md_rdev *rdev, char *page)
44476 {
44477 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44478 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44479 }
44480
44481 static ssize_t
44482 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44483 char *e;
44484 unsigned long n = simple_strtoul(buf, &e, 10);
44485 if (*buf && (*e == 0 || *e == '\n')) {
44486 - atomic_set(&rdev->corrected_errors, n);
44487 + atomic_set_unchecked(&rdev->corrected_errors, n);
44488 return len;
44489 }
44490 return -EINVAL;
44491 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44492 rdev->sb_loaded = 0;
44493 rdev->bb_page = NULL;
44494 atomic_set(&rdev->nr_pending, 0);
44495 - atomic_set(&rdev->read_errors, 0);
44496 - atomic_set(&rdev->corrected_errors, 0);
44497 + atomic_set_unchecked(&rdev->read_errors, 0);
44498 + atomic_set_unchecked(&rdev->corrected_errors, 0);
44499
44500 INIT_LIST_HEAD(&rdev->same_set);
44501 init_waitqueue_head(&rdev->blocked_wait);
44502 @@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44503
44504 spin_unlock(&pers_lock);
44505 seq_printf(seq, "\n");
44506 - seq->poll_event = atomic_read(&md_event_count);
44507 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44508 return 0;
44509 }
44510 if (v == (void*)2) {
44511 @@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44512 return error;
44513
44514 seq = file->private_data;
44515 - seq->poll_event = atomic_read(&md_event_count);
44516 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44517 return error;
44518 }
44519
44520 @@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44521 /* always allow read */
44522 mask = POLLIN | POLLRDNORM;
44523
44524 - if (seq->poll_event != atomic_read(&md_event_count))
44525 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44526 mask |= POLLERR | POLLPRI;
44527 return mask;
44528 }
44529 @@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44530 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44531 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44532 (int)part_stat_read(&disk->part0, sectors[1]) -
44533 - atomic_read(&disk->sync_io);
44534 + atomic_read_unchecked(&disk->sync_io);
44535 /* sync IO will cause sync_io to increase before the disk_stats
44536 * as sync_io is counted when a request starts, and
44537 * disk_stats is counted when it completes.
44538 diff --git a/drivers/md/md.h b/drivers/md/md.h
44539 index 07bba96..2d6788c 100644
44540 --- a/drivers/md/md.h
44541 +++ b/drivers/md/md.h
44542 @@ -94,13 +94,13 @@ struct md_rdev {
44543 * only maintained for arrays that
44544 * support hot removal
44545 */
44546 - atomic_t read_errors; /* number of consecutive read errors that
44547 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44548 * we have tried to ignore.
44549 */
44550 struct timespec last_read_error; /* monotonic time since our
44551 * last read error
44552 */
44553 - atomic_t corrected_errors; /* number of corrected read errors,
44554 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44555 * for reporting to userspace and storing
44556 * in superblock.
44557 */
44558 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44559
44560 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44561 {
44562 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44563 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44564 }
44565
44566 struct md_personality
44567 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44568 index 786b689..ea8c956 100644
44569 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44570 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44571 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44572 * Flick into a mode where all blocks get allocated in the new area.
44573 */
44574 smm->begin = old_len;
44575 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44576 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44577
44578 /*
44579 * Extend.
44580 @@ -710,7 +710,7 @@ out:
44581 /*
44582 * Switch back to normal behaviour.
44583 */
44584 - memcpy(sm, &ops, sizeof(*sm));
44585 + memcpy((void *)sm, &ops, sizeof(*sm));
44586 return r;
44587 }
44588
44589 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44590 index 3e6d115..ffecdeb 100644
44591 --- a/drivers/md/persistent-data/dm-space-map.h
44592 +++ b/drivers/md/persistent-data/dm-space-map.h
44593 @@ -71,6 +71,7 @@ struct dm_space_map {
44594 dm_sm_threshold_fn fn,
44595 void *context);
44596 };
44597 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44598
44599 /*----------------------------------------------------------------*/
44600
44601 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44602 index 4a6ca1c..e952750 100644
44603 --- a/drivers/md/raid1.c
44604 +++ b/drivers/md/raid1.c
44605 @@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44606 if (r1_sync_page_io(rdev, sect, s,
44607 bio->bi_io_vec[idx].bv_page,
44608 READ) != 0)
44609 - atomic_add(s, &rdev->corrected_errors);
44610 + atomic_add_unchecked(s, &rdev->corrected_errors);
44611 }
44612 sectors -= s;
44613 sect += s;
44614 @@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44615 test_bit(In_sync, &rdev->flags)) {
44616 if (r1_sync_page_io(rdev, sect, s,
44617 conf->tmppage, READ)) {
44618 - atomic_add(s, &rdev->corrected_errors);
44619 + atomic_add_unchecked(s, &rdev->corrected_errors);
44620 printk(KERN_INFO
44621 "md/raid1:%s: read error corrected "
44622 "(%d sectors at %llu on %s)\n",
44623 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44624 index 33fc408..fc61709 100644
44625 --- a/drivers/md/raid10.c
44626 +++ b/drivers/md/raid10.c
44627 @@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
44628 /* The write handler will notice the lack of
44629 * R10BIO_Uptodate and record any errors etc
44630 */
44631 - atomic_add(r10_bio->sectors,
44632 + atomic_add_unchecked(r10_bio->sectors,
44633 &conf->mirrors[d].rdev->corrected_errors);
44634
44635 /* for reconstruct, we always reschedule after a read.
44636 @@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44637 {
44638 struct timespec cur_time_mon;
44639 unsigned long hours_since_last;
44640 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44641 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44642
44643 ktime_get_ts(&cur_time_mon);
44644
44645 @@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44646 * overflowing the shift of read_errors by hours_since_last.
44647 */
44648 if (hours_since_last >= 8 * sizeof(read_errors))
44649 - atomic_set(&rdev->read_errors, 0);
44650 + atomic_set_unchecked(&rdev->read_errors, 0);
44651 else
44652 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44653 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44654 }
44655
44656 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44657 @@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44658 return;
44659
44660 check_decay_read_errors(mddev, rdev);
44661 - atomic_inc(&rdev->read_errors);
44662 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44663 + atomic_inc_unchecked(&rdev->read_errors);
44664 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44665 char b[BDEVNAME_SIZE];
44666 bdevname(rdev->bdev, b);
44667
44668 @@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44669 "md/raid10:%s: %s: Raid device exceeded "
44670 "read_error threshold [cur %d:max %d]\n",
44671 mdname(mddev), b,
44672 - atomic_read(&rdev->read_errors), max_read_errors);
44673 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44674 printk(KERN_NOTICE
44675 "md/raid10:%s: %s: Failing raid device\n",
44676 mdname(mddev), b);
44677 @@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44678 sect +
44679 choose_data_offset(r10_bio, rdev)),
44680 bdevname(rdev->bdev, b));
44681 - atomic_add(s, &rdev->corrected_errors);
44682 + atomic_add_unchecked(s, &rdev->corrected_errors);
44683 }
44684
44685 rdev_dec_pending(rdev, mddev);
44686 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44687 index 16f5c21..4df20dc 100644
44688 --- a/drivers/md/raid5.c
44689 +++ b/drivers/md/raid5.c
44690 @@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44691 mdname(conf->mddev), STRIPE_SECTORS,
44692 (unsigned long long)s,
44693 bdevname(rdev->bdev, b));
44694 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44695 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44696 clear_bit(R5_ReadError, &sh->dev[i].flags);
44697 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44698 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44699 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44700
44701 - if (atomic_read(&rdev->read_errors))
44702 - atomic_set(&rdev->read_errors, 0);
44703 + if (atomic_read_unchecked(&rdev->read_errors))
44704 + atomic_set_unchecked(&rdev->read_errors, 0);
44705 } else {
44706 const char *bdn = bdevname(rdev->bdev, b);
44707 int retry = 0;
44708 int set_bad = 0;
44709
44710 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44711 - atomic_inc(&rdev->read_errors);
44712 + atomic_inc_unchecked(&rdev->read_errors);
44713 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44714 printk_ratelimited(
44715 KERN_WARNING
44716 @@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44717 mdname(conf->mddev),
44718 (unsigned long long)s,
44719 bdn);
44720 - } else if (atomic_read(&rdev->read_errors)
44721 + } else if (atomic_read_unchecked(&rdev->read_errors)
44722 > conf->max_nr_stripes)
44723 printk(KERN_WARNING
44724 "md/raid:%s: Too many read errors, failing device %s.\n",
44725 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44726 index 983db75..ef9248c 100644
44727 --- a/drivers/media/dvb-core/dvbdev.c
44728 +++ b/drivers/media/dvb-core/dvbdev.c
44729 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44730 const struct dvb_device *template, void *priv, int type)
44731 {
44732 struct dvb_device *dvbdev;
44733 - struct file_operations *dvbdevfops;
44734 + file_operations_no_const *dvbdevfops;
44735 struct device *clsdev;
44736 int minor;
44737 int id;
44738 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44739 index 9b6c3bb..baeb5c7 100644
44740 --- a/drivers/media/dvb-frontends/dib3000.h
44741 +++ b/drivers/media/dvb-frontends/dib3000.h
44742 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44743 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44744 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44745 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44746 -};
44747 +} __no_const;
44748
44749 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44750 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44751 diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
44752 index d5a7a13..703560f 100644
44753 --- a/drivers/media/media-device.c
44754 +++ b/drivers/media/media-device.c
44755 @@ -93,6 +93,7 @@ static long media_device_enum_entities(struct media_device *mdev,
44756 struct media_entity *ent;
44757 struct media_entity_desc u_ent;
44758
44759 + memset(&u_ent, 0, sizeof(u_ent));
44760 if (copy_from_user(&u_ent.id, &uent->id, sizeof(u_ent.id)))
44761 return -EFAULT;
44762
44763 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44764 index ed8cb90..5ef7f79 100644
44765 --- a/drivers/media/pci/cx88/cx88-video.c
44766 +++ b/drivers/media/pci/cx88/cx88-video.c
44767 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44768
44769 /* ------------------------------------------------------------------ */
44770
44771 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44772 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44773 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44774 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44775 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44776 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44777
44778 module_param_array(video_nr, int, NULL, 0444);
44779 module_param_array(vbi_nr, int, NULL, 0444);
44780 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44781 index 802642d..5534900 100644
44782 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44783 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44784 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44785 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44786
44787 /* ivtv instance counter */
44788 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44789 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44790
44791 /* Parameter declarations */
44792 static int cardtype[IVTV_MAX_CARDS];
44793 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44794 index dfd0a21..6bbb465 100644
44795 --- a/drivers/media/platform/omap/omap_vout.c
44796 +++ b/drivers/media/platform/omap/omap_vout.c
44797 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44798 OMAP_VIDEO2,
44799 };
44800
44801 -static struct videobuf_queue_ops video_vbq_ops;
44802 /* Variables configurable through module params*/
44803 static u32 video1_numbuffers = 3;
44804 static u32 video2_numbuffers = 3;
44805 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44806 {
44807 struct videobuf_queue *q;
44808 struct omap_vout_device *vout = NULL;
44809 + static struct videobuf_queue_ops video_vbq_ops = {
44810 + .buf_setup = omap_vout_buffer_setup,
44811 + .buf_prepare = omap_vout_buffer_prepare,
44812 + .buf_release = omap_vout_buffer_release,
44813 + .buf_queue = omap_vout_buffer_queue,
44814 + };
44815
44816 vout = video_drvdata(file);
44817 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44818 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44819 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44820
44821 q = &vout->vbq;
44822 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44823 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44824 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44825 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44826 spin_lock_init(&vout->vbq_lock);
44827
44828 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44829 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44830 index fb2acc5..a2fcbdc4 100644
44831 --- a/drivers/media/platform/s5p-tv/mixer.h
44832 +++ b/drivers/media/platform/s5p-tv/mixer.h
44833 @@ -156,7 +156,7 @@ struct mxr_layer {
44834 /** layer index (unique identifier) */
44835 int idx;
44836 /** callbacks for layer methods */
44837 - struct mxr_layer_ops ops;
44838 + struct mxr_layer_ops *ops;
44839 /** format array */
44840 const struct mxr_format **fmt_array;
44841 /** size of format array */
44842 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44843 index 74344c7..a39e70e 100644
44844 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44845 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44846 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44847 {
44848 struct mxr_layer *layer;
44849 int ret;
44850 - struct mxr_layer_ops ops = {
44851 + static struct mxr_layer_ops ops = {
44852 .release = mxr_graph_layer_release,
44853 .buffer_set = mxr_graph_buffer_set,
44854 .stream_set = mxr_graph_stream_set,
44855 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44856 index b713403..53cb5ad 100644
44857 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44858 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44859 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44860 layer->update_buf = next;
44861 }
44862
44863 - layer->ops.buffer_set(layer, layer->update_buf);
44864 + layer->ops->buffer_set(layer, layer->update_buf);
44865
44866 if (done && done != layer->shadow_buf)
44867 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44868 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44869 index c5059ba..2649f28 100644
44870 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44871 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44872 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44873 layer->geo.src.height = layer->geo.src.full_height;
44874
44875 mxr_geometry_dump(mdev, &layer->geo);
44876 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44877 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44878 mxr_geometry_dump(mdev, &layer->geo);
44879 }
44880
44881 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44882 layer->geo.dst.full_width = mbus_fmt.width;
44883 layer->geo.dst.full_height = mbus_fmt.height;
44884 layer->geo.dst.field = mbus_fmt.field;
44885 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44886 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44887
44888 mxr_geometry_dump(mdev, &layer->geo);
44889 }
44890 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44891 /* set source size to highest accepted value */
44892 geo->src.full_width = max(geo->dst.full_width, pix->width);
44893 geo->src.full_height = max(geo->dst.full_height, pix->height);
44894 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44895 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44896 mxr_geometry_dump(mdev, &layer->geo);
44897 /* set cropping to total visible screen */
44898 geo->src.width = pix->width;
44899 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44900 geo->src.x_offset = 0;
44901 geo->src.y_offset = 0;
44902 /* assure consistency of geometry */
44903 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44904 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44905 mxr_geometry_dump(mdev, &layer->geo);
44906 /* set full size to lowest possible value */
44907 geo->src.full_width = 0;
44908 geo->src.full_height = 0;
44909 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44910 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44911 mxr_geometry_dump(mdev, &layer->geo);
44912
44913 /* returning results */
44914 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44915 target->width = s->r.width;
44916 target->height = s->r.height;
44917
44918 - layer->ops.fix_geometry(layer, stage, s->flags);
44919 + layer->ops->fix_geometry(layer, stage, s->flags);
44920
44921 /* retrieve update selection rectangle */
44922 res.left = target->x_offset;
44923 @@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44924 mxr_output_get(mdev);
44925
44926 mxr_layer_update_output(layer);
44927 - layer->ops.format_set(layer);
44928 + layer->ops->format_set(layer);
44929 /* enabling layer in hardware */
44930 spin_lock_irqsave(&layer->enq_slock, flags);
44931 layer->state = MXR_LAYER_STREAMING;
44932 spin_unlock_irqrestore(&layer->enq_slock, flags);
44933
44934 - layer->ops.stream_set(layer, MXR_ENABLE);
44935 + layer->ops->stream_set(layer, MXR_ENABLE);
44936 mxr_streamer_get(mdev);
44937
44938 return 0;
44939 @@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44940 spin_unlock_irqrestore(&layer->enq_slock, flags);
44941
44942 /* disabling layer in hardware */
44943 - layer->ops.stream_set(layer, MXR_DISABLE);
44944 + layer->ops->stream_set(layer, MXR_DISABLE);
44945 /* remove one streamer */
44946 mxr_streamer_put(mdev);
44947 /* allow changes in output configuration */
44948 @@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44949
44950 void mxr_layer_release(struct mxr_layer *layer)
44951 {
44952 - if (layer->ops.release)
44953 - layer->ops.release(layer);
44954 + if (layer->ops->release)
44955 + layer->ops->release(layer);
44956 }
44957
44958 void mxr_base_layer_release(struct mxr_layer *layer)
44959 @@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44960
44961 layer->mdev = mdev;
44962 layer->idx = idx;
44963 - layer->ops = *ops;
44964 + layer->ops = ops;
44965
44966 spin_lock_init(&layer->enq_slock);
44967 INIT_LIST_HEAD(&layer->enq_list);
44968 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44969 index c9388c4..ce71ece 100644
44970 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44971 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44972 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44973 {
44974 struct mxr_layer *layer;
44975 int ret;
44976 - struct mxr_layer_ops ops = {
44977 + static struct mxr_layer_ops ops = {
44978 .release = mxr_vp_layer_release,
44979 .buffer_set = mxr_vp_buffer_set,
44980 .stream_set = mxr_vp_stream_set,
44981 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44982 index 2d4e73b..8b4d5b6 100644
44983 --- a/drivers/media/platform/vivi.c
44984 +++ b/drivers/media/platform/vivi.c
44985 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44986 MODULE_LICENSE("Dual BSD/GPL");
44987 MODULE_VERSION(VIVI_VERSION);
44988
44989 -static unsigned video_nr = -1;
44990 -module_param(video_nr, uint, 0644);
44991 +static int video_nr = -1;
44992 +module_param(video_nr, int, 0644);
44993 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44994
44995 static unsigned n_devs = 1;
44996 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44997 index 545c04c..a14bded 100644
44998 --- a/drivers/media/radio/radio-cadet.c
44999 +++ b/drivers/media/radio/radio-cadet.c
45000 @@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45001 unsigned char readbuf[RDS_BUFFER];
45002 int i = 0;
45003
45004 + if (count > RDS_BUFFER)
45005 + return -EFAULT;
45006 mutex_lock(&dev->lock);
45007 if (dev->rdsstat == 0)
45008 cadet_start_rds(dev);
45009 @@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45010 while (i < count && dev->rdsin != dev->rdsout)
45011 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45012
45013 - if (i && copy_to_user(data, readbuf, i))
45014 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
45015 i = -EFAULT;
45016 unlock:
45017 mutex_unlock(&dev->lock);
45018 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45019 index 5236035..c622c74 100644
45020 --- a/drivers/media/radio/radio-maxiradio.c
45021 +++ b/drivers/media/radio/radio-maxiradio.c
45022 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45023 /* TEA5757 pin mappings */
45024 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45025
45026 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45027 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45028
45029 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45030 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45031 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45032 index 050b3bb..79f62b9 100644
45033 --- a/drivers/media/radio/radio-shark.c
45034 +++ b/drivers/media/radio/radio-shark.c
45035 @@ -79,7 +79,7 @@ struct shark_device {
45036 u32 last_val;
45037 };
45038
45039 -static atomic_t shark_instance = ATOMIC_INIT(0);
45040 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45041
45042 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45043 {
45044 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45045 index 8654e0d..0608a64 100644
45046 --- a/drivers/media/radio/radio-shark2.c
45047 +++ b/drivers/media/radio/radio-shark2.c
45048 @@ -74,7 +74,7 @@ struct shark_device {
45049 u8 *transfer_buffer;
45050 };
45051
45052 -static atomic_t shark_instance = ATOMIC_INIT(0);
45053 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45054
45055 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45056 {
45057 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45058 index 2fd9009..278cc1e 100644
45059 --- a/drivers/media/radio/radio-si476x.c
45060 +++ b/drivers/media/radio/radio-si476x.c
45061 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45062 struct si476x_radio *radio;
45063 struct v4l2_ctrl *ctrl;
45064
45065 - static atomic_t instance = ATOMIC_INIT(0);
45066 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
45067
45068 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45069 if (!radio)
45070 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
45071 index a1c641e..3007da9 100644
45072 --- a/drivers/media/usb/dvb-usb/cxusb.c
45073 +++ b/drivers/media/usb/dvb-usb/cxusb.c
45074 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
45075
45076 struct dib0700_adapter_state {
45077 int (*set_param_save) (struct dvb_frontend *);
45078 -};
45079 +} __no_const;
45080
45081 static int dib7070_set_param_override(struct dvb_frontend *fe)
45082 {
45083 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45084 index ae0f56a..ec71784 100644
45085 --- a/drivers/media/usb/dvb-usb/dw2102.c
45086 +++ b/drivers/media/usb/dvb-usb/dw2102.c
45087 @@ -118,7 +118,7 @@ struct su3000_state {
45088
45089 struct s6x0_state {
45090 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45091 -};
45092 +} __no_const;
45093
45094 /* debug */
45095 static int dvb_usb_dw2102_debug;
45096 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45097 index b63a5e5..b16a062 100644
45098 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45099 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45100 @@ -326,7 +326,7 @@ struct v4l2_buffer32 {
45101 __u32 reserved;
45102 };
45103
45104 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45105 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45106 enum v4l2_memory memory)
45107 {
45108 void __user *up_pln;
45109 @@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45110 return 0;
45111 }
45112
45113 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45114 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45115 enum v4l2_memory memory)
45116 {
45117 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
45118 @@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45119 * by passing a very big num_planes value */
45120 uplane = compat_alloc_user_space(num_planes *
45121 sizeof(struct v4l2_plane));
45122 - kp->m.planes = uplane;
45123 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
45124
45125 while (--num_planes >= 0) {
45126 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
45127 @@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45128 if (num_planes == 0)
45129 return 0;
45130
45131 - uplane = kp->m.planes;
45132 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
45133 if (get_user(p, &up->m.planes))
45134 return -EFAULT;
45135 uplane32 = compat_ptr(p);
45136 @@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
45137 get_user(kp->capability, &up->capability) ||
45138 get_user(kp->flags, &up->flags))
45139 return -EFAULT;
45140 - kp->base = compat_ptr(tmp);
45141 + kp->base = (void __force_kernel *)compat_ptr(tmp);
45142 get_v4l2_pix_format(&kp->fmt, &up->fmt);
45143 return 0;
45144 }
45145 @@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45146 n * sizeof(struct v4l2_ext_control32)))
45147 return -EFAULT;
45148 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
45149 - kp->controls = kcontrols;
45150 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
45151 while (--n >= 0) {
45152 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
45153 return -EFAULT;
45154 @@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45155 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
45156 {
45157 struct v4l2_ext_control32 __user *ucontrols;
45158 - struct v4l2_ext_control __user *kcontrols = kp->controls;
45159 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
45160 int n = kp->count;
45161 compat_caddr_t p;
45162
45163 @@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
45164 put_user(kp->start_block, &up->start_block) ||
45165 put_user(kp->blocks, &up->blocks) ||
45166 put_user(tmp, &up->edid) ||
45167 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
45168 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
45169 return -EFAULT;
45170 return 0;
45171 }
45172 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
45173 index 6ff002b..6b9316b 100644
45174 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
45175 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
45176 @@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
45177 return 0;
45178
45179 case V4L2_CTRL_TYPE_STRING:
45180 - len = strlen(c->string);
45181 - if (len < ctrl->minimum)
45182 + len = strlen_user(c->string);
45183 + if (!len || len < ctrl->minimum)
45184 return -ERANGE;
45185 if ((len - ctrl->minimum) % ctrl->step)
45186 return -ERANGE;
45187 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
45188 index 02d1b63..5fd6b16 100644
45189 --- a/drivers/media/v4l2-core/v4l2-device.c
45190 +++ b/drivers/media/v4l2-core/v4l2-device.c
45191 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
45192 EXPORT_SYMBOL_GPL(v4l2_device_put);
45193
45194 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
45195 - atomic_t *instance)
45196 + atomic_unchecked_t *instance)
45197 {
45198 - int num = atomic_inc_return(instance) - 1;
45199 + int num = atomic_inc_return_unchecked(instance) - 1;
45200 int len = strlen(basename);
45201
45202 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
45203 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
45204 index 707aef7..93b8ac0 100644
45205 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
45206 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
45207 @@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
45208 struct file *file, void *fh, void *p);
45209 } u;
45210 void (*debug)(const void *arg, bool write_only);
45211 -};
45212 +} __do_const;
45213 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
45214
45215 /* This control needs a priority check */
45216 #define INFO_FL_PRIO (1 << 0)
45217 @@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
45218 struct video_device *vfd = video_devdata(file);
45219 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
45220 bool write_only = false;
45221 - struct v4l2_ioctl_info default_info;
45222 + v4l2_ioctl_info_no_const default_info;
45223 const struct v4l2_ioctl_info *info;
45224 void *fh = file->private_data;
45225 struct v4l2_fh *vfh = NULL;
45226 @@ -2197,7 +2198,7 @@ done:
45227 }
45228
45229 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45230 - void * __user *user_ptr, void ***kernel_ptr)
45231 + void __user **user_ptr, void ***kernel_ptr)
45232 {
45233 int ret = 0;
45234
45235 @@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45236 ret = -EINVAL;
45237 break;
45238 }
45239 - *user_ptr = (void __user *)buf->m.planes;
45240 + *user_ptr = (void __force_user *)buf->m.planes;
45241 *kernel_ptr = (void *)&buf->m.planes;
45242 *array_size = sizeof(struct v4l2_plane) * buf->length;
45243 ret = 1;
45244 @@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45245 ret = -EINVAL;
45246 break;
45247 }
45248 - *user_ptr = (void __user *)ctrls->controls;
45249 + *user_ptr = (void __force_user *)ctrls->controls;
45250 *kernel_ptr = (void *)&ctrls->controls;
45251 *array_size = sizeof(struct v4l2_ext_control)
45252 * ctrls->count;
45253 @@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
45254 }
45255
45256 if (has_array_args) {
45257 - *kernel_ptr = user_ptr;
45258 + *kernel_ptr = (void __force_kernel *)user_ptr;
45259 if (copy_to_user(user_ptr, mbuf, array_size))
45260 err = -EFAULT;
45261 goto out_array_args;
45262 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
45263 index 570b18a..f880314 100644
45264 --- a/drivers/message/fusion/mptbase.c
45265 +++ b/drivers/message/fusion/mptbase.c
45266 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45267 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
45268 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
45269
45270 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45271 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
45272 +#else
45273 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
45274 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
45275 +#endif
45276 +
45277 /*
45278 * Rounding UP to nearest 4-kB boundary here...
45279 */
45280 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45281 ioc->facts.GlobalCredits);
45282
45283 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
45284 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45285 + NULL, NULL);
45286 +#else
45287 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
45288 +#endif
45289 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
45290 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
45291 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
45292 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
45293 index 00d339c..2ea899d 100644
45294 --- a/drivers/message/fusion/mptsas.c
45295 +++ b/drivers/message/fusion/mptsas.c
45296 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
45297 return 0;
45298 }
45299
45300 +static inline void
45301 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45302 +{
45303 + if (phy_info->port_details) {
45304 + phy_info->port_details->rphy = rphy;
45305 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45306 + ioc->name, rphy));
45307 + }
45308 +
45309 + if (rphy) {
45310 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45311 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45312 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45313 + ioc->name, rphy, rphy->dev.release));
45314 + }
45315 +}
45316 +
45317 /* no mutex */
45318 static void
45319 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
45320 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
45321 return NULL;
45322 }
45323
45324 -static inline void
45325 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45326 -{
45327 - if (phy_info->port_details) {
45328 - phy_info->port_details->rphy = rphy;
45329 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45330 - ioc->name, rphy));
45331 - }
45332 -
45333 - if (rphy) {
45334 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45335 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45336 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45337 - ioc->name, rphy, rphy->dev.release));
45338 - }
45339 -}
45340 -
45341 static inline struct sas_port *
45342 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45343 {
45344 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45345 index 727819c..ad74694 100644
45346 --- a/drivers/message/fusion/mptscsih.c
45347 +++ b/drivers/message/fusion/mptscsih.c
45348 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45349
45350 h = shost_priv(SChost);
45351
45352 - if (h) {
45353 - if (h->info_kbuf == NULL)
45354 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45355 - return h->info_kbuf;
45356 - h->info_kbuf[0] = '\0';
45357 + if (!h)
45358 + return NULL;
45359
45360 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45361 - h->info_kbuf[size-1] = '\0';
45362 - }
45363 + if (h->info_kbuf == NULL)
45364 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45365 + return h->info_kbuf;
45366 + h->info_kbuf[0] = '\0';
45367 +
45368 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45369 + h->info_kbuf[size-1] = '\0';
45370
45371 return h->info_kbuf;
45372 }
45373 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45374 index b7d87cd..3fb36da 100644
45375 --- a/drivers/message/i2o/i2o_proc.c
45376 +++ b/drivers/message/i2o/i2o_proc.c
45377 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45378 "Array Controller Device"
45379 };
45380
45381 -static char *chtostr(char *tmp, u8 *chars, int n)
45382 -{
45383 - tmp[0] = 0;
45384 - return strncat(tmp, (char *)chars, n);
45385 -}
45386 -
45387 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45388 char *group)
45389 {
45390 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45391 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45392 {
45393 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45394 - static u32 work32[5];
45395 - static u8 *work8 = (u8 *) work32;
45396 - static u16 *work16 = (u16 *) work32;
45397 + u32 work32[5];
45398 + u8 *work8 = (u8 *) work32;
45399 + u16 *work16 = (u16 *) work32;
45400 int token;
45401 u32 hwcap;
45402
45403 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45404 } *result;
45405
45406 i2o_exec_execute_ddm_table ddm_table;
45407 - char tmp[28 + 1];
45408
45409 result = kmalloc(sizeof(*result), GFP_KERNEL);
45410 if (!result)
45411 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45412
45413 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45414 seq_printf(seq, "%-#8x", ddm_table.module_id);
45415 - seq_printf(seq, "%-29s",
45416 - chtostr(tmp, ddm_table.module_name_version, 28));
45417 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45418 seq_printf(seq, "%9d ", ddm_table.data_size);
45419 seq_printf(seq, "%8d", ddm_table.code_size);
45420
45421 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45422
45423 i2o_driver_result_table *result;
45424 i2o_driver_store_table *dst;
45425 - char tmp[28 + 1];
45426
45427 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45428 if (result == NULL)
45429 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45430
45431 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45432 seq_printf(seq, "%-#8x", dst->module_id);
45433 - seq_printf(seq, "%-29s",
45434 - chtostr(tmp, dst->module_name_version, 28));
45435 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45436 + seq_printf(seq, "%-.28s", dst->module_name_version);
45437 + seq_printf(seq, "%-.8s", dst->date);
45438 seq_printf(seq, "%8d ", dst->module_size);
45439 seq_printf(seq, "%8d ", dst->mpb_size);
45440 seq_printf(seq, "0x%04x", dst->module_flags);
45441 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45442 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45443 {
45444 struct i2o_device *d = (struct i2o_device *)seq->private;
45445 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45446 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45447 // == (allow) 512d bytes (max)
45448 - static u16 *work16 = (u16 *) work32;
45449 + u16 *work16 = (u16 *) work32;
45450 int token;
45451 - char tmp[16 + 1];
45452
45453 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45454
45455 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45456 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45457 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45458 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45459 - seq_printf(seq, "Vendor info : %s\n",
45460 - chtostr(tmp, (u8 *) (work32 + 2), 16));
45461 - seq_printf(seq, "Product info : %s\n",
45462 - chtostr(tmp, (u8 *) (work32 + 6), 16));
45463 - seq_printf(seq, "Description : %s\n",
45464 - chtostr(tmp, (u8 *) (work32 + 10), 16));
45465 - seq_printf(seq, "Product rev. : %s\n",
45466 - chtostr(tmp, (u8 *) (work32 + 14), 8));
45467 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45468 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45469 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45470 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45471
45472 seq_printf(seq, "Serial number : ");
45473 print_serial_number(seq, (u8 *) (work32 + 16),
45474 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45475 u8 pad[256]; // allow up to 256 byte (max) serial number
45476 } result;
45477
45478 - char tmp[24 + 1];
45479 -
45480 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45481
45482 if (token < 0) {
45483 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45484 }
45485
45486 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45487 - seq_printf(seq, "Module name : %s\n",
45488 - chtostr(tmp, result.module_name, 24));
45489 - seq_printf(seq, "Module revision : %s\n",
45490 - chtostr(tmp, result.module_rev, 8));
45491 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
45492 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45493
45494 seq_printf(seq, "Serial number : ");
45495 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45496 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45497 u8 instance_number[4];
45498 } result;
45499
45500 - char tmp[64 + 1];
45501 -
45502 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45503
45504 if (token < 0) {
45505 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45506 return 0;
45507 }
45508
45509 - seq_printf(seq, "Device name : %s\n",
45510 - chtostr(tmp, result.device_name, 64));
45511 - seq_printf(seq, "Service name : %s\n",
45512 - chtostr(tmp, result.service_name, 64));
45513 - seq_printf(seq, "Physical name : %s\n",
45514 - chtostr(tmp, result.physical_location, 64));
45515 - seq_printf(seq, "Instance number : %s\n",
45516 - chtostr(tmp, result.instance_number, 4));
45517 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
45518 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
45519 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45520 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45521
45522 return 0;
45523 }
45524 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45525 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45526 {
45527 struct i2o_device *d = (struct i2o_device *)seq->private;
45528 - static u32 work32[12];
45529 - static u16 *work16 = (u16 *) work32;
45530 - static u8 *work8 = (u8 *) work32;
45531 + u32 work32[12];
45532 + u16 *work16 = (u16 *) work32;
45533 + u8 *work8 = (u8 *) work32;
45534 int token;
45535
45536 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45537 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45538 index a8c08f3..155fe3d 100644
45539 --- a/drivers/message/i2o/iop.c
45540 +++ b/drivers/message/i2o/iop.c
45541 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45542
45543 spin_lock_irqsave(&c->context_list_lock, flags);
45544
45545 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45546 - atomic_inc(&c->context_list_counter);
45547 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45548 + atomic_inc_unchecked(&c->context_list_counter);
45549
45550 - entry->context = atomic_read(&c->context_list_counter);
45551 + entry->context = atomic_read_unchecked(&c->context_list_counter);
45552
45553 list_add(&entry->list, &c->context_list);
45554
45555 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45556
45557 #if BITS_PER_LONG == 64
45558 spin_lock_init(&c->context_list_lock);
45559 - atomic_set(&c->context_list_counter, 0);
45560 + atomic_set_unchecked(&c->context_list_counter, 0);
45561 INIT_LIST_HEAD(&c->context_list);
45562 #endif
45563
45564 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45565 index d1a22aa..d0f7bf7 100644
45566 --- a/drivers/mfd/ab8500-debugfs.c
45567 +++ b/drivers/mfd/ab8500-debugfs.c
45568 @@ -100,7 +100,7 @@ static int irq_last;
45569 static u32 *irq_count;
45570 static int num_irqs;
45571
45572 -static struct device_attribute **dev_attr;
45573 +static device_attribute_no_const **dev_attr;
45574 static char **event_name;
45575
45576 static u8 avg_sample = SAMPLE_16;
45577 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45578 index 81b7d88..95ae998 100644
45579 --- a/drivers/mfd/janz-cmodio.c
45580 +++ b/drivers/mfd/janz-cmodio.c
45581 @@ -13,6 +13,7 @@
45582
45583 #include <linux/kernel.h>
45584 #include <linux/module.h>
45585 +#include <linux/slab.h>
45586 #include <linux/init.h>
45587 #include <linux/pci.h>
45588 #include <linux/interrupt.h>
45589 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45590 index a83eed5..62a58a9 100644
45591 --- a/drivers/mfd/max8925-i2c.c
45592 +++ b/drivers/mfd/max8925-i2c.c
45593 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45594 const struct i2c_device_id *id)
45595 {
45596 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45597 - static struct max8925_chip *chip;
45598 + struct max8925_chip *chip;
45599 struct device_node *node = client->dev.of_node;
45600
45601 if (node && !pdata) {
45602 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45603 index d657331..0d9a80f 100644
45604 --- a/drivers/mfd/tps65910.c
45605 +++ b/drivers/mfd/tps65910.c
45606 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45607 struct tps65910_platform_data *pdata)
45608 {
45609 int ret = 0;
45610 - static struct regmap_irq_chip *tps6591x_irqs_chip;
45611 + struct regmap_irq_chip *tps6591x_irqs_chip;
45612
45613 if (!irq) {
45614 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45615 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45616 index 9aa6d1e..1631bfc 100644
45617 --- a/drivers/mfd/twl4030-irq.c
45618 +++ b/drivers/mfd/twl4030-irq.c
45619 @@ -35,6 +35,7 @@
45620 #include <linux/of.h>
45621 #include <linux/irqdomain.h>
45622 #include <linux/i2c/twl.h>
45623 +#include <asm/pgtable.h>
45624
45625 #include "twl-core.h"
45626
45627 @@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45628 * Install an irq handler for each of the SIH modules;
45629 * clone dummy irq_chip since PIH can't *do* anything
45630 */
45631 - twl4030_irq_chip = dummy_irq_chip;
45632 - twl4030_irq_chip.name = "twl4030";
45633 + pax_open_kernel();
45634 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45635 + *(const char **)&twl4030_irq_chip.name = "twl4030";
45636
45637 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45638 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45639 + pax_close_kernel();
45640
45641 for (i = irq_base; i < irq_end; i++) {
45642 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45643 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45644 index 464419b..64bae8d 100644
45645 --- a/drivers/misc/c2port/core.c
45646 +++ b/drivers/misc/c2port/core.c
45647 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45648 goto error_idr_alloc;
45649 c2dev->id = ret;
45650
45651 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45652 + pax_open_kernel();
45653 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45654 + pax_close_kernel();
45655
45656 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45657 "c2port%d", c2dev->id);
45658 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45659 index 9c34e57..b981cda 100644
45660 --- a/drivers/misc/eeprom/sunxi_sid.c
45661 +++ b/drivers/misc/eeprom/sunxi_sid.c
45662 @@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45663
45664 platform_set_drvdata(pdev, sid_data);
45665
45666 - sid_bin_attr.size = sid_data->keysize;
45667 + pax_open_kernel();
45668 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45669 + pax_close_kernel();
45670 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45671 return -ENODEV;
45672
45673 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45674 index 36f5d52..32311c3 100644
45675 --- a/drivers/misc/kgdbts.c
45676 +++ b/drivers/misc/kgdbts.c
45677 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45678 char before[BREAK_INSTR_SIZE];
45679 char after[BREAK_INSTR_SIZE];
45680
45681 - probe_kernel_read(before, (char *)kgdbts_break_test,
45682 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45683 BREAK_INSTR_SIZE);
45684 init_simple_test();
45685 ts.tst = plant_and_detach_test;
45686 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45687 /* Activate test with initial breakpoint */
45688 if (!is_early)
45689 kgdb_breakpoint();
45690 - probe_kernel_read(after, (char *)kgdbts_break_test,
45691 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45692 BREAK_INSTR_SIZE);
45693 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45694 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45695 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45696 index 036effe..b3a6336 100644
45697 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45698 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45699 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45700 * the lid is closed. This leads to interrupts as soon as a little move
45701 * is done.
45702 */
45703 - atomic_inc(&lis3->count);
45704 + atomic_inc_unchecked(&lis3->count);
45705
45706 wake_up_interruptible(&lis3->misc_wait);
45707 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45708 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45709 if (lis3->pm_dev)
45710 pm_runtime_get_sync(lis3->pm_dev);
45711
45712 - atomic_set(&lis3->count, 0);
45713 + atomic_set_unchecked(&lis3->count, 0);
45714 return 0;
45715 }
45716
45717 @@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45718 add_wait_queue(&lis3->misc_wait, &wait);
45719 while (true) {
45720 set_current_state(TASK_INTERRUPTIBLE);
45721 - data = atomic_xchg(&lis3->count, 0);
45722 + data = atomic_xchg_unchecked(&lis3->count, 0);
45723 if (data)
45724 break;
45725
45726 @@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45727 struct lis3lv02d, miscdev);
45728
45729 poll_wait(file, &lis3->misc_wait, wait);
45730 - if (atomic_read(&lis3->count))
45731 + if (atomic_read_unchecked(&lis3->count))
45732 return POLLIN | POLLRDNORM;
45733 return 0;
45734 }
45735 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45736 index c439c82..1f20f57 100644
45737 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45738 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45739 @@ -297,7 +297,7 @@ struct lis3lv02d {
45740 struct input_polled_dev *idev; /* input device */
45741 struct platform_device *pdev; /* platform device */
45742 struct regulator_bulk_data regulators[2];
45743 - atomic_t count; /* interrupt count after last read */
45744 + atomic_unchecked_t count; /* interrupt count after last read */
45745 union axis_conversion ac; /* hw -> logical axis */
45746 int mapped_btns[3];
45747
45748 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45749 index 2f30bad..c4c13d0 100644
45750 --- a/drivers/misc/sgi-gru/gruhandles.c
45751 +++ b/drivers/misc/sgi-gru/gruhandles.c
45752 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45753 unsigned long nsec;
45754
45755 nsec = CLKS2NSEC(clks);
45756 - atomic_long_inc(&mcs_op_statistics[op].count);
45757 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45758 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45759 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45760 if (mcs_op_statistics[op].max < nsec)
45761 mcs_op_statistics[op].max = nsec;
45762 }
45763 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45764 index 4f76359..cdfcb2e 100644
45765 --- a/drivers/misc/sgi-gru/gruprocfs.c
45766 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45767 @@ -32,9 +32,9 @@
45768
45769 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45770
45771 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45772 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45773 {
45774 - unsigned long val = atomic_long_read(v);
45775 + unsigned long val = atomic_long_read_unchecked(v);
45776
45777 seq_printf(s, "%16lu %s\n", val, id);
45778 }
45779 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45780
45781 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45782 for (op = 0; op < mcsop_last; op++) {
45783 - count = atomic_long_read(&mcs_op_statistics[op].count);
45784 - total = atomic_long_read(&mcs_op_statistics[op].total);
45785 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45786 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45787 max = mcs_op_statistics[op].max;
45788 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45789 count ? total / count : 0, max);
45790 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45791 index 5c3ce24..4915ccb 100644
45792 --- a/drivers/misc/sgi-gru/grutables.h
45793 +++ b/drivers/misc/sgi-gru/grutables.h
45794 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45795 * GRU statistics.
45796 */
45797 struct gru_stats_s {
45798 - atomic_long_t vdata_alloc;
45799 - atomic_long_t vdata_free;
45800 - atomic_long_t gts_alloc;
45801 - atomic_long_t gts_free;
45802 - atomic_long_t gms_alloc;
45803 - atomic_long_t gms_free;
45804 - atomic_long_t gts_double_allocate;
45805 - atomic_long_t assign_context;
45806 - atomic_long_t assign_context_failed;
45807 - atomic_long_t free_context;
45808 - atomic_long_t load_user_context;
45809 - atomic_long_t load_kernel_context;
45810 - atomic_long_t lock_kernel_context;
45811 - atomic_long_t unlock_kernel_context;
45812 - atomic_long_t steal_user_context;
45813 - atomic_long_t steal_kernel_context;
45814 - atomic_long_t steal_context_failed;
45815 - atomic_long_t nopfn;
45816 - atomic_long_t asid_new;
45817 - atomic_long_t asid_next;
45818 - atomic_long_t asid_wrap;
45819 - atomic_long_t asid_reuse;
45820 - atomic_long_t intr;
45821 - atomic_long_t intr_cbr;
45822 - atomic_long_t intr_tfh;
45823 - atomic_long_t intr_spurious;
45824 - atomic_long_t intr_mm_lock_failed;
45825 - atomic_long_t call_os;
45826 - atomic_long_t call_os_wait_queue;
45827 - atomic_long_t user_flush_tlb;
45828 - atomic_long_t user_unload_context;
45829 - atomic_long_t user_exception;
45830 - atomic_long_t set_context_option;
45831 - atomic_long_t check_context_retarget_intr;
45832 - atomic_long_t check_context_unload;
45833 - atomic_long_t tlb_dropin;
45834 - atomic_long_t tlb_preload_page;
45835 - atomic_long_t tlb_dropin_fail_no_asid;
45836 - atomic_long_t tlb_dropin_fail_upm;
45837 - atomic_long_t tlb_dropin_fail_invalid;
45838 - atomic_long_t tlb_dropin_fail_range_active;
45839 - atomic_long_t tlb_dropin_fail_idle;
45840 - atomic_long_t tlb_dropin_fail_fmm;
45841 - atomic_long_t tlb_dropin_fail_no_exception;
45842 - atomic_long_t tfh_stale_on_fault;
45843 - atomic_long_t mmu_invalidate_range;
45844 - atomic_long_t mmu_invalidate_page;
45845 - atomic_long_t flush_tlb;
45846 - atomic_long_t flush_tlb_gru;
45847 - atomic_long_t flush_tlb_gru_tgh;
45848 - atomic_long_t flush_tlb_gru_zero_asid;
45849 + atomic_long_unchecked_t vdata_alloc;
45850 + atomic_long_unchecked_t vdata_free;
45851 + atomic_long_unchecked_t gts_alloc;
45852 + atomic_long_unchecked_t gts_free;
45853 + atomic_long_unchecked_t gms_alloc;
45854 + atomic_long_unchecked_t gms_free;
45855 + atomic_long_unchecked_t gts_double_allocate;
45856 + atomic_long_unchecked_t assign_context;
45857 + atomic_long_unchecked_t assign_context_failed;
45858 + atomic_long_unchecked_t free_context;
45859 + atomic_long_unchecked_t load_user_context;
45860 + atomic_long_unchecked_t load_kernel_context;
45861 + atomic_long_unchecked_t lock_kernel_context;
45862 + atomic_long_unchecked_t unlock_kernel_context;
45863 + atomic_long_unchecked_t steal_user_context;
45864 + atomic_long_unchecked_t steal_kernel_context;
45865 + atomic_long_unchecked_t steal_context_failed;
45866 + atomic_long_unchecked_t nopfn;
45867 + atomic_long_unchecked_t asid_new;
45868 + atomic_long_unchecked_t asid_next;
45869 + atomic_long_unchecked_t asid_wrap;
45870 + atomic_long_unchecked_t asid_reuse;
45871 + atomic_long_unchecked_t intr;
45872 + atomic_long_unchecked_t intr_cbr;
45873 + atomic_long_unchecked_t intr_tfh;
45874 + atomic_long_unchecked_t intr_spurious;
45875 + atomic_long_unchecked_t intr_mm_lock_failed;
45876 + atomic_long_unchecked_t call_os;
45877 + atomic_long_unchecked_t call_os_wait_queue;
45878 + atomic_long_unchecked_t user_flush_tlb;
45879 + atomic_long_unchecked_t user_unload_context;
45880 + atomic_long_unchecked_t user_exception;
45881 + atomic_long_unchecked_t set_context_option;
45882 + atomic_long_unchecked_t check_context_retarget_intr;
45883 + atomic_long_unchecked_t check_context_unload;
45884 + atomic_long_unchecked_t tlb_dropin;
45885 + atomic_long_unchecked_t tlb_preload_page;
45886 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45887 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45888 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45889 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45890 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45891 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45892 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45893 + atomic_long_unchecked_t tfh_stale_on_fault;
45894 + atomic_long_unchecked_t mmu_invalidate_range;
45895 + atomic_long_unchecked_t mmu_invalidate_page;
45896 + atomic_long_unchecked_t flush_tlb;
45897 + atomic_long_unchecked_t flush_tlb_gru;
45898 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45899 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45900
45901 - atomic_long_t copy_gpa;
45902 - atomic_long_t read_gpa;
45903 + atomic_long_unchecked_t copy_gpa;
45904 + atomic_long_unchecked_t read_gpa;
45905
45906 - atomic_long_t mesq_receive;
45907 - atomic_long_t mesq_receive_none;
45908 - atomic_long_t mesq_send;
45909 - atomic_long_t mesq_send_failed;
45910 - atomic_long_t mesq_noop;
45911 - atomic_long_t mesq_send_unexpected_error;
45912 - atomic_long_t mesq_send_lb_overflow;
45913 - atomic_long_t mesq_send_qlimit_reached;
45914 - atomic_long_t mesq_send_amo_nacked;
45915 - atomic_long_t mesq_send_put_nacked;
45916 - atomic_long_t mesq_page_overflow;
45917 - atomic_long_t mesq_qf_locked;
45918 - atomic_long_t mesq_qf_noop_not_full;
45919 - atomic_long_t mesq_qf_switch_head_failed;
45920 - atomic_long_t mesq_qf_unexpected_error;
45921 - atomic_long_t mesq_noop_unexpected_error;
45922 - atomic_long_t mesq_noop_lb_overflow;
45923 - atomic_long_t mesq_noop_qlimit_reached;
45924 - atomic_long_t mesq_noop_amo_nacked;
45925 - atomic_long_t mesq_noop_put_nacked;
45926 - atomic_long_t mesq_noop_page_overflow;
45927 + atomic_long_unchecked_t mesq_receive;
45928 + atomic_long_unchecked_t mesq_receive_none;
45929 + atomic_long_unchecked_t mesq_send;
45930 + atomic_long_unchecked_t mesq_send_failed;
45931 + atomic_long_unchecked_t mesq_noop;
45932 + atomic_long_unchecked_t mesq_send_unexpected_error;
45933 + atomic_long_unchecked_t mesq_send_lb_overflow;
45934 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45935 + atomic_long_unchecked_t mesq_send_amo_nacked;
45936 + atomic_long_unchecked_t mesq_send_put_nacked;
45937 + atomic_long_unchecked_t mesq_page_overflow;
45938 + atomic_long_unchecked_t mesq_qf_locked;
45939 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45940 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45941 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45942 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45943 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45944 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45945 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45946 + atomic_long_unchecked_t mesq_noop_put_nacked;
45947 + atomic_long_unchecked_t mesq_noop_page_overflow;
45948
45949 };
45950
45951 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45952 tghop_invalidate, mcsop_last};
45953
45954 struct mcs_op_statistic {
45955 - atomic_long_t count;
45956 - atomic_long_t total;
45957 + atomic_long_unchecked_t count;
45958 + atomic_long_unchecked_t total;
45959 unsigned long max;
45960 };
45961
45962 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45963
45964 #define STAT(id) do { \
45965 if (gru_options & OPT_STATS) \
45966 - atomic_long_inc(&gru_stats.id); \
45967 + atomic_long_inc_unchecked(&gru_stats.id); \
45968 } while (0)
45969
45970 #ifdef CONFIG_SGI_GRU_DEBUG
45971 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45972 index c862cd4..0d176fe 100644
45973 --- a/drivers/misc/sgi-xp/xp.h
45974 +++ b/drivers/misc/sgi-xp/xp.h
45975 @@ -288,7 +288,7 @@ struct xpc_interface {
45976 xpc_notify_func, void *);
45977 void (*received) (short, int, void *);
45978 enum xp_retval (*partid_to_nasids) (short, void *);
45979 -};
45980 +} __no_const;
45981
45982 extern struct xpc_interface xpc_interface;
45983
45984 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45985 index 01be66d..e3a0c7e 100644
45986 --- a/drivers/misc/sgi-xp/xp_main.c
45987 +++ b/drivers/misc/sgi-xp/xp_main.c
45988 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45989 }
45990
45991 struct xpc_interface xpc_interface = {
45992 - (void (*)(int))xpc_notloaded,
45993 - (void (*)(int))xpc_notloaded,
45994 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45995 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45996 + .connect = (void (*)(int))xpc_notloaded,
45997 + .disconnect = (void (*)(int))xpc_notloaded,
45998 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45999 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46000 void *))xpc_notloaded,
46001 - (void (*)(short, int, void *))xpc_notloaded,
46002 - (enum xp_retval(*)(short, void *))xpc_notloaded
46003 + .received = (void (*)(short, int, void *))xpc_notloaded,
46004 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
46005 };
46006 EXPORT_SYMBOL_GPL(xpc_interface);
46007
46008 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
46009 index b94d5f7..7f494c5 100644
46010 --- a/drivers/misc/sgi-xp/xpc.h
46011 +++ b/drivers/misc/sgi-xp/xpc.h
46012 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
46013 void (*received_payload) (struct xpc_channel *, void *);
46014 void (*notify_senders_of_disconnect) (struct xpc_channel *);
46015 };
46016 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
46017
46018 /* struct xpc_partition act_state values (for XPC HB) */
46019
46020 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
46021 /* found in xpc_main.c */
46022 extern struct device *xpc_part;
46023 extern struct device *xpc_chan;
46024 -extern struct xpc_arch_operations xpc_arch_ops;
46025 +extern xpc_arch_operations_no_const xpc_arch_ops;
46026 extern int xpc_disengage_timelimit;
46027 extern int xpc_disengage_timedout;
46028 extern int xpc_activate_IRQ_rcvd;
46029 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46030 index 82dc574..8539ab2 100644
46031 --- a/drivers/misc/sgi-xp/xpc_main.c
46032 +++ b/drivers/misc/sgi-xp/xpc_main.c
46033 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
46034 .notifier_call = xpc_system_die,
46035 };
46036
46037 -struct xpc_arch_operations xpc_arch_ops;
46038 +xpc_arch_operations_no_const xpc_arch_ops;
46039
46040 /*
46041 * Timer function to enforce the timelimit on the partition disengage.
46042 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
46043
46044 if (((die_args->trapnr == X86_TRAP_MF) ||
46045 (die_args->trapnr == X86_TRAP_XF)) &&
46046 - !user_mode_vm(die_args->regs))
46047 + !user_mode(die_args->regs))
46048 xpc_die_deactivate();
46049
46050 break;
46051 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46052 index 7b5424f..ed1d6ac 100644
46053 --- a/drivers/mmc/card/block.c
46054 +++ b/drivers/mmc/card/block.c
46055 @@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46056 if (idata->ic.postsleep_min_us)
46057 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
46058
46059 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
46060 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
46061 err = -EFAULT;
46062 goto cmd_rel_host;
46063 }
46064 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
46065 index e5b5eeb..7bf2212 100644
46066 --- a/drivers/mmc/core/mmc_ops.c
46067 +++ b/drivers/mmc/core/mmc_ops.c
46068 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
46069 void *data_buf;
46070 int is_on_stack;
46071
46072 - is_on_stack = object_is_on_stack(buf);
46073 + is_on_stack = object_starts_on_stack(buf);
46074 if (is_on_stack) {
46075 /*
46076 * dma onto stack is unsafe/nonportable, but callers to this
46077 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
46078 index 6bf24ab..13d0293b 100644
46079 --- a/drivers/mmc/host/dw_mmc.h
46080 +++ b/drivers/mmc/host/dw_mmc.h
46081 @@ -258,5 +258,5 @@ struct dw_mci_drv_data {
46082 int (*parse_dt)(struct dw_mci *host);
46083 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
46084 struct dw_mci_tuning_data *tuning_data);
46085 -};
46086 +} __do_const;
46087 #endif /* _DW_MMC_H_ */
46088 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
46089 index b931226..df6a085 100644
46090 --- a/drivers/mmc/host/mmci.c
46091 +++ b/drivers/mmc/host/mmci.c
46092 @@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
46093 }
46094
46095 if (variant->busy_detect) {
46096 - mmci_ops.card_busy = mmci_card_busy;
46097 + pax_open_kernel();
46098 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
46099 + pax_close_kernel();
46100 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
46101 }
46102
46103 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
46104 index b841bb7..d82712f5 100644
46105 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
46106 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
46107 @@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
46108 host->mmc->caps |= MMC_CAP_1_8V_DDR;
46109 }
46110
46111 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
46112 - sdhci_esdhc_ops.platform_execute_tuning =
46113 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
46114 + pax_open_kernel();
46115 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
46116 esdhc_executing_tuning;
46117 + pax_close_kernel();
46118 + }
46119
46120 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
46121 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
46122 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
46123 index 6debda9..2ba7427 100644
46124 --- a/drivers/mmc/host/sdhci-s3c.c
46125 +++ b/drivers/mmc/host/sdhci-s3c.c
46126 @@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
46127 * we can use overriding functions instead of default.
46128 */
46129 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
46130 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46131 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46132 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46133 + pax_open_kernel();
46134 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46135 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46136 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46137 + pax_close_kernel();
46138 }
46139
46140 /* It supports additional host capabilities if needed */
46141 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
46142 index 096993f..f02c23b 100644
46143 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
46144 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
46145 @@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
46146 size_t totlen = 0, thislen;
46147 int ret = 0;
46148 size_t buflen = 0;
46149 - static char *buffer;
46150 + char *buffer;
46151
46152 if (!ECCBUF_SIZE) {
46153 /* We should fall back to a general writev implementation.
46154 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
46155 index c07cd57..61c4fbd 100644
46156 --- a/drivers/mtd/nand/denali.c
46157 +++ b/drivers/mtd/nand/denali.c
46158 @@ -24,6 +24,7 @@
46159 #include <linux/slab.h>
46160 #include <linux/mtd/mtd.h>
46161 #include <linux/module.h>
46162 +#include <linux/slab.h>
46163
46164 #include "denali.h"
46165
46166 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46167 index ca6369f..0ce9fed 100644
46168 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46169 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46170 @@ -369,7 +369,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
46171
46172 /* first try to map the upper buffer directly */
46173 if (virt_addr_valid(this->upper_buf) &&
46174 - !object_is_on_stack(this->upper_buf)) {
46175 + !object_starts_on_stack(this->upper_buf)) {
46176 sg_init_one(sgl, this->upper_buf, this->upper_len);
46177 ret = dma_map_sg(this->dev, sgl, 1, dr);
46178 if (ret == 0)
46179 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
46180 index 51b9d6a..52af9a7 100644
46181 --- a/drivers/mtd/nftlmount.c
46182 +++ b/drivers/mtd/nftlmount.c
46183 @@ -24,6 +24,7 @@
46184 #include <asm/errno.h>
46185 #include <linux/delay.h>
46186 #include <linux/slab.h>
46187 +#include <linux/sched.h>
46188 #include <linux/mtd/mtd.h>
46189 #include <linux/mtd/nand.h>
46190 #include <linux/mtd/nftl.h>
46191 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
46192 index cf49c22..971b133 100644
46193 --- a/drivers/mtd/sm_ftl.c
46194 +++ b/drivers/mtd/sm_ftl.c
46195 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
46196 #define SM_CIS_VENDOR_OFFSET 0x59
46197 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
46198 {
46199 - struct attribute_group *attr_group;
46200 + attribute_group_no_const *attr_group;
46201 struct attribute **attributes;
46202 struct sm_sysfs_attribute *vendor_attribute;
46203 char *vendor;
46204 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
46205 index e5628fc..ffe54d1 100644
46206 --- a/drivers/net/bonding/bond_main.c
46207 +++ b/drivers/net/bonding/bond_main.c
46208 @@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
46209
46210 bond_netlink_fini();
46211 unregister_pernet_subsys(&bond_net_ops);
46212 + rtnl_link_unregister(&bond_link_ops);
46213
46214 #ifdef CONFIG_NET_POLL_CONTROLLER
46215 /*
46216 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
46217 index 70651f8..7eb1bdf 100644
46218 --- a/drivers/net/bonding/bond_netlink.c
46219 +++ b/drivers/net/bonding/bond_netlink.c
46220 @@ -542,7 +542,7 @@ nla_put_failure:
46221 return -EMSGSIZE;
46222 }
46223
46224 -struct rtnl_link_ops bond_link_ops __read_mostly = {
46225 +struct rtnl_link_ops bond_link_ops = {
46226 .kind = "bond",
46227 .priv_size = sizeof(struct bonding),
46228 .setup = bond_setup,
46229 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
46230 index 9e7d95d..d447b88 100644
46231 --- a/drivers/net/can/Kconfig
46232 +++ b/drivers/net/can/Kconfig
46233 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
46234
46235 config CAN_FLEXCAN
46236 tristate "Support for Freescale FLEXCAN based chips"
46237 - depends on ARM || PPC
46238 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
46239 ---help---
46240 Say Y here if you want to support for Freescale FlexCAN.
46241
46242 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
46243 index 455d4c3..3353ee7 100644
46244 --- a/drivers/net/ethernet/8390/ax88796.c
46245 +++ b/drivers/net/ethernet/8390/ax88796.c
46246 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
46247 if (ax->plat->reg_offsets)
46248 ei_local->reg_offset = ax->plat->reg_offsets;
46249 else {
46250 + resource_size_t _mem_size = mem_size;
46251 + do_div(_mem_size, 0x18);
46252 ei_local->reg_offset = ax->reg_offsets;
46253 for (ret = 0; ret < 0x18; ret++)
46254 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
46255 + ax->reg_offsets[ret] = _mem_size * ret;
46256 }
46257
46258 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
46259 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46260 index a89a40f..5a8a2ac 100644
46261 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46262 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46263 @@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
46264 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
46265 {
46266 /* RX_MODE controlling object */
46267 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
46268 + bnx2x_init_rx_mode_obj(bp);
46269
46270 /* multicast configuration controlling object */
46271 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
46272 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46273 index 0fb6ff2..78fd55c 100644
46274 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46275 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46276 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
46277 return rc;
46278 }
46279
46280 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46281 - struct bnx2x_rx_mode_obj *o)
46282 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
46283 {
46284 if (CHIP_IS_E1x(bp)) {
46285 - o->wait_comp = bnx2x_empty_rx_mode_wait;
46286 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
46287 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
46288 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
46289 } else {
46290 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
46291 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
46292 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
46293 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
46294 }
46295 }
46296
46297 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46298 index 00d7f21..2cddec4 100644
46299 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46300 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46301 @@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
46302
46303 /********************* RX MODE ****************/
46304
46305 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46306 - struct bnx2x_rx_mode_obj *o);
46307 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
46308
46309 /**
46310 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
46311 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
46312 index 04321e5..b51cdc4 100644
46313 --- a/drivers/net/ethernet/broadcom/tg3.h
46314 +++ b/drivers/net/ethernet/broadcom/tg3.h
46315 @@ -150,6 +150,7 @@
46316 #define CHIPREV_ID_5750_A0 0x4000
46317 #define CHIPREV_ID_5750_A1 0x4001
46318 #define CHIPREV_ID_5750_A3 0x4003
46319 +#define CHIPREV_ID_5750_C1 0x4201
46320 #define CHIPREV_ID_5750_C2 0x4202
46321 #define CHIPREV_ID_5752_A0_HW 0x5000
46322 #define CHIPREV_ID_5752_A0 0x6000
46323 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46324 index 13f9636..228040f 100644
46325 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46326 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46327 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46328 }
46329
46330 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46331 - bna_cb_ioceth_enable,
46332 - bna_cb_ioceth_disable,
46333 - bna_cb_ioceth_hbfail,
46334 - bna_cb_ioceth_reset
46335 + .enable_cbfn = bna_cb_ioceth_enable,
46336 + .disable_cbfn = bna_cb_ioceth_disable,
46337 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
46338 + .reset_cbfn = bna_cb_ioceth_reset
46339 };
46340
46341 static void bna_attr_init(struct bna_ioceth *ioceth)
46342 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46343 index 8cffcdf..aadf043 100644
46344 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46345 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46346 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46347 */
46348 struct l2t_skb_cb {
46349 arp_failure_handler_func arp_failure_handler;
46350 -};
46351 +} __no_const;
46352
46353 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46354
46355 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46356 index 34e2488..07e2079 100644
46357 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46358 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46359 @@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46360
46361 int i;
46362 struct adapter *ap = netdev2adap(dev);
46363 - static const unsigned int *reg_ranges;
46364 + const unsigned int *reg_ranges;
46365 int arr_size = 0, buf_size = 0;
46366
46367 if (is_t4(ap->params.chip)) {
46368 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46369 index c05b66d..ed69872 100644
46370 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
46371 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46372 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46373 for (i=0; i<ETH_ALEN; i++) {
46374 tmp.addr[i] = dev->dev_addr[i];
46375 }
46376 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46377 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46378 break;
46379
46380 case DE4X5_SET_HWADDR: /* Set the hardware address */
46381 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46382 spin_lock_irqsave(&lp->lock, flags);
46383 memcpy(&statbuf, &lp->pktStats, ioc->len);
46384 spin_unlock_irqrestore(&lp->lock, flags);
46385 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
46386 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46387 return -EFAULT;
46388 break;
46389 }
46390 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46391 index 36c8061..ca5e1e0 100644
46392 --- a/drivers/net/ethernet/emulex/benet/be_main.c
46393 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
46394 @@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46395
46396 if (wrapped)
46397 newacc += 65536;
46398 - ACCESS_ONCE(*acc) = newacc;
46399 + ACCESS_ONCE_RW(*acc) = newacc;
46400 }
46401
46402 static void populate_erx_stats(struct be_adapter *adapter,
46403 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46404 index c11ecbc..13bb299 100644
46405 --- a/drivers/net/ethernet/faraday/ftgmac100.c
46406 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
46407 @@ -30,6 +30,8 @@
46408 #include <linux/netdevice.h>
46409 #include <linux/phy.h>
46410 #include <linux/platform_device.h>
46411 +#include <linux/interrupt.h>
46412 +#include <linux/irqreturn.h>
46413 #include <net/ip.h>
46414
46415 #include "ftgmac100.h"
46416 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46417 index 8be5b40..081bc1b 100644
46418 --- a/drivers/net/ethernet/faraday/ftmac100.c
46419 +++ b/drivers/net/ethernet/faraday/ftmac100.c
46420 @@ -31,6 +31,8 @@
46421 #include <linux/module.h>
46422 #include <linux/netdevice.h>
46423 #include <linux/platform_device.h>
46424 +#include <linux/interrupt.h>
46425 +#include <linux/irqreturn.h>
46426
46427 #include "ftmac100.h"
46428
46429 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46430 index e33ec6c..f54cfe7 100644
46431 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46432 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46433 @@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46434 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46435
46436 /* Update the base adjustement value. */
46437 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
46438 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46439 smp_mb(); /* Force the above update. */
46440 }
46441
46442 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46443 index 5184e2a..acb28c3 100644
46444 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46445 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46446 @@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46447 }
46448
46449 /* update the base incval used to calculate frequency adjustment */
46450 - ACCESS_ONCE(adapter->base_incval) = incval;
46451 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
46452 smp_mb();
46453
46454 /* need lock to prevent incorrect read while modifying cyclecounter */
46455 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46456 index 089b713..28d87ae 100644
46457 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46458 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46459 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46460 struct __vxge_hw_fifo *fifo;
46461 struct vxge_hw_fifo_config *config;
46462 u32 txdl_size, txdl_per_memblock;
46463 - struct vxge_hw_mempool_cbs fifo_mp_callback;
46464 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46465 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46466 + };
46467 +
46468 struct __vxge_hw_virtualpath *vpath;
46469
46470 if ((vp == NULL) || (attr == NULL)) {
46471 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46472 goto exit;
46473 }
46474
46475 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46476 -
46477 fifo->mempool =
46478 __vxge_hw_mempool_create(vpath->hldev,
46479 fifo->config->memblock_size,
46480 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46481 index 90a2dda..47e620e 100644
46482 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46483 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46484 @@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46485 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46486 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46487 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46488 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46489 + pax_open_kernel();
46490 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46491 + pax_close_kernel();
46492 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46493 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46494 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
46495 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46496 index be7d7a6..a8983f8 100644
46497 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46498 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46499 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46500 case QLCNIC_NON_PRIV_FUNC:
46501 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46502 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46503 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46504 + pax_open_kernel();
46505 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46506 + pax_close_kernel();
46507 break;
46508 case QLCNIC_PRIV_FUNC:
46509 ahw->op_mode = QLCNIC_PRIV_FUNC;
46510 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46511 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46512 + pax_open_kernel();
46513 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46514 + pax_close_kernel();
46515 break;
46516 case QLCNIC_MGMT_FUNC:
46517 ahw->op_mode = QLCNIC_MGMT_FUNC;
46518 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46519 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46520 + pax_open_kernel();
46521 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46522 + pax_close_kernel();
46523 break;
46524 default:
46525 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46526 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46527 index 7763962..c3499a7 100644
46528 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46529 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46530 @@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46531 struct qlcnic_dump_entry *entry;
46532 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46533 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
46534 - static const struct qlcnic_dump_operations *fw_dump_ops;
46535 + const struct qlcnic_dump_operations *fw_dump_ops;
46536 struct device *dev = &adapter->pdev->dev;
46537 struct qlcnic_hardware_context *ahw;
46538 void *temp_buffer;
46539 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46540 index 3ff7bc3..366091b 100644
46541 --- a/drivers/net/ethernet/realtek/r8169.c
46542 +++ b/drivers/net/ethernet/realtek/r8169.c
46543 @@ -758,22 +758,22 @@ struct rtl8169_private {
46544 struct mdio_ops {
46545 void (*write)(struct rtl8169_private *, int, int);
46546 int (*read)(struct rtl8169_private *, int);
46547 - } mdio_ops;
46548 + } __no_const mdio_ops;
46549
46550 struct pll_power_ops {
46551 void (*down)(struct rtl8169_private *);
46552 void (*up)(struct rtl8169_private *);
46553 - } pll_power_ops;
46554 + } __no_const pll_power_ops;
46555
46556 struct jumbo_ops {
46557 void (*enable)(struct rtl8169_private *);
46558 void (*disable)(struct rtl8169_private *);
46559 - } jumbo_ops;
46560 + } __no_const jumbo_ops;
46561
46562 struct csi_ops {
46563 void (*write)(struct rtl8169_private *, int, int);
46564 u32 (*read)(struct rtl8169_private *, int);
46565 - } csi_ops;
46566 + } __no_const csi_ops;
46567
46568 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46569 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46570 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46571 index d7a3682..9ce272a 100644
46572 --- a/drivers/net/ethernet/sfc/ptp.c
46573 +++ b/drivers/net/ethernet/sfc/ptp.c
46574 @@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46575 ptp->start.dma_addr);
46576
46577 /* Clear flag that signals MC ready */
46578 - ACCESS_ONCE(*start) = 0;
46579 + ACCESS_ONCE_RW(*start) = 0;
46580 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46581 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46582 EFX_BUG_ON_PARANOID(rc);
46583 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46584 index 50617c5..b13724c 100644
46585 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46586 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46587 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46588
46589 writel(value, ioaddr + MMC_CNTRL);
46590
46591 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46592 - MMC_CNTRL, value);
46593 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46594 +// MMC_CNTRL, value);
46595 }
46596
46597 /* To mask all all interrupts.*/
46598 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46599 index 7b594ce..1f6c5708 100644
46600 --- a/drivers/net/hyperv/hyperv_net.h
46601 +++ b/drivers/net/hyperv/hyperv_net.h
46602 @@ -100,7 +100,7 @@ struct rndis_device {
46603
46604 enum rndis_device_state state;
46605 bool link_state;
46606 - atomic_t new_req_id;
46607 + atomic_unchecked_t new_req_id;
46608
46609 spinlock_t request_lock;
46610 struct list_head req_list;
46611 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46612 index b54fd25..9bd2bae 100644
46613 --- a/drivers/net/hyperv/rndis_filter.c
46614 +++ b/drivers/net/hyperv/rndis_filter.c
46615 @@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46616 * template
46617 */
46618 set = &rndis_msg->msg.set_req;
46619 - set->req_id = atomic_inc_return(&dev->new_req_id);
46620 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46621
46622 /* Add to the request list */
46623 spin_lock_irqsave(&dev->request_lock, flags);
46624 @@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46625
46626 /* Setup the rndis set */
46627 halt = &request->request_msg.msg.halt_req;
46628 - halt->req_id = atomic_inc_return(&dev->new_req_id);
46629 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46630
46631 /* Ignore return since this msg is optional. */
46632 rndis_filter_send_request(dev, request);
46633 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46634 index bf0d55e..82bcfbd1 100644
46635 --- a/drivers/net/ieee802154/fakehard.c
46636 +++ b/drivers/net/ieee802154/fakehard.c
46637 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46638 phy->transmit_power = 0xbf;
46639
46640 dev->netdev_ops = &fake_ops;
46641 - dev->ml_priv = &fake_mlme;
46642 + dev->ml_priv = (void *)&fake_mlme;
46643
46644 priv = netdev_priv(dev);
46645 priv->phy = phy;
46646 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46647 index 1831fb7..9c24bca 100644
46648 --- a/drivers/net/macvlan.c
46649 +++ b/drivers/net/macvlan.c
46650 @@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46651 int macvlan_link_register(struct rtnl_link_ops *ops)
46652 {
46653 /* common fields */
46654 - ops->priv_size = sizeof(struct macvlan_dev);
46655 - ops->validate = macvlan_validate;
46656 - ops->maxtype = IFLA_MACVLAN_MAX;
46657 - ops->policy = macvlan_policy;
46658 - ops->changelink = macvlan_changelink;
46659 - ops->get_size = macvlan_get_size;
46660 - ops->fill_info = macvlan_fill_info;
46661 + pax_open_kernel();
46662 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46663 + *(void **)&ops->validate = macvlan_validate;
46664 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46665 + *(const void **)&ops->policy = macvlan_policy;
46666 + *(void **)&ops->changelink = macvlan_changelink;
46667 + *(void **)&ops->get_size = macvlan_get_size;
46668 + *(void **)&ops->fill_info = macvlan_fill_info;
46669 + pax_close_kernel();
46670
46671 return rtnl_link_register(ops);
46672 };
46673 @@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46674 return NOTIFY_DONE;
46675 }
46676
46677 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46678 +static struct notifier_block macvlan_notifier_block = {
46679 .notifier_call = macvlan_device_event,
46680 };
46681
46682 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46683 index ff111a8..c4c3ac4 100644
46684 --- a/drivers/net/macvtap.c
46685 +++ b/drivers/net/macvtap.c
46686 @@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46687 }
46688
46689 ret = 0;
46690 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46691 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46692 put_user(q->flags, &ifr->ifr_flags))
46693 ret = -EFAULT;
46694 macvtap_put_vlan(vlan);
46695 @@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46696 return NOTIFY_DONE;
46697 }
46698
46699 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46700 +static struct notifier_block macvtap_notifier_block = {
46701 .notifier_call = macvtap_device_event,
46702 };
46703
46704 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46705 index daec9b0..6428fcb 100644
46706 --- a/drivers/net/phy/mdio-bitbang.c
46707 +++ b/drivers/net/phy/mdio-bitbang.c
46708 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46709 struct mdiobb_ctrl *ctrl = bus->priv;
46710
46711 module_put(ctrl->ops->owner);
46712 + mdiobus_unregister(bus);
46713 mdiobus_free(bus);
46714 }
46715 EXPORT_SYMBOL(free_mdio_bitbang);
46716 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46717 index 72ff14b..11d442d 100644
46718 --- a/drivers/net/ppp/ppp_generic.c
46719 +++ b/drivers/net/ppp/ppp_generic.c
46720 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46721 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46722 struct ppp_stats stats;
46723 struct ppp_comp_stats cstats;
46724 - char *vers;
46725
46726 switch (cmd) {
46727 case SIOCGPPPSTATS:
46728 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46729 break;
46730
46731 case SIOCGPPPVER:
46732 - vers = PPP_VERSION;
46733 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46734 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46735 break;
46736 err = 0;
46737 break;
46738 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46739 index 1252d9c..80e660b 100644
46740 --- a/drivers/net/slip/slhc.c
46741 +++ b/drivers/net/slip/slhc.c
46742 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46743 register struct tcphdr *thp;
46744 register struct iphdr *ip;
46745 register struct cstate *cs;
46746 - int len, hdrlen;
46747 + long len, hdrlen;
46748 unsigned char *cp = icp;
46749
46750 /* We've got a compressed packet; read the change byte */
46751 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46752 index c8624a8..f0a4f6a 100644
46753 --- a/drivers/net/team/team.c
46754 +++ b/drivers/net/team/team.c
46755 @@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46756 return NOTIFY_DONE;
46757 }
46758
46759 -static struct notifier_block team_notifier_block __read_mostly = {
46760 +static struct notifier_block team_notifier_block = {
46761 .notifier_call = team_device_event,
46762 };
46763
46764 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46765 index 26f8635..c237839 100644
46766 --- a/drivers/net/tun.c
46767 +++ b/drivers/net/tun.c
46768 @@ -1876,7 +1876,7 @@ unlock:
46769 }
46770
46771 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46772 - unsigned long arg, int ifreq_len)
46773 + unsigned long arg, size_t ifreq_len)
46774 {
46775 struct tun_file *tfile = file->private_data;
46776 struct tun_struct *tun;
46777 @@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46778 unsigned int ifindex;
46779 int ret;
46780
46781 + if (ifreq_len > sizeof ifr)
46782 + return -EFAULT;
46783 +
46784 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46785 if (copy_from_user(&ifr, argp, ifreq_len))
46786 return -EFAULT;
46787 diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
46788 index d350d27..75d7d9d 100644
46789 --- a/drivers/net/usb/cdc_ncm.c
46790 +++ b/drivers/net/usb/cdc_ncm.c
46791 @@ -768,7 +768,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
46792 skb_out->len > CDC_NCM_MIN_TX_PKT)
46793 memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0,
46794 ctx->tx_max - skb_out->len);
46795 - else if ((skb_out->len % dev->maxpacket) == 0)
46796 + else if (skb_out->len < ctx->tx_max && (skb_out->len % dev->maxpacket) == 0)
46797 *skb_put(skb_out, 1) = 0; /* force short packet */
46798
46799 /* set final frame length */
46800 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46801 index 660bd5e..ac59452 100644
46802 --- a/drivers/net/usb/hso.c
46803 +++ b/drivers/net/usb/hso.c
46804 @@ -71,7 +71,7 @@
46805 #include <asm/byteorder.h>
46806 #include <linux/serial_core.h>
46807 #include <linux/serial.h>
46808 -
46809 +#include <asm/local.h>
46810
46811 #define MOD_AUTHOR "Option Wireless"
46812 #define MOD_DESCRIPTION "USB High Speed Option driver"
46813 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46814 struct urb *urb;
46815
46816 urb = serial->rx_urb[0];
46817 - if (serial->port.count > 0) {
46818 + if (atomic_read(&serial->port.count) > 0) {
46819 count = put_rxbuf_data(urb, serial);
46820 if (count == -1)
46821 return;
46822 @@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46823 DUMP1(urb->transfer_buffer, urb->actual_length);
46824
46825 /* Anyone listening? */
46826 - if (serial->port.count == 0)
46827 + if (atomic_read(&serial->port.count) == 0)
46828 return;
46829
46830 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46831 @@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46832 tty_port_tty_set(&serial->port, tty);
46833
46834 /* check for port already opened, if not set the termios */
46835 - serial->port.count++;
46836 - if (serial->port.count == 1) {
46837 + if (atomic_inc_return(&serial->port.count) == 1) {
46838 serial->rx_state = RX_IDLE;
46839 /* Force default termio settings */
46840 _hso_serial_set_termios(tty, NULL);
46841 @@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46842 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46843 if (result) {
46844 hso_stop_serial_device(serial->parent);
46845 - serial->port.count--;
46846 + atomic_dec(&serial->port.count);
46847 kref_put(&serial->parent->ref, hso_serial_ref_free);
46848 }
46849 } else {
46850 @@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46851
46852 /* reset the rts and dtr */
46853 /* do the actual close */
46854 - serial->port.count--;
46855 + atomic_dec(&serial->port.count);
46856
46857 - if (serial->port.count <= 0) {
46858 - serial->port.count = 0;
46859 + if (atomic_read(&serial->port.count) <= 0) {
46860 + atomic_set(&serial->port.count, 0);
46861 tty_port_tty_set(&serial->port, NULL);
46862 if (!usb_gone)
46863 hso_stop_serial_device(serial->parent);
46864 @@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46865
46866 /* the actual setup */
46867 spin_lock_irqsave(&serial->serial_lock, flags);
46868 - if (serial->port.count)
46869 + if (atomic_read(&serial->port.count))
46870 _hso_serial_set_termios(tty, old);
46871 else
46872 tty->termios = *old;
46873 @@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46874 D1("Pending read interrupt on port %d\n", i);
46875 spin_lock(&serial->serial_lock);
46876 if (serial->rx_state == RX_IDLE &&
46877 - serial->port.count > 0) {
46878 + atomic_read(&serial->port.count) > 0) {
46879 /* Setup and send a ctrl req read on
46880 * port i */
46881 if (!serial->rx_urb_filled[0]) {
46882 @@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46883 /* Start all serial ports */
46884 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46885 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46886 - if (dev2ser(serial_table[i])->port.count) {
46887 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46888 result =
46889 hso_start_serial_device(serial_table[i], GFP_NOIO);
46890 hso_kick_transmit(dev2ser(serial_table[i]));
46891 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46892 index adb12f3..48005ab 100644
46893 --- a/drivers/net/usb/r8152.c
46894 +++ b/drivers/net/usb/r8152.c
46895 @@ -513,7 +513,7 @@ struct r8152 {
46896 void (*disable)(struct r8152 *);
46897 void (*down)(struct r8152 *);
46898 void (*unload)(struct r8152 *);
46899 - } rtl_ops;
46900 + } __no_const rtl_ops;
46901
46902 int intr_interval;
46903 u32 msg_enable;
46904 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46905 index a2515887..6d13233 100644
46906 --- a/drivers/net/usb/sierra_net.c
46907 +++ b/drivers/net/usb/sierra_net.c
46908 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46909 /* atomic counter partially included in MAC address to make sure 2 devices
46910 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46911 */
46912 -static atomic_t iface_counter = ATOMIC_INIT(0);
46913 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46914
46915 /*
46916 * SYNC Timer Delay definition used to set the expiry time
46917 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46918 dev->net->netdev_ops = &sierra_net_device_ops;
46919
46920 /* change MAC addr to include, ifacenum, and to be unique */
46921 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46922 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46923 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46924
46925 /* we will have to manufacture ethernet headers, prepare template */
46926 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46927 index d091e52..568bb179 100644
46928 --- a/drivers/net/vxlan.c
46929 +++ b/drivers/net/vxlan.c
46930 @@ -2847,7 +2847,7 @@ nla_put_failure:
46931 return -EMSGSIZE;
46932 }
46933
46934 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46935 +static struct rtnl_link_ops vxlan_link_ops = {
46936 .kind = "vxlan",
46937 .maxtype = IFLA_VXLAN_MAX,
46938 .policy = vxlan_policy,
46939 @@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46940 return NOTIFY_DONE;
46941 }
46942
46943 -static struct notifier_block vxlan_notifier_block __read_mostly = {
46944 +static struct notifier_block vxlan_notifier_block = {
46945 .notifier_call = vxlan_lowerdev_event,
46946 };
46947
46948 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46949 index 5920c99..ff2e4a5 100644
46950 --- a/drivers/net/wan/lmc/lmc_media.c
46951 +++ b/drivers/net/wan/lmc/lmc_media.c
46952 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46953 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46954
46955 lmc_media_t lmc_ds3_media = {
46956 - lmc_ds3_init, /* special media init stuff */
46957 - lmc_ds3_default, /* reset to default state */
46958 - lmc_ds3_set_status, /* reset status to state provided */
46959 - lmc_dummy_set_1, /* set clock source */
46960 - lmc_dummy_set2_1, /* set line speed */
46961 - lmc_ds3_set_100ft, /* set cable length */
46962 - lmc_ds3_set_scram, /* set scrambler */
46963 - lmc_ds3_get_link_status, /* get link status */
46964 - lmc_dummy_set_1, /* set link status */
46965 - lmc_ds3_set_crc_length, /* set CRC length */
46966 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46967 - lmc_ds3_watchdog
46968 + .init = lmc_ds3_init, /* special media init stuff */
46969 + .defaults = lmc_ds3_default, /* reset to default state */
46970 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46971 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46972 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46973 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46974 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46975 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46976 + .set_link_status = lmc_dummy_set_1, /* set link status */
46977 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46978 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46979 + .watchdog = lmc_ds3_watchdog
46980 };
46981
46982 lmc_media_t lmc_hssi_media = {
46983 - lmc_hssi_init, /* special media init stuff */
46984 - lmc_hssi_default, /* reset to default state */
46985 - lmc_hssi_set_status, /* reset status to state provided */
46986 - lmc_hssi_set_clock, /* set clock source */
46987 - lmc_dummy_set2_1, /* set line speed */
46988 - lmc_dummy_set_1, /* set cable length */
46989 - lmc_dummy_set_1, /* set scrambler */
46990 - lmc_hssi_get_link_status, /* get link status */
46991 - lmc_hssi_set_link_status, /* set link status */
46992 - lmc_hssi_set_crc_length, /* set CRC length */
46993 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46994 - lmc_hssi_watchdog
46995 + .init = lmc_hssi_init, /* special media init stuff */
46996 + .defaults = lmc_hssi_default, /* reset to default state */
46997 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46998 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46999 + .set_speed = lmc_dummy_set2_1, /* set line speed */
47000 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
47001 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47002 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
47003 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
47004 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
47005 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
47006 + .watchdog = lmc_hssi_watchdog
47007 };
47008
47009 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
47010 - lmc_ssi_default, /* reset to default state */
47011 - lmc_ssi_set_status, /* reset status to state provided */
47012 - lmc_ssi_set_clock, /* set clock source */
47013 - lmc_ssi_set_speed, /* set line speed */
47014 - lmc_dummy_set_1, /* set cable length */
47015 - lmc_dummy_set_1, /* set scrambler */
47016 - lmc_ssi_get_link_status, /* get link status */
47017 - lmc_ssi_set_link_status, /* set link status */
47018 - lmc_ssi_set_crc_length, /* set CRC length */
47019 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
47020 - lmc_ssi_watchdog
47021 +lmc_media_t lmc_ssi_media = {
47022 + .init = lmc_ssi_init, /* special media init stuff */
47023 + .defaults = lmc_ssi_default, /* reset to default state */
47024 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
47025 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
47026 + .set_speed = lmc_ssi_set_speed, /* set line speed */
47027 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
47028 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47029 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
47030 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
47031 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
47032 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
47033 + .watchdog = lmc_ssi_watchdog
47034 };
47035
47036 lmc_media_t lmc_t1_media = {
47037 - lmc_t1_init, /* special media init stuff */
47038 - lmc_t1_default, /* reset to default state */
47039 - lmc_t1_set_status, /* reset status to state provided */
47040 - lmc_t1_set_clock, /* set clock source */
47041 - lmc_dummy_set2_1, /* set line speed */
47042 - lmc_dummy_set_1, /* set cable length */
47043 - lmc_dummy_set_1, /* set scrambler */
47044 - lmc_t1_get_link_status, /* get link status */
47045 - lmc_dummy_set_1, /* set link status */
47046 - lmc_t1_set_crc_length, /* set CRC length */
47047 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47048 - lmc_t1_watchdog
47049 + .init = lmc_t1_init, /* special media init stuff */
47050 + .defaults = lmc_t1_default, /* reset to default state */
47051 + .set_status = lmc_t1_set_status, /* reset status to state provided */
47052 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
47053 + .set_speed = lmc_dummy_set2_1, /* set line speed */
47054 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
47055 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47056 + .get_link_status = lmc_t1_get_link_status, /* get link status */
47057 + .set_link_status = lmc_dummy_set_1, /* set link status */
47058 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
47059 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47060 + .watchdog = lmc_t1_watchdog
47061 };
47062
47063 static void
47064 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
47065 index feacc3b..5bac0de 100644
47066 --- a/drivers/net/wan/z85230.c
47067 +++ b/drivers/net/wan/z85230.c
47068 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
47069
47070 struct z8530_irqhandler z8530_sync =
47071 {
47072 - z8530_rx,
47073 - z8530_tx,
47074 - z8530_status
47075 + .rx = z8530_rx,
47076 + .tx = z8530_tx,
47077 + .status = z8530_status
47078 };
47079
47080 EXPORT_SYMBOL(z8530_sync);
47081 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
47082 }
47083
47084 static struct z8530_irqhandler z8530_dma_sync = {
47085 - z8530_dma_rx,
47086 - z8530_dma_tx,
47087 - z8530_dma_status
47088 + .rx = z8530_dma_rx,
47089 + .tx = z8530_dma_tx,
47090 + .status = z8530_dma_status
47091 };
47092
47093 static struct z8530_irqhandler z8530_txdma_sync = {
47094 - z8530_rx,
47095 - z8530_dma_tx,
47096 - z8530_dma_status
47097 + .rx = z8530_rx,
47098 + .tx = z8530_dma_tx,
47099 + .status = z8530_dma_status
47100 };
47101
47102 /**
47103 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
47104
47105 struct z8530_irqhandler z8530_nop=
47106 {
47107 - z8530_rx_clear,
47108 - z8530_tx_clear,
47109 - z8530_status_clear
47110 + .rx = z8530_rx_clear,
47111 + .tx = z8530_tx_clear,
47112 + .status = z8530_status_clear
47113 };
47114
47115
47116 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
47117 index 0b60295..b8bfa5b 100644
47118 --- a/drivers/net/wimax/i2400m/rx.c
47119 +++ b/drivers/net/wimax/i2400m/rx.c
47120 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
47121 if (i2400m->rx_roq == NULL)
47122 goto error_roq_alloc;
47123
47124 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
47125 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
47126 GFP_KERNEL);
47127 if (rd == NULL) {
47128 result = -ENOMEM;
47129 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
47130 index edf4b57..68b51c0 100644
47131 --- a/drivers/net/wireless/airo.c
47132 +++ b/drivers/net/wireless/airo.c
47133 @@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
47134 struct airo_info *ai = dev->ml_priv;
47135 int ridcode;
47136 int enabled;
47137 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47138 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47139 unsigned char *iobuf;
47140
47141 /* Only super-user can write RIDs */
47142 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
47143 index 99b3bfa..9559372 100644
47144 --- a/drivers/net/wireless/at76c50x-usb.c
47145 +++ b/drivers/net/wireless/at76c50x-usb.c
47146 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
47147 }
47148
47149 /* Convert timeout from the DFU status to jiffies */
47150 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
47151 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
47152 {
47153 return msecs_to_jiffies((s->poll_timeout[2] << 16)
47154 | (s->poll_timeout[1] << 8)
47155 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
47156 index edc57ab..ff49e0a 100644
47157 --- a/drivers/net/wireless/ath/ath10k/htc.c
47158 +++ b/drivers/net/wireless/ath/ath10k/htc.c
47159 @@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
47160 /* registered target arrival callback from the HIF layer */
47161 int ath10k_htc_init(struct ath10k *ar)
47162 {
47163 - struct ath10k_hif_cb htc_callbacks;
47164 + static struct ath10k_hif_cb htc_callbacks = {
47165 + .rx_completion = ath10k_htc_rx_completion_handler,
47166 + .tx_completion = ath10k_htc_tx_completion_handler,
47167 + };
47168 struct ath10k_htc_ep *ep = NULL;
47169 struct ath10k_htc *htc = &ar->htc;
47170
47171 @@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
47172 ath10k_htc_reset_endpoint_states(htc);
47173
47174 /* setup HIF layer callbacks */
47175 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
47176 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
47177 htc->ar = ar;
47178
47179 /* Get HIF default pipe for HTC message exchange */
47180 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
47181 index 4716d33..a688310 100644
47182 --- a/drivers/net/wireless/ath/ath10k/htc.h
47183 +++ b/drivers/net/wireless/ath/ath10k/htc.h
47184 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
47185
47186 struct ath10k_htc_ops {
47187 void (*target_send_suspend_complete)(struct ath10k *ar);
47188 -};
47189 +} __no_const;
47190
47191 struct ath10k_htc_ep_ops {
47192 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
47193 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
47194 void (*ep_tx_credits)(struct ath10k *);
47195 -};
47196 +} __no_const;
47197
47198 /* service connection information */
47199 struct ath10k_htc_svc_conn_req {
47200 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47201 index 741b38d..b7ae41b 100644
47202 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47203 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47204 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47205 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
47206 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
47207
47208 - ACCESS_ONCE(ads->ds_link) = i->link;
47209 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
47210 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
47211 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
47212
47213 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
47214 ctl6 = SM(i->keytype, AR_EncrType);
47215 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47216
47217 if ((i->is_first || i->is_last) &&
47218 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
47219 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
47220 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
47221 | set11nTries(i->rates, 1)
47222 | set11nTries(i->rates, 2)
47223 | set11nTries(i->rates, 3)
47224 | (i->dur_update ? AR_DurUpdateEna : 0)
47225 | SM(0, AR_BurstDur);
47226
47227 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
47228 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
47229 | set11nRate(i->rates, 1)
47230 | set11nRate(i->rates, 2)
47231 | set11nRate(i->rates, 3);
47232 } else {
47233 - ACCESS_ONCE(ads->ds_ctl2) = 0;
47234 - ACCESS_ONCE(ads->ds_ctl3) = 0;
47235 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
47236 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
47237 }
47238
47239 if (!i->is_first) {
47240 - ACCESS_ONCE(ads->ds_ctl0) = 0;
47241 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47242 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47243 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
47244 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47245 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47246 return;
47247 }
47248
47249 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47250 break;
47251 }
47252
47253 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47254 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47255 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47256 | SM(i->txpower, AR_XmitPower)
47257 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47258 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47259 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
47260 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
47261
47262 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47263 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47264 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47265 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47266
47267 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
47268 return;
47269
47270 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47271 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47272 | set11nPktDurRTSCTS(i->rates, 1);
47273
47274 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47275 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47276 | set11nPktDurRTSCTS(i->rates, 3);
47277
47278 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47279 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47280 | set11nRateFlags(i->rates, 1)
47281 | set11nRateFlags(i->rates, 2)
47282 | set11nRateFlags(i->rates, 3)
47283 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47284 index 729ffbf..49f50e3 100644
47285 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47286 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47287 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47288 (i->qcu << AR_TxQcuNum_S) | desc_len;
47289
47290 checksum += val;
47291 - ACCESS_ONCE(ads->info) = val;
47292 + ACCESS_ONCE_RW(ads->info) = val;
47293
47294 checksum += i->link;
47295 - ACCESS_ONCE(ads->link) = i->link;
47296 + ACCESS_ONCE_RW(ads->link) = i->link;
47297
47298 checksum += i->buf_addr[0];
47299 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
47300 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
47301 checksum += i->buf_addr[1];
47302 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
47303 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
47304 checksum += i->buf_addr[2];
47305 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
47306 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
47307 checksum += i->buf_addr[3];
47308 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
47309 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
47310
47311 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
47312 - ACCESS_ONCE(ads->ctl3) = val;
47313 + ACCESS_ONCE_RW(ads->ctl3) = val;
47314 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
47315 - ACCESS_ONCE(ads->ctl5) = val;
47316 + ACCESS_ONCE_RW(ads->ctl5) = val;
47317 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
47318 - ACCESS_ONCE(ads->ctl7) = val;
47319 + ACCESS_ONCE_RW(ads->ctl7) = val;
47320 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
47321 - ACCESS_ONCE(ads->ctl9) = val;
47322 + ACCESS_ONCE_RW(ads->ctl9) = val;
47323
47324 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
47325 - ACCESS_ONCE(ads->ctl10) = checksum;
47326 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
47327
47328 if (i->is_first || i->is_last) {
47329 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
47330 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
47331 | set11nTries(i->rates, 1)
47332 | set11nTries(i->rates, 2)
47333 | set11nTries(i->rates, 3)
47334 | (i->dur_update ? AR_DurUpdateEna : 0)
47335 | SM(0, AR_BurstDur);
47336
47337 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47338 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47339 | set11nRate(i->rates, 1)
47340 | set11nRate(i->rates, 2)
47341 | set11nRate(i->rates, 3);
47342 } else {
47343 - ACCESS_ONCE(ads->ctl13) = 0;
47344 - ACCESS_ONCE(ads->ctl14) = 0;
47345 + ACCESS_ONCE_RW(ads->ctl13) = 0;
47346 + ACCESS_ONCE_RW(ads->ctl14) = 0;
47347 }
47348
47349 ads->ctl20 = 0;
47350 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47351
47352 ctl17 = SM(i->keytype, AR_EncrType);
47353 if (!i->is_first) {
47354 - ACCESS_ONCE(ads->ctl11) = 0;
47355 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47356 - ACCESS_ONCE(ads->ctl15) = 0;
47357 - ACCESS_ONCE(ads->ctl16) = 0;
47358 - ACCESS_ONCE(ads->ctl17) = ctl17;
47359 - ACCESS_ONCE(ads->ctl18) = 0;
47360 - ACCESS_ONCE(ads->ctl19) = 0;
47361 + ACCESS_ONCE_RW(ads->ctl11) = 0;
47362 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47363 + ACCESS_ONCE_RW(ads->ctl15) = 0;
47364 + ACCESS_ONCE_RW(ads->ctl16) = 0;
47365 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47366 + ACCESS_ONCE_RW(ads->ctl18) = 0;
47367 + ACCESS_ONCE_RW(ads->ctl19) = 0;
47368 return;
47369 }
47370
47371 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47372 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47373 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47374 | SM(i->txpower, AR_XmitPower)
47375 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47376 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47377 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47378 ctl12 |= SM(val, AR_PAPRDChainMask);
47379
47380 - ACCESS_ONCE(ads->ctl12) = ctl12;
47381 - ACCESS_ONCE(ads->ctl17) = ctl17;
47382 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47383 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47384
47385 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47386 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47387 | set11nPktDurRTSCTS(i->rates, 1);
47388
47389 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47390 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47391 | set11nPktDurRTSCTS(i->rates, 3);
47392
47393 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47394 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47395 | set11nRateFlags(i->rates, 1)
47396 | set11nRateFlags(i->rates, 2)
47397 | set11nRateFlags(i->rates, 3)
47398 | SM(i->rtscts_rate, AR_RTSCTSRate);
47399
47400 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47401 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47402 }
47403
47404 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47405 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47406 index 0acd4b5..0591c91 100644
47407 --- a/drivers/net/wireless/ath/ath9k/hw.h
47408 +++ b/drivers/net/wireless/ath/ath9k/hw.h
47409 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47410
47411 /* ANI */
47412 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47413 -};
47414 +} __no_const;
47415
47416 /**
47417 * struct ath_spec_scan - parameters for Atheros spectral scan
47418 @@ -706,7 +706,7 @@ struct ath_hw_ops {
47419 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47420 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47421 #endif
47422 -};
47423 +} __no_const;
47424
47425 struct ath_nf_limits {
47426 s16 max;
47427 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47428 index 92190da..f3a4c4c 100644
47429 --- a/drivers/net/wireless/b43/phy_lp.c
47430 +++ b/drivers/net/wireless/b43/phy_lp.c
47431 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47432 {
47433 struct ssb_bus *bus = dev->dev->sdev->bus;
47434
47435 - static const struct b206x_channel *chandata = NULL;
47436 + const struct b206x_channel *chandata = NULL;
47437 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47438 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47439 u16 old_comm15, scale;
47440 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47441 index 0487461..fd9e84a 100644
47442 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
47443 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47444 @@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47445 */
47446 if (il3945_mod_params.disable_hw_scan) {
47447 D_INFO("Disabling hw_scan\n");
47448 - il3945_mac_ops.hw_scan = NULL;
47449 + pax_open_kernel();
47450 + *(void **)&il3945_mac_ops.hw_scan = NULL;
47451 + pax_close_kernel();
47452 }
47453
47454 D_INFO("*** LOAD DRIVER ***\n");
47455 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47456 index d2fe259..0c4c682 100644
47457 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47458 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47459 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47460 {
47461 struct iwl_priv *priv = file->private_data;
47462 char buf[64];
47463 - int buf_size;
47464 + size_t buf_size;
47465 u32 offset, len;
47466
47467 memset(buf, 0, sizeof(buf));
47468 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47469 struct iwl_priv *priv = file->private_data;
47470
47471 char buf[8];
47472 - int buf_size;
47473 + size_t buf_size;
47474 u32 reset_flag;
47475
47476 memset(buf, 0, sizeof(buf));
47477 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47478 {
47479 struct iwl_priv *priv = file->private_data;
47480 char buf[8];
47481 - int buf_size;
47482 + size_t buf_size;
47483 int ht40;
47484
47485 memset(buf, 0, sizeof(buf));
47486 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47487 {
47488 struct iwl_priv *priv = file->private_data;
47489 char buf[8];
47490 - int buf_size;
47491 + size_t buf_size;
47492 int value;
47493
47494 memset(buf, 0, sizeof(buf));
47495 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47496 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47497 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47498
47499 -static const char *fmt_value = " %-30s %10u\n";
47500 -static const char *fmt_hex = " %-30s 0x%02X\n";
47501 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47502 -static const char *fmt_header =
47503 +static const char fmt_value[] = " %-30s %10u\n";
47504 +static const char fmt_hex[] = " %-30s 0x%02X\n";
47505 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47506 +static const char fmt_header[] =
47507 "%-32s current cumulative delta max\n";
47508
47509 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47510 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47511 {
47512 struct iwl_priv *priv = file->private_data;
47513 char buf[8];
47514 - int buf_size;
47515 + size_t buf_size;
47516 int clear;
47517
47518 memset(buf, 0, sizeof(buf));
47519 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47520 {
47521 struct iwl_priv *priv = file->private_data;
47522 char buf[8];
47523 - int buf_size;
47524 + size_t buf_size;
47525 int trace;
47526
47527 memset(buf, 0, sizeof(buf));
47528 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47529 {
47530 struct iwl_priv *priv = file->private_data;
47531 char buf[8];
47532 - int buf_size;
47533 + size_t buf_size;
47534 int missed;
47535
47536 memset(buf, 0, sizeof(buf));
47537 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47538
47539 struct iwl_priv *priv = file->private_data;
47540 char buf[8];
47541 - int buf_size;
47542 + size_t buf_size;
47543 int plcp;
47544
47545 memset(buf, 0, sizeof(buf));
47546 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47547
47548 struct iwl_priv *priv = file->private_data;
47549 char buf[8];
47550 - int buf_size;
47551 + size_t buf_size;
47552 int flush;
47553
47554 memset(buf, 0, sizeof(buf));
47555 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47556
47557 struct iwl_priv *priv = file->private_data;
47558 char buf[8];
47559 - int buf_size;
47560 + size_t buf_size;
47561 int rts;
47562
47563 if (!priv->cfg->ht_params)
47564 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47565 {
47566 struct iwl_priv *priv = file->private_data;
47567 char buf[8];
47568 - int buf_size;
47569 + size_t buf_size;
47570
47571 memset(buf, 0, sizeof(buf));
47572 buf_size = min(count, sizeof(buf) - 1);
47573 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47574 struct iwl_priv *priv = file->private_data;
47575 u32 event_log_flag;
47576 char buf[8];
47577 - int buf_size;
47578 + size_t buf_size;
47579
47580 /* check that the interface is up */
47581 if (!iwl_is_ready(priv))
47582 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47583 struct iwl_priv *priv = file->private_data;
47584 char buf[8];
47585 u32 calib_disabled;
47586 - int buf_size;
47587 + size_t buf_size;
47588
47589 memset(buf, 0, sizeof(buf));
47590 buf_size = min(count, sizeof(buf) - 1);
47591 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47592 index ea7e70c..bc0c45f 100644
47593 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
47594 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47595 @@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47596 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47597 {
47598 struct iwl_nvm_data *data = priv->nvm_data;
47599 - char *debug_msg;
47600 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47601
47602 if (data->sku_cap_11n_enable &&
47603 !priv->cfg->ht_params) {
47604 @@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47605 return -EINVAL;
47606 }
47607
47608 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47609 IWL_DEBUG_INFO(priv, debug_msg,
47610 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47611 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47612 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47613 index f950780..be9df93 100644
47614 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47615 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47616 @@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47617 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47618
47619 char buf[8];
47620 - int buf_size;
47621 + size_t buf_size;
47622 u32 reset_flag;
47623
47624 memset(buf, 0, sizeof(buf));
47625 @@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47626 {
47627 struct iwl_trans *trans = file->private_data;
47628 char buf[8];
47629 - int buf_size;
47630 + size_t buf_size;
47631 int csr;
47632
47633 memset(buf, 0, sizeof(buf));
47634 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47635 index 69d4c31..bd0b316 100644
47636 --- a/drivers/net/wireless/mac80211_hwsim.c
47637 +++ b/drivers/net/wireless/mac80211_hwsim.c
47638 @@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
47639 if (channels < 1)
47640 return -EINVAL;
47641
47642 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47643 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47644 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47645 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47646 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47647 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47648 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47649 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47650 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47651 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47652 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47653 - mac80211_hwsim_assign_vif_chanctx;
47654 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47655 - mac80211_hwsim_unassign_vif_chanctx;
47656 + pax_open_kernel();
47657 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47658 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47659 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47660 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47661 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47662 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47663 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47664 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47665 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47666 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47667 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47668 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47669 + pax_close_kernel();
47670
47671 spin_lock_init(&hwsim_radio_lock);
47672 INIT_LIST_HEAD(&hwsim_radios);
47673 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47674 index 5028557..91cf394 100644
47675 --- a/drivers/net/wireless/rndis_wlan.c
47676 +++ b/drivers/net/wireless/rndis_wlan.c
47677 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47678
47679 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47680
47681 - if (rts_threshold < 0 || rts_threshold > 2347)
47682 + if (rts_threshold > 2347)
47683 rts_threshold = 2347;
47684
47685 tmp = cpu_to_le32(rts_threshold);
47686 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47687 index e3b885d..7a7de2f 100644
47688 --- a/drivers/net/wireless/rt2x00/rt2x00.h
47689 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47690 @@ -375,7 +375,7 @@ struct rt2x00_intf {
47691 * for hardware which doesn't support hardware
47692 * sequence counting.
47693 */
47694 - atomic_t seqno;
47695 + atomic_unchecked_t seqno;
47696 };
47697
47698 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47699 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47700 index 5642ccc..01f03eb 100644
47701 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47702 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47703 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47704 * sequence counter given by mac80211.
47705 */
47706 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47707 - seqno = atomic_add_return(0x10, &intf->seqno);
47708 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47709 else
47710 - seqno = atomic_read(&intf->seqno);
47711 + seqno = atomic_read_unchecked(&intf->seqno);
47712
47713 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47714 hdr->seq_ctrl |= cpu_to_le16(seqno);
47715 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47716 index e2b3d9c..67a5184 100644
47717 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47718 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47719 @@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47720
47721 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47722
47723 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47724 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47725 + pax_open_kernel();
47726 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47727 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47728 + pax_close_kernel();
47729
47730 wl1251_info("using dedicated interrupt line");
47731 } else {
47732 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47733 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47734 + pax_open_kernel();
47735 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47736 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47737 + pax_close_kernel();
47738
47739 wl1251_info("using SDIO interrupt");
47740 }
47741 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47742 index be7129b..4161356 100644
47743 --- a/drivers/net/wireless/ti/wl12xx/main.c
47744 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47745 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47746 sizeof(wl->conf.mem));
47747
47748 /* read data preparation is only needed by wl127x */
47749 - wl->ops->prepare_read = wl127x_prepare_read;
47750 + pax_open_kernel();
47751 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47752 + pax_close_kernel();
47753
47754 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47755 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47756 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47757 sizeof(wl->conf.mem));
47758
47759 /* read data preparation is only needed by wl127x */
47760 - wl->ops->prepare_read = wl127x_prepare_read;
47761 + pax_open_kernel();
47762 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47763 + pax_close_kernel();
47764
47765 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47766 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47767 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47768 index ec37b16..7e34d66 100644
47769 --- a/drivers/net/wireless/ti/wl18xx/main.c
47770 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47771 @@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47772 }
47773
47774 if (!checksum_param) {
47775 - wl18xx_ops.set_rx_csum = NULL;
47776 - wl18xx_ops.init_vif = NULL;
47777 + pax_open_kernel();
47778 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47779 + *(void **)&wl18xx_ops.init_vif = NULL;
47780 + pax_close_kernel();
47781 }
47782
47783 /* Enable 11a Band only if we have 5G antennas */
47784 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47785 index a912dc0..a8225ba 100644
47786 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47787 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47788 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47789 {
47790 struct zd_usb *usb = urb->context;
47791 struct zd_usb_interrupt *intr = &usb->intr;
47792 - int len;
47793 + unsigned int len;
47794 u16 int_num;
47795
47796 ZD_ASSERT(in_interrupt());
47797 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47798 index 683671a..4519fc2 100644
47799 --- a/drivers/nfc/nfcwilink.c
47800 +++ b/drivers/nfc/nfcwilink.c
47801 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47802
47803 static int nfcwilink_probe(struct platform_device *pdev)
47804 {
47805 - static struct nfcwilink *drv;
47806 + struct nfcwilink *drv;
47807 int rc;
47808 __u32 protocols;
47809
47810 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47811 index d93b2b6..ae50401 100644
47812 --- a/drivers/oprofile/buffer_sync.c
47813 +++ b/drivers/oprofile/buffer_sync.c
47814 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47815 if (cookie == NO_COOKIE)
47816 offset = pc;
47817 if (cookie == INVALID_COOKIE) {
47818 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47819 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47820 offset = pc;
47821 }
47822 if (cookie != last_cookie) {
47823 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47824 /* add userspace sample */
47825
47826 if (!mm) {
47827 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47828 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47829 return 0;
47830 }
47831
47832 cookie = lookup_dcookie(mm, s->eip, &offset);
47833
47834 if (cookie == INVALID_COOKIE) {
47835 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47836 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47837 return 0;
47838 }
47839
47840 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47841 /* ignore backtraces if failed to add a sample */
47842 if (state == sb_bt_start) {
47843 state = sb_bt_ignore;
47844 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47845 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47846 }
47847 }
47848 release_mm(mm);
47849 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47850 index c0cc4e7..44d4e54 100644
47851 --- a/drivers/oprofile/event_buffer.c
47852 +++ b/drivers/oprofile/event_buffer.c
47853 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47854 }
47855
47856 if (buffer_pos == buffer_size) {
47857 - atomic_inc(&oprofile_stats.event_lost_overflow);
47858 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47859 return;
47860 }
47861
47862 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47863 index ed2c3ec..deda85a 100644
47864 --- a/drivers/oprofile/oprof.c
47865 +++ b/drivers/oprofile/oprof.c
47866 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47867 if (oprofile_ops.switch_events())
47868 return;
47869
47870 - atomic_inc(&oprofile_stats.multiplex_counter);
47871 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47872 start_switch_worker();
47873 }
47874
47875 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47876 index ee2cfce..7f8f699 100644
47877 --- a/drivers/oprofile/oprofile_files.c
47878 +++ b/drivers/oprofile/oprofile_files.c
47879 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47880
47881 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47882
47883 -static ssize_t timeout_read(struct file *file, char __user *buf,
47884 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47885 size_t count, loff_t *offset)
47886 {
47887 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47888 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47889 index 59659ce..6c860a0 100644
47890 --- a/drivers/oprofile/oprofile_stats.c
47891 +++ b/drivers/oprofile/oprofile_stats.c
47892 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47893 cpu_buf->sample_invalid_eip = 0;
47894 }
47895
47896 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47897 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47898 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47899 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47900 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47901 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47902 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47903 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47904 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47905 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47906 }
47907
47908
47909 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47910 index 1fc622b..8c48fc3 100644
47911 --- a/drivers/oprofile/oprofile_stats.h
47912 +++ b/drivers/oprofile/oprofile_stats.h
47913 @@ -13,11 +13,11 @@
47914 #include <linux/atomic.h>
47915
47916 struct oprofile_stat_struct {
47917 - atomic_t sample_lost_no_mm;
47918 - atomic_t sample_lost_no_mapping;
47919 - atomic_t bt_lost_no_mapping;
47920 - atomic_t event_lost_overflow;
47921 - atomic_t multiplex_counter;
47922 + atomic_unchecked_t sample_lost_no_mm;
47923 + atomic_unchecked_t sample_lost_no_mapping;
47924 + atomic_unchecked_t bt_lost_no_mapping;
47925 + atomic_unchecked_t event_lost_overflow;
47926 + atomic_unchecked_t multiplex_counter;
47927 };
47928
47929 extern struct oprofile_stat_struct oprofile_stats;
47930 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47931 index 3f49345..c750d0b 100644
47932 --- a/drivers/oprofile/oprofilefs.c
47933 +++ b/drivers/oprofile/oprofilefs.c
47934 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47935
47936 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47937 {
47938 - atomic_t *val = file->private_data;
47939 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47940 + atomic_unchecked_t *val = file->private_data;
47941 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47942 }
47943
47944
47945 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47946
47947
47948 int oprofilefs_create_ro_atomic(struct dentry *root,
47949 - char const *name, atomic_t *val)
47950 + char const *name, atomic_unchecked_t *val)
47951 {
47952 return __oprofilefs_create_file(root, name,
47953 &atomic_ro_fops, 0444, val);
47954 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47955 index 61be1d9..dec05d7 100644
47956 --- a/drivers/oprofile/timer_int.c
47957 +++ b/drivers/oprofile/timer_int.c
47958 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47959 return NOTIFY_OK;
47960 }
47961
47962 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47963 +static struct notifier_block oprofile_cpu_notifier = {
47964 .notifier_call = oprofile_cpu_notify,
47965 };
47966
47967 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47968 index 92ed045..62d39bd7 100644
47969 --- a/drivers/parport/procfs.c
47970 +++ b/drivers/parport/procfs.c
47971 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47972
47973 *ppos += len;
47974
47975 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47976 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47977 }
47978
47979 #ifdef CONFIG_PARPORT_1284
47980 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47981
47982 *ppos += len;
47983
47984 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47985 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47986 }
47987 #endif /* IEEE1284.3 support. */
47988
47989 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47990 index 8dcccff..35d701d 100644
47991 --- a/drivers/pci/hotplug/acpiphp_ibm.c
47992 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
47993 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47994 goto init_cleanup;
47995 }
47996
47997 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47998 + pax_open_kernel();
47999 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
48000 + pax_close_kernel();
48001 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
48002
48003 return retval;
48004 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
48005 index 7536eef..52dc8fa 100644
48006 --- a/drivers/pci/hotplug/cpcihp_generic.c
48007 +++ b/drivers/pci/hotplug/cpcihp_generic.c
48008 @@ -73,7 +73,6 @@ static u16 port;
48009 static unsigned int enum_bit;
48010 static u8 enum_mask;
48011
48012 -static struct cpci_hp_controller_ops generic_hpc_ops;
48013 static struct cpci_hp_controller generic_hpc;
48014
48015 static int __init validate_parameters(void)
48016 @@ -139,6 +138,10 @@ static int query_enum(void)
48017 return ((value & enum_mask) == enum_mask);
48018 }
48019
48020 +static struct cpci_hp_controller_ops generic_hpc_ops = {
48021 + .query_enum = query_enum,
48022 +};
48023 +
48024 static int __init cpcihp_generic_init(void)
48025 {
48026 int status;
48027 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
48028 pci_dev_put(dev);
48029
48030 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
48031 - generic_hpc_ops.query_enum = query_enum;
48032 generic_hpc.ops = &generic_hpc_ops;
48033
48034 status = cpci_hp_register_controller(&generic_hpc);
48035 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
48036 index e8c4a7c..7046f5c 100644
48037 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
48038 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
48039 @@ -59,7 +59,6 @@
48040 /* local variables */
48041 static bool debug;
48042 static bool poll;
48043 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
48044 static struct cpci_hp_controller zt5550_hpc;
48045
48046 /* Primary cPCI bus bridge device */
48047 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
48048 return 0;
48049 }
48050
48051 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
48052 + .query_enum = zt5550_hc_query_enum,
48053 +};
48054 +
48055 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
48056 {
48057 int status;
48058 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
48059 dbg("returned from zt5550_hc_config");
48060
48061 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
48062 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
48063 zt5550_hpc.ops = &zt5550_hpc_ops;
48064 if(!poll) {
48065 zt5550_hpc.irq = hc_dev->irq;
48066 zt5550_hpc.irq_flags = IRQF_SHARED;
48067 zt5550_hpc.dev_id = hc_dev;
48068
48069 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48070 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48071 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48072 + pax_open_kernel();
48073 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48074 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48075 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48076 + pax_open_kernel();
48077 } else {
48078 info("using ENUM# polling mode");
48079 }
48080 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
48081 index 76ba8a1..20ca857 100644
48082 --- a/drivers/pci/hotplug/cpqphp_nvram.c
48083 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
48084 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
48085
48086 void compaq_nvram_init (void __iomem *rom_start)
48087 {
48088 +
48089 +#ifndef CONFIG_PAX_KERNEXEC
48090 if (rom_start) {
48091 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
48092 }
48093 +#endif
48094 +
48095 dbg("int15 entry = %p\n", compaq_int15_entry_point);
48096
48097 /* initialize our int15 lock */
48098 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
48099 index cfa92a9..29539c5 100644
48100 --- a/drivers/pci/hotplug/pci_hotplug_core.c
48101 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
48102 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
48103 return -EINVAL;
48104 }
48105
48106 - slot->ops->owner = owner;
48107 - slot->ops->mod_name = mod_name;
48108 + pax_open_kernel();
48109 + *(struct module **)&slot->ops->owner = owner;
48110 + *(const char **)&slot->ops->mod_name = mod_name;
48111 + pax_close_kernel();
48112
48113 mutex_lock(&pci_hp_mutex);
48114 /*
48115 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
48116 index 53b58de..4479896 100644
48117 --- a/drivers/pci/hotplug/pciehp_core.c
48118 +++ b/drivers/pci/hotplug/pciehp_core.c
48119 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
48120 struct slot *slot = ctrl->slot;
48121 struct hotplug_slot *hotplug = NULL;
48122 struct hotplug_slot_info *info = NULL;
48123 - struct hotplug_slot_ops *ops = NULL;
48124 + hotplug_slot_ops_no_const *ops = NULL;
48125 char name[SLOT_NAME_SIZE];
48126 int retval = -ENOMEM;
48127
48128 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
48129 index 955ab79..d1df9c7 100644
48130 --- a/drivers/pci/msi.c
48131 +++ b/drivers/pci/msi.c
48132 @@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
48133 {
48134 struct attribute **msi_attrs;
48135 struct attribute *msi_attr;
48136 - struct device_attribute *msi_dev_attr;
48137 - struct attribute_group *msi_irq_group;
48138 + device_attribute_no_const *msi_dev_attr;
48139 + attribute_group_no_const *msi_irq_group;
48140 const struct attribute_group **msi_irq_groups;
48141 struct msi_desc *entry;
48142 int ret = -ENOMEM;
48143 @@ -589,7 +589,7 @@ error_attrs:
48144 count = 0;
48145 msi_attr = msi_attrs[count];
48146 while (msi_attr) {
48147 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
48148 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
48149 kfree(msi_attr->name);
48150 kfree(msi_dev_attr);
48151 ++count;
48152 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
48153 index 276ef9c..1d33a36 100644
48154 --- a/drivers/pci/pci-sysfs.c
48155 +++ b/drivers/pci/pci-sysfs.c
48156 @@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
48157 {
48158 /* allocate attribute structure, piggyback attribute name */
48159 int name_len = write_combine ? 13 : 10;
48160 - struct bin_attribute *res_attr;
48161 + bin_attribute_no_const *res_attr;
48162 int retval;
48163
48164 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
48165 @@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
48166 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
48167 {
48168 int retval;
48169 - struct bin_attribute *attr;
48170 + bin_attribute_no_const *attr;
48171
48172 /* If the device has VPD, try to expose it in sysfs. */
48173 if (dev->vpd) {
48174 @@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
48175 {
48176 int retval;
48177 int rom_size = 0;
48178 - struct bin_attribute *attr;
48179 + bin_attribute_no_const *attr;
48180
48181 if (!sysfs_initialized)
48182 return -EACCES;
48183 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
48184 index 4df38df..b6bb7fe 100644
48185 --- a/drivers/pci/pci.h
48186 +++ b/drivers/pci/pci.h
48187 @@ -93,7 +93,7 @@ struct pci_vpd_ops {
48188 struct pci_vpd {
48189 unsigned int len;
48190 const struct pci_vpd_ops *ops;
48191 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
48192 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
48193 };
48194
48195 int pci_vpd_pci22_init(struct pci_dev *dev);
48196 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
48197 index e1e7026..d28dd33 100644
48198 --- a/drivers/pci/pcie/aspm.c
48199 +++ b/drivers/pci/pcie/aspm.c
48200 @@ -27,9 +27,9 @@
48201 #define MODULE_PARAM_PREFIX "pcie_aspm."
48202
48203 /* Note: those are not register definitions */
48204 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
48205 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
48206 -#define ASPM_STATE_L1 (4) /* L1 state */
48207 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
48208 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
48209 +#define ASPM_STATE_L1 (4U) /* L1 state */
48210 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
48211 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
48212
48213 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
48214 index 6e34498..9911975 100644
48215 --- a/drivers/pci/probe.c
48216 +++ b/drivers/pci/probe.c
48217 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
48218 struct pci_bus_region region, inverted_region;
48219 bool bar_too_big = false, bar_disabled = false;
48220
48221 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
48222 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
48223
48224 /* No printks while decoding is disabled! */
48225 if (!dev->mmio_always_on) {
48226 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
48227 index 46d1378..30e452b 100644
48228 --- a/drivers/pci/proc.c
48229 +++ b/drivers/pci/proc.c
48230 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
48231 static int __init pci_proc_init(void)
48232 {
48233 struct pci_dev *dev = NULL;
48234 +
48235 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48236 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48237 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
48238 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48239 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48240 +#endif
48241 +#else
48242 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
48243 +#endif
48244 proc_create("devices", 0, proc_bus_pci_dir,
48245 &proc_bus_pci_dev_operations);
48246 proc_initialized = 1;
48247 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
48248 index 7f3aad0..7d604bb 100644
48249 --- a/drivers/platform/chrome/chromeos_laptop.c
48250 +++ b/drivers/platform/chrome/chromeos_laptop.c
48251 @@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
48252 .callback = chromeos_laptop_dmi_matched, \
48253 .driver_data = (void *)&board_
48254
48255 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
48256 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
48257 {
48258 .ident = "Samsung Series 5 550",
48259 .matches = {
48260 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
48261 index c5e082f..d6307a0 100644
48262 --- a/drivers/platform/x86/asus-wmi.c
48263 +++ b/drivers/platform/x86/asus-wmi.c
48264 @@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
48265 int err;
48266 u32 retval = -1;
48267
48268 +#ifdef CONFIG_GRKERNSEC_KMEM
48269 + return -EPERM;
48270 +#endif
48271 +
48272 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
48273
48274 if (err < 0)
48275 @@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
48276 int err;
48277 u32 retval = -1;
48278
48279 +#ifdef CONFIG_GRKERNSEC_KMEM
48280 + return -EPERM;
48281 +#endif
48282 +
48283 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
48284 &retval);
48285
48286 @@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
48287 union acpi_object *obj;
48288 acpi_status status;
48289
48290 +#ifdef CONFIG_GRKERNSEC_KMEM
48291 + return -EPERM;
48292 +#endif
48293 +
48294 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
48295 1, asus->debug.method_id,
48296 &input, &output);
48297 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
48298 index 62f8030..c7f2a45 100644
48299 --- a/drivers/platform/x86/msi-laptop.c
48300 +++ b/drivers/platform/x86/msi-laptop.c
48301 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
48302
48303 if (!quirks->ec_read_only) {
48304 /* allow userland write sysfs file */
48305 - dev_attr_bluetooth.store = store_bluetooth;
48306 - dev_attr_wlan.store = store_wlan;
48307 - dev_attr_threeg.store = store_threeg;
48308 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
48309 - dev_attr_wlan.attr.mode |= S_IWUSR;
48310 - dev_attr_threeg.attr.mode |= S_IWUSR;
48311 + pax_open_kernel();
48312 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48313 + *(void **)&dev_attr_wlan.store = store_wlan;
48314 + *(void **)&dev_attr_threeg.store = store_threeg;
48315 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48316 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48317 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48318 + pax_close_kernel();
48319 }
48320
48321 /* disable hardware control by fn key */
48322 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48323 index 70222f2..8c8ce66 100644
48324 --- a/drivers/platform/x86/msi-wmi.c
48325 +++ b/drivers/platform/x86/msi-wmi.c
48326 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48327 static void msi_wmi_notify(u32 value, void *context)
48328 {
48329 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48330 - static struct key_entry *key;
48331 + struct key_entry *key;
48332 union acpi_object *obj;
48333 acpi_status status;
48334
48335 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48336 index 8f8551a..3ace3ca 100644
48337 --- a/drivers/platform/x86/sony-laptop.c
48338 +++ b/drivers/platform/x86/sony-laptop.c
48339 @@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48340 }
48341
48342 /* High speed charging function */
48343 -static struct device_attribute *hsc_handle;
48344 +static device_attribute_no_const *hsc_handle;
48345
48346 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48347 struct device_attribute *attr,
48348 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48349 index e2a91c8..986cc9f 100644
48350 --- a/drivers/platform/x86/thinkpad_acpi.c
48351 +++ b/drivers/platform/x86/thinkpad_acpi.c
48352 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48353 return 0;
48354 }
48355
48356 -void static hotkey_mask_warn_incomplete_mask(void)
48357 +static void hotkey_mask_warn_incomplete_mask(void)
48358 {
48359 /* log only what the user can fix... */
48360 const u32 wantedmask = hotkey_driver_mask &
48361 @@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
48362 }
48363 }
48364
48365 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48366 - struct tp_nvram_state *newn,
48367 - const u32 event_mask)
48368 -{
48369 -
48370 #define TPACPI_COMPARE_KEY(__scancode, __member) \
48371 do { \
48372 if ((event_mask & (1 << __scancode)) && \
48373 @@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48374 tpacpi_hotkey_send_key(__scancode); \
48375 } while (0)
48376
48377 - void issue_volchange(const unsigned int oldvol,
48378 - const unsigned int newvol)
48379 - {
48380 - unsigned int i = oldvol;
48381 +static void issue_volchange(const unsigned int oldvol,
48382 + const unsigned int newvol,
48383 + const u32 event_mask)
48384 +{
48385 + unsigned int i = oldvol;
48386
48387 - while (i > newvol) {
48388 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48389 - i--;
48390 - }
48391 - while (i < newvol) {
48392 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48393 - i++;
48394 - }
48395 + while (i > newvol) {
48396 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48397 + i--;
48398 }
48399 + while (i < newvol) {
48400 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48401 + i++;
48402 + }
48403 +}
48404
48405 - void issue_brightnesschange(const unsigned int oldbrt,
48406 - const unsigned int newbrt)
48407 - {
48408 - unsigned int i = oldbrt;
48409 +static void issue_brightnesschange(const unsigned int oldbrt,
48410 + const unsigned int newbrt,
48411 + const u32 event_mask)
48412 +{
48413 + unsigned int i = oldbrt;
48414
48415 - while (i > newbrt) {
48416 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48417 - i--;
48418 - }
48419 - while (i < newbrt) {
48420 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48421 - i++;
48422 - }
48423 + while (i > newbrt) {
48424 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48425 + i--;
48426 + }
48427 + while (i < newbrt) {
48428 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48429 + i++;
48430 }
48431 +}
48432
48433 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48434 + struct tp_nvram_state *newn,
48435 + const u32 event_mask)
48436 +{
48437 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
48438 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
48439 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
48440 @@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48441 oldn->volume_level != newn->volume_level) {
48442 /* recently muted, or repeated mute keypress, or
48443 * multiple presses ending in mute */
48444 - issue_volchange(oldn->volume_level, newn->volume_level);
48445 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48446 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
48447 }
48448 } else {
48449 @@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48450 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48451 }
48452 if (oldn->volume_level != newn->volume_level) {
48453 - issue_volchange(oldn->volume_level, newn->volume_level);
48454 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48455 } else if (oldn->volume_toggle != newn->volume_toggle) {
48456 /* repeated vol up/down keypress at end of scale ? */
48457 if (newn->volume_level == 0)
48458 @@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48459 /* handle brightness */
48460 if (oldn->brightness_level != newn->brightness_level) {
48461 issue_brightnesschange(oldn->brightness_level,
48462 - newn->brightness_level);
48463 + newn->brightness_level,
48464 + event_mask);
48465 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
48466 /* repeated key presses that didn't change state */
48467 if (newn->brightness_level == 0)
48468 @@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48469 && !tp_features.bright_unkfw)
48470 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48471 }
48472 +}
48473
48474 #undef TPACPI_COMPARE_KEY
48475 #undef TPACPI_MAY_SEND_KEY
48476 -}
48477
48478 /*
48479 * Polling driver
48480 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48481 index 769d265..a3a05ca 100644
48482 --- a/drivers/pnp/pnpbios/bioscalls.c
48483 +++ b/drivers/pnp/pnpbios/bioscalls.c
48484 @@ -58,7 +58,7 @@ do { \
48485 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48486 } while(0)
48487
48488 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48489 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48490 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48491
48492 /*
48493 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48494
48495 cpu = get_cpu();
48496 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48497 +
48498 + pax_open_kernel();
48499 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48500 + pax_close_kernel();
48501
48502 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48503 spin_lock_irqsave(&pnp_bios_lock, flags);
48504 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48505 :"memory");
48506 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48507
48508 + pax_open_kernel();
48509 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48510 + pax_close_kernel();
48511 +
48512 put_cpu();
48513
48514 /* If we get here and this is set then the PnP BIOS faulted on us. */
48515 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48516 return status;
48517 }
48518
48519 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
48520 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48521 {
48522 int i;
48523
48524 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48525 pnp_bios_callpoint.offset = header->fields.pm16offset;
48526 pnp_bios_callpoint.segment = PNP_CS16;
48527
48528 + pax_open_kernel();
48529 +
48530 for_each_possible_cpu(i) {
48531 struct desc_struct *gdt = get_cpu_gdt_table(i);
48532 if (!gdt)
48533 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48534 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48535 (unsigned long)__va(header->fields.pm16dseg));
48536 }
48537 +
48538 + pax_close_kernel();
48539 }
48540 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48541 index bacddd1..65ea100 100644
48542 --- a/drivers/pnp/resource.c
48543 +++ b/drivers/pnp/resource.c
48544 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48545 return 1;
48546
48547 /* check if the resource is valid */
48548 - if (*irq < 0 || *irq > 15)
48549 + if (*irq > 15)
48550 return 0;
48551
48552 /* check if the resource is reserved */
48553 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48554 return 1;
48555
48556 /* check if the resource is valid */
48557 - if (*dma < 0 || *dma == 4 || *dma > 7)
48558 + if (*dma == 4 || *dma > 7)
48559 return 0;
48560
48561 /* check if the resource is reserved */
48562 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48563 index 0c52e2a..3421ab7 100644
48564 --- a/drivers/power/pda_power.c
48565 +++ b/drivers/power/pda_power.c
48566 @@ -37,7 +37,11 @@ static int polling;
48567
48568 #if IS_ENABLED(CONFIG_USB_PHY)
48569 static struct usb_phy *transceiver;
48570 -static struct notifier_block otg_nb;
48571 +static int otg_handle_notification(struct notifier_block *nb,
48572 + unsigned long event, void *unused);
48573 +static struct notifier_block otg_nb = {
48574 + .notifier_call = otg_handle_notification
48575 +};
48576 #endif
48577
48578 static struct regulator *ac_draw;
48579 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48580
48581 #if IS_ENABLED(CONFIG_USB_PHY)
48582 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48583 - otg_nb.notifier_call = otg_handle_notification;
48584 ret = usb_register_notifier(transceiver, &otg_nb);
48585 if (ret) {
48586 dev_err(dev, "failure to register otg notifier\n");
48587 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48588 index cc439fd..8fa30df 100644
48589 --- a/drivers/power/power_supply.h
48590 +++ b/drivers/power/power_supply.h
48591 @@ -16,12 +16,12 @@ struct power_supply;
48592
48593 #ifdef CONFIG_SYSFS
48594
48595 -extern void power_supply_init_attrs(struct device_type *dev_type);
48596 +extern void power_supply_init_attrs(void);
48597 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48598
48599 #else
48600
48601 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48602 +static inline void power_supply_init_attrs(void) {}
48603 #define power_supply_uevent NULL
48604
48605 #endif /* CONFIG_SYSFS */
48606 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48607 index 2660664..75fcb04 100644
48608 --- a/drivers/power/power_supply_core.c
48609 +++ b/drivers/power/power_supply_core.c
48610 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48611 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48612 EXPORT_SYMBOL_GPL(power_supply_notifier);
48613
48614 -static struct device_type power_supply_dev_type;
48615 +extern const struct attribute_group *power_supply_attr_groups[];
48616 +static struct device_type power_supply_dev_type = {
48617 + .groups = power_supply_attr_groups,
48618 +};
48619
48620 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48621 struct power_supply *supply)
48622 @@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48623 return PTR_ERR(power_supply_class);
48624
48625 power_supply_class->dev_uevent = power_supply_uevent;
48626 - power_supply_init_attrs(&power_supply_dev_type);
48627 + power_supply_init_attrs();
48628
48629 return 0;
48630 }
48631 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48632 index 44420d1..967126e 100644
48633 --- a/drivers/power/power_supply_sysfs.c
48634 +++ b/drivers/power/power_supply_sysfs.c
48635 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48636 .is_visible = power_supply_attr_is_visible,
48637 };
48638
48639 -static const struct attribute_group *power_supply_attr_groups[] = {
48640 +const struct attribute_group *power_supply_attr_groups[] = {
48641 &power_supply_attr_group,
48642 NULL,
48643 };
48644
48645 -void power_supply_init_attrs(struct device_type *dev_type)
48646 +void power_supply_init_attrs(void)
48647 {
48648 int i;
48649
48650 - dev_type->groups = power_supply_attr_groups;
48651 -
48652 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48653 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48654 }
48655 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48656 index 84419af..268ede8 100644
48657 --- a/drivers/powercap/powercap_sys.c
48658 +++ b/drivers/powercap/powercap_sys.c
48659 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48660 struct device_attribute name_attr;
48661 };
48662
48663 +static ssize_t show_constraint_name(struct device *dev,
48664 + struct device_attribute *dev_attr,
48665 + char *buf);
48666 +
48667 static struct powercap_constraint_attr
48668 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48669 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48670 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48671 + .power_limit_attr = {
48672 + .attr = {
48673 + .name = NULL,
48674 + .mode = S_IWUSR | S_IRUGO
48675 + },
48676 + .show = show_constraint_power_limit_uw,
48677 + .store = store_constraint_power_limit_uw
48678 + },
48679 +
48680 + .time_window_attr = {
48681 + .attr = {
48682 + .name = NULL,
48683 + .mode = S_IWUSR | S_IRUGO
48684 + },
48685 + .show = show_constraint_time_window_us,
48686 + .store = store_constraint_time_window_us
48687 + },
48688 +
48689 + .max_power_attr = {
48690 + .attr = {
48691 + .name = NULL,
48692 + .mode = S_IRUGO
48693 + },
48694 + .show = show_constraint_max_power_uw,
48695 + .store = NULL
48696 + },
48697 +
48698 + .min_power_attr = {
48699 + .attr = {
48700 + .name = NULL,
48701 + .mode = S_IRUGO
48702 + },
48703 + .show = show_constraint_min_power_uw,
48704 + .store = NULL
48705 + },
48706 +
48707 + .max_time_window_attr = {
48708 + .attr = {
48709 + .name = NULL,
48710 + .mode = S_IRUGO
48711 + },
48712 + .show = show_constraint_max_time_window_us,
48713 + .store = NULL
48714 + },
48715 +
48716 + .min_time_window_attr = {
48717 + .attr = {
48718 + .name = NULL,
48719 + .mode = S_IRUGO
48720 + },
48721 + .show = show_constraint_min_time_window_us,
48722 + .store = NULL
48723 + },
48724 +
48725 + .name_attr = {
48726 + .attr = {
48727 + .name = NULL,
48728 + .mode = S_IRUGO
48729 + },
48730 + .show = show_constraint_name,
48731 + .store = NULL
48732 + }
48733 + }
48734 +};
48735
48736 /* A list of powercap control_types */
48737 static LIST_HEAD(powercap_cntrl_list);
48738 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48739 }
48740
48741 static int create_constraint_attribute(int id, const char *name,
48742 - int mode,
48743 - struct device_attribute *dev_attr,
48744 - ssize_t (*show)(struct device *,
48745 - struct device_attribute *, char *),
48746 - ssize_t (*store)(struct device *,
48747 - struct device_attribute *,
48748 - const char *, size_t)
48749 - )
48750 + struct device_attribute *dev_attr)
48751 {
48752 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48753
48754 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48755 - id, name);
48756 - if (!dev_attr->attr.name)
48757 + if (!name)
48758 return -ENOMEM;
48759 - dev_attr->attr.mode = mode;
48760 - dev_attr->show = show;
48761 - dev_attr->store = store;
48762 +
48763 + pax_open_kernel();
48764 + *(const char **)&dev_attr->attr.name = name;
48765 + pax_close_kernel();
48766
48767 return 0;
48768 }
48769 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48770
48771 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48772 ret = create_constraint_attribute(i, "power_limit_uw",
48773 - S_IWUSR | S_IRUGO,
48774 - &constraint_attrs[i].power_limit_attr,
48775 - show_constraint_power_limit_uw,
48776 - store_constraint_power_limit_uw);
48777 + &constraint_attrs[i].power_limit_attr);
48778 if (ret)
48779 goto err_alloc;
48780 ret = create_constraint_attribute(i, "time_window_us",
48781 - S_IWUSR | S_IRUGO,
48782 - &constraint_attrs[i].time_window_attr,
48783 - show_constraint_time_window_us,
48784 - store_constraint_time_window_us);
48785 + &constraint_attrs[i].time_window_attr);
48786 if (ret)
48787 goto err_alloc;
48788 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48789 - &constraint_attrs[i].name_attr,
48790 - show_constraint_name,
48791 - NULL);
48792 + ret = create_constraint_attribute(i, "name",
48793 + &constraint_attrs[i].name_attr);
48794 if (ret)
48795 goto err_alloc;
48796 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48797 - &constraint_attrs[i].max_power_attr,
48798 - show_constraint_max_power_uw,
48799 - NULL);
48800 + ret = create_constraint_attribute(i, "max_power_uw",
48801 + &constraint_attrs[i].max_power_attr);
48802 if (ret)
48803 goto err_alloc;
48804 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48805 - &constraint_attrs[i].min_power_attr,
48806 - show_constraint_min_power_uw,
48807 - NULL);
48808 + ret = create_constraint_attribute(i, "min_power_uw",
48809 + &constraint_attrs[i].min_power_attr);
48810 if (ret)
48811 goto err_alloc;
48812 ret = create_constraint_attribute(i, "max_time_window_us",
48813 - S_IRUGO,
48814 - &constraint_attrs[i].max_time_window_attr,
48815 - show_constraint_max_time_window_us,
48816 - NULL);
48817 + &constraint_attrs[i].max_time_window_attr);
48818 if (ret)
48819 goto err_alloc;
48820 ret = create_constraint_attribute(i, "min_time_window_us",
48821 - S_IRUGO,
48822 - &constraint_attrs[i].min_time_window_attr,
48823 - show_constraint_min_time_window_us,
48824 - NULL);
48825 + &constraint_attrs[i].min_time_window_attr);
48826 if (ret)
48827 goto err_alloc;
48828
48829 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48830 power_zone->zone_dev_attrs[count++] =
48831 &dev_attr_max_energy_range_uj.attr;
48832 if (power_zone->ops->get_energy_uj) {
48833 + pax_open_kernel();
48834 if (power_zone->ops->reset_energy_uj)
48835 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48836 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48837 else
48838 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48839 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48840 + pax_close_kernel();
48841 power_zone->zone_dev_attrs[count++] =
48842 &dev_attr_energy_uj.attr;
48843 }
48844 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48845 index afca1bc..86840b8 100644
48846 --- a/drivers/regulator/core.c
48847 +++ b/drivers/regulator/core.c
48848 @@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48849 {
48850 const struct regulation_constraints *constraints = NULL;
48851 const struct regulator_init_data *init_data;
48852 - static atomic_t regulator_no = ATOMIC_INIT(0);
48853 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48854 struct regulator_dev *rdev;
48855 struct device *dev;
48856 int ret, i;
48857 @@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48858 rdev->dev.of_node = config->of_node;
48859 rdev->dev.parent = dev;
48860 dev_set_name(&rdev->dev, "regulator.%d",
48861 - atomic_inc_return(&regulator_no) - 1);
48862 + atomic_inc_return_unchecked(&regulator_no) - 1);
48863 ret = device_register(&rdev->dev);
48864 if (ret != 0) {
48865 put_device(&rdev->dev);
48866 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48867 index 8d94d3d..653b623 100644
48868 --- a/drivers/regulator/max8660.c
48869 +++ b/drivers/regulator/max8660.c
48870 @@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48871 max8660->shadow_regs[MAX8660_OVER1] = 5;
48872 } else {
48873 /* Otherwise devices can be toggled via software */
48874 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48875 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48876 + pax_open_kernel();
48877 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48878 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48879 + pax_close_kernel();
48880 }
48881
48882 /*
48883 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48884 index 892aa1e..ebd1b9c 100644
48885 --- a/drivers/regulator/max8973-regulator.c
48886 +++ b/drivers/regulator/max8973-regulator.c
48887 @@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48888 if (!pdata || !pdata->enable_ext_control) {
48889 max->desc.enable_reg = MAX8973_VOUT;
48890 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48891 - max->ops.enable = regulator_enable_regmap;
48892 - max->ops.disable = regulator_disable_regmap;
48893 - max->ops.is_enabled = regulator_is_enabled_regmap;
48894 + pax_open_kernel();
48895 + *(void **)&max->ops.enable = regulator_enable_regmap;
48896 + *(void **)&max->ops.disable = regulator_disable_regmap;
48897 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48898 + pax_close_kernel();
48899 }
48900
48901 if (pdata) {
48902 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48903 index f374fa5..26f0683 100644
48904 --- a/drivers/regulator/mc13892-regulator.c
48905 +++ b/drivers/regulator/mc13892-regulator.c
48906 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48907 }
48908 mc13xxx_unlock(mc13892);
48909
48910 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48911 + pax_open_kernel();
48912 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48913 = mc13892_vcam_set_mode;
48914 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48915 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48916 = mc13892_vcam_get_mode;
48917 + pax_close_kernel();
48918
48919 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48920 ARRAY_SIZE(mc13892_regulators));
48921 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48922 index cae212f..58a3980 100644
48923 --- a/drivers/rtc/rtc-cmos.c
48924 +++ b/drivers/rtc/rtc-cmos.c
48925 @@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48926 hpet_rtc_timer_init();
48927
48928 /* export at least the first block of NVRAM */
48929 - nvram.size = address_space - NVRAM_OFFSET;
48930 + pax_open_kernel();
48931 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48932 + pax_close_kernel();
48933 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48934 if (retval < 0) {
48935 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48936 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48937 index d049393..bb20be0 100644
48938 --- a/drivers/rtc/rtc-dev.c
48939 +++ b/drivers/rtc/rtc-dev.c
48940 @@ -16,6 +16,7 @@
48941 #include <linux/module.h>
48942 #include <linux/rtc.h>
48943 #include <linux/sched.h>
48944 +#include <linux/grsecurity.h>
48945 #include "rtc-core.h"
48946
48947 static dev_t rtc_devt;
48948 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48949 if (copy_from_user(&tm, uarg, sizeof(tm)))
48950 return -EFAULT;
48951
48952 + gr_log_timechange();
48953 +
48954 return rtc_set_time(rtc, &tm);
48955
48956 case RTC_PIE_ON:
48957 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48958 index 4e75345..09f8663 100644
48959 --- a/drivers/rtc/rtc-ds1307.c
48960 +++ b/drivers/rtc/rtc-ds1307.c
48961 @@ -107,7 +107,7 @@ struct ds1307 {
48962 u8 offset; /* register's offset */
48963 u8 regs[11];
48964 u16 nvram_offset;
48965 - struct bin_attribute *nvram;
48966 + bin_attribute_no_const *nvram;
48967 enum ds_type type;
48968 unsigned long flags;
48969 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48970 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48971 index 11880c1..b823aa4 100644
48972 --- a/drivers/rtc/rtc-m48t59.c
48973 +++ b/drivers/rtc/rtc-m48t59.c
48974 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48975 if (IS_ERR(m48t59->rtc))
48976 return PTR_ERR(m48t59->rtc);
48977
48978 - m48t59_nvram_attr.size = pdata->offset;
48979 + pax_open_kernel();
48980 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48981 + pax_close_kernel();
48982
48983 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48984 if (ret)
48985 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48986 index 14b5f8d..cc9bd26 100644
48987 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48988 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48989 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48990 for (bit = 0; bit < 8; bit++) {
48991
48992 if ((pci_status[i] & (0x1 << bit)) != 0) {
48993 - static const char *s;
48994 + const char *s;
48995
48996 s = pci_status_strings[bit];
48997 if (i == 7/*TARG*/ && bit == 3)
48998 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48999
49000 for (bit = 0; bit < 8; bit++) {
49001
49002 - if ((split_status[i] & (0x1 << bit)) != 0) {
49003 - static const char *s;
49004 -
49005 - s = split_status_strings[bit];
49006 - printk(s, ahd_name(ahd),
49007 + if ((split_status[i] & (0x1 << bit)) != 0)
49008 + printk(split_status_strings[bit], ahd_name(ahd),
49009 split_status_source[i]);
49010 - }
49011
49012 if (i > 1)
49013 continue;
49014
49015 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
49016 - static const char *s;
49017 -
49018 - s = split_status_strings[bit];
49019 - printk(s, ahd_name(ahd), "SG");
49020 - }
49021 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
49022 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
49023 }
49024 }
49025 /*
49026 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
49027 index e693af6..2e525b6 100644
49028 --- a/drivers/scsi/bfa/bfa_fcpim.h
49029 +++ b/drivers/scsi/bfa/bfa_fcpim.h
49030 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
49031
49032 struct bfa_itn_s {
49033 bfa_isr_func_t isr;
49034 -};
49035 +} __no_const;
49036
49037 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
49038 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
49039 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
49040 index a3ab5cc..8143622 100644
49041 --- a/drivers/scsi/bfa/bfa_fcs.c
49042 +++ b/drivers/scsi/bfa/bfa_fcs.c
49043 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
49044 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
49045
49046 static struct bfa_fcs_mod_s fcs_modules[] = {
49047 - { bfa_fcs_port_attach, NULL, NULL },
49048 - { bfa_fcs_uf_attach, NULL, NULL },
49049 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
49050 - bfa_fcs_fabric_modexit },
49051 + {
49052 + .attach = bfa_fcs_port_attach,
49053 + .modinit = NULL,
49054 + .modexit = NULL
49055 + },
49056 + {
49057 + .attach = bfa_fcs_uf_attach,
49058 + .modinit = NULL,
49059 + .modexit = NULL
49060 + },
49061 + {
49062 + .attach = bfa_fcs_fabric_attach,
49063 + .modinit = bfa_fcs_fabric_modinit,
49064 + .modexit = bfa_fcs_fabric_modexit
49065 + },
49066 };
49067
49068 /*
49069 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
49070 index ff75ef8..2dfe00a 100644
49071 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
49072 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
49073 @@ -89,15 +89,26 @@ static struct {
49074 void (*offline) (struct bfa_fcs_lport_s *port);
49075 } __port_action[] = {
49076 {
49077 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
49078 - bfa_fcs_lport_unknown_offline}, {
49079 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
49080 - bfa_fcs_lport_fab_offline}, {
49081 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
49082 - bfa_fcs_lport_n2n_offline}, {
49083 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
49084 - bfa_fcs_lport_loop_offline},
49085 - };
49086 + .init = bfa_fcs_lport_unknown_init,
49087 + .online = bfa_fcs_lport_unknown_online,
49088 + .offline = bfa_fcs_lport_unknown_offline
49089 + },
49090 + {
49091 + .init = bfa_fcs_lport_fab_init,
49092 + .online = bfa_fcs_lport_fab_online,
49093 + .offline = bfa_fcs_lport_fab_offline
49094 + },
49095 + {
49096 + .init = bfa_fcs_lport_n2n_init,
49097 + .online = bfa_fcs_lport_n2n_online,
49098 + .offline = bfa_fcs_lport_n2n_offline
49099 + },
49100 + {
49101 + .init = bfa_fcs_lport_loop_init,
49102 + .online = bfa_fcs_lport_loop_online,
49103 + .offline = bfa_fcs_lport_loop_offline
49104 + },
49105 +};
49106
49107 /*
49108 * fcs_port_sm FCS logical port state machine
49109 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
49110 index 2e28392..9d865b6 100644
49111 --- a/drivers/scsi/bfa/bfa_ioc.h
49112 +++ b/drivers/scsi/bfa/bfa_ioc.h
49113 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
49114 bfa_ioc_disable_cbfn_t disable_cbfn;
49115 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
49116 bfa_ioc_reset_cbfn_t reset_cbfn;
49117 -};
49118 +} __no_const;
49119
49120 /*
49121 * IOC event notification mechanism.
49122 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
49123 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
49124 enum bfi_ioc_state fwstate);
49125 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
49126 -};
49127 +} __no_const;
49128
49129 /*
49130 * Queue element to wait for room in request queue. FIFO order is
49131 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
49132 index a14c784..6de6790 100644
49133 --- a/drivers/scsi/bfa/bfa_modules.h
49134 +++ b/drivers/scsi/bfa/bfa_modules.h
49135 @@ -78,12 +78,12 @@ enum {
49136 \
49137 extern struct bfa_module_s hal_mod_ ## __mod; \
49138 struct bfa_module_s hal_mod_ ## __mod = { \
49139 - bfa_ ## __mod ## _meminfo, \
49140 - bfa_ ## __mod ## _attach, \
49141 - bfa_ ## __mod ## _detach, \
49142 - bfa_ ## __mod ## _start, \
49143 - bfa_ ## __mod ## _stop, \
49144 - bfa_ ## __mod ## _iocdisable, \
49145 + .meminfo = bfa_ ## __mod ## _meminfo, \
49146 + .attach = bfa_ ## __mod ## _attach, \
49147 + .detach = bfa_ ## __mod ## _detach, \
49148 + .start = bfa_ ## __mod ## _start, \
49149 + .stop = bfa_ ## __mod ## _stop, \
49150 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
49151 }
49152
49153 #define BFA_CACHELINE_SZ (256)
49154 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
49155 index 045c4e1..13de803 100644
49156 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
49157 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
49158 @@ -33,8 +33,8 @@
49159 */
49160 #include "libfcoe.h"
49161
49162 -static atomic_t ctlr_num;
49163 -static atomic_t fcf_num;
49164 +static atomic_unchecked_t ctlr_num;
49165 +static atomic_unchecked_t fcf_num;
49166
49167 /*
49168 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
49169 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
49170 if (!ctlr)
49171 goto out;
49172
49173 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
49174 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
49175 ctlr->f = f;
49176 ctlr->mode = FIP_CONN_TYPE_FABRIC;
49177 INIT_LIST_HEAD(&ctlr->fcfs);
49178 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
49179 fcf->dev.parent = &ctlr->dev;
49180 fcf->dev.bus = &fcoe_bus_type;
49181 fcf->dev.type = &fcoe_fcf_device_type;
49182 - fcf->id = atomic_inc_return(&fcf_num) - 1;
49183 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
49184 fcf->state = FCOE_FCF_STATE_UNKNOWN;
49185
49186 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
49187 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
49188 {
49189 int error;
49190
49191 - atomic_set(&ctlr_num, 0);
49192 - atomic_set(&fcf_num, 0);
49193 + atomic_set_unchecked(&ctlr_num, 0);
49194 + atomic_set_unchecked(&fcf_num, 0);
49195
49196 error = bus_register(&fcoe_bus_type);
49197 if (error)
49198 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
49199 index f28ea07..34b16d3 100644
49200 --- a/drivers/scsi/hosts.c
49201 +++ b/drivers/scsi/hosts.c
49202 @@ -42,7 +42,7 @@
49203 #include "scsi_logging.h"
49204
49205
49206 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49207 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49208
49209
49210 static void scsi_host_cls_release(struct device *dev)
49211 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
49212 * subtract one because we increment first then return, but we need to
49213 * know what the next host number was before increment
49214 */
49215 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
49216 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
49217 shost->dma_channel = 0xff;
49218
49219 /* These three are default values which can be overridden */
49220 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
49221 index 868318a..e07ef3b 100644
49222 --- a/drivers/scsi/hpsa.c
49223 +++ b/drivers/scsi/hpsa.c
49224 @@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
49225 unsigned long flags;
49226
49227 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
49228 - return h->access.command_completed(h, q);
49229 + return h->access->command_completed(h, q);
49230
49231 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
49232 a = rq->head[rq->current_entry];
49233 @@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
49234 while (!list_empty(&h->reqQ)) {
49235 c = list_entry(h->reqQ.next, struct CommandList, list);
49236 /* can't do anything if fifo is full */
49237 - if ((h->access.fifo_full(h))) {
49238 + if ((h->access->fifo_full(h))) {
49239 h->fifo_recently_full = 1;
49240 dev_warn(&h->pdev->dev, "fifo full\n");
49241 break;
49242 @@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
49243
49244 /* Tell the controller execute command */
49245 spin_unlock_irqrestore(&h->lock, flags);
49246 - h->access.submit_command(h, c);
49247 + h->access->submit_command(h, c);
49248 spin_lock_irqsave(&h->lock, flags);
49249 }
49250 spin_unlock_irqrestore(&h->lock, flags);
49251 @@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
49252
49253 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
49254 {
49255 - return h->access.command_completed(h, q);
49256 + return h->access->command_completed(h, q);
49257 }
49258
49259 static inline bool interrupt_pending(struct ctlr_info *h)
49260 {
49261 - return h->access.intr_pending(h);
49262 + return h->access->intr_pending(h);
49263 }
49264
49265 static inline long interrupt_not_for_us(struct ctlr_info *h)
49266 {
49267 - return (h->access.intr_pending(h) == 0) ||
49268 + return (h->access->intr_pending(h) == 0) ||
49269 (h->interrupts_enabled == 0);
49270 }
49271
49272 @@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
49273 if (prod_index < 0)
49274 return -ENODEV;
49275 h->product_name = products[prod_index].product_name;
49276 - h->access = *(products[prod_index].access);
49277 + h->access = products[prod_index].access;
49278
49279 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
49280 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
49281 @@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
49282 {
49283 unsigned long flags;
49284
49285 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49286 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49287 spin_lock_irqsave(&h->lock, flags);
49288 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
49289 spin_unlock_irqrestore(&h->lock, flags);
49290 @@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
49291 }
49292
49293 /* make sure the board interrupts are off */
49294 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49295 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49296
49297 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
49298 goto clean2;
49299 @@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
49300 * fake ones to scoop up any residual completions.
49301 */
49302 spin_lock_irqsave(&h->lock, flags);
49303 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49304 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49305 spin_unlock_irqrestore(&h->lock, flags);
49306 free_irqs(h);
49307 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
49308 @@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
49309 dev_info(&h->pdev->dev, "Board READY.\n");
49310 dev_info(&h->pdev->dev,
49311 "Waiting for stale completions to drain.\n");
49312 - h->access.set_intr_mask(h, HPSA_INTR_ON);
49313 + h->access->set_intr_mask(h, HPSA_INTR_ON);
49314 msleep(10000);
49315 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49316 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49317
49318 rc = controller_reset_failed(h->cfgtable);
49319 if (rc)
49320 @@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
49321 }
49322
49323 /* Turn the interrupts on so we can service requests */
49324 - h->access.set_intr_mask(h, HPSA_INTR_ON);
49325 + h->access->set_intr_mask(h, HPSA_INTR_ON);
49326
49327 hpsa_hba_inquiry(h);
49328 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
49329 @@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
49330 * To write all data in the battery backed cache to disks
49331 */
49332 hpsa_flush_cache(h);
49333 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
49334 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
49335 hpsa_free_irqs_and_disable_msix(h);
49336 }
49337
49338 @@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
49339 return;
49340 }
49341 /* Change the access methods to the performant access methods */
49342 - h->access = SA5_performant_access;
49343 + h->access = &SA5_performant_access;
49344 h->transMethod = CFGTBL_Trans_Performant;
49345 }
49346
49347 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49348 index 01c3283..4655219 100644
49349 --- a/drivers/scsi/hpsa.h
49350 +++ b/drivers/scsi/hpsa.h
49351 @@ -79,7 +79,7 @@ struct ctlr_info {
49352 unsigned int msix_vector;
49353 unsigned int msi_vector;
49354 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49355 - struct access_method access;
49356 + struct access_method *access;
49357
49358 /* queue and queue Info */
49359 struct list_head reqQ;
49360 @@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
49361 }
49362
49363 static struct access_method SA5_access = {
49364 - SA5_submit_command,
49365 - SA5_intr_mask,
49366 - SA5_fifo_full,
49367 - SA5_intr_pending,
49368 - SA5_completed,
49369 + .submit_command = SA5_submit_command,
49370 + .set_intr_mask = SA5_intr_mask,
49371 + .fifo_full = SA5_fifo_full,
49372 + .intr_pending = SA5_intr_pending,
49373 + .command_completed = SA5_completed,
49374 };
49375
49376 static struct access_method SA5_performant_access = {
49377 - SA5_submit_command,
49378 - SA5_performant_intr_mask,
49379 - SA5_fifo_full,
49380 - SA5_performant_intr_pending,
49381 - SA5_performant_completed,
49382 + .submit_command = SA5_submit_command,
49383 + .set_intr_mask = SA5_performant_intr_mask,
49384 + .fifo_full = SA5_fifo_full,
49385 + .intr_pending = SA5_performant_intr_pending,
49386 + .command_completed = SA5_performant_completed,
49387 };
49388
49389 struct board_type {
49390 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49391 index 1b3a094..068e683 100644
49392 --- a/drivers/scsi/libfc/fc_exch.c
49393 +++ b/drivers/scsi/libfc/fc_exch.c
49394 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
49395 u16 pool_max_index;
49396
49397 struct {
49398 - atomic_t no_free_exch;
49399 - atomic_t no_free_exch_xid;
49400 - atomic_t xid_not_found;
49401 - atomic_t xid_busy;
49402 - atomic_t seq_not_found;
49403 - atomic_t non_bls_resp;
49404 + atomic_unchecked_t no_free_exch;
49405 + atomic_unchecked_t no_free_exch_xid;
49406 + atomic_unchecked_t xid_not_found;
49407 + atomic_unchecked_t xid_busy;
49408 + atomic_unchecked_t seq_not_found;
49409 + atomic_unchecked_t non_bls_resp;
49410 } stats;
49411 };
49412
49413 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49414 /* allocate memory for exchange */
49415 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49416 if (!ep) {
49417 - atomic_inc(&mp->stats.no_free_exch);
49418 + atomic_inc_unchecked(&mp->stats.no_free_exch);
49419 goto out;
49420 }
49421 memset(ep, 0, sizeof(*ep));
49422 @@ -874,7 +874,7 @@ out:
49423 return ep;
49424 err:
49425 spin_unlock_bh(&pool->lock);
49426 - atomic_inc(&mp->stats.no_free_exch_xid);
49427 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49428 mempool_free(ep, mp->ep_pool);
49429 return NULL;
49430 }
49431 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49432 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49433 ep = fc_exch_find(mp, xid);
49434 if (!ep) {
49435 - atomic_inc(&mp->stats.xid_not_found);
49436 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49437 reject = FC_RJT_OX_ID;
49438 goto out;
49439 }
49440 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49441 ep = fc_exch_find(mp, xid);
49442 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49443 if (ep) {
49444 - atomic_inc(&mp->stats.xid_busy);
49445 + atomic_inc_unchecked(&mp->stats.xid_busy);
49446 reject = FC_RJT_RX_ID;
49447 goto rel;
49448 }
49449 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49450 }
49451 xid = ep->xid; /* get our XID */
49452 } else if (!ep) {
49453 - atomic_inc(&mp->stats.xid_not_found);
49454 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49455 reject = FC_RJT_RX_ID; /* XID not found */
49456 goto out;
49457 }
49458 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49459 } else {
49460 sp = &ep->seq;
49461 if (sp->id != fh->fh_seq_id) {
49462 - atomic_inc(&mp->stats.seq_not_found);
49463 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49464 if (f_ctl & FC_FC_END_SEQ) {
49465 /*
49466 * Update sequence_id based on incoming last
49467 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49468
49469 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49470 if (!ep) {
49471 - atomic_inc(&mp->stats.xid_not_found);
49472 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49473 goto out;
49474 }
49475 if (ep->esb_stat & ESB_ST_COMPLETE) {
49476 - atomic_inc(&mp->stats.xid_not_found);
49477 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49478 goto rel;
49479 }
49480 if (ep->rxid == FC_XID_UNKNOWN)
49481 ep->rxid = ntohs(fh->fh_rx_id);
49482 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49483 - atomic_inc(&mp->stats.xid_not_found);
49484 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49485 goto rel;
49486 }
49487 if (ep->did != ntoh24(fh->fh_s_id) &&
49488 ep->did != FC_FID_FLOGI) {
49489 - atomic_inc(&mp->stats.xid_not_found);
49490 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49491 goto rel;
49492 }
49493 sof = fr_sof(fp);
49494 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49495 sp->ssb_stat |= SSB_ST_RESP;
49496 sp->id = fh->fh_seq_id;
49497 } else if (sp->id != fh->fh_seq_id) {
49498 - atomic_inc(&mp->stats.seq_not_found);
49499 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49500 goto rel;
49501 }
49502
49503 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49504 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49505
49506 if (!sp)
49507 - atomic_inc(&mp->stats.xid_not_found);
49508 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49509 else
49510 - atomic_inc(&mp->stats.non_bls_resp);
49511 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
49512
49513 fc_frame_free(fp);
49514 }
49515 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49516
49517 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49518 mp = ema->mp;
49519 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49520 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49521 st->fc_no_free_exch_xid +=
49522 - atomic_read(&mp->stats.no_free_exch_xid);
49523 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49524 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49525 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49526 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49527 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49528 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49529 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49530 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49531 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49532 }
49533 }
49534 EXPORT_SYMBOL(fc_exch_update_stats);
49535 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49536 index d289583..b745eec 100644
49537 --- a/drivers/scsi/libsas/sas_ata.c
49538 +++ b/drivers/scsi/libsas/sas_ata.c
49539 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49540 .postreset = ata_std_postreset,
49541 .error_handler = ata_std_error_handler,
49542 .post_internal_cmd = sas_ata_post_internal,
49543 - .qc_defer = ata_std_qc_defer,
49544 + .qc_defer = ata_std_qc_defer,
49545 .qc_prep = ata_noop_qc_prep,
49546 .qc_issue = sas_ata_qc_issue,
49547 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49548 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49549 index 4e1b75c..0bbdfa9 100644
49550 --- a/drivers/scsi/lpfc/lpfc.h
49551 +++ b/drivers/scsi/lpfc/lpfc.h
49552 @@ -432,7 +432,7 @@ struct lpfc_vport {
49553 struct dentry *debug_nodelist;
49554 struct dentry *vport_debugfs_root;
49555 struct lpfc_debugfs_trc *disc_trc;
49556 - atomic_t disc_trc_cnt;
49557 + atomic_unchecked_t disc_trc_cnt;
49558 #endif
49559 uint8_t stat_data_enabled;
49560 uint8_t stat_data_blocked;
49561 @@ -865,8 +865,8 @@ struct lpfc_hba {
49562 struct timer_list fabric_block_timer;
49563 unsigned long bit_flags;
49564 #define FABRIC_COMANDS_BLOCKED 0
49565 - atomic_t num_rsrc_err;
49566 - atomic_t num_cmd_success;
49567 + atomic_unchecked_t num_rsrc_err;
49568 + atomic_unchecked_t num_cmd_success;
49569 unsigned long last_rsrc_error_time;
49570 unsigned long last_ramp_down_time;
49571 unsigned long last_ramp_up_time;
49572 @@ -902,7 +902,7 @@ struct lpfc_hba {
49573
49574 struct dentry *debug_slow_ring_trc;
49575 struct lpfc_debugfs_trc *slow_ring_trc;
49576 - atomic_t slow_ring_trc_cnt;
49577 + atomic_unchecked_t slow_ring_trc_cnt;
49578 /* iDiag debugfs sub-directory */
49579 struct dentry *idiag_root;
49580 struct dentry *idiag_pci_cfg;
49581 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49582 index b800cc9..16b6a91 100644
49583 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
49584 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49585 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49586
49587 #include <linux/debugfs.h>
49588
49589 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49590 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49591 static unsigned long lpfc_debugfs_start_time = 0L;
49592
49593 /* iDiag */
49594 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49595 lpfc_debugfs_enable = 0;
49596
49597 len = 0;
49598 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49599 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49600 (lpfc_debugfs_max_disc_trc - 1);
49601 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49602 dtp = vport->disc_trc + i;
49603 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49604 lpfc_debugfs_enable = 0;
49605
49606 len = 0;
49607 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49608 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49609 (lpfc_debugfs_max_slow_ring_trc - 1);
49610 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49611 dtp = phba->slow_ring_trc + i;
49612 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49613 !vport || !vport->disc_trc)
49614 return;
49615
49616 - index = atomic_inc_return(&vport->disc_trc_cnt) &
49617 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49618 (lpfc_debugfs_max_disc_trc - 1);
49619 dtp = vport->disc_trc + index;
49620 dtp->fmt = fmt;
49621 dtp->data1 = data1;
49622 dtp->data2 = data2;
49623 dtp->data3 = data3;
49624 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49625 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49626 dtp->jif = jiffies;
49627 #endif
49628 return;
49629 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49630 !phba || !phba->slow_ring_trc)
49631 return;
49632
49633 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49634 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49635 (lpfc_debugfs_max_slow_ring_trc - 1);
49636 dtp = phba->slow_ring_trc + index;
49637 dtp->fmt = fmt;
49638 dtp->data1 = data1;
49639 dtp->data2 = data2;
49640 dtp->data3 = data3;
49641 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49642 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49643 dtp->jif = jiffies;
49644 #endif
49645 return;
49646 @@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49647 "slow_ring buffer\n");
49648 goto debug_failed;
49649 }
49650 - atomic_set(&phba->slow_ring_trc_cnt, 0);
49651 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49652 memset(phba->slow_ring_trc, 0,
49653 (sizeof(struct lpfc_debugfs_trc) *
49654 lpfc_debugfs_max_slow_ring_trc));
49655 @@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49656 "buffer\n");
49657 goto debug_failed;
49658 }
49659 - atomic_set(&vport->disc_trc_cnt, 0);
49660 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49661
49662 snprintf(name, sizeof(name), "discovery_trace");
49663 vport->debug_disc_trc =
49664 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49665 index 68c94cc..8c27be5 100644
49666 --- a/drivers/scsi/lpfc/lpfc_init.c
49667 +++ b/drivers/scsi/lpfc/lpfc_init.c
49668 @@ -10949,8 +10949,10 @@ lpfc_init(void)
49669 "misc_register returned with status %d", error);
49670
49671 if (lpfc_enable_npiv) {
49672 - lpfc_transport_functions.vport_create = lpfc_vport_create;
49673 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49674 + pax_open_kernel();
49675 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49676 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49677 + pax_close_kernel();
49678 }
49679 lpfc_transport_template =
49680 fc_attach_transport(&lpfc_transport_functions);
49681 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49682 index b2ede05..aaf482ca 100644
49683 --- a/drivers/scsi/lpfc/lpfc_scsi.c
49684 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
49685 @@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49686 uint32_t evt_posted;
49687
49688 spin_lock_irqsave(&phba->hbalock, flags);
49689 - atomic_inc(&phba->num_rsrc_err);
49690 + atomic_inc_unchecked(&phba->num_rsrc_err);
49691 phba->last_rsrc_error_time = jiffies;
49692
49693 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49694 @@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49695 unsigned long flags;
49696 struct lpfc_hba *phba = vport->phba;
49697 uint32_t evt_posted;
49698 - atomic_inc(&phba->num_cmd_success);
49699 + atomic_inc_unchecked(&phba->num_cmd_success);
49700
49701 if (vport->cfg_lun_queue_depth <= queue_depth)
49702 return;
49703 @@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49704 unsigned long num_rsrc_err, num_cmd_success;
49705 int i;
49706
49707 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49708 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49709 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49710 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49711
49712 /*
49713 * The error and success command counters are global per
49714 @@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49715 }
49716 }
49717 lpfc_destroy_vport_work_array(phba, vports);
49718 - atomic_set(&phba->num_rsrc_err, 0);
49719 - atomic_set(&phba->num_cmd_success, 0);
49720 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49721 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49722 }
49723
49724 /**
49725 @@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49726 }
49727 }
49728 lpfc_destroy_vport_work_array(phba, vports);
49729 - atomic_set(&phba->num_rsrc_err, 0);
49730 - atomic_set(&phba->num_cmd_success, 0);
49731 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49732 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49733 }
49734
49735 /**
49736 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49737 index 6fd7d40..b444223 100644
49738 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49739 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49740 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49741 {
49742 struct scsi_device *sdev = to_scsi_device(dev);
49743 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49744 - static struct _raid_device *raid_device;
49745 + struct _raid_device *raid_device;
49746 unsigned long flags;
49747 Mpi2RaidVolPage0_t vol_pg0;
49748 Mpi2ConfigReply_t mpi_reply;
49749 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49750 {
49751 struct scsi_device *sdev = to_scsi_device(dev);
49752 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49753 - static struct _raid_device *raid_device;
49754 + struct _raid_device *raid_device;
49755 unsigned long flags;
49756 Mpi2RaidVolPage0_t vol_pg0;
49757 Mpi2ConfigReply_t mpi_reply;
49758 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49759 struct fw_event_work *fw_event)
49760 {
49761 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49762 - static struct _raid_device *raid_device;
49763 + struct _raid_device *raid_device;
49764 unsigned long flags;
49765 u16 handle;
49766
49767 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49768 u64 sas_address;
49769 struct _sas_device *sas_device;
49770 struct _sas_node *expander_device;
49771 - static struct _raid_device *raid_device;
49772 + struct _raid_device *raid_device;
49773 u8 retry_count;
49774 unsigned long flags;
49775
49776 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49777 index be8ce54..94ed33a 100644
49778 --- a/drivers/scsi/pmcraid.c
49779 +++ b/drivers/scsi/pmcraid.c
49780 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49781 res->scsi_dev = scsi_dev;
49782 scsi_dev->hostdata = res;
49783 res->change_detected = 0;
49784 - atomic_set(&res->read_failures, 0);
49785 - atomic_set(&res->write_failures, 0);
49786 + atomic_set_unchecked(&res->read_failures, 0);
49787 + atomic_set_unchecked(&res->write_failures, 0);
49788 rc = 0;
49789 }
49790 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49791 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49792
49793 /* If this was a SCSI read/write command keep count of errors */
49794 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49795 - atomic_inc(&res->read_failures);
49796 + atomic_inc_unchecked(&res->read_failures);
49797 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49798 - atomic_inc(&res->write_failures);
49799 + atomic_inc_unchecked(&res->write_failures);
49800
49801 if (!RES_IS_GSCSI(res->cfg_entry) &&
49802 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49803 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49804 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49805 * hrrq_id assigned here in queuecommand
49806 */
49807 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49808 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49809 pinstance->num_hrrq;
49810 cmd->cmd_done = pmcraid_io_done;
49811
49812 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49813 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49814 * hrrq_id assigned here in queuecommand
49815 */
49816 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49817 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49818 pinstance->num_hrrq;
49819
49820 if (request_size) {
49821 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49822
49823 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49824 /* add resources only after host is added into system */
49825 - if (!atomic_read(&pinstance->expose_resources))
49826 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49827 return;
49828
49829 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49830 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49831 init_waitqueue_head(&pinstance->reset_wait_q);
49832
49833 atomic_set(&pinstance->outstanding_cmds, 0);
49834 - atomic_set(&pinstance->last_message_id, 0);
49835 - atomic_set(&pinstance->expose_resources, 0);
49836 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49837 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49838
49839 INIT_LIST_HEAD(&pinstance->free_res_q);
49840 INIT_LIST_HEAD(&pinstance->used_res_q);
49841 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49842 /* Schedule worker thread to handle CCN and take care of adding and
49843 * removing devices to OS
49844 */
49845 - atomic_set(&pinstance->expose_resources, 1);
49846 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49847 schedule_work(&pinstance->worker_q);
49848 return rc;
49849
49850 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49851 index e1d150f..6c6df44 100644
49852 --- a/drivers/scsi/pmcraid.h
49853 +++ b/drivers/scsi/pmcraid.h
49854 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49855 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49856
49857 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49858 - atomic_t last_message_id;
49859 + atomic_unchecked_t last_message_id;
49860
49861 /* configuration table */
49862 struct pmcraid_config_table *cfg_table;
49863 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49864 atomic_t outstanding_cmds;
49865
49866 /* should add/delete resources to mid-layer now ?*/
49867 - atomic_t expose_resources;
49868 + atomic_unchecked_t expose_resources;
49869
49870
49871
49872 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49873 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49874 };
49875 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49876 - atomic_t read_failures; /* count of failed READ commands */
49877 - atomic_t write_failures; /* count of failed WRITE commands */
49878 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49879 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49880
49881 /* To indicate add/delete/modify during CCN */
49882 u8 change_detected;
49883 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49884 index 4a0d7c9..3d658d7 100644
49885 --- a/drivers/scsi/qla2xxx/qla_attr.c
49886 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49887 @@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49888 return 0;
49889 }
49890
49891 -struct fc_function_template qla2xxx_transport_functions = {
49892 +fc_function_template_no_const qla2xxx_transport_functions = {
49893
49894 .show_host_node_name = 1,
49895 .show_host_port_name = 1,
49896 @@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49897 .bsg_timeout = qla24xx_bsg_timeout,
49898 };
49899
49900 -struct fc_function_template qla2xxx_transport_vport_functions = {
49901 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49902
49903 .show_host_node_name = 1,
49904 .show_host_port_name = 1,
49905 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49906 index 1f42662..bf9836c 100644
49907 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49908 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49909 @@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49910 struct device_attribute;
49911 extern struct device_attribute *qla2x00_host_attrs[];
49912 struct fc_function_template;
49913 -extern struct fc_function_template qla2xxx_transport_functions;
49914 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49915 +extern fc_function_template_no_const qla2xxx_transport_functions;
49916 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49917 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49918 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49919 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49920 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49921 index 83cb612..9b7b08c 100644
49922 --- a/drivers/scsi/qla2xxx/qla_os.c
49923 +++ b/drivers/scsi/qla2xxx/qla_os.c
49924 @@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49925 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49926 /* Ok, a 64bit DMA mask is applicable. */
49927 ha->flags.enable_64bit_addressing = 1;
49928 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49929 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49930 + pax_open_kernel();
49931 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49932 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49933 + pax_close_kernel();
49934 return;
49935 }
49936 }
49937 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49938 index aa67bb9..06d0e2a 100644
49939 --- a/drivers/scsi/qla4xxx/ql4_def.h
49940 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49941 @@ -303,7 +303,7 @@ struct ddb_entry {
49942 * (4000 only) */
49943 atomic_t relogin_timer; /* Max Time to wait for
49944 * relogin to complete */
49945 - atomic_t relogin_retry_count; /* Num of times relogin has been
49946 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49947 * retried */
49948 uint32_t default_time2wait; /* Default Min time between
49949 * relogins (+aens) */
49950 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49951 index c21adc3..1b4155f 100644
49952 --- a/drivers/scsi/qla4xxx/ql4_os.c
49953 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49954 @@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49955 */
49956 if (!iscsi_is_session_online(cls_sess)) {
49957 /* Reset retry relogin timer */
49958 - atomic_inc(&ddb_entry->relogin_retry_count);
49959 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49960 DEBUG2(ql4_printk(KERN_INFO, ha,
49961 "%s: index[%d] relogin timed out-retrying"
49962 " relogin (%d), retry (%d)\n", __func__,
49963 ddb_entry->fw_ddb_index,
49964 - atomic_read(&ddb_entry->relogin_retry_count),
49965 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49966 ddb_entry->default_time2wait + 4));
49967 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49968 atomic_set(&ddb_entry->retry_relogin_timer,
49969 @@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49970
49971 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49972 atomic_set(&ddb_entry->relogin_timer, 0);
49973 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49974 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49975 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49976 ddb_entry->default_relogin_timeout =
49977 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49978 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49979 index d8afec8..3ec7152 100644
49980 --- a/drivers/scsi/scsi.c
49981 +++ b/drivers/scsi/scsi.c
49982 @@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49983 struct Scsi_Host *host = cmd->device->host;
49984 int rtn = 0;
49985
49986 - atomic_inc(&cmd->device->iorequest_cnt);
49987 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49988
49989 /* check if the device is still usable */
49990 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49991 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49992 index 62ec84b..93159d8 100644
49993 --- a/drivers/scsi/scsi_lib.c
49994 +++ b/drivers/scsi/scsi_lib.c
49995 @@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49996 shost = sdev->host;
49997 scsi_init_cmd_errh(cmd);
49998 cmd->result = DID_NO_CONNECT << 16;
49999 - atomic_inc(&cmd->device->iorequest_cnt);
50000 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
50001
50002 /*
50003 * SCSI request completion path will do scsi_device_unbusy(),
50004 @@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
50005
50006 INIT_LIST_HEAD(&cmd->eh_entry);
50007
50008 - atomic_inc(&cmd->device->iodone_cnt);
50009 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
50010 if (cmd->result)
50011 - atomic_inc(&cmd->device->ioerr_cnt);
50012 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
50013
50014 disposition = scsi_decide_disposition(cmd);
50015 if (disposition != SUCCESS &&
50016 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
50017 index 9117d0b..d289a7a 100644
50018 --- a/drivers/scsi/scsi_sysfs.c
50019 +++ b/drivers/scsi/scsi_sysfs.c
50020 @@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
50021 char *buf) \
50022 { \
50023 struct scsi_device *sdev = to_scsi_device(dev); \
50024 - unsigned long long count = atomic_read(&sdev->field); \
50025 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
50026 return snprintf(buf, 20, "0x%llx\n", count); \
50027 } \
50028 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
50029 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
50030 index 84a1fdf..693b0d6 100644
50031 --- a/drivers/scsi/scsi_tgt_lib.c
50032 +++ b/drivers/scsi/scsi_tgt_lib.c
50033 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
50034 int err;
50035
50036 dprintk("%lx %u\n", uaddr, len);
50037 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
50038 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
50039 if (err) {
50040 /*
50041 * TODO: need to fixup sg_tablesize, max_segment_size,
50042 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
50043 index 4628fd5..a94a1c2 100644
50044 --- a/drivers/scsi/scsi_transport_fc.c
50045 +++ b/drivers/scsi/scsi_transport_fc.c
50046 @@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
50047 * Netlink Infrastructure
50048 */
50049
50050 -static atomic_t fc_event_seq;
50051 +static atomic_unchecked_t fc_event_seq;
50052
50053 /**
50054 * fc_get_event_number - Obtain the next sequential FC event number
50055 @@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
50056 u32
50057 fc_get_event_number(void)
50058 {
50059 - return atomic_add_return(1, &fc_event_seq);
50060 + return atomic_add_return_unchecked(1, &fc_event_seq);
50061 }
50062 EXPORT_SYMBOL(fc_get_event_number);
50063
50064 @@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
50065 {
50066 int error;
50067
50068 - atomic_set(&fc_event_seq, 0);
50069 + atomic_set_unchecked(&fc_event_seq, 0);
50070
50071 error = transport_class_register(&fc_host_class);
50072 if (error)
50073 @@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
50074 char *cp;
50075
50076 *val = simple_strtoul(buf, &cp, 0);
50077 - if ((*cp && (*cp != '\n')) || (*val < 0))
50078 + if (*cp && (*cp != '\n'))
50079 return -EINVAL;
50080 /*
50081 * Check for overflow; dev_loss_tmo is u32
50082 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
50083 index fd8ffe6..fd0bebf 100644
50084 --- a/drivers/scsi/scsi_transport_iscsi.c
50085 +++ b/drivers/scsi/scsi_transport_iscsi.c
50086 @@ -79,7 +79,7 @@ struct iscsi_internal {
50087 struct transport_container session_cont;
50088 };
50089
50090 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
50091 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
50092 static struct workqueue_struct *iscsi_eh_timer_workq;
50093
50094 static DEFINE_IDA(iscsi_sess_ida);
50095 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
50096 int err;
50097
50098 ihost = shost->shost_data;
50099 - session->sid = atomic_add_return(1, &iscsi_session_nr);
50100 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
50101
50102 if (target_id == ISCSI_MAX_TARGET) {
50103 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
50104 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
50105 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
50106 ISCSI_TRANSPORT_VERSION);
50107
50108 - atomic_set(&iscsi_session_nr, 0);
50109 + atomic_set_unchecked(&iscsi_session_nr, 0);
50110
50111 err = class_register(&iscsi_transport_class);
50112 if (err)
50113 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
50114 index d47ffc8..30f46a9 100644
50115 --- a/drivers/scsi/scsi_transport_srp.c
50116 +++ b/drivers/scsi/scsi_transport_srp.c
50117 @@ -36,7 +36,7 @@
50118 #include "scsi_transport_srp_internal.h"
50119
50120 struct srp_host_attrs {
50121 - atomic_t next_port_id;
50122 + atomic_unchecked_t next_port_id;
50123 };
50124 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
50125
50126 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
50127 struct Scsi_Host *shost = dev_to_shost(dev);
50128 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
50129
50130 - atomic_set(&srp_host->next_port_id, 0);
50131 + atomic_set_unchecked(&srp_host->next_port_id, 0);
50132 return 0;
50133 }
50134
50135 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
50136 rport_fast_io_fail_timedout);
50137 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
50138
50139 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
50140 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
50141 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
50142
50143 transport_setup_device(&rport->dev);
50144 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
50145 index 36d1a23..3f33303 100644
50146 --- a/drivers/scsi/sd.c
50147 +++ b/drivers/scsi/sd.c
50148 @@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
50149 sdkp->disk = gd;
50150 sdkp->index = index;
50151 atomic_set(&sdkp->openers, 0);
50152 - atomic_set(&sdkp->device->ioerr_cnt, 0);
50153 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
50154
50155 if (!sdp->request_queue->rq_timeout) {
50156 if (sdp->type != TYPE_MOD)
50157 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
50158 index df5e961..df6b97f 100644
50159 --- a/drivers/scsi/sg.c
50160 +++ b/drivers/scsi/sg.c
50161 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
50162 sdp->disk->disk_name,
50163 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
50164 NULL,
50165 - (char *)arg);
50166 + (char __user *)arg);
50167 case BLKTRACESTART:
50168 return blk_trace_startstop(sdp->device->request_queue, 1);
50169 case BLKTRACESTOP:
50170 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
50171 index d0b28bb..a263613 100644
50172 --- a/drivers/spi/spi.c
50173 +++ b/drivers/spi/spi.c
50174 @@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
50175 EXPORT_SYMBOL_GPL(spi_bus_unlock);
50176
50177 /* portable code must never pass more than 32 bytes */
50178 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
50179 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
50180
50181 static u8 *buf;
50182
50183 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
50184 index 2c61783..4d49e4e 100644
50185 --- a/drivers/staging/android/timed_output.c
50186 +++ b/drivers/staging/android/timed_output.c
50187 @@ -25,7 +25,7 @@
50188 #include "timed_output.h"
50189
50190 static struct class *timed_output_class;
50191 -static atomic_t device_count;
50192 +static atomic_unchecked_t device_count;
50193
50194 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
50195 char *buf)
50196 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
50197 timed_output_class = class_create(THIS_MODULE, "timed_output");
50198 if (IS_ERR(timed_output_class))
50199 return PTR_ERR(timed_output_class);
50200 - atomic_set(&device_count, 0);
50201 + atomic_set_unchecked(&device_count, 0);
50202 timed_output_class->dev_groups = timed_output_groups;
50203 }
50204
50205 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
50206 if (ret < 0)
50207 return ret;
50208
50209 - tdev->index = atomic_inc_return(&device_count);
50210 + tdev->index = atomic_inc_return_unchecked(&device_count);
50211 tdev->dev = device_create(timed_output_class, NULL,
50212 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
50213 if (IS_ERR(tdev->dev))
50214 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
50215 index fe47cd3..19a1bd1 100644
50216 --- a/drivers/staging/gdm724x/gdm_tty.c
50217 +++ b/drivers/staging/gdm724x/gdm_tty.c
50218 @@ -44,7 +44,7 @@
50219 #define gdm_tty_send_control(n, r, v, d, l) (\
50220 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
50221
50222 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
50223 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
50224
50225 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
50226 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
50227 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
50228 index 236ed66..dd9cd74 100644
50229 --- a/drivers/staging/imx-drm/imx-drm-core.c
50230 +++ b/drivers/staging/imx-drm/imx-drm-core.c
50231 @@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
50232 goto err_busy;
50233 }
50234
50235 - if (imxdrm->drm->open_count) {
50236 + if (local_read(&imxdrm->drm->open_count)) {
50237 ret = -EBUSY;
50238 goto err_busy;
50239 }
50240 @@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
50241
50242 mutex_lock(&imxdrm->mutex);
50243
50244 - if (imxdrm->drm->open_count) {
50245 + if (local_read(&imxdrm->drm->open_count)) {
50246 ret = -EBUSY;
50247 goto err_busy;
50248 }
50249 @@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
50250
50251 mutex_lock(&imxdrm->mutex);
50252
50253 - if (imxdrm->drm->open_count) {
50254 + if (local_read(&imxdrm->drm->open_count)) {
50255 ret = -EBUSY;
50256 goto err_busy;
50257 }
50258 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
50259 index 3f8020c..649fded 100644
50260 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
50261 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
50262 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
50263 return 0;
50264 }
50265
50266 -sfw_test_client_ops_t brw_test_client;
50267 -void brw_init_test_client(void)
50268 -{
50269 - brw_test_client.tso_init = brw_client_init;
50270 - brw_test_client.tso_fini = brw_client_fini;
50271 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
50272 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
50273 +sfw_test_client_ops_t brw_test_client = {
50274 + .tso_init = brw_client_init,
50275 + .tso_fini = brw_client_fini,
50276 + .tso_prep_rpc = brw_client_prep_rpc,
50277 + .tso_done_rpc = brw_client_done_rpc,
50278 };
50279
50280 srpc_service_t brw_test_service;
50281 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
50282 index 050723a..fa6fdf1 100644
50283 --- a/drivers/staging/lustre/lnet/selftest/framework.c
50284 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
50285 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
50286
50287 extern sfw_test_client_ops_t ping_test_client;
50288 extern srpc_service_t ping_test_service;
50289 -extern void ping_init_test_client(void);
50290 extern void ping_init_test_service(void);
50291
50292 extern sfw_test_client_ops_t brw_test_client;
50293 extern srpc_service_t brw_test_service;
50294 -extern void brw_init_test_client(void);
50295 extern void brw_init_test_service(void);
50296
50297
50298 @@ -1684,12 +1682,10 @@ sfw_startup (void)
50299 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
50300 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
50301
50302 - brw_init_test_client();
50303 brw_init_test_service();
50304 rc = sfw_register_test(&brw_test_service, &brw_test_client);
50305 LASSERT (rc == 0);
50306
50307 - ping_init_test_client();
50308 ping_init_test_service();
50309 rc = sfw_register_test(&ping_test_service, &ping_test_client);
50310 LASSERT (rc == 0);
50311 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
50312 index 750cac4..e4d751f 100644
50313 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
50314 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
50315 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
50316 return 0;
50317 }
50318
50319 -sfw_test_client_ops_t ping_test_client;
50320 -void ping_init_test_client(void)
50321 -{
50322 - ping_test_client.tso_init = ping_client_init;
50323 - ping_test_client.tso_fini = ping_client_fini;
50324 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
50325 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
50326 -}
50327 +sfw_test_client_ops_t ping_test_client = {
50328 + .tso_init = ping_client_init,
50329 + .tso_fini = ping_client_fini,
50330 + .tso_prep_rpc = ping_client_prep_rpc,
50331 + .tso_done_rpc = ping_client_done_rpc,
50332 +};
50333
50334 srpc_service_t ping_test_service;
50335 void ping_init_test_service(void)
50336 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50337 index ec4bb5e..740c6dd 100644
50338 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
50339 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50340 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
50341 ldlm_completion_callback lcs_completion;
50342 ldlm_blocking_callback lcs_blocking;
50343 ldlm_glimpse_callback lcs_glimpse;
50344 -};
50345 +} __no_const;
50346
50347 /* ldlm_lockd.c */
50348 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50349 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50350 index c3470ce..2bef527 100644
50351 --- a/drivers/staging/lustre/lustre/include/obd.h
50352 +++ b/drivers/staging/lustre/lustre/include/obd.h
50353 @@ -1426,7 +1426,7 @@ struct md_ops {
50354 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50355 * wrapper function in include/linux/obd_class.h.
50356 */
50357 -};
50358 +} __no_const;
50359
50360 struct lsm_operations {
50361 void (*lsm_free)(struct lov_stripe_md *);
50362 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50363 index c9aae13..60ea292 100644
50364 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50365 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50366 @@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50367 int added = (mode == LCK_NL);
50368 int overlaps = 0;
50369 int splitted = 0;
50370 - const struct ldlm_callback_suite null_cbs = { NULL };
50371 + const struct ldlm_callback_suite null_cbs = { };
50372
50373 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50374 LPU64" end "LPU64"\n", *flags,
50375 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50376 index e947b91..f408990 100644
50377 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50378 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50379 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50380 int LL_PROC_PROTO(proc_console_max_delay_cs)
50381 {
50382 int rc, max_delay_cs;
50383 - ctl_table_t dummy = *table;
50384 + ctl_table_no_const dummy = *table;
50385 cfs_duration_t d;
50386
50387 dummy.data = &max_delay_cs;
50388 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50389 int LL_PROC_PROTO(proc_console_min_delay_cs)
50390 {
50391 int rc, min_delay_cs;
50392 - ctl_table_t dummy = *table;
50393 + ctl_table_no_const dummy = *table;
50394 cfs_duration_t d;
50395
50396 dummy.data = &min_delay_cs;
50397 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50398 int LL_PROC_PROTO(proc_console_backoff)
50399 {
50400 int rc, backoff;
50401 - ctl_table_t dummy = *table;
50402 + ctl_table_no_const dummy = *table;
50403
50404 dummy.data = &backoff;
50405 dummy.proc_handler = &proc_dointvec;
50406 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50407 index 24ae26d..9d09cab 100644
50408 --- a/drivers/staging/lustre/lustre/libcfs/module.c
50409 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
50410 @@ -313,11 +313,11 @@ out:
50411
50412
50413 struct cfs_psdev_ops libcfs_psdev_ops = {
50414 - libcfs_psdev_open,
50415 - libcfs_psdev_release,
50416 - NULL,
50417 - NULL,
50418 - libcfs_ioctl
50419 + .p_open = libcfs_psdev_open,
50420 + .p_close = libcfs_psdev_release,
50421 + .p_read = NULL,
50422 + .p_write = NULL,
50423 + .p_ioctl = libcfs_ioctl
50424 };
50425
50426 extern int insert_proc(void);
50427 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50428 index 52b7731..d604da0 100644
50429 --- a/drivers/staging/lustre/lustre/llite/dir.c
50430 +++ b/drivers/staging/lustre/lustre/llite/dir.c
50431 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50432 int mode;
50433 int err;
50434
50435 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50436 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50437 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50438 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50439 lump);
50440 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50441 index 480b7c4..6846324 100644
50442 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
50443 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50444 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50445
50446 static int solo_sysfs_init(struct solo_dev *solo_dev)
50447 {
50448 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50449 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50450 struct device *dev = &solo_dev->dev;
50451 const char *driver;
50452 int i;
50453 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50454 index 1db18c7..35e6afc 100644
50455 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50456 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50457 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50458
50459 int solo_g723_init(struct solo_dev *solo_dev)
50460 {
50461 - static struct snd_device_ops ops = { NULL };
50462 + static struct snd_device_ops ops = { };
50463 struct snd_card *card;
50464 struct snd_kcontrol_new kctl;
50465 char name[32];
50466 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50467 index 7f2f247..d999137 100644
50468 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50469 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50470 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50471
50472 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50473 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50474 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50475 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50476 if (p2m_id < 0)
50477 p2m_id = -p2m_id;
50478 }
50479 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50480 index 8964f8b..36eb087 100644
50481 --- a/drivers/staging/media/solo6x10/solo6x10.h
50482 +++ b/drivers/staging/media/solo6x10/solo6x10.h
50483 @@ -237,7 +237,7 @@ struct solo_dev {
50484
50485 /* P2M DMA Engine */
50486 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50487 - atomic_t p2m_count;
50488 + atomic_unchecked_t p2m_count;
50489 int p2m_jiffies;
50490 unsigned int p2m_timeouts;
50491
50492 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50493 index a0f4868..139f1fb 100644
50494 --- a/drivers/staging/octeon/ethernet-rx.c
50495 +++ b/drivers/staging/octeon/ethernet-rx.c
50496 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50497 /* Increment RX stats for virtual ports */
50498 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50499 #ifdef CONFIG_64BIT
50500 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50501 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50502 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50503 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50504 #else
50505 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50506 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50507 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50508 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50509 #endif
50510 }
50511 netif_receive_skb(skb);
50512 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50513 dev->name);
50514 */
50515 #ifdef CONFIG_64BIT
50516 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50517 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50518 #else
50519 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50520 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50521 #endif
50522 dev_kfree_skb_irq(skb);
50523 }
50524 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50525 index 089dc4b..c9a687e 100644
50526 --- a/drivers/staging/octeon/ethernet.c
50527 +++ b/drivers/staging/octeon/ethernet.c
50528 @@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50529 * since the RX tasklet also increments it.
50530 */
50531 #ifdef CONFIG_64BIT
50532 - atomic64_add(rx_status.dropped_packets,
50533 - (atomic64_t *)&priv->stats.rx_dropped);
50534 + atomic64_add_unchecked(rx_status.dropped_packets,
50535 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50536 #else
50537 - atomic_add(rx_status.dropped_packets,
50538 - (atomic_t *)&priv->stats.rx_dropped);
50539 + atomic_add_unchecked(rx_status.dropped_packets,
50540 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
50541 #endif
50542 }
50543
50544 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50545 index c274b34..f84de76 100644
50546 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
50547 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50548 @@ -271,7 +271,7 @@ struct hal_ops {
50549 s32 (*c2h_handler)(struct adapter *padapter,
50550 struct c2h_evt_hdr *c2h_evt);
50551 c2h_id_filter c2h_id_filter_ccx;
50552 -};
50553 +} __no_const;
50554
50555 enum rt_eeprom_type {
50556 EEPROM_93C46,
50557 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50558 index 3d1dfcc..ff5620a 100644
50559 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
50560 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50561 @@ -126,7 +126,7 @@ struct _io_ops {
50562 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50563 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50564 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50565 -};
50566 +} __no_const;
50567
50568 struct io_req {
50569 struct list_head list;
50570 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50571 index dc23395..cf7e9b1 100644
50572 --- a/drivers/staging/rtl8712/rtl871x_io.h
50573 +++ b/drivers/staging/rtl8712/rtl871x_io.h
50574 @@ -108,7 +108,7 @@ struct _io_ops {
50575 u8 *pmem);
50576 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50577 u8 *pmem);
50578 -};
50579 +} __no_const;
50580
50581 struct io_req {
50582 struct list_head list;
50583 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50584 index 1f5088b..0e59820 100644
50585 --- a/drivers/staging/sbe-2t3e3/netdev.c
50586 +++ b/drivers/staging/sbe-2t3e3/netdev.c
50587 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50588 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50589
50590 if (rlen)
50591 - if (copy_to_user(data, &resp, rlen))
50592 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50593 return -EFAULT;
50594
50595 return 0;
50596 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50597 index a863a98..d272795 100644
50598 --- a/drivers/staging/usbip/vhci.h
50599 +++ b/drivers/staging/usbip/vhci.h
50600 @@ -83,7 +83,7 @@ struct vhci_hcd {
50601 unsigned resuming:1;
50602 unsigned long re_timeout;
50603
50604 - atomic_t seqnum;
50605 + atomic_unchecked_t seqnum;
50606
50607 /*
50608 * NOTE:
50609 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50610 index 72391ef..7c6717a 100644
50611 --- a/drivers/staging/usbip/vhci_hcd.c
50612 +++ b/drivers/staging/usbip/vhci_hcd.c
50613 @@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
50614
50615 spin_lock(&vdev->priv_lock);
50616
50617 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50618 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50619 if (priv->seqnum == 0xffff)
50620 dev_info(&urb->dev->dev, "seqnum max\n");
50621
50622 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50623 return -ENOMEM;
50624 }
50625
50626 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50627 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50628 if (unlink->seqnum == 0xffff)
50629 pr_info("seqnum max\n");
50630
50631 @@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
50632 vdev->rhport = rhport;
50633 }
50634
50635 - atomic_set(&vhci->seqnum, 0);
50636 + atomic_set_unchecked(&vhci->seqnum, 0);
50637 spin_lock_init(&vhci->lock);
50638
50639 hcd->power_budget = 0; /* no limit */
50640 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50641 index d07fcb5..358e1e1 100644
50642 --- a/drivers/staging/usbip/vhci_rx.c
50643 +++ b/drivers/staging/usbip/vhci_rx.c
50644 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50645 if (!urb) {
50646 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50647 pr_info("max seqnum %d\n",
50648 - atomic_read(&the_controller->seqnum));
50649 + atomic_read_unchecked(&the_controller->seqnum));
50650 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50651 return;
50652 }
50653 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50654 index 6eecd53..29317c6 100644
50655 --- a/drivers/staging/vt6655/hostap.c
50656 +++ b/drivers/staging/vt6655/hostap.c
50657 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50658 *
50659 */
50660
50661 +static net_device_ops_no_const apdev_netdev_ops;
50662 +
50663 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50664 {
50665 PSDevice apdev_priv;
50666 struct net_device *dev = pDevice->dev;
50667 int ret;
50668 - const struct net_device_ops apdev_netdev_ops = {
50669 - .ndo_start_xmit = pDevice->tx_80211,
50670 - };
50671
50672 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50673
50674 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50675 *apdev_priv = *pDevice;
50676 eth_hw_addr_inherit(pDevice->apdev, dev);
50677
50678 + /* only half broken now */
50679 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50680 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50681
50682 pDevice->apdev->type = ARPHRD_IEEE80211;
50683 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50684 index 67ba48b..24e602f 100644
50685 --- a/drivers/staging/vt6656/hostap.c
50686 +++ b/drivers/staging/vt6656/hostap.c
50687 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50688 *
50689 */
50690
50691 +static net_device_ops_no_const apdev_netdev_ops;
50692 +
50693 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50694 {
50695 struct vnt_private *apdev_priv;
50696 struct net_device *dev = pDevice->dev;
50697 int ret;
50698 - const struct net_device_ops apdev_netdev_ops = {
50699 - .ndo_start_xmit = pDevice->tx_80211,
50700 - };
50701
50702 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50703
50704 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50705 *apdev_priv = *pDevice;
50706 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50707
50708 + /* only half broken now */
50709 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50710 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50711
50712 pDevice->apdev->type = ARPHRD_IEEE80211;
50713 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50714 index 24884ca..26c8220 100644
50715 --- a/drivers/target/sbp/sbp_target.c
50716 +++ b/drivers/target/sbp/sbp_target.c
50717 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50718
50719 #define SESSION_MAINTENANCE_INTERVAL HZ
50720
50721 -static atomic_t login_id = ATOMIC_INIT(0);
50722 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50723
50724 static void session_maintenance_work(struct work_struct *);
50725 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50726 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50727 login->lun = se_lun;
50728 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50729 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50730 - login->login_id = atomic_inc_return(&login_id);
50731 + login->login_id = atomic_inc_return_unchecked(&login_id);
50732
50733 login->tgt_agt = sbp_target_agent_register(login);
50734 if (IS_ERR(login->tgt_agt)) {
50735 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50736 index 65001e1..2ebfbb9 100644
50737 --- a/drivers/target/target_core_device.c
50738 +++ b/drivers/target/target_core_device.c
50739 @@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50740 spin_lock_init(&dev->se_tmr_lock);
50741 spin_lock_init(&dev->qf_cmd_lock);
50742 sema_init(&dev->caw_sem, 1);
50743 - atomic_set(&dev->dev_ordered_id, 0);
50744 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50745 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50746 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50747 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50748 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50749 index 2956250..b10f722 100644
50750 --- a/drivers/target/target_core_transport.c
50751 +++ b/drivers/target/target_core_transport.c
50752 @@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50753 * Used to determine when ORDERED commands should go from
50754 * Dormant to Active status.
50755 */
50756 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50757 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50758 smp_mb__after_atomic_inc();
50759 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50760 cmd->se_ordered_id, cmd->sam_task_attr,
50761 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50762 index 04b1be7..5eff86d 100644
50763 --- a/drivers/thermal/of-thermal.c
50764 +++ b/drivers/thermal/of-thermal.c
50765 @@ -30,6 +30,7 @@
50766 #include <linux/err.h>
50767 #include <linux/export.h>
50768 #include <linux/string.h>
50769 +#include <linux/mm.h>
50770
50771 #include "thermal_core.h"
50772
50773 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50774 tz->get_trend = get_trend;
50775 tz->sensor_data = data;
50776
50777 - tzd->ops->get_temp = of_thermal_get_temp;
50778 - tzd->ops->get_trend = of_thermal_get_trend;
50779 + pax_open_kernel();
50780 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50781 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50782 + pax_close_kernel();
50783 mutex_unlock(&tzd->lock);
50784
50785 return tzd;
50786 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50787 return;
50788
50789 mutex_lock(&tzd->lock);
50790 - tzd->ops->get_temp = NULL;
50791 - tzd->ops->get_trend = NULL;
50792 + pax_open_kernel();
50793 + *(void **)&tzd->ops->get_temp = NULL;
50794 + *(void **)&tzd->ops->get_trend = NULL;
50795 + pax_close_kernel();
50796
50797 tz->get_temp = NULL;
50798 tz->get_trend = NULL;
50799 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50800 index a57bb5a..1f727d33 100644
50801 --- a/drivers/tty/cyclades.c
50802 +++ b/drivers/tty/cyclades.c
50803 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50804 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50805 info->port.count);
50806 #endif
50807 - info->port.count++;
50808 + atomic_inc(&info->port.count);
50809 #ifdef CY_DEBUG_COUNT
50810 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50811 - current->pid, info->port.count);
50812 + current->pid, atomic_read(&info->port.count));
50813 #endif
50814
50815 /*
50816 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50817 for (j = 0; j < cy_card[i].nports; j++) {
50818 info = &cy_card[i].ports[j];
50819
50820 - if (info->port.count) {
50821 + if (atomic_read(&info->port.count)) {
50822 /* XXX is the ldisc num worth this? */
50823 struct tty_struct *tty;
50824 struct tty_ldisc *ld;
50825 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50826 index 0ff7fda..dbc7d52 100644
50827 --- a/drivers/tty/hvc/hvc_console.c
50828 +++ b/drivers/tty/hvc/hvc_console.c
50829 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50830
50831 spin_lock_irqsave(&hp->port.lock, flags);
50832 /* Check and then increment for fast path open. */
50833 - if (hp->port.count++ > 0) {
50834 + if (atomic_inc_return(&hp->port.count) > 1) {
50835 spin_unlock_irqrestore(&hp->port.lock, flags);
50836 hvc_kick();
50837 return 0;
50838 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50839
50840 spin_lock_irqsave(&hp->port.lock, flags);
50841
50842 - if (--hp->port.count == 0) {
50843 + if (atomic_dec_return(&hp->port.count) == 0) {
50844 spin_unlock_irqrestore(&hp->port.lock, flags);
50845 /* We are done with the tty pointer now. */
50846 tty_port_tty_set(&hp->port, NULL);
50847 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50848 */
50849 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50850 } else {
50851 - if (hp->port.count < 0)
50852 + if (atomic_read(&hp->port.count) < 0)
50853 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50854 - hp->vtermno, hp->port.count);
50855 + hp->vtermno, atomic_read(&hp->port.count));
50856 spin_unlock_irqrestore(&hp->port.lock, flags);
50857 }
50858 }
50859 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50860 * open->hangup case this can be called after the final close so prevent
50861 * that from happening for now.
50862 */
50863 - if (hp->port.count <= 0) {
50864 + if (atomic_read(&hp->port.count) <= 0) {
50865 spin_unlock_irqrestore(&hp->port.lock, flags);
50866 return;
50867 }
50868
50869 - hp->port.count = 0;
50870 + atomic_set(&hp->port.count, 0);
50871 spin_unlock_irqrestore(&hp->port.lock, flags);
50872 tty_port_tty_set(&hp->port, NULL);
50873
50874 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50875 return -EPIPE;
50876
50877 /* FIXME what's this (unprotected) check for? */
50878 - if (hp->port.count <= 0)
50879 + if (atomic_read(&hp->port.count) <= 0)
50880 return -EIO;
50881
50882 spin_lock_irqsave(&hp->lock, flags);
50883 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50884 index 81e939e..95ead10 100644
50885 --- a/drivers/tty/hvc/hvcs.c
50886 +++ b/drivers/tty/hvc/hvcs.c
50887 @@ -83,6 +83,7 @@
50888 #include <asm/hvcserver.h>
50889 #include <asm/uaccess.h>
50890 #include <asm/vio.h>
50891 +#include <asm/local.h>
50892
50893 /*
50894 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50895 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50896
50897 spin_lock_irqsave(&hvcsd->lock, flags);
50898
50899 - if (hvcsd->port.count > 0) {
50900 + if (atomic_read(&hvcsd->port.count) > 0) {
50901 spin_unlock_irqrestore(&hvcsd->lock, flags);
50902 printk(KERN_INFO "HVCS: vterm state unchanged. "
50903 "The hvcs device node is still in use.\n");
50904 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50905 }
50906 }
50907
50908 - hvcsd->port.count = 0;
50909 + atomic_set(&hvcsd->port.count, 0);
50910 hvcsd->port.tty = tty;
50911 tty->driver_data = hvcsd;
50912
50913 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50914 unsigned long flags;
50915
50916 spin_lock_irqsave(&hvcsd->lock, flags);
50917 - hvcsd->port.count++;
50918 + atomic_inc(&hvcsd->port.count);
50919 hvcsd->todo_mask |= HVCS_SCHED_READ;
50920 spin_unlock_irqrestore(&hvcsd->lock, flags);
50921
50922 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50923 hvcsd = tty->driver_data;
50924
50925 spin_lock_irqsave(&hvcsd->lock, flags);
50926 - if (--hvcsd->port.count == 0) {
50927 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50928
50929 vio_disable_interrupts(hvcsd->vdev);
50930
50931 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50932
50933 free_irq(irq, hvcsd);
50934 return;
50935 - } else if (hvcsd->port.count < 0) {
50936 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50937 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50938 " is missmanaged.\n",
50939 - hvcsd->vdev->unit_address, hvcsd->port.count);
50940 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50941 }
50942
50943 spin_unlock_irqrestore(&hvcsd->lock, flags);
50944 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50945
50946 spin_lock_irqsave(&hvcsd->lock, flags);
50947 /* Preserve this so that we know how many kref refs to put */
50948 - temp_open_count = hvcsd->port.count;
50949 + temp_open_count = atomic_read(&hvcsd->port.count);
50950
50951 /*
50952 * Don't kref put inside the spinlock because the destruction
50953 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50954 tty->driver_data = NULL;
50955 hvcsd->port.tty = NULL;
50956
50957 - hvcsd->port.count = 0;
50958 + atomic_set(&hvcsd->port.count, 0);
50959
50960 /* This will drop any buffered data on the floor which is OK in a hangup
50961 * scenario. */
50962 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50963 * the middle of a write operation? This is a crummy place to do this
50964 * but we want to keep it all in the spinlock.
50965 */
50966 - if (hvcsd->port.count <= 0) {
50967 + if (atomic_read(&hvcsd->port.count) <= 0) {
50968 spin_unlock_irqrestore(&hvcsd->lock, flags);
50969 return -ENODEV;
50970 }
50971 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50972 {
50973 struct hvcs_struct *hvcsd = tty->driver_data;
50974
50975 - if (!hvcsd || hvcsd->port.count <= 0)
50976 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50977 return 0;
50978
50979 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50980 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50981 index 4190199..06d5bfa 100644
50982 --- a/drivers/tty/hvc/hvsi.c
50983 +++ b/drivers/tty/hvc/hvsi.c
50984 @@ -85,7 +85,7 @@ struct hvsi_struct {
50985 int n_outbuf;
50986 uint32_t vtermno;
50987 uint32_t virq;
50988 - atomic_t seqno; /* HVSI packet sequence number */
50989 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
50990 uint16_t mctrl;
50991 uint8_t state; /* HVSI protocol state */
50992 uint8_t flags;
50993 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50994
50995 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50996 packet.hdr.len = sizeof(struct hvsi_query_response);
50997 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50998 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50999 packet.verb = VSV_SEND_VERSION_NUMBER;
51000 packet.u.version = HVSI_VERSION;
51001 packet.query_seqno = query_seqno+1;
51002 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
51003
51004 packet.hdr.type = VS_QUERY_PACKET_HEADER;
51005 packet.hdr.len = sizeof(struct hvsi_query);
51006 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51007 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51008 packet.verb = verb;
51009
51010 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
51011 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
51012 int wrote;
51013
51014 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
51015 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51016 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51017 packet.hdr.len = sizeof(struct hvsi_control);
51018 packet.verb = VSV_SET_MODEM_CTL;
51019 packet.mask = HVSI_TSDTR;
51020 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
51021 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
51022
51023 packet.hdr.type = VS_DATA_PACKET_HEADER;
51024 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51025 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51026 packet.hdr.len = count + sizeof(struct hvsi_header);
51027 memcpy(&packet.data, buf, count);
51028
51029 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
51030 struct hvsi_control packet __ALIGNED__;
51031
51032 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
51033 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
51034 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
51035 packet.hdr.len = 6;
51036 packet.verb = VSV_CLOSE_PROTOCOL;
51037
51038 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
51039
51040 tty_port_tty_set(&hp->port, tty);
51041 spin_lock_irqsave(&hp->lock, flags);
51042 - hp->port.count++;
51043 + atomic_inc(&hp->port.count);
51044 atomic_set(&hp->seqno, 0);
51045 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
51046 spin_unlock_irqrestore(&hp->lock, flags);
51047 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51048
51049 spin_lock_irqsave(&hp->lock, flags);
51050
51051 - if (--hp->port.count == 0) {
51052 + if (atomic_dec_return(&hp->port.count) == 0) {
51053 tty_port_tty_set(&hp->port, NULL);
51054 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
51055
51056 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51057
51058 spin_lock_irqsave(&hp->lock, flags);
51059 }
51060 - } else if (hp->port.count < 0)
51061 + } else if (atomic_read(&hp->port.count) < 0)
51062 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
51063 - hp - hvsi_ports, hp->port.count);
51064 + hp - hvsi_ports, atomic_read(&hp->port.count));
51065
51066 spin_unlock_irqrestore(&hp->lock, flags);
51067 }
51068 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
51069 tty_port_tty_set(&hp->port, NULL);
51070
51071 spin_lock_irqsave(&hp->lock, flags);
51072 - hp->port.count = 0;
51073 + atomic_set(&hp->port.count, 0);
51074 hp->n_outbuf = 0;
51075 spin_unlock_irqrestore(&hp->lock, flags);
51076 }
51077 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
51078 index 7ae6c29..05c6dba 100644
51079 --- a/drivers/tty/hvc/hvsi_lib.c
51080 +++ b/drivers/tty/hvc/hvsi_lib.c
51081 @@ -8,7 +8,7 @@
51082
51083 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
51084 {
51085 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
51086 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
51087
51088 /* Assumes that always succeeds, works in practice */
51089 return pv->put_chars(pv->termno, (char *)packet, packet->len);
51090 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
51091
51092 /* Reset state */
51093 pv->established = 0;
51094 - atomic_set(&pv->seqno, 0);
51095 + atomic_set_unchecked(&pv->seqno, 0);
51096
51097 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
51098
51099 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
51100 index 17ee3bf..8d2520d 100644
51101 --- a/drivers/tty/ipwireless/tty.c
51102 +++ b/drivers/tty/ipwireless/tty.c
51103 @@ -28,6 +28,7 @@
51104 #include <linux/tty_driver.h>
51105 #include <linux/tty_flip.h>
51106 #include <linux/uaccess.h>
51107 +#include <asm/local.h>
51108
51109 #include "tty.h"
51110 #include "network.h"
51111 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51112 mutex_unlock(&tty->ipw_tty_mutex);
51113 return -ENODEV;
51114 }
51115 - if (tty->port.count == 0)
51116 + if (atomic_read(&tty->port.count) == 0)
51117 tty->tx_bytes_queued = 0;
51118
51119 - tty->port.count++;
51120 + atomic_inc(&tty->port.count);
51121
51122 tty->port.tty = linux_tty;
51123 linux_tty->driver_data = tty;
51124 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51125
51126 static void do_ipw_close(struct ipw_tty *tty)
51127 {
51128 - tty->port.count--;
51129 -
51130 - if (tty->port.count == 0) {
51131 + if (atomic_dec_return(&tty->port.count) == 0) {
51132 struct tty_struct *linux_tty = tty->port.tty;
51133
51134 if (linux_tty != NULL) {
51135 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
51136 return;
51137
51138 mutex_lock(&tty->ipw_tty_mutex);
51139 - if (tty->port.count == 0) {
51140 + if (atomic_read(&tty->port.count) == 0) {
51141 mutex_unlock(&tty->ipw_tty_mutex);
51142 return;
51143 }
51144 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
51145
51146 mutex_lock(&tty->ipw_tty_mutex);
51147
51148 - if (!tty->port.count) {
51149 + if (!atomic_read(&tty->port.count)) {
51150 mutex_unlock(&tty->ipw_tty_mutex);
51151 return;
51152 }
51153 @@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
51154 return -ENODEV;
51155
51156 mutex_lock(&tty->ipw_tty_mutex);
51157 - if (!tty->port.count) {
51158 + if (!atomic_read(&tty->port.count)) {
51159 mutex_unlock(&tty->ipw_tty_mutex);
51160 return -EINVAL;
51161 }
51162 @@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
51163 if (!tty)
51164 return -ENODEV;
51165
51166 - if (!tty->port.count)
51167 + if (!atomic_read(&tty->port.count))
51168 return -EINVAL;
51169
51170 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
51171 @@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
51172 if (!tty)
51173 return 0;
51174
51175 - if (!tty->port.count)
51176 + if (!atomic_read(&tty->port.count))
51177 return 0;
51178
51179 return tty->tx_bytes_queued;
51180 @@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
51181 if (!tty)
51182 return -ENODEV;
51183
51184 - if (!tty->port.count)
51185 + if (!atomic_read(&tty->port.count))
51186 return -EINVAL;
51187
51188 return get_control_lines(tty);
51189 @@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
51190 if (!tty)
51191 return -ENODEV;
51192
51193 - if (!tty->port.count)
51194 + if (!atomic_read(&tty->port.count))
51195 return -EINVAL;
51196
51197 return set_control_lines(tty, set, clear);
51198 @@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
51199 if (!tty)
51200 return -ENODEV;
51201
51202 - if (!tty->port.count)
51203 + if (!atomic_read(&tty->port.count))
51204 return -EINVAL;
51205
51206 /* FIXME: Exactly how is the tty object locked here .. */
51207 @@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
51208 * are gone */
51209 mutex_lock(&ttyj->ipw_tty_mutex);
51210 }
51211 - while (ttyj->port.count)
51212 + while (atomic_read(&ttyj->port.count))
51213 do_ipw_close(ttyj);
51214 ipwireless_disassociate_network_ttys(network,
51215 ttyj->channel_idx);
51216 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
51217 index 1deaca4..c8582d4 100644
51218 --- a/drivers/tty/moxa.c
51219 +++ b/drivers/tty/moxa.c
51220 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
51221 }
51222
51223 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
51224 - ch->port.count++;
51225 + atomic_inc(&ch->port.count);
51226 tty->driver_data = ch;
51227 tty_port_tty_set(&ch->port, tty);
51228 mutex_lock(&ch->port.mutex);
51229 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
51230 index 2ebe47b..3205833 100644
51231 --- a/drivers/tty/n_gsm.c
51232 +++ b/drivers/tty/n_gsm.c
51233 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
51234 spin_lock_init(&dlci->lock);
51235 mutex_init(&dlci->mutex);
51236 dlci->fifo = &dlci->_fifo;
51237 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
51238 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
51239 kfree(dlci);
51240 return NULL;
51241 }
51242 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
51243 struct gsm_dlci *dlci = tty->driver_data;
51244 struct tty_port *port = &dlci->port;
51245
51246 - port->count++;
51247 + atomic_inc(&port->count);
51248 tty_port_tty_set(port, tty);
51249
51250 dlci->modem_rx = 0;
51251 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
51252 index e36d1f5..9938e3e 100644
51253 --- a/drivers/tty/n_tty.c
51254 +++ b/drivers/tty/n_tty.c
51255 @@ -115,7 +115,7 @@ struct n_tty_data {
51256 int minimum_to_wake;
51257
51258 /* consumer-published */
51259 - size_t read_tail;
51260 + size_t read_tail __intentional_overflow(-1);
51261 size_t line_start;
51262
51263 /* protected by output lock */
51264 @@ -2519,6 +2519,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
51265 {
51266 *ops = tty_ldisc_N_TTY;
51267 ops->owner = NULL;
51268 - ops->refcount = ops->flags = 0;
51269 + atomic_set(&ops->refcount, 0);
51270 + ops->flags = 0;
51271 }
51272 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
51273 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
51274 index 25c9bc7..24077b7 100644
51275 --- a/drivers/tty/pty.c
51276 +++ b/drivers/tty/pty.c
51277 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
51278 panic("Couldn't register Unix98 pts driver");
51279
51280 /* Now create the /dev/ptmx special device */
51281 + pax_open_kernel();
51282 tty_default_fops(&ptmx_fops);
51283 - ptmx_fops.open = ptmx_open;
51284 + *(void **)&ptmx_fops.open = ptmx_open;
51285 + pax_close_kernel();
51286
51287 cdev_init(&ptmx_cdev, &ptmx_fops);
51288 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
51289 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
51290 index 383c4c7..d408e21 100644
51291 --- a/drivers/tty/rocket.c
51292 +++ b/drivers/tty/rocket.c
51293 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51294 tty->driver_data = info;
51295 tty_port_tty_set(port, tty);
51296
51297 - if (port->count++ == 0) {
51298 + if (atomic_inc_return(&port->count) == 1) {
51299 atomic_inc(&rp_num_ports_open);
51300
51301 #ifdef ROCKET_DEBUG_OPEN
51302 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51303 #endif
51304 }
51305 #ifdef ROCKET_DEBUG_OPEN
51306 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
51307 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
51308 #endif
51309
51310 /*
51311 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
51312 spin_unlock_irqrestore(&info->port.lock, flags);
51313 return;
51314 }
51315 - if (info->port.count)
51316 + if (atomic_read(&info->port.count))
51317 atomic_dec(&rp_num_ports_open);
51318 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51319 spin_unlock_irqrestore(&info->port.lock, flags);
51320 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51321 index 1274499..f541382 100644
51322 --- a/drivers/tty/serial/ioc4_serial.c
51323 +++ b/drivers/tty/serial/ioc4_serial.c
51324 @@ -437,7 +437,7 @@ struct ioc4_soft {
51325 } is_intr_info[MAX_IOC4_INTR_ENTS];
51326
51327 /* Number of entries active in the above array */
51328 - atomic_t is_num_intrs;
51329 + atomic_unchecked_t is_num_intrs;
51330 } is_intr_type[IOC4_NUM_INTR_TYPES];
51331
51332 /* is_ir_lock must be held while
51333 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51334 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51335 || (type == IOC4_OTHER_INTR_TYPE)));
51336
51337 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51338 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51339 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51340
51341 /* Save off the lower level interrupt handler */
51342 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51343
51344 soft = arg;
51345 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51346 - num_intrs = (int)atomic_read(
51347 + num_intrs = (int)atomic_read_unchecked(
51348 &soft->is_intr_type[intr_type].is_num_intrs);
51349
51350 this_mir = this_ir = pending_intrs(soft, intr_type);
51351 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51352 index a260cde..6b2b5ce 100644
51353 --- a/drivers/tty/serial/kgdboc.c
51354 +++ b/drivers/tty/serial/kgdboc.c
51355 @@ -24,8 +24,9 @@
51356 #define MAX_CONFIG_LEN 40
51357
51358 static struct kgdb_io kgdboc_io_ops;
51359 +static struct kgdb_io kgdboc_io_ops_console;
51360
51361 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51362 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51363 static int configured = -1;
51364
51365 static char config[MAX_CONFIG_LEN];
51366 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51367 kgdboc_unregister_kbd();
51368 if (configured == 1)
51369 kgdb_unregister_io_module(&kgdboc_io_ops);
51370 + else if (configured == 2)
51371 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
51372 }
51373
51374 static int configure_kgdboc(void)
51375 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51376 int err;
51377 char *cptr = config;
51378 struct console *cons;
51379 + int is_console = 0;
51380
51381 err = kgdboc_option_setup(config);
51382 if (err || !strlen(config) || isspace(config[0]))
51383 goto noconfig;
51384
51385 err = -ENODEV;
51386 - kgdboc_io_ops.is_console = 0;
51387 kgdb_tty_driver = NULL;
51388
51389 kgdboc_use_kms = 0;
51390 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51391 int idx;
51392 if (cons->device && cons->device(cons, &idx) == p &&
51393 idx == tty_line) {
51394 - kgdboc_io_ops.is_console = 1;
51395 + is_console = 1;
51396 break;
51397 }
51398 cons = cons->next;
51399 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51400 kgdb_tty_line = tty_line;
51401
51402 do_register:
51403 - err = kgdb_register_io_module(&kgdboc_io_ops);
51404 + if (is_console) {
51405 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
51406 + configured = 2;
51407 + } else {
51408 + err = kgdb_register_io_module(&kgdboc_io_ops);
51409 + configured = 1;
51410 + }
51411 if (err)
51412 goto noconfig;
51413
51414 @@ -205,8 +214,6 @@ do_register:
51415 if (err)
51416 goto nmi_con_failed;
51417
51418 - configured = 1;
51419 -
51420 return 0;
51421
51422 nmi_con_failed:
51423 @@ -223,7 +230,7 @@ noconfig:
51424 static int __init init_kgdboc(void)
51425 {
51426 /* Already configured? */
51427 - if (configured == 1)
51428 + if (configured >= 1)
51429 return 0;
51430
51431 return configure_kgdboc();
51432 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51433 if (config[len - 1] == '\n')
51434 config[len - 1] = '\0';
51435
51436 - if (configured == 1)
51437 + if (configured >= 1)
51438 cleanup_kgdboc();
51439
51440 /* Go and configure with the new params. */
51441 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51442 .post_exception = kgdboc_post_exp_handler,
51443 };
51444
51445 +static struct kgdb_io kgdboc_io_ops_console = {
51446 + .name = "kgdboc",
51447 + .read_char = kgdboc_get_char,
51448 + .write_char = kgdboc_put_char,
51449 + .pre_exception = kgdboc_pre_exp_handler,
51450 + .post_exception = kgdboc_post_exp_handler,
51451 + .is_console = 1
51452 +};
51453 +
51454 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51455 /* This is only available if kgdboc is a built in for early debugging */
51456 static int __init kgdboc_early_init(char *opt)
51457 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51458 index b5d779c..3622cfe 100644
51459 --- a/drivers/tty/serial/msm_serial.c
51460 +++ b/drivers/tty/serial/msm_serial.c
51461 @@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
51462 .cons = MSM_CONSOLE,
51463 };
51464
51465 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51466 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51467
51468 static const struct of_device_id msm_uartdm_table[] = {
51469 { .compatible = "qcom,msm-uartdm" },
51470 @@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51471 int irq;
51472
51473 if (pdev->id == -1)
51474 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51475 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51476
51477 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51478 return -ENXIO;
51479 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51480 index 9cd706d..6ff2de7 100644
51481 --- a/drivers/tty/serial/samsung.c
51482 +++ b/drivers/tty/serial/samsung.c
51483 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51484 }
51485 }
51486
51487 +static int s3c64xx_serial_startup(struct uart_port *port);
51488 static int s3c24xx_serial_startup(struct uart_port *port)
51489 {
51490 struct s3c24xx_uart_port *ourport = to_ourport(port);
51491 int ret;
51492
51493 + /* Startup sequence is different for s3c64xx and higher SoC's */
51494 + if (s3c24xx_serial_has_interrupt_mask(port))
51495 + return s3c64xx_serial_startup(port);
51496 +
51497 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51498 port->mapbase, port->membase);
51499
51500 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51501 /* setup info for port */
51502 port->dev = &platdev->dev;
51503
51504 - /* Startup sequence is different for s3c64xx and higher SoC's */
51505 - if (s3c24xx_serial_has_interrupt_mask(port))
51506 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51507 -
51508 port->uartclk = 1;
51509
51510 if (cfg->uart_flags & UPF_CONS_FLOW) {
51511 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51512 index ece2049..fba2524 100644
51513 --- a/drivers/tty/serial/serial_core.c
51514 +++ b/drivers/tty/serial/serial_core.c
51515 @@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
51516 uart_flush_buffer(tty);
51517 uart_shutdown(tty, state);
51518 spin_lock_irqsave(&port->lock, flags);
51519 - port->count = 0;
51520 + atomic_set(&port->count, 0);
51521 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51522 spin_unlock_irqrestore(&port->lock, flags);
51523 tty_port_tty_set(port, NULL);
51524 @@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51525 goto end;
51526 }
51527
51528 - port->count++;
51529 + atomic_inc(&port->count);
51530 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51531 retval = -ENXIO;
51532 goto err_dec_count;
51533 @@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51534 /*
51535 * Make sure the device is in D0 state.
51536 */
51537 - if (port->count == 1)
51538 + if (atomic_read(&port->count) == 1)
51539 uart_change_pm(state, UART_PM_STATE_ON);
51540
51541 /*
51542 @@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51543 end:
51544 return retval;
51545 err_dec_count:
51546 - port->count--;
51547 + atomic_inc(&port->count);
51548 mutex_unlock(&port->mutex);
51549 goto end;
51550 }
51551 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51552 index 5ae14b4..2c1288f 100644
51553 --- a/drivers/tty/synclink.c
51554 +++ b/drivers/tty/synclink.c
51555 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51556
51557 if (debug_level >= DEBUG_LEVEL_INFO)
51558 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51559 - __FILE__,__LINE__, info->device_name, info->port.count);
51560 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51561
51562 if (tty_port_close_start(&info->port, tty, filp) == 0)
51563 goto cleanup;
51564 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51565 cleanup:
51566 if (debug_level >= DEBUG_LEVEL_INFO)
51567 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51568 - tty->driver->name, info->port.count);
51569 + tty->driver->name, atomic_read(&info->port.count));
51570
51571 } /* end of mgsl_close() */
51572
51573 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51574
51575 mgsl_flush_buffer(tty);
51576 shutdown(info);
51577 -
51578 - info->port.count = 0;
51579 +
51580 + atomic_set(&info->port.count, 0);
51581 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51582 info->port.tty = NULL;
51583
51584 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51585
51586 if (debug_level >= DEBUG_LEVEL_INFO)
51587 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51588 - __FILE__,__LINE__, tty->driver->name, port->count );
51589 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51590
51591 spin_lock_irqsave(&info->irq_spinlock, flags);
51592 if (!tty_hung_up_p(filp)) {
51593 extra_count = true;
51594 - port->count--;
51595 + atomic_dec(&port->count);
51596 }
51597 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51598 port->blocked_open++;
51599 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51600
51601 if (debug_level >= DEBUG_LEVEL_INFO)
51602 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51603 - __FILE__,__LINE__, tty->driver->name, port->count );
51604 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51605
51606 tty_unlock(tty);
51607 schedule();
51608 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51609
51610 /* FIXME: Racy on hangup during close wait */
51611 if (extra_count)
51612 - port->count++;
51613 + atomic_inc(&port->count);
51614 port->blocked_open--;
51615
51616 if (debug_level >= DEBUG_LEVEL_INFO)
51617 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51618 - __FILE__,__LINE__, tty->driver->name, port->count );
51619 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51620
51621 if (!retval)
51622 port->flags |= ASYNC_NORMAL_ACTIVE;
51623 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51624
51625 if (debug_level >= DEBUG_LEVEL_INFO)
51626 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51627 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51628 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51629
51630 /* If port is closing, signal caller to try again */
51631 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51632 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51633 spin_unlock_irqrestore(&info->netlock, flags);
51634 goto cleanup;
51635 }
51636 - info->port.count++;
51637 + atomic_inc(&info->port.count);
51638 spin_unlock_irqrestore(&info->netlock, flags);
51639
51640 - if (info->port.count == 1) {
51641 + if (atomic_read(&info->port.count) == 1) {
51642 /* 1st open on this device, init hardware */
51643 retval = startup(info);
51644 if (retval < 0)
51645 @@ -3446,8 +3446,8 @@ cleanup:
51646 if (retval) {
51647 if (tty->count == 1)
51648 info->port.tty = NULL; /* tty layer will release tty struct */
51649 - if(info->port.count)
51650 - info->port.count--;
51651 + if (atomic_read(&info->port.count))
51652 + atomic_dec(&info->port.count);
51653 }
51654
51655 return retval;
51656 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51657 unsigned short new_crctype;
51658
51659 /* return error if TTY interface open */
51660 - if (info->port.count)
51661 + if (atomic_read(&info->port.count))
51662 return -EBUSY;
51663
51664 switch (encoding)
51665 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51666
51667 /* arbitrate between network and tty opens */
51668 spin_lock_irqsave(&info->netlock, flags);
51669 - if (info->port.count != 0 || info->netcount != 0) {
51670 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51671 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51672 spin_unlock_irqrestore(&info->netlock, flags);
51673 return -EBUSY;
51674 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51675 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51676
51677 /* return error if TTY interface open */
51678 - if (info->port.count)
51679 + if (atomic_read(&info->port.count))
51680 return -EBUSY;
51681
51682 if (cmd != SIOCWANDEV)
51683 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51684 index c359a91..959fc26 100644
51685 --- a/drivers/tty/synclink_gt.c
51686 +++ b/drivers/tty/synclink_gt.c
51687 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51688 tty->driver_data = info;
51689 info->port.tty = tty;
51690
51691 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51692 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51693
51694 /* If port is closing, signal caller to try again */
51695 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51696 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51697 mutex_unlock(&info->port.mutex);
51698 goto cleanup;
51699 }
51700 - info->port.count++;
51701 + atomic_inc(&info->port.count);
51702 spin_unlock_irqrestore(&info->netlock, flags);
51703
51704 - if (info->port.count == 1) {
51705 + if (atomic_read(&info->port.count) == 1) {
51706 /* 1st open on this device, init hardware */
51707 retval = startup(info);
51708 if (retval < 0) {
51709 @@ -715,8 +715,8 @@ cleanup:
51710 if (retval) {
51711 if (tty->count == 1)
51712 info->port.tty = NULL; /* tty layer will release tty struct */
51713 - if(info->port.count)
51714 - info->port.count--;
51715 + if(atomic_read(&info->port.count))
51716 + atomic_dec(&info->port.count);
51717 }
51718
51719 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51720 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51721
51722 if (sanity_check(info, tty->name, "close"))
51723 return;
51724 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51725 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51726
51727 if (tty_port_close_start(&info->port, tty, filp) == 0)
51728 goto cleanup;
51729 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51730 tty_port_close_end(&info->port, tty);
51731 info->port.tty = NULL;
51732 cleanup:
51733 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51734 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51735 }
51736
51737 static void hangup(struct tty_struct *tty)
51738 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51739 shutdown(info);
51740
51741 spin_lock_irqsave(&info->port.lock, flags);
51742 - info->port.count = 0;
51743 + atomic_set(&info->port.count, 0);
51744 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51745 info->port.tty = NULL;
51746 spin_unlock_irqrestore(&info->port.lock, flags);
51747 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51748 unsigned short new_crctype;
51749
51750 /* return error if TTY interface open */
51751 - if (info->port.count)
51752 + if (atomic_read(&info->port.count))
51753 return -EBUSY;
51754
51755 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51756 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51757
51758 /* arbitrate between network and tty opens */
51759 spin_lock_irqsave(&info->netlock, flags);
51760 - if (info->port.count != 0 || info->netcount != 0) {
51761 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51762 DBGINFO(("%s hdlc_open busy\n", dev->name));
51763 spin_unlock_irqrestore(&info->netlock, flags);
51764 return -EBUSY;
51765 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51766 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51767
51768 /* return error if TTY interface open */
51769 - if (info->port.count)
51770 + if (atomic_read(&info->port.count))
51771 return -EBUSY;
51772
51773 if (cmd != SIOCWANDEV)
51774 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51775 if (port == NULL)
51776 continue;
51777 spin_lock(&port->lock);
51778 - if ((port->port.count || port->netcount) &&
51779 + if ((atomic_read(&port->port.count) || port->netcount) &&
51780 port->pending_bh && !port->bh_running &&
51781 !port->bh_requested) {
51782 DBGISR(("%s bh queued\n", port->device_name));
51783 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51784 spin_lock_irqsave(&info->lock, flags);
51785 if (!tty_hung_up_p(filp)) {
51786 extra_count = true;
51787 - port->count--;
51788 + atomic_dec(&port->count);
51789 }
51790 spin_unlock_irqrestore(&info->lock, flags);
51791 port->blocked_open++;
51792 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51793 remove_wait_queue(&port->open_wait, &wait);
51794
51795 if (extra_count)
51796 - port->count++;
51797 + atomic_inc(&port->count);
51798 port->blocked_open--;
51799
51800 if (!retval)
51801 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51802 index 144202e..4ccb07d 100644
51803 --- a/drivers/tty/synclinkmp.c
51804 +++ b/drivers/tty/synclinkmp.c
51805 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51806
51807 if (debug_level >= DEBUG_LEVEL_INFO)
51808 printk("%s(%d):%s open(), old ref count = %d\n",
51809 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51810 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51811
51812 /* If port is closing, signal caller to try again */
51813 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51814 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51815 spin_unlock_irqrestore(&info->netlock, flags);
51816 goto cleanup;
51817 }
51818 - info->port.count++;
51819 + atomic_inc(&info->port.count);
51820 spin_unlock_irqrestore(&info->netlock, flags);
51821
51822 - if (info->port.count == 1) {
51823 + if (atomic_read(&info->port.count) == 1) {
51824 /* 1st open on this device, init hardware */
51825 retval = startup(info);
51826 if (retval < 0)
51827 @@ -796,8 +796,8 @@ cleanup:
51828 if (retval) {
51829 if (tty->count == 1)
51830 info->port.tty = NULL; /* tty layer will release tty struct */
51831 - if(info->port.count)
51832 - info->port.count--;
51833 + if(atomic_read(&info->port.count))
51834 + atomic_dec(&info->port.count);
51835 }
51836
51837 return retval;
51838 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51839
51840 if (debug_level >= DEBUG_LEVEL_INFO)
51841 printk("%s(%d):%s close() entry, count=%d\n",
51842 - __FILE__,__LINE__, info->device_name, info->port.count);
51843 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51844
51845 if (tty_port_close_start(&info->port, tty, filp) == 0)
51846 goto cleanup;
51847 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51848 cleanup:
51849 if (debug_level >= DEBUG_LEVEL_INFO)
51850 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51851 - tty->driver->name, info->port.count);
51852 + tty->driver->name, atomic_read(&info->port.count));
51853 }
51854
51855 /* Called by tty_hangup() when a hangup is signaled.
51856 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51857 shutdown(info);
51858
51859 spin_lock_irqsave(&info->port.lock, flags);
51860 - info->port.count = 0;
51861 + atomic_set(&info->port.count, 0);
51862 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51863 info->port.tty = NULL;
51864 spin_unlock_irqrestore(&info->port.lock, flags);
51865 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51866 unsigned short new_crctype;
51867
51868 /* return error if TTY interface open */
51869 - if (info->port.count)
51870 + if (atomic_read(&info->port.count))
51871 return -EBUSY;
51872
51873 switch (encoding)
51874 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51875
51876 /* arbitrate between network and tty opens */
51877 spin_lock_irqsave(&info->netlock, flags);
51878 - if (info->port.count != 0 || info->netcount != 0) {
51879 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51880 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51881 spin_unlock_irqrestore(&info->netlock, flags);
51882 return -EBUSY;
51883 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51884 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51885
51886 /* return error if TTY interface open */
51887 - if (info->port.count)
51888 + if (atomic_read(&info->port.count))
51889 return -EBUSY;
51890
51891 if (cmd != SIOCWANDEV)
51892 @@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51893 * do not request bottom half processing if the
51894 * device is not open in a normal mode.
51895 */
51896 - if ( port && (port->port.count || port->netcount) &&
51897 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51898 port->pending_bh && !port->bh_running &&
51899 !port->bh_requested ) {
51900 if ( debug_level >= DEBUG_LEVEL_ISR )
51901 @@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51902
51903 if (debug_level >= DEBUG_LEVEL_INFO)
51904 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51905 - __FILE__,__LINE__, tty->driver->name, port->count );
51906 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51907
51908 spin_lock_irqsave(&info->lock, flags);
51909 if (!tty_hung_up_p(filp)) {
51910 extra_count = true;
51911 - port->count--;
51912 + atomic_dec(&port->count);
51913 }
51914 spin_unlock_irqrestore(&info->lock, flags);
51915 port->blocked_open++;
51916 @@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51917
51918 if (debug_level >= DEBUG_LEVEL_INFO)
51919 printk("%s(%d):%s block_til_ready() count=%d\n",
51920 - __FILE__,__LINE__, tty->driver->name, port->count );
51921 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51922
51923 tty_unlock(tty);
51924 schedule();
51925 @@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51926 remove_wait_queue(&port->open_wait, &wait);
51927
51928 if (extra_count)
51929 - port->count++;
51930 + atomic_inc(&port->count);
51931 port->blocked_open--;
51932
51933 if (debug_level >= DEBUG_LEVEL_INFO)
51934 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51935 - __FILE__,__LINE__, tty->driver->name, port->count );
51936 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51937
51938 if (!retval)
51939 port->flags |= ASYNC_NORMAL_ACTIVE;
51940 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51941 index ce396ec..04a37be 100644
51942 --- a/drivers/tty/sysrq.c
51943 +++ b/drivers/tty/sysrq.c
51944 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51945 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51946 size_t count, loff_t *ppos)
51947 {
51948 - if (count) {
51949 + if (count && capable(CAP_SYS_ADMIN)) {
51950 char c;
51951
51952 if (get_user(c, buf))
51953 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51954 index d3448a9..28e8db0 100644
51955 --- a/drivers/tty/tty_io.c
51956 +++ b/drivers/tty/tty_io.c
51957 @@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51958
51959 void tty_default_fops(struct file_operations *fops)
51960 {
51961 - *fops = tty_fops;
51962 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51963 }
51964
51965 /*
51966 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51967 index 2d822aa..a566234 100644
51968 --- a/drivers/tty/tty_ldisc.c
51969 +++ b/drivers/tty/tty_ldisc.c
51970 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51971 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51972 tty_ldiscs[disc] = new_ldisc;
51973 new_ldisc->num = disc;
51974 - new_ldisc->refcount = 0;
51975 + atomic_set(&new_ldisc->refcount, 0);
51976 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51977
51978 return ret;
51979 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51980 return -EINVAL;
51981
51982 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51983 - if (tty_ldiscs[disc]->refcount)
51984 + if (atomic_read(&tty_ldiscs[disc]->refcount))
51985 ret = -EBUSY;
51986 else
51987 tty_ldiscs[disc] = NULL;
51988 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51989 if (ldops) {
51990 ret = ERR_PTR(-EAGAIN);
51991 if (try_module_get(ldops->owner)) {
51992 - ldops->refcount++;
51993 + atomic_inc(&ldops->refcount);
51994 ret = ldops;
51995 }
51996 }
51997 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51998 unsigned long flags;
51999
52000 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
52001 - ldops->refcount--;
52002 + atomic_dec(&ldops->refcount);
52003 module_put(ldops->owner);
52004 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
52005 }
52006 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
52007 index 3f746c8..2f2fcaa 100644
52008 --- a/drivers/tty/tty_port.c
52009 +++ b/drivers/tty/tty_port.c
52010 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
52011 unsigned long flags;
52012
52013 spin_lock_irqsave(&port->lock, flags);
52014 - port->count = 0;
52015 + atomic_set(&port->count, 0);
52016 port->flags &= ~ASYNC_NORMAL_ACTIVE;
52017 tty = port->tty;
52018 if (tty)
52019 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52020 /* The port lock protects the port counts */
52021 spin_lock_irqsave(&port->lock, flags);
52022 if (!tty_hung_up_p(filp))
52023 - port->count--;
52024 + atomic_dec(&port->count);
52025 port->blocked_open++;
52026 spin_unlock_irqrestore(&port->lock, flags);
52027
52028 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
52029 we must not mess that up further */
52030 spin_lock_irqsave(&port->lock, flags);
52031 if (!tty_hung_up_p(filp))
52032 - port->count++;
52033 + atomic_inc(&port->count);
52034 port->blocked_open--;
52035 if (retval == 0)
52036 port->flags |= ASYNC_NORMAL_ACTIVE;
52037 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
52038 return 0;
52039 }
52040
52041 - if (tty->count == 1 && port->count != 1) {
52042 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
52043 printk(KERN_WARNING
52044 "tty_port_close_start: tty->count = 1 port count = %d.\n",
52045 - port->count);
52046 - port->count = 1;
52047 + atomic_read(&port->count));
52048 + atomic_set(&port->count, 1);
52049 }
52050 - if (--port->count < 0) {
52051 + if (atomic_dec_return(&port->count) < 0) {
52052 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
52053 - port->count);
52054 - port->count = 0;
52055 + atomic_read(&port->count));
52056 + atomic_set(&port->count, 0);
52057 }
52058
52059 - if (port->count) {
52060 + if (atomic_read(&port->count)) {
52061 spin_unlock_irqrestore(&port->lock, flags);
52062 return 0;
52063 }
52064 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
52065 {
52066 spin_lock_irq(&port->lock);
52067 if (!tty_hung_up_p(filp))
52068 - ++port->count;
52069 + atomic_inc(&port->count);
52070 spin_unlock_irq(&port->lock);
52071 tty_port_tty_set(port, tty);
52072
52073 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
52074 index d0e3a44..5f8b754 100644
52075 --- a/drivers/tty/vt/keyboard.c
52076 +++ b/drivers/tty/vt/keyboard.c
52077 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
52078 kbd->kbdmode == VC_OFF) &&
52079 value != KVAL(K_SAK))
52080 return; /* SAK is allowed even in raw mode */
52081 +
52082 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52083 + {
52084 + void *func = fn_handler[value];
52085 + if (func == fn_show_state || func == fn_show_ptregs ||
52086 + func == fn_show_mem)
52087 + return;
52088 + }
52089 +#endif
52090 +
52091 fn_handler[value](vc);
52092 }
52093
52094 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52095 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
52096 return -EFAULT;
52097
52098 - if (!capable(CAP_SYS_TTY_CONFIG))
52099 - perm = 0;
52100 -
52101 switch (cmd) {
52102 case KDGKBENT:
52103 /* Ensure another thread doesn't free it under us */
52104 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52105 spin_unlock_irqrestore(&kbd_event_lock, flags);
52106 return put_user(val, &user_kbe->kb_value);
52107 case KDSKBENT:
52108 + if (!capable(CAP_SYS_TTY_CONFIG))
52109 + perm = 0;
52110 +
52111 if (!perm)
52112 return -EPERM;
52113 if (!i && v == K_NOSUCHMAP) {
52114 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52115 int i, j, k;
52116 int ret;
52117
52118 - if (!capable(CAP_SYS_TTY_CONFIG))
52119 - perm = 0;
52120 -
52121 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
52122 if (!kbs) {
52123 ret = -ENOMEM;
52124 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52125 kfree(kbs);
52126 return ((p && *p) ? -EOVERFLOW : 0);
52127 case KDSKBSENT:
52128 + if (!capable(CAP_SYS_TTY_CONFIG))
52129 + perm = 0;
52130 +
52131 if (!perm) {
52132 ret = -EPERM;
52133 goto reterr;
52134 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
52135 index a673e5b..36e5d32 100644
52136 --- a/drivers/uio/uio.c
52137 +++ b/drivers/uio/uio.c
52138 @@ -25,6 +25,7 @@
52139 #include <linux/kobject.h>
52140 #include <linux/cdev.h>
52141 #include <linux/uio_driver.h>
52142 +#include <asm/local.h>
52143
52144 #define UIO_MAX_DEVICES (1U << MINORBITS)
52145
52146 @@ -32,7 +33,7 @@ struct uio_device {
52147 struct module *owner;
52148 struct device *dev;
52149 int minor;
52150 - atomic_t event;
52151 + atomic_unchecked_t event;
52152 struct fasync_struct *async_queue;
52153 wait_queue_head_t wait;
52154 struct uio_info *info;
52155 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
52156 struct device_attribute *attr, char *buf)
52157 {
52158 struct uio_device *idev = dev_get_drvdata(dev);
52159 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
52160 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
52161 }
52162 static DEVICE_ATTR_RO(event);
52163
52164 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
52165 {
52166 struct uio_device *idev = info->uio_dev;
52167
52168 - atomic_inc(&idev->event);
52169 + atomic_inc_unchecked(&idev->event);
52170 wake_up_interruptible(&idev->wait);
52171 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
52172 }
52173 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
52174 }
52175
52176 listener->dev = idev;
52177 - listener->event_count = atomic_read(&idev->event);
52178 + listener->event_count = atomic_read_unchecked(&idev->event);
52179 filep->private_data = listener;
52180
52181 if (idev->info->open) {
52182 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
52183 return -EIO;
52184
52185 poll_wait(filep, &idev->wait, wait);
52186 - if (listener->event_count != atomic_read(&idev->event))
52187 + if (listener->event_count != atomic_read_unchecked(&idev->event))
52188 return POLLIN | POLLRDNORM;
52189 return 0;
52190 }
52191 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
52192 do {
52193 set_current_state(TASK_INTERRUPTIBLE);
52194
52195 - event_count = atomic_read(&idev->event);
52196 + event_count = atomic_read_unchecked(&idev->event);
52197 if (event_count != listener->event_count) {
52198 if (copy_to_user(buf, &event_count, count))
52199 retval = -EFAULT;
52200 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
52201 static int uio_find_mem_index(struct vm_area_struct *vma)
52202 {
52203 struct uio_device *idev = vma->vm_private_data;
52204 + unsigned long size;
52205
52206 if (vma->vm_pgoff < MAX_UIO_MAPS) {
52207 - if (idev->info->mem[vma->vm_pgoff].size == 0)
52208 + size = idev->info->mem[vma->vm_pgoff].size;
52209 + if (size == 0)
52210 + return -1;
52211 + if (vma->vm_end - vma->vm_start > size)
52212 return -1;
52213 return (int)vma->vm_pgoff;
52214 }
52215 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
52216 idev->owner = owner;
52217 idev->info = info;
52218 init_waitqueue_head(&idev->wait);
52219 - atomic_set(&idev->event, 0);
52220 + atomic_set_unchecked(&idev->event, 0);
52221
52222 ret = uio_get_minor(idev);
52223 if (ret)
52224 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
52225 index 813d4d3..a71934f 100644
52226 --- a/drivers/usb/atm/cxacru.c
52227 +++ b/drivers/usb/atm/cxacru.c
52228 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
52229 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
52230 if (ret < 2)
52231 return -EINVAL;
52232 - if (index < 0 || index > 0x7f)
52233 + if (index > 0x7f)
52234 return -EINVAL;
52235 pos += tmp;
52236
52237 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
52238 index dada014..1d0d517 100644
52239 --- a/drivers/usb/atm/usbatm.c
52240 +++ b/drivers/usb/atm/usbatm.c
52241 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52242 if (printk_ratelimit())
52243 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
52244 __func__, vpi, vci);
52245 - atomic_inc(&vcc->stats->rx_err);
52246 + atomic_inc_unchecked(&vcc->stats->rx_err);
52247 return;
52248 }
52249
52250 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52251 if (length > ATM_MAX_AAL5_PDU) {
52252 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
52253 __func__, length, vcc);
52254 - atomic_inc(&vcc->stats->rx_err);
52255 + atomic_inc_unchecked(&vcc->stats->rx_err);
52256 goto out;
52257 }
52258
52259 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52260 if (sarb->len < pdu_length) {
52261 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
52262 __func__, pdu_length, sarb->len, vcc);
52263 - atomic_inc(&vcc->stats->rx_err);
52264 + atomic_inc_unchecked(&vcc->stats->rx_err);
52265 goto out;
52266 }
52267
52268 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
52269 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
52270 __func__, vcc);
52271 - atomic_inc(&vcc->stats->rx_err);
52272 + atomic_inc_unchecked(&vcc->stats->rx_err);
52273 goto out;
52274 }
52275
52276 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52277 if (printk_ratelimit())
52278 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
52279 __func__, length);
52280 - atomic_inc(&vcc->stats->rx_drop);
52281 + atomic_inc_unchecked(&vcc->stats->rx_drop);
52282 goto out;
52283 }
52284
52285 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52286
52287 vcc->push(vcc, skb);
52288
52289 - atomic_inc(&vcc->stats->rx);
52290 + atomic_inc_unchecked(&vcc->stats->rx);
52291 out:
52292 skb_trim(sarb, 0);
52293 }
52294 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
52295 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
52296
52297 usbatm_pop(vcc, skb);
52298 - atomic_inc(&vcc->stats->tx);
52299 + atomic_inc_unchecked(&vcc->stats->tx);
52300
52301 skb = skb_dequeue(&instance->sndqueue);
52302 }
52303 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
52304 if (!left--)
52305 return sprintf(page,
52306 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
52307 - atomic_read(&atm_dev->stats.aal5.tx),
52308 - atomic_read(&atm_dev->stats.aal5.tx_err),
52309 - atomic_read(&atm_dev->stats.aal5.rx),
52310 - atomic_read(&atm_dev->stats.aal5.rx_err),
52311 - atomic_read(&atm_dev->stats.aal5.rx_drop));
52312 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
52313 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
52314 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
52315 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52316 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52317
52318 if (!left--) {
52319 if (instance->disconnected)
52320 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52321 index 2a3bbdf..91d72cf 100644
52322 --- a/drivers/usb/core/devices.c
52323 +++ b/drivers/usb/core/devices.c
52324 @@ -126,7 +126,7 @@ static const char format_endpt[] =
52325 * time it gets called.
52326 */
52327 static struct device_connect_event {
52328 - atomic_t count;
52329 + atomic_unchecked_t count;
52330 wait_queue_head_t wait;
52331 } device_event = {
52332 .count = ATOMIC_INIT(1),
52333 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52334
52335 void usbfs_conn_disc_event(void)
52336 {
52337 - atomic_add(2, &device_event.count);
52338 + atomic_add_unchecked(2, &device_event.count);
52339 wake_up(&device_event.wait);
52340 }
52341
52342 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52343
52344 poll_wait(file, &device_event.wait, wait);
52345
52346 - event_count = atomic_read(&device_event.count);
52347 + event_count = atomic_read_unchecked(&device_event.count);
52348 if (file->f_version != event_count) {
52349 file->f_version = event_count;
52350 return POLLIN | POLLRDNORM;
52351 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52352 index 90e18f6..5eeda46 100644
52353 --- a/drivers/usb/core/devio.c
52354 +++ b/drivers/usb/core/devio.c
52355 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52356 struct dev_state *ps = file->private_data;
52357 struct usb_device *dev = ps->dev;
52358 ssize_t ret = 0;
52359 - unsigned len;
52360 + size_t len;
52361 loff_t pos;
52362 int i;
52363
52364 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52365 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52366 struct usb_config_descriptor *config =
52367 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52368 - unsigned int length = le16_to_cpu(config->wTotalLength);
52369 + size_t length = le16_to_cpu(config->wTotalLength);
52370
52371 if (*ppos < pos + length) {
52372
52373 /* The descriptor may claim to be longer than it
52374 * really is. Here is the actual allocated length. */
52375 - unsigned alloclen =
52376 + size_t alloclen =
52377 le16_to_cpu(dev->config[i].desc.wTotalLength);
52378
52379 - len = length - (*ppos - pos);
52380 + len = length + pos - *ppos;
52381 if (len > nbytes)
52382 len = nbytes;
52383
52384 /* Simply don't write (skip over) unallocated parts */
52385 if (alloclen > (*ppos - pos)) {
52386 - alloclen -= (*ppos - pos);
52387 + alloclen = alloclen + pos - *ppos;
52388 if (copy_to_user(buf,
52389 dev->rawdescriptors[i] + (*ppos - pos),
52390 min(len, alloclen))) {
52391 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52392 index 2518c32..1c201bb 100644
52393 --- a/drivers/usb/core/hcd.c
52394 +++ b/drivers/usb/core/hcd.c
52395 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52396 */
52397 usb_get_urb(urb);
52398 atomic_inc(&urb->use_count);
52399 - atomic_inc(&urb->dev->urbnum);
52400 + atomic_inc_unchecked(&urb->dev->urbnum);
52401 usbmon_urb_submit(&hcd->self, urb);
52402
52403 /* NOTE requirements on root-hub callers (usbfs and the hub
52404 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52405 urb->hcpriv = NULL;
52406 INIT_LIST_HEAD(&urb->urb_list);
52407 atomic_dec(&urb->use_count);
52408 - atomic_dec(&urb->dev->urbnum);
52409 + atomic_dec_unchecked(&urb->dev->urbnum);
52410 if (atomic_read(&urb->reject))
52411 wake_up(&usb_kill_urb_queue);
52412 usb_put_urb(urb);
52413 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52414 index d498d03..e26f959 100644
52415 --- a/drivers/usb/core/hub.c
52416 +++ b/drivers/usb/core/hub.c
52417 @@ -27,6 +27,7 @@
52418 #include <linux/freezer.h>
52419 #include <linux/random.h>
52420 #include <linux/pm_qos.h>
52421 +#include <linux/grsecurity.h>
52422
52423 #include <asm/uaccess.h>
52424 #include <asm/byteorder.h>
52425 @@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52426 goto done;
52427 return;
52428 }
52429 +
52430 + if (gr_handle_new_usb())
52431 + goto done;
52432 +
52433 if (hub_is_superspeed(hub->hdev))
52434 unit_load = 150;
52435 else
52436 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52437 index f829a1a..e6c334a 100644
52438 --- a/drivers/usb/core/message.c
52439 +++ b/drivers/usb/core/message.c
52440 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52441 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52442 * error number.
52443 */
52444 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52445 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52446 __u8 requesttype, __u16 value, __u16 index, void *data,
52447 __u16 size, int timeout)
52448 {
52449 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52450 * If successful, 0. Otherwise a negative error number. The number of actual
52451 * bytes transferred will be stored in the @actual_length paramater.
52452 */
52453 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52454 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52455 void *data, int len, int *actual_length, int timeout)
52456 {
52457 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52458 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52459 * bytes transferred will be stored in the @actual_length parameter.
52460 *
52461 */
52462 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52463 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52464 void *data, int len, int *actual_length, int timeout)
52465 {
52466 struct urb *urb;
52467 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52468 index 1236c60..d47a51c 100644
52469 --- a/drivers/usb/core/sysfs.c
52470 +++ b/drivers/usb/core/sysfs.c
52471 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52472 struct usb_device *udev;
52473
52474 udev = to_usb_device(dev);
52475 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52476 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52477 }
52478 static DEVICE_ATTR_RO(urbnum);
52479
52480 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52481 index 4d11449..f4ccabf 100644
52482 --- a/drivers/usb/core/usb.c
52483 +++ b/drivers/usb/core/usb.c
52484 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52485 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52486 dev->state = USB_STATE_ATTACHED;
52487 dev->lpm_disable_count = 1;
52488 - atomic_set(&dev->urbnum, 0);
52489 + atomic_set_unchecked(&dev->urbnum, 0);
52490
52491 INIT_LIST_HEAD(&dev->ep0.urb_list);
52492 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52493 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52494 index 2da0a5a..4870e09 100644
52495 --- a/drivers/usb/dwc3/gadget.c
52496 +++ b/drivers/usb/dwc3/gadget.c
52497 @@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52498 if (!usb_endpoint_xfer_isoc(desc))
52499 return 0;
52500
52501 - memset(&trb_link, 0, sizeof(trb_link));
52502 -
52503 /* Link TRB for ISOC. The HWO bit is never reset */
52504 trb_st_hw = &dep->trb_pool[0];
52505
52506 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52507 index 8cfc319..4868255 100644
52508 --- a/drivers/usb/early/ehci-dbgp.c
52509 +++ b/drivers/usb/early/ehci-dbgp.c
52510 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52511
52512 #ifdef CONFIG_KGDB
52513 static struct kgdb_io kgdbdbgp_io_ops;
52514 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52515 +static struct kgdb_io kgdbdbgp_io_ops_console;
52516 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52517 #else
52518 #define dbgp_kgdb_mode (0)
52519 #endif
52520 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52521 .write_char = kgdbdbgp_write_char,
52522 };
52523
52524 +static struct kgdb_io kgdbdbgp_io_ops_console = {
52525 + .name = "kgdbdbgp",
52526 + .read_char = kgdbdbgp_read_char,
52527 + .write_char = kgdbdbgp_write_char,
52528 + .is_console = 1
52529 +};
52530 +
52531 static int kgdbdbgp_wait_time;
52532
52533 static int __init kgdbdbgp_parse_config(char *str)
52534 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52535 ptr++;
52536 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52537 }
52538 - kgdb_register_io_module(&kgdbdbgp_io_ops);
52539 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52540 + if (early_dbgp_console.index != -1)
52541 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52542 + else
52543 + kgdb_register_io_module(&kgdbdbgp_io_ops);
52544
52545 return 0;
52546 }
52547 diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52548 index 2b4c82d..06a8ee6 100644
52549 --- a/drivers/usb/gadget/f_uac1.c
52550 +++ b/drivers/usb/gadget/f_uac1.c
52551 @@ -13,6 +13,7 @@
52552 #include <linux/kernel.h>
52553 #include <linux/device.h>
52554 #include <linux/atomic.h>
52555 +#include <linux/module.h>
52556
52557 #include "u_uac1.h"
52558
52559 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52560 index ad0aca8..8ff84865 100644
52561 --- a/drivers/usb/gadget/u_serial.c
52562 +++ b/drivers/usb/gadget/u_serial.c
52563 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52564 spin_lock_irq(&port->port_lock);
52565
52566 /* already open? Great. */
52567 - if (port->port.count) {
52568 + if (atomic_read(&port->port.count)) {
52569 status = 0;
52570 - port->port.count++;
52571 + atomic_inc(&port->port.count);
52572
52573 /* currently opening/closing? wait ... */
52574 } else if (port->openclose) {
52575 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52576 tty->driver_data = port;
52577 port->port.tty = tty;
52578
52579 - port->port.count = 1;
52580 + atomic_set(&port->port.count, 1);
52581 port->openclose = false;
52582
52583 /* if connected, start the I/O stream */
52584 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52585
52586 spin_lock_irq(&port->port_lock);
52587
52588 - if (port->port.count != 1) {
52589 - if (port->port.count == 0)
52590 + if (atomic_read(&port->port.count) != 1) {
52591 + if (atomic_read(&port->port.count) == 0)
52592 WARN_ON(1);
52593 else
52594 - --port->port.count;
52595 + atomic_dec(&port->port.count);
52596 goto exit;
52597 }
52598
52599 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52600 * and sleep if necessary
52601 */
52602 port->openclose = true;
52603 - port->port.count = 0;
52604 + atomic_set(&port->port.count, 0);
52605
52606 gser = port->port_usb;
52607 if (gser && gser->disconnect)
52608 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52609 int cond;
52610
52611 spin_lock_irq(&port->port_lock);
52612 - cond = (port->port.count == 0) && !port->openclose;
52613 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52614 spin_unlock_irq(&port->port_lock);
52615 return cond;
52616 }
52617 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52618 /* if it's already open, start I/O ... and notify the serial
52619 * protocol about open/close status (connect/disconnect).
52620 */
52621 - if (port->port.count) {
52622 + if (atomic_read(&port->port.count)) {
52623 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52624 gs_start_io(port);
52625 if (gser->connect)
52626 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52627
52628 port->port_usb = NULL;
52629 gser->ioport = NULL;
52630 - if (port->port.count > 0 || port->openclose) {
52631 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
52632 wake_up_interruptible(&port->drain_wait);
52633 if (port->port.tty)
52634 tty_hangup(port->port.tty);
52635 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52636
52637 /* finally, free any unused/unusable I/O buffers */
52638 spin_lock_irqsave(&port->port_lock, flags);
52639 - if (port->port.count == 0 && !port->openclose)
52640 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
52641 gs_buf_free(&port->port_write_buf);
52642 gs_free_requests(gser->out, &port->read_pool, NULL);
52643 gs_free_requests(gser->out, &port->read_queue, NULL);
52644 diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52645 index 7a55fea..cc0ed4f 100644
52646 --- a/drivers/usb/gadget/u_uac1.c
52647 +++ b/drivers/usb/gadget/u_uac1.c
52648 @@ -16,6 +16,7 @@
52649 #include <linux/ctype.h>
52650 #include <linux/random.h>
52651 #include <linux/syscalls.h>
52652 +#include <linux/module.h>
52653
52654 #include "u_uac1.h"
52655
52656 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52657 index 7ae0c4d..35521b7 100644
52658 --- a/drivers/usb/host/ehci-hub.c
52659 +++ b/drivers/usb/host/ehci-hub.c
52660 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52661 urb->transfer_flags = URB_DIR_IN;
52662 usb_get_urb(urb);
52663 atomic_inc(&urb->use_count);
52664 - atomic_inc(&urb->dev->urbnum);
52665 + atomic_inc_unchecked(&urb->dev->urbnum);
52666 urb->setup_dma = dma_map_single(
52667 hcd->self.controller,
52668 urb->setup_packet,
52669 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52670 urb->status = -EINPROGRESS;
52671 usb_get_urb(urb);
52672 atomic_inc(&urb->use_count);
52673 - atomic_inc(&urb->dev->urbnum);
52674 + atomic_inc_unchecked(&urb->dev->urbnum);
52675 retval = submit_single_step_set_feature(hcd, urb, 0);
52676 if (!retval && !wait_for_completion_timeout(&done,
52677 msecs_to_jiffies(2000))) {
52678 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52679 index ba6a5d6..f88f7f3 100644
52680 --- a/drivers/usb/misc/appledisplay.c
52681 +++ b/drivers/usb/misc/appledisplay.c
52682 @@ -83,7 +83,7 @@ struct appledisplay {
52683 spinlock_t lock;
52684 };
52685
52686 -static atomic_t count_displays = ATOMIC_INIT(0);
52687 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52688 static struct workqueue_struct *wq;
52689
52690 static void appledisplay_complete(struct urb *urb)
52691 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52692
52693 /* Register backlight device */
52694 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52695 - atomic_inc_return(&count_displays) - 1);
52696 + atomic_inc_return_unchecked(&count_displays) - 1);
52697 memset(&props, 0, sizeof(struct backlight_properties));
52698 props.type = BACKLIGHT_RAW;
52699 props.max_brightness = 0xff;
52700 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52701 index 8d7fc48..01c4986 100644
52702 --- a/drivers/usb/serial/console.c
52703 +++ b/drivers/usb/serial/console.c
52704 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52705
52706 info->port = port;
52707
52708 - ++port->port.count;
52709 + atomic_inc(&port->port.count);
52710 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52711 if (serial->type->set_termios) {
52712 /*
52713 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52714 }
52715 /* Now that any required fake tty operations are completed restore
52716 * the tty port count */
52717 - --port->port.count;
52718 + atomic_dec(&port->port.count);
52719 /* The console is special in terms of closing the device so
52720 * indicate this port is now acting as a system console. */
52721 port->port.console = 1;
52722 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52723 free_tty:
52724 kfree(tty);
52725 reset_open_count:
52726 - port->port.count = 0;
52727 + atomic_set(&port->port.count, 0);
52728 usb_autopm_put_interface(serial->interface);
52729 error_get_interface:
52730 usb_serial_put(serial);
52731 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52732 static void usb_console_write(struct console *co,
52733 const char *buf, unsigned count)
52734 {
52735 - static struct usbcons_info *info = &usbcons_info;
52736 + struct usbcons_info *info = &usbcons_info;
52737 struct usb_serial_port *port = info->port;
52738 struct usb_serial *serial;
52739 int retval = -ENODEV;
52740 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52741 index 75f70f0..d467e1a 100644
52742 --- a/drivers/usb/storage/usb.h
52743 +++ b/drivers/usb/storage/usb.h
52744 @@ -63,7 +63,7 @@ struct us_unusual_dev {
52745 __u8 useProtocol;
52746 __u8 useTransport;
52747 int (*initFunction)(struct us_data *);
52748 -};
52749 +} __do_const;
52750
52751
52752 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52753 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52754 index a2ef84b..aa7c2b8 100644
52755 --- a/drivers/usb/wusbcore/wa-hc.h
52756 +++ b/drivers/usb/wusbcore/wa-hc.h
52757 @@ -225,7 +225,7 @@ struct wahc {
52758 spinlock_t xfer_list_lock;
52759 struct work_struct xfer_enqueue_work;
52760 struct work_struct xfer_error_work;
52761 - atomic_t xfer_id_count;
52762 + atomic_unchecked_t xfer_id_count;
52763
52764 kernel_ulong_t quirks;
52765 };
52766 @@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52767 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52768 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52769 wa->dto_in_use = 0;
52770 - atomic_set(&wa->xfer_id_count, 1);
52771 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52772 }
52773
52774 /**
52775 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52776 index 3cd96e9..bd7c58d 100644
52777 --- a/drivers/usb/wusbcore/wa-xfer.c
52778 +++ b/drivers/usb/wusbcore/wa-xfer.c
52779 @@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52780 */
52781 static void wa_xfer_id_init(struct wa_xfer *xfer)
52782 {
52783 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52784 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52785 }
52786
52787 /* Return the xfer's ID. */
52788 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52789 index 21271d8..45b55a0 100644
52790 --- a/drivers/vfio/vfio.c
52791 +++ b/drivers/vfio/vfio.c
52792 @@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52793 return 0;
52794
52795 /* TODO Prevent device auto probing */
52796 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52797 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52798 iommu_group_id(group->iommu_group));
52799
52800 return 0;
52801 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52802 index 5174eba..451e6bc 100644
52803 --- a/drivers/vhost/vringh.c
52804 +++ b/drivers/vhost/vringh.c
52805 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52806 /* Userspace access helpers: in this case, addresses are really userspace. */
52807 static inline int getu16_user(u16 *val, const u16 *p)
52808 {
52809 - return get_user(*val, (__force u16 __user *)p);
52810 + return get_user(*val, (u16 __force_user *)p);
52811 }
52812
52813 static inline int putu16_user(u16 *p, u16 val)
52814 {
52815 - return put_user(val, (__force u16 __user *)p);
52816 + return put_user(val, (u16 __force_user *)p);
52817 }
52818
52819 static inline int copydesc_user(void *dst, const void *src, size_t len)
52820 {
52821 - return copy_from_user(dst, (__force void __user *)src, len) ?
52822 + return copy_from_user(dst, (void __force_user *)src, len) ?
52823 -EFAULT : 0;
52824 }
52825
52826 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52827 const struct vring_used_elem *src,
52828 unsigned int num)
52829 {
52830 - return copy_to_user((__force void __user *)dst, src,
52831 + return copy_to_user((void __force_user *)dst, src,
52832 sizeof(*dst) * num) ? -EFAULT : 0;
52833 }
52834
52835 static inline int xfer_from_user(void *src, void *dst, size_t len)
52836 {
52837 - return copy_from_user(dst, (__force void __user *)src, len) ?
52838 + return copy_from_user(dst, (void __force_user *)src, len) ?
52839 -EFAULT : 0;
52840 }
52841
52842 static inline int xfer_to_user(void *dst, void *src, size_t len)
52843 {
52844 - return copy_to_user((__force void __user *)dst, src, len) ?
52845 + return copy_to_user((void __force_user *)dst, src, len) ?
52846 -EFAULT : 0;
52847 }
52848
52849 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52850 vrh->last_used_idx = 0;
52851 vrh->vring.num = num;
52852 /* vring expects kernel addresses, but only used via accessors. */
52853 - vrh->vring.desc = (__force struct vring_desc *)desc;
52854 - vrh->vring.avail = (__force struct vring_avail *)avail;
52855 - vrh->vring.used = (__force struct vring_used *)used;
52856 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52857 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52858 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52859 return 0;
52860 }
52861 EXPORT_SYMBOL(vringh_init_user);
52862 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52863
52864 static inline int putu16_kern(u16 *p, u16 val)
52865 {
52866 - ACCESS_ONCE(*p) = val;
52867 + ACCESS_ONCE_RW(*p) = val;
52868 return 0;
52869 }
52870
52871 diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52872 index 1b0b233..6f34c2c 100644
52873 --- a/drivers/video/arcfb.c
52874 +++ b/drivers/video/arcfb.c
52875 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52876 return -ENOSPC;
52877
52878 err = 0;
52879 - if ((count + p) > fbmemlength) {
52880 + if (count > (fbmemlength - p)) {
52881 count = fbmemlength - p;
52882 err = -ENOSPC;
52883 }
52884 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52885 index 52108be..c7c110d 100644
52886 --- a/drivers/video/aty/aty128fb.c
52887 +++ b/drivers/video/aty/aty128fb.c
52888 @@ -149,7 +149,7 @@ enum {
52889 };
52890
52891 /* Must match above enum */
52892 -static char * const r128_family[] = {
52893 +static const char * const r128_family[] = {
52894 "AGP",
52895 "PCI",
52896 "PRO AGP",
52897 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52898 index 28fafbf..ae91651 100644
52899 --- a/drivers/video/aty/atyfb_base.c
52900 +++ b/drivers/video/aty/atyfb_base.c
52901 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52902 par->accel_flags = var->accel_flags; /* hack */
52903
52904 if (var->accel_flags) {
52905 - info->fbops->fb_sync = atyfb_sync;
52906 + pax_open_kernel();
52907 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52908 + pax_close_kernel();
52909 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52910 } else {
52911 - info->fbops->fb_sync = NULL;
52912 + pax_open_kernel();
52913 + *(void **)&info->fbops->fb_sync = NULL;
52914 + pax_close_kernel();
52915 info->flags |= FBINFO_HWACCEL_DISABLED;
52916 }
52917
52918 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52919 index 0fe02e2..ab01b26 100644
52920 --- a/drivers/video/aty/mach64_cursor.c
52921 +++ b/drivers/video/aty/mach64_cursor.c
52922 @@ -8,6 +8,7 @@
52923 #include "../fb_draw.h"
52924
52925 #include <asm/io.h>
52926 +#include <asm/pgtable.h>
52927
52928 #ifdef __sparc__
52929 #include <asm/fbio.h>
52930 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52931 info->sprite.buf_align = 16; /* and 64 lines tall. */
52932 info->sprite.flags = FB_PIXMAP_IO;
52933
52934 - info->fbops->fb_cursor = atyfb_cursor;
52935 + pax_open_kernel();
52936 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52937 + pax_close_kernel();
52938
52939 return 0;
52940 }
52941 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52942 index 84a110a..96312c3 100644
52943 --- a/drivers/video/backlight/kb3886_bl.c
52944 +++ b/drivers/video/backlight/kb3886_bl.c
52945 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52946 static unsigned long kb3886bl_flags;
52947 #define KB3886BL_SUSPENDED 0x01
52948
52949 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52950 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52951 {
52952 .ident = "Sahara Touch-iT",
52953 .matches = {
52954 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52955 index 900aa4e..6d49418 100644
52956 --- a/drivers/video/fb_defio.c
52957 +++ b/drivers/video/fb_defio.c
52958 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52959
52960 BUG_ON(!fbdefio);
52961 mutex_init(&fbdefio->lock);
52962 - info->fbops->fb_mmap = fb_deferred_io_mmap;
52963 + pax_open_kernel();
52964 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52965 + pax_close_kernel();
52966 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52967 INIT_LIST_HEAD(&fbdefio->pagelist);
52968 if (fbdefio->delay == 0) /* set a default of 1 s */
52969 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52970 page->mapping = NULL;
52971 }
52972
52973 - info->fbops->fb_mmap = NULL;
52974 + *(void **)&info->fbops->fb_mmap = NULL;
52975 mutex_destroy(&fbdefio->lock);
52976 }
52977 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52978 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52979 index 7309ac7..be3c49c 100644
52980 --- a/drivers/video/fbmem.c
52981 +++ b/drivers/video/fbmem.c
52982 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52983 image->dx += image->width + 8;
52984 }
52985 } else if (rotate == FB_ROTATE_UD) {
52986 - for (x = 0; x < num && image->dx >= 0; x++) {
52987 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52988 info->fbops->fb_imageblit(info, image);
52989 image->dx -= image->width + 8;
52990 }
52991 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52992 image->dy += image->height + 8;
52993 }
52994 } else if (rotate == FB_ROTATE_CCW) {
52995 - for (x = 0; x < num && image->dy >= 0; x++) {
52996 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52997 info->fbops->fb_imageblit(info, image);
52998 image->dy -= image->height + 8;
52999 }
53000 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
53001 return -EFAULT;
53002 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
53003 return -EINVAL;
53004 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
53005 + if (con2fb.framebuffer >= FB_MAX)
53006 return -EINVAL;
53007 if (!registered_fb[con2fb.framebuffer])
53008 request_module("fb%d", con2fb.framebuffer);
53009 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
53010 __u32 data;
53011 int err;
53012
53013 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
53014 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
53015
53016 data = (__u32) (unsigned long) fix->smem_start;
53017 err |= put_user(data, &fix32->smem_start);
53018 diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
53019 index 130708f..cdac1a9 100644
53020 --- a/drivers/video/hyperv_fb.c
53021 +++ b/drivers/video/hyperv_fb.c
53022 @@ -233,7 +233,7 @@ static uint screen_fb_size;
53023 static inline int synthvid_send(struct hv_device *hdev,
53024 struct synthvid_msg *msg)
53025 {
53026 - static atomic64_t request_id = ATOMIC64_INIT(0);
53027 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
53028 int ret;
53029
53030 msg->pipe_hdr.type = PIPE_MSG_DATA;
53031 @@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
53032
53033 ret = vmbus_sendpacket(hdev->channel, msg,
53034 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
53035 - atomic64_inc_return(&request_id),
53036 + atomic64_inc_return_unchecked(&request_id),
53037 VM_PKT_DATA_INBAND, 0);
53038
53039 if (ret)
53040 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
53041 index 7672d2e..b56437f 100644
53042 --- a/drivers/video/i810/i810_accel.c
53043 +++ b/drivers/video/i810/i810_accel.c
53044 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
53045 }
53046 }
53047 printk("ringbuffer lockup!!!\n");
53048 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
53049 i810_report_error(mmio);
53050 par->dev_flags |= LOCKUP;
53051 info->pixmap.scan_align = 1;
53052 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53053 index 3c14e43..2630570 100644
53054 --- a/drivers/video/logo/logo_linux_clut224.ppm
53055 +++ b/drivers/video/logo/logo_linux_clut224.ppm
53056 @@ -2,1603 +2,1123 @@ P3
53057 # Standard 224-color Linux logo
53058 80 80
53059 255
53060 - 0 0 0 0 0 0 0 0 0 0 0 0
53061 - 0 0 0 0 0 0 0 0 0 0 0 0
53062 - 0 0 0 0 0 0 0 0 0 0 0 0
53063 - 0 0 0 0 0 0 0 0 0 0 0 0
53064 - 0 0 0 0 0 0 0 0 0 0 0 0
53065 - 0 0 0 0 0 0 0 0 0 0 0 0
53066 - 0 0 0 0 0 0 0 0 0 0 0 0
53067 - 0 0 0 0 0 0 0 0 0 0 0 0
53068 - 0 0 0 0 0 0 0 0 0 0 0 0
53069 - 6 6 6 6 6 6 10 10 10 10 10 10
53070 - 10 10 10 6 6 6 6 6 6 6 6 6
53071 - 0 0 0 0 0 0 0 0 0 0 0 0
53072 - 0 0 0 0 0 0 0 0 0 0 0 0
53073 - 0 0 0 0 0 0 0 0 0 0 0 0
53074 - 0 0 0 0 0 0 0 0 0 0 0 0
53075 - 0 0 0 0 0 0 0 0 0 0 0 0
53076 - 0 0 0 0 0 0 0 0 0 0 0 0
53077 - 0 0 0 0 0 0 0 0 0 0 0 0
53078 - 0 0 0 0 0 0 0 0 0 0 0 0
53079 - 0 0 0 0 0 0 0 0 0 0 0 0
53080 - 0 0 0 0 0 0 0 0 0 0 0 0
53081 - 0 0 0 0 0 0 0 0 0 0 0 0
53082 - 0 0 0 0 0 0 0 0 0 0 0 0
53083 - 0 0 0 0 0 0 0 0 0 0 0 0
53084 - 0 0 0 0 0 0 0 0 0 0 0 0
53085 - 0 0 0 0 0 0 0 0 0 0 0 0
53086 - 0 0 0 0 0 0 0 0 0 0 0 0
53087 - 0 0 0 0 0 0 0 0 0 0 0 0
53088 - 0 0 0 6 6 6 10 10 10 14 14 14
53089 - 22 22 22 26 26 26 30 30 30 34 34 34
53090 - 30 30 30 30 30 30 26 26 26 18 18 18
53091 - 14 14 14 10 10 10 6 6 6 0 0 0
53092 - 0 0 0 0 0 0 0 0 0 0 0 0
53093 - 0 0 0 0 0 0 0 0 0 0 0 0
53094 - 0 0 0 0 0 0 0 0 0 0 0 0
53095 - 0 0 0 0 0 0 0 0 0 0 0 0
53096 - 0 0 0 0 0 0 0 0 0 0 0 0
53097 - 0 0 0 0 0 0 0 0 0 0 0 0
53098 - 0 0 0 0 0 0 0 0 0 0 0 0
53099 - 0 0 0 0 0 0 0 0 0 0 0 0
53100 - 0 0 0 0 0 0 0 0 0 0 0 0
53101 - 0 0 0 0 0 1 0 0 1 0 0 0
53102 - 0 0 0 0 0 0 0 0 0 0 0 0
53103 - 0 0 0 0 0 0 0 0 0 0 0 0
53104 - 0 0 0 0 0 0 0 0 0 0 0 0
53105 - 0 0 0 0 0 0 0 0 0 0 0 0
53106 - 0 0 0 0 0 0 0 0 0 0 0 0
53107 - 0 0 0 0 0 0 0 0 0 0 0 0
53108 - 6 6 6 14 14 14 26 26 26 42 42 42
53109 - 54 54 54 66 66 66 78 78 78 78 78 78
53110 - 78 78 78 74 74 74 66 66 66 54 54 54
53111 - 42 42 42 26 26 26 18 18 18 10 10 10
53112 - 6 6 6 0 0 0 0 0 0 0 0 0
53113 - 0 0 0 0 0 0 0 0 0 0 0 0
53114 - 0 0 0 0 0 0 0 0 0 0 0 0
53115 - 0 0 0 0 0 0 0 0 0 0 0 0
53116 - 0 0 0 0 0 0 0 0 0 0 0 0
53117 - 0 0 0 0 0 0 0 0 0 0 0 0
53118 - 0 0 0 0 0 0 0 0 0 0 0 0
53119 - 0 0 0 0 0 0 0 0 0 0 0 0
53120 - 0 0 0 0 0 0 0 0 0 0 0 0
53121 - 0 0 1 0 0 0 0 0 0 0 0 0
53122 - 0 0 0 0 0 0 0 0 0 0 0 0
53123 - 0 0 0 0 0 0 0 0 0 0 0 0
53124 - 0 0 0 0 0 0 0 0 0 0 0 0
53125 - 0 0 0 0 0 0 0 0 0 0 0 0
53126 - 0 0 0 0 0 0 0 0 0 0 0 0
53127 - 0 0 0 0 0 0 0 0 0 10 10 10
53128 - 22 22 22 42 42 42 66 66 66 86 86 86
53129 - 66 66 66 38 38 38 38 38 38 22 22 22
53130 - 26 26 26 34 34 34 54 54 54 66 66 66
53131 - 86 86 86 70 70 70 46 46 46 26 26 26
53132 - 14 14 14 6 6 6 0 0 0 0 0 0
53133 - 0 0 0 0 0 0 0 0 0 0 0 0
53134 - 0 0 0 0 0 0 0 0 0 0 0 0
53135 - 0 0 0 0 0 0 0 0 0 0 0 0
53136 - 0 0 0 0 0 0 0 0 0 0 0 0
53137 - 0 0 0 0 0 0 0 0 0 0 0 0
53138 - 0 0 0 0 0 0 0 0 0 0 0 0
53139 - 0 0 0 0 0 0 0 0 0 0 0 0
53140 - 0 0 0 0 0 0 0 0 0 0 0 0
53141 - 0 0 1 0 0 1 0 0 1 0 0 0
53142 - 0 0 0 0 0 0 0 0 0 0 0 0
53143 - 0 0 0 0 0 0 0 0 0 0 0 0
53144 - 0 0 0 0 0 0 0 0 0 0 0 0
53145 - 0 0 0 0 0 0 0 0 0 0 0 0
53146 - 0 0 0 0 0 0 0 0 0 0 0 0
53147 - 0 0 0 0 0 0 10 10 10 26 26 26
53148 - 50 50 50 82 82 82 58 58 58 6 6 6
53149 - 2 2 6 2 2 6 2 2 6 2 2 6
53150 - 2 2 6 2 2 6 2 2 6 2 2 6
53151 - 6 6 6 54 54 54 86 86 86 66 66 66
53152 - 38 38 38 18 18 18 6 6 6 0 0 0
53153 - 0 0 0 0 0 0 0 0 0 0 0 0
53154 - 0 0 0 0 0 0 0 0 0 0 0 0
53155 - 0 0 0 0 0 0 0 0 0 0 0 0
53156 - 0 0 0 0 0 0 0 0 0 0 0 0
53157 - 0 0 0 0 0 0 0 0 0 0 0 0
53158 - 0 0 0 0 0 0 0 0 0 0 0 0
53159 - 0 0 0 0 0 0 0 0 0 0 0 0
53160 - 0 0 0 0 0 0 0 0 0 0 0 0
53161 - 0 0 0 0 0 0 0 0 0 0 0 0
53162 - 0 0 0 0 0 0 0 0 0 0 0 0
53163 - 0 0 0 0 0 0 0 0 0 0 0 0
53164 - 0 0 0 0 0 0 0 0 0 0 0 0
53165 - 0 0 0 0 0 0 0 0 0 0 0 0
53166 - 0 0 0 0 0 0 0 0 0 0 0 0
53167 - 0 0 0 6 6 6 22 22 22 50 50 50
53168 - 78 78 78 34 34 34 2 2 6 2 2 6
53169 - 2 2 6 2 2 6 2 2 6 2 2 6
53170 - 2 2 6 2 2 6 2 2 6 2 2 6
53171 - 2 2 6 2 2 6 6 6 6 70 70 70
53172 - 78 78 78 46 46 46 22 22 22 6 6 6
53173 - 0 0 0 0 0 0 0 0 0 0 0 0
53174 - 0 0 0 0 0 0 0 0 0 0 0 0
53175 - 0 0 0 0 0 0 0 0 0 0 0 0
53176 - 0 0 0 0 0 0 0 0 0 0 0 0
53177 - 0 0 0 0 0 0 0 0 0 0 0 0
53178 - 0 0 0 0 0 0 0 0 0 0 0 0
53179 - 0 0 0 0 0 0 0 0 0 0 0 0
53180 - 0 0 0 0 0 0 0 0 0 0 0 0
53181 - 0 0 1 0 0 1 0 0 1 0 0 0
53182 - 0 0 0 0 0 0 0 0 0 0 0 0
53183 - 0 0 0 0 0 0 0 0 0 0 0 0
53184 - 0 0 0 0 0 0 0 0 0 0 0 0
53185 - 0 0 0 0 0 0 0 0 0 0 0 0
53186 - 0 0 0 0 0 0 0 0 0 0 0 0
53187 - 6 6 6 18 18 18 42 42 42 82 82 82
53188 - 26 26 26 2 2 6 2 2 6 2 2 6
53189 - 2 2 6 2 2 6 2 2 6 2 2 6
53190 - 2 2 6 2 2 6 2 2 6 14 14 14
53191 - 46 46 46 34 34 34 6 6 6 2 2 6
53192 - 42 42 42 78 78 78 42 42 42 18 18 18
53193 - 6 6 6 0 0 0 0 0 0 0 0 0
53194 - 0 0 0 0 0 0 0 0 0 0 0 0
53195 - 0 0 0 0 0 0 0 0 0 0 0 0
53196 - 0 0 0 0 0 0 0 0 0 0 0 0
53197 - 0 0 0 0 0 0 0 0 0 0 0 0
53198 - 0 0 0 0 0 0 0 0 0 0 0 0
53199 - 0 0 0 0 0 0 0 0 0 0 0 0
53200 - 0 0 0 0 0 0 0 0 0 0 0 0
53201 - 0 0 1 0 0 0 0 0 1 0 0 0
53202 - 0 0 0 0 0 0 0 0 0 0 0 0
53203 - 0 0 0 0 0 0 0 0 0 0 0 0
53204 - 0 0 0 0 0 0 0 0 0 0 0 0
53205 - 0 0 0 0 0 0 0 0 0 0 0 0
53206 - 0 0 0 0 0 0 0 0 0 0 0 0
53207 - 10 10 10 30 30 30 66 66 66 58 58 58
53208 - 2 2 6 2 2 6 2 2 6 2 2 6
53209 - 2 2 6 2 2 6 2 2 6 2 2 6
53210 - 2 2 6 2 2 6 2 2 6 26 26 26
53211 - 86 86 86 101 101 101 46 46 46 10 10 10
53212 - 2 2 6 58 58 58 70 70 70 34 34 34
53213 - 10 10 10 0 0 0 0 0 0 0 0 0
53214 - 0 0 0 0 0 0 0 0 0 0 0 0
53215 - 0 0 0 0 0 0 0 0 0 0 0 0
53216 - 0 0 0 0 0 0 0 0 0 0 0 0
53217 - 0 0 0 0 0 0 0 0 0 0 0 0
53218 - 0 0 0 0 0 0 0 0 0 0 0 0
53219 - 0 0 0 0 0 0 0 0 0 0 0 0
53220 - 0 0 0 0 0 0 0 0 0 0 0 0
53221 - 0 0 1 0 0 1 0 0 1 0 0 0
53222 - 0 0 0 0 0 0 0 0 0 0 0 0
53223 - 0 0 0 0 0 0 0 0 0 0 0 0
53224 - 0 0 0 0 0 0 0 0 0 0 0 0
53225 - 0 0 0 0 0 0 0 0 0 0 0 0
53226 - 0 0 0 0 0 0 0 0 0 0 0 0
53227 - 14 14 14 42 42 42 86 86 86 10 10 10
53228 - 2 2 6 2 2 6 2 2 6 2 2 6
53229 - 2 2 6 2 2 6 2 2 6 2 2 6
53230 - 2 2 6 2 2 6 2 2 6 30 30 30
53231 - 94 94 94 94 94 94 58 58 58 26 26 26
53232 - 2 2 6 6 6 6 78 78 78 54 54 54
53233 - 22 22 22 6 6 6 0 0 0 0 0 0
53234 - 0 0 0 0 0 0 0 0 0 0 0 0
53235 - 0 0 0 0 0 0 0 0 0 0 0 0
53236 - 0 0 0 0 0 0 0 0 0 0 0 0
53237 - 0 0 0 0 0 0 0 0 0 0 0 0
53238 - 0 0 0 0 0 0 0 0 0 0 0 0
53239 - 0 0 0 0 0 0 0 0 0 0 0 0
53240 - 0 0 0 0 0 0 0 0 0 0 0 0
53241 - 0 0 0 0 0 0 0 0 0 0 0 0
53242 - 0 0 0 0 0 0 0 0 0 0 0 0
53243 - 0 0 0 0 0 0 0 0 0 0 0 0
53244 - 0 0 0 0 0 0 0 0 0 0 0 0
53245 - 0 0 0 0 0 0 0 0 0 0 0 0
53246 - 0 0 0 0 0 0 0 0 0 6 6 6
53247 - 22 22 22 62 62 62 62 62 62 2 2 6
53248 - 2 2 6 2 2 6 2 2 6 2 2 6
53249 - 2 2 6 2 2 6 2 2 6 2 2 6
53250 - 2 2 6 2 2 6 2 2 6 26 26 26
53251 - 54 54 54 38 38 38 18 18 18 10 10 10
53252 - 2 2 6 2 2 6 34 34 34 82 82 82
53253 - 38 38 38 14 14 14 0 0 0 0 0 0
53254 - 0 0 0 0 0 0 0 0 0 0 0 0
53255 - 0 0 0 0 0 0 0 0 0 0 0 0
53256 - 0 0 0 0 0 0 0 0 0 0 0 0
53257 - 0 0 0 0 0 0 0 0 0 0 0 0
53258 - 0 0 0 0 0 0 0 0 0 0 0 0
53259 - 0 0 0 0 0 0 0 0 0 0 0 0
53260 - 0 0 0 0 0 0 0 0 0 0 0 0
53261 - 0 0 0 0 0 1 0 0 1 0 0 0
53262 - 0 0 0 0 0 0 0 0 0 0 0 0
53263 - 0 0 0 0 0 0 0 0 0 0 0 0
53264 - 0 0 0 0 0 0 0 0 0 0 0 0
53265 - 0 0 0 0 0 0 0 0 0 0 0 0
53266 - 0 0 0 0 0 0 0 0 0 6 6 6
53267 - 30 30 30 78 78 78 30 30 30 2 2 6
53268 - 2 2 6 2 2 6 2 2 6 2 2 6
53269 - 2 2 6 2 2 6 2 2 6 2 2 6
53270 - 2 2 6 2 2 6 2 2 6 10 10 10
53271 - 10 10 10 2 2 6 2 2 6 2 2 6
53272 - 2 2 6 2 2 6 2 2 6 78 78 78
53273 - 50 50 50 18 18 18 6 6 6 0 0 0
53274 - 0 0 0 0 0 0 0 0 0 0 0 0
53275 - 0 0 0 0 0 0 0 0 0 0 0 0
53276 - 0 0 0 0 0 0 0 0 0 0 0 0
53277 - 0 0 0 0 0 0 0 0 0 0 0 0
53278 - 0 0 0 0 0 0 0 0 0 0 0 0
53279 - 0 0 0 0 0 0 0 0 0 0 0 0
53280 - 0 0 0 0 0 0 0 0 0 0 0 0
53281 - 0 0 1 0 0 0 0 0 0 0 0 0
53282 - 0 0 0 0 0 0 0 0 0 0 0 0
53283 - 0 0 0 0 0 0 0 0 0 0 0 0
53284 - 0 0 0 0 0 0 0 0 0 0 0 0
53285 - 0 0 0 0 0 0 0 0 0 0 0 0
53286 - 0 0 0 0 0 0 0 0 0 10 10 10
53287 - 38 38 38 86 86 86 14 14 14 2 2 6
53288 - 2 2 6 2 2 6 2 2 6 2 2 6
53289 - 2 2 6 2 2 6 2 2 6 2 2 6
53290 - 2 2 6 2 2 6 2 2 6 2 2 6
53291 - 2 2 6 2 2 6 2 2 6 2 2 6
53292 - 2 2 6 2 2 6 2 2 6 54 54 54
53293 - 66 66 66 26 26 26 6 6 6 0 0 0
53294 - 0 0 0 0 0 0 0 0 0 0 0 0
53295 - 0 0 0 0 0 0 0 0 0 0 0 0
53296 - 0 0 0 0 0 0 0 0 0 0 0 0
53297 - 0 0 0 0 0 0 0 0 0 0 0 0
53298 - 0 0 0 0 0 0 0 0 0 0 0 0
53299 - 0 0 0 0 0 0 0 0 0 0 0 0
53300 - 0 0 0 0 0 0 0 0 0 0 0 0
53301 - 0 0 0 0 0 1 0 0 1 0 0 0
53302 - 0 0 0 0 0 0 0 0 0 0 0 0
53303 - 0 0 0 0 0 0 0 0 0 0 0 0
53304 - 0 0 0 0 0 0 0 0 0 0 0 0
53305 - 0 0 0 0 0 0 0 0 0 0 0 0
53306 - 0 0 0 0 0 0 0 0 0 14 14 14
53307 - 42 42 42 82 82 82 2 2 6 2 2 6
53308 - 2 2 6 6 6 6 10 10 10 2 2 6
53309 - 2 2 6 2 2 6 2 2 6 2 2 6
53310 - 2 2 6 2 2 6 2 2 6 6 6 6
53311 - 14 14 14 10 10 10 2 2 6 2 2 6
53312 - 2 2 6 2 2 6 2 2 6 18 18 18
53313 - 82 82 82 34 34 34 10 10 10 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 - 0 0 1 0 0 0 0 0 0 0 0 0
53322 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
53327 - 46 46 46 86 86 86 2 2 6 2 2 6
53328 - 6 6 6 6 6 6 22 22 22 34 34 34
53329 - 6 6 6 2 2 6 2 2 6 2 2 6
53330 - 2 2 6 2 2 6 18 18 18 34 34 34
53331 - 10 10 10 50 50 50 22 22 22 2 2 6
53332 - 2 2 6 2 2 6 2 2 6 10 10 10
53333 - 86 86 86 42 42 42 14 14 14 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 0 0 0 0 0 0 0 0 0
53341 - 0 0 1 0 0 1 0 0 1 0 0 0
53342 - 0 0 0 0 0 0 0 0 0 0 0 0
53343 - 0 0 0 0 0 0 0 0 0 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 14 14 14
53347 - 46 46 46 86 86 86 2 2 6 2 2 6
53348 - 38 38 38 116 116 116 94 94 94 22 22 22
53349 - 22 22 22 2 2 6 2 2 6 2 2 6
53350 - 14 14 14 86 86 86 138 138 138 162 162 162
53351 -154 154 154 38 38 38 26 26 26 6 6 6
53352 - 2 2 6 2 2 6 2 2 6 2 2 6
53353 - 86 86 86 46 46 46 14 14 14 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 - 0 0 0 0 0 0 0 0 0 0 0 0
53361 - 0 0 0 0 0 0 0 0 0 0 0 0
53362 - 0 0 0 0 0 0 0 0 0 0 0 0
53363 - 0 0 0 0 0 0 0 0 0 0 0 0
53364 - 0 0 0 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 14 14 14
53367 - 46 46 46 86 86 86 2 2 6 14 14 14
53368 -134 134 134 198 198 198 195 195 195 116 116 116
53369 - 10 10 10 2 2 6 2 2 6 6 6 6
53370 -101 98 89 187 187 187 210 210 210 218 218 218
53371 -214 214 214 134 134 134 14 14 14 6 6 6
53372 - 2 2 6 2 2 6 2 2 6 2 2 6
53373 - 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0
53380 - 0 0 0 0 0 0 0 0 1 0 0 0
53381 - 0 0 1 0 0 1 0 0 1 0 0 0
53382 - 0 0 0 0 0 0 0 0 0 0 0 0
53383 - 0 0 0 0 0 0 0 0 0 0 0 0
53384 - 0 0 0 0 0 0 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 14 14 14
53387 - 46 46 46 86 86 86 2 2 6 54 54 54
53388 -218 218 218 195 195 195 226 226 226 246 246 246
53389 - 58 58 58 2 2 6 2 2 6 30 30 30
53390 -210 210 210 253 253 253 174 174 174 123 123 123
53391 -221 221 221 234 234 234 74 74 74 2 2 6
53392 - 2 2 6 2 2 6 2 2 6 2 2 6
53393 - 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0
53400 - 0 0 0 0 0 0 0 0 0 0 0 0
53401 - 0 0 0 0 0 0 0 0 0 0 0 0
53402 - 0 0 0 0 0 0 0 0 0 0 0 0
53403 - 0 0 0 0 0 0 0 0 0 0 0 0
53404 - 0 0 0 0 0 0 0 0 0 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 14 14 14
53407 - 46 46 46 82 82 82 2 2 6 106 106 106
53408 -170 170 170 26 26 26 86 86 86 226 226 226
53409 -123 123 123 10 10 10 14 14 14 46 46 46
53410 -231 231 231 190 190 190 6 6 6 70 70 70
53411 - 90 90 90 238 238 238 158 158 158 2 2 6
53412 - 2 2 6 2 2 6 2 2 6 2 2 6
53413 - 70 70 70 58 58 58 22 22 22 6 6 6
53414 - 0 0 0 0 0 0 0 0 0 0 0 0
53415 - 0 0 0 0 0 0 0 0 0 0 0 0
53416 - 0 0 0 0 0 0 0 0 0 0 0 0
53417 - 0 0 0 0 0 0 0 0 0 0 0 0
53418 - 0 0 0 0 0 0 0 0 0 0 0 0
53419 - 0 0 0 0 0 0 0 0 0 0 0 0
53420 - 0 0 0 0 0 0 0 0 1 0 0 0
53421 - 0 0 1 0 0 1 0 0 1 0 0 0
53422 - 0 0 0 0 0 0 0 0 0 0 0 0
53423 - 0 0 0 0 0 0 0 0 0 0 0 0
53424 - 0 0 0 0 0 0 0 0 0 0 0 0
53425 - 0 0 0 0 0 0 0 0 0 0 0 0
53426 - 0 0 0 0 0 0 0 0 0 14 14 14
53427 - 42 42 42 86 86 86 6 6 6 116 116 116
53428 -106 106 106 6 6 6 70 70 70 149 149 149
53429 -128 128 128 18 18 18 38 38 38 54 54 54
53430 -221 221 221 106 106 106 2 2 6 14 14 14
53431 - 46 46 46 190 190 190 198 198 198 2 2 6
53432 - 2 2 6 2 2 6 2 2 6 2 2 6
53433 - 74 74 74 62 62 62 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
53440 - 0 0 0 0 0 0 0 0 1 0 0 0
53441 - 0 0 1 0 0 0 0 0 1 0 0 0
53442 - 0 0 0 0 0 0 0 0 0 0 0 0
53443 - 0 0 0 0 0 0 0 0 0 0 0 0
53444 - 0 0 0 0 0 0 0 0 0 0 0 0
53445 - 0 0 0 0 0 0 0 0 0 0 0 0
53446 - 0 0 0 0 0 0 0 0 0 14 14 14
53447 - 42 42 42 94 94 94 14 14 14 101 101 101
53448 -128 128 128 2 2 6 18 18 18 116 116 116
53449 -118 98 46 121 92 8 121 92 8 98 78 10
53450 -162 162 162 106 106 106 2 2 6 2 2 6
53451 - 2 2 6 195 195 195 195 195 195 6 6 6
53452 - 2 2 6 2 2 6 2 2 6 2 2 6
53453 - 74 74 74 62 62 62 22 22 22 6 6 6
53454 - 0 0 0 0 0 0 0 0 0 0 0 0
53455 - 0 0 0 0 0 0 0 0 0 0 0 0
53456 - 0 0 0 0 0 0 0 0 0 0 0 0
53457 - 0 0 0 0 0 0 0 0 0 0 0 0
53458 - 0 0 0 0 0 0 0 0 0 0 0 0
53459 - 0 0 0 0 0 0 0 0 0 0 0 0
53460 - 0 0 0 0 0 0 0 0 1 0 0 1
53461 - 0 0 1 0 0 0 0 0 1 0 0 0
53462 - 0 0 0 0 0 0 0 0 0 0 0 0
53463 - 0 0 0 0 0 0 0 0 0 0 0 0
53464 - 0 0 0 0 0 0 0 0 0 0 0 0
53465 - 0 0 0 0 0 0 0 0 0 0 0 0
53466 - 0 0 0 0 0 0 0 0 0 10 10 10
53467 - 38 38 38 90 90 90 14 14 14 58 58 58
53468 -210 210 210 26 26 26 54 38 6 154 114 10
53469 -226 170 11 236 186 11 225 175 15 184 144 12
53470 -215 174 15 175 146 61 37 26 9 2 2 6
53471 - 70 70 70 246 246 246 138 138 138 2 2 6
53472 - 2 2 6 2 2 6 2 2 6 2 2 6
53473 - 70 70 70 66 66 66 26 26 26 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
53480 - 0 0 0 0 0 0 0 0 0 0 0 0
53481 - 0 0 0 0 0 0 0 0 0 0 0 0
53482 - 0 0 0 0 0 0 0 0 0 0 0 0
53483 - 0 0 0 0 0 0 0 0 0 0 0 0
53484 - 0 0 0 0 0 0 0 0 0 0 0 0
53485 - 0 0 0 0 0 0 0 0 0 0 0 0
53486 - 0 0 0 0 0 0 0 0 0 10 10 10
53487 - 38 38 38 86 86 86 14 14 14 10 10 10
53488 -195 195 195 188 164 115 192 133 9 225 175 15
53489 -239 182 13 234 190 10 232 195 16 232 200 30
53490 -245 207 45 241 208 19 232 195 16 184 144 12
53491 -218 194 134 211 206 186 42 42 42 2 2 6
53492 - 2 2 6 2 2 6 2 2 6 2 2 6
53493 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
53499 - 0 0 0 0 0 0 0 0 0 0 0 0
53500 - 0 0 0 0 0 0 0 0 0 0 0 0
53501 - 0 0 0 0 0 0 0 0 0 0 0 0
53502 - 0 0 0 0 0 0 0 0 0 0 0 0
53503 - 0 0 0 0 0 0 0 0 0 0 0 0
53504 - 0 0 0 0 0 0 0 0 0 0 0 0
53505 - 0 0 0 0 0 0 0 0 0 0 0 0
53506 - 0 0 0 0 0 0 0 0 0 10 10 10
53507 - 34 34 34 86 86 86 14 14 14 2 2 6
53508 -121 87 25 192 133 9 219 162 10 239 182 13
53509 -236 186 11 232 195 16 241 208 19 244 214 54
53510 -246 218 60 246 218 38 246 215 20 241 208 19
53511 -241 208 19 226 184 13 121 87 25 2 2 6
53512 - 2 2 6 2 2 6 2 2 6 2 2 6
53513 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
53519 - 0 0 0 0 0 0 0 0 0 0 0 0
53520 - 0 0 0 0 0 0 0 0 0 0 0 0
53521 - 0 0 0 0 0 0 0 0 0 0 0 0
53522 - 0 0 0 0 0 0 0 0 0 0 0 0
53523 - 0 0 0 0 0 0 0 0 0 0 0 0
53524 - 0 0 0 0 0 0 0 0 0 0 0 0
53525 - 0 0 0 0 0 0 0 0 0 0 0 0
53526 - 0 0 0 0 0 0 0 0 0 10 10 10
53527 - 34 34 34 82 82 82 30 30 30 61 42 6
53528 -180 123 7 206 145 10 230 174 11 239 182 13
53529 -234 190 10 238 202 15 241 208 19 246 218 74
53530 -246 218 38 246 215 20 246 215 20 246 215 20
53531 -226 184 13 215 174 15 184 144 12 6 6 6
53532 - 2 2 6 2 2 6 2 2 6 2 2 6
53533 - 26 26 26 94 94 94 42 42 42 14 14 14
53534 - 0 0 0 0 0 0 0 0 0 0 0 0
53535 - 0 0 0 0 0 0 0 0 0 0 0 0
53536 - 0 0 0 0 0 0 0 0 0 0 0 0
53537 - 0 0 0 0 0 0 0 0 0 0 0 0
53538 - 0 0 0 0 0 0 0 0 0 0 0 0
53539 - 0 0 0 0 0 0 0 0 0 0 0 0
53540 - 0 0 0 0 0 0 0 0 0 0 0 0
53541 - 0 0 0 0 0 0 0 0 0 0 0 0
53542 - 0 0 0 0 0 0 0 0 0 0 0 0
53543 - 0 0 0 0 0 0 0 0 0 0 0 0
53544 - 0 0 0 0 0 0 0 0 0 0 0 0
53545 - 0 0 0 0 0 0 0 0 0 0 0 0
53546 - 0 0 0 0 0 0 0 0 0 10 10 10
53547 - 30 30 30 78 78 78 50 50 50 104 69 6
53548 -192 133 9 216 158 10 236 178 12 236 186 11
53549 -232 195 16 241 208 19 244 214 54 245 215 43
53550 -246 215 20 246 215 20 241 208 19 198 155 10
53551 -200 144 11 216 158 10 156 118 10 2 2 6
53552 - 2 2 6 2 2 6 2 2 6 2 2 6
53553 - 6 6 6 90 90 90 54 54 54 18 18 18
53554 - 6 6 6 0 0 0 0 0 0 0 0 0
53555 - 0 0 0 0 0 0 0 0 0 0 0 0
53556 - 0 0 0 0 0 0 0 0 0 0 0 0
53557 - 0 0 0 0 0 0 0 0 0 0 0 0
53558 - 0 0 0 0 0 0 0 0 0 0 0 0
53559 - 0 0 0 0 0 0 0 0 0 0 0 0
53560 - 0 0 0 0 0 0 0 0 0 0 0 0
53561 - 0 0 0 0 0 0 0 0 0 0 0 0
53562 - 0 0 0 0 0 0 0 0 0 0 0 0
53563 - 0 0 0 0 0 0 0 0 0 0 0 0
53564 - 0 0 0 0 0 0 0 0 0 0 0 0
53565 - 0 0 0 0 0 0 0 0 0 0 0 0
53566 - 0 0 0 0 0 0 0 0 0 10 10 10
53567 - 30 30 30 78 78 78 46 46 46 22 22 22
53568 -137 92 6 210 162 10 239 182 13 238 190 10
53569 -238 202 15 241 208 19 246 215 20 246 215 20
53570 -241 208 19 203 166 17 185 133 11 210 150 10
53571 -216 158 10 210 150 10 102 78 10 2 2 6
53572 - 6 6 6 54 54 54 14 14 14 2 2 6
53573 - 2 2 6 62 62 62 74 74 74 30 30 30
53574 - 10 10 10 0 0 0 0 0 0 0 0 0
53575 - 0 0 0 0 0 0 0 0 0 0 0 0
53576 - 0 0 0 0 0 0 0 0 0 0 0 0
53577 - 0 0 0 0 0 0 0 0 0 0 0 0
53578 - 0 0 0 0 0 0 0 0 0 0 0 0
53579 - 0 0 0 0 0 0 0 0 0 0 0 0
53580 - 0 0 0 0 0 0 0 0 0 0 0 0
53581 - 0 0 0 0 0 0 0 0 0 0 0 0
53582 - 0 0 0 0 0 0 0 0 0 0 0 0
53583 - 0 0 0 0 0 0 0 0 0 0 0 0
53584 - 0 0 0 0 0 0 0 0 0 0 0 0
53585 - 0 0 0 0 0 0 0 0 0 0 0 0
53586 - 0 0 0 0 0 0 0 0 0 10 10 10
53587 - 34 34 34 78 78 78 50 50 50 6 6 6
53588 - 94 70 30 139 102 15 190 146 13 226 184 13
53589 -232 200 30 232 195 16 215 174 15 190 146 13
53590 -168 122 10 192 133 9 210 150 10 213 154 11
53591 -202 150 34 182 157 106 101 98 89 2 2 6
53592 - 2 2 6 78 78 78 116 116 116 58 58 58
53593 - 2 2 6 22 22 22 90 90 90 46 46 46
53594 - 18 18 18 6 6 6 0 0 0 0 0 0
53595 - 0 0 0 0 0 0 0 0 0 0 0 0
53596 - 0 0 0 0 0 0 0 0 0 0 0 0
53597 - 0 0 0 0 0 0 0 0 0 0 0 0
53598 - 0 0 0 0 0 0 0 0 0 0 0 0
53599 - 0 0 0 0 0 0 0 0 0 0 0 0
53600 - 0 0 0 0 0 0 0 0 0 0 0 0
53601 - 0 0 0 0 0 0 0 0 0 0 0 0
53602 - 0 0 0 0 0 0 0 0 0 0 0 0
53603 - 0 0 0 0 0 0 0 0 0 0 0 0
53604 - 0 0 0 0 0 0 0 0 0 0 0 0
53605 - 0 0 0 0 0 0 0 0 0 0 0 0
53606 - 0 0 0 0 0 0 0 0 0 10 10 10
53607 - 38 38 38 86 86 86 50 50 50 6 6 6
53608 -128 128 128 174 154 114 156 107 11 168 122 10
53609 -198 155 10 184 144 12 197 138 11 200 144 11
53610 -206 145 10 206 145 10 197 138 11 188 164 115
53611 -195 195 195 198 198 198 174 174 174 14 14 14
53612 - 2 2 6 22 22 22 116 116 116 116 116 116
53613 - 22 22 22 2 2 6 74 74 74 70 70 70
53614 - 30 30 30 10 10 10 0 0 0 0 0 0
53615 - 0 0 0 0 0 0 0 0 0 0 0 0
53616 - 0 0 0 0 0 0 0 0 0 0 0 0
53617 - 0 0 0 0 0 0 0 0 0 0 0 0
53618 - 0 0 0 0 0 0 0 0 0 0 0 0
53619 - 0 0 0 0 0 0 0 0 0 0 0 0
53620 - 0 0 0 0 0 0 0 0 0 0 0 0
53621 - 0 0 0 0 0 0 0 0 0 0 0 0
53622 - 0 0 0 0 0 0 0 0 0 0 0 0
53623 - 0 0 0 0 0 0 0 0 0 0 0 0
53624 - 0 0 0 0 0 0 0 0 0 0 0 0
53625 - 0 0 0 0 0 0 0 0 0 0 0 0
53626 - 0 0 0 0 0 0 6 6 6 18 18 18
53627 - 50 50 50 101 101 101 26 26 26 10 10 10
53628 -138 138 138 190 190 190 174 154 114 156 107 11
53629 -197 138 11 200 144 11 197 138 11 192 133 9
53630 -180 123 7 190 142 34 190 178 144 187 187 187
53631 -202 202 202 221 221 221 214 214 214 66 66 66
53632 - 2 2 6 2 2 6 50 50 50 62 62 62
53633 - 6 6 6 2 2 6 10 10 10 90 90 90
53634 - 50 50 50 18 18 18 6 6 6 0 0 0
53635 - 0 0 0 0 0 0 0 0 0 0 0 0
53636 - 0 0 0 0 0 0 0 0 0 0 0 0
53637 - 0 0 0 0 0 0 0 0 0 0 0 0
53638 - 0 0 0 0 0 0 0 0 0 0 0 0
53639 - 0 0 0 0 0 0 0 0 0 0 0 0
53640 - 0 0 0 0 0 0 0 0 0 0 0 0
53641 - 0 0 0 0 0 0 0 0 0 0 0 0
53642 - 0 0 0 0 0 0 0 0 0 0 0 0
53643 - 0 0 0 0 0 0 0 0 0 0 0 0
53644 - 0 0 0 0 0 0 0 0 0 0 0 0
53645 - 0 0 0 0 0 0 0 0 0 0 0 0
53646 - 0 0 0 0 0 0 10 10 10 34 34 34
53647 - 74 74 74 74 74 74 2 2 6 6 6 6
53648 -144 144 144 198 198 198 190 190 190 178 166 146
53649 -154 121 60 156 107 11 156 107 11 168 124 44
53650 -174 154 114 187 187 187 190 190 190 210 210 210
53651 -246 246 246 253 253 253 253 253 253 182 182 182
53652 - 6 6 6 2 2 6 2 2 6 2 2 6
53653 - 2 2 6 2 2 6 2 2 6 62 62 62
53654 - 74 74 74 34 34 34 14 14 14 0 0 0
53655 - 0 0 0 0 0 0 0 0 0 0 0 0
53656 - 0 0 0 0 0 0 0 0 0 0 0 0
53657 - 0 0 0 0 0 0 0 0 0 0 0 0
53658 - 0 0 0 0 0 0 0 0 0 0 0 0
53659 - 0 0 0 0 0 0 0 0 0 0 0 0
53660 - 0 0 0 0 0 0 0 0 0 0 0 0
53661 - 0 0 0 0 0 0 0 0 0 0 0 0
53662 - 0 0 0 0 0 0 0 0 0 0 0 0
53663 - 0 0 0 0 0 0 0 0 0 0 0 0
53664 - 0 0 0 0 0 0 0 0 0 0 0 0
53665 - 0 0 0 0 0 0 0 0 0 0 0 0
53666 - 0 0 0 10 10 10 22 22 22 54 54 54
53667 - 94 94 94 18 18 18 2 2 6 46 46 46
53668 -234 234 234 221 221 221 190 190 190 190 190 190
53669 -190 190 190 187 187 187 187 187 187 190 190 190
53670 -190 190 190 195 195 195 214 214 214 242 242 242
53671 -253 253 253 253 253 253 253 253 253 253 253 253
53672 - 82 82 82 2 2 6 2 2 6 2 2 6
53673 - 2 2 6 2 2 6 2 2 6 14 14 14
53674 - 86 86 86 54 54 54 22 22 22 6 6 6
53675 - 0 0 0 0 0 0 0 0 0 0 0 0
53676 - 0 0 0 0 0 0 0 0 0 0 0 0
53677 - 0 0 0 0 0 0 0 0 0 0 0 0
53678 - 0 0 0 0 0 0 0 0 0 0 0 0
53679 - 0 0 0 0 0 0 0 0 0 0 0 0
53680 - 0 0 0 0 0 0 0 0 0 0 0 0
53681 - 0 0 0 0 0 0 0 0 0 0 0 0
53682 - 0 0 0 0 0 0 0 0 0 0 0 0
53683 - 0 0 0 0 0 0 0 0 0 0 0 0
53684 - 0 0 0 0 0 0 0 0 0 0 0 0
53685 - 0 0 0 0 0 0 0 0 0 0 0 0
53686 - 6 6 6 18 18 18 46 46 46 90 90 90
53687 - 46 46 46 18 18 18 6 6 6 182 182 182
53688 -253 253 253 246 246 246 206 206 206 190 190 190
53689 -190 190 190 190 190 190 190 190 190 190 190 190
53690 -206 206 206 231 231 231 250 250 250 253 253 253
53691 -253 253 253 253 253 253 253 253 253 253 253 253
53692 -202 202 202 14 14 14 2 2 6 2 2 6
53693 - 2 2 6 2 2 6 2 2 6 2 2 6
53694 - 42 42 42 86 86 86 42 42 42 18 18 18
53695 - 6 6 6 0 0 0 0 0 0 0 0 0
53696 - 0 0 0 0 0 0 0 0 0 0 0 0
53697 - 0 0 0 0 0 0 0 0 0 0 0 0
53698 - 0 0 0 0 0 0 0 0 0 0 0 0
53699 - 0 0 0 0 0 0 0 0 0 0 0 0
53700 - 0 0 0 0 0 0 0 0 0 0 0 0
53701 - 0 0 0 0 0 0 0 0 0 0 0 0
53702 - 0 0 0 0 0 0 0 0 0 0 0 0
53703 - 0 0 0 0 0 0 0 0 0 0 0 0
53704 - 0 0 0 0 0 0 0 0 0 0 0 0
53705 - 0 0 0 0 0 0 0 0 0 6 6 6
53706 - 14 14 14 38 38 38 74 74 74 66 66 66
53707 - 2 2 6 6 6 6 90 90 90 250 250 250
53708 -253 253 253 253 253 253 238 238 238 198 198 198
53709 -190 190 190 190 190 190 195 195 195 221 221 221
53710 -246 246 246 253 253 253 253 253 253 253 253 253
53711 -253 253 253 253 253 253 253 253 253 253 253 253
53712 -253 253 253 82 82 82 2 2 6 2 2 6
53713 - 2 2 6 2 2 6 2 2 6 2 2 6
53714 - 2 2 6 78 78 78 70 70 70 34 34 34
53715 - 14 14 14 6 6 6 0 0 0 0 0 0
53716 - 0 0 0 0 0 0 0 0 0 0 0 0
53717 - 0 0 0 0 0 0 0 0 0 0 0 0
53718 - 0 0 0 0 0 0 0 0 0 0 0 0
53719 - 0 0 0 0 0 0 0 0 0 0 0 0
53720 - 0 0 0 0 0 0 0 0 0 0 0 0
53721 - 0 0 0 0 0 0 0 0 0 0 0 0
53722 - 0 0 0 0 0 0 0 0 0 0 0 0
53723 - 0 0 0 0 0 0 0 0 0 0 0 0
53724 - 0 0 0 0 0 0 0 0 0 0 0 0
53725 - 0 0 0 0 0 0 0 0 0 14 14 14
53726 - 34 34 34 66 66 66 78 78 78 6 6 6
53727 - 2 2 6 18 18 18 218 218 218 253 253 253
53728 -253 253 253 253 253 253 253 253 253 246 246 246
53729 -226 226 226 231 231 231 246 246 246 253 253 253
53730 -253 253 253 253 253 253 253 253 253 253 253 253
53731 -253 253 253 253 253 253 253 253 253 253 253 253
53732 -253 253 253 178 178 178 2 2 6 2 2 6
53733 - 2 2 6 2 2 6 2 2 6 2 2 6
53734 - 2 2 6 18 18 18 90 90 90 62 62 62
53735 - 30 30 30 10 10 10 0 0 0 0 0 0
53736 - 0 0 0 0 0 0 0 0 0 0 0 0
53737 - 0 0 0 0 0 0 0 0 0 0 0 0
53738 - 0 0 0 0 0 0 0 0 0 0 0 0
53739 - 0 0 0 0 0 0 0 0 0 0 0 0
53740 - 0 0 0 0 0 0 0 0 0 0 0 0
53741 - 0 0 0 0 0 0 0 0 0 0 0 0
53742 - 0 0 0 0 0 0 0 0 0 0 0 0
53743 - 0 0 0 0 0 0 0 0 0 0 0 0
53744 - 0 0 0 0 0 0 0 0 0 0 0 0
53745 - 0 0 0 0 0 0 10 10 10 26 26 26
53746 - 58 58 58 90 90 90 18 18 18 2 2 6
53747 - 2 2 6 110 110 110 253 253 253 253 253 253
53748 -253 253 253 253 253 253 253 253 253 253 253 253
53749 -250 250 250 253 253 253 253 253 253 253 253 253
53750 -253 253 253 253 253 253 253 253 253 253 253 253
53751 -253 253 253 253 253 253 253 253 253 253 253 253
53752 -253 253 253 231 231 231 18 18 18 2 2 6
53753 - 2 2 6 2 2 6 2 2 6 2 2 6
53754 - 2 2 6 2 2 6 18 18 18 94 94 94
53755 - 54 54 54 26 26 26 10 10 10 0 0 0
53756 - 0 0 0 0 0 0 0 0 0 0 0 0
53757 - 0 0 0 0 0 0 0 0 0 0 0 0
53758 - 0 0 0 0 0 0 0 0 0 0 0 0
53759 - 0 0 0 0 0 0 0 0 0 0 0 0
53760 - 0 0 0 0 0 0 0 0 0 0 0 0
53761 - 0 0 0 0 0 0 0 0 0 0 0 0
53762 - 0 0 0 0 0 0 0 0 0 0 0 0
53763 - 0 0 0 0 0 0 0 0 0 0 0 0
53764 - 0 0 0 0 0 0 0 0 0 0 0 0
53765 - 0 0 0 6 6 6 22 22 22 50 50 50
53766 - 90 90 90 26 26 26 2 2 6 2 2 6
53767 - 14 14 14 195 195 195 250 250 250 253 253 253
53768 -253 253 253 253 253 253 253 253 253 253 253 253
53769 -253 253 253 253 253 253 253 253 253 253 253 253
53770 -253 253 253 253 253 253 253 253 253 253 253 253
53771 -253 253 253 253 253 253 253 253 253 253 253 253
53772 -250 250 250 242 242 242 54 54 54 2 2 6
53773 - 2 2 6 2 2 6 2 2 6 2 2 6
53774 - 2 2 6 2 2 6 2 2 6 38 38 38
53775 - 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0
53779 - 0 0 0 0 0 0 0 0 0 0 0 0
53780 - 0 0 0 0 0 0 0 0 0 0 0 0
53781 - 0 0 0 0 0 0 0 0 0 0 0 0
53782 - 0 0 0 0 0 0 0 0 0 0 0 0
53783 - 0 0 0 0 0 0 0 0 0 0 0 0
53784 - 0 0 0 0 0 0 0 0 0 0 0 0
53785 - 6 6 6 14 14 14 38 38 38 82 82 82
53786 - 34 34 34 2 2 6 2 2 6 2 2 6
53787 - 42 42 42 195 195 195 246 246 246 253 253 253
53788 -253 253 253 253 253 253 253 253 253 250 250 250
53789 -242 242 242 242 242 242 250 250 250 253 253 253
53790 -253 253 253 253 253 253 253 253 253 253 253 253
53791 -253 253 253 250 250 250 246 246 246 238 238 238
53792 -226 226 226 231 231 231 101 101 101 6 6 6
53793 - 2 2 6 2 2 6 2 2 6 2 2 6
53794 - 2 2 6 2 2 6 2 2 6 2 2 6
53795 - 38 38 38 82 82 82 42 42 42 14 14 14
53796 - 6 6 6 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 0 0 0
53799 - 0 0 0 0 0 0 0 0 0 0 0 0
53800 - 0 0 0 0 0 0 0 0 0 0 0 0
53801 - 0 0 0 0 0 0 0 0 0 0 0 0
53802 - 0 0 0 0 0 0 0 0 0 0 0 0
53803 - 0 0 0 0 0 0 0 0 0 0 0 0
53804 - 0 0 0 0 0 0 0 0 0 0 0 0
53805 - 10 10 10 26 26 26 62 62 62 66 66 66
53806 - 2 2 6 2 2 6 2 2 6 6 6 6
53807 - 70 70 70 170 170 170 206 206 206 234 234 234
53808 -246 246 246 250 250 250 250 250 250 238 238 238
53809 -226 226 226 231 231 231 238 238 238 250 250 250
53810 -250 250 250 250 250 250 246 246 246 231 231 231
53811 -214 214 214 206 206 206 202 202 202 202 202 202
53812 -198 198 198 202 202 202 182 182 182 18 18 18
53813 - 2 2 6 2 2 6 2 2 6 2 2 6
53814 - 2 2 6 2 2 6 2 2 6 2 2 6
53815 - 2 2 6 62 62 62 66 66 66 30 30 30
53816 - 10 10 10 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 0 0 0
53819 - 0 0 0 0 0 0 0 0 0 0 0 0
53820 - 0 0 0 0 0 0 0 0 0 0 0 0
53821 - 0 0 0 0 0 0 0 0 0 0 0 0
53822 - 0 0 0 0 0 0 0 0 0 0 0 0
53823 - 0 0 0 0 0 0 0 0 0 0 0 0
53824 - 0 0 0 0 0 0 0 0 0 0 0 0
53825 - 14 14 14 42 42 42 82 82 82 18 18 18
53826 - 2 2 6 2 2 6 2 2 6 10 10 10
53827 - 94 94 94 182 182 182 218 218 218 242 242 242
53828 -250 250 250 253 253 253 253 253 253 250 250 250
53829 -234 234 234 253 253 253 253 253 253 253 253 253
53830 -253 253 253 253 253 253 253 253 253 246 246 246
53831 -238 238 238 226 226 226 210 210 210 202 202 202
53832 -195 195 195 195 195 195 210 210 210 158 158 158
53833 - 6 6 6 14 14 14 50 50 50 14 14 14
53834 - 2 2 6 2 2 6 2 2 6 2 2 6
53835 - 2 2 6 6 6 6 86 86 86 46 46 46
53836 - 18 18 18 6 6 6 0 0 0 0 0 0
53837 - 0 0 0 0 0 0 0 0 0 0 0 0
53838 - 0 0 0 0 0 0 0 0 0 0 0 0
53839 - 0 0 0 0 0 0 0 0 0 0 0 0
53840 - 0 0 0 0 0 0 0 0 0 0 0 0
53841 - 0 0 0 0 0 0 0 0 0 0 0 0
53842 - 0 0 0 0 0 0 0 0 0 0 0 0
53843 - 0 0 0 0 0 0 0 0 0 0 0 0
53844 - 0 0 0 0 0 0 0 0 0 6 6 6
53845 - 22 22 22 54 54 54 70 70 70 2 2 6
53846 - 2 2 6 10 10 10 2 2 6 22 22 22
53847 -166 166 166 231 231 231 250 250 250 253 253 253
53848 -253 253 253 253 253 253 253 253 253 250 250 250
53849 -242 242 242 253 253 253 253 253 253 253 253 253
53850 -253 253 253 253 253 253 253 253 253 253 253 253
53851 -253 253 253 253 253 253 253 253 253 246 246 246
53852 -231 231 231 206 206 206 198 198 198 226 226 226
53853 - 94 94 94 2 2 6 6 6 6 38 38 38
53854 - 30 30 30 2 2 6 2 2 6 2 2 6
53855 - 2 2 6 2 2 6 62 62 62 66 66 66
53856 - 26 26 26 10 10 10 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 0 0 0
53859 - 0 0 0 0 0 0 0 0 0 0 0 0
53860 - 0 0 0 0 0 0 0 0 0 0 0 0
53861 - 0 0 0 0 0 0 0 0 0 0 0 0
53862 - 0 0 0 0 0 0 0 0 0 0 0 0
53863 - 0 0 0 0 0 0 0 0 0 0 0 0
53864 - 0 0 0 0 0 0 0 0 0 10 10 10
53865 - 30 30 30 74 74 74 50 50 50 2 2 6
53866 - 26 26 26 26 26 26 2 2 6 106 106 106
53867 -238 238 238 253 253 253 253 253 253 253 253 253
53868 -253 253 253 253 253 253 253 253 253 253 253 253
53869 -253 253 253 253 253 253 253 253 253 253 253 253
53870 -253 253 253 253 253 253 253 253 253 253 253 253
53871 -253 253 253 253 253 253 253 253 253 253 253 253
53872 -253 253 253 246 246 246 218 218 218 202 202 202
53873 -210 210 210 14 14 14 2 2 6 2 2 6
53874 - 30 30 30 22 22 22 2 2 6 2 2 6
53875 - 2 2 6 2 2 6 18 18 18 86 86 86
53876 - 42 42 42 14 14 14 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 0 0 0 0 0 0
53879 - 0 0 0 0 0 0 0 0 0 0 0 0
53880 - 0 0 0 0 0 0 0 0 0 0 0 0
53881 - 0 0 0 0 0 0 0 0 0 0 0 0
53882 - 0 0 0 0 0 0 0 0 0 0 0 0
53883 - 0 0 0 0 0 0 0 0 0 0 0 0
53884 - 0 0 0 0 0 0 0 0 0 14 14 14
53885 - 42 42 42 90 90 90 22 22 22 2 2 6
53886 - 42 42 42 2 2 6 18 18 18 218 218 218
53887 -253 253 253 253 253 253 253 253 253 253 253 253
53888 -253 253 253 253 253 253 253 253 253 253 253 253
53889 -253 253 253 253 253 253 253 253 253 253 253 253
53890 -253 253 253 253 253 253 253 253 253 253 253 253
53891 -253 253 253 253 253 253 253 253 253 253 253 253
53892 -253 253 253 253 253 253 250 250 250 221 221 221
53893 -218 218 218 101 101 101 2 2 6 14 14 14
53894 - 18 18 18 38 38 38 10 10 10 2 2 6
53895 - 2 2 6 2 2 6 2 2 6 78 78 78
53896 - 58 58 58 22 22 22 6 6 6 0 0 0
53897 - 0 0 0 0 0 0 0 0 0 0 0 0
53898 - 0 0 0 0 0 0 0 0 0 0 0 0
53899 - 0 0 0 0 0 0 0 0 0 0 0 0
53900 - 0 0 0 0 0 0 0 0 0 0 0 0
53901 - 0 0 0 0 0 0 0 0 0 0 0 0
53902 - 0 0 0 0 0 0 0 0 0 0 0 0
53903 - 0 0 0 0 0 0 0 0 0 0 0 0
53904 - 0 0 0 0 0 0 6 6 6 18 18 18
53905 - 54 54 54 82 82 82 2 2 6 26 26 26
53906 - 22 22 22 2 2 6 123 123 123 253 253 253
53907 -253 253 253 253 253 253 253 253 253 253 253 253
53908 -253 253 253 253 253 253 253 253 253 253 253 253
53909 -253 253 253 253 253 253 253 253 253 253 253 253
53910 -253 253 253 253 253 253 253 253 253 253 253 253
53911 -253 253 253 253 253 253 253 253 253 253 253 253
53912 -253 253 253 253 253 253 253 253 253 250 250 250
53913 -238 238 238 198 198 198 6 6 6 38 38 38
53914 - 58 58 58 26 26 26 38 38 38 2 2 6
53915 - 2 2 6 2 2 6 2 2 6 46 46 46
53916 - 78 78 78 30 30 30 10 10 10 0 0 0
53917 - 0 0 0 0 0 0 0 0 0 0 0 0
53918 - 0 0 0 0 0 0 0 0 0 0 0 0
53919 - 0 0 0 0 0 0 0 0 0 0 0 0
53920 - 0 0 0 0 0 0 0 0 0 0 0 0
53921 - 0 0 0 0 0 0 0 0 0 0 0 0
53922 - 0 0 0 0 0 0 0 0 0 0 0 0
53923 - 0 0 0 0 0 0 0 0 0 0 0 0
53924 - 0 0 0 0 0 0 10 10 10 30 30 30
53925 - 74 74 74 58 58 58 2 2 6 42 42 42
53926 - 2 2 6 22 22 22 231 231 231 253 253 253
53927 -253 253 253 253 253 253 253 253 253 253 253 253
53928 -253 253 253 253 253 253 253 253 253 250 250 250
53929 -253 253 253 253 253 253 253 253 253 253 253 253
53930 -253 253 253 253 253 253 253 253 253 253 253 253
53931 -253 253 253 253 253 253 253 253 253 253 253 253
53932 -253 253 253 253 253 253 253 253 253 253 253 253
53933 -253 253 253 246 246 246 46 46 46 38 38 38
53934 - 42 42 42 14 14 14 38 38 38 14 14 14
53935 - 2 2 6 2 2 6 2 2 6 6 6 6
53936 - 86 86 86 46 46 46 14 14 14 0 0 0
53937 - 0 0 0 0 0 0 0 0 0 0 0 0
53938 - 0 0 0 0 0 0 0 0 0 0 0 0
53939 - 0 0 0 0 0 0 0 0 0 0 0 0
53940 - 0 0 0 0 0 0 0 0 0 0 0 0
53941 - 0 0 0 0 0 0 0 0 0 0 0 0
53942 - 0 0 0 0 0 0 0 0 0 0 0 0
53943 - 0 0 0 0 0 0 0 0 0 0 0 0
53944 - 0 0 0 6 6 6 14 14 14 42 42 42
53945 - 90 90 90 18 18 18 18 18 18 26 26 26
53946 - 2 2 6 116 116 116 253 253 253 253 253 253
53947 -253 253 253 253 253 253 253 253 253 253 253 253
53948 -253 253 253 253 253 253 250 250 250 238 238 238
53949 -253 253 253 253 253 253 253 253 253 253 253 253
53950 -253 253 253 253 253 253 253 253 253 253 253 253
53951 -253 253 253 253 253 253 253 253 253 253 253 253
53952 -253 253 253 253 253 253 253 253 253 253 253 253
53953 -253 253 253 253 253 253 94 94 94 6 6 6
53954 - 2 2 6 2 2 6 10 10 10 34 34 34
53955 - 2 2 6 2 2 6 2 2 6 2 2 6
53956 - 74 74 74 58 58 58 22 22 22 6 6 6
53957 - 0 0 0 0 0 0 0 0 0 0 0 0
53958 - 0 0 0 0 0 0 0 0 0 0 0 0
53959 - 0 0 0 0 0 0 0 0 0 0 0 0
53960 - 0 0 0 0 0 0 0 0 0 0 0 0
53961 - 0 0 0 0 0 0 0 0 0 0 0 0
53962 - 0 0 0 0 0 0 0 0 0 0 0 0
53963 - 0 0 0 0 0 0 0 0 0 0 0 0
53964 - 0 0 0 10 10 10 26 26 26 66 66 66
53965 - 82 82 82 2 2 6 38 38 38 6 6 6
53966 - 14 14 14 210 210 210 253 253 253 253 253 253
53967 -253 253 253 253 253 253 253 253 253 253 253 253
53968 -253 253 253 253 253 253 246 246 246 242 242 242
53969 -253 253 253 253 253 253 253 253 253 253 253 253
53970 -253 253 253 253 253 253 253 253 253 253 253 253
53971 -253 253 253 253 253 253 253 253 253 253 253 253
53972 -253 253 253 253 253 253 253 253 253 253 253 253
53973 -253 253 253 253 253 253 144 144 144 2 2 6
53974 - 2 2 6 2 2 6 2 2 6 46 46 46
53975 - 2 2 6 2 2 6 2 2 6 2 2 6
53976 - 42 42 42 74 74 74 30 30 30 10 10 10
53977 - 0 0 0 0 0 0 0 0 0 0 0 0
53978 - 0 0 0 0 0 0 0 0 0 0 0 0
53979 - 0 0 0 0 0 0 0 0 0 0 0 0
53980 - 0 0 0 0 0 0 0 0 0 0 0 0
53981 - 0 0 0 0 0 0 0 0 0 0 0 0
53982 - 0 0 0 0 0 0 0 0 0 0 0 0
53983 - 0 0 0 0 0 0 0 0 0 0 0 0
53984 - 6 6 6 14 14 14 42 42 42 90 90 90
53985 - 26 26 26 6 6 6 42 42 42 2 2 6
53986 - 74 74 74 250 250 250 253 253 253 253 253 253
53987 -253 253 253 253 253 253 253 253 253 253 253 253
53988 -253 253 253 253 253 253 242 242 242 242 242 242
53989 -253 253 253 253 253 253 253 253 253 253 253 253
53990 -253 253 253 253 253 253 253 253 253 253 253 253
53991 -253 253 253 253 253 253 253 253 253 253 253 253
53992 -253 253 253 253 253 253 253 253 253 253 253 253
53993 -253 253 253 253 253 253 182 182 182 2 2 6
53994 - 2 2 6 2 2 6 2 2 6 46 46 46
53995 - 2 2 6 2 2 6 2 2 6 2 2 6
53996 - 10 10 10 86 86 86 38 38 38 10 10 10
53997 - 0 0 0 0 0 0 0 0 0 0 0 0
53998 - 0 0 0 0 0 0 0 0 0 0 0 0
53999 - 0 0 0 0 0 0 0 0 0 0 0 0
54000 - 0 0 0 0 0 0 0 0 0 0 0 0
54001 - 0 0 0 0 0 0 0 0 0 0 0 0
54002 - 0 0 0 0 0 0 0 0 0 0 0 0
54003 - 0 0 0 0 0 0 0 0 0 0 0 0
54004 - 10 10 10 26 26 26 66 66 66 82 82 82
54005 - 2 2 6 22 22 22 18 18 18 2 2 6
54006 -149 149 149 253 253 253 253 253 253 253 253 253
54007 -253 253 253 253 253 253 253 253 253 253 253 253
54008 -253 253 253 253 253 253 234 234 234 242 242 242
54009 -253 253 253 253 253 253 253 253 253 253 253 253
54010 -253 253 253 253 253 253 253 253 253 253 253 253
54011 -253 253 253 253 253 253 253 253 253 253 253 253
54012 -253 253 253 253 253 253 253 253 253 253 253 253
54013 -253 253 253 253 253 253 206 206 206 2 2 6
54014 - 2 2 6 2 2 6 2 2 6 38 38 38
54015 - 2 2 6 2 2 6 2 2 6 2 2 6
54016 - 6 6 6 86 86 86 46 46 46 14 14 14
54017 - 0 0 0 0 0 0 0 0 0 0 0 0
54018 - 0 0 0 0 0 0 0 0 0 0 0 0
54019 - 0 0 0 0 0 0 0 0 0 0 0 0
54020 - 0 0 0 0 0 0 0 0 0 0 0 0
54021 - 0 0 0 0 0 0 0 0 0 0 0 0
54022 - 0 0 0 0 0 0 0 0 0 0 0 0
54023 - 0 0 0 0 0 0 0 0 0 6 6 6
54024 - 18 18 18 46 46 46 86 86 86 18 18 18
54025 - 2 2 6 34 34 34 10 10 10 6 6 6
54026 -210 210 210 253 253 253 253 253 253 253 253 253
54027 -253 253 253 253 253 253 253 253 253 253 253 253
54028 -253 253 253 253 253 253 234 234 234 242 242 242
54029 -253 253 253 253 253 253 253 253 253 253 253 253
54030 -253 253 253 253 253 253 253 253 253 253 253 253
54031 -253 253 253 253 253 253 253 253 253 253 253 253
54032 -253 253 253 253 253 253 253 253 253 253 253 253
54033 -253 253 253 253 253 253 221 221 221 6 6 6
54034 - 2 2 6 2 2 6 6 6 6 30 30 30
54035 - 2 2 6 2 2 6 2 2 6 2 2 6
54036 - 2 2 6 82 82 82 54 54 54 18 18 18
54037 - 6 6 6 0 0 0 0 0 0 0 0 0
54038 - 0 0 0 0 0 0 0 0 0 0 0 0
54039 - 0 0 0 0 0 0 0 0 0 0 0 0
54040 - 0 0 0 0 0 0 0 0 0 0 0 0
54041 - 0 0 0 0 0 0 0 0 0 0 0 0
54042 - 0 0 0 0 0 0 0 0 0 0 0 0
54043 - 0 0 0 0 0 0 0 0 0 10 10 10
54044 - 26 26 26 66 66 66 62 62 62 2 2 6
54045 - 2 2 6 38 38 38 10 10 10 26 26 26
54046 -238 238 238 253 253 253 253 253 253 253 253 253
54047 -253 253 253 253 253 253 253 253 253 253 253 253
54048 -253 253 253 253 253 253 231 231 231 238 238 238
54049 -253 253 253 253 253 253 253 253 253 253 253 253
54050 -253 253 253 253 253 253 253 253 253 253 253 253
54051 -253 253 253 253 253 253 253 253 253 253 253 253
54052 -253 253 253 253 253 253 253 253 253 253 253 253
54053 -253 253 253 253 253 253 231 231 231 6 6 6
54054 - 2 2 6 2 2 6 10 10 10 30 30 30
54055 - 2 2 6 2 2 6 2 2 6 2 2 6
54056 - 2 2 6 66 66 66 58 58 58 22 22 22
54057 - 6 6 6 0 0 0 0 0 0 0 0 0
54058 - 0 0 0 0 0 0 0 0 0 0 0 0
54059 - 0 0 0 0 0 0 0 0 0 0 0 0
54060 - 0 0 0 0 0 0 0 0 0 0 0 0
54061 - 0 0 0 0 0 0 0 0 0 0 0 0
54062 - 0 0 0 0 0 0 0 0 0 0 0 0
54063 - 0 0 0 0 0 0 0 0 0 10 10 10
54064 - 38 38 38 78 78 78 6 6 6 2 2 6
54065 - 2 2 6 46 46 46 14 14 14 42 42 42
54066 -246 246 246 253 253 253 253 253 253 253 253 253
54067 -253 253 253 253 253 253 253 253 253 253 253 253
54068 -253 253 253 253 253 253 231 231 231 242 242 242
54069 -253 253 253 253 253 253 253 253 253 253 253 253
54070 -253 253 253 253 253 253 253 253 253 253 253 253
54071 -253 253 253 253 253 253 253 253 253 253 253 253
54072 -253 253 253 253 253 253 253 253 253 253 253 253
54073 -253 253 253 253 253 253 234 234 234 10 10 10
54074 - 2 2 6 2 2 6 22 22 22 14 14 14
54075 - 2 2 6 2 2 6 2 2 6 2 2 6
54076 - 2 2 6 66 66 66 62 62 62 22 22 22
54077 - 6 6 6 0 0 0 0 0 0 0 0 0
54078 - 0 0 0 0 0 0 0 0 0 0 0 0
54079 - 0 0 0 0 0 0 0 0 0 0 0 0
54080 - 0 0 0 0 0 0 0 0 0 0 0 0
54081 - 0 0 0 0 0 0 0 0 0 0 0 0
54082 - 0 0 0 0 0 0 0 0 0 0 0 0
54083 - 0 0 0 0 0 0 6 6 6 18 18 18
54084 - 50 50 50 74 74 74 2 2 6 2 2 6
54085 - 14 14 14 70 70 70 34 34 34 62 62 62
54086 -250 250 250 253 253 253 253 253 253 253 253 253
54087 -253 253 253 253 253 253 253 253 253 253 253 253
54088 -253 253 253 253 253 253 231 231 231 246 246 246
54089 -253 253 253 253 253 253 253 253 253 253 253 253
54090 -253 253 253 253 253 253 253 253 253 253 253 253
54091 -253 253 253 253 253 253 253 253 253 253 253 253
54092 -253 253 253 253 253 253 253 253 253 253 253 253
54093 -253 253 253 253 253 253 234 234 234 14 14 14
54094 - 2 2 6 2 2 6 30 30 30 2 2 6
54095 - 2 2 6 2 2 6 2 2 6 2 2 6
54096 - 2 2 6 66 66 66 62 62 62 22 22 22
54097 - 6 6 6 0 0 0 0 0 0 0 0 0
54098 - 0 0 0 0 0 0 0 0 0 0 0 0
54099 - 0 0 0 0 0 0 0 0 0 0 0 0
54100 - 0 0 0 0 0 0 0 0 0 0 0 0
54101 - 0 0 0 0 0 0 0 0 0 0 0 0
54102 - 0 0 0 0 0 0 0 0 0 0 0 0
54103 - 0 0 0 0 0 0 6 6 6 18 18 18
54104 - 54 54 54 62 62 62 2 2 6 2 2 6
54105 - 2 2 6 30 30 30 46 46 46 70 70 70
54106 -250 250 250 253 253 253 253 253 253 253 253 253
54107 -253 253 253 253 253 253 253 253 253 253 253 253
54108 -253 253 253 253 253 253 231 231 231 246 246 246
54109 -253 253 253 253 253 253 253 253 253 253 253 253
54110 -253 253 253 253 253 253 253 253 253 253 253 253
54111 -253 253 253 253 253 253 253 253 253 253 253 253
54112 -253 253 253 253 253 253 253 253 253 253 253 253
54113 -253 253 253 253 253 253 226 226 226 10 10 10
54114 - 2 2 6 6 6 6 30 30 30 2 2 6
54115 - 2 2 6 2 2 6 2 2 6 2 2 6
54116 - 2 2 6 66 66 66 58 58 58 22 22 22
54117 - 6 6 6 0 0 0 0 0 0 0 0 0
54118 - 0 0 0 0 0 0 0 0 0 0 0 0
54119 - 0 0 0 0 0 0 0 0 0 0 0 0
54120 - 0 0 0 0 0 0 0 0 0 0 0 0
54121 - 0 0 0 0 0 0 0 0 0 0 0 0
54122 - 0 0 0 0 0 0 0 0 0 0 0 0
54123 - 0 0 0 0 0 0 6 6 6 22 22 22
54124 - 58 58 58 62 62 62 2 2 6 2 2 6
54125 - 2 2 6 2 2 6 30 30 30 78 78 78
54126 -250 250 250 253 253 253 253 253 253 253 253 253
54127 -253 253 253 253 253 253 253 253 253 253 253 253
54128 -253 253 253 253 253 253 231 231 231 246 246 246
54129 -253 253 253 253 253 253 253 253 253 253 253 253
54130 -253 253 253 253 253 253 253 253 253 253 253 253
54131 -253 253 253 253 253 253 253 253 253 253 253 253
54132 -253 253 253 253 253 253 253 253 253 253 253 253
54133 -253 253 253 253 253 253 206 206 206 2 2 6
54134 - 22 22 22 34 34 34 18 14 6 22 22 22
54135 - 26 26 26 18 18 18 6 6 6 2 2 6
54136 - 2 2 6 82 82 82 54 54 54 18 18 18
54137 - 6 6 6 0 0 0 0 0 0 0 0 0
54138 - 0 0 0 0 0 0 0 0 0 0 0 0
54139 - 0 0 0 0 0 0 0 0 0 0 0 0
54140 - 0 0 0 0 0 0 0 0 0 0 0 0
54141 - 0 0 0 0 0 0 0 0 0 0 0 0
54142 - 0 0 0 0 0 0 0 0 0 0 0 0
54143 - 0 0 0 0 0 0 6 6 6 26 26 26
54144 - 62 62 62 106 106 106 74 54 14 185 133 11
54145 -210 162 10 121 92 8 6 6 6 62 62 62
54146 -238 238 238 253 253 253 253 253 253 253 253 253
54147 -253 253 253 253 253 253 253 253 253 253 253 253
54148 -253 253 253 253 253 253 231 231 231 246 246 246
54149 -253 253 253 253 253 253 253 253 253 253 253 253
54150 -253 253 253 253 253 253 253 253 253 253 253 253
54151 -253 253 253 253 253 253 253 253 253 253 253 253
54152 -253 253 253 253 253 253 253 253 253 253 253 253
54153 -253 253 253 253 253 253 158 158 158 18 18 18
54154 - 14 14 14 2 2 6 2 2 6 2 2 6
54155 - 6 6 6 18 18 18 66 66 66 38 38 38
54156 - 6 6 6 94 94 94 50 50 50 18 18 18
54157 - 6 6 6 0 0 0 0 0 0 0 0 0
54158 - 0 0 0 0 0 0 0 0 0 0 0 0
54159 - 0 0 0 0 0 0 0 0 0 0 0 0
54160 - 0 0 0 0 0 0 0 0 0 0 0 0
54161 - 0 0 0 0 0 0 0 0 0 0 0 0
54162 - 0 0 0 0 0 0 0 0 0 6 6 6
54163 - 10 10 10 10 10 10 18 18 18 38 38 38
54164 - 78 78 78 142 134 106 216 158 10 242 186 14
54165 -246 190 14 246 190 14 156 118 10 10 10 10
54166 - 90 90 90 238 238 238 253 253 253 253 253 253
54167 -253 253 253 253 253 253 253 253 253 253 253 253
54168 -253 253 253 253 253 253 231 231 231 250 250 250
54169 -253 253 253 253 253 253 253 253 253 253 253 253
54170 -253 253 253 253 253 253 253 253 253 253 253 253
54171 -253 253 253 253 253 253 253 253 253 253 253 253
54172 -253 253 253 253 253 253 253 253 253 246 230 190
54173 -238 204 91 238 204 91 181 142 44 37 26 9
54174 - 2 2 6 2 2 6 2 2 6 2 2 6
54175 - 2 2 6 2 2 6 38 38 38 46 46 46
54176 - 26 26 26 106 106 106 54 54 54 18 18 18
54177 - 6 6 6 0 0 0 0 0 0 0 0 0
54178 - 0 0 0 0 0 0 0 0 0 0 0 0
54179 - 0 0 0 0 0 0 0 0 0 0 0 0
54180 - 0 0 0 0 0 0 0 0 0 0 0 0
54181 - 0 0 0 0 0 0 0 0 0 0 0 0
54182 - 0 0 0 6 6 6 14 14 14 22 22 22
54183 - 30 30 30 38 38 38 50 50 50 70 70 70
54184 -106 106 106 190 142 34 226 170 11 242 186 14
54185 -246 190 14 246 190 14 246 190 14 154 114 10
54186 - 6 6 6 74 74 74 226 226 226 253 253 253
54187 -253 253 253 253 253 253 253 253 253 253 253 253
54188 -253 253 253 253 253 253 231 231 231 250 250 250
54189 -253 253 253 253 253 253 253 253 253 253 253 253
54190 -253 253 253 253 253 253 253 253 253 253 253 253
54191 -253 253 253 253 253 253 253 253 253 253 253 253
54192 -253 253 253 253 253 253 253 253 253 228 184 62
54193 -241 196 14 241 208 19 232 195 16 38 30 10
54194 - 2 2 6 2 2 6 2 2 6 2 2 6
54195 - 2 2 6 6 6 6 30 30 30 26 26 26
54196 -203 166 17 154 142 90 66 66 66 26 26 26
54197 - 6 6 6 0 0 0 0 0 0 0 0 0
54198 - 0 0 0 0 0 0 0 0 0 0 0 0
54199 - 0 0 0 0 0 0 0 0 0 0 0 0
54200 - 0 0 0 0 0 0 0 0 0 0 0 0
54201 - 0 0 0 0 0 0 0 0 0 0 0 0
54202 - 6 6 6 18 18 18 38 38 38 58 58 58
54203 - 78 78 78 86 86 86 101 101 101 123 123 123
54204 -175 146 61 210 150 10 234 174 13 246 186 14
54205 -246 190 14 246 190 14 246 190 14 238 190 10
54206 -102 78 10 2 2 6 46 46 46 198 198 198
54207 -253 253 253 253 253 253 253 253 253 253 253 253
54208 -253 253 253 253 253 253 234 234 234 242 242 242
54209 -253 253 253 253 253 253 253 253 253 253 253 253
54210 -253 253 253 253 253 253 253 253 253 253 253 253
54211 -253 253 253 253 253 253 253 253 253 253 253 253
54212 -253 253 253 253 253 253 253 253 253 224 178 62
54213 -242 186 14 241 196 14 210 166 10 22 18 6
54214 - 2 2 6 2 2 6 2 2 6 2 2 6
54215 - 2 2 6 2 2 6 6 6 6 121 92 8
54216 -238 202 15 232 195 16 82 82 82 34 34 34
54217 - 10 10 10 0 0 0 0 0 0 0 0 0
54218 - 0 0 0 0 0 0 0 0 0 0 0 0
54219 - 0 0 0 0 0 0 0 0 0 0 0 0
54220 - 0 0 0 0 0 0 0 0 0 0 0 0
54221 - 0 0 0 0 0 0 0 0 0 0 0 0
54222 - 14 14 14 38 38 38 70 70 70 154 122 46
54223 -190 142 34 200 144 11 197 138 11 197 138 11
54224 -213 154 11 226 170 11 242 186 14 246 190 14
54225 -246 190 14 246 190 14 246 190 14 246 190 14
54226 -225 175 15 46 32 6 2 2 6 22 22 22
54227 -158 158 158 250 250 250 253 253 253 253 253 253
54228 -253 253 253 253 253 253 253 253 253 253 253 253
54229 -253 253 253 253 253 253 253 253 253 253 253 253
54230 -253 253 253 253 253 253 253 253 253 253 253 253
54231 -253 253 253 253 253 253 253 253 253 253 253 253
54232 -253 253 253 250 250 250 242 242 242 224 178 62
54233 -239 182 13 236 186 11 213 154 11 46 32 6
54234 - 2 2 6 2 2 6 2 2 6 2 2 6
54235 - 2 2 6 2 2 6 61 42 6 225 175 15
54236 -238 190 10 236 186 11 112 100 78 42 42 42
54237 - 14 14 14 0 0 0 0 0 0 0 0 0
54238 - 0 0 0 0 0 0 0 0 0 0 0 0
54239 - 0 0 0 0 0 0 0 0 0 0 0 0
54240 - 0 0 0 0 0 0 0 0 0 0 0 0
54241 - 0 0 0 0 0 0 0 0 0 6 6 6
54242 - 22 22 22 54 54 54 154 122 46 213 154 11
54243 -226 170 11 230 174 11 226 170 11 226 170 11
54244 -236 178 12 242 186 14 246 190 14 246 190 14
54245 -246 190 14 246 190 14 246 190 14 246 190 14
54246 -241 196 14 184 144 12 10 10 10 2 2 6
54247 - 6 6 6 116 116 116 242 242 242 253 253 253
54248 -253 253 253 253 253 253 253 253 253 253 253 253
54249 -253 253 253 253 253 253 253 253 253 253 253 253
54250 -253 253 253 253 253 253 253 253 253 253 253 253
54251 -253 253 253 253 253 253 253 253 253 253 253 253
54252 -253 253 253 231 231 231 198 198 198 214 170 54
54253 -236 178 12 236 178 12 210 150 10 137 92 6
54254 - 18 14 6 2 2 6 2 2 6 2 2 6
54255 - 6 6 6 70 47 6 200 144 11 236 178 12
54256 -239 182 13 239 182 13 124 112 88 58 58 58
54257 - 22 22 22 6 6 6 0 0 0 0 0 0
54258 - 0 0 0 0 0 0 0 0 0 0 0 0
54259 - 0 0 0 0 0 0 0 0 0 0 0 0
54260 - 0 0 0 0 0 0 0 0 0 0 0 0
54261 - 0 0 0 0 0 0 0 0 0 10 10 10
54262 - 30 30 30 70 70 70 180 133 36 226 170 11
54263 -239 182 13 242 186 14 242 186 14 246 186 14
54264 -246 190 14 246 190 14 246 190 14 246 190 14
54265 -246 190 14 246 190 14 246 190 14 246 190 14
54266 -246 190 14 232 195 16 98 70 6 2 2 6
54267 - 2 2 6 2 2 6 66 66 66 221 221 221
54268 -253 253 253 253 253 253 253 253 253 253 253 253
54269 -253 253 253 253 253 253 253 253 253 253 253 253
54270 -253 253 253 253 253 253 253 253 253 253 253 253
54271 -253 253 253 253 253 253 253 253 253 253 253 253
54272 -253 253 253 206 206 206 198 198 198 214 166 58
54273 -230 174 11 230 174 11 216 158 10 192 133 9
54274 -163 110 8 116 81 8 102 78 10 116 81 8
54275 -167 114 7 197 138 11 226 170 11 239 182 13
54276 -242 186 14 242 186 14 162 146 94 78 78 78
54277 - 34 34 34 14 14 14 6 6 6 0 0 0
54278 - 0 0 0 0 0 0 0 0 0 0 0 0
54279 - 0 0 0 0 0 0 0 0 0 0 0 0
54280 - 0 0 0 0 0 0 0 0 0 0 0 0
54281 - 0 0 0 0 0 0 0 0 0 6 6 6
54282 - 30 30 30 78 78 78 190 142 34 226 170 11
54283 -239 182 13 246 190 14 246 190 14 246 190 14
54284 -246 190 14 246 190 14 246 190 14 246 190 14
54285 -246 190 14 246 190 14 246 190 14 246 190 14
54286 -246 190 14 241 196 14 203 166 17 22 18 6
54287 - 2 2 6 2 2 6 2 2 6 38 38 38
54288 -218 218 218 253 253 253 253 253 253 253 253 253
54289 -253 253 253 253 253 253 253 253 253 253 253 253
54290 -253 253 253 253 253 253 253 253 253 253 253 253
54291 -253 253 253 253 253 253 253 253 253 253 253 253
54292 -250 250 250 206 206 206 198 198 198 202 162 69
54293 -226 170 11 236 178 12 224 166 10 210 150 10
54294 -200 144 11 197 138 11 192 133 9 197 138 11
54295 -210 150 10 226 170 11 242 186 14 246 190 14
54296 -246 190 14 246 186 14 225 175 15 124 112 88
54297 - 62 62 62 30 30 30 14 14 14 6 6 6
54298 - 0 0 0 0 0 0 0 0 0 0 0 0
54299 - 0 0 0 0 0 0 0 0 0 0 0 0
54300 - 0 0 0 0 0 0 0 0 0 0 0 0
54301 - 0 0 0 0 0 0 0 0 0 10 10 10
54302 - 30 30 30 78 78 78 174 135 50 224 166 10
54303 -239 182 13 246 190 14 246 190 14 246 190 14
54304 -246 190 14 246 190 14 246 190 14 246 190 14
54305 -246 190 14 246 190 14 246 190 14 246 190 14
54306 -246 190 14 246 190 14 241 196 14 139 102 15
54307 - 2 2 6 2 2 6 2 2 6 2 2 6
54308 - 78 78 78 250 250 250 253 253 253 253 253 253
54309 -253 253 253 253 253 253 253 253 253 253 253 253
54310 -253 253 253 253 253 253 253 253 253 253 253 253
54311 -253 253 253 253 253 253 253 253 253 253 253 253
54312 -250 250 250 214 214 214 198 198 198 190 150 46
54313 -219 162 10 236 178 12 234 174 13 224 166 10
54314 -216 158 10 213 154 11 213 154 11 216 158 10
54315 -226 170 11 239 182 13 246 190 14 246 190 14
54316 -246 190 14 246 190 14 242 186 14 206 162 42
54317 -101 101 101 58 58 58 30 30 30 14 14 14
54318 - 6 6 6 0 0 0 0 0 0 0 0 0
54319 - 0 0 0 0 0 0 0 0 0 0 0 0
54320 - 0 0 0 0 0 0 0 0 0 0 0 0
54321 - 0 0 0 0 0 0 0 0 0 10 10 10
54322 - 30 30 30 74 74 74 174 135 50 216 158 10
54323 -236 178 12 246 190 14 246 190 14 246 190 14
54324 -246 190 14 246 190 14 246 190 14 246 190 14
54325 -246 190 14 246 190 14 246 190 14 246 190 14
54326 -246 190 14 246 190 14 241 196 14 226 184 13
54327 - 61 42 6 2 2 6 2 2 6 2 2 6
54328 - 22 22 22 238 238 238 253 253 253 253 253 253
54329 -253 253 253 253 253 253 253 253 253 253 253 253
54330 -253 253 253 253 253 253 253 253 253 253 253 253
54331 -253 253 253 253 253 253 253 253 253 253 253 253
54332 -253 253 253 226 226 226 187 187 187 180 133 36
54333 -216 158 10 236 178 12 239 182 13 236 178 12
54334 -230 174 11 226 170 11 226 170 11 230 174 11
54335 -236 178 12 242 186 14 246 190 14 246 190 14
54336 -246 190 14 246 190 14 246 186 14 239 182 13
54337 -206 162 42 106 106 106 66 66 66 34 34 34
54338 - 14 14 14 6 6 6 0 0 0 0 0 0
54339 - 0 0 0 0 0 0 0 0 0 0 0 0
54340 - 0 0 0 0 0 0 0 0 0 0 0 0
54341 - 0 0 0 0 0 0 0 0 0 6 6 6
54342 - 26 26 26 70 70 70 163 133 67 213 154 11
54343 -236 178 12 246 190 14 246 190 14 246 190 14
54344 -246 190 14 246 190 14 246 190 14 246 190 14
54345 -246 190 14 246 190 14 246 190 14 246 190 14
54346 -246 190 14 246 190 14 246 190 14 241 196 14
54347 -190 146 13 18 14 6 2 2 6 2 2 6
54348 - 46 46 46 246 246 246 253 253 253 253 253 253
54349 -253 253 253 253 253 253 253 253 253 253 253 253
54350 -253 253 253 253 253 253 253 253 253 253 253 253
54351 -253 253 253 253 253 253 253 253 253 253 253 253
54352 -253 253 253 221 221 221 86 86 86 156 107 11
54353 -216 158 10 236 178 12 242 186 14 246 186 14
54354 -242 186 14 239 182 13 239 182 13 242 186 14
54355 -242 186 14 246 186 14 246 190 14 246 190 14
54356 -246 190 14 246 190 14 246 190 14 246 190 14
54357 -242 186 14 225 175 15 142 122 72 66 66 66
54358 - 30 30 30 10 10 10 0 0 0 0 0 0
54359 - 0 0 0 0 0 0 0 0 0 0 0 0
54360 - 0 0 0 0 0 0 0 0 0 0 0 0
54361 - 0 0 0 0 0 0 0 0 0 6 6 6
54362 - 26 26 26 70 70 70 163 133 67 210 150 10
54363 -236 178 12 246 190 14 246 190 14 246 190 14
54364 -246 190 14 246 190 14 246 190 14 246 190 14
54365 -246 190 14 246 190 14 246 190 14 246 190 14
54366 -246 190 14 246 190 14 246 190 14 246 190 14
54367 -232 195 16 121 92 8 34 34 34 106 106 106
54368 -221 221 221 253 253 253 253 253 253 253 253 253
54369 -253 253 253 253 253 253 253 253 253 253 253 253
54370 -253 253 253 253 253 253 253 253 253 253 253 253
54371 -253 253 253 253 253 253 253 253 253 253 253 253
54372 -242 242 242 82 82 82 18 14 6 163 110 8
54373 -216 158 10 236 178 12 242 186 14 246 190 14
54374 -246 190 14 246 190 14 246 190 14 246 190 14
54375 -246 190 14 246 190 14 246 190 14 246 190 14
54376 -246 190 14 246 190 14 246 190 14 246 190 14
54377 -246 190 14 246 190 14 242 186 14 163 133 67
54378 - 46 46 46 18 18 18 6 6 6 0 0 0
54379 - 0 0 0 0 0 0 0 0 0 0 0 0
54380 - 0 0 0 0 0 0 0 0 0 0 0 0
54381 - 0 0 0 0 0 0 0 0 0 10 10 10
54382 - 30 30 30 78 78 78 163 133 67 210 150 10
54383 -236 178 12 246 186 14 246 190 14 246 190 14
54384 -246 190 14 246 190 14 246 190 14 246 190 14
54385 -246 190 14 246 190 14 246 190 14 246 190 14
54386 -246 190 14 246 190 14 246 190 14 246 190 14
54387 -241 196 14 215 174 15 190 178 144 253 253 253
54388 -253 253 253 253 253 253 253 253 253 253 253 253
54389 -253 253 253 253 253 253 253 253 253 253 253 253
54390 -253 253 253 253 253 253 253 253 253 253 253 253
54391 -253 253 253 253 253 253 253 253 253 218 218 218
54392 - 58 58 58 2 2 6 22 18 6 167 114 7
54393 -216 158 10 236 178 12 246 186 14 246 190 14
54394 -246 190 14 246 190 14 246 190 14 246 190 14
54395 -246 190 14 246 190 14 246 190 14 246 190 14
54396 -246 190 14 246 190 14 246 190 14 246 190 14
54397 -246 190 14 246 186 14 242 186 14 190 150 46
54398 - 54 54 54 22 22 22 6 6 6 0 0 0
54399 - 0 0 0 0 0 0 0 0 0 0 0 0
54400 - 0 0 0 0 0 0 0 0 0 0 0 0
54401 - 0 0 0 0 0 0 0 0 0 14 14 14
54402 - 38 38 38 86 86 86 180 133 36 213 154 11
54403 -236 178 12 246 186 14 246 190 14 246 190 14
54404 -246 190 14 246 190 14 246 190 14 246 190 14
54405 -246 190 14 246 190 14 246 190 14 246 190 14
54406 -246 190 14 246 190 14 246 190 14 246 190 14
54407 -246 190 14 232 195 16 190 146 13 214 214 214
54408 -253 253 253 253 253 253 253 253 253 253 253 253
54409 -253 253 253 253 253 253 253 253 253 253 253 253
54410 -253 253 253 253 253 253 253 253 253 253 253 253
54411 -253 253 253 250 250 250 170 170 170 26 26 26
54412 - 2 2 6 2 2 6 37 26 9 163 110 8
54413 -219 162 10 239 182 13 246 186 14 246 190 14
54414 -246 190 14 246 190 14 246 190 14 246 190 14
54415 -246 190 14 246 190 14 246 190 14 246 190 14
54416 -246 190 14 246 190 14 246 190 14 246 190 14
54417 -246 186 14 236 178 12 224 166 10 142 122 72
54418 - 46 46 46 18 18 18 6 6 6 0 0 0
54419 - 0 0 0 0 0 0 0 0 0 0 0 0
54420 - 0 0 0 0 0 0 0 0 0 0 0 0
54421 - 0 0 0 0 0 0 6 6 6 18 18 18
54422 - 50 50 50 109 106 95 192 133 9 224 166 10
54423 -242 186 14 246 190 14 246 190 14 246 190 14
54424 -246 190 14 246 190 14 246 190 14 246 190 14
54425 -246 190 14 246 190 14 246 190 14 246 190 14
54426 -246 190 14 246 190 14 246 190 14 246 190 14
54427 -242 186 14 226 184 13 210 162 10 142 110 46
54428 -226 226 226 253 253 253 253 253 253 253 253 253
54429 -253 253 253 253 253 253 253 253 253 253 253 253
54430 -253 253 253 253 253 253 253 253 253 253 253 253
54431 -198 198 198 66 66 66 2 2 6 2 2 6
54432 - 2 2 6 2 2 6 50 34 6 156 107 11
54433 -219 162 10 239 182 13 246 186 14 246 190 14
54434 -246 190 14 246 190 14 246 190 14 246 190 14
54435 -246 190 14 246 190 14 246 190 14 246 190 14
54436 -246 190 14 246 190 14 246 190 14 242 186 14
54437 -234 174 13 213 154 11 154 122 46 66 66 66
54438 - 30 30 30 10 10 10 0 0 0 0 0 0
54439 - 0 0 0 0 0 0 0 0 0 0 0 0
54440 - 0 0 0 0 0 0 0 0 0 0 0 0
54441 - 0 0 0 0 0 0 6 6 6 22 22 22
54442 - 58 58 58 154 121 60 206 145 10 234 174 13
54443 -242 186 14 246 186 14 246 190 14 246 190 14
54444 -246 190 14 246 190 14 246 190 14 246 190 14
54445 -246 190 14 246 190 14 246 190 14 246 190 14
54446 -246 190 14 246 190 14 246 190 14 246 190 14
54447 -246 186 14 236 178 12 210 162 10 163 110 8
54448 - 61 42 6 138 138 138 218 218 218 250 250 250
54449 -253 253 253 253 253 253 253 253 253 250 250 250
54450 -242 242 242 210 210 210 144 144 144 66 66 66
54451 - 6 6 6 2 2 6 2 2 6 2 2 6
54452 - 2 2 6 2 2 6 61 42 6 163 110 8
54453 -216 158 10 236 178 12 246 190 14 246 190 14
54454 -246 190 14 246 190 14 246 190 14 246 190 14
54455 -246 190 14 246 190 14 246 190 14 246 190 14
54456 -246 190 14 239 182 13 230 174 11 216 158 10
54457 -190 142 34 124 112 88 70 70 70 38 38 38
54458 - 18 18 18 6 6 6 0 0 0 0 0 0
54459 - 0 0 0 0 0 0 0 0 0 0 0 0
54460 - 0 0 0 0 0 0 0 0 0 0 0 0
54461 - 0 0 0 0 0 0 6 6 6 22 22 22
54462 - 62 62 62 168 124 44 206 145 10 224 166 10
54463 -236 178 12 239 182 13 242 186 14 242 186 14
54464 -246 186 14 246 190 14 246 190 14 246 190 14
54465 -246 190 14 246 190 14 246 190 14 246 190 14
54466 -246 190 14 246 190 14 246 190 14 246 190 14
54467 -246 190 14 236 178 12 216 158 10 175 118 6
54468 - 80 54 7 2 2 6 6 6 6 30 30 30
54469 - 54 54 54 62 62 62 50 50 50 38 38 38
54470 - 14 14 14 2 2 6 2 2 6 2 2 6
54471 - 2 2 6 2 2 6 2 2 6 2 2 6
54472 - 2 2 6 6 6 6 80 54 7 167 114 7
54473 -213 154 11 236 178 12 246 190 14 246 190 14
54474 -246 190 14 246 190 14 246 190 14 246 190 14
54475 -246 190 14 242 186 14 239 182 13 239 182 13
54476 -230 174 11 210 150 10 174 135 50 124 112 88
54477 - 82 82 82 54 54 54 34 34 34 18 18 18
54478 - 6 6 6 0 0 0 0 0 0 0 0 0
54479 - 0 0 0 0 0 0 0 0 0 0 0 0
54480 - 0 0 0 0 0 0 0 0 0 0 0 0
54481 - 0 0 0 0 0 0 6 6 6 18 18 18
54482 - 50 50 50 158 118 36 192 133 9 200 144 11
54483 -216 158 10 219 162 10 224 166 10 226 170 11
54484 -230 174 11 236 178 12 239 182 13 239 182 13
54485 -242 186 14 246 186 14 246 190 14 246 190 14
54486 -246 190 14 246 190 14 246 190 14 246 190 14
54487 -246 186 14 230 174 11 210 150 10 163 110 8
54488 -104 69 6 10 10 10 2 2 6 2 2 6
54489 - 2 2 6 2 2 6 2 2 6 2 2 6
54490 - 2 2 6 2 2 6 2 2 6 2 2 6
54491 - 2 2 6 2 2 6 2 2 6 2 2 6
54492 - 2 2 6 6 6 6 91 60 6 167 114 7
54493 -206 145 10 230 174 11 242 186 14 246 190 14
54494 -246 190 14 246 190 14 246 186 14 242 186 14
54495 -239 182 13 230 174 11 224 166 10 213 154 11
54496 -180 133 36 124 112 88 86 86 86 58 58 58
54497 - 38 38 38 22 22 22 10 10 10 6 6 6
54498 - 0 0 0 0 0 0 0 0 0 0 0 0
54499 - 0 0 0 0 0 0 0 0 0 0 0 0
54500 - 0 0 0 0 0 0 0 0 0 0 0 0
54501 - 0 0 0 0 0 0 0 0 0 14 14 14
54502 - 34 34 34 70 70 70 138 110 50 158 118 36
54503 -167 114 7 180 123 7 192 133 9 197 138 11
54504 -200 144 11 206 145 10 213 154 11 219 162 10
54505 -224 166 10 230 174 11 239 182 13 242 186 14
54506 -246 186 14 246 186 14 246 186 14 246 186 14
54507 -239 182 13 216 158 10 185 133 11 152 99 6
54508 -104 69 6 18 14 6 2 2 6 2 2 6
54509 - 2 2 6 2 2 6 2 2 6 2 2 6
54510 - 2 2 6 2 2 6 2 2 6 2 2 6
54511 - 2 2 6 2 2 6 2 2 6 2 2 6
54512 - 2 2 6 6 6 6 80 54 7 152 99 6
54513 -192 133 9 219 162 10 236 178 12 239 182 13
54514 -246 186 14 242 186 14 239 182 13 236 178 12
54515 -224 166 10 206 145 10 192 133 9 154 121 60
54516 - 94 94 94 62 62 62 42 42 42 22 22 22
54517 - 14 14 14 6 6 6 0 0 0 0 0 0
54518 - 0 0 0 0 0 0 0 0 0 0 0 0
54519 - 0 0 0 0 0 0 0 0 0 0 0 0
54520 - 0 0 0 0 0 0 0 0 0 0 0 0
54521 - 0 0 0 0 0 0 0 0 0 6 6 6
54522 - 18 18 18 34 34 34 58 58 58 78 78 78
54523 -101 98 89 124 112 88 142 110 46 156 107 11
54524 -163 110 8 167 114 7 175 118 6 180 123 7
54525 -185 133 11 197 138 11 210 150 10 219 162 10
54526 -226 170 11 236 178 12 236 178 12 234 174 13
54527 -219 162 10 197 138 11 163 110 8 130 83 6
54528 - 91 60 6 10 10 10 2 2 6 2 2 6
54529 - 18 18 18 38 38 38 38 38 38 38 38 38
54530 - 38 38 38 38 38 38 38 38 38 38 38 38
54531 - 38 38 38 38 38 38 26 26 26 2 2 6
54532 - 2 2 6 6 6 6 70 47 6 137 92 6
54533 -175 118 6 200 144 11 219 162 10 230 174 11
54534 -234 174 13 230 174 11 219 162 10 210 150 10
54535 -192 133 9 163 110 8 124 112 88 82 82 82
54536 - 50 50 50 30 30 30 14 14 14 6 6 6
54537 - 0 0 0 0 0 0 0 0 0 0 0 0
54538 - 0 0 0 0 0 0 0 0 0 0 0 0
54539 - 0 0 0 0 0 0 0 0 0 0 0 0
54540 - 0 0 0 0 0 0 0 0 0 0 0 0
54541 - 0 0 0 0 0 0 0 0 0 0 0 0
54542 - 6 6 6 14 14 14 22 22 22 34 34 34
54543 - 42 42 42 58 58 58 74 74 74 86 86 86
54544 -101 98 89 122 102 70 130 98 46 121 87 25
54545 -137 92 6 152 99 6 163 110 8 180 123 7
54546 -185 133 11 197 138 11 206 145 10 200 144 11
54547 -180 123 7 156 107 11 130 83 6 104 69 6
54548 - 50 34 6 54 54 54 110 110 110 101 98 89
54549 - 86 86 86 82 82 82 78 78 78 78 78 78
54550 - 78 78 78 78 78 78 78 78 78 78 78 78
54551 - 78 78 78 82 82 82 86 86 86 94 94 94
54552 -106 106 106 101 101 101 86 66 34 124 80 6
54553 -156 107 11 180 123 7 192 133 9 200 144 11
54554 -206 145 10 200 144 11 192 133 9 175 118 6
54555 -139 102 15 109 106 95 70 70 70 42 42 42
54556 - 22 22 22 10 10 10 0 0 0 0 0 0
54557 - 0 0 0 0 0 0 0 0 0 0 0 0
54558 - 0 0 0 0 0 0 0 0 0 0 0 0
54559 - 0 0 0 0 0 0 0 0 0 0 0 0
54560 - 0 0 0 0 0 0 0 0 0 0 0 0
54561 - 0 0 0 0 0 0 0 0 0 0 0 0
54562 - 0 0 0 0 0 0 6 6 6 10 10 10
54563 - 14 14 14 22 22 22 30 30 30 38 38 38
54564 - 50 50 50 62 62 62 74 74 74 90 90 90
54565 -101 98 89 112 100 78 121 87 25 124 80 6
54566 -137 92 6 152 99 6 152 99 6 152 99 6
54567 -138 86 6 124 80 6 98 70 6 86 66 30
54568 -101 98 89 82 82 82 58 58 58 46 46 46
54569 - 38 38 38 34 34 34 34 34 34 34 34 34
54570 - 34 34 34 34 34 34 34 34 34 34 34 34
54571 - 34 34 34 34 34 34 38 38 38 42 42 42
54572 - 54 54 54 82 82 82 94 86 76 91 60 6
54573 -134 86 6 156 107 11 167 114 7 175 118 6
54574 -175 118 6 167 114 7 152 99 6 121 87 25
54575 -101 98 89 62 62 62 34 34 34 18 18 18
54576 - 6 6 6 0 0 0 0 0 0 0 0 0
54577 - 0 0 0 0 0 0 0 0 0 0 0 0
54578 - 0 0 0 0 0 0 0 0 0 0 0 0
54579 - 0 0 0 0 0 0 0 0 0 0 0 0
54580 - 0 0 0 0 0 0 0 0 0 0 0 0
54581 - 0 0 0 0 0 0 0 0 0 0 0 0
54582 - 0 0 0 0 0 0 0 0 0 0 0 0
54583 - 0 0 0 6 6 6 6 6 6 10 10 10
54584 - 18 18 18 22 22 22 30 30 30 42 42 42
54585 - 50 50 50 66 66 66 86 86 86 101 98 89
54586 -106 86 58 98 70 6 104 69 6 104 69 6
54587 -104 69 6 91 60 6 82 62 34 90 90 90
54588 - 62 62 62 38 38 38 22 22 22 14 14 14
54589 - 10 10 10 10 10 10 10 10 10 10 10 10
54590 - 10 10 10 10 10 10 6 6 6 10 10 10
54591 - 10 10 10 10 10 10 10 10 10 14 14 14
54592 - 22 22 22 42 42 42 70 70 70 89 81 66
54593 - 80 54 7 104 69 6 124 80 6 137 92 6
54594 -134 86 6 116 81 8 100 82 52 86 86 86
54595 - 58 58 58 30 30 30 14 14 14 6 6 6
54596 - 0 0 0 0 0 0 0 0 0 0 0 0
54597 - 0 0 0 0 0 0 0 0 0 0 0 0
54598 - 0 0 0 0 0 0 0 0 0 0 0 0
54599 - 0 0 0 0 0 0 0 0 0 0 0 0
54600 - 0 0 0 0 0 0 0 0 0 0 0 0
54601 - 0 0 0 0 0 0 0 0 0 0 0 0
54602 - 0 0 0 0 0 0 0 0 0 0 0 0
54603 - 0 0 0 0 0 0 0 0 0 0 0 0
54604 - 0 0 0 6 6 6 10 10 10 14 14 14
54605 - 18 18 18 26 26 26 38 38 38 54 54 54
54606 - 70 70 70 86 86 86 94 86 76 89 81 66
54607 - 89 81 66 86 86 86 74 74 74 50 50 50
54608 - 30 30 30 14 14 14 6 6 6 0 0 0
54609 - 0 0 0 0 0 0 0 0 0 0 0 0
54610 - 0 0 0 0 0 0 0 0 0 0 0 0
54611 - 0 0 0 0 0 0 0 0 0 0 0 0
54612 - 6 6 6 18 18 18 34 34 34 58 58 58
54613 - 82 82 82 89 81 66 89 81 66 89 81 66
54614 - 94 86 66 94 86 76 74 74 74 50 50 50
54615 - 26 26 26 14 14 14 6 6 6 0 0 0
54616 - 0 0 0 0 0 0 0 0 0 0 0 0
54617 - 0 0 0 0 0 0 0 0 0 0 0 0
54618 - 0 0 0 0 0 0 0 0 0 0 0 0
54619 - 0 0 0 0 0 0 0 0 0 0 0 0
54620 - 0 0 0 0 0 0 0 0 0 0 0 0
54621 - 0 0 0 0 0 0 0 0 0 0 0 0
54622 - 0 0 0 0 0 0 0 0 0 0 0 0
54623 - 0 0 0 0 0 0 0 0 0 0 0 0
54624 - 0 0 0 0 0 0 0 0 0 0 0 0
54625 - 6 6 6 6 6 6 14 14 14 18 18 18
54626 - 30 30 30 38 38 38 46 46 46 54 54 54
54627 - 50 50 50 42 42 42 30 30 30 18 18 18
54628 - 10 10 10 0 0 0 0 0 0 0 0 0
54629 - 0 0 0 0 0 0 0 0 0 0 0 0
54630 - 0 0 0 0 0 0 0 0 0 0 0 0
54631 - 0 0 0 0 0 0 0 0 0 0 0 0
54632 - 0 0 0 6 6 6 14 14 14 26 26 26
54633 - 38 38 38 50 50 50 58 58 58 58 58 58
54634 - 54 54 54 42 42 42 30 30 30 18 18 18
54635 - 10 10 10 0 0 0 0 0 0 0 0 0
54636 - 0 0 0 0 0 0 0 0 0 0 0 0
54637 - 0 0 0 0 0 0 0 0 0 0 0 0
54638 - 0 0 0 0 0 0 0 0 0 0 0 0
54639 - 0 0 0 0 0 0 0 0 0 0 0 0
54640 - 0 0 0 0 0 0 0 0 0 0 0 0
54641 - 0 0 0 0 0 0 0 0 0 0 0 0
54642 - 0 0 0 0 0 0 0 0 0 0 0 0
54643 - 0 0 0 0 0 0 0 0 0 0 0 0
54644 - 0 0 0 0 0 0 0 0 0 0 0 0
54645 - 0 0 0 0 0 0 0 0 0 6 6 6
54646 - 6 6 6 10 10 10 14 14 14 18 18 18
54647 - 18 18 18 14 14 14 10 10 10 6 6 6
54648 - 0 0 0 0 0 0 0 0 0 0 0 0
54649 - 0 0 0 0 0 0 0 0 0 0 0 0
54650 - 0 0 0 0 0 0 0 0 0 0 0 0
54651 - 0 0 0 0 0 0 0 0 0 0 0 0
54652 - 0 0 0 0 0 0 0 0 0 6 6 6
54653 - 14 14 14 18 18 18 22 22 22 22 22 22
54654 - 18 18 18 14 14 14 10 10 10 6 6 6
54655 - 0 0 0 0 0 0 0 0 0 0 0 0
54656 - 0 0 0 0 0 0 0 0 0 0 0 0
54657 - 0 0 0 0 0 0 0 0 0 0 0 0
54658 - 0 0 0 0 0 0 0 0 0 0 0 0
54659 - 0 0 0 0 0 0 0 0 0 0 0 0
54660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54664 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54673 +4 4 4 4 4 4
54674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54687 +4 4 4 4 4 4
54688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54701 +4 4 4 4 4 4
54702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54715 +4 4 4 4 4 4
54716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54729 +4 4 4 4 4 4
54730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54743 +4 4 4 4 4 4
54744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54748 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54749 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54753 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54754 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54755 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54757 +4 4 4 4 4 4
54758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54762 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54763 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54764 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54767 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54768 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54769 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54770 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54771 +4 4 4 4 4 4
54772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54776 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54777 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54778 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54781 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54782 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54783 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54784 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54785 +4 4 4 4 4 4
54786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54789 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54790 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54791 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54792 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54794 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54795 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54796 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54797 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54798 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54799 +4 4 4 4 4 4
54800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54803 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54804 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54805 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54806 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54807 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54808 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54809 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54810 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54811 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54812 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54813 +4 4 4 4 4 4
54814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54817 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54818 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54819 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54820 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54821 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54822 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54823 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54824 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54825 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54826 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54827 +4 4 4 4 4 4
54828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54830 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54831 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54832 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54833 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54834 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54835 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54836 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54837 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54838 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54839 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54840 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54841 +4 4 4 4 4 4
54842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54844 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54845 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54846 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54847 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54848 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54849 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54850 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54851 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54852 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54853 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54854 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54855 +4 4 4 4 4 4
54856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54858 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54859 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54860 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54861 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54862 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54863 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54864 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54865 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54866 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54867 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54868 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54869 +4 4 4 4 4 4
54870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54872 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54873 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54874 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54875 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54876 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54877 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54878 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54879 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54880 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54881 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54882 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54883 +4 4 4 4 4 4
54884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54885 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54886 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54887 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54888 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54889 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54890 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54891 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54892 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54893 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54894 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54895 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54896 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54897 +4 4 4 4 4 4
54898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54899 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54900 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54901 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54902 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54903 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54904 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54905 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54906 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54907 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54908 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54909 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54910 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54911 +0 0 0 4 4 4
54912 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54913 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54914 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54915 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54916 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54917 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54918 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54919 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54920 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54921 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54922 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54923 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54924 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54925 +2 0 0 0 0 0
54926 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54927 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54928 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54929 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54930 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54931 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54932 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54933 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54934 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54935 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54936 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54937 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54938 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54939 +37 38 37 0 0 0
54940 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54941 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54942 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54943 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54944 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54945 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54946 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54947 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54948 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54949 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54950 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54951 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54952 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54953 +85 115 134 4 0 0
54954 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54955 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54956 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54957 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54958 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54959 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54960 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54961 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54962 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54963 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54964 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54965 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54966 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54967 +60 73 81 4 0 0
54968 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54969 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54970 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54971 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54972 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54973 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54974 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54975 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54976 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54977 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54978 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54979 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54980 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54981 +16 19 21 4 0 0
54982 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54983 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54984 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54985 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54986 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54987 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54988 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54989 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54990 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54991 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54992 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54993 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54994 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54995 +4 0 0 4 3 3
54996 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54997 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54998 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55000 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55001 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55002 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55003 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55004 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55005 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55006 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55007 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55008 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55009 +3 2 2 4 4 4
55010 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55011 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55012 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55013 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55014 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55015 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55016 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55017 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55018 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55019 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55020 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55021 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55022 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55023 +4 4 4 4 4 4
55024 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55025 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55026 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55027 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55028 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55029 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55030 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55031 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55032 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55033 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55034 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55035 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55036 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55037 +4 4 4 4 4 4
55038 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55039 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55040 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55041 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55042 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55043 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55044 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55045 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55046 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55047 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55048 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55049 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55050 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55051 +5 5 5 5 5 5
55052 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55053 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55054 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55055 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55056 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55057 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55058 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55059 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55060 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55061 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55062 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55063 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55064 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55065 +5 5 5 4 4 4
55066 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55067 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55068 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55069 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55070 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55071 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55072 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55073 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55074 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55075 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55076 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55077 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55079 +4 4 4 4 4 4
55080 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55081 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55082 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55083 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55084 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55085 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55086 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55087 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55088 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55089 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55090 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55091 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55093 +4 4 4 4 4 4
55094 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55095 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55096 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55097 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55098 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55099 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55100 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55101 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55102 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55103 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55104 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55107 +4 4 4 4 4 4
55108 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55109 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55110 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55111 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55112 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55113 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55114 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55115 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55116 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55117 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55118 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55121 +4 4 4 4 4 4
55122 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55123 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55124 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55125 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55126 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55127 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55128 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55129 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55130 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55131 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55132 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55135 +4 4 4 4 4 4
55136 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55137 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55138 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55139 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55140 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55141 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55142 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55143 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55144 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55145 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55146 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55149 +4 4 4 4 4 4
55150 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55151 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55152 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55153 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55154 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55155 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55156 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55157 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55158 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55159 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55160 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55163 +4 4 4 4 4 4
55164 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55165 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55166 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55167 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55168 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55169 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55170 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55171 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55172 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55173 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55174 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55177 +4 4 4 4 4 4
55178 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55179 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55180 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55181 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55182 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55183 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55184 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55185 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55186 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55187 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55188 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55191 +4 4 4 4 4 4
55192 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55193 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55194 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55195 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55196 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55197 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55198 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55199 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55200 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55201 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55202 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55205 +4 4 4 4 4 4
55206 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55207 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55208 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55209 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55210 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55211 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55212 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55213 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55214 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55215 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55216 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55219 +4 4 4 4 4 4
55220 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55221 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55222 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55223 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55224 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55225 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55226 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55227 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55228 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55229 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55230 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55233 +4 4 4 4 4 4
55234 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55235 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55236 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55237 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55238 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55239 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55240 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55241 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55242 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55243 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55244 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55247 +4 4 4 4 4 4
55248 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55249 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55250 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55251 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55252 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55253 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55254 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55255 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55256 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55257 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55258 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55261 +4 4 4 4 4 4
55262 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55263 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55264 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55265 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55266 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55267 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55268 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55269 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55270 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55271 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55272 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55275 +4 4 4 4 4 4
55276 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55277 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55278 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55279 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55280 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55281 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55282 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55283 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55284 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55285 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55286 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55289 +4 4 4 4 4 4
55290 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55291 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55292 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55293 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55294 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55295 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55296 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55297 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55298 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55299 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55300 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55303 +4 4 4 4 4 4
55304 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55305 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55306 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55307 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55308 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55309 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55310 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55311 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55312 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55313 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55314 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55317 +4 4 4 4 4 4
55318 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55319 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55320 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55321 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55322 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55323 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55324 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55325 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55326 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55327 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55328 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55331 +4 4 4 4 4 4
55332 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55333 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55334 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55335 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55336 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55337 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55338 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55339 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55340 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55341 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55342 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55345 +4 4 4 4 4 4
55346 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55347 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55348 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55349 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55350 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55351 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55352 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55353 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55354 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55355 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55356 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55359 +4 4 4 4 4 4
55360 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55361 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55362 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55363 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55364 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55365 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55366 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55367 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55368 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55369 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55370 +0 0 0 3 3 3 5 5 5 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 60 73 81 174 174 174 220 221 221 174 174 174
55375 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55376 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55377 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55378 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55379 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55380 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55381 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55382 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55383 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55384 +0 0 0 3 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 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55389 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55390 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55391 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55392 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55393 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55394 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55395 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55396 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55397 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55398 +0 0 0 3 3 3 5 5 5 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 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55403 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55404 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55405 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55406 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55407 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55408 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55409 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55410 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55411 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55412 +0 0 0 3 3 3 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 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55417 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55418 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55419 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55420 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55421 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55422 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55423 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55424 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55425 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55426 +0 0 0 3 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 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55431 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55432 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55433 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55434 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55435 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55436 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55437 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55438 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55439 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55440 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55441 +4 4 4 4 4 4 4 4 4 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 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55445 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55446 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55447 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55448 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55449 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55450 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55451 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55452 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55453 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55454 +4 3 3 5 5 5 4 4 4 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 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55459 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55460 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55461 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55462 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55463 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55464 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55465 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55466 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55467 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55468 +5 5 5 4 4 4 4 4 4 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 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55473 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55474 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55475 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55476 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55477 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55478 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55479 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55480 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55481 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55482 +4 4 4 4 4 4 4 4 4 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 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55487 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55488 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55489 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55490 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55491 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55492 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55493 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55494 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55495 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55496 +4 4 4 4 4 4 4 4 4 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 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55501 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55502 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55503 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55504 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55505 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55506 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55507 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55508 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55509 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55510 +4 4 4 4 4 4 4 4 4 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 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55515 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55516 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55517 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55518 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55519 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55520 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55521 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55522 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55523 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55524 +4 4 4 4 4 4 4 4 4 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 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55529 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55530 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55531 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55532 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55533 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55534 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55535 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55536 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55538 +4 4 4 4 4 4 4 4 4 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 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55543 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55544 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55545 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55546 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55547 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55548 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55549 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55550 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55552 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55557 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55558 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55559 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55560 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55561 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55562 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55563 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55564 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55566 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55571 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55572 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55573 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55574 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55575 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55576 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55577 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55580 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55585 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55586 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55587 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55588 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55589 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55590 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55591 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55594 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55599 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55600 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55601 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55602 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55603 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55604 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55605 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55608 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55613 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55614 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55615 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55616 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55617 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55618 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55619 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55622 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55627 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55628 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55629 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55630 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55631 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55632 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55633 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55636 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55642 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55643 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55644 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55645 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55646 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55647 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55650 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55657 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55658 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55659 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55660 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55664 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55671 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55672 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55673 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55674 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55678 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55685 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55686 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55687 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55688 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55692 +4 4 4 4 4 4 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55699 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55700 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55701 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55702 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55706 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55714 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55715 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55716 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55720 +4 4 4 4 4 4 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55728 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55729 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55730 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55734 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55742 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55743 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55744 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55748 +4 4 4 4 4 4 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55756 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55757 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55762 +4 4 4 4 4 4 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55770 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55771 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55776 +4 4 4 4 4 4 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 diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55781 index a01147f..5d896f8 100644
55782 --- a/drivers/video/matrox/matroxfb_DAC1064.c
55783 +++ b/drivers/video/matrox/matroxfb_DAC1064.c
55784 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55785
55786 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55787 struct matrox_switch matrox_mystique = {
55788 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55789 + .preinit = MGA1064_preinit,
55790 + .reset = MGA1064_reset,
55791 + .init = MGA1064_init,
55792 + .restore = MGA1064_restore,
55793 };
55794 EXPORT_SYMBOL(matrox_mystique);
55795 #endif
55796
55797 #ifdef CONFIG_FB_MATROX_G
55798 struct matrox_switch matrox_G100 = {
55799 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55800 + .preinit = MGAG100_preinit,
55801 + .reset = MGAG100_reset,
55802 + .init = MGAG100_init,
55803 + .restore = MGAG100_restore,
55804 };
55805 EXPORT_SYMBOL(matrox_G100);
55806 #endif
55807 diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55808 index 195ad7c..09743fc 100644
55809 --- a/drivers/video/matrox/matroxfb_Ti3026.c
55810 +++ b/drivers/video/matrox/matroxfb_Ti3026.c
55811 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55812 }
55813
55814 struct matrox_switch matrox_millennium = {
55815 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55816 + .preinit = Ti3026_preinit,
55817 + .reset = Ti3026_reset,
55818 + .init = Ti3026_init,
55819 + .restore = Ti3026_restore
55820 };
55821 EXPORT_SYMBOL(matrox_millennium);
55822 #endif
55823 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55824 index fe92eed..106e085 100644
55825 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
55826 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55827 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55828 struct mb862xxfb_par *par = info->par;
55829
55830 if (info->var.bits_per_pixel == 32) {
55831 - info->fbops->fb_fillrect = cfb_fillrect;
55832 - info->fbops->fb_copyarea = cfb_copyarea;
55833 - info->fbops->fb_imageblit = cfb_imageblit;
55834 + pax_open_kernel();
55835 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55836 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55837 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55838 + pax_close_kernel();
55839 } else {
55840 outreg(disp, GC_L0EM, 3);
55841 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55842 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55843 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55844 + pax_open_kernel();
55845 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55846 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55847 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55848 + pax_close_kernel();
55849 }
55850 outreg(draw, GDC_REG_DRAW_BASE, 0);
55851 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55852 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55853 index def0412..fed6529 100644
55854 --- a/drivers/video/nvidia/nvidia.c
55855 +++ b/drivers/video/nvidia/nvidia.c
55856 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55857 info->fix.line_length = (info->var.xres_virtual *
55858 info->var.bits_per_pixel) >> 3;
55859 if (info->var.accel_flags) {
55860 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55861 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55862 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55863 - info->fbops->fb_sync = nvidiafb_sync;
55864 + pax_open_kernel();
55865 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55866 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55867 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55868 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55869 + pax_close_kernel();
55870 info->pixmap.scan_align = 4;
55871 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55872 info->flags |= FBINFO_READS_FAST;
55873 NVResetGraphics(info);
55874 } else {
55875 - info->fbops->fb_imageblit = cfb_imageblit;
55876 - info->fbops->fb_fillrect = cfb_fillrect;
55877 - info->fbops->fb_copyarea = cfb_copyarea;
55878 - info->fbops->fb_sync = NULL;
55879 + pax_open_kernel();
55880 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55881 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55882 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55883 + *(void **)&info->fbops->fb_sync = NULL;
55884 + pax_close_kernel();
55885 info->pixmap.scan_align = 1;
55886 info->flags |= FBINFO_HWACCEL_DISABLED;
55887 info->flags &= ~FBINFO_READS_FAST;
55888 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55889 info->pixmap.size = 8 * 1024;
55890 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55891
55892 - if (!hwcur)
55893 - info->fbops->fb_cursor = NULL;
55894 + if (!hwcur) {
55895 + pax_open_kernel();
55896 + *(void **)&info->fbops->fb_cursor = NULL;
55897 + pax_close_kernel();
55898 + }
55899
55900 info->var.accel_flags = (!noaccel);
55901
55902 diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55903 index 669a81f..e216d76 100644
55904 --- a/drivers/video/omap2/dss/display.c
55905 +++ b/drivers/video/omap2/dss/display.c
55906 @@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55907 snprintf(dssdev->alias, sizeof(dssdev->alias),
55908 "display%d", disp_num_counter++);
55909
55910 + pax_open_kernel();
55911 if (drv && drv->get_resolution == NULL)
55912 - drv->get_resolution = omapdss_default_get_resolution;
55913 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55914 if (drv && drv->get_recommended_bpp == NULL)
55915 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55916 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55917 if (drv && drv->get_timings == NULL)
55918 - drv->get_timings = omapdss_default_get_timings;
55919 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55920 + pax_close_kernel();
55921
55922 mutex_lock(&panel_list_mutex);
55923 list_add_tail(&dssdev->panel_list, &panel_list);
55924 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55925 index 83433cb..71e9b98 100644
55926 --- a/drivers/video/s1d13xxxfb.c
55927 +++ b/drivers/video/s1d13xxxfb.c
55928 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55929
55930 switch(prod_id) {
55931 case S1D13506_PROD_ID: /* activate acceleration */
55932 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55933 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55934 + pax_open_kernel();
55935 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55936 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55937 + pax_close_kernel();
55938 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55939 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55940 break;
55941 diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
55942 index 2bcc84a..29dd1ea 100644
55943 --- a/drivers/video/sh_mobile_lcdcfb.c
55944 +++ b/drivers/video/sh_mobile_lcdcfb.c
55945 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55946 }
55947
55948 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55949 - lcdc_sys_write_index,
55950 - lcdc_sys_write_data,
55951 - lcdc_sys_read_data,
55952 + .write_index = lcdc_sys_write_index,
55953 + .write_data = lcdc_sys_write_data,
55954 + .read_data = lcdc_sys_read_data,
55955 };
55956
55957 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55958 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55959 index d513ed6..90b0de9 100644
55960 --- a/drivers/video/smscufx.c
55961 +++ b/drivers/video/smscufx.c
55962 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55963 fb_deferred_io_cleanup(info);
55964 kfree(info->fbdefio);
55965 info->fbdefio = NULL;
55966 - info->fbops->fb_mmap = ufx_ops_mmap;
55967 + pax_open_kernel();
55968 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55969 + pax_close_kernel();
55970 }
55971
55972 pr_debug("released /dev/fb%d user=%d count=%d",
55973 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55974 index 77b890e..458e666 100644
55975 --- a/drivers/video/udlfb.c
55976 +++ b/drivers/video/udlfb.c
55977 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55978 dlfb_urb_completion(urb);
55979
55980 error:
55981 - atomic_add(bytes_sent, &dev->bytes_sent);
55982 - atomic_add(bytes_identical, &dev->bytes_identical);
55983 - atomic_add(width*height*2, &dev->bytes_rendered);
55984 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55985 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55986 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55987 end_cycles = get_cycles();
55988 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55989 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55990 >> 10)), /* Kcycles */
55991 &dev->cpu_kcycles_used);
55992
55993 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55994 dlfb_urb_completion(urb);
55995
55996 error:
55997 - atomic_add(bytes_sent, &dev->bytes_sent);
55998 - atomic_add(bytes_identical, &dev->bytes_identical);
55999 - atomic_add(bytes_rendered, &dev->bytes_rendered);
56000 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
56001 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
56002 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
56003 end_cycles = get_cycles();
56004 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
56005 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
56006 >> 10)), /* Kcycles */
56007 &dev->cpu_kcycles_used);
56008 }
56009 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
56010 fb_deferred_io_cleanup(info);
56011 kfree(info->fbdefio);
56012 info->fbdefio = NULL;
56013 - info->fbops->fb_mmap = dlfb_ops_mmap;
56014 + pax_open_kernel();
56015 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
56016 + pax_close_kernel();
56017 }
56018
56019 pr_warn("released /dev/fb%d user=%d count=%d\n",
56020 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
56021 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56022 struct dlfb_data *dev = fb_info->par;
56023 return snprintf(buf, PAGE_SIZE, "%u\n",
56024 - atomic_read(&dev->bytes_rendered));
56025 + atomic_read_unchecked(&dev->bytes_rendered));
56026 }
56027
56028 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56029 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
56030 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56031 struct dlfb_data *dev = fb_info->par;
56032 return snprintf(buf, PAGE_SIZE, "%u\n",
56033 - atomic_read(&dev->bytes_identical));
56034 + atomic_read_unchecked(&dev->bytes_identical));
56035 }
56036
56037 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56038 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
56039 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56040 struct dlfb_data *dev = fb_info->par;
56041 return snprintf(buf, PAGE_SIZE, "%u\n",
56042 - atomic_read(&dev->bytes_sent));
56043 + atomic_read_unchecked(&dev->bytes_sent));
56044 }
56045
56046 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56047 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
56048 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56049 struct dlfb_data *dev = fb_info->par;
56050 return snprintf(buf, PAGE_SIZE, "%u\n",
56051 - atomic_read(&dev->cpu_kcycles_used));
56052 + atomic_read_unchecked(&dev->cpu_kcycles_used));
56053 }
56054
56055 static ssize_t edid_show(
56056 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
56057 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56058 struct dlfb_data *dev = fb_info->par;
56059
56060 - atomic_set(&dev->bytes_rendered, 0);
56061 - atomic_set(&dev->bytes_identical, 0);
56062 - atomic_set(&dev->bytes_sent, 0);
56063 - atomic_set(&dev->cpu_kcycles_used, 0);
56064 + atomic_set_unchecked(&dev->bytes_rendered, 0);
56065 + atomic_set_unchecked(&dev->bytes_identical, 0);
56066 + atomic_set_unchecked(&dev->bytes_sent, 0);
56067 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
56068
56069 return count;
56070 }
56071 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
56072 index 256fba7..6e75516 100644
56073 --- a/drivers/video/uvesafb.c
56074 +++ b/drivers/video/uvesafb.c
56075 @@ -19,6 +19,7 @@
56076 #include <linux/io.h>
56077 #include <linux/mutex.h>
56078 #include <linux/slab.h>
56079 +#include <linux/moduleloader.h>
56080 #include <video/edid.h>
56081 #include <video/uvesafb.h>
56082 #ifdef CONFIG_X86
56083 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
56084 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
56085 par->pmi_setpal = par->ypan = 0;
56086 } else {
56087 +
56088 +#ifdef CONFIG_PAX_KERNEXEC
56089 +#ifdef CONFIG_MODULES
56090 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
56091 +#endif
56092 + if (!par->pmi_code) {
56093 + par->pmi_setpal = par->ypan = 0;
56094 + return 0;
56095 + }
56096 +#endif
56097 +
56098 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
56099 + task->t.regs.edi);
56100 +
56101 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56102 + pax_open_kernel();
56103 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
56104 + pax_close_kernel();
56105 +
56106 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
56107 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
56108 +#else
56109 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
56110 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
56111 +#endif
56112 +
56113 printk(KERN_INFO "uvesafb: protected mode interface info at "
56114 "%04x:%04x\n",
56115 (u16)task->t.regs.es, (u16)task->t.regs.edi);
56116 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
56117 par->ypan = ypan;
56118
56119 if (par->pmi_setpal || par->ypan) {
56120 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
56121 if (__supported_pte_mask & _PAGE_NX) {
56122 par->pmi_setpal = par->ypan = 0;
56123 printk(KERN_WARNING "uvesafb: NX protection is active, "
56124 "better not use the PMI.\n");
56125 - } else {
56126 + } else
56127 +#endif
56128 uvesafb_vbe_getpmi(task, par);
56129 - }
56130 }
56131 #else
56132 /* The protected mode interface is not available on non-x86. */
56133 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56134 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
56135
56136 /* Disable blanking if the user requested so. */
56137 - if (!blank)
56138 - info->fbops->fb_blank = NULL;
56139 + if (!blank) {
56140 + pax_open_kernel();
56141 + *(void **)&info->fbops->fb_blank = NULL;
56142 + pax_close_kernel();
56143 + }
56144
56145 /*
56146 * Find out how much IO memory is required for the mode with
56147 @@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56148 info->flags = FBINFO_FLAG_DEFAULT |
56149 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
56150
56151 - if (!par->ypan)
56152 - info->fbops->fb_pan_display = NULL;
56153 + if (!par->ypan) {
56154 + pax_open_kernel();
56155 + *(void **)&info->fbops->fb_pan_display = NULL;
56156 + pax_close_kernel();
56157 + }
56158 }
56159
56160 static void uvesafb_init_mtrr(struct fb_info *info)
56161 @@ -1792,6 +1822,11 @@ out_mode:
56162 out:
56163 kfree(par->vbe_modes);
56164
56165 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56166 + if (par->pmi_code)
56167 + module_free_exec(NULL, par->pmi_code);
56168 +#endif
56169 +
56170 framebuffer_release(info);
56171 return err;
56172 }
56173 @@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
56174 kfree(par->vbe_modes);
56175 kfree(par->vbe_state_orig);
56176 kfree(par->vbe_state_saved);
56177 +
56178 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56179 + if (par->pmi_code)
56180 + module_free_exec(NULL, par->pmi_code);
56181 +#endif
56182 +
56183 }
56184
56185 framebuffer_release(info);
56186 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
56187 index 1c7da3b..56ea0bd 100644
56188 --- a/drivers/video/vesafb.c
56189 +++ b/drivers/video/vesafb.c
56190 @@ -9,6 +9,7 @@
56191 */
56192
56193 #include <linux/module.h>
56194 +#include <linux/moduleloader.h>
56195 #include <linux/kernel.h>
56196 #include <linux/errno.h>
56197 #include <linux/string.h>
56198 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
56199 static int vram_total; /* Set total amount of memory */
56200 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
56201 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56202 -static void (*pmi_start)(void) __read_mostly;
56203 -static void (*pmi_pal) (void) __read_mostly;
56204 +static void (*pmi_start)(void) __read_only;
56205 +static void (*pmi_pal) (void) __read_only;
56206 static int depth __read_mostly;
56207 static int vga_compat __read_mostly;
56208 /* --------------------------------------------------------------------- */
56209 @@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
56210 unsigned int size_remap;
56211 unsigned int size_total;
56212 char *option = NULL;
56213 + void *pmi_code = NULL;
56214
56215 /* ignore error return of fb_get_options */
56216 fb_get_options("vesafb", &option);
56217 @@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
56218 size_remap = size_total;
56219 vesafb_fix.smem_len = size_remap;
56220
56221 -#ifndef __i386__
56222 - screen_info.vesapm_seg = 0;
56223 -#endif
56224 -
56225 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
56226 printk(KERN_WARNING
56227 "vesafb: cannot reserve video memory at 0x%lx\n",
56228 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
56229 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
56230 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
56231
56232 +#ifdef __i386__
56233 +
56234 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56235 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
56236 + if (!pmi_code)
56237 +#elif !defined(CONFIG_PAX_KERNEXEC)
56238 + if (0)
56239 +#endif
56240 +
56241 +#endif
56242 + screen_info.vesapm_seg = 0;
56243 +
56244 if (screen_info.vesapm_seg) {
56245 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
56246 - screen_info.vesapm_seg,screen_info.vesapm_off);
56247 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
56248 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
56249 }
56250
56251 if (screen_info.vesapm_seg < 0xc000)
56252 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
56253
56254 if (ypan || pmi_setpal) {
56255 unsigned short *pmi_base;
56256 +
56257 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
56258 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
56259 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
56260 +
56261 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56262 + pax_open_kernel();
56263 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
56264 +#else
56265 + pmi_code = pmi_base;
56266 +#endif
56267 +
56268 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
56269 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
56270 +
56271 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56272 + pmi_start = ktva_ktla(pmi_start);
56273 + pmi_pal = ktva_ktla(pmi_pal);
56274 + pax_close_kernel();
56275 +#endif
56276 +
56277 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
56278 if (pmi_base[3]) {
56279 printk(KERN_INFO "vesafb: pmi: ports = ");
56280 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
56281 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
56282 (ypan ? FBINFO_HWACCEL_YPAN : 0);
56283
56284 - if (!ypan)
56285 - info->fbops->fb_pan_display = NULL;
56286 + if (!ypan) {
56287 + pax_open_kernel();
56288 + *(void **)&info->fbops->fb_pan_display = NULL;
56289 + pax_close_kernel();
56290 + }
56291
56292 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
56293 err = -ENOMEM;
56294 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
56295 fb_info(info, "%s frame buffer device\n", info->fix.id);
56296 return 0;
56297 err:
56298 +
56299 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56300 + module_free_exec(NULL, pmi_code);
56301 +#endif
56302 +
56303 if (info->screen_base)
56304 iounmap(info->screen_base);
56305 framebuffer_release(info);
56306 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
56307 index 88714ae..16c2e11 100644
56308 --- a/drivers/video/via/via_clock.h
56309 +++ b/drivers/video/via/via_clock.h
56310 @@ -56,7 +56,7 @@ struct via_clock {
56311
56312 void (*set_engine_pll_state)(u8 state);
56313 void (*set_engine_pll)(struct via_pll_config config);
56314 -};
56315 +} __no_const;
56316
56317
56318 static inline u32 get_pll_internal_frequency(u32 ref_freq,
56319 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56320 index fef20db..d28b1ab 100644
56321 --- a/drivers/xen/xenfs/xenstored.c
56322 +++ b/drivers/xen/xenfs/xenstored.c
56323 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56324 static int xsd_kva_open(struct inode *inode, struct file *file)
56325 {
56326 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56327 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56328 + NULL);
56329 +#else
56330 xen_store_interface);
56331 +#endif
56332 +
56333 if (!file->private_data)
56334 return -ENOMEM;
56335 return 0;
56336 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56337 index c71e886..61d3d44b 100644
56338 --- a/fs/9p/vfs_addr.c
56339 +++ b/fs/9p/vfs_addr.c
56340 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56341
56342 retval = v9fs_file_write_internal(inode,
56343 v9inode->writeback_fid,
56344 - (__force const char __user *)buffer,
56345 + (const char __force_user *)buffer,
56346 len, &offset, 0);
56347 if (retval > 0)
56348 retval = 0;
56349 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56350 index bb7991c..481e21a 100644
56351 --- a/fs/9p/vfs_inode.c
56352 +++ b/fs/9p/vfs_inode.c
56353 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56354 void
56355 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56356 {
56357 - char *s = nd_get_link(nd);
56358 + const char *s = nd_get_link(nd);
56359
56360 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56361 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56362 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56363 index 370b24c..ff0be7b 100644
56364 --- a/fs/Kconfig.binfmt
56365 +++ b/fs/Kconfig.binfmt
56366 @@ -103,7 +103,7 @@ config HAVE_AOUT
56367
56368 config BINFMT_AOUT
56369 tristate "Kernel support for a.out and ECOFF binaries"
56370 - depends on HAVE_AOUT
56371 + depends on HAVE_AOUT && BROKEN
56372 ---help---
56373 A.out (Assembler.OUTput) is a set of formats for libraries and
56374 executables used in the earliest versions of UNIX. Linux used
56375 diff --git a/fs/affs/super.c b/fs/affs/super.c
56376 index d098731..9a5b19d 100644
56377 --- a/fs/affs/super.c
56378 +++ b/fs/affs/super.c
56379 @@ -336,8 +336,6 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
56380 &blocksize,&sbi->s_prefix,
56381 sbi->s_volume, &mount_flags)) {
56382 printk(KERN_ERR "AFFS: Error parsing options\n");
56383 - kfree(sbi->s_prefix);
56384 - kfree(sbi);
56385 return -EINVAL;
56386 }
56387 /* N.B. after this point s_prefix must be released */
56388 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56389 index ce25d75..dc09eeb 100644
56390 --- a/fs/afs/inode.c
56391 +++ b/fs/afs/inode.c
56392 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56393 struct afs_vnode *vnode;
56394 struct super_block *sb;
56395 struct inode *inode;
56396 - static atomic_t afs_autocell_ino;
56397 + static atomic_unchecked_t afs_autocell_ino;
56398
56399 _enter("{%x:%u},%*.*s,",
56400 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56401 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56402 data.fid.unique = 0;
56403 data.fid.vnode = 0;
56404
56405 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56406 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56407 afs_iget5_autocell_test, afs_iget5_set,
56408 &data);
56409 if (!inode) {
56410 diff --git a/fs/aio.c b/fs/aio.c
56411 index 12a3de0e..25949c1 100644
56412 --- a/fs/aio.c
56413 +++ b/fs/aio.c
56414 @@ -375,7 +375,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56415 size += sizeof(struct io_event) * nr_events;
56416
56417 nr_pages = PFN_UP(size);
56418 - if (nr_pages < 0)
56419 + if (nr_pages <= 0)
56420 return -EINVAL;
56421
56422 file = aio_private_file(ctx, nr_pages);
56423 @@ -1299,10 +1299,8 @@ rw_common:
56424 &iovec, compat)
56425 : aio_setup_single_vector(req, rw, buf, &nr_segs,
56426 iovec);
56427 - if (ret)
56428 - return ret;
56429 -
56430 - ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56431 + if (!ret)
56432 + ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56433 if (ret < 0) {
56434 if (iovec != &inline_vec)
56435 kfree(iovec);
56436 diff --git a/fs/attr.c b/fs/attr.c
56437 index 5d4e59d..fd02418 100644
56438 --- a/fs/attr.c
56439 +++ b/fs/attr.c
56440 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56441 unsigned long limit;
56442
56443 limit = rlimit(RLIMIT_FSIZE);
56444 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56445 if (limit != RLIM_INFINITY && offset > limit)
56446 goto out_sig;
56447 if (offset > inode->i_sb->s_maxbytes)
56448 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56449 index 116fd38..c04182da 100644
56450 --- a/fs/autofs4/waitq.c
56451 +++ b/fs/autofs4/waitq.c
56452 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56453 {
56454 unsigned long sigpipe, flags;
56455 mm_segment_t fs;
56456 - const char *data = (const char *)addr;
56457 + const char __user *data = (const char __force_user *)addr;
56458 ssize_t wr = 0;
56459
56460 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56461 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56462 return 1;
56463 }
56464
56465 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56466 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56467 +#endif
56468 +
56469 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56470 enum autofs_notify notify)
56471 {
56472 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56473
56474 /* If this is a direct mount request create a dummy name */
56475 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56476 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56477 + /* this name does get written to userland via autofs4_write() */
56478 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56479 +#else
56480 qstr.len = sprintf(name, "%p", dentry);
56481 +#endif
56482 else {
56483 qstr.len = autofs4_getpath(sbi, dentry, &name);
56484 if (!qstr.len) {
56485 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56486 index 2722387..56059b5 100644
56487 --- a/fs/befs/endian.h
56488 +++ b/fs/befs/endian.h
56489 @@ -11,7 +11,7 @@
56490
56491 #include <asm/byteorder.h>
56492
56493 -static inline u64
56494 +static inline u64 __intentional_overflow(-1)
56495 fs64_to_cpu(const struct super_block *sb, fs64 n)
56496 {
56497 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56498 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56499 return (__force fs64)cpu_to_be64(n);
56500 }
56501
56502 -static inline u32
56503 +static inline u32 __intentional_overflow(-1)
56504 fs32_to_cpu(const struct super_block *sb, fs32 n)
56505 {
56506 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56507 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56508 return (__force fs32)cpu_to_be32(n);
56509 }
56510
56511 -static inline u16
56512 +static inline u16 __intentional_overflow(-1)
56513 fs16_to_cpu(const struct super_block *sb, fs16 n)
56514 {
56515 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56516 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56517 index ca0ba15..0fa3257 100644
56518 --- a/fs/binfmt_aout.c
56519 +++ b/fs/binfmt_aout.c
56520 @@ -16,6 +16,7 @@
56521 #include <linux/string.h>
56522 #include <linux/fs.h>
56523 #include <linux/file.h>
56524 +#include <linux/security.h>
56525 #include <linux/stat.h>
56526 #include <linux/fcntl.h>
56527 #include <linux/ptrace.h>
56528 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56529 #endif
56530 # define START_STACK(u) ((void __user *)u.start_stack)
56531
56532 + memset(&dump, 0, sizeof(dump));
56533 +
56534 fs = get_fs();
56535 set_fs(KERNEL_DS);
56536 has_dumped = 1;
56537 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56538
56539 /* If the size of the dump file exceeds the rlimit, then see what would happen
56540 if we wrote the stack, but not the data area. */
56541 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56542 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56543 dump.u_dsize = 0;
56544
56545 /* Make sure we have enough room to write the stack and data areas. */
56546 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56547 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56548 dump.u_ssize = 0;
56549
56550 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56551 rlim = rlimit(RLIMIT_DATA);
56552 if (rlim >= RLIM_INFINITY)
56553 rlim = ~0;
56554 +
56555 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56556 if (ex.a_data + ex.a_bss > rlim)
56557 return -ENOMEM;
56558
56559 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56560
56561 install_exec_creds(bprm);
56562
56563 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56564 + current->mm->pax_flags = 0UL;
56565 +#endif
56566 +
56567 +#ifdef CONFIG_PAX_PAGEEXEC
56568 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56569 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56570 +
56571 +#ifdef CONFIG_PAX_EMUTRAMP
56572 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56573 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56574 +#endif
56575 +
56576 +#ifdef CONFIG_PAX_MPROTECT
56577 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56578 + current->mm->pax_flags |= MF_PAX_MPROTECT;
56579 +#endif
56580 +
56581 + }
56582 +#endif
56583 +
56584 if (N_MAGIC(ex) == OMAGIC) {
56585 unsigned long text_addr, map_size;
56586 loff_t pos;
56587 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56588 }
56589
56590 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56591 - PROT_READ | PROT_WRITE | PROT_EXEC,
56592 + PROT_READ | PROT_WRITE,
56593 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56594 fd_offset + ex.a_text);
56595 if (error != N_DATADDR(ex)) {
56596 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56597 index 67be295..83e2f86 100644
56598 --- a/fs/binfmt_elf.c
56599 +++ b/fs/binfmt_elf.c
56600 @@ -34,6 +34,7 @@
56601 #include <linux/utsname.h>
56602 #include <linux/coredump.h>
56603 #include <linux/sched.h>
56604 +#include <linux/xattr.h>
56605 #include <asm/uaccess.h>
56606 #include <asm/param.h>
56607 #include <asm/page.h>
56608 @@ -48,7 +49,7 @@
56609 static int load_elf_binary(struct linux_binprm *bprm);
56610 static int load_elf_library(struct file *);
56611 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56612 - int, int, unsigned long);
56613 + int, int, unsigned long) __intentional_overflow(-1);
56614
56615 /*
56616 * If we don't support core dumping, then supply a NULL so we
56617 @@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56618 #define elf_core_dump NULL
56619 #endif
56620
56621 +#ifdef CONFIG_PAX_MPROTECT
56622 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56623 +#endif
56624 +
56625 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56626 +static void elf_handle_mmap(struct file *file);
56627 +#endif
56628 +
56629 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56630 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56631 #else
56632 @@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56633 .load_binary = load_elf_binary,
56634 .load_shlib = load_elf_library,
56635 .core_dump = elf_core_dump,
56636 +
56637 +#ifdef CONFIG_PAX_MPROTECT
56638 + .handle_mprotect= elf_handle_mprotect,
56639 +#endif
56640 +
56641 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56642 + .handle_mmap = elf_handle_mmap,
56643 +#endif
56644 +
56645 .min_coredump = ELF_EXEC_PAGESIZE,
56646 };
56647
56648 @@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56649
56650 static int set_brk(unsigned long start, unsigned long end)
56651 {
56652 + unsigned long e = end;
56653 +
56654 start = ELF_PAGEALIGN(start);
56655 end = ELF_PAGEALIGN(end);
56656 if (end > start) {
56657 @@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56658 if (BAD_ADDR(addr))
56659 return addr;
56660 }
56661 - current->mm->start_brk = current->mm->brk = end;
56662 + current->mm->start_brk = current->mm->brk = e;
56663 return 0;
56664 }
56665
56666 @@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56667 elf_addr_t __user *u_rand_bytes;
56668 const char *k_platform = ELF_PLATFORM;
56669 const char *k_base_platform = ELF_BASE_PLATFORM;
56670 - unsigned char k_rand_bytes[16];
56671 + u32 k_rand_bytes[4];
56672 int items;
56673 elf_addr_t *elf_info;
56674 int ei_index = 0;
56675 const struct cred *cred = current_cred();
56676 struct vm_area_struct *vma;
56677 + unsigned long saved_auxv[AT_VECTOR_SIZE];
56678
56679 /*
56680 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56681 @@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56682 * Generate 16 random bytes for userspace PRNG seeding.
56683 */
56684 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56685 - u_rand_bytes = (elf_addr_t __user *)
56686 - STACK_ALLOC(p, sizeof(k_rand_bytes));
56687 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56688 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56689 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56690 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56691 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
56692 + u_rand_bytes = (elf_addr_t __user *) p;
56693 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56694 return -EFAULT;
56695
56696 @@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56697 return -EFAULT;
56698 current->mm->env_end = p;
56699
56700 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56701 +
56702 /* Put the elf_info on the stack in the right place. */
56703 sp = (elf_addr_t __user *)envp + 1;
56704 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56705 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56706 return -EFAULT;
56707 return 0;
56708 }
56709 @@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56710 an ELF header */
56711
56712 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56713 - struct file *interpreter, unsigned long *interp_map_addr,
56714 - unsigned long no_base)
56715 + struct file *interpreter, unsigned long no_base)
56716 {
56717 struct elf_phdr *elf_phdata;
56718 struct elf_phdr *eppnt;
56719 - unsigned long load_addr = 0;
56720 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56721 int load_addr_set = 0;
56722 unsigned long last_bss = 0, elf_bss = 0;
56723 - unsigned long error = ~0UL;
56724 + unsigned long error = -EINVAL;
56725 unsigned long total_size;
56726 int retval, i, size;
56727
56728 @@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56729 goto out_close;
56730 }
56731
56732 +#ifdef CONFIG_PAX_SEGMEXEC
56733 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56734 + pax_task_size = SEGMEXEC_TASK_SIZE;
56735 +#endif
56736 +
56737 eppnt = elf_phdata;
56738 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56739 if (eppnt->p_type == PT_LOAD) {
56740 @@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56741 map_addr = elf_map(interpreter, load_addr + vaddr,
56742 eppnt, elf_prot, elf_type, total_size);
56743 total_size = 0;
56744 - if (!*interp_map_addr)
56745 - *interp_map_addr = map_addr;
56746 error = map_addr;
56747 if (BAD_ADDR(map_addr))
56748 goto out_close;
56749 @@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56750 k = load_addr + eppnt->p_vaddr;
56751 if (BAD_ADDR(k) ||
56752 eppnt->p_filesz > eppnt->p_memsz ||
56753 - eppnt->p_memsz > TASK_SIZE ||
56754 - TASK_SIZE - eppnt->p_memsz < k) {
56755 + eppnt->p_memsz > pax_task_size ||
56756 + pax_task_size - eppnt->p_memsz < k) {
56757 error = -ENOMEM;
56758 goto out_close;
56759 }
56760 @@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56761 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56762
56763 /* Map the last of the bss segment */
56764 - error = vm_brk(elf_bss, last_bss - elf_bss);
56765 - if (BAD_ADDR(error))
56766 - goto out_close;
56767 + if (last_bss > elf_bss) {
56768 + error = vm_brk(elf_bss, last_bss - elf_bss);
56769 + if (BAD_ADDR(error))
56770 + goto out_close;
56771 + }
56772 }
56773
56774 error = load_addr;
56775 @@ -538,6 +569,336 @@ out:
56776 return error;
56777 }
56778
56779 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56780 +#ifdef CONFIG_PAX_SOFTMODE
56781 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56782 +{
56783 + unsigned long pax_flags = 0UL;
56784 +
56785 +#ifdef CONFIG_PAX_PAGEEXEC
56786 + if (elf_phdata->p_flags & PF_PAGEEXEC)
56787 + pax_flags |= MF_PAX_PAGEEXEC;
56788 +#endif
56789 +
56790 +#ifdef CONFIG_PAX_SEGMEXEC
56791 + if (elf_phdata->p_flags & PF_SEGMEXEC)
56792 + pax_flags |= MF_PAX_SEGMEXEC;
56793 +#endif
56794 +
56795 +#ifdef CONFIG_PAX_EMUTRAMP
56796 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56797 + pax_flags |= MF_PAX_EMUTRAMP;
56798 +#endif
56799 +
56800 +#ifdef CONFIG_PAX_MPROTECT
56801 + if (elf_phdata->p_flags & PF_MPROTECT)
56802 + pax_flags |= MF_PAX_MPROTECT;
56803 +#endif
56804 +
56805 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56806 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56807 + pax_flags |= MF_PAX_RANDMMAP;
56808 +#endif
56809 +
56810 + return pax_flags;
56811 +}
56812 +#endif
56813 +
56814 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56815 +{
56816 + unsigned long pax_flags = 0UL;
56817 +
56818 +#ifdef CONFIG_PAX_PAGEEXEC
56819 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56820 + pax_flags |= MF_PAX_PAGEEXEC;
56821 +#endif
56822 +
56823 +#ifdef CONFIG_PAX_SEGMEXEC
56824 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56825 + pax_flags |= MF_PAX_SEGMEXEC;
56826 +#endif
56827 +
56828 +#ifdef CONFIG_PAX_EMUTRAMP
56829 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56830 + pax_flags |= MF_PAX_EMUTRAMP;
56831 +#endif
56832 +
56833 +#ifdef CONFIG_PAX_MPROTECT
56834 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56835 + pax_flags |= MF_PAX_MPROTECT;
56836 +#endif
56837 +
56838 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56839 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56840 + pax_flags |= MF_PAX_RANDMMAP;
56841 +#endif
56842 +
56843 + return pax_flags;
56844 +}
56845 +#endif
56846 +
56847 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56848 +#ifdef CONFIG_PAX_SOFTMODE
56849 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56850 +{
56851 + unsigned long pax_flags = 0UL;
56852 +
56853 +#ifdef CONFIG_PAX_PAGEEXEC
56854 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56855 + pax_flags |= MF_PAX_PAGEEXEC;
56856 +#endif
56857 +
56858 +#ifdef CONFIG_PAX_SEGMEXEC
56859 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56860 + pax_flags |= MF_PAX_SEGMEXEC;
56861 +#endif
56862 +
56863 +#ifdef CONFIG_PAX_EMUTRAMP
56864 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56865 + pax_flags |= MF_PAX_EMUTRAMP;
56866 +#endif
56867 +
56868 +#ifdef CONFIG_PAX_MPROTECT
56869 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56870 + pax_flags |= MF_PAX_MPROTECT;
56871 +#endif
56872 +
56873 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56874 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56875 + pax_flags |= MF_PAX_RANDMMAP;
56876 +#endif
56877 +
56878 + return pax_flags;
56879 +}
56880 +#endif
56881 +
56882 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56883 +{
56884 + unsigned long pax_flags = 0UL;
56885 +
56886 +#ifdef CONFIG_PAX_PAGEEXEC
56887 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56888 + pax_flags |= MF_PAX_PAGEEXEC;
56889 +#endif
56890 +
56891 +#ifdef CONFIG_PAX_SEGMEXEC
56892 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56893 + pax_flags |= MF_PAX_SEGMEXEC;
56894 +#endif
56895 +
56896 +#ifdef CONFIG_PAX_EMUTRAMP
56897 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56898 + pax_flags |= MF_PAX_EMUTRAMP;
56899 +#endif
56900 +
56901 +#ifdef CONFIG_PAX_MPROTECT
56902 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56903 + pax_flags |= MF_PAX_MPROTECT;
56904 +#endif
56905 +
56906 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56907 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56908 + pax_flags |= MF_PAX_RANDMMAP;
56909 +#endif
56910 +
56911 + return pax_flags;
56912 +}
56913 +#endif
56914 +
56915 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56916 +static unsigned long pax_parse_defaults(void)
56917 +{
56918 + unsigned long pax_flags = 0UL;
56919 +
56920 +#ifdef CONFIG_PAX_SOFTMODE
56921 + if (pax_softmode)
56922 + return pax_flags;
56923 +#endif
56924 +
56925 +#ifdef CONFIG_PAX_PAGEEXEC
56926 + pax_flags |= MF_PAX_PAGEEXEC;
56927 +#endif
56928 +
56929 +#ifdef CONFIG_PAX_SEGMEXEC
56930 + pax_flags |= MF_PAX_SEGMEXEC;
56931 +#endif
56932 +
56933 +#ifdef CONFIG_PAX_MPROTECT
56934 + pax_flags |= MF_PAX_MPROTECT;
56935 +#endif
56936 +
56937 +#ifdef CONFIG_PAX_RANDMMAP
56938 + if (randomize_va_space)
56939 + pax_flags |= MF_PAX_RANDMMAP;
56940 +#endif
56941 +
56942 + return pax_flags;
56943 +}
56944 +
56945 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56946 +{
56947 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56948 +
56949 +#ifdef CONFIG_PAX_EI_PAX
56950 +
56951 +#ifdef CONFIG_PAX_SOFTMODE
56952 + if (pax_softmode)
56953 + return pax_flags;
56954 +#endif
56955 +
56956 + pax_flags = 0UL;
56957 +
56958 +#ifdef CONFIG_PAX_PAGEEXEC
56959 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56960 + pax_flags |= MF_PAX_PAGEEXEC;
56961 +#endif
56962 +
56963 +#ifdef CONFIG_PAX_SEGMEXEC
56964 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56965 + pax_flags |= MF_PAX_SEGMEXEC;
56966 +#endif
56967 +
56968 +#ifdef CONFIG_PAX_EMUTRAMP
56969 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56970 + pax_flags |= MF_PAX_EMUTRAMP;
56971 +#endif
56972 +
56973 +#ifdef CONFIG_PAX_MPROTECT
56974 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56975 + pax_flags |= MF_PAX_MPROTECT;
56976 +#endif
56977 +
56978 +#ifdef CONFIG_PAX_ASLR
56979 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56980 + pax_flags |= MF_PAX_RANDMMAP;
56981 +#endif
56982 +
56983 +#endif
56984 +
56985 + return pax_flags;
56986 +
56987 +}
56988 +
56989 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56990 +{
56991 +
56992 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56993 + unsigned long i;
56994 +
56995 + for (i = 0UL; i < elf_ex->e_phnum; i++)
56996 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56997 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56998 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56999 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
57000 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
57001 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
57002 + return PAX_PARSE_FLAGS_FALLBACK;
57003 +
57004 +#ifdef CONFIG_PAX_SOFTMODE
57005 + if (pax_softmode)
57006 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
57007 + else
57008 +#endif
57009 +
57010 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
57011 + break;
57012 + }
57013 +#endif
57014 +
57015 + return PAX_PARSE_FLAGS_FALLBACK;
57016 +}
57017 +
57018 +static unsigned long pax_parse_xattr_pax(struct file * const file)
57019 +{
57020 +
57021 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
57022 + ssize_t xattr_size, i;
57023 + unsigned char xattr_value[sizeof("pemrs") - 1];
57024 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
57025 +
57026 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
57027 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
57028 + return PAX_PARSE_FLAGS_FALLBACK;
57029 +
57030 + for (i = 0; i < xattr_size; i++)
57031 + switch (xattr_value[i]) {
57032 + default:
57033 + return PAX_PARSE_FLAGS_FALLBACK;
57034 +
57035 +#define parse_flag(option1, option2, flag) \
57036 + case option1: \
57037 + if (pax_flags_hardmode & MF_PAX_##flag) \
57038 + return PAX_PARSE_FLAGS_FALLBACK;\
57039 + pax_flags_hardmode |= MF_PAX_##flag; \
57040 + break; \
57041 + case option2: \
57042 + if (pax_flags_softmode & MF_PAX_##flag) \
57043 + return PAX_PARSE_FLAGS_FALLBACK;\
57044 + pax_flags_softmode |= MF_PAX_##flag; \
57045 + break;
57046 +
57047 + parse_flag('p', 'P', PAGEEXEC);
57048 + parse_flag('e', 'E', EMUTRAMP);
57049 + parse_flag('m', 'M', MPROTECT);
57050 + parse_flag('r', 'R', RANDMMAP);
57051 + parse_flag('s', 'S', SEGMEXEC);
57052 +
57053 +#undef parse_flag
57054 + }
57055 +
57056 + if (pax_flags_hardmode & pax_flags_softmode)
57057 + return PAX_PARSE_FLAGS_FALLBACK;
57058 +
57059 +#ifdef CONFIG_PAX_SOFTMODE
57060 + if (pax_softmode)
57061 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
57062 + else
57063 +#endif
57064 +
57065 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
57066 +#else
57067 + return PAX_PARSE_FLAGS_FALLBACK;
57068 +#endif
57069 +
57070 +}
57071 +
57072 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
57073 +{
57074 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
57075 +
57076 + pax_flags = pax_parse_defaults();
57077 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
57078 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
57079 + xattr_pax_flags = pax_parse_xattr_pax(file);
57080 +
57081 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57082 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57083 + pt_pax_flags != xattr_pax_flags)
57084 + return -EINVAL;
57085 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57086 + pax_flags = xattr_pax_flags;
57087 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57088 + pax_flags = pt_pax_flags;
57089 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57090 + pax_flags = ei_pax_flags;
57091 +
57092 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
57093 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57094 + if ((__supported_pte_mask & _PAGE_NX))
57095 + pax_flags &= ~MF_PAX_SEGMEXEC;
57096 + else
57097 + pax_flags &= ~MF_PAX_PAGEEXEC;
57098 + }
57099 +#endif
57100 +
57101 + if (0 > pax_check_flags(&pax_flags))
57102 + return -EINVAL;
57103 +
57104 + current->mm->pax_flags = pax_flags;
57105 + return 0;
57106 +}
57107 +#endif
57108 +
57109 /*
57110 * These are the functions used to load ELF style executables and shared
57111 * libraries. There is no binary dependent code anywhere else.
57112 @@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
57113 {
57114 unsigned int random_variable = 0;
57115
57116 +#ifdef CONFIG_PAX_RANDUSTACK
57117 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
57118 + return stack_top - current->mm->delta_stack;
57119 +#endif
57120 +
57121 if ((current->flags & PF_RANDOMIZE) &&
57122 !(current->personality & ADDR_NO_RANDOMIZE)) {
57123 random_variable = get_random_int() & STACK_RND_MASK;
57124 @@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57125 unsigned long load_addr = 0, load_bias = 0;
57126 int load_addr_set = 0;
57127 char * elf_interpreter = NULL;
57128 - unsigned long error;
57129 + unsigned long error = 0;
57130 struct elf_phdr *elf_ppnt, *elf_phdata;
57131 unsigned long elf_bss, elf_brk;
57132 int retval, i;
57133 @@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
57134 unsigned long start_code, end_code, start_data, end_data;
57135 unsigned long reloc_func_desc __maybe_unused = 0;
57136 int executable_stack = EXSTACK_DEFAULT;
57137 - unsigned long def_flags = 0;
57138 struct pt_regs *regs = current_pt_regs();
57139 struct {
57140 struct elfhdr elf_ex;
57141 struct elfhdr interp_elf_ex;
57142 } *loc;
57143 + unsigned long pax_task_size;
57144
57145 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
57146 if (!loc) {
57147 @@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
57148 goto out_free_dentry;
57149
57150 /* OK, This is the point of no return */
57151 - current->mm->def_flags = def_flags;
57152 + current->mm->def_flags = 0;
57153
57154 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
57155 may depend on the personality. */
57156 SET_PERSONALITY(loc->elf_ex);
57157 +
57158 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57159 + current->mm->pax_flags = 0UL;
57160 +#endif
57161 +
57162 +#ifdef CONFIG_PAX_DLRESOLVE
57163 + current->mm->call_dl_resolve = 0UL;
57164 +#endif
57165 +
57166 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
57167 + current->mm->call_syscall = 0UL;
57168 +#endif
57169 +
57170 +#ifdef CONFIG_PAX_ASLR
57171 + current->mm->delta_mmap = 0UL;
57172 + current->mm->delta_stack = 0UL;
57173 +#endif
57174 +
57175 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57176 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
57177 + send_sig(SIGKILL, current, 0);
57178 + goto out_free_dentry;
57179 + }
57180 +#endif
57181 +
57182 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57183 + pax_set_initial_flags(bprm);
57184 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
57185 + if (pax_set_initial_flags_func)
57186 + (pax_set_initial_flags_func)(bprm);
57187 +#endif
57188 +
57189 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
57190 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
57191 + current->mm->context.user_cs_limit = PAGE_SIZE;
57192 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
57193 + }
57194 +#endif
57195 +
57196 +#ifdef CONFIG_PAX_SEGMEXEC
57197 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
57198 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
57199 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
57200 + pax_task_size = SEGMEXEC_TASK_SIZE;
57201 + current->mm->def_flags |= VM_NOHUGEPAGE;
57202 + } else
57203 +#endif
57204 +
57205 + pax_task_size = TASK_SIZE;
57206 +
57207 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
57208 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57209 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
57210 + put_cpu();
57211 + }
57212 +#endif
57213 +
57214 +#ifdef CONFIG_PAX_ASLR
57215 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57216 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
57217 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
57218 + }
57219 +#endif
57220 +
57221 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57222 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57223 + executable_stack = EXSTACK_DISABLE_X;
57224 + current->personality &= ~READ_IMPLIES_EXEC;
57225 + } else
57226 +#endif
57227 +
57228 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
57229 current->personality |= READ_IMPLIES_EXEC;
57230
57231 @@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
57232 #else
57233 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
57234 #endif
57235 +
57236 +#ifdef CONFIG_PAX_RANDMMAP
57237 + /* PaX: randomize base address at the default exe base if requested */
57238 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
57239 +#ifdef CONFIG_SPARC64
57240 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
57241 +#else
57242 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
57243 +#endif
57244 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
57245 + elf_flags |= MAP_FIXED;
57246 + }
57247 +#endif
57248 +
57249 }
57250
57251 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
57252 @@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
57253 * allowed task size. Note that p_filesz must always be
57254 * <= p_memsz so it is only necessary to check p_memsz.
57255 */
57256 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57257 - elf_ppnt->p_memsz > TASK_SIZE ||
57258 - TASK_SIZE - elf_ppnt->p_memsz < k) {
57259 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57260 + elf_ppnt->p_memsz > pax_task_size ||
57261 + pax_task_size - elf_ppnt->p_memsz < k) {
57262 /* set_brk can never work. Avoid overflows. */
57263 send_sig(SIGKILL, current, 0);
57264 retval = -EINVAL;
57265 @@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
57266 goto out_free_dentry;
57267 }
57268 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
57269 - send_sig(SIGSEGV, current, 0);
57270 - retval = -EFAULT; /* Nobody gets to see this, but.. */
57271 - goto out_free_dentry;
57272 + /*
57273 + * This bss-zeroing can fail if the ELF
57274 + * file specifies odd protections. So
57275 + * we don't check the return value
57276 + */
57277 }
57278
57279 +#ifdef CONFIG_PAX_RANDMMAP
57280 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57281 + unsigned long start, size, flags;
57282 + vm_flags_t vm_flags;
57283 +
57284 + start = ELF_PAGEALIGN(elf_brk);
57285 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
57286 + flags = MAP_FIXED | MAP_PRIVATE;
57287 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
57288 +
57289 + down_write(&current->mm->mmap_sem);
57290 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
57291 + retval = -ENOMEM;
57292 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
57293 +// if (current->personality & ADDR_NO_RANDOMIZE)
57294 +// vm_flags |= VM_READ | VM_MAYREAD;
57295 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
57296 + retval = IS_ERR_VALUE(start) ? start : 0;
57297 + }
57298 + up_write(&current->mm->mmap_sem);
57299 + if (retval == 0)
57300 + retval = set_brk(start + size, start + size + PAGE_SIZE);
57301 + if (retval < 0) {
57302 + send_sig(SIGKILL, current, 0);
57303 + goto out_free_dentry;
57304 + }
57305 + }
57306 +#endif
57307 +
57308 if (elf_interpreter) {
57309 - unsigned long interp_map_addr = 0;
57310 -
57311 elf_entry = load_elf_interp(&loc->interp_elf_ex,
57312 interpreter,
57313 - &interp_map_addr,
57314 load_bias);
57315 if (!IS_ERR((void *)elf_entry)) {
57316 /*
57317 @@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
57318 * Decide what to dump of a segment, part, all or none.
57319 */
57320 static unsigned long vma_dump_size(struct vm_area_struct *vma,
57321 - unsigned long mm_flags)
57322 + unsigned long mm_flags, long signr)
57323 {
57324 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57325
57326 @@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57327 if (vma->vm_file == NULL)
57328 return 0;
57329
57330 - if (FILTER(MAPPED_PRIVATE))
57331 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57332 goto whole;
57333
57334 /*
57335 @@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57336 {
57337 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57338 int i = 0;
57339 - do
57340 + do {
57341 i += 2;
57342 - while (auxv[i - 2] != AT_NULL);
57343 + } while (auxv[i - 2] != AT_NULL);
57344 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57345 }
57346
57347 @@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57348 {
57349 mm_segment_t old_fs = get_fs();
57350 set_fs(KERNEL_DS);
57351 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57352 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57353 set_fs(old_fs);
57354 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57355 }
57356 @@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57357 }
57358
57359 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57360 - unsigned long mm_flags)
57361 + struct coredump_params *cprm)
57362 {
57363 struct vm_area_struct *vma;
57364 size_t size = 0;
57365
57366 for (vma = first_vma(current, gate_vma); vma != NULL;
57367 vma = next_vma(vma, gate_vma))
57368 - size += vma_dump_size(vma, mm_flags);
57369 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57370 return size;
57371 }
57372
57373 @@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57374
57375 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57376
57377 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57378 + offset += elf_core_vma_data_size(gate_vma, cprm);
57379 offset += elf_core_extra_data_size();
57380 e_shoff = offset;
57381
57382 @@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57383 phdr.p_offset = offset;
57384 phdr.p_vaddr = vma->vm_start;
57385 phdr.p_paddr = 0;
57386 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57387 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57388 phdr.p_memsz = vma->vm_end - vma->vm_start;
57389 offset += phdr.p_filesz;
57390 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57391 @@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57392 unsigned long addr;
57393 unsigned long end;
57394
57395 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57396 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57397
57398 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57399 struct page *page;
57400 @@ -2199,6 +2678,167 @@ out:
57401
57402 #endif /* CONFIG_ELF_CORE */
57403
57404 +#ifdef CONFIG_PAX_MPROTECT
57405 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
57406 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57407 + * we'll remove VM_MAYWRITE for good on RELRO segments.
57408 + *
57409 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57410 + * basis because we want to allow the common case and not the special ones.
57411 + */
57412 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57413 +{
57414 + struct elfhdr elf_h;
57415 + struct elf_phdr elf_p;
57416 + unsigned long i;
57417 + unsigned long oldflags;
57418 + bool is_textrel_rw, is_textrel_rx, is_relro;
57419 +
57420 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57421 + return;
57422 +
57423 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57424 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57425 +
57426 +#ifdef CONFIG_PAX_ELFRELOCS
57427 + /* possible TEXTREL */
57428 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57429 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57430 +#else
57431 + is_textrel_rw = false;
57432 + is_textrel_rx = false;
57433 +#endif
57434 +
57435 + /* possible RELRO */
57436 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57437 +
57438 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57439 + return;
57440 +
57441 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57442 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57443 +
57444 +#ifdef CONFIG_PAX_ETEXECRELOCS
57445 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57446 +#else
57447 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57448 +#endif
57449 +
57450 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57451 + !elf_check_arch(&elf_h) ||
57452 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57453 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57454 + return;
57455 +
57456 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57457 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57458 + return;
57459 + switch (elf_p.p_type) {
57460 + case PT_DYNAMIC:
57461 + if (!is_textrel_rw && !is_textrel_rx)
57462 + continue;
57463 + i = 0UL;
57464 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57465 + elf_dyn dyn;
57466 +
57467 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57468 + break;
57469 + if (dyn.d_tag == DT_NULL)
57470 + break;
57471 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57472 + gr_log_textrel(vma);
57473 + if (is_textrel_rw)
57474 + vma->vm_flags |= VM_MAYWRITE;
57475 + else
57476 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57477 + vma->vm_flags &= ~VM_MAYWRITE;
57478 + break;
57479 + }
57480 + i++;
57481 + }
57482 + is_textrel_rw = false;
57483 + is_textrel_rx = false;
57484 + continue;
57485 +
57486 + case PT_GNU_RELRO:
57487 + if (!is_relro)
57488 + continue;
57489 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57490 + vma->vm_flags &= ~VM_MAYWRITE;
57491 + is_relro = false;
57492 + continue;
57493 +
57494 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
57495 + case PT_PAX_FLAGS: {
57496 + const char *msg_mprotect = "", *msg_emutramp = "";
57497 + char *buffer_lib, *buffer_exe;
57498 +
57499 + if (elf_p.p_flags & PF_NOMPROTECT)
57500 + msg_mprotect = "MPROTECT disabled";
57501 +
57502 +#ifdef CONFIG_PAX_EMUTRAMP
57503 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57504 + msg_emutramp = "EMUTRAMP enabled";
57505 +#endif
57506 +
57507 + if (!msg_mprotect[0] && !msg_emutramp[0])
57508 + continue;
57509 +
57510 + if (!printk_ratelimit())
57511 + continue;
57512 +
57513 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57514 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57515 + if (buffer_lib && buffer_exe) {
57516 + char *path_lib, *path_exe;
57517 +
57518 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57519 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57520 +
57521 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57522 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57523 +
57524 + }
57525 + free_page((unsigned long)buffer_exe);
57526 + free_page((unsigned long)buffer_lib);
57527 + continue;
57528 + }
57529 +#endif
57530 +
57531 + }
57532 + }
57533 +}
57534 +#endif
57535 +
57536 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57537 +
57538 +extern int grsec_enable_log_rwxmaps;
57539 +
57540 +static void elf_handle_mmap(struct file *file)
57541 +{
57542 + struct elfhdr elf_h;
57543 + struct elf_phdr elf_p;
57544 + unsigned long i;
57545 +
57546 + if (!grsec_enable_log_rwxmaps)
57547 + return;
57548 +
57549 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57550 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57551 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57552 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57553 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57554 + return;
57555 +
57556 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57557 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57558 + return;
57559 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57560 + gr_log_ptgnustack(file);
57561 + }
57562 +}
57563 +#endif
57564 +
57565 static int __init init_elf_binfmt(void)
57566 {
57567 register_binfmt(&elf_format);
57568 diff --git a/fs/bio.c b/fs/bio.c
57569 index 8754e7b..0669094 100644
57570 --- a/fs/bio.c
57571 +++ b/fs/bio.c
57572 @@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57573 /*
57574 * Overflow, abort
57575 */
57576 - if (end < start)
57577 + if (end < start || end - start > INT_MAX - nr_pages)
57578 return ERR_PTR(-EINVAL);
57579
57580 nr_pages += end - start;
57581 @@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57582 /*
57583 * Overflow, abort
57584 */
57585 - if (end < start)
57586 + if (end < start || end - start > INT_MAX - nr_pages)
57587 return ERR_PTR(-EINVAL);
57588
57589 nr_pages += end - start;
57590 @@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57591 const int read = bio_data_dir(bio) == READ;
57592 struct bio_map_data *bmd = bio->bi_private;
57593 int i;
57594 - char *p = bmd->sgvecs[0].iov_base;
57595 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57596
57597 bio_for_each_segment_all(bvec, bio, i) {
57598 char *addr = page_address(bvec->bv_page);
57599 diff --git a/fs/block_dev.c b/fs/block_dev.c
57600 index 1e86823..8e34695 100644
57601 --- a/fs/block_dev.c
57602 +++ b/fs/block_dev.c
57603 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57604 else if (bdev->bd_contains == bdev)
57605 return true; /* is a whole device which isn't held */
57606
57607 - else if (whole->bd_holder == bd_may_claim)
57608 + else if (whole->bd_holder == (void *)bd_may_claim)
57609 return true; /* is a partition of a device that is being partitioned */
57610 else if (whole->bd_holder != NULL)
57611 return false; /* is a partition of a held device */
57612 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57613 index cbd3a7d..c6a2881 100644
57614 --- a/fs/btrfs/ctree.c
57615 +++ b/fs/btrfs/ctree.c
57616 @@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57617 free_extent_buffer(buf);
57618 add_root_to_dirty_list(root);
57619 } else {
57620 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57621 - parent_start = parent->start;
57622 - else
57623 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57624 + if (parent)
57625 + parent_start = parent->start;
57626 + else
57627 + parent_start = 0;
57628 + } else
57629 parent_start = 0;
57630
57631 WARN_ON(trans->transid != btrfs_header_generation(parent));
57632 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57633 index 451b00c..a2cccee 100644
57634 --- a/fs/btrfs/delayed-inode.c
57635 +++ b/fs/btrfs/delayed-inode.c
57636 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57637
57638 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57639 {
57640 - int seq = atomic_inc_return(&delayed_root->items_seq);
57641 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57642 if ((atomic_dec_return(&delayed_root->items) <
57643 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57644 waitqueue_active(&delayed_root->wait))
57645 @@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57646
57647 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57648 {
57649 - int val = atomic_read(&delayed_root->items_seq);
57650 + int val = atomic_read_unchecked(&delayed_root->items_seq);
57651
57652 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57653 return 1;
57654 @@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57655 int seq;
57656 int ret;
57657
57658 - seq = atomic_read(&delayed_root->items_seq);
57659 + seq = atomic_read_unchecked(&delayed_root->items_seq);
57660
57661 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57662 if (ret)
57663 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57664 index f70119f..ab5894d 100644
57665 --- a/fs/btrfs/delayed-inode.h
57666 +++ b/fs/btrfs/delayed-inode.h
57667 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57668 */
57669 struct list_head prepare_list;
57670 atomic_t items; /* for delayed items */
57671 - atomic_t items_seq; /* for delayed items */
57672 + atomic_unchecked_t items_seq; /* for delayed items */
57673 int nodes; /* for delayed nodes */
57674 wait_queue_head_t wait;
57675 };
57676 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57677 struct btrfs_delayed_root *delayed_root)
57678 {
57679 atomic_set(&delayed_root->items, 0);
57680 - atomic_set(&delayed_root->items_seq, 0);
57681 + atomic_set_unchecked(&delayed_root->items_seq, 0);
57682 delayed_root->nodes = 0;
57683 spin_lock_init(&delayed_root->lock);
57684 init_waitqueue_head(&delayed_root->wait);
57685 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57686 index a6d8efa..2f062cf 100644
57687 --- a/fs/btrfs/ioctl.c
57688 +++ b/fs/btrfs/ioctl.c
57689 @@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57690 for (i = 0; i < num_types; i++) {
57691 struct btrfs_space_info *tmp;
57692
57693 + /* Don't copy in more than we allocated */
57694 if (!slot_count)
57695 break;
57696
57697 + slot_count--;
57698 +
57699 info = NULL;
57700 rcu_read_lock();
57701 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57702 @@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57703 memcpy(dest, &space, sizeof(space));
57704 dest++;
57705 space_args.total_spaces++;
57706 - slot_count--;
57707 }
57708 - if (!slot_count)
57709 - break;
57710 }
57711 up_read(&info->groups_sem);
57712 }
57713 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57714 index d04db81..96e54f1 100644
57715 --- a/fs/btrfs/super.c
57716 +++ b/fs/btrfs/super.c
57717 @@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57718 function, line, errstr);
57719 return;
57720 }
57721 - ACCESS_ONCE(trans->transaction->aborted) = errno;
57722 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57723 /* Wake up anybody who may be waiting on this transaction */
57724 wake_up(&root->fs_info->transaction_wait);
57725 wake_up(&root->fs_info->transaction_blocked_wait);
57726 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57727 index 865f4cf..f321e86 100644
57728 --- a/fs/btrfs/sysfs.c
57729 +++ b/fs/btrfs/sysfs.c
57730 @@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57731 for (set = 0; set < FEAT_MAX; set++) {
57732 int i;
57733 struct attribute *attrs[2];
57734 - struct attribute_group agroup = {
57735 + attribute_group_no_const agroup = {
57736 .name = "features",
57737 .attrs = attrs,
57738 };
57739 diff --git a/fs/buffer.c b/fs/buffer.c
57740 index 27265a8..289f488 100644
57741 --- a/fs/buffer.c
57742 +++ b/fs/buffer.c
57743 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57744 bh_cachep = kmem_cache_create("buffer_head",
57745 sizeof(struct buffer_head), 0,
57746 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57747 - SLAB_MEM_SPREAD),
57748 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57749 NULL);
57750
57751 /*
57752 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57753 index 622f469..e8d2d55 100644
57754 --- a/fs/cachefiles/bind.c
57755 +++ b/fs/cachefiles/bind.c
57756 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57757 args);
57758
57759 /* start by checking things over */
57760 - ASSERT(cache->fstop_percent >= 0 &&
57761 - cache->fstop_percent < cache->fcull_percent &&
57762 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57763 cache->fcull_percent < cache->frun_percent &&
57764 cache->frun_percent < 100);
57765
57766 - ASSERT(cache->bstop_percent >= 0 &&
57767 - cache->bstop_percent < cache->bcull_percent &&
57768 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57769 cache->bcull_percent < cache->brun_percent &&
57770 cache->brun_percent < 100);
57771
57772 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57773 index 0a1467b..6a53245 100644
57774 --- a/fs/cachefiles/daemon.c
57775 +++ b/fs/cachefiles/daemon.c
57776 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57777 if (n > buflen)
57778 return -EMSGSIZE;
57779
57780 - if (copy_to_user(_buffer, buffer, n) != 0)
57781 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57782 return -EFAULT;
57783
57784 return n;
57785 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57786 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57787 return -EIO;
57788
57789 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57790 + if (datalen > PAGE_SIZE - 1)
57791 return -EOPNOTSUPP;
57792
57793 /* drag the command string into the kernel so we can parse it */
57794 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57795 if (args[0] != '%' || args[1] != '\0')
57796 return -EINVAL;
57797
57798 - if (fstop < 0 || fstop >= cache->fcull_percent)
57799 + if (fstop >= cache->fcull_percent)
57800 return cachefiles_daemon_range_error(cache, args);
57801
57802 cache->fstop_percent = fstop;
57803 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57804 if (args[0] != '%' || args[1] != '\0')
57805 return -EINVAL;
57806
57807 - if (bstop < 0 || bstop >= cache->bcull_percent)
57808 + if (bstop >= cache->bcull_percent)
57809 return cachefiles_daemon_range_error(cache, args);
57810
57811 cache->bstop_percent = bstop;
57812 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57813 index 5349473..d6c0b93 100644
57814 --- a/fs/cachefiles/internal.h
57815 +++ b/fs/cachefiles/internal.h
57816 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57817 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57818 struct rb_root active_nodes; /* active nodes (can't be culled) */
57819 rwlock_t active_lock; /* lock for active_nodes */
57820 - atomic_t gravecounter; /* graveyard uniquifier */
57821 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57822 unsigned frun_percent; /* when to stop culling (% files) */
57823 unsigned fcull_percent; /* when to start culling (% files) */
57824 unsigned fstop_percent; /* when to stop allocating (% files) */
57825 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57826 * proc.c
57827 */
57828 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57829 -extern atomic_t cachefiles_lookup_histogram[HZ];
57830 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57831 -extern atomic_t cachefiles_create_histogram[HZ];
57832 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57833 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57834 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57835
57836 extern int __init cachefiles_proc_init(void);
57837 extern void cachefiles_proc_cleanup(void);
57838 static inline
57839 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57840 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57841 {
57842 unsigned long jif = jiffies - start_jif;
57843 if (jif >= HZ)
57844 jif = HZ - 1;
57845 - atomic_inc(&histogram[jif]);
57846 + atomic_inc_unchecked(&histogram[jif]);
57847 }
57848
57849 #else
57850 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57851 index ca65f39..48921e3 100644
57852 --- a/fs/cachefiles/namei.c
57853 +++ b/fs/cachefiles/namei.c
57854 @@ -317,7 +317,7 @@ try_again:
57855 /* first step is to make up a grave dentry in the graveyard */
57856 sprintf(nbuffer, "%08x%08x",
57857 (uint32_t) get_seconds(),
57858 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57859 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57860
57861 /* do the multiway lock magic */
57862 trap = lock_rename(cache->graveyard, dir);
57863 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57864 index eccd339..4c1d995 100644
57865 --- a/fs/cachefiles/proc.c
57866 +++ b/fs/cachefiles/proc.c
57867 @@ -14,9 +14,9 @@
57868 #include <linux/seq_file.h>
57869 #include "internal.h"
57870
57871 -atomic_t cachefiles_lookup_histogram[HZ];
57872 -atomic_t cachefiles_mkdir_histogram[HZ];
57873 -atomic_t cachefiles_create_histogram[HZ];
57874 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57875 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57876 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57877
57878 /*
57879 * display the latency histogram
57880 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57881 return 0;
57882 default:
57883 index = (unsigned long) v - 3;
57884 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57885 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57886 - z = atomic_read(&cachefiles_create_histogram[index]);
57887 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57888 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57889 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57890 if (x == 0 && y == 0 && z == 0)
57891 return 0;
57892
57893 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57894 index ebaff36..7e3ea26 100644
57895 --- a/fs/cachefiles/rdwr.c
57896 +++ b/fs/cachefiles/rdwr.c
57897 @@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57898 old_fs = get_fs();
57899 set_fs(KERNEL_DS);
57900 ret = file->f_op->write(
57901 - file, (const void __user *) data, len, &pos);
57902 + file, (const void __force_user *) data, len, &pos);
57903 set_fs(old_fs);
57904 kunmap(page);
57905 file_end_write(file);
57906 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57907 index 45eda6d..9126f7f 100644
57908 --- a/fs/ceph/dir.c
57909 +++ b/fs/ceph/dir.c
57910 @@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57911 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57912 struct ceph_mds_client *mdsc = fsc->mdsc;
57913 unsigned frag = fpos_frag(ctx->pos);
57914 - int off = fpos_off(ctx->pos);
57915 + unsigned int off = fpos_off(ctx->pos);
57916 int err;
57917 u32 ftype;
57918 struct ceph_mds_reply_info_parsed *rinfo;
57919 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57920 index 10a4ccb..92dbc5e 100644
57921 --- a/fs/ceph/super.c
57922 +++ b/fs/ceph/super.c
57923 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57924 /*
57925 * construct our own bdi so we can control readahead, etc.
57926 */
57927 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57928 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57929
57930 static int ceph_register_bdi(struct super_block *sb,
57931 struct ceph_fs_client *fsc)
57932 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57933 default_backing_dev_info.ra_pages;
57934
57935 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57936 - atomic_long_inc_return(&bdi_seq));
57937 + atomic_long_inc_return_unchecked(&bdi_seq));
57938 if (!err)
57939 sb->s_bdi = &fsc->backing_dev_info;
57940 return err;
57941 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57942 index f3ac415..3d2420c 100644
57943 --- a/fs/cifs/cifs_debug.c
57944 +++ b/fs/cifs/cifs_debug.c
57945 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57946
57947 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57948 #ifdef CONFIG_CIFS_STATS2
57949 - atomic_set(&totBufAllocCount, 0);
57950 - atomic_set(&totSmBufAllocCount, 0);
57951 + atomic_set_unchecked(&totBufAllocCount, 0);
57952 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57953 #endif /* CONFIG_CIFS_STATS2 */
57954 spin_lock(&cifs_tcp_ses_lock);
57955 list_for_each(tmp1, &cifs_tcp_ses_list) {
57956 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57957 tcon = list_entry(tmp3,
57958 struct cifs_tcon,
57959 tcon_list);
57960 - atomic_set(&tcon->num_smbs_sent, 0);
57961 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57962 if (server->ops->clear_stats)
57963 server->ops->clear_stats(tcon);
57964 }
57965 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57966 smBufAllocCount.counter, cifs_min_small);
57967 #ifdef CONFIG_CIFS_STATS2
57968 seq_printf(m, "Total Large %d Small %d Allocations\n",
57969 - atomic_read(&totBufAllocCount),
57970 - atomic_read(&totSmBufAllocCount));
57971 + atomic_read_unchecked(&totBufAllocCount),
57972 + atomic_read_unchecked(&totSmBufAllocCount));
57973 #endif /* CONFIG_CIFS_STATS2 */
57974
57975 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57976 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57977 if (tcon->need_reconnect)
57978 seq_puts(m, "\tDISCONNECTED ");
57979 seq_printf(m, "\nSMBs: %d",
57980 - atomic_read(&tcon->num_smbs_sent));
57981 + atomic_read_unchecked(&tcon->num_smbs_sent));
57982 if (server->ops->print_stats)
57983 server->ops->print_stats(m, tcon);
57984 }
57985 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57986 index 849f613..eae6dec 100644
57987 --- a/fs/cifs/cifsfs.c
57988 +++ b/fs/cifs/cifsfs.c
57989 @@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57990 */
57991 cifs_req_cachep = kmem_cache_create("cifs_request",
57992 CIFSMaxBufSize + max_hdr_size, 0,
57993 - SLAB_HWCACHE_ALIGN, NULL);
57994 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57995 if (cifs_req_cachep == NULL)
57996 return -ENOMEM;
57997
57998 @@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57999 efficient to alloc 1 per page off the slab compared to 17K (5page)
58000 alloc of large cifs buffers even when page debugging is on */
58001 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
58002 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
58003 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
58004 NULL);
58005 if (cifs_sm_req_cachep == NULL) {
58006 mempool_destroy(cifs_req_poolp);
58007 @@ -1168,8 +1168,8 @@ init_cifs(void)
58008 atomic_set(&bufAllocCount, 0);
58009 atomic_set(&smBufAllocCount, 0);
58010 #ifdef CONFIG_CIFS_STATS2
58011 - atomic_set(&totBufAllocCount, 0);
58012 - atomic_set(&totSmBufAllocCount, 0);
58013 + atomic_set_unchecked(&totBufAllocCount, 0);
58014 + atomic_set_unchecked(&totSmBufAllocCount, 0);
58015 #endif /* CONFIG_CIFS_STATS2 */
58016
58017 atomic_set(&midCount, 0);
58018 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
58019 index c0f3718..6afed7d 100644
58020 --- a/fs/cifs/cifsglob.h
58021 +++ b/fs/cifs/cifsglob.h
58022 @@ -804,35 +804,35 @@ struct cifs_tcon {
58023 __u16 Flags; /* optional support bits */
58024 enum statusEnum tidStatus;
58025 #ifdef CONFIG_CIFS_STATS
58026 - atomic_t num_smbs_sent;
58027 + atomic_unchecked_t num_smbs_sent;
58028 union {
58029 struct {
58030 - atomic_t num_writes;
58031 - atomic_t num_reads;
58032 - atomic_t num_flushes;
58033 - atomic_t num_oplock_brks;
58034 - atomic_t num_opens;
58035 - atomic_t num_closes;
58036 - atomic_t num_deletes;
58037 - atomic_t num_mkdirs;
58038 - atomic_t num_posixopens;
58039 - atomic_t num_posixmkdirs;
58040 - atomic_t num_rmdirs;
58041 - atomic_t num_renames;
58042 - atomic_t num_t2renames;
58043 - atomic_t num_ffirst;
58044 - atomic_t num_fnext;
58045 - atomic_t num_fclose;
58046 - atomic_t num_hardlinks;
58047 - atomic_t num_symlinks;
58048 - atomic_t num_locks;
58049 - atomic_t num_acl_get;
58050 - atomic_t num_acl_set;
58051 + atomic_unchecked_t num_writes;
58052 + atomic_unchecked_t num_reads;
58053 + atomic_unchecked_t num_flushes;
58054 + atomic_unchecked_t num_oplock_brks;
58055 + atomic_unchecked_t num_opens;
58056 + atomic_unchecked_t num_closes;
58057 + atomic_unchecked_t num_deletes;
58058 + atomic_unchecked_t num_mkdirs;
58059 + atomic_unchecked_t num_posixopens;
58060 + atomic_unchecked_t num_posixmkdirs;
58061 + atomic_unchecked_t num_rmdirs;
58062 + atomic_unchecked_t num_renames;
58063 + atomic_unchecked_t num_t2renames;
58064 + atomic_unchecked_t num_ffirst;
58065 + atomic_unchecked_t num_fnext;
58066 + atomic_unchecked_t num_fclose;
58067 + atomic_unchecked_t num_hardlinks;
58068 + atomic_unchecked_t num_symlinks;
58069 + atomic_unchecked_t num_locks;
58070 + atomic_unchecked_t num_acl_get;
58071 + atomic_unchecked_t num_acl_set;
58072 } cifs_stats;
58073 #ifdef CONFIG_CIFS_SMB2
58074 struct {
58075 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58076 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58077 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58078 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58079 } smb2_stats;
58080 #endif /* CONFIG_CIFS_SMB2 */
58081 } stats;
58082 @@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
58083 }
58084
58085 #ifdef CONFIG_CIFS_STATS
58086 -#define cifs_stats_inc atomic_inc
58087 +#define cifs_stats_inc atomic_inc_unchecked
58088
58089 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
58090 unsigned int bytes)
58091 @@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
58092 /* Various Debug counters */
58093 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
58094 #ifdef CONFIG_CIFS_STATS2
58095 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
58096 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
58097 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
58098 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
58099 #endif
58100 GLOBAL_EXTERN atomic_t smBufAllocCount;
58101 GLOBAL_EXTERN atomic_t midCount;
58102 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
58103 index 834fce7..8a314b5 100644
58104 --- a/fs/cifs/file.c
58105 +++ b/fs/cifs/file.c
58106 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
58107 index = mapping->writeback_index; /* Start from prev offset */
58108 end = -1;
58109 } else {
58110 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
58111 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
58112 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
58113 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
58114 range_whole = true;
58115 + index = 0;
58116 + end = ULONG_MAX;
58117 + } else {
58118 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
58119 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
58120 + }
58121 scanned = true;
58122 }
58123 retry:
58124 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
58125 index 2f9f379..43f8025 100644
58126 --- a/fs/cifs/misc.c
58127 +++ b/fs/cifs/misc.c
58128 @@ -170,7 +170,7 @@ cifs_buf_get(void)
58129 memset(ret_buf, 0, buf_size + 3);
58130 atomic_inc(&bufAllocCount);
58131 #ifdef CONFIG_CIFS_STATS2
58132 - atomic_inc(&totBufAllocCount);
58133 + atomic_inc_unchecked(&totBufAllocCount);
58134 #endif /* CONFIG_CIFS_STATS2 */
58135 }
58136
58137 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
58138 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
58139 atomic_inc(&smBufAllocCount);
58140 #ifdef CONFIG_CIFS_STATS2
58141 - atomic_inc(&totSmBufAllocCount);
58142 + atomic_inc_unchecked(&totSmBufAllocCount);
58143 #endif /* CONFIG_CIFS_STATS2 */
58144
58145 }
58146 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
58147 index 526fb89..ecdbf5a 100644
58148 --- a/fs/cifs/smb1ops.c
58149 +++ b/fs/cifs/smb1ops.c
58150 @@ -616,27 +616,27 @@ static void
58151 cifs_clear_stats(struct cifs_tcon *tcon)
58152 {
58153 #ifdef CONFIG_CIFS_STATS
58154 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
58155 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
58156 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
58157 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58158 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
58159 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
58160 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58161 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
58162 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
58163 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
58164 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
58165 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
58166 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
58167 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
58168 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
58169 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
58170 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
58171 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
58172 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
58173 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
58174 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
58175 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
58176 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
58177 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
58178 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58179 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
58180 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
58181 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58182 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
58183 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
58184 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
58185 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
58186 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
58187 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
58188 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
58189 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
58190 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
58191 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
58192 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
58193 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
58194 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
58195 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
58196 #endif
58197 }
58198
58199 @@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58200 {
58201 #ifdef CONFIG_CIFS_STATS
58202 seq_printf(m, " Oplocks breaks: %d",
58203 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
58204 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
58205 seq_printf(m, "\nReads: %d Bytes: %llu",
58206 - atomic_read(&tcon->stats.cifs_stats.num_reads),
58207 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
58208 (long long)(tcon->bytes_read));
58209 seq_printf(m, "\nWrites: %d Bytes: %llu",
58210 - atomic_read(&tcon->stats.cifs_stats.num_writes),
58211 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
58212 (long long)(tcon->bytes_written));
58213 seq_printf(m, "\nFlushes: %d",
58214 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
58215 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
58216 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
58217 - atomic_read(&tcon->stats.cifs_stats.num_locks),
58218 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
58219 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
58220 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
58221 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
58222 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
58223 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
58224 - atomic_read(&tcon->stats.cifs_stats.num_opens),
58225 - atomic_read(&tcon->stats.cifs_stats.num_closes),
58226 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
58227 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
58228 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
58229 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
58230 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
58231 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
58232 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
58233 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
58234 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
58235 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
58236 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
58237 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
58238 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
58239 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
58240 seq_printf(m, "\nRenames: %d T2 Renames %d",
58241 - atomic_read(&tcon->stats.cifs_stats.num_renames),
58242 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
58243 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
58244 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
58245 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
58246 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
58247 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
58248 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
58249 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
58250 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
58251 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
58252 #endif
58253 }
58254
58255 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
58256 index 192f51a..539307e 100644
58257 --- a/fs/cifs/smb2ops.c
58258 +++ b/fs/cifs/smb2ops.c
58259 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
58260 #ifdef CONFIG_CIFS_STATS
58261 int i;
58262 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
58263 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58264 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58265 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58266 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58267 }
58268 #endif
58269 }
58270 @@ -405,65 +405,65 @@ static void
58271 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58272 {
58273 #ifdef CONFIG_CIFS_STATS
58274 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58275 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58276 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58277 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58278 seq_printf(m, "\nNegotiates: %d sent %d failed",
58279 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58280 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58281 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58282 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58283 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58284 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58285 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58286 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58287 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58288 seq_printf(m, "\nLogoffs: %d sent %d failed",
58289 - atomic_read(&sent[SMB2_LOGOFF_HE]),
58290 - atomic_read(&failed[SMB2_LOGOFF_HE]));
58291 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58292 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58293 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58294 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58295 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58296 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58297 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58298 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58299 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58300 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58301 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58302 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58303 seq_printf(m, "\nCreates: %d sent %d failed",
58304 - atomic_read(&sent[SMB2_CREATE_HE]),
58305 - atomic_read(&failed[SMB2_CREATE_HE]));
58306 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58307 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58308 seq_printf(m, "\nCloses: %d sent %d failed",
58309 - atomic_read(&sent[SMB2_CLOSE_HE]),
58310 - atomic_read(&failed[SMB2_CLOSE_HE]));
58311 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58312 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58313 seq_printf(m, "\nFlushes: %d sent %d failed",
58314 - atomic_read(&sent[SMB2_FLUSH_HE]),
58315 - atomic_read(&failed[SMB2_FLUSH_HE]));
58316 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58317 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58318 seq_printf(m, "\nReads: %d sent %d failed",
58319 - atomic_read(&sent[SMB2_READ_HE]),
58320 - atomic_read(&failed[SMB2_READ_HE]));
58321 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
58322 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
58323 seq_printf(m, "\nWrites: %d sent %d failed",
58324 - atomic_read(&sent[SMB2_WRITE_HE]),
58325 - atomic_read(&failed[SMB2_WRITE_HE]));
58326 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58327 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58328 seq_printf(m, "\nLocks: %d sent %d failed",
58329 - atomic_read(&sent[SMB2_LOCK_HE]),
58330 - atomic_read(&failed[SMB2_LOCK_HE]));
58331 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58332 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58333 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58334 - atomic_read(&sent[SMB2_IOCTL_HE]),
58335 - atomic_read(&failed[SMB2_IOCTL_HE]));
58336 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58337 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58338 seq_printf(m, "\nCancels: %d sent %d failed",
58339 - atomic_read(&sent[SMB2_CANCEL_HE]),
58340 - atomic_read(&failed[SMB2_CANCEL_HE]));
58341 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58342 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58343 seq_printf(m, "\nEchos: %d sent %d failed",
58344 - atomic_read(&sent[SMB2_ECHO_HE]),
58345 - atomic_read(&failed[SMB2_ECHO_HE]));
58346 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58347 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58348 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58349 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58350 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58351 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58352 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58353 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58354 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58355 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58356 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58357 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58358 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58359 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58360 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58361 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58362 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58363 seq_printf(m, "\nSetInfos: %d sent %d failed",
58364 - atomic_read(&sent[SMB2_SET_INFO_HE]),
58365 - atomic_read(&failed[SMB2_SET_INFO_HE]));
58366 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58367 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58368 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58369 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58370 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58371 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58372 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58373 #endif
58374 }
58375
58376 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58377 index 8603447..f9caeee 100644
58378 --- a/fs/cifs/smb2pdu.c
58379 +++ b/fs/cifs/smb2pdu.c
58380 @@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58381 default:
58382 cifs_dbg(VFS, "info level %u isn't supported\n",
58383 srch_inf->info_level);
58384 - rc = -EINVAL;
58385 - goto qdir_exit;
58386 + return -EINVAL;
58387 }
58388
58389 req->FileIndex = cpu_to_le32(index);
58390 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58391 index 1da168c..8bc7ff6 100644
58392 --- a/fs/coda/cache.c
58393 +++ b/fs/coda/cache.c
58394 @@ -24,7 +24,7 @@
58395 #include "coda_linux.h"
58396 #include "coda_cache.h"
58397
58398 -static atomic_t permission_epoch = ATOMIC_INIT(0);
58399 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58400
58401 /* replace or extend an acl cache hit */
58402 void coda_cache_enter(struct inode *inode, int mask)
58403 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58404 struct coda_inode_info *cii = ITOC(inode);
58405
58406 spin_lock(&cii->c_lock);
58407 - cii->c_cached_epoch = atomic_read(&permission_epoch);
58408 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58409 if (!uid_eq(cii->c_uid, current_fsuid())) {
58410 cii->c_uid = current_fsuid();
58411 cii->c_cached_perm = mask;
58412 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58413 {
58414 struct coda_inode_info *cii = ITOC(inode);
58415 spin_lock(&cii->c_lock);
58416 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58417 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58418 spin_unlock(&cii->c_lock);
58419 }
58420
58421 /* remove all acl caches */
58422 void coda_cache_clear_all(struct super_block *sb)
58423 {
58424 - atomic_inc(&permission_epoch);
58425 + atomic_inc_unchecked(&permission_epoch);
58426 }
58427
58428
58429 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58430 spin_lock(&cii->c_lock);
58431 hit = (mask & cii->c_cached_perm) == mask &&
58432 uid_eq(cii->c_uid, current_fsuid()) &&
58433 - cii->c_cached_epoch == atomic_read(&permission_epoch);
58434 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58435 spin_unlock(&cii->c_lock);
58436
58437 return hit;
58438 diff --git a/fs/compat.c b/fs/compat.c
58439 index 6af20de..fec3fbb 100644
58440 --- a/fs/compat.c
58441 +++ b/fs/compat.c
58442 @@ -54,7 +54,7 @@
58443 #include <asm/ioctls.h>
58444 #include "internal.h"
58445
58446 -int compat_log = 1;
58447 +int compat_log = 0;
58448
58449 int compat_printk(const char *fmt, ...)
58450 {
58451 @@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
58452
58453 set_fs(KERNEL_DS);
58454 /* The __user pointer cast is valid because of the set_fs() */
58455 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58456 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58457 set_fs(oldfs);
58458 /* truncating is ok because it's a user address */
58459 if (!ret)
58460 @@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58461 goto out;
58462
58463 ret = -EINVAL;
58464 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58465 + if (nr_segs > UIO_MAXIOV)
58466 goto out;
58467 if (nr_segs > fast_segs) {
58468 ret = -ENOMEM;
58469 @@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
58470 struct compat_readdir_callback {
58471 struct dir_context ctx;
58472 struct compat_old_linux_dirent __user *dirent;
58473 + struct file * file;
58474 int result;
58475 };
58476
58477 @@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58478 buf->result = -EOVERFLOW;
58479 return -EOVERFLOW;
58480 }
58481 +
58482 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58483 + return 0;
58484 +
58485 buf->result++;
58486 dirent = buf->dirent;
58487 if (!access_ok(VERIFY_WRITE, dirent,
58488 @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
58489 if (!f.file)
58490 return -EBADF;
58491
58492 + buf.file = f.file;
58493 error = iterate_dir(f.file, &buf.ctx);
58494 if (buf.result)
58495 error = buf.result;
58496 @@ -901,6 +907,7 @@ struct compat_getdents_callback {
58497 struct dir_context ctx;
58498 struct compat_linux_dirent __user *current_dir;
58499 struct compat_linux_dirent __user *previous;
58500 + struct file * file;
58501 int count;
58502 int error;
58503 };
58504 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58505 buf->error = -EOVERFLOW;
58506 return -EOVERFLOW;
58507 }
58508 +
58509 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58510 + return 0;
58511 +
58512 dirent = buf->previous;
58513 if (dirent) {
58514 if (__put_user(offset, &dirent->d_off))
58515 @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
58516 if (!f.file)
58517 return -EBADF;
58518
58519 + buf.file = f.file;
58520 error = iterate_dir(f.file, &buf.ctx);
58521 if (error >= 0)
58522 error = buf.error;
58523 @@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
58524 struct dir_context ctx;
58525 struct linux_dirent64 __user *current_dir;
58526 struct linux_dirent64 __user *previous;
58527 + struct file * file;
58528 int count;
58529 int error;
58530 };
58531 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58532 buf->error = -EINVAL; /* only used if we fail.. */
58533 if (reclen > buf->count)
58534 return -EINVAL;
58535 +
58536 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58537 + return 0;
58538 +
58539 dirent = buf->previous;
58540
58541 if (dirent) {
58542 @@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
58543 if (!f.file)
58544 return -EBADF;
58545
58546 + buf.file = f.file;
58547 error = iterate_dir(f.file, &buf.ctx);
58548 if (error >= 0)
58549 error = buf.error;
58550 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58551 index a81147e..20bf2b5 100644
58552 --- a/fs/compat_binfmt_elf.c
58553 +++ b/fs/compat_binfmt_elf.c
58554 @@ -30,11 +30,13 @@
58555 #undef elf_phdr
58556 #undef elf_shdr
58557 #undef elf_note
58558 +#undef elf_dyn
58559 #undef elf_addr_t
58560 #define elfhdr elf32_hdr
58561 #define elf_phdr elf32_phdr
58562 #define elf_shdr elf32_shdr
58563 #define elf_note elf32_note
58564 +#define elf_dyn Elf32_Dyn
58565 #define elf_addr_t Elf32_Addr
58566
58567 /*
58568 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58569 index 3881610..ab3df0b 100644
58570 --- a/fs/compat_ioctl.c
58571 +++ b/fs/compat_ioctl.c
58572 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58573 return -EFAULT;
58574 if (__get_user(udata, &ss32->iomem_base))
58575 return -EFAULT;
58576 - ss.iomem_base = compat_ptr(udata);
58577 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58578 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58579 __get_user(ss.port_high, &ss32->port_high))
58580 return -EFAULT;
58581 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58582 for (i = 0; i < nmsgs; i++) {
58583 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58584 return -EFAULT;
58585 - if (get_user(datap, &umsgs[i].buf) ||
58586 - put_user(compat_ptr(datap), &tmsgs[i].buf))
58587 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58588 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58589 return -EFAULT;
58590 }
58591 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58592 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58593 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58594 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58595 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58596 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58597 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58598 return -EFAULT;
58599
58600 return ioctl_preallocate(file, p);
58601 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58602 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58603 {
58604 unsigned int a, b;
58605 - a = *(unsigned int *)p;
58606 - b = *(unsigned int *)q;
58607 + a = *(const unsigned int *)p;
58608 + b = *(const unsigned int *)q;
58609 if (a > b)
58610 return 1;
58611 if (a < b)
58612 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58613 index e081acb..911df21 100644
58614 --- a/fs/configfs/dir.c
58615 +++ b/fs/configfs/dir.c
58616 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58617 }
58618 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58619 struct configfs_dirent *next;
58620 - const char *name;
58621 + const unsigned char * name;
58622 + char d_name[sizeof(next->s_dentry->d_iname)];
58623 int len;
58624 struct inode *inode = NULL;
58625
58626 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58627 continue;
58628
58629 name = configfs_get_name(next);
58630 - len = strlen(name);
58631 + if (next->s_dentry && name == next->s_dentry->d_iname) {
58632 + len = next->s_dentry->d_name.len;
58633 + memcpy(d_name, name, len);
58634 + name = d_name;
58635 + } else
58636 + len = strlen(name);
58637
58638 /*
58639 * We'll have a dentry and an inode for
58640 diff --git a/fs/coredump.c b/fs/coredump.c
58641 index e3ad709..836c55f 100644
58642 --- a/fs/coredump.c
58643 +++ b/fs/coredump.c
58644 @@ -73,10 +73,15 @@ static int expand_corename(struct core_name *cn, int size)
58645 static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
58646 {
58647 int free, need;
58648 + va_list arg_copy;
58649
58650 again:
58651 free = cn->size - cn->used;
58652 - need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
58653 +
58654 + va_copy(arg_copy, arg);
58655 + need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy);
58656 + va_end(arg_copy);
58657 +
58658 if (need < free) {
58659 cn->used += need;
58660 return 0;
58661 @@ -437,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58662 struct pipe_inode_info *pipe = file->private_data;
58663
58664 pipe_lock(pipe);
58665 - pipe->readers++;
58666 - pipe->writers--;
58667 + atomic_inc(&pipe->readers);
58668 + atomic_dec(&pipe->writers);
58669 wake_up_interruptible_sync(&pipe->wait);
58670 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58671 pipe_unlock(pipe);
58672 @@ -447,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58673 * We actually want wait_event_freezable() but then we need
58674 * to clear TIF_SIGPENDING and improve dump_interrupted().
58675 */
58676 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
58677 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58678
58679 pipe_lock(pipe);
58680 - pipe->readers--;
58681 - pipe->writers++;
58682 + atomic_dec(&pipe->readers);
58683 + atomic_inc(&pipe->writers);
58684 pipe_unlock(pipe);
58685 }
58686
58687 @@ -498,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58688 struct files_struct *displaced;
58689 bool need_nonrelative = false;
58690 bool core_dumped = false;
58691 - static atomic_t core_dump_count = ATOMIC_INIT(0);
58692 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58693 + long signr = siginfo->si_signo;
58694 + int dumpable;
58695 struct coredump_params cprm = {
58696 .siginfo = siginfo,
58697 .regs = signal_pt_regs(),
58698 @@ -511,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58699 .mm_flags = mm->flags,
58700 };
58701
58702 - audit_core_dumps(siginfo->si_signo);
58703 + audit_core_dumps(signr);
58704 +
58705 + dumpable = __get_dumpable(cprm.mm_flags);
58706 +
58707 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58708 + gr_handle_brute_attach(dumpable);
58709
58710 binfmt = mm->binfmt;
58711 if (!binfmt || !binfmt->core_dump)
58712 goto fail;
58713 - if (!__get_dumpable(cprm.mm_flags))
58714 + if (!dumpable)
58715 goto fail;
58716
58717 cred = prepare_creds();
58718 @@ -535,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58719 need_nonrelative = true;
58720 }
58721
58722 - retval = coredump_wait(siginfo->si_signo, &core_state);
58723 + retval = coredump_wait(signr, &core_state);
58724 if (retval < 0)
58725 goto fail_creds;
58726
58727 @@ -578,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58728 }
58729 cprm.limit = RLIM_INFINITY;
58730
58731 - dump_count = atomic_inc_return(&core_dump_count);
58732 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
58733 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58734 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58735 task_tgid_vnr(current), current->comm);
58736 @@ -610,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58737 } else {
58738 struct inode *inode;
58739
58740 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58741 +
58742 if (cprm.limit < binfmt->min_coredump)
58743 goto fail_unlock;
58744
58745 @@ -668,7 +682,7 @@ close_fail:
58746 filp_close(cprm.file, NULL);
58747 fail_dropcount:
58748 if (ispipe)
58749 - atomic_dec(&core_dump_count);
58750 + atomic_dec_unchecked(&core_dump_count);
58751 fail_unlock:
58752 kfree(cn.corename);
58753 coredump_finish(mm, core_dumped);
58754 @@ -689,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58755 struct file *file = cprm->file;
58756 loff_t pos = file->f_pos;
58757 ssize_t n;
58758 +
58759 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58760 if (cprm->written + nr > cprm->limit)
58761 return 0;
58762 while (nr) {
58763 diff --git a/fs/dcache.c b/fs/dcache.c
58764 index ca02c13..7e2b581 100644
58765 --- a/fs/dcache.c
58766 +++ b/fs/dcache.c
58767 @@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58768 */
58769 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58770 if (name->len > DNAME_INLINE_LEN-1) {
58771 - dname = kmalloc(name->len + 1, GFP_KERNEL);
58772 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58773 if (!dname) {
58774 kmem_cache_free(dentry_cache, dentry);
58775 return NULL;
58776 @@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
58777 mempages -= reserve;
58778
58779 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58780 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58781 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58782 + SLAB_NO_SANITIZE, NULL);
58783
58784 dcache_init();
58785 inode_init();
58786 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58787 index 9c0444c..628490c 100644
58788 --- a/fs/debugfs/inode.c
58789 +++ b/fs/debugfs/inode.c
58790 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58791 */
58792 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58793 {
58794 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58795 + return __create_file(name, S_IFDIR | S_IRWXU,
58796 +#else
58797 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58798 +#endif
58799 parent, NULL, NULL);
58800 }
58801 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58802 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58803 index b167ca4..a224e19 100644
58804 --- a/fs/ecryptfs/inode.c
58805 +++ b/fs/ecryptfs/inode.c
58806 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58807 old_fs = get_fs();
58808 set_fs(get_ds());
58809 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58810 - (char __user *)lower_buf,
58811 + (char __force_user *)lower_buf,
58812 PATH_MAX);
58813 set_fs(old_fs);
58814 if (rc < 0)
58815 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58816 index e4141f2..d8263e8 100644
58817 --- a/fs/ecryptfs/miscdev.c
58818 +++ b/fs/ecryptfs/miscdev.c
58819 @@ -304,7 +304,7 @@ check_list:
58820 goto out_unlock_msg_ctx;
58821 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58822 if (msg_ctx->msg) {
58823 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58824 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58825 goto out_unlock_msg_ctx;
58826 i += packet_length_size;
58827 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58828 diff --git a/fs/exec.c b/fs/exec.c
58829 index 3d78fcc..460e2a0 100644
58830 --- a/fs/exec.c
58831 +++ b/fs/exec.c
58832 @@ -55,8 +55,20 @@
58833 #include <linux/pipe_fs_i.h>
58834 #include <linux/oom.h>
58835 #include <linux/compat.h>
58836 +#include <linux/random.h>
58837 +#include <linux/seq_file.h>
58838 +#include <linux/coredump.h>
58839 +#include <linux/mman.h>
58840 +
58841 +#ifdef CONFIG_PAX_REFCOUNT
58842 +#include <linux/kallsyms.h>
58843 +#include <linux/kdebug.h>
58844 +#endif
58845 +
58846 +#include <trace/events/fs.h>
58847
58848 #include <asm/uaccess.h>
58849 +#include <asm/sections.h>
58850 #include <asm/mmu_context.h>
58851 #include <asm/tlb.h>
58852
58853 @@ -65,19 +77,34 @@
58854
58855 #include <trace/events/sched.h>
58856
58857 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58858 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58859 +{
58860 + 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");
58861 +}
58862 +#endif
58863 +
58864 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58865 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58866 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58867 +#endif
58868 +
58869 int suid_dumpable = 0;
58870
58871 static LIST_HEAD(formats);
58872 static DEFINE_RWLOCK(binfmt_lock);
58873
58874 +extern int gr_process_kernel_exec_ban(void);
58875 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58876 +
58877 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58878 {
58879 BUG_ON(!fmt);
58880 if (WARN_ON(!fmt->load_binary))
58881 return;
58882 write_lock(&binfmt_lock);
58883 - insert ? list_add(&fmt->lh, &formats) :
58884 - list_add_tail(&fmt->lh, &formats);
58885 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58886 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58887 write_unlock(&binfmt_lock);
58888 }
58889
58890 @@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58891 void unregister_binfmt(struct linux_binfmt * fmt)
58892 {
58893 write_lock(&binfmt_lock);
58894 - list_del(&fmt->lh);
58895 + pax_list_del((struct list_head *)&fmt->lh);
58896 write_unlock(&binfmt_lock);
58897 }
58898
58899 @@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58900 int write)
58901 {
58902 struct page *page;
58903 - int ret;
58904
58905 -#ifdef CONFIG_STACK_GROWSUP
58906 - if (write) {
58907 - ret = expand_downwards(bprm->vma, pos);
58908 - if (ret < 0)
58909 - return NULL;
58910 - }
58911 -#endif
58912 - ret = get_user_pages(current, bprm->mm, pos,
58913 - 1, write, 1, &page, NULL);
58914 - if (ret <= 0)
58915 + if (0 > expand_downwards(bprm->vma, pos))
58916 + return NULL;
58917 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58918 return NULL;
58919
58920 if (write) {
58921 @@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58922 if (size <= ARG_MAX)
58923 return page;
58924
58925 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58926 + // only allow 512KB for argv+env on suid/sgid binaries
58927 + // to prevent easy ASLR exhaustion
58928 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58929 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58930 + (size > (512 * 1024))) {
58931 + put_page(page);
58932 + return NULL;
58933 + }
58934 +#endif
58935 +
58936 /*
58937 * Limit to 1/4-th the stack size for the argv+env strings.
58938 * This ensures that:
58939 @@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58940 vma->vm_end = STACK_TOP_MAX;
58941 vma->vm_start = vma->vm_end - PAGE_SIZE;
58942 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58943 +
58944 +#ifdef CONFIG_PAX_SEGMEXEC
58945 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58946 +#endif
58947 +
58948 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58949 INIT_LIST_HEAD(&vma->anon_vma_chain);
58950
58951 @@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58952 mm->stack_vm = mm->total_vm = 1;
58953 up_write(&mm->mmap_sem);
58954 bprm->p = vma->vm_end - sizeof(void *);
58955 +
58956 +#ifdef CONFIG_PAX_RANDUSTACK
58957 + if (randomize_va_space)
58958 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
58959 +#endif
58960 +
58961 return 0;
58962 err:
58963 up_write(&mm->mmap_sem);
58964 @@ -396,7 +437,7 @@ struct user_arg_ptr {
58965 } ptr;
58966 };
58967
58968 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58969 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58970 {
58971 const char __user *native;
58972
58973 @@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58974 compat_uptr_t compat;
58975
58976 if (get_user(compat, argv.ptr.compat + nr))
58977 - return ERR_PTR(-EFAULT);
58978 + return (const char __force_user *)ERR_PTR(-EFAULT);
58979
58980 return compat_ptr(compat);
58981 }
58982 #endif
58983
58984 if (get_user(native, argv.ptr.native + nr))
58985 - return ERR_PTR(-EFAULT);
58986 + return (const char __force_user *)ERR_PTR(-EFAULT);
58987
58988 return native;
58989 }
58990 @@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
58991 if (!p)
58992 break;
58993
58994 - if (IS_ERR(p))
58995 + if (IS_ERR((const char __force_kernel *)p))
58996 return -EFAULT;
58997
58998 if (i >= max)
58999 @@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
59000
59001 ret = -EFAULT;
59002 str = get_user_arg_ptr(argv, argc);
59003 - if (IS_ERR(str))
59004 + if (IS_ERR((const char __force_kernel *)str))
59005 goto out;
59006
59007 len = strnlen_user(str, MAX_ARG_STRLEN);
59008 @@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
59009 int r;
59010 mm_segment_t oldfs = get_fs();
59011 struct user_arg_ptr argv = {
59012 - .ptr.native = (const char __user *const __user *)__argv,
59013 + .ptr.native = (const char __user * const __force_user *)__argv,
59014 };
59015
59016 set_fs(KERNEL_DS);
59017 @@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59018 unsigned long new_end = old_end - shift;
59019 struct mmu_gather tlb;
59020
59021 - BUG_ON(new_start > new_end);
59022 + if (new_start >= new_end || new_start < mmap_min_addr)
59023 + return -ENOMEM;
59024
59025 /*
59026 * ensure there are no vmas between where we want to go
59027 @@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
59028 if (vma != find_vma(mm, new_start))
59029 return -EFAULT;
59030
59031 +#ifdef CONFIG_PAX_SEGMEXEC
59032 + BUG_ON(pax_find_mirror_vma(vma));
59033 +#endif
59034 +
59035 /*
59036 * cover the whole range: [new_start, old_end)
59037 */
59038 @@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59039 stack_top = arch_align_stack(stack_top);
59040 stack_top = PAGE_ALIGN(stack_top);
59041
59042 - if (unlikely(stack_top < mmap_min_addr) ||
59043 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
59044 - return -ENOMEM;
59045 -
59046 stack_shift = vma->vm_end - stack_top;
59047
59048 bprm->p -= stack_shift;
59049 @@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
59050 bprm->exec -= stack_shift;
59051
59052 down_write(&mm->mmap_sem);
59053 +
59054 + /* Move stack pages down in memory. */
59055 + if (stack_shift) {
59056 + ret = shift_arg_pages(vma, stack_shift);
59057 + if (ret)
59058 + goto out_unlock;
59059 + }
59060 +
59061 vm_flags = VM_STACK_FLAGS;
59062
59063 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59064 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59065 + vm_flags &= ~VM_EXEC;
59066 +
59067 +#ifdef CONFIG_PAX_MPROTECT
59068 + if (mm->pax_flags & MF_PAX_MPROTECT)
59069 + vm_flags &= ~VM_MAYEXEC;
59070 +#endif
59071 +
59072 + }
59073 +#endif
59074 +
59075 /*
59076 * Adjust stack execute permissions; explicitly enable for
59077 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
59078 @@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59079 goto out_unlock;
59080 BUG_ON(prev != vma);
59081
59082 - /* Move stack pages down in memory. */
59083 - if (stack_shift) {
59084 - ret = shift_arg_pages(vma, stack_shift);
59085 - if (ret)
59086 - goto out_unlock;
59087 - }
59088 -
59089 /* mprotect_fixup is overkill to remove the temporary stack flags */
59090 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
59091
59092 @@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
59093 #endif
59094 current->mm->start_stack = bprm->p;
59095 ret = expand_stack(vma, stack_base);
59096 +
59097 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
59098 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
59099 + unsigned long size;
59100 + vm_flags_t vm_flags;
59101 +
59102 + size = STACK_TOP - vma->vm_end;
59103 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
59104 +
59105 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
59106 +
59107 +#ifdef CONFIG_X86
59108 + if (!ret) {
59109 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
59110 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
59111 + }
59112 +#endif
59113 +
59114 + }
59115 +#endif
59116 +
59117 if (ret)
59118 ret = -EFAULT;
59119
59120 @@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
59121
59122 fsnotify_open(file);
59123
59124 + trace_open_exec(name->name);
59125 +
59126 err = deny_write_access(file);
59127 if (err)
59128 goto exit;
59129 @@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
59130 old_fs = get_fs();
59131 set_fs(get_ds());
59132 /* The cast to a user pointer is valid due to the set_fs() */
59133 - result = vfs_read(file, (void __user *)addr, count, &pos);
59134 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
59135 set_fs(old_fs);
59136 return result;
59137 }
59138 @@ -1258,7 +1336,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
59139 }
59140 rcu_read_unlock();
59141
59142 - if (p->fs->users > n_fs)
59143 + if (atomic_read(&p->fs->users) > n_fs)
59144 bprm->unsafe |= LSM_UNSAFE_SHARE;
59145 else
59146 p->fs->in_exec = 1;
59147 @@ -1434,6 +1512,31 @@ static int exec_binprm(struct linux_binprm *bprm)
59148 return ret;
59149 }
59150
59151 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59152 +static DEFINE_PER_CPU(u64, exec_counter);
59153 +static int __init init_exec_counters(void)
59154 +{
59155 + unsigned int cpu;
59156 +
59157 + for_each_possible_cpu(cpu) {
59158 + per_cpu(exec_counter, cpu) = (u64)cpu;
59159 + }
59160 +
59161 + return 0;
59162 +}
59163 +early_initcall(init_exec_counters);
59164 +static inline void increment_exec_counter(void)
59165 +{
59166 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
59167 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
59168 +}
59169 +#else
59170 +static inline void increment_exec_counter(void) {}
59171 +#endif
59172 +
59173 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
59174 + struct user_arg_ptr argv);
59175 +
59176 /*
59177 * sys_execve() executes a new program.
59178 */
59179 @@ -1441,6 +1544,11 @@ static int do_execve_common(struct filename *filename,
59180 struct user_arg_ptr argv,
59181 struct user_arg_ptr envp)
59182 {
59183 +#ifdef CONFIG_GRKERNSEC
59184 + struct file *old_exec_file;
59185 + struct acl_subject_label *old_acl;
59186 + struct rlimit old_rlim[RLIM_NLIMITS];
59187 +#endif
59188 struct linux_binprm *bprm;
59189 struct file *file;
59190 struct files_struct *displaced;
59191 @@ -1449,6 +1557,8 @@ static int do_execve_common(struct filename *filename,
59192 if (IS_ERR(filename))
59193 return PTR_ERR(filename);
59194
59195 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
59196 +
59197 /*
59198 * We move the actual failure in case of RLIMIT_NPROC excess from
59199 * set*uid() to execve() because too many poorly written programs
59200 @@ -1486,11 +1596,21 @@ static int do_execve_common(struct filename *filename,
59201 if (IS_ERR(file))
59202 goto out_unmark;
59203
59204 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
59205 + retval = -EPERM;
59206 + goto out_unmark;
59207 + }
59208 +
59209 sched_exec();
59210
59211 bprm->file = file;
59212 bprm->filename = bprm->interp = filename->name;
59213
59214 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
59215 + retval = -EACCES;
59216 + goto out_unmark;
59217 + }
59218 +
59219 retval = bprm_mm_init(bprm);
59220 if (retval)
59221 goto out_unmark;
59222 @@ -1507,24 +1627,70 @@ static int do_execve_common(struct filename *filename,
59223 if (retval < 0)
59224 goto out;
59225
59226 +#ifdef CONFIG_GRKERNSEC
59227 + old_acl = current->acl;
59228 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
59229 + old_exec_file = current->exec_file;
59230 + get_file(file);
59231 + current->exec_file = file;
59232 +#endif
59233 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59234 + /* limit suid stack to 8MB
59235 + * we saved the old limits above and will restore them if this exec fails
59236 + */
59237 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
59238 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
59239 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
59240 +#endif
59241 +
59242 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
59243 + retval = -EPERM;
59244 + goto out_fail;
59245 + }
59246 +
59247 + if (!gr_tpe_allow(file)) {
59248 + retval = -EACCES;
59249 + goto out_fail;
59250 + }
59251 +
59252 + if (gr_check_crash_exec(file)) {
59253 + retval = -EACCES;
59254 + goto out_fail;
59255 + }
59256 +
59257 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
59258 + bprm->unsafe);
59259 + if (retval < 0)
59260 + goto out_fail;
59261 +
59262 retval = copy_strings_kernel(1, &bprm->filename, bprm);
59263 if (retval < 0)
59264 - goto out;
59265 + goto out_fail;
59266
59267 bprm->exec = bprm->p;
59268 retval = copy_strings(bprm->envc, envp, bprm);
59269 if (retval < 0)
59270 - goto out;
59271 + goto out_fail;
59272
59273 retval = copy_strings(bprm->argc, argv, bprm);
59274 if (retval < 0)
59275 - goto out;
59276 + goto out_fail;
59277 +
59278 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
59279 +
59280 + gr_handle_exec_args(bprm, argv);
59281
59282 retval = exec_binprm(bprm);
59283 if (retval < 0)
59284 - goto out;
59285 + goto out_fail;
59286 +#ifdef CONFIG_GRKERNSEC
59287 + if (old_exec_file)
59288 + fput(old_exec_file);
59289 +#endif
59290
59291 /* execve succeeded */
59292 +
59293 + increment_exec_counter();
59294 current->fs->in_exec = 0;
59295 current->in_execve = 0;
59296 acct_update_integrals(current);
59297 @@ -1535,6 +1701,14 @@ static int do_execve_common(struct filename *filename,
59298 put_files_struct(displaced);
59299 return retval;
59300
59301 +out_fail:
59302 +#ifdef CONFIG_GRKERNSEC
59303 + current->acl = old_acl;
59304 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59305 + fput(current->exec_file);
59306 + current->exec_file = old_exec_file;
59307 +#endif
59308 +
59309 out:
59310 if (bprm->mm) {
59311 acct_arg_size(bprm, 0);
59312 @@ -1626,3 +1800,296 @@ asmlinkage long compat_sys_execve(const char __user * filename,
59313 return compat_do_execve(getname(filename), argv, envp);
59314 }
59315 #endif
59316 +
59317 +int pax_check_flags(unsigned long *flags)
59318 +{
59319 + int retval = 0;
59320 +
59321 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59322 + if (*flags & MF_PAX_SEGMEXEC)
59323 + {
59324 + *flags &= ~MF_PAX_SEGMEXEC;
59325 + retval = -EINVAL;
59326 + }
59327 +#endif
59328 +
59329 + if ((*flags & MF_PAX_PAGEEXEC)
59330 +
59331 +#ifdef CONFIG_PAX_PAGEEXEC
59332 + && (*flags & MF_PAX_SEGMEXEC)
59333 +#endif
59334 +
59335 + )
59336 + {
59337 + *flags &= ~MF_PAX_PAGEEXEC;
59338 + retval = -EINVAL;
59339 + }
59340 +
59341 + if ((*flags & MF_PAX_MPROTECT)
59342 +
59343 +#ifdef CONFIG_PAX_MPROTECT
59344 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59345 +#endif
59346 +
59347 + )
59348 + {
59349 + *flags &= ~MF_PAX_MPROTECT;
59350 + retval = -EINVAL;
59351 + }
59352 +
59353 + if ((*flags & MF_PAX_EMUTRAMP)
59354 +
59355 +#ifdef CONFIG_PAX_EMUTRAMP
59356 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59357 +#endif
59358 +
59359 + )
59360 + {
59361 + *flags &= ~MF_PAX_EMUTRAMP;
59362 + retval = -EINVAL;
59363 + }
59364 +
59365 + return retval;
59366 +}
59367 +
59368 +EXPORT_SYMBOL(pax_check_flags);
59369 +
59370 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59371 +char *pax_get_path(const struct path *path, char *buf, int buflen)
59372 +{
59373 + char *pathname = d_path(path, buf, buflen);
59374 +
59375 + if (IS_ERR(pathname))
59376 + goto toolong;
59377 +
59378 + pathname = mangle_path(buf, pathname, "\t\n\\");
59379 + if (!pathname)
59380 + goto toolong;
59381 +
59382 + *pathname = 0;
59383 + return buf;
59384 +
59385 +toolong:
59386 + return "<path too long>";
59387 +}
59388 +EXPORT_SYMBOL(pax_get_path);
59389 +
59390 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59391 +{
59392 + struct task_struct *tsk = current;
59393 + struct mm_struct *mm = current->mm;
59394 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59395 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59396 + char *path_exec = NULL;
59397 + char *path_fault = NULL;
59398 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
59399 + siginfo_t info = { };
59400 +
59401 + if (buffer_exec && buffer_fault) {
59402 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59403 +
59404 + down_read(&mm->mmap_sem);
59405 + vma = mm->mmap;
59406 + while (vma && (!vma_exec || !vma_fault)) {
59407 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59408 + vma_exec = vma;
59409 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59410 + vma_fault = vma;
59411 + vma = vma->vm_next;
59412 + }
59413 + if (vma_exec)
59414 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59415 + if (vma_fault) {
59416 + start = vma_fault->vm_start;
59417 + end = vma_fault->vm_end;
59418 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59419 + if (vma_fault->vm_file)
59420 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59421 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59422 + path_fault = "<heap>";
59423 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59424 + path_fault = "<stack>";
59425 + else
59426 + path_fault = "<anonymous mapping>";
59427 + }
59428 + up_read(&mm->mmap_sem);
59429 + }
59430 + if (tsk->signal->curr_ip)
59431 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59432 + else
59433 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59434 + 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),
59435 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59436 + free_page((unsigned long)buffer_exec);
59437 + free_page((unsigned long)buffer_fault);
59438 + pax_report_insns(regs, pc, sp);
59439 + info.si_signo = SIGKILL;
59440 + info.si_errno = 0;
59441 + info.si_code = SI_KERNEL;
59442 + info.si_pid = 0;
59443 + info.si_uid = 0;
59444 + do_coredump(&info);
59445 +}
59446 +#endif
59447 +
59448 +#ifdef CONFIG_PAX_REFCOUNT
59449 +void pax_report_refcount_overflow(struct pt_regs *regs)
59450 +{
59451 + if (current->signal->curr_ip)
59452 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59453 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
59454 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59455 + else
59456 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59457 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59458 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59459 + preempt_disable();
59460 + show_regs(regs);
59461 + preempt_enable();
59462 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59463 +}
59464 +#endif
59465 +
59466 +#ifdef CONFIG_PAX_USERCOPY
59467 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59468 +static noinline int check_stack_object(const void *obj, unsigned long len)
59469 +{
59470 + const void * const stack = task_stack_page(current);
59471 + const void * const stackend = stack + THREAD_SIZE;
59472 +
59473 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59474 + const void *frame = NULL;
59475 + const void *oldframe;
59476 +#endif
59477 +
59478 + if (obj + len < obj)
59479 + return -1;
59480 +
59481 + if (obj + len <= stack || stackend <= obj)
59482 + return 0;
59483 +
59484 + if (obj < stack || stackend < obj + len)
59485 + return -1;
59486 +
59487 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59488 + oldframe = __builtin_frame_address(1);
59489 + if (oldframe)
59490 + frame = __builtin_frame_address(2);
59491 + /*
59492 + low ----------------------------------------------> high
59493 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
59494 + ^----------------^
59495 + allow copies only within here
59496 + */
59497 + while (stack <= frame && frame < stackend) {
59498 + /* if obj + len extends past the last frame, this
59499 + check won't pass and the next frame will be 0,
59500 + causing us to bail out and correctly report
59501 + the copy as invalid
59502 + */
59503 + if (obj + len <= frame)
59504 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59505 + oldframe = frame;
59506 + frame = *(const void * const *)frame;
59507 + }
59508 + return -1;
59509 +#else
59510 + return 1;
59511 +#endif
59512 +}
59513 +
59514 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59515 +{
59516 + if (current->signal->curr_ip)
59517 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59518 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59519 + else
59520 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59521 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59522 + dump_stack();
59523 + gr_handle_kernel_exploit();
59524 + do_group_exit(SIGKILL);
59525 +}
59526 +#endif
59527 +
59528 +#ifdef CONFIG_PAX_USERCOPY
59529 +
59530 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59531 +{
59532 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59533 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
59534 +#ifdef CONFIG_MODULES
59535 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59536 +#else
59537 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59538 +#endif
59539 +
59540 +#else
59541 + unsigned long textlow = (unsigned long)_stext;
59542 + unsigned long texthigh = (unsigned long)_etext;
59543 +
59544 +#ifdef CONFIG_X86_64
59545 + /* check against linear mapping as well */
59546 + if (high > (unsigned long)__va(__pa(textlow)) &&
59547 + low < (unsigned long)__va(__pa(texthigh)))
59548 + return true;
59549 +#endif
59550 +
59551 +#endif
59552 +
59553 + if (high <= textlow || low >= texthigh)
59554 + return false;
59555 + else
59556 + return true;
59557 +}
59558 +#endif
59559 +
59560 +void __check_object_size(const void *ptr, unsigned long n, bool to_user)
59561 +{
59562 +
59563 +#ifdef CONFIG_PAX_USERCOPY
59564 + const char *type;
59565 +
59566 + if (!n)
59567 + return;
59568 +
59569 + type = check_heap_object(ptr, n);
59570 + if (!type) {
59571 + int ret = check_stack_object(ptr, n);
59572 + if (ret == 1 || ret == 2)
59573 + return;
59574 + if (ret == 0) {
59575 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59576 + type = "<kernel text>";
59577 + else
59578 + return;
59579 + } else
59580 + type = "<process stack>";
59581 + }
59582 +
59583 + pax_report_usercopy(ptr, n, to_user, type);
59584 +#endif
59585 +
59586 +}
59587 +EXPORT_SYMBOL(__check_object_size);
59588 +
59589 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59590 +void pax_track_stack(void)
59591 +{
59592 + unsigned long sp = (unsigned long)&sp;
59593 + if (sp < current_thread_info()->lowest_stack &&
59594 + sp > (unsigned long)task_stack_page(current))
59595 + current_thread_info()->lowest_stack = sp;
59596 +}
59597 +EXPORT_SYMBOL(pax_track_stack);
59598 +#endif
59599 +
59600 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
59601 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59602 +{
59603 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59604 + dump_stack();
59605 + do_group_exit(SIGKILL);
59606 +}
59607 +EXPORT_SYMBOL(report_size_overflow);
59608 +#endif
59609 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59610 index 9f9992b..8b59411 100644
59611 --- a/fs/ext2/balloc.c
59612 +++ b/fs/ext2/balloc.c
59613 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59614
59615 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59616 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59617 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59618 + if (free_blocks < root_blocks + 1 &&
59619 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59620 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59621 - !in_group_p (sbi->s_resgid))) {
59622 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59623 return 0;
59624 }
59625 return 1;
59626 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59627 index 9142614..97484fa 100644
59628 --- a/fs/ext2/xattr.c
59629 +++ b/fs/ext2/xattr.c
59630 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59631 struct buffer_head *bh = NULL;
59632 struct ext2_xattr_entry *entry;
59633 char *end;
59634 - size_t rest = buffer_size;
59635 + size_t rest = buffer_size, total_size = 0;
59636 int error;
59637
59638 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59639 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59640 buffer += size;
59641 }
59642 rest -= size;
59643 + total_size += size;
59644 }
59645 }
59646 - error = buffer_size - rest; /* total size */
59647 + error = total_size;
59648
59649 cleanup:
59650 brelse(bh);
59651 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59652 index 22548f5..41521d8 100644
59653 --- a/fs/ext3/balloc.c
59654 +++ b/fs/ext3/balloc.c
59655 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59656
59657 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59658 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59659 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59660 + if (free_blocks < root_blocks + 1 &&
59661 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59662 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59663 - !in_group_p (sbi->s_resgid))) {
59664 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59665 return 0;
59666 }
59667 return 1;
59668 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59669 index c6874be..f8a6ae8 100644
59670 --- a/fs/ext3/xattr.c
59671 +++ b/fs/ext3/xattr.c
59672 @@ -330,7 +330,7 @@ static int
59673 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59674 char *buffer, size_t buffer_size)
59675 {
59676 - size_t rest = buffer_size;
59677 + size_t rest = buffer_size, total_size = 0;
59678
59679 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59680 const struct xattr_handler *handler =
59681 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59682 buffer += size;
59683 }
59684 rest -= size;
59685 + total_size += size;
59686 }
59687 }
59688 - return buffer_size - rest;
59689 + return total_size;
59690 }
59691
59692 static int
59693 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59694 index 6ea7b14..8fa16d9 100644
59695 --- a/fs/ext4/balloc.c
59696 +++ b/fs/ext4/balloc.c
59697 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59698 /* Hm, nope. Are (enough) root reserved clusters available? */
59699 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59700 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59701 - capable(CAP_SYS_RESOURCE) ||
59702 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59703 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59704 + capable_nolog(CAP_SYS_RESOURCE)) {
59705
59706 if (free_clusters >= (nclusters + dirty_clusters +
59707 resv_clusters))
59708 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59709 index 3a603a8..9b868ba 100644
59710 --- a/fs/ext4/ext4.h
59711 +++ b/fs/ext4/ext4.h
59712 @@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59713 unsigned long s_mb_last_start;
59714
59715 /* stats for buddy allocator */
59716 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59717 - atomic_t s_bal_success; /* we found long enough chunks */
59718 - atomic_t s_bal_allocated; /* in blocks */
59719 - atomic_t s_bal_ex_scanned; /* total extents scanned */
59720 - atomic_t s_bal_goals; /* goal hits */
59721 - atomic_t s_bal_breaks; /* too long searches */
59722 - atomic_t s_bal_2orders; /* 2^order hits */
59723 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59724 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59725 + atomic_unchecked_t s_bal_allocated; /* in blocks */
59726 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59727 + atomic_unchecked_t s_bal_goals; /* goal hits */
59728 + atomic_unchecked_t s_bal_breaks; /* too long searches */
59729 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59730 spinlock_t s_bal_lock;
59731 unsigned long s_mb_buddies_generated;
59732 unsigned long long s_mb_generation_time;
59733 - atomic_t s_mb_lost_chunks;
59734 - atomic_t s_mb_preallocated;
59735 - atomic_t s_mb_discarded;
59736 + atomic_unchecked_t s_mb_lost_chunks;
59737 + atomic_unchecked_t s_mb_preallocated;
59738 + atomic_unchecked_t s_mb_discarded;
59739 atomic_t s_lock_busy;
59740
59741 /* locality groups */
59742 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59743 index 04a5c75..09894fa 100644
59744 --- a/fs/ext4/mballoc.c
59745 +++ b/fs/ext4/mballoc.c
59746 @@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59747 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59748
59749 if (EXT4_SB(sb)->s_mb_stats)
59750 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59751 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59752
59753 break;
59754 }
59755 @@ -2189,7 +2189,7 @@ repeat:
59756 ac->ac_status = AC_STATUS_CONTINUE;
59757 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59758 cr = 3;
59759 - atomic_inc(&sbi->s_mb_lost_chunks);
59760 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59761 goto repeat;
59762 }
59763 }
59764 @@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59765 if (sbi->s_mb_stats) {
59766 ext4_msg(sb, KERN_INFO,
59767 "mballoc: %u blocks %u reqs (%u success)",
59768 - atomic_read(&sbi->s_bal_allocated),
59769 - atomic_read(&sbi->s_bal_reqs),
59770 - atomic_read(&sbi->s_bal_success));
59771 + atomic_read_unchecked(&sbi->s_bal_allocated),
59772 + atomic_read_unchecked(&sbi->s_bal_reqs),
59773 + atomic_read_unchecked(&sbi->s_bal_success));
59774 ext4_msg(sb, KERN_INFO,
59775 "mballoc: %u extents scanned, %u goal hits, "
59776 "%u 2^N hits, %u breaks, %u lost",
59777 - atomic_read(&sbi->s_bal_ex_scanned),
59778 - atomic_read(&sbi->s_bal_goals),
59779 - atomic_read(&sbi->s_bal_2orders),
59780 - atomic_read(&sbi->s_bal_breaks),
59781 - atomic_read(&sbi->s_mb_lost_chunks));
59782 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59783 + atomic_read_unchecked(&sbi->s_bal_goals),
59784 + atomic_read_unchecked(&sbi->s_bal_2orders),
59785 + atomic_read_unchecked(&sbi->s_bal_breaks),
59786 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59787 ext4_msg(sb, KERN_INFO,
59788 "mballoc: %lu generated and it took %Lu",
59789 sbi->s_mb_buddies_generated,
59790 sbi->s_mb_generation_time);
59791 ext4_msg(sb, KERN_INFO,
59792 "mballoc: %u preallocated, %u discarded",
59793 - atomic_read(&sbi->s_mb_preallocated),
59794 - atomic_read(&sbi->s_mb_discarded));
59795 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59796 + atomic_read_unchecked(&sbi->s_mb_discarded));
59797 }
59798
59799 free_percpu(sbi->s_locality_groups);
59800 @@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59801 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59802
59803 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59804 - atomic_inc(&sbi->s_bal_reqs);
59805 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59806 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59807 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59808 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59809 - atomic_inc(&sbi->s_bal_success);
59810 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59811 + atomic_inc_unchecked(&sbi->s_bal_success);
59812 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59813 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59814 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59815 - atomic_inc(&sbi->s_bal_goals);
59816 + atomic_inc_unchecked(&sbi->s_bal_goals);
59817 if (ac->ac_found > sbi->s_mb_max_to_scan)
59818 - atomic_inc(&sbi->s_bal_breaks);
59819 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59820 }
59821
59822 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59823 @@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59824 trace_ext4_mb_new_inode_pa(ac, pa);
59825
59826 ext4_mb_use_inode_pa(ac, pa);
59827 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59828 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59829
59830 ei = EXT4_I(ac->ac_inode);
59831 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59832 @@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59833 trace_ext4_mb_new_group_pa(ac, pa);
59834
59835 ext4_mb_use_group_pa(ac, pa);
59836 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59837 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59838
59839 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59840 lg = ac->ac_lg;
59841 @@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59842 * from the bitmap and continue.
59843 */
59844 }
59845 - atomic_add(free, &sbi->s_mb_discarded);
59846 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59847
59848 return err;
59849 }
59850 @@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59851 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59852 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59853 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59854 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59855 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59856 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59857
59858 return 0;
59859 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59860 index 04434ad..6404663 100644
59861 --- a/fs/ext4/mmp.c
59862 +++ b/fs/ext4/mmp.c
59863 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59864 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59865 const char *function, unsigned int line, const char *msg)
59866 {
59867 - __ext4_warning(sb, function, line, msg);
59868 + __ext4_warning(sb, function, line, "%s", msg);
59869 __ext4_warning(sb, function, line,
59870 "MMP failure info: last update time: %llu, last update "
59871 "node: %s, last update device: %s\n",
59872 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59873 index 710fed2..a82e4e8 100644
59874 --- a/fs/ext4/super.c
59875 +++ b/fs/ext4/super.c
59876 @@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59877 }
59878
59879 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59880 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59881 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59882 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59883
59884 #ifdef CONFIG_QUOTA
59885 @@ -2450,7 +2450,7 @@ struct ext4_attr {
59886 int offset;
59887 int deprecated_val;
59888 } u;
59889 -};
59890 +} __do_const;
59891
59892 static int parse_strtoull(const char *buf,
59893 unsigned long long max, unsigned long long *value)
59894 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59895 index 55e611c..cfad16d 100644
59896 --- a/fs/ext4/xattr.c
59897 +++ b/fs/ext4/xattr.c
59898 @@ -381,7 +381,7 @@ static int
59899 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59900 char *buffer, size_t buffer_size)
59901 {
59902 - size_t rest = buffer_size;
59903 + size_t rest = buffer_size, total_size = 0;
59904
59905 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59906 const struct xattr_handler *handler =
59907 @@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59908 buffer += size;
59909 }
59910 rest -= size;
59911 + total_size += size;
59912 }
59913 }
59914 - return buffer_size - rest;
59915 + return total_size;
59916 }
59917
59918 static int
59919 diff --git a/fs/fcntl.c b/fs/fcntl.c
59920 index ef68665..5deacdc 100644
59921 --- a/fs/fcntl.c
59922 +++ b/fs/fcntl.c
59923 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59924 if (err)
59925 return err;
59926
59927 + if (gr_handle_chroot_fowner(pid, type))
59928 + return -ENOENT;
59929 + if (gr_check_protected_task_fowner(pid, type))
59930 + return -EACCES;
59931 +
59932 f_modown(filp, pid, type, force);
59933 return 0;
59934 }
59935 diff --git a/fs/fhandle.c b/fs/fhandle.c
59936 index 999ff5c..41f4109 100644
59937 --- a/fs/fhandle.c
59938 +++ b/fs/fhandle.c
59939 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59940 } else
59941 retval = 0;
59942 /* copy the mount id */
59943 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59944 - sizeof(*mnt_id)) ||
59945 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59946 copy_to_user(ufh, handle,
59947 sizeof(struct file_handle) + handle_bytes))
59948 retval = -EFAULT;
59949 diff --git a/fs/file.c b/fs/file.c
59950 index eb56a13..ccee850 100644
59951 --- a/fs/file.c
59952 +++ b/fs/file.c
59953 @@ -16,6 +16,7 @@
59954 #include <linux/slab.h>
59955 #include <linux/vmalloc.h>
59956 #include <linux/file.h>
59957 +#include <linux/security.h>
59958 #include <linux/fdtable.h>
59959 #include <linux/bitops.h>
59960 #include <linux/interrupt.h>
59961 @@ -141,7 +142,7 @@ out:
59962 * Return <0 error code on error; 1 on successful completion.
59963 * The files->file_lock should be held on entry, and will be held on exit.
59964 */
59965 -static int expand_fdtable(struct files_struct *files, int nr)
59966 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
59967 __releases(files->file_lock)
59968 __acquires(files->file_lock)
59969 {
59970 @@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59971 * expanded and execution may have blocked.
59972 * The files->file_lock should be held on entry, and will be held on exit.
59973 */
59974 -static int expand_files(struct files_struct *files, int nr)
59975 +static int expand_files(struct files_struct *files, unsigned int nr)
59976 {
59977 struct fdtable *fdt;
59978
59979 @@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59980 if (!file)
59981 return __close_fd(files, fd);
59982
59983 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59984 if (fd >= rlimit(RLIMIT_NOFILE))
59985 return -EBADF;
59986
59987 @@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59988 if (unlikely(oldfd == newfd))
59989 return -EINVAL;
59990
59991 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59992 if (newfd >= rlimit(RLIMIT_NOFILE))
59993 return -EBADF;
59994
59995 @@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59996 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59997 {
59998 int err;
59999 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
60000 if (from >= rlimit(RLIMIT_NOFILE))
60001 return -EINVAL;
60002 err = alloc_fd(from, flags);
60003 diff --git a/fs/filesystems.c b/fs/filesystems.c
60004 index 92567d9..fcd8cbf 100644
60005 --- a/fs/filesystems.c
60006 +++ b/fs/filesystems.c
60007 @@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
60008 int len = dot ? dot - name : strlen(name);
60009
60010 fs = __get_fs_type(name, len);
60011 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
60012 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
60013 +#else
60014 if (!fs && (request_module("fs-%.*s", len, name) == 0))
60015 +#endif
60016 fs = __get_fs_type(name, len);
60017
60018 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
60019 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
60020 index 7dca743..543d620 100644
60021 --- a/fs/fs_struct.c
60022 +++ b/fs/fs_struct.c
60023 @@ -4,6 +4,7 @@
60024 #include <linux/path.h>
60025 #include <linux/slab.h>
60026 #include <linux/fs_struct.h>
60027 +#include <linux/grsecurity.h>
60028 #include "internal.h"
60029
60030 /*
60031 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
60032 write_seqcount_begin(&fs->seq);
60033 old_root = fs->root;
60034 fs->root = *path;
60035 + gr_set_chroot_entries(current, path);
60036 write_seqcount_end(&fs->seq);
60037 spin_unlock(&fs->lock);
60038 if (old_root.dentry)
60039 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
60040 int hits = 0;
60041 spin_lock(&fs->lock);
60042 write_seqcount_begin(&fs->seq);
60043 + /* this root replacement is only done by pivot_root,
60044 + leave grsec's chroot tagging alone for this task
60045 + so that a pivoted root isn't treated as a chroot
60046 + */
60047 hits += replace_path(&fs->root, old_root, new_root);
60048 hits += replace_path(&fs->pwd, old_root, new_root);
60049 write_seqcount_end(&fs->seq);
60050 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
60051 task_lock(tsk);
60052 spin_lock(&fs->lock);
60053 tsk->fs = NULL;
60054 - kill = !--fs->users;
60055 + gr_clear_chroot_entries(tsk);
60056 + kill = !atomic_dec_return(&fs->users);
60057 spin_unlock(&fs->lock);
60058 task_unlock(tsk);
60059 if (kill)
60060 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60061 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
60062 /* We don't need to lock fs - think why ;-) */
60063 if (fs) {
60064 - fs->users = 1;
60065 + atomic_set(&fs->users, 1);
60066 fs->in_exec = 0;
60067 spin_lock_init(&fs->lock);
60068 seqcount_init(&fs->seq);
60069 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60070 spin_lock(&old->lock);
60071 fs->root = old->root;
60072 path_get(&fs->root);
60073 + /* instead of calling gr_set_chroot_entries here,
60074 + we call it from every caller of this function
60075 + */
60076 fs->pwd = old->pwd;
60077 path_get(&fs->pwd);
60078 spin_unlock(&old->lock);
60079 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
60080
60081 task_lock(current);
60082 spin_lock(&fs->lock);
60083 - kill = !--fs->users;
60084 + kill = !atomic_dec_return(&fs->users);
60085 current->fs = new_fs;
60086 + gr_set_chroot_entries(current, &new_fs->root);
60087 spin_unlock(&fs->lock);
60088 task_unlock(current);
60089
60090 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
60091
60092 int current_umask(void)
60093 {
60094 - return current->fs->umask;
60095 + return current->fs->umask | gr_acl_umask();
60096 }
60097 EXPORT_SYMBOL(current_umask);
60098
60099 /* to be mentioned only in INIT_TASK */
60100 struct fs_struct init_fs = {
60101 - .users = 1,
60102 + .users = ATOMIC_INIT(1),
60103 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
60104 .seq = SEQCNT_ZERO(init_fs.seq),
60105 .umask = 0022,
60106 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
60107 index 29d7feb..303644d 100644
60108 --- a/fs/fscache/cookie.c
60109 +++ b/fs/fscache/cookie.c
60110 @@ -19,7 +19,7 @@
60111
60112 struct kmem_cache *fscache_cookie_jar;
60113
60114 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
60115 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
60116
60117 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
60118 static int fscache_alloc_object(struct fscache_cache *cache,
60119 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
60120 parent ? (char *) parent->def->name : "<no-parent>",
60121 def->name, netfs_data, enable);
60122
60123 - fscache_stat(&fscache_n_acquires);
60124 + fscache_stat_unchecked(&fscache_n_acquires);
60125
60126 /* if there's no parent cookie, then we don't create one here either */
60127 if (!parent) {
60128 - fscache_stat(&fscache_n_acquires_null);
60129 + fscache_stat_unchecked(&fscache_n_acquires_null);
60130 _leave(" [no parent]");
60131 return NULL;
60132 }
60133 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60134 /* allocate and initialise a cookie */
60135 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
60136 if (!cookie) {
60137 - fscache_stat(&fscache_n_acquires_oom);
60138 + fscache_stat_unchecked(&fscache_n_acquires_oom);
60139 _leave(" [ENOMEM]");
60140 return NULL;
60141 }
60142 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
60143
60144 switch (cookie->def->type) {
60145 case FSCACHE_COOKIE_TYPE_INDEX:
60146 - fscache_stat(&fscache_n_cookie_index);
60147 + fscache_stat_unchecked(&fscache_n_cookie_index);
60148 break;
60149 case FSCACHE_COOKIE_TYPE_DATAFILE:
60150 - fscache_stat(&fscache_n_cookie_data);
60151 + fscache_stat_unchecked(&fscache_n_cookie_data);
60152 break;
60153 default:
60154 - fscache_stat(&fscache_n_cookie_special);
60155 + fscache_stat_unchecked(&fscache_n_cookie_special);
60156 break;
60157 }
60158
60159 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60160 } else {
60161 atomic_dec(&parent->n_children);
60162 __fscache_cookie_put(cookie);
60163 - fscache_stat(&fscache_n_acquires_nobufs);
60164 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
60165 _leave(" = NULL");
60166 return NULL;
60167 }
60168 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60169 }
60170 }
60171
60172 - fscache_stat(&fscache_n_acquires_ok);
60173 + fscache_stat_unchecked(&fscache_n_acquires_ok);
60174 _leave(" = %p", cookie);
60175 return cookie;
60176 }
60177 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
60178 cache = fscache_select_cache_for_object(cookie->parent);
60179 if (!cache) {
60180 up_read(&fscache_addremove_sem);
60181 - fscache_stat(&fscache_n_acquires_no_cache);
60182 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
60183 _leave(" = -ENOMEDIUM [no cache]");
60184 return -ENOMEDIUM;
60185 }
60186 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
60187 object = cache->ops->alloc_object(cache, cookie);
60188 fscache_stat_d(&fscache_n_cop_alloc_object);
60189 if (IS_ERR(object)) {
60190 - fscache_stat(&fscache_n_object_no_alloc);
60191 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
60192 ret = PTR_ERR(object);
60193 goto error;
60194 }
60195
60196 - fscache_stat(&fscache_n_object_alloc);
60197 + fscache_stat_unchecked(&fscache_n_object_alloc);
60198
60199 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
60200 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
60201
60202 _debug("ALLOC OBJ%x: %s {%lx}",
60203 object->debug_id, cookie->def->name, object->events);
60204 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
60205
60206 _enter("{%s}", cookie->def->name);
60207
60208 - fscache_stat(&fscache_n_invalidates);
60209 + fscache_stat_unchecked(&fscache_n_invalidates);
60210
60211 /* Only permit invalidation of data files. Invalidating an index will
60212 * require the caller to release all its attachments to the tree rooted
60213 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
60214 {
60215 struct fscache_object *object;
60216
60217 - fscache_stat(&fscache_n_updates);
60218 + fscache_stat_unchecked(&fscache_n_updates);
60219
60220 if (!cookie) {
60221 - fscache_stat(&fscache_n_updates_null);
60222 + fscache_stat_unchecked(&fscache_n_updates_null);
60223 _leave(" [no cookie]");
60224 return;
60225 }
60226 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
60227 */
60228 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
60229 {
60230 - fscache_stat(&fscache_n_relinquishes);
60231 + fscache_stat_unchecked(&fscache_n_relinquishes);
60232 if (retire)
60233 - fscache_stat(&fscache_n_relinquishes_retire);
60234 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
60235
60236 if (!cookie) {
60237 - fscache_stat(&fscache_n_relinquishes_null);
60238 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
60239 _leave(" [no cookie]");
60240 return;
60241 }
60242 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60243 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60244 goto inconsistent;
60245
60246 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60247 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60248
60249 __fscache_use_cookie(cookie);
60250 if (fscache_submit_op(object, op) < 0)
60251 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60252 index 4226f66..0fb3f45 100644
60253 --- a/fs/fscache/internal.h
60254 +++ b/fs/fscache/internal.h
60255 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60256 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60257 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60258 struct fscache_operation *,
60259 - atomic_t *,
60260 - atomic_t *,
60261 + atomic_unchecked_t *,
60262 + atomic_unchecked_t *,
60263 void (*)(struct fscache_operation *));
60264 extern void fscache_invalidate_writes(struct fscache_cookie *);
60265
60266 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60267 * stats.c
60268 */
60269 #ifdef CONFIG_FSCACHE_STATS
60270 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60271 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60272 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60273 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60274
60275 -extern atomic_t fscache_n_op_pend;
60276 -extern atomic_t fscache_n_op_run;
60277 -extern atomic_t fscache_n_op_enqueue;
60278 -extern atomic_t fscache_n_op_deferred_release;
60279 -extern atomic_t fscache_n_op_release;
60280 -extern atomic_t fscache_n_op_gc;
60281 -extern atomic_t fscache_n_op_cancelled;
60282 -extern atomic_t fscache_n_op_rejected;
60283 +extern atomic_unchecked_t fscache_n_op_pend;
60284 +extern atomic_unchecked_t fscache_n_op_run;
60285 +extern atomic_unchecked_t fscache_n_op_enqueue;
60286 +extern atomic_unchecked_t fscache_n_op_deferred_release;
60287 +extern atomic_unchecked_t fscache_n_op_release;
60288 +extern atomic_unchecked_t fscache_n_op_gc;
60289 +extern atomic_unchecked_t fscache_n_op_cancelled;
60290 +extern atomic_unchecked_t fscache_n_op_rejected;
60291
60292 -extern atomic_t fscache_n_attr_changed;
60293 -extern atomic_t fscache_n_attr_changed_ok;
60294 -extern atomic_t fscache_n_attr_changed_nobufs;
60295 -extern atomic_t fscache_n_attr_changed_nomem;
60296 -extern atomic_t fscache_n_attr_changed_calls;
60297 +extern atomic_unchecked_t fscache_n_attr_changed;
60298 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
60299 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60300 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60301 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
60302
60303 -extern atomic_t fscache_n_allocs;
60304 -extern atomic_t fscache_n_allocs_ok;
60305 -extern atomic_t fscache_n_allocs_wait;
60306 -extern atomic_t fscache_n_allocs_nobufs;
60307 -extern atomic_t fscache_n_allocs_intr;
60308 -extern atomic_t fscache_n_allocs_object_dead;
60309 -extern atomic_t fscache_n_alloc_ops;
60310 -extern atomic_t fscache_n_alloc_op_waits;
60311 +extern atomic_unchecked_t fscache_n_allocs;
60312 +extern atomic_unchecked_t fscache_n_allocs_ok;
60313 +extern atomic_unchecked_t fscache_n_allocs_wait;
60314 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
60315 +extern atomic_unchecked_t fscache_n_allocs_intr;
60316 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
60317 +extern atomic_unchecked_t fscache_n_alloc_ops;
60318 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
60319
60320 -extern atomic_t fscache_n_retrievals;
60321 -extern atomic_t fscache_n_retrievals_ok;
60322 -extern atomic_t fscache_n_retrievals_wait;
60323 -extern atomic_t fscache_n_retrievals_nodata;
60324 -extern atomic_t fscache_n_retrievals_nobufs;
60325 -extern atomic_t fscache_n_retrievals_intr;
60326 -extern atomic_t fscache_n_retrievals_nomem;
60327 -extern atomic_t fscache_n_retrievals_object_dead;
60328 -extern atomic_t fscache_n_retrieval_ops;
60329 -extern atomic_t fscache_n_retrieval_op_waits;
60330 +extern atomic_unchecked_t fscache_n_retrievals;
60331 +extern atomic_unchecked_t fscache_n_retrievals_ok;
60332 +extern atomic_unchecked_t fscache_n_retrievals_wait;
60333 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
60334 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60335 +extern atomic_unchecked_t fscache_n_retrievals_intr;
60336 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
60337 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60338 +extern atomic_unchecked_t fscache_n_retrieval_ops;
60339 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60340
60341 -extern atomic_t fscache_n_stores;
60342 -extern atomic_t fscache_n_stores_ok;
60343 -extern atomic_t fscache_n_stores_again;
60344 -extern atomic_t fscache_n_stores_nobufs;
60345 -extern atomic_t fscache_n_stores_oom;
60346 -extern atomic_t fscache_n_store_ops;
60347 -extern atomic_t fscache_n_store_calls;
60348 -extern atomic_t fscache_n_store_pages;
60349 -extern atomic_t fscache_n_store_radix_deletes;
60350 -extern atomic_t fscache_n_store_pages_over_limit;
60351 +extern atomic_unchecked_t fscache_n_stores;
60352 +extern atomic_unchecked_t fscache_n_stores_ok;
60353 +extern atomic_unchecked_t fscache_n_stores_again;
60354 +extern atomic_unchecked_t fscache_n_stores_nobufs;
60355 +extern atomic_unchecked_t fscache_n_stores_oom;
60356 +extern atomic_unchecked_t fscache_n_store_ops;
60357 +extern atomic_unchecked_t fscache_n_store_calls;
60358 +extern atomic_unchecked_t fscache_n_store_pages;
60359 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
60360 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60361
60362 -extern atomic_t fscache_n_store_vmscan_not_storing;
60363 -extern atomic_t fscache_n_store_vmscan_gone;
60364 -extern atomic_t fscache_n_store_vmscan_busy;
60365 -extern atomic_t fscache_n_store_vmscan_cancelled;
60366 -extern atomic_t fscache_n_store_vmscan_wait;
60367 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60368 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60369 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60370 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60371 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60372
60373 -extern atomic_t fscache_n_marks;
60374 -extern atomic_t fscache_n_uncaches;
60375 +extern atomic_unchecked_t fscache_n_marks;
60376 +extern atomic_unchecked_t fscache_n_uncaches;
60377
60378 -extern atomic_t fscache_n_acquires;
60379 -extern atomic_t fscache_n_acquires_null;
60380 -extern atomic_t fscache_n_acquires_no_cache;
60381 -extern atomic_t fscache_n_acquires_ok;
60382 -extern atomic_t fscache_n_acquires_nobufs;
60383 -extern atomic_t fscache_n_acquires_oom;
60384 +extern atomic_unchecked_t fscache_n_acquires;
60385 +extern atomic_unchecked_t fscache_n_acquires_null;
60386 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
60387 +extern atomic_unchecked_t fscache_n_acquires_ok;
60388 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
60389 +extern atomic_unchecked_t fscache_n_acquires_oom;
60390
60391 -extern atomic_t fscache_n_invalidates;
60392 -extern atomic_t fscache_n_invalidates_run;
60393 +extern atomic_unchecked_t fscache_n_invalidates;
60394 +extern atomic_unchecked_t fscache_n_invalidates_run;
60395
60396 -extern atomic_t fscache_n_updates;
60397 -extern atomic_t fscache_n_updates_null;
60398 -extern atomic_t fscache_n_updates_run;
60399 +extern atomic_unchecked_t fscache_n_updates;
60400 +extern atomic_unchecked_t fscache_n_updates_null;
60401 +extern atomic_unchecked_t fscache_n_updates_run;
60402
60403 -extern atomic_t fscache_n_relinquishes;
60404 -extern atomic_t fscache_n_relinquishes_null;
60405 -extern atomic_t fscache_n_relinquishes_waitcrt;
60406 -extern atomic_t fscache_n_relinquishes_retire;
60407 +extern atomic_unchecked_t fscache_n_relinquishes;
60408 +extern atomic_unchecked_t fscache_n_relinquishes_null;
60409 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60410 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
60411
60412 -extern atomic_t fscache_n_cookie_index;
60413 -extern atomic_t fscache_n_cookie_data;
60414 -extern atomic_t fscache_n_cookie_special;
60415 +extern atomic_unchecked_t fscache_n_cookie_index;
60416 +extern atomic_unchecked_t fscache_n_cookie_data;
60417 +extern atomic_unchecked_t fscache_n_cookie_special;
60418
60419 -extern atomic_t fscache_n_object_alloc;
60420 -extern atomic_t fscache_n_object_no_alloc;
60421 -extern atomic_t fscache_n_object_lookups;
60422 -extern atomic_t fscache_n_object_lookups_negative;
60423 -extern atomic_t fscache_n_object_lookups_positive;
60424 -extern atomic_t fscache_n_object_lookups_timed_out;
60425 -extern atomic_t fscache_n_object_created;
60426 -extern atomic_t fscache_n_object_avail;
60427 -extern atomic_t fscache_n_object_dead;
60428 +extern atomic_unchecked_t fscache_n_object_alloc;
60429 +extern atomic_unchecked_t fscache_n_object_no_alloc;
60430 +extern atomic_unchecked_t fscache_n_object_lookups;
60431 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
60432 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
60433 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60434 +extern atomic_unchecked_t fscache_n_object_created;
60435 +extern atomic_unchecked_t fscache_n_object_avail;
60436 +extern atomic_unchecked_t fscache_n_object_dead;
60437
60438 -extern atomic_t fscache_n_checkaux_none;
60439 -extern atomic_t fscache_n_checkaux_okay;
60440 -extern atomic_t fscache_n_checkaux_update;
60441 -extern atomic_t fscache_n_checkaux_obsolete;
60442 +extern atomic_unchecked_t fscache_n_checkaux_none;
60443 +extern atomic_unchecked_t fscache_n_checkaux_okay;
60444 +extern atomic_unchecked_t fscache_n_checkaux_update;
60445 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60446
60447 extern atomic_t fscache_n_cop_alloc_object;
60448 extern atomic_t fscache_n_cop_lookup_object;
60449 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60450 atomic_inc(stat);
60451 }
60452
60453 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60454 +{
60455 + atomic_inc_unchecked(stat);
60456 +}
60457 +
60458 static inline void fscache_stat_d(atomic_t *stat)
60459 {
60460 atomic_dec(stat);
60461 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60462
60463 #define __fscache_stat(stat) (NULL)
60464 #define fscache_stat(stat) do {} while (0)
60465 +#define fscache_stat_unchecked(stat) do {} while (0)
60466 #define fscache_stat_d(stat) do {} while (0)
60467 #endif
60468
60469 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60470 index d3b4539..ed0c659 100644
60471 --- a/fs/fscache/object.c
60472 +++ b/fs/fscache/object.c
60473 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60474 _debug("LOOKUP \"%s\" in \"%s\"",
60475 cookie->def->name, object->cache->tag->name);
60476
60477 - fscache_stat(&fscache_n_object_lookups);
60478 + fscache_stat_unchecked(&fscache_n_object_lookups);
60479 fscache_stat(&fscache_n_cop_lookup_object);
60480 ret = object->cache->ops->lookup_object(object);
60481 fscache_stat_d(&fscache_n_cop_lookup_object);
60482 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60483 if (ret == -ETIMEDOUT) {
60484 /* probably stuck behind another object, so move this one to
60485 * the back of the queue */
60486 - fscache_stat(&fscache_n_object_lookups_timed_out);
60487 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60488 _leave(" [timeout]");
60489 return NO_TRANSIT;
60490 }
60491 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60492 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60493
60494 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60495 - fscache_stat(&fscache_n_object_lookups_negative);
60496 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60497
60498 /* Allow write requests to begin stacking up and read requests to begin
60499 * returning ENODATA.
60500 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60501 /* if we were still looking up, then we must have a positive lookup
60502 * result, in which case there may be data available */
60503 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60504 - fscache_stat(&fscache_n_object_lookups_positive);
60505 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60506
60507 /* We do (presumably) have data */
60508 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60509 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60510 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60511 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60512 } else {
60513 - fscache_stat(&fscache_n_object_created);
60514 + fscache_stat_unchecked(&fscache_n_object_created);
60515 }
60516
60517 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60518 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60519 fscache_stat_d(&fscache_n_cop_lookup_complete);
60520
60521 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60522 - fscache_stat(&fscache_n_object_avail);
60523 + fscache_stat_unchecked(&fscache_n_object_avail);
60524
60525 _leave("");
60526 return transit_to(JUMPSTART_DEPS);
60527 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60528
60529 /* this just shifts the object release to the work processor */
60530 fscache_put_object(object);
60531 - fscache_stat(&fscache_n_object_dead);
60532 + fscache_stat_unchecked(&fscache_n_object_dead);
60533
60534 _leave("");
60535 return transit_to(OBJECT_DEAD);
60536 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60537 enum fscache_checkaux result;
60538
60539 if (!object->cookie->def->check_aux) {
60540 - fscache_stat(&fscache_n_checkaux_none);
60541 + fscache_stat_unchecked(&fscache_n_checkaux_none);
60542 return FSCACHE_CHECKAUX_OKAY;
60543 }
60544
60545 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60546 switch (result) {
60547 /* entry okay as is */
60548 case FSCACHE_CHECKAUX_OKAY:
60549 - fscache_stat(&fscache_n_checkaux_okay);
60550 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
60551 break;
60552
60553 /* entry requires update */
60554 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60555 - fscache_stat(&fscache_n_checkaux_update);
60556 + fscache_stat_unchecked(&fscache_n_checkaux_update);
60557 break;
60558
60559 /* entry requires deletion */
60560 case FSCACHE_CHECKAUX_OBSOLETE:
60561 - fscache_stat(&fscache_n_checkaux_obsolete);
60562 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60563 break;
60564
60565 default:
60566 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60567 {
60568 const struct fscache_state *s;
60569
60570 - fscache_stat(&fscache_n_invalidates_run);
60571 + fscache_stat_unchecked(&fscache_n_invalidates_run);
60572 fscache_stat(&fscache_n_cop_invalidate_object);
60573 s = _fscache_invalidate_object(object, event);
60574 fscache_stat_d(&fscache_n_cop_invalidate_object);
60575 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60576 {
60577 _enter("{OBJ%x},%d", object->debug_id, event);
60578
60579 - fscache_stat(&fscache_n_updates_run);
60580 + fscache_stat_unchecked(&fscache_n_updates_run);
60581 fscache_stat(&fscache_n_cop_update_object);
60582 object->cache->ops->update_object(object);
60583 fscache_stat_d(&fscache_n_cop_update_object);
60584 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60585 index 318071a..379938b 100644
60586 --- a/fs/fscache/operation.c
60587 +++ b/fs/fscache/operation.c
60588 @@ -17,7 +17,7 @@
60589 #include <linux/slab.h>
60590 #include "internal.h"
60591
60592 -atomic_t fscache_op_debug_id;
60593 +atomic_unchecked_t fscache_op_debug_id;
60594 EXPORT_SYMBOL(fscache_op_debug_id);
60595
60596 /**
60597 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60598 ASSERTCMP(atomic_read(&op->usage), >, 0);
60599 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60600
60601 - fscache_stat(&fscache_n_op_enqueue);
60602 + fscache_stat_unchecked(&fscache_n_op_enqueue);
60603 switch (op->flags & FSCACHE_OP_TYPE) {
60604 case FSCACHE_OP_ASYNC:
60605 _debug("queue async");
60606 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60607 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60608 if (op->processor)
60609 fscache_enqueue_operation(op);
60610 - fscache_stat(&fscache_n_op_run);
60611 + fscache_stat_unchecked(&fscache_n_op_run);
60612 }
60613
60614 /*
60615 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60616 if (object->n_in_progress > 0) {
60617 atomic_inc(&op->usage);
60618 list_add_tail(&op->pend_link, &object->pending_ops);
60619 - fscache_stat(&fscache_n_op_pend);
60620 + fscache_stat_unchecked(&fscache_n_op_pend);
60621 } else if (!list_empty(&object->pending_ops)) {
60622 atomic_inc(&op->usage);
60623 list_add_tail(&op->pend_link, &object->pending_ops);
60624 - fscache_stat(&fscache_n_op_pend);
60625 + fscache_stat_unchecked(&fscache_n_op_pend);
60626 fscache_start_operations(object);
60627 } else {
60628 ASSERTCMP(object->n_in_progress, ==, 0);
60629 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60630 object->n_exclusive++; /* reads and writes must wait */
60631 atomic_inc(&op->usage);
60632 list_add_tail(&op->pend_link, &object->pending_ops);
60633 - fscache_stat(&fscache_n_op_pend);
60634 + fscache_stat_unchecked(&fscache_n_op_pend);
60635 ret = 0;
60636 } else {
60637 /* If we're in any other state, there must have been an I/O
60638 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60639 if (object->n_exclusive > 0) {
60640 atomic_inc(&op->usage);
60641 list_add_tail(&op->pend_link, &object->pending_ops);
60642 - fscache_stat(&fscache_n_op_pend);
60643 + fscache_stat_unchecked(&fscache_n_op_pend);
60644 } else if (!list_empty(&object->pending_ops)) {
60645 atomic_inc(&op->usage);
60646 list_add_tail(&op->pend_link, &object->pending_ops);
60647 - fscache_stat(&fscache_n_op_pend);
60648 + fscache_stat_unchecked(&fscache_n_op_pend);
60649 fscache_start_operations(object);
60650 } else {
60651 ASSERTCMP(object->n_exclusive, ==, 0);
60652 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60653 object->n_ops++;
60654 atomic_inc(&op->usage);
60655 list_add_tail(&op->pend_link, &object->pending_ops);
60656 - fscache_stat(&fscache_n_op_pend);
60657 + fscache_stat_unchecked(&fscache_n_op_pend);
60658 ret = 0;
60659 } else if (fscache_object_is_dying(object)) {
60660 - fscache_stat(&fscache_n_op_rejected);
60661 + fscache_stat_unchecked(&fscache_n_op_rejected);
60662 op->state = FSCACHE_OP_ST_CANCELLED;
60663 ret = -ENOBUFS;
60664 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60665 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60666 ret = -EBUSY;
60667 if (op->state == FSCACHE_OP_ST_PENDING) {
60668 ASSERT(!list_empty(&op->pend_link));
60669 - fscache_stat(&fscache_n_op_cancelled);
60670 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60671 list_del_init(&op->pend_link);
60672 if (do_cancel)
60673 do_cancel(op);
60674 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60675 while (!list_empty(&object->pending_ops)) {
60676 op = list_entry(object->pending_ops.next,
60677 struct fscache_operation, pend_link);
60678 - fscache_stat(&fscache_n_op_cancelled);
60679 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60680 list_del_init(&op->pend_link);
60681
60682 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60683 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60684 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60685 op->state = FSCACHE_OP_ST_DEAD;
60686
60687 - fscache_stat(&fscache_n_op_release);
60688 + fscache_stat_unchecked(&fscache_n_op_release);
60689
60690 if (op->release) {
60691 op->release(op);
60692 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60693 * lock, and defer it otherwise */
60694 if (!spin_trylock(&object->lock)) {
60695 _debug("defer put");
60696 - fscache_stat(&fscache_n_op_deferred_release);
60697 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
60698
60699 cache = object->cache;
60700 spin_lock(&cache->op_gc_list_lock);
60701 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60702
60703 _debug("GC DEFERRED REL OBJ%x OP%x",
60704 object->debug_id, op->debug_id);
60705 - fscache_stat(&fscache_n_op_gc);
60706 + fscache_stat_unchecked(&fscache_n_op_gc);
60707
60708 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60709 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60710 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60711 index 7f5c658..6c1e164 100644
60712 --- a/fs/fscache/page.c
60713 +++ b/fs/fscache/page.c
60714 @@ -61,7 +61,7 @@ try_again:
60715 val = radix_tree_lookup(&cookie->stores, page->index);
60716 if (!val) {
60717 rcu_read_unlock();
60718 - fscache_stat(&fscache_n_store_vmscan_not_storing);
60719 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60720 __fscache_uncache_page(cookie, page);
60721 return true;
60722 }
60723 @@ -91,11 +91,11 @@ try_again:
60724 spin_unlock(&cookie->stores_lock);
60725
60726 if (xpage) {
60727 - fscache_stat(&fscache_n_store_vmscan_cancelled);
60728 - fscache_stat(&fscache_n_store_radix_deletes);
60729 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60730 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60731 ASSERTCMP(xpage, ==, page);
60732 } else {
60733 - fscache_stat(&fscache_n_store_vmscan_gone);
60734 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60735 }
60736
60737 wake_up_bit(&cookie->flags, 0);
60738 @@ -110,11 +110,11 @@ page_busy:
60739 * sleeping on memory allocation, so we may need to impose a timeout
60740 * too. */
60741 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60742 - fscache_stat(&fscache_n_store_vmscan_busy);
60743 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60744 return false;
60745 }
60746
60747 - fscache_stat(&fscache_n_store_vmscan_wait);
60748 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60749 __fscache_wait_on_page_write(cookie, page);
60750 gfp &= ~__GFP_WAIT;
60751 goto try_again;
60752 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60753 FSCACHE_COOKIE_STORING_TAG);
60754 if (!radix_tree_tag_get(&cookie->stores, page->index,
60755 FSCACHE_COOKIE_PENDING_TAG)) {
60756 - fscache_stat(&fscache_n_store_radix_deletes);
60757 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60758 xpage = radix_tree_delete(&cookie->stores, page->index);
60759 }
60760 spin_unlock(&cookie->stores_lock);
60761 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60762
60763 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60764
60765 - fscache_stat(&fscache_n_attr_changed_calls);
60766 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60767
60768 if (fscache_object_is_active(object)) {
60769 fscache_stat(&fscache_n_cop_attr_changed);
60770 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60771
60772 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60773
60774 - fscache_stat(&fscache_n_attr_changed);
60775 + fscache_stat_unchecked(&fscache_n_attr_changed);
60776
60777 op = kzalloc(sizeof(*op), GFP_KERNEL);
60778 if (!op) {
60779 - fscache_stat(&fscache_n_attr_changed_nomem);
60780 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60781 _leave(" = -ENOMEM");
60782 return -ENOMEM;
60783 }
60784 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60785 if (fscache_submit_exclusive_op(object, op) < 0)
60786 goto nobufs;
60787 spin_unlock(&cookie->lock);
60788 - fscache_stat(&fscache_n_attr_changed_ok);
60789 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60790 fscache_put_operation(op);
60791 _leave(" = 0");
60792 return 0;
60793 @@ -225,7 +225,7 @@ nobufs:
60794 kfree(op);
60795 if (wake_cookie)
60796 __fscache_wake_unused_cookie(cookie);
60797 - fscache_stat(&fscache_n_attr_changed_nobufs);
60798 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60799 _leave(" = %d", -ENOBUFS);
60800 return -ENOBUFS;
60801 }
60802 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60803 /* allocate a retrieval operation and attempt to submit it */
60804 op = kzalloc(sizeof(*op), GFP_NOIO);
60805 if (!op) {
60806 - fscache_stat(&fscache_n_retrievals_nomem);
60807 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60808 return NULL;
60809 }
60810
60811 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60812 return 0;
60813 }
60814
60815 - fscache_stat(&fscache_n_retrievals_wait);
60816 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60817
60818 jif = jiffies;
60819 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60820 fscache_wait_bit_interruptible,
60821 TASK_INTERRUPTIBLE) != 0) {
60822 - fscache_stat(&fscache_n_retrievals_intr);
60823 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60824 _leave(" = -ERESTARTSYS");
60825 return -ERESTARTSYS;
60826 }
60827 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60828 */
60829 int fscache_wait_for_operation_activation(struct fscache_object *object,
60830 struct fscache_operation *op,
60831 - atomic_t *stat_op_waits,
60832 - atomic_t *stat_object_dead,
60833 + atomic_unchecked_t *stat_op_waits,
60834 + atomic_unchecked_t *stat_object_dead,
60835 void (*do_cancel)(struct fscache_operation *))
60836 {
60837 int ret;
60838 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60839
60840 _debug(">>> WT");
60841 if (stat_op_waits)
60842 - fscache_stat(stat_op_waits);
60843 + fscache_stat_unchecked(stat_op_waits);
60844 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60845 fscache_wait_bit_interruptible,
60846 TASK_INTERRUPTIBLE) != 0) {
60847 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60848 check_if_dead:
60849 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60850 if (stat_object_dead)
60851 - fscache_stat(stat_object_dead);
60852 + fscache_stat_unchecked(stat_object_dead);
60853 _leave(" = -ENOBUFS [cancelled]");
60854 return -ENOBUFS;
60855 }
60856 @@ -366,7 +366,7 @@ check_if_dead:
60857 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60858 fscache_cancel_op(op, do_cancel);
60859 if (stat_object_dead)
60860 - fscache_stat(stat_object_dead);
60861 + fscache_stat_unchecked(stat_object_dead);
60862 return -ENOBUFS;
60863 }
60864 return 0;
60865 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60866
60867 _enter("%p,%p,,,", cookie, page);
60868
60869 - fscache_stat(&fscache_n_retrievals);
60870 + fscache_stat_unchecked(&fscache_n_retrievals);
60871
60872 if (hlist_empty(&cookie->backing_objects))
60873 goto nobufs;
60874 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60875 goto nobufs_unlock_dec;
60876 spin_unlock(&cookie->lock);
60877
60878 - fscache_stat(&fscache_n_retrieval_ops);
60879 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60880
60881 /* pin the netfs read context in case we need to do the actual netfs
60882 * read because we've encountered a cache read failure */
60883 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60884
60885 error:
60886 if (ret == -ENOMEM)
60887 - fscache_stat(&fscache_n_retrievals_nomem);
60888 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60889 else if (ret == -ERESTARTSYS)
60890 - fscache_stat(&fscache_n_retrievals_intr);
60891 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60892 else if (ret == -ENODATA)
60893 - fscache_stat(&fscache_n_retrievals_nodata);
60894 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60895 else if (ret < 0)
60896 - fscache_stat(&fscache_n_retrievals_nobufs);
60897 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60898 else
60899 - fscache_stat(&fscache_n_retrievals_ok);
60900 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60901
60902 fscache_put_retrieval(op);
60903 _leave(" = %d", ret);
60904 @@ -490,7 +490,7 @@ nobufs_unlock:
60905 __fscache_wake_unused_cookie(cookie);
60906 kfree(op);
60907 nobufs:
60908 - fscache_stat(&fscache_n_retrievals_nobufs);
60909 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60910 _leave(" = -ENOBUFS");
60911 return -ENOBUFS;
60912 }
60913 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60914
60915 _enter("%p,,%d,,,", cookie, *nr_pages);
60916
60917 - fscache_stat(&fscache_n_retrievals);
60918 + fscache_stat_unchecked(&fscache_n_retrievals);
60919
60920 if (hlist_empty(&cookie->backing_objects))
60921 goto nobufs;
60922 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60923 goto nobufs_unlock_dec;
60924 spin_unlock(&cookie->lock);
60925
60926 - fscache_stat(&fscache_n_retrieval_ops);
60927 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60928
60929 /* pin the netfs read context in case we need to do the actual netfs
60930 * read because we've encountered a cache read failure */
60931 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60932
60933 error:
60934 if (ret == -ENOMEM)
60935 - fscache_stat(&fscache_n_retrievals_nomem);
60936 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60937 else if (ret == -ERESTARTSYS)
60938 - fscache_stat(&fscache_n_retrievals_intr);
60939 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60940 else if (ret == -ENODATA)
60941 - fscache_stat(&fscache_n_retrievals_nodata);
60942 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60943 else if (ret < 0)
60944 - fscache_stat(&fscache_n_retrievals_nobufs);
60945 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60946 else
60947 - fscache_stat(&fscache_n_retrievals_ok);
60948 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60949
60950 fscache_put_retrieval(op);
60951 _leave(" = %d", ret);
60952 @@ -621,7 +621,7 @@ nobufs_unlock:
60953 if (wake_cookie)
60954 __fscache_wake_unused_cookie(cookie);
60955 nobufs:
60956 - fscache_stat(&fscache_n_retrievals_nobufs);
60957 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60958 _leave(" = -ENOBUFS");
60959 return -ENOBUFS;
60960 }
60961 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60962
60963 _enter("%p,%p,,,", cookie, page);
60964
60965 - fscache_stat(&fscache_n_allocs);
60966 + fscache_stat_unchecked(&fscache_n_allocs);
60967
60968 if (hlist_empty(&cookie->backing_objects))
60969 goto nobufs;
60970 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60971 goto nobufs_unlock_dec;
60972 spin_unlock(&cookie->lock);
60973
60974 - fscache_stat(&fscache_n_alloc_ops);
60975 + fscache_stat_unchecked(&fscache_n_alloc_ops);
60976
60977 ret = fscache_wait_for_operation_activation(
60978 object, &op->op,
60979 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60980
60981 error:
60982 if (ret == -ERESTARTSYS)
60983 - fscache_stat(&fscache_n_allocs_intr);
60984 + fscache_stat_unchecked(&fscache_n_allocs_intr);
60985 else if (ret < 0)
60986 - fscache_stat(&fscache_n_allocs_nobufs);
60987 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60988 else
60989 - fscache_stat(&fscache_n_allocs_ok);
60990 + fscache_stat_unchecked(&fscache_n_allocs_ok);
60991
60992 fscache_put_retrieval(op);
60993 _leave(" = %d", ret);
60994 @@ -715,7 +715,7 @@ nobufs_unlock:
60995 if (wake_cookie)
60996 __fscache_wake_unused_cookie(cookie);
60997 nobufs:
60998 - fscache_stat(&fscache_n_allocs_nobufs);
60999 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
61000 _leave(" = -ENOBUFS");
61001 return -ENOBUFS;
61002 }
61003 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61004
61005 spin_lock(&cookie->stores_lock);
61006
61007 - fscache_stat(&fscache_n_store_calls);
61008 + fscache_stat_unchecked(&fscache_n_store_calls);
61009
61010 /* find a page to store */
61011 page = NULL;
61012 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61013 page = results[0];
61014 _debug("gang %d [%lx]", n, page->index);
61015 if (page->index > op->store_limit) {
61016 - fscache_stat(&fscache_n_store_pages_over_limit);
61017 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
61018 goto superseded;
61019 }
61020
61021 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
61022 spin_unlock(&cookie->stores_lock);
61023 spin_unlock(&object->lock);
61024
61025 - fscache_stat(&fscache_n_store_pages);
61026 + fscache_stat_unchecked(&fscache_n_store_pages);
61027 fscache_stat(&fscache_n_cop_write_page);
61028 ret = object->cache->ops->write_page(op, page);
61029 fscache_stat_d(&fscache_n_cop_write_page);
61030 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61031 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61032 ASSERT(PageFsCache(page));
61033
61034 - fscache_stat(&fscache_n_stores);
61035 + fscache_stat_unchecked(&fscache_n_stores);
61036
61037 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
61038 _leave(" = -ENOBUFS [invalidating]");
61039 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61040 spin_unlock(&cookie->stores_lock);
61041 spin_unlock(&object->lock);
61042
61043 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
61044 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61045 op->store_limit = object->store_limit;
61046
61047 __fscache_use_cookie(cookie);
61048 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61049
61050 spin_unlock(&cookie->lock);
61051 radix_tree_preload_end();
61052 - fscache_stat(&fscache_n_store_ops);
61053 - fscache_stat(&fscache_n_stores_ok);
61054 + fscache_stat_unchecked(&fscache_n_store_ops);
61055 + fscache_stat_unchecked(&fscache_n_stores_ok);
61056
61057 /* the work queue now carries its own ref on the object */
61058 fscache_put_operation(&op->op);
61059 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61060 return 0;
61061
61062 already_queued:
61063 - fscache_stat(&fscache_n_stores_again);
61064 + fscache_stat_unchecked(&fscache_n_stores_again);
61065 already_pending:
61066 spin_unlock(&cookie->stores_lock);
61067 spin_unlock(&object->lock);
61068 spin_unlock(&cookie->lock);
61069 radix_tree_preload_end();
61070 kfree(op);
61071 - fscache_stat(&fscache_n_stores_ok);
61072 + fscache_stat_unchecked(&fscache_n_stores_ok);
61073 _leave(" = 0");
61074 return 0;
61075
61076 @@ -1024,14 +1024,14 @@ nobufs:
61077 kfree(op);
61078 if (wake_cookie)
61079 __fscache_wake_unused_cookie(cookie);
61080 - fscache_stat(&fscache_n_stores_nobufs);
61081 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
61082 _leave(" = -ENOBUFS");
61083 return -ENOBUFS;
61084
61085 nomem_free:
61086 kfree(op);
61087 nomem:
61088 - fscache_stat(&fscache_n_stores_oom);
61089 + fscache_stat_unchecked(&fscache_n_stores_oom);
61090 _leave(" = -ENOMEM");
61091 return -ENOMEM;
61092 }
61093 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
61094 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61095 ASSERTCMP(page, !=, NULL);
61096
61097 - fscache_stat(&fscache_n_uncaches);
61098 + fscache_stat_unchecked(&fscache_n_uncaches);
61099
61100 /* cache withdrawal may beat us to it */
61101 if (!PageFsCache(page))
61102 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
61103 struct fscache_cookie *cookie = op->op.object->cookie;
61104
61105 #ifdef CONFIG_FSCACHE_STATS
61106 - atomic_inc(&fscache_n_marks);
61107 + atomic_inc_unchecked(&fscache_n_marks);
61108 #endif
61109
61110 _debug("- mark %p{%lx}", page, page->index);
61111 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
61112 index 40d13c7..ddf52b9 100644
61113 --- a/fs/fscache/stats.c
61114 +++ b/fs/fscache/stats.c
61115 @@ -18,99 +18,99 @@
61116 /*
61117 * operation counters
61118 */
61119 -atomic_t fscache_n_op_pend;
61120 -atomic_t fscache_n_op_run;
61121 -atomic_t fscache_n_op_enqueue;
61122 -atomic_t fscache_n_op_requeue;
61123 -atomic_t fscache_n_op_deferred_release;
61124 -atomic_t fscache_n_op_release;
61125 -atomic_t fscache_n_op_gc;
61126 -atomic_t fscache_n_op_cancelled;
61127 -atomic_t fscache_n_op_rejected;
61128 +atomic_unchecked_t fscache_n_op_pend;
61129 +atomic_unchecked_t fscache_n_op_run;
61130 +atomic_unchecked_t fscache_n_op_enqueue;
61131 +atomic_unchecked_t fscache_n_op_requeue;
61132 +atomic_unchecked_t fscache_n_op_deferred_release;
61133 +atomic_unchecked_t fscache_n_op_release;
61134 +atomic_unchecked_t fscache_n_op_gc;
61135 +atomic_unchecked_t fscache_n_op_cancelled;
61136 +atomic_unchecked_t fscache_n_op_rejected;
61137
61138 -atomic_t fscache_n_attr_changed;
61139 -atomic_t fscache_n_attr_changed_ok;
61140 -atomic_t fscache_n_attr_changed_nobufs;
61141 -atomic_t fscache_n_attr_changed_nomem;
61142 -atomic_t fscache_n_attr_changed_calls;
61143 +atomic_unchecked_t fscache_n_attr_changed;
61144 +atomic_unchecked_t fscache_n_attr_changed_ok;
61145 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
61146 +atomic_unchecked_t fscache_n_attr_changed_nomem;
61147 +atomic_unchecked_t fscache_n_attr_changed_calls;
61148
61149 -atomic_t fscache_n_allocs;
61150 -atomic_t fscache_n_allocs_ok;
61151 -atomic_t fscache_n_allocs_wait;
61152 -atomic_t fscache_n_allocs_nobufs;
61153 -atomic_t fscache_n_allocs_intr;
61154 -atomic_t fscache_n_allocs_object_dead;
61155 -atomic_t fscache_n_alloc_ops;
61156 -atomic_t fscache_n_alloc_op_waits;
61157 +atomic_unchecked_t fscache_n_allocs;
61158 +atomic_unchecked_t fscache_n_allocs_ok;
61159 +atomic_unchecked_t fscache_n_allocs_wait;
61160 +atomic_unchecked_t fscache_n_allocs_nobufs;
61161 +atomic_unchecked_t fscache_n_allocs_intr;
61162 +atomic_unchecked_t fscache_n_allocs_object_dead;
61163 +atomic_unchecked_t fscache_n_alloc_ops;
61164 +atomic_unchecked_t fscache_n_alloc_op_waits;
61165
61166 -atomic_t fscache_n_retrievals;
61167 -atomic_t fscache_n_retrievals_ok;
61168 -atomic_t fscache_n_retrievals_wait;
61169 -atomic_t fscache_n_retrievals_nodata;
61170 -atomic_t fscache_n_retrievals_nobufs;
61171 -atomic_t fscache_n_retrievals_intr;
61172 -atomic_t fscache_n_retrievals_nomem;
61173 -atomic_t fscache_n_retrievals_object_dead;
61174 -atomic_t fscache_n_retrieval_ops;
61175 -atomic_t fscache_n_retrieval_op_waits;
61176 +atomic_unchecked_t fscache_n_retrievals;
61177 +atomic_unchecked_t fscache_n_retrievals_ok;
61178 +atomic_unchecked_t fscache_n_retrievals_wait;
61179 +atomic_unchecked_t fscache_n_retrievals_nodata;
61180 +atomic_unchecked_t fscache_n_retrievals_nobufs;
61181 +atomic_unchecked_t fscache_n_retrievals_intr;
61182 +atomic_unchecked_t fscache_n_retrievals_nomem;
61183 +atomic_unchecked_t fscache_n_retrievals_object_dead;
61184 +atomic_unchecked_t fscache_n_retrieval_ops;
61185 +atomic_unchecked_t fscache_n_retrieval_op_waits;
61186
61187 -atomic_t fscache_n_stores;
61188 -atomic_t fscache_n_stores_ok;
61189 -atomic_t fscache_n_stores_again;
61190 -atomic_t fscache_n_stores_nobufs;
61191 -atomic_t fscache_n_stores_oom;
61192 -atomic_t fscache_n_store_ops;
61193 -atomic_t fscache_n_store_calls;
61194 -atomic_t fscache_n_store_pages;
61195 -atomic_t fscache_n_store_radix_deletes;
61196 -atomic_t fscache_n_store_pages_over_limit;
61197 +atomic_unchecked_t fscache_n_stores;
61198 +atomic_unchecked_t fscache_n_stores_ok;
61199 +atomic_unchecked_t fscache_n_stores_again;
61200 +atomic_unchecked_t fscache_n_stores_nobufs;
61201 +atomic_unchecked_t fscache_n_stores_oom;
61202 +atomic_unchecked_t fscache_n_store_ops;
61203 +atomic_unchecked_t fscache_n_store_calls;
61204 +atomic_unchecked_t fscache_n_store_pages;
61205 +atomic_unchecked_t fscache_n_store_radix_deletes;
61206 +atomic_unchecked_t fscache_n_store_pages_over_limit;
61207
61208 -atomic_t fscache_n_store_vmscan_not_storing;
61209 -atomic_t fscache_n_store_vmscan_gone;
61210 -atomic_t fscache_n_store_vmscan_busy;
61211 -atomic_t fscache_n_store_vmscan_cancelled;
61212 -atomic_t fscache_n_store_vmscan_wait;
61213 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
61214 +atomic_unchecked_t fscache_n_store_vmscan_gone;
61215 +atomic_unchecked_t fscache_n_store_vmscan_busy;
61216 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
61217 +atomic_unchecked_t fscache_n_store_vmscan_wait;
61218
61219 -atomic_t fscache_n_marks;
61220 -atomic_t fscache_n_uncaches;
61221 +atomic_unchecked_t fscache_n_marks;
61222 +atomic_unchecked_t fscache_n_uncaches;
61223
61224 -atomic_t fscache_n_acquires;
61225 -atomic_t fscache_n_acquires_null;
61226 -atomic_t fscache_n_acquires_no_cache;
61227 -atomic_t fscache_n_acquires_ok;
61228 -atomic_t fscache_n_acquires_nobufs;
61229 -atomic_t fscache_n_acquires_oom;
61230 +atomic_unchecked_t fscache_n_acquires;
61231 +atomic_unchecked_t fscache_n_acquires_null;
61232 +atomic_unchecked_t fscache_n_acquires_no_cache;
61233 +atomic_unchecked_t fscache_n_acquires_ok;
61234 +atomic_unchecked_t fscache_n_acquires_nobufs;
61235 +atomic_unchecked_t fscache_n_acquires_oom;
61236
61237 -atomic_t fscache_n_invalidates;
61238 -atomic_t fscache_n_invalidates_run;
61239 +atomic_unchecked_t fscache_n_invalidates;
61240 +atomic_unchecked_t fscache_n_invalidates_run;
61241
61242 -atomic_t fscache_n_updates;
61243 -atomic_t fscache_n_updates_null;
61244 -atomic_t fscache_n_updates_run;
61245 +atomic_unchecked_t fscache_n_updates;
61246 +atomic_unchecked_t fscache_n_updates_null;
61247 +atomic_unchecked_t fscache_n_updates_run;
61248
61249 -atomic_t fscache_n_relinquishes;
61250 -atomic_t fscache_n_relinquishes_null;
61251 -atomic_t fscache_n_relinquishes_waitcrt;
61252 -atomic_t fscache_n_relinquishes_retire;
61253 +atomic_unchecked_t fscache_n_relinquishes;
61254 +atomic_unchecked_t fscache_n_relinquishes_null;
61255 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61256 +atomic_unchecked_t fscache_n_relinquishes_retire;
61257
61258 -atomic_t fscache_n_cookie_index;
61259 -atomic_t fscache_n_cookie_data;
61260 -atomic_t fscache_n_cookie_special;
61261 +atomic_unchecked_t fscache_n_cookie_index;
61262 +atomic_unchecked_t fscache_n_cookie_data;
61263 +atomic_unchecked_t fscache_n_cookie_special;
61264
61265 -atomic_t fscache_n_object_alloc;
61266 -atomic_t fscache_n_object_no_alloc;
61267 -atomic_t fscache_n_object_lookups;
61268 -atomic_t fscache_n_object_lookups_negative;
61269 -atomic_t fscache_n_object_lookups_positive;
61270 -atomic_t fscache_n_object_lookups_timed_out;
61271 -atomic_t fscache_n_object_created;
61272 -atomic_t fscache_n_object_avail;
61273 -atomic_t fscache_n_object_dead;
61274 +atomic_unchecked_t fscache_n_object_alloc;
61275 +atomic_unchecked_t fscache_n_object_no_alloc;
61276 +atomic_unchecked_t fscache_n_object_lookups;
61277 +atomic_unchecked_t fscache_n_object_lookups_negative;
61278 +atomic_unchecked_t fscache_n_object_lookups_positive;
61279 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
61280 +atomic_unchecked_t fscache_n_object_created;
61281 +atomic_unchecked_t fscache_n_object_avail;
61282 +atomic_unchecked_t fscache_n_object_dead;
61283
61284 -atomic_t fscache_n_checkaux_none;
61285 -atomic_t fscache_n_checkaux_okay;
61286 -atomic_t fscache_n_checkaux_update;
61287 -atomic_t fscache_n_checkaux_obsolete;
61288 +atomic_unchecked_t fscache_n_checkaux_none;
61289 +atomic_unchecked_t fscache_n_checkaux_okay;
61290 +atomic_unchecked_t fscache_n_checkaux_update;
61291 +atomic_unchecked_t fscache_n_checkaux_obsolete;
61292
61293 atomic_t fscache_n_cop_alloc_object;
61294 atomic_t fscache_n_cop_lookup_object;
61295 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61296 seq_puts(m, "FS-Cache statistics\n");
61297
61298 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61299 - atomic_read(&fscache_n_cookie_index),
61300 - atomic_read(&fscache_n_cookie_data),
61301 - atomic_read(&fscache_n_cookie_special));
61302 + atomic_read_unchecked(&fscache_n_cookie_index),
61303 + atomic_read_unchecked(&fscache_n_cookie_data),
61304 + atomic_read_unchecked(&fscache_n_cookie_special));
61305
61306 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61307 - atomic_read(&fscache_n_object_alloc),
61308 - atomic_read(&fscache_n_object_no_alloc),
61309 - atomic_read(&fscache_n_object_avail),
61310 - atomic_read(&fscache_n_object_dead));
61311 + atomic_read_unchecked(&fscache_n_object_alloc),
61312 + atomic_read_unchecked(&fscache_n_object_no_alloc),
61313 + atomic_read_unchecked(&fscache_n_object_avail),
61314 + atomic_read_unchecked(&fscache_n_object_dead));
61315 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61316 - atomic_read(&fscache_n_checkaux_none),
61317 - atomic_read(&fscache_n_checkaux_okay),
61318 - atomic_read(&fscache_n_checkaux_update),
61319 - atomic_read(&fscache_n_checkaux_obsolete));
61320 + atomic_read_unchecked(&fscache_n_checkaux_none),
61321 + atomic_read_unchecked(&fscache_n_checkaux_okay),
61322 + atomic_read_unchecked(&fscache_n_checkaux_update),
61323 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61324
61325 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61326 - atomic_read(&fscache_n_marks),
61327 - atomic_read(&fscache_n_uncaches));
61328 + atomic_read_unchecked(&fscache_n_marks),
61329 + atomic_read_unchecked(&fscache_n_uncaches));
61330
61331 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61332 " oom=%u\n",
61333 - atomic_read(&fscache_n_acquires),
61334 - atomic_read(&fscache_n_acquires_null),
61335 - atomic_read(&fscache_n_acquires_no_cache),
61336 - atomic_read(&fscache_n_acquires_ok),
61337 - atomic_read(&fscache_n_acquires_nobufs),
61338 - atomic_read(&fscache_n_acquires_oom));
61339 + atomic_read_unchecked(&fscache_n_acquires),
61340 + atomic_read_unchecked(&fscache_n_acquires_null),
61341 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
61342 + atomic_read_unchecked(&fscache_n_acquires_ok),
61343 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
61344 + atomic_read_unchecked(&fscache_n_acquires_oom));
61345
61346 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61347 - atomic_read(&fscache_n_object_lookups),
61348 - atomic_read(&fscache_n_object_lookups_negative),
61349 - atomic_read(&fscache_n_object_lookups_positive),
61350 - atomic_read(&fscache_n_object_created),
61351 - atomic_read(&fscache_n_object_lookups_timed_out));
61352 + atomic_read_unchecked(&fscache_n_object_lookups),
61353 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
61354 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
61355 + atomic_read_unchecked(&fscache_n_object_created),
61356 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61357
61358 seq_printf(m, "Invals : n=%u run=%u\n",
61359 - atomic_read(&fscache_n_invalidates),
61360 - atomic_read(&fscache_n_invalidates_run));
61361 + atomic_read_unchecked(&fscache_n_invalidates),
61362 + atomic_read_unchecked(&fscache_n_invalidates_run));
61363
61364 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61365 - atomic_read(&fscache_n_updates),
61366 - atomic_read(&fscache_n_updates_null),
61367 - atomic_read(&fscache_n_updates_run));
61368 + atomic_read_unchecked(&fscache_n_updates),
61369 + atomic_read_unchecked(&fscache_n_updates_null),
61370 + atomic_read_unchecked(&fscache_n_updates_run));
61371
61372 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61373 - atomic_read(&fscache_n_relinquishes),
61374 - atomic_read(&fscache_n_relinquishes_null),
61375 - atomic_read(&fscache_n_relinquishes_waitcrt),
61376 - atomic_read(&fscache_n_relinquishes_retire));
61377 + atomic_read_unchecked(&fscache_n_relinquishes),
61378 + atomic_read_unchecked(&fscache_n_relinquishes_null),
61379 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61380 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
61381
61382 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61383 - atomic_read(&fscache_n_attr_changed),
61384 - atomic_read(&fscache_n_attr_changed_ok),
61385 - atomic_read(&fscache_n_attr_changed_nobufs),
61386 - atomic_read(&fscache_n_attr_changed_nomem),
61387 - atomic_read(&fscache_n_attr_changed_calls));
61388 + atomic_read_unchecked(&fscache_n_attr_changed),
61389 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
61390 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61391 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61392 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
61393
61394 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61395 - atomic_read(&fscache_n_allocs),
61396 - atomic_read(&fscache_n_allocs_ok),
61397 - atomic_read(&fscache_n_allocs_wait),
61398 - atomic_read(&fscache_n_allocs_nobufs),
61399 - atomic_read(&fscache_n_allocs_intr));
61400 + atomic_read_unchecked(&fscache_n_allocs),
61401 + atomic_read_unchecked(&fscache_n_allocs_ok),
61402 + atomic_read_unchecked(&fscache_n_allocs_wait),
61403 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
61404 + atomic_read_unchecked(&fscache_n_allocs_intr));
61405 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61406 - atomic_read(&fscache_n_alloc_ops),
61407 - atomic_read(&fscache_n_alloc_op_waits),
61408 - atomic_read(&fscache_n_allocs_object_dead));
61409 + atomic_read_unchecked(&fscache_n_alloc_ops),
61410 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
61411 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
61412
61413 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61414 " int=%u oom=%u\n",
61415 - atomic_read(&fscache_n_retrievals),
61416 - atomic_read(&fscache_n_retrievals_ok),
61417 - atomic_read(&fscache_n_retrievals_wait),
61418 - atomic_read(&fscache_n_retrievals_nodata),
61419 - atomic_read(&fscache_n_retrievals_nobufs),
61420 - atomic_read(&fscache_n_retrievals_intr),
61421 - atomic_read(&fscache_n_retrievals_nomem));
61422 + atomic_read_unchecked(&fscache_n_retrievals),
61423 + atomic_read_unchecked(&fscache_n_retrievals_ok),
61424 + atomic_read_unchecked(&fscache_n_retrievals_wait),
61425 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
61426 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61427 + atomic_read_unchecked(&fscache_n_retrievals_intr),
61428 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
61429 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61430 - atomic_read(&fscache_n_retrieval_ops),
61431 - atomic_read(&fscache_n_retrieval_op_waits),
61432 - atomic_read(&fscache_n_retrievals_object_dead));
61433 + atomic_read_unchecked(&fscache_n_retrieval_ops),
61434 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61435 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61436
61437 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61438 - atomic_read(&fscache_n_stores),
61439 - atomic_read(&fscache_n_stores_ok),
61440 - atomic_read(&fscache_n_stores_again),
61441 - atomic_read(&fscache_n_stores_nobufs),
61442 - atomic_read(&fscache_n_stores_oom));
61443 + atomic_read_unchecked(&fscache_n_stores),
61444 + atomic_read_unchecked(&fscache_n_stores_ok),
61445 + atomic_read_unchecked(&fscache_n_stores_again),
61446 + atomic_read_unchecked(&fscache_n_stores_nobufs),
61447 + atomic_read_unchecked(&fscache_n_stores_oom));
61448 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61449 - atomic_read(&fscache_n_store_ops),
61450 - atomic_read(&fscache_n_store_calls),
61451 - atomic_read(&fscache_n_store_pages),
61452 - atomic_read(&fscache_n_store_radix_deletes),
61453 - atomic_read(&fscache_n_store_pages_over_limit));
61454 + atomic_read_unchecked(&fscache_n_store_ops),
61455 + atomic_read_unchecked(&fscache_n_store_calls),
61456 + atomic_read_unchecked(&fscache_n_store_pages),
61457 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
61458 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61459
61460 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61461 - atomic_read(&fscache_n_store_vmscan_not_storing),
61462 - atomic_read(&fscache_n_store_vmscan_gone),
61463 - atomic_read(&fscache_n_store_vmscan_busy),
61464 - atomic_read(&fscache_n_store_vmscan_cancelled),
61465 - atomic_read(&fscache_n_store_vmscan_wait));
61466 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61467 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61468 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61469 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61470 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61471
61472 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61473 - atomic_read(&fscache_n_op_pend),
61474 - atomic_read(&fscache_n_op_run),
61475 - atomic_read(&fscache_n_op_enqueue),
61476 - atomic_read(&fscache_n_op_cancelled),
61477 - atomic_read(&fscache_n_op_rejected));
61478 + atomic_read_unchecked(&fscache_n_op_pend),
61479 + atomic_read_unchecked(&fscache_n_op_run),
61480 + atomic_read_unchecked(&fscache_n_op_enqueue),
61481 + atomic_read_unchecked(&fscache_n_op_cancelled),
61482 + atomic_read_unchecked(&fscache_n_op_rejected));
61483 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61484 - atomic_read(&fscache_n_op_deferred_release),
61485 - atomic_read(&fscache_n_op_release),
61486 - atomic_read(&fscache_n_op_gc));
61487 + atomic_read_unchecked(&fscache_n_op_deferred_release),
61488 + atomic_read_unchecked(&fscache_n_op_release),
61489 + atomic_read_unchecked(&fscache_n_op_gc));
61490
61491 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61492 atomic_read(&fscache_n_cop_alloc_object),
61493 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61494 index b96a49b..9bfdc47 100644
61495 --- a/fs/fuse/cuse.c
61496 +++ b/fs/fuse/cuse.c
61497 @@ -606,10 +606,12 @@ static int __init cuse_init(void)
61498 INIT_LIST_HEAD(&cuse_conntbl[i]);
61499
61500 /* inherit and extend fuse_dev_operations */
61501 - cuse_channel_fops = fuse_dev_operations;
61502 - cuse_channel_fops.owner = THIS_MODULE;
61503 - cuse_channel_fops.open = cuse_channel_open;
61504 - cuse_channel_fops.release = cuse_channel_release;
61505 + pax_open_kernel();
61506 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61507 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61508 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
61509 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
61510 + pax_close_kernel();
61511
61512 cuse_class = class_create(THIS_MODULE, "cuse");
61513 if (IS_ERR(cuse_class))
61514 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61515 index 0a648bb..8d463f1 100644
61516 --- a/fs/fuse/dev.c
61517 +++ b/fs/fuse/dev.c
61518 @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61519 ret = 0;
61520 pipe_lock(pipe);
61521
61522 - if (!pipe->readers) {
61523 + if (!atomic_read(&pipe->readers)) {
61524 send_sig(SIGPIPE, current, 0);
61525 if (!ret)
61526 ret = -EPIPE;
61527 @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61528 page_nr++;
61529 ret += buf->len;
61530
61531 - if (pipe->files)
61532 + if (atomic_read(&pipe->files))
61533 do_wakeup = 1;
61534 }
61535
61536 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61537 index 1d1292c..bba17ea 100644
61538 --- a/fs/fuse/dir.c
61539 +++ b/fs/fuse/dir.c
61540 @@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
61541 return link;
61542 }
61543
61544 -static void free_link(char *link)
61545 +static void free_link(const char *link)
61546 {
61547 if (!IS_ERR(link))
61548 free_page((unsigned long) link);
61549 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61550 index fe649d3..c679164 100644
61551 --- a/fs/hostfs/hostfs_kern.c
61552 +++ b/fs/hostfs/hostfs_kern.c
61553 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61554
61555 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61556 {
61557 - char *s = nd_get_link(nd);
61558 + const char *s = nd_get_link(nd);
61559 if (!IS_ERR(s))
61560 __putname(s);
61561 }
61562 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61563 index d19b30a..ef89c36 100644
61564 --- a/fs/hugetlbfs/inode.c
61565 +++ b/fs/hugetlbfs/inode.c
61566 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61567 struct mm_struct *mm = current->mm;
61568 struct vm_area_struct *vma;
61569 struct hstate *h = hstate_file(file);
61570 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61571 struct vm_unmapped_area_info info;
61572
61573 if (len & ~huge_page_mask(h))
61574 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61575 return addr;
61576 }
61577
61578 +#ifdef CONFIG_PAX_RANDMMAP
61579 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61580 +#endif
61581 +
61582 if (addr) {
61583 addr = ALIGN(addr, huge_page_size(h));
61584 vma = find_vma(mm, addr);
61585 - if (TASK_SIZE - len >= addr &&
61586 - (!vma || addr + len <= vma->vm_start))
61587 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61588 return addr;
61589 }
61590
61591 info.flags = 0;
61592 info.length = len;
61593 info.low_limit = TASK_UNMAPPED_BASE;
61594 +
61595 +#ifdef CONFIG_PAX_RANDMMAP
61596 + if (mm->pax_flags & MF_PAX_RANDMMAP)
61597 + info.low_limit += mm->delta_mmap;
61598 +#endif
61599 +
61600 info.high_limit = TASK_SIZE;
61601 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61602 info.align_offset = 0;
61603 @@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61604 };
61605 MODULE_ALIAS_FS("hugetlbfs");
61606
61607 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61608 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61609
61610 static int can_do_hugetlb_shm(void)
61611 {
61612 diff --git a/fs/inode.c b/fs/inode.c
61613 index 4bcdad3..1883822 100644
61614 --- a/fs/inode.c
61615 +++ b/fs/inode.c
61616 @@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61617
61618 #ifdef CONFIG_SMP
61619 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61620 - static atomic_t shared_last_ino;
61621 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61622 + static atomic_unchecked_t shared_last_ino;
61623 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61624
61625 res = next - LAST_INO_BATCH;
61626 }
61627 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61628 index 4a6cf28..d3a29d3 100644
61629 --- a/fs/jffs2/erase.c
61630 +++ b/fs/jffs2/erase.c
61631 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61632 struct jffs2_unknown_node marker = {
61633 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61634 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61635 - .totlen = cpu_to_je32(c->cleanmarker_size)
61636 + .totlen = cpu_to_je32(c->cleanmarker_size),
61637 + .hdr_crc = cpu_to_je32(0)
61638 };
61639
61640 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61641 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61642 index a6597d6..41b30ec 100644
61643 --- a/fs/jffs2/wbuf.c
61644 +++ b/fs/jffs2/wbuf.c
61645 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61646 {
61647 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61648 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61649 - .totlen = constant_cpu_to_je32(8)
61650 + .totlen = constant_cpu_to_je32(8),
61651 + .hdr_crc = constant_cpu_to_je32(0)
61652 };
61653
61654 /*
61655 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61656 index e2b7483..855bca3 100644
61657 --- a/fs/jfs/super.c
61658 +++ b/fs/jfs/super.c
61659 @@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
61660
61661 jfs_inode_cachep =
61662 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61663 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61664 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61665 init_once);
61666 if (jfs_inode_cachep == NULL)
61667 return -ENOMEM;
61668 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61669 index 39c0143..d54fad4 100644
61670 --- a/fs/kernfs/dir.c
61671 +++ b/fs/kernfs/dir.c
61672 @@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
61673 *
61674 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61675 */
61676 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
61677 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61678 {
61679 unsigned long hash = init_name_hash();
61680 unsigned int len = strlen(name);
61681 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61682 index dbf397b..d624b48 100644
61683 --- a/fs/kernfs/file.c
61684 +++ b/fs/kernfs/file.c
61685 @@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61686
61687 struct kernfs_open_node {
61688 atomic_t refcnt;
61689 - atomic_t event;
61690 + atomic_unchecked_t event;
61691 wait_queue_head_t poll;
61692 struct list_head files; /* goes through kernfs_open_file.list */
61693 };
61694 @@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61695 {
61696 struct kernfs_open_file *of = sf->private;
61697
61698 - of->event = atomic_read(&of->kn->attr.open->event);
61699 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61700
61701 return of->kn->attr.ops->seq_show(sf, v);
61702 }
61703 @@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61704 return ret;
61705 }
61706
61707 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61708 - void *buf, int len, int write)
61709 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61710 + void *buf, size_t len, int write)
61711 {
61712 struct file *file = vma->vm_file;
61713 struct kernfs_open_file *of = kernfs_of(file);
61714 - int ret;
61715 + ssize_t ret;
61716
61717 if (!of->vm_ops)
61718 return -EINVAL;
61719 @@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61720 return -ENOMEM;
61721
61722 atomic_set(&new_on->refcnt, 0);
61723 - atomic_set(&new_on->event, 1);
61724 + atomic_set_unchecked(&new_on->event, 1);
61725 init_waitqueue_head(&new_on->poll);
61726 INIT_LIST_HEAD(&new_on->files);
61727 goto retry;
61728 @@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61729
61730 kernfs_put_active(kn);
61731
61732 - if (of->event != atomic_read(&on->event))
61733 + if (of->event != atomic_read_unchecked(&on->event))
61734 goto trigger;
61735
61736 return DEFAULT_POLLMASK;
61737 @@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
61738 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61739 on = kn->attr.open;
61740 if (on) {
61741 - atomic_inc(&on->event);
61742 + atomic_inc_unchecked(&on->event);
61743 wake_up_interruptible(&on->poll);
61744 }
61745 }
61746 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61747 index 4d45705..b35e0bd 100644
61748 --- a/fs/kernfs/symlink.c
61749 +++ b/fs/kernfs/symlink.c
61750 @@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61751 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61752 void *cookie)
61753 {
61754 - char *page = nd_get_link(nd);
61755 + const char *page = nd_get_link(nd);
61756 if (!IS_ERR(page))
61757 free_page((unsigned long)page);
61758 }
61759 diff --git a/fs/libfs.c b/fs/libfs.c
61760 index a184424..944ddce 100644
61761 --- a/fs/libfs.c
61762 +++ b/fs/libfs.c
61763 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61764
61765 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61766 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61767 + char d_name[sizeof(next->d_iname)];
61768 + const unsigned char *name;
61769 +
61770 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61771 if (!simple_positive(next)) {
61772 spin_unlock(&next->d_lock);
61773 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61774
61775 spin_unlock(&next->d_lock);
61776 spin_unlock(&dentry->d_lock);
61777 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61778 + name = next->d_name.name;
61779 + if (name == next->d_iname) {
61780 + memcpy(d_name, name, next->d_name.len);
61781 + name = d_name;
61782 + }
61783 + if (!dir_emit(ctx, name, next->d_name.len,
61784 next->d_inode->i_ino, dt_type(next->d_inode)))
61785 return 0;
61786 spin_lock(&dentry->d_lock);
61787 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61788 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61789 void *cookie)
61790 {
61791 - char *s = nd_get_link(nd);
61792 + const char *s = nd_get_link(nd);
61793 if (!IS_ERR(s))
61794 kfree(s);
61795 }
61796 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61797 index acd3947..1f896e2 100644
61798 --- a/fs/lockd/clntproc.c
61799 +++ b/fs/lockd/clntproc.c
61800 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61801 /*
61802 * Cookie counter for NLM requests
61803 */
61804 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61805 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61806
61807 void nlmclnt_next_cookie(struct nlm_cookie *c)
61808 {
61809 - u32 cookie = atomic_inc_return(&nlm_cookie);
61810 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61811
61812 memcpy(c->data, &cookie, 4);
61813 c->len=4;
61814 diff --git a/fs/locks.c b/fs/locks.c
61815 index 4dd39b9..12d6aaf 100644
61816 --- a/fs/locks.c
61817 +++ b/fs/locks.c
61818 @@ -2218,16 +2218,16 @@ void locks_remove_flock(struct file *filp)
61819 return;
61820
61821 if (filp->f_op->flock) {
61822 - struct file_lock fl = {
61823 + struct file_lock flock = {
61824 .fl_pid = current->tgid,
61825 .fl_file = filp,
61826 .fl_flags = FL_FLOCK,
61827 .fl_type = F_UNLCK,
61828 .fl_end = OFFSET_MAX,
61829 };
61830 - filp->f_op->flock(filp, F_SETLKW, &fl);
61831 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
61832 - fl.fl_ops->fl_release_private(&fl);
61833 + filp->f_op->flock(filp, F_SETLKW, &flock);
61834 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
61835 + flock.fl_ops->fl_release_private(&flock);
61836 }
61837
61838 spin_lock(&inode->i_lock);
61839 diff --git a/fs/mount.h b/fs/mount.h
61840 index b29e42f..5ea7fdf 100644
61841 --- a/fs/mount.h
61842 +++ b/fs/mount.h
61843 @@ -11,7 +11,7 @@ struct mnt_namespace {
61844 u64 seq; /* Sequence number to prevent loops */
61845 wait_queue_head_t poll;
61846 int event;
61847 -};
61848 +} __randomize_layout;
61849
61850 struct mnt_pcp {
61851 int mnt_count;
61852 @@ -57,7 +57,7 @@ struct mount {
61853 int mnt_expiry_mark; /* true if marked for expiry */
61854 int mnt_pinned;
61855 struct path mnt_ex_mountpoint;
61856 -};
61857 +} __randomize_layout;
61858
61859 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61860
61861 diff --git a/fs/namei.c b/fs/namei.c
61862 index 4b491b4..a0166f9 100644
61863 --- a/fs/namei.c
61864 +++ b/fs/namei.c
61865 @@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61866 if (ret != -EACCES)
61867 return ret;
61868
61869 +#ifdef CONFIG_GRKERNSEC
61870 + /* we'll block if we have to log due to a denied capability use */
61871 + if (mask & MAY_NOT_BLOCK)
61872 + return -ECHILD;
61873 +#endif
61874 +
61875 if (S_ISDIR(inode->i_mode)) {
61876 /* DACs are overridable for directories */
61877 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
61878 - return 0;
61879 if (!(mask & MAY_WRITE))
61880 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61881 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61882 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61883 return 0;
61884 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
61885 + return 0;
61886 return -EACCES;
61887 }
61888 /*
61889 + * Searching includes executable on directories, else just read.
61890 + */
61891 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61892 + if (mask == MAY_READ)
61893 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61894 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61895 + return 0;
61896 +
61897 + /*
61898 * Read/write DACs are always overridable.
61899 * Executable DACs are overridable when there is
61900 * at least one exec bit set.
61901 @@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61902 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61903 return 0;
61904
61905 - /*
61906 - * Searching includes executable on directories, else just read.
61907 - */
61908 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61909 - if (mask == MAY_READ)
61910 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61911 - return 0;
61912 -
61913 return -EACCES;
61914 }
61915
61916 @@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61917 {
61918 struct dentry *dentry = link->dentry;
61919 int error;
61920 - char *s;
61921 + const char *s;
61922
61923 BUG_ON(nd->flags & LOOKUP_RCU);
61924
61925 @@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61926 if (error)
61927 goto out_put_nd_path;
61928
61929 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
61930 + dentry->d_inode, dentry, nd->path.mnt)) {
61931 + error = -EACCES;
61932 + goto out_put_nd_path;
61933 + }
61934 +
61935 nd->last_type = LAST_BIND;
61936 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61937 error = PTR_ERR(*p);
61938 @@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61939 if (res)
61940 break;
61941 res = walk_component(nd, path, LOOKUP_FOLLOW);
61942 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61943 + res = -EACCES;
61944 put_link(nd, &link, cookie);
61945 } while (res > 0);
61946
61947 @@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
61948 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61949 {
61950 unsigned long a, b, adata, bdata, mask, hash, len;
61951 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61952 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61953
61954 hash = a = 0;
61955 len = -sizeof(unsigned long);
61956 @@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
61957 if (err)
61958 break;
61959 err = lookup_last(nd, &path);
61960 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
61961 + err = -EACCES;
61962 put_link(nd, &link, cookie);
61963 }
61964 }
61965 @@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
61966 if (!err)
61967 err = complete_walk(nd);
61968
61969 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
61970 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61971 + path_put(&nd->path);
61972 + err = -ENOENT;
61973 + }
61974 + }
61975 +
61976 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61977 if (!d_is_directory(nd->path.dentry)) {
61978 path_put(&nd->path);
61979 @@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
61980 retval = path_lookupat(dfd, name->name,
61981 flags | LOOKUP_REVAL, nd);
61982
61983 - if (likely(!retval))
61984 + if (likely(!retval)) {
61985 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61986 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61987 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61988 + path_put(&nd->path);
61989 + return -ENOENT;
61990 + }
61991 + }
61992 + }
61993 return retval;
61994 }
61995
61996 @@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61997 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61998 return -EPERM;
61999
62000 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
62001 + return -EPERM;
62002 + if (gr_handle_rawio(inode))
62003 + return -EPERM;
62004 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
62005 + return -EACCES;
62006 +
62007 return 0;
62008 }
62009
62010 @@ -2787,7 +2826,7 @@ looked_up:
62011 * cleared otherwise prior to returning.
62012 */
62013 static int lookup_open(struct nameidata *nd, struct path *path,
62014 - struct file *file,
62015 + struct path *link, struct file *file,
62016 const struct open_flags *op,
62017 bool got_write, int *opened)
62018 {
62019 @@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62020 /* Negative dentry, just create the file */
62021 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
62022 umode_t mode = op->mode;
62023 +
62024 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
62025 + error = -EACCES;
62026 + goto out_dput;
62027 + }
62028 +
62029 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
62030 + error = -EACCES;
62031 + goto out_dput;
62032 + }
62033 +
62034 if (!IS_POSIXACL(dir->d_inode))
62035 mode &= ~current_umask();
62036 /*
62037 @@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
62038 nd->flags & LOOKUP_EXCL);
62039 if (error)
62040 goto out_dput;
62041 + else
62042 + gr_handle_create(dentry, nd->path.mnt);
62043 }
62044 out_no_open:
62045 path->dentry = dentry;
62046 @@ -2857,7 +2909,7 @@ out_dput:
62047 /*
62048 * Handle the last step of open()
62049 */
62050 -static int do_last(struct nameidata *nd, struct path *path,
62051 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
62052 struct file *file, const struct open_flags *op,
62053 int *opened, struct filename *name)
62054 {
62055 @@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
62056 if (error)
62057 return error;
62058
62059 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
62060 + error = -ENOENT;
62061 + goto out;
62062 + }
62063 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
62064 + error = -EACCES;
62065 + goto out;
62066 + }
62067 +
62068 audit_inode(name, dir, LOOKUP_PARENT);
62069 error = -EISDIR;
62070 /* trailing slashes? */
62071 @@ -2926,7 +2987,7 @@ retry_lookup:
62072 */
62073 }
62074 mutex_lock(&dir->d_inode->i_mutex);
62075 - error = lookup_open(nd, path, file, op, got_write, opened);
62076 + error = lookup_open(nd, path, link, file, op, got_write, opened);
62077 mutex_unlock(&dir->d_inode->i_mutex);
62078
62079 if (error <= 0) {
62080 @@ -2950,11 +3011,28 @@ retry_lookup:
62081 goto finish_open_created;
62082 }
62083
62084 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
62085 + error = -ENOENT;
62086 + goto exit_dput;
62087 + }
62088 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
62089 + error = -EACCES;
62090 + goto exit_dput;
62091 + }
62092 +
62093 /*
62094 * create/update audit record if it already exists.
62095 */
62096 - if (d_is_positive(path->dentry))
62097 + if (d_is_positive(path->dentry)) {
62098 + /* only check if O_CREAT is specified, all other checks need to go
62099 + into may_open */
62100 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
62101 + error = -EACCES;
62102 + goto exit_dput;
62103 + }
62104 +
62105 audit_inode(name, path->dentry, 0);
62106 + }
62107
62108 /*
62109 * If atomic_open() acquired write access it is dropped now due to
62110 @@ -2995,6 +3073,11 @@ finish_lookup:
62111 }
62112 }
62113 BUG_ON(inode != path->dentry->d_inode);
62114 + /* if we're resolving a symlink to another symlink */
62115 + if (link && gr_handle_symlink_owner(link, inode)) {
62116 + error = -EACCES;
62117 + goto out;
62118 + }
62119 return 1;
62120 }
62121
62122 @@ -3004,7 +3087,6 @@ finish_lookup:
62123 save_parent.dentry = nd->path.dentry;
62124 save_parent.mnt = mntget(path->mnt);
62125 nd->path.dentry = path->dentry;
62126 -
62127 }
62128 nd->inode = inode;
62129 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
62130 @@ -3014,7 +3096,18 @@ finish_open:
62131 path_put(&save_parent);
62132 return error;
62133 }
62134 +
62135 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62136 + error = -ENOENT;
62137 + goto out;
62138 + }
62139 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
62140 + error = -EACCES;
62141 + goto out;
62142 + }
62143 +
62144 audit_inode(name, nd->path.dentry, 0);
62145 +
62146 error = -EISDIR;
62147 if ((open_flag & O_CREAT) &&
62148 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
62149 @@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62150 if (unlikely(error))
62151 goto out;
62152
62153 - error = do_last(nd, &path, file, op, &opened, pathname);
62154 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
62155 while (unlikely(error > 0)) { /* trailing symlink */
62156 struct path link = path;
62157 void *cookie;
62158 @@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62159 error = follow_link(&link, nd, &cookie);
62160 if (unlikely(error))
62161 break;
62162 - error = do_last(nd, &path, file, op, &opened, pathname);
62163 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
62164 put_link(nd, &link, cookie);
62165 }
62166 out:
62167 @@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
62168 goto unlock;
62169
62170 error = -EEXIST;
62171 - if (d_is_positive(dentry))
62172 + if (d_is_positive(dentry)) {
62173 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
62174 + error = -ENOENT;
62175 goto fail;
62176 -
62177 + }
62178 /*
62179 * Special case - lookup gave negative, but... we had foo/bar/
62180 * From the vfs_mknod() POV we just have a negative dentry -
62181 @@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
62182 }
62183 EXPORT_SYMBOL(user_path_create);
62184
62185 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
62186 +{
62187 + struct filename *tmp = getname(pathname);
62188 + struct dentry *res;
62189 + if (IS_ERR(tmp))
62190 + return ERR_CAST(tmp);
62191 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
62192 + if (IS_ERR(res))
62193 + putname(tmp);
62194 + else
62195 + *to = tmp;
62196 + return res;
62197 +}
62198 +
62199 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
62200 {
62201 int error = may_create(dir, dentry);
62202 @@ -3412,6 +3521,17 @@ retry:
62203
62204 if (!IS_POSIXACL(path.dentry->d_inode))
62205 mode &= ~current_umask();
62206 +
62207 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
62208 + error = -EPERM;
62209 + goto out;
62210 + }
62211 +
62212 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
62213 + error = -EACCES;
62214 + goto out;
62215 + }
62216 +
62217 error = security_path_mknod(&path, dentry, mode, dev);
62218 if (error)
62219 goto out;
62220 @@ -3428,6 +3548,8 @@ retry:
62221 break;
62222 }
62223 out:
62224 + if (!error)
62225 + gr_handle_create(dentry, path.mnt);
62226 done_path_create(&path, dentry);
62227 if (retry_estale(error, lookup_flags)) {
62228 lookup_flags |= LOOKUP_REVAL;
62229 @@ -3480,9 +3602,16 @@ retry:
62230
62231 if (!IS_POSIXACL(path.dentry->d_inode))
62232 mode &= ~current_umask();
62233 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62234 + error = -EACCES;
62235 + goto out;
62236 + }
62237 error = security_path_mkdir(&path, dentry, mode);
62238 if (!error)
62239 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62240 + if (!error)
62241 + gr_handle_create(dentry, path.mnt);
62242 +out:
62243 done_path_create(&path, dentry);
62244 if (retry_estale(error, lookup_flags)) {
62245 lookup_flags |= LOOKUP_REVAL;
62246 @@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62247 struct filename *name;
62248 struct dentry *dentry;
62249 struct nameidata nd;
62250 + ino_t saved_ino = 0;
62251 + dev_t saved_dev = 0;
62252 unsigned int lookup_flags = 0;
62253 retry:
62254 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62255 @@ -3595,10 +3726,21 @@ retry:
62256 error = -ENOENT;
62257 goto exit3;
62258 }
62259 +
62260 + saved_ino = dentry->d_inode->i_ino;
62261 + saved_dev = gr_get_dev_from_dentry(dentry);
62262 +
62263 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62264 + error = -EACCES;
62265 + goto exit3;
62266 + }
62267 +
62268 error = security_path_rmdir(&nd.path, dentry);
62269 if (error)
62270 goto exit3;
62271 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62272 + if (!error && (saved_dev || saved_ino))
62273 + gr_handle_delete(saved_ino, saved_dev);
62274 exit3:
62275 dput(dentry);
62276 exit2:
62277 @@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62278 struct nameidata nd;
62279 struct inode *inode = NULL;
62280 struct inode *delegated_inode = NULL;
62281 + ino_t saved_ino = 0;
62282 + dev_t saved_dev = 0;
62283 unsigned int lookup_flags = 0;
62284 retry:
62285 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62286 @@ -3714,10 +3858,22 @@ retry_deleg:
62287 if (d_is_negative(dentry))
62288 goto slashes;
62289 ihold(inode);
62290 +
62291 + if (inode->i_nlink <= 1) {
62292 + saved_ino = inode->i_ino;
62293 + saved_dev = gr_get_dev_from_dentry(dentry);
62294 + }
62295 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62296 + error = -EACCES;
62297 + goto exit2;
62298 + }
62299 +
62300 error = security_path_unlink(&nd.path, dentry);
62301 if (error)
62302 goto exit2;
62303 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62304 + if (!error && (saved_ino || saved_dev))
62305 + gr_handle_delete(saved_ino, saved_dev);
62306 exit2:
62307 dput(dentry);
62308 }
62309 @@ -3805,9 +3961,17 @@ retry:
62310 if (IS_ERR(dentry))
62311 goto out_putname;
62312
62313 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62314 + error = -EACCES;
62315 + goto out;
62316 + }
62317 +
62318 error = security_path_symlink(&path, dentry, from->name);
62319 if (!error)
62320 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62321 + if (!error)
62322 + gr_handle_create(dentry, path.mnt);
62323 +out:
62324 done_path_create(&path, dentry);
62325 if (retry_estale(error, lookup_flags)) {
62326 lookup_flags |= LOOKUP_REVAL;
62327 @@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62328 struct dentry *new_dentry;
62329 struct path old_path, new_path;
62330 struct inode *delegated_inode = NULL;
62331 + struct filename *to = NULL;
62332 int how = 0;
62333 int error;
62334
62335 @@ -3933,7 +4098,7 @@ retry:
62336 if (error)
62337 return error;
62338
62339 - new_dentry = user_path_create(newdfd, newname, &new_path,
62340 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62341 (how & LOOKUP_REVAL));
62342 error = PTR_ERR(new_dentry);
62343 if (IS_ERR(new_dentry))
62344 @@ -3945,11 +4110,28 @@ retry:
62345 error = may_linkat(&old_path);
62346 if (unlikely(error))
62347 goto out_dput;
62348 +
62349 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62350 + old_path.dentry->d_inode,
62351 + old_path.dentry->d_inode->i_mode, to)) {
62352 + error = -EACCES;
62353 + goto out_dput;
62354 + }
62355 +
62356 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62357 + old_path.dentry, old_path.mnt, to)) {
62358 + error = -EACCES;
62359 + goto out_dput;
62360 + }
62361 +
62362 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62363 if (error)
62364 goto out_dput;
62365 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62366 + if (!error)
62367 + gr_handle_create(new_dentry, new_path.mnt);
62368 out_dput:
62369 + putname(to);
62370 done_path_create(&new_path, new_dentry);
62371 if (delegated_inode) {
62372 error = break_deleg_wait(&delegated_inode);
62373 @@ -4236,6 +4418,12 @@ retry_deleg:
62374 if (new_dentry == trap)
62375 goto exit5;
62376
62377 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62378 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
62379 + to);
62380 + if (error)
62381 + goto exit5;
62382 +
62383 error = security_path_rename(&oldnd.path, old_dentry,
62384 &newnd.path, new_dentry);
62385 if (error)
62386 @@ -4243,6 +4431,9 @@ retry_deleg:
62387 error = vfs_rename(old_dir->d_inode, old_dentry,
62388 new_dir->d_inode, new_dentry,
62389 &delegated_inode);
62390 + if (!error)
62391 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62392 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
62393 exit5:
62394 dput(new_dentry);
62395 exit4:
62396 @@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62397
62398 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
62399 {
62400 + char tmpbuf[64];
62401 + const char *newlink;
62402 int len;
62403
62404 len = PTR_ERR(link);
62405 @@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
62406 len = strlen(link);
62407 if (len > (unsigned) buflen)
62408 len = buflen;
62409 - if (copy_to_user(buffer, link, len))
62410 +
62411 + if (len < sizeof(tmpbuf)) {
62412 + memcpy(tmpbuf, link, len);
62413 + newlink = tmpbuf;
62414 + } else
62415 + newlink = link;
62416 +
62417 + if (copy_to_user(buffer, newlink, len))
62418 len = -EFAULT;
62419 out:
62420 return len;
62421 diff --git a/fs/namespace.c b/fs/namespace.c
62422 index 65233a5..82ac953 100644
62423 --- a/fs/namespace.c
62424 +++ b/fs/namespace.c
62425 @@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
62426 if (!(sb->s_flags & MS_RDONLY))
62427 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62428 up_write(&sb->s_umount);
62429 +
62430 + gr_log_remount(mnt->mnt_devname, retval);
62431 +
62432 return retval;
62433 }
62434
62435 @@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
62436 }
62437 unlock_mount_hash();
62438 namespace_unlock();
62439 +
62440 + gr_log_unmount(mnt->mnt_devname, retval);
62441 +
62442 return retval;
62443 }
62444
62445 @@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
62446 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62447 */
62448
62449 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62450 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62451 {
62452 struct path path;
62453 struct mount *mnt;
62454 @@ -1422,7 +1428,7 @@ out:
62455 /*
62456 * The 2.0 compatible umount. No flags.
62457 */
62458 -SYSCALL_DEFINE1(oldumount, char __user *, name)
62459 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
62460 {
62461 return sys_umount(name, 0);
62462 }
62463 @@ -2431,6 +2437,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62464 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62465 MS_STRICTATIME);
62466
62467 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62468 + retval = -EPERM;
62469 + goto dput_out;
62470 + }
62471 +
62472 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62473 + retval = -EPERM;
62474 + goto dput_out;
62475 + }
62476 +
62477 if (flags & MS_REMOUNT)
62478 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62479 data_page);
62480 @@ -2445,6 +2461,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62481 dev_name, data_page);
62482 dput_out:
62483 path_put(&path);
62484 +
62485 + gr_log_mount(dev_name, dir_name, retval);
62486 +
62487 return retval;
62488 }
62489
62490 @@ -2462,7 +2481,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62491 * number incrementing at 10Ghz will take 12,427 years to wrap which
62492 * is effectively never, so we can ignore the possibility.
62493 */
62494 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62495 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62496
62497 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62498 {
62499 @@ -2477,7 +2496,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62500 kfree(new_ns);
62501 return ERR_PTR(ret);
62502 }
62503 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62504 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62505 atomic_set(&new_ns->count, 1);
62506 new_ns->root = NULL;
62507 INIT_LIST_HEAD(&new_ns->list);
62508 @@ -2487,7 +2506,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62509 return new_ns;
62510 }
62511
62512 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62513 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62514 struct user_namespace *user_ns, struct fs_struct *new_fs)
62515 {
62516 struct mnt_namespace *new_ns;
62517 @@ -2608,8 +2627,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62518 }
62519 EXPORT_SYMBOL(mount_subtree);
62520
62521 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62522 - char __user *, type, unsigned long, flags, void __user *, data)
62523 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62524 + const char __user *, type, unsigned long, flags, void __user *, data)
62525 {
62526 int ret;
62527 char *kernel_type;
62528 @@ -2722,6 +2741,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62529 if (error)
62530 goto out2;
62531
62532 + if (gr_handle_chroot_pivot()) {
62533 + error = -EPERM;
62534 + goto out2;
62535 + }
62536 +
62537 get_fs_root(current->fs, &root);
62538 old_mp = lock_mount(&old);
62539 error = PTR_ERR(old_mp);
62540 @@ -2990,7 +3014,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62541 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62542 return -EPERM;
62543
62544 - if (fs->users != 1)
62545 + if (atomic_read(&fs->users) != 1)
62546 return -EINVAL;
62547
62548 get_mnt_ns(mnt_ns);
62549 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62550 index f4ccfe6..a5cf064 100644
62551 --- a/fs/nfs/callback_xdr.c
62552 +++ b/fs/nfs/callback_xdr.c
62553 @@ -51,7 +51,7 @@ struct callback_op {
62554 callback_decode_arg_t decode_args;
62555 callback_encode_res_t encode_res;
62556 long res_maxsize;
62557 -};
62558 +} __do_const;
62559
62560 static struct callback_op callback_ops[];
62561
62562 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62563 index 360114a..ac6e265 100644
62564 --- a/fs/nfs/inode.c
62565 +++ b/fs/nfs/inode.c
62566 @@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62567 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62568 }
62569
62570 -static atomic_long_t nfs_attr_generation_counter;
62571 +static atomic_long_unchecked_t nfs_attr_generation_counter;
62572
62573 static unsigned long nfs_read_attr_generation_counter(void)
62574 {
62575 - return atomic_long_read(&nfs_attr_generation_counter);
62576 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62577 }
62578
62579 unsigned long nfs_inc_attr_generation_counter(void)
62580 {
62581 - return atomic_long_inc_return(&nfs_attr_generation_counter);
62582 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62583 }
62584
62585 void nfs_fattr_init(struct nfs_fattr *fattr)
62586 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62587 index 9a914e8..e89c0ea 100644
62588 --- a/fs/nfsd/nfs4proc.c
62589 +++ b/fs/nfsd/nfs4proc.c
62590 @@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62591 nfsd4op_rsize op_rsize_bop;
62592 stateid_getter op_get_currentstateid;
62593 stateid_setter op_set_currentstateid;
62594 -};
62595 +} __do_const;
62596
62597 static struct nfsd4_operation nfsd4_ops[];
62598
62599 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62600 index 16e8fa7..b0803f6 100644
62601 --- a/fs/nfsd/nfs4xdr.c
62602 +++ b/fs/nfsd/nfs4xdr.c
62603 @@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62604
62605 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62606
62607 -static nfsd4_dec nfsd4_dec_ops[] = {
62608 +static const nfsd4_dec nfsd4_dec_ops[] = {
62609 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62610 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62611 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62612 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62613 index f8f060f..c4ba09a 100644
62614 --- a/fs/nfsd/nfscache.c
62615 +++ b/fs/nfsd/nfscache.c
62616 @@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62617 {
62618 struct svc_cacherep *rp = rqstp->rq_cacherep;
62619 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62620 - int len;
62621 + long len;
62622 size_t bufsize = 0;
62623
62624 if (!rp)
62625 return;
62626
62627 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62628 - len >>= 2;
62629 + if (statp) {
62630 + len = (char*)statp - (char*)resv->iov_base;
62631 + len = resv->iov_len - len;
62632 + len >>= 2;
62633 + }
62634
62635 /* Don't cache excessive amounts of data and XDR failures */
62636 if (!statp || len > (256 >> 2)) {
62637 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62638 index eea5ad1..5a84ac7 100644
62639 --- a/fs/nfsd/vfs.c
62640 +++ b/fs/nfsd/vfs.c
62641 @@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62642 } else {
62643 oldfs = get_fs();
62644 set_fs(KERNEL_DS);
62645 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62646 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62647 set_fs(oldfs);
62648 }
62649
62650 @@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62651
62652 /* Write the data. */
62653 oldfs = get_fs(); set_fs(KERNEL_DS);
62654 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62655 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62656 set_fs(oldfs);
62657 if (host_err < 0)
62658 goto out_nfserr;
62659 @@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62660 */
62661
62662 oldfs = get_fs(); set_fs(KERNEL_DS);
62663 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62664 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62665 set_fs(oldfs);
62666
62667 if (host_err < 0)
62668 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62669 index 52ccd34..43a53b1 100644
62670 --- a/fs/nls/nls_base.c
62671 +++ b/fs/nls/nls_base.c
62672 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62673
62674 int __register_nls(struct nls_table *nls, struct module *owner)
62675 {
62676 - struct nls_table ** tmp = &tables;
62677 + struct nls_table *tmp = tables;
62678
62679 if (nls->next)
62680 return -EBUSY;
62681
62682 - nls->owner = owner;
62683 + pax_open_kernel();
62684 + *(void **)&nls->owner = owner;
62685 + pax_close_kernel();
62686 spin_lock(&nls_lock);
62687 - while (*tmp) {
62688 - if (nls == *tmp) {
62689 + while (tmp) {
62690 + if (nls == tmp) {
62691 spin_unlock(&nls_lock);
62692 return -EBUSY;
62693 }
62694 - tmp = &(*tmp)->next;
62695 + tmp = tmp->next;
62696 }
62697 - nls->next = tables;
62698 + pax_open_kernel();
62699 + *(struct nls_table **)&nls->next = tables;
62700 + pax_close_kernel();
62701 tables = nls;
62702 spin_unlock(&nls_lock);
62703 return 0;
62704 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62705
62706 int unregister_nls(struct nls_table * nls)
62707 {
62708 - struct nls_table ** tmp = &tables;
62709 + struct nls_table * const * tmp = &tables;
62710
62711 spin_lock(&nls_lock);
62712 while (*tmp) {
62713 if (nls == *tmp) {
62714 - *tmp = nls->next;
62715 + pax_open_kernel();
62716 + *(struct nls_table **)tmp = nls->next;
62717 + pax_close_kernel();
62718 spin_unlock(&nls_lock);
62719 return 0;
62720 }
62721 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62722 index 162b3f1..6076a7c 100644
62723 --- a/fs/nls/nls_euc-jp.c
62724 +++ b/fs/nls/nls_euc-jp.c
62725 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62726 p_nls = load_nls("cp932");
62727
62728 if (p_nls) {
62729 - table.charset2upper = p_nls->charset2upper;
62730 - table.charset2lower = p_nls->charset2lower;
62731 + pax_open_kernel();
62732 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62733 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62734 + pax_close_kernel();
62735 return register_nls(&table);
62736 }
62737
62738 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62739 index a80a741..7b96e1b 100644
62740 --- a/fs/nls/nls_koi8-ru.c
62741 +++ b/fs/nls/nls_koi8-ru.c
62742 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62743 p_nls = load_nls("koi8-u");
62744
62745 if (p_nls) {
62746 - table.charset2upper = p_nls->charset2upper;
62747 - table.charset2lower = p_nls->charset2lower;
62748 + pax_open_kernel();
62749 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62750 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62751 + pax_close_kernel();
62752 return register_nls(&table);
62753 }
62754
62755 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62756 index 287a22c..4e56e4e 100644
62757 --- a/fs/notify/fanotify/fanotify_user.c
62758 +++ b/fs/notify/fanotify/fanotify_user.c
62759 @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62760
62761 fd = fanotify_event_metadata.fd;
62762 ret = -EFAULT;
62763 - if (copy_to_user(buf, &fanotify_event_metadata,
62764 - fanotify_event_metadata.event_len))
62765 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62766 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62767 goto out_close_fd;
62768
62769 ret = prepare_for_access_response(group, event, fd);
62770 @@ -742,6 +742,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
62771 oevent->path.mnt = NULL;
62772 oevent->path.dentry = NULL;
62773
62774 + if (force_o_largefile())
62775 + event_f_flags |= O_LARGEFILE;
62776 group->fanotify_data.f_flags = event_f_flags;
62777 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62778 oevent->response = 0;
62779 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62780 index 1e58402..bb2d6f4 100644
62781 --- a/fs/notify/notification.c
62782 +++ b/fs/notify/notification.c
62783 @@ -48,7 +48,7 @@
62784 #include <linux/fsnotify_backend.h>
62785 #include "fsnotify.h"
62786
62787 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62788 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62789
62790 /**
62791 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62792 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62793 */
62794 u32 fsnotify_get_cookie(void)
62795 {
62796 - return atomic_inc_return(&fsnotify_sync_cookie);
62797 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62798 }
62799 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62800
62801 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62802 index 9e38daf..5727cae 100644
62803 --- a/fs/ntfs/dir.c
62804 +++ b/fs/ntfs/dir.c
62805 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
62806 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62807 ~(s64)(ndir->itype.index.block_size - 1)));
62808 /* Bounds checks. */
62809 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62810 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62811 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62812 "inode 0x%lx or driver bug.", vdir->i_ino);
62813 goto err_out;
62814 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62815 index db9bd8a..8338fb6 100644
62816 --- a/fs/ntfs/file.c
62817 +++ b/fs/ntfs/file.c
62818 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62819 char *addr;
62820 size_t total = 0;
62821 unsigned len;
62822 - int left;
62823 + unsigned left;
62824
62825 do {
62826 len = PAGE_CACHE_SIZE - ofs;
62827 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62828 index 82650d5..db37dcf 100644
62829 --- a/fs/ntfs/super.c
62830 +++ b/fs/ntfs/super.c
62831 @@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62832 if (!silent)
62833 ntfs_error(sb, "Primary boot sector is invalid.");
62834 } else if (!silent)
62835 - ntfs_error(sb, read_err_str, "primary");
62836 + ntfs_error(sb, read_err_str, "%s", "primary");
62837 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62838 if (bh_primary)
62839 brelse(bh_primary);
62840 @@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62841 goto hotfix_primary_boot_sector;
62842 brelse(bh_backup);
62843 } else if (!silent)
62844 - ntfs_error(sb, read_err_str, "backup");
62845 + ntfs_error(sb, read_err_str, "%s", "backup");
62846 /* Try to read NT3.51- backup boot sector. */
62847 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62848 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62849 @@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62850 "sector.");
62851 brelse(bh_backup);
62852 } else if (!silent)
62853 - ntfs_error(sb, read_err_str, "backup");
62854 + ntfs_error(sb, read_err_str, "%s", "backup");
62855 /* We failed. Cleanup and return. */
62856 if (bh_primary)
62857 brelse(bh_primary);
62858 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62859 index 0440134..d52c93a 100644
62860 --- a/fs/ocfs2/localalloc.c
62861 +++ b/fs/ocfs2/localalloc.c
62862 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62863 goto bail;
62864 }
62865
62866 - atomic_inc(&osb->alloc_stats.moves);
62867 + atomic_inc_unchecked(&osb->alloc_stats.moves);
62868
62869 bail:
62870 if (handle)
62871 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62872 index 553f53c..aaf5133 100644
62873 --- a/fs/ocfs2/ocfs2.h
62874 +++ b/fs/ocfs2/ocfs2.h
62875 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
62876
62877 struct ocfs2_alloc_stats
62878 {
62879 - atomic_t moves;
62880 - atomic_t local_data;
62881 - atomic_t bitmap_data;
62882 - atomic_t bg_allocs;
62883 - atomic_t bg_extends;
62884 + atomic_unchecked_t moves;
62885 + atomic_unchecked_t local_data;
62886 + atomic_unchecked_t bitmap_data;
62887 + atomic_unchecked_t bg_allocs;
62888 + atomic_unchecked_t bg_extends;
62889 };
62890
62891 enum ocfs2_local_alloc_state
62892 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62893 index 47ae266..6e8b793 100644
62894 --- a/fs/ocfs2/suballoc.c
62895 +++ b/fs/ocfs2/suballoc.c
62896 @@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62897 mlog_errno(status);
62898 goto bail;
62899 }
62900 - atomic_inc(&osb->alloc_stats.bg_extends);
62901 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62902
62903 /* You should never ask for this much metadata */
62904 BUG_ON(bits_wanted >
62905 @@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62906 mlog_errno(status);
62907 goto bail;
62908 }
62909 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62910 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62911
62912 *suballoc_loc = res.sr_bg_blkno;
62913 *suballoc_bit_start = res.sr_bit_offset;
62914 @@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62915 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62916 res->sr_bits);
62917
62918 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62919 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62920
62921 BUG_ON(res->sr_bits != 1);
62922
62923 @@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62924 mlog_errno(status);
62925 goto bail;
62926 }
62927 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62928 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62929
62930 BUG_ON(res.sr_bits != 1);
62931
62932 @@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62933 cluster_start,
62934 num_clusters);
62935 if (!status)
62936 - atomic_inc(&osb->alloc_stats.local_data);
62937 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
62938 } else {
62939 if (min_clusters > (osb->bitmap_cpg - 1)) {
62940 /* The only paths asking for contiguousness
62941 @@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62942 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62943 res.sr_bg_blkno,
62944 res.sr_bit_offset);
62945 - atomic_inc(&osb->alloc_stats.bitmap_data);
62946 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62947 *num_clusters = res.sr_bits;
62948 }
62949 }
62950 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62951 index 49d84f8..4807e0b 100644
62952 --- a/fs/ocfs2/super.c
62953 +++ b/fs/ocfs2/super.c
62954 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62955 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62956 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62957 "Stats",
62958 - atomic_read(&osb->alloc_stats.bitmap_data),
62959 - atomic_read(&osb->alloc_stats.local_data),
62960 - atomic_read(&osb->alloc_stats.bg_allocs),
62961 - atomic_read(&osb->alloc_stats.moves),
62962 - atomic_read(&osb->alloc_stats.bg_extends));
62963 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62964 + atomic_read_unchecked(&osb->alloc_stats.local_data),
62965 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62966 + atomic_read_unchecked(&osb->alloc_stats.moves),
62967 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62968
62969 out += snprintf(buf + out, len - out,
62970 "%10s => State: %u Descriptor: %llu Size: %u bits "
62971 @@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62972 spin_lock_init(&osb->osb_xattr_lock);
62973 ocfs2_init_steal_slots(osb);
62974
62975 - atomic_set(&osb->alloc_stats.moves, 0);
62976 - atomic_set(&osb->alloc_stats.local_data, 0);
62977 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
62978 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
62979 - atomic_set(&osb->alloc_stats.bg_extends, 0);
62980 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62981 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62982 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62983 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62984 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62985
62986 /* Copy the blockcheck stats from the superblock probe */
62987 osb->osb_ecc_stats = *stats;
62988 diff --git a/fs/open.c b/fs/open.c
62989 index b9ed8b2..0d5c7a0 100644
62990 --- a/fs/open.c
62991 +++ b/fs/open.c
62992 @@ -32,6 +32,8 @@
62993 #include <linux/dnotify.h>
62994 #include <linux/compat.h>
62995
62996 +#define CREATE_TRACE_POINTS
62997 +#include <trace/events/fs.h>
62998 #include "internal.h"
62999
63000 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
63001 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
63002 error = locks_verify_truncate(inode, NULL, length);
63003 if (!error)
63004 error = security_path_truncate(path);
63005 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
63006 + error = -EACCES;
63007 if (!error)
63008 error = do_truncate(path->dentry, length, 0, NULL);
63009
63010 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
63011 error = locks_verify_truncate(inode, f.file, length);
63012 if (!error)
63013 error = security_path_truncate(&f.file->f_path);
63014 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
63015 + error = -EACCES;
63016 if (!error)
63017 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
63018 sb_end_write(inode->i_sb);
63019 @@ -361,6 +367,9 @@ retry:
63020 if (__mnt_is_readonly(path.mnt))
63021 res = -EROFS;
63022
63023 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
63024 + res = -EACCES;
63025 +
63026 out_path_release:
63027 path_put(&path);
63028 if (retry_estale(res, lookup_flags)) {
63029 @@ -392,6 +401,8 @@ retry:
63030 if (error)
63031 goto dput_and_out;
63032
63033 + gr_log_chdir(path.dentry, path.mnt);
63034 +
63035 set_fs_pwd(current->fs, &path);
63036
63037 dput_and_out:
63038 @@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
63039 goto out_putf;
63040
63041 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
63042 +
63043 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
63044 + error = -EPERM;
63045 +
63046 + if (!error)
63047 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
63048 +
63049 if (!error)
63050 set_fs_pwd(current->fs, &f.file->f_path);
63051 out_putf:
63052 @@ -450,7 +468,13 @@ retry:
63053 if (error)
63054 goto dput_and_out;
63055
63056 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
63057 + goto dput_and_out;
63058 +
63059 set_fs_root(current->fs, &path);
63060 +
63061 + gr_handle_chroot_chdir(&path);
63062 +
63063 error = 0;
63064 dput_and_out:
63065 path_put(&path);
63066 @@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
63067 return error;
63068 retry_deleg:
63069 mutex_lock(&inode->i_mutex);
63070 +
63071 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
63072 + error = -EACCES;
63073 + goto out_unlock;
63074 + }
63075 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
63076 + error = -EACCES;
63077 + goto out_unlock;
63078 + }
63079 +
63080 error = security_path_chmod(path, mode);
63081 if (error)
63082 goto out_unlock;
63083 @@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
63084 uid = make_kuid(current_user_ns(), user);
63085 gid = make_kgid(current_user_ns(), group);
63086
63087 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
63088 + return -EACCES;
63089 +
63090 newattrs.ia_valid = ATTR_CTIME;
63091 if (user != (uid_t) -1) {
63092 if (!uid_valid(uid))
63093 @@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
63094 } else {
63095 fsnotify_open(f);
63096 fd_install(fd, f);
63097 + trace_do_sys_open(tmp->name, flags, mode);
63098 }
63099 }
63100 putname(tmp);
63101 diff --git a/fs/pipe.c b/fs/pipe.c
63102 index 78fd0d0..f71fc09 100644
63103 --- a/fs/pipe.c
63104 +++ b/fs/pipe.c
63105 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
63106
63107 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
63108 {
63109 - if (pipe->files)
63110 + if (atomic_read(&pipe->files))
63111 mutex_lock_nested(&pipe->mutex, subclass);
63112 }
63113
63114 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
63115
63116 void pipe_unlock(struct pipe_inode_info *pipe)
63117 {
63118 - if (pipe->files)
63119 + if (atomic_read(&pipe->files))
63120 mutex_unlock(&pipe->mutex);
63121 }
63122 EXPORT_SYMBOL(pipe_unlock);
63123 @@ -449,9 +449,9 @@ redo:
63124 }
63125 if (bufs) /* More to do? */
63126 continue;
63127 - if (!pipe->writers)
63128 + if (!atomic_read(&pipe->writers))
63129 break;
63130 - if (!pipe->waiting_writers) {
63131 + if (!atomic_read(&pipe->waiting_writers)) {
63132 /* syscall merging: Usually we must not sleep
63133 * if O_NONBLOCK is set, or if we got some data.
63134 * But if a writer sleeps in kernel space, then
63135 @@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
63136 ret = 0;
63137 __pipe_lock(pipe);
63138
63139 - if (!pipe->readers) {
63140 + if (!atomic_read(&pipe->readers)) {
63141 send_sig(SIGPIPE, current, 0);
63142 ret = -EPIPE;
63143 goto out;
63144 @@ -562,7 +562,7 @@ redo1:
63145 for (;;) {
63146 int bufs;
63147
63148 - if (!pipe->readers) {
63149 + if (!atomic_read(&pipe->readers)) {
63150 send_sig(SIGPIPE, current, 0);
63151 if (!ret)
63152 ret = -EPIPE;
63153 @@ -653,9 +653,9 @@ redo2:
63154 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63155 do_wakeup = 0;
63156 }
63157 - pipe->waiting_writers++;
63158 + atomic_inc(&pipe->waiting_writers);
63159 pipe_wait(pipe);
63160 - pipe->waiting_writers--;
63161 + atomic_dec(&pipe->waiting_writers);
63162 }
63163 out:
63164 __pipe_unlock(pipe);
63165 @@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63166 mask = 0;
63167 if (filp->f_mode & FMODE_READ) {
63168 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
63169 - if (!pipe->writers && filp->f_version != pipe->w_counter)
63170 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
63171 mask |= POLLHUP;
63172 }
63173
63174 @@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63175 * Most Unices do not set POLLERR for FIFOs but on Linux they
63176 * behave exactly like pipes for poll().
63177 */
63178 - if (!pipe->readers)
63179 + if (!atomic_read(&pipe->readers))
63180 mask |= POLLERR;
63181 }
63182
63183 @@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
63184 int kill = 0;
63185
63186 spin_lock(&inode->i_lock);
63187 - if (!--pipe->files) {
63188 + if (atomic_dec_and_test(&pipe->files)) {
63189 inode->i_pipe = NULL;
63190 kill = 1;
63191 }
63192 @@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
63193
63194 __pipe_lock(pipe);
63195 if (file->f_mode & FMODE_READ)
63196 - pipe->readers--;
63197 + atomic_dec(&pipe->readers);
63198 if (file->f_mode & FMODE_WRITE)
63199 - pipe->writers--;
63200 + atomic_dec(&pipe->writers);
63201
63202 - if (pipe->readers || pipe->writers) {
63203 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
63204 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
63205 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63206 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
63207 @@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
63208 kfree(pipe);
63209 }
63210
63211 -static struct vfsmount *pipe_mnt __read_mostly;
63212 +struct vfsmount *pipe_mnt __read_mostly;
63213
63214 /*
63215 * pipefs_dname() is called from d_path().
63216 @@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
63217 goto fail_iput;
63218
63219 inode->i_pipe = pipe;
63220 - pipe->files = 2;
63221 - pipe->readers = pipe->writers = 1;
63222 + atomic_set(&pipe->files, 2);
63223 + atomic_set(&pipe->readers, 1);
63224 + atomic_set(&pipe->writers, 1);
63225 inode->i_fop = &pipefifo_fops;
63226
63227 /*
63228 @@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
63229 spin_lock(&inode->i_lock);
63230 if (inode->i_pipe) {
63231 pipe = inode->i_pipe;
63232 - pipe->files++;
63233 + atomic_inc(&pipe->files);
63234 spin_unlock(&inode->i_lock);
63235 } else {
63236 spin_unlock(&inode->i_lock);
63237 pipe = alloc_pipe_info();
63238 if (!pipe)
63239 return -ENOMEM;
63240 - pipe->files = 1;
63241 + atomic_set(&pipe->files, 1);
63242 spin_lock(&inode->i_lock);
63243 if (unlikely(inode->i_pipe)) {
63244 - inode->i_pipe->files++;
63245 + atomic_inc(&inode->i_pipe->files);
63246 spin_unlock(&inode->i_lock);
63247 free_pipe_info(pipe);
63248 pipe = inode->i_pipe;
63249 @@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63250 * opened, even when there is no process writing the FIFO.
63251 */
63252 pipe->r_counter++;
63253 - if (pipe->readers++ == 0)
63254 + if (atomic_inc_return(&pipe->readers) == 1)
63255 wake_up_partner(pipe);
63256
63257 - if (!is_pipe && !pipe->writers) {
63258 + if (!is_pipe && !atomic_read(&pipe->writers)) {
63259 if ((filp->f_flags & O_NONBLOCK)) {
63260 /* suppress POLLHUP until we have
63261 * seen a writer */
63262 @@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63263 * errno=ENXIO when there is no process reading the FIFO.
63264 */
63265 ret = -ENXIO;
63266 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63267 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63268 goto err;
63269
63270 pipe->w_counter++;
63271 - if (!pipe->writers++)
63272 + if (atomic_inc_return(&pipe->writers) == 1)
63273 wake_up_partner(pipe);
63274
63275 - if (!is_pipe && !pipe->readers) {
63276 + if (!is_pipe && !atomic_read(&pipe->readers)) {
63277 if (wait_for_partner(pipe, &pipe->r_counter))
63278 goto err_wr;
63279 }
63280 @@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63281 * the process can at least talk to itself.
63282 */
63283
63284 - pipe->readers++;
63285 - pipe->writers++;
63286 + atomic_inc(&pipe->readers);
63287 + atomic_inc(&pipe->writers);
63288 pipe->r_counter++;
63289 pipe->w_counter++;
63290 - if (pipe->readers == 1 || pipe->writers == 1)
63291 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63292 wake_up_partner(pipe);
63293 break;
63294
63295 @@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63296 return 0;
63297
63298 err_rd:
63299 - if (!--pipe->readers)
63300 + if (atomic_dec_and_test(&pipe->readers))
63301 wake_up_interruptible(&pipe->wait);
63302 ret = -ERESTARTSYS;
63303 goto err;
63304
63305 err_wr:
63306 - if (!--pipe->writers)
63307 + if (atomic_dec_and_test(&pipe->writers))
63308 wake_up_interruptible(&pipe->wait);
63309 ret = -ERESTARTSYS;
63310 goto err;
63311 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63312 index 9e363e4..d936d15 100644
63313 --- a/fs/posix_acl.c
63314 +++ b/fs/posix_acl.c
63315 @@ -20,6 +20,7 @@
63316 #include <linux/xattr.h>
63317 #include <linux/export.h>
63318 #include <linux/user_namespace.h>
63319 +#include <linux/grsecurity.h>
63320
63321 struct posix_acl **acl_by_type(struct inode *inode, int type)
63322 {
63323 @@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63324 }
63325 }
63326 if (mode_p)
63327 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63328 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63329 return not_equiv;
63330 }
63331 EXPORT_SYMBOL(posix_acl_equiv_mode);
63332 @@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63333 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63334 }
63335
63336 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63337 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63338 return not_equiv;
63339 }
63340
63341 @@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63342 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63343 int err = -ENOMEM;
63344 if (clone) {
63345 + *mode_p &= ~gr_acl_umask();
63346 +
63347 err = posix_acl_create_masq(clone, mode_p);
63348 if (err < 0) {
63349 posix_acl_release(clone);
63350 @@ -653,11 +656,12 @@ struct posix_acl *
63351 posix_acl_from_xattr(struct user_namespace *user_ns,
63352 const void *value, size_t size)
63353 {
63354 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63355 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63356 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63357 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63358 int count;
63359 struct posix_acl *acl;
63360 struct posix_acl_entry *acl_e;
63361 + umode_t umask = gr_acl_umask();
63362
63363 if (!value)
63364 return NULL;
63365 @@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63366
63367 switch(acl_e->e_tag) {
63368 case ACL_USER_OBJ:
63369 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63370 + break;
63371 case ACL_GROUP_OBJ:
63372 case ACL_MASK:
63373 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63374 + break;
63375 case ACL_OTHER:
63376 + acl_e->e_perm &= ~(umask & S_IRWXO);
63377 break;
63378
63379 case ACL_USER:
63380 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63381 acl_e->e_uid =
63382 make_kuid(user_ns,
63383 le32_to_cpu(entry->e_id));
63384 @@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63385 goto fail;
63386 break;
63387 case ACL_GROUP:
63388 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63389 acl_e->e_gid =
63390 make_kgid(user_ns,
63391 le32_to_cpu(entry->e_id));
63392 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63393 index 2183fcf..3c32a98 100644
63394 --- a/fs/proc/Kconfig
63395 +++ b/fs/proc/Kconfig
63396 @@ -30,7 +30,7 @@ config PROC_FS
63397
63398 config PROC_KCORE
63399 bool "/proc/kcore support" if !ARM
63400 - depends on PROC_FS && MMU
63401 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63402 help
63403 Provides a virtual ELF core file of the live kernel. This can
63404 be read with gdb and other ELF tools. No modifications can be
63405 @@ -38,8 +38,8 @@ config PROC_KCORE
63406
63407 config PROC_VMCORE
63408 bool "/proc/vmcore support"
63409 - depends on PROC_FS && CRASH_DUMP
63410 - default y
63411 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63412 + default n
63413 help
63414 Exports the dump image of crashed kernel in ELF format.
63415
63416 @@ -63,8 +63,8 @@ config PROC_SYSCTL
63417 limited in memory.
63418
63419 config PROC_PAGE_MONITOR
63420 - default y
63421 - depends on PROC_FS && MMU
63422 + default n
63423 + depends on PROC_FS && MMU && !GRKERNSEC
63424 bool "Enable /proc page monitoring" if EXPERT
63425 help
63426 Various /proc files exist to monitor process memory utilization:
63427 diff --git a/fs/proc/array.c b/fs/proc/array.c
63428 index 656e401..b5b86b9 100644
63429 --- a/fs/proc/array.c
63430 +++ b/fs/proc/array.c
63431 @@ -60,6 +60,7 @@
63432 #include <linux/tty.h>
63433 #include <linux/string.h>
63434 #include <linux/mman.h>
63435 +#include <linux/grsecurity.h>
63436 #include <linux/proc_fs.h>
63437 #include <linux/ioport.h>
63438 #include <linux/uaccess.h>
63439 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63440 seq_putc(m, '\n');
63441 }
63442
63443 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63444 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
63445 +{
63446 + if (p->mm)
63447 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63448 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63449 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63450 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63451 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63452 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63453 + else
63454 + seq_printf(m, "PaX:\t-----\n");
63455 +}
63456 +#endif
63457 +
63458 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63459 struct pid *pid, struct task_struct *task)
63460 {
63461 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63462 task_cpus_allowed(m, task);
63463 cpuset_task_status_allowed(m, task);
63464 task_context_switch_counts(m, task);
63465 +
63466 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63467 + task_pax(m, task);
63468 +#endif
63469 +
63470 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63471 + task_grsec_rbac(m, task);
63472 +#endif
63473 +
63474 return 0;
63475 }
63476
63477 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63478 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63479 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63480 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63481 +#endif
63482 +
63483 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63484 struct pid *pid, struct task_struct *task, int whole)
63485 {
63486 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63487 char tcomm[sizeof(task->comm)];
63488 unsigned long flags;
63489
63490 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63491 + if (current->exec_id != m->exec_id) {
63492 + gr_log_badprocpid("stat");
63493 + return 0;
63494 + }
63495 +#endif
63496 +
63497 state = *get_task_state(task);
63498 vsize = eip = esp = 0;
63499 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63500 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63501 gtime = task_gtime(task);
63502 }
63503
63504 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63505 + if (PAX_RAND_FLAGS(mm)) {
63506 + eip = 0;
63507 + esp = 0;
63508 + wchan = 0;
63509 + }
63510 +#endif
63511 +#ifdef CONFIG_GRKERNSEC_HIDESYM
63512 + wchan = 0;
63513 + eip =0;
63514 + esp =0;
63515 +#endif
63516 +
63517 /* scale priority and nice values from timeslices to -20..20 */
63518 /* to make it look like a "normal" Unix priority/nice value */
63519 priority = task_prio(task);
63520 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63521 seq_put_decimal_ull(m, ' ', vsize);
63522 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63523 seq_put_decimal_ull(m, ' ', rsslim);
63524 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63525 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63526 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63527 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63528 +#else
63529 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63530 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63531 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63532 +#endif
63533 seq_put_decimal_ull(m, ' ', esp);
63534 seq_put_decimal_ull(m, ' ', eip);
63535 /* The signal information here is obsolete.
63536 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63537 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63538 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63539
63540 - if (mm && permitted) {
63541 + if (mm && permitted
63542 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63543 + && !PAX_RAND_FLAGS(mm)
63544 +#endif
63545 + ) {
63546 seq_put_decimal_ull(m, ' ', mm->start_data);
63547 seq_put_decimal_ull(m, ' ', mm->end_data);
63548 seq_put_decimal_ull(m, ' ', mm->start_brk);
63549 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63550 struct pid *pid, struct task_struct *task)
63551 {
63552 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63553 - struct mm_struct *mm = get_task_mm(task);
63554 + struct mm_struct *mm;
63555
63556 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63557 + if (current->exec_id != m->exec_id) {
63558 + gr_log_badprocpid("statm");
63559 + return 0;
63560 + }
63561 +#endif
63562 + mm = get_task_mm(task);
63563 if (mm) {
63564 size = task_statm(mm, &shared, &text, &data, &resident);
63565 mmput(mm);
63566 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63567 return 0;
63568 }
63569
63570 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63571 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63572 +{
63573 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63574 +}
63575 +#endif
63576 +
63577 #ifdef CONFIG_CHECKPOINT_RESTORE
63578 static struct pid *
63579 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63580 diff --git a/fs/proc/base.c b/fs/proc/base.c
63581 index b976062..584d0bc 100644
63582 --- a/fs/proc/base.c
63583 +++ b/fs/proc/base.c
63584 @@ -113,6 +113,14 @@ struct pid_entry {
63585 union proc_op op;
63586 };
63587
63588 +struct getdents_callback {
63589 + struct linux_dirent __user * current_dir;
63590 + struct linux_dirent __user * previous;
63591 + struct file * file;
63592 + int count;
63593 + int error;
63594 +};
63595 +
63596 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63597 .name = (NAME), \
63598 .len = sizeof(NAME) - 1, \
63599 @@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
63600 if (!mm->arg_end)
63601 goto out_mm; /* Shh! No looking before we're done */
63602
63603 + if (gr_acl_handle_procpidmem(task))
63604 + goto out_mm;
63605 +
63606 len = mm->arg_end - mm->arg_start;
63607
63608 if (len > PAGE_SIZE)
63609 @@ -237,12 +248,28 @@ out:
63610 return res;
63611 }
63612
63613 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63614 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63615 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63616 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63617 +#endif
63618 +
63619 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63620 {
63621 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63622 int res = PTR_ERR(mm);
63623 if (mm && !IS_ERR(mm)) {
63624 unsigned int nwords = 0;
63625 +
63626 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63627 + /* allow if we're currently ptracing this task */
63628 + if (PAX_RAND_FLAGS(mm) &&
63629 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63630 + mmput(mm);
63631 + return 0;
63632 + }
63633 +#endif
63634 +
63635 do {
63636 nwords += 2;
63637 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63638 @@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63639 }
63640
63641
63642 -#ifdef CONFIG_KALLSYMS
63643 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63644 /*
63645 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63646 * Returns the resolved symbol. If that fails, simply return the address.
63647 @@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
63648 mutex_unlock(&task->signal->cred_guard_mutex);
63649 }
63650
63651 -#ifdef CONFIG_STACKTRACE
63652 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63653
63654 #define MAX_STACK_TRACE_DEPTH 64
63655
63656 @@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63657 return count;
63658 }
63659
63660 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63661 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63662 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63663 {
63664 long nr;
63665 @@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63666 /************************************************************************/
63667
63668 /* permission checks */
63669 -static int proc_fd_access_allowed(struct inode *inode)
63670 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63671 {
63672 struct task_struct *task;
63673 int allowed = 0;
63674 @@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63675 */
63676 task = get_proc_task(inode);
63677 if (task) {
63678 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63679 + if (log)
63680 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63681 + else
63682 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63683 put_task_struct(task);
63684 }
63685 return allowed;
63686 @@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63687 struct task_struct *task,
63688 int hide_pid_min)
63689 {
63690 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63691 + return false;
63692 +
63693 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63694 + rcu_read_lock();
63695 + {
63696 + const struct cred *tmpcred = current_cred();
63697 + const struct cred *cred = __task_cred(task);
63698 +
63699 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63700 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63701 + || in_group_p(grsec_proc_gid)
63702 +#endif
63703 + ) {
63704 + rcu_read_unlock();
63705 + return true;
63706 + }
63707 + }
63708 + rcu_read_unlock();
63709 +
63710 + if (!pid->hide_pid)
63711 + return false;
63712 +#endif
63713 +
63714 if (pid->hide_pid < hide_pid_min)
63715 return true;
63716 if (in_group_p(pid->pid_gid))
63717 return true;
63718 +
63719 return ptrace_may_access(task, PTRACE_MODE_READ);
63720 }
63721
63722 @@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63723 put_task_struct(task);
63724
63725 if (!has_perms) {
63726 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63727 + {
63728 +#else
63729 if (pid->hide_pid == 2) {
63730 +#endif
63731 /*
63732 * Let's make getdents(), stat(), and open()
63733 * consistent with each other. If a process
63734 @@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63735 if (!task)
63736 return -ESRCH;
63737
63738 + if (gr_acl_handle_procpidmem(task)) {
63739 + put_task_struct(task);
63740 + return -EPERM;
63741 + }
63742 +
63743 mm = mm_access(task, mode);
63744 put_task_struct(task);
63745
63746 @@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63747
63748 file->private_data = mm;
63749
63750 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63751 + file->f_version = current->exec_id;
63752 +#endif
63753 +
63754 return 0;
63755 }
63756
63757 @@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63758 ssize_t copied;
63759 char *page;
63760
63761 +#ifdef CONFIG_GRKERNSEC
63762 + if (write)
63763 + return -EPERM;
63764 +#endif
63765 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63766 + if (file->f_version != current->exec_id) {
63767 + gr_log_badprocpid("mem");
63768 + return 0;
63769 + }
63770 +#endif
63771 +
63772 if (!mm)
63773 return 0;
63774
63775 @@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63776 goto free;
63777
63778 while (count > 0) {
63779 - int this_len = min_t(int, count, PAGE_SIZE);
63780 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63781
63782 if (write && copy_from_user(page, buf, this_len)) {
63783 copied = -EFAULT;
63784 @@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63785 if (!mm)
63786 return 0;
63787
63788 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63789 + if (file->f_version != current->exec_id) {
63790 + gr_log_badprocpid("environ");
63791 + return 0;
63792 + }
63793 +#endif
63794 +
63795 page = (char *)__get_free_page(GFP_TEMPORARY);
63796 if (!page)
63797 return -ENOMEM;
63798 @@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63799 goto free;
63800 while (count > 0) {
63801 size_t this_len, max_len;
63802 - int retval;
63803 + ssize_t retval;
63804
63805 if (src >= (mm->env_end - mm->env_start))
63806 break;
63807 @@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63808 int error = -EACCES;
63809
63810 /* Are we allowed to snoop on the tasks file descriptors? */
63811 - if (!proc_fd_access_allowed(inode))
63812 + if (!proc_fd_access_allowed(inode, 0))
63813 goto out;
63814
63815 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63816 @@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63817 struct path path;
63818
63819 /* Are we allowed to snoop on the tasks file descriptors? */
63820 - if (!proc_fd_access_allowed(inode))
63821 - goto out;
63822 + /* logging this is needed for learning on chromium to work properly,
63823 + but we don't want to flood the logs from 'ps' which does a readlink
63824 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63825 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
63826 + */
63827 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63828 + if (!proc_fd_access_allowed(inode,0))
63829 + goto out;
63830 + } else {
63831 + if (!proc_fd_access_allowed(inode,1))
63832 + goto out;
63833 + }
63834
63835 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63836 if (error)
63837 @@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63838 rcu_read_lock();
63839 cred = __task_cred(task);
63840 inode->i_uid = cred->euid;
63841 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63842 + inode->i_gid = grsec_proc_gid;
63843 +#else
63844 inode->i_gid = cred->egid;
63845 +#endif
63846 rcu_read_unlock();
63847 }
63848 security_task_to_inode(task, inode);
63849 @@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63850 return -ENOENT;
63851 }
63852 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63853 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63854 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63855 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63856 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63857 +#endif
63858 task_dumpable(task)) {
63859 cred = __task_cred(task);
63860 stat->uid = cred->euid;
63861 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63862 + stat->gid = grsec_proc_gid;
63863 +#else
63864 stat->gid = cred->egid;
63865 +#endif
63866 }
63867 }
63868 rcu_read_unlock();
63869 @@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63870
63871 if (task) {
63872 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63873 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63874 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63875 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63876 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63877 +#endif
63878 task_dumpable(task)) {
63879 rcu_read_lock();
63880 cred = __task_cred(task);
63881 inode->i_uid = cred->euid;
63882 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63883 + inode->i_gid = grsec_proc_gid;
63884 +#else
63885 inode->i_gid = cred->egid;
63886 +#endif
63887 rcu_read_unlock();
63888 } else {
63889 inode->i_uid = GLOBAL_ROOT_UID;
63890 @@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63891 if (!task)
63892 goto out_no_task;
63893
63894 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63895 + goto out;
63896 +
63897 /*
63898 * Yes, it does not scale. And it should not. Don't add
63899 * new entries into /proc/<tgid>/ without very good reasons.
63900 @@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63901 if (!task)
63902 return -ENOENT;
63903
63904 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63905 + goto out;
63906 +
63907 if (!dir_emit_dots(file, ctx))
63908 goto out;
63909
63910 @@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63911 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63912 #endif
63913 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63914 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63915 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63916 INF("syscall", S_IRUGO, proc_pid_syscall),
63917 #endif
63918 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63919 @@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63920 #ifdef CONFIG_SECURITY
63921 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63922 #endif
63923 -#ifdef CONFIG_KALLSYMS
63924 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63925 INF("wchan", S_IRUGO, proc_pid_wchan),
63926 #endif
63927 -#ifdef CONFIG_STACKTRACE
63928 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63929 ONE("stack", S_IRUGO, proc_pid_stack),
63930 #endif
63931 #ifdef CONFIG_SCHEDSTATS
63932 @@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63933 #ifdef CONFIG_HARDWALL
63934 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63935 #endif
63936 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63937 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63938 +#endif
63939 #ifdef CONFIG_USER_NS
63940 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63941 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63942 @@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
63943 if (!inode)
63944 goto out;
63945
63946 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63947 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63948 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63949 + inode->i_gid = grsec_proc_gid;
63950 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63951 +#else
63952 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63953 +#endif
63954 inode->i_op = &proc_tgid_base_inode_operations;
63955 inode->i_fop = &proc_tgid_base_operations;
63956 inode->i_flags|=S_IMMUTABLE;
63957 @@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63958 if (!task)
63959 goto out;
63960
63961 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63962 + goto out_put_task;
63963 +
63964 result = proc_pid_instantiate(dir, dentry, task, NULL);
63965 +out_put_task:
63966 put_task_struct(task);
63967 out:
63968 return ERR_PTR(result);
63969 @@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
63970 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63971 #endif
63972 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63973 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63974 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63975 INF("syscall", S_IRUGO, proc_pid_syscall),
63976 #endif
63977 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63978 @@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
63979 #ifdef CONFIG_SECURITY
63980 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63981 #endif
63982 -#ifdef CONFIG_KALLSYMS
63983 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63984 INF("wchan", S_IRUGO, proc_pid_wchan),
63985 #endif
63986 -#ifdef CONFIG_STACKTRACE
63987 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63988 ONE("stack", S_IRUGO, proc_pid_stack),
63989 #endif
63990 #ifdef CONFIG_SCHEDSTATS
63991 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63992 index cbd82df..c0407d2 100644
63993 --- a/fs/proc/cmdline.c
63994 +++ b/fs/proc/cmdline.c
63995 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63996
63997 static int __init proc_cmdline_init(void)
63998 {
63999 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64000 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
64001 +#else
64002 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
64003 +#endif
64004 return 0;
64005 }
64006 fs_initcall(proc_cmdline_init);
64007 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
64008 index 50493ed..248166b 100644
64009 --- a/fs/proc/devices.c
64010 +++ b/fs/proc/devices.c
64011 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
64012
64013 static int __init proc_devices_init(void)
64014 {
64015 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64016 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
64017 +#else
64018 proc_create("devices", 0, NULL, &proc_devinfo_operations);
64019 +#endif
64020 return 0;
64021 }
64022 fs_initcall(proc_devices_init);
64023 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
64024 index 985ea88..d118a0a 100644
64025 --- a/fs/proc/fd.c
64026 +++ b/fs/proc/fd.c
64027 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
64028 if (!task)
64029 return -ENOENT;
64030
64031 - files = get_files_struct(task);
64032 + if (!gr_acl_handle_procpidmem(task))
64033 + files = get_files_struct(task);
64034 put_task_struct(task);
64035
64036 if (files) {
64037 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
64038 */
64039 int proc_fd_permission(struct inode *inode, int mask)
64040 {
64041 + struct task_struct *task;
64042 int rv = generic_permission(inode, mask);
64043 - if (rv == 0)
64044 - return 0;
64045 +
64046 if (task_tgid(current) == proc_pid(inode))
64047 rv = 0;
64048 +
64049 + task = get_proc_task(inode);
64050 + if (task == NULL)
64051 + return rv;
64052 +
64053 + if (gr_acl_handle_procpidmem(task))
64054 + rv = -EACCES;
64055 +
64056 + put_task_struct(task);
64057 +
64058 return rv;
64059 }
64060
64061 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
64062 index b7f268e..3bea6b7 100644
64063 --- a/fs/proc/generic.c
64064 +++ b/fs/proc/generic.c
64065 @@ -23,6 +23,7 @@
64066 #include <linux/bitops.h>
64067 #include <linux/spinlock.h>
64068 #include <linux/completion.h>
64069 +#include <linux/grsecurity.h>
64070 #include <asm/uaccess.h>
64071
64072 #include "internal.h"
64073 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
64074 return proc_lookup_de(PDE(dir), dir, dentry);
64075 }
64076
64077 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
64078 + unsigned int flags)
64079 +{
64080 + if (gr_proc_is_restricted())
64081 + return ERR_PTR(-EACCES);
64082 +
64083 + return proc_lookup_de(PDE(dir), dir, dentry);
64084 +}
64085 +
64086 /*
64087 * This returns non-zero if at EOF, so that the /proc
64088 * root directory can use this and check if it should
64089 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
64090 return proc_readdir_de(PDE(inode), file, ctx);
64091 }
64092
64093 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
64094 +{
64095 + struct inode *inode = file_inode(file);
64096 +
64097 + if (gr_proc_is_restricted())
64098 + return -EACCES;
64099 +
64100 + return proc_readdir_de(PDE(inode), file, ctx);
64101 +}
64102 +
64103 /*
64104 * These are the generic /proc directory operations. They
64105 * use the in-memory "struct proc_dir_entry" tree to parse
64106 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
64107 .iterate = proc_readdir,
64108 };
64109
64110 +static const struct file_operations proc_dir_restricted_operations = {
64111 + .llseek = generic_file_llseek,
64112 + .read = generic_read_dir,
64113 + .iterate = proc_readdir_restrict,
64114 +};
64115 +
64116 /*
64117 * proc directories can do almost nothing..
64118 */
64119 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
64120 .setattr = proc_notify_change,
64121 };
64122
64123 +static const struct inode_operations proc_dir_restricted_inode_operations = {
64124 + .lookup = proc_lookup_restrict,
64125 + .getattr = proc_getattr,
64126 + .setattr = proc_notify_change,
64127 +};
64128 +
64129 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
64130 {
64131 struct proc_dir_entry *tmp;
64132 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
64133 return ret;
64134
64135 if (S_ISDIR(dp->mode)) {
64136 - dp->proc_fops = &proc_dir_operations;
64137 - dp->proc_iops = &proc_dir_inode_operations;
64138 + if (dp->restricted) {
64139 + dp->proc_fops = &proc_dir_restricted_operations;
64140 + dp->proc_iops = &proc_dir_restricted_inode_operations;
64141 + } else {
64142 + dp->proc_fops = &proc_dir_operations;
64143 + dp->proc_iops = &proc_dir_inode_operations;
64144 + }
64145 dir->nlink++;
64146 } else if (S_ISLNK(dp->mode)) {
64147 dp->proc_iops = &proc_link_inode_operations;
64148 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
64149 }
64150 EXPORT_SYMBOL_GPL(proc_mkdir_data);
64151
64152 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
64153 + struct proc_dir_entry *parent, void *data)
64154 +{
64155 + struct proc_dir_entry *ent;
64156 +
64157 + if (mode == 0)
64158 + mode = S_IRUGO | S_IXUGO;
64159 +
64160 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
64161 + if (ent) {
64162 + ent->data = data;
64163 + ent->restricted = 1;
64164 + if (proc_register(parent, ent) < 0) {
64165 + kfree(ent);
64166 + ent = NULL;
64167 + }
64168 + }
64169 + return ent;
64170 +}
64171 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
64172 +
64173 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
64174 struct proc_dir_entry *parent)
64175 {
64176 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
64177 }
64178 EXPORT_SYMBOL(proc_mkdir);
64179
64180 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
64181 + struct proc_dir_entry *parent)
64182 +{
64183 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
64184 +}
64185 +EXPORT_SYMBOL(proc_mkdir_restrict);
64186 +
64187 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
64188 struct proc_dir_entry *parent,
64189 const struct file_operations *proc_fops,
64190 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
64191 index 124fc43..8afbb02 100644
64192 --- a/fs/proc/inode.c
64193 +++ b/fs/proc/inode.c
64194 @@ -23,11 +23,17 @@
64195 #include <linux/slab.h>
64196 #include <linux/mount.h>
64197 #include <linux/magic.h>
64198 +#include <linux/grsecurity.h>
64199
64200 #include <asm/uaccess.h>
64201
64202 #include "internal.h"
64203
64204 +#ifdef CONFIG_PROC_SYSCTL
64205 +extern const struct inode_operations proc_sys_inode_operations;
64206 +extern const struct inode_operations proc_sys_dir_operations;
64207 +#endif
64208 +
64209 static void proc_evict_inode(struct inode *inode)
64210 {
64211 struct proc_dir_entry *de;
64212 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
64213 ns = PROC_I(inode)->ns.ns;
64214 if (ns_ops && ns)
64215 ns_ops->put(ns);
64216 +
64217 +#ifdef CONFIG_PROC_SYSCTL
64218 + if (inode->i_op == &proc_sys_inode_operations ||
64219 + inode->i_op == &proc_sys_dir_operations)
64220 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
64221 +#endif
64222 +
64223 }
64224
64225 static struct kmem_cache * proc_inode_cachep;
64226 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
64227 if (de->mode) {
64228 inode->i_mode = de->mode;
64229 inode->i_uid = de->uid;
64230 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64231 + inode->i_gid = grsec_proc_gid;
64232 +#else
64233 inode->i_gid = de->gid;
64234 +#endif
64235 }
64236 if (de->size)
64237 inode->i_size = de->size;
64238 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
64239 index 651d09a..6a4b495 100644
64240 --- a/fs/proc/internal.h
64241 +++ b/fs/proc/internal.h
64242 @@ -46,9 +46,10 @@ struct proc_dir_entry {
64243 struct completion *pde_unload_completion;
64244 struct list_head pde_openers; /* who did ->open, but not ->release */
64245 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64246 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64247 u8 namelen;
64248 char name[];
64249 -};
64250 +} __randomize_layout;
64251
64252 union proc_op {
64253 int (*proc_get_link)(struct dentry *, struct path *);
64254 @@ -67,7 +68,7 @@ struct proc_inode {
64255 struct ctl_table *sysctl_entry;
64256 struct proc_ns ns;
64257 struct inode vfs_inode;
64258 -};
64259 +} __randomize_layout;
64260
64261 /*
64262 * General functions
64263 @@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64264 struct pid *, struct task_struct *);
64265 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64266 struct pid *, struct task_struct *);
64267 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64268 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64269 +#endif
64270
64271 /*
64272 * base.c
64273 @@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64274 extern spinlock_t proc_subdir_lock;
64275
64276 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64277 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64278 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64279 struct dentry *);
64280 extern int proc_readdir(struct file *, struct dir_context *);
64281 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
64282 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64283
64284 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64285 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64286 index a352d57..cb94a5c 100644
64287 --- a/fs/proc/interrupts.c
64288 +++ b/fs/proc/interrupts.c
64289 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64290
64291 static int __init proc_interrupts_init(void)
64292 {
64293 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64294 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64295 +#else
64296 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64297 +#endif
64298 return 0;
64299 }
64300 fs_initcall(proc_interrupts_init);
64301 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64302 index 39e6ef3..2f9cb5e 100644
64303 --- a/fs/proc/kcore.c
64304 +++ b/fs/proc/kcore.c
64305 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64306 * the addresses in the elf_phdr on our list.
64307 */
64308 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64309 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64310 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64311 + if (tsz > buflen)
64312 tsz = buflen;
64313 -
64314 +
64315 while (buflen) {
64316 struct kcore_list *m;
64317
64318 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64319 kfree(elf_buf);
64320 } else {
64321 if (kern_addr_valid(start)) {
64322 - unsigned long n;
64323 + char *elf_buf;
64324 + mm_segment_t oldfs;
64325
64326 - n = copy_to_user(buffer, (char *)start, tsz);
64327 - /*
64328 - * We cannot distinguish between fault on source
64329 - * and fault on destination. When this happens
64330 - * we clear too and hope it will trigger the
64331 - * EFAULT again.
64332 - */
64333 - if (n) {
64334 - if (clear_user(buffer + tsz - n,
64335 - n))
64336 + elf_buf = kmalloc(tsz, GFP_KERNEL);
64337 + if (!elf_buf)
64338 + return -ENOMEM;
64339 + oldfs = get_fs();
64340 + set_fs(KERNEL_DS);
64341 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64342 + set_fs(oldfs);
64343 + if (copy_to_user(buffer, elf_buf, tsz)) {
64344 + kfree(elf_buf);
64345 return -EFAULT;
64346 + }
64347 }
64348 + set_fs(oldfs);
64349 + kfree(elf_buf);
64350 } else {
64351 if (clear_user(buffer, tsz))
64352 return -EFAULT;
64353 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64354
64355 static int open_kcore(struct inode *inode, struct file *filp)
64356 {
64357 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64358 + return -EPERM;
64359 +#endif
64360 if (!capable(CAP_SYS_RAWIO))
64361 return -EPERM;
64362 if (kcore_need_update)
64363 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64364 index 136e548..1f88922 100644
64365 --- a/fs/proc/meminfo.c
64366 +++ b/fs/proc/meminfo.c
64367 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64368 vmi.used >> 10,
64369 vmi.largest_chunk >> 10
64370 #ifdef CONFIG_MEMORY_FAILURE
64371 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64372 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64373 #endif
64374 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64375 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64376 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64377 index d4a3574..b421ce9 100644
64378 --- a/fs/proc/nommu.c
64379 +++ b/fs/proc/nommu.c
64380 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64381
64382 if (file) {
64383 seq_pad(m, ' ');
64384 - seq_path(m, &file->f_path, "");
64385 + seq_path(m, &file->f_path, "\n\\");
64386 }
64387
64388 seq_putc(m, '\n');
64389 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64390 index 4677bb7..94067cd 100644
64391 --- a/fs/proc/proc_net.c
64392 +++ b/fs/proc/proc_net.c
64393 @@ -23,6 +23,7 @@
64394 #include <linux/nsproxy.h>
64395 #include <net/net_namespace.h>
64396 #include <linux/seq_file.h>
64397 +#include <linux/grsecurity.h>
64398
64399 #include "internal.h"
64400
64401 @@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
64402 return maybe_get_net(PDE_NET(PDE(inode)));
64403 }
64404
64405 +extern const struct seq_operations dev_seq_ops;
64406 +
64407 int seq_open_net(struct inode *ino, struct file *f,
64408 const struct seq_operations *ops, int size)
64409 {
64410 @@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
64411
64412 BUG_ON(size < sizeof(*p));
64413
64414 + /* only permit access to /proc/net/dev */
64415 + if (ops != &dev_seq_ops && gr_proc_is_restricted())
64416 + return -EACCES;
64417 +
64418 net = get_proc_net(ino);
64419 if (net == NULL)
64420 return -ENXIO;
64421 @@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
64422 int err;
64423 struct net *net;
64424
64425 + if (gr_proc_is_restricted())
64426 + return -EACCES;
64427 +
64428 err = -ENXIO;
64429 net = get_proc_net(inode);
64430 if (net == NULL)
64431 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64432 index 7129046..6914844 100644
64433 --- a/fs/proc/proc_sysctl.c
64434 +++ b/fs/proc/proc_sysctl.c
64435 @@ -11,13 +11,21 @@
64436 #include <linux/namei.h>
64437 #include <linux/mm.h>
64438 #include <linux/module.h>
64439 +#include <linux/nsproxy.h>
64440 +#ifdef CONFIG_GRKERNSEC
64441 +#include <net/net_namespace.h>
64442 +#endif
64443 #include "internal.h"
64444
64445 +extern int gr_handle_chroot_sysctl(const int op);
64446 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64447 + const int op);
64448 +
64449 static const struct dentry_operations proc_sys_dentry_operations;
64450 static const struct file_operations proc_sys_file_operations;
64451 -static const struct inode_operations proc_sys_inode_operations;
64452 +const struct inode_operations proc_sys_inode_operations;
64453 static const struct file_operations proc_sys_dir_file_operations;
64454 -static const struct inode_operations proc_sys_dir_operations;
64455 +const struct inode_operations proc_sys_dir_operations;
64456
64457 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64458 {
64459 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64460
64461 err = NULL;
64462 d_set_d_op(dentry, &proc_sys_dentry_operations);
64463 +
64464 + gr_handle_proc_create(dentry, inode);
64465 +
64466 d_add(dentry, inode);
64467
64468 out:
64469 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64470 struct inode *inode = file_inode(filp);
64471 struct ctl_table_header *head = grab_header(inode);
64472 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64473 + int op = write ? MAY_WRITE : MAY_READ;
64474 ssize_t error;
64475 size_t res;
64476
64477 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64478 * and won't be until we finish.
64479 */
64480 error = -EPERM;
64481 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64482 + if (sysctl_perm(head, table, op))
64483 goto out;
64484
64485 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64486 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64487 if (!table->proc_handler)
64488 goto out;
64489
64490 +#ifdef CONFIG_GRKERNSEC
64491 + error = -EPERM;
64492 + if (gr_handle_chroot_sysctl(op))
64493 + goto out;
64494 + dget(filp->f_path.dentry);
64495 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64496 + dput(filp->f_path.dentry);
64497 + goto out;
64498 + }
64499 + dput(filp->f_path.dentry);
64500 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64501 + goto out;
64502 + if (write) {
64503 + if (current->nsproxy->net_ns != table->extra2) {
64504 + if (!capable(CAP_SYS_ADMIN))
64505 + goto out;
64506 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64507 + goto out;
64508 + }
64509 +#endif
64510 +
64511 /* careful: calling conventions are nasty here */
64512 res = count;
64513 error = table->proc_handler(table, write, buf, &res, ppos);
64514 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64515 return false;
64516 } else {
64517 d_set_d_op(child, &proc_sys_dentry_operations);
64518 +
64519 + gr_handle_proc_create(child, inode);
64520 +
64521 d_add(child, inode);
64522 }
64523 } else {
64524 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64525 if ((*pos)++ < ctx->pos)
64526 return true;
64527
64528 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64529 + return 0;
64530 +
64531 if (unlikely(S_ISLNK(table->mode)))
64532 res = proc_sys_link_fill_cache(file, ctx, head, table);
64533 else
64534 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64535 if (IS_ERR(head))
64536 return PTR_ERR(head);
64537
64538 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64539 + return -ENOENT;
64540 +
64541 generic_fillattr(inode, stat);
64542 if (table)
64543 stat->mode = (stat->mode & S_IFMT) | table->mode;
64544 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64545 .llseek = generic_file_llseek,
64546 };
64547
64548 -static const struct inode_operations proc_sys_inode_operations = {
64549 +const struct inode_operations proc_sys_inode_operations = {
64550 .permission = proc_sys_permission,
64551 .setattr = proc_sys_setattr,
64552 .getattr = proc_sys_getattr,
64553 };
64554
64555 -static const struct inode_operations proc_sys_dir_operations = {
64556 +const struct inode_operations proc_sys_dir_operations = {
64557 .lookup = proc_sys_lookup,
64558 .permission = proc_sys_permission,
64559 .setattr = proc_sys_setattr,
64560 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64561 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64562 const char *name, int namelen)
64563 {
64564 - struct ctl_table *table;
64565 + ctl_table_no_const *table;
64566 struct ctl_dir *new;
64567 struct ctl_node *node;
64568 char *new_name;
64569 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64570 return NULL;
64571
64572 node = (struct ctl_node *)(new + 1);
64573 - table = (struct ctl_table *)(node + 1);
64574 + table = (ctl_table_no_const *)(node + 1);
64575 new_name = (char *)(table + 2);
64576 memcpy(new_name, name, namelen);
64577 new_name[namelen] = '\0';
64578 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64579 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64580 struct ctl_table_root *link_root)
64581 {
64582 - struct ctl_table *link_table, *entry, *link;
64583 + ctl_table_no_const *link_table, *link;
64584 + struct ctl_table *entry;
64585 struct ctl_table_header *links;
64586 struct ctl_node *node;
64587 char *link_name;
64588 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64589 return NULL;
64590
64591 node = (struct ctl_node *)(links + 1);
64592 - link_table = (struct ctl_table *)(node + nr_entries);
64593 + link_table = (ctl_table_no_const *)(node + nr_entries);
64594 link_name = (char *)&link_table[nr_entries + 1];
64595
64596 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64597 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64598 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64599 struct ctl_table *table)
64600 {
64601 - struct ctl_table *ctl_table_arg = NULL;
64602 - struct ctl_table *entry, *files;
64603 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64604 + struct ctl_table *entry;
64605 int nr_files = 0;
64606 int nr_dirs = 0;
64607 int err = -ENOMEM;
64608 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64609 nr_files++;
64610 }
64611
64612 - files = table;
64613 /* If there are mixed files and directories we need a new table */
64614 if (nr_dirs && nr_files) {
64615 - struct ctl_table *new;
64616 + ctl_table_no_const *new;
64617 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64618 GFP_KERNEL);
64619 if (!files)
64620 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64621 /* Register everything except a directory full of subdirectories */
64622 if (nr_files || !nr_dirs) {
64623 struct ctl_table_header *header;
64624 - header = __register_sysctl_table(set, path, files);
64625 + header = __register_sysctl_table(set, path, files ? files : table);
64626 if (!header) {
64627 kfree(ctl_table_arg);
64628 goto out;
64629 diff --git a/fs/proc/root.c b/fs/proc/root.c
64630 index 87dbcbe..55e1b4d 100644
64631 --- a/fs/proc/root.c
64632 +++ b/fs/proc/root.c
64633 @@ -186,7 +186,15 @@ void __init proc_root_init(void)
64634 #ifdef CONFIG_PROC_DEVICETREE
64635 proc_device_tree_init();
64636 #endif
64637 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64638 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64639 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64640 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64641 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64642 +#endif
64643 +#else
64644 proc_mkdir("bus", NULL);
64645 +#endif
64646 proc_sys_init();
64647 }
64648
64649 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64650 index 6f599c6..bd00271 100644
64651 --- a/fs/proc/stat.c
64652 +++ b/fs/proc/stat.c
64653 @@ -11,6 +11,7 @@
64654 #include <linux/irqnr.h>
64655 #include <asm/cputime.h>
64656 #include <linux/tick.h>
64657 +#include <linux/grsecurity.h>
64658
64659 #ifndef arch_irq_stat_cpu
64660 #define arch_irq_stat_cpu(cpu) 0
64661 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64662 u64 sum_softirq = 0;
64663 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64664 struct timespec boottime;
64665 + int unrestricted = 1;
64666 +
64667 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64668 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64669 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64670 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64671 + && !in_group_p(grsec_proc_gid)
64672 +#endif
64673 + )
64674 + unrestricted = 0;
64675 +#endif
64676 +#endif
64677
64678 user = nice = system = idle = iowait =
64679 irq = softirq = steal = 0;
64680 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64681 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64682 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64683 idle += get_idle_time(i);
64684 - iowait += get_iowait_time(i);
64685 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64686 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64687 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64688 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64689 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64690 - sum += kstat_cpu_irqs_sum(i);
64691 - sum += arch_irq_stat_cpu(i);
64692 + if (unrestricted) {
64693 + iowait += get_iowait_time(i);
64694 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64695 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64696 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64697 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64698 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64699 + sum += kstat_cpu_irqs_sum(i);
64700 + sum += arch_irq_stat_cpu(i);
64701 + for (j = 0; j < NR_SOFTIRQS; j++) {
64702 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64703
64704 - for (j = 0; j < NR_SOFTIRQS; j++) {
64705 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64706 -
64707 - per_softirq_sums[j] += softirq_stat;
64708 - sum_softirq += softirq_stat;
64709 + per_softirq_sums[j] += softirq_stat;
64710 + sum_softirq += softirq_stat;
64711 + }
64712 }
64713 }
64714 - sum += arch_irq_stat();
64715 + if (unrestricted)
64716 + sum += arch_irq_stat();
64717
64718 seq_puts(p, "cpu ");
64719 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64720 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64721 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64722 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64723 idle = get_idle_time(i);
64724 - iowait = get_iowait_time(i);
64725 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64726 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64727 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64728 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64729 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64730 + if (unrestricted) {
64731 + iowait = get_iowait_time(i);
64732 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64733 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64734 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64735 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64736 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64737 + }
64738 seq_printf(p, "cpu%d", i);
64739 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64740 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64741 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64742
64743 /* sum again ? it could be updated? */
64744 for_each_irq_nr(j)
64745 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64746 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64747
64748 seq_printf(p,
64749 "\nctxt %llu\n"
64750 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64751 "processes %lu\n"
64752 "procs_running %lu\n"
64753 "procs_blocked %lu\n",
64754 - nr_context_switches(),
64755 + unrestricted ? nr_context_switches() : 0ULL,
64756 (unsigned long)jif,
64757 - total_forks,
64758 - nr_running(),
64759 - nr_iowait());
64760 + unrestricted ? total_forks : 0UL,
64761 + unrestricted ? nr_running() : 0UL,
64762 + unrestricted ? nr_iowait() : 0UL);
64763
64764 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64765
64766 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64767 index fb52b54..5fc7c14 100644
64768 --- a/fs/proc/task_mmu.c
64769 +++ b/fs/proc/task_mmu.c
64770 @@ -12,12 +12,19 @@
64771 #include <linux/swap.h>
64772 #include <linux/swapops.h>
64773 #include <linux/mmu_notifier.h>
64774 +#include <linux/grsecurity.h>
64775
64776 #include <asm/elf.h>
64777 #include <asm/uaccess.h>
64778 #include <asm/tlbflush.h>
64779 #include "internal.h"
64780
64781 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64782 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64783 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
64784 + _mm->pax_flags & MF_PAX_SEGMEXEC))
64785 +#endif
64786 +
64787 void task_mem(struct seq_file *m, struct mm_struct *mm)
64788 {
64789 unsigned long data, text, lib, swap;
64790 @@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64791 "VmExe:\t%8lu kB\n"
64792 "VmLib:\t%8lu kB\n"
64793 "VmPTE:\t%8lu kB\n"
64794 - "VmSwap:\t%8lu kB\n",
64795 - hiwater_vm << (PAGE_SHIFT-10),
64796 + "VmSwap:\t%8lu kB\n"
64797 +
64798 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64799 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64800 +#endif
64801 +
64802 + ,hiwater_vm << (PAGE_SHIFT-10),
64803 total_vm << (PAGE_SHIFT-10),
64804 mm->locked_vm << (PAGE_SHIFT-10),
64805 mm->pinned_vm << (PAGE_SHIFT-10),
64806 @@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64807 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64808 (PTRS_PER_PTE * sizeof(pte_t) *
64809 atomic_long_read(&mm->nr_ptes)) >> 10,
64810 - swap << (PAGE_SHIFT-10));
64811 + swap << (PAGE_SHIFT-10)
64812 +
64813 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64814 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64815 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64816 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64817 +#else
64818 + , mm->context.user_cs_base
64819 + , mm->context.user_cs_limit
64820 +#endif
64821 +#endif
64822 +
64823 + );
64824 }
64825
64826 unsigned long task_vsize(struct mm_struct *mm)
64827 @@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64828 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64829 }
64830
64831 - /* We don't show the stack guard page in /proc/maps */
64832 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64833 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64834 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64835 +#else
64836 start = vma->vm_start;
64837 - if (stack_guard_page_start(vma, start))
64838 - start += PAGE_SIZE;
64839 end = vma->vm_end;
64840 - if (stack_guard_page_end(vma, end))
64841 - end -= PAGE_SIZE;
64842 +#endif
64843
64844 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64845 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64846 @@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64847 flags & VM_WRITE ? 'w' : '-',
64848 flags & VM_EXEC ? 'x' : '-',
64849 flags & VM_MAYSHARE ? 's' : 'p',
64850 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64851 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64852 +#else
64853 pgoff,
64854 +#endif
64855 MAJOR(dev), MINOR(dev), ino);
64856
64857 /*
64858 @@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64859 */
64860 if (file) {
64861 seq_pad(m, ' ');
64862 - seq_path(m, &file->f_path, "\n");
64863 + seq_path(m, &file->f_path, "\n\\");
64864 goto done;
64865 }
64866
64867 @@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64868 * Thread stack in /proc/PID/task/TID/maps or
64869 * the main process stack.
64870 */
64871 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
64872 - vma->vm_end >= mm->start_stack)) {
64873 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64874 + (vma->vm_start <= mm->start_stack &&
64875 + vma->vm_end >= mm->start_stack)) {
64876 name = "[stack]";
64877 } else {
64878 /* Thread stack in /proc/PID/maps */
64879 @@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64880 struct proc_maps_private *priv = m->private;
64881 struct task_struct *task = priv->task;
64882
64883 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64884 + if (current->exec_id != m->exec_id) {
64885 + gr_log_badprocpid("maps");
64886 + return 0;
64887 + }
64888 +#endif
64889 +
64890 show_map_vma(m, vma, is_pid);
64891
64892 if (m->count < m->size) /* vma is copied successfully */
64893 @@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64894 .private = &mss,
64895 };
64896
64897 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64898 + if (current->exec_id != m->exec_id) {
64899 + gr_log_badprocpid("smaps");
64900 + return 0;
64901 + }
64902 +#endif
64903 memset(&mss, 0, sizeof mss);
64904 - mss.vma = vma;
64905 - /* mmap_sem is held in m_start */
64906 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64907 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64908 -
64909 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64910 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64911 +#endif
64912 + mss.vma = vma;
64913 + /* mmap_sem is held in m_start */
64914 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64915 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64916 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64917 + }
64918 +#endif
64919 show_map_vma(m, vma, is_pid);
64920
64921 seq_printf(m,
64922 @@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64923 "KernelPageSize: %8lu kB\n"
64924 "MMUPageSize: %8lu kB\n"
64925 "Locked: %8lu kB\n",
64926 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64927 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64928 +#else
64929 (vma->vm_end - vma->vm_start) >> 10,
64930 +#endif
64931 mss.resident >> 10,
64932 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64933 mss.shared_clean >> 10,
64934 @@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64935 char buffer[64];
64936 int nid;
64937
64938 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64939 + if (current->exec_id != m->exec_id) {
64940 + gr_log_badprocpid("numa_maps");
64941 + return 0;
64942 + }
64943 +#endif
64944 +
64945 if (!mm)
64946 return 0;
64947
64948 @@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64949 mpol_to_str(buffer, sizeof(buffer), pol);
64950 mpol_cond_put(pol);
64951
64952 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64953 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64954 +#else
64955 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64956 +#endif
64957
64958 if (file) {
64959 seq_printf(m, " file=");
64960 - seq_path(m, &file->f_path, "\n\t= ");
64961 + seq_path(m, &file->f_path, "\n\t\\= ");
64962 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64963 seq_printf(m, " heap");
64964 } else {
64965 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64966 index 678455d..ebd3245 100644
64967 --- a/fs/proc/task_nommu.c
64968 +++ b/fs/proc/task_nommu.c
64969 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64970 else
64971 bytes += kobjsize(mm);
64972
64973 - if (current->fs && current->fs->users > 1)
64974 + if (current->fs && atomic_read(&current->fs->users) > 1)
64975 sbytes += kobjsize(current->fs);
64976 else
64977 bytes += kobjsize(current->fs);
64978 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64979
64980 if (file) {
64981 seq_pad(m, ' ');
64982 - seq_path(m, &file->f_path, "");
64983 + seq_path(m, &file->f_path, "\n\\");
64984 } else if (mm) {
64985 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64986
64987 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64988 index 88d4585..c10bfeb 100644
64989 --- a/fs/proc/vmcore.c
64990 +++ b/fs/proc/vmcore.c
64991 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64992 nr_bytes = count;
64993
64994 /* If pfn is not ram, return zeros for sparse dump files */
64995 - if (pfn_is_ram(pfn) == 0)
64996 - memset(buf, 0, nr_bytes);
64997 - else {
64998 + if (pfn_is_ram(pfn) == 0) {
64999 + if (userbuf) {
65000 + if (clear_user((char __force_user *)buf, nr_bytes))
65001 + return -EFAULT;
65002 + } else
65003 + memset(buf, 0, nr_bytes);
65004 + } else {
65005 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
65006 offset, userbuf);
65007 if (tmp < 0)
65008 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
65009 static int copy_to(void *target, void *src, size_t size, int userbuf)
65010 {
65011 if (userbuf) {
65012 - if (copy_to_user((char __user *) target, src, size))
65013 + if (copy_to_user((char __force_user *) target, src, size))
65014 return -EFAULT;
65015 } else {
65016 memcpy(target, src, size);
65017 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65018 if (*fpos < m->offset + m->size) {
65019 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
65020 start = m->paddr + *fpos - m->offset;
65021 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
65022 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
65023 if (tmp < 0)
65024 return tmp;
65025 buflen -= tsz;
65026 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
65027 static ssize_t read_vmcore(struct file *file, char __user *buffer,
65028 size_t buflen, loff_t *fpos)
65029 {
65030 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
65031 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
65032 }
65033
65034 /*
65035 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
65036 index b00fcc9..e0c6381 100644
65037 --- a/fs/qnx6/qnx6.h
65038 +++ b/fs/qnx6/qnx6.h
65039 @@ -74,7 +74,7 @@ enum {
65040 BYTESEX_BE,
65041 };
65042
65043 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65044 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
65045 {
65046 if (sbi->s_bytesex == BYTESEX_LE)
65047 return le64_to_cpu((__force __le64)n);
65048 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
65049 return (__force __fs64)cpu_to_be64(n);
65050 }
65051
65052 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65053 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65054 {
65055 if (sbi->s_bytesex == BYTESEX_LE)
65056 return le32_to_cpu((__force __le32)n);
65057 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
65058 index 72d2917..c917c12 100644
65059 --- a/fs/quota/netlink.c
65060 +++ b/fs/quota/netlink.c
65061 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
65062 void quota_send_warning(struct kqid qid, dev_t dev,
65063 const char warntype)
65064 {
65065 - static atomic_t seq;
65066 + static atomic_unchecked_t seq;
65067 struct sk_buff *skb;
65068 void *msg_head;
65069 int ret;
65070 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
65071 "VFS: Not enough memory to send quota warning.\n");
65072 return;
65073 }
65074 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
65075 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
65076 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
65077 if (!msg_head) {
65078 printk(KERN_ERR
65079 diff --git a/fs/read_write.c b/fs/read_write.c
65080 index 28cc9c8..208e4fb 100644
65081 --- a/fs/read_write.c
65082 +++ b/fs/read_write.c
65083 @@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
65084
65085 old_fs = get_fs();
65086 set_fs(get_ds());
65087 - p = (__force const char __user *)buf;
65088 + p = (const char __force_user *)buf;
65089 if (count > MAX_RW_COUNT)
65090 count = MAX_RW_COUNT;
65091 if (file->f_op->write)
65092 diff --git a/fs/readdir.c b/fs/readdir.c
65093 index 5b53d99..a6c3049 100644
65094 --- a/fs/readdir.c
65095 +++ b/fs/readdir.c
65096 @@ -17,6 +17,7 @@
65097 #include <linux/security.h>
65098 #include <linux/syscalls.h>
65099 #include <linux/unistd.h>
65100 +#include <linux/namei.h>
65101
65102 #include <asm/uaccess.h>
65103
65104 @@ -69,6 +70,7 @@ struct old_linux_dirent {
65105 struct readdir_callback {
65106 struct dir_context ctx;
65107 struct old_linux_dirent __user * dirent;
65108 + struct file * file;
65109 int result;
65110 };
65111
65112 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
65113 buf->result = -EOVERFLOW;
65114 return -EOVERFLOW;
65115 }
65116 +
65117 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65118 + return 0;
65119 +
65120 buf->result++;
65121 dirent = buf->dirent;
65122 if (!access_ok(VERIFY_WRITE, dirent,
65123 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
65124 if (!f.file)
65125 return -EBADF;
65126
65127 + buf.file = f.file;
65128 error = iterate_dir(f.file, &buf.ctx);
65129 if (buf.result)
65130 error = buf.result;
65131 @@ -142,6 +149,7 @@ struct getdents_callback {
65132 struct dir_context ctx;
65133 struct linux_dirent __user * current_dir;
65134 struct linux_dirent __user * previous;
65135 + struct file * file;
65136 int count;
65137 int error;
65138 };
65139 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
65140 buf->error = -EOVERFLOW;
65141 return -EOVERFLOW;
65142 }
65143 +
65144 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65145 + return 0;
65146 +
65147 dirent = buf->previous;
65148 if (dirent) {
65149 if (__put_user(offset, &dirent->d_off))
65150 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
65151 if (!f.file)
65152 return -EBADF;
65153
65154 + buf.file = f.file;
65155 error = iterate_dir(f.file, &buf.ctx);
65156 if (error >= 0)
65157 error = buf.error;
65158 @@ -226,6 +239,7 @@ struct getdents_callback64 {
65159 struct dir_context ctx;
65160 struct linux_dirent64 __user * current_dir;
65161 struct linux_dirent64 __user * previous;
65162 + struct file *file;
65163 int count;
65164 int error;
65165 };
65166 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
65167 buf->error = -EINVAL; /* only used if we fail.. */
65168 if (reclen > buf->count)
65169 return -EINVAL;
65170 +
65171 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65172 + return 0;
65173 +
65174 dirent = buf->previous;
65175 if (dirent) {
65176 if (__put_user(offset, &dirent->d_off))
65177 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
65178 if (!f.file)
65179 return -EBADF;
65180
65181 + buf.file = f.file;
65182 error = iterate_dir(f.file, &buf.ctx);
65183 if (error >= 0)
65184 error = buf.error;
65185 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
65186 index 9a3c68c..767933e 100644
65187 --- a/fs/reiserfs/do_balan.c
65188 +++ b/fs/reiserfs/do_balan.c
65189 @@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
65190 return;
65191 }
65192
65193 - atomic_inc(&(fs_generation(tb->tb_sb)));
65194 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
65195 do_balance_starts(tb);
65196
65197 /* balance leaf returns 0 except if combining L R and S into
65198 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
65199 index ee382ef..f4eb6eb5 100644
65200 --- a/fs/reiserfs/item_ops.c
65201 +++ b/fs/reiserfs/item_ops.c
65202 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
65203 }
65204
65205 static struct item_operations errcatch_ops = {
65206 - errcatch_bytes_number,
65207 - errcatch_decrement_key,
65208 - errcatch_is_left_mergeable,
65209 - errcatch_print_item,
65210 - errcatch_check_item,
65211 + .bytes_number = errcatch_bytes_number,
65212 + .decrement_key = errcatch_decrement_key,
65213 + .is_left_mergeable = errcatch_is_left_mergeable,
65214 + .print_item = errcatch_print_item,
65215 + .check_item = errcatch_check_item,
65216
65217 - errcatch_create_vi,
65218 - errcatch_check_left,
65219 - errcatch_check_right,
65220 - errcatch_part_size,
65221 - errcatch_unit_num,
65222 - errcatch_print_vi
65223 + .create_vi = errcatch_create_vi,
65224 + .check_left = errcatch_check_left,
65225 + .check_right = errcatch_check_right,
65226 + .part_size = errcatch_part_size,
65227 + .unit_num = errcatch_unit_num,
65228 + .print_vi = errcatch_print_vi
65229 };
65230
65231 //////////////////////////////////////////////////////////////////////////////
65232 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65233 index 02b0b7d..c85018b 100644
65234 --- a/fs/reiserfs/procfs.c
65235 +++ b/fs/reiserfs/procfs.c
65236 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65237 "SMALL_TAILS " : "NO_TAILS ",
65238 replay_only(sb) ? "REPLAY_ONLY " : "",
65239 convert_reiserfs(sb) ? "CONV " : "",
65240 - atomic_read(&r->s_generation_counter),
65241 + atomic_read_unchecked(&r->s_generation_counter),
65242 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65243 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65244 SF(s_good_search_by_key_reada), SF(s_bmaps),
65245 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65246 index 8d06adf..7e1c9f8 100644
65247 --- a/fs/reiserfs/reiserfs.h
65248 +++ b/fs/reiserfs/reiserfs.h
65249 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65250 /* Comment? -Hans */
65251 wait_queue_head_t s_wait;
65252 /* To be obsoleted soon by per buffer seals.. -Hans */
65253 - atomic_t s_generation_counter; // increased by one every time the
65254 + atomic_unchecked_t s_generation_counter; // increased by one every time the
65255 // tree gets re-balanced
65256 unsigned long s_properties; /* File system properties. Currently holds
65257 on-disk FS format */
65258 @@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65259 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65260
65261 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65262 -#define get_generation(s) atomic_read (&fs_generation(s))
65263 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65264 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65265 #define __fs_changed(gen,s) (gen != get_generation (s))
65266 #define fs_changed(gen,s) \
65267 diff --git a/fs/select.c b/fs/select.c
65268 index 467bb1c..cf9d65a 100644
65269 --- a/fs/select.c
65270 +++ b/fs/select.c
65271 @@ -20,6 +20,7 @@
65272 #include <linux/export.h>
65273 #include <linux/slab.h>
65274 #include <linux/poll.h>
65275 +#include <linux/security.h>
65276 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65277 #include <linux/file.h>
65278 #include <linux/fdtable.h>
65279 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65280 struct poll_list *walk = head;
65281 unsigned long todo = nfds;
65282
65283 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65284 if (nfds > rlimit(RLIMIT_NOFILE))
65285 return -EINVAL;
65286
65287 diff --git a/fs/seq_file.c b/fs/seq_file.c
65288 index 1d641bb..c2f4743 100644
65289 --- a/fs/seq_file.c
65290 +++ b/fs/seq_file.c
65291 @@ -10,6 +10,8 @@
65292 #include <linux/seq_file.h>
65293 #include <linux/slab.h>
65294 #include <linux/cred.h>
65295 +#include <linux/sched.h>
65296 +#include <linux/grsecurity.h>
65297
65298 #include <asm/uaccess.h>
65299 #include <asm/page.h>
65300 @@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65301 #ifdef CONFIG_USER_NS
65302 p->user_ns = file->f_cred->user_ns;
65303 #endif
65304 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65305 + p->exec_id = current->exec_id;
65306 +#endif
65307
65308 /*
65309 * Wrappers around seq_open(e.g. swaps_open) need to be
65310 @@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65311 }
65312 EXPORT_SYMBOL(seq_open);
65313
65314 +
65315 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
65316 +{
65317 + if (gr_proc_is_restricted())
65318 + return -EACCES;
65319 +
65320 + return seq_open(file, op);
65321 +}
65322 +EXPORT_SYMBOL(seq_open_restrict);
65323 +
65324 static int traverse(struct seq_file *m, loff_t offset)
65325 {
65326 loff_t pos = 0, index;
65327 @@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65328 return 0;
65329 }
65330 if (!m->buf) {
65331 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65332 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65333 if (!m->buf)
65334 return -ENOMEM;
65335 }
65336 @@ -137,7 +152,7 @@ Eoverflow:
65337 m->op->stop(m, p);
65338 kfree(m->buf);
65339 m->count = 0;
65340 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65341 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65342 return !m->buf ? -ENOMEM : -EAGAIN;
65343 }
65344
65345 @@ -153,7 +168,7 @@ Eoverflow:
65346 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65347 {
65348 struct seq_file *m = file->private_data;
65349 - size_t copied = 0;
65350 + ssize_t copied = 0;
65351 loff_t pos;
65352 size_t n;
65353 void *p;
65354 @@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65355
65356 /* grab buffer if we didn't have one */
65357 if (!m->buf) {
65358 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65359 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65360 if (!m->buf)
65361 goto Enomem;
65362 }
65363 @@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65364 m->op->stop(m, p);
65365 kfree(m->buf);
65366 m->count = 0;
65367 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65368 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65369 if (!m->buf)
65370 goto Enomem;
65371 m->version = 0;
65372 @@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65373 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65374 void *data)
65375 {
65376 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65377 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65378 int res = -ENOMEM;
65379
65380 if (op) {
65381 @@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65382 }
65383 EXPORT_SYMBOL(single_open_size);
65384
65385 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65386 + void *data)
65387 +{
65388 + if (gr_proc_is_restricted())
65389 + return -EACCES;
65390 +
65391 + return single_open(file, show, data);
65392 +}
65393 +EXPORT_SYMBOL(single_open_restrict);
65394 +
65395 +
65396 int single_release(struct inode *inode, struct file *file)
65397 {
65398 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65399 diff --git a/fs/splice.c b/fs/splice.c
65400 index 12028fa..a6f2619 100644
65401 --- a/fs/splice.c
65402 +++ b/fs/splice.c
65403 @@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65404 pipe_lock(pipe);
65405
65406 for (;;) {
65407 - if (!pipe->readers) {
65408 + if (!atomic_read(&pipe->readers)) {
65409 send_sig(SIGPIPE, current, 0);
65410 if (!ret)
65411 ret = -EPIPE;
65412 @@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65413 page_nr++;
65414 ret += buf->len;
65415
65416 - if (pipe->files)
65417 + if (atomic_read(&pipe->files))
65418 do_wakeup = 1;
65419
65420 if (!--spd->nr_pages)
65421 @@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65422 do_wakeup = 0;
65423 }
65424
65425 - pipe->waiting_writers++;
65426 + atomic_inc(&pipe->waiting_writers);
65427 pipe_wait(pipe);
65428 - pipe->waiting_writers--;
65429 + atomic_dec(&pipe->waiting_writers);
65430 }
65431
65432 pipe_unlock(pipe);
65433 @@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65434 old_fs = get_fs();
65435 set_fs(get_ds());
65436 /* The cast to a user pointer is valid due to the set_fs() */
65437 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65438 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65439 set_fs(old_fs);
65440
65441 return res;
65442 @@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65443 old_fs = get_fs();
65444 set_fs(get_ds());
65445 /* The cast to a user pointer is valid due to the set_fs() */
65446 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65447 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65448 set_fs(old_fs);
65449
65450 return res;
65451 @@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65452 goto err;
65453
65454 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65455 - vec[i].iov_base = (void __user *) page_address(page);
65456 + vec[i].iov_base = (void __force_user *) page_address(page);
65457 vec[i].iov_len = this_len;
65458 spd.pages[i] = page;
65459 spd.nr_pages++;
65460 @@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65461 ops->release(pipe, buf);
65462 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65463 pipe->nrbufs--;
65464 - if (pipe->files)
65465 + if (atomic_read(&pipe->files))
65466 sd->need_wakeup = true;
65467 }
65468
65469 @@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65470 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65471 {
65472 while (!pipe->nrbufs) {
65473 - if (!pipe->writers)
65474 + if (!atomic_read(&pipe->writers))
65475 return 0;
65476
65477 - if (!pipe->waiting_writers && sd->num_spliced)
65478 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65479 return 0;
65480
65481 if (sd->flags & SPLICE_F_NONBLOCK)
65482 @@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65483 * out of the pipe right after the splice_to_pipe(). So set
65484 * PIPE_READERS appropriately.
65485 */
65486 - pipe->readers = 1;
65487 + atomic_set(&pipe->readers, 1);
65488
65489 current->splice_pipe = pipe;
65490 }
65491 @@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65492
65493 partial[buffers].offset = off;
65494 partial[buffers].len = plen;
65495 + partial[buffers].private = 0;
65496
65497 off = 0;
65498 len -= plen;
65499 @@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65500 ret = -ERESTARTSYS;
65501 break;
65502 }
65503 - if (!pipe->writers)
65504 + if (!atomic_read(&pipe->writers))
65505 break;
65506 - if (!pipe->waiting_writers) {
65507 + if (!atomic_read(&pipe->waiting_writers)) {
65508 if (flags & SPLICE_F_NONBLOCK) {
65509 ret = -EAGAIN;
65510 break;
65511 @@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65512 pipe_lock(pipe);
65513
65514 while (pipe->nrbufs >= pipe->buffers) {
65515 - if (!pipe->readers) {
65516 + if (!atomic_read(&pipe->readers)) {
65517 send_sig(SIGPIPE, current, 0);
65518 ret = -EPIPE;
65519 break;
65520 @@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65521 ret = -ERESTARTSYS;
65522 break;
65523 }
65524 - pipe->waiting_writers++;
65525 + atomic_inc(&pipe->waiting_writers);
65526 pipe_wait(pipe);
65527 - pipe->waiting_writers--;
65528 + atomic_dec(&pipe->waiting_writers);
65529 }
65530
65531 pipe_unlock(pipe);
65532 @@ -1880,14 +1881,14 @@ retry:
65533 pipe_double_lock(ipipe, opipe);
65534
65535 do {
65536 - if (!opipe->readers) {
65537 + if (!atomic_read(&opipe->readers)) {
65538 send_sig(SIGPIPE, current, 0);
65539 if (!ret)
65540 ret = -EPIPE;
65541 break;
65542 }
65543
65544 - if (!ipipe->nrbufs && !ipipe->writers)
65545 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65546 break;
65547
65548 /*
65549 @@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65550 pipe_double_lock(ipipe, opipe);
65551
65552 do {
65553 - if (!opipe->readers) {
65554 + if (!atomic_read(&opipe->readers)) {
65555 send_sig(SIGPIPE, current, 0);
65556 if (!ret)
65557 ret = -EPIPE;
65558 @@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65559 * return EAGAIN if we have the potential of some data in the
65560 * future, otherwise just return 0
65561 */
65562 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65563 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65564 ret = -EAGAIN;
65565
65566 pipe_unlock(ipipe);
65567 diff --git a/fs/stat.c b/fs/stat.c
65568 index ae0c3ce..9ee641c 100644
65569 --- a/fs/stat.c
65570 +++ b/fs/stat.c
65571 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65572 stat->gid = inode->i_gid;
65573 stat->rdev = inode->i_rdev;
65574 stat->size = i_size_read(inode);
65575 - stat->atime = inode->i_atime;
65576 - stat->mtime = inode->i_mtime;
65577 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65578 + stat->atime = inode->i_ctime;
65579 + stat->mtime = inode->i_ctime;
65580 + } else {
65581 + stat->atime = inode->i_atime;
65582 + stat->mtime = inode->i_mtime;
65583 + }
65584 stat->ctime = inode->i_ctime;
65585 stat->blksize = (1 << inode->i_blkbits);
65586 stat->blocks = inode->i_blocks;
65587 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65588 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65589 {
65590 struct inode *inode = path->dentry->d_inode;
65591 + int retval;
65592
65593 - if (inode->i_op->getattr)
65594 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
65595 + if (inode->i_op->getattr) {
65596 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65597 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65598 + stat->atime = stat->ctime;
65599 + stat->mtime = stat->ctime;
65600 + }
65601 + return retval;
65602 + }
65603
65604 generic_fillattr(inode, stat);
65605 return 0;
65606 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65607 index ee0d761..b346c58 100644
65608 --- a/fs/sysfs/dir.c
65609 +++ b/fs/sysfs/dir.c
65610 @@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65611 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65612 {
65613 struct kernfs_node *parent, *kn;
65614 + const char *name;
65615 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65616 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65617 + const char *parent_name;
65618 +#endif
65619
65620 BUG_ON(!kobj);
65621
65622 + name = kobject_name(kobj);
65623 +
65624 if (kobj->parent)
65625 parent = kobj->parent->sd;
65626 else
65627 @@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65628 if (!parent)
65629 return -ENOENT;
65630
65631 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65632 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65633 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65634 + parent_name = parent->name;
65635 + mode = S_IRWXU;
65636 +
65637 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65638 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65639 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65640 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65641 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
65642 +#endif
65643 +
65644 + kn = kernfs_create_dir_ns(parent, name,
65645 + mode, kobj, ns);
65646 if (IS_ERR(kn)) {
65647 if (PTR_ERR(kn) == -EEXIST)
65648 - sysfs_warn_dup(parent, kobject_name(kobj));
65649 + sysfs_warn_dup(parent, name);
65650 return PTR_ERR(kn);
65651 }
65652
65653 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
65654 index 810cf6e..5fd2bf1 100644
65655 --- a/fs/sysfs/file.c
65656 +++ b/fs/sysfs/file.c
65657 @@ -47,12 +47,13 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
65658 ssize_t count;
65659 char *buf;
65660
65661 - /* acquire buffer and ensure that it's >= PAGE_SIZE */
65662 + /* acquire buffer and ensure that it's >= PAGE_SIZE and clear */
65663 count = seq_get_buf(sf, &buf);
65664 if (count < PAGE_SIZE) {
65665 seq_commit(sf, -1);
65666 return 0;
65667 }
65668 + memset(buf, 0, PAGE_SIZE);
65669
65670 /*
65671 * Invoke show(). Control may reach here via seq file lseek even
65672 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65673 index 69d4889..a810bd4 100644
65674 --- a/fs/sysv/sysv.h
65675 +++ b/fs/sysv/sysv.h
65676 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65677 #endif
65678 }
65679
65680 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65681 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65682 {
65683 if (sbi->s_bytesex == BYTESEX_PDP)
65684 return PDP_swab((__force __u32)n);
65685 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65686 index e18b988..f1d4ad0f 100644
65687 --- a/fs/ubifs/io.c
65688 +++ b/fs/ubifs/io.c
65689 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65690 return err;
65691 }
65692
65693 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65694 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65695 {
65696 int err;
65697
65698 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65699 index c175b4d..8f36a16 100644
65700 --- a/fs/udf/misc.c
65701 +++ b/fs/udf/misc.c
65702 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65703
65704 u8 udf_tag_checksum(const struct tag *t)
65705 {
65706 - u8 *data = (u8 *)t;
65707 + const u8 *data = (const u8 *)t;
65708 u8 checksum = 0;
65709 int i;
65710 for (i = 0; i < sizeof(struct tag); ++i)
65711 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65712 index 8d974c4..b82f6ec 100644
65713 --- a/fs/ufs/swab.h
65714 +++ b/fs/ufs/swab.h
65715 @@ -22,7 +22,7 @@ enum {
65716 BYTESEX_BE
65717 };
65718
65719 -static inline u64
65720 +static inline u64 __intentional_overflow(-1)
65721 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65722 {
65723 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65724 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65725 return (__force __fs64)cpu_to_be64(n);
65726 }
65727
65728 -static inline u32
65729 +static inline u32 __intentional_overflow(-1)
65730 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65731 {
65732 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65733 diff --git a/fs/utimes.c b/fs/utimes.c
65734 index aa138d6..5f3a811 100644
65735 --- a/fs/utimes.c
65736 +++ b/fs/utimes.c
65737 @@ -1,6 +1,7 @@
65738 #include <linux/compiler.h>
65739 #include <linux/file.h>
65740 #include <linux/fs.h>
65741 +#include <linux/security.h>
65742 #include <linux/linkage.h>
65743 #include <linux/mount.h>
65744 #include <linux/namei.h>
65745 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65746 }
65747 }
65748 retry_deleg:
65749 +
65750 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65751 + error = -EACCES;
65752 + goto mnt_drop_write_and_out;
65753 + }
65754 +
65755 mutex_lock(&inode->i_mutex);
65756 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65757 mutex_unlock(&inode->i_mutex);
65758 diff --git a/fs/xattr.c b/fs/xattr.c
65759 index 3377dff..f394815 100644
65760 --- a/fs/xattr.c
65761 +++ b/fs/xattr.c
65762 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65763 return rc;
65764 }
65765
65766 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65767 +ssize_t
65768 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
65769 +{
65770 + struct inode *inode = dentry->d_inode;
65771 + ssize_t error;
65772 +
65773 + error = inode_permission(inode, MAY_EXEC);
65774 + if (error)
65775 + return error;
65776 +
65777 + if (inode->i_op->getxattr)
65778 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65779 + else
65780 + error = -EOPNOTSUPP;
65781 +
65782 + return error;
65783 +}
65784 +EXPORT_SYMBOL(pax_getxattr);
65785 +#endif
65786 +
65787 ssize_t
65788 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65789 {
65790 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65791 * Extended attribute SET operations
65792 */
65793 static long
65794 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
65795 +setxattr(struct path *path, const char __user *name, const void __user *value,
65796 size_t size, int flags)
65797 {
65798 int error;
65799 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65800 posix_acl_fix_xattr_from_user(kvalue, size);
65801 }
65802
65803 - error = vfs_setxattr(d, kname, kvalue, size, flags);
65804 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65805 + error = -EACCES;
65806 + goto out;
65807 + }
65808 +
65809 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65810 out:
65811 if (vvalue)
65812 vfree(vvalue);
65813 @@ -377,7 +403,7 @@ retry:
65814 return error;
65815 error = mnt_want_write(path.mnt);
65816 if (!error) {
65817 - error = setxattr(path.dentry, name, value, size, flags);
65818 + error = setxattr(&path, name, value, size, flags);
65819 mnt_drop_write(path.mnt);
65820 }
65821 path_put(&path);
65822 @@ -401,7 +427,7 @@ retry:
65823 return error;
65824 error = mnt_want_write(path.mnt);
65825 if (!error) {
65826 - error = setxattr(path.dentry, name, value, size, flags);
65827 + error = setxattr(&path, name, value, size, flags);
65828 mnt_drop_write(path.mnt);
65829 }
65830 path_put(&path);
65831 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65832 const void __user *,value, size_t, size, int, flags)
65833 {
65834 struct fd f = fdget(fd);
65835 - struct dentry *dentry;
65836 int error = -EBADF;
65837
65838 if (!f.file)
65839 return error;
65840 - dentry = f.file->f_path.dentry;
65841 - audit_inode(NULL, dentry, 0);
65842 + audit_inode(NULL, f.file->f_path.dentry, 0);
65843 error = mnt_want_write_file(f.file);
65844 if (!error) {
65845 - error = setxattr(dentry, name, value, size, flags);
65846 + error = setxattr(&f.file->f_path, name, value, size, flags);
65847 mnt_drop_write_file(f.file);
65848 }
65849 fdput(f);
65850 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65851 * Extended attribute REMOVE operations
65852 */
65853 static long
65854 -removexattr(struct dentry *d, const char __user *name)
65855 +removexattr(struct path *path, const char __user *name)
65856 {
65857 int error;
65858 char kname[XATTR_NAME_MAX + 1];
65859 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65860 if (error < 0)
65861 return error;
65862
65863 - return vfs_removexattr(d, kname);
65864 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65865 + return -EACCES;
65866 +
65867 + return vfs_removexattr(path->dentry, kname);
65868 }
65869
65870 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65871 @@ -652,7 +679,7 @@ retry:
65872 return error;
65873 error = mnt_want_write(path.mnt);
65874 if (!error) {
65875 - error = removexattr(path.dentry, name);
65876 + error = removexattr(&path, name);
65877 mnt_drop_write(path.mnt);
65878 }
65879 path_put(&path);
65880 @@ -675,7 +702,7 @@ retry:
65881 return error;
65882 error = mnt_want_write(path.mnt);
65883 if (!error) {
65884 - error = removexattr(path.dentry, name);
65885 + error = removexattr(&path, name);
65886 mnt_drop_write(path.mnt);
65887 }
65888 path_put(&path);
65889 @@ -689,16 +716,16 @@ retry:
65890 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65891 {
65892 struct fd f = fdget(fd);
65893 - struct dentry *dentry;
65894 + struct path *path;
65895 int error = -EBADF;
65896
65897 if (!f.file)
65898 return error;
65899 - dentry = f.file->f_path.dentry;
65900 - audit_inode(NULL, dentry, 0);
65901 + path = &f.file->f_path;
65902 + audit_inode(NULL, path->dentry, 0);
65903 error = mnt_want_write_file(f.file);
65904 if (!error) {
65905 - error = removexattr(dentry, name);
65906 + error = removexattr(path, name);
65907 mnt_drop_write_file(f.file);
65908 }
65909 fdput(f);
65910 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65911 index 152543c..d80c361 100644
65912 --- a/fs/xfs/xfs_bmap.c
65913 +++ b/fs/xfs/xfs_bmap.c
65914 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65915
65916 #else
65917 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65918 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65919 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65920 #endif /* DEBUG */
65921
65922 /*
65923 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65924 index aead369..0dfecfd 100644
65925 --- a/fs/xfs/xfs_dir2_readdir.c
65926 +++ b/fs/xfs/xfs_dir2_readdir.c
65927 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65928 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65929 filetype = dp->d_ops->sf_get_ftype(sfep);
65930 ctx->pos = off & 0x7fffffff;
65931 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65932 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65933 + char name[sfep->namelen];
65934 + memcpy(name, sfep->name, sfep->namelen);
65935 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65936 + return 0;
65937 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65938 xfs_dir3_get_dtype(mp, filetype)))
65939 return 0;
65940 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65941 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65942 index bcfe612..aa399c0 100644
65943 --- a/fs/xfs/xfs_ioctl.c
65944 +++ b/fs/xfs/xfs_ioctl.c
65945 @@ -122,7 +122,7 @@ xfs_find_handle(
65946 }
65947
65948 error = -EFAULT;
65949 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65950 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65951 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65952 goto out_put;
65953
65954 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65955 new file mode 100644
65956 index 0000000..3abaf02
65957 --- /dev/null
65958 +++ b/grsecurity/Kconfig
65959 @@ -0,0 +1,1161 @@
65960 +#
65961 +# grecurity configuration
65962 +#
65963 +menu "Memory Protections"
65964 +depends on GRKERNSEC
65965 +
65966 +config GRKERNSEC_KMEM
65967 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65968 + default y if GRKERNSEC_CONFIG_AUTO
65969 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65970 + help
65971 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65972 + be written to or read from to modify or leak the contents of the running
65973 + kernel. /dev/port will also not be allowed to be opened, writing to
65974 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65975 + If you have module support disabled, enabling this will close up several
65976 + ways that are currently used to insert malicious code into the running
65977 + kernel.
65978 +
65979 + Even with this feature enabled, we still highly recommend that
65980 + you use the RBAC system, as it is still possible for an attacker to
65981 + modify the running kernel through other more obscure methods.
65982 +
65983 + It is highly recommended that you say Y here if you meet all the
65984 + conditions above.
65985 +
65986 +config GRKERNSEC_VM86
65987 + bool "Restrict VM86 mode"
65988 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65989 + depends on X86_32
65990 +
65991 + help
65992 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65993 + make use of a special execution mode on 32bit x86 processors called
65994 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65995 + video cards and will still work with this option enabled. The purpose
65996 + of the option is to prevent exploitation of emulation errors in
65997 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
65998 + Nearly all users should be able to enable this option.
65999 +
66000 +config GRKERNSEC_IO
66001 + bool "Disable privileged I/O"
66002 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66003 + depends on X86
66004 + select RTC_CLASS
66005 + select RTC_INTF_DEV
66006 + select RTC_DRV_CMOS
66007 +
66008 + help
66009 + If you say Y here, all ioperm and iopl calls will return an error.
66010 + Ioperm and iopl can be used to modify the running kernel.
66011 + Unfortunately, some programs need this access to operate properly,
66012 + the most notable of which are XFree86 and hwclock. hwclock can be
66013 + remedied by having RTC support in the kernel, so real-time
66014 + clock support is enabled if this option is enabled, to ensure
66015 + that hwclock operates correctly. If hwclock still does not work,
66016 + either update udev or symlink /dev/rtc to /dev/rtc0.
66017 +
66018 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
66019 + you may not be able to boot into a graphical environment with this
66020 + option enabled. In this case, you should use the RBAC system instead.
66021 +
66022 +config GRKERNSEC_JIT_HARDEN
66023 + bool "Harden BPF JIT against spray attacks"
66024 + default y if GRKERNSEC_CONFIG_AUTO
66025 + depends on BPF_JIT && X86
66026 + help
66027 + If you say Y here, the native code generated by the kernel's Berkeley
66028 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
66029 + attacks that attempt to fit attacker-beneficial instructions in
66030 + 32bit immediate fields of JIT-generated native instructions. The
66031 + attacker will generally aim to cause an unintended instruction sequence
66032 + of JIT-generated native code to execute by jumping into the middle of
66033 + a generated instruction. This feature effectively randomizes the 32bit
66034 + immediate constants present in the generated code to thwart such attacks.
66035 +
66036 + If you're using KERNEXEC, it's recommended that you enable this option
66037 + to supplement the hardening of the kernel.
66038 +
66039 +config GRKERNSEC_PERF_HARDEN
66040 + bool "Disable unprivileged PERF_EVENTS usage by default"
66041 + default y if GRKERNSEC_CONFIG_AUTO
66042 + depends on PERF_EVENTS
66043 + help
66044 + If you say Y here, the range of acceptable values for the
66045 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
66046 + default to a new value: 3. When the sysctl is set to this value, no
66047 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
66048 +
66049 + Though PERF_EVENTS can be used legitimately for performance monitoring
66050 + and low-level application profiling, it is forced on regardless of
66051 + configuration, has been at fault for several vulnerabilities, and
66052 + creates new opportunities for side channels and other information leaks.
66053 +
66054 + This feature puts PERF_EVENTS into a secure default state and permits
66055 + the administrator to change out of it temporarily if unprivileged
66056 + application profiling is needed.
66057 +
66058 +config GRKERNSEC_RAND_THREADSTACK
66059 + bool "Insert random gaps between thread stacks"
66060 + default y if GRKERNSEC_CONFIG_AUTO
66061 + depends on PAX_RANDMMAP && !PPC
66062 + help
66063 + If you say Y here, a random-sized gap will be enforced between allocated
66064 + thread stacks. Glibc's NPTL and other threading libraries that
66065 + pass MAP_STACK to the kernel for thread stack allocation are supported.
66066 + The implementation currently provides 8 bits of entropy for the gap.
66067 +
66068 + Many distributions do not compile threaded remote services with the
66069 + -fstack-check argument to GCC, causing the variable-sized stack-based
66070 + allocator, alloca(), to not probe the stack on allocation. This
66071 + permits an unbounded alloca() to skip over any guard page and potentially
66072 + modify another thread's stack reliably. An enforced random gap
66073 + reduces the reliability of such an attack and increases the chance
66074 + that such a read/write to another thread's stack instead lands in
66075 + an unmapped area, causing a crash and triggering grsecurity's
66076 + anti-bruteforcing logic.
66077 +
66078 +config GRKERNSEC_PROC_MEMMAP
66079 + bool "Harden ASLR against information leaks and entropy reduction"
66080 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
66081 + depends on PAX_NOEXEC || PAX_ASLR
66082 + help
66083 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
66084 + give no information about the addresses of its mappings if
66085 + PaX features that rely on random addresses are enabled on the task.
66086 + In addition to sanitizing this information and disabling other
66087 + dangerous sources of information, this option causes reads of sensitive
66088 + /proc/<pid> entries where the file descriptor was opened in a different
66089 + task than the one performing the read. Such attempts are logged.
66090 + This option also limits argv/env strings for suid/sgid binaries
66091 + to 512KB to prevent a complete exhaustion of the stack entropy provided
66092 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
66093 + binaries to prevent alternative mmap layouts from being abused.
66094 +
66095 + If you use PaX it is essential that you say Y here as it closes up
66096 + several holes that make full ASLR useless locally.
66097 +
66098 +config GRKERNSEC_BRUTE
66099 + bool "Deter exploit bruteforcing"
66100 + default y if GRKERNSEC_CONFIG_AUTO
66101 + help
66102 + If you say Y here, attempts to bruteforce exploits against forking
66103 + daemons such as apache or sshd, as well as against suid/sgid binaries
66104 + will be deterred. When a child of a forking daemon is killed by PaX
66105 + or crashes due to an illegal instruction or other suspicious signal,
66106 + the parent process will be delayed 30 seconds upon every subsequent
66107 + fork until the administrator is able to assess the situation and
66108 + restart the daemon.
66109 + In the suid/sgid case, the attempt is logged, the user has all their
66110 + existing instances of the suid/sgid binary terminated and will
66111 + be unable to execute any suid/sgid binaries for 15 minutes.
66112 +
66113 + It is recommended that you also enable signal logging in the auditing
66114 + section so that logs are generated when a process triggers a suspicious
66115 + signal.
66116 + If the sysctl option is enabled, a sysctl option with name
66117 + "deter_bruteforce" is created.
66118 +
66119 +config GRKERNSEC_MODHARDEN
66120 + bool "Harden module auto-loading"
66121 + default y if GRKERNSEC_CONFIG_AUTO
66122 + depends on MODULES
66123 + help
66124 + If you say Y here, module auto-loading in response to use of some
66125 + feature implemented by an unloaded module will be restricted to
66126 + root users. Enabling this option helps defend against attacks
66127 + by unprivileged users who abuse the auto-loading behavior to
66128 + cause a vulnerable module to load that is then exploited.
66129 +
66130 + If this option prevents a legitimate use of auto-loading for a
66131 + non-root user, the administrator can execute modprobe manually
66132 + with the exact name of the module mentioned in the alert log.
66133 + Alternatively, the administrator can add the module to the list
66134 + of modules loaded at boot by modifying init scripts.
66135 +
66136 + Modification of init scripts will most likely be needed on
66137 + Ubuntu servers with encrypted home directory support enabled,
66138 + as the first non-root user logging in will cause the ecb(aes),
66139 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
66140 +
66141 +config GRKERNSEC_HIDESYM
66142 + bool "Hide kernel symbols"
66143 + default y if GRKERNSEC_CONFIG_AUTO
66144 + select PAX_USERCOPY_SLABS
66145 + help
66146 + If you say Y here, getting information on loaded modules, and
66147 + displaying all kernel symbols through a syscall will be restricted
66148 + to users with CAP_SYS_MODULE. For software compatibility reasons,
66149 + /proc/kallsyms will be restricted to the root user. The RBAC
66150 + system can hide that entry even from root.
66151 +
66152 + This option also prevents leaking of kernel addresses through
66153 + several /proc entries.
66154 +
66155 + Note that this option is only effective provided the following
66156 + conditions are met:
66157 + 1) The kernel using grsecurity is not precompiled by some distribution
66158 + 2) You have also enabled GRKERNSEC_DMESG
66159 + 3) You are using the RBAC system and hiding other files such as your
66160 + kernel image and System.map. Alternatively, enabling this option
66161 + causes the permissions on /boot, /lib/modules, and the kernel
66162 + source directory to change at compile time to prevent
66163 + reading by non-root users.
66164 + If the above conditions are met, this option will aid in providing a
66165 + useful protection against local kernel exploitation of overflows
66166 + and arbitrary read/write vulnerabilities.
66167 +
66168 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
66169 + in addition to this feature.
66170 +
66171 +config GRKERNSEC_RANDSTRUCT
66172 + bool "Randomize layout of sensitive kernel structures"
66173 + default y if GRKERNSEC_CONFIG_AUTO
66174 + select GRKERNSEC_HIDESYM
66175 + select MODVERSIONS if MODULES
66176 + help
66177 + If you say Y here, the layouts of a number of sensitive kernel
66178 + structures (task, fs, cred, etc) and all structures composed entirely
66179 + of function pointers (aka "ops" structs) will be randomized at compile-time.
66180 + This can introduce the requirement of an additional infoleak
66181 + vulnerability for exploits targeting these structure types.
66182 +
66183 + Enabling this feature will introduce some performance impact, slightly
66184 + increase memory usage, and prevent the use of forensic tools like
66185 + Volatility against the system (unless the kernel source tree isn't
66186 + cleaned after kernel installation).
66187 +
66188 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
66189 + It remains after a make clean to allow for external modules to be compiled
66190 + with the existing seed and will be removed by a make mrproper or
66191 + make distclean.
66192 +
66193 + Note that the implementation requires gcc 4.6.4. or newer. You may need
66194 + to install the supporting headers explicitly in addition to the normal
66195 + gcc package.
66196 +
66197 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
66198 + bool "Use cacheline-aware structure randomization"
66199 + depends on GRKERNSEC_RANDSTRUCT
66200 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
66201 + help
66202 + If you say Y here, the RANDSTRUCT randomization will make a best effort
66203 + at restricting randomization to cacheline-sized groups of elements. It
66204 + will further not randomize bitfields in structures. This reduces the
66205 + performance hit of RANDSTRUCT at the cost of weakened randomization.
66206 +
66207 +config GRKERNSEC_KERN_LOCKOUT
66208 + bool "Active kernel exploit response"
66209 + default y if GRKERNSEC_CONFIG_AUTO
66210 + depends on X86 || ARM || PPC || SPARC
66211 + help
66212 + If you say Y here, when a PaX alert is triggered due to suspicious
66213 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
66214 + or an OOPS occurs due to bad memory accesses, instead of just
66215 + terminating the offending process (and potentially allowing
66216 + a subsequent exploit from the same user), we will take one of two
66217 + actions:
66218 + If the user was root, we will panic the system
66219 + If the user was non-root, we will log the attempt, terminate
66220 + all processes owned by the user, then prevent them from creating
66221 + any new processes until the system is restarted
66222 + This deters repeated kernel exploitation/bruteforcing attempts
66223 + and is useful for later forensics.
66224 +
66225 +config GRKERNSEC_OLD_ARM_USERLAND
66226 + bool "Old ARM userland compatibility"
66227 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66228 + help
66229 + If you say Y here, stubs of executable code to perform such operations
66230 + as "compare-exchange" will be placed at fixed locations in the ARM vector
66231 + table. This is unfortunately needed for old ARM userland meant to run
66232 + across a wide range of processors. Without this option enabled,
66233 + the get_tls and data memory barrier stubs will be emulated by the kernel,
66234 + which is enough for Linaro userlands or other userlands designed for v6
66235 + and newer ARM CPUs. It's recommended that you try without this option enabled
66236 + first, and only enable it if your userland does not boot (it will likely fail
66237 + at init time).
66238 +
66239 +endmenu
66240 +menu "Role Based Access Control Options"
66241 +depends on GRKERNSEC
66242 +
66243 +config GRKERNSEC_RBAC_DEBUG
66244 + bool
66245 +
66246 +config GRKERNSEC_NO_RBAC
66247 + bool "Disable RBAC system"
66248 + help
66249 + If you say Y here, the /dev/grsec device will be removed from the kernel,
66250 + preventing the RBAC system from being enabled. You should only say Y
66251 + here if you have no intention of using the RBAC system, so as to prevent
66252 + an attacker with root access from misusing the RBAC system to hide files
66253 + and processes when loadable module support and /dev/[k]mem have been
66254 + locked down.
66255 +
66256 +config GRKERNSEC_ACL_HIDEKERN
66257 + bool "Hide kernel processes"
66258 + help
66259 + If you say Y here, all kernel threads will be hidden to all
66260 + processes but those whose subject has the "view hidden processes"
66261 + flag.
66262 +
66263 +config GRKERNSEC_ACL_MAXTRIES
66264 + int "Maximum tries before password lockout"
66265 + default 3
66266 + help
66267 + This option enforces the maximum number of times a user can attempt
66268 + to authorize themselves with the grsecurity RBAC system before being
66269 + denied the ability to attempt authorization again for a specified time.
66270 + The lower the number, the harder it will be to brute-force a password.
66271 +
66272 +config GRKERNSEC_ACL_TIMEOUT
66273 + int "Time to wait after max password tries, in seconds"
66274 + default 30
66275 + help
66276 + This option specifies the time the user must wait after attempting to
66277 + authorize to the RBAC system with the maximum number of invalid
66278 + passwords. The higher the number, the harder it will be to brute-force
66279 + a password.
66280 +
66281 +endmenu
66282 +menu "Filesystem Protections"
66283 +depends on GRKERNSEC
66284 +
66285 +config GRKERNSEC_PROC
66286 + bool "Proc restrictions"
66287 + default y if GRKERNSEC_CONFIG_AUTO
66288 + help
66289 + If you say Y here, the permissions of the /proc filesystem
66290 + will be altered to enhance system security and privacy. You MUST
66291 + choose either a user only restriction or a user and group restriction.
66292 + Depending upon the option you choose, you can either restrict users to
66293 + see only the processes they themselves run, or choose a group that can
66294 + view all processes and files normally restricted to root if you choose
66295 + the "restrict to user only" option. NOTE: If you're running identd or
66296 + ntpd as a non-root user, you will have to run it as the group you
66297 + specify here.
66298 +
66299 +config GRKERNSEC_PROC_USER
66300 + bool "Restrict /proc to user only"
66301 + depends on GRKERNSEC_PROC
66302 + help
66303 + If you say Y here, non-root users will only be able to view their own
66304 + processes, and restricts them from viewing network-related information,
66305 + and viewing kernel symbol and module information.
66306 +
66307 +config GRKERNSEC_PROC_USERGROUP
66308 + bool "Allow special group"
66309 + default y if GRKERNSEC_CONFIG_AUTO
66310 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66311 + help
66312 + If you say Y here, you will be able to select a group that will be
66313 + able to view all processes and network-related information. If you've
66314 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66315 + remain hidden. This option is useful if you want to run identd as
66316 + a non-root user. The group you select may also be chosen at boot time
66317 + via "grsec_proc_gid=" on the kernel commandline.
66318 +
66319 +config GRKERNSEC_PROC_GID
66320 + int "GID for special group"
66321 + depends on GRKERNSEC_PROC_USERGROUP
66322 + default 1001
66323 +
66324 +config GRKERNSEC_PROC_ADD
66325 + bool "Additional restrictions"
66326 + default y if GRKERNSEC_CONFIG_AUTO
66327 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66328 + help
66329 + If you say Y here, additional restrictions will be placed on
66330 + /proc that keep normal users from viewing device information and
66331 + slabinfo information that could be useful for exploits.
66332 +
66333 +config GRKERNSEC_LINK
66334 + bool "Linking restrictions"
66335 + default y if GRKERNSEC_CONFIG_AUTO
66336 + help
66337 + If you say Y here, /tmp race exploits will be prevented, since users
66338 + will no longer be able to follow symlinks owned by other users in
66339 + world-writable +t directories (e.g. /tmp), unless the owner of the
66340 + symlink is the owner of the directory. users will also not be
66341 + able to hardlink to files they do not own. If the sysctl option is
66342 + enabled, a sysctl option with name "linking_restrictions" is created.
66343 +
66344 +config GRKERNSEC_SYMLINKOWN
66345 + bool "Kernel-enforced SymlinksIfOwnerMatch"
66346 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66347 + help
66348 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
66349 + that prevents it from being used as a security feature. As Apache
66350 + verifies the symlink by performing a stat() against the target of
66351 + the symlink before it is followed, an attacker can setup a symlink
66352 + to point to a same-owned file, then replace the symlink with one
66353 + that targets another user's file just after Apache "validates" the
66354 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
66355 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66356 + will be in place for the group you specify. If the sysctl option
66357 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
66358 + created.
66359 +
66360 +config GRKERNSEC_SYMLINKOWN_GID
66361 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66362 + depends on GRKERNSEC_SYMLINKOWN
66363 + default 1006
66364 + help
66365 + Setting this GID determines what group kernel-enforced
66366 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66367 + is enabled, a sysctl option with name "symlinkown_gid" is created.
66368 +
66369 +config GRKERNSEC_FIFO
66370 + bool "FIFO restrictions"
66371 + default y if GRKERNSEC_CONFIG_AUTO
66372 + help
66373 + If you say Y here, users will not be able to write to FIFOs they don't
66374 + own in world-writable +t directories (e.g. /tmp), unless the owner of
66375 + the FIFO is the same owner of the directory it's held in. If the sysctl
66376 + option is enabled, a sysctl option with name "fifo_restrictions" is
66377 + created.
66378 +
66379 +config GRKERNSEC_SYSFS_RESTRICT
66380 + bool "Sysfs/debugfs restriction"
66381 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66382 + depends on SYSFS
66383 + help
66384 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66385 + any filesystem normally mounted under it (e.g. debugfs) will be
66386 + mostly accessible only by root. These filesystems generally provide access
66387 + to hardware and debug information that isn't appropriate for unprivileged
66388 + users of the system. Sysfs and debugfs have also become a large source
66389 + of new vulnerabilities, ranging from infoleaks to local compromise.
66390 + There has been very little oversight with an eye toward security involved
66391 + in adding new exporters of information to these filesystems, so their
66392 + use is discouraged.
66393 + For reasons of compatibility, a few directories have been whitelisted
66394 + for access by non-root users:
66395 + /sys/fs/selinux
66396 + /sys/fs/fuse
66397 + /sys/devices/system/cpu
66398 +
66399 +config GRKERNSEC_ROFS
66400 + bool "Runtime read-only mount protection"
66401 + depends on SYSCTL
66402 + help
66403 + If you say Y here, a sysctl option with name "romount_protect" will
66404 + be created. By setting this option to 1 at runtime, filesystems
66405 + will be protected in the following ways:
66406 + * No new writable mounts will be allowed
66407 + * Existing read-only mounts won't be able to be remounted read/write
66408 + * Write operations will be denied on all block devices
66409 + This option acts independently of grsec_lock: once it is set to 1,
66410 + it cannot be turned off. Therefore, please be mindful of the resulting
66411 + behavior if this option is enabled in an init script on a read-only
66412 + filesystem.
66413 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66414 + and GRKERNSEC_IO should be enabled and module loading disabled via
66415 + config or at runtime.
66416 + This feature is mainly intended for secure embedded systems.
66417 +
66418 +
66419 +config GRKERNSEC_DEVICE_SIDECHANNEL
66420 + bool "Eliminate stat/notify-based device sidechannels"
66421 + default y if GRKERNSEC_CONFIG_AUTO
66422 + help
66423 + If you say Y here, timing analyses on block or character
66424 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66425 + will be thwarted for unprivileged users. If a process without
66426 + CAP_MKNOD stats such a device, the last access and last modify times
66427 + will match the device's create time. No access or modify events
66428 + will be triggered through inotify/dnotify/fanotify for such devices.
66429 + This feature will prevent attacks that may at a minimum
66430 + allow an attacker to determine the administrator's password length.
66431 +
66432 +config GRKERNSEC_CHROOT
66433 + bool "Chroot jail restrictions"
66434 + default y if GRKERNSEC_CONFIG_AUTO
66435 + help
66436 + If you say Y here, you will be able to choose several options that will
66437 + make breaking out of a chrooted jail much more difficult. If you
66438 + encounter no software incompatibilities with the following options, it
66439 + is recommended that you enable each one.
66440 +
66441 + Note that the chroot restrictions are not intended to apply to "chroots"
66442 + to directories that are simple bind mounts of the global root filesystem.
66443 + For several other reasons, a user shouldn't expect any significant
66444 + security by performing such a chroot.
66445 +
66446 +config GRKERNSEC_CHROOT_MOUNT
66447 + bool "Deny mounts"
66448 + default y if GRKERNSEC_CONFIG_AUTO
66449 + depends on GRKERNSEC_CHROOT
66450 + help
66451 + If you say Y here, processes inside a chroot will not be able to
66452 + mount or remount filesystems. If the sysctl option is enabled, a
66453 + sysctl option with name "chroot_deny_mount" is created.
66454 +
66455 +config GRKERNSEC_CHROOT_DOUBLE
66456 + bool "Deny double-chroots"
66457 + default y if GRKERNSEC_CONFIG_AUTO
66458 + depends on GRKERNSEC_CHROOT
66459 + help
66460 + If you say Y here, processes inside a chroot will not be able to chroot
66461 + again outside the chroot. This is a widely used method of breaking
66462 + out of a chroot jail and should not be allowed. If the sysctl
66463 + option is enabled, a sysctl option with name
66464 + "chroot_deny_chroot" is created.
66465 +
66466 +config GRKERNSEC_CHROOT_PIVOT
66467 + bool "Deny pivot_root in chroot"
66468 + default y if GRKERNSEC_CONFIG_AUTO
66469 + depends on GRKERNSEC_CHROOT
66470 + help
66471 + If you say Y here, processes inside a chroot will not be able to use
66472 + a function called pivot_root() that was introduced in Linux 2.3.41. It
66473 + works similar to chroot in that it changes the root filesystem. This
66474 + function could be misused in a chrooted process to attempt to break out
66475 + of the chroot, and therefore should not be allowed. If the sysctl
66476 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
66477 + created.
66478 +
66479 +config GRKERNSEC_CHROOT_CHDIR
66480 + bool "Enforce chdir(\"/\") on all chroots"
66481 + default y if GRKERNSEC_CONFIG_AUTO
66482 + depends on GRKERNSEC_CHROOT
66483 + help
66484 + If you say Y here, the current working directory of all newly-chrooted
66485 + applications will be set to the the root directory of the chroot.
66486 + The man page on chroot(2) states:
66487 + Note that this call does not change the current working
66488 + directory, so that `.' can be outside the tree rooted at
66489 + `/'. In particular, the super-user can escape from a
66490 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66491 +
66492 + It is recommended that you say Y here, since it's not known to break
66493 + any software. If the sysctl option is enabled, a sysctl option with
66494 + name "chroot_enforce_chdir" is created.
66495 +
66496 +config GRKERNSEC_CHROOT_CHMOD
66497 + bool "Deny (f)chmod +s"
66498 + default y if GRKERNSEC_CONFIG_AUTO
66499 + depends on GRKERNSEC_CHROOT
66500 + help
66501 + If you say Y here, processes inside a chroot will not be able to chmod
66502 + or fchmod files to make them have suid or sgid bits. This protects
66503 + against another published method of breaking a chroot. If the sysctl
66504 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
66505 + created.
66506 +
66507 +config GRKERNSEC_CHROOT_FCHDIR
66508 + bool "Deny fchdir out of chroot"
66509 + default y if GRKERNSEC_CONFIG_AUTO
66510 + depends on GRKERNSEC_CHROOT
66511 + help
66512 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
66513 + to a file descriptor of the chrooting process that points to a directory
66514 + outside the filesystem will be stopped. If the sysctl option
66515 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
66516 +
66517 +config GRKERNSEC_CHROOT_MKNOD
66518 + bool "Deny mknod"
66519 + default y if GRKERNSEC_CONFIG_AUTO
66520 + depends on GRKERNSEC_CHROOT
66521 + help
66522 + If you say Y here, processes inside a chroot will not be allowed to
66523 + mknod. The problem with using mknod inside a chroot is that it
66524 + would allow an attacker to create a device entry that is the same
66525 + as one on the physical root of your system, which could range from
66526 + anything from the console device to a device for your harddrive (which
66527 + they could then use to wipe the drive or steal data). It is recommended
66528 + that you say Y here, unless you run into software incompatibilities.
66529 + If the sysctl option is enabled, a sysctl option with name
66530 + "chroot_deny_mknod" is created.
66531 +
66532 +config GRKERNSEC_CHROOT_SHMAT
66533 + bool "Deny shmat() out of chroot"
66534 + default y if GRKERNSEC_CONFIG_AUTO
66535 + depends on GRKERNSEC_CHROOT
66536 + help
66537 + If you say Y here, processes inside a chroot will not be able to attach
66538 + to shared memory segments that were created outside of the chroot jail.
66539 + It is recommended that you say Y here. If the sysctl option is enabled,
66540 + a sysctl option with name "chroot_deny_shmat" is created.
66541 +
66542 +config GRKERNSEC_CHROOT_UNIX
66543 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
66544 + default y if GRKERNSEC_CONFIG_AUTO
66545 + depends on GRKERNSEC_CHROOT
66546 + help
66547 + If you say Y here, processes inside a chroot will not be able to
66548 + connect to abstract (meaning not belonging to a filesystem) Unix
66549 + domain sockets that were bound outside of a chroot. It is recommended
66550 + that you say Y here. If the sysctl option is enabled, a sysctl option
66551 + with name "chroot_deny_unix" is created.
66552 +
66553 +config GRKERNSEC_CHROOT_FINDTASK
66554 + bool "Protect outside processes"
66555 + default y if GRKERNSEC_CONFIG_AUTO
66556 + depends on GRKERNSEC_CHROOT
66557 + help
66558 + If you say Y here, processes inside a chroot will not be able to
66559 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66560 + getsid, or view any process outside of the chroot. If the sysctl
66561 + option is enabled, a sysctl option with name "chroot_findtask" is
66562 + created.
66563 +
66564 +config GRKERNSEC_CHROOT_NICE
66565 + bool "Restrict priority changes"
66566 + default y if GRKERNSEC_CONFIG_AUTO
66567 + depends on GRKERNSEC_CHROOT
66568 + help
66569 + If you say Y here, processes inside a chroot will not be able to raise
66570 + the priority of processes in the chroot, or alter the priority of
66571 + processes outside the chroot. This provides more security than simply
66572 + removing CAP_SYS_NICE from the process' capability set. If the
66573 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66574 + is created.
66575 +
66576 +config GRKERNSEC_CHROOT_SYSCTL
66577 + bool "Deny sysctl writes"
66578 + default y if GRKERNSEC_CONFIG_AUTO
66579 + depends on GRKERNSEC_CHROOT
66580 + help
66581 + If you say Y here, an attacker in a chroot will not be able to
66582 + write to sysctl entries, either by sysctl(2) or through a /proc
66583 + interface. It is strongly recommended that you say Y here. If the
66584 + sysctl option is enabled, a sysctl option with name
66585 + "chroot_deny_sysctl" is created.
66586 +
66587 +config GRKERNSEC_CHROOT_CAPS
66588 + bool "Capability restrictions"
66589 + default y if GRKERNSEC_CONFIG_AUTO
66590 + depends on GRKERNSEC_CHROOT
66591 + help
66592 + If you say Y here, the capabilities on all processes within a
66593 + chroot jail will be lowered to stop module insertion, raw i/o,
66594 + system and net admin tasks, rebooting the system, modifying immutable
66595 + files, modifying IPC owned by another, and changing the system time.
66596 + This is left an option because it can break some apps. Disable this
66597 + if your chrooted apps are having problems performing those kinds of
66598 + tasks. If the sysctl option is enabled, a sysctl option with
66599 + name "chroot_caps" is created.
66600 +
66601 +config GRKERNSEC_CHROOT_INITRD
66602 + bool "Exempt initrd tasks from restrictions"
66603 + default y if GRKERNSEC_CONFIG_AUTO
66604 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66605 + help
66606 + If you say Y here, tasks started prior to init will be exempted from
66607 + grsecurity's chroot restrictions. This option is mainly meant to
66608 + resolve Plymouth's performing privileged operations unnecessarily
66609 + in a chroot.
66610 +
66611 +endmenu
66612 +menu "Kernel Auditing"
66613 +depends on GRKERNSEC
66614 +
66615 +config GRKERNSEC_AUDIT_GROUP
66616 + bool "Single group for auditing"
66617 + help
66618 + If you say Y here, the exec and chdir logging features will only operate
66619 + on a group you specify. This option is recommended if you only want to
66620 + watch certain users instead of having a large amount of logs from the
66621 + entire system. If the sysctl option is enabled, a sysctl option with
66622 + name "audit_group" is created.
66623 +
66624 +config GRKERNSEC_AUDIT_GID
66625 + int "GID for auditing"
66626 + depends on GRKERNSEC_AUDIT_GROUP
66627 + default 1007
66628 +
66629 +config GRKERNSEC_EXECLOG
66630 + bool "Exec logging"
66631 + help
66632 + If you say Y here, all execve() calls will be logged (since the
66633 + other exec*() calls are frontends to execve(), all execution
66634 + will be logged). Useful for shell-servers that like to keep track
66635 + of their users. If the sysctl option is enabled, a sysctl option with
66636 + name "exec_logging" is created.
66637 + WARNING: This option when enabled will produce a LOT of logs, especially
66638 + on an active system.
66639 +
66640 +config GRKERNSEC_RESLOG
66641 + bool "Resource logging"
66642 + default y if GRKERNSEC_CONFIG_AUTO
66643 + help
66644 + If you say Y here, all attempts to overstep resource limits will
66645 + be logged with the resource name, the requested size, and the current
66646 + limit. It is highly recommended that you say Y here. If the sysctl
66647 + option is enabled, a sysctl option with name "resource_logging" is
66648 + created. If the RBAC system is enabled, the sysctl value is ignored.
66649 +
66650 +config GRKERNSEC_CHROOT_EXECLOG
66651 + bool "Log execs within chroot"
66652 + help
66653 + If you say Y here, all executions inside a chroot jail will be logged
66654 + to syslog. This can cause a large amount of logs if certain
66655 + applications (eg. djb's daemontools) are installed on the system, and
66656 + is therefore left as an option. If the sysctl option is enabled, a
66657 + sysctl option with name "chroot_execlog" is created.
66658 +
66659 +config GRKERNSEC_AUDIT_PTRACE
66660 + bool "Ptrace logging"
66661 + help
66662 + If you say Y here, all attempts to attach to a process via ptrace
66663 + will be logged. If the sysctl option is enabled, a sysctl option
66664 + with name "audit_ptrace" is created.
66665 +
66666 +config GRKERNSEC_AUDIT_CHDIR
66667 + bool "Chdir logging"
66668 + help
66669 + If you say Y here, all chdir() calls will be logged. If the sysctl
66670 + option is enabled, a sysctl option with name "audit_chdir" is created.
66671 +
66672 +config GRKERNSEC_AUDIT_MOUNT
66673 + bool "(Un)Mount logging"
66674 + help
66675 + If you say Y here, all mounts and unmounts will be logged. If the
66676 + sysctl option is enabled, a sysctl option with name "audit_mount" is
66677 + created.
66678 +
66679 +config GRKERNSEC_SIGNAL
66680 + bool "Signal logging"
66681 + default y if GRKERNSEC_CONFIG_AUTO
66682 + help
66683 + If you say Y here, certain important signals will be logged, such as
66684 + SIGSEGV, which will as a result inform you of when a error in a program
66685 + occurred, which in some cases could mean a possible exploit attempt.
66686 + If the sysctl option is enabled, a sysctl option with name
66687 + "signal_logging" is created.
66688 +
66689 +config GRKERNSEC_FORKFAIL
66690 + bool "Fork failure logging"
66691 + help
66692 + If you say Y here, all failed fork() attempts will be logged.
66693 + This could suggest a fork bomb, or someone attempting to overstep
66694 + their process limit. If the sysctl option is enabled, a sysctl option
66695 + with name "forkfail_logging" is created.
66696 +
66697 +config GRKERNSEC_TIME
66698 + bool "Time change logging"
66699 + default y if GRKERNSEC_CONFIG_AUTO
66700 + help
66701 + If you say Y here, any changes of the system clock will be logged.
66702 + If the sysctl option is enabled, a sysctl option with name
66703 + "timechange_logging" is created.
66704 +
66705 +config GRKERNSEC_PROC_IPADDR
66706 + bool "/proc/<pid>/ipaddr support"
66707 + default y if GRKERNSEC_CONFIG_AUTO
66708 + help
66709 + If you say Y here, a new entry will be added to each /proc/<pid>
66710 + directory that contains the IP address of the person using the task.
66711 + The IP is carried across local TCP and AF_UNIX stream sockets.
66712 + This information can be useful for IDS/IPSes to perform remote response
66713 + to a local attack. The entry is readable by only the owner of the
66714 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66715 + the RBAC system), and thus does not create privacy concerns.
66716 +
66717 +config GRKERNSEC_RWXMAP_LOG
66718 + bool 'Denied RWX mmap/mprotect logging'
66719 + default y if GRKERNSEC_CONFIG_AUTO
66720 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66721 + help
66722 + If you say Y here, calls to mmap() and mprotect() with explicit
66723 + usage of PROT_WRITE and PROT_EXEC together will be logged when
66724 + denied by the PAX_MPROTECT feature. This feature will also
66725 + log other problematic scenarios that can occur when PAX_MPROTECT
66726 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
66727 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66728 + is created.
66729 +
66730 +endmenu
66731 +
66732 +menu "Executable Protections"
66733 +depends on GRKERNSEC
66734 +
66735 +config GRKERNSEC_DMESG
66736 + bool "Dmesg(8) restriction"
66737 + default y if GRKERNSEC_CONFIG_AUTO
66738 + help
66739 + If you say Y here, non-root users will not be able to use dmesg(8)
66740 + to view the contents of the kernel's circular log buffer.
66741 + The kernel's log buffer often contains kernel addresses and other
66742 + identifying information useful to an attacker in fingerprinting a
66743 + system for a targeted exploit.
66744 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
66745 + created.
66746 +
66747 +config GRKERNSEC_HARDEN_PTRACE
66748 + bool "Deter ptrace-based process snooping"
66749 + default y if GRKERNSEC_CONFIG_AUTO
66750 + help
66751 + If you say Y here, TTY sniffers and other malicious monitoring
66752 + programs implemented through ptrace will be defeated. If you
66753 + have been using the RBAC system, this option has already been
66754 + enabled for several years for all users, with the ability to make
66755 + fine-grained exceptions.
66756 +
66757 + This option only affects the ability of non-root users to ptrace
66758 + processes that are not a descendent of the ptracing process.
66759 + This means that strace ./binary and gdb ./binary will still work,
66760 + but attaching to arbitrary processes will not. If the sysctl
66761 + option is enabled, a sysctl option with name "harden_ptrace" is
66762 + created.
66763 +
66764 +config GRKERNSEC_PTRACE_READEXEC
66765 + bool "Require read access to ptrace sensitive binaries"
66766 + default y if GRKERNSEC_CONFIG_AUTO
66767 + help
66768 + If you say Y here, unprivileged users will not be able to ptrace unreadable
66769 + binaries. This option is useful in environments that
66770 + remove the read bits (e.g. file mode 4711) from suid binaries to
66771 + prevent infoleaking of their contents. This option adds
66772 + consistency to the use of that file mode, as the binary could normally
66773 + be read out when run without privileges while ptracing.
66774 +
66775 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66776 + is created.
66777 +
66778 +config GRKERNSEC_SETXID
66779 + bool "Enforce consistent multithreaded privileges"
66780 + default y if GRKERNSEC_CONFIG_AUTO
66781 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66782 + help
66783 + If you say Y here, a change from a root uid to a non-root uid
66784 + in a multithreaded application will cause the resulting uids,
66785 + gids, supplementary groups, and capabilities in that thread
66786 + to be propagated to the other threads of the process. In most
66787 + cases this is unnecessary, as glibc will emulate this behavior
66788 + on behalf of the application. Other libcs do not act in the
66789 + same way, allowing the other threads of the process to continue
66790 + running with root privileges. If the sysctl option is enabled,
66791 + a sysctl option with name "consistent_setxid" is created.
66792 +
66793 +config GRKERNSEC_HARDEN_IPC
66794 + bool "Disallow access to overly-permissive IPC objects"
66795 + default y if GRKERNSEC_CONFIG_AUTO
66796 + depends on SYSVIPC
66797 + help
66798 + If you say Y here, access to overly-permissive IPC objects (shared
66799 + memory, message queues, and semaphores) will be denied for processes
66800 + given the following criteria beyond normal permission checks:
66801 + 1) If the IPC object is world-accessible and the euid doesn't match
66802 + that of the creator or current uid for the IPC object
66803 + 2) If the IPC object is group-accessible and the egid doesn't
66804 + match that of the creator or current gid for the IPC object
66805 + It's a common error to grant too much permission to these objects,
66806 + with impact ranging from denial of service and information leaking to
66807 + privilege escalation. This feature was developed in response to
66808 + research by Tim Brown:
66809 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66810 + who found hundreds of such insecure usages. Processes with
66811 + CAP_IPC_OWNER are still permitted to access these IPC objects.
66812 + If the sysctl option is enabled, a sysctl option with name
66813 + "harden_ipc" is created.
66814 +
66815 +config GRKERNSEC_TPE
66816 + bool "Trusted Path Execution (TPE)"
66817 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66818 + help
66819 + If you say Y here, you will be able to choose a gid to add to the
66820 + supplementary groups of users you want to mark as "untrusted."
66821 + These users will not be able to execute any files that are not in
66822 + root-owned directories writable only by root. If the sysctl option
66823 + is enabled, a sysctl option with name "tpe" is created.
66824 +
66825 +config GRKERNSEC_TPE_ALL
66826 + bool "Partially restrict all non-root users"
66827 + depends on GRKERNSEC_TPE
66828 + help
66829 + If you say Y here, all non-root users will be covered under
66830 + a weaker TPE restriction. This is separate from, and in addition to,
66831 + the main TPE options that you have selected elsewhere. Thus, if a
66832 + "trusted" GID is chosen, this restriction applies to even that GID.
66833 + Under this restriction, all non-root users will only be allowed to
66834 + execute files in directories they own that are not group or
66835 + world-writable, or in directories owned by root and writable only by
66836 + root. If the sysctl option is enabled, a sysctl option with name
66837 + "tpe_restrict_all" is created.
66838 +
66839 +config GRKERNSEC_TPE_INVERT
66840 + bool "Invert GID option"
66841 + depends on GRKERNSEC_TPE
66842 + help
66843 + If you say Y here, the group you specify in the TPE configuration will
66844 + decide what group TPE restrictions will be *disabled* for. This
66845 + option is useful if you want TPE restrictions to be applied to most
66846 + users on the system. If the sysctl option is enabled, a sysctl option
66847 + with name "tpe_invert" is created. Unlike other sysctl options, this
66848 + entry will default to on for backward-compatibility.
66849 +
66850 +config GRKERNSEC_TPE_GID
66851 + int
66852 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66853 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66854 +
66855 +config GRKERNSEC_TPE_UNTRUSTED_GID
66856 + int "GID for TPE-untrusted users"
66857 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66858 + default 1005
66859 + help
66860 + Setting this GID determines what group TPE restrictions will be
66861 + *enabled* for. If the sysctl option is enabled, a sysctl option
66862 + with name "tpe_gid" is created.
66863 +
66864 +config GRKERNSEC_TPE_TRUSTED_GID
66865 + int "GID for TPE-trusted users"
66866 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66867 + default 1005
66868 + help
66869 + Setting this GID determines what group TPE restrictions will be
66870 + *disabled* for. If the sysctl option is enabled, a sysctl option
66871 + with name "tpe_gid" is created.
66872 +
66873 +endmenu
66874 +menu "Network Protections"
66875 +depends on GRKERNSEC
66876 +
66877 +config GRKERNSEC_RANDNET
66878 + bool "Larger entropy pools"
66879 + default y if GRKERNSEC_CONFIG_AUTO
66880 + help
66881 + If you say Y here, the entropy pools used for many features of Linux
66882 + and grsecurity will be doubled in size. Since several grsecurity
66883 + features use additional randomness, it is recommended that you say Y
66884 + here. Saying Y here has a similar effect as modifying
66885 + /proc/sys/kernel/random/poolsize.
66886 +
66887 +config GRKERNSEC_BLACKHOLE
66888 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66889 + default y if GRKERNSEC_CONFIG_AUTO
66890 + depends on NET
66891 + help
66892 + If you say Y here, neither TCP resets nor ICMP
66893 + destination-unreachable packets will be sent in response to packets
66894 + sent to ports for which no associated listening process exists.
66895 + This feature supports both IPV4 and IPV6 and exempts the
66896 + loopback interface from blackholing. Enabling this feature
66897 + makes a host more resilient to DoS attacks and reduces network
66898 + visibility against scanners.
66899 +
66900 + The blackhole feature as-implemented is equivalent to the FreeBSD
66901 + blackhole feature, as it prevents RST responses to all packets, not
66902 + just SYNs. Under most application behavior this causes no
66903 + problems, but applications (like haproxy) may not close certain
66904 + connections in a way that cleanly terminates them on the remote
66905 + end, leaving the remote host in LAST_ACK state. Because of this
66906 + side-effect and to prevent intentional LAST_ACK DoSes, this
66907 + feature also adds automatic mitigation against such attacks.
66908 + The mitigation drastically reduces the amount of time a socket
66909 + can spend in LAST_ACK state. If you're using haproxy and not
66910 + all servers it connects to have this option enabled, consider
66911 + disabling this feature on the haproxy host.
66912 +
66913 + If the sysctl option is enabled, two sysctl options with names
66914 + "ip_blackhole" and "lastack_retries" will be created.
66915 + While "ip_blackhole" takes the standard zero/non-zero on/off
66916 + toggle, "lastack_retries" uses the same kinds of values as
66917 + "tcp_retries1" and "tcp_retries2". The default value of 4
66918 + prevents a socket from lasting more than 45 seconds in LAST_ACK
66919 + state.
66920 +
66921 +config GRKERNSEC_NO_SIMULT_CONNECT
66922 + bool "Disable TCP Simultaneous Connect"
66923 + default y if GRKERNSEC_CONFIG_AUTO
66924 + depends on NET
66925 + help
66926 + If you say Y here, a feature by Willy Tarreau will be enabled that
66927 + removes a weakness in Linux's strict implementation of TCP that
66928 + allows two clients to connect to each other without either entering
66929 + a listening state. The weakness allows an attacker to easily prevent
66930 + a client from connecting to a known server provided the source port
66931 + for the connection is guessed correctly.
66932 +
66933 + As the weakness could be used to prevent an antivirus or IPS from
66934 + fetching updates, or prevent an SSL gateway from fetching a CRL,
66935 + it should be eliminated by enabling this option. Though Linux is
66936 + one of few operating systems supporting simultaneous connect, it
66937 + has no legitimate use in practice and is rarely supported by firewalls.
66938 +
66939 +config GRKERNSEC_SOCKET
66940 + bool "Socket restrictions"
66941 + depends on NET
66942 + help
66943 + If you say Y here, you will be able to choose from several options.
66944 + If you assign a GID on your system and add it to the supplementary
66945 + groups of users you want to restrict socket access to, this patch
66946 + will perform up to three things, based on the option(s) you choose.
66947 +
66948 +config GRKERNSEC_SOCKET_ALL
66949 + bool "Deny any sockets to group"
66950 + depends on GRKERNSEC_SOCKET
66951 + help
66952 + If you say Y here, you will be able to choose a GID of whose users will
66953 + be unable to connect to other hosts from your machine or run server
66954 + applications from your machine. If the sysctl option is enabled, a
66955 + sysctl option with name "socket_all" is created.
66956 +
66957 +config GRKERNSEC_SOCKET_ALL_GID
66958 + int "GID to deny all sockets for"
66959 + depends on GRKERNSEC_SOCKET_ALL
66960 + default 1004
66961 + help
66962 + Here you can choose the GID to disable socket access for. Remember to
66963 + add the users you want socket access disabled for to the GID
66964 + specified here. If the sysctl option is enabled, a sysctl option
66965 + with name "socket_all_gid" is created.
66966 +
66967 +config GRKERNSEC_SOCKET_CLIENT
66968 + bool "Deny client sockets to group"
66969 + depends on GRKERNSEC_SOCKET
66970 + help
66971 + If you say Y here, you will be able to choose a GID of whose users will
66972 + be unable to connect to other hosts from your machine, but will be
66973 + able to run servers. If this option is enabled, all users in the group
66974 + you specify will have to use passive mode when initiating ftp transfers
66975 + from the shell on your machine. If the sysctl option is enabled, a
66976 + sysctl option with name "socket_client" is created.
66977 +
66978 +config GRKERNSEC_SOCKET_CLIENT_GID
66979 + int "GID to deny client sockets for"
66980 + depends on GRKERNSEC_SOCKET_CLIENT
66981 + default 1003
66982 + help
66983 + Here you can choose the GID to disable client socket access for.
66984 + Remember to add the users you want client socket access disabled for to
66985 + the GID specified here. If the sysctl option is enabled, a sysctl
66986 + option with name "socket_client_gid" is created.
66987 +
66988 +config GRKERNSEC_SOCKET_SERVER
66989 + bool "Deny server sockets to group"
66990 + depends on GRKERNSEC_SOCKET
66991 + help
66992 + If you say Y here, you will be able to choose a GID of whose users will
66993 + be unable to run server applications from your machine. If the sysctl
66994 + option is enabled, a sysctl option with name "socket_server" is created.
66995 +
66996 +config GRKERNSEC_SOCKET_SERVER_GID
66997 + int "GID to deny server sockets for"
66998 + depends on GRKERNSEC_SOCKET_SERVER
66999 + default 1002
67000 + help
67001 + Here you can choose the GID to disable server socket access for.
67002 + Remember to add the users you want server socket access disabled for to
67003 + the GID specified here. If the sysctl option is enabled, a sysctl
67004 + option with name "socket_server_gid" is created.
67005 +
67006 +endmenu
67007 +
67008 +menu "Physical Protections"
67009 +depends on GRKERNSEC
67010 +
67011 +config GRKERNSEC_DENYUSB
67012 + bool "Deny new USB connections after toggle"
67013 + default y if GRKERNSEC_CONFIG_AUTO
67014 + depends on SYSCTL && USB_SUPPORT
67015 + help
67016 + If you say Y here, a new sysctl option with name "deny_new_usb"
67017 + will be created. Setting its value to 1 will prevent any new
67018 + USB devices from being recognized by the OS. Any attempted USB
67019 + device insertion will be logged. This option is intended to be
67020 + used against custom USB devices designed to exploit vulnerabilities
67021 + in various USB device drivers.
67022 +
67023 + For greatest effectiveness, this sysctl should be set after any
67024 + relevant init scripts. This option is safe to enable in distros
67025 + as each user can choose whether or not to toggle the sysctl.
67026 +
67027 +config GRKERNSEC_DENYUSB_FORCE
67028 + bool "Reject all USB devices not connected at boot"
67029 + select USB
67030 + depends on GRKERNSEC_DENYUSB
67031 + help
67032 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
67033 + that doesn't involve a sysctl entry. This option should only be
67034 + enabled if you're sure you want to deny all new USB connections
67035 + at runtime and don't want to modify init scripts. This should not
67036 + be enabled by distros. It forces the core USB code to be built
67037 + into the kernel image so that all devices connected at boot time
67038 + can be recognized and new USB device connections can be prevented
67039 + prior to init running.
67040 +
67041 +endmenu
67042 +
67043 +menu "Sysctl Support"
67044 +depends on GRKERNSEC && SYSCTL
67045 +
67046 +config GRKERNSEC_SYSCTL
67047 + bool "Sysctl support"
67048 + default y if GRKERNSEC_CONFIG_AUTO
67049 + help
67050 + If you say Y here, you will be able to change the options that
67051 + grsecurity runs with at bootup, without having to recompile your
67052 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
67053 + to enable (1) or disable (0) various features. All the sysctl entries
67054 + are mutable until the "grsec_lock" entry is set to a non-zero value.
67055 + All features enabled in the kernel configuration are disabled at boot
67056 + if you do not say Y to the "Turn on features by default" option.
67057 + All options should be set at startup, and the grsec_lock entry should
67058 + be set to a non-zero value after all the options are set.
67059 + *THIS IS EXTREMELY IMPORTANT*
67060 +
67061 +config GRKERNSEC_SYSCTL_DISTRO
67062 + bool "Extra sysctl support for distro makers (READ HELP)"
67063 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
67064 + help
67065 + If you say Y here, additional sysctl options will be created
67066 + for features that affect processes running as root. Therefore,
67067 + it is critical when using this option that the grsec_lock entry be
67068 + enabled after boot. Only distros with prebuilt kernel packages
67069 + with this option enabled that can ensure grsec_lock is enabled
67070 + after boot should use this option.
67071 + *Failure to set grsec_lock after boot makes all grsec features
67072 + this option covers useless*
67073 +
67074 + Currently this option creates the following sysctl entries:
67075 + "Disable Privileged I/O": "disable_priv_io"
67076 +
67077 +config GRKERNSEC_SYSCTL_ON
67078 + bool "Turn on features by default"
67079 + default y if GRKERNSEC_CONFIG_AUTO
67080 + depends on GRKERNSEC_SYSCTL
67081 + help
67082 + If you say Y here, instead of having all features enabled in the
67083 + kernel configuration disabled at boot time, the features will be
67084 + enabled at boot time. It is recommended you say Y here unless
67085 + there is some reason you would want all sysctl-tunable features to
67086 + be disabled by default. As mentioned elsewhere, it is important
67087 + to enable the grsec_lock entry once you have finished modifying
67088 + the sysctl entries.
67089 +
67090 +endmenu
67091 +menu "Logging Options"
67092 +depends on GRKERNSEC
67093 +
67094 +config GRKERNSEC_FLOODTIME
67095 + int "Seconds in between log messages (minimum)"
67096 + default 10
67097 + help
67098 + This option allows you to enforce the number of seconds between
67099 + grsecurity log messages. The default should be suitable for most
67100 + people, however, if you choose to change it, choose a value small enough
67101 + to allow informative logs to be produced, but large enough to
67102 + prevent flooding.
67103 +
67104 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
67105 + any rate limiting on grsecurity log messages.
67106 +
67107 +config GRKERNSEC_FLOODBURST
67108 + int "Number of messages in a burst (maximum)"
67109 + default 6
67110 + help
67111 + This option allows you to choose the maximum number of messages allowed
67112 + within the flood time interval you chose in a separate option. The
67113 + default should be suitable for most people, however if you find that
67114 + many of your logs are being interpreted as flooding, you may want to
67115 + raise this value.
67116 +
67117 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
67118 + any rate limiting on grsecurity log messages.
67119 +
67120 +endmenu
67121 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
67122 new file mode 100644
67123 index 0000000..30ababb
67124 --- /dev/null
67125 +++ b/grsecurity/Makefile
67126 @@ -0,0 +1,54 @@
67127 +# grsecurity – access control and security hardening for Linux
67128 +# All code in this directory and various hooks located throughout the Linux kernel are
67129 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
67130 +# http://www.grsecurity.net spender@grsecurity.net
67131 +#
67132 +# This program is free software; you can redistribute it and/or
67133 +# modify it under the terms of the GNU General Public License version 2
67134 +# as published by the Free Software Foundation.
67135 +#
67136 +# This program is distributed in the hope that it will be useful,
67137 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
67138 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67139 +# GNU General Public License for more details.
67140 +#
67141 +# You should have received a copy of the GNU General Public License
67142 +# along with this program; if not, write to the Free Software
67143 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
67144 +
67145 +KBUILD_CFLAGS += -Werror
67146 +
67147 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
67148 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
67149 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
67150 + grsec_usb.o grsec_ipc.o grsec_proc.o
67151 +
67152 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
67153 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
67154 + gracl_learn.o grsec_log.o gracl_policy.o
67155 +ifdef CONFIG_COMPAT
67156 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
67157 +endif
67158 +
67159 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
67160 +
67161 +ifdef CONFIG_NET
67162 +obj-y += grsec_sock.o
67163 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
67164 +endif
67165 +
67166 +ifndef CONFIG_GRKERNSEC
67167 +obj-y += grsec_disabled.o
67168 +endif
67169 +
67170 +ifdef CONFIG_GRKERNSEC_HIDESYM
67171 +extra-y := grsec_hidesym.o
67172 +$(obj)/grsec_hidesym.o:
67173 + @-chmod -f 500 /boot
67174 + @-chmod -f 500 /lib/modules
67175 + @-chmod -f 500 /lib64/modules
67176 + @-chmod -f 500 /lib32/modules
67177 + @-chmod -f 700 .
67178 + @-chmod -f 700 $(objtree)
67179 + @echo ' grsec: protected kernel image paths'
67180 +endif
67181 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
67182 new file mode 100644
67183 index 0000000..e56396f
67184 --- /dev/null
67185 +++ b/grsecurity/gracl.c
67186 @@ -0,0 +1,2679 @@
67187 +#include <linux/kernel.h>
67188 +#include <linux/module.h>
67189 +#include <linux/sched.h>
67190 +#include <linux/mm.h>
67191 +#include <linux/file.h>
67192 +#include <linux/fs.h>
67193 +#include <linux/namei.h>
67194 +#include <linux/mount.h>
67195 +#include <linux/tty.h>
67196 +#include <linux/proc_fs.h>
67197 +#include <linux/lglock.h>
67198 +#include <linux/slab.h>
67199 +#include <linux/vmalloc.h>
67200 +#include <linux/types.h>
67201 +#include <linux/sysctl.h>
67202 +#include <linux/netdevice.h>
67203 +#include <linux/ptrace.h>
67204 +#include <linux/gracl.h>
67205 +#include <linux/gralloc.h>
67206 +#include <linux/security.h>
67207 +#include <linux/grinternal.h>
67208 +#include <linux/pid_namespace.h>
67209 +#include <linux/stop_machine.h>
67210 +#include <linux/fdtable.h>
67211 +#include <linux/percpu.h>
67212 +#include <linux/lglock.h>
67213 +#include <linux/hugetlb.h>
67214 +#include <linux/posix-timers.h>
67215 +#include <linux/prefetch.h>
67216 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67217 +#include <linux/magic.h>
67218 +#include <linux/pagemap.h>
67219 +#include "../fs/btrfs/async-thread.h"
67220 +#include "../fs/btrfs/ctree.h"
67221 +#include "../fs/btrfs/btrfs_inode.h"
67222 +#endif
67223 +#include "../fs/mount.h"
67224 +
67225 +#include <asm/uaccess.h>
67226 +#include <asm/errno.h>
67227 +#include <asm/mman.h>
67228 +
67229 +#define FOR_EACH_ROLE_START(role) \
67230 + role = running_polstate.role_list; \
67231 + while (role) {
67232 +
67233 +#define FOR_EACH_ROLE_END(role) \
67234 + role = role->prev; \
67235 + }
67236 +
67237 +extern struct path gr_real_root;
67238 +
67239 +static struct gr_policy_state running_polstate;
67240 +struct gr_policy_state *polstate = &running_polstate;
67241 +extern struct gr_alloc_state *current_alloc_state;
67242 +
67243 +extern char *gr_shared_page[4];
67244 +DEFINE_RWLOCK(gr_inode_lock);
67245 +
67246 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
67247 +
67248 +#ifdef CONFIG_NET
67249 +extern struct vfsmount *sock_mnt;
67250 +#endif
67251 +
67252 +extern struct vfsmount *pipe_mnt;
67253 +extern struct vfsmount *shm_mnt;
67254 +
67255 +#ifdef CONFIG_HUGETLBFS
67256 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67257 +#endif
67258 +
67259 +extern u16 acl_sp_role_value;
67260 +extern struct acl_object_label *fakefs_obj_rw;
67261 +extern struct acl_object_label *fakefs_obj_rwx;
67262 +
67263 +int gr_acl_is_enabled(void)
67264 +{
67265 + return (gr_status & GR_READY);
67266 +}
67267 +
67268 +void gr_enable_rbac_system(void)
67269 +{
67270 + pax_open_kernel();
67271 + gr_status |= GR_READY;
67272 + pax_close_kernel();
67273 +}
67274 +
67275 +int gr_rbac_disable(void *unused)
67276 +{
67277 + pax_open_kernel();
67278 + gr_status &= ~GR_READY;
67279 + pax_close_kernel();
67280 +
67281 + return 0;
67282 +}
67283 +
67284 +static inline dev_t __get_dev(const struct dentry *dentry)
67285 +{
67286 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67287 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67288 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
67289 + else
67290 +#endif
67291 + return dentry->d_sb->s_dev;
67292 +}
67293 +
67294 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67295 +{
67296 + return __get_dev(dentry);
67297 +}
67298 +
67299 +static char gr_task_roletype_to_char(struct task_struct *task)
67300 +{
67301 + switch (task->role->roletype &
67302 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67303 + GR_ROLE_SPECIAL)) {
67304 + case GR_ROLE_DEFAULT:
67305 + return 'D';
67306 + case GR_ROLE_USER:
67307 + return 'U';
67308 + case GR_ROLE_GROUP:
67309 + return 'G';
67310 + case GR_ROLE_SPECIAL:
67311 + return 'S';
67312 + }
67313 +
67314 + return 'X';
67315 +}
67316 +
67317 +char gr_roletype_to_char(void)
67318 +{
67319 + return gr_task_roletype_to_char(current);
67320 +}
67321 +
67322 +__inline__ int
67323 +gr_acl_tpe_check(void)
67324 +{
67325 + if (unlikely(!(gr_status & GR_READY)))
67326 + return 0;
67327 + if (current->role->roletype & GR_ROLE_TPE)
67328 + return 1;
67329 + else
67330 + return 0;
67331 +}
67332 +
67333 +int
67334 +gr_handle_rawio(const struct inode *inode)
67335 +{
67336 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67337 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67338 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67339 + !capable(CAP_SYS_RAWIO))
67340 + return 1;
67341 +#endif
67342 + return 0;
67343 +}
67344 +
67345 +int
67346 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67347 +{
67348 + if (likely(lena != lenb))
67349 + return 0;
67350 +
67351 + return !memcmp(a, b, lena);
67352 +}
67353 +
67354 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67355 +{
67356 + *buflen -= namelen;
67357 + if (*buflen < 0)
67358 + return -ENAMETOOLONG;
67359 + *buffer -= namelen;
67360 + memcpy(*buffer, str, namelen);
67361 + return 0;
67362 +}
67363 +
67364 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67365 +{
67366 + return prepend(buffer, buflen, name->name, name->len);
67367 +}
67368 +
67369 +static int prepend_path(const struct path *path, struct path *root,
67370 + char **buffer, int *buflen)
67371 +{
67372 + struct dentry *dentry = path->dentry;
67373 + struct vfsmount *vfsmnt = path->mnt;
67374 + struct mount *mnt = real_mount(vfsmnt);
67375 + bool slash = false;
67376 + int error = 0;
67377 +
67378 + while (dentry != root->dentry || vfsmnt != root->mnt) {
67379 + struct dentry * parent;
67380 +
67381 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67382 + /* Global root? */
67383 + if (!mnt_has_parent(mnt)) {
67384 + goto out;
67385 + }
67386 + dentry = mnt->mnt_mountpoint;
67387 + mnt = mnt->mnt_parent;
67388 + vfsmnt = &mnt->mnt;
67389 + continue;
67390 + }
67391 + parent = dentry->d_parent;
67392 + prefetch(parent);
67393 + spin_lock(&dentry->d_lock);
67394 + error = prepend_name(buffer, buflen, &dentry->d_name);
67395 + spin_unlock(&dentry->d_lock);
67396 + if (!error)
67397 + error = prepend(buffer, buflen, "/", 1);
67398 + if (error)
67399 + break;
67400 +
67401 + slash = true;
67402 + dentry = parent;
67403 + }
67404 +
67405 +out:
67406 + if (!error && !slash)
67407 + error = prepend(buffer, buflen, "/", 1);
67408 +
67409 + return error;
67410 +}
67411 +
67412 +/* this must be called with mount_lock and rename_lock held */
67413 +
67414 +static char *__our_d_path(const struct path *path, struct path *root,
67415 + char *buf, int buflen)
67416 +{
67417 + char *res = buf + buflen;
67418 + int error;
67419 +
67420 + prepend(&res, &buflen, "\0", 1);
67421 + error = prepend_path(path, root, &res, &buflen);
67422 + if (error)
67423 + return ERR_PTR(error);
67424 +
67425 + return res;
67426 +}
67427 +
67428 +static char *
67429 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67430 +{
67431 + char *retval;
67432 +
67433 + retval = __our_d_path(path, root, buf, buflen);
67434 + if (unlikely(IS_ERR(retval)))
67435 + retval = strcpy(buf, "<path too long>");
67436 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67437 + retval[1] = '\0';
67438 +
67439 + return retval;
67440 +}
67441 +
67442 +static char *
67443 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67444 + char *buf, int buflen)
67445 +{
67446 + struct path path;
67447 + char *res;
67448 +
67449 + path.dentry = (struct dentry *)dentry;
67450 + path.mnt = (struct vfsmount *)vfsmnt;
67451 +
67452 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67453 + by the RBAC system */
67454 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
67455 +
67456 + return res;
67457 +}
67458 +
67459 +static char *
67460 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67461 + char *buf, int buflen)
67462 +{
67463 + char *res;
67464 + struct path path;
67465 + struct path root;
67466 + struct task_struct *reaper = init_pid_ns.child_reaper;
67467 +
67468 + path.dentry = (struct dentry *)dentry;
67469 + path.mnt = (struct vfsmount *)vfsmnt;
67470 +
67471 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67472 + get_fs_root(reaper->fs, &root);
67473 +
67474 + read_seqlock_excl(&mount_lock);
67475 + write_seqlock(&rename_lock);
67476 + res = gen_full_path(&path, &root, buf, buflen);
67477 + write_sequnlock(&rename_lock);
67478 + read_sequnlock_excl(&mount_lock);
67479 +
67480 + path_put(&root);
67481 + return res;
67482 +}
67483 +
67484 +char *
67485 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67486 +{
67487 + char *ret;
67488 + read_seqlock_excl(&mount_lock);
67489 + write_seqlock(&rename_lock);
67490 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67491 + PAGE_SIZE);
67492 + write_sequnlock(&rename_lock);
67493 + read_sequnlock_excl(&mount_lock);
67494 + return ret;
67495 +}
67496 +
67497 +static char *
67498 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67499 +{
67500 + char *ret;
67501 + char *buf;
67502 + int buflen;
67503 +
67504 + read_seqlock_excl(&mount_lock);
67505 + write_seqlock(&rename_lock);
67506 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67507 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67508 + buflen = (int)(ret - buf);
67509 + if (buflen >= 5)
67510 + prepend(&ret, &buflen, "/proc", 5);
67511 + else
67512 + ret = strcpy(buf, "<path too long>");
67513 + write_sequnlock(&rename_lock);
67514 + read_sequnlock_excl(&mount_lock);
67515 + return ret;
67516 +}
67517 +
67518 +char *
67519 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67520 +{
67521 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67522 + PAGE_SIZE);
67523 +}
67524 +
67525 +char *
67526 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67527 +{
67528 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67529 + PAGE_SIZE);
67530 +}
67531 +
67532 +char *
67533 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67534 +{
67535 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67536 + PAGE_SIZE);
67537 +}
67538 +
67539 +char *
67540 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67541 +{
67542 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67543 + PAGE_SIZE);
67544 +}
67545 +
67546 +char *
67547 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67548 +{
67549 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67550 + PAGE_SIZE);
67551 +}
67552 +
67553 +__inline__ __u32
67554 +to_gr_audit(const __u32 reqmode)
67555 +{
67556 + /* masks off auditable permission flags, then shifts them to create
67557 + auditing flags, and adds the special case of append auditing if
67558 + we're requesting write */
67559 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67560 +}
67561 +
67562 +struct acl_role_label *
67563 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67564 + const gid_t gid)
67565 +{
67566 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67567 + struct acl_role_label *match;
67568 + struct role_allowed_ip *ipp;
67569 + unsigned int x;
67570 + u32 curr_ip = task->signal->saved_ip;
67571 +
67572 + match = state->acl_role_set.r_hash[index];
67573 +
67574 + while (match) {
67575 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67576 + for (x = 0; x < match->domain_child_num; x++) {
67577 + if (match->domain_children[x] == uid)
67578 + goto found;
67579 + }
67580 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67581 + break;
67582 + match = match->next;
67583 + }
67584 +found:
67585 + if (match == NULL) {
67586 + try_group:
67587 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67588 + match = state->acl_role_set.r_hash[index];
67589 +
67590 + while (match) {
67591 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67592 + for (x = 0; x < match->domain_child_num; x++) {
67593 + if (match->domain_children[x] == gid)
67594 + goto found2;
67595 + }
67596 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67597 + break;
67598 + match = match->next;
67599 + }
67600 +found2:
67601 + if (match == NULL)
67602 + match = state->default_role;
67603 + if (match->allowed_ips == NULL)
67604 + return match;
67605 + else {
67606 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67607 + if (likely
67608 + ((ntohl(curr_ip) & ipp->netmask) ==
67609 + (ntohl(ipp->addr) & ipp->netmask)))
67610 + return match;
67611 + }
67612 + match = state->default_role;
67613 + }
67614 + } else if (match->allowed_ips == NULL) {
67615 + return match;
67616 + } else {
67617 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67618 + if (likely
67619 + ((ntohl(curr_ip) & ipp->netmask) ==
67620 + (ntohl(ipp->addr) & ipp->netmask)))
67621 + return match;
67622 + }
67623 + goto try_group;
67624 + }
67625 +
67626 + return match;
67627 +}
67628 +
67629 +static struct acl_role_label *
67630 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67631 + const gid_t gid)
67632 +{
67633 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67634 +}
67635 +
67636 +struct acl_subject_label *
67637 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67638 + const struct acl_role_label *role)
67639 +{
67640 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67641 + struct acl_subject_label *match;
67642 +
67643 + match = role->subj_hash[index];
67644 +
67645 + while (match && (match->inode != ino || match->device != dev ||
67646 + (match->mode & GR_DELETED))) {
67647 + match = match->next;
67648 + }
67649 +
67650 + if (match && !(match->mode & GR_DELETED))
67651 + return match;
67652 + else
67653 + return NULL;
67654 +}
67655 +
67656 +struct acl_subject_label *
67657 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67658 + const struct acl_role_label *role)
67659 +{
67660 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67661 + struct acl_subject_label *match;
67662 +
67663 + match = role->subj_hash[index];
67664 +
67665 + while (match && (match->inode != ino || match->device != dev ||
67666 + !(match->mode & GR_DELETED))) {
67667 + match = match->next;
67668 + }
67669 +
67670 + if (match && (match->mode & GR_DELETED))
67671 + return match;
67672 + else
67673 + return NULL;
67674 +}
67675 +
67676 +static struct acl_object_label *
67677 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67678 + const struct acl_subject_label *subj)
67679 +{
67680 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67681 + struct acl_object_label *match;
67682 +
67683 + match = subj->obj_hash[index];
67684 +
67685 + while (match && (match->inode != ino || match->device != dev ||
67686 + (match->mode & GR_DELETED))) {
67687 + match = match->next;
67688 + }
67689 +
67690 + if (match && !(match->mode & GR_DELETED))
67691 + return match;
67692 + else
67693 + return NULL;
67694 +}
67695 +
67696 +static struct acl_object_label *
67697 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67698 + const struct acl_subject_label *subj)
67699 +{
67700 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67701 + struct acl_object_label *match;
67702 +
67703 + match = subj->obj_hash[index];
67704 +
67705 + while (match && (match->inode != ino || match->device != dev ||
67706 + !(match->mode & GR_DELETED))) {
67707 + match = match->next;
67708 + }
67709 +
67710 + if (match && (match->mode & GR_DELETED))
67711 + return match;
67712 +
67713 + match = subj->obj_hash[index];
67714 +
67715 + while (match && (match->inode != ino || match->device != dev ||
67716 + (match->mode & GR_DELETED))) {
67717 + match = match->next;
67718 + }
67719 +
67720 + if (match && !(match->mode & GR_DELETED))
67721 + return match;
67722 + else
67723 + return NULL;
67724 +}
67725 +
67726 +struct name_entry *
67727 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67728 +{
67729 + unsigned int len = strlen(name);
67730 + unsigned int key = full_name_hash(name, len);
67731 + unsigned int index = key % state->name_set.n_size;
67732 + struct name_entry *match;
67733 +
67734 + match = state->name_set.n_hash[index];
67735 +
67736 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67737 + match = match->next;
67738 +
67739 + return match;
67740 +}
67741 +
67742 +static struct name_entry *
67743 +lookup_name_entry(const char *name)
67744 +{
67745 + return __lookup_name_entry(&running_polstate, name);
67746 +}
67747 +
67748 +static struct name_entry *
67749 +lookup_name_entry_create(const char *name)
67750 +{
67751 + unsigned int len = strlen(name);
67752 + unsigned int key = full_name_hash(name, len);
67753 + unsigned int index = key % running_polstate.name_set.n_size;
67754 + struct name_entry *match;
67755 +
67756 + match = running_polstate.name_set.n_hash[index];
67757 +
67758 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67759 + !match->deleted))
67760 + match = match->next;
67761 +
67762 + if (match && match->deleted)
67763 + return match;
67764 +
67765 + match = running_polstate.name_set.n_hash[index];
67766 +
67767 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67768 + match->deleted))
67769 + match = match->next;
67770 +
67771 + if (match && !match->deleted)
67772 + return match;
67773 + else
67774 + return NULL;
67775 +}
67776 +
67777 +static struct inodev_entry *
67778 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
67779 +{
67780 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67781 + struct inodev_entry *match;
67782 +
67783 + match = running_polstate.inodev_set.i_hash[index];
67784 +
67785 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67786 + match = match->next;
67787 +
67788 + return match;
67789 +}
67790 +
67791 +void
67792 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67793 +{
67794 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67795 + state->inodev_set.i_size);
67796 + struct inodev_entry **curr;
67797 +
67798 + entry->prev = NULL;
67799 +
67800 + curr = &state->inodev_set.i_hash[index];
67801 + if (*curr != NULL)
67802 + (*curr)->prev = entry;
67803 +
67804 + entry->next = *curr;
67805 + *curr = entry;
67806 +
67807 + return;
67808 +}
67809 +
67810 +static void
67811 +insert_inodev_entry(struct inodev_entry *entry)
67812 +{
67813 + __insert_inodev_entry(&running_polstate, entry);
67814 +}
67815 +
67816 +void
67817 +insert_acl_obj_label(struct acl_object_label *obj,
67818 + struct acl_subject_label *subj)
67819 +{
67820 + unsigned int index =
67821 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67822 + struct acl_object_label **curr;
67823 +
67824 + obj->prev = NULL;
67825 +
67826 + curr = &subj->obj_hash[index];
67827 + if (*curr != NULL)
67828 + (*curr)->prev = obj;
67829 +
67830 + obj->next = *curr;
67831 + *curr = obj;
67832 +
67833 + return;
67834 +}
67835 +
67836 +void
67837 +insert_acl_subj_label(struct acl_subject_label *obj,
67838 + struct acl_role_label *role)
67839 +{
67840 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67841 + struct acl_subject_label **curr;
67842 +
67843 + obj->prev = NULL;
67844 +
67845 + curr = &role->subj_hash[index];
67846 + if (*curr != NULL)
67847 + (*curr)->prev = obj;
67848 +
67849 + obj->next = *curr;
67850 + *curr = obj;
67851 +
67852 + return;
67853 +}
67854 +
67855 +/* derived from glibc fnmatch() 0: match, 1: no match*/
67856 +
67857 +static int
67858 +glob_match(const char *p, const char *n)
67859 +{
67860 + char c;
67861 +
67862 + while ((c = *p++) != '\0') {
67863 + switch (c) {
67864 + case '?':
67865 + if (*n == '\0')
67866 + return 1;
67867 + else if (*n == '/')
67868 + return 1;
67869 + break;
67870 + case '\\':
67871 + if (*n != c)
67872 + return 1;
67873 + break;
67874 + case '*':
67875 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
67876 + if (*n == '/')
67877 + return 1;
67878 + else if (c == '?') {
67879 + if (*n == '\0')
67880 + return 1;
67881 + else
67882 + ++n;
67883 + }
67884 + }
67885 + if (c == '\0') {
67886 + return 0;
67887 + } else {
67888 + const char *endp;
67889 +
67890 + if ((endp = strchr(n, '/')) == NULL)
67891 + endp = n + strlen(n);
67892 +
67893 + if (c == '[') {
67894 + for (--p; n < endp; ++n)
67895 + if (!glob_match(p, n))
67896 + return 0;
67897 + } else if (c == '/') {
67898 + while (*n != '\0' && *n != '/')
67899 + ++n;
67900 + if (*n == '/' && !glob_match(p, n + 1))
67901 + return 0;
67902 + } else {
67903 + for (--p; n < endp; ++n)
67904 + if (*n == c && !glob_match(p, n))
67905 + return 0;
67906 + }
67907 +
67908 + return 1;
67909 + }
67910 + case '[':
67911 + {
67912 + int not;
67913 + char cold;
67914 +
67915 + if (*n == '\0' || *n == '/')
67916 + return 1;
67917 +
67918 + not = (*p == '!' || *p == '^');
67919 + if (not)
67920 + ++p;
67921 +
67922 + c = *p++;
67923 + for (;;) {
67924 + unsigned char fn = (unsigned char)*n;
67925 +
67926 + if (c == '\0')
67927 + return 1;
67928 + else {
67929 + if (c == fn)
67930 + goto matched;
67931 + cold = c;
67932 + c = *p++;
67933 +
67934 + if (c == '-' && *p != ']') {
67935 + unsigned char cend = *p++;
67936 +
67937 + if (cend == '\0')
67938 + return 1;
67939 +
67940 + if (cold <= fn && fn <= cend)
67941 + goto matched;
67942 +
67943 + c = *p++;
67944 + }
67945 + }
67946 +
67947 + if (c == ']')
67948 + break;
67949 + }
67950 + if (!not)
67951 + return 1;
67952 + break;
67953 + matched:
67954 + while (c != ']') {
67955 + if (c == '\0')
67956 + return 1;
67957 +
67958 + c = *p++;
67959 + }
67960 + if (not)
67961 + return 1;
67962 + }
67963 + break;
67964 + default:
67965 + if (c != *n)
67966 + return 1;
67967 + }
67968 +
67969 + ++n;
67970 + }
67971 +
67972 + if (*n == '\0')
67973 + return 0;
67974 +
67975 + if (*n == '/')
67976 + return 0;
67977 +
67978 + return 1;
67979 +}
67980 +
67981 +static struct acl_object_label *
67982 +chk_glob_label(struct acl_object_label *globbed,
67983 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67984 +{
67985 + struct acl_object_label *tmp;
67986 +
67987 + if (*path == NULL)
67988 + *path = gr_to_filename_nolock(dentry, mnt);
67989 +
67990 + tmp = globbed;
67991 +
67992 + while (tmp) {
67993 + if (!glob_match(tmp->filename, *path))
67994 + return tmp;
67995 + tmp = tmp->next;
67996 + }
67997 +
67998 + return NULL;
67999 +}
68000 +
68001 +static struct acl_object_label *
68002 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68003 + const ino_t curr_ino, const dev_t curr_dev,
68004 + const struct acl_subject_label *subj, char **path, const int checkglob)
68005 +{
68006 + struct acl_subject_label *tmpsubj;
68007 + struct acl_object_label *retval;
68008 + struct acl_object_label *retval2;
68009 +
68010 + tmpsubj = (struct acl_subject_label *) subj;
68011 + read_lock(&gr_inode_lock);
68012 + do {
68013 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
68014 + if (retval) {
68015 + if (checkglob && retval->globbed) {
68016 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
68017 + if (retval2)
68018 + retval = retval2;
68019 + }
68020 + break;
68021 + }
68022 + } while ((tmpsubj = tmpsubj->parent_subject));
68023 + read_unlock(&gr_inode_lock);
68024 +
68025 + return retval;
68026 +}
68027 +
68028 +static __inline__ struct acl_object_label *
68029 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
68030 + struct dentry *curr_dentry,
68031 + const struct acl_subject_label *subj, char **path, const int checkglob)
68032 +{
68033 + int newglob = checkglob;
68034 + ino_t inode;
68035 + dev_t device;
68036 +
68037 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
68038 + as we don't want a / * rule to match instead of the / object
68039 + don't do this for create lookups that call this function though, since they're looking up
68040 + on the parent and thus need globbing checks on all paths
68041 + */
68042 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
68043 + newglob = GR_NO_GLOB;
68044 +
68045 + spin_lock(&curr_dentry->d_lock);
68046 + inode = curr_dentry->d_inode->i_ino;
68047 + device = __get_dev(curr_dentry);
68048 + spin_unlock(&curr_dentry->d_lock);
68049 +
68050 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
68051 +}
68052 +
68053 +#ifdef CONFIG_HUGETLBFS
68054 +static inline bool
68055 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
68056 +{
68057 + int i;
68058 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
68059 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
68060 + return true;
68061 + }
68062 +
68063 + return false;
68064 +}
68065 +#endif
68066 +
68067 +static struct acl_object_label *
68068 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68069 + const struct acl_subject_label *subj, char *path, const int checkglob)
68070 +{
68071 + struct dentry *dentry = (struct dentry *) l_dentry;
68072 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68073 + struct mount *real_mnt = real_mount(mnt);
68074 + struct acl_object_label *retval;
68075 + struct dentry *parent;
68076 +
68077 + read_seqlock_excl(&mount_lock);
68078 + write_seqlock(&rename_lock);
68079 +
68080 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
68081 +#ifdef CONFIG_NET
68082 + mnt == sock_mnt ||
68083 +#endif
68084 +#ifdef CONFIG_HUGETLBFS
68085 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
68086 +#endif
68087 + /* ignore Eric Biederman */
68088 + IS_PRIVATE(l_dentry->d_inode))) {
68089 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
68090 + goto out;
68091 + }
68092 +
68093 + for (;;) {
68094 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68095 + break;
68096 +
68097 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68098 + if (!mnt_has_parent(real_mnt))
68099 + break;
68100 +
68101 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68102 + if (retval != NULL)
68103 + goto out;
68104 +
68105 + dentry = real_mnt->mnt_mountpoint;
68106 + real_mnt = real_mnt->mnt_parent;
68107 + mnt = &real_mnt->mnt;
68108 + continue;
68109 + }
68110 +
68111 + parent = dentry->d_parent;
68112 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68113 + if (retval != NULL)
68114 + goto out;
68115 +
68116 + dentry = parent;
68117 + }
68118 +
68119 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68120 +
68121 + /* gr_real_root is pinned so we don't have to hold a reference */
68122 + if (retval == NULL)
68123 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
68124 +out:
68125 + write_sequnlock(&rename_lock);
68126 + read_sequnlock_excl(&mount_lock);
68127 +
68128 + BUG_ON(retval == NULL);
68129 +
68130 + return retval;
68131 +}
68132 +
68133 +static __inline__ struct acl_object_label *
68134 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68135 + const struct acl_subject_label *subj)
68136 +{
68137 + char *path = NULL;
68138 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
68139 +}
68140 +
68141 +static __inline__ struct acl_object_label *
68142 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68143 + const struct acl_subject_label *subj)
68144 +{
68145 + char *path = NULL;
68146 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
68147 +}
68148 +
68149 +static __inline__ struct acl_object_label *
68150 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68151 + const struct acl_subject_label *subj, char *path)
68152 +{
68153 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
68154 +}
68155 +
68156 +struct acl_subject_label *
68157 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68158 + const struct acl_role_label *role)
68159 +{
68160 + struct dentry *dentry = (struct dentry *) l_dentry;
68161 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68162 + struct mount *real_mnt = real_mount(mnt);
68163 + struct acl_subject_label *retval;
68164 + struct dentry *parent;
68165 +
68166 + read_seqlock_excl(&mount_lock);
68167 + write_seqlock(&rename_lock);
68168 +
68169 + for (;;) {
68170 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68171 + break;
68172 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68173 + if (!mnt_has_parent(real_mnt))
68174 + break;
68175 +
68176 + spin_lock(&dentry->d_lock);
68177 + read_lock(&gr_inode_lock);
68178 + retval =
68179 + lookup_acl_subj_label(dentry->d_inode->i_ino,
68180 + __get_dev(dentry), role);
68181 + read_unlock(&gr_inode_lock);
68182 + spin_unlock(&dentry->d_lock);
68183 + if (retval != NULL)
68184 + goto out;
68185 +
68186 + dentry = real_mnt->mnt_mountpoint;
68187 + real_mnt = real_mnt->mnt_parent;
68188 + mnt = &real_mnt->mnt;
68189 + continue;
68190 + }
68191 +
68192 + spin_lock(&dentry->d_lock);
68193 + read_lock(&gr_inode_lock);
68194 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68195 + __get_dev(dentry), role);
68196 + read_unlock(&gr_inode_lock);
68197 + parent = dentry->d_parent;
68198 + spin_unlock(&dentry->d_lock);
68199 +
68200 + if (retval != NULL)
68201 + goto out;
68202 +
68203 + dentry = parent;
68204 + }
68205 +
68206 + spin_lock(&dentry->d_lock);
68207 + read_lock(&gr_inode_lock);
68208 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68209 + __get_dev(dentry), role);
68210 + read_unlock(&gr_inode_lock);
68211 + spin_unlock(&dentry->d_lock);
68212 +
68213 + if (unlikely(retval == NULL)) {
68214 + /* gr_real_root is pinned, we don't need to hold a reference */
68215 + read_lock(&gr_inode_lock);
68216 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
68217 + __get_dev(gr_real_root.dentry), role);
68218 + read_unlock(&gr_inode_lock);
68219 + }
68220 +out:
68221 + write_sequnlock(&rename_lock);
68222 + read_sequnlock_excl(&mount_lock);
68223 +
68224 + BUG_ON(retval == NULL);
68225 +
68226 + return retval;
68227 +}
68228 +
68229 +void
68230 +assign_special_role(const char *rolename)
68231 +{
68232 + struct acl_object_label *obj;
68233 + struct acl_role_label *r;
68234 + struct acl_role_label *assigned = NULL;
68235 + struct task_struct *tsk;
68236 + struct file *filp;
68237 +
68238 + FOR_EACH_ROLE_START(r)
68239 + if (!strcmp(rolename, r->rolename) &&
68240 + (r->roletype & GR_ROLE_SPECIAL)) {
68241 + assigned = r;
68242 + break;
68243 + }
68244 + FOR_EACH_ROLE_END(r)
68245 +
68246 + if (!assigned)
68247 + return;
68248 +
68249 + read_lock(&tasklist_lock);
68250 + read_lock(&grsec_exec_file_lock);
68251 +
68252 + tsk = current->real_parent;
68253 + if (tsk == NULL)
68254 + goto out_unlock;
68255 +
68256 + filp = tsk->exec_file;
68257 + if (filp == NULL)
68258 + goto out_unlock;
68259 +
68260 + tsk->is_writable = 0;
68261 + tsk->inherited = 0;
68262 +
68263 + tsk->acl_sp_role = 1;
68264 + tsk->acl_role_id = ++acl_sp_role_value;
68265 + tsk->role = assigned;
68266 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68267 +
68268 + /* ignore additional mmap checks for processes that are writable
68269 + by the default ACL */
68270 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68271 + if (unlikely(obj->mode & GR_WRITE))
68272 + tsk->is_writable = 1;
68273 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68274 + if (unlikely(obj->mode & GR_WRITE))
68275 + tsk->is_writable = 1;
68276 +
68277 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68278 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68279 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68280 +#endif
68281 +
68282 +out_unlock:
68283 + read_unlock(&grsec_exec_file_lock);
68284 + read_unlock(&tasklist_lock);
68285 + return;
68286 +}
68287 +
68288 +
68289 +static void
68290 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68291 +{
68292 + struct task_struct *task = current;
68293 + const struct cred *cred = current_cred();
68294 +
68295 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68296 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68297 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68298 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68299 +
68300 + return;
68301 +}
68302 +
68303 +static void
68304 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68305 +{
68306 + struct task_struct *task = current;
68307 + const struct cred *cred = current_cred();
68308 +
68309 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68310 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68311 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68312 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68313 +
68314 + return;
68315 +}
68316 +
68317 +static void
68318 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68319 +{
68320 + struct task_struct *task = current;
68321 + const struct cred *cred = current_cred();
68322 +
68323 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68324 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68325 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68326 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68327 +
68328 + return;
68329 +}
68330 +
68331 +static void
68332 +gr_set_proc_res(struct task_struct *task)
68333 +{
68334 + struct acl_subject_label *proc;
68335 + unsigned short i;
68336 +
68337 + proc = task->acl;
68338 +
68339 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68340 + return;
68341 +
68342 + for (i = 0; i < RLIM_NLIMITS; i++) {
68343 + if (!(proc->resmask & (1U << i)))
68344 + continue;
68345 +
68346 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68347 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68348 +
68349 + if (i == RLIMIT_CPU)
68350 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
68351 + }
68352 +
68353 + return;
68354 +}
68355 +
68356 +/* both of the below must be called with
68357 + rcu_read_lock();
68358 + read_lock(&tasklist_lock);
68359 + read_lock(&grsec_exec_file_lock);
68360 +*/
68361 +
68362 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68363 +{
68364 + char *tmpname;
68365 + struct acl_subject_label *tmpsubj;
68366 + struct file *filp;
68367 + struct name_entry *nmatch;
68368 +
68369 + filp = task->exec_file;
68370 + if (filp == NULL)
68371 + return NULL;
68372 +
68373 + /* the following is to apply the correct subject
68374 + on binaries running when the RBAC system
68375 + is enabled, when the binaries have been
68376 + replaced or deleted since their execution
68377 + -----
68378 + when the RBAC system starts, the inode/dev
68379 + from exec_file will be one the RBAC system
68380 + is unaware of. It only knows the inode/dev
68381 + of the present file on disk, or the absence
68382 + of it.
68383 + */
68384 +
68385 + if (filename)
68386 + nmatch = __lookup_name_entry(state, filename);
68387 + else {
68388 + preempt_disable();
68389 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68390 +
68391 + nmatch = __lookup_name_entry(state, tmpname);
68392 + preempt_enable();
68393 + }
68394 + tmpsubj = NULL;
68395 + if (nmatch) {
68396 + if (nmatch->deleted)
68397 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68398 + else
68399 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68400 + }
68401 + /* this also works for the reload case -- if we don't match a potentially inherited subject
68402 + then we fall back to a normal lookup based on the binary's ino/dev
68403 + */
68404 + if (tmpsubj == NULL)
68405 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68406 +
68407 + return tmpsubj;
68408 +}
68409 +
68410 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68411 +{
68412 + return __gr_get_subject_for_task(&running_polstate, task, filename);
68413 +}
68414 +
68415 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68416 +{
68417 + struct acl_object_label *obj;
68418 + struct file *filp;
68419 +
68420 + filp = task->exec_file;
68421 +
68422 + task->acl = subj;
68423 + task->is_writable = 0;
68424 + /* ignore additional mmap checks for processes that are writable
68425 + by the default ACL */
68426 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68427 + if (unlikely(obj->mode & GR_WRITE))
68428 + task->is_writable = 1;
68429 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68430 + if (unlikely(obj->mode & GR_WRITE))
68431 + task->is_writable = 1;
68432 +
68433 + gr_set_proc_res(task);
68434 +
68435 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68436 + 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);
68437 +#endif
68438 +}
68439 +
68440 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68441 +{
68442 + __gr_apply_subject_to_task(&running_polstate, task, subj);
68443 +}
68444 +
68445 +__u32
68446 +gr_search_file(const struct dentry * dentry, const __u32 mode,
68447 + const struct vfsmount * mnt)
68448 +{
68449 + __u32 retval = mode;
68450 + struct acl_subject_label *curracl;
68451 + struct acl_object_label *currobj;
68452 +
68453 + if (unlikely(!(gr_status & GR_READY)))
68454 + return (mode & ~GR_AUDITS);
68455 +
68456 + curracl = current->acl;
68457 +
68458 + currobj = chk_obj_label(dentry, mnt, curracl);
68459 + retval = currobj->mode & mode;
68460 +
68461 + /* if we're opening a specified transfer file for writing
68462 + (e.g. /dev/initctl), then transfer our role to init
68463 + */
68464 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68465 + current->role->roletype & GR_ROLE_PERSIST)) {
68466 + struct task_struct *task = init_pid_ns.child_reaper;
68467 +
68468 + if (task->role != current->role) {
68469 + struct acl_subject_label *subj;
68470 +
68471 + task->acl_sp_role = 0;
68472 + task->acl_role_id = current->acl_role_id;
68473 + task->role = current->role;
68474 + rcu_read_lock();
68475 + read_lock(&grsec_exec_file_lock);
68476 + subj = gr_get_subject_for_task(task, NULL);
68477 + gr_apply_subject_to_task(task, subj);
68478 + read_unlock(&grsec_exec_file_lock);
68479 + rcu_read_unlock();
68480 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68481 + }
68482 + }
68483 +
68484 + if (unlikely
68485 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68486 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68487 + __u32 new_mode = mode;
68488 +
68489 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68490 +
68491 + retval = new_mode;
68492 +
68493 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68494 + new_mode |= GR_INHERIT;
68495 +
68496 + if (!(mode & GR_NOLEARN))
68497 + gr_log_learn(dentry, mnt, new_mode);
68498 + }
68499 +
68500 + return retval;
68501 +}
68502 +
68503 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68504 + const struct dentry *parent,
68505 + const struct vfsmount *mnt)
68506 +{
68507 + struct name_entry *match;
68508 + struct acl_object_label *matchpo;
68509 + struct acl_subject_label *curracl;
68510 + char *path;
68511 +
68512 + if (unlikely(!(gr_status & GR_READY)))
68513 + return NULL;
68514 +
68515 + preempt_disable();
68516 + path = gr_to_filename_rbac(new_dentry, mnt);
68517 + match = lookup_name_entry_create(path);
68518 +
68519 + curracl = current->acl;
68520 +
68521 + if (match) {
68522 + read_lock(&gr_inode_lock);
68523 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68524 + read_unlock(&gr_inode_lock);
68525 +
68526 + if (matchpo) {
68527 + preempt_enable();
68528 + return matchpo;
68529 + }
68530 + }
68531 +
68532 + // lookup parent
68533 +
68534 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68535 +
68536 + preempt_enable();
68537 + return matchpo;
68538 +}
68539 +
68540 +__u32
68541 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68542 + const struct vfsmount * mnt, const __u32 mode)
68543 +{
68544 + struct acl_object_label *matchpo;
68545 + __u32 retval;
68546 +
68547 + if (unlikely(!(gr_status & GR_READY)))
68548 + return (mode & ~GR_AUDITS);
68549 +
68550 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
68551 +
68552 + retval = matchpo->mode & mode;
68553 +
68554 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68555 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68556 + __u32 new_mode = mode;
68557 +
68558 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68559 +
68560 + gr_log_learn(new_dentry, mnt, new_mode);
68561 + return new_mode;
68562 + }
68563 +
68564 + return retval;
68565 +}
68566 +
68567 +__u32
68568 +gr_check_link(const struct dentry * new_dentry,
68569 + const struct dentry * parent_dentry,
68570 + const struct vfsmount * parent_mnt,
68571 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68572 +{
68573 + struct acl_object_label *obj;
68574 + __u32 oldmode, newmode;
68575 + __u32 needmode;
68576 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68577 + GR_DELETE | GR_INHERIT;
68578 +
68579 + if (unlikely(!(gr_status & GR_READY)))
68580 + return (GR_CREATE | GR_LINK);
68581 +
68582 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68583 + oldmode = obj->mode;
68584 +
68585 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68586 + newmode = obj->mode;
68587 +
68588 + needmode = newmode & checkmodes;
68589 +
68590 + // old name for hardlink must have at least the permissions of the new name
68591 + if ((oldmode & needmode) != needmode)
68592 + goto bad;
68593 +
68594 + // if old name had restrictions/auditing, make sure the new name does as well
68595 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68596 +
68597 + // don't allow hardlinking of suid/sgid/fcapped files without permission
68598 + if (is_privileged_binary(old_dentry))
68599 + needmode |= GR_SETID;
68600 +
68601 + if ((newmode & needmode) != needmode)
68602 + goto bad;
68603 +
68604 + // enforce minimum permissions
68605 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68606 + return newmode;
68607 +bad:
68608 + needmode = oldmode;
68609 + if (is_privileged_binary(old_dentry))
68610 + needmode |= GR_SETID;
68611 +
68612 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68613 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68614 + return (GR_CREATE | GR_LINK);
68615 + } else if (newmode & GR_SUPPRESS)
68616 + return GR_SUPPRESS;
68617 + else
68618 + return 0;
68619 +}
68620 +
68621 +int
68622 +gr_check_hidden_task(const struct task_struct *task)
68623 +{
68624 + if (unlikely(!(gr_status & GR_READY)))
68625 + return 0;
68626 +
68627 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68628 + return 1;
68629 +
68630 + return 0;
68631 +}
68632 +
68633 +int
68634 +gr_check_protected_task(const struct task_struct *task)
68635 +{
68636 + if (unlikely(!(gr_status & GR_READY) || !task))
68637 + return 0;
68638 +
68639 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68640 + task->acl != current->acl)
68641 + return 1;
68642 +
68643 + return 0;
68644 +}
68645 +
68646 +int
68647 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68648 +{
68649 + struct task_struct *p;
68650 + int ret = 0;
68651 +
68652 + if (unlikely(!(gr_status & GR_READY) || !pid))
68653 + return ret;
68654 +
68655 + read_lock(&tasklist_lock);
68656 + do_each_pid_task(pid, type, p) {
68657 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68658 + p->acl != current->acl) {
68659 + ret = 1;
68660 + goto out;
68661 + }
68662 + } while_each_pid_task(pid, type, p);
68663 +out:
68664 + read_unlock(&tasklist_lock);
68665 +
68666 + return ret;
68667 +}
68668 +
68669 +void
68670 +gr_copy_label(struct task_struct *tsk)
68671 +{
68672 + struct task_struct *p = current;
68673 +
68674 + tsk->inherited = p->inherited;
68675 + tsk->acl_sp_role = 0;
68676 + tsk->acl_role_id = p->acl_role_id;
68677 + tsk->acl = p->acl;
68678 + tsk->role = p->role;
68679 + tsk->signal->used_accept = 0;
68680 + tsk->signal->curr_ip = p->signal->curr_ip;
68681 + tsk->signal->saved_ip = p->signal->saved_ip;
68682 + if (p->exec_file)
68683 + get_file(p->exec_file);
68684 + tsk->exec_file = p->exec_file;
68685 + tsk->is_writable = p->is_writable;
68686 + if (unlikely(p->signal->used_accept)) {
68687 + p->signal->curr_ip = 0;
68688 + p->signal->saved_ip = 0;
68689 + }
68690 +
68691 + return;
68692 +}
68693 +
68694 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68695 +
68696 +int
68697 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68698 +{
68699 + unsigned int i;
68700 + __u16 num;
68701 + uid_t *uidlist;
68702 + uid_t curuid;
68703 + int realok = 0;
68704 + int effectiveok = 0;
68705 + int fsok = 0;
68706 + uid_t globalreal, globaleffective, globalfs;
68707 +
68708 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68709 + struct user_struct *user;
68710 +
68711 + if (!uid_valid(real))
68712 + goto skipit;
68713 +
68714 + /* find user based on global namespace */
68715 +
68716 + globalreal = GR_GLOBAL_UID(real);
68717 +
68718 + user = find_user(make_kuid(&init_user_ns, globalreal));
68719 + if (user == NULL)
68720 + goto skipit;
68721 +
68722 + if (gr_process_kernel_setuid_ban(user)) {
68723 + /* for find_user */
68724 + free_uid(user);
68725 + return 1;
68726 + }
68727 +
68728 + /* for find_user */
68729 + free_uid(user);
68730 +
68731 +skipit:
68732 +#endif
68733 +
68734 + if (unlikely(!(gr_status & GR_READY)))
68735 + return 0;
68736 +
68737 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68738 + gr_log_learn_uid_change(real, effective, fs);
68739 +
68740 + num = current->acl->user_trans_num;
68741 + uidlist = current->acl->user_transitions;
68742 +
68743 + if (uidlist == NULL)
68744 + return 0;
68745 +
68746 + if (!uid_valid(real)) {
68747 + realok = 1;
68748 + globalreal = (uid_t)-1;
68749 + } else {
68750 + globalreal = GR_GLOBAL_UID(real);
68751 + }
68752 + if (!uid_valid(effective)) {
68753 + effectiveok = 1;
68754 + globaleffective = (uid_t)-1;
68755 + } else {
68756 + globaleffective = GR_GLOBAL_UID(effective);
68757 + }
68758 + if (!uid_valid(fs)) {
68759 + fsok = 1;
68760 + globalfs = (uid_t)-1;
68761 + } else {
68762 + globalfs = GR_GLOBAL_UID(fs);
68763 + }
68764 +
68765 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
68766 + for (i = 0; i < num; i++) {
68767 + curuid = uidlist[i];
68768 + if (globalreal == curuid)
68769 + realok = 1;
68770 + if (globaleffective == curuid)
68771 + effectiveok = 1;
68772 + if (globalfs == curuid)
68773 + fsok = 1;
68774 + }
68775 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
68776 + for (i = 0; i < num; i++) {
68777 + curuid = uidlist[i];
68778 + if (globalreal == curuid)
68779 + break;
68780 + if (globaleffective == curuid)
68781 + break;
68782 + if (globalfs == curuid)
68783 + break;
68784 + }
68785 + /* not in deny list */
68786 + if (i == num) {
68787 + realok = 1;
68788 + effectiveok = 1;
68789 + fsok = 1;
68790 + }
68791 + }
68792 +
68793 + if (realok && effectiveok && fsok)
68794 + return 0;
68795 + else {
68796 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68797 + return 1;
68798 + }
68799 +}
68800 +
68801 +int
68802 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68803 +{
68804 + unsigned int i;
68805 + __u16 num;
68806 + gid_t *gidlist;
68807 + gid_t curgid;
68808 + int realok = 0;
68809 + int effectiveok = 0;
68810 + int fsok = 0;
68811 + gid_t globalreal, globaleffective, globalfs;
68812 +
68813 + if (unlikely(!(gr_status & GR_READY)))
68814 + return 0;
68815 +
68816 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68817 + gr_log_learn_gid_change(real, effective, fs);
68818 +
68819 + num = current->acl->group_trans_num;
68820 + gidlist = current->acl->group_transitions;
68821 +
68822 + if (gidlist == NULL)
68823 + return 0;
68824 +
68825 + if (!gid_valid(real)) {
68826 + realok = 1;
68827 + globalreal = (gid_t)-1;
68828 + } else {
68829 + globalreal = GR_GLOBAL_GID(real);
68830 + }
68831 + if (!gid_valid(effective)) {
68832 + effectiveok = 1;
68833 + globaleffective = (gid_t)-1;
68834 + } else {
68835 + globaleffective = GR_GLOBAL_GID(effective);
68836 + }
68837 + if (!gid_valid(fs)) {
68838 + fsok = 1;
68839 + globalfs = (gid_t)-1;
68840 + } else {
68841 + globalfs = GR_GLOBAL_GID(fs);
68842 + }
68843 +
68844 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
68845 + for (i = 0; i < num; i++) {
68846 + curgid = gidlist[i];
68847 + if (globalreal == curgid)
68848 + realok = 1;
68849 + if (globaleffective == curgid)
68850 + effectiveok = 1;
68851 + if (globalfs == curgid)
68852 + fsok = 1;
68853 + }
68854 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
68855 + for (i = 0; i < num; i++) {
68856 + curgid = gidlist[i];
68857 + if (globalreal == curgid)
68858 + break;
68859 + if (globaleffective == curgid)
68860 + break;
68861 + if (globalfs == curgid)
68862 + break;
68863 + }
68864 + /* not in deny list */
68865 + if (i == num) {
68866 + realok = 1;
68867 + effectiveok = 1;
68868 + fsok = 1;
68869 + }
68870 + }
68871 +
68872 + if (realok && effectiveok && fsok)
68873 + return 0;
68874 + else {
68875 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68876 + return 1;
68877 + }
68878 +}
68879 +
68880 +extern int gr_acl_is_capable(const int cap);
68881 +
68882 +void
68883 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68884 +{
68885 + struct acl_role_label *role = task->role;
68886 + struct acl_subject_label *subj = NULL;
68887 + struct acl_object_label *obj;
68888 + struct file *filp;
68889 + uid_t uid;
68890 + gid_t gid;
68891 +
68892 + if (unlikely(!(gr_status & GR_READY)))
68893 + return;
68894 +
68895 + uid = GR_GLOBAL_UID(kuid);
68896 + gid = GR_GLOBAL_GID(kgid);
68897 +
68898 + filp = task->exec_file;
68899 +
68900 + /* kernel process, we'll give them the kernel role */
68901 + if (unlikely(!filp)) {
68902 + task->role = running_polstate.kernel_role;
68903 + task->acl = running_polstate.kernel_role->root_label;
68904 + return;
68905 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68906 + /* save the current ip at time of role lookup so that the proper
68907 + IP will be learned for role_allowed_ip */
68908 + task->signal->saved_ip = task->signal->curr_ip;
68909 + role = lookup_acl_role_label(task, uid, gid);
68910 + }
68911 +
68912 + /* don't change the role if we're not a privileged process */
68913 + if (role && task->role != role &&
68914 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68915 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68916 + return;
68917 +
68918 + /* perform subject lookup in possibly new role
68919 + we can use this result below in the case where role == task->role
68920 + */
68921 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68922 +
68923 + /* if we changed uid/gid, but result in the same role
68924 + and are using inheritance, don't lose the inherited subject
68925 + if current subject is other than what normal lookup
68926 + would result in, we arrived via inheritance, don't
68927 + lose subject
68928 + */
68929 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68930 + (subj == task->acl)))
68931 + task->acl = subj;
68932 +
68933 + /* leave task->inherited unaffected */
68934 +
68935 + task->role = role;
68936 +
68937 + task->is_writable = 0;
68938 +
68939 + /* ignore additional mmap checks for processes that are writable
68940 + by the default ACL */
68941 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68942 + if (unlikely(obj->mode & GR_WRITE))
68943 + task->is_writable = 1;
68944 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68945 + if (unlikely(obj->mode & GR_WRITE))
68946 + task->is_writable = 1;
68947 +
68948 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68949 + 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);
68950 +#endif
68951 +
68952 + gr_set_proc_res(task);
68953 +
68954 + return;
68955 +}
68956 +
68957 +int
68958 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68959 + const int unsafe_flags)
68960 +{
68961 + struct task_struct *task = current;
68962 + struct acl_subject_label *newacl;
68963 + struct acl_object_label *obj;
68964 + __u32 retmode;
68965 +
68966 + if (unlikely(!(gr_status & GR_READY)))
68967 + return 0;
68968 +
68969 + newacl = chk_subj_label(dentry, mnt, task->role);
68970 +
68971 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68972 + did an exec
68973 + */
68974 + rcu_read_lock();
68975 + read_lock(&tasklist_lock);
68976 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68977 + (task->parent->acl->mode & GR_POVERRIDE))) {
68978 + read_unlock(&tasklist_lock);
68979 + rcu_read_unlock();
68980 + goto skip_check;
68981 + }
68982 + read_unlock(&tasklist_lock);
68983 + rcu_read_unlock();
68984 +
68985 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68986 + !(task->role->roletype & GR_ROLE_GOD) &&
68987 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68988 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68989 + if (unsafe_flags & LSM_UNSAFE_SHARE)
68990 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68991 + else
68992 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68993 + return -EACCES;
68994 + }
68995 +
68996 +skip_check:
68997 +
68998 + obj = chk_obj_label(dentry, mnt, task->acl);
68999 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
69000 +
69001 + if (!(task->acl->mode & GR_INHERITLEARN) &&
69002 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
69003 + if (obj->nested)
69004 + task->acl = obj->nested;
69005 + else
69006 + task->acl = newacl;
69007 + task->inherited = 0;
69008 + } else {
69009 + task->inherited = 1;
69010 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
69011 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
69012 + }
69013 +
69014 + task->is_writable = 0;
69015 +
69016 + /* ignore additional mmap checks for processes that are writable
69017 + by the default ACL */
69018 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
69019 + if (unlikely(obj->mode & GR_WRITE))
69020 + task->is_writable = 1;
69021 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
69022 + if (unlikely(obj->mode & GR_WRITE))
69023 + task->is_writable = 1;
69024 +
69025 + gr_set_proc_res(task);
69026 +
69027 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
69028 + 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);
69029 +#endif
69030 + return 0;
69031 +}
69032 +
69033 +/* always called with valid inodev ptr */
69034 +static void
69035 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
69036 +{
69037 + struct acl_object_label *matchpo;
69038 + struct acl_subject_label *matchps;
69039 + struct acl_subject_label *subj;
69040 + struct acl_role_label *role;
69041 + unsigned int x;
69042 +
69043 + FOR_EACH_ROLE_START(role)
69044 + FOR_EACH_SUBJECT_START(role, subj, x)
69045 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69046 + matchpo->mode |= GR_DELETED;
69047 + FOR_EACH_SUBJECT_END(subj,x)
69048 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
69049 + /* nested subjects aren't in the role's subj_hash table */
69050 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
69051 + matchpo->mode |= GR_DELETED;
69052 + FOR_EACH_NESTED_SUBJECT_END(subj)
69053 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
69054 + matchps->mode |= GR_DELETED;
69055 + FOR_EACH_ROLE_END(role)
69056 +
69057 + inodev->nentry->deleted = 1;
69058 +
69059 + return;
69060 +}
69061 +
69062 +void
69063 +gr_handle_delete(const ino_t ino, const dev_t dev)
69064 +{
69065 + struct inodev_entry *inodev;
69066 +
69067 + if (unlikely(!(gr_status & GR_READY)))
69068 + return;
69069 +
69070 + write_lock(&gr_inode_lock);
69071 + inodev = lookup_inodev_entry(ino, dev);
69072 + if (inodev != NULL)
69073 + do_handle_delete(inodev, ino, dev);
69074 + write_unlock(&gr_inode_lock);
69075 +
69076 + return;
69077 +}
69078 +
69079 +static void
69080 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
69081 + const ino_t newinode, const dev_t newdevice,
69082 + struct acl_subject_label *subj)
69083 +{
69084 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
69085 + struct acl_object_label *match;
69086 +
69087 + match = subj->obj_hash[index];
69088 +
69089 + while (match && (match->inode != oldinode ||
69090 + match->device != olddevice ||
69091 + !(match->mode & GR_DELETED)))
69092 + match = match->next;
69093 +
69094 + if (match && (match->inode == oldinode)
69095 + && (match->device == olddevice)
69096 + && (match->mode & GR_DELETED)) {
69097 + if (match->prev == NULL) {
69098 + subj->obj_hash[index] = match->next;
69099 + if (match->next != NULL)
69100 + match->next->prev = NULL;
69101 + } else {
69102 + match->prev->next = match->next;
69103 + if (match->next != NULL)
69104 + match->next->prev = match->prev;
69105 + }
69106 + match->prev = NULL;
69107 + match->next = NULL;
69108 + match->inode = newinode;
69109 + match->device = newdevice;
69110 + match->mode &= ~GR_DELETED;
69111 +
69112 + insert_acl_obj_label(match, subj);
69113 + }
69114 +
69115 + return;
69116 +}
69117 +
69118 +static void
69119 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
69120 + const ino_t newinode, const dev_t newdevice,
69121 + struct acl_role_label *role)
69122 +{
69123 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
69124 + struct acl_subject_label *match;
69125 +
69126 + match = role->subj_hash[index];
69127 +
69128 + while (match && (match->inode != oldinode ||
69129 + match->device != olddevice ||
69130 + !(match->mode & GR_DELETED)))
69131 + match = match->next;
69132 +
69133 + if (match && (match->inode == oldinode)
69134 + && (match->device == olddevice)
69135 + && (match->mode & GR_DELETED)) {
69136 + if (match->prev == NULL) {
69137 + role->subj_hash[index] = match->next;
69138 + if (match->next != NULL)
69139 + match->next->prev = NULL;
69140 + } else {
69141 + match->prev->next = match->next;
69142 + if (match->next != NULL)
69143 + match->next->prev = match->prev;
69144 + }
69145 + match->prev = NULL;
69146 + match->next = NULL;
69147 + match->inode = newinode;
69148 + match->device = newdevice;
69149 + match->mode &= ~GR_DELETED;
69150 +
69151 + insert_acl_subj_label(match, role);
69152 + }
69153 +
69154 + return;
69155 +}
69156 +
69157 +static void
69158 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
69159 + const ino_t newinode, const dev_t newdevice)
69160 +{
69161 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
69162 + struct inodev_entry *match;
69163 +
69164 + match = running_polstate.inodev_set.i_hash[index];
69165 +
69166 + while (match && (match->nentry->inode != oldinode ||
69167 + match->nentry->device != olddevice || !match->nentry->deleted))
69168 + match = match->next;
69169 +
69170 + if (match && (match->nentry->inode == oldinode)
69171 + && (match->nentry->device == olddevice) &&
69172 + match->nentry->deleted) {
69173 + if (match->prev == NULL) {
69174 + running_polstate.inodev_set.i_hash[index] = match->next;
69175 + if (match->next != NULL)
69176 + match->next->prev = NULL;
69177 + } else {
69178 + match->prev->next = match->next;
69179 + if (match->next != NULL)
69180 + match->next->prev = match->prev;
69181 + }
69182 + match->prev = NULL;
69183 + match->next = NULL;
69184 + match->nentry->inode = newinode;
69185 + match->nentry->device = newdevice;
69186 + match->nentry->deleted = 0;
69187 +
69188 + insert_inodev_entry(match);
69189 + }
69190 +
69191 + return;
69192 +}
69193 +
69194 +static void
69195 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
69196 +{
69197 + struct acl_subject_label *subj;
69198 + struct acl_role_label *role;
69199 + unsigned int x;
69200 +
69201 + FOR_EACH_ROLE_START(role)
69202 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
69203 +
69204 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
69205 + if ((subj->inode == ino) && (subj->device == dev)) {
69206 + subj->inode = ino;
69207 + subj->device = dev;
69208 + }
69209 + /* nested subjects aren't in the role's subj_hash table */
69210 + update_acl_obj_label(matchn->inode, matchn->device,
69211 + ino, dev, subj);
69212 + FOR_EACH_NESTED_SUBJECT_END(subj)
69213 + FOR_EACH_SUBJECT_START(role, subj, x)
69214 + update_acl_obj_label(matchn->inode, matchn->device,
69215 + ino, dev, subj);
69216 + FOR_EACH_SUBJECT_END(subj,x)
69217 + FOR_EACH_ROLE_END(role)
69218 +
69219 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
69220 +
69221 + return;
69222 +}
69223 +
69224 +static void
69225 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69226 + const struct vfsmount *mnt)
69227 +{
69228 + ino_t ino = dentry->d_inode->i_ino;
69229 + dev_t dev = __get_dev(dentry);
69230 +
69231 + __do_handle_create(matchn, ino, dev);
69232 +
69233 + return;
69234 +}
69235 +
69236 +void
69237 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69238 +{
69239 + struct name_entry *matchn;
69240 +
69241 + if (unlikely(!(gr_status & GR_READY)))
69242 + return;
69243 +
69244 + preempt_disable();
69245 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69246 +
69247 + if (unlikely((unsigned long)matchn)) {
69248 + write_lock(&gr_inode_lock);
69249 + do_handle_create(matchn, dentry, mnt);
69250 + write_unlock(&gr_inode_lock);
69251 + }
69252 + preempt_enable();
69253 +
69254 + return;
69255 +}
69256 +
69257 +void
69258 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69259 +{
69260 + struct name_entry *matchn;
69261 +
69262 + if (unlikely(!(gr_status & GR_READY)))
69263 + return;
69264 +
69265 + preempt_disable();
69266 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69267 +
69268 + if (unlikely((unsigned long)matchn)) {
69269 + write_lock(&gr_inode_lock);
69270 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69271 + write_unlock(&gr_inode_lock);
69272 + }
69273 + preempt_enable();
69274 +
69275 + return;
69276 +}
69277 +
69278 +void
69279 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69280 + struct dentry *old_dentry,
69281 + struct dentry *new_dentry,
69282 + struct vfsmount *mnt, const __u8 replace)
69283 +{
69284 + struct name_entry *matchn;
69285 + struct inodev_entry *inodev;
69286 + struct inode *inode = new_dentry->d_inode;
69287 + ino_t old_ino = old_dentry->d_inode->i_ino;
69288 + dev_t old_dev = __get_dev(old_dentry);
69289 +
69290 + /* vfs_rename swaps the name and parent link for old_dentry and
69291 + new_dentry
69292 + at this point, old_dentry has the new name, parent link, and inode
69293 + for the renamed file
69294 + if a file is being replaced by a rename, new_dentry has the inode
69295 + and name for the replaced file
69296 + */
69297 +
69298 + if (unlikely(!(gr_status & GR_READY)))
69299 + return;
69300 +
69301 + preempt_disable();
69302 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69303 +
69304 + /* we wouldn't have to check d_inode if it weren't for
69305 + NFS silly-renaming
69306 + */
69307 +
69308 + write_lock(&gr_inode_lock);
69309 + if (unlikely(replace && inode)) {
69310 + ino_t new_ino = inode->i_ino;
69311 + dev_t new_dev = __get_dev(new_dentry);
69312 +
69313 + inodev = lookup_inodev_entry(new_ino, new_dev);
69314 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69315 + do_handle_delete(inodev, new_ino, new_dev);
69316 + }
69317 +
69318 + inodev = lookup_inodev_entry(old_ino, old_dev);
69319 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69320 + do_handle_delete(inodev, old_ino, old_dev);
69321 +
69322 + if (unlikely((unsigned long)matchn))
69323 + do_handle_create(matchn, old_dentry, mnt);
69324 +
69325 + write_unlock(&gr_inode_lock);
69326 + preempt_enable();
69327 +
69328 + return;
69329 +}
69330 +
69331 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69332 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69333 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69334 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69335 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69336 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69337 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69338 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69339 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69340 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69341 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69342 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69343 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69344 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69345 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69346 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69347 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69348 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69349 +};
69350 +
69351 +void
69352 +gr_learn_resource(const struct task_struct *task,
69353 + const int res, const unsigned long wanted, const int gt)
69354 +{
69355 + struct acl_subject_label *acl;
69356 + const struct cred *cred;
69357 +
69358 + if (unlikely((gr_status & GR_READY) &&
69359 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69360 + goto skip_reslog;
69361 +
69362 + gr_log_resource(task, res, wanted, gt);
69363 +skip_reslog:
69364 +
69365 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69366 + return;
69367 +
69368 + acl = task->acl;
69369 +
69370 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69371 + !(acl->resmask & (1U << (unsigned short) res))))
69372 + return;
69373 +
69374 + if (wanted >= acl->res[res].rlim_cur) {
69375 + unsigned long res_add;
69376 +
69377 + res_add = wanted + res_learn_bumps[res];
69378 +
69379 + acl->res[res].rlim_cur = res_add;
69380 +
69381 + if (wanted > acl->res[res].rlim_max)
69382 + acl->res[res].rlim_max = res_add;
69383 +
69384 + /* only log the subject filename, since resource logging is supported for
69385 + single-subject learning only */
69386 + rcu_read_lock();
69387 + cred = __task_cred(task);
69388 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69389 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69390 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69391 + "", (unsigned long) res, &task->signal->saved_ip);
69392 + rcu_read_unlock();
69393 + }
69394 +
69395 + return;
69396 +}
69397 +EXPORT_SYMBOL_GPL(gr_learn_resource);
69398 +#endif
69399 +
69400 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69401 +void
69402 +pax_set_initial_flags(struct linux_binprm *bprm)
69403 +{
69404 + struct task_struct *task = current;
69405 + struct acl_subject_label *proc;
69406 + unsigned long flags;
69407 +
69408 + if (unlikely(!(gr_status & GR_READY)))
69409 + return;
69410 +
69411 + flags = pax_get_flags(task);
69412 +
69413 + proc = task->acl;
69414 +
69415 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69416 + flags &= ~MF_PAX_PAGEEXEC;
69417 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69418 + flags &= ~MF_PAX_SEGMEXEC;
69419 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69420 + flags &= ~MF_PAX_RANDMMAP;
69421 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69422 + flags &= ~MF_PAX_EMUTRAMP;
69423 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69424 + flags &= ~MF_PAX_MPROTECT;
69425 +
69426 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69427 + flags |= MF_PAX_PAGEEXEC;
69428 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69429 + flags |= MF_PAX_SEGMEXEC;
69430 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69431 + flags |= MF_PAX_RANDMMAP;
69432 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69433 + flags |= MF_PAX_EMUTRAMP;
69434 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69435 + flags |= MF_PAX_MPROTECT;
69436 +
69437 + pax_set_flags(task, flags);
69438 +
69439 + return;
69440 +}
69441 +#endif
69442 +
69443 +int
69444 +gr_handle_proc_ptrace(struct task_struct *task)
69445 +{
69446 + struct file *filp;
69447 + struct task_struct *tmp = task;
69448 + struct task_struct *curtemp = current;
69449 + __u32 retmode;
69450 +
69451 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69452 + if (unlikely(!(gr_status & GR_READY)))
69453 + return 0;
69454 +#endif
69455 +
69456 + read_lock(&tasklist_lock);
69457 + read_lock(&grsec_exec_file_lock);
69458 + filp = task->exec_file;
69459 +
69460 + while (task_pid_nr(tmp) > 0) {
69461 + if (tmp == curtemp)
69462 + break;
69463 + tmp = tmp->real_parent;
69464 + }
69465 +
69466 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69467 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69468 + read_unlock(&grsec_exec_file_lock);
69469 + read_unlock(&tasklist_lock);
69470 + return 1;
69471 + }
69472 +
69473 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69474 + if (!(gr_status & GR_READY)) {
69475 + read_unlock(&grsec_exec_file_lock);
69476 + read_unlock(&tasklist_lock);
69477 + return 0;
69478 + }
69479 +#endif
69480 +
69481 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69482 + read_unlock(&grsec_exec_file_lock);
69483 + read_unlock(&tasklist_lock);
69484 +
69485 + if (retmode & GR_NOPTRACE)
69486 + return 1;
69487 +
69488 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69489 + && (current->acl != task->acl || (current->acl != current->role->root_label
69490 + && task_pid_nr(current) != task_pid_nr(task))))
69491 + return 1;
69492 +
69493 + return 0;
69494 +}
69495 +
69496 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69497 +{
69498 + if (unlikely(!(gr_status & GR_READY)))
69499 + return;
69500 +
69501 + if (!(current->role->roletype & GR_ROLE_GOD))
69502 + return;
69503 +
69504 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69505 + p->role->rolename, gr_task_roletype_to_char(p),
69506 + p->acl->filename);
69507 +}
69508 +
69509 +int
69510 +gr_handle_ptrace(struct task_struct *task, const long request)
69511 +{
69512 + struct task_struct *tmp = task;
69513 + struct task_struct *curtemp = current;
69514 + __u32 retmode;
69515 +
69516 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69517 + if (unlikely(!(gr_status & GR_READY)))
69518 + return 0;
69519 +#endif
69520 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69521 + read_lock(&tasklist_lock);
69522 + while (task_pid_nr(tmp) > 0) {
69523 + if (tmp == curtemp)
69524 + break;
69525 + tmp = tmp->real_parent;
69526 + }
69527 +
69528 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69529 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69530 + read_unlock(&tasklist_lock);
69531 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69532 + return 1;
69533 + }
69534 + read_unlock(&tasklist_lock);
69535 + }
69536 +
69537 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69538 + if (!(gr_status & GR_READY))
69539 + return 0;
69540 +#endif
69541 +
69542 + read_lock(&grsec_exec_file_lock);
69543 + if (unlikely(!task->exec_file)) {
69544 + read_unlock(&grsec_exec_file_lock);
69545 + return 0;
69546 + }
69547 +
69548 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69549 + read_unlock(&grsec_exec_file_lock);
69550 +
69551 + if (retmode & GR_NOPTRACE) {
69552 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69553 + return 1;
69554 + }
69555 +
69556 + if (retmode & GR_PTRACERD) {
69557 + switch (request) {
69558 + case PTRACE_SEIZE:
69559 + case PTRACE_POKETEXT:
69560 + case PTRACE_POKEDATA:
69561 + case PTRACE_POKEUSR:
69562 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69563 + case PTRACE_SETREGS:
69564 + case PTRACE_SETFPREGS:
69565 +#endif
69566 +#ifdef CONFIG_X86
69567 + case PTRACE_SETFPXREGS:
69568 +#endif
69569 +#ifdef CONFIG_ALTIVEC
69570 + case PTRACE_SETVRREGS:
69571 +#endif
69572 + return 1;
69573 + default:
69574 + return 0;
69575 + }
69576 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
69577 + !(current->role->roletype & GR_ROLE_GOD) &&
69578 + (current->acl != task->acl)) {
69579 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69580 + return 1;
69581 + }
69582 +
69583 + return 0;
69584 +}
69585 +
69586 +static int is_writable_mmap(const struct file *filp)
69587 +{
69588 + struct task_struct *task = current;
69589 + struct acl_object_label *obj, *obj2;
69590 +
69591 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69592 + !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))) {
69593 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69594 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69595 + task->role->root_label);
69596 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69597 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69598 + return 1;
69599 + }
69600 + }
69601 + return 0;
69602 +}
69603 +
69604 +int
69605 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69606 +{
69607 + __u32 mode;
69608 +
69609 + if (unlikely(!file || !(prot & PROT_EXEC)))
69610 + return 1;
69611 +
69612 + if (is_writable_mmap(file))
69613 + return 0;
69614 +
69615 + mode =
69616 + gr_search_file(file->f_path.dentry,
69617 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69618 + file->f_path.mnt);
69619 +
69620 + if (!gr_tpe_allow(file))
69621 + return 0;
69622 +
69623 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69624 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69625 + return 0;
69626 + } else if (unlikely(!(mode & GR_EXEC))) {
69627 + return 0;
69628 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69629 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69630 + return 1;
69631 + }
69632 +
69633 + return 1;
69634 +}
69635 +
69636 +int
69637 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69638 +{
69639 + __u32 mode;
69640 +
69641 + if (unlikely(!file || !(prot & PROT_EXEC)))
69642 + return 1;
69643 +
69644 + if (is_writable_mmap(file))
69645 + return 0;
69646 +
69647 + mode =
69648 + gr_search_file(file->f_path.dentry,
69649 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69650 + file->f_path.mnt);
69651 +
69652 + if (!gr_tpe_allow(file))
69653 + return 0;
69654 +
69655 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69656 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69657 + return 0;
69658 + } else if (unlikely(!(mode & GR_EXEC))) {
69659 + return 0;
69660 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69661 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69662 + return 1;
69663 + }
69664 +
69665 + return 1;
69666 +}
69667 +
69668 +void
69669 +gr_acl_handle_psacct(struct task_struct *task, const long code)
69670 +{
69671 + unsigned long runtime, cputime;
69672 + cputime_t utime, stime;
69673 + unsigned int wday, cday;
69674 + __u8 whr, chr;
69675 + __u8 wmin, cmin;
69676 + __u8 wsec, csec;
69677 + struct timespec timeval;
69678 +
69679 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69680 + !(task->acl->mode & GR_PROCACCT)))
69681 + return;
69682 +
69683 + do_posix_clock_monotonic_gettime(&timeval);
69684 + runtime = timeval.tv_sec - task->start_time.tv_sec;
69685 + wday = runtime / (60 * 60 * 24);
69686 + runtime -= wday * (60 * 60 * 24);
69687 + whr = runtime / (60 * 60);
69688 + runtime -= whr * (60 * 60);
69689 + wmin = runtime / 60;
69690 + runtime -= wmin * 60;
69691 + wsec = runtime;
69692 +
69693 + task_cputime(task, &utime, &stime);
69694 + cputime = cputime_to_secs(utime + stime);
69695 + cday = cputime / (60 * 60 * 24);
69696 + cputime -= cday * (60 * 60 * 24);
69697 + chr = cputime / (60 * 60);
69698 + cputime -= chr * (60 * 60);
69699 + cmin = cputime / 60;
69700 + cputime -= cmin * 60;
69701 + csec = cputime;
69702 +
69703 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69704 +
69705 + return;
69706 +}
69707 +
69708 +#ifdef CONFIG_TASKSTATS
69709 +int gr_is_taskstats_denied(int pid)
69710 +{
69711 + struct task_struct *task;
69712 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69713 + const struct cred *cred;
69714 +#endif
69715 + int ret = 0;
69716 +
69717 + /* restrict taskstats viewing to un-chrooted root users
69718 + who have the 'view' subject flag if the RBAC system is enabled
69719 + */
69720 +
69721 + rcu_read_lock();
69722 + read_lock(&tasklist_lock);
69723 + task = find_task_by_vpid(pid);
69724 + if (task) {
69725 +#ifdef CONFIG_GRKERNSEC_CHROOT
69726 + if (proc_is_chrooted(task))
69727 + ret = -EACCES;
69728 +#endif
69729 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69730 + cred = __task_cred(task);
69731 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69732 + if (gr_is_global_nonroot(cred->uid))
69733 + ret = -EACCES;
69734 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69735 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69736 + ret = -EACCES;
69737 +#endif
69738 +#endif
69739 + if (gr_status & GR_READY) {
69740 + if (!(task->acl->mode & GR_VIEW))
69741 + ret = -EACCES;
69742 + }
69743 + } else
69744 + ret = -ENOENT;
69745 +
69746 + read_unlock(&tasklist_lock);
69747 + rcu_read_unlock();
69748 +
69749 + return ret;
69750 +}
69751 +#endif
69752 +
69753 +/* AUXV entries are filled via a descendant of search_binary_handler
69754 + after we've already applied the subject for the target
69755 +*/
69756 +int gr_acl_enable_at_secure(void)
69757 +{
69758 + if (unlikely(!(gr_status & GR_READY)))
69759 + return 0;
69760 +
69761 + if (current->acl->mode & GR_ATSECURE)
69762 + return 1;
69763 +
69764 + return 0;
69765 +}
69766 +
69767 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69768 +{
69769 + struct task_struct *task = current;
69770 + struct dentry *dentry = file->f_path.dentry;
69771 + struct vfsmount *mnt = file->f_path.mnt;
69772 + struct acl_object_label *obj, *tmp;
69773 + struct acl_subject_label *subj;
69774 + unsigned int bufsize;
69775 + int is_not_root;
69776 + char *path;
69777 + dev_t dev = __get_dev(dentry);
69778 +
69779 + if (unlikely(!(gr_status & GR_READY)))
69780 + return 1;
69781 +
69782 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69783 + return 1;
69784 +
69785 + /* ignore Eric Biederman */
69786 + if (IS_PRIVATE(dentry->d_inode))
69787 + return 1;
69788 +
69789 + subj = task->acl;
69790 + read_lock(&gr_inode_lock);
69791 + do {
69792 + obj = lookup_acl_obj_label(ino, dev, subj);
69793 + if (obj != NULL) {
69794 + read_unlock(&gr_inode_lock);
69795 + return (obj->mode & GR_FIND) ? 1 : 0;
69796 + }
69797 + } while ((subj = subj->parent_subject));
69798 + read_unlock(&gr_inode_lock);
69799 +
69800 + /* this is purely an optimization since we're looking for an object
69801 + for the directory we're doing a readdir on
69802 + if it's possible for any globbed object to match the entry we're
69803 + filling into the directory, then the object we find here will be
69804 + an anchor point with attached globbed objects
69805 + */
69806 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69807 + if (obj->globbed == NULL)
69808 + return (obj->mode & GR_FIND) ? 1 : 0;
69809 +
69810 + is_not_root = ((obj->filename[0] == '/') &&
69811 + (obj->filename[1] == '\0')) ? 0 : 1;
69812 + bufsize = PAGE_SIZE - namelen - is_not_root;
69813 +
69814 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
69815 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69816 + return 1;
69817 +
69818 + preempt_disable();
69819 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69820 + bufsize);
69821 +
69822 + bufsize = strlen(path);
69823 +
69824 + /* if base is "/", don't append an additional slash */
69825 + if (is_not_root)
69826 + *(path + bufsize) = '/';
69827 + memcpy(path + bufsize + is_not_root, name, namelen);
69828 + *(path + bufsize + namelen + is_not_root) = '\0';
69829 +
69830 + tmp = obj->globbed;
69831 + while (tmp) {
69832 + if (!glob_match(tmp->filename, path)) {
69833 + preempt_enable();
69834 + return (tmp->mode & GR_FIND) ? 1 : 0;
69835 + }
69836 + tmp = tmp->next;
69837 + }
69838 + preempt_enable();
69839 + return (obj->mode & GR_FIND) ? 1 : 0;
69840 +}
69841 +
69842 +void gr_put_exec_file(struct task_struct *task)
69843 +{
69844 + struct file *filp;
69845 +
69846 + write_lock(&grsec_exec_file_lock);
69847 + filp = task->exec_file;
69848 + task->exec_file = NULL;
69849 + write_unlock(&grsec_exec_file_lock);
69850 +
69851 + if (filp)
69852 + fput(filp);
69853 +
69854 + return;
69855 +}
69856 +
69857 +
69858 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69859 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69860 +#endif
69861 +#ifdef CONFIG_SECURITY
69862 +EXPORT_SYMBOL_GPL(gr_check_user_change);
69863 +EXPORT_SYMBOL_GPL(gr_check_group_change);
69864 +#endif
69865 +
69866 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69867 new file mode 100644
69868 index 0000000..18ffbbd
69869 --- /dev/null
69870 +++ b/grsecurity/gracl_alloc.c
69871 @@ -0,0 +1,105 @@
69872 +#include <linux/kernel.h>
69873 +#include <linux/mm.h>
69874 +#include <linux/slab.h>
69875 +#include <linux/vmalloc.h>
69876 +#include <linux/gracl.h>
69877 +#include <linux/grsecurity.h>
69878 +
69879 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69880 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69881 +
69882 +static __inline__ int
69883 +alloc_pop(void)
69884 +{
69885 + if (current_alloc_state->alloc_stack_next == 1)
69886 + return 0;
69887 +
69888 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69889 +
69890 + current_alloc_state->alloc_stack_next--;
69891 +
69892 + return 1;
69893 +}
69894 +
69895 +static __inline__ int
69896 +alloc_push(void *buf)
69897 +{
69898 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69899 + return 1;
69900 +
69901 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69902 +
69903 + current_alloc_state->alloc_stack_next++;
69904 +
69905 + return 0;
69906 +}
69907 +
69908 +void *
69909 +acl_alloc(unsigned long len)
69910 +{
69911 + void *ret = NULL;
69912 +
69913 + if (!len || len > PAGE_SIZE)
69914 + goto out;
69915 +
69916 + ret = kmalloc(len, GFP_KERNEL);
69917 +
69918 + if (ret) {
69919 + if (alloc_push(ret)) {
69920 + kfree(ret);
69921 + ret = NULL;
69922 + }
69923 + }
69924 +
69925 +out:
69926 + return ret;
69927 +}
69928 +
69929 +void *
69930 +acl_alloc_num(unsigned long num, unsigned long len)
69931 +{
69932 + if (!len || (num > (PAGE_SIZE / len)))
69933 + return NULL;
69934 +
69935 + return acl_alloc(num * len);
69936 +}
69937 +
69938 +void
69939 +acl_free_all(void)
69940 +{
69941 + if (!current_alloc_state->alloc_stack)
69942 + return;
69943 +
69944 + while (alloc_pop()) ;
69945 +
69946 + if (current_alloc_state->alloc_stack) {
69947 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69948 + kfree(current_alloc_state->alloc_stack);
69949 + else
69950 + vfree(current_alloc_state->alloc_stack);
69951 + }
69952 +
69953 + current_alloc_state->alloc_stack = NULL;
69954 + current_alloc_state->alloc_stack_size = 1;
69955 + current_alloc_state->alloc_stack_next = 1;
69956 +
69957 + return;
69958 +}
69959 +
69960 +int
69961 +acl_alloc_stack_init(unsigned long size)
69962 +{
69963 + if ((size * sizeof (void *)) <= PAGE_SIZE)
69964 + current_alloc_state->alloc_stack =
69965 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69966 + else
69967 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69968 +
69969 + current_alloc_state->alloc_stack_size = size;
69970 + current_alloc_state->alloc_stack_next = 1;
69971 +
69972 + if (!current_alloc_state->alloc_stack)
69973 + return 0;
69974 + else
69975 + return 1;
69976 +}
69977 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69978 new file mode 100644
69979 index 0000000..bdd51ea
69980 --- /dev/null
69981 +++ b/grsecurity/gracl_cap.c
69982 @@ -0,0 +1,110 @@
69983 +#include <linux/kernel.h>
69984 +#include <linux/module.h>
69985 +#include <linux/sched.h>
69986 +#include <linux/gracl.h>
69987 +#include <linux/grsecurity.h>
69988 +#include <linux/grinternal.h>
69989 +
69990 +extern const char *captab_log[];
69991 +extern int captab_log_entries;
69992 +
69993 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69994 +{
69995 + struct acl_subject_label *curracl;
69996 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69997 + kernel_cap_t cap_audit = __cap_empty_set;
69998 +
69999 + if (!gr_acl_is_enabled())
70000 + return 1;
70001 +
70002 + curracl = task->acl;
70003 +
70004 + cap_drop = curracl->cap_lower;
70005 + cap_mask = curracl->cap_mask;
70006 + cap_audit = curracl->cap_invert_audit;
70007 +
70008 + while ((curracl = curracl->parent_subject)) {
70009 + /* if the cap isn't specified in the current computed mask but is specified in the
70010 + current level subject, and is lowered in the current level subject, then add
70011 + it to the set of dropped capabilities
70012 + otherwise, add the current level subject's mask to the current computed mask
70013 + */
70014 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70015 + cap_raise(cap_mask, cap);
70016 + if (cap_raised(curracl->cap_lower, cap))
70017 + cap_raise(cap_drop, cap);
70018 + if (cap_raised(curracl->cap_invert_audit, cap))
70019 + cap_raise(cap_audit, cap);
70020 + }
70021 + }
70022 +
70023 + if (!cap_raised(cap_drop, cap)) {
70024 + if (cap_raised(cap_audit, cap))
70025 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
70026 + return 1;
70027 + }
70028 +
70029 + curracl = task->acl;
70030 +
70031 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
70032 + && cap_raised(cred->cap_effective, cap)) {
70033 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
70034 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
70035 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
70036 + gr_to_filename(task->exec_file->f_path.dentry,
70037 + task->exec_file->f_path.mnt) : curracl->filename,
70038 + curracl->filename, 0UL,
70039 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
70040 + return 1;
70041 + }
70042 +
70043 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
70044 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
70045 +
70046 + return 0;
70047 +}
70048 +
70049 +int
70050 +gr_acl_is_capable(const int cap)
70051 +{
70052 + return gr_task_acl_is_capable(current, current_cred(), cap);
70053 +}
70054 +
70055 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
70056 +{
70057 + struct acl_subject_label *curracl;
70058 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
70059 +
70060 + if (!gr_acl_is_enabled())
70061 + return 1;
70062 +
70063 + curracl = task->acl;
70064 +
70065 + cap_drop = curracl->cap_lower;
70066 + cap_mask = curracl->cap_mask;
70067 +
70068 + while ((curracl = curracl->parent_subject)) {
70069 + /* if the cap isn't specified in the current computed mask but is specified in the
70070 + current level subject, and is lowered in the current level subject, then add
70071 + it to the set of dropped capabilities
70072 + otherwise, add the current level subject's mask to the current computed mask
70073 + */
70074 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70075 + cap_raise(cap_mask, cap);
70076 + if (cap_raised(curracl->cap_lower, cap))
70077 + cap_raise(cap_drop, cap);
70078 + }
70079 + }
70080 +
70081 + if (!cap_raised(cap_drop, cap))
70082 + return 1;
70083 +
70084 + return 0;
70085 +}
70086 +
70087 +int
70088 +gr_acl_is_capable_nolog(const int cap)
70089 +{
70090 + return gr_task_acl_is_capable_nolog(current, cap);
70091 +}
70092 +
70093 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
70094 new file mode 100644
70095 index 0000000..ca25605
70096 --- /dev/null
70097 +++ b/grsecurity/gracl_compat.c
70098 @@ -0,0 +1,270 @@
70099 +#include <linux/kernel.h>
70100 +#include <linux/gracl.h>
70101 +#include <linux/compat.h>
70102 +#include <linux/gracl_compat.h>
70103 +
70104 +#include <asm/uaccess.h>
70105 +
70106 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
70107 +{
70108 + struct gr_arg_wrapper_compat uwrapcompat;
70109 +
70110 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
70111 + return -EFAULT;
70112 +
70113 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
70114 + (uwrapcompat.version != 0x2901)) ||
70115 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
70116 + return -EINVAL;
70117 +
70118 + uwrap->arg = compat_ptr(uwrapcompat.arg);
70119 + uwrap->version = uwrapcompat.version;
70120 + uwrap->size = sizeof(struct gr_arg);
70121 +
70122 + return 0;
70123 +}
70124 +
70125 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
70126 +{
70127 + struct gr_arg_compat argcompat;
70128 +
70129 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
70130 + return -EFAULT;
70131 +
70132 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
70133 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
70134 + arg->role_db.num_roles = argcompat.role_db.num_roles;
70135 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
70136 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
70137 + arg->role_db.num_objects = argcompat.role_db.num_objects;
70138 +
70139 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
70140 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
70141 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
70142 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
70143 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
70144 + arg->segv_device = argcompat.segv_device;
70145 + arg->segv_inode = argcompat.segv_inode;
70146 + arg->segv_uid = argcompat.segv_uid;
70147 + arg->num_sprole_pws = argcompat.num_sprole_pws;
70148 + arg->mode = argcompat.mode;
70149 +
70150 + return 0;
70151 +}
70152 +
70153 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
70154 +{
70155 + struct acl_object_label_compat objcompat;
70156 +
70157 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
70158 + return -EFAULT;
70159 +
70160 + obj->filename = compat_ptr(objcompat.filename);
70161 + obj->inode = objcompat.inode;
70162 + obj->device = objcompat.device;
70163 + obj->mode = objcompat.mode;
70164 +
70165 + obj->nested = compat_ptr(objcompat.nested);
70166 + obj->globbed = compat_ptr(objcompat.globbed);
70167 +
70168 + obj->prev = compat_ptr(objcompat.prev);
70169 + obj->next = compat_ptr(objcompat.next);
70170 +
70171 + return 0;
70172 +}
70173 +
70174 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70175 +{
70176 + unsigned int i;
70177 + struct acl_subject_label_compat subjcompat;
70178 +
70179 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
70180 + return -EFAULT;
70181 +
70182 + subj->filename = compat_ptr(subjcompat.filename);
70183 + subj->inode = subjcompat.inode;
70184 + subj->device = subjcompat.device;
70185 + subj->mode = subjcompat.mode;
70186 + subj->cap_mask = subjcompat.cap_mask;
70187 + subj->cap_lower = subjcompat.cap_lower;
70188 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
70189 +
70190 + for (i = 0; i < GR_NLIMITS; i++) {
70191 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
70192 + subj->res[i].rlim_cur = RLIM_INFINITY;
70193 + else
70194 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
70195 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
70196 + subj->res[i].rlim_max = RLIM_INFINITY;
70197 + else
70198 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70199 + }
70200 + subj->resmask = subjcompat.resmask;
70201 +
70202 + subj->user_trans_type = subjcompat.user_trans_type;
70203 + subj->group_trans_type = subjcompat.group_trans_type;
70204 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70205 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70206 + subj->user_trans_num = subjcompat.user_trans_num;
70207 + subj->group_trans_num = subjcompat.group_trans_num;
70208 +
70209 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70210 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70211 + subj->ip_type = subjcompat.ip_type;
70212 + subj->ips = compat_ptr(subjcompat.ips);
70213 + subj->ip_num = subjcompat.ip_num;
70214 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
70215 +
70216 + subj->crashes = subjcompat.crashes;
70217 + subj->expires = subjcompat.expires;
70218 +
70219 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70220 + subj->hash = compat_ptr(subjcompat.hash);
70221 + subj->prev = compat_ptr(subjcompat.prev);
70222 + subj->next = compat_ptr(subjcompat.next);
70223 +
70224 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70225 + subj->obj_hash_size = subjcompat.obj_hash_size;
70226 + subj->pax_flags = subjcompat.pax_flags;
70227 +
70228 + return 0;
70229 +}
70230 +
70231 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70232 +{
70233 + struct acl_role_label_compat rolecompat;
70234 +
70235 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70236 + return -EFAULT;
70237 +
70238 + role->rolename = compat_ptr(rolecompat.rolename);
70239 + role->uidgid = rolecompat.uidgid;
70240 + role->roletype = rolecompat.roletype;
70241 +
70242 + role->auth_attempts = rolecompat.auth_attempts;
70243 + role->expires = rolecompat.expires;
70244 +
70245 + role->root_label = compat_ptr(rolecompat.root_label);
70246 + role->hash = compat_ptr(rolecompat.hash);
70247 +
70248 + role->prev = compat_ptr(rolecompat.prev);
70249 + role->next = compat_ptr(rolecompat.next);
70250 +
70251 + role->transitions = compat_ptr(rolecompat.transitions);
70252 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70253 + role->domain_children = compat_ptr(rolecompat.domain_children);
70254 + role->domain_child_num = rolecompat.domain_child_num;
70255 +
70256 + role->umask = rolecompat.umask;
70257 +
70258 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
70259 + role->subj_hash_size = rolecompat.subj_hash_size;
70260 +
70261 + return 0;
70262 +}
70263 +
70264 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70265 +{
70266 + struct role_allowed_ip_compat roleip_compat;
70267 +
70268 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70269 + return -EFAULT;
70270 +
70271 + roleip->addr = roleip_compat.addr;
70272 + roleip->netmask = roleip_compat.netmask;
70273 +
70274 + roleip->prev = compat_ptr(roleip_compat.prev);
70275 + roleip->next = compat_ptr(roleip_compat.next);
70276 +
70277 + return 0;
70278 +}
70279 +
70280 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70281 +{
70282 + struct role_transition_compat trans_compat;
70283 +
70284 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70285 + return -EFAULT;
70286 +
70287 + trans->rolename = compat_ptr(trans_compat.rolename);
70288 +
70289 + trans->prev = compat_ptr(trans_compat.prev);
70290 + trans->next = compat_ptr(trans_compat.next);
70291 +
70292 + return 0;
70293 +
70294 +}
70295 +
70296 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70297 +{
70298 + struct gr_hash_struct_compat hash_compat;
70299 +
70300 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70301 + return -EFAULT;
70302 +
70303 + hash->table = compat_ptr(hash_compat.table);
70304 + hash->nametable = compat_ptr(hash_compat.nametable);
70305 + hash->first = compat_ptr(hash_compat.first);
70306 +
70307 + hash->table_size = hash_compat.table_size;
70308 + hash->used_size = hash_compat.used_size;
70309 +
70310 + hash->type = hash_compat.type;
70311 +
70312 + return 0;
70313 +}
70314 +
70315 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70316 +{
70317 + compat_uptr_t ptrcompat;
70318 +
70319 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70320 + return -EFAULT;
70321 +
70322 + *(void **)ptr = compat_ptr(ptrcompat);
70323 +
70324 + return 0;
70325 +}
70326 +
70327 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70328 +{
70329 + struct acl_ip_label_compat ip_compat;
70330 +
70331 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70332 + return -EFAULT;
70333 +
70334 + ip->iface = compat_ptr(ip_compat.iface);
70335 + ip->addr = ip_compat.addr;
70336 + ip->netmask = ip_compat.netmask;
70337 + ip->low = ip_compat.low;
70338 + ip->high = ip_compat.high;
70339 + ip->mode = ip_compat.mode;
70340 + ip->type = ip_compat.type;
70341 +
70342 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70343 +
70344 + ip->prev = compat_ptr(ip_compat.prev);
70345 + ip->next = compat_ptr(ip_compat.next);
70346 +
70347 + return 0;
70348 +}
70349 +
70350 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70351 +{
70352 + struct sprole_pw_compat pw_compat;
70353 +
70354 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70355 + return -EFAULT;
70356 +
70357 + pw->rolename = compat_ptr(pw_compat.rolename);
70358 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70359 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70360 +
70361 + return 0;
70362 +}
70363 +
70364 +size_t get_gr_arg_wrapper_size_compat(void)
70365 +{
70366 + return sizeof(struct gr_arg_wrapper_compat);
70367 +}
70368 +
70369 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70370 new file mode 100644
70371 index 0000000..a89b1f4
70372 --- /dev/null
70373 +++ b/grsecurity/gracl_fs.c
70374 @@ -0,0 +1,437 @@
70375 +#include <linux/kernel.h>
70376 +#include <linux/sched.h>
70377 +#include <linux/types.h>
70378 +#include <linux/fs.h>
70379 +#include <linux/file.h>
70380 +#include <linux/stat.h>
70381 +#include <linux/grsecurity.h>
70382 +#include <linux/grinternal.h>
70383 +#include <linux/gracl.h>
70384 +
70385 +umode_t
70386 +gr_acl_umask(void)
70387 +{
70388 + if (unlikely(!gr_acl_is_enabled()))
70389 + return 0;
70390 +
70391 + return current->role->umask;
70392 +}
70393 +
70394 +__u32
70395 +gr_acl_handle_hidden_file(const struct dentry * dentry,
70396 + const struct vfsmount * mnt)
70397 +{
70398 + __u32 mode;
70399 +
70400 + if (unlikely(d_is_negative(dentry)))
70401 + return GR_FIND;
70402 +
70403 + mode =
70404 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70405 +
70406 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70407 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70408 + return mode;
70409 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70410 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70411 + return 0;
70412 + } else if (unlikely(!(mode & GR_FIND)))
70413 + return 0;
70414 +
70415 + return GR_FIND;
70416 +}
70417 +
70418 +__u32
70419 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70420 + int acc_mode)
70421 +{
70422 + __u32 reqmode = GR_FIND;
70423 + __u32 mode;
70424 +
70425 + if (unlikely(d_is_negative(dentry)))
70426 + return reqmode;
70427 +
70428 + if (acc_mode & MAY_APPEND)
70429 + reqmode |= GR_APPEND;
70430 + else if (acc_mode & MAY_WRITE)
70431 + reqmode |= GR_WRITE;
70432 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70433 + reqmode |= GR_READ;
70434 +
70435 + mode =
70436 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70437 + mnt);
70438 +
70439 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70440 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70441 + reqmode & GR_READ ? " reading" : "",
70442 + reqmode & GR_WRITE ? " writing" : reqmode &
70443 + GR_APPEND ? " appending" : "");
70444 + return reqmode;
70445 + } else
70446 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70447 + {
70448 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70449 + reqmode & GR_READ ? " reading" : "",
70450 + reqmode & GR_WRITE ? " writing" : reqmode &
70451 + GR_APPEND ? " appending" : "");
70452 + return 0;
70453 + } else if (unlikely((mode & reqmode) != reqmode))
70454 + return 0;
70455 +
70456 + return reqmode;
70457 +}
70458 +
70459 +__u32
70460 +gr_acl_handle_creat(const struct dentry * dentry,
70461 + const struct dentry * p_dentry,
70462 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70463 + const int imode)
70464 +{
70465 + __u32 reqmode = GR_WRITE | GR_CREATE;
70466 + __u32 mode;
70467 +
70468 + if (acc_mode & MAY_APPEND)
70469 + reqmode |= GR_APPEND;
70470 + // if a directory was required or the directory already exists, then
70471 + // don't count this open as a read
70472 + if ((acc_mode & MAY_READ) &&
70473 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70474 + reqmode |= GR_READ;
70475 + if ((open_flags & O_CREAT) &&
70476 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70477 + reqmode |= GR_SETID;
70478 +
70479 + mode =
70480 + gr_check_create(dentry, p_dentry, p_mnt,
70481 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70482 +
70483 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70484 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70485 + reqmode & GR_READ ? " reading" : "",
70486 + reqmode & GR_WRITE ? " writing" : reqmode &
70487 + GR_APPEND ? " appending" : "");
70488 + return reqmode;
70489 + } else
70490 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70491 + {
70492 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70493 + reqmode & GR_READ ? " reading" : "",
70494 + reqmode & GR_WRITE ? " writing" : reqmode &
70495 + GR_APPEND ? " appending" : "");
70496 + return 0;
70497 + } else if (unlikely((mode & reqmode) != reqmode))
70498 + return 0;
70499 +
70500 + return reqmode;
70501 +}
70502 +
70503 +__u32
70504 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70505 + const int fmode)
70506 +{
70507 + __u32 mode, reqmode = GR_FIND;
70508 +
70509 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70510 + reqmode |= GR_EXEC;
70511 + if (fmode & S_IWOTH)
70512 + reqmode |= GR_WRITE;
70513 + if (fmode & S_IROTH)
70514 + reqmode |= GR_READ;
70515 +
70516 + mode =
70517 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70518 + mnt);
70519 +
70520 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70521 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70522 + reqmode & GR_READ ? " reading" : "",
70523 + reqmode & GR_WRITE ? " writing" : "",
70524 + reqmode & GR_EXEC ? " executing" : "");
70525 + return reqmode;
70526 + } else
70527 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70528 + {
70529 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70530 + reqmode & GR_READ ? " reading" : "",
70531 + reqmode & GR_WRITE ? " writing" : "",
70532 + reqmode & GR_EXEC ? " executing" : "");
70533 + return 0;
70534 + } else if (unlikely((mode & reqmode) != reqmode))
70535 + return 0;
70536 +
70537 + return reqmode;
70538 +}
70539 +
70540 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70541 +{
70542 + __u32 mode;
70543 +
70544 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70545 +
70546 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70547 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70548 + return mode;
70549 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70550 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70551 + return 0;
70552 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70553 + return 0;
70554 +
70555 + return (reqmode);
70556 +}
70557 +
70558 +__u32
70559 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70560 +{
70561 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70562 +}
70563 +
70564 +__u32
70565 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70566 +{
70567 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70568 +}
70569 +
70570 +__u32
70571 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70572 +{
70573 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70574 +}
70575 +
70576 +__u32
70577 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70578 +{
70579 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70580 +}
70581 +
70582 +__u32
70583 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70584 + umode_t *modeptr)
70585 +{
70586 + umode_t mode;
70587 +
70588 + *modeptr &= ~gr_acl_umask();
70589 + mode = *modeptr;
70590 +
70591 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70592 + return 1;
70593 +
70594 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70595 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70596 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70597 + GR_CHMOD_ACL_MSG);
70598 + } else {
70599 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70600 + }
70601 +}
70602 +
70603 +__u32
70604 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70605 +{
70606 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70607 +}
70608 +
70609 +__u32
70610 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70611 +{
70612 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70613 +}
70614 +
70615 +__u32
70616 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70617 +{
70618 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70619 +}
70620 +
70621 +__u32
70622 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70623 +{
70624 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70625 +}
70626 +
70627 +__u32
70628 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70629 +{
70630 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70631 + GR_UNIXCONNECT_ACL_MSG);
70632 +}
70633 +
70634 +/* hardlinks require at minimum create and link permission,
70635 + any additional privilege required is based on the
70636 + privilege of the file being linked to
70637 +*/
70638 +__u32
70639 +gr_acl_handle_link(const struct dentry * new_dentry,
70640 + const struct dentry * parent_dentry,
70641 + const struct vfsmount * parent_mnt,
70642 + const struct dentry * old_dentry,
70643 + const struct vfsmount * old_mnt, const struct filename *to)
70644 +{
70645 + __u32 mode;
70646 + __u32 needmode = GR_CREATE | GR_LINK;
70647 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70648 +
70649 + mode =
70650 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70651 + old_mnt);
70652 +
70653 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70654 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70655 + return mode;
70656 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70657 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70658 + return 0;
70659 + } else if (unlikely((mode & needmode) != needmode))
70660 + return 0;
70661 +
70662 + return 1;
70663 +}
70664 +
70665 +__u32
70666 +gr_acl_handle_symlink(const struct dentry * new_dentry,
70667 + const struct dentry * parent_dentry,
70668 + const struct vfsmount * parent_mnt, const struct filename *from)
70669 +{
70670 + __u32 needmode = GR_WRITE | GR_CREATE;
70671 + __u32 mode;
70672 +
70673 + mode =
70674 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
70675 + GR_CREATE | GR_AUDIT_CREATE |
70676 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70677 +
70678 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70679 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70680 + return mode;
70681 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70682 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70683 + return 0;
70684 + } else if (unlikely((mode & needmode) != needmode))
70685 + return 0;
70686 +
70687 + return (GR_WRITE | GR_CREATE);
70688 +}
70689 +
70690 +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)
70691 +{
70692 + __u32 mode;
70693 +
70694 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70695 +
70696 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70697 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70698 + return mode;
70699 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70700 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70701 + return 0;
70702 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70703 + return 0;
70704 +
70705 + return (reqmode);
70706 +}
70707 +
70708 +__u32
70709 +gr_acl_handle_mknod(const struct dentry * new_dentry,
70710 + const struct dentry * parent_dentry,
70711 + const struct vfsmount * parent_mnt,
70712 + const int mode)
70713 +{
70714 + __u32 reqmode = GR_WRITE | GR_CREATE;
70715 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70716 + reqmode |= GR_SETID;
70717 +
70718 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70719 + reqmode, GR_MKNOD_ACL_MSG);
70720 +}
70721 +
70722 +__u32
70723 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
70724 + const struct dentry *parent_dentry,
70725 + const struct vfsmount *parent_mnt)
70726 +{
70727 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70728 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70729 +}
70730 +
70731 +#define RENAME_CHECK_SUCCESS(old, new) \
70732 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70733 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70734 +
70735 +int
70736 +gr_acl_handle_rename(struct dentry *new_dentry,
70737 + struct dentry *parent_dentry,
70738 + const struct vfsmount *parent_mnt,
70739 + struct dentry *old_dentry,
70740 + struct inode *old_parent_inode,
70741 + struct vfsmount *old_mnt, const struct filename *newname)
70742 +{
70743 + __u32 comp1, comp2;
70744 + int error = 0;
70745 +
70746 + if (unlikely(!gr_acl_is_enabled()))
70747 + return 0;
70748 +
70749 + if (d_is_negative(new_dentry)) {
70750 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70751 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70752 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70753 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70754 + GR_DELETE | GR_AUDIT_DELETE |
70755 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70756 + GR_SUPPRESS, old_mnt);
70757 + } else {
70758 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70759 + GR_CREATE | GR_DELETE |
70760 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70761 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70762 + GR_SUPPRESS, parent_mnt);
70763 + comp2 =
70764 + gr_search_file(old_dentry,
70765 + GR_READ | GR_WRITE | GR_AUDIT_READ |
70766 + GR_DELETE | GR_AUDIT_DELETE |
70767 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70768 + }
70769 +
70770 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70771 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70772 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70773 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70774 + && !(comp2 & GR_SUPPRESS)) {
70775 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70776 + error = -EACCES;
70777 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70778 + error = -EACCES;
70779 +
70780 + return error;
70781 +}
70782 +
70783 +void
70784 +gr_acl_handle_exit(void)
70785 +{
70786 + u16 id;
70787 + char *rolename;
70788 +
70789 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70790 + !(current->role->roletype & GR_ROLE_PERSIST))) {
70791 + id = current->acl_role_id;
70792 + rolename = current->role->rolename;
70793 + gr_set_acls(1);
70794 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70795 + }
70796 +
70797 + gr_put_exec_file(current);
70798 + return;
70799 +}
70800 +
70801 +int
70802 +gr_acl_handle_procpidmem(const struct task_struct *task)
70803 +{
70804 + if (unlikely(!gr_acl_is_enabled()))
70805 + return 0;
70806 +
70807 + if (task != current && task->acl->mode & GR_PROTPROCFD)
70808 + return -EACCES;
70809 +
70810 + return 0;
70811 +}
70812 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70813 new file mode 100644
70814 index 0000000..f056b81
70815 --- /dev/null
70816 +++ b/grsecurity/gracl_ip.c
70817 @@ -0,0 +1,386 @@
70818 +#include <linux/kernel.h>
70819 +#include <asm/uaccess.h>
70820 +#include <asm/errno.h>
70821 +#include <net/sock.h>
70822 +#include <linux/file.h>
70823 +#include <linux/fs.h>
70824 +#include <linux/net.h>
70825 +#include <linux/in.h>
70826 +#include <linux/skbuff.h>
70827 +#include <linux/ip.h>
70828 +#include <linux/udp.h>
70829 +#include <linux/types.h>
70830 +#include <linux/sched.h>
70831 +#include <linux/netdevice.h>
70832 +#include <linux/inetdevice.h>
70833 +#include <linux/gracl.h>
70834 +#include <linux/grsecurity.h>
70835 +#include <linux/grinternal.h>
70836 +
70837 +#define GR_BIND 0x01
70838 +#define GR_CONNECT 0x02
70839 +#define GR_INVERT 0x04
70840 +#define GR_BINDOVERRIDE 0x08
70841 +#define GR_CONNECTOVERRIDE 0x10
70842 +#define GR_SOCK_FAMILY 0x20
70843 +
70844 +static const char * gr_protocols[IPPROTO_MAX] = {
70845 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70846 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70847 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70848 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70849 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70850 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70851 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70852 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70853 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70854 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70855 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70856 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70857 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70858 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70859 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70860 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70861 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70862 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70863 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70864 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70865 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70866 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70867 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70868 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70869 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70870 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70871 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70872 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70873 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70874 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70875 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70876 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70877 + };
70878 +
70879 +static const char * gr_socktypes[SOCK_MAX] = {
70880 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70881 + "unknown:7", "unknown:8", "unknown:9", "packet"
70882 + };
70883 +
70884 +static const char * gr_sockfamilies[AF_MAX+1] = {
70885 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70886 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70887 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70888 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70889 + };
70890 +
70891 +const char *
70892 +gr_proto_to_name(unsigned char proto)
70893 +{
70894 + return gr_protocols[proto];
70895 +}
70896 +
70897 +const char *
70898 +gr_socktype_to_name(unsigned char type)
70899 +{
70900 + return gr_socktypes[type];
70901 +}
70902 +
70903 +const char *
70904 +gr_sockfamily_to_name(unsigned char family)
70905 +{
70906 + return gr_sockfamilies[family];
70907 +}
70908 +
70909 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70910 +
70911 +int
70912 +gr_search_socket(const int domain, const int type, const int protocol)
70913 +{
70914 + struct acl_subject_label *curr;
70915 + const struct cred *cred = current_cred();
70916 +
70917 + if (unlikely(!gr_acl_is_enabled()))
70918 + goto exit;
70919 +
70920 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
70921 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70922 + goto exit; // let the kernel handle it
70923 +
70924 + curr = current->acl;
70925 +
70926 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70927 + /* the family is allowed, if this is PF_INET allow it only if
70928 + the extra sock type/protocol checks pass */
70929 + if (domain == PF_INET)
70930 + goto inet_check;
70931 + goto exit;
70932 + } else {
70933 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70934 + __u32 fakeip = 0;
70935 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70936 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70937 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70938 + gr_to_filename(current->exec_file->f_path.dentry,
70939 + current->exec_file->f_path.mnt) :
70940 + curr->filename, curr->filename,
70941 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70942 + &current->signal->saved_ip);
70943 + goto exit;
70944 + }
70945 + goto exit_fail;
70946 + }
70947 +
70948 +inet_check:
70949 + /* the rest of this checking is for IPv4 only */
70950 + if (!curr->ips)
70951 + goto exit;
70952 +
70953 + if ((curr->ip_type & (1U << type)) &&
70954 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70955 + goto exit;
70956 +
70957 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70958 + /* we don't place acls on raw sockets , and sometimes
70959 + dgram/ip sockets are opened for ioctl and not
70960 + bind/connect, so we'll fake a bind learn log */
70961 + if (type == SOCK_RAW || type == SOCK_PACKET) {
70962 + __u32 fakeip = 0;
70963 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70964 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70965 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70966 + gr_to_filename(current->exec_file->f_path.dentry,
70967 + current->exec_file->f_path.mnt) :
70968 + curr->filename, curr->filename,
70969 + &fakeip, 0, type,
70970 + protocol, GR_CONNECT, &current->signal->saved_ip);
70971 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70972 + __u32 fakeip = 0;
70973 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70974 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70975 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70976 + gr_to_filename(current->exec_file->f_path.dentry,
70977 + current->exec_file->f_path.mnt) :
70978 + curr->filename, curr->filename,
70979 + &fakeip, 0, type,
70980 + protocol, GR_BIND, &current->signal->saved_ip);
70981 + }
70982 + /* we'll log when they use connect or bind */
70983 + goto exit;
70984 + }
70985 +
70986 +exit_fail:
70987 + if (domain == PF_INET)
70988 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70989 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
70990 + else if (rcu_access_pointer(net_families[domain]) != NULL)
70991 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70992 + gr_socktype_to_name(type), protocol);
70993 +
70994 + return 0;
70995 +exit:
70996 + return 1;
70997 +}
70998 +
70999 +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)
71000 +{
71001 + if ((ip->mode & mode) &&
71002 + (ip_port >= ip->low) &&
71003 + (ip_port <= ip->high) &&
71004 + ((ntohl(ip_addr) & our_netmask) ==
71005 + (ntohl(our_addr) & our_netmask))
71006 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
71007 + && (ip->type & (1U << type))) {
71008 + if (ip->mode & GR_INVERT)
71009 + return 2; // specifically denied
71010 + else
71011 + return 1; // allowed
71012 + }
71013 +
71014 + return 0; // not specifically allowed, may continue parsing
71015 +}
71016 +
71017 +static int
71018 +gr_search_connectbind(const int full_mode, struct sock *sk,
71019 + struct sockaddr_in *addr, const int type)
71020 +{
71021 + char iface[IFNAMSIZ] = {0};
71022 + struct acl_subject_label *curr;
71023 + struct acl_ip_label *ip;
71024 + struct inet_sock *isk;
71025 + struct net_device *dev;
71026 + struct in_device *idev;
71027 + unsigned long i;
71028 + int ret;
71029 + int mode = full_mode & (GR_BIND | GR_CONNECT);
71030 + __u32 ip_addr = 0;
71031 + __u32 our_addr;
71032 + __u32 our_netmask;
71033 + char *p;
71034 + __u16 ip_port = 0;
71035 + const struct cred *cred = current_cred();
71036 +
71037 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
71038 + return 0;
71039 +
71040 + curr = current->acl;
71041 + isk = inet_sk(sk);
71042 +
71043 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
71044 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
71045 + addr->sin_addr.s_addr = curr->inaddr_any_override;
71046 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
71047 + struct sockaddr_in saddr;
71048 + int err;
71049 +
71050 + saddr.sin_family = AF_INET;
71051 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
71052 + saddr.sin_port = isk->inet_sport;
71053 +
71054 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71055 + if (err)
71056 + return err;
71057 +
71058 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
71059 + if (err)
71060 + return err;
71061 + }
71062 +
71063 + if (!curr->ips)
71064 + return 0;
71065 +
71066 + ip_addr = addr->sin_addr.s_addr;
71067 + ip_port = ntohs(addr->sin_port);
71068 +
71069 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
71070 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71071 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
71072 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
71073 + gr_to_filename(current->exec_file->f_path.dentry,
71074 + current->exec_file->f_path.mnt) :
71075 + curr->filename, curr->filename,
71076 + &ip_addr, ip_port, type,
71077 + sk->sk_protocol, mode, &current->signal->saved_ip);
71078 + return 0;
71079 + }
71080 +
71081 + for (i = 0; i < curr->ip_num; i++) {
71082 + ip = *(curr->ips + i);
71083 + if (ip->iface != NULL) {
71084 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
71085 + p = strchr(iface, ':');
71086 + if (p != NULL)
71087 + *p = '\0';
71088 + dev = dev_get_by_name(sock_net(sk), iface);
71089 + if (dev == NULL)
71090 + continue;
71091 + idev = in_dev_get(dev);
71092 + if (idev == NULL) {
71093 + dev_put(dev);
71094 + continue;
71095 + }
71096 + rcu_read_lock();
71097 + for_ifa(idev) {
71098 + if (!strcmp(ip->iface, ifa->ifa_label)) {
71099 + our_addr = ifa->ifa_address;
71100 + our_netmask = 0xffffffff;
71101 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71102 + if (ret == 1) {
71103 + rcu_read_unlock();
71104 + in_dev_put(idev);
71105 + dev_put(dev);
71106 + return 0;
71107 + } else if (ret == 2) {
71108 + rcu_read_unlock();
71109 + in_dev_put(idev);
71110 + dev_put(dev);
71111 + goto denied;
71112 + }
71113 + }
71114 + } endfor_ifa(idev);
71115 + rcu_read_unlock();
71116 + in_dev_put(idev);
71117 + dev_put(dev);
71118 + } else {
71119 + our_addr = ip->addr;
71120 + our_netmask = ip->netmask;
71121 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71122 + if (ret == 1)
71123 + return 0;
71124 + else if (ret == 2)
71125 + goto denied;
71126 + }
71127 + }
71128 +
71129 +denied:
71130 + if (mode == GR_BIND)
71131 + 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));
71132 + else if (mode == GR_CONNECT)
71133 + 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));
71134 +
71135 + return -EACCES;
71136 +}
71137 +
71138 +int
71139 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
71140 +{
71141 + /* always allow disconnection of dgram sockets with connect */
71142 + if (addr->sin_family == AF_UNSPEC)
71143 + return 0;
71144 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
71145 +}
71146 +
71147 +int
71148 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
71149 +{
71150 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
71151 +}
71152 +
71153 +int gr_search_listen(struct socket *sock)
71154 +{
71155 + struct sock *sk = sock->sk;
71156 + struct sockaddr_in addr;
71157 +
71158 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71159 + addr.sin_port = inet_sk(sk)->inet_sport;
71160 +
71161 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71162 +}
71163 +
71164 +int gr_search_accept(struct socket *sock)
71165 +{
71166 + struct sock *sk = sock->sk;
71167 + struct sockaddr_in addr;
71168 +
71169 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71170 + addr.sin_port = inet_sk(sk)->inet_sport;
71171 +
71172 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71173 +}
71174 +
71175 +int
71176 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
71177 +{
71178 + if (addr)
71179 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
71180 + else {
71181 + struct sockaddr_in sin;
71182 + const struct inet_sock *inet = inet_sk(sk);
71183 +
71184 + sin.sin_addr.s_addr = inet->inet_daddr;
71185 + sin.sin_port = inet->inet_dport;
71186 +
71187 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71188 + }
71189 +}
71190 +
71191 +int
71192 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71193 +{
71194 + struct sockaddr_in sin;
71195 +
71196 + if (unlikely(skb->len < sizeof (struct udphdr)))
71197 + return 0; // skip this packet
71198 +
71199 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71200 + sin.sin_port = udp_hdr(skb)->source;
71201 +
71202 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71203 +}
71204 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71205 new file mode 100644
71206 index 0000000..25f54ef
71207 --- /dev/null
71208 +++ b/grsecurity/gracl_learn.c
71209 @@ -0,0 +1,207 @@
71210 +#include <linux/kernel.h>
71211 +#include <linux/mm.h>
71212 +#include <linux/sched.h>
71213 +#include <linux/poll.h>
71214 +#include <linux/string.h>
71215 +#include <linux/file.h>
71216 +#include <linux/types.h>
71217 +#include <linux/vmalloc.h>
71218 +#include <linux/grinternal.h>
71219 +
71220 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71221 + size_t count, loff_t *ppos);
71222 +extern int gr_acl_is_enabled(void);
71223 +
71224 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71225 +static int gr_learn_attached;
71226 +
71227 +/* use a 512k buffer */
71228 +#define LEARN_BUFFER_SIZE (512 * 1024)
71229 +
71230 +static DEFINE_SPINLOCK(gr_learn_lock);
71231 +static DEFINE_MUTEX(gr_learn_user_mutex);
71232 +
71233 +/* we need to maintain two buffers, so that the kernel context of grlearn
71234 + uses a semaphore around the userspace copying, and the other kernel contexts
71235 + use a spinlock when copying into the buffer, since they cannot sleep
71236 +*/
71237 +static char *learn_buffer;
71238 +static char *learn_buffer_user;
71239 +static int learn_buffer_len;
71240 +static int learn_buffer_user_len;
71241 +
71242 +static ssize_t
71243 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71244 +{
71245 + DECLARE_WAITQUEUE(wait, current);
71246 + ssize_t retval = 0;
71247 +
71248 + add_wait_queue(&learn_wait, &wait);
71249 + set_current_state(TASK_INTERRUPTIBLE);
71250 + do {
71251 + mutex_lock(&gr_learn_user_mutex);
71252 + spin_lock(&gr_learn_lock);
71253 + if (learn_buffer_len)
71254 + break;
71255 + spin_unlock(&gr_learn_lock);
71256 + mutex_unlock(&gr_learn_user_mutex);
71257 + if (file->f_flags & O_NONBLOCK) {
71258 + retval = -EAGAIN;
71259 + goto out;
71260 + }
71261 + if (signal_pending(current)) {
71262 + retval = -ERESTARTSYS;
71263 + goto out;
71264 + }
71265 +
71266 + schedule();
71267 + } while (1);
71268 +
71269 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71270 + learn_buffer_user_len = learn_buffer_len;
71271 + retval = learn_buffer_len;
71272 + learn_buffer_len = 0;
71273 +
71274 + spin_unlock(&gr_learn_lock);
71275 +
71276 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71277 + retval = -EFAULT;
71278 +
71279 + mutex_unlock(&gr_learn_user_mutex);
71280 +out:
71281 + set_current_state(TASK_RUNNING);
71282 + remove_wait_queue(&learn_wait, &wait);
71283 + return retval;
71284 +}
71285 +
71286 +static unsigned int
71287 +poll_learn(struct file * file, poll_table * wait)
71288 +{
71289 + poll_wait(file, &learn_wait, wait);
71290 +
71291 + if (learn_buffer_len)
71292 + return (POLLIN | POLLRDNORM);
71293 +
71294 + return 0;
71295 +}
71296 +
71297 +void
71298 +gr_clear_learn_entries(void)
71299 +{
71300 + char *tmp;
71301 +
71302 + mutex_lock(&gr_learn_user_mutex);
71303 + spin_lock(&gr_learn_lock);
71304 + tmp = learn_buffer;
71305 + learn_buffer = NULL;
71306 + spin_unlock(&gr_learn_lock);
71307 + if (tmp)
71308 + vfree(tmp);
71309 + if (learn_buffer_user != NULL) {
71310 + vfree(learn_buffer_user);
71311 + learn_buffer_user = NULL;
71312 + }
71313 + learn_buffer_len = 0;
71314 + mutex_unlock(&gr_learn_user_mutex);
71315 +
71316 + return;
71317 +}
71318 +
71319 +void
71320 +gr_add_learn_entry(const char *fmt, ...)
71321 +{
71322 + va_list args;
71323 + unsigned int len;
71324 +
71325 + if (!gr_learn_attached)
71326 + return;
71327 +
71328 + spin_lock(&gr_learn_lock);
71329 +
71330 + /* leave a gap at the end so we know when it's "full" but don't have to
71331 + compute the exact length of the string we're trying to append
71332 + */
71333 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71334 + spin_unlock(&gr_learn_lock);
71335 + wake_up_interruptible(&learn_wait);
71336 + return;
71337 + }
71338 + if (learn_buffer == NULL) {
71339 + spin_unlock(&gr_learn_lock);
71340 + return;
71341 + }
71342 +
71343 + va_start(args, fmt);
71344 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71345 + va_end(args);
71346 +
71347 + learn_buffer_len += len + 1;
71348 +
71349 + spin_unlock(&gr_learn_lock);
71350 + wake_up_interruptible(&learn_wait);
71351 +
71352 + return;
71353 +}
71354 +
71355 +static int
71356 +open_learn(struct inode *inode, struct file *file)
71357 +{
71358 + if (file->f_mode & FMODE_READ && gr_learn_attached)
71359 + return -EBUSY;
71360 + if (file->f_mode & FMODE_READ) {
71361 + int retval = 0;
71362 + mutex_lock(&gr_learn_user_mutex);
71363 + if (learn_buffer == NULL)
71364 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71365 + if (learn_buffer_user == NULL)
71366 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71367 + if (learn_buffer == NULL) {
71368 + retval = -ENOMEM;
71369 + goto out_error;
71370 + }
71371 + if (learn_buffer_user == NULL) {
71372 + retval = -ENOMEM;
71373 + goto out_error;
71374 + }
71375 + learn_buffer_len = 0;
71376 + learn_buffer_user_len = 0;
71377 + gr_learn_attached = 1;
71378 +out_error:
71379 + mutex_unlock(&gr_learn_user_mutex);
71380 + return retval;
71381 + }
71382 + return 0;
71383 +}
71384 +
71385 +static int
71386 +close_learn(struct inode *inode, struct file *file)
71387 +{
71388 + if (file->f_mode & FMODE_READ) {
71389 + char *tmp = NULL;
71390 + mutex_lock(&gr_learn_user_mutex);
71391 + spin_lock(&gr_learn_lock);
71392 + tmp = learn_buffer;
71393 + learn_buffer = NULL;
71394 + spin_unlock(&gr_learn_lock);
71395 + if (tmp)
71396 + vfree(tmp);
71397 + if (learn_buffer_user != NULL) {
71398 + vfree(learn_buffer_user);
71399 + learn_buffer_user = NULL;
71400 + }
71401 + learn_buffer_len = 0;
71402 + learn_buffer_user_len = 0;
71403 + gr_learn_attached = 0;
71404 + mutex_unlock(&gr_learn_user_mutex);
71405 + }
71406 +
71407 + return 0;
71408 +}
71409 +
71410 +const struct file_operations grsec_fops = {
71411 + .read = read_learn,
71412 + .write = write_grsec_handler,
71413 + .open = open_learn,
71414 + .release = close_learn,
71415 + .poll = poll_learn,
71416 +};
71417 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71418 new file mode 100644
71419 index 0000000..361a099
71420 --- /dev/null
71421 +++ b/grsecurity/gracl_policy.c
71422 @@ -0,0 +1,1782 @@
71423 +#include <linux/kernel.h>
71424 +#include <linux/module.h>
71425 +#include <linux/sched.h>
71426 +#include <linux/mm.h>
71427 +#include <linux/file.h>
71428 +#include <linux/fs.h>
71429 +#include <linux/namei.h>
71430 +#include <linux/mount.h>
71431 +#include <linux/tty.h>
71432 +#include <linux/proc_fs.h>
71433 +#include <linux/lglock.h>
71434 +#include <linux/slab.h>
71435 +#include <linux/vmalloc.h>
71436 +#include <linux/types.h>
71437 +#include <linux/sysctl.h>
71438 +#include <linux/netdevice.h>
71439 +#include <linux/ptrace.h>
71440 +#include <linux/gracl.h>
71441 +#include <linux/gralloc.h>
71442 +#include <linux/security.h>
71443 +#include <linux/grinternal.h>
71444 +#include <linux/pid_namespace.h>
71445 +#include <linux/stop_machine.h>
71446 +#include <linux/fdtable.h>
71447 +#include <linux/percpu.h>
71448 +#include <linux/lglock.h>
71449 +#include <linux/hugetlb.h>
71450 +#include <linux/posix-timers.h>
71451 +#include "../fs/mount.h"
71452 +
71453 +#include <asm/uaccess.h>
71454 +#include <asm/errno.h>
71455 +#include <asm/mman.h>
71456 +
71457 +extern struct gr_policy_state *polstate;
71458 +
71459 +#define FOR_EACH_ROLE_START(role) \
71460 + role = polstate->role_list; \
71461 + while (role) {
71462 +
71463 +#define FOR_EACH_ROLE_END(role) \
71464 + role = role->prev; \
71465 + }
71466 +
71467 +struct path gr_real_root;
71468 +
71469 +extern struct gr_alloc_state *current_alloc_state;
71470 +
71471 +u16 acl_sp_role_value;
71472 +
71473 +static DEFINE_MUTEX(gr_dev_mutex);
71474 +
71475 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71476 +extern void gr_clear_learn_entries(void);
71477 +
71478 +static struct gr_arg gr_usermode;
71479 +static unsigned char gr_system_salt[GR_SALT_LEN];
71480 +static unsigned char gr_system_sum[GR_SHA_LEN];
71481 +
71482 +static unsigned int gr_auth_attempts = 0;
71483 +static unsigned long gr_auth_expires = 0UL;
71484 +
71485 +struct acl_object_label *fakefs_obj_rw;
71486 +struct acl_object_label *fakefs_obj_rwx;
71487 +
71488 +extern int gr_init_uidset(void);
71489 +extern void gr_free_uidset(void);
71490 +extern void gr_remove_uid(uid_t uid);
71491 +extern int gr_find_uid(uid_t uid);
71492 +
71493 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71494 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71495 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71496 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71497 +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);
71498 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71499 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71500 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71501 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71502 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71503 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71504 +extern void assign_special_role(const char *rolename);
71505 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71506 +extern int gr_rbac_disable(void *unused);
71507 +extern void gr_enable_rbac_system(void);
71508 +
71509 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71510 +{
71511 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71512 + return -EFAULT;
71513 +
71514 + return 0;
71515 +}
71516 +
71517 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71518 +{
71519 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71520 + return -EFAULT;
71521 +
71522 + return 0;
71523 +}
71524 +
71525 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71526 +{
71527 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71528 + return -EFAULT;
71529 +
71530 + return 0;
71531 +}
71532 +
71533 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71534 +{
71535 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71536 + return -EFAULT;
71537 +
71538 + return 0;
71539 +}
71540 +
71541 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71542 +{
71543 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71544 + return -EFAULT;
71545 +
71546 + return 0;
71547 +}
71548 +
71549 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71550 +{
71551 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71552 + return -EFAULT;
71553 +
71554 + return 0;
71555 +}
71556 +
71557 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71558 +{
71559 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71560 + return -EFAULT;
71561 +
71562 + return 0;
71563 +}
71564 +
71565 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71566 +{
71567 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71568 + return -EFAULT;
71569 +
71570 + return 0;
71571 +}
71572 +
71573 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71574 +{
71575 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71576 + return -EFAULT;
71577 +
71578 + return 0;
71579 +}
71580 +
71581 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71582 +{
71583 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71584 + return -EFAULT;
71585 +
71586 + if (((uwrap->version != GRSECURITY_VERSION) &&
71587 + (uwrap->version != 0x2901)) ||
71588 + (uwrap->size != sizeof(struct gr_arg)))
71589 + return -EINVAL;
71590 +
71591 + return 0;
71592 +}
71593 +
71594 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71595 +{
71596 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71597 + return -EFAULT;
71598 +
71599 + return 0;
71600 +}
71601 +
71602 +static size_t get_gr_arg_wrapper_size_normal(void)
71603 +{
71604 + return sizeof(struct gr_arg_wrapper);
71605 +}
71606 +
71607 +#ifdef CONFIG_COMPAT
71608 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71609 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71610 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71611 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71612 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71613 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71614 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71615 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71616 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71617 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71618 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71619 +extern size_t get_gr_arg_wrapper_size_compat(void);
71620 +
71621 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71622 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71623 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71624 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71625 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71626 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71627 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71628 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71629 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71630 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71631 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71632 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71633 +
71634 +#else
71635 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71636 +#define copy_gr_arg copy_gr_arg_normal
71637 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
71638 +#define copy_acl_object_label copy_acl_object_label_normal
71639 +#define copy_acl_subject_label copy_acl_subject_label_normal
71640 +#define copy_acl_role_label copy_acl_role_label_normal
71641 +#define copy_acl_ip_label copy_acl_ip_label_normal
71642 +#define copy_pointer_from_array copy_pointer_from_array_normal
71643 +#define copy_sprole_pw copy_sprole_pw_normal
71644 +#define copy_role_transition copy_role_transition_normal
71645 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
71646 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71647 +#endif
71648 +
71649 +static struct acl_subject_label *
71650 +lookup_subject_map(const struct acl_subject_label *userp)
71651 +{
71652 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71653 + struct subject_map *match;
71654 +
71655 + match = polstate->subj_map_set.s_hash[index];
71656 +
71657 + while (match && match->user != userp)
71658 + match = match->next;
71659 +
71660 + if (match != NULL)
71661 + return match->kernel;
71662 + else
71663 + return NULL;
71664 +}
71665 +
71666 +static void
71667 +insert_subj_map_entry(struct subject_map *subjmap)
71668 +{
71669 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71670 + struct subject_map **curr;
71671 +
71672 + subjmap->prev = NULL;
71673 +
71674 + curr = &polstate->subj_map_set.s_hash[index];
71675 + if (*curr != NULL)
71676 + (*curr)->prev = subjmap;
71677 +
71678 + subjmap->next = *curr;
71679 + *curr = subjmap;
71680 +
71681 + return;
71682 +}
71683 +
71684 +static void
71685 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71686 +{
71687 + unsigned int index =
71688 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71689 + struct acl_role_label **curr;
71690 + struct acl_role_label *tmp, *tmp2;
71691 +
71692 + curr = &polstate->acl_role_set.r_hash[index];
71693 +
71694 + /* simple case, slot is empty, just set it to our role */
71695 + if (*curr == NULL) {
71696 + *curr = role;
71697 + } else {
71698 + /* example:
71699 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
71700 + 2 -> 3
71701 + */
71702 + /* first check to see if we can already be reached via this slot */
71703 + tmp = *curr;
71704 + while (tmp && tmp != role)
71705 + tmp = tmp->next;
71706 + if (tmp == role) {
71707 + /* we don't need to add ourselves to this slot's chain */
71708 + return;
71709 + }
71710 + /* we need to add ourselves to this chain, two cases */
71711 + if (role->next == NULL) {
71712 + /* simple case, append the current chain to our role */
71713 + role->next = *curr;
71714 + *curr = role;
71715 + } else {
71716 + /* 1 -> 2 -> 3 -> 4
71717 + 2 -> 3 -> 4
71718 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71719 + */
71720 + /* trickier case: walk our role's chain until we find
71721 + the role for the start of the current slot's chain */
71722 + tmp = role;
71723 + tmp2 = *curr;
71724 + while (tmp->next && tmp->next != tmp2)
71725 + tmp = tmp->next;
71726 + if (tmp->next == tmp2) {
71727 + /* from example above, we found 3, so just
71728 + replace this slot's chain with ours */
71729 + *curr = role;
71730 + } else {
71731 + /* we didn't find a subset of our role's chain
71732 + in the current slot's chain, so append their
71733 + chain to ours, and set us as the first role in
71734 + the slot's chain
71735 +
71736 + we could fold this case with the case above,
71737 + but making it explicit for clarity
71738 + */
71739 + tmp->next = tmp2;
71740 + *curr = role;
71741 + }
71742 + }
71743 + }
71744 +
71745 + return;
71746 +}
71747 +
71748 +static void
71749 +insert_acl_role_label(struct acl_role_label *role)
71750 +{
71751 + int i;
71752 +
71753 + if (polstate->role_list == NULL) {
71754 + polstate->role_list = role;
71755 + role->prev = NULL;
71756 + } else {
71757 + role->prev = polstate->role_list;
71758 + polstate->role_list = role;
71759 + }
71760 +
71761 + /* used for hash chains */
71762 + role->next = NULL;
71763 +
71764 + if (role->roletype & GR_ROLE_DOMAIN) {
71765 + for (i = 0; i < role->domain_child_num; i++)
71766 + __insert_acl_role_label(role, role->domain_children[i]);
71767 + } else
71768 + __insert_acl_role_label(role, role->uidgid);
71769 +}
71770 +
71771 +static int
71772 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71773 +{
71774 + struct name_entry **curr, *nentry;
71775 + struct inodev_entry *ientry;
71776 + unsigned int len = strlen(name);
71777 + unsigned int key = full_name_hash(name, len);
71778 + unsigned int index = key % polstate->name_set.n_size;
71779 +
71780 + curr = &polstate->name_set.n_hash[index];
71781 +
71782 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71783 + curr = &((*curr)->next);
71784 +
71785 + if (*curr != NULL)
71786 + return 1;
71787 +
71788 + nentry = acl_alloc(sizeof (struct name_entry));
71789 + if (nentry == NULL)
71790 + return 0;
71791 + ientry = acl_alloc(sizeof (struct inodev_entry));
71792 + if (ientry == NULL)
71793 + return 0;
71794 + ientry->nentry = nentry;
71795 +
71796 + nentry->key = key;
71797 + nentry->name = name;
71798 + nentry->inode = inode;
71799 + nentry->device = device;
71800 + nentry->len = len;
71801 + nentry->deleted = deleted;
71802 +
71803 + nentry->prev = NULL;
71804 + curr = &polstate->name_set.n_hash[index];
71805 + if (*curr != NULL)
71806 + (*curr)->prev = nentry;
71807 + nentry->next = *curr;
71808 + *curr = nentry;
71809 +
71810 + /* insert us into the table searchable by inode/dev */
71811 + __insert_inodev_entry(polstate, ientry);
71812 +
71813 + return 1;
71814 +}
71815 +
71816 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71817 +
71818 +static void *
71819 +create_table(__u32 * len, int elementsize)
71820 +{
71821 + unsigned int table_sizes[] = {
71822 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71823 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71824 + 4194301, 8388593, 16777213, 33554393, 67108859
71825 + };
71826 + void *newtable = NULL;
71827 + unsigned int pwr = 0;
71828 +
71829 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71830 + table_sizes[pwr] <= *len)
71831 + pwr++;
71832 +
71833 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71834 + return newtable;
71835 +
71836 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71837 + newtable =
71838 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71839 + else
71840 + newtable = vmalloc(table_sizes[pwr] * elementsize);
71841 +
71842 + *len = table_sizes[pwr];
71843 +
71844 + return newtable;
71845 +}
71846 +
71847 +static int
71848 +init_variables(const struct gr_arg *arg, bool reload)
71849 +{
71850 + struct task_struct *reaper = init_pid_ns.child_reaper;
71851 + unsigned int stacksize;
71852 +
71853 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71854 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71855 + polstate->name_set.n_size = arg->role_db.num_objects;
71856 + polstate->inodev_set.i_size = arg->role_db.num_objects;
71857 +
71858 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71859 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71860 + return 1;
71861 +
71862 + if (!reload) {
71863 + if (!gr_init_uidset())
71864 + return 1;
71865 + }
71866 +
71867 + /* set up the stack that holds allocation info */
71868 +
71869 + stacksize = arg->role_db.num_pointers + 5;
71870 +
71871 + if (!acl_alloc_stack_init(stacksize))
71872 + return 1;
71873 +
71874 + if (!reload) {
71875 + /* grab reference for the real root dentry and vfsmount */
71876 + get_fs_root(reaper->fs, &gr_real_root);
71877 +
71878 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71879 + 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);
71880 +#endif
71881 +
71882 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71883 + if (fakefs_obj_rw == NULL)
71884 + return 1;
71885 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71886 +
71887 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71888 + if (fakefs_obj_rwx == NULL)
71889 + return 1;
71890 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71891 + }
71892 +
71893 + polstate->subj_map_set.s_hash =
71894 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71895 + polstate->acl_role_set.r_hash =
71896 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71897 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71898 + polstate->inodev_set.i_hash =
71899 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71900 +
71901 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71902 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71903 + return 1;
71904 +
71905 + memset(polstate->subj_map_set.s_hash, 0,
71906 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71907 + memset(polstate->acl_role_set.r_hash, 0,
71908 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71909 + memset(polstate->name_set.n_hash, 0,
71910 + sizeof (struct name_entry *) * polstate->name_set.n_size);
71911 + memset(polstate->inodev_set.i_hash, 0,
71912 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71913 +
71914 + return 0;
71915 +}
71916 +
71917 +/* free information not needed after startup
71918 + currently contains user->kernel pointer mappings for subjects
71919 +*/
71920 +
71921 +static void
71922 +free_init_variables(void)
71923 +{
71924 + __u32 i;
71925 +
71926 + if (polstate->subj_map_set.s_hash) {
71927 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71928 + if (polstate->subj_map_set.s_hash[i]) {
71929 + kfree(polstate->subj_map_set.s_hash[i]);
71930 + polstate->subj_map_set.s_hash[i] = NULL;
71931 + }
71932 + }
71933 +
71934 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71935 + PAGE_SIZE)
71936 + kfree(polstate->subj_map_set.s_hash);
71937 + else
71938 + vfree(polstate->subj_map_set.s_hash);
71939 + }
71940 +
71941 + return;
71942 +}
71943 +
71944 +static void
71945 +free_variables(bool reload)
71946 +{
71947 + struct acl_subject_label *s;
71948 + struct acl_role_label *r;
71949 + struct task_struct *task, *task2;
71950 + unsigned int x;
71951 +
71952 + if (!reload) {
71953 + gr_clear_learn_entries();
71954 +
71955 + read_lock(&tasklist_lock);
71956 + do_each_thread(task2, task) {
71957 + task->acl_sp_role = 0;
71958 + task->acl_role_id = 0;
71959 + task->inherited = 0;
71960 + task->acl = NULL;
71961 + task->role = NULL;
71962 + } while_each_thread(task2, task);
71963 + read_unlock(&tasklist_lock);
71964 +
71965 + kfree(fakefs_obj_rw);
71966 + fakefs_obj_rw = NULL;
71967 + kfree(fakefs_obj_rwx);
71968 + fakefs_obj_rwx = NULL;
71969 +
71970 + /* release the reference to the real root dentry and vfsmount */
71971 + path_put(&gr_real_root);
71972 + memset(&gr_real_root, 0, sizeof(gr_real_root));
71973 + }
71974 +
71975 + /* free all object hash tables */
71976 +
71977 + FOR_EACH_ROLE_START(r)
71978 + if (r->subj_hash == NULL)
71979 + goto next_role;
71980 + FOR_EACH_SUBJECT_START(r, s, x)
71981 + if (s->obj_hash == NULL)
71982 + break;
71983 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71984 + kfree(s->obj_hash);
71985 + else
71986 + vfree(s->obj_hash);
71987 + FOR_EACH_SUBJECT_END(s, x)
71988 + FOR_EACH_NESTED_SUBJECT_START(r, s)
71989 + if (s->obj_hash == NULL)
71990 + break;
71991 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71992 + kfree(s->obj_hash);
71993 + else
71994 + vfree(s->obj_hash);
71995 + FOR_EACH_NESTED_SUBJECT_END(s)
71996 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71997 + kfree(r->subj_hash);
71998 + else
71999 + vfree(r->subj_hash);
72000 + r->subj_hash = NULL;
72001 +next_role:
72002 + FOR_EACH_ROLE_END(r)
72003 +
72004 + acl_free_all();
72005 +
72006 + if (polstate->acl_role_set.r_hash) {
72007 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
72008 + PAGE_SIZE)
72009 + kfree(polstate->acl_role_set.r_hash);
72010 + else
72011 + vfree(polstate->acl_role_set.r_hash);
72012 + }
72013 + if (polstate->name_set.n_hash) {
72014 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
72015 + PAGE_SIZE)
72016 + kfree(polstate->name_set.n_hash);
72017 + else
72018 + vfree(polstate->name_set.n_hash);
72019 + }
72020 +
72021 + if (polstate->inodev_set.i_hash) {
72022 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
72023 + PAGE_SIZE)
72024 + kfree(polstate->inodev_set.i_hash);
72025 + else
72026 + vfree(polstate->inodev_set.i_hash);
72027 + }
72028 +
72029 + if (!reload)
72030 + gr_free_uidset();
72031 +
72032 + memset(&polstate->name_set, 0, sizeof (struct name_db));
72033 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
72034 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
72035 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
72036 +
72037 + polstate->default_role = NULL;
72038 + polstate->kernel_role = NULL;
72039 + polstate->role_list = NULL;
72040 +
72041 + return;
72042 +}
72043 +
72044 +static struct acl_subject_label *
72045 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
72046 +
72047 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
72048 +{
72049 + unsigned int len = strnlen_user(*name, maxlen);
72050 + char *tmp;
72051 +
72052 + if (!len || len >= maxlen)
72053 + return -EINVAL;
72054 +
72055 + if ((tmp = (char *) acl_alloc(len)) == NULL)
72056 + return -ENOMEM;
72057 +
72058 + if (copy_from_user(tmp, *name, len))
72059 + return -EFAULT;
72060 +
72061 + tmp[len-1] = '\0';
72062 + *name = tmp;
72063 +
72064 + return 0;
72065 +}
72066 +
72067 +static int
72068 +copy_user_glob(struct acl_object_label *obj)
72069 +{
72070 + struct acl_object_label *g_tmp, **guser;
72071 + int error;
72072 +
72073 + if (obj->globbed == NULL)
72074 + return 0;
72075 +
72076 + guser = &obj->globbed;
72077 + while (*guser) {
72078 + g_tmp = (struct acl_object_label *)
72079 + acl_alloc(sizeof (struct acl_object_label));
72080 + if (g_tmp == NULL)
72081 + return -ENOMEM;
72082 +
72083 + if (copy_acl_object_label(g_tmp, *guser))
72084 + return -EFAULT;
72085 +
72086 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
72087 + if (error)
72088 + return error;
72089 +
72090 + *guser = g_tmp;
72091 + guser = &(g_tmp->next);
72092 + }
72093 +
72094 + return 0;
72095 +}
72096 +
72097 +static int
72098 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
72099 + struct acl_role_label *role)
72100 +{
72101 + struct acl_object_label *o_tmp;
72102 + int ret;
72103 +
72104 + while (userp) {
72105 + if ((o_tmp = (struct acl_object_label *)
72106 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
72107 + return -ENOMEM;
72108 +
72109 + if (copy_acl_object_label(o_tmp, userp))
72110 + return -EFAULT;
72111 +
72112 + userp = o_tmp->prev;
72113 +
72114 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
72115 + if (ret)
72116 + return ret;
72117 +
72118 + insert_acl_obj_label(o_tmp, subj);
72119 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
72120 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
72121 + return -ENOMEM;
72122 +
72123 + ret = copy_user_glob(o_tmp);
72124 + if (ret)
72125 + return ret;
72126 +
72127 + if (o_tmp->nested) {
72128 + int already_copied;
72129 +
72130 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
72131 + if (IS_ERR(o_tmp->nested))
72132 + return PTR_ERR(o_tmp->nested);
72133 +
72134 + /* insert into nested subject list if we haven't copied this one yet
72135 + to prevent duplicate entries */
72136 + if (!already_copied) {
72137 + o_tmp->nested->next = role->hash->first;
72138 + role->hash->first = o_tmp->nested;
72139 + }
72140 + }
72141 + }
72142 +
72143 + return 0;
72144 +}
72145 +
72146 +static __u32
72147 +count_user_subjs(struct acl_subject_label *userp)
72148 +{
72149 + struct acl_subject_label s_tmp;
72150 + __u32 num = 0;
72151 +
72152 + while (userp) {
72153 + if (copy_acl_subject_label(&s_tmp, userp))
72154 + break;
72155 +
72156 + userp = s_tmp.prev;
72157 + }
72158 +
72159 + return num;
72160 +}
72161 +
72162 +static int
72163 +copy_user_allowedips(struct acl_role_label *rolep)
72164 +{
72165 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
72166 +
72167 + ruserip = rolep->allowed_ips;
72168 +
72169 + while (ruserip) {
72170 + rlast = rtmp;
72171 +
72172 + if ((rtmp = (struct role_allowed_ip *)
72173 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
72174 + return -ENOMEM;
72175 +
72176 + if (copy_role_allowed_ip(rtmp, ruserip))
72177 + return -EFAULT;
72178 +
72179 + ruserip = rtmp->prev;
72180 +
72181 + if (!rlast) {
72182 + rtmp->prev = NULL;
72183 + rolep->allowed_ips = rtmp;
72184 + } else {
72185 + rlast->next = rtmp;
72186 + rtmp->prev = rlast;
72187 + }
72188 +
72189 + if (!ruserip)
72190 + rtmp->next = NULL;
72191 + }
72192 +
72193 + return 0;
72194 +}
72195 +
72196 +static int
72197 +copy_user_transitions(struct acl_role_label *rolep)
72198 +{
72199 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
72200 + int error;
72201 +
72202 + rusertp = rolep->transitions;
72203 +
72204 + while (rusertp) {
72205 + rlast = rtmp;
72206 +
72207 + if ((rtmp = (struct role_transition *)
72208 + acl_alloc(sizeof (struct role_transition))) == NULL)
72209 + return -ENOMEM;
72210 +
72211 + if (copy_role_transition(rtmp, rusertp))
72212 + return -EFAULT;
72213 +
72214 + rusertp = rtmp->prev;
72215 +
72216 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72217 + if (error)
72218 + return error;
72219 +
72220 + if (!rlast) {
72221 + rtmp->prev = NULL;
72222 + rolep->transitions = rtmp;
72223 + } else {
72224 + rlast->next = rtmp;
72225 + rtmp->prev = rlast;
72226 + }
72227 +
72228 + if (!rusertp)
72229 + rtmp->next = NULL;
72230 + }
72231 +
72232 + return 0;
72233 +}
72234 +
72235 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
72236 +{
72237 + struct acl_object_label o_tmp;
72238 + __u32 num = 0;
72239 +
72240 + while (userp) {
72241 + if (copy_acl_object_label(&o_tmp, userp))
72242 + break;
72243 +
72244 + userp = o_tmp.prev;
72245 + num++;
72246 + }
72247 +
72248 + return num;
72249 +}
72250 +
72251 +static struct acl_subject_label *
72252 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72253 +{
72254 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72255 + __u32 num_objs;
72256 + struct acl_ip_label **i_tmp, *i_utmp2;
72257 + struct gr_hash_struct ghash;
72258 + struct subject_map *subjmap;
72259 + unsigned int i_num;
72260 + int err;
72261 +
72262 + if (already_copied != NULL)
72263 + *already_copied = 0;
72264 +
72265 + s_tmp = lookup_subject_map(userp);
72266 +
72267 + /* we've already copied this subject into the kernel, just return
72268 + the reference to it, and don't copy it over again
72269 + */
72270 + if (s_tmp) {
72271 + if (already_copied != NULL)
72272 + *already_copied = 1;
72273 + return(s_tmp);
72274 + }
72275 +
72276 + if ((s_tmp = (struct acl_subject_label *)
72277 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72278 + return ERR_PTR(-ENOMEM);
72279 +
72280 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72281 + if (subjmap == NULL)
72282 + return ERR_PTR(-ENOMEM);
72283 +
72284 + subjmap->user = userp;
72285 + subjmap->kernel = s_tmp;
72286 + insert_subj_map_entry(subjmap);
72287 +
72288 + if (copy_acl_subject_label(s_tmp, userp))
72289 + return ERR_PTR(-EFAULT);
72290 +
72291 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72292 + if (err)
72293 + return ERR_PTR(err);
72294 +
72295 + if (!strcmp(s_tmp->filename, "/"))
72296 + role->root_label = s_tmp;
72297 +
72298 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72299 + return ERR_PTR(-EFAULT);
72300 +
72301 + /* copy user and group transition tables */
72302 +
72303 + if (s_tmp->user_trans_num) {
72304 + uid_t *uidlist;
72305 +
72306 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72307 + if (uidlist == NULL)
72308 + return ERR_PTR(-ENOMEM);
72309 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72310 + return ERR_PTR(-EFAULT);
72311 +
72312 + s_tmp->user_transitions = uidlist;
72313 + }
72314 +
72315 + if (s_tmp->group_trans_num) {
72316 + gid_t *gidlist;
72317 +
72318 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72319 + if (gidlist == NULL)
72320 + return ERR_PTR(-ENOMEM);
72321 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72322 + return ERR_PTR(-EFAULT);
72323 +
72324 + s_tmp->group_transitions = gidlist;
72325 + }
72326 +
72327 + /* set up object hash table */
72328 + num_objs = count_user_objs(ghash.first);
72329 +
72330 + s_tmp->obj_hash_size = num_objs;
72331 + s_tmp->obj_hash =
72332 + (struct acl_object_label **)
72333 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72334 +
72335 + if (!s_tmp->obj_hash)
72336 + return ERR_PTR(-ENOMEM);
72337 +
72338 + memset(s_tmp->obj_hash, 0,
72339 + s_tmp->obj_hash_size *
72340 + sizeof (struct acl_object_label *));
72341 +
72342 + /* add in objects */
72343 + err = copy_user_objs(ghash.first, s_tmp, role);
72344 +
72345 + if (err)
72346 + return ERR_PTR(err);
72347 +
72348 + /* set pointer for parent subject */
72349 + if (s_tmp->parent_subject) {
72350 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72351 +
72352 + if (IS_ERR(s_tmp2))
72353 + return s_tmp2;
72354 +
72355 + s_tmp->parent_subject = s_tmp2;
72356 + }
72357 +
72358 + /* add in ip acls */
72359 +
72360 + if (!s_tmp->ip_num) {
72361 + s_tmp->ips = NULL;
72362 + goto insert;
72363 + }
72364 +
72365 + i_tmp =
72366 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72367 + sizeof (struct acl_ip_label *));
72368 +
72369 + if (!i_tmp)
72370 + return ERR_PTR(-ENOMEM);
72371 +
72372 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72373 + *(i_tmp + i_num) =
72374 + (struct acl_ip_label *)
72375 + acl_alloc(sizeof (struct acl_ip_label));
72376 + if (!*(i_tmp + i_num))
72377 + return ERR_PTR(-ENOMEM);
72378 +
72379 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72380 + return ERR_PTR(-EFAULT);
72381 +
72382 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72383 + return ERR_PTR(-EFAULT);
72384 +
72385 + if ((*(i_tmp + i_num))->iface == NULL)
72386 + continue;
72387 +
72388 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72389 + if (err)
72390 + return ERR_PTR(err);
72391 + }
72392 +
72393 + s_tmp->ips = i_tmp;
72394 +
72395 +insert:
72396 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72397 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72398 + return ERR_PTR(-ENOMEM);
72399 +
72400 + return s_tmp;
72401 +}
72402 +
72403 +static int
72404 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72405 +{
72406 + struct acl_subject_label s_pre;
72407 + struct acl_subject_label * ret;
72408 + int err;
72409 +
72410 + while (userp) {
72411 + if (copy_acl_subject_label(&s_pre, userp))
72412 + return -EFAULT;
72413 +
72414 + ret = do_copy_user_subj(userp, role, NULL);
72415 +
72416 + err = PTR_ERR(ret);
72417 + if (IS_ERR(ret))
72418 + return err;
72419 +
72420 + insert_acl_subj_label(ret, role);
72421 +
72422 + userp = s_pre.prev;
72423 + }
72424 +
72425 + return 0;
72426 +}
72427 +
72428 +static int
72429 +copy_user_acl(struct gr_arg *arg)
72430 +{
72431 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72432 + struct acl_subject_label *subj_list;
72433 + struct sprole_pw *sptmp;
72434 + struct gr_hash_struct *ghash;
72435 + uid_t *domainlist;
72436 + unsigned int r_num;
72437 + int err = 0;
72438 + __u16 i;
72439 + __u32 num_subjs;
72440 +
72441 + /* we need a default and kernel role */
72442 + if (arg->role_db.num_roles < 2)
72443 + return -EINVAL;
72444 +
72445 + /* copy special role authentication info from userspace */
72446 +
72447 + polstate->num_sprole_pws = arg->num_sprole_pws;
72448 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72449 +
72450 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72451 + return -ENOMEM;
72452 +
72453 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72454 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72455 + if (!sptmp)
72456 + return -ENOMEM;
72457 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72458 + return -EFAULT;
72459 +
72460 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72461 + if (err)
72462 + return err;
72463 +
72464 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72465 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72466 +#endif
72467 +
72468 + polstate->acl_special_roles[i] = sptmp;
72469 + }
72470 +
72471 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72472 +
72473 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72474 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
72475 +
72476 + if (!r_tmp)
72477 + return -ENOMEM;
72478 +
72479 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72480 + return -EFAULT;
72481 +
72482 + if (copy_acl_role_label(r_tmp, r_utmp2))
72483 + return -EFAULT;
72484 +
72485 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72486 + if (err)
72487 + return err;
72488 +
72489 + if (!strcmp(r_tmp->rolename, "default")
72490 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72491 + polstate->default_role = r_tmp;
72492 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72493 + polstate->kernel_role = r_tmp;
72494 + }
72495 +
72496 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72497 + return -ENOMEM;
72498 +
72499 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
72500 + return -EFAULT;
72501 +
72502 + r_tmp->hash = ghash;
72503 +
72504 + num_subjs = count_user_subjs(r_tmp->hash->first);
72505 +
72506 + r_tmp->subj_hash_size = num_subjs;
72507 + r_tmp->subj_hash =
72508 + (struct acl_subject_label **)
72509 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72510 +
72511 + if (!r_tmp->subj_hash)
72512 + return -ENOMEM;
72513 +
72514 + err = copy_user_allowedips(r_tmp);
72515 + if (err)
72516 + return err;
72517 +
72518 + /* copy domain info */
72519 + if (r_tmp->domain_children != NULL) {
72520 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72521 + if (domainlist == NULL)
72522 + return -ENOMEM;
72523 +
72524 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72525 + return -EFAULT;
72526 +
72527 + r_tmp->domain_children = domainlist;
72528 + }
72529 +
72530 + err = copy_user_transitions(r_tmp);
72531 + if (err)
72532 + return err;
72533 +
72534 + memset(r_tmp->subj_hash, 0,
72535 + r_tmp->subj_hash_size *
72536 + sizeof (struct acl_subject_label *));
72537 +
72538 + /* acquire the list of subjects, then NULL out
72539 + the list prior to parsing the subjects for this role,
72540 + as during this parsing the list is replaced with a list
72541 + of *nested* subjects for the role
72542 + */
72543 + subj_list = r_tmp->hash->first;
72544 +
72545 + /* set nested subject list to null */
72546 + r_tmp->hash->first = NULL;
72547 +
72548 + err = copy_user_subjs(subj_list, r_tmp);
72549 +
72550 + if (err)
72551 + return err;
72552 +
72553 + insert_acl_role_label(r_tmp);
72554 + }
72555 +
72556 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72557 + return -EINVAL;
72558 +
72559 + return err;
72560 +}
72561 +
72562 +static int gracl_reload_apply_policies(void *reload)
72563 +{
72564 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72565 + struct task_struct *task, *task2;
72566 + struct acl_role_label *role, *rtmp;
72567 + struct acl_subject_label *subj;
72568 + const struct cred *cred;
72569 + int role_applied;
72570 + int ret = 0;
72571 +
72572 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72573 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72574 +
72575 + /* first make sure we'll be able to apply the new policy cleanly */
72576 + do_each_thread(task2, task) {
72577 + if (task->exec_file == NULL)
72578 + continue;
72579 + role_applied = 0;
72580 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72581 + /* preserve special roles */
72582 + FOR_EACH_ROLE_START(role)
72583 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72584 + rtmp = task->role;
72585 + task->role = role;
72586 + role_applied = 1;
72587 + break;
72588 + }
72589 + FOR_EACH_ROLE_END(role)
72590 + }
72591 + if (!role_applied) {
72592 + cred = __task_cred(task);
72593 + rtmp = task->role;
72594 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72595 + }
72596 + /* this handles non-nested inherited subjects, nested subjects will still
72597 + be dropped currently */
72598 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72599 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72600 + /* change the role back so that we've made no modifications to the policy */
72601 + task->role = rtmp;
72602 +
72603 + if (subj == NULL || task->tmpacl == NULL) {
72604 + ret = -EINVAL;
72605 + goto out;
72606 + }
72607 + } while_each_thread(task2, task);
72608 +
72609 + /* now actually apply the policy */
72610 +
72611 + do_each_thread(task2, task) {
72612 + if (task->exec_file) {
72613 + role_applied = 0;
72614 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72615 + /* preserve special roles */
72616 + FOR_EACH_ROLE_START(role)
72617 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72618 + task->role = role;
72619 + role_applied = 1;
72620 + break;
72621 + }
72622 + FOR_EACH_ROLE_END(role)
72623 + }
72624 + if (!role_applied) {
72625 + cred = __task_cred(task);
72626 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72627 + }
72628 + /* this handles non-nested inherited subjects, nested subjects will still
72629 + be dropped currently */
72630 + if (!reload_state->oldmode && task->inherited)
72631 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72632 + else {
72633 + /* looked up and tagged to the task previously */
72634 + subj = task->tmpacl;
72635 + }
72636 + /* subj will be non-null */
72637 + __gr_apply_subject_to_task(polstate, task, subj);
72638 + if (reload_state->oldmode) {
72639 + task->acl_role_id = 0;
72640 + task->acl_sp_role = 0;
72641 + task->inherited = 0;
72642 + }
72643 + } else {
72644 + // it's a kernel process
72645 + task->role = polstate->kernel_role;
72646 + task->acl = polstate->kernel_role->root_label;
72647 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72648 + task->acl->mode &= ~GR_PROCFIND;
72649 +#endif
72650 + }
72651 + } while_each_thread(task2, task);
72652 +
72653 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72654 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72655 +
72656 +out:
72657 +
72658 + return ret;
72659 +}
72660 +
72661 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72662 +{
72663 + struct gr_reload_state new_reload_state = { };
72664 + int err;
72665 +
72666 + new_reload_state.oldpolicy_ptr = polstate;
72667 + new_reload_state.oldalloc_ptr = current_alloc_state;
72668 + new_reload_state.oldmode = oldmode;
72669 +
72670 + current_alloc_state = &new_reload_state.newalloc;
72671 + polstate = &new_reload_state.newpolicy;
72672 +
72673 + /* everything relevant is now saved off, copy in the new policy */
72674 + if (init_variables(args, true)) {
72675 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72676 + err = -ENOMEM;
72677 + goto error;
72678 + }
72679 +
72680 + err = copy_user_acl(args);
72681 + free_init_variables();
72682 + if (err)
72683 + goto error;
72684 + /* the new policy is copied in, with the old policy available via saved_state
72685 + first go through applying roles, making sure to preserve special roles
72686 + then apply new subjects, making sure to preserve inherited and nested subjects,
72687 + though currently only inherited subjects will be preserved
72688 + */
72689 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72690 + if (err)
72691 + goto error;
72692 +
72693 + /* we've now applied the new policy, so restore the old policy state to free it */
72694 + polstate = &new_reload_state.oldpolicy;
72695 + current_alloc_state = &new_reload_state.oldalloc;
72696 + free_variables(true);
72697 +
72698 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72699 + to running_polstate/current_alloc_state inside stop_machine
72700 + */
72701 + err = 0;
72702 + goto out;
72703 +error:
72704 + /* on error of loading the new policy, we'll just keep the previous
72705 + policy set around
72706 + */
72707 + free_variables(true);
72708 +
72709 + /* doesn't affect runtime, but maintains consistent state */
72710 +out:
72711 + polstate = new_reload_state.oldpolicy_ptr;
72712 + current_alloc_state = new_reload_state.oldalloc_ptr;
72713 +
72714 + return err;
72715 +}
72716 +
72717 +static int
72718 +gracl_init(struct gr_arg *args)
72719 +{
72720 + int error = 0;
72721 +
72722 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72723 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72724 +
72725 + if (init_variables(args, false)) {
72726 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72727 + error = -ENOMEM;
72728 + goto out;
72729 + }
72730 +
72731 + error = copy_user_acl(args);
72732 + free_init_variables();
72733 + if (error)
72734 + goto out;
72735 +
72736 + error = gr_set_acls(0);
72737 + if (error)
72738 + goto out;
72739 +
72740 + gr_enable_rbac_system();
72741 +
72742 + return 0;
72743 +
72744 +out:
72745 + free_variables(false);
72746 + return error;
72747 +}
72748 +
72749 +static int
72750 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72751 + unsigned char **sum)
72752 +{
72753 + struct acl_role_label *r;
72754 + struct role_allowed_ip *ipp;
72755 + struct role_transition *trans;
72756 + unsigned int i;
72757 + int found = 0;
72758 + u32 curr_ip = current->signal->curr_ip;
72759 +
72760 + current->signal->saved_ip = curr_ip;
72761 +
72762 + /* check transition table */
72763 +
72764 + for (trans = current->role->transitions; trans; trans = trans->next) {
72765 + if (!strcmp(rolename, trans->rolename)) {
72766 + found = 1;
72767 + break;
72768 + }
72769 + }
72770 +
72771 + if (!found)
72772 + return 0;
72773 +
72774 + /* handle special roles that do not require authentication
72775 + and check ip */
72776 +
72777 + FOR_EACH_ROLE_START(r)
72778 + if (!strcmp(rolename, r->rolename) &&
72779 + (r->roletype & GR_ROLE_SPECIAL)) {
72780 + found = 0;
72781 + if (r->allowed_ips != NULL) {
72782 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72783 + if ((ntohl(curr_ip) & ipp->netmask) ==
72784 + (ntohl(ipp->addr) & ipp->netmask))
72785 + found = 1;
72786 + }
72787 + } else
72788 + found = 2;
72789 + if (!found)
72790 + return 0;
72791 +
72792 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72793 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72794 + *salt = NULL;
72795 + *sum = NULL;
72796 + return 1;
72797 + }
72798 + }
72799 + FOR_EACH_ROLE_END(r)
72800 +
72801 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72802 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72803 + *salt = polstate->acl_special_roles[i]->salt;
72804 + *sum = polstate->acl_special_roles[i]->sum;
72805 + return 1;
72806 + }
72807 + }
72808 +
72809 + return 0;
72810 +}
72811 +
72812 +int gr_check_secure_terminal(struct task_struct *task)
72813 +{
72814 + struct task_struct *p, *p2, *p3;
72815 + struct files_struct *files;
72816 + struct fdtable *fdt;
72817 + struct file *our_file = NULL, *file;
72818 + int i;
72819 +
72820 + if (task->signal->tty == NULL)
72821 + return 1;
72822 +
72823 + files = get_files_struct(task);
72824 + if (files != NULL) {
72825 + rcu_read_lock();
72826 + fdt = files_fdtable(files);
72827 + for (i=0; i < fdt->max_fds; i++) {
72828 + file = fcheck_files(files, i);
72829 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72830 + get_file(file);
72831 + our_file = file;
72832 + }
72833 + }
72834 + rcu_read_unlock();
72835 + put_files_struct(files);
72836 + }
72837 +
72838 + if (our_file == NULL)
72839 + return 1;
72840 +
72841 + read_lock(&tasklist_lock);
72842 + do_each_thread(p2, p) {
72843 + files = get_files_struct(p);
72844 + if (files == NULL ||
72845 + (p->signal && p->signal->tty == task->signal->tty)) {
72846 + if (files != NULL)
72847 + put_files_struct(files);
72848 + continue;
72849 + }
72850 + rcu_read_lock();
72851 + fdt = files_fdtable(files);
72852 + for (i=0; i < fdt->max_fds; i++) {
72853 + file = fcheck_files(files, i);
72854 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72855 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72856 + p3 = task;
72857 + while (task_pid_nr(p3) > 0) {
72858 + if (p3 == p)
72859 + break;
72860 + p3 = p3->real_parent;
72861 + }
72862 + if (p3 == p)
72863 + break;
72864 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72865 + gr_handle_alertkill(p);
72866 + rcu_read_unlock();
72867 + put_files_struct(files);
72868 + read_unlock(&tasklist_lock);
72869 + fput(our_file);
72870 + return 0;
72871 + }
72872 + }
72873 + rcu_read_unlock();
72874 + put_files_struct(files);
72875 + } while_each_thread(p2, p);
72876 + read_unlock(&tasklist_lock);
72877 +
72878 + fput(our_file);
72879 + return 1;
72880 +}
72881 +
72882 +ssize_t
72883 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72884 +{
72885 + struct gr_arg_wrapper uwrap;
72886 + unsigned char *sprole_salt = NULL;
72887 + unsigned char *sprole_sum = NULL;
72888 + int error = 0;
72889 + int error2 = 0;
72890 + size_t req_count = 0;
72891 + unsigned char oldmode = 0;
72892 +
72893 + mutex_lock(&gr_dev_mutex);
72894 +
72895 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72896 + error = -EPERM;
72897 + goto out;
72898 + }
72899 +
72900 +#ifdef CONFIG_COMPAT
72901 + pax_open_kernel();
72902 + if (is_compat_task()) {
72903 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72904 + copy_gr_arg = &copy_gr_arg_compat;
72905 + copy_acl_object_label = &copy_acl_object_label_compat;
72906 + copy_acl_subject_label = &copy_acl_subject_label_compat;
72907 + copy_acl_role_label = &copy_acl_role_label_compat;
72908 + copy_acl_ip_label = &copy_acl_ip_label_compat;
72909 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72910 + copy_role_transition = &copy_role_transition_compat;
72911 + copy_sprole_pw = &copy_sprole_pw_compat;
72912 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72913 + copy_pointer_from_array = &copy_pointer_from_array_compat;
72914 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72915 + } else {
72916 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72917 + copy_gr_arg = &copy_gr_arg_normal;
72918 + copy_acl_object_label = &copy_acl_object_label_normal;
72919 + copy_acl_subject_label = &copy_acl_subject_label_normal;
72920 + copy_acl_role_label = &copy_acl_role_label_normal;
72921 + copy_acl_ip_label = &copy_acl_ip_label_normal;
72922 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72923 + copy_role_transition = &copy_role_transition_normal;
72924 + copy_sprole_pw = &copy_sprole_pw_normal;
72925 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72926 + copy_pointer_from_array = &copy_pointer_from_array_normal;
72927 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72928 + }
72929 + pax_close_kernel();
72930 +#endif
72931 +
72932 + req_count = get_gr_arg_wrapper_size();
72933 +
72934 + if (count != req_count) {
72935 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72936 + error = -EINVAL;
72937 + goto out;
72938 + }
72939 +
72940 +
72941 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72942 + gr_auth_expires = 0;
72943 + gr_auth_attempts = 0;
72944 + }
72945 +
72946 + error = copy_gr_arg_wrapper(buf, &uwrap);
72947 + if (error)
72948 + goto out;
72949 +
72950 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
72951 + if (error)
72952 + goto out;
72953 +
72954 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72955 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72956 + time_after(gr_auth_expires, get_seconds())) {
72957 + error = -EBUSY;
72958 + goto out;
72959 + }
72960 +
72961 + /* if non-root trying to do anything other than use a special role,
72962 + do not attempt authentication, do not count towards authentication
72963 + locking
72964 + */
72965 +
72966 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72967 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72968 + gr_is_global_nonroot(current_uid())) {
72969 + error = -EPERM;
72970 + goto out;
72971 + }
72972 +
72973 + /* ensure pw and special role name are null terminated */
72974 +
72975 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72976 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72977 +
72978 + /* Okay.
72979 + * We have our enough of the argument structure..(we have yet
72980 + * to copy_from_user the tables themselves) . Copy the tables
72981 + * only if we need them, i.e. for loading operations. */
72982 +
72983 + switch (gr_usermode.mode) {
72984 + case GR_STATUS:
72985 + if (gr_acl_is_enabled()) {
72986 + error = 1;
72987 + if (!gr_check_secure_terminal(current))
72988 + error = 3;
72989 + } else
72990 + error = 2;
72991 + goto out;
72992 + case GR_SHUTDOWN:
72993 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72994 + stop_machine(gr_rbac_disable, NULL, NULL);
72995 + free_variables(false);
72996 + memset(&gr_usermode, 0, sizeof(gr_usermode));
72997 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72998 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72999 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
73000 + } else if (gr_acl_is_enabled()) {
73001 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
73002 + error = -EPERM;
73003 + } else {
73004 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
73005 + error = -EAGAIN;
73006 + }
73007 + break;
73008 + case GR_ENABLE:
73009 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
73010 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
73011 + else {
73012 + if (gr_acl_is_enabled())
73013 + error = -EAGAIN;
73014 + else
73015 + error = error2;
73016 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
73017 + }
73018 + break;
73019 + case GR_OLDRELOAD:
73020 + oldmode = 1;
73021 + case GR_RELOAD:
73022 + if (!gr_acl_is_enabled()) {
73023 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
73024 + error = -EAGAIN;
73025 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73026 + error2 = gracl_reload(&gr_usermode, oldmode);
73027 + if (!error2)
73028 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
73029 + else {
73030 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73031 + error = error2;
73032 + }
73033 + } else {
73034 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
73035 + error = -EPERM;
73036 + }
73037 + break;
73038 + case GR_SEGVMOD:
73039 + if (unlikely(!gr_acl_is_enabled())) {
73040 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
73041 + error = -EAGAIN;
73042 + break;
73043 + }
73044 +
73045 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
73046 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
73047 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
73048 + struct acl_subject_label *segvacl;
73049 + segvacl =
73050 + lookup_acl_subj_label(gr_usermode.segv_inode,
73051 + gr_usermode.segv_device,
73052 + current->role);
73053 + if (segvacl) {
73054 + segvacl->crashes = 0;
73055 + segvacl->expires = 0;
73056 + }
73057 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
73058 + gr_remove_uid(gr_usermode.segv_uid);
73059 + }
73060 + } else {
73061 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
73062 + error = -EPERM;
73063 + }
73064 + break;
73065 + case GR_SPROLE:
73066 + case GR_SPROLEPAM:
73067 + if (unlikely(!gr_acl_is_enabled())) {
73068 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
73069 + error = -EAGAIN;
73070 + break;
73071 + }
73072 +
73073 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
73074 + current->role->expires = 0;
73075 + current->role->auth_attempts = 0;
73076 + }
73077 +
73078 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73079 + time_after(current->role->expires, get_seconds())) {
73080 + error = -EBUSY;
73081 + goto out;
73082 + }
73083 +
73084 + if (lookup_special_role_auth
73085 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
73086 + && ((!sprole_salt && !sprole_sum)
73087 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
73088 + char *p = "";
73089 + assign_special_role(gr_usermode.sp_role);
73090 + read_lock(&tasklist_lock);
73091 + if (current->real_parent)
73092 + p = current->real_parent->role->rolename;
73093 + read_unlock(&tasklist_lock);
73094 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
73095 + p, acl_sp_role_value);
73096 + } else {
73097 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
73098 + error = -EPERM;
73099 + if(!(current->role->auth_attempts++))
73100 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73101 +
73102 + goto out;
73103 + }
73104 + break;
73105 + case GR_UNSPROLE:
73106 + if (unlikely(!gr_acl_is_enabled())) {
73107 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
73108 + error = -EAGAIN;
73109 + break;
73110 + }
73111 +
73112 + if (current->role->roletype & GR_ROLE_SPECIAL) {
73113 + char *p = "";
73114 + int i = 0;
73115 +
73116 + read_lock(&tasklist_lock);
73117 + if (current->real_parent) {
73118 + p = current->real_parent->role->rolename;
73119 + i = current->real_parent->acl_role_id;
73120 + }
73121 + read_unlock(&tasklist_lock);
73122 +
73123 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
73124 + gr_set_acls(1);
73125 + } else {
73126 + error = -EPERM;
73127 + goto out;
73128 + }
73129 + break;
73130 + default:
73131 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
73132 + error = -EINVAL;
73133 + break;
73134 + }
73135 +
73136 + if (error != -EPERM)
73137 + goto out;
73138 +
73139 + if(!(gr_auth_attempts++))
73140 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73141 +
73142 + out:
73143 + mutex_unlock(&gr_dev_mutex);
73144 +
73145 + if (!error)
73146 + error = req_count;
73147 +
73148 + return error;
73149 +}
73150 +
73151 +int
73152 +gr_set_acls(const int type)
73153 +{
73154 + struct task_struct *task, *task2;
73155 + struct acl_role_label *role = current->role;
73156 + struct acl_subject_label *subj;
73157 + __u16 acl_role_id = current->acl_role_id;
73158 + const struct cred *cred;
73159 + int ret;
73160 +
73161 + rcu_read_lock();
73162 + read_lock(&tasklist_lock);
73163 + read_lock(&grsec_exec_file_lock);
73164 + do_each_thread(task2, task) {
73165 + /* check to see if we're called from the exit handler,
73166 + if so, only replace ACLs that have inherited the admin
73167 + ACL */
73168 +
73169 + if (type && (task->role != role ||
73170 + task->acl_role_id != acl_role_id))
73171 + continue;
73172 +
73173 + task->acl_role_id = 0;
73174 + task->acl_sp_role = 0;
73175 + task->inherited = 0;
73176 +
73177 + if (task->exec_file) {
73178 + cred = __task_cred(task);
73179 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
73180 + subj = __gr_get_subject_for_task(polstate, task, NULL);
73181 + if (subj == NULL) {
73182 + ret = -EINVAL;
73183 + read_unlock(&grsec_exec_file_lock);
73184 + read_unlock(&tasklist_lock);
73185 + rcu_read_unlock();
73186 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
73187 + return ret;
73188 + }
73189 + __gr_apply_subject_to_task(polstate, task, subj);
73190 + } else {
73191 + // it's a kernel process
73192 + task->role = polstate->kernel_role;
73193 + task->acl = polstate->kernel_role->root_label;
73194 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73195 + task->acl->mode &= ~GR_PROCFIND;
73196 +#endif
73197 + }
73198 + } while_each_thread(task2, task);
73199 + read_unlock(&grsec_exec_file_lock);
73200 + read_unlock(&tasklist_lock);
73201 + rcu_read_unlock();
73202 +
73203 + return 0;
73204 +}
73205 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73206 new file mode 100644
73207 index 0000000..39645c9
73208 --- /dev/null
73209 +++ b/grsecurity/gracl_res.c
73210 @@ -0,0 +1,68 @@
73211 +#include <linux/kernel.h>
73212 +#include <linux/sched.h>
73213 +#include <linux/gracl.h>
73214 +#include <linux/grinternal.h>
73215 +
73216 +static const char *restab_log[] = {
73217 + [RLIMIT_CPU] = "RLIMIT_CPU",
73218 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73219 + [RLIMIT_DATA] = "RLIMIT_DATA",
73220 + [RLIMIT_STACK] = "RLIMIT_STACK",
73221 + [RLIMIT_CORE] = "RLIMIT_CORE",
73222 + [RLIMIT_RSS] = "RLIMIT_RSS",
73223 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
73224 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73225 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73226 + [RLIMIT_AS] = "RLIMIT_AS",
73227 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73228 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73229 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73230 + [RLIMIT_NICE] = "RLIMIT_NICE",
73231 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73232 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73233 + [GR_CRASH_RES] = "RLIMIT_CRASH"
73234 +};
73235 +
73236 +void
73237 +gr_log_resource(const struct task_struct *task,
73238 + const int res, const unsigned long wanted, const int gt)
73239 +{
73240 + const struct cred *cred;
73241 + unsigned long rlim;
73242 +
73243 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
73244 + return;
73245 +
73246 + // not yet supported resource
73247 + if (unlikely(!restab_log[res]))
73248 + return;
73249 +
73250 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73251 + rlim = task_rlimit_max(task, res);
73252 + else
73253 + rlim = task_rlimit(task, res);
73254 +
73255 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73256 + return;
73257 +
73258 + rcu_read_lock();
73259 + cred = __task_cred(task);
73260 +
73261 + if (res == RLIMIT_NPROC &&
73262 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73263 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73264 + goto out_rcu_unlock;
73265 + else if (res == RLIMIT_MEMLOCK &&
73266 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73267 + goto out_rcu_unlock;
73268 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73269 + goto out_rcu_unlock;
73270 + rcu_read_unlock();
73271 +
73272 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73273 +
73274 + return;
73275 +out_rcu_unlock:
73276 + rcu_read_unlock();
73277 + return;
73278 +}
73279 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73280 new file mode 100644
73281 index 0000000..2040e61
73282 --- /dev/null
73283 +++ b/grsecurity/gracl_segv.c
73284 @@ -0,0 +1,313 @@
73285 +#include <linux/kernel.h>
73286 +#include <linux/mm.h>
73287 +#include <asm/uaccess.h>
73288 +#include <asm/errno.h>
73289 +#include <asm/mman.h>
73290 +#include <net/sock.h>
73291 +#include <linux/file.h>
73292 +#include <linux/fs.h>
73293 +#include <linux/net.h>
73294 +#include <linux/in.h>
73295 +#include <linux/slab.h>
73296 +#include <linux/types.h>
73297 +#include <linux/sched.h>
73298 +#include <linux/timer.h>
73299 +#include <linux/gracl.h>
73300 +#include <linux/grsecurity.h>
73301 +#include <linux/grinternal.h>
73302 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73303 +#include <linux/magic.h>
73304 +#include <linux/pagemap.h>
73305 +#include "../fs/btrfs/async-thread.h"
73306 +#include "../fs/btrfs/ctree.h"
73307 +#include "../fs/btrfs/btrfs_inode.h"
73308 +#endif
73309 +
73310 +static struct crash_uid *uid_set;
73311 +static unsigned short uid_used;
73312 +static DEFINE_SPINLOCK(gr_uid_lock);
73313 +extern rwlock_t gr_inode_lock;
73314 +extern struct acl_subject_label *
73315 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73316 + struct acl_role_label *role);
73317 +
73318 +static inline dev_t __get_dev(const struct dentry *dentry)
73319 +{
73320 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73321 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73322 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
73323 + else
73324 +#endif
73325 + return dentry->d_sb->s_dev;
73326 +}
73327 +
73328 +int
73329 +gr_init_uidset(void)
73330 +{
73331 + uid_set =
73332 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73333 + uid_used = 0;
73334 +
73335 + return uid_set ? 1 : 0;
73336 +}
73337 +
73338 +void
73339 +gr_free_uidset(void)
73340 +{
73341 + if (uid_set) {
73342 + struct crash_uid *tmpset;
73343 + spin_lock(&gr_uid_lock);
73344 + tmpset = uid_set;
73345 + uid_set = NULL;
73346 + uid_used = 0;
73347 + spin_unlock(&gr_uid_lock);
73348 + if (tmpset)
73349 + kfree(tmpset);
73350 + }
73351 +
73352 + return;
73353 +}
73354 +
73355 +int
73356 +gr_find_uid(const uid_t uid)
73357 +{
73358 + struct crash_uid *tmp = uid_set;
73359 + uid_t buid;
73360 + int low = 0, high = uid_used - 1, mid;
73361 +
73362 + while (high >= low) {
73363 + mid = (low + high) >> 1;
73364 + buid = tmp[mid].uid;
73365 + if (buid == uid)
73366 + return mid;
73367 + if (buid > uid)
73368 + high = mid - 1;
73369 + if (buid < uid)
73370 + low = mid + 1;
73371 + }
73372 +
73373 + return -1;
73374 +}
73375 +
73376 +static __inline__ void
73377 +gr_insertsort(void)
73378 +{
73379 + unsigned short i, j;
73380 + struct crash_uid index;
73381 +
73382 + for (i = 1; i < uid_used; i++) {
73383 + index = uid_set[i];
73384 + j = i;
73385 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73386 + uid_set[j] = uid_set[j - 1];
73387 + j--;
73388 + }
73389 + uid_set[j] = index;
73390 + }
73391 +
73392 + return;
73393 +}
73394 +
73395 +static __inline__ void
73396 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73397 +{
73398 + int loc;
73399 + uid_t uid = GR_GLOBAL_UID(kuid);
73400 +
73401 + if (uid_used == GR_UIDTABLE_MAX)
73402 + return;
73403 +
73404 + loc = gr_find_uid(uid);
73405 +
73406 + if (loc >= 0) {
73407 + uid_set[loc].expires = expires;
73408 + return;
73409 + }
73410 +
73411 + uid_set[uid_used].uid = uid;
73412 + uid_set[uid_used].expires = expires;
73413 + uid_used++;
73414 +
73415 + gr_insertsort();
73416 +
73417 + return;
73418 +}
73419 +
73420 +void
73421 +gr_remove_uid(const unsigned short loc)
73422 +{
73423 + unsigned short i;
73424 +
73425 + for (i = loc + 1; i < uid_used; i++)
73426 + uid_set[i - 1] = uid_set[i];
73427 +
73428 + uid_used--;
73429 +
73430 + return;
73431 +}
73432 +
73433 +int
73434 +gr_check_crash_uid(const kuid_t kuid)
73435 +{
73436 + int loc;
73437 + int ret = 0;
73438 + uid_t uid;
73439 +
73440 + if (unlikely(!gr_acl_is_enabled()))
73441 + return 0;
73442 +
73443 + uid = GR_GLOBAL_UID(kuid);
73444 +
73445 + spin_lock(&gr_uid_lock);
73446 + loc = gr_find_uid(uid);
73447 +
73448 + if (loc < 0)
73449 + goto out_unlock;
73450 +
73451 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
73452 + gr_remove_uid(loc);
73453 + else
73454 + ret = 1;
73455 +
73456 +out_unlock:
73457 + spin_unlock(&gr_uid_lock);
73458 + return ret;
73459 +}
73460 +
73461 +static __inline__ int
73462 +proc_is_setxid(const struct cred *cred)
73463 +{
73464 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73465 + !uid_eq(cred->uid, cred->fsuid))
73466 + return 1;
73467 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73468 + !gid_eq(cred->gid, cred->fsgid))
73469 + return 1;
73470 +
73471 + return 0;
73472 +}
73473 +
73474 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
73475 +
73476 +void
73477 +gr_handle_crash(struct task_struct *task, const int sig)
73478 +{
73479 + struct acl_subject_label *curr;
73480 + struct task_struct *tsk, *tsk2;
73481 + const struct cred *cred;
73482 + const struct cred *cred2;
73483 +
73484 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73485 + return;
73486 +
73487 + if (unlikely(!gr_acl_is_enabled()))
73488 + return;
73489 +
73490 + curr = task->acl;
73491 +
73492 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
73493 + return;
73494 +
73495 + if (time_before_eq(curr->expires, get_seconds())) {
73496 + curr->expires = 0;
73497 + curr->crashes = 0;
73498 + }
73499 +
73500 + curr->crashes++;
73501 +
73502 + if (!curr->expires)
73503 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73504 +
73505 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73506 + time_after(curr->expires, get_seconds())) {
73507 + rcu_read_lock();
73508 + cred = __task_cred(task);
73509 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73510 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73511 + spin_lock(&gr_uid_lock);
73512 + gr_insert_uid(cred->uid, curr->expires);
73513 + spin_unlock(&gr_uid_lock);
73514 + curr->expires = 0;
73515 + curr->crashes = 0;
73516 + read_lock(&tasklist_lock);
73517 + do_each_thread(tsk2, tsk) {
73518 + cred2 = __task_cred(tsk);
73519 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
73520 + gr_fake_force_sig(SIGKILL, tsk);
73521 + } while_each_thread(tsk2, tsk);
73522 + read_unlock(&tasklist_lock);
73523 + } else {
73524 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73525 + read_lock(&tasklist_lock);
73526 + read_lock(&grsec_exec_file_lock);
73527 + do_each_thread(tsk2, tsk) {
73528 + if (likely(tsk != task)) {
73529 + // if this thread has the same subject as the one that triggered
73530 + // RES_CRASH and it's the same binary, kill it
73531 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73532 + gr_fake_force_sig(SIGKILL, tsk);
73533 + }
73534 + } while_each_thread(tsk2, tsk);
73535 + read_unlock(&grsec_exec_file_lock);
73536 + read_unlock(&tasklist_lock);
73537 + }
73538 + rcu_read_unlock();
73539 + }
73540 +
73541 + return;
73542 +}
73543 +
73544 +int
73545 +gr_check_crash_exec(const struct file *filp)
73546 +{
73547 + struct acl_subject_label *curr;
73548 +
73549 + if (unlikely(!gr_acl_is_enabled()))
73550 + return 0;
73551 +
73552 + read_lock(&gr_inode_lock);
73553 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73554 + __get_dev(filp->f_path.dentry),
73555 + current->role);
73556 + read_unlock(&gr_inode_lock);
73557 +
73558 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73559 + (!curr->crashes && !curr->expires))
73560 + return 0;
73561 +
73562 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73563 + time_after(curr->expires, get_seconds()))
73564 + return 1;
73565 + else if (time_before_eq(curr->expires, get_seconds())) {
73566 + curr->crashes = 0;
73567 + curr->expires = 0;
73568 + }
73569 +
73570 + return 0;
73571 +}
73572 +
73573 +void
73574 +gr_handle_alertkill(struct task_struct *task)
73575 +{
73576 + struct acl_subject_label *curracl;
73577 + __u32 curr_ip;
73578 + struct task_struct *p, *p2;
73579 +
73580 + if (unlikely(!gr_acl_is_enabled()))
73581 + return;
73582 +
73583 + curracl = task->acl;
73584 + curr_ip = task->signal->curr_ip;
73585 +
73586 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73587 + read_lock(&tasklist_lock);
73588 + do_each_thread(p2, p) {
73589 + if (p->signal->curr_ip == curr_ip)
73590 + gr_fake_force_sig(SIGKILL, p);
73591 + } while_each_thread(p2, p);
73592 + read_unlock(&tasklist_lock);
73593 + } else if (curracl->mode & GR_KILLPROC)
73594 + gr_fake_force_sig(SIGKILL, task);
73595 +
73596 + return;
73597 +}
73598 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73599 new file mode 100644
73600 index 0000000..98011b0
73601 --- /dev/null
73602 +++ b/grsecurity/gracl_shm.c
73603 @@ -0,0 +1,40 @@
73604 +#include <linux/kernel.h>
73605 +#include <linux/mm.h>
73606 +#include <linux/sched.h>
73607 +#include <linux/file.h>
73608 +#include <linux/ipc.h>
73609 +#include <linux/gracl.h>
73610 +#include <linux/grsecurity.h>
73611 +#include <linux/grinternal.h>
73612 +
73613 +int
73614 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73615 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73616 +{
73617 + struct task_struct *task;
73618 +
73619 + if (!gr_acl_is_enabled())
73620 + return 1;
73621 +
73622 + rcu_read_lock();
73623 + read_lock(&tasklist_lock);
73624 +
73625 + task = find_task_by_vpid(shm_cprid);
73626 +
73627 + if (unlikely(!task))
73628 + task = find_task_by_vpid(shm_lapid);
73629 +
73630 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73631 + (task_pid_nr(task) == shm_lapid)) &&
73632 + (task->acl->mode & GR_PROTSHM) &&
73633 + (task->acl != current->acl))) {
73634 + read_unlock(&tasklist_lock);
73635 + rcu_read_unlock();
73636 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73637 + return 0;
73638 + }
73639 + read_unlock(&tasklist_lock);
73640 + rcu_read_unlock();
73641 +
73642 + return 1;
73643 +}
73644 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73645 new file mode 100644
73646 index 0000000..bc0be01
73647 --- /dev/null
73648 +++ b/grsecurity/grsec_chdir.c
73649 @@ -0,0 +1,19 @@
73650 +#include <linux/kernel.h>
73651 +#include <linux/sched.h>
73652 +#include <linux/fs.h>
73653 +#include <linux/file.h>
73654 +#include <linux/grsecurity.h>
73655 +#include <linux/grinternal.h>
73656 +
73657 +void
73658 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73659 +{
73660 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73661 + if ((grsec_enable_chdir && grsec_enable_group &&
73662 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73663 + !grsec_enable_group)) {
73664 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73665 + }
73666 +#endif
73667 + return;
73668 +}
73669 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73670 new file mode 100644
73671 index 0000000..651d6c2
73672 --- /dev/null
73673 +++ b/grsecurity/grsec_chroot.c
73674 @@ -0,0 +1,370 @@
73675 +#include <linux/kernel.h>
73676 +#include <linux/module.h>
73677 +#include <linux/sched.h>
73678 +#include <linux/file.h>
73679 +#include <linux/fs.h>
73680 +#include <linux/mount.h>
73681 +#include <linux/types.h>
73682 +#include "../fs/mount.h"
73683 +#include <linux/grsecurity.h>
73684 +#include <linux/grinternal.h>
73685 +
73686 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73687 +int gr_init_ran;
73688 +#endif
73689 +
73690 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73691 +{
73692 +#ifdef CONFIG_GRKERNSEC
73693 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73694 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73695 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73696 + && gr_init_ran
73697 +#endif
73698 + )
73699 + task->gr_is_chrooted = 1;
73700 + else {
73701 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73702 + if (task_pid_nr(task) == 1 && !gr_init_ran)
73703 + gr_init_ran = 1;
73704 +#endif
73705 + task->gr_is_chrooted = 0;
73706 + }
73707 +
73708 + task->gr_chroot_dentry = path->dentry;
73709 +#endif
73710 + return;
73711 +}
73712 +
73713 +void gr_clear_chroot_entries(struct task_struct *task)
73714 +{
73715 +#ifdef CONFIG_GRKERNSEC
73716 + task->gr_is_chrooted = 0;
73717 + task->gr_chroot_dentry = NULL;
73718 +#endif
73719 + return;
73720 +}
73721 +
73722 +int
73723 +gr_handle_chroot_unix(const pid_t pid)
73724 +{
73725 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73726 + struct task_struct *p;
73727 +
73728 + if (unlikely(!grsec_enable_chroot_unix))
73729 + return 1;
73730 +
73731 + if (likely(!proc_is_chrooted(current)))
73732 + return 1;
73733 +
73734 + rcu_read_lock();
73735 + read_lock(&tasklist_lock);
73736 + p = find_task_by_vpid_unrestricted(pid);
73737 + if (unlikely(p && !have_same_root(current, p))) {
73738 + read_unlock(&tasklist_lock);
73739 + rcu_read_unlock();
73740 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73741 + return 0;
73742 + }
73743 + read_unlock(&tasklist_lock);
73744 + rcu_read_unlock();
73745 +#endif
73746 + return 1;
73747 +}
73748 +
73749 +int
73750 +gr_handle_chroot_nice(void)
73751 +{
73752 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73753 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73754 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73755 + return -EPERM;
73756 + }
73757 +#endif
73758 + return 0;
73759 +}
73760 +
73761 +int
73762 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73763 +{
73764 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73765 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73766 + && proc_is_chrooted(current)) {
73767 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73768 + return -EACCES;
73769 + }
73770 +#endif
73771 + return 0;
73772 +}
73773 +
73774 +int
73775 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73776 +{
73777 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73778 + struct task_struct *p;
73779 + int ret = 0;
73780 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73781 + return ret;
73782 +
73783 + read_lock(&tasklist_lock);
73784 + do_each_pid_task(pid, type, p) {
73785 + if (!have_same_root(current, p)) {
73786 + ret = 1;
73787 + goto out;
73788 + }
73789 + } while_each_pid_task(pid, type, p);
73790 +out:
73791 + read_unlock(&tasklist_lock);
73792 + return ret;
73793 +#endif
73794 + return 0;
73795 +}
73796 +
73797 +int
73798 +gr_pid_is_chrooted(struct task_struct *p)
73799 +{
73800 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73801 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73802 + return 0;
73803 +
73804 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73805 + !have_same_root(current, p)) {
73806 + return 1;
73807 + }
73808 +#endif
73809 + return 0;
73810 +}
73811 +
73812 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73813 +
73814 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73815 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73816 +{
73817 + struct path path, currentroot;
73818 + int ret = 0;
73819 +
73820 + path.dentry = (struct dentry *)u_dentry;
73821 + path.mnt = (struct vfsmount *)u_mnt;
73822 + get_fs_root(current->fs, &currentroot);
73823 + if (path_is_under(&path, &currentroot))
73824 + ret = 1;
73825 + path_put(&currentroot);
73826 +
73827 + return ret;
73828 +}
73829 +#endif
73830 +
73831 +int
73832 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73833 +{
73834 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73835 + if (!grsec_enable_chroot_fchdir)
73836 + return 1;
73837 +
73838 + if (!proc_is_chrooted(current))
73839 + return 1;
73840 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73841 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73842 + return 0;
73843 + }
73844 +#endif
73845 + return 1;
73846 +}
73847 +
73848 +int
73849 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73850 + const time_t shm_createtime)
73851 +{
73852 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73853 + struct task_struct *p;
73854 + time_t starttime;
73855 +
73856 + if (unlikely(!grsec_enable_chroot_shmat))
73857 + return 1;
73858 +
73859 + if (likely(!proc_is_chrooted(current)))
73860 + return 1;
73861 +
73862 + rcu_read_lock();
73863 + read_lock(&tasklist_lock);
73864 +
73865 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73866 + starttime = p->start_time.tv_sec;
73867 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73868 + if (have_same_root(current, p)) {
73869 + goto allow;
73870 + } else {
73871 + read_unlock(&tasklist_lock);
73872 + rcu_read_unlock();
73873 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73874 + return 0;
73875 + }
73876 + }
73877 + /* creator exited, pid reuse, fall through to next check */
73878 + }
73879 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73880 + if (unlikely(!have_same_root(current, p))) {
73881 + read_unlock(&tasklist_lock);
73882 + rcu_read_unlock();
73883 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73884 + return 0;
73885 + }
73886 + }
73887 +
73888 +allow:
73889 + read_unlock(&tasklist_lock);
73890 + rcu_read_unlock();
73891 +#endif
73892 + return 1;
73893 +}
73894 +
73895 +void
73896 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73897 +{
73898 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73899 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73900 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73901 +#endif
73902 + return;
73903 +}
73904 +
73905 +int
73906 +gr_handle_chroot_mknod(const struct dentry *dentry,
73907 + const struct vfsmount *mnt, const int mode)
73908 +{
73909 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73910 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73911 + proc_is_chrooted(current)) {
73912 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73913 + return -EPERM;
73914 + }
73915 +#endif
73916 + return 0;
73917 +}
73918 +
73919 +int
73920 +gr_handle_chroot_mount(const struct dentry *dentry,
73921 + const struct vfsmount *mnt, const char *dev_name)
73922 +{
73923 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73924 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73925 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73926 + return -EPERM;
73927 + }
73928 +#endif
73929 + return 0;
73930 +}
73931 +
73932 +int
73933 +gr_handle_chroot_pivot(void)
73934 +{
73935 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73936 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73937 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73938 + return -EPERM;
73939 + }
73940 +#endif
73941 + return 0;
73942 +}
73943 +
73944 +int
73945 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73946 +{
73947 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73948 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73949 + !gr_is_outside_chroot(dentry, mnt)) {
73950 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73951 + return -EPERM;
73952 + }
73953 +#endif
73954 + return 0;
73955 +}
73956 +
73957 +extern const char *captab_log[];
73958 +extern int captab_log_entries;
73959 +
73960 +int
73961 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73962 +{
73963 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73964 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73965 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73966 + if (cap_raised(chroot_caps, cap)) {
73967 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73968 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73969 + }
73970 + return 0;
73971 + }
73972 + }
73973 +#endif
73974 + return 1;
73975 +}
73976 +
73977 +int
73978 +gr_chroot_is_capable(const int cap)
73979 +{
73980 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73981 + return gr_task_chroot_is_capable(current, current_cred(), cap);
73982 +#endif
73983 + return 1;
73984 +}
73985 +
73986 +int
73987 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73988 +{
73989 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73990 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73991 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73992 + if (cap_raised(chroot_caps, cap)) {
73993 + return 0;
73994 + }
73995 + }
73996 +#endif
73997 + return 1;
73998 +}
73999 +
74000 +int
74001 +gr_chroot_is_capable_nolog(const int cap)
74002 +{
74003 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74004 + return gr_task_chroot_is_capable_nolog(current, cap);
74005 +#endif
74006 + return 1;
74007 +}
74008 +
74009 +int
74010 +gr_handle_chroot_sysctl(const int op)
74011 +{
74012 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74013 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
74014 + proc_is_chrooted(current))
74015 + return -EACCES;
74016 +#endif
74017 + return 0;
74018 +}
74019 +
74020 +void
74021 +gr_handle_chroot_chdir(const struct path *path)
74022 +{
74023 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74024 + if (grsec_enable_chroot_chdir)
74025 + set_fs_pwd(current->fs, path);
74026 +#endif
74027 + return;
74028 +}
74029 +
74030 +int
74031 +gr_handle_chroot_chmod(const struct dentry *dentry,
74032 + const struct vfsmount *mnt, const int mode)
74033 +{
74034 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74035 + /* allow chmod +s on directories, but not files */
74036 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
74037 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
74038 + proc_is_chrooted(current)) {
74039 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
74040 + return -EPERM;
74041 + }
74042 +#endif
74043 + return 0;
74044 +}
74045 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
74046 new file mode 100644
74047 index 0000000..4d6fce8
74048 --- /dev/null
74049 +++ b/grsecurity/grsec_disabled.c
74050 @@ -0,0 +1,433 @@
74051 +#include <linux/kernel.h>
74052 +#include <linux/module.h>
74053 +#include <linux/sched.h>
74054 +#include <linux/file.h>
74055 +#include <linux/fs.h>
74056 +#include <linux/kdev_t.h>
74057 +#include <linux/net.h>
74058 +#include <linux/in.h>
74059 +#include <linux/ip.h>
74060 +#include <linux/skbuff.h>
74061 +#include <linux/sysctl.h>
74062 +
74063 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
74064 +void
74065 +pax_set_initial_flags(struct linux_binprm *bprm)
74066 +{
74067 + return;
74068 +}
74069 +#endif
74070 +
74071 +#ifdef CONFIG_SYSCTL
74072 +__u32
74073 +gr_handle_sysctl(const struct ctl_table * table, const int op)
74074 +{
74075 + return 0;
74076 +}
74077 +#endif
74078 +
74079 +#ifdef CONFIG_TASKSTATS
74080 +int gr_is_taskstats_denied(int pid)
74081 +{
74082 + return 0;
74083 +}
74084 +#endif
74085 +
74086 +int
74087 +gr_acl_is_enabled(void)
74088 +{
74089 + return 0;
74090 +}
74091 +
74092 +void
74093 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
74094 +{
74095 + return;
74096 +}
74097 +
74098 +int
74099 +gr_handle_rawio(const struct inode *inode)
74100 +{
74101 + return 0;
74102 +}
74103 +
74104 +void
74105 +gr_acl_handle_psacct(struct task_struct *task, const long code)
74106 +{
74107 + return;
74108 +}
74109 +
74110 +int
74111 +gr_handle_ptrace(struct task_struct *task, const long request)
74112 +{
74113 + return 0;
74114 +}
74115 +
74116 +int
74117 +gr_handle_proc_ptrace(struct task_struct *task)
74118 +{
74119 + return 0;
74120 +}
74121 +
74122 +int
74123 +gr_set_acls(const int type)
74124 +{
74125 + return 0;
74126 +}
74127 +
74128 +int
74129 +gr_check_hidden_task(const struct task_struct *tsk)
74130 +{
74131 + return 0;
74132 +}
74133 +
74134 +int
74135 +gr_check_protected_task(const struct task_struct *task)
74136 +{
74137 + return 0;
74138 +}
74139 +
74140 +int
74141 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
74142 +{
74143 + return 0;
74144 +}
74145 +
74146 +void
74147 +gr_copy_label(struct task_struct *tsk)
74148 +{
74149 + return;
74150 +}
74151 +
74152 +void
74153 +gr_set_pax_flags(struct task_struct *task)
74154 +{
74155 + return;
74156 +}
74157 +
74158 +int
74159 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
74160 + const int unsafe_share)
74161 +{
74162 + return 0;
74163 +}
74164 +
74165 +void
74166 +gr_handle_delete(const ino_t ino, const dev_t dev)
74167 +{
74168 + return;
74169 +}
74170 +
74171 +void
74172 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74173 +{
74174 + return;
74175 +}
74176 +
74177 +void
74178 +gr_handle_crash(struct task_struct *task, const int sig)
74179 +{
74180 + return;
74181 +}
74182 +
74183 +int
74184 +gr_check_crash_exec(const struct file *filp)
74185 +{
74186 + return 0;
74187 +}
74188 +
74189 +int
74190 +gr_check_crash_uid(const kuid_t uid)
74191 +{
74192 + return 0;
74193 +}
74194 +
74195 +void
74196 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74197 + struct dentry *old_dentry,
74198 + struct dentry *new_dentry,
74199 + struct vfsmount *mnt, const __u8 replace)
74200 +{
74201 + return;
74202 +}
74203 +
74204 +int
74205 +gr_search_socket(const int family, const int type, const int protocol)
74206 +{
74207 + return 1;
74208 +}
74209 +
74210 +int
74211 +gr_search_connectbind(const int mode, const struct socket *sock,
74212 + const struct sockaddr_in *addr)
74213 +{
74214 + return 0;
74215 +}
74216 +
74217 +void
74218 +gr_handle_alertkill(struct task_struct *task)
74219 +{
74220 + return;
74221 +}
74222 +
74223 +__u32
74224 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74225 +{
74226 + return 1;
74227 +}
74228 +
74229 +__u32
74230 +gr_acl_handle_hidden_file(const struct dentry * dentry,
74231 + const struct vfsmount * mnt)
74232 +{
74233 + return 1;
74234 +}
74235 +
74236 +__u32
74237 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74238 + int acc_mode)
74239 +{
74240 + return 1;
74241 +}
74242 +
74243 +__u32
74244 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74245 +{
74246 + return 1;
74247 +}
74248 +
74249 +__u32
74250 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74251 +{
74252 + return 1;
74253 +}
74254 +
74255 +int
74256 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74257 + unsigned int *vm_flags)
74258 +{
74259 + return 1;
74260 +}
74261 +
74262 +__u32
74263 +gr_acl_handle_truncate(const struct dentry * dentry,
74264 + const struct vfsmount * mnt)
74265 +{
74266 + return 1;
74267 +}
74268 +
74269 +__u32
74270 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74271 +{
74272 + return 1;
74273 +}
74274 +
74275 +__u32
74276 +gr_acl_handle_access(const struct dentry * dentry,
74277 + const struct vfsmount * mnt, const int fmode)
74278 +{
74279 + return 1;
74280 +}
74281 +
74282 +__u32
74283 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74284 + umode_t *mode)
74285 +{
74286 + return 1;
74287 +}
74288 +
74289 +__u32
74290 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74291 +{
74292 + return 1;
74293 +}
74294 +
74295 +__u32
74296 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74297 +{
74298 + return 1;
74299 +}
74300 +
74301 +__u32
74302 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74303 +{
74304 + return 1;
74305 +}
74306 +
74307 +void
74308 +grsecurity_init(void)
74309 +{
74310 + return;
74311 +}
74312 +
74313 +umode_t gr_acl_umask(void)
74314 +{
74315 + return 0;
74316 +}
74317 +
74318 +__u32
74319 +gr_acl_handle_mknod(const struct dentry * new_dentry,
74320 + const struct dentry * parent_dentry,
74321 + const struct vfsmount * parent_mnt,
74322 + const int mode)
74323 +{
74324 + return 1;
74325 +}
74326 +
74327 +__u32
74328 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
74329 + const struct dentry * parent_dentry,
74330 + const struct vfsmount * parent_mnt)
74331 +{
74332 + return 1;
74333 +}
74334 +
74335 +__u32
74336 +gr_acl_handle_symlink(const struct dentry * new_dentry,
74337 + const struct dentry * parent_dentry,
74338 + const struct vfsmount * parent_mnt, const struct filename *from)
74339 +{
74340 + return 1;
74341 +}
74342 +
74343 +__u32
74344 +gr_acl_handle_link(const struct dentry * new_dentry,
74345 + const struct dentry * parent_dentry,
74346 + const struct vfsmount * parent_mnt,
74347 + const struct dentry * old_dentry,
74348 + const struct vfsmount * old_mnt, const struct filename *to)
74349 +{
74350 + return 1;
74351 +}
74352 +
74353 +int
74354 +gr_acl_handle_rename(const struct dentry *new_dentry,
74355 + const struct dentry *parent_dentry,
74356 + const struct vfsmount *parent_mnt,
74357 + const struct dentry *old_dentry,
74358 + const struct inode *old_parent_inode,
74359 + const struct vfsmount *old_mnt, const struct filename *newname)
74360 +{
74361 + return 0;
74362 +}
74363 +
74364 +int
74365 +gr_acl_handle_filldir(const struct file *file, const char *name,
74366 + const int namelen, const ino_t ino)
74367 +{
74368 + return 1;
74369 +}
74370 +
74371 +int
74372 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74373 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
74374 +{
74375 + return 1;
74376 +}
74377 +
74378 +int
74379 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74380 +{
74381 + return 0;
74382 +}
74383 +
74384 +int
74385 +gr_search_accept(const struct socket *sock)
74386 +{
74387 + return 0;
74388 +}
74389 +
74390 +int
74391 +gr_search_listen(const struct socket *sock)
74392 +{
74393 + return 0;
74394 +}
74395 +
74396 +int
74397 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74398 +{
74399 + return 0;
74400 +}
74401 +
74402 +__u32
74403 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74404 +{
74405 + return 1;
74406 +}
74407 +
74408 +__u32
74409 +gr_acl_handle_creat(const struct dentry * dentry,
74410 + const struct dentry * p_dentry,
74411 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74412 + const int imode)
74413 +{
74414 + return 1;
74415 +}
74416 +
74417 +void
74418 +gr_acl_handle_exit(void)
74419 +{
74420 + return;
74421 +}
74422 +
74423 +int
74424 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74425 +{
74426 + return 1;
74427 +}
74428 +
74429 +void
74430 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
74431 +{
74432 + return;
74433 +}
74434 +
74435 +int
74436 +gr_acl_handle_procpidmem(const struct task_struct *task)
74437 +{
74438 + return 0;
74439 +}
74440 +
74441 +int
74442 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74443 +{
74444 + return 0;
74445 +}
74446 +
74447 +int
74448 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74449 +{
74450 + return 0;
74451 +}
74452 +
74453 +int
74454 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74455 +{
74456 + return 0;
74457 +}
74458 +
74459 +int
74460 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74461 +{
74462 + return 0;
74463 +}
74464 +
74465 +int gr_acl_enable_at_secure(void)
74466 +{
74467 + return 0;
74468 +}
74469 +
74470 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74471 +{
74472 + return dentry->d_sb->s_dev;
74473 +}
74474 +
74475 +void gr_put_exec_file(struct task_struct *task)
74476 +{
74477 + return;
74478 +}
74479 +
74480 +#ifdef CONFIG_SECURITY
74481 +EXPORT_SYMBOL_GPL(gr_check_user_change);
74482 +EXPORT_SYMBOL_GPL(gr_check_group_change);
74483 +#endif
74484 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74485 new file mode 100644
74486 index 0000000..f35f454
74487 --- /dev/null
74488 +++ b/grsecurity/grsec_exec.c
74489 @@ -0,0 +1,187 @@
74490 +#include <linux/kernel.h>
74491 +#include <linux/sched.h>
74492 +#include <linux/file.h>
74493 +#include <linux/binfmts.h>
74494 +#include <linux/fs.h>
74495 +#include <linux/types.h>
74496 +#include <linux/grdefs.h>
74497 +#include <linux/grsecurity.h>
74498 +#include <linux/grinternal.h>
74499 +#include <linux/capability.h>
74500 +#include <linux/module.h>
74501 +#include <linux/compat.h>
74502 +
74503 +#include <asm/uaccess.h>
74504 +
74505 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74506 +static char gr_exec_arg_buf[132];
74507 +static DEFINE_MUTEX(gr_exec_arg_mutex);
74508 +#endif
74509 +
74510 +struct user_arg_ptr {
74511 +#ifdef CONFIG_COMPAT
74512 + bool is_compat;
74513 +#endif
74514 + union {
74515 + const char __user *const __user *native;
74516 +#ifdef CONFIG_COMPAT
74517 + const compat_uptr_t __user *compat;
74518 +#endif
74519 + } ptr;
74520 +};
74521 +
74522 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74523 +
74524 +void
74525 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74526 +{
74527 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74528 + char *grarg = gr_exec_arg_buf;
74529 + unsigned int i, x, execlen = 0;
74530 + char c;
74531 +
74532 + if (!((grsec_enable_execlog && grsec_enable_group &&
74533 + in_group_p(grsec_audit_gid))
74534 + || (grsec_enable_execlog && !grsec_enable_group)))
74535 + return;
74536 +
74537 + mutex_lock(&gr_exec_arg_mutex);
74538 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
74539 +
74540 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
74541 + const char __user *p;
74542 + unsigned int len;
74543 +
74544 + p = get_user_arg_ptr(argv, i);
74545 + if (IS_ERR(p))
74546 + goto log;
74547 +
74548 + len = strnlen_user(p, 128 - execlen);
74549 + if (len > 128 - execlen)
74550 + len = 128 - execlen;
74551 + else if (len > 0)
74552 + len--;
74553 + if (copy_from_user(grarg + execlen, p, len))
74554 + goto log;
74555 +
74556 + /* rewrite unprintable characters */
74557 + for (x = 0; x < len; x++) {
74558 + c = *(grarg + execlen + x);
74559 + if (c < 32 || c > 126)
74560 + *(grarg + execlen + x) = ' ';
74561 + }
74562 +
74563 + execlen += len;
74564 + *(grarg + execlen) = ' ';
74565 + *(grarg + execlen + 1) = '\0';
74566 + execlen++;
74567 + }
74568 +
74569 + log:
74570 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74571 + bprm->file->f_path.mnt, grarg);
74572 + mutex_unlock(&gr_exec_arg_mutex);
74573 +#endif
74574 + return;
74575 +}
74576 +
74577 +#ifdef CONFIG_GRKERNSEC
74578 +extern int gr_acl_is_capable(const int cap);
74579 +extern int gr_acl_is_capable_nolog(const int cap);
74580 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74581 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74582 +extern int gr_chroot_is_capable(const int cap);
74583 +extern int gr_chroot_is_capable_nolog(const int cap);
74584 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74585 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74586 +#endif
74587 +
74588 +const char *captab_log[] = {
74589 + "CAP_CHOWN",
74590 + "CAP_DAC_OVERRIDE",
74591 + "CAP_DAC_READ_SEARCH",
74592 + "CAP_FOWNER",
74593 + "CAP_FSETID",
74594 + "CAP_KILL",
74595 + "CAP_SETGID",
74596 + "CAP_SETUID",
74597 + "CAP_SETPCAP",
74598 + "CAP_LINUX_IMMUTABLE",
74599 + "CAP_NET_BIND_SERVICE",
74600 + "CAP_NET_BROADCAST",
74601 + "CAP_NET_ADMIN",
74602 + "CAP_NET_RAW",
74603 + "CAP_IPC_LOCK",
74604 + "CAP_IPC_OWNER",
74605 + "CAP_SYS_MODULE",
74606 + "CAP_SYS_RAWIO",
74607 + "CAP_SYS_CHROOT",
74608 + "CAP_SYS_PTRACE",
74609 + "CAP_SYS_PACCT",
74610 + "CAP_SYS_ADMIN",
74611 + "CAP_SYS_BOOT",
74612 + "CAP_SYS_NICE",
74613 + "CAP_SYS_RESOURCE",
74614 + "CAP_SYS_TIME",
74615 + "CAP_SYS_TTY_CONFIG",
74616 + "CAP_MKNOD",
74617 + "CAP_LEASE",
74618 + "CAP_AUDIT_WRITE",
74619 + "CAP_AUDIT_CONTROL",
74620 + "CAP_SETFCAP",
74621 + "CAP_MAC_OVERRIDE",
74622 + "CAP_MAC_ADMIN",
74623 + "CAP_SYSLOG",
74624 + "CAP_WAKE_ALARM"
74625 +};
74626 +
74627 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74628 +
74629 +int gr_is_capable(const int cap)
74630 +{
74631 +#ifdef CONFIG_GRKERNSEC
74632 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74633 + return 1;
74634 + return 0;
74635 +#else
74636 + return 1;
74637 +#endif
74638 +}
74639 +
74640 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74641 +{
74642 +#ifdef CONFIG_GRKERNSEC
74643 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74644 + return 1;
74645 + return 0;
74646 +#else
74647 + return 1;
74648 +#endif
74649 +}
74650 +
74651 +int gr_is_capable_nolog(const int cap)
74652 +{
74653 +#ifdef CONFIG_GRKERNSEC
74654 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74655 + return 1;
74656 + return 0;
74657 +#else
74658 + return 1;
74659 +#endif
74660 +}
74661 +
74662 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74663 +{
74664 +#ifdef CONFIG_GRKERNSEC
74665 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74666 + return 1;
74667 + return 0;
74668 +#else
74669 + return 1;
74670 +#endif
74671 +}
74672 +
74673 +EXPORT_SYMBOL_GPL(gr_is_capable);
74674 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74675 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
74676 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74677 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74678 new file mode 100644
74679 index 0000000..06cc6ea
74680 --- /dev/null
74681 +++ b/grsecurity/grsec_fifo.c
74682 @@ -0,0 +1,24 @@
74683 +#include <linux/kernel.h>
74684 +#include <linux/sched.h>
74685 +#include <linux/fs.h>
74686 +#include <linux/file.h>
74687 +#include <linux/grinternal.h>
74688 +
74689 +int
74690 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74691 + const struct dentry *dir, const int flag, const int acc_mode)
74692 +{
74693 +#ifdef CONFIG_GRKERNSEC_FIFO
74694 + const struct cred *cred = current_cred();
74695 +
74696 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74697 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74698 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74699 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74700 + if (!inode_permission(dentry->d_inode, acc_mode))
74701 + 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));
74702 + return -EACCES;
74703 + }
74704 +#endif
74705 + return 0;
74706 +}
74707 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74708 new file mode 100644
74709 index 0000000..8ca18bf
74710 --- /dev/null
74711 +++ b/grsecurity/grsec_fork.c
74712 @@ -0,0 +1,23 @@
74713 +#include <linux/kernel.h>
74714 +#include <linux/sched.h>
74715 +#include <linux/grsecurity.h>
74716 +#include <linux/grinternal.h>
74717 +#include <linux/errno.h>
74718 +
74719 +void
74720 +gr_log_forkfail(const int retval)
74721 +{
74722 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74723 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74724 + switch (retval) {
74725 + case -EAGAIN:
74726 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74727 + break;
74728 + case -ENOMEM:
74729 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74730 + break;
74731 + }
74732 + }
74733 +#endif
74734 + return;
74735 +}
74736 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74737 new file mode 100644
74738 index 0000000..ae6c028
74739 --- /dev/null
74740 +++ b/grsecurity/grsec_init.c
74741 @@ -0,0 +1,272 @@
74742 +#include <linux/kernel.h>
74743 +#include <linux/sched.h>
74744 +#include <linux/mm.h>
74745 +#include <linux/gracl.h>
74746 +#include <linux/slab.h>
74747 +#include <linux/vmalloc.h>
74748 +#include <linux/percpu.h>
74749 +#include <linux/module.h>
74750 +
74751 +int grsec_enable_ptrace_readexec;
74752 +int grsec_enable_setxid;
74753 +int grsec_enable_symlinkown;
74754 +kgid_t grsec_symlinkown_gid;
74755 +int grsec_enable_brute;
74756 +int grsec_enable_link;
74757 +int grsec_enable_dmesg;
74758 +int grsec_enable_harden_ptrace;
74759 +int grsec_enable_harden_ipc;
74760 +int grsec_enable_fifo;
74761 +int grsec_enable_execlog;
74762 +int grsec_enable_signal;
74763 +int grsec_enable_forkfail;
74764 +int grsec_enable_audit_ptrace;
74765 +int grsec_enable_time;
74766 +int grsec_enable_group;
74767 +kgid_t grsec_audit_gid;
74768 +int grsec_enable_chdir;
74769 +int grsec_enable_mount;
74770 +int grsec_enable_rofs;
74771 +int grsec_deny_new_usb;
74772 +int grsec_enable_chroot_findtask;
74773 +int grsec_enable_chroot_mount;
74774 +int grsec_enable_chroot_shmat;
74775 +int grsec_enable_chroot_fchdir;
74776 +int grsec_enable_chroot_double;
74777 +int grsec_enable_chroot_pivot;
74778 +int grsec_enable_chroot_chdir;
74779 +int grsec_enable_chroot_chmod;
74780 +int grsec_enable_chroot_mknod;
74781 +int grsec_enable_chroot_nice;
74782 +int grsec_enable_chroot_execlog;
74783 +int grsec_enable_chroot_caps;
74784 +int grsec_enable_chroot_sysctl;
74785 +int grsec_enable_chroot_unix;
74786 +int grsec_enable_tpe;
74787 +kgid_t grsec_tpe_gid;
74788 +int grsec_enable_blackhole;
74789 +#ifdef CONFIG_IPV6_MODULE
74790 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74791 +#endif
74792 +int grsec_lastack_retries;
74793 +int grsec_enable_tpe_all;
74794 +int grsec_enable_tpe_invert;
74795 +int grsec_enable_socket_all;
74796 +kgid_t grsec_socket_all_gid;
74797 +int grsec_enable_socket_client;
74798 +kgid_t grsec_socket_client_gid;
74799 +int grsec_enable_socket_server;
74800 +kgid_t grsec_socket_server_gid;
74801 +int grsec_resource_logging;
74802 +int grsec_disable_privio;
74803 +int grsec_enable_log_rwxmaps;
74804 +int grsec_lock;
74805 +
74806 +DEFINE_SPINLOCK(grsec_alert_lock);
74807 +unsigned long grsec_alert_wtime = 0;
74808 +unsigned long grsec_alert_fyet = 0;
74809 +
74810 +DEFINE_SPINLOCK(grsec_audit_lock);
74811 +
74812 +DEFINE_RWLOCK(grsec_exec_file_lock);
74813 +
74814 +char *gr_shared_page[4];
74815 +
74816 +char *gr_alert_log_fmt;
74817 +char *gr_audit_log_fmt;
74818 +char *gr_alert_log_buf;
74819 +char *gr_audit_log_buf;
74820 +
74821 +void __init
74822 +grsecurity_init(void)
74823 +{
74824 + int j;
74825 + /* create the per-cpu shared pages */
74826 +
74827 +#ifdef CONFIG_X86
74828 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74829 +#endif
74830 +
74831 + for (j = 0; j < 4; j++) {
74832 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74833 + if (gr_shared_page[j] == NULL) {
74834 + panic("Unable to allocate grsecurity shared page");
74835 + return;
74836 + }
74837 + }
74838 +
74839 + /* allocate log buffers */
74840 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74841 + if (!gr_alert_log_fmt) {
74842 + panic("Unable to allocate grsecurity alert log format buffer");
74843 + return;
74844 + }
74845 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74846 + if (!gr_audit_log_fmt) {
74847 + panic("Unable to allocate grsecurity audit log format buffer");
74848 + return;
74849 + }
74850 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74851 + if (!gr_alert_log_buf) {
74852 + panic("Unable to allocate grsecurity alert log buffer");
74853 + return;
74854 + }
74855 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74856 + if (!gr_audit_log_buf) {
74857 + panic("Unable to allocate grsecurity audit log buffer");
74858 + return;
74859 + }
74860 +
74861 +#ifdef CONFIG_GRKERNSEC_IO
74862 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74863 + grsec_disable_privio = 1;
74864 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74865 + grsec_disable_privio = 1;
74866 +#else
74867 + grsec_disable_privio = 0;
74868 +#endif
74869 +#endif
74870 +
74871 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74872 + /* for backward compatibility, tpe_invert always defaults to on if
74873 + enabled in the kernel
74874 + */
74875 + grsec_enable_tpe_invert = 1;
74876 +#endif
74877 +
74878 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74879 +#ifndef CONFIG_GRKERNSEC_SYSCTL
74880 + grsec_lock = 1;
74881 +#endif
74882 +
74883 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74884 + grsec_enable_log_rwxmaps = 1;
74885 +#endif
74886 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74887 + grsec_enable_group = 1;
74888 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74889 +#endif
74890 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74891 + grsec_enable_ptrace_readexec = 1;
74892 +#endif
74893 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74894 + grsec_enable_chdir = 1;
74895 +#endif
74896 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74897 + grsec_enable_harden_ptrace = 1;
74898 +#endif
74899 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74900 + grsec_enable_harden_ipc = 1;
74901 +#endif
74902 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74903 + grsec_enable_mount = 1;
74904 +#endif
74905 +#ifdef CONFIG_GRKERNSEC_LINK
74906 + grsec_enable_link = 1;
74907 +#endif
74908 +#ifdef CONFIG_GRKERNSEC_BRUTE
74909 + grsec_enable_brute = 1;
74910 +#endif
74911 +#ifdef CONFIG_GRKERNSEC_DMESG
74912 + grsec_enable_dmesg = 1;
74913 +#endif
74914 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74915 + grsec_enable_blackhole = 1;
74916 + grsec_lastack_retries = 4;
74917 +#endif
74918 +#ifdef CONFIG_GRKERNSEC_FIFO
74919 + grsec_enable_fifo = 1;
74920 +#endif
74921 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74922 + grsec_enable_execlog = 1;
74923 +#endif
74924 +#ifdef CONFIG_GRKERNSEC_SETXID
74925 + grsec_enable_setxid = 1;
74926 +#endif
74927 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74928 + grsec_enable_signal = 1;
74929 +#endif
74930 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74931 + grsec_enable_forkfail = 1;
74932 +#endif
74933 +#ifdef CONFIG_GRKERNSEC_TIME
74934 + grsec_enable_time = 1;
74935 +#endif
74936 +#ifdef CONFIG_GRKERNSEC_RESLOG
74937 + grsec_resource_logging = 1;
74938 +#endif
74939 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74940 + grsec_enable_chroot_findtask = 1;
74941 +#endif
74942 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74943 + grsec_enable_chroot_unix = 1;
74944 +#endif
74945 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74946 + grsec_enable_chroot_mount = 1;
74947 +#endif
74948 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74949 + grsec_enable_chroot_fchdir = 1;
74950 +#endif
74951 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74952 + grsec_enable_chroot_shmat = 1;
74953 +#endif
74954 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74955 + grsec_enable_audit_ptrace = 1;
74956 +#endif
74957 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74958 + grsec_enable_chroot_double = 1;
74959 +#endif
74960 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74961 + grsec_enable_chroot_pivot = 1;
74962 +#endif
74963 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74964 + grsec_enable_chroot_chdir = 1;
74965 +#endif
74966 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74967 + grsec_enable_chroot_chmod = 1;
74968 +#endif
74969 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74970 + grsec_enable_chroot_mknod = 1;
74971 +#endif
74972 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74973 + grsec_enable_chroot_nice = 1;
74974 +#endif
74975 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74976 + grsec_enable_chroot_execlog = 1;
74977 +#endif
74978 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74979 + grsec_enable_chroot_caps = 1;
74980 +#endif
74981 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74982 + grsec_enable_chroot_sysctl = 1;
74983 +#endif
74984 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74985 + grsec_enable_symlinkown = 1;
74986 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74987 +#endif
74988 +#ifdef CONFIG_GRKERNSEC_TPE
74989 + grsec_enable_tpe = 1;
74990 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74991 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74992 + grsec_enable_tpe_all = 1;
74993 +#endif
74994 +#endif
74995 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74996 + grsec_enable_socket_all = 1;
74997 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74998 +#endif
74999 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75000 + grsec_enable_socket_client = 1;
75001 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
75002 +#endif
75003 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75004 + grsec_enable_socket_server = 1;
75005 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
75006 +#endif
75007 +#endif
75008 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
75009 + grsec_deny_new_usb = 1;
75010 +#endif
75011 +
75012 + return;
75013 +}
75014 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
75015 new file mode 100644
75016 index 0000000..1773300
75017 --- /dev/null
75018 +++ b/grsecurity/grsec_ipc.c
75019 @@ -0,0 +1,48 @@
75020 +#include <linux/kernel.h>
75021 +#include <linux/mm.h>
75022 +#include <linux/sched.h>
75023 +#include <linux/file.h>
75024 +#include <linux/ipc.h>
75025 +#include <linux/ipc_namespace.h>
75026 +#include <linux/grsecurity.h>
75027 +#include <linux/grinternal.h>
75028 +
75029 +int
75030 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
75031 +{
75032 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75033 + int write;
75034 + int orig_granted_mode;
75035 + kuid_t euid;
75036 + kgid_t egid;
75037 +
75038 + if (!grsec_enable_harden_ipc)
75039 + return 1;
75040 +
75041 + euid = current_euid();
75042 + egid = current_egid();
75043 +
75044 + write = requested_mode & 00002;
75045 + orig_granted_mode = ipcp->mode;
75046 +
75047 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
75048 + orig_granted_mode >>= 6;
75049 + else {
75050 + /* if likely wrong permissions, lock to user */
75051 + if (orig_granted_mode & 0007)
75052 + orig_granted_mode = 0;
75053 + /* otherwise do a egid-only check */
75054 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
75055 + orig_granted_mode >>= 3;
75056 + /* otherwise, no access */
75057 + else
75058 + orig_granted_mode = 0;
75059 + }
75060 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
75061 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
75062 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
75063 + return 0;
75064 + }
75065 +#endif
75066 + return 1;
75067 +}
75068 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
75069 new file mode 100644
75070 index 0000000..5e05e20
75071 --- /dev/null
75072 +++ b/grsecurity/grsec_link.c
75073 @@ -0,0 +1,58 @@
75074 +#include <linux/kernel.h>
75075 +#include <linux/sched.h>
75076 +#include <linux/fs.h>
75077 +#include <linux/file.h>
75078 +#include <linux/grinternal.h>
75079 +
75080 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
75081 +{
75082 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75083 + const struct inode *link_inode = link->dentry->d_inode;
75084 +
75085 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
75086 + /* ignore root-owned links, e.g. /proc/self */
75087 + gr_is_global_nonroot(link_inode->i_uid) && target &&
75088 + !uid_eq(link_inode->i_uid, target->i_uid)) {
75089 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
75090 + return 1;
75091 + }
75092 +#endif
75093 + return 0;
75094 +}
75095 +
75096 +int
75097 +gr_handle_follow_link(const struct inode *parent,
75098 + const struct inode *inode,
75099 + const struct dentry *dentry, const struct vfsmount *mnt)
75100 +{
75101 +#ifdef CONFIG_GRKERNSEC_LINK
75102 + const struct cred *cred = current_cred();
75103 +
75104 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
75105 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
75106 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
75107 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
75108 + return -EACCES;
75109 + }
75110 +#endif
75111 + return 0;
75112 +}
75113 +
75114 +int
75115 +gr_handle_hardlink(const struct dentry *dentry,
75116 + const struct vfsmount *mnt,
75117 + struct inode *inode, const int mode, const struct filename *to)
75118 +{
75119 +#ifdef CONFIG_GRKERNSEC_LINK
75120 + const struct cred *cred = current_cred();
75121 +
75122 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
75123 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
75124 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
75125 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
75126 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
75127 + return -EPERM;
75128 + }
75129 +#endif
75130 + return 0;
75131 +}
75132 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
75133 new file mode 100644
75134 index 0000000..dbe0a6b
75135 --- /dev/null
75136 +++ b/grsecurity/grsec_log.c
75137 @@ -0,0 +1,341 @@
75138 +#include <linux/kernel.h>
75139 +#include <linux/sched.h>
75140 +#include <linux/file.h>
75141 +#include <linux/tty.h>
75142 +#include <linux/fs.h>
75143 +#include <linux/mm.h>
75144 +#include <linux/grinternal.h>
75145 +
75146 +#ifdef CONFIG_TREE_PREEMPT_RCU
75147 +#define DISABLE_PREEMPT() preempt_disable()
75148 +#define ENABLE_PREEMPT() preempt_enable()
75149 +#else
75150 +#define DISABLE_PREEMPT()
75151 +#define ENABLE_PREEMPT()
75152 +#endif
75153 +
75154 +#define BEGIN_LOCKS(x) \
75155 + DISABLE_PREEMPT(); \
75156 + rcu_read_lock(); \
75157 + read_lock(&tasklist_lock); \
75158 + read_lock(&grsec_exec_file_lock); \
75159 + if (x != GR_DO_AUDIT) \
75160 + spin_lock(&grsec_alert_lock); \
75161 + else \
75162 + spin_lock(&grsec_audit_lock)
75163 +
75164 +#define END_LOCKS(x) \
75165 + if (x != GR_DO_AUDIT) \
75166 + spin_unlock(&grsec_alert_lock); \
75167 + else \
75168 + spin_unlock(&grsec_audit_lock); \
75169 + read_unlock(&grsec_exec_file_lock); \
75170 + read_unlock(&tasklist_lock); \
75171 + rcu_read_unlock(); \
75172 + ENABLE_PREEMPT(); \
75173 + if (x == GR_DONT_AUDIT) \
75174 + gr_handle_alertkill(current)
75175 +
75176 +enum {
75177 + FLOODING,
75178 + NO_FLOODING
75179 +};
75180 +
75181 +extern char *gr_alert_log_fmt;
75182 +extern char *gr_audit_log_fmt;
75183 +extern char *gr_alert_log_buf;
75184 +extern char *gr_audit_log_buf;
75185 +
75186 +static int gr_log_start(int audit)
75187 +{
75188 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75189 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75190 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75191 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75192 + unsigned long curr_secs = get_seconds();
75193 +
75194 + if (audit == GR_DO_AUDIT)
75195 + goto set_fmt;
75196 +
75197 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75198 + grsec_alert_wtime = curr_secs;
75199 + grsec_alert_fyet = 0;
75200 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75201 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75202 + grsec_alert_fyet++;
75203 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75204 + grsec_alert_wtime = curr_secs;
75205 + grsec_alert_fyet++;
75206 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75207 + return FLOODING;
75208 + }
75209 + else return FLOODING;
75210 +
75211 +set_fmt:
75212 +#endif
75213 + memset(buf, 0, PAGE_SIZE);
75214 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
75215 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75216 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75217 + } else if (current->signal->curr_ip) {
75218 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75219 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75220 + } else if (gr_acl_is_enabled()) {
75221 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75222 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75223 + } else {
75224 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
75225 + strcpy(buf, fmt);
75226 + }
75227 +
75228 + return NO_FLOODING;
75229 +}
75230 +
75231 +static void gr_log_middle(int audit, const char *msg, va_list ap)
75232 + __attribute__ ((format (printf, 2, 0)));
75233 +
75234 +static void gr_log_middle(int audit, const char *msg, va_list ap)
75235 +{
75236 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75237 + unsigned int len = strlen(buf);
75238 +
75239 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75240 +
75241 + return;
75242 +}
75243 +
75244 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
75245 + __attribute__ ((format (printf, 2, 3)));
75246 +
75247 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
75248 +{
75249 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75250 + unsigned int len = strlen(buf);
75251 + va_list ap;
75252 +
75253 + va_start(ap, msg);
75254 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75255 + va_end(ap);
75256 +
75257 + return;
75258 +}
75259 +
75260 +static void gr_log_end(int audit, int append_default)
75261 +{
75262 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75263 + if (append_default) {
75264 + struct task_struct *task = current;
75265 + struct task_struct *parent = task->real_parent;
75266 + const struct cred *cred = __task_cred(task);
75267 + const struct cred *pcred = __task_cred(parent);
75268 + unsigned int len = strlen(buf);
75269 +
75270 + 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));
75271 + }
75272 +
75273 + printk("%s\n", buf);
75274 +
75275 + return;
75276 +}
75277 +
75278 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75279 +{
75280 + int logtype;
75281 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75282 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75283 + void *voidptr = NULL;
75284 + int num1 = 0, num2 = 0;
75285 + unsigned long ulong1 = 0, ulong2 = 0;
75286 + struct dentry *dentry = NULL;
75287 + struct vfsmount *mnt = NULL;
75288 + struct file *file = NULL;
75289 + struct task_struct *task = NULL;
75290 + struct vm_area_struct *vma = NULL;
75291 + const struct cred *cred, *pcred;
75292 + va_list ap;
75293 +
75294 + BEGIN_LOCKS(audit);
75295 + logtype = gr_log_start(audit);
75296 + if (logtype == FLOODING) {
75297 + END_LOCKS(audit);
75298 + return;
75299 + }
75300 + va_start(ap, argtypes);
75301 + switch (argtypes) {
75302 + case GR_TTYSNIFF:
75303 + task = va_arg(ap, struct task_struct *);
75304 + 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));
75305 + break;
75306 + case GR_SYSCTL_HIDDEN:
75307 + str1 = va_arg(ap, char *);
75308 + gr_log_middle_varargs(audit, msg, result, str1);
75309 + break;
75310 + case GR_RBAC:
75311 + dentry = va_arg(ap, struct dentry *);
75312 + mnt = va_arg(ap, struct vfsmount *);
75313 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75314 + break;
75315 + case GR_RBAC_STR:
75316 + dentry = va_arg(ap, struct dentry *);
75317 + mnt = va_arg(ap, struct vfsmount *);
75318 + str1 = va_arg(ap, char *);
75319 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75320 + break;
75321 + case GR_STR_RBAC:
75322 + str1 = va_arg(ap, char *);
75323 + dentry = va_arg(ap, struct dentry *);
75324 + mnt = va_arg(ap, struct vfsmount *);
75325 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75326 + break;
75327 + case GR_RBAC_MODE2:
75328 + dentry = va_arg(ap, struct dentry *);
75329 + mnt = va_arg(ap, struct vfsmount *);
75330 + str1 = va_arg(ap, char *);
75331 + str2 = va_arg(ap, char *);
75332 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75333 + break;
75334 + case GR_RBAC_MODE3:
75335 + dentry = va_arg(ap, struct dentry *);
75336 + mnt = va_arg(ap, struct vfsmount *);
75337 + str1 = va_arg(ap, char *);
75338 + str2 = va_arg(ap, char *);
75339 + str3 = va_arg(ap, char *);
75340 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75341 + break;
75342 + case GR_FILENAME:
75343 + dentry = va_arg(ap, struct dentry *);
75344 + mnt = va_arg(ap, struct vfsmount *);
75345 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75346 + break;
75347 + case GR_STR_FILENAME:
75348 + str1 = va_arg(ap, char *);
75349 + dentry = va_arg(ap, struct dentry *);
75350 + mnt = va_arg(ap, struct vfsmount *);
75351 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75352 + break;
75353 + case GR_FILENAME_STR:
75354 + dentry = va_arg(ap, struct dentry *);
75355 + mnt = va_arg(ap, struct vfsmount *);
75356 + str1 = va_arg(ap, char *);
75357 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75358 + break;
75359 + case GR_FILENAME_TWO_INT:
75360 + dentry = va_arg(ap, struct dentry *);
75361 + mnt = va_arg(ap, struct vfsmount *);
75362 + num1 = va_arg(ap, int);
75363 + num2 = va_arg(ap, int);
75364 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75365 + break;
75366 + case GR_FILENAME_TWO_INT_STR:
75367 + dentry = va_arg(ap, struct dentry *);
75368 + mnt = va_arg(ap, struct vfsmount *);
75369 + num1 = va_arg(ap, int);
75370 + num2 = va_arg(ap, int);
75371 + str1 = va_arg(ap, char *);
75372 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75373 + break;
75374 + case GR_TEXTREL:
75375 + file = va_arg(ap, struct file *);
75376 + ulong1 = va_arg(ap, unsigned long);
75377 + ulong2 = va_arg(ap, unsigned long);
75378 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75379 + break;
75380 + case GR_PTRACE:
75381 + task = va_arg(ap, struct task_struct *);
75382 + 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));
75383 + break;
75384 + case GR_RESOURCE:
75385 + task = va_arg(ap, struct task_struct *);
75386 + cred = __task_cred(task);
75387 + pcred = __task_cred(task->real_parent);
75388 + ulong1 = va_arg(ap, unsigned long);
75389 + str1 = va_arg(ap, char *);
75390 + ulong2 = va_arg(ap, unsigned long);
75391 + 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));
75392 + break;
75393 + case GR_CAP:
75394 + task = va_arg(ap, struct task_struct *);
75395 + cred = __task_cred(task);
75396 + pcred = __task_cred(task->real_parent);
75397 + str1 = va_arg(ap, char *);
75398 + 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));
75399 + break;
75400 + case GR_SIG:
75401 + str1 = va_arg(ap, char *);
75402 + voidptr = va_arg(ap, void *);
75403 + gr_log_middle_varargs(audit, msg, str1, voidptr);
75404 + break;
75405 + case GR_SIG2:
75406 + task = va_arg(ap, struct task_struct *);
75407 + cred = __task_cred(task);
75408 + pcred = __task_cred(task->real_parent);
75409 + num1 = va_arg(ap, int);
75410 + 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));
75411 + break;
75412 + case GR_CRASH1:
75413 + task = va_arg(ap, struct task_struct *);
75414 + cred = __task_cred(task);
75415 + pcred = __task_cred(task->real_parent);
75416 + ulong1 = va_arg(ap, unsigned long);
75417 + 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);
75418 + break;
75419 + case GR_CRASH2:
75420 + task = va_arg(ap, struct task_struct *);
75421 + cred = __task_cred(task);
75422 + pcred = __task_cred(task->real_parent);
75423 + ulong1 = va_arg(ap, unsigned long);
75424 + 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);
75425 + break;
75426 + case GR_RWXMAP:
75427 + file = va_arg(ap, struct file *);
75428 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75429 + break;
75430 + case GR_RWXMAPVMA:
75431 + vma = va_arg(ap, struct vm_area_struct *);
75432 + if (vma->vm_file)
75433 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75434 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75435 + str1 = "<stack>";
75436 + else if (vma->vm_start <= current->mm->brk &&
75437 + vma->vm_end >= current->mm->start_brk)
75438 + str1 = "<heap>";
75439 + else
75440 + str1 = "<anonymous mapping>";
75441 + gr_log_middle_varargs(audit, msg, str1);
75442 + break;
75443 + case GR_PSACCT:
75444 + {
75445 + unsigned int wday, cday;
75446 + __u8 whr, chr;
75447 + __u8 wmin, cmin;
75448 + __u8 wsec, csec;
75449 + char cur_tty[64] = { 0 };
75450 + char parent_tty[64] = { 0 };
75451 +
75452 + task = va_arg(ap, struct task_struct *);
75453 + wday = va_arg(ap, unsigned int);
75454 + cday = va_arg(ap, unsigned int);
75455 + whr = va_arg(ap, int);
75456 + chr = va_arg(ap, int);
75457 + wmin = va_arg(ap, int);
75458 + cmin = va_arg(ap, int);
75459 + wsec = va_arg(ap, int);
75460 + csec = va_arg(ap, int);
75461 + ulong1 = va_arg(ap, unsigned long);
75462 + cred = __task_cred(task);
75463 + pcred = __task_cred(task->real_parent);
75464 +
75465 + 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));
75466 + }
75467 + break;
75468 + default:
75469 + gr_log_middle(audit, msg, ap);
75470 + }
75471 + va_end(ap);
75472 + // these don't need DEFAULTSECARGS printed on the end
75473 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75474 + gr_log_end(audit, 0);
75475 + else
75476 + gr_log_end(audit, 1);
75477 + END_LOCKS(audit);
75478 +}
75479 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75480 new file mode 100644
75481 index 0000000..0e39d8c
75482 --- /dev/null
75483 +++ b/grsecurity/grsec_mem.c
75484 @@ -0,0 +1,48 @@
75485 +#include <linux/kernel.h>
75486 +#include <linux/sched.h>
75487 +#include <linux/mm.h>
75488 +#include <linux/mman.h>
75489 +#include <linux/module.h>
75490 +#include <linux/grinternal.h>
75491 +
75492 +void gr_handle_msr_write(void)
75493 +{
75494 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75495 + return;
75496 +}
75497 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75498 +
75499 +void
75500 +gr_handle_ioperm(void)
75501 +{
75502 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75503 + return;
75504 +}
75505 +
75506 +void
75507 +gr_handle_iopl(void)
75508 +{
75509 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75510 + return;
75511 +}
75512 +
75513 +void
75514 +gr_handle_mem_readwrite(u64 from, u64 to)
75515 +{
75516 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75517 + return;
75518 +}
75519 +
75520 +void
75521 +gr_handle_vm86(void)
75522 +{
75523 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75524 + return;
75525 +}
75526 +
75527 +void
75528 +gr_log_badprocpid(const char *entry)
75529 +{
75530 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75531 + return;
75532 +}
75533 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75534 new file mode 100644
75535 index 0000000..cd9e124
75536 --- /dev/null
75537 +++ b/grsecurity/grsec_mount.c
75538 @@ -0,0 +1,65 @@
75539 +#include <linux/kernel.h>
75540 +#include <linux/sched.h>
75541 +#include <linux/mount.h>
75542 +#include <linux/major.h>
75543 +#include <linux/grsecurity.h>
75544 +#include <linux/grinternal.h>
75545 +
75546 +void
75547 +gr_log_remount(const char *devname, const int retval)
75548 +{
75549 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75550 + if (grsec_enable_mount && (retval >= 0))
75551 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75552 +#endif
75553 + return;
75554 +}
75555 +
75556 +void
75557 +gr_log_unmount(const char *devname, const int retval)
75558 +{
75559 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75560 + if (grsec_enable_mount && (retval >= 0))
75561 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75562 +#endif
75563 + return;
75564 +}
75565 +
75566 +void
75567 +gr_log_mount(const char *from, const char *to, const int retval)
75568 +{
75569 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75570 + if (grsec_enable_mount && (retval >= 0))
75571 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75572 +#endif
75573 + return;
75574 +}
75575 +
75576 +int
75577 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75578 +{
75579 +#ifdef CONFIG_GRKERNSEC_ROFS
75580 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75581 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75582 + return -EPERM;
75583 + } else
75584 + return 0;
75585 +#endif
75586 + return 0;
75587 +}
75588 +
75589 +int
75590 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75591 +{
75592 +#ifdef CONFIG_GRKERNSEC_ROFS
75593 + struct inode *inode = dentry->d_inode;
75594 +
75595 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75596 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75597 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75598 + return -EPERM;
75599 + } else
75600 + return 0;
75601 +#endif
75602 + return 0;
75603 +}
75604 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75605 new file mode 100644
75606 index 0000000..6ee9d50
75607 --- /dev/null
75608 +++ b/grsecurity/grsec_pax.c
75609 @@ -0,0 +1,45 @@
75610 +#include <linux/kernel.h>
75611 +#include <linux/sched.h>
75612 +#include <linux/mm.h>
75613 +#include <linux/file.h>
75614 +#include <linux/grinternal.h>
75615 +#include <linux/grsecurity.h>
75616 +
75617 +void
75618 +gr_log_textrel(struct vm_area_struct * vma)
75619 +{
75620 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75621 + if (grsec_enable_log_rwxmaps)
75622 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75623 +#endif
75624 + return;
75625 +}
75626 +
75627 +void gr_log_ptgnustack(struct file *file)
75628 +{
75629 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75630 + if (grsec_enable_log_rwxmaps)
75631 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75632 +#endif
75633 + return;
75634 +}
75635 +
75636 +void
75637 +gr_log_rwxmmap(struct file *file)
75638 +{
75639 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75640 + if (grsec_enable_log_rwxmaps)
75641 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75642 +#endif
75643 + return;
75644 +}
75645 +
75646 +void
75647 +gr_log_rwxmprotect(struct vm_area_struct *vma)
75648 +{
75649 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75650 + if (grsec_enable_log_rwxmaps)
75651 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75652 +#endif
75653 + return;
75654 +}
75655 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75656 new file mode 100644
75657 index 0000000..2005a3a
75658 --- /dev/null
75659 +++ b/grsecurity/grsec_proc.c
75660 @@ -0,0 +1,20 @@
75661 +#include <linux/kernel.h>
75662 +#include <linux/sched.h>
75663 +#include <linux/grsecurity.h>
75664 +#include <linux/grinternal.h>
75665 +
75666 +int gr_proc_is_restricted(void)
75667 +{
75668 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75669 + const struct cred *cred = current_cred();
75670 +#endif
75671 +
75672 +#ifdef CONFIG_GRKERNSEC_PROC_USER
75673 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75674 + return -EACCES;
75675 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75676 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75677 + return -EACCES;
75678 +#endif
75679 + return 0;
75680 +}
75681 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75682 new file mode 100644
75683 index 0000000..f7f29aa
75684 --- /dev/null
75685 +++ b/grsecurity/grsec_ptrace.c
75686 @@ -0,0 +1,30 @@
75687 +#include <linux/kernel.h>
75688 +#include <linux/sched.h>
75689 +#include <linux/grinternal.h>
75690 +#include <linux/security.h>
75691 +
75692 +void
75693 +gr_audit_ptrace(struct task_struct *task)
75694 +{
75695 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75696 + if (grsec_enable_audit_ptrace)
75697 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75698 +#endif
75699 + return;
75700 +}
75701 +
75702 +int
75703 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
75704 +{
75705 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75706 + const struct dentry *dentry = file->f_path.dentry;
75707 + const struct vfsmount *mnt = file->f_path.mnt;
75708 +
75709 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75710 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75711 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75712 + return -EACCES;
75713 + }
75714 +#endif
75715 + return 0;
75716 +}
75717 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75718 new file mode 100644
75719 index 0000000..3860c7e
75720 --- /dev/null
75721 +++ b/grsecurity/grsec_sig.c
75722 @@ -0,0 +1,236 @@
75723 +#include <linux/kernel.h>
75724 +#include <linux/sched.h>
75725 +#include <linux/fs.h>
75726 +#include <linux/delay.h>
75727 +#include <linux/grsecurity.h>
75728 +#include <linux/grinternal.h>
75729 +#include <linux/hardirq.h>
75730 +
75731 +char *signames[] = {
75732 + [SIGSEGV] = "Segmentation fault",
75733 + [SIGILL] = "Illegal instruction",
75734 + [SIGABRT] = "Abort",
75735 + [SIGBUS] = "Invalid alignment/Bus error"
75736 +};
75737 +
75738 +void
75739 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75740 +{
75741 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75742 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75743 + (sig == SIGABRT) || (sig == SIGBUS))) {
75744 + if (task_pid_nr(t) == task_pid_nr(current)) {
75745 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75746 + } else {
75747 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75748 + }
75749 + }
75750 +#endif
75751 + return;
75752 +}
75753 +
75754 +int
75755 +gr_handle_signal(const struct task_struct *p, const int sig)
75756 +{
75757 +#ifdef CONFIG_GRKERNSEC
75758 + /* ignore the 0 signal for protected task checks */
75759 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75760 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75761 + return -EPERM;
75762 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75763 + return -EPERM;
75764 + }
75765 +#endif
75766 + return 0;
75767 +}
75768 +
75769 +#ifdef CONFIG_GRKERNSEC
75770 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75771 +
75772 +int gr_fake_force_sig(int sig, struct task_struct *t)
75773 +{
75774 + unsigned long int flags;
75775 + int ret, blocked, ignored;
75776 + struct k_sigaction *action;
75777 +
75778 + spin_lock_irqsave(&t->sighand->siglock, flags);
75779 + action = &t->sighand->action[sig-1];
75780 + ignored = action->sa.sa_handler == SIG_IGN;
75781 + blocked = sigismember(&t->blocked, sig);
75782 + if (blocked || ignored) {
75783 + action->sa.sa_handler = SIG_DFL;
75784 + if (blocked) {
75785 + sigdelset(&t->blocked, sig);
75786 + recalc_sigpending_and_wake(t);
75787 + }
75788 + }
75789 + if (action->sa.sa_handler == SIG_DFL)
75790 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
75791 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75792 +
75793 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
75794 +
75795 + return ret;
75796 +}
75797 +#endif
75798 +
75799 +#define GR_USER_BAN_TIME (15 * 60)
75800 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
75801 +
75802 +void gr_handle_brute_attach(int dumpable)
75803 +{
75804 +#ifdef CONFIG_GRKERNSEC_BRUTE
75805 + struct task_struct *p = current;
75806 + kuid_t uid = GLOBAL_ROOT_UID;
75807 + int daemon = 0;
75808 +
75809 + if (!grsec_enable_brute)
75810 + return;
75811 +
75812 + rcu_read_lock();
75813 + read_lock(&tasklist_lock);
75814 + read_lock(&grsec_exec_file_lock);
75815 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75816 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75817 + p->real_parent->brute = 1;
75818 + daemon = 1;
75819 + } else {
75820 + const struct cred *cred = __task_cred(p), *cred2;
75821 + struct task_struct *tsk, *tsk2;
75822 +
75823 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75824 + struct user_struct *user;
75825 +
75826 + uid = cred->uid;
75827 +
75828 + /* this is put upon execution past expiration */
75829 + user = find_user(uid);
75830 + if (user == NULL)
75831 + goto unlock;
75832 + user->suid_banned = 1;
75833 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75834 + if (user->suid_ban_expires == ~0UL)
75835 + user->suid_ban_expires--;
75836 +
75837 + /* only kill other threads of the same binary, from the same user */
75838 + do_each_thread(tsk2, tsk) {
75839 + cred2 = __task_cred(tsk);
75840 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75841 + gr_fake_force_sig(SIGKILL, tsk);
75842 + } while_each_thread(tsk2, tsk);
75843 + }
75844 + }
75845 +unlock:
75846 + read_unlock(&grsec_exec_file_lock);
75847 + read_unlock(&tasklist_lock);
75848 + rcu_read_unlock();
75849 +
75850 + if (gr_is_global_nonroot(uid))
75851 + 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);
75852 + else if (daemon)
75853 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75854 +
75855 +#endif
75856 + return;
75857 +}
75858 +
75859 +void gr_handle_brute_check(void)
75860 +{
75861 +#ifdef CONFIG_GRKERNSEC_BRUTE
75862 + struct task_struct *p = current;
75863 +
75864 + if (unlikely(p->brute)) {
75865 + if (!grsec_enable_brute)
75866 + p->brute = 0;
75867 + else if (time_before(get_seconds(), p->brute_expires))
75868 + msleep(30 * 1000);
75869 + }
75870 +#endif
75871 + return;
75872 +}
75873 +
75874 +void gr_handle_kernel_exploit(void)
75875 +{
75876 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75877 + const struct cred *cred;
75878 + struct task_struct *tsk, *tsk2;
75879 + struct user_struct *user;
75880 + kuid_t uid;
75881 +
75882 + if (in_irq() || in_serving_softirq() || in_nmi())
75883 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75884 +
75885 + uid = current_uid();
75886 +
75887 + if (gr_is_global_root(uid))
75888 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
75889 + else {
75890 + /* kill all the processes of this user, hold a reference
75891 + to their creds struct, and prevent them from creating
75892 + another process until system reset
75893 + */
75894 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75895 + GR_GLOBAL_UID(uid));
75896 + /* we intentionally leak this ref */
75897 + user = get_uid(current->cred->user);
75898 + if (user)
75899 + user->kernel_banned = 1;
75900 +
75901 + /* kill all processes of this user */
75902 + read_lock(&tasklist_lock);
75903 + do_each_thread(tsk2, tsk) {
75904 + cred = __task_cred(tsk);
75905 + if (uid_eq(cred->uid, uid))
75906 + gr_fake_force_sig(SIGKILL, tsk);
75907 + } while_each_thread(tsk2, tsk);
75908 + read_unlock(&tasklist_lock);
75909 + }
75910 +#endif
75911 +}
75912 +
75913 +#ifdef CONFIG_GRKERNSEC_BRUTE
75914 +static bool suid_ban_expired(struct user_struct *user)
75915 +{
75916 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75917 + user->suid_banned = 0;
75918 + user->suid_ban_expires = 0;
75919 + free_uid(user);
75920 + return true;
75921 + }
75922 +
75923 + return false;
75924 +}
75925 +#endif
75926 +
75927 +int gr_process_kernel_exec_ban(void)
75928 +{
75929 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75930 + if (unlikely(current->cred->user->kernel_banned))
75931 + return -EPERM;
75932 +#endif
75933 + return 0;
75934 +}
75935 +
75936 +int gr_process_kernel_setuid_ban(struct user_struct *user)
75937 +{
75938 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75939 + if (unlikely(user->kernel_banned))
75940 + gr_fake_force_sig(SIGKILL, current);
75941 +#endif
75942 + return 0;
75943 +}
75944 +
75945 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75946 +{
75947 +#ifdef CONFIG_GRKERNSEC_BRUTE
75948 + struct user_struct *user = current->cred->user;
75949 + if (unlikely(user->suid_banned)) {
75950 + if (suid_ban_expired(user))
75951 + return 0;
75952 + /* disallow execution of suid binaries only */
75953 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75954 + return -EPERM;
75955 + }
75956 +#endif
75957 + return 0;
75958 +}
75959 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75960 new file mode 100644
75961 index 0000000..c0aef3a
75962 --- /dev/null
75963 +++ b/grsecurity/grsec_sock.c
75964 @@ -0,0 +1,244 @@
75965 +#include <linux/kernel.h>
75966 +#include <linux/module.h>
75967 +#include <linux/sched.h>
75968 +#include <linux/file.h>
75969 +#include <linux/net.h>
75970 +#include <linux/in.h>
75971 +#include <linux/ip.h>
75972 +#include <net/sock.h>
75973 +#include <net/inet_sock.h>
75974 +#include <linux/grsecurity.h>
75975 +#include <linux/grinternal.h>
75976 +#include <linux/gracl.h>
75977 +
75978 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75979 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75980 +
75981 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75982 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75983 +
75984 +#ifdef CONFIG_UNIX_MODULE
75985 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75986 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75987 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75988 +EXPORT_SYMBOL_GPL(gr_handle_create);
75989 +#endif
75990 +
75991 +#ifdef CONFIG_GRKERNSEC
75992 +#define gr_conn_table_size 32749
75993 +struct conn_table_entry {
75994 + struct conn_table_entry *next;
75995 + struct signal_struct *sig;
75996 +};
75997 +
75998 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75999 +DEFINE_SPINLOCK(gr_conn_table_lock);
76000 +
76001 +extern const char * gr_socktype_to_name(unsigned char type);
76002 +extern const char * gr_proto_to_name(unsigned char proto);
76003 +extern const char * gr_sockfamily_to_name(unsigned char family);
76004 +
76005 +static __inline__ int
76006 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
76007 +{
76008 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
76009 +}
76010 +
76011 +static __inline__ int
76012 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
76013 + __u16 sport, __u16 dport)
76014 +{
76015 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
76016 + sig->gr_sport == sport && sig->gr_dport == dport))
76017 + return 1;
76018 + else
76019 + return 0;
76020 +}
76021 +
76022 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
76023 +{
76024 + struct conn_table_entry **match;
76025 + unsigned int index;
76026 +
76027 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76028 + sig->gr_sport, sig->gr_dport,
76029 + gr_conn_table_size);
76030 +
76031 + newent->sig = sig;
76032 +
76033 + match = &gr_conn_table[index];
76034 + newent->next = *match;
76035 + *match = newent;
76036 +
76037 + return;
76038 +}
76039 +
76040 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
76041 +{
76042 + struct conn_table_entry *match, *last = NULL;
76043 + unsigned int index;
76044 +
76045 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
76046 + sig->gr_sport, sig->gr_dport,
76047 + gr_conn_table_size);
76048 +
76049 + match = gr_conn_table[index];
76050 + while (match && !conn_match(match->sig,
76051 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
76052 + sig->gr_dport)) {
76053 + last = match;
76054 + match = match->next;
76055 + }
76056 +
76057 + if (match) {
76058 + if (last)
76059 + last->next = match->next;
76060 + else
76061 + gr_conn_table[index] = NULL;
76062 + kfree(match);
76063 + }
76064 +
76065 + return;
76066 +}
76067 +
76068 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
76069 + __u16 sport, __u16 dport)
76070 +{
76071 + struct conn_table_entry *match;
76072 + unsigned int index;
76073 +
76074 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
76075 +
76076 + match = gr_conn_table[index];
76077 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
76078 + match = match->next;
76079 +
76080 + if (match)
76081 + return match->sig;
76082 + else
76083 + return NULL;
76084 +}
76085 +
76086 +#endif
76087 +
76088 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
76089 +{
76090 +#ifdef CONFIG_GRKERNSEC
76091 + struct signal_struct *sig = task->signal;
76092 + struct conn_table_entry *newent;
76093 +
76094 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
76095 + if (newent == NULL)
76096 + return;
76097 + /* no bh lock needed since we are called with bh disabled */
76098 + spin_lock(&gr_conn_table_lock);
76099 + gr_del_task_from_ip_table_nolock(sig);
76100 + sig->gr_saddr = inet->inet_rcv_saddr;
76101 + sig->gr_daddr = inet->inet_daddr;
76102 + sig->gr_sport = inet->inet_sport;
76103 + sig->gr_dport = inet->inet_dport;
76104 + gr_add_to_task_ip_table_nolock(sig, newent);
76105 + spin_unlock(&gr_conn_table_lock);
76106 +#endif
76107 + return;
76108 +}
76109 +
76110 +void gr_del_task_from_ip_table(struct task_struct *task)
76111 +{
76112 +#ifdef CONFIG_GRKERNSEC
76113 + spin_lock_bh(&gr_conn_table_lock);
76114 + gr_del_task_from_ip_table_nolock(task->signal);
76115 + spin_unlock_bh(&gr_conn_table_lock);
76116 +#endif
76117 + return;
76118 +}
76119 +
76120 +void
76121 +gr_attach_curr_ip(const struct sock *sk)
76122 +{
76123 +#ifdef CONFIG_GRKERNSEC
76124 + struct signal_struct *p, *set;
76125 + const struct inet_sock *inet = inet_sk(sk);
76126 +
76127 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
76128 + return;
76129 +
76130 + set = current->signal;
76131 +
76132 + spin_lock_bh(&gr_conn_table_lock);
76133 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
76134 + inet->inet_dport, inet->inet_sport);
76135 + if (unlikely(p != NULL)) {
76136 + set->curr_ip = p->curr_ip;
76137 + set->used_accept = 1;
76138 + gr_del_task_from_ip_table_nolock(p);
76139 + spin_unlock_bh(&gr_conn_table_lock);
76140 + return;
76141 + }
76142 + spin_unlock_bh(&gr_conn_table_lock);
76143 +
76144 + set->curr_ip = inet->inet_daddr;
76145 + set->used_accept = 1;
76146 +#endif
76147 + return;
76148 +}
76149 +
76150 +int
76151 +gr_handle_sock_all(const int family, const int type, const int protocol)
76152 +{
76153 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76154 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
76155 + (family != AF_UNIX)) {
76156 + if (family == AF_INET)
76157 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
76158 + else
76159 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
76160 + return -EACCES;
76161 + }
76162 +#endif
76163 + return 0;
76164 +}
76165 +
76166 +int
76167 +gr_handle_sock_server(const struct sockaddr *sck)
76168 +{
76169 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76170 + if (grsec_enable_socket_server &&
76171 + in_group_p(grsec_socket_server_gid) &&
76172 + sck && (sck->sa_family != AF_UNIX) &&
76173 + (sck->sa_family != AF_LOCAL)) {
76174 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76175 + return -EACCES;
76176 + }
76177 +#endif
76178 + return 0;
76179 +}
76180 +
76181 +int
76182 +gr_handle_sock_server_other(const struct sock *sck)
76183 +{
76184 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76185 + if (grsec_enable_socket_server &&
76186 + in_group_p(grsec_socket_server_gid) &&
76187 + sck && (sck->sk_family != AF_UNIX) &&
76188 + (sck->sk_family != AF_LOCAL)) {
76189 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76190 + return -EACCES;
76191 + }
76192 +#endif
76193 + return 0;
76194 +}
76195 +
76196 +int
76197 +gr_handle_sock_client(const struct sockaddr *sck)
76198 +{
76199 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76200 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76201 + sck && (sck->sa_family != AF_UNIX) &&
76202 + (sck->sa_family != AF_LOCAL)) {
76203 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76204 + return -EACCES;
76205 + }
76206 +#endif
76207 + return 0;
76208 +}
76209 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76210 new file mode 100644
76211 index 0000000..8159888
76212 --- /dev/null
76213 +++ b/grsecurity/grsec_sysctl.c
76214 @@ -0,0 +1,479 @@
76215 +#include <linux/kernel.h>
76216 +#include <linux/sched.h>
76217 +#include <linux/sysctl.h>
76218 +#include <linux/grsecurity.h>
76219 +#include <linux/grinternal.h>
76220 +
76221 +int
76222 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76223 +{
76224 +#ifdef CONFIG_GRKERNSEC_SYSCTL
76225 + if (dirname == NULL || name == NULL)
76226 + return 0;
76227 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76228 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76229 + return -EACCES;
76230 + }
76231 +#endif
76232 + return 0;
76233 +}
76234 +
76235 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76236 +static int __maybe_unused __read_only one = 1;
76237 +#endif
76238 +
76239 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76240 + defined(CONFIG_GRKERNSEC_DENYUSB)
76241 +struct ctl_table grsecurity_table[] = {
76242 +#ifdef CONFIG_GRKERNSEC_SYSCTL
76243 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76244 +#ifdef CONFIG_GRKERNSEC_IO
76245 + {
76246 + .procname = "disable_priv_io",
76247 + .data = &grsec_disable_privio,
76248 + .maxlen = sizeof(int),
76249 + .mode = 0600,
76250 + .proc_handler = &proc_dointvec,
76251 + },
76252 +#endif
76253 +#endif
76254 +#ifdef CONFIG_GRKERNSEC_LINK
76255 + {
76256 + .procname = "linking_restrictions",
76257 + .data = &grsec_enable_link,
76258 + .maxlen = sizeof(int),
76259 + .mode = 0600,
76260 + .proc_handler = &proc_dointvec,
76261 + },
76262 +#endif
76263 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76264 + {
76265 + .procname = "enforce_symlinksifowner",
76266 + .data = &grsec_enable_symlinkown,
76267 + .maxlen = sizeof(int),
76268 + .mode = 0600,
76269 + .proc_handler = &proc_dointvec,
76270 + },
76271 + {
76272 + .procname = "symlinkown_gid",
76273 + .data = &grsec_symlinkown_gid,
76274 + .maxlen = sizeof(int),
76275 + .mode = 0600,
76276 + .proc_handler = &proc_dointvec,
76277 + },
76278 +#endif
76279 +#ifdef CONFIG_GRKERNSEC_BRUTE
76280 + {
76281 + .procname = "deter_bruteforce",
76282 + .data = &grsec_enable_brute,
76283 + .maxlen = sizeof(int),
76284 + .mode = 0600,
76285 + .proc_handler = &proc_dointvec,
76286 + },
76287 +#endif
76288 +#ifdef CONFIG_GRKERNSEC_FIFO
76289 + {
76290 + .procname = "fifo_restrictions",
76291 + .data = &grsec_enable_fifo,
76292 + .maxlen = sizeof(int),
76293 + .mode = 0600,
76294 + .proc_handler = &proc_dointvec,
76295 + },
76296 +#endif
76297 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76298 + {
76299 + .procname = "ptrace_readexec",
76300 + .data = &grsec_enable_ptrace_readexec,
76301 + .maxlen = sizeof(int),
76302 + .mode = 0600,
76303 + .proc_handler = &proc_dointvec,
76304 + },
76305 +#endif
76306 +#ifdef CONFIG_GRKERNSEC_SETXID
76307 + {
76308 + .procname = "consistent_setxid",
76309 + .data = &grsec_enable_setxid,
76310 + .maxlen = sizeof(int),
76311 + .mode = 0600,
76312 + .proc_handler = &proc_dointvec,
76313 + },
76314 +#endif
76315 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76316 + {
76317 + .procname = "ip_blackhole",
76318 + .data = &grsec_enable_blackhole,
76319 + .maxlen = sizeof(int),
76320 + .mode = 0600,
76321 + .proc_handler = &proc_dointvec,
76322 + },
76323 + {
76324 + .procname = "lastack_retries",
76325 + .data = &grsec_lastack_retries,
76326 + .maxlen = sizeof(int),
76327 + .mode = 0600,
76328 + .proc_handler = &proc_dointvec,
76329 + },
76330 +#endif
76331 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76332 + {
76333 + .procname = "exec_logging",
76334 + .data = &grsec_enable_execlog,
76335 + .maxlen = sizeof(int),
76336 + .mode = 0600,
76337 + .proc_handler = &proc_dointvec,
76338 + },
76339 +#endif
76340 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76341 + {
76342 + .procname = "rwxmap_logging",
76343 + .data = &grsec_enable_log_rwxmaps,
76344 + .maxlen = sizeof(int),
76345 + .mode = 0600,
76346 + .proc_handler = &proc_dointvec,
76347 + },
76348 +#endif
76349 +#ifdef CONFIG_GRKERNSEC_SIGNAL
76350 + {
76351 + .procname = "signal_logging",
76352 + .data = &grsec_enable_signal,
76353 + .maxlen = sizeof(int),
76354 + .mode = 0600,
76355 + .proc_handler = &proc_dointvec,
76356 + },
76357 +#endif
76358 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
76359 + {
76360 + .procname = "forkfail_logging",
76361 + .data = &grsec_enable_forkfail,
76362 + .maxlen = sizeof(int),
76363 + .mode = 0600,
76364 + .proc_handler = &proc_dointvec,
76365 + },
76366 +#endif
76367 +#ifdef CONFIG_GRKERNSEC_TIME
76368 + {
76369 + .procname = "timechange_logging",
76370 + .data = &grsec_enable_time,
76371 + .maxlen = sizeof(int),
76372 + .mode = 0600,
76373 + .proc_handler = &proc_dointvec,
76374 + },
76375 +#endif
76376 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76377 + {
76378 + .procname = "chroot_deny_shmat",
76379 + .data = &grsec_enable_chroot_shmat,
76380 + .maxlen = sizeof(int),
76381 + .mode = 0600,
76382 + .proc_handler = &proc_dointvec,
76383 + },
76384 +#endif
76385 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76386 + {
76387 + .procname = "chroot_deny_unix",
76388 + .data = &grsec_enable_chroot_unix,
76389 + .maxlen = sizeof(int),
76390 + .mode = 0600,
76391 + .proc_handler = &proc_dointvec,
76392 + },
76393 +#endif
76394 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76395 + {
76396 + .procname = "chroot_deny_mount",
76397 + .data = &grsec_enable_chroot_mount,
76398 + .maxlen = sizeof(int),
76399 + .mode = 0600,
76400 + .proc_handler = &proc_dointvec,
76401 + },
76402 +#endif
76403 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76404 + {
76405 + .procname = "chroot_deny_fchdir",
76406 + .data = &grsec_enable_chroot_fchdir,
76407 + .maxlen = sizeof(int),
76408 + .mode = 0600,
76409 + .proc_handler = &proc_dointvec,
76410 + },
76411 +#endif
76412 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76413 + {
76414 + .procname = "chroot_deny_chroot",
76415 + .data = &grsec_enable_chroot_double,
76416 + .maxlen = sizeof(int),
76417 + .mode = 0600,
76418 + .proc_handler = &proc_dointvec,
76419 + },
76420 +#endif
76421 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76422 + {
76423 + .procname = "chroot_deny_pivot",
76424 + .data = &grsec_enable_chroot_pivot,
76425 + .maxlen = sizeof(int),
76426 + .mode = 0600,
76427 + .proc_handler = &proc_dointvec,
76428 + },
76429 +#endif
76430 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76431 + {
76432 + .procname = "chroot_enforce_chdir",
76433 + .data = &grsec_enable_chroot_chdir,
76434 + .maxlen = sizeof(int),
76435 + .mode = 0600,
76436 + .proc_handler = &proc_dointvec,
76437 + },
76438 +#endif
76439 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76440 + {
76441 + .procname = "chroot_deny_chmod",
76442 + .data = &grsec_enable_chroot_chmod,
76443 + .maxlen = sizeof(int),
76444 + .mode = 0600,
76445 + .proc_handler = &proc_dointvec,
76446 + },
76447 +#endif
76448 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76449 + {
76450 + .procname = "chroot_deny_mknod",
76451 + .data = &grsec_enable_chroot_mknod,
76452 + .maxlen = sizeof(int),
76453 + .mode = 0600,
76454 + .proc_handler = &proc_dointvec,
76455 + },
76456 +#endif
76457 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76458 + {
76459 + .procname = "chroot_restrict_nice",
76460 + .data = &grsec_enable_chroot_nice,
76461 + .maxlen = sizeof(int),
76462 + .mode = 0600,
76463 + .proc_handler = &proc_dointvec,
76464 + },
76465 +#endif
76466 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76467 + {
76468 + .procname = "chroot_execlog",
76469 + .data = &grsec_enable_chroot_execlog,
76470 + .maxlen = sizeof(int),
76471 + .mode = 0600,
76472 + .proc_handler = &proc_dointvec,
76473 + },
76474 +#endif
76475 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76476 + {
76477 + .procname = "chroot_caps",
76478 + .data = &grsec_enable_chroot_caps,
76479 + .maxlen = sizeof(int),
76480 + .mode = 0600,
76481 + .proc_handler = &proc_dointvec,
76482 + },
76483 +#endif
76484 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76485 + {
76486 + .procname = "chroot_deny_sysctl",
76487 + .data = &grsec_enable_chroot_sysctl,
76488 + .maxlen = sizeof(int),
76489 + .mode = 0600,
76490 + .proc_handler = &proc_dointvec,
76491 + },
76492 +#endif
76493 +#ifdef CONFIG_GRKERNSEC_TPE
76494 + {
76495 + .procname = "tpe",
76496 + .data = &grsec_enable_tpe,
76497 + .maxlen = sizeof(int),
76498 + .mode = 0600,
76499 + .proc_handler = &proc_dointvec,
76500 + },
76501 + {
76502 + .procname = "tpe_gid",
76503 + .data = &grsec_tpe_gid,
76504 + .maxlen = sizeof(int),
76505 + .mode = 0600,
76506 + .proc_handler = &proc_dointvec,
76507 + },
76508 +#endif
76509 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76510 + {
76511 + .procname = "tpe_invert",
76512 + .data = &grsec_enable_tpe_invert,
76513 + .maxlen = sizeof(int),
76514 + .mode = 0600,
76515 + .proc_handler = &proc_dointvec,
76516 + },
76517 +#endif
76518 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76519 + {
76520 + .procname = "tpe_restrict_all",
76521 + .data = &grsec_enable_tpe_all,
76522 + .maxlen = sizeof(int),
76523 + .mode = 0600,
76524 + .proc_handler = &proc_dointvec,
76525 + },
76526 +#endif
76527 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76528 + {
76529 + .procname = "socket_all",
76530 + .data = &grsec_enable_socket_all,
76531 + .maxlen = sizeof(int),
76532 + .mode = 0600,
76533 + .proc_handler = &proc_dointvec,
76534 + },
76535 + {
76536 + .procname = "socket_all_gid",
76537 + .data = &grsec_socket_all_gid,
76538 + .maxlen = sizeof(int),
76539 + .mode = 0600,
76540 + .proc_handler = &proc_dointvec,
76541 + },
76542 +#endif
76543 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76544 + {
76545 + .procname = "socket_client",
76546 + .data = &grsec_enable_socket_client,
76547 + .maxlen = sizeof(int),
76548 + .mode = 0600,
76549 + .proc_handler = &proc_dointvec,
76550 + },
76551 + {
76552 + .procname = "socket_client_gid",
76553 + .data = &grsec_socket_client_gid,
76554 + .maxlen = sizeof(int),
76555 + .mode = 0600,
76556 + .proc_handler = &proc_dointvec,
76557 + },
76558 +#endif
76559 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76560 + {
76561 + .procname = "socket_server",
76562 + .data = &grsec_enable_socket_server,
76563 + .maxlen = sizeof(int),
76564 + .mode = 0600,
76565 + .proc_handler = &proc_dointvec,
76566 + },
76567 + {
76568 + .procname = "socket_server_gid",
76569 + .data = &grsec_socket_server_gid,
76570 + .maxlen = sizeof(int),
76571 + .mode = 0600,
76572 + .proc_handler = &proc_dointvec,
76573 + },
76574 +#endif
76575 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76576 + {
76577 + .procname = "audit_group",
76578 + .data = &grsec_enable_group,
76579 + .maxlen = sizeof(int),
76580 + .mode = 0600,
76581 + .proc_handler = &proc_dointvec,
76582 + },
76583 + {
76584 + .procname = "audit_gid",
76585 + .data = &grsec_audit_gid,
76586 + .maxlen = sizeof(int),
76587 + .mode = 0600,
76588 + .proc_handler = &proc_dointvec,
76589 + },
76590 +#endif
76591 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76592 + {
76593 + .procname = "audit_chdir",
76594 + .data = &grsec_enable_chdir,
76595 + .maxlen = sizeof(int),
76596 + .mode = 0600,
76597 + .proc_handler = &proc_dointvec,
76598 + },
76599 +#endif
76600 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76601 + {
76602 + .procname = "audit_mount",
76603 + .data = &grsec_enable_mount,
76604 + .maxlen = sizeof(int),
76605 + .mode = 0600,
76606 + .proc_handler = &proc_dointvec,
76607 + },
76608 +#endif
76609 +#ifdef CONFIG_GRKERNSEC_DMESG
76610 + {
76611 + .procname = "dmesg",
76612 + .data = &grsec_enable_dmesg,
76613 + .maxlen = sizeof(int),
76614 + .mode = 0600,
76615 + .proc_handler = &proc_dointvec,
76616 + },
76617 +#endif
76618 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76619 + {
76620 + .procname = "chroot_findtask",
76621 + .data = &grsec_enable_chroot_findtask,
76622 + .maxlen = sizeof(int),
76623 + .mode = 0600,
76624 + .proc_handler = &proc_dointvec,
76625 + },
76626 +#endif
76627 +#ifdef CONFIG_GRKERNSEC_RESLOG
76628 + {
76629 + .procname = "resource_logging",
76630 + .data = &grsec_resource_logging,
76631 + .maxlen = sizeof(int),
76632 + .mode = 0600,
76633 + .proc_handler = &proc_dointvec,
76634 + },
76635 +#endif
76636 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76637 + {
76638 + .procname = "audit_ptrace",
76639 + .data = &grsec_enable_audit_ptrace,
76640 + .maxlen = sizeof(int),
76641 + .mode = 0600,
76642 + .proc_handler = &proc_dointvec,
76643 + },
76644 +#endif
76645 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76646 + {
76647 + .procname = "harden_ptrace",
76648 + .data = &grsec_enable_harden_ptrace,
76649 + .maxlen = sizeof(int),
76650 + .mode = 0600,
76651 + .proc_handler = &proc_dointvec,
76652 + },
76653 +#endif
76654 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76655 + {
76656 + .procname = "harden_ipc",
76657 + .data = &grsec_enable_harden_ipc,
76658 + .maxlen = sizeof(int),
76659 + .mode = 0600,
76660 + .proc_handler = &proc_dointvec,
76661 + },
76662 +#endif
76663 + {
76664 + .procname = "grsec_lock",
76665 + .data = &grsec_lock,
76666 + .maxlen = sizeof(int),
76667 + .mode = 0600,
76668 + .proc_handler = &proc_dointvec,
76669 + },
76670 +#endif
76671 +#ifdef CONFIG_GRKERNSEC_ROFS
76672 + {
76673 + .procname = "romount_protect",
76674 + .data = &grsec_enable_rofs,
76675 + .maxlen = sizeof(int),
76676 + .mode = 0600,
76677 + .proc_handler = &proc_dointvec_minmax,
76678 + .extra1 = &one,
76679 + .extra2 = &one,
76680 + },
76681 +#endif
76682 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76683 + {
76684 + .procname = "deny_new_usb",
76685 + .data = &grsec_deny_new_usb,
76686 + .maxlen = sizeof(int),
76687 + .mode = 0600,
76688 + .proc_handler = &proc_dointvec,
76689 + },
76690 +#endif
76691 + { }
76692 +};
76693 +#endif
76694 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76695 new file mode 100644
76696 index 0000000..61b514e
76697 --- /dev/null
76698 +++ b/grsecurity/grsec_time.c
76699 @@ -0,0 +1,16 @@
76700 +#include <linux/kernel.h>
76701 +#include <linux/sched.h>
76702 +#include <linux/grinternal.h>
76703 +#include <linux/module.h>
76704 +
76705 +void
76706 +gr_log_timechange(void)
76707 +{
76708 +#ifdef CONFIG_GRKERNSEC_TIME
76709 + if (grsec_enable_time)
76710 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76711 +#endif
76712 + return;
76713 +}
76714 +
76715 +EXPORT_SYMBOL_GPL(gr_log_timechange);
76716 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76717 new file mode 100644
76718 index 0000000..ee57dcf
76719 --- /dev/null
76720 +++ b/grsecurity/grsec_tpe.c
76721 @@ -0,0 +1,73 @@
76722 +#include <linux/kernel.h>
76723 +#include <linux/sched.h>
76724 +#include <linux/file.h>
76725 +#include <linux/fs.h>
76726 +#include <linux/grinternal.h>
76727 +
76728 +extern int gr_acl_tpe_check(void);
76729 +
76730 +int
76731 +gr_tpe_allow(const struct file *file)
76732 +{
76733 +#ifdef CONFIG_GRKERNSEC
76734 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76735 + const struct cred *cred = current_cred();
76736 + char *msg = NULL;
76737 + char *msg2 = NULL;
76738 +
76739 + // never restrict root
76740 + if (gr_is_global_root(cred->uid))
76741 + return 1;
76742 +
76743 + if (grsec_enable_tpe) {
76744 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76745 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76746 + msg = "not being in trusted group";
76747 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76748 + msg = "being in untrusted group";
76749 +#else
76750 + if (in_group_p(grsec_tpe_gid))
76751 + msg = "being in untrusted group";
76752 +#endif
76753 + }
76754 + if (!msg && gr_acl_tpe_check())
76755 + msg = "being in untrusted role";
76756 +
76757 + // not in any affected group/role
76758 + if (!msg)
76759 + goto next_check;
76760 +
76761 + if (gr_is_global_nonroot(inode->i_uid))
76762 + msg2 = "file in non-root-owned directory";
76763 + else if (inode->i_mode & S_IWOTH)
76764 + msg2 = "file in world-writable directory";
76765 + else if (inode->i_mode & S_IWGRP)
76766 + msg2 = "file in group-writable directory";
76767 +
76768 + if (msg && msg2) {
76769 + char fullmsg[70] = {0};
76770 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76771 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76772 + return 0;
76773 + }
76774 + msg = NULL;
76775 +next_check:
76776 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76777 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76778 + return 1;
76779 +
76780 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76781 + msg = "directory not owned by user";
76782 + else if (inode->i_mode & S_IWOTH)
76783 + msg = "file in world-writable directory";
76784 + else if (inode->i_mode & S_IWGRP)
76785 + msg = "file in group-writable directory";
76786 +
76787 + if (msg) {
76788 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76789 + return 0;
76790 + }
76791 +#endif
76792 +#endif
76793 + return 1;
76794 +}
76795 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76796 new file mode 100644
76797 index 0000000..ae02d8e
76798 --- /dev/null
76799 +++ b/grsecurity/grsec_usb.c
76800 @@ -0,0 +1,15 @@
76801 +#include <linux/kernel.h>
76802 +#include <linux/grinternal.h>
76803 +#include <linux/module.h>
76804 +
76805 +int gr_handle_new_usb(void)
76806 +{
76807 +#ifdef CONFIG_GRKERNSEC_DENYUSB
76808 + if (grsec_deny_new_usb) {
76809 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76810 + return 1;
76811 + }
76812 +#endif
76813 + return 0;
76814 +}
76815 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76816 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76817 new file mode 100644
76818 index 0000000..9f7b1ac
76819 --- /dev/null
76820 +++ b/grsecurity/grsum.c
76821 @@ -0,0 +1,61 @@
76822 +#include <linux/err.h>
76823 +#include <linux/kernel.h>
76824 +#include <linux/sched.h>
76825 +#include <linux/mm.h>
76826 +#include <linux/scatterlist.h>
76827 +#include <linux/crypto.h>
76828 +#include <linux/gracl.h>
76829 +
76830 +
76831 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76832 +#error "crypto and sha256 must be built into the kernel"
76833 +#endif
76834 +
76835 +int
76836 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76837 +{
76838 + char *p;
76839 + struct crypto_hash *tfm;
76840 + struct hash_desc desc;
76841 + struct scatterlist sg;
76842 + unsigned char temp_sum[GR_SHA_LEN];
76843 + volatile int retval = 0;
76844 + volatile int dummy = 0;
76845 + unsigned int i;
76846 +
76847 + sg_init_table(&sg, 1);
76848 +
76849 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76850 + if (IS_ERR(tfm)) {
76851 + /* should never happen, since sha256 should be built in */
76852 + return 1;
76853 + }
76854 +
76855 + desc.tfm = tfm;
76856 + desc.flags = 0;
76857 +
76858 + crypto_hash_init(&desc);
76859 +
76860 + p = salt;
76861 + sg_set_buf(&sg, p, GR_SALT_LEN);
76862 + crypto_hash_update(&desc, &sg, sg.length);
76863 +
76864 + p = entry->pw;
76865 + sg_set_buf(&sg, p, strlen(p));
76866 +
76867 + crypto_hash_update(&desc, &sg, sg.length);
76868 +
76869 + crypto_hash_final(&desc, temp_sum);
76870 +
76871 + memset(entry->pw, 0, GR_PW_LEN);
76872 +
76873 + for (i = 0; i < GR_SHA_LEN; i++)
76874 + if (sum[i] != temp_sum[i])
76875 + retval = 1;
76876 + else
76877 + dummy = 1; // waste a cycle
76878 +
76879 + crypto_free_hash(tfm);
76880 +
76881 + return retval;
76882 +}
76883 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76884 index 77ff547..181834f 100644
76885 --- a/include/asm-generic/4level-fixup.h
76886 +++ b/include/asm-generic/4level-fixup.h
76887 @@ -13,8 +13,10 @@
76888 #define pmd_alloc(mm, pud, address) \
76889 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76890 NULL: pmd_offset(pud, address))
76891 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76892
76893 #define pud_alloc(mm, pgd, address) (pgd)
76894 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76895 #define pud_offset(pgd, start) (pgd)
76896 #define pud_none(pud) 0
76897 #define pud_bad(pud) 0
76898 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76899 index b7babf0..97f4c4f 100644
76900 --- a/include/asm-generic/atomic-long.h
76901 +++ b/include/asm-generic/atomic-long.h
76902 @@ -22,6 +22,12 @@
76903
76904 typedef atomic64_t atomic_long_t;
76905
76906 +#ifdef CONFIG_PAX_REFCOUNT
76907 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
76908 +#else
76909 +typedef atomic64_t atomic_long_unchecked_t;
76910 +#endif
76911 +
76912 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76913
76914 static inline long atomic_long_read(atomic_long_t *l)
76915 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76916 return (long)atomic64_read(v);
76917 }
76918
76919 +#ifdef CONFIG_PAX_REFCOUNT
76920 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76921 +{
76922 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76923 +
76924 + return (long)atomic64_read_unchecked(v);
76925 +}
76926 +#endif
76927 +
76928 static inline void atomic_long_set(atomic_long_t *l, long i)
76929 {
76930 atomic64_t *v = (atomic64_t *)l;
76931 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76932 atomic64_set(v, i);
76933 }
76934
76935 +#ifdef CONFIG_PAX_REFCOUNT
76936 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76937 +{
76938 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76939 +
76940 + atomic64_set_unchecked(v, i);
76941 +}
76942 +#endif
76943 +
76944 static inline void atomic_long_inc(atomic_long_t *l)
76945 {
76946 atomic64_t *v = (atomic64_t *)l;
76947 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76948 atomic64_inc(v);
76949 }
76950
76951 +#ifdef CONFIG_PAX_REFCOUNT
76952 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76953 +{
76954 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76955 +
76956 + atomic64_inc_unchecked(v);
76957 +}
76958 +#endif
76959 +
76960 static inline void atomic_long_dec(atomic_long_t *l)
76961 {
76962 atomic64_t *v = (atomic64_t *)l;
76963 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76964 atomic64_dec(v);
76965 }
76966
76967 +#ifdef CONFIG_PAX_REFCOUNT
76968 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76969 +{
76970 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76971 +
76972 + atomic64_dec_unchecked(v);
76973 +}
76974 +#endif
76975 +
76976 static inline void atomic_long_add(long i, atomic_long_t *l)
76977 {
76978 atomic64_t *v = (atomic64_t *)l;
76979 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76980 atomic64_add(i, v);
76981 }
76982
76983 +#ifdef CONFIG_PAX_REFCOUNT
76984 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76985 +{
76986 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76987 +
76988 + atomic64_add_unchecked(i, v);
76989 +}
76990 +#endif
76991 +
76992 static inline void atomic_long_sub(long i, atomic_long_t *l)
76993 {
76994 atomic64_t *v = (atomic64_t *)l;
76995 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76996 atomic64_sub(i, v);
76997 }
76998
76999 +#ifdef CONFIG_PAX_REFCOUNT
77000 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77001 +{
77002 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77003 +
77004 + atomic64_sub_unchecked(i, v);
77005 +}
77006 +#endif
77007 +
77008 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77009 {
77010 atomic64_t *v = (atomic64_t *)l;
77011 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
77012 return atomic64_add_negative(i, v);
77013 }
77014
77015 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
77016 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
77017 {
77018 atomic64_t *v = (atomic64_t *)l;
77019
77020 return (long)atomic64_add_return(i, v);
77021 }
77022
77023 +#ifdef CONFIG_PAX_REFCOUNT
77024 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77025 +{
77026 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77027 +
77028 + return (long)atomic64_add_return_unchecked(i, v);
77029 +}
77030 +#endif
77031 +
77032 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77033 {
77034 atomic64_t *v = (atomic64_t *)l;
77035 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77036 return (long)atomic64_inc_return(v);
77037 }
77038
77039 +#ifdef CONFIG_PAX_REFCOUNT
77040 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77041 +{
77042 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
77043 +
77044 + return (long)atomic64_inc_return_unchecked(v);
77045 +}
77046 +#endif
77047 +
77048 static inline long atomic_long_dec_return(atomic_long_t *l)
77049 {
77050 atomic64_t *v = (atomic64_t *)l;
77051 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77052
77053 typedef atomic_t atomic_long_t;
77054
77055 +#ifdef CONFIG_PAX_REFCOUNT
77056 +typedef atomic_unchecked_t atomic_long_unchecked_t;
77057 +#else
77058 +typedef atomic_t atomic_long_unchecked_t;
77059 +#endif
77060 +
77061 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
77062 static inline long atomic_long_read(atomic_long_t *l)
77063 {
77064 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
77065 return (long)atomic_read(v);
77066 }
77067
77068 +#ifdef CONFIG_PAX_REFCOUNT
77069 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
77070 +{
77071 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77072 +
77073 + return (long)atomic_read_unchecked(v);
77074 +}
77075 +#endif
77076 +
77077 static inline void atomic_long_set(atomic_long_t *l, long i)
77078 {
77079 atomic_t *v = (atomic_t *)l;
77080 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77081 atomic_set(v, i);
77082 }
77083
77084 +#ifdef CONFIG_PAX_REFCOUNT
77085 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77086 +{
77087 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77088 +
77089 + atomic_set_unchecked(v, i);
77090 +}
77091 +#endif
77092 +
77093 static inline void atomic_long_inc(atomic_long_t *l)
77094 {
77095 atomic_t *v = (atomic_t *)l;
77096 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77097 atomic_inc(v);
77098 }
77099
77100 +#ifdef CONFIG_PAX_REFCOUNT
77101 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77102 +{
77103 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77104 +
77105 + atomic_inc_unchecked(v);
77106 +}
77107 +#endif
77108 +
77109 static inline void atomic_long_dec(atomic_long_t *l)
77110 {
77111 atomic_t *v = (atomic_t *)l;
77112 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77113 atomic_dec(v);
77114 }
77115
77116 +#ifdef CONFIG_PAX_REFCOUNT
77117 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77118 +{
77119 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77120 +
77121 + atomic_dec_unchecked(v);
77122 +}
77123 +#endif
77124 +
77125 static inline void atomic_long_add(long i, atomic_long_t *l)
77126 {
77127 atomic_t *v = (atomic_t *)l;
77128 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77129 atomic_add(i, v);
77130 }
77131
77132 +#ifdef CONFIG_PAX_REFCOUNT
77133 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77134 +{
77135 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77136 +
77137 + atomic_add_unchecked(i, v);
77138 +}
77139 +#endif
77140 +
77141 static inline void atomic_long_sub(long i, atomic_long_t *l)
77142 {
77143 atomic_t *v = (atomic_t *)l;
77144 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77145 atomic_sub(i, v);
77146 }
77147
77148 +#ifdef CONFIG_PAX_REFCOUNT
77149 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77150 +{
77151 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77152 +
77153 + atomic_sub_unchecked(i, v);
77154 +}
77155 +#endif
77156 +
77157 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77158 {
77159 atomic_t *v = (atomic_t *)l;
77160 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
77161 return (long)atomic_add_return(i, v);
77162 }
77163
77164 +#ifdef CONFIG_PAX_REFCOUNT
77165 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77166 +{
77167 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77168 +
77169 + return (long)atomic_add_return_unchecked(i, v);
77170 +}
77171 +
77172 +#endif
77173 +
77174 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77175 {
77176 atomic_t *v = (atomic_t *)l;
77177 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77178 return (long)atomic_inc_return(v);
77179 }
77180
77181 +#ifdef CONFIG_PAX_REFCOUNT
77182 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77183 +{
77184 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77185 +
77186 + return (long)atomic_inc_return_unchecked(v);
77187 +}
77188 +#endif
77189 +
77190 static inline long atomic_long_dec_return(atomic_long_t *l)
77191 {
77192 atomic_t *v = (atomic_t *)l;
77193 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77194
77195 #endif /* BITS_PER_LONG == 64 */
77196
77197 +#ifdef CONFIG_PAX_REFCOUNT
77198 +static inline void pax_refcount_needs_these_functions(void)
77199 +{
77200 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
77201 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77202 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77203 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77204 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77205 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77206 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77207 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77208 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77209 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77210 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77211 +#ifdef CONFIG_X86
77212 + atomic_clear_mask_unchecked(0, NULL);
77213 + atomic_set_mask_unchecked(0, NULL);
77214 +#endif
77215 +
77216 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77217 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77218 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77219 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77220 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77221 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77222 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77223 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77224 +}
77225 +#else
77226 +#define atomic_read_unchecked(v) atomic_read(v)
77227 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77228 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77229 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77230 +#define atomic_inc_unchecked(v) atomic_inc(v)
77231 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77232 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77233 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77234 +#define atomic_dec_unchecked(v) atomic_dec(v)
77235 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77236 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77237 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77238 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77239 +
77240 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
77241 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77242 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77243 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77244 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77245 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77246 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77247 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77248 +#endif
77249 +
77250 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77251 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77252 index 33bd2de..f31bff97 100644
77253 --- a/include/asm-generic/atomic.h
77254 +++ b/include/asm-generic/atomic.h
77255 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77256 * Atomically clears the bits set in @mask from @v
77257 */
77258 #ifndef atomic_clear_mask
77259 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77260 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77261 {
77262 unsigned long flags;
77263
77264 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77265 index b18ce4f..2ee2843 100644
77266 --- a/include/asm-generic/atomic64.h
77267 +++ b/include/asm-generic/atomic64.h
77268 @@ -16,6 +16,8 @@ typedef struct {
77269 long long counter;
77270 } atomic64_t;
77271
77272 +typedef atomic64_t atomic64_unchecked_t;
77273 +
77274 #define ATOMIC64_INIT(i) { (i) }
77275
77276 extern long long atomic64_read(const atomic64_t *v);
77277 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77278 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77279 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77280
77281 +#define atomic64_read_unchecked(v) atomic64_read(v)
77282 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77283 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77284 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77285 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77286 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
77287 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77288 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
77289 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77290 +
77291 #endif /* _ASM_GENERIC_ATOMIC64_H */
77292 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77293 index a60a7cc..0fe12f2 100644
77294 --- a/include/asm-generic/bitops/__fls.h
77295 +++ b/include/asm-generic/bitops/__fls.h
77296 @@ -9,7 +9,7 @@
77297 *
77298 * Undefined if no set bit exists, so code should check against 0 first.
77299 */
77300 -static __always_inline unsigned long __fls(unsigned long word)
77301 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77302 {
77303 int num = BITS_PER_LONG - 1;
77304
77305 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77306 index 0576d1f..dad6c71 100644
77307 --- a/include/asm-generic/bitops/fls.h
77308 +++ b/include/asm-generic/bitops/fls.h
77309 @@ -9,7 +9,7 @@
77310 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77311 */
77312
77313 -static __always_inline int fls(int x)
77314 +static __always_inline int __intentional_overflow(-1) fls(int x)
77315 {
77316 int r = 32;
77317
77318 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77319 index b097cf8..3d40e14 100644
77320 --- a/include/asm-generic/bitops/fls64.h
77321 +++ b/include/asm-generic/bitops/fls64.h
77322 @@ -15,7 +15,7 @@
77323 * at position 64.
77324 */
77325 #if BITS_PER_LONG == 32
77326 -static __always_inline int fls64(__u64 x)
77327 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77328 {
77329 __u32 h = x >> 32;
77330 if (h)
77331 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77332 return fls(x);
77333 }
77334 #elif BITS_PER_LONG == 64
77335 -static __always_inline int fls64(__u64 x)
77336 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77337 {
77338 if (x == 0)
77339 return 0;
77340 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77341 index 1bfcfe5..e04c5c9 100644
77342 --- a/include/asm-generic/cache.h
77343 +++ b/include/asm-generic/cache.h
77344 @@ -6,7 +6,7 @@
77345 * cache lines need to provide their own cache.h.
77346 */
77347
77348 -#define L1_CACHE_SHIFT 5
77349 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77350 +#define L1_CACHE_SHIFT 5UL
77351 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77352
77353 #endif /* __ASM_GENERIC_CACHE_H */
77354 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77355 index 0d68a1e..b74a761 100644
77356 --- a/include/asm-generic/emergency-restart.h
77357 +++ b/include/asm-generic/emergency-restart.h
77358 @@ -1,7 +1,7 @@
77359 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77360 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77361
77362 -static inline void machine_emergency_restart(void)
77363 +static inline __noreturn void machine_emergency_restart(void)
77364 {
77365 machine_restart(NULL);
77366 }
77367 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77368 index 90f99c7..00ce236 100644
77369 --- a/include/asm-generic/kmap_types.h
77370 +++ b/include/asm-generic/kmap_types.h
77371 @@ -2,9 +2,9 @@
77372 #define _ASM_GENERIC_KMAP_TYPES_H
77373
77374 #ifdef __WITH_KM_FENCE
77375 -# define KM_TYPE_NR 41
77376 +# define KM_TYPE_NR 42
77377 #else
77378 -# define KM_TYPE_NR 20
77379 +# define KM_TYPE_NR 21
77380 #endif
77381
77382 #endif
77383 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77384 index 9ceb03b..62b0b8f 100644
77385 --- a/include/asm-generic/local.h
77386 +++ b/include/asm-generic/local.h
77387 @@ -23,24 +23,37 @@ typedef struct
77388 atomic_long_t a;
77389 } local_t;
77390
77391 +typedef struct {
77392 + atomic_long_unchecked_t a;
77393 +} local_unchecked_t;
77394 +
77395 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77396
77397 #define local_read(l) atomic_long_read(&(l)->a)
77398 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77399 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77400 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77401 #define local_inc(l) atomic_long_inc(&(l)->a)
77402 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77403 #define local_dec(l) atomic_long_dec(&(l)->a)
77404 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77405 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77406 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77407 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77408 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77409
77410 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77411 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77412 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77413 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77414 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77415 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77416 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77417 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77418 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77419
77420 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77421 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77422 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77423 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77424 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77425 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77426 index 725612b..9cc513a 100644
77427 --- a/include/asm-generic/pgtable-nopmd.h
77428 +++ b/include/asm-generic/pgtable-nopmd.h
77429 @@ -1,14 +1,19 @@
77430 #ifndef _PGTABLE_NOPMD_H
77431 #define _PGTABLE_NOPMD_H
77432
77433 -#ifndef __ASSEMBLY__
77434 -
77435 #include <asm-generic/pgtable-nopud.h>
77436
77437 -struct mm_struct;
77438 -
77439 #define __PAGETABLE_PMD_FOLDED
77440
77441 +#define PMD_SHIFT PUD_SHIFT
77442 +#define PTRS_PER_PMD 1
77443 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77444 +#define PMD_MASK (~(PMD_SIZE-1))
77445 +
77446 +#ifndef __ASSEMBLY__
77447 +
77448 +struct mm_struct;
77449 +
77450 /*
77451 * Having the pmd type consist of a pud gets the size right, and allows
77452 * us to conceptually access the pud entry that this pmd is folded into
77453 @@ -16,11 +21,6 @@ struct mm_struct;
77454 */
77455 typedef struct { pud_t pud; } pmd_t;
77456
77457 -#define PMD_SHIFT PUD_SHIFT
77458 -#define PTRS_PER_PMD 1
77459 -#define PMD_SIZE (1UL << PMD_SHIFT)
77460 -#define PMD_MASK (~(PMD_SIZE-1))
77461 -
77462 /*
77463 * The "pud_xxx()" functions here are trivial for a folded two-level
77464 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77465 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77466 index 810431d..0ec4804f 100644
77467 --- a/include/asm-generic/pgtable-nopud.h
77468 +++ b/include/asm-generic/pgtable-nopud.h
77469 @@ -1,10 +1,15 @@
77470 #ifndef _PGTABLE_NOPUD_H
77471 #define _PGTABLE_NOPUD_H
77472
77473 -#ifndef __ASSEMBLY__
77474 -
77475 #define __PAGETABLE_PUD_FOLDED
77476
77477 +#define PUD_SHIFT PGDIR_SHIFT
77478 +#define PTRS_PER_PUD 1
77479 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77480 +#define PUD_MASK (~(PUD_SIZE-1))
77481 +
77482 +#ifndef __ASSEMBLY__
77483 +
77484 /*
77485 * Having the pud type consist of a pgd gets the size right, and allows
77486 * us to conceptually access the pgd entry that this pud is folded into
77487 @@ -12,11 +17,6 @@
77488 */
77489 typedef struct { pgd_t pgd; } pud_t;
77490
77491 -#define PUD_SHIFT PGDIR_SHIFT
77492 -#define PTRS_PER_PUD 1
77493 -#define PUD_SIZE (1UL << PUD_SHIFT)
77494 -#define PUD_MASK (~(PUD_SIZE-1))
77495 -
77496 /*
77497 * The "pgd_xxx()" functions here are trivial for a folded two-level
77498 * setup: the pud is never bad, and a pud always exists (as it's folded
77499 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77500 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77501
77502 #define pgd_populate(mm, pgd, pud) do { } while (0)
77503 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77504 /*
77505 * (puds are folded into pgds so this doesn't get actually called,
77506 * but the define is needed for a generic inline function.)
77507 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77508 index 34c7bdc..38d4f3b 100644
77509 --- a/include/asm-generic/pgtable.h
77510 +++ b/include/asm-generic/pgtable.h
77511 @@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77512 }
77513 #endif /* CONFIG_NUMA_BALANCING */
77514
77515 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77516 +#ifdef CONFIG_PAX_KERNEXEC
77517 +#error KERNEXEC requires pax_open_kernel
77518 +#else
77519 +static inline unsigned long pax_open_kernel(void) { return 0; }
77520 +#endif
77521 +#endif
77522 +
77523 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77524 +#ifdef CONFIG_PAX_KERNEXEC
77525 +#error KERNEXEC requires pax_close_kernel
77526 +#else
77527 +static inline unsigned long pax_close_kernel(void) { return 0; }
77528 +#endif
77529 +#endif
77530 +
77531 #endif /* CONFIG_MMU */
77532
77533 #endif /* !__ASSEMBLY__ */
77534 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77535 index 72d8803..cb9749c 100644
77536 --- a/include/asm-generic/uaccess.h
77537 +++ b/include/asm-generic/uaccess.h
77538 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77539 return __clear_user(to, n);
77540 }
77541
77542 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77543 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77544 +#error UDEREF requires pax_open_userland
77545 +#else
77546 +static inline unsigned long pax_open_userland(void) { return 0; }
77547 +#endif
77548 +#endif
77549 +
77550 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77551 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77552 +#error UDEREF requires pax_close_userland
77553 +#else
77554 +static inline unsigned long pax_close_userland(void) { return 0; }
77555 +#endif
77556 +#endif
77557 +
77558 #endif /* __ASM_GENERIC_UACCESS_H */
77559 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77560 index bc2121f..2f41f9a 100644
77561 --- a/include/asm-generic/vmlinux.lds.h
77562 +++ b/include/asm-generic/vmlinux.lds.h
77563 @@ -232,6 +232,7 @@
77564 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77565 VMLINUX_SYMBOL(__start_rodata) = .; \
77566 *(.rodata) *(.rodata.*) \
77567 + *(.data..read_only) \
77568 *(__vermagic) /* Kernel version magic */ \
77569 . = ALIGN(8); \
77570 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77571 @@ -716,17 +717,18 @@
77572 * section in the linker script will go there too. @phdr should have
77573 * a leading colon.
77574 *
77575 - * Note that this macros defines __per_cpu_load as an absolute symbol.
77576 + * Note that this macros defines per_cpu_load as an absolute symbol.
77577 * If there is no need to put the percpu section at a predetermined
77578 * address, use PERCPU_SECTION.
77579 */
77580 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77581 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
77582 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77583 + per_cpu_load = .; \
77584 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77585 - LOAD_OFFSET) { \
77586 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77587 PERCPU_INPUT(cacheline) \
77588 } phdr \
77589 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77590 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77591
77592 /**
77593 * PERCPU_SECTION - define output section for percpu area, simple version
77594 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77595 index e73c19e..5b89e00 100644
77596 --- a/include/crypto/algapi.h
77597 +++ b/include/crypto/algapi.h
77598 @@ -34,7 +34,7 @@ struct crypto_type {
77599 unsigned int maskclear;
77600 unsigned int maskset;
77601 unsigned int tfmsize;
77602 -};
77603 +} __do_const;
77604
77605 struct crypto_instance {
77606 struct crypto_alg alg;
77607 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77608 index 04a7f31..668d424 100644
77609 --- a/include/drm/drmP.h
77610 +++ b/include/drm/drmP.h
77611 @@ -67,6 +67,7 @@
77612 #include <linux/workqueue.h>
77613 #include <linux/poll.h>
77614 #include <asm/pgalloc.h>
77615 +#include <asm/local.h>
77616 #include <drm/drm.h>
77617 #include <drm/drm_sarea.h>
77618 #include <drm/drm_vma_manager.h>
77619 @@ -297,10 +298,12 @@ do { \
77620 * \param cmd command.
77621 * \param arg argument.
77622 */
77623 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77624 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77625 + struct drm_file *file_priv);
77626 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77627 struct drm_file *file_priv);
77628
77629 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77630 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77631 unsigned long arg);
77632
77633 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77634 @@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77635 struct drm_ioctl_desc {
77636 unsigned int cmd;
77637 int flags;
77638 - drm_ioctl_t *func;
77639 + drm_ioctl_t func;
77640 unsigned int cmd_drv;
77641 const char *name;
77642 -};
77643 +} __do_const;
77644
77645 /**
77646 * Creates a driver or general drm_ioctl_desc array entry for the given
77647 @@ -1022,7 +1025,8 @@ struct drm_info_list {
77648 int (*show)(struct seq_file*, void*); /** show callback */
77649 u32 driver_features; /**< Required driver features for this entry */
77650 void *data;
77651 -};
77652 +} __do_const;
77653 +typedef struct drm_info_list __no_const drm_info_list_no_const;
77654
77655 /**
77656 * debugfs node structure. This structure represents a debugfs file.
77657 @@ -1106,7 +1110,7 @@ struct drm_device {
77658
77659 /** \name Usage Counters */
77660 /*@{ */
77661 - int open_count; /**< Outstanding files open */
77662 + local_t open_count; /**< Outstanding files open */
77663 int buf_use; /**< Buffers in use -- cannot alloc */
77664 atomic_t buf_alloc; /**< Buffer allocation in progress */
77665 /*@} */
77666 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77667 index b1388b5..e1d1163 100644
77668 --- a/include/drm/drm_crtc_helper.h
77669 +++ b/include/drm/drm_crtc_helper.h
77670 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77671 struct drm_connector *connector);
77672 /* disable encoder when not in use - more explicit than dpms off */
77673 void (*disable)(struct drm_encoder *encoder);
77674 -};
77675 +} __no_const;
77676
77677 /**
77678 * drm_connector_helper_funcs - helper operations for connectors
77679 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77680 index 940ece4..8cb727f 100644
77681 --- a/include/drm/i915_pciids.h
77682 +++ b/include/drm/i915_pciids.h
77683 @@ -37,7 +37,7 @@
77684 */
77685 #define INTEL_VGA_DEVICE(id, info) { \
77686 0x8086, id, \
77687 - ~0, ~0, \
77688 + PCI_ANY_ID, PCI_ANY_ID, \
77689 0x030000, 0xff0000, \
77690 (unsigned long) info }
77691
77692 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77693 index 72dcbe8..8db58d7 100644
77694 --- a/include/drm/ttm/ttm_memory.h
77695 +++ b/include/drm/ttm/ttm_memory.h
77696 @@ -48,7 +48,7 @@
77697
77698 struct ttm_mem_shrink {
77699 int (*do_shrink) (struct ttm_mem_shrink *);
77700 -};
77701 +} __no_const;
77702
77703 /**
77704 * struct ttm_mem_global - Global memory accounting structure.
77705 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77706 index 49a8284..9643967 100644
77707 --- a/include/drm/ttm/ttm_page_alloc.h
77708 +++ b/include/drm/ttm/ttm_page_alloc.h
77709 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77710 */
77711 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77712
77713 +struct device;
77714 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77715 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77716
77717 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77718 index 4b840e8..155d235 100644
77719 --- a/include/keys/asymmetric-subtype.h
77720 +++ b/include/keys/asymmetric-subtype.h
77721 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77722 /* Verify the signature on a key of this subtype (optional) */
77723 int (*verify_signature)(const struct key *key,
77724 const struct public_key_signature *sig);
77725 -};
77726 +} __do_const;
77727
77728 /**
77729 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77730 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77731 index c1da539..1dcec55 100644
77732 --- a/include/linux/atmdev.h
77733 +++ b/include/linux/atmdev.h
77734 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77735 #endif
77736
77737 struct k_atm_aal_stats {
77738 -#define __HANDLE_ITEM(i) atomic_t i
77739 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
77740 __AAL_STAT_ITEMS
77741 #undef __HANDLE_ITEM
77742 };
77743 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77744 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77745 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77746 struct module *owner;
77747 -};
77748 +} __do_const ;
77749
77750 struct atmphy_ops {
77751 int (*start)(struct atm_dev *dev);
77752 diff --git a/include/linux/audit.h b/include/linux/audit.h
77753 index ec1464d..833274b 100644
77754 --- a/include/linux/audit.h
77755 +++ b/include/linux/audit.h
77756 @@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
77757 extern unsigned int audit_serial(void);
77758 extern int auditsc_get_stamp(struct audit_context *ctx,
77759 struct timespec *t, unsigned int *serial);
77760 -extern int audit_set_loginuid(kuid_t loginuid);
77761 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77762
77763 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77764 {
77765 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77766 index b4a745d..e3c0942 100644
77767 --- a/include/linux/binfmts.h
77768 +++ b/include/linux/binfmts.h
77769 @@ -45,7 +45,7 @@ struct linux_binprm {
77770 unsigned interp_data;
77771 unsigned long loader, exec;
77772 char tcomm[TASK_COMM_LEN];
77773 -};
77774 +} __randomize_layout;
77775
77776 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77777 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77778 @@ -74,8 +74,10 @@ struct linux_binfmt {
77779 int (*load_binary)(struct linux_binprm *);
77780 int (*load_shlib)(struct file *);
77781 int (*core_dump)(struct coredump_params *cprm);
77782 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77783 + void (*handle_mmap)(struct file *);
77784 unsigned long min_coredump; /* minimal dump size */
77785 -};
77786 +} __do_const __randomize_layout;
77787
77788 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77789
77790 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77791 index be5fd38..d71192a 100644
77792 --- a/include/linux/bitops.h
77793 +++ b/include/linux/bitops.h
77794 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77795 * @word: value to rotate
77796 * @shift: bits to roll
77797 */
77798 -static inline __u32 rol32(__u32 word, unsigned int shift)
77799 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77800 {
77801 return (word << shift) | (word >> (32 - shift));
77802 }
77803 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77804 * @word: value to rotate
77805 * @shift: bits to roll
77806 */
77807 -static inline __u32 ror32(__u32 word, unsigned int shift)
77808 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77809 {
77810 return (word >> shift) | (word << (32 - shift));
77811 }
77812 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77813 return (__s32)(value << shift) >> shift;
77814 }
77815
77816 -static inline unsigned fls_long(unsigned long l)
77817 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77818 {
77819 if (sizeof(l) == 4)
77820 return fls(l);
77821 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77822 index 4afa4f8..1ed7824 100644
77823 --- a/include/linux/blkdev.h
77824 +++ b/include/linux/blkdev.h
77825 @@ -1572,7 +1572,7 @@ struct block_device_operations {
77826 /* this callback is with swap_lock and sometimes page table lock held */
77827 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77828 struct module *owner;
77829 -};
77830 +} __do_const;
77831
77832 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77833 unsigned long);
77834 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77835 index afc1343..9735539 100644
77836 --- a/include/linux/blktrace_api.h
77837 +++ b/include/linux/blktrace_api.h
77838 @@ -25,7 +25,7 @@ struct blk_trace {
77839 struct dentry *dropped_file;
77840 struct dentry *msg_file;
77841 struct list_head running_list;
77842 - atomic_t dropped;
77843 + atomic_unchecked_t dropped;
77844 };
77845
77846 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77847 diff --git a/include/linux/cache.h b/include/linux/cache.h
77848 index 17e7e82..1d7da26 100644
77849 --- a/include/linux/cache.h
77850 +++ b/include/linux/cache.h
77851 @@ -16,6 +16,14 @@
77852 #define __read_mostly
77853 #endif
77854
77855 +#ifndef __read_only
77856 +#ifdef CONFIG_PAX_KERNEXEC
77857 +#error KERNEXEC requires __read_only
77858 +#else
77859 +#define __read_only __read_mostly
77860 +#endif
77861 +#endif
77862 +
77863 #ifndef ____cacheline_aligned
77864 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77865 #endif
77866 diff --git a/include/linux/capability.h b/include/linux/capability.h
77867 index a6ee1f9..e1ca49d 100644
77868 --- a/include/linux/capability.h
77869 +++ b/include/linux/capability.h
77870 @@ -212,8 +212,13 @@ extern bool capable(int cap);
77871 extern bool ns_capable(struct user_namespace *ns, int cap);
77872 extern bool inode_capable(const struct inode *inode, int cap);
77873 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77874 +extern bool capable_nolog(int cap);
77875 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77876 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
77877
77878 /* audit system wants to get cap info from files as well */
77879 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77880
77881 +extern int is_privileged_binary(const struct dentry *dentry);
77882 +
77883 #endif /* !_LINUX_CAPABILITY_H */
77884 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77885 index 8609d57..86e4d79 100644
77886 --- a/include/linux/cdrom.h
77887 +++ b/include/linux/cdrom.h
77888 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
77889
77890 /* driver specifications */
77891 const int capability; /* capability flags */
77892 - int n_minors; /* number of active minor devices */
77893 /* handle uniform packets for scsi type devices (scsi,atapi) */
77894 int (*generic_packet) (struct cdrom_device_info *,
77895 struct packet_command *);
77896 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77897 index 4ce9056..86caac6 100644
77898 --- a/include/linux/cleancache.h
77899 +++ b/include/linux/cleancache.h
77900 @@ -31,7 +31,7 @@ struct cleancache_ops {
77901 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77902 void (*invalidate_inode)(int, struct cleancache_filekey);
77903 void (*invalidate_fs)(int);
77904 -};
77905 +} __no_const;
77906
77907 extern struct cleancache_ops *
77908 cleancache_register_ops(struct cleancache_ops *ops);
77909 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77910 index 939533d..cf0a57c 100644
77911 --- a/include/linux/clk-provider.h
77912 +++ b/include/linux/clk-provider.h
77913 @@ -166,6 +166,7 @@ struct clk_ops {
77914 unsigned long parent_accuracy);
77915 void (*init)(struct clk_hw *hw);
77916 };
77917 +typedef struct clk_ops __no_const clk_ops_no_const;
77918
77919 /**
77920 * struct clk_init_data - holds init data that's common to all clocks and is
77921 diff --git a/include/linux/compat.h b/include/linux/compat.h
77922 index 3f448c6..df3ce1d 100644
77923 --- a/include/linux/compat.h
77924 +++ b/include/linux/compat.h
77925 @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77926 compat_size_t __user *len_ptr);
77927
77928 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77929 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77930 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77931 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77932 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77933 compat_ssize_t msgsz, int msgflg);
77934 @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77935 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77936 compat_ulong_t addr, compat_ulong_t data);
77937 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77938 - compat_long_t addr, compat_long_t data);
77939 + compat_ulong_t addr, compat_ulong_t data);
77940
77941 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77942 /*
77943 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77944 index 2507fd2..55203f8 100644
77945 --- a/include/linux/compiler-gcc4.h
77946 +++ b/include/linux/compiler-gcc4.h
77947 @@ -39,9 +39,34 @@
77948 # define __compiletime_warning(message) __attribute__((warning(message)))
77949 # define __compiletime_error(message) __attribute__((error(message)))
77950 #endif /* __CHECKER__ */
77951 +
77952 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77953 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77954 +#define __bos0(ptr) __bos((ptr), 0)
77955 +#define __bos1(ptr) __bos((ptr), 1)
77956 #endif /* GCC_VERSION >= 40300 */
77957
77958 #if GCC_VERSION >= 40500
77959 +
77960 +#ifdef RANDSTRUCT_PLUGIN
77961 +#define __randomize_layout __attribute__((randomize_layout))
77962 +#define __no_randomize_layout __attribute__((no_randomize_layout))
77963 +#endif
77964 +
77965 +#ifdef CONSTIFY_PLUGIN
77966 +#define __no_const __attribute__((no_const))
77967 +#define __do_const __attribute__((do_const))
77968 +#endif
77969 +
77970 +#ifdef SIZE_OVERFLOW_PLUGIN
77971 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77972 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77973 +#endif
77974 +
77975 +#ifdef LATENT_ENTROPY_PLUGIN
77976 +#define __latent_entropy __attribute__((latent_entropy))
77977 +#endif
77978 +
77979 /*
77980 * Mark a position in code as unreachable. This can be used to
77981 * suppress control flow warnings after asm blocks that transfer
77982 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77983 index 2472740..4857634 100644
77984 --- a/include/linux/compiler.h
77985 +++ b/include/linux/compiler.h
77986 @@ -5,11 +5,14 @@
77987
77988 #ifdef __CHECKER__
77989 # define __user __attribute__((noderef, address_space(1)))
77990 +# define __force_user __force __user
77991 # define __kernel __attribute__((address_space(0)))
77992 +# define __force_kernel __force __kernel
77993 # define __safe __attribute__((safe))
77994 # define __force __attribute__((force))
77995 # define __nocast __attribute__((nocast))
77996 # define __iomem __attribute__((noderef, address_space(2)))
77997 +# define __force_iomem __force __iomem
77998 # define __must_hold(x) __attribute__((context(x,1,1)))
77999 # define __acquires(x) __attribute__((context(x,0,1)))
78000 # define __releases(x) __attribute__((context(x,1,0)))
78001 @@ -17,20 +20,37 @@
78002 # define __release(x) __context__(x,-1)
78003 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
78004 # define __percpu __attribute__((noderef, address_space(3)))
78005 +# define __force_percpu __force __percpu
78006 #ifdef CONFIG_SPARSE_RCU_POINTER
78007 # define __rcu __attribute__((noderef, address_space(4)))
78008 +# define __force_rcu __force __rcu
78009 #else
78010 # define __rcu
78011 +# define __force_rcu
78012 #endif
78013 extern void __chk_user_ptr(const volatile void __user *);
78014 extern void __chk_io_ptr(const volatile void __iomem *);
78015 #else
78016 -# define __user
78017 -# define __kernel
78018 +# ifdef CHECKER_PLUGIN
78019 +//# define __user
78020 +//# define __force_user
78021 +//# define __kernel
78022 +//# define __force_kernel
78023 +# else
78024 +# ifdef STRUCTLEAK_PLUGIN
78025 +# define __user __attribute__((user))
78026 +# else
78027 +# define __user
78028 +# endif
78029 +# define __force_user
78030 +# define __kernel
78031 +# define __force_kernel
78032 +# endif
78033 # define __safe
78034 # define __force
78035 # define __nocast
78036 # define __iomem
78037 +# define __force_iomem
78038 # define __chk_user_ptr(x) (void)0
78039 # define __chk_io_ptr(x) (void)0
78040 # define __builtin_warning(x, y...) (1)
78041 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
78042 # define __release(x) (void)0
78043 # define __cond_lock(x,c) (c)
78044 # define __percpu
78045 +# define __force_percpu
78046 # define __rcu
78047 +# define __force_rcu
78048 #endif
78049
78050 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
78051 @@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78052 # define __attribute_const__ /* unimplemented */
78053 #endif
78054
78055 +#ifndef __randomize_layout
78056 +# define __randomize_layout
78057 +#endif
78058 +
78059 +#ifndef __no_randomize_layout
78060 +# define __no_randomize_layout
78061 +#endif
78062 +
78063 +#ifndef __no_const
78064 +# define __no_const
78065 +#endif
78066 +
78067 +#ifndef __do_const
78068 +# define __do_const
78069 +#endif
78070 +
78071 +#ifndef __size_overflow
78072 +# define __size_overflow(...)
78073 +#endif
78074 +
78075 +#ifndef __intentional_overflow
78076 +# define __intentional_overflow(...)
78077 +#endif
78078 +
78079 +#ifndef __latent_entropy
78080 +# define __latent_entropy
78081 +#endif
78082 +
78083 /*
78084 * Tell gcc if a function is cold. The compiler will assume any path
78085 * directly leading to the call is unlikely.
78086 @@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78087 #define __cold
78088 #endif
78089
78090 +#ifndef __alloc_size
78091 +#define __alloc_size(...)
78092 +#endif
78093 +
78094 +#ifndef __bos
78095 +#define __bos(ptr, arg)
78096 +#endif
78097 +
78098 +#ifndef __bos0
78099 +#define __bos0(ptr)
78100 +#endif
78101 +
78102 +#ifndef __bos1
78103 +#define __bos1(ptr)
78104 +#endif
78105 +
78106 /* Simple shorthand for a section definition */
78107 #ifndef __section
78108 # define __section(S) __attribute__ ((__section__(#S)))
78109 @@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78110 * use is to mediate communication between process-level code and irq/NMI
78111 * handlers, all running on the same CPU.
78112 */
78113 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
78114 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
78115 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
78116
78117 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
78118 #ifdef CONFIG_KPROBES
78119 diff --git a/include/linux/completion.h b/include/linux/completion.h
78120 index 5d5aaae..0ea9b84 100644
78121 --- a/include/linux/completion.h
78122 +++ b/include/linux/completion.h
78123 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
78124
78125 extern void wait_for_completion(struct completion *);
78126 extern void wait_for_completion_io(struct completion *);
78127 -extern int wait_for_completion_interruptible(struct completion *x);
78128 -extern int wait_for_completion_killable(struct completion *x);
78129 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
78130 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
78131 extern unsigned long wait_for_completion_timeout(struct completion *x,
78132 - unsigned long timeout);
78133 + unsigned long timeout) __intentional_overflow(-1);
78134 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
78135 - unsigned long timeout);
78136 + unsigned long timeout) __intentional_overflow(-1);
78137 extern long wait_for_completion_interruptible_timeout(
78138 - struct completion *x, unsigned long timeout);
78139 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78140 extern long wait_for_completion_killable_timeout(
78141 - struct completion *x, unsigned long timeout);
78142 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78143 extern bool try_wait_for_completion(struct completion *x);
78144 extern bool completion_done(struct completion *x);
78145
78146 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78147 index 34025df..d94bbbc 100644
78148 --- a/include/linux/configfs.h
78149 +++ b/include/linux/configfs.h
78150 @@ -125,7 +125,7 @@ struct configfs_attribute {
78151 const char *ca_name;
78152 struct module *ca_owner;
78153 umode_t ca_mode;
78154 -};
78155 +} __do_const;
78156
78157 /*
78158 * Users often need to create attribute structures for their configurable
78159 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78160 index 4d89e0e..5281847 100644
78161 --- a/include/linux/cpufreq.h
78162 +++ b/include/linux/cpufreq.h
78163 @@ -191,6 +191,7 @@ struct global_attr {
78164 ssize_t (*store)(struct kobject *a, struct attribute *b,
78165 const char *c, size_t count);
78166 };
78167 +typedef struct global_attr __no_const global_attr_no_const;
78168
78169 #define define_one_global_ro(_name) \
78170 static struct global_attr _name = \
78171 @@ -232,7 +233,7 @@ struct cpufreq_driver {
78172 bool boost_supported;
78173 bool boost_enabled;
78174 int (*set_boost) (int state);
78175 -};
78176 +} __do_const;
78177
78178 /* flags */
78179 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78180 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78181 index 50fcbb0..9d2dbd9 100644
78182 --- a/include/linux/cpuidle.h
78183 +++ b/include/linux/cpuidle.h
78184 @@ -50,7 +50,8 @@ struct cpuidle_state {
78185 int index);
78186
78187 int (*enter_dead) (struct cpuidle_device *dev, int index);
78188 -};
78189 +} __do_const;
78190 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78191
78192 /* Idle State Flags */
78193 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78194 @@ -192,7 +193,7 @@ struct cpuidle_governor {
78195 void (*reflect) (struct cpuidle_device *dev, int index);
78196
78197 struct module *owner;
78198 -};
78199 +} __do_const;
78200
78201 #ifdef CONFIG_CPU_IDLE
78202 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78203 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78204 index d08e4d2..95fad61 100644
78205 --- a/include/linux/cpumask.h
78206 +++ b/include/linux/cpumask.h
78207 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78208 }
78209
78210 /* Valid inputs for n are -1 and 0. */
78211 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78212 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78213 {
78214 return n+1;
78215 }
78216
78217 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78218 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78219 {
78220 return n+1;
78221 }
78222
78223 -static inline unsigned int cpumask_next_and(int n,
78224 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78225 const struct cpumask *srcp,
78226 const struct cpumask *andp)
78227 {
78228 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78229 *
78230 * Returns >= nr_cpu_ids if no further cpus set.
78231 */
78232 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78233 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78234 {
78235 /* -1 is a legal arg here. */
78236 if (n != -1)
78237 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78238 *
78239 * Returns >= nr_cpu_ids if no further cpus unset.
78240 */
78241 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78242 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78243 {
78244 /* -1 is a legal arg here. */
78245 if (n != -1)
78246 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78247 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78248 }
78249
78250 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78251 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78252 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78253
78254 /**
78255 diff --git a/include/linux/cred.h b/include/linux/cred.h
78256 index 04421e8..117e17a 100644
78257 --- a/include/linux/cred.h
78258 +++ b/include/linux/cred.h
78259 @@ -35,7 +35,7 @@ struct group_info {
78260 int nblocks;
78261 kgid_t small_block[NGROUPS_SMALL];
78262 kgid_t *blocks[0];
78263 -};
78264 +} __randomize_layout;
78265
78266 /**
78267 * get_group_info - Get a reference to a group info structure
78268 @@ -136,7 +136,7 @@ struct cred {
78269 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78270 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78271 struct rcu_head rcu; /* RCU deletion hook */
78272 -};
78273 +} __randomize_layout;
78274
78275 extern void __put_cred(struct cred *);
78276 extern void exit_creds(struct task_struct *);
78277 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78278 static inline void validate_process_creds(void)
78279 {
78280 }
78281 +static inline void validate_task_creds(struct task_struct *task)
78282 +{
78283 +}
78284 #endif
78285
78286 /**
78287 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78288 index b92eadf..b4ecdc1 100644
78289 --- a/include/linux/crypto.h
78290 +++ b/include/linux/crypto.h
78291 @@ -373,7 +373,7 @@ struct cipher_tfm {
78292 const u8 *key, unsigned int keylen);
78293 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78294 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78295 -};
78296 +} __no_const;
78297
78298 struct hash_tfm {
78299 int (*init)(struct hash_desc *desc);
78300 @@ -394,13 +394,13 @@ struct compress_tfm {
78301 int (*cot_decompress)(struct crypto_tfm *tfm,
78302 const u8 *src, unsigned int slen,
78303 u8 *dst, unsigned int *dlen);
78304 -};
78305 +} __no_const;
78306
78307 struct rng_tfm {
78308 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78309 unsigned int dlen);
78310 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78311 -};
78312 +} __no_const;
78313
78314 #define crt_ablkcipher crt_u.ablkcipher
78315 #define crt_aead crt_u.aead
78316 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78317 index 653589e..4ef254a 100644
78318 --- a/include/linux/ctype.h
78319 +++ b/include/linux/ctype.h
78320 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78321 * Fast implementation of tolower() for internal usage. Do not use in your
78322 * code.
78323 */
78324 -static inline char _tolower(const char c)
78325 +static inline unsigned char _tolower(const unsigned char c)
78326 {
78327 return c | 0x20;
78328 }
78329 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78330 index bf72e9a..4ca7927 100644
78331 --- a/include/linux/dcache.h
78332 +++ b/include/linux/dcache.h
78333 @@ -133,7 +133,7 @@ struct dentry {
78334 } d_u;
78335 struct list_head d_subdirs; /* our children */
78336 struct hlist_node d_alias; /* inode alias list */
78337 -};
78338 +} __randomize_layout;
78339
78340 /*
78341 * dentry->d_lock spinlock nesting subclasses:
78342 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78343 index 7925bf0..d5143d2 100644
78344 --- a/include/linux/decompress/mm.h
78345 +++ b/include/linux/decompress/mm.h
78346 @@ -77,7 +77,7 @@ static void free(void *where)
78347 * warnings when not needed (indeed large_malloc / large_free are not
78348 * needed by inflate */
78349
78350 -#define malloc(a) kmalloc(a, GFP_KERNEL)
78351 +#define malloc(a) kmalloc((a), GFP_KERNEL)
78352 #define free(a) kfree(a)
78353
78354 #define large_malloc(a) vmalloc(a)
78355 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78356 index d48dc00..211ee54 100644
78357 --- a/include/linux/devfreq.h
78358 +++ b/include/linux/devfreq.h
78359 @@ -114,7 +114,7 @@ struct devfreq_governor {
78360 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78361 int (*event_handler)(struct devfreq *devfreq,
78362 unsigned int event, void *data);
78363 -};
78364 +} __do_const;
78365
78366 /**
78367 * struct devfreq - Device devfreq structure
78368 diff --git a/include/linux/device.h b/include/linux/device.h
78369 index 952b010..d5b7691 100644
78370 --- a/include/linux/device.h
78371 +++ b/include/linux/device.h
78372 @@ -310,7 +310,7 @@ struct subsys_interface {
78373 struct list_head node;
78374 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78375 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78376 -};
78377 +} __do_const;
78378
78379 int subsys_interface_register(struct subsys_interface *sif);
78380 void subsys_interface_unregister(struct subsys_interface *sif);
78381 @@ -506,7 +506,7 @@ struct device_type {
78382 void (*release)(struct device *dev);
78383
78384 const struct dev_pm_ops *pm;
78385 -};
78386 +} __do_const;
78387
78388 /* interface for exporting device attributes */
78389 struct device_attribute {
78390 @@ -516,11 +516,12 @@ struct device_attribute {
78391 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78392 const char *buf, size_t count);
78393 };
78394 +typedef struct device_attribute __no_const device_attribute_no_const;
78395
78396 struct dev_ext_attribute {
78397 struct device_attribute attr;
78398 void *var;
78399 -};
78400 +} __do_const;
78401
78402 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78403 char *buf);
78404 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78405 index fd4aee2..1f28db9 100644
78406 --- a/include/linux/dma-mapping.h
78407 +++ b/include/linux/dma-mapping.h
78408 @@ -54,7 +54,7 @@ struct dma_map_ops {
78409 u64 (*get_required_mask)(struct device *dev);
78410 #endif
78411 int is_phys;
78412 -};
78413 +} __do_const;
78414
78415 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78416
78417 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78418 index c5c92d5..6a5c2b2 100644
78419 --- a/include/linux/dmaengine.h
78420 +++ b/include/linux/dmaengine.h
78421 @@ -1150,9 +1150,9 @@ struct dma_pinned_list {
78422 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78423 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78424
78425 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78426 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78427 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78428 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78429 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78430 struct dma_pinned_list *pinned_list, struct page *page,
78431 unsigned int offset, size_t len);
78432
78433 diff --git a/include/linux/efi.h b/include/linux/efi.h
78434 index 0a819e7..8ed47f1 100644
78435 --- a/include/linux/efi.h
78436 +++ b/include/linux/efi.h
78437 @@ -768,6 +768,7 @@ struct efivar_operations {
78438 efi_set_variable_t *set_variable;
78439 efi_query_variable_store_t *query_variable_store;
78440 };
78441 +typedef struct efivar_operations __no_const efivar_operations_no_const;
78442
78443 struct efivars {
78444 /*
78445 diff --git a/include/linux/elf.h b/include/linux/elf.h
78446 index 67a5fa7..b817372 100644
78447 --- a/include/linux/elf.h
78448 +++ b/include/linux/elf.h
78449 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78450 #define elf_note elf32_note
78451 #define elf_addr_t Elf32_Off
78452 #define Elf_Half Elf32_Half
78453 +#define elf_dyn Elf32_Dyn
78454
78455 #else
78456
78457 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78458 #define elf_note elf64_note
78459 #define elf_addr_t Elf64_Off
78460 #define Elf_Half Elf64_Half
78461 +#define elf_dyn Elf64_Dyn
78462
78463 #endif
78464
78465 diff --git a/include/linux/err.h b/include/linux/err.h
78466 index 15f92e0..e825a8e 100644
78467 --- a/include/linux/err.h
78468 +++ b/include/linux/err.h
78469 @@ -19,12 +19,12 @@
78470
78471 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78472
78473 -static inline void * __must_check ERR_PTR(long error)
78474 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78475 {
78476 return (void *) error;
78477 }
78478
78479 -static inline long __must_check PTR_ERR(__force const void *ptr)
78480 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78481 {
78482 return (long) ptr;
78483 }
78484 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78485 index 21c59af..6057a03 100644
78486 --- a/include/linux/extcon.h
78487 +++ b/include/linux/extcon.h
78488 @@ -135,7 +135,7 @@ struct extcon_dev {
78489 /* /sys/class/extcon/.../mutually_exclusive/... */
78490 struct attribute_group attr_g_muex;
78491 struct attribute **attrs_muex;
78492 - struct device_attribute *d_attrs_muex;
78493 + device_attribute_no_const *d_attrs_muex;
78494 };
78495
78496 /**
78497 diff --git a/include/linux/fb.h b/include/linux/fb.h
78498 index fe6ac95..898d41d 100644
78499 --- a/include/linux/fb.h
78500 +++ b/include/linux/fb.h
78501 @@ -304,7 +304,7 @@ struct fb_ops {
78502 /* called at KDB enter and leave time to prepare the console */
78503 int (*fb_debug_enter)(struct fb_info *info);
78504 int (*fb_debug_leave)(struct fb_info *info);
78505 -};
78506 +} __do_const;
78507
78508 #ifdef CONFIG_FB_TILEBLITTING
78509 #define FB_TILE_CURSOR_NONE 0
78510 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78511 index 70e8e21..1939916 100644
78512 --- a/include/linux/fdtable.h
78513 +++ b/include/linux/fdtable.h
78514 @@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78515 void put_files_struct(struct files_struct *fs);
78516 void reset_files_struct(struct files_struct *);
78517 int unshare_files(struct files_struct **);
78518 -struct files_struct *dup_fd(struct files_struct *, int *);
78519 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78520 void do_close_on_exec(struct files_struct *);
78521 int iterate_fd(struct files_struct *, unsigned,
78522 int (*)(const void *, struct file *, unsigned),
78523 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78524 index 8293262..2b3b8bd 100644
78525 --- a/include/linux/frontswap.h
78526 +++ b/include/linux/frontswap.h
78527 @@ -11,7 +11,7 @@ struct frontswap_ops {
78528 int (*load)(unsigned, pgoff_t, struct page *);
78529 void (*invalidate_page)(unsigned, pgoff_t);
78530 void (*invalidate_area)(unsigned);
78531 -};
78532 +} __no_const;
78533
78534 extern bool frontswap_enabled;
78535 extern struct frontswap_ops *
78536 diff --git a/include/linux/fs.h b/include/linux/fs.h
78537 index 23b2a35..8764ab7 100644
78538 --- a/include/linux/fs.h
78539 +++ b/include/linux/fs.h
78540 @@ -426,7 +426,7 @@ struct address_space {
78541 spinlock_t private_lock; /* for use by the address_space */
78542 struct list_head private_list; /* ditto */
78543 void *private_data; /* ditto */
78544 -} __attribute__((aligned(sizeof(long))));
78545 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78546 /*
78547 * On most architectures that alignment is already the case; but
78548 * must be enforced here for CRIS, to let the least significant bit
78549 @@ -469,7 +469,7 @@ struct block_device {
78550 int bd_fsfreeze_count;
78551 /* Mutex for freeze */
78552 struct mutex bd_fsfreeze_mutex;
78553 -};
78554 +} __randomize_layout;
78555
78556 /*
78557 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78558 @@ -613,7 +613,7 @@ struct inode {
78559 atomic_t i_readcount; /* struct files open RO */
78560 #endif
78561 void *i_private; /* fs or device private pointer */
78562 -};
78563 +} __randomize_layout;
78564
78565 static inline int inode_unhashed(struct inode *inode)
78566 {
78567 @@ -812,7 +812,7 @@ struct file {
78568 #ifdef CONFIG_DEBUG_WRITECOUNT
78569 unsigned long f_mnt_write_state;
78570 #endif
78571 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78572 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78573
78574 struct file_handle {
78575 __u32 handle_bytes;
78576 @@ -982,7 +982,7 @@ struct file_lock {
78577 int state; /* state of grant or error if -ve */
78578 } afs;
78579 } fl_u;
78580 -};
78581 +} __randomize_layout;
78582
78583 /* The following constant reflects the upper bound of the file/locking space */
78584 #ifndef OFFSET_MAX
78585 @@ -1329,7 +1329,7 @@ struct super_block {
78586 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78587 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78588 struct rcu_head rcu;
78589 -};
78590 +} __randomize_layout;
78591
78592 extern struct timespec current_fs_time(struct super_block *sb);
78593
78594 @@ -1551,7 +1551,8 @@ struct file_operations {
78595 long (*fallocate)(struct file *file, int mode, loff_t offset,
78596 loff_t len);
78597 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78598 -};
78599 +} __do_const __randomize_layout;
78600 +typedef struct file_operations __no_const file_operations_no_const;
78601
78602 struct inode_operations {
78603 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78604 @@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
78605 return !IS_DEADDIR(inode);
78606 }
78607
78608 +static inline bool is_sidechannel_device(const struct inode *inode)
78609 +{
78610 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78611 + umode_t mode = inode->i_mode;
78612 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78613 +#else
78614 + return false;
78615 +#endif
78616 +}
78617 +
78618 #endif /* _LINUX_FS_H */
78619 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78620 index 0efc3e6..fd23610 100644
78621 --- a/include/linux/fs_struct.h
78622 +++ b/include/linux/fs_struct.h
78623 @@ -6,13 +6,13 @@
78624 #include <linux/seqlock.h>
78625
78626 struct fs_struct {
78627 - int users;
78628 + atomic_t users;
78629 spinlock_t lock;
78630 seqcount_t seq;
78631 int umask;
78632 int in_exec;
78633 struct path root, pwd;
78634 -};
78635 +} __randomize_layout;
78636
78637 extern struct kmem_cache *fs_cachep;
78638
78639 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78640 index 7714849..a4a5c7a 100644
78641 --- a/include/linux/fscache-cache.h
78642 +++ b/include/linux/fscache-cache.h
78643 @@ -113,7 +113,7 @@ struct fscache_operation {
78644 fscache_operation_release_t release;
78645 };
78646
78647 -extern atomic_t fscache_op_debug_id;
78648 +extern atomic_unchecked_t fscache_op_debug_id;
78649 extern void fscache_op_work_func(struct work_struct *work);
78650
78651 extern void fscache_enqueue_operation(struct fscache_operation *);
78652 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78653 INIT_WORK(&op->work, fscache_op_work_func);
78654 atomic_set(&op->usage, 1);
78655 op->state = FSCACHE_OP_ST_INITIALISED;
78656 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78657 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78658 op->processor = processor;
78659 op->release = release;
78660 INIT_LIST_HEAD(&op->pend_link);
78661 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78662 index 115bb81..e7b812b 100644
78663 --- a/include/linux/fscache.h
78664 +++ b/include/linux/fscache.h
78665 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
78666 * - this is mandatory for any object that may have data
78667 */
78668 void (*now_uncached)(void *cookie_netfs_data);
78669 -};
78670 +} __do_const;
78671
78672 /*
78673 * fscache cached network filesystem type
78674 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78675 index 1c804b0..1432c2b 100644
78676 --- a/include/linux/fsnotify.h
78677 +++ b/include/linux/fsnotify.h
78678 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78679 struct inode *inode = file_inode(file);
78680 __u32 mask = FS_ACCESS;
78681
78682 + if (is_sidechannel_device(inode))
78683 + return;
78684 +
78685 if (S_ISDIR(inode->i_mode))
78686 mask |= FS_ISDIR;
78687
78688 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78689 struct inode *inode = file_inode(file);
78690 __u32 mask = FS_MODIFY;
78691
78692 + if (is_sidechannel_device(inode))
78693 + return;
78694 +
78695 if (S_ISDIR(inode->i_mode))
78696 mask |= FS_ISDIR;
78697
78698 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78699 */
78700 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78701 {
78702 - return kstrdup(name, GFP_KERNEL);
78703 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78704 }
78705
78706 /*
78707 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78708 index 9f3c275..8bdff5d 100644
78709 --- a/include/linux/genhd.h
78710 +++ b/include/linux/genhd.h
78711 @@ -194,7 +194,7 @@ struct gendisk {
78712 struct kobject *slave_dir;
78713
78714 struct timer_rand_state *random;
78715 - atomic_t sync_io; /* RAID */
78716 + atomic_unchecked_t sync_io; /* RAID */
78717 struct disk_events *ev;
78718 #ifdef CONFIG_BLK_DEV_INTEGRITY
78719 struct blk_integrity *integrity;
78720 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78721 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78722
78723 /* drivers/char/random.c */
78724 -extern void add_disk_randomness(struct gendisk *disk);
78725 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78726 extern void rand_initialize_disk(struct gendisk *disk);
78727
78728 static inline sector_t get_start_sect(struct block_device *bdev)
78729 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78730 index c0894dd..2fbf10c 100644
78731 --- a/include/linux/genl_magic_func.h
78732 +++ b/include/linux/genl_magic_func.h
78733 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78734 },
78735
78736 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78737 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78738 +static struct genl_ops ZZZ_genl_ops[] = {
78739 #include GENL_MAGIC_INCLUDE_FILE
78740 };
78741
78742 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78743 index 39b81dc..819dc51 100644
78744 --- a/include/linux/gfp.h
78745 +++ b/include/linux/gfp.h
78746 @@ -36,6 +36,13 @@ struct vm_area_struct;
78747 #define ___GFP_NO_KSWAPD 0x400000u
78748 #define ___GFP_OTHER_NODE 0x800000u
78749 #define ___GFP_WRITE 0x1000000u
78750 +
78751 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78752 +#define ___GFP_USERCOPY 0x2000000u
78753 +#else
78754 +#define ___GFP_USERCOPY 0
78755 +#endif
78756 +
78757 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78758
78759 /*
78760 @@ -93,6 +100,7 @@ struct vm_area_struct;
78761 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78762 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78763 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78764 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78765
78766 /*
78767 * This may seem redundant, but it's a way of annotating false positives vs.
78768 @@ -100,7 +108,7 @@ struct vm_area_struct;
78769 */
78770 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78771
78772 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78773 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78774 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78775
78776 /* This equals 0, but use constants in case they ever change */
78777 @@ -158,6 +166,8 @@ struct vm_area_struct;
78778 /* 4GB DMA on some platforms */
78779 #define GFP_DMA32 __GFP_DMA32
78780
78781 +#define GFP_USERCOPY __GFP_USERCOPY
78782 +
78783 /* Convert GFP flags to their corresponding migrate type */
78784 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78785 {
78786 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78787 new file mode 100644
78788 index 0000000..edb2cb6
78789 --- /dev/null
78790 +++ b/include/linux/gracl.h
78791 @@ -0,0 +1,340 @@
78792 +#ifndef GR_ACL_H
78793 +#define GR_ACL_H
78794 +
78795 +#include <linux/grdefs.h>
78796 +#include <linux/resource.h>
78797 +#include <linux/capability.h>
78798 +#include <linux/dcache.h>
78799 +#include <asm/resource.h>
78800 +
78801 +/* Major status information */
78802 +
78803 +#define GR_VERSION "grsecurity 3.0"
78804 +#define GRSECURITY_VERSION 0x3000
78805 +
78806 +enum {
78807 + GR_SHUTDOWN = 0,
78808 + GR_ENABLE = 1,
78809 + GR_SPROLE = 2,
78810 + GR_OLDRELOAD = 3,
78811 + GR_SEGVMOD = 4,
78812 + GR_STATUS = 5,
78813 + GR_UNSPROLE = 6,
78814 + GR_PASSSET = 7,
78815 + GR_SPROLEPAM = 8,
78816 + GR_RELOAD = 9,
78817 +};
78818 +
78819 +/* Password setup definitions
78820 + * kernel/grhash.c */
78821 +enum {
78822 + GR_PW_LEN = 128,
78823 + GR_SALT_LEN = 16,
78824 + GR_SHA_LEN = 32,
78825 +};
78826 +
78827 +enum {
78828 + GR_SPROLE_LEN = 64,
78829 +};
78830 +
78831 +enum {
78832 + GR_NO_GLOB = 0,
78833 + GR_REG_GLOB,
78834 + GR_CREATE_GLOB
78835 +};
78836 +
78837 +#define GR_NLIMITS 32
78838 +
78839 +/* Begin Data Structures */
78840 +
78841 +struct sprole_pw {
78842 + unsigned char *rolename;
78843 + unsigned char salt[GR_SALT_LEN];
78844 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78845 +};
78846 +
78847 +struct name_entry {
78848 + __u32 key;
78849 + ino_t inode;
78850 + dev_t device;
78851 + char *name;
78852 + __u16 len;
78853 + __u8 deleted;
78854 + struct name_entry *prev;
78855 + struct name_entry *next;
78856 +};
78857 +
78858 +struct inodev_entry {
78859 + struct name_entry *nentry;
78860 + struct inodev_entry *prev;
78861 + struct inodev_entry *next;
78862 +};
78863 +
78864 +struct acl_role_db {
78865 + struct acl_role_label **r_hash;
78866 + __u32 r_size;
78867 +};
78868 +
78869 +struct inodev_db {
78870 + struct inodev_entry **i_hash;
78871 + __u32 i_size;
78872 +};
78873 +
78874 +struct name_db {
78875 + struct name_entry **n_hash;
78876 + __u32 n_size;
78877 +};
78878 +
78879 +struct crash_uid {
78880 + uid_t uid;
78881 + unsigned long expires;
78882 +};
78883 +
78884 +struct gr_hash_struct {
78885 + void **table;
78886 + void **nametable;
78887 + void *first;
78888 + __u32 table_size;
78889 + __u32 used_size;
78890 + int type;
78891 +};
78892 +
78893 +/* Userspace Grsecurity ACL data structures */
78894 +
78895 +struct acl_subject_label {
78896 + char *filename;
78897 + ino_t inode;
78898 + dev_t device;
78899 + __u32 mode;
78900 + kernel_cap_t cap_mask;
78901 + kernel_cap_t cap_lower;
78902 + kernel_cap_t cap_invert_audit;
78903 +
78904 + struct rlimit res[GR_NLIMITS];
78905 + __u32 resmask;
78906 +
78907 + __u8 user_trans_type;
78908 + __u8 group_trans_type;
78909 + uid_t *user_transitions;
78910 + gid_t *group_transitions;
78911 + __u16 user_trans_num;
78912 + __u16 group_trans_num;
78913 +
78914 + __u32 sock_families[2];
78915 + __u32 ip_proto[8];
78916 + __u32 ip_type;
78917 + struct acl_ip_label **ips;
78918 + __u32 ip_num;
78919 + __u32 inaddr_any_override;
78920 +
78921 + __u32 crashes;
78922 + unsigned long expires;
78923 +
78924 + struct acl_subject_label *parent_subject;
78925 + struct gr_hash_struct *hash;
78926 + struct acl_subject_label *prev;
78927 + struct acl_subject_label *next;
78928 +
78929 + struct acl_object_label **obj_hash;
78930 + __u32 obj_hash_size;
78931 + __u16 pax_flags;
78932 +};
78933 +
78934 +struct role_allowed_ip {
78935 + __u32 addr;
78936 + __u32 netmask;
78937 +
78938 + struct role_allowed_ip *prev;
78939 + struct role_allowed_ip *next;
78940 +};
78941 +
78942 +struct role_transition {
78943 + char *rolename;
78944 +
78945 + struct role_transition *prev;
78946 + struct role_transition *next;
78947 +};
78948 +
78949 +struct acl_role_label {
78950 + char *rolename;
78951 + uid_t uidgid;
78952 + __u16 roletype;
78953 +
78954 + __u16 auth_attempts;
78955 + unsigned long expires;
78956 +
78957 + struct acl_subject_label *root_label;
78958 + struct gr_hash_struct *hash;
78959 +
78960 + struct acl_role_label *prev;
78961 + struct acl_role_label *next;
78962 +
78963 + struct role_transition *transitions;
78964 + struct role_allowed_ip *allowed_ips;
78965 + uid_t *domain_children;
78966 + __u16 domain_child_num;
78967 +
78968 + umode_t umask;
78969 +
78970 + struct acl_subject_label **subj_hash;
78971 + __u32 subj_hash_size;
78972 +};
78973 +
78974 +struct user_acl_role_db {
78975 + struct acl_role_label **r_table;
78976 + __u32 num_pointers; /* Number of allocations to track */
78977 + __u32 num_roles; /* Number of roles */
78978 + __u32 num_domain_children; /* Number of domain children */
78979 + __u32 num_subjects; /* Number of subjects */
78980 + __u32 num_objects; /* Number of objects */
78981 +};
78982 +
78983 +struct acl_object_label {
78984 + char *filename;
78985 + ino_t inode;
78986 + dev_t device;
78987 + __u32 mode;
78988 +
78989 + struct acl_subject_label *nested;
78990 + struct acl_object_label *globbed;
78991 +
78992 + /* next two structures not used */
78993 +
78994 + struct acl_object_label *prev;
78995 + struct acl_object_label *next;
78996 +};
78997 +
78998 +struct acl_ip_label {
78999 + char *iface;
79000 + __u32 addr;
79001 + __u32 netmask;
79002 + __u16 low, high;
79003 + __u8 mode;
79004 + __u32 type;
79005 + __u32 proto[8];
79006 +
79007 + /* next two structures not used */
79008 +
79009 + struct acl_ip_label *prev;
79010 + struct acl_ip_label *next;
79011 +};
79012 +
79013 +struct gr_arg {
79014 + struct user_acl_role_db role_db;
79015 + unsigned char pw[GR_PW_LEN];
79016 + unsigned char salt[GR_SALT_LEN];
79017 + unsigned char sum[GR_SHA_LEN];
79018 + unsigned char sp_role[GR_SPROLE_LEN];
79019 + struct sprole_pw *sprole_pws;
79020 + dev_t segv_device;
79021 + ino_t segv_inode;
79022 + uid_t segv_uid;
79023 + __u16 num_sprole_pws;
79024 + __u16 mode;
79025 +};
79026 +
79027 +struct gr_arg_wrapper {
79028 + struct gr_arg *arg;
79029 + __u32 version;
79030 + __u32 size;
79031 +};
79032 +
79033 +struct subject_map {
79034 + struct acl_subject_label *user;
79035 + struct acl_subject_label *kernel;
79036 + struct subject_map *prev;
79037 + struct subject_map *next;
79038 +};
79039 +
79040 +struct acl_subj_map_db {
79041 + struct subject_map **s_hash;
79042 + __u32 s_size;
79043 +};
79044 +
79045 +struct gr_policy_state {
79046 + struct sprole_pw **acl_special_roles;
79047 + __u16 num_sprole_pws;
79048 + struct acl_role_label *kernel_role;
79049 + struct acl_role_label *role_list;
79050 + struct acl_role_label *default_role;
79051 + struct acl_role_db acl_role_set;
79052 + struct acl_subj_map_db subj_map_set;
79053 + struct name_db name_set;
79054 + struct inodev_db inodev_set;
79055 +};
79056 +
79057 +struct gr_alloc_state {
79058 + unsigned long alloc_stack_next;
79059 + unsigned long alloc_stack_size;
79060 + void **alloc_stack;
79061 +};
79062 +
79063 +struct gr_reload_state {
79064 + struct gr_policy_state oldpolicy;
79065 + struct gr_alloc_state oldalloc;
79066 + struct gr_policy_state newpolicy;
79067 + struct gr_alloc_state newalloc;
79068 + struct gr_policy_state *oldpolicy_ptr;
79069 + struct gr_alloc_state *oldalloc_ptr;
79070 + unsigned char oldmode;
79071 +};
79072 +
79073 +/* End Data Structures Section */
79074 +
79075 +/* Hash functions generated by empirical testing by Brad Spengler
79076 + Makes good use of the low bits of the inode. Generally 0-1 times
79077 + in loop for successful match. 0-3 for unsuccessful match.
79078 + Shift/add algorithm with modulus of table size and an XOR*/
79079 +
79080 +static __inline__ unsigned int
79081 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
79082 +{
79083 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
79084 +}
79085 +
79086 + static __inline__ unsigned int
79087 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
79088 +{
79089 + return ((const unsigned long)userp % sz);
79090 +}
79091 +
79092 +static __inline__ unsigned int
79093 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
79094 +{
79095 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
79096 +}
79097 +
79098 +static __inline__ unsigned int
79099 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
79100 +{
79101 + return full_name_hash((const unsigned char *)name, len) % sz;
79102 +}
79103 +
79104 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
79105 + subj = NULL; \
79106 + iter = 0; \
79107 + while (iter < role->subj_hash_size) { \
79108 + if (subj == NULL) \
79109 + subj = role->subj_hash[iter]; \
79110 + if (subj == NULL) { \
79111 + iter++; \
79112 + continue; \
79113 + }
79114 +
79115 +#define FOR_EACH_SUBJECT_END(subj,iter) \
79116 + subj = subj->next; \
79117 + if (subj == NULL) \
79118 + iter++; \
79119 + }
79120 +
79121 +
79122 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
79123 + subj = role->hash->first; \
79124 + while (subj != NULL) {
79125 +
79126 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
79127 + subj = subj->next; \
79128 + }
79129 +
79130 +#endif
79131 +
79132 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79133 new file mode 100644
79134 index 0000000..33ebd1f
79135 --- /dev/null
79136 +++ b/include/linux/gracl_compat.h
79137 @@ -0,0 +1,156 @@
79138 +#ifndef GR_ACL_COMPAT_H
79139 +#define GR_ACL_COMPAT_H
79140 +
79141 +#include <linux/resource.h>
79142 +#include <asm/resource.h>
79143 +
79144 +struct sprole_pw_compat {
79145 + compat_uptr_t rolename;
79146 + unsigned char salt[GR_SALT_LEN];
79147 + unsigned char sum[GR_SHA_LEN];
79148 +};
79149 +
79150 +struct gr_hash_struct_compat {
79151 + compat_uptr_t table;
79152 + compat_uptr_t nametable;
79153 + compat_uptr_t first;
79154 + __u32 table_size;
79155 + __u32 used_size;
79156 + int type;
79157 +};
79158 +
79159 +struct acl_subject_label_compat {
79160 + compat_uptr_t filename;
79161 + compat_ino_t inode;
79162 + __u32 device;
79163 + __u32 mode;
79164 + kernel_cap_t cap_mask;
79165 + kernel_cap_t cap_lower;
79166 + kernel_cap_t cap_invert_audit;
79167 +
79168 + struct compat_rlimit res[GR_NLIMITS];
79169 + __u32 resmask;
79170 +
79171 + __u8 user_trans_type;
79172 + __u8 group_trans_type;
79173 + compat_uptr_t user_transitions;
79174 + compat_uptr_t group_transitions;
79175 + __u16 user_trans_num;
79176 + __u16 group_trans_num;
79177 +
79178 + __u32 sock_families[2];
79179 + __u32 ip_proto[8];
79180 + __u32 ip_type;
79181 + compat_uptr_t ips;
79182 + __u32 ip_num;
79183 + __u32 inaddr_any_override;
79184 +
79185 + __u32 crashes;
79186 + compat_ulong_t expires;
79187 +
79188 + compat_uptr_t parent_subject;
79189 + compat_uptr_t hash;
79190 + compat_uptr_t prev;
79191 + compat_uptr_t next;
79192 +
79193 + compat_uptr_t obj_hash;
79194 + __u32 obj_hash_size;
79195 + __u16 pax_flags;
79196 +};
79197 +
79198 +struct role_allowed_ip_compat {
79199 + __u32 addr;
79200 + __u32 netmask;
79201 +
79202 + compat_uptr_t prev;
79203 + compat_uptr_t next;
79204 +};
79205 +
79206 +struct role_transition_compat {
79207 + compat_uptr_t rolename;
79208 +
79209 + compat_uptr_t prev;
79210 + compat_uptr_t next;
79211 +};
79212 +
79213 +struct acl_role_label_compat {
79214 + compat_uptr_t rolename;
79215 + uid_t uidgid;
79216 + __u16 roletype;
79217 +
79218 + __u16 auth_attempts;
79219 + compat_ulong_t expires;
79220 +
79221 + compat_uptr_t root_label;
79222 + compat_uptr_t hash;
79223 +
79224 + compat_uptr_t prev;
79225 + compat_uptr_t next;
79226 +
79227 + compat_uptr_t transitions;
79228 + compat_uptr_t allowed_ips;
79229 + compat_uptr_t domain_children;
79230 + __u16 domain_child_num;
79231 +
79232 + umode_t umask;
79233 +
79234 + compat_uptr_t subj_hash;
79235 + __u32 subj_hash_size;
79236 +};
79237 +
79238 +struct user_acl_role_db_compat {
79239 + compat_uptr_t r_table;
79240 + __u32 num_pointers;
79241 + __u32 num_roles;
79242 + __u32 num_domain_children;
79243 + __u32 num_subjects;
79244 + __u32 num_objects;
79245 +};
79246 +
79247 +struct acl_object_label_compat {
79248 + compat_uptr_t filename;
79249 + compat_ino_t inode;
79250 + __u32 device;
79251 + __u32 mode;
79252 +
79253 + compat_uptr_t nested;
79254 + compat_uptr_t globbed;
79255 +
79256 + compat_uptr_t prev;
79257 + compat_uptr_t next;
79258 +};
79259 +
79260 +struct acl_ip_label_compat {
79261 + compat_uptr_t iface;
79262 + __u32 addr;
79263 + __u32 netmask;
79264 + __u16 low, high;
79265 + __u8 mode;
79266 + __u32 type;
79267 + __u32 proto[8];
79268 +
79269 + compat_uptr_t prev;
79270 + compat_uptr_t next;
79271 +};
79272 +
79273 +struct gr_arg_compat {
79274 + struct user_acl_role_db_compat role_db;
79275 + unsigned char pw[GR_PW_LEN];
79276 + unsigned char salt[GR_SALT_LEN];
79277 + unsigned char sum[GR_SHA_LEN];
79278 + unsigned char sp_role[GR_SPROLE_LEN];
79279 + compat_uptr_t sprole_pws;
79280 + __u32 segv_device;
79281 + compat_ino_t segv_inode;
79282 + uid_t segv_uid;
79283 + __u16 num_sprole_pws;
79284 + __u16 mode;
79285 +};
79286 +
79287 +struct gr_arg_wrapper_compat {
79288 + compat_uptr_t arg;
79289 + __u32 version;
79290 + __u32 size;
79291 +};
79292 +
79293 +#endif
79294 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79295 new file mode 100644
79296 index 0000000..323ecf2
79297 --- /dev/null
79298 +++ b/include/linux/gralloc.h
79299 @@ -0,0 +1,9 @@
79300 +#ifndef __GRALLOC_H
79301 +#define __GRALLOC_H
79302 +
79303 +void acl_free_all(void);
79304 +int acl_alloc_stack_init(unsigned long size);
79305 +void *acl_alloc(unsigned long len);
79306 +void *acl_alloc_num(unsigned long num, unsigned long len);
79307 +
79308 +#endif
79309 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79310 new file mode 100644
79311 index 0000000..be66033
79312 --- /dev/null
79313 +++ b/include/linux/grdefs.h
79314 @@ -0,0 +1,140 @@
79315 +#ifndef GRDEFS_H
79316 +#define GRDEFS_H
79317 +
79318 +/* Begin grsecurity status declarations */
79319 +
79320 +enum {
79321 + GR_READY = 0x01,
79322 + GR_STATUS_INIT = 0x00 // disabled state
79323 +};
79324 +
79325 +/* Begin ACL declarations */
79326 +
79327 +/* Role flags */
79328 +
79329 +enum {
79330 + GR_ROLE_USER = 0x0001,
79331 + GR_ROLE_GROUP = 0x0002,
79332 + GR_ROLE_DEFAULT = 0x0004,
79333 + GR_ROLE_SPECIAL = 0x0008,
79334 + GR_ROLE_AUTH = 0x0010,
79335 + GR_ROLE_NOPW = 0x0020,
79336 + GR_ROLE_GOD = 0x0040,
79337 + GR_ROLE_LEARN = 0x0080,
79338 + GR_ROLE_TPE = 0x0100,
79339 + GR_ROLE_DOMAIN = 0x0200,
79340 + GR_ROLE_PAM = 0x0400,
79341 + GR_ROLE_PERSIST = 0x0800
79342 +};
79343 +
79344 +/* ACL Subject and Object mode flags */
79345 +enum {
79346 + GR_DELETED = 0x80000000
79347 +};
79348 +
79349 +/* ACL Object-only mode flags */
79350 +enum {
79351 + GR_READ = 0x00000001,
79352 + GR_APPEND = 0x00000002,
79353 + GR_WRITE = 0x00000004,
79354 + GR_EXEC = 0x00000008,
79355 + GR_FIND = 0x00000010,
79356 + GR_INHERIT = 0x00000020,
79357 + GR_SETID = 0x00000040,
79358 + GR_CREATE = 0x00000080,
79359 + GR_DELETE = 0x00000100,
79360 + GR_LINK = 0x00000200,
79361 + GR_AUDIT_READ = 0x00000400,
79362 + GR_AUDIT_APPEND = 0x00000800,
79363 + GR_AUDIT_WRITE = 0x00001000,
79364 + GR_AUDIT_EXEC = 0x00002000,
79365 + GR_AUDIT_FIND = 0x00004000,
79366 + GR_AUDIT_INHERIT= 0x00008000,
79367 + GR_AUDIT_SETID = 0x00010000,
79368 + GR_AUDIT_CREATE = 0x00020000,
79369 + GR_AUDIT_DELETE = 0x00040000,
79370 + GR_AUDIT_LINK = 0x00080000,
79371 + GR_PTRACERD = 0x00100000,
79372 + GR_NOPTRACE = 0x00200000,
79373 + GR_SUPPRESS = 0x00400000,
79374 + GR_NOLEARN = 0x00800000,
79375 + GR_INIT_TRANSFER= 0x01000000
79376 +};
79377 +
79378 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79379 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79380 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79381 +
79382 +/* ACL subject-only mode flags */
79383 +enum {
79384 + GR_KILL = 0x00000001,
79385 + GR_VIEW = 0x00000002,
79386 + GR_PROTECTED = 0x00000004,
79387 + GR_LEARN = 0x00000008,
79388 + GR_OVERRIDE = 0x00000010,
79389 + /* just a placeholder, this mode is only used in userspace */
79390 + GR_DUMMY = 0x00000020,
79391 + GR_PROTSHM = 0x00000040,
79392 + GR_KILLPROC = 0x00000080,
79393 + GR_KILLIPPROC = 0x00000100,
79394 + /* just a placeholder, this mode is only used in userspace */
79395 + GR_NOTROJAN = 0x00000200,
79396 + GR_PROTPROCFD = 0x00000400,
79397 + GR_PROCACCT = 0x00000800,
79398 + GR_RELAXPTRACE = 0x00001000,
79399 + //GR_NESTED = 0x00002000,
79400 + GR_INHERITLEARN = 0x00004000,
79401 + GR_PROCFIND = 0x00008000,
79402 + GR_POVERRIDE = 0x00010000,
79403 + GR_KERNELAUTH = 0x00020000,
79404 + GR_ATSECURE = 0x00040000,
79405 + GR_SHMEXEC = 0x00080000
79406 +};
79407 +
79408 +enum {
79409 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79410 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79411 + GR_PAX_ENABLE_MPROTECT = 0x0004,
79412 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
79413 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79414 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79415 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79416 + GR_PAX_DISABLE_MPROTECT = 0x0400,
79417 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
79418 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79419 +};
79420 +
79421 +enum {
79422 + GR_ID_USER = 0x01,
79423 + GR_ID_GROUP = 0x02,
79424 +};
79425 +
79426 +enum {
79427 + GR_ID_ALLOW = 0x01,
79428 + GR_ID_DENY = 0x02,
79429 +};
79430 +
79431 +#define GR_CRASH_RES 31
79432 +#define GR_UIDTABLE_MAX 500
79433 +
79434 +/* begin resource learning section */
79435 +enum {
79436 + GR_RLIM_CPU_BUMP = 60,
79437 + GR_RLIM_FSIZE_BUMP = 50000,
79438 + GR_RLIM_DATA_BUMP = 10000,
79439 + GR_RLIM_STACK_BUMP = 1000,
79440 + GR_RLIM_CORE_BUMP = 10000,
79441 + GR_RLIM_RSS_BUMP = 500000,
79442 + GR_RLIM_NPROC_BUMP = 1,
79443 + GR_RLIM_NOFILE_BUMP = 5,
79444 + GR_RLIM_MEMLOCK_BUMP = 50000,
79445 + GR_RLIM_AS_BUMP = 500000,
79446 + GR_RLIM_LOCKS_BUMP = 2,
79447 + GR_RLIM_SIGPENDING_BUMP = 5,
79448 + GR_RLIM_MSGQUEUE_BUMP = 10000,
79449 + GR_RLIM_NICE_BUMP = 1,
79450 + GR_RLIM_RTPRIO_BUMP = 1,
79451 + GR_RLIM_RTTIME_BUMP = 1000000
79452 +};
79453 +
79454 +#endif
79455 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79456 new file mode 100644
79457 index 0000000..d25522e
79458 --- /dev/null
79459 +++ b/include/linux/grinternal.h
79460 @@ -0,0 +1,229 @@
79461 +#ifndef __GRINTERNAL_H
79462 +#define __GRINTERNAL_H
79463 +
79464 +#ifdef CONFIG_GRKERNSEC
79465 +
79466 +#include <linux/fs.h>
79467 +#include <linux/mnt_namespace.h>
79468 +#include <linux/nsproxy.h>
79469 +#include <linux/gracl.h>
79470 +#include <linux/grdefs.h>
79471 +#include <linux/grmsg.h>
79472 +
79473 +void gr_add_learn_entry(const char *fmt, ...)
79474 + __attribute__ ((format (printf, 1, 2)));
79475 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79476 + const struct vfsmount *mnt);
79477 +__u32 gr_check_create(const struct dentry *new_dentry,
79478 + const struct dentry *parent,
79479 + const struct vfsmount *mnt, const __u32 mode);
79480 +int gr_check_protected_task(const struct task_struct *task);
79481 +__u32 to_gr_audit(const __u32 reqmode);
79482 +int gr_set_acls(const int type);
79483 +int gr_acl_is_enabled(void);
79484 +char gr_roletype_to_char(void);
79485 +
79486 +void gr_handle_alertkill(struct task_struct *task);
79487 +char *gr_to_filename(const struct dentry *dentry,
79488 + const struct vfsmount *mnt);
79489 +char *gr_to_filename1(const struct dentry *dentry,
79490 + const struct vfsmount *mnt);
79491 +char *gr_to_filename2(const struct dentry *dentry,
79492 + const struct vfsmount *mnt);
79493 +char *gr_to_filename3(const struct dentry *dentry,
79494 + const struct vfsmount *mnt);
79495 +
79496 +extern int grsec_enable_ptrace_readexec;
79497 +extern int grsec_enable_harden_ptrace;
79498 +extern int grsec_enable_link;
79499 +extern int grsec_enable_fifo;
79500 +extern int grsec_enable_execve;
79501 +extern int grsec_enable_shm;
79502 +extern int grsec_enable_execlog;
79503 +extern int grsec_enable_signal;
79504 +extern int grsec_enable_audit_ptrace;
79505 +extern int grsec_enable_forkfail;
79506 +extern int grsec_enable_time;
79507 +extern int grsec_enable_rofs;
79508 +extern int grsec_deny_new_usb;
79509 +extern int grsec_enable_chroot_shmat;
79510 +extern int grsec_enable_chroot_mount;
79511 +extern int grsec_enable_chroot_double;
79512 +extern int grsec_enable_chroot_pivot;
79513 +extern int grsec_enable_chroot_chdir;
79514 +extern int grsec_enable_chroot_chmod;
79515 +extern int grsec_enable_chroot_mknod;
79516 +extern int grsec_enable_chroot_fchdir;
79517 +extern int grsec_enable_chroot_nice;
79518 +extern int grsec_enable_chroot_execlog;
79519 +extern int grsec_enable_chroot_caps;
79520 +extern int grsec_enable_chroot_sysctl;
79521 +extern int grsec_enable_chroot_unix;
79522 +extern int grsec_enable_symlinkown;
79523 +extern kgid_t grsec_symlinkown_gid;
79524 +extern int grsec_enable_tpe;
79525 +extern kgid_t grsec_tpe_gid;
79526 +extern int grsec_enable_tpe_all;
79527 +extern int grsec_enable_tpe_invert;
79528 +extern int grsec_enable_socket_all;
79529 +extern kgid_t grsec_socket_all_gid;
79530 +extern int grsec_enable_socket_client;
79531 +extern kgid_t grsec_socket_client_gid;
79532 +extern int grsec_enable_socket_server;
79533 +extern kgid_t grsec_socket_server_gid;
79534 +extern kgid_t grsec_audit_gid;
79535 +extern int grsec_enable_group;
79536 +extern int grsec_enable_log_rwxmaps;
79537 +extern int grsec_enable_mount;
79538 +extern int grsec_enable_chdir;
79539 +extern int grsec_resource_logging;
79540 +extern int grsec_enable_blackhole;
79541 +extern int grsec_lastack_retries;
79542 +extern int grsec_enable_brute;
79543 +extern int grsec_enable_harden_ipc;
79544 +extern int grsec_lock;
79545 +
79546 +extern spinlock_t grsec_alert_lock;
79547 +extern unsigned long grsec_alert_wtime;
79548 +extern unsigned long grsec_alert_fyet;
79549 +
79550 +extern spinlock_t grsec_audit_lock;
79551 +
79552 +extern rwlock_t grsec_exec_file_lock;
79553 +
79554 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79555 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79556 + (tsk)->exec_file->f_path.mnt) : "/")
79557 +
79558 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79559 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79560 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79561 +
79562 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79563 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
79564 + (tsk)->exec_file->f_path.mnt) : "/")
79565 +
79566 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79567 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79568 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79569 +
79570 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79571 +
79572 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79573 +
79574 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79575 +{
79576 + if (file1 && file2) {
79577 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
79578 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
79579 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79580 + return true;
79581 + }
79582 +
79583 + return false;
79584 +}
79585 +
79586 +#define GR_CHROOT_CAPS {{ \
79587 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79588 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79589 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79590 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79591 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79592 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79593 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79594 +
79595 +#define security_learn(normal_msg,args...) \
79596 +({ \
79597 + read_lock(&grsec_exec_file_lock); \
79598 + gr_add_learn_entry(normal_msg "\n", ## args); \
79599 + read_unlock(&grsec_exec_file_lock); \
79600 +})
79601 +
79602 +enum {
79603 + GR_DO_AUDIT,
79604 + GR_DONT_AUDIT,
79605 + /* used for non-audit messages that we shouldn't kill the task on */
79606 + GR_DONT_AUDIT_GOOD
79607 +};
79608 +
79609 +enum {
79610 + GR_TTYSNIFF,
79611 + GR_RBAC,
79612 + GR_RBAC_STR,
79613 + GR_STR_RBAC,
79614 + GR_RBAC_MODE2,
79615 + GR_RBAC_MODE3,
79616 + GR_FILENAME,
79617 + GR_SYSCTL_HIDDEN,
79618 + GR_NOARGS,
79619 + GR_ONE_INT,
79620 + GR_ONE_INT_TWO_STR,
79621 + GR_ONE_STR,
79622 + GR_STR_INT,
79623 + GR_TWO_STR_INT,
79624 + GR_TWO_INT,
79625 + GR_TWO_U64,
79626 + GR_THREE_INT,
79627 + GR_FIVE_INT_TWO_STR,
79628 + GR_TWO_STR,
79629 + GR_THREE_STR,
79630 + GR_FOUR_STR,
79631 + GR_STR_FILENAME,
79632 + GR_FILENAME_STR,
79633 + GR_FILENAME_TWO_INT,
79634 + GR_FILENAME_TWO_INT_STR,
79635 + GR_TEXTREL,
79636 + GR_PTRACE,
79637 + GR_RESOURCE,
79638 + GR_CAP,
79639 + GR_SIG,
79640 + GR_SIG2,
79641 + GR_CRASH1,
79642 + GR_CRASH2,
79643 + GR_PSACCT,
79644 + GR_RWXMAP,
79645 + GR_RWXMAPVMA
79646 +};
79647 +
79648 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79649 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79650 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79651 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79652 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79653 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79654 +#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)
79655 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79656 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79657 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79658 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79659 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79660 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79661 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79662 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79663 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79664 +#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)
79665 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79666 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79667 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79668 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79669 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79670 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79671 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79672 +#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)
79673 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79674 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79675 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79676 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79677 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79678 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79679 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79680 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79681 +#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)
79682 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79683 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79684 +
79685 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79686 +
79687 +#endif
79688 +
79689 +#endif
79690 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79691 new file mode 100644
79692 index 0000000..ba93581
79693 --- /dev/null
79694 +++ b/include/linux/grmsg.h
79695 @@ -0,0 +1,116 @@
79696 +#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"
79697 +#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"
79698 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79699 +#define GR_STOPMOD_MSG "denied modification of module state by "
79700 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79701 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79702 +#define GR_IOPERM_MSG "denied use of ioperm() by "
79703 +#define GR_IOPL_MSG "denied use of iopl() by "
79704 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79705 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79706 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79707 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79708 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79709 +#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"
79710 +#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"
79711 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79712 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79713 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79714 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79715 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79716 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79717 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79718 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79719 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79720 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79721 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79722 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79723 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79724 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79725 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79726 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79727 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79728 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79729 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79730 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79731 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79732 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79733 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79734 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79735 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79736 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79737 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79738 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79739 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79740 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79741 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79742 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79743 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79744 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79745 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79746 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79747 +#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"
79748 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79749 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79750 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79751 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79752 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79753 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79754 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79755 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79756 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79757 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79758 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79759 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79760 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79761 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79762 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79763 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79764 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79765 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79766 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79767 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79768 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
79769 +#define GR_NICE_CHROOT_MSG "denied priority change by "
79770 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79771 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79772 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79773 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79774 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79775 +#define GR_TIME_MSG "time set by "
79776 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79777 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79778 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79779 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79780 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79781 +#define GR_BIND_MSG "denied bind() by "
79782 +#define GR_CONNECT_MSG "denied connect() by "
79783 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79784 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79785 +#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"
79786 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79787 +#define GR_CAP_ACL_MSG "use of %s denied for "
79788 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79789 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79790 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79791 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79792 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79793 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79794 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79795 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79796 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79797 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79798 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79799 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79800 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79801 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79802 +#define GR_VM86_MSG "denied use of vm86 by "
79803 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79804 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79805 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79806 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79807 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79808 +#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 "
79809 +#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 "
79810 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79811 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79812 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79813 new file mode 100644
79814 index 0000000..f2d8c6c
79815 --- /dev/null
79816 +++ b/include/linux/grsecurity.h
79817 @@ -0,0 +1,248 @@
79818 +#ifndef GR_SECURITY_H
79819 +#define GR_SECURITY_H
79820 +#include <linux/fs.h>
79821 +#include <linux/fs_struct.h>
79822 +#include <linux/binfmts.h>
79823 +#include <linux/gracl.h>
79824 +
79825 +/* notify of brain-dead configs */
79826 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79827 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79828 +#endif
79829 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79830 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79831 +#endif
79832 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79833 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79834 +#endif
79835 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79836 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
79837 +#endif
79838 +
79839 +int gr_handle_new_usb(void);
79840 +
79841 +void gr_handle_brute_attach(int dumpable);
79842 +void gr_handle_brute_check(void);
79843 +void gr_handle_kernel_exploit(void);
79844 +
79845 +char gr_roletype_to_char(void);
79846 +
79847 +int gr_proc_is_restricted(void);
79848 +
79849 +int gr_acl_enable_at_secure(void);
79850 +
79851 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79852 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79853 +
79854 +void gr_del_task_from_ip_table(struct task_struct *p);
79855 +
79856 +int gr_pid_is_chrooted(struct task_struct *p);
79857 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79858 +int gr_handle_chroot_nice(void);
79859 +int gr_handle_chroot_sysctl(const int op);
79860 +int gr_handle_chroot_setpriority(struct task_struct *p,
79861 + const int niceval);
79862 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79863 +int gr_handle_chroot_chroot(const struct dentry *dentry,
79864 + const struct vfsmount *mnt);
79865 +void gr_handle_chroot_chdir(const struct path *path);
79866 +int gr_handle_chroot_chmod(const struct dentry *dentry,
79867 + const struct vfsmount *mnt, const int mode);
79868 +int gr_handle_chroot_mknod(const struct dentry *dentry,
79869 + const struct vfsmount *mnt, const int mode);
79870 +int gr_handle_chroot_mount(const struct dentry *dentry,
79871 + const struct vfsmount *mnt,
79872 + const char *dev_name);
79873 +int gr_handle_chroot_pivot(void);
79874 +int gr_handle_chroot_unix(const pid_t pid);
79875 +
79876 +int gr_handle_rawio(const struct inode *inode);
79877 +
79878 +void gr_handle_ioperm(void);
79879 +void gr_handle_iopl(void);
79880 +void gr_handle_msr_write(void);
79881 +
79882 +umode_t gr_acl_umask(void);
79883 +
79884 +int gr_tpe_allow(const struct file *file);
79885 +
79886 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79887 +void gr_clear_chroot_entries(struct task_struct *task);
79888 +
79889 +void gr_log_forkfail(const int retval);
79890 +void gr_log_timechange(void);
79891 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79892 +void gr_log_chdir(const struct dentry *dentry,
79893 + const struct vfsmount *mnt);
79894 +void gr_log_chroot_exec(const struct dentry *dentry,
79895 + const struct vfsmount *mnt);
79896 +void gr_log_remount(const char *devname, const int retval);
79897 +void gr_log_unmount(const char *devname, const int retval);
79898 +void gr_log_mount(const char *from, const char *to, const int retval);
79899 +void gr_log_textrel(struct vm_area_struct *vma);
79900 +void gr_log_ptgnustack(struct file *file);
79901 +void gr_log_rwxmmap(struct file *file);
79902 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
79903 +
79904 +int gr_handle_follow_link(const struct inode *parent,
79905 + const struct inode *inode,
79906 + const struct dentry *dentry,
79907 + const struct vfsmount *mnt);
79908 +int gr_handle_fifo(const struct dentry *dentry,
79909 + const struct vfsmount *mnt,
79910 + const struct dentry *dir, const int flag,
79911 + const int acc_mode);
79912 +int gr_handle_hardlink(const struct dentry *dentry,
79913 + const struct vfsmount *mnt,
79914 + struct inode *inode,
79915 + const int mode, const struct filename *to);
79916 +
79917 +int gr_is_capable(const int cap);
79918 +int gr_is_capable_nolog(const int cap);
79919 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79920 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79921 +
79922 +void gr_copy_label(struct task_struct *tsk);
79923 +void gr_handle_crash(struct task_struct *task, const int sig);
79924 +int gr_handle_signal(const struct task_struct *p, const int sig);
79925 +int gr_check_crash_uid(const kuid_t uid);
79926 +int gr_check_protected_task(const struct task_struct *task);
79927 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79928 +int gr_acl_handle_mmap(const struct file *file,
79929 + const unsigned long prot);
79930 +int gr_acl_handle_mprotect(const struct file *file,
79931 + const unsigned long prot);
79932 +int gr_check_hidden_task(const struct task_struct *tsk);
79933 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79934 + const struct vfsmount *mnt);
79935 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
79936 + const struct vfsmount *mnt);
79937 +__u32 gr_acl_handle_access(const struct dentry *dentry,
79938 + const struct vfsmount *mnt, const int fmode);
79939 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79940 + const struct vfsmount *mnt, umode_t *mode);
79941 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
79942 + const struct vfsmount *mnt);
79943 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79944 + const struct vfsmount *mnt);
79945 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79946 + const struct vfsmount *mnt);
79947 +int gr_handle_ptrace(struct task_struct *task, const long request);
79948 +int gr_handle_proc_ptrace(struct task_struct *task);
79949 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
79950 + const struct vfsmount *mnt);
79951 +int gr_check_crash_exec(const struct file *filp);
79952 +int gr_acl_is_enabled(void);
79953 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79954 + const kgid_t gid);
79955 +int gr_set_proc_label(const struct dentry *dentry,
79956 + const struct vfsmount *mnt,
79957 + const int unsafe_flags);
79958 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79959 + const struct vfsmount *mnt);
79960 +__u32 gr_acl_handle_open(const struct dentry *dentry,
79961 + const struct vfsmount *mnt, int acc_mode);
79962 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
79963 + const struct dentry *p_dentry,
79964 + const struct vfsmount *p_mnt,
79965 + int open_flags, int acc_mode, const int imode);
79966 +void gr_handle_create(const struct dentry *dentry,
79967 + const struct vfsmount *mnt);
79968 +void gr_handle_proc_create(const struct dentry *dentry,
79969 + const struct inode *inode);
79970 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79971 + const struct dentry *parent_dentry,
79972 + const struct vfsmount *parent_mnt,
79973 + const int mode);
79974 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79975 + const struct dentry *parent_dentry,
79976 + const struct vfsmount *parent_mnt);
79977 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79978 + const struct vfsmount *mnt);
79979 +void gr_handle_delete(const ino_t ino, const dev_t dev);
79980 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79981 + const struct vfsmount *mnt);
79982 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79983 + const struct dentry *parent_dentry,
79984 + const struct vfsmount *parent_mnt,
79985 + const struct filename *from);
79986 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79987 + const struct dentry *parent_dentry,
79988 + const struct vfsmount *parent_mnt,
79989 + const struct dentry *old_dentry,
79990 + const struct vfsmount *old_mnt, const struct filename *to);
79991 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79992 +int gr_acl_handle_rename(struct dentry *new_dentry,
79993 + struct dentry *parent_dentry,
79994 + const struct vfsmount *parent_mnt,
79995 + struct dentry *old_dentry,
79996 + struct inode *old_parent_inode,
79997 + struct vfsmount *old_mnt, const struct filename *newname);
79998 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79999 + struct dentry *old_dentry,
80000 + struct dentry *new_dentry,
80001 + struct vfsmount *mnt, const __u8 replace);
80002 +__u32 gr_check_link(const struct dentry *new_dentry,
80003 + const struct dentry *parent_dentry,
80004 + const struct vfsmount *parent_mnt,
80005 + const struct dentry *old_dentry,
80006 + const struct vfsmount *old_mnt);
80007 +int gr_acl_handle_filldir(const struct file *file, const char *name,
80008 + const unsigned int namelen, const ino_t ino);
80009 +
80010 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
80011 + const struct vfsmount *mnt);
80012 +void gr_acl_handle_exit(void);
80013 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
80014 +int gr_acl_handle_procpidmem(const struct task_struct *task);
80015 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
80016 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
80017 +void gr_audit_ptrace(struct task_struct *task);
80018 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
80019 +void gr_put_exec_file(struct task_struct *task);
80020 +
80021 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
80022 +
80023 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
80024 +extern void gr_learn_resource(const struct task_struct *task, const int res,
80025 + const unsigned long wanted, const int gt);
80026 +#else
80027 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
80028 + const unsigned long wanted, const int gt)
80029 +{
80030 +}
80031 +#endif
80032 +
80033 +#ifdef CONFIG_GRKERNSEC_RESLOG
80034 +extern void gr_log_resource(const struct task_struct *task, const int res,
80035 + const unsigned long wanted, const int gt);
80036 +#else
80037 +static inline void gr_log_resource(const struct task_struct *task, const int res,
80038 + const unsigned long wanted, const int gt)
80039 +{
80040 +}
80041 +#endif
80042 +
80043 +#ifdef CONFIG_GRKERNSEC
80044 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
80045 +void gr_handle_vm86(void);
80046 +void gr_handle_mem_readwrite(u64 from, u64 to);
80047 +
80048 +void gr_log_badprocpid(const char *entry);
80049 +
80050 +extern int grsec_enable_dmesg;
80051 +extern int grsec_disable_privio;
80052 +
80053 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80054 +extern kgid_t grsec_proc_gid;
80055 +#endif
80056 +
80057 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
80058 +extern int grsec_enable_chroot_findtask;
80059 +#endif
80060 +#ifdef CONFIG_GRKERNSEC_SETXID
80061 +extern int grsec_enable_setxid;
80062 +#endif
80063 +#endif
80064 +
80065 +#endif
80066 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
80067 new file mode 100644
80068 index 0000000..e7ffaaf
80069 --- /dev/null
80070 +++ b/include/linux/grsock.h
80071 @@ -0,0 +1,19 @@
80072 +#ifndef __GRSOCK_H
80073 +#define __GRSOCK_H
80074 +
80075 +extern void gr_attach_curr_ip(const struct sock *sk);
80076 +extern int gr_handle_sock_all(const int family, const int type,
80077 + const int protocol);
80078 +extern int gr_handle_sock_server(const struct sockaddr *sck);
80079 +extern int gr_handle_sock_server_other(const struct sock *sck);
80080 +extern int gr_handle_sock_client(const struct sockaddr *sck);
80081 +extern int gr_search_connect(struct socket * sock,
80082 + struct sockaddr_in * addr);
80083 +extern int gr_search_bind(struct socket * sock,
80084 + struct sockaddr_in * addr);
80085 +extern int gr_search_listen(struct socket * sock);
80086 +extern int gr_search_accept(struct socket * sock);
80087 +extern int gr_search_socket(const int domain, const int type,
80088 + const int protocol);
80089 +
80090 +#endif
80091 diff --git a/include/linux/hash.h b/include/linux/hash.h
80092 index bd1754c..8240892 100644
80093 --- a/include/linux/hash.h
80094 +++ b/include/linux/hash.h
80095 @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
80096 struct fast_hash_ops {
80097 u32 (*hash)(const void *data, u32 len, u32 seed);
80098 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
80099 -};
80100 +} __no_const;
80101
80102 /**
80103 * arch_fast_hash - Caclulates a hash over a given buffer that can have
80104 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
80105 index 7fb31da..08b5114 100644
80106 --- a/include/linux/highmem.h
80107 +++ b/include/linux/highmem.h
80108 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
80109 kunmap_atomic(kaddr);
80110 }
80111
80112 +static inline void sanitize_highpage(struct page *page)
80113 +{
80114 + void *kaddr;
80115 + unsigned long flags;
80116 +
80117 + local_irq_save(flags);
80118 + kaddr = kmap_atomic(page);
80119 + clear_page(kaddr);
80120 + kunmap_atomic(kaddr);
80121 + local_irq_restore(flags);
80122 +}
80123 +
80124 static inline void zero_user_segments(struct page *page,
80125 unsigned start1, unsigned end1,
80126 unsigned start2, unsigned end2)
80127 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
80128 index 1c7b89a..7dda400 100644
80129 --- a/include/linux/hwmon-sysfs.h
80130 +++ b/include/linux/hwmon-sysfs.h
80131 @@ -25,7 +25,8 @@
80132 struct sensor_device_attribute{
80133 struct device_attribute dev_attr;
80134 int index;
80135 -};
80136 +} __do_const;
80137 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80138 #define to_sensor_dev_attr(_dev_attr) \
80139 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80140
80141 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80142 struct device_attribute dev_attr;
80143 u8 index;
80144 u8 nr;
80145 -};
80146 +} __do_const;
80147 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80148 #define to_sensor_dev_attr_2(_dev_attr) \
80149 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80150
80151 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80152 index deddeb8..bcaf62d 100644
80153 --- a/include/linux/i2c.h
80154 +++ b/include/linux/i2c.h
80155 @@ -378,6 +378,7 @@ struct i2c_algorithm {
80156 /* To determine what the adapter supports */
80157 u32 (*functionality) (struct i2c_adapter *);
80158 };
80159 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80160
80161 /**
80162 * struct i2c_bus_recovery_info - I2C bus recovery information
80163 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80164 index d23c3c2..eb63c81 100644
80165 --- a/include/linux/i2o.h
80166 +++ b/include/linux/i2o.h
80167 @@ -565,7 +565,7 @@ struct i2o_controller {
80168 struct i2o_device *exec; /* Executive */
80169 #if BITS_PER_LONG == 64
80170 spinlock_t context_list_lock; /* lock for context_list */
80171 - atomic_t context_list_counter; /* needed for unique contexts */
80172 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80173 struct list_head context_list; /* list of context id's
80174 and pointers */
80175 #endif
80176 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80177 index aff7ad8..3942bbd 100644
80178 --- a/include/linux/if_pppox.h
80179 +++ b/include/linux/if_pppox.h
80180 @@ -76,7 +76,7 @@ struct pppox_proto {
80181 int (*ioctl)(struct socket *sock, unsigned int cmd,
80182 unsigned long arg);
80183 struct module *owner;
80184 -};
80185 +} __do_const;
80186
80187 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80188 extern void unregister_pppox_proto(int proto_num);
80189 diff --git a/include/linux/init.h b/include/linux/init.h
80190 index e168880..d9b489d 100644
80191 --- a/include/linux/init.h
80192 +++ b/include/linux/init.h
80193 @@ -37,9 +37,17 @@
80194 * section.
80195 */
80196
80197 +#define add_init_latent_entropy __latent_entropy
80198 +
80199 +#ifdef CONFIG_MEMORY_HOTPLUG
80200 +#define add_meminit_latent_entropy
80201 +#else
80202 +#define add_meminit_latent_entropy __latent_entropy
80203 +#endif
80204 +
80205 /* These are for everybody (although not all archs will actually
80206 discard it in modules) */
80207 -#define __init __section(.init.text) __cold notrace
80208 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80209 #define __initdata __section(.init.data)
80210 #define __initconst __constsection(.init.rodata)
80211 #define __exitdata __section(.exit.data)
80212 @@ -100,7 +108,7 @@
80213 #define __cpuexitconst
80214
80215 /* Used for MEMORY_HOTPLUG */
80216 -#define __meminit __section(.meminit.text) __cold notrace
80217 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80218 #define __meminitdata __section(.meminit.data)
80219 #define __meminitconst __constsection(.meminit.rodata)
80220 #define __memexit __section(.memexit.text) __exitused __cold notrace
80221 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80222 index 6df7f9f..d0bf699 100644
80223 --- a/include/linux/init_task.h
80224 +++ b/include/linux/init_task.h
80225 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80226
80227 #define INIT_TASK_COMM "swapper"
80228
80229 +#ifdef CONFIG_X86
80230 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80231 +#else
80232 +#define INIT_TASK_THREAD_INFO
80233 +#endif
80234 +
80235 #ifdef CONFIG_RT_MUTEXES
80236 # define INIT_RT_MUTEXES(tsk) \
80237 .pi_waiters = RB_ROOT, \
80238 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80239 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80240 .comm = INIT_TASK_COMM, \
80241 .thread = INIT_THREAD, \
80242 + INIT_TASK_THREAD_INFO \
80243 .fs = &init_fs, \
80244 .files = &init_files, \
80245 .signal = &init_signals, \
80246 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80247 index a2678d3..e411b1b 100644
80248 --- a/include/linux/interrupt.h
80249 +++ b/include/linux/interrupt.h
80250 @@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80251
80252 struct softirq_action
80253 {
80254 - void (*action)(struct softirq_action *);
80255 -};
80256 + void (*action)(void);
80257 +} __no_const;
80258
80259 asmlinkage void do_softirq(void);
80260 asmlinkage void __do_softirq(void);
80261 @@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
80262 }
80263 #endif
80264
80265 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80266 +extern void open_softirq(int nr, void (*action)(void));
80267 extern void softirq_init(void);
80268 extern void __raise_softirq_irqoff(unsigned int nr);
80269
80270 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80271 index b96a5b2..2732d1c 100644
80272 --- a/include/linux/iommu.h
80273 +++ b/include/linux/iommu.h
80274 @@ -131,7 +131,7 @@ struct iommu_ops {
80275 u32 (*domain_get_windows)(struct iommu_domain *domain);
80276
80277 unsigned long pgsize_bitmap;
80278 -};
80279 +} __do_const;
80280
80281 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80282 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80283 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80284 index 89b7c24..382af74 100644
80285 --- a/include/linux/ioport.h
80286 +++ b/include/linux/ioport.h
80287 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80288 int adjust_resource(struct resource *res, resource_size_t start,
80289 resource_size_t size);
80290 resource_size_t resource_alignment(struct resource *res);
80291 -static inline resource_size_t resource_size(const struct resource *res)
80292 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80293 {
80294 return res->end - res->start + 1;
80295 }
80296 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80297 index 35e7eca..6afb7ad 100644
80298 --- a/include/linux/ipc_namespace.h
80299 +++ b/include/linux/ipc_namespace.h
80300 @@ -69,7 +69,7 @@ struct ipc_namespace {
80301 struct user_namespace *user_ns;
80302
80303 unsigned int proc_inum;
80304 -};
80305 +} __randomize_layout;
80306
80307 extern struct ipc_namespace init_ipc_ns;
80308 extern atomic_t nr_ipc_ns;
80309 diff --git a/include/linux/irq.h b/include/linux/irq.h
80310 index 7dc1003..407327b 100644
80311 --- a/include/linux/irq.h
80312 +++ b/include/linux/irq.h
80313 @@ -338,7 +338,8 @@ struct irq_chip {
80314 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
80315
80316 unsigned long flags;
80317 -};
80318 +} __do_const;
80319 +typedef struct irq_chip __no_const irq_chip_no_const;
80320
80321 /*
80322 * irq_chip specific flags
80323 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80324 index 0ceb389..eed3fb8 100644
80325 --- a/include/linux/irqchip/arm-gic.h
80326 +++ b/include/linux/irqchip/arm-gic.h
80327 @@ -73,9 +73,11 @@
80328
80329 #ifndef __ASSEMBLY__
80330
80331 +#include <linux/irq.h>
80332 +
80333 struct device_node;
80334
80335 -extern struct irq_chip gic_arch_extn;
80336 +extern irq_chip_no_const gic_arch_extn;
80337
80338 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80339 u32 offset, struct device_node *);
80340 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80341 index 1f44466..b481806 100644
80342 --- a/include/linux/jiffies.h
80343 +++ b/include/linux/jiffies.h
80344 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80345 /*
80346 * Convert various time units to each other:
80347 */
80348 -extern unsigned int jiffies_to_msecs(const unsigned long j);
80349 -extern unsigned int jiffies_to_usecs(const unsigned long j);
80350 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80351 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80352
80353 -static inline u64 jiffies_to_nsecs(const unsigned long j)
80354 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80355 {
80356 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80357 }
80358
80359 -extern unsigned long msecs_to_jiffies(const unsigned int m);
80360 -extern unsigned long usecs_to_jiffies(const unsigned int u);
80361 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80362 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80363 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80364 extern void jiffies_to_timespec(const unsigned long jiffies,
80365 - struct timespec *value);
80366 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
80367 + struct timespec *value) __intentional_overflow(-1);
80368 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80369 extern void jiffies_to_timeval(const unsigned long jiffies,
80370 struct timeval *value);
80371
80372 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80373 index 6883e19..e854fcb 100644
80374 --- a/include/linux/kallsyms.h
80375 +++ b/include/linux/kallsyms.h
80376 @@ -15,7 +15,8 @@
80377
80378 struct module;
80379
80380 -#ifdef CONFIG_KALLSYMS
80381 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80382 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80383 /* Lookup the address for a symbol. Returns 0 if not found. */
80384 unsigned long kallsyms_lookup_name(const char *name);
80385
80386 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80387 /* Stupid that this does nothing, but I didn't create this mess. */
80388 #define __print_symbol(fmt, addr)
80389 #endif /*CONFIG_KALLSYMS*/
80390 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80391 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80392 +extern unsigned long kallsyms_lookup_name(const char *name);
80393 +extern void __print_symbol(const char *fmt, unsigned long address);
80394 +extern int sprint_backtrace(char *buffer, unsigned long address);
80395 +extern int sprint_symbol(char *buffer, unsigned long address);
80396 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80397 +const char *kallsyms_lookup(unsigned long addr,
80398 + unsigned long *symbolsize,
80399 + unsigned long *offset,
80400 + char **modname, char *namebuf);
80401 +extern int kallsyms_lookup_size_offset(unsigned long addr,
80402 + unsigned long *symbolsize,
80403 + unsigned long *offset);
80404 +#endif
80405
80406 /* This macro allows us to keep printk typechecking */
80407 static __printf(1, 2)
80408 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80409 index a74c3a8..28d3f21 100644
80410 --- a/include/linux/key-type.h
80411 +++ b/include/linux/key-type.h
80412 @@ -131,7 +131,7 @@ struct key_type {
80413 /* internal fields */
80414 struct list_head link; /* link in types list */
80415 struct lock_class_key lock_class; /* key->sem lock class */
80416 -};
80417 +} __do_const;
80418
80419 extern struct key_type key_type_keyring;
80420
80421 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80422 index 6b06d37..c134867 100644
80423 --- a/include/linux/kgdb.h
80424 +++ b/include/linux/kgdb.h
80425 @@ -52,7 +52,7 @@ extern int kgdb_connected;
80426 extern int kgdb_io_module_registered;
80427
80428 extern atomic_t kgdb_setting_breakpoint;
80429 -extern atomic_t kgdb_cpu_doing_single_step;
80430 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80431
80432 extern struct task_struct *kgdb_usethread;
80433 extern struct task_struct *kgdb_contthread;
80434 @@ -254,7 +254,7 @@ struct kgdb_arch {
80435 void (*correct_hw_break)(void);
80436
80437 void (*enable_nmi)(bool on);
80438 -};
80439 +} __do_const;
80440
80441 /**
80442 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80443 @@ -279,7 +279,7 @@ struct kgdb_io {
80444 void (*pre_exception) (void);
80445 void (*post_exception) (void);
80446 int is_console;
80447 -};
80448 +} __do_const;
80449
80450 extern struct kgdb_arch arch_kgdb_ops;
80451
80452 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80453 index 0555cc6..40116ce 100644
80454 --- a/include/linux/kmod.h
80455 +++ b/include/linux/kmod.h
80456 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80457 * usually useless though. */
80458 extern __printf(2, 3)
80459 int __request_module(bool wait, const char *name, ...);
80460 +extern __printf(3, 4)
80461 +int ___request_module(bool wait, char *param_name, const char *name, ...);
80462 #define request_module(mod...) __request_module(true, mod)
80463 #define request_module_nowait(mod...) __request_module(false, mod)
80464 #define try_then_request_module(x, mod...) \
80465 @@ -57,6 +59,9 @@ struct subprocess_info {
80466 struct work_struct work;
80467 struct completion *complete;
80468 char *path;
80469 +#ifdef CONFIG_GRKERNSEC
80470 + char *origpath;
80471 +#endif
80472 char **argv;
80473 char **envp;
80474 int wait;
80475 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80476 index 926afb6..58dd6e5 100644
80477 --- a/include/linux/kobject.h
80478 +++ b/include/linux/kobject.h
80479 @@ -116,7 +116,7 @@ struct kobj_type {
80480 struct attribute **default_attrs;
80481 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80482 const void *(*namespace)(struct kobject *kobj);
80483 -};
80484 +} __do_const;
80485
80486 struct kobj_uevent_env {
80487 char *envp[UEVENT_NUM_ENVP];
80488 @@ -139,6 +139,7 @@ struct kobj_attribute {
80489 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80490 const char *buf, size_t count);
80491 };
80492 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80493
80494 extern const struct sysfs_ops kobj_sysfs_ops;
80495
80496 @@ -166,7 +167,7 @@ struct kset {
80497 spinlock_t list_lock;
80498 struct kobject kobj;
80499 const struct kset_uevent_ops *uevent_ops;
80500 -};
80501 +} __randomize_layout;
80502
80503 extern void kset_init(struct kset *kset);
80504 extern int __must_check kset_register(struct kset *kset);
80505 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80506 index df32d25..fb52e27 100644
80507 --- a/include/linux/kobject_ns.h
80508 +++ b/include/linux/kobject_ns.h
80509 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80510 const void *(*netlink_ns)(struct sock *sk);
80511 const void *(*initial_ns)(void);
80512 void (*drop_ns)(void *);
80513 -};
80514 +} __do_const;
80515
80516 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80517 int kobj_ns_type_registered(enum kobj_ns_type type);
80518 diff --git a/include/linux/kref.h b/include/linux/kref.h
80519 index 484604d..0f6c5b6 100644
80520 --- a/include/linux/kref.h
80521 +++ b/include/linux/kref.h
80522 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80523 static inline int kref_sub(struct kref *kref, unsigned int count,
80524 void (*release)(struct kref *kref))
80525 {
80526 - WARN_ON(release == NULL);
80527 + BUG_ON(release == NULL);
80528
80529 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80530 release(kref);
80531 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80532 index b8e9a43..632678d 100644
80533 --- a/include/linux/kvm_host.h
80534 +++ b/include/linux/kvm_host.h
80535 @@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
80536 {
80537 }
80538 #endif
80539 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80540 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80541 struct module *module);
80542 void kvm_exit(void);
80543
80544 @@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80545 struct kvm_guest_debug *dbg);
80546 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80547
80548 -int kvm_arch_init(void *opaque);
80549 +int kvm_arch_init(const void *opaque);
80550 void kvm_arch_exit(void);
80551
80552 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80553 diff --git a/include/linux/libata.h b/include/linux/libata.h
80554 index 3fee55e..42565b7 100644
80555 --- a/include/linux/libata.h
80556 +++ b/include/linux/libata.h
80557 @@ -976,7 +976,7 @@ struct ata_port_operations {
80558 * fields must be pointers.
80559 */
80560 const struct ata_port_operations *inherits;
80561 -};
80562 +} __do_const;
80563
80564 struct ata_port_info {
80565 unsigned long flags;
80566 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80567 index a6a42dd..6c5ebce 100644
80568 --- a/include/linux/linkage.h
80569 +++ b/include/linux/linkage.h
80570 @@ -36,6 +36,7 @@
80571 #endif
80572
80573 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80574 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80575 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80576
80577 /*
80578 diff --git a/include/linux/list.h b/include/linux/list.h
80579 index ef95941..82db65a 100644
80580 --- a/include/linux/list.h
80581 +++ b/include/linux/list.h
80582 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80583 extern void list_del(struct list_head *entry);
80584 #endif
80585
80586 +extern void __pax_list_add(struct list_head *new,
80587 + struct list_head *prev,
80588 + struct list_head *next);
80589 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
80590 +{
80591 + __pax_list_add(new, head, head->next);
80592 +}
80593 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80594 +{
80595 + __pax_list_add(new, head->prev, head);
80596 +}
80597 +extern void pax_list_del(struct list_head *entry);
80598 +
80599 /**
80600 * list_replace - replace old entry by new one
80601 * @old : the element to be replaced
80602 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80603 INIT_LIST_HEAD(entry);
80604 }
80605
80606 +extern void pax_list_del_init(struct list_head *entry);
80607 +
80608 /**
80609 * list_move - delete from one list and add as another's head
80610 * @list: the entry to move
80611 diff --git a/include/linux/math64.h b/include/linux/math64.h
80612 index c45c089..298841c 100644
80613 --- a/include/linux/math64.h
80614 +++ b/include/linux/math64.h
80615 @@ -15,7 +15,7 @@
80616 * This is commonly provided by 32bit archs to provide an optimized 64bit
80617 * divide.
80618 */
80619 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80620 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80621 {
80622 *remainder = dividend % divisor;
80623 return dividend / divisor;
80624 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80625 /**
80626 * div64_u64 - unsigned 64bit divide with 64bit divisor
80627 */
80628 -static inline u64 div64_u64(u64 dividend, u64 divisor)
80629 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80630 {
80631 return dividend / divisor;
80632 }
80633 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80634 #define div64_ul(x, y) div_u64((x), (y))
80635
80636 #ifndef div_u64_rem
80637 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80638 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80639 {
80640 *remainder = do_div(dividend, divisor);
80641 return dividend;
80642 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80643 #endif
80644
80645 #ifndef div64_u64
80646 -extern u64 div64_u64(u64 dividend, u64 divisor);
80647 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80648 #endif
80649
80650 #ifndef div64_s64
80651 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80652 * divide.
80653 */
80654 #ifndef div_u64
80655 -static inline u64 div_u64(u64 dividend, u32 divisor)
80656 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80657 {
80658 u32 remainder;
80659 return div_u64_rem(dividend, divisor, &remainder);
80660 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80661 index 5f1ea75..5125ac5 100644
80662 --- a/include/linux/mempolicy.h
80663 +++ b/include/linux/mempolicy.h
80664 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80665 }
80666
80667 #define vma_policy(vma) ((vma)->vm_policy)
80668 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80669 +{
80670 + vma->vm_policy = pol;
80671 +}
80672
80673 static inline void mpol_get(struct mempolicy *pol)
80674 {
80675 @@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80676 }
80677
80678 #define vma_policy(vma) NULL
80679 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80680 +{
80681 +}
80682
80683 static inline int
80684 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80685 diff --git a/include/linux/mm.h b/include/linux/mm.h
80686 index c1b7414..5ea2ad8 100644
80687 --- a/include/linux/mm.h
80688 +++ b/include/linux/mm.h
80689 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80690 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80691 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80692 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80693 +
80694 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80695 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80696 +#endif
80697 +
80698 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80699
80700 #ifdef CONFIG_MEM_SOFT_DIRTY
80701 @@ -229,8 +234,8 @@ struct vm_operations_struct {
80702 /* called by access_process_vm when get_user_pages() fails, typically
80703 * for use by special VMAs that can switch between memory and hardware
80704 */
80705 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
80706 - void *buf, int len, int write);
80707 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80708 + void *buf, size_t len, int write);
80709 #ifdef CONFIG_NUMA
80710 /*
80711 * set_policy() op must add a reference to any non-NULL @new mempolicy
80712 @@ -260,6 +265,7 @@ struct vm_operations_struct {
80713 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80714 unsigned long size, pgoff_t pgoff);
80715 };
80716 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80717
80718 struct mmu_gather;
80719 struct inode;
80720 @@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80721 unsigned long *pfn);
80722 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80723 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80724 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80725 - void *buf, int len, int write);
80726 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80727 + void *buf, size_t len, int write);
80728
80729 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80730 loff_t const holebegin, loff_t const holelen)
80731 @@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80732 }
80733 #endif
80734
80735 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80736 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80737 - void *buf, int len, int write);
80738 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80739 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80740 + void *buf, size_t len, int write);
80741
80742 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80743 unsigned long start, unsigned long nr_pages,
80744 @@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
80745 int set_page_dirty_lock(struct page *page);
80746 int clear_page_dirty_for_io(struct page *page);
80747
80748 -/* Is the vma a continuation of the stack vma above it? */
80749 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80750 -{
80751 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80752 -}
80753 -
80754 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
80755 - unsigned long addr)
80756 -{
80757 - return (vma->vm_flags & VM_GROWSDOWN) &&
80758 - (vma->vm_start == addr) &&
80759 - !vma_growsdown(vma->vm_prev, addr);
80760 -}
80761 -
80762 -/* Is the vma a continuation of the stack vma below it? */
80763 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80764 -{
80765 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80766 -}
80767 -
80768 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
80769 - unsigned long addr)
80770 -{
80771 - return (vma->vm_flags & VM_GROWSUP) &&
80772 - (vma->vm_end == addr) &&
80773 - !vma_growsup(vma->vm_next, addr);
80774 -}
80775 -
80776 extern pid_t
80777 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80778
80779 @@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80780 }
80781 #endif
80782
80783 +#ifdef CONFIG_MMU
80784 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80785 +#else
80786 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80787 +{
80788 + return __pgprot(0);
80789 +}
80790 +#endif
80791 +
80792 int vma_wants_writenotify(struct vm_area_struct *vma);
80793
80794 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80795 @@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80796 {
80797 return 0;
80798 }
80799 +
80800 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80801 + unsigned long address)
80802 +{
80803 + return 0;
80804 +}
80805 #else
80806 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80807 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80808 #endif
80809
80810 #ifdef __PAGETABLE_PMD_FOLDED
80811 @@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80812 {
80813 return 0;
80814 }
80815 +
80816 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80817 + unsigned long address)
80818 +{
80819 + return 0;
80820 +}
80821 #else
80822 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80823 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80824 #endif
80825
80826 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80827 @@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80828 NULL: pud_offset(pgd, address);
80829 }
80830
80831 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80832 +{
80833 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80834 + NULL: pud_offset(pgd, address);
80835 +}
80836 +
80837 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80838 {
80839 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80840 NULL: pmd_offset(pud, address);
80841 }
80842 +
80843 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80844 +{
80845 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80846 + NULL: pmd_offset(pud, address);
80847 +}
80848 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80849
80850 #if USE_SPLIT_PTE_PTLOCKS
80851 @@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80852 unsigned long addr, unsigned long len,
80853 unsigned long flags, struct page **pages);
80854
80855 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80856 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80857
80858 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80859 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80860 @@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80861 unsigned long len, unsigned long prot, unsigned long flags,
80862 unsigned long pgoff, unsigned long *populate);
80863 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80864 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80865
80866 #ifdef CONFIG_MMU
80867 extern int __mm_populate(unsigned long addr, unsigned long len,
80868 @@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
80869 unsigned long high_limit;
80870 unsigned long align_mask;
80871 unsigned long align_offset;
80872 + unsigned long threadstack_offset;
80873 };
80874
80875 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80876 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80877 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80878 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80879
80880 /*
80881 * Search for an unmapped address range.
80882 @@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80883 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80884 */
80885 static inline unsigned long
80886 -vm_unmapped_area(struct vm_unmapped_area_info *info)
80887 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
80888 {
80889 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80890 return unmapped_area(info);
80891 @@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80892 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80893 struct vm_area_struct **pprev);
80894
80895 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80896 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80897 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80898 +
80899 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80900 NULL if none. Assume start_addr < end_addr. */
80901 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80902 @@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80903 return vma;
80904 }
80905
80906 -#ifdef CONFIG_MMU
80907 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
80908 -#else
80909 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80910 -{
80911 - return __pgprot(0);
80912 -}
80913 -#endif
80914 -
80915 #ifdef CONFIG_NUMA_BALANCING
80916 unsigned long change_prot_numa(struct vm_area_struct *vma,
80917 unsigned long start, unsigned long end);
80918 @@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80919 static inline void vm_stat_account(struct mm_struct *mm,
80920 unsigned long flags, struct file *file, long pages)
80921 {
80922 +
80923 +#ifdef CONFIG_PAX_RANDMMAP
80924 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80925 +#endif
80926 +
80927 mm->total_vm += pages;
80928 }
80929 #endif /* CONFIG_PROC_FS */
80930 @@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
80931 extern int sysctl_memory_failure_early_kill;
80932 extern int sysctl_memory_failure_recovery;
80933 extern void shake_page(struct page *p, int access);
80934 -extern atomic_long_t num_poisoned_pages;
80935 +extern atomic_long_unchecked_t num_poisoned_pages;
80936 extern int soft_offline_page(struct page *page, int flags);
80937
80938 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80939 @@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
80940 static inline void setup_nr_node_ids(void) {}
80941 #endif
80942
80943 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80944 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80945 +#else
80946 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80947 +#endif
80948 +
80949 #endif /* __KERNEL__ */
80950 #endif /* _LINUX_MM_H */
80951 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80952 index 290901a..e99b01c 100644
80953 --- a/include/linux/mm_types.h
80954 +++ b/include/linux/mm_types.h
80955 @@ -307,7 +307,9 @@ struct vm_area_struct {
80956 #ifdef CONFIG_NUMA
80957 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80958 #endif
80959 -};
80960 +
80961 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80962 +} __randomize_layout;
80963
80964 struct core_thread {
80965 struct task_struct *task;
80966 @@ -453,7 +455,25 @@ struct mm_struct {
80967 bool tlb_flush_pending;
80968 #endif
80969 struct uprobes_state uprobes_state;
80970 -};
80971 +
80972 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80973 + unsigned long pax_flags;
80974 +#endif
80975 +
80976 +#ifdef CONFIG_PAX_DLRESOLVE
80977 + unsigned long call_dl_resolve;
80978 +#endif
80979 +
80980 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80981 + unsigned long call_syscall;
80982 +#endif
80983 +
80984 +#ifdef CONFIG_PAX_ASLR
80985 + unsigned long delta_mmap; /* randomized offset */
80986 + unsigned long delta_stack; /* randomized offset */
80987 +#endif
80988 +
80989 +} __randomize_layout;
80990
80991 static inline void mm_init_cpumask(struct mm_struct *mm)
80992 {
80993 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80994 index c5d5278..f0b68c8 100644
80995 --- a/include/linux/mmiotrace.h
80996 +++ b/include/linux/mmiotrace.h
80997 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80998 /* Called from ioremap.c */
80999 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
81000 void __iomem *addr);
81001 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
81002 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
81003
81004 /* For anyone to insert markers. Remember trailing newline. */
81005 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
81006 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
81007 {
81008 }
81009
81010 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
81011 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
81012 {
81013 }
81014
81015 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
81016 index 9b61b9b..52147d6b 100644
81017 --- a/include/linux/mmzone.h
81018 +++ b/include/linux/mmzone.h
81019 @@ -396,7 +396,7 @@ struct zone {
81020 unsigned long flags; /* zone flags, see below */
81021
81022 /* Zone statistics */
81023 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81024 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81025
81026 /*
81027 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
81028 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
81029 index 45e9214..a7227d6 100644
81030 --- a/include/linux/mod_devicetable.h
81031 +++ b/include/linux/mod_devicetable.h
81032 @@ -13,7 +13,7 @@
81033 typedef unsigned long kernel_ulong_t;
81034 #endif
81035
81036 -#define PCI_ANY_ID (~0)
81037 +#define PCI_ANY_ID ((__u16)~0)
81038
81039 struct pci_device_id {
81040 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
81041 @@ -139,7 +139,7 @@ struct usb_device_id {
81042 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
81043 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
81044
81045 -#define HID_ANY_ID (~0)
81046 +#define HID_ANY_ID (~0U)
81047 #define HID_BUS_ANY 0xffff
81048 #define HID_GROUP_ANY 0x0000
81049
81050 @@ -467,7 +467,7 @@ struct dmi_system_id {
81051 const char *ident;
81052 struct dmi_strmatch matches[4];
81053 void *driver_data;
81054 -};
81055 +} __do_const;
81056 /*
81057 * struct dmi_device_id appears during expansion of
81058 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
81059 diff --git a/include/linux/module.h b/include/linux/module.h
81060 index eaf60ff..641979a 100644
81061 --- a/include/linux/module.h
81062 +++ b/include/linux/module.h
81063 @@ -17,9 +17,11 @@
81064 #include <linux/moduleparam.h>
81065 #include <linux/tracepoint.h>
81066 #include <linux/export.h>
81067 +#include <linux/fs.h>
81068
81069 #include <linux/percpu.h>
81070 #include <asm/module.h>
81071 +#include <asm/pgtable.h>
81072
81073 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
81074 #define MODULE_SIG_STRING "~Module signature appended~\n"
81075 @@ -42,7 +44,7 @@ struct module_kobject {
81076 struct kobject *drivers_dir;
81077 struct module_param_attrs *mp;
81078 struct completion *kobj_completion;
81079 -};
81080 +} __randomize_layout;
81081
81082 struct module_attribute {
81083 struct attribute attr;
81084 @@ -54,12 +56,13 @@ struct module_attribute {
81085 int (*test)(struct module *);
81086 void (*free)(struct module *);
81087 };
81088 +typedef struct module_attribute __no_const module_attribute_no_const;
81089
81090 struct module_version_attribute {
81091 struct module_attribute mattr;
81092 const char *module_name;
81093 const char *version;
81094 -} __attribute__ ((__aligned__(sizeof(void *))));
81095 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
81096
81097 extern ssize_t __modver_version_show(struct module_attribute *,
81098 struct module_kobject *, char *);
81099 @@ -238,7 +241,7 @@ struct module {
81100
81101 /* Sysfs stuff. */
81102 struct module_kobject mkobj;
81103 - struct module_attribute *modinfo_attrs;
81104 + module_attribute_no_const *modinfo_attrs;
81105 const char *version;
81106 const char *srcversion;
81107 struct kobject *holders_dir;
81108 @@ -287,19 +290,16 @@ struct module {
81109 int (*init)(void);
81110
81111 /* If this is non-NULL, vfree after init() returns */
81112 - void *module_init;
81113 + void *module_init_rx, *module_init_rw;
81114
81115 /* Here is the actual code + data, vfree'd on unload. */
81116 - void *module_core;
81117 + void *module_core_rx, *module_core_rw;
81118
81119 /* Here are the sizes of the init and core sections */
81120 - unsigned int init_size, core_size;
81121 + unsigned int init_size_rw, core_size_rw;
81122
81123 /* The size of the executable code in each section. */
81124 - unsigned int init_text_size, core_text_size;
81125 -
81126 - /* Size of RO sections of the module (text+rodata) */
81127 - unsigned int init_ro_size, core_ro_size;
81128 + unsigned int init_size_rx, core_size_rx;
81129
81130 /* Arch-specific module values */
81131 struct mod_arch_specific arch;
81132 @@ -355,6 +355,10 @@ struct module {
81133 #ifdef CONFIG_EVENT_TRACING
81134 struct ftrace_event_call **trace_events;
81135 unsigned int num_trace_events;
81136 + struct file_operations trace_id;
81137 + struct file_operations trace_enable;
81138 + struct file_operations trace_format;
81139 + struct file_operations trace_filter;
81140 #endif
81141 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81142 unsigned int num_ftrace_callsites;
81143 @@ -378,7 +382,7 @@ struct module {
81144 ctor_fn_t *ctors;
81145 unsigned int num_ctors;
81146 #endif
81147 -};
81148 +} __randomize_layout;
81149 #ifndef MODULE_ARCH_INIT
81150 #define MODULE_ARCH_INIT {}
81151 #endif
81152 @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
81153 bool is_module_percpu_address(unsigned long addr);
81154 bool is_module_text_address(unsigned long addr);
81155
81156 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81157 +{
81158 +
81159 +#ifdef CONFIG_PAX_KERNEXEC
81160 + if (ktla_ktva(addr) >= (unsigned long)start &&
81161 + ktla_ktva(addr) < (unsigned long)start + size)
81162 + return 1;
81163 +#endif
81164 +
81165 + return ((void *)addr >= start && (void *)addr < start + size);
81166 +}
81167 +
81168 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81169 +{
81170 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81171 +}
81172 +
81173 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81174 +{
81175 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81176 +}
81177 +
81178 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81179 +{
81180 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81181 +}
81182 +
81183 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81184 +{
81185 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81186 +}
81187 +
81188 static inline int within_module_core(unsigned long addr, const struct module *mod)
81189 {
81190 - return (unsigned long)mod->module_core <= addr &&
81191 - addr < (unsigned long)mod->module_core + mod->core_size;
81192 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81193 }
81194
81195 static inline int within_module_init(unsigned long addr, const struct module *mod)
81196 {
81197 - return (unsigned long)mod->module_init <= addr &&
81198 - addr < (unsigned long)mod->module_init + mod->init_size;
81199 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81200 }
81201
81202 /* Search for module by name: must hold module_mutex. */
81203 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81204 index 560ca53..ef621ef 100644
81205 --- a/include/linux/moduleloader.h
81206 +++ b/include/linux/moduleloader.h
81207 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81208 sections. Returns NULL on failure. */
81209 void *module_alloc(unsigned long size);
81210
81211 +#ifdef CONFIG_PAX_KERNEXEC
81212 +void *module_alloc_exec(unsigned long size);
81213 +#else
81214 +#define module_alloc_exec(x) module_alloc(x)
81215 +#endif
81216 +
81217 /* Free memory returned from module_alloc. */
81218 void module_free(struct module *mod, void *module_region);
81219
81220 +#ifdef CONFIG_PAX_KERNEXEC
81221 +void module_free_exec(struct module *mod, void *module_region);
81222 +#else
81223 +#define module_free_exec(x, y) module_free((x), (y))
81224 +#endif
81225 +
81226 /*
81227 * Apply the given relocation to the (simplified) ELF. Return -error
81228 * or 0.
81229 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81230 unsigned int relsec,
81231 struct module *me)
81232 {
81233 +#ifdef CONFIG_MODULES
81234 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81235 +#endif
81236 return -ENOEXEC;
81237 }
81238 #endif
81239 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81240 unsigned int relsec,
81241 struct module *me)
81242 {
81243 +#ifdef CONFIG_MODULES
81244 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81245 +#endif
81246 return -ENOEXEC;
81247 }
81248 #endif
81249 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81250 index c3eb102..073c4a6 100644
81251 --- a/include/linux/moduleparam.h
81252 +++ b/include/linux/moduleparam.h
81253 @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
81254 * @len is usually just sizeof(string).
81255 */
81256 #define module_param_string(name, string, len, perm) \
81257 - static const struct kparam_string __param_string_##name \
81258 + static const struct kparam_string __param_string_##name __used \
81259 = { len, string }; \
81260 __module_param_call(MODULE_PARAM_PREFIX, name, \
81261 &param_ops_string, \
81262 @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81263 */
81264 #define module_param_array_named(name, array, type, nump, perm) \
81265 param_check_##type(name, &(array)[0]); \
81266 - static const struct kparam_array __param_arr_##name \
81267 + static const struct kparam_array __param_arr_##name __used \
81268 = { .max = ARRAY_SIZE(array), .num = nump, \
81269 .ops = &param_ops_##type, \
81270 .elemsize = sizeof(array[0]), .elem = array }; \
81271 diff --git a/include/linux/mount.h b/include/linux/mount.h
81272 index 839bac2..a96b37c 100644
81273 --- a/include/linux/mount.h
81274 +++ b/include/linux/mount.h
81275 @@ -59,7 +59,7 @@ struct vfsmount {
81276 struct dentry *mnt_root; /* root of the mounted tree */
81277 struct super_block *mnt_sb; /* pointer to superblock */
81278 int mnt_flags;
81279 -};
81280 +} __randomize_layout;
81281
81282 struct file; /* forward dec */
81283
81284 diff --git a/include/linux/namei.h b/include/linux/namei.h
81285 index 492de72..1bddcd4 100644
81286 --- a/include/linux/namei.h
81287 +++ b/include/linux/namei.h
81288 @@ -19,7 +19,7 @@ struct nameidata {
81289 unsigned seq, m_seq;
81290 int last_type;
81291 unsigned depth;
81292 - char *saved_names[MAX_NESTED_LINKS + 1];
81293 + const char *saved_names[MAX_NESTED_LINKS + 1];
81294 };
81295
81296 /*
81297 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81298
81299 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81300
81301 -static inline void nd_set_link(struct nameidata *nd, char *path)
81302 +static inline void nd_set_link(struct nameidata *nd, const char *path)
81303 {
81304 nd->saved_names[nd->depth] = path;
81305 }
81306
81307 -static inline char *nd_get_link(struct nameidata *nd)
81308 +static inline const char *nd_get_link(const struct nameidata *nd)
81309 {
81310 return nd->saved_names[nd->depth];
81311 }
81312 diff --git a/include/linux/net.h b/include/linux/net.h
81313 index 94734a6..d8d6931 100644
81314 --- a/include/linux/net.h
81315 +++ b/include/linux/net.h
81316 @@ -192,7 +192,7 @@ struct net_proto_family {
81317 int (*create)(struct net *net, struct socket *sock,
81318 int protocol, int kern);
81319 struct module *owner;
81320 -};
81321 +} __do_const;
81322
81323 struct iovec;
81324 struct kvec;
81325 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81326 index daafd95..74c5d1e 100644
81327 --- a/include/linux/netdevice.h
81328 +++ b/include/linux/netdevice.h
81329 @@ -1146,6 +1146,7 @@ struct net_device_ops {
81330 struct net_device *dev,
81331 void *priv);
81332 };
81333 +typedef struct net_device_ops __no_const net_device_ops_no_const;
81334
81335 /*
81336 * The DEVICE structure.
81337 @@ -1228,7 +1229,7 @@ struct net_device {
81338 int iflink;
81339
81340 struct net_device_stats stats;
81341 - atomic_long_t rx_dropped; /* dropped packets by core network
81342 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
81343 * Do not use this in drivers.
81344 */
81345
81346 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81347 index 2077489..a15e561 100644
81348 --- a/include/linux/netfilter.h
81349 +++ b/include/linux/netfilter.h
81350 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81351 #endif
81352 /* Use the module struct to lock set/get code in place */
81353 struct module *owner;
81354 -};
81355 +} __do_const;
81356
81357 /* Function to register/unregister hook points. */
81358 int nf_register_hook(struct nf_hook_ops *reg);
81359 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81360 index 28c7436..2d6156a 100644
81361 --- a/include/linux/netfilter/nfnetlink.h
81362 +++ b/include/linux/netfilter/nfnetlink.h
81363 @@ -19,7 +19,7 @@ struct nfnl_callback {
81364 const struct nlattr * const cda[]);
81365 const struct nla_policy *policy; /* netlink attribute policy */
81366 const u_int16_t attr_count; /* number of nlattr's */
81367 -};
81368 +} __do_const;
81369
81370 struct nfnetlink_subsystem {
81371 const char *name;
81372 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81373 new file mode 100644
81374 index 0000000..33f4af8
81375 --- /dev/null
81376 +++ b/include/linux/netfilter/xt_gradm.h
81377 @@ -0,0 +1,9 @@
81378 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
81379 +#define _LINUX_NETFILTER_XT_GRADM_H 1
81380 +
81381 +struct xt_gradm_mtinfo {
81382 + __u16 flags;
81383 + __u16 invflags;
81384 +};
81385 +
81386 +#endif
81387 diff --git a/include/linux/nls.h b/include/linux/nls.h
81388 index 520681b..1d67ed2 100644
81389 --- a/include/linux/nls.h
81390 +++ b/include/linux/nls.h
81391 @@ -31,7 +31,7 @@ struct nls_table {
81392 const unsigned char *charset2upper;
81393 struct module *owner;
81394 struct nls_table *next;
81395 -};
81396 +} __do_const;
81397
81398 /* this value hold the maximum octet of charset */
81399 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81400 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81401 index d14a4c3..a078786 100644
81402 --- a/include/linux/notifier.h
81403 +++ b/include/linux/notifier.h
81404 @@ -54,7 +54,8 @@ struct notifier_block {
81405 notifier_fn_t notifier_call;
81406 struct notifier_block __rcu *next;
81407 int priority;
81408 -};
81409 +} __do_const;
81410 +typedef struct notifier_block __no_const notifier_block_no_const;
81411
81412 struct atomic_notifier_head {
81413 spinlock_t lock;
81414 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81415 index b2a0f15..4d7da32 100644
81416 --- a/include/linux/oprofile.h
81417 +++ b/include/linux/oprofile.h
81418 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81419 int oprofilefs_create_ro_ulong(struct dentry * root,
81420 char const * name, ulong * val);
81421
81422 -/** Create a file for read-only access to an atomic_t. */
81423 +/** Create a file for read-only access to an atomic_unchecked_t. */
81424 int oprofilefs_create_ro_atomic(struct dentry * root,
81425 - char const * name, atomic_t * val);
81426 + char const * name, atomic_unchecked_t * val);
81427
81428 /** create a directory */
81429 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81430 diff --git a/include/linux/padata.h b/include/linux/padata.h
81431 index 4386946..f50c615 100644
81432 --- a/include/linux/padata.h
81433 +++ b/include/linux/padata.h
81434 @@ -129,7 +129,7 @@ struct parallel_data {
81435 struct padata_serial_queue __percpu *squeue;
81436 atomic_t reorder_objects;
81437 atomic_t refcnt;
81438 - atomic_t seq_nr;
81439 + atomic_unchecked_t seq_nr;
81440 struct padata_cpumask cpumask;
81441 spinlock_t lock ____cacheline_aligned;
81442 unsigned int processed;
81443 diff --git a/include/linux/path.h b/include/linux/path.h
81444 index d137218..be0c176 100644
81445 --- a/include/linux/path.h
81446 +++ b/include/linux/path.h
81447 @@ -1,13 +1,15 @@
81448 #ifndef _LINUX_PATH_H
81449 #define _LINUX_PATH_H
81450
81451 +#include <linux/compiler.h>
81452 +
81453 struct dentry;
81454 struct vfsmount;
81455
81456 struct path {
81457 struct vfsmount *mnt;
81458 struct dentry *dentry;
81459 -};
81460 +} __randomize_layout;
81461
81462 extern void path_get(const struct path *);
81463 extern void path_put(const struct path *);
81464 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81465 index 5f2e559..7d59314 100644
81466 --- a/include/linux/pci_hotplug.h
81467 +++ b/include/linux/pci_hotplug.h
81468 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81469 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81470 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81471 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81472 -};
81473 +} __do_const;
81474 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81475
81476 /**
81477 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81478 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81479 index e56b07f..aef789b 100644
81480 --- a/include/linux/perf_event.h
81481 +++ b/include/linux/perf_event.h
81482 @@ -328,8 +328,8 @@ struct perf_event {
81483
81484 enum perf_event_active_state state;
81485 unsigned int attach_state;
81486 - local64_t count;
81487 - atomic64_t child_count;
81488 + local64_t count; /* PaX: fix it one day */
81489 + atomic64_unchecked_t child_count;
81490
81491 /*
81492 * These are the total time in nanoseconds that the event
81493 @@ -380,8 +380,8 @@ struct perf_event {
81494 * These accumulate total time (in nanoseconds) that children
81495 * events have been enabled and running, respectively.
81496 */
81497 - atomic64_t child_total_time_enabled;
81498 - atomic64_t child_total_time_running;
81499 + atomic64_unchecked_t child_total_time_enabled;
81500 + atomic64_unchecked_t child_total_time_running;
81501
81502 /*
81503 * Protect attach/detach and child_list:
81504 @@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81505 entry->ip[entry->nr++] = ip;
81506 }
81507
81508 -extern int sysctl_perf_event_paranoid;
81509 +extern int sysctl_perf_event_legitimately_concerned;
81510 extern int sysctl_perf_event_mlock;
81511 extern int sysctl_perf_event_sample_rate;
81512 extern int sysctl_perf_cpu_time_max_percent;
81513 @@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81514 loff_t *ppos);
81515
81516
81517 +static inline bool perf_paranoid_any(void)
81518 +{
81519 + return sysctl_perf_event_legitimately_concerned > 2;
81520 +}
81521 +
81522 static inline bool perf_paranoid_tracepoint_raw(void)
81523 {
81524 - return sysctl_perf_event_paranoid > -1;
81525 + return sysctl_perf_event_legitimately_concerned > -1;
81526 }
81527
81528 static inline bool perf_paranoid_cpu(void)
81529 {
81530 - return sysctl_perf_event_paranoid > 0;
81531 + return sysctl_perf_event_legitimately_concerned > 0;
81532 }
81533
81534 static inline bool perf_paranoid_kernel(void)
81535 {
81536 - return sysctl_perf_event_paranoid > 1;
81537 + return sysctl_perf_event_legitimately_concerned > 1;
81538 }
81539
81540 extern void perf_event_init(void);
81541 @@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
81542 struct device_attribute attr;
81543 u64 id;
81544 const char *event_str;
81545 -};
81546 +} __do_const;
81547
81548 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81549 static struct perf_pmu_events_attr _var = { \
81550 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81551 index 7246ef3..1539ea4 100644
81552 --- a/include/linux/pid_namespace.h
81553 +++ b/include/linux/pid_namespace.h
81554 @@ -43,7 +43,7 @@ struct pid_namespace {
81555 int hide_pid;
81556 int reboot; /* group exit code if this pidns was rebooted */
81557 unsigned int proc_inum;
81558 -};
81559 +} __randomize_layout;
81560
81561 extern struct pid_namespace init_pid_ns;
81562
81563 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81564 index ab57526..94598804 100644
81565 --- a/include/linux/pipe_fs_i.h
81566 +++ b/include/linux/pipe_fs_i.h
81567 @@ -47,10 +47,10 @@ struct pipe_inode_info {
81568 struct mutex mutex;
81569 wait_queue_head_t wait;
81570 unsigned int nrbufs, curbuf, buffers;
81571 - unsigned int readers;
81572 - unsigned int writers;
81573 - unsigned int files;
81574 - unsigned int waiting_writers;
81575 + atomic_t readers;
81576 + atomic_t writers;
81577 + atomic_t files;
81578 + atomic_t waiting_writers;
81579 unsigned int r_counter;
81580 unsigned int w_counter;
81581 struct page *tmp_page;
81582 diff --git a/include/linux/pm.h b/include/linux/pm.h
81583 index 8c6583a..febb84c 100644
81584 --- a/include/linux/pm.h
81585 +++ b/include/linux/pm.h
81586 @@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81587 struct dev_pm_domain {
81588 struct dev_pm_ops ops;
81589 };
81590 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81591
81592 /*
81593 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81594 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81595 index 7c1d252..0e7061d 100644
81596 --- a/include/linux/pm_domain.h
81597 +++ b/include/linux/pm_domain.h
81598 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
81599 int (*thaw_early)(struct device *dev);
81600 int (*thaw)(struct device *dev);
81601 bool (*active_wakeup)(struct device *dev);
81602 -};
81603 +} __no_const;
81604
81605 struct gpd_cpu_data {
81606 unsigned int saved_exit_latency;
81607 - struct cpuidle_state *idle_state;
81608 + cpuidle_state_no_const *idle_state;
81609 };
81610
81611 struct generic_pm_domain {
81612 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81613 index 16c9a62..f9f0838 100644
81614 --- a/include/linux/pm_runtime.h
81615 +++ b/include/linux/pm_runtime.h
81616 @@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81617
81618 static inline void pm_runtime_mark_last_busy(struct device *dev)
81619 {
81620 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
81621 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81622 }
81623
81624 #else /* !CONFIG_PM_RUNTIME */
81625 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81626 index 195aafc..49a7bc2 100644
81627 --- a/include/linux/pnp.h
81628 +++ b/include/linux/pnp.h
81629 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81630 struct pnp_fixup {
81631 char id[7];
81632 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81633 -};
81634 +} __do_const;
81635
81636 /* config parameters */
81637 #define PNP_CONFIG_NORMAL 0x0001
81638 diff --git a/include/linux/poison.h b/include/linux/poison.h
81639 index 2110a81..13a11bb 100644
81640 --- a/include/linux/poison.h
81641 +++ b/include/linux/poison.h
81642 @@ -19,8 +19,8 @@
81643 * under normal circumstances, used to verify that nobody uses
81644 * non-initialized list entries.
81645 */
81646 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81647 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81648 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81649 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81650
81651 /********** include/linux/timer.h **********/
81652 /*
81653 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81654 index d8b187c3..9a9257a 100644
81655 --- a/include/linux/power/smartreflex.h
81656 +++ b/include/linux/power/smartreflex.h
81657 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
81658 int (*notify)(struct omap_sr *sr, u32 status);
81659 u8 notify_flags;
81660 u8 class_type;
81661 -};
81662 +} __do_const;
81663
81664 /**
81665 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81666 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81667 index 4ea1d37..80f4b33 100644
81668 --- a/include/linux/ppp-comp.h
81669 +++ b/include/linux/ppp-comp.h
81670 @@ -84,7 +84,7 @@ struct compressor {
81671 struct module *owner;
81672 /* Extra skb space needed by the compressor algorithm */
81673 unsigned int comp_extra;
81674 -};
81675 +} __do_const;
81676
81677 /*
81678 * The return value from decompress routine is the length of the
81679 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81680 index de83b4e..c4b997d 100644
81681 --- a/include/linux/preempt.h
81682 +++ b/include/linux/preempt.h
81683 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81684 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81685 #endif
81686
81687 +#define raw_preempt_count_add(val) __preempt_count_add(val)
81688 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81689 +
81690 #define __preempt_count_inc() __preempt_count_add(1)
81691 #define __preempt_count_dec() __preempt_count_sub(1)
81692
81693 #define preempt_count_inc() preempt_count_add(1)
81694 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
81695 #define preempt_count_dec() preempt_count_sub(1)
81696 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81697
81698 #ifdef CONFIG_PREEMPT_COUNT
81699
81700 @@ -41,6 +46,12 @@ do { \
81701 barrier(); \
81702 } while (0)
81703
81704 +#define raw_preempt_disable() \
81705 +do { \
81706 + raw_preempt_count_inc(); \
81707 + barrier(); \
81708 +} while (0)
81709 +
81710 #define sched_preempt_enable_no_resched() \
81711 do { \
81712 barrier(); \
81713 @@ -49,6 +60,12 @@ do { \
81714
81715 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81716
81717 +#define raw_preempt_enable_no_resched() \
81718 +do { \
81719 + barrier(); \
81720 + raw_preempt_count_dec(); \
81721 +} while (0)
81722 +
81723 #ifdef CONFIG_PREEMPT
81724 #define preempt_enable() \
81725 do { \
81726 @@ -113,8 +130,10 @@ do { \
81727 * region.
81728 */
81729 #define preempt_disable() barrier()
81730 +#define raw_preempt_disable() barrier()
81731 #define sched_preempt_enable_no_resched() barrier()
81732 #define preempt_enable_no_resched() barrier()
81733 +#define raw_preempt_enable_no_resched() barrier()
81734 #define preempt_enable() barrier()
81735 #define preempt_check_resched() do { } while (0)
81736
81737 @@ -128,11 +147,13 @@ do { \
81738 /*
81739 * Modules have no business playing preemption tricks.
81740 */
81741 +#ifndef CONFIG_PAX_KERNEXEC
81742 #undef sched_preempt_enable_no_resched
81743 #undef preempt_enable_no_resched
81744 #undef preempt_enable_no_resched_notrace
81745 #undef preempt_check_resched
81746 #endif
81747 +#endif
81748
81749 #define preempt_set_need_resched() \
81750 do { \
81751 diff --git a/include/linux/printk.h b/include/linux/printk.h
81752 index fa47e27..c08e034 100644
81753 --- a/include/linux/printk.h
81754 +++ b/include/linux/printk.h
81755 @@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
81756 void early_printk(const char *s, ...) { }
81757 #endif
81758
81759 +extern int kptr_restrict;
81760 +
81761 #ifdef CONFIG_PRINTK
81762 asmlinkage __printf(5, 0)
81763 int vprintk_emit(int facility, int level,
81764 @@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81765
81766 extern int printk_delay_msec;
81767 extern int dmesg_restrict;
81768 -extern int kptr_restrict;
81769
81770 extern void wake_up_klogd(void);
81771
81772 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81773 index 608e60a..bbcb1a0 100644
81774 --- a/include/linux/proc_fs.h
81775 +++ b/include/linux/proc_fs.h
81776 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81777 extern struct proc_dir_entry *proc_symlink(const char *,
81778 struct proc_dir_entry *, const char *);
81779 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81780 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81781 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81782 struct proc_dir_entry *, void *);
81783 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81784 + struct proc_dir_entry *, void *);
81785 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81786 struct proc_dir_entry *);
81787
81788 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81789 return proc_create_data(name, mode, parent, proc_fops, NULL);
81790 }
81791
81792 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81793 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81794 +{
81795 +#ifdef CONFIG_GRKERNSEC_PROC_USER
81796 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81797 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81798 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81799 +#else
81800 + return proc_create_data(name, mode, parent, proc_fops, NULL);
81801 +#endif
81802 +}
81803 +
81804 +
81805 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81806 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81807 extern void *PDE_DATA(const struct inode *);
81808 @@ -73,7 +89,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81809 static inline struct proc_dir_entry *proc_net_mkdir(
81810 struct net *net, const char *name, struct proc_dir_entry *parent)
81811 {
81812 - return proc_mkdir_data(name, 0, parent, net);
81813 + return proc_mkdir_data_restrict(name, 0, parent, net);
81814 }
81815
81816 #endif /* _LINUX_PROC_FS_H */
81817 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81818 index 34a1e10..70f6bde 100644
81819 --- a/include/linux/proc_ns.h
81820 +++ b/include/linux/proc_ns.h
81821 @@ -14,7 +14,7 @@ struct proc_ns_operations {
81822 void (*put)(void *ns);
81823 int (*install)(struct nsproxy *nsproxy, void *ns);
81824 unsigned int (*inum)(void *ns);
81825 -};
81826 +} __do_const __randomize_layout;
81827
81828 struct proc_ns {
81829 void *ns;
81830 diff --git a/include/linux/quota.h b/include/linux/quota.h
81831 index cc7494a..1e27036 100644
81832 --- a/include/linux/quota.h
81833 +++ b/include/linux/quota.h
81834 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81835
81836 extern bool qid_eq(struct kqid left, struct kqid right);
81837 extern bool qid_lt(struct kqid left, struct kqid right);
81838 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81839 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81840 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81841 extern bool qid_valid(struct kqid qid);
81842
81843 diff --git a/include/linux/random.h b/include/linux/random.h
81844 index 1cfce0e..b0b9235 100644
81845 --- a/include/linux/random.h
81846 +++ b/include/linux/random.h
81847 @@ -9,9 +9,19 @@
81848 #include <uapi/linux/random.h>
81849
81850 extern void add_device_randomness(const void *, unsigned int);
81851 +
81852 +static inline void add_latent_entropy(void)
81853 +{
81854 +
81855 +#ifdef LATENT_ENTROPY_PLUGIN
81856 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81857 +#endif
81858 +
81859 +}
81860 +
81861 extern void add_input_randomness(unsigned int type, unsigned int code,
81862 - unsigned int value);
81863 -extern void add_interrupt_randomness(int irq, int irq_flags);
81864 + unsigned int value) __latent_entropy;
81865 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81866
81867 extern void get_random_bytes(void *buf, int nbytes);
81868 extern void get_random_bytes_arch(void *buf, int nbytes);
81869 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81870 extern const struct file_operations random_fops, urandom_fops;
81871 #endif
81872
81873 -unsigned int get_random_int(void);
81874 +unsigned int __intentional_overflow(-1) get_random_int(void);
81875 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81876
81877 -u32 prandom_u32(void);
81878 +u32 prandom_u32(void) __intentional_overflow(-1);
81879 void prandom_bytes(void *buf, int nbytes);
81880 void prandom_seed(u32 seed);
81881 void prandom_reseed_late(void);
81882 @@ -37,6 +47,11 @@ struct rnd_state {
81883 u32 prandom_u32_state(struct rnd_state *state);
81884 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81885
81886 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81887 +{
81888 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81889 +}
81890 +
81891 /**
81892 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81893 * @ep_ro: right open interval endpoint
81894 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81895 index fea49b5..2ac22bb 100644
81896 --- a/include/linux/rbtree_augmented.h
81897 +++ b/include/linux/rbtree_augmented.h
81898 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81899 old->rbaugmented = rbcompute(old); \
81900 } \
81901 rbstatic const struct rb_augment_callbacks rbname = { \
81902 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81903 + .propagate = rbname ## _propagate, \
81904 + .copy = rbname ## _copy, \
81905 + .rotate = rbname ## _rotate \
81906 };
81907
81908
81909 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81910 index dbaf990..52e07b8 100644
81911 --- a/include/linux/rculist.h
81912 +++ b/include/linux/rculist.h
81913 @@ -29,8 +29,8 @@
81914 */
81915 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81916 {
81917 - ACCESS_ONCE(list->next) = list;
81918 - ACCESS_ONCE(list->prev) = list;
81919 + ACCESS_ONCE_RW(list->next) = list;
81920 + ACCESS_ONCE_RW(list->prev) = list;
81921 }
81922
81923 /*
81924 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81925 struct list_head *prev, struct list_head *next);
81926 #endif
81927
81928 +void __pax_list_add_rcu(struct list_head *new,
81929 + struct list_head *prev, struct list_head *next);
81930 +
81931 /**
81932 * list_add_rcu - add a new entry to rcu-protected list
81933 * @new: new entry to be added
81934 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81935 __list_add_rcu(new, head, head->next);
81936 }
81937
81938 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81939 +{
81940 + __pax_list_add_rcu(new, head, head->next);
81941 +}
81942 +
81943 /**
81944 * list_add_tail_rcu - add a new entry to rcu-protected list
81945 * @new: new entry to be added
81946 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81947 __list_add_rcu(new, head->prev, head);
81948 }
81949
81950 +static inline void pax_list_add_tail_rcu(struct list_head *new,
81951 + struct list_head *head)
81952 +{
81953 + __pax_list_add_rcu(new, head->prev, head);
81954 +}
81955 +
81956 /**
81957 * list_del_rcu - deletes entry from list without re-initialization
81958 * @entry: the element to delete from the list.
81959 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81960 entry->prev = LIST_POISON2;
81961 }
81962
81963 +extern void pax_list_del_rcu(struct list_head *entry);
81964 +
81965 /**
81966 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81967 * @n: the element to delete from the hash list.
81968 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
81969 index 72bf3a0..853347f 100644
81970 --- a/include/linux/rcupdate.h
81971 +++ b/include/linux/rcupdate.h
81972 @@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
81973 #define rcu_assign_pointer(p, v) \
81974 do { \
81975 smp_wmb(); \
81976 - ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
81977 + ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
81978 } while (0)
81979
81980
81981 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81982 index 9e7db9e..7d4fd72 100644
81983 --- a/include/linux/reboot.h
81984 +++ b/include/linux/reboot.h
81985 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81986 */
81987
81988 extern void migrate_to_reboot_cpu(void);
81989 -extern void machine_restart(char *cmd);
81990 -extern void machine_halt(void);
81991 -extern void machine_power_off(void);
81992 +extern void machine_restart(char *cmd) __noreturn;
81993 +extern void machine_halt(void) __noreturn;
81994 +extern void machine_power_off(void) __noreturn;
81995
81996 extern void machine_shutdown(void);
81997 struct pt_regs;
81998 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81999 */
82000
82001 extern void kernel_restart_prepare(char *cmd);
82002 -extern void kernel_restart(char *cmd);
82003 -extern void kernel_halt(void);
82004 -extern void kernel_power_off(void);
82005 +extern void kernel_restart(char *cmd) __noreturn;
82006 +extern void kernel_halt(void) __noreturn;
82007 +extern void kernel_power_off(void) __noreturn;
82008
82009 extern int C_A_D; /* for sysctl */
82010 void ctrl_alt_del(void);
82011 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
82012 * Emergency restart, callable from an interrupt handler.
82013 */
82014
82015 -extern void emergency_restart(void);
82016 +extern void emergency_restart(void) __noreturn;
82017 #include <asm/emergency-restart.h>
82018
82019 #endif /* _LINUX_REBOOT_H */
82020 diff --git a/include/linux/regset.h b/include/linux/regset.h
82021 index 8e0c9fe..ac4d221 100644
82022 --- a/include/linux/regset.h
82023 +++ b/include/linux/regset.h
82024 @@ -161,7 +161,8 @@ struct user_regset {
82025 unsigned int align;
82026 unsigned int bias;
82027 unsigned int core_note_type;
82028 -};
82029 +} __do_const;
82030 +typedef struct user_regset __no_const user_regset_no_const;
82031
82032 /**
82033 * struct user_regset_view - available regsets
82034 diff --git a/include/linux/relay.h b/include/linux/relay.h
82035 index d7c8359..818daf5 100644
82036 --- a/include/linux/relay.h
82037 +++ b/include/linux/relay.h
82038 @@ -157,7 +157,7 @@ struct rchan_callbacks
82039 * The callback should return 0 if successful, negative if not.
82040 */
82041 int (*remove_buf_file)(struct dentry *dentry);
82042 -};
82043 +} __no_const;
82044
82045 /*
82046 * CONFIG_RELAY kernel API, kernel/relay.c
82047 diff --git a/include/linux/rio.h b/include/linux/rio.h
82048 index b71d573..2f940bd 100644
82049 --- a/include/linux/rio.h
82050 +++ b/include/linux/rio.h
82051 @@ -355,7 +355,7 @@ struct rio_ops {
82052 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
82053 u64 rstart, u32 size, u32 flags);
82054 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
82055 -};
82056 +} __no_const;
82057
82058 #define RIO_RESOURCE_MEM 0x00000100
82059 #define RIO_RESOURCE_DOORBELL 0x00000200
82060 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
82061 index b66c211..13d2915 100644
82062 --- a/include/linux/rmap.h
82063 +++ b/include/linux/rmap.h
82064 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
82065 void anon_vma_init(void); /* create anon_vma_cachep */
82066 int anon_vma_prepare(struct vm_area_struct *);
82067 void unlink_anon_vmas(struct vm_area_struct *);
82068 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
82069 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
82070 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
82071 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
82072
82073 static inline void anon_vma_merge(struct vm_area_struct *vma,
82074 struct vm_area_struct *next)
82075 diff --git a/include/linux/sched.h b/include/linux/sched.h
82076 index a781dec..be1d2a3 100644
82077 --- a/include/linux/sched.h
82078 +++ b/include/linux/sched.h
82079 @@ -129,6 +129,7 @@ struct fs_struct;
82080 struct perf_event_context;
82081 struct blk_plug;
82082 struct filename;
82083 +struct linux_binprm;
82084
82085 /*
82086 * List of flags we want to share for kernel threads,
82087 @@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
82088 extern int in_sched_functions(unsigned long addr);
82089
82090 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
82091 -extern signed long schedule_timeout(signed long timeout);
82092 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
82093 extern signed long schedule_timeout_interruptible(signed long timeout);
82094 extern signed long schedule_timeout_killable(signed long timeout);
82095 extern signed long schedule_timeout_uninterruptible(signed long timeout);
82096 @@ -380,6 +381,19 @@ struct nsproxy;
82097 struct user_namespace;
82098
82099 #ifdef CONFIG_MMU
82100 +
82101 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82102 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
82103 +#else
82104 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82105 +{
82106 + return 0;
82107 +}
82108 +#endif
82109 +
82110 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82111 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82112 +
82113 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82114 extern unsigned long
82115 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82116 @@ -677,6 +691,17 @@ struct signal_struct {
82117 #ifdef CONFIG_TASKSTATS
82118 struct taskstats *stats;
82119 #endif
82120 +
82121 +#ifdef CONFIG_GRKERNSEC
82122 + u32 curr_ip;
82123 + u32 saved_ip;
82124 + u32 gr_saddr;
82125 + u32 gr_daddr;
82126 + u16 gr_sport;
82127 + u16 gr_dport;
82128 + u8 used_accept:1;
82129 +#endif
82130 +
82131 #ifdef CONFIG_AUDIT
82132 unsigned audit_tty;
82133 unsigned audit_tty_log_passwd;
82134 @@ -703,7 +728,7 @@ struct signal_struct {
82135 struct mutex cred_guard_mutex; /* guard against foreign influences on
82136 * credential calculations
82137 * (notably. ptrace) */
82138 -};
82139 +} __randomize_layout;
82140
82141 /*
82142 * Bits in flags field of signal_struct.
82143 @@ -757,6 +782,14 @@ struct user_struct {
82144 struct key *session_keyring; /* UID's default session keyring */
82145 #endif
82146
82147 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82148 + unsigned char kernel_banned;
82149 +#endif
82150 +#ifdef CONFIG_GRKERNSEC_BRUTE
82151 + unsigned char suid_banned;
82152 + unsigned long suid_ban_expires;
82153 +#endif
82154 +
82155 /* Hash table maintenance information */
82156 struct hlist_node uidhash_node;
82157 kuid_t uid;
82158 @@ -764,7 +797,7 @@ struct user_struct {
82159 #ifdef CONFIG_PERF_EVENTS
82160 atomic_long_t locked_vm;
82161 #endif
82162 -};
82163 +} __randomize_layout;
82164
82165 extern int uids_sysfs_init(void);
82166
82167 @@ -1286,8 +1319,8 @@ struct task_struct {
82168 struct list_head thread_node;
82169
82170 struct completion *vfork_done; /* for vfork() */
82171 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82172 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82173 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82174 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82175
82176 cputime_t utime, stime, utimescaled, stimescaled;
82177 cputime_t gtime;
82178 @@ -1312,11 +1345,6 @@ struct task_struct {
82179 struct task_cputime cputime_expires;
82180 struct list_head cpu_timers[3];
82181
82182 -/* process credentials */
82183 - const struct cred __rcu *real_cred; /* objective and real subjective task
82184 - * credentials (COW) */
82185 - const struct cred __rcu *cred; /* effective (overridable) subjective task
82186 - * credentials (COW) */
82187 char comm[TASK_COMM_LEN]; /* executable name excluding path
82188 - access with [gs]et_task_comm (which lock
82189 it with task_lock())
82190 @@ -1333,6 +1361,10 @@ struct task_struct {
82191 #endif
82192 /* CPU-specific state of this task */
82193 struct thread_struct thread;
82194 +/* thread_info moved to task_struct */
82195 +#ifdef CONFIG_X86
82196 + struct thread_info tinfo;
82197 +#endif
82198 /* filesystem information */
82199 struct fs_struct *fs;
82200 /* open file information */
82201 @@ -1409,6 +1441,10 @@ struct task_struct {
82202 gfp_t lockdep_reclaim_gfp;
82203 #endif
82204
82205 +/* process credentials */
82206 + const struct cred __rcu *real_cred; /* objective and real subjective task
82207 + * credentials (COW) */
82208 +
82209 /* journalling filesystem info */
82210 void *journal_info;
82211
82212 @@ -1447,6 +1483,10 @@ struct task_struct {
82213 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82214 struct list_head cg_list;
82215 #endif
82216 +
82217 + const struct cred __rcu *cred; /* effective (overridable) subjective task
82218 + * credentials (COW) */
82219 +
82220 #ifdef CONFIG_FUTEX
82221 struct robust_list_head __user *robust_list;
82222 #ifdef CONFIG_COMPAT
82223 @@ -1581,7 +1621,78 @@ struct task_struct {
82224 unsigned int sequential_io;
82225 unsigned int sequential_io_avg;
82226 #endif
82227 -};
82228 +
82229 +#ifdef CONFIG_GRKERNSEC
82230 + /* grsecurity */
82231 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82232 + u64 exec_id;
82233 +#endif
82234 +#ifdef CONFIG_GRKERNSEC_SETXID
82235 + const struct cred *delayed_cred;
82236 +#endif
82237 + struct dentry *gr_chroot_dentry;
82238 + struct acl_subject_label *acl;
82239 + struct acl_subject_label *tmpacl;
82240 + struct acl_role_label *role;
82241 + struct file *exec_file;
82242 + unsigned long brute_expires;
82243 + u16 acl_role_id;
82244 + u8 inherited;
82245 + /* is this the task that authenticated to the special role */
82246 + u8 acl_sp_role;
82247 + u8 is_writable;
82248 + u8 brute;
82249 + u8 gr_is_chrooted;
82250 +#endif
82251 +
82252 +} __randomize_layout;
82253 +
82254 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82255 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82256 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82257 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82258 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82259 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82260 +
82261 +#ifdef CONFIG_PAX_SOFTMODE
82262 +extern int pax_softmode;
82263 +#endif
82264 +
82265 +extern int pax_check_flags(unsigned long *);
82266 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82267 +
82268 +/* if tsk != current then task_lock must be held on it */
82269 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82270 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
82271 +{
82272 + if (likely(tsk->mm))
82273 + return tsk->mm->pax_flags;
82274 + else
82275 + return 0UL;
82276 +}
82277 +
82278 +/* if tsk != current then task_lock must be held on it */
82279 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82280 +{
82281 + if (likely(tsk->mm)) {
82282 + tsk->mm->pax_flags = flags;
82283 + return 0;
82284 + }
82285 + return -EINVAL;
82286 +}
82287 +#endif
82288 +
82289 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82290 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
82291 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82292 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82293 +#endif
82294 +
82295 +struct path;
82296 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82297 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82298 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82299 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
82300
82301 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82302 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82303 @@ -1658,7 +1769,7 @@ struct pid_namespace;
82304 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82305 struct pid_namespace *ns);
82306
82307 -static inline pid_t task_pid_nr(struct task_struct *tsk)
82308 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
82309 {
82310 return tsk->pid;
82311 }
82312 @@ -2112,7 +2223,9 @@ void yield(void);
82313 extern struct exec_domain default_exec_domain;
82314
82315 union thread_union {
82316 +#ifndef CONFIG_X86
82317 struct thread_info thread_info;
82318 +#endif
82319 unsigned long stack[THREAD_SIZE/sizeof(long)];
82320 };
82321
82322 @@ -2145,6 +2258,7 @@ extern struct pid_namespace init_pid_ns;
82323 */
82324
82325 extern struct task_struct *find_task_by_vpid(pid_t nr);
82326 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82327 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82328 struct pid_namespace *ns);
82329
82330 @@ -2307,7 +2421,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82331 extern void exit_itimers(struct signal_struct *);
82332 extern void flush_itimer_signals(void);
82333
82334 -extern void do_group_exit(int);
82335 +extern __noreturn void do_group_exit(int);
82336
82337 extern int allow_signal(int);
82338 extern int disallow_signal(int);
82339 @@ -2508,9 +2622,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82340
82341 #endif
82342
82343 -static inline int object_is_on_stack(void *obj)
82344 +static inline int object_starts_on_stack(void *obj)
82345 {
82346 - void *stack = task_stack_page(current);
82347 + const void *stack = task_stack_page(current);
82348
82349 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82350 }
82351 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82352 index 8045a55..c959cd5 100644
82353 --- a/include/linux/sched/sysctl.h
82354 +++ b/include/linux/sched/sysctl.h
82355 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82356 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82357
82358 extern int sysctl_max_map_count;
82359 +extern unsigned long sysctl_heap_stack_gap;
82360
82361 extern unsigned int sysctl_sched_latency;
82362 extern unsigned int sysctl_sched_min_granularity;
82363 diff --git a/include/linux/security.h b/include/linux/security.h
82364 index 2fc42d1..4d802f2 100644
82365 --- a/include/linux/security.h
82366 +++ b/include/linux/security.h
82367 @@ -27,6 +27,7 @@
82368 #include <linux/slab.h>
82369 #include <linux/err.h>
82370 #include <linux/string.h>
82371 +#include <linux/grsecurity.h>
82372
82373 struct linux_binprm;
82374 struct cred;
82375 @@ -116,8 +117,6 @@ struct seq_file;
82376
82377 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82378
82379 -void reset_security_ops(void);
82380 -
82381 #ifdef CONFIG_MMU
82382 extern unsigned long mmap_min_addr;
82383 extern unsigned long dac_mmap_min_addr;
82384 @@ -1719,7 +1718,7 @@ struct security_operations {
82385 struct audit_context *actx);
82386 void (*audit_rule_free) (void *lsmrule);
82387 #endif /* CONFIG_AUDIT */
82388 -};
82389 +} __randomize_layout;
82390
82391 /* prototypes */
82392 extern int security_init(void);
82393 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82394 index dc368b8..e895209 100644
82395 --- a/include/linux/semaphore.h
82396 +++ b/include/linux/semaphore.h
82397 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82398 }
82399
82400 extern void down(struct semaphore *sem);
82401 -extern int __must_check down_interruptible(struct semaphore *sem);
82402 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82403 extern int __must_check down_killable(struct semaphore *sem);
82404 extern int __must_check down_trylock(struct semaphore *sem);
82405 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82406 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82407 index 52e0097..383f21d 100644
82408 --- a/include/linux/seq_file.h
82409 +++ b/include/linux/seq_file.h
82410 @@ -27,6 +27,9 @@ struct seq_file {
82411 struct mutex lock;
82412 const struct seq_operations *op;
82413 int poll_event;
82414 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82415 + u64 exec_id;
82416 +#endif
82417 #ifdef CONFIG_USER_NS
82418 struct user_namespace *user_ns;
82419 #endif
82420 @@ -39,6 +42,7 @@ struct seq_operations {
82421 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82422 int (*show) (struct seq_file *m, void *v);
82423 };
82424 +typedef struct seq_operations __no_const seq_operations_no_const;
82425
82426 #define SEQ_SKIP 1
82427
82428 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82429
82430 char *mangle_path(char *s, const char *p, const char *esc);
82431 int seq_open(struct file *, const struct seq_operations *);
82432 +int seq_open_restrict(struct file *, const struct seq_operations *);
82433 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82434 loff_t seq_lseek(struct file *, loff_t, int);
82435 int seq_release(struct inode *, struct file *);
82436 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82437 }
82438
82439 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82440 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82441 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82442 int single_release(struct inode *, struct file *);
82443 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82444 diff --git a/include/linux/shm.h b/include/linux/shm.h
82445 index 1e2cd2e..0288750 100644
82446 --- a/include/linux/shm.h
82447 +++ b/include/linux/shm.h
82448 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82449
82450 /* The task created the shm object. NULL if the task is dead. */
82451 struct task_struct *shm_creator;
82452 +#ifdef CONFIG_GRKERNSEC
82453 + time_t shm_createtime;
82454 + pid_t shm_lapid;
82455 +#endif
82456 };
82457
82458 /* shm_mode upper byte flags */
82459 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82460 index 15ede6a..80161c3 100644
82461 --- a/include/linux/skbuff.h
82462 +++ b/include/linux/skbuff.h
82463 @@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82464 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82465 int node);
82466 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82467 -static inline struct sk_buff *alloc_skb(unsigned int size,
82468 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82469 gfp_t priority)
82470 {
82471 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82472 @@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82473 return skb->inner_transport_header - skb->inner_network_header;
82474 }
82475
82476 -static inline int skb_network_offset(const struct sk_buff *skb)
82477 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82478 {
82479 return skb_network_header(skb) - skb->data;
82480 }
82481 @@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82482 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82483 */
82484 #ifndef NET_SKB_PAD
82485 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82486 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82487 #endif
82488
82489 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82490 @@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82491 int *err);
82492 unsigned int datagram_poll(struct file *file, struct socket *sock,
82493 struct poll_table_struct *wait);
82494 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82495 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82496 struct iovec *to, int size);
82497 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82498 struct iovec *iov);
82499 @@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
82500 nf_bridge_put(skb->nf_bridge);
82501 skb->nf_bridge = NULL;
82502 #endif
82503 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82504 + skb->nf_trace = 0;
82505 +#endif
82506 }
82507
82508 static inline void nf_reset_trace(struct sk_buff *skb)
82509 diff --git a/include/linux/slab.h b/include/linux/slab.h
82510 index b5b2df6..69f5734 100644
82511 --- a/include/linux/slab.h
82512 +++ b/include/linux/slab.h
82513 @@ -14,15 +14,29 @@
82514 #include <linux/gfp.h>
82515 #include <linux/types.h>
82516 #include <linux/workqueue.h>
82517 -
82518 +#include <linux/err.h>
82519
82520 /*
82521 * Flags to pass to kmem_cache_create().
82522 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82523 */
82524 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82525 +
82526 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82527 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82528 +#else
82529 +#define SLAB_USERCOPY 0x00000000UL
82530 +#endif
82531 +
82532 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82533 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82534 +
82535 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
82536 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82537 +#else
82538 +#define SLAB_NO_SANITIZE 0x00000000UL
82539 +#endif
82540 +
82541 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82542 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82543 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82544 @@ -98,10 +112,13 @@
82545 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82546 * Both make kfree a no-op.
82547 */
82548 -#define ZERO_SIZE_PTR ((void *)16)
82549 +#define ZERO_SIZE_PTR \
82550 +({ \
82551 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82552 + (void *)(-MAX_ERRNO-1L); \
82553 +})
82554
82555 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82556 - (unsigned long)ZERO_SIZE_PTR)
82557 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82558
82559 #include <linux/kmemleak.h>
82560
82561 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82562 void kfree(const void *);
82563 void kzfree(const void *);
82564 size_t ksize(const void *);
82565 +const char *check_heap_object(const void *ptr, unsigned long n);
82566 +bool is_usercopy_object(const void *ptr);
82567
82568 /*
82569 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82570 @@ -174,7 +193,7 @@ struct kmem_cache {
82571 unsigned int align; /* Alignment as calculated */
82572 unsigned long flags; /* Active flags on the slab */
82573 const char *name; /* Slab name for sysfs */
82574 - int refcount; /* Use counter */
82575 + atomic_t refcount; /* Use counter */
82576 void (*ctor)(void *); /* Called on object slot creation */
82577 struct list_head list; /* List of all slab caches on the system */
82578 };
82579 @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82580 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82581 #endif
82582
82583 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82584 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82585 +#endif
82586 +
82587 /*
82588 * Figure out which kmalloc slab an allocation of a certain size
82589 * belongs to.
82590 @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82591 * 2 = 120 .. 192 bytes
82592 * n = 2^(n-1) .. 2^n -1
82593 */
82594 -static __always_inline int kmalloc_index(size_t size)
82595 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82596 {
82597 if (!size)
82598 return 0;
82599 @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
82600 }
82601 #endif /* !CONFIG_SLOB */
82602
82603 -void *__kmalloc(size_t size, gfp_t flags);
82604 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82605 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82606
82607 #ifdef CONFIG_NUMA
82608 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
82609 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82610 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82611 #else
82612 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82613 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82614 index 8235dfb..47ce586 100644
82615 --- a/include/linux/slab_def.h
82616 +++ b/include/linux/slab_def.h
82617 @@ -38,7 +38,7 @@ struct kmem_cache {
82618 /* 4) cache creation/removal */
82619 const char *name;
82620 struct list_head list;
82621 - int refcount;
82622 + atomic_t refcount;
82623 int object_size;
82624 int align;
82625
82626 @@ -54,10 +54,14 @@ struct kmem_cache {
82627 unsigned long node_allocs;
82628 unsigned long node_frees;
82629 unsigned long node_overflow;
82630 - atomic_t allochit;
82631 - atomic_t allocmiss;
82632 - atomic_t freehit;
82633 - atomic_t freemiss;
82634 + atomic_unchecked_t allochit;
82635 + atomic_unchecked_t allocmiss;
82636 + atomic_unchecked_t freehit;
82637 + atomic_unchecked_t freemiss;
82638 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
82639 + atomic_unchecked_t sanitized;
82640 + atomic_unchecked_t not_sanitized;
82641 +#endif
82642
82643 /*
82644 * If debugging is enabled, then the allocator can add additional
82645 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82646 index f56bfa9..8378a26 100644
82647 --- a/include/linux/slub_def.h
82648 +++ b/include/linux/slub_def.h
82649 @@ -74,7 +74,7 @@ struct kmem_cache {
82650 struct kmem_cache_order_objects max;
82651 struct kmem_cache_order_objects min;
82652 gfp_t allocflags; /* gfp flags to use on each alloc */
82653 - int refcount; /* Refcount for slab cache destroy */
82654 + atomic_t refcount; /* Refcount for slab cache destroy */
82655 void (*ctor)(void *);
82656 int inuse; /* Offset to metadata */
82657 int align; /* Alignment */
82658 diff --git a/include/linux/smp.h b/include/linux/smp.h
82659 index 6ae004e..2743532 100644
82660 --- a/include/linux/smp.h
82661 +++ b/include/linux/smp.h
82662 @@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
82663 #endif
82664
82665 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82666 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82667 #define put_cpu() preempt_enable()
82668 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82669
82670 /*
82671 * Callback to arch code if there's nosmp or maxcpus=0 on the
82672 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82673 index 54f91d3..be2c379 100644
82674 --- a/include/linux/sock_diag.h
82675 +++ b/include/linux/sock_diag.h
82676 @@ -11,7 +11,7 @@ struct sock;
82677 struct sock_diag_handler {
82678 __u8 family;
82679 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82680 -};
82681 +} __do_const;
82682
82683 int sock_diag_register(const struct sock_diag_handler *h);
82684 void sock_diag_unregister(const struct sock_diag_handler *h);
82685 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82686 index 680f9a3..f13aeb0 100644
82687 --- a/include/linux/sonet.h
82688 +++ b/include/linux/sonet.h
82689 @@ -7,7 +7,7 @@
82690 #include <uapi/linux/sonet.h>
82691
82692 struct k_sonet_stats {
82693 -#define __HANDLE_ITEM(i) atomic_t i
82694 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
82695 __SONET_ITEMS
82696 #undef __HANDLE_ITEM
82697 };
82698 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82699 index 07d8e53..dc934c9 100644
82700 --- a/include/linux/sunrpc/addr.h
82701 +++ b/include/linux/sunrpc/addr.h
82702 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82703 {
82704 switch (sap->sa_family) {
82705 case AF_INET:
82706 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
82707 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82708 case AF_INET6:
82709 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82710 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82711 }
82712 return 0;
82713 }
82714 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82715 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82716 const struct sockaddr *src)
82717 {
82718 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82719 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82720 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82721
82722 dsin->sin_family = ssin->sin_family;
82723 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82724 if (sa->sa_family != AF_INET6)
82725 return 0;
82726
82727 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82728 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82729 }
82730
82731 #endif /* _LINUX_SUNRPC_ADDR_H */
82732 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82733 index 8af2804..c7414ef 100644
82734 --- a/include/linux/sunrpc/clnt.h
82735 +++ b/include/linux/sunrpc/clnt.h
82736 @@ -97,7 +97,7 @@ struct rpc_procinfo {
82737 unsigned int p_timer; /* Which RTT timer to use */
82738 u32 p_statidx; /* Which procedure to account */
82739 const char * p_name; /* name of procedure */
82740 -};
82741 +} __do_const;
82742
82743 #ifdef __KERNEL__
82744
82745 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82746 index 04e7632..2e2a8a3 100644
82747 --- a/include/linux/sunrpc/svc.h
82748 +++ b/include/linux/sunrpc/svc.h
82749 @@ -412,7 +412,7 @@ struct svc_procedure {
82750 unsigned int pc_count; /* call count */
82751 unsigned int pc_cachetype; /* cache info (NFS) */
82752 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82753 -};
82754 +} __do_const;
82755
82756 /*
82757 * Function prototypes.
82758 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82759 index 0b8e3e6..33e0a01 100644
82760 --- a/include/linux/sunrpc/svc_rdma.h
82761 +++ b/include/linux/sunrpc/svc_rdma.h
82762 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82763 extern unsigned int svcrdma_max_requests;
82764 extern unsigned int svcrdma_max_req_size;
82765
82766 -extern atomic_t rdma_stat_recv;
82767 -extern atomic_t rdma_stat_read;
82768 -extern atomic_t rdma_stat_write;
82769 -extern atomic_t rdma_stat_sq_starve;
82770 -extern atomic_t rdma_stat_rq_starve;
82771 -extern atomic_t rdma_stat_rq_poll;
82772 -extern atomic_t rdma_stat_rq_prod;
82773 -extern atomic_t rdma_stat_sq_poll;
82774 -extern atomic_t rdma_stat_sq_prod;
82775 +extern atomic_unchecked_t rdma_stat_recv;
82776 +extern atomic_unchecked_t rdma_stat_read;
82777 +extern atomic_unchecked_t rdma_stat_write;
82778 +extern atomic_unchecked_t rdma_stat_sq_starve;
82779 +extern atomic_unchecked_t rdma_stat_rq_starve;
82780 +extern atomic_unchecked_t rdma_stat_rq_poll;
82781 +extern atomic_unchecked_t rdma_stat_rq_prod;
82782 +extern atomic_unchecked_t rdma_stat_sq_poll;
82783 +extern atomic_unchecked_t rdma_stat_sq_prod;
82784
82785 #define RPCRDMA_VERSION 1
82786
82787 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82788 index 8d71d65..f79586e 100644
82789 --- a/include/linux/sunrpc/svcauth.h
82790 +++ b/include/linux/sunrpc/svcauth.h
82791 @@ -120,7 +120,7 @@ struct auth_ops {
82792 int (*release)(struct svc_rqst *rq);
82793 void (*domain_release)(struct auth_domain *);
82794 int (*set_client)(struct svc_rqst *rq);
82795 -};
82796 +} __do_const;
82797
82798 #define SVC_GARBAGE 1
82799 #define SVC_SYSERR 2
82800 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82801 index a5ffd32..0935dea 100644
82802 --- a/include/linux/swiotlb.h
82803 +++ b/include/linux/swiotlb.h
82804 @@ -60,7 +60,8 @@ extern void
82805
82806 extern void
82807 swiotlb_free_coherent(struct device *hwdev, size_t size,
82808 - void *vaddr, dma_addr_t dma_handle);
82809 + void *vaddr, dma_addr_t dma_handle,
82810 + struct dma_attrs *attrs);
82811
82812 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82813 unsigned long offset, size_t size,
82814 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82815 index a747a77..9e14df7 100644
82816 --- a/include/linux/syscalls.h
82817 +++ b/include/linux/syscalls.h
82818 @@ -98,8 +98,14 @@ struct sigaltstack;
82819 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82820
82821 #define __SC_DECL(t, a) t a
82822 +#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))
82823 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82824 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82825 +#define __SC_LONG(t, a) __typeof( \
82826 + __builtin_choose_expr( \
82827 + sizeof(t) > sizeof(int), \
82828 + (t) 0, \
82829 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82830 + )) a
82831 #define __SC_CAST(t, a) (t) a
82832 #define __SC_ARGS(t, a) a
82833 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82834 @@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
82835 asmlinkage long sys_fsync(unsigned int fd);
82836 asmlinkage long sys_fdatasync(unsigned int fd);
82837 asmlinkage long sys_bdflush(int func, long data);
82838 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82839 - char __user *type, unsigned long flags,
82840 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82841 + const char __user *type, unsigned long flags,
82842 void __user *data);
82843 -asmlinkage long sys_umount(char __user *name, int flags);
82844 -asmlinkage long sys_oldumount(char __user *name);
82845 +asmlinkage long sys_umount(const char __user *name, int flags);
82846 +asmlinkage long sys_oldumount(const char __user *name);
82847 asmlinkage long sys_truncate(const char __user *path, long length);
82848 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82849 asmlinkage long sys_stat(const char __user *filename,
82850 @@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82851 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82852 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82853 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82854 - struct sockaddr __user *, int);
82855 + struct sockaddr __user *, int) __intentional_overflow(0);
82856 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82857 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82858 unsigned int vlen, unsigned flags);
82859 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82860 index 27b3b0b..e093dd9 100644
82861 --- a/include/linux/syscore_ops.h
82862 +++ b/include/linux/syscore_ops.h
82863 @@ -16,7 +16,7 @@ struct syscore_ops {
82864 int (*suspend)(void);
82865 void (*resume)(void);
82866 void (*shutdown)(void);
82867 -};
82868 +} __do_const;
82869
82870 extern void register_syscore_ops(struct syscore_ops *ops);
82871 extern void unregister_syscore_ops(struct syscore_ops *ops);
82872 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82873 index 14a8ff2..fa95f3a 100644
82874 --- a/include/linux/sysctl.h
82875 +++ b/include/linux/sysctl.h
82876 @@ -34,13 +34,13 @@ struct ctl_table_root;
82877 struct ctl_table_header;
82878 struct ctl_dir;
82879
82880 -typedef struct ctl_table ctl_table;
82881 -
82882 typedef int proc_handler (struct ctl_table *ctl, int write,
82883 void __user *buffer, size_t *lenp, loff_t *ppos);
82884
82885 extern int proc_dostring(struct ctl_table *, int,
82886 void __user *, size_t *, loff_t *);
82887 +extern int proc_dostring_modpriv(struct ctl_table *, int,
82888 + void __user *, size_t *, loff_t *);
82889 extern int proc_dointvec(struct ctl_table *, int,
82890 void __user *, size_t *, loff_t *);
82891 extern int proc_dointvec_minmax(struct ctl_table *, int,
82892 @@ -115,7 +115,9 @@ struct ctl_table
82893 struct ctl_table_poll *poll;
82894 void *extra1;
82895 void *extra2;
82896 -};
82897 +} __do_const __randomize_layout;
82898 +typedef struct ctl_table __no_const ctl_table_no_const;
82899 +typedef struct ctl_table ctl_table;
82900
82901 struct ctl_node {
82902 struct rb_node node;
82903 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82904 index 30b2ebe..37412ef 100644
82905 --- a/include/linux/sysfs.h
82906 +++ b/include/linux/sysfs.h
82907 @@ -34,7 +34,8 @@ struct attribute {
82908 struct lock_class_key *key;
82909 struct lock_class_key skey;
82910 #endif
82911 -};
82912 +} __do_const;
82913 +typedef struct attribute __no_const attribute_no_const;
82914
82915 /**
82916 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82917 @@ -63,7 +64,8 @@ struct attribute_group {
82918 struct attribute *, int);
82919 struct attribute **attrs;
82920 struct bin_attribute **bin_attrs;
82921 -};
82922 +} __do_const;
82923 +typedef struct attribute_group __no_const attribute_group_no_const;
82924
82925 /**
82926 * Use these macros to make defining attributes easier. See include/linux/device.h
82927 @@ -127,7 +129,8 @@ struct bin_attribute {
82928 char *, loff_t, size_t);
82929 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82930 struct vm_area_struct *vma);
82931 -};
82932 +} __do_const;
82933 +typedef struct bin_attribute __no_const bin_attribute_no_const;
82934
82935 /**
82936 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82937 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82938 index 387fa7d..3fcde6b 100644
82939 --- a/include/linux/sysrq.h
82940 +++ b/include/linux/sysrq.h
82941 @@ -16,6 +16,7 @@
82942
82943 #include <linux/errno.h>
82944 #include <linux/types.h>
82945 +#include <linux/compiler.h>
82946
82947 /* Possible values of bitmask for enabling sysrq functions */
82948 /* 0x0001 is reserved for enable everything */
82949 @@ -33,7 +34,7 @@ struct sysrq_key_op {
82950 char *help_msg;
82951 char *action_msg;
82952 int enable_mask;
82953 -};
82954 +} __do_const;
82955
82956 #ifdef CONFIG_MAGIC_SYSRQ
82957
82958 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82959 index fddbe20..e4cce53 100644
82960 --- a/include/linux/thread_info.h
82961 +++ b/include/linux/thread_info.h
82962 @@ -161,6 +161,25 @@ static inline bool test_and_clear_restore_sigmask(void)
82963 #error "no set_restore_sigmask() provided and default one won't work"
82964 #endif
82965
82966 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82967 +
82968 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
82969 +extern void pax_check_alloca(unsigned long size);
82970 +#endif
82971 +
82972 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82973 +{
82974 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
82975 + /* always check if we've overflowed the stack in a copy*user */
82976 + pax_check_alloca(sizeof(unsigned long));
82977 +#endif
82978 +
82979 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
82980 + if (!__builtin_constant_p(n))
82981 +#endif
82982 + __check_object_size(ptr, n, to_user);
82983 +}
82984 +
82985 #endif /* __KERNEL__ */
82986
82987 #endif /* _LINUX_THREAD_INFO_H */
82988 diff --git a/include/linux/tty.h b/include/linux/tty.h
82989 index b90b5c2..e23a512 100644
82990 --- a/include/linux/tty.h
82991 +++ b/include/linux/tty.h
82992 @@ -202,7 +202,7 @@ struct tty_port {
82993 const struct tty_port_operations *ops; /* Port operations */
82994 spinlock_t lock; /* Lock protecting tty field */
82995 int blocked_open; /* Waiting to open */
82996 - int count; /* Usage count */
82997 + atomic_t count; /* Usage count */
82998 wait_queue_head_t open_wait; /* Open waiters */
82999 wait_queue_head_t close_wait; /* Close waiters */
83000 wait_queue_head_t delta_msr_wait; /* Modem status change */
83001 @@ -284,7 +284,7 @@ struct tty_struct {
83002 /* If the tty has a pending do_SAK, queue it here - akpm */
83003 struct work_struct SAK_work;
83004 struct tty_port *port;
83005 -};
83006 +} __randomize_layout;
83007
83008 /* Each of a tty's open files has private_data pointing to tty_file_private */
83009 struct tty_file_private {
83010 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
83011 struct tty_struct *tty, struct file *filp);
83012 static inline int tty_port_users(struct tty_port *port)
83013 {
83014 - return port->count + port->blocked_open;
83015 + return atomic_read(&port->count) + port->blocked_open;
83016 }
83017
83018 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
83019 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
83020 index 756a609..89db85e 100644
83021 --- a/include/linux/tty_driver.h
83022 +++ b/include/linux/tty_driver.h
83023 @@ -285,7 +285,7 @@ struct tty_operations {
83024 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
83025 #endif
83026 const struct file_operations *proc_fops;
83027 -};
83028 +} __do_const __randomize_layout;
83029
83030 struct tty_driver {
83031 int magic; /* magic number for this structure */
83032 @@ -319,7 +319,7 @@ struct tty_driver {
83033
83034 const struct tty_operations *ops;
83035 struct list_head tty_drivers;
83036 -};
83037 +} __randomize_layout;
83038
83039 extern struct list_head tty_drivers;
83040
83041 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
83042 index b8347c2..85d8b0f 100644
83043 --- a/include/linux/tty_ldisc.h
83044 +++ b/include/linux/tty_ldisc.h
83045 @@ -213,7 +213,7 @@ struct tty_ldisc_ops {
83046
83047 struct module *owner;
83048
83049 - int refcount;
83050 + atomic_t refcount;
83051 };
83052
83053 struct tty_ldisc {
83054 diff --git a/include/linux/types.h b/include/linux/types.h
83055 index 4d118ba..c3ee9bf 100644
83056 --- a/include/linux/types.h
83057 +++ b/include/linux/types.h
83058 @@ -176,10 +176,26 @@ typedef struct {
83059 int counter;
83060 } atomic_t;
83061
83062 +#ifdef CONFIG_PAX_REFCOUNT
83063 +typedef struct {
83064 + int counter;
83065 +} atomic_unchecked_t;
83066 +#else
83067 +typedef atomic_t atomic_unchecked_t;
83068 +#endif
83069 +
83070 #ifdef CONFIG_64BIT
83071 typedef struct {
83072 long counter;
83073 } atomic64_t;
83074 +
83075 +#ifdef CONFIG_PAX_REFCOUNT
83076 +typedef struct {
83077 + long counter;
83078 +} atomic64_unchecked_t;
83079 +#else
83080 +typedef atomic64_t atomic64_unchecked_t;
83081 +#endif
83082 #endif
83083
83084 struct list_head {
83085 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83086 index ecd3319..8a36ded 100644
83087 --- a/include/linux/uaccess.h
83088 +++ b/include/linux/uaccess.h
83089 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83090 long ret; \
83091 mm_segment_t old_fs = get_fs(); \
83092 \
83093 - set_fs(KERNEL_DS); \
83094 pagefault_disable(); \
83095 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83096 - pagefault_enable(); \
83097 + set_fs(KERNEL_DS); \
83098 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83099 set_fs(old_fs); \
83100 + pagefault_enable(); \
83101 ret; \
83102 })
83103
83104 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83105 index 2d1f9b6..d7a9fce 100644
83106 --- a/include/linux/uidgid.h
83107 +++ b/include/linux/uidgid.h
83108 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83109
83110 #endif /* CONFIG_USER_NS */
83111
83112 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83113 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83114 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83115 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83116 +
83117 #endif /* _LINUX_UIDGID_H */
83118 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83119 index 99c1b4d..562e6f3 100644
83120 --- a/include/linux/unaligned/access_ok.h
83121 +++ b/include/linux/unaligned/access_ok.h
83122 @@ -4,34 +4,34 @@
83123 #include <linux/kernel.h>
83124 #include <asm/byteorder.h>
83125
83126 -static inline u16 get_unaligned_le16(const void *p)
83127 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83128 {
83129 - return le16_to_cpup((__le16 *)p);
83130 + return le16_to_cpup((const __le16 *)p);
83131 }
83132
83133 -static inline u32 get_unaligned_le32(const void *p)
83134 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83135 {
83136 - return le32_to_cpup((__le32 *)p);
83137 + return le32_to_cpup((const __le32 *)p);
83138 }
83139
83140 -static inline u64 get_unaligned_le64(const void *p)
83141 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83142 {
83143 - return le64_to_cpup((__le64 *)p);
83144 + return le64_to_cpup((const __le64 *)p);
83145 }
83146
83147 -static inline u16 get_unaligned_be16(const void *p)
83148 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83149 {
83150 - return be16_to_cpup((__be16 *)p);
83151 + return be16_to_cpup((const __be16 *)p);
83152 }
83153
83154 -static inline u32 get_unaligned_be32(const void *p)
83155 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83156 {
83157 - return be32_to_cpup((__be32 *)p);
83158 + return be32_to_cpup((const __be32 *)p);
83159 }
83160
83161 -static inline u64 get_unaligned_be64(const void *p)
83162 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83163 {
83164 - return be64_to_cpup((__be64 *)p);
83165 + return be64_to_cpup((const __be64 *)p);
83166 }
83167
83168 static inline void put_unaligned_le16(u16 val, void *p)
83169 diff --git a/include/linux/usb.h b/include/linux/usb.h
83170 index 7f6eb85..656e806 100644
83171 --- a/include/linux/usb.h
83172 +++ b/include/linux/usb.h
83173 @@ -563,7 +563,7 @@ struct usb_device {
83174 int maxchild;
83175
83176 u32 quirks;
83177 - atomic_t urbnum;
83178 + atomic_unchecked_t urbnum;
83179
83180 unsigned long active_duration;
83181
83182 @@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83183
83184 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83185 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83186 - void *data, __u16 size, int timeout);
83187 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
83188 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83189 void *data, int len, int *actual_length, int timeout);
83190 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83191 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83192 index e452ba6..78f8e80 100644
83193 --- a/include/linux/usb/renesas_usbhs.h
83194 +++ b/include/linux/usb/renesas_usbhs.h
83195 @@ -39,7 +39,7 @@ enum {
83196 */
83197 struct renesas_usbhs_driver_callback {
83198 int (*notify_hotplug)(struct platform_device *pdev);
83199 -};
83200 +} __no_const;
83201
83202 /*
83203 * callback functions for platform
83204 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83205 index 4836ba3..603f6ee 100644
83206 --- a/include/linux/user_namespace.h
83207 +++ b/include/linux/user_namespace.h
83208 @@ -33,7 +33,7 @@ struct user_namespace {
83209 struct key *persistent_keyring_register;
83210 struct rw_semaphore persistent_keyring_register_sem;
83211 #endif
83212 -};
83213 +} __randomize_layout;
83214
83215 extern struct user_namespace init_user_ns;
83216
83217 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83218 index 239e277..22a5cf5 100644
83219 --- a/include/linux/utsname.h
83220 +++ b/include/linux/utsname.h
83221 @@ -24,7 +24,7 @@ struct uts_namespace {
83222 struct new_utsname name;
83223 struct user_namespace *user_ns;
83224 unsigned int proc_inum;
83225 -};
83226 +} __randomize_layout;
83227 extern struct uts_namespace init_uts_ns;
83228
83229 #ifdef CONFIG_UTS_NS
83230 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83231 index 6f8fbcf..4efc177 100644
83232 --- a/include/linux/vermagic.h
83233 +++ b/include/linux/vermagic.h
83234 @@ -25,9 +25,42 @@
83235 #define MODULE_ARCH_VERMAGIC ""
83236 #endif
83237
83238 +#ifdef CONFIG_PAX_REFCOUNT
83239 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
83240 +#else
83241 +#define MODULE_PAX_REFCOUNT ""
83242 +#endif
83243 +
83244 +#ifdef CONSTIFY_PLUGIN
83245 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83246 +#else
83247 +#define MODULE_CONSTIFY_PLUGIN ""
83248 +#endif
83249 +
83250 +#ifdef STACKLEAK_PLUGIN
83251 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83252 +#else
83253 +#define MODULE_STACKLEAK_PLUGIN ""
83254 +#endif
83255 +
83256 +#ifdef RANDSTRUCT_PLUGIN
83257 +#include <generated/randomize_layout_hash.h>
83258 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83259 +#else
83260 +#define MODULE_RANDSTRUCT_PLUGIN
83261 +#endif
83262 +
83263 +#ifdef CONFIG_GRKERNSEC
83264 +#define MODULE_GRSEC "GRSEC "
83265 +#else
83266 +#define MODULE_GRSEC ""
83267 +#endif
83268 +
83269 #define VERMAGIC_STRING \
83270 UTS_RELEASE " " \
83271 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83272 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83273 - MODULE_ARCH_VERMAGIC
83274 + MODULE_ARCH_VERMAGIC \
83275 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83276 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83277
83278 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83279 index 502073a..a7de024 100644
83280 --- a/include/linux/vga_switcheroo.h
83281 +++ b/include/linux/vga_switcheroo.h
83282 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83283
83284 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83285
83286 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83287 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83288 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83289 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83290 #else
83291
83292 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83293 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83294
83295 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83296
83297 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83298 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83299 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83300 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83301
83302 #endif
83303 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83304 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83305 index 4b8a891..cb8df6e 100644
83306 --- a/include/linux/vmalloc.h
83307 +++ b/include/linux/vmalloc.h
83308 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83309 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83310 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83311 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83312 +
83313 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83314 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83315 +#endif
83316 +
83317 /* bits [20..32] reserved for arch specific ioremap internals */
83318
83319 /*
83320 @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
83321
83322 /* for /dev/kmem */
83323 extern long vread(char *buf, char *addr, unsigned long count);
83324 -extern long vwrite(char *buf, char *addr, unsigned long count);
83325 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83326
83327 /*
83328 * Internals. Dont't use..
83329 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83330 index 67ce70c..d540954 100644
83331 --- a/include/linux/vmstat.h
83332 +++ b/include/linux/vmstat.h
83333 @@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
83334 /*
83335 * Zone based page accounting with per cpu differentials.
83336 */
83337 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83338 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83339
83340 static inline void zone_page_state_add(long x, struct zone *zone,
83341 enum zone_stat_item item)
83342 {
83343 - atomic_long_add(x, &zone->vm_stat[item]);
83344 - atomic_long_add(x, &vm_stat[item]);
83345 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83346 + atomic_long_add_unchecked(x, &vm_stat[item]);
83347 }
83348
83349 -static inline unsigned long global_page_state(enum zone_stat_item item)
83350 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83351 {
83352 - long x = atomic_long_read(&vm_stat[item]);
83353 + long x = atomic_long_read_unchecked(&vm_stat[item]);
83354 #ifdef CONFIG_SMP
83355 if (x < 0)
83356 x = 0;
83357 @@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83358 return x;
83359 }
83360
83361 -static inline unsigned long zone_page_state(struct zone *zone,
83362 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83363 enum zone_stat_item item)
83364 {
83365 - long x = atomic_long_read(&zone->vm_stat[item]);
83366 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83367 #ifdef CONFIG_SMP
83368 if (x < 0)
83369 x = 0;
83370 @@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83371 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83372 enum zone_stat_item item)
83373 {
83374 - long x = atomic_long_read(&zone->vm_stat[item]);
83375 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83376
83377 #ifdef CONFIG_SMP
83378 int cpu;
83379 @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
83380
83381 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83382 {
83383 - atomic_long_inc(&zone->vm_stat[item]);
83384 - atomic_long_inc(&vm_stat[item]);
83385 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
83386 + atomic_long_inc_unchecked(&vm_stat[item]);
83387 }
83388
83389 static inline void __inc_zone_page_state(struct page *page,
83390 @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
83391
83392 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83393 {
83394 - atomic_long_dec(&zone->vm_stat[item]);
83395 - atomic_long_dec(&vm_stat[item]);
83396 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
83397 + atomic_long_dec_unchecked(&vm_stat[item]);
83398 }
83399
83400 static inline void __dec_zone_page_state(struct page *page,
83401 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83402 index 91b0a68..0e9adf6 100644
83403 --- a/include/linux/xattr.h
83404 +++ b/include/linux/xattr.h
83405 @@ -28,7 +28,7 @@ struct xattr_handler {
83406 size_t size, int handler_flags);
83407 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83408 size_t size, int flags, int handler_flags);
83409 -};
83410 +} __do_const;
83411
83412 struct xattr {
83413 const char *name;
83414 @@ -37,6 +37,9 @@ struct xattr {
83415 };
83416
83417 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83418 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83419 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
83420 +#endif
83421 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83422 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83423 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83424 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83425 index 9c5a6b4..09c9438 100644
83426 --- a/include/linux/zlib.h
83427 +++ b/include/linux/zlib.h
83428 @@ -31,6 +31,7 @@
83429 #define _ZLIB_H
83430
83431 #include <linux/zconf.h>
83432 +#include <linux/compiler.h>
83433
83434 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83435 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83436 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83437
83438 /* basic functions */
83439
83440 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83441 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83442 /*
83443 Returns the number of bytes that needs to be allocated for a per-
83444 stream workspace with the specified parameters. A pointer to this
83445 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83446 index c768c9f..bdcaa5a 100644
83447 --- a/include/media/v4l2-dev.h
83448 +++ b/include/media/v4l2-dev.h
83449 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
83450 int (*mmap) (struct file *, struct vm_area_struct *);
83451 int (*open) (struct file *);
83452 int (*release) (struct file *);
83453 -};
83454 +} __do_const;
83455
83456 /*
83457 * Newer version of video_device, handled by videodev2.c
83458 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83459 index c9b1593..a572459 100644
83460 --- a/include/media/v4l2-device.h
83461 +++ b/include/media/v4l2-device.h
83462 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83463 this function returns 0. If the name ends with a digit (e.g. cx18),
83464 then the name will be set to cx18-0 since cx180 looks really odd. */
83465 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83466 - atomic_t *instance);
83467 + atomic_unchecked_t *instance);
83468
83469 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83470 Since the parent disappears this ensures that v4l2_dev doesn't have an
83471 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83472 index 9a36d92..0aafe2a 100644
83473 --- a/include/net/9p/transport.h
83474 +++ b/include/net/9p/transport.h
83475 @@ -60,7 +60,7 @@ struct p9_trans_module {
83476 int (*cancel) (struct p9_client *, struct p9_req_t *req);
83477 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83478 char *, char *, int , int, int, int);
83479 -};
83480 +} __do_const;
83481
83482 void v9fs_register_trans(struct p9_trans_module *m);
83483 void v9fs_unregister_trans(struct p9_trans_module *m);
83484 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83485 index a175ba4..196eb82 100644
83486 --- a/include/net/af_unix.h
83487 +++ b/include/net/af_unix.h
83488 @@ -36,7 +36,7 @@ struct unix_skb_parms {
83489 u32 secid; /* Security ID */
83490 #endif
83491 u32 consumed;
83492 -};
83493 +} __randomize_layout;
83494
83495 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83496 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83497 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83498 index dbc4a89..4a59b5d 100644
83499 --- a/include/net/bluetooth/l2cap.h
83500 +++ b/include/net/bluetooth/l2cap.h
83501 @@ -600,7 +600,7 @@ struct l2cap_ops {
83502 long (*get_sndtimeo) (struct l2cap_chan *chan);
83503 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83504 unsigned long len, int nb);
83505 -};
83506 +} __do_const;
83507
83508 struct l2cap_conn {
83509 struct hci_conn *hcon;
83510 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83511 index f2ae33d..c457cf0 100644
83512 --- a/include/net/caif/cfctrl.h
83513 +++ b/include/net/caif/cfctrl.h
83514 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
83515 void (*radioset_rsp)(void);
83516 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83517 struct cflayer *client_layer);
83518 -};
83519 +} __no_const;
83520
83521 /* Link Setup Parameters for CAIF-Links. */
83522 struct cfctrl_link_param {
83523 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
83524 struct cfctrl {
83525 struct cfsrvl serv;
83526 struct cfctrl_rsp res;
83527 - atomic_t req_seq_no;
83528 - atomic_t rsp_seq_no;
83529 + atomic_unchecked_t req_seq_no;
83530 + atomic_unchecked_t rsp_seq_no;
83531 struct list_head list;
83532 /* Protects from simultaneous access to first_req list */
83533 spinlock_t info_list_lock;
83534 diff --git a/include/net/flow.h b/include/net/flow.h
83535 index d23e7fa..e188307 100644
83536 --- a/include/net/flow.h
83537 +++ b/include/net/flow.h
83538 @@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
83539
83540 void flow_cache_flush(void);
83541 void flow_cache_flush_deferred(void);
83542 -extern atomic_t flow_cache_genid;
83543 +extern atomic_unchecked_t flow_cache_genid;
83544
83545 #endif
83546 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83547 index 93695f0..766d71c 100644
83548 --- a/include/net/genetlink.h
83549 +++ b/include/net/genetlink.h
83550 @@ -120,7 +120,7 @@ struct genl_ops {
83551 u8 cmd;
83552 u8 internal_flags;
83553 u8 flags;
83554 -};
83555 +} __do_const;
83556
83557 int __genl_register_family(struct genl_family *family);
83558
83559 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83560 index 734d9b5..48a9a4b 100644
83561 --- a/include/net/gro_cells.h
83562 +++ b/include/net/gro_cells.h
83563 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83564 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83565
83566 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83567 - atomic_long_inc(&dev->rx_dropped);
83568 + atomic_long_inc_unchecked(&dev->rx_dropped);
83569 kfree_skb(skb);
83570 return;
83571 }
83572 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83573 index c55aeed..b3393f4 100644
83574 --- a/include/net/inet_connection_sock.h
83575 +++ b/include/net/inet_connection_sock.h
83576 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83577 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83578 int (*bind_conflict)(const struct sock *sk,
83579 const struct inet_bind_bucket *tb, bool relax);
83580 -};
83581 +} __do_const;
83582
83583 /** inet_connection_sock - INET connection oriented sock
83584 *
83585 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83586 index 6efe73c..fa94270 100644
83587 --- a/include/net/inetpeer.h
83588 +++ b/include/net/inetpeer.h
83589 @@ -47,8 +47,8 @@ struct inet_peer {
83590 */
83591 union {
83592 struct {
83593 - atomic_t rid; /* Frag reception counter */
83594 - atomic_t ip_id_count; /* IP ID for the next packet */
83595 + atomic_unchecked_t rid; /* Frag reception counter */
83596 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83597 };
83598 struct rcu_head rcu;
83599 struct inet_peer *gc_next;
83600 @@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
83601 /* can be called with or without local BH being disabled */
83602 static inline int inet_getid(struct inet_peer *p, int more)
83603 {
83604 - int old, new;
83605 + int id;
83606 more++;
83607 inet_peer_refcheck(p);
83608 - do {
83609 - old = atomic_read(&p->ip_id_count);
83610 - new = old + more;
83611 - if (!new)
83612 - new = 1;
83613 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
83614 - return new;
83615 + id = atomic_add_return_unchecked(more, &p->ip_id_count);
83616 + if (!id)
83617 + id = atomic_inc_return_unchecked(&p->ip_id_count);
83618 + return id;
83619 }
83620
83621 #endif /* _NET_INETPEER_H */
83622 diff --git a/include/net/ip.h b/include/net/ip.h
83623 index 23be0fd..0cb3e2c 100644
83624 --- a/include/net/ip.h
83625 +++ b/include/net/ip.h
83626 @@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83627
83628 void inet_get_local_port_range(struct net *net, int *low, int *high);
83629
83630 -extern unsigned long *sysctl_local_reserved_ports;
83631 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83632 static inline int inet_is_reserved_local_port(int port)
83633 {
83634 return test_bit(port, sysctl_local_reserved_ports);
83635 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83636 index 9922093..a1755d6 100644
83637 --- a/include/net/ip_fib.h
83638 +++ b/include/net/ip_fib.h
83639 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83640
83641 #define FIB_RES_SADDR(net, res) \
83642 ((FIB_RES_NH(res).nh_saddr_genid == \
83643 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83644 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83645 FIB_RES_NH(res).nh_saddr : \
83646 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83647 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83648 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83649 index 5679d92..2e7a690 100644
83650 --- a/include/net/ip_vs.h
83651 +++ b/include/net/ip_vs.h
83652 @@ -558,7 +558,7 @@ struct ip_vs_conn {
83653 struct ip_vs_conn *control; /* Master control connection */
83654 atomic_t n_control; /* Number of controlled ones */
83655 struct ip_vs_dest *dest; /* real server */
83656 - atomic_t in_pkts; /* incoming packet counter */
83657 + atomic_unchecked_t in_pkts; /* incoming packet counter */
83658
83659 /* packet transmitter for different forwarding methods. If it
83660 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83661 @@ -705,7 +705,7 @@ struct ip_vs_dest {
83662 __be16 port; /* port number of the server */
83663 union nf_inet_addr addr; /* IP address of the server */
83664 volatile unsigned int flags; /* dest status flags */
83665 - atomic_t conn_flags; /* flags to copy to conn */
83666 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
83667 atomic_t weight; /* server weight */
83668
83669 atomic_t refcnt; /* reference counter */
83670 @@ -960,11 +960,11 @@ struct netns_ipvs {
83671 /* ip_vs_lblc */
83672 int sysctl_lblc_expiration;
83673 struct ctl_table_header *lblc_ctl_header;
83674 - struct ctl_table *lblc_ctl_table;
83675 + ctl_table_no_const *lblc_ctl_table;
83676 /* ip_vs_lblcr */
83677 int sysctl_lblcr_expiration;
83678 struct ctl_table_header *lblcr_ctl_header;
83679 - struct ctl_table *lblcr_ctl_table;
83680 + ctl_table_no_const *lblcr_ctl_table;
83681 /* ip_vs_est */
83682 struct list_head est_list; /* estimator list */
83683 spinlock_t est_lock;
83684 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83685 index 8d4f588..2e37ad2 100644
83686 --- a/include/net/irda/ircomm_tty.h
83687 +++ b/include/net/irda/ircomm_tty.h
83688 @@ -33,6 +33,7 @@
83689 #include <linux/termios.h>
83690 #include <linux/timer.h>
83691 #include <linux/tty.h> /* struct tty_struct */
83692 +#include <asm/local.h>
83693
83694 #include <net/irda/irias_object.h>
83695 #include <net/irda/ircomm_core.h>
83696 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83697 index 714cc9a..ea05f3e 100644
83698 --- a/include/net/iucv/af_iucv.h
83699 +++ b/include/net/iucv/af_iucv.h
83700 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
83701 struct iucv_sock_list {
83702 struct hlist_head head;
83703 rwlock_t lock;
83704 - atomic_t autobind_name;
83705 + atomic_unchecked_t autobind_name;
83706 };
83707
83708 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83709 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83710 index f3be818..bf46196 100644
83711 --- a/include/net/llc_c_ac.h
83712 +++ b/include/net/llc_c_ac.h
83713 @@ -87,7 +87,7 @@
83714 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83715 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83716
83717 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83718 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83719
83720 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83721 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83722 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83723 index 3948cf1..83b28c4 100644
83724 --- a/include/net/llc_c_ev.h
83725 +++ b/include/net/llc_c_ev.h
83726 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83727 return (struct llc_conn_state_ev *)skb->cb;
83728 }
83729
83730 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83731 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83732 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83733 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83734
83735 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83736 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83737 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83738 index 0e79cfb..f46db31 100644
83739 --- a/include/net/llc_c_st.h
83740 +++ b/include/net/llc_c_st.h
83741 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83742 u8 next_state;
83743 llc_conn_ev_qfyr_t *ev_qualifiers;
83744 llc_conn_action_t *ev_actions;
83745 -};
83746 +} __do_const;
83747
83748 struct llc_conn_state {
83749 u8 current_state;
83750 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83751 index a61b98c..aade1eb 100644
83752 --- a/include/net/llc_s_ac.h
83753 +++ b/include/net/llc_s_ac.h
83754 @@ -23,7 +23,7 @@
83755 #define SAP_ACT_TEST_IND 9
83756
83757 /* All action functions must look like this */
83758 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83759 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83760
83761 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83762 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83763 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83764 index 567c681..cd73ac0 100644
83765 --- a/include/net/llc_s_st.h
83766 +++ b/include/net/llc_s_st.h
83767 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83768 llc_sap_ev_t ev;
83769 u8 next_state;
83770 llc_sap_action_t *ev_actions;
83771 -};
83772 +} __do_const;
83773
83774 struct llc_sap_state {
83775 u8 curr_state;
83776 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83777 index f4ab2fb..71a85ba 100644
83778 --- a/include/net/mac80211.h
83779 +++ b/include/net/mac80211.h
83780 @@ -4476,7 +4476,7 @@ struct rate_control_ops {
83781 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83782 struct dentry *dir);
83783 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83784 -};
83785 +} __do_const;
83786
83787 static inline int rate_supported(struct ieee80211_sta *sta,
83788 enum ieee80211_band band,
83789 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83790 index 7277caf..fd095bc 100644
83791 --- a/include/net/neighbour.h
83792 +++ b/include/net/neighbour.h
83793 @@ -163,7 +163,7 @@ struct neigh_ops {
83794 void (*error_report)(struct neighbour *, struct sk_buff *);
83795 int (*output)(struct neighbour *, struct sk_buff *);
83796 int (*connected_output)(struct neighbour *, struct sk_buff *);
83797 -};
83798 +} __do_const;
83799
83800 struct pneigh_entry {
83801 struct pneigh_entry *next;
83802 @@ -203,7 +203,6 @@ struct neigh_table {
83803 void (*proxy_redo)(struct sk_buff *skb);
83804 char *id;
83805 struct neigh_parms parms;
83806 - /* HACK. gc_* should follow parms without a gap! */
83807 int gc_interval;
83808 int gc_thresh1;
83809 int gc_thresh2;
83810 @@ -218,7 +217,7 @@ struct neigh_table {
83811 struct neigh_statistics __percpu *stats;
83812 struct neigh_hash_table __rcu *nht;
83813 struct pneigh_entry **phash_buckets;
83814 -};
83815 +} __randomize_layout;
83816
83817 static inline int neigh_parms_family(struct neigh_parms *p)
83818 {
83819 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83820 index 991dcd9..ab58d00 100644
83821 --- a/include/net/net_namespace.h
83822 +++ b/include/net/net_namespace.h
83823 @@ -124,8 +124,8 @@ struct net {
83824 struct netns_ipvs *ipvs;
83825 #endif
83826 struct sock *diag_nlsk;
83827 - atomic_t fnhe_genid;
83828 -};
83829 + atomic_unchecked_t fnhe_genid;
83830 +} __randomize_layout;
83831
83832 /*
83833 * ifindex generation is per-net namespace, and loopback is
83834 @@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83835 #define __net_init __init
83836 #define __net_exit __exit_refok
83837 #define __net_initdata __initdata
83838 +#ifdef CONSTIFY_PLUGIN
83839 #define __net_initconst __initconst
83840 +#else
83841 +#define __net_initconst __initdata
83842 +#endif
83843 #endif
83844
83845 struct pernet_operations {
83846 @@ -299,7 +303,7 @@ struct pernet_operations {
83847 void (*exit_batch)(struct list_head *net_exit_list);
83848 int *id;
83849 size_t size;
83850 -};
83851 +} __do_const;
83852
83853 /*
83854 * Use these carefully. If you implement a network device and it
83855 @@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83856
83857 static inline int rt_genid_ipv4(struct net *net)
83858 {
83859 - return atomic_read(&net->ipv4.rt_genid);
83860 + return atomic_read_unchecked(&net->ipv4.rt_genid);
83861 }
83862
83863 static inline void rt_genid_bump_ipv4(struct net *net)
83864 {
83865 - atomic_inc(&net->ipv4.rt_genid);
83866 + atomic_inc_unchecked(&net->ipv4.rt_genid);
83867 }
83868
83869 #if IS_ENABLED(CONFIG_IPV6)
83870 static inline int rt_genid_ipv6(struct net *net)
83871 {
83872 - return atomic_read(&net->ipv6.rt_genid);
83873 + return atomic_read_unchecked(&net->ipv6.rt_genid);
83874 }
83875
83876 static inline void rt_genid_bump_ipv6(struct net *net)
83877 {
83878 - atomic_inc(&net->ipv6.rt_genid);
83879 + atomic_inc_unchecked(&net->ipv6.rt_genid);
83880 }
83881 #else
83882 static inline int rt_genid_ipv6(struct net *net)
83883 @@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
83884
83885 static inline int fnhe_genid(struct net *net)
83886 {
83887 - return atomic_read(&net->fnhe_genid);
83888 + return atomic_read_unchecked(&net->fnhe_genid);
83889 }
83890
83891 static inline void fnhe_genid_bump(struct net *net)
83892 {
83893 - atomic_inc(&net->fnhe_genid);
83894 + atomic_inc_unchecked(&net->fnhe_genid);
83895 }
83896
83897 #endif /* __NET_NET_NAMESPACE_H */
83898 diff --git a/include/net/netdma.h b/include/net/netdma.h
83899 index 8ba8ce2..99b7fff 100644
83900 --- a/include/net/netdma.h
83901 +++ b/include/net/netdma.h
83902 @@ -24,7 +24,7 @@
83903 #include <linux/dmaengine.h>
83904 #include <linux/skbuff.h>
83905
83906 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83907 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83908 struct sk_buff *skb, int offset, struct iovec *to,
83909 size_t len, struct dma_pinned_list *pinned_list);
83910
83911 diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
83912 index 956b175..55d1504 100644
83913 --- a/include/net/netfilter/nf_conntrack_extend.h
83914 +++ b/include/net/netfilter/nf_conntrack_extend.h
83915 @@ -47,8 +47,8 @@ enum nf_ct_ext_id {
83916 /* Extensions: optional stuff which isn't permanently in struct. */
83917 struct nf_ct_ext {
83918 struct rcu_head rcu;
83919 - u8 offset[NF_CT_EXT_NUM];
83920 - u8 len;
83921 + u16 offset[NF_CT_EXT_NUM];
83922 + u16 len;
83923 char data[0];
83924 };
83925
83926 diff --git a/include/net/netlink.h b/include/net/netlink.h
83927 index 2b47eaa..6d5bcc2 100644
83928 --- a/include/net/netlink.h
83929 +++ b/include/net/netlink.h
83930 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83931 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83932 {
83933 if (mark)
83934 - skb_trim(skb, (unsigned char *) mark - skb->data);
83935 + skb_trim(skb, (const unsigned char *) mark - skb->data);
83936 }
83937
83938 /**
83939 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83940 index fbcc7fa..03c7e51 100644
83941 --- a/include/net/netns/conntrack.h
83942 +++ b/include/net/netns/conntrack.h
83943 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
83944 struct nf_proto_net {
83945 #ifdef CONFIG_SYSCTL
83946 struct ctl_table_header *ctl_table_header;
83947 - struct ctl_table *ctl_table;
83948 + ctl_table_no_const *ctl_table;
83949 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83950 struct ctl_table_header *ctl_compat_header;
83951 - struct ctl_table *ctl_compat_table;
83952 + ctl_table_no_const *ctl_compat_table;
83953 #endif
83954 #endif
83955 unsigned int users;
83956 @@ -58,7 +58,7 @@ struct nf_ip_net {
83957 struct nf_icmp_net icmpv6;
83958 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83959 struct ctl_table_header *ctl_table_header;
83960 - struct ctl_table *ctl_table;
83961 + ctl_table_no_const *ctl_table;
83962 #endif
83963 };
83964
83965 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83966 index 80f500a..f0c23c2 100644
83967 --- a/include/net/netns/ipv4.h
83968 +++ b/include/net/netns/ipv4.h
83969 @@ -74,7 +74,7 @@ struct netns_ipv4 {
83970
83971 kgid_t sysctl_ping_group_range[2];
83972
83973 - atomic_t dev_addr_genid;
83974 + atomic_unchecked_t dev_addr_genid;
83975
83976 #ifdef CONFIG_IP_MROUTE
83977 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83978 @@ -84,6 +84,6 @@ struct netns_ipv4 {
83979 struct fib_rules_ops *mr_rules_ops;
83980 #endif
83981 #endif
83982 - atomic_t rt_genid;
83983 + atomic_unchecked_t rt_genid;
83984 };
83985 #endif
83986 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83987 index 21edaf1..4c5faae 100644
83988 --- a/include/net/netns/ipv6.h
83989 +++ b/include/net/netns/ipv6.h
83990 @@ -73,8 +73,8 @@ struct netns_ipv6 {
83991 struct fib_rules_ops *mr6_rules_ops;
83992 #endif
83993 #endif
83994 - atomic_t dev_addr_genid;
83995 - atomic_t rt_genid;
83996 + atomic_unchecked_t dev_addr_genid;
83997 + atomic_unchecked_t rt_genid;
83998 };
83999
84000 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
84001 diff --git a/include/net/ping.h b/include/net/ping.h
84002 index 026479b..d9b2829 100644
84003 --- a/include/net/ping.h
84004 +++ b/include/net/ping.h
84005 @@ -54,7 +54,7 @@ struct ping_iter_state {
84006
84007 extern struct proto ping_prot;
84008 #if IS_ENABLED(CONFIG_IPV6)
84009 -extern struct pingv6_ops pingv6_ops;
84010 +extern struct pingv6_ops *pingv6_ops;
84011 #endif
84012
84013 struct pingfakehdr {
84014 diff --git a/include/net/protocol.h b/include/net/protocol.h
84015 index a7e986b..dc67bce 100644
84016 --- a/include/net/protocol.h
84017 +++ b/include/net/protocol.h
84018 @@ -49,7 +49,7 @@ struct net_protocol {
84019 * socket lookup?
84020 */
84021 icmp_strict_tag_validation:1;
84022 -};
84023 +} __do_const;
84024
84025 #if IS_ENABLED(CONFIG_IPV6)
84026 struct inet6_protocol {
84027 @@ -62,7 +62,7 @@ struct inet6_protocol {
84028 u8 type, u8 code, int offset,
84029 __be32 info);
84030 unsigned int flags; /* INET6_PROTO_xxx */
84031 -};
84032 +} __do_const;
84033
84034 #define INET6_PROTO_NOPOLICY 0x1
84035 #define INET6_PROTO_FINAL 0x2
84036 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
84037 index 661e45d..54c39df 100644
84038 --- a/include/net/rtnetlink.h
84039 +++ b/include/net/rtnetlink.h
84040 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
84041 int (*fill_slave_info)(struct sk_buff *skb,
84042 const struct net_device *dev,
84043 const struct net_device *slave_dev);
84044 -};
84045 +} __do_const;
84046
84047 int __rtnl_link_register(struct rtnl_link_ops *ops);
84048 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
84049 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
84050 index 4a5b9a3..ca27d73 100644
84051 --- a/include/net/sctp/checksum.h
84052 +++ b/include/net/sctp/checksum.h
84053 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
84054 unsigned int offset)
84055 {
84056 struct sctphdr *sh = sctp_hdr(skb);
84057 - __le32 ret, old = sh->checksum;
84058 - const struct skb_checksum_ops ops = {
84059 + __le32 ret, old = sh->checksum;
84060 + static const struct skb_checksum_ops ops = {
84061 .update = sctp_csum_update,
84062 .combine = sctp_csum_combine,
84063 };
84064 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
84065 index 7f4eeb3..37e8fe1 100644
84066 --- a/include/net/sctp/sm.h
84067 +++ b/include/net/sctp/sm.h
84068 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
84069 typedef struct {
84070 sctp_state_fn_t *fn;
84071 const char *name;
84072 -} sctp_sm_table_entry_t;
84073 +} __do_const sctp_sm_table_entry_t;
84074
84075 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
84076 * currently in use.
84077 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
84078 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
84079
84080 /* Extern declarations for major data structures. */
84081 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84082 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84083
84084
84085 /* Get the size of a DATA chunk payload. */
84086 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
84087 index 6ee76c8..45f2609 100644
84088 --- a/include/net/sctp/structs.h
84089 +++ b/include/net/sctp/structs.h
84090 @@ -507,7 +507,7 @@ struct sctp_pf {
84091 struct sctp_association *asoc);
84092 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84093 struct sctp_af *af;
84094 -};
84095 +} __do_const;
84096
84097
84098 /* Structure to track chunk fragments that have been acked, but peer
84099 diff --git a/include/net/sock.h b/include/net/sock.h
84100 index b9586a1..b2948c0 100644
84101 --- a/include/net/sock.h
84102 +++ b/include/net/sock.h
84103 @@ -348,7 +348,7 @@ struct sock {
84104 unsigned int sk_napi_id;
84105 unsigned int sk_ll_usec;
84106 #endif
84107 - atomic_t sk_drops;
84108 + atomic_unchecked_t sk_drops;
84109 int sk_rcvbuf;
84110
84111 struct sk_filter __rcu *sk_filter;
84112 @@ -1036,7 +1036,7 @@ struct proto {
84113 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84114 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84115 #endif
84116 -};
84117 +} __randomize_layout;
84118
84119 /*
84120 * Bits in struct cg_proto.flags
84121 @@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84122 return ret >> PAGE_SHIFT;
84123 }
84124
84125 -static inline long
84126 +static inline long __intentional_overflow(-1)
84127 sk_memory_allocated(const struct sock *sk)
84128 {
84129 struct proto *prot = sk->sk_prot;
84130 @@ -1368,7 +1368,7 @@ struct sock_iocb {
84131 struct scm_cookie *scm;
84132 struct msghdr *msg, async_msg;
84133 struct kiocb *kiocb;
84134 -};
84135 +} __randomize_layout;
84136
84137 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84138 {
84139 @@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84140 }
84141
84142 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84143 - char __user *from, char *to,
84144 + char __user *from, unsigned char *to,
84145 int copy, int offset)
84146 {
84147 if (skb->ip_summed == CHECKSUM_NONE) {
84148 @@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84149 }
84150 }
84151
84152 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84153 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84154
84155 /**
84156 * sk_page_frag - return an appropriate page_frag
84157 diff --git a/include/net/tcp.h b/include/net/tcp.h
84158 index 743acce..44a58b0 100644
84159 --- a/include/net/tcp.h
84160 +++ b/include/net/tcp.h
84161 @@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84162 void tcp_xmit_retransmit_queue(struct sock *);
84163 void tcp_simple_retransmit(struct sock *);
84164 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84165 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84166 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84167
84168 void tcp_send_probe0(struct sock *);
84169 void tcp_send_partial(struct sock *);
84170 @@ -710,8 +710,8 @@ struct tcp_skb_cb {
84171 struct inet6_skb_parm h6;
84172 #endif
84173 } header; /* For incoming frames */
84174 - __u32 seq; /* Starting sequence number */
84175 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84176 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
84177 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84178 __u32 when; /* used to compute rtt's */
84179 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84180
84181 @@ -725,7 +725,7 @@ struct tcp_skb_cb {
84182
84183 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84184 /* 1 byte hole */
84185 - __u32 ack_seq; /* Sequence number ACK'd */
84186 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84187 };
84188
84189 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84190 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84191 index fb5654a..4457522 100644
84192 --- a/include/net/xfrm.h
84193 +++ b/include/net/xfrm.h
84194 @@ -286,7 +286,6 @@ struct xfrm_dst;
84195 struct xfrm_policy_afinfo {
84196 unsigned short family;
84197 struct dst_ops *dst_ops;
84198 - void (*garbage_collect)(struct net *net);
84199 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84200 const xfrm_address_t *saddr,
84201 const xfrm_address_t *daddr);
84202 @@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
84203 struct net_device *dev,
84204 const struct flowi *fl);
84205 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84206 -};
84207 +} __do_const;
84208
84209 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84210 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84211 @@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
84212 int (*transport_finish)(struct sk_buff *skb,
84213 int async);
84214 void (*local_error)(struct sk_buff *skb, u32 mtu);
84215 -};
84216 +} __do_const;
84217
84218 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84219 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84220 @@ -428,7 +427,7 @@ struct xfrm_mode {
84221 struct module *owner;
84222 unsigned int encap;
84223 int flags;
84224 -};
84225 +} __do_const;
84226
84227 /* Flags for xfrm_mode. */
84228 enum {
84229 @@ -525,7 +524,7 @@ struct xfrm_policy {
84230 struct timer_list timer;
84231
84232 struct flow_cache_object flo;
84233 - atomic_t genid;
84234 + atomic_unchecked_t genid;
84235 u32 priority;
84236 u32 index;
84237 struct xfrm_mark mark;
84238 @@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84239 }
84240
84241 void xfrm_garbage_collect(struct net *net);
84242 +void xfrm_garbage_collect_deferred(struct net *net);
84243
84244 #else
84245
84246 @@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84247 static inline void xfrm_garbage_collect(struct net *net)
84248 {
84249 }
84250 +static inline void xfrm_garbage_collect_deferred(struct net *net)
84251 +{
84252 +}
84253 #endif
84254
84255 static __inline__
84256 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84257 index 1017e0b..227aa4d 100644
84258 --- a/include/rdma/iw_cm.h
84259 +++ b/include/rdma/iw_cm.h
84260 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
84261 int backlog);
84262
84263 int (*destroy_listen)(struct iw_cm_id *cm_id);
84264 -};
84265 +} __no_const;
84266
84267 /**
84268 * iw_create_cm_id - Create an IW CM identifier.
84269 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84270 index 52beadf..598734c 100644
84271 --- a/include/scsi/libfc.h
84272 +++ b/include/scsi/libfc.h
84273 @@ -771,6 +771,7 @@ struct libfc_function_template {
84274 */
84275 void (*disc_stop_final) (struct fc_lport *);
84276 };
84277 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84278
84279 /**
84280 * struct fc_disc - Discovery context
84281 @@ -875,7 +876,7 @@ struct fc_lport {
84282 struct fc_vport *vport;
84283
84284 /* Operational Information */
84285 - struct libfc_function_template tt;
84286 + libfc_function_template_no_const tt;
84287 u8 link_up;
84288 u8 qfull;
84289 enum fc_lport_state state;
84290 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84291 index d65fbec..f80fef2 100644
84292 --- a/include/scsi/scsi_device.h
84293 +++ b/include/scsi/scsi_device.h
84294 @@ -180,9 +180,9 @@ struct scsi_device {
84295 unsigned int max_device_blocked; /* what device_blocked counts down from */
84296 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84297
84298 - atomic_t iorequest_cnt;
84299 - atomic_t iodone_cnt;
84300 - atomic_t ioerr_cnt;
84301 + atomic_unchecked_t iorequest_cnt;
84302 + atomic_unchecked_t iodone_cnt;
84303 + atomic_unchecked_t ioerr_cnt;
84304
84305 struct device sdev_gendev,
84306 sdev_dev;
84307 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84308 index b797e8f..8e2c3aa 100644
84309 --- a/include/scsi/scsi_transport_fc.h
84310 +++ b/include/scsi/scsi_transport_fc.h
84311 @@ -751,7 +751,8 @@ struct fc_function_template {
84312 unsigned long show_host_system_hostname:1;
84313
84314 unsigned long disable_target_scan:1;
84315 -};
84316 +} __do_const;
84317 +typedef struct fc_function_template __no_const fc_function_template_no_const;
84318
84319
84320 /**
84321 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84322 index ae6c3b8..fd748ac 100644
84323 --- a/include/sound/compress_driver.h
84324 +++ b/include/sound/compress_driver.h
84325 @@ -128,7 +128,7 @@ struct snd_compr_ops {
84326 struct snd_compr_caps *caps);
84327 int (*get_codec_caps) (struct snd_compr_stream *stream,
84328 struct snd_compr_codec_caps *codec);
84329 -};
84330 +} __no_const;
84331
84332 /**
84333 * struct snd_compr: Compressed device
84334 diff --git a/include/sound/soc.h b/include/sound/soc.h
84335 index 9a00147..d814573 100644
84336 --- a/include/sound/soc.h
84337 +++ b/include/sound/soc.h
84338 @@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
84339 /* probe ordering - for components with runtime dependencies */
84340 int probe_order;
84341 int remove_order;
84342 -};
84343 +} __do_const;
84344
84345 /* SoC platform interface */
84346 struct snd_soc_platform_driver {
84347 @@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
84348 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84349 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84350 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84351 -};
84352 +} __do_const;
84353
84354 struct snd_soc_platform {
84355 const char *name;
84356 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84357 index 1772fad..282e3e2 100644
84358 --- a/include/target/target_core_base.h
84359 +++ b/include/target/target_core_base.h
84360 @@ -754,7 +754,7 @@ struct se_device {
84361 atomic_long_t write_bytes;
84362 /* Active commands on this virtual SE device */
84363 atomic_t simple_cmds;
84364 - atomic_t dev_ordered_id;
84365 + atomic_unchecked_t dev_ordered_id;
84366 atomic_t dev_ordered_sync;
84367 atomic_t dev_qf_count;
84368 int export_count;
84369 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84370 new file mode 100644
84371 index 0000000..fb634b7
84372 --- /dev/null
84373 +++ b/include/trace/events/fs.h
84374 @@ -0,0 +1,53 @@
84375 +#undef TRACE_SYSTEM
84376 +#define TRACE_SYSTEM fs
84377 +
84378 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84379 +#define _TRACE_FS_H
84380 +
84381 +#include <linux/fs.h>
84382 +#include <linux/tracepoint.h>
84383 +
84384 +TRACE_EVENT(do_sys_open,
84385 +
84386 + TP_PROTO(const char *filename, int flags, int mode),
84387 +
84388 + TP_ARGS(filename, flags, mode),
84389 +
84390 + TP_STRUCT__entry(
84391 + __string( filename, filename )
84392 + __field( int, flags )
84393 + __field( int, mode )
84394 + ),
84395 +
84396 + TP_fast_assign(
84397 + __assign_str(filename, filename);
84398 + __entry->flags = flags;
84399 + __entry->mode = mode;
84400 + ),
84401 +
84402 + TP_printk("\"%s\" %x %o",
84403 + __get_str(filename), __entry->flags, __entry->mode)
84404 +);
84405 +
84406 +TRACE_EVENT(open_exec,
84407 +
84408 + TP_PROTO(const char *filename),
84409 +
84410 + TP_ARGS(filename),
84411 +
84412 + TP_STRUCT__entry(
84413 + __string( filename, filename )
84414 + ),
84415 +
84416 + TP_fast_assign(
84417 + __assign_str(filename, filename);
84418 + ),
84419 +
84420 + TP_printk("\"%s\"",
84421 + __get_str(filename))
84422 +);
84423 +
84424 +#endif /* _TRACE_FS_H */
84425 +
84426 +/* This part must be outside protection */
84427 +#include <trace/define_trace.h>
84428 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84429 index 1c09820..7f5ec79 100644
84430 --- a/include/trace/events/irq.h
84431 +++ b/include/trace/events/irq.h
84432 @@ -36,7 +36,7 @@ struct softirq_action;
84433 */
84434 TRACE_EVENT(irq_handler_entry,
84435
84436 - TP_PROTO(int irq, struct irqaction *action),
84437 + TP_PROTO(int irq, const struct irqaction *action),
84438
84439 TP_ARGS(irq, action),
84440
84441 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84442 */
84443 TRACE_EVENT(irq_handler_exit,
84444
84445 - TP_PROTO(int irq, struct irqaction *action, int ret),
84446 + TP_PROTO(int irq, const struct irqaction *action, int ret),
84447
84448 TP_ARGS(irq, action, ret),
84449
84450 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84451 index 7caf44c..23c6f27 100644
84452 --- a/include/uapi/linux/a.out.h
84453 +++ b/include/uapi/linux/a.out.h
84454 @@ -39,6 +39,14 @@ enum machine_type {
84455 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84456 };
84457
84458 +/* Constants for the N_FLAGS field */
84459 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84460 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84461 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84462 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84463 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84464 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84465 +
84466 #if !defined (N_MAGIC)
84467 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84468 #endif
84469 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84470 index 22b6ad3..aeba37e 100644
84471 --- a/include/uapi/linux/bcache.h
84472 +++ b/include/uapi/linux/bcache.h
84473 @@ -5,6 +5,7 @@
84474 * Bcache on disk data structures
84475 */
84476
84477 +#include <linux/compiler.h>
84478 #include <asm/types.h>
84479
84480 #define BITMASK(name, type, field, offset, size) \
84481 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84482 /* Btree keys - all units are in sectors */
84483
84484 struct bkey {
84485 - __u64 high;
84486 - __u64 low;
84487 + __u64 high __intentional_overflow(-1);
84488 + __u64 low __intentional_overflow(-1);
84489 __u64 ptr[];
84490 };
84491
84492 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84493 index d876736..ccce5c0 100644
84494 --- a/include/uapi/linux/byteorder/little_endian.h
84495 +++ b/include/uapi/linux/byteorder/little_endian.h
84496 @@ -42,51 +42,51 @@
84497
84498 static inline __le64 __cpu_to_le64p(const __u64 *p)
84499 {
84500 - return (__force __le64)*p;
84501 + return (__force const __le64)*p;
84502 }
84503 -static inline __u64 __le64_to_cpup(const __le64 *p)
84504 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84505 {
84506 - return (__force __u64)*p;
84507 + return (__force const __u64)*p;
84508 }
84509 static inline __le32 __cpu_to_le32p(const __u32 *p)
84510 {
84511 - return (__force __le32)*p;
84512 + return (__force const __le32)*p;
84513 }
84514 static inline __u32 __le32_to_cpup(const __le32 *p)
84515 {
84516 - return (__force __u32)*p;
84517 + return (__force const __u32)*p;
84518 }
84519 static inline __le16 __cpu_to_le16p(const __u16 *p)
84520 {
84521 - return (__force __le16)*p;
84522 + return (__force const __le16)*p;
84523 }
84524 static inline __u16 __le16_to_cpup(const __le16 *p)
84525 {
84526 - return (__force __u16)*p;
84527 + return (__force const __u16)*p;
84528 }
84529 static inline __be64 __cpu_to_be64p(const __u64 *p)
84530 {
84531 - return (__force __be64)__swab64p(p);
84532 + return (__force const __be64)__swab64p(p);
84533 }
84534 static inline __u64 __be64_to_cpup(const __be64 *p)
84535 {
84536 - return __swab64p((__u64 *)p);
84537 + return __swab64p((const __u64 *)p);
84538 }
84539 static inline __be32 __cpu_to_be32p(const __u32 *p)
84540 {
84541 - return (__force __be32)__swab32p(p);
84542 + return (__force const __be32)__swab32p(p);
84543 }
84544 -static inline __u32 __be32_to_cpup(const __be32 *p)
84545 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84546 {
84547 - return __swab32p((__u32 *)p);
84548 + return __swab32p((const __u32 *)p);
84549 }
84550 static inline __be16 __cpu_to_be16p(const __u16 *p)
84551 {
84552 - return (__force __be16)__swab16p(p);
84553 + return (__force const __be16)__swab16p(p);
84554 }
84555 static inline __u16 __be16_to_cpup(const __be16 *p)
84556 {
84557 - return __swab16p((__u16 *)p);
84558 + return __swab16p((const __u16 *)p);
84559 }
84560 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84561 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84562 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84563 index ef6103b..d4e65dd 100644
84564 --- a/include/uapi/linux/elf.h
84565 +++ b/include/uapi/linux/elf.h
84566 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84567 #define PT_GNU_EH_FRAME 0x6474e550
84568
84569 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84570 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84571 +
84572 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84573 +
84574 +/* Constants for the e_flags field */
84575 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84576 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84577 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84578 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84579 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84580 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84581
84582 /*
84583 * Extended Numbering
84584 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84585 #define DT_DEBUG 21
84586 #define DT_TEXTREL 22
84587 #define DT_JMPREL 23
84588 +#define DT_FLAGS 30
84589 + #define DF_TEXTREL 0x00000004
84590 #define DT_ENCODING 32
84591 #define OLD_DT_LOOS 0x60000000
84592 #define DT_LOOS 0x6000000d
84593 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84594 #define PF_W 0x2
84595 #define PF_X 0x1
84596
84597 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84598 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84599 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84600 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84601 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84602 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84603 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84604 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84605 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84606 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84607 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84608 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84609 +
84610 typedef struct elf32_phdr{
84611 Elf32_Word p_type;
84612 Elf32_Off p_offset;
84613 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84614 #define EI_OSABI 7
84615 #define EI_PAD 8
84616
84617 +#define EI_PAX 14
84618 +
84619 #define ELFMAG0 0x7f /* EI_MAG */
84620 #define ELFMAG1 'E'
84621 #define ELFMAG2 'L'
84622 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84623 index aa169c4..6a2771d 100644
84624 --- a/include/uapi/linux/personality.h
84625 +++ b/include/uapi/linux/personality.h
84626 @@ -30,6 +30,7 @@ enum {
84627 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84628 ADDR_NO_RANDOMIZE | \
84629 ADDR_COMPAT_LAYOUT | \
84630 + ADDR_LIMIT_3GB | \
84631 MMAP_PAGE_ZERO)
84632
84633 /*
84634 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84635 index 7530e74..e714828 100644
84636 --- a/include/uapi/linux/screen_info.h
84637 +++ b/include/uapi/linux/screen_info.h
84638 @@ -43,7 +43,8 @@ struct screen_info {
84639 __u16 pages; /* 0x32 */
84640 __u16 vesa_attributes; /* 0x34 */
84641 __u32 capabilities; /* 0x36 */
84642 - __u8 _reserved[6]; /* 0x3a */
84643 + __u16 vesapm_size; /* 0x3a */
84644 + __u8 _reserved[4]; /* 0x3c */
84645 } __attribute__((packed));
84646
84647 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84648 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84649 index 0e011eb..82681b1 100644
84650 --- a/include/uapi/linux/swab.h
84651 +++ b/include/uapi/linux/swab.h
84652 @@ -43,7 +43,7 @@
84653 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84654 */
84655
84656 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
84657 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84658 {
84659 #ifdef __HAVE_BUILTIN_BSWAP16__
84660 return __builtin_bswap16(val);
84661 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84662 #endif
84663 }
84664
84665 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
84666 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84667 {
84668 #ifdef __HAVE_BUILTIN_BSWAP32__
84669 return __builtin_bswap32(val);
84670 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84671 #endif
84672 }
84673
84674 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
84675 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84676 {
84677 #ifdef __HAVE_BUILTIN_BSWAP64__
84678 return __builtin_bswap64(val);
84679 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84680 index 6d67213..552fdd9 100644
84681 --- a/include/uapi/linux/sysctl.h
84682 +++ b/include/uapi/linux/sysctl.h
84683 @@ -155,8 +155,6 @@ enum
84684 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84685 };
84686
84687 -
84688 -
84689 /* CTL_VM names: */
84690 enum
84691 {
84692 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84693 index fe94bb9..c9e51c2 100644
84694 --- a/include/uapi/linux/videodev2.h
84695 +++ b/include/uapi/linux/videodev2.h
84696 @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
84697 union {
84698 __s32 value;
84699 __s64 value64;
84700 - char *string;
84701 + char __user *string;
84702 };
84703 } __attribute__ ((packed));
84704
84705 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84706 index c38355c..17a57bc 100644
84707 --- a/include/uapi/linux/xattr.h
84708 +++ b/include/uapi/linux/xattr.h
84709 @@ -73,5 +73,9 @@
84710 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84711 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84712
84713 +/* User namespace */
84714 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84715 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
84716 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84717
84718 #endif /* _UAPI_LINUX_XATTR_H */
84719 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84720 index f9466fa..f4e2b81 100644
84721 --- a/include/video/udlfb.h
84722 +++ b/include/video/udlfb.h
84723 @@ -53,10 +53,10 @@ struct dlfb_data {
84724 u32 pseudo_palette[256];
84725 int blank_mode; /*one of FB_BLANK_ */
84726 /* blit-only rendering path metrics, exposed through sysfs */
84727 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84728 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84729 - atomic_t bytes_sent; /* to usb, after compression including overhead */
84730 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84731 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84732 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84733 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84734 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84735 };
84736
84737 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84738 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84739 index 30f5362..8ed8ac9 100644
84740 --- a/include/video/uvesafb.h
84741 +++ b/include/video/uvesafb.h
84742 @@ -122,6 +122,7 @@ struct uvesafb_par {
84743 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84744 u8 pmi_setpal; /* PMI for palette changes */
84745 u16 *pmi_base; /* protected mode interface location */
84746 + u8 *pmi_code; /* protected mode code location */
84747 void *pmi_start;
84748 void *pmi_pal;
84749 u8 *vbe_state_orig; /*
84750 diff --git a/init/Kconfig b/init/Kconfig
84751 index d56cb03..7e6d5dc 100644
84752 --- a/init/Kconfig
84753 +++ b/init/Kconfig
84754 @@ -1079,6 +1079,7 @@ endif # CGROUPS
84755
84756 config CHECKPOINT_RESTORE
84757 bool "Checkpoint/restore support" if EXPERT
84758 + depends on !GRKERNSEC
84759 default n
84760 help
84761 Enables additional kernel features in a sake of checkpoint/restore.
84762 @@ -1545,7 +1546,7 @@ config SLUB_DEBUG
84763
84764 config COMPAT_BRK
84765 bool "Disable heap randomization"
84766 - default y
84767 + default n
84768 help
84769 Randomizing heap placement makes heap exploits harder, but it
84770 also breaks ancient binaries (including anything libc5 based).
84771 @@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
84772 config STOP_MACHINE
84773 bool
84774 default y
84775 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84776 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84777 help
84778 Need stop_machine() primitive.
84779
84780 diff --git a/init/Makefile b/init/Makefile
84781 index 7bc47ee..6da2dc7 100644
84782 --- a/init/Makefile
84783 +++ b/init/Makefile
84784 @@ -2,6 +2,9 @@
84785 # Makefile for the linux kernel.
84786 #
84787
84788 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
84789 +asflags-y := $(GCC_PLUGINS_AFLAGS)
84790 +
84791 obj-y := main.o version.o mounts.o
84792 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84793 obj-y += noinitramfs.o
84794 diff --git a/init/do_mounts.c b/init/do_mounts.c
84795 index 8e5addc..c96ea61 100644
84796 --- a/init/do_mounts.c
84797 +++ b/init/do_mounts.c
84798 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84799 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84800 {
84801 struct super_block *s;
84802 - int err = sys_mount(name, "/root", fs, flags, data);
84803 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84804 if (err)
84805 return err;
84806
84807 - sys_chdir("/root");
84808 + sys_chdir((const char __force_user *)"/root");
84809 s = current->fs->pwd.dentry->d_sb;
84810 ROOT_DEV = s->s_dev;
84811 printk(KERN_INFO
84812 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84813 va_start(args, fmt);
84814 vsprintf(buf, fmt, args);
84815 va_end(args);
84816 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84817 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84818 if (fd >= 0) {
84819 sys_ioctl(fd, FDEJECT, 0);
84820 sys_close(fd);
84821 }
84822 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84823 - fd = sys_open("/dev/console", O_RDWR, 0);
84824 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84825 if (fd >= 0) {
84826 sys_ioctl(fd, TCGETS, (long)&termios);
84827 termios.c_lflag &= ~ICANON;
84828 sys_ioctl(fd, TCSETSF, (long)&termios);
84829 - sys_read(fd, &c, 1);
84830 + sys_read(fd, (char __user *)&c, 1);
84831 termios.c_lflag |= ICANON;
84832 sys_ioctl(fd, TCSETSF, (long)&termios);
84833 sys_close(fd);
84834 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84835 mount_root();
84836 out:
84837 devtmpfs_mount("dev");
84838 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
84839 - sys_chroot(".");
84840 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84841 + sys_chroot((const char __force_user *)".");
84842 }
84843
84844 static bool is_tmpfs;
84845 diff --git a/init/do_mounts.h b/init/do_mounts.h
84846 index f5b978a..69dbfe8 100644
84847 --- a/init/do_mounts.h
84848 +++ b/init/do_mounts.h
84849 @@ -15,15 +15,15 @@ extern int root_mountflags;
84850
84851 static inline int create_dev(char *name, dev_t dev)
84852 {
84853 - sys_unlink(name);
84854 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84855 + sys_unlink((char __force_user *)name);
84856 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84857 }
84858
84859 #if BITS_PER_LONG == 32
84860 static inline u32 bstat(char *name)
84861 {
84862 struct stat64 stat;
84863 - if (sys_stat64(name, &stat) != 0)
84864 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84865 return 0;
84866 if (!S_ISBLK(stat.st_mode))
84867 return 0;
84868 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84869 static inline u32 bstat(char *name)
84870 {
84871 struct stat stat;
84872 - if (sys_newstat(name, &stat) != 0)
84873 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84874 return 0;
84875 if (!S_ISBLK(stat.st_mode))
84876 return 0;
84877 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84878 index 3e0878e..8a9d7a0 100644
84879 --- a/init/do_mounts_initrd.c
84880 +++ b/init/do_mounts_initrd.c
84881 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84882 {
84883 sys_unshare(CLONE_FS | CLONE_FILES);
84884 /* stdin/stdout/stderr for /linuxrc */
84885 - sys_open("/dev/console", O_RDWR, 0);
84886 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84887 sys_dup(0);
84888 sys_dup(0);
84889 /* move initrd over / and chdir/chroot in initrd root */
84890 - sys_chdir("/root");
84891 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
84892 - sys_chroot(".");
84893 + sys_chdir((const char __force_user *)"/root");
84894 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84895 + sys_chroot((const char __force_user *)".");
84896 sys_setsid();
84897 return 0;
84898 }
84899 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84900 create_dev("/dev/root.old", Root_RAM0);
84901 /* mount initrd on rootfs' /root */
84902 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84903 - sys_mkdir("/old", 0700);
84904 - sys_chdir("/old");
84905 + sys_mkdir((const char __force_user *)"/old", 0700);
84906 + sys_chdir((const char __force_user *)"/old");
84907
84908 /* try loading default modules from initrd */
84909 load_default_modules();
84910 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84911 current->flags &= ~PF_FREEZER_SKIP;
84912
84913 /* move initrd to rootfs' /old */
84914 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
84915 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84916 /* switch root and cwd back to / of rootfs */
84917 - sys_chroot("..");
84918 + sys_chroot((const char __force_user *)"..");
84919
84920 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84921 - sys_chdir("/old");
84922 + sys_chdir((const char __force_user *)"/old");
84923 return;
84924 }
84925
84926 - sys_chdir("/");
84927 + sys_chdir((const char __force_user *)"/");
84928 ROOT_DEV = new_decode_dev(real_root_dev);
84929 mount_root();
84930
84931 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84932 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84933 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84934 if (!error)
84935 printk("okay\n");
84936 else {
84937 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
84938 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84939 if (error == -ENOENT)
84940 printk("/initrd does not exist. Ignored.\n");
84941 else
84942 printk("failed\n");
84943 printk(KERN_NOTICE "Unmounting old root\n");
84944 - sys_umount("/old", MNT_DETACH);
84945 + sys_umount((char __force_user *)"/old", MNT_DETACH);
84946 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84947 if (fd < 0) {
84948 error = fd;
84949 @@ -127,11 +127,11 @@ int __init initrd_load(void)
84950 * mounted in the normal path.
84951 */
84952 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84953 - sys_unlink("/initrd.image");
84954 + sys_unlink((const char __force_user *)"/initrd.image");
84955 handle_initrd();
84956 return 1;
84957 }
84958 }
84959 - sys_unlink("/initrd.image");
84960 + sys_unlink((const char __force_user *)"/initrd.image");
84961 return 0;
84962 }
84963 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84964 index 8cb6db5..d729f50 100644
84965 --- a/init/do_mounts_md.c
84966 +++ b/init/do_mounts_md.c
84967 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84968 partitioned ? "_d" : "", minor,
84969 md_setup_args[ent].device_names);
84970
84971 - fd = sys_open(name, 0, 0);
84972 + fd = sys_open((char __force_user *)name, 0, 0);
84973 if (fd < 0) {
84974 printk(KERN_ERR "md: open failed - cannot start "
84975 "array %s\n", name);
84976 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84977 * array without it
84978 */
84979 sys_close(fd);
84980 - fd = sys_open(name, 0, 0);
84981 + fd = sys_open((char __force_user *)name, 0, 0);
84982 sys_ioctl(fd, BLKRRPART, 0);
84983 }
84984 sys_close(fd);
84985 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84986
84987 wait_for_device_probe();
84988
84989 - fd = sys_open("/dev/md0", 0, 0);
84990 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84991 if (fd >= 0) {
84992 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84993 sys_close(fd);
84994 diff --git a/init/init_task.c b/init/init_task.c
84995 index ba0a7f36..2bcf1d5 100644
84996 --- a/init/init_task.c
84997 +++ b/init/init_task.c
84998 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84999 * Initial thread structure. Alignment of this is handled by a special
85000 * linker map entry.
85001 */
85002 +#ifdef CONFIG_X86
85003 +union thread_union init_thread_union __init_task_data;
85004 +#else
85005 union thread_union init_thread_union __init_task_data =
85006 { INIT_THREAD_INFO(init_task) };
85007 +#endif
85008 diff --git a/init/initramfs.c b/init/initramfs.c
85009 index 93b6139..8d628b7 100644
85010 --- a/init/initramfs.c
85011 +++ b/init/initramfs.c
85012 @@ -84,7 +84,7 @@ static void __init free_hash(void)
85013 }
85014 }
85015
85016 -static long __init do_utime(char *filename, time_t mtime)
85017 +static long __init do_utime(char __force_user *filename, time_t mtime)
85018 {
85019 struct timespec t[2];
85020
85021 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
85022 struct dir_entry *de, *tmp;
85023 list_for_each_entry_safe(de, tmp, &dir_list, list) {
85024 list_del(&de->list);
85025 - do_utime(de->name, de->mtime);
85026 + do_utime((char __force_user *)de->name, de->mtime);
85027 kfree(de->name);
85028 kfree(de);
85029 }
85030 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
85031 if (nlink >= 2) {
85032 char *old = find_link(major, minor, ino, mode, collected);
85033 if (old)
85034 - return (sys_link(old, collected) < 0) ? -1 : 1;
85035 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
85036 }
85037 return 0;
85038 }
85039 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
85040 {
85041 struct stat st;
85042
85043 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
85044 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
85045 if (S_ISDIR(st.st_mode))
85046 - sys_rmdir(path);
85047 + sys_rmdir((char __force_user *)path);
85048 else
85049 - sys_unlink(path);
85050 + sys_unlink((char __force_user *)path);
85051 }
85052 }
85053
85054 @@ -315,7 +315,7 @@ static int __init do_name(void)
85055 int openflags = O_WRONLY|O_CREAT;
85056 if (ml != 1)
85057 openflags |= O_TRUNC;
85058 - wfd = sys_open(collected, openflags, mode);
85059 + wfd = sys_open((char __force_user *)collected, openflags, mode);
85060
85061 if (wfd >= 0) {
85062 sys_fchown(wfd, uid, gid);
85063 @@ -327,17 +327,17 @@ static int __init do_name(void)
85064 }
85065 }
85066 } else if (S_ISDIR(mode)) {
85067 - sys_mkdir(collected, mode);
85068 - sys_chown(collected, uid, gid);
85069 - sys_chmod(collected, mode);
85070 + sys_mkdir((char __force_user *)collected, mode);
85071 + sys_chown((char __force_user *)collected, uid, gid);
85072 + sys_chmod((char __force_user *)collected, mode);
85073 dir_add(collected, mtime);
85074 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
85075 S_ISFIFO(mode) || S_ISSOCK(mode)) {
85076 if (maybe_link() == 0) {
85077 - sys_mknod(collected, mode, rdev);
85078 - sys_chown(collected, uid, gid);
85079 - sys_chmod(collected, mode);
85080 - do_utime(collected, mtime);
85081 + sys_mknod((char __force_user *)collected, mode, rdev);
85082 + sys_chown((char __force_user *)collected, uid, gid);
85083 + sys_chmod((char __force_user *)collected, mode);
85084 + do_utime((char __force_user *)collected, mtime);
85085 }
85086 }
85087 return 0;
85088 @@ -346,15 +346,15 @@ static int __init do_name(void)
85089 static int __init do_copy(void)
85090 {
85091 if (count >= body_len) {
85092 - sys_write(wfd, victim, body_len);
85093 + sys_write(wfd, (char __force_user *)victim, body_len);
85094 sys_close(wfd);
85095 - do_utime(vcollected, mtime);
85096 + do_utime((char __force_user *)vcollected, mtime);
85097 kfree(vcollected);
85098 eat(body_len);
85099 state = SkipIt;
85100 return 0;
85101 } else {
85102 - sys_write(wfd, victim, count);
85103 + sys_write(wfd, (char __force_user *)victim, count);
85104 body_len -= count;
85105 eat(count);
85106 return 1;
85107 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
85108 {
85109 collected[N_ALIGN(name_len) + body_len] = '\0';
85110 clean_path(collected, 0);
85111 - sys_symlink(collected + N_ALIGN(name_len), collected);
85112 - sys_lchown(collected, uid, gid);
85113 - do_utime(collected, mtime);
85114 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85115 + sys_lchown((char __force_user *)collected, uid, gid);
85116 + do_utime((char __force_user *)collected, mtime);
85117 state = SkipIt;
85118 next_state = Reset;
85119 return 0;
85120 diff --git a/init/main.c b/init/main.c
85121 index 9c7fd4c..650b4f1 100644
85122 --- a/init/main.c
85123 +++ b/init/main.c
85124 @@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85125 static inline void mark_rodata_ro(void) { }
85126 #endif
85127
85128 +extern void grsecurity_init(void);
85129 +
85130 /*
85131 * Debug helper: via this flag we know that we are in 'early bootup code'
85132 * where only the boot processor is running with IRQ disabled. This means
85133 @@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85134
85135 __setup("reset_devices", set_reset_devices);
85136
85137 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85138 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85139 +static int __init setup_grsec_proc_gid(char *str)
85140 +{
85141 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85142 + return 1;
85143 +}
85144 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85145 +#endif
85146 +
85147 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85148 +unsigned long pax_user_shadow_base __read_only;
85149 +EXPORT_SYMBOL(pax_user_shadow_base);
85150 +extern char pax_enter_kernel_user[];
85151 +extern char pax_exit_kernel_user[];
85152 +#endif
85153 +
85154 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85155 +static int __init setup_pax_nouderef(char *str)
85156 +{
85157 +#ifdef CONFIG_X86_32
85158 + unsigned int cpu;
85159 + struct desc_struct *gdt;
85160 +
85161 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85162 + gdt = get_cpu_gdt_table(cpu);
85163 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85164 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85165 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85166 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85167 + }
85168 + loadsegment(ds, __KERNEL_DS);
85169 + loadsegment(es, __KERNEL_DS);
85170 + loadsegment(ss, __KERNEL_DS);
85171 +#else
85172 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85173 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85174 + clone_pgd_mask = ~(pgdval_t)0UL;
85175 + pax_user_shadow_base = 0UL;
85176 + setup_clear_cpu_cap(X86_FEATURE_PCID);
85177 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85178 +#endif
85179 +
85180 + return 0;
85181 +}
85182 +early_param("pax_nouderef", setup_pax_nouderef);
85183 +
85184 +#ifdef CONFIG_X86_64
85185 +static int __init setup_pax_weakuderef(char *str)
85186 +{
85187 + if (clone_pgd_mask != ~(pgdval_t)0UL)
85188 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85189 + return 1;
85190 +}
85191 +__setup("pax_weakuderef", setup_pax_weakuderef);
85192 +#endif
85193 +#endif
85194 +
85195 +#ifdef CONFIG_PAX_SOFTMODE
85196 +int pax_softmode;
85197 +
85198 +static int __init setup_pax_softmode(char *str)
85199 +{
85200 + get_option(&str, &pax_softmode);
85201 + return 1;
85202 +}
85203 +__setup("pax_softmode=", setup_pax_softmode);
85204 +#endif
85205 +
85206 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85207 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85208 static const char *panic_later, *panic_param;
85209 @@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85210 {
85211 int count = preempt_count();
85212 int ret;
85213 - char msgbuf[64];
85214 + const char *msg1 = "", *msg2 = "";
85215
85216 if (initcall_debug)
85217 ret = do_one_initcall_debug(fn);
85218 else
85219 ret = fn();
85220
85221 - msgbuf[0] = 0;
85222 -
85223 if (preempt_count() != count) {
85224 - sprintf(msgbuf, "preemption imbalance ");
85225 + msg1 = " preemption imbalance";
85226 preempt_count_set(count);
85227 }
85228 if (irqs_disabled()) {
85229 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85230 + msg2 = " disabled interrupts";
85231 local_irq_enable();
85232 }
85233 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85234 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85235
85236 + add_latent_entropy();
85237 return ret;
85238 }
85239
85240 @@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
85241 {
85242 argv_init[0] = init_filename;
85243 return do_execve(getname_kernel(init_filename),
85244 - (const char __user *const __user *)argv_init,
85245 - (const char __user *const __user *)envp_init);
85246 + (const char __user *const __force_user *)argv_init,
85247 + (const char __user *const __force_user *)envp_init);
85248 }
85249
85250 static int try_to_run_init_process(const char *init_filename)
85251 @@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
85252 return ret;
85253 }
85254
85255 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85256 +extern int gr_init_ran;
85257 +#endif
85258 +
85259 static noinline void __init kernel_init_freeable(void);
85260
85261 static int __ref kernel_init(void *unused)
85262 @@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
85263 ramdisk_execute_command, ret);
85264 }
85265
85266 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85267 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
85268 + gr_init_ran = 1;
85269 +#endif
85270 +
85271 /*
85272 * We try each of these until one succeeds.
85273 *
85274 @@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
85275 do_basic_setup();
85276
85277 /* Open the /dev/console on the rootfs, this should never fail */
85278 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85279 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85280 pr_err("Warning: unable to open an initial console.\n");
85281
85282 (void) sys_dup(0);
85283 @@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
85284 if (!ramdisk_execute_command)
85285 ramdisk_execute_command = "/init";
85286
85287 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85288 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85289 ramdisk_execute_command = NULL;
85290 prepare_namespace();
85291 }
85292
85293 + grsecurity_init();
85294 +
85295 /*
85296 * Ok, we have completed the initial bootup, and
85297 * we're essentially up and running. Get rid of the
85298 diff --git a/ipc/compat.c b/ipc/compat.c
85299 index f486b00..442867f 100644
85300 --- a/ipc/compat.c
85301 +++ b/ipc/compat.c
85302 @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85303 COMPAT_SHMLBA);
85304 if (err < 0)
85305 return err;
85306 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85307 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85308 }
85309 case SHMDT:
85310 return sys_shmdt(compat_ptr(ptr));
85311 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85312 index 1702864..797fa84 100644
85313 --- a/ipc/ipc_sysctl.c
85314 +++ b/ipc/ipc_sysctl.c
85315 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85316 static int proc_ipc_dointvec(ctl_table *table, int write,
85317 void __user *buffer, size_t *lenp, loff_t *ppos)
85318 {
85319 - struct ctl_table ipc_table;
85320 + ctl_table_no_const ipc_table;
85321
85322 memcpy(&ipc_table, table, sizeof(ipc_table));
85323 ipc_table.data = get_ipc(table);
85324 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85325 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85326 void __user *buffer, size_t *lenp, loff_t *ppos)
85327 {
85328 - struct ctl_table ipc_table;
85329 + ctl_table_no_const ipc_table;
85330
85331 memcpy(&ipc_table, table, sizeof(ipc_table));
85332 ipc_table.data = get_ipc(table);
85333 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85334 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85335 void __user *buffer, size_t *lenp, loff_t *ppos)
85336 {
85337 - struct ctl_table ipc_table;
85338 + ctl_table_no_const ipc_table;
85339 size_t lenp_bef = *lenp;
85340 int rc;
85341
85342 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85343 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85344 void __user *buffer, size_t *lenp, loff_t *ppos)
85345 {
85346 - struct ctl_table ipc_table;
85347 + ctl_table_no_const ipc_table;
85348 memcpy(&ipc_table, table, sizeof(ipc_table));
85349 ipc_table.data = get_ipc(table);
85350
85351 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85352 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85353 void __user *buffer, size_t *lenp, loff_t *ppos)
85354 {
85355 - struct ctl_table ipc_table;
85356 + ctl_table_no_const ipc_table;
85357 size_t lenp_bef = *lenp;
85358 int oldval;
85359 int rc;
85360 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85361 index 5bb8bfe..a38ec05 100644
85362 --- a/ipc/mq_sysctl.c
85363 +++ b/ipc/mq_sysctl.c
85364 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85365 static int proc_mq_dointvec(ctl_table *table, int write,
85366 void __user *buffer, size_t *lenp, loff_t *ppos)
85367 {
85368 - struct ctl_table mq_table;
85369 + ctl_table_no_const mq_table;
85370 memcpy(&mq_table, table, sizeof(mq_table));
85371 mq_table.data = get_mq(table);
85372
85373 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85374 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85375 void __user *buffer, size_t *lenp, loff_t *ppos)
85376 {
85377 - struct ctl_table mq_table;
85378 + ctl_table_no_const mq_table;
85379 memcpy(&mq_table, table, sizeof(mq_table));
85380 mq_table.data = get_mq(table);
85381
85382 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85383 index c3b3117..1efa933 100644
85384 --- a/ipc/mqueue.c
85385 +++ b/ipc/mqueue.c
85386 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85387 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85388 info->attr.mq_msgsize);
85389
85390 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85391 spin_lock(&mq_lock);
85392 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85393 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85394 diff --git a/ipc/msg.c b/ipc/msg.c
85395 index 6498531..b0ff3c8 100644
85396 --- a/ipc/msg.c
85397 +++ b/ipc/msg.c
85398 @@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85399 return security_msg_queue_associate(msq, msgflg);
85400 }
85401
85402 +static struct ipc_ops msg_ops = {
85403 + .getnew = newque,
85404 + .associate = msg_security,
85405 + .more_checks = NULL
85406 +};
85407 +
85408 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85409 {
85410 struct ipc_namespace *ns;
85411 - struct ipc_ops msg_ops;
85412 struct ipc_params msg_params;
85413
85414 ns = current->nsproxy->ipc_ns;
85415
85416 - msg_ops.getnew = newque;
85417 - msg_ops.associate = msg_security;
85418 - msg_ops.more_checks = NULL;
85419 -
85420 msg_params.key = key;
85421 msg_params.flg = msgflg;
85422
85423 diff --git a/ipc/sem.c b/ipc/sem.c
85424 index bee5554..e9af81dd 100644
85425 --- a/ipc/sem.c
85426 +++ b/ipc/sem.c
85427 @@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85428 return 0;
85429 }
85430
85431 +static struct ipc_ops sem_ops = {
85432 + .getnew = newary,
85433 + .associate = sem_security,
85434 + .more_checks = sem_more_checks
85435 +};
85436 +
85437 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85438 {
85439 struct ipc_namespace *ns;
85440 - struct ipc_ops sem_ops;
85441 struct ipc_params sem_params;
85442
85443 ns = current->nsproxy->ipc_ns;
85444 @@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85445 if (nsems < 0 || nsems > ns->sc_semmsl)
85446 return -EINVAL;
85447
85448 - sem_ops.getnew = newary;
85449 - sem_ops.associate = sem_security;
85450 - sem_ops.more_checks = sem_more_checks;
85451 -
85452 sem_params.key = key;
85453 sem_params.flg = semflg;
85454 sem_params.u.nsems = nsems;
85455 diff --git a/ipc/shm.c b/ipc/shm.c
85456 index 7645961..afc7f02 100644
85457 --- a/ipc/shm.c
85458 +++ b/ipc/shm.c
85459 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85460 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85461 #endif
85462
85463 +#ifdef CONFIG_GRKERNSEC
85464 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85465 + const time_t shm_createtime, const kuid_t cuid,
85466 + const int shmid);
85467 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85468 + const time_t shm_createtime);
85469 +#endif
85470 +
85471 void shm_init_ns(struct ipc_namespace *ns)
85472 {
85473 ns->shm_ctlmax = SHMMAX;
85474 @@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85475 shp->shm_lprid = 0;
85476 shp->shm_atim = shp->shm_dtim = 0;
85477 shp->shm_ctim = get_seconds();
85478 +#ifdef CONFIG_GRKERNSEC
85479 + {
85480 + struct timespec timeval;
85481 + do_posix_clock_monotonic_gettime(&timeval);
85482 +
85483 + shp->shm_createtime = timeval.tv_sec;
85484 + }
85485 +#endif
85486 shp->shm_segsz = size;
85487 shp->shm_nattch = 0;
85488 shp->shm_file = file;
85489 @@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85490 return 0;
85491 }
85492
85493 +static struct ipc_ops shm_ops = {
85494 + .getnew = newseg,
85495 + .associate = shm_security,
85496 + .more_checks = shm_more_checks
85497 +};
85498 +
85499 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85500 {
85501 struct ipc_namespace *ns;
85502 - struct ipc_ops shm_ops;
85503 struct ipc_params shm_params;
85504
85505 ns = current->nsproxy->ipc_ns;
85506
85507 - shm_ops.getnew = newseg;
85508 - shm_ops.associate = shm_security;
85509 - shm_ops.more_checks = shm_more_checks;
85510 -
85511 shm_params.key = key;
85512 shm_params.flg = shmflg;
85513 shm_params.u.size = size;
85514 @@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85515 f_mode = FMODE_READ | FMODE_WRITE;
85516 }
85517 if (shmflg & SHM_EXEC) {
85518 +
85519 +#ifdef CONFIG_PAX_MPROTECT
85520 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
85521 + goto out;
85522 +#endif
85523 +
85524 prot |= PROT_EXEC;
85525 acc_mode |= S_IXUGO;
85526 }
85527 @@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85528 if (err)
85529 goto out_unlock;
85530
85531 +#ifdef CONFIG_GRKERNSEC
85532 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85533 + shp->shm_perm.cuid, shmid) ||
85534 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85535 + err = -EACCES;
85536 + goto out_unlock;
85537 + }
85538 +#endif
85539 +
85540 ipc_lock_object(&shp->shm_perm);
85541
85542 /* check if shm_destroy() is tearing down shp */
85543 @@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85544 path = shp->shm_file->f_path;
85545 path_get(&path);
85546 shp->shm_nattch++;
85547 +#ifdef CONFIG_GRKERNSEC
85548 + shp->shm_lapid = current->pid;
85549 +#endif
85550 size = i_size_read(path.dentry->d_inode);
85551 ipc_unlock_object(&shp->shm_perm);
85552 rcu_read_unlock();
85553 diff --git a/ipc/util.c b/ipc/util.c
85554 index e1b4c6d..8174204 100644
85555 --- a/ipc/util.c
85556 +++ b/ipc/util.c
85557 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
85558 int (*show)(struct seq_file *, void *);
85559 };
85560
85561 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85562 +
85563 static void ipc_memory_notifier(struct work_struct *work)
85564 {
85565 ipcns_notify(IPCNS_MEMCHANGED);
85566 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85567 granted_mode >>= 6;
85568 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85569 granted_mode >>= 3;
85570 +
85571 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85572 + return -1;
85573 +
85574 /* is there some bit set in requested_mode but not in granted_mode? */
85575 if ((requested_mode & ~granted_mode & 0007) &&
85576 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85577 diff --git a/kernel/acct.c b/kernel/acct.c
85578 index 8d6e145..33e0b1e 100644
85579 --- a/kernel/acct.c
85580 +++ b/kernel/acct.c
85581 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85582 */
85583 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85584 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85585 - file->f_op->write(file, (char *)&ac,
85586 + file->f_op->write(file, (char __force_user *)&ac,
85587 sizeof(acct_t), &file->f_pos);
85588 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85589 set_fs(fs);
85590 diff --git a/kernel/audit.c b/kernel/audit.c
85591 index 95a20f3..e1cb300 100644
85592 --- a/kernel/audit.c
85593 +++ b/kernel/audit.c
85594 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85595 3) suppressed due to audit_rate_limit
85596 4) suppressed due to audit_backlog_limit
85597 */
85598 -static atomic_t audit_lost = ATOMIC_INIT(0);
85599 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85600
85601 /* The netlink socket. */
85602 static struct sock *audit_sock;
85603 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85604 unsigned long now;
85605 int print;
85606
85607 - atomic_inc(&audit_lost);
85608 + atomic_inc_unchecked(&audit_lost);
85609
85610 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85611
85612 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85613 if (print) {
85614 if (printk_ratelimit())
85615 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85616 - atomic_read(&audit_lost),
85617 + atomic_read_unchecked(&audit_lost),
85618 audit_rate_limit,
85619 audit_backlog_limit);
85620 audit_panic(message);
85621 @@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85622 s.pid = audit_pid;
85623 s.rate_limit = audit_rate_limit;
85624 s.backlog_limit = audit_backlog_limit;
85625 - s.lost = atomic_read(&audit_lost);
85626 + s.lost = atomic_read_unchecked(&audit_lost);
85627 s.backlog = skb_queue_len(&audit_skb_queue);
85628 s.version = AUDIT_VERSION_LATEST;
85629 s.backlog_wait_time = audit_backlog_wait_time;
85630 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85631 index 7aef2f4..db6ced2 100644
85632 --- a/kernel/auditsc.c
85633 +++ b/kernel/auditsc.c
85634 @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85635 }
85636
85637 /* global counter which is incremented every time something logs in */
85638 -static atomic_t session_id = ATOMIC_INIT(0);
85639 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85640
85641 static int audit_set_loginuid_perm(kuid_t loginuid)
85642 {
85643 @@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
85644
85645 /* are we setting or clearing? */
85646 if (uid_valid(loginuid))
85647 - sessionid = (unsigned int)atomic_inc_return(&session_id);
85648 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85649
85650 task->sessionid = sessionid;
85651 task->loginuid = loginuid;
85652 diff --git a/kernel/capability.c b/kernel/capability.c
85653 index 34019c5..363f279 100644
85654 --- a/kernel/capability.c
85655 +++ b/kernel/capability.c
85656 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85657 * before modification is attempted and the application
85658 * fails.
85659 */
85660 + if (tocopy > ARRAY_SIZE(kdata))
85661 + return -EFAULT;
85662 +
85663 if (copy_to_user(dataptr, kdata, tocopy
85664 * sizeof(struct __user_cap_data_struct))) {
85665 return -EFAULT;
85666 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
85667 int ret;
85668
85669 rcu_read_lock();
85670 - ret = security_capable(__task_cred(t), ns, cap);
85671 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85672 + gr_task_is_capable(t, __task_cred(t), cap);
85673 rcu_read_unlock();
85674
85675 - return (ret == 0);
85676 + return ret;
85677 }
85678
85679 /**
85680 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85681 int ret;
85682
85683 rcu_read_lock();
85684 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
85685 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85686 rcu_read_unlock();
85687
85688 - return (ret == 0);
85689 + return ret;
85690 }
85691
85692 /**
85693 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85694 BUG();
85695 }
85696
85697 - if (security_capable(current_cred(), ns, cap) == 0) {
85698 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85699 current->flags |= PF_SUPERPRIV;
85700 return true;
85701 }
85702 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85703 }
85704 EXPORT_SYMBOL(ns_capable);
85705
85706 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
85707 +{
85708 + if (unlikely(!cap_valid(cap))) {
85709 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85710 + BUG();
85711 + }
85712 +
85713 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85714 + current->flags |= PF_SUPERPRIV;
85715 + return true;
85716 + }
85717 + return false;
85718 +}
85719 +EXPORT_SYMBOL(ns_capable_nolog);
85720 +
85721 /**
85722 * file_ns_capable - Determine if the file's opener had a capability in effect
85723 * @file: The file we want to check
85724 @@ -432,6 +451,12 @@ bool capable(int cap)
85725 }
85726 EXPORT_SYMBOL(capable);
85727
85728 +bool capable_nolog(int cap)
85729 +{
85730 + return ns_capable_nolog(&init_user_ns, cap);
85731 +}
85732 +EXPORT_SYMBOL(capable_nolog);
85733 +
85734 /**
85735 * inode_capable - Check superior capability over inode
85736 * @inode: The inode in question
85737 @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
85738 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85739 }
85740 EXPORT_SYMBOL(inode_capable);
85741 +
85742 +bool inode_capable_nolog(const struct inode *inode, int cap)
85743 +{
85744 + struct user_namespace *ns = current_user_ns();
85745 +
85746 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85747 +}
85748 +EXPORT_SYMBOL(inode_capable_nolog);
85749 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85750 index 0c753dd..dd7d3d6 100644
85751 --- a/kernel/cgroup.c
85752 +++ b/kernel/cgroup.c
85753 @@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85754 struct css_set *cset = link->cset;
85755 struct task_struct *task;
85756 int count = 0;
85757 - seq_printf(seq, "css_set %p\n", cset);
85758 + seq_printf(seq, "css_set %pK\n", cset);
85759 list_for_each_entry(task, &cset->tasks, cg_list) {
85760 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
85761 seq_puts(seq, " ...\n");
85762 diff --git a/kernel/compat.c b/kernel/compat.c
85763 index 0a09e48..b46b3d78 100644
85764 --- a/kernel/compat.c
85765 +++ b/kernel/compat.c
85766 @@ -13,6 +13,7 @@
85767
85768 #include <linux/linkage.h>
85769 #include <linux/compat.h>
85770 +#include <linux/module.h>
85771 #include <linux/errno.h>
85772 #include <linux/time.h>
85773 #include <linux/signal.h>
85774 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85775 mm_segment_t oldfs;
85776 long ret;
85777
85778 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85779 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85780 oldfs = get_fs();
85781 set_fs(KERNEL_DS);
85782 ret = hrtimer_nanosleep_restart(restart);
85783 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
85784 oldfs = get_fs();
85785 set_fs(KERNEL_DS);
85786 ret = hrtimer_nanosleep(&tu,
85787 - rmtp ? (struct timespec __user *)&rmt : NULL,
85788 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
85789 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85790 set_fs(oldfs);
85791
85792 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
85793 mm_segment_t old_fs = get_fs();
85794
85795 set_fs(KERNEL_DS);
85796 - ret = sys_sigpending((old_sigset_t __user *) &s);
85797 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
85798 set_fs(old_fs);
85799 if (ret == 0)
85800 ret = put_user(s, set);
85801 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
85802 mm_segment_t old_fs = get_fs();
85803
85804 set_fs(KERNEL_DS);
85805 - ret = sys_old_getrlimit(resource, &r);
85806 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85807 set_fs(old_fs);
85808
85809 if (!ret) {
85810 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85811 set_fs (KERNEL_DS);
85812 ret = sys_wait4(pid,
85813 (stat_addr ?
85814 - (unsigned int __user *) &status : NULL),
85815 - options, (struct rusage __user *) &r);
85816 + (unsigned int __force_user *) &status : NULL),
85817 + options, (struct rusage __force_user *) &r);
85818 set_fs (old_fs);
85819
85820 if (ret > 0) {
85821 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85822 memset(&info, 0, sizeof(info));
85823
85824 set_fs(KERNEL_DS);
85825 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85826 - uru ? (struct rusage __user *)&ru : NULL);
85827 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85828 + uru ? (struct rusage __force_user *)&ru : NULL);
85829 set_fs(old_fs);
85830
85831 if ((ret < 0) || (info.si_signo == 0))
85832 @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
85833 oldfs = get_fs();
85834 set_fs(KERNEL_DS);
85835 err = sys_timer_settime(timer_id, flags,
85836 - (struct itimerspec __user *) &newts,
85837 - (struct itimerspec __user *) &oldts);
85838 + (struct itimerspec __force_user *) &newts,
85839 + (struct itimerspec __force_user *) &oldts);
85840 set_fs(oldfs);
85841 if (!err && old && put_compat_itimerspec(old, &oldts))
85842 return -EFAULT;
85843 @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
85844 oldfs = get_fs();
85845 set_fs(KERNEL_DS);
85846 err = sys_timer_gettime(timer_id,
85847 - (struct itimerspec __user *) &ts);
85848 + (struct itimerspec __force_user *) &ts);
85849 set_fs(oldfs);
85850 if (!err && put_compat_itimerspec(setting, &ts))
85851 return -EFAULT;
85852 @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
85853 oldfs = get_fs();
85854 set_fs(KERNEL_DS);
85855 err = sys_clock_settime(which_clock,
85856 - (struct timespec __user *) &ts);
85857 + (struct timespec __force_user *) &ts);
85858 set_fs(oldfs);
85859 return err;
85860 }
85861 @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
85862 oldfs = get_fs();
85863 set_fs(KERNEL_DS);
85864 err = sys_clock_gettime(which_clock,
85865 - (struct timespec __user *) &ts);
85866 + (struct timespec __force_user *) &ts);
85867 set_fs(oldfs);
85868 if (!err && put_compat_timespec(&ts, tp))
85869 return -EFAULT;
85870 @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
85871
85872 oldfs = get_fs();
85873 set_fs(KERNEL_DS);
85874 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85875 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85876 set_fs(oldfs);
85877
85878 err = compat_put_timex(utp, &txc);
85879 @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
85880 oldfs = get_fs();
85881 set_fs(KERNEL_DS);
85882 err = sys_clock_getres(which_clock,
85883 - (struct timespec __user *) &ts);
85884 + (struct timespec __force_user *) &ts);
85885 set_fs(oldfs);
85886 if (!err && tp && put_compat_timespec(&ts, tp))
85887 return -EFAULT;
85888 @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85889 long err;
85890 mm_segment_t oldfs;
85891 struct timespec tu;
85892 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
85893 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85894
85895 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85896 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85897 oldfs = get_fs();
85898 set_fs(KERNEL_DS);
85899 err = clock_nanosleep_restart(restart);
85900 @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
85901 oldfs = get_fs();
85902 set_fs(KERNEL_DS);
85903 err = sys_clock_nanosleep(which_clock, flags,
85904 - (struct timespec __user *) &in,
85905 - (struct timespec __user *) &out);
85906 + (struct timespec __force_user *) &in,
85907 + (struct timespec __force_user *) &out);
85908 set_fs(oldfs);
85909
85910 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85911 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85912 mm_segment_t old_fs = get_fs();
85913
85914 set_fs(KERNEL_DS);
85915 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85916 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85917 set_fs(old_fs);
85918 if (put_compat_timespec(&t, interval))
85919 return -EFAULT;
85920 diff --git a/kernel/configs.c b/kernel/configs.c
85921 index c18b1f1..b9a0132 100644
85922 --- a/kernel/configs.c
85923 +++ b/kernel/configs.c
85924 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85925 struct proc_dir_entry *entry;
85926
85927 /* create the current config file */
85928 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85929 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85930 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85931 + &ikconfig_file_ops);
85932 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85933 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85934 + &ikconfig_file_ops);
85935 +#endif
85936 +#else
85937 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85938 &ikconfig_file_ops);
85939 +#endif
85940 +
85941 if (!entry)
85942 return -ENOMEM;
85943
85944 diff --git a/kernel/cred.c b/kernel/cred.c
85945 index e0573a4..3874e41 100644
85946 --- a/kernel/cred.c
85947 +++ b/kernel/cred.c
85948 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85949 validate_creds(cred);
85950 alter_cred_subscribers(cred, -1);
85951 put_cred(cred);
85952 +
85953 +#ifdef CONFIG_GRKERNSEC_SETXID
85954 + cred = (struct cred *) tsk->delayed_cred;
85955 + if (cred != NULL) {
85956 + tsk->delayed_cred = NULL;
85957 + validate_creds(cred);
85958 + alter_cred_subscribers(cred, -1);
85959 + put_cred(cred);
85960 + }
85961 +#endif
85962 }
85963
85964 /**
85965 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85966 * Always returns 0 thus allowing this function to be tail-called at the end
85967 * of, say, sys_setgid().
85968 */
85969 -int commit_creds(struct cred *new)
85970 +static int __commit_creds(struct cred *new)
85971 {
85972 struct task_struct *task = current;
85973 const struct cred *old = task->real_cred;
85974 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85975
85976 get_cred(new); /* we will require a ref for the subj creds too */
85977
85978 + gr_set_role_label(task, new->uid, new->gid);
85979 +
85980 /* dumpability changes */
85981 if (!uid_eq(old->euid, new->euid) ||
85982 !gid_eq(old->egid, new->egid) ||
85983 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85984 put_cred(old);
85985 return 0;
85986 }
85987 +#ifdef CONFIG_GRKERNSEC_SETXID
85988 +extern int set_user(struct cred *new);
85989 +
85990 +void gr_delayed_cred_worker(void)
85991 +{
85992 + const struct cred *new = current->delayed_cred;
85993 + struct cred *ncred;
85994 +
85995 + current->delayed_cred = NULL;
85996 +
85997 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85998 + // from doing get_cred on it when queueing this
85999 + put_cred(new);
86000 + return;
86001 + } else if (new == NULL)
86002 + return;
86003 +
86004 + ncred = prepare_creds();
86005 + if (!ncred)
86006 + goto die;
86007 + // uids
86008 + ncred->uid = new->uid;
86009 + ncred->euid = new->euid;
86010 + ncred->suid = new->suid;
86011 + ncred->fsuid = new->fsuid;
86012 + // gids
86013 + ncred->gid = new->gid;
86014 + ncred->egid = new->egid;
86015 + ncred->sgid = new->sgid;
86016 + ncred->fsgid = new->fsgid;
86017 + // groups
86018 + if (set_groups(ncred, new->group_info) < 0) {
86019 + abort_creds(ncred);
86020 + goto die;
86021 + }
86022 + // caps
86023 + ncred->securebits = new->securebits;
86024 + ncred->cap_inheritable = new->cap_inheritable;
86025 + ncred->cap_permitted = new->cap_permitted;
86026 + ncred->cap_effective = new->cap_effective;
86027 + ncred->cap_bset = new->cap_bset;
86028 +
86029 + if (set_user(ncred)) {
86030 + abort_creds(ncred);
86031 + goto die;
86032 + }
86033 +
86034 + // from doing get_cred on it when queueing this
86035 + put_cred(new);
86036 +
86037 + __commit_creds(ncred);
86038 + return;
86039 +die:
86040 + // from doing get_cred on it when queueing this
86041 + put_cred(new);
86042 + do_group_exit(SIGKILL);
86043 +}
86044 +#endif
86045 +
86046 +int commit_creds(struct cred *new)
86047 +{
86048 +#ifdef CONFIG_GRKERNSEC_SETXID
86049 + int ret;
86050 + int schedule_it = 0;
86051 + struct task_struct *t;
86052 +
86053 + /* we won't get called with tasklist_lock held for writing
86054 + and interrupts disabled as the cred struct in that case is
86055 + init_cred
86056 + */
86057 + if (grsec_enable_setxid && !current_is_single_threaded() &&
86058 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
86059 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
86060 + schedule_it = 1;
86061 + }
86062 + ret = __commit_creds(new);
86063 + if (schedule_it) {
86064 + rcu_read_lock();
86065 + read_lock(&tasklist_lock);
86066 + for (t = next_thread(current); t != current;
86067 + t = next_thread(t)) {
86068 + if (t->delayed_cred == NULL) {
86069 + t->delayed_cred = get_cred(new);
86070 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
86071 + set_tsk_need_resched(t);
86072 + }
86073 + }
86074 + read_unlock(&tasklist_lock);
86075 + rcu_read_unlock();
86076 + }
86077 + return ret;
86078 +#else
86079 + return __commit_creds(new);
86080 +#endif
86081 +}
86082 +
86083 EXPORT_SYMBOL(commit_creds);
86084
86085 /**
86086 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86087 index 334b398..9145fb1 100644
86088 --- a/kernel/debug/debug_core.c
86089 +++ b/kernel/debug/debug_core.c
86090 @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86091 */
86092 static atomic_t masters_in_kgdb;
86093 static atomic_t slaves_in_kgdb;
86094 -static atomic_t kgdb_break_tasklet_var;
86095 +static atomic_unchecked_t kgdb_break_tasklet_var;
86096 atomic_t kgdb_setting_breakpoint;
86097
86098 struct task_struct *kgdb_usethread;
86099 @@ -133,7 +133,7 @@ int kgdb_single_step;
86100 static pid_t kgdb_sstep_pid;
86101
86102 /* to keep track of the CPU which is doing the single stepping*/
86103 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86104 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86105
86106 /*
86107 * If you are debugging a problem where roundup (the collection of
86108 @@ -541,7 +541,7 @@ return_normal:
86109 * kernel will only try for the value of sstep_tries before
86110 * giving up and continuing on.
86111 */
86112 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86113 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86114 (kgdb_info[cpu].task &&
86115 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86116 atomic_set(&kgdb_active, -1);
86117 @@ -639,8 +639,8 @@ cpu_master_loop:
86118 }
86119
86120 kgdb_restore:
86121 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86122 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86123 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86124 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86125 if (kgdb_info[sstep_cpu].task)
86126 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86127 else
86128 @@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
86129 static void kgdb_tasklet_bpt(unsigned long ing)
86130 {
86131 kgdb_breakpoint();
86132 - atomic_set(&kgdb_break_tasklet_var, 0);
86133 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86134 }
86135
86136 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86137
86138 void kgdb_schedule_breakpoint(void)
86139 {
86140 - if (atomic_read(&kgdb_break_tasklet_var) ||
86141 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86142 atomic_read(&kgdb_active) != -1 ||
86143 atomic_read(&kgdb_setting_breakpoint))
86144 return;
86145 - atomic_inc(&kgdb_break_tasklet_var);
86146 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
86147 tasklet_schedule(&kgdb_tasklet_breakpoint);
86148 }
86149 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86150 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86151 index 0b097c8..11dd5c5 100644
86152 --- a/kernel/debug/kdb/kdb_main.c
86153 +++ b/kernel/debug/kdb/kdb_main.c
86154 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86155 continue;
86156
86157 kdb_printf("%-20s%8u 0x%p ", mod->name,
86158 - mod->core_size, (void *)mod);
86159 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
86160 #ifdef CONFIG_MODULE_UNLOAD
86161 kdb_printf("%4ld ", module_refcount(mod));
86162 #endif
86163 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86164 kdb_printf(" (Loading)");
86165 else
86166 kdb_printf(" (Live)");
86167 - kdb_printf(" 0x%p", mod->module_core);
86168 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86169
86170 #ifdef CONFIG_MODULE_UNLOAD
86171 {
86172 diff --git a/kernel/events/core.c b/kernel/events/core.c
86173 index fa0b2d4..67a1c7a 100644
86174 --- a/kernel/events/core.c
86175 +++ b/kernel/events/core.c
86176 @@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86177 * 0 - disallow raw tracepoint access for unpriv
86178 * 1 - disallow cpu events for unpriv
86179 * 2 - disallow kernel profiling for unpriv
86180 + * 3 - disallow all unpriv perf event use
86181 */
86182 -int sysctl_perf_event_paranoid __read_mostly = 1;
86183 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86184 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86185 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86186 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86187 +#else
86188 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86189 +#endif
86190
86191 /* Minimum for 512 kiB + 1 user control page */
86192 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86193 @@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86194
86195 tmp *= sysctl_perf_cpu_time_max_percent;
86196 do_div(tmp, 100);
86197 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86198 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86199 }
86200
86201 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86202 @@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86203 update_perf_cpu_limits();
86204 }
86205
86206 -static atomic64_t perf_event_id;
86207 +static atomic64_unchecked_t perf_event_id;
86208
86209 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86210 enum event_type_t event_type);
86211 @@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
86212
86213 static inline u64 perf_event_count(struct perf_event *event)
86214 {
86215 - return local64_read(&event->count) + atomic64_read(&event->child_count);
86216 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86217 }
86218
86219 static u64 perf_event_read(struct perf_event *event)
86220 @@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86221 mutex_lock(&event->child_mutex);
86222 total += perf_event_read(event);
86223 *enabled += event->total_time_enabled +
86224 - atomic64_read(&event->child_total_time_enabled);
86225 + atomic64_read_unchecked(&event->child_total_time_enabled);
86226 *running += event->total_time_running +
86227 - atomic64_read(&event->child_total_time_running);
86228 + atomic64_read_unchecked(&event->child_total_time_running);
86229
86230 list_for_each_entry(child, &event->child_list, child_list) {
86231 total += perf_event_read(child);
86232 @@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
86233 userpg->offset -= local64_read(&event->hw.prev_count);
86234
86235 userpg->time_enabled = enabled +
86236 - atomic64_read(&event->child_total_time_enabled);
86237 + atomic64_read_unchecked(&event->child_total_time_enabled);
86238
86239 userpg->time_running = running +
86240 - atomic64_read(&event->child_total_time_running);
86241 + atomic64_read_unchecked(&event->child_total_time_running);
86242
86243 arch_perf_update_userpage(userpg, now);
86244
86245 @@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86246
86247 /* Data. */
86248 sp = perf_user_stack_pointer(regs);
86249 - rem = __output_copy_user(handle, (void *) sp, dump_size);
86250 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86251 dyn_size = dump_size - rem;
86252
86253 perf_output_skip(handle, rem);
86254 @@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86255 values[n++] = perf_event_count(event);
86256 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86257 values[n++] = enabled +
86258 - atomic64_read(&event->child_total_time_enabled);
86259 + atomic64_read_unchecked(&event->child_total_time_enabled);
86260 }
86261 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86262 values[n++] = running +
86263 - atomic64_read(&event->child_total_time_running);
86264 + atomic64_read_unchecked(&event->child_total_time_running);
86265 }
86266 if (read_format & PERF_FORMAT_ID)
86267 values[n++] = primary_event_id(event);
86268 @@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86269 event->parent = parent_event;
86270
86271 event->ns = get_pid_ns(task_active_pid_ns(current));
86272 - event->id = atomic64_inc_return(&perf_event_id);
86273 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
86274
86275 event->state = PERF_EVENT_STATE_INACTIVE;
86276
86277 @@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
86278 if (flags & ~PERF_FLAG_ALL)
86279 return -EINVAL;
86280
86281 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86282 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86283 + return -EACCES;
86284 +#endif
86285 +
86286 err = perf_copy_attr(attr_uptr, &attr);
86287 if (err)
86288 return err;
86289 @@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
86290 /*
86291 * Add back the child's count to the parent's count:
86292 */
86293 - atomic64_add(child_val, &parent_event->child_count);
86294 - atomic64_add(child_event->total_time_enabled,
86295 + atomic64_add_unchecked(child_val, &parent_event->child_count);
86296 + atomic64_add_unchecked(child_event->total_time_enabled,
86297 &parent_event->child_total_time_enabled);
86298 - atomic64_add(child_event->total_time_running,
86299 + atomic64_add_unchecked(child_event->total_time_running,
86300 &parent_event->child_total_time_running);
86301
86302 /*
86303 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86304 index 569b2187..19940d9 100644
86305 --- a/kernel/events/internal.h
86306 +++ b/kernel/events/internal.h
86307 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86308 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86309 }
86310
86311 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86312 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86313 static inline unsigned long \
86314 func_name(struct perf_output_handle *handle, \
86315 - const void *buf, unsigned long len) \
86316 + const void user *buf, unsigned long len) \
86317 { \
86318 unsigned long size, written; \
86319 \
86320 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86321 return 0;
86322 }
86323
86324 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86325 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86326
86327 static inline unsigned long
86328 memcpy_skip(void *dst, const void *src, unsigned long n)
86329 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86330 return 0;
86331 }
86332
86333 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86334 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86335
86336 #ifndef arch_perf_out_copy_user
86337 #define arch_perf_out_copy_user arch_perf_out_copy_user
86338 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86339 }
86340 #endif
86341
86342 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86343 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86344
86345 /* Callchain handling */
86346 extern struct perf_callchain_entry *
86347 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86348 index 307d87c..6466cbe 100644
86349 --- a/kernel/events/uprobes.c
86350 +++ b/kernel/events/uprobes.c
86351 @@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86352 {
86353 struct page *page;
86354 uprobe_opcode_t opcode;
86355 - int result;
86356 + long result;
86357
86358 pagefault_disable();
86359 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86360 diff --git a/kernel/exit.c b/kernel/exit.c
86361 index 81b3d67..ef189a4 100644
86362 --- a/kernel/exit.c
86363 +++ b/kernel/exit.c
86364 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86365 struct task_struct *leader;
86366 int zap_leader;
86367 repeat:
86368 +#ifdef CONFIG_NET
86369 + gr_del_task_from_ip_table(p);
86370 +#endif
86371 +
86372 /* don't need to get the RCU readlock here - the process is dead and
86373 * can't be modifying its own credentials. But shut RCU-lockdep up */
86374 rcu_read_lock();
86375 @@ -330,7 +334,7 @@ int allow_signal(int sig)
86376 * know it'll be handled, so that they don't get converted to
86377 * SIGKILL or just silently dropped.
86378 */
86379 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86380 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86381 recalc_sigpending();
86382 spin_unlock_irq(&current->sighand->siglock);
86383 return 0;
86384 @@ -706,6 +710,8 @@ void do_exit(long code)
86385 struct task_struct *tsk = current;
86386 int group_dead;
86387
86388 + set_fs(USER_DS);
86389 +
86390 profile_task_exit(tsk);
86391
86392 WARN_ON(blk_needs_flush_plug(tsk));
86393 @@ -722,7 +728,6 @@ void do_exit(long code)
86394 * mm_release()->clear_child_tid() from writing to a user-controlled
86395 * kernel address.
86396 */
86397 - set_fs(USER_DS);
86398
86399 ptrace_event(PTRACE_EVENT_EXIT, code);
86400
86401 @@ -781,6 +786,9 @@ void do_exit(long code)
86402 tsk->exit_code = code;
86403 taskstats_exit(tsk, group_dead);
86404
86405 + gr_acl_handle_psacct(tsk, code);
86406 + gr_acl_handle_exit();
86407 +
86408 exit_mm(tsk);
86409
86410 if (group_dead)
86411 @@ -900,7 +908,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86412 * Take down every thread in the group. This is called by fatal signals
86413 * as well as by sys_exit_group (below).
86414 */
86415 -void
86416 +__noreturn void
86417 do_group_exit(int exit_code)
86418 {
86419 struct signal_struct *sig = current->signal;
86420 diff --git a/kernel/fork.c b/kernel/fork.c
86421 index a17621c..b77fef8 100644
86422 --- a/kernel/fork.c
86423 +++ b/kernel/fork.c
86424 @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86425 *stackend = STACK_END_MAGIC; /* for overflow detection */
86426
86427 #ifdef CONFIG_CC_STACKPROTECTOR
86428 - tsk->stack_canary = get_random_int();
86429 + tsk->stack_canary = pax_get_random_long();
86430 #endif
86431
86432 /*
86433 @@ -345,12 +345,80 @@ free_tsk:
86434 }
86435
86436 #ifdef CONFIG_MMU
86437 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86438 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86439 +{
86440 + struct vm_area_struct *tmp;
86441 + unsigned long charge;
86442 + struct file *file;
86443 + int retval;
86444 +
86445 + charge = 0;
86446 + if (mpnt->vm_flags & VM_ACCOUNT) {
86447 + unsigned long len = vma_pages(mpnt);
86448 +
86449 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86450 + goto fail_nomem;
86451 + charge = len;
86452 + }
86453 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86454 + if (!tmp)
86455 + goto fail_nomem;
86456 + *tmp = *mpnt;
86457 + tmp->vm_mm = mm;
86458 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
86459 + retval = vma_dup_policy(mpnt, tmp);
86460 + if (retval)
86461 + goto fail_nomem_policy;
86462 + if (anon_vma_fork(tmp, mpnt))
86463 + goto fail_nomem_anon_vma_fork;
86464 + tmp->vm_flags &= ~VM_LOCKED;
86465 + tmp->vm_next = tmp->vm_prev = NULL;
86466 + tmp->vm_mirror = NULL;
86467 + file = tmp->vm_file;
86468 + if (file) {
86469 + struct inode *inode = file_inode(file);
86470 + struct address_space *mapping = file->f_mapping;
86471 +
86472 + get_file(file);
86473 + if (tmp->vm_flags & VM_DENYWRITE)
86474 + atomic_dec(&inode->i_writecount);
86475 + mutex_lock(&mapping->i_mmap_mutex);
86476 + if (tmp->vm_flags & VM_SHARED)
86477 + mapping->i_mmap_writable++;
86478 + flush_dcache_mmap_lock(mapping);
86479 + /* insert tmp into the share list, just after mpnt */
86480 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86481 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86482 + else
86483 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86484 + flush_dcache_mmap_unlock(mapping);
86485 + mutex_unlock(&mapping->i_mmap_mutex);
86486 + }
86487 +
86488 + /*
86489 + * Clear hugetlb-related page reserves for children. This only
86490 + * affects MAP_PRIVATE mappings. Faults generated by the child
86491 + * are not guaranteed to succeed, even if read-only
86492 + */
86493 + if (is_vm_hugetlb_page(tmp))
86494 + reset_vma_resv_huge_pages(tmp);
86495 +
86496 + return tmp;
86497 +
86498 +fail_nomem_anon_vma_fork:
86499 + mpol_put(vma_policy(tmp));
86500 +fail_nomem_policy:
86501 + kmem_cache_free(vm_area_cachep, tmp);
86502 +fail_nomem:
86503 + vm_unacct_memory(charge);
86504 + return NULL;
86505 +}
86506 +
86507 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86508 {
86509 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86510 struct rb_node **rb_link, *rb_parent;
86511 int retval;
86512 - unsigned long charge;
86513
86514 uprobe_start_dup_mmap();
86515 down_write(&oldmm->mmap_sem);
86516 @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86517
86518 prev = NULL;
86519 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86520 - struct file *file;
86521 -
86522 if (mpnt->vm_flags & VM_DONTCOPY) {
86523 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86524 -vma_pages(mpnt));
86525 continue;
86526 }
86527 - charge = 0;
86528 - if (mpnt->vm_flags & VM_ACCOUNT) {
86529 - unsigned long len = vma_pages(mpnt);
86530 -
86531 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86532 - goto fail_nomem;
86533 - charge = len;
86534 - }
86535 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86536 - if (!tmp)
86537 - goto fail_nomem;
86538 - *tmp = *mpnt;
86539 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
86540 - retval = vma_dup_policy(mpnt, tmp);
86541 - if (retval)
86542 - goto fail_nomem_policy;
86543 - tmp->vm_mm = mm;
86544 - if (anon_vma_fork(tmp, mpnt))
86545 - goto fail_nomem_anon_vma_fork;
86546 - tmp->vm_flags &= ~VM_LOCKED;
86547 - tmp->vm_next = tmp->vm_prev = NULL;
86548 - file = tmp->vm_file;
86549 - if (file) {
86550 - struct inode *inode = file_inode(file);
86551 - struct address_space *mapping = file->f_mapping;
86552 -
86553 - get_file(file);
86554 - if (tmp->vm_flags & VM_DENYWRITE)
86555 - atomic_dec(&inode->i_writecount);
86556 - mutex_lock(&mapping->i_mmap_mutex);
86557 - if (tmp->vm_flags & VM_SHARED)
86558 - mapping->i_mmap_writable++;
86559 - flush_dcache_mmap_lock(mapping);
86560 - /* insert tmp into the share list, just after mpnt */
86561 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86562 - vma_nonlinear_insert(tmp,
86563 - &mapping->i_mmap_nonlinear);
86564 - else
86565 - vma_interval_tree_insert_after(tmp, mpnt,
86566 - &mapping->i_mmap);
86567 - flush_dcache_mmap_unlock(mapping);
86568 - mutex_unlock(&mapping->i_mmap_mutex);
86569 + tmp = dup_vma(mm, oldmm, mpnt);
86570 + if (!tmp) {
86571 + retval = -ENOMEM;
86572 + goto out;
86573 }
86574
86575 /*
86576 @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86577 if (retval)
86578 goto out;
86579 }
86580 +
86581 +#ifdef CONFIG_PAX_SEGMEXEC
86582 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86583 + struct vm_area_struct *mpnt_m;
86584 +
86585 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86586 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86587 +
86588 + if (!mpnt->vm_mirror)
86589 + continue;
86590 +
86591 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86592 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86593 + mpnt->vm_mirror = mpnt_m;
86594 + } else {
86595 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86596 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86597 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86598 + mpnt->vm_mirror->vm_mirror = mpnt;
86599 + }
86600 + }
86601 + BUG_ON(mpnt_m);
86602 + }
86603 +#endif
86604 +
86605 /* a new mm has just been created */
86606 arch_dup_mmap(oldmm, mm);
86607 retval = 0;
86608 @@ -468,14 +521,6 @@ out:
86609 up_write(&oldmm->mmap_sem);
86610 uprobe_end_dup_mmap();
86611 return retval;
86612 -fail_nomem_anon_vma_fork:
86613 - mpol_put(vma_policy(tmp));
86614 -fail_nomem_policy:
86615 - kmem_cache_free(vm_area_cachep, tmp);
86616 -fail_nomem:
86617 - retval = -ENOMEM;
86618 - vm_unacct_memory(charge);
86619 - goto out;
86620 }
86621
86622 static inline int mm_alloc_pgd(struct mm_struct *mm)
86623 @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86624 return ERR_PTR(err);
86625
86626 mm = get_task_mm(task);
86627 - if (mm && mm != current->mm &&
86628 - !ptrace_may_access(task, mode)) {
86629 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86630 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86631 mmput(mm);
86632 mm = ERR_PTR(-EACCES);
86633 }
86634 @@ -906,13 +951,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86635 spin_unlock(&fs->lock);
86636 return -EAGAIN;
86637 }
86638 - fs->users++;
86639 + atomic_inc(&fs->users);
86640 spin_unlock(&fs->lock);
86641 return 0;
86642 }
86643 tsk->fs = copy_fs_struct(fs);
86644 if (!tsk->fs)
86645 return -ENOMEM;
86646 + /* Carry through gr_chroot_dentry and is_chrooted instead
86647 + of recomputing it here. Already copied when the task struct
86648 + is duplicated. This allows pivot_root to not be treated as
86649 + a chroot
86650 + */
86651 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
86652 +
86653 return 0;
86654 }
86655
86656 @@ -1130,7 +1182,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86657 * parts of the process environment (as per the clone
86658 * flags). The actual kick-off is left to the caller.
86659 */
86660 -static struct task_struct *copy_process(unsigned long clone_flags,
86661 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86662 unsigned long stack_start,
86663 unsigned long stack_size,
86664 int __user *child_tidptr,
86665 @@ -1202,6 +1254,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86666 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86667 #endif
86668 retval = -EAGAIN;
86669 +
86670 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86671 +
86672 if (atomic_read(&p->real_cred->user->processes) >=
86673 task_rlimit(p, RLIMIT_NPROC)) {
86674 if (p->real_cred->user != INIT_USER &&
86675 @@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86676 goto bad_fork_free_pid;
86677 }
86678
86679 + /* synchronizes with gr_set_acls()
86680 + we need to call this past the point of no return for fork()
86681 + */
86682 + gr_copy_label(p);
86683 +
86684 if (likely(p->pid)) {
86685 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86686
86687 @@ -1537,6 +1597,8 @@ bad_fork_cleanup_count:
86688 bad_fork_free:
86689 free_task(p);
86690 fork_out:
86691 + gr_log_forkfail(retval);
86692 +
86693 return ERR_PTR(retval);
86694 }
86695
86696 @@ -1598,6 +1660,7 @@ long do_fork(unsigned long clone_flags,
86697
86698 p = copy_process(clone_flags, stack_start, stack_size,
86699 child_tidptr, NULL, trace);
86700 + add_latent_entropy();
86701 /*
86702 * Do this prior waking up the new thread - the thread pointer
86703 * might get invalid after that point, if the thread exits quickly.
86704 @@ -1612,6 +1675,8 @@ long do_fork(unsigned long clone_flags,
86705 if (clone_flags & CLONE_PARENT_SETTID)
86706 put_user(nr, parent_tidptr);
86707
86708 + gr_handle_brute_check();
86709 +
86710 if (clone_flags & CLONE_VFORK) {
86711 p->vfork_done = &vfork;
86712 init_completion(&vfork);
86713 @@ -1728,7 +1793,7 @@ void __init proc_caches_init(void)
86714 mm_cachep = kmem_cache_create("mm_struct",
86715 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86716 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86717 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86718 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86719 mmap_init();
86720 nsproxy_cache_init();
86721 }
86722 @@ -1768,7 +1833,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86723 return 0;
86724
86725 /* don't need lock here; in the worst case we'll do useless copy */
86726 - if (fs->users == 1)
86727 + if (atomic_read(&fs->users) == 1)
86728 return 0;
86729
86730 *new_fsp = copy_fs_struct(fs);
86731 @@ -1875,7 +1940,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86732 fs = current->fs;
86733 spin_lock(&fs->lock);
86734 current->fs = new_fs;
86735 - if (--fs->users)
86736 + gr_set_chroot_entries(current, &current->fs->root);
86737 + if (atomic_dec_return(&fs->users))
86738 new_fs = NULL;
86739 else
86740 new_fs = fs;
86741 diff --git a/kernel/futex.c b/kernel/futex.c
86742 index 6801b37..bb6becca 100644
86743 --- a/kernel/futex.c
86744 +++ b/kernel/futex.c
86745 @@ -54,6 +54,7 @@
86746 #include <linux/mount.h>
86747 #include <linux/pagemap.h>
86748 #include <linux/syscalls.h>
86749 +#include <linux/ptrace.h>
86750 #include <linux/signal.h>
86751 #include <linux/export.h>
86752 #include <linux/magic.h>
86753 @@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86754 struct page *page, *page_head;
86755 int err, ro = 0;
86756
86757 +#ifdef CONFIG_PAX_SEGMEXEC
86758 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86759 + return -EFAULT;
86760 +#endif
86761 +
86762 /*
86763 * The futex address must be "naturally" aligned.
86764 */
86765 @@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86766
86767 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86768 {
86769 - int ret;
86770 + unsigned long ret;
86771
86772 pagefault_disable();
86773 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86774 @@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
86775 {
86776 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86777 u32 curval;
86778 + mm_segment_t oldfs;
86779
86780 /*
86781 * This will fail and we want it. Some arch implementations do
86782 @@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
86783 * implementation, the non-functional ones will return
86784 * -ENOSYS.
86785 */
86786 + oldfs = get_fs();
86787 + set_fs(USER_DS);
86788 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86789 futex_cmpxchg_enabled = 1;
86790 + set_fs(oldfs);
86791 #endif
86792 }
86793
86794 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86795 index f9f44fd..29885e4 100644
86796 --- a/kernel/futex_compat.c
86797 +++ b/kernel/futex_compat.c
86798 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86799 return 0;
86800 }
86801
86802 -static void __user *futex_uaddr(struct robust_list __user *entry,
86803 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86804 compat_long_t futex_offset)
86805 {
86806 compat_uptr_t base = ptr_to_compat(entry);
86807 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86808 index f45b75b..bfac6d5 100644
86809 --- a/kernel/gcov/base.c
86810 +++ b/kernel/gcov/base.c
86811 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
86812 }
86813
86814 #ifdef CONFIG_MODULES
86815 -static inline int within(void *addr, void *start, unsigned long size)
86816 -{
86817 - return ((addr >= start) && (addr < start + size));
86818 -}
86819 -
86820 /* Update list and generate events when modules are unloaded. */
86821 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86822 void *data)
86823 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86824
86825 /* Remove entries located in module from linked list. */
86826 while ((info = gcov_info_next(info))) {
86827 - if (within(info, mod->module_core, mod->core_size)) {
86828 + if (within_module_core_rw((unsigned long)info, mod)) {
86829 gcov_info_unlink(prev, info);
86830 if (gcov_events_enabled)
86831 gcov_event(GCOV_REMOVE, info);
86832 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86833 index 0909436..6037d22 100644
86834 --- a/kernel/hrtimer.c
86835 +++ b/kernel/hrtimer.c
86836 @@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
86837 local_irq_restore(flags);
86838 }
86839
86840 -static void run_hrtimer_softirq(struct softirq_action *h)
86841 +static __latent_entropy void run_hrtimer_softirq(void)
86842 {
86843 hrtimer_peek_ahead_timers();
86844 }
86845 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86846 index 55fcce6..0e4cf34 100644
86847 --- a/kernel/irq_work.c
86848 +++ b/kernel/irq_work.c
86849 @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86850 return NOTIFY_OK;
86851 }
86852
86853 -static struct notifier_block cpu_notify;
86854 +static struct notifier_block cpu_notify = {
86855 + .notifier_call = irq_work_cpu_notify,
86856 + .priority = 0,
86857 +};
86858
86859 static __init int irq_work_init_cpu_notifier(void)
86860 {
86861 - cpu_notify.notifier_call = irq_work_cpu_notify;
86862 - cpu_notify.priority = 0;
86863 register_cpu_notifier(&cpu_notify);
86864 return 0;
86865 }
86866 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86867 index 9019f15..9a3c42e 100644
86868 --- a/kernel/jump_label.c
86869 +++ b/kernel/jump_label.c
86870 @@ -14,6 +14,7 @@
86871 #include <linux/err.h>
86872 #include <linux/static_key.h>
86873 #include <linux/jump_label_ratelimit.h>
86874 +#include <linux/mm.h>
86875
86876 #ifdef HAVE_JUMP_LABEL
86877
86878 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86879
86880 size = (((unsigned long)stop - (unsigned long)start)
86881 / sizeof(struct jump_entry));
86882 + pax_open_kernel();
86883 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86884 + pax_close_kernel();
86885 }
86886
86887 static void jump_label_update(struct static_key *key, int enable);
86888 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86889 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86890 struct jump_entry *iter;
86891
86892 + pax_open_kernel();
86893 for (iter = iter_start; iter < iter_stop; iter++) {
86894 if (within_module_init(iter->code, mod))
86895 iter->code = 0;
86896 }
86897 + pax_close_kernel();
86898 }
86899
86900 static int
86901 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86902 index 3127ad5..159d880 100644
86903 --- a/kernel/kallsyms.c
86904 +++ b/kernel/kallsyms.c
86905 @@ -11,6 +11,9 @@
86906 * Changed the compression method from stem compression to "table lookup"
86907 * compression (see scripts/kallsyms.c for a more complete description)
86908 */
86909 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86910 +#define __INCLUDED_BY_HIDESYM 1
86911 +#endif
86912 #include <linux/kallsyms.h>
86913 #include <linux/module.h>
86914 #include <linux/init.h>
86915 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
86916
86917 static inline int is_kernel_inittext(unsigned long addr)
86918 {
86919 + if (system_state != SYSTEM_BOOTING)
86920 + return 0;
86921 +
86922 if (addr >= (unsigned long)_sinittext
86923 && addr <= (unsigned long)_einittext)
86924 return 1;
86925 return 0;
86926 }
86927
86928 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86929 +#ifdef CONFIG_MODULES
86930 +static inline int is_module_text(unsigned long addr)
86931 +{
86932 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86933 + return 1;
86934 +
86935 + addr = ktla_ktva(addr);
86936 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86937 +}
86938 +#else
86939 +static inline int is_module_text(unsigned long addr)
86940 +{
86941 + return 0;
86942 +}
86943 +#endif
86944 +#endif
86945 +
86946 static inline int is_kernel_text(unsigned long addr)
86947 {
86948 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86949 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86950
86951 static inline int is_kernel(unsigned long addr)
86952 {
86953 +
86954 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86955 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
86956 + return 1;
86957 +
86958 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86959 +#else
86960 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86961 +#endif
86962 +
86963 return 1;
86964 return in_gate_area_no_mm(addr);
86965 }
86966
86967 static int is_ksym_addr(unsigned long addr)
86968 {
86969 +
86970 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86971 + if (is_module_text(addr))
86972 + return 0;
86973 +#endif
86974 +
86975 if (all_var)
86976 return is_kernel(addr);
86977
86978 @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86979
86980 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86981 {
86982 - iter->name[0] = '\0';
86983 iter->nameoff = get_symbol_offset(new_pos);
86984 iter->pos = new_pos;
86985 }
86986 @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86987 {
86988 struct kallsym_iter *iter = m->private;
86989
86990 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86991 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86992 + return 0;
86993 +#endif
86994 +
86995 /* Some debugging symbols have no name. Ignore them. */
86996 if (!iter->name[0])
86997 return 0;
86998 @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86999 */
87000 type = iter->exported ? toupper(iter->type) :
87001 tolower(iter->type);
87002 +
87003 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
87004 type, iter->name, iter->module_name);
87005 } else
87006 @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
87007 struct kallsym_iter *iter;
87008 int ret;
87009
87010 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
87011 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
87012 if (!iter)
87013 return -ENOMEM;
87014 reset_iter(iter, 0);
87015 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
87016 index e30ac0f..3528cac 100644
87017 --- a/kernel/kcmp.c
87018 +++ b/kernel/kcmp.c
87019 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
87020 struct task_struct *task1, *task2;
87021 int ret;
87022
87023 +#ifdef CONFIG_GRKERNSEC
87024 + return -ENOSYS;
87025 +#endif
87026 +
87027 rcu_read_lock();
87028
87029 /*
87030 diff --git a/kernel/kexec.c b/kernel/kexec.c
87031 index 60bafbe..a120f4f 100644
87032 --- a/kernel/kexec.c
87033 +++ b/kernel/kexec.c
87034 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
87035 unsigned long flags)
87036 {
87037 struct compat_kexec_segment in;
87038 - struct kexec_segment out, __user *ksegments;
87039 + struct kexec_segment out;
87040 + struct kexec_segment __user *ksegments;
87041 unsigned long i, result;
87042
87043 /* Don't allow clients that don't understand the native
87044 diff --git a/kernel/kmod.c b/kernel/kmod.c
87045 index 6b375af..eaff670 100644
87046 --- a/kernel/kmod.c
87047 +++ b/kernel/kmod.c
87048 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
87049 kfree(info->argv);
87050 }
87051
87052 -static int call_modprobe(char *module_name, int wait)
87053 +static int call_modprobe(char *module_name, char *module_param, int wait)
87054 {
87055 struct subprocess_info *info;
87056 static char *envp[] = {
87057 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
87058 NULL
87059 };
87060
87061 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
87062 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
87063 if (!argv)
87064 goto out;
87065
87066 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
87067 argv[1] = "-q";
87068 argv[2] = "--";
87069 argv[3] = module_name; /* check free_modprobe_argv() */
87070 - argv[4] = NULL;
87071 + argv[4] = module_param;
87072 + argv[5] = NULL;
87073
87074 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87075 NULL, free_modprobe_argv, NULL);
87076 @@ -129,9 +130,8 @@ out:
87077 * If module auto-loading support is disabled then this function
87078 * becomes a no-operation.
87079 */
87080 -int __request_module(bool wait, const char *fmt, ...)
87081 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87082 {
87083 - va_list args;
87084 char module_name[MODULE_NAME_LEN];
87085 unsigned int max_modprobes;
87086 int ret;
87087 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87088 if (!modprobe_path[0])
87089 return 0;
87090
87091 - va_start(args, fmt);
87092 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87093 - va_end(args);
87094 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87095 if (ret >= MODULE_NAME_LEN)
87096 return -ENAMETOOLONG;
87097
87098 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87099 if (ret)
87100 return ret;
87101
87102 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87103 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87104 + /* hack to workaround consolekit/udisks stupidity */
87105 + read_lock(&tasklist_lock);
87106 + if (!strcmp(current->comm, "mount") &&
87107 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87108 + read_unlock(&tasklist_lock);
87109 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87110 + return -EPERM;
87111 + }
87112 + read_unlock(&tasklist_lock);
87113 + }
87114 +#endif
87115 +
87116 /* If modprobe needs a service that is in a module, we get a recursive
87117 * loop. Limit the number of running kmod threads to max_threads/2 or
87118 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87119 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87120
87121 trace_module_request(module_name, wait, _RET_IP_);
87122
87123 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87124 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87125
87126 atomic_dec(&kmod_concurrent);
87127 return ret;
87128 }
87129 +
87130 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87131 +{
87132 + va_list args;
87133 + int ret;
87134 +
87135 + va_start(args, fmt);
87136 + ret = ____request_module(wait, module_param, fmt, args);
87137 + va_end(args);
87138 +
87139 + return ret;
87140 +}
87141 +
87142 +int __request_module(bool wait, const char *fmt, ...)
87143 +{
87144 + va_list args;
87145 + int ret;
87146 +
87147 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87148 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87149 + char module_param[MODULE_NAME_LEN];
87150 +
87151 + memset(module_param, 0, sizeof(module_param));
87152 +
87153 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87154 +
87155 + va_start(args, fmt);
87156 + ret = ____request_module(wait, module_param, fmt, args);
87157 + va_end(args);
87158 +
87159 + return ret;
87160 + }
87161 +#endif
87162 +
87163 + va_start(args, fmt);
87164 + ret = ____request_module(wait, NULL, fmt, args);
87165 + va_end(args);
87166 +
87167 + return ret;
87168 +}
87169 +
87170 EXPORT_SYMBOL(__request_module);
87171 #endif /* CONFIG_MODULES */
87172
87173 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87174 */
87175 set_user_nice(current, 0);
87176
87177 +#ifdef CONFIG_GRKERNSEC
87178 + /* this is race-free as far as userland is concerned as we copied
87179 + out the path to be used prior to this point and are now operating
87180 + on that copy
87181 + */
87182 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87183 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87184 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87185 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87186 + retval = -EPERM;
87187 + goto fail;
87188 + }
87189 +#endif
87190 +
87191 retval = -ENOMEM;
87192 new = prepare_kernel_cred(current);
87193 if (!new)
87194 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87195 commit_creds(new);
87196
87197 retval = do_execve(getname_kernel(sub_info->path),
87198 - (const char __user *const __user *)sub_info->argv,
87199 - (const char __user *const __user *)sub_info->envp);
87200 + (const char __user *const __force_user *)sub_info->argv,
87201 + (const char __user *const __force_user *)sub_info->envp);
87202 if (!retval)
87203 return 0;
87204
87205 @@ -260,6 +327,10 @@ static int call_helper(void *data)
87206
87207 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87208 {
87209 +#ifdef CONFIG_GRKERNSEC
87210 + kfree(info->path);
87211 + info->path = info->origpath;
87212 +#endif
87213 if (info->cleanup)
87214 (*info->cleanup)(info);
87215 kfree(info);
87216 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87217 *
87218 * Thus the __user pointer cast is valid here.
87219 */
87220 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
87221 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87222
87223 /*
87224 * If ret is 0, either ____call_usermodehelper failed and the
87225 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87226 goto out;
87227
87228 INIT_WORK(&sub_info->work, __call_usermodehelper);
87229 +#ifdef CONFIG_GRKERNSEC
87230 + sub_info->origpath = path;
87231 + sub_info->path = kstrdup(path, gfp_mask);
87232 +#else
87233 sub_info->path = path;
87234 +#endif
87235 sub_info->argv = argv;
87236 sub_info->envp = envp;
87237
87238 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87239 static int proc_cap_handler(struct ctl_table *table, int write,
87240 void __user *buffer, size_t *lenp, loff_t *ppos)
87241 {
87242 - struct ctl_table t;
87243 + ctl_table_no_const t;
87244 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87245 kernel_cap_t new_cap;
87246 int err, i;
87247 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87248 index ceeadfc..11c18b6 100644
87249 --- a/kernel/kprobes.c
87250 +++ b/kernel/kprobes.c
87251 @@ -31,6 +31,9 @@
87252 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87253 * <prasanna@in.ibm.com> added function-return probes.
87254 */
87255 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87256 +#define __INCLUDED_BY_HIDESYM 1
87257 +#endif
87258 #include <linux/kprobes.h>
87259 #include <linux/hash.h>
87260 #include <linux/init.h>
87261 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
87262
87263 static void *alloc_insn_page(void)
87264 {
87265 - return module_alloc(PAGE_SIZE);
87266 + return module_alloc_exec(PAGE_SIZE);
87267 }
87268
87269 static void free_insn_page(void *page)
87270 {
87271 - module_free(NULL, page);
87272 + module_free_exec(NULL, page);
87273 }
87274
87275 struct kprobe_insn_cache kprobe_insn_slots = {
87276 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87277 kprobe_type = "k";
87278
87279 if (sym)
87280 - seq_printf(pi, "%p %s %s+0x%x %s ",
87281 + seq_printf(pi, "%pK %s %s+0x%x %s ",
87282 p->addr, kprobe_type, sym, offset,
87283 (modname ? modname : " "));
87284 else
87285 - seq_printf(pi, "%p %s %p ",
87286 + seq_printf(pi, "%pK %s %pK ",
87287 p->addr, kprobe_type, p->addr);
87288
87289 if (!pp)
87290 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87291 index d945a94..0b7f45f 100644
87292 --- a/kernel/ksysfs.c
87293 +++ b/kernel/ksysfs.c
87294 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87295 {
87296 if (count+1 > UEVENT_HELPER_PATH_LEN)
87297 return -ENOENT;
87298 + if (!capable(CAP_SYS_ADMIN))
87299 + return -EPERM;
87300 memcpy(uevent_helper, buf, count);
87301 uevent_helper[count] = '\0';
87302 if (count && uevent_helper[count-1] == '\n')
87303 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87304 return count;
87305 }
87306
87307 -static struct bin_attribute notes_attr = {
87308 +static bin_attribute_no_const notes_attr __read_only = {
87309 .attr = {
87310 .name = "notes",
87311 .mode = S_IRUGO,
87312 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87313 index eb8a547..321d8e1 100644
87314 --- a/kernel/locking/lockdep.c
87315 +++ b/kernel/locking/lockdep.c
87316 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
87317 end = (unsigned long) &_end,
87318 addr = (unsigned long) obj;
87319
87320 +#ifdef CONFIG_PAX_KERNEXEC
87321 + start = ktla_ktva(start);
87322 +#endif
87323 +
87324 /*
87325 * static variable?
87326 */
87327 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87328 if (!static_obj(lock->key)) {
87329 debug_locks_off();
87330 printk("INFO: trying to register non-static key.\n");
87331 + printk("lock:%pS key:%pS.\n", lock, lock->key);
87332 printk("the code is fine but needs lockdep annotation.\n");
87333 printk("turning off the locking correctness validator.\n");
87334 dump_stack();
87335 @@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87336 if (!class)
87337 return 0;
87338 }
87339 - atomic_inc((atomic_t *)&class->ops);
87340 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87341 if (very_verbose(class)) {
87342 printk("\nacquire class [%p] %s", class->key, class->name);
87343 if (class->name_version > 1)
87344 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87345 index ef43ac4..2720dfa 100644
87346 --- a/kernel/locking/lockdep_proc.c
87347 +++ b/kernel/locking/lockdep_proc.c
87348 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87349 return 0;
87350 }
87351
87352 - seq_printf(m, "%p", class->key);
87353 + seq_printf(m, "%pK", class->key);
87354 #ifdef CONFIG_DEBUG_LOCKDEP
87355 seq_printf(m, " OPS:%8ld", class->ops);
87356 #endif
87357 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87358
87359 list_for_each_entry(entry, &class->locks_after, entry) {
87360 if (entry->distance == 1) {
87361 - seq_printf(m, " -> [%p] ", entry->class->key);
87362 + seq_printf(m, " -> [%pK] ", entry->class->key);
87363 print_name(m, entry->class);
87364 seq_puts(m, "\n");
87365 }
87366 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87367 if (!class->key)
87368 continue;
87369
87370 - seq_printf(m, "[%p] ", class->key);
87371 + seq_printf(m, "[%pK] ", class->key);
87372 print_name(m, class);
87373 seq_puts(m, "\n");
87374 }
87375 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87376 if (!i)
87377 seq_line(m, '-', 40-namelen, namelen);
87378
87379 - snprintf(ip, sizeof(ip), "[<%p>]",
87380 + snprintf(ip, sizeof(ip), "[<%pK>]",
87381 (void *)class->contention_point[i]);
87382 seq_printf(m, "%40s %14lu %29s %pS\n",
87383 name, stats->contention_point[i],
87384 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87385 if (!i)
87386 seq_line(m, '-', 40-namelen, namelen);
87387
87388 - snprintf(ip, sizeof(ip), "[<%p>]",
87389 + snprintf(ip, sizeof(ip), "[<%pK>]",
87390 (void *)class->contending_point[i]);
87391 seq_printf(m, "%40s %14lu %29s %pS\n",
87392 name, stats->contending_point[i],
87393 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87394 index faf6f5b..dc9070a 100644
87395 --- a/kernel/locking/mutex-debug.c
87396 +++ b/kernel/locking/mutex-debug.c
87397 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87398 }
87399
87400 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87401 - struct thread_info *ti)
87402 + struct task_struct *task)
87403 {
87404 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87405
87406 /* Mark the current thread as blocked on the lock: */
87407 - ti->task->blocked_on = waiter;
87408 + task->blocked_on = waiter;
87409 }
87410
87411 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87412 - struct thread_info *ti)
87413 + struct task_struct *task)
87414 {
87415 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87416 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87417 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87418 - ti->task->blocked_on = NULL;
87419 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
87420 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87421 + task->blocked_on = NULL;
87422
87423 list_del_init(&waiter->list);
87424 waiter->task = NULL;
87425 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87426 index 0799fd3..d06ae3b 100644
87427 --- a/kernel/locking/mutex-debug.h
87428 +++ b/kernel/locking/mutex-debug.h
87429 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87430 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87431 extern void debug_mutex_add_waiter(struct mutex *lock,
87432 struct mutex_waiter *waiter,
87433 - struct thread_info *ti);
87434 + struct task_struct *task);
87435 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87436 - struct thread_info *ti);
87437 + struct task_struct *task);
87438 extern void debug_mutex_unlock(struct mutex *lock);
87439 extern void debug_mutex_init(struct mutex *lock, const char *name,
87440 struct lock_class_key *key);
87441 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87442 index 4dd6e4c..df52693 100644
87443 --- a/kernel/locking/mutex.c
87444 +++ b/kernel/locking/mutex.c
87445 @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
87446 node->locked = 1;
87447 return;
87448 }
87449 - ACCESS_ONCE(prev->next) = node;
87450 + ACCESS_ONCE_RW(prev->next) = node;
87451 smp_wmb();
87452 /* Wait until the lock holder passes the lock down */
87453 while (!ACCESS_ONCE(node->locked))
87454 @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
87455 while (!(next = ACCESS_ONCE(node->next)))
87456 arch_mutex_cpu_relax();
87457 }
87458 - ACCESS_ONCE(next->locked) = 1;
87459 + ACCESS_ONCE_RW(next->locked) = 1;
87460 smp_wmb();
87461 }
87462
87463 @@ -520,7 +520,7 @@ slowpath:
87464 goto skip_wait;
87465
87466 debug_mutex_lock_common(lock, &waiter);
87467 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87468 + debug_mutex_add_waiter(lock, &waiter, task);
87469
87470 /* add waiting tasks to the end of the waitqueue (FIFO): */
87471 list_add_tail(&waiter.list, &lock->wait_list);
87472 @@ -564,7 +564,7 @@ slowpath:
87473 schedule_preempt_disabled();
87474 spin_lock_mutex(&lock->wait_lock, flags);
87475 }
87476 - mutex_remove_waiter(lock, &waiter, current_thread_info());
87477 + mutex_remove_waiter(lock, &waiter, task);
87478 /* set it to 0 if there are no waiters left: */
87479 if (likely(list_empty(&lock->wait_list)))
87480 atomic_set(&lock->count, 0);
87481 @@ -601,7 +601,7 @@ skip_wait:
87482 return 0;
87483
87484 err:
87485 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87486 + mutex_remove_waiter(lock, &waiter, task);
87487 spin_unlock_mutex(&lock->wait_lock, flags);
87488 debug_mutex_free_waiter(&waiter);
87489 mutex_release(&lock->dep_map, 1, ip);
87490 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87491 index 1d96dd0..994ff19 100644
87492 --- a/kernel/locking/rtmutex-tester.c
87493 +++ b/kernel/locking/rtmutex-tester.c
87494 @@ -22,7 +22,7 @@
87495 #define MAX_RT_TEST_MUTEXES 8
87496
87497 static spinlock_t rttest_lock;
87498 -static atomic_t rttest_event;
87499 +static atomic_unchecked_t rttest_event;
87500
87501 struct test_thread_data {
87502 int opcode;
87503 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87504
87505 case RTTEST_LOCKCONT:
87506 td->mutexes[td->opdata] = 1;
87507 - td->event = atomic_add_return(1, &rttest_event);
87508 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87509 return 0;
87510
87511 case RTTEST_RESET:
87512 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87513 return 0;
87514
87515 case RTTEST_RESETEVENT:
87516 - atomic_set(&rttest_event, 0);
87517 + atomic_set_unchecked(&rttest_event, 0);
87518 return 0;
87519
87520 default:
87521 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87522 return ret;
87523
87524 td->mutexes[id] = 1;
87525 - td->event = atomic_add_return(1, &rttest_event);
87526 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87527 rt_mutex_lock(&mutexes[id]);
87528 - td->event = atomic_add_return(1, &rttest_event);
87529 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87530 td->mutexes[id] = 4;
87531 return 0;
87532
87533 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87534 return ret;
87535
87536 td->mutexes[id] = 1;
87537 - td->event = atomic_add_return(1, &rttest_event);
87538 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87539 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87540 - td->event = atomic_add_return(1, &rttest_event);
87541 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87542 td->mutexes[id] = ret ? 0 : 4;
87543 return ret ? -EINTR : 0;
87544
87545 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87546 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87547 return ret;
87548
87549 - td->event = atomic_add_return(1, &rttest_event);
87550 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87551 rt_mutex_unlock(&mutexes[id]);
87552 - td->event = atomic_add_return(1, &rttest_event);
87553 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87554 td->mutexes[id] = 0;
87555 return 0;
87556
87557 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87558 break;
87559
87560 td->mutexes[dat] = 2;
87561 - td->event = atomic_add_return(1, &rttest_event);
87562 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87563 break;
87564
87565 default:
87566 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87567 return;
87568
87569 td->mutexes[dat] = 3;
87570 - td->event = atomic_add_return(1, &rttest_event);
87571 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87572 break;
87573
87574 case RTTEST_LOCKNOWAIT:
87575 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87576 return;
87577
87578 td->mutexes[dat] = 1;
87579 - td->event = atomic_add_return(1, &rttest_event);
87580 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87581 return;
87582
87583 default:
87584 diff --git a/kernel/module.c b/kernel/module.c
87585 index d24fcf2..2af3fd9 100644
87586 --- a/kernel/module.c
87587 +++ b/kernel/module.c
87588 @@ -61,6 +61,7 @@
87589 #include <linux/pfn.h>
87590 #include <linux/bsearch.h>
87591 #include <linux/fips.h>
87592 +#include <linux/grsecurity.h>
87593 #include <uapi/linux/module.h>
87594 #include "module-internal.h"
87595
87596 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87597
87598 /* Bounds of module allocation, for speeding __module_address.
87599 * Protected by module_mutex. */
87600 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87601 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87602 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87603
87604 int register_module_notifier(struct notifier_block * nb)
87605 {
87606 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87607 return true;
87608
87609 list_for_each_entry_rcu(mod, &modules, list) {
87610 - struct symsearch arr[] = {
87611 + struct symsearch modarr[] = {
87612 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87613 NOT_GPL_ONLY, false },
87614 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87615 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87616 if (mod->state == MODULE_STATE_UNFORMED)
87617 continue;
87618
87619 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87620 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87621 return true;
87622 }
87623 return false;
87624 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87625 if (!pcpusec->sh_size)
87626 return 0;
87627
87628 - if (align > PAGE_SIZE) {
87629 + if (align-1 >= PAGE_SIZE) {
87630 pr_warn("%s: per-cpu alignment %li > %li\n",
87631 mod->name, align, PAGE_SIZE);
87632 align = PAGE_SIZE;
87633 @@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
87634 static ssize_t show_coresize(struct module_attribute *mattr,
87635 struct module_kobject *mk, char *buffer)
87636 {
87637 - return sprintf(buffer, "%u\n", mk->mod->core_size);
87638 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87639 }
87640
87641 static struct module_attribute modinfo_coresize =
87642 @@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
87643 static ssize_t show_initsize(struct module_attribute *mattr,
87644 struct module_kobject *mk, char *buffer)
87645 {
87646 - return sprintf(buffer, "%u\n", mk->mod->init_size);
87647 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87648 }
87649
87650 static struct module_attribute modinfo_initsize =
87651 @@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
87652 goto bad_version;
87653 }
87654
87655 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87656 + /*
87657 + * avoid potentially printing jibberish on attempted load
87658 + * of a module randomized with a different seed
87659 + */
87660 + pr_warn("no symbol version for %s\n", symname);
87661 +#else
87662 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87663 +#endif
87664 return 0;
87665
87666 bad_version:
87667 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87668 + /*
87669 + * avoid potentially printing jibberish on attempted load
87670 + * of a module randomized with a different seed
87671 + */
87672 + printk("attempted module disagrees about version of symbol %s\n",
87673 + symname);
87674 +#else
87675 printk("%s: disagrees about version of symbol %s\n",
87676 mod->name, symname);
87677 +#endif
87678 return 0;
87679 }
87680
87681 @@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
87682 */
87683 #ifdef CONFIG_SYSFS
87684
87685 -#ifdef CONFIG_KALLSYMS
87686 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87687 static inline bool sect_empty(const Elf_Shdr *sect)
87688 {
87689 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87690 @@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87691 {
87692 unsigned int notes, loaded, i;
87693 struct module_notes_attrs *notes_attrs;
87694 - struct bin_attribute *nattr;
87695 + bin_attribute_no_const *nattr;
87696
87697 /* failed to create section attributes, so can't create notes */
87698 if (!mod->sect_attrs)
87699 @@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
87700 static int module_add_modinfo_attrs(struct module *mod)
87701 {
87702 struct module_attribute *attr;
87703 - struct module_attribute *temp_attr;
87704 + module_attribute_no_const *temp_attr;
87705 int error = 0;
87706 int i;
87707
87708 @@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
87709
87710 static void unset_module_core_ro_nx(struct module *mod)
87711 {
87712 - set_page_attributes(mod->module_core + mod->core_text_size,
87713 - mod->module_core + mod->core_size,
87714 + set_page_attributes(mod->module_core_rw,
87715 + mod->module_core_rw + mod->core_size_rw,
87716 set_memory_x);
87717 - set_page_attributes(mod->module_core,
87718 - mod->module_core + mod->core_ro_size,
87719 + set_page_attributes(mod->module_core_rx,
87720 + mod->module_core_rx + mod->core_size_rx,
87721 set_memory_rw);
87722 }
87723
87724 static void unset_module_init_ro_nx(struct module *mod)
87725 {
87726 - set_page_attributes(mod->module_init + mod->init_text_size,
87727 - mod->module_init + mod->init_size,
87728 + set_page_attributes(mod->module_init_rw,
87729 + mod->module_init_rw + mod->init_size_rw,
87730 set_memory_x);
87731 - set_page_attributes(mod->module_init,
87732 - mod->module_init + mod->init_ro_size,
87733 + set_page_attributes(mod->module_init_rx,
87734 + mod->module_init_rx + mod->init_size_rx,
87735 set_memory_rw);
87736 }
87737
87738 @@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
87739 list_for_each_entry_rcu(mod, &modules, list) {
87740 if (mod->state == MODULE_STATE_UNFORMED)
87741 continue;
87742 - if ((mod->module_core) && (mod->core_text_size)) {
87743 - set_page_attributes(mod->module_core,
87744 - mod->module_core + mod->core_text_size,
87745 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
87746 + set_page_attributes(mod->module_core_rx,
87747 + mod->module_core_rx + mod->core_size_rx,
87748 set_memory_rw);
87749 }
87750 - if ((mod->module_init) && (mod->init_text_size)) {
87751 - set_page_attributes(mod->module_init,
87752 - mod->module_init + mod->init_text_size,
87753 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
87754 + set_page_attributes(mod->module_init_rx,
87755 + mod->module_init_rx + mod->init_size_rx,
87756 set_memory_rw);
87757 }
87758 }
87759 @@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
87760 list_for_each_entry_rcu(mod, &modules, list) {
87761 if (mod->state == MODULE_STATE_UNFORMED)
87762 continue;
87763 - if ((mod->module_core) && (mod->core_text_size)) {
87764 - set_page_attributes(mod->module_core,
87765 - mod->module_core + mod->core_text_size,
87766 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
87767 + set_page_attributes(mod->module_core_rx,
87768 + mod->module_core_rx + mod->core_size_rx,
87769 set_memory_ro);
87770 }
87771 - if ((mod->module_init) && (mod->init_text_size)) {
87772 - set_page_attributes(mod->module_init,
87773 - mod->module_init + mod->init_text_size,
87774 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
87775 + set_page_attributes(mod->module_init_rx,
87776 + mod->module_init_rx + mod->init_size_rx,
87777 set_memory_ro);
87778 }
87779 }
87780 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
87781
87782 /* This may be NULL, but that's OK */
87783 unset_module_init_ro_nx(mod);
87784 - module_free(mod, mod->module_init);
87785 + module_free(mod, mod->module_init_rw);
87786 + module_free_exec(mod, mod->module_init_rx);
87787 kfree(mod->args);
87788 percpu_modfree(mod);
87789
87790 /* Free lock-classes: */
87791 - lockdep_free_key_range(mod->module_core, mod->core_size);
87792 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87793 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87794
87795 /* Finally, free the core (containing the module structure) */
87796 unset_module_core_ro_nx(mod);
87797 - module_free(mod, mod->module_core);
87798 + module_free_exec(mod, mod->module_core_rx);
87799 + module_free(mod, mod->module_core_rw);
87800
87801 #ifdef CONFIG_MPU
87802 update_protections(current->mm);
87803 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87804 int ret = 0;
87805 const struct kernel_symbol *ksym;
87806
87807 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87808 + int is_fs_load = 0;
87809 + int register_filesystem_found = 0;
87810 + char *p;
87811 +
87812 + p = strstr(mod->args, "grsec_modharden_fs");
87813 + if (p) {
87814 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87815 + /* copy \0 as well */
87816 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87817 + is_fs_load = 1;
87818 + }
87819 +#endif
87820 +
87821 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87822 const char *name = info->strtab + sym[i].st_name;
87823
87824 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87825 + /* it's a real shame this will never get ripped and copied
87826 + upstream! ;(
87827 + */
87828 + if (is_fs_load && !strcmp(name, "register_filesystem"))
87829 + register_filesystem_found = 1;
87830 +#endif
87831 +
87832 switch (sym[i].st_shndx) {
87833 case SHN_COMMON:
87834 /* We compiled with -fno-common. These are not
87835 @@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87836 ksym = resolve_symbol_wait(mod, info, name);
87837 /* Ok if resolved. */
87838 if (ksym && !IS_ERR(ksym)) {
87839 + pax_open_kernel();
87840 sym[i].st_value = ksym->value;
87841 + pax_close_kernel();
87842 break;
87843 }
87844
87845 @@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87846 secbase = (unsigned long)mod_percpu(mod);
87847 else
87848 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87849 + pax_open_kernel();
87850 sym[i].st_value += secbase;
87851 + pax_close_kernel();
87852 break;
87853 }
87854 }
87855
87856 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87857 + if (is_fs_load && !register_filesystem_found) {
87858 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87859 + ret = -EPERM;
87860 + }
87861 +#endif
87862 +
87863 return ret;
87864 }
87865
87866 @@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87867 || s->sh_entsize != ~0UL
87868 || strstarts(sname, ".init"))
87869 continue;
87870 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87871 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87872 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87873 + else
87874 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87875 pr_debug("\t%s\n", sname);
87876 }
87877 - switch (m) {
87878 - case 0: /* executable */
87879 - mod->core_size = debug_align(mod->core_size);
87880 - mod->core_text_size = mod->core_size;
87881 - break;
87882 - case 1: /* RO: text and ro-data */
87883 - mod->core_size = debug_align(mod->core_size);
87884 - mod->core_ro_size = mod->core_size;
87885 - break;
87886 - case 3: /* whole core */
87887 - mod->core_size = debug_align(mod->core_size);
87888 - break;
87889 - }
87890 }
87891
87892 pr_debug("Init section allocation order:\n");
87893 @@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87894 || s->sh_entsize != ~0UL
87895 || !strstarts(sname, ".init"))
87896 continue;
87897 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87898 - | INIT_OFFSET_MASK);
87899 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87900 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87901 + else
87902 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87903 + s->sh_entsize |= INIT_OFFSET_MASK;
87904 pr_debug("\t%s\n", sname);
87905 }
87906 - switch (m) {
87907 - case 0: /* executable */
87908 - mod->init_size = debug_align(mod->init_size);
87909 - mod->init_text_size = mod->init_size;
87910 - break;
87911 - case 1: /* RO: text and ro-data */
87912 - mod->init_size = debug_align(mod->init_size);
87913 - mod->init_ro_size = mod->init_size;
87914 - break;
87915 - case 3: /* whole init */
87916 - mod->init_size = debug_align(mod->init_size);
87917 - break;
87918 - }
87919 }
87920 }
87921
87922 @@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87923
87924 /* Put symbol section at end of init part of module. */
87925 symsect->sh_flags |= SHF_ALLOC;
87926 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87927 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87928 info->index.sym) | INIT_OFFSET_MASK;
87929 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87930
87931 @@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87932 }
87933
87934 /* Append room for core symbols at end of core part. */
87935 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87936 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87937 - mod->core_size += strtab_size;
87938 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87939 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87940 + mod->core_size_rx += strtab_size;
87941
87942 /* Put string table section at end of init part of module. */
87943 strsect->sh_flags |= SHF_ALLOC;
87944 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87945 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87946 info->index.str) | INIT_OFFSET_MASK;
87947 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87948 }
87949 @@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87950 /* Make sure we get permanent strtab: don't use info->strtab. */
87951 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87952
87953 + pax_open_kernel();
87954 +
87955 /* Set types up while we still have access to sections. */
87956 for (i = 0; i < mod->num_symtab; i++)
87957 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87958
87959 - mod->core_symtab = dst = mod->module_core + info->symoffs;
87960 - mod->core_strtab = s = mod->module_core + info->stroffs;
87961 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87962 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87963 src = mod->symtab;
87964 for (ndst = i = 0; i < mod->num_symtab; i++) {
87965 if (i == 0 ||
87966 @@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87967 }
87968 }
87969 mod->core_num_syms = ndst;
87970 +
87971 + pax_close_kernel();
87972 }
87973 #else
87974 static inline void layout_symtab(struct module *mod, struct load_info *info)
87975 @@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
87976 return vmalloc_exec(size);
87977 }
87978
87979 -static void *module_alloc_update_bounds(unsigned long size)
87980 +static void *module_alloc_update_bounds_rw(unsigned long size)
87981 {
87982 void *ret = module_alloc(size);
87983
87984 if (ret) {
87985 mutex_lock(&module_mutex);
87986 /* Update module bounds. */
87987 - if ((unsigned long)ret < module_addr_min)
87988 - module_addr_min = (unsigned long)ret;
87989 - if ((unsigned long)ret + size > module_addr_max)
87990 - module_addr_max = (unsigned long)ret + size;
87991 + if ((unsigned long)ret < module_addr_min_rw)
87992 + module_addr_min_rw = (unsigned long)ret;
87993 + if ((unsigned long)ret + size > module_addr_max_rw)
87994 + module_addr_max_rw = (unsigned long)ret + size;
87995 + mutex_unlock(&module_mutex);
87996 + }
87997 + return ret;
87998 +}
87999 +
88000 +static void *module_alloc_update_bounds_rx(unsigned long size)
88001 +{
88002 + void *ret = module_alloc_exec(size);
88003 +
88004 + if (ret) {
88005 + mutex_lock(&module_mutex);
88006 + /* Update module bounds. */
88007 + if ((unsigned long)ret < module_addr_min_rx)
88008 + module_addr_min_rx = (unsigned long)ret;
88009 + if ((unsigned long)ret + size > module_addr_max_rx)
88010 + module_addr_max_rx = (unsigned long)ret + size;
88011 mutex_unlock(&module_mutex);
88012 }
88013 return ret;
88014 @@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88015 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
88016
88017 if (info->index.sym == 0) {
88018 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88019 + /*
88020 + * avoid potentially printing jibberish on attempted load
88021 + * of a module randomized with a different seed
88022 + */
88023 + pr_warn("module has no symbols (stripped?)\n");
88024 +#else
88025 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
88026 +#endif
88027 return ERR_PTR(-ENOEXEC);
88028 }
88029
88030 @@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88031 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88032 {
88033 const char *modmagic = get_modinfo(info, "vermagic");
88034 + const char *license = get_modinfo(info, "license");
88035 int err;
88036
88037 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
88038 + if (!license || !license_is_gpl_compatible(license))
88039 + return -ENOEXEC;
88040 +#endif
88041 +
88042 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
88043 modmagic = NULL;
88044
88045 @@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88046 }
88047
88048 /* Set up license info based on the info section */
88049 - set_license(mod, get_modinfo(info, "license"));
88050 + set_license(mod, license);
88051
88052 return 0;
88053 }
88054 @@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
88055 void *ptr;
88056
88057 /* Do the allocs. */
88058 - ptr = module_alloc_update_bounds(mod->core_size);
88059 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
88060 /*
88061 * The pointer to this block is stored in the module structure
88062 * which is inside the block. Just mark it as not being a
88063 @@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
88064 if (!ptr)
88065 return -ENOMEM;
88066
88067 - memset(ptr, 0, mod->core_size);
88068 - mod->module_core = ptr;
88069 + memset(ptr, 0, mod->core_size_rw);
88070 + mod->module_core_rw = ptr;
88071
88072 - if (mod->init_size) {
88073 - ptr = module_alloc_update_bounds(mod->init_size);
88074 + if (mod->init_size_rw) {
88075 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88076 /*
88077 * The pointer to this block is stored in the module structure
88078 * which is inside the block. This block doesn't need to be
88079 @@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
88080 */
88081 kmemleak_ignore(ptr);
88082 if (!ptr) {
88083 - module_free(mod, mod->module_core);
88084 + module_free(mod, mod->module_core_rw);
88085 return -ENOMEM;
88086 }
88087 - memset(ptr, 0, mod->init_size);
88088 - mod->module_init = ptr;
88089 + memset(ptr, 0, mod->init_size_rw);
88090 + mod->module_init_rw = ptr;
88091 } else
88092 - mod->module_init = NULL;
88093 + mod->module_init_rw = NULL;
88094 +
88095 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88096 + kmemleak_not_leak(ptr);
88097 + if (!ptr) {
88098 + if (mod->module_init_rw)
88099 + module_free(mod, mod->module_init_rw);
88100 + module_free(mod, mod->module_core_rw);
88101 + return -ENOMEM;
88102 + }
88103 +
88104 + pax_open_kernel();
88105 + memset(ptr, 0, mod->core_size_rx);
88106 + pax_close_kernel();
88107 + mod->module_core_rx = ptr;
88108 +
88109 + if (mod->init_size_rx) {
88110 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88111 + kmemleak_ignore(ptr);
88112 + if (!ptr && mod->init_size_rx) {
88113 + module_free_exec(mod, mod->module_core_rx);
88114 + if (mod->module_init_rw)
88115 + module_free(mod, mod->module_init_rw);
88116 + module_free(mod, mod->module_core_rw);
88117 + return -ENOMEM;
88118 + }
88119 +
88120 + pax_open_kernel();
88121 + memset(ptr, 0, mod->init_size_rx);
88122 + pax_close_kernel();
88123 + mod->module_init_rx = ptr;
88124 + } else
88125 + mod->module_init_rx = NULL;
88126
88127 /* Transfer each section which specifies SHF_ALLOC */
88128 pr_debug("final section addresses:\n");
88129 @@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
88130 if (!(shdr->sh_flags & SHF_ALLOC))
88131 continue;
88132
88133 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
88134 - dest = mod->module_init
88135 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88136 - else
88137 - dest = mod->module_core + shdr->sh_entsize;
88138 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88139 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88140 + dest = mod->module_init_rw
88141 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88142 + else
88143 + dest = mod->module_init_rx
88144 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88145 + } else {
88146 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88147 + dest = mod->module_core_rw + shdr->sh_entsize;
88148 + else
88149 + dest = mod->module_core_rx + shdr->sh_entsize;
88150 + }
88151 +
88152 + if (shdr->sh_type != SHT_NOBITS) {
88153 +
88154 +#ifdef CONFIG_PAX_KERNEXEC
88155 +#ifdef CONFIG_X86_64
88156 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88157 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88158 +#endif
88159 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88160 + pax_open_kernel();
88161 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88162 + pax_close_kernel();
88163 + } else
88164 +#endif
88165
88166 - if (shdr->sh_type != SHT_NOBITS)
88167 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88168 + }
88169 /* Update sh_addr to point to copy in image. */
88170 - shdr->sh_addr = (unsigned long)dest;
88171 +
88172 +#ifdef CONFIG_PAX_KERNEXEC
88173 + if (shdr->sh_flags & SHF_EXECINSTR)
88174 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
88175 + else
88176 +#endif
88177 +
88178 + shdr->sh_addr = (unsigned long)dest;
88179 pr_debug("\t0x%lx %s\n",
88180 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88181 }
88182 @@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
88183 * Do it before processing of module parameters, so the module
88184 * can provide parameter accessor functions of its own.
88185 */
88186 - if (mod->module_init)
88187 - flush_icache_range((unsigned long)mod->module_init,
88188 - (unsigned long)mod->module_init
88189 - + mod->init_size);
88190 - flush_icache_range((unsigned long)mod->module_core,
88191 - (unsigned long)mod->module_core + mod->core_size);
88192 + if (mod->module_init_rx)
88193 + flush_icache_range((unsigned long)mod->module_init_rx,
88194 + (unsigned long)mod->module_init_rx
88195 + + mod->init_size_rx);
88196 + flush_icache_range((unsigned long)mod->module_core_rx,
88197 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
88198
88199 set_fs(old_fs);
88200 }
88201 @@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88202 static void module_deallocate(struct module *mod, struct load_info *info)
88203 {
88204 percpu_modfree(mod);
88205 - module_free(mod, mod->module_init);
88206 - module_free(mod, mod->module_core);
88207 + module_free_exec(mod, mod->module_init_rx);
88208 + module_free_exec(mod, mod->module_core_rx);
88209 + module_free(mod, mod->module_init_rw);
88210 + module_free(mod, mod->module_core_rw);
88211 }
88212
88213 int __weak module_finalize(const Elf_Ehdr *hdr,
88214 @@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88215 static int post_relocation(struct module *mod, const struct load_info *info)
88216 {
88217 /* Sort exception table now relocations are done. */
88218 + pax_open_kernel();
88219 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88220 + pax_close_kernel();
88221
88222 /* Copy relocated percpu area over. */
88223 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88224 @@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
88225 MODULE_STATE_COMING, mod);
88226
88227 /* Set RO and NX regions for core */
88228 - set_section_ro_nx(mod->module_core,
88229 - mod->core_text_size,
88230 - mod->core_ro_size,
88231 - mod->core_size);
88232 + set_section_ro_nx(mod->module_core_rx,
88233 + mod->core_size_rx,
88234 + mod->core_size_rx,
88235 + mod->core_size_rx);
88236
88237 /* Set RO and NX regions for init */
88238 - set_section_ro_nx(mod->module_init,
88239 - mod->init_text_size,
88240 - mod->init_ro_size,
88241 - mod->init_size);
88242 + set_section_ro_nx(mod->module_init_rx,
88243 + mod->init_size_rx,
88244 + mod->init_size_rx,
88245 + mod->init_size_rx);
88246
88247 do_mod_ctors(mod);
88248 /* Start the module */
88249 @@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
88250 mod->strtab = mod->core_strtab;
88251 #endif
88252 unset_module_init_ro_nx(mod);
88253 - module_free(mod, mod->module_init);
88254 - mod->module_init = NULL;
88255 - mod->init_size = 0;
88256 - mod->init_ro_size = 0;
88257 - mod->init_text_size = 0;
88258 + module_free(mod, mod->module_init_rw);
88259 + module_free_exec(mod, mod->module_init_rx);
88260 + mod->module_init_rw = NULL;
88261 + mod->module_init_rx = NULL;
88262 + mod->init_size_rw = 0;
88263 + mod->init_size_rx = 0;
88264 mutex_unlock(&module_mutex);
88265 wake_up_all(&module_wq);
88266
88267 @@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88268 if (err)
88269 goto free_unload;
88270
88271 + /* Now copy in args */
88272 + mod->args = strndup_user(uargs, ~0UL >> 1);
88273 + if (IS_ERR(mod->args)) {
88274 + err = PTR_ERR(mod->args);
88275 + goto free_unload;
88276 + }
88277 +
88278 /* Set up MODINFO_ATTR fields */
88279 setup_modinfo(mod, info);
88280
88281 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88282 + {
88283 + char *p, *p2;
88284 +
88285 + if (strstr(mod->args, "grsec_modharden_netdev")) {
88286 + 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);
88287 + err = -EPERM;
88288 + goto free_modinfo;
88289 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88290 + p += sizeof("grsec_modharden_normal") - 1;
88291 + p2 = strstr(p, "_");
88292 + if (p2) {
88293 + *p2 = '\0';
88294 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88295 + *p2 = '_';
88296 + }
88297 + err = -EPERM;
88298 + goto free_modinfo;
88299 + }
88300 + }
88301 +#endif
88302 +
88303 /* Fix up syms, so that st_value is a pointer to location. */
88304 err = simplify_symbols(mod, info);
88305 if (err < 0)
88306 @@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88307
88308 flush_module_icache(mod);
88309
88310 - /* Now copy in args */
88311 - mod->args = strndup_user(uargs, ~0UL >> 1);
88312 - if (IS_ERR(mod->args)) {
88313 - err = PTR_ERR(mod->args);
88314 - goto free_arch_cleanup;
88315 - }
88316 -
88317 dynamic_debug_setup(info->debug, info->num_debug);
88318
88319 /* Finally it's fully formed, ready to start executing. */
88320 @@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88321 ddebug_cleanup:
88322 dynamic_debug_remove(info->debug);
88323 synchronize_sched();
88324 - kfree(mod->args);
88325 - free_arch_cleanup:
88326 module_arch_cleanup(mod);
88327 free_modinfo:
88328 free_modinfo(mod);
88329 + kfree(mod->args);
88330 free_unload:
88331 module_unload_free(mod);
88332 unlink_mod:
88333 @@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
88334 unsigned long nextval;
88335
88336 /* At worse, next value is at end of module */
88337 - if (within_module_init(addr, mod))
88338 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
88339 + if (within_module_init_rx(addr, mod))
88340 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88341 + else if (within_module_init_rw(addr, mod))
88342 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88343 + else if (within_module_core_rx(addr, mod))
88344 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88345 + else if (within_module_core_rw(addr, mod))
88346 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88347 else
88348 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
88349 + return NULL;
88350
88351 /* Scan for closest preceding symbol, and next symbol. (ELF
88352 starts real symbols at 1). */
88353 @@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
88354 return 0;
88355
88356 seq_printf(m, "%s %u",
88357 - mod->name, mod->init_size + mod->core_size);
88358 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88359 print_unload_info(m, mod);
88360
88361 /* Informative for users. */
88362 @@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
88363 mod->state == MODULE_STATE_COMING ? "Loading":
88364 "Live");
88365 /* Used by oprofile and other similar tools. */
88366 - seq_printf(m, " 0x%pK", mod->module_core);
88367 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88368
88369 /* Taints info */
88370 if (mod->taints)
88371 @@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
88372
88373 static int __init proc_modules_init(void)
88374 {
88375 +#ifndef CONFIG_GRKERNSEC_HIDESYM
88376 +#ifdef CONFIG_GRKERNSEC_PROC_USER
88377 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88378 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88379 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88380 +#else
88381 proc_create("modules", 0, NULL, &proc_modules_operations);
88382 +#endif
88383 +#else
88384 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88385 +#endif
88386 return 0;
88387 }
88388 module_init(proc_modules_init);
88389 @@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
88390 {
88391 struct module *mod;
88392
88393 - if (addr < module_addr_min || addr > module_addr_max)
88394 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88395 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
88396 return NULL;
88397
88398 list_for_each_entry_rcu(mod, &modules, list) {
88399 if (mod->state == MODULE_STATE_UNFORMED)
88400 continue;
88401 - if (within_module_core(addr, mod)
88402 - || within_module_init(addr, mod))
88403 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
88404 return mod;
88405 }
88406 return NULL;
88407 @@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
88408 */
88409 struct module *__module_text_address(unsigned long addr)
88410 {
88411 - struct module *mod = __module_address(addr);
88412 + struct module *mod;
88413 +
88414 +#ifdef CONFIG_X86_32
88415 + addr = ktla_ktva(addr);
88416 +#endif
88417 +
88418 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88419 + return NULL;
88420 +
88421 + mod = __module_address(addr);
88422 +
88423 if (mod) {
88424 /* Make sure it's within the text section. */
88425 - if (!within(addr, mod->module_init, mod->init_text_size)
88426 - && !within(addr, mod->module_core, mod->core_text_size))
88427 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88428 mod = NULL;
88429 }
88430 return mod;
88431 diff --git a/kernel/notifier.c b/kernel/notifier.c
88432 index 2d5cc4c..d9ea600 100644
88433 --- a/kernel/notifier.c
88434 +++ b/kernel/notifier.c
88435 @@ -5,6 +5,7 @@
88436 #include <linux/rcupdate.h>
88437 #include <linux/vmalloc.h>
88438 #include <linux/reboot.h>
88439 +#include <linux/mm.h>
88440
88441 /*
88442 * Notifier list for kernel code which wants to be called
88443 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88444 while ((*nl) != NULL) {
88445 if (n->priority > (*nl)->priority)
88446 break;
88447 - nl = &((*nl)->next);
88448 + nl = (struct notifier_block **)&((*nl)->next);
88449 }
88450 - n->next = *nl;
88451 + pax_open_kernel();
88452 + *(const void **)&n->next = *nl;
88453 rcu_assign_pointer(*nl, n);
88454 + pax_close_kernel();
88455 return 0;
88456 }
88457
88458 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88459 return 0;
88460 if (n->priority > (*nl)->priority)
88461 break;
88462 - nl = &((*nl)->next);
88463 + nl = (struct notifier_block **)&((*nl)->next);
88464 }
88465 - n->next = *nl;
88466 + pax_open_kernel();
88467 + *(const void **)&n->next = *nl;
88468 rcu_assign_pointer(*nl, n);
88469 + pax_close_kernel();
88470 return 0;
88471 }
88472
88473 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88474 {
88475 while ((*nl) != NULL) {
88476 if ((*nl) == n) {
88477 + pax_open_kernel();
88478 rcu_assign_pointer(*nl, n->next);
88479 + pax_close_kernel();
88480 return 0;
88481 }
88482 - nl = &((*nl)->next);
88483 + nl = (struct notifier_block **)&((*nl)->next);
88484 }
88485 return -ENOENT;
88486 }
88487 diff --git a/kernel/padata.c b/kernel/padata.c
88488 index 161402f..598814c 100644
88489 --- a/kernel/padata.c
88490 +++ b/kernel/padata.c
88491 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88492 * seq_nr mod. number of cpus in use.
88493 */
88494
88495 - seq_nr = atomic_inc_return(&pd->seq_nr);
88496 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88497 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88498
88499 return padata_index_to_cpu(pd, cpu_index);
88500 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88501 padata_init_pqueues(pd);
88502 padata_init_squeues(pd);
88503 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88504 - atomic_set(&pd->seq_nr, -1);
88505 + atomic_set_unchecked(&pd->seq_nr, -1);
88506 atomic_set(&pd->reorder_objects, 0);
88507 atomic_set(&pd->refcnt, 0);
88508 pd->pinst = pinst;
88509 diff --git a/kernel/panic.c b/kernel/panic.c
88510 index 6d63003..486a109 100644
88511 --- a/kernel/panic.c
88512 +++ b/kernel/panic.c
88513 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88514 /*
88515 * Stop ourself in panic -- architecture code may override this
88516 */
88517 -void __weak panic_smp_self_stop(void)
88518 +void __weak __noreturn panic_smp_self_stop(void)
88519 {
88520 while (1)
88521 cpu_relax();
88522 @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88523 disable_trace_on_warning();
88524
88525 pr_warn("------------[ cut here ]------------\n");
88526 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88527 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88528 raw_smp_processor_id(), current->pid, file, line, caller);
88529
88530 if (args)
88531 @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88532 */
88533 void __stack_chk_fail(void)
88534 {
88535 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
88536 + dump_stack();
88537 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88538 __builtin_return_address(0));
88539 }
88540 EXPORT_SYMBOL(__stack_chk_fail);
88541 diff --git a/kernel/pid.c b/kernel/pid.c
88542 index 9b9a266..c20ef80 100644
88543 --- a/kernel/pid.c
88544 +++ b/kernel/pid.c
88545 @@ -33,6 +33,7 @@
88546 #include <linux/rculist.h>
88547 #include <linux/bootmem.h>
88548 #include <linux/hash.h>
88549 +#include <linux/security.h>
88550 #include <linux/pid_namespace.h>
88551 #include <linux/init_task.h>
88552 #include <linux/syscalls.h>
88553 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88554
88555 int pid_max = PID_MAX_DEFAULT;
88556
88557 -#define RESERVED_PIDS 300
88558 +#define RESERVED_PIDS 500
88559
88560 int pid_max_min = RESERVED_PIDS + 1;
88561 int pid_max_max = PID_MAX_LIMIT;
88562 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88563 */
88564 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88565 {
88566 + struct task_struct *task;
88567 +
88568 rcu_lockdep_assert(rcu_read_lock_held(),
88569 "find_task_by_pid_ns() needs rcu_read_lock()"
88570 " protection");
88571 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88572 +
88573 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88574 +
88575 + if (gr_pid_is_chrooted(task))
88576 + return NULL;
88577 +
88578 + return task;
88579 }
88580
88581 struct task_struct *find_task_by_vpid(pid_t vnr)
88582 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88583 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88584 }
88585
88586 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88587 +{
88588 + rcu_lockdep_assert(rcu_read_lock_held(),
88589 + "find_task_by_pid_ns() needs rcu_read_lock()"
88590 + " protection");
88591 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88592 +}
88593 +
88594 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88595 {
88596 struct pid *pid;
88597 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88598 index db95d8e..a0ca23f 100644
88599 --- a/kernel/pid_namespace.c
88600 +++ b/kernel/pid_namespace.c
88601 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88602 void __user *buffer, size_t *lenp, loff_t *ppos)
88603 {
88604 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88605 - struct ctl_table tmp = *table;
88606 + ctl_table_no_const tmp = *table;
88607
88608 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88609 return -EPERM;
88610 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88611 index 3b89464..5e38379 100644
88612 --- a/kernel/posix-cpu-timers.c
88613 +++ b/kernel/posix-cpu-timers.c
88614 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88615
88616 static __init int init_posix_cpu_timers(void)
88617 {
88618 - struct k_clock process = {
88619 + static struct k_clock process = {
88620 .clock_getres = process_cpu_clock_getres,
88621 .clock_get = process_cpu_clock_get,
88622 .timer_create = process_cpu_timer_create,
88623 .nsleep = process_cpu_nsleep,
88624 .nsleep_restart = process_cpu_nsleep_restart,
88625 };
88626 - struct k_clock thread = {
88627 + static struct k_clock thread = {
88628 .clock_getres = thread_cpu_clock_getres,
88629 .clock_get = thread_cpu_clock_get,
88630 .timer_create = thread_cpu_timer_create,
88631 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88632 index 424c2d4..679242f 100644
88633 --- a/kernel/posix-timers.c
88634 +++ b/kernel/posix-timers.c
88635 @@ -43,6 +43,7 @@
88636 #include <linux/hash.h>
88637 #include <linux/posix-clock.h>
88638 #include <linux/posix-timers.h>
88639 +#include <linux/grsecurity.h>
88640 #include <linux/syscalls.h>
88641 #include <linux/wait.h>
88642 #include <linux/workqueue.h>
88643 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88644 * which we beg off on and pass to do_sys_settimeofday().
88645 */
88646
88647 -static struct k_clock posix_clocks[MAX_CLOCKS];
88648 +static struct k_clock *posix_clocks[MAX_CLOCKS];
88649
88650 /*
88651 * These ones are defined below.
88652 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88653 */
88654 static __init int init_posix_timers(void)
88655 {
88656 - struct k_clock clock_realtime = {
88657 + static struct k_clock clock_realtime = {
88658 .clock_getres = hrtimer_get_res,
88659 .clock_get = posix_clock_realtime_get,
88660 .clock_set = posix_clock_realtime_set,
88661 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88662 .timer_get = common_timer_get,
88663 .timer_del = common_timer_del,
88664 };
88665 - struct k_clock clock_monotonic = {
88666 + static struct k_clock clock_monotonic = {
88667 .clock_getres = hrtimer_get_res,
88668 .clock_get = posix_ktime_get_ts,
88669 .nsleep = common_nsleep,
88670 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88671 .timer_get = common_timer_get,
88672 .timer_del = common_timer_del,
88673 };
88674 - struct k_clock clock_monotonic_raw = {
88675 + static struct k_clock clock_monotonic_raw = {
88676 .clock_getres = hrtimer_get_res,
88677 .clock_get = posix_get_monotonic_raw,
88678 };
88679 - struct k_clock clock_realtime_coarse = {
88680 + static struct k_clock clock_realtime_coarse = {
88681 .clock_getres = posix_get_coarse_res,
88682 .clock_get = posix_get_realtime_coarse,
88683 };
88684 - struct k_clock clock_monotonic_coarse = {
88685 + static struct k_clock clock_monotonic_coarse = {
88686 .clock_getres = posix_get_coarse_res,
88687 .clock_get = posix_get_monotonic_coarse,
88688 };
88689 - struct k_clock clock_tai = {
88690 + static struct k_clock clock_tai = {
88691 .clock_getres = hrtimer_get_res,
88692 .clock_get = posix_get_tai,
88693 .nsleep = common_nsleep,
88694 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88695 .timer_get = common_timer_get,
88696 .timer_del = common_timer_del,
88697 };
88698 - struct k_clock clock_boottime = {
88699 + static struct k_clock clock_boottime = {
88700 .clock_getres = hrtimer_get_res,
88701 .clock_get = posix_get_boottime,
88702 .nsleep = common_nsleep,
88703 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88704 return;
88705 }
88706
88707 - posix_clocks[clock_id] = *new_clock;
88708 + posix_clocks[clock_id] = new_clock;
88709 }
88710 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88711
88712 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88713 return (id & CLOCKFD_MASK) == CLOCKFD ?
88714 &clock_posix_dynamic : &clock_posix_cpu;
88715
88716 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88717 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88718 return NULL;
88719 - return &posix_clocks[id];
88720 + return posix_clocks[id];
88721 }
88722
88723 static int common_timer_create(struct k_itimer *new_timer)
88724 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88725 struct k_clock *kc = clockid_to_kclock(which_clock);
88726 struct k_itimer *new_timer;
88727 int error, new_timer_id;
88728 - sigevent_t event;
88729 + sigevent_t event = { };
88730 int it_id_set = IT_ID_NOT_SET;
88731
88732 if (!kc)
88733 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88734 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88735 return -EFAULT;
88736
88737 + /* only the CLOCK_REALTIME clock can be set, all other clocks
88738 + have their clock_set fptr set to a nosettime dummy function
88739 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88740 + call common_clock_set, which calls do_sys_settimeofday, which
88741 + we hook
88742 + */
88743 +
88744 return kc->clock_set(which_clock, &new_tp);
88745 }
88746
88747 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88748 index 2fac9cc..56fef29 100644
88749 --- a/kernel/power/Kconfig
88750 +++ b/kernel/power/Kconfig
88751 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88752 config HIBERNATION
88753 bool "Hibernation (aka 'suspend to disk')"
88754 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88755 + depends on !GRKERNSEC_KMEM
88756 + depends on !PAX_MEMORY_SANITIZE
88757 select HIBERNATE_CALLBACKS
88758 select LZO_COMPRESS
88759 select LZO_DECOMPRESS
88760 diff --git a/kernel/power/process.c b/kernel/power/process.c
88761 index 06ec886..9dba35e 100644
88762 --- a/kernel/power/process.c
88763 +++ b/kernel/power/process.c
88764 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88765 unsigned int elapsed_msecs;
88766 bool wakeup = false;
88767 int sleep_usecs = USEC_PER_MSEC;
88768 + bool timedout = false;
88769
88770 do_gettimeofday(&start);
88771
88772 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88773
88774 while (true) {
88775 todo = 0;
88776 + if (time_after(jiffies, end_time))
88777 + timedout = true;
88778 read_lock(&tasklist_lock);
88779 do_each_thread(g, p) {
88780 if (p == current || !freeze_task(p))
88781 continue;
88782
88783 - if (!freezer_should_skip(p))
88784 + if (!freezer_should_skip(p)) {
88785 todo++;
88786 + if (timedout) {
88787 + printk(KERN_ERR "Task refusing to freeze:\n");
88788 + sched_show_task(p);
88789 + }
88790 + }
88791 } while_each_thread(g, p);
88792 read_unlock(&tasklist_lock);
88793
88794 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88795 todo += wq_busy;
88796 }
88797
88798 - if (!todo || time_after(jiffies, end_time))
88799 + if (!todo || timedout)
88800 break;
88801
88802 if (pm_wakeup_pending()) {
88803 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88804 index 4dae9cb..039ffbb 100644
88805 --- a/kernel/printk/printk.c
88806 +++ b/kernel/printk/printk.c
88807 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88808 if (from_file && type != SYSLOG_ACTION_OPEN)
88809 return 0;
88810
88811 +#ifdef CONFIG_GRKERNSEC_DMESG
88812 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88813 + return -EPERM;
88814 +#endif
88815 +
88816 if (syslog_action_restricted(type)) {
88817 if (capable(CAP_SYSLOG))
88818 return 0;
88819 diff --git a/kernel/profile.c b/kernel/profile.c
88820 index ebdd9c1..612ee05 100644
88821 --- a/kernel/profile.c
88822 +++ b/kernel/profile.c
88823 @@ -37,7 +37,7 @@ struct profile_hit {
88824 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88825 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88826
88827 -static atomic_t *prof_buffer;
88828 +static atomic_unchecked_t *prof_buffer;
88829 static unsigned long prof_len, prof_shift;
88830
88831 int prof_on __read_mostly;
88832 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88833 hits[i].pc = 0;
88834 continue;
88835 }
88836 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88837 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88838 hits[i].hits = hits[i].pc = 0;
88839 }
88840 }
88841 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88842 * Add the current hit(s) and flush the write-queue out
88843 * to the global buffer:
88844 */
88845 - atomic_add(nr_hits, &prof_buffer[pc]);
88846 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88847 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88848 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88849 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88850 hits[i].pc = hits[i].hits = 0;
88851 }
88852 out:
88853 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88854 {
88855 unsigned long pc;
88856 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88857 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88858 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88859 }
88860 #endif /* !CONFIG_SMP */
88861
88862 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88863 return -EFAULT;
88864 buf++; p++; count--; read++;
88865 }
88866 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88867 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88868 if (copy_to_user(buf, (void *)pnt, count))
88869 return -EFAULT;
88870 read += count;
88871 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88872 }
88873 #endif
88874 profile_discard_flip_buffers();
88875 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88876 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88877 return count;
88878 }
88879
88880 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88881 index 1f4bcb3..99cf7ab 100644
88882 --- a/kernel/ptrace.c
88883 +++ b/kernel/ptrace.c
88884 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88885 if (seize)
88886 flags |= PT_SEIZED;
88887 rcu_read_lock();
88888 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88889 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88890 flags |= PT_PTRACE_CAP;
88891 rcu_read_unlock();
88892 task->ptrace = flags;
88893 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88894 break;
88895 return -EIO;
88896 }
88897 - if (copy_to_user(dst, buf, retval))
88898 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88899 return -EFAULT;
88900 copied += retval;
88901 src += retval;
88902 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88903 bool seized = child->ptrace & PT_SEIZED;
88904 int ret = -EIO;
88905 siginfo_t siginfo, *si;
88906 - void __user *datavp = (void __user *) data;
88907 + void __user *datavp = (__force void __user *) data;
88908 unsigned long __user *datalp = datavp;
88909 unsigned long flags;
88910
88911 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88912 goto out;
88913 }
88914
88915 + if (gr_handle_ptrace(child, request)) {
88916 + ret = -EPERM;
88917 + goto out_put_task_struct;
88918 + }
88919 +
88920 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88921 ret = ptrace_attach(child, request, addr, data);
88922 /*
88923 * Some architectures need to do book-keeping after
88924 * a ptrace attach.
88925 */
88926 - if (!ret)
88927 + if (!ret) {
88928 arch_ptrace_attach(child);
88929 + gr_audit_ptrace(child);
88930 + }
88931 goto out_put_task_struct;
88932 }
88933
88934 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88935 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88936 if (copied != sizeof(tmp))
88937 return -EIO;
88938 - return put_user(tmp, (unsigned long __user *)data);
88939 + return put_user(tmp, (__force unsigned long __user *)data);
88940 }
88941
88942 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88943 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88944 }
88945
88946 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88947 - compat_long_t addr, compat_long_t data)
88948 + compat_ulong_t addr, compat_ulong_t data)
88949 {
88950 struct task_struct *child;
88951 long ret;
88952 @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88953 goto out;
88954 }
88955
88956 + if (gr_handle_ptrace(child, request)) {
88957 + ret = -EPERM;
88958 + goto out_put_task_struct;
88959 + }
88960 +
88961 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88962 ret = ptrace_attach(child, request, addr, data);
88963 /*
88964 * Some architectures need to do book-keeping after
88965 * a ptrace attach.
88966 */
88967 - if (!ret)
88968 + if (!ret) {
88969 arch_ptrace_attach(child);
88970 + gr_audit_ptrace(child);
88971 + }
88972 goto out_put_task_struct;
88973 }
88974
88975 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88976 index 3318d82..1a5b2d1 100644
88977 --- a/kernel/rcu/srcu.c
88978 +++ b/kernel/rcu/srcu.c
88979 @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88980
88981 idx = ACCESS_ONCE(sp->completed) & 0x1;
88982 preempt_disable();
88983 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88984 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88985 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88986 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88987 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88988 preempt_enable();
88989 return idx;
88990 }
88991 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88992 index 1254f31..16258dc 100644
88993 --- a/kernel/rcu/tiny.c
88994 +++ b/kernel/rcu/tiny.c
88995 @@ -46,7 +46,7 @@
88996 /* Forward declarations for tiny_plugin.h. */
88997 struct rcu_ctrlblk;
88998 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88999 -static void rcu_process_callbacks(struct softirq_action *unused);
89000 +static void rcu_process_callbacks(void);
89001 static void __call_rcu(struct rcu_head *head,
89002 void (*func)(struct rcu_head *rcu),
89003 struct rcu_ctrlblk *rcp);
89004 @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89005 false));
89006 }
89007
89008 -static void rcu_process_callbacks(struct softirq_action *unused)
89009 +static __latent_entropy void rcu_process_callbacks(void)
89010 {
89011 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89012 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89013 diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
89014 index 732f8ae..42c1919 100644
89015 --- a/kernel/rcu/torture.c
89016 +++ b/kernel/rcu/torture.c
89017 @@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
89018 { 0 };
89019 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
89020 { 0 };
89021 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89022 -static atomic_t n_rcu_torture_alloc;
89023 -static atomic_t n_rcu_torture_alloc_fail;
89024 -static atomic_t n_rcu_torture_free;
89025 -static atomic_t n_rcu_torture_mberror;
89026 -static atomic_t n_rcu_torture_error;
89027 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89028 +static atomic_unchecked_t n_rcu_torture_alloc;
89029 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
89030 +static atomic_unchecked_t n_rcu_torture_free;
89031 +static atomic_unchecked_t n_rcu_torture_mberror;
89032 +static atomic_unchecked_t n_rcu_torture_error;
89033 static long n_rcu_torture_barrier_error;
89034 static long n_rcu_torture_boost_ktrerror;
89035 static long n_rcu_torture_boost_rterror;
89036 @@ -297,11 +297,11 @@ rcu_torture_alloc(void)
89037
89038 spin_lock_bh(&rcu_torture_lock);
89039 if (list_empty(&rcu_torture_freelist)) {
89040 - atomic_inc(&n_rcu_torture_alloc_fail);
89041 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
89042 spin_unlock_bh(&rcu_torture_lock);
89043 return NULL;
89044 }
89045 - atomic_inc(&n_rcu_torture_alloc);
89046 + atomic_inc_unchecked(&n_rcu_torture_alloc);
89047 p = rcu_torture_freelist.next;
89048 list_del_init(p);
89049 spin_unlock_bh(&rcu_torture_lock);
89050 @@ -314,7 +314,7 @@ rcu_torture_alloc(void)
89051 static void
89052 rcu_torture_free(struct rcu_torture *p)
89053 {
89054 - atomic_inc(&n_rcu_torture_free);
89055 + atomic_inc_unchecked(&n_rcu_torture_free);
89056 spin_lock_bh(&rcu_torture_lock);
89057 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
89058 spin_unlock_bh(&rcu_torture_lock);
89059 @@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
89060 i = rp->rtort_pipe_count;
89061 if (i > RCU_TORTURE_PIPE_LEN)
89062 i = RCU_TORTURE_PIPE_LEN;
89063 - atomic_inc(&rcu_torture_wcount[i]);
89064 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89065 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
89066 rp->rtort_mbtest = 0;
89067 rcu_torture_free(rp);
89068 @@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
89069 i = old_rp->rtort_pipe_count;
89070 if (i > RCU_TORTURE_PIPE_LEN)
89071 i = RCU_TORTURE_PIPE_LEN;
89072 - atomic_inc(&rcu_torture_wcount[i]);
89073 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89074 old_rp->rtort_pipe_count++;
89075 if (gp_normal == gp_exp)
89076 exp = !!(rcu_random(&rand) & 0x80);
89077 @@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
89078 i = rp->rtort_pipe_count;
89079 if (i > RCU_TORTURE_PIPE_LEN)
89080 i = RCU_TORTURE_PIPE_LEN;
89081 - atomic_inc(&rcu_torture_wcount[i]);
89082 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89083 if (++rp->rtort_pipe_count >=
89084 RCU_TORTURE_PIPE_LEN) {
89085 rp->rtort_mbtest = 0;
89086 @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
89087 return;
89088 }
89089 if (p->rtort_mbtest == 0)
89090 - atomic_inc(&n_rcu_torture_mberror);
89091 + atomic_inc_unchecked(&n_rcu_torture_mberror);
89092 spin_lock(&rand_lock);
89093 cur_ops->read_delay(&rand);
89094 n_rcu_torture_timers++;
89095 @@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
89096 continue;
89097 }
89098 if (p->rtort_mbtest == 0)
89099 - atomic_inc(&n_rcu_torture_mberror);
89100 + atomic_inc_unchecked(&n_rcu_torture_mberror);
89101 cur_ops->read_delay(&rand);
89102 preempt_disable();
89103 pipe_count = p->rtort_pipe_count;
89104 @@ -1068,15 +1068,15 @@ rcu_torture_printk(char *page)
89105 }
89106 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89107 page += sprintf(page,
89108 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89109 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89110 rcu_torture_current,
89111 rcu_torture_current_version,
89112 list_empty(&rcu_torture_freelist),
89113 - atomic_read(&n_rcu_torture_alloc),
89114 - atomic_read(&n_rcu_torture_alloc_fail),
89115 - atomic_read(&n_rcu_torture_free));
89116 + atomic_read_unchecked(&n_rcu_torture_alloc),
89117 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89118 + atomic_read_unchecked(&n_rcu_torture_free));
89119 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89120 - atomic_read(&n_rcu_torture_mberror),
89121 + atomic_read_unchecked(&n_rcu_torture_mberror),
89122 n_rcu_torture_boost_ktrerror,
89123 n_rcu_torture_boost_rterror);
89124 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89125 @@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
89126 n_barrier_attempts,
89127 n_rcu_torture_barrier_error);
89128 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89129 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89130 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89131 n_rcu_torture_barrier_error != 0 ||
89132 n_rcu_torture_boost_ktrerror != 0 ||
89133 n_rcu_torture_boost_rterror != 0 ||
89134 n_rcu_torture_boost_failure != 0 ||
89135 i > 1) {
89136 page += sprintf(page, "!!! ");
89137 - atomic_inc(&n_rcu_torture_error);
89138 + atomic_inc_unchecked(&n_rcu_torture_error);
89139 WARN_ON_ONCE(1);
89140 }
89141 page += sprintf(page, "Reader Pipe: ");
89142 @@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
89143 page += sprintf(page, "Free-Block Circulation: ");
89144 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89145 page += sprintf(page, " %d",
89146 - atomic_read(&rcu_torture_wcount[i]));
89147 + atomic_read_unchecked(&rcu_torture_wcount[i]));
89148 }
89149 page += sprintf(page, "\n");
89150 if (cur_ops->stats)
89151 @@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
89152
89153 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89154
89155 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89156 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89157 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89158 else if (n_online_successes != n_online_attempts ||
89159 n_offline_successes != n_offline_attempts)
89160 @@ -1961,18 +1961,18 @@ rcu_torture_init(void)
89161
89162 rcu_torture_current = NULL;
89163 rcu_torture_current_version = 0;
89164 - atomic_set(&n_rcu_torture_alloc, 0);
89165 - atomic_set(&n_rcu_torture_alloc_fail, 0);
89166 - atomic_set(&n_rcu_torture_free, 0);
89167 - atomic_set(&n_rcu_torture_mberror, 0);
89168 - atomic_set(&n_rcu_torture_error, 0);
89169 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89170 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89171 + atomic_set_unchecked(&n_rcu_torture_free, 0);
89172 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89173 + atomic_set_unchecked(&n_rcu_torture_error, 0);
89174 n_rcu_torture_barrier_error = 0;
89175 n_rcu_torture_boost_ktrerror = 0;
89176 n_rcu_torture_boost_rterror = 0;
89177 n_rcu_torture_boost_failure = 0;
89178 n_rcu_torture_boosts = 0;
89179 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89180 - atomic_set(&rcu_torture_wcount[i], 0);
89181 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89182 for_each_possible_cpu(cpu) {
89183 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89184 per_cpu(rcu_torture_count, cpu)[i] = 0;
89185 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89186 index b3d116c..ebf6598 100644
89187 --- a/kernel/rcu/tree.c
89188 +++ b/kernel/rcu/tree.c
89189 @@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89190 rcu_prepare_for_idle(smp_processor_id());
89191 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89192 smp_mb__before_atomic_inc(); /* See above. */
89193 - atomic_inc(&rdtp->dynticks);
89194 + atomic_inc_unchecked(&rdtp->dynticks);
89195 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89196 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89197 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89198
89199 /*
89200 * It is illegal to enter an extended quiescent state while
89201 @@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89202 int user)
89203 {
89204 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89205 - atomic_inc(&rdtp->dynticks);
89206 + atomic_inc_unchecked(&rdtp->dynticks);
89207 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89208 smp_mb__after_atomic_inc(); /* See above. */
89209 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89210 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89211 rcu_cleanup_after_idle(smp_processor_id());
89212 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89213 if (!user && !is_idle_task(current)) {
89214 @@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
89215 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89216
89217 if (rdtp->dynticks_nmi_nesting == 0 &&
89218 - (atomic_read(&rdtp->dynticks) & 0x1))
89219 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89220 return;
89221 rdtp->dynticks_nmi_nesting++;
89222 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89223 - atomic_inc(&rdtp->dynticks);
89224 + atomic_inc_unchecked(&rdtp->dynticks);
89225 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89226 smp_mb__after_atomic_inc(); /* See above. */
89227 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89228 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89229 }
89230
89231 /**
89232 @@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
89233 return;
89234 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89235 smp_mb__before_atomic_inc(); /* See above. */
89236 - atomic_inc(&rdtp->dynticks);
89237 + atomic_inc_unchecked(&rdtp->dynticks);
89238 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89239 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89240 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89241 }
89242
89243 /**
89244 @@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
89245 */
89246 bool notrace __rcu_is_watching(void)
89247 {
89248 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89249 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89250 }
89251
89252 /**
89253 @@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89254 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89255 bool *isidle, unsigned long *maxj)
89256 {
89257 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89258 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89259 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89260 return (rdp->dynticks_snap & 0x1) == 0;
89261 }
89262 @@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89263 unsigned int curr;
89264 unsigned int snap;
89265
89266 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89267 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89268 snap = (unsigned int)rdp->dynticks_snap;
89269
89270 /*
89271 @@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89272 rdp = this_cpu_ptr(rsp->rda);
89273 rcu_preempt_check_blocked_tasks(rnp);
89274 rnp->qsmask = rnp->qsmaskinit;
89275 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89276 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89277 WARN_ON_ONCE(rnp->completed != rsp->completed);
89278 - ACCESS_ONCE(rnp->completed) = rsp->completed;
89279 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89280 if (rnp == rdp->mynode)
89281 __note_gp_changes(rsp, rnp, rdp);
89282 rcu_preempt_boost_start_gp(rnp);
89283 @@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89284 rcu_for_each_node_breadth_first(rsp, rnp) {
89285 raw_spin_lock_irq(&rnp->lock);
89286 smp_mb__after_unlock_lock();
89287 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89288 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89289 rdp = this_cpu_ptr(rsp->rda);
89290 if (rnp == rdp->mynode)
89291 __note_gp_changes(rsp, rnp, rdp);
89292 @@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89293 rsp->qlen += rdp->qlen;
89294 rdp->n_cbs_orphaned += rdp->qlen;
89295 rdp->qlen_lazy = 0;
89296 - ACCESS_ONCE(rdp->qlen) = 0;
89297 + ACCESS_ONCE_RW(rdp->qlen) = 0;
89298 }
89299
89300 /*
89301 @@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89302 }
89303 smp_mb(); /* List handling before counting for rcu_barrier(). */
89304 rdp->qlen_lazy -= count_lazy;
89305 - ACCESS_ONCE(rdp->qlen) -= count;
89306 + ACCESS_ONCE_RW(rdp->qlen) -= count;
89307 rdp->n_cbs_invoked += count;
89308
89309 /* Reinstate batch limit if we have worked down the excess. */
89310 @@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89311 /*
89312 * Do RCU core processing for the current CPU.
89313 */
89314 -static void rcu_process_callbacks(struct softirq_action *unused)
89315 +static void rcu_process_callbacks(void)
89316 {
89317 struct rcu_state *rsp;
89318
89319 @@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89320 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89321 if (debug_rcu_head_queue(head)) {
89322 /* Probable double call_rcu(), so leak the callback. */
89323 - ACCESS_ONCE(head->func) = rcu_leak_callback;
89324 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89325 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89326 return;
89327 }
89328 @@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89329 local_irq_restore(flags);
89330 return;
89331 }
89332 - ACCESS_ONCE(rdp->qlen)++;
89333 + ACCESS_ONCE_RW(rdp->qlen)++;
89334 if (lazy)
89335 rdp->qlen_lazy++;
89336 else
89337 @@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
89338 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89339 * course be required on a 64-bit system.
89340 */
89341 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89342 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89343 (ulong)atomic_long_read(&rsp->expedited_done) +
89344 ULONG_MAX / 8)) {
89345 synchronize_sched();
89346 - atomic_long_inc(&rsp->expedited_wrap);
89347 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
89348 return;
89349 }
89350
89351 @@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
89352 * Take a ticket. Note that atomic_inc_return() implies a
89353 * full memory barrier.
89354 */
89355 - snap = atomic_long_inc_return(&rsp->expedited_start);
89356 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89357 firstsnap = snap;
89358 get_online_cpus();
89359 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89360 @@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
89361 synchronize_sched_expedited_cpu_stop,
89362 NULL) == -EAGAIN) {
89363 put_online_cpus();
89364 - atomic_long_inc(&rsp->expedited_tryfail);
89365 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89366
89367 /* Check to see if someone else did our work for us. */
89368 s = atomic_long_read(&rsp->expedited_done);
89369 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89370 /* ensure test happens before caller kfree */
89371 smp_mb__before_atomic_inc(); /* ^^^ */
89372 - atomic_long_inc(&rsp->expedited_workdone1);
89373 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89374 return;
89375 }
89376
89377 @@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
89378 udelay(trycount * num_online_cpus());
89379 } else {
89380 wait_rcu_gp(call_rcu_sched);
89381 - atomic_long_inc(&rsp->expedited_normal);
89382 + atomic_long_inc_unchecked(&rsp->expedited_normal);
89383 return;
89384 }
89385
89386 @@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
89387 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89388 /* ensure test happens before caller kfree */
89389 smp_mb__before_atomic_inc(); /* ^^^ */
89390 - atomic_long_inc(&rsp->expedited_workdone2);
89391 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89392 return;
89393 }
89394
89395 @@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
89396 * period works for us.
89397 */
89398 get_online_cpus();
89399 - snap = atomic_long_read(&rsp->expedited_start);
89400 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
89401 smp_mb(); /* ensure read is before try_stop_cpus(). */
89402 }
89403 - atomic_long_inc(&rsp->expedited_stoppedcpus);
89404 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89405
89406 /*
89407 * Everyone up to our most recent fetch is covered by our grace
89408 @@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
89409 * than we did already did their update.
89410 */
89411 do {
89412 - atomic_long_inc(&rsp->expedited_done_tries);
89413 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89414 s = atomic_long_read(&rsp->expedited_done);
89415 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89416 /* ensure test happens before caller kfree */
89417 smp_mb__before_atomic_inc(); /* ^^^ */
89418 - atomic_long_inc(&rsp->expedited_done_lost);
89419 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89420 break;
89421 }
89422 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89423 - atomic_long_inc(&rsp->expedited_done_exit);
89424 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89425
89426 put_online_cpus();
89427 }
89428 @@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89429 * ACCESS_ONCE() to prevent the compiler from speculating
89430 * the increment to precede the early-exit check.
89431 */
89432 - ACCESS_ONCE(rsp->n_barrier_done)++;
89433 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89434 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89435 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89436 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89437 @@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89438
89439 /* Increment ->n_barrier_done to prevent duplicate work. */
89440 smp_mb(); /* Keep increment after above mechanism. */
89441 - ACCESS_ONCE(rsp->n_barrier_done)++;
89442 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89443 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89444 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89445 smp_mb(); /* Keep increment before caller's subsequent code. */
89446 @@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89447 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89448 init_callback_list(rdp);
89449 rdp->qlen_lazy = 0;
89450 - ACCESS_ONCE(rdp->qlen) = 0;
89451 + ACCESS_ONCE_RW(rdp->qlen) = 0;
89452 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89453 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89454 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89455 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89456 rdp->cpu = cpu;
89457 rdp->rsp = rsp;
89458 rcu_boot_init_nocb_percpu_data(rdp);
89459 @@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89460 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89461 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89462 rcu_sysidle_init_percpu_data(rdp->dynticks);
89463 - atomic_set(&rdp->dynticks->dynticks,
89464 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89465 + atomic_set_unchecked(&rdp->dynticks->dynticks,
89466 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89467 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89468
89469 /* Add CPU to rcu_node bitmasks. */
89470 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89471 index 8c19873..bf83c57 100644
89472 --- a/kernel/rcu/tree.h
89473 +++ b/kernel/rcu/tree.h
89474 @@ -87,11 +87,11 @@ struct rcu_dynticks {
89475 long long dynticks_nesting; /* Track irq/process nesting level. */
89476 /* Process level is worth LLONG_MAX/2. */
89477 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89478 - atomic_t dynticks; /* Even value for idle, else odd. */
89479 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89480 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89481 long long dynticks_idle_nesting;
89482 /* irq/process nesting level from idle. */
89483 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
89484 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89485 /* "Idle" excludes userspace execution. */
89486 unsigned long dynticks_idle_jiffies;
89487 /* End of last non-NMI non-idle period. */
89488 @@ -431,17 +431,17 @@ struct rcu_state {
89489 /* _rcu_barrier(). */
89490 /* End of fields guarded by barrier_mutex. */
89491
89492 - atomic_long_t expedited_start; /* Starting ticket. */
89493 - atomic_long_t expedited_done; /* Done ticket. */
89494 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89495 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
89496 - atomic_long_t expedited_workdone1; /* # done by others #1. */
89497 - atomic_long_t expedited_workdone2; /* # done by others #2. */
89498 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
89499 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89500 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
89501 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89502 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89503 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89504 + atomic_long_t expedited_done; /* Done ticket. */
89505 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89506 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89507 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89508 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89509 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89510 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89511 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89512 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89513 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89514
89515 unsigned long jiffies_force_qs; /* Time at which to invoke */
89516 /* force_quiescent_state(). */
89517 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89518 index 6e2ef4b..c15df94 100644
89519 --- a/kernel/rcu/tree_plugin.h
89520 +++ b/kernel/rcu/tree_plugin.h
89521 @@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89522 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89523 {
89524 return !rcu_preempted_readers_exp(rnp) &&
89525 - ACCESS_ONCE(rnp->expmask) == 0;
89526 + ACCESS_ONCE_RW(rnp->expmask) == 0;
89527 }
89528
89529 /*
89530 @@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89531
89532 /* Clean up and exit. */
89533 smp_mb(); /* ensure expedited GP seen before counter increment. */
89534 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89535 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89536 unlock_mb_ret:
89537 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89538 mb_ret:
89539 @@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89540 free_cpumask_var(cm);
89541 }
89542
89543 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89544 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89545 .store = &rcu_cpu_kthread_task,
89546 .thread_should_run = rcu_cpu_kthread_should_run,
89547 .thread_fn = rcu_cpu_kthread,
89548 @@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89549 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89550 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89551 cpu, ticks_value, ticks_title,
89552 - atomic_read(&rdtp->dynticks) & 0xfff,
89553 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89554 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89555 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89556 fast_no_hz);
89557 @@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89558
89559 /* Enqueue the callback on the nocb list and update counts. */
89560 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89561 - ACCESS_ONCE(*old_rhpp) = rhp;
89562 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
89563 atomic_long_add(rhcount, &rdp->nocb_q_count);
89564 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89565
89566 @@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
89567 * Extract queued callbacks, update counts, and wait
89568 * for a grace period to elapse.
89569 */
89570 - ACCESS_ONCE(rdp->nocb_head) = NULL;
89571 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89572 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89573 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89574 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89575 - ACCESS_ONCE(rdp->nocb_p_count) += c;
89576 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89577 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89578 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89579 rcu_nocb_wait_gp(rdp);
89580
89581 /* Each pass through the following loop invokes a callback. */
89582 @@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
89583 list = next;
89584 }
89585 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89586 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
89587 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89588 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89589 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89590 rdp->n_nocbs_invoked += c;
89591 }
89592 return 0;
89593 @@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89594 {
89595 if (!rcu_nocb_need_deferred_wakeup(rdp))
89596 return;
89597 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89598 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89599 wake_up(&rdp->nocb_wq);
89600 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89601 }
89602 @@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89603 t = kthread_run(rcu_nocb_kthread, rdp,
89604 "rcuo%c/%d", rsp->abbr, cpu);
89605 BUG_ON(IS_ERR(t));
89606 - ACCESS_ONCE(rdp->nocb_kthread) = t;
89607 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89608 }
89609 }
89610
89611 @@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89612
89613 /* Record start of fully idle period. */
89614 j = jiffies;
89615 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89616 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89617 smp_mb__before_atomic_inc();
89618 - atomic_inc(&rdtp->dynticks_idle);
89619 + atomic_inc_unchecked(&rdtp->dynticks_idle);
89620 smp_mb__after_atomic_inc();
89621 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89622 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89623 }
89624
89625 /*
89626 @@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89627
89628 /* Record end of idle period. */
89629 smp_mb__before_atomic_inc();
89630 - atomic_inc(&rdtp->dynticks_idle);
89631 + atomic_inc_unchecked(&rdtp->dynticks_idle);
89632 smp_mb__after_atomic_inc();
89633 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89634 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89635
89636 /*
89637 * If we are the timekeeping CPU, we are permitted to be non-idle
89638 @@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89639 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89640
89641 /* Pick up current idle and NMI-nesting counter and check. */
89642 - cur = atomic_read(&rdtp->dynticks_idle);
89643 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89644 if (cur & 0x1) {
89645 *isidle = false; /* We are not idle! */
89646 return;
89647 @@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
89648 case RCU_SYSIDLE_NOT:
89649
89650 /* First time all are idle, so note a short idle period. */
89651 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89652 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89653 break;
89654
89655 case RCU_SYSIDLE_SHORT:
89656 @@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
89657 static void rcu_sysidle_cancel(void)
89658 {
89659 smp_mb();
89660 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89661 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89662 }
89663
89664 /*
89665 @@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89666 smp_mb(); /* grace period precedes setting inuse. */
89667
89668 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89669 - ACCESS_ONCE(rshp->inuse) = 0;
89670 + ACCESS_ONCE_RW(rshp->inuse) = 0;
89671 }
89672
89673 /*
89674 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89675 index 4def475..8ffddde 100644
89676 --- a/kernel/rcu/tree_trace.c
89677 +++ b/kernel/rcu/tree_trace.c
89678 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89679 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89680 rdp->passed_quiesce, rdp->qs_pending);
89681 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89682 - atomic_read(&rdp->dynticks->dynticks),
89683 + atomic_read_unchecked(&rdp->dynticks->dynticks),
89684 rdp->dynticks->dynticks_nesting,
89685 rdp->dynticks->dynticks_nmi_nesting,
89686 rdp->dynticks_fqs);
89687 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89688 struct rcu_state *rsp = (struct rcu_state *)m->private;
89689
89690 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",
89691 - atomic_long_read(&rsp->expedited_start),
89692 + atomic_long_read_unchecked(&rsp->expedited_start),
89693 atomic_long_read(&rsp->expedited_done),
89694 - atomic_long_read(&rsp->expedited_wrap),
89695 - atomic_long_read(&rsp->expedited_tryfail),
89696 - atomic_long_read(&rsp->expedited_workdone1),
89697 - atomic_long_read(&rsp->expedited_workdone2),
89698 - atomic_long_read(&rsp->expedited_normal),
89699 - atomic_long_read(&rsp->expedited_stoppedcpus),
89700 - atomic_long_read(&rsp->expedited_done_tries),
89701 - atomic_long_read(&rsp->expedited_done_lost),
89702 - atomic_long_read(&rsp->expedited_done_exit));
89703 + atomic_long_read_unchecked(&rsp->expedited_wrap),
89704 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
89705 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
89706 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
89707 + atomic_long_read_unchecked(&rsp->expedited_normal),
89708 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89709 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
89710 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
89711 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
89712 return 0;
89713 }
89714
89715 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89716 index c54609f..2e8829c 100644
89717 --- a/kernel/rcu/update.c
89718 +++ b/kernel/rcu/update.c
89719 @@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
89720 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89721 */
89722 if (till_stall_check < 3) {
89723 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89724 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89725 till_stall_check = 3;
89726 } else if (till_stall_check > 300) {
89727 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89728 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89729 till_stall_check = 300;
89730 }
89731 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89732 diff --git a/kernel/resource.c b/kernel/resource.c
89733 index 3f285dc..5755f62 100644
89734 --- a/kernel/resource.c
89735 +++ b/kernel/resource.c
89736 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89737
89738 static int __init ioresources_init(void)
89739 {
89740 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89741 +#ifdef CONFIG_GRKERNSEC_PROC_USER
89742 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89743 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89744 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89745 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89746 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89747 +#endif
89748 +#else
89749 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89750 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89751 +#endif
89752 return 0;
89753 }
89754 __initcall(ioresources_init);
89755 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89756 index 4a07353..66b5291 100644
89757 --- a/kernel/sched/auto_group.c
89758 +++ b/kernel/sched/auto_group.c
89759 @@ -11,7 +11,7 @@
89760
89761 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89762 static struct autogroup autogroup_default;
89763 -static atomic_t autogroup_seq_nr;
89764 +static atomic_unchecked_t autogroup_seq_nr;
89765
89766 void __init autogroup_init(struct task_struct *init_task)
89767 {
89768 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89769
89770 kref_init(&ag->kref);
89771 init_rwsem(&ag->lock);
89772 - ag->id = atomic_inc_return(&autogroup_seq_nr);
89773 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89774 ag->tg = tg;
89775 #ifdef CONFIG_RT_GROUP_SCHED
89776 /*
89777 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89778 index a63f4dc..349bbb0 100644
89779 --- a/kernel/sched/completion.c
89780 +++ b/kernel/sched/completion.c
89781 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89782 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89783 * or number of jiffies left till timeout) if completed.
89784 */
89785 -long __sched
89786 +long __sched __intentional_overflow(-1)
89787 wait_for_completion_interruptible_timeout(struct completion *x,
89788 unsigned long timeout)
89789 {
89790 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89791 *
89792 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89793 */
89794 -int __sched wait_for_completion_killable(struct completion *x)
89795 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89796 {
89797 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89798 if (t == -ERESTARTSYS)
89799 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89800 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89801 * or number of jiffies left till timeout) if completed.
89802 */
89803 -long __sched
89804 +long __sched __intentional_overflow(-1)
89805 wait_for_completion_killable_timeout(struct completion *x,
89806 unsigned long timeout)
89807 {
89808 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89809 index f5c6635..ab9f223 100644
89810 --- a/kernel/sched/core.c
89811 +++ b/kernel/sched/core.c
89812 @@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89813 int sysctl_numa_balancing(struct ctl_table *table, int write,
89814 void __user *buffer, size_t *lenp, loff_t *ppos)
89815 {
89816 - struct ctl_table t;
89817 + ctl_table_no_const t;
89818 int err;
89819 int state = numabalancing_enabled;
89820
89821 @@ -3049,6 +3049,8 @@ int can_nice(const struct task_struct *p, const int nice)
89822 /* convert nice value [19,-20] to rlimit style value [1,40] */
89823 int nice_rlim = 20 - nice;
89824
89825 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89826 +
89827 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89828 capable(CAP_SYS_NICE));
89829 }
89830 @@ -3082,7 +3084,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89831 if (nice > 19)
89832 nice = 19;
89833
89834 - if (increment < 0 && !can_nice(current, nice))
89835 + if (increment < 0 && (!can_nice(current, nice) ||
89836 + gr_handle_chroot_nice()))
89837 return -EPERM;
89838
89839 retval = security_task_setnice(current, nice);
89840 @@ -3332,6 +3335,7 @@ recheck:
89841 if (policy != p->policy && !rlim_rtprio)
89842 return -EPERM;
89843
89844 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89845 /* can't increase priority */
89846 if (attr->sched_priority > p->rt_priority &&
89847 attr->sched_priority > rlim_rtprio)
89848 @@ -4781,7 +4785,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89849
89850 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89851
89852 -static struct ctl_table sd_ctl_dir[] = {
89853 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
89854 {
89855 .procname = "sched_domain",
89856 .mode = 0555,
89857 @@ -4798,17 +4802,17 @@ static struct ctl_table sd_ctl_root[] = {
89858 {}
89859 };
89860
89861 -static struct ctl_table *sd_alloc_ctl_entry(int n)
89862 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89863 {
89864 - struct ctl_table *entry =
89865 + ctl_table_no_const *entry =
89866 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89867
89868 return entry;
89869 }
89870
89871 -static void sd_free_ctl_entry(struct ctl_table **tablep)
89872 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89873 {
89874 - struct ctl_table *entry;
89875 + ctl_table_no_const *entry;
89876
89877 /*
89878 * In the intermediate directories, both the child directory and
89879 @@ -4816,22 +4820,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89880 * will always be set. In the lowest directory the names are
89881 * static strings and all have proc handlers.
89882 */
89883 - for (entry = *tablep; entry->mode; entry++) {
89884 - if (entry->child)
89885 - sd_free_ctl_entry(&entry->child);
89886 + for (entry = tablep; entry->mode; entry++) {
89887 + if (entry->child) {
89888 + sd_free_ctl_entry(entry->child);
89889 + pax_open_kernel();
89890 + entry->child = NULL;
89891 + pax_close_kernel();
89892 + }
89893 if (entry->proc_handler == NULL)
89894 kfree(entry->procname);
89895 }
89896
89897 - kfree(*tablep);
89898 - *tablep = NULL;
89899 + kfree(tablep);
89900 }
89901
89902 static int min_load_idx = 0;
89903 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89904
89905 static void
89906 -set_table_entry(struct ctl_table *entry,
89907 +set_table_entry(ctl_table_no_const *entry,
89908 const char *procname, void *data, int maxlen,
89909 umode_t mode, proc_handler *proc_handler,
89910 bool load_idx)
89911 @@ -4851,7 +4858,7 @@ set_table_entry(struct ctl_table *entry,
89912 static struct ctl_table *
89913 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89914 {
89915 - struct ctl_table *table = sd_alloc_ctl_entry(13);
89916 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
89917
89918 if (table == NULL)
89919 return NULL;
89920 @@ -4886,9 +4893,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89921 return table;
89922 }
89923
89924 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89925 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89926 {
89927 - struct ctl_table *entry, *table;
89928 + ctl_table_no_const *entry, *table;
89929 struct sched_domain *sd;
89930 int domain_num = 0, i;
89931 char buf[32];
89932 @@ -4915,11 +4922,13 @@ static struct ctl_table_header *sd_sysctl_header;
89933 static void register_sched_domain_sysctl(void)
89934 {
89935 int i, cpu_num = num_possible_cpus();
89936 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89937 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89938 char buf[32];
89939
89940 WARN_ON(sd_ctl_dir[0].child);
89941 + pax_open_kernel();
89942 sd_ctl_dir[0].child = entry;
89943 + pax_close_kernel();
89944
89945 if (entry == NULL)
89946 return;
89947 @@ -4942,8 +4951,12 @@ static void unregister_sched_domain_sysctl(void)
89948 if (sd_sysctl_header)
89949 unregister_sysctl_table(sd_sysctl_header);
89950 sd_sysctl_header = NULL;
89951 - if (sd_ctl_dir[0].child)
89952 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
89953 + if (sd_ctl_dir[0].child) {
89954 + sd_free_ctl_entry(sd_ctl_dir[0].child);
89955 + pax_open_kernel();
89956 + sd_ctl_dir[0].child = NULL;
89957 + pax_close_kernel();
89958 + }
89959 }
89960 #else
89961 static void register_sched_domain_sysctl(void)
89962 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89963 index 9b4c4f3..665489b 100644
89964 --- a/kernel/sched/fair.c
89965 +++ b/kernel/sched/fair.c
89966 @@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89967
89968 static void reset_ptenuma_scan(struct task_struct *p)
89969 {
89970 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
89971 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89972 p->mm->numa_scan_offset = 0;
89973 }
89974
89975 @@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89976 * run_rebalance_domains is triggered when needed from the scheduler tick.
89977 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89978 */
89979 -static void run_rebalance_domains(struct softirq_action *h)
89980 +static __latent_entropy void run_rebalance_domains(void)
89981 {
89982 struct rq *this_rq = this_rq();
89983 enum cpu_idle_type idle = this_rq->idle_balance ?
89984 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89985 index f964add..dcd823d 100644
89986 --- a/kernel/sched/sched.h
89987 +++ b/kernel/sched/sched.h
89988 @@ -1157,7 +1157,7 @@ struct sched_class {
89989 #ifdef CONFIG_FAIR_GROUP_SCHED
89990 void (*task_move_group) (struct task_struct *p, int on_rq);
89991 #endif
89992 -};
89993 +} __do_const;
89994
89995 #define sched_class_highest (&stop_sched_class)
89996 #define for_each_class(class) \
89997 diff --git a/kernel/signal.c b/kernel/signal.c
89998 index 52f881d..1e9f941 100644
89999 --- a/kernel/signal.c
90000 +++ b/kernel/signal.c
90001 @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
90002
90003 int print_fatal_signals __read_mostly;
90004
90005 -static void __user *sig_handler(struct task_struct *t, int sig)
90006 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
90007 {
90008 return t->sighand->action[sig - 1].sa.sa_handler;
90009 }
90010
90011 -static int sig_handler_ignored(void __user *handler, int sig)
90012 +static int sig_handler_ignored(__sighandler_t handler, int sig)
90013 {
90014 /* Is it explicitly or implicitly ignored? */
90015 return handler == SIG_IGN ||
90016 @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
90017
90018 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
90019 {
90020 - void __user *handler;
90021 + __sighandler_t handler;
90022
90023 handler = sig_handler(t, sig);
90024
90025 @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
90026 atomic_inc(&user->sigpending);
90027 rcu_read_unlock();
90028
90029 + if (!override_rlimit)
90030 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
90031 +
90032 if (override_rlimit ||
90033 atomic_read(&user->sigpending) <=
90034 task_rlimit(t, RLIMIT_SIGPENDING)) {
90035 @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
90036
90037 int unhandled_signal(struct task_struct *tsk, int sig)
90038 {
90039 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
90040 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
90041 if (is_global_init(tsk))
90042 return 1;
90043 if (handler != SIG_IGN && handler != SIG_DFL)
90044 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
90045 }
90046 }
90047
90048 + /* allow glibc communication via tgkill to other threads in our
90049 + thread group */
90050 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90051 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90052 + && gr_handle_signal(t, sig))
90053 + return -EPERM;
90054 +
90055 return security_task_kill(t, info, sig, 0);
90056 }
90057
90058 @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90059 return send_signal(sig, info, p, 1);
90060 }
90061
90062 -static int
90063 +int
90064 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90065 {
90066 return send_signal(sig, info, t, 0);
90067 @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90068 unsigned long int flags;
90069 int ret, blocked, ignored;
90070 struct k_sigaction *action;
90071 + int is_unhandled = 0;
90072
90073 spin_lock_irqsave(&t->sighand->siglock, flags);
90074 action = &t->sighand->action[sig-1];
90075 @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90076 }
90077 if (action->sa.sa_handler == SIG_DFL)
90078 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90079 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90080 + is_unhandled = 1;
90081 ret = specific_send_sig_info(sig, info, t);
90082 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90083
90084 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
90085 + normal operation */
90086 + if (is_unhandled) {
90087 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90088 + gr_handle_crash(t, sig);
90089 + }
90090 +
90091 return ret;
90092 }
90093
90094 @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90095 ret = check_kill_permission(sig, info, p);
90096 rcu_read_unlock();
90097
90098 - if (!ret && sig)
90099 + if (!ret && sig) {
90100 ret = do_send_sig_info(sig, info, p, true);
90101 + if (!ret)
90102 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90103 + }
90104
90105 return ret;
90106 }
90107 @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90108 int error = -ESRCH;
90109
90110 rcu_read_lock();
90111 - p = find_task_by_vpid(pid);
90112 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90113 + /* allow glibc communication via tgkill to other threads in our
90114 + thread group */
90115 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90116 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
90117 + p = find_task_by_vpid_unrestricted(pid);
90118 + else
90119 +#endif
90120 + p = find_task_by_vpid(pid);
90121 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90122 error = check_kill_permission(sig, info, p);
90123 /*
90124 @@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90125 }
90126 seg = get_fs();
90127 set_fs(KERNEL_DS);
90128 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90129 - (stack_t __force __user *) &uoss,
90130 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90131 + (stack_t __force_user *) &uoss,
90132 compat_user_stack_pointer());
90133 set_fs(seg);
90134 if (ret >= 0 && uoss_ptr) {
90135 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90136 index eb89e18..a4e6792 100644
90137 --- a/kernel/smpboot.c
90138 +++ b/kernel/smpboot.c
90139 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90140 }
90141 smpboot_unpark_thread(plug_thread, cpu);
90142 }
90143 - list_add(&plug_thread->list, &hotplug_threads);
90144 + pax_list_add(&plug_thread->list, &hotplug_threads);
90145 out:
90146 mutex_unlock(&smpboot_threads_lock);
90147 return ret;
90148 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90149 {
90150 get_online_cpus();
90151 mutex_lock(&smpboot_threads_lock);
90152 - list_del(&plug_thread->list);
90153 + pax_list_del(&plug_thread->list);
90154 smpboot_destroy_threads(plug_thread);
90155 mutex_unlock(&smpboot_threads_lock);
90156 put_online_cpus();
90157 diff --git a/kernel/softirq.c b/kernel/softirq.c
90158 index 490fcbb..1e502c6 100644
90159 --- a/kernel/softirq.c
90160 +++ b/kernel/softirq.c
90161 @@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90162 EXPORT_SYMBOL(irq_stat);
90163 #endif
90164
90165 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90166 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90167
90168 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90169
90170 @@ -267,7 +267,7 @@ restart:
90171 kstat_incr_softirqs_this_cpu(vec_nr);
90172
90173 trace_softirq_entry(vec_nr);
90174 - h->action(h);
90175 + h->action();
90176 trace_softirq_exit(vec_nr);
90177 if (unlikely(prev_count != preempt_count())) {
90178 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90179 @@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90180 or_softirq_pending(1UL << nr);
90181 }
90182
90183 -void open_softirq(int nr, void (*action)(struct softirq_action *))
90184 +void __init open_softirq(int nr, void (*action)(void))
90185 {
90186 softirq_vec[nr].action = action;
90187 }
90188 @@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90189 }
90190 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90191
90192 -static void tasklet_action(struct softirq_action *a)
90193 +static void tasklet_action(void)
90194 {
90195 struct tasklet_struct *list;
90196
90197 @@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
90198 }
90199 }
90200
90201 -static void tasklet_hi_action(struct softirq_action *a)
90202 +static __latent_entropy void tasklet_hi_action(void)
90203 {
90204 struct tasklet_struct *list;
90205
90206 @@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
90207 .notifier_call = cpu_callback
90208 };
90209
90210 -static struct smp_hotplug_thread softirq_threads = {
90211 +static struct smp_hotplug_thread softirq_threads __read_only = {
90212 .store = &ksoftirqd,
90213 .thread_should_run = ksoftirqd_should_run,
90214 .thread_fn = run_ksoftirqd,
90215 diff --git a/kernel/sys.c b/kernel/sys.c
90216 index c0a58be..784c618 100644
90217 --- a/kernel/sys.c
90218 +++ b/kernel/sys.c
90219 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90220 error = -EACCES;
90221 goto out;
90222 }
90223 +
90224 + if (gr_handle_chroot_setpriority(p, niceval)) {
90225 + error = -EACCES;
90226 + goto out;
90227 + }
90228 +
90229 no_nice = security_task_setnice(p, niceval);
90230 if (no_nice) {
90231 error = no_nice;
90232 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90233 goto error;
90234 }
90235
90236 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90237 + goto error;
90238 +
90239 if (rgid != (gid_t) -1 ||
90240 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90241 new->sgid = new->egid;
90242 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90243 old = current_cred();
90244
90245 retval = -EPERM;
90246 +
90247 + if (gr_check_group_change(kgid, kgid, kgid))
90248 + goto error;
90249 +
90250 if (ns_capable(old->user_ns, CAP_SETGID))
90251 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90252 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90253 @@ -403,7 +416,7 @@ error:
90254 /*
90255 * change the user struct in a credentials set to match the new UID
90256 */
90257 -static int set_user(struct cred *new)
90258 +int set_user(struct cred *new)
90259 {
90260 struct user_struct *new_user;
90261
90262 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90263 goto error;
90264 }
90265
90266 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90267 + goto error;
90268 +
90269 if (!uid_eq(new->uid, old->uid)) {
90270 retval = set_user(new);
90271 if (retval < 0)
90272 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90273 old = current_cred();
90274
90275 retval = -EPERM;
90276 +
90277 + if (gr_check_crash_uid(kuid))
90278 + goto error;
90279 + if (gr_check_user_change(kuid, kuid, kuid))
90280 + goto error;
90281 +
90282 if (ns_capable(old->user_ns, CAP_SETUID)) {
90283 new->suid = new->uid = kuid;
90284 if (!uid_eq(kuid, old->uid)) {
90285 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90286 goto error;
90287 }
90288
90289 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
90290 + goto error;
90291 +
90292 if (ruid != (uid_t) -1) {
90293 new->uid = kruid;
90294 if (!uid_eq(kruid, old->uid)) {
90295 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90296 goto error;
90297 }
90298
90299 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
90300 + goto error;
90301 +
90302 if (rgid != (gid_t) -1)
90303 new->gid = krgid;
90304 if (egid != (gid_t) -1)
90305 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90306 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90307 ns_capable(old->user_ns, CAP_SETUID)) {
90308 if (!uid_eq(kuid, old->fsuid)) {
90309 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90310 + goto error;
90311 +
90312 new->fsuid = kuid;
90313 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90314 goto change_okay;
90315 }
90316 }
90317
90318 +error:
90319 abort_creds(new);
90320 return old_fsuid;
90321
90322 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90323 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90324 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90325 ns_capable(old->user_ns, CAP_SETGID)) {
90326 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90327 + goto error;
90328 +
90329 if (!gid_eq(kgid, old->fsgid)) {
90330 new->fsgid = kgid;
90331 goto change_okay;
90332 }
90333 }
90334
90335 +error:
90336 abort_creds(new);
90337 return old_fsgid;
90338
90339 @@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90340 return -EFAULT;
90341
90342 down_read(&uts_sem);
90343 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
90344 + error = __copy_to_user(name->sysname, &utsname()->sysname,
90345 __OLD_UTS_LEN);
90346 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90347 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90348 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
90349 __OLD_UTS_LEN);
90350 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90351 - error |= __copy_to_user(&name->release, &utsname()->release,
90352 + error |= __copy_to_user(name->release, &utsname()->release,
90353 __OLD_UTS_LEN);
90354 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90355 - error |= __copy_to_user(&name->version, &utsname()->version,
90356 + error |= __copy_to_user(name->version, &utsname()->version,
90357 __OLD_UTS_LEN);
90358 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90359 - error |= __copy_to_user(&name->machine, &utsname()->machine,
90360 + error |= __copy_to_user(name->machine, &utsname()->machine,
90361 __OLD_UTS_LEN);
90362 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90363 up_read(&uts_sem);
90364 @@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90365 */
90366 new_rlim->rlim_cur = 1;
90367 }
90368 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90369 + is changed to a lower value. Since tasks can be created by the same
90370 + user in between this limit change and an execve by this task, force
90371 + a recheck only for this task by setting PF_NPROC_EXCEEDED
90372 + */
90373 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90374 + tsk->flags |= PF_NPROC_EXCEEDED;
90375 }
90376 if (!retval) {
90377 if (old_rlim)
90378 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90379 index aae21e8..58d8c9a 100644
90380 --- a/kernel/sysctl.c
90381 +++ b/kernel/sysctl.c
90382 @@ -94,7 +94,6 @@
90383
90384
90385 #if defined(CONFIG_SYSCTL)
90386 -
90387 /* External variables not in a header file. */
90388 extern int max_threads;
90389 extern int suid_dumpable;
90390 @@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
90391
90392 /* Constants used for minimum and maximum */
90393 #ifdef CONFIG_LOCKUP_DETECTOR
90394 -static int sixty = 60;
90395 +static int sixty __read_only = 60;
90396 #endif
90397
90398 -static int __maybe_unused neg_one = -1;
90399 -
90400 -static int zero;
90401 -static int __maybe_unused one = 1;
90402 -static int __maybe_unused two = 2;
90403 -static int __maybe_unused three = 3;
90404 -static unsigned long one_ul = 1;
90405 -static int one_hundred = 100;
90406 +static int __maybe_unused neg_one __read_only = -1;
90407 +static int zero __read_only = 0;
90408 +static int __maybe_unused one __read_only = 1;
90409 +static int __maybe_unused two __read_only = 2;
90410 +static int __maybe_unused three __read_only = 3;
90411 +static unsigned long one_ul __read_only = 1;
90412 +static int one_hundred __read_only = 100;
90413 #ifdef CONFIG_PRINTK
90414 -static int ten_thousand = 10000;
90415 +static int ten_thousand __read_only = 10000;
90416 #endif
90417
90418 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90419 @@ -182,10 +180,8 @@ static int proc_taint(struct ctl_table *table, int write,
90420 void __user *buffer, size_t *lenp, loff_t *ppos);
90421 #endif
90422
90423 -#ifdef CONFIG_PRINTK
90424 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90425 void __user *buffer, size_t *lenp, loff_t *ppos);
90426 -#endif
90427
90428 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90429 void __user *buffer, size_t *lenp, loff_t *ppos);
90430 @@ -216,6 +212,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90431
90432 #endif
90433
90434 +extern struct ctl_table grsecurity_table[];
90435 +
90436 static struct ctl_table kern_table[];
90437 static struct ctl_table vm_table[];
90438 static struct ctl_table fs_table[];
90439 @@ -230,6 +228,20 @@ extern struct ctl_table epoll_table[];
90440 int sysctl_legacy_va_layout;
90441 #endif
90442
90443 +#ifdef CONFIG_PAX_SOFTMODE
90444 +static ctl_table pax_table[] = {
90445 + {
90446 + .procname = "softmode",
90447 + .data = &pax_softmode,
90448 + .maxlen = sizeof(unsigned int),
90449 + .mode = 0600,
90450 + .proc_handler = &proc_dointvec,
90451 + },
90452 +
90453 + { }
90454 +};
90455 +#endif
90456 +
90457 /* The default sysctl tables: */
90458
90459 static struct ctl_table sysctl_base_table[] = {
90460 @@ -278,6 +290,22 @@ static int max_extfrag_threshold = 1000;
90461 #endif
90462
90463 static struct ctl_table kern_table[] = {
90464 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90465 + {
90466 + .procname = "grsecurity",
90467 + .mode = 0500,
90468 + .child = grsecurity_table,
90469 + },
90470 +#endif
90471 +
90472 +#ifdef CONFIG_PAX_SOFTMODE
90473 + {
90474 + .procname = "pax",
90475 + .mode = 0500,
90476 + .child = pax_table,
90477 + },
90478 +#endif
90479 +
90480 {
90481 .procname = "sched_child_runs_first",
90482 .data = &sysctl_sched_child_runs_first,
90483 @@ -640,7 +668,7 @@ static struct ctl_table kern_table[] = {
90484 .data = &modprobe_path,
90485 .maxlen = KMOD_PATH_LEN,
90486 .mode = 0644,
90487 - .proc_handler = proc_dostring,
90488 + .proc_handler = proc_dostring_modpriv,
90489 },
90490 {
90491 .procname = "modules_disabled",
90492 @@ -807,16 +835,20 @@ static struct ctl_table kern_table[] = {
90493 .extra1 = &zero,
90494 .extra2 = &one,
90495 },
90496 +#endif
90497 {
90498 .procname = "kptr_restrict",
90499 .data = &kptr_restrict,
90500 .maxlen = sizeof(int),
90501 .mode = 0644,
90502 .proc_handler = proc_dointvec_minmax_sysadmin,
90503 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90504 + .extra1 = &two,
90505 +#else
90506 .extra1 = &zero,
90507 +#endif
90508 .extra2 = &two,
90509 },
90510 -#endif
90511 {
90512 .procname = "ngroups_max",
90513 .data = &ngroups_max,
90514 @@ -1061,10 +1093,17 @@ static struct ctl_table kern_table[] = {
90515 */
90516 {
90517 .procname = "perf_event_paranoid",
90518 - .data = &sysctl_perf_event_paranoid,
90519 - .maxlen = sizeof(sysctl_perf_event_paranoid),
90520 + .data = &sysctl_perf_event_legitimately_concerned,
90521 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90522 .mode = 0644,
90523 - .proc_handler = proc_dointvec,
90524 + /* go ahead, be a hero */
90525 + .proc_handler = proc_dointvec_minmax_sysadmin,
90526 + .extra1 = &neg_one,
90527 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90528 + .extra2 = &three,
90529 +#else
90530 + .extra2 = &two,
90531 +#endif
90532 },
90533 {
90534 .procname = "perf_event_mlock_kb",
90535 @@ -1335,6 +1374,13 @@ static struct ctl_table vm_table[] = {
90536 .proc_handler = proc_dointvec_minmax,
90537 .extra1 = &zero,
90538 },
90539 + {
90540 + .procname = "heap_stack_gap",
90541 + .data = &sysctl_heap_stack_gap,
90542 + .maxlen = sizeof(sysctl_heap_stack_gap),
90543 + .mode = 0644,
90544 + .proc_handler = proc_doulongvec_minmax,
90545 + },
90546 #else
90547 {
90548 .procname = "nr_trim_pages",
90549 @@ -1799,6 +1845,16 @@ int proc_dostring(struct ctl_table *table, int write,
90550 buffer, lenp, ppos);
90551 }
90552
90553 +int proc_dostring_modpriv(struct ctl_table *table, int write,
90554 + void __user *buffer, size_t *lenp, loff_t *ppos)
90555 +{
90556 + if (write && !capable(CAP_SYS_MODULE))
90557 + return -EPERM;
90558 +
90559 + return _proc_do_string(table->data, table->maxlen, write,
90560 + buffer, lenp, ppos);
90561 +}
90562 +
90563 static size_t proc_skip_spaces(char **buf)
90564 {
90565 size_t ret;
90566 @@ -1904,6 +1960,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90567 len = strlen(tmp);
90568 if (len > *size)
90569 len = *size;
90570 + if (len > sizeof(tmp))
90571 + len = sizeof(tmp);
90572 if (copy_to_user(*buf, tmp, len))
90573 return -EFAULT;
90574 *size -= len;
90575 @@ -2068,7 +2126,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90576 static int proc_taint(struct ctl_table *table, int write,
90577 void __user *buffer, size_t *lenp, loff_t *ppos)
90578 {
90579 - struct ctl_table t;
90580 + ctl_table_no_const t;
90581 unsigned long tmptaint = get_taint();
90582 int err;
90583
90584 @@ -2096,7 +2154,6 @@ static int proc_taint(struct ctl_table *table, int write,
90585 return err;
90586 }
90587
90588 -#ifdef CONFIG_PRINTK
90589 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90590 void __user *buffer, size_t *lenp, loff_t *ppos)
90591 {
90592 @@ -2105,7 +2162,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90593
90594 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90595 }
90596 -#endif
90597
90598 struct do_proc_dointvec_minmax_conv_param {
90599 int *min;
90600 @@ -2652,6 +2708,12 @@ int proc_dostring(struct ctl_table *table, int write,
90601 return -ENOSYS;
90602 }
90603
90604 +int proc_dostring_modpriv(struct ctl_table *table, int write,
90605 + void __user *buffer, size_t *lenp, loff_t *ppos)
90606 +{
90607 + return -ENOSYS;
90608 +}
90609 +
90610 int proc_dointvec(struct ctl_table *table, int write,
90611 void __user *buffer, size_t *lenp, loff_t *ppos)
90612 {
90613 @@ -2708,5 +2770,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90614 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90615 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90616 EXPORT_SYMBOL(proc_dostring);
90617 +EXPORT_SYMBOL(proc_dostring_modpriv);
90618 EXPORT_SYMBOL(proc_doulongvec_minmax);
90619 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90620 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90621 index 13d2f7c..c93d0b0 100644
90622 --- a/kernel/taskstats.c
90623 +++ b/kernel/taskstats.c
90624 @@ -28,9 +28,12 @@
90625 #include <linux/fs.h>
90626 #include <linux/file.h>
90627 #include <linux/pid_namespace.h>
90628 +#include <linux/grsecurity.h>
90629 #include <net/genetlink.h>
90630 #include <linux/atomic.h>
90631
90632 +extern int gr_is_taskstats_denied(int pid);
90633 +
90634 /*
90635 * Maximum length of a cpumask that can be specified in
90636 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90637 @@ -576,6 +579,9 @@ err:
90638
90639 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90640 {
90641 + if (gr_is_taskstats_denied(current->pid))
90642 + return -EACCES;
90643 +
90644 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90645 return cmd_attr_register_cpumask(info);
90646 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90647 diff --git a/kernel/time.c b/kernel/time.c
90648 index 7c7964c..2a0d412 100644
90649 --- a/kernel/time.c
90650 +++ b/kernel/time.c
90651 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90652 return error;
90653
90654 if (tz) {
90655 + /* we log in do_settimeofday called below, so don't log twice
90656 + */
90657 + if (!tv)
90658 + gr_log_timechange();
90659 +
90660 sys_tz = *tz;
90661 update_vsyscall_tz();
90662 if (firsttime) {
90663 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90664 index 88c9c65..7497ebc 100644
90665 --- a/kernel/time/alarmtimer.c
90666 +++ b/kernel/time/alarmtimer.c
90667 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90668 struct platform_device *pdev;
90669 int error = 0;
90670 int i;
90671 - struct k_clock alarm_clock = {
90672 + static struct k_clock alarm_clock = {
90673 .clock_getres = alarm_clock_getres,
90674 .clock_get = alarm_clock_get,
90675 .timer_create = alarm_timer_create,
90676 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90677 index 5b40279..81e58db 100644
90678 --- a/kernel/time/timekeeping.c
90679 +++ b/kernel/time/timekeeping.c
90680 @@ -15,6 +15,7 @@
90681 #include <linux/init.h>
90682 #include <linux/mm.h>
90683 #include <linux/sched.h>
90684 +#include <linux/grsecurity.h>
90685 #include <linux/syscore_ops.h>
90686 #include <linux/clocksource.h>
90687 #include <linux/jiffies.h>
90688 @@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
90689 if (!timespec_valid_strict(tv))
90690 return -EINVAL;
90691
90692 + gr_log_timechange();
90693 +
90694 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90695 write_seqcount_begin(&timekeeper_seq);
90696
90697 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90698 index 61ed862..3b52c65 100644
90699 --- a/kernel/time/timer_list.c
90700 +++ b/kernel/time/timer_list.c
90701 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90702
90703 static void print_name_offset(struct seq_file *m, void *sym)
90704 {
90705 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90706 + SEQ_printf(m, "<%p>", NULL);
90707 +#else
90708 char symname[KSYM_NAME_LEN];
90709
90710 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90711 SEQ_printf(m, "<%pK>", sym);
90712 else
90713 SEQ_printf(m, "%s", symname);
90714 +#endif
90715 }
90716
90717 static void
90718 @@ -119,7 +123,11 @@ next_one:
90719 static void
90720 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90721 {
90722 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90723 + SEQ_printf(m, " .base: %p\n", NULL);
90724 +#else
90725 SEQ_printf(m, " .base: %pK\n", base);
90726 +#endif
90727 SEQ_printf(m, " .index: %d\n",
90728 base->index);
90729 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90730 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90731 {
90732 struct proc_dir_entry *pe;
90733
90734 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
90735 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90736 +#else
90737 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90738 +#endif
90739 if (!pe)
90740 return -ENOMEM;
90741 return 0;
90742 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90743 index 1fb08f2..ca4bb1e 100644
90744 --- a/kernel/time/timer_stats.c
90745 +++ b/kernel/time/timer_stats.c
90746 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90747 static unsigned long nr_entries;
90748 static struct entry entries[MAX_ENTRIES];
90749
90750 -static atomic_t overflow_count;
90751 +static atomic_unchecked_t overflow_count;
90752
90753 /*
90754 * The entries are in a hash-table, for fast lookup:
90755 @@ -140,7 +140,7 @@ static void reset_entries(void)
90756 nr_entries = 0;
90757 memset(entries, 0, sizeof(entries));
90758 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90759 - atomic_set(&overflow_count, 0);
90760 + atomic_set_unchecked(&overflow_count, 0);
90761 }
90762
90763 static struct entry *alloc_entry(void)
90764 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90765 if (likely(entry))
90766 entry->count++;
90767 else
90768 - atomic_inc(&overflow_count);
90769 + atomic_inc_unchecked(&overflow_count);
90770
90771 out_unlock:
90772 raw_spin_unlock_irqrestore(lock, flags);
90773 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90774
90775 static void print_name_offset(struct seq_file *m, unsigned long addr)
90776 {
90777 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90778 + seq_printf(m, "<%p>", NULL);
90779 +#else
90780 char symname[KSYM_NAME_LEN];
90781
90782 if (lookup_symbol_name(addr, symname) < 0)
90783 - seq_printf(m, "<%p>", (void *)addr);
90784 + seq_printf(m, "<%pK>", (void *)addr);
90785 else
90786 seq_printf(m, "%s", symname);
90787 +#endif
90788 }
90789
90790 static int tstats_show(struct seq_file *m, void *v)
90791 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90792
90793 seq_puts(m, "Timer Stats Version: v0.3\n");
90794 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90795 - if (atomic_read(&overflow_count))
90796 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90797 + if (atomic_read_unchecked(&overflow_count))
90798 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90799 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90800
90801 for (i = 0; i < nr_entries; i++) {
90802 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90803 {
90804 struct proc_dir_entry *pe;
90805
90806 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
90807 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90808 +#else
90809 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90810 +#endif
90811 if (!pe)
90812 return -ENOMEM;
90813 return 0;
90814 diff --git a/kernel/timer.c b/kernel/timer.c
90815 index accfd24..e00f0c0 100644
90816 --- a/kernel/timer.c
90817 +++ b/kernel/timer.c
90818 @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
90819 /*
90820 * This function runs timers and the timer-tq in bottom half context.
90821 */
90822 -static void run_timer_softirq(struct softirq_action *h)
90823 +static __latent_entropy void run_timer_softirq(void)
90824 {
90825 struct tvec_base *base = __this_cpu_read(tvec_bases);
90826
90827 @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
90828 *
90829 * In all cases the return value is guaranteed to be non-negative.
90830 */
90831 -signed long __sched schedule_timeout(signed long timeout)
90832 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90833 {
90834 struct timer_list timer;
90835 unsigned long expire;
90836 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90837 index b418cb0..f879a3d 100644
90838 --- a/kernel/trace/blktrace.c
90839 +++ b/kernel/trace/blktrace.c
90840 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90841 struct blk_trace *bt = filp->private_data;
90842 char buf[16];
90843
90844 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90845 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90846
90847 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90848 }
90849 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90850 return 1;
90851
90852 bt = buf->chan->private_data;
90853 - atomic_inc(&bt->dropped);
90854 + atomic_inc_unchecked(&bt->dropped);
90855 return 0;
90856 }
90857
90858 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90859
90860 bt->dir = dir;
90861 bt->dev = dev;
90862 - atomic_set(&bt->dropped, 0);
90863 + atomic_set_unchecked(&bt->dropped, 0);
90864 INIT_LIST_HEAD(&bt->running_list);
90865
90866 ret = -EIO;
90867 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90868 index cd7f76d..553c805 100644
90869 --- a/kernel/trace/ftrace.c
90870 +++ b/kernel/trace/ftrace.c
90871 @@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90872 if (unlikely(ftrace_disabled))
90873 return 0;
90874
90875 + ret = ftrace_arch_code_modify_prepare();
90876 + FTRACE_WARN_ON(ret);
90877 + if (ret)
90878 + return 0;
90879 +
90880 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90881 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90882 if (ret) {
90883 ftrace_bug(ret, ip);
90884 - return 0;
90885 }
90886 - return 1;
90887 + return ret ? 0 : 1;
90888 }
90889
90890 /*
90891 @@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
90892 if (!count)
90893 return 0;
90894
90895 + pax_open_kernel();
90896 sort(start, count, sizeof(*start),
90897 ftrace_cmp_ips, ftrace_swap_ips);
90898 + pax_close_kernel();
90899
90900 start_pg = ftrace_allocate_pages(count);
90901 if (!start_pg)
90902 @@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90903 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90904
90905 static int ftrace_graph_active;
90906 -static struct notifier_block ftrace_suspend_notifier;
90907 -
90908 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90909 {
90910 return 0;
90911 @@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
90912 ftrace_graph_entry = ftrace_graph_entry_test;
90913 }
90914
90915 +static struct notifier_block ftrace_suspend_notifier = {
90916 + .notifier_call = ftrace_suspend_notifier_call
90917 +};
90918 +
90919 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90920 trace_func_graph_ent_t entryfunc)
90921 {
90922 @@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90923 goto out;
90924 }
90925
90926 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90927 register_pm_notifier(&ftrace_suspend_notifier);
90928
90929 ftrace_graph_active++;
90930 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90931 index fc4da2d..f3e800b 100644
90932 --- a/kernel/trace/ring_buffer.c
90933 +++ b/kernel/trace/ring_buffer.c
90934 @@ -352,9 +352,9 @@ struct buffer_data_page {
90935 */
90936 struct buffer_page {
90937 struct list_head list; /* list of buffer pages */
90938 - local_t write; /* index for next write */
90939 + local_unchecked_t write; /* index for next write */
90940 unsigned read; /* index for next read */
90941 - local_t entries; /* entries on this page */
90942 + local_unchecked_t entries; /* entries on this page */
90943 unsigned long real_end; /* real end of data */
90944 struct buffer_data_page *page; /* Actual data page */
90945 };
90946 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90947 unsigned long last_overrun;
90948 local_t entries_bytes;
90949 local_t entries;
90950 - local_t overrun;
90951 - local_t commit_overrun;
90952 + local_unchecked_t overrun;
90953 + local_unchecked_t commit_overrun;
90954 local_t dropped_events;
90955 local_t committing;
90956 local_t commits;
90957 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90958 *
90959 * We add a counter to the write field to denote this.
90960 */
90961 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90962 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90963 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90964 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90965
90966 /*
90967 * Just make sure we have seen our old_write and synchronize
90968 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90969 * cmpxchg to only update if an interrupt did not already
90970 * do it for us. If the cmpxchg fails, we don't care.
90971 */
90972 - (void)local_cmpxchg(&next_page->write, old_write, val);
90973 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90974 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90975 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90976
90977 /*
90978 * No need to worry about races with clearing out the commit.
90979 @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90980
90981 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90982 {
90983 - return local_read(&bpage->entries) & RB_WRITE_MASK;
90984 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90985 }
90986
90987 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90988 {
90989 - return local_read(&bpage->write) & RB_WRITE_MASK;
90990 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90991 }
90992
90993 static int
90994 @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90995 * bytes consumed in ring buffer from here.
90996 * Increment overrun to account for the lost events.
90997 */
90998 - local_add(page_entries, &cpu_buffer->overrun);
90999 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
91000 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91001 }
91002
91003 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
91004 * it is our responsibility to update
91005 * the counters.
91006 */
91007 - local_add(entries, &cpu_buffer->overrun);
91008 + local_add_unchecked(entries, &cpu_buffer->overrun);
91009 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91010
91011 /*
91012 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91013 if (tail == BUF_PAGE_SIZE)
91014 tail_page->real_end = 0;
91015
91016 - local_sub(length, &tail_page->write);
91017 + local_sub_unchecked(length, &tail_page->write);
91018 return;
91019 }
91020
91021 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91022 rb_event_set_padding(event);
91023
91024 /* Set the write back to the previous setting */
91025 - local_sub(length, &tail_page->write);
91026 + local_sub_unchecked(length, &tail_page->write);
91027 return;
91028 }
91029
91030 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91031
91032 /* Set write to end of buffer */
91033 length = (tail + length) - BUF_PAGE_SIZE;
91034 - local_sub(length, &tail_page->write);
91035 + local_sub_unchecked(length, &tail_page->write);
91036 }
91037
91038 /*
91039 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91040 * about it.
91041 */
91042 if (unlikely(next_page == commit_page)) {
91043 - local_inc(&cpu_buffer->commit_overrun);
91044 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91045 goto out_reset;
91046 }
91047
91048 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91049 cpu_buffer->tail_page) &&
91050 (cpu_buffer->commit_page ==
91051 cpu_buffer->reader_page))) {
91052 - local_inc(&cpu_buffer->commit_overrun);
91053 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91054 goto out_reset;
91055 }
91056 }
91057 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91058 length += RB_LEN_TIME_EXTEND;
91059
91060 tail_page = cpu_buffer->tail_page;
91061 - write = local_add_return(length, &tail_page->write);
91062 + write = local_add_return_unchecked(length, &tail_page->write);
91063
91064 /* set write to only the index of the write */
91065 write &= RB_WRITE_MASK;
91066 @@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91067 kmemcheck_annotate_bitfield(event, bitfield);
91068 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91069
91070 - local_inc(&tail_page->entries);
91071 + local_inc_unchecked(&tail_page->entries);
91072
91073 /*
91074 * If this is the first commit on the page, then update
91075 @@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91076
91077 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91078 unsigned long write_mask =
91079 - local_read(&bpage->write) & ~RB_WRITE_MASK;
91080 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91081 unsigned long event_length = rb_event_length(event);
91082 /*
91083 * This is on the tail page. It is possible that
91084 @@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91085 */
91086 old_index += write_mask;
91087 new_index += write_mask;
91088 - index = local_cmpxchg(&bpage->write, old_index, new_index);
91089 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91090 if (index == old_index) {
91091 /* update counters */
91092 local_sub(event_length, &cpu_buffer->entries_bytes);
91093 @@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91094
91095 /* Do the likely case first */
91096 if (likely(bpage->page == (void *)addr)) {
91097 - local_dec(&bpage->entries);
91098 + local_dec_unchecked(&bpage->entries);
91099 return;
91100 }
91101
91102 @@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91103 start = bpage;
91104 do {
91105 if (bpage->page == (void *)addr) {
91106 - local_dec(&bpage->entries);
91107 + local_dec_unchecked(&bpage->entries);
91108 return;
91109 }
91110 rb_inc_page(cpu_buffer, &bpage);
91111 @@ -3146,7 +3146,7 @@ static inline unsigned long
91112 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91113 {
91114 return local_read(&cpu_buffer->entries) -
91115 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91116 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91117 }
91118
91119 /**
91120 @@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91121 return 0;
91122
91123 cpu_buffer = buffer->buffers[cpu];
91124 - ret = local_read(&cpu_buffer->overrun);
91125 + ret = local_read_unchecked(&cpu_buffer->overrun);
91126
91127 return ret;
91128 }
91129 @@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91130 return 0;
91131
91132 cpu_buffer = buffer->buffers[cpu];
91133 - ret = local_read(&cpu_buffer->commit_overrun);
91134 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91135
91136 return ret;
91137 }
91138 @@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91139 /* if you care about this being correct, lock the buffer */
91140 for_each_buffer_cpu(buffer, cpu) {
91141 cpu_buffer = buffer->buffers[cpu];
91142 - overruns += local_read(&cpu_buffer->overrun);
91143 + overruns += local_read_unchecked(&cpu_buffer->overrun);
91144 }
91145
91146 return overruns;
91147 @@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91148 /*
91149 * Reset the reader page to size zero.
91150 */
91151 - local_set(&cpu_buffer->reader_page->write, 0);
91152 - local_set(&cpu_buffer->reader_page->entries, 0);
91153 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91154 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91155 local_set(&cpu_buffer->reader_page->page->commit, 0);
91156 cpu_buffer->reader_page->real_end = 0;
91157
91158 @@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91159 * want to compare with the last_overrun.
91160 */
91161 smp_mb();
91162 - overwrite = local_read(&(cpu_buffer->overrun));
91163 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91164
91165 /*
91166 * Here's the tricky part.
91167 @@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91168
91169 cpu_buffer->head_page
91170 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91171 - local_set(&cpu_buffer->head_page->write, 0);
91172 - local_set(&cpu_buffer->head_page->entries, 0);
91173 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
91174 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91175 local_set(&cpu_buffer->head_page->page->commit, 0);
91176
91177 cpu_buffer->head_page->read = 0;
91178 @@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91179
91180 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91181 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91182 - local_set(&cpu_buffer->reader_page->write, 0);
91183 - local_set(&cpu_buffer->reader_page->entries, 0);
91184 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91185 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91186 local_set(&cpu_buffer->reader_page->page->commit, 0);
91187 cpu_buffer->reader_page->read = 0;
91188
91189 local_set(&cpu_buffer->entries_bytes, 0);
91190 - local_set(&cpu_buffer->overrun, 0);
91191 - local_set(&cpu_buffer->commit_overrun, 0);
91192 + local_set_unchecked(&cpu_buffer->overrun, 0);
91193 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91194 local_set(&cpu_buffer->dropped_events, 0);
91195 local_set(&cpu_buffer->entries, 0);
91196 local_set(&cpu_buffer->committing, 0);
91197 @@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91198 rb_init_page(bpage);
91199 bpage = reader->page;
91200 reader->page = *data_page;
91201 - local_set(&reader->write, 0);
91202 - local_set(&reader->entries, 0);
91203 + local_set_unchecked(&reader->write, 0);
91204 + local_set_unchecked(&reader->entries, 0);
91205 reader->read = 0;
91206 *data_page = bpage;
91207
91208 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91209 index 24c1f23..781fd73f 100644
91210 --- a/kernel/trace/trace.c
91211 +++ b/kernel/trace/trace.c
91212 @@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91213 return 0;
91214 }
91215
91216 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91217 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91218 {
91219 /* do nothing if flag is already set */
91220 if (!!(trace_flags & mask) == !!enabled)
91221 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91222 index 02b592f..f971546 100644
91223 --- a/kernel/trace/trace.h
91224 +++ b/kernel/trace/trace.h
91225 @@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
91226 void trace_printk_init_buffers(void);
91227 void trace_printk_start_comm(void);
91228 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91229 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91230 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91231
91232 /*
91233 * Normal trace_printk() and friends allocates special buffers
91234 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91235 index 26dc348..8708ca7 100644
91236 --- a/kernel/trace/trace_clock.c
91237 +++ b/kernel/trace/trace_clock.c
91238 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91239 return now;
91240 }
91241
91242 -static atomic64_t trace_counter;
91243 +static atomic64_unchecked_t trace_counter;
91244
91245 /*
91246 * trace_clock_counter(): simply an atomic counter.
91247 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91248 */
91249 u64 notrace trace_clock_counter(void)
91250 {
91251 - return atomic64_add_return(1, &trace_counter);
91252 + return atomic64_inc_return_unchecked(&trace_counter);
91253 }
91254 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91255 index 7b16d40..1b2875d 100644
91256 --- a/kernel/trace/trace_events.c
91257 +++ b/kernel/trace/trace_events.c
91258 @@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91259 return 0;
91260 }
91261
91262 -struct ftrace_module_file_ops;
91263 static void __add_event_to_tracers(struct ftrace_event_call *call);
91264
91265 /* Add an additional event_call dynamically */
91266 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91267 index 0abd9b8..6a663a2 100644
91268 --- a/kernel/trace/trace_mmiotrace.c
91269 +++ b/kernel/trace/trace_mmiotrace.c
91270 @@ -24,7 +24,7 @@ struct header_iter {
91271 static struct trace_array *mmio_trace_array;
91272 static bool overrun_detected;
91273 static unsigned long prev_overruns;
91274 -static atomic_t dropped_count;
91275 +static atomic_unchecked_t dropped_count;
91276
91277 static void mmio_reset_data(struct trace_array *tr)
91278 {
91279 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91280
91281 static unsigned long count_overruns(struct trace_iterator *iter)
91282 {
91283 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
91284 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91285 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91286
91287 if (over > prev_overruns)
91288 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91289 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91290 sizeof(*entry), 0, pc);
91291 if (!event) {
91292 - atomic_inc(&dropped_count);
91293 + atomic_inc_unchecked(&dropped_count);
91294 return;
91295 }
91296 entry = ring_buffer_event_data(event);
91297 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91298 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91299 sizeof(*entry), 0, pc);
91300 if (!event) {
91301 - atomic_inc(&dropped_count);
91302 + atomic_inc_unchecked(&dropped_count);
91303 return;
91304 }
91305 entry = ring_buffer_event_data(event);
91306 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91307 index ed32284..884d6c3 100644
91308 --- a/kernel/trace/trace_output.c
91309 +++ b/kernel/trace/trace_output.c
91310 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91311
91312 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91313 if (!IS_ERR(p)) {
91314 - p = mangle_path(s->buffer + s->len, p, "\n");
91315 + p = mangle_path(s->buffer + s->len, p, "\n\\");
91316 if (p) {
91317 s->len = p - s->buffer;
91318 return 1;
91319 @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
91320 goto out;
91321 }
91322
91323 + pax_open_kernel();
91324 if (event->funcs->trace == NULL)
91325 - event->funcs->trace = trace_nop_print;
91326 + *(void **)&event->funcs->trace = trace_nop_print;
91327 if (event->funcs->raw == NULL)
91328 - event->funcs->raw = trace_nop_print;
91329 + *(void **)&event->funcs->raw = trace_nop_print;
91330 if (event->funcs->hex == NULL)
91331 - event->funcs->hex = trace_nop_print;
91332 + *(void **)&event->funcs->hex = trace_nop_print;
91333 if (event->funcs->binary == NULL)
91334 - event->funcs->binary = trace_nop_print;
91335 + *(void **)&event->funcs->binary = trace_nop_print;
91336 + pax_close_kernel();
91337
91338 key = event->type & (EVENT_HASHSIZE - 1);
91339
91340 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91341 index e6be585..d73ae5e 100644
91342 --- a/kernel/trace/trace_stack.c
91343 +++ b/kernel/trace/trace_stack.c
91344 @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91345 return;
91346
91347 /* we do not handle interrupt stacks yet */
91348 - if (!object_is_on_stack(stack))
91349 + if (!object_starts_on_stack(stack))
91350 return;
91351
91352 local_irq_save(flags);
91353 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91354 index 80a57af..7f5a7ff 100644
91355 --- a/kernel/user_namespace.c
91356 +++ b/kernel/user_namespace.c
91357 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91358 !kgid_has_mapping(parent_ns, group))
91359 return -EPERM;
91360
91361 +#ifdef CONFIG_GRKERNSEC
91362 + /*
91363 + * This doesn't really inspire confidence:
91364 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91365 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91366 + * Increases kernel attack surface in areas developers
91367 + * previously cared little about ("low importance due
91368 + * to requiring "root" capability")
91369 + * To be removed when this code receives *proper* review
91370 + */
91371 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91372 + !capable(CAP_SETGID))
91373 + return -EPERM;
91374 +#endif
91375 +
91376 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91377 if (!ns)
91378 return -ENOMEM;
91379 @@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91380 if (atomic_read(&current->mm->mm_users) > 1)
91381 return -EINVAL;
91382
91383 - if (current->fs->users != 1)
91384 + if (atomic_read(&current->fs->users) != 1)
91385 return -EINVAL;
91386
91387 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91388 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91389 index 4f69f9a..7c6f8f8 100644
91390 --- a/kernel/utsname_sysctl.c
91391 +++ b/kernel/utsname_sysctl.c
91392 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91393 static int proc_do_uts_string(ctl_table *table, int write,
91394 void __user *buffer, size_t *lenp, loff_t *ppos)
91395 {
91396 - struct ctl_table uts_table;
91397 + ctl_table_no_const uts_table;
91398 int r;
91399 memcpy(&uts_table, table, sizeof(uts_table));
91400 uts_table.data = get_uts(table, write);
91401 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91402 index 4431610..4265616 100644
91403 --- a/kernel/watchdog.c
91404 +++ b/kernel/watchdog.c
91405 @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91406 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91407 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91408
91409 -static struct smp_hotplug_thread watchdog_threads = {
91410 +static struct smp_hotplug_thread watchdog_threads __read_only = {
91411 .store = &softlockup_watchdog,
91412 .thread_should_run = watchdog_should_run,
91413 .thread_fn = watchdog,
91414 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91415 index 193e977..26dd63f 100644
91416 --- a/kernel/workqueue.c
91417 +++ b/kernel/workqueue.c
91418 @@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
91419 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91420 worker_flags |= WORKER_REBOUND;
91421 worker_flags &= ~WORKER_UNBOUND;
91422 - ACCESS_ONCE(worker->flags) = worker_flags;
91423 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
91424 }
91425
91426 spin_unlock_irq(&pool->lock);
91427 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91428 index a48abea..e108def 100644
91429 --- a/lib/Kconfig.debug
91430 +++ b/lib/Kconfig.debug
91431 @@ -854,7 +854,7 @@ config DEBUG_MUTEXES
91432
91433 config DEBUG_WW_MUTEX_SLOWPATH
91434 bool "Wait/wound mutex debugging: Slowpath testing"
91435 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91436 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91437 select DEBUG_LOCK_ALLOC
91438 select DEBUG_SPINLOCK
91439 select DEBUG_MUTEXES
91440 @@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91441
91442 config DEBUG_LOCK_ALLOC
91443 bool "Lock debugging: detect incorrect freeing of live locks"
91444 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91445 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91446 select DEBUG_SPINLOCK
91447 select DEBUG_MUTEXES
91448 select LOCKDEP
91449 @@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
91450
91451 config PROVE_LOCKING
91452 bool "Lock debugging: prove locking correctness"
91453 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91454 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91455 select LOCKDEP
91456 select DEBUG_SPINLOCK
91457 select DEBUG_MUTEXES
91458 @@ -932,7 +932,7 @@ config LOCKDEP
91459
91460 config LOCK_STAT
91461 bool "Lock usage statistics"
91462 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91463 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91464 select LOCKDEP
91465 select DEBUG_SPINLOCK
91466 select DEBUG_MUTEXES
91467 @@ -1394,6 +1394,7 @@ config LATENCYTOP
91468 depends on DEBUG_KERNEL
91469 depends on STACKTRACE_SUPPORT
91470 depends on PROC_FS
91471 + depends on !GRKERNSEC_HIDESYM
91472 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91473 select KALLSYMS
91474 select KALLSYMS_ALL
91475 @@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91476 config DEBUG_STRICT_USER_COPY_CHECKS
91477 bool "Strict user copy size checks"
91478 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91479 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91480 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91481 help
91482 Enabling this option turns a certain set of sanity checks for user
91483 copy operations into compile time failures.
91484 @@ -1529,7 +1530,7 @@ endmenu # runtime tests
91485
91486 config PROVIDE_OHCI1394_DMA_INIT
91487 bool "Remote debugging over FireWire early on boot"
91488 - depends on PCI && X86
91489 + depends on PCI && X86 && !GRKERNSEC
91490 help
91491 If you want to debug problems which hang or crash the kernel early
91492 on boot and the crashing machine has a FireWire port, you can use
91493 diff --git a/lib/Makefile b/lib/Makefile
91494 index 48140e3..de854e5 100644
91495 --- a/lib/Makefile
91496 +++ b/lib/Makefile
91497 @@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91498 obj-$(CONFIG_BTREE) += btree.o
91499 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91500 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91501 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91502 +obj-y += list_debug.o
91503 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91504
91505 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91506 diff --git a/lib/average.c b/lib/average.c
91507 index 114d1be..ab0350c 100644
91508 --- a/lib/average.c
91509 +++ b/lib/average.c
91510 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91511 {
91512 unsigned long internal = ACCESS_ONCE(avg->internal);
91513
91514 - ACCESS_ONCE(avg->internal) = internal ?
91515 + ACCESS_ONCE_RW(avg->internal) = internal ?
91516 (((internal << avg->weight) - internal) +
91517 (val << avg->factor)) >> avg->weight :
91518 (val << avg->factor);
91519 diff --git a/lib/bitmap.c b/lib/bitmap.c
91520 index 06f7e4f..f3cf2b0 100644
91521 --- a/lib/bitmap.c
91522 +++ b/lib/bitmap.c
91523 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91524 {
91525 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91526 u32 chunk;
91527 - const char __user __force *ubuf = (const char __user __force *)buf;
91528 + const char __user *ubuf = (const char __force_user *)buf;
91529
91530 bitmap_zero(maskp, nmaskbits);
91531
91532 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91533 {
91534 if (!access_ok(VERIFY_READ, ubuf, ulen))
91535 return -EFAULT;
91536 - return __bitmap_parse((const char __force *)ubuf,
91537 + return __bitmap_parse((const char __force_kernel *)ubuf,
91538 ulen, 1, maskp, nmaskbits);
91539
91540 }
91541 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91542 {
91543 unsigned a, b;
91544 int c, old_c, totaldigits;
91545 - const char __user __force *ubuf = (const char __user __force *)buf;
91546 + const char __user *ubuf = (const char __force_user *)buf;
91547 int exp_digit, in_range;
91548
91549 totaldigits = c = 0;
91550 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91551 {
91552 if (!access_ok(VERIFY_READ, ubuf, ulen))
91553 return -EFAULT;
91554 - return __bitmap_parselist((const char __force *)ubuf,
91555 + return __bitmap_parselist((const char __force_kernel *)ubuf,
91556 ulen, 1, maskp, nmaskbits);
91557 }
91558 EXPORT_SYMBOL(bitmap_parselist_user);
91559 diff --git a/lib/bug.c b/lib/bug.c
91560 index 1686034..a9c00c8 100644
91561 --- a/lib/bug.c
91562 +++ b/lib/bug.c
91563 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91564 return BUG_TRAP_TYPE_NONE;
91565
91566 bug = find_bug(bugaddr);
91567 + if (!bug)
91568 + return BUG_TRAP_TYPE_NONE;
91569
91570 file = NULL;
91571 line = 0;
91572 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91573 index e0731c3..ad66444 100644
91574 --- a/lib/debugobjects.c
91575 +++ b/lib/debugobjects.c
91576 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91577 if (limit > 4)
91578 return;
91579
91580 - is_on_stack = object_is_on_stack(addr);
91581 + is_on_stack = object_starts_on_stack(addr);
91582 if (is_on_stack == onstack)
91583 return;
91584
91585 diff --git a/lib/devres.c b/lib/devres.c
91586 index 8235331..5881053 100644
91587 --- a/lib/devres.c
91588 +++ b/lib/devres.c
91589 @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
91590 void devm_iounmap(struct device *dev, void __iomem *addr)
91591 {
91592 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
91593 - (void *)addr));
91594 + (void __force *)addr));
91595 iounmap(addr);
91596 }
91597 EXPORT_SYMBOL(devm_iounmap);
91598 @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
91599 {
91600 ioport_unmap(addr);
91601 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
91602 - devm_ioport_map_match, (void *)addr));
91603 + devm_ioport_map_match, (void __force *)addr));
91604 }
91605 EXPORT_SYMBOL(devm_ioport_unmap);
91606 #endif /* CONFIG_HAS_IOPORT */
91607 diff --git a/lib/div64.c b/lib/div64.c
91608 index 4382ad7..08aa558 100644
91609 --- a/lib/div64.c
91610 +++ b/lib/div64.c
91611 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91612 EXPORT_SYMBOL(__div64_32);
91613
91614 #ifndef div_s64_rem
91615 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91616 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91617 {
91618 u64 quotient;
91619
91620 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91621 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91622 */
91623 #ifndef div64_u64
91624 -u64 div64_u64(u64 dividend, u64 divisor)
91625 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91626 {
91627 u32 high = divisor >> 32;
91628 u64 quot;
91629 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91630 index 98f2d7e..899da5c 100644
91631 --- a/lib/dma-debug.c
91632 +++ b/lib/dma-debug.c
91633 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91634
91635 void dma_debug_add_bus(struct bus_type *bus)
91636 {
91637 - struct notifier_block *nb;
91638 + notifier_block_no_const *nb;
91639
91640 if (global_disable)
91641 return;
91642 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91643
91644 static void check_for_stack(struct device *dev, void *addr)
91645 {
91646 - if (object_is_on_stack(addr))
91647 + if (object_starts_on_stack(addr))
91648 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91649 "stack [addr=%p]\n", addr);
91650 }
91651 diff --git a/lib/hash.c b/lib/hash.c
91652 index fea973f..386626f 100644
91653 --- a/lib/hash.c
91654 +++ b/lib/hash.c
91655 @@ -14,7 +14,7 @@
91656 #include <linux/hash.h>
91657 #include <linux/cache.h>
91658
91659 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
91660 +static struct fast_hash_ops arch_hash_ops __read_only = {
91661 .hash = jhash,
91662 .hash2 = jhash2,
91663 };
91664 diff --git a/lib/inflate.c b/lib/inflate.c
91665 index 013a761..c28f3fc 100644
91666 --- a/lib/inflate.c
91667 +++ b/lib/inflate.c
91668 @@ -269,7 +269,7 @@ static void free(void *where)
91669 malloc_ptr = free_mem_ptr;
91670 }
91671 #else
91672 -#define malloc(a) kmalloc(a, GFP_KERNEL)
91673 +#define malloc(a) kmalloc((a), GFP_KERNEL)
91674 #define free(a) kfree(a)
91675 #endif
91676
91677 diff --git a/lib/ioremap.c b/lib/ioremap.c
91678 index 0c9216c..863bd89 100644
91679 --- a/lib/ioremap.c
91680 +++ b/lib/ioremap.c
91681 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91682 unsigned long next;
91683
91684 phys_addr -= addr;
91685 - pmd = pmd_alloc(&init_mm, pud, addr);
91686 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91687 if (!pmd)
91688 return -ENOMEM;
91689 do {
91690 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91691 unsigned long next;
91692
91693 phys_addr -= addr;
91694 - pud = pud_alloc(&init_mm, pgd, addr);
91695 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
91696 if (!pud)
91697 return -ENOMEM;
91698 do {
91699 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91700 index bd2bea9..6b3c95e 100644
91701 --- a/lib/is_single_threaded.c
91702 +++ b/lib/is_single_threaded.c
91703 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91704 struct task_struct *p, *t;
91705 bool ret;
91706
91707 + if (!mm)
91708 + return true;
91709 +
91710 if (atomic_read(&task->signal->live) != 1)
91711 return false;
91712
91713 diff --git a/lib/kobject.c b/lib/kobject.c
91714 index cb14aea..8c53cdb 100644
91715 --- a/lib/kobject.c
91716 +++ b/lib/kobject.c
91717 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91718
91719
91720 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91721 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91722 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91723
91724 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91725 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91726 {
91727 enum kobj_ns_type type = ops->type;
91728 int error;
91729 diff --git a/lib/list_debug.c b/lib/list_debug.c
91730 index c24c2f7..f0296f4 100644
91731 --- a/lib/list_debug.c
91732 +++ b/lib/list_debug.c
91733 @@ -11,7 +11,9 @@
91734 #include <linux/bug.h>
91735 #include <linux/kernel.h>
91736 #include <linux/rculist.h>
91737 +#include <linux/mm.h>
91738
91739 +#ifdef CONFIG_DEBUG_LIST
91740 /*
91741 * Insert a new entry between two known consecutive entries.
91742 *
91743 @@ -19,21 +21,40 @@
91744 * the prev/next entries already!
91745 */
91746
91747 +static bool __list_add_debug(struct list_head *new,
91748 + struct list_head *prev,
91749 + struct list_head *next)
91750 +{
91751 + if (unlikely(next->prev != prev)) {
91752 + printk(KERN_ERR "list_add corruption. next->prev should be "
91753 + "prev (%p), but was %p. (next=%p).\n",
91754 + prev, next->prev, next);
91755 + BUG();
91756 + return false;
91757 + }
91758 + if (unlikely(prev->next != next)) {
91759 + printk(KERN_ERR "list_add corruption. prev->next should be "
91760 + "next (%p), but was %p. (prev=%p).\n",
91761 + next, prev->next, prev);
91762 + BUG();
91763 + return false;
91764 + }
91765 + if (unlikely(new == prev || new == next)) {
91766 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91767 + new, prev, next);
91768 + BUG();
91769 + return false;
91770 + }
91771 + return true;
91772 +}
91773 +
91774 void __list_add(struct list_head *new,
91775 - struct list_head *prev,
91776 - struct list_head *next)
91777 + struct list_head *prev,
91778 + struct list_head *next)
91779 {
91780 - WARN(next->prev != prev,
91781 - "list_add corruption. next->prev should be "
91782 - "prev (%p), but was %p. (next=%p).\n",
91783 - prev, next->prev, next);
91784 - WARN(prev->next != next,
91785 - "list_add corruption. prev->next should be "
91786 - "next (%p), but was %p. (prev=%p).\n",
91787 - next, prev->next, prev);
91788 - WARN(new == prev || new == next,
91789 - "list_add double add: new=%p, prev=%p, next=%p.\n",
91790 - new, prev, next);
91791 + if (!__list_add_debug(new, prev, next))
91792 + return;
91793 +
91794 next->prev = new;
91795 new->next = next;
91796 new->prev = prev;
91797 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91798 }
91799 EXPORT_SYMBOL(__list_add);
91800
91801 -void __list_del_entry(struct list_head *entry)
91802 +static bool __list_del_entry_debug(struct list_head *entry)
91803 {
91804 struct list_head *prev, *next;
91805
91806 prev = entry->prev;
91807 next = entry->next;
91808
91809 - if (WARN(next == LIST_POISON1,
91810 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91811 - entry, LIST_POISON1) ||
91812 - WARN(prev == LIST_POISON2,
91813 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91814 - entry, LIST_POISON2) ||
91815 - WARN(prev->next != entry,
91816 - "list_del corruption. prev->next should be %p, "
91817 - "but was %p\n", entry, prev->next) ||
91818 - WARN(next->prev != entry,
91819 - "list_del corruption. next->prev should be %p, "
91820 - "but was %p\n", entry, next->prev))
91821 + if (unlikely(next == LIST_POISON1)) {
91822 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91823 + entry, LIST_POISON1);
91824 + BUG();
91825 + return false;
91826 + }
91827 + if (unlikely(prev == LIST_POISON2)) {
91828 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91829 + entry, LIST_POISON2);
91830 + BUG();
91831 + return false;
91832 + }
91833 + if (unlikely(entry->prev->next != entry)) {
91834 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91835 + "but was %p\n", entry, prev->next);
91836 + BUG();
91837 + return false;
91838 + }
91839 + if (unlikely(entry->next->prev != entry)) {
91840 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91841 + "but was %p\n", entry, next->prev);
91842 + BUG();
91843 + return false;
91844 + }
91845 + return true;
91846 +}
91847 +
91848 +void __list_del_entry(struct list_head *entry)
91849 +{
91850 + if (!__list_del_entry_debug(entry))
91851 return;
91852
91853 - __list_del(prev, next);
91854 + __list_del(entry->prev, entry->next);
91855 }
91856 EXPORT_SYMBOL(__list_del_entry);
91857
91858 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91859 void __list_add_rcu(struct list_head *new,
91860 struct list_head *prev, struct list_head *next)
91861 {
91862 - WARN(next->prev != prev,
91863 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91864 - prev, next->prev, next);
91865 - WARN(prev->next != next,
91866 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91867 - next, prev->next, prev);
91868 + if (!__list_add_debug(new, prev, next))
91869 + return;
91870 +
91871 new->next = next;
91872 new->prev = prev;
91873 rcu_assign_pointer(list_next_rcu(prev), new);
91874 next->prev = new;
91875 }
91876 EXPORT_SYMBOL(__list_add_rcu);
91877 +#endif
91878 +
91879 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91880 +{
91881 +#ifdef CONFIG_DEBUG_LIST
91882 + if (!__list_add_debug(new, prev, next))
91883 + return;
91884 +#endif
91885 +
91886 + pax_open_kernel();
91887 + next->prev = new;
91888 + new->next = next;
91889 + new->prev = prev;
91890 + prev->next = new;
91891 + pax_close_kernel();
91892 +}
91893 +EXPORT_SYMBOL(__pax_list_add);
91894 +
91895 +void pax_list_del(struct list_head *entry)
91896 +{
91897 +#ifdef CONFIG_DEBUG_LIST
91898 + if (!__list_del_entry_debug(entry))
91899 + return;
91900 +#endif
91901 +
91902 + pax_open_kernel();
91903 + __list_del(entry->prev, entry->next);
91904 + entry->next = LIST_POISON1;
91905 + entry->prev = LIST_POISON2;
91906 + pax_close_kernel();
91907 +}
91908 +EXPORT_SYMBOL(pax_list_del);
91909 +
91910 +void pax_list_del_init(struct list_head *entry)
91911 +{
91912 + pax_open_kernel();
91913 + __list_del(entry->prev, entry->next);
91914 + INIT_LIST_HEAD(entry);
91915 + pax_close_kernel();
91916 +}
91917 +EXPORT_SYMBOL(pax_list_del_init);
91918 +
91919 +void __pax_list_add_rcu(struct list_head *new,
91920 + struct list_head *prev, struct list_head *next)
91921 +{
91922 +#ifdef CONFIG_DEBUG_LIST
91923 + if (!__list_add_debug(new, prev, next))
91924 + return;
91925 +#endif
91926 +
91927 + pax_open_kernel();
91928 + new->next = next;
91929 + new->prev = prev;
91930 + rcu_assign_pointer(list_next_rcu(prev), new);
91931 + next->prev = new;
91932 + pax_close_kernel();
91933 +}
91934 +EXPORT_SYMBOL(__pax_list_add_rcu);
91935 +
91936 +void pax_list_del_rcu(struct list_head *entry)
91937 +{
91938 +#ifdef CONFIG_DEBUG_LIST
91939 + if (!__list_del_entry_debug(entry))
91940 + return;
91941 +#endif
91942 +
91943 + pax_open_kernel();
91944 + __list_del(entry->prev, entry->next);
91945 + entry->next = LIST_POISON1;
91946 + entry->prev = LIST_POISON2;
91947 + pax_close_kernel();
91948 +}
91949 +EXPORT_SYMBOL(pax_list_del_rcu);
91950 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91951 index 963b703..438bc51 100644
91952 --- a/lib/percpu-refcount.c
91953 +++ b/lib/percpu-refcount.c
91954 @@ -29,7 +29,7 @@
91955 * can't hit 0 before we've added up all the percpu refs.
91956 */
91957
91958 -#define PCPU_COUNT_BIAS (1U << 31)
91959 +#define PCPU_COUNT_BIAS (1U << 30)
91960
91961 /**
91962 * percpu_ref_init - initialize a percpu refcount
91963 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91964 index bd4a8df..9e4804f 100644
91965 --- a/lib/radix-tree.c
91966 +++ b/lib/radix-tree.c
91967 @@ -93,7 +93,7 @@ struct radix_tree_preload {
91968 int nr;
91969 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91970 };
91971 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91972 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91973
91974 static inline void *ptr_to_indirect(void *ptr)
91975 {
91976 diff --git a/lib/random32.c b/lib/random32.c
91977 index 6148967..009bfe8 100644
91978 --- a/lib/random32.c
91979 +++ b/lib/random32.c
91980 @@ -44,7 +44,7 @@
91981 static void __init prandom_state_selftest(void);
91982 #endif
91983
91984 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91985 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91986
91987 /**
91988 * prandom_u32_state - seeded pseudo-random number generator.
91989 diff --git a/lib/rbtree.c b/lib/rbtree.c
91990 index 65f4eff..2cfa167 100644
91991 --- a/lib/rbtree.c
91992 +++ b/lib/rbtree.c
91993 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91994 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91995
91996 static const struct rb_augment_callbacks dummy_callbacks = {
91997 - dummy_propagate, dummy_copy, dummy_rotate
91998 + .propagate = dummy_propagate,
91999 + .copy = dummy_copy,
92000 + .rotate = dummy_rotate
92001 };
92002
92003 void rb_insert_color(struct rb_node *node, struct rb_root *root)
92004 diff --git a/lib/show_mem.c b/lib/show_mem.c
92005 index 0922579..9d7adb9 100644
92006 --- a/lib/show_mem.c
92007 +++ b/lib/show_mem.c
92008 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
92009 quicklist_total_size());
92010 #endif
92011 #ifdef CONFIG_MEMORY_FAILURE
92012 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
92013 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
92014 #endif
92015 }
92016 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
92017 index bb2b201..46abaf9 100644
92018 --- a/lib/strncpy_from_user.c
92019 +++ b/lib/strncpy_from_user.c
92020 @@ -21,7 +21,7 @@
92021 */
92022 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
92023 {
92024 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92025 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92026 long res = 0;
92027
92028 /*
92029 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
92030 index a28df52..3d55877 100644
92031 --- a/lib/strnlen_user.c
92032 +++ b/lib/strnlen_user.c
92033 @@ -26,7 +26,7 @@
92034 */
92035 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92036 {
92037 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92038 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92039 long align, res = 0;
92040 unsigned long c;
92041
92042 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92043 index b604b83..c0547f6 100644
92044 --- a/lib/swiotlb.c
92045 +++ b/lib/swiotlb.c
92046 @@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92047
92048 void
92049 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92050 - dma_addr_t dev_addr)
92051 + dma_addr_t dev_addr, struct dma_attrs *attrs)
92052 {
92053 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92054
92055 diff --git a/lib/usercopy.c b/lib/usercopy.c
92056 index 4f5b1dd..7cab418 100644
92057 --- a/lib/usercopy.c
92058 +++ b/lib/usercopy.c
92059 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92060 WARN(1, "Buffer overflow detected!\n");
92061 }
92062 EXPORT_SYMBOL(copy_from_user_overflow);
92063 +
92064 +void copy_to_user_overflow(void)
92065 +{
92066 + WARN(1, "Buffer overflow detected!\n");
92067 +}
92068 +EXPORT_SYMBOL(copy_to_user_overflow);
92069 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92070 index 185b6d3..823c48c 100644
92071 --- a/lib/vsprintf.c
92072 +++ b/lib/vsprintf.c
92073 @@ -16,6 +16,9 @@
92074 * - scnprintf and vscnprintf
92075 */
92076
92077 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92078 +#define __INCLUDED_BY_HIDESYM 1
92079 +#endif
92080 #include <stdarg.h>
92081 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92082 #include <linux/types.h>
92083 @@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
92084 return number(buf, end, num, spec);
92085 }
92086
92087 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92088 +int kptr_restrict __read_mostly = 2;
92089 +#else
92090 int kptr_restrict __read_mostly;
92091 +#endif
92092
92093 /*
92094 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92095 @@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
92096 * - 'f' For simple symbolic function names without offset
92097 * - 'S' For symbolic direct pointers with offset
92098 * - 's' For symbolic direct pointers without offset
92099 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92100 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92101 * - 'B' For backtraced symbolic direct pointers with offset
92102 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92103 @@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92104
92105 if (!ptr && *fmt != 'K') {
92106 /*
92107 - * Print (null) with the same width as a pointer so it makes
92108 + * Print (nil) with the same width as a pointer so it makes
92109 * tabular output look nice.
92110 */
92111 if (spec.field_width == -1)
92112 spec.field_width = default_width;
92113 - return string(buf, end, "(null)", spec);
92114 + return string(buf, end, "(nil)", spec);
92115 }
92116
92117 switch (*fmt) {
92118 @@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92119 /* Fallthrough */
92120 case 'S':
92121 case 's':
92122 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92123 + break;
92124 +#else
92125 + return symbol_string(buf, end, ptr, spec, fmt);
92126 +#endif
92127 + case 'A':
92128 case 'B':
92129 return symbol_string(buf, end, ptr, spec, fmt);
92130 case 'R':
92131 @@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92132 va_end(va);
92133 return buf;
92134 }
92135 + case 'P':
92136 + break;
92137 case 'K':
92138 /*
92139 * %pK cannot be used in IRQ context because its test
92140 @@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92141 ((const struct file *)ptr)->f_path.dentry,
92142 spec, fmt);
92143 }
92144 +
92145 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92146 + /* 'P' = approved pointers to copy to userland,
92147 + as in the /proc/kallsyms case, as we make it display nothing
92148 + for non-root users, and the real contents for root users
92149 + Also ignore 'K' pointers, since we force their NULLing for non-root users
92150 + above
92151 + */
92152 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92153 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92154 + dump_stack();
92155 + ptr = NULL;
92156 + }
92157 +#endif
92158 +
92159 spec.flags |= SMALL;
92160 if (spec.field_width == -1) {
92161 spec.field_width = default_width;
92162 @@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92163 typeof(type) value; \
92164 if (sizeof(type) == 8) { \
92165 args = PTR_ALIGN(args, sizeof(u32)); \
92166 - *(u32 *)&value = *(u32 *)args; \
92167 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92168 + *(u32 *)&value = *(const u32 *)args; \
92169 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92170 } else { \
92171 args = PTR_ALIGN(args, sizeof(type)); \
92172 - value = *(typeof(type) *)args; \
92173 + value = *(const typeof(type) *)args; \
92174 } \
92175 args += sizeof(type); \
92176 value; \
92177 @@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92178 case FORMAT_TYPE_STR: {
92179 const char *str_arg = args;
92180 args += strlen(str_arg) + 1;
92181 - str = string(str, end, (char *)str_arg, spec);
92182 + str = string(str, end, str_arg, spec);
92183 break;
92184 }
92185
92186 diff --git a/localversion-grsec b/localversion-grsec
92187 new file mode 100644
92188 index 0000000..7cd6065
92189 --- /dev/null
92190 +++ b/localversion-grsec
92191 @@ -0,0 +1 @@
92192 +-grsec
92193 diff --git a/mm/Kconfig b/mm/Kconfig
92194 index 2888024..c15a810 100644
92195 --- a/mm/Kconfig
92196 +++ b/mm/Kconfig
92197 @@ -326,10 +326,11 @@ config KSM
92198 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92199
92200 config DEFAULT_MMAP_MIN_ADDR
92201 - int "Low address space to protect from user allocation"
92202 + int "Low address space to protect from user allocation"
92203 depends on MMU
92204 - default 4096
92205 - help
92206 + default 32768 if ALPHA || ARM || PARISC || SPARC32
92207 + default 65536
92208 + help
92209 This is the portion of low virtual memory which should be protected
92210 from userspace allocation. Keeping a user from writing to low pages
92211 can help reduce the impact of kernel NULL pointer bugs.
92212 @@ -360,7 +361,7 @@ config MEMORY_FAILURE
92213
92214 config HWPOISON_INJECT
92215 tristate "HWPoison pages injector"
92216 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92217 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92218 select PROC_PAGE_MONITOR
92219
92220 config NOMMU_INITIAL_TRIM_EXCESS
92221 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92222 index 09d9591..165bb75 100644
92223 --- a/mm/backing-dev.c
92224 +++ b/mm/backing-dev.c
92225 @@ -12,7 +12,7 @@
92226 #include <linux/device.h>
92227 #include <trace/events/writeback.h>
92228
92229 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92230 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92231
92232 struct backing_dev_info default_backing_dev_info = {
92233 .name = "default",
92234 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92235 return err;
92236
92237 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92238 - atomic_long_inc_return(&bdi_seq));
92239 + atomic_long_inc_return_unchecked(&bdi_seq));
92240 if (err) {
92241 bdi_destroy(bdi);
92242 return err;
92243 diff --git a/mm/filemap.c b/mm/filemap.c
92244 index 7a13f6a..e52e841 100644
92245 --- a/mm/filemap.c
92246 +++ b/mm/filemap.c
92247 @@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92248 struct address_space *mapping = file->f_mapping;
92249
92250 if (!mapping->a_ops->readpage)
92251 - return -ENOEXEC;
92252 + return -ENODEV;
92253 file_accessed(file);
92254 vma->vm_ops = &generic_file_vm_ops;
92255 return 0;
92256 @@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92257
92258 while (bytes) {
92259 char __user *buf = iov->iov_base + base;
92260 - int copy = min(bytes, iov->iov_len - base);
92261 + size_t copy = min(bytes, iov->iov_len - base);
92262
92263 base = 0;
92264 left = __copy_from_user_inatomic(vaddr, buf, copy);
92265 @@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92266 BUG_ON(!in_atomic());
92267 kaddr = kmap_atomic(page);
92268 if (likely(i->nr_segs == 1)) {
92269 - int left;
92270 + size_t left;
92271 char __user *buf = i->iov->iov_base + i->iov_offset;
92272 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92273 copied = bytes - left;
92274 @@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92275
92276 kaddr = kmap(page);
92277 if (likely(i->nr_segs == 1)) {
92278 - int left;
92279 + size_t left;
92280 char __user *buf = i->iov->iov_base + i->iov_offset;
92281 left = __copy_from_user(kaddr + offset, buf, bytes);
92282 copied = bytes - left;
92283 @@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92284 * zero-length segments (without overruning the iovec).
92285 */
92286 while (bytes || unlikely(i->count && !iov->iov_len)) {
92287 - int copy;
92288 + size_t copy;
92289
92290 copy = min(bytes, iov->iov_len - base);
92291 BUG_ON(!i->count || i->count < copy);
92292 @@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92293 *pos = i_size_read(inode);
92294
92295 if (limit != RLIM_INFINITY) {
92296 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92297 if (*pos >= limit) {
92298 send_sig(SIGXFSZ, current, 0);
92299 return -EFBIG;
92300 diff --git a/mm/fremap.c b/mm/fremap.c
92301 index 34feba6..315fe78 100644
92302 --- a/mm/fremap.c
92303 +++ b/mm/fremap.c
92304 @@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92305 retry:
92306 vma = find_vma(mm, start);
92307
92308 +#ifdef CONFIG_PAX_SEGMEXEC
92309 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92310 + goto out;
92311 +#endif
92312 +
92313 /*
92314 * Make sure the vma is shared, that it supports prefaulting,
92315 * and that the remapped range is valid and fully within
92316 diff --git a/mm/highmem.c b/mm/highmem.c
92317 index b32b70c..e512eb0 100644
92318 --- a/mm/highmem.c
92319 +++ b/mm/highmem.c
92320 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92321 * So no dangers, even with speculative execution.
92322 */
92323 page = pte_page(pkmap_page_table[i]);
92324 + pax_open_kernel();
92325 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92326 -
92327 + pax_close_kernel();
92328 set_page_address(page, NULL);
92329 need_flush = 1;
92330 }
92331 @@ -198,9 +199,11 @@ start:
92332 }
92333 }
92334 vaddr = PKMAP_ADDR(last_pkmap_nr);
92335 +
92336 + pax_open_kernel();
92337 set_pte_at(&init_mm, vaddr,
92338 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92339 -
92340 + pax_close_kernel();
92341 pkmap_count[last_pkmap_nr] = 1;
92342 set_page_address(page, (void *)vaddr);
92343
92344 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92345 index 2de3c84..4ecaf1b 100644
92346 --- a/mm/hugetlb.c
92347 +++ b/mm/hugetlb.c
92348 @@ -2069,15 +2069,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92349 struct hstate *h = &default_hstate;
92350 unsigned long tmp;
92351 int ret;
92352 + ctl_table_no_const hugetlb_table;
92353
92354 tmp = h->max_huge_pages;
92355
92356 if (write && h->order >= MAX_ORDER)
92357 return -EINVAL;
92358
92359 - table->data = &tmp;
92360 - table->maxlen = sizeof(unsigned long);
92361 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92362 + hugetlb_table = *table;
92363 + hugetlb_table.data = &tmp;
92364 + hugetlb_table.maxlen = sizeof(unsigned long);
92365 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92366 if (ret)
92367 goto out;
92368
92369 @@ -2122,15 +2124,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92370 struct hstate *h = &default_hstate;
92371 unsigned long tmp;
92372 int ret;
92373 + ctl_table_no_const hugetlb_table;
92374
92375 tmp = h->nr_overcommit_huge_pages;
92376
92377 if (write && h->order >= MAX_ORDER)
92378 return -EINVAL;
92379
92380 - table->data = &tmp;
92381 - table->maxlen = sizeof(unsigned long);
92382 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92383 + hugetlb_table = *table;
92384 + hugetlb_table.data = &tmp;
92385 + hugetlb_table.maxlen = sizeof(unsigned long);
92386 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92387 if (ret)
92388 goto out;
92389
92390 @@ -2599,6 +2603,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92391 return 1;
92392 }
92393
92394 +#ifdef CONFIG_PAX_SEGMEXEC
92395 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92396 +{
92397 + struct mm_struct *mm = vma->vm_mm;
92398 + struct vm_area_struct *vma_m;
92399 + unsigned long address_m;
92400 + pte_t *ptep_m;
92401 +
92402 + vma_m = pax_find_mirror_vma(vma);
92403 + if (!vma_m)
92404 + return;
92405 +
92406 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92407 + address_m = address + SEGMEXEC_TASK_SIZE;
92408 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92409 + get_page(page_m);
92410 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
92411 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92412 +}
92413 +#endif
92414 +
92415 /*
92416 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92417 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92418 @@ -2715,6 +2740,11 @@ retry_avoidcopy:
92419 make_huge_pte(vma, new_page, 1));
92420 page_remove_rmap(old_page);
92421 hugepage_add_new_anon_rmap(new_page, vma, address);
92422 +
92423 +#ifdef CONFIG_PAX_SEGMEXEC
92424 + pax_mirror_huge_pte(vma, address, new_page);
92425 +#endif
92426 +
92427 /* Make the old page be freed below */
92428 new_page = old_page;
92429 }
92430 @@ -2879,6 +2909,10 @@ retry:
92431 && (vma->vm_flags & VM_SHARED)));
92432 set_huge_pte_at(mm, address, ptep, new_pte);
92433
92434 +#ifdef CONFIG_PAX_SEGMEXEC
92435 + pax_mirror_huge_pte(vma, address, page);
92436 +#endif
92437 +
92438 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92439 /* Optimization, do the COW without a second fault */
92440 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92441 @@ -2909,6 +2943,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92442 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
92443 struct hstate *h = hstate_vma(vma);
92444
92445 +#ifdef CONFIG_PAX_SEGMEXEC
92446 + struct vm_area_struct *vma_m;
92447 +#endif
92448 +
92449 address &= huge_page_mask(h);
92450
92451 ptep = huge_pte_offset(mm, address);
92452 @@ -2922,6 +2960,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92453 VM_FAULT_SET_HINDEX(hstate_index(h));
92454 }
92455
92456 +#ifdef CONFIG_PAX_SEGMEXEC
92457 + vma_m = pax_find_mirror_vma(vma);
92458 + if (vma_m) {
92459 + unsigned long address_m;
92460 +
92461 + if (vma->vm_start > vma_m->vm_start) {
92462 + address_m = address;
92463 + address -= SEGMEXEC_TASK_SIZE;
92464 + vma = vma_m;
92465 + h = hstate_vma(vma);
92466 + } else
92467 + address_m = address + SEGMEXEC_TASK_SIZE;
92468 +
92469 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92470 + return VM_FAULT_OOM;
92471 + address_m &= HPAGE_MASK;
92472 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92473 + }
92474 +#endif
92475 +
92476 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92477 if (!ptep)
92478 return VM_FAULT_OOM;
92479 diff --git a/mm/internal.h b/mm/internal.h
92480 index 3e91000..4741a60 100644
92481 --- a/mm/internal.h
92482 +++ b/mm/internal.h
92483 @@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92484 * in mm/page_alloc.c
92485 */
92486 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92487 +extern void free_compound_page(struct page *page);
92488 extern void prep_compound_page(struct page *page, unsigned long order);
92489 #ifdef CONFIG_MEMORY_FAILURE
92490 extern bool is_free_buddy_page(struct page *page);
92491 @@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
92492
92493 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92494 unsigned long, unsigned long,
92495 - unsigned long, unsigned long);
92496 + unsigned long, unsigned long) __intentional_overflow(-1);
92497
92498 extern void set_pageblock_order(void);
92499 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92500 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92501 index 31f01c5..7015178 100644
92502 --- a/mm/kmemleak.c
92503 +++ b/mm/kmemleak.c
92504 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
92505
92506 for (i = 0; i < object->trace_len; i++) {
92507 void *ptr = (void *)object->trace[i];
92508 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92509 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92510 }
92511 }
92512
92513 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
92514 return -ENOMEM;
92515 }
92516
92517 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92518 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92519 &kmemleak_fops);
92520 if (!dentry)
92521 pr_warning("Failed to create the debugfs kmemleak file\n");
92522 diff --git a/mm/maccess.c b/mm/maccess.c
92523 index d53adf9..03a24bf 100644
92524 --- a/mm/maccess.c
92525 +++ b/mm/maccess.c
92526 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92527 set_fs(KERNEL_DS);
92528 pagefault_disable();
92529 ret = __copy_from_user_inatomic(dst,
92530 - (__force const void __user *)src, size);
92531 + (const void __force_user *)src, size);
92532 pagefault_enable();
92533 set_fs(old_fs);
92534
92535 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92536
92537 set_fs(KERNEL_DS);
92538 pagefault_disable();
92539 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92540 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92541 pagefault_enable();
92542 set_fs(old_fs);
92543
92544 diff --git a/mm/madvise.c b/mm/madvise.c
92545 index 539eeb9..e24a987 100644
92546 --- a/mm/madvise.c
92547 +++ b/mm/madvise.c
92548 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92549 pgoff_t pgoff;
92550 unsigned long new_flags = vma->vm_flags;
92551
92552 +#ifdef CONFIG_PAX_SEGMEXEC
92553 + struct vm_area_struct *vma_m;
92554 +#endif
92555 +
92556 switch (behavior) {
92557 case MADV_NORMAL:
92558 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92559 @@ -126,6 +130,13 @@ success:
92560 /*
92561 * vm_flags is protected by the mmap_sem held in write mode.
92562 */
92563 +
92564 +#ifdef CONFIG_PAX_SEGMEXEC
92565 + vma_m = pax_find_mirror_vma(vma);
92566 + if (vma_m)
92567 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92568 +#endif
92569 +
92570 vma->vm_flags = new_flags;
92571
92572 out:
92573 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92574 struct vm_area_struct **prev,
92575 unsigned long start, unsigned long end)
92576 {
92577 +
92578 +#ifdef CONFIG_PAX_SEGMEXEC
92579 + struct vm_area_struct *vma_m;
92580 +#endif
92581 +
92582 *prev = vma;
92583 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92584 return -EINVAL;
92585 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92586 zap_page_range(vma, start, end - start, &details);
92587 } else
92588 zap_page_range(vma, start, end - start, NULL);
92589 +
92590 +#ifdef CONFIG_PAX_SEGMEXEC
92591 + vma_m = pax_find_mirror_vma(vma);
92592 + if (vma_m) {
92593 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92594 + struct zap_details details = {
92595 + .nonlinear_vma = vma_m,
92596 + .last_index = ULONG_MAX,
92597 + };
92598 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92599 + } else
92600 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92601 + }
92602 +#endif
92603 +
92604 return 0;
92605 }
92606
92607 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92608 if (end < start)
92609 return error;
92610
92611 +#ifdef CONFIG_PAX_SEGMEXEC
92612 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92613 + if (end > SEGMEXEC_TASK_SIZE)
92614 + return error;
92615 + } else
92616 +#endif
92617 +
92618 + if (end > TASK_SIZE)
92619 + return error;
92620 +
92621 error = 0;
92622 if (end == start)
92623 return error;
92624 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92625 index 90002ea..db1452d 100644
92626 --- a/mm/memory-failure.c
92627 +++ b/mm/memory-failure.c
92628 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92629
92630 int sysctl_memory_failure_recovery __read_mostly = 1;
92631
92632 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92633 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92634
92635 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92636
92637 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92638 pfn, t->comm, t->pid);
92639 si.si_signo = SIGBUS;
92640 si.si_errno = 0;
92641 - si.si_addr = (void *)addr;
92642 + si.si_addr = (void __user *)addr;
92643 #ifdef __ARCH_SI_TRAPNO
92644 si.si_trapno = trapno;
92645 #endif
92646 @@ -762,7 +762,7 @@ static struct page_state {
92647 unsigned long res;
92648 char *msg;
92649 int (*action)(struct page *p, unsigned long pfn);
92650 -} error_states[] = {
92651 +} __do_const error_states[] = {
92652 { reserved, reserved, "reserved kernel", me_kernel },
92653 /*
92654 * free pages are specially detected outside this table:
92655 @@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92656 nr_pages = 1 << compound_order(hpage);
92657 else /* normal page or thp */
92658 nr_pages = 1;
92659 - atomic_long_add(nr_pages, &num_poisoned_pages);
92660 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92661
92662 /*
92663 * We need/can do nothing about count=0 pages.
92664 @@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92665 if (!PageHWPoison(hpage)
92666 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
92667 || (p != hpage && TestSetPageHWPoison(hpage))) {
92668 - atomic_long_sub(nr_pages, &num_poisoned_pages);
92669 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92670 return 0;
92671 }
92672 set_page_hwpoison_huge_page(hpage);
92673 @@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92674 }
92675 if (hwpoison_filter(p)) {
92676 if (TestClearPageHWPoison(p))
92677 - atomic_long_sub(nr_pages, &num_poisoned_pages);
92678 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92679 unlock_page(hpage);
92680 put_page(hpage);
92681 return 0;
92682 @@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
92683 return 0;
92684 }
92685 if (TestClearPageHWPoison(p))
92686 - atomic_long_dec(&num_poisoned_pages);
92687 + atomic_long_dec_unchecked(&num_poisoned_pages);
92688 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92689 return 0;
92690 }
92691 @@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
92692 */
92693 if (TestClearPageHWPoison(page)) {
92694 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92695 - atomic_long_sub(nr_pages, &num_poisoned_pages);
92696 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92697 freeit = 1;
92698 if (PageHuge(page))
92699 clear_page_hwpoison_huge_page(page);
92700 @@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92701 if (PageHuge(page)) {
92702 set_page_hwpoison_huge_page(hpage);
92703 dequeue_hwpoisoned_huge_page(hpage);
92704 - atomic_long_add(1 << compound_order(hpage),
92705 + atomic_long_add_unchecked(1 << compound_order(hpage),
92706 &num_poisoned_pages);
92707 } else {
92708 SetPageHWPoison(page);
92709 - atomic_long_inc(&num_poisoned_pages);
92710 + atomic_long_inc_unchecked(&num_poisoned_pages);
92711 }
92712 }
92713 return ret;
92714 @@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
92715 put_page(page);
92716 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92717 SetPageHWPoison(page);
92718 - atomic_long_inc(&num_poisoned_pages);
92719 + atomic_long_inc_unchecked(&num_poisoned_pages);
92720 return 0;
92721 }
92722
92723 @@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
92724 if (!is_free_buddy_page(page))
92725 pr_info("soft offline: %#lx: page leaked\n",
92726 pfn);
92727 - atomic_long_inc(&num_poisoned_pages);
92728 + atomic_long_inc_unchecked(&num_poisoned_pages);
92729 }
92730 } else {
92731 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92732 @@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
92733 if (PageHuge(page)) {
92734 set_page_hwpoison_huge_page(hpage);
92735 dequeue_hwpoisoned_huge_page(hpage);
92736 - atomic_long_add(1 << compound_order(hpage),
92737 + atomic_long_add_unchecked(1 << compound_order(hpage),
92738 &num_poisoned_pages);
92739 } else {
92740 SetPageHWPoison(page);
92741 - atomic_long_inc(&num_poisoned_pages);
92742 + atomic_long_inc_unchecked(&num_poisoned_pages);
92743 }
92744 }
92745 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92746 diff --git a/mm/memory.c b/mm/memory.c
92747 index 22dfa61..90d7ec5 100644
92748 --- a/mm/memory.c
92749 +++ b/mm/memory.c
92750 @@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92751 free_pte_range(tlb, pmd, addr);
92752 } while (pmd++, addr = next, addr != end);
92753
92754 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92755 start &= PUD_MASK;
92756 if (start < floor)
92757 return;
92758 @@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92759 pmd = pmd_offset(pud, start);
92760 pud_clear(pud);
92761 pmd_free_tlb(tlb, pmd, start);
92762 +#endif
92763 +
92764 }
92765
92766 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92767 @@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92768 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92769 } while (pud++, addr = next, addr != end);
92770
92771 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92772 start &= PGDIR_MASK;
92773 if (start < floor)
92774 return;
92775 @@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92776 pud = pud_offset(pgd, start);
92777 pgd_clear(pgd);
92778 pud_free_tlb(tlb, pud, start);
92779 +#endif
92780 +
92781 }
92782
92783 /*
92784 @@ -1636,12 +1642,6 @@ no_page_table:
92785 return page;
92786 }
92787
92788 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92789 -{
92790 - return stack_guard_page_start(vma, addr) ||
92791 - stack_guard_page_end(vma, addr+PAGE_SIZE);
92792 -}
92793 -
92794 /**
92795 * __get_user_pages() - pin user pages in memory
92796 * @tsk: task_struct of target task
92797 @@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92798
92799 i = 0;
92800
92801 - do {
92802 + while (nr_pages) {
92803 struct vm_area_struct *vma;
92804
92805 - vma = find_extend_vma(mm, start);
92806 + vma = find_vma(mm, start);
92807 if (!vma && in_gate_area(mm, start)) {
92808 unsigned long pg = start & PAGE_MASK;
92809 pgd_t *pgd;
92810 @@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92811 goto next_page;
92812 }
92813
92814 - if (!vma ||
92815 + if (!vma || start < vma->vm_start ||
92816 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
92817 !(vm_flags & vma->vm_flags))
92818 return i ? : -EFAULT;
92819 @@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92820 int ret;
92821 unsigned int fault_flags = 0;
92822
92823 - /* For mlock, just skip the stack guard page. */
92824 - if (foll_flags & FOLL_MLOCK) {
92825 - if (stack_guard_page(vma, start))
92826 - goto next_page;
92827 - }
92828 if (foll_flags & FOLL_WRITE)
92829 fault_flags |= FAULT_FLAG_WRITE;
92830 if (nonblocking)
92831 @@ -1893,7 +1888,7 @@ next_page:
92832 start += page_increm * PAGE_SIZE;
92833 nr_pages -= page_increm;
92834 } while (nr_pages && start < vma->vm_end);
92835 - } while (nr_pages);
92836 + }
92837 return i;
92838 }
92839 EXPORT_SYMBOL(__get_user_pages);
92840 @@ -1929,12 +1924,17 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
92841 unsigned long address, unsigned int fault_flags)
92842 {
92843 struct vm_area_struct *vma;
92844 + vm_flags_t vm_flags;
92845 int ret;
92846
92847 vma = find_extend_vma(mm, address);
92848 if (!vma || address < vma->vm_start)
92849 return -EFAULT;
92850
92851 + vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
92852 + if (!(vm_flags & vma->vm_flags))
92853 + return -EFAULT;
92854 +
92855 ret = handle_mm_fault(mm, vma, address, fault_flags);
92856 if (ret & VM_FAULT_ERROR) {
92857 if (ret & VM_FAULT_OOM)
92858 @@ -2100,6 +2100,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92859 page_add_file_rmap(page);
92860 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92861
92862 +#ifdef CONFIG_PAX_SEGMEXEC
92863 + pax_mirror_file_pte(vma, addr, page, ptl);
92864 +#endif
92865 +
92866 retval = 0;
92867 pte_unmap_unlock(pte, ptl);
92868 return retval;
92869 @@ -2144,9 +2148,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92870 if (!page_count(page))
92871 return -EINVAL;
92872 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92873 +
92874 +#ifdef CONFIG_PAX_SEGMEXEC
92875 + struct vm_area_struct *vma_m;
92876 +#endif
92877 +
92878 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92879 BUG_ON(vma->vm_flags & VM_PFNMAP);
92880 vma->vm_flags |= VM_MIXEDMAP;
92881 +
92882 +#ifdef CONFIG_PAX_SEGMEXEC
92883 + vma_m = pax_find_mirror_vma(vma);
92884 + if (vma_m)
92885 + vma_m->vm_flags |= VM_MIXEDMAP;
92886 +#endif
92887 +
92888 }
92889 return insert_page(vma, addr, page, vma->vm_page_prot);
92890 }
92891 @@ -2229,6 +2245,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92892 unsigned long pfn)
92893 {
92894 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92895 + BUG_ON(vma->vm_mirror);
92896
92897 if (addr < vma->vm_start || addr >= vma->vm_end)
92898 return -EFAULT;
92899 @@ -2476,7 +2493,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92900
92901 BUG_ON(pud_huge(*pud));
92902
92903 - pmd = pmd_alloc(mm, pud, addr);
92904 + pmd = (mm == &init_mm) ?
92905 + pmd_alloc_kernel(mm, pud, addr) :
92906 + pmd_alloc(mm, pud, addr);
92907 if (!pmd)
92908 return -ENOMEM;
92909 do {
92910 @@ -2496,7 +2515,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92911 unsigned long next;
92912 int err;
92913
92914 - pud = pud_alloc(mm, pgd, addr);
92915 + pud = (mm == &init_mm) ?
92916 + pud_alloc_kernel(mm, pgd, addr) :
92917 + pud_alloc(mm, pgd, addr);
92918 if (!pud)
92919 return -ENOMEM;
92920 do {
92921 @@ -2586,6 +2607,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
92922 copy_user_highpage(dst, src, va, vma);
92923 }
92924
92925 +#ifdef CONFIG_PAX_SEGMEXEC
92926 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92927 +{
92928 + struct mm_struct *mm = vma->vm_mm;
92929 + spinlock_t *ptl;
92930 + pte_t *pte, entry;
92931 +
92932 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92933 + entry = *pte;
92934 + if (!pte_present(entry)) {
92935 + if (!pte_none(entry)) {
92936 + BUG_ON(pte_file(entry));
92937 + free_swap_and_cache(pte_to_swp_entry(entry));
92938 + pte_clear_not_present_full(mm, address, pte, 0);
92939 + }
92940 + } else {
92941 + struct page *page;
92942 +
92943 + flush_cache_page(vma, address, pte_pfn(entry));
92944 + entry = ptep_clear_flush(vma, address, pte);
92945 + BUG_ON(pte_dirty(entry));
92946 + page = vm_normal_page(vma, address, entry);
92947 + if (page) {
92948 + update_hiwater_rss(mm);
92949 + if (PageAnon(page))
92950 + dec_mm_counter_fast(mm, MM_ANONPAGES);
92951 + else
92952 + dec_mm_counter_fast(mm, MM_FILEPAGES);
92953 + page_remove_rmap(page);
92954 + page_cache_release(page);
92955 + }
92956 + }
92957 + pte_unmap_unlock(pte, ptl);
92958 +}
92959 +
92960 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
92961 + *
92962 + * the ptl of the lower mapped page is held on entry and is not released on exit
92963 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92964 + */
92965 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92966 +{
92967 + struct mm_struct *mm = vma->vm_mm;
92968 + unsigned long address_m;
92969 + spinlock_t *ptl_m;
92970 + struct vm_area_struct *vma_m;
92971 + pmd_t *pmd_m;
92972 + pte_t *pte_m, entry_m;
92973 +
92974 + BUG_ON(!page_m || !PageAnon(page_m));
92975 +
92976 + vma_m = pax_find_mirror_vma(vma);
92977 + if (!vma_m)
92978 + return;
92979 +
92980 + BUG_ON(!PageLocked(page_m));
92981 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92982 + address_m = address + SEGMEXEC_TASK_SIZE;
92983 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92984 + pte_m = pte_offset_map(pmd_m, address_m);
92985 + ptl_m = pte_lockptr(mm, pmd_m);
92986 + if (ptl != ptl_m) {
92987 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92988 + if (!pte_none(*pte_m))
92989 + goto out;
92990 + }
92991 +
92992 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92993 + page_cache_get(page_m);
92994 + page_add_anon_rmap(page_m, vma_m, address_m);
92995 + inc_mm_counter_fast(mm, MM_ANONPAGES);
92996 + set_pte_at(mm, address_m, pte_m, entry_m);
92997 + update_mmu_cache(vma_m, address_m, pte_m);
92998 +out:
92999 + if (ptl != ptl_m)
93000 + spin_unlock(ptl_m);
93001 + pte_unmap(pte_m);
93002 + unlock_page(page_m);
93003 +}
93004 +
93005 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93006 +{
93007 + struct mm_struct *mm = vma->vm_mm;
93008 + unsigned long address_m;
93009 + spinlock_t *ptl_m;
93010 + struct vm_area_struct *vma_m;
93011 + pmd_t *pmd_m;
93012 + pte_t *pte_m, entry_m;
93013 +
93014 + BUG_ON(!page_m || PageAnon(page_m));
93015 +
93016 + vma_m = pax_find_mirror_vma(vma);
93017 + if (!vma_m)
93018 + return;
93019 +
93020 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93021 + address_m = address + SEGMEXEC_TASK_SIZE;
93022 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93023 + pte_m = pte_offset_map(pmd_m, address_m);
93024 + ptl_m = pte_lockptr(mm, pmd_m);
93025 + if (ptl != ptl_m) {
93026 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93027 + if (!pte_none(*pte_m))
93028 + goto out;
93029 + }
93030 +
93031 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93032 + page_cache_get(page_m);
93033 + page_add_file_rmap(page_m);
93034 + inc_mm_counter_fast(mm, MM_FILEPAGES);
93035 + set_pte_at(mm, address_m, pte_m, entry_m);
93036 + update_mmu_cache(vma_m, address_m, pte_m);
93037 +out:
93038 + if (ptl != ptl_m)
93039 + spin_unlock(ptl_m);
93040 + pte_unmap(pte_m);
93041 +}
93042 +
93043 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93044 +{
93045 + struct mm_struct *mm = vma->vm_mm;
93046 + unsigned long address_m;
93047 + spinlock_t *ptl_m;
93048 + struct vm_area_struct *vma_m;
93049 + pmd_t *pmd_m;
93050 + pte_t *pte_m, entry_m;
93051 +
93052 + vma_m = pax_find_mirror_vma(vma);
93053 + if (!vma_m)
93054 + return;
93055 +
93056 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93057 + address_m = address + SEGMEXEC_TASK_SIZE;
93058 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93059 + pte_m = pte_offset_map(pmd_m, address_m);
93060 + ptl_m = pte_lockptr(mm, pmd_m);
93061 + if (ptl != ptl_m) {
93062 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93063 + if (!pte_none(*pte_m))
93064 + goto out;
93065 + }
93066 +
93067 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93068 + set_pte_at(mm, address_m, pte_m, entry_m);
93069 +out:
93070 + if (ptl != ptl_m)
93071 + spin_unlock(ptl_m);
93072 + pte_unmap(pte_m);
93073 +}
93074 +
93075 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93076 +{
93077 + struct page *page_m;
93078 + pte_t entry;
93079 +
93080 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93081 + goto out;
93082 +
93083 + entry = *pte;
93084 + page_m = vm_normal_page(vma, address, entry);
93085 + if (!page_m)
93086 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93087 + else if (PageAnon(page_m)) {
93088 + if (pax_find_mirror_vma(vma)) {
93089 + pte_unmap_unlock(pte, ptl);
93090 + lock_page(page_m);
93091 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93092 + if (pte_same(entry, *pte))
93093 + pax_mirror_anon_pte(vma, address, page_m, ptl);
93094 + else
93095 + unlock_page(page_m);
93096 + }
93097 + } else
93098 + pax_mirror_file_pte(vma, address, page_m, ptl);
93099 +
93100 +out:
93101 + pte_unmap_unlock(pte, ptl);
93102 +}
93103 +#endif
93104 +
93105 /*
93106 * This routine handles present pages, when users try to write
93107 * to a shared page. It is done by copying the page to a new address
93108 @@ -2810,6 +3011,12 @@ gotten:
93109 */
93110 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93111 if (likely(pte_same(*page_table, orig_pte))) {
93112 +
93113 +#ifdef CONFIG_PAX_SEGMEXEC
93114 + if (pax_find_mirror_vma(vma))
93115 + BUG_ON(!trylock_page(new_page));
93116 +#endif
93117 +
93118 if (old_page) {
93119 if (!PageAnon(old_page)) {
93120 dec_mm_counter_fast(mm, MM_FILEPAGES);
93121 @@ -2861,6 +3068,10 @@ gotten:
93122 page_remove_rmap(old_page);
93123 }
93124
93125 +#ifdef CONFIG_PAX_SEGMEXEC
93126 + pax_mirror_anon_pte(vma, address, new_page, ptl);
93127 +#endif
93128 +
93129 /* Free the old page.. */
93130 new_page = old_page;
93131 ret |= VM_FAULT_WRITE;
93132 @@ -3138,6 +3349,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93133 swap_free(entry);
93134 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93135 try_to_free_swap(page);
93136 +
93137 +#ifdef CONFIG_PAX_SEGMEXEC
93138 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93139 +#endif
93140 +
93141 unlock_page(page);
93142 if (page != swapcache) {
93143 /*
93144 @@ -3161,6 +3377,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93145
93146 /* No need to invalidate - it was non-present before */
93147 update_mmu_cache(vma, address, page_table);
93148 +
93149 +#ifdef CONFIG_PAX_SEGMEXEC
93150 + pax_mirror_anon_pte(vma, address, page, ptl);
93151 +#endif
93152 +
93153 unlock:
93154 pte_unmap_unlock(page_table, ptl);
93155 out:
93156 @@ -3180,40 +3401,6 @@ out_release:
93157 }
93158
93159 /*
93160 - * This is like a special single-page "expand_{down|up}wards()",
93161 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
93162 - * doesn't hit another vma.
93163 - */
93164 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93165 -{
93166 - address &= PAGE_MASK;
93167 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93168 - struct vm_area_struct *prev = vma->vm_prev;
93169 -
93170 - /*
93171 - * Is there a mapping abutting this one below?
93172 - *
93173 - * That's only ok if it's the same stack mapping
93174 - * that has gotten split..
93175 - */
93176 - if (prev && prev->vm_end == address)
93177 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93178 -
93179 - expand_downwards(vma, address - PAGE_SIZE);
93180 - }
93181 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93182 - struct vm_area_struct *next = vma->vm_next;
93183 -
93184 - /* As VM_GROWSDOWN but s/below/above/ */
93185 - if (next && next->vm_start == address + PAGE_SIZE)
93186 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93187 -
93188 - expand_upwards(vma, address + PAGE_SIZE);
93189 - }
93190 - return 0;
93191 -}
93192 -
93193 -/*
93194 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93195 * but allow concurrent faults), and pte mapped but not yet locked.
93196 * We return with mmap_sem still held, but pte unmapped and unlocked.
93197 @@ -3222,27 +3409,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93198 unsigned long address, pte_t *page_table, pmd_t *pmd,
93199 unsigned int flags)
93200 {
93201 - struct page *page;
93202 + struct page *page = NULL;
93203 spinlock_t *ptl;
93204 pte_t entry;
93205
93206 - pte_unmap(page_table);
93207 -
93208 - /* Check if we need to add a guard page to the stack */
93209 - if (check_stack_guard_page(vma, address) < 0)
93210 - return VM_FAULT_SIGBUS;
93211 -
93212 - /* Use the zero-page for reads */
93213 if (!(flags & FAULT_FLAG_WRITE)) {
93214 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93215 vma->vm_page_prot));
93216 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93217 + ptl = pte_lockptr(mm, pmd);
93218 + spin_lock(ptl);
93219 if (!pte_none(*page_table))
93220 goto unlock;
93221 goto setpte;
93222 }
93223
93224 /* Allocate our own private page. */
93225 + pte_unmap(page_table);
93226 +
93227 if (unlikely(anon_vma_prepare(vma)))
93228 goto oom;
93229 page = alloc_zeroed_user_highpage_movable(vma, address);
93230 @@ -3266,6 +3449,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93231 if (!pte_none(*page_table))
93232 goto release;
93233
93234 +#ifdef CONFIG_PAX_SEGMEXEC
93235 + if (pax_find_mirror_vma(vma))
93236 + BUG_ON(!trylock_page(page));
93237 +#endif
93238 +
93239 inc_mm_counter_fast(mm, MM_ANONPAGES);
93240 page_add_new_anon_rmap(page, vma, address);
93241 setpte:
93242 @@ -3273,6 +3461,12 @@ setpte:
93243
93244 /* No need to invalidate - it was non-present before */
93245 update_mmu_cache(vma, address, page_table);
93246 +
93247 +#ifdef CONFIG_PAX_SEGMEXEC
93248 + if (page)
93249 + pax_mirror_anon_pte(vma, address, page, ptl);
93250 +#endif
93251 +
93252 unlock:
93253 pte_unmap_unlock(page_table, ptl);
93254 return 0;
93255 @@ -3417,6 +3611,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93256 */
93257 /* Only go through if we didn't race with anybody else... */
93258 if (likely(pte_same(*page_table, orig_pte))) {
93259 +
93260 +#ifdef CONFIG_PAX_SEGMEXEC
93261 + if (anon && pax_find_mirror_vma(vma))
93262 + BUG_ON(!trylock_page(page));
93263 +#endif
93264 +
93265 flush_icache_page(vma, page);
93266 entry = mk_pte(page, vma->vm_page_prot);
93267 if (flags & FAULT_FLAG_WRITE)
93268 @@ -3438,6 +3638,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93269
93270 /* no need to invalidate: a not-present page won't be cached */
93271 update_mmu_cache(vma, address, page_table);
93272 +
93273 +#ifdef CONFIG_PAX_SEGMEXEC
93274 + if (anon)
93275 + pax_mirror_anon_pte(vma, address, page, ptl);
93276 + else
93277 + pax_mirror_file_pte(vma, address, page, ptl);
93278 +#endif
93279 +
93280 } else {
93281 if (cow_page)
93282 mem_cgroup_uncharge_page(cow_page);
93283 @@ -3685,6 +3893,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93284 if (flags & FAULT_FLAG_WRITE)
93285 flush_tlb_fix_spurious_fault(vma, address);
93286 }
93287 +
93288 +#ifdef CONFIG_PAX_SEGMEXEC
93289 + pax_mirror_pte(vma, address, pte, pmd, ptl);
93290 + return 0;
93291 +#endif
93292 +
93293 unlock:
93294 pte_unmap_unlock(pte, ptl);
93295 return 0;
93296 @@ -3701,9 +3915,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93297 pmd_t *pmd;
93298 pte_t *pte;
93299
93300 +#ifdef CONFIG_PAX_SEGMEXEC
93301 + struct vm_area_struct *vma_m;
93302 +#endif
93303 +
93304 if (unlikely(is_vm_hugetlb_page(vma)))
93305 return hugetlb_fault(mm, vma, address, flags);
93306
93307 +#ifdef CONFIG_PAX_SEGMEXEC
93308 + vma_m = pax_find_mirror_vma(vma);
93309 + if (vma_m) {
93310 + unsigned long address_m;
93311 + pgd_t *pgd_m;
93312 + pud_t *pud_m;
93313 + pmd_t *pmd_m;
93314 +
93315 + if (vma->vm_start > vma_m->vm_start) {
93316 + address_m = address;
93317 + address -= SEGMEXEC_TASK_SIZE;
93318 + vma = vma_m;
93319 + } else
93320 + address_m = address + SEGMEXEC_TASK_SIZE;
93321 +
93322 + pgd_m = pgd_offset(mm, address_m);
93323 + pud_m = pud_alloc(mm, pgd_m, address_m);
93324 + if (!pud_m)
93325 + return VM_FAULT_OOM;
93326 + pmd_m = pmd_alloc(mm, pud_m, address_m);
93327 + if (!pmd_m)
93328 + return VM_FAULT_OOM;
93329 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93330 + return VM_FAULT_OOM;
93331 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93332 + }
93333 +#endif
93334 +
93335 pgd = pgd_offset(mm, address);
93336 pud = pud_alloc(mm, pgd, address);
93337 if (!pud)
93338 @@ -3834,6 +4080,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93339 spin_unlock(&mm->page_table_lock);
93340 return 0;
93341 }
93342 +
93343 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93344 +{
93345 + pud_t *new = pud_alloc_one(mm, address);
93346 + if (!new)
93347 + return -ENOMEM;
93348 +
93349 + smp_wmb(); /* See comment in __pte_alloc */
93350 +
93351 + spin_lock(&mm->page_table_lock);
93352 + if (pgd_present(*pgd)) /* Another has populated it */
93353 + pud_free(mm, new);
93354 + else
93355 + pgd_populate_kernel(mm, pgd, new);
93356 + spin_unlock(&mm->page_table_lock);
93357 + return 0;
93358 +}
93359 #endif /* __PAGETABLE_PUD_FOLDED */
93360
93361 #ifndef __PAGETABLE_PMD_FOLDED
93362 @@ -3864,6 +4127,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93363 spin_unlock(&mm->page_table_lock);
93364 return 0;
93365 }
93366 +
93367 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93368 +{
93369 + pmd_t *new = pmd_alloc_one(mm, address);
93370 + if (!new)
93371 + return -ENOMEM;
93372 +
93373 + smp_wmb(); /* See comment in __pte_alloc */
93374 +
93375 + spin_lock(&mm->page_table_lock);
93376 +#ifndef __ARCH_HAS_4LEVEL_HACK
93377 + if (pud_present(*pud)) /* Another has populated it */
93378 + pmd_free(mm, new);
93379 + else
93380 + pud_populate_kernel(mm, pud, new);
93381 +#else
93382 + if (pgd_present(*pud)) /* Another has populated it */
93383 + pmd_free(mm, new);
93384 + else
93385 + pgd_populate_kernel(mm, pud, new);
93386 +#endif /* __ARCH_HAS_4LEVEL_HACK */
93387 + spin_unlock(&mm->page_table_lock);
93388 + return 0;
93389 +}
93390 #endif /* __PAGETABLE_PMD_FOLDED */
93391
93392 #if !defined(__HAVE_ARCH_GATE_AREA)
93393 @@ -3877,7 +4164,7 @@ static int __init gate_vma_init(void)
93394 gate_vma.vm_start = FIXADDR_USER_START;
93395 gate_vma.vm_end = FIXADDR_USER_END;
93396 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93397 - gate_vma.vm_page_prot = __P101;
93398 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93399
93400 return 0;
93401 }
93402 @@ -4011,8 +4298,8 @@ out:
93403 return ret;
93404 }
93405
93406 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93407 - void *buf, int len, int write)
93408 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93409 + void *buf, size_t len, int write)
93410 {
93411 resource_size_t phys_addr;
93412 unsigned long prot = 0;
93413 @@ -4038,8 +4325,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93414 * Access another process' address space as given in mm. If non-NULL, use the
93415 * given task for page fault accounting.
93416 */
93417 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93418 - unsigned long addr, void *buf, int len, int write)
93419 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93420 + unsigned long addr, void *buf, size_t len, int write)
93421 {
93422 struct vm_area_struct *vma;
93423 void *old_buf = buf;
93424 @@ -4047,7 +4334,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93425 down_read(&mm->mmap_sem);
93426 /* ignore errors, just check how much was successfully transferred */
93427 while (len) {
93428 - int bytes, ret, offset;
93429 + ssize_t bytes, ret, offset;
93430 void *maddr;
93431 struct page *page = NULL;
93432
93433 @@ -4106,8 +4393,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93434 *
93435 * The caller must hold a reference on @mm.
93436 */
93437 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93438 - void *buf, int len, int write)
93439 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93440 + void *buf, size_t len, int write)
93441 {
93442 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93443 }
93444 @@ -4117,11 +4404,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93445 * Source/target buffer must be kernel space,
93446 * Do not walk the page table directly, use get_user_pages
93447 */
93448 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
93449 - void *buf, int len, int write)
93450 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93451 + void *buf, size_t len, int write)
93452 {
93453 struct mm_struct *mm;
93454 - int ret;
93455 + ssize_t ret;
93456
93457 mm = get_task_mm(tsk);
93458 if (!mm)
93459 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93460 index ae3c8f3..fa4ee8e 100644
93461 --- a/mm/mempolicy.c
93462 +++ b/mm/mempolicy.c
93463 @@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93464 unsigned long vmstart;
93465 unsigned long vmend;
93466
93467 +#ifdef CONFIG_PAX_SEGMEXEC
93468 + struct vm_area_struct *vma_m;
93469 +#endif
93470 +
93471 vma = find_vma(mm, start);
93472 if (!vma || vma->vm_start > start)
93473 return -EFAULT;
93474 @@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93475 err = vma_replace_policy(vma, new_pol);
93476 if (err)
93477 goto out;
93478 +
93479 +#ifdef CONFIG_PAX_SEGMEXEC
93480 + vma_m = pax_find_mirror_vma(vma);
93481 + if (vma_m) {
93482 + err = vma_replace_policy(vma_m, new_pol);
93483 + if (err)
93484 + goto out;
93485 + }
93486 +#endif
93487 +
93488 }
93489
93490 out:
93491 @@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93492
93493 if (end < start)
93494 return -EINVAL;
93495 +
93496 +#ifdef CONFIG_PAX_SEGMEXEC
93497 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93498 + if (end > SEGMEXEC_TASK_SIZE)
93499 + return -EINVAL;
93500 + } else
93501 +#endif
93502 +
93503 + if (end > TASK_SIZE)
93504 + return -EINVAL;
93505 +
93506 if (end == start)
93507 return 0;
93508
93509 @@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93510 */
93511 tcred = __task_cred(task);
93512 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93513 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93514 - !capable(CAP_SYS_NICE)) {
93515 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93516 rcu_read_unlock();
93517 err = -EPERM;
93518 goto out_put;
93519 @@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93520 goto out;
93521 }
93522
93523 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93524 + if (mm != current->mm &&
93525 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93526 + mmput(mm);
93527 + err = -EPERM;
93528 + goto out;
93529 + }
93530 +#endif
93531 +
93532 err = do_migrate_pages(mm, old, new,
93533 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93534
93535 diff --git a/mm/migrate.c b/mm/migrate.c
93536 index bed4880..a493f67 100644
93537 --- a/mm/migrate.c
93538 +++ b/mm/migrate.c
93539 @@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93540 */
93541 tcred = __task_cred(task);
93542 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93543 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93544 - !capable(CAP_SYS_NICE)) {
93545 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93546 rcu_read_unlock();
93547 err = -EPERM;
93548 goto out;
93549 diff --git a/mm/mlock.c b/mm/mlock.c
93550 index b1eb536..091d154 100644
93551 --- a/mm/mlock.c
93552 +++ b/mm/mlock.c
93553 @@ -14,6 +14,7 @@
93554 #include <linux/pagevec.h>
93555 #include <linux/mempolicy.h>
93556 #include <linux/syscalls.h>
93557 +#include <linux/security.h>
93558 #include <linux/sched.h>
93559 #include <linux/export.h>
93560 #include <linux/rmap.h>
93561 @@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93562 {
93563 unsigned long nstart, end, tmp;
93564 struct vm_area_struct * vma, * prev;
93565 - int error;
93566 + int error = 0;
93567
93568 VM_BUG_ON(start & ~PAGE_MASK);
93569 VM_BUG_ON(len != PAGE_ALIGN(len));
93570 @@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93571 return -EINVAL;
93572 if (end == start)
93573 return 0;
93574 + if (end > TASK_SIZE)
93575 + return -EINVAL;
93576 +
93577 vma = find_vma(current->mm, start);
93578 if (!vma || vma->vm_start > start)
93579 return -ENOMEM;
93580 @@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93581 for (nstart = start ; ; ) {
93582 vm_flags_t newflags;
93583
93584 +#ifdef CONFIG_PAX_SEGMEXEC
93585 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93586 + break;
93587 +#endif
93588 +
93589 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93590
93591 newflags = vma->vm_flags & ~VM_LOCKED;
93592 @@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93593 locked += current->mm->locked_vm;
93594
93595 /* check against resource limits */
93596 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93597 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93598 error = do_mlock(start, len, 1);
93599
93600 @@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93601 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93602 vm_flags_t newflags;
93603
93604 +#ifdef CONFIG_PAX_SEGMEXEC
93605 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93606 + break;
93607 +#endif
93608 +
93609 newflags = vma->vm_flags & ~VM_LOCKED;
93610 if (flags & MCL_CURRENT)
93611 newflags |= VM_LOCKED;
93612 @@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93613 lock_limit >>= PAGE_SHIFT;
93614
93615 ret = -ENOMEM;
93616 +
93617 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93618 +
93619 down_write(&current->mm->mmap_sem);
93620 -
93621 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93622 capable(CAP_IPC_LOCK))
93623 ret = do_mlockall(flags);
93624 diff --git a/mm/mmap.c b/mm/mmap.c
93625 index 20ff0c3..a9eda98 100644
93626 --- a/mm/mmap.c
93627 +++ b/mm/mmap.c
93628 @@ -36,6 +36,7 @@
93629 #include <linux/sched/sysctl.h>
93630 #include <linux/notifier.h>
93631 #include <linux/memory.h>
93632 +#include <linux/random.h>
93633
93634 #include <asm/uaccess.h>
93635 #include <asm/cacheflush.h>
93636 @@ -52,6 +53,16 @@
93637 #define arch_rebalance_pgtables(addr, len) (addr)
93638 #endif
93639
93640 +static inline void verify_mm_writelocked(struct mm_struct *mm)
93641 +{
93642 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93643 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93644 + up_read(&mm->mmap_sem);
93645 + BUG();
93646 + }
93647 +#endif
93648 +}
93649 +
93650 static void unmap_region(struct mm_struct *mm,
93651 struct vm_area_struct *vma, struct vm_area_struct *prev,
93652 unsigned long start, unsigned long end);
93653 @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
93654 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93655 *
93656 */
93657 -pgprot_t protection_map[16] = {
93658 +pgprot_t protection_map[16] __read_only = {
93659 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93660 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93661 };
93662
93663 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
93664 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93665 {
93666 - return __pgprot(pgprot_val(protection_map[vm_flags &
93667 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93668 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93669 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93670 +
93671 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93672 + if (!(__supported_pte_mask & _PAGE_NX) &&
93673 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93674 + (vm_flags & (VM_READ | VM_WRITE)))
93675 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93676 +#endif
93677 +
93678 + return prot;
93679 }
93680 EXPORT_SYMBOL(vm_get_page_prot);
93681
93682 @@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93683 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93684 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93685 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93686 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93687 /*
93688 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93689 * other variables. It can be updated by several CPUs frequently.
93690 @@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93691 struct vm_area_struct *next = vma->vm_next;
93692
93693 might_sleep();
93694 + BUG_ON(vma->vm_mirror);
93695 if (vma->vm_ops && vma->vm_ops->close)
93696 vma->vm_ops->close(vma);
93697 if (vma->vm_file)
93698 @@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93699 * not page aligned -Ram Gupta
93700 */
93701 rlim = rlimit(RLIMIT_DATA);
93702 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93703 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93704 (mm->end_data - mm->start_data) > rlim)
93705 goto out;
93706 @@ -940,6 +963,12 @@ static int
93707 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93708 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93709 {
93710 +
93711 +#ifdef CONFIG_PAX_SEGMEXEC
93712 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93713 + return 0;
93714 +#endif
93715 +
93716 if (is_mergeable_vma(vma, file, vm_flags) &&
93717 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93718 if (vma->vm_pgoff == vm_pgoff)
93719 @@ -959,6 +988,12 @@ static int
93720 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93721 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93722 {
93723 +
93724 +#ifdef CONFIG_PAX_SEGMEXEC
93725 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93726 + return 0;
93727 +#endif
93728 +
93729 if (is_mergeable_vma(vma, file, vm_flags) &&
93730 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93731 pgoff_t vm_pglen;
93732 @@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93733 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93734 struct vm_area_struct *prev, unsigned long addr,
93735 unsigned long end, unsigned long vm_flags,
93736 - struct anon_vma *anon_vma, struct file *file,
93737 + struct anon_vma *anon_vma, struct file *file,
93738 pgoff_t pgoff, struct mempolicy *policy)
93739 {
93740 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93741 struct vm_area_struct *area, *next;
93742 int err;
93743
93744 +#ifdef CONFIG_PAX_SEGMEXEC
93745 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93746 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93747 +
93748 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93749 +#endif
93750 +
93751 /*
93752 * We later require that vma->vm_flags == vm_flags,
93753 * so this tests vma->vm_flags & VM_SPECIAL, too.
93754 @@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93755 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93756 next = next->vm_next;
93757
93758 +#ifdef CONFIG_PAX_SEGMEXEC
93759 + if (prev)
93760 + prev_m = pax_find_mirror_vma(prev);
93761 + if (area)
93762 + area_m = pax_find_mirror_vma(area);
93763 + if (next)
93764 + next_m = pax_find_mirror_vma(next);
93765 +#endif
93766 +
93767 /*
93768 * Can it merge with the predecessor?
93769 */
93770 @@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93771 /* cases 1, 6 */
93772 err = vma_adjust(prev, prev->vm_start,
93773 next->vm_end, prev->vm_pgoff, NULL);
93774 - } else /* cases 2, 5, 7 */
93775 +
93776 +#ifdef CONFIG_PAX_SEGMEXEC
93777 + if (!err && prev_m)
93778 + err = vma_adjust(prev_m, prev_m->vm_start,
93779 + next_m->vm_end, prev_m->vm_pgoff, NULL);
93780 +#endif
93781 +
93782 + } else { /* cases 2, 5, 7 */
93783 err = vma_adjust(prev, prev->vm_start,
93784 end, prev->vm_pgoff, NULL);
93785 +
93786 +#ifdef CONFIG_PAX_SEGMEXEC
93787 + if (!err && prev_m)
93788 + err = vma_adjust(prev_m, prev_m->vm_start,
93789 + end_m, prev_m->vm_pgoff, NULL);
93790 +#endif
93791 +
93792 + }
93793 if (err)
93794 return NULL;
93795 khugepaged_enter_vma_merge(prev);
93796 @@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93797 mpol_equal(policy, vma_policy(next)) &&
93798 can_vma_merge_before(next, vm_flags,
93799 anon_vma, file, pgoff+pglen)) {
93800 - if (prev && addr < prev->vm_end) /* case 4 */
93801 + if (prev && addr < prev->vm_end) { /* case 4 */
93802 err = vma_adjust(prev, prev->vm_start,
93803 addr, prev->vm_pgoff, NULL);
93804 - else /* cases 3, 8 */
93805 +
93806 +#ifdef CONFIG_PAX_SEGMEXEC
93807 + if (!err && prev_m)
93808 + err = vma_adjust(prev_m, prev_m->vm_start,
93809 + addr_m, prev_m->vm_pgoff, NULL);
93810 +#endif
93811 +
93812 + } else { /* cases 3, 8 */
93813 err = vma_adjust(area, addr, next->vm_end,
93814 next->vm_pgoff - pglen, NULL);
93815 +
93816 +#ifdef CONFIG_PAX_SEGMEXEC
93817 + if (!err && area_m)
93818 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
93819 + next_m->vm_pgoff - pglen, NULL);
93820 +#endif
93821 +
93822 + }
93823 if (err)
93824 return NULL;
93825 khugepaged_enter_vma_merge(area);
93826 @@ -1172,8 +1253,10 @@ none:
93827 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93828 struct file *file, long pages)
93829 {
93830 - const unsigned long stack_flags
93831 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93832 +
93833 +#ifdef CONFIG_PAX_RANDMMAP
93834 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93835 +#endif
93836
93837 mm->total_vm += pages;
93838
93839 @@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93840 mm->shared_vm += pages;
93841 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93842 mm->exec_vm += pages;
93843 - } else if (flags & stack_flags)
93844 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93845 mm->stack_vm += pages;
93846 }
93847 #endif /* CONFIG_PROC_FS */
93848 @@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93849 locked += mm->locked_vm;
93850 lock_limit = rlimit(RLIMIT_MEMLOCK);
93851 lock_limit >>= PAGE_SHIFT;
93852 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93853 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93854 return -EAGAIN;
93855 }
93856 @@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93857 * (the exception is when the underlying filesystem is noexec
93858 * mounted, in which case we dont add PROT_EXEC.)
93859 */
93860 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93861 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93862 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93863 prot |= PROT_EXEC;
93864
93865 @@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93866 /* Obtain the address to map to. we verify (or select) it and ensure
93867 * that it represents a valid section of the address space.
93868 */
93869 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
93870 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93871 if (addr & ~PAGE_MASK)
93872 return addr;
93873
93874 @@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93875 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93876 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93877
93878 +#ifdef CONFIG_PAX_MPROTECT
93879 + if (mm->pax_flags & MF_PAX_MPROTECT) {
93880 +
93881 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93882 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93883 + mm->binfmt->handle_mmap)
93884 + mm->binfmt->handle_mmap(file);
93885 +#endif
93886 +
93887 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
93888 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93889 + gr_log_rwxmmap(file);
93890 +
93891 +#ifdef CONFIG_PAX_EMUPLT
93892 + vm_flags &= ~VM_EXEC;
93893 +#else
93894 + return -EPERM;
93895 +#endif
93896 +
93897 + }
93898 +
93899 + if (!(vm_flags & VM_EXEC))
93900 + vm_flags &= ~VM_MAYEXEC;
93901 +#else
93902 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93903 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93904 +#endif
93905 + else
93906 + vm_flags &= ~VM_MAYWRITE;
93907 + }
93908 +#endif
93909 +
93910 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93911 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93912 + vm_flags &= ~VM_PAGEEXEC;
93913 +#endif
93914 +
93915 if (flags & MAP_LOCKED)
93916 if (!can_do_mlock())
93917 return -EPERM;
93918 @@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93919 vm_flags |= VM_NORESERVE;
93920 }
93921
93922 + if (!gr_acl_handle_mmap(file, prot))
93923 + return -EACCES;
93924 +
93925 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93926 if (!IS_ERR_VALUE(addr) &&
93927 ((vm_flags & VM_LOCKED) ||
93928 @@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93929 vm_flags_t vm_flags = vma->vm_flags;
93930
93931 /* If it was private or non-writable, the write bit is already clear */
93932 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93933 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93934 return 0;
93935
93936 /* The backer wishes to know when pages are first written to? */
93937 @@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93938 struct rb_node **rb_link, *rb_parent;
93939 unsigned long charged = 0;
93940
93941 +#ifdef CONFIG_PAX_SEGMEXEC
93942 + struct vm_area_struct *vma_m = NULL;
93943 +#endif
93944 +
93945 + /*
93946 + * mm->mmap_sem is required to protect against another thread
93947 + * changing the mappings in case we sleep.
93948 + */
93949 + verify_mm_writelocked(mm);
93950 +
93951 /* Check against address space limit. */
93952 +
93953 +#ifdef CONFIG_PAX_RANDMMAP
93954 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93955 +#endif
93956 +
93957 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93958 unsigned long nr_pages;
93959
93960 @@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93961
93962 /* Clear old maps */
93963 error = -ENOMEM;
93964 -munmap_back:
93965 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93966 if (do_munmap(mm, addr, len))
93967 return -ENOMEM;
93968 - goto munmap_back;
93969 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93970 }
93971
93972 /*
93973 @@ -1554,6 +1692,16 @@ munmap_back:
93974 goto unacct_error;
93975 }
93976
93977 +#ifdef CONFIG_PAX_SEGMEXEC
93978 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93979 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93980 + if (!vma_m) {
93981 + error = -ENOMEM;
93982 + goto free_vma;
93983 + }
93984 + }
93985 +#endif
93986 +
93987 vma->vm_mm = mm;
93988 vma->vm_start = addr;
93989 vma->vm_end = addr + len;
93990 @@ -1573,6 +1721,13 @@ munmap_back:
93991 if (error)
93992 goto unmap_and_free_vma;
93993
93994 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93995 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93996 + vma->vm_flags |= VM_PAGEEXEC;
93997 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93998 + }
93999 +#endif
94000 +
94001 /* Can addr have changed??
94002 *
94003 * Answer: Yes, several device drivers can do it in their
94004 @@ -1606,6 +1761,12 @@ munmap_back:
94005 }
94006
94007 vma_link(mm, vma, prev, rb_link, rb_parent);
94008 +
94009 +#ifdef CONFIG_PAX_SEGMEXEC
94010 + if (vma_m)
94011 + BUG_ON(pax_mirror_vma(vma_m, vma));
94012 +#endif
94013 +
94014 /* Once vma denies write, undo our temporary denial count */
94015 if (vm_flags & VM_DENYWRITE)
94016 allow_write_access(file);
94017 @@ -1614,6 +1775,7 @@ out:
94018 perf_event_mmap(vma);
94019
94020 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94021 + track_exec_limit(mm, addr, addr + len, vm_flags);
94022 if (vm_flags & VM_LOCKED) {
94023 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94024 vma == get_gate_vma(current->mm)))
94025 @@ -1646,6 +1808,12 @@ unmap_and_free_vma:
94026 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94027 charged = 0;
94028 free_vma:
94029 +
94030 +#ifdef CONFIG_PAX_SEGMEXEC
94031 + if (vma_m)
94032 + kmem_cache_free(vm_area_cachep, vma_m);
94033 +#endif
94034 +
94035 kmem_cache_free(vm_area_cachep, vma);
94036 unacct_error:
94037 if (charged)
94038 @@ -1653,7 +1821,63 @@ unacct_error:
94039 return error;
94040 }
94041
94042 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94043 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94044 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94045 +{
94046 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94047 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94048 +
94049 + return 0;
94050 +}
94051 +#endif
94052 +
94053 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94054 +{
94055 + if (!vma) {
94056 +#ifdef CONFIG_STACK_GROWSUP
94057 + if (addr > sysctl_heap_stack_gap)
94058 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94059 + else
94060 + vma = find_vma(current->mm, 0);
94061 + if (vma && (vma->vm_flags & VM_GROWSUP))
94062 + return false;
94063 +#endif
94064 + return true;
94065 + }
94066 +
94067 + if (addr + len > vma->vm_start)
94068 + return false;
94069 +
94070 + if (vma->vm_flags & VM_GROWSDOWN)
94071 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94072 +#ifdef CONFIG_STACK_GROWSUP
94073 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94074 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94075 +#endif
94076 + else if (offset)
94077 + return offset <= vma->vm_start - addr - len;
94078 +
94079 + return true;
94080 +}
94081 +
94082 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94083 +{
94084 + if (vma->vm_start < len)
94085 + return -ENOMEM;
94086 +
94087 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
94088 + if (offset <= vma->vm_start - len)
94089 + return vma->vm_start - len - offset;
94090 + else
94091 + return -ENOMEM;
94092 + }
94093 +
94094 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
94095 + return vma->vm_start - len - sysctl_heap_stack_gap;
94096 + return -ENOMEM;
94097 +}
94098 +
94099 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94100 {
94101 /*
94102 * We implement the search by looking for an rbtree node that
94103 @@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94104 }
94105 }
94106
94107 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94108 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94109 check_current:
94110 /* Check if current node has a suitable gap */
94111 if (gap_start > high_limit)
94112 return -ENOMEM;
94113 +
94114 + if (gap_end - gap_start > info->threadstack_offset)
94115 + gap_start += info->threadstack_offset;
94116 + else
94117 + gap_start = gap_end;
94118 +
94119 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94120 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94121 + gap_start += sysctl_heap_stack_gap;
94122 + else
94123 + gap_start = gap_end;
94124 + }
94125 + if (vma->vm_flags & VM_GROWSDOWN) {
94126 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94127 + gap_end -= sysctl_heap_stack_gap;
94128 + else
94129 + gap_end = gap_start;
94130 + }
94131 if (gap_end >= low_limit && gap_end - gap_start >= length)
94132 goto found;
94133
94134 @@ -1755,7 +1997,7 @@ found:
94135 return gap_start;
94136 }
94137
94138 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94139 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94140 {
94141 struct mm_struct *mm = current->mm;
94142 struct vm_area_struct *vma;
94143 @@ -1809,6 +2051,24 @@ check_current:
94144 gap_end = vma->vm_start;
94145 if (gap_end < low_limit)
94146 return -ENOMEM;
94147 +
94148 + if (gap_end - gap_start > info->threadstack_offset)
94149 + gap_end -= info->threadstack_offset;
94150 + else
94151 + gap_end = gap_start;
94152 +
94153 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94154 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94155 + gap_start += sysctl_heap_stack_gap;
94156 + else
94157 + gap_start = gap_end;
94158 + }
94159 + if (vma->vm_flags & VM_GROWSDOWN) {
94160 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94161 + gap_end -= sysctl_heap_stack_gap;
94162 + else
94163 + gap_end = gap_start;
94164 + }
94165 if (gap_start <= high_limit && gap_end - gap_start >= length)
94166 goto found;
94167
94168 @@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94169 struct mm_struct *mm = current->mm;
94170 struct vm_area_struct *vma;
94171 struct vm_unmapped_area_info info;
94172 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94173
94174 if (len > TASK_SIZE - mmap_min_addr)
94175 return -ENOMEM;
94176 @@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94177 if (flags & MAP_FIXED)
94178 return addr;
94179
94180 +#ifdef CONFIG_PAX_RANDMMAP
94181 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94182 +#endif
94183 +
94184 if (addr) {
94185 addr = PAGE_ALIGN(addr);
94186 vma = find_vma(mm, addr);
94187 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94188 - (!vma || addr + len <= vma->vm_start))
94189 + check_heap_stack_gap(vma, addr, len, offset))
94190 return addr;
94191 }
94192
94193 @@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94194 info.low_limit = mm->mmap_base;
94195 info.high_limit = TASK_SIZE;
94196 info.align_mask = 0;
94197 + info.threadstack_offset = offset;
94198 return vm_unmapped_area(&info);
94199 }
94200 #endif
94201 @@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94202 struct mm_struct *mm = current->mm;
94203 unsigned long addr = addr0;
94204 struct vm_unmapped_area_info info;
94205 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94206
94207 /* requested length too big for entire address space */
94208 if (len > TASK_SIZE - mmap_min_addr)
94209 @@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94210 if (flags & MAP_FIXED)
94211 return addr;
94212
94213 +#ifdef CONFIG_PAX_RANDMMAP
94214 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94215 +#endif
94216 +
94217 /* requesting a specific address */
94218 if (addr) {
94219 addr = PAGE_ALIGN(addr);
94220 vma = find_vma(mm, addr);
94221 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94222 - (!vma || addr + len <= vma->vm_start))
94223 + check_heap_stack_gap(vma, addr, len, offset))
94224 return addr;
94225 }
94226
94227 @@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94228 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94229 info.high_limit = mm->mmap_base;
94230 info.align_mask = 0;
94231 + info.threadstack_offset = offset;
94232 addr = vm_unmapped_area(&info);
94233
94234 /*
94235 @@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94236 VM_BUG_ON(addr != -ENOMEM);
94237 info.flags = 0;
94238 info.low_limit = TASK_UNMAPPED_BASE;
94239 +
94240 +#ifdef CONFIG_PAX_RANDMMAP
94241 + if (mm->pax_flags & MF_PAX_RANDMMAP)
94242 + info.low_limit += mm->delta_mmap;
94243 +#endif
94244 +
94245 info.high_limit = TASK_SIZE;
94246 addr = vm_unmapped_area(&info);
94247 }
94248 @@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94249 return vma;
94250 }
94251
94252 +#ifdef CONFIG_PAX_SEGMEXEC
94253 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94254 +{
94255 + struct vm_area_struct *vma_m;
94256 +
94257 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94258 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94259 + BUG_ON(vma->vm_mirror);
94260 + return NULL;
94261 + }
94262 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94263 + vma_m = vma->vm_mirror;
94264 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94265 + BUG_ON(vma->vm_file != vma_m->vm_file);
94266 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94267 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94268 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94269 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94270 + return vma_m;
94271 +}
94272 +#endif
94273 +
94274 /*
94275 * Verify that the stack growth is acceptable and
94276 * update accounting. This is shared with both the
94277 @@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94278 return -ENOMEM;
94279
94280 /* Stack limit test */
94281 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
94282 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94283 return -ENOMEM;
94284
94285 @@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94286 locked = mm->locked_vm + grow;
94287 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94288 limit >>= PAGE_SHIFT;
94289 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94290 if (locked > limit && !capable(CAP_IPC_LOCK))
94291 return -ENOMEM;
94292 }
94293 @@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94294 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94295 * vma is the last one with address > vma->vm_end. Have to extend vma.
94296 */
94297 +#ifndef CONFIG_IA64
94298 +static
94299 +#endif
94300 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94301 {
94302 int error;
94303 + bool locknext;
94304
94305 if (!(vma->vm_flags & VM_GROWSUP))
94306 return -EFAULT;
94307
94308 + /* Also guard against wrapping around to address 0. */
94309 + if (address < PAGE_ALIGN(address+1))
94310 + address = PAGE_ALIGN(address+1);
94311 + else
94312 + return -ENOMEM;
94313 +
94314 /*
94315 * We must make sure the anon_vma is allocated
94316 * so that the anon_vma locking is not a noop.
94317 */
94318 if (unlikely(anon_vma_prepare(vma)))
94319 return -ENOMEM;
94320 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94321 + if (locknext && anon_vma_prepare(vma->vm_next))
94322 + return -ENOMEM;
94323 vma_lock_anon_vma(vma);
94324 + if (locknext)
94325 + vma_lock_anon_vma(vma->vm_next);
94326
94327 /*
94328 * vma->vm_start/vm_end cannot change under us because the caller
94329 * is required to hold the mmap_sem in read mode. We need the
94330 - * anon_vma lock to serialize against concurrent expand_stacks.
94331 - * Also guard against wrapping around to address 0.
94332 + * anon_vma locks to serialize against concurrent expand_stacks
94333 + * and expand_upwards.
94334 */
94335 - if (address < PAGE_ALIGN(address+4))
94336 - address = PAGE_ALIGN(address+4);
94337 - else {
94338 - vma_unlock_anon_vma(vma);
94339 - return -ENOMEM;
94340 - }
94341 error = 0;
94342
94343 /* Somebody else might have raced and expanded it already */
94344 - if (address > vma->vm_end) {
94345 + 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)
94346 + error = -ENOMEM;
94347 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94348 unsigned long size, grow;
94349
94350 size = address - vma->vm_start;
94351 @@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94352 }
94353 }
94354 }
94355 + if (locknext)
94356 + vma_unlock_anon_vma(vma->vm_next);
94357 vma_unlock_anon_vma(vma);
94358 khugepaged_enter_vma_merge(vma);
94359 validate_mm(vma->vm_mm);
94360 @@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
94361 unsigned long address)
94362 {
94363 int error;
94364 + bool lockprev = false;
94365 + struct vm_area_struct *prev;
94366
94367 /*
94368 * We must make sure the anon_vma is allocated
94369 @@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
94370 if (error)
94371 return error;
94372
94373 + prev = vma->vm_prev;
94374 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94375 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94376 +#endif
94377 + if (lockprev && anon_vma_prepare(prev))
94378 + return -ENOMEM;
94379 + if (lockprev)
94380 + vma_lock_anon_vma(prev);
94381 +
94382 vma_lock_anon_vma(vma);
94383
94384 /*
94385 @@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
94386 */
94387
94388 /* Somebody else might have raced and expanded it already */
94389 - if (address < vma->vm_start) {
94390 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94391 + error = -ENOMEM;
94392 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94393 unsigned long size, grow;
94394
94395 +#ifdef CONFIG_PAX_SEGMEXEC
94396 + struct vm_area_struct *vma_m;
94397 +
94398 + vma_m = pax_find_mirror_vma(vma);
94399 +#endif
94400 +
94401 size = vma->vm_end - address;
94402 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94403
94404 @@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
94405 vma->vm_pgoff -= grow;
94406 anon_vma_interval_tree_post_update_vma(vma);
94407 vma_gap_update(vma);
94408 +
94409 +#ifdef CONFIG_PAX_SEGMEXEC
94410 + if (vma_m) {
94411 + anon_vma_interval_tree_pre_update_vma(vma_m);
94412 + vma_m->vm_start -= grow << PAGE_SHIFT;
94413 + vma_m->vm_pgoff -= grow;
94414 + anon_vma_interval_tree_post_update_vma(vma_m);
94415 + vma_gap_update(vma_m);
94416 + }
94417 +#endif
94418 +
94419 spin_unlock(&vma->vm_mm->page_table_lock);
94420
94421 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94422 perf_event_mmap(vma);
94423 }
94424 }
94425 }
94426 vma_unlock_anon_vma(vma);
94427 + if (lockprev)
94428 + vma_unlock_anon_vma(prev);
94429 khugepaged_enter_vma_merge(vma);
94430 validate_mm(vma->vm_mm);
94431 return error;
94432 @@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94433 do {
94434 long nrpages = vma_pages(vma);
94435
94436 +#ifdef CONFIG_PAX_SEGMEXEC
94437 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94438 + vma = remove_vma(vma);
94439 + continue;
94440 + }
94441 +#endif
94442 +
94443 if (vma->vm_flags & VM_ACCOUNT)
94444 nr_accounted += nrpages;
94445 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94446 @@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94447 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94448 vma->vm_prev = NULL;
94449 do {
94450 +
94451 +#ifdef CONFIG_PAX_SEGMEXEC
94452 + if (vma->vm_mirror) {
94453 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94454 + vma->vm_mirror->vm_mirror = NULL;
94455 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
94456 + vma->vm_mirror = NULL;
94457 + }
94458 +#endif
94459 +
94460 vma_rb_erase(vma, &mm->mm_rb);
94461 mm->map_count--;
94462 tail_vma = vma;
94463 @@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94464 struct vm_area_struct *new;
94465 int err = -ENOMEM;
94466
94467 +#ifdef CONFIG_PAX_SEGMEXEC
94468 + struct vm_area_struct *vma_m, *new_m = NULL;
94469 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94470 +#endif
94471 +
94472 if (is_vm_hugetlb_page(vma) && (addr &
94473 ~(huge_page_mask(hstate_vma(vma)))))
94474 return -EINVAL;
94475
94476 +#ifdef CONFIG_PAX_SEGMEXEC
94477 + vma_m = pax_find_mirror_vma(vma);
94478 +#endif
94479 +
94480 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94481 if (!new)
94482 goto out_err;
94483
94484 +#ifdef CONFIG_PAX_SEGMEXEC
94485 + if (vma_m) {
94486 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94487 + if (!new_m) {
94488 + kmem_cache_free(vm_area_cachep, new);
94489 + goto out_err;
94490 + }
94491 + }
94492 +#endif
94493 +
94494 /* most fields are the same, copy all, and then fixup */
94495 *new = *vma;
94496
94497 @@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94498 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94499 }
94500
94501 +#ifdef CONFIG_PAX_SEGMEXEC
94502 + if (vma_m) {
94503 + *new_m = *vma_m;
94504 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
94505 + new_m->vm_mirror = new;
94506 + new->vm_mirror = new_m;
94507 +
94508 + if (new_below)
94509 + new_m->vm_end = addr_m;
94510 + else {
94511 + new_m->vm_start = addr_m;
94512 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94513 + }
94514 + }
94515 +#endif
94516 +
94517 err = vma_dup_policy(vma, new);
94518 if (err)
94519 goto out_free_vma;
94520 @@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94521 else
94522 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94523
94524 +#ifdef CONFIG_PAX_SEGMEXEC
94525 + if (!err && vma_m) {
94526 + struct mempolicy *pol = vma_policy(new);
94527 +
94528 + if (anon_vma_clone(new_m, vma_m))
94529 + goto out_free_mpol;
94530 +
94531 + mpol_get(pol);
94532 + set_vma_policy(new_m, pol);
94533 +
94534 + if (new_m->vm_file)
94535 + get_file(new_m->vm_file);
94536 +
94537 + if (new_m->vm_ops && new_m->vm_ops->open)
94538 + new_m->vm_ops->open(new_m);
94539 +
94540 + if (new_below)
94541 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94542 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94543 + else
94544 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94545 +
94546 + if (err) {
94547 + if (new_m->vm_ops && new_m->vm_ops->close)
94548 + new_m->vm_ops->close(new_m);
94549 + if (new_m->vm_file)
94550 + fput(new_m->vm_file);
94551 + mpol_put(pol);
94552 + }
94553 + }
94554 +#endif
94555 +
94556 /* Success. */
94557 if (!err)
94558 return 0;
94559 @@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94560 new->vm_ops->close(new);
94561 if (new->vm_file)
94562 fput(new->vm_file);
94563 - unlink_anon_vmas(new);
94564 out_free_mpol:
94565 mpol_put(vma_policy(new));
94566 out_free_vma:
94567 +
94568 +#ifdef CONFIG_PAX_SEGMEXEC
94569 + if (new_m) {
94570 + unlink_anon_vmas(new_m);
94571 + kmem_cache_free(vm_area_cachep, new_m);
94572 + }
94573 +#endif
94574 +
94575 + unlink_anon_vmas(new);
94576 kmem_cache_free(vm_area_cachep, new);
94577 out_err:
94578 return err;
94579 @@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94580 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94581 unsigned long addr, int new_below)
94582 {
94583 +
94584 +#ifdef CONFIG_PAX_SEGMEXEC
94585 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94586 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94587 + if (mm->map_count >= sysctl_max_map_count-1)
94588 + return -ENOMEM;
94589 + } else
94590 +#endif
94591 +
94592 if (mm->map_count >= sysctl_max_map_count)
94593 return -ENOMEM;
94594
94595 @@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94596 * work. This now handles partial unmappings.
94597 * Jeremy Fitzhardinge <jeremy@goop.org>
94598 */
94599 +#ifdef CONFIG_PAX_SEGMEXEC
94600 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94601 {
94602 + int ret = __do_munmap(mm, start, len);
94603 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94604 + return ret;
94605 +
94606 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94607 +}
94608 +
94609 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94610 +#else
94611 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94612 +#endif
94613 +{
94614 unsigned long end;
94615 struct vm_area_struct *vma, *prev, *last;
94616
94617 + /*
94618 + * mm->mmap_sem is required to protect against another thread
94619 + * changing the mappings in case we sleep.
94620 + */
94621 + verify_mm_writelocked(mm);
94622 +
94623 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94624 return -EINVAL;
94625
94626 @@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94627 /* Fix up all other VM information */
94628 remove_vma_list(mm, vma);
94629
94630 + track_exec_limit(mm, start, end, 0UL);
94631 +
94632 return 0;
94633 }
94634
94635 @@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
94636 int ret;
94637 struct mm_struct *mm = current->mm;
94638
94639 +
94640 +#ifdef CONFIG_PAX_SEGMEXEC
94641 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94642 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94643 + return -EINVAL;
94644 +#endif
94645 +
94646 down_write(&mm->mmap_sem);
94647 ret = do_munmap(mm, start, len);
94648 up_write(&mm->mmap_sem);
94649 @@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94650 return vm_munmap(addr, len);
94651 }
94652
94653 -static inline void verify_mm_writelocked(struct mm_struct *mm)
94654 -{
94655 -#ifdef CONFIG_DEBUG_VM
94656 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94657 - WARN_ON(1);
94658 - up_read(&mm->mmap_sem);
94659 - }
94660 -#endif
94661 -}
94662 -
94663 /*
94664 * this is really a simplified "do_mmap". it only handles
94665 * anonymous maps. eventually we may be able to do some
94666 @@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94667 struct rb_node ** rb_link, * rb_parent;
94668 pgoff_t pgoff = addr >> PAGE_SHIFT;
94669 int error;
94670 + unsigned long charged;
94671
94672 len = PAGE_ALIGN(len);
94673 if (!len)
94674 @@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94675
94676 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94677
94678 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94679 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94680 + flags &= ~VM_EXEC;
94681 +
94682 +#ifdef CONFIG_PAX_MPROTECT
94683 + if (mm->pax_flags & MF_PAX_MPROTECT)
94684 + flags &= ~VM_MAYEXEC;
94685 +#endif
94686 +
94687 + }
94688 +#endif
94689 +
94690 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94691 if (error & ~PAGE_MASK)
94692 return error;
94693
94694 + charged = len >> PAGE_SHIFT;
94695 +
94696 error = mlock_future_check(mm, mm->def_flags, len);
94697 if (error)
94698 return error;
94699 @@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94700 /*
94701 * Clear old maps. this also does some error checking for us
94702 */
94703 - munmap_back:
94704 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94705 if (do_munmap(mm, addr, len))
94706 return -ENOMEM;
94707 - goto munmap_back;
94708 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94709 }
94710
94711 /* Check against address space limits *after* clearing old maps... */
94712 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94713 + if (!may_expand_vm(mm, charged))
94714 return -ENOMEM;
94715
94716 if (mm->map_count > sysctl_max_map_count)
94717 return -ENOMEM;
94718
94719 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94720 + if (security_vm_enough_memory_mm(mm, charged))
94721 return -ENOMEM;
94722
94723 /* Can we just expand an old private anonymous mapping? */
94724 @@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94725 */
94726 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94727 if (!vma) {
94728 - vm_unacct_memory(len >> PAGE_SHIFT);
94729 + vm_unacct_memory(charged);
94730 return -ENOMEM;
94731 }
94732
94733 @@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94734 vma_link(mm, vma, prev, rb_link, rb_parent);
94735 out:
94736 perf_event_mmap(vma);
94737 - mm->total_vm += len >> PAGE_SHIFT;
94738 + mm->total_vm += charged;
94739 if (flags & VM_LOCKED)
94740 - mm->locked_vm += (len >> PAGE_SHIFT);
94741 + mm->locked_vm += charged;
94742 vma->vm_flags |= VM_SOFTDIRTY;
94743 + track_exec_limit(mm, addr, addr + len, flags);
94744 return addr;
94745 }
94746
94747 @@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
94748 while (vma) {
94749 if (vma->vm_flags & VM_ACCOUNT)
94750 nr_accounted += vma_pages(vma);
94751 + vma->vm_mirror = NULL;
94752 vma = remove_vma(vma);
94753 }
94754 vm_unacct_memory(nr_accounted);
94755 @@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94756 struct vm_area_struct *prev;
94757 struct rb_node **rb_link, *rb_parent;
94758
94759 +#ifdef CONFIG_PAX_SEGMEXEC
94760 + struct vm_area_struct *vma_m = NULL;
94761 +#endif
94762 +
94763 + if (security_mmap_addr(vma->vm_start))
94764 + return -EPERM;
94765 +
94766 /*
94767 * The vm_pgoff of a purely anonymous vma should be irrelevant
94768 * until its first write fault, when page's anon_vma and index
94769 @@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94770 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94771 return -ENOMEM;
94772
94773 +#ifdef CONFIG_PAX_SEGMEXEC
94774 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94775 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94776 + if (!vma_m)
94777 + return -ENOMEM;
94778 + }
94779 +#endif
94780 +
94781 vma_link(mm, vma, prev, rb_link, rb_parent);
94782 +
94783 +#ifdef CONFIG_PAX_SEGMEXEC
94784 + if (vma_m)
94785 + BUG_ON(pax_mirror_vma(vma_m, vma));
94786 +#endif
94787 +
94788 return 0;
94789 }
94790
94791 @@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94792 struct rb_node **rb_link, *rb_parent;
94793 bool faulted_in_anon_vma = true;
94794
94795 + BUG_ON(vma->vm_mirror);
94796 +
94797 /*
94798 * If anonymous vma has not yet been faulted, update new pgoff
94799 * to match new location, to increase its chance of merging.
94800 @@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94801 return NULL;
94802 }
94803
94804 +#ifdef CONFIG_PAX_SEGMEXEC
94805 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94806 +{
94807 + struct vm_area_struct *prev_m;
94808 + struct rb_node **rb_link_m, *rb_parent_m;
94809 + struct mempolicy *pol_m;
94810 +
94811 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94812 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94813 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94814 + *vma_m = *vma;
94815 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94816 + if (anon_vma_clone(vma_m, vma))
94817 + return -ENOMEM;
94818 + pol_m = vma_policy(vma_m);
94819 + mpol_get(pol_m);
94820 + set_vma_policy(vma_m, pol_m);
94821 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94822 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94823 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94824 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94825 + if (vma_m->vm_file)
94826 + get_file(vma_m->vm_file);
94827 + if (vma_m->vm_ops && vma_m->vm_ops->open)
94828 + vma_m->vm_ops->open(vma_m);
94829 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94830 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94831 + vma_m->vm_mirror = vma;
94832 + vma->vm_mirror = vma_m;
94833 + return 0;
94834 +}
94835 +#endif
94836 +
94837 /*
94838 * Return true if the calling process may expand its vm space by the passed
94839 * number of pages
94840 @@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94841
94842 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94843
94844 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94845 if (cur + npages > lim)
94846 return 0;
94847 return 1;
94848 @@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
94849 vma->vm_start = addr;
94850 vma->vm_end = addr + len;
94851
94852 +#ifdef CONFIG_PAX_MPROTECT
94853 + if (mm->pax_flags & MF_PAX_MPROTECT) {
94854 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
94855 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94856 + return -EPERM;
94857 + if (!(vm_flags & VM_EXEC))
94858 + vm_flags &= ~VM_MAYEXEC;
94859 +#else
94860 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94861 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94862 +#endif
94863 + else
94864 + vm_flags &= ~VM_MAYWRITE;
94865 + }
94866 +#endif
94867 +
94868 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94869 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94870
94871 diff --git a/mm/mprotect.c b/mm/mprotect.c
94872 index 769a67a..414d24f 100644
94873 --- a/mm/mprotect.c
94874 +++ b/mm/mprotect.c
94875 @@ -24,10 +24,18 @@
94876 #include <linux/migrate.h>
94877 #include <linux/perf_event.h>
94878 #include <linux/ksm.h>
94879 +#include <linux/sched/sysctl.h>
94880 +
94881 +#ifdef CONFIG_PAX_MPROTECT
94882 +#include <linux/elf.h>
94883 +#include <linux/binfmts.h>
94884 +#endif
94885 +
94886 #include <asm/uaccess.h>
94887 #include <asm/pgtable.h>
94888 #include <asm/cacheflush.h>
94889 #include <asm/tlbflush.h>
94890 +#include <asm/mmu_context.h>
94891
94892 #ifndef pgprot_modify
94893 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94894 @@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94895 return pages;
94896 }
94897
94898 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94899 +/* called while holding the mmap semaphor for writing except stack expansion */
94900 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94901 +{
94902 + unsigned long oldlimit, newlimit = 0UL;
94903 +
94904 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94905 + return;
94906 +
94907 + spin_lock(&mm->page_table_lock);
94908 + oldlimit = mm->context.user_cs_limit;
94909 + if ((prot & VM_EXEC) && oldlimit < end)
94910 + /* USER_CS limit moved up */
94911 + newlimit = end;
94912 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94913 + /* USER_CS limit moved down */
94914 + newlimit = start;
94915 +
94916 + if (newlimit) {
94917 + mm->context.user_cs_limit = newlimit;
94918 +
94919 +#ifdef CONFIG_SMP
94920 + wmb();
94921 + cpus_clear(mm->context.cpu_user_cs_mask);
94922 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94923 +#endif
94924 +
94925 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94926 + }
94927 + spin_unlock(&mm->page_table_lock);
94928 + if (newlimit == end) {
94929 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
94930 +
94931 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
94932 + if (is_vm_hugetlb_page(vma))
94933 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94934 + else
94935 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94936 + }
94937 +}
94938 +#endif
94939 +
94940 int
94941 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94942 unsigned long start, unsigned long end, unsigned long newflags)
94943 @@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94944 int error;
94945 int dirty_accountable = 0;
94946
94947 +#ifdef CONFIG_PAX_SEGMEXEC
94948 + struct vm_area_struct *vma_m = NULL;
94949 + unsigned long start_m, end_m;
94950 +
94951 + start_m = start + SEGMEXEC_TASK_SIZE;
94952 + end_m = end + SEGMEXEC_TASK_SIZE;
94953 +#endif
94954 +
94955 if (newflags == oldflags) {
94956 *pprev = vma;
94957 return 0;
94958 }
94959
94960 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94961 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94962 +
94963 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94964 + return -ENOMEM;
94965 +
94966 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94967 + return -ENOMEM;
94968 + }
94969 +
94970 /*
94971 * If we make a private mapping writable we increase our commit;
94972 * but (without finer accounting) cannot reduce our commit if we
94973 @@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94974 }
94975 }
94976
94977 +#ifdef CONFIG_PAX_SEGMEXEC
94978 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94979 + if (start != vma->vm_start) {
94980 + error = split_vma(mm, vma, start, 1);
94981 + if (error)
94982 + goto fail;
94983 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94984 + *pprev = (*pprev)->vm_next;
94985 + }
94986 +
94987 + if (end != vma->vm_end) {
94988 + error = split_vma(mm, vma, end, 0);
94989 + if (error)
94990 + goto fail;
94991 + }
94992 +
94993 + if (pax_find_mirror_vma(vma)) {
94994 + error = __do_munmap(mm, start_m, end_m - start_m);
94995 + if (error)
94996 + goto fail;
94997 + } else {
94998 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94999 + if (!vma_m) {
95000 + error = -ENOMEM;
95001 + goto fail;
95002 + }
95003 + vma->vm_flags = newflags;
95004 + error = pax_mirror_vma(vma_m, vma);
95005 + if (error) {
95006 + vma->vm_flags = oldflags;
95007 + goto fail;
95008 + }
95009 + }
95010 + }
95011 +#endif
95012 +
95013 /*
95014 * First try to merge with previous and/or next vma.
95015 */
95016 @@ -277,9 +381,21 @@ success:
95017 * vm_flags and vm_page_prot are protected by the mmap_sem
95018 * held in write mode.
95019 */
95020 +
95021 +#ifdef CONFIG_PAX_SEGMEXEC
95022 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95023 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95024 +#endif
95025 +
95026 vma->vm_flags = newflags;
95027 +
95028 +#ifdef CONFIG_PAX_MPROTECT
95029 + if (mm->binfmt && mm->binfmt->handle_mprotect)
95030 + mm->binfmt->handle_mprotect(vma, newflags);
95031 +#endif
95032 +
95033 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95034 - vm_get_page_prot(newflags));
95035 + vm_get_page_prot(vma->vm_flags));
95036
95037 if (vma_wants_writenotify(vma)) {
95038 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95039 @@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95040 end = start + len;
95041 if (end <= start)
95042 return -ENOMEM;
95043 +
95044 +#ifdef CONFIG_PAX_SEGMEXEC
95045 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95046 + if (end > SEGMEXEC_TASK_SIZE)
95047 + return -EINVAL;
95048 + } else
95049 +#endif
95050 +
95051 + if (end > TASK_SIZE)
95052 + return -EINVAL;
95053 +
95054 if (!arch_validate_prot(prot))
95055 return -EINVAL;
95056
95057 @@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95058 /*
95059 * Does the application expect PROT_READ to imply PROT_EXEC:
95060 */
95061 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95062 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95063 prot |= PROT_EXEC;
95064
95065 vm_flags = calc_vm_prot_bits(prot);
95066 @@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95067 if (start > vma->vm_start)
95068 prev = vma;
95069
95070 +#ifdef CONFIG_PAX_MPROTECT
95071 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95072 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
95073 +#endif
95074 +
95075 for (nstart = start ; ; ) {
95076 unsigned long newflags;
95077
95078 @@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95079
95080 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95081 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95082 + if (prot & (PROT_WRITE | PROT_EXEC))
95083 + gr_log_rwxmprotect(vma);
95084 +
95085 + error = -EACCES;
95086 + goto out;
95087 + }
95088 +
95089 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95090 error = -EACCES;
95091 goto out;
95092 }
95093 @@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95094 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95095 if (error)
95096 goto out;
95097 +
95098 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
95099 +
95100 nstart = tmp;
95101
95102 if (nstart < prev->vm_end)
95103 diff --git a/mm/mremap.c b/mm/mremap.c
95104 index 0843feb..c3cde48 100644
95105 --- a/mm/mremap.c
95106 +++ b/mm/mremap.c
95107 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95108 continue;
95109 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95110 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95111 +
95112 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95113 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95114 + pte = pte_exprotect(pte);
95115 +#endif
95116 +
95117 pte = move_soft_dirty_pte(pte);
95118 set_pte_at(mm, new_addr, new_pte, pte);
95119 }
95120 @@ -194,10 +200,17 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
95121 break;
95122 if (pmd_trans_huge(*old_pmd)) {
95123 int err = 0;
95124 - if (extent == HPAGE_PMD_SIZE)
95125 + if (extent == HPAGE_PMD_SIZE) {
95126 + VM_BUG_ON(vma->vm_file || !vma->anon_vma);
95127 + /* See comment in move_ptes() */
95128 + if (need_rmap_locks)
95129 + anon_vma_lock_write(vma->anon_vma);
95130 err = move_huge_pmd(vma, new_vma, old_addr,
95131 new_addr, old_end,
95132 old_pmd, new_pmd);
95133 + if (need_rmap_locks)
95134 + anon_vma_unlock_write(vma->anon_vma);
95135 + }
95136 if (err > 0) {
95137 need_flush = true;
95138 continue;
95139 @@ -337,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95140 if (is_vm_hugetlb_page(vma))
95141 goto Einval;
95142
95143 +#ifdef CONFIG_PAX_SEGMEXEC
95144 + if (pax_find_mirror_vma(vma))
95145 + goto Einval;
95146 +#endif
95147 +
95148 /* We can't remap across vm area boundaries */
95149 if (old_len > vma->vm_end - addr)
95150 goto Efault;
95151 @@ -392,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95152 unsigned long ret = -EINVAL;
95153 unsigned long charged = 0;
95154 unsigned long map_flags;
95155 + unsigned long pax_task_size = TASK_SIZE;
95156
95157 if (new_addr & ~PAGE_MASK)
95158 goto out;
95159
95160 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95161 +#ifdef CONFIG_PAX_SEGMEXEC
95162 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95163 + pax_task_size = SEGMEXEC_TASK_SIZE;
95164 +#endif
95165 +
95166 + pax_task_size -= PAGE_SIZE;
95167 +
95168 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95169 goto out;
95170
95171 /* Check if the location we're moving into overlaps the
95172 * old location at all, and fail if it does.
95173 */
95174 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
95175 - goto out;
95176 -
95177 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
95178 + if (addr + old_len > new_addr && new_addr + new_len > addr)
95179 goto out;
95180
95181 ret = do_munmap(mm, new_addr, new_len);
95182 @@ -474,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95183 unsigned long ret = -EINVAL;
95184 unsigned long charged = 0;
95185 bool locked = false;
95186 + unsigned long pax_task_size = TASK_SIZE;
95187
95188 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95189 return ret;
95190 @@ -495,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95191 if (!new_len)
95192 return ret;
95193
95194 +#ifdef CONFIG_PAX_SEGMEXEC
95195 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95196 + pax_task_size = SEGMEXEC_TASK_SIZE;
95197 +#endif
95198 +
95199 + pax_task_size -= PAGE_SIZE;
95200 +
95201 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95202 + old_len > pax_task_size || addr > pax_task_size-old_len)
95203 + return ret;
95204 +
95205 down_write(&current->mm->mmap_sem);
95206
95207 if (flags & MREMAP_FIXED) {
95208 @@ -545,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95209 new_addr = addr;
95210 }
95211 ret = addr;
95212 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95213 goto out;
95214 }
95215 }
95216 @@ -568,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95217 goto out;
95218 }
95219
95220 + map_flags = vma->vm_flags;
95221 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95222 + if (!(ret & ~PAGE_MASK)) {
95223 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95224 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95225 + }
95226 }
95227 out:
95228 if (ret & ~PAGE_MASK)
95229 diff --git a/mm/nommu.c b/mm/nommu.c
95230 index 8740213..f87e25b 100644
95231 --- a/mm/nommu.c
95232 +++ b/mm/nommu.c
95233 @@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95234 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95235 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95236 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95237 -int heap_stack_gap = 0;
95238
95239 atomic_long_t mmap_pages_allocated;
95240
95241 @@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95242 EXPORT_SYMBOL(find_vma);
95243
95244 /*
95245 - * find a VMA
95246 - * - we don't extend stack VMAs under NOMMU conditions
95247 - */
95248 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95249 -{
95250 - return find_vma(mm, addr);
95251 -}
95252 -
95253 -/*
95254 * expand a stack to a given address
95255 * - not supported under NOMMU conditions
95256 */
95257 @@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95258
95259 /* most fields are the same, copy all, and then fixup */
95260 *new = *vma;
95261 + INIT_LIST_HEAD(&new->anon_vma_chain);
95262 *region = *vma->vm_region;
95263 new->vm_region = region;
95264
95265 @@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95266 }
95267 EXPORT_SYMBOL(generic_file_remap_pages);
95268
95269 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95270 - unsigned long addr, void *buf, int len, int write)
95271 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95272 + unsigned long addr, void *buf, size_t len, int write)
95273 {
95274 struct vm_area_struct *vma;
95275
95276 @@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95277 *
95278 * The caller must hold a reference on @mm.
95279 */
95280 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95281 - void *buf, int len, int write)
95282 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95283 + void *buf, size_t len, int write)
95284 {
95285 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95286 }
95287 @@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95288 * Access another process' address space.
95289 * - source/target buffer must be kernel space
95290 */
95291 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95292 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95293 {
95294 struct mm_struct *mm;
95295
95296 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95297 index 7106cb1..0805f48 100644
95298 --- a/mm/page-writeback.c
95299 +++ b/mm/page-writeback.c
95300 @@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
95301 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95302 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95303 */
95304 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95305 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95306 unsigned long thresh,
95307 unsigned long bg_thresh,
95308 unsigned long dirty,
95309 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95310 index 7387a67..67105e4 100644
95311 --- a/mm/page_alloc.c
95312 +++ b/mm/page_alloc.c
95313 @@ -61,6 +61,7 @@
95314 #include <linux/page-debug-flags.h>
95315 #include <linux/hugetlb.h>
95316 #include <linux/sched/rt.h>
95317 +#include <linux/random.h>
95318
95319 #include <asm/sections.h>
95320 #include <asm/tlbflush.h>
95321 @@ -354,7 +355,7 @@ out:
95322 * This usage means that zero-order pages may not be compound.
95323 */
95324
95325 -static void free_compound_page(struct page *page)
95326 +void free_compound_page(struct page *page)
95327 {
95328 __free_pages_ok(page, compound_order(page));
95329 }
95330 @@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95331 int i;
95332 int bad = 0;
95333
95334 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95335 + unsigned long index = 1UL << order;
95336 +#endif
95337 +
95338 trace_mm_page_free(page, order);
95339 kmemcheck_free_shadow(page, order);
95340
95341 @@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95342 debug_check_no_obj_freed(page_address(page),
95343 PAGE_SIZE << order);
95344 }
95345 +
95346 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95347 + for (; index; --index)
95348 + sanitize_highpage(page + index - 1);
95349 +#endif
95350 +
95351 arch_free_page(page, order);
95352 kernel_map_pages(page, 1 << order, 0);
95353
95354 @@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95355 local_irq_restore(flags);
95356 }
95357
95358 +#ifdef CONFIG_PAX_LATENT_ENTROPY
95359 +bool __meminitdata extra_latent_entropy;
95360 +
95361 +static int __init setup_pax_extra_latent_entropy(char *str)
95362 +{
95363 + extra_latent_entropy = true;
95364 + return 0;
95365 +}
95366 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95367 +
95368 +volatile u64 latent_entropy __latent_entropy;
95369 +EXPORT_SYMBOL(latent_entropy);
95370 +#endif
95371 +
95372 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95373 {
95374 unsigned int nr_pages = 1 << order;
95375 @@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95376 __ClearPageReserved(p);
95377 set_page_count(p, 0);
95378
95379 +#ifdef CONFIG_PAX_LATENT_ENTROPY
95380 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95381 + u64 hash = 0;
95382 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95383 + const u64 *data = lowmem_page_address(page);
95384 +
95385 + for (index = 0; index < end; index++)
95386 + hash ^= hash + data[index];
95387 + latent_entropy ^= hash;
95388 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95389 + }
95390 +#endif
95391 +
95392 page_zone(page)->managed_pages += nr_pages;
95393 set_page_refcounted(page);
95394 __free_pages(page, order);
95395 @@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95396 arch_alloc_page(page, order);
95397 kernel_map_pages(page, 1 << order, 1);
95398
95399 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
95400 if (gfp_flags & __GFP_ZERO)
95401 prep_zero_page(page, order, gfp_flags);
95402 +#endif
95403
95404 if (order && (gfp_flags & __GFP_COMP))
95405 prep_compound_page(page, order);
95406 @@ -2401,7 +2441,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95407 continue;
95408 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95409 high_wmark_pages(zone) - low_wmark_pages(zone) -
95410 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95411 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95412 }
95413 }
95414
95415 @@ -6565,4 +6605,4 @@ void dump_page(struct page *page, char *reason)
95416 {
95417 dump_page_badflags(page, reason, 0);
95418 }
95419 -EXPORT_SYMBOL_GPL(dump_page);
95420 +EXPORT_SYMBOL(dump_page);
95421 diff --git a/mm/page_io.c b/mm/page_io.c
95422 index 7c59ef6..1358905 100644
95423 --- a/mm/page_io.c
95424 +++ b/mm/page_io.c
95425 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95426 struct file *swap_file = sis->swap_file;
95427 struct address_space *mapping = swap_file->f_mapping;
95428 struct iovec iov = {
95429 - .iov_base = kmap(page),
95430 + .iov_base = (void __force_user *)kmap(page),
95431 .iov_len = PAGE_SIZE,
95432 };
95433
95434 diff --git a/mm/percpu.c b/mm/percpu.c
95435 index 036cfe0..980d0fa 100644
95436 --- a/mm/percpu.c
95437 +++ b/mm/percpu.c
95438 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95439 static unsigned int pcpu_high_unit_cpu __read_mostly;
95440
95441 /* the address of the first chunk which starts with the kernel static area */
95442 -void *pcpu_base_addr __read_mostly;
95443 +void *pcpu_base_addr __read_only;
95444 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95445
95446 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95447 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95448 index fd26d04..0cea1b0 100644
95449 --- a/mm/process_vm_access.c
95450 +++ b/mm/process_vm_access.c
95451 @@ -13,6 +13,7 @@
95452 #include <linux/uio.h>
95453 #include <linux/sched.h>
95454 #include <linux/highmem.h>
95455 +#include <linux/security.h>
95456 #include <linux/ptrace.h>
95457 #include <linux/slab.h>
95458 #include <linux/syscalls.h>
95459 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95460 size_t iov_l_curr_offset = 0;
95461 ssize_t iov_len;
95462
95463 + return -ENOSYS; // PaX: until properly audited
95464 +
95465 /*
95466 * Work out how many pages of struct pages we're going to need
95467 * when eventually calling get_user_pages
95468 */
95469 for (i = 0; i < riovcnt; i++) {
95470 iov_len = rvec[i].iov_len;
95471 - if (iov_len > 0) {
95472 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
95473 - + iov_len)
95474 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95475 - / PAGE_SIZE + 1;
95476 - nr_pages = max(nr_pages, nr_pages_iov);
95477 - }
95478 + if (iov_len <= 0)
95479 + continue;
95480 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95481 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95482 + nr_pages = max(nr_pages, nr_pages_iov);
95483 }
95484
95485 if (nr_pages == 0)
95486 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95487 goto free_proc_pages;
95488 }
95489
95490 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95491 + rc = -EPERM;
95492 + goto put_task_struct;
95493 + }
95494 +
95495 mm = mm_access(task, PTRACE_MODE_ATTACH);
95496 if (!mm || IS_ERR(mm)) {
95497 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95498 diff --git a/mm/rmap.c b/mm/rmap.c
95499 index d3cbac5..0788da4 100644
95500 --- a/mm/rmap.c
95501 +++ b/mm/rmap.c
95502 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95503 struct anon_vma *anon_vma = vma->anon_vma;
95504 struct anon_vma_chain *avc;
95505
95506 +#ifdef CONFIG_PAX_SEGMEXEC
95507 + struct anon_vma_chain *avc_m = NULL;
95508 +#endif
95509 +
95510 might_sleep();
95511 if (unlikely(!anon_vma)) {
95512 struct mm_struct *mm = vma->vm_mm;
95513 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95514 if (!avc)
95515 goto out_enomem;
95516
95517 +#ifdef CONFIG_PAX_SEGMEXEC
95518 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95519 + if (!avc_m)
95520 + goto out_enomem_free_avc;
95521 +#endif
95522 +
95523 anon_vma = find_mergeable_anon_vma(vma);
95524 allocated = NULL;
95525 if (!anon_vma) {
95526 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95527 /* page_table_lock to protect against threads */
95528 spin_lock(&mm->page_table_lock);
95529 if (likely(!vma->anon_vma)) {
95530 +
95531 +#ifdef CONFIG_PAX_SEGMEXEC
95532 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95533 +
95534 + if (vma_m) {
95535 + BUG_ON(vma_m->anon_vma);
95536 + vma_m->anon_vma = anon_vma;
95537 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
95538 + avc_m = NULL;
95539 + }
95540 +#endif
95541 +
95542 vma->anon_vma = anon_vma;
95543 anon_vma_chain_link(vma, avc, anon_vma);
95544 allocated = NULL;
95545 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95546
95547 if (unlikely(allocated))
95548 put_anon_vma(allocated);
95549 +
95550 +#ifdef CONFIG_PAX_SEGMEXEC
95551 + if (unlikely(avc_m))
95552 + anon_vma_chain_free(avc_m);
95553 +#endif
95554 +
95555 if (unlikely(avc))
95556 anon_vma_chain_free(avc);
95557 }
95558 return 0;
95559
95560 out_enomem_free_avc:
95561 +
95562 +#ifdef CONFIG_PAX_SEGMEXEC
95563 + if (avc_m)
95564 + anon_vma_chain_free(avc_m);
95565 +#endif
95566 +
95567 anon_vma_chain_free(avc);
95568 out_enomem:
95569 return -ENOMEM;
95570 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95571 * Attach the anon_vmas from src to dst.
95572 * Returns 0 on success, -ENOMEM on failure.
95573 */
95574 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95575 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95576 {
95577 struct anon_vma_chain *avc, *pavc;
95578 struct anon_vma *root = NULL;
95579 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95580 * the corresponding VMA in the parent process is attached to.
95581 * Returns 0 on success, non-zero on failure.
95582 */
95583 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95584 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95585 {
95586 struct anon_vma_chain *avc;
95587 struct anon_vma *anon_vma;
95588 @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
95589 void __init anon_vma_init(void)
95590 {
95591 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95592 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95593 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95594 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95595 + anon_vma_ctor);
95596 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95597 + SLAB_PANIC|SLAB_NO_SANITIZE);
95598 }
95599
95600 /*
95601 diff --git a/mm/shmem.c b/mm/shmem.c
95602 index 1f18c9d..3e03d33 100644
95603 --- a/mm/shmem.c
95604 +++ b/mm/shmem.c
95605 @@ -33,7 +33,7 @@
95606 #include <linux/swap.h>
95607 #include <linux/aio.h>
95608
95609 -static struct vfsmount *shm_mnt;
95610 +struct vfsmount *shm_mnt;
95611
95612 #ifdef CONFIG_SHMEM
95613 /*
95614 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
95615 #define BOGO_DIRENT_SIZE 20
95616
95617 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95618 -#define SHORT_SYMLINK_LEN 128
95619 +#define SHORT_SYMLINK_LEN 64
95620
95621 /*
95622 * shmem_fallocate and shmem_writepage communicate via inode->i_private
95623 @@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95624 static int shmem_xattr_validate(const char *name)
95625 {
95626 struct { const char *prefix; size_t len; } arr[] = {
95627 +
95628 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95629 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95630 +#endif
95631 +
95632 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95633 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95634 };
95635 @@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95636 if (err)
95637 return err;
95638
95639 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95640 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95641 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95642 + return -EOPNOTSUPP;
95643 + if (size > 8)
95644 + return -EINVAL;
95645 + }
95646 +#endif
95647 +
95648 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95649 }
95650
95651 @@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95652 int err = -ENOMEM;
95653
95654 /* Round up to L1_CACHE_BYTES to resist false sharing */
95655 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95656 - L1_CACHE_BYTES), GFP_KERNEL);
95657 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95658 if (!sbinfo)
95659 return -ENOMEM;
95660
95661 diff --git a/mm/slab.c b/mm/slab.c
95662 index b264214..83872cd 100644
95663 --- a/mm/slab.c
95664 +++ b/mm/slab.c
95665 @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95666 if ((x)->max_freeable < i) \
95667 (x)->max_freeable = i; \
95668 } while (0)
95669 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95670 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95671 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95672 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95673 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95674 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95675 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95676 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95677 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95678 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95679 #else
95680 #define STATS_INC_ACTIVE(x) do { } while (0)
95681 #define STATS_DEC_ACTIVE(x) do { } while (0)
95682 @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95683 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95684 #define STATS_INC_FREEHIT(x) do { } while (0)
95685 #define STATS_INC_FREEMISS(x) do { } while (0)
95686 +#define STATS_INC_SANITIZED(x) do { } while (0)
95687 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95688 #endif
95689
95690 #if DEBUG
95691 @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95692 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95693 */
95694 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95695 - const struct page *page, void *obj)
95696 + const struct page *page, const void *obj)
95697 {
95698 u32 offset = (obj - page->s_mem);
95699 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95700 @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
95701 */
95702
95703 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95704 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95705 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95706
95707 if (INDEX_AC != INDEX_NODE)
95708 kmalloc_caches[INDEX_NODE] =
95709 create_kmalloc_cache("kmalloc-node",
95710 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95711 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95712
95713 slab_early_init = 0;
95714
95715 @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95716 struct array_cache *ac = cpu_cache_get(cachep);
95717
95718 check_irq_off();
95719 +
95720 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95721 + if (pax_sanitize_slab) {
95722 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95723 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95724 +
95725 + if (cachep->ctor)
95726 + cachep->ctor(objp);
95727 +
95728 + STATS_INC_SANITIZED(cachep);
95729 + } else
95730 + STATS_INC_NOT_SANITIZED(cachep);
95731 + }
95732 +#endif
95733 +
95734 kmemleak_free_recursive(objp, cachep->flags);
95735 objp = cache_free_debugcheck(cachep, objp, caller);
95736
95737 @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
95738
95739 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95740 return;
95741 + VM_BUG_ON(!virt_addr_valid(objp));
95742 local_irq_save(flags);
95743 kfree_debugcheck(objp);
95744 c = virt_to_cache(objp);
95745 @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95746 }
95747 /* cpu stats */
95748 {
95749 - unsigned long allochit = atomic_read(&cachep->allochit);
95750 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95751 - unsigned long freehit = atomic_read(&cachep->freehit);
95752 - unsigned long freemiss = atomic_read(&cachep->freemiss);
95753 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95754 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95755 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95756 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95757
95758 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95759 allochit, allocmiss, freehit, freemiss);
95760 }
95761 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95762 + {
95763 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95764 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95765 +
95766 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95767 + }
95768 +#endif
95769 #endif
95770 }
95771
95772 @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
95773 static int __init slab_proc_init(void)
95774 {
95775 #ifdef CONFIG_DEBUG_SLAB_LEAK
95776 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95777 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95778 #endif
95779 return 0;
95780 }
95781 module_init(slab_proc_init);
95782 #endif
95783
95784 +bool is_usercopy_object(const void *ptr)
95785 +{
95786 + struct page *page;
95787 + struct kmem_cache *cachep;
95788 +
95789 + if (ZERO_OR_NULL_PTR(ptr))
95790 + return false;
95791 +
95792 + if (!slab_is_available())
95793 + return false;
95794 +
95795 + if (!virt_addr_valid(ptr))
95796 + return false;
95797 +
95798 + page = virt_to_head_page(ptr);
95799 +
95800 + if (!PageSlab(page))
95801 + return false;
95802 +
95803 + cachep = page->slab_cache;
95804 + return cachep->flags & SLAB_USERCOPY;
95805 +}
95806 +
95807 +#ifdef CONFIG_PAX_USERCOPY
95808 +const char *check_heap_object(const void *ptr, unsigned long n)
95809 +{
95810 + struct page *page;
95811 + struct kmem_cache *cachep;
95812 + unsigned int objnr;
95813 + unsigned long offset;
95814 +
95815 + if (ZERO_OR_NULL_PTR(ptr))
95816 + return "<null>";
95817 +
95818 + if (!virt_addr_valid(ptr))
95819 + return NULL;
95820 +
95821 + page = virt_to_head_page(ptr);
95822 +
95823 + if (!PageSlab(page))
95824 + return NULL;
95825 +
95826 + cachep = page->slab_cache;
95827 + if (!(cachep->flags & SLAB_USERCOPY))
95828 + return cachep->name;
95829 +
95830 + objnr = obj_to_index(cachep, page, ptr);
95831 + BUG_ON(objnr >= cachep->num);
95832 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95833 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95834 + return NULL;
95835 +
95836 + return cachep->name;
95837 +}
95838 +#endif
95839 +
95840 /**
95841 * ksize - get the actual amount of memory allocated for a given object
95842 * @objp: Pointer to the object
95843 diff --git a/mm/slab.h b/mm/slab.h
95844 index 8184a7c..ab27737 100644
95845 --- a/mm/slab.h
95846 +++ b/mm/slab.h
95847 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95848 /* The slab cache that manages slab cache information */
95849 extern struct kmem_cache *kmem_cache;
95850
95851 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95852 +#ifdef CONFIG_X86_64
95853 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95854 +#else
95855 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95856 +#endif
95857 +extern bool pax_sanitize_slab;
95858 +#endif
95859 +
95860 unsigned long calculate_alignment(unsigned long flags,
95861 unsigned long align, unsigned long size);
95862
95863 @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95864
95865 /* Legal flag mask for kmem_cache_create(), for various configurations */
95866 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95867 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95868 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95869 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
95870
95871 #if defined(CONFIG_DEBUG_SLAB)
95872 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95873 @@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95874 return s;
95875
95876 page = virt_to_head_page(x);
95877 +
95878 + BUG_ON(!PageSlab(page));
95879 +
95880 cachep = page->slab_cache;
95881 if (slab_equal_or_root(cachep, s))
95882 return cachep;
95883 diff --git a/mm/slab_common.c b/mm/slab_common.c
95884 index 1ec3c61..2067c11 100644
95885 --- a/mm/slab_common.c
95886 +++ b/mm/slab_common.c
95887 @@ -23,11 +23,22 @@
95888
95889 #include "slab.h"
95890
95891 -enum slab_state slab_state;
95892 +enum slab_state slab_state __read_only;
95893 LIST_HEAD(slab_caches);
95894 DEFINE_MUTEX(slab_mutex);
95895 struct kmem_cache *kmem_cache;
95896
95897 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95898 +bool pax_sanitize_slab __read_only = true;
95899 +static int __init pax_sanitize_slab_setup(char *str)
95900 +{
95901 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95902 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95903 + return 1;
95904 +}
95905 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95906 +#endif
95907 +
95908 #ifdef CONFIG_DEBUG_VM
95909 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
95910 size_t size)
95911 @@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
95912 if (err)
95913 goto out_free_cache;
95914
95915 - s->refcount = 1;
95916 + atomic_set(&s->refcount, 1);
95917 list_add(&s->list, &slab_caches);
95918 memcg_register_cache(s);
95919
95920 @@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95921
95922 get_online_cpus();
95923 mutex_lock(&slab_mutex);
95924 - s->refcount--;
95925 - if (!s->refcount) {
95926 + if (atomic_dec_and_test(&s->refcount)) {
95927 list_del(&s->list);
95928
95929 if (!__kmem_cache_shutdown(s)) {
95930 @@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95931 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95932 name, size, err);
95933
95934 - s->refcount = -1; /* Exempt from merging for now */
95935 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95936 }
95937
95938 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95939 @@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95940
95941 create_boot_cache(s, name, size, flags);
95942 list_add(&s->list, &slab_caches);
95943 - s->refcount = 1;
95944 + atomic_set(&s->refcount, 1);
95945 return s;
95946 }
95947
95948 @@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
95949 EXPORT_SYMBOL(kmalloc_dma_caches);
95950 #endif
95951
95952 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95953 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
95954 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
95955 +#endif
95956 +
95957 /*
95958 * Conversion table for small slabs sizes / 8 to the index in the
95959 * kmalloc array. This is necessary for slabs < 192 since we have non power
95960 @@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
95961 return kmalloc_dma_caches[index];
95962
95963 #endif
95964 +
95965 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95966 + if (unlikely((flags & GFP_USERCOPY)))
95967 + return kmalloc_usercopy_caches[index];
95968 +
95969 +#endif
95970 +
95971 return kmalloc_caches[index];
95972 }
95973
95974 @@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
95975 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
95976 if (!kmalloc_caches[i]) {
95977 kmalloc_caches[i] = create_kmalloc_cache(NULL,
95978 - 1 << i, flags);
95979 + 1 << i, SLAB_USERCOPY | flags);
95980 }
95981
95982 /*
95983 @@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
95984 * earlier power of two caches
95985 */
95986 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
95987 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
95988 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
95989
95990 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
95991 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
95992 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
95993 }
95994
95995 /* Kmalloc array is now usable */
95996 @@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
95997 }
95998 }
95999 #endif
96000 +
96001 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96002 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96003 + struct kmem_cache *s = kmalloc_caches[i];
96004 +
96005 + if (s) {
96006 + int size = kmalloc_size(i);
96007 + char *n = kasprintf(GFP_NOWAIT,
96008 + "usercopy-kmalloc-%d", size);
96009 +
96010 + BUG_ON(!n);
96011 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96012 + size, SLAB_USERCOPY | flags);
96013 + }
96014 + }
96015 +#endif
96016 +
96017 }
96018 #endif /* !CONFIG_SLOB */
96019
96020 @@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
96021 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96022 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96023 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96024 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96025 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
96026 +#endif
96027 #endif
96028 seq_putc(m, '\n');
96029 }
96030 diff --git a/mm/slob.c b/mm/slob.c
96031 index 4bf8809..98a6914 100644
96032 --- a/mm/slob.c
96033 +++ b/mm/slob.c
96034 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96035 /*
96036 * Return the size of a slob block.
96037 */
96038 -static slobidx_t slob_units(slob_t *s)
96039 +static slobidx_t slob_units(const slob_t *s)
96040 {
96041 if (s->units > 0)
96042 return s->units;
96043 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96044 /*
96045 * Return the next free slob block pointer after this one.
96046 */
96047 -static slob_t *slob_next(slob_t *s)
96048 +static slob_t *slob_next(const slob_t *s)
96049 {
96050 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96051 slobidx_t next;
96052 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96053 /*
96054 * Returns true if s is the last free block in its page.
96055 */
96056 -static int slob_last(slob_t *s)
96057 +static int slob_last(const slob_t *s)
96058 {
96059 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96060 }
96061
96062 -static void *slob_new_pages(gfp_t gfp, int order, int node)
96063 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96064 {
96065 - void *page;
96066 + struct page *page;
96067
96068 #ifdef CONFIG_NUMA
96069 if (node != NUMA_NO_NODE)
96070 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96071 if (!page)
96072 return NULL;
96073
96074 - return page_address(page);
96075 + __SetPageSlab(page);
96076 + return page;
96077 }
96078
96079 -static void slob_free_pages(void *b, int order)
96080 +static void slob_free_pages(struct page *sp, int order)
96081 {
96082 if (current->reclaim_state)
96083 current->reclaim_state->reclaimed_slab += 1 << order;
96084 - free_pages((unsigned long)b, order);
96085 + __ClearPageSlab(sp);
96086 + page_mapcount_reset(sp);
96087 + sp->private = 0;
96088 + __free_pages(sp, order);
96089 }
96090
96091 /*
96092 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96093
96094 /* Not enough space: must allocate a new page */
96095 if (!b) {
96096 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96097 - if (!b)
96098 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96099 + if (!sp)
96100 return NULL;
96101 - sp = virt_to_page(b);
96102 - __SetPageSlab(sp);
96103 + b = page_address(sp);
96104
96105 spin_lock_irqsave(&slob_lock, flags);
96106 sp->units = SLOB_UNITS(PAGE_SIZE);
96107 sp->freelist = b;
96108 + sp->private = 0;
96109 INIT_LIST_HEAD(&sp->list);
96110 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96111 set_slob_page_free(sp, slob_list);
96112 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96113 if (slob_page_free(sp))
96114 clear_slob_page_free(sp);
96115 spin_unlock_irqrestore(&slob_lock, flags);
96116 - __ClearPageSlab(sp);
96117 - page_mapcount_reset(sp);
96118 - slob_free_pages(b, 0);
96119 + slob_free_pages(sp, 0);
96120 return;
96121 }
96122
96123 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96124 + if (pax_sanitize_slab)
96125 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96126 +#endif
96127 +
96128 if (!slob_page_free(sp)) {
96129 /* This slob page is about to become partially free. Easy! */
96130 sp->units = units;
96131 @@ -424,11 +431,10 @@ out:
96132 */
96133
96134 static __always_inline void *
96135 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96136 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96137 {
96138 - unsigned int *m;
96139 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96140 - void *ret;
96141 + slob_t *m;
96142 + void *ret = NULL;
96143
96144 gfp &= gfp_allowed_mask;
96145
96146 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96147
96148 if (!m)
96149 return NULL;
96150 - *m = size;
96151 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96152 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96153 + m[0].units = size;
96154 + m[1].units = align;
96155 ret = (void *)m + align;
96156
96157 trace_kmalloc_node(caller, ret,
96158 size, size + align, gfp, node);
96159 } else {
96160 unsigned int order = get_order(size);
96161 + struct page *page;
96162
96163 if (likely(order))
96164 gfp |= __GFP_COMP;
96165 - ret = slob_new_pages(gfp, order, node);
96166 + page = slob_new_pages(gfp, order, node);
96167 + if (page) {
96168 + ret = page_address(page);
96169 + page->private = size;
96170 + }
96171
96172 trace_kmalloc_node(caller, ret,
96173 size, PAGE_SIZE << order, gfp, node);
96174 }
96175
96176 - kmemleak_alloc(ret, size, 1, gfp);
96177 + return ret;
96178 +}
96179 +
96180 +static __always_inline void *
96181 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96182 +{
96183 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96184 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96185 +
96186 + if (!ZERO_OR_NULL_PTR(ret))
96187 + kmemleak_alloc(ret, size, 1, gfp);
96188 return ret;
96189 }
96190
96191 @@ -493,34 +517,112 @@ void kfree(const void *block)
96192 return;
96193 kmemleak_free(block);
96194
96195 + VM_BUG_ON(!virt_addr_valid(block));
96196 sp = virt_to_page(block);
96197 - if (PageSlab(sp)) {
96198 + VM_BUG_ON(!PageSlab(sp));
96199 + if (!sp->private) {
96200 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96201 - unsigned int *m = (unsigned int *)(block - align);
96202 - slob_free(m, *m + align);
96203 - } else
96204 + slob_t *m = (slob_t *)(block - align);
96205 + slob_free(m, m[0].units + align);
96206 + } else {
96207 + __ClearPageSlab(sp);
96208 + page_mapcount_reset(sp);
96209 + sp->private = 0;
96210 __free_pages(sp, compound_order(sp));
96211 + }
96212 }
96213 EXPORT_SYMBOL(kfree);
96214
96215 +bool is_usercopy_object(const void *ptr)
96216 +{
96217 + if (!slab_is_available())
96218 + return false;
96219 +
96220 + // PAX: TODO
96221 +
96222 + return false;
96223 +}
96224 +
96225 +#ifdef CONFIG_PAX_USERCOPY
96226 +const char *check_heap_object(const void *ptr, unsigned long n)
96227 +{
96228 + struct page *page;
96229 + const slob_t *free;
96230 + const void *base;
96231 + unsigned long flags;
96232 +
96233 + if (ZERO_OR_NULL_PTR(ptr))
96234 + return "<null>";
96235 +
96236 + if (!virt_addr_valid(ptr))
96237 + return NULL;
96238 +
96239 + page = virt_to_head_page(ptr);
96240 + if (!PageSlab(page))
96241 + return NULL;
96242 +
96243 + if (page->private) {
96244 + base = page;
96245 + if (base <= ptr && n <= page->private - (ptr - base))
96246 + return NULL;
96247 + return "<slob>";
96248 + }
96249 +
96250 + /* some tricky double walking to find the chunk */
96251 + spin_lock_irqsave(&slob_lock, flags);
96252 + base = (void *)((unsigned long)ptr & PAGE_MASK);
96253 + free = page->freelist;
96254 +
96255 + while (!slob_last(free) && (void *)free <= ptr) {
96256 + base = free + slob_units(free);
96257 + free = slob_next(free);
96258 + }
96259 +
96260 + while (base < (void *)free) {
96261 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96262 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
96263 + int offset;
96264 +
96265 + if (ptr < base + align)
96266 + break;
96267 +
96268 + offset = ptr - base - align;
96269 + if (offset >= m) {
96270 + base += size;
96271 + continue;
96272 + }
96273 +
96274 + if (n > m - offset)
96275 + break;
96276 +
96277 + spin_unlock_irqrestore(&slob_lock, flags);
96278 + return NULL;
96279 + }
96280 +
96281 + spin_unlock_irqrestore(&slob_lock, flags);
96282 + return "<slob>";
96283 +}
96284 +#endif
96285 +
96286 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96287 size_t ksize(const void *block)
96288 {
96289 struct page *sp;
96290 int align;
96291 - unsigned int *m;
96292 + slob_t *m;
96293
96294 BUG_ON(!block);
96295 if (unlikely(block == ZERO_SIZE_PTR))
96296 return 0;
96297
96298 sp = virt_to_page(block);
96299 - if (unlikely(!PageSlab(sp)))
96300 - return PAGE_SIZE << compound_order(sp);
96301 + VM_BUG_ON(!PageSlab(sp));
96302 + if (sp->private)
96303 + return sp->private;
96304
96305 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96306 - m = (unsigned int *)(block - align);
96307 - return SLOB_UNITS(*m) * SLOB_UNIT;
96308 + m = (slob_t *)(block - align);
96309 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96310 }
96311 EXPORT_SYMBOL(ksize);
96312
96313 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96314
96315 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96316 {
96317 - void *b;
96318 + void *b = NULL;
96319
96320 flags &= gfp_allowed_mask;
96321
96322 lockdep_trace_alloc(flags);
96323
96324 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96325 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96326 +#else
96327 if (c->size < PAGE_SIZE) {
96328 b = slob_alloc(c->size, flags, c->align, node);
96329 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96330 SLOB_UNITS(c->size) * SLOB_UNIT,
96331 flags, node);
96332 } else {
96333 - b = slob_new_pages(flags, get_order(c->size), node);
96334 + struct page *sp;
96335 +
96336 + sp = slob_new_pages(flags, get_order(c->size), node);
96337 + if (sp) {
96338 + b = page_address(sp);
96339 + sp->private = c->size;
96340 + }
96341 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96342 PAGE_SIZE << get_order(c->size),
96343 flags, node);
96344 }
96345 +#endif
96346
96347 if (b && c->ctor)
96348 c->ctor(b);
96349 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96350
96351 static void __kmem_cache_free(void *b, int size)
96352 {
96353 - if (size < PAGE_SIZE)
96354 + struct page *sp;
96355 +
96356 + sp = virt_to_page(b);
96357 + BUG_ON(!PageSlab(sp));
96358 + if (!sp->private)
96359 slob_free(b, size);
96360 else
96361 - slob_free_pages(b, get_order(size));
96362 + slob_free_pages(sp, get_order(size));
96363 }
96364
96365 static void kmem_rcu_free(struct rcu_head *head)
96366 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96367
96368 void kmem_cache_free(struct kmem_cache *c, void *b)
96369 {
96370 + int size = c->size;
96371 +
96372 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96373 + if (size + c->align < PAGE_SIZE) {
96374 + size += c->align;
96375 + b -= c->align;
96376 + }
96377 +#endif
96378 +
96379 kmemleak_free_recursive(b, c->flags);
96380 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96381 struct slob_rcu *slob_rcu;
96382 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96383 - slob_rcu->size = c->size;
96384 + slob_rcu = b + (size - sizeof(struct slob_rcu));
96385 + slob_rcu->size = size;
96386 call_rcu(&slob_rcu->head, kmem_rcu_free);
96387 } else {
96388 - __kmem_cache_free(b, c->size);
96389 + __kmem_cache_free(b, size);
96390 }
96391
96392 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96393 + trace_kfree(_RET_IP_, b);
96394 +#else
96395 trace_kmem_cache_free(_RET_IP_, b);
96396 +#endif
96397 +
96398 }
96399 EXPORT_SYMBOL(kmem_cache_free);
96400
96401 diff --git a/mm/slub.c b/mm/slub.c
96402 index 25f14ad..c904f6f 100644
96403 --- a/mm/slub.c
96404 +++ b/mm/slub.c
96405 @@ -207,7 +207,7 @@ struct track {
96406
96407 enum track_item { TRACK_ALLOC, TRACK_FREE };
96408
96409 -#ifdef CONFIG_SYSFS
96410 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96411 static int sysfs_slab_add(struct kmem_cache *);
96412 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96413 static void sysfs_slab_remove(struct kmem_cache *);
96414 @@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
96415 if (!t->addr)
96416 return;
96417
96418 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96419 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96420 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96421 #ifdef CONFIG_STACKTRACE
96422 {
96423 @@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96424
96425 slab_free_hook(s, x);
96426
96427 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96428 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96429 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96430 + if (s->ctor)
96431 + s->ctor(x);
96432 + }
96433 +#endif
96434 +
96435 redo:
96436 /*
96437 * Determine the currently cpus per cpu slab.
96438 @@ -2733,7 +2741,7 @@ static int slub_min_objects;
96439 * Merge control. If this is set then no merging of slab caches will occur.
96440 * (Could be removed. This was introduced to pacify the merge skeptics.)
96441 */
96442 -static int slub_nomerge;
96443 +static int slub_nomerge = 1;
96444
96445 /*
96446 * Calculate the order of allocation given an slab object size.
96447 @@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96448 s->inuse = size;
96449
96450 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96451 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96452 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96453 +#endif
96454 s->ctor)) {
96455 /*
96456 * Relocate free pointer after the object if it is not
96457 @@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96458 EXPORT_SYMBOL(__kmalloc_node);
96459 #endif
96460
96461 +bool is_usercopy_object(const void *ptr)
96462 +{
96463 + struct page *page;
96464 + struct kmem_cache *s;
96465 +
96466 + if (ZERO_OR_NULL_PTR(ptr))
96467 + return false;
96468 +
96469 + if (!slab_is_available())
96470 + return false;
96471 +
96472 + if (!virt_addr_valid(ptr))
96473 + return false;
96474 +
96475 + page = virt_to_head_page(ptr);
96476 +
96477 + if (!PageSlab(page))
96478 + return false;
96479 +
96480 + s = page->slab_cache;
96481 + return s->flags & SLAB_USERCOPY;
96482 +}
96483 +
96484 +#ifdef CONFIG_PAX_USERCOPY
96485 +const char *check_heap_object(const void *ptr, unsigned long n)
96486 +{
96487 + struct page *page;
96488 + struct kmem_cache *s;
96489 + unsigned long offset;
96490 +
96491 + if (ZERO_OR_NULL_PTR(ptr))
96492 + return "<null>";
96493 +
96494 + if (!virt_addr_valid(ptr))
96495 + return NULL;
96496 +
96497 + page = virt_to_head_page(ptr);
96498 +
96499 + if (!PageSlab(page))
96500 + return NULL;
96501 +
96502 + s = page->slab_cache;
96503 + if (!(s->flags & SLAB_USERCOPY))
96504 + return s->name;
96505 +
96506 + offset = (ptr - page_address(page)) % s->size;
96507 + if (offset <= s->object_size && n <= s->object_size - offset)
96508 + return NULL;
96509 +
96510 + return s->name;
96511 +}
96512 +#endif
96513 +
96514 size_t ksize(const void *object)
96515 {
96516 struct page *page;
96517 @@ -3387,6 +3451,7 @@ void kfree(const void *x)
96518 if (unlikely(ZERO_OR_NULL_PTR(x)))
96519 return;
96520
96521 + VM_BUG_ON(!virt_addr_valid(x));
96522 page = virt_to_head_page(x);
96523 if (unlikely(!PageSlab(page))) {
96524 BUG_ON(!PageCompound(page));
96525 @@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96526 /*
96527 * We may have set a slab to be unmergeable during bootstrap.
96528 */
96529 - if (s->refcount < 0)
96530 + if (atomic_read(&s->refcount) < 0)
96531 return 1;
96532
96533 return 0;
96534 @@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96535
96536 s = find_mergeable(memcg, size, align, flags, name, ctor);
96537 if (s) {
96538 - s->refcount++;
96539 + atomic_inc(&s->refcount);
96540 /*
96541 * Adjust the object sizes so that we clear
96542 * the complete object on kzalloc.
96543 @@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96544 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
96545
96546 if (sysfs_slab_alias(s, name)) {
96547 - s->refcount--;
96548 + atomic_dec(&s->refcount);
96549 s = NULL;
96550 }
96551 }
96552 @@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96553 }
96554 #endif
96555
96556 -#ifdef CONFIG_SYSFS
96557 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96558 static int count_inuse(struct page *page)
96559 {
96560 return page->inuse;
96561 @@ -4163,7 +4228,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
96562 len += sprintf(buf + len, "%7ld ", l->count);
96563
96564 if (l->addr)
96565 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96566 + len += sprintf(buf + len, "%pS", NULL);
96567 +#else
96568 len += sprintf(buf + len, "%pS", (void *)l->addr);
96569 +#endif
96570 else
96571 len += sprintf(buf + len, "<not-available>");
96572
96573 @@ -4268,12 +4337,12 @@ static void resiliency_test(void)
96574 validate_slab_cache(kmalloc_caches[9]);
96575 }
96576 #else
96577 -#ifdef CONFIG_SYSFS
96578 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96579 static void resiliency_test(void) {};
96580 #endif
96581 #endif
96582
96583 -#ifdef CONFIG_SYSFS
96584 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96585 enum slab_stat_type {
96586 SL_ALL, /* All slabs */
96587 SL_PARTIAL, /* Only partially allocated slabs */
96588 @@ -4513,13 +4582,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
96589 {
96590 if (!s->ctor)
96591 return 0;
96592 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96593 + return sprintf(buf, "%pS\n", NULL);
96594 +#else
96595 return sprintf(buf, "%pS\n", s->ctor);
96596 +#endif
96597 }
96598 SLAB_ATTR_RO(ctor);
96599
96600 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96601 {
96602 - return sprintf(buf, "%d\n", s->refcount - 1);
96603 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96604 }
96605 SLAB_ATTR_RO(aliases);
96606
96607 @@ -4607,6 +4680,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96608 SLAB_ATTR_RO(cache_dma);
96609 #endif
96610
96611 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96612 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96613 +{
96614 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96615 +}
96616 +SLAB_ATTR_RO(usercopy);
96617 +#endif
96618 +
96619 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96620 {
96621 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96622 @@ -4941,6 +5022,9 @@ static struct attribute *slab_attrs[] = {
96623 #ifdef CONFIG_ZONE_DMA
96624 &cache_dma_attr.attr,
96625 #endif
96626 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96627 + &usercopy_attr.attr,
96628 +#endif
96629 #ifdef CONFIG_NUMA
96630 &remote_node_defrag_ratio_attr.attr,
96631 #endif
96632 @@ -5173,6 +5257,7 @@ static char *create_unique_id(struct kmem_cache *s)
96633 return name;
96634 }
96635
96636 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96637 static int sysfs_slab_add(struct kmem_cache *s)
96638 {
96639 int err;
96640 @@ -5230,6 +5315,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
96641 kobject_del(&s->kobj);
96642 kobject_put(&s->kobj);
96643 }
96644 +#endif
96645
96646 /*
96647 * Need to buffer aliases during bootup until sysfs becomes
96648 @@ -5243,6 +5329,7 @@ struct saved_alias {
96649
96650 static struct saved_alias *alias_list;
96651
96652 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96653 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96654 {
96655 struct saved_alias *al;
96656 @@ -5265,6 +5352,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96657 alias_list = al;
96658 return 0;
96659 }
96660 +#endif
96661
96662 static int __init slab_sysfs_init(void)
96663 {
96664 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96665 index 4cba9c2..b4f9fcc 100644
96666 --- a/mm/sparse-vmemmap.c
96667 +++ b/mm/sparse-vmemmap.c
96668 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96669 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96670 if (!p)
96671 return NULL;
96672 - pud_populate(&init_mm, pud, p);
96673 + pud_populate_kernel(&init_mm, pud, p);
96674 }
96675 return pud;
96676 }
96677 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96678 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96679 if (!p)
96680 return NULL;
96681 - pgd_populate(&init_mm, pgd, p);
96682 + pgd_populate_kernel(&init_mm, pgd, p);
96683 }
96684 return pgd;
96685 }
96686 diff --git a/mm/sparse.c b/mm/sparse.c
96687 index 63c3ea5..95c0858 100644
96688 --- a/mm/sparse.c
96689 +++ b/mm/sparse.c
96690 @@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96691
96692 for (i = 0; i < PAGES_PER_SECTION; i++) {
96693 if (PageHWPoison(&memmap[i])) {
96694 - atomic_long_sub(1, &num_poisoned_pages);
96695 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
96696 ClearPageHWPoison(&memmap[i]);
96697 }
96698 }
96699 diff --git a/mm/swap.c b/mm/swap.c
96700 index 0092097..33361ff 100644
96701 --- a/mm/swap.c
96702 +++ b/mm/swap.c
96703 @@ -31,6 +31,7 @@
96704 #include <linux/memcontrol.h>
96705 #include <linux/gfp.h>
96706 #include <linux/uio.h>
96707 +#include <linux/hugetlb.h>
96708
96709 #include "internal.h"
96710
96711 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96712
96713 __page_cache_release(page);
96714 dtor = get_compound_page_dtor(page);
96715 + if (!PageHuge(page))
96716 + BUG_ON(dtor != free_compound_page);
96717 (*dtor)(page);
96718 }
96719
96720 diff --git a/mm/swapfile.c b/mm/swapfile.c
96721 index 4a7f7e6..22cddf5 100644
96722 --- a/mm/swapfile.c
96723 +++ b/mm/swapfile.c
96724 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96725
96726 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96727 /* Activity counter to indicate that a swapon or swapoff has occurred */
96728 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
96729 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96730
96731 static inline unsigned char swap_count(unsigned char ent)
96732 {
96733 @@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96734 spin_unlock(&swap_lock);
96735
96736 err = 0;
96737 - atomic_inc(&proc_poll_event);
96738 + atomic_inc_unchecked(&proc_poll_event);
96739 wake_up_interruptible(&proc_poll_wait);
96740
96741 out_dput:
96742 @@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96743
96744 poll_wait(file, &proc_poll_wait, wait);
96745
96746 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
96747 - seq->poll_event = atomic_read(&proc_poll_event);
96748 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96749 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96750 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96751 }
96752
96753 @@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96754 return ret;
96755
96756 seq = file->private_data;
96757 - seq->poll_event = atomic_read(&proc_poll_event);
96758 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96759 return 0;
96760 }
96761
96762 @@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96763 (frontswap_map) ? "FS" : "");
96764
96765 mutex_unlock(&swapon_mutex);
96766 - atomic_inc(&proc_poll_event);
96767 + atomic_inc_unchecked(&proc_poll_event);
96768 wake_up_interruptible(&proc_poll_wait);
96769
96770 if (S_ISREG(inode->i_mode))
96771 diff --git a/mm/util.c b/mm/util.c
96772 index a24aa22..a0d41ae 100644
96773 --- a/mm/util.c
96774 +++ b/mm/util.c
96775 @@ -297,6 +297,12 @@ done:
96776 void arch_pick_mmap_layout(struct mm_struct *mm)
96777 {
96778 mm->mmap_base = TASK_UNMAPPED_BASE;
96779 +
96780 +#ifdef CONFIG_PAX_RANDMMAP
96781 + if (mm->pax_flags & MF_PAX_RANDMMAP)
96782 + mm->mmap_base += mm->delta_mmap;
96783 +#endif
96784 +
96785 mm->get_unmapped_area = arch_get_unmapped_area;
96786 }
96787 #endif
96788 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96789 index 0fdf968..d6686e8 100644
96790 --- a/mm/vmalloc.c
96791 +++ b/mm/vmalloc.c
96792 @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96793
96794 pte = pte_offset_kernel(pmd, addr);
96795 do {
96796 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96797 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96798 +
96799 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96800 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
96801 + BUG_ON(!pte_exec(*pte));
96802 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
96803 + continue;
96804 + }
96805 +#endif
96806 +
96807 + {
96808 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96809 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96810 + }
96811 } while (pte++, addr += PAGE_SIZE, addr != end);
96812 }
96813
96814 @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
96815 pte = pte_alloc_kernel(pmd, addr);
96816 if (!pte)
96817 return -ENOMEM;
96818 +
96819 + pax_open_kernel();
96820 do {
96821 struct page *page = pages[*nr];
96822
96823 - if (WARN_ON(!pte_none(*pte)))
96824 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96825 + if (pgprot_val(prot) & _PAGE_NX)
96826 +#endif
96827 +
96828 + if (!pte_none(*pte)) {
96829 + pax_close_kernel();
96830 + WARN_ON(1);
96831 return -EBUSY;
96832 - if (WARN_ON(!page))
96833 + }
96834 + if (!page) {
96835 + pax_close_kernel();
96836 + WARN_ON(1);
96837 return -ENOMEM;
96838 + }
96839 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96840 (*nr)++;
96841 } while (pte++, addr += PAGE_SIZE, addr != end);
96842 + pax_close_kernel();
96843 return 0;
96844 }
96845
96846 @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96847 pmd_t *pmd;
96848 unsigned long next;
96849
96850 - pmd = pmd_alloc(&init_mm, pud, addr);
96851 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96852 if (!pmd)
96853 return -ENOMEM;
96854 do {
96855 @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
96856 pud_t *pud;
96857 unsigned long next;
96858
96859 - pud = pud_alloc(&init_mm, pgd, addr);
96860 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
96861 if (!pud)
96862 return -ENOMEM;
96863 do {
96864 @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
96865 if (addr >= MODULES_VADDR && addr < MODULES_END)
96866 return 1;
96867 #endif
96868 +
96869 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96870 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
96871 + return 1;
96872 +#endif
96873 +
96874 return is_vmalloc_addr(x);
96875 }
96876
96877 @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
96878
96879 if (!pgd_none(*pgd)) {
96880 pud_t *pud = pud_offset(pgd, addr);
96881 +#ifdef CONFIG_X86
96882 + if (!pud_large(*pud))
96883 +#endif
96884 if (!pud_none(*pud)) {
96885 pmd_t *pmd = pmd_offset(pud, addr);
96886 +#ifdef CONFIG_X86
96887 + if (!pmd_large(*pmd))
96888 +#endif
96889 if (!pmd_none(*pmd)) {
96890 pte_t *ptep, pte;
96891
96892 @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
96893 struct vm_struct *area;
96894
96895 BUG_ON(in_interrupt());
96896 +
96897 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96898 + if (flags & VM_KERNEXEC) {
96899 + if (start != VMALLOC_START || end != VMALLOC_END)
96900 + return NULL;
96901 + start = (unsigned long)MODULES_EXEC_VADDR;
96902 + end = (unsigned long)MODULES_EXEC_END;
96903 + }
96904 +#endif
96905 +
96906 if (flags & VM_IOREMAP)
96907 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
96908
96909 @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
96910 if (count > totalram_pages)
96911 return NULL;
96912
96913 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96914 + if (!(pgprot_val(prot) & _PAGE_NX))
96915 + flags |= VM_KERNEXEC;
96916 +#endif
96917 +
96918 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
96919 __builtin_return_address(0));
96920 if (!area)
96921 @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
96922 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
96923 goto fail;
96924
96925 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96926 + if (!(pgprot_val(prot) & _PAGE_NX))
96927 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
96928 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
96929 + else
96930 +#endif
96931 +
96932 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
96933 start, end, node, gfp_mask, caller);
96934 if (!area)
96935 @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
96936 * For tight control over page level allocator and protection flags
96937 * use __vmalloc() instead.
96938 */
96939 -
96940 void *vmalloc_exec(unsigned long size)
96941 {
96942 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
96943 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
96944 NUMA_NO_NODE, __builtin_return_address(0));
96945 }
96946
96947 @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
96948 {
96949 struct vm_struct *area;
96950
96951 + BUG_ON(vma->vm_mirror);
96952 +
96953 size = PAGE_ALIGN(size);
96954
96955 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
96956 @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
96957 v->addr, v->addr + v->size, v->size);
96958
96959 if (v->caller)
96960 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96961 + seq_printf(m, " %pK", v->caller);
96962 +#else
96963 seq_printf(m, " %pS", v->caller);
96964 +#endif
96965
96966 if (v->nr_pages)
96967 seq_printf(m, " pages=%d", v->nr_pages);
96968 diff --git a/mm/vmstat.c b/mm/vmstat.c
96969 index def5dd2..4ce55cec 100644
96970 --- a/mm/vmstat.c
96971 +++ b/mm/vmstat.c
96972 @@ -20,6 +20,7 @@
96973 #include <linux/writeback.h>
96974 #include <linux/compaction.h>
96975 #include <linux/mm_inline.h>
96976 +#include <linux/grsecurity.h>
96977
96978 #include "internal.h"
96979
96980 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
96981 *
96982 * vm_stat contains the global counters
96983 */
96984 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96985 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96986 EXPORT_SYMBOL(vm_stat);
96987
96988 #ifdef CONFIG_SMP
96989 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
96990
96991 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96992 if (diff[i])
96993 - atomic_long_add(diff[i], &vm_stat[i]);
96994 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
96995 }
96996
96997 /*
96998 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
96999 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97000 if (v) {
97001
97002 - atomic_long_add(v, &zone->vm_stat[i]);
97003 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97004 global_diff[i] += v;
97005 #ifdef CONFIG_NUMA
97006 /* 3 seconds idle till flush */
97007 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97008
97009 v = p->vm_stat_diff[i];
97010 p->vm_stat_diff[i] = 0;
97011 - atomic_long_add(v, &zone->vm_stat[i]);
97012 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97013 global_diff[i] += v;
97014 }
97015 }
97016 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97017 if (pset->vm_stat_diff[i]) {
97018 int v = pset->vm_stat_diff[i];
97019 pset->vm_stat_diff[i] = 0;
97020 - atomic_long_add(v, &zone->vm_stat[i]);
97021 - atomic_long_add(v, &vm_stat[i]);
97022 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97023 + atomic_long_add_unchecked(v, &vm_stat[i]);
97024 }
97025 }
97026 #endif
97027 @@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97028 stat_items_size += sizeof(struct vm_event_state);
97029 #endif
97030
97031 - v = kmalloc(stat_items_size, GFP_KERNEL);
97032 + v = kzalloc(stat_items_size, GFP_KERNEL);
97033 m->private = v;
97034 if (!v)
97035 return ERR_PTR(-ENOMEM);
97036 +
97037 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97038 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97039 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97040 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97041 + && !in_group_p(grsec_proc_gid)
97042 +#endif
97043 + )
97044 + return (unsigned long *)m->private + *pos;
97045 +#endif
97046 +#endif
97047 +
97048 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97049 v[i] = global_page_state(i);
97050 v += NR_VM_ZONE_STAT_ITEMS;
97051 @@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
97052 put_online_cpus();
97053 #endif
97054 #ifdef CONFIG_PROC_FS
97055 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97056 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97057 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97058 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97059 + {
97060 + mode_t gr_mode = S_IRUGO;
97061 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97062 + gr_mode = S_IRUSR;
97063 +#endif
97064 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97065 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97066 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97067 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97068 + }
97069 #endif
97070 return 0;
97071 }
97072 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97073 index 175273f..1c63e05 100644
97074 --- a/net/8021q/vlan.c
97075 +++ b/net/8021q/vlan.c
97076 @@ -474,7 +474,7 @@ out:
97077 return NOTIFY_DONE;
97078 }
97079
97080 -static struct notifier_block vlan_notifier_block __read_mostly = {
97081 +static struct notifier_block vlan_notifier_block = {
97082 .notifier_call = vlan_device_event,
97083 };
97084
97085 @@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97086 err = -EPERM;
97087 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97088 break;
97089 - if ((args.u.name_type >= 0) &&
97090 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97091 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97092 struct vlan_net *vn;
97093
97094 vn = net_generic(net, vlan_net_id);
97095 diff --git a/net/9p/client.c b/net/9p/client.c
97096 index 9186550..e604a2f 100644
97097 --- a/net/9p/client.c
97098 +++ b/net/9p/client.c
97099 @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97100 len - inline_len);
97101 } else {
97102 err = copy_from_user(ename + inline_len,
97103 - uidata, len - inline_len);
97104 + (char __force_user *)uidata, len - inline_len);
97105 if (err) {
97106 err = -EFAULT;
97107 goto out_err;
97108 @@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97109 kernel_buf = 1;
97110 indata = data;
97111 } else
97112 - indata = (__force char *)udata;
97113 + indata = (__force_kernel char *)udata;
97114 /*
97115 * response header len is 11
97116 * PDU Header(7) + IO Size (4)
97117 @@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97118 kernel_buf = 1;
97119 odata = data;
97120 } else
97121 - odata = (char *)udata;
97122 + odata = (char __force_kernel *)udata;
97123 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97124 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97125 fid->fid, offset, rsize);
97126 diff --git a/net/9p/mod.c b/net/9p/mod.c
97127 index 6ab36ae..6f1841b 100644
97128 --- a/net/9p/mod.c
97129 +++ b/net/9p/mod.c
97130 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97131 void v9fs_register_trans(struct p9_trans_module *m)
97132 {
97133 spin_lock(&v9fs_trans_lock);
97134 - list_add_tail(&m->list, &v9fs_trans_list);
97135 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97136 spin_unlock(&v9fs_trans_lock);
97137 }
97138 EXPORT_SYMBOL(v9fs_register_trans);
97139 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97140 void v9fs_unregister_trans(struct p9_trans_module *m)
97141 {
97142 spin_lock(&v9fs_trans_lock);
97143 - list_del_init(&m->list);
97144 + pax_list_del_init((struct list_head *)&m->list);
97145 spin_unlock(&v9fs_trans_lock);
97146 }
97147 EXPORT_SYMBOL(v9fs_unregister_trans);
97148 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97149 index b7bd7f2..2498bf7 100644
97150 --- a/net/9p/trans_fd.c
97151 +++ b/net/9p/trans_fd.c
97152 @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97153 oldfs = get_fs();
97154 set_fs(get_ds());
97155 /* The cast to a user pointer is valid due to the set_fs() */
97156 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97157 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97158 set_fs(oldfs);
97159
97160 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97161 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97162 index af46bc4..f9adfcd 100644
97163 --- a/net/appletalk/atalk_proc.c
97164 +++ b/net/appletalk/atalk_proc.c
97165 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97166 struct proc_dir_entry *p;
97167 int rc = -ENOMEM;
97168
97169 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97170 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97171 if (!atalk_proc_dir)
97172 goto out;
97173
97174 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97175 index 876fbe8..8bbea9f 100644
97176 --- a/net/atm/atm_misc.c
97177 +++ b/net/atm/atm_misc.c
97178 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97179 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97180 return 1;
97181 atm_return(vcc, truesize);
97182 - atomic_inc(&vcc->stats->rx_drop);
97183 + atomic_inc_unchecked(&vcc->stats->rx_drop);
97184 return 0;
97185 }
97186 EXPORT_SYMBOL(atm_charge);
97187 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97188 }
97189 }
97190 atm_return(vcc, guess);
97191 - atomic_inc(&vcc->stats->rx_drop);
97192 + atomic_inc_unchecked(&vcc->stats->rx_drop);
97193 return NULL;
97194 }
97195 EXPORT_SYMBOL(atm_alloc_charge);
97196 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97197
97198 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97199 {
97200 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97201 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97202 __SONET_ITEMS
97203 #undef __HANDLE_ITEM
97204 }
97205 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97206
97207 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97208 {
97209 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97210 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97211 __SONET_ITEMS
97212 #undef __HANDLE_ITEM
97213 }
97214 diff --git a/net/atm/lec.c b/net/atm/lec.c
97215 index 5a2f602..9396143 100644
97216 --- a/net/atm/lec.c
97217 +++ b/net/atm/lec.c
97218 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97219 }
97220
97221 static struct lane2_ops lane2_ops = {
97222 - lane2_resolve, /* resolve, spec 3.1.3 */
97223 - lane2_associate_req, /* associate_req, spec 3.1.4 */
97224 - NULL /* associate indicator, spec 3.1.5 */
97225 + .resolve = lane2_resolve,
97226 + .associate_req = lane2_associate_req,
97227 + .associate_indicator = NULL
97228 };
97229
97230 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97231 diff --git a/net/atm/lec.h b/net/atm/lec.h
97232 index 4149db1..f2ab682 100644
97233 --- a/net/atm/lec.h
97234 +++ b/net/atm/lec.h
97235 @@ -48,7 +48,7 @@ struct lane2_ops {
97236 const u8 *tlvs, u32 sizeoftlvs);
97237 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97238 const u8 *tlvs, u32 sizeoftlvs);
97239 -};
97240 +} __no_const;
97241
97242 /*
97243 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97244 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97245 index d1b2d9a..d549f7f 100644
97246 --- a/net/atm/mpoa_caches.c
97247 +++ b/net/atm/mpoa_caches.c
97248 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97249
97250
97251 static struct in_cache_ops ingress_ops = {
97252 - in_cache_add_entry, /* add_entry */
97253 - in_cache_get, /* get */
97254 - in_cache_get_with_mask, /* get_with_mask */
97255 - in_cache_get_by_vcc, /* get_by_vcc */
97256 - in_cache_put, /* put */
97257 - in_cache_remove_entry, /* remove_entry */
97258 - cache_hit, /* cache_hit */
97259 - clear_count_and_expired, /* clear_count */
97260 - check_resolving_entries, /* check_resolving */
97261 - refresh_entries, /* refresh */
97262 - in_destroy_cache /* destroy_cache */
97263 + .add_entry = in_cache_add_entry,
97264 + .get = in_cache_get,
97265 + .get_with_mask = in_cache_get_with_mask,
97266 + .get_by_vcc = in_cache_get_by_vcc,
97267 + .put = in_cache_put,
97268 + .remove_entry = in_cache_remove_entry,
97269 + .cache_hit = cache_hit,
97270 + .clear_count = clear_count_and_expired,
97271 + .check_resolving = check_resolving_entries,
97272 + .refresh = refresh_entries,
97273 + .destroy_cache = in_destroy_cache
97274 };
97275
97276 static struct eg_cache_ops egress_ops = {
97277 - eg_cache_add_entry, /* add_entry */
97278 - eg_cache_get_by_cache_id, /* get_by_cache_id */
97279 - eg_cache_get_by_tag, /* get_by_tag */
97280 - eg_cache_get_by_vcc, /* get_by_vcc */
97281 - eg_cache_get_by_src_ip, /* get_by_src_ip */
97282 - eg_cache_put, /* put */
97283 - eg_cache_remove_entry, /* remove_entry */
97284 - update_eg_cache_entry, /* update */
97285 - clear_expired, /* clear_expired */
97286 - eg_destroy_cache /* destroy_cache */
97287 + .add_entry = eg_cache_add_entry,
97288 + .get_by_cache_id = eg_cache_get_by_cache_id,
97289 + .get_by_tag = eg_cache_get_by_tag,
97290 + .get_by_vcc = eg_cache_get_by_vcc,
97291 + .get_by_src_ip = eg_cache_get_by_src_ip,
97292 + .put = eg_cache_put,
97293 + .remove_entry = eg_cache_remove_entry,
97294 + .update = update_eg_cache_entry,
97295 + .clear_expired = clear_expired,
97296 + .destroy_cache = eg_destroy_cache
97297 };
97298
97299
97300 diff --git a/net/atm/proc.c b/net/atm/proc.c
97301 index bbb6461..cf04016 100644
97302 --- a/net/atm/proc.c
97303 +++ b/net/atm/proc.c
97304 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97305 const struct k_atm_aal_stats *stats)
97306 {
97307 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97308 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97309 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97310 - atomic_read(&stats->rx_drop));
97311 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97312 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97313 + atomic_read_unchecked(&stats->rx_drop));
97314 }
97315
97316 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97317 diff --git a/net/atm/resources.c b/net/atm/resources.c
97318 index 0447d5d..3cf4728 100644
97319 --- a/net/atm/resources.c
97320 +++ b/net/atm/resources.c
97321 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97322 static void copy_aal_stats(struct k_atm_aal_stats *from,
97323 struct atm_aal_stats *to)
97324 {
97325 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97326 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97327 __AAL_STAT_ITEMS
97328 #undef __HANDLE_ITEM
97329 }
97330 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97331 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97332 struct atm_aal_stats *to)
97333 {
97334 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97335 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97336 __AAL_STAT_ITEMS
97337 #undef __HANDLE_ITEM
97338 }
97339 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97340 index 919a5ce..cc6b444 100644
97341 --- a/net/ax25/sysctl_net_ax25.c
97342 +++ b/net/ax25/sysctl_net_ax25.c
97343 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97344 {
97345 char path[sizeof("net/ax25/") + IFNAMSIZ];
97346 int k;
97347 - struct ctl_table *table;
97348 + ctl_table_no_const *table;
97349
97350 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97351 if (!table)
97352 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97353 index 8323bce..a03130d 100644
97354 --- a/net/batman-adv/bat_iv_ogm.c
97355 +++ b/net/batman-adv/bat_iv_ogm.c
97356 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97357
97358 /* randomize initial seqno to avoid collision */
97359 get_random_bytes(&random_seqno, sizeof(random_seqno));
97360 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97361 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97362
97363 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97364 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97365 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97366 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97367
97368 /* change sequence number to network order */
97369 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97370 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97371 batadv_ogm_packet->seqno = htonl(seqno);
97372 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97373 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97374
97375 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97376
97377 @@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97378 return;
97379
97380 /* could be changed by schedule_own_packet() */
97381 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97382 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97383
97384 if (ogm_packet->flags & BATADV_DIRECTLINK)
97385 has_directlink_flag = true;
97386 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97387 index 88df9b1..69cf7c0 100644
97388 --- a/net/batman-adv/fragmentation.c
97389 +++ b/net/batman-adv/fragmentation.c
97390 @@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97391 frag_header.packet_type = BATADV_UNICAST_FRAG;
97392 frag_header.version = BATADV_COMPAT_VERSION;
97393 frag_header.ttl = BATADV_TTL;
97394 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97395 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97396 frag_header.reserved = 0;
97397 frag_header.no = 0;
97398 frag_header.total_size = htons(skb->len);
97399 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97400 index f82c267..0e56d32 100644
97401 --- a/net/batman-adv/soft-interface.c
97402 +++ b/net/batman-adv/soft-interface.c
97403 @@ -283,7 +283,7 @@ send:
97404 primary_if->net_dev->dev_addr, ETH_ALEN);
97405
97406 /* set broadcast sequence number */
97407 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97408 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97409 bcast_packet->seqno = htonl(seqno);
97410
97411 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97412 @@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97413 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97414
97415 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97416 - atomic_set(&bat_priv->bcast_seqno, 1);
97417 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97418 atomic_set(&bat_priv->tt.vn, 0);
97419 atomic_set(&bat_priv->tt.local_changes, 0);
97420 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97421 @@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97422
97423 /* randomize initial seqno to avoid collision */
97424 get_random_bytes(&random_seqno, sizeof(random_seqno));
97425 - atomic_set(&bat_priv->frag_seqno, random_seqno);
97426 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97427
97428 bat_priv->primary_if = NULL;
97429 bat_priv->num_ifaces = 0;
97430 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97431 index 78370ab..1cb3614 100644
97432 --- a/net/batman-adv/types.h
97433 +++ b/net/batman-adv/types.h
97434 @@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
97435 struct batadv_hard_iface_bat_iv {
97436 unsigned char *ogm_buff;
97437 int ogm_buff_len;
97438 - atomic_t ogm_seqno;
97439 + atomic_unchecked_t ogm_seqno;
97440 };
97441
97442 /**
97443 @@ -714,7 +714,7 @@ struct batadv_priv {
97444 atomic_t bonding;
97445 atomic_t fragmentation;
97446 atomic_t packet_size_max;
97447 - atomic_t frag_seqno;
97448 + atomic_unchecked_t frag_seqno;
97449 #ifdef CONFIG_BATMAN_ADV_BLA
97450 atomic_t bridge_loop_avoidance;
97451 #endif
97452 @@ -730,7 +730,7 @@ struct batadv_priv {
97453 #endif
97454 uint32_t isolation_mark;
97455 uint32_t isolation_mark_mask;
97456 - atomic_t bcast_seqno;
97457 + atomic_unchecked_t bcast_seqno;
97458 atomic_t bcast_queue_left;
97459 atomic_t batman_queue_left;
97460 char num_ifaces;
97461 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97462 index 7552f9e..074ce29 100644
97463 --- a/net/bluetooth/hci_sock.c
97464 +++ b/net/bluetooth/hci_sock.c
97465 @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97466 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97467 }
97468
97469 - len = min_t(unsigned int, len, sizeof(uf));
97470 + len = min((size_t)len, sizeof(uf));
97471 if (copy_from_user(&uf, optval, len)) {
97472 err = -EFAULT;
97473 break;
97474 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97475 index b0ad2c7..96f6a5e 100644
97476 --- a/net/bluetooth/l2cap_core.c
97477 +++ b/net/bluetooth/l2cap_core.c
97478 @@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97479 break;
97480
97481 case L2CAP_CONF_RFC:
97482 - if (olen == sizeof(rfc))
97483 - memcpy(&rfc, (void *)val, olen);
97484 + if (olen != sizeof(rfc))
97485 + break;
97486 +
97487 + memcpy(&rfc, (void *)val, olen);
97488
97489 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97490 rfc.mode != chan->mode)
97491 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97492 index d58f76b..b69600a 100644
97493 --- a/net/bluetooth/l2cap_sock.c
97494 +++ b/net/bluetooth/l2cap_sock.c
97495 @@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97496 struct sock *sk = sock->sk;
97497 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97498 struct l2cap_options opts;
97499 - int len, err = 0;
97500 + int err = 0;
97501 + size_t len = optlen;
97502 u32 opt;
97503
97504 BT_DBG("sk %p", sk);
97505 @@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97506 opts.max_tx = chan->max_tx;
97507 opts.txwin_size = chan->tx_win;
97508
97509 - len = min_t(unsigned int, sizeof(opts), optlen);
97510 + len = min(sizeof(opts), len);
97511 if (copy_from_user((char *) &opts, optval, len)) {
97512 err = -EFAULT;
97513 break;
97514 @@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97515 struct bt_security sec;
97516 struct bt_power pwr;
97517 struct l2cap_conn *conn;
97518 - int len, err = 0;
97519 + int err = 0;
97520 + size_t len = optlen;
97521 u32 opt;
97522
97523 BT_DBG("sk %p", sk);
97524 @@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97525
97526 sec.level = BT_SECURITY_LOW;
97527
97528 - len = min_t(unsigned int, sizeof(sec), optlen);
97529 + len = min(sizeof(sec), len);
97530 if (copy_from_user((char *) &sec, optval, len)) {
97531 err = -EFAULT;
97532 break;
97533 @@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97534
97535 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97536
97537 - len = min_t(unsigned int, sizeof(pwr), optlen);
97538 + len = min(sizeof(pwr), len);
97539 if (copy_from_user((char *) &pwr, optval, len)) {
97540 err = -EFAULT;
97541 break;
97542 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97543 index 3c2d3e4..884855a 100644
97544 --- a/net/bluetooth/rfcomm/sock.c
97545 +++ b/net/bluetooth/rfcomm/sock.c
97546 @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97547 struct sock *sk = sock->sk;
97548 struct bt_security sec;
97549 int err = 0;
97550 - size_t len;
97551 + size_t len = optlen;
97552 u32 opt;
97553
97554 BT_DBG("sk %p", sk);
97555 @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97556
97557 sec.level = BT_SECURITY_LOW;
97558
97559 - len = min_t(unsigned int, sizeof(sec), optlen);
97560 + len = min(sizeof(sec), len);
97561 if (copy_from_user((char *) &sec, optval, len)) {
97562 err = -EFAULT;
97563 break;
97564 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97565 index f9c0980a..fcbbfeb 100644
97566 --- a/net/bluetooth/rfcomm/tty.c
97567 +++ b/net/bluetooth/rfcomm/tty.c
97568 @@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97569 BT_DBG("tty %p id %d", tty, tty->index);
97570
97571 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97572 - dev->channel, dev->port.count);
97573 + dev->channel, atomic_read(&dev->port.count));
97574
97575 err = tty_port_open(&dev->port, tty, filp);
97576 if (err)
97577 @@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97578 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97579
97580 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97581 - dev->port.count);
97582 + atomic_read(&dev->port.count));
97583
97584 tty_port_close(&dev->port, tty, filp);
97585 }
97586 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97587 index 0e474b1..fb7109c 100644
97588 --- a/net/bridge/netfilter/ebtables.c
97589 +++ b/net/bridge/netfilter/ebtables.c
97590 @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97591 tmp.valid_hooks = t->table->valid_hooks;
97592 }
97593 mutex_unlock(&ebt_mutex);
97594 - if (copy_to_user(user, &tmp, *len) != 0) {
97595 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97596 BUGPRINT("c2u Didn't work\n");
97597 ret = -EFAULT;
97598 break;
97599 @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97600 goto out;
97601 tmp.valid_hooks = t->valid_hooks;
97602
97603 - if (copy_to_user(user, &tmp, *len) != 0) {
97604 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97605 ret = -EFAULT;
97606 break;
97607 }
97608 @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97609 tmp.entries_size = t->table->entries_size;
97610 tmp.valid_hooks = t->table->valid_hooks;
97611
97612 - if (copy_to_user(user, &tmp, *len) != 0) {
97613 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97614 ret = -EFAULT;
97615 break;
97616 }
97617 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97618 index 0f45522..dab651f 100644
97619 --- a/net/caif/cfctrl.c
97620 +++ b/net/caif/cfctrl.c
97621 @@ -10,6 +10,7 @@
97622 #include <linux/spinlock.h>
97623 #include <linux/slab.h>
97624 #include <linux/pkt_sched.h>
97625 +#include <linux/sched.h>
97626 #include <net/caif/caif_layer.h>
97627 #include <net/caif/cfpkt.h>
97628 #include <net/caif/cfctrl.h>
97629 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97630 memset(&dev_info, 0, sizeof(dev_info));
97631 dev_info.id = 0xff;
97632 cfsrvl_init(&this->serv, 0, &dev_info, false);
97633 - atomic_set(&this->req_seq_no, 1);
97634 - atomic_set(&this->rsp_seq_no, 1);
97635 + atomic_set_unchecked(&this->req_seq_no, 1);
97636 + atomic_set_unchecked(&this->rsp_seq_no, 1);
97637 this->serv.layer.receive = cfctrl_recv;
97638 sprintf(this->serv.layer.name, "ctrl");
97639 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97640 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97641 struct cfctrl_request_info *req)
97642 {
97643 spin_lock_bh(&ctrl->info_list_lock);
97644 - atomic_inc(&ctrl->req_seq_no);
97645 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
97646 + atomic_inc_unchecked(&ctrl->req_seq_no);
97647 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97648 list_add_tail(&req->list, &ctrl->list);
97649 spin_unlock_bh(&ctrl->info_list_lock);
97650 }
97651 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97652 if (p != first)
97653 pr_warn("Requests are not received in order\n");
97654
97655 - atomic_set(&ctrl->rsp_seq_no,
97656 + atomic_set_unchecked(&ctrl->rsp_seq_no,
97657 p->sequence_no);
97658 list_del(&p->list);
97659 goto out;
97660 diff --git a/net/can/af_can.c b/net/can/af_can.c
97661 index a27f8aa..67174a3 100644
97662 --- a/net/can/af_can.c
97663 +++ b/net/can/af_can.c
97664 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97665 };
97666
97667 /* notifier block for netdevice event */
97668 -static struct notifier_block can_netdev_notifier __read_mostly = {
97669 +static struct notifier_block can_netdev_notifier = {
97670 .notifier_call = can_notifier,
97671 };
97672
97673 diff --git a/net/can/bcm.c b/net/can/bcm.c
97674 index dcb75c0..24b1b43 100644
97675 --- a/net/can/bcm.c
97676 +++ b/net/can/bcm.c
97677 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97678 }
97679
97680 /* create /proc/net/can-bcm directory */
97681 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97682 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97683 return 0;
97684 }
97685
97686 diff --git a/net/can/gw.c b/net/can/gw.c
97687 index ac31891..4799c17 100644
97688 --- a/net/can/gw.c
97689 +++ b/net/can/gw.c
97690 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97691 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97692
97693 static HLIST_HEAD(cgw_list);
97694 -static struct notifier_block notifier;
97695
97696 static struct kmem_cache *cgw_cache __read_mostly;
97697
97698 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97699 return err;
97700 }
97701
97702 +static struct notifier_block notifier = {
97703 + .notifier_call = cgw_notifier
97704 +};
97705 +
97706 static __init int cgw_module_init(void)
97707 {
97708 /* sanitize given module parameter */
97709 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97710 return -ENOMEM;
97711
97712 /* set notifier */
97713 - notifier.notifier_call = cgw_notifier;
97714 register_netdevice_notifier(&notifier);
97715
97716 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97717 diff --git a/net/can/proc.c b/net/can/proc.c
97718 index b543470..d2ddae2 100644
97719 --- a/net/can/proc.c
97720 +++ b/net/can/proc.c
97721 @@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97722 void can_init_proc(void)
97723 {
97724 /* create /proc/net/can directory */
97725 - can_dir = proc_mkdir("can", init_net.proc_net);
97726 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97727
97728 if (!can_dir) {
97729 printk(KERN_INFO "can: failed to create /proc/net/can . "
97730 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97731 index 30efc5c..cfa1bbc 100644
97732 --- a/net/ceph/messenger.c
97733 +++ b/net/ceph/messenger.c
97734 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97735 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97736
97737 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97738 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
97739 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97740
97741 static struct page *zero_page; /* used in certain error cases */
97742
97743 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97744 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97745 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
97746
97747 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97748 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97749 s = addr_str[i];
97750
97751 switch (ss->ss_family) {
97752 diff --git a/net/compat.c b/net/compat.c
97753 index f50161f..94fa415 100644
97754 --- a/net/compat.c
97755 +++ b/net/compat.c
97756 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
97757 return -EFAULT;
97758 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
97759 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
97760 - kmsg->msg_name = compat_ptr(tmp1);
97761 - kmsg->msg_iov = compat_ptr(tmp2);
97762 - kmsg->msg_control = compat_ptr(tmp3);
97763 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
97764 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
97765 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
97766 return 0;
97767 }
97768
97769 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97770
97771 if (kern_msg->msg_namelen) {
97772 if (mode == VERIFY_READ) {
97773 - int err = move_addr_to_kernel(kern_msg->msg_name,
97774 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
97775 kern_msg->msg_namelen,
97776 kern_address);
97777 if (err < 0)
97778 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97779 kern_msg->msg_name = NULL;
97780
97781 tot_len = iov_from_user_compat_to_kern(kern_iov,
97782 - (struct compat_iovec __user *)kern_msg->msg_iov,
97783 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
97784 kern_msg->msg_iovlen);
97785 if (tot_len >= 0)
97786 kern_msg->msg_iov = kern_iov;
97787 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97788
97789 #define CMSG_COMPAT_FIRSTHDR(msg) \
97790 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
97791 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97792 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
97793 (struct compat_cmsghdr __user *)NULL)
97794
97795 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
97796 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
97797 (ucmlen) <= (unsigned long) \
97798 ((mhdr)->msg_controllen - \
97799 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
97800 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
97801
97802 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
97803 struct compat_cmsghdr __user *cmsg, int cmsg_len)
97804 {
97805 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
97806 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
97807 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
97808 msg->msg_controllen)
97809 return NULL;
97810 return (struct compat_cmsghdr __user *)ptr;
97811 @@ -222,7 +222,7 @@ Efault:
97812
97813 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
97814 {
97815 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97816 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97817 struct compat_cmsghdr cmhdr;
97818 struct compat_timeval ctv;
97819 struct compat_timespec cts[3];
97820 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
97821
97822 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
97823 {
97824 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97825 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97826 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
97827 int fdnum = scm->fp->count;
97828 struct file **fp = scm->fp->fp;
97829 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
97830 return -EFAULT;
97831 old_fs = get_fs();
97832 set_fs(KERNEL_DS);
97833 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
97834 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
97835 set_fs(old_fs);
97836
97837 return err;
97838 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
97839 len = sizeof(ktime);
97840 old_fs = get_fs();
97841 set_fs(KERNEL_DS);
97842 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
97843 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
97844 set_fs(old_fs);
97845
97846 if (!err) {
97847 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97848 case MCAST_JOIN_GROUP:
97849 case MCAST_LEAVE_GROUP:
97850 {
97851 - struct compat_group_req __user *gr32 = (void *)optval;
97852 + struct compat_group_req __user *gr32 = (void __user *)optval;
97853 struct group_req __user *kgr =
97854 compat_alloc_user_space(sizeof(struct group_req));
97855 u32 interface;
97856 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97857 case MCAST_BLOCK_SOURCE:
97858 case MCAST_UNBLOCK_SOURCE:
97859 {
97860 - struct compat_group_source_req __user *gsr32 = (void *)optval;
97861 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
97862 struct group_source_req __user *kgsr = compat_alloc_user_space(
97863 sizeof(struct group_source_req));
97864 u32 interface;
97865 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97866 }
97867 case MCAST_MSFILTER:
97868 {
97869 - struct compat_group_filter __user *gf32 = (void *)optval;
97870 + struct compat_group_filter __user *gf32 = (void __user *)optval;
97871 struct group_filter __user *kgf;
97872 u32 interface, fmode, numsrc;
97873
97874 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
97875 char __user *optval, int __user *optlen,
97876 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
97877 {
97878 - struct compat_group_filter __user *gf32 = (void *)optval;
97879 + struct compat_group_filter __user *gf32 = (void __user *)optval;
97880 struct group_filter __user *kgf;
97881 int __user *koptlen;
97882 u32 interface, fmode, numsrc;
97883 @@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
97884
97885 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
97886 return -EINVAL;
97887 - if (copy_from_user(a, args, nas[call]))
97888 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
97889 return -EFAULT;
97890 a0 = a[0];
97891 a1 = a[1];
97892 diff --git a/net/core/datagram.c b/net/core/datagram.c
97893 index a16ed7b..eb44d17 100644
97894 --- a/net/core/datagram.c
97895 +++ b/net/core/datagram.c
97896 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
97897 }
97898
97899 kfree_skb(skb);
97900 - atomic_inc(&sk->sk_drops);
97901 + atomic_inc_unchecked(&sk->sk_drops);
97902 sk_mem_reclaim_partial(sk);
97903
97904 return err;
97905 diff --git a/net/core/dev.c b/net/core/dev.c
97906 index 45fa2f1..f3e28ec 100644
97907 --- a/net/core/dev.c
97908 +++ b/net/core/dev.c
97909 @@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
97910 {
97911 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
97912 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
97913 - atomic_long_inc(&dev->rx_dropped);
97914 + atomic_long_inc_unchecked(&dev->rx_dropped);
97915 kfree_skb(skb);
97916 return NET_RX_DROP;
97917 }
97918 }
97919
97920 if (unlikely(!is_skb_forwardable(dev, skb))) {
97921 - atomic_long_inc(&dev->rx_dropped);
97922 + atomic_long_inc_unchecked(&dev->rx_dropped);
97923 kfree_skb(skb);
97924 return NET_RX_DROP;
97925 }
97926 @@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
97927
97928 struct dev_gso_cb {
97929 void (*destructor)(struct sk_buff *skb);
97930 -};
97931 +} __no_const;
97932
97933 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
97934
97935 @@ -3227,7 +3227,7 @@ enqueue:
97936
97937 local_irq_restore(flags);
97938
97939 - atomic_long_inc(&skb->dev->rx_dropped);
97940 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97941 kfree_skb(skb);
97942 return NET_RX_DROP;
97943 }
97944 @@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
97945 }
97946 EXPORT_SYMBOL(netif_rx_ni);
97947
97948 -static void net_tx_action(struct softirq_action *h)
97949 +static __latent_entropy void net_tx_action(void)
97950 {
97951 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97952
97953 @@ -3645,7 +3645,7 @@ ncls:
97954 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
97955 } else {
97956 drop:
97957 - atomic_long_inc(&skb->dev->rx_dropped);
97958 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97959 kfree_skb(skb);
97960 /* Jamal, now you will not able to escape explaining
97961 * me how you were going to use this. :-)
97962 @@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
97963 }
97964 EXPORT_SYMBOL(netif_napi_del);
97965
97966 -static void net_rx_action(struct softirq_action *h)
97967 +static __latent_entropy void net_rx_action(void)
97968 {
97969 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97970 unsigned long time_limit = jiffies + 2;
97971 @@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
97972 } else {
97973 netdev_stats_to_stats64(storage, &dev->stats);
97974 }
97975 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
97976 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
97977 return storage;
97978 }
97979 EXPORT_SYMBOL(dev_get_stats);
97980 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
97981 index cf999e0..c59a975 100644
97982 --- a/net/core/dev_ioctl.c
97983 +++ b/net/core/dev_ioctl.c
97984 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
97985 if (no_module && capable(CAP_NET_ADMIN))
97986 no_module = request_module("netdev-%s", name);
97987 if (no_module && capable(CAP_SYS_MODULE)) {
97988 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
97989 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
97990 +#else
97991 if (!request_module("%s", name))
97992 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
97993 name);
97994 +#endif
97995 }
97996 }
97997 EXPORT_SYMBOL(dev_load);
97998 diff --git a/net/core/filter.c b/net/core/filter.c
97999 index ad30d62..21c0743 100644
98000 --- a/net/core/filter.c
98001 +++ b/net/core/filter.c
98002 @@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
98003 void *ptr;
98004 u32 A = 0; /* Accumulator */
98005 u32 X = 0; /* Index Register */
98006 - u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
98007 + u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
98008 u32 tmp;
98009 int k;
98010
98011 @@ -292,10 +292,10 @@ load_b:
98012 X = K;
98013 continue;
98014 case BPF_S_LD_MEM:
98015 - A = mem[K];
98016 + A = mem[K&15];
98017 continue;
98018 case BPF_S_LDX_MEM:
98019 - X = mem[K];
98020 + X = mem[K&15];
98021 continue;
98022 case BPF_S_MISC_TAX:
98023 X = A;
98024 @@ -308,10 +308,10 @@ load_b:
98025 case BPF_S_RET_A:
98026 return A;
98027 case BPF_S_ST:
98028 - mem[K] = A;
98029 + mem[K&15] = A;
98030 continue;
98031 case BPF_S_STX:
98032 - mem[K] = X;
98033 + mem[K&15] = X;
98034 continue;
98035 case BPF_S_ANC_PROTOCOL:
98036 A = ntohs(skb->protocol);
98037 @@ -355,6 +355,10 @@ load_b:
98038
98039 if (skb_is_nonlinear(skb))
98040 return 0;
98041 +
98042 + if (skb->len < sizeof(struct nlattr))
98043 + return 0;
98044 +
98045 if (A > skb->len - sizeof(struct nlattr))
98046 return 0;
98047
98048 @@ -371,11 +375,15 @@ load_b:
98049
98050 if (skb_is_nonlinear(skb))
98051 return 0;
98052 +
98053 + if (skb->len < sizeof(struct nlattr))
98054 + return 0;
98055 +
98056 if (A > skb->len - sizeof(struct nlattr))
98057 return 0;
98058
98059 nla = (struct nlattr *)&skb->data[A];
98060 - if (nla->nla_len > A - skb->len)
98061 + if (nla->nla_len > skb->len - A)
98062 return 0;
98063
98064 nla = nla_find_nested(nla, X);
98065 @@ -391,9 +399,10 @@ load_b:
98066 continue;
98067 #endif
98068 default:
98069 - WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
98070 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98071 fentry->code, fentry->jt,
98072 fentry->jf, fentry->k);
98073 + BUG();
98074 return 0;
98075 }
98076 }
98077 @@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98078 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98079 int pc, ret = 0;
98080
98081 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
98082 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
98083 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98084 if (!masks)
98085 return -ENOMEM;
98086 @@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98087 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
98088 if (!fp)
98089 return -ENOMEM;
98090 - memcpy(fp->insns, fprog->filter, fsize);
98091 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98092
98093 atomic_set(&fp->refcnt, 1);
98094 fp->len = fprog->len;
98095 diff --git a/net/core/flow.c b/net/core/flow.c
98096 index dfa602c..3103d88 100644
98097 --- a/net/core/flow.c
98098 +++ b/net/core/flow.c
98099 @@ -61,7 +61,7 @@ struct flow_cache {
98100 struct timer_list rnd_timer;
98101 };
98102
98103 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
98104 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
98105 EXPORT_SYMBOL(flow_cache_genid);
98106 static struct flow_cache flow_cache_global;
98107 static struct kmem_cache *flow_cachep __read_mostly;
98108 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98109
98110 static int flow_entry_valid(struct flow_cache_entry *fle)
98111 {
98112 - if (atomic_read(&flow_cache_genid) != fle->genid)
98113 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
98114 return 0;
98115 if (fle->object && !fle->object->ops->check(fle->object))
98116 return 0;
98117 @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98118 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98119 fcp->hash_count++;
98120 }
98121 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
98122 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
98123 flo = fle->object;
98124 if (!flo)
98125 goto ret_object;
98126 @@ -279,7 +279,7 @@ nocache:
98127 }
98128 flo = resolver(net, key, family, dir, flo, ctx);
98129 if (fle) {
98130 - fle->genid = atomic_read(&flow_cache_genid);
98131 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
98132 if (!IS_ERR(flo))
98133 fle->object = flo;
98134 else
98135 diff --git a/net/core/iovec.c b/net/core/iovec.c
98136 index b618694..192bbba 100644
98137 --- a/net/core/iovec.c
98138 +++ b/net/core/iovec.c
98139 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98140 if (m->msg_namelen) {
98141 if (mode == VERIFY_READ) {
98142 void __user *namep;
98143 - namep = (void __user __force *) m->msg_name;
98144 + namep = (void __force_user *) m->msg_name;
98145 err = move_addr_to_kernel(namep, m->msg_namelen,
98146 address);
98147 if (err < 0)
98148 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98149 }
98150
98151 size = m->msg_iovlen * sizeof(struct iovec);
98152 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98153 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98154 return -EFAULT;
98155
98156 m->msg_iov = iov;
98157 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98158 index e161290..8149aea 100644
98159 --- a/net/core/neighbour.c
98160 +++ b/net/core/neighbour.c
98161 @@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98162 void __user *buffer, size_t *lenp, loff_t *ppos)
98163 {
98164 int size, ret;
98165 - struct ctl_table tmp = *ctl;
98166 + ctl_table_no_const tmp = *ctl;
98167
98168 tmp.extra1 = &zero;
98169 tmp.extra2 = &unres_qlen_max;
98170 @@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98171 void __user *buffer,
98172 size_t *lenp, loff_t *ppos)
98173 {
98174 - struct ctl_table tmp = *ctl;
98175 + ctl_table_no_const tmp = *ctl;
98176 int ret;
98177
98178 tmp.extra1 = &zero;
98179 @@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98180 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98181 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98182 } else {
98183 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98184 dev_name_source = "default";
98185 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98186 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98187 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98188 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98189 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98190 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98191 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98192 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98193 }
98194
98195 if (handler) {
98196 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98197 index 2bf8329..2eb1423 100644
98198 --- a/net/core/net-procfs.c
98199 +++ b/net/core/net-procfs.c
98200 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98201 struct rtnl_link_stats64 temp;
98202 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98203
98204 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98205 + if (gr_proc_is_restricted())
98206 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98207 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98208 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98209 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98210 + else
98211 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98212 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98213 dev->name, stats->rx_bytes, stats->rx_packets,
98214 stats->rx_errors,
98215 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98216 return 0;
98217 }
98218
98219 -static const struct seq_operations dev_seq_ops = {
98220 +const struct seq_operations dev_seq_ops = {
98221 .start = dev_seq_start,
98222 .next = dev_seq_next,
98223 .stop = dev_seq_stop,
98224 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98225
98226 static int softnet_seq_open(struct inode *inode, struct file *file)
98227 {
98228 - return seq_open(file, &softnet_seq_ops);
98229 + return seq_open_restrict(file, &softnet_seq_ops);
98230 }
98231
98232 static const struct file_operations softnet_seq_fops = {
98233 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98234 else
98235 seq_printf(seq, "%04x", ntohs(pt->type));
98236
98237 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98238 + seq_printf(seq, " %-8s %pf\n",
98239 + pt->dev ? pt->dev->name : "", NULL);
98240 +#else
98241 seq_printf(seq, " %-8s %pf\n",
98242 pt->dev ? pt->dev->name : "", pt->func);
98243 +#endif
98244 }
98245
98246 return 0;
98247 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98248 index 81d3a9a..a0bd7a8 100644
98249 --- a/net/core/net_namespace.c
98250 +++ b/net/core/net_namespace.c
98251 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98252 int error;
98253 LIST_HEAD(net_exit_list);
98254
98255 - list_add_tail(&ops->list, list);
98256 + pax_list_add_tail((struct list_head *)&ops->list, list);
98257 if (ops->init || (ops->id && ops->size)) {
98258 for_each_net(net) {
98259 error = ops_init(ops, net);
98260 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98261
98262 out_undo:
98263 /* If I have an error cleanup all namespaces I initialized */
98264 - list_del(&ops->list);
98265 + pax_list_del((struct list_head *)&ops->list);
98266 ops_exit_list(ops, &net_exit_list);
98267 ops_free_list(ops, &net_exit_list);
98268 return error;
98269 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98270 struct net *net;
98271 LIST_HEAD(net_exit_list);
98272
98273 - list_del(&ops->list);
98274 + pax_list_del((struct list_head *)&ops->list);
98275 for_each_net(net)
98276 list_add_tail(&net->exit_list, &net_exit_list);
98277 ops_exit_list(ops, &net_exit_list);
98278 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98279 mutex_lock(&net_mutex);
98280 error = register_pernet_operations(&pernet_list, ops);
98281 if (!error && (first_device == &pernet_list))
98282 - first_device = &ops->list;
98283 + first_device = (struct list_head *)&ops->list;
98284 mutex_unlock(&net_mutex);
98285 return error;
98286 }
98287 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98288 index df9e6b1..6e68e4e 100644
98289 --- a/net/core/netpoll.c
98290 +++ b/net/core/netpoll.c
98291 @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98292 struct udphdr *udph;
98293 struct iphdr *iph;
98294 struct ethhdr *eth;
98295 - static atomic_t ip_ident;
98296 + static atomic_unchecked_t ip_ident;
98297 struct ipv6hdr *ip6h;
98298
98299 udp_len = len + sizeof(*udph);
98300 @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98301 put_unaligned(0x45, (unsigned char *)iph);
98302 iph->tos = 0;
98303 put_unaligned(htons(ip_len), &(iph->tot_len));
98304 - iph->id = htons(atomic_inc_return(&ip_ident));
98305 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98306 iph->frag_off = 0;
98307 iph->ttl = 64;
98308 iph->protocol = IPPROTO_UDP;
98309 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98310 index fdac61c..e5e5b46 100644
98311 --- a/net/core/pktgen.c
98312 +++ b/net/core/pktgen.c
98313 @@ -3719,7 +3719,7 @@ static int __net_init pg_net_init(struct net *net)
98314 pn->net = net;
98315 INIT_LIST_HEAD(&pn->pktgen_threads);
98316 pn->pktgen_exiting = false;
98317 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98318 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98319 if (!pn->proc_dir) {
98320 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98321 return -ENODEV;
98322 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98323 index 120eecc..cd1ec44 100644
98324 --- a/net/core/rtnetlink.c
98325 +++ b/net/core/rtnetlink.c
98326 @@ -58,7 +58,7 @@ struct rtnl_link {
98327 rtnl_doit_func doit;
98328 rtnl_dumpit_func dumpit;
98329 rtnl_calcit_func calcit;
98330 -};
98331 +} __no_const;
98332
98333 static DEFINE_MUTEX(rtnl_mutex);
98334
98335 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98336 if (rtnl_link_ops_get(ops->kind))
98337 return -EEXIST;
98338
98339 - if (!ops->dellink)
98340 - ops->dellink = unregister_netdevice_queue;
98341 + if (!ops->dellink) {
98342 + pax_open_kernel();
98343 + *(void **)&ops->dellink = unregister_netdevice_queue;
98344 + pax_close_kernel();
98345 + }
98346
98347 - list_add_tail(&ops->list, &link_ops);
98348 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98349 return 0;
98350 }
98351 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98352 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98353 for_each_net(net) {
98354 __rtnl_kill_links(net, ops);
98355 }
98356 - list_del(&ops->list);
98357 + pax_list_del((struct list_head *)&ops->list);
98358 }
98359 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98360
98361 diff --git a/net/core/scm.c b/net/core/scm.c
98362 index b442e7e..6f5b5a2 100644
98363 --- a/net/core/scm.c
98364 +++ b/net/core/scm.c
98365 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98366 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98367 {
98368 struct cmsghdr __user *cm
98369 - = (__force struct cmsghdr __user *)msg->msg_control;
98370 + = (struct cmsghdr __force_user *)msg->msg_control;
98371 struct cmsghdr cmhdr;
98372 int cmlen = CMSG_LEN(len);
98373 int err;
98374 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98375 err = -EFAULT;
98376 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98377 goto out;
98378 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98379 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98380 goto out;
98381 cmlen = CMSG_SPACE(len);
98382 if (msg->msg_controllen < cmlen)
98383 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98384 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98385 {
98386 struct cmsghdr __user *cm
98387 - = (__force struct cmsghdr __user*)msg->msg_control;
98388 + = (struct cmsghdr __force_user *)msg->msg_control;
98389
98390 int fdmax = 0;
98391 int fdnum = scm->fp->count;
98392 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98393 if (fdnum < fdmax)
98394 fdmax = fdnum;
98395
98396 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98397 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98398 i++, cmfptr++)
98399 {
98400 struct socket *sock;
98401 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98402 index 90b96a1..cd18f16d 100644
98403 --- a/net/core/skbuff.c
98404 +++ b/net/core/skbuff.c
98405 @@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98406 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98407 int len, __wsum csum)
98408 {
98409 - const struct skb_checksum_ops ops = {
98410 + static const struct skb_checksum_ops ops = {
98411 .update = csum_partial_ext,
98412 .combine = csum_block_add_ext,
98413 };
98414 @@ -3220,13 +3220,15 @@ void __init skb_init(void)
98415 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98416 sizeof(struct sk_buff),
98417 0,
98418 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98419 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98420 + SLAB_NO_SANITIZE,
98421 NULL);
98422 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98423 (2*sizeof(struct sk_buff)) +
98424 sizeof(atomic_t),
98425 0,
98426 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98427 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98428 + SLAB_NO_SANITIZE,
98429 NULL);
98430 }
98431
98432 diff --git a/net/core/sock.c b/net/core/sock.c
98433 index c0fc6bd..51d8326 100644
98434 --- a/net/core/sock.c
98435 +++ b/net/core/sock.c
98436 @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98437 struct sk_buff_head *list = &sk->sk_receive_queue;
98438
98439 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98440 - atomic_inc(&sk->sk_drops);
98441 + atomic_inc_unchecked(&sk->sk_drops);
98442 trace_sock_rcvqueue_full(sk, skb);
98443 return -ENOMEM;
98444 }
98445 @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98446 return err;
98447
98448 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98449 - atomic_inc(&sk->sk_drops);
98450 + atomic_inc_unchecked(&sk->sk_drops);
98451 return -ENOBUFS;
98452 }
98453
98454 @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98455 skb_dst_force(skb);
98456
98457 spin_lock_irqsave(&list->lock, flags);
98458 - skb->dropcount = atomic_read(&sk->sk_drops);
98459 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98460 __skb_queue_tail(list, skb);
98461 spin_unlock_irqrestore(&list->lock, flags);
98462
98463 @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98464 skb->dev = NULL;
98465
98466 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98467 - atomic_inc(&sk->sk_drops);
98468 + atomic_inc_unchecked(&sk->sk_drops);
98469 goto discard_and_relse;
98470 }
98471 if (nested)
98472 @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98473 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98474 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98475 bh_unlock_sock(sk);
98476 - atomic_inc(&sk->sk_drops);
98477 + atomic_inc_unchecked(&sk->sk_drops);
98478 goto discard_and_relse;
98479 }
98480
98481 @@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98482 struct timeval tm;
98483 } v;
98484
98485 - int lv = sizeof(int);
98486 - int len;
98487 + unsigned int lv = sizeof(int);
98488 + unsigned int len;
98489
98490 if (get_user(len, optlen))
98491 return -EFAULT;
98492 - if (len < 0)
98493 + if (len > INT_MAX)
98494 return -EINVAL;
98495
98496 memset(&v, 0, sizeof(v));
98497 @@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98498
98499 case SO_PEERNAME:
98500 {
98501 - char address[128];
98502 + char address[_K_SS_MAXSIZE];
98503
98504 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98505 return -ENOTCONN;
98506 - if (lv < len)
98507 + if (lv < len || sizeof address < len)
98508 return -EINVAL;
98509 if (copy_to_user(optval, address, len))
98510 return -EFAULT;
98511 @@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98512
98513 if (len > lv)
98514 len = lv;
98515 - if (copy_to_user(optval, &v, len))
98516 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
98517 return -EFAULT;
98518 lenout:
98519 if (put_user(len, optlen))
98520 @@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98521 */
98522 smp_wmb();
98523 atomic_set(&sk->sk_refcnt, 1);
98524 - atomic_set(&sk->sk_drops, 0);
98525 + atomic_set_unchecked(&sk->sk_drops, 0);
98526 }
98527 EXPORT_SYMBOL(sock_init_data);
98528
98529 @@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98530 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98531 int level, int type)
98532 {
98533 + struct sock_extended_err ee;
98534 struct sock_exterr_skb *serr;
98535 struct sk_buff *skb, *skb2;
98536 int copied, err;
98537 @@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98538 sock_recv_timestamp(msg, sk, skb);
98539
98540 serr = SKB_EXT_ERR(skb);
98541 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98542 + ee = serr->ee;
98543 + put_cmsg(msg, level, type, sizeof ee, &ee);
98544
98545 msg->msg_flags |= MSG_ERRQUEUE;
98546 err = copied;
98547 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98548 index a0e9cf6..ef7f9ed 100644
98549 --- a/net/core/sock_diag.c
98550 +++ b/net/core/sock_diag.c
98551 @@ -9,26 +9,33 @@
98552 #include <linux/inet_diag.h>
98553 #include <linux/sock_diag.h>
98554
98555 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98556 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98557 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98558 static DEFINE_MUTEX(sock_diag_table_mutex);
98559
98560 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98561 {
98562 +#ifndef CONFIG_GRKERNSEC_HIDESYM
98563 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98564 cookie[1] != INET_DIAG_NOCOOKIE) &&
98565 ((u32)(unsigned long)sk != cookie[0] ||
98566 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98567 return -ESTALE;
98568 else
98569 +#endif
98570 return 0;
98571 }
98572 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98573
98574 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98575 {
98576 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98577 + cookie[0] = 0;
98578 + cookie[1] = 0;
98579 +#else
98580 cookie[0] = (u32)(unsigned long)sk;
98581 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98582 +#endif
98583 }
98584 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98585
98586 @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98587 mutex_lock(&sock_diag_table_mutex);
98588 if (sock_diag_handlers[hndl->family])
98589 err = -EBUSY;
98590 - else
98591 + else {
98592 + pax_open_kernel();
98593 sock_diag_handlers[hndl->family] = hndl;
98594 + pax_close_kernel();
98595 + }
98596 mutex_unlock(&sock_diag_table_mutex);
98597
98598 return err;
98599 @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98600
98601 mutex_lock(&sock_diag_table_mutex);
98602 BUG_ON(sock_diag_handlers[family] != hnld);
98603 + pax_open_kernel();
98604 sock_diag_handlers[family] = NULL;
98605 + pax_close_kernel();
98606 mutex_unlock(&sock_diag_table_mutex);
98607 }
98608 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98609 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98610 index cf9cd13..8b56af3 100644
98611 --- a/net/core/sysctl_net_core.c
98612 +++ b/net/core/sysctl_net_core.c
98613 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98614 {
98615 unsigned int orig_size, size;
98616 int ret, i;
98617 - struct ctl_table tmp = {
98618 + ctl_table_no_const tmp = {
98619 .data = &size,
98620 .maxlen = sizeof(size),
98621 .mode = table->mode
98622 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98623 void __user *buffer, size_t *lenp, loff_t *ppos)
98624 {
98625 char id[IFNAMSIZ];
98626 - struct ctl_table tbl = {
98627 + ctl_table_no_const tbl = {
98628 .data = id,
98629 .maxlen = IFNAMSIZ,
98630 };
98631 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98632
98633 static __net_init int sysctl_core_net_init(struct net *net)
98634 {
98635 - struct ctl_table *tbl;
98636 + ctl_table_no_const *tbl = NULL;
98637
98638 net->core.sysctl_somaxconn = SOMAXCONN;
98639
98640 - tbl = netns_core_table;
98641 if (!net_eq(net, &init_net)) {
98642 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98643 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98644 if (tbl == NULL)
98645 goto err_dup;
98646
98647 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98648 if (net->user_ns != &init_user_ns) {
98649 tbl[0].procname = NULL;
98650 }
98651 - }
98652 -
98653 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98654 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98655 + } else
98656 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98657 if (net->core.sysctl_hdr == NULL)
98658 goto err_reg;
98659
98660 return 0;
98661
98662 err_reg:
98663 - if (tbl != netns_core_table)
98664 - kfree(tbl);
98665 + kfree(tbl);
98666 err_dup:
98667 return -ENOMEM;
98668 }
98669 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98670 kfree(tbl);
98671 }
98672
98673 -static __net_initdata struct pernet_operations sysctl_core_ops = {
98674 +static __net_initconst struct pernet_operations sysctl_core_ops = {
98675 .init = sysctl_core_net_init,
98676 .exit = sysctl_core_net_exit,
98677 };
98678 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98679 index 4c04848..f575934 100644
98680 --- a/net/decnet/af_decnet.c
98681 +++ b/net/decnet/af_decnet.c
98682 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
98683 .sysctl_rmem = sysctl_decnet_rmem,
98684 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98685 .obj_size = sizeof(struct dn_sock),
98686 + .slab_flags = SLAB_USERCOPY,
98687 };
98688
98689 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98690 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98691 index a603823..a36ee0b 100644
98692 --- a/net/decnet/dn_dev.c
98693 +++ b/net/decnet/dn_dev.c
98694 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98695 .extra1 = &min_t3,
98696 .extra2 = &max_t3
98697 },
98698 - {0}
98699 + { }
98700 },
98701 };
98702
98703 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98704 index 5325b54..a0d4d69 100644
98705 --- a/net/decnet/sysctl_net_decnet.c
98706 +++ b/net/decnet/sysctl_net_decnet.c
98707 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98708
98709 if (len > *lenp) len = *lenp;
98710
98711 - if (copy_to_user(buffer, addr, len))
98712 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
98713 return -EFAULT;
98714
98715 *lenp = len;
98716 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98717
98718 if (len > *lenp) len = *lenp;
98719
98720 - if (copy_to_user(buffer, devname, len))
98721 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
98722 return -EFAULT;
98723
98724 *lenp = len;
98725 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
98726 index 1846c1f..96d4a9f 100644
98727 --- a/net/ieee802154/dgram.c
98728 +++ b/net/ieee802154/dgram.c
98729 @@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
98730 if (saddr) {
98731 saddr->family = AF_IEEE802154;
98732 saddr->addr = mac_cb(skb)->sa;
98733 + }
98734 + if (addr_len)
98735 *addr_len = sizeof(*saddr);
98736 - }
98737
98738 if (flags & MSG_TRUNC)
98739 copied = skb->len;
98740 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
98741 index 19ab78a..bf575c9 100644
98742 --- a/net/ipv4/af_inet.c
98743 +++ b/net/ipv4/af_inet.c
98744 @@ -1703,13 +1703,9 @@ static int __init inet_init(void)
98745
98746 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
98747
98748 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
98749 - if (!sysctl_local_reserved_ports)
98750 - goto out;
98751 -
98752 rc = proto_register(&tcp_prot, 1);
98753 if (rc)
98754 - goto out_free_reserved_ports;
98755 + goto out;
98756
98757 rc = proto_register(&udp_prot, 1);
98758 if (rc)
98759 @@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
98760 proto_unregister(&udp_prot);
98761 out_unregister_tcp_proto:
98762 proto_unregister(&tcp_prot);
98763 -out_free_reserved_ports:
98764 - kfree(sysctl_local_reserved_ports);
98765 goto out;
98766 }
98767
98768 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
98769 index bdbf68b..deb4759 100644
98770 --- a/net/ipv4/devinet.c
98771 +++ b/net/ipv4/devinet.c
98772 @@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
98773 idx = 0;
98774 head = &net->dev_index_head[h];
98775 rcu_read_lock();
98776 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98777 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98778 net->dev_base_seq;
98779 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98780 if (idx < s_idx)
98781 @@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
98782 idx = 0;
98783 head = &net->dev_index_head[h];
98784 rcu_read_lock();
98785 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98786 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98787 net->dev_base_seq;
98788 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98789 if (idx < s_idx)
98790 @@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
98791 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
98792 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
98793
98794 -static struct devinet_sysctl_table {
98795 +static const struct devinet_sysctl_table {
98796 struct ctl_table_header *sysctl_header;
98797 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
98798 } devinet_sysctl = {
98799 @@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
98800 int err;
98801 struct ipv4_devconf *all, *dflt;
98802 #ifdef CONFIG_SYSCTL
98803 - struct ctl_table *tbl = ctl_forward_entry;
98804 + ctl_table_no_const *tbl = NULL;
98805 struct ctl_table_header *forw_hdr;
98806 #endif
98807
98808 @@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
98809 goto err_alloc_dflt;
98810
98811 #ifdef CONFIG_SYSCTL
98812 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
98813 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
98814 if (tbl == NULL)
98815 goto err_alloc_ctl;
98816
98817 @@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
98818 goto err_reg_dflt;
98819
98820 err = -ENOMEM;
98821 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98822 + if (!net_eq(net, &init_net))
98823 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98824 + else
98825 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
98826 if (forw_hdr == NULL)
98827 goto err_reg_ctl;
98828 net->ipv4.forw_hdr = forw_hdr;
98829 @@ -2272,8 +2275,7 @@ err_reg_ctl:
98830 err_reg_dflt:
98831 __devinet_sysctl_unregister(all);
98832 err_reg_all:
98833 - if (tbl != ctl_forward_entry)
98834 - kfree(tbl);
98835 + kfree(tbl);
98836 err_alloc_ctl:
98837 #endif
98838 if (dflt != &ipv4_devconf_dflt)
98839 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
98840 index c7539e2..b455e51 100644
98841 --- a/net/ipv4/fib_frontend.c
98842 +++ b/net/ipv4/fib_frontend.c
98843 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
98844 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98845 fib_sync_up(dev);
98846 #endif
98847 - atomic_inc(&net->ipv4.dev_addr_genid);
98848 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98849 rt_cache_flush(dev_net(dev));
98850 break;
98851 case NETDEV_DOWN:
98852 fib_del_ifaddr(ifa, NULL);
98853 - atomic_inc(&net->ipv4.dev_addr_genid);
98854 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98855 if (ifa->ifa_dev->ifa_list == NULL) {
98856 /* Last address was deleted from this interface.
98857 * Disable IP.
98858 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
98859 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98860 fib_sync_up(dev);
98861 #endif
98862 - atomic_inc(&net->ipv4.dev_addr_genid);
98863 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98864 rt_cache_flush(net);
98865 break;
98866 case NETDEV_DOWN:
98867 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
98868 index b53f0bf..3585b33 100644
98869 --- a/net/ipv4/fib_semantics.c
98870 +++ b/net/ipv4/fib_semantics.c
98871 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
98872 nh->nh_saddr = inet_select_addr(nh->nh_dev,
98873 nh->nh_gw,
98874 nh->nh_parent->fib_scope);
98875 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
98876 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
98877
98878 return nh->nh_saddr;
98879 }
98880 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
98881 index 0d1e2cb..4501a2c 100644
98882 --- a/net/ipv4/inet_connection_sock.c
98883 +++ b/net/ipv4/inet_connection_sock.c
98884 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
98885 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
98886 #endif
98887
98888 -unsigned long *sysctl_local_reserved_ports;
98889 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
98890 EXPORT_SYMBOL(sysctl_local_reserved_ports);
98891
98892 void inet_get_local_port_range(struct net *net, int *low, int *high)
98893 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
98894 index 8b9cf27..0d8d592 100644
98895 --- a/net/ipv4/inet_hashtables.c
98896 +++ b/net/ipv4/inet_hashtables.c
98897 @@ -18,6 +18,7 @@
98898 #include <linux/sched.h>
98899 #include <linux/slab.h>
98900 #include <linux/wait.h>
98901 +#include <linux/security.h>
98902
98903 #include <net/inet_connection_sock.h>
98904 #include <net/inet_hashtables.h>
98905 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
98906 return inet_ehashfn(net, laddr, lport, faddr, fport);
98907 }
98908
98909 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
98910 +
98911 /*
98912 * Allocate and initialize a new local port bind bucket.
98913 * The bindhash mutex for snum's hash chain must be held here.
98914 @@ -554,6 +557,8 @@ ok:
98915 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
98916 spin_unlock(&head->lock);
98917
98918 + gr_update_task_in_ip_table(current, inet_sk(sk));
98919 +
98920 if (tw) {
98921 inet_twsk_deschedule(tw, death_row);
98922 while (twrefcnt) {
98923 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
98924 index 48f4244..f56d83a 100644
98925 --- a/net/ipv4/inetpeer.c
98926 +++ b/net/ipv4/inetpeer.c
98927 @@ -496,8 +496,8 @@ relookup:
98928 if (p) {
98929 p->daddr = *daddr;
98930 atomic_set(&p->refcnt, 1);
98931 - atomic_set(&p->rid, 0);
98932 - atomic_set(&p->ip_id_count,
98933 + atomic_set_unchecked(&p->rid, 0);
98934 + atomic_set_unchecked(&p->ip_id_count,
98935 (daddr->family == AF_INET) ?
98936 secure_ip_id(daddr->addr.a4) :
98937 secure_ipv6_id(daddr->addr.a6));
98938 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
98939 index c10a3ce..dd71f84 100644
98940 --- a/net/ipv4/ip_fragment.c
98941 +++ b/net/ipv4/ip_fragment.c
98942 @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
98943 return 0;
98944
98945 start = qp->rid;
98946 - end = atomic_inc_return(&peer->rid);
98947 + end = atomic_inc_return_unchecked(&peer->rid);
98948 qp->rid = end;
98949
98950 rc = qp->q.fragments && (end - start) > max;
98951 @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
98952
98953 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98954 {
98955 - struct ctl_table *table;
98956 + ctl_table_no_const *table = NULL;
98957 struct ctl_table_header *hdr;
98958
98959 - table = ip4_frags_ns_ctl_table;
98960 if (!net_eq(net, &init_net)) {
98961 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98962 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98963 if (table == NULL)
98964 goto err_alloc;
98965
98966 @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98967 /* Don't export sysctls to unprivileged users */
98968 if (net->user_ns != &init_user_ns)
98969 table[0].procname = NULL;
98970 - }
98971 + hdr = register_net_sysctl(net, "net/ipv4", table);
98972 + } else
98973 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
98974
98975 - hdr = register_net_sysctl(net, "net/ipv4", table);
98976 if (hdr == NULL)
98977 goto err_reg;
98978
98979 @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98980 return 0;
98981
98982 err_reg:
98983 - if (!net_eq(net, &init_net))
98984 - kfree(table);
98985 + kfree(table);
98986 err_alloc:
98987 return -ENOMEM;
98988 }
98989 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
98990 index ec4f762..4ce3645 100644
98991 --- a/net/ipv4/ip_gre.c
98992 +++ b/net/ipv4/ip_gre.c
98993 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
98994 module_param(log_ecn_error, bool, 0644);
98995 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98996
98997 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
98998 +static struct rtnl_link_ops ipgre_link_ops;
98999 static int ipgre_tunnel_init(struct net_device *dev);
99000
99001 static int ipgre_net_id __read_mostly;
99002 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99003 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99004 };
99005
99006 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99007 +static struct rtnl_link_ops ipgre_link_ops = {
99008 .kind = "gre",
99009 .maxtype = IFLA_GRE_MAX,
99010 .policy = ipgre_policy,
99011 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99012 .fill_info = ipgre_fill_info,
99013 };
99014
99015 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99016 +static struct rtnl_link_ops ipgre_tap_ops = {
99017 .kind = "gretap",
99018 .maxtype = IFLA_GRE_MAX,
99019 .policy = ipgre_policy,
99020 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99021 index 580dd96..9fcef7e 100644
99022 --- a/net/ipv4/ip_sockglue.c
99023 +++ b/net/ipv4/ip_sockglue.c
99024 @@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99025 len = min_t(unsigned int, len, opt->optlen);
99026 if (put_user(len, optlen))
99027 return -EFAULT;
99028 - if (copy_to_user(optval, opt->__data, len))
99029 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99030 + copy_to_user(optval, opt->__data, len))
99031 return -EFAULT;
99032 return 0;
99033 }
99034 @@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99035 if (sk->sk_type != SOCK_STREAM)
99036 return -ENOPROTOOPT;
99037
99038 - msg.msg_control = optval;
99039 + msg.msg_control = (void __force_kernel *)optval;
99040 msg.msg_controllen = len;
99041 msg.msg_flags = flags;
99042
99043 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99044 index 48eafae..defff53 100644
99045 --- a/net/ipv4/ip_vti.c
99046 +++ b/net/ipv4/ip_vti.c
99047 @@ -44,7 +44,7 @@
99048 #include <net/net_namespace.h>
99049 #include <net/netns/generic.h>
99050
99051 -static struct rtnl_link_ops vti_link_ops __read_mostly;
99052 +static struct rtnl_link_ops vti_link_ops;
99053
99054 static int vti_net_id __read_mostly;
99055 static int vti_tunnel_init(struct net_device *dev);
99056 @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99057 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99058 };
99059
99060 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
99061 +static struct rtnl_link_ops vti_link_ops = {
99062 .kind = "vti",
99063 .maxtype = IFLA_VTI_MAX,
99064 .policy = vti_policy,
99065 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99066 index b3e86ea..18ce98c 100644
99067 --- a/net/ipv4/ipconfig.c
99068 +++ b/net/ipv4/ipconfig.c
99069 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99070
99071 mm_segment_t oldfs = get_fs();
99072 set_fs(get_ds());
99073 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99074 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99075 set_fs(oldfs);
99076 return res;
99077 }
99078 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99079
99080 mm_segment_t oldfs = get_fs();
99081 set_fs(get_ds());
99082 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99083 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99084 set_fs(oldfs);
99085 return res;
99086 }
99087 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99088
99089 mm_segment_t oldfs = get_fs();
99090 set_fs(get_ds());
99091 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99092 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99093 set_fs(oldfs);
99094 return res;
99095 }
99096 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99097 index 812b183..56cbe9c 100644
99098 --- a/net/ipv4/ipip.c
99099 +++ b/net/ipv4/ipip.c
99100 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99101 static int ipip_net_id __read_mostly;
99102
99103 static int ipip_tunnel_init(struct net_device *dev);
99104 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
99105 +static struct rtnl_link_ops ipip_link_ops;
99106
99107 static int ipip_err(struct sk_buff *skb, u32 info)
99108 {
99109 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99110 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99111 };
99112
99113 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99114 +static struct rtnl_link_ops ipip_link_ops = {
99115 .kind = "ipip",
99116 .maxtype = IFLA_IPTUN_MAX,
99117 .policy = ipip_policy,
99118 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99119 index 59da7cd..e318de1 100644
99120 --- a/net/ipv4/netfilter/arp_tables.c
99121 +++ b/net/ipv4/netfilter/arp_tables.c
99122 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99123 #endif
99124
99125 static int get_info(struct net *net, void __user *user,
99126 - const int *len, int compat)
99127 + int len, int compat)
99128 {
99129 char name[XT_TABLE_MAXNAMELEN];
99130 struct xt_table *t;
99131 int ret;
99132
99133 - if (*len != sizeof(struct arpt_getinfo)) {
99134 - duprintf("length %u != %Zu\n", *len,
99135 + if (len != sizeof(struct arpt_getinfo)) {
99136 + duprintf("length %u != %Zu\n", len,
99137 sizeof(struct arpt_getinfo));
99138 return -EINVAL;
99139 }
99140 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99141 info.size = private->size;
99142 strcpy(info.name, name);
99143
99144 - if (copy_to_user(user, &info, *len) != 0)
99145 + if (copy_to_user(user, &info, len) != 0)
99146 ret = -EFAULT;
99147 else
99148 ret = 0;
99149 @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99150
99151 switch (cmd) {
99152 case ARPT_SO_GET_INFO:
99153 - ret = get_info(sock_net(sk), user, len, 1);
99154 + ret = get_info(sock_net(sk), user, *len, 1);
99155 break;
99156 case ARPT_SO_GET_ENTRIES:
99157 ret = compat_get_entries(sock_net(sk), user, len);
99158 @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99159
99160 switch (cmd) {
99161 case ARPT_SO_GET_INFO:
99162 - ret = get_info(sock_net(sk), user, len, 0);
99163 + ret = get_info(sock_net(sk), user, *len, 0);
99164 break;
99165
99166 case ARPT_SO_GET_ENTRIES:
99167 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99168 index 718dfbd..cef4152 100644
99169 --- a/net/ipv4/netfilter/ip_tables.c
99170 +++ b/net/ipv4/netfilter/ip_tables.c
99171 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99172 #endif
99173
99174 static int get_info(struct net *net, void __user *user,
99175 - const int *len, int compat)
99176 + int len, int compat)
99177 {
99178 char name[XT_TABLE_MAXNAMELEN];
99179 struct xt_table *t;
99180 int ret;
99181
99182 - if (*len != sizeof(struct ipt_getinfo)) {
99183 - duprintf("length %u != %zu\n", *len,
99184 + if (len != sizeof(struct ipt_getinfo)) {
99185 + duprintf("length %u != %zu\n", len,
99186 sizeof(struct ipt_getinfo));
99187 return -EINVAL;
99188 }
99189 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99190 info.size = private->size;
99191 strcpy(info.name, name);
99192
99193 - if (copy_to_user(user, &info, *len) != 0)
99194 + if (copy_to_user(user, &info, len) != 0)
99195 ret = -EFAULT;
99196 else
99197 ret = 0;
99198 @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99199
99200 switch (cmd) {
99201 case IPT_SO_GET_INFO:
99202 - ret = get_info(sock_net(sk), user, len, 1);
99203 + ret = get_info(sock_net(sk), user, *len, 1);
99204 break;
99205 case IPT_SO_GET_ENTRIES:
99206 ret = compat_get_entries(sock_net(sk), user, len);
99207 @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99208
99209 switch (cmd) {
99210 case IPT_SO_GET_INFO:
99211 - ret = get_info(sock_net(sk), user, len, 0);
99212 + ret = get_info(sock_net(sk), user, *len, 0);
99213 break;
99214
99215 case IPT_SO_GET_ENTRIES:
99216 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99217 index 2510c02..cfb34fa 100644
99218 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99219 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99220 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99221 spin_lock_init(&cn->lock);
99222
99223 #ifdef CONFIG_PROC_FS
99224 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99225 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99226 if (!cn->procdir) {
99227 pr_err("Unable to proc dir entry\n");
99228 return -ENOMEM;
99229 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99230 index 2d11c09..3f153f8 100644
99231 --- a/net/ipv4/ping.c
99232 +++ b/net/ipv4/ping.c
99233 @@ -59,7 +59,7 @@ struct ping_table {
99234 };
99235
99236 static struct ping_table ping_table;
99237 -struct pingv6_ops pingv6_ops;
99238 +struct pingv6_ops *pingv6_ops;
99239 EXPORT_SYMBOL_GPL(pingv6_ops);
99240
99241 static u16 ping_port_rover;
99242 @@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
99243 struct group_info *group_info = get_current_groups();
99244 int i, j, count = group_info->ngroups;
99245 kgid_t low, high;
99246 + int ret = 0;
99247
99248 inet_get_ping_group_range_net(net, &low, &high);
99249 if (gid_lte(low, group) && gid_lte(group, high))
99250 - return 0;
99251 + goto out_release_group;
99252
99253 for (i = 0; i < group_info->nblocks; i++) {
99254 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
99255 for (j = 0; j < cp_count; j++) {
99256 kgid_t gid = group_info->blocks[i][j];
99257 if (gid_lte(low, gid) && gid_lte(gid, high))
99258 - return 0;
99259 + goto out_release_group;
99260 }
99261
99262 count -= cp_count;
99263 }
99264
99265 - return -EACCES;
99266 + ret = -EACCES;
99267 +
99268 +out_release_group:
99269 + put_group_info(group_info);
99270 + return ret;
99271 }
99272 EXPORT_SYMBOL_GPL(ping_init_sock);
99273
99274 @@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99275 return -ENODEV;
99276 }
99277 }
99278 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99279 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99280 scoped);
99281 rcu_read_unlock();
99282
99283 @@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99284 }
99285 #if IS_ENABLED(CONFIG_IPV6)
99286 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99287 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99288 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99289 #endif
99290 }
99291
99292 @@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99293 info, (u8 *)icmph);
99294 #if IS_ENABLED(CONFIG_IPV6)
99295 } else if (family == AF_INET6) {
99296 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99297 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99298 info, (u8 *)icmph);
99299 #endif
99300 }
99301 @@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99302 {
99303 struct inet_sock *isk = inet_sk(sk);
99304 int family = sk->sk_family;
99305 + struct sockaddr_in *sin;
99306 + struct sockaddr_in6 *sin6;
99307 struct sk_buff *skb;
99308 int copied, err;
99309
99310 @@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99311 if (flags & MSG_OOB)
99312 goto out;
99313
99314 + if (addr_len) {
99315 + if (family == AF_INET)
99316 + *addr_len = sizeof(*sin);
99317 + else if (family == AF_INET6 && addr_len)
99318 + *addr_len = sizeof(*sin6);
99319 + }
99320 +
99321 if (flags & MSG_ERRQUEUE) {
99322 if (family == AF_INET) {
99323 return ip_recv_error(sk, msg, len, addr_len);
99324 #if IS_ENABLED(CONFIG_IPV6)
99325 } else if (family == AF_INET6) {
99326 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
99327 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
99328 addr_len);
99329 #endif
99330 }
99331 @@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99332 sin->sin_port = 0 /* skb->h.uh->source */;
99333 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99334 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99335 - *addr_len = sizeof(*sin);
99336 }
99337
99338 if (isk->cmsg_flags)
99339 @@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99340 sin6->sin6_scope_id =
99341 ipv6_iface_scope_id(&sin6->sin6_addr,
99342 IP6CB(skb)->iif);
99343 - *addr_len = sizeof(*sin6);
99344 }
99345
99346 if (inet6_sk(sk)->rxopt.all)
99347 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99348 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99349 if (skb->protocol == htons(ETH_P_IPV6) &&
99350 inet6_sk(sk)->rxopt.all)
99351 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99352 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99353 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99354 ip_cmsg_recv(msg, skb);
99355 #endif
99356 @@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99357 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99358 0, sock_i_ino(sp),
99359 atomic_read(&sp->sk_refcnt), sp,
99360 - atomic_read(&sp->sk_drops));
99361 + atomic_read_unchecked(&sp->sk_drops));
99362 }
99363
99364 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99365 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99366 index c04518f..824ebe5 100644
99367 --- a/net/ipv4/raw.c
99368 +++ b/net/ipv4/raw.c
99369 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99370 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99371 {
99372 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99373 - atomic_inc(&sk->sk_drops);
99374 + atomic_inc_unchecked(&sk->sk_drops);
99375 kfree_skb(skb);
99376 return NET_RX_DROP;
99377 }
99378 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99379 if (flags & MSG_OOB)
99380 goto out;
99381
99382 + if (addr_len)
99383 + *addr_len = sizeof(*sin);
99384 +
99385 if (flags & MSG_ERRQUEUE) {
99386 err = ip_recv_error(sk, msg, len, addr_len);
99387 goto out;
99388 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99389 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99390 sin->sin_port = 0;
99391 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99392 - *addr_len = sizeof(*sin);
99393 }
99394 if (inet->cmsg_flags)
99395 ip_cmsg_recv(msg, skb);
99396 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99397
99398 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99399 {
99400 + struct icmp_filter filter;
99401 +
99402 if (optlen > sizeof(struct icmp_filter))
99403 optlen = sizeof(struct icmp_filter);
99404 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99405 + if (copy_from_user(&filter, optval, optlen))
99406 return -EFAULT;
99407 + raw_sk(sk)->filter = filter;
99408 return 0;
99409 }
99410
99411 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99412 {
99413 int len, ret = -EFAULT;
99414 + struct icmp_filter filter;
99415
99416 if (get_user(len, optlen))
99417 goto out;
99418 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99419 if (len > sizeof(struct icmp_filter))
99420 len = sizeof(struct icmp_filter);
99421 ret = -EFAULT;
99422 - if (put_user(len, optlen) ||
99423 - copy_to_user(optval, &raw_sk(sk)->filter, len))
99424 + filter = raw_sk(sk)->filter;
99425 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99426 goto out;
99427 ret = 0;
99428 out: return ret;
99429 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99430 0, 0L, 0,
99431 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99432 0, sock_i_ino(sp),
99433 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99434 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99435 }
99436
99437 static int raw_seq_show(struct seq_file *seq, void *v)
99438 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99439 index 4c011ec..8fae66b 100644
99440 --- a/net/ipv4/route.c
99441 +++ b/net/ipv4/route.c
99442 @@ -233,7 +233,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99443
99444 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99445 {
99446 - return seq_open(file, &rt_cache_seq_ops);
99447 + return seq_open_restrict(file, &rt_cache_seq_ops);
99448 }
99449
99450 static const struct file_operations rt_cache_seq_fops = {
99451 @@ -324,7 +324,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99452
99453 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99454 {
99455 - return seq_open(file, &rt_cpu_seq_ops);
99456 + return seq_open_restrict(file, &rt_cpu_seq_ops);
99457 }
99458
99459 static const struct file_operations rt_cpu_seq_fops = {
99460 @@ -362,7 +362,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99461
99462 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99463 {
99464 - return single_open(file, rt_acct_proc_show, NULL);
99465 + return single_open_restrict(file, rt_acct_proc_show, NULL);
99466 }
99467
99468 static const struct file_operations rt_acct_proc_fops = {
99469 @@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99470 .maxlen = sizeof(int),
99471 .mode = 0200,
99472 .proc_handler = ipv4_sysctl_rtcache_flush,
99473 + .extra1 = &init_net,
99474 },
99475 { },
99476 };
99477
99478 static __net_init int sysctl_route_net_init(struct net *net)
99479 {
99480 - struct ctl_table *tbl;
99481 + ctl_table_no_const *tbl = NULL;
99482
99483 - tbl = ipv4_route_flush_table;
99484 if (!net_eq(net, &init_net)) {
99485 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99486 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99487 if (tbl == NULL)
99488 goto err_dup;
99489
99490 /* Don't export sysctls to unprivileged users */
99491 if (net->user_ns != &init_user_ns)
99492 tbl[0].procname = NULL;
99493 - }
99494 - tbl[0].extra1 = net;
99495 + tbl[0].extra1 = net;
99496 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99497 + } else
99498 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99499
99500 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99501 if (net->ipv4.route_hdr == NULL)
99502 goto err_reg;
99503 return 0;
99504
99505 err_reg:
99506 - if (tbl != ipv4_route_flush_table)
99507 - kfree(tbl);
99508 + kfree(tbl);
99509 err_dup:
99510 return -ENOMEM;
99511 }
99512 @@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99513
99514 static __net_init int rt_genid_init(struct net *net)
99515 {
99516 - atomic_set(&net->ipv4.rt_genid, 0);
99517 - atomic_set(&net->fnhe_genid, 0);
99518 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99519 + atomic_set_unchecked(&net->fnhe_genid, 0);
99520 get_random_bytes(&net->ipv4.dev_addr_genid,
99521 sizeof(net->ipv4.dev_addr_genid));
99522 return 0;
99523 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99524 index 44eba05..b36864b 100644
99525 --- a/net/ipv4/sysctl_net_ipv4.c
99526 +++ b/net/ipv4/sysctl_net_ipv4.c
99527 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99528 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
99529 int ret;
99530 int range[2];
99531 - struct ctl_table tmp = {
99532 + ctl_table_no_const tmp = {
99533 .data = &range,
99534 .maxlen = sizeof(range),
99535 .mode = table->mode,
99536 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99537 int ret;
99538 gid_t urange[2];
99539 kgid_t low, high;
99540 - struct ctl_table tmp = {
99541 + ctl_table_no_const tmp = {
99542 .data = &urange,
99543 .maxlen = sizeof(urange),
99544 .mode = table->mode,
99545 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99546 void __user *buffer, size_t *lenp, loff_t *ppos)
99547 {
99548 char val[TCP_CA_NAME_MAX];
99549 - struct ctl_table tbl = {
99550 + ctl_table_no_const tbl = {
99551 .data = val,
99552 .maxlen = TCP_CA_NAME_MAX,
99553 };
99554 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99555 void __user *buffer, size_t *lenp,
99556 loff_t *ppos)
99557 {
99558 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99559 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99560 int ret;
99561
99562 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99563 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99564 void __user *buffer, size_t *lenp,
99565 loff_t *ppos)
99566 {
99567 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99568 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99569 int ret;
99570
99571 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99572 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99573 void __user *buffer, size_t *lenp,
99574 loff_t *ppos)
99575 {
99576 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99577 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99578 struct tcp_fastopen_context *ctxt;
99579 int ret;
99580 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99581 @@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99582 },
99583 {
99584 .procname = "ip_local_reserved_ports",
99585 - .data = NULL, /* initialized in sysctl_ipv4_init */
99586 + .data = sysctl_local_reserved_ports,
99587 .maxlen = 65536,
99588 .mode = 0644,
99589 .proc_handler = proc_do_large_bitmap,
99590 @@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99591
99592 static __net_init int ipv4_sysctl_init_net(struct net *net)
99593 {
99594 - struct ctl_table *table;
99595 + ctl_table_no_const *table = NULL;
99596
99597 - table = ipv4_net_table;
99598 if (!net_eq(net, &init_net)) {
99599 int i;
99600
99601 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99602 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99603 if (table == NULL)
99604 goto err_alloc;
99605
99606 @@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99607 net->ipv4.sysctl_local_ports.range[0] = 32768;
99608 net->ipv4.sysctl_local_ports.range[1] = 61000;
99609
99610 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99611 + if (!net_eq(net, &init_net))
99612 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99613 + else
99614 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99615 if (net->ipv4.ipv4_hdr == NULL)
99616 goto err_reg;
99617
99618 return 0;
99619
99620 err_reg:
99621 - if (!net_eq(net, &init_net))
99622 - kfree(table);
99623 + kfree(table);
99624 err_alloc:
99625 return -ENOMEM;
99626 }
99627 @@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99628 static __init int sysctl_ipv4_init(void)
99629 {
99630 struct ctl_table_header *hdr;
99631 - struct ctl_table *i;
99632 -
99633 - for (i = ipv4_table; i->procname; i++) {
99634 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99635 - i->data = sysctl_local_reserved_ports;
99636 - break;
99637 - }
99638 - }
99639 - if (!i->procname)
99640 - return -EINVAL;
99641
99642 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99643 if (hdr == NULL)
99644 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99645 index eeaac39..dc29942 100644
99646 --- a/net/ipv4/tcp_input.c
99647 +++ b/net/ipv4/tcp_input.c
99648 @@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99649 * without any lock. We want to make sure compiler wont store
99650 * intermediate values in this location.
99651 */
99652 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99653 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99654 sk->sk_max_pacing_rate);
99655 }
99656
99657 @@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99658 * simplifies code)
99659 */
99660 static void
99661 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99662 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99663 struct sk_buff *head, struct sk_buff *tail,
99664 u32 start, u32 end)
99665 {
99666 @@ -5562,6 +5562,7 @@ discard:
99667 tcp_paws_reject(&tp->rx_opt, 0))
99668 goto discard_and_undo;
99669
99670 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99671 if (th->syn) {
99672 /* We see SYN without ACK. It is attempt of
99673 * simultaneous connect with crossed SYNs.
99674 @@ -5612,6 +5613,7 @@ discard:
99675 goto discard;
99676 #endif
99677 }
99678 +#endif
99679 /* "fifth, if neither of the SYN or RST bits is set then
99680 * drop the segment and return."
99681 */
99682 @@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99683 goto discard;
99684
99685 if (th->syn) {
99686 - if (th->fin)
99687 + if (th->fin || th->urg || th->psh)
99688 goto discard;
99689 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99690 return 1;
99691 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99692 index 1e4eac7..a66fa4a 100644
99693 --- a/net/ipv4/tcp_ipv4.c
99694 +++ b/net/ipv4/tcp_ipv4.c
99695 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99696 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99697
99698
99699 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99700 +extern int grsec_enable_blackhole;
99701 +#endif
99702 +
99703 #ifdef CONFIG_TCP_MD5SIG
99704 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99705 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99706 @@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99707 return 0;
99708
99709 reset:
99710 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99711 + if (!grsec_enable_blackhole)
99712 +#endif
99713 tcp_v4_send_reset(rsk, skb);
99714 discard:
99715 kfree_skb(skb);
99716 @@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99717 TCP_SKB_CB(skb)->sacked = 0;
99718
99719 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99720 - if (!sk)
99721 + if (!sk) {
99722 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99723 + ret = 1;
99724 +#endif
99725 goto no_tcp_socket;
99726 -
99727 + }
99728 process:
99729 - if (sk->sk_state == TCP_TIME_WAIT)
99730 + if (sk->sk_state == TCP_TIME_WAIT) {
99731 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99732 + ret = 2;
99733 +#endif
99734 goto do_time_wait;
99735 + }
99736
99737 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
99738 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99739 @@ -2033,6 +2047,10 @@ csum_error:
99740 bad_packet:
99741 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99742 } else {
99743 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99744 + if (!grsec_enable_blackhole || (ret == 1 &&
99745 + (skb->dev->flags & IFF_LOOPBACK)))
99746 +#endif
99747 tcp_v4_send_reset(NULL, skb);
99748 }
99749
99750 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
99751 index 7a436c5..1b05c59 100644
99752 --- a/net/ipv4/tcp_minisocks.c
99753 +++ b/net/ipv4/tcp_minisocks.c
99754 @@ -27,6 +27,10 @@
99755 #include <net/inet_common.h>
99756 #include <net/xfrm.h>
99757
99758 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99759 +extern int grsec_enable_blackhole;
99760 +#endif
99761 +
99762 int sysctl_tcp_syncookies __read_mostly = 1;
99763 EXPORT_SYMBOL(sysctl_tcp_syncookies);
99764
99765 @@ -709,7 +713,10 @@ embryonic_reset:
99766 * avoid becoming vulnerable to outside attack aiming at
99767 * resetting legit local connections.
99768 */
99769 - req->rsk_ops->send_reset(sk, skb);
99770 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99771 + if (!grsec_enable_blackhole)
99772 +#endif
99773 + req->rsk_ops->send_reset(sk, skb);
99774 } else if (fastopen) { /* received a valid RST pkt */
99775 reqsk_fastopen_remove(sk, req, true);
99776 tcp_reset(sk);
99777 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
99778 index 1f2d376..01d18c4 100644
99779 --- a/net/ipv4/tcp_probe.c
99780 +++ b/net/ipv4/tcp_probe.c
99781 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
99782 if (cnt + width >= len)
99783 break;
99784
99785 - if (copy_to_user(buf + cnt, tbuf, width))
99786 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
99787 return -EFAULT;
99788 cnt += width;
99789 }
99790 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
99791 index 64f0354..a81b39d 100644
99792 --- a/net/ipv4/tcp_timer.c
99793 +++ b/net/ipv4/tcp_timer.c
99794 @@ -22,6 +22,10 @@
99795 #include <linux/gfp.h>
99796 #include <net/tcp.h>
99797
99798 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99799 +extern int grsec_lastack_retries;
99800 +#endif
99801 +
99802 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
99803 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
99804 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
99805 @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
99806 }
99807 }
99808
99809 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99810 + if ((sk->sk_state == TCP_LAST_ACK) &&
99811 + (grsec_lastack_retries > 0) &&
99812 + (grsec_lastack_retries < retry_until))
99813 + retry_until = grsec_lastack_retries;
99814 +#endif
99815 +
99816 if (retransmits_timed_out(sk, retry_until,
99817 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
99818 /* Has it gone just too far? */
99819 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
99820 index 77bd16f..5f7174a 100644
99821 --- a/net/ipv4/udp.c
99822 +++ b/net/ipv4/udp.c
99823 @@ -87,6 +87,7 @@
99824 #include <linux/types.h>
99825 #include <linux/fcntl.h>
99826 #include <linux/module.h>
99827 +#include <linux/security.h>
99828 #include <linux/socket.h>
99829 #include <linux/sockios.h>
99830 #include <linux/igmp.h>
99831 @@ -113,6 +114,10 @@
99832 #include <net/busy_poll.h>
99833 #include "udp_impl.h"
99834
99835 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99836 +extern int grsec_enable_blackhole;
99837 +#endif
99838 +
99839 struct udp_table udp_table __read_mostly;
99840 EXPORT_SYMBOL(udp_table);
99841
99842 @@ -615,6 +620,9 @@ found:
99843 return s;
99844 }
99845
99846 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
99847 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
99848 +
99849 /*
99850 * This routine is called by the ICMP module when it gets some
99851 * sort of error condition. If err < 0 then the socket should
99852 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99853 dport = usin->sin_port;
99854 if (dport == 0)
99855 return -EINVAL;
99856 +
99857 + err = gr_search_udp_sendmsg(sk, usin);
99858 + if (err)
99859 + return err;
99860 } else {
99861 if (sk->sk_state != TCP_ESTABLISHED)
99862 return -EDESTADDRREQ;
99863 +
99864 + err = gr_search_udp_sendmsg(sk, NULL);
99865 + if (err)
99866 + return err;
99867 +
99868 daddr = inet->inet_daddr;
99869 dport = inet->inet_dport;
99870 /* Open fast path for connected socket.
99871 @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
99872 IS_UDPLITE(sk));
99873 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99874 IS_UDPLITE(sk));
99875 - atomic_inc(&sk->sk_drops);
99876 + atomic_inc_unchecked(&sk->sk_drops);
99877 __skb_unlink(skb, rcvq);
99878 __skb_queue_tail(&list_kill, skb);
99879 }
99880 @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99881 int is_udplite = IS_UDPLITE(sk);
99882 bool slow;
99883
99884 + /*
99885 + * Check any passed addresses
99886 + */
99887 + if (addr_len)
99888 + *addr_len = sizeof(*sin);
99889 +
99890 if (flags & MSG_ERRQUEUE)
99891 return ip_recv_error(sk, msg, len, addr_len);
99892
99893 @@ -1243,6 +1266,10 @@ try_again:
99894 if (!skb)
99895 goto out;
99896
99897 + err = gr_search_udp_recvmsg(sk, skb);
99898 + if (err)
99899 + goto out_free;
99900 +
99901 ulen = skb->len - sizeof(struct udphdr);
99902 copied = len;
99903 if (copied > ulen)
99904 @@ -1276,7 +1303,7 @@ try_again:
99905 if (unlikely(err)) {
99906 trace_kfree_skb(skb, udp_recvmsg);
99907 if (!peeked) {
99908 - atomic_inc(&sk->sk_drops);
99909 + atomic_inc_unchecked(&sk->sk_drops);
99910 UDP_INC_STATS_USER(sock_net(sk),
99911 UDP_MIB_INERRORS, is_udplite);
99912 }
99913 @@ -1295,7 +1322,6 @@ try_again:
99914 sin->sin_port = udp_hdr(skb)->source;
99915 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99916 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99917 - *addr_len = sizeof(*sin);
99918 }
99919 if (inet->cmsg_flags)
99920 ip_cmsg_recv(msg, skb);
99921 @@ -1566,7 +1592,7 @@ csum_error:
99922 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99923 drop:
99924 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99925 - atomic_inc(&sk->sk_drops);
99926 + atomic_inc_unchecked(&sk->sk_drops);
99927 kfree_skb(skb);
99928 return -1;
99929 }
99930 @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99931 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99932
99933 if (!skb1) {
99934 - atomic_inc(&sk->sk_drops);
99935 + atomic_inc_unchecked(&sk->sk_drops);
99936 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99937 IS_UDPLITE(sk));
99938 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99939 @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99940 goto csum_error;
99941
99942 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99943 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99944 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99945 +#endif
99946 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
99947
99948 /*
99949 @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
99950 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99951 0, sock_i_ino(sp),
99952 atomic_read(&sp->sk_refcnt), sp,
99953 - atomic_read(&sp->sk_drops));
99954 + atomic_read_unchecked(&sp->sk_drops));
99955 }
99956
99957 int udp4_seq_show(struct seq_file *seq, void *v)
99958 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
99959 index e1a6393..f634ce5 100644
99960 --- a/net/ipv4/xfrm4_policy.c
99961 +++ b/net/ipv4/xfrm4_policy.c
99962 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
99963 fl4->flowi4_tos = iph->tos;
99964 }
99965
99966 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
99967 +static int xfrm4_garbage_collect(struct dst_ops *ops)
99968 {
99969 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
99970
99971 - xfrm4_policy_afinfo.garbage_collect(net);
99972 + xfrm_garbage_collect_deferred(net);
99973 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
99974 }
99975
99976 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
99977
99978 static int __net_init xfrm4_net_init(struct net *net)
99979 {
99980 - struct ctl_table *table;
99981 + ctl_table_no_const *table = NULL;
99982 struct ctl_table_header *hdr;
99983
99984 - table = xfrm4_policy_table;
99985 if (!net_eq(net, &init_net)) {
99986 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99987 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99988 if (!table)
99989 goto err_alloc;
99990
99991 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
99992 - }
99993 -
99994 - hdr = register_net_sysctl(net, "net/ipv4", table);
99995 + hdr = register_net_sysctl(net, "net/ipv4", table);
99996 + } else
99997 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
99998 if (!hdr)
99999 goto err_reg;
100000
100001 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100002 return 0;
100003
100004 err_reg:
100005 - if (!net_eq(net, &init_net))
100006 - kfree(table);
100007 + kfree(table);
100008 err_alloc:
100009 return -ENOMEM;
100010 }
100011 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100012 index 6c7fa08..285086c 100644
100013 --- a/net/ipv6/addrconf.c
100014 +++ b/net/ipv6/addrconf.c
100015 @@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100016 idx = 0;
100017 head = &net->dev_index_head[h];
100018 rcu_read_lock();
100019 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100020 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100021 net->dev_base_seq;
100022 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100023 if (idx < s_idx)
100024 @@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100025 p.iph.ihl = 5;
100026 p.iph.protocol = IPPROTO_IPV6;
100027 p.iph.ttl = 64;
100028 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100029 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100030
100031 if (ops->ndo_do_ioctl) {
100032 mm_segment_t oldfs = get_fs();
100033 @@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100034 s_ip_idx = ip_idx = cb->args[2];
100035
100036 rcu_read_lock();
100037 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100038 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100039 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100040 idx = 0;
100041 head = &net->dev_index_head[h];
100042 @@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100043 dst_free(&ifp->rt->dst);
100044 break;
100045 }
100046 - atomic_inc(&net->ipv6.dev_addr_genid);
100047 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100048 rt_genid_bump_ipv6(net);
100049 }
100050
100051 @@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100052 int *valp = ctl->data;
100053 int val = *valp;
100054 loff_t pos = *ppos;
100055 - struct ctl_table lctl;
100056 + ctl_table_no_const lctl;
100057 int ret;
100058
100059 /*
100060 @@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100061 int *valp = ctl->data;
100062 int val = *valp;
100063 loff_t pos = *ppos;
100064 - struct ctl_table lctl;
100065 + ctl_table_no_const lctl;
100066 int ret;
100067
100068 /*
100069 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100070 index d935889..2f64330 100644
100071 --- a/net/ipv6/af_inet6.c
100072 +++ b/net/ipv6/af_inet6.c
100073 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100074 net->ipv6.sysctl.bindv6only = 0;
100075 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100076 net->ipv6.sysctl.flowlabel_consistency = 1;
100077 - atomic_set(&net->ipv6.rt_genid, 0);
100078 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100079
100080 err = ipv6_init_mibs(net);
100081 if (err)
100082 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100083 index c3bf2d2..1f00573 100644
100084 --- a/net/ipv6/datagram.c
100085 +++ b/net/ipv6/datagram.c
100086 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100087 0,
100088 sock_i_ino(sp),
100089 atomic_read(&sp->sk_refcnt), sp,
100090 - atomic_read(&sp->sk_drops));
100091 + atomic_read_unchecked(&sp->sk_drops));
100092 }
100093 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100094 index 7b32652..0bc348b 100644
100095 --- a/net/ipv6/icmp.c
100096 +++ b/net/ipv6/icmp.c
100097 @@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100098
100099 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100100 {
100101 - struct ctl_table *table;
100102 + ctl_table_no_const *table;
100103
100104 table = kmemdup(ipv6_icmp_table_template,
100105 sizeof(ipv6_icmp_table_template),
100106 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100107 index f3ffb43..1172ba7 100644
100108 --- a/net/ipv6/ip6_gre.c
100109 +++ b/net/ipv6/ip6_gre.c
100110 @@ -71,7 +71,7 @@ struct ip6gre_net {
100111 struct net_device *fb_tunnel_dev;
100112 };
100113
100114 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100115 +static struct rtnl_link_ops ip6gre_link_ops;
100116 static int ip6gre_tunnel_init(struct net_device *dev);
100117 static void ip6gre_tunnel_setup(struct net_device *dev);
100118 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100119 @@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100120 }
100121
100122
100123 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
100124 +static struct inet6_protocol ip6gre_protocol = {
100125 .handler = ip6gre_rcv,
100126 .err_handler = ip6gre_err,
100127 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100128 @@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100129 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100130 };
100131
100132 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100133 +static struct rtnl_link_ops ip6gre_link_ops = {
100134 .kind = "ip6gre",
100135 .maxtype = IFLA_GRE_MAX,
100136 .policy = ip6gre_policy,
100137 @@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100138 .fill_info = ip6gre_fill_info,
100139 };
100140
100141 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100142 +static struct rtnl_link_ops ip6gre_tap_ops = {
100143 .kind = "ip6gretap",
100144 .maxtype = IFLA_GRE_MAX,
100145 .policy = ip6gre_policy,
100146 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100147 index 5db8d31..4a72c26 100644
100148 --- a/net/ipv6/ip6_tunnel.c
100149 +++ b/net/ipv6/ip6_tunnel.c
100150 @@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100151
100152 static int ip6_tnl_dev_init(struct net_device *dev);
100153 static void ip6_tnl_dev_setup(struct net_device *dev);
100154 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
100155 +static struct rtnl_link_ops ip6_link_ops;
100156
100157 static int ip6_tnl_net_id __read_mostly;
100158 struct ip6_tnl_net {
100159 @@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100160 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100161 };
100162
100163 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100164 +static struct rtnl_link_ops ip6_link_ops = {
100165 .kind = "ip6tnl",
100166 .maxtype = IFLA_IPTUN_MAX,
100167 .policy = ip6_tnl_policy,
100168 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100169 index 2d19272..3a46322 100644
100170 --- a/net/ipv6/ip6_vti.c
100171 +++ b/net/ipv6/ip6_vti.c
100172 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100173
100174 static int vti6_dev_init(struct net_device *dev);
100175 static void vti6_dev_setup(struct net_device *dev);
100176 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
100177 +static struct rtnl_link_ops vti6_link_ops;
100178
100179 static int vti6_net_id __read_mostly;
100180 struct vti6_net {
100181 @@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100182 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100183 };
100184
100185 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100186 +static struct rtnl_link_ops vti6_link_ops = {
100187 .kind = "vti6",
100188 .maxtype = IFLA_VTI_MAX,
100189 .policy = vti6_policy,
100190 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100191 index 0a00f44..bec42b2 100644
100192 --- a/net/ipv6/ipv6_sockglue.c
100193 +++ b/net/ipv6/ipv6_sockglue.c
100194 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100195 if (sk->sk_type != SOCK_STREAM)
100196 return -ENOPROTOOPT;
100197
100198 - msg.msg_control = optval;
100199 + msg.msg_control = (void __force_kernel *)optval;
100200 msg.msg_controllen = len;
100201 msg.msg_flags = flags;
100202
100203 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100204 index 710238f..0fd1816 100644
100205 --- a/net/ipv6/netfilter/ip6_tables.c
100206 +++ b/net/ipv6/netfilter/ip6_tables.c
100207 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100208 #endif
100209
100210 static int get_info(struct net *net, void __user *user,
100211 - const int *len, int compat)
100212 + int len, int compat)
100213 {
100214 char name[XT_TABLE_MAXNAMELEN];
100215 struct xt_table *t;
100216 int ret;
100217
100218 - if (*len != sizeof(struct ip6t_getinfo)) {
100219 - duprintf("length %u != %zu\n", *len,
100220 + if (len != sizeof(struct ip6t_getinfo)) {
100221 + duprintf("length %u != %zu\n", len,
100222 sizeof(struct ip6t_getinfo));
100223 return -EINVAL;
100224 }
100225 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100226 info.size = private->size;
100227 strcpy(info.name, name);
100228
100229 - if (copy_to_user(user, &info, *len) != 0)
100230 + if (copy_to_user(user, &info, len) != 0)
100231 ret = -EFAULT;
100232 else
100233 ret = 0;
100234 @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100235
100236 switch (cmd) {
100237 case IP6T_SO_GET_INFO:
100238 - ret = get_info(sock_net(sk), user, len, 1);
100239 + ret = get_info(sock_net(sk), user, *len, 1);
100240 break;
100241 case IP6T_SO_GET_ENTRIES:
100242 ret = compat_get_entries(sock_net(sk), user, len);
100243 @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100244
100245 switch (cmd) {
100246 case IP6T_SO_GET_INFO:
100247 - ret = get_info(sock_net(sk), user, len, 0);
100248 + ret = get_info(sock_net(sk), user, *len, 0);
100249 break;
100250
100251 case IP6T_SO_GET_ENTRIES:
100252 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100253 index 767ab8d..c5ec70a 100644
100254 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100255 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100256 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100257
100258 static int nf_ct_frag6_sysctl_register(struct net *net)
100259 {
100260 - struct ctl_table *table;
100261 + ctl_table_no_const *table = NULL;
100262 struct ctl_table_header *hdr;
100263
100264 - table = nf_ct_frag6_sysctl_table;
100265 if (!net_eq(net, &init_net)) {
100266 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100267 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100268 GFP_KERNEL);
100269 if (table == NULL)
100270 goto err_alloc;
100271 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100272 table[0].data = &net->nf_frag.frags.timeout;
100273 table[1].data = &net->nf_frag.frags.low_thresh;
100274 table[2].data = &net->nf_frag.frags.high_thresh;
100275 - }
100276 -
100277 - hdr = register_net_sysctl(net, "net/netfilter", table);
100278 + hdr = register_net_sysctl(net, "net/netfilter", table);
100279 + } else
100280 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100281 if (hdr == NULL)
100282 goto err_reg;
100283
100284 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100285 return 0;
100286
100287 err_reg:
100288 - if (!net_eq(net, &init_net))
100289 - kfree(table);
100290 + kfree(table);
100291 err_alloc:
100292 return -ENOMEM;
100293 }
100294 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100295 index 827f795..7e28e82 100644
100296 --- a/net/ipv6/output_core.c
100297 +++ b/net/ipv6/output_core.c
100298 @@ -9,8 +9,8 @@
100299
100300 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100301 {
100302 - static atomic_t ipv6_fragmentation_id;
100303 - int old, new;
100304 + static atomic_unchecked_t ipv6_fragmentation_id;
100305 + int id;
100306
100307 #if IS_ENABLED(CONFIG_IPV6)
100308 if (rt && !(rt->dst.flags & DST_NOPEER)) {
100309 @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100310 }
100311 }
100312 #endif
100313 - do {
100314 - old = atomic_read(&ipv6_fragmentation_id);
100315 - new = old + 1;
100316 - if (!new)
100317 - new = 1;
100318 - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
100319 - fhdr->identification = htonl(new);
100320 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100321 + if (!id)
100322 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100323 + fhdr->identification = htonl(id);
100324 }
100325 EXPORT_SYMBOL(ipv6_select_ident);
100326
100327 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100328 index bda7429..469b26b 100644
100329 --- a/net/ipv6/ping.c
100330 +++ b/net/ipv6/ping.c
100331 @@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100332 };
100333 #endif
100334
100335 +static struct pingv6_ops real_pingv6_ops = {
100336 + .ipv6_recv_error = ipv6_recv_error,
100337 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100338 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100339 + .icmpv6_err_convert = icmpv6_err_convert,
100340 + .ipv6_icmp_error = ipv6_icmp_error,
100341 + .ipv6_chk_addr = ipv6_chk_addr,
100342 +};
100343 +
100344 +static struct pingv6_ops dummy_pingv6_ops = {
100345 + .ipv6_recv_error = dummy_ipv6_recv_error,
100346 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100347 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100348 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
100349 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
100350 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
100351 +};
100352 +
100353 int __init pingv6_init(void)
100354 {
100355 #ifdef CONFIG_PROC_FS
100356 @@ -253,13 +271,7 @@ int __init pingv6_init(void)
100357 if (ret)
100358 return ret;
100359 #endif
100360 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100361 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100362 - pingv6_ops.ip6_datagram_recv_specific_ctl =
100363 - ip6_datagram_recv_specific_ctl;
100364 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100365 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100366 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100367 + pingv6_ops = &real_pingv6_ops;
100368 return inet6_register_protosw(&pingv6_protosw);
100369 }
100370
100371 @@ -268,14 +280,9 @@ int __init pingv6_init(void)
100372 */
100373 void pingv6_exit(void)
100374 {
100375 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100376 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100377 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100378 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100379 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100380 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100381 #ifdef CONFIG_PROC_FS
100382 unregister_pernet_subsys(&ping_v6_net_ops);
100383 #endif
100384 + pingv6_ops = &dummy_pingv6_ops;
100385 inet6_unregister_protosw(&pingv6_protosw);
100386 }
100387 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100388 index 091d066..139d410 100644
100389 --- a/net/ipv6/proc.c
100390 +++ b/net/ipv6/proc.c
100391 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100392 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100393 goto proc_snmp6_fail;
100394
100395 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100396 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100397 if (!net->mib.proc_net_devsnmp6)
100398 goto proc_dev_snmp6_fail;
100399 return 0;
100400 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100401 index 1f29996..46fe0c7 100644
100402 --- a/net/ipv6/raw.c
100403 +++ b/net/ipv6/raw.c
100404 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100405 {
100406 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100407 skb_checksum_complete(skb)) {
100408 - atomic_inc(&sk->sk_drops);
100409 + atomic_inc_unchecked(&sk->sk_drops);
100410 kfree_skb(skb);
100411 return NET_RX_DROP;
100412 }
100413 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100414 struct raw6_sock *rp = raw6_sk(sk);
100415
100416 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100417 - atomic_inc(&sk->sk_drops);
100418 + atomic_inc_unchecked(&sk->sk_drops);
100419 kfree_skb(skb);
100420 return NET_RX_DROP;
100421 }
100422 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100423
100424 if (inet->hdrincl) {
100425 if (skb_checksum_complete(skb)) {
100426 - atomic_inc(&sk->sk_drops);
100427 + atomic_inc_unchecked(&sk->sk_drops);
100428 kfree_skb(skb);
100429 return NET_RX_DROP;
100430 }
100431 @@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100432 if (flags & MSG_OOB)
100433 return -EOPNOTSUPP;
100434
100435 + if (addr_len)
100436 + *addr_len=sizeof(*sin6);
100437 +
100438 if (flags & MSG_ERRQUEUE)
100439 return ipv6_recv_error(sk, msg, len, addr_len);
100440
100441 @@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100442 sin6->sin6_flowinfo = 0;
100443 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100444 IP6CB(skb)->iif);
100445 - *addr_len = sizeof(*sin6);
100446 }
100447
100448 sock_recv_ts_and_drops(msg, sk, skb);
100449 @@ -610,7 +612,7 @@ out:
100450 return err;
100451 }
100452
100453 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100454 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100455 struct flowi6 *fl6, struct dst_entry **dstp,
100456 unsigned int flags)
100457 {
100458 @@ -922,12 +924,15 @@ do_confirm:
100459 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100460 char __user *optval, int optlen)
100461 {
100462 + struct icmp6_filter filter;
100463 +
100464 switch (optname) {
100465 case ICMPV6_FILTER:
100466 if (optlen > sizeof(struct icmp6_filter))
100467 optlen = sizeof(struct icmp6_filter);
100468 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100469 + if (copy_from_user(&filter, optval, optlen))
100470 return -EFAULT;
100471 + raw6_sk(sk)->filter = filter;
100472 return 0;
100473 default:
100474 return -ENOPROTOOPT;
100475 @@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100476 char __user *optval, int __user *optlen)
100477 {
100478 int len;
100479 + struct icmp6_filter filter;
100480
100481 switch (optname) {
100482 case ICMPV6_FILTER:
100483 @@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100484 len = sizeof(struct icmp6_filter);
100485 if (put_user(len, optlen))
100486 return -EFAULT;
100487 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100488 + filter = raw6_sk(sk)->filter;
100489 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
100490 return -EFAULT;
100491 return 0;
100492 default:
100493 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100494 index cc85a9b..526a133 100644
100495 --- a/net/ipv6/reassembly.c
100496 +++ b/net/ipv6/reassembly.c
100497 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100498
100499 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100500 {
100501 - struct ctl_table *table;
100502 + ctl_table_no_const *table = NULL;
100503 struct ctl_table_header *hdr;
100504
100505 - table = ip6_frags_ns_ctl_table;
100506 if (!net_eq(net, &init_net)) {
100507 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100508 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100509 if (table == NULL)
100510 goto err_alloc;
100511
100512 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100513 /* Don't export sysctls to unprivileged users */
100514 if (net->user_ns != &init_user_ns)
100515 table[0].procname = NULL;
100516 - }
100517 + hdr = register_net_sysctl(net, "net/ipv6", table);
100518 + } else
100519 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100520
100521 - hdr = register_net_sysctl(net, "net/ipv6", table);
100522 if (hdr == NULL)
100523 goto err_reg;
100524
100525 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100526 return 0;
100527
100528 err_reg:
100529 - if (!net_eq(net, &init_net))
100530 - kfree(table);
100531 + kfree(table);
100532 err_alloc:
100533 return -ENOMEM;
100534 }
100535 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100536 index fba54a4..73e374e 100644
100537 --- a/net/ipv6/route.c
100538 +++ b/net/ipv6/route.c
100539 @@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
100540
100541 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100542 {
100543 - struct ctl_table *table;
100544 + ctl_table_no_const *table;
100545
100546 table = kmemdup(ipv6_route_table_template,
100547 sizeof(ipv6_route_table_template),
100548 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100549 index b4d74c8..b4f3fbe 100644
100550 --- a/net/ipv6/sit.c
100551 +++ b/net/ipv6/sit.c
100552 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100553 static void ipip6_dev_free(struct net_device *dev);
100554 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100555 __be32 *v4dst);
100556 -static struct rtnl_link_ops sit_link_ops __read_mostly;
100557 +static struct rtnl_link_ops sit_link_ops;
100558
100559 static int sit_net_id __read_mostly;
100560 struct sit_net {
100561 @@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100562 unregister_netdevice_queue(dev, head);
100563 }
100564
100565 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
100566 +static struct rtnl_link_ops sit_link_ops = {
100567 .kind = "sit",
100568 .maxtype = IFLA_IPTUN_MAX,
100569 .policy = ipip6_policy,
100570 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100571 index 7f405a1..eabef92 100644
100572 --- a/net/ipv6/sysctl_net_ipv6.c
100573 +++ b/net/ipv6/sysctl_net_ipv6.c
100574 @@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100575
100576 static int __net_init ipv6_sysctl_net_init(struct net *net)
100577 {
100578 - struct ctl_table *ipv6_table;
100579 + ctl_table_no_const *ipv6_table;
100580 struct ctl_table *ipv6_route_table;
100581 struct ctl_table *ipv6_icmp_table;
100582 int err;
100583 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100584 index 889079b..a04512c 100644
100585 --- a/net/ipv6/tcp_ipv6.c
100586 +++ b/net/ipv6/tcp_ipv6.c
100587 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100588 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100589 }
100590
100591 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100592 +extern int grsec_enable_blackhole;
100593 +#endif
100594 +
100595 static void tcp_v6_hash(struct sock *sk)
100596 {
100597 if (sk->sk_state != TCP_CLOSE) {
100598 @@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100599 return 0;
100600
100601 reset:
100602 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100603 + if (!grsec_enable_blackhole)
100604 +#endif
100605 tcp_v6_send_reset(sk, skb);
100606 discard:
100607 if (opt_skb)
100608 @@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100609 TCP_SKB_CB(skb)->sacked = 0;
100610
100611 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100612 - if (!sk)
100613 + if (!sk) {
100614 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100615 + ret = 1;
100616 +#endif
100617 goto no_tcp_socket;
100618 + }
100619
100620 process:
100621 - if (sk->sk_state == TCP_TIME_WAIT)
100622 + if (sk->sk_state == TCP_TIME_WAIT) {
100623 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100624 + ret = 2;
100625 +#endif
100626 goto do_time_wait;
100627 + }
100628
100629 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100630 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100631 @@ -1553,6 +1568,10 @@ csum_error:
100632 bad_packet:
100633 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100634 } else {
100635 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100636 + if (!grsec_enable_blackhole || (ret == 1 &&
100637 + (skb->dev->flags & IFF_LOOPBACK)))
100638 +#endif
100639 tcp_v6_send_reset(NULL, skb);
100640 }
100641
100642 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100643 index 1e586d9..384a9c9 100644
100644 --- a/net/ipv6/udp.c
100645 +++ b/net/ipv6/udp.c
100646 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100647 udp_ipv6_hash_secret + net_hash_mix(net));
100648 }
100649
100650 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100651 +extern int grsec_enable_blackhole;
100652 +#endif
100653 +
100654 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100655 {
100656 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100657 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100658 int is_udp4;
100659 bool slow;
100660
100661 + if (addr_len)
100662 + *addr_len = sizeof(struct sockaddr_in6);
100663 +
100664 if (flags & MSG_ERRQUEUE)
100665 return ipv6_recv_error(sk, msg, len, addr_len);
100666
100667 @@ -435,7 +442,7 @@ try_again:
100668 if (unlikely(err)) {
100669 trace_kfree_skb(skb, udpv6_recvmsg);
100670 if (!peeked) {
100671 - atomic_inc(&sk->sk_drops);
100672 + atomic_inc_unchecked(&sk->sk_drops);
100673 if (is_udp4)
100674 UDP_INC_STATS_USER(sock_net(sk),
100675 UDP_MIB_INERRORS,
100676 @@ -475,7 +482,7 @@ try_again:
100677 ipv6_iface_scope_id(&sin6->sin6_addr,
100678 IP6CB(skb)->iif);
100679 }
100680 - *addr_len = sizeof(*sin6);
100681 +
100682 }
100683
100684 if (np->rxopt.all)
100685 @@ -690,7 +697,7 @@ csum_error:
100686 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100687 drop:
100688 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100689 - atomic_inc(&sk->sk_drops);
100690 + atomic_inc_unchecked(&sk->sk_drops);
100691 kfree_skb(skb);
100692 return -1;
100693 }
100694 @@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100695 if (likely(skb1 == NULL))
100696 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100697 if (!skb1) {
100698 - atomic_inc(&sk->sk_drops);
100699 + atomic_inc_unchecked(&sk->sk_drops);
100700 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100701 IS_UDPLITE(sk));
100702 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100703 @@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100704 goto csum_error;
100705
100706 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100707 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100708 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100709 +#endif
100710 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100711
100712 kfree_skb(skb);
100713 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100714 index 5f8e128..865d38e 100644
100715 --- a/net/ipv6/xfrm6_policy.c
100716 +++ b/net/ipv6/xfrm6_policy.c
100717 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100718 }
100719 }
100720
100721 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100722 +static int xfrm6_garbage_collect(struct dst_ops *ops)
100723 {
100724 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100725
100726 - xfrm6_policy_afinfo.garbage_collect(net);
100727 + xfrm_garbage_collect_deferred(net);
100728 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100729 }
100730
100731 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
100732
100733 static int __net_init xfrm6_net_init(struct net *net)
100734 {
100735 - struct ctl_table *table;
100736 + ctl_table_no_const *table = NULL;
100737 struct ctl_table_header *hdr;
100738
100739 - table = xfrm6_policy_table;
100740 if (!net_eq(net, &init_net)) {
100741 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100742 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100743 if (!table)
100744 goto err_alloc;
100745
100746 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
100747 - }
100748 + hdr = register_net_sysctl(net, "net/ipv6", table);
100749 + } else
100750 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
100751
100752 - hdr = register_net_sysctl(net, "net/ipv6", table);
100753 if (!hdr)
100754 goto err_reg;
100755
100756 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
100757 return 0;
100758
100759 err_reg:
100760 - if (!net_eq(net, &init_net))
100761 - kfree(table);
100762 + kfree(table);
100763 err_alloc:
100764 return -ENOMEM;
100765 }
100766 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
100767 index e15c16a..7cf07aa 100644
100768 --- a/net/ipx/ipx_proc.c
100769 +++ b/net/ipx/ipx_proc.c
100770 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
100771 struct proc_dir_entry *p;
100772 int rc = -ENOMEM;
100773
100774 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
100775 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
100776
100777 if (!ipx_proc_dir)
100778 goto out;
100779 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
100780 index 2ba8b97..6d33010 100644
100781 --- a/net/irda/ircomm/ircomm_tty.c
100782 +++ b/net/irda/ircomm/ircomm_tty.c
100783 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100784 add_wait_queue(&port->open_wait, &wait);
100785
100786 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
100787 - __FILE__, __LINE__, tty->driver->name, port->count);
100788 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100789
100790 spin_lock_irqsave(&port->lock, flags);
100791 if (!tty_hung_up_p(filp))
100792 - port->count--;
100793 + atomic_dec(&port->count);
100794 port->blocked_open++;
100795 spin_unlock_irqrestore(&port->lock, flags);
100796
100797 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100798 }
100799
100800 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
100801 - __FILE__, __LINE__, tty->driver->name, port->count);
100802 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100803
100804 schedule();
100805 }
100806 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100807
100808 spin_lock_irqsave(&port->lock, flags);
100809 if (!tty_hung_up_p(filp))
100810 - port->count++;
100811 + atomic_inc(&port->count);
100812 port->blocked_open--;
100813 spin_unlock_irqrestore(&port->lock, flags);
100814
100815 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
100816 - __FILE__, __LINE__, tty->driver->name, port->count);
100817 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100818
100819 if (!retval)
100820 port->flags |= ASYNC_NORMAL_ACTIVE;
100821 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
100822
100823 /* ++ is not atomic, so this should be protected - Jean II */
100824 spin_lock_irqsave(&self->port.lock, flags);
100825 - self->port.count++;
100826 + atomic_inc(&self->port.count);
100827 spin_unlock_irqrestore(&self->port.lock, flags);
100828 tty_port_tty_set(&self->port, tty);
100829
100830 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
100831 - self->line, self->port.count);
100832 + self->line, atomic_read(&self->port.count));
100833
100834 /* Not really used by us, but lets do it anyway */
100835 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
100836 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
100837 tty_kref_put(port->tty);
100838 }
100839 port->tty = NULL;
100840 - port->count = 0;
100841 + atomic_set(&port->count, 0);
100842 spin_unlock_irqrestore(&port->lock, flags);
100843
100844 wake_up_interruptible(&port->open_wait);
100845 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
100846 seq_putc(m, '\n');
100847
100848 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
100849 - seq_printf(m, "Open count: %d\n", self->port.count);
100850 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
100851 seq_printf(m, "Max data size: %d\n", self->max_data_size);
100852 seq_printf(m, "Max header size: %d\n", self->max_header_size);
100853
100854 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
100855 index b9ac598..f88cc56 100644
100856 --- a/net/irda/irproc.c
100857 +++ b/net/irda/irproc.c
100858 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
100859 {
100860 int i;
100861
100862 - proc_irda = proc_mkdir("irda", init_net.proc_net);
100863 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
100864 if (proc_irda == NULL)
100865 return;
100866
100867 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
100868 index c4b7218..3e83259 100644
100869 --- a/net/iucv/af_iucv.c
100870 +++ b/net/iucv/af_iucv.c
100871 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
100872
100873 write_lock_bh(&iucv_sk_list.lock);
100874
100875 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
100876 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100877 while (__iucv_get_sock_by_name(name)) {
100878 sprintf(name, "%08x",
100879 - atomic_inc_return(&iucv_sk_list.autobind_name));
100880 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100881 }
100882
100883 write_unlock_bh(&iucv_sk_list.lock);
100884 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
100885 index cd5b8ec..f205e6b 100644
100886 --- a/net/iucv/iucv.c
100887 +++ b/net/iucv/iucv.c
100888 @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
100889 return NOTIFY_OK;
100890 }
100891
100892 -static struct notifier_block __refdata iucv_cpu_notifier = {
100893 +static struct notifier_block iucv_cpu_notifier = {
100894 .notifier_call = iucv_cpu_notify,
100895 };
100896
100897 diff --git a/net/key/af_key.c b/net/key/af_key.c
100898 index 7932697..a13d158 100644
100899 --- a/net/key/af_key.c
100900 +++ b/net/key/af_key.c
100901 @@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
100902 static u32 get_acqseq(void)
100903 {
100904 u32 res;
100905 - static atomic_t acqseq;
100906 + static atomic_unchecked_t acqseq;
100907
100908 do {
100909 - res = atomic_inc_return(&acqseq);
100910 + res = atomic_inc_return_unchecked(&acqseq);
100911 } while (!res);
100912 return res;
100913 }
100914 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
100915 index 0b44d85..1a7f88b 100644
100916 --- a/net/l2tp/l2tp_ip.c
100917 +++ b/net/l2tp/l2tp_ip.c
100918 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100919 if (flags & MSG_OOB)
100920 goto out;
100921
100922 + if (addr_len)
100923 + *addr_len = sizeof(*sin);
100924 +
100925 skb = skb_recv_datagram(sk, flags, noblock, &err);
100926 if (!skb)
100927 goto out;
100928 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100929 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100930 sin->sin_port = 0;
100931 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
100932 - *addr_len = sizeof(*sin);
100933 }
100934 if (inet->cmsg_flags)
100935 ip_cmsg_recv(msg, skb);
100936 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
100937 index 1a3c7e0..80f8b0c 100644
100938 --- a/net/llc/llc_proc.c
100939 +++ b/net/llc/llc_proc.c
100940 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
100941 int rc = -ENOMEM;
100942 struct proc_dir_entry *p;
100943
100944 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
100945 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
100946 if (!llc_proc_dir)
100947 goto out;
100948
100949 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
100950 index 453e974..b3a43a5 100644
100951 --- a/net/mac80211/cfg.c
100952 +++ b/net/mac80211/cfg.c
100953 @@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
100954 ret = ieee80211_vif_use_channel(sdata, chandef,
100955 IEEE80211_CHANCTX_EXCLUSIVE);
100956 }
100957 - } else if (local->open_count == local->monitors) {
100958 + } else if (local_read(&local->open_count) == local->monitors) {
100959 local->_oper_chandef = *chandef;
100960 ieee80211_hw_config(local, 0);
100961 }
100962 @@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
100963 else
100964 local->probe_req_reg--;
100965
100966 - if (!local->open_count)
100967 + if (!local_read(&local->open_count))
100968 break;
100969
100970 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
100971 @@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
100972 if (chanctx_conf) {
100973 *chandef = chanctx_conf->def;
100974 ret = 0;
100975 - } else if (local->open_count > 0 &&
100976 - local->open_count == local->monitors &&
100977 + } else if (local_read(&local->open_count) > 0 &&
100978 + local_read(&local->open_count) == local->monitors &&
100979 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
100980 if (local->use_chanctx)
100981 *chandef = local->monitor_chandef;
100982 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
100983 index 6bd4984..d8805c5 100644
100984 --- a/net/mac80211/ieee80211_i.h
100985 +++ b/net/mac80211/ieee80211_i.h
100986 @@ -28,6 +28,7 @@
100987 #include <net/ieee80211_radiotap.h>
100988 #include <net/cfg80211.h>
100989 #include <net/mac80211.h>
100990 +#include <asm/local.h>
100991 #include "key.h"
100992 #include "sta_info.h"
100993 #include "debug.h"
100994 @@ -994,7 +995,7 @@ struct ieee80211_local {
100995 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
100996 spinlock_t queue_stop_reason_lock;
100997
100998 - int open_count;
100999 + local_t open_count;
101000 int monitors, cooked_mntrs;
101001 /* number of interfaces with corresponding FIF_ flags */
101002 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101003 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101004 index ce1c443..6cd39e1 100644
101005 --- a/net/mac80211/iface.c
101006 +++ b/net/mac80211/iface.c
101007 @@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101008 break;
101009 }
101010
101011 - if (local->open_count == 0) {
101012 + if (local_read(&local->open_count) == 0) {
101013 res = drv_start(local);
101014 if (res)
101015 goto err_del_bss;
101016 @@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101017 res = drv_add_interface(local, sdata);
101018 if (res)
101019 goto err_stop;
101020 - } else if (local->monitors == 0 && local->open_count == 0) {
101021 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101022 res = ieee80211_add_virtual_monitor(local);
101023 if (res)
101024 goto err_stop;
101025 @@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101026 atomic_inc(&local->iff_promiscs);
101027
101028 if (coming_up)
101029 - local->open_count++;
101030 + local_inc(&local->open_count);
101031
101032 if (hw_reconf_flags)
101033 ieee80211_hw_config(local, hw_reconf_flags);
101034 @@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101035 err_del_interface:
101036 drv_remove_interface(local, sdata);
101037 err_stop:
101038 - if (!local->open_count)
101039 + if (!local_read(&local->open_count))
101040 drv_stop(local);
101041 err_del_bss:
101042 sdata->bss = NULL;
101043 @@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101044 }
101045
101046 if (going_down)
101047 - local->open_count--;
101048 + local_dec(&local->open_count);
101049
101050 switch (sdata->vif.type) {
101051 case NL80211_IFTYPE_AP_VLAN:
101052 @@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101053 }
101054 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101055
101056 - if (local->open_count == 0)
101057 + if (local_read(&local->open_count) == 0)
101058 ieee80211_clear_tx_pending(local);
101059
101060 /*
101061 @@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101062
101063 ieee80211_recalc_ps(local, -1);
101064
101065 - if (local->open_count == 0) {
101066 + if (local_read(&local->open_count) == 0) {
101067 ieee80211_stop_device(local);
101068
101069 /* no reconfiguring after stop! */
101070 @@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101071 ieee80211_configure_filter(local);
101072 ieee80211_hw_config(local, hw_reconf_flags);
101073
101074 - if (local->monitors == local->open_count)
101075 + if (local->monitors == local_read(&local->open_count))
101076 ieee80211_add_virtual_monitor(local);
101077 }
101078
101079 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101080 index c7a7a86..a74f57b 100644
101081 --- a/net/mac80211/main.c
101082 +++ b/net/mac80211/main.c
101083 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101084 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101085 IEEE80211_CONF_CHANGE_POWER);
101086
101087 - if (changed && local->open_count) {
101088 + if (changed && local_read(&local->open_count)) {
101089 ret = drv_config(local, changed);
101090 /*
101091 * Goal:
101092 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101093 index d478b88..8c8d157 100644
101094 --- a/net/mac80211/pm.c
101095 +++ b/net/mac80211/pm.c
101096 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101097 struct ieee80211_sub_if_data *sdata;
101098 struct sta_info *sta;
101099
101100 - if (!local->open_count)
101101 + if (!local_read(&local->open_count))
101102 goto suspend;
101103
101104 ieee80211_scan_cancel(local);
101105 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101106 cancel_work_sync(&local->dynamic_ps_enable_work);
101107 del_timer_sync(&local->dynamic_ps_timer);
101108
101109 - local->wowlan = wowlan && local->open_count;
101110 + local->wowlan = wowlan && local_read(&local->open_count);
101111 if (local->wowlan) {
101112 int err = drv_suspend(local, wowlan);
101113 if (err < 0) {
101114 @@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101115 WARN_ON(!list_empty(&local->chanctx_list));
101116
101117 /* stop hardware - this must stop RX */
101118 - if (local->open_count)
101119 + if (local_read(&local->open_count))
101120 ieee80211_stop_device(local);
101121
101122 suspend:
101123 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101124 index 22b223f..ab70070 100644
101125 --- a/net/mac80211/rate.c
101126 +++ b/net/mac80211/rate.c
101127 @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101128
101129 ASSERT_RTNL();
101130
101131 - if (local->open_count)
101132 + if (local_read(&local->open_count))
101133 return -EBUSY;
101134
101135 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101136 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101137 index 6ff1346..936ca9a 100644
101138 --- a/net/mac80211/rc80211_pid_debugfs.c
101139 +++ b/net/mac80211/rc80211_pid_debugfs.c
101140 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101141
101142 spin_unlock_irqrestore(&events->lock, status);
101143
101144 - if (copy_to_user(buf, pb, p))
101145 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101146 return -EFAULT;
101147
101148 return p;
101149 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101150 index b8700d4..89086d5 100644
101151 --- a/net/mac80211/util.c
101152 +++ b/net/mac80211/util.c
101153 @@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101154 }
101155 #endif
101156 /* everything else happens only if HW was up & running */
101157 - if (!local->open_count)
101158 + if (!local_read(&local->open_count))
101159 goto wake_up;
101160
101161 /*
101162 @@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101163 local->in_reconfig = false;
101164 barrier();
101165
101166 - if (local->monitors == local->open_count && local->monitors > 0)
101167 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101168 ieee80211_add_virtual_monitor(local);
101169
101170 /*
101171 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101172 index e9410d1..77b6378 100644
101173 --- a/net/netfilter/Kconfig
101174 +++ b/net/netfilter/Kconfig
101175 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101176
101177 To compile it as a module, choose M here. If unsure, say N.
101178
101179 +config NETFILTER_XT_MATCH_GRADM
101180 + tristate '"gradm" match support'
101181 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101182 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101183 + ---help---
101184 + The gradm match allows to match on grsecurity RBAC being enabled.
101185 + It is useful when iptables rules are applied early on bootup to
101186 + prevent connections to the machine (except from a trusted host)
101187 + while the RBAC system is disabled.
101188 +
101189 config NETFILTER_XT_MATCH_HASHLIMIT
101190 tristate '"hashlimit" match support'
101191 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101192 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101193 index bffdad7..f9317d1 100644
101194 --- a/net/netfilter/Makefile
101195 +++ b/net/netfilter/Makefile
101196 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101197 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101198 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101199 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101200 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101201 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101202 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101203 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101204 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101205 index de770ec..3fc49d2 100644
101206 --- a/net/netfilter/ipset/ip_set_core.c
101207 +++ b/net/netfilter/ipset/ip_set_core.c
101208 @@ -1922,7 +1922,7 @@ done:
101209 return ret;
101210 }
101211
101212 -static struct nf_sockopt_ops so_set __read_mostly = {
101213 +static struct nf_sockopt_ops so_set = {
101214 .pf = PF_INET,
101215 .get_optmin = SO_IP_SET,
101216 .get_optmax = SO_IP_SET + 1,
101217 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101218 index a8eb0a8..86f2de4 100644
101219 --- a/net/netfilter/ipvs/ip_vs_conn.c
101220 +++ b/net/netfilter/ipvs/ip_vs_conn.c
101221 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101222 /* Increase the refcnt counter of the dest */
101223 ip_vs_dest_hold(dest);
101224
101225 - conn_flags = atomic_read(&dest->conn_flags);
101226 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
101227 if (cp->protocol != IPPROTO_UDP)
101228 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101229 flags = cp->flags;
101230 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101231
101232 cp->control = NULL;
101233 atomic_set(&cp->n_control, 0);
101234 - atomic_set(&cp->in_pkts, 0);
101235 + atomic_set_unchecked(&cp->in_pkts, 0);
101236
101237 cp->packet_xmit = NULL;
101238 cp->app = NULL;
101239 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101240
101241 /* Don't drop the entry if its number of incoming packets is not
101242 located in [0, 8] */
101243 - i = atomic_read(&cp->in_pkts);
101244 + i = atomic_read_unchecked(&cp->in_pkts);
101245 if (i > 8 || i < 0) return 0;
101246
101247 if (!todrop_rate[i]) return 0;
101248 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101249 index 4f26ee4..6a9d7c3 100644
101250 --- a/net/netfilter/ipvs/ip_vs_core.c
101251 +++ b/net/netfilter/ipvs/ip_vs_core.c
101252 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101253 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101254 /* do not touch skb anymore */
101255
101256 - atomic_inc(&cp->in_pkts);
101257 + atomic_inc_unchecked(&cp->in_pkts);
101258 ip_vs_conn_put(cp);
101259 return ret;
101260 }
101261 @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101262 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101263 pkts = sysctl_sync_threshold(ipvs);
101264 else
101265 - pkts = atomic_add_return(1, &cp->in_pkts);
101266 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101267
101268 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101269 ip_vs_sync_conn(net, cp, pkts);
101270 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101271 index 35be035..50f8834 100644
101272 --- a/net/netfilter/ipvs/ip_vs_ctl.c
101273 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
101274 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101275 */
101276 ip_vs_rs_hash(ipvs, dest);
101277 }
101278 - atomic_set(&dest->conn_flags, conn_flags);
101279 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
101280
101281 /* bind the service */
101282 old_svc = rcu_dereference_protected(dest->svc, 1);
101283 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101284 * align with netns init in ip_vs_control_net_init()
101285 */
101286
101287 -static struct ctl_table vs_vars[] = {
101288 +static ctl_table_no_const vs_vars[] __read_only = {
101289 {
101290 .procname = "amemthresh",
101291 .maxlen = sizeof(int),
101292 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101293 " %-7s %-6d %-10d %-10d\n",
101294 &dest->addr.in6,
101295 ntohs(dest->port),
101296 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101297 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101298 atomic_read(&dest->weight),
101299 atomic_read(&dest->activeconns),
101300 atomic_read(&dest->inactconns));
101301 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101302 "%-7s %-6d %-10d %-10d\n",
101303 ntohl(dest->addr.ip),
101304 ntohs(dest->port),
101305 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101306 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101307 atomic_read(&dest->weight),
101308 atomic_read(&dest->activeconns),
101309 atomic_read(&dest->inactconns));
101310 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101311
101312 entry.addr = dest->addr.ip;
101313 entry.port = dest->port;
101314 - entry.conn_flags = atomic_read(&dest->conn_flags);
101315 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101316 entry.weight = atomic_read(&dest->weight);
101317 entry.u_threshold = dest->u_threshold;
101318 entry.l_threshold = dest->l_threshold;
101319 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101320 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101321 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101322 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101323 - (atomic_read(&dest->conn_flags) &
101324 + (atomic_read_unchecked(&dest->conn_flags) &
101325 IP_VS_CONN_F_FWD_MASK)) ||
101326 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101327 atomic_read(&dest->weight)) ||
101328 @@ -3580,7 +3580,7 @@ out:
101329 }
101330
101331
101332 -static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
101333 +static const struct genl_ops ip_vs_genl_ops[] = {
101334 {
101335 .cmd = IPVS_CMD_NEW_SERVICE,
101336 .flags = GENL_ADMIN_PERM,
101337 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101338 {
101339 int idx;
101340 struct netns_ipvs *ipvs = net_ipvs(net);
101341 - struct ctl_table *tbl;
101342 + ctl_table_no_const *tbl;
101343
101344 atomic_set(&ipvs->dropentry, 0);
101345 spin_lock_init(&ipvs->dropentry_lock);
101346 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101347 index ca056a3..9cf01ef 100644
101348 --- a/net/netfilter/ipvs/ip_vs_lblc.c
101349 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
101350 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101351 * IPVS LBLC sysctl table
101352 */
101353 #ifdef CONFIG_SYSCTL
101354 -static struct ctl_table vs_vars_table[] = {
101355 +static ctl_table_no_const vs_vars_table[] __read_only = {
101356 {
101357 .procname = "lblc_expiration",
101358 .data = NULL,
101359 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101360 index 3f21a2f..a112e85 100644
101361 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
101362 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101363 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101364 * IPVS LBLCR sysctl table
101365 */
101366
101367 -static struct ctl_table vs_vars_table[] = {
101368 +static ctl_table_no_const vs_vars_table[] __read_only = {
101369 {
101370 .procname = "lblcr_expiration",
101371 .data = NULL,
101372 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101373 index db80126..ef7110e 100644
101374 --- a/net/netfilter/ipvs/ip_vs_sync.c
101375 +++ b/net/netfilter/ipvs/ip_vs_sync.c
101376 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101377 cp = cp->control;
101378 if (cp) {
101379 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101380 - pkts = atomic_add_return(1, &cp->in_pkts);
101381 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101382 else
101383 pkts = sysctl_sync_threshold(ipvs);
101384 ip_vs_sync_conn(net, cp->control, pkts);
101385 @@ -771,7 +771,7 @@ control:
101386 if (!cp)
101387 return;
101388 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101389 - pkts = atomic_add_return(1, &cp->in_pkts);
101390 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101391 else
101392 pkts = sysctl_sync_threshold(ipvs);
101393 goto sloop;
101394 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101395
101396 if (opt)
101397 memcpy(&cp->in_seq, opt, sizeof(*opt));
101398 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101399 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101400 cp->state = state;
101401 cp->old_state = cp->state;
101402 /*
101403 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101404 index c47444e..b0961c6 100644
101405 --- a/net/netfilter/ipvs/ip_vs_xmit.c
101406 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
101407 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101408 else
101409 rc = NF_ACCEPT;
101410 /* do not touch skb anymore */
101411 - atomic_inc(&cp->in_pkts);
101412 + atomic_inc_unchecked(&cp->in_pkts);
101413 goto out;
101414 }
101415
101416 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101417 else
101418 rc = NF_ACCEPT;
101419 /* do not touch skb anymore */
101420 - atomic_inc(&cp->in_pkts);
101421 + atomic_inc_unchecked(&cp->in_pkts);
101422 goto out;
101423 }
101424
101425 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101426 index a4b5e2a..13b1de3 100644
101427 --- a/net/netfilter/nf_conntrack_acct.c
101428 +++ b/net/netfilter/nf_conntrack_acct.c
101429 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101430 #ifdef CONFIG_SYSCTL
101431 static int nf_conntrack_acct_init_sysctl(struct net *net)
101432 {
101433 - struct ctl_table *table;
101434 + ctl_table_no_const *table;
101435
101436 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101437 GFP_KERNEL);
101438 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101439 index 356bef5..99932cb 100644
101440 --- a/net/netfilter/nf_conntrack_core.c
101441 +++ b/net/netfilter/nf_conntrack_core.c
101442 @@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
101443 #define DYING_NULLS_VAL ((1<<30)+1)
101444 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101445
101446 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101447 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101448 +#endif
101449 +
101450 int nf_conntrack_init_net(struct net *net)
101451 {
101452 int ret;
101453 @@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
101454 goto err_stat;
101455 }
101456
101457 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101458 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
101459 +#else
101460 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101461 +#endif
101462 if (!net->ct.slabname) {
101463 ret = -ENOMEM;
101464 goto err_slabname;
101465 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101466 index 1df1761..ce8b88a 100644
101467 --- a/net/netfilter/nf_conntrack_ecache.c
101468 +++ b/net/netfilter/nf_conntrack_ecache.c
101469 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101470 #ifdef CONFIG_SYSCTL
101471 static int nf_conntrack_event_init_sysctl(struct net *net)
101472 {
101473 - struct ctl_table *table;
101474 + ctl_table_no_const *table;
101475
101476 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101477 GFP_KERNEL);
101478 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101479 index 974a2a4..52cc6ff 100644
101480 --- a/net/netfilter/nf_conntrack_helper.c
101481 +++ b/net/netfilter/nf_conntrack_helper.c
101482 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101483
101484 static int nf_conntrack_helper_init_sysctl(struct net *net)
101485 {
101486 - struct ctl_table *table;
101487 + ctl_table_no_const *table;
101488
101489 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101490 GFP_KERNEL);
101491 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101492 index b65d586..beec902 100644
101493 --- a/net/netfilter/nf_conntrack_proto.c
101494 +++ b/net/netfilter/nf_conntrack_proto.c
101495 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101496
101497 static void
101498 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101499 - struct ctl_table **table,
101500 + ctl_table_no_const **table,
101501 unsigned int users)
101502 {
101503 if (users > 0)
101504 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101505 index f641751..d3c5b51 100644
101506 --- a/net/netfilter/nf_conntrack_standalone.c
101507 +++ b/net/netfilter/nf_conntrack_standalone.c
101508 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101509
101510 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101511 {
101512 - struct ctl_table *table;
101513 + ctl_table_no_const *table;
101514
101515 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101516 GFP_KERNEL);
101517 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101518 index 7a394df..bd91a8a 100644
101519 --- a/net/netfilter/nf_conntrack_timestamp.c
101520 +++ b/net/netfilter/nf_conntrack_timestamp.c
101521 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101522 #ifdef CONFIG_SYSCTL
101523 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101524 {
101525 - struct ctl_table *table;
101526 + ctl_table_no_const *table;
101527
101528 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101529 GFP_KERNEL);
101530 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101531 index 85296d4..8becdec 100644
101532 --- a/net/netfilter/nf_log.c
101533 +++ b/net/netfilter/nf_log.c
101534 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101535
101536 #ifdef CONFIG_SYSCTL
101537 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101538 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101539 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101540
101541 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101542 void __user *buffer, size_t *lenp, loff_t *ppos)
101543 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101544 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101545 mutex_unlock(&nf_log_mutex);
101546 } else {
101547 + ctl_table_no_const nf_log_table = *table;
101548 +
101549 mutex_lock(&nf_log_mutex);
101550 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101551 lockdep_is_held(&nf_log_mutex));
101552 if (!logger)
101553 - table->data = "NONE";
101554 + nf_log_table.data = "NONE";
101555 else
101556 - table->data = logger->name;
101557 - r = proc_dostring(table, write, buffer, lenp, ppos);
101558 + nf_log_table.data = logger->name;
101559 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101560 mutex_unlock(&nf_log_mutex);
101561 }
101562
101563 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101564 index f042ae5..30ea486 100644
101565 --- a/net/netfilter/nf_sockopt.c
101566 +++ b/net/netfilter/nf_sockopt.c
101567 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101568 }
101569 }
101570
101571 - list_add(&reg->list, &nf_sockopts);
101572 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101573 out:
101574 mutex_unlock(&nf_sockopt_mutex);
101575 return ret;
101576 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101577 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101578 {
101579 mutex_lock(&nf_sockopt_mutex);
101580 - list_del(&reg->list);
101581 + pax_list_del((struct list_head *)&reg->list);
101582 mutex_unlock(&nf_sockopt_mutex);
101583 }
101584 EXPORT_SYMBOL(nf_unregister_sockopt);
101585 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
101586 index adce01e..8d52d50 100644
101587 --- a/net/netfilter/nf_tables_api.c
101588 +++ b/net/netfilter/nf_tables_api.c
101589 @@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
101590 #ifdef CONFIG_MODULES
101591 if (autoload) {
101592 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
101593 - request_module("nft-chain-%u-%*.s", afi->family,
101594 - nla_len(nla)-1, (const char *)nla_data(nla));
101595 + request_module("nft-chain-%u-%.*s", afi->family,
101596 + nla_len(nla), (const char *)nla_data(nla));
101597 nfnl_lock(NFNL_SUBSYS_NFTABLES);
101598 type = __nf_tables_chain_type_lookup(afi->family, nla);
101599 if (type != NULL)
101600 @@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
101601
101602 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
101603 [NFTA_SET_TABLE] = { .type = NLA_STRING },
101604 - [NFTA_SET_NAME] = { .type = NLA_STRING },
101605 + [NFTA_SET_NAME] = { .type = NLA_STRING,
101606 + .len = IFNAMSIZ - 1 },
101607 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
101608 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
101609 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
101610 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101611 index a155d19..726b0f2 100644
101612 --- a/net/netfilter/nfnetlink_log.c
101613 +++ b/net/netfilter/nfnetlink_log.c
101614 @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
101615 struct nfnl_log_net {
101616 spinlock_t instances_lock;
101617 struct hlist_head instance_table[INSTANCE_BUCKETS];
101618 - atomic_t global_seq;
101619 + atomic_unchecked_t global_seq;
101620 };
101621
101622 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101623 @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
101624 /* global sequence number */
101625 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101626 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101627 - htonl(atomic_inc_return(&log->global_seq))))
101628 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
101629 goto nla_put_failure;
101630
101631 if (data_len) {
101632 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101633 index 82cb823..5685dd5 100644
101634 --- a/net/netfilter/nft_compat.c
101635 +++ b/net/netfilter/nft_compat.c
101636 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101637 /* We want to reuse existing compat_to_user */
101638 old_fs = get_fs();
101639 set_fs(KERNEL_DS);
101640 - t->compat_to_user(out, in);
101641 + t->compat_to_user((void __force_user *)out, in);
101642 set_fs(old_fs);
101643 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101644 kfree(out);
101645 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101646 /* We want to reuse existing compat_to_user */
101647 old_fs = get_fs();
101648 set_fs(KERNEL_DS);
101649 - m->compat_to_user(out, in);
101650 + m->compat_to_user((void __force_user *)out, in);
101651 set_fs(old_fs);
101652 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101653 kfree(out);
101654 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101655 new file mode 100644
101656 index 0000000..c566332
101657 --- /dev/null
101658 +++ b/net/netfilter/xt_gradm.c
101659 @@ -0,0 +1,51 @@
101660 +/*
101661 + * gradm match for netfilter
101662 + * Copyright © Zbigniew Krzystolik, 2010
101663 + *
101664 + * This program is free software; you can redistribute it and/or modify
101665 + * it under the terms of the GNU General Public License; either version
101666 + * 2 or 3 as published by the Free Software Foundation.
101667 + */
101668 +#include <linux/module.h>
101669 +#include <linux/moduleparam.h>
101670 +#include <linux/skbuff.h>
101671 +#include <linux/netfilter/x_tables.h>
101672 +#include <linux/grsecurity.h>
101673 +#include <linux/netfilter/xt_gradm.h>
101674 +
101675 +static bool
101676 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
101677 +{
101678 + const struct xt_gradm_mtinfo *info = par->matchinfo;
101679 + bool retval = false;
101680 + if (gr_acl_is_enabled())
101681 + retval = true;
101682 + return retval ^ info->invflags;
101683 +}
101684 +
101685 +static struct xt_match gradm_mt_reg __read_mostly = {
101686 + .name = "gradm",
101687 + .revision = 0,
101688 + .family = NFPROTO_UNSPEC,
101689 + .match = gradm_mt,
101690 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
101691 + .me = THIS_MODULE,
101692 +};
101693 +
101694 +static int __init gradm_mt_init(void)
101695 +{
101696 + return xt_register_match(&gradm_mt_reg);
101697 +}
101698 +
101699 +static void __exit gradm_mt_exit(void)
101700 +{
101701 + xt_unregister_match(&gradm_mt_reg);
101702 +}
101703 +
101704 +module_init(gradm_mt_init);
101705 +module_exit(gradm_mt_exit);
101706 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
101707 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
101708 +MODULE_LICENSE("GPL");
101709 +MODULE_ALIAS("ipt_gradm");
101710 +MODULE_ALIAS("ip6t_gradm");
101711 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
101712 index a3910fc..2d2ba14 100644
101713 --- a/net/netfilter/xt_hashlimit.c
101714 +++ b/net/netfilter/xt_hashlimit.c
101715 @@ -870,11 +870,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
101716 {
101717 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
101718
101719 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
101720 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
101721 if (!hashlimit_net->ipt_hashlimit)
101722 return -ENOMEM;
101723 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
101724 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
101725 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
101726 if (!hashlimit_net->ip6t_hashlimit) {
101727 remove_proc_entry("ipt_hashlimit", net->proc_net);
101728 return -ENOMEM;
101729 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
101730 index 1e657cf..1eb1c34 100644
101731 --- a/net/netfilter/xt_recent.c
101732 +++ b/net/netfilter/xt_recent.c
101733 @@ -618,7 +618,7 @@ static int __net_init recent_proc_net_init(struct net *net)
101734 {
101735 struct recent_net *recent_net = recent_pernet(net);
101736
101737 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
101738 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
101739 if (!recent_net->xt_recent)
101740 return -ENOMEM;
101741 return 0;
101742 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
101743 index 11de55e..f25e448 100644
101744 --- a/net/netfilter/xt_statistic.c
101745 +++ b/net/netfilter/xt_statistic.c
101746 @@ -19,7 +19,7 @@
101747 #include <linux/module.h>
101748
101749 struct xt_statistic_priv {
101750 - atomic_t count;
101751 + atomic_unchecked_t count;
101752 } ____cacheline_aligned_in_smp;
101753
101754 MODULE_LICENSE("GPL");
101755 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
101756 break;
101757 case XT_STATISTIC_MODE_NTH:
101758 do {
101759 - oval = atomic_read(&info->master->count);
101760 + oval = atomic_read_unchecked(&info->master->count);
101761 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
101762 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
101763 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
101764 if (nval == 0)
101765 ret = !ret;
101766 break;
101767 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
101768 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
101769 if (info->master == NULL)
101770 return -ENOMEM;
101771 - atomic_set(&info->master->count, info->u.nth.count);
101772 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
101773
101774 return 0;
101775 }
101776 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
101777 index 04748ab6..ca8f86f 100644
101778 --- a/net/netlink/af_netlink.c
101779 +++ b/net/netlink/af_netlink.c
101780 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
101781 sk->sk_error_report(sk);
101782 }
101783 }
101784 - atomic_inc(&sk->sk_drops);
101785 + atomic_inc_unchecked(&sk->sk_drops);
101786 }
101787
101788 static void netlink_rcv_wake(struct sock *sk)
101789 @@ -2933,7 +2933,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
101790 sk_wmem_alloc_get(s),
101791 nlk->cb_running,
101792 atomic_read(&s->sk_refcnt),
101793 - atomic_read(&s->sk_drops),
101794 + atomic_read_unchecked(&s->sk_drops),
101795 sock_i_ino(s)
101796 );
101797
101798 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
101799 index b74aa07..d41926e 100644
101800 --- a/net/netrom/af_netrom.c
101801 +++ b/net/netrom/af_netrom.c
101802 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
101803 *uaddr_len = sizeof(struct full_sockaddr_ax25);
101804 } else {
101805 sax->fsa_ax25.sax25_family = AF_NETROM;
101806 - sax->fsa_ax25.sax25_ndigis = 0;
101807 sax->fsa_ax25.sax25_call = nr->source_addr;
101808 *uaddr_len = sizeof(struct sockaddr_ax25);
101809 }
101810 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
101811 index 48a6a93..0b0496e 100644
101812 --- a/net/packet/af_packet.c
101813 +++ b/net/packet/af_packet.c
101814 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
101815
101816 spin_lock(&sk->sk_receive_queue.lock);
101817 po->stats.stats1.tp_packets++;
101818 - skb->dropcount = atomic_read(&sk->sk_drops);
101819 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
101820 __skb_queue_tail(&sk->sk_receive_queue, skb);
101821 spin_unlock(&sk->sk_receive_queue.lock);
101822 sk->sk_data_ready(sk, skb->len);
101823 @@ -1854,7 +1854,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
101824 drop_n_acct:
101825 spin_lock(&sk->sk_receive_queue.lock);
101826 po->stats.stats1.tp_drops++;
101827 - atomic_inc(&sk->sk_drops);
101828 + atomic_inc_unchecked(&sk->sk_drops);
101829 spin_unlock(&sk->sk_receive_queue.lock);
101830
101831 drop_n_restore:
101832 @@ -3449,7 +3449,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
101833 case PACKET_HDRLEN:
101834 if (len > sizeof(int))
101835 len = sizeof(int);
101836 - if (copy_from_user(&val, optval, len))
101837 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
101838 return -EFAULT;
101839 switch (val) {
101840 case TPACKET_V1:
101841 @@ -3495,7 +3495,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
101842 len = lv;
101843 if (put_user(len, optlen))
101844 return -EFAULT;
101845 - if (copy_to_user(optval, data, len))
101846 + if (len > sizeof(st) || copy_to_user(optval, data, len))
101847 return -EFAULT;
101848 return 0;
101849 }
101850 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
101851 index e774117..900b8b7 100644
101852 --- a/net/phonet/pep.c
101853 +++ b/net/phonet/pep.c
101854 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
101855
101856 case PNS_PEP_CTRL_REQ:
101857 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
101858 - atomic_inc(&sk->sk_drops);
101859 + atomic_inc_unchecked(&sk->sk_drops);
101860 break;
101861 }
101862 __skb_pull(skb, 4);
101863 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
101864 }
101865
101866 if (pn->rx_credits == 0) {
101867 - atomic_inc(&sk->sk_drops);
101868 + atomic_inc_unchecked(&sk->sk_drops);
101869 err = -ENOBUFS;
101870 break;
101871 }
101872 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
101873 }
101874
101875 if (pn->rx_credits == 0) {
101876 - atomic_inc(&sk->sk_drops);
101877 + atomic_inc_unchecked(&sk->sk_drops);
101878 err = NET_RX_DROP;
101879 break;
101880 }
101881 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
101882 index 008214a..bb68240 100644
101883 --- a/net/phonet/socket.c
101884 +++ b/net/phonet/socket.c
101885 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
101886 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
101887 sock_i_ino(sk),
101888 atomic_read(&sk->sk_refcnt), sk,
101889 - atomic_read(&sk->sk_drops));
101890 + atomic_read_unchecked(&sk->sk_drops));
101891 }
101892 seq_pad(seq, '\n');
101893 return 0;
101894 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
101895 index c02a8c4..3c5b600 100644
101896 --- a/net/phonet/sysctl.c
101897 +++ b/net/phonet/sysctl.c
101898 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
101899 {
101900 int ret;
101901 int range[2] = {local_port_range[0], local_port_range[1]};
101902 - struct ctl_table tmp = {
101903 + ctl_table_no_const tmp = {
101904 .data = &range,
101905 .maxlen = sizeof(range),
101906 .mode = table->mode,
101907 diff --git a/net/rds/cong.c b/net/rds/cong.c
101908 index e5b65ac..f3b6fb7 100644
101909 --- a/net/rds/cong.c
101910 +++ b/net/rds/cong.c
101911 @@ -78,7 +78,7 @@
101912 * finds that the saved generation number is smaller than the global generation
101913 * number, it wakes up the process.
101914 */
101915 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
101916 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
101917
101918 /*
101919 * Congestion monitoring
101920 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
101921 rdsdebug("waking map %p for %pI4\n",
101922 map, &map->m_addr);
101923 rds_stats_inc(s_cong_update_received);
101924 - atomic_inc(&rds_cong_generation);
101925 + atomic_inc_unchecked(&rds_cong_generation);
101926 if (waitqueue_active(&map->m_waitq))
101927 wake_up(&map->m_waitq);
101928 if (waitqueue_active(&rds_poll_waitq))
101929 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
101930
101931 int rds_cong_updated_since(unsigned long *recent)
101932 {
101933 - unsigned long gen = atomic_read(&rds_cong_generation);
101934 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
101935
101936 if (likely(*recent == gen))
101937 return 0;
101938 diff --git a/net/rds/ib.h b/net/rds/ib.h
101939 index 7280ab8..e04f4ea 100644
101940 --- a/net/rds/ib.h
101941 +++ b/net/rds/ib.h
101942 @@ -128,7 +128,7 @@ struct rds_ib_connection {
101943 /* sending acks */
101944 unsigned long i_ack_flags;
101945 #ifdef KERNEL_HAS_ATOMIC64
101946 - atomic64_t i_ack_next; /* next ACK to send */
101947 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
101948 #else
101949 spinlock_t i_ack_lock; /* protect i_ack_next */
101950 u64 i_ack_next; /* next ACK to send */
101951 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
101952 index 31b74f5..dc1fbfa 100644
101953 --- a/net/rds/ib_cm.c
101954 +++ b/net/rds/ib_cm.c
101955 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
101956 /* Clear the ACK state */
101957 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
101958 #ifdef KERNEL_HAS_ATOMIC64
101959 - atomic64_set(&ic->i_ack_next, 0);
101960 + atomic64_set_unchecked(&ic->i_ack_next, 0);
101961 #else
101962 ic->i_ack_next = 0;
101963 #endif
101964 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
101965 index b7ebe23..b6352f6 100644
101966 --- a/net/rds/ib_recv.c
101967 +++ b/net/rds/ib_recv.c
101968 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
101969 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
101970 int ack_required)
101971 {
101972 - atomic64_set(&ic->i_ack_next, seq);
101973 + atomic64_set_unchecked(&ic->i_ack_next, seq);
101974 if (ack_required) {
101975 smp_mb__before_clear_bit();
101976 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
101977 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
101978 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
101979 smp_mb__after_clear_bit();
101980
101981 - return atomic64_read(&ic->i_ack_next);
101982 + return atomic64_read_unchecked(&ic->i_ack_next);
101983 }
101984 #endif
101985
101986 diff --git a/net/rds/iw.h b/net/rds/iw.h
101987 index 04ce3b1..48119a6 100644
101988 --- a/net/rds/iw.h
101989 +++ b/net/rds/iw.h
101990 @@ -134,7 +134,7 @@ struct rds_iw_connection {
101991 /* sending acks */
101992 unsigned long i_ack_flags;
101993 #ifdef KERNEL_HAS_ATOMIC64
101994 - atomic64_t i_ack_next; /* next ACK to send */
101995 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
101996 #else
101997 spinlock_t i_ack_lock; /* protect i_ack_next */
101998 u64 i_ack_next; /* next ACK to send */
101999 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
102000 index a91e1db..cf3053f 100644
102001 --- a/net/rds/iw_cm.c
102002 +++ b/net/rds/iw_cm.c
102003 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
102004 /* Clear the ACK state */
102005 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
102006 #ifdef KERNEL_HAS_ATOMIC64
102007 - atomic64_set(&ic->i_ack_next, 0);
102008 + atomic64_set_unchecked(&ic->i_ack_next, 0);
102009 #else
102010 ic->i_ack_next = 0;
102011 #endif
102012 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
102013 index 4503335..db566b4 100644
102014 --- a/net/rds/iw_recv.c
102015 +++ b/net/rds/iw_recv.c
102016 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102017 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
102018 int ack_required)
102019 {
102020 - atomic64_set(&ic->i_ack_next, seq);
102021 + atomic64_set_unchecked(&ic->i_ack_next, seq);
102022 if (ack_required) {
102023 smp_mb__before_clear_bit();
102024 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102025 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102026 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102027 smp_mb__after_clear_bit();
102028
102029 - return atomic64_read(&ic->i_ack_next);
102030 + return atomic64_read_unchecked(&ic->i_ack_next);
102031 }
102032 #endif
102033
102034 diff --git a/net/rds/rds.h b/net/rds/rds.h
102035 index 48f8ffc..0ef3eec 100644
102036 --- a/net/rds/rds.h
102037 +++ b/net/rds/rds.h
102038 @@ -449,7 +449,7 @@ struct rds_transport {
102039 void (*sync_mr)(void *trans_private, int direction);
102040 void (*free_mr)(void *trans_private, int invalidate);
102041 void (*flush_mrs)(void);
102042 -};
102043 +} __do_const;
102044
102045 struct rds_sock {
102046 struct sock rs_sk;
102047 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
102048 index edac9ef..16bcb98 100644
102049 --- a/net/rds/tcp.c
102050 +++ b/net/rds/tcp.c
102051 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
102052 int val = 1;
102053
102054 set_fs(KERNEL_DS);
102055 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
102056 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
102057 sizeof(val));
102058 set_fs(oldfs);
102059 }
102060 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
102061 index 81cf5a4..b5826ff 100644
102062 --- a/net/rds/tcp_send.c
102063 +++ b/net/rds/tcp_send.c
102064 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
102065
102066 oldfs = get_fs();
102067 set_fs(KERNEL_DS);
102068 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
102069 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
102070 sizeof(val));
102071 set_fs(oldfs);
102072 }
102073 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
102074 index e61aa60..f07cc89 100644
102075 --- a/net/rxrpc/af_rxrpc.c
102076 +++ b/net/rxrpc/af_rxrpc.c
102077 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
102078 __be32 rxrpc_epoch;
102079
102080 /* current debugging ID */
102081 -atomic_t rxrpc_debug_id;
102082 +atomic_unchecked_t rxrpc_debug_id;
102083
102084 /* count of skbs currently in use */
102085 atomic_t rxrpc_n_skbs;
102086 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
102087 index cd97a0c..0041649 100644
102088 --- a/net/rxrpc/ar-ack.c
102089 +++ b/net/rxrpc/ar-ack.c
102090 @@ -182,7 +182,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102091
102092 _enter("{%d,%d,%d,%d},",
102093 call->acks_hard, call->acks_unacked,
102094 - atomic_read(&call->sequence),
102095 + atomic_read_unchecked(&call->sequence),
102096 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
102097
102098 stop = 0;
102099 @@ -206,7 +206,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102100
102101 /* each Tx packet has a new serial number */
102102 sp->hdr.serial =
102103 - htonl(atomic_inc_return(&call->conn->serial));
102104 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
102105
102106 hdr = (struct rxrpc_header *) txb->head;
102107 hdr->serial = sp->hdr.serial;
102108 @@ -410,7 +410,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
102109 */
102110 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
102111 {
102112 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
102113 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
102114 }
102115
102116 /*
102117 @@ -636,7 +636,7 @@ process_further:
102118
102119 latest = ntohl(sp->hdr.serial);
102120 hard = ntohl(ack.firstPacket);
102121 - tx = atomic_read(&call->sequence);
102122 + tx = atomic_read_unchecked(&call->sequence);
102123
102124 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
102125 latest,
102126 @@ -1168,7 +1168,7 @@ void rxrpc_process_call(struct work_struct *work)
102127 goto maybe_reschedule;
102128
102129 send_ACK_with_skew:
102130 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
102131 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
102132 ntohl(ack.serial));
102133 send_ACK:
102134 mtu = call->conn->trans->peer->if_mtu;
102135 @@ -1180,7 +1180,7 @@ send_ACK:
102136 ackinfo.rxMTU = htonl(5692);
102137 ackinfo.jumbo_max = htonl(4);
102138
102139 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
102140 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
102141 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
102142 ntohl(hdr.serial),
102143 ntohs(ack.maxSkew),
102144 @@ -1198,7 +1198,7 @@ send_ACK:
102145 send_message:
102146 _debug("send message");
102147
102148 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
102149 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
102150 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
102151 send_message_2:
102152
102153 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
102154 index a3bbb36..3341fb9 100644
102155 --- a/net/rxrpc/ar-call.c
102156 +++ b/net/rxrpc/ar-call.c
102157 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
102158 spin_lock_init(&call->lock);
102159 rwlock_init(&call->state_lock);
102160 atomic_set(&call->usage, 1);
102161 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
102162 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102163 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
102164
102165 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
102166 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
102167 index 7bf5b5b..4a3bf2c 100644
102168 --- a/net/rxrpc/ar-connection.c
102169 +++ b/net/rxrpc/ar-connection.c
102170 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
102171 rwlock_init(&conn->lock);
102172 spin_lock_init(&conn->state_lock);
102173 atomic_set(&conn->usage, 1);
102174 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
102175 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102176 conn->avail_calls = RXRPC_MAXCALLS;
102177 conn->size_align = 4;
102178 conn->header_size = sizeof(struct rxrpc_header);
102179 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
102180 index e7ed43a..6afa140 100644
102181 --- a/net/rxrpc/ar-connevent.c
102182 +++ b/net/rxrpc/ar-connevent.c
102183 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
102184
102185 len = iov[0].iov_len + iov[1].iov_len;
102186
102187 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
102188 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102189 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
102190
102191 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
102192 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
102193 index 529572f..c758ca7 100644
102194 --- a/net/rxrpc/ar-input.c
102195 +++ b/net/rxrpc/ar-input.c
102196 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
102197 /* track the latest serial number on this connection for ACK packet
102198 * information */
102199 serial = ntohl(sp->hdr.serial);
102200 - hi_serial = atomic_read(&call->conn->hi_serial);
102201 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
102202 while (serial > hi_serial)
102203 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
102204 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
102205 serial);
102206
102207 /* request ACK generation for any ACK or DATA packet that requests
102208 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
102209 index 5f43675..ca07817 100644
102210 --- a/net/rxrpc/ar-internal.h
102211 +++ b/net/rxrpc/ar-internal.h
102212 @@ -272,8 +272,8 @@ struct rxrpc_connection {
102213 int error; /* error code for local abort */
102214 int debug_id; /* debug ID for printks */
102215 unsigned int call_counter; /* call ID counter */
102216 - atomic_t serial; /* packet serial number counter */
102217 - atomic_t hi_serial; /* highest serial number received */
102218 + atomic_unchecked_t serial; /* packet serial number counter */
102219 + atomic_unchecked_t hi_serial; /* highest serial number received */
102220 u8 avail_calls; /* number of calls available */
102221 u8 size_align; /* data size alignment (for security) */
102222 u8 header_size; /* rxrpc + security header size */
102223 @@ -346,7 +346,7 @@ struct rxrpc_call {
102224 spinlock_t lock;
102225 rwlock_t state_lock; /* lock for state transition */
102226 atomic_t usage;
102227 - atomic_t sequence; /* Tx data packet sequence counter */
102228 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
102229 u32 abort_code; /* local/remote abort code */
102230 enum { /* current state of call */
102231 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
102232 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
102233 */
102234 extern atomic_t rxrpc_n_skbs;
102235 extern __be32 rxrpc_epoch;
102236 -extern atomic_t rxrpc_debug_id;
102237 +extern atomic_unchecked_t rxrpc_debug_id;
102238 extern struct workqueue_struct *rxrpc_workqueue;
102239
102240 /*
102241 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
102242 index 87f7135..74d3703 100644
102243 --- a/net/rxrpc/ar-local.c
102244 +++ b/net/rxrpc/ar-local.c
102245 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
102246 spin_lock_init(&local->lock);
102247 rwlock_init(&local->services_lock);
102248 atomic_set(&local->usage, 1);
102249 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
102250 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102251 memcpy(&local->srx, srx, sizeof(*srx));
102252 }
102253
102254 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
102255 index d0e8f1c..a3a1686 100644
102256 --- a/net/rxrpc/ar-output.c
102257 +++ b/net/rxrpc/ar-output.c
102258 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
102259 sp->hdr.cid = call->cid;
102260 sp->hdr.callNumber = call->call_id;
102261 sp->hdr.seq =
102262 - htonl(atomic_inc_return(&call->sequence));
102263 + htonl(atomic_inc_return_unchecked(&call->sequence));
102264 sp->hdr.serial =
102265 - htonl(atomic_inc_return(&conn->serial));
102266 + htonl(atomic_inc_return_unchecked(&conn->serial));
102267 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
102268 sp->hdr.userStatus = 0;
102269 sp->hdr.securityIndex = conn->security_ix;
102270 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
102271 index bebaa43..2644591 100644
102272 --- a/net/rxrpc/ar-peer.c
102273 +++ b/net/rxrpc/ar-peer.c
102274 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
102275 INIT_LIST_HEAD(&peer->error_targets);
102276 spin_lock_init(&peer->lock);
102277 atomic_set(&peer->usage, 1);
102278 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
102279 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102280 memcpy(&peer->srx, srx, sizeof(*srx));
102281
102282 rxrpc_assess_MTU_size(peer);
102283 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
102284 index 38047f7..9f48511 100644
102285 --- a/net/rxrpc/ar-proc.c
102286 +++ b/net/rxrpc/ar-proc.c
102287 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
102288 atomic_read(&conn->usage),
102289 rxrpc_conn_states[conn->state],
102290 key_serial(conn->key),
102291 - atomic_read(&conn->serial),
102292 - atomic_read(&conn->hi_serial));
102293 + atomic_read_unchecked(&conn->serial),
102294 + atomic_read_unchecked(&conn->hi_serial));
102295
102296 return 0;
102297 }
102298 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
102299 index 92df566..87ec1bf 100644
102300 --- a/net/rxrpc/ar-transport.c
102301 +++ b/net/rxrpc/ar-transport.c
102302 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
102303 spin_lock_init(&trans->client_lock);
102304 rwlock_init(&trans->conn_lock);
102305 atomic_set(&trans->usage, 1);
102306 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
102307 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102308
102309 if (peer->srx.transport.family == AF_INET) {
102310 switch (peer->srx.transport_type) {
102311 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
102312 index f226709..0e735a8 100644
102313 --- a/net/rxrpc/rxkad.c
102314 +++ b/net/rxrpc/rxkad.c
102315 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
102316
102317 len = iov[0].iov_len + iov[1].iov_len;
102318
102319 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
102320 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102321 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
102322
102323 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
102324 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
102325
102326 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
102327
102328 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
102329 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102330 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
102331
102332 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
102333 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
102334 index 2b1738e..a9d0fc9 100644
102335 --- a/net/sctp/ipv6.c
102336 +++ b/net/sctp/ipv6.c
102337 @@ -966,7 +966,7 @@ static const struct inet6_protocol sctpv6_protocol = {
102338 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
102339 };
102340
102341 -static struct sctp_af sctp_af_inet6 = {
102342 +static struct sctp_af sctp_af_inet6 __read_only = {
102343 .sa_family = AF_INET6,
102344 .sctp_xmit = sctp_v6_xmit,
102345 .setsockopt = ipv6_setsockopt,
102346 @@ -998,7 +998,7 @@ static struct sctp_af sctp_af_inet6 = {
102347 #endif
102348 };
102349
102350 -static struct sctp_pf sctp_pf_inet6 = {
102351 +static struct sctp_pf sctp_pf_inet6 __read_only = {
102352 .event_msgname = sctp_inet6_event_msgname,
102353 .skb_msgname = sctp_inet6_skb_msgname,
102354 .af_supported = sctp_inet6_af_supported,
102355 @@ -1023,7 +1023,7 @@ void sctp_v6_pf_init(void)
102356
102357 void sctp_v6_pf_exit(void)
102358 {
102359 - list_del(&sctp_af_inet6.list);
102360 + pax_list_del(&sctp_af_inet6.list);
102361 }
102362
102363 /* Initialize IPv6 support and register with socket layer. */
102364 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
102365 index 4e1d0fc..068fef7 100644
102366 --- a/net/sctp/protocol.c
102367 +++ b/net/sctp/protocol.c
102368 @@ -831,8 +831,10 @@ int sctp_register_af(struct sctp_af *af)
102369 return 0;
102370 }
102371
102372 + pax_open_kernel();
102373 INIT_LIST_HEAD(&af->list);
102374 - list_add_tail(&af->list, &sctp_address_families);
102375 + pax_close_kernel();
102376 + pax_list_add_tail(&af->list, &sctp_address_families);
102377 return 1;
102378 }
102379
102380 @@ -962,7 +964,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
102381
102382 static struct sctp_af sctp_af_inet;
102383
102384 -static struct sctp_pf sctp_pf_inet = {
102385 +static struct sctp_pf sctp_pf_inet __read_only = {
102386 .event_msgname = sctp_inet_event_msgname,
102387 .skb_msgname = sctp_inet_skb_msgname,
102388 .af_supported = sctp_inet_af_supported,
102389 @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
102390 };
102391
102392 /* IPv4 address related functions. */
102393 -static struct sctp_af sctp_af_inet = {
102394 +static struct sctp_af sctp_af_inet __read_only = {
102395 .sa_family = AF_INET,
102396 .sctp_xmit = sctp_v4_xmit,
102397 .setsockopt = ip_setsockopt,
102398 @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
102399
102400 static void sctp_v4_pf_exit(void)
102401 {
102402 - list_del(&sctp_af_inet.list);
102403 + pax_list_del(&sctp_af_inet.list);
102404 }
102405
102406 static int sctp_v4_protosw_init(void)
102407 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
102408 index 5d6883f..394a102 100644
102409 --- a/net/sctp/sm_sideeffect.c
102410 +++ b/net/sctp/sm_sideeffect.c
102411 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
102412 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
102413 }
102414
102415 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
102416 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
102417 NULL,
102418 sctp_generate_t1_cookie_event,
102419 sctp_generate_t1_init_event,
102420 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
102421 index 981aaf8..5bc016d 100644
102422 --- a/net/sctp/socket.c
102423 +++ b/net/sctp/socket.c
102424 @@ -2169,11 +2169,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
102425 {
102426 struct sctp_association *asoc;
102427 struct sctp_ulpevent *event;
102428 + struct sctp_event_subscribe subscribe;
102429
102430 if (optlen > sizeof(struct sctp_event_subscribe))
102431 return -EINVAL;
102432 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
102433 + if (copy_from_user(&subscribe, optval, optlen))
102434 return -EFAULT;
102435 + sctp_sk(sk)->subscribe = subscribe;
102436
102437 /*
102438 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
102439 @@ -4255,13 +4257,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
102440 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
102441 int __user *optlen)
102442 {
102443 + struct sctp_event_subscribe subscribe;
102444 +
102445 if (len <= 0)
102446 return -EINVAL;
102447 if (len > sizeof(struct sctp_event_subscribe))
102448 len = sizeof(struct sctp_event_subscribe);
102449 if (put_user(len, optlen))
102450 return -EFAULT;
102451 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
102452 + subscribe = sctp_sk(sk)->subscribe;
102453 + if (copy_to_user(optval, &subscribe, len))
102454 return -EFAULT;
102455 return 0;
102456 }
102457 @@ -4279,6 +4284,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
102458 */
102459 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
102460 {
102461 + __u32 autoclose;
102462 +
102463 /* Applicable to UDP-style socket only */
102464 if (sctp_style(sk, TCP))
102465 return -EOPNOTSUPP;
102466 @@ -4287,7 +4294,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
102467 len = sizeof(int);
102468 if (put_user(len, optlen))
102469 return -EFAULT;
102470 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
102471 + autoclose = sctp_sk(sk)->autoclose;
102472 + if (copy_to_user(optval, &autoclose, sizeof(int)))
102473 return -EFAULT;
102474 return 0;
102475 }
102476 @@ -4662,12 +4670,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
102477 */
102478 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
102479 {
102480 + struct sctp_initmsg initmsg;
102481 +
102482 if (len < sizeof(struct sctp_initmsg))
102483 return -EINVAL;
102484 len = sizeof(struct sctp_initmsg);
102485 if (put_user(len, optlen))
102486 return -EFAULT;
102487 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
102488 + initmsg = sctp_sk(sk)->initmsg;
102489 + if (copy_to_user(optval, &initmsg, len))
102490 return -EFAULT;
102491 return 0;
102492 }
102493 @@ -4708,6 +4719,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
102494 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
102495 if (space_left < addrlen)
102496 return -ENOMEM;
102497 + if (addrlen > sizeof(temp) || addrlen < 0)
102498 + return -EFAULT;
102499 if (copy_to_user(to, &temp, addrlen))
102500 return -EFAULT;
102501 to += addrlen;
102502 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
102503 index 35c8923..536614e 100644
102504 --- a/net/sctp/sysctl.c
102505 +++ b/net/sctp/sysctl.c
102506 @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
102507 {
102508 struct net *net = current->nsproxy->net_ns;
102509 char tmp[8];
102510 - struct ctl_table tbl;
102511 + ctl_table_no_const tbl;
102512 int ret;
102513 int changed = 0;
102514 char *none = "none";
102515 @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
102516 {
102517 struct net *net = current->nsproxy->net_ns;
102518 int new_value;
102519 - struct ctl_table tbl;
102520 + ctl_table_no_const tbl;
102521 unsigned int min = *(unsigned int *) ctl->extra1;
102522 unsigned int max = *(unsigned int *) ctl->extra2;
102523 int ret;
102524 @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
102525 {
102526 struct net *net = current->nsproxy->net_ns;
102527 int new_value;
102528 - struct ctl_table tbl;
102529 + ctl_table_no_const tbl;
102530 unsigned int min = *(unsigned int *) ctl->extra1;
102531 unsigned int max = *(unsigned int *) ctl->extra2;
102532 int ret;
102533 @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
102534
102535 int sctp_sysctl_net_register(struct net *net)
102536 {
102537 - struct ctl_table *table = sctp_net_table;
102538 + ctl_table_no_const *table = NULL;
102539
102540 if (!net_eq(net, &init_net)) {
102541 int i;
102542 @@ -415,7 +415,10 @@ int sctp_sysctl_net_register(struct net *net)
102543 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
102544 }
102545
102546 - net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
102547 + if (!net_eq(net, &init_net))
102548 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
102549 + else
102550 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", sctp_net_table);
102551 return 0;
102552 }
102553
102554 diff --git a/net/socket.c b/net/socket.c
102555 index a19ae19..89554dc 100644
102556 --- a/net/socket.c
102557 +++ b/net/socket.c
102558 @@ -88,6 +88,7 @@
102559 #include <linux/magic.h>
102560 #include <linux/slab.h>
102561 #include <linux/xattr.h>
102562 +#include <linux/in.h>
102563
102564 #include <asm/uaccess.h>
102565 #include <asm/unistd.h>
102566 @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
102567 unsigned int sysctl_net_busy_poll __read_mostly;
102568 #endif
102569
102570 +#include <linux/grsock.h>
102571 +
102572 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
102573 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
102574 unsigned long nr_segs, loff_t pos);
102575 @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
102576 */
102577
102578 static DEFINE_SPINLOCK(net_family_lock);
102579 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
102580 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
102581
102582 /*
102583 * Statistics counters of the socket lists
102584 @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
102585 &sockfs_dentry_operations, SOCKFS_MAGIC);
102586 }
102587
102588 -static struct vfsmount *sock_mnt __read_mostly;
102589 +struct vfsmount *sock_mnt __read_mostly;
102590
102591 static struct file_system_type sock_fs_type = {
102592 .name = "sockfs",
102593 @@ -1256,6 +1259,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
102594 return -EAFNOSUPPORT;
102595 if (type < 0 || type >= SOCK_MAX)
102596 return -EINVAL;
102597 + if (protocol < 0)
102598 + return -EINVAL;
102599
102600 /* Compatibility.
102601
102602 @@ -1276,6 +1281,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
102603 if (err)
102604 return err;
102605
102606 + if(!kern && !gr_search_socket(family, type, protocol)) {
102607 + if (rcu_access_pointer(net_families[family]) == NULL)
102608 + return -EAFNOSUPPORT;
102609 + else
102610 + return -EACCES;
102611 + }
102612 +
102613 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
102614 + if (rcu_access_pointer(net_families[family]) == NULL)
102615 + return -EAFNOSUPPORT;
102616 + else
102617 + return -EACCES;
102618 + }
102619 +
102620 /*
102621 * Allocate the socket and allow the family to set things up. if
102622 * the protocol is 0, the family is instructed to select an appropriate
102623 @@ -1527,6 +1546,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
102624 if (sock) {
102625 err = move_addr_to_kernel(umyaddr, addrlen, &address);
102626 if (err >= 0) {
102627 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
102628 + err = -EACCES;
102629 + goto error;
102630 + }
102631 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
102632 + if (err)
102633 + goto error;
102634 +
102635 err = security_socket_bind(sock,
102636 (struct sockaddr *)&address,
102637 addrlen);
102638 @@ -1535,6 +1562,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
102639 (struct sockaddr *)
102640 &address, addrlen);
102641 }
102642 +error:
102643 fput_light(sock->file, fput_needed);
102644 }
102645 return err;
102646 @@ -1558,10 +1586,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
102647 if ((unsigned int)backlog > somaxconn)
102648 backlog = somaxconn;
102649
102650 + if (gr_handle_sock_server_other(sock->sk)) {
102651 + err = -EPERM;
102652 + goto error;
102653 + }
102654 +
102655 + err = gr_search_listen(sock);
102656 + if (err)
102657 + goto error;
102658 +
102659 err = security_socket_listen(sock, backlog);
102660 if (!err)
102661 err = sock->ops->listen(sock, backlog);
102662
102663 +error:
102664 fput_light(sock->file, fput_needed);
102665 }
102666 return err;
102667 @@ -1605,6 +1643,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
102668 newsock->type = sock->type;
102669 newsock->ops = sock->ops;
102670
102671 + if (gr_handle_sock_server_other(sock->sk)) {
102672 + err = -EPERM;
102673 + sock_release(newsock);
102674 + goto out_put;
102675 + }
102676 +
102677 + err = gr_search_accept(sock);
102678 + if (err) {
102679 + sock_release(newsock);
102680 + goto out_put;
102681 + }
102682 +
102683 /*
102684 * We don't need try_module_get here, as the listening socket (sock)
102685 * has the protocol module (sock->ops->owner) held.
102686 @@ -1650,6 +1700,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
102687 fd_install(newfd, newfile);
102688 err = newfd;
102689
102690 + gr_attach_curr_ip(newsock->sk);
102691 +
102692 out_put:
102693 fput_light(sock->file, fput_needed);
102694 out:
102695 @@ -1682,6 +1734,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
102696 int, addrlen)
102697 {
102698 struct socket *sock;
102699 + struct sockaddr *sck;
102700 struct sockaddr_storage address;
102701 int err, fput_needed;
102702
102703 @@ -1692,6 +1745,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
102704 if (err < 0)
102705 goto out_put;
102706
102707 + sck = (struct sockaddr *)&address;
102708 +
102709 + if (gr_handle_sock_client(sck)) {
102710 + err = -EACCES;
102711 + goto out_put;
102712 + }
102713 +
102714 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
102715 + if (err)
102716 + goto out_put;
102717 +
102718 err =
102719 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
102720 if (err)
102721 @@ -1773,6 +1837,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
102722 * the protocol.
102723 */
102724
102725 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
102726 +
102727 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
102728 unsigned int, flags, struct sockaddr __user *, addr,
102729 int, addr_len)
102730 @@ -1839,7 +1905,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
102731 struct socket *sock;
102732 struct iovec iov;
102733 struct msghdr msg;
102734 - struct sockaddr_storage address;
102735 + struct sockaddr_storage address = { };
102736 int err, err2;
102737 int fput_needed;
102738
102739 @@ -2065,7 +2131,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
102740 * checking falls down on this.
102741 */
102742 if (copy_from_user(ctl_buf,
102743 - (void __user __force *)msg_sys->msg_control,
102744 + (void __force_user *)msg_sys->msg_control,
102745 ctl_len))
102746 goto out_freectl;
102747 msg_sys->msg_control = ctl_buf;
102748 @@ -2216,7 +2282,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
102749 int err, total_len, len;
102750
102751 /* kernel mode address */
102752 - struct sockaddr_storage addr;
102753 + struct sockaddr_storage addr = { };
102754
102755 /* user mode address pointers */
102756 struct sockaddr __user *uaddr;
102757 @@ -2245,7 +2311,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
102758 /* Save the user-mode address (verify_iovec will change the
102759 * kernel msghdr to use the kernel address space)
102760 */
102761 - uaddr = (__force void __user *)msg_sys->msg_name;
102762 + uaddr = (void __force_user *)msg_sys->msg_name;
102763 uaddr_len = COMPAT_NAMELEN(msg);
102764 if (MSG_CMSG_COMPAT & flags)
102765 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
102766 @@ -2889,7 +2955,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
102767 ifr = compat_alloc_user_space(buf_size);
102768 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
102769
102770 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
102771 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
102772 return -EFAULT;
102773
102774 if (put_user(convert_in ? rxnfc : compat_ptr(data),
102775 @@ -3000,7 +3066,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
102776 old_fs = get_fs();
102777 set_fs(KERNEL_DS);
102778 err = dev_ioctl(net, cmd,
102779 - (struct ifreq __user __force *) &kifr);
102780 + (struct ifreq __force_user *) &kifr);
102781 set_fs(old_fs);
102782
102783 return err;
102784 @@ -3093,7 +3159,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
102785
102786 old_fs = get_fs();
102787 set_fs(KERNEL_DS);
102788 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
102789 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
102790 set_fs(old_fs);
102791
102792 if (cmd == SIOCGIFMAP && !err) {
102793 @@ -3177,7 +3243,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
102794 ret |= get_user(rtdev, &(ur4->rt_dev));
102795 if (rtdev) {
102796 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
102797 - r4.rt_dev = (char __user __force *)devname;
102798 + r4.rt_dev = (char __force_user *)devname;
102799 devname[15] = 0;
102800 } else
102801 r4.rt_dev = NULL;
102802 @@ -3404,8 +3470,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
102803 int __user *uoptlen;
102804 int err;
102805
102806 - uoptval = (char __user __force *) optval;
102807 - uoptlen = (int __user __force *) optlen;
102808 + uoptval = (char __force_user *) optval;
102809 + uoptlen = (int __force_user *) optlen;
102810
102811 set_fs(KERNEL_DS);
102812 if (level == SOL_SOCKET)
102813 @@ -3425,7 +3491,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
102814 char __user *uoptval;
102815 int err;
102816
102817 - uoptval = (char __user __force *) optval;
102818 + uoptval = (char __force_user *) optval;
102819
102820 set_fs(KERNEL_DS);
102821 if (level == SOL_SOCKET)
102822 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
102823 index 0f73f45..a96aa52 100644
102824 --- a/net/sunrpc/auth_gss/svcauth_gss.c
102825 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
102826 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
102827 uint64_t *handle)
102828 {
102829 struct rsc rsci, *rscp = NULL;
102830 - static atomic64_t ctxhctr;
102831 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
102832 long long ctxh;
102833 struct gss_api_mech *gm = NULL;
102834 time_t expiry;
102835 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
102836 status = -ENOMEM;
102837 /* the handle needs to be just a unique id,
102838 * use a static counter */
102839 - ctxh = atomic64_inc_return(&ctxhctr);
102840 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
102841
102842 /* make a copy for the caller */
102843 *handle = ctxh;
102844 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
102845 index ae333c1..18521f0 100644
102846 --- a/net/sunrpc/cache.c
102847 +++ b/net/sunrpc/cache.c
102848 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
102849 struct sunrpc_net *sn;
102850
102851 sn = net_generic(net, sunrpc_net_id);
102852 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
102853 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
102854 if (cd->u.procfs.proc_ent == NULL)
102855 goto out_nomem;
102856 cd->u.procfs.channel_ent = NULL;
102857 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
102858 index 3ea5cda..bfb3e08 100644
102859 --- a/net/sunrpc/clnt.c
102860 +++ b/net/sunrpc/clnt.c
102861 @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
102862 (RPC_IS_ASYNC(task) ? "async" : "sync"));
102863
102864 /* Increment call count */
102865 - task->tk_msg.rpc_proc->p_count++;
102866 + pax_open_kernel();
102867 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
102868 + pax_close_kernel();
102869 clnt->cl_stats->rpccnt++;
102870 task->tk_action = call_reserve;
102871 }
102872 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
102873 index ff3cc4b..7612a9e 100644
102874 --- a/net/sunrpc/sched.c
102875 +++ b/net/sunrpc/sched.c
102876 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
102877 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
102878 static void rpc_task_set_debuginfo(struct rpc_task *task)
102879 {
102880 - static atomic_t rpc_pid;
102881 + static atomic_unchecked_t rpc_pid;
102882
102883 - task->tk_pid = atomic_inc_return(&rpc_pid);
102884 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
102885 }
102886 #else
102887 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
102888 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
102889 index 5453049..465669a 100644
102890 --- a/net/sunrpc/stats.c
102891 +++ b/net/sunrpc/stats.c
102892 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
102893
102894 dprintk("RPC: registering /proc/net/rpc\n");
102895 sn = net_generic(net, sunrpc_net_id);
102896 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
102897 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
102898 if (sn->proc_net_rpc == NULL)
102899 return -ENOMEM;
102900
102901 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
102902 index 5de6801..b4e330d 100644
102903 --- a/net/sunrpc/svc.c
102904 +++ b/net/sunrpc/svc.c
102905 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
102906 svc_putnl(resv, RPC_SUCCESS);
102907
102908 /* Bump per-procedure stats counter */
102909 - procp->pc_count++;
102910 + pax_open_kernel();
102911 + (*(unsigned int *)&procp->pc_count)++;
102912 + pax_close_kernel();
102913
102914 /* Initialize storage for argp and resp */
102915 memset(rqstp->rq_argp, 0, procp->pc_argsize);
102916 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
102917 index 621ca7b..59421dd 100644
102918 --- a/net/sunrpc/svcauth_unix.c
102919 +++ b/net/sunrpc/svcauth_unix.c
102920 @@ -414,7 +414,7 @@ struct unix_gid {
102921 struct group_info *gi;
102922 };
102923
102924 -static int unix_gid_hash(kuid_t uid)
102925 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
102926 {
102927 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
102928 }
102929 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
102930 (*bpp)[-1] = '\n';
102931 }
102932
102933 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
102934 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
102935
102936 static int unix_gid_parse(struct cache_detail *cd,
102937 char *mesg, int mlen)
102938 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
102939 index c1b6270..05089c1 100644
102940 --- a/net/sunrpc/xprtrdma/svc_rdma.c
102941 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
102942 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
102943 static unsigned int min_max_inline = 4096;
102944 static unsigned int max_max_inline = 65536;
102945
102946 -atomic_t rdma_stat_recv;
102947 -atomic_t rdma_stat_read;
102948 -atomic_t rdma_stat_write;
102949 -atomic_t rdma_stat_sq_starve;
102950 -atomic_t rdma_stat_rq_starve;
102951 -atomic_t rdma_stat_rq_poll;
102952 -atomic_t rdma_stat_rq_prod;
102953 -atomic_t rdma_stat_sq_poll;
102954 -atomic_t rdma_stat_sq_prod;
102955 +atomic_unchecked_t rdma_stat_recv;
102956 +atomic_unchecked_t rdma_stat_read;
102957 +atomic_unchecked_t rdma_stat_write;
102958 +atomic_unchecked_t rdma_stat_sq_starve;
102959 +atomic_unchecked_t rdma_stat_rq_starve;
102960 +atomic_unchecked_t rdma_stat_rq_poll;
102961 +atomic_unchecked_t rdma_stat_rq_prod;
102962 +atomic_unchecked_t rdma_stat_sq_poll;
102963 +atomic_unchecked_t rdma_stat_sq_prod;
102964
102965 /* Temporary NFS request map and context caches */
102966 struct kmem_cache *svc_rdma_map_cachep;
102967 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
102968 len -= *ppos;
102969 if (len > *lenp)
102970 len = *lenp;
102971 - if (len && copy_to_user(buffer, str_buf, len))
102972 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
102973 return -EFAULT;
102974 *lenp = len;
102975 *ppos += len;
102976 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
102977 {
102978 .procname = "rdma_stat_read",
102979 .data = &rdma_stat_read,
102980 - .maxlen = sizeof(atomic_t),
102981 + .maxlen = sizeof(atomic_unchecked_t),
102982 .mode = 0644,
102983 .proc_handler = read_reset_stat,
102984 },
102985 {
102986 .procname = "rdma_stat_recv",
102987 .data = &rdma_stat_recv,
102988 - .maxlen = sizeof(atomic_t),
102989 + .maxlen = sizeof(atomic_unchecked_t),
102990 .mode = 0644,
102991 .proc_handler = read_reset_stat,
102992 },
102993 {
102994 .procname = "rdma_stat_write",
102995 .data = &rdma_stat_write,
102996 - .maxlen = sizeof(atomic_t),
102997 + .maxlen = sizeof(atomic_unchecked_t),
102998 .mode = 0644,
102999 .proc_handler = read_reset_stat,
103000 },
103001 {
103002 .procname = "rdma_stat_sq_starve",
103003 .data = &rdma_stat_sq_starve,
103004 - .maxlen = sizeof(atomic_t),
103005 + .maxlen = sizeof(atomic_unchecked_t),
103006 .mode = 0644,
103007 .proc_handler = read_reset_stat,
103008 },
103009 {
103010 .procname = "rdma_stat_rq_starve",
103011 .data = &rdma_stat_rq_starve,
103012 - .maxlen = sizeof(atomic_t),
103013 + .maxlen = sizeof(atomic_unchecked_t),
103014 .mode = 0644,
103015 .proc_handler = read_reset_stat,
103016 },
103017 {
103018 .procname = "rdma_stat_rq_poll",
103019 .data = &rdma_stat_rq_poll,
103020 - .maxlen = sizeof(atomic_t),
103021 + .maxlen = sizeof(atomic_unchecked_t),
103022 .mode = 0644,
103023 .proc_handler = read_reset_stat,
103024 },
103025 {
103026 .procname = "rdma_stat_rq_prod",
103027 .data = &rdma_stat_rq_prod,
103028 - .maxlen = sizeof(atomic_t),
103029 + .maxlen = sizeof(atomic_unchecked_t),
103030 .mode = 0644,
103031 .proc_handler = read_reset_stat,
103032 },
103033 {
103034 .procname = "rdma_stat_sq_poll",
103035 .data = &rdma_stat_sq_poll,
103036 - .maxlen = sizeof(atomic_t),
103037 + .maxlen = sizeof(atomic_unchecked_t),
103038 .mode = 0644,
103039 .proc_handler = read_reset_stat,
103040 },
103041 {
103042 .procname = "rdma_stat_sq_prod",
103043 .data = &rdma_stat_sq_prod,
103044 - .maxlen = sizeof(atomic_t),
103045 + .maxlen = sizeof(atomic_unchecked_t),
103046 .mode = 0644,
103047 .proc_handler = read_reset_stat,
103048 },
103049 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103050 index 0ce7552..d074459 100644
103051 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103052 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103053 @@ -501,7 +501,7 @@ next_sge:
103054 svc_rdma_put_context(ctxt, 0);
103055 goto out;
103056 }
103057 - atomic_inc(&rdma_stat_read);
103058 + atomic_inc_unchecked(&rdma_stat_read);
103059
103060 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
103061 chl_map->ch[ch_no].count -= read_wr.num_sge;
103062 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103063 dto_q);
103064 list_del_init(&ctxt->dto_q);
103065 } else {
103066 - atomic_inc(&rdma_stat_rq_starve);
103067 + atomic_inc_unchecked(&rdma_stat_rq_starve);
103068 clear_bit(XPT_DATA, &xprt->xpt_flags);
103069 ctxt = NULL;
103070 }
103071 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103072 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
103073 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
103074 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
103075 - atomic_inc(&rdma_stat_recv);
103076 + atomic_inc_unchecked(&rdma_stat_recv);
103077
103078 /* Build up the XDR from the receive buffers. */
103079 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
103080 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103081 index c1d124d..acfc59e 100644
103082 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103083 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103084 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
103085 write_wr.wr.rdma.remote_addr = to;
103086
103087 /* Post It */
103088 - atomic_inc(&rdma_stat_write);
103089 + atomic_inc_unchecked(&rdma_stat_write);
103090 if (svc_rdma_send(xprt, &write_wr))
103091 goto err;
103092 return 0;
103093 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
103094 index 62e4f9b..dd3f2d7 100644
103095 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
103096 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
103097 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
103098 return;
103099
103100 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
103101 - atomic_inc(&rdma_stat_rq_poll);
103102 + atomic_inc_unchecked(&rdma_stat_rq_poll);
103103
103104 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
103105 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
103106 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
103107 }
103108
103109 if (ctxt)
103110 - atomic_inc(&rdma_stat_rq_prod);
103111 + atomic_inc_unchecked(&rdma_stat_rq_prod);
103112
103113 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
103114 /*
103115 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
103116 return;
103117
103118 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
103119 - atomic_inc(&rdma_stat_sq_poll);
103120 + atomic_inc_unchecked(&rdma_stat_sq_poll);
103121 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
103122 if (wc.status != IB_WC_SUCCESS)
103123 /* Close the transport */
103124 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
103125 }
103126
103127 if (ctxt)
103128 - atomic_inc(&rdma_stat_sq_prod);
103129 + atomic_inc_unchecked(&rdma_stat_sq_prod);
103130 }
103131
103132 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
103133 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
103134 spin_lock_bh(&xprt->sc_lock);
103135 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
103136 spin_unlock_bh(&xprt->sc_lock);
103137 - atomic_inc(&rdma_stat_sq_starve);
103138 + atomic_inc_unchecked(&rdma_stat_sq_starve);
103139
103140 /* See if we can opportunistically reap SQ WR to make room */
103141 sq_cq_reap(xprt);
103142 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
103143 index e7000be..e3b0ba7 100644
103144 --- a/net/sysctl_net.c
103145 +++ b/net/sysctl_net.c
103146 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
103147 kgid_t root_gid = make_kgid(net->user_ns, 0);
103148
103149 /* Allow network administrator to have same access as root. */
103150 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
103151 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
103152 uid_eq(root_uid, current_euid())) {
103153 int mode = (table->mode >> 6) & 7;
103154 return (mode << 6) | (mode << 3) | mode;
103155 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
103156 index 6424372..afd36e9 100644
103157 --- a/net/tipc/subscr.c
103158 +++ b/net/tipc/subscr.c
103159 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
103160 struct tipc_subscriber *subscriber = sub->subscriber;
103161 struct kvec msg_sect;
103162
103163 - msg_sect.iov_base = (void *)&sub->evt;
103164 + msg_sect.iov_base = &sub->evt;
103165 msg_sect.iov_len = sizeof(struct tipc_event);
103166 sub->evt.event = htohl(event, sub->swap);
103167 sub->evt.found_lower = htohl(found_lower, sub->swap);
103168 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
103169 index 94404f1..5782191 100644
103170 --- a/net/unix/af_unix.c
103171 +++ b/net/unix/af_unix.c
103172 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
103173 err = -ECONNREFUSED;
103174 if (!S_ISSOCK(inode->i_mode))
103175 goto put_fail;
103176 +
103177 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
103178 + err = -EACCES;
103179 + goto put_fail;
103180 + }
103181 +
103182 u = unix_find_socket_byinode(inode);
103183 if (!u)
103184 goto put_fail;
103185 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
103186 if (u) {
103187 struct dentry *dentry;
103188 dentry = unix_sk(u)->path.dentry;
103189 +
103190 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
103191 + err = -EPERM;
103192 + sock_put(u);
103193 + goto fail;
103194 + }
103195 +
103196 if (dentry)
103197 touch_atime(&unix_sk(u)->path);
103198 } else
103199 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
103200 */
103201 err = security_path_mknod(&path, dentry, mode, 0);
103202 if (!err) {
103203 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
103204 + err = -EACCES;
103205 + goto out;
103206 + }
103207 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
103208 if (!err) {
103209 res->mnt = mntget(path.mnt);
103210 res->dentry = dget(dentry);
103211 + gr_handle_create(dentry, path.mnt);
103212 }
103213 }
103214 +out:
103215 done_path_create(&path, dentry);
103216 return err;
103217 }
103218 @@ -2344,9 +2363,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
103219 seq_puts(seq, "Num RefCount Protocol Flags Type St "
103220 "Inode Path\n");
103221 else {
103222 - struct sock *s = v;
103223 + struct sock *s = v, *peer;
103224 struct unix_sock *u = unix_sk(s);
103225 unix_state_lock(s);
103226 + peer = unix_peer(s);
103227 + unix_state_unlock(s);
103228 +
103229 + unix_state_double_lock(s, peer);
103230
103231 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
103232 s,
103233 @@ -2373,8 +2396,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
103234 }
103235 for ( ; i < len; i++)
103236 seq_putc(seq, u->addr->name->sun_path[i]);
103237 - }
103238 - unix_state_unlock(s);
103239 + } else if (peer)
103240 + seq_printf(seq, " P%lu", sock_i_ino(peer));
103241 +
103242 + unix_state_double_unlock(s, peer);
103243 seq_putc(seq, '\n');
103244 }
103245
103246 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
103247 index b3d5150..ff3a837 100644
103248 --- a/net/unix/sysctl_net_unix.c
103249 +++ b/net/unix/sysctl_net_unix.c
103250 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
103251
103252 int __net_init unix_sysctl_register(struct net *net)
103253 {
103254 - struct ctl_table *table;
103255 + ctl_table_no_const *table;
103256
103257 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
103258 if (table == NULL)
103259 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
103260 index 9a73074..aecba9a 100644
103261 --- a/net/vmw_vsock/vmci_transport_notify.c
103262 +++ b/net/vmw_vsock/vmci_transport_notify.c
103263 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
103264
103265 /* Socket control packet based operations. */
103266 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
103267 - vmci_transport_notify_pkt_socket_init,
103268 - vmci_transport_notify_pkt_socket_destruct,
103269 - vmci_transport_notify_pkt_poll_in,
103270 - vmci_transport_notify_pkt_poll_out,
103271 - vmci_transport_notify_pkt_handle_pkt,
103272 - vmci_transport_notify_pkt_recv_init,
103273 - vmci_transport_notify_pkt_recv_pre_block,
103274 - vmci_transport_notify_pkt_recv_pre_dequeue,
103275 - vmci_transport_notify_pkt_recv_post_dequeue,
103276 - vmci_transport_notify_pkt_send_init,
103277 - vmci_transport_notify_pkt_send_pre_block,
103278 - vmci_transport_notify_pkt_send_pre_enqueue,
103279 - vmci_transport_notify_pkt_send_post_enqueue,
103280 - vmci_transport_notify_pkt_process_request,
103281 - vmci_transport_notify_pkt_process_negotiate,
103282 + .socket_init = vmci_transport_notify_pkt_socket_init,
103283 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
103284 + .poll_in = vmci_transport_notify_pkt_poll_in,
103285 + .poll_out = vmci_transport_notify_pkt_poll_out,
103286 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
103287 + .recv_init = vmci_transport_notify_pkt_recv_init,
103288 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
103289 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
103290 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
103291 + .send_init = vmci_transport_notify_pkt_send_init,
103292 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
103293 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
103294 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
103295 + .process_request = vmci_transport_notify_pkt_process_request,
103296 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
103297 };
103298 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
103299 index 622bd7a..b92086c 100644
103300 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
103301 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
103302 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
103303
103304 /* Socket always on control packet based operations. */
103305 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
103306 - vmci_transport_notify_pkt_socket_init,
103307 - vmci_transport_notify_pkt_socket_destruct,
103308 - vmci_transport_notify_pkt_poll_in,
103309 - vmci_transport_notify_pkt_poll_out,
103310 - vmci_transport_notify_pkt_handle_pkt,
103311 - vmci_transport_notify_pkt_recv_init,
103312 - vmci_transport_notify_pkt_recv_pre_block,
103313 - vmci_transport_notify_pkt_recv_pre_dequeue,
103314 - vmci_transport_notify_pkt_recv_post_dequeue,
103315 - vmci_transport_notify_pkt_send_init,
103316 - vmci_transport_notify_pkt_send_pre_block,
103317 - vmci_transport_notify_pkt_send_pre_enqueue,
103318 - vmci_transport_notify_pkt_send_post_enqueue,
103319 - vmci_transport_notify_pkt_process_request,
103320 - vmci_transport_notify_pkt_process_negotiate,
103321 + .socket_init = vmci_transport_notify_pkt_socket_init,
103322 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
103323 + .poll_in = vmci_transport_notify_pkt_poll_in,
103324 + .poll_out = vmci_transport_notify_pkt_poll_out,
103325 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
103326 + .recv_init = vmci_transport_notify_pkt_recv_init,
103327 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
103328 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
103329 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
103330 + .send_init = vmci_transport_notify_pkt_send_init,
103331 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
103332 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
103333 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
103334 + .process_request = vmci_transport_notify_pkt_process_request,
103335 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
103336 };
103337 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
103338 index c8717c1..08539f5 100644
103339 --- a/net/wireless/wext-core.c
103340 +++ b/net/wireless/wext-core.c
103341 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
103342 */
103343
103344 /* Support for very large requests */
103345 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
103346 - (user_length > descr->max_tokens)) {
103347 + if (user_length > descr->max_tokens) {
103348 /* Allow userspace to GET more than max so
103349 * we can support any size GET requests.
103350 * There is still a limit : -ENOMEM.
103351 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
103352 }
103353 }
103354
103355 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
103356 - /*
103357 - * If this is a GET, but not NOMAX, it means that the extra
103358 - * data is not bounded by userspace, but by max_tokens. Thus
103359 - * set the length to max_tokens. This matches the extra data
103360 - * allocation.
103361 - * The driver should fill it with the number of tokens it
103362 - * provided, and it may check iwp->length rather than having
103363 - * knowledge of max_tokens. If the driver doesn't change the
103364 - * iwp->length, this ioctl just copies back max_token tokens
103365 - * filled with zeroes. Hopefully the driver isn't claiming
103366 - * them to be valid data.
103367 - */
103368 - iwp->length = descr->max_tokens;
103369 - }
103370 -
103371 err = handler(dev, info, (union iwreq_data *) iwp, extra);
103372
103373 iwp->length += essid_compat;
103374 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
103375 index 4323952..a06dfe1 100644
103376 --- a/net/x25/sysctl_net_x25.c
103377 +++ b/net/x25/sysctl_net_x25.c
103378 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
103379 .mode = 0644,
103380 .proc_handler = proc_dointvec,
103381 },
103382 - { 0, },
103383 + { },
103384 };
103385
103386 void __init x25_register_sysctl(void)
103387 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
103388 index 0917f04..f4e3d8c 100644
103389 --- a/net/x25/x25_proc.c
103390 +++ b/net/x25/x25_proc.c
103391 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
103392
103393 int __init x25_proc_init(void)
103394 {
103395 - if (!proc_mkdir("x25", init_net.proc_net))
103396 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
103397 return -ENOMEM;
103398
103399 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
103400 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
103401 index 1d5c7bf..f762f1f 100644
103402 --- a/net/xfrm/xfrm_policy.c
103403 +++ b/net/xfrm/xfrm_policy.c
103404 @@ -327,7 +327,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
103405 {
103406 policy->walk.dead = 1;
103407
103408 - atomic_inc(&policy->genid);
103409 + atomic_inc_unchecked(&policy->genid);
103410
103411 if (del_timer(&policy->polq.hold_timer))
103412 xfrm_pol_put(policy);
103413 @@ -661,7 +661,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
103414 hlist_add_head(&policy->bydst, chain);
103415 xfrm_pol_hold(policy);
103416 net->xfrm.policy_count[dir]++;
103417 - atomic_inc(&flow_cache_genid);
103418 + atomic_inc_unchecked(&flow_cache_genid);
103419
103420 /* After previous checking, family can either be AF_INET or AF_INET6 */
103421 if (policy->family == AF_INET)
103422 @@ -1761,7 +1761,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
103423
103424 xdst->num_pols = num_pols;
103425 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
103426 - xdst->policy_genid = atomic_read(&pols[0]->genid);
103427 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
103428
103429 return xdst;
103430 }
103431 @@ -2572,11 +2572,12 @@ void xfrm_garbage_collect(struct net *net)
103432 }
103433 EXPORT_SYMBOL(xfrm_garbage_collect);
103434
103435 -static void xfrm_garbage_collect_deferred(struct net *net)
103436 +void xfrm_garbage_collect_deferred(struct net *net)
103437 {
103438 flow_cache_flush_deferred();
103439 __xfrm_garbage_collect(net);
103440 }
103441 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
103442
103443 static void xfrm_init_pmtu(struct dst_entry *dst)
103444 {
103445 @@ -2626,7 +2627,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
103446 if (xdst->xfrm_genid != dst->xfrm->genid)
103447 return 0;
103448 if (xdst->num_pols > 0 &&
103449 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
103450 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
103451 return 0;
103452
103453 mtu = dst_mtu(dst->child);
103454 @@ -2714,8 +2715,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
103455 dst_ops->link_failure = xfrm_link_failure;
103456 if (likely(dst_ops->neigh_lookup == NULL))
103457 dst_ops->neigh_lookup = xfrm_neigh_lookup;
103458 - if (likely(afinfo->garbage_collect == NULL))
103459 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
103460 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
103461 }
103462 spin_unlock(&xfrm_policy_afinfo_lock);
103463 @@ -2769,7 +2768,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
103464 dst_ops->check = NULL;
103465 dst_ops->negative_advice = NULL;
103466 dst_ops->link_failure = NULL;
103467 - afinfo->garbage_collect = NULL;
103468 }
103469 return err;
103470 }
103471 @@ -3159,7 +3157,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
103472 sizeof(pol->xfrm_vec[i].saddr));
103473 pol->xfrm_vec[i].encap_family = mp->new_family;
103474 /* flush bundles */
103475 - atomic_inc(&pol->genid);
103476 + atomic_inc_unchecked(&pol->genid);
103477 }
103478 }
103479
103480 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
103481 index 40f1b3e..e33fdfa 100644
103482 --- a/net/xfrm/xfrm_state.c
103483 +++ b/net/xfrm/xfrm_state.c
103484 @@ -172,12 +172,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
103485
103486 if (unlikely(afinfo == NULL))
103487 return -EAFNOSUPPORT;
103488 - typemap = afinfo->type_map;
103489 + typemap = (const struct xfrm_type **)afinfo->type_map;
103490 spin_lock_bh(&xfrm_type_lock);
103491
103492 - if (likely(typemap[type->proto] == NULL))
103493 + if (likely(typemap[type->proto] == NULL)) {
103494 + pax_open_kernel();
103495 typemap[type->proto] = type;
103496 - else
103497 + pax_close_kernel();
103498 + } else
103499 err = -EEXIST;
103500 spin_unlock_bh(&xfrm_type_lock);
103501 xfrm_state_put_afinfo(afinfo);
103502 @@ -193,13 +195,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
103503
103504 if (unlikely(afinfo == NULL))
103505 return -EAFNOSUPPORT;
103506 - typemap = afinfo->type_map;
103507 + typemap = (const struct xfrm_type **)afinfo->type_map;
103508 spin_lock_bh(&xfrm_type_lock);
103509
103510 if (unlikely(typemap[type->proto] != type))
103511 err = -ENOENT;
103512 - else
103513 + else {
103514 + pax_open_kernel();
103515 typemap[type->proto] = NULL;
103516 + pax_close_kernel();
103517 + }
103518 spin_unlock_bh(&xfrm_type_lock);
103519 xfrm_state_put_afinfo(afinfo);
103520 return err;
103521 @@ -209,7 +214,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
103522 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
103523 {
103524 struct xfrm_state_afinfo *afinfo;
103525 - const struct xfrm_type **typemap;
103526 const struct xfrm_type *type;
103527 int modload_attempted = 0;
103528
103529 @@ -217,9 +221,8 @@ retry:
103530 afinfo = xfrm_state_get_afinfo(family);
103531 if (unlikely(afinfo == NULL))
103532 return NULL;
103533 - typemap = afinfo->type_map;
103534
103535 - type = typemap[proto];
103536 + type = afinfo->type_map[proto];
103537 if (unlikely(type && !try_module_get(type->owner)))
103538 type = NULL;
103539 if (!type && !modload_attempted) {
103540 @@ -253,7 +256,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
103541 return -EAFNOSUPPORT;
103542
103543 err = -EEXIST;
103544 - modemap = afinfo->mode_map;
103545 + modemap = (struct xfrm_mode **)afinfo->mode_map;
103546 spin_lock_bh(&xfrm_mode_lock);
103547 if (modemap[mode->encap])
103548 goto out;
103549 @@ -262,8 +265,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
103550 if (!try_module_get(afinfo->owner))
103551 goto out;
103552
103553 - mode->afinfo = afinfo;
103554 + pax_open_kernel();
103555 + *(const void **)&mode->afinfo = afinfo;
103556 modemap[mode->encap] = mode;
103557 + pax_close_kernel();
103558 err = 0;
103559
103560 out:
103561 @@ -287,10 +292,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
103562 return -EAFNOSUPPORT;
103563
103564 err = -ENOENT;
103565 - modemap = afinfo->mode_map;
103566 + modemap = (struct xfrm_mode **)afinfo->mode_map;
103567 spin_lock_bh(&xfrm_mode_lock);
103568 if (likely(modemap[mode->encap] == mode)) {
103569 + pax_open_kernel();
103570 modemap[mode->encap] = NULL;
103571 + pax_close_kernel();
103572 module_put(mode->afinfo->owner);
103573 err = 0;
103574 }
103575 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
103576 u32 xfrm_get_acqseq(void)
103577 {
103578 u32 res;
103579 - static atomic_t acqseq;
103580 + static atomic_unchecked_t acqseq;
103581
103582 do {
103583 - res = atomic_inc_return(&acqseq);
103584 + res = atomic_inc_return_unchecked(&acqseq);
103585 } while (!res);
103586
103587 return res;
103588 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
103589 index 05a6e3d..6716ec9 100644
103590 --- a/net/xfrm/xfrm_sysctl.c
103591 +++ b/net/xfrm/xfrm_sysctl.c
103592 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
103593
103594 int __net_init xfrm_sysctl_init(struct net *net)
103595 {
103596 - struct ctl_table *table;
103597 + ctl_table_no_const *table;
103598
103599 __xfrm_sysctl_init(net);
103600
103601 diff --git a/scripts/Makefile b/scripts/Makefile
103602 index 01e7adb..6176d5d 100644
103603 --- a/scripts/Makefile
103604 +++ b/scripts/Makefile
103605 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
103606
103607 # Let clean descend into subdirs
103608 subdir- += basic kconfig package selinux
103609 +
103610 +clean-files := randstruct.seed
103611 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
103612 index d5d859c..781cbcb 100644
103613 --- a/scripts/Makefile.build
103614 +++ b/scripts/Makefile.build
103615 @@ -111,7 +111,7 @@ endif
103616 endif
103617
103618 # Do not include host rules unless needed
103619 -ifneq ($(hostprogs-y)$(hostprogs-m),)
103620 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
103621 include scripts/Makefile.host
103622 endif
103623
103624 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
103625 index 686cb0d..9d653bf 100644
103626 --- a/scripts/Makefile.clean
103627 +++ b/scripts/Makefile.clean
103628 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
103629 __clean-files := $(extra-y) $(always) \
103630 $(targets) $(clean-files) \
103631 $(host-progs) \
103632 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
103633 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
103634 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
103635
103636 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
103637
103638 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
103639 index 1ac414f..38575f7 100644
103640 --- a/scripts/Makefile.host
103641 +++ b/scripts/Makefile.host
103642 @@ -31,6 +31,8 @@
103643 # Note: Shared libraries consisting of C++ files are not supported
103644
103645 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
103646 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
103647 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
103648
103649 # C code
103650 # Executables compiled from a single .c file
103651 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
103652 # Shared libaries (only .c supported)
103653 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
103654 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
103655 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
103656 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
103657 # Remove .so files from "xxx-objs"
103658 host-cobjs := $(filter-out %.so,$(host-cobjs))
103659 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
103660
103661 -#Object (.o) files used by the shared libaries
103662 +# Object (.o) files used by the shared libaries
103663 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
103664 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
103665
103666 # output directory for programs/.o files
103667 # hostprogs-y := tools/build may have been specified. Retrieve directory
103668 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
103669 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
103670 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
103671 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
103672 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
103673 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
103674 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
103675 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
103676
103677 obj-dirs += $(host-objdirs)
103678 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
103679 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
103680 $(call if_changed_dep,host-cshobjs)
103681
103682 +# Compile .c file, create position independent .o file
103683 +# host-cxxshobjs -> .o
103684 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
103685 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
103686 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
103687 + $(call if_changed_dep,host-cxxshobjs)
103688 +
103689 # Link a shared library, based on position independent .o files
103690 # *.o -> .so shared library (host-cshlib)
103691 quiet_cmd_host-cshlib = HOSTLLD -shared $@
103692 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
103693 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
103694 $(call if_changed,host-cshlib)
103695
103696 +# Link a shared library, based on position independent .o files
103697 +# *.o -> .so shared library (host-cxxshlib)
103698 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
103699 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
103700 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
103701 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
103702 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
103703 + $(call if_changed,host-cxxshlib)
103704 +
103705 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
103706 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
103707 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
103708
103709 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
103710 index 078fe1d..fbdb363 100644
103711 --- a/scripts/basic/fixdep.c
103712 +++ b/scripts/basic/fixdep.c
103713 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
103714 /*
103715 * Lookup a value in the configuration string.
103716 */
103717 -static int is_defined_config(const char *name, int len, unsigned int hash)
103718 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
103719 {
103720 struct item *aux;
103721
103722 @@ -211,10 +211,10 @@ static void clear_config(void)
103723 /*
103724 * Record the use of a CONFIG_* word.
103725 */
103726 -static void use_config(const char *m, int slen)
103727 +static void use_config(const char *m, unsigned int slen)
103728 {
103729 unsigned int hash = strhash(m, slen);
103730 - int c, i;
103731 + unsigned int c, i;
103732
103733 if (is_defined_config(m, slen, hash))
103734 return;
103735 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
103736
103737 static void parse_config_file(const char *map, size_t len)
103738 {
103739 - const int *end = (const int *) (map + len);
103740 + const unsigned int *end = (const unsigned int *) (map + len);
103741 /* start at +1, so that p can never be < map */
103742 - const int *m = (const int *) map + 1;
103743 + const unsigned int *m = (const unsigned int *) map + 1;
103744 const char *p, *q;
103745
103746 for (; m < end; m++) {
103747 @@ -435,7 +435,7 @@ static void print_deps(void)
103748 static void traps(void)
103749 {
103750 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
103751 - int *p = (int *)test;
103752 + unsigned int *p = (unsigned int *)test;
103753
103754 if (*p != INT_CONF) {
103755 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
103756 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
103757 new file mode 100644
103758 index 0000000..edcbc3a
103759 --- /dev/null
103760 +++ b/scripts/gcc-plugin.sh
103761 @@ -0,0 +1,16 @@
103762 +#!/bin/bash
103763 +srctree=$(dirname "$0")
103764 +gccplugins_dir=$($3 -print-file-name=plugin)
103765 +plugincc=$($1 -E -shared - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
103766 +#include "gcc-common.h"
103767 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
103768 +#warning $2
103769 +#else
103770 +#warning $1
103771 +#endif
103772 +EOF
103773 +)
103774 +if [ $? -eq 0 ]
103775 +then
103776 + ( [[ "$plugincc" =~ "$1" ]] && echo "$1" ) || ( [[ "$plugincc" =~ "$2" ]] && echo "$2" )
103777 +fi
103778 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
103779 index 5de5660..d3deb89 100644
103780 --- a/scripts/headers_install.sh
103781 +++ b/scripts/headers_install.sh
103782 @@ -32,6 +32,7 @@ do
103783 FILE="$(basename "$i")"
103784 sed -r \
103785 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
103786 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
103787 -e 's/__attribute_const__([ \t]|$)/\1/g' \
103788 -e 's@^#include <linux/compiler.h>@@' \
103789 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
103790 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
103791 index 2dcb377..a82c500 100644
103792 --- a/scripts/link-vmlinux.sh
103793 +++ b/scripts/link-vmlinux.sh
103794 @@ -162,7 +162,7 @@ else
103795 fi;
103796
103797 # final build of init/
103798 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
103799 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
103800
103801 kallsymso=""
103802 kallsyms_vmlinux=""
103803 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
103804 index 25e5cb0..6e85821 100644
103805 --- a/scripts/mod/file2alias.c
103806 +++ b/scripts/mod/file2alias.c
103807 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
103808 unsigned long size, unsigned long id_size,
103809 void *symval)
103810 {
103811 - int i;
103812 + unsigned int i;
103813
103814 if (size % id_size || size < id_size) {
103815 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
103816 @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
103817 /* USB is special because the bcdDevice can be matched against a numeric range */
103818 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
103819 static void do_usb_entry(void *symval,
103820 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
103821 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
103822 unsigned char range_lo, unsigned char range_hi,
103823 unsigned char max, struct module *mod)
103824 {
103825 @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
103826 {
103827 unsigned int devlo, devhi;
103828 unsigned char chi, clo, max;
103829 - int ndigits;
103830 + unsigned int ndigits;
103831
103832 DEF_FIELD(symval, usb_device_id, match_flags);
103833 DEF_FIELD(symval, usb_device_id, idVendor);
103834 @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
103835 for (i = 0; i < count; i++) {
103836 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
103837 char acpi_id[sizeof(*id)];
103838 - int j;
103839 + unsigned int j;
103840
103841 buf_printf(&mod->dev_table_buf,
103842 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
103843 @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
103844
103845 for (j = 0; j < PNP_MAX_DEVICES; j++) {
103846 const char *id = (char *)(*devs)[j].id;
103847 - int i2, j2;
103848 + unsigned int i2, j2;
103849 int dup = 0;
103850
103851 if (!id[0])
103852 @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
103853 /* add an individual alias for every device entry */
103854 if (!dup) {
103855 char acpi_id[PNP_ID_LEN];
103856 - int k;
103857 + unsigned int k;
103858
103859 buf_printf(&mod->dev_table_buf,
103860 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
103861 @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
103862 static int do_dmi_entry(const char *filename, void *symval,
103863 char *alias)
103864 {
103865 - int i, j;
103866 + unsigned int i, j;
103867 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
103868 sprintf(alias, "dmi*");
103869
103870 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
103871 index 99a45fd..4b995a3 100644
103872 --- a/scripts/mod/modpost.c
103873 +++ b/scripts/mod/modpost.c
103874 @@ -945,6 +945,7 @@ enum mismatch {
103875 ANY_INIT_TO_ANY_EXIT,
103876 ANY_EXIT_TO_ANY_INIT,
103877 EXPORT_TO_INIT_EXIT,
103878 + DATA_TO_TEXT
103879 };
103880
103881 struct sectioncheck {
103882 @@ -1031,6 +1032,12 @@ const struct sectioncheck sectioncheck[] = {
103883 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
103884 .mismatch = EXPORT_TO_INIT_EXIT,
103885 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
103886 +},
103887 +/* Do not reference code from writable data */
103888 +{
103889 + .fromsec = { DATA_SECTIONS, NULL },
103890 + .tosec = { TEXT_SECTIONS, NULL },
103891 + .mismatch = DATA_TO_TEXT
103892 }
103893 };
103894
103895 @@ -1151,10 +1158,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
103896 continue;
103897 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
103898 continue;
103899 - if (sym->st_value == addr)
103900 - return sym;
103901 /* Find a symbol nearby - addr are maybe negative */
103902 d = sym->st_value - addr;
103903 + if (d == 0)
103904 + return sym;
103905 if (d < 0)
103906 d = addr - sym->st_value;
103907 if (d < distance) {
103908 @@ -1432,6 +1439,14 @@ static void report_sec_mismatch(const char *modname,
103909 tosym, prl_to, prl_to, tosym);
103910 free(prl_to);
103911 break;
103912 + case DATA_TO_TEXT:
103913 +#if 0
103914 + fprintf(stderr,
103915 + "The %s %s:%s references\n"
103916 + "the %s %s:%s%s\n",
103917 + from, fromsec, fromsym, to, tosec, tosym, to_p);
103918 +#endif
103919 + break;
103920 }
103921 fprintf(stderr, "\n");
103922 }
103923 @@ -1679,7 +1694,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
103924 static void check_sec_ref(struct module *mod, const char *modname,
103925 struct elf_info *elf)
103926 {
103927 - int i;
103928 + unsigned int i;
103929 Elf_Shdr *sechdrs = elf->sechdrs;
103930
103931 /* Walk through all sections */
103932 @@ -1798,7 +1813,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
103933 va_end(ap);
103934 }
103935
103936 -void buf_write(struct buffer *buf, const char *s, int len)
103937 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
103938 {
103939 if (buf->size - buf->pos < len) {
103940 buf->size += len + SZ;
103941 @@ -2017,7 +2032,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
103942 if (fstat(fileno(file), &st) < 0)
103943 goto close_write;
103944
103945 - if (st.st_size != b->pos)
103946 + if (st.st_size != (off_t)b->pos)
103947 goto close_write;
103948
103949 tmp = NOFAIL(malloc(b->pos));
103950 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
103951 index 51207e4..f7d603d 100644
103952 --- a/scripts/mod/modpost.h
103953 +++ b/scripts/mod/modpost.h
103954 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
103955
103956 struct buffer {
103957 char *p;
103958 - int pos;
103959 - int size;
103960 + unsigned int pos;
103961 + unsigned int size;
103962 };
103963
103964 void __attribute__((format(printf, 2, 3)))
103965 buf_printf(struct buffer *buf, const char *fmt, ...);
103966
103967 void
103968 -buf_write(struct buffer *buf, const char *s, int len);
103969 +buf_write(struct buffer *buf, const char *s, unsigned int len);
103970
103971 struct module {
103972 struct module *next;
103973 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
103974 index deb2994..af4f63e 100644
103975 --- a/scripts/mod/sumversion.c
103976 +++ b/scripts/mod/sumversion.c
103977 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
103978 goto out;
103979 }
103980
103981 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
103982 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
103983 warn("writing sum in %s failed: %s\n",
103984 filename, strerror(errno));
103985 goto out;
103986 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
103987 index 0865b3e..7235dd4 100644
103988 --- a/scripts/module-common.lds
103989 +++ b/scripts/module-common.lds
103990 @@ -6,6 +6,10 @@
103991 SECTIONS {
103992 /DISCARD/ : { *(.discard) }
103993
103994 + .rodata : {
103995 + *(.rodata) *(.rodata.*)
103996 + *(.data..read_only)
103997 + }
103998 __ksymtab : { *(SORT(___ksymtab+*)) }
103999 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
104000 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
104001 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
104002 index f46e4dd..090e168 100644
104003 --- a/scripts/package/builddeb
104004 +++ b/scripts/package/builddeb
104005 @@ -291,6 +291,7 @@ fi
104006 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
104007 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
104008 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
104009 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
104010 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
104011 mkdir -p "$destdir"
104012 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
104013 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
104014 index 68bb4ef..2f419e1 100644
104015 --- a/scripts/pnmtologo.c
104016 +++ b/scripts/pnmtologo.c
104017 @@ -244,14 +244,14 @@ static void write_header(void)
104018 fprintf(out, " * Linux logo %s\n", logoname);
104019 fputs(" */\n\n", out);
104020 fputs("#include <linux/linux_logo.h>\n\n", out);
104021 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
104022 + fprintf(out, "static unsigned char %s_data[] = {\n",
104023 logoname);
104024 }
104025
104026 static void write_footer(void)
104027 {
104028 fputs("\n};\n\n", out);
104029 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
104030 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
104031 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
104032 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
104033 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
104034 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
104035 fputs("\n};\n\n", out);
104036
104037 /* write logo clut */
104038 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
104039 + fprintf(out, "static unsigned char %s_clut[] = {\n",
104040 logoname);
104041 write_hex_cnt = 0;
104042 for (i = 0; i < logo_clutsize; i++) {
104043 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
104044 index 8fac3fd..32ff38d 100644
104045 --- a/scripts/sortextable.h
104046 +++ b/scripts/sortextable.h
104047 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
104048 const char *secstrtab;
104049 const char *strtab;
104050 char *extab_image;
104051 - int extab_index = 0;
104052 - int i;
104053 - int idx;
104054 + unsigned int extab_index = 0;
104055 + unsigned int i;
104056 + unsigned int idx;
104057 unsigned int num_sections;
104058 unsigned int secindex_strings;
104059
104060 diff --git a/security/Kconfig b/security/Kconfig
104061 index beb86b5..55198cd 100644
104062 --- a/security/Kconfig
104063 +++ b/security/Kconfig
104064 @@ -4,6 +4,961 @@
104065
104066 menu "Security options"
104067
104068 +menu "Grsecurity"
104069 +
104070 + config ARCH_TRACK_EXEC_LIMIT
104071 + bool
104072 +
104073 + config PAX_KERNEXEC_PLUGIN
104074 + bool
104075 +
104076 + config PAX_PER_CPU_PGD
104077 + bool
104078 +
104079 + config TASK_SIZE_MAX_SHIFT
104080 + int
104081 + depends on X86_64
104082 + default 47 if !PAX_PER_CPU_PGD
104083 + default 42 if PAX_PER_CPU_PGD
104084 +
104085 + config PAX_ENABLE_PAE
104086 + bool
104087 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
104088 +
104089 + config PAX_USERCOPY_SLABS
104090 + bool
104091 +
104092 +config GRKERNSEC
104093 + bool "Grsecurity"
104094 + select CRYPTO
104095 + select CRYPTO_SHA256
104096 + select PROC_FS
104097 + select STOP_MACHINE
104098 + select TTY
104099 + select DEBUG_KERNEL
104100 + select DEBUG_LIST
104101 + select DEBUG_STACKOVERFLOW if HAVE_DEBUG_STACKOVERFLOW
104102 + help
104103 + If you say Y here, you will be able to configure many features
104104 + that will enhance the security of your system. It is highly
104105 + recommended that you say Y here and read through the help
104106 + for each option so that you fully understand the features and
104107 + can evaluate their usefulness for your machine.
104108 +
104109 +choice
104110 + prompt "Configuration Method"
104111 + depends on GRKERNSEC
104112 + default GRKERNSEC_CONFIG_CUSTOM
104113 + help
104114 +
104115 +config GRKERNSEC_CONFIG_AUTO
104116 + bool "Automatic"
104117 + help
104118 + If you choose this configuration method, you'll be able to answer a small
104119 + number of simple questions about how you plan to use this kernel.
104120 + The settings of grsecurity and PaX will be automatically configured for
104121 + the highest commonly-used settings within the provided constraints.
104122 +
104123 + If you require additional configuration, custom changes can still be made
104124 + from the "custom configuration" menu.
104125 +
104126 +config GRKERNSEC_CONFIG_CUSTOM
104127 + bool "Custom"
104128 + help
104129 + If you choose this configuration method, you'll be able to configure all
104130 + grsecurity and PaX settings manually. Via this method, no options are
104131 + automatically enabled.
104132 +
104133 +endchoice
104134 +
104135 +choice
104136 + prompt "Usage Type"
104137 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104138 + default GRKERNSEC_CONFIG_SERVER
104139 + help
104140 +
104141 +config GRKERNSEC_CONFIG_SERVER
104142 + bool "Server"
104143 + help
104144 + Choose this option if you plan to use this kernel on a server.
104145 +
104146 +config GRKERNSEC_CONFIG_DESKTOP
104147 + bool "Desktop"
104148 + help
104149 + Choose this option if you plan to use this kernel on a desktop.
104150 +
104151 +endchoice
104152 +
104153 +choice
104154 + prompt "Virtualization Type"
104155 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
104156 + default GRKERNSEC_CONFIG_VIRT_NONE
104157 + help
104158 +
104159 +config GRKERNSEC_CONFIG_VIRT_NONE
104160 + bool "None"
104161 + help
104162 + Choose this option if this kernel will be run on bare metal.
104163 +
104164 +config GRKERNSEC_CONFIG_VIRT_GUEST
104165 + bool "Guest"
104166 + help
104167 + Choose this option if this kernel will be run as a VM guest.
104168 +
104169 +config GRKERNSEC_CONFIG_VIRT_HOST
104170 + bool "Host"
104171 + help
104172 + Choose this option if this kernel will be run as a VM host.
104173 +
104174 +endchoice
104175 +
104176 +choice
104177 + prompt "Virtualization Hardware"
104178 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
104179 + help
104180 +
104181 +config GRKERNSEC_CONFIG_VIRT_EPT
104182 + bool "EPT/RVI Processor Support"
104183 + depends on X86
104184 + help
104185 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
104186 + hardware virtualization. This allows for additional kernel hardening protections
104187 + to operate without additional performance impact.
104188 +
104189 + To see if your Intel processor supports EPT, see:
104190 + http://ark.intel.com/Products/VirtualizationTechnology
104191 + (Most Core i3/5/7 support EPT)
104192 +
104193 + To see if your AMD processor supports RVI, see:
104194 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
104195 +
104196 +config GRKERNSEC_CONFIG_VIRT_SOFT
104197 + bool "First-gen/No Hardware Virtualization"
104198 + help
104199 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
104200 + support hardware virtualization or doesn't support the EPT/RVI extensions.
104201 +
104202 +endchoice
104203 +
104204 +choice
104205 + prompt "Virtualization Software"
104206 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
104207 + help
104208 +
104209 +config GRKERNSEC_CONFIG_VIRT_XEN
104210 + bool "Xen"
104211 + help
104212 + Choose this option if this kernel is running as a Xen guest or host.
104213 +
104214 +config GRKERNSEC_CONFIG_VIRT_VMWARE
104215 + bool "VMWare"
104216 + help
104217 + Choose this option if this kernel is running as a VMWare guest or host.
104218 +
104219 +config GRKERNSEC_CONFIG_VIRT_KVM
104220 + bool "KVM"
104221 + help
104222 + Choose this option if this kernel is running as a KVM guest or host.
104223 +
104224 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
104225 + bool "VirtualBox"
104226 + help
104227 + Choose this option if this kernel is running as a VirtualBox guest or host.
104228 +
104229 +endchoice
104230 +
104231 +choice
104232 + prompt "Required Priorities"
104233 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104234 + default GRKERNSEC_CONFIG_PRIORITY_PERF
104235 + help
104236 +
104237 +config GRKERNSEC_CONFIG_PRIORITY_PERF
104238 + bool "Performance"
104239 + help
104240 + Choose this option if performance is of highest priority for this deployment
104241 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
104242 + clearing of structures intended for userland, and freed memory sanitizing will
104243 + be disabled.
104244 +
104245 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
104246 + bool "Security"
104247 + help
104248 + Choose this option if security is of highest priority for this deployment of
104249 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
104250 + for userland, and freed memory sanitizing will be enabled for this kernel.
104251 + In a worst-case scenario, these features can introduce a 20% performance hit
104252 + (UDEREF on x64 contributing half of this hit).
104253 +
104254 +endchoice
104255 +
104256 +menu "Default Special Groups"
104257 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104258 +
104259 +config GRKERNSEC_PROC_GID
104260 + int "GID exempted from /proc restrictions"
104261 + default 1001
104262 + help
104263 + Setting this GID determines which group will be exempted from
104264 + grsecurity's /proc restrictions, allowing users of the specified
104265 + group to view network statistics and the existence of other users'
104266 + processes on the system. This GID may also be chosen at boot time
104267 + via "grsec_proc_gid=" on the kernel commandline.
104268 +
104269 +config GRKERNSEC_TPE_UNTRUSTED_GID
104270 + int "GID for TPE-untrusted users"
104271 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
104272 + default 1005
104273 + help
104274 + Setting this GID determines which group untrusted users should
104275 + be added to. These users will be placed under grsecurity's Trusted Path
104276 + Execution mechanism, preventing them from executing their own binaries.
104277 + The users will only be able to execute binaries in directories owned and
104278 + writable only by the root user. If the sysctl option is enabled, a sysctl
104279 + option with name "tpe_gid" is created.
104280 +
104281 +config GRKERNSEC_TPE_TRUSTED_GID
104282 + int "GID for TPE-trusted users"
104283 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
104284 + default 1005
104285 + help
104286 + Setting this GID determines what group TPE restrictions will be
104287 + *disabled* for. If the sysctl option is enabled, a sysctl option
104288 + with name "tpe_gid" is created.
104289 +
104290 +config GRKERNSEC_SYMLINKOWN_GID
104291 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
104292 + depends on GRKERNSEC_CONFIG_SERVER
104293 + default 1006
104294 + help
104295 + Setting this GID determines what group kernel-enforced
104296 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
104297 + is enabled, a sysctl option with name "symlinkown_gid" is created.
104298 +
104299 +
104300 +endmenu
104301 +
104302 +menu "Customize Configuration"
104303 +depends on GRKERNSEC
104304 +
104305 +menu "PaX"
104306 +
104307 +config PAX
104308 + bool "Enable various PaX features"
104309 + default y if GRKERNSEC_CONFIG_AUTO
104310 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
104311 + help
104312 + This allows you to enable various PaX features. PaX adds
104313 + intrusion prevention mechanisms to the kernel that reduce
104314 + the risks posed by exploitable memory corruption bugs.
104315 +
104316 +menu "PaX Control"
104317 + depends on PAX
104318 +
104319 +config PAX_SOFTMODE
104320 + bool 'Support soft mode'
104321 + help
104322 + Enabling this option will allow you to run PaX in soft mode, that
104323 + is, PaX features will not be enforced by default, only on executables
104324 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
104325 + support as they are the only way to mark executables for soft mode use.
104326 +
104327 + Soft mode can be activated by using the "pax_softmode=1" kernel command
104328 + line option on boot. Furthermore you can control various PaX features
104329 + at runtime via the entries in /proc/sys/kernel/pax.
104330 +
104331 +config PAX_EI_PAX
104332 + bool 'Use legacy ELF header marking'
104333 + default y if GRKERNSEC_CONFIG_AUTO
104334 + help
104335 + Enabling this option will allow you to control PaX features on
104336 + a per executable basis via the 'chpax' utility available at
104337 + http://pax.grsecurity.net/. The control flags will be read from
104338 + an otherwise reserved part of the ELF header. This marking has
104339 + numerous drawbacks (no support for soft-mode, toolchain does not
104340 + know about the non-standard use of the ELF header) therefore it
104341 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
104342 + support.
104343 +
104344 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
104345 + support as well, they will override the legacy EI_PAX marks.
104346 +
104347 + If you enable none of the marking options then all applications
104348 + will run with PaX enabled on them by default.
104349 +
104350 +config PAX_PT_PAX_FLAGS
104351 + bool 'Use ELF program header marking'
104352 + default y if GRKERNSEC_CONFIG_AUTO
104353 + help
104354 + Enabling this option will allow you to control PaX features on
104355 + a per executable basis via the 'paxctl' utility available at
104356 + http://pax.grsecurity.net/. The control flags will be read from
104357 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
104358 + has the benefits of supporting both soft mode and being fully
104359 + integrated into the toolchain (the binutils patch is available
104360 + from http://pax.grsecurity.net).
104361 +
104362 + Note that if you enable the legacy EI_PAX marking support as well,
104363 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
104364 +
104365 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
104366 + must make sure that the marks are the same if a binary has both marks.
104367 +
104368 + If you enable none of the marking options then all applications
104369 + will run with PaX enabled on them by default.
104370 +
104371 +config PAX_XATTR_PAX_FLAGS
104372 + bool 'Use filesystem extended attributes marking'
104373 + default y if GRKERNSEC_CONFIG_AUTO
104374 + select CIFS_XATTR if CIFS
104375 + select EXT2_FS_XATTR if EXT2_FS
104376 + select EXT3_FS_XATTR if EXT3_FS
104377 + select JFFS2_FS_XATTR if JFFS2_FS
104378 + select REISERFS_FS_XATTR if REISERFS_FS
104379 + select SQUASHFS_XATTR if SQUASHFS
104380 + select TMPFS_XATTR if TMPFS
104381 + select UBIFS_FS_XATTR if UBIFS_FS
104382 + help
104383 + Enabling this option will allow you to control PaX features on
104384 + a per executable basis via the 'setfattr' utility. The control
104385 + flags will be read from the user.pax.flags extended attribute of
104386 + the file. This marking has the benefit of supporting binary-only
104387 + applications that self-check themselves (e.g., skype) and would
104388 + not tolerate chpax/paxctl changes. The main drawback is that
104389 + extended attributes are not supported by some filesystems (e.g.,
104390 + isofs, udf, vfat) so copying files through such filesystems will
104391 + lose the extended attributes and these PaX markings.
104392 +
104393 + Note that if you enable the legacy EI_PAX marking support as well,
104394 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
104395 +
104396 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
104397 + must make sure that the marks are the same if a binary has both marks.
104398 +
104399 + If you enable none of the marking options then all applications
104400 + will run with PaX enabled on them by default.
104401 +
104402 +choice
104403 + prompt 'MAC system integration'
104404 + default PAX_HAVE_ACL_FLAGS
104405 + help
104406 + Mandatory Access Control systems have the option of controlling
104407 + PaX flags on a per executable basis, choose the method supported
104408 + by your particular system.
104409 +
104410 + - "none": if your MAC system does not interact with PaX,
104411 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
104412 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
104413 +
104414 + NOTE: this option is for developers/integrators only.
104415 +
104416 + config PAX_NO_ACL_FLAGS
104417 + bool 'none'
104418 +
104419 + config PAX_HAVE_ACL_FLAGS
104420 + bool 'direct'
104421 +
104422 + config PAX_HOOK_ACL_FLAGS
104423 + bool 'hook'
104424 +endchoice
104425 +
104426 +endmenu
104427 +
104428 +menu "Non-executable pages"
104429 + depends on PAX
104430 +
104431 +config PAX_NOEXEC
104432 + bool "Enforce non-executable pages"
104433 + default y if GRKERNSEC_CONFIG_AUTO
104434 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
104435 + help
104436 + By design some architectures do not allow for protecting memory
104437 + pages against execution or even if they do, Linux does not make
104438 + use of this feature. In practice this means that if a page is
104439 + readable (such as the stack or heap) it is also executable.
104440 +
104441 + There is a well known exploit technique that makes use of this
104442 + fact and a common programming mistake where an attacker can
104443 + introduce code of his choice somewhere in the attacked program's
104444 + memory (typically the stack or the heap) and then execute it.
104445 +
104446 + If the attacked program was running with different (typically
104447 + higher) privileges than that of the attacker, then he can elevate
104448 + his own privilege level (e.g. get a root shell, write to files for
104449 + which he does not have write access to, etc).
104450 +
104451 + Enabling this option will let you choose from various features
104452 + that prevent the injection and execution of 'foreign' code in
104453 + a program.
104454 +
104455 + This will also break programs that rely on the old behaviour and
104456 + expect that dynamically allocated memory via the malloc() family
104457 + of functions is executable (which it is not). Notable examples
104458 + are the XFree86 4.x server, the java runtime and wine.
104459 +
104460 +config PAX_PAGEEXEC
104461 + bool "Paging based non-executable pages"
104462 + default y if GRKERNSEC_CONFIG_AUTO
104463 + 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)
104464 + select ARCH_TRACK_EXEC_LIMIT if X86_32
104465 + help
104466 + This implementation is based on the paging feature of the CPU.
104467 + On i386 without hardware non-executable bit support there is a
104468 + variable but usually low performance impact, however on Intel's
104469 + P4 core based CPUs it is very high so you should not enable this
104470 + for kernels meant to be used on such CPUs.
104471 +
104472 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
104473 + with hardware non-executable bit support there is no performance
104474 + impact, on ppc the impact is negligible.
104475 +
104476 + Note that several architectures require various emulations due to
104477 + badly designed userland ABIs, this will cause a performance impact
104478 + but will disappear as soon as userland is fixed. For example, ppc
104479 + userland MUST have been built with secure-plt by a recent toolchain.
104480 +
104481 +config PAX_SEGMEXEC
104482 + bool "Segmentation based non-executable pages"
104483 + default y if GRKERNSEC_CONFIG_AUTO
104484 + depends on PAX_NOEXEC && X86_32
104485 + help
104486 + This implementation is based on the segmentation feature of the
104487 + CPU and has a very small performance impact, however applications
104488 + will be limited to a 1.5 GB address space instead of the normal
104489 + 3 GB.
104490 +
104491 +config PAX_EMUTRAMP
104492 + bool "Emulate trampolines"
104493 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
104494 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
104495 + help
104496 + There are some programs and libraries that for one reason or
104497 + another attempt to execute special small code snippets from
104498 + non-executable memory pages. Most notable examples are the
104499 + signal handler return code generated by the kernel itself and
104500 + the GCC trampolines.
104501 +
104502 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
104503 + such programs will no longer work under your kernel.
104504 +
104505 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
104506 + utilities to enable trampoline emulation for the affected programs
104507 + yet still have the protection provided by the non-executable pages.
104508 +
104509 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
104510 + your system will not even boot.
104511 +
104512 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
104513 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
104514 + for the affected files.
104515 +
104516 + NOTE: enabling this feature *may* open up a loophole in the
104517 + protection provided by non-executable pages that an attacker
104518 + could abuse. Therefore the best solution is to not have any
104519 + files on your system that would require this option. This can
104520 + be achieved by not using libc5 (which relies on the kernel
104521 + signal handler return code) and not using or rewriting programs
104522 + that make use of the nested function implementation of GCC.
104523 + Skilled users can just fix GCC itself so that it implements
104524 + nested function calls in a way that does not interfere with PaX.
104525 +
104526 +config PAX_EMUSIGRT
104527 + bool "Automatically emulate sigreturn trampolines"
104528 + depends on PAX_EMUTRAMP && PARISC
104529 + default y
104530 + help
104531 + Enabling this option will have the kernel automatically detect
104532 + and emulate signal return trampolines executing on the stack
104533 + that would otherwise lead to task termination.
104534 +
104535 + This solution is intended as a temporary one for users with
104536 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
104537 + Modula-3 runtime, etc) or executables linked to such, basically
104538 + everything that does not specify its own SA_RESTORER function in
104539 + normal executable memory like glibc 2.1+ does.
104540 +
104541 + On parisc you MUST enable this option, otherwise your system will
104542 + not even boot.
104543 +
104544 + NOTE: this feature cannot be disabled on a per executable basis
104545 + and since it *does* open up a loophole in the protection provided
104546 + by non-executable pages, the best solution is to not have any
104547 + files on your system that would require this option.
104548 +
104549 +config PAX_MPROTECT
104550 + bool "Restrict mprotect()"
104551 + default y if GRKERNSEC_CONFIG_AUTO
104552 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
104553 + help
104554 + Enabling this option will prevent programs from
104555 + - changing the executable status of memory pages that were
104556 + not originally created as executable,
104557 + - making read-only executable pages writable again,
104558 + - creating executable pages from anonymous memory,
104559 + - making read-only-after-relocations (RELRO) data pages writable again.
104560 +
104561 + You should say Y here to complete the protection provided by
104562 + the enforcement of non-executable pages.
104563 +
104564 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
104565 + this feature on a per file basis.
104566 +
104567 +config PAX_MPROTECT_COMPAT
104568 + bool "Use legacy/compat protection demoting (read help)"
104569 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
104570 + depends on PAX_MPROTECT
104571 + help
104572 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
104573 + by sending the proper error code to the application. For some broken
104574 + userland, this can cause problems with Python or other applications. The
104575 + current implementation however allows for applications like clamav to
104576 + detect if JIT compilation/execution is allowed and to fall back gracefully
104577 + to an interpreter-based mode if it does not. While we encourage everyone
104578 + to use the current implementation as-is and push upstream to fix broken
104579 + userland (note that the RWX logging option can assist with this), in some
104580 + environments this may not be possible. Having to disable MPROTECT
104581 + completely on certain binaries reduces the security benefit of PaX,
104582 + so this option is provided for those environments to revert to the old
104583 + behavior.
104584 +
104585 +config PAX_ELFRELOCS
104586 + bool "Allow ELF text relocations (read help)"
104587 + depends on PAX_MPROTECT
104588 + default n
104589 + help
104590 + Non-executable pages and mprotect() restrictions are effective
104591 + in preventing the introduction of new executable code into an
104592 + attacked task's address space. There remain only two venues
104593 + for this kind of attack: if the attacker can execute already
104594 + existing code in the attacked task then he can either have it
104595 + create and mmap() a file containing his code or have it mmap()
104596 + an already existing ELF library that does not have position
104597 + independent code in it and use mprotect() on it to make it
104598 + writable and copy his code there. While protecting against
104599 + the former approach is beyond PaX, the latter can be prevented
104600 + by having only PIC ELF libraries on one's system (which do not
104601 + need to relocate their code). If you are sure this is your case,
104602 + as is the case with all modern Linux distributions, then leave
104603 + this option disabled. You should say 'n' here.
104604 +
104605 +config PAX_ETEXECRELOCS
104606 + bool "Allow ELF ET_EXEC text relocations"
104607 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
104608 + select PAX_ELFRELOCS
104609 + default y
104610 + help
104611 + On some architectures there are incorrectly created applications
104612 + that require text relocations and would not work without enabling
104613 + this option. If you are an alpha, ia64 or parisc user, you should
104614 + enable this option and disable it once you have made sure that
104615 + none of your applications need it.
104616 +
104617 +config PAX_EMUPLT
104618 + bool "Automatically emulate ELF PLT"
104619 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
104620 + default y
104621 + help
104622 + Enabling this option will have the kernel automatically detect
104623 + and emulate the Procedure Linkage Table entries in ELF files.
104624 + On some architectures such entries are in writable memory, and
104625 + become non-executable leading to task termination. Therefore
104626 + it is mandatory that you enable this option on alpha, parisc,
104627 + sparc and sparc64, otherwise your system would not even boot.
104628 +
104629 + NOTE: this feature *does* open up a loophole in the protection
104630 + provided by the non-executable pages, therefore the proper
104631 + solution is to modify the toolchain to produce a PLT that does
104632 + not need to be writable.
104633 +
104634 +config PAX_DLRESOLVE
104635 + bool 'Emulate old glibc resolver stub'
104636 + depends on PAX_EMUPLT && SPARC
104637 + default n
104638 + help
104639 + This option is needed if userland has an old glibc (before 2.4)
104640 + that puts a 'save' instruction into the runtime generated resolver
104641 + stub that needs special emulation.
104642 +
104643 +config PAX_KERNEXEC
104644 + bool "Enforce non-executable kernel pages"
104645 + 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))
104646 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
104647 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
104648 + select PAX_KERNEXEC_PLUGIN if X86_64
104649 + help
104650 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
104651 + that is, enabling this option will make it harder to inject
104652 + and execute 'foreign' code in kernel memory itself.
104653 +
104654 +choice
104655 + prompt "Return Address Instrumentation Method"
104656 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
104657 + depends on PAX_KERNEXEC_PLUGIN
104658 + help
104659 + Select the method used to instrument function pointer dereferences.
104660 + Note that binary modules cannot be instrumented by this approach.
104661 +
104662 + Note that the implementation requires a gcc with plugin support,
104663 + i.e., gcc 4.5 or newer. You may need to install the supporting
104664 + headers explicitly in addition to the normal gcc package.
104665 +
104666 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
104667 + bool "bts"
104668 + help
104669 + This method is compatible with binary only modules but has
104670 + a higher runtime overhead.
104671 +
104672 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
104673 + bool "or"
104674 + depends on !PARAVIRT
104675 + help
104676 + This method is incompatible with binary only modules but has
104677 + a lower runtime overhead.
104678 +endchoice
104679 +
104680 +config PAX_KERNEXEC_PLUGIN_METHOD
104681 + string
104682 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
104683 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
104684 + default ""
104685 +
104686 +config PAX_KERNEXEC_MODULE_TEXT
104687 + int "Minimum amount of memory reserved for module code"
104688 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
104689 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
104690 + depends on PAX_KERNEXEC && X86_32
104691 + help
104692 + Due to implementation details the kernel must reserve a fixed
104693 + amount of memory for runtime allocated code (such as modules)
104694 + at compile time that cannot be changed at runtime. Here you
104695 + can specify the minimum amount in MB that will be reserved.
104696 + Due to the same implementation details this size will always
104697 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
104698 + the actually available memory for runtime allocated code will
104699 + usually be more than this minimum.
104700 +
104701 + The default 4 MB should be enough for most users but if you have
104702 + an excessive number of modules (e.g., most distribution configs
104703 + compile many drivers as modules) or use huge modules such as
104704 + nvidia's kernel driver, you will need to adjust this amount.
104705 + A good rule of thumb is to look at your currently loaded kernel
104706 + modules and add up their sizes.
104707 +
104708 +endmenu
104709 +
104710 +menu "Address Space Layout Randomization"
104711 + depends on PAX
104712 +
104713 +config PAX_ASLR
104714 + bool "Address Space Layout Randomization"
104715 + default y if GRKERNSEC_CONFIG_AUTO
104716 + help
104717 + Many if not most exploit techniques rely on the knowledge of
104718 + certain addresses in the attacked program. The following options
104719 + will allow the kernel to apply a certain amount of randomization
104720 + to specific parts of the program thereby forcing an attacker to
104721 + guess them in most cases. Any failed guess will most likely crash
104722 + the attacked program which allows the kernel to detect such attempts
104723 + and react on them. PaX itself provides no reaction mechanisms,
104724 + instead it is strongly encouraged that you make use of Nergal's
104725 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
104726 + (http://www.grsecurity.net/) built-in crash detection features or
104727 + develop one yourself.
104728 +
104729 + By saying Y here you can choose to randomize the following areas:
104730 + - top of the task's kernel stack
104731 + - top of the task's userland stack
104732 + - base address for mmap() requests that do not specify one
104733 + (this includes all libraries)
104734 + - base address of the main executable
104735 +
104736 + It is strongly recommended to say Y here as address space layout
104737 + randomization has negligible impact on performance yet it provides
104738 + a very effective protection.
104739 +
104740 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
104741 + this feature on a per file basis.
104742 +
104743 +config PAX_RANDKSTACK
104744 + bool "Randomize kernel stack base"
104745 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
104746 + depends on X86_TSC && X86
104747 + help
104748 + By saying Y here the kernel will randomize every task's kernel
104749 + stack on every system call. This will not only force an attacker
104750 + to guess it but also prevent him from making use of possible
104751 + leaked information about it.
104752 +
104753 + Since the kernel stack is a rather scarce resource, randomization
104754 + may cause unexpected stack overflows, therefore you should very
104755 + carefully test your system. Note that once enabled in the kernel
104756 + configuration, this feature cannot be disabled on a per file basis.
104757 +
104758 +config PAX_RANDUSTACK
104759 + bool "Randomize user stack base"
104760 + default y if GRKERNSEC_CONFIG_AUTO
104761 + depends on PAX_ASLR
104762 + help
104763 + By saying Y here the kernel will randomize every task's userland
104764 + stack. The randomization is done in two steps where the second
104765 + one may apply a big amount of shift to the top of the stack and
104766 + cause problems for programs that want to use lots of memory (more
104767 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
104768 + For this reason the second step can be controlled by 'chpax' or
104769 + 'paxctl' on a per file basis.
104770 +
104771 +config PAX_RANDMMAP
104772 + bool "Randomize mmap() base"
104773 + default y if GRKERNSEC_CONFIG_AUTO
104774 + depends on PAX_ASLR
104775 + help
104776 + By saying Y here the kernel will use a randomized base address for
104777 + mmap() requests that do not specify one themselves. As a result
104778 + all dynamically loaded libraries will appear at random addresses
104779 + and therefore be harder to exploit by a technique where an attacker
104780 + attempts to execute library code for his purposes (e.g. spawn a
104781 + shell from an exploited program that is running at an elevated
104782 + privilege level).
104783 +
104784 + Furthermore, if a program is relinked as a dynamic ELF file, its
104785 + base address will be randomized as well, completing the full
104786 + randomization of the address space layout. Attacking such programs
104787 + becomes a guess game. You can find an example of doing this at
104788 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
104789 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
104790 +
104791 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
104792 + feature on a per file basis.
104793 +
104794 +endmenu
104795 +
104796 +menu "Miscellaneous hardening features"
104797 +
104798 +config PAX_MEMORY_SANITIZE
104799 + bool "Sanitize all freed memory"
104800 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
104801 + help
104802 + By saying Y here the kernel will erase memory pages and slab objects
104803 + as soon as they are freed. This in turn reduces the lifetime of data
104804 + stored in them, making it less likely that sensitive information such
104805 + as passwords, cryptographic secrets, etc stay in memory for too long.
104806 +
104807 + This is especially useful for programs whose runtime is short, long
104808 + lived processes and the kernel itself benefit from this as long as
104809 + they ensure timely freeing of memory that may hold sensitive
104810 + information.
104811 +
104812 + A nice side effect of the sanitization of slab objects is the
104813 + reduction of possible info leaks caused by padding bytes within the
104814 + leaky structures. Use-after-free bugs for structures containing
104815 + pointers can also be detected as dereferencing the sanitized pointer
104816 + will generate an access violation.
104817 +
104818 + The tradeoff is performance impact, on a single CPU system kernel
104819 + compilation sees a 3% slowdown, other systems and workloads may vary
104820 + and you are advised to test this feature on your expected workload
104821 + before deploying it.
104822 +
104823 + To reduce the performance penalty by sanitizing pages only, albeit
104824 + limiting the effectiveness of this feature at the same time, slab
104825 + sanitization can be disabled with the kernel commandline parameter
104826 + "pax_sanitize_slab=0".
104827 +
104828 + Note that this feature does not protect data stored in live pages,
104829 + e.g., process memory swapped to disk may stay there for a long time.
104830 +
104831 +config PAX_MEMORY_STACKLEAK
104832 + bool "Sanitize kernel stack"
104833 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
104834 + depends on X86
104835 + help
104836 + By saying Y here the kernel will erase the kernel stack before it
104837 + returns from a system call. This in turn reduces the information
104838 + that a kernel stack leak bug can reveal.
104839 +
104840 + Note that such a bug can still leak information that was put on
104841 + the stack by the current system call (the one eventually triggering
104842 + the bug) but traces of earlier system calls on the kernel stack
104843 + cannot leak anymore.
104844 +
104845 + The tradeoff is performance impact: on a single CPU system kernel
104846 + compilation sees a 1% slowdown, other systems and workloads may vary
104847 + and you are advised to test this feature on your expected workload
104848 + before deploying it.
104849 +
104850 + Note that the full feature requires a gcc with plugin support,
104851 + i.e., gcc 4.5 or newer. You may need to install the supporting
104852 + headers explicitly in addition to the normal gcc package. Using
104853 + older gcc versions means that functions with large enough stack
104854 + frames may leave uninitialized memory behind that may be exposed
104855 + to a later syscall leaking the stack.
104856 +
104857 +config PAX_MEMORY_STRUCTLEAK
104858 + bool "Forcibly initialize local variables copied to userland"
104859 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
104860 + help
104861 + By saying Y here the kernel will zero initialize some local
104862 + variables that are going to be copied to userland. This in
104863 + turn prevents unintended information leakage from the kernel
104864 + stack should later code forget to explicitly set all parts of
104865 + the copied variable.
104866 +
104867 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
104868 + at a much smaller coverage.
104869 +
104870 + Note that the implementation requires a gcc with plugin support,
104871 + i.e., gcc 4.5 or newer. You may need to install the supporting
104872 + headers explicitly in addition to the normal gcc package.
104873 +
104874 +config PAX_MEMORY_UDEREF
104875 + bool "Prevent invalid userland pointer dereference"
104876 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
104877 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
104878 + select PAX_PER_CPU_PGD if X86_64
104879 + help
104880 + By saying Y here the kernel will be prevented from dereferencing
104881 + userland pointers in contexts where the kernel expects only kernel
104882 + pointers. This is both a useful runtime debugging feature and a
104883 + security measure that prevents exploiting a class of kernel bugs.
104884 +
104885 + The tradeoff is that some virtualization solutions may experience
104886 + a huge slowdown and therefore you should not enable this feature
104887 + for kernels meant to run in such environments. Whether a given VM
104888 + solution is affected or not is best determined by simply trying it
104889 + out, the performance impact will be obvious right on boot as this
104890 + mechanism engages from very early on. A good rule of thumb is that
104891 + VMs running on CPUs without hardware virtualization support (i.e.,
104892 + the majority of IA-32 CPUs) will likely experience the slowdown.
104893 +
104894 + On X86_64 the kernel will make use of PCID support when available
104895 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
104896 + or performance impact. Pass pax_weakuderef on the kernel command
104897 + line to choose the latter.
104898 +
104899 +config PAX_REFCOUNT
104900 + bool "Prevent various kernel object reference counter overflows"
104901 + default y if GRKERNSEC_CONFIG_AUTO
104902 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
104903 + help
104904 + By saying Y here the kernel will detect and prevent overflowing
104905 + various (but not all) kinds of object reference counters. Such
104906 + overflows can normally occur due to bugs only and are often, if
104907 + not always, exploitable.
104908 +
104909 + The tradeoff is that data structures protected by an overflowed
104910 + refcount will never be freed and therefore will leak memory. Note
104911 + that this leak also happens even without this protection but in
104912 + that case the overflow can eventually trigger the freeing of the
104913 + data structure while it is still being used elsewhere, resulting
104914 + in the exploitable situation that this feature prevents.
104915 +
104916 + Since this has a negligible performance impact, you should enable
104917 + this feature.
104918 +
104919 +config PAX_CONSTIFY_PLUGIN
104920 + bool "Automatically constify eligible structures"
104921 + default y
104922 + depends on !UML && PAX_KERNEXEC
104923 + help
104924 + By saying Y here the compiler will automatically constify a class
104925 + of types that contain only function pointers. This reduces the
104926 + kernel's attack surface and also produces a better memory layout.
104927 +
104928 + Note that the implementation requires a gcc with plugin support,
104929 + i.e., gcc 4.5 or newer. You may need to install the supporting
104930 + headers explicitly in addition to the normal gcc package.
104931 +
104932 + Note that if some code really has to modify constified variables
104933 + then the source code will have to be patched to allow it. Examples
104934 + can be found in PaX itself (the no_const attribute) and for some
104935 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
104936 +
104937 +config PAX_USERCOPY
104938 + bool "Harden heap object copies between kernel and userland"
104939 + default y if GRKERNSEC_CONFIG_AUTO
104940 + depends on ARM || IA64 || PPC || SPARC || X86
104941 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
104942 + select PAX_USERCOPY_SLABS
104943 + help
104944 + By saying Y here the kernel will enforce the size of heap objects
104945 + when they are copied in either direction between the kernel and
104946 + userland, even if only a part of the heap object is copied.
104947 +
104948 + Specifically, this checking prevents information leaking from the
104949 + kernel heap during kernel to userland copies (if the kernel heap
104950 + object is otherwise fully initialized) and prevents kernel heap
104951 + overflows during userland to kernel copies.
104952 +
104953 + Note that the current implementation provides the strictest bounds
104954 + checks for the SLUB allocator.
104955 +
104956 + Enabling this option also enables per-slab cache protection against
104957 + data in a given cache being copied into/out of via userland
104958 + accessors. Though the whitelist of regions will be reduced over
104959 + time, it notably protects important data structures like task structs.
104960 +
104961 + If frame pointers are enabled on x86, this option will also restrict
104962 + copies into and out of the kernel stack to local variables within a
104963 + single frame.
104964 +
104965 + Since this has a negligible performance impact, you should enable
104966 + this feature.
104967 +
104968 +config PAX_USERCOPY_DEBUG
104969 + bool
104970 + depends on X86 && PAX_USERCOPY
104971 + default n
104972 +
104973 +config PAX_SIZE_OVERFLOW
104974 + bool "Prevent various integer overflows in function size parameters"
104975 + default y if GRKERNSEC_CONFIG_AUTO
104976 + depends on X86
104977 + help
104978 + By saying Y here the kernel recomputes expressions of function
104979 + arguments marked by a size_overflow attribute with double integer
104980 + precision (DImode/TImode for 32/64 bit integer types).
104981 +
104982 + The recomputed argument is checked against TYPE_MAX and an event
104983 + is logged on overflow and the triggering process is killed.
104984 +
104985 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
104986 +
104987 + Note that the implementation requires a gcc with plugin support,
104988 + i.e., gcc 4.5 or newer. You may need to install the supporting
104989 + headers explicitly in addition to the normal gcc package.
104990 +
104991 +config PAX_LATENT_ENTROPY
104992 + bool "Generate some entropy during boot and runtime"
104993 + default y if GRKERNSEC_CONFIG_AUTO
104994 + help
104995 + By saying Y here the kernel will instrument some kernel code to
104996 + extract some entropy from both original and artificially created
104997 + program state. This will help especially embedded systems where
104998 + there is little 'natural' source of entropy normally. The cost
104999 + is some slowdown of the boot process and fork and irq processing.
105000 +
105001 + When pax_extra_latent_entropy is passed on the kernel command line,
105002 + entropy will be extracted from up to the first 4GB of RAM while the
105003 + runtime memory allocator is being initialized. This costs even more
105004 + slowdown of the boot process.
105005 +
105006 + Note that the implementation requires a gcc with plugin support,
105007 + i.e., gcc 4.5 or newer. You may need to install the supporting
105008 + headers explicitly in addition to the normal gcc package.
105009 +
105010 + Note that entropy extracted this way is not cryptographically
105011 + secure!
105012 +
105013 +endmenu
105014 +
105015 +endmenu
105016 +
105017 +source grsecurity/Kconfig
105018 +
105019 +endmenu
105020 +
105021 +endmenu
105022 +
105023 source security/keys/Kconfig
105024
105025 config SECURITY_DMESG_RESTRICT
105026 @@ -103,7 +1058,7 @@ config INTEL_TXT
105027 config LSM_MMAP_MIN_ADDR
105028 int "Low address space for LSM to protect from user allocation"
105029 depends on SECURITY && SECURITY_SELINUX
105030 - default 32768 if ARM || (ARM64 && COMPAT)
105031 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
105032 default 65536
105033 help
105034 This is the portion of low virtual memory which should be protected
105035 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
105036 index fdaa50c..2761dcb 100644
105037 --- a/security/apparmor/file.c
105038 +++ b/security/apparmor/file.c
105039 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
105040 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
105041 struct path *new_dir, struct dentry *new_dentry)
105042 {
105043 - struct path link = { new_dir->mnt, new_dentry };
105044 - struct path target = { new_dir->mnt, old_dentry };
105045 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
105046 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
105047 struct path_cond cond = {
105048 old_dentry->d_inode->i_uid,
105049 old_dentry->d_inode->i_mode
105050 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
105051 index 4257b7e..2d0732d 100644
105052 --- a/security/apparmor/lsm.c
105053 +++ b/security/apparmor/lsm.c
105054 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
105055 struct dentry *dentry, u32 mask,
105056 struct path_cond *cond)
105057 {
105058 - struct path path = { dir->mnt, dentry };
105059 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
105060
105061 return common_perm(op, &path, mask, cond);
105062 }
105063 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
105064 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
105065 struct dentry *dentry, u32 mask)
105066 {
105067 - struct path path = { mnt, dentry };
105068 + struct path path = { .mnt = mnt, .dentry = dentry };
105069 struct path_cond cond = { dentry->d_inode->i_uid,
105070 dentry->d_inode->i_mode
105071 };
105072 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
105073
105074 profile = aa_current_profile();
105075 if (!unconfined(profile)) {
105076 - struct path old_path = { old_dir->mnt, old_dentry };
105077 - struct path new_path = { new_dir->mnt, new_dentry };
105078 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
105079 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
105080 struct path_cond cond = { old_dentry->d_inode->i_uid,
105081 old_dentry->d_inode->i_mode
105082 };
105083 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
105084 return error;
105085 }
105086
105087 -static struct security_operations apparmor_ops = {
105088 +static struct security_operations apparmor_ops __read_only = {
105089 .name = "apparmor",
105090
105091 .ptrace_access_check = apparmor_ptrace_access_check,
105092 diff --git a/security/commoncap.c b/security/commoncap.c
105093 index b9d613e..f68305c 100644
105094 --- a/security/commoncap.c
105095 +++ b/security/commoncap.c
105096 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
105097 return 0;
105098 }
105099
105100 +/* returns:
105101 + 1 for suid privilege
105102 + 2 for sgid privilege
105103 + 3 for fscap privilege
105104 +*/
105105 +int is_privileged_binary(const struct dentry *dentry)
105106 +{
105107 + struct cpu_vfs_cap_data capdata;
105108 + struct inode *inode = dentry->d_inode;
105109 +
105110 + if (!inode || S_ISDIR(inode->i_mode))
105111 + return 0;
105112 +
105113 + if (inode->i_mode & S_ISUID)
105114 + return 1;
105115 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
105116 + return 2;
105117 +
105118 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
105119 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
105120 + return 3;
105121 + }
105122 +
105123 + return 0;
105124 +}
105125 +
105126 /*
105127 * Attempt to get the on-exec apply capability sets for an executable file from
105128 * its xattrs and, if present, apply them to the proposed credentials being
105129 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
105130 const struct cred *cred = current_cred();
105131 kuid_t root_uid = make_kuid(cred->user_ns, 0);
105132
105133 + if (gr_acl_enable_at_secure())
105134 + return 1;
105135 +
105136 if (!uid_eq(cred->uid, root_uid)) {
105137 if (bprm->cap_effective)
105138 return 1;
105139 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
105140 index f79fa8b..6161868 100644
105141 --- a/security/integrity/ima/ima.h
105142 +++ b/security/integrity/ima/ima.h
105143 @@ -118,8 +118,8 @@ int ima_init_template(void);
105144 extern spinlock_t ima_queue_lock;
105145
105146 struct ima_h_table {
105147 - atomic_long_t len; /* number of stored measurements in the list */
105148 - atomic_long_t violations;
105149 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
105150 + atomic_long_unchecked_t violations;
105151 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
105152 };
105153 extern struct ima_h_table ima_htable;
105154 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
105155 index c38bbce..f45133d 100644
105156 --- a/security/integrity/ima/ima_api.c
105157 +++ b/security/integrity/ima/ima_api.c
105158 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
105159 int result;
105160
105161 /* can overflow, only indicator */
105162 - atomic_long_inc(&ima_htable.violations);
105163 + atomic_long_inc_unchecked(&ima_htable.violations);
105164
105165 result = ima_alloc_init_template(NULL, file, filename,
105166 NULL, 0, &entry);
105167 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
105168 index 468a3ba..9af5cae 100644
105169 --- a/security/integrity/ima/ima_fs.c
105170 +++ b/security/integrity/ima/ima_fs.c
105171 @@ -28,12 +28,12 @@
105172 static int valid_policy = 1;
105173 #define TMPBUFLEN 12
105174 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
105175 - loff_t *ppos, atomic_long_t *val)
105176 + loff_t *ppos, atomic_long_unchecked_t *val)
105177 {
105178 char tmpbuf[TMPBUFLEN];
105179 ssize_t len;
105180
105181 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
105182 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
105183 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
105184 }
105185
105186 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
105187 index d85e997..6992813 100644
105188 --- a/security/integrity/ima/ima_queue.c
105189 +++ b/security/integrity/ima/ima_queue.c
105190 @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
105191 INIT_LIST_HEAD(&qe->later);
105192 list_add_tail_rcu(&qe->later, &ima_measurements);
105193
105194 - atomic_long_inc(&ima_htable.len);
105195 + atomic_long_inc_unchecked(&ima_htable.len);
105196 key = ima_hash_key(entry->digest);
105197 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
105198 return 0;
105199 diff --git a/security/keys/compat.c b/security/keys/compat.c
105200 index bbd32c7..c60c927 100644
105201 --- a/security/keys/compat.c
105202 +++ b/security/keys/compat.c
105203 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
105204 if (ret == 0)
105205 goto no_payload_free;
105206
105207 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
105208 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
105209 err:
105210 if (iov != iovstack)
105211 kfree(iov);
105212 diff --git a/security/keys/internal.h b/security/keys/internal.h
105213 index 80b2aac..bb7ee65 100644
105214 --- a/security/keys/internal.h
105215 +++ b/security/keys/internal.h
105216 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
105217 extern long keyctl_invalidate_key(key_serial_t);
105218
105219 extern long keyctl_instantiate_key_common(key_serial_t,
105220 - const struct iovec *,
105221 + const struct iovec __user *,
105222 unsigned, size_t, key_serial_t);
105223 #ifdef CONFIG_PERSISTENT_KEYRINGS
105224 extern long keyctl_get_persistent(uid_t, key_serial_t);
105225 diff --git a/security/keys/key.c b/security/keys/key.c
105226 index 6e21c11..9ed67ca 100644
105227 --- a/security/keys/key.c
105228 +++ b/security/keys/key.c
105229 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
105230
105231 atomic_set(&key->usage, 1);
105232 init_rwsem(&key->sem);
105233 - lockdep_set_class(&key->sem, &type->lock_class);
105234 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
105235 key->index_key.type = type;
105236 key->user = user;
105237 key->quotalen = quotalen;
105238 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
105239 struct key_type *p;
105240 int ret;
105241
105242 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
105243 + pax_open_kernel();
105244 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
105245 + pax_close_kernel();
105246
105247 ret = -EEXIST;
105248 down_write(&key_types_sem);
105249 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
105250 }
105251
105252 /* store the type */
105253 - list_add(&ktype->link, &key_types_list);
105254 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
105255
105256 pr_notice("Key type %s registered\n", ktype->name);
105257 ret = 0;
105258 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
105259 void unregister_key_type(struct key_type *ktype)
105260 {
105261 down_write(&key_types_sem);
105262 - list_del_init(&ktype->link);
105263 + pax_list_del_init((struct list_head *)&ktype->link);
105264 downgrade_write(&key_types_sem);
105265 key_gc_keytype(ktype);
105266 pr_notice("Key type %s unregistered\n", ktype->name);
105267 @@ -1088,10 +1090,10 @@ void __init key_init(void)
105268 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
105269
105270 /* add the special key types */
105271 - list_add_tail(&key_type_keyring.link, &key_types_list);
105272 - list_add_tail(&key_type_dead.link, &key_types_list);
105273 - list_add_tail(&key_type_user.link, &key_types_list);
105274 - list_add_tail(&key_type_logon.link, &key_types_list);
105275 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
105276 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
105277 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
105278 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
105279
105280 /* record the root user tracking */
105281 rb_link_node(&root_key_user.node,
105282 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
105283 index cee72ce..e46074a 100644
105284 --- a/security/keys/keyctl.c
105285 +++ b/security/keys/keyctl.c
105286 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
105287 /*
105288 * Copy the iovec data from userspace
105289 */
105290 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
105291 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
105292 unsigned ioc)
105293 {
105294 for (; ioc > 0; ioc--) {
105295 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
105296 * If successful, 0 will be returned.
105297 */
105298 long keyctl_instantiate_key_common(key_serial_t id,
105299 - const struct iovec *payload_iov,
105300 + const struct iovec __user *payload_iov,
105301 unsigned ioc,
105302 size_t plen,
105303 key_serial_t ringid)
105304 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
105305 [0].iov_len = plen
105306 };
105307
105308 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
105309 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
105310 }
105311
105312 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
105313 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
105314 if (ret == 0)
105315 goto no_payload_free;
105316
105317 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
105318 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
105319 err:
105320 if (iov != iovstack)
105321 kfree(iov);
105322 diff --git a/security/min_addr.c b/security/min_addr.c
105323 index f728728..6457a0c 100644
105324 --- a/security/min_addr.c
105325 +++ b/security/min_addr.c
105326 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
105327 */
105328 static void update_mmap_min_addr(void)
105329 {
105330 +#ifndef SPARC
105331 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
105332 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
105333 mmap_min_addr = dac_mmap_min_addr;
105334 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
105335 #else
105336 mmap_min_addr = dac_mmap_min_addr;
105337 #endif
105338 +#endif
105339 }
105340
105341 /*
105342 diff --git a/security/security.c b/security/security.c
105343 index 919cad9..2127be1 100644
105344 --- a/security/security.c
105345 +++ b/security/security.c
105346 @@ -33,8 +33,8 @@
105347 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
105348 CONFIG_DEFAULT_SECURITY;
105349
105350 -static struct security_operations *security_ops;
105351 -static struct security_operations default_security_ops = {
105352 +struct security_operations *security_ops __read_only;
105353 +struct security_operations default_security_ops __read_only = {
105354 .name = "default",
105355 };
105356
105357 @@ -73,11 +73,6 @@ int __init security_init(void)
105358 return 0;
105359 }
105360
105361 -void reset_security_ops(void)
105362 -{
105363 - security_ops = &default_security_ops;
105364 -}
105365 -
105366 /* Save user chosen LSM */
105367 static int __init choose_lsm(char *str)
105368 {
105369 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
105370 index fc3e662..7844c60 100644
105371 --- a/security/selinux/avc.c
105372 +++ b/security/selinux/avc.c
105373 @@ -59,7 +59,7 @@ struct avc_node {
105374 struct avc_cache {
105375 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
105376 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
105377 - atomic_t lru_hint; /* LRU hint for reclaim scan */
105378 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
105379 atomic_t active_nodes;
105380 u32 latest_notif; /* latest revocation notification */
105381 };
105382 @@ -167,7 +167,7 @@ void __init avc_init(void)
105383 spin_lock_init(&avc_cache.slots_lock[i]);
105384 }
105385 atomic_set(&avc_cache.active_nodes, 0);
105386 - atomic_set(&avc_cache.lru_hint, 0);
105387 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
105388
105389 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
105390 0, SLAB_PANIC, NULL);
105391 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
105392 spinlock_t *lock;
105393
105394 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
105395 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
105396 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
105397 head = &avc_cache.slots[hvalue];
105398 lock = &avc_cache.slots_lock[hvalue];
105399
105400 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
105401 index e294b86..eda45c55 100644
105402 --- a/security/selinux/hooks.c
105403 +++ b/security/selinux/hooks.c
105404 @@ -95,8 +95,6 @@
105405 #include "audit.h"
105406 #include "avc_ss.h"
105407
105408 -extern struct security_operations *security_ops;
105409 -
105410 /* SECMARK reference count */
105411 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
105412
105413 @@ -5759,7 +5757,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
105414
105415 #endif
105416
105417 -static struct security_operations selinux_ops = {
105418 +static struct security_operations selinux_ops __read_only = {
105419 .name = "selinux",
105420
105421 .ptrace_access_check = selinux_ptrace_access_check,
105422 @@ -6112,6 +6110,9 @@ static void selinux_nf_ip_exit(void)
105423 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
105424 static int selinux_disabled;
105425
105426 +extern struct security_operations *security_ops;
105427 +extern struct security_operations default_security_ops;
105428 +
105429 int selinux_disable(void)
105430 {
105431 if (ss_initialized) {
105432 @@ -6129,7 +6130,9 @@ int selinux_disable(void)
105433 selinux_disabled = 1;
105434 selinux_enabled = 0;
105435
105436 - reset_security_ops();
105437 + pax_open_kernel();
105438 + security_ops = &default_security_ops;
105439 + pax_close_kernel();
105440
105441 /* Try to destroy the avc node cache */
105442 avc_disable();
105443 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
105444 index 9f05847..7933395 100644
105445 --- a/security/selinux/include/xfrm.h
105446 +++ b/security/selinux/include/xfrm.h
105447 @@ -46,7 +46,7 @@ static inline void selinux_xfrm_notify_policyload(void)
105448 {
105449 struct net *net;
105450
105451 - atomic_inc(&flow_cache_genid);
105452 + atomic_inc_unchecked(&flow_cache_genid);
105453 rtnl_lock();
105454 for_each_net(net)
105455 rt_genid_bump_all(net);
105456 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
105457 index 14f52be..7352368 100644
105458 --- a/security/smack/smack_lsm.c
105459 +++ b/security/smack/smack_lsm.c
105460 @@ -3726,7 +3726,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
105461 return 0;
105462 }
105463
105464 -struct security_operations smack_ops = {
105465 +struct security_operations smack_ops __read_only = {
105466 .name = "smack",
105467
105468 .ptrace_access_check = smack_ptrace_access_check,
105469 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
105470 index 4003907..13a2b55 100644
105471 --- a/security/tomoyo/file.c
105472 +++ b/security/tomoyo/file.c
105473 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
105474 {
105475 struct tomoyo_request_info r;
105476 struct tomoyo_obj_info obj = {
105477 - .path1 = *path,
105478 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
105479 };
105480 int error = -ENOMEM;
105481 struct tomoyo_path_info buf;
105482 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
105483 struct tomoyo_path_info buf;
105484 struct tomoyo_request_info r;
105485 struct tomoyo_obj_info obj = {
105486 - .path1 = *path,
105487 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
105488 };
105489 int idx;
105490
105491 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
105492 {
105493 struct tomoyo_request_info r;
105494 struct tomoyo_obj_info obj = {
105495 - .path1 = *path,
105496 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
105497 };
105498 int error;
105499 struct tomoyo_path_info buf;
105500 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
105501 {
105502 struct tomoyo_request_info r;
105503 struct tomoyo_obj_info obj = {
105504 - .path1 = *path,
105505 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
105506 };
105507 int error = -ENOMEM;
105508 struct tomoyo_path_info buf;
105509 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
105510 struct tomoyo_path_info buf2;
105511 struct tomoyo_request_info r;
105512 struct tomoyo_obj_info obj = {
105513 - .path1 = *path1,
105514 - .path2 = *path2,
105515 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
105516 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
105517 };
105518 int idx;
105519
105520 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
105521 index 390c646..f2f8db3 100644
105522 --- a/security/tomoyo/mount.c
105523 +++ b/security/tomoyo/mount.c
105524 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
105525 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
105526 need_dev = -1; /* dev_name is a directory */
105527 } else {
105528 + if (!capable(CAP_SYS_ADMIN)) {
105529 + error = -EPERM;
105530 + goto out;
105531 + }
105532 fstype = get_fs_type(type);
105533 if (!fstype) {
105534 error = -ENODEV;
105535 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
105536 index f0b756e..8aa497b 100644
105537 --- a/security/tomoyo/tomoyo.c
105538 +++ b/security/tomoyo/tomoyo.c
105539 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
105540 */
105541 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
105542 {
105543 - struct path path = { mnt, dentry };
105544 + struct path path = { .mnt = mnt, .dentry = dentry };
105545 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
105546 }
105547
105548 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
105549 */
105550 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
105551 {
105552 - struct path path = { parent->mnt, dentry };
105553 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
105554 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
105555 }
105556
105557 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
105558 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
105559 umode_t mode)
105560 {
105561 - struct path path = { parent->mnt, dentry };
105562 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
105563 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
105564 mode & S_IALLUGO);
105565 }
105566 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
105567 */
105568 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
105569 {
105570 - struct path path = { parent->mnt, dentry };
105571 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
105572 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
105573 }
105574
105575 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
105576 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
105577 const char *old_name)
105578 {
105579 - struct path path = { parent->mnt, dentry };
105580 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
105581 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
105582 }
105583
105584 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
105585 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
105586 umode_t mode, unsigned int dev)
105587 {
105588 - struct path path = { parent->mnt, dentry };
105589 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
105590 int type = TOMOYO_TYPE_CREATE;
105591 const unsigned int perm = mode & S_IALLUGO;
105592
105593 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
105594 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
105595 struct dentry *new_dentry)
105596 {
105597 - struct path path1 = { new_dir->mnt, old_dentry };
105598 - struct path path2 = { new_dir->mnt, new_dentry };
105599 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
105600 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
105601 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
105602 }
105603
105604 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
105605 struct path *new_parent,
105606 struct dentry *new_dentry)
105607 {
105608 - struct path path1 = { old_parent->mnt, old_dentry };
105609 - struct path path2 = { new_parent->mnt, new_dentry };
105610 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
105611 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
105612 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
105613 }
105614
105615 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
105616 */
105617 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
105618 {
105619 - struct path path = { mnt, mnt->mnt_root };
105620 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
105621 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
105622 }
105623
105624 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
105625 * tomoyo_security_ops is a "struct security_operations" which is used for
105626 * registering TOMOYO.
105627 */
105628 -static struct security_operations tomoyo_security_ops = {
105629 +static struct security_operations tomoyo_security_ops __read_only = {
105630 .name = "tomoyo",
105631 .cred_alloc_blank = tomoyo_cred_alloc_blank,
105632 .cred_prepare = tomoyo_cred_prepare,
105633 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
105634 index 20ef514..4182bed 100644
105635 --- a/security/yama/Kconfig
105636 +++ b/security/yama/Kconfig
105637 @@ -1,6 +1,6 @@
105638 config SECURITY_YAMA
105639 bool "Yama support"
105640 - depends on SECURITY
105641 + depends on SECURITY && !GRKERNSEC
105642 select SECURITYFS
105643 select SECURITY_PATH
105644 default n
105645 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
105646 index 13c88fbc..f8c115e 100644
105647 --- a/security/yama/yama_lsm.c
105648 +++ b/security/yama/yama_lsm.c
105649 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
105650 }
105651
105652 #ifndef CONFIG_SECURITY_YAMA_STACKED
105653 -static struct security_operations yama_ops = {
105654 +static struct security_operations yama_ops __read_only = {
105655 .name = "yama",
105656
105657 .ptrace_access_check = yama_ptrace_access_check,
105658 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
105659 #endif
105660
105661 #ifdef CONFIG_SYSCTL
105662 +static int zero __read_only;
105663 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
105664 +
105665 static int yama_dointvec_minmax(struct ctl_table *table, int write,
105666 void __user *buffer, size_t *lenp, loff_t *ppos)
105667 {
105668 - int rc;
105669 + ctl_table_no_const yama_table;
105670
105671 if (write && !capable(CAP_SYS_PTRACE))
105672 return -EPERM;
105673
105674 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
105675 - if (rc)
105676 - return rc;
105677 -
105678 + yama_table = *table;
105679 /* Lock the max value if it ever gets set. */
105680 - if (write && *(int *)table->data == *(int *)table->extra2)
105681 - table->extra1 = table->extra2;
105682 -
105683 - return rc;
105684 + if (ptrace_scope == max_scope)
105685 + yama_table.extra1 = &max_scope;
105686 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
105687 }
105688
105689 -static int zero;
105690 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
105691 -
105692 struct ctl_path yama_sysctl_path[] = {
105693 { .procname = "kernel", },
105694 { .procname = "yama", },
105695 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
105696 index 4cedc69..e59d8a3 100644
105697 --- a/sound/aoa/codecs/onyx.c
105698 +++ b/sound/aoa/codecs/onyx.c
105699 @@ -54,7 +54,7 @@ struct onyx {
105700 spdif_locked:1,
105701 analog_locked:1,
105702 original_mute:2;
105703 - int open_count;
105704 + local_t open_count;
105705 struct codec_info *codec_info;
105706
105707 /* mutex serializes concurrent access to the device
105708 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
105709 struct onyx *onyx = cii->codec_data;
105710
105711 mutex_lock(&onyx->mutex);
105712 - onyx->open_count++;
105713 + local_inc(&onyx->open_count);
105714 mutex_unlock(&onyx->mutex);
105715
105716 return 0;
105717 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
105718 struct onyx *onyx = cii->codec_data;
105719
105720 mutex_lock(&onyx->mutex);
105721 - onyx->open_count--;
105722 - if (!onyx->open_count)
105723 + if (local_dec_and_test(&onyx->open_count))
105724 onyx->spdif_locked = onyx->analog_locked = 0;
105725 mutex_unlock(&onyx->mutex);
105726
105727 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
105728 index ffd2025..df062c9 100644
105729 --- a/sound/aoa/codecs/onyx.h
105730 +++ b/sound/aoa/codecs/onyx.h
105731 @@ -11,6 +11,7 @@
105732 #include <linux/i2c.h>
105733 #include <asm/pmac_low_i2c.h>
105734 #include <asm/prom.h>
105735 +#include <asm/local.h>
105736
105737 /* PCM3052 register definitions */
105738
105739 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
105740 index 4c1cc51..16040040 100644
105741 --- a/sound/core/oss/pcm_oss.c
105742 +++ b/sound/core/oss/pcm_oss.c
105743 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
105744 if (in_kernel) {
105745 mm_segment_t fs;
105746 fs = snd_enter_user();
105747 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
105748 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
105749 snd_leave_user(fs);
105750 } else {
105751 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
105752 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
105753 }
105754 if (ret != -EPIPE && ret != -ESTRPIPE)
105755 break;
105756 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
105757 if (in_kernel) {
105758 mm_segment_t fs;
105759 fs = snd_enter_user();
105760 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
105761 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
105762 snd_leave_user(fs);
105763 } else {
105764 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
105765 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
105766 }
105767 if (ret == -EPIPE) {
105768 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
105769 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
105770 struct snd_pcm_plugin_channel *channels;
105771 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
105772 if (!in_kernel) {
105773 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
105774 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
105775 return -EFAULT;
105776 buf = runtime->oss.buffer;
105777 }
105778 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
105779 }
105780 } else {
105781 tmp = snd_pcm_oss_write2(substream,
105782 - (const char __force *)buf,
105783 + (const char __force_kernel *)buf,
105784 runtime->oss.period_bytes, 0);
105785 if (tmp <= 0)
105786 goto err;
105787 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
105788 struct snd_pcm_runtime *runtime = substream->runtime;
105789 snd_pcm_sframes_t frames, frames1;
105790 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
105791 - char __user *final_dst = (char __force __user *)buf;
105792 + char __user *final_dst = (char __force_user *)buf;
105793 if (runtime->oss.plugin_first) {
105794 struct snd_pcm_plugin_channel *channels;
105795 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
105796 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
105797 xfer += tmp;
105798 runtime->oss.buffer_used -= tmp;
105799 } else {
105800 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
105801 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
105802 runtime->oss.period_bytes, 0);
105803 if (tmp <= 0)
105804 goto err;
105805 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
105806 size1);
105807 size1 /= runtime->channels; /* frames */
105808 fs = snd_enter_user();
105809 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
105810 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
105811 snd_leave_user(fs);
105812 }
105813 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
105814 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
105815 index af49721..e85058e 100644
105816 --- a/sound/core/pcm_compat.c
105817 +++ b/sound/core/pcm_compat.c
105818 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
105819 int err;
105820
105821 fs = snd_enter_user();
105822 - err = snd_pcm_delay(substream, &delay);
105823 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
105824 snd_leave_user(fs);
105825 if (err < 0)
105826 return err;
105827 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
105828 index 01a5e05..c6bb425 100644
105829 --- a/sound/core/pcm_native.c
105830 +++ b/sound/core/pcm_native.c
105831 @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
105832 switch (substream->stream) {
105833 case SNDRV_PCM_STREAM_PLAYBACK:
105834 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
105835 - (void __user *)arg);
105836 + (void __force_user *)arg);
105837 break;
105838 case SNDRV_PCM_STREAM_CAPTURE:
105839 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
105840 - (void __user *)arg);
105841 + (void __force_user *)arg);
105842 break;
105843 default:
105844 result = -EINVAL;
105845 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
105846 index 8d4d5e8..fdd0826 100644
105847 --- a/sound/core/seq/oss/seq_oss.c
105848 +++ b/sound/core/seq/oss/seq_oss.c
105849 @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
105850 {
105851 int rc;
105852 static struct snd_seq_dev_ops ops = {
105853 - snd_seq_oss_synth_register,
105854 - snd_seq_oss_synth_unregister,
105855 + .init_device = snd_seq_oss_synth_register,
105856 + .free_device = snd_seq_oss_synth_unregister,
105857 };
105858
105859 snd_seq_autoload_lock();
105860 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
105861 index 040c60e..989a19a 100644
105862 --- a/sound/core/seq/seq_device.c
105863 +++ b/sound/core/seq/seq_device.c
105864 @@ -64,7 +64,7 @@ struct ops_list {
105865 int argsize; /* argument size */
105866
105867 /* operators */
105868 - struct snd_seq_dev_ops ops;
105869 + struct snd_seq_dev_ops *ops;
105870
105871 /* registered devices */
105872 struct list_head dev_list; /* list of devices */
105873 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
105874
105875 mutex_lock(&ops->reg_mutex);
105876 /* copy driver operators */
105877 - ops->ops = *entry;
105878 + ops->ops = entry;
105879 ops->driver |= DRIVER_LOADED;
105880 ops->argsize = argsize;
105881
105882 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
105883 dev->name, ops->id, ops->argsize, dev->argsize);
105884 return -EINVAL;
105885 }
105886 - if (ops->ops.init_device(dev) >= 0) {
105887 + if (ops->ops->init_device(dev) >= 0) {
105888 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
105889 ops->num_init_devices++;
105890 } else {
105891 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
105892 dev->name, ops->id, ops->argsize, dev->argsize);
105893 return -EINVAL;
105894 }
105895 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
105896 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
105897 dev->status = SNDRV_SEQ_DEVICE_FREE;
105898 dev->driver_data = NULL;
105899 ops->num_init_devices--;
105900 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
105901 index 64069db..3c6d392 100644
105902 --- a/sound/core/seq/seq_midi.c
105903 +++ b/sound/core/seq/seq_midi.c
105904 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
105905 static int __init alsa_seq_midi_init(void)
105906 {
105907 static struct snd_seq_dev_ops ops = {
105908 - snd_seq_midisynth_register_port,
105909 - snd_seq_midisynth_unregister_port,
105910 + .init_device = snd_seq_midisynth_register_port,
105911 + .free_device = snd_seq_midisynth_unregister_port,
105912 };
105913 memset(&synths, 0, sizeof(synths));
105914 snd_seq_autoload_lock();
105915 diff --git a/sound/core/sound.c b/sound/core/sound.c
105916 index 437c25e..cd040ab 100644
105917 --- a/sound/core/sound.c
105918 +++ b/sound/core/sound.c
105919 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
105920 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
105921 default: return;
105922 }
105923 - request_module(str);
105924 + request_module("%s", str);
105925 }
105926
105927 #endif /* modular kernel */
105928 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
105929 index 4e0dd22..7a1f32c 100644
105930 --- a/sound/drivers/mts64.c
105931 +++ b/sound/drivers/mts64.c
105932 @@ -29,6 +29,7 @@
105933 #include <sound/initval.h>
105934 #include <sound/rawmidi.h>
105935 #include <sound/control.h>
105936 +#include <asm/local.h>
105937
105938 #define CARD_NAME "Miditerminal 4140"
105939 #define DRIVER_NAME "MTS64"
105940 @@ -67,7 +68,7 @@ struct mts64 {
105941 struct pardevice *pardev;
105942 int pardev_claimed;
105943
105944 - int open_count;
105945 + local_t open_count;
105946 int current_midi_output_port;
105947 int current_midi_input_port;
105948 u8 mode[MTS64_NUM_INPUT_PORTS];
105949 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
105950 {
105951 struct mts64 *mts = substream->rmidi->private_data;
105952
105953 - if (mts->open_count == 0) {
105954 + if (local_read(&mts->open_count) == 0) {
105955 /* We don't need a spinlock here, because this is just called
105956 if the device has not been opened before.
105957 So there aren't any IRQs from the device */
105958 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
105959
105960 msleep(50);
105961 }
105962 - ++(mts->open_count);
105963 + local_inc(&mts->open_count);
105964
105965 return 0;
105966 }
105967 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
105968 struct mts64 *mts = substream->rmidi->private_data;
105969 unsigned long flags;
105970
105971 - --(mts->open_count);
105972 - if (mts->open_count == 0) {
105973 + if (local_dec_return(&mts->open_count) == 0) {
105974 /* We need the spinlock_irqsave here because we can still
105975 have IRQs at this point */
105976 spin_lock_irqsave(&mts->lock, flags);
105977 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
105978
105979 msleep(500);
105980
105981 - } else if (mts->open_count < 0)
105982 - mts->open_count = 0;
105983 + } else if (local_read(&mts->open_count) < 0)
105984 + local_set(&mts->open_count, 0);
105985
105986 return 0;
105987 }
105988 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
105989 index 6839953..7a0f4b9 100644
105990 --- a/sound/drivers/opl3/opl3_seq.c
105991 +++ b/sound/drivers/opl3/opl3_seq.c
105992 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
105993 {
105994 static struct snd_seq_dev_ops ops =
105995 {
105996 - snd_opl3_seq_new_device,
105997 - snd_opl3_seq_delete_device
105998 + .init_device = snd_opl3_seq_new_device,
105999 + .free_device = snd_opl3_seq_delete_device
106000 };
106001
106002 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
106003 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
106004 index b953fb4..1999c01 100644
106005 --- a/sound/drivers/opl4/opl4_lib.c
106006 +++ b/sound/drivers/opl4/opl4_lib.c
106007 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
106008 MODULE_DESCRIPTION("OPL4 driver");
106009 MODULE_LICENSE("GPL");
106010
106011 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
106012 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
106013 {
106014 int timeout = 10;
106015 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
106016 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
106017 index 9919769..d7de36c 100644
106018 --- a/sound/drivers/opl4/opl4_seq.c
106019 +++ b/sound/drivers/opl4/opl4_seq.c
106020 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
106021 static int __init alsa_opl4_synth_init(void)
106022 {
106023 static struct snd_seq_dev_ops ops = {
106024 - snd_opl4_seq_new_device,
106025 - snd_opl4_seq_delete_device
106026 + .init_device = snd_opl4_seq_new_device,
106027 + .free_device = snd_opl4_seq_delete_device
106028 };
106029
106030 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
106031 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
106032 index 991018d..8984740 100644
106033 --- a/sound/drivers/portman2x4.c
106034 +++ b/sound/drivers/portman2x4.c
106035 @@ -48,6 +48,7 @@
106036 #include <sound/initval.h>
106037 #include <sound/rawmidi.h>
106038 #include <sound/control.h>
106039 +#include <asm/local.h>
106040
106041 #define CARD_NAME "Portman 2x4"
106042 #define DRIVER_NAME "portman"
106043 @@ -85,7 +86,7 @@ struct portman {
106044 struct pardevice *pardev;
106045 int pardev_claimed;
106046
106047 - int open_count;
106048 + local_t open_count;
106049 int mode[PORTMAN_NUM_INPUT_PORTS];
106050 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
106051 };
106052 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
106053 index 9048777..2d8b1fc 100644
106054 --- a/sound/firewire/amdtp.c
106055 +++ b/sound/firewire/amdtp.c
106056 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
106057 ptr = s->pcm_buffer_pointer + data_blocks;
106058 if (ptr >= pcm->runtime->buffer_size)
106059 ptr -= pcm->runtime->buffer_size;
106060 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
106061 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
106062
106063 s->pcm_period_pointer += data_blocks;
106064 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
106065 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
106066 */
106067 void amdtp_out_stream_update(struct amdtp_out_stream *s)
106068 {
106069 - ACCESS_ONCE(s->source_node_id_field) =
106070 + ACCESS_ONCE_RW(s->source_node_id_field) =
106071 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
106072 }
106073 EXPORT_SYMBOL(amdtp_out_stream_update);
106074 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
106075 index 2746ecd..c35dedd 100644
106076 --- a/sound/firewire/amdtp.h
106077 +++ b/sound/firewire/amdtp.h
106078 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
106079 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
106080 struct snd_pcm_substream *pcm)
106081 {
106082 - ACCESS_ONCE(s->pcm) = pcm;
106083 + ACCESS_ONCE_RW(s->pcm) = pcm;
106084 }
106085
106086 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
106087 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
106088 index fd42e6b..c041971 100644
106089 --- a/sound/firewire/isight.c
106090 +++ b/sound/firewire/isight.c
106091 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
106092 ptr += count;
106093 if (ptr >= runtime->buffer_size)
106094 ptr -= runtime->buffer_size;
106095 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
106096 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
106097
106098 isight->period_counter += count;
106099 if (isight->period_counter >= runtime->period_size) {
106100 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
106101 if (err < 0)
106102 return err;
106103
106104 - ACCESS_ONCE(isight->pcm_active) = true;
106105 + ACCESS_ONCE_RW(isight->pcm_active) = true;
106106
106107 return 0;
106108 }
106109 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
106110 {
106111 struct isight *isight = substream->private_data;
106112
106113 - ACCESS_ONCE(isight->pcm_active) = false;
106114 + ACCESS_ONCE_RW(isight->pcm_active) = false;
106115
106116 mutex_lock(&isight->mutex);
106117 isight_stop_streaming(isight);
106118 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
106119
106120 switch (cmd) {
106121 case SNDRV_PCM_TRIGGER_START:
106122 - ACCESS_ONCE(isight->pcm_running) = true;
106123 + ACCESS_ONCE_RW(isight->pcm_running) = true;
106124 break;
106125 case SNDRV_PCM_TRIGGER_STOP:
106126 - ACCESS_ONCE(isight->pcm_running) = false;
106127 + ACCESS_ONCE_RW(isight->pcm_running) = false;
106128 break;
106129 default:
106130 return -EINVAL;
106131 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
106132 index 858023c..83b3d3c 100644
106133 --- a/sound/firewire/scs1x.c
106134 +++ b/sound/firewire/scs1x.c
106135 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
106136 {
106137 struct scs *scs = stream->rmidi->private_data;
106138
106139 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
106140 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
106141 if (up) {
106142 scs->output_idle = false;
106143 tasklet_schedule(&scs->tasklet);
106144 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
106145 {
106146 struct scs *scs = stream->rmidi->private_data;
106147
106148 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
106149 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
106150 }
106151
106152 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
106153 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
106154
106155 snd_card_disconnect(scs->card);
106156
106157 - ACCESS_ONCE(scs->output) = NULL;
106158 - ACCESS_ONCE(scs->input) = NULL;
106159 + ACCESS_ONCE_RW(scs->output) = NULL;
106160 + ACCESS_ONCE_RW(scs->input) = NULL;
106161
106162 wait_event(scs->idle_wait, scs->output_idle);
106163
106164 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
106165 index 4e3fcfb..ab45a9d 100644
106166 --- a/sound/isa/sb/emu8000_synth.c
106167 +++ b/sound/isa/sb/emu8000_synth.c
106168 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
106169 {
106170
106171 static struct snd_seq_dev_ops ops = {
106172 - snd_emu8000_new_device,
106173 - snd_emu8000_delete_device,
106174 + .init_device = snd_emu8000_new_device,
106175 + .free_device = snd_emu8000_delete_device,
106176 };
106177 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
106178 sizeof(struct snd_emu8000*));
106179 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
106180 index 048439a..3be9f6f 100644
106181 --- a/sound/oss/sb_audio.c
106182 +++ b/sound/oss/sb_audio.c
106183 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
106184 buf16 = (signed short *)(localbuf + localoffs);
106185 while (c)
106186 {
106187 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
106188 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
106189 if (copy_from_user(lbuf8,
106190 userbuf+useroffs + p,
106191 locallen))
106192 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
106193 index f851fd0..92576fb 100644
106194 --- a/sound/oss/swarm_cs4297a.c
106195 +++ b/sound/oss/swarm_cs4297a.c
106196 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
106197 {
106198 struct cs4297a_state *s;
106199 u32 pwr, id;
106200 - mm_segment_t fs;
106201 int rval;
106202 #ifndef CONFIG_BCM_CS4297A_CSWARM
106203 u64 cfg;
106204 @@ -2713,22 +2712,23 @@ static int __init cs4297a_init(void)
106205 if (!rval) {
106206 char *sb1250_duart_present;
106207
106208 +#if 0
106209 + mm_segment_t fs;
106210 fs = get_fs();
106211 set_fs(KERNEL_DS);
106212 -#if 0
106213 val = SOUND_MASK_LINE;
106214 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
106215 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
106216 val = initvol[i].vol;
106217 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
106218 }
106219 + set_fs(fs);
106220 // cs4297a_write_ac97(s, 0x18, 0x0808);
106221 #else
106222 // cs4297a_write_ac97(s, 0x5e, 0x180);
106223 cs4297a_write_ac97(s, 0x02, 0x0808);
106224 cs4297a_write_ac97(s, 0x18, 0x0808);
106225 #endif
106226 - set_fs(fs);
106227
106228 list_add(&s->list, &cs4297a_devs);
106229
106230 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
106231 index 4c41c90..37f3631 100644
106232 --- a/sound/pci/emu10k1/emu10k1_synth.c
106233 +++ b/sound/pci/emu10k1/emu10k1_synth.c
106234 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
106235 {
106236
106237 static struct snd_seq_dev_ops ops = {
106238 - snd_emu10k1_synth_new_device,
106239 - snd_emu10k1_synth_delete_device,
106240 + .init_device = snd_emu10k1_synth_new_device,
106241 + .free_device = snd_emu10k1_synth_delete_device,
106242 };
106243 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
106244 sizeof(struct snd_emu10k1_synth_arg));
106245 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
106246 index dafcf82..dd9356f 100644
106247 --- a/sound/pci/hda/hda_codec.c
106248 +++ b/sound/pci/hda/hda_codec.c
106249 @@ -983,14 +983,10 @@ find_codec_preset(struct hda_codec *codec)
106250 mutex_unlock(&preset_mutex);
106251
106252 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
106253 - char name[32];
106254 if (!mod_requested)
106255 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
106256 - codec->vendor_id);
106257 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
106258 else
106259 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
106260 - (codec->vendor_id >> 16) & 0xffff);
106261 - request_module(name);
106262 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
106263 mod_requested++;
106264 goto again;
106265 }
106266 @@ -2739,7 +2735,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
106267 /* FIXME: set_fs() hack for obtaining user-space TLV data */
106268 mm_segment_t fs = get_fs();
106269 set_fs(get_ds());
106270 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
106271 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
106272 tlv = _tlv;
106273 set_fs(fs);
106274 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
106275 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
106276 index 4631a23..001ae57 100644
106277 --- a/sound/pci/ymfpci/ymfpci.h
106278 +++ b/sound/pci/ymfpci/ymfpci.h
106279 @@ -358,7 +358,7 @@ struct snd_ymfpci {
106280 spinlock_t reg_lock;
106281 spinlock_t voice_lock;
106282 wait_queue_head_t interrupt_sleep;
106283 - atomic_t interrupt_sleep_count;
106284 + atomic_unchecked_t interrupt_sleep_count;
106285 struct snd_info_entry *proc_entry;
106286 const struct firmware *dsp_microcode;
106287 const struct firmware *controller_microcode;
106288 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
106289 index d591c15..8cb8f94 100644
106290 --- a/sound/pci/ymfpci/ymfpci_main.c
106291 +++ b/sound/pci/ymfpci/ymfpci_main.c
106292 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
106293 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
106294 break;
106295 }
106296 - if (atomic_read(&chip->interrupt_sleep_count)) {
106297 - atomic_set(&chip->interrupt_sleep_count, 0);
106298 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
106299 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106300 wake_up(&chip->interrupt_sleep);
106301 }
106302 __end:
106303 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
106304 continue;
106305 init_waitqueue_entry(&wait, current);
106306 add_wait_queue(&chip->interrupt_sleep, &wait);
106307 - atomic_inc(&chip->interrupt_sleep_count);
106308 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
106309 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
106310 remove_wait_queue(&chip->interrupt_sleep, &wait);
106311 }
106312 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
106313 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
106314 spin_unlock(&chip->reg_lock);
106315
106316 - if (atomic_read(&chip->interrupt_sleep_count)) {
106317 - atomic_set(&chip->interrupt_sleep_count, 0);
106318 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
106319 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106320 wake_up(&chip->interrupt_sleep);
106321 }
106322 }
106323 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
106324 spin_lock_init(&chip->reg_lock);
106325 spin_lock_init(&chip->voice_lock);
106326 init_waitqueue_head(&chip->interrupt_sleep);
106327 - atomic_set(&chip->interrupt_sleep_count, 0);
106328 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106329 chip->card = card;
106330 chip->pci = pci;
106331 chip->irq = -1;
106332 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
106333 index 5428a1f..474f651 100644
106334 --- a/sound/soc/fsl/fsl_ssi.c
106335 +++ b/sound/soc/fsl/fsl_ssi.c
106336 @@ -1255,7 +1255,6 @@ static int fsl_ssi_probe(struct platform_device *pdev)
106337 {
106338 struct fsl_ssi_private *ssi_private;
106339 int ret = 0;
106340 - struct device_attribute *dev_attr = NULL;
106341 struct device_node *np = pdev->dev.of_node;
106342 const struct of_device_id *of_id;
106343 enum fsl_ssi_type hw_type;
106344 @@ -1481,7 +1480,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
106345 &ssi_private->cpu_dai_drv, 1);
106346 if (ret) {
106347 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
106348 - goto error_dev;
106349 + goto error_clk;
106350 }
106351
106352 ret = fsl_ssi_debugfs_create(ssi_private, &pdev->dev);
106353 @@ -1562,9 +1561,6 @@ error_pcm:
106354 error_dbgfs:
106355 snd_soc_unregister_component(&pdev->dev);
106356
106357 -error_dev:
106358 - device_remove_file(&pdev->dev, dev_attr);
106359 -
106360 error_clk:
106361 if (ssi_private->ssi_on_imx) {
106362 if (!IS_ERR(ssi_private->baudclk))
106363 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
106364 index fe1df50..09d3be6 100644
106365 --- a/sound/soc/soc-core.c
106366 +++ b/sound/soc/soc-core.c
106367 @@ -2254,8 +2254,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
106368 if (ret)
106369 return ret;
106370
106371 - ops->warm_reset = snd_soc_ac97_warm_reset;
106372 - ops->reset = snd_soc_ac97_reset;
106373 + pax_open_kernel();
106374 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
106375 + *(void **)&ops->reset = snd_soc_ac97_reset;
106376 + pax_close_kernel();
106377
106378 snd_ac97_rst_cfg = cfg;
106379 return 0;
106380 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
106381 index 7778b8e..3d619fc 100644
106382 --- a/sound/synth/emux/emux_seq.c
106383 +++ b/sound/synth/emux/emux_seq.c
106384 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
106385 * MIDI emulation operators
106386 */
106387 static struct snd_midi_op emux_ops = {
106388 - snd_emux_note_on,
106389 - snd_emux_note_off,
106390 - snd_emux_key_press,
106391 - snd_emux_terminate_note,
106392 - snd_emux_control,
106393 - snd_emux_nrpn,
106394 - snd_emux_sysex,
106395 + .note_on = snd_emux_note_on,
106396 + .note_off = snd_emux_note_off,
106397 + .key_press = snd_emux_key_press,
106398 + .note_terminate = snd_emux_terminate_note,
106399 + .control = snd_emux_control,
106400 + .nrpn = snd_emux_nrpn,
106401 + .sysex = snd_emux_sysex,
106402 };
106403
106404
106405 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
106406 new file mode 100644
106407 index 0000000..60e7af2
106408 --- /dev/null
106409 +++ b/tools/gcc/.gitignore
106410 @@ -0,0 +1,2 @@
106411 +randomize_layout_seed.h
106412 +randomize_layout_hash.h
106413 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
106414 new file mode 100644
106415 index 0000000..7b8921f
106416 --- /dev/null
106417 +++ b/tools/gcc/Makefile
106418 @@ -0,0 +1,52 @@
106419 +#CC := gcc
106420 +#PLUGIN_SOURCE_FILES := pax_plugin.c
106421 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
106422 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
106423 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
106424 +
106425 +ifeq ($(PLUGINCC),$(HOSTCC))
106426 +HOSTLIBS := hostlibs
106427 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
106428 +export HOST_EXTRACFLAGS
106429 +else
106430 +HOSTLIBS := hostcxxlibs
106431 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
106432 +export HOST_EXTRACXXFLAGS
106433 +endif
106434 +
106435 +export GCCPLUGINS_DIR HOSTLIBS
106436 +
106437 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
106438 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
106439 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
106440 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
106441 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
106442 +$(HOSTLIBS)-y += colorize_plugin.so
106443 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
106444 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
106445 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
106446 +
106447 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
106448 +subdir- += size_overflow_plugin
106449 +
106450 +always := $($(HOSTLIBS)-y)
106451 +
106452 +constify_plugin-objs := constify_plugin.o
106453 +stackleak_plugin-objs := stackleak_plugin.o
106454 +kallocstat_plugin-objs := kallocstat_plugin.o
106455 +kernexec_plugin-objs := kernexec_plugin.o
106456 +checker_plugin-objs := checker_plugin.o
106457 +colorize_plugin-objs := colorize_plugin.o
106458 +latent_entropy_plugin-objs := latent_entropy_plugin.o
106459 +structleak_plugin-objs := structleak_plugin.o
106460 +randomize_layout_plugin-objs := randomize_layout_plugin.o
106461 +
106462 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
106463 +
106464 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
106465 + cmd_create_randomize_layout_seed = \
106466 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
106467 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
106468 + $(call if_changed,create_randomize_layout_seed)
106469 +
106470 +targets += randomize_layout_seed.h randomize_layout_hash.h
106471 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
106472 new file mode 100644
106473 index 0000000..5452feea
106474 --- /dev/null
106475 +++ b/tools/gcc/checker_plugin.c
106476 @@ -0,0 +1,150 @@
106477 +/*
106478 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106479 + * Licensed under the GPL v2
106480 + *
106481 + * Note: the choice of the license means that the compilation process is
106482 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106483 + * but for the kernel it doesn't matter since it doesn't link against
106484 + * any of the gcc libraries
106485 + *
106486 + * gcc plugin to implement various sparse (source code checker) features
106487 + *
106488 + * TODO:
106489 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
106490 + *
106491 + * BUGS:
106492 + * - none known
106493 + */
106494 +
106495 +#include "gcc-common.h"
106496 +
106497 +extern void c_register_addr_space (const char *str, addr_space_t as);
106498 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
106499 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
106500 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
106501 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
106502 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
106503 +
106504 +int plugin_is_GPL_compatible;
106505 +
106506 +static struct plugin_info checker_plugin_info = {
106507 + .version = "201304082245",
106508 + .help = NULL,
106509 +};
106510 +
106511 +#define ADDR_SPACE_KERNEL 0
106512 +#define ADDR_SPACE_FORCE_KERNEL 1
106513 +#define ADDR_SPACE_USER 2
106514 +#define ADDR_SPACE_FORCE_USER 3
106515 +#define ADDR_SPACE_IOMEM 0
106516 +#define ADDR_SPACE_FORCE_IOMEM 0
106517 +#define ADDR_SPACE_PERCPU 0
106518 +#define ADDR_SPACE_FORCE_PERCPU 0
106519 +#define ADDR_SPACE_RCU 0
106520 +#define ADDR_SPACE_FORCE_RCU 0
106521 +
106522 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
106523 +{
106524 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
106525 +}
106526 +
106527 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
106528 +{
106529 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
106530 +}
106531 +
106532 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
106533 +{
106534 + return default_addr_space_valid_pointer_mode(mode, as);
106535 +}
106536 +
106537 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
106538 +{
106539 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
106540 +}
106541 +
106542 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
106543 +{
106544 + return default_addr_space_legitimize_address(x, oldx, mode, as);
106545 +}
106546 +
106547 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
106548 +{
106549 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
106550 + return true;
106551 +
106552 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
106553 + return true;
106554 +
106555 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
106556 + return true;
106557 +
106558 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
106559 + return true;
106560 +
106561 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
106562 + return true;
106563 +
106564 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
106565 + return true;
106566 +
106567 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
106568 + return true;
106569 +
106570 + return subset == superset;
106571 +}
106572 +
106573 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
106574 +{
106575 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
106576 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
106577 +
106578 + return op;
106579 +}
106580 +
106581 +static void register_checker_address_spaces(void *event_data, void *data)
106582 +{
106583 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
106584 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
106585 + c_register_addr_space("__user", ADDR_SPACE_USER);
106586 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
106587 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
106588 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
106589 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
106590 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
106591 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
106592 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
106593 +
106594 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
106595 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
106596 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
106597 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
106598 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
106599 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
106600 + targetm.addr_space.convert = checker_addr_space_convert;
106601 +}
106602 +
106603 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106604 +{
106605 + const char * const plugin_name = plugin_info->base_name;
106606 + const int argc = plugin_info->argc;
106607 + const struct plugin_argument * const argv = plugin_info->argv;
106608 + int i;
106609 +
106610 + if (!plugin_default_version_check(version, &gcc_version)) {
106611 + error(G_("incompatible gcc/plugin versions"));
106612 + return 1;
106613 + }
106614 +
106615 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
106616 +
106617 + for (i = 0; i < argc; ++i)
106618 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106619 +
106620 + if (TARGET_64BIT == 0)
106621 + return 0;
106622 +
106623 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
106624 +
106625 + return 0;
106626 +}
106627 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
106628 new file mode 100644
106629 index 0000000..54461af
106630 --- /dev/null
106631 +++ b/tools/gcc/colorize_plugin.c
106632 @@ -0,0 +1,210 @@
106633 +/*
106634 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
106635 + * Licensed under the GPL v2
106636 + *
106637 + * Note: the choice of the license means that the compilation process is
106638 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106639 + * but for the kernel it doesn't matter since it doesn't link against
106640 + * any of the gcc libraries
106641 + *
106642 + * gcc plugin to colorize diagnostic output
106643 + *
106644 + */
106645 +
106646 +#include "gcc-common.h"
106647 +
106648 +int plugin_is_GPL_compatible;
106649 +
106650 +static struct plugin_info colorize_plugin_info = {
106651 + .version = "201404202350",
106652 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
106653 +};
106654 +
106655 +#define GREEN "\033[32m\033[K"
106656 +#define LIGHTGREEN "\033[1;32m\033[K"
106657 +#define YELLOW "\033[33m\033[K"
106658 +#define LIGHTYELLOW "\033[1;33m\033[K"
106659 +#define RED "\033[31m\033[K"
106660 +#define LIGHTRED "\033[1;31m\033[K"
106661 +#define BLUE "\033[34m\033[K"
106662 +#define LIGHTBLUE "\033[1;34m\033[K"
106663 +#define BRIGHT "\033[1;m\033[K"
106664 +#define NORMAL "\033[m\033[K"
106665 +
106666 +static diagnostic_starter_fn old_starter;
106667 +static diagnostic_finalizer_fn old_finalizer;
106668 +
106669 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
106670 +{
106671 + const char *color;
106672 + char *newprefix;
106673 +
106674 + switch (diagnostic->kind) {
106675 + case DK_NOTE:
106676 + color = LIGHTBLUE;
106677 + break;
106678 +
106679 + case DK_PEDWARN:
106680 + case DK_WARNING:
106681 + color = LIGHTYELLOW;
106682 + break;
106683 +
106684 + case DK_ERROR:
106685 + case DK_FATAL:
106686 + case DK_ICE:
106687 + case DK_PERMERROR:
106688 + case DK_SORRY:
106689 + color = LIGHTRED;
106690 + break;
106691 +
106692 + default:
106693 + color = NORMAL;
106694 + }
106695 +
106696 + old_starter(context, diagnostic);
106697 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
106698 + return;
106699 + pp_destroy_prefix(context->printer);
106700 + pp_set_prefix(context->printer, newprefix);
106701 +}
106702 +
106703 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
106704 +{
106705 + old_finalizer(context, diagnostic);
106706 +}
106707 +
106708 +static void colorize_arm(void)
106709 +{
106710 + old_starter = diagnostic_starter(global_dc);
106711 + old_finalizer = diagnostic_finalizer(global_dc);
106712 +
106713 + diagnostic_starter(global_dc) = start_colorize;
106714 + diagnostic_finalizer(global_dc) = finalize_colorize;
106715 +}
106716 +
106717 +static unsigned int execute_colorize_rearm(void)
106718 +{
106719 + if (diagnostic_starter(global_dc) == start_colorize)
106720 + return 0;
106721 +
106722 + colorize_arm();
106723 + return 0;
106724 +}
106725 +
106726 +#if BUILDING_GCC_VERSION >= 4009
106727 +static const struct pass_data colorize_rearm_pass_data = {
106728 +#else
106729 +struct simple_ipa_opt_pass colorize_rearm_pass = {
106730 + .pass = {
106731 +#endif
106732 + .type = SIMPLE_IPA_PASS,
106733 + .name = "colorize_rearm",
106734 +#if BUILDING_GCC_VERSION >= 4008
106735 + .optinfo_flags = OPTGROUP_NONE,
106736 +#endif
106737 +#if BUILDING_GCC_VERSION >= 4009
106738 + .has_gate = false,
106739 + .has_execute = true,
106740 +#else
106741 + .gate = NULL,
106742 + .execute = execute_colorize_rearm,
106743 + .sub = NULL,
106744 + .next = NULL,
106745 + .static_pass_number = 0,
106746 +#endif
106747 + .tv_id = TV_NONE,
106748 + .properties_required = 0,
106749 + .properties_provided = 0,
106750 + .properties_destroyed = 0,
106751 + .todo_flags_start = 0,
106752 + .todo_flags_finish = 0
106753 +#if BUILDING_GCC_VERSION < 4009
106754 + }
106755 +#endif
106756 +};
106757 +
106758 +#if BUILDING_GCC_VERSION >= 4009
106759 +namespace {
106760 +class colorize_rearm_pass : public simple_ipa_opt_pass {
106761 +public:
106762 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
106763 + unsigned int execute() { return execute_colorize_rearm(); }
106764 +};
106765 +}
106766 +
106767 +static opt_pass *make_colorize_rearm_pass(void)
106768 +{
106769 + return new colorize_rearm_pass();
106770 +}
106771 +#else
106772 +static struct opt_pass *make_colorize_rearm_pass(void)
106773 +{
106774 + return &colorize_rearm_pass.pass;
106775 +}
106776 +#endif
106777 +
106778 +static void colorize_start_unit(void *gcc_data, void *user_data)
106779 +{
106780 + colorize_arm();
106781 +}
106782 +
106783 +static bool should_colorize(void)
106784 +{
106785 +#if BUILDING_GCC_VERSION >= 4009
106786 + return false;
106787 +#else
106788 + char const *t = getenv("TERM");
106789 +
106790 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
106791 +#endif
106792 +}
106793 +
106794 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106795 +{
106796 + const char * const plugin_name = plugin_info->base_name;
106797 + const int argc = plugin_info->argc;
106798 + const struct plugin_argument * const argv = plugin_info->argv;
106799 + int i;
106800 + struct register_pass_info colorize_rearm_pass_info;
106801 + bool colorize;
106802 +
106803 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
106804 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
106805 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
106806 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
106807 +
106808 + if (!plugin_default_version_check(version, &gcc_version)) {
106809 + error(G_("incompatible gcc/plugin versions"));
106810 + return 1;
106811 + }
106812 +
106813 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
106814 +
106815 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
106816 +
106817 + for (i = 0; i < argc; ++i) {
106818 + if (!strcmp(argv[i].key, "color")) {
106819 + if (!argv[i].value) {
106820 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106821 + continue;
106822 + }
106823 + if (!strcmp(argv[i].value, "always"))
106824 + colorize = true;
106825 + else if (!strcmp(argv[i].value, "never"))
106826 + colorize = false;
106827 + else if (!strcmp(argv[i].value, "auto"))
106828 + colorize = should_colorize();
106829 + else
106830 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
106831 + continue;
106832 + }
106833 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
106834 + }
106835 +
106836 + if (colorize) {
106837 + // TODO: parse GCC_COLORS as used by gcc 4.9+
106838 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
106839 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
106840 + }
106841 + return 0;
106842 +}
106843 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
106844 new file mode 100644
106845 index 0000000..82bc5a8
106846 --- /dev/null
106847 +++ b/tools/gcc/constify_plugin.c
106848 @@ -0,0 +1,557 @@
106849 +/*
106850 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
106851 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
106852 + * Licensed under the GPL v2, or (at your option) v3
106853 + *
106854 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
106855 + *
106856 + * Homepage:
106857 + * http://www.grsecurity.net/~ephox/const_plugin/
106858 + *
106859 + * Usage:
106860 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
106861 + * $ gcc -fplugin=constify_plugin.so test.c -O2
106862 + */
106863 +
106864 +#include "gcc-common.h"
106865 +
106866 +// unused C type flag in all versions 4.5-4.9
106867 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
106868 +
106869 +int plugin_is_GPL_compatible;
106870 +
106871 +static struct plugin_info const_plugin_info = {
106872 + .version = "201401270210",
106873 + .help = "no-constify\tturn off constification\n",
106874 +};
106875 +
106876 +typedef struct {
106877 + bool has_fptr_field;
106878 + bool has_writable_field;
106879 + bool has_do_const_field;
106880 + bool has_no_const_field;
106881 +} constify_info;
106882 +
106883 +static const_tree get_field_type(const_tree field)
106884 +{
106885 + return strip_array_types(TREE_TYPE(field));
106886 +}
106887 +
106888 +static bool is_fptr(const_tree field)
106889 +{
106890 + const_tree ptr = get_field_type(field);
106891 +
106892 + if (TREE_CODE(ptr) != POINTER_TYPE)
106893 + return false;
106894 +
106895 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
106896 +}
106897 +
106898 +/*
106899 + * determine whether the given structure type meets the requirements for automatic constification,
106900 + * including the constification attributes on nested structure types
106901 + */
106902 +static void constifiable(const_tree node, constify_info *cinfo)
106903 +{
106904 + const_tree field;
106905 +
106906 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
106907 +
106908 + // e.g., pointer to structure fields while still constructing the structure type
106909 + if (TYPE_FIELDS(node) == NULL_TREE)
106910 + return;
106911 +
106912 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
106913 + const_tree type = get_field_type(field);
106914 + enum tree_code code = TREE_CODE(type);
106915 +
106916 + if (node == type)
106917 + continue;
106918 +
106919 + if (is_fptr(field))
106920 + cinfo->has_fptr_field = true;
106921 + else if (!TREE_READONLY(field))
106922 + cinfo->has_writable_field = true;
106923 +
106924 + if (code == RECORD_TYPE || code == UNION_TYPE) {
106925 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
106926 + cinfo->has_do_const_field = true;
106927 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
106928 + cinfo->has_no_const_field = true;
106929 + else
106930 + constifiable(type, cinfo);
106931 + }
106932 + }
106933 +}
106934 +
106935 +static bool constified(const_tree node)
106936 +{
106937 + constify_info cinfo = {
106938 + .has_fptr_field = false,
106939 + .has_writable_field = false,
106940 + .has_do_const_field = false,
106941 + .has_no_const_field = false
106942 + };
106943 +
106944 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
106945 +
106946 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
106947 +// gcc_assert(!TYPE_READONLY(node));
106948 + return false;
106949 + }
106950 +
106951 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
106952 + gcc_assert(TYPE_READONLY(node));
106953 + return true;
106954 + }
106955 +
106956 + constifiable(node, &cinfo);
106957 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
106958 + return false;
106959 +
106960 + return TYPE_READONLY(node);
106961 +}
106962 +
106963 +static void deconstify_tree(tree node);
106964 +
106965 +static void deconstify_type(tree type)
106966 +{
106967 + tree field;
106968 +
106969 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
106970 +
106971 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
106972 + const_tree fieldtype = get_field_type(field);
106973 +
106974 + // special case handling of simple ptr-to-same-array-type members
106975 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
106976 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
106977 +
106978 + if (TREE_TYPE(TREE_TYPE(field)) == type)
106979 + continue;
106980 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
106981 + continue;
106982 + if (!constified(ptrtype))
106983 + continue;
106984 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
106985 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
106986 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
106987 + }
106988 + continue;
106989 + }
106990 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
106991 + continue;
106992 + if (!constified(fieldtype))
106993 + continue;
106994 +
106995 + deconstify_tree(field);
106996 + TREE_READONLY(field) = 0;
106997 + }
106998 + TYPE_READONLY(type) = 0;
106999 + C_TYPE_FIELDS_READONLY(type) = 0;
107000 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107001 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107002 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
107003 + }
107004 +}
107005 +
107006 +static void deconstify_tree(tree node)
107007 +{
107008 + tree old_type, new_type, field;
107009 +
107010 + old_type = TREE_TYPE(node);
107011 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
107012 + node = TREE_TYPE(node) = copy_node(old_type);
107013 + old_type = TREE_TYPE(old_type);
107014 + }
107015 +
107016 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
107017 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
107018 +
107019 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
107020 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
107021 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
107022 + DECL_FIELD_CONTEXT(field) = new_type;
107023 +
107024 + deconstify_type(new_type);
107025 +
107026 + TREE_TYPE(node) = new_type;
107027 +}
107028 +
107029 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107030 +{
107031 + tree type;
107032 + constify_info cinfo = {
107033 + .has_fptr_field = false,
107034 + .has_writable_field = false,
107035 + .has_do_const_field = false,
107036 + .has_no_const_field = false
107037 + };
107038 +
107039 + *no_add_attrs = true;
107040 + if (TREE_CODE(*node) == FUNCTION_DECL) {
107041 + error("%qE attribute does not apply to functions (%qF)", name, *node);
107042 + return NULL_TREE;
107043 + }
107044 +
107045 + if (TREE_CODE(*node) == PARM_DECL) {
107046 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
107047 + return NULL_TREE;
107048 + }
107049 +
107050 + if (TREE_CODE(*node) == VAR_DECL) {
107051 + error("%qE attribute does not apply to variables (%qD)", name, *node);
107052 + return NULL_TREE;
107053 + }
107054 +
107055 + if (TYPE_P(*node)) {
107056 + type = *node;
107057 + } else {
107058 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
107059 + type = TREE_TYPE(*node);
107060 + }
107061 +
107062 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
107063 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
107064 + return NULL_TREE;
107065 + }
107066 +
107067 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
107068 + error("%qE attribute is already applied to the type %qT", name, type);
107069 + return NULL_TREE;
107070 + }
107071 +
107072 + if (TYPE_P(*node)) {
107073 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
107074 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
107075 + else
107076 + *no_add_attrs = false;
107077 + return NULL_TREE;
107078 + }
107079 +
107080 + constifiable(type, &cinfo);
107081 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107082 + deconstify_tree(*node);
107083 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
107084 + return NULL_TREE;
107085 + }
107086 +
107087 + error("%qE attribute used on type %qT that is not constified", name, type);
107088 + return NULL_TREE;
107089 +}
107090 +
107091 +static void constify_type(tree type)
107092 +{
107093 + TYPE_READONLY(type) = 1;
107094 + C_TYPE_FIELDS_READONLY(type) = 1;
107095 + TYPE_CONSTIFY_VISITED(type) = 1;
107096 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107097 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
107098 +}
107099 +
107100 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107101 +{
107102 + *no_add_attrs = true;
107103 + if (!TYPE_P(*node)) {
107104 + error("%qE attribute applies to types only (%qD)", name, *node);
107105 + return NULL_TREE;
107106 + }
107107 +
107108 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
107109 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
107110 + return NULL_TREE;
107111 + }
107112 +
107113 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
107114 + error("%qE attribute used on %qT is already applied to the type", name, *node);
107115 + return NULL_TREE;
107116 + }
107117 +
107118 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
107119 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
107120 + return NULL_TREE;
107121 + }
107122 +
107123 + *no_add_attrs = false;
107124 + return NULL_TREE;
107125 +}
107126 +
107127 +static struct attribute_spec no_const_attr = {
107128 + .name = "no_const",
107129 + .min_length = 0,
107130 + .max_length = 0,
107131 + .decl_required = false,
107132 + .type_required = false,
107133 + .function_type_required = false,
107134 + .handler = handle_no_const_attribute,
107135 +#if BUILDING_GCC_VERSION >= 4007
107136 + .affects_type_identity = true
107137 +#endif
107138 +};
107139 +
107140 +static struct attribute_spec do_const_attr = {
107141 + .name = "do_const",
107142 + .min_length = 0,
107143 + .max_length = 0,
107144 + .decl_required = false,
107145 + .type_required = false,
107146 + .function_type_required = false,
107147 + .handler = handle_do_const_attribute,
107148 +#if BUILDING_GCC_VERSION >= 4007
107149 + .affects_type_identity = true
107150 +#endif
107151 +};
107152 +
107153 +static void register_attributes(void *event_data, void *data)
107154 +{
107155 + register_attribute(&no_const_attr);
107156 + register_attribute(&do_const_attr);
107157 +}
107158 +
107159 +static void finish_type(void *event_data, void *data)
107160 +{
107161 + tree type = (tree)event_data;
107162 + constify_info cinfo = {
107163 + .has_fptr_field = false,
107164 + .has_writable_field = false,
107165 + .has_do_const_field = false,
107166 + .has_no_const_field = false
107167 + };
107168 +
107169 + if (type == NULL_TREE || type == error_mark_node)
107170 + return;
107171 +
107172 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
107173 + return;
107174 +
107175 + constifiable(type, &cinfo);
107176 +
107177 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
107178 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
107179 + deconstify_type(type);
107180 + TYPE_CONSTIFY_VISITED(type) = 1;
107181 + } else
107182 + error("'no_const' attribute used on type %qT that is not constified", type);
107183 + return;
107184 + }
107185 +
107186 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107187 + if (!cinfo.has_writable_field) {
107188 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
107189 + return;
107190 + }
107191 + constify_type(type);
107192 + return;
107193 + }
107194 +
107195 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
107196 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107197 + error("'do_const' attribute used on type %qT that is constified", type);
107198 + return;
107199 + }
107200 + constify_type(type);
107201 + return;
107202 + }
107203 +
107204 + deconstify_type(type);
107205 + TYPE_CONSTIFY_VISITED(type) = 1;
107206 +}
107207 +
107208 +static void check_global_variables(void *event_data, void *data)
107209 +{
107210 +#if BUILDING_GCC_VERSION >= 4009
107211 + varpool_node *node;
107212 +#else
107213 + struct varpool_node *node;
107214 +#endif
107215 +
107216 + FOR_EACH_VARIABLE(node) {
107217 + tree var = NODE_DECL(node);
107218 + tree type = TREE_TYPE(var);
107219 +
107220 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
107221 + continue;
107222 +
107223 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
107224 + continue;
107225 +
107226 + if (!TYPE_CONSTIFY_VISITED(type))
107227 + continue;
107228 +
107229 + if (DECL_EXTERNAL(var))
107230 + continue;
107231 +
107232 + if (DECL_INITIAL(var))
107233 + continue;
107234 +
107235 + // this works around a gcc bug/feature where uninitialized globals
107236 + // are moved into the .bss section regardless of any constification
107237 + DECL_INITIAL(var) = build_constructor(type, NULL);
107238 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
107239 + }
107240 +}
107241 +
107242 +static unsigned int check_local_variables(void)
107243 +{
107244 + unsigned int ret = 0;
107245 + tree var;
107246 +
107247 + unsigned int i;
107248 +
107249 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
107250 + tree type = TREE_TYPE(var);
107251 +
107252 + gcc_assert(DECL_P(var));
107253 + if (is_global_var(var))
107254 + continue;
107255 +
107256 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
107257 + continue;
107258 +
107259 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
107260 + continue;
107261 +
107262 + if (!TYPE_CONSTIFY_VISITED(type))
107263 + continue;
107264 +
107265 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
107266 + ret = 1;
107267 + }
107268 + return ret;
107269 +}
107270 +
107271 +#if BUILDING_GCC_VERSION >= 4009
107272 +static const struct pass_data check_local_variables_pass_data = {
107273 +#else
107274 +static struct gimple_opt_pass check_local_variables_pass = {
107275 + .pass = {
107276 +#endif
107277 + .type = GIMPLE_PASS,
107278 + .name = "check_local_variables",
107279 +#if BUILDING_GCC_VERSION >= 4008
107280 + .optinfo_flags = OPTGROUP_NONE,
107281 +#endif
107282 +#if BUILDING_GCC_VERSION >= 4009
107283 + .has_gate = false,
107284 + .has_execute = true,
107285 +#else
107286 + .gate = NULL,
107287 + .execute = check_local_variables,
107288 + .sub = NULL,
107289 + .next = NULL,
107290 + .static_pass_number = 0,
107291 +#endif
107292 + .tv_id = TV_NONE,
107293 + .properties_required = 0,
107294 + .properties_provided = 0,
107295 + .properties_destroyed = 0,
107296 + .todo_flags_start = 0,
107297 + .todo_flags_finish = 0
107298 +#if BUILDING_GCC_VERSION < 4009
107299 + }
107300 +#endif
107301 +};
107302 +
107303 +#if BUILDING_GCC_VERSION >= 4009
107304 +namespace {
107305 +class check_local_variables_pass : public gimple_opt_pass {
107306 +public:
107307 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
107308 + unsigned int execute() { return check_local_variables(); }
107309 +};
107310 +}
107311 +
107312 +static opt_pass *make_check_local_variables_pass(void)
107313 +{
107314 + return new check_local_variables_pass();
107315 +}
107316 +#else
107317 +static struct opt_pass *make_check_local_variables_pass(void)
107318 +{
107319 + return &check_local_variables_pass.pass;
107320 +}
107321 +#endif
107322 +
107323 +static struct {
107324 + const char *name;
107325 + const char *asm_op;
107326 +} sections[] = {
107327 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
107328 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
107329 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
107330 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
107331 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
107332 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
107333 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
107334 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
107335 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
107336 +};
107337 +
107338 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
107339 +
107340 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
107341 +{
107342 + size_t i;
107343 +
107344 + for (i = 0; i < ARRAY_SIZE(sections); i++)
107345 + if (!strcmp(sections[i].name, name))
107346 + return 0;
107347 + return old_section_type_flags(decl, name, reloc);
107348 +}
107349 +
107350 +static void constify_start_unit(void *gcc_data, void *user_data)
107351 +{
107352 +// size_t i;
107353 +
107354 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
107355 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
107356 +// sections[i].section = get_section(sections[i].name, 0, NULL);
107357 +
107358 + old_section_type_flags = targetm.section_type_flags;
107359 + targetm.section_type_flags = constify_section_type_flags;
107360 +}
107361 +
107362 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107363 +{
107364 + const char * const plugin_name = plugin_info->base_name;
107365 + const int argc = plugin_info->argc;
107366 + const struct plugin_argument * const argv = plugin_info->argv;
107367 + int i;
107368 + bool constify = true;
107369 +
107370 + struct register_pass_info check_local_variables_pass_info;
107371 +
107372 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
107373 + check_local_variables_pass_info.reference_pass_name = "ssa";
107374 + check_local_variables_pass_info.ref_pass_instance_number = 1;
107375 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
107376 +
107377 + if (!plugin_default_version_check(version, &gcc_version)) {
107378 + error(G_("incompatible gcc/plugin versions"));
107379 + return 1;
107380 + }
107381 +
107382 + for (i = 0; i < argc; ++i) {
107383 + if (!(strcmp(argv[i].key, "no-constify"))) {
107384 + constify = false;
107385 + continue;
107386 + }
107387 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107388 + }
107389 +
107390 + if (strcmp(lang_hooks.name, "GNU C")) {
107391 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
107392 + constify = false;
107393 + }
107394 +
107395 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
107396 + if (constify) {
107397 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
107398 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
107399 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
107400 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
107401 + }
107402 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
107403 +
107404 + return 0;
107405 +}
107406 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
107407 new file mode 100644
107408 index 0000000..8af3693
107409 --- /dev/null
107410 +++ b/tools/gcc/gcc-common.h
107411 @@ -0,0 +1,287 @@
107412 +#ifndef GCC_COMMON_H_INCLUDED
107413 +#define GCC_COMMON_H_INCLUDED
107414 +
107415 +#include "plugin.h"
107416 +#include "bversion.h"
107417 +#include "plugin-version.h"
107418 +#include "config.h"
107419 +#include "system.h"
107420 +#include "coretypes.h"
107421 +#include "tm.h"
107422 +#include "line-map.h"
107423 +#include "input.h"
107424 +#include "tree.h"
107425 +
107426 +#include "tree-inline.h"
107427 +#include "version.h"
107428 +#include "rtl.h"
107429 +#include "tm_p.h"
107430 +#include "flags.h"
107431 +//#include "insn-attr.h"
107432 +//#include "insn-config.h"
107433 +//#include "insn-flags.h"
107434 +#include "hard-reg-set.h"
107435 +//#include "recog.h"
107436 +#include "output.h"
107437 +#include "except.h"
107438 +#include "function.h"
107439 +#include "toplev.h"
107440 +//#include "expr.h"
107441 +#include "basic-block.h"
107442 +#include "intl.h"
107443 +#include "ggc.h"
107444 +//#include "regs.h"
107445 +#include "timevar.h"
107446 +
107447 +#include "params.h"
107448 +#include "pointer-set.h"
107449 +#include "emit-rtl.h"
107450 +//#include "reload.h"
107451 +//#include "ira.h"
107452 +//#include "dwarf2asm.h"
107453 +#include "debug.h"
107454 +#include "target.h"
107455 +#include "langhooks.h"
107456 +#include "cfgloop.h"
107457 +//#include "hosthooks.h"
107458 +#include "cgraph.h"
107459 +#include "opts.h"
107460 +//#include "coverage.h"
107461 +//#include "value-prof.h"
107462 +
107463 +#if BUILDING_GCC_VERSION >= 4007
107464 +#include "tree-pretty-print.h"
107465 +#include "gimple-pretty-print.h"
107466 +#include "c-tree.h"
107467 +//#include "alloc-pool.h"
107468 +#endif
107469 +
107470 +#if BUILDING_GCC_VERSION <= 4008
107471 +#include "tree-flow.h"
107472 +#else
107473 +#include "tree-cfgcleanup.h"
107474 +#endif
107475 +
107476 +#include "diagnostic.h"
107477 +//#include "tree-diagnostic.h"
107478 +#include "tree-dump.h"
107479 +#include "tree-pass.h"
107480 +//#include "df.h"
107481 +#include "predict.h"
107482 +//#include "lto-streamer.h"
107483 +#include "ipa-utils.h"
107484 +
107485 +#if BUILDING_GCC_VERSION >= 4009
107486 +#include "varasm.h"
107487 +#include "stor-layout.h"
107488 +#include "internal-fn.h"
107489 +#include "gimple-expr.h"
107490 +//#include "diagnostic-color.h"
107491 +#include "context.h"
107492 +#include "tree-ssa-alias.h"
107493 +#include "stringpool.h"
107494 +#include "tree-ssanames.h"
107495 +#include "print-tree.h"
107496 +#include "tree-eh.h"
107497 +#endif
107498 +
107499 +#include "gimple.h"
107500 +
107501 +#if BUILDING_GCC_VERSION >= 4009
107502 +#include "tree-ssa-operands.h"
107503 +#include "tree-phinodes.h"
107504 +#include "tree-cfg.h"
107505 +#include "gimple-iterator.h"
107506 +#include "gimple-ssa.h"
107507 +#include "ssa-iterators.h"
107508 +#endif
107509 +
107510 +//#include "expr.h" where are you...
107511 +extern rtx emit_move_insn(rtx x, rtx y);
107512 +
107513 +// missing from basic_block.h...
107514 +extern void debug_dominance_info(enum cdi_direction dir);
107515 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
107516 +
107517 +#define __unused __attribute__((__unused__))
107518 +
107519 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
107520 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
107521 +
107522 +#if BUILDING_GCC_VERSION == 4005
107523 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
107524 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
107525 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
107526 +#define TODO_rebuild_cgraph_edges 0
107527 +
107528 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
107529 +{
107530 + tree fndecl;
107531 +
107532 + if (!is_gimple_call(stmt))
107533 + return false;
107534 + fndecl = gimple_call_fndecl(stmt);
107535 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
107536 + return false;
107537 +// print_node(stderr, "pax", fndecl, 4);
107538 + return DECL_FUNCTION_CODE(fndecl) == code;
107539 +}
107540 +
107541 +static inline bool is_simple_builtin(tree decl)
107542 +{
107543 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
107544 + return false;
107545 +
107546 + switch (DECL_FUNCTION_CODE(decl)) {
107547 + /* Builtins that expand to constants. */
107548 + case BUILT_IN_CONSTANT_P:
107549 + case BUILT_IN_EXPECT:
107550 + case BUILT_IN_OBJECT_SIZE:
107551 + case BUILT_IN_UNREACHABLE:
107552 + /* Simple register moves or loads from stack. */
107553 + case BUILT_IN_RETURN_ADDRESS:
107554 + case BUILT_IN_EXTRACT_RETURN_ADDR:
107555 + case BUILT_IN_FROB_RETURN_ADDR:
107556 + case BUILT_IN_RETURN:
107557 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
107558 + case BUILT_IN_FRAME_ADDRESS:
107559 + case BUILT_IN_VA_END:
107560 + case BUILT_IN_STACK_SAVE:
107561 + case BUILT_IN_STACK_RESTORE:
107562 + /* Exception state returns or moves registers around. */
107563 + case BUILT_IN_EH_FILTER:
107564 + case BUILT_IN_EH_POINTER:
107565 + case BUILT_IN_EH_COPY_VALUES:
107566 + return true;
107567 +
107568 + default:
107569 + return false;
107570 + }
107571 +}
107572 +#endif
107573 +
107574 +#if BUILDING_GCC_VERSION <= 4006
107575 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
107576 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
107577 +
107578 +// should come from c-tree.h if only it were installed for gcc 4.5...
107579 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
107580 +
107581 +#define get_random_seed(noinit) ({ \
107582 + unsigned HOST_WIDE_INT seed; \
107583 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
107584 + seed * seed; })
107585 +
107586 +static inline bool gimple_clobber_p(gimple s)
107587 +{
107588 + return false;
107589 +}
107590 +
107591 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
107592 +{
107593 + return implicit_built_in_decls[fncode];
107594 +}
107595 +
107596 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
107597 +{
107598 + struct cgraph_node *node = cgraph_get_node(decl);
107599 +
107600 + return node ? node : cgraph_node(decl);
107601 +}
107602 +
107603 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
107604 +{
107605 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
107606 +}
107607 +
107608 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
107609 +{
107610 + struct cgraph_node *node;
107611 +
107612 + for (node = cgraph_nodes; node; node = node->next)
107613 + if (cgraph_function_with_gimple_body_p(node))
107614 + return node;
107615 + return NULL;
107616 +}
107617 +
107618 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
107619 +{
107620 + for (node = node->next; node; node = node->next)
107621 + if (cgraph_function_with_gimple_body_p(node))
107622 + return node;
107623 + return NULL;
107624 +}
107625 +
107626 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
107627 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
107628 + (node) = cgraph_next_function_with_gimple_body(node))
107629 +#endif
107630 +
107631 +#if BUILDING_GCC_VERSION == 4006
107632 +extern void debug_gimple_stmt(gimple);
107633 +extern void debug_gimple_seq(gimple_seq);
107634 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
107635 +extern void print_gimple_stmt(FILE *, gimple, int, int);
107636 +extern void print_gimple_expr(FILE *, gimple, int, int);
107637 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
107638 +#endif
107639 +
107640 +#if BUILDING_GCC_VERSION <= 4007
107641 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
107642 +#define PROP_loops 0
107643 +
107644 +static inline int bb_loop_depth(const_basic_block bb)
107645 +{
107646 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
107647 +}
107648 +
107649 +static inline bool gimple_store_p(gimple gs)
107650 +{
107651 + tree lhs = gimple_get_lhs(gs);
107652 + return lhs && !is_gimple_reg(lhs);
107653 +}
107654 +#endif
107655 +
107656 +#if BUILDING_GCC_VERSION >= 4007
107657 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
107658 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
107659 +#endif
107660 +
107661 +#if BUILDING_GCC_VERSION <= 4008
107662 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
107663 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
107664 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
107665 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
107666 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
107667 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
107668 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
107669 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
107670 +
107671 +static inline const char *get_tree_code_name(enum tree_code code)
107672 +{
107673 + gcc_assert(code < MAX_TREE_CODES);
107674 + return tree_code_name[code];
107675 +}
107676 +
107677 +#define ipa_remove_stmt_references(cnode, stmt)
107678 +#endif
107679 +
107680 +#if BUILDING_GCC_VERSION == 4008
107681 +#define NODE_DECL(node) node->symbol.decl
107682 +#else
107683 +#define NODE_DECL(node) node->decl
107684 +#endif
107685 +
107686 +#if BUILDING_GCC_VERSION >= 4008
107687 +#define add_referenced_var(var)
107688 +#define mark_sym_for_renaming(var)
107689 +#define varpool_mark_needed_node(node)
107690 +#define TODO_dump_func 0
107691 +#define TODO_dump_cgraph 0
107692 +#endif
107693 +
107694 +#if BUILDING_GCC_VERSION >= 4009
107695 +#define TODO_ggc_collect 0
107696 +#endif
107697 +
107698 +#endif
107699 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
107700 new file mode 100644
107701 index 0000000..7514850
107702 --- /dev/null
107703 +++ b/tools/gcc/gen-random-seed.sh
107704 @@ -0,0 +1,8 @@
107705 +#!/bin/sh
107706 +
107707 +if [ ! -f "$1" ]; then
107708 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
107709 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
107710 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
107711 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
107712 +fi
107713 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
107714 new file mode 100644
107715 index 0000000..d81c094
107716 --- /dev/null
107717 +++ b/tools/gcc/kallocstat_plugin.c
107718 @@ -0,0 +1,183 @@
107719 +/*
107720 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
107721 + * Licensed under the GPL v2
107722 + *
107723 + * Note: the choice of the license means that the compilation process is
107724 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107725 + * but for the kernel it doesn't matter since it doesn't link against
107726 + * any of the gcc libraries
107727 + *
107728 + * gcc plugin to find the distribution of k*alloc sizes
107729 + *
107730 + * TODO:
107731 + *
107732 + * BUGS:
107733 + * - none known
107734 + */
107735 +
107736 +#include "gcc-common.h"
107737 +
107738 +int plugin_is_GPL_compatible;
107739 +
107740 +static struct plugin_info kallocstat_plugin_info = {
107741 + .version = "201401260140",
107742 + .help = NULL
107743 +};
107744 +
107745 +static const char * const kalloc_functions[] = {
107746 + "__kmalloc",
107747 + "kmalloc",
107748 + "kmalloc_large",
107749 + "kmalloc_node",
107750 + "kmalloc_order",
107751 + "kmalloc_order_trace",
107752 + "kmalloc_slab",
107753 + "kzalloc",
107754 + "kzalloc_node",
107755 +};
107756 +
107757 +static bool is_kalloc(const char *fnname)
107758 +{
107759 + size_t i;
107760 +
107761 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
107762 + if (!strcmp(fnname, kalloc_functions[i]))
107763 + return true;
107764 + return false;
107765 +}
107766 +
107767 +static unsigned int execute_kallocstat(void)
107768 +{
107769 + basic_block bb;
107770 +
107771 + // 1. loop through BBs and GIMPLE statements
107772 + FOR_EACH_BB_FN(bb, cfun) {
107773 + gimple_stmt_iterator gsi;
107774 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
107775 + // gimple match:
107776 + tree fndecl, size;
107777 + gimple stmt;
107778 + const char *fnname;
107779 +
107780 + // is it a call
107781 + stmt = gsi_stmt(gsi);
107782 + if (!is_gimple_call(stmt))
107783 + continue;
107784 + fndecl = gimple_call_fndecl(stmt);
107785 + if (fndecl == NULL_TREE)
107786 + continue;
107787 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
107788 + continue;
107789 +
107790 + // is it a call to k*alloc
107791 + fnname = DECL_NAME_POINTER(fndecl);
107792 + if (!is_kalloc(fnname))
107793 + continue;
107794 +
107795 + // is the size arg const or the result of a simple const assignment
107796 + size = gimple_call_arg(stmt, 0);
107797 + while (true) {
107798 + expanded_location xloc;
107799 + size_t size_val;
107800 +
107801 + if (TREE_CONSTANT(size)) {
107802 + xloc = expand_location(gimple_location(stmt));
107803 + if (!xloc.file)
107804 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
107805 + size_val = TREE_INT_CST_LOW(size);
107806 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
107807 + break;
107808 + }
107809 +
107810 + if (TREE_CODE(size) != SSA_NAME)
107811 + break;
107812 + stmt = SSA_NAME_DEF_STMT(size);
107813 +//debug_gimple_stmt(stmt);
107814 +//debug_tree(size);
107815 + if (!stmt || !is_gimple_assign(stmt))
107816 + break;
107817 + if (gimple_num_ops(stmt) != 2)
107818 + break;
107819 + size = gimple_assign_rhs1(stmt);
107820 + }
107821 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
107822 +//debug_tree(gimple_call_fn(call_stmt));
107823 +//print_node(stderr, "pax", fndecl, 4);
107824 + }
107825 + }
107826 +
107827 + return 0;
107828 +}
107829 +
107830 +#if BUILDING_GCC_VERSION >= 4009
107831 +static const struct pass_data kallocstat_pass_data = {
107832 +#else
107833 +static struct gimple_opt_pass kallocstat_pass = {
107834 + .pass = {
107835 +#endif
107836 + .type = GIMPLE_PASS,
107837 + .name = "kallocstat",
107838 +#if BUILDING_GCC_VERSION >= 4008
107839 + .optinfo_flags = OPTGROUP_NONE,
107840 +#endif
107841 +#if BUILDING_GCC_VERSION >= 4009
107842 + .has_gate = false,
107843 + .has_execute = true,
107844 +#else
107845 + .gate = NULL,
107846 + .execute = execute_kallocstat,
107847 + .sub = NULL,
107848 + .next = NULL,
107849 + .static_pass_number = 0,
107850 +#endif
107851 + .tv_id = TV_NONE,
107852 + .properties_required = 0,
107853 + .properties_provided = 0,
107854 + .properties_destroyed = 0,
107855 + .todo_flags_start = 0,
107856 + .todo_flags_finish = 0
107857 +#if BUILDING_GCC_VERSION < 4009
107858 + }
107859 +#endif
107860 +};
107861 +
107862 +#if BUILDING_GCC_VERSION >= 4009
107863 +namespace {
107864 +class kallocstat_pass : public gimple_opt_pass {
107865 +public:
107866 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
107867 + unsigned int execute() { return execute_kallocstat(); }
107868 +};
107869 +}
107870 +
107871 +static opt_pass *make_kallocstat_pass(void)
107872 +{
107873 + return new kallocstat_pass();
107874 +}
107875 +#else
107876 +static struct opt_pass *make_kallocstat_pass(void)
107877 +{
107878 + return &kallocstat_pass.pass;
107879 +}
107880 +#endif
107881 +
107882 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107883 +{
107884 + const char * const plugin_name = plugin_info->base_name;
107885 + struct register_pass_info kallocstat_pass_info;
107886 +
107887 + kallocstat_pass_info.pass = make_kallocstat_pass();
107888 + kallocstat_pass_info.reference_pass_name = "ssa";
107889 + kallocstat_pass_info.ref_pass_instance_number = 1;
107890 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107891 +
107892 + if (!plugin_default_version_check(version, &gcc_version)) {
107893 + error(G_("incompatible gcc/plugin versions"));
107894 + return 1;
107895 + }
107896 +
107897 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
107898 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
107899 +
107900 + return 0;
107901 +}
107902 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
107903 new file mode 100644
107904 index 0000000..89f256d
107905 --- /dev/null
107906 +++ b/tools/gcc/kernexec_plugin.c
107907 @@ -0,0 +1,522 @@
107908 +/*
107909 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
107910 + * Licensed under the GPL v2
107911 + *
107912 + * Note: the choice of the license means that the compilation process is
107913 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107914 + * but for the kernel it doesn't matter since it doesn't link against
107915 + * any of the gcc libraries
107916 + *
107917 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
107918 + *
107919 + * TODO:
107920 + *
107921 + * BUGS:
107922 + * - none known
107923 + */
107924 +
107925 +#include "gcc-common.h"
107926 +
107927 +int plugin_is_GPL_compatible;
107928 +
107929 +static struct plugin_info kernexec_plugin_info = {
107930 + .version = "201401260140",
107931 + .help = "method=[bts|or]\tinstrumentation method\n"
107932 +};
107933 +
107934 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
107935 +static void (*kernexec_instrument_retaddr)(rtx);
107936 +
107937 +/*
107938 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
107939 + */
107940 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
107941 +{
107942 + gimple asm_movabs_stmt;
107943 +
107944 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
107945 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
107946 + gimple_asm_set_volatile(asm_movabs_stmt, true);
107947 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
107948 + update_stmt(asm_movabs_stmt);
107949 +}
107950 +
107951 +/*
107952 + * find all asm() stmts that clobber r12 and add a reload of r12
107953 + */
107954 +static unsigned int execute_kernexec_reload(void)
107955 +{
107956 + basic_block bb;
107957 +
107958 + // 1. loop through BBs and GIMPLE statements
107959 + FOR_EACH_BB_FN(bb, cfun) {
107960 + gimple_stmt_iterator gsi;
107961 +
107962 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
107963 + // gimple match: __asm__ ("" : : : "r12");
107964 + gimple asm_stmt;
107965 + size_t nclobbers;
107966 +
107967 + // is it an asm ...
107968 + asm_stmt = gsi_stmt(gsi);
107969 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
107970 + continue;
107971 +
107972 + // ... clobbering r12
107973 + nclobbers = gimple_asm_nclobbers(asm_stmt);
107974 + while (nclobbers--) {
107975 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
107976 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
107977 + continue;
107978 + kernexec_reload_fptr_mask(&gsi);
107979 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
107980 + break;
107981 + }
107982 + }
107983 + }
107984 +
107985 + return 0;
107986 +}
107987 +
107988 +/*
107989 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
107990 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
107991 + */
107992 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
107993 +{
107994 + gimple assign_intptr, assign_new_fptr, call_stmt;
107995 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
107996 +
107997 + call_stmt = gsi_stmt(*gsi);
107998 + old_fptr = gimple_call_fn(call_stmt);
107999 +
108000 + // create temporary unsigned long variable used for bitops and cast fptr to it
108001 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
108002 + add_referenced_var(intptr);
108003 + intptr = make_ssa_name(intptr, NULL);
108004 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
108005 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108006 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108007 + update_stmt(assign_intptr);
108008 +
108009 + // apply logical or to temporary unsigned long and bitmask
108010 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
108011 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
108012 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
108013 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
108014 + assign_intptr = gimple_build_assign(intptr, orptr);
108015 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108016 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108017 + update_stmt(assign_intptr);
108018 +
108019 + // cast temporary unsigned long back to a temporary fptr variable
108020 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
108021 + add_referenced_var(new_fptr);
108022 + new_fptr = make_ssa_name(new_fptr, NULL);
108023 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
108024 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
108025 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
108026 + update_stmt(assign_new_fptr);
108027 +
108028 + // replace call stmt fn with the new fptr
108029 + gimple_call_set_fn(call_stmt, new_fptr);
108030 + update_stmt(call_stmt);
108031 +}
108032 +
108033 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
108034 +{
108035 + gimple asm_or_stmt, call_stmt;
108036 + tree old_fptr, new_fptr, input, output;
108037 +#if BUILDING_GCC_VERSION <= 4007
108038 + VEC(tree, gc) *inputs = NULL;
108039 + VEC(tree, gc) *outputs = NULL;
108040 +#else
108041 + vec<tree, va_gc> *inputs = NULL;
108042 + vec<tree, va_gc> *outputs = NULL;
108043 +#endif
108044 +
108045 + call_stmt = gsi_stmt(*gsi);
108046 + old_fptr = gimple_call_fn(call_stmt);
108047 +
108048 + // create temporary fptr variable
108049 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
108050 + add_referenced_var(new_fptr);
108051 + new_fptr = make_ssa_name(new_fptr, NULL);
108052 +
108053 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
108054 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
108055 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
108056 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
108057 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
108058 +#if BUILDING_GCC_VERSION <= 4007
108059 + VEC_safe_push(tree, gc, inputs, input);
108060 + VEC_safe_push(tree, gc, outputs, output);
108061 +#else
108062 + vec_safe_push(inputs, input);
108063 + vec_safe_push(outputs, output);
108064 +#endif
108065 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
108066 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
108067 + gimple_asm_set_volatile(asm_or_stmt, true);
108068 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
108069 + update_stmt(asm_or_stmt);
108070 +
108071 + // replace call stmt fn with the new fptr
108072 + gimple_call_set_fn(call_stmt, new_fptr);
108073 + update_stmt(call_stmt);
108074 +}
108075 +
108076 +/*
108077 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
108078 + */
108079 +static unsigned int execute_kernexec_fptr(void)
108080 +{
108081 + basic_block bb;
108082 +
108083 + // 1. loop through BBs and GIMPLE statements
108084 + FOR_EACH_BB_FN(bb, cfun) {
108085 + gimple_stmt_iterator gsi;
108086 +
108087 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108088 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
108089 + tree fn;
108090 + gimple call_stmt;
108091 +
108092 + // is it a call ...
108093 + call_stmt = gsi_stmt(gsi);
108094 + if (!is_gimple_call(call_stmt))
108095 + continue;
108096 + fn = gimple_call_fn(call_stmt);
108097 + if (TREE_CODE(fn) == ADDR_EXPR)
108098 + continue;
108099 + if (TREE_CODE(fn) != SSA_NAME)
108100 + gcc_unreachable();
108101 +
108102 + // ... through a function pointer
108103 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
108104 + fn = SSA_NAME_VAR(fn);
108105 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
108106 + debug_tree(fn);
108107 + gcc_unreachable();
108108 + }
108109 + }
108110 + fn = TREE_TYPE(fn);
108111 + if (TREE_CODE(fn) != POINTER_TYPE)
108112 + continue;
108113 + fn = TREE_TYPE(fn);
108114 + if (TREE_CODE(fn) != FUNCTION_TYPE)
108115 + continue;
108116 +
108117 + kernexec_instrument_fptr(&gsi);
108118 +
108119 +//debug_tree(gimple_call_fn(call_stmt));
108120 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
108121 + }
108122 + }
108123 +
108124 + return 0;
108125 +}
108126 +
108127 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
108128 +static void kernexec_instrument_retaddr_bts(rtx insn)
108129 +{
108130 + rtx btsq;
108131 + rtvec argvec, constraintvec, labelvec;
108132 + int line;
108133 +
108134 + // create asm volatile("btsq $63,(%%rsp)":::)
108135 + argvec = rtvec_alloc(0);
108136 + constraintvec = rtvec_alloc(0);
108137 + labelvec = rtvec_alloc(0);
108138 + line = expand_location(RTL_LOCATION(insn)).line;
108139 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
108140 + MEM_VOLATILE_P(btsq) = 1;
108141 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
108142 + emit_insn_before(btsq, insn);
108143 +}
108144 +
108145 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
108146 +static void kernexec_instrument_retaddr_or(rtx insn)
108147 +{
108148 + rtx orq;
108149 + rtvec argvec, constraintvec, labelvec;
108150 + int line;
108151 +
108152 + // create asm volatile("orq %%r12,(%%rsp)":::)
108153 + argvec = rtvec_alloc(0);
108154 + constraintvec = rtvec_alloc(0);
108155 + labelvec = rtvec_alloc(0);
108156 + line = expand_location(RTL_LOCATION(insn)).line;
108157 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
108158 + MEM_VOLATILE_P(orq) = 1;
108159 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
108160 + emit_insn_before(orq, insn);
108161 +}
108162 +
108163 +/*
108164 + * find all asm level function returns and forcibly set the highest bit of the return address
108165 + */
108166 +static unsigned int execute_kernexec_retaddr(void)
108167 +{
108168 + rtx insn;
108169 +
108170 +// if (stack_realign_drap)
108171 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
108172 +
108173 + // 1. find function returns
108174 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
108175 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
108176 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
108177 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
108178 + rtx body;
108179 +
108180 + // is it a retn
108181 + if (!JUMP_P(insn))
108182 + continue;
108183 + body = PATTERN(insn);
108184 + if (GET_CODE(body) == PARALLEL)
108185 + body = XVECEXP(body, 0, 0);
108186 + if (!ANY_RETURN_P(body))
108187 + continue;
108188 + kernexec_instrument_retaddr(insn);
108189 + }
108190 +
108191 +// print_simple_rtl(stderr, get_insns());
108192 +// print_rtl(stderr, get_insns());
108193 +
108194 + return 0;
108195 +}
108196 +
108197 +static bool kernexec_cmodel_check(void)
108198 +{
108199 + tree section;
108200 +
108201 + if (ix86_cmodel != CM_KERNEL)
108202 + return false;
108203 +
108204 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
108205 + if (!section || !TREE_VALUE(section))
108206 + return true;
108207 +
108208 + section = TREE_VALUE(TREE_VALUE(section));
108209 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
108210 + return true;
108211 +
108212 + return false;
108213 +}
108214 +
108215 +#if BUILDING_GCC_VERSION >= 4009
108216 +static const struct pass_data kernexec_reload_pass_data = {
108217 +#else
108218 +static struct gimple_opt_pass kernexec_reload_pass = {
108219 + .pass = {
108220 +#endif
108221 + .type = GIMPLE_PASS,
108222 + .name = "kernexec_reload",
108223 +#if BUILDING_GCC_VERSION >= 4008
108224 + .optinfo_flags = OPTGROUP_NONE,
108225 +#endif
108226 +#if BUILDING_GCC_VERSION >= 4009
108227 + .has_gate = true,
108228 + .has_execute = true,
108229 +#else
108230 + .gate = kernexec_cmodel_check,
108231 + .execute = execute_kernexec_reload,
108232 + .sub = NULL,
108233 + .next = NULL,
108234 + .static_pass_number = 0,
108235 +#endif
108236 + .tv_id = TV_NONE,
108237 + .properties_required = 0,
108238 + .properties_provided = 0,
108239 + .properties_destroyed = 0,
108240 + .todo_flags_start = 0,
108241 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
108242 +#if BUILDING_GCC_VERSION < 4009
108243 + }
108244 +#endif
108245 +};
108246 +
108247 +#if BUILDING_GCC_VERSION >= 4009
108248 +static const struct pass_data kernexec_fptr_pass_data = {
108249 +#else
108250 +static struct gimple_opt_pass kernexec_fptr_pass = {
108251 + .pass = {
108252 +#endif
108253 + .type = GIMPLE_PASS,
108254 + .name = "kernexec_fptr",
108255 +#if BUILDING_GCC_VERSION >= 4008
108256 + .optinfo_flags = OPTGROUP_NONE,
108257 +#endif
108258 +#if BUILDING_GCC_VERSION >= 4009
108259 + .has_gate = true,
108260 + .has_execute = true,
108261 +#else
108262 + .gate = kernexec_cmodel_check,
108263 + .execute = execute_kernexec_fptr,
108264 + .sub = NULL,
108265 + .next = NULL,
108266 + .static_pass_number = 0,
108267 +#endif
108268 + .tv_id = TV_NONE,
108269 + .properties_required = 0,
108270 + .properties_provided = 0,
108271 + .properties_destroyed = 0,
108272 + .todo_flags_start = 0,
108273 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
108274 +#if BUILDING_GCC_VERSION < 4009
108275 + }
108276 +#endif
108277 +};
108278 +
108279 +#if BUILDING_GCC_VERSION >= 4009
108280 +static const struct pass_data kernexec_retaddr_pass_data = {
108281 +#else
108282 +static struct rtl_opt_pass kernexec_retaddr_pass = {
108283 + .pass = {
108284 +#endif
108285 + .type = RTL_PASS,
108286 + .name = "kernexec_retaddr",
108287 +#if BUILDING_GCC_VERSION >= 4008
108288 + .optinfo_flags = OPTGROUP_NONE,
108289 +#endif
108290 +#if BUILDING_GCC_VERSION >= 4009
108291 + .has_gate = true,
108292 + .has_execute = true,
108293 +#else
108294 + .gate = kernexec_cmodel_check,
108295 + .execute = execute_kernexec_retaddr,
108296 + .sub = NULL,
108297 + .next = NULL,
108298 + .static_pass_number = 0,
108299 +#endif
108300 + .tv_id = TV_NONE,
108301 + .properties_required = 0,
108302 + .properties_provided = 0,
108303 + .properties_destroyed = 0,
108304 + .todo_flags_start = 0,
108305 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
108306 +#if BUILDING_GCC_VERSION < 4009
108307 + }
108308 +#endif
108309 +};
108310 +
108311 +#if BUILDING_GCC_VERSION >= 4009
108312 +namespace {
108313 +class kernexec_reload_pass : public gimple_opt_pass {
108314 +public:
108315 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
108316 + bool gate() { return kernexec_cmodel_check(); }
108317 + unsigned int execute() { return execute_kernexec_reload(); }
108318 +};
108319 +
108320 +class kernexec_fptr_pass : public gimple_opt_pass {
108321 +public:
108322 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
108323 + bool gate() { return kernexec_cmodel_check(); }
108324 + unsigned int execute() { return execute_kernexec_fptr(); }
108325 +};
108326 +
108327 +class kernexec_retaddr_pass : public rtl_opt_pass {
108328 +public:
108329 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
108330 + bool gate() { return kernexec_cmodel_check(); }
108331 + unsigned int execute() { return execute_kernexec_retaddr(); }
108332 +};
108333 +}
108334 +
108335 +static opt_pass *make_kernexec_reload_pass(void)
108336 +{
108337 + return new kernexec_reload_pass();
108338 +}
108339 +
108340 +static opt_pass *make_kernexec_fptr_pass(void)
108341 +{
108342 + return new kernexec_fptr_pass();
108343 +}
108344 +
108345 +static opt_pass *make_kernexec_retaddr_pass(void)
108346 +{
108347 + return new kernexec_retaddr_pass();
108348 +}
108349 +#else
108350 +static struct opt_pass *make_kernexec_reload_pass(void)
108351 +{
108352 + return &kernexec_reload_pass.pass;
108353 +}
108354 +
108355 +static struct opt_pass *make_kernexec_fptr_pass(void)
108356 +{
108357 + return &kernexec_fptr_pass.pass;
108358 +}
108359 +
108360 +static struct opt_pass *make_kernexec_retaddr_pass(void)
108361 +{
108362 + return &kernexec_retaddr_pass.pass;
108363 +}
108364 +#endif
108365 +
108366 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108367 +{
108368 + const char * const plugin_name = plugin_info->base_name;
108369 + const int argc = plugin_info->argc;
108370 + const struct plugin_argument * const argv = plugin_info->argv;
108371 + int i;
108372 + struct register_pass_info kernexec_reload_pass_info;
108373 + struct register_pass_info kernexec_fptr_pass_info;
108374 + struct register_pass_info kernexec_retaddr_pass_info;
108375 +
108376 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
108377 + kernexec_reload_pass_info.reference_pass_name = "ssa";
108378 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
108379 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108380 +
108381 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
108382 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
108383 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
108384 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108385 +
108386 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
108387 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
108388 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
108389 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108390 +
108391 + if (!plugin_default_version_check(version, &gcc_version)) {
108392 + error(G_("incompatible gcc/plugin versions"));
108393 + return 1;
108394 + }
108395 +
108396 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
108397 +
108398 + if (TARGET_64BIT == 0)
108399 + return 0;
108400 +
108401 + for (i = 0; i < argc; ++i) {
108402 + if (!strcmp(argv[i].key, "method")) {
108403 + if (!argv[i].value) {
108404 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108405 + continue;
108406 + }
108407 + if (!strcmp(argv[i].value, "bts")) {
108408 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
108409 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
108410 + } else if (!strcmp(argv[i].value, "or")) {
108411 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
108412 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
108413 + fix_register("r12", 1, 1);
108414 + } else
108415 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
108416 + continue;
108417 + }
108418 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108419 + }
108420 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
108421 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
108422 +
108423 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
108424 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
108425 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
108426 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
108427 +
108428 + return 0;
108429 +}
108430 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
108431 new file mode 100644
108432 index 0000000..39d7cc7
108433 --- /dev/null
108434 +++ b/tools/gcc/latent_entropy_plugin.c
108435 @@ -0,0 +1,462 @@
108436 +/*
108437 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
108438 + * Licensed under the GPL v2
108439 + *
108440 + * Note: the choice of the license means that the compilation process is
108441 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108442 + * but for the kernel it doesn't matter since it doesn't link against
108443 + * any of the gcc libraries
108444 + *
108445 + * gcc plugin to help generate a little bit of entropy from program state,
108446 + * used throughout the uptime of the kernel
108447 + *
108448 + * TODO:
108449 + * - add ipa pass to identify not explicitly marked candidate functions
108450 + * - mix in more program state (function arguments/return values, loop variables, etc)
108451 + * - more instrumentation control via attribute parameters
108452 + *
108453 + * BUGS:
108454 + * - LTO needs -flto-partition=none for now
108455 + */
108456 +
108457 +#include "gcc-common.h"
108458 +
108459 +int plugin_is_GPL_compatible;
108460 +
108461 +static tree latent_entropy_decl;
108462 +
108463 +static struct plugin_info latent_entropy_plugin_info = {
108464 + .version = "201403280150",
108465 + .help = NULL
108466 +};
108467 +
108468 +static unsigned HOST_WIDE_INT seed;
108469 +static unsigned HOST_WIDE_INT get_random_const(void)
108470 +{
108471 + unsigned int i;
108472 + unsigned HOST_WIDE_INT ret = 0;
108473 +
108474 + for (i = 0; i < 8 * sizeof ret; i++) {
108475 + ret = (ret << 1) | (seed & 1);
108476 + seed >>= 1;
108477 + if (ret & 1)
108478 + seed ^= 0xD800000000000000ULL;
108479 + }
108480 +
108481 + return ret;
108482 +}
108483 +
108484 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
108485 +{
108486 + tree type;
108487 + unsigned long long mask;
108488 +#if BUILDING_GCC_VERSION <= 4007
108489 + VEC(constructor_elt, gc) *vals;
108490 +#else
108491 + vec<constructor_elt, va_gc> *vals;
108492 +#endif
108493 +
108494 + switch (TREE_CODE(*node)) {
108495 + default:
108496 + *no_add_attrs = true;
108497 + error("%qE attribute only applies to functions and variables", name);
108498 + break;
108499 +
108500 + case VAR_DECL:
108501 + if (DECL_INITIAL(*node)) {
108502 + *no_add_attrs = true;
108503 + error("variable %qD with %qE attribute must not be initialized", *node, name);
108504 + break;
108505 + }
108506 +
108507 + if (!TREE_STATIC(*node)) {
108508 + *no_add_attrs = true;
108509 + error("variable %qD with %qE attribute must not be local", *node, name);
108510 + break;
108511 + }
108512 +
108513 + type = TREE_TYPE(*node);
108514 + switch (TREE_CODE(type)) {
108515 + default:
108516 + *no_add_attrs = true;
108517 + 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);
108518 + break;
108519 +
108520 + case RECORD_TYPE: {
108521 + tree field;
108522 + unsigned int nelt = 0;
108523 +
108524 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
108525 + tree fieldtype;
108526 +
108527 + fieldtype = TREE_TYPE(field);
108528 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
108529 + *no_add_attrs = true;
108530 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
108531 + break;
108532 + }
108533 + }
108534 +
108535 + if (field)
108536 + break;
108537 +
108538 +#if BUILDING_GCC_VERSION <= 4007
108539 + vals = VEC_alloc(constructor_elt, gc, nelt);
108540 +#else
108541 + vec_alloc(vals, nelt);
108542 +#endif
108543 +
108544 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
108545 + tree fieldtype;
108546 +
108547 + fieldtype = TREE_TYPE(field);
108548 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
108549 + mask = 2 * (mask - 1) + 1;
108550 +
108551 + if (TYPE_UNSIGNED(fieldtype))
108552 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
108553 + else
108554 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
108555 + }
108556 +
108557 + DECL_INITIAL(*node) = build_constructor(type, vals);
108558 +//debug_tree(DECL_INITIAL(*node));
108559 + break;
108560 + }
108561 +
108562 + case INTEGER_TYPE:
108563 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
108564 + mask = 2 * (mask - 1) + 1;
108565 +
108566 + if (TYPE_UNSIGNED(type))
108567 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
108568 + else
108569 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
108570 + break;
108571 +
108572 + case ARRAY_TYPE: {
108573 + tree elt_type, array_size, elt_size;
108574 + unsigned int i, nelt;
108575 +
108576 + elt_type = TREE_TYPE(type);
108577 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
108578 + array_size = TYPE_SIZE_UNIT(type);
108579 +
108580 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
108581 + *no_add_attrs = true;
108582 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
108583 + break;
108584 + }
108585 +
108586 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
108587 +#if BUILDING_GCC_VERSION <= 4007
108588 + vals = VEC_alloc(constructor_elt, gc, nelt);
108589 +#else
108590 + vec_alloc(vals, nelt);
108591 +#endif
108592 +
108593 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
108594 + mask = 2 * (mask - 1) + 1;
108595 +
108596 + for (i = 0; i < nelt; i++)
108597 + if (TYPE_UNSIGNED(elt_type))
108598 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
108599 + else
108600 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
108601 +
108602 + DECL_INITIAL(*node) = build_constructor(type, vals);
108603 +//debug_tree(DECL_INITIAL(*node));
108604 + break;
108605 + }
108606 + }
108607 + break;
108608 +
108609 + case FUNCTION_DECL:
108610 + break;
108611 + }
108612 +
108613 + return NULL_TREE;
108614 +}
108615 +
108616 +static struct attribute_spec latent_entropy_attr = {
108617 + .name = "latent_entropy",
108618 + .min_length = 0,
108619 + .max_length = 0,
108620 + .decl_required = true,
108621 + .type_required = false,
108622 + .function_type_required = false,
108623 + .handler = handle_latent_entropy_attribute,
108624 +#if BUILDING_GCC_VERSION >= 4007
108625 + .affects_type_identity = false
108626 +#endif
108627 +};
108628 +
108629 +static void register_attributes(void *event_data, void *data)
108630 +{
108631 + register_attribute(&latent_entropy_attr);
108632 +}
108633 +
108634 +static bool gate_latent_entropy(void)
108635 +{
108636 + // don't bother with noreturn functions for now
108637 + if (TREE_THIS_VOLATILE(current_function_decl))
108638 + return false;
108639 +
108640 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
108641 +}
108642 +
108643 +static enum tree_code get_op(tree *rhs)
108644 +{
108645 + static enum tree_code op;
108646 + unsigned HOST_WIDE_INT random_const;
108647 +
108648 + random_const = get_random_const();
108649 +
108650 + switch (op) {
108651 + case BIT_XOR_EXPR:
108652 + op = PLUS_EXPR;
108653 + break;
108654 +
108655 + case PLUS_EXPR:
108656 + if (rhs) {
108657 + op = LROTATE_EXPR;
108658 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
108659 + break;
108660 + }
108661 +
108662 + case LROTATE_EXPR:
108663 + default:
108664 + op = BIT_XOR_EXPR;
108665 + break;
108666 + }
108667 + if (rhs)
108668 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
108669 + return op;
108670 +}
108671 +
108672 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
108673 +{
108674 + gimple_stmt_iterator gsi;
108675 + gimple assign;
108676 + tree addxorrol, rhs;
108677 + enum tree_code op;
108678 +
108679 + op = get_op(&rhs);
108680 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
108681 + assign = gimple_build_assign(local_entropy, addxorrol);
108682 + gsi = gsi_after_labels(bb);
108683 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
108684 + update_stmt(assign);
108685 +//debug_bb(bb);
108686 +}
108687 +
108688 +static void perturb_latent_entropy(basic_block bb, tree rhs)
108689 +{
108690 + gimple_stmt_iterator gsi;
108691 + gimple assign;
108692 + tree addxorrol, temp;
108693 +
108694 + // 1. create temporary copy of latent_entropy
108695 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
108696 + add_referenced_var(temp);
108697 +
108698 + // 2. read...
108699 + temp = make_ssa_name(temp, NULL);
108700 + assign = gimple_build_assign(temp, latent_entropy_decl);
108701 + SSA_NAME_DEF_STMT(temp) = assign;
108702 + add_referenced_var(latent_entropy_decl);
108703 + gsi = gsi_after_labels(bb);
108704 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
108705 + update_stmt(assign);
108706 +
108707 + // 3. ...modify...
108708 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
108709 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
108710 + assign = gimple_build_assign(temp, addxorrol);
108711 + SSA_NAME_DEF_STMT(temp) = assign;
108712 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
108713 + update_stmt(assign);
108714 +
108715 + // 4. ...write latent_entropy
108716 + assign = gimple_build_assign(latent_entropy_decl, temp);
108717 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
108718 + update_stmt(assign);
108719 +}
108720 +
108721 +static unsigned int execute_latent_entropy(void)
108722 +{
108723 + basic_block bb;
108724 + gimple assign;
108725 + gimple_stmt_iterator gsi;
108726 + tree local_entropy;
108727 +
108728 + if (!latent_entropy_decl) {
108729 +#if BUILDING_GCC_VERSION >= 4009
108730 + varpool_node *node;
108731 +#else
108732 + struct varpool_node *node;
108733 +#endif
108734 +
108735 + FOR_EACH_VARIABLE(node) {
108736 + tree var = NODE_DECL(node);
108737 +
108738 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
108739 + continue;
108740 + latent_entropy_decl = var;
108741 +// debug_tree(var);
108742 + break;
108743 + }
108744 + if (!latent_entropy_decl) {
108745 +// debug_tree(current_function_decl);
108746 + return 0;
108747 + }
108748 + }
108749 +
108750 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
108751 +
108752 + // 1. create local entropy variable
108753 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
108754 + add_referenced_var(local_entropy);
108755 + mark_sym_for_renaming(local_entropy);
108756 +
108757 + // 2. initialize local entropy variable
108758 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
108759 + if (dom_info_available_p(CDI_DOMINATORS))
108760 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
108761 + gsi = gsi_start_bb(bb);
108762 +
108763 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
108764 +// gimple_set_location(assign, loc);
108765 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
108766 + update_stmt(assign);
108767 +//debug_bb(bb);
108768 + gcc_assert(single_succ_p(bb));
108769 + bb = single_succ(bb);
108770 +
108771 + // 3. instrument each BB with an operation on the local entropy variable
108772 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
108773 + perturb_local_entropy(bb, local_entropy);
108774 +//debug_bb(bb);
108775 + bb = bb->next_bb;
108776 + };
108777 +
108778 + // 4. mix local entropy into the global entropy variable
108779 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
108780 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
108781 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
108782 + return 0;
108783 +}
108784 +
108785 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
108786 +{
108787 + tree latent_entropy_type;
108788 +
108789 + seed = get_random_seed(false);
108790 +
108791 + if (in_lto_p)
108792 + return;
108793 +
108794 + // extern volatile u64 latent_entropy
108795 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
108796 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
108797 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
108798 +
108799 + TREE_STATIC(latent_entropy_decl) = 1;
108800 + TREE_PUBLIC(latent_entropy_decl) = 1;
108801 + TREE_USED(latent_entropy_decl) = 1;
108802 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
108803 + DECL_EXTERNAL(latent_entropy_decl) = 1;
108804 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
108805 + lang_hooks.decls.pushdecl(latent_entropy_decl);
108806 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
108807 +// varpool_finalize_decl(latent_entropy_decl);
108808 +// varpool_mark_needed_node(latent_entropy_decl);
108809 +}
108810 +
108811 +#if BUILDING_GCC_VERSION >= 4009
108812 +static const struct pass_data latent_entropy_pass_data = {
108813 +#else
108814 +static struct gimple_opt_pass latent_entropy_pass = {
108815 + .pass = {
108816 +#endif
108817 + .type = GIMPLE_PASS,
108818 + .name = "latent_entropy",
108819 +#if BUILDING_GCC_VERSION >= 4008
108820 + .optinfo_flags = OPTGROUP_NONE,
108821 +#endif
108822 +#if BUILDING_GCC_VERSION >= 4009
108823 + .has_gate = true,
108824 + .has_execute = true,
108825 +#else
108826 + .gate = gate_latent_entropy,
108827 + .execute = execute_latent_entropy,
108828 + .sub = NULL,
108829 + .next = NULL,
108830 + .static_pass_number = 0,
108831 +#endif
108832 + .tv_id = TV_NONE,
108833 + .properties_required = PROP_gimple_leh | PROP_cfg,
108834 + .properties_provided = 0,
108835 + .properties_destroyed = 0,
108836 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
108837 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
108838 +#if BUILDING_GCC_VERSION < 4009
108839 + }
108840 +#endif
108841 +};
108842 +
108843 +#if BUILDING_GCC_VERSION >= 4009
108844 +namespace {
108845 +class latent_entropy_pass : public gimple_opt_pass {
108846 +public:
108847 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
108848 + bool gate() { return gate_latent_entropy(); }
108849 + unsigned int execute() { return execute_latent_entropy(); }
108850 +};
108851 +}
108852 +
108853 +static opt_pass *make_latent_entropy_pass(void)
108854 +{
108855 + return new latent_entropy_pass();
108856 +}
108857 +#else
108858 +static struct opt_pass *make_latent_entropy_pass(void)
108859 +{
108860 + return &latent_entropy_pass.pass;
108861 +}
108862 +#endif
108863 +
108864 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108865 +{
108866 + const char * const plugin_name = plugin_info->base_name;
108867 + struct register_pass_info latent_entropy_pass_info;
108868 +
108869 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
108870 + latent_entropy_pass_info.reference_pass_name = "optimized";
108871 + latent_entropy_pass_info.ref_pass_instance_number = 1;
108872 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
108873 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
108874 + {
108875 + .base = &latent_entropy_decl,
108876 + .nelt = 1,
108877 + .stride = sizeof(latent_entropy_decl),
108878 + .cb = &gt_ggc_mx_tree_node,
108879 + .pchw = &gt_pch_nx_tree_node
108880 + },
108881 + LAST_GGC_ROOT_TAB
108882 + };
108883 +
108884 + if (!plugin_default_version_check(version, &gcc_version)) {
108885 + error(G_("incompatible gcc/plugin versions"));
108886 + return 1;
108887 + }
108888 +
108889 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
108890 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
108891 + if (!in_lto_p)
108892 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
108893 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
108894 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
108895 +
108896 + return 0;
108897 +}
108898 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
108899 new file mode 100644
108900 index 0000000..8dafb22
108901 --- /dev/null
108902 +++ b/tools/gcc/randomize_layout_plugin.c
108903 @@ -0,0 +1,910 @@
108904 +/*
108905 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
108906 + * and PaX Team <pageexec@freemail.hu>
108907 + * Licensed under the GPL v2
108908 + *
108909 + * Usage:
108910 + * $ # for 4.5/4.6/C based 4.7
108911 + * $ 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
108912 + * $ # for C++ based 4.7/4.8+
108913 + * $ 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
108914 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
108915 + */
108916 +
108917 +#include "gcc-common.h"
108918 +#include "randomize_layout_seed.h"
108919 +
108920 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
108921 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
108922 +#endif
108923 +
108924 +#define ORIG_TYPE_NAME(node) \
108925 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
108926 +
108927 +int plugin_is_GPL_compatible;
108928 +
108929 +static int performance_mode;
108930 +
108931 +static struct plugin_info randomize_layout_plugin_info = {
108932 + .version = "201402201816",
108933 + .help = "disable\t\t\tdo not activate plugin\n"
108934 + "performance-mode\tenable cacheline-aware layout randomization\n"
108935 +};
108936 +
108937 +/* from old Linux dcache.h */
108938 +static inline unsigned long
108939 +partial_name_hash(unsigned long c, unsigned long prevhash)
108940 +{
108941 + return (prevhash + (c << 4) + (c >> 4)) * 11;
108942 +}
108943 +static inline unsigned int
108944 +name_hash(const unsigned char *name)
108945 +{
108946 + unsigned long hash = 0;
108947 + unsigned int len = strlen((const char *)name);
108948 + while (len--)
108949 + hash = partial_name_hash(*name++, hash);
108950 + return (unsigned int)hash;
108951 +}
108952 +
108953 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
108954 +{
108955 + tree type;
108956 +
108957 + *no_add_attrs = true;
108958 + if (TREE_CODE(*node) == FUNCTION_DECL) {
108959 + error("%qE attribute does not apply to functions (%qF)", name, *node);
108960 + return NULL_TREE;
108961 + }
108962 +
108963 + if (TREE_CODE(*node) == PARM_DECL) {
108964 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
108965 + return NULL_TREE;
108966 + }
108967 +
108968 + if (TREE_CODE(*node) == VAR_DECL) {
108969 + error("%qE attribute does not apply to variables (%qD)", name, *node);
108970 + return NULL_TREE;
108971 + }
108972 +
108973 + if (TYPE_P(*node)) {
108974 + type = *node;
108975 + } else {
108976 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
108977 + type = TREE_TYPE(*node);
108978 + }
108979 +
108980 + if (TREE_CODE(type) != RECORD_TYPE) {
108981 + error("%qE attribute used on %qT applies to struct types only", name, type);
108982 + return NULL_TREE;
108983 + }
108984 +
108985 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
108986 + error("%qE attribute is already applied to the type %qT", name, type);
108987 + return NULL_TREE;
108988 + }
108989 +
108990 + *no_add_attrs = false;
108991 +
108992 + return NULL_TREE;
108993 +}
108994 +
108995 +/* set on complete types that we don't need to inspect further at all */
108996 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
108997 +{
108998 + *no_add_attrs = false;
108999 + return NULL_TREE;
109000 +}
109001 +
109002 +/*
109003 + * set on types that we've performed a shuffle on, to prevent re-shuffling
109004 + * this does not preclude us from inspecting its fields for potential shuffles
109005 + */
109006 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109007 +{
109008 + *no_add_attrs = false;
109009 + return NULL_TREE;
109010 +}
109011 +
109012 +/*
109013 + * 64bit variant of Bob Jenkins' public domain PRNG
109014 + * 256 bits of internal state
109015 + */
109016 +
109017 +typedef unsigned long long u64;
109018 +
109019 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
109020 +
109021 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
109022 +static u64 ranval(ranctx *x) {
109023 + u64 e = x->a - rot(x->b, 7);
109024 + x->a = x->b ^ rot(x->c, 13);
109025 + x->b = x->c + rot(x->d, 37);
109026 + x->c = x->d + e;
109027 + x->d = e + x->a;
109028 + return x->d;
109029 +}
109030 +
109031 +static void raninit(ranctx *x, u64 *seed) {
109032 + int i;
109033 +
109034 + x->a = seed[0];
109035 + x->b = seed[1];
109036 + x->c = seed[2];
109037 + x->d = seed[3];
109038 +
109039 + for (i=0; i < 30; ++i)
109040 + (void)ranval(x);
109041 +}
109042 +
109043 +static u64 shuffle_seed[4];
109044 +
109045 +struct partition_group {
109046 + tree tree_start;
109047 + unsigned long start;
109048 + unsigned long length;
109049 +};
109050 +
109051 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
109052 +{
109053 + unsigned long i;
109054 + unsigned long accum_size = 0;
109055 + unsigned long accum_length = 0;
109056 + unsigned long group_idx = 0;
109057 +
109058 + gcc_assert(length < INT_MAX);
109059 +
109060 + memset(size_groups, 0, sizeof(struct partition_group) * length);
109061 +
109062 + for (i = 0; i < length; i++) {
109063 + if (size_groups[group_idx].tree_start == NULL_TREE) {
109064 + size_groups[group_idx].tree_start = fields[i];
109065 + size_groups[group_idx].start = i;
109066 + accum_length = 0;
109067 + accum_size = 0;
109068 + }
109069 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
109070 + accum_length++;
109071 + if (accum_size >= 64) {
109072 + size_groups[group_idx].length = accum_length;
109073 + accum_length = 0;
109074 + group_idx++;
109075 + }
109076 + }
109077 +
109078 + if (size_groups[group_idx].tree_start != NULL_TREE &&
109079 + !size_groups[group_idx].length) {
109080 + size_groups[group_idx].length = accum_length;
109081 + group_idx++;
109082 + }
109083 +
109084 + *num_groups = group_idx;
109085 +}
109086 +
109087 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
109088 +{
109089 + unsigned long i, x;
109090 + struct partition_group size_group[length];
109091 + unsigned long num_groups = 0;
109092 + unsigned long randnum;
109093 +
109094 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
109095 + for (i = num_groups - 1; i > 0; i--) {
109096 + struct partition_group tmp;
109097 + randnum = ranval(prng_state) % (i + 1);
109098 + tmp = size_group[i];
109099 + size_group[i] = size_group[randnum];
109100 + size_group[randnum] = tmp;
109101 + }
109102 +
109103 + for (x = 0; x < num_groups; x++) {
109104 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
109105 + tree tmp;
109106 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
109107 + continue;
109108 + randnum = ranval(prng_state) % (i + 1);
109109 + // we could handle this case differently if desired
109110 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
109111 + continue;
109112 + tmp = newtree[i];
109113 + newtree[i] = newtree[randnum];
109114 + newtree[randnum] = tmp;
109115 + }
109116 + }
109117 +}
109118 +
109119 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
109120 +{
109121 + unsigned long i, randnum;
109122 +
109123 + for (i = length - 1; i > 0; i--) {
109124 + tree tmp;
109125 + randnum = ranval(prng_state) % (i + 1);
109126 + tmp = newtree[i];
109127 + newtree[i] = newtree[randnum];
109128 + newtree[randnum] = tmp;
109129 + }
109130 +}
109131 +
109132 +/* modern in-place Fisher-Yates shuffle */
109133 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
109134 +{
109135 + unsigned long i;
109136 + u64 seed[4];
109137 + ranctx prng_state;
109138 + const unsigned char *structname;
109139 +
109140 + if (length == 0)
109141 + return;
109142 +
109143 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109144 +
109145 + structname = ORIG_TYPE_NAME(type);
109146 +
109147 +#ifdef __DEBUG_PLUGIN
109148 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
109149 +#ifdef __DEBUG_VERBOSE
109150 + debug_tree((tree)type);
109151 +#endif
109152 +#endif
109153 +
109154 + for (i = 0; i < 4; i++) {
109155 + seed[i] = shuffle_seed[i];
109156 + seed[i] ^= name_hash(structname);
109157 + }
109158 +
109159 + raninit(&prng_state, (u64 *)&seed);
109160 +
109161 + if (performance_mode)
109162 + performance_shuffle(newtree, length, &prng_state);
109163 + else
109164 + full_shuffle(newtree, length, &prng_state);
109165 +}
109166 +
109167 +static bool is_flexible_array(const_tree field)
109168 +{
109169 + const_tree fieldtype;
109170 + const_tree typesize;
109171 + const_tree elemtype;
109172 + const_tree elemsize;
109173 +
109174 + fieldtype = TREE_TYPE(field);
109175 + typesize = TYPE_SIZE(fieldtype);
109176 +
109177 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
109178 + return false;
109179 +
109180 + elemtype = TREE_TYPE(fieldtype);
109181 + elemsize = TYPE_SIZE(elemtype);
109182 +
109183 + /* size of type is represented in bits */
109184 +
109185 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
109186 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
109187 + return true;
109188 +
109189 + if (typesize != NULL_TREE &&
109190 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
109191 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
109192 + return true;
109193 +
109194 + return false;
109195 +}
109196 +
109197 +static int relayout_struct(tree type)
109198 +{
109199 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
109200 + unsigned long shuffle_length = num_fields;
109201 + tree field;
109202 + tree newtree[num_fields];
109203 + unsigned long i;
109204 + tree list;
109205 + tree variant;
109206 + expanded_location xloc;
109207 +
109208 + if (TYPE_FIELDS(type) == NULL_TREE)
109209 + return 0;
109210 +
109211 + if (num_fields < 2)
109212 + return 0;
109213 +
109214 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109215 +
109216 + gcc_assert(num_fields < INT_MAX);
109217 +
109218 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
109219 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
109220 + return 0;
109221 +
109222 + /* throw out any structs in uapi */
109223 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
109224 +
109225 + if (strstr(xloc.file, "/uapi/"))
109226 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
109227 +
109228 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
109229 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
109230 + newtree[i] = field;
109231 + }
109232 +
109233 + /*
109234 + * enforce that we don't randomize the layout of the last
109235 + * element of a struct if it's a 0 or 1-length array
109236 + * or a proper flexible array
109237 + */
109238 + if (is_flexible_array(newtree[num_fields - 1]))
109239 + shuffle_length--;
109240 +
109241 + shuffle(type, (tree *)newtree, shuffle_length);
109242 +
109243 + /*
109244 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
109245 + * as gcc provides no other way to detect such code
109246 + */
109247 + list = make_node(FIELD_DECL);
109248 + TREE_CHAIN(list) = newtree[0];
109249 + TREE_TYPE(list) = void_type_node;
109250 + DECL_SIZE(list) = bitsize_zero_node;
109251 + DECL_NONADDRESSABLE_P(list) = 1;
109252 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
109253 + DECL_SIZE_UNIT(list) = size_zero_node;
109254 + DECL_FIELD_OFFSET(list) = size_zero_node;
109255 + // to satisfy the constify plugin
109256 + TREE_READONLY(list) = 1;
109257 +
109258 + for (i = 0; i < num_fields - 1; i++)
109259 + TREE_CHAIN(newtree[i]) = newtree[i+1];
109260 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
109261 +
109262 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
109263 + TYPE_FIELDS(variant) = list;
109264 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
109265 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
109266 + // force a re-layout
109267 + TYPE_SIZE(variant) = NULL_TREE;
109268 + layout_type(variant);
109269 + }
109270 +
109271 + return 1;
109272 +}
109273 +
109274 +/* from constify plugin */
109275 +static const_tree get_field_type(const_tree field)
109276 +{
109277 + return strip_array_types(TREE_TYPE(field));
109278 +}
109279 +
109280 +/* from constify plugin */
109281 +static bool is_fptr(const_tree fieldtype)
109282 +{
109283 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
109284 + return false;
109285 +
109286 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
109287 +}
109288 +
109289 +/* derived from constify plugin */
109290 +static int is_pure_ops_struct(const_tree node)
109291 +{
109292 + const_tree field;
109293 +
109294 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
109295 +
109296 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
109297 + const_tree fieldtype = get_field_type(field);
109298 + enum tree_code code = TREE_CODE(fieldtype);
109299 +
109300 + if (node == fieldtype)
109301 + continue;
109302 +
109303 + if (!is_fptr(fieldtype))
109304 + return 0;
109305 +
109306 + if (code != RECORD_TYPE && code != UNION_TYPE)
109307 + continue;
109308 +
109309 + if (!is_pure_ops_struct(fieldtype))
109310 + return 0;
109311 + }
109312 +
109313 + return 1;
109314 +}
109315 +
109316 +static void randomize_type(tree type)
109317 +{
109318 + tree variant;
109319 +
109320 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109321 +
109322 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
109323 + return;
109324 +
109325 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
109326 + relayout_struct(type);
109327 +
109328 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
109329 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
109330 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
109331 + }
109332 +#ifdef __DEBUG_PLUGIN
109333 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
109334 +#ifdef __DEBUG_VERBOSE
109335 + debug_tree(type);
109336 +#endif
109337 +#endif
109338 +}
109339 +
109340 +static void randomize_layout_finish_decl(void *event_data, void *data)
109341 +{
109342 + tree decl = (tree)event_data;
109343 + tree type;
109344 +
109345 + if (decl == NULL_TREE || decl == error_mark_node)
109346 + return;
109347 +
109348 + type = TREE_TYPE(decl);
109349 +
109350 + if (TREE_CODE(decl) != VAR_DECL)
109351 + return;
109352 +
109353 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
109354 + return;
109355 +
109356 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
109357 + return;
109358 +
109359 + relayout_decl(decl);
109360 +}
109361 +
109362 +static void finish_type(void *event_data, void *data)
109363 +{
109364 + tree type = (tree)event_data;
109365 +
109366 + if (type == NULL_TREE || type == error_mark_node)
109367 + return;
109368 +
109369 + if (TREE_CODE(type) != RECORD_TYPE)
109370 + return;
109371 +
109372 + if (TYPE_FIELDS(type) == NULL_TREE)
109373 + return;
109374 +
109375 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
109376 + return;
109377 +
109378 +#ifdef __DEBUG_PLUGIN
109379 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
109380 +#endif
109381 +#ifdef __DEBUG_VERBOSE
109382 + debug_tree(type);
109383 +#endif
109384 + randomize_type(type);
109385 +
109386 + return;
109387 +}
109388 +
109389 +static struct attribute_spec randomize_layout_attr = {
109390 + .name = "randomize_layout",
109391 + // related to args
109392 + .min_length = 0,
109393 + .max_length = 0,
109394 + .decl_required = false,
109395 + // need type declaration
109396 + .type_required = true,
109397 + .function_type_required = false,
109398 + .handler = handle_randomize_layout_attr,
109399 +#if BUILDING_GCC_VERSION >= 4007
109400 + .affects_type_identity = true
109401 +#endif
109402 +};
109403 +
109404 +static struct attribute_spec no_randomize_layout_attr = {
109405 + .name = "no_randomize_layout",
109406 + // related to args
109407 + .min_length = 0,
109408 + .max_length = 0,
109409 + .decl_required = false,
109410 + // need type declaration
109411 + .type_required = true,
109412 + .function_type_required = false,
109413 + .handler = handle_randomize_layout_attr,
109414 +#if BUILDING_GCC_VERSION >= 4007
109415 + .affects_type_identity = true
109416 +#endif
109417 +};
109418 +
109419 +static struct attribute_spec randomize_considered_attr = {
109420 + .name = "randomize_considered",
109421 + // related to args
109422 + .min_length = 0,
109423 + .max_length = 0,
109424 + .decl_required = false,
109425 + // need type declaration
109426 + .type_required = true,
109427 + .function_type_required = false,
109428 + .handler = handle_randomize_considered_attr,
109429 +#if BUILDING_GCC_VERSION >= 4007
109430 + .affects_type_identity = false
109431 +#endif
109432 +};
109433 +
109434 +static struct attribute_spec randomize_performed_attr = {
109435 + .name = "randomize_performed",
109436 + // related to args
109437 + .min_length = 0,
109438 + .max_length = 0,
109439 + .decl_required = false,
109440 + // need type declaration
109441 + .type_required = true,
109442 + .function_type_required = false,
109443 + .handler = handle_randomize_performed_attr,
109444 +#if BUILDING_GCC_VERSION >= 4007
109445 + .affects_type_identity = false
109446 +#endif
109447 +};
109448 +
109449 +static void register_attributes(void *event_data, void *data)
109450 +{
109451 + register_attribute(&randomize_layout_attr);
109452 + register_attribute(&no_randomize_layout_attr);
109453 + register_attribute(&randomize_considered_attr);
109454 + register_attribute(&randomize_performed_attr);
109455 +}
109456 +
109457 +static void check_bad_casts_in_constructor(tree var, tree init)
109458 +{
109459 + unsigned HOST_WIDE_INT idx;
109460 + tree field, val;
109461 + tree field_type, val_type;
109462 +
109463 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
109464 + if (TREE_CODE(val) == CONSTRUCTOR) {
109465 + check_bad_casts_in_constructor(var, val);
109466 + continue;
109467 + }
109468 +
109469 + /* pipacs' plugin creates franken-arrays that differ from those produced by
109470 + normal code which all have valid 'field' trees. work around this */
109471 + if (field == NULL_TREE)
109472 + continue;
109473 + field_type = TREE_TYPE(field);
109474 + val_type = TREE_TYPE(val);
109475 +
109476 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
109477 + continue;
109478 +
109479 + if (field_type == val_type)
109480 + continue;
109481 +
109482 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
109483 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
109484 +
109485 + if (field_type == void_type_node)
109486 + continue;
109487 + if (field_type == val_type)
109488 + continue;
109489 + if (TREE_CODE(val_type) != RECORD_TYPE)
109490 + continue;
109491 +
109492 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
109493 + continue;
109494 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
109495 + }
109496 +}
109497 +
109498 +/* derived from the constify plugin */
109499 +static void check_global_variables(void *event_data, void *data)
109500 +{
109501 + struct varpool_node *node;
109502 + tree init;
109503 +
109504 + FOR_EACH_VARIABLE(node) {
109505 + tree var = NODE_DECL(node);
109506 + init = DECL_INITIAL(var);
109507 + if (init == NULL_TREE)
109508 + continue;
109509 +
109510 + if (TREE_CODE(init) != CONSTRUCTOR)
109511 + continue;
109512 +
109513 + check_bad_casts_in_constructor(var, init);
109514 + }
109515 +}
109516 +
109517 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
109518 +{
109519 + basic_block dom;
109520 + gimple dom_stmt;
109521 + gimple call_stmt;
109522 + const_tree dom_lhs;
109523 + const_tree poss_is_err_cond;
109524 + const_tree poss_is_err_func;
109525 + const_tree is_err_arg;
109526 +
109527 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
109528 + if (!dom)
109529 + return false;
109530 +
109531 + dom_stmt = last_stmt(dom);
109532 + if (!dom_stmt)
109533 + return false;
109534 +
109535 + if (gimple_code(dom_stmt) != GIMPLE_COND)
109536 + return false;
109537 +
109538 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
109539 + return false;
109540 +
109541 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
109542 + return false;
109543 +
109544 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
109545 +
109546 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
109547 + return false;
109548 +
109549 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
109550 +
109551 + if (gimple_code(call_stmt) != GIMPLE_CALL)
109552 + return false;
109553 +
109554 + dom_lhs = gimple_get_lhs(call_stmt);
109555 + poss_is_err_func = gimple_call_fndecl(call_stmt);
109556 + if (!poss_is_err_func)
109557 + return false;
109558 + if (dom_lhs != poss_is_err_cond)
109559 + return false;
109560 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
109561 + return false;
109562 +
109563 + is_err_arg = gimple_call_arg(call_stmt, 0);
109564 + if (!is_err_arg)
109565 + return false;
109566 +
109567 + if (is_err_arg != rhs)
109568 + return false;
109569 +
109570 + return true;
109571 +}
109572 +
109573 +static void handle_local_var_initializers(void)
109574 +{
109575 + tree var;
109576 + unsigned int i;
109577 +
109578 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
109579 + tree init = DECL_INITIAL(var);
109580 + if (!init)
109581 + continue;
109582 + if (TREE_CODE(init) != CONSTRUCTOR)
109583 + continue;
109584 + check_bad_casts_in_constructor(var, init);
109585 + }
109586 +}
109587 +
109588 +/*
109589 + * iterate over all statements to find "bad" casts:
109590 + * those where the address of the start of a structure is cast
109591 + * to a pointer of a structure of a different type, or a
109592 + * structure pointer type is cast to a different structure pointer type
109593 + */
109594 +static unsigned int find_bad_casts(void)
109595 +{
109596 + basic_block bb;
109597 +
109598 + handle_local_var_initializers();
109599 +
109600 + FOR_ALL_BB_FN(bb, cfun) {
109601 + gimple_stmt_iterator gsi;
109602 +
109603 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
109604 + gimple stmt;
109605 + const_tree lhs;
109606 + const_tree lhs_type;
109607 + const_tree rhs1;
109608 + const_tree rhs_type;
109609 + const_tree ptr_lhs_type;
109610 + const_tree ptr_rhs_type;
109611 + const_tree op0;
109612 + const_tree op0_type;
109613 + enum tree_code rhs_code;
109614 +
109615 + stmt = gsi_stmt(gsi);
109616 +
109617 +#ifdef __DEBUG_PLUGIN
109618 +#ifdef __DEBUG_VERBOSE
109619 + debug_gimple_stmt(stmt);
109620 + debug_tree(gimple_get_lhs(stmt));
109621 +#endif
109622 +#endif
109623 +
109624 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
109625 + continue;
109626 +
109627 +#ifdef __DEBUG_PLUGIN
109628 +#ifdef __DEBUG_VERBOSE
109629 + debug_tree(gimple_assign_rhs1(stmt));
109630 +#endif
109631 +#endif
109632 +
109633 + rhs_code = gimple_assign_rhs_code(stmt);
109634 +
109635 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
109636 + continue;
109637 +
109638 + lhs = gimple_get_lhs(stmt);
109639 + lhs_type = TREE_TYPE(lhs);
109640 + rhs1 = gimple_assign_rhs1(stmt);
109641 + rhs_type = TREE_TYPE(rhs1);
109642 +
109643 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
109644 + TREE_CODE(lhs_type) != POINTER_TYPE)
109645 + continue;
109646 +
109647 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
109648 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
109649 +
109650 + if (ptr_rhs_type == void_type_node)
109651 + continue;
109652 +
109653 + if (ptr_lhs_type == void_type_node)
109654 + continue;
109655 +
109656 + if (dominated_by_is_err(rhs1, bb))
109657 + continue;
109658 +
109659 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
109660 +#ifndef __DEBUG_PLUGIN
109661 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
109662 +#endif
109663 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
109664 + continue;
109665 + }
109666 +
109667 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
109668 + continue;
109669 +
109670 + if (rhs_code == ADDR_EXPR) {
109671 + op0 = TREE_OPERAND(rhs1, 0);
109672 +
109673 + if (op0 == NULL_TREE)
109674 + continue;
109675 +
109676 + if (TREE_CODE(op0) != VAR_DECL)
109677 + continue;
109678 +
109679 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
109680 + if (op0_type == ptr_lhs_type)
109681 + continue;
109682 +
109683 +#ifndef __DEBUG_PLUGIN
109684 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
109685 +#endif
109686 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
109687 + } else {
109688 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
109689 + /* skip bogus type casts introduced by container_of */
109690 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
109691 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
109692 + continue;
109693 +#ifndef __DEBUG_PLUGIN
109694 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
109695 +#endif
109696 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
109697 + }
109698 +
109699 + }
109700 + }
109701 + return 0;
109702 +}
109703 +
109704 +#if BUILDING_GCC_VERSION >= 4009
109705 +static const struct pass_data randomize_layout_bad_cast_data = {
109706 +#else
109707 +static struct gimple_opt_pass randomize_layout_bad_cast = {
109708 + .pass = {
109709 +#endif
109710 + .type = GIMPLE_PASS,
109711 + .name = "randomize_layout_bad_cast",
109712 +#if BUILDING_GCC_VERSION >= 4008
109713 + .optinfo_flags = OPTGROUP_NONE,
109714 +#endif
109715 +#if BUILDING_GCC_VERSION >= 4009
109716 + .has_gate = false,
109717 + .has_execute = true,
109718 +#else
109719 + .gate = NULL,
109720 + .execute = find_bad_casts,
109721 + .sub = NULL,
109722 + .next = NULL,
109723 + .static_pass_number = 0,
109724 +#endif
109725 + .tv_id = TV_NONE,
109726 + .properties_required = PROP_cfg,
109727 + .properties_provided = 0,
109728 + .properties_destroyed = 0,
109729 + .todo_flags_start = 0,
109730 + .todo_flags_finish = TODO_dump_func
109731 +#if BUILDING_GCC_VERSION < 4009
109732 + }
109733 +#endif
109734 +};
109735 +
109736 +#if BUILDING_GCC_VERSION >= 4009
109737 +namespace {
109738 +class randomize_layout_bad_cast : public gimple_opt_pass {
109739 +public:
109740 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
109741 + unsigned int execute() { return find_bad_casts(); }
109742 +};
109743 +}
109744 +#endif
109745 +
109746 +static struct opt_pass *make_randomize_layout_bad_cast(void)
109747 +{
109748 +#if BUILDING_GCC_VERSION >= 4009
109749 + return new randomize_layout_bad_cast();
109750 +#else
109751 + return &randomize_layout_bad_cast.pass;
109752 +#endif
109753 +}
109754 +
109755 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
109756 +{
109757 + int i;
109758 + const char * const plugin_name = plugin_info->base_name;
109759 + const int argc = plugin_info->argc;
109760 + const struct plugin_argument * const argv = plugin_info->argv;
109761 + bool enable = true;
109762 + int obtained_seed = 0;
109763 + struct register_pass_info randomize_layout_bad_cast_info;
109764 +
109765 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
109766 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
109767 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
109768 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
109769 +
109770 + if (!plugin_default_version_check(version, &gcc_version)) {
109771 + error(G_("incompatible gcc/plugin versions"));
109772 + return 1;
109773 + }
109774 +
109775 + if (strcmp(lang_hooks.name, "GNU C")) {
109776 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
109777 + enable = false;
109778 + }
109779 +
109780 + for (i = 0; i < argc; ++i) {
109781 + if (!strcmp(argv[i].key, "disable")) {
109782 + enable = false;
109783 + continue;
109784 + }
109785 + if (!strcmp(argv[i].key, "performance-mode")) {
109786 + performance_mode = 1;
109787 + continue;
109788 + }
109789 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
109790 + }
109791 +
109792 + if (strlen(randstruct_seed) != 64) {
109793 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
109794 + return 1;
109795 + }
109796 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
109797 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
109798 + if (obtained_seed != 4) {
109799 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
109800 + return 1;
109801 + }
109802 +
109803 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
109804 + if (enable) {
109805 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
109806 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
109807 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
109808 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
109809 + }
109810 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
109811 +
109812 + return 0;
109813 +}
109814 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
109815 new file mode 100644
109816 index 0000000..92d3b0c
109817 --- /dev/null
109818 +++ b/tools/gcc/size_overflow_plugin/.gitignore
109819 @@ -0,0 +1,2 @@
109820 +size_overflow_hash.h
109821 +size_overflow_hash_aux.h
109822 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
109823 new file mode 100644
109824 index 0000000..1ae2ed5
109825 --- /dev/null
109826 +++ b/tools/gcc/size_overflow_plugin/Makefile
109827 @@ -0,0 +1,20 @@
109828 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
109829 +always := $($(HOSTLIBS)-y)
109830 +
109831 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
109832 +
109833 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
109834 +
109835 +quiet_cmd_build_size_overflow_hash = GENHASH $@
109836 + cmd_build_size_overflow_hash = \
109837 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
109838 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
109839 + $(call if_changed,build_size_overflow_hash)
109840 +
109841 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
109842 + cmd_build_size_overflow_hash_aux = \
109843 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
109844 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
109845 + $(call if_changed,build_size_overflow_hash_aux)
109846 +
109847 +targets += size_overflow_hash.h size_overflow_hash_aux.h
109848 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
109849 new file mode 100644
109850 index 0000000..12b1e3b
109851 --- /dev/null
109852 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
109853 @@ -0,0 +1,102 @@
109854 +#!/bin/bash
109855 +
109856 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
109857 +
109858 +header1="size_overflow_hash.h"
109859 +database="size_overflow_hash.data"
109860 +n=65536
109861 +hashtable_name="size_overflow_hash"
109862 +
109863 +usage() {
109864 +cat <<EOF
109865 +usage: $0 options
109866 +OPTIONS:
109867 + -h|--help help
109868 + -o header file
109869 + -d database file
109870 + -n hash array size
109871 + -s name of the hash table
109872 +EOF
109873 + return 0
109874 +}
109875 +
109876 +while true
109877 +do
109878 + case "$1" in
109879 + -h|--help) usage && exit 0;;
109880 + -n) n=$2; shift 2;;
109881 + -o) header1="$2"; shift 2;;
109882 + -d) database="$2"; shift 2;;
109883 + -s) hashtable_name="$2"; shift 2;;
109884 + --) shift 1; break ;;
109885 + *) break ;;
109886 + esac
109887 +done
109888 +
109889 +create_defines() {
109890 + for i in `seq 0 31`
109891 + do
109892 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
109893 + done
109894 + echo >> "$header1"
109895 +}
109896 +
109897 +create_structs() {
109898 + rm -f "$header1"
109899 +
109900 + create_defines
109901 +
109902 + cat "$database" | while read data
109903 + do
109904 + data_array=($data)
109905 + struct_hash_name="${data_array[0]}"
109906 + funcn="${data_array[1]}"
109907 + params="${data_array[2]}"
109908 + next="${data_array[4]}"
109909 +
109910 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
109911 +
109912 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
109913 + echo -en "\t.param\t= " >> "$header1"
109914 + line=
109915 + for param_num in ${params//-/ };
109916 + do
109917 + line="${line}PARAM"$param_num"|"
109918 + done
109919 +
109920 + echo -e "${line%?},\n};\n" >> "$header1"
109921 + done
109922 +}
109923 +
109924 +create_headers() {
109925 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
109926 +}
109927 +
109928 +create_array_elements() {
109929 + index=0
109930 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
109931 + do
109932 + data_array=($data)
109933 + i="${data_array[3]}"
109934 + hash="${data_array[0]}"
109935 + while [[ $index -lt $i ]]
109936 + do
109937 + echo -e "\t["$index"]\t= NULL," >> "$header1"
109938 + index=$(($index + 1))
109939 + done
109940 + index=$(($index + 1))
109941 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
109942 + done
109943 + echo '};' >> $header1
109944 +}
109945 +
109946 +size_overflow_plugin_dir=`dirname $header1`
109947 +if [ "$size_overflow_plugin_dir" != '.' ]; then
109948 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
109949 +fi
109950 +
109951 +create_structs
109952 +create_headers
109953 +create_array_elements
109954 +
109955 +exit 0
109956 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
109957 new file mode 100644
109958 index 0000000..3e8148c
109959 --- /dev/null
109960 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
109961 @@ -0,0 +1,790 @@
109962 +/*
109963 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
109964 + * Licensed under the GPL v2, or (at your option) v3
109965 + *
109966 + * Homepage:
109967 + * http://www.grsecurity.net/~ephox/overflow_plugin/
109968 + *
109969 + * Documentation:
109970 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
109971 + *
109972 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
109973 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
109974 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
109975 + *
109976 + * Usage:
109977 + * $ make
109978 + * $ make run
109979 + */
109980 +
109981 +#include "gcc-common.h"
109982 +#include "size_overflow.h"
109983 +
109984 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
109985 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
109986 +
109987 +// data for the size_overflow asm stmt
109988 +struct asm_data {
109989 + gimple def_stmt;
109990 + tree input;
109991 + tree output;
109992 +};
109993 +
109994 +#if BUILDING_GCC_VERSION <= 4007
109995 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
109996 +#else
109997 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
109998 +#endif
109999 +{
110000 + tree list;
110001 +#if BUILDING_GCC_VERSION <= 4007
110002 + VEC(tree, gc) *vec_list = NULL;
110003 +#else
110004 + vec<tree, va_gc> *vec_list = NULL;
110005 +#endif
110006 +
110007 + list = build_tree_list(NULL_TREE, string);
110008 + list = chainon(NULL_TREE, build_tree_list(list, io));
110009 +#if BUILDING_GCC_VERSION <= 4007
110010 + VEC_safe_push(tree, gc, vec_list, list);
110011 +#else
110012 + vec_safe_push(vec_list, list);
110013 +#endif
110014 + return vec_list;
110015 +}
110016 +
110017 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
110018 +{
110019 + gimple asm_stmt;
110020 + gimple_stmt_iterator gsi;
110021 +#if BUILDING_GCC_VERSION <= 4007
110022 + VEC(tree, gc) *input, *output = NULL;
110023 +#else
110024 + vec<tree, va_gc> *input, *output = NULL;
110025 +#endif
110026 +
110027 + input = create_asm_io_list(str_input, asm_data->input);
110028 +
110029 + if (asm_data->output)
110030 + output = create_asm_io_list(str_output, asm_data->output);
110031 +
110032 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
110033 + gsi = gsi_for_stmt(asm_data->def_stmt);
110034 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
110035 +
110036 + if (asm_data->output)
110037 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
110038 +}
110039 +
110040 +static void replace_call_lhs(const struct asm_data *asm_data)
110041 +{
110042 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
110043 + update_stmt(asm_data->def_stmt);
110044 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
110045 +}
110046 +
110047 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
110048 +{
110049 + enum mark cur_fndecl_attr;
110050 + gimple phi = get_def_stmt(result);
110051 + unsigned int i, n = gimple_phi_num_args(phi);
110052 +
110053 + pointer_set_insert(visited, phi);
110054 + for (i = 0; i < n; i++) {
110055 + tree arg = gimple_phi_arg_def(phi, i);
110056 +
110057 + cur_fndecl_attr = search_intentional(visited, arg);
110058 + if (cur_fndecl_attr != MARK_NO)
110059 + return cur_fndecl_attr;
110060 + }
110061 + return MARK_NO;
110062 +}
110063 +
110064 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
110065 +{
110066 + enum mark cur_fndecl_attr;
110067 + const_tree rhs1, rhs2;
110068 + gimple def_stmt = get_def_stmt(lhs);
110069 +
110070 + rhs1 = gimple_assign_rhs1(def_stmt);
110071 + rhs2 = gimple_assign_rhs2(def_stmt);
110072 +
110073 + cur_fndecl_attr = search_intentional(visited, rhs1);
110074 + if (cur_fndecl_attr != MARK_NO)
110075 + return cur_fndecl_attr;
110076 + return search_intentional(visited, rhs2);
110077 +}
110078 +
110079 +// Look up the intentional_overflow attribute on the caller and the callee functions.
110080 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
110081 +{
110082 + const_gimple def_stmt;
110083 +
110084 + if (TREE_CODE(lhs) != SSA_NAME)
110085 + return get_intentional_attr_type(lhs);
110086 +
110087 + def_stmt = get_def_stmt(lhs);
110088 + if (!def_stmt)
110089 + return MARK_NO;
110090 +
110091 + if (pointer_set_contains(visited, def_stmt))
110092 + return MARK_NO;
110093 +
110094 + switch (gimple_code(def_stmt)) {
110095 + case GIMPLE_NOP:
110096 + return search_intentional(visited, SSA_NAME_VAR(lhs));
110097 + case GIMPLE_ASM:
110098 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
110099 + return MARK_TURN_OFF;
110100 + return MARK_NO;
110101 + case GIMPLE_CALL:
110102 + return MARK_NO;
110103 + case GIMPLE_PHI:
110104 + return search_intentional_phi(visited, lhs);
110105 + case GIMPLE_ASSIGN:
110106 + switch (gimple_num_ops(def_stmt)) {
110107 + case 2:
110108 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
110109 + case 3:
110110 + return search_intentional_binary(visited, lhs);
110111 + }
110112 + case GIMPLE_RETURN:
110113 + return MARK_NO;
110114 + default:
110115 + debug_gimple_stmt((gimple)def_stmt);
110116 + error("%s: unknown gimple code", __func__);
110117 + gcc_unreachable();
110118 + }
110119 +}
110120 +
110121 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
110122 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
110123 +{
110124 + const_tree fndecl;
110125 + struct pointer_set_t *visited;
110126 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
110127 +
110128 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
110129 + if (is_end_intentional_intentional_attr(fndecl, argnum))
110130 + decl_attr = MARK_NOT_INTENTIONAL;
110131 + else if (is_yes_intentional_attr(fndecl, argnum))
110132 + decl_attr = MARK_YES;
110133 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
110134 + return MARK_TURN_OFF;
110135 + }
110136 +
110137 + visited = pointer_set_create();
110138 + cur_fndecl_attr = search_intentional(visited, arg);
110139 + pointer_set_destroy(visited);
110140 +
110141 + switch (cur_fndecl_attr) {
110142 + case MARK_NO:
110143 + case MARK_TURN_OFF:
110144 + return cur_fndecl_attr;
110145 + default:
110146 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
110147 + return MARK_YES;
110148 + }
110149 +}
110150 +
110151 +static void check_missing_size_overflow_attribute(tree var)
110152 +{
110153 + tree orig_fndecl;
110154 + unsigned int num;
110155 +
110156 + if (is_a_return_check(var))
110157 + orig_fndecl = DECL_ORIGIN(var);
110158 + else
110159 + orig_fndecl = DECL_ORIGIN(current_function_decl);
110160 +
110161 + num = get_function_num(var, orig_fndecl);
110162 + if (num == CANNOT_FIND_ARG)
110163 + return;
110164 +
110165 + is_missing_function(orig_fndecl, num);
110166 +}
110167 +
110168 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
110169 +{
110170 + gimple phi = get_def_stmt(result);
110171 + unsigned int i, n = gimple_phi_num_args(phi);
110172 +
110173 + pointer_set_insert(visited, phi);
110174 + for (i = 0; i < n; i++) {
110175 + tree arg = gimple_phi_arg_def(phi, i);
110176 +
110177 + search_size_overflow_attribute(visited, arg);
110178 + }
110179 +}
110180 +
110181 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
110182 +{
110183 + const_gimple def_stmt = get_def_stmt(lhs);
110184 + tree rhs1, rhs2;
110185 +
110186 + rhs1 = gimple_assign_rhs1(def_stmt);
110187 + rhs2 = gimple_assign_rhs2(def_stmt);
110188 +
110189 + search_size_overflow_attribute(visited, rhs1);
110190 + search_size_overflow_attribute(visited, rhs2);
110191 +}
110192 +
110193 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
110194 +{
110195 + const_gimple def_stmt;
110196 +
110197 + if (TREE_CODE(lhs) == PARM_DECL) {
110198 + check_missing_size_overflow_attribute(lhs);
110199 + return;
110200 + }
110201 +
110202 + def_stmt = get_def_stmt(lhs);
110203 + if (!def_stmt)
110204 + return;
110205 +
110206 + if (pointer_set_insert(visited, def_stmt))
110207 + return;
110208 +
110209 + switch (gimple_code(def_stmt)) {
110210 + case GIMPLE_NOP:
110211 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
110212 + case GIMPLE_ASM:
110213 + return;
110214 + case GIMPLE_CALL: {
110215 + tree fndecl = gimple_call_fndecl(def_stmt);
110216 +
110217 + if (fndecl == NULL_TREE)
110218 + return;
110219 + check_missing_size_overflow_attribute(fndecl);
110220 + return;
110221 + }
110222 + case GIMPLE_PHI:
110223 + return search_size_overflow_attribute_phi(visited, lhs);
110224 + case GIMPLE_ASSIGN:
110225 + switch (gimple_num_ops(def_stmt)) {
110226 + case 2:
110227 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
110228 + case 3:
110229 + return search_size_overflow_attribute_binary(visited, lhs);
110230 + }
110231 + default:
110232 + debug_gimple_stmt((gimple)def_stmt);
110233 + error("%s: unknown gimple code", __func__);
110234 + gcc_unreachable();
110235 + }
110236 +}
110237 +
110238 +// Search missing entries in the hash table (invoked from the gimple pass)
110239 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
110240 +{
110241 + tree fndecl = NULL_TREE;
110242 + tree lhs;
110243 + struct pointer_set_t *visited;
110244 +
110245 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
110246 + return;
110247 +
110248 + if (num == 0) {
110249 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
110250 + lhs = gimple_return_retval(stmt);
110251 + } else {
110252 + gcc_assert(is_gimple_call(stmt));
110253 + lhs = gimple_call_arg(stmt, num - 1);
110254 + fndecl = gimple_call_fndecl(stmt);
110255 + }
110256 +
110257 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
110258 + return;
110259 +
110260 + visited = pointer_set_create();
110261 + search_size_overflow_attribute(visited, lhs);
110262 + pointer_set_destroy(visited);
110263 +}
110264 +
110265 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
110266 +{
110267 + gimple_stmt_iterator gsi;
110268 + gimple assign;
110269 +
110270 + assign = gimple_build_assign(asm_data->input, asm_data->output);
110271 + gsi = gsi_for_stmt(stmt);
110272 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
110273 + asm_data->def_stmt = assign;
110274 +
110275 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
110276 + asm_data->output = make_ssa_name(asm_data->output, stmt);
110277 + if (gimple_code(stmt) == GIMPLE_RETURN)
110278 + gimple_return_set_retval(stmt, asm_data->output);
110279 + else
110280 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
110281 + update_stmt(stmt);
110282 +}
110283 +
110284 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
110285 +{
110286 + const char *fn_name;
110287 + char *asm_comment;
110288 + unsigned int len;
110289 +
110290 + if (argnum == 0)
110291 + fn_name = DECL_NAME_POINTER(current_function_decl);
110292 + else
110293 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
110294 +
110295 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
110296 + gcc_assert(len > 0);
110297 +
110298 + return asm_comment;
110299 +}
110300 +
110301 +static const char *convert_mark_to_str(enum mark mark)
110302 +{
110303 + switch (mark) {
110304 + case MARK_NO:
110305 + return OK_ASM_STR;
110306 + case MARK_YES:
110307 + case MARK_NOT_INTENTIONAL:
110308 + return YES_ASM_STR;
110309 + case MARK_TURN_OFF:
110310 + return TURN_OFF_ASM_STR;
110311 + }
110312 +
110313 + gcc_unreachable();
110314 +}
110315 +
110316 +/* Create the input of the size_overflow asm stmt.
110317 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
110318 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
110319 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
110320 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
110321 + */
110322 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
110323 +{
110324 + if (!asm_data->def_stmt) {
110325 + asm_data->input = NULL_TREE;
110326 + return;
110327 + }
110328 +
110329 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
110330 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
110331 +
110332 + switch (gimple_code(asm_data->def_stmt)) {
110333 + case GIMPLE_ASSIGN:
110334 + case GIMPLE_CALL:
110335 + replace_call_lhs(asm_data);
110336 + break;
110337 + case GIMPLE_PHI:
110338 + create_output_from_phi(stmt, argnum, asm_data);
110339 + break;
110340 + case GIMPLE_NOP: {
110341 + enum mark mark;
110342 + const char *mark_str;
110343 + char *asm_comment;
110344 +
110345 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
110346 +
110347 + asm_data->input = asm_data->output;
110348 + asm_data->output = NULL;
110349 + asm_data->def_stmt = stmt;
110350 +
110351 + mark_str = convert_mark_to_str(mark);
110352 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
110353 +
110354 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
110355 + free(asm_comment);
110356 + asm_data->input = NULL_TREE;
110357 + break;
110358 + }
110359 + case GIMPLE_ASM:
110360 + if (is_size_overflow_asm(asm_data->def_stmt)) {
110361 + asm_data->input = NULL_TREE;
110362 + break;
110363 + }
110364 + default:
110365 + debug_gimple_stmt(asm_data->def_stmt);
110366 + gcc_unreachable();
110367 + }
110368 +}
110369 +
110370 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
110371 + * is of the right kind create the appropriate size_overflow asm stmts:
110372 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
110373 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
110374 + */
110375 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
110376 +{
110377 + struct asm_data asm_data;
110378 + const char *mark_str;
110379 + char *asm_comment;
110380 + enum mark mark;
110381 +
110382 + if (is_gimple_constant(output_node))
110383 + return;
110384 +
110385 + asm_data.output = output_node;
110386 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
110387 + if (mark != MARK_TURN_OFF)
110388 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
110389 +
110390 + asm_data.def_stmt = get_def_stmt(asm_data.output);
110391 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
110392 + return;
110393 +
110394 + create_asm_input(stmt, argnum, &asm_data);
110395 + if (asm_data.input == NULL_TREE)
110396 + return;
110397 +
110398 + mark_str = convert_mark_to_str(mark);
110399 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
110400 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
110401 + free(asm_comment);
110402 +}
110403 +
110404 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
110405 +static bool create_mark_asm(gimple stmt, enum mark mark)
110406 +{
110407 + struct asm_data asm_data;
110408 + const char *asm_str;
110409 +
110410 + switch (mark) {
110411 + case MARK_TURN_OFF:
110412 + asm_str = TURN_OFF_ASM_STR;
110413 + break;
110414 + case MARK_NOT_INTENTIONAL:
110415 + case MARK_YES:
110416 + asm_str = YES_ASM_STR;
110417 + break;
110418 + default:
110419 + gcc_unreachable();
110420 + }
110421 +
110422 + asm_data.def_stmt = stmt;
110423 + asm_data.output = gimple_call_lhs(stmt);
110424 +
110425 + if (asm_data.output == NULL_TREE) {
110426 + asm_data.input = gimple_call_arg(stmt, 0);
110427 + if (is_gimple_constant(asm_data.input))
110428 + return false;
110429 + asm_data.output = NULL;
110430 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
110431 + return true;
110432 + }
110433 +
110434 + create_asm_input(stmt, 0, &asm_data);
110435 + gcc_assert(asm_data.input != NULL_TREE);
110436 +
110437 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
110438 + return true;
110439 +}
110440 +
110441 +static bool is_from_cast(const_tree node)
110442 +{
110443 + gimple def_stmt = get_def_stmt(node);
110444 +
110445 + if (!def_stmt)
110446 + return false;
110447 +
110448 + if (gimple_assign_cast_p(def_stmt))
110449 + return true;
110450 +
110451 + return false;
110452 +}
110453 +
110454 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
110455 +static bool skip_ptr_minus(gimple stmt)
110456 +{
110457 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
110458 +
110459 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
110460 + return false;
110461 +
110462 + rhs1 = gimple_assign_rhs1(stmt);
110463 + if (!is_from_cast(rhs1))
110464 + return false;
110465 +
110466 + rhs2 = gimple_assign_rhs2(stmt);
110467 + if (!is_from_cast(rhs2))
110468 + return false;
110469 +
110470 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
110471 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
110472 +
110473 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
110474 + return false;
110475 +
110476 + create_mark_asm(stmt, MARK_YES);
110477 + return true;
110478 +}
110479 +
110480 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
110481 +{
110482 + gimple def_stmt;
110483 +
110484 + def_stmt = get_def_stmt(lhs);
110485 + if (!def_stmt)
110486 + return;
110487 +
110488 + if (pointer_set_insert(visited, def_stmt))
110489 + return;
110490 +
110491 + switch (gimple_code(def_stmt)) {
110492 + case GIMPLE_NOP:
110493 + case GIMPLE_ASM:
110494 + case GIMPLE_CALL:
110495 + break;
110496 + case GIMPLE_PHI: {
110497 + unsigned int i, n = gimple_phi_num_args(def_stmt);
110498 +
110499 + pointer_set_insert(visited, def_stmt);
110500 +
110501 + for (i = 0; i < n; i++) {
110502 + tree arg = gimple_phi_arg_def(def_stmt, i);
110503 +
110504 + walk_use_def_ptr(visited, arg);
110505 + }
110506 + }
110507 + case GIMPLE_ASSIGN:
110508 + switch (gimple_num_ops(def_stmt)) {
110509 + case 2:
110510 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
110511 + return;
110512 + case 3:
110513 + if (skip_ptr_minus(def_stmt))
110514 + return;
110515 +
110516 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
110517 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
110518 + return;
110519 + default:
110520 + return;
110521 + }
110522 + default:
110523 + debug_gimple_stmt((gimple)def_stmt);
110524 + error("%s: unknown gimple code", __func__);
110525 + gcc_unreachable();
110526 + }
110527 +}
110528 +
110529 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
110530 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
110531 +{
110532 + struct pointer_set_t *visited;
110533 +
110534 + visited = pointer_set_create();
110535 + walk_use_def_ptr(visited, arg);
110536 + pointer_set_destroy(visited);
110537 +}
110538 +
110539 +// Determine the return value and insert the asm stmt to mark the return stmt.
110540 +static void insert_asm_ret(gimple stmt)
110541 +{
110542 + tree ret;
110543 +
110544 + ret = gimple_return_retval(stmt);
110545 + create_size_overflow_asm(stmt, ret, 0);
110546 +}
110547 +
110548 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
110549 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
110550 +{
110551 + tree arg;
110552 + unsigned int argnum;
110553 +
110554 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
110555 + gcc_assert(argnum != 0);
110556 + if (argnum == CANNOT_FIND_ARG)
110557 + return;
110558 +
110559 + arg = gimple_call_arg(stmt, argnum - 1);
110560 + gcc_assert(arg != NULL_TREE);
110561 +
110562 + // skip all ptr - ptr expressions
110563 + insert_mark_not_intentional_asm_at_ptr(arg);
110564 +
110565 + create_size_overflow_asm(stmt, arg, argnum);
110566 +}
110567 +
110568 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
110569 +static void set_argnum_attribute(const_tree attr, bool *argnums)
110570 +{
110571 + unsigned int argnum;
110572 + tree attr_value;
110573 +
110574 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
110575 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
110576 + argnums[argnum] = true;
110577 + }
110578 +}
110579 +
110580 +// If a function arg or the return value is in the hash table then set its index in the array.
110581 +static void set_argnum_hash(tree fndecl, bool *argnums)
110582 +{
110583 + unsigned int num;
110584 + const struct size_overflow_hash *hash;
110585 +
110586 + hash = get_function_hash(DECL_ORIGIN(fndecl));
110587 + if (!hash)
110588 + return;
110589 +
110590 + for (num = 0; num <= MAX_PARAM; num++) {
110591 + if (!(hash->param & (1U << num)))
110592 + continue;
110593 +
110594 + argnums[num] = true;
110595 + }
110596 +}
110597 +
110598 +static bool is_all_the_argnums_empty(bool *argnums)
110599 +{
110600 + unsigned int i;
110601 +
110602 + for (i = 0; i <= MAX_PARAM; i++)
110603 + if (argnums[i])
110604 + return false;
110605 + return true;
110606 +}
110607 +
110608 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
110609 +static void search_interesting_args(tree fndecl, bool *argnums)
110610 +{
110611 + const_tree attr;
110612 +
110613 + set_argnum_hash(fndecl, argnums);
110614 + if (!is_all_the_argnums_empty(argnums))
110615 + return;
110616 +
110617 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
110618 + if (attr && TREE_VALUE(attr))
110619 + set_argnum_attribute(attr, argnums);
110620 +}
110621 +
110622 +/*
110623 + * Look up the intentional_overflow attribute that turns off ipa based duplication
110624 + * on the callee function.
110625 + */
110626 +static bool is_mark_turn_off_attribute(gimple stmt)
110627 +{
110628 + enum mark mark;
110629 + const_tree fndecl = gimple_call_fndecl(stmt);
110630 +
110631 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
110632 + if (mark == MARK_TURN_OFF)
110633 + return true;
110634 + return false;
110635 +}
110636 +
110637 +// 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
110638 +static void handle_interesting_function(gimple stmt)
110639 +{
110640 + unsigned int argnum;
110641 + tree fndecl;
110642 + bool orig_argnums[MAX_PARAM + 1] = {false};
110643 +
110644 + if (gimple_call_num_args(stmt) == 0)
110645 + return;
110646 + fndecl = gimple_call_fndecl(stmt);
110647 + if (fndecl == NULL_TREE)
110648 + return;
110649 + fndecl = DECL_ORIGIN(fndecl);
110650 +
110651 + if (is_mark_turn_off_attribute(stmt)) {
110652 + create_mark_asm(stmt, MARK_TURN_OFF);
110653 + return;
110654 + }
110655 +
110656 + search_interesting_args(fndecl, orig_argnums);
110657 +
110658 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
110659 + if (orig_argnums[argnum])
110660 + insert_asm_arg(stmt, argnum);
110661 +}
110662 +
110663 +// 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
110664 +static void handle_interesting_ret(gimple stmt)
110665 +{
110666 + bool orig_argnums[MAX_PARAM + 1] = {false};
110667 +
110668 + search_interesting_args(current_function_decl, orig_argnums);
110669 +
110670 + if (orig_argnums[0])
110671 + insert_asm_ret(stmt);
110672 +}
110673 +
110674 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
110675 +static unsigned int search_interesting_functions(void)
110676 +{
110677 + basic_block bb;
110678 +
110679 + FOR_ALL_BB_FN(bb, cfun) {
110680 + gimple_stmt_iterator gsi;
110681 +
110682 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
110683 + gimple stmt = gsi_stmt(gsi);
110684 +
110685 + if (is_size_overflow_asm(stmt))
110686 + continue;
110687 +
110688 + if (is_gimple_call(stmt))
110689 + handle_interesting_function(stmt);
110690 + else if (gimple_code(stmt) == GIMPLE_RETURN)
110691 + handle_interesting_ret(stmt);
110692 + }
110693 + }
110694 + return 0;
110695 +}
110696 +
110697 +/*
110698 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
110699 + * this pass inserts asm stmts to mark the interesting args
110700 + * that the ipa pass will detect and insert the size overflow checks for.
110701 + */
110702 +#if BUILDING_GCC_VERSION >= 4009
110703 +static const struct pass_data insert_size_overflow_asm_pass_data = {
110704 +#else
110705 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
110706 + .pass = {
110707 +#endif
110708 + .type = GIMPLE_PASS,
110709 + .name = "insert_size_overflow_asm",
110710 +#if BUILDING_GCC_VERSION >= 4008
110711 + .optinfo_flags = OPTGROUP_NONE,
110712 +#endif
110713 +#if BUILDING_GCC_VERSION >= 4009
110714 + .has_gate = false,
110715 + .has_execute = true,
110716 +#else
110717 + .gate = NULL,
110718 + .execute = search_interesting_functions,
110719 + .sub = NULL,
110720 + .next = NULL,
110721 + .static_pass_number = 0,
110722 +#endif
110723 + .tv_id = TV_NONE,
110724 + .properties_required = PROP_cfg,
110725 + .properties_provided = 0,
110726 + .properties_destroyed = 0,
110727 + .todo_flags_start = 0,
110728 + .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
110729 +#if BUILDING_GCC_VERSION < 4009
110730 + }
110731 +#endif
110732 +};
110733 +
110734 +#if BUILDING_GCC_VERSION >= 4009
110735 +namespace {
110736 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
110737 +public:
110738 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
110739 + unsigned int execute() { return search_interesting_functions(); }
110740 +};
110741 +}
110742 +#endif
110743 +
110744 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
110745 +{
110746 +#if BUILDING_GCC_VERSION >= 4009
110747 + return new insert_size_overflow_asm_pass();
110748 +#else
110749 + return &insert_size_overflow_asm_pass.pass;
110750 +#endif
110751 +}
110752 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
110753 new file mode 100644
110754 index 0000000..88469e9
110755 --- /dev/null
110756 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
110757 @@ -0,0 +1,902 @@
110758 +/*
110759 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
110760 + * Licensed under the GPL v2, or (at your option) v3
110761 + *
110762 + * Homepage:
110763 + * http://www.grsecurity.net/~ephox/overflow_plugin/
110764 + *
110765 + * Documentation:
110766 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
110767 + *
110768 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
110769 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
110770 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
110771 + *
110772 + * Usage:
110773 + * $ make
110774 + * $ make run
110775 + */
110776 +
110777 +#include "gcc-common.h"
110778 +#include "size_overflow.h"
110779 +
110780 +#define MIN_CHECK true
110781 +#define MAX_CHECK false
110782 +
110783 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
110784 +{
110785 + const_tree type;
110786 + tree new_type;
110787 +
110788 + gcc_assert(node != NULL_TREE);
110789 +
110790 + type = TREE_TYPE(node);
110791 +
110792 + if (pointer_set_contains(visited->my_stmts, stmt))
110793 + return TREE_TYPE(node);
110794 +
110795 + switch (TYPE_MODE(type)) {
110796 + case QImode:
110797 + new_type = size_overflow_type_HI;
110798 + break;
110799 + case HImode:
110800 + new_type = size_overflow_type_SI;
110801 + break;
110802 + case SImode:
110803 + new_type = size_overflow_type_DI;
110804 + break;
110805 + case DImode:
110806 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
110807 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
110808 + else
110809 + new_type = size_overflow_type_TI;
110810 + break;
110811 + case TImode:
110812 + gcc_assert(!TYPE_UNSIGNED(type));
110813 + new_type = size_overflow_type_TI;
110814 + break;
110815 + default:
110816 + debug_tree((tree)node);
110817 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
110818 + gcc_unreachable();
110819 + }
110820 +
110821 + if (TYPE_QUALS(type) != 0)
110822 + return build_qualified_type(new_type, TYPE_QUALS(type));
110823 + return new_type;
110824 +}
110825 +
110826 +static tree get_lhs(const_gimple stmt)
110827 +{
110828 + switch (gimple_code(stmt)) {
110829 + case GIMPLE_ASSIGN:
110830 + case GIMPLE_CALL:
110831 + return gimple_get_lhs(stmt);
110832 + case GIMPLE_PHI:
110833 + return gimple_phi_result(stmt);
110834 + default:
110835 + return NULL_TREE;
110836 + }
110837 +}
110838 +
110839 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
110840 +{
110841 + gimple_stmt_iterator gsi;
110842 + tree lhs;
110843 + gimple new_stmt;
110844 +
110845 + if (rhs == NULL_TREE)
110846 + return NULL_TREE;
110847 +
110848 + gsi = gsi_for_stmt(stmt);
110849 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
110850 + pointer_set_insert(visited->my_stmts, new_stmt);
110851 +
110852 + lhs = get_lhs(new_stmt);
110853 + gcc_assert(lhs != NULL_TREE);
110854 + return lhs;
110855 +}
110856 +
110857 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
110858 +{
110859 + tree lhs, dst_type;
110860 + gimple_stmt_iterator gsi;
110861 +
110862 + if (rhs1 == NULL_TREE) {
110863 + debug_gimple_stmt(oldstmt);
110864 + error("%s: rhs1 is NULL_TREE", __func__);
110865 + gcc_unreachable();
110866 + }
110867 +
110868 + switch (gimple_code(oldstmt)) {
110869 + case GIMPLE_ASM:
110870 + lhs = rhs1;
110871 + break;
110872 + case GIMPLE_CALL:
110873 + case GIMPLE_ASSIGN:
110874 + lhs = gimple_get_lhs(oldstmt);
110875 + break;
110876 + default:
110877 + debug_gimple_stmt(oldstmt);
110878 + gcc_unreachable();
110879 + }
110880 +
110881 + gsi = gsi_for_stmt(oldstmt);
110882 + pointer_set_insert(visited->stmts, oldstmt);
110883 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
110884 + basic_block next_bb, cur_bb;
110885 + const_edge e;
110886 +
110887 + gcc_assert(before == false);
110888 + gcc_assert(stmt_can_throw_internal(oldstmt));
110889 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
110890 + gcc_assert(!gsi_end_p(gsi));
110891 +
110892 + cur_bb = gimple_bb(oldstmt);
110893 + next_bb = cur_bb->next_bb;
110894 + e = find_edge(cur_bb, next_bb);
110895 + gcc_assert(e != NULL);
110896 + gcc_assert(e->flags & EDGE_FALLTHRU);
110897 +
110898 + gsi = gsi_after_labels(next_bb);
110899 + gcc_assert(!gsi_end_p(gsi));
110900 +
110901 + before = true;
110902 + oldstmt = gsi_stmt(gsi);
110903 + }
110904 +
110905 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
110906 +
110907 + if (is_gimple_constant(rhs1))
110908 + return cast_a_tree(dst_type, rhs1);
110909 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
110910 +}
110911 +
110912 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
110913 +{
110914 + gimple stmt;
110915 + gimple_stmt_iterator gsi;
110916 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
110917 +
110918 + if (pointer_set_contains(visited->my_stmts, oldstmt))
110919 + return lhs;
110920 +
110921 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
110922 + rhs1 = gimple_assign_rhs1(oldstmt);
110923 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
110924 + }
110925 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
110926 + rhs2 = gimple_assign_rhs2(oldstmt);
110927 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
110928 + }
110929 +
110930 + stmt = gimple_copy(oldstmt);
110931 + gimple_set_location(stmt, gimple_location(oldstmt));
110932 + pointer_set_insert(visited->my_stmts, stmt);
110933 +
110934 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
110935 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
110936 +
110937 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
110938 +
110939 + new_var = create_new_var(size_overflow_type);
110940 + new_var = make_ssa_name(new_var, stmt);
110941 + gimple_assign_set_lhs(stmt, new_var);
110942 +
110943 + if (rhs1 != NULL_TREE)
110944 + gimple_assign_set_rhs1(stmt, rhs1);
110945 +
110946 + if (rhs2 != NULL_TREE)
110947 + gimple_assign_set_rhs2(stmt, rhs2);
110948 +#if BUILDING_GCC_VERSION >= 4006
110949 + if (rhs3 != NULL_TREE)
110950 + gimple_assign_set_rhs3(stmt, rhs3);
110951 +#endif
110952 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
110953 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
110954 +
110955 + gsi = gsi_for_stmt(oldstmt);
110956 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
110957 + update_stmt(stmt);
110958 + pointer_set_insert(visited->stmts, oldstmt);
110959 + return gimple_assign_lhs(stmt);
110960 +}
110961 +
110962 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
110963 +{
110964 + gimple assign;
110965 + gimple_stmt_iterator gsi;
110966 + basic_block first_bb;
110967 +
110968 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
110969 +
110970 + if (bb->index == 0) {
110971 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
110972 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
110973 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
110974 + bb = first_bb;
110975 + }
110976 +
110977 + gsi = gsi_after_labels(bb);
110978 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
110979 + pointer_set_insert(visited->my_stmts, assign);
110980 +
110981 + return gimple_assign_lhs(assign);
110982 +}
110983 +
110984 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
110985 +{
110986 + gimple_stmt_iterator gsi;
110987 + gimple assign, def_stmt = get_def_stmt(new_arg);
110988 +
110989 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
110990 + gsi = gsi_after_labels(gimple_bb(def_stmt));
110991 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
110992 + } else {
110993 + gsi = gsi_for_stmt(def_stmt);
110994 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
110995 + }
110996 +
110997 + pointer_set_insert(visited->my_stmts, assign);
110998 + return gimple_assign_lhs(assign);
110999 +}
111000 +
111001 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
111002 +{
111003 + basic_block bb;
111004 + gimple_stmt_iterator gsi;
111005 + const_gimple def_stmt;
111006 + gimple assign;
111007 +
111008 + def_stmt = get_def_stmt(arg);
111009 + bb = gimple_bb(def_stmt);
111010 + gcc_assert(bb->index != 0);
111011 + gsi = gsi_after_labels(bb);
111012 +
111013 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
111014 + pointer_set_insert(visited->my_stmts, assign);
111015 + return gimple_assign_lhs(assign);
111016 +}
111017 +
111018 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
111019 +{
111020 + tree size_overflow_type;
111021 + tree arg;
111022 + const_gimple def_stmt;
111023 +
111024 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
111025 + return new_arg;
111026 +
111027 + arg = gimple_phi_arg_def(oldstmt, i);
111028 + def_stmt = get_def_stmt(arg);
111029 + gcc_assert(def_stmt != NULL);
111030 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
111031 +
111032 + switch (gimple_code(def_stmt)) {
111033 + case GIMPLE_PHI:
111034 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
111035 + case GIMPLE_NOP: {
111036 + basic_block bb;
111037 +
111038 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
111039 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
111040 + }
111041 + case GIMPLE_ASM: {
111042 + gimple_stmt_iterator gsi;
111043 + gimple assign, stmt = get_def_stmt(arg);
111044 +
111045 + gsi = gsi_for_stmt(stmt);
111046 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
111047 + pointer_set_insert(visited->my_stmts, assign);
111048 + return gimple_assign_lhs(assign);
111049 + }
111050 + default:
111051 + gcc_assert(new_arg != NULL_TREE);
111052 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
111053 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
111054 + }
111055 +}
111056 +
111057 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
111058 +{
111059 + basic_block bb;
111060 + gimple phi;
111061 + gimple_seq seq;
111062 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
111063 +
111064 + bb = gsi_bb(gsi);
111065 +
111066 + if (result == NULL_TREE) {
111067 + tree old_result = gimple_phi_result(oldstmt);
111068 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
111069 +
111070 + result = create_new_var(size_overflow_type);
111071 + }
111072 +
111073 + phi = create_phi_node(result, bb);
111074 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
111075 + seq = phi_nodes(bb);
111076 + gsi = gsi_last(seq);
111077 + gsi_remove(&gsi, false);
111078 +
111079 + gsi = gsi_for_stmt(oldstmt);
111080 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
111081 + gimple_set_bb(phi, bb);
111082 + return phi;
111083 +}
111084 +
111085 +#if BUILDING_GCC_VERSION <= 4007
111086 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
111087 +#else
111088 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
111089 +#endif
111090 +{
111091 + gimple new_phi;
111092 + unsigned int i;
111093 + tree arg, result;
111094 + location_t loc = gimple_location(oldstmt);
111095 +
111096 +#if BUILDING_GCC_VERSION <= 4007
111097 + gcc_assert(!VEC_empty(tree, *args));
111098 +#else
111099 + gcc_assert(!args->is_empty());
111100 +#endif
111101 +
111102 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
111103 + result = gimple_phi_result(new_phi);
111104 + ssa_name_var = SSA_NAME_VAR(result);
111105 +
111106 +#if BUILDING_GCC_VERSION <= 4007
111107 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
111108 +#else
111109 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
111110 +#endif
111111 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
111112 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
111113 + }
111114 +
111115 +#if BUILDING_GCC_VERSION <= 4007
111116 + VEC_free(tree, heap, *args);
111117 +#else
111118 + vec_free(args);
111119 +#endif
111120 + update_stmt(new_phi);
111121 + pointer_set_insert(visited->my_stmts, new_phi);
111122 + return result;
111123 +}
111124 +
111125 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
111126 +{
111127 + tree ssa_name_var = NULL_TREE;
111128 +#if BUILDING_GCC_VERSION <= 4007
111129 + VEC(tree, heap) *args = NULL;
111130 +#else
111131 + vec<tree, va_heap, vl_embed> *args = NULL;
111132 +#endif
111133 + gimple oldstmt = get_def_stmt(orig_result);
111134 + unsigned int i, len = gimple_phi_num_args(oldstmt);
111135 +
111136 + pointer_set_insert(visited->stmts, oldstmt);
111137 + for (i = 0; i < len; i++) {
111138 + tree arg, new_arg;
111139 +
111140 + arg = gimple_phi_arg_def(oldstmt, i);
111141 + new_arg = expand(visited, caller_node, arg);
111142 +
111143 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
111144 + ssa_name_var = SSA_NAME_VAR(new_arg);
111145 +
111146 + if (is_gimple_constant(arg)) {
111147 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
111148 +
111149 + new_arg = cast_a_tree(size_overflow_type, arg);
111150 + }
111151 +
111152 +#if BUILDING_GCC_VERSION <= 4007
111153 + VEC_safe_push(tree, heap, args, new_arg);
111154 +#else
111155 + vec_safe_push(args, new_arg);
111156 +#endif
111157 + }
111158 +
111159 +#if BUILDING_GCC_VERSION <= 4007
111160 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
111161 +#else
111162 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
111163 +#endif
111164 +}
111165 +
111166 +static tree create_cast_assign(struct visited *visited, gimple stmt)
111167 +{
111168 + tree rhs1 = gimple_assign_rhs1(stmt);
111169 + tree lhs = gimple_assign_lhs(stmt);
111170 + const_tree rhs1_type = TREE_TYPE(rhs1);
111171 + const_tree lhs_type = TREE_TYPE(lhs);
111172 +
111173 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
111174 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111175 +
111176 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
111177 +}
111178 +
111179 +static bool skip_lhs_cast_check(const_gimple stmt)
111180 +{
111181 + const_tree rhs = gimple_assign_rhs1(stmt);
111182 + const_gimple def_stmt = get_def_stmt(rhs);
111183 +
111184 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
111185 + if (gimple_code(def_stmt) == GIMPLE_ASM)
111186 + return true;
111187 +
111188 + if (is_const_plus_unsigned_signed_truncation(rhs))
111189 + return true;
111190 +
111191 + return false;
111192 +}
111193 +
111194 +static tree create_string_param(tree string)
111195 +{
111196 + tree i_type, a_type;
111197 + const int length = TREE_STRING_LENGTH(string);
111198 +
111199 + gcc_assert(length > 0);
111200 +
111201 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
111202 + a_type = build_array_type(char_type_node, i_type);
111203 +
111204 + TREE_TYPE(string) = a_type;
111205 + TREE_CONSTANT(string) = 1;
111206 + TREE_READONLY(string) = 1;
111207 +
111208 + return build1(ADDR_EXPR, ptr_type_node, string);
111209 +}
111210 +
111211 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
111212 +{
111213 + gimple cond_stmt;
111214 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
111215 +
111216 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
111217 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
111218 + update_stmt(cond_stmt);
111219 +}
111220 +
111221 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
111222 +{
111223 + gimple func_stmt;
111224 + const_gimple def_stmt;
111225 + const_tree loc_line;
111226 + tree loc_file, ssa_name, current_func;
111227 + expanded_location xloc;
111228 + char *ssa_name_buf;
111229 + int len;
111230 + struct cgraph_edge *edge;
111231 + struct cgraph_node *callee_node;
111232 + int frequency;
111233 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
111234 +
111235 + def_stmt = get_def_stmt(arg);
111236 + xloc = expand_location(gimple_location(def_stmt));
111237 +
111238 + if (!gimple_has_location(def_stmt)) {
111239 + xloc = expand_location(gimple_location(stmt));
111240 + if (!gimple_has_location(stmt))
111241 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
111242 + }
111243 +
111244 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
111245 +
111246 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
111247 + loc_file = create_string_param(loc_file);
111248 +
111249 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
111250 + current_func = create_string_param(current_func);
111251 +
111252 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
111253 + call_count++;
111254 + 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);
111255 + gcc_assert(len > 0);
111256 + ssa_name = build_string(len + 1, ssa_name_buf);
111257 + free(ssa_name_buf);
111258 + ssa_name = create_string_param(ssa_name);
111259 +
111260 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
111261 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
111262 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
111263 +
111264 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
111265 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
111266 +
111267 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
111268 + gcc_assert(edge != NULL);
111269 +}
111270 +
111271 +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)
111272 +{
111273 + basic_block cond_bb, join_bb, bb_true;
111274 + edge e;
111275 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
111276 +
111277 + cond_bb = gimple_bb(stmt);
111278 + if (before)
111279 + gsi_prev(&gsi);
111280 + if (gsi_end_p(gsi))
111281 + e = split_block_after_labels(cond_bb);
111282 + else
111283 + e = split_block(cond_bb, gsi_stmt(gsi));
111284 + cond_bb = e->src;
111285 + join_bb = e->dest;
111286 + e->flags = EDGE_FALSE_VALUE;
111287 + e->probability = REG_BR_PROB_BASE;
111288 +
111289 + bb_true = create_empty_bb(cond_bb);
111290 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
111291 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
111292 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
111293 +
111294 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
111295 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
111296 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
111297 +
111298 + if (current_loops != NULL) {
111299 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
111300 + add_bb_to_loop(bb_true, cond_bb->loop_father);
111301 + }
111302 +
111303 + insert_cond(cond_bb, arg, cond_code, type_value);
111304 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
111305 +
111306 +// print_the_code_insertions(stmt);
111307 +}
111308 +
111309 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
111310 +{
111311 + const_tree rhs_type = TREE_TYPE(rhs);
111312 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
111313 +
111314 + gcc_assert(rhs_type != NULL_TREE);
111315 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
111316 + return;
111317 +
111318 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
111319 +
111320 + if (is_const_plus_unsigned_signed_truncation(rhs))
111321 + return;
111322 +
111323 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
111324 + // typemax (-1) < typemin (0)
111325 + if (TREE_OVERFLOW(type_max))
111326 + return;
111327 +
111328 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
111329 +
111330 + cast_rhs_type = TREE_TYPE(cast_rhs);
111331 + type_max_type = TREE_TYPE(type_max);
111332 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
111333 +
111334 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
111335 +
111336 + // special case: get_size_overflow_type(), 32, u64->s
111337 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
111338 + return;
111339 +
111340 + type_min_type = TREE_TYPE(type_min);
111341 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
111342 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
111343 +}
111344 +
111345 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
111346 +{
111347 + bool cast_lhs, cast_rhs;
111348 + tree lhs = gimple_assign_lhs(stmt);
111349 + tree rhs = gimple_assign_rhs1(stmt);
111350 + const_tree lhs_type = TREE_TYPE(lhs);
111351 + const_tree rhs_type = TREE_TYPE(rhs);
111352 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
111353 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
111354 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
111355 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
111356 +
111357 + static bool check_lhs[3][4] = {
111358 + // ss su us uu
111359 + { false, true, true, false }, // lhs > rhs
111360 + { false, false, false, false }, // lhs = rhs
111361 + { true, true, true, true }, // lhs < rhs
111362 + };
111363 +
111364 + static bool check_rhs[3][4] = {
111365 + // ss su us uu
111366 + { true, false, true, true }, // lhs > rhs
111367 + { true, false, true, true }, // lhs = rhs
111368 + { true, false, true, true }, // lhs < rhs
111369 + };
111370 +
111371 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
111372 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
111373 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111374 +
111375 + if (lhs_size > rhs_size) {
111376 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111377 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111378 + } else if (lhs_size == rhs_size) {
111379 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111380 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111381 + } else {
111382 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111383 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111384 + }
111385 +
111386 + if (!cast_lhs && !cast_rhs)
111387 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111388 +
111389 + if (cast_lhs && !skip_lhs_cast_check(stmt))
111390 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
111391 +
111392 + if (cast_rhs)
111393 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
111394 +
111395 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111396 +}
111397 +
111398 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
111399 +{
111400 + enum tree_code rhs_code;
111401 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
111402 +
111403 + if (pointer_set_contains(visited->my_stmts, stmt))
111404 + return lhs;
111405 +
111406 + rhs1 = gimple_assign_rhs1(stmt);
111407 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
111408 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111409 +
111410 + new_rhs1 = expand(visited, caller_node, rhs1);
111411 +
111412 + if (new_rhs1 == NULL_TREE)
111413 + return create_cast_assign(visited, stmt);
111414 +
111415 + if (pointer_set_contains(visited->no_cast_check, stmt))
111416 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111417 +
111418 + rhs_code = gimple_assign_rhs_code(stmt);
111419 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
111420 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
111421 +
111422 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
111423 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
111424 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111425 + }
111426 +
111427 + if (!gimple_assign_cast_p(stmt))
111428 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111429 +
111430 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
111431 +}
111432 +
111433 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
111434 +{
111435 + tree rhs1, lhs = gimple_assign_lhs(stmt);
111436 + gimple def_stmt = get_def_stmt(lhs);
111437 +
111438 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
111439 + rhs1 = gimple_assign_rhs1(def_stmt);
111440 +
111441 + if (is_gimple_constant(rhs1))
111442 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
111443 +
111444 + switch (TREE_CODE(rhs1)) {
111445 + case SSA_NAME: {
111446 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
111447 +
111448 + if (gimple_assign_cast_p(stmt))
111449 + unsigned_signed_cast_intentional_overflow(visited, stmt);
111450 + return ret;
111451 + }
111452 + case ARRAY_REF:
111453 + case BIT_FIELD_REF:
111454 + case ADDR_EXPR:
111455 + case COMPONENT_REF:
111456 + case INDIRECT_REF:
111457 +#if BUILDING_GCC_VERSION >= 4006
111458 + case MEM_REF:
111459 +#endif
111460 + case TARGET_MEM_REF:
111461 + case VIEW_CONVERT_EXPR:
111462 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
111463 + case PARM_DECL:
111464 + case VAR_DECL:
111465 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111466 +
111467 + default:
111468 + debug_gimple_stmt(def_stmt);
111469 + debug_tree(rhs1);
111470 + gcc_unreachable();
111471 + }
111472 +}
111473 +
111474 +static void __unused print_the_code_insertions(const_gimple stmt)
111475 +{
111476 + location_t loc = gimple_location(stmt);
111477 +
111478 + inform(loc, "Integer size_overflow check applied here.");
111479 +}
111480 +
111481 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
111482 +{
111483 + enum intentional_overflow_type res;
111484 + tree rhs1, rhs2, new_lhs;
111485 + gimple def_stmt = get_def_stmt(lhs);
111486 + tree new_rhs1 = NULL_TREE;
111487 + tree new_rhs2 = NULL_TREE;
111488 +
111489 + rhs1 = gimple_assign_rhs1(def_stmt);
111490 + rhs2 = gimple_assign_rhs2(def_stmt);
111491 +
111492 + /* no DImode/TImode division in the 32/64 bit kernel */
111493 + switch (gimple_assign_rhs_code(def_stmt)) {
111494 + case RDIV_EXPR:
111495 + case TRUNC_DIV_EXPR:
111496 + case CEIL_DIV_EXPR:
111497 + case FLOOR_DIV_EXPR:
111498 + case ROUND_DIV_EXPR:
111499 + case TRUNC_MOD_EXPR:
111500 + case CEIL_MOD_EXPR:
111501 + case FLOOR_MOD_EXPR:
111502 + case ROUND_MOD_EXPR:
111503 + case EXACT_DIV_EXPR:
111504 + case POINTER_PLUS_EXPR:
111505 + case BIT_AND_EXPR:
111506 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
111507 + default:
111508 + break;
111509 + }
111510 +
111511 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
111512 + if (new_lhs != NULL_TREE)
111513 + return new_lhs;
111514 +
111515 + if (TREE_CODE(rhs1) == SSA_NAME)
111516 + new_rhs1 = expand(visited, caller_node, rhs1);
111517 + if (TREE_CODE(rhs2) == SSA_NAME)
111518 + new_rhs2 = expand(visited, caller_node, rhs2);
111519 +
111520 + res = add_mul_intentional_overflow(def_stmt);
111521 + if (res != NO_INTENTIONAL_OVERFLOW) {
111522 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
111523 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
111524 + return new_lhs;
111525 + }
111526 +
111527 + if (skip_expr_on_double_type(def_stmt)) {
111528 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
111529 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
111530 + return new_lhs;
111531 + }
111532 +
111533 + if (is_a_neg_overflow(def_stmt, rhs2))
111534 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
111535 + if (is_a_neg_overflow(def_stmt, rhs1))
111536 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
111537 +
111538 +
111539 + if (is_a_constant_overflow(def_stmt, rhs2))
111540 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
111541 + if (is_a_constant_overflow(def_stmt, rhs1))
111542 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
111543 +
111544 + // the const is between 0 and (signed) MAX
111545 + if (is_gimple_constant(rhs1))
111546 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
111547 + if (is_gimple_constant(rhs2))
111548 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
111549 +
111550 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
111551 +}
111552 +
111553 +#if BUILDING_GCC_VERSION >= 4006
111554 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
111555 +{
111556 + if (is_gimple_constant(rhs))
111557 + return cast_a_tree(size_overflow_type, rhs);
111558 + if (TREE_CODE(rhs) != SSA_NAME)
111559 + return NULL_TREE;
111560 + return expand(visited, caller_node, rhs);
111561 +}
111562 +
111563 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
111564 +{
111565 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
111566 + gimple def_stmt = get_def_stmt(lhs);
111567 +
111568 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
111569 +
111570 + rhs1 = gimple_assign_rhs1(def_stmt);
111571 + rhs2 = gimple_assign_rhs2(def_stmt);
111572 + rhs3 = gimple_assign_rhs3(def_stmt);
111573 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
111574 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
111575 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
111576 +
111577 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
111578 +}
111579 +#endif
111580 +
111581 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
111582 +{
111583 + gimple_stmt_iterator gsi;
111584 + gimple next_stmt = NULL;
111585 +
111586 + gsi = gsi_for_stmt(stmt);
111587 +
111588 + do {
111589 + gsi_next(&gsi);
111590 + next_stmt = gsi_stmt(gsi);
111591 +
111592 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
111593 + return NULL_TREE;
111594 +
111595 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
111596 + break;
111597 +
111598 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
111599 + } while (!gsi_end_p(gsi));
111600 +
111601 + gcc_assert(next_stmt);
111602 + return get_lhs(next_stmt);
111603 +}
111604 +
111605 +static tree expand_visited(struct visited *visited, gimple def_stmt)
111606 +{
111607 + gimple_stmt_iterator gsi;
111608 + enum gimple_code code = gimple_code(def_stmt);
111609 +
111610 + if (code == GIMPLE_ASM)
111611 + return NULL_TREE;
111612 +
111613 + gsi = gsi_for_stmt(def_stmt);
111614 + gsi_next(&gsi);
111615 +
111616 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
111617 + return NULL_TREE;
111618 + return get_my_stmt_lhs(visited, def_stmt);
111619 +}
111620 +
111621 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
111622 +{
111623 + gimple def_stmt;
111624 +
111625 + def_stmt = get_def_stmt(lhs);
111626 +
111627 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
111628 + return NULL_TREE;
111629 +
111630 + if (pointer_set_contains(visited->my_stmts, def_stmt))
111631 + return lhs;
111632 +
111633 + if (pointer_set_contains(visited->stmts, def_stmt))
111634 + return expand_visited(visited, def_stmt);
111635 +
111636 + switch (gimple_code(def_stmt)) {
111637 + case GIMPLE_PHI:
111638 + return handle_phi(visited, caller_node, lhs);
111639 + case GIMPLE_CALL:
111640 + case GIMPLE_ASM:
111641 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
111642 + case GIMPLE_ASSIGN:
111643 + switch (gimple_num_ops(def_stmt)) {
111644 + case 2:
111645 + return handle_unary_ops(visited, caller_node, def_stmt);
111646 + case 3:
111647 + return handle_binary_ops(visited, caller_node, lhs);
111648 +#if BUILDING_GCC_VERSION >= 4006
111649 + case 4:
111650 + return handle_ternary_ops(visited, caller_node, lhs);
111651 +#endif
111652 + }
111653 + default:
111654 + debug_gimple_stmt(def_stmt);
111655 + error("%s: unknown gimple code", __func__);
111656 + gcc_unreachable();
111657 + }
111658 +}
111659 +
111660 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
111661 new file mode 100644
111662 index 0000000..f8f5dd5
111663 --- /dev/null
111664 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
111665 @@ -0,0 +1,1133 @@
111666 +/*
111667 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
111668 + * Licensed under the GPL v2, or (at your option) v3
111669 + *
111670 + * Homepage:
111671 + * http://www.grsecurity.net/~ephox/overflow_plugin/
111672 + *
111673 + * Documentation:
111674 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
111675 + *
111676 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
111677 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
111678 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
111679 + *
111680 + * Usage:
111681 + * $ make
111682 + * $ make run
111683 + */
111684 +
111685 +#include "gcc-common.h"
111686 +#include "size_overflow.h"
111687 +
111688 +#define VEC_LEN 128
111689 +#define RET_CHECK NULL_TREE
111690 +#define WRONG_NODE 32
111691 +#define NOT_INTENTIONAL_ASM NULL
111692 +
111693 +unsigned int call_count;
111694 +
111695 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
111696 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
111697 +
111698 +struct visited_fns {
111699 + struct visited_fns *next;
111700 + const_tree fndecl;
111701 + unsigned int num;
111702 + const_gimple first_stmt;
111703 +};
111704 +
111705 +struct next_cgraph_node {
111706 + struct next_cgraph_node *next;
111707 + struct cgraph_node *current_function;
111708 + tree callee_fndecl;
111709 + unsigned int num;
111710 +};
111711 +
111712 +// Don't want to duplicate entries in next_cgraph_node
111713 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
111714 +{
111715 + const_tree new_callee_fndecl;
111716 + struct next_cgraph_node *cur_node;
111717 +
111718 + if (fndecl == RET_CHECK)
111719 + new_callee_fndecl = NODE_DECL(node);
111720 + else
111721 + new_callee_fndecl = fndecl;
111722 +
111723 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
111724 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
111725 + continue;
111726 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
111727 + continue;
111728 + if (num == cur_node->num)
111729 + return true;
111730 + }
111731 + return false;
111732 +}
111733 +
111734 +/* Add a next_cgraph_node into the list for handle_function().
111735 + * handle_function() iterates over all the next cgraph nodes and
111736 + * starts the overflow check insertion process.
111737 + */
111738 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
111739 +{
111740 + struct next_cgraph_node *new_node;
111741 +
111742 + if (is_in_next_cgraph_node(head, node, fndecl, num))
111743 + return head;
111744 +
111745 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
111746 + new_node->current_function = node;
111747 + new_node->next = NULL;
111748 + new_node->num = num;
111749 + if (fndecl == RET_CHECK)
111750 + new_node->callee_fndecl = NODE_DECL(node);
111751 + else
111752 + new_node->callee_fndecl = fndecl;
111753 +
111754 + if (!head)
111755 + return new_node;
111756 +
111757 + new_node->next = head;
111758 + return new_node;
111759 +}
111760 +
111761 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
111762 +{
111763 + struct cgraph_edge *e;
111764 +
111765 + if (num == 0)
111766 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
111767 +
111768 + for (e = node->callers; e; e = e->next_caller) {
111769 + tree fndecl = gimple_call_fndecl(e->call_stmt);
111770 +
111771 + gcc_assert(fndecl != NULL_TREE);
111772 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
111773 + }
111774 +
111775 + return head;
111776 +}
111777 +
111778 +struct missing_functions {
111779 + struct missing_functions *next;
111780 + const_tree node;
111781 + tree fndecl;
111782 +};
111783 +
111784 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
111785 +{
111786 + struct missing_functions *new_function;
111787 +
111788 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
111789 + new_function->node = node;
111790 + new_function->next = NULL;
111791 +
111792 + if (TREE_CODE(node) == FUNCTION_DECL)
111793 + new_function->fndecl = node;
111794 + else
111795 + new_function->fndecl = current_function_decl;
111796 + gcc_assert(new_function->fndecl);
111797 +
111798 + if (!missing_fn_head)
111799 + return new_function;
111800 +
111801 + new_function->next = missing_fn_head;
111802 + return new_function;
111803 +}
111804 +
111805 +/* If the function is missing from the hash table and it is a static function
111806 + * then create a next_cgraph_node from it for handle_function()
111807 + */
111808 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
111809 +{
111810 + unsigned int num;
111811 + const_tree orig_fndecl;
111812 + struct cgraph_node *next_node = NULL;
111813 +
111814 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
111815 +
111816 + num = get_function_num(missing_fn_head->node, orig_fndecl);
111817 + if (num == CANNOT_FIND_ARG)
111818 + return cnodes;
111819 +
111820 + if (!is_missing_function(orig_fndecl, num))
111821 + return cnodes;
111822 +
111823 + next_node = cgraph_get_node(missing_fn_head->fndecl);
111824 + if (next_node && next_node->local.local)
111825 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
111826 + return cnodes;
111827 +}
111828 +
111829 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
111830 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
111831 + */
111832 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
111833 +{
111834 + unsigned int i;
111835 + tree node;
111836 + struct missing_functions *cur, *missing_fn_head = NULL;
111837 +
111838 +#if BUILDING_GCC_VERSION <= 4007
111839 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
111840 +#else
111841 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
111842 +#endif
111843 + switch (TREE_CODE(node)) {
111844 + case PARM_DECL:
111845 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
111846 + break;
111847 + case FUNCTION_DECL:
111848 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
111849 + break;
111850 + default:
111851 + break;
111852 + }
111853 + }
111854 +
111855 + while (missing_fn_head) {
111856 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
111857 +
111858 + cur = missing_fn_head->next;
111859 + free(missing_fn_head);
111860 + missing_fn_head = cur;
111861 + }
111862 +
111863 + return cnodes;
111864 +}
111865 +
111866 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
111867 +{
111868 + gimple phi = get_def_stmt(result);
111869 + unsigned int i, n = gimple_phi_num_args(phi);
111870 +
111871 + pointer_set_insert(visited, phi);
111872 + for (i = 0; i < n; i++) {
111873 + const_tree arg = gimple_phi_arg_def(phi, i);
111874 +
111875 + set_conditions(visited, interesting_conditions, arg);
111876 + }
111877 +}
111878 +
111879 +enum conditions {
111880 + FROM_CONST, NOT_UNARY, CAST
111881 +};
111882 +
111883 +// Search for constants, cast assignments and binary/ternary assignments
111884 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
111885 +{
111886 + gimple def_stmt = get_def_stmt(lhs);
111887 +
111888 + if (is_gimple_constant(lhs)) {
111889 + interesting_conditions[FROM_CONST] = true;
111890 + return;
111891 + }
111892 +
111893 + if (!def_stmt)
111894 + return;
111895 +
111896 + if (pointer_set_contains(visited, def_stmt))
111897 + return;
111898 +
111899 + switch (gimple_code(def_stmt)) {
111900 + case GIMPLE_NOP:
111901 + case GIMPLE_CALL:
111902 + case GIMPLE_ASM:
111903 + return;
111904 + case GIMPLE_PHI:
111905 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
111906 + case GIMPLE_ASSIGN:
111907 + if (gimple_num_ops(def_stmt) == 2) {
111908 + const_tree rhs = gimple_assign_rhs1(def_stmt);
111909 +
111910 + if (gimple_assign_cast_p(def_stmt))
111911 + interesting_conditions[CAST] = true;
111912 +
111913 + return set_conditions(visited, interesting_conditions, rhs);
111914 + } else {
111915 + interesting_conditions[NOT_UNARY] = true;
111916 + return;
111917 + }
111918 + default:
111919 + debug_gimple_stmt(def_stmt);
111920 + gcc_unreachable();
111921 + }
111922 +}
111923 +
111924 +// determine whether duplication will be necessary or not.
111925 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
111926 +{
111927 + struct pointer_set_t *visited;
111928 +
111929 + if (gimple_assign_cast_p(cur_node->first_stmt))
111930 + interesting_conditions[CAST] = true;
111931 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
111932 + interesting_conditions[NOT_UNARY] = true;
111933 +
111934 + visited = pointer_set_create();
111935 + set_conditions(visited, interesting_conditions, cur_node->node);
111936 + pointer_set_destroy(visited);
111937 +}
111938 +
111939 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
111940 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
111941 +{
111942 + gimple assign;
111943 + gimple_stmt_iterator gsi;
111944 +
111945 + // already removed
111946 + if (gimple_bb(asm_stmt) == NULL)
111947 + return;
111948 + gsi = gsi_for_stmt(asm_stmt);
111949 +
111950 + assign = gimple_build_assign(lhs, rhs);
111951 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
111952 + SSA_NAME_DEF_STMT(lhs) = assign;
111953 +
111954 + gsi_remove(&gsi, true);
111955 +}
111956 +
111957 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
111958 + * stmt is a return otherwise it is the callee function.
111959 + */
111960 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
111961 +{
111962 + const_tree fndecl;
111963 +
111964 + if (argnum == 0)
111965 + fndecl = current_function_decl;
111966 + else
111967 + fndecl = gimple_call_fndecl(stmt);
111968 +
111969 + if (fndecl == NULL_TREE)
111970 + return NULL_TREE;
111971 +
111972 + return DECL_ORIGIN(fndecl);
111973 +}
111974 +
111975 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
111976 +static bool skip_asm(const_tree arg)
111977 +{
111978 + gimple def_stmt = get_def_stmt(arg);
111979 +
111980 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
111981 + return false;
111982 +
111983 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
111984 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
111985 +}
111986 +
111987 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
111988 +{
111989 + gimple phi = get_def_stmt(result);
111990 + unsigned int i, n = gimple_phi_num_args(phi);
111991 +
111992 + pointer_set_insert(visited, phi);
111993 + for (i = 0; i < n; i++) {
111994 + tree arg = gimple_phi_arg_def(phi, i);
111995 +
111996 + walk_use_def(visited, cur_node, arg);
111997 + }
111998 +}
111999 +
112000 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
112001 +{
112002 + gimple def_stmt = get_def_stmt(lhs);
112003 + tree rhs1, rhs2;
112004 +
112005 + rhs1 = gimple_assign_rhs1(def_stmt);
112006 + rhs2 = gimple_assign_rhs2(def_stmt);
112007 +
112008 + walk_use_def(visited, cur_node, rhs1);
112009 + walk_use_def(visited, cur_node, rhs2);
112010 +}
112011 +
112012 +static void insert_last_node(struct interesting_node *cur_node, tree node)
112013 +{
112014 + unsigned int i;
112015 + tree element;
112016 + enum tree_code code;
112017 +
112018 + gcc_assert(node != NULL_TREE);
112019 +
112020 + if (is_gimple_constant(node))
112021 + return;
112022 +
112023 + code = TREE_CODE(node);
112024 + if (code == VAR_DECL) {
112025 + node = DECL_ORIGIN(node);
112026 + code = TREE_CODE(node);
112027 + }
112028 +
112029 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
112030 + return;
112031 +
112032 +#if BUILDING_GCC_VERSION <= 4007
112033 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
112034 +#else
112035 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
112036 +#endif
112037 + if (operand_equal_p(node, element, 0))
112038 + return;
112039 + }
112040 +
112041 +#if BUILDING_GCC_VERSION <= 4007
112042 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
112043 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
112044 +#else
112045 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
112046 + vec_safe_push(cur_node->last_nodes, node);
112047 +#endif
112048 +}
112049 +
112050 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
112051 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
112052 +{
112053 + if (!is_size_overflow_asm(stmt))
112054 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
112055 +}
112056 +
112057 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
112058 + * and component refs (for checking the intentional_overflow attribute).
112059 + */
112060 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
112061 +{
112062 + const_gimple def_stmt;
112063 +
112064 + if (TREE_CODE(lhs) != SSA_NAME) {
112065 + insert_last_node(cur_node, lhs);
112066 + return;
112067 + }
112068 +
112069 + def_stmt = get_def_stmt(lhs);
112070 + if (!def_stmt)
112071 + return;
112072 +
112073 + if (pointer_set_insert(visited, def_stmt))
112074 + return;
112075 +
112076 + switch (gimple_code(def_stmt)) {
112077 + case GIMPLE_NOP:
112078 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
112079 + case GIMPLE_ASM:
112080 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
112081 + case GIMPLE_CALL: {
112082 + tree fndecl = gimple_call_fndecl(def_stmt);
112083 +
112084 + if (fndecl == NULL_TREE)
112085 + return;
112086 + insert_last_node(cur_node, fndecl);
112087 + return;
112088 + }
112089 + case GIMPLE_PHI:
112090 + return walk_use_def_phi(visited, cur_node, lhs);
112091 + case GIMPLE_ASSIGN:
112092 + switch (gimple_num_ops(def_stmt)) {
112093 + case 2:
112094 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
112095 + case 3:
112096 + return walk_use_def_binary(visited, cur_node, lhs);
112097 + }
112098 + default:
112099 + debug_gimple_stmt((gimple)def_stmt);
112100 + error("%s: unknown gimple code", __func__);
112101 + gcc_unreachable();
112102 + }
112103 +}
112104 +
112105 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
112106 +static void set_last_nodes(struct interesting_node *cur_node)
112107 +{
112108 + struct pointer_set_t *visited;
112109 +
112110 + visited = pointer_set_create();
112111 + walk_use_def(visited, cur_node, cur_node->node);
112112 + pointer_set_destroy(visited);
112113 +}
112114 +
112115 +enum precond {
112116 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
112117 +};
112118 +
112119 +/* 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.
112120 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
112121 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
112122 + * 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.
112123 + */
112124 +static enum precond check_preconditions(struct interesting_node *cur_node)
112125 +{
112126 + bool interesting_conditions[3] = {false, false, false};
112127 +
112128 + set_last_nodes(cur_node);
112129 +
112130 + check_intentional_attribute_ipa(cur_node);
112131 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
112132 + return NO_ATTRIBUTE_SEARCH;
112133 +
112134 + search_interesting_conditions(cur_node, interesting_conditions);
112135 +
112136 + // error code
112137 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
112138 + return NO_ATTRIBUTE_SEARCH;
112139 +
112140 + // unnecessary overflow check
112141 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
112142 + return NO_CHECK_INSERT;
112143 +
112144 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
112145 + return NO_CHECK_INSERT;
112146 +
112147 + return NONE;
112148 +}
112149 +
112150 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
112151 +{
112152 + const_gimple assign;
112153 + tree orig_type = TREE_TYPE(orig_node);
112154 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
112155 +
112156 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
112157 + return gimple_assign_lhs(assign);
112158 +}
112159 +
112160 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
112161 +{
112162 + void (*set_rhs)(gimple, tree);
112163 + gimple stmt = cur_node->first_stmt;
112164 + const_tree orig_node = cur_node->node;
112165 +
112166 + switch (gimple_code(stmt)) {
112167 + case GIMPLE_RETURN:
112168 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
112169 + break;
112170 + case GIMPLE_CALL:
112171 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
112172 + break;
112173 + case GIMPLE_ASSIGN:
112174 + switch (cur_node->num) {
112175 + case 1:
112176 + set_rhs = &gimple_assign_set_rhs1;
112177 + break;
112178 + case 2:
112179 + set_rhs = &gimple_assign_set_rhs2;
112180 + break;
112181 +#if BUILDING_GCC_VERSION >= 4006
112182 + case 3:
112183 + set_rhs = &gimple_assign_set_rhs3;
112184 + break;
112185 +#endif
112186 + default:
112187 + gcc_unreachable();
112188 + }
112189 +
112190 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
112191 + break;
112192 + default:
112193 + debug_gimple_stmt(stmt);
112194 + gcc_unreachable();
112195 + }
112196 +
112197 + update_stmt(stmt);
112198 +}
112199 +
112200 +static struct visited *create_visited(void)
112201 +{
112202 + struct visited *new_node;
112203 +
112204 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
112205 + new_node->stmts = pointer_set_create();
112206 + new_node->my_stmts = pointer_set_create();
112207 + new_node->skip_expr_casts = pointer_set_create();
112208 + new_node->no_cast_check = pointer_set_create();
112209 + return new_node;
112210 +}
112211 +
112212 +static void free_visited(struct visited *visited)
112213 +{
112214 + pointer_set_destroy(visited->stmts);
112215 + pointer_set_destroy(visited->my_stmts);
112216 + pointer_set_destroy(visited->skip_expr_casts);
112217 + pointer_set_destroy(visited->no_cast_check);
112218 +
112219 + free(visited);
112220 +}
112221 +
112222 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
112223 + * 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
112224 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
112225 + */
112226 +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)
112227 +{
112228 + enum precond ret;
112229 + tree new_node, orig_node = cur_node->node;
112230 +
112231 + ret = check_preconditions(cur_node);
112232 + if (ret == NO_ATTRIBUTE_SEARCH)
112233 + return cnodes;
112234 +
112235 + cnodes = search_overflow_attribute(cnodes, cur_node);
112236 +
112237 + if (ret == NO_CHECK_INSERT)
112238 + return cnodes;
112239 +
112240 + new_node = expand(visited, caller_node, orig_node);
112241 + if (new_node == NULL_TREE)
112242 + return cnodes;
112243 +
112244 + change_orig_node(visited, cur_node, new_node);
112245 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
112246 +
112247 + return cnodes;
112248 +}
112249 +
112250 +// Check visited_fns interesting nodes.
112251 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
112252 +{
112253 + struct interesting_node *cur;
112254 +
112255 + for (cur = head; cur; cur = cur->next) {
112256 + if (!operand_equal_p(node, cur->node, 0))
112257 + continue;
112258 + if (num != cur->num)
112259 + continue;
112260 + if (first_stmt == cur->first_stmt)
112261 + return true;
112262 + }
112263 + return false;
112264 +}
112265 +
112266 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
112267 + 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
112268 + 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
112269 + the intentional_overflow attribute check. They are collected by set_last_nodes().
112270 + num: arg count of a call stmt or 0 when it is a ret
112271 + node: the recursion starts from here, it is a call arg or a return value
112272 + 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.
112273 + intentional_attr_decl: intentional_overflow attribute of the callee function
112274 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
112275 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
112276 + */
112277 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
112278 +{
112279 + struct interesting_node *new_node;
112280 + tree fndecl;
112281 + enum gimple_code code;
112282 +
112283 + gcc_assert(node != NULL_TREE);
112284 + code = gimple_code(first_stmt);
112285 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
112286 +
112287 + if (num == CANNOT_FIND_ARG)
112288 + return head;
112289 +
112290 + if (skip_types(node))
112291 + return head;
112292 +
112293 + if (skip_asm(node))
112294 + return head;
112295 +
112296 + if (is_gimple_call(first_stmt))
112297 + fndecl = gimple_call_fndecl(first_stmt);
112298 + else
112299 + fndecl = current_function_decl;
112300 +
112301 + if (fndecl == NULL_TREE)
112302 + return head;
112303 +
112304 + if (is_in_interesting_node(head, first_stmt, node, num))
112305 + return head;
112306 +
112307 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
112308 +
112309 + new_node->next = NULL;
112310 + new_node->first_stmt = first_stmt;
112311 +#if BUILDING_GCC_VERSION <= 4007
112312 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
112313 +#else
112314 + vec_alloc(new_node->last_nodes, VEC_LEN);
112315 +#endif
112316 + new_node->num = num;
112317 + new_node->node = node;
112318 + new_node->fndecl = fndecl;
112319 + new_node->intentional_attr_decl = MARK_NO;
112320 + new_node->intentional_attr_cur_fndecl = MARK_NO;
112321 + new_node->intentional_mark_from_gimple = asm_stmt;
112322 +
112323 + if (!head)
112324 + return new_node;
112325 +
112326 + new_node->next = head;
112327 + return new_node;
112328 +}
112329 +
112330 +/* 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).
112331 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
112332 + */
112333 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
112334 +{
112335 + struct next_cgraph_node *cur_node;
112336 + tree ret = gimple_return_retval(stmt);
112337 +
112338 + if (ret == NULL_TREE)
112339 + return head;
112340 +
112341 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
112342 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
112343 + continue;
112344 + if (cur_node->num == 0)
112345 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
112346 + }
112347 +
112348 + return head;
112349 +}
112350 +
112351 +/* 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).
112352 + * If the call stmt is in the next cgraph node list then it's an interesting call.
112353 + */
112354 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
112355 +{
112356 + unsigned int argnum;
112357 + tree arg;
112358 + const_tree fndecl;
112359 + struct next_cgraph_node *cur_node;
112360 +
112361 + fndecl = gimple_call_fndecl(stmt);
112362 + if (fndecl == NULL_TREE)
112363 + return head;
112364 +
112365 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
112366 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
112367 + continue;
112368 + argnum = get_correct_arg_count(cur_node->num, fndecl);
112369 + gcc_assert(argnum != CANNOT_FIND_ARG);
112370 + if (argnum == 0)
112371 + continue;
112372 +
112373 + arg = gimple_call_arg(stmt, argnum - 1);
112374 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
112375 + }
112376 +
112377 + return head;
112378 +}
112379 +
112380 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
112381 +{
112382 + if (!operand_equal_p(orig_node, node, 0))
112383 + return WRONG_NODE;
112384 + if (skip_types(node))
112385 + return WRONG_NODE;
112386 + return ret_count;
112387 +}
112388 +
112389 +// Get the index of the rhs node in an assignment
112390 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
112391 +{
112392 + const_tree rhs1, rhs2;
112393 + unsigned int ret;
112394 +
112395 + gcc_assert(stmt);
112396 + gcc_assert(is_gimple_assign(stmt));
112397 +
112398 + rhs1 = gimple_assign_rhs1(stmt);
112399 + gcc_assert(rhs1 != NULL_TREE);
112400 +
112401 + switch (gimple_num_ops(stmt)) {
112402 + case 2:
112403 + return check_ops(node, rhs1, 1);
112404 + case 3:
112405 + ret = check_ops(node, rhs1, 1);
112406 + if (ret != WRONG_NODE)
112407 + return ret;
112408 +
112409 + rhs2 = gimple_assign_rhs2(stmt);
112410 + gcc_assert(rhs2 != NULL_TREE);
112411 + return check_ops(node, rhs2, 2);
112412 + default:
112413 + gcc_unreachable();
112414 + }
112415 +}
112416 +
112417 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
112418 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
112419 +{
112420 + unsigned int i;
112421 +
112422 + if (gimple_call_fndecl(stmt) == NULL_TREE)
112423 + return CANNOT_FIND_ARG;
112424 +
112425 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
112426 + tree node;
112427 +
112428 + node = gimple_call_arg(stmt, i);
112429 + if (!operand_equal_p(arg, node, 0))
112430 + continue;
112431 + if (!skip_types(node))
112432 + return i + 1;
112433 + }
112434 +
112435 + return CANNOT_FIND_ARG;
112436 +}
112437 +
112438 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
112439 + * any of return, call or assignment stmts (because of inlining).
112440 + */
112441 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
112442 +{
112443 + use_operand_p use_p;
112444 + imm_use_iterator imm_iter;
112445 + unsigned int argnum;
112446 +
112447 + gcc_assert(TREE_CODE(node) == SSA_NAME);
112448 +
112449 + if (pointer_set_insert(visited, node))
112450 + return head;
112451 +
112452 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
112453 + gimple stmt = USE_STMT(use_p);
112454 +
112455 + if (stmt == NULL)
112456 + return head;
112457 + if (is_gimple_debug(stmt))
112458 + continue;
112459 +
112460 + switch (gimple_code(stmt)) {
112461 + case GIMPLE_CALL:
112462 + argnum = find_arg_number_gimple(node, stmt);
112463 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
112464 + break;
112465 + case GIMPLE_RETURN:
112466 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
112467 + break;
112468 + case GIMPLE_ASSIGN:
112469 + argnum = get_assign_ops_count(stmt, node);
112470 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
112471 + break;
112472 + case GIMPLE_PHI: {
112473 + tree result = gimple_phi_result(stmt);
112474 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
112475 + break;
112476 + }
112477 + case GIMPLE_ASM:
112478 + if (gimple_asm_noutputs(stmt) != 0)
112479 + break;
112480 + if (!is_size_overflow_asm(stmt))
112481 + break;
112482 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
112483 + break;
112484 + case GIMPLE_COND:
112485 + case GIMPLE_SWITCH:
112486 + break;
112487 + default:
112488 + debug_gimple_stmt(stmt);
112489 + gcc_unreachable();
112490 + break;
112491 + }
112492 + }
112493 + return head;
112494 +}
112495 +
112496 +static void remove_size_overflow_asm(gimple stmt)
112497 +{
112498 + gimple_stmt_iterator gsi;
112499 + tree input, output;
112500 +
112501 + if (!is_size_overflow_asm(stmt))
112502 + return;
112503 +
112504 + if (gimple_asm_noutputs(stmt) == 0) {
112505 + gsi = gsi_for_stmt(stmt);
112506 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
112507 + gsi_remove(&gsi, true);
112508 + return;
112509 + }
112510 +
112511 + input = gimple_asm_input_op(stmt, 0);
112512 + output = gimple_asm_output_op(stmt, 0);
112513 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
112514 +}
112515 +
112516 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
112517 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
112518 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
112519 + */
112520 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
112521 +{
112522 + const_tree output;
112523 + struct pointer_set_t *visited;
112524 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
112525 +
112526 + if (!is_size_overflow_asm(stmt))
112527 + return head;
112528 +
112529 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
112530 + intentional_asm = stmt;
112531 +
112532 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
112533 +
112534 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
112535 + return head;
112536 +
112537 + if (gimple_asm_noutputs(stmt) == 0) {
112538 + const_tree input;
112539 +
112540 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
112541 + return head;
112542 +
112543 + input = gimple_asm_input_op(stmt, 0);
112544 + remove_size_overflow_asm(stmt);
112545 + if (is_gimple_constant(TREE_VALUE(input)))
112546 + return head;
112547 + visited = pointer_set_create();
112548 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
112549 + pointer_set_destroy(visited);
112550 + return head;
112551 + }
112552 +
112553 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
112554 + remove_size_overflow_asm(stmt);
112555 +
112556 + visited = pointer_set_create();
112557 + output = gimple_asm_output_op(stmt, 0);
112558 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
112559 + pointer_set_destroy(visited);
112560 + return head;
112561 +}
112562 +
112563 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
112564 + * or a call stmt or a return stmt and store them in the interesting_node list
112565 + */
112566 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
112567 +{
112568 + basic_block bb;
112569 + struct interesting_node *head = NULL;
112570 +
112571 + FOR_ALL_BB_FN(bb, cfun) {
112572 + gimple_stmt_iterator gsi;
112573 +
112574 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
112575 + enum gimple_code code;
112576 + gimple stmt = gsi_stmt(gsi);
112577 +
112578 + code = gimple_code(stmt);
112579 +
112580 + if (code == GIMPLE_ASM)
112581 + head = handle_stmt_by_size_overflow_asm(stmt, head);
112582 +
112583 + if (!next_node)
112584 + continue;
112585 + if (code == GIMPLE_CALL)
112586 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
112587 + if (code == GIMPLE_RETURN)
112588 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
112589 + }
112590 + }
112591 + return head;
112592 +}
112593 +
112594 +static void free_interesting_node(struct interesting_node *head)
112595 +{
112596 + struct interesting_node *cur;
112597 +
112598 + while (head) {
112599 + cur = head->next;
112600 +#if BUILDING_GCC_VERSION <= 4007
112601 + VEC_free(tree, gc, head->last_nodes);
112602 +#else
112603 + vec_free(head->last_nodes);
112604 +#endif
112605 + free(head);
112606 + head = cur;
112607 + }
112608 +}
112609 +
112610 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
112611 +{
112612 + struct visited_fns *new_visited_fns;
112613 +
112614 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
112615 + new_visited_fns->fndecl = cur_node->fndecl;
112616 + new_visited_fns->num = cur_node->num;
112617 + new_visited_fns->first_stmt = cur_node->first_stmt;
112618 + new_visited_fns->next = NULL;
112619 +
112620 + if (!head)
112621 + return new_visited_fns;
112622 +
112623 + new_visited_fns->next = head;
112624 + return new_visited_fns;
112625 +}
112626 +
112627 +/* 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
112628 + * it is a visited_fns function.
112629 + */
112630 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
112631 +{
112632 + struct visited_fns *cur;
112633 +
112634 + if (!head)
112635 + return false;
112636 +
112637 + for (cur = head; cur; cur = cur->next) {
112638 + if (cur_node->first_stmt != cur->first_stmt)
112639 + continue;
112640 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
112641 + continue;
112642 + if (cur_node->num == cur->num)
112643 + return true;
112644 + }
112645 + return false;
112646 +}
112647 +
112648 +static void free_next_cgraph_node(struct next_cgraph_node *head)
112649 +{
112650 + struct next_cgraph_node *cur;
112651 +
112652 + while (head) {
112653 + cur = head->next;
112654 + free(head);
112655 + head = cur;
112656 + }
112657 +}
112658 +
112659 +static void remove_all_size_overflow_asm(void)
112660 +{
112661 + basic_block bb;
112662 +
112663 + FOR_ALL_BB_FN(bb, cfun) {
112664 + gimple_stmt_iterator si;
112665 +
112666 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
112667 + remove_size_overflow_asm(gsi_stmt(si));
112668 + }
112669 +}
112670 +
112671 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
112672 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
112673 + * the newly collected interesting functions (they are interesting if there is control flow between
112674 + * the interesting stmts and them).
112675 + */
112676 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
112677 +{
112678 + struct visited *visited;
112679 + struct interesting_node *head, *cur_node;
112680 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
112681 +
112682 + set_current_function_decl(NODE_DECL(node));
112683 + call_count = 0;
112684 +
112685 + head = collect_interesting_stmts(next_node);
112686 +
112687 + visited = create_visited();
112688 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
112689 + if (is_visited_fns_function(visited_fns, cur_node))
112690 + continue;
112691 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
112692 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
112693 + }
112694 +
112695 + free_visited(visited);
112696 + free_interesting_node(head);
112697 + remove_all_size_overflow_asm();
112698 + unset_current_function_decl();
112699 +
112700 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
112701 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
112702 +
112703 + free_next_cgraph_node(cnodes_head);
112704 + return visited_fns;
112705 +}
112706 +
112707 +static void free_visited_fns(struct visited_fns *head)
112708 +{
112709 + struct visited_fns *cur;
112710 +
112711 + while (head) {
112712 + cur = head->next;
112713 + free(head);
112714 + head = cur;
112715 + }
112716 +}
112717 +
112718 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
112719 +unsigned int search_function(void)
112720 +{
112721 + struct cgraph_node *node;
112722 + struct visited_fns *visited_fns = NULL;
112723 +
112724 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
112725 + gcc_assert(cgraph_function_flags_ready);
112726 +#if BUILDING_GCC_VERSION <= 4007
112727 + gcc_assert(node->reachable);
112728 +#endif
112729 +
112730 + visited_fns = handle_function(node, NULL, visited_fns);
112731 + }
112732 +
112733 + free_visited_fns(visited_fns);
112734 + return 0;
112735 +}
112736 +
112737 +#if BUILDING_GCC_VERSION >= 4009
112738 +static const struct pass_data insert_size_overflow_check_data = {
112739 +#else
112740 +static struct ipa_opt_pass_d insert_size_overflow_check = {
112741 + .pass = {
112742 +#endif
112743 + .type = SIMPLE_IPA_PASS,
112744 + .name = "size_overflow",
112745 +#if BUILDING_GCC_VERSION >= 4008
112746 + .optinfo_flags = OPTGROUP_NONE,
112747 +#endif
112748 +#if BUILDING_GCC_VERSION >= 4009
112749 + .has_gate = false,
112750 + .has_execute = true,
112751 +#else
112752 + .gate = NULL,
112753 + .execute = search_function,
112754 + .sub = NULL,
112755 + .next = NULL,
112756 + .static_pass_number = 0,
112757 +#endif
112758 + .tv_id = TV_NONE,
112759 + .properties_required = 0,
112760 + .properties_provided = 0,
112761 + .properties_destroyed = 0,
112762 + .todo_flags_start = 0,
112763 + .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,
112764 +#if BUILDING_GCC_VERSION < 4009
112765 + },
112766 + .generate_summary = NULL,
112767 + .write_summary = NULL,
112768 + .read_summary = NULL,
112769 +#if BUILDING_GCC_VERSION >= 4006
112770 + .write_optimization_summary = NULL,
112771 + .read_optimization_summary = NULL,
112772 +#endif
112773 + .stmt_fixup = NULL,
112774 + .function_transform_todo_flags_start = 0,
112775 + .function_transform = NULL,
112776 + .variable_transform = NULL,
112777 +#endif
112778 +};
112779 +
112780 +#if BUILDING_GCC_VERSION >= 4009
112781 +namespace {
112782 +class insert_size_overflow_check : public ipa_opt_pass_d {
112783 +public:
112784 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
112785 + unsigned int execute() { return search_function(); }
112786 +};
112787 +}
112788 +#endif
112789 +
112790 +struct opt_pass *make_insert_size_overflow_check(void)
112791 +{
112792 +#if BUILDING_GCC_VERSION >= 4009
112793 + return new insert_size_overflow_check();
112794 +#else
112795 + return &insert_size_overflow_check.pass;
112796 +#endif
112797 +}
112798 +
112799 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
112800 new file mode 100644
112801 index 0000000..38904bc
112802 --- /dev/null
112803 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
112804 @@ -0,0 +1,733 @@
112805 +/*
112806 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
112807 + * Licensed under the GPL v2, or (at your option) v3
112808 + *
112809 + * Homepage:
112810 + * http://www.grsecurity.net/~ephox/overflow_plugin/
112811 + *
112812 + * Documentation:
112813 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
112814 + *
112815 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
112816 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
112817 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
112818 + *
112819 + * Usage:
112820 + * $ make
112821 + * $ make run
112822 + */
112823 +
112824 +#include "gcc-common.h"
112825 +#include "size_overflow.h"
112826 +
112827 +/* Get the param of the intentional_overflow attribute.
112828 + * * 0: MARK_NOT_INTENTIONAL
112829 + * * 1..MAX_PARAM: MARK_YES
112830 + * * -1: MARK_TURN_OFF
112831 + */
112832 +static tree get_attribute_param(const_tree decl)
112833 +{
112834 + const_tree attr;
112835 +
112836 + if (decl == NULL_TREE)
112837 + return NULL_TREE;
112838 +
112839 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
112840 + if (!attr || !TREE_VALUE(attr))
112841 + return NULL_TREE;
112842 +
112843 + return TREE_VALUE(attr);
112844 +}
112845 +
112846 +// MARK_TURN_OFF
112847 +bool is_turn_off_intentional_attr(const_tree decl)
112848 +{
112849 + const_tree param_head;
112850 +
112851 + param_head = get_attribute_param(decl);
112852 + if (param_head == NULL_TREE)
112853 + return false;
112854 +
112855 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
112856 + return true;
112857 + return false;
112858 +}
112859 +
112860 +// MARK_NOT_INTENTIONAL
112861 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
112862 +{
112863 + const_tree param_head;
112864 +
112865 + if (argnum == 0)
112866 + return false;
112867 +
112868 + param_head = get_attribute_param(decl);
112869 + if (param_head == NULL_TREE)
112870 + return false;
112871 +
112872 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
112873 + return true;
112874 + return false;
112875 +}
112876 +
112877 +// MARK_YES
112878 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
112879 +{
112880 + tree param, param_head;
112881 +
112882 + if (argnum == 0)
112883 + return false;
112884 +
112885 + param_head = get_attribute_param(decl);
112886 + for (param = param_head; param; param = TREE_CHAIN(param))
112887 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
112888 + return true;
112889 + return false;
112890 +}
112891 +
112892 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
112893 +{
112894 + location_t loc;
112895 +
112896 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
112897 + return;
112898 +
112899 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
112900 + return;
112901 +
112902 + loc = DECL_SOURCE_LOCATION(decl);
112903 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
112904 +}
112905 +
112906 +// Get the field decl of a component ref for intentional_overflow checking
112907 +static const_tree search_field_decl(const_tree comp_ref)
112908 +{
112909 + const_tree field = NULL_TREE;
112910 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
112911 +
112912 + for (i = 0; i < len; i++) {
112913 + field = TREE_OPERAND(comp_ref, i);
112914 + if (TREE_CODE(field) == FIELD_DECL)
112915 + break;
112916 + }
112917 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
112918 + return field;
112919 +}
112920 +
112921 +/* Get the type of the intentional_overflow attribute of a node
112922 + * * MARK_TURN_OFF
112923 + * * MARK_YES
112924 + * * MARK_NO
112925 + * * MARK_NOT_INTENTIONAL
112926 + */
112927 +enum mark get_intentional_attr_type(const_tree node)
112928 +{
112929 + const_tree cur_decl;
112930 +
112931 + if (node == NULL_TREE)
112932 + return MARK_NO;
112933 +
112934 + switch (TREE_CODE(node)) {
112935 + case COMPONENT_REF:
112936 + cur_decl = search_field_decl(node);
112937 + if (is_turn_off_intentional_attr(cur_decl))
112938 + return MARK_TURN_OFF;
112939 + if (is_end_intentional_intentional_attr(cur_decl, 1))
112940 + return MARK_YES;
112941 + break;
112942 + case PARM_DECL: {
112943 + unsigned int argnum;
112944 +
112945 + cur_decl = DECL_ORIGIN(current_function_decl);
112946 + argnum = find_arg_number_tree(node, cur_decl);
112947 + if (argnum == CANNOT_FIND_ARG)
112948 + return MARK_NO;
112949 + if (is_yes_intentional_attr(cur_decl, argnum))
112950 + return MARK_YES;
112951 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
112952 + return MARK_NOT_INTENTIONAL;
112953 + break;
112954 + }
112955 + case FUNCTION_DECL:
112956 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
112957 + return MARK_TURN_OFF;
112958 + break;
112959 + default:
112960 + break;
112961 + }
112962 + return MARK_NO;
112963 +}
112964 +
112965 +// Search for the intentional_overflow attribute on the last nodes
112966 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
112967 +{
112968 + unsigned int i;
112969 + tree last_node;
112970 + enum mark mark = MARK_NO;
112971 +
112972 +#if BUILDING_GCC_VERSION <= 4007
112973 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
112974 +#else
112975 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
112976 +#endif
112977 + mark = get_intentional_attr_type(last_node);
112978 + if (mark != MARK_NO)
112979 + break;
112980 + }
112981 + return mark;
112982 +}
112983 +
112984 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
112985 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
112986 + */
112987 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
112988 +{
112989 + if (!cur_node->intentional_mark_from_gimple)
112990 + return false;
112991 +
112992 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
112993 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
112994 + else
112995 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
112996 +
112997 + // skip param decls
112998 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
112999 + return true;
113000 + return true;
113001 +}
113002 +
113003 +/* Search intentional_overflow attribute on caller and on callee too.
113004 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
113005 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
113006 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
113007 +*/
113008 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
113009 +{
113010 + const_tree fndecl;
113011 +
113012 + if (is_intentional_attribute_from_gimple(cur_node))
113013 + return;
113014 +
113015 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
113016 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
113017 + return;
113018 + }
113019 +
113020 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
113021 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
113022 + return;
113023 + }
113024 +
113025 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
113026 + return;
113027 +
113028 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
113029 + if (is_turn_off_intentional_attr(fndecl)) {
113030 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
113031 + return;
113032 + }
113033 +
113034 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
113035 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
113036 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
113037 + cur_node->intentional_attr_decl = MARK_YES;
113038 +
113039 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
113040 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
113041 +}
113042 +
113043 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
113044 +{
113045 + const_tree rhs1, lhs, rhs1_type, lhs_type;
113046 + enum machine_mode lhs_mode, rhs_mode;
113047 + gimple def_stmt = get_def_stmt(no_const_rhs);
113048 +
113049 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113050 + return false;
113051 +
113052 + rhs1 = gimple_assign_rhs1(def_stmt);
113053 + lhs = gimple_assign_lhs(def_stmt);
113054 + rhs1_type = TREE_TYPE(rhs1);
113055 + lhs_type = TREE_TYPE(lhs);
113056 + rhs_mode = TYPE_MODE(rhs1_type);
113057 + lhs_mode = TYPE_MODE(lhs_type);
113058 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
113059 + return false;
113060 +
113061 + return true;
113062 +}
113063 +
113064 +static unsigned int uses_num(tree node)
113065 +{
113066 + imm_use_iterator imm_iter;
113067 + use_operand_p use_p;
113068 + unsigned int num = 0;
113069 +
113070 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113071 + gimple use_stmt = USE_STMT(use_p);
113072 +
113073 + if (use_stmt == NULL)
113074 + return num;
113075 + if (is_gimple_debug(use_stmt))
113076 + continue;
113077 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
113078 + continue;
113079 + num++;
113080 + }
113081 + return num;
113082 +}
113083 +
113084 +static bool no_uses(tree node)
113085 +{
113086 + return !uses_num(node);
113087 +}
113088 +
113089 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
113090 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
113091 +{
113092 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
113093 + gimple def_stmt = get_def_stmt(lhs);
113094 +
113095 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113096 + return false;
113097 +
113098 + rhs1 = gimple_assign_rhs1(def_stmt);
113099 + rhs_type = TREE_TYPE(rhs1);
113100 + lhs_type = TREE_TYPE(lhs);
113101 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
113102 + return false;
113103 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
113104 + return false;
113105 +
113106 + def_stmt = get_def_stmt(rhs1);
113107 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
113108 + return false;
113109 +
113110 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
113111 + return false;
113112 +
113113 + rhs1 = gimple_assign_rhs1(def_stmt);
113114 + rhs2 = gimple_assign_rhs2(def_stmt);
113115 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
113116 + return false;
113117 +
113118 + if (is_gimple_constant(rhs2))
113119 + not_const_rhs = rhs1;
113120 + else
113121 + not_const_rhs = rhs2;
113122 +
113123 + return no_uses(not_const_rhs);
113124 +}
113125 +
113126 +static bool is_lt_signed_type_max(const_tree rhs)
113127 +{
113128 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
113129 +
113130 + if (!TYPE_UNSIGNED(type))
113131 + return true;
113132 +
113133 + switch (TYPE_MODE(type)) {
113134 + case QImode:
113135 + new_type = intQI_type_node;
113136 + break;
113137 + case HImode:
113138 + new_type = intHI_type_node;
113139 + break;
113140 + case SImode:
113141 + new_type = intSI_type_node;
113142 + break;
113143 + case DImode:
113144 + new_type = intDI_type_node;
113145 + break;
113146 + default:
113147 + debug_tree((tree)type);
113148 + gcc_unreachable();
113149 + }
113150 +
113151 + type_max = TYPE_MAX_VALUE(new_type);
113152 + if (!tree_int_cst_lt(type_max, rhs))
113153 + return true;
113154 +
113155 + return false;
113156 +}
113157 +
113158 +static bool is_gt_zero(const_tree rhs)
113159 +{
113160 + const_tree type = TREE_TYPE(rhs);
113161 +
113162 + if (TYPE_UNSIGNED(type))
113163 + return true;
113164 +
113165 + if (!tree_int_cst_lt(rhs, integer_zero_node))
113166 + return true;
113167 +
113168 + return false;
113169 +}
113170 +
113171 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
113172 +{
113173 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
113174 + return false;
113175 + if (!is_gimple_constant(rhs))
113176 + return false;
113177 +
113178 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
113179 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
113180 + return false;
113181 +
113182 + return true;
113183 +}
113184 +
113185 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
113186 +{
113187 + gimple assign;
113188 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113189 + tree origtype = TREE_TYPE(orig_rhs);
113190 +
113191 + gcc_assert(is_gimple_assign(stmt));
113192 +
113193 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113194 + pointer_set_insert(visited->my_stmts, assign);
113195 + return gimple_assign_lhs(assign);
113196 +}
113197 +
113198 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
113199 +{
113200 + tree new_rhs, orig_rhs;
113201 + void (*gimple_assign_set_rhs)(gimple, tree);
113202 + tree rhs1 = gimple_assign_rhs1(stmt);
113203 + tree rhs2 = gimple_assign_rhs2(stmt);
113204 + tree lhs = gimple_assign_lhs(stmt);
113205 +
113206 + if (!check_overflow)
113207 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113208 +
113209 + if (change_rhs == NULL_TREE)
113210 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113211 +
113212 + if (new_rhs2 == NULL_TREE) {
113213 + orig_rhs = rhs1;
113214 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
113215 + } else {
113216 + orig_rhs = rhs2;
113217 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
113218 + }
113219 +
113220 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
113221 +
113222 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
113223 + gimple_assign_set_rhs(stmt, new_rhs);
113224 + update_stmt(stmt);
113225 +
113226 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113227 +}
113228 +
113229 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
113230 +{
113231 + gimple rhs1_def_stmt, rhs2_def_stmt;
113232 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
113233 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
113234 + const_tree rhs1 = gimple_assign_rhs1(stmt);
113235 + const_tree rhs2 = gimple_assign_rhs2(stmt);
113236 +
113237 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
113238 + return false;
113239 +
113240 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
113241 +
113242 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
113243 + return false;
113244 +
113245 + rhs1_def_stmt = get_def_stmt(rhs1);
113246 + rhs2_def_stmt = get_def_stmt(rhs2);
113247 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
113248 + return false;
113249 +
113250 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
113251 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
113252 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
113253 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
113254 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
113255 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
113256 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
113257 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
113258 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
113259 + return false;
113260 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
113261 + return false;
113262 +
113263 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
113264 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
113265 + return true;
113266 +}
113267 +
113268 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
113269 +{
113270 + gimple assign;
113271 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113272 + tree type = TREE_TYPE(rhs1);
113273 + tree lhs = create_new_var(type);
113274 +
113275 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
113276 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
113277 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113278 +
113279 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113280 + update_stmt(assign);
113281 + pointer_set_insert(visited->my_stmts, assign);
113282 + return assign;
113283 +}
113284 +
113285 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
113286 +{
113287 + gimple_stmt_iterator gsi;
113288 + gimple cast_stmt;
113289 + tree type = TREE_TYPE(node);
113290 +
113291 + if (types_compatible_p(type, intTI_type_node))
113292 + return node;
113293 +
113294 + gsi = gsi_for_stmt(stmt);
113295 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113296 + pointer_set_insert(visited->my_stmts, cast_stmt);
113297 + return gimple_assign_lhs(cast_stmt);
113298 +}
113299 +
113300 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
113301 +{
113302 + tree rhs1, def_stmt_rhs1;
113303 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
113304 +
113305 + def_stmt = get_def_stmt(var);
113306 + if (!gimple_assign_cast_p(def_stmt))
113307 + return NULL_TREE;
113308 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
113309 +
113310 + rhs1 = gimple_assign_rhs1(def_stmt);
113311 + rhs1_def_stmt = get_def_stmt(rhs1);
113312 + if (!gimple_assign_cast_p(rhs1_def_stmt))
113313 + return rhs1;
113314 +
113315 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
113316 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
113317 +
113318 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
113319 + case GIMPLE_CALL:
113320 + case GIMPLE_NOP:
113321 + case GIMPLE_ASM:
113322 + case GIMPLE_PHI:
113323 + return def_stmt_rhs1;
113324 + case GIMPLE_ASSIGN:
113325 + return rhs1;
113326 + default:
113327 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
113328 + gcc_unreachable();
113329 + }
113330 +}
113331 +
113332 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
113333 +{
113334 + tree new_rhs1, new_rhs2;
113335 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
113336 + gimple assign, stmt = get_def_stmt(lhs);
113337 + tree rhs1 = gimple_assign_rhs1(stmt);
113338 + tree rhs2 = gimple_assign_rhs2(stmt);
113339 +
113340 + if (!is_subtraction_special(visited, stmt))
113341 + return NULL_TREE;
113342 +
113343 + new_rhs1 = expand(visited, caller_node, rhs1);
113344 + new_rhs2 = expand(visited, caller_node, rhs2);
113345 +
113346 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
113347 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
113348 +
113349 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
113350 + return NULL_TREE;
113351 +
113352 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
113353 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
113354 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
113355 + }
113356 +
113357 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
113358 + new_lhs = gimple_assign_lhs(assign);
113359 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
113360 +
113361 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
113362 +}
113363 +
113364 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
113365 +{
113366 + const_gimple def_stmt;
113367 +
113368 + if (TREE_CODE(rhs) != SSA_NAME)
113369 + return false;
113370 +
113371 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
113372 + return false;
113373 +
113374 + def_stmt = get_def_stmt(rhs);
113375 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
113376 + return false;
113377 +
113378 + return true;
113379 +}
113380 +
113381 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
113382 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
113383 + * fffffff * 16 > signed max -> truncate
113384 + */
113385 +static bool look_for_mult_and_add(const_gimple stmt)
113386 +{
113387 + const_tree res;
113388 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
113389 + const_gimple def_stmt;
113390 +
113391 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
113392 + return false;
113393 + if (!is_gimple_assign(stmt))
113394 + return false;
113395 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
113396 + return false;
113397 +
113398 + rhs1 = gimple_assign_rhs1(stmt);
113399 + rhs2 = gimple_assign_rhs2(stmt);
113400 + if (is_gimple_constant(rhs1)) {
113401 + const_rhs = rhs1;
113402 + def_stmt = get_def_stmt(rhs2);
113403 + } else if (is_gimple_constant(rhs2)) {
113404 + const_rhs = rhs2;
113405 + def_stmt = get_def_stmt(rhs1);
113406 + } else
113407 + return false;
113408 +
113409 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
113410 + return false;
113411 +
113412 + def_rhs1 = gimple_assign_rhs1(def_stmt);
113413 + def_rhs2 = gimple_assign_rhs2(def_stmt);
113414 + if (is_gimple_constant(def_rhs1))
113415 + def_const_rhs = def_rhs1;
113416 + else if (is_gimple_constant(def_rhs2))
113417 + def_const_rhs = def_rhs2;
113418 + else
113419 + return false;
113420 +
113421 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
113422 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
113423 + return false;
113424 + return true;
113425 +}
113426 +
113427 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
113428 +{
113429 + const_gimple def_stmt_1, def_stmt_2;
113430 + const_tree rhs1, rhs2;
113431 + bool add_mul_rhs1, add_mul_rhs2;
113432 +
113433 + rhs1 = gimple_assign_rhs1(stmt);
113434 + def_stmt_1 = get_def_stmt(rhs1);
113435 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
113436 +
113437 + rhs2 = gimple_assign_rhs2(stmt);
113438 + def_stmt_2 = get_def_stmt(rhs2);
113439 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
113440 +
113441 + if (add_mul_rhs1)
113442 + return RHS1_INTENTIONAL_OVERFLOW;
113443 + if (add_mul_rhs2)
113444 + return RHS2_INTENTIONAL_OVERFLOW;
113445 + return NO_INTENTIONAL_OVERFLOW;
113446 +}
113447 +
113448 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
113449 +{
113450 + gimple my_stmt;
113451 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113452 +
113453 + gsi_next(&gsi);
113454 + my_stmt = gsi_stmt(gsi);
113455 +
113456 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
113457 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
113458 +
113459 + return my_stmt;
113460 +}
113461 +
113462 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
113463 + * unsigned type cast to signed type, unsigned type: no more uses
113464 + * e.g., lib/vsprintf.c:simple_strtol()
113465 + * _10 = (unsigned long int) _9
113466 + * _11 = -_10;
113467 + * _12 = (long int) _11; (_11_ no more uses)
113468 + */
113469 +static bool is_call_or_cast(gimple stmt)
113470 +{
113471 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
113472 +}
113473 +
113474 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
113475 +{
113476 + const_tree rhs;
113477 + gimple def_stmt;
113478 +
113479 + if (node == NULL_TREE)
113480 + return true;
113481 + if (is_gimple_constant(node))
113482 + return true;
113483 +
113484 + def_stmt = get_def_stmt(node);
113485 + if (!def_stmt)
113486 + return false;
113487 +
113488 + if (is_call_or_cast(def_stmt))
113489 + return true;
113490 +
113491 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
113492 + return false;
113493 + rhs = gimple_assign_rhs1(def_stmt);
113494 + def_stmt = get_def_stmt(rhs);
113495 + if (!def_stmt)
113496 + return false;
113497 + return is_call_or_cast(def_stmt);
113498 +}
113499 +
113500 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
113501 +{
113502 + unsigned int use_num;
113503 + gimple so_stmt;
113504 + const_gimple def_stmt;
113505 + const_tree rhs1, rhs2;
113506 + tree rhs = gimple_assign_rhs1(stmt);
113507 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
113508 + const_tree rhs_type = TREE_TYPE(rhs);
113509 +
113510 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
113511 + return;
113512 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
113513 + return;
113514 + use_num = uses_num(rhs);
113515 + if (use_num != 1)
113516 + return;
113517 +
113518 + def_stmt = get_def_stmt(rhs);
113519 + if (!def_stmt)
113520 + return;
113521 + if (!is_gimple_assign(def_stmt))
113522 + return;
113523 +
113524 + rhs1 = gimple_assign_rhs1(def_stmt);
113525 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
113526 + return;
113527 +
113528 + rhs2 = gimple_assign_rhs2(def_stmt);
113529 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
113530 + return;
113531 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
113532 + return;
113533 +
113534 + so_stmt = get_dup_stmt(visited, stmt);
113535 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
113536 +}
113537 +
113538 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
113539 new file mode 100644
113540 index 0000000..4bddad2
113541 --- /dev/null
113542 +++ b/tools/gcc/size_overflow_plugin/misc.c
113543 @@ -0,0 +1,203 @@
113544 +/*
113545 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113546 + * Licensed under the GPL v2, or (at your option) v3
113547 + *
113548 + * Homepage:
113549 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113550 + *
113551 + * Documentation:
113552 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113553 + *
113554 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113555 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113556 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113557 + *
113558 + * Usage:
113559 + * $ make
113560 + * $ make run
113561 + */
113562 +
113563 +#include "gcc-common.h"
113564 +#include "size_overflow.h"
113565 +
113566 +void set_current_function_decl(tree fndecl)
113567 +{
113568 + gcc_assert(fndecl != NULL_TREE);
113569 +
113570 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
113571 + calculate_dominance_info(CDI_DOMINATORS);
113572 + current_function_decl = fndecl;
113573 +}
113574 +
113575 +void unset_current_function_decl(void)
113576 +{
113577 + free_dominance_info(CDI_DOMINATORS);
113578 + pop_cfun();
113579 + current_function_decl = NULL_TREE;
113580 +}
113581 +
113582 +static bool is_bool(const_tree node)
113583 +{
113584 + const_tree type;
113585 +
113586 + if (node == NULL_TREE)
113587 + return false;
113588 +
113589 + type = TREE_TYPE(node);
113590 + if (!INTEGRAL_TYPE_P(type))
113591 + return false;
113592 + if (TREE_CODE(type) == BOOLEAN_TYPE)
113593 + return true;
113594 + if (TYPE_PRECISION(type) == 1)
113595 + return true;
113596 + return false;
113597 +}
113598 +
113599 +bool skip_types(const_tree var)
113600 +{
113601 + tree type;
113602 + enum tree_code code;
113603 +
113604 + if (is_gimple_constant(var))
113605 + return true;
113606 +
113607 + switch (TREE_CODE(var)) {
113608 + case ADDR_EXPR:
113609 +#if BUILDING_GCC_VERSION >= 4006
113610 + case MEM_REF:
113611 +#endif
113612 + case ARRAY_REF:
113613 + case BIT_FIELD_REF:
113614 + case INDIRECT_REF:
113615 + case TARGET_MEM_REF:
113616 + case COMPONENT_REF:
113617 + case VAR_DECL:
113618 + case VIEW_CONVERT_EXPR:
113619 + return true;
113620 + default:
113621 + break;
113622 + }
113623 +
113624 + code = TREE_CODE(var);
113625 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
113626 +
113627 + type = TREE_TYPE(var);
113628 + switch (TREE_CODE(type)) {
113629 + case INTEGER_TYPE:
113630 + case ENUMERAL_TYPE:
113631 + return false;
113632 + case BOOLEAN_TYPE:
113633 + return is_bool(var);
113634 + default:
113635 + return true;
113636 + }
113637 +}
113638 +
113639 +gimple get_def_stmt(const_tree node)
113640 +{
113641 + gcc_assert(node != NULL_TREE);
113642 +
113643 + if (skip_types(node))
113644 + return NULL;
113645 +
113646 + if (TREE_CODE(node) != SSA_NAME)
113647 + return NULL;
113648 + return SSA_NAME_DEF_STMT(node);
113649 +}
113650 +
113651 +tree create_new_var(tree type)
113652 +{
113653 + tree new_var = create_tmp_var(type, "cicus");
113654 +
113655 + add_referenced_var(new_var);
113656 + return new_var;
113657 +}
113658 +
113659 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
113660 +{
113661 + const_gimple def_stmt = get_def_stmt(rhs);
113662 +
113663 + if (force)
113664 + return false;
113665 +
113666 + if (is_gimple_constant(rhs))
113667 + return false;
113668 +
113669 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
113670 + return false;
113671 +
113672 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
113673 + return false;
113674 +
113675 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
113676 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
113677 + return false;
113678 +
113679 + return true;
113680 +}
113681 +
113682 +tree cast_a_tree(tree type, tree var)
113683 +{
113684 + gcc_assert(type != NULL_TREE);
113685 + gcc_assert(var != NULL_TREE);
113686 + gcc_assert(fold_convertible_p(type, var));
113687 +
113688 + return fold_convert(type, var);
113689 +}
113690 +
113691 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
113692 +{
113693 + gimple assign, def_stmt;
113694 +
113695 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
113696 + gcc_assert(!is_gimple_constant(rhs));
113697 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
113698 + gcc_unreachable();
113699 +
113700 + def_stmt = get_def_stmt(rhs);
113701 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
113702 + return def_stmt;
113703 +
113704 + if (lhs == CREATE_NEW_VAR)
113705 + lhs = create_new_var(dst_type);
113706 +
113707 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
113708 +
113709 + if (!gsi_end_p(*gsi)) {
113710 + location_t loc = gimple_location(gsi_stmt(*gsi));
113711 + gimple_set_location(assign, loc);
113712 + }
113713 +
113714 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113715 +
113716 + if (before)
113717 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
113718 + else
113719 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
113720 + update_stmt(assign);
113721 + return assign;
113722 +}
113723 +
113724 +bool is_size_overflow_type(const_tree var)
113725 +{
113726 + const char *name;
113727 + const_tree type_name, type;
113728 +
113729 + if (var == NULL_TREE)
113730 + return false;
113731 +
113732 + type = TREE_TYPE(var);
113733 + type_name = TYPE_NAME(type);
113734 + if (type_name == NULL_TREE)
113735 + return false;
113736 +
113737 + if (DECL_P(type_name))
113738 + name = DECL_NAME_POINTER(type_name);
113739 + else
113740 + name = IDENTIFIER_POINTER(type_name);
113741 +
113742 + if (!strncmp(name, "size_overflow_type", 18))
113743 + return true;
113744 + return false;
113745 +}
113746 +
113747 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
113748 new file mode 100644
113749 index 0000000..7c9e6d1
113750 --- /dev/null
113751 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
113752 @@ -0,0 +1,138 @@
113753 +/*
113754 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113755 + * Licensed under the GPL v2, or (at your option) v3
113756 + *
113757 + * Homepage:
113758 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113759 + *
113760 + * Documentation:
113761 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113762 + *
113763 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113764 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113765 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113766 + *
113767 + * Usage:
113768 + * $ make
113769 + * $ make run
113770 + */
113771 +
113772 +#include "gcc-common.h"
113773 +#include "size_overflow.h"
113774 +
113775 +bool skip_expr_on_double_type(const_gimple stmt)
113776 +{
113777 + enum tree_code code = gimple_assign_rhs_code(stmt);
113778 +
113779 + switch (code) {
113780 + case RSHIFT_EXPR:
113781 + case TRUNC_DIV_EXPR:
113782 + case CEIL_DIV_EXPR:
113783 + case FLOOR_DIV_EXPR:
113784 + case ROUND_DIV_EXPR:
113785 + case EXACT_DIV_EXPR:
113786 + case RDIV_EXPR:
113787 + case TRUNC_MOD_EXPR:
113788 + case CEIL_MOD_EXPR:
113789 + case FLOOR_MOD_EXPR:
113790 + case ROUND_MOD_EXPR:
113791 + return true;
113792 + default:
113793 + return false;
113794 + }
113795 +}
113796 +
113797 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
113798 +{
113799 + const_tree orig_rhs1;
113800 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
113801 + gimple down_cast, up_cast;
113802 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
113803 +
113804 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113805 + down_lhs = gimple_assign_lhs(down_cast);
113806 +
113807 + gsi = gsi_for_stmt(use_stmt);
113808 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113809 + new_lhs = gimple_assign_lhs(up_cast);
113810 +
113811 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
113812 + if (operand_equal_p(orig_rhs1, rhs, 0))
113813 + gimple_assign_set_rhs1(use_stmt, new_lhs);
113814 + else
113815 + gimple_assign_set_rhs2(use_stmt, new_lhs);
113816 + update_stmt(use_stmt);
113817 +
113818 + pointer_set_insert(visited->my_stmts, up_cast);
113819 + pointer_set_insert(visited->my_stmts, down_cast);
113820 + pointer_set_insert(visited->skip_expr_casts, up_cast);
113821 + pointer_set_insert(visited->skip_expr_casts, down_cast);
113822 +}
113823 +
113824 +static tree get_proper_unsigned_half_type(const_tree node)
113825 +{
113826 + tree new_type, type;
113827 +
113828 + gcc_assert(is_size_overflow_type(node));
113829 +
113830 + type = TREE_TYPE(node);
113831 + switch (TYPE_MODE(type)) {
113832 + case HImode:
113833 + new_type = unsigned_intQI_type_node;
113834 + break;
113835 + case SImode:
113836 + new_type = unsigned_intHI_type_node;
113837 + break;
113838 + case DImode:
113839 + new_type = unsigned_intSI_type_node;
113840 + break;
113841 + case TImode:
113842 + new_type = unsigned_intDI_type_node;
113843 + break;
113844 + default:
113845 + gcc_unreachable();
113846 + }
113847 +
113848 + if (TYPE_QUALS(type) != 0)
113849 + return build_qualified_type(new_type, TYPE_QUALS(type));
113850 + return new_type;
113851 +}
113852 +
113853 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
113854 +{
113855 + tree type;
113856 +
113857 + if (rhs == NULL_TREE)
113858 + return;
113859 + if (!is_size_overflow_type(rhs))
113860 + return;
113861 +
113862 + type = get_proper_unsigned_half_type(rhs);
113863 + if (is_gimple_constant(rhs))
113864 + return;
113865 + create_up_and_down_cast(visited, stmt, type, rhs);
113866 +}
113867 +
113868 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
113869 +{
113870 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
113871 + return;
113872 + gcc_assert(is_size_overflow_type(rhs));
113873 + insert_cast_rhs(visited, stmt, rhs);
113874 +}
113875 +
113876 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
113877 +{
113878 + tree rhs1, rhs2;
113879 +
113880 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
113881 + rhs1 = gimple_assign_rhs1(stmt);
113882 + insert_cast(visited, stmt, rhs1);
113883 + }
113884 +
113885 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
113886 + rhs2 = gimple_assign_rhs2(stmt);
113887 + insert_cast(visited, stmt, rhs2);
113888 + }
113889 +}
113890 +
113891 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
113892 new file mode 100644
113893 index 0000000..e5b4e50
113894 --- /dev/null
113895 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
113896 @@ -0,0 +1,127 @@
113897 +#ifndef SIZE_OVERFLOW_H
113898 +#define SIZE_OVERFLOW_H
113899 +
113900 +#define CREATE_NEW_VAR NULL_TREE
113901 +#define CANNOT_FIND_ARG 32
113902 +#define MAX_PARAM 31
113903 +#define BEFORE_STMT true
113904 +#define AFTER_STMT false
113905 +
113906 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
113907 +#define YES_ASM_STR "# size_overflow MARK_YES "
113908 +#define OK_ASM_STR "# size_overflow "
113909 +
113910 +enum mark {
113911 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
113912 +};
113913 +
113914 +enum intentional_overflow_type {
113915 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
113916 +};
113917 +
113918 +struct visited {
113919 + struct pointer_set_t *stmts;
113920 + struct pointer_set_t *my_stmts;
113921 + struct pointer_set_t *skip_expr_casts;
113922 + struct pointer_set_t *no_cast_check;
113923 +};
113924 +
113925 +// size_overflow_plugin.c
113926 +extern tree report_size_overflow_decl;
113927 +extern tree size_overflow_type_HI;
113928 +extern tree size_overflow_type_SI;
113929 +extern tree size_overflow_type_DI;
113930 +extern tree size_overflow_type_TI;
113931 +
113932 +
113933 +// size_overflow_plugin_hash.c
113934 +struct size_overflow_hash {
113935 + const struct size_overflow_hash * const next;
113936 + const char * const name;
113937 + const unsigned int param;
113938 +};
113939 +
113940 +struct interesting_node {
113941 + struct interesting_node *next;
113942 + gimple first_stmt;
113943 + const_tree fndecl;
113944 + tree node;
113945 +#if BUILDING_GCC_VERSION <= 4007
113946 + VEC(tree, gc) *last_nodes;
113947 +#else
113948 + vec<tree, va_gc> *last_nodes;
113949 +#endif
113950 + unsigned int num;
113951 + enum mark intentional_attr_decl;
113952 + enum mark intentional_attr_cur_fndecl;
113953 + gimple intentional_mark_from_gimple;
113954 +};
113955 +
113956 +extern bool is_size_overflow_asm(const_gimple stmt);
113957 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
113958 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
113959 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
113960 +extern bool is_a_return_check(const_tree node);
113961 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
113962 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
113963 +
113964 +
113965 +// size_overflow_debug.c
113966 +extern struct opt_pass *make_dump_pass(void);
113967 +
113968 +
113969 +// intentional_overflow.c
113970 +extern enum mark get_intentional_attr_type(const_tree node);
113971 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
113972 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
113973 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
113974 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
113975 +extern bool is_turn_off_intentional_attr(const_tree decl);
113976 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
113977 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
113978 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
113979 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
113980 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
113981 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
113982 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
113983 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
113984 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
113985 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
113986 +
113987 +
113988 +// insert_size_overflow_check_ipa.c
113989 +extern unsigned int search_function(void);
113990 +extern unsigned int call_count;
113991 +extern struct opt_pass *make_insert_size_overflow_check(void);
113992 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
113993 +
113994 +
113995 +// insert_size_overflow_asm.c
113996 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
113997 +
113998 +
113999 +// misc.c
114000 +extern void set_current_function_decl(tree fndecl);
114001 +extern void unset_current_function_decl(void);
114002 +extern gimple get_def_stmt(const_tree node);
114003 +extern tree create_new_var(tree type);
114004 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
114005 +extern bool skip_types(const_tree var);
114006 +extern tree cast_a_tree(tree type, tree var);
114007 +extern bool is_size_overflow_type(const_tree var);
114008 +
114009 +
114010 +// insert_size_overflow_check_core.c
114011 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
114012 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114013 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114014 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
114015 +
114016 +
114017 +// remove_unnecessary_dup.c
114018 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
114019 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
114020 +extern bool skip_expr_on_double_type(const_gimple stmt);
114021 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
114022 +
114023 +#endif
114024 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114025 new file mode 100644
114026 index 0000000..4378111
114027 --- /dev/null
114028 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114029 @@ -0,0 +1,116 @@
114030 +/*
114031 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114032 + * Licensed under the GPL v2, or (at your option) v3
114033 + *
114034 + * Homepage:
114035 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114036 + *
114037 + * Documentation:
114038 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114039 + *
114040 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114041 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114042 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114043 + *
114044 + * Usage:
114045 + * $ make
114046 + * $ make run
114047 + */
114048 +
114049 +#include "gcc-common.h"
114050 +
114051 +static unsigned int dump_functions(void)
114052 +{
114053 + struct cgraph_node *node;
114054 +
114055 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
114056 + basic_block bb;
114057 +
114058 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
114059 + current_function_decl = NODE_DECL(node);
114060 +
114061 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
114062 +
114063 + FOR_ALL_BB_FN(bb, cfun) {
114064 + gimple_stmt_iterator si;
114065 +
114066 + fprintf(stderr, "<bb %u>:\n", bb->index);
114067 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
114068 + debug_gimple_stmt(gsi_stmt(si));
114069 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
114070 + debug_gimple_stmt(gsi_stmt(si));
114071 + fprintf(stderr, "\n");
114072 + }
114073 +
114074 + fprintf(stderr, "-------------------------------------------------------------------------\n");
114075 +
114076 + pop_cfun();
114077 + current_function_decl = NULL_TREE;
114078 + }
114079 +
114080 + fprintf(stderr, "###############################################################################\n");
114081 +
114082 + return 0;
114083 +}
114084 +
114085 +#if BUILDING_GCC_VERSION >= 4009
114086 +static const struct pass_data dump_pass_data = {
114087 +#else
114088 +static struct ipa_opt_pass_d dump_pass = {
114089 + .pass = {
114090 +#endif
114091 + .type = SIMPLE_IPA_PASS,
114092 + .name = "dump",
114093 +#if BUILDING_GCC_VERSION >= 4008
114094 + .optinfo_flags = OPTGROUP_NONE,
114095 +#endif
114096 +#if BUILDING_GCC_VERSION >= 4009
114097 + .has_gate = false,
114098 + .has_execute = true,
114099 +#else
114100 + .gate = NULL,
114101 + .execute = dump_functions,
114102 + .sub = NULL,
114103 + .next = NULL,
114104 + .static_pass_number = 0,
114105 +#endif
114106 + .tv_id = TV_NONE,
114107 + .properties_required = 0,
114108 + .properties_provided = 0,
114109 + .properties_destroyed = 0,
114110 + .todo_flags_start = 0,
114111 + .todo_flags_finish = 0,
114112 +#if BUILDING_GCC_VERSION < 4009
114113 + },
114114 + .generate_summary = NULL,
114115 + .write_summary = NULL,
114116 + .read_summary = NULL,
114117 +#if BUILDING_GCC_VERSION >= 4006
114118 + .write_optimization_summary = NULL,
114119 + .read_optimization_summary = NULL,
114120 +#endif
114121 + .stmt_fixup = NULL,
114122 + .function_transform_todo_flags_start = 0,
114123 + .function_transform = NULL,
114124 + .variable_transform = NULL,
114125 +#endif
114126 +};
114127 +
114128 +#if BUILDING_GCC_VERSION >= 4009
114129 +namespace {
114130 +class dump_pass : public ipa_opt_pass_d {
114131 +public:
114132 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
114133 + unsigned int execute() { return dump_functions(); }
114134 +};
114135 +}
114136 +#endif
114137 +
114138 +struct opt_pass *make_dump_pass(void)
114139 +{
114140 +#if BUILDING_GCC_VERSION >= 4009
114141 + return new dump_pass();
114142 +#else
114143 + return &dump_pass.pass;
114144 +#endif
114145 +}
114146 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
114147 new file mode 100644
114148 index 0000000..72e9c0e
114149 --- /dev/null
114150 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
114151 @@ -0,0 +1,5986 @@
114152 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
114153 +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
114154 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
114155 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
114156 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
114157 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
114158 +padzero_55 padzero 1 55 &sel_read_policyvers_55
114159 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
114160 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
114161 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
114162 +load_msg_95 load_msg 2 95 NULL
114163 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
114164 +init_q_132 init_q 4 132 NULL
114165 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
114166 +gfs2_glock_get_147 gfs2_glock_get 0 147 NULL
114167 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
114168 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
114169 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
114170 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
114171 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
114172 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
114173 +xfs_bmap_btalloc_192 xfs_bmap_btalloc 0 192 NULL
114174 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
114175 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
114176 +br_port_info_size_268 br_port_info_size 0 268 NULL
114177 +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
114178 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
114179 +xfs_zero_last_block_298 xfs_zero_last_block 0 298 NULL
114180 +SYSC_connect_304 SYSC_connect 3 304 NULL
114181 +syslog_print_307 syslog_print 2 307 NULL
114182 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
114183 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
114184 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
114185 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
114186 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
114187 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
114188 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
114189 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
114190 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
114191 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
114192 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
114193 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
114194 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
114195 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
114196 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
114197 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
114198 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
114199 +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
114200 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
114201 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
114202 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
114203 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
114204 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
114205 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
114206 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
114207 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
114208 +unlink_queued_645 unlink_queued 4 645 NULL
114209 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
114210 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
114211 +persistent_ram_vmap_709 persistent_ram_vmap 1-2 709 NULL
114212 +xfs_bmap_eof_728 xfs_bmap_eof 0 728 NULL
114213 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
114214 +dvb_video_write_754 dvb_video_write 3 754 NULL
114215 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
114216 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
114217 +if_writecmd_815 if_writecmd 2 815 NULL
114218 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
114219 +error_state_read_859 error_state_read 6 859 NULL
114220 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
114221 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
114222 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
114223 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
114224 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
114225 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
114226 +mnt_want_write_975 mnt_want_write 0 975 NULL
114227 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
114228 +memcmp_990 memcmp 0 990 NULL
114229 +readreg_1017 readreg 0-1 1017 NULL
114230 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
114231 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
114232 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
114233 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
114234 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
114235 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
114236 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
114237 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
114238 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
114239 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
114240 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
114241 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
114242 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
114243 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
114244 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
114245 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
114246 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
114247 +fsync_buffers_list_1219 fsync_buffers_list 0 1219 NULL
114248 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
114249 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
114250 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
114251 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
114252 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
114253 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
114254 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
114255 +tcf_hash_create_1305 tcf_hash_create 4 1305 NULL
114256 +ffs_1322 ffs 0 1322 NULL
114257 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
114258 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
114259 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
114260 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
114261 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
114262 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
114263 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
114264 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
114265 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
114266 +file_read_actor_1401 file_read_actor 4-0 1401 NULL
114267 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
114268 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
114269 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
114270 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
114271 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
114272 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
114273 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
114274 +fpregs_set_1497 fpregs_set 4 1497 NULL
114275 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
114276 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
114277 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
114278 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
114279 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
114280 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
114281 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
114282 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
114283 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
114284 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
114285 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
114286 +rmap_add_1677 rmap_add 3 1677 NULL
114287 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
114288 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
114289 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
114290 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
114291 +internal_create_group_1733 internal_create_group 0 1733 NULL
114292 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
114293 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
114294 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
114295 +cosa_write_1774 cosa_write 3 1774 NULL
114296 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
114297 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
114298 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
114299 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
114300 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
114301 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
114302 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
114303 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
114304 +bdev_erase_1933 bdev_erase 3 1933 NULL
114305 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
114306 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
114307 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
114308 +update_qd_1955 update_qd 0 1955 NULL
114309 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
114310 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
114311 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
114312 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
114313 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
114314 +xfs_mru_cache_insert_2013 xfs_mru_cache_insert 0 2013 NULL
114315 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
114316 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
114317 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
114318 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
114319 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
114320 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
114321 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
114322 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
114323 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
114324 +audit_expand_2098 audit_expand 0 2098 NULL
114325 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
114326 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
114327 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
114328 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
114329 +enable_read_2117 enable_read 3 2117 NULL
114330 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
114331 +xfs_recover_inode_owner_change_2132 xfs_recover_inode_owner_change 0 2132 NULL
114332 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
114333 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
114334 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
114335 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
114336 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
114337 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
114338 +xfs_inobt_update_2206 xfs_inobt_update 0 2206 NULL
114339 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
114340 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
114341 +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
114342 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
114343 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
114344 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
114345 +do_update_counters_2259 do_update_counters 4 2259 NULL
114346 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
114347 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
114348 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
114349 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
114350 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
114351 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
114352 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
114353 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
114354 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
114355 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
114356 +ntfs_file_aio_write_nolock_2360 ntfs_file_aio_write_nolock 0 2360 NULL
114357 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
114358 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5-0 2368 NULL nohasharray
114359 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
114360 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
114361 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
114362 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
114363 +raid1_size_2419 raid1_size 0-2 2419 NULL
114364 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
114365 +wiphy_new_2482 wiphy_new 2 2482 NULL
114366 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
114367 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
114368 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
114369 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
114370 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
114371 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
114372 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
114373 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
114374 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
114375 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
114376 +slot_bytes_2609 slot_bytes 0 2609 NULL
114377 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
114378 +switch_status_2629 switch_status 5 2629 NULL
114379 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
114380 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
114381 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
114382 +oti6858_write_2692 oti6858_write 4 2692 NULL
114383 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
114384 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
114385 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
114386 +gfs2_glock_nq_num_2747 gfs2_glock_nq_num 0 2747 NULL
114387 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
114388 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
114389 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
114390 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
114391 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
114392 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
114393 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
114394 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
114395 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
114396 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
114397 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
114398 +nla_padlen_2883 nla_padlen 1 2883 NULL
114399 +cmm_write_2896 cmm_write 3 2896 NULL
114400 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
114401 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
114402 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
114403 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
114404 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
114405 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
114406 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
114407 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
114408 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
114409 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
114410 +_xfs_filestream_pick_ag_3007 _xfs_filestream_pick_ag 0 3007 NULL
114411 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
114412 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
114413 +depth_write_3021 depth_write 3 3021 NULL
114414 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
114415 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
114416 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
114417 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
114418 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
114419 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
114420 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
114421 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
114422 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
114423 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
114424 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
114425 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
114426 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
114427 +rb_alloc_3102 rb_alloc 1 3102 NULL
114428 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
114429 +print_time_3132 print_time 0 3132 NULL
114430 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
114431 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
114432 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
114433 +gfs2_rindex_update_3165 gfs2_rindex_update 0 3165 NULL
114434 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
114435 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
114436 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
114437 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
114438 +alloc_context_3194 alloc_context 1 3194 NULL
114439 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
114440 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
114441 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
114442 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
114443 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
114444 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
114445 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
114446 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
114447 +key_key_read_3241 key_key_read 3 3241 NULL
114448 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
114449 +__set_extent_bit_3305 __set_extent_bit 0 3305 NULL
114450 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
114451 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
114452 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
114453 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
114454 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
114455 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
114456 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
114457 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
114458 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
114459 +scnprintf_3360 scnprintf 0-2 3360 NULL
114460 +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
114461 +sr_read_3366 sr_read 3 3366 NULL
114462 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
114463 +send_stream_3397 send_stream 4 3397 NULL
114464 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
114465 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
114466 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
114467 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
114468 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
114469 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
114470 +softsynth_write_3455 softsynth_write 3 3455 NULL
114471 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
114472 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
114473 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
114474 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
114475 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
114476 +SyS_readv_3539 SyS_readv 3 3539 NULL
114477 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
114478 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
114479 +evtchn_read_3569 evtchn_read 3 3569 NULL
114480 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
114481 +vc_resize_3585 vc_resize 3-2 3585 NULL
114482 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
114483 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
114484 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
114485 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
114486 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
114487 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
114488 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
114489 +xfs_attr3_leaf_list_int_3661 xfs_attr3_leaf_list_int 0 3661 NULL
114490 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
114491 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
114492 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
114493 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
114494 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
114495 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
114496 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
114497 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
114498 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
114499 +get_fd_set_3866 get_fd_set 1 3866 NULL
114500 +apei_res_sub_3873 apei_res_sub 0 3873 NULL
114501 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
114502 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
114503 +nvram_write_3894 nvram_write 3 3894 NULL
114504 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
114505 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
114506 +vcs_write_3910 vcs_write 3 3910 NULL
114507 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
114508 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
114509 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
114510 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
114511 +do_add_counters_3992 do_add_counters 3 3992 NULL
114512 +xfs_bmbt_lookup_eq_3997 xfs_bmbt_lookup_eq 0 3997 NULL
114513 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
114514 +userspace_status_4004 userspace_status 4 4004 NULL
114515 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
114516 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
114517 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
114518 +blk_end_request_4024 blk_end_request 3 4024 NULL
114519 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
114520 +xfs_free_ag_extent_4036 xfs_free_ag_extent 0 4036 NULL
114521 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
114522 +read_file_queues_4078 read_file_queues 3 4078 NULL
114523 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
114524 +tm6000_read_4151 tm6000_read 3 4151 NULL
114525 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
114526 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
114527 +get_alua_req_4166 get_alua_req 3 4166 NULL
114528 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
114529 +read_file_bool_4180 read_file_bool 3 4180 NULL
114530 +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
114531 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
114532 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
114533 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
114534 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
114535 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
114536 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
114537 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
114538 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
114539 +count_strings_4315 count_strings 0 4315 NULL
114540 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
114541 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
114542 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
114543 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
114544 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
114545 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
114546 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
114547 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
114548 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
114549 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
114550 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
114551 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
114552 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
114553 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
114554 +set_link_security_4502 set_link_security 4 4502 NULL
114555 +xfs_btree_kill_root_4526 xfs_btree_kill_root 0 4526 NULL
114556 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
114557 +tty_register_device_4544 tty_register_device 2 4544 NULL
114558 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
114559 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
114560 +bch_alloc_4593 bch_alloc 1 4593 NULL
114561 +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
114562 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
114563 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
114564 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
114565 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
114566 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
114567 +kone_receive_4690 kone_receive 4 4690 NULL
114568 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
114569 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
114570 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
114571 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
114572 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
114573 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
114574 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
114575 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
114576 +create_subvol_4791 create_subvol 4 4791 NULL
114577 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
114578 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
114579 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
114580 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
114581 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
114582 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
114583 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
114584 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
114585 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
114586 +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
114587 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
114588 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
114589 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
114590 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
114591 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
114592 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
114593 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
114594 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
114595 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
114596 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
114597 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
114598 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
114599 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
114600 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
114601 +sound_write_5102 sound_write 3 5102 NULL
114602 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
114603 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
114604 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
114605 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
114606 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
114607 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
114608 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
114609 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
114610 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
114611 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
114612 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
114613 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
114614 +cq_free_res_5355 cq_free_res 5 5355 NULL
114615 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
114616 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
114617 +xfs_free_extent_5411 xfs_free_extent 0 5411 NULL
114618 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
114619 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
114620 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
114621 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
114622 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
114623 +tty_write_5494 tty_write 3 5494 NULL
114624 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
114625 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
114626 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
114627 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
114628 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
114629 +le_readq_5557 le_readq 0 5557 NULL
114630 +inw_5558 inw 0 5558 NULL
114631 +gfs2_extent_map_5561 gfs2_extent_map 0 5561 NULL
114632 +bioset_create_5580 bioset_create 1 5580 NULL
114633 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
114634 +__remove_suid_5618 __remove_suid 0 5618 NULL
114635 +gfs2_unstuffer_page_5620 gfs2_unstuffer_page 0 5620 NULL
114636 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
114637 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
114638 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
114639 +get_arg_5694 get_arg 3 5694 NULL
114640 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
114641 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
114642 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
114643 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
114644 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
114645 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
114646 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
114647 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
114648 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
114649 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
114650 +setup_req_5848 setup_req 3 5848 NULL
114651 +ria_page_count_5849 ria_page_count 0 5849 NULL
114652 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
114653 +config_buf_5862 config_buf 0 5862 NULL
114654 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
114655 +port_show_regs_5904 port_show_regs 3 5904 NULL
114656 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
114657 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
114658 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
114659 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
114660 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
114661 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
114662 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
114663 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
114664 +alloc_msg_6072 alloc_msg 1 6072 NULL
114665 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
114666 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
114667 +__mnt_want_write_6091 __mnt_want_write 0 6091 NULL
114668 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
114669 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
114670 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
114671 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
114672 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
114673 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
114674 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
114675 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
114676 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
114677 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
114678 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
114679 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
114680 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
114681 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
114682 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
114683 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
114684 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
114685 +serial_port_in_6291 serial_port_in 0 6291 NULL
114686 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
114687 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
114688 +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
114689 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
114690 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
114691 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
114692 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
114693 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
114694 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
114695 +xfs_bmap_extents_to_btree_6387 xfs_bmap_extents_to_btree 0 6387 NULL
114696 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
114697 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
114698 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
114699 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
114700 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
114701 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
114702 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
114703 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
114704 +mei_read_6507 mei_read 3 6507 NULL
114705 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
114706 +wdm_read_6549 wdm_read 3 6549 NULL
114707 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
114708 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
114709 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
114710 +xfs_iozero_6573 xfs_iozero 0 6573 NULL
114711 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
114712 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
114713 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
114714 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
114715 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
114716 +mpeg_read_6708 mpeg_read 3 6708 NULL
114717 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
114718 +video_proc_write_6724 video_proc_write 3 6724 NULL
114719 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
114720 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
114721 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
114722 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
114723 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
114724 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
114725 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
114726 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
114727 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
114728 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
114729 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
114730 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
114731 +xfs_rtany_summary_6851 xfs_rtany_summary 0 6851 NULL
114732 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
114733 +dio_complete_6879 dio_complete 0-2-3 6879 NULL
114734 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
114735 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
114736 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
114737 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
114738 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
114739 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
114740 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
114741 +lops_scan_elements_6916 lops_scan_elements 0 6916 NULL
114742 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
114743 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
114744 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
114745 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
114746 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
114747 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
114748 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
114749 +request_key_async_6990 request_key_async 4 6990 NULL
114750 +tpl_write_6998 tpl_write 3 6998 NULL
114751 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
114752 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
114753 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
114754 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
114755 +wimax_msg_7030 wimax_msg 4 7030 NULL
114756 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
114757 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
114758 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
114759 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
114760 +event_enable_read_7074 event_enable_read 3 7074 NULL
114761 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
114762 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
114763 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
114764 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
114765 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
114766 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
114767 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
114768 +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
114769 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
114770 +get_string_7302 get_string 0 7302 NULL
114771 +security_inode_need_killpriv_7322 security_inode_need_killpriv 0 7322 NULL
114772 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
114773 +mgmt_control_7349 mgmt_control 3 7349 NULL
114774 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
114775 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
114776 +xfs_btree_delete_7384 xfs_btree_delete 0 7384 NULL
114777 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
114778 +hweight_long_7388 hweight_long 1-0 7388 NULL
114779 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
114780 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
114781 +readb_7401 readb 0 7401 NULL
114782 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
114783 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
114784 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
114785 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
114786 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
114787 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
114788 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
114789 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
114790 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
114791 +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
114792 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
114793 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
114794 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
114795 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
114796 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
114797 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
114798 +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
114799 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
114800 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
114801 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
114802 +xfs_bmap_btalloc_nullfb_7654 xfs_bmap_btalloc_nullfb 0 7654 NULL
114803 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
114804 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
114805 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
114806 +dev_write_7708 dev_write 3 7708 NULL
114807 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
114808 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
114809 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
114810 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
114811 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
114812 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
114813 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
114814 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
114815 +xfs_alloc_find_best_extent_7837 xfs_alloc_find_best_extent 0 7837 NULL
114816 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
114817 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
114818 +config_desc_7878 config_desc 0 7878 NULL
114819 +gfs2_permission_7884 gfs2_permission 0 7884 NULL
114820 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
114821 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
114822 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
114823 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
114824 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
114825 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
114826 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
114827 +vcs_read_8017 vcs_read 3 8017 NULL
114828 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
114829 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
114830 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
114831 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
114832 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
114833 +venus_lookup_8121 venus_lookup 4 8121 NULL
114834 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
114835 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
114836 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
114837 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
114838 +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
114839 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
114840 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
114841 +play_iframe_8219 play_iframe 3 8219 NULL
114842 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
114843 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
114844 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
114845 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
114846 +init_cdev_8274 init_cdev 1 8274 NULL
114847 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
114848 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
114849 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
114850 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
114851 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
114852 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
114853 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
114854 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
114855 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
114856 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
114857 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
114858 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
114859 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
114860 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
114861 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
114862 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
114863 +dev_config_8506 dev_config 3 8506 NULL
114864 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
114865 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
114866 +user_on_off_8552 user_on_off 2 8552 NULL
114867 +profile_remove_8556 profile_remove 3 8556 NULL
114868 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
114869 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
114870 +tower_write_8580 tower_write 3 8580 NULL
114871 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
114872 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
114873 +xfs_qm_dqattach_locked_8625 xfs_qm_dqattach_locked 0 8625 NULL
114874 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
114875 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
114876 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
114877 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
114878 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
114879 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
114880 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
114881 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
114882 +arcfb_write_8702 arcfb_write 3 8702 NULL
114883 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
114884 +init_header_8703 init_header 0 8703 &i_size_read_8703
114885 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
114886 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
114887 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
114888 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
114889 +__create_irqs_8733 __create_irqs 2 8733 NULL
114890 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
114891 +compound_order_8750 compound_order 0 8750 NULL
114892 +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
114893 +yurex_write_8761 yurex_write 3 8761 NULL
114894 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
114895 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
114896 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
114897 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
114898 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
114899 +gfs2_glock_nq_8808 gfs2_glock_nq 0 8808 NULL
114900 +ntfs_commit_pages_after_write_8809 ntfs_commit_pages_after_write 0 8809 NULL
114901 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
114902 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
114903 +extent_read_full_page_8826 extent_read_full_page 0 8826 NULL
114904 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
114905 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
114906 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
114907 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
114908 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
114909 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
114910 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
114911 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
114912 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
114913 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
114914 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
114915 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
114916 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
114917 +write_file_ani_8918 write_file_ani 3 8918 NULL
114918 +layout_commit_8926 layout_commit 3 8926 NULL
114919 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
114920 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
114921 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
114922 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
114923 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
114924 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
114925 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
114926 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
114927 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
114928 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
114929 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
114930 +xfs_inobt_get_rec_9023 xfs_inobt_get_rec 0 9023 NULL
114931 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
114932 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
114933 +nla_put_9042 nla_put 3 9042 NULL
114934 +ffs_func_revmap_intf_9043 ffs_func_revmap_intf 0 9043 NULL
114935 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
114936 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
114937 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
114938 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
114939 +create_queues_9088 create_queues 2-3 9088 NULL
114940 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
114941 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
114942 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
114943 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110 nohasharray
114944 +jhead_scan_9110 jhead_scan 0 9110 &gfn_to_rmap_9110
114945 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
114946 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
114947 +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
114948 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
114949 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
114950 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
114951 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
114952 +xfs_btree_rshift_9187 xfs_btree_rshift 0 9187 NULL
114953 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
114954 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
114955 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
114956 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
114957 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
114958 +xfs_error_trap_9239 xfs_error_trap 0-1 9239 NULL
114959 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
114960 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
114961 +flakey_status_9274 flakey_status 5 9274 NULL
114962 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
114963 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
114964 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
114965 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
114966 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
114967 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
114968 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
114969 +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
114970 +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
114971 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
114972 +read_9397 read 3 9397 NULL
114973 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
114974 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
114975 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
114976 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
114977 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
114978 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
114979 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
114980 +crypt_status_9492 crypt_status 5 9492 NULL
114981 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
114982 +lp_write_9511 lp_write 3 9511 NULL
114983 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
114984 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
114985 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
114986 +read_file_dma_9530 read_file_dma 3 9530 NULL
114987 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
114988 +xfs_ialloc_read_agi_9545 xfs_ialloc_read_agi 0 9545 NULL
114989 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
114990 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
114991 +fw_node_create_9559 fw_node_create 2 9559 NULL
114992 +kobj_map_9566 kobj_map 2-3 9566 NULL
114993 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
114994 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
114995 +xfs_qm_dqattach_one_9612 xfs_qm_dqattach_one 0 9612 NULL
114996 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
114997 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
114998 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
114999 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
115000 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
115001 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
115002 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
115003 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
115004 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
115005 +dns_query_9676 dns_query 3 9676 NULL
115006 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
115007 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
115008 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
115009 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
115010 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
115011 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
115012 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
115013 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
115014 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
115015 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
115016 +shmem_replace_page_9740 shmem_replace_page 0 9740 NULL
115017 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
115018 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
115019 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
115020 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
115021 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
115022 +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
115023 +tpm_data_in_9802 tpm_data_in 0 9802 NULL
115024 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
115025 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
115026 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
115027 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
115028 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
115029 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
115030 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
115031 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
115032 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
115033 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
115034 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
115035 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
115036 +read_file_misc_9948 read_file_misc 3 9948 NULL
115037 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
115038 +xfs_buf_geterror_9959 xfs_buf_geterror 0 9959 NULL
115039 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
115040 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
115041 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
115042 +gameport_read_9983 gameport_read 0 9983 NULL
115043 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
115044 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
115045 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
115046 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
115047 +xfs_attr_rmtval_get_10092 xfs_attr_rmtval_get 0 10092 NULL
115048 +xfs_btree_check_lptr_10104 xfs_btree_check_lptr 0 10104 NULL
115049 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
115050 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
115051 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
115052 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
115053 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
115054 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
115055 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
115056 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
115057 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
115058 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
115059 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
115060 +xfs_attr_rmtval_copyout_10222 xfs_attr_rmtval_copyout 0 10222 NULL nohasharray
115061 +xfs_btree_read_buf_block_10222 xfs_btree_read_buf_block 0 10222 &xfs_attr_rmtval_copyout_10222
115062 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
115063 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
115064 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
115065 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
115066 +read_emulate_10310 read_emulate 2-4 10310 NULL
115067 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
115068 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
115069 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
115070 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
115071 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
115072 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
115073 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
115074 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
115075 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
115076 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
115077 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
115078 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
115079 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
115080 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
115081 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
115082 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
115083 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
115084 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
115085 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
115086 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
115087 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
115088 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
115089 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
115090 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
115091 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
115092 +otp_read_10594 otp_read 2-4-5 10594 NULL
115093 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
115094 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
115095 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
115096 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
115097 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
115098 +parport_write_10669 parport_write 0 10669 NULL
115099 +edge_write_10692 edge_write 4 10692 NULL
115100 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
115101 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
115102 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
115103 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
115104 +spi_sync_10731 spi_sync 0 10731 NULL
115105 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
115106 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
115107 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
115108 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
115109 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
115110 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
115111 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
115112 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
115113 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
115114 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
115115 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
115116 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
115117 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
115118 +get_scq_10897 get_scq 2 10897 NULL
115119 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
115120 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
115121 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
115122 +kobject_add_10919 kobject_add 0 10919 NULL
115123 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
115124 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
115125 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
115126 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
115127 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
115128 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
115129 +gfs2_dir_read_11017 gfs2_dir_read 0 11017 NULL
115130 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
115131 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
115132 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
115133 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
115134 +count_argc_11083 count_argc 0 11083 NULL
115135 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
115136 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
115137 +page_offset_11120 page_offset 0 11120 NULL
115138 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
115139 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
115140 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
115141 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
115142 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
115143 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
115144 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
115145 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
115146 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
115147 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
115148 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
115149 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
115150 +shmem_radix_tree_replace_11325 shmem_radix_tree_replace 0 11325 NULL
115151 +construct_key_11329 construct_key 3 11329 NULL nohasharray
115152 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
115153 +next_segment_11330 next_segment 0-2-1 11330 NULL
115154 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 2-1 11332 NULL
115155 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
115156 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
115157 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
115158 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
115159 +nft_value_dump_11381 nft_value_dump 3 11381 NULL
115160 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
115161 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
115162 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
115163 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
115164 +str_to_user_11411 str_to_user 2 11411 NULL
115165 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
115166 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
115167 +xfs_btree_lookup_11417 xfs_btree_lookup 0 11417 NULL nohasharray
115168 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 &xfs_btree_lookup_11417
115169 +trace_options_read_11419 trace_options_read 3 11419 NULL
115170 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
115171 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
115172 +bttv_read_11432 bttv_read 3 11432 NULL
115173 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
115174 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
115175 +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
115176 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
115177 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4-0 11492 NULL
115178 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
115179 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
115180 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
115181 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
115182 +xfs_rtcheck_alloc_range_11553 xfs_rtcheck_alloc_range 0 11553 NULL
115183 +radix_tree_extend_11555 radix_tree_extend 0 11555 NULL
115184 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
115185 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
115186 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
115187 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
115188 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
115189 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
115190 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
115191 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
115192 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
115193 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
115194 +slab_ksize_11664 slab_ksize 0 11664 NULL
115195 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
115196 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
115197 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
115198 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
115199 +split_11691 split 2 11691 NULL
115200 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
115201 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
115202 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
115203 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
115204 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
115205 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
115206 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
115207 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
115208 +xfs_ialloc_11819 xfs_ialloc 0 11819 NULL
115209 +umc_device_register_11824 umc_device_register 0 11824 NULL
115210 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
115211 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
115212 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
115213 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
115214 +xfs_file_aio_write_checks_11851 xfs_file_aio_write_checks 0 11851 NULL
115215 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
115216 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
115217 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
115218 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
115219 +ti_write_11916 ti_write 4 11916 NULL
115220 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
115221 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
115222 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
115223 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
115224 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
115225 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
115226 +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
115227 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
115228 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
115229 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
115230 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
115231 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
115232 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
115233 +gfs2_find_jhead_12117 gfs2_find_jhead 0 12117 NULL
115234 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
115235 +set_powered_12129 set_powered 4 12129 NULL
115236 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
115237 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
115238 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
115239 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
115240 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
115241 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
115242 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
115243 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
115244 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
115245 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
115246 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
115247 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
115248 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
115249 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
115250 +xfs_attr3_leaf_read_12222 xfs_attr3_leaf_read 0 12222 NULL
115251 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
115252 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
115253 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
115254 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
115255 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
115256 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
115257 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
115258 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
115259 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
115260 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
115261 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
115262 +xfs_bmap_last_extent_12335 xfs_bmap_last_extent 0 12335 NULL
115263 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
115264 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
115265 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
115266 +populate_dir_12391 populate_dir 0 12391 NULL nohasharray
115267 +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
115268 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
115269 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
115270 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
115271 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
115272 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
115273 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
115274 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
115275 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
115276 +write_inode_now_12565 write_inode_now 0 12565 NULL
115277 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
115278 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
115279 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
115280 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
115281 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
115282 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
115283 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
115284 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
115285 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
115286 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
115287 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
115288 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
115289 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
115290 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
115291 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
115292 +ivtv_write_12721 ivtv_write 3 12721 NULL
115293 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
115294 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
115295 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
115296 +listxattr_12769 listxattr 3 12769 NULL
115297 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
115298 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
115299 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
115300 +readq_12825 readq 0 12825 NULL
115301 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
115302 +gfs2_log_reserve_12835 gfs2_log_reserve 0 12835 NULL
115303 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
115304 +spidev_sync_12842 spidev_sync 0 12842 NULL
115305 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
115306 +xfs_rtallocate_extent_exact_12865 xfs_rtallocate_extent_exact 0 12865 NULL
115307 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
115308 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
115309 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
115310 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
115311 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
115312 +bm_status_write_12964 bm_status_write 3 12964 NULL
115313 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
115314 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
115315 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
115316 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
115317 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
115318 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
115319 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
115320 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
115321 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
115322 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
115323 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
115324 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
115325 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
115326 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
115327 +blk_update_request_13146 blk_update_request 3 13146 NULL
115328 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
115329 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
115330 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
115331 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
115332 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
115333 +comedi_read_13199 comedi_read 3 13199 NULL
115334 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
115335 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
115336 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
115337 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
115338 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
115339 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
115340 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
115341 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
115342 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
115343 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
115344 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
115345 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
115346 +sd_major_13294 sd_major 0-1 13294 NULL
115347 +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
115348 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
115349 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
115350 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
115351 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
115352 +xfs_btree_delrec_13364 xfs_btree_delrec 0 13364 NULL
115353 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
115354 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
115355 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
115356 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
115357 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
115358 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
115359 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
115360 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
115361 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
115362 +data_read_13494 data_read 3 13494 NULL
115363 +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
115364 +core_status_13515 core_status 4 13515 NULL
115365 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
115366 +bm_init_13529 bm_init 2 13529 NULL
115367 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
115368 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
115369 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
115370 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
115371 +cache_write_13589 cache_write 3 13589 NULL
115372 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
115373 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
115374 +__ntfs_grab_cache_pages_13617 __ntfs_grab_cache_pages 0 13617 NULL
115375 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
115376 +packet_snd_13634 packet_snd 3 13634 NULL
115377 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
115378 +cache_downcall_13666 cache_downcall 3 13666 NULL
115379 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
115380 +usb_get_string_13693 usb_get_string 0 13693 NULL
115381 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
115382 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
115383 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
115384 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
115385 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
115386 +random_read_13815 random_read 3 13815 NULL
115387 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
115388 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
115389 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
115390 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
115391 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
115392 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
115393 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
115394 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
115395 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
115396 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
115397 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
115398 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
115399 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
115400 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
115401 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL nohasharray
115402 +pagecache_write_end_13950 pagecache_write_end 0 13950 &lpfc_idiag_queacc_read_13950
115403 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
115404 +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
115405 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
115406 +qcam_read_13977 qcam_read 3 13977 NULL
115407 +dsp_read_13980 dsp_read 2 13980 NULL
115408 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
115409 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
115410 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
115411 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
115412 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
115413 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
115414 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
115415 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
115416 +xfs_bmap_alloc_14044 xfs_bmap_alloc 0 14044 NULL
115417 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
115418 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
115419 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
115420 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
115421 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
115422 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
115423 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
115424 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
115425 +em_canid_change_14150 em_canid_change 3 14150 NULL
115426 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
115427 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
115428 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
115429 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
115430 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
115431 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
115432 +alloc_async_14208 alloc_async 1 14208 NULL
115433 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
115434 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
115435 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
115436 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
115437 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
115438 +rr_status_14293 rr_status 5 14293 NULL
115439 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
115440 +update_rgrp_lvb_14303 update_rgrp_lvb 0 14303 NULL
115441 +xfs_qm_qino_alloc_14309 xfs_qm_qino_alloc 0 14309 NULL
115442 +oo_objects_14319 oo_objects 0 14319 NULL
115443 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
115444 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
115445 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
115446 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
115447 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
115448 +lowpan_read_14369 lowpan_read 3 14369 NULL
115449 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
115450 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
115451 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
115452 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
115453 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
115454 +block_size_14443 block_size 0 14443 NULL
115455 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
115456 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
115457 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
115458 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
115459 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
115460 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
115461 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
115462 +split_state_14491 split_state 0 14491 NULL
115463 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
115464 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
115465 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
115466 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
115467 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
115468 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
115469 +stuffed_readpage_14581 stuffed_readpage 0 14581 NULL
115470 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
115471 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
115472 +dbJoin_14644 dbJoin 0 14644 NULL
115473 +profile_replace_14652 profile_replace 3 14652 NULL
115474 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
115475 +add_to_page_cache_locked_14668 add_to_page_cache_locked 0 14668 NULL
115476 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
115477 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
115478 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
115479 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
115480 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
115481 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
115482 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
115483 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
115484 +cgroup_path_14713 cgroup_path 3 14713 NULL
115485 +vfd_write_14717 vfd_write 3 14717 NULL
115486 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
115487 +raid1_resize_14740 raid1_resize 2 14740 NULL
115488 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
115489 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
115490 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
115491 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
115492 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
115493 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
115494 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
115495 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
115496 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
115497 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
115498 +security_inode_rename_14805 security_inode_rename 0 14805 NULL
115499 +xfs_btree_kill_iroot_14824 xfs_btree_kill_iroot 0 14824 NULL
115500 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
115501 +lcd_write_14857 lcd_write 3 14857 NULL
115502 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
115503 +xfs_bmapi_convert_unwritten_14886 xfs_bmapi_convert_unwritten 0 14886 NULL
115504 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
115505 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
115506 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
115507 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
115508 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
115509 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
115510 +queue_cnt_14951 queue_cnt 0 14951 NULL
115511 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
115512 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
115513 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
115514 +setkey_14987 setkey 3 14987 NULL nohasharray
115515 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
115516 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
115517 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
115518 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
115519 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
115520 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
115521 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
115522 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
115523 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
115524 +xfs_btree_insrec_15090 xfs_btree_insrec 0 15090 NULL
115525 +btrfs_readpage_15094 btrfs_readpage 0 15094 NULL
115526 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
115527 +start_port_15124 start_port 0 15124 NULL
115528 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
115529 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
115530 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
115531 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
115532 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
115533 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
115534 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
115535 +simple_strtol_15273 simple_strtol 0 15273 NULL
115536 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
115537 +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
115538 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
115539 +ioread16_15342 ioread16 0 15342 NULL
115540 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
115541 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
115542 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
115543 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
115544 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
115545 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
115546 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
115547 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
115548 +get_modalias_15406 get_modalias 2 15406 NULL
115549 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
115550 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
115551 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
115552 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
115553 +memweight_15450 memweight 2 15450 NULL
115554 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
115555 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
115556 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
115557 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
115558 +persistent_status_15574 persistent_status 4 15574 NULL
115559 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
115560 +vme_user_write_15587 vme_user_write 3 15587 NULL
115561 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
115562 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
115563 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
115564 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
115565 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
115566 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
115567 +fs_path_add_15648 fs_path_add 3 15648 NULL
115568 +__do_readpage_15652 __do_readpage 0 15652 NULL
115569 +xsd_read_15653 xsd_read 3 15653 NULL
115570 +unix_bind_15668 unix_bind 3 15668 NULL
115571 +dm_read_15674 dm_read 3 15674 NULL nohasharray
115572 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
115573 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
115574 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
115575 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
115576 +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
115577 +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
115578 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
115579 +table_size_15851 table_size 0-1-2 15851 NULL
115580 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
115581 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
115582 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
115583 +native_read_msr_15905 native_read_msr 0 15905 NULL
115584 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
115585 +power_read_15939 power_read 3 15939 NULL
115586 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
115587 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
115588 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
115589 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
115590 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
115591 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
115592 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
115593 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
115594 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
115595 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
115596 +gfs2_jdesc_check_16122 gfs2_jdesc_check 0 16122 NULL
115597 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
115598 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
115599 +fsm_init_16134 fsm_init 2 16134 NULL
115600 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
115601 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
115602 +mapping_level_16188 mapping_level 2-0 16188 NULL
115603 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
115604 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
115605 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
115606 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
115607 +create_table_16213 create_table 2 16213 NULL
115608 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
115609 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
115610 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
115611 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
115612 +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
115613 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
115614 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
115615 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
115616 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
115617 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
115618 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
115619 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
115620 +account_16283 account 0-4-2 16283 NULL nohasharray
115621 +mirror_status_16283 mirror_status 5 16283 &account_16283
115622 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
115623 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
115624 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
115625 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
115626 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
115627 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
115628 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
115629 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
115630 +xfs_inobt_lookup_16367 xfs_inobt_lookup 0 16367 NULL
115631 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
115632 +gfs2_dinode_in_16378 gfs2_dinode_in 0 16378 NULL
115633 +xfs_btree_check_block_16419 xfs_btree_check_block 0 16419 NULL
115634 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
115635 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
115636 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
115637 +cmdline_store_16442 cmdline_store 4 16442 NULL
115638 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
115639 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
115640 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
115641 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
115642 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
115643 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
115644 +raid10_resize_16537 raid10_resize 2 16537 NULL
115645 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
115646 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
115647 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
115648 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
115649 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
115650 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
115651 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
115652 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
115653 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
115654 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
115655 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
115656 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
115657 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
115658 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
115659 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
115660 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
115661 +xfs_dialloc_ag_16868 xfs_dialloc_ag 0 16868 NULL
115662 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL nohasharray
115663 +xfs_iget_16872 xfs_iget 0 16872 &alloc_idx_lebs_16872
115664 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
115665 +st_write_16874 st_write 3 16874 NULL
115666 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
115667 +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
115668 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
115669 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
115670 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
115671 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
115672 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
115673 +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
115674 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
115675 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
115676 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
115677 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
115678 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
115679 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
115680 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
115681 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
115682 +entry_length_17093 entry_length 0 17093 NULL
115683 +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
115684 +write_mem_17114 write_mem 3 17114 NULL
115685 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
115686 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
115687 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
115688 +sep_read_17161 sep_read 3 17161 NULL
115689 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
115690 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
115691 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
115692 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
115693 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
115694 +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
115695 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
115696 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
115697 +sync_request_17208 sync_request 2 17208 NULL
115698 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
115699 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
115700 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
115701 +alloc_ep_17269 alloc_ep 1 17269 NULL
115702 +pg_read_17276 pg_read 3 17276 NULL
115703 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
115704 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
115705 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
115706 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
115707 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
115708 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
115709 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
115710 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
115711 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
115712 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
115713 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
115714 +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
115715 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
115716 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
115717 +xfs_btree_lshift_17448 xfs_btree_lshift 0 17448 NULL
115718 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
115719 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
115720 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
115721 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
115722 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
115723 +qp_free_res_17541 qp_free_res 5 17541 NULL
115724 +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
115725 +copy_from_user_17559 copy_from_user 0-3 17559 NULL
115726 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
115727 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
115728 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
115729 +osst_execute_17607 osst_execute 7-6 17607 NULL
115730 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
115731 +dma_map_page_17628 dma_map_page 0 17628 NULL
115732 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
115733 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
115734 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
115735 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
115736 +filemap_fdatawait_17688 filemap_fdatawait 0 17688 NULL
115737 +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
115738 +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
115739 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
115740 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
115741 +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
115742 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
115743 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
115744 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
115745 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
115746 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
115747 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
115748 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
115749 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
115750 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
115751 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
115752 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
115753 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
115754 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
115755 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
115756 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
115757 +xfs_rtallocate_extent_near_17916 xfs_rtallocate_extent_near 0 17916 NULL
115758 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
115759 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
115760 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
115761 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
115762 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
115763 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
115764 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
115765 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
115766 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
115767 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
115768 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
115769 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
115770 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
115771 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
115772 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
115773 +fpregs_get_18066 fpregs_get 4 18066 NULL
115774 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
115775 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
115776 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
115777 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
115778 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
115779 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
115780 +svc_getnl_18120 svc_getnl 0 18120 NULL
115781 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
115782 +xfs_zero_eof_18134 xfs_zero_eof 0 18134 NULL
115783 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
115784 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
115785 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
115786 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
115787 +read_rindex_entry_18213 read_rindex_entry 0 18213 NULL
115788 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
115789 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
115790 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
115791 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
115792 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
115793 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
115794 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
115795 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
115796 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
115797 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
115798 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
115799 +um_idi_write_18293 um_idi_write 3 18293 NULL
115800 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
115801 +vga_r_18310 vga_r 0 18310 NULL
115802 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
115803 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
115804 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
115805 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
115806 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
115807 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
115808 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
115809 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
115810 +ep_io_18367 ep_io 0 18367 NULL
115811 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
115812 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
115813 +ci_role_write_18388 ci_role_write 3 18388 NULL
115814 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
115815 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
115816 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
115817 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
115818 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
115819 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
115820 +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
115821 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
115822 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
115823 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
115824 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
115825 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
115826 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
115827 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
115828 +__block_write_begin_18511 __block_write_begin 0 18511 NULL
115829 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
115830 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
115831 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
115832 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
115833 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
115834 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
115835 +debug_output_18575 debug_output 3 18575 NULL
115836 +xfs_btree_read_bufl_18597 xfs_btree_read_bufl 0 18597 NULL
115837 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL
115838 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
115839 +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL
115840 +from_buffer_18625 from_buffer 3 18625 NULL
115841 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
115842 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
115843 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
115844 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
115845 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
115846 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
115847 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
115848 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
115849 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
115850 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
115851 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
115852 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
115853 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
115854 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
115855 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
115856 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
115857 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
115858 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
115859 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
115860 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
115861 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
115862 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
115863 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
115864 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
115865 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
115866 +clean_journal_18955 clean_journal 0 18955 NULL
115867 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
115868 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
115869 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
115870 +huge_page_size_19008 huge_page_size 0 19008 NULL
115871 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
115872 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
115873 +revalidate_19043 revalidate 2 19043 NULL
115874 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
115875 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
115876 +get_log_header_19063 get_log_header 0 19063 NULL
115877 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
115878 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
115879 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
115880 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
115881 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
115882 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
115883 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
115884 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
115885 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
115886 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
115887 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
115888 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
115889 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
115890 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
115891 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
115892 +ucma_query_19260 ucma_query 4 19260 NULL
115893 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
115894 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
115895 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
115896 +qc_capture_19298 qc_capture 3 19298 NULL
115897 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
115898 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
115899 +debug_read_19322 debug_read 3 19322 NULL
115900 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
115901 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
115902 +closure_sub_19359 closure_sub 2 19359 NULL
115903 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
115904 +read_zero_19366 read_zero 3 19366 NULL
115905 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
115906 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
115907 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
115908 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
115909 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
115910 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
115911 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
115912 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
115913 +sky2_read16_19475 sky2_read16 0 19475 NULL
115914 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
115915 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
115916 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
115917 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
115918 +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
115919 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
115920 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
115921 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
115922 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
115923 +nfsd_read_19568 nfsd_read 5 19568 NULL
115924 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
115925 +mnt_want_write_file_19579 mnt_want_write_file 0 19579 NULL
115926 +bm_status_read_19583 bm_status_read 3 19583 NULL
115927 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
115928 +fallocate_chunk_19610 fallocate_chunk 0 19610 NULL
115929 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
115930 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
115931 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
115932 +ocfs2_control_get_this_node_19721 ocfs2_control_get_this_node 0 19721 NULL
115933 +read_reg_19723 read_reg 0 19723 NULL
115934 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
115935 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
115936 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
115937 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
115938 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
115939 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
115940 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
115941 +readhscx_19769 readhscx 0 19769 NULL
115942 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
115943 +xfs_bmap_add_extent_hole_real_19828 xfs_bmap_add_extent_hole_real 0 19828 NULL
115944 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
115945 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
115946 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
115947 +__nla_put_19857 __nla_put 3 19857 NULL
115948 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
115949 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
115950 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
115951 +mangle_name_19923 mangle_name 0 19923 NULL
115952 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
115953 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
115954 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
115955 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
115956 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
115957 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
115958 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
115959 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
115960 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
115961 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
115962 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
115963 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
115964 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
115965 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
115966 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
115967 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
115968 +target_message_20072 target_message 2 20072 NULL
115969 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
115970 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
115971 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
115972 +team_options_register_20091 team_options_register 3 20091 NULL
115973 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
115974 +xfs_qm_dqget_20103 xfs_qm_dqget 0 20103 NULL
115975 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
115976 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
115977 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
115978 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
115979 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
115980 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
115981 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
115982 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
115983 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
115984 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
115985 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
115986 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
115987 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
115988 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
115989 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
115990 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
115991 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
115992 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
115993 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
115994 +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
115995 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
115996 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
115997 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
115998 +read_buf_20469 read_buf 2 20469 NULL
115999 +bio_trim_20472 bio_trim 2 20472 NULL
116000 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
116001 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
116002 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
116003 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
116004 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
116005 +venus_create_20555 venus_create 4 20555 NULL
116006 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
116007 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
116008 +xfs_bmap_isaeof_20570 xfs_bmap_isaeof 0 20570 NULL
116009 +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
116010 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
116011 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
116012 +lirc_write_20604 lirc_write 3 20604 NULL
116013 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
116014 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
116015 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
116016 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
116017 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
116018 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
116019 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
116020 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL nohasharray
116021 +btrfs_qgroup_reserve_20676 btrfs_qgroup_reserve 0 20676 &snd_hdsp_playback_copy_20676
116022 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
116023 +cpumask_size_20683 cpumask_size 0 20683 NULL
116024 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
116025 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
116026 +__maestro_read_20700 __maestro_read 0 20700 NULL
116027 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
116028 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
116029 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
116030 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
116031 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
116032 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
116033 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
116034 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL nohasharray
116035 +mnt_clone_write_20763 mnt_clone_write 0 20763 &brcmf_p2p_escan_20763
116036 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
116037 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
116038 +lowpan_write_20800 lowpan_write 3 20800 NULL
116039 +strndup_user_20819 strndup_user 2 20819 NULL nohasharray
116040 +do_glock_20819 do_glock 0 20819 &strndup_user_20819
116041 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
116042 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
116043 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
116044 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
116045 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
116046 +get_name_20855 get_name 4 20855 NULL
116047 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
116048 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
116049 +srq_free_res_20868 srq_free_res 5 20868 NULL
116050 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
116051 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
116052 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
116053 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
116054 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
116055 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
116056 +htable_bits_20933 htable_bits 0 20933 NULL
116057 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
116058 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
116059 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
116060 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
116061 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
116062 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
116063 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
116064 +btrfs_dirty_pages_21019 btrfs_dirty_pages 0 21019 NULL
116065 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
116066 +xfs_btree_new_root_21028 xfs_btree_new_root 0 21028 NULL
116067 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
116068 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
116069 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
116070 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
116071 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
116072 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
116073 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
116074 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
116075 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
116076 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
116077 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
116078 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
116079 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
116080 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
116081 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
116082 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
116083 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
116084 +input_ff_create_21240 input_ff_create 2 21240 NULL
116085 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
116086 +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
116087 +fru_length_21257 fru_length 0 21257 NULL
116088 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
116089 +xfs_alloc_ag_vextent_size_21276 xfs_alloc_ag_vextent_size 0 21276 NULL
116090 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
116091 +add_res_range_21310 add_res_range 4 21310 NULL
116092 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
116093 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
116094 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
116095 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
116096 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
116097 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
116098 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
116099 +insert_ptr_21386 insert_ptr 6 21386 NULL
116100 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
116101 +__clone_and_map_simple_bio_21404 __clone_and_map_simple_bio 4 21404 NULL
116102 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
116103 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
116104 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
116105 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
116106 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
116107 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
116108 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
116109 +ReadISAR_21453 ReadISAR 0 21453 NULL
116110 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
116111 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
116112 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
116113 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
116114 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
116115 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
116116 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
116117 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
116118 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
116119 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
116120 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
116121 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
116122 +gfs2_glock_nq_init_21624 gfs2_glock_nq_init 0 21624 NULL
116123 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
116124 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
116125 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
116126 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
116127 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
116128 +xfs_btree_insert_21712 xfs_btree_insert 0 21712 NULL
116129 +update_time_21719 update_time 0 21719 NULL
116130 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
116131 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
116132 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
116133 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
116134 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
116135 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
116136 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
116137 +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
116138 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
116139 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
116140 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
116141 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
116142 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
116143 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
116144 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
116145 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
116146 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
116147 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
116148 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
116149 +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
116150 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
116151 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
116152 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
116153 +lookup_metapath_22039 lookup_metapath 0 22039 NULL
116154 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
116155 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
116156 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
116157 +mem_rw_22085 mem_rw 3 22085 NULL
116158 +xfs_bmapi_reserve_delalloc_22086 xfs_bmapi_reserve_delalloc 0 22086 NULL
116159 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
116160 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
116161 +shmem_add_to_page_cache_22121 shmem_add_to_page_cache 0 22121 NULL
116162 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
116163 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
116164 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
116165 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
116166 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
116167 +mem_write_22232 mem_write 3 22232 NULL
116168 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
116169 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
116170 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
116171 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
116172 +add_res_tree_22263 add_res_tree 7 22263 NULL
116173 +__btrfs_direct_write_22273 __btrfs_direct_write 4-0 22273 NULL
116174 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
116175 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
116176 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
116177 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
116178 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
116179 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
116180 +atomic_read_22342 atomic_read 0 22342 NULL
116181 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
116182 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
116183 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
116184 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
116185 +zoran_write_22404 zoran_write 3 22404 NULL
116186 +queue_reply_22416 queue_reply 3 22416 NULL
116187 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
116188 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
116189 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
116190 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
116191 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
116192 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
116193 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
116194 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
116195 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
116196 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
116197 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
116198 +snapshot_read_22601 snapshot_read 3 22601 NULL
116199 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
116200 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
116201 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
116202 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
116203 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
116204 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
116205 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
116206 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
116207 +reg_umr_22686 reg_umr 5 22686 NULL
116208 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
116209 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
116210 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
116211 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
116212 +__writeback_single_inode_22739 __writeback_single_inode 0 22739 NULL
116213 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
116214 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
116215 +print_frame_22769 print_frame 0 22769 NULL
116216 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
116217 +__break_lease_22777 __break_lease 0 22777 NULL
116218 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
116219 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
116220 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
116221 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
116222 +create_attr_set_22861 create_attr_set 1 22861 NULL
116223 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
116224 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
116225 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
116226 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
116227 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
116228 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
116229 +__set_xattr_22923 __set_xattr 0 22923 NULL
116230 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
116231 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
116232 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
116233 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
116234 +vme_get_size_22964 vme_get_size 0 22964 NULL
116235 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
116236 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
116237 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
116238 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
116239 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
116240 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
116241 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0 23029 NULL
116242 +st_status_23032 st_status 5 23032 NULL
116243 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
116244 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
116245 +security_inode_killpriv_23060 security_inode_killpriv 0 23060 NULL
116246 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
116247 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
116248 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
116249 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
116250 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
116251 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
116252 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
116253 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
116254 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
116255 +xfs_dir_ialloc_23100 xfs_dir_ialloc 0 23100 NULL
116256 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
116257 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
116258 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
116259 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL nohasharray
116260 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 &nl80211_send_rx_auth_23111
116261 +__clear_user_23118 __clear_user 0-2 23118 NULL
116262 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
116263 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
116264 +read_file_ani_23161 read_file_ani 3 23161 NULL
116265 +usblp_write_23178 usblp_write 3 23178 NULL
116266 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
116267 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
116268 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
116269 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
116270 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
116271 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
116272 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
116273 +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
116274 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
116275 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
116276 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
116277 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
116278 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
116279 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
116280 +page_readlink_23346 page_readlink 3 23346 NULL
116281 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
116282 +get_dst_timing_23358 get_dst_timing 0 23358 NULL nohasharray
116283 +write_inode_23358 write_inode 0 23358 &get_dst_timing_23358
116284 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
116285 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
116286 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
116287 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
116288 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
116289 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
116290 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
116291 +sync_mapping_buffers_23485 sync_mapping_buffers 0 23485 &linear_conf_23485
116292 +event_filter_read_23494 event_filter_read 3 23494 NULL
116293 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
116294 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
116295 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
116296 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
116297 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
116298 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
116299 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
116300 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
116301 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
116302 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
116303 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
116304 +xfs_qm_dqread_23613 xfs_qm_dqread 0 23613 NULL
116305 +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
116306 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
116307 +sInW_23663 sInW 0 23663 NULL
116308 +SyS_connect_23669 SyS_connect 3 23669 NULL
116309 +cx18_read_23699 cx18_read 3 23699 NULL
116310 +at_get_23708 at_get 0 23708 NULL
116311 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
116312 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
116313 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
116314 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
116315 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
116316 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
116317 +map_write_23795 map_write 3 23795 NULL
116318 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
116319 +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
116320 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
116321 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
116322 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 0-4-3 23829 NULL
116323 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
116324 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
116325 +p54_init_common_23850 p54_init_common 1 23850 NULL
116326 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
116327 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
116328 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
116329 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL nohasharray
116330 +writeback_single_inode_23881 writeback_single_inode 0 23881 &nouveau_clock_create__23881
116331 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
116332 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
116333 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
116334 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
116335 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
116336 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
116337 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
116338 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
116339 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
116340 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
116341 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
116342 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
116343 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
116344 +give_pages_24021 give_pages 3 24021 NULL
116345 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
116346 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
116347 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
116348 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
116349 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
116350 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
116351 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
116352 +lov_brw_24122 lov_brw 4 24122 NULL
116353 +mpu401_read_24126 mpu401_read 3-0 24126 NULL
116354 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
116355 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL nohasharray
116356 +xfs_btree_increment_24139 xfs_btree_increment 0 24139 &irnet_ctrl_write_24139
116357 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
116358 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
116359 +adu_read_24177 adu_read 3 24177 NULL
116360 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
116361 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
116362 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
116363 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
116364 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
116365 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
116366 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
116367 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
116368 +xfs_bmap_rtalloc_24237 xfs_bmap_rtalloc 0 24237 NULL
116369 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
116370 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
116371 +thin_status_24278 thin_status 5 24278 NULL
116372 +msg_size_24288 msg_size 0 24288 NULL
116373 +gserial_connect_24302 gserial_connect 0 24302 NULL
116374 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
116375 +reserve_metadata_bytes_24313 reserve_metadata_bytes 0 24313 NULL
116376 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
116377 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
116378 +prepare_pages_24349 prepare_pages 0 24349 NULL
116379 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
116380 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
116381 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
116382 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
116383 +igetword_24373 igetword 0 24373 NULL nohasharray
116384 +break_deleg_24373 break_deleg 0 24373 &igetword_24373
116385 +max_io_len_24384 max_io_len 0-1 24384 NULL
116386 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
116387 +xfs_bmapi_read_24392 xfs_bmapi_read 0 24392 NULL
116388 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
116389 +getxattr_24398 getxattr 4 24398 NULL nohasharray
116390 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
116391 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
116392 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
116393 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
116394 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
116395 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
116396 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
116397 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
116398 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
116399 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
116400 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
116401 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
116402 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
116403 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
116404 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
116405 +pd_video_read_24510 pd_video_read 3 24510 NULL
116406 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
116407 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
116408 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
116409 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
116410 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
116411 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
116412 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
116413 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
116414 +SyS_poll_24620 SyS_poll 2 24620 NULL
116415 +context_alloc_24645 context_alloc 3 24645 NULL
116416 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
116417 +xfs_log_commit_cil_24653 xfs_log_commit_cil 0 24653 NULL
116418 +btrfs_check_data_free_space_24692 btrfs_check_data_free_space 0 24692 NULL
116419 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
116420 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
116421 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
116422 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
116423 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
116424 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
116425 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
116426 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
116427 +cache_read_24790 cache_read 3 24790 NULL
116428 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
116429 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
116430 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
116431 +net2272_read_24825 net2272_read 0 24825 NULL
116432 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
116433 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
116434 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
116435 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
116436 +queues_read_24877 queues_read 3 24877 NULL
116437 +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
116438 +xfs_qm_dqattach_24898 xfs_qm_dqattach 0 24898 NULL
116439 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
116440 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
116441 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
116442 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
116443 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
116444 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
116445 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
116446 +slot_get_24999 slot_get 0 24999 NULL
116447 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
116448 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
116449 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
116450 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
116451 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
116452 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
116453 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
116454 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
116455 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
116456 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
116457 +blkg_path_25099 blkg_path 3 25099 NULL
116458 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
116459 +gfs2_quota_check_25130 gfs2_quota_check 0 25130 NULL
116460 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
116461 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
116462 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
116463 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
116464 +stripe_status_25259 stripe_status 5 25259 NULL
116465 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
116466 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
116467 +vfs_writev_25278 vfs_writev 3 25278 NULL
116468 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
116469 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
116470 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
116471 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
116472 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
116473 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
116474 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
116475 +xfs_ialloc_pagi_init_25411 xfs_ialloc_pagi_init 0 25411 NULL
116476 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
116477 +xfs_qm_dqtobp_25448 xfs_qm_dqtobp 0 25448 NULL
116478 +generic_file_buffered_write_25464 generic_file_buffered_write 4-0-7 25464 NULL
116479 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
116480 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
116481 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
116482 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
116483 +xfs_alloc_fix_freelist_25514 xfs_alloc_fix_freelist 0 25514 NULL
116484 +sb_permission_25523 sb_permission 0 25523 NULL
116485 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
116486 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
116487 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
116488 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
116489 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
116490 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
116491 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
116492 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
116493 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
116494 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
116495 +__direct_map_25647 __direct_map 5-6 25647 NULL
116496 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
116497 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
116498 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
116499 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
116500 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
116501 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
116502 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
116503 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
116504 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
116505 +sg_read_25799 sg_read 3 25799 NULL
116506 +xfs_alloc_ag_vextent_exact_25810 xfs_alloc_ag_vextent_exact 0 25810 NULL
116507 +system_enable_read_25815 system_enable_read 3 25815 NULL
116508 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
116509 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
116510 +parport_read_25855 parport_read 0 25855 NULL
116511 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
116512 +key_attr_size_25865 key_attr_size 0 25865 NULL
116513 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
116514 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
116515 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
116516 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
116517 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
116518 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
116519 +rcname_read_25919 rcname_read 3 25919 NULL
116520 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
116521 +key_flags_read_25931 key_flags_read 3 25931 NULL
116522 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
116523 +flush_25957 flush 2 25957 NULL
116524 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
116525 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
116526 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
116527 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
116528 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
116529 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
116530 +btrfs_wait_ordered_range_26086 btrfs_wait_ordered_range 0 26086 NULL
116531 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
116532 +read_sb_page_26119 read_sb_page 5 26119 NULL
116533 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
116534 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
116535 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
116536 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
116537 +disk_devt_26180 disk_devt 0 26180 NULL
116538 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
116539 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
116540 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
116541 +mce_write_26201 mce_write 3 26201 NULL
116542 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
116543 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
116544 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
116545 +simple_setattr_26234 simple_setattr 0 26234 NULL
116546 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
116547 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
116548 +apei_resources_request_26279 apei_resources_request 0 26279 NULL
116549 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
116550 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
116551 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
116552 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
116553 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
116554 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
116555 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
116556 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
116557 +ntty_write_26404 ntty_write 3 26404 NULL
116558 +firmware_store_26408 firmware_store 4 26408 NULL
116559 +pagemap_read_26441 pagemap_read 3 26441 NULL
116560 +tower_read_26461 tower_read 3 26461 NULL nohasharray
116561 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
116562 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
116563 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
116564 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
116565 +read_vmcore_26501 read_vmcore 3 26501 NULL
116566 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
116567 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
116568 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
116569 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
116570 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
116571 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
116572 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
116573 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
116574 +xfs_rtcheck_range_26614 xfs_rtcheck_range 0 26614 NULL
116575 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
116576 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
116577 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
116578 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
116579 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
116580 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
116581 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
116582 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
116583 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
116584 +bos_desc_26752 bos_desc 0 26752 NULL
116585 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
116586 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
116587 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
116588 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
116589 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
116590 +smk_write_load_26829 smk_write_load 3 26829 NULL
116591 +xfs_alloc_pagf_init_26834 xfs_alloc_pagf_init 0 26834 NULL
116592 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
116593 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
116594 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
116595 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
116596 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
116597 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
116598 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
116599 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
116600 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
116601 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
116602 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
116603 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
116604 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
116605 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
116606 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
116607 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
116608 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
116609 +xfs_filestream_associate_27030 xfs_filestream_associate 0 27030 NULL
116610 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
116611 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
116612 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
116613 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
116614 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
116615 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
116616 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
116617 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
116618 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
116619 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
116620 +pms_capture_27142 pms_capture 4 27142 NULL
116621 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
116622 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
116623 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
116624 +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
116625 +write_kmem_27225 write_kmem 3 27225 NULL
116626 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
116627 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
116628 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
116629 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
116630 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
116631 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
116632 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
116633 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
116634 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
116635 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
116636 +seq_read_27411 seq_read 3 27411 NULL
116637 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
116638 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
116639 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0 27422 NULL
116640 +cypress_write_27423 cypress_write 4 27423 NULL
116641 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
116642 +xfs_btree_lookup_get_block_27448 xfs_btree_lookup_get_block 0 27448 NULL
116643 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
116644 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
116645 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
116646 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
116647 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
116648 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
116649 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
116650 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
116651 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
116652 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
116653 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
116654 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
116655 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
116656 +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
116657 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642 nohasharray
116658 +xfs_alloc_vextent_27642 xfs_alloc_vextent 0 27642 &ocfs2_direct_IO_27642
116659 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
116660 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
116661 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
116662 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
116663 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
116664 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
116665 +evm_write_key_27715 evm_write_key 3 27715 NULL
116666 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
116667 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
116668 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
116669 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
116670 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
116671 +SyS_readv_27804 SyS_readv 3 27804 NULL
116672 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
116673 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
116674 +init_header_complete_27833 init_header_complete 0 27833 NULL
116675 +read_profile_27859 read_profile 3 27859 NULL
116676 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
116677 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
116678 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
116679 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
116680 +bio_next_split_27961 bio_next_split 2 27961 NULL nohasharray
116681 +tracing_clock_write_27961 tracing_clock_write 3 27961 &bio_next_split_27961
116682 +security_path_chown_27966 security_path_chown 0 27966 NULL
116683 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
116684 +device_register_27972 device_register 0 27972 NULL nohasharray
116685 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
116686 +xfs_alloc_fixup_trees_27975 xfs_alloc_fixup_trees 0 27975 NULL
116687 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL nohasharray
116688 +__kernfs_setattr_27977 __kernfs_setattr 0 27977 &pci_enable_device_flags_27977
116689 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
116690 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
116691 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
116692 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
116693 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
116694 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
116695 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
116696 +pool_status_28055 pool_status 5 28055 NULL
116697 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
116698 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
116699 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
116700 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
116701 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
116702 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
116703 +memblock_virt_alloc_from_nopanic_28146 memblock_virt_alloc_from_nopanic 1 28146 NULL
116704 +video_read_28148 video_read 3 28148 NULL
116705 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
116706 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
116707 +vread_28173 vread 0-3 28173 NULL
116708 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
116709 +counter_free_res_28187 counter_free_res 5 28187 NULL
116710 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
116711 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
116712 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
116713 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
116714 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
116715 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
116716 +usemap_size_28281 usemap_size 0 28281 NULL
116717 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
116718 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
116719 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
116720 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
116721 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
116722 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
116723 +security_inode_link_28327 security_inode_link 0 28327 NULL
116724 +generic_write_checks_28329 generic_write_checks 0 28329 NULL
116725 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
116726 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
116727 +snapshot_write_28351 snapshot_write 3 28351 NULL
116728 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
116729 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
116730 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
116731 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
116732 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
116733 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
116734 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
116735 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
116736 +xfs_rtfind_back_28450 xfs_rtfind_back 0 28450 NULL
116737 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
116738 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
116739 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
116740 +__filemap_fdatawrite_28485 __filemap_fdatawrite 0 28485 NULL
116741 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
116742 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
116743 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
116744 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
116745 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
116746 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
116747 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
116748 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
116749 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
116750 +gfs2_meta_indirect_buffer_28573 gfs2_meta_indirect_buffer 0 28573 NULL
116751 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
116752 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
116753 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
116754 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
116755 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
116756 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
116757 +xfs_bmap_finish_28644 xfs_bmap_finish 0 28644 NULL
116758 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
116759 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
116760 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
116761 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
116762 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
116763 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
116764 +spi_execute_28736 spi_execute 5 28736 NULL
116765 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
116766 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
116767 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
116768 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
116769 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
116770 +sel_write_member_28800 sel_write_member 3 28800 NULL
116771 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
116772 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
116773 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
116774 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
116775 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
116776 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
116777 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
116778 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
116779 +push_rx_28939 push_rx 3 28939 NULL
116780 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
116781 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
116782 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
116783 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
116784 +xfs_alloc_update_28982 xfs_alloc_update 0 28982 NULL
116785 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
116786 +bin_uuid_28999 bin_uuid 3 28999 NULL
116787 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
116788 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
116789 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
116790 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
116791 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
116792 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
116793 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
116794 +xfs_alloc_ag_vextent_small_29084 xfs_alloc_ag_vextent_small 0 29084 NULL
116795 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
116796 +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
116797 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
116798 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
116799 +snprintf_29125 snprintf 0 29125 NULL
116800 +iov_shorten_29130 iov_shorten 0 29130 NULL
116801 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
116802 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
116803 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
116804 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
116805 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
116806 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
116807 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
116808 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
116809 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
116810 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
116811 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
116812 +xfs_bmap_btree_to_extents_29297 xfs_bmap_btree_to_extents 0 29297 NULL
116813 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
116814 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
116815 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
116816 +xfs_bmbt_change_owner_29325 xfs_bmbt_change_owner 0 29325 NULL
116817 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
116818 +tun_put_user_29337 tun_put_user 5 29337 NULL
116819 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
116820 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
116821 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
116822 +mempool_create_29437 mempool_create 1 29437 NULL
116823 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
116824 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
116825 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
116826 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
116827 +do_register_entry_29478 do_register_entry 4 29478 NULL
116828 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
116829 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
116830 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
116831 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
116832 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
116833 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
116834 +add_to_page_cache_lru_29534 add_to_page_cache_lru 0 29534 NULL
116835 +ftrace_write_29551 ftrace_write 3 29551 NULL
116836 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
116837 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
116838 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
116839 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
116840 +security_path_chmod_29578 security_path_chmod 0 29578 NULL
116841 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
116842 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
116843 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
116844 +slots_per_page_29601 slots_per_page 0 29601 NULL
116845 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
116846 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
116847 +gfs2_alloc_blocks_29630 gfs2_alloc_blocks 0 29630 NULL
116848 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
116849 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
116850 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
116851 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
116852 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
116853 +probes_write_29711 probes_write 3 29711 NULL
116854 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
116855 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
116856 +std_nic_write_29752 std_nic_write 3 29752 NULL
116857 +dbAlloc_29794 dbAlloc 0 29794 NULL
116858 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
116859 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
116860 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
116861 +count_partial_29850 count_partial 0 29850 NULL
116862 +xfs_rtfind_forw_29866 xfs_rtfind_forw 0 29866 NULL
116863 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
116864 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
116865 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
116866 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
116867 +xfs_alloc_read_agf_29893 xfs_alloc_read_agf 0 29893 NULL
116868 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
116869 +write_file_queue_29922 write_file_queue 3 29922 NULL
116870 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
116871 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
116872 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
116873 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
116874 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
116875 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
116876 +drp_wmove_30043 drp_wmove 4 30043 NULL
116877 +mem_cgroup_charge_common_30047 mem_cgroup_charge_common 0 30047 NULL
116878 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
116879 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
116880 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
116881 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
116882 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
116883 +xfs_iget_cache_miss_30115 xfs_iget_cache_miss 0 30115 NULL
116884 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
116885 +recv_stream_30138 recv_stream 4 30138 NULL
116886 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
116887 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
116888 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
116889 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
116890 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
116891 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
116892 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
116893 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
116894 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
116895 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
116896 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
116897 +shmem_unuse_inode_30263 shmem_unuse_inode 0 30263 NULL
116898 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
116899 +try_break_deleg_30271 try_break_deleg 0 30271 NULL nohasharray
116900 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 &try_break_deleg_30271
116901 +compat_readv_30273 compat_readv 3 30273 NULL
116902 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
116903 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
116904 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
116905 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
116906 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
116907 +i8254_read_30330 i8254_read 0 30330 NULL
116908 +resource_from_user_30341 resource_from_user 3 30341 NULL
116909 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
116910 +gfs2_trans_begin_30359 gfs2_trans_begin 0 30359 NULL
116911 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
116912 +pagecache_write_begin_30364 pagecache_write_begin 0 30364 NULL
116913 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
116914 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
116915 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
116916 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
116917 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
116918 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
116919 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
116920 +enable_write_30456 enable_write 3 30456 NULL
116921 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
116922 +urandom_read_30462 urandom_read 3 30462 NULL
116923 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
116924 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
116925 +adu_write_30487 adu_write 3 30487 NULL
116926 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
116927 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
116928 +__send_duplicate_bios_30498 __send_duplicate_bios 4 30498 NULL
116929 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
116930 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
116931 +set_config_30526 set_config 0 30526 NULL nohasharray
116932 +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
116933 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
116934 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
116935 +set_le_30581 set_le 4 30581 NULL
116936 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
116937 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
116938 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
116939 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
116940 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
116941 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
116942 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
116943 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
116944 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
116945 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL nohasharray
116946 +xfs_bmap_add_extent_unwritten_real_30701 xfs_bmap_add_extent_unwritten_real 0 30701 &dccp_setsockopt_ccid_30701
116947 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
116948 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
116949 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
116950 +snapshot_status_30744 snapshot_status 5 30744 NULL
116951 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
116952 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
116953 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
116954 +xlog_grant_head_wait_30829 xlog_grant_head_wait 0 30829 NULL
116955 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
116956 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
116957 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
116958 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
116959 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
116960 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
116961 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
116962 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
116963 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
116964 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
116965 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
116966 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
116967 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
116968 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
116969 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
116970 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
116971 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
116972 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
116973 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
116974 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
116975 +depth_read_31112 depth_read 3 31112 NULL
116976 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
116977 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
116978 +size_inside_page_31141 size_inside_page 0 31141 NULL
116979 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
116980 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
116981 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
116982 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
116983 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
116984 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
116985 +__read_reg_31216 __read_reg 0 31216 NULL
116986 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
116987 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
116988 +cyy_readb_31240 cyy_readb 0 31240 NULL
116989 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
116990 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
116991 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
116992 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
116993 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
116994 +command_file_write_31318 command_file_write 3 31318 NULL
116995 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
116996 +radix_tree_insert_31336 radix_tree_insert 0 31336 NULL
116997 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
116998 +outlen_write_31358 outlen_write 3 31358 NULL
116999 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
117000 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
117001 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
117002 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
117003 +inb_31388 inb 0 31388 NULL
117004 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
117005 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
117006 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
117007 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
117008 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
117009 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
117010 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
117011 +alg_setkey_31485 alg_setkey 3 31485 NULL
117012 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
117013 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
117014 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
117015 +hidraw_write_31536 hidraw_write 3 31536 NULL
117016 +usbvision_read_31555 usbvision_read 3 31555 NULL
117017 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
117018 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
117019 +osst_write_31581 osst_write 3 31581 NULL
117020 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
117021 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
117022 +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
117023 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL nohasharray
117024 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 &arvo_sysfs_read_31617
117025 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
117026 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
117027 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
117028 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
117029 +__lgread_31668 __lgread 4 31668 NULL
117030 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
117031 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
117032 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
117033 +gfs2_dir_check_31711 gfs2_dir_check 0 31711 NULL
117034 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
117035 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
117036 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
117037 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
117038 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
117039 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
117040 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
117041 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
117042 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
117043 +osync_buffers_list_31789 osync_buffers_list 0 31789 NULL
117044 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
117045 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
117046 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
117047 +data_write_31805 data_write 3 31805 NULL
117048 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
117049 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
117050 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
117051 +clone_bio_31854 clone_bio 4-3 31854 NULL
117052 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
117053 +foreach_descriptor_31873 foreach_descriptor 0 31873 NULL
117054 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
117055 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
117056 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
117057 +xattr_permission_31907 xattr_permission 0 31907 NULL
117058 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
117059 +new_dir_31919 new_dir 3 31919 NULL
117060 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
117061 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
117062 +read_mem_31942 read_mem 3 31942 NULL nohasharray
117063 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
117064 +vb2_write_31948 vb2_write 3 31948 NULL
117065 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
117066 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
117067 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
117068 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
117069 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
117070 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
117071 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
117072 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
117073 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
117074 +calc_hmac_32010 calc_hmac 3 32010 NULL
117075 +aead_len_32021 aead_len 0 32021 NULL
117076 +stk_read_32038 stk_read 3 32038 NULL
117077 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
117078 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
117079 +xfs_buf_iowait_32068 xfs_buf_iowait 0 32068 NULL
117080 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
117081 +bio_alloc_32095 bio_alloc 2 32095 NULL
117082 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
117083 +disk_status_32120 disk_status 4 32120 NULL
117084 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
117085 +venus_link_32165 venus_link 5 32165 NULL
117086 +do_writepages_32173 do_writepages 0 32173 NULL
117087 +del_ptr_32197 del_ptr 4 32197 NULL
117088 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
117089 +__mem_cgroup_try_charge_swapin_32204 __mem_cgroup_try_charge_swapin 0 32204 NULL
117090 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
117091 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
117092 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
117093 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
117094 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
117095 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
117096 +SyS_select_32319 SyS_select 1 32319 NULL
117097 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
117098 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
117099 +xfs_bmap_extsize_align_32338 xfs_bmap_extsize_align 0 32338 NULL
117100 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
117101 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
117102 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
117103 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
117104 +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
117105 +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
117106 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
117107 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
117108 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
117109 +xfs_alloc_put_freelist_32437 xfs_alloc_put_freelist 0 32437 NULL
117110 +cache_status_32462 cache_status 5 32462 NULL
117111 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
117112 +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
117113 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
117114 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
117115 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
117116 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
117117 +disconnect_32521 disconnect 4 32521 NULL
117118 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
117119 +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL
117120 +ilo_read_32531 ilo_read 3 32531 NULL
117121 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
117122 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
117123 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
117124 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
117125 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
117126 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
117127 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
117128 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
117129 +xfs_bmap_last_offset_32614 xfs_bmap_last_offset 0 32614 NULL
117130 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
117131 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
117132 +kvmalloc_32646 kvmalloc 1 32646 NULL
117133 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
117134 +generic_readlink_32654 generic_readlink 3 32654 NULL
117135 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
117136 +apei_res_add_32674 apei_res_add 0 32674 NULL
117137 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
117138 +xfs_filestream_new_ag_32711 xfs_filestream_new_ag 0 32711 NULL
117139 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
117140 +xfs_bmbt_update_32713 xfs_bmbt_update 0 32713 NULL
117141 +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
117142 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
117143 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
117144 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
117145 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
117146 +xfs_trans_read_buf_32795 xfs_trans_read_buf 0 32795 NULL
117147 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
117148 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
117149 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
117150 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
117151 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
117152 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
117153 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
117154 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
117155 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
117156 +xfs_log_reserve_32959 xfs_log_reserve 0 32959 NULL
117157 +compat_filldir_32999 compat_filldir 3 32999 NULL
117158 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
117159 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
117160 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
117161 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
117162 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
117163 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
117164 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
117165 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
117166 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
117167 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
117168 +alloc_tio_33077 alloc_tio 3 33077 NULL
117169 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
117170 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
117171 +notify_change_33143 notify_change 0 33143 NULL
117172 +SyS_poll_33152 SyS_poll 2 33152 NULL
117173 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
117174 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
117175 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
117176 +pp_read_33210 pp_read 3 33210 NULL
117177 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
117178 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
117179 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
117180 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
117181 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
117182 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
117183 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
117184 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
117185 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
117186 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
117187 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
117188 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
117189 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
117190 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
117191 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
117192 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
117193 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
117194 +filemap_fdatawrite_33415 filemap_fdatawrite 0 33415 NULL
117195 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
117196 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
117197 +message_stats_list_33440 message_stats_list 5 33440 NULL
117198 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
117199 +create_entry_33479 create_entry 2 33479 NULL
117200 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
117201 +res_counter_read_33499 res_counter_read 4 33499 NULL
117202 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
117203 +fb_read_33506 fb_read 3 33506 NULL
117204 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
117205 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
117206 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
117207 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
117208 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
117209 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
117210 +count_subheaders_33591 count_subheaders 0 33591 NULL
117211 +scsi_execute_33596 scsi_execute 5 33596 NULL
117212 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
117213 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
117214 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
117215 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
117216 +xfs_btree_check_sblock_33618 xfs_btree_check_sblock 0 33618 NULL
117217 +stride_page_count_33641 stride_page_count 2 33641 NULL
117218 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
117219 +inw_p_33668 inw_p 0 33668 NULL
117220 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
117221 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
117222 +submit_one_bio_33683 submit_one_bio 0 33683 NULL
117223 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
117224 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
117225 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
117226 +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
117227 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
117228 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
117229 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
117230 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
117231 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
117232 +hashtab_create_33769 hashtab_create 3 33769 NULL
117233 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
117234 +filter_write_33819 filter_write 3 33819 NULL
117235 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
117236 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
117237 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
117238 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
117239 +get_user_pages_33908 get_user_pages 0 33908 NULL
117240 +sg_nents_33909 sg_nents 0 33909 NULL
117241 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
117242 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
117243 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
117244 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
117245 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
117246 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
117247 +btrfs_delalloc_reserve_metadata_33963 btrfs_delalloc_reserve_metadata 0 33963 NULL
117248 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
117249 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
117250 +ppp_write_34034 ppp_write 3 34034 NULL
117251 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
117252 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
117253 +xfs_dialloc_34078 xfs_dialloc 0 34078 NULL
117254 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
117255 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
117256 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
117257 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
117258 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
117259 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
117260 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
117261 +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
117262 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
117263 +xfs_bmapi_write_34208 xfs_bmapi_write 0 34208 NULL
117264 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
117265 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
117266 +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
117267 +device_private_init_34279 device_private_init 0 34279 NULL
117268 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
117269 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
117270 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
117271 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
117272 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
117273 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
117274 +ea_read_34378 ea_read 0 34378 NULL
117275 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
117276 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
117277 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
117278 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
117279 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
117280 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
117281 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
117282 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
117283 +__extent_read_full_page_34437 __extent_read_full_page 0 34437 NULL
117284 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
117285 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
117286 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
117287 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
117288 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
117289 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
117290 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
117291 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
117292 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
117293 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
117294 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
117295 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
117296 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
117297 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
117298 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
117299 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
117300 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
117301 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
117302 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
117303 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
117304 +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
117305 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
117306 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
117307 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
117308 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
117309 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
117310 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
117311 +port_print_34704 port_print 3 34704 NULL
117312 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
117313 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
117314 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
117315 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
117316 +bootmode_store_34762 bootmode_store 4 34762 NULL
117317 +device_add_34766 device_add 0 34766 NULL
117318 +xfs_iget_cache_hit_34767 xfs_iget_cache_hit 0 34767 NULL
117319 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
117320 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
117321 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
117322 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
117323 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
117324 +file_page_index_34820 file_page_index 0-2 34820 NULL
117325 +bio_segments_34832 bio_segments 0 34832 NULL
117326 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
117327 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
117328 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
117329 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
117330 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
117331 +msg_print_text_34889 msg_print_text 0 34889 NULL
117332 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
117333 +gfs2_glock_wait_34913 gfs2_glock_wait 0 34913 NULL
117334 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
117335 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
117336 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
117337 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
117338 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
117339 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
117340 +i2c_transfer_34958 i2c_transfer 0 34958 NULL
117341 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
117342 +print_message_35000 print_message 0 35000 NULL
117343 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
117344 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
117345 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
117346 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
117347 +xfs_rtallocate_extent_35052 xfs_rtallocate_extent 0 35052 NULL
117348 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
117349 +ntfs_attr_extend_initialized_35084 ntfs_attr_extend_initialized 0 35084 NULL
117350 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
117351 +capi_write_35104 capi_write 3 35104 NULL nohasharray
117352 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
117353 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
117354 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
117355 +message_stats_print_35158 message_stats_print 6 35158 NULL
117356 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
117357 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
117358 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
117359 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
117360 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
117361 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
117362 +set_fd_set_35249 set_fd_set 1 35249 NULL
117363 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
117364 +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
117365 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
117366 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
117367 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
117368 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
117369 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
117370 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3-0 35311 NULL nohasharray
117371 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
117372 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
117373 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
117374 +xfs_btree_check_lblock_35333 xfs_btree_check_lblock 0 35333 NULL
117375 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
117376 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
117377 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
117378 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
117379 +read_kmem_35372 read_kmem 3 35372 NULL
117380 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
117381 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
117382 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
117383 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
117384 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
117385 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
117386 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
117387 +async_setkey_35521 async_setkey 3 35521 NULL
117388 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
117389 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
117390 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
117391 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
117392 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
117393 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
117394 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
117395 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
117396 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
117397 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
117398 +kernel_readv_35617 kernel_readv 3 35617 NULL
117399 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
117400 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
117401 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
117402 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
117403 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
117404 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
117405 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
117406 +md_super_write_35703 md_super_write 4 35703 NULL
117407 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
117408 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
117409 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
117410 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
117411 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
117412 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
117413 +fls64_35862 fls64 0 35862 NULL
117414 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
117415 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
117416 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
117417 +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
117418 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
117419 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
117420 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
117421 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
117422 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
117423 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
117424 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
117425 +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
117426 +acl_alloc_35979 acl_alloc 1 35979 NULL
117427 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
117428 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
117429 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
117430 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
117431 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
117432 +account_shadowed_36048 account_shadowed 2 36048 NULL
117433 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
117434 +write_emulate_36065 write_emulate 2-4 36065 NULL
117435 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
117436 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
117437 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
117438 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
117439 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
117440 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
117441 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
117442 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
117443 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
117444 +twl_set_36154 twl_set 2 36154 NULL
117445 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
117446 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
117447 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
117448 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
117449 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
117450 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
117451 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
117452 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
117453 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
117454 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
117455 +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
117456 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
117457 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
117458 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
117459 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
117460 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
117461 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
117462 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
117463 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
117464 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
117465 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
117466 +lc_create_36332 lc_create 4 36332 NULL
117467 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
117468 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
117469 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
117470 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
117471 +to_sector_36361 to_sector 0-1 36361 NULL
117472 +tunables_read_36385 tunables_read 3 36385 NULL
117473 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
117474 +sierra_write_36402 sierra_write 4 36402 NULL
117475 +qdsb_get_36409 qdsb_get 0 36409 NULL
117476 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
117477 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
117478 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
117479 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
117480 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
117481 +lock_and_cleanup_extent_if_need_36480 lock_and_cleanup_extent_if_need 0 36480 NULL
117482 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
117483 +ip6_append_data_36490 ip6_append_data 4 36490 NULL nohasharray
117484 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
117485 +cmd_loop_36491 cmd_loop 0 36491 NULL
117486 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
117487 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
117488 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
117489 +get_param_l_36518 get_param_l 0 36518 NULL
117490 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
117491 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
117492 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
117493 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
117494 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
117495 +__erst_read_36579 __erst_read 0 36579 NULL
117496 +put_cmsg_36589 put_cmsg 4 36589 NULL
117497 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
117498 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
117499 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
117500 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
117501 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
117502 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
117503 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
117504 +xillybus_read_36678 xillybus_read 3 36678 NULL
117505 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
117506 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
117507 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
117508 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
117509 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
117510 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
117511 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
117512 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
117513 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
117514 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
117515 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
117516 +cm_write_36858 cm_write 3 36858 NULL
117517 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
117518 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
117519 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
117520 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
117521 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
117522 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
117523 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
117524 +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
117525 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
117526 +xfs_btree_check_sptr_36984 xfs_btree_check_sptr 0 36984 NULL
117527 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
117528 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
117529 +setxattr_37006 setxattr 4 37006 NULL
117530 +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
117531 +command_file_read_37038 command_file_read 3 37038 NULL
117532 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
117533 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
117534 +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
117535 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
117536 +parse_command_37079 parse_command 2 37079 NULL
117537 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
117538 +tun_get_user_37094 tun_get_user 5 37094 NULL
117539 +xlog_grant_head_check_37116 xlog_grant_head_check 0 37116 NULL
117540 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
117541 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
117542 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
117543 +msg_word_37164 msg_word 0 37164 NULL
117544 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
117545 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
117546 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
117547 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
117548 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
117549 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
117550 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
117551 +__do_replace_37227 __do_replace 5 37227 NULL
117552 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
117553 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
117554 +xfs_reclaim_inode_37257 xfs_reclaim_inode 0 37257 NULL
117555 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
117556 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
117557 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
117558 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
117559 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
117560 +send_msg_37323 send_msg 4 37323 NULL
117561 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
117562 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
117563 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
117564 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
117565 +xfs_iomap_write_allocate_37336 xfs_iomap_write_allocate 0 37336 NULL
117566 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
117567 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
117568 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
117569 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
117570 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
117571 +fru_alloc_37442 fru_alloc 1 37442 NULL
117572 +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
117573 +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
117574 +xfs_btree_dec_cursor_37452 xfs_btree_dec_cursor 0 37452 NULL
117575 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
117576 +get_est_timing_37484 get_est_timing 0 37484 NULL
117577 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
117578 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
117579 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
117580 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
117581 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
117582 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
117583 +hdr_size_37536 hdr_size 0 37536 NULL
117584 +extent_map_end_37550 extent_map_end 0 37550 NULL
117585 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
117586 +fat_cont_expand_37552 fat_cont_expand 0 37552 NULL
117587 +ioat_chansts_37558 ioat_chansts 0 37558 NULL
117588 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
117589 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
117590 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
117591 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
117592 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
117593 +may_delete_37656 may_delete 0 37656 NULL
117594 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
117595 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
117596 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
117597 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
117598 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
117599 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
117600 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
117601 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
117602 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
117603 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
117604 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
117605 +xfs_read_agf_37749 xfs_read_agf 0 37749 NULL
117606 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
117607 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
117608 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
117609 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
117610 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
117611 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
117612 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
117613 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
117614 +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
117615 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
117616 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
117617 +set_registers_37883 set_registers 4 37883 NULL
117618 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
117619 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
117620 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
117621 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
117622 +write_file_bool_37957 write_file_bool 3 37957 NULL
117623 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
117624 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
117625 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
117626 +vfs_readv_38011 vfs_readv 3 38011 NULL
117627 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
117628 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
117629 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
117630 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
117631 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
117632 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
117633 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
117634 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
117635 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
117636 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
117637 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
117638 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
117639 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
117640 +ep0_read_38095 ep0_read 3 38095 NULL
117641 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
117642 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
117643 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
117644 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
117645 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
117646 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
117647 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
117648 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
117649 +cdev_add_38176 cdev_add 2-3 38176 NULL
117650 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
117651 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
117652 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL nohasharray
117653 +xfs_rtallocate_range_38223 xfs_rtallocate_range 0 38223 &osd_req_list_partition_collections_38223
117654 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
117655 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
117656 +xfs_qm_dqrepair_38262 xfs_qm_dqrepair 0 38262 NULL
117657 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
117658 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
117659 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
117660 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
117661 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
117662 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
117663 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
117664 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
117665 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
117666 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
117667 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
117668 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
117669 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
117670 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
117671 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
117672 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
117673 +dev_names_read_38509 dev_names_read 3 38509 NULL
117674 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
117675 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
117676 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
117677 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
117678 +kuc_len_38557 kuc_len 0-1 38557 NULL
117679 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
117680 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
117681 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
117682 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
117683 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
117684 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
117685 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
117686 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
117687 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
117688 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
117689 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
117690 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
117691 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
117692 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
117693 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
117694 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
117695 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
117696 +udf_readpages_38761 udf_readpages 4 38761 NULL
117697 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
117698 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
117699 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
117700 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
117701 +err_decode_38804 err_decode 2 38804 NULL
117702 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
117703 +direct_entry_38836 direct_entry 3 38836 NULL
117704 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
117705 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
117706 +interfaces_38859 interfaces 2 38859 NULL
117707 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
117708 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
117709 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
117710 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
117711 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
117712 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
117713 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
117714 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
117715 +get_nodes_39012 get_nodes 3 39012 NULL
117716 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
117717 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
117718 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
117719 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
117720 +ReadHFC_39104 ReadHFC 0 39104 NULL
117721 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
117722 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
117723 +ea_foreach_39133 ea_foreach 0 39133 NULL
117724 +generic_permission_39150 generic_permission 0 39150 NULL
117725 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
117726 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
117727 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
117728 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
117729 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
117730 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
117731 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
117732 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
117733 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
117734 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
117735 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
117736 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
117737 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
117738 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
117739 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
117740 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
117741 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
117742 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
117743 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
117744 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
117745 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
117746 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
117747 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
117748 +__send_to_port_39386 __send_to_port 3 39386 NULL
117749 +xfs_btree_dup_cursor_39394 xfs_btree_dup_cursor 0 39394 NULL
117750 +gfs2_internal_read_39413 gfs2_internal_read 0 39413 NULL
117751 +user_power_read_39414 user_power_read 3 39414 NULL
117752 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
117753 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
117754 +apei_resources_add_39470 apei_resources_add 0 39470 NULL
117755 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
117756 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
117757 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
117758 +int_proc_write_39542 int_proc_write 3 39542 NULL
117759 +pp_write_39554 pp_write 3 39554 NULL
117760 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
117761 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
117762 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
117763 +ext_depth_39607 ext_depth 0 39607 NULL
117764 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
117765 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
117766 +sdio_readb_39618 sdio_readb 0 39618 NULL
117767 +prepare_uptodate_page_39622 prepare_uptodate_page 0 39622 NULL
117768 +set_dev_class_39645 set_dev_class 4 39645 NULL
117769 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
117770 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
117771 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
117772 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
117773 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
117774 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
117775 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
117776 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
117777 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
117778 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
117779 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
117780 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
117781 +pkt_add_39897 pkt_add 3 39897 NULL
117782 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
117783 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
117784 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
117785 +__mnt_want_write_file_39917 __mnt_want_write_file 0 39917 NULL
117786 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
117787 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
117788 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
117789 +__spi_async_39932 __spi_async 0 39932 NULL
117790 +__get_order_39935 __get_order 0 39935 NULL
117791 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
117792 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
117793 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
117794 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
117795 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
117796 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
117797 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
117798 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
117799 +server_name2svname_39998 server_name2svname 4 39998 NULL
117800 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
117801 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
117802 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
117803 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
117804 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
117805 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
117806 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
117807 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
117808 +xfs_rtbuf_get_40107 xfs_rtbuf_get 0 40107 NULL
117809 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
117810 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
117811 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
117812 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
117813 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
117814 +pt_write_40159 pt_write 3 40159 NULL
117815 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
117816 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
117817 +allocate_probes_40204 allocate_probes 1 40204 NULL
117818 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
117819 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
117820 +osst_read_40237 osst_read 3 40237 NULL
117821 +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
117822 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
117823 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
117824 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
117825 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
117826 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
117827 +SyS_bind_40303 SyS_bind 3 40303 NULL
117828 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
117829 +mmio_read_40348 mmio_read 4 40348 NULL
117830 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
117831 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
117832 +get_chars_40373 get_chars 3 40373 NULL
117833 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
117834 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
117835 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
117836 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
117837 +SyS_writev_40467 SyS_writev 3 40467 NULL
117838 +SyS_select_40473 SyS_select 1 40473 NULL
117839 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
117840 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
117841 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
117842 +xfs_iread_extents_40510 xfs_iread_extents 0 40510 NULL
117843 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
117844 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
117845 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
117846 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
117847 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
117848 +b1_get_byte_40597 b1_get_byte 0 40597 NULL
117849 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
117850 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
117851 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
117852 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
117853 +fops_read_40672 fops_read 3 40672 NULL
117854 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
117855 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
117856 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
117857 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
117858 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
117859 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
117860 +set_extent_bit_40719 set_extent_bit 0 40719 NULL
117861 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
117862 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
117863 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
117864 +card_send_command_40757 card_send_command 3 40757 NULL
117865 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
117866 +pg_write_40766 pg_write 3 40766 NULL
117867 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
117868 +show_list_40775 show_list 3-0 40775 NULL
117869 +kfifo_out_copy_r_40784 kfifo_out_copy_r 3-0 40784 NULL
117870 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
117871 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
117872 +add_action_40811 add_action 4 40811 NULL
117873 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
117874 +SyS_mbind_40828 SyS_mbind 5 40828 NULL
117875 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
117876 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
117877 +read_file_queue_40895 read_file_queue 3 40895 NULL
117878 +waiters_read_40902 waiters_read 3 40902 NULL
117879 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
117880 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
117881 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
117882 +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
117883 +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
117884 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
117885 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
117886 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
117887 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
117888 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
117889 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
117890 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
117891 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
117892 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
117893 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
117894 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
117895 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
117896 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
117897 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
117898 +dma_attach_41094 dma_attach 5-6 41094 NULL
117899 +provide_user_output_41105 provide_user_output 3 41105 NULL
117900 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
117901 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
117902 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
117903 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
117904 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
117905 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
117906 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
117907 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
117908 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
117909 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
117910 +erst_read_41260 erst_read 0 41260 NULL
117911 +alloc_context_41283 alloc_context 1 41283 NULL
117912 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
117913 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
117914 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
117915 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
117916 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
117917 +kmp_init_41373 kmp_init 2 41373 NULL
117918 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
117919 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
117920 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
117921 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
117922 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
117923 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
117924 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4-0 41442 NULL
117925 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
117926 +se_io_cb_41461 se_io_cb 3 41461 NULL
117927 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
117928 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
117929 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
117930 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
117931 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
117932 +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
117933 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
117934 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
117935 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
117936 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
117937 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
117938 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
117939 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
117940 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
117941 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
117942 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
117943 +vga_io_r_41609 vga_io_r 0 41609 NULL
117944 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
117945 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
117946 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
117947 +a2mp_send_41615 a2mp_send 4 41615 NULL
117948 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
117949 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
117950 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
117951 +get_std_timing_41654 get_std_timing 0 41654 NULL
117952 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
117953 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
117954 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
117955 +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
117956 +fillonedir_41746 fillonedir 3 41746 NULL
117957 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
117958 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
117959 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
117960 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
117961 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
117962 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
117963 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
117964 +xfs_rtget_summary_41864 xfs_rtget_summary 0 41864 NULL
117965 +pci_map_single_41869 pci_map_single 0 41869 NULL
117966 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
117967 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
117968 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
117969 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
117970 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
117971 +read_gssp_41947 read_gssp 3 41947 NULL
117972 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
117973 +portnames_read_41958 portnames_read 3 41958 NULL
117974 +dst_mtu_41969 dst_mtu 0 41969 NULL
117975 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
117976 +xfs_qm_dqalloc_41985 xfs_qm_dqalloc 0 41985 NULL
117977 +pool_allocate_42012 pool_allocate 3 42012 NULL
117978 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
117979 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
117980 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
117981 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
117982 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
117983 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
117984 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
117985 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
117986 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
117987 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
117988 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
117989 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
117990 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
117991 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
117992 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
117993 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
117994 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
117995 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
117996 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
117997 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
117998 +xfs_rtfree_range_42244 xfs_rtfree_range 0 42244 NULL
117999 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
118000 +find_last_bit_42260 find_last_bit 0 42260 NULL
118001 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
118002 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
118003 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
118004 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
118005 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
118006 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
118007 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
118008 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
118009 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
118010 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
118011 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
118012 +tipc_send_42374 tipc_send 3 42374 NULL
118013 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
118014 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
118015 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
118016 +krng_get_random_42420 krng_get_random 3 42420 NULL
118017 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
118018 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
118019 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
118020 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
118021 +kuc_free_42455 kuc_free 2 42455 NULL
118022 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
118023 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
118024 +bypass_write_42498 bypass_write 3 42498 NULL
118025 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
118026 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
118027 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
118028 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
118029 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
118030 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
118031 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
118032 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
118033 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
118034 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
118035 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
118036 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
118037 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
118038 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
118039 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
118040 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
118041 +vb2_read_42703 vb2_read 3 42703 NULL
118042 +read_status_42722 read_status 0 42722 NULL
118043 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
118044 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
118045 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
118046 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
118047 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
118048 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
118049 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
118050 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
118051 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
118052 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
118053 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
118054 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
118055 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
118056 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
118057 +set_arg_42824 set_arg 3 42824 NULL
118058 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
118059 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
118060 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
118061 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
118062 +hd_end_request_42904 hd_end_request 2 42904 NULL
118063 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
118064 +xfs_bmapi_allocate_42938 xfs_bmapi_allocate 0 42938 NULL
118065 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
118066 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
118067 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
118068 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
118069 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
118070 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
118071 +xfs_da_read_buf_43008 xfs_da_read_buf 0 43008 NULL
118072 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
118073 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
118074 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
118075 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
118076 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
118077 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
118078 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
118079 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
118080 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
118081 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
118082 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
118083 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
118084 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
118085 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
118086 +uio_write_43202 uio_write 3 43202 NULL
118087 +iso_callback_43208 iso_callback 3 43208 NULL
118088 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
118089 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
118090 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
118091 +inode_init_always_43225 inode_init_always 0 43225 NULL
118092 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
118093 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
118094 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
118095 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
118096 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
118097 +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
118098 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
118099 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
118100 +mmu_set_spte_43327 mmu_set_spte 6-7 43327 NULL
118101 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
118102 +xfs_log_regrant_43350 xfs_log_regrant 0 43350 NULL
118103 +gfs2_rgrp_bh_get_43375 gfs2_rgrp_bh_get 0 43375 NULL
118104 +xfs_btree_new_iroot_43392 xfs_btree_new_iroot 0 43392 NULL
118105 +xenfb_write_43412 xenfb_write 3 43412 NULL
118106 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
118107 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
118108 +cifs_writev_43437 cifs_writev 4 43437 NULL
118109 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
118110 +usb_string_43443 usb_string 0 43443 NULL nohasharray
118111 +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
118112 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
118113 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
118114 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
118115 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
118116 +do_readlink_43518 do_readlink 2 43518 NULL
118117 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
118118 +read_events_43534 read_events 3 43534 NULL
118119 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
118120 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
118121 +request_resource_43548 request_resource 0 43548 NULL
118122 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
118123 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
118124 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
118125 +proc_read_43614 proc_read 3 43614 NULL
118126 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
118127 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
118128 +random_write_43656 random_write 3 43656 NULL
118129 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
118130 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
118131 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
118132 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
118133 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
118134 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
118135 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
118136 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
118137 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
118138 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
118139 +xfs_alloc_lookup_eq_43775 xfs_alloc_lookup_eq 0 43775 NULL
118140 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
118141 +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
118142 +xfs_trans_reserve_quota_bydquots_43797 xfs_trans_reserve_quota_bydquots 0 43797 NULL
118143 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
118144 +_xfs_filestream_update_ag_43824 _xfs_filestream_update_ag 0 43824 NULL
118145 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
118146 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
118147 +read_flush_43851 read_flush 3 43851 NULL
118148 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
118149 +SendString_43928 SendString 3 43928 NULL
118150 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
118151 +xfs_trans_dqresv_43960 xfs_trans_dqresv 0 43960 NULL
118152 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
118153 +nla_reserve_43984 nla_reserve 3 43984 NULL
118154 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
118155 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
118156 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
118157 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
118158 +ulist_add_43994 ulist_add 0 43994 NULL
118159 +emit_flags_44006 emit_flags 4-3 44006 NULL
118160 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
118161 +fru_strlen_44046 fru_strlen 0 44046 NULL
118162 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
118163 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
118164 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL nohasharray
118165 +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 &pci_msix_vec_count_44093
118166 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
118167 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
118168 +file_remove_suid_44122 file_remove_suid 0 44122 NULL nohasharray
118169 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 &file_remove_suid_44122
118170 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
118171 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
118172 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
118173 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
118174 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
118175 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
118176 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
118177 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
118178 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
118179 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
118180 +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
118181 +device_create_file_44285 device_create_file 0 44285 NULL
118182 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
118183 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
118184 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
118185 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
118186 +rs_init_44327 rs_init 1 44327 NULL
118187 +radix_tree_maybe_preload_44346 radix_tree_maybe_preload 0 44346 NULL
118188 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
118189 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
118190 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
118191 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
118192 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
118193 +strlcpy_44400 strlcpy 3 44400 NULL
118194 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
118195 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
118196 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
118197 +xfs_mod_incore_sb_44439 xfs_mod_incore_sb 0 44439 NULL
118198 +write_file_debug_44476 write_file_debug 3 44476 NULL
118199 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
118200 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
118201 +bio_advance_44496 bio_advance 2 44496 NULL
118202 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
118203 +ac_register_board_44504 ac_register_board 3 44504 NULL
118204 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
118205 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
118206 +spidev_write_44510 spidev_write 3 44510 NULL
118207 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
118208 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
118209 +comm_write_44537 comm_write 3 44537 NULL
118210 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
118211 +btrfs_set_extent_delalloc_44587 btrfs_set_extent_delalloc 0 44587 NULL
118212 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
118213 +xfs_bmapi_delay_44630 xfs_bmapi_delay 0 44630 NULL
118214 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
118215 +mpi_resize_44674 mpi_resize 2 44674 NULL
118216 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
118217 +ts_read_44687 ts_read 3 44687 NULL
118218 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
118219 +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
118220 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
118221 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
118222 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
118223 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
118224 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
118225 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
118226 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
118227 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
118228 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
118229 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
118230 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
118231 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
118232 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
118233 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
118234 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
118235 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
118236 +sisusb_write_44834 sisusb_write 3 44834 NULL
118237 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
118238 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
118239 +copydesc_user_44855 copydesc_user 3 44855 NULL
118240 +set_advertising_44870 set_advertising 4 44870 NULL
118241 +init_rs_44873 init_rs 1 44873 NULL
118242 +skb_availroom_44883 skb_availroom 0 44883 NULL
118243 +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
118244 +do_tty_write_44896 do_tty_write 5 44896 NULL
118245 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
118246 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
118247 +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
118248 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
118249 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
118250 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
118251 +sel_write_user_45060 sel_write_user 3 45060 NULL
118252 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
118253 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
118254 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
118255 +usbdev_read_45114 usbdev_read 3 45114 NULL
118256 +send_to_tty_45141 send_to_tty 3 45141 NULL
118257 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
118258 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
118259 +device_write_45156 device_write 3 45156 NULL nohasharray
118260 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
118261 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
118262 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
118263 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
118264 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
118265 +__radix_tree_preload_45197 __radix_tree_preload 0 45197 NULL
118266 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
118267 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
118268 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
118269 +event_enable_write_45238 event_enable_write 3 45238 NULL
118270 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
118271 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
118272 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
118273 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
118274 +xfs_alert_fsblock_zero_45304 xfs_alert_fsblock_zero 0 45304 NULL
118275 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
118276 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
118277 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
118278 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
118279 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
118280 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
118281 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
118282 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
118283 +__node_remap_45458 __node_remap 4 45458 NULL
118284 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
118285 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
118286 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
118287 +xfs_btree_block_change_owner_45476 xfs_btree_block_change_owner 0 45476 NULL
118288 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
118289 +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
118290 +copy_macs_45534 copy_macs 4 45534 NULL
118291 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
118292 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
118293 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
118294 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
118295 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
118296 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
118297 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
118298 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
118299 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
118300 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
118301 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
118302 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
118303 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
118304 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
118305 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
118306 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL nohasharray
118307 +task_cgroup_path_45734 task_cgroup_path 3 45734 &snd_cs46xx_io_read_45734
118308 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
118309 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
118310 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
118311 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
118312 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
118313 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
118314 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
118315 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
118316 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
118317 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
118318 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
118319 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
118320 +insert_state_45848 insert_state 0 45848 NULL
118321 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
118322 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
118323 +isdn_write_45863 isdn_write 3 45863 NULL
118324 +tpm_config_in_45880 tpm_config_in 0 45880 NULL
118325 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
118326 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
118327 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
118328 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
118329 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
118330 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
118331 +alloc_mr_45935 alloc_mr 1 45935 NULL
118332 +copy_to_45969 copy_to 3 45969 NULL
118333 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
118334 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
118335 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
118336 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
118337 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
118338 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
118339 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
118340 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
118341 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
118342 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
118343 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
118344 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
118345 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
118346 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
118347 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
118348 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
118349 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
118350 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
118351 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
118352 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
118353 +fq_resize_46195 fq_resize 2 46195 NULL
118354 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
118355 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
118356 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
118357 +dsp_write_46218 dsp_write 2 46218 NULL
118358 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
118359 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
118360 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
118361 +ReadReg_46277 ReadReg 0 46277 NULL
118362 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
118363 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
118364 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
118365 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
118366 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
118367 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
118368 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
118369 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
118370 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
118371 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
118372 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
118373 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
118374 +filldir64_46469 filldir64 3 46469 NULL
118375 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
118376 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
118377 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
118378 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
118379 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
118380 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
118381 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
118382 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
118383 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
118384 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
118385 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
118386 +__kfifo_out_r_46623 __kfifo_out_r 3-0 46623 NULL
118387 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
118388 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
118389 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
118390 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
118391 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
118392 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
118393 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
118394 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
118395 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
118396 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
118397 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
118398 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
118399 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
118400 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
118401 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
118402 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
118403 +readreg_46845 readreg 0 46845 NULL
118404 +spi_async_46857 spi_async 0 46857 NULL
118405 +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
118406 +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
118407 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
118408 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
118409 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
118410 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
118411 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
118412 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
118413 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
118414 +fb_write_46924 fb_write 3 46924 NULL
118415 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
118416 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL nohasharray
118417 +ntfs_truncate_46953 ntfs_truncate 0 46953 &qla4xxx_post_aen_work_46953
118418 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
118419 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
118420 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
118421 +strlcat_46985 strlcat 3 46985 NULL
118422 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
118423 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
118424 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
118425 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
118426 +fs_path_len_47060 fs_path_len 0 47060 NULL
118427 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
118428 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
118429 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
118430 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
118431 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
118432 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
118433 +mousedev_read_47123 mousedev_read 3 47123 NULL
118434 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
118435 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
118436 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
118437 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
118438 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
118439 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
118440 +xfs_btree_get_buf_block_47197 xfs_btree_get_buf_block 0 47197 NULL
118441 +options_write_47243 options_write 3 47243 NULL
118442 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
118443 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
118444 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
118445 +vsnprintf_47291 vsnprintf 0 47291 NULL
118446 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
118447 +xfs_trans_reserve_quota_nblks_47313 xfs_trans_reserve_quota_nblks 0 47313 NULL
118448 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
118449 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
118450 +gfs2_replay_read_block_47357 gfs2_replay_read_block 0 47357 NULL
118451 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
118452 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
118453 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
118454 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
118455 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
118456 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
118457 +nametbl_list_47391 nametbl_list 2 47391 NULL
118458 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
118459 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
118460 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
118461 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
118462 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
118463 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
118464 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
118465 +newpart_47485 newpart 6-4 47485 NULL
118466 +core_sys_select_47494 core_sys_select 1 47494 NULL
118467 +unlink_simple_47506 unlink_simple 3 47506 NULL
118468 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
118469 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
118470 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
118471 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
118472 +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
118473 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
118474 +read_ldt_47570 read_ldt 2 47570 NULL
118475 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
118476 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
118477 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
118478 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
118479 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
118480 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
118481 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
118482 +get_size_47644 get_size 1-2 47644 NULL
118483 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
118484 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
118485 +save_microcode_47717 save_microcode 3 47717 NULL
118486 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
118487 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
118488 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
118489 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
118490 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
118491 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
118492 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
118493 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
118494 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
118495 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
118496 +lov_packmd_47810 lov_packmd 0 47810 NULL
118497 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
118498 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
118499 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
118500 +vhci_read_47878 vhci_read 3 47878 NULL
118501 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
118502 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
118503 +comedi_write_47926 comedi_write 3 47926 NULL
118504 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
118505 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
118506 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
118507 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
118508 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
118509 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
118510 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
118511 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
118512 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
118513 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
118514 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
118515 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
118516 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
118517 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
118518 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
118519 +disc_write_48070 disc_write 3 48070 NULL
118520 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
118521 +xfs_read_agi_48100 xfs_read_agi 0 48100 NULL
118522 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
118523 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
118524 +set_discoverable_48141 set_discoverable 4 48141 NULL
118525 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
118526 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
118527 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
118528 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
118529 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
118530 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
118531 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
118532 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
118533 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
118534 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
118535 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
118536 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
118537 +read_file_recv_48232 read_file_recv 3 48232 NULL
118538 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
118539 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
118540 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
118541 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
118542 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
118543 +trace_options_write_48275 trace_options_write 3 48275 NULL
118544 +send_set_info_48288 send_set_info 7 48288 NULL
118545 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
118546 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
118547 +hash_setkey_48310 hash_setkey 3 48310 NULL
118548 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
118549 +skb_add_data_48363 skb_add_data 3 48363 NULL
118550 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
118551 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
118552 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
118553 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
118554 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
118555 +print_filtered_48442 print_filtered 2-0 48442 NULL
118556 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
118557 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
118558 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
118559 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
118560 +send_control_msg_48498 send_control_msg 6 48498 NULL
118561 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
118562 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
118563 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
118564 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
118565 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
118566 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
118567 +llog_data_len_48607 llog_data_len 1 48607 NULL
118568 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
118569 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
118570 +mtd_read_48655 mtd_read 0 48655 NULL
118571 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
118572 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
118573 +security_inode_setattr_48689 security_inode_setattr 0 48689 NULL
118574 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
118575 +altera_drscan_48698 altera_drscan 2 48698 NULL
118576 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
118577 +recv_msg_48709 recv_msg 4 48709 NULL
118578 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
118579 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
118580 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
118581 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
118582 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
118583 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
118584 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
118585 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
118586 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
118587 +azx_get_position_48841 azx_get_position 0 48841 NULL
118588 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
118589 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
118590 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
118591 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
118592 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
118593 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
118594 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
118595 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
118596 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
118597 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
118598 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
118599 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
118600 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
118601 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
118602 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
118603 +xfs_trans_commit_48982 xfs_trans_commit 0 48982 NULL
118604 +gfs2_dir_add_48987 gfs2_dir_add 0 48987 NULL
118605 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
118606 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
118607 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
118608 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
118609 +transient_status_49027 transient_status 4 49027 NULL
118610 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
118611 +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
118612 +scsi_register_49094 scsi_register 2 49094 NULL
118613 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
118614 +gfs2_diradd_alloc_required_49105 gfs2_diradd_alloc_required 0 49105 NULL
118615 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
118616 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
118617 +pt_read_49136 pt_read 3 49136 NULL
118618 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
118619 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
118620 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
118621 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
118622 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
118623 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
118624 +print_queue_49191 print_queue 4-0 49191 NULL
118625 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
118626 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
118627 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
118628 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
118629 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
118630 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
118631 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
118632 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
118633 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
118634 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
118635 +uio_read_49300 uio_read 3 49300 NULL
118636 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
118637 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
118638 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
118639 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
118640 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
118641 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
118642 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
118643 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
118644 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
118645 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
118646 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
118647 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
118648 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
118649 +xfs_iformat_local_49472 xfs_iformat_local 4-0 49472 NULL
118650 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
118651 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
118652 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
118653 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
118654 +smk_write_access_49561 smk_write_access 3 49561 NULL
118655 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
118656 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
118657 +readfifo_49583 readfifo 1 49583 NULL
118658 +gfs2_quota_lock_49587 gfs2_quota_lock 0 49587 NULL
118659 +evm_inode_setattr_49594 evm_inode_setattr 0 49594 NULL
118660 +tap_write_49595 tap_write 3 49595 NULL
118661 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
118662 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
118663 +heap_init_49617 heap_init 2 49617 NULL
118664 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
118665 +port_fops_read_49626 port_fops_read 3 49626 NULL
118666 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
118667 +xfs_ialloc_get_rec_49648 xfs_ialloc_get_rec 0 49648 NULL
118668 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
118669 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
118670 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
118671 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
118672 +write_pool_49718 write_pool 3 49718 NULL
118673 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
118674 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
118675 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
118676 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
118677 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
118678 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
118679 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
118680 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
118681 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
118682 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
118683 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
118684 +add_uuid_49831 add_uuid 4 49831 NULL
118685 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
118686 +twl4030_write_49846 twl4030_write 2 49846 NULL
118687 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
118688 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
118689 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
118690 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
118691 +osc_brw_49896 osc_brw 4 49896 NULL
118692 +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
118693 +xfs_ialloc_ag_alloc_49960 xfs_ialloc_ag_alloc 0 49960 NULL
118694 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
118695 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
118696 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
118697 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
118698 +xfs_ialloc_inode_init_50015 xfs_ialloc_inode_init 0 50015 NULL
118699 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
118700 +isdn_read_50021 isdn_read 3 50021 NULL
118701 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
118702 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
118703 +ioread8_50049 ioread8 0 50049 NULL
118704 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
118705 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
118706 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
118707 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
118708 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
118709 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
118710 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
118711 +read_file_slot_50111 read_file_slot 3 50111 NULL
118712 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
118713 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
118714 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
118715 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
118716 +xfs_bwrite_50154 xfs_bwrite 0 50154 NULL
118717 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
118718 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
118719 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
118720 +odev_update_50169 odev_update 2 50169 NULL
118721 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
118722 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
118723 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
118724 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
118725 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
118726 +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
118727 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
118728 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
118729 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
118730 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
118731 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
118732 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
118733 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
118734 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
118735 +do_launder_page_50329 do_launder_page 0 50329 NULL
118736 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
118737 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
118738 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
118739 +tpm_read_50344 tpm_read 3 50344 NULL
118740 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
118741 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
118742 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
118743 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
118744 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
118745 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
118746 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
118747 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
118748 +xfs_alloc_update_counters_50441 xfs_alloc_update_counters 0 50441 NULL
118749 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
118750 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
118751 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
118752 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
118753 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
118754 +xfs_iformat_extents_50486 xfs_iformat_extents 0 50486 NULL
118755 +gfs2_block_map_50492 gfs2_block_map 0 50492 NULL
118756 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
118757 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
118758 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
118759 +bh_get_50543 bh_get 0 50543 NULL
118760 +gfs2_meta_inode_buffer_50544 gfs2_meta_inode_buffer 0 50544 NULL
118761 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
118762 +fat_readpages_50582 fat_readpages 4 50582 NULL
118763 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
118764 +xillybus_write_50605 xillybus_write 3 50605 NULL
118765 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
118766 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
118767 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
118768 +gfs2_unstuff_dinode_50644 gfs2_unstuff_dinode 0 50644 NULL
118769 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
118770 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
118771 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
118772 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
118773 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
118774 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
118775 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
118776 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
118777 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
118778 +bio_alloc_map_data_50782 bio_alloc_map_data 2 50782 NULL
118779 +tpm_write_50798 tpm_write 3 50798 NULL
118780 +tun_do_read_50800 tun_do_read 4 50800 NULL
118781 +write_flush_50803 write_flush 3 50803 NULL
118782 +dvb_play_50814 dvb_play 3 50814 NULL
118783 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
118784 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
118785 +SetArea_50835 SetArea 4 50835 NULL
118786 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
118787 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
118788 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
118789 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
118790 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
118791 +xfs_alloc_get_freelist_50906 xfs_alloc_get_freelist 0 50906 NULL
118792 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
118793 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
118794 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
118795 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
118796 +show_device_status_50947 show_device_status 0 50947 NULL
118797 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
118798 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
118799 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
118800 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
118801 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
118802 +timeout_write_50991 timeout_write 3 50991 NULL
118803 +proc_write_51003 proc_write 3 51003 NULL
118804 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
118805 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
118806 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
118807 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
118808 +dump_midi_51040 dump_midi 3 51040 NULL
118809 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
118810 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
118811 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
118812 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
118813 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
118814 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
118815 +ti_recv_51110 ti_recv 3 51110 NULL
118816 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
118817 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
118818 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
118819 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
118820 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
118821 +drm_property_create_51239 drm_property_create 4 51239 NULL
118822 +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
118823 +st_read_51251 st_read 3 51251 NULL
118824 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
118825 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
118826 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
118827 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
118828 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
118829 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
118830 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
118831 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
118832 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
118833 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
118834 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
118835 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
118836 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
118837 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
118838 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
118839 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
118840 +xfs_mod_incore_sb_unlocked_51439 xfs_mod_incore_sb_unlocked 0 51439 NULL
118841 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
118842 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
118843 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
118844 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
118845 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
118846 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
118847 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
118848 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
118849 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
118850 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
118851 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
118852 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
118853 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
118854 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
118855 +xfs_iformat_btree_51651 xfs_iformat_btree 0 51651 NULL
118856 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
118857 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
118858 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
118859 +sel_write_access_51704 sel_write_access 3 51704 NULL
118860 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
118861 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
118862 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
118863 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
118864 +cm4040_read_51732 cm4040_read 3 51732 NULL
118865 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
118866 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
118867 +if_write_51756 if_write 3 51756 NULL
118868 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
118869 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
118870 +ioread32_51847 ioread32 0 51847 NULL nohasharray
118871 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
118872 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
118873 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
118874 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
118875 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
118876 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
118877 +user_read_51881 user_read 3 51881 NULL
118878 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
118879 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
118880 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
118881 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
118882 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
118883 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
118884 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
118885 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
118886 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
118887 +get_zone_51981 get_zone 0-1 51981 NULL
118888 +cifs_strict_writev_51984 cifs_strict_writev 4 51984 NULL
118889 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
118890 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
118891 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
118892 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
118893 +rdmalt_52022 rdmalt 0 52022 NULL
118894 +override_release_52032 override_release 2 52032 NULL
118895 +end_port_52042 end_port 0 52042 NULL
118896 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
118897 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
118898 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
118899 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
118900 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
118901 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
118902 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
118903 +ulist_add_merge_52096 ulist_add_merge 0 52096 NULL
118904 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
118905 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
118906 +retry_count_read_52129 retry_count_read 3 52129 NULL
118907 +xfs_btree_change_owner_52137 xfs_btree_change_owner 0 52137 NULL
118908 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
118909 +sub_alloc_52140 sub_alloc 0 52140 NULL
118910 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
118911 +htable_size_52148 htable_size 0-1 52148 NULL
118912 +gfs2_rs_alloc_52152 gfs2_rs_alloc 0 52152 NULL
118913 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
118914 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
118915 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
118916 +print_prefix_52176 print_prefix 0 52176 NULL
118917 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
118918 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
118919 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
118920 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
118921 +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 0 52243 &fuse_request_alloc_52243
118922 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
118923 +shrink_slab_52261 shrink_slab 2 52261 NULL
118924 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
118925 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
118926 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
118927 +read_file_reset_52310 read_file_reset 3 52310 NULL
118928 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
118929 +hwflags_read_52318 hwflags_read 3 52318 NULL
118930 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
118931 +hur_len_52339 hur_len 0 52339 NULL
118932 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL nohasharray
118933 +cap_inode_killpriv_52362 cap_inode_killpriv 0 52362 &bytes_to_frames_52362
118934 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
118935 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
118936 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
118937 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
118938 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
118939 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
118940 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
118941 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
118942 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
118943 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
118944 +delay_status_52431 delay_status 5 52431 NULL
118945 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
118946 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
118947 +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
118948 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
118949 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
118950 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
118951 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
118952 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
118953 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
118954 +xfs_alloc_get_rec_52502 xfs_alloc_get_rec 0 52502 NULL
118955 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
118956 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
118957 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
118958 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
118959 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
118960 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
118961 +ntfs_prepare_pages_for_non_resident_write_52556 ntfs_prepare_pages_for_non_resident_write 0 52556 NULL
118962 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
118963 +kernfs_setattr_52583 kernfs_setattr 0 52583 NULL
118964 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
118965 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
118966 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
118967 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
118968 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
118969 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
118970 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
118971 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
118972 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
118973 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
118974 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
118975 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
118976 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
118977 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
118978 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
118979 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
118980 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
118981 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
118982 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
118983 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
118984 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
118985 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
118986 +twlreg_write_52880 twlreg_write 3 52880 NULL
118987 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
118988 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
118989 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
118990 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
118991 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
118992 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
118993 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
118994 +send_packet_52960 send_packet 4 52960 NULL
118995 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
118996 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
118997 +num_node_state_52989 num_node_state 0 52989 NULL
118998 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
118999 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
119000 +xfs_rtfree_extent_53024 xfs_rtfree_extent 0 53024 NULL
119001 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
119002 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
119003 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
119004 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
119005 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
119006 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
119007 +verity_status_53120 verity_status 5 53120 NULL
119008 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
119009 +inode_newsize_ok_53140 inode_newsize_ok 0 53140 NULL nohasharray
119010 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 &inode_newsize_ok_53140
119011 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
119012 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
119013 +find_good_lh_53183 find_good_lh 0 53183 NULL
119014 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
119015 +xfs_btree_updkey_53195 xfs_btree_updkey 0 53195 NULL
119016 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
119017 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
119018 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5-0 53258 NULL
119019 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
119020 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
119021 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
119022 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
119023 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
119024 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
119025 +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
119026 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
119027 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
119028 +xfs_imap_53389 xfs_imap 0 53389 NULL
119029 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
119030 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
119031 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
119032 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
119033 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
119034 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
119035 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
119036 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
119037 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
119038 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
119039 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
119040 +check_acl_53512 check_acl 0 53512 NULL
119041 +ll_xattr_cache_update_53515 ll_xattr_cache_update 4 53515 NULL
119042 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
119043 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
119044 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
119045 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
119046 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
119047 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
119048 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
119049 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
119050 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
119051 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
119052 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
119053 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
119054 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
119055 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
119056 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
119057 +wdm_write_53735 wdm_write 3 53735 NULL
119058 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
119059 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
119060 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
119061 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
119062 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
119063 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
119064 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
119065 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
119066 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
119067 +setup_data_read_53822 setup_data_read 3 53822 NULL
119068 +pms_read_53873 pms_read 3 53873 NULL
119069 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
119070 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
119071 +posix_acl_chmod_53904 posix_acl_chmod 0 53904 NULL
119072 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
119073 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
119074 +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
119075 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
119076 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
119077 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
119078 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
119079 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
119080 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
119081 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
119082 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
119083 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
119084 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
119085 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
119086 +_malloc_54077 _malloc 1 54077 NULL
119087 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
119088 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
119089 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2-0 54103 &altera_set_ir_pre_54103
119090 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
119091 +strn_len_54122 strn_len 0 54122 NULL
119092 +isku_receive_54130 isku_receive 4 54130 NULL
119093 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
119094 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
119095 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
119096 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
119097 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
119098 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
119099 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
119100 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
119101 +reada_add_block_54247 reada_add_block 2 54247 NULL
119102 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
119103 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
119104 +audio_write_54261 audio_write 4 54261 NULL nohasharray
119105 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
119106 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
119107 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
119108 +tipc_multicast_54285 tipc_multicast 4 54285 NULL
119109 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
119110 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
119111 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
119112 +sprintf_54306 sprintf 0 54306 NULL
119113 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
119114 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
119115 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
119116 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
119117 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
119118 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
119119 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
119120 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
119121 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
119122 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
119123 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
119124 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
119125 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
119126 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
119127 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
119128 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
119129 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
119130 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
119131 +viacam_read_54526 viacam_read 3 54526 NULL
119132 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
119133 +setsockopt_54539 setsockopt 5 54539 NULL
119134 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
119135 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
119136 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
119137 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
119138 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
119139 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
119140 +port_fops_write_54627 port_fops_write 3 54627 NULL
119141 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
119142 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
119143 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
119144 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
119145 +bus_add_device_54665 bus_add_device 0 54665 NULL
119146 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
119147 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
119148 +evm_read_key_54674 evm_read_key 3 54674 NULL
119149 +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
119150 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
119151 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
119152 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
119153 +kzalloc_54740 kzalloc 1 54740 NULL
119154 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
119155 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
119156 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
119157 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
119158 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
119159 +xfs_rtallocate_extent_block_54791 xfs_rtallocate_extent_block 0 54791 NULL
119160 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
119161 +nfsd_write_54809 nfsd_write 6 54809 NULL
119162 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
119163 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
119164 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
119165 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
119166 +generic_perform_write_54832 generic_perform_write 3-0 54832 NULL
119167 +write_rio_54837 write_rio 3 54837 NULL
119168 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
119169 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
119170 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
119171 +printer_read_54851 printer_read 3 54851 NULL
119172 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
119173 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
119174 +xfs_alloc_read_agfl_54879 xfs_alloc_read_agfl 0 54879 NULL
119175 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
119176 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
119177 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
119178 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
119179 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
119180 +add_port_54941 add_port 2 54941 NULL
119181 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
119182 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
119183 +c4_add_card_54968 c4_add_card 3 54968 NULL
119184 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
119185 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
119186 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
119187 +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
119188 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
119189 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
119190 +read_dma_55086 read_dma 3 55086 NULL
119191 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
119192 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
119193 +filldir_55137 filldir 3 55137 NULL
119194 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
119195 +xfs_check_agi_freecount_55149 xfs_check_agi_freecount 0 55149 NULL nohasharray
119196 +npages_to_npools_55149 npages_to_npools 0-1 55149 &xfs_check_agi_freecount_55149
119197 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
119198 +xfs_icsb_modify_counters_55156 xfs_icsb_modify_counters 0 55156 NULL
119199 +gfs2_ri_update_55185 gfs2_ri_update 0 55185 NULL
119200 +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
119201 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
119202 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
119203 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
119204 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
119205 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
119206 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
119207 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
119208 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
119209 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
119210 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
119211 +persistent_ram_new_55286 persistent_ram_new 2-1 55286 NULL
119212 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
119213 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
119214 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
119215 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
119216 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
119217 +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
119218 +vme_user_read_55338 vme_user_read 3 55338 NULL
119219 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
119220 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
119221 +tipc_send2name_55373 tipc_send2name 5 55373 NULL
119222 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
119223 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
119224 +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
119225 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
119226 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
119227 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
119228 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
119229 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
119230 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
119231 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
119232 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
119233 +xfs_btree_split_55515 xfs_btree_split 0 55515 NULL
119234 +ea_get_55522 ea_get 3-0 55522 NULL
119235 +buffer_size_55534 buffer_size 0 55534 NULL
119236 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
119237 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
119238 +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
119239 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
119240 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
119241 +add_partition_55588 add_partition 2 55588 NULL
119242 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
119243 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
119244 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
119245 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
119246 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
119247 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
119248 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
119249 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
119250 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
119251 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
119252 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
119253 +get_info_55681 get_info 3 55681 NULL
119254 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
119255 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
119256 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
119257 +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
119258 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
119259 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
119260 +set_local_name_55757 set_local_name 4 55757 NULL
119261 +strlen_55778 strlen 0 55778 NULL
119262 +set_spte_55783 set_spte 4-5 55783 NULL
119263 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
119264 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
119265 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
119266 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
119267 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
119268 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
119269 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
119270 +hsc_write_55875 hsc_write 3 55875 NULL
119271 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
119272 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
119273 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
119274 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
119275 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
119276 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
119277 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
119278 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
119279 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
119280 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
119281 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
119282 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
119283 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
119284 +usb_ocp_write_56047 usb_ocp_write 4 56047 NULL
119285 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
119286 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
119287 +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
119288 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
119289 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
119290 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
119291 +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
119292 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
119293 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
119294 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
119295 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
119296 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
119297 +fd_copyin_56247 fd_copyin 3 56247 NULL
119298 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
119299 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
119300 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
119301 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
119302 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
119303 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
119304 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
119305 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
119306 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
119307 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
119308 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
119309 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
119310 +qd_get_56365 qd_get 0 56365 NULL
119311 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
119312 +dev_read_56369 dev_read 3 56369 NULL
119313 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
119314 +write_gssp_56404 write_gssp 3 56404 NULL
119315 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
119316 +do_get_write_access_56410 do_get_write_access 0 56410 NULL
119317 +store_msg_56417 store_msg 3 56417 NULL
119318 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
119319 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
119320 +fl_create_56435 fl_create 5 56435 NULL
119321 +gnttab_map_56439 gnttab_map 2 56439 NULL
119322 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
119323 +set_connectable_56458 set_connectable 4 56458 NULL
119324 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
119325 +putused_user_56467 putused_user 3 56467 NULL
119326 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
119327 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
119328 +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
119329 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
119330 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
119331 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
119332 +init_map_ip_56508 init_map_ip 5 56508 NULL
119333 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3-0-2 56512 NULL
119334 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
119335 +ip_options_get_56538 ip_options_get 4 56538 NULL
119336 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
119337 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
119338 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
119339 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
119340 +event_filter_write_56609 event_filter_write 3 56609 NULL
119341 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
119342 +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
119343 +gather_array_56641 gather_array 3 56641 NULL
119344 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
119345 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
119346 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
119347 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
119348 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
119349 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
119350 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
119351 +xfs_btree_decrement_56718 xfs_btree_decrement 0 56718 NULL
119352 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
119353 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
119354 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
119355 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
119356 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
119357 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
119358 +do_syslog_56807 do_syslog 3 56807 NULL
119359 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
119360 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
119361 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
119362 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
119363 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
119364 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
119365 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
119366 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
119367 +strcspn_56913 strcspn 0 56913 NULL
119368 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
119369 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
119370 +xfs_alloc_ag_vextent_56943 xfs_alloc_ag_vextent 0 56943 NULL
119371 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
119372 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
119373 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
119374 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
119375 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
119376 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
119377 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
119378 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
119379 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
119380 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
119381 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
119382 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
119383 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
119384 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
119385 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
119386 +altera_get_note_57099 altera_get_note 6 57099 NULL
119387 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
119388 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
119389 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
119390 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
119391 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
119392 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
119393 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
119394 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
119395 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
119396 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
119397 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
119398 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
119399 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
119400 +dma_fifo_alloc_57236 dma_fifo_alloc 5-3-2 57236 NULL
119401 +flush_space_57241 flush_space 0 57241 NULL
119402 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
119403 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
119404 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
119405 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
119406 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
119407 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
119408 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
119409 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
119410 +xfs_iread_57313 xfs_iread 0 57313 NULL nohasharray
119411 +write_file_regval_57313 write_file_regval 3 57313 &xfs_iread_57313
119412 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
119413 +usblp_read_57342 usblp_read 3 57342 NULL
119414 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
119415 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
119416 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
119417 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
119418 +read_file_blob_57406 read_file_blob 3 57406 NULL
119419 +enclosure_register_57412 enclosure_register 3 57412 NULL
119420 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
119421 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
119422 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
119423 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
119424 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
119425 +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
119426 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
119427 +skb_headlen_57501 skb_headlen 0 57501 NULL
119428 +copy_in_user_57502 copy_in_user 3 57502 NULL
119429 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL nohasharray
119430 +gfs2_quota_hold_57505 gfs2_quota_hold 0 57505 &ckhdid_printf_57505
119431 +init_tag_map_57515 init_tag_map 3 57515 NULL
119432 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
119433 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
119434 +cmm_read_57520 cmm_read 3 57520 NULL
119435 +inode_permission_57531 inode_permission 0 57531 NULL
119436 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
119437 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
119438 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
119439 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
119440 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
119441 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
119442 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
119443 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
119444 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
119445 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
119446 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
119447 +mem_read_57631 mem_read 3 57631 NULL
119448 +xfs_alloc_ag_vextent_near_57653 xfs_alloc_ag_vextent_near 0 57653 NULL
119449 +r3964_write_57662 r3964_write 4 57662 NULL
119450 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
119451 +__lgwrite_57669 __lgwrite 4 57669 NULL
119452 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
119453 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
119454 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
119455 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
119456 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
119457 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
119458 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
119459 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
119460 +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
119461 +security_inode_unlink_57791 security_inode_unlink 0 57791 NULL
119462 +ld2_57794 ld2 0 57794 NULL
119463 +ivtv_read_57796 ivtv_read 3 57796 NULL
119464 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
119465 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
119466 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
119467 +xfs_rtpick_extent_57843 xfs_rtpick_extent 0 57843 NULL nohasharray
119468 +flash_read_57843 flash_read 3 57843 &xfs_rtpick_extent_57843
119469 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
119470 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
119471 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
119472 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
119473 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
119474 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
119475 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
119476 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
119477 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
119478 +xfs_inode_item_format_convert_57937 xfs_inode_item_format_convert 0 57937 NULL
119479 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
119480 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
119481 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
119482 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
119483 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
119484 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
119485 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
119486 +mce_async_out_58056 mce_async_out 3 58056 NULL
119487 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
119488 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
119489 +cm4040_write_58079 cm4040_write 3 58079 NULL
119490 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
119491 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
119492 +rd_build_prot_space_58137 rd_build_prot_space 2 58137 NULL
119493 +xfs_bmap_add_extent_delay_real_58151 xfs_bmap_add_extent_delay_real 0 58151 NULL
119494 +xfs_btree_update_58167 xfs_btree_update 0 58167 NULL
119495 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
119496 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
119497 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
119498 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
119499 +read_file_debug_58256 read_file_debug 3 58256 NULL
119500 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
119501 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
119502 +profile_load_58267 profile_load 3 58267 NULL
119503 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
119504 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
119505 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
119506 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
119507 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
119508 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
119509 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
119510 +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
119511 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
119512 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
119513 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
119514 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
119515 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
119516 +xfs_btree_get_rec_58410 xfs_btree_get_rec 0 58410 NULL
119517 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
119518 +capabilities_read_58457 capabilities_read 3 58457 NULL
119519 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
119520 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
119521 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
119522 +nv_rd08_58472 nv_rd08 0 58472 NULL
119523 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
119524 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
119525 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
119526 +btrfs_cont_expand_58498 btrfs_cont_expand 0-2-3 58498 NULL
119527 +gfs2_dir_get_new_buffer_58509 gfs2_dir_get_new_buffer 0 58509 NULL
119528 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
119529 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
119530 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
119531 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
119532 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
119533 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
119534 +xip_file_read_58592 xip_file_read 3 58592 NULL
119535 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
119536 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
119537 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
119538 +filemap_fdatawrite_range_58630 filemap_fdatawrite_range 0 58630 NULL
119539 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
119540 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
119541 +find_zero_58685 find_zero 0-1 58685 NULL
119542 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
119543 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
119544 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
119545 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
119546 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
119547 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
119548 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
119549 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
119550 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
119551 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
119552 +ep_read_58813 ep_read 3 58813 NULL
119553 +command_write_58841 command_write 3 58841 NULL
119554 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
119555 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
119556 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
119557 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
119558 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
119559 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
119560 +xfs_bmap_read_extents_58936 xfs_bmap_read_extents 0 58936 NULL
119561 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
119562 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
119563 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
119564 +__mem_cgroup_try_charge_58976 __mem_cgroup_try_charge 0 58976 NULL
119565 +init_list_set_59005 init_list_set 3 59005 NULL
119566 +ep_write_59008 ep_write 3 59008 NULL
119567 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
119568 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
119569 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
119570 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
119571 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
119572 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
119573 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
119574 +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL nohasharray
119575 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 &scsi_io_completion_59122
119576 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
119577 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
119578 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
119579 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
119580 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
119581 +ksize_59176 ksize 0 59176 NULL
119582 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
119583 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
119584 +xfs_ialloc_next_rec_59193 xfs_ialloc_next_rec 0 59193 NULL
119585 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
119586 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
119587 +dt3155_read_59226 dt3155_read 3 59226 NULL
119588 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
119589 +nla_len_59258 nla_len 0 59258 NULL
119590 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
119591 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
119592 +xfs_iformat_fork_59312 xfs_iformat_fork 0 59312 NULL
119593 +fd_copyout_59323 fd_copyout 3 59323 NULL
119594 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
119595 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
119596 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL nohasharray
119597 +xfs_alloc_lookup_le_59346 xfs_alloc_lookup_le 0 59346 &xfs_attrmulti_attr_set_59346
119598 +__map_request_59350 __map_request 0 59350 NULL
119599 +gfs2_quota_lock_check_59353 gfs2_quota_lock_check 0 59353 NULL
119600 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
119601 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
119602 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
119603 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
119604 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
119605 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
119606 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
119607 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
119608 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
119609 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
119610 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
119611 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
119612 +tunables_write_59563 tunables_write 3 59563 NULL
119613 +bio_split_59564 bio_split 2 59564 NULL
119614 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
119615 +write_pbl_59583 write_pbl 4 59583 NULL
119616 +memdup_user_59590 memdup_user 2 59590 NULL
119617 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
119618 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
119619 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
119620 +mtrr_write_59622 mtrr_write 3 59622 NULL
119621 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
119622 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
119623 +file_update_time_59647 file_update_time 0 59647 NULL
119624 +hidraw_read_59650 hidraw_read 3 59650 NULL
119625 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
119626 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
119627 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
119628 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
119629 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
119630 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
119631 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
119632 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
119633 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
119634 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
119635 +strnlen_59746 strnlen 0 59746 NULL
119636 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
119637 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL nohasharray
119638 +cap_inode_need_killpriv_59766 cap_inode_need_killpriv 0 59766 &long_retry_limit_read_59766
119639 +venus_remove_59781 venus_remove 4 59781 NULL
119640 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
119641 +ipw_write_59807 ipw_write 3 59807 NULL
119642 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
119643 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
119644 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
119645 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
119646 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
119647 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
119648 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
119649 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
119650 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
119651 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
119652 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
119653 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
119654 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
119655 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
119656 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
119657 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
119658 +copy_items_60009 copy_items 7 60009 NULL
119659 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
119660 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
119661 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
119662 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
119663 +xfs_imap_to_bp_60034 xfs_imap_to_bp 0 60034 NULL
119664 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
119665 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
119666 +vcs_size_60050 vcs_size 0 60050 NULL
119667 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
119668 +compat_writev_60063 compat_writev 3 60063 NULL
119669 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
119670 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
119671 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
119672 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
119673 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
119674 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
119675 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
119676 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
119677 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
119678 +init_state_60165 init_state 2 60165 NULL
119679 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
119680 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
119681 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
119682 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
119683 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
119684 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
119685 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
119686 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
119687 +printer_write_60276 printer_write 3 60276 NULL
119688 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
119689 +getDataLength_60301 getDataLength 0 60301 NULL
119690 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
119691 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
119692 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
119693 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
119694 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
119695 +driver_names_read_60399 driver_names_read 3 60399 NULL
119696 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
119697 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
119698 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
119699 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
119700 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
119701 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
119702 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
119703 +xfs_btree_make_block_unfull_60511 xfs_btree_make_block_unfull 0 60511 NULL
119704 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
119705 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
119706 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
119707 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
119708 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
119709 +inode_change_ok_60614 inode_change_ok 0 60614 NULL
119710 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
119711 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
119712 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
119713 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
119714 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
119715 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
119716 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
119717 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
119718 +raid_status_60755 raid_status 5 60755 NULL
119719 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
119720 +opticon_write_60775 opticon_write 4 60775 NULL
119721 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
119722 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
119723 +gfs2_bmap_alloc_60822 gfs2_bmap_alloc 0 60822 NULL
119724 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
119725 +__clone_and_map_data_bio_60861 __clone_and_map_data_bio 4-3 60861 NULL
119726 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
119727 +generic_writepages_60871 generic_writepages 0 60871 NULL
119728 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
119729 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
119730 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
119731 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
119732 +scrub_chunk_60926 scrub_chunk 5 60926 NULL
119733 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
119734 +xfs_rtallocate_extent_size_60939 xfs_rtallocate_extent_size 0 60939 NULL
119735 +pti_char_write_60960 pti_char_write 3 60960 NULL
119736 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
119737 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
119738 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
119739 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
119740 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
119741 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
119742 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
119743 +symtab_init_61050 symtab_init 2 61050 NULL
119744 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
119745 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
119746 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
119747 +xfs_dabuf_map_61093 xfs_dabuf_map 0 61093 NULL
119748 +get_derived_key_61100 get_derived_key 4 61100 NULL
119749 +mem_cgroup_cache_charge_61101 mem_cgroup_cache_charge 0 61101 NULL
119750 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
119751 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
119752 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
119753 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
119754 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
119755 +pair_device_61175 pair_device 4 61175 NULL nohasharray
119756 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
119757 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
119758 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
119759 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
119760 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
119761 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
119762 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
119763 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
119764 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
119765 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
119766 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
119767 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
119768 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
119769 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
119770 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
119771 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
119772 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
119773 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
119774 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
119775 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
119776 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
119777 +system_enable_write_61396 system_enable_write 3 61396 NULL
119778 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
119779 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
119780 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
119781 +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
119782 +erst_errno_61526 erst_errno 0 61526 NULL
119783 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
119784 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
119785 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
119786 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
119787 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
119788 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
119789 +seq_open_private_61589 seq_open_private 3 61589 NULL
119790 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
119791 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
119792 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
119793 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
119794 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
119795 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
119796 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
119797 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
119798 +resize_stripes_61650 resize_stripes 2 61650 NULL
119799 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
119800 +insert_one_name_61668 insert_one_name 7 61668 NULL
119801 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
119802 +lock_loop_61681 lock_loop 1 61681 NULL
119803 +filter_read_61692 filter_read 3 61692 NULL
119804 +iov_length_61716 iov_length 0 61716 NULL
119805 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
119806 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
119807 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
119808 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
119809 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
119810 +gfs2_meta_wait_61773 gfs2_meta_wait 0 61773 NULL
119811 +xfs_file_dio_aio_write_61801 xfs_file_dio_aio_write 0 61801 NULL
119812 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
119813 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
119814 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
119815 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
119816 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
119817 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
119818 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
119819 +get_fw_name_61874 get_fw_name 3 61874 NULL
119820 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
119821 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
119822 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
119823 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
119824 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
119825 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
119826 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
119827 +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
119828 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
119829 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
119830 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
119831 +fix_read_error_61965 fix_read_error 4 61965 NULL
119832 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
119833 +cow_file_range_61979 cow_file_range 3 61979 NULL
119834 +set_extent_delalloc_61982 set_extent_delalloc 0 61982 NULL
119835 +dequeue_event_62000 dequeue_event 3 62000 NULL
119836 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
119837 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
119838 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
119839 +SYSC_select_62024 SYSC_select 1 62024 NULL
119840 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
119841 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
119842 +do_pselect_62061 do_pselect 1 62061 NULL
119843 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
119844 +_xfs_log_force_lsn_62083 _xfs_log_force_lsn 0 62083 NULL
119845 +fat_setattr_62084 fat_setattr 0 62084 NULL
119846 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
119847 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
119848 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
119849 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
119850 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
119851 +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
119852 +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
119853 +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
119854 +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
119855 +video_usercopy_62151 video_usercopy 2 62151 NULL
119856 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
119857 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
119858 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
119859 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
119860 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
119861 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
119862 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
119863 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
119864 +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
119865 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
119866 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
119867 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
119868 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
119869 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
119870 +subseq_list_62332 subseq_list 3-0 62332 NULL
119871 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
119872 +flash_write_62354 flash_write 3 62354 NULL
119873 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
119874 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
119875 +altera_irscan_62396 altera_irscan 2 62396 NULL
119876 +set_ssp_62411 set_ssp 4 62411 NULL
119877 +udf_expand_file_adinicb_62470 udf_expand_file_adinicb 0 62470 NULL
119878 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
119879 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
119880 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
119881 +debugfs_read_62535 debugfs_read 3 62535 NULL
119882 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
119883 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
119884 +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
119885 +compute_bitstructs_62570 compute_bitstructs 0 62570 NULL
119886 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
119887 +get_subdir_62581 get_subdir 3 62581 NULL
119888 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
119889 +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
119890 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
119891 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
119892 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
119893 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
119894 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
119895 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
119896 +rdm_62719 rdm 0 62719 NULL
119897 +add_to_page_cache_62724 add_to_page_cache 0 62724 NULL
119898 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
119899 +key_replays_read_62746 key_replays_read 3 62746 NULL
119900 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
119901 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
119902 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
119903 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
119904 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
119905 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
119906 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
119907 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
119908 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
119909 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
119910 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
119911 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
119912 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
119913 +xfs_rtmodify_range_62877 xfs_rtmodify_range 0 62877 NULL
119914 +aoechr_write_62883 aoechr_write 3 62883 NULL
119915 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
119916 +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
119917 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
119918 +getdqbuf_62908 getdqbuf 1 62908 NULL
119919 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
119920 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
119921 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL nohasharray
119922 +xfs_trans_reserve_63026 xfs_trans_reserve 0 63026 &kstrtoull_from_user_63026
119923 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
119924 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
119925 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
119926 +unlink1_63059 unlink1 3 63059 NULL
119927 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
119928 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
119929 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
119930 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
119931 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
119932 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
119933 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
119934 +vme_master_read_63221 vme_master_read 0 63221 NULL
119935 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
119936 +ptp_read_63251 ptp_read 4 63251 NULL
119937 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
119938 +raid5_resize_63306 raid5_resize 2 63306 NULL
119939 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
119940 +proc_info_read_63344 proc_info_read 3 63344 NULL
119941 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
119942 +idmouse_read_63374 idmouse_read 3 63374 NULL
119943 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
119944 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
119945 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
119946 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
119947 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
119948 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
119949 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
119950 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
119951 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
119952 +read_kcore_63488 read_kcore 3 63488 NULL
119953 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
119954 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
119955 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL nohasharray
119956 +generic_cont_expand_simple_63534 generic_cont_expand_simple 0 63534 &ubi_more_leb_change_data_63534
119957 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
119958 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
119959 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
119960 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
119961 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
119962 +write_debug_level_63613 write_debug_level 3 63613 NULL
119963 +__spi_validate_63618 __spi_validate 0 63618 NULL
119964 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
119965 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
119966 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
119967 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
119968 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
119969 +vbi_read_63673 vbi_read 3 63673 NULL
119970 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
119971 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
119972 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
119973 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
119974 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
119975 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
119976 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
119977 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
119978 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
119979 +sel_write_load_63830 sel_write_load 3 63830 NULL
119980 +ll_readlink_63836 ll_readlink 3 63836 NULL
119981 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
119982 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
119983 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
119984 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
119985 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
119986 +__team_options_register_63941 __team_options_register 3 63941 NULL
119987 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
119988 +xfs_iflush_63956 xfs_iflush 0 63956 NULL
119989 +set_bredr_63975 set_bredr 4 63975 NULL
119990 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
119991 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
119992 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
119993 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
119994 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
119995 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
119996 +__generic_file_aio_write_64049 __generic_file_aio_write 0 64049 NULL
119997 +get_u8_64076 get_u8 0 64076 NULL
119998 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
119999 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
120000 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
120001 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
120002 +gfs2_inplace_reserve_64096 gfs2_inplace_reserve 0 64096 NULL nohasharray
120003 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 &gfs2_inplace_reserve_64096
120004 +to_bytes_64103 to_bytes 0-1 64103 NULL
120005 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
120006 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
120007 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
120008 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
120009 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
120010 +init_bch_64130 init_bch 1-2 64130 NULL
120011 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
120012 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
120013 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
120014 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
120015 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
120016 +read_pulse_64227 read_pulse 0-3 64227 NULL
120017 +ea_len_64229 ea_len 0 64229 NULL
120018 +xfs_rtmodify_summary_64265 xfs_rtmodify_summary 0 64265 NULL
120019 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
120020 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
120021 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
120022 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3-0 64288 NULL nohasharray
120023 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
120024 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
120025 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
120026 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
120027 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
120028 +ts_write_64336 ts_write 3 64336 NULL
120029 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
120030 +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
120031 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
120032 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
120033 +reg_create_64372 reg_create 5 64372 NULL
120034 +ilo_write_64378 ilo_write 3 64378 NULL
120035 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
120036 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
120037 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
120038 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
120039 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
120040 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
120041 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
120042 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
120043 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
120044 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
120045 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
120046 +single_open_size_64483 single_open_size 4 64483 NULL
120047 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL nohasharray
120048 +xfs_inode_ag_walk_64493 xfs_inode_ag_walk 0 64493 &p54_parse_rssical_64493
120049 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
120050 +remove_uuid_64505 remove_uuid 4 64505 NULL
120051 +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
120052 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
120053 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
120054 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
120055 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
120056 +SyS_bind_64544 SyS_bind 3 64544 NULL
120057 +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
120058 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
120059 +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
120060 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
120061 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
120062 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
120063 +do_erase_64574 do_erase 4 64574 NULL
120064 +fanotify_write_64623 fanotify_write 3 64623 NULL
120065 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
120066 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
120067 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
120068 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
120069 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
120070 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
120071 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
120072 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
120073 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
120074 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
120075 +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
120076 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
120077 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
120078 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
120079 +message_for_md_64777 message_for_md 5 64777 NULL
120080 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
120081 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
120082 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
120083 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
120084 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
120085 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
120086 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
120087 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
120088 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
120089 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
120090 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
120091 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
120092 +xfs_imap_lookup_64906 xfs_imap_lookup 0 64906 NULL
120093 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
120094 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
120095 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
120096 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
120097 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
120098 +insert_dent_65034 insert_dent 7 65034 NULL
120099 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
120100 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
120101 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
120102 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
120103 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
120104 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
120105 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
120106 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
120107 +__xfs_bmapi_allocate_65142 __xfs_bmapi_allocate 0 65142 NULL
120108 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
120109 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
120110 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
120111 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
120112 +xfs_btree_check_ptr_65281 xfs_btree_check_ptr 0 65281 NULL
120113 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
120114 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
120115 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
120116 +get_var_len_65304 get_var_len 0 65304 NULL
120117 +unpack_array_65318 unpack_array 0 65318 NULL
120118 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
120119 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
120120 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
120121 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
120122 +SyS_writev_65372 SyS_writev 3 65372 NULL
120123 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
120124 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
120125 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
120126 +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
120127 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
120128 +device_add_groups_65423 device_add_groups 0 65423 NULL
120129 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
120130 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
120131 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
120132 +clear_user_65470 clear_user 2 65470 NULL
120133 +xfs_alloc_lookup_ge_65481 xfs_alloc_lookup_ge 0 65481 NULL
120134 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
120135 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
120136 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
120137 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
120138 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120139 new file mode 100644
120140 index 0000000..560cd7b
120141 --- /dev/null
120142 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120143 @@ -0,0 +1,92 @@
120144 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
120145 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
120146 +mappedread_2627 mappedread 2 2627 NULL
120147 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
120148 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
120149 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
120150 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
120151 +dmu_write_6048 dmu_write 4-3 6048 NULL
120152 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
120153 +update_pages_6225 update_pages 2-3 6225 NULL
120154 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
120155 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
120156 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
120157 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
120158 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
120159 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
120160 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
120161 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
120162 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
120163 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
120164 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
120165 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
120166 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
120167 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
120168 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
120169 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
120170 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
120171 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
120172 +uiocopy_18680 uiocopy 2 18680 NULL
120173 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
120174 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
120175 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
120176 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
120177 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
120178 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
120179 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
120180 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
120181 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
120182 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
120183 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
120184 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
120185 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
120186 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
120187 +splat_write_30943 splat_write 3 30943 NULL
120188 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
120189 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
120190 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
120191 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
120192 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
120193 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
120194 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
120195 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
120196 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
120197 +copyinstr_36980 copyinstr 3 36980 NULL
120198 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
120199 +splat_read_38116 splat_read 3 38116 NULL
120200 +sa_setup_38756 sa_setup 4 38756 NULL
120201 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
120202 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
120203 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
120204 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
120205 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
120206 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
120207 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
120208 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
120209 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
120210 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
120211 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
120212 +kcopy_write_43683 kcopy_write 3 43683 NULL
120213 +uiomove_44355 uiomove 2 44355 NULL
120214 +dmu_read_44418 dmu_read 4-3 44418 NULL
120215 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
120216 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
120217 +copyin_45945 copyin 3 45945 NULL
120218 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
120219 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
120220 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
120221 +spa_history_write_49650 spa_history_write 3 49650 NULL
120222 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
120223 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
120224 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
120225 +copyout_51409 copyout 3 51409 NULL
120226 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
120227 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
120228 +get_nvlist_56685 get_nvlist 2 56685 NULL
120229 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
120230 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
120231 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
120232 +zpios_write_61823 zpios_write 3 61823 NULL
120233 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
120234 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
120235 +zpios_read_64734 zpios_read 3 64734 NULL
120236 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
120237 new file mode 100644
120238 index 0000000..e6fe17b
120239 --- /dev/null
120240 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
120241 @@ -0,0 +1,259 @@
120242 +/*
120243 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120244 + * Licensed under the GPL v2, or (at your option) v3
120245 + *
120246 + * Homepage:
120247 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120248 + *
120249 + * Documentation:
120250 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120251 + *
120252 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120253 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120254 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120255 + *
120256 + * Usage:
120257 + * $ make
120258 + * $ make run
120259 + */
120260 +
120261 +#include "gcc-common.h"
120262 +#include "size_overflow.h"
120263 +
120264 +int plugin_is_GPL_compatible;
120265 +
120266 +tree report_size_overflow_decl;
120267 +
120268 +tree size_overflow_type_HI;
120269 +tree size_overflow_type_SI;
120270 +tree size_overflow_type_DI;
120271 +tree size_overflow_type_TI;
120272 +
120273 +static struct plugin_info size_overflow_plugin_info = {
120274 + .version = "20140517",
120275 + .help = "no-size-overflow\tturn off size overflow checking\n",
120276 +};
120277 +
120278 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
120279 +{
120280 + unsigned int arg_count;
120281 + enum tree_code code = TREE_CODE(*node);
120282 +
120283 + switch (code) {
120284 + case FUNCTION_DECL:
120285 + arg_count = type_num_arguments(TREE_TYPE(*node));
120286 + break;
120287 + case FUNCTION_TYPE:
120288 + case METHOD_TYPE:
120289 + arg_count = type_num_arguments(*node);
120290 + break;
120291 + default:
120292 + *no_add_attrs = true;
120293 + error("%s: %qE attribute only applies to functions", __func__, name);
120294 + return NULL_TREE;
120295 + }
120296 +
120297 + for (; args; args = TREE_CHAIN(args)) {
120298 + tree position = TREE_VALUE(args);
120299 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
120300 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
120301 + *no_add_attrs = true;
120302 + }
120303 + }
120304 + return NULL_TREE;
120305 +}
120306 +
120307 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
120308 +{
120309 + unsigned int arg_count;
120310 + enum tree_code code = TREE_CODE(*node);
120311 +
120312 + switch (code) {
120313 + case FUNCTION_DECL:
120314 + arg_count = type_num_arguments(TREE_TYPE(*node));
120315 + break;
120316 + case FUNCTION_TYPE:
120317 + case METHOD_TYPE:
120318 + arg_count = type_num_arguments(*node);
120319 + break;
120320 + case FIELD_DECL:
120321 + return NULL_TREE;
120322 + default:
120323 + *no_add_attrs = true;
120324 + error("%qE attribute only applies to functions", name);
120325 + return NULL_TREE;
120326 + }
120327 +
120328 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
120329 + return NULL_TREE;
120330 +
120331 + for (; args; args = TREE_CHAIN(args)) {
120332 + tree position = TREE_VALUE(args);
120333 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
120334 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
120335 + *no_add_attrs = true;
120336 + }
120337 + }
120338 + return NULL_TREE;
120339 +}
120340 +
120341 +static struct attribute_spec size_overflow_attr = {
120342 + .name = "size_overflow",
120343 + .min_length = 1,
120344 + .max_length = -1,
120345 + .decl_required = true,
120346 + .type_required = false,
120347 + .function_type_required = false,
120348 + .handler = handle_size_overflow_attribute,
120349 +#if BUILDING_GCC_VERSION >= 4007
120350 + .affects_type_identity = false
120351 +#endif
120352 +};
120353 +
120354 +static struct attribute_spec intentional_overflow_attr = {
120355 + .name = "intentional_overflow",
120356 + .min_length = 1,
120357 + .max_length = -1,
120358 + .decl_required = true,
120359 + .type_required = false,
120360 + .function_type_required = false,
120361 + .handler = handle_intentional_overflow_attribute,
120362 +#if BUILDING_GCC_VERSION >= 4007
120363 + .affects_type_identity = false
120364 +#endif
120365 +};
120366 +
120367 +static void register_attributes(void __unused *event_data, void __unused *data)
120368 +{
120369 + register_attribute(&size_overflow_attr);
120370 + register_attribute(&intentional_overflow_attr);
120371 +}
120372 +
120373 +static tree create_typedef(tree type, const char* ident)
120374 +{
120375 + tree new_type, decl;
120376 +
120377 + new_type = build_variant_type_copy(type);
120378 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
120379 + DECL_ORIGINAL_TYPE(decl) = type;
120380 + TYPE_NAME(new_type) = decl;
120381 + return new_type;
120382 +}
120383 +
120384 +// Create the noreturn report_size_overflow() function decl.
120385 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
120386 +{
120387 + tree const_char_ptr_type_node;
120388 + tree fntype;
120389 +
120390 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
120391 +
120392 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
120393 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
120394 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
120395 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
120396 +
120397 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
120398 + fntype = build_function_type_list(void_type_node,
120399 + const_char_ptr_type_node,
120400 + unsigned_type_node,
120401 + const_char_ptr_type_node,
120402 + const_char_ptr_type_node,
120403 + NULL_TREE);
120404 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
120405 +
120406 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
120407 + TREE_PUBLIC(report_size_overflow_decl) = 1;
120408 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
120409 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
120410 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
120411 +}
120412 +
120413 +
120414 +extern struct gimple_opt_pass pass_dce;
120415 +
120416 +static struct opt_pass *make_dce_pass(void)
120417 +{
120418 +#if BUILDING_GCC_VERSION >= 4009
120419 + return make_pass_dce(g);
120420 +#else
120421 + return &pass_dce.pass;
120422 +#endif
120423 +}
120424 +
120425 +
120426 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
120427 +{
120428 + int i;
120429 + const char * const plugin_name = plugin_info->base_name;
120430 + const int argc = plugin_info->argc;
120431 + const struct plugin_argument * const argv = plugin_info->argv;
120432 + bool enable = true;
120433 + struct register_pass_info insert_size_overflow_asm_pass_info;
120434 + struct register_pass_info __unused dump_before_pass_info;
120435 + struct register_pass_info __unused dump_after_pass_info;
120436 + struct register_pass_info insert_size_overflow_check_info;
120437 + struct register_pass_info dce_pass_info;
120438 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
120439 + {
120440 + .base = &report_size_overflow_decl,
120441 + .nelt = 1,
120442 + .stride = sizeof(report_size_overflow_decl),
120443 + .cb = &gt_ggc_mx_tree_node,
120444 + .pchw = &gt_pch_nx_tree_node
120445 + },
120446 + LAST_GGC_ROOT_TAB
120447 + };
120448 +
120449 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
120450 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
120451 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
120452 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
120453 +
120454 + dump_before_pass_info.pass = make_dump_pass();
120455 + dump_before_pass_info.reference_pass_name = "increase_alignment";
120456 + dump_before_pass_info.ref_pass_instance_number = 1;
120457 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
120458 +
120459 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
120460 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
120461 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
120462 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
120463 +
120464 + dump_after_pass_info.pass = make_dump_pass();
120465 + dump_after_pass_info.reference_pass_name = "increase_alignment";
120466 + dump_after_pass_info.ref_pass_instance_number = 1;
120467 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
120468 +
120469 + dce_pass_info.pass = make_dce_pass();
120470 + dce_pass_info.reference_pass_name = "vrp";
120471 + dce_pass_info.ref_pass_instance_number = 1;
120472 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
120473 +
120474 + if (!plugin_default_version_check(version, &gcc_version)) {
120475 + error(G_("incompatible gcc/plugin versions"));
120476 + return 1;
120477 + }
120478 +
120479 + for (i = 0; i < argc; ++i) {
120480 + if (!strcmp(argv[i].key, "no-size-overflow")) {
120481 + enable = false;
120482 + continue;
120483 + }
120484 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
120485 + }
120486 +
120487 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
120488 + if (enable) {
120489 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
120490 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
120491 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
120492 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
120493 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
120494 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
120495 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
120496 + }
120497 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
120498 +
120499 + return 0;
120500 +}
120501 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
120502 new file mode 100644
120503 index 0000000..0888f6c
120504 --- /dev/null
120505 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
120506 @@ -0,0 +1,364 @@
120507 +/*
120508 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120509 + * Licensed under the GPL v2, or (at your option) v3
120510 + *
120511 + * Homepage:
120512 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120513 + *
120514 + * Documentation:
120515 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120516 + *
120517 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120518 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120519 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120520 + *
120521 + * Usage:
120522 + * $ make
120523 + * $ make run
120524 + */
120525 +
120526 +#include "gcc-common.h"
120527 +#include "size_overflow.h"
120528 +
120529 +#include "size_overflow_hash.h"
120530 +#include "size_overflow_hash_aux.h"
120531 +
120532 +#define CODES_LIMIT 32
120533 +
120534 +static unsigned char get_tree_code(const_tree type)
120535 +{
120536 + switch (TREE_CODE(type)) {
120537 + case ARRAY_TYPE:
120538 + return 0;
120539 + case BOOLEAN_TYPE:
120540 + return 1;
120541 + case ENUMERAL_TYPE:
120542 + return 2;
120543 + case FUNCTION_TYPE:
120544 + return 3;
120545 + case INTEGER_TYPE:
120546 + return 4;
120547 + case POINTER_TYPE:
120548 + return 5;
120549 + case RECORD_TYPE:
120550 + return 6;
120551 + case UNION_TYPE:
120552 + return 7;
120553 + case VOID_TYPE:
120554 + return 8;
120555 + case REAL_TYPE:
120556 + return 9;
120557 + case VECTOR_TYPE:
120558 + return 10;
120559 + case REFERENCE_TYPE:
120560 + return 11;
120561 + case OFFSET_TYPE:
120562 + return 12;
120563 + case COMPLEX_TYPE:
120564 + return 13;
120565 + default:
120566 + debug_tree((tree)type);
120567 + gcc_unreachable();
120568 + }
120569 +}
120570 +
120571 +struct function_hash {
120572 + size_t tree_codes_len;
120573 + unsigned char tree_codes[CODES_LIMIT];
120574 + const_tree fndecl;
120575 + unsigned int hash;
120576 +};
120577 +
120578 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
120579 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
120580 +{
120581 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
120582 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
120583 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
120584 +
120585 + unsigned int m = 0x57559429;
120586 + unsigned int n = 0x5052acdb;
120587 + const unsigned int *key4 = (const unsigned int *)key;
120588 + unsigned int h = len;
120589 + unsigned int k = len + seed + n;
120590 + unsigned long long p;
120591 +
120592 + while (len >= 8) {
120593 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
120594 + len -= 8;
120595 + }
120596 + if (len >= 4) {
120597 + cwmixb(key4[0]) key4 += 1;
120598 + len -= 4;
120599 + }
120600 + if (len)
120601 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
120602 + cwmixb(h ^ (k + n));
120603 + return k ^ h;
120604 +
120605 +#undef cwfold
120606 +#undef cwmixa
120607 +#undef cwmixb
120608 +}
120609 +
120610 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
120611 +{
120612 + unsigned int fn, codes, seed = 0;
120613 +
120614 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
120615 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
120616 +
120617 + fn_hash_data->hash = fn ^ codes;
120618 +}
120619 +
120620 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
120621 +{
120622 + gcc_assert(type != NULL_TREE);
120623 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
120624 +
120625 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
120626 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
120627 + fn_hash_data->tree_codes_len++;
120628 + type = TREE_TYPE(type);
120629 + }
120630 +}
120631 +
120632 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
120633 +{
120634 + const_tree result;
120635 +
120636 + gcc_assert(node != NULL_TREE);
120637 +
120638 + if (DECL_P(node)) {
120639 + result = DECL_RESULT(node);
120640 + if (result != NULL_TREE)
120641 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
120642 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
120643 + }
120644 +
120645 + gcc_assert(TYPE_P(node));
120646 +
120647 + if (TREE_CODE(node) == FUNCTION_TYPE)
120648 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
120649 +
120650 + return set_node_codes(node, fn_hash_data);
120651 +}
120652 +
120653 +static void set_function_codes(struct function_hash *fn_hash_data)
120654 +{
120655 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
120656 + enum tree_code code = TREE_CODE(type);
120657 +
120658 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
120659 +
120660 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
120661 +
120662 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
120663 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
120664 +}
120665 +
120666 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
120667 +{
120668 + while (entry) {
120669 + if (!strcmp(entry->name, func_name))
120670 + return entry;
120671 + entry = entry->next;
120672 + }
120673 + return NULL;
120674 +}
120675 +
120676 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
120677 +{
120678 + const struct size_overflow_hash *entry;
120679 + struct function_hash fn_hash_data;
120680 + const char *func_name;
120681 +
120682 + // skip builtins __builtin_constant_p
120683 + if (DECL_BUILT_IN(fndecl))
120684 + return NULL;
120685 +
120686 + fn_hash_data.fndecl = fndecl;
120687 + fn_hash_data.tree_codes_len = 0;
120688 +
120689 + set_function_codes(&fn_hash_data);
120690 + gcc_assert(fn_hash_data.tree_codes_len != 0);
120691 +
120692 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
120693 + set_hash(func_name, &fn_hash_data);
120694 +
120695 + entry = size_overflow_hash[fn_hash_data.hash];
120696 + entry = get_proper_hash_chain(entry, func_name);
120697 + if (entry)
120698 + return entry;
120699 + entry = size_overflow_hash_aux[fn_hash_data.hash];
120700 + return get_proper_hash_chain(entry, func_name);
120701 +}
120702 +
120703 +static void print_missing_msg(const_tree func, unsigned int argnum)
120704 +{
120705 + location_t loc;
120706 + const char *curfunc;
120707 + struct function_hash fn_hash_data;
120708 +
120709 + fn_hash_data.fndecl = DECL_ORIGIN(func);
120710 + fn_hash_data.tree_codes_len = 0;
120711 +
120712 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
120713 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
120714 +
120715 + set_function_codes(&fn_hash_data);
120716 + set_hash(curfunc, &fn_hash_data);
120717 +
120718 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
120719 +}
120720 +
120721 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
120722 +{
120723 + tree var;
120724 + unsigned int argnum = 1;
120725 +
120726 + if (TREE_CODE(arg) == SSA_NAME)
120727 + arg = SSA_NAME_VAR(arg);
120728 +
120729 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
120730 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
120731 + continue;
120732 + if (!skip_types(var))
120733 + return argnum;
120734 + }
120735 +
120736 + return CANNOT_FIND_ARG;
120737 +}
120738 +
120739 +static const char *get_asm_string(const_gimple stmt)
120740 +{
120741 + if (!stmt)
120742 + return NULL;
120743 + if (gimple_code(stmt) != GIMPLE_ASM)
120744 + return NULL;
120745 +
120746 + return gimple_asm_string(stmt);
120747 +}
120748 +
120749 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
120750 +{
120751 + const char *str;
120752 +
120753 + str = get_asm_string(stmt);
120754 + if (!str)
120755 + return false;
120756 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
120757 +}
120758 +
120759 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
120760 +{
120761 + const char *str;
120762 +
120763 + str = get_asm_string(stmt);
120764 + if (!str)
120765 + return false;
120766 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
120767 +}
120768 +
120769 +bool is_size_overflow_asm(const_gimple stmt)
120770 +{
120771 + const char *str;
120772 +
120773 + str = get_asm_string(stmt);
120774 + if (!str)
120775 + return false;
120776 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
120777 +}
120778 +
120779 +bool is_a_return_check(const_tree node)
120780 +{
120781 + if (TREE_CODE(node) == FUNCTION_DECL)
120782 + return true;
120783 +
120784 + gcc_assert(TREE_CODE(node) == PARM_DECL);
120785 + return false;
120786 +}
120787 +
120788 +// Get the argnum of a function decl, if node is a return then the argnum is 0
120789 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
120790 +{
120791 + if (is_a_return_check(node))
120792 + return 0;
120793 + else
120794 + return find_arg_number_tree(node, orig_fndecl);
120795 +}
120796 +
120797 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
120798 +{
120799 + const struct size_overflow_hash *hash;
120800 + unsigned int new_argnum;
120801 + tree arg;
120802 + const_tree origarg;
120803 +
120804 + if (argnum == 0)
120805 + return argnum;
120806 +
120807 + hash = get_function_hash(fndecl);
120808 + if (hash && hash->param & (1U << argnum))
120809 + return argnum;
120810 +
120811 + if (DECL_EXTERNAL(fndecl))
120812 + return argnum;
120813 +
120814 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
120815 + argnum--;
120816 + while (origarg && argnum) {
120817 + origarg = TREE_CHAIN(origarg);
120818 + argnum--;
120819 + }
120820 + gcc_assert(argnum == 0);
120821 + gcc_assert(origarg != NULL_TREE);
120822 +
120823 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
120824 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
120825 + return new_argnum;
120826 +
120827 + return CANNOT_FIND_ARG;
120828 +}
120829 +
120830 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
120831 +{
120832 + const struct size_overflow_hash *hash;
120833 +
120834 + hash = get_function_hash(fndecl);
120835 + if (hash && (hash->param & (1U << num)))
120836 + return true;
120837 + return false;
120838 +}
120839 +
120840 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
120841 + * If the function is missing everywhere then print the missing message into stderr.
120842 + */
120843 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
120844 +{
120845 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
120846 +#if BUILDING_GCC_VERSION >= 4008
120847 + case BUILT_IN_BSWAP16:
120848 +#endif
120849 + case BUILT_IN_BSWAP32:
120850 + case BUILT_IN_BSWAP64:
120851 + case BUILT_IN_EXPECT:
120852 + case BUILT_IN_MEMCMP:
120853 + return false;
120854 + default:
120855 + break;
120856 + }
120857 +
120858 + // skip test.c
120859 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
120860 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
120861 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
120862 + }
120863 +
120864 + if (is_in_hash_table(orig_fndecl, num))
120865 + return false;
120866 +
120867 + print_missing_msg(orig_fndecl, num);
120868 + return true;
120869 +}
120870 +
120871 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
120872 new file mode 100644
120873 index 0000000..dd94983
120874 --- /dev/null
120875 +++ b/tools/gcc/stackleak_plugin.c
120876 @@ -0,0 +1,376 @@
120877 +/*
120878 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
120879 + * Licensed under the GPL v2
120880 + *
120881 + * Note: the choice of the license means that the compilation process is
120882 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
120883 + * but for the kernel it doesn't matter since it doesn't link against
120884 + * any of the gcc libraries
120885 + *
120886 + * gcc plugin to help implement various PaX features
120887 + *
120888 + * - track lowest stack pointer
120889 + *
120890 + * TODO:
120891 + * - initialize all local variables
120892 + *
120893 + * BUGS:
120894 + * - none known
120895 + */
120896 +
120897 +#include "gcc-common.h"
120898 +
120899 +int plugin_is_GPL_compatible;
120900 +
120901 +static int track_frame_size = -1;
120902 +static const char track_function[] = "pax_track_stack";
120903 +static const char check_function[] = "pax_check_alloca";
120904 +static tree track_function_decl, check_function_decl;
120905 +static bool init_locals;
120906 +
120907 +static struct plugin_info stackleak_plugin_info = {
120908 + .version = "201402131920",
120909 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
120910 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
120911 +};
120912 +
120913 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
120914 +{
120915 + gimple check_alloca;
120916 + tree alloca_size;
120917 +
120918 + // insert call to void pax_check_alloca(unsigned long size)
120919 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
120920 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
120921 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
120922 +}
120923 +
120924 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
120925 +{
120926 + gimple track_stack;
120927 +
120928 + // insert call to void pax_track_stack(void)
120929 + track_stack = gimple_build_call(track_function_decl, 0);
120930 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
120931 +}
120932 +
120933 +static bool is_alloca(gimple stmt)
120934 +{
120935 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
120936 + return true;
120937 +
120938 +#if BUILDING_GCC_VERSION >= 4007
120939 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
120940 + return true;
120941 +#endif
120942 +
120943 + return false;
120944 +}
120945 +
120946 +static unsigned int execute_stackleak_tree_instrument(void)
120947 +{
120948 + basic_block bb, entry_bb;
120949 + bool prologue_instrumented = false, is_leaf = true;
120950 +
120951 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
120952 +
120953 + // 1. loop through BBs and GIMPLE statements
120954 + FOR_EACH_BB_FN(bb, cfun) {
120955 + gimple_stmt_iterator gsi;
120956 +
120957 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
120958 + gimple stmt;
120959 +
120960 + stmt = gsi_stmt(gsi);
120961 +
120962 + if (is_gimple_call(stmt))
120963 + is_leaf = false;
120964 +
120965 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
120966 + if (!is_alloca(stmt))
120967 + continue;
120968 +
120969 + // 2. insert stack overflow check before each __builtin_alloca call
120970 + stackleak_check_alloca(&gsi);
120971 +
120972 + // 3. insert track call after each __builtin_alloca call
120973 + stackleak_add_instrumentation(&gsi);
120974 + if (bb == entry_bb)
120975 + prologue_instrumented = true;
120976 + }
120977 + }
120978 +
120979 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
120980 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
120981 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
120982 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
120983 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
120984 + return 0;
120985 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
120986 + return 0;
120987 +
120988 + // 4. insert track call at the beginning
120989 + if (!prologue_instrumented) {
120990 + gimple_stmt_iterator gsi;
120991 +
120992 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
120993 + if (dom_info_available_p(CDI_DOMINATORS))
120994 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
120995 + gsi = gsi_start_bb(bb);
120996 + stackleak_add_instrumentation(&gsi);
120997 + }
120998 +
120999 + return 0;
121000 +}
121001 +
121002 +static unsigned int execute_stackleak_final(void)
121003 +{
121004 + rtx insn, next;
121005 +
121006 + if (cfun->calls_alloca)
121007 + return 0;
121008 +
121009 + // keep calls only if function frame is big enough
121010 + if (get_frame_size() >= track_frame_size)
121011 + return 0;
121012 +
121013 + // 1. find pax_track_stack calls
121014 + for (insn = get_insns(); insn; insn = next) {
121015 + // 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))
121016 + rtx body;
121017 +
121018 + next = NEXT_INSN(insn);
121019 + if (!CALL_P(insn))
121020 + continue;
121021 + body = PATTERN(insn);
121022 + if (GET_CODE(body) != CALL)
121023 + continue;
121024 + body = XEXP(body, 0);
121025 + if (GET_CODE(body) != MEM)
121026 + continue;
121027 + body = XEXP(body, 0);
121028 + if (GET_CODE(body) != SYMBOL_REF)
121029 + continue;
121030 +// if (strcmp(XSTR(body, 0), track_function))
121031 + if (SYMBOL_REF_DECL(body) != track_function_decl)
121032 + continue;
121033 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121034 + // 2. delete call
121035 + delete_insn_and_edges(insn);
121036 +#if BUILDING_GCC_VERSION >= 4007
121037 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
121038 + insn = next;
121039 + next = NEXT_INSN(insn);
121040 + delete_insn_and_edges(insn);
121041 + }
121042 +#endif
121043 + }
121044 +
121045 +// print_simple_rtl(stderr, get_insns());
121046 +// print_rtl(stderr, get_insns());
121047 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121048 +
121049 + return 0;
121050 +}
121051 +
121052 +static bool gate_stackleak_track_stack(void)
121053 +{
121054 + return track_frame_size >= 0;
121055 +}
121056 +
121057 +static void stackleak_start_unit(void *gcc_data, void *user_data)
121058 +{
121059 + tree fntype;
121060 +
121061 + // void pax_track_stack(void)
121062 + fntype = build_function_type_list(void_type_node, NULL_TREE);
121063 + track_function_decl = build_fn_decl(track_function, fntype);
121064 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
121065 + TREE_PUBLIC(track_function_decl) = 1;
121066 + DECL_EXTERNAL(track_function_decl) = 1;
121067 + DECL_ARTIFICIAL(track_function_decl) = 1;
121068 +
121069 + // void pax_check_alloca(unsigned long)
121070 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
121071 + check_function_decl = build_fn_decl(check_function, fntype);
121072 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
121073 + TREE_PUBLIC(check_function_decl) = 1;
121074 + DECL_EXTERNAL(check_function_decl) = 1;
121075 + DECL_ARTIFICIAL(check_function_decl) = 1;
121076 +}
121077 +
121078 +#if BUILDING_GCC_VERSION >= 4009
121079 +static const struct pass_data stackleak_tree_instrument_pass_data = {
121080 +#else
121081 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
121082 + .pass = {
121083 +#endif
121084 + .type = GIMPLE_PASS,
121085 + .name = "stackleak_tree_instrument",
121086 +#if BUILDING_GCC_VERSION >= 4008
121087 + .optinfo_flags = OPTGROUP_NONE,
121088 +#endif
121089 +#if BUILDING_GCC_VERSION >= 4009
121090 + .has_gate = true,
121091 + .has_execute = true,
121092 +#else
121093 + .gate = gate_stackleak_track_stack,
121094 + .execute = execute_stackleak_tree_instrument,
121095 + .sub = NULL,
121096 + .next = NULL,
121097 + .static_pass_number = 0,
121098 +#endif
121099 + .tv_id = TV_NONE,
121100 + .properties_required = PROP_gimple_leh | PROP_cfg,
121101 + .properties_provided = 0,
121102 + .properties_destroyed = 0,
121103 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
121104 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
121105 +#if BUILDING_GCC_VERSION < 4009
121106 + }
121107 +#endif
121108 +};
121109 +
121110 +#if BUILDING_GCC_VERSION >= 4009
121111 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
121112 +#else
121113 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
121114 + .pass = {
121115 +#endif
121116 + .type = RTL_PASS,
121117 + .name = "stackleak_final",
121118 +#if BUILDING_GCC_VERSION >= 4008
121119 + .optinfo_flags = OPTGROUP_NONE,
121120 +#endif
121121 +#if BUILDING_GCC_VERSION >= 4009
121122 + .has_gate = true,
121123 + .has_execute = true,
121124 +#else
121125 + .gate = gate_stackleak_track_stack,
121126 + .execute = execute_stackleak_final,
121127 + .sub = NULL,
121128 + .next = NULL,
121129 + .static_pass_number = 0,
121130 +#endif
121131 + .tv_id = TV_NONE,
121132 + .properties_required = 0,
121133 + .properties_provided = 0,
121134 + .properties_destroyed = 0,
121135 + .todo_flags_start = 0,
121136 + .todo_flags_finish = TODO_dump_func
121137 +#if BUILDING_GCC_VERSION < 4009
121138 + }
121139 +#endif
121140 +};
121141 +
121142 +#if BUILDING_GCC_VERSION >= 4009
121143 +namespace {
121144 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
121145 +public:
121146 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
121147 + bool gate() { return gate_stackleak_track_stack(); }
121148 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
121149 +};
121150 +
121151 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
121152 +public:
121153 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
121154 + bool gate() { return gate_stackleak_track_stack(); }
121155 + unsigned int execute() { return execute_stackleak_final(); }
121156 +};
121157 +}
121158 +
121159 +static opt_pass *make_stackleak_tree_instrument_pass(void)
121160 +{
121161 + return new stackleak_tree_instrument_pass();
121162 +}
121163 +
121164 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
121165 +{
121166 + return new stackleak_final_rtl_opt_pass();
121167 +}
121168 +#else
121169 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
121170 +{
121171 + return &stackleak_tree_instrument_pass.pass;
121172 +}
121173 +
121174 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
121175 +{
121176 + return &stackleak_final_rtl_opt_pass.pass;
121177 +}
121178 +#endif
121179 +
121180 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121181 +{
121182 + const char * const plugin_name = plugin_info->base_name;
121183 + const int argc = plugin_info->argc;
121184 + const struct plugin_argument * const argv = plugin_info->argv;
121185 + int i;
121186 + struct register_pass_info stackleak_tree_instrument_pass_info;
121187 + struct register_pass_info stackleak_final_pass_info;
121188 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
121189 + {
121190 + .base = &track_function_decl,
121191 + .nelt = 1,
121192 + .stride = sizeof(track_function_decl),
121193 + .cb = &gt_ggc_mx_tree_node,
121194 + .pchw = &gt_pch_nx_tree_node
121195 + },
121196 + {
121197 + .base = &check_function_decl,
121198 + .nelt = 1,
121199 + .stride = sizeof(check_function_decl),
121200 + .cb = &gt_ggc_mx_tree_node,
121201 + .pchw = &gt_pch_nx_tree_node
121202 + },
121203 + LAST_GGC_ROOT_TAB
121204 + };
121205 +
121206 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
121207 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
121208 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
121209 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
121210 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121211 +
121212 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
121213 + stackleak_final_pass_info.reference_pass_name = "final";
121214 + stackleak_final_pass_info.ref_pass_instance_number = 1;
121215 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121216 +
121217 + if (!plugin_default_version_check(version, &gcc_version)) {
121218 + error(G_("incompatible gcc/plugin versions"));
121219 + return 1;
121220 + }
121221 +
121222 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
121223 +
121224 + for (i = 0; i < argc; ++i) {
121225 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
121226 + if (!argv[i].value) {
121227 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121228 + continue;
121229 + }
121230 + track_frame_size = atoi(argv[i].value);
121231 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
121232 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
121233 + continue;
121234 + }
121235 + if (!strcmp(argv[i].key, "initialize-locals")) {
121236 + if (argv[i].value) {
121237 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
121238 + continue;
121239 + }
121240 + init_locals = true;
121241 + continue;
121242 + }
121243 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121244 + }
121245 +
121246 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
121247 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
121248 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
121249 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
121250 +
121251 + return 0;
121252 +}
121253 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
121254 new file mode 100644
121255 index 0000000..4ee2231
121256 --- /dev/null
121257 +++ b/tools/gcc/structleak_plugin.c
121258 @@ -0,0 +1,274 @@
121259 +/*
121260 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
121261 + * Licensed under the GPL v2
121262 + *
121263 + * Note: the choice of the license means that the compilation process is
121264 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
121265 + * but for the kernel it doesn't matter since it doesn't link against
121266 + * any of the gcc libraries
121267 + *
121268 + * gcc plugin to forcibly initialize certain local variables that could
121269 + * otherwise leak kernel stack to userland if they aren't properly initialized
121270 + * by later code
121271 + *
121272 + * Homepage: http://pax.grsecurity.net/
121273 + *
121274 + * Usage:
121275 + * $ # for 4.5/4.6/C based 4.7
121276 + * $ 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
121277 + * $ # for C++ based 4.7/4.8+
121278 + * $ 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
121279 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
121280 + *
121281 + * TODO: eliminate redundant initializers
121282 + * increase type coverage
121283 + */
121284 +
121285 +#include "gcc-common.h"
121286 +
121287 +// unused C type flag in all versions 4.5-4.9
121288 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
121289 +
121290 +int plugin_is_GPL_compatible;
121291 +
121292 +static struct plugin_info structleak_plugin_info = {
121293 + .version = "201401260140",
121294 + .help = "disable\tdo not activate plugin\n",
121295 +};
121296 +
121297 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
121298 +{
121299 + *no_add_attrs = true;
121300 +
121301 + // check for types? for now accept everything linux has to offer
121302 + if (TREE_CODE(*node) != FIELD_DECL)
121303 + return NULL_TREE;
121304 +
121305 + *no_add_attrs = false;
121306 + return NULL_TREE;
121307 +}
121308 +
121309 +static struct attribute_spec user_attr = {
121310 + .name = "user",
121311 + .min_length = 0,
121312 + .max_length = 0,
121313 + .decl_required = false,
121314 + .type_required = false,
121315 + .function_type_required = false,
121316 + .handler = handle_user_attribute,
121317 +#if BUILDING_GCC_VERSION >= 4007
121318 + .affects_type_identity = true
121319 +#endif
121320 +};
121321 +
121322 +static void register_attributes(void *event_data, void *data)
121323 +{
121324 + register_attribute(&user_attr);
121325 +// register_attribute(&force_attr);
121326 +}
121327 +
121328 +static tree get_field_type(tree field)
121329 +{
121330 + return strip_array_types(TREE_TYPE(field));
121331 +}
121332 +
121333 +static bool is_userspace_type(tree type)
121334 +{
121335 + tree field;
121336 +
121337 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
121338 + tree fieldtype = get_field_type(field);
121339 + enum tree_code code = TREE_CODE(fieldtype);
121340 +
121341 + if (code == RECORD_TYPE || code == UNION_TYPE)
121342 + if (is_userspace_type(fieldtype))
121343 + return true;
121344 +
121345 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
121346 + return true;
121347 + }
121348 + return false;
121349 +}
121350 +
121351 +static void finish_type(void *event_data, void *data)
121352 +{
121353 + tree type = (tree)event_data;
121354 +
121355 + if (TYPE_USERSPACE(type))
121356 + return;
121357 +
121358 + if (is_userspace_type(type))
121359 + TYPE_USERSPACE(type) = 1;
121360 +}
121361 +
121362 +static void initialize(tree var)
121363 +{
121364 + basic_block bb;
121365 + gimple_stmt_iterator gsi;
121366 + tree initializer;
121367 + gimple init_stmt;
121368 +
121369 + // this is the original entry bb before the forced split
121370 + // TODO: check further BBs in case more splits occured before us
121371 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
121372 +
121373 + // first check if the variable is already initialized, warn otherwise
121374 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121375 + gimple stmt = gsi_stmt(gsi);
121376 + tree rhs1;
121377 +
121378 + // we're looking for an assignment of a single rhs...
121379 + if (!gimple_assign_single_p(stmt))
121380 + continue;
121381 + rhs1 = gimple_assign_rhs1(stmt);
121382 +#if BUILDING_GCC_VERSION >= 4007
121383 + // ... of a non-clobbering expression...
121384 + if (TREE_CLOBBER_P(rhs1))
121385 + continue;
121386 +#endif
121387 + // ... to our variable...
121388 + if (gimple_get_lhs(stmt) != var)
121389 + continue;
121390 + // if it's an initializer then we're good
121391 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
121392 + return;
121393 + }
121394 +
121395 + // these aren't the 0days you're looking for
121396 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
121397 +
121398 + // build the initializer expression
121399 + initializer = build_constructor(TREE_TYPE(var), NULL);
121400 +
121401 + // build the initializer stmt
121402 + init_stmt = gimple_build_assign(var, initializer);
121403 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
121404 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
121405 + update_stmt(init_stmt);
121406 +}
121407 +
121408 +static unsigned int handle_function(void)
121409 +{
121410 + basic_block bb;
121411 + unsigned int ret = 0;
121412 + tree var;
121413 + unsigned int i;
121414 +
121415 + // split the first bb where we can put the forced initializers
121416 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
121417 + if (dom_info_available_p(CDI_DOMINATORS))
121418 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
121419 +
121420 + // enumarate all local variables and forcibly initialize our targets
121421 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
121422 + tree type = TREE_TYPE(var);
121423 +
121424 + gcc_assert(DECL_P(var));
121425 + if (!auto_var_in_fn_p(var, current_function_decl))
121426 + continue;
121427 +
121428 + // only care about structure types
121429 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
121430 + continue;
121431 +
121432 + // if the type is of interest, examine the variable
121433 + if (TYPE_USERSPACE(type))
121434 + initialize(var);
121435 + }
121436 +
121437 + return ret;
121438 +}
121439 +
121440 +#if BUILDING_GCC_VERSION >= 4009
121441 +static const struct pass_data structleak_pass_data = {
121442 +#else
121443 +static struct gimple_opt_pass structleak_pass = {
121444 + .pass = {
121445 +#endif
121446 + .type = GIMPLE_PASS,
121447 + .name = "structleak",
121448 +#if BUILDING_GCC_VERSION >= 4008
121449 + .optinfo_flags = OPTGROUP_NONE,
121450 +#endif
121451 +#if BUILDING_GCC_VERSION >= 4009
121452 + .has_gate = false,
121453 + .has_execute = true,
121454 +#else
121455 + .gate = NULL,
121456 + .execute = handle_function,
121457 + .sub = NULL,
121458 + .next = NULL,
121459 + .static_pass_number = 0,
121460 +#endif
121461 + .tv_id = TV_NONE,
121462 + .properties_required = PROP_cfg,
121463 + .properties_provided = 0,
121464 + .properties_destroyed = 0,
121465 + .todo_flags_start = 0,
121466 + .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
121467 +#if BUILDING_GCC_VERSION < 4009
121468 + }
121469 +#endif
121470 +};
121471 +
121472 +#if BUILDING_GCC_VERSION >= 4009
121473 +namespace {
121474 +class structleak_pass : public gimple_opt_pass {
121475 +public:
121476 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
121477 + unsigned int execute() { return handle_function(); }
121478 +};
121479 +}
121480 +
121481 +static opt_pass *make_structleak_pass(void)
121482 +{
121483 + return new structleak_pass();
121484 +}
121485 +#else
121486 +static struct opt_pass *make_structleak_pass(void)
121487 +{
121488 + return &structleak_pass.pass;
121489 +}
121490 +#endif
121491 +
121492 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121493 +{
121494 + int i;
121495 + const char * const plugin_name = plugin_info->base_name;
121496 + const int argc = plugin_info->argc;
121497 + const struct plugin_argument * const argv = plugin_info->argv;
121498 + bool enable = true;
121499 + struct register_pass_info structleak_pass_info;
121500 +
121501 + structleak_pass_info.pass = make_structleak_pass();
121502 + structleak_pass_info.reference_pass_name = "ssa";
121503 + structleak_pass_info.ref_pass_instance_number = 1;
121504 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
121505 +
121506 + if (!plugin_default_version_check(version, &gcc_version)) {
121507 + error(G_("incompatible gcc/plugin versions"));
121508 + return 1;
121509 + }
121510 +
121511 + if (strcmp(lang_hooks.name, "GNU C")) {
121512 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
121513 + enable = false;
121514 + }
121515 +
121516 + for (i = 0; i < argc; ++i) {
121517 + if (!strcmp(argv[i].key, "disable")) {
121518 + enable = false;
121519 + continue;
121520 + }
121521 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121522 + }
121523 +
121524 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
121525 + if (enable) {
121526 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
121527 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
121528 + }
121529 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
121530 +
121531 + return 0;
121532 +}
121533 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
121534 index fbc6665..5e9ce79 100644
121535 --- a/tools/include/linux/compiler.h
121536 +++ b/tools/include/linux/compiler.h
121537 @@ -35,4 +35,12 @@
121538 # define unlikely(x) __builtin_expect(!!(x), 0)
121539 #endif
121540
121541 +#ifndef __size_overflow
121542 +# define __size_overflow(...)
121543 +#endif
121544 +
121545 +#ifndef __intentional_overflow
121546 +# define __intentional_overflow(...)
121547 +#endif
121548 +
121549 #endif /* _TOOLS_LINUX_COMPILER_H */
121550 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
121551 index ed2f51e..cc2d8f6 100644
121552 --- a/tools/lib/api/Makefile
121553 +++ b/tools/lib/api/Makefile
121554 @@ -14,7 +14,7 @@ LIB_OBJS += $(OUTPUT)fs/debugfs.o
121555
121556 LIBFILE = libapikfs.a
121557
121558 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
121559 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
121560 EXTLIBS = -lelf -lpthread -lrt -lm
121561 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
121562 ALL_LDFLAGS = $(LDFLAGS)
121563 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
121564 index 6789d78..4afd019e 100644
121565 --- a/tools/perf/util/include/asm/alternative-asm.h
121566 +++ b/tools/perf/util/include/asm/alternative-asm.h
121567 @@ -5,4 +5,7 @@
121568
121569 #define altinstruction_entry #
121570
121571 + .macro pax_force_retaddr rip=0, reload=0
121572 + .endm
121573 +
121574 #endif
121575 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
121576 index 03a0381..8b31923 100644
121577 --- a/virt/kvm/kvm_main.c
121578 +++ b/virt/kvm/kvm_main.c
121579 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
121580
121581 static cpumask_var_t cpus_hardware_enabled;
121582 static int kvm_usage_count = 0;
121583 -static atomic_t hardware_enable_failed;
121584 +static atomic_unchecked_t hardware_enable_failed;
121585
121586 struct kmem_cache *kvm_vcpu_cache;
121587 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
121588
121589 -static __read_mostly struct preempt_ops kvm_preempt_ops;
121590 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
121591 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
121592 +static struct preempt_ops kvm_preempt_ops = {
121593 + .sched_in = kvm_sched_in,
121594 + .sched_out = kvm_sched_out,
121595 +};
121596
121597 struct dentry *kvm_debugfs_dir;
121598
121599 @@ -758,7 +763,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
121600 /* We can read the guest memory with __xxx_user() later on. */
121601 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
121602 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
121603 - !access_ok(VERIFY_WRITE,
121604 + !access_ok_noprefault(VERIFY_WRITE,
121605 (void __user *)(unsigned long)mem->userspace_addr,
121606 mem->memory_size)))
121607 goto out;
121608 @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
121609
121610 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
121611 {
121612 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
121613 + int r;
121614 + unsigned long addr;
121615
121616 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
121617 + addr = gfn_to_hva(kvm, gfn);
121618 + if (kvm_is_error_hva(addr))
121619 + return -EFAULT;
121620 + r = __clear_user((void __user *)addr + offset, len);
121621 + if (r)
121622 + return -EFAULT;
121623 + mark_page_dirty(kvm, gfn);
121624 + return 0;
121625 }
121626 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
121627
121628 @@ -1867,7 +1880,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
121629 return 0;
121630 }
121631
121632 -static struct file_operations kvm_vcpu_fops = {
121633 +static file_operations_no_const kvm_vcpu_fops __read_only = {
121634 .release = kvm_vcpu_release,
121635 .unlocked_ioctl = kvm_vcpu_ioctl,
121636 #ifdef CONFIG_COMPAT
121637 @@ -2532,7 +2545,7 @@ out:
121638 }
121639 #endif
121640
121641 -static struct file_operations kvm_vm_fops = {
121642 +static file_operations_no_const kvm_vm_fops __read_only = {
121643 .release = kvm_vm_release,
121644 .unlocked_ioctl = kvm_vm_ioctl,
121645 #ifdef CONFIG_COMPAT
121646 @@ -2632,7 +2645,7 @@ out:
121647 return r;
121648 }
121649
121650 -static struct file_operations kvm_chardev_ops = {
121651 +static file_operations_no_const kvm_chardev_ops __read_only = {
121652 .unlocked_ioctl = kvm_dev_ioctl,
121653 .compat_ioctl = kvm_dev_ioctl,
121654 .llseek = noop_llseek,
121655 @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
121656
121657 if (r) {
121658 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
121659 - atomic_inc(&hardware_enable_failed);
121660 + atomic_inc_unchecked(&hardware_enable_failed);
121661 printk(KERN_INFO "kvm: enabling virtualization on "
121662 "CPU%d failed\n", cpu);
121663 }
121664 @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
121665
121666 kvm_usage_count++;
121667 if (kvm_usage_count == 1) {
121668 - atomic_set(&hardware_enable_failed, 0);
121669 + atomic_set_unchecked(&hardware_enable_failed, 0);
121670 on_each_cpu(hardware_enable_nolock, NULL, 1);
121671
121672 - if (atomic_read(&hardware_enable_failed)) {
121673 + if (atomic_read_unchecked(&hardware_enable_failed)) {
121674 hardware_disable_all_nolock();
121675 r = -EBUSY;
121676 }
121677 @@ -3121,7 +3134,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
121678 kvm_arch_vcpu_put(vcpu);
121679 }
121680
121681 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
121682 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
121683 struct module *module)
121684 {
121685 int r;
121686 @@ -3168,7 +3181,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
121687 if (!vcpu_align)
121688 vcpu_align = __alignof__(struct kvm_vcpu);
121689 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
121690 - 0, NULL);
121691 + SLAB_USERCOPY, NULL);
121692 if (!kvm_vcpu_cache) {
121693 r = -ENOMEM;
121694 goto out_free_3;
121695 @@ -3178,9 +3191,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
121696 if (r)
121697 goto out_free;
121698
121699 + pax_open_kernel();
121700 kvm_chardev_ops.owner = module;
121701 kvm_vm_fops.owner = module;
121702 kvm_vcpu_fops.owner = module;
121703 + pax_close_kernel();
121704
121705 r = misc_register(&kvm_dev);
121706 if (r) {
121707 @@ -3190,9 +3205,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
121708
121709 register_syscore_ops(&kvm_syscore_ops);
121710
121711 - kvm_preempt_ops.sched_in = kvm_sched_in;
121712 - kvm_preempt_ops.sched_out = kvm_sched_out;
121713 -
121714 r = kvm_init_debug();
121715 if (r) {
121716 printk(KERN_ERR "kvm: create debugfs files failed\n");