]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.14.1-201404192355.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.14.1-201404192355.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 7d0b699..05f9ddb 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 -fno-delete-null-pointer-checks
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.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,8 @@ 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 tools/gcc/size_overflow_hash.h \
454 + tools/gcc/randomize_layout_seed.h
455
456 # clean - Delete most, but leave enough to build external modules
457 #
458 @@ -1112,6 +1187,7 @@ distclean: mrproper
459 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
460 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
461 -o -name '.*.rej' \
462 + -o -name '.*.rej' -o -name '*.so' \
463 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
464 -type f -print | xargs rm -f
465
466 @@ -1273,6 +1349,8 @@ PHONY += $(module-dirs) modules
467 $(module-dirs): crmodverdir $(objtree)/Module.symvers
468 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
469
470 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
471 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
472 modules: $(module-dirs)
473 @$(kecho) ' Building modules, stage 2.';
474 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
475 @@ -1412,17 +1490,21 @@ else
476 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
477 endif
478
479 -%.s: %.c prepare scripts FORCE
480 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
481 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
482 +%.s: %.c gcc-plugins prepare scripts FORCE
483 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
484 %.i: %.c prepare scripts FORCE
485 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
486 -%.o: %.c prepare scripts FORCE
487 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
488 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
489 +%.o: %.c gcc-plugins prepare scripts FORCE
490 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
491 %.lst: %.c prepare scripts FORCE
492 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
493 -%.s: %.S prepare scripts FORCE
494 +%.s: %.S gcc-plugins prepare scripts FORCE
495 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
496 -%.o: %.S prepare scripts FORCE
497 +%.o: %.S gcc-plugins prepare scripts FORCE
498 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
499 %.symtypes: %.c prepare scripts FORCE
500 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
501 @@ -1432,11 +1514,15 @@ endif
502 $(cmd_crmodverdir)
503 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
504 $(build)=$(build-dir)
505 -%/: prepare scripts FORCE
506 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
507 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
508 +%/: gcc-plugins prepare scripts FORCE
509 $(cmd_crmodverdir)
510 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
511 $(build)=$(build-dir)
512 -%.ko: prepare scripts FORCE
513 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
514 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
515 +%.ko: gcc-plugins prepare scripts FORCE
516 $(cmd_crmodverdir)
517 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
518 $(build)=$(build-dir) $(@:.ko=.o)
519 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
520 index 78b03ef..da28a51 100644
521 --- a/arch/alpha/include/asm/atomic.h
522 +++ b/arch/alpha/include/asm/atomic.h
523 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
524 #define atomic_dec(v) atomic_sub(1,(v))
525 #define atomic64_dec(v) atomic64_sub(1,(v))
526
527 +#define atomic64_read_unchecked(v) atomic64_read(v)
528 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
529 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
530 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
531 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
532 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
533 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
534 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
535 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
536 +
537 #define smp_mb__before_atomic_dec() smp_mb()
538 #define smp_mb__after_atomic_dec() smp_mb()
539 #define smp_mb__before_atomic_inc() smp_mb()
540 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
541 index ad368a9..fbe0f25 100644
542 --- a/arch/alpha/include/asm/cache.h
543 +++ b/arch/alpha/include/asm/cache.h
544 @@ -4,19 +4,19 @@
545 #ifndef __ARCH_ALPHA_CACHE_H
546 #define __ARCH_ALPHA_CACHE_H
547
548 +#include <linux/const.h>
549
550 /* Bytes per L1 (data) cache line. */
551 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
552 -# define L1_CACHE_BYTES 64
553 # define L1_CACHE_SHIFT 6
554 #else
555 /* Both EV4 and EV5 are write-through, read-allocate,
556 direct-mapped, physical.
557 */
558 -# define L1_CACHE_BYTES 32
559 # define L1_CACHE_SHIFT 5
560 #endif
561
562 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
563 #define SMP_CACHE_BYTES L1_CACHE_BYTES
564
565 #endif
566 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
567 index 968d999..d36b2df 100644
568 --- a/arch/alpha/include/asm/elf.h
569 +++ b/arch/alpha/include/asm/elf.h
570 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
571
572 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
573
574 +#ifdef CONFIG_PAX_ASLR
575 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
576 +
577 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
578 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
579 +#endif
580 +
581 /* $0 is set by ld.so to a pointer to a function which might be
582 registered using atexit. This provides a mean for the dynamic
583 linker to call DT_FINI functions for shared libraries that have
584 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
585 index aab14a0..b4fa3e7 100644
586 --- a/arch/alpha/include/asm/pgalloc.h
587 +++ b/arch/alpha/include/asm/pgalloc.h
588 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
589 pgd_set(pgd, pmd);
590 }
591
592 +static inline void
593 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
594 +{
595 + pgd_populate(mm, pgd, pmd);
596 +}
597 +
598 extern pgd_t *pgd_alloc(struct mm_struct *mm);
599
600 static inline void
601 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
602 index d8f9b7e..f6222fa 100644
603 --- a/arch/alpha/include/asm/pgtable.h
604 +++ b/arch/alpha/include/asm/pgtable.h
605 @@ -102,6 +102,17 @@ struct vm_area_struct;
606 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
607 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
608 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
609 +
610 +#ifdef CONFIG_PAX_PAGEEXEC
611 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
612 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
613 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
614 +#else
615 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
616 +# define PAGE_COPY_NOEXEC PAGE_COPY
617 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
618 +#endif
619 +
620 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
621
622 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
623 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
624 index 2fd00b7..cfd5069 100644
625 --- a/arch/alpha/kernel/module.c
626 +++ b/arch/alpha/kernel/module.c
627 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
628
629 /* The small sections were sorted to the end of the segment.
630 The following should definitely cover them. */
631 - gp = (u64)me->module_core + me->core_size - 0x8000;
632 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
633 got = sechdrs[me->arch.gotsecindex].sh_addr;
634
635 for (i = 0; i < n; i++) {
636 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
637 index 1402fcc..0b1abd2 100644
638 --- a/arch/alpha/kernel/osf_sys.c
639 +++ b/arch/alpha/kernel/osf_sys.c
640 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
641 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
642
643 static unsigned long
644 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
645 - unsigned long limit)
646 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
647 + unsigned long limit, unsigned long flags)
648 {
649 struct vm_unmapped_area_info info;
650 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
651
652 info.flags = 0;
653 info.length = len;
654 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
655 info.high_limit = limit;
656 info.align_mask = 0;
657 info.align_offset = 0;
658 + info.threadstack_offset = offset;
659 return vm_unmapped_area(&info);
660 }
661
662 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
663 merely specific addresses, but regions of memory -- perhaps
664 this feature should be incorporated into all ports? */
665
666 +#ifdef CONFIG_PAX_RANDMMAP
667 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
668 +#endif
669 +
670 if (addr) {
671 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
672 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
673 if (addr != (unsigned long) -ENOMEM)
674 return addr;
675 }
676
677 /* Next, try allocating at TASK_UNMAPPED_BASE. */
678 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
679 - len, limit);
680 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
681 +
682 if (addr != (unsigned long) -ENOMEM)
683 return addr;
684
685 /* Finally, try allocating in low memory. */
686 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
687 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
688
689 return addr;
690 }
691 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
692 index 98838a0..b304fb4 100644
693 --- a/arch/alpha/mm/fault.c
694 +++ b/arch/alpha/mm/fault.c
695 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
696 __reload_thread(pcb);
697 }
698
699 +#ifdef CONFIG_PAX_PAGEEXEC
700 +/*
701 + * PaX: decide what to do with offenders (regs->pc = fault address)
702 + *
703 + * returns 1 when task should be killed
704 + * 2 when patched PLT trampoline was detected
705 + * 3 when unpatched PLT trampoline was detected
706 + */
707 +static int pax_handle_fetch_fault(struct pt_regs *regs)
708 +{
709 +
710 +#ifdef CONFIG_PAX_EMUPLT
711 + int err;
712 +
713 + do { /* PaX: patched PLT emulation #1 */
714 + unsigned int ldah, ldq, jmp;
715 +
716 + err = get_user(ldah, (unsigned int *)regs->pc);
717 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
718 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
719 +
720 + if (err)
721 + break;
722 +
723 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
724 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
725 + jmp == 0x6BFB0000U)
726 + {
727 + unsigned long r27, addr;
728 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
729 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
730 +
731 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
732 + err = get_user(r27, (unsigned long *)addr);
733 + if (err)
734 + break;
735 +
736 + regs->r27 = r27;
737 + regs->pc = r27;
738 + return 2;
739 + }
740 + } while (0);
741 +
742 + do { /* PaX: patched PLT emulation #2 */
743 + unsigned int ldah, lda, br;
744 +
745 + err = get_user(ldah, (unsigned int *)regs->pc);
746 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
747 + err |= get_user(br, (unsigned int *)(regs->pc+8));
748 +
749 + if (err)
750 + break;
751 +
752 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
753 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
754 + (br & 0xFFE00000U) == 0xC3E00000U)
755 + {
756 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
757 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
758 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
759 +
760 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
761 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
762 + return 2;
763 + }
764 + } while (0);
765 +
766 + do { /* PaX: unpatched PLT emulation */
767 + unsigned int br;
768 +
769 + err = get_user(br, (unsigned int *)regs->pc);
770 +
771 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
772 + unsigned int br2, ldq, nop, jmp;
773 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
774 +
775 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
776 + err = get_user(br2, (unsigned int *)addr);
777 + err |= get_user(ldq, (unsigned int *)(addr+4));
778 + err |= get_user(nop, (unsigned int *)(addr+8));
779 + err |= get_user(jmp, (unsigned int *)(addr+12));
780 + err |= get_user(resolver, (unsigned long *)(addr+16));
781 +
782 + if (err)
783 + break;
784 +
785 + if (br2 == 0xC3600000U &&
786 + ldq == 0xA77B000CU &&
787 + nop == 0x47FF041FU &&
788 + jmp == 0x6B7B0000U)
789 + {
790 + regs->r28 = regs->pc+4;
791 + regs->r27 = addr+16;
792 + regs->pc = resolver;
793 + return 3;
794 + }
795 + }
796 + } while (0);
797 +#endif
798 +
799 + return 1;
800 +}
801 +
802 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
803 +{
804 + unsigned long i;
805 +
806 + printk(KERN_ERR "PAX: bytes at PC: ");
807 + for (i = 0; i < 5; i++) {
808 + unsigned int c;
809 + if (get_user(c, (unsigned int *)pc+i))
810 + printk(KERN_CONT "???????? ");
811 + else
812 + printk(KERN_CONT "%08x ", c);
813 + }
814 + printk("\n");
815 +}
816 +#endif
817
818 /*
819 * This routine handles page faults. It determines the address,
820 @@ -133,8 +251,29 @@ retry:
821 good_area:
822 si_code = SEGV_ACCERR;
823 if (cause < 0) {
824 - if (!(vma->vm_flags & VM_EXEC))
825 + if (!(vma->vm_flags & VM_EXEC)) {
826 +
827 +#ifdef CONFIG_PAX_PAGEEXEC
828 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
829 + goto bad_area;
830 +
831 + up_read(&mm->mmap_sem);
832 + switch (pax_handle_fetch_fault(regs)) {
833 +
834 +#ifdef CONFIG_PAX_EMUPLT
835 + case 2:
836 + case 3:
837 + return;
838 +#endif
839 +
840 + }
841 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
842 + do_group_exit(SIGKILL);
843 +#else
844 goto bad_area;
845 +#endif
846 +
847 + }
848 } else if (!cause) {
849 /* Allow reads even for write-only mappings */
850 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
851 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
852 index 1594945..adf4001 100644
853 --- a/arch/arm/Kconfig
854 +++ b/arch/arm/Kconfig
855 @@ -1862,7 +1862,7 @@ config ALIGNMENT_TRAP
856
857 config UACCESS_WITH_MEMCPY
858 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
859 - depends on MMU
860 + depends on MMU && !PAX_MEMORY_UDEREF
861 default y if CPU_FEROCEON
862 help
863 Implement faster copy_to_user and clear_user methods for CPU
864 @@ -2125,6 +2125,7 @@ config XIP_PHYS_ADDR
865 config KEXEC
866 bool "Kexec system call (EXPERIMENTAL)"
867 depends on (!SMP || PM_SLEEP_SMP)
868 + depends on !GRKERNSEC_KMEM
869 help
870 kexec is a system call that implements the ability to shutdown your
871 current kernel, and to start another kernel. It is like a reboot
872 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
873 index 62d2cb5..09d45e3 100644
874 --- a/arch/arm/include/asm/atomic.h
875 +++ b/arch/arm/include/asm/atomic.h
876 @@ -18,17 +18,35 @@
877 #include <asm/barrier.h>
878 #include <asm/cmpxchg.h>
879
880 +#ifdef CONFIG_GENERIC_ATOMIC64
881 +#include <asm-generic/atomic64.h>
882 +#endif
883 +
884 #define ATOMIC_INIT(i) { (i) }
885
886 #ifdef __KERNEL__
887
888 +#define _ASM_EXTABLE(from, to) \
889 +" .pushsection __ex_table,\"a\"\n"\
890 +" .align 3\n" \
891 +" .long " #from ", " #to"\n" \
892 +" .popsection"
893 +
894 /*
895 * On ARM, ordinary assignment (str instruction) doesn't clear the local
896 * strex/ldrex monitor on some implementations. The reason we can use it for
897 * atomic_set() is the clrex or dummy strex done on every exception return.
898 */
899 #define atomic_read(v) (*(volatile int *)&(v)->counter)
900 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
901 +{
902 + return v->counter;
903 +}
904 #define atomic_set(v,i) (((v)->counter) = (i))
905 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
906 +{
907 + v->counter = i;
908 +}
909
910 #if __LINUX_ARM_ARCH__ >= 6
911
912 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
913
914 prefetchw(&v->counter);
915 __asm__ __volatile__("@ atomic_add\n"
916 +"1: ldrex %1, [%3]\n"
917 +" adds %0, %1, %4\n"
918 +
919 +#ifdef CONFIG_PAX_REFCOUNT
920 +" bvc 3f\n"
921 +"2: bkpt 0xf103\n"
922 +"3:\n"
923 +#endif
924 +
925 +" strex %1, %0, [%3]\n"
926 +" teq %1, #0\n"
927 +" bne 1b"
928 +
929 +#ifdef CONFIG_PAX_REFCOUNT
930 +"\n4:\n"
931 + _ASM_EXTABLE(2b, 4b)
932 +#endif
933 +
934 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
935 + : "r" (&v->counter), "Ir" (i)
936 + : "cc");
937 +}
938 +
939 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
940 +{
941 + unsigned long tmp;
942 + int result;
943 +
944 + prefetchw(&v->counter);
945 + __asm__ __volatile__("@ atomic_add_unchecked\n"
946 "1: ldrex %0, [%3]\n"
947 " add %0, %0, %4\n"
948 " strex %1, %0, [%3]\n"
949 @@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
950 smp_mb();
951
952 __asm__ __volatile__("@ atomic_add_return\n"
953 +"1: ldrex %1, [%3]\n"
954 +" adds %0, %1, %4\n"
955 +
956 +#ifdef CONFIG_PAX_REFCOUNT
957 +" bvc 3f\n"
958 +" mov %0, %1\n"
959 +"2: bkpt 0xf103\n"
960 +"3:\n"
961 +#endif
962 +
963 +" strex %1, %0, [%3]\n"
964 +" teq %1, #0\n"
965 +" bne 1b"
966 +
967 +#ifdef CONFIG_PAX_REFCOUNT
968 +"\n4:\n"
969 + _ASM_EXTABLE(2b, 4b)
970 +#endif
971 +
972 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
973 + : "r" (&v->counter), "Ir" (i)
974 + : "cc");
975 +
976 + smp_mb();
977 +
978 + return result;
979 +}
980 +
981 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
982 +{
983 + unsigned long tmp;
984 + int result;
985 +
986 + smp_mb();
987 +
988 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
989 "1: ldrex %0, [%3]\n"
990 " add %0, %0, %4\n"
991 " strex %1, %0, [%3]\n"
992 @@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
993
994 prefetchw(&v->counter);
995 __asm__ __volatile__("@ atomic_sub\n"
996 +"1: ldrex %1, [%3]\n"
997 +" subs %0, %1, %4\n"
998 +
999 +#ifdef CONFIG_PAX_REFCOUNT
1000 +" bvc 3f\n"
1001 +"2: bkpt 0xf103\n"
1002 +"3:\n"
1003 +#endif
1004 +
1005 +" strex %1, %0, [%3]\n"
1006 +" teq %1, #0\n"
1007 +" bne 1b"
1008 +
1009 +#ifdef CONFIG_PAX_REFCOUNT
1010 +"\n4:\n"
1011 + _ASM_EXTABLE(2b, 4b)
1012 +#endif
1013 +
1014 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1015 + : "r" (&v->counter), "Ir" (i)
1016 + : "cc");
1017 +}
1018 +
1019 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1020 +{
1021 + unsigned long tmp;
1022 + int result;
1023 +
1024 + prefetchw(&v->counter);
1025 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1026 "1: ldrex %0, [%3]\n"
1027 " sub %0, %0, %4\n"
1028 " strex %1, %0, [%3]\n"
1029 @@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1030 smp_mb();
1031
1032 __asm__ __volatile__("@ atomic_sub_return\n"
1033 -"1: ldrex %0, [%3]\n"
1034 -" sub %0, %0, %4\n"
1035 +"1: ldrex %1, [%3]\n"
1036 +" subs %0, %1, %4\n"
1037 +
1038 +#ifdef CONFIG_PAX_REFCOUNT
1039 +" bvc 3f\n"
1040 +" mov %0, %1\n"
1041 +"2: bkpt 0xf103\n"
1042 +"3:\n"
1043 +#endif
1044 +
1045 " strex %1, %0, [%3]\n"
1046 " teq %1, #0\n"
1047 " bne 1b"
1048 +
1049 +#ifdef CONFIG_PAX_REFCOUNT
1050 +"\n4:\n"
1051 + _ASM_EXTABLE(2b, 4b)
1052 +#endif
1053 +
1054 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1055 : "r" (&v->counter), "Ir" (i)
1056 : "cc");
1057 @@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1058 return oldval;
1059 }
1060
1061 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1062 +{
1063 + unsigned long oldval, res;
1064 +
1065 + smp_mb();
1066 +
1067 + do {
1068 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1069 + "ldrex %1, [%3]\n"
1070 + "mov %0, #0\n"
1071 + "teq %1, %4\n"
1072 + "strexeq %0, %5, [%3]\n"
1073 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1074 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1075 + : "cc");
1076 + } while (res);
1077 +
1078 + smp_mb();
1079 +
1080 + return oldval;
1081 +}
1082 +
1083 #else /* ARM_ARCH_6 */
1084
1085 #ifdef CONFIG_SMP
1086 @@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1087
1088 return val;
1089 }
1090 +
1091 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1092 +{
1093 + return atomic_add_return(i, v);
1094 +}
1095 +
1096 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1097 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1098 +{
1099 + (void) atomic_add_return(i, v);
1100 +}
1101
1102 static inline int atomic_sub_return(int i, atomic_t *v)
1103 {
1104 @@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1105 return val;
1106 }
1107 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1108 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1109 +{
1110 + (void) atomic_sub_return(i, v);
1111 +}
1112
1113 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1114 {
1115 @@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1116 return ret;
1117 }
1118
1119 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1120 +{
1121 + return atomic_cmpxchg(v, old, new);
1122 +}
1123 +
1124 #endif /* __LINUX_ARM_ARCH__ */
1125
1126 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1127 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1128 +{
1129 + return xchg(&v->counter, new);
1130 +}
1131
1132 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1133 {
1134 @@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1135 }
1136
1137 #define atomic_inc(v) atomic_add(1, v)
1138 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1139 +{
1140 + atomic_add_unchecked(1, v);
1141 +}
1142 #define atomic_dec(v) atomic_sub(1, v)
1143 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1144 +{
1145 + atomic_sub_unchecked(1, v);
1146 +}
1147
1148 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1149 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1150 +{
1151 + return atomic_add_return_unchecked(1, v) == 0;
1152 +}
1153 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1154 #define atomic_inc_return(v) (atomic_add_return(1, v))
1155 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1156 +{
1157 + return atomic_add_return_unchecked(1, v);
1158 +}
1159 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1160 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1161
1162 @@ -221,6 +410,14 @@ typedef struct {
1163 long long counter;
1164 } atomic64_t;
1165
1166 +#ifdef CONFIG_PAX_REFCOUNT
1167 +typedef struct {
1168 + long long counter;
1169 +} atomic64_unchecked_t;
1170 +#else
1171 +typedef atomic64_t atomic64_unchecked_t;
1172 +#endif
1173 +
1174 #define ATOMIC64_INIT(i) { (i) }
1175
1176 #ifdef CONFIG_ARM_LPAE
1177 @@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1178 return result;
1179 }
1180
1181 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1182 +{
1183 + long long result;
1184 +
1185 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1186 +" ldrd %0, %H0, [%1]"
1187 + : "=&r" (result)
1188 + : "r" (&v->counter), "Qo" (v->counter)
1189 + );
1190 +
1191 + return result;
1192 +}
1193 +
1194 static inline void atomic64_set(atomic64_t *v, long long i)
1195 {
1196 __asm__ __volatile__("@ atomic64_set\n"
1197 @@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1198 : "r" (&v->counter), "r" (i)
1199 );
1200 }
1201 +
1202 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1203 +{
1204 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1205 +" strd %2, %H2, [%1]"
1206 + : "=Qo" (v->counter)
1207 + : "r" (&v->counter), "r" (i)
1208 + );
1209 +}
1210 #else
1211 static inline long long atomic64_read(const atomic64_t *v)
1212 {
1213 @@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1214 return result;
1215 }
1216
1217 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1218 +{
1219 + long long result;
1220 +
1221 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1222 +" ldrexd %0, %H0, [%1]"
1223 + : "=&r" (result)
1224 + : "r" (&v->counter), "Qo" (v->counter)
1225 + );
1226 +
1227 + return result;
1228 +}
1229 +
1230 static inline void atomic64_set(atomic64_t *v, long long i)
1231 {
1232 long long tmp;
1233 @@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1234 : "r" (&v->counter), "r" (i)
1235 : "cc");
1236 }
1237 +
1238 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1239 +{
1240 + long long tmp;
1241 +
1242 + prefetchw(&v->counter);
1243 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1244 +"1: ldrexd %0, %H0, [%2]\n"
1245 +" strexd %0, %3, %H3, [%2]\n"
1246 +" teq %0, #0\n"
1247 +" bne 1b"
1248 + : "=&r" (tmp), "=Qo" (v->counter)
1249 + : "r" (&v->counter), "r" (i)
1250 + : "cc");
1251 +}
1252 #endif
1253
1254 static inline void atomic64_add(long long i, atomic64_t *v)
1255 @@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1256 __asm__ __volatile__("@ atomic64_add\n"
1257 "1: ldrexd %0, %H0, [%3]\n"
1258 " adds %Q0, %Q0, %Q4\n"
1259 +" adcs %R0, %R0, %R4\n"
1260 +
1261 +#ifdef CONFIG_PAX_REFCOUNT
1262 +" bvc 3f\n"
1263 +"2: bkpt 0xf103\n"
1264 +"3:\n"
1265 +#endif
1266 +
1267 +" strexd %1, %0, %H0, [%3]\n"
1268 +" teq %1, #0\n"
1269 +" bne 1b"
1270 +
1271 +#ifdef CONFIG_PAX_REFCOUNT
1272 +"\n4:\n"
1273 + _ASM_EXTABLE(2b, 4b)
1274 +#endif
1275 +
1276 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1277 + : "r" (&v->counter), "r" (i)
1278 + : "cc");
1279 +}
1280 +
1281 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1282 +{
1283 + long long result;
1284 + unsigned long tmp;
1285 +
1286 + prefetchw(&v->counter);
1287 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1288 +"1: ldrexd %0, %H0, [%3]\n"
1289 +" adds %Q0, %Q0, %Q4\n"
1290 " adc %R0, %R0, %R4\n"
1291 " strexd %1, %0, %H0, [%3]\n"
1292 " teq %1, #0\n"
1293 @@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1294 __asm__ __volatile__("@ atomic64_add_return\n"
1295 "1: ldrexd %0, %H0, [%3]\n"
1296 " adds %Q0, %Q0, %Q4\n"
1297 +" adcs %R0, %R0, %R4\n"
1298 +
1299 +#ifdef CONFIG_PAX_REFCOUNT
1300 +" bvc 3f\n"
1301 +" mov %0, %1\n"
1302 +" mov %H0, %H1\n"
1303 +"2: bkpt 0xf103\n"
1304 +"3:\n"
1305 +#endif
1306 +
1307 +" strexd %1, %0, %H0, [%3]\n"
1308 +" teq %1, #0\n"
1309 +" bne 1b"
1310 +
1311 +#ifdef CONFIG_PAX_REFCOUNT
1312 +"\n4:\n"
1313 + _ASM_EXTABLE(2b, 4b)
1314 +#endif
1315 +
1316 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1317 + : "r" (&v->counter), "r" (i)
1318 + : "cc");
1319 +
1320 + smp_mb();
1321 +
1322 + return result;
1323 +}
1324 +
1325 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1326 +{
1327 + long long result;
1328 + unsigned long tmp;
1329 +
1330 + smp_mb();
1331 +
1332 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1333 +"1: ldrexd %0, %H0, [%3]\n"
1334 +" adds %Q0, %Q0, %Q4\n"
1335 " adc %R0, %R0, %R4\n"
1336 " strexd %1, %0, %H0, [%3]\n"
1337 " teq %1, #0\n"
1338 @@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1339 __asm__ __volatile__("@ atomic64_sub\n"
1340 "1: ldrexd %0, %H0, [%3]\n"
1341 " subs %Q0, %Q0, %Q4\n"
1342 +" sbcs %R0, %R0, %R4\n"
1343 +
1344 +#ifdef CONFIG_PAX_REFCOUNT
1345 +" bvc 3f\n"
1346 +"2: bkpt 0xf103\n"
1347 +"3:\n"
1348 +#endif
1349 +
1350 +" strexd %1, %0, %H0, [%3]\n"
1351 +" teq %1, #0\n"
1352 +" bne 1b"
1353 +
1354 +#ifdef CONFIG_PAX_REFCOUNT
1355 +"\n4:\n"
1356 + _ASM_EXTABLE(2b, 4b)
1357 +#endif
1358 +
1359 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1360 + : "r" (&v->counter), "r" (i)
1361 + : "cc");
1362 +}
1363 +
1364 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1365 +{
1366 + long long result;
1367 + unsigned long tmp;
1368 +
1369 + prefetchw(&v->counter);
1370 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1371 +"1: ldrexd %0, %H0, [%3]\n"
1372 +" subs %Q0, %Q0, %Q4\n"
1373 " sbc %R0, %R0, %R4\n"
1374 " strexd %1, %0, %H0, [%3]\n"
1375 " teq %1, #0\n"
1376 @@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1377 __asm__ __volatile__("@ atomic64_sub_return\n"
1378 "1: ldrexd %0, %H0, [%3]\n"
1379 " subs %Q0, %Q0, %Q4\n"
1380 -" sbc %R0, %R0, %R4\n"
1381 +" sbcs %R0, %R0, %R4\n"
1382 +
1383 +#ifdef CONFIG_PAX_REFCOUNT
1384 +" bvc 3f\n"
1385 +" mov %0, %1\n"
1386 +" mov %H0, %H1\n"
1387 +"2: bkpt 0xf103\n"
1388 +"3:\n"
1389 +#endif
1390 +
1391 " strexd %1, %0, %H0, [%3]\n"
1392 " teq %1, #0\n"
1393 " bne 1b"
1394 +
1395 +#ifdef CONFIG_PAX_REFCOUNT
1396 +"\n4:\n"
1397 + _ASM_EXTABLE(2b, 4b)
1398 +#endif
1399 +
1400 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1401 : "r" (&v->counter), "r" (i)
1402 : "cc");
1403
1404 - smp_mb();
1405 -
1406 return result;
1407 }
1408
1409 @@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1410 return oldval;
1411 }
1412
1413 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1414 + long long new)
1415 +{
1416 + long long oldval;
1417 + unsigned long res;
1418 +
1419 + smp_mb();
1420 +
1421 + do {
1422 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1423 + "ldrexd %1, %H1, [%3]\n"
1424 + "mov %0, #0\n"
1425 + "teq %1, %4\n"
1426 + "teqeq %H1, %H4\n"
1427 + "strexdeq %0, %5, %H5, [%3]"
1428 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1429 + : "r" (&ptr->counter), "r" (old), "r" (new)
1430 + : "cc");
1431 + } while (res);
1432 +
1433 + smp_mb();
1434 +
1435 + return oldval;
1436 +}
1437 +
1438 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1439 {
1440 long long result;
1441 @@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1443 {
1444 long long result;
1445 - unsigned long tmp;
1446 + u64 tmp;
1447
1448 smp_mb();
1449
1450 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1451 -"1: ldrexd %0, %H0, [%3]\n"
1452 -" subs %Q0, %Q0, #1\n"
1453 -" sbc %R0, %R0, #0\n"
1454 +"1: ldrexd %1, %H1, [%3]\n"
1455 +" subs %Q0, %Q1, #1\n"
1456 +" sbcs %R0, %R1, #0\n"
1457 +
1458 +#ifdef CONFIG_PAX_REFCOUNT
1459 +" bvc 3f\n"
1460 +" mov %Q0, %Q1\n"
1461 +" mov %R0, %R1\n"
1462 +"2: bkpt 0xf103\n"
1463 +"3:\n"
1464 +#endif
1465 +
1466 " teq %R0, #0\n"
1467 -" bmi 2f\n"
1468 +" bmi 4f\n"
1469 " strexd %1, %0, %H0, [%3]\n"
1470 " teq %1, #0\n"
1471 " bne 1b\n"
1472 -"2:"
1473 +"4:\n"
1474 +
1475 +#ifdef CONFIG_PAX_REFCOUNT
1476 + _ASM_EXTABLE(2b, 4b)
1477 +#endif
1478 +
1479 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1480 : "r" (&v->counter)
1481 : "cc");
1482 @@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1483 " teq %0, %5\n"
1484 " teqeq %H0, %H5\n"
1485 " moveq %1, #0\n"
1486 -" beq 2f\n"
1487 +" beq 4f\n"
1488 " adds %Q0, %Q0, %Q6\n"
1489 -" adc %R0, %R0, %R6\n"
1490 +" adcs %R0, %R0, %R6\n"
1491 +
1492 +#ifdef CONFIG_PAX_REFCOUNT
1493 +" bvc 3f\n"
1494 +"2: bkpt 0xf103\n"
1495 +"3:\n"
1496 +#endif
1497 +
1498 " strexd %2, %0, %H0, [%4]\n"
1499 " teq %2, #0\n"
1500 " bne 1b\n"
1501 -"2:"
1502 +"4:\n"
1503 +
1504 +#ifdef CONFIG_PAX_REFCOUNT
1505 + _ASM_EXTABLE(2b, 4b)
1506 +#endif
1507 +
1508 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1509 : "r" (&v->counter), "r" (u), "r" (a)
1510 : "cc");
1511 @@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1512
1513 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1514 #define atomic64_inc(v) atomic64_add(1LL, (v))
1515 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1516 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1517 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1518 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1519 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1520 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1521 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1522 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1523 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1524 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1525 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1526 index 75fe66b..ba3dee4 100644
1527 --- a/arch/arm/include/asm/cache.h
1528 +++ b/arch/arm/include/asm/cache.h
1529 @@ -4,8 +4,10 @@
1530 #ifndef __ASMARM_CACHE_H
1531 #define __ASMARM_CACHE_H
1532
1533 +#include <linux/const.h>
1534 +
1535 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1536 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1537 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1538
1539 /*
1540 * Memory returned by kmalloc() may be used for DMA, so we must make
1541 @@ -24,5 +26,6 @@
1542 #endif
1543
1544 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1545 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1546
1547 #endif
1548 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1549 index 8b8b616..d973d24 100644
1550 --- a/arch/arm/include/asm/cacheflush.h
1551 +++ b/arch/arm/include/asm/cacheflush.h
1552 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1553 void (*dma_unmap_area)(const void *, size_t, int);
1554
1555 void (*dma_flush_range)(const void *, const void *);
1556 -};
1557 +} __no_const;
1558
1559 /*
1560 * Select the calling method
1561 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1562 index 5233151..87a71fa 100644
1563 --- a/arch/arm/include/asm/checksum.h
1564 +++ b/arch/arm/include/asm/checksum.h
1565 @@ -37,7 +37,19 @@ __wsum
1566 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1567
1568 __wsum
1569 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1570 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1571 +
1572 +static inline __wsum
1573 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1574 +{
1575 + __wsum ret;
1576 + pax_open_userland();
1577 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1578 + pax_close_userland();
1579 + return ret;
1580 +}
1581 +
1582 +
1583
1584 /*
1585 * Fold a partial checksum without adding pseudo headers
1586 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1587 index df2fbba..63fe3e1 100644
1588 --- a/arch/arm/include/asm/cmpxchg.h
1589 +++ b/arch/arm/include/asm/cmpxchg.h
1590 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1591
1592 #define xchg(ptr,x) \
1593 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1594 +#define xchg_unchecked(ptr,x) \
1595 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1596
1597 #include <asm-generic/cmpxchg-local.h>
1598
1599 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1600 index 6ddbe44..b5e38b1 100644
1601 --- a/arch/arm/include/asm/domain.h
1602 +++ b/arch/arm/include/asm/domain.h
1603 @@ -48,18 +48,37 @@
1604 * Domain types
1605 */
1606 #define DOMAIN_NOACCESS 0
1607 -#define DOMAIN_CLIENT 1
1608 #ifdef CONFIG_CPU_USE_DOMAINS
1609 +#define DOMAIN_USERCLIENT 1
1610 +#define DOMAIN_KERNELCLIENT 1
1611 #define DOMAIN_MANAGER 3
1612 +#define DOMAIN_VECTORS DOMAIN_USER
1613 #else
1614 +
1615 +#ifdef CONFIG_PAX_KERNEXEC
1616 #define DOMAIN_MANAGER 1
1617 +#define DOMAIN_KERNEXEC 3
1618 +#else
1619 +#define DOMAIN_MANAGER 1
1620 +#endif
1621 +
1622 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1623 +#define DOMAIN_USERCLIENT 0
1624 +#define DOMAIN_UDEREF 1
1625 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1626 +#else
1627 +#define DOMAIN_USERCLIENT 1
1628 +#define DOMAIN_VECTORS DOMAIN_USER
1629 +#endif
1630 +#define DOMAIN_KERNELCLIENT 1
1631 +
1632 #endif
1633
1634 #define domain_val(dom,type) ((type) << (2*(dom)))
1635
1636 #ifndef __ASSEMBLY__
1637
1638 -#ifdef CONFIG_CPU_USE_DOMAINS
1639 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1640 static inline void set_domain(unsigned val)
1641 {
1642 asm volatile(
1643 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1644 isb();
1645 }
1646
1647 -#define modify_domain(dom,type) \
1648 - do { \
1649 - struct thread_info *thread = current_thread_info(); \
1650 - unsigned int domain = thread->cpu_domain; \
1651 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1652 - thread->cpu_domain = domain | domain_val(dom, type); \
1653 - set_domain(thread->cpu_domain); \
1654 - } while (0)
1655 -
1656 +extern void modify_domain(unsigned int dom, unsigned int type);
1657 #else
1658 static inline void set_domain(unsigned val) { }
1659 static inline void modify_domain(unsigned dom, unsigned type) { }
1660 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1661 index f4b46d3..abc9b2b 100644
1662 --- a/arch/arm/include/asm/elf.h
1663 +++ b/arch/arm/include/asm/elf.h
1664 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 the loader. We need to make sure that it is out of the way of the program
1666 that it will "exec", and that there is sufficient room for the brk. */
1667
1668 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1669 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1670 +
1671 +#ifdef CONFIG_PAX_ASLR
1672 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1673 +
1674 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1675 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1676 +#endif
1677
1678 /* When the program starts, a1 contains a pointer to a function to be
1679 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1680 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1681 extern void elf_set_personality(const struct elf32_hdr *);
1682 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1683
1684 -struct mm_struct;
1685 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1686 -#define arch_randomize_brk arch_randomize_brk
1687 -
1688 #ifdef CONFIG_MMU
1689 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1690 struct linux_binprm;
1691 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1692 index de53547..52b9a28 100644
1693 --- a/arch/arm/include/asm/fncpy.h
1694 +++ b/arch/arm/include/asm/fncpy.h
1695 @@ -81,7 +81,9 @@
1696 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1697 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1698 \
1699 + pax_open_kernel(); \
1700 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1701 + pax_close_kernel(); \
1702 flush_icache_range((unsigned long)(dest_buf), \
1703 (unsigned long)(dest_buf) + (size)); \
1704 \
1705 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1706 index e42cf59..7b94b8f 100644
1707 --- a/arch/arm/include/asm/futex.h
1708 +++ b/arch/arm/include/asm/futex.h
1709 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1710 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1711 return -EFAULT;
1712
1713 + pax_open_userland();
1714 +
1715 smp_mb();
1716 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1717 "1: ldrex %1, [%4]\n"
1718 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1719 : "cc", "memory");
1720 smp_mb();
1721
1722 + pax_close_userland();
1723 +
1724 *uval = val;
1725 return ret;
1726 }
1727 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1728 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1729 return -EFAULT;
1730
1731 + pax_open_userland();
1732 +
1733 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1734 "1: " TUSER(ldr) " %1, [%4]\n"
1735 " teq %1, %2\n"
1736 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1737 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1738 : "cc", "memory");
1739
1740 + pax_close_userland();
1741 +
1742 *uval = val;
1743 return ret;
1744 }
1745 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1746 return -EFAULT;
1747
1748 pagefault_disable(); /* implies preempt_disable() */
1749 + pax_open_userland();
1750
1751 switch (op) {
1752 case FUTEX_OP_SET:
1753 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1754 ret = -ENOSYS;
1755 }
1756
1757 + pax_close_userland();
1758 pagefault_enable(); /* subsumes preempt_enable() */
1759
1760 if (!ret) {
1761 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1762 index 83eb2f7..ed77159 100644
1763 --- a/arch/arm/include/asm/kmap_types.h
1764 +++ b/arch/arm/include/asm/kmap_types.h
1765 @@ -4,6 +4,6 @@
1766 /*
1767 * This is the "bare minimum". AIO seems to require this.
1768 */
1769 -#define KM_TYPE_NR 16
1770 +#define KM_TYPE_NR 17
1771
1772 #endif
1773 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1774 index 9e614a1..3302cca 100644
1775 --- a/arch/arm/include/asm/mach/dma.h
1776 +++ b/arch/arm/include/asm/mach/dma.h
1777 @@ -22,7 +22,7 @@ struct dma_ops {
1778 int (*residue)(unsigned int, dma_t *); /* optional */
1779 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1780 const char *type;
1781 -};
1782 +} __do_const;
1783
1784 struct dma_struct {
1785 void *addr; /* single DMA address */
1786 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1787 index f98c7f3..6d2a756 100644
1788 --- a/arch/arm/include/asm/mach/map.h
1789 +++ b/arch/arm/include/asm/mach/map.h
1790 @@ -24,16 +24,18 @@ struct map_desc {
1791 /* types 0-3 are defined in asm/io.h */
1792 enum {
1793 MT_UNCACHED = 4,
1794 - MT_CACHECLEAN,
1795 - MT_MINICLEAN,
1796 + MT_CACHECLEAN_RO,
1797 + MT_MINICLEAN_RO,
1798 MT_LOW_VECTORS,
1799 MT_HIGH_VECTORS,
1800 - MT_MEMORY_RWX,
1801 + __MT_MEMORY_RWX,
1802 MT_MEMORY_RW,
1803 + MT_MEMORY_RX,
1804 MT_ROM,
1805 - MT_MEMORY_RWX_NONCACHED,
1806 + MT_MEMORY_RW_NONCACHED,
1807 + MT_MEMORY_RX_NONCACHED,
1808 MT_MEMORY_RW_DTCM,
1809 - MT_MEMORY_RWX_ITCM,
1810 + MT_MEMORY_RX_ITCM,
1811 MT_MEMORY_RW_SO,
1812 MT_MEMORY_DMA_READY,
1813 };
1814 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1815 index f94784f..9a09a4a 100644
1816 --- a/arch/arm/include/asm/outercache.h
1817 +++ b/arch/arm/include/asm/outercache.h
1818 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1819 #endif
1820 void (*set_debug)(unsigned long);
1821 void (*resume)(void);
1822 -};
1823 +} __no_const;
1824
1825 extern struct outer_cache_fns outer_cache;
1826
1827 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1828 index 4355f0e..cd9168e 100644
1829 --- a/arch/arm/include/asm/page.h
1830 +++ b/arch/arm/include/asm/page.h
1831 @@ -23,6 +23,7 @@
1832
1833 #else
1834
1835 +#include <linux/compiler.h>
1836 #include <asm/glue.h>
1837
1838 /*
1839 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1840 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1841 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1842 unsigned long vaddr, struct vm_area_struct *vma);
1843 -};
1844 +} __no_const;
1845
1846 #ifdef MULTI_USER
1847 extern struct cpu_user_fns cpu_user;
1848 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1849 index 78a7793..e3dc06c 100644
1850 --- a/arch/arm/include/asm/pgalloc.h
1851 +++ b/arch/arm/include/asm/pgalloc.h
1852 @@ -17,6 +17,7 @@
1853 #include <asm/processor.h>
1854 #include <asm/cacheflush.h>
1855 #include <asm/tlbflush.h>
1856 +#include <asm/system_info.h>
1857
1858 #define check_pgt_cache() do { } while (0)
1859
1860 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1861 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1862 }
1863
1864 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1865 +{
1866 + pud_populate(mm, pud, pmd);
1867 +}
1868 +
1869 #else /* !CONFIG_ARM_LPAE */
1870
1871 /*
1872 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1873 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1874 #define pmd_free(mm, pmd) do { } while (0)
1875 #define pud_populate(mm,pmd,pte) BUG()
1876 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1877
1878 #endif /* CONFIG_ARM_LPAE */
1879
1880 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1881 __free_page(pte);
1882 }
1883
1884 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1885 +{
1886 +#ifdef CONFIG_ARM_LPAE
1887 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1888 +#else
1889 + if (addr & SECTION_SIZE)
1890 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1891 + else
1892 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1893 +#endif
1894 + flush_pmd_entry(pmdp);
1895 +}
1896 +
1897 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1898 pmdval_t prot)
1899 {
1900 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1901 static inline void
1902 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1903 {
1904 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1905 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1906 }
1907 #define pmd_pgtable(pmd) pmd_page(pmd)
1908
1909 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1910 index 5cfba15..f415e1a 100644
1911 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1912 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1913 @@ -20,12 +20,15 @@
1914 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1915 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1916 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1917 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1918 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1919 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1920 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1921 +
1922 /*
1923 * - section
1924 */
1925 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1926 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1927 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1928 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1929 @@ -37,6 +40,7 @@
1930 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1931 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1932 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1933 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1934
1935 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1936 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1937 @@ -66,6 +70,7 @@
1938 * - extended small page/tiny page
1939 */
1940 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1941 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1942 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1943 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1944 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1945 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1946 index dfff709..ed4c4e7 100644
1947 --- a/arch/arm/include/asm/pgtable-2level.h
1948 +++ b/arch/arm/include/asm/pgtable-2level.h
1949 @@ -126,6 +126,9 @@
1950 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1951 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1952
1953 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1954 +#define L_PTE_PXN (_AT(pteval_t, 0))
1955 +
1956 /*
1957 * These are the memory types, defined to be compatible with
1958 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1959 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1960 index 626989f..9d67a33 100644
1961 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1962 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1963 @@ -75,6 +75,7 @@
1964 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1965 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1966 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1967 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1968 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1969
1970 /*
1971 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1972 index 85c60ad..b0bbd7e 100644
1973 --- a/arch/arm/include/asm/pgtable-3level.h
1974 +++ b/arch/arm/include/asm/pgtable-3level.h
1975 @@ -82,6 +82,7 @@
1976 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1977 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1978 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1979 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1980 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1981 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1982 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1983 @@ -95,6 +96,7 @@
1984 /*
1985 * To be used in assembly code with the upper page attributes.
1986 */
1987 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1988 #define L_PTE_XN_HIGH (1 << (54 - 32))
1989 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1990
1991 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1992 index 7d59b52..27a12f8 100644
1993 --- a/arch/arm/include/asm/pgtable.h
1994 +++ b/arch/arm/include/asm/pgtable.h
1995 @@ -33,6 +33,9 @@
1996 #include <asm/pgtable-2level.h>
1997 #endif
1998
1999 +#define ktla_ktva(addr) (addr)
2000 +#define ktva_ktla(addr) (addr)
2001 +
2002 /*
2003 * Just any arbitrary offset to the start of the vmalloc VM area: the
2004 * current 8MB value just means that there will be a 8MB "hole" after the
2005 @@ -48,6 +51,9 @@
2006 #define LIBRARY_TEXT_START 0x0c000000
2007
2008 #ifndef __ASSEMBLY__
2009 +extern pteval_t __supported_pte_mask;
2010 +extern pmdval_t __supported_pmd_mask;
2011 +
2012 extern void __pte_error(const char *file, int line, pte_t);
2013 extern void __pmd_error(const char *file, int line, pmd_t);
2014 extern void __pgd_error(const char *file, int line, pgd_t);
2015 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2016 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2017 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2018
2019 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2020 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2021 +
2022 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2023 +#include <asm/domain.h>
2024 +#include <linux/thread_info.h>
2025 +#include <linux/preempt.h>
2026 +
2027 +static inline int test_domain(int domain, int domaintype)
2028 +{
2029 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2030 +}
2031 +#endif
2032 +
2033 +#ifdef CONFIG_PAX_KERNEXEC
2034 +static inline unsigned long pax_open_kernel(void) {
2035 +#ifdef CONFIG_ARM_LPAE
2036 + /* TODO */
2037 +#else
2038 + preempt_disable();
2039 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2040 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2041 +#endif
2042 + return 0;
2043 +}
2044 +
2045 +static inline unsigned long pax_close_kernel(void) {
2046 +#ifdef CONFIG_ARM_LPAE
2047 + /* TODO */
2048 +#else
2049 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2050 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2051 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2052 + preempt_enable_no_resched();
2053 +#endif
2054 + return 0;
2055 +}
2056 +#else
2057 +static inline unsigned long pax_open_kernel(void) { return 0; }
2058 +static inline unsigned long pax_close_kernel(void) { return 0; }
2059 +#endif
2060 +
2061 /*
2062 * This is the lowest virtual address we can permit any user space
2063 * mapping to be mapped at. This is particularly important for
2064 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2065 /*
2066 * The pgprot_* and protection_map entries will be fixed up in runtime
2067 * to include the cachable and bufferable bits based on memory policy,
2068 - * as well as any architecture dependent bits like global/ASID and SMP
2069 - * shared mapping bits.
2070 + * as well as any architecture dependent bits like global/ASID, PXN,
2071 + * and SMP shared mapping bits.
2072 */
2073 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2074
2075 @@ -262,7 +310,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2076 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2077 {
2078 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2079 - L_PTE_NONE | L_PTE_VALID;
2080 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2081 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2082 return pte;
2083 }
2084 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2085 index c4ae171..ea0c0c2 100644
2086 --- a/arch/arm/include/asm/psci.h
2087 +++ b/arch/arm/include/asm/psci.h
2088 @@ -29,7 +29,7 @@ struct psci_operations {
2089 int (*cpu_off)(struct psci_power_state state);
2090 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2091 int (*migrate)(unsigned long cpuid);
2092 -};
2093 +} __no_const;
2094
2095 extern struct psci_operations psci_ops;
2096 extern struct smp_operations psci_smp_ops;
2097 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2098 index 22a3b9b..7f214ee 100644
2099 --- a/arch/arm/include/asm/smp.h
2100 +++ b/arch/arm/include/asm/smp.h
2101 @@ -112,7 +112,7 @@ struct smp_operations {
2102 int (*cpu_disable)(unsigned int cpu);
2103 #endif
2104 #endif
2105 -};
2106 +} __no_const;
2107
2108 /*
2109 * set platform specific SMP operations
2110 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2111 index 71a06b2..8bb9ae1 100644
2112 --- a/arch/arm/include/asm/thread_info.h
2113 +++ b/arch/arm/include/asm/thread_info.h
2114 @@ -88,9 +88,9 @@ struct thread_info {
2115 .flags = 0, \
2116 .preempt_count = INIT_PREEMPT_COUNT, \
2117 .addr_limit = KERNEL_DS, \
2118 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2119 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2120 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2121 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2122 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2123 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2124 .restart_block = { \
2125 .fn = do_no_restart_syscall, \
2126 }, \
2127 @@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2128 #define TIF_SYSCALL_AUDIT 9
2129 #define TIF_SYSCALL_TRACEPOINT 10
2130 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2131 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2132 +/* within 8 bits of TIF_SYSCALL_TRACE
2133 + * to meet flexible second operand requirements
2134 + */
2135 +#define TIF_GRSEC_SETXID 12
2136 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2137 #define TIF_USING_IWMMXT 17
2138 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2139 #define TIF_RESTORE_SIGMASK 20
2140 @@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2141 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2142 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2143 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2144 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2145
2146 /* Checks for any syscall work in entry-common.S */
2147 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2148 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2149 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2150
2151 /*
2152 * Change these and you break ASM code in entry-common.S
2153 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2154 index 72abdc5..35acac1 100644
2155 --- a/arch/arm/include/asm/uaccess.h
2156 +++ b/arch/arm/include/asm/uaccess.h
2157 @@ -18,6 +18,7 @@
2158 #include <asm/domain.h>
2159 #include <asm/unified.h>
2160 #include <asm/compiler.h>
2161 +#include <asm/pgtable.h>
2162
2163 #if __LINUX_ARM_ARCH__ < 6
2164 #include <asm-generic/uaccess-unaligned.h>
2165 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2166 static inline void set_fs(mm_segment_t fs)
2167 {
2168 current_thread_info()->addr_limit = fs;
2169 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2170 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2171 }
2172
2173 #define segment_eq(a,b) ((a) == (b))
2174
2175 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2176 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2177 +
2178 +static inline void pax_open_userland(void)
2179 +{
2180 +
2181 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2182 + if (segment_eq(get_fs(), USER_DS)) {
2183 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2184 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2185 + }
2186 +#endif
2187 +
2188 +}
2189 +
2190 +static inline void pax_close_userland(void)
2191 +{
2192 +
2193 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2194 + if (segment_eq(get_fs(), USER_DS)) {
2195 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2196 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2197 + }
2198 +#endif
2199 +
2200 +}
2201 +
2202 #define __addr_ok(addr) ({ \
2203 unsigned long flag; \
2204 __asm__("cmp %2, %0; movlo %0, #0" \
2205 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2206
2207 #define get_user(x,p) \
2208 ({ \
2209 + int __e; \
2210 might_fault(); \
2211 - __get_user_check(x,p); \
2212 + pax_open_userland(); \
2213 + __e = __get_user_check(x,p); \
2214 + pax_close_userland(); \
2215 + __e; \
2216 })
2217
2218 extern int __put_user_1(void *, unsigned int);
2219 @@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2220
2221 #define put_user(x,p) \
2222 ({ \
2223 + int __e; \
2224 might_fault(); \
2225 - __put_user_check(x,p); \
2226 + pax_open_userland(); \
2227 + __e = __put_user_check(x,p); \
2228 + pax_close_userland(); \
2229 + __e; \
2230 })
2231
2232 #else /* CONFIG_MMU */
2233 @@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2234
2235 #endif /* CONFIG_MMU */
2236
2237 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2238 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2239
2240 #define user_addr_max() \
2241 @@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2242 #define __get_user(x,ptr) \
2243 ({ \
2244 long __gu_err = 0; \
2245 + pax_open_userland(); \
2246 __get_user_err((x),(ptr),__gu_err); \
2247 + pax_close_userland(); \
2248 __gu_err; \
2249 })
2250
2251 #define __get_user_error(x,ptr,err) \
2252 ({ \
2253 + pax_open_userland(); \
2254 __get_user_err((x),(ptr),err); \
2255 + pax_close_userland(); \
2256 (void) 0; \
2257 })
2258
2259 @@ -319,13 +360,17 @@ do { \
2260 #define __put_user(x,ptr) \
2261 ({ \
2262 long __pu_err = 0; \
2263 + pax_open_userland(); \
2264 __put_user_err((x),(ptr),__pu_err); \
2265 + pax_close_userland(); \
2266 __pu_err; \
2267 })
2268
2269 #define __put_user_error(x,ptr,err) \
2270 ({ \
2271 + pax_open_userland(); \
2272 __put_user_err((x),(ptr),err); \
2273 + pax_close_userland(); \
2274 (void) 0; \
2275 })
2276
2277 @@ -425,11 +470,44 @@ do { \
2278
2279
2280 #ifdef CONFIG_MMU
2281 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2282 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2283 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2284 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2285 +
2286 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2287 +{
2288 + unsigned long ret;
2289 +
2290 + check_object_size(to, n, false);
2291 + pax_open_userland();
2292 + ret = ___copy_from_user(to, from, n);
2293 + pax_close_userland();
2294 + return ret;
2295 +}
2296 +
2297 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2298 +{
2299 + unsigned long ret;
2300 +
2301 + check_object_size(from, n, true);
2302 + pax_open_userland();
2303 + ret = ___copy_to_user(to, from, n);
2304 + pax_close_userland();
2305 + return ret;
2306 +}
2307 +
2308 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2309 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2310 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2311 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2312 +
2313 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2314 +{
2315 + unsigned long ret;
2316 + pax_open_userland();
2317 + ret = ___clear_user(addr, n);
2318 + pax_close_userland();
2319 + return ret;
2320 +}
2321 +
2322 #else
2323 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2324 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2325 @@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2326
2327 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2328 {
2329 + if ((long)n < 0)
2330 + return n;
2331 +
2332 if (access_ok(VERIFY_READ, from, n))
2333 n = __copy_from_user(to, from, n);
2334 else /* security hole - plug it */
2335 @@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2336
2337 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2338 {
2339 + if ((long)n < 0)
2340 + return n;
2341 +
2342 if (access_ok(VERIFY_WRITE, to, n))
2343 n = __copy_to_user(to, from, n);
2344 return n;
2345 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2346 index 5af0ed1..cea83883 100644
2347 --- a/arch/arm/include/uapi/asm/ptrace.h
2348 +++ b/arch/arm/include/uapi/asm/ptrace.h
2349 @@ -92,7 +92,7 @@
2350 * ARMv7 groups of PSR bits
2351 */
2352 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2353 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2354 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2355 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2356 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2357
2358 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2359 index 85e664b..419a1cd 100644
2360 --- a/arch/arm/kernel/armksyms.c
2361 +++ b/arch/arm/kernel/armksyms.c
2362 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2363
2364 /* networking */
2365 EXPORT_SYMBOL(csum_partial);
2366 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2367 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2368 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2369 EXPORT_SYMBOL(__csum_ipv6_magic);
2370
2371 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2372 #ifdef CONFIG_MMU
2373 EXPORT_SYMBOL(copy_page);
2374
2375 -EXPORT_SYMBOL(__copy_from_user);
2376 -EXPORT_SYMBOL(__copy_to_user);
2377 -EXPORT_SYMBOL(__clear_user);
2378 +EXPORT_SYMBOL(___copy_from_user);
2379 +EXPORT_SYMBOL(___copy_to_user);
2380 +EXPORT_SYMBOL(___clear_user);
2381
2382 EXPORT_SYMBOL(__get_user_1);
2383 EXPORT_SYMBOL(__get_user_2);
2384 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2385 index 1879e8d..b2207fc 100644
2386 --- a/arch/arm/kernel/entry-armv.S
2387 +++ b/arch/arm/kernel/entry-armv.S
2388 @@ -47,6 +47,87 @@
2389 9997:
2390 .endm
2391
2392 + .macro pax_enter_kernel
2393 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2394 + @ make aligned space for saved DACR
2395 + sub sp, sp, #8
2396 + @ save regs
2397 + stmdb sp!, {r1, r2}
2398 + @ read DACR from cpu_domain into r1
2399 + mov r2, sp
2400 + @ assume 8K pages, since we have to split the immediate in two
2401 + bic r2, r2, #(0x1fc0)
2402 + bic r2, r2, #(0x3f)
2403 + ldr r1, [r2, #TI_CPU_DOMAIN]
2404 + @ store old DACR on stack
2405 + str r1, [sp, #8]
2406 +#ifdef CONFIG_PAX_KERNEXEC
2407 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2408 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2409 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2410 +#endif
2411 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2412 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2413 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2414 +#endif
2415 + @ write r1 to current_thread_info()->cpu_domain
2416 + str r1, [r2, #TI_CPU_DOMAIN]
2417 + @ write r1 to DACR
2418 + mcr p15, 0, r1, c3, c0, 0
2419 + @ instruction sync
2420 + instr_sync
2421 + @ restore regs
2422 + ldmia sp!, {r1, r2}
2423 +#endif
2424 + .endm
2425 +
2426 + .macro pax_open_userland
2427 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2428 + @ save regs
2429 + stmdb sp!, {r0, r1}
2430 + @ read DACR from cpu_domain into r1
2431 + mov r0, sp
2432 + @ assume 8K pages, since we have to split the immediate in two
2433 + bic r0, r0, #(0x1fc0)
2434 + bic r0, r0, #(0x3f)
2435 + ldr r1, [r0, #TI_CPU_DOMAIN]
2436 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2437 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2438 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2439 + @ write r1 to current_thread_info()->cpu_domain
2440 + str r1, [r0, #TI_CPU_DOMAIN]
2441 + @ write r1 to DACR
2442 + mcr p15, 0, r1, c3, c0, 0
2443 + @ instruction sync
2444 + instr_sync
2445 + @ restore regs
2446 + ldmia sp!, {r0, r1}
2447 +#endif
2448 + .endm
2449 +
2450 + .macro pax_close_userland
2451 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2452 + @ save regs
2453 + stmdb sp!, {r0, r1}
2454 + @ read DACR from cpu_domain into r1
2455 + mov r0, sp
2456 + @ assume 8K pages, since we have to split the immediate in two
2457 + bic r0, r0, #(0x1fc0)
2458 + bic r0, r0, #(0x3f)
2459 + ldr r1, [r0, #TI_CPU_DOMAIN]
2460 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2461 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2462 + @ write r1 to current_thread_info()->cpu_domain
2463 + str r1, [r0, #TI_CPU_DOMAIN]
2464 + @ write r1 to DACR
2465 + mcr p15, 0, r1, c3, c0, 0
2466 + @ instruction sync
2467 + instr_sync
2468 + @ restore regs
2469 + ldmia sp!, {r0, r1}
2470 +#endif
2471 + .endm
2472 +
2473 .macro pabt_helper
2474 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2475 #ifdef MULTI_PABORT
2476 @@ -89,11 +170,15 @@
2477 * Invalid mode handlers
2478 */
2479 .macro inv_entry, reason
2480 +
2481 + pax_enter_kernel
2482 +
2483 sub sp, sp, #S_FRAME_SIZE
2484 ARM( stmib sp, {r1 - lr} )
2485 THUMB( stmia sp, {r0 - r12} )
2486 THUMB( str sp, [sp, #S_SP] )
2487 THUMB( str lr, [sp, #S_LR] )
2488 +
2489 mov r1, #\reason
2490 .endm
2491
2492 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2493 .macro svc_entry, stack_hole=0
2494 UNWIND(.fnstart )
2495 UNWIND(.save {r0 - pc} )
2496 +
2497 + pax_enter_kernel
2498 +
2499 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2500 +
2501 #ifdef CONFIG_THUMB2_KERNEL
2502 SPFIX( str r0, [sp] ) @ temporarily saved
2503 SPFIX( mov r0, sp )
2504 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2505 ldmia r0, {r3 - r5}
2506 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2507 mov r6, #-1 @ "" "" "" ""
2508 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2509 + @ offset sp by 8 as done in pax_enter_kernel
2510 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2511 +#else
2512 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2513 +#endif
2514 SPFIX( addeq r2, r2, #4 )
2515 str r3, [sp, #-4]! @ save the "real" r0 copied
2516 @ from the exception stack
2517 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2518 .macro usr_entry
2519 UNWIND(.fnstart )
2520 UNWIND(.cantunwind ) @ don't unwind the user space
2521 +
2522 + pax_enter_kernel_user
2523 +
2524 sub sp, sp, #S_FRAME_SIZE
2525 ARM( stmib sp, {r1 - r12} )
2526 THUMB( stmia sp, {r0 - r12} )
2527 @@ -416,7 +513,9 @@ __und_usr:
2528 tst r3, #PSR_T_BIT @ Thumb mode?
2529 bne __und_usr_thumb
2530 sub r4, r2, #4 @ ARM instr at LR - 4
2531 + pax_open_userland
2532 1: ldrt r0, [r4]
2533 + pax_close_userland
2534 ARM_BE8(rev r0, r0) @ little endian instruction
2535
2536 @ r0 = 32-bit ARM instruction which caused the exception
2537 @@ -450,11 +549,15 @@ __und_usr_thumb:
2538 */
2539 .arch armv6t2
2540 #endif
2541 + pax_open_userland
2542 2: ldrht r5, [r4]
2543 + pax_close_userland
2544 ARM_BE8(rev16 r5, r5) @ little endian instruction
2545 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2546 blo __und_usr_fault_16 @ 16bit undefined instruction
2547 + pax_open_userland
2548 3: ldrht r0, [r2]
2549 + pax_close_userland
2550 ARM_BE8(rev16 r0, r0) @ little endian instruction
2551 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2552 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2553 @@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2554 */
2555 .pushsection .fixup, "ax"
2556 .align 2
2557 -4: mov pc, r9
2558 +4: pax_close_userland
2559 + mov pc, r9
2560 .popsection
2561 .pushsection __ex_table,"a"
2562 .long 1b, 4b
2563 @@ -694,7 +798,7 @@ ENTRY(__switch_to)
2564 THUMB( str lr, [ip], #4 )
2565 ldr r4, [r2, #TI_TP_VALUE]
2566 ldr r5, [r2, #TI_TP_VALUE + 4]
2567 -#ifdef CONFIG_CPU_USE_DOMAINS
2568 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2569 ldr r6, [r2, #TI_CPU_DOMAIN]
2570 #endif
2571 switch_tls r1, r4, r5, r3, r7
2572 @@ -703,7 +807,7 @@ ENTRY(__switch_to)
2573 ldr r8, =__stack_chk_guard
2574 ldr r7, [r7, #TSK_STACK_CANARY]
2575 #endif
2576 -#ifdef CONFIG_CPU_USE_DOMAINS
2577 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2578 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2579 #endif
2580 mov r5, r0
2581 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2582 index a2dcafd..1048b5a 100644
2583 --- a/arch/arm/kernel/entry-common.S
2584 +++ b/arch/arm/kernel/entry-common.S
2585 @@ -10,18 +10,46 @@
2586
2587 #include <asm/unistd.h>
2588 #include <asm/ftrace.h>
2589 +#include <asm/domain.h>
2590 #include <asm/unwind.h>
2591
2592 +#include "entry-header.S"
2593 +
2594 #ifdef CONFIG_NEED_RET_TO_USER
2595 #include <mach/entry-macro.S>
2596 #else
2597 .macro arch_ret_to_user, tmp1, tmp2
2598 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2599 + @ save regs
2600 + stmdb sp!, {r1, r2}
2601 + @ read DACR from cpu_domain into r1
2602 + mov r2, sp
2603 + @ assume 8K pages, since we have to split the immediate in two
2604 + bic r2, r2, #(0x1fc0)
2605 + bic r2, r2, #(0x3f)
2606 + ldr r1, [r2, #TI_CPU_DOMAIN]
2607 +#ifdef CONFIG_PAX_KERNEXEC
2608 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2609 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2610 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2611 +#endif
2612 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2613 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2614 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2615 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2616 +#endif
2617 + @ write r1 to current_thread_info()->cpu_domain
2618 + str r1, [r2, #TI_CPU_DOMAIN]
2619 + @ write r1 to DACR
2620 + mcr p15, 0, r1, c3, c0, 0
2621 + @ instruction sync
2622 + instr_sync
2623 + @ restore regs
2624 + ldmia sp!, {r1, r2}
2625 +#endif
2626 .endm
2627 #endif
2628
2629 -#include "entry-header.S"
2630 -
2631 -
2632 .align 5
2633 /*
2634 * This is the fast syscall return path. We do as little as
2635 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2636 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2637 #endif
2638
2639 + /*
2640 + * do this here to avoid a performance hit of wrapping the code above
2641 + * that directly dereferences userland to parse the SWI instruction
2642 + */
2643 + pax_enter_kernel_user
2644 +
2645 adr tbl, sys_call_table @ load syscall table pointer
2646
2647 #if defined(CONFIG_OABI_COMPAT)
2648 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2649 index 39f89fb..d612bd9 100644
2650 --- a/arch/arm/kernel/entry-header.S
2651 +++ b/arch/arm/kernel/entry-header.S
2652 @@ -184,6 +184,60 @@
2653 msr cpsr_c, \rtemp @ switch back to the SVC mode
2654 .endm
2655
2656 + .macro pax_enter_kernel_user
2657 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2658 + @ save regs
2659 + stmdb sp!, {r0, r1}
2660 + @ read DACR from cpu_domain into r1
2661 + mov r0, sp
2662 + @ assume 8K pages, since we have to split the immediate in two
2663 + bic r0, r0, #(0x1fc0)
2664 + bic r0, r0, #(0x3f)
2665 + ldr r1, [r0, #TI_CPU_DOMAIN]
2666 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2667 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2668 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2669 +#endif
2670 +#ifdef CONFIG_PAX_KERNEXEC
2671 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2672 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2673 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2674 +#endif
2675 + @ write r1 to current_thread_info()->cpu_domain
2676 + str r1, [r0, #TI_CPU_DOMAIN]
2677 + @ write r1 to DACR
2678 + mcr p15, 0, r1, c3, c0, 0
2679 + @ instruction sync
2680 + instr_sync
2681 + @ restore regs
2682 + ldmia sp!, {r0, r1}
2683 +#endif
2684 + .endm
2685 +
2686 + .macro pax_exit_kernel
2687 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2688 + @ save regs
2689 + stmdb sp!, {r0, r1}
2690 + @ read old DACR from stack into r1
2691 + ldr r1, [sp, #(8 + S_SP)]
2692 + sub r1, r1, #8
2693 + ldr r1, [r1]
2694 +
2695 + @ write r1 to current_thread_info()->cpu_domain
2696 + mov r0, sp
2697 + @ assume 8K pages, since we have to split the immediate in two
2698 + bic r0, r0, #(0x1fc0)
2699 + bic r0, r0, #(0x3f)
2700 + str r1, [r0, #TI_CPU_DOMAIN]
2701 + @ write r1 to DACR
2702 + mcr p15, 0, r1, c3, c0, 0
2703 + @ instruction sync
2704 + instr_sync
2705 + @ restore regs
2706 + ldmia sp!, {r0, r1}
2707 +#endif
2708 + .endm
2709 +
2710 #ifndef CONFIG_THUMB2_KERNEL
2711 .macro svc_exit, rpsr, irq = 0
2712 .if \irq != 0
2713 @@ -203,6 +257,9 @@
2714 blne trace_hardirqs_off
2715 #endif
2716 .endif
2717 +
2718 + pax_exit_kernel
2719 +
2720 msr spsr_cxsf, \rpsr
2721 #if defined(CONFIG_CPU_V6)
2722 ldr r0, [sp]
2723 @@ -266,6 +323,9 @@
2724 blne trace_hardirqs_off
2725 #endif
2726 .endif
2727 +
2728 + pax_exit_kernel
2729 +
2730 ldr lr, [sp, #S_SP] @ top of the stack
2731 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2732 clrex @ clear the exclusive monitor
2733 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2734 index 918875d..cd5fa27 100644
2735 --- a/arch/arm/kernel/fiq.c
2736 +++ b/arch/arm/kernel/fiq.c
2737 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2738 void *base = vectors_page;
2739 unsigned offset = FIQ_OFFSET;
2740
2741 + pax_open_kernel();
2742 memcpy(base + offset, start, length);
2743 + pax_close_kernel();
2744 +
2745 if (!cache_is_vipt_nonaliasing())
2746 flush_icache_range((unsigned long)base + offset, offset +
2747 length);
2748 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2749 index f5f381d..a6f36a1 100644
2750 --- a/arch/arm/kernel/head.S
2751 +++ b/arch/arm/kernel/head.S
2752 @@ -437,7 +437,7 @@ __enable_mmu:
2753 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2754 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2755 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2756 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2757 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2758 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2759 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2760 #endif
2761 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2762 index 45e4781..8eac93d 100644
2763 --- a/arch/arm/kernel/module.c
2764 +++ b/arch/arm/kernel/module.c
2765 @@ -38,12 +38,39 @@
2766 #endif
2767
2768 #ifdef CONFIG_MMU
2769 -void *module_alloc(unsigned long size)
2770 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2771 {
2772 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2773 + return NULL;
2774 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2775 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2776 + GFP_KERNEL, prot, NUMA_NO_NODE,
2777 __builtin_return_address(0));
2778 }
2779 +
2780 +void *module_alloc(unsigned long size)
2781 +{
2782 +
2783 +#ifdef CONFIG_PAX_KERNEXEC
2784 + return __module_alloc(size, PAGE_KERNEL);
2785 +#else
2786 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2787 +#endif
2788 +
2789 +}
2790 +
2791 +#ifdef CONFIG_PAX_KERNEXEC
2792 +void module_free_exec(struct module *mod, void *module_region)
2793 +{
2794 + module_free(mod, module_region);
2795 +}
2796 +EXPORT_SYMBOL(module_free_exec);
2797 +
2798 +void *module_alloc_exec(unsigned long size)
2799 +{
2800 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2801 +}
2802 +EXPORT_SYMBOL(module_alloc_exec);
2803 +#endif
2804 #endif
2805
2806 int
2807 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2808 index 07314af..c46655c 100644
2809 --- a/arch/arm/kernel/patch.c
2810 +++ b/arch/arm/kernel/patch.c
2811 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2812 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2813 int size;
2814
2815 + pax_open_kernel();
2816 if (thumb2 && __opcode_is_thumb16(insn)) {
2817 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2818 size = sizeof(u16);
2819 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2820 *(u32 *)addr = insn;
2821 size = sizeof(u32);
2822 }
2823 + pax_close_kernel();
2824
2825 flush_icache_range((uintptr_t)(addr),
2826 (uintptr_t)(addr) + size);
2827 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2828 index 92f7b15..7048500 100644
2829 --- a/arch/arm/kernel/process.c
2830 +++ b/arch/arm/kernel/process.c
2831 @@ -217,6 +217,7 @@ void machine_power_off(void)
2832
2833 if (pm_power_off)
2834 pm_power_off();
2835 + BUG();
2836 }
2837
2838 /*
2839 @@ -230,7 +231,7 @@ void machine_power_off(void)
2840 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2841 * to use. Implementing such co-ordination would be essentially impossible.
2842 */
2843 -void machine_restart(char *cmd)
2844 +__noreturn void machine_restart(char *cmd)
2845 {
2846 local_irq_disable();
2847 smp_send_stop();
2848 @@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2849
2850 show_regs_print_info(KERN_DEFAULT);
2851
2852 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2853 - print_symbol("LR is at %s\n", regs->ARM_lr);
2854 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2855 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2856 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2857 "sp : %08lx ip : %08lx fp : %08lx\n",
2858 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2859 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2860 return 0;
2861 }
2862
2863 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2864 -{
2865 - unsigned long range_end = mm->brk + 0x02000000;
2866 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2867 -}
2868 -
2869 #ifdef CONFIG_MMU
2870 #ifdef CONFIG_KUSER_HELPERS
2871 /*
2872 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2873
2874 static int __init gate_vma_init(void)
2875 {
2876 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2877 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2878 return 0;
2879 }
2880 arch_initcall(gate_vma_init);
2881 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2882
2883 const char *arch_vma_name(struct vm_area_struct *vma)
2884 {
2885 - return is_gate_vma(vma) ? "[vectors]" :
2886 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2887 - "[sigpage]" : NULL;
2888 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2889 }
2890
2891 -static struct page *signal_page;
2892 -extern struct page *get_signal_page(void);
2893 -
2894 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2895 {
2896 struct mm_struct *mm = current->mm;
2897 - unsigned long addr;
2898 - int ret;
2899 -
2900 - if (!signal_page)
2901 - signal_page = get_signal_page();
2902 - if (!signal_page)
2903 - return -ENOMEM;
2904
2905 down_write(&mm->mmap_sem);
2906 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2907 - if (IS_ERR_VALUE(addr)) {
2908 - ret = addr;
2909 - goto up_fail;
2910 - }
2911 -
2912 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2913 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2914 - &signal_page);
2915 -
2916 - if (ret == 0)
2917 - mm->context.sigpage = addr;
2918 -
2919 - up_fail:
2920 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2921 up_write(&mm->mmap_sem);
2922 - return ret;
2923 + return 0;
2924 }
2925 #endif
2926 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2927 index 4693188..4596c5e 100644
2928 --- a/arch/arm/kernel/psci.c
2929 +++ b/arch/arm/kernel/psci.c
2930 @@ -24,7 +24,7 @@
2931 #include <asm/opcodes-virt.h>
2932 #include <asm/psci.h>
2933
2934 -struct psci_operations psci_ops;
2935 +struct psci_operations psci_ops __read_only;
2936
2937 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2938
2939 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2940 index 0dd3b79..e018f64 100644
2941 --- a/arch/arm/kernel/ptrace.c
2942 +++ b/arch/arm/kernel/ptrace.c
2943 @@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2944 return current_thread_info()->syscall;
2945 }
2946
2947 +#ifdef CONFIG_GRKERNSEC_SETXID
2948 +extern void gr_delayed_cred_worker(void);
2949 +#endif
2950 +
2951 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2952 {
2953 current_thread_info()->syscall = scno;
2954
2955 +#ifdef CONFIG_GRKERNSEC_SETXID
2956 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2957 + gr_delayed_cred_worker();
2958 +#endif
2959 +
2960 /* Do the secure computing check first; failures should be fast. */
2961 if (secure_computing(scno) == -1)
2962 return -1;
2963 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2964 index 1e8b030..37c3022 100644
2965 --- a/arch/arm/kernel/setup.c
2966 +++ b/arch/arm/kernel/setup.c
2967 @@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2968 unsigned int elf_hwcap __read_mostly;
2969 EXPORT_SYMBOL(elf_hwcap);
2970
2971 +pteval_t __supported_pte_mask __read_only;
2972 +pmdval_t __supported_pmd_mask __read_only;
2973
2974 #ifdef MULTI_CPU
2975 -struct processor processor __read_mostly;
2976 +struct processor processor __read_only;
2977 #endif
2978 #ifdef MULTI_TLB
2979 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2980 +struct cpu_tlb_fns cpu_tlb __read_only;
2981 #endif
2982 #ifdef MULTI_USER
2983 -struct cpu_user_fns cpu_user __read_mostly;
2984 +struct cpu_user_fns cpu_user __read_only;
2985 #endif
2986 #ifdef MULTI_CACHE
2987 -struct cpu_cache_fns cpu_cache __read_mostly;
2988 +struct cpu_cache_fns cpu_cache __read_only;
2989 #endif
2990 #ifdef CONFIG_OUTER_CACHE
2991 -struct outer_cache_fns outer_cache __read_mostly;
2992 +struct outer_cache_fns outer_cache __read_only;
2993 EXPORT_SYMBOL(outer_cache);
2994 #endif
2995
2996 @@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
2997 asm("mrc p15, 0, %0, c0, c1, 4"
2998 : "=r" (mmfr0));
2999 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3000 - (mmfr0 & 0x000000f0) >= 0x00000030)
3001 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3002 cpu_arch = CPU_ARCH_ARMv7;
3003 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3004 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3005 + __supported_pte_mask |= L_PTE_PXN;
3006 + __supported_pmd_mask |= PMD_PXNTABLE;
3007 + }
3008 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3009 (mmfr0 & 0x000000f0) == 0x00000020)
3010 cpu_arch = CPU_ARCH_ARMv6;
3011 else
3012 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3013 index 04d6388..5115238 100644
3014 --- a/arch/arm/kernel/signal.c
3015 +++ b/arch/arm/kernel/signal.c
3016 @@ -23,8 +23,6 @@
3017
3018 extern const unsigned long sigreturn_codes[7];
3019
3020 -static unsigned long signal_return_offset;
3021 -
3022 #ifdef CONFIG_CRUNCH
3023 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3024 {
3025 @@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3026 * except when the MPU has protected the vectors
3027 * page from PL0
3028 */
3029 - retcode = mm->context.sigpage + signal_return_offset +
3030 - (idx << 2) + thumb;
3031 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3032 } else
3033 #endif
3034 {
3035 @@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3036 } while (thread_flags & _TIF_WORK_MASK);
3037 return 0;
3038 }
3039 -
3040 -struct page *get_signal_page(void)
3041 -{
3042 - unsigned long ptr;
3043 - unsigned offset;
3044 - struct page *page;
3045 - void *addr;
3046 -
3047 - page = alloc_pages(GFP_KERNEL, 0);
3048 -
3049 - if (!page)
3050 - return NULL;
3051 -
3052 - addr = page_address(page);
3053 -
3054 - /* Give the signal return code some randomness */
3055 - offset = 0x200 + (get_random_int() & 0x7fc);
3056 - signal_return_offset = offset;
3057 -
3058 - /*
3059 - * Copy signal return handlers into the vector page, and
3060 - * set sigreturn to be a pointer to these.
3061 - */
3062 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3063 -
3064 - ptr = (unsigned long)addr + offset;
3065 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3066 -
3067 - return page;
3068 -}
3069 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3070 index b7b4c86..47c4f77 100644
3071 --- a/arch/arm/kernel/smp.c
3072 +++ b/arch/arm/kernel/smp.c
3073 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3074
3075 static DECLARE_COMPLETION(cpu_running);
3076
3077 -static struct smp_operations smp_ops;
3078 +static struct smp_operations smp_ops __read_only;
3079
3080 void __init smp_set_ops(struct smp_operations *ops)
3081 {
3082 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3083 index 7a3be1d..b00c7de 100644
3084 --- a/arch/arm/kernel/tcm.c
3085 +++ b/arch/arm/kernel/tcm.c
3086 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3087 .virtual = ITCM_OFFSET,
3088 .pfn = __phys_to_pfn(ITCM_OFFSET),
3089 .length = 0,
3090 - .type = MT_MEMORY_RWX_ITCM,
3091 + .type = MT_MEMORY_RX_ITCM,
3092 }
3093 };
3094
3095 @@ -267,7 +267,9 @@ no_dtcm:
3096 start = &__sitcm_text;
3097 end = &__eitcm_text;
3098 ram = &__itcm_start;
3099 + pax_open_kernel();
3100 memcpy(start, ram, itcm_code_sz);
3101 + pax_close_kernel();
3102 pr_debug("CPU ITCM: copied code from %p - %p\n",
3103 start, end);
3104 itcm_present = true;
3105 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3106 index 172ee18..ce4ec3d 100644
3107 --- a/arch/arm/kernel/traps.c
3108 +++ b/arch/arm/kernel/traps.c
3109 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3110 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3111 {
3112 #ifdef CONFIG_KALLSYMS
3113 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3114 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3115 #else
3116 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3117 #endif
3118 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3119 static int die_owner = -1;
3120 static unsigned int die_nest_count;
3121
3122 +extern void gr_handle_kernel_exploit(void);
3123 +
3124 static unsigned long oops_begin(void)
3125 {
3126 int cpu;
3127 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3128 panic("Fatal exception in interrupt");
3129 if (panic_on_oops)
3130 panic("Fatal exception");
3131 +
3132 + gr_handle_kernel_exploit();
3133 +
3134 if (signr)
3135 do_exit(signr);
3136 }
3137 @@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3138 * The user helper at 0xffff0fe0 must be used instead.
3139 * (see entry-armv.S for details)
3140 */
3141 + pax_open_kernel();
3142 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3143 + pax_close_kernel();
3144 }
3145 return 0;
3146
3147 @@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3148 kuser_init(vectors_base);
3149
3150 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3151 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3152 +
3153 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3154 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3155 +#endif
3156 +
3157 #else /* ifndef CONFIG_CPU_V7M */
3158 /*
3159 * on V7-M there is no need to copy the vector table to a dedicated
3160 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3161 index 7bcee5c..e2f3249 100644
3162 --- a/arch/arm/kernel/vmlinux.lds.S
3163 +++ b/arch/arm/kernel/vmlinux.lds.S
3164 @@ -8,7 +8,11 @@
3165 #include <asm/thread_info.h>
3166 #include <asm/memory.h>
3167 #include <asm/page.h>
3168 -
3169 +
3170 +#ifdef CONFIG_PAX_KERNEXEC
3171 +#include <asm/pgtable.h>
3172 +#endif
3173 +
3174 #define PROC_INFO \
3175 . = ALIGN(4); \
3176 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3177 @@ -34,7 +38,7 @@
3178 #endif
3179
3180 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3181 - defined(CONFIG_GENERIC_BUG)
3182 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3183 #define ARM_EXIT_KEEP(x) x
3184 #define ARM_EXIT_DISCARD(x)
3185 #else
3186 @@ -90,6 +94,11 @@ SECTIONS
3187 _text = .;
3188 HEAD_TEXT
3189 }
3190 +
3191 +#ifdef CONFIG_PAX_KERNEXEC
3192 + . = ALIGN(1<<SECTION_SHIFT);
3193 +#endif
3194 +
3195 .text : { /* Real text segment */
3196 _stext = .; /* Text and read-only data */
3197 __exception_text_start = .;
3198 @@ -112,6 +121,8 @@ SECTIONS
3199 ARM_CPU_KEEP(PROC_INFO)
3200 }
3201
3202 + _etext = .; /* End of text section */
3203 +
3204 RO_DATA(PAGE_SIZE)
3205
3206 . = ALIGN(4);
3207 @@ -142,7 +153,9 @@ SECTIONS
3208
3209 NOTES
3210
3211 - _etext = .; /* End of text and rodata section */
3212 +#ifdef CONFIG_PAX_KERNEXEC
3213 + . = ALIGN(1<<SECTION_SHIFT);
3214 +#endif
3215
3216 #ifndef CONFIG_XIP_KERNEL
3217 . = ALIGN(PAGE_SIZE);
3218 @@ -220,6 +233,11 @@ SECTIONS
3219 . = PAGE_OFFSET + TEXT_OFFSET;
3220 #else
3221 __init_end = .;
3222 +
3223 +#ifdef CONFIG_PAX_KERNEXEC
3224 + . = ALIGN(1<<SECTION_SHIFT);
3225 +#endif
3226 +
3227 . = ALIGN(THREAD_SIZE);
3228 __data_loc = .;
3229 #endif
3230 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3231 index bd18bb8..87ede26 100644
3232 --- a/arch/arm/kvm/arm.c
3233 +++ b/arch/arm/kvm/arm.c
3234 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3235 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3236
3237 /* The VMID used in the VTTBR */
3238 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3239 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3240 static u8 kvm_next_vmid;
3241 static DEFINE_SPINLOCK(kvm_vmid_lock);
3242
3243 @@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3244 */
3245 static bool need_new_vmid_gen(struct kvm *kvm)
3246 {
3247 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3248 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3249 }
3250
3251 /**
3252 @@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3253
3254 /* First user of a new VMID generation? */
3255 if (unlikely(kvm_next_vmid == 0)) {
3256 - atomic64_inc(&kvm_vmid_gen);
3257 + atomic64_inc_unchecked(&kvm_vmid_gen);
3258 kvm_next_vmid = 1;
3259
3260 /*
3261 @@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3262 kvm_call_hyp(__kvm_flush_vm_context);
3263 }
3264
3265 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3266 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3267 kvm->arch.vmid = kvm_next_vmid;
3268 kvm_next_vmid++;
3269
3270 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3271 index 14a0d98..7771a7d 100644
3272 --- a/arch/arm/lib/clear_user.S
3273 +++ b/arch/arm/lib/clear_user.S
3274 @@ -12,14 +12,14 @@
3275
3276 .text
3277
3278 -/* Prototype: int __clear_user(void *addr, size_t sz)
3279 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3280 * Purpose : clear some user memory
3281 * Params : addr - user memory address to clear
3282 * : sz - number of bytes to clear
3283 * Returns : number of bytes NOT cleared
3284 */
3285 ENTRY(__clear_user_std)
3286 -WEAK(__clear_user)
3287 +WEAK(___clear_user)
3288 stmfd sp!, {r1, lr}
3289 mov r2, #0
3290 cmp r1, #4
3291 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3292 USER( strnebt r2, [r0])
3293 mov r0, #0
3294 ldmfd sp!, {r1, pc}
3295 -ENDPROC(__clear_user)
3296 +ENDPROC(___clear_user)
3297 ENDPROC(__clear_user_std)
3298
3299 .pushsection .fixup,"ax"
3300 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3301 index 66a477a..bee61d3 100644
3302 --- a/arch/arm/lib/copy_from_user.S
3303 +++ b/arch/arm/lib/copy_from_user.S
3304 @@ -16,7 +16,7 @@
3305 /*
3306 * Prototype:
3307 *
3308 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3309 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3310 *
3311 * Purpose:
3312 *
3313 @@ -84,11 +84,11 @@
3314
3315 .text
3316
3317 -ENTRY(__copy_from_user)
3318 +ENTRY(___copy_from_user)
3319
3320 #include "copy_template.S"
3321
3322 -ENDPROC(__copy_from_user)
3323 +ENDPROC(___copy_from_user)
3324
3325 .pushsection .fixup,"ax"
3326 .align 0
3327 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3328 index 6ee2f67..d1cce76 100644
3329 --- a/arch/arm/lib/copy_page.S
3330 +++ b/arch/arm/lib/copy_page.S
3331 @@ -10,6 +10,7 @@
3332 * ASM optimised string functions
3333 */
3334 #include <linux/linkage.h>
3335 +#include <linux/const.h>
3336 #include <asm/assembler.h>
3337 #include <asm/asm-offsets.h>
3338 #include <asm/cache.h>
3339 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3340 index d066df6..df28194 100644
3341 --- a/arch/arm/lib/copy_to_user.S
3342 +++ b/arch/arm/lib/copy_to_user.S
3343 @@ -16,7 +16,7 @@
3344 /*
3345 * Prototype:
3346 *
3347 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3348 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3349 *
3350 * Purpose:
3351 *
3352 @@ -88,11 +88,11 @@
3353 .text
3354
3355 ENTRY(__copy_to_user_std)
3356 -WEAK(__copy_to_user)
3357 +WEAK(___copy_to_user)
3358
3359 #include "copy_template.S"
3360
3361 -ENDPROC(__copy_to_user)
3362 +ENDPROC(___copy_to_user)
3363 ENDPROC(__copy_to_user_std)
3364
3365 .pushsection .fixup,"ax"
3366 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3367 index 7d08b43..f7ca7ea 100644
3368 --- a/arch/arm/lib/csumpartialcopyuser.S
3369 +++ b/arch/arm/lib/csumpartialcopyuser.S
3370 @@ -57,8 +57,8 @@
3371 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3372 */
3373
3374 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3375 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3376 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3377 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3378
3379 #include "csumpartialcopygeneric.S"
3380
3381 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3382 index 5306de3..aed6d03 100644
3383 --- a/arch/arm/lib/delay.c
3384 +++ b/arch/arm/lib/delay.c
3385 @@ -28,7 +28,7 @@
3386 /*
3387 * Default to the loop-based delay implementation.
3388 */
3389 -struct arm_delay_ops arm_delay_ops = {
3390 +struct arm_delay_ops arm_delay_ops __read_only = {
3391 .delay = __loop_delay,
3392 .const_udelay = __loop_const_udelay,
3393 .udelay = __loop_udelay,
3394 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3395 index 3e58d71..029817c 100644
3396 --- a/arch/arm/lib/uaccess_with_memcpy.c
3397 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3398 @@ -136,7 +136,7 @@ out:
3399 }
3400
3401 unsigned long
3402 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3403 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3404 {
3405 /*
3406 * This test is stubbed out of the main function above to keep
3407 @@ -190,7 +190,7 @@ out:
3408 return n;
3409 }
3410
3411 -unsigned long __clear_user(void __user *addr, unsigned long n)
3412 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3413 {
3414 /* See rational for this in __copy_to_user() above. */
3415 if (n < 64)
3416 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3417 index f7ca97b..3d7e719 100644
3418 --- a/arch/arm/mach-at91/setup.c
3419 +++ b/arch/arm/mach-at91/setup.c
3420 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3421
3422 desc->pfn = __phys_to_pfn(base);
3423 desc->length = length;
3424 - desc->type = MT_MEMORY_RWX_NONCACHED;
3425 + desc->type = MT_MEMORY_RW_NONCACHED;
3426
3427 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3428 base, length, desc->virtual);
3429 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3430 index f3407a5..bd4256f 100644
3431 --- a/arch/arm/mach-kirkwood/common.c
3432 +++ b/arch/arm/mach-kirkwood/common.c
3433 @@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3434 clk_gate_ops.disable(hw);
3435 }
3436
3437 -static struct clk_ops clk_gate_fn_ops;
3438 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3439 +{
3440 + return clk_gate_ops.is_enabled(hw);
3441 +}
3442 +
3443 +static struct clk_ops clk_gate_fn_ops = {
3444 + .enable = clk_gate_fn_enable,
3445 + .disable = clk_gate_fn_disable,
3446 + .is_enabled = clk_gate_fn_is_enabled,
3447 +};
3448
3449 static struct clk __init *clk_register_gate_fn(struct device *dev,
3450 const char *name,
3451 @@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3452 gate_fn->fn_en = fn_en;
3453 gate_fn->fn_dis = fn_dis;
3454
3455 - /* ops is the gate ops, but with our enable/disable functions */
3456 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3457 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3458 - clk_gate_fn_ops = clk_gate_ops;
3459 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3460 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3461 - }
3462 -
3463 clk = clk_register(dev, &gate_fn->gate.hw);
3464
3465 if (IS_ERR(clk))
3466 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3467 index aead77a..a2253fa 100644
3468 --- a/arch/arm/mach-omap2/board-n8x0.c
3469 +++ b/arch/arm/mach-omap2/board-n8x0.c
3470 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3471 }
3472 #endif
3473
3474 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3475 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3476 .late_init = n8x0_menelaus_late_init,
3477 };
3478
3479 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3480 index ab43755..ccfa231 100644
3481 --- a/arch/arm/mach-omap2/gpmc.c
3482 +++ b/arch/arm/mach-omap2/gpmc.c
3483 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3484 };
3485
3486 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3487 -static struct irq_chip gpmc_irq_chip;
3488 static int gpmc_irq_start;
3489
3490 static struct resource gpmc_mem_root;
3491 @@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3492
3493 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3494
3495 +static struct irq_chip gpmc_irq_chip = {
3496 + .name = "gpmc",
3497 + .irq_startup = gpmc_irq_noop_ret,
3498 + .irq_enable = gpmc_irq_enable,
3499 + .irq_disable = gpmc_irq_disable,
3500 + .irq_shutdown = gpmc_irq_noop,
3501 + .irq_ack = gpmc_irq_noop,
3502 + .irq_mask = gpmc_irq_noop,
3503 + .irq_unmask = gpmc_irq_noop,
3504 +
3505 +};
3506 +
3507 static int gpmc_setup_irq(void)
3508 {
3509 int i;
3510 @@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3511 return gpmc_irq_start;
3512 }
3513
3514 - gpmc_irq_chip.name = "gpmc";
3515 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3516 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3517 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3518 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3519 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3520 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3521 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3522 -
3523 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3524 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3525
3526 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3527 index 667915d..2ee1219 100644
3528 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3529 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3530 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3531 int (*finish_suspend)(unsigned long cpu_state);
3532 void (*resume)(void);
3533 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3534 -};
3535 +} __no_const;
3536
3537 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3538 static struct powerdomain *mpuss_pd;
3539 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3540 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3541 {}
3542
3543 -struct cpu_pm_ops omap_pm_ops = {
3544 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3545 .finish_suspend = default_finish_suspend,
3546 .resume = dummy_cpu_resume,
3547 .scu_prepare = dummy_scu_prepare,
3548 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3549 index 3664562..72f85c6 100644
3550 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3551 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3552 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3553 return NOTIFY_OK;
3554 }
3555
3556 -static struct notifier_block __refdata irq_hotplug_notifier = {
3557 +static struct notifier_block irq_hotplug_notifier = {
3558 .notifier_call = irq_cpu_hotplug_notify,
3559 };
3560
3561 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3562 index 01ef59d..32ae28a8 100644
3563 --- a/arch/arm/mach-omap2/omap_device.c
3564 +++ b/arch/arm/mach-omap2/omap_device.c
3565 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3566 struct platform_device __init *omap_device_build(const char *pdev_name,
3567 int pdev_id,
3568 struct omap_hwmod *oh,
3569 - void *pdata, int pdata_len)
3570 + const void *pdata, int pdata_len)
3571 {
3572 struct omap_hwmod *ohs[] = { oh };
3573
3574 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3575 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3576 int pdev_id,
3577 struct omap_hwmod **ohs,
3578 - int oh_cnt, void *pdata,
3579 + int oh_cnt, const void *pdata,
3580 int pdata_len)
3581 {
3582 int ret = -ENOMEM;
3583 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3584 index 78c02b3..c94109a 100644
3585 --- a/arch/arm/mach-omap2/omap_device.h
3586 +++ b/arch/arm/mach-omap2/omap_device.h
3587 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3588 /* Core code interface */
3589
3590 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3591 - struct omap_hwmod *oh, void *pdata,
3592 + struct omap_hwmod *oh, const void *pdata,
3593 int pdata_len);
3594
3595 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3596 struct omap_hwmod **oh, int oh_cnt,
3597 - void *pdata, int pdata_len);
3598 + const void *pdata, int pdata_len);
3599
3600 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3601 struct omap_hwmod **ohs, int oh_cnt);
3602 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3603 index 1f33f5d..b29fa75 100644
3604 --- a/arch/arm/mach-omap2/omap_hwmod.c
3605 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3606 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3607 int (*init_clkdm)(struct omap_hwmod *oh);
3608 void (*update_context_lost)(struct omap_hwmod *oh);
3609 int (*get_context_lost)(struct omap_hwmod *oh);
3610 -};
3611 +} __no_const;
3612
3613 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3614 -static struct omap_hwmod_soc_ops soc_ops;
3615 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3616
3617 /* omap_hwmod_list contains all registered struct omap_hwmods */
3618 static LIST_HEAD(omap_hwmod_list);
3619 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3620 index 95fee54..cfa9cf1 100644
3621 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3622 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3623 @@ -10,6 +10,7 @@
3624
3625 #include <linux/kernel.h>
3626 #include <linux/init.h>
3627 +#include <asm/pgtable.h>
3628
3629 #include "powerdomain.h"
3630
3631 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3632
3633 void __init am43xx_powerdomains_init(void)
3634 {
3635 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3636 + pax_open_kernel();
3637 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3638 + pax_close_kernel();
3639 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3640 pwrdm_register_pwrdms(powerdomains_am43xx);
3641 pwrdm_complete_init();
3642 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3643 index d15c7bb..b2d1f0c 100644
3644 --- a/arch/arm/mach-omap2/wd_timer.c
3645 +++ b/arch/arm/mach-omap2/wd_timer.c
3646 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3647 struct omap_hwmod *oh;
3648 char *oh_name = "wd_timer2";
3649 char *dev_name = "omap_wdt";
3650 - struct omap_wd_timer_platform_data pdata;
3651 + static struct omap_wd_timer_platform_data pdata = {
3652 + .read_reset_sources = prm_read_reset_sources
3653 + };
3654
3655 if (!cpu_class_is_omap2() || of_have_populated_dt())
3656 return 0;
3657 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3658 return -EINVAL;
3659 }
3660
3661 - pdata.read_reset_sources = prm_read_reset_sources;
3662 -
3663 pdev = omap_device_build(dev_name, id, oh, &pdata,
3664 sizeof(struct omap_wd_timer_platform_data));
3665 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3666 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3667 index b82dcae..44ee5b6 100644
3668 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3669 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3670 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3671 bool entered_lp2 = false;
3672
3673 if (tegra_pending_sgi())
3674 - ACCESS_ONCE(abort_flag) = true;
3675 + ACCESS_ONCE_RW(abort_flag) = true;
3676
3677 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3678
3679 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3680 index 2dea8b5..6499da2 100644
3681 --- a/arch/arm/mach-ux500/setup.h
3682 +++ b/arch/arm/mach-ux500/setup.h
3683 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3684 .type = MT_DEVICE, \
3685 }
3686
3687 -#define __MEM_DEV_DESC(x, sz) { \
3688 - .virtual = IO_ADDRESS(x), \
3689 - .pfn = __phys_to_pfn(x), \
3690 - .length = sz, \
3691 - .type = MT_MEMORY_RWX, \
3692 -}
3693 -
3694 extern struct smp_operations ux500_smp_ops;
3695 extern void ux500_cpu_die(unsigned int cpu);
3696
3697 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3698 index 1f8fed9..14d7823 100644
3699 --- a/arch/arm/mm/Kconfig
3700 +++ b/arch/arm/mm/Kconfig
3701 @@ -446,7 +446,7 @@ config CPU_32v5
3702
3703 config CPU_32v6
3704 bool
3705 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3706 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3707 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3708
3709 config CPU_32v6K
3710 @@ -601,6 +601,7 @@ config CPU_CP15_MPU
3711
3712 config CPU_USE_DOMAINS
3713 bool
3714 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3715 help
3716 This option enables or disables the use of domain switching
3717 via the set_fs() function.
3718 @@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3719 config KUSER_HELPERS
3720 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3721 default y
3722 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3723 help
3724 Warning: disabling this option may break user programs.
3725
3726 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3727 See Documentation/arm/kernel_user_helpers.txt for details.
3728
3729 However, the fixed address nature of these helpers can be used
3730 - by ROP (return orientated programming) authors when creating
3731 + by ROP (Return Oriented Programming) authors when creating
3732 exploits.
3733
3734 If all of the binaries and libraries which run on your platform
3735 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3736 index 9240364..a2b8cf3 100644
3737 --- a/arch/arm/mm/alignment.c
3738 +++ b/arch/arm/mm/alignment.c
3739 @@ -212,10 +212,12 @@ union offset_union {
3740 #define __get16_unaligned_check(ins,val,addr) \
3741 do { \
3742 unsigned int err = 0, v, a = addr; \
3743 + pax_open_userland(); \
3744 __get8_unaligned_check(ins,v,a,err); \
3745 val = v << ((BE) ? 8 : 0); \
3746 __get8_unaligned_check(ins,v,a,err); \
3747 val |= v << ((BE) ? 0 : 8); \
3748 + pax_close_userland(); \
3749 if (err) \
3750 goto fault; \
3751 } while (0)
3752 @@ -229,6 +231,7 @@ union offset_union {
3753 #define __get32_unaligned_check(ins,val,addr) \
3754 do { \
3755 unsigned int err = 0, v, a = addr; \
3756 + pax_open_userland(); \
3757 __get8_unaligned_check(ins,v,a,err); \
3758 val = v << ((BE) ? 24 : 0); \
3759 __get8_unaligned_check(ins,v,a,err); \
3760 @@ -237,6 +240,7 @@ union offset_union {
3761 val |= v << ((BE) ? 8 : 16); \
3762 __get8_unaligned_check(ins,v,a,err); \
3763 val |= v << ((BE) ? 0 : 24); \
3764 + pax_close_userland(); \
3765 if (err) \
3766 goto fault; \
3767 } while (0)
3768 @@ -250,6 +254,7 @@ union offset_union {
3769 #define __put16_unaligned_check(ins,val,addr) \
3770 do { \
3771 unsigned int err = 0, v = val, a = addr; \
3772 + pax_open_userland(); \
3773 __asm__( FIRST_BYTE_16 \
3774 ARM( "1: "ins" %1, [%2], #1\n" ) \
3775 THUMB( "1: "ins" %1, [%2]\n" ) \
3776 @@ -269,6 +274,7 @@ union offset_union {
3777 " .popsection\n" \
3778 : "=r" (err), "=&r" (v), "=&r" (a) \
3779 : "0" (err), "1" (v), "2" (a)); \
3780 + pax_close_userland(); \
3781 if (err) \
3782 goto fault; \
3783 } while (0)
3784 @@ -282,6 +288,7 @@ union offset_union {
3785 #define __put32_unaligned_check(ins,val,addr) \
3786 do { \
3787 unsigned int err = 0, v = val, a = addr; \
3788 + pax_open_userland(); \
3789 __asm__( FIRST_BYTE_32 \
3790 ARM( "1: "ins" %1, [%2], #1\n" ) \
3791 THUMB( "1: "ins" %1, [%2]\n" ) \
3792 @@ -311,6 +318,7 @@ union offset_union {
3793 " .popsection\n" \
3794 : "=r" (err), "=&r" (v), "=&r" (a) \
3795 : "0" (err), "1" (v), "2" (a)); \
3796 + pax_close_userland(); \
3797 if (err) \
3798 goto fault; \
3799 } while (0)
3800 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3801 index 7abde2c..9df495f 100644
3802 --- a/arch/arm/mm/cache-l2x0.c
3803 +++ b/arch/arm/mm/cache-l2x0.c
3804 @@ -46,7 +46,7 @@ struct l2x0_of_data {
3805 void (*setup)(const struct device_node *, u32 *, u32 *);
3806 void (*save)(void);
3807 struct outer_cache_fns outer_cache;
3808 -};
3809 +} __do_const;
3810
3811 static bool of_init = false;
3812
3813 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3814 index 6eb97b3..ac509f6 100644
3815 --- a/arch/arm/mm/context.c
3816 +++ b/arch/arm/mm/context.c
3817 @@ -43,7 +43,7 @@
3818 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3819
3820 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3821 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3822 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3823 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3824
3825 static DEFINE_PER_CPU(atomic64_t, active_asids);
3826 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3827 {
3828 static u32 cur_idx = 1;
3829 u64 asid = atomic64_read(&mm->context.id);
3830 - u64 generation = atomic64_read(&asid_generation);
3831 + u64 generation = atomic64_read_unchecked(&asid_generation);
3832
3833 if (asid != 0 && is_reserved_asid(asid)) {
3834 /*
3835 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3836 */
3837 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3838 if (asid == NUM_USER_ASIDS) {
3839 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3840 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3841 &asid_generation);
3842 flush_context(cpu);
3843 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3844 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3845 cpu_set_reserved_ttbr0();
3846
3847 asid = atomic64_read(&mm->context.id);
3848 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3849 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3850 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3851 goto switch_mm_fastpath;
3852
3853 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3854 /* Check that our ASID belongs to the current generation. */
3855 asid = atomic64_read(&mm->context.id);
3856 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3857 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3858 asid = new_context(mm, cpu);
3859 atomic64_set(&mm->context.id, asid);
3860 }
3861 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3862 index eb8830a..5360ce7 100644
3863 --- a/arch/arm/mm/fault.c
3864 +++ b/arch/arm/mm/fault.c
3865 @@ -25,6 +25,7 @@
3866 #include <asm/system_misc.h>
3867 #include <asm/system_info.h>
3868 #include <asm/tlbflush.h>
3869 +#include <asm/sections.h>
3870
3871 #include "fault.h"
3872
3873 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3874 if (fixup_exception(regs))
3875 return;
3876
3877 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3878 + if (addr < TASK_SIZE) {
3879 + if (current->signal->curr_ip)
3880 + 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),
3881 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3882 + else
3883 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3884 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3885 + }
3886 +#endif
3887 +
3888 +#ifdef CONFIG_PAX_KERNEXEC
3889 + if ((fsr & FSR_WRITE) &&
3890 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3891 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3892 + {
3893 + if (current->signal->curr_ip)
3894 + 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),
3895 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3896 + else
3897 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3898 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3899 + }
3900 +#endif
3901 +
3902 /*
3903 * No handler, we'll have to terminate things with extreme prejudice.
3904 */
3905 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3906 }
3907 #endif
3908
3909 +#ifdef CONFIG_PAX_PAGEEXEC
3910 + if (fsr & FSR_LNX_PF) {
3911 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3912 + do_group_exit(SIGKILL);
3913 + }
3914 +#endif
3915 +
3916 tsk->thread.address = addr;
3917 tsk->thread.error_code = fsr;
3918 tsk->thread.trap_no = 14;
3919 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3920 }
3921 #endif /* CONFIG_MMU */
3922
3923 +#ifdef CONFIG_PAX_PAGEEXEC
3924 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3925 +{
3926 + long i;
3927 +
3928 + printk(KERN_ERR "PAX: bytes at PC: ");
3929 + for (i = 0; i < 20; i++) {
3930 + unsigned char c;
3931 + if (get_user(c, (__force unsigned char __user *)pc+i))
3932 + printk(KERN_CONT "?? ");
3933 + else
3934 + printk(KERN_CONT "%02x ", c);
3935 + }
3936 + printk("\n");
3937 +
3938 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3939 + for (i = -1; i < 20; i++) {
3940 + unsigned long c;
3941 + if (get_user(c, (__force unsigned long __user *)sp+i))
3942 + printk(KERN_CONT "???????? ");
3943 + else
3944 + printk(KERN_CONT "%08lx ", c);
3945 + }
3946 + printk("\n");
3947 +}
3948 +#endif
3949 +
3950 /*
3951 * First Level Translation Fault Handler
3952 *
3953 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3954 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3955 struct siginfo info;
3956
3957 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3958 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3959 + if (current->signal->curr_ip)
3960 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3961 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3962 + else
3963 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3964 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3965 + goto die;
3966 + }
3967 +#endif
3968 +
3969 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3970 return;
3971
3972 +die:
3973 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3974 inf->name, fsr, addr);
3975
3976 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3977 ifsr_info[nr].name = name;
3978 }
3979
3980 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
3981 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3982 +
3983 asmlinkage void __exception
3984 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3985 {
3986 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3987 struct siginfo info;
3988 + unsigned long pc = instruction_pointer(regs);
3989 +
3990 + if (user_mode(regs)) {
3991 + unsigned long sigpage = current->mm->context.sigpage;
3992 +
3993 + if (sigpage <= pc && pc < sigpage + 7*4) {
3994 + if (pc < sigpage + 3*4)
3995 + sys_sigreturn(regs);
3996 + else
3997 + sys_rt_sigreturn(regs);
3998 + return;
3999 + }
4000 + if (pc == 0xffff0f60UL) {
4001 + /*
4002 + * PaX: __kuser_cmpxchg64 emulation
4003 + */
4004 + // TODO
4005 + //regs->ARM_pc = regs->ARM_lr;
4006 + //return;
4007 + }
4008 + if (pc == 0xffff0fa0UL) {
4009 + /*
4010 + * PaX: __kuser_memory_barrier emulation
4011 + */
4012 + // dmb(); implied by the exception
4013 + regs->ARM_pc = regs->ARM_lr;
4014 + return;
4015 + }
4016 + if (pc == 0xffff0fc0UL) {
4017 + /*
4018 + * PaX: __kuser_cmpxchg emulation
4019 + */
4020 + // TODO
4021 + //long new;
4022 + //int op;
4023 +
4024 + //op = FUTEX_OP_SET << 28;
4025 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4026 + //regs->ARM_r0 = old != new;
4027 + //regs->ARM_pc = regs->ARM_lr;
4028 + //return;
4029 + }
4030 + if (pc == 0xffff0fe0UL) {
4031 + /*
4032 + * PaX: __kuser_get_tls emulation
4033 + */
4034 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4035 + regs->ARM_pc = regs->ARM_lr;
4036 + return;
4037 + }
4038 + }
4039 +
4040 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4041 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4042 + if (current->signal->curr_ip)
4043 + 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),
4044 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4045 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4046 + else
4047 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", 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 + goto die;
4051 + }
4052 +#endif
4053 +
4054 +#ifdef CONFIG_PAX_REFCOUNT
4055 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4056 + unsigned int bkpt;
4057 +
4058 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4059 + current->thread.error_code = ifsr;
4060 + current->thread.trap_no = 0;
4061 + pax_report_refcount_overflow(regs);
4062 + fixup_exception(regs);
4063 + return;
4064 + }
4065 + }
4066 +#endif
4067
4068 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4069 return;
4070
4071 +die:
4072 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4073 inf->name, ifsr, addr);
4074
4075 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4076 index cf08bdf..772656c 100644
4077 --- a/arch/arm/mm/fault.h
4078 +++ b/arch/arm/mm/fault.h
4079 @@ -3,6 +3,7 @@
4080
4081 /*
4082 * Fault status register encodings. We steal bit 31 for our own purposes.
4083 + * Set when the FSR value is from an instruction fault.
4084 */
4085 #define FSR_LNX_PF (1 << 31)
4086 #define FSR_WRITE (1 << 11)
4087 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4088 }
4089 #endif
4090
4091 +/* valid for LPAE and !LPAE */
4092 +static inline int is_xn_fault(unsigned int fsr)
4093 +{
4094 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4095 +}
4096 +
4097 +static inline int is_domain_fault(unsigned int fsr)
4098 +{
4099 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4100 +}
4101 +
4102 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4103 unsigned long search_exception_table(unsigned long addr);
4104
4105 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4106 index 804d615..fcec50a 100644
4107 --- a/arch/arm/mm/init.c
4108 +++ b/arch/arm/mm/init.c
4109 @@ -30,6 +30,8 @@
4110 #include <asm/setup.h>
4111 #include <asm/tlb.h>
4112 #include <asm/fixmap.h>
4113 +#include <asm/system_info.h>
4114 +#include <asm/cp15.h>
4115
4116 #include <asm/mach/arch.h>
4117 #include <asm/mach/map.h>
4118 @@ -625,7 +627,46 @@ void free_initmem(void)
4119 {
4120 #ifdef CONFIG_HAVE_TCM
4121 extern char __tcm_start, __tcm_end;
4122 +#endif
4123
4124 +#ifdef CONFIG_PAX_KERNEXEC
4125 + unsigned long addr;
4126 + pgd_t *pgd;
4127 + pud_t *pud;
4128 + pmd_t *pmd;
4129 + int cpu_arch = cpu_architecture();
4130 + unsigned int cr = get_cr();
4131 +
4132 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4133 + /* make pages tables, etc before .text NX */
4134 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4135 + pgd = pgd_offset_k(addr);
4136 + pud = pud_offset(pgd, addr);
4137 + pmd = pmd_offset(pud, addr);
4138 + __section_update(pmd, addr, PMD_SECT_XN);
4139 + }
4140 + /* make init NX */
4141 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4142 + pgd = pgd_offset_k(addr);
4143 + pud = pud_offset(pgd, addr);
4144 + pmd = pmd_offset(pud, addr);
4145 + __section_update(pmd, addr, PMD_SECT_XN);
4146 + }
4147 + /* make kernel code/rodata RX */
4148 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4149 + pgd = pgd_offset_k(addr);
4150 + pud = pud_offset(pgd, addr);
4151 + pmd = pmd_offset(pud, addr);
4152 +#ifdef CONFIG_ARM_LPAE
4153 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4154 +#else
4155 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4156 +#endif
4157 + }
4158 + }
4159 +#endif
4160 +
4161 +#ifdef CONFIG_HAVE_TCM
4162 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4163 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4164 #endif
4165 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4166 index f9c32ba..8540068 100644
4167 --- a/arch/arm/mm/ioremap.c
4168 +++ b/arch/arm/mm/ioremap.c
4169 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4170 unsigned int mtype;
4171
4172 if (cached)
4173 - mtype = MT_MEMORY_RWX;
4174 + mtype = MT_MEMORY_RX;
4175 else
4176 - mtype = MT_MEMORY_RWX_NONCACHED;
4177 + mtype = MT_MEMORY_RX_NONCACHED;
4178
4179 return __arm_ioremap_caller(phys_addr, size, mtype,
4180 __builtin_return_address(0));
4181 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4182 index 5e85ed3..b10a7ed 100644
4183 --- a/arch/arm/mm/mmap.c
4184 +++ b/arch/arm/mm/mmap.c
4185 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4186 struct vm_area_struct *vma;
4187 int do_align = 0;
4188 int aliasing = cache_is_vipt_aliasing();
4189 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4190 struct vm_unmapped_area_info info;
4191
4192 /*
4193 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4194 if (len > TASK_SIZE)
4195 return -ENOMEM;
4196
4197 +#ifdef CONFIG_PAX_RANDMMAP
4198 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4199 +#endif
4200 +
4201 if (addr) {
4202 if (do_align)
4203 addr = COLOUR_ALIGN(addr, pgoff);
4204 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4205 addr = PAGE_ALIGN(addr);
4206
4207 vma = find_vma(mm, addr);
4208 - if (TASK_SIZE - len >= addr &&
4209 - (!vma || addr + len <= vma->vm_start))
4210 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4211 return addr;
4212 }
4213
4214 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4215 info.high_limit = TASK_SIZE;
4216 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4217 info.align_offset = pgoff << PAGE_SHIFT;
4218 + info.threadstack_offset = offset;
4219 return vm_unmapped_area(&info);
4220 }
4221
4222 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4223 unsigned long addr = addr0;
4224 int do_align = 0;
4225 int aliasing = cache_is_vipt_aliasing();
4226 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4227 struct vm_unmapped_area_info info;
4228
4229 /*
4230 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4231 return addr;
4232 }
4233
4234 +#ifdef CONFIG_PAX_RANDMMAP
4235 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4236 +#endif
4237 +
4238 /* requesting a specific address */
4239 if (addr) {
4240 if (do_align)
4241 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4242 else
4243 addr = PAGE_ALIGN(addr);
4244 vma = find_vma(mm, addr);
4245 - if (TASK_SIZE - len >= addr &&
4246 - (!vma || addr + len <= vma->vm_start))
4247 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4248 return addr;
4249 }
4250
4251 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4252 info.high_limit = mm->mmap_base;
4253 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4254 info.align_offset = pgoff << PAGE_SHIFT;
4255 + info.threadstack_offset = offset;
4256 addr = vm_unmapped_area(&info);
4257
4258 /*
4259 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4260 {
4261 unsigned long random_factor = 0UL;
4262
4263 +#ifdef CONFIG_PAX_RANDMMAP
4264 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4265 +#endif
4266 +
4267 /* 8 bits of randomness in 20 address space bits */
4268 if ((current->flags & PF_RANDOMIZE) &&
4269 !(current->personality & ADDR_NO_RANDOMIZE))
4270 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4271
4272 if (mmap_is_legacy()) {
4273 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4274 +
4275 +#ifdef CONFIG_PAX_RANDMMAP
4276 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4277 + mm->mmap_base += mm->delta_mmap;
4278 +#endif
4279 +
4280 mm->get_unmapped_area = arch_get_unmapped_area;
4281 } else {
4282 mm->mmap_base = mmap_base(random_factor);
4283 +
4284 +#ifdef CONFIG_PAX_RANDMMAP
4285 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4286 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4287 +#endif
4288 +
4289 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4290 }
4291 }
4292 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4293 index a623cb3..c5e3f19 100644
4294 --- a/arch/arm/mm/mmu.c
4295 +++ b/arch/arm/mm/mmu.c
4296 @@ -39,6 +39,22 @@
4297 #include "mm.h"
4298 #include "tcm.h"
4299
4300 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4301 +void modify_domain(unsigned int dom, unsigned int type)
4302 +{
4303 + struct thread_info *thread = current_thread_info();
4304 + unsigned int domain = thread->cpu_domain;
4305 + /*
4306 + * DOMAIN_MANAGER might be defined to some other value,
4307 + * use the arch-defined constant
4308 + */
4309 + domain &= ~domain_val(dom, 3);
4310 + thread->cpu_domain = domain | domain_val(dom, type);
4311 + set_domain(thread->cpu_domain);
4312 +}
4313 +EXPORT_SYMBOL(modify_domain);
4314 +#endif
4315 +
4316 /*
4317 * empty_zero_page is a special page that is used for
4318 * zero-initialized data and COW.
4319 @@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4320 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4321 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4322
4323 -static struct mem_type mem_types[] = {
4324 +#ifdef CONFIG_PAX_KERNEXEC
4325 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4326 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4327 +#else
4328 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4329 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4330 +#endif
4331 +
4332 +static struct mem_type mem_types[] __read_only = {
4333 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4334 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4335 L_PTE_SHARED,
4336 @@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4337 .prot_sect = PROT_SECT_DEVICE,
4338 .domain = DOMAIN_IO,
4339 },
4340 - [MT_UNCACHED] = {
4341 + [MT_UNCACHED_RW] = {
4342 .prot_pte = PROT_PTE_DEVICE,
4343 .prot_l1 = PMD_TYPE_TABLE,
4344 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4345 .domain = DOMAIN_IO,
4346 },
4347 - [MT_CACHECLEAN] = {
4348 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4349 + [MT_CACHECLEAN_RO] = {
4350 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4351 .domain = DOMAIN_KERNEL,
4352 },
4353 #ifndef CONFIG_ARM_LPAE
4354 - [MT_MINICLEAN] = {
4355 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4356 + [MT_MINICLEAN_RO] = {
4357 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4358 .domain = DOMAIN_KERNEL,
4359 },
4360 #endif
4361 @@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4362 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4363 L_PTE_RDONLY,
4364 .prot_l1 = PMD_TYPE_TABLE,
4365 - .domain = DOMAIN_USER,
4366 + .domain = DOMAIN_VECTORS,
4367 },
4368 [MT_HIGH_VECTORS] = {
4369 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4370 L_PTE_USER | L_PTE_RDONLY,
4371 .prot_l1 = PMD_TYPE_TABLE,
4372 - .domain = DOMAIN_USER,
4373 + .domain = DOMAIN_VECTORS,
4374 },
4375 - [MT_MEMORY_RWX] = {
4376 + [__MT_MEMORY_RWX] = {
4377 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4378 .prot_l1 = PMD_TYPE_TABLE,
4379 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4380 @@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4381 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4382 .domain = DOMAIN_KERNEL,
4383 },
4384 - [MT_ROM] = {
4385 - .prot_sect = PMD_TYPE_SECT,
4386 + [MT_MEMORY_RX] = {
4387 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4388 + .prot_l1 = PMD_TYPE_TABLE,
4389 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4390 + .domain = DOMAIN_KERNEL,
4391 + },
4392 + [MT_ROM_RX] = {
4393 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4394 .domain = DOMAIN_KERNEL,
4395 },
4396 - [MT_MEMORY_RWX_NONCACHED] = {
4397 + [MT_MEMORY_RW_NONCACHED] = {
4398 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4399 L_PTE_MT_BUFFERABLE,
4400 .prot_l1 = PMD_TYPE_TABLE,
4401 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4402 .domain = DOMAIN_KERNEL,
4403 },
4404 + [MT_MEMORY_RX_NONCACHED] = {
4405 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4406 + L_PTE_MT_BUFFERABLE,
4407 + .prot_l1 = PMD_TYPE_TABLE,
4408 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4409 + .domain = DOMAIN_KERNEL,
4410 + },
4411 [MT_MEMORY_RW_DTCM] = {
4412 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4413 L_PTE_XN,
4414 @@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4415 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4416 .domain = DOMAIN_KERNEL,
4417 },
4418 - [MT_MEMORY_RWX_ITCM] = {
4419 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4420 + [MT_MEMORY_RX_ITCM] = {
4421 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4422 .prot_l1 = PMD_TYPE_TABLE,
4423 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4424 .domain = DOMAIN_KERNEL,
4425 },
4426 [MT_MEMORY_RW_SO] = {
4427 @@ -524,9 +562,14 @@ static void __init build_mem_type_table(void)
4428 * Mark cache clean areas and XIP ROM read only
4429 * from SVC mode and no access from userspace.
4430 */
4431 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4432 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4433 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4434 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4435 +#ifdef CONFIG_PAX_KERNEXEC
4436 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4437 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4438 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4439 +#endif
4440 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4441 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4442 #endif
4443
4444 if (is_smp()) {
4445 @@ -542,13 +585,17 @@ static void __init build_mem_type_table(void)
4446 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4447 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4448 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4449 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4450 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4451 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4452 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4453 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4454 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4455 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4456 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4457 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4458 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4459 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4460 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4461 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4462 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4463 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4464 }
4465 }
4466
4467 @@ -559,15 +606,20 @@ static void __init build_mem_type_table(void)
4468 if (cpu_arch >= CPU_ARCH_ARMv6) {
4469 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4470 /* Non-cacheable Normal is XCB = 001 */
4471 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4472 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4473 + PMD_SECT_BUFFERED;
4474 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4475 PMD_SECT_BUFFERED;
4476 } else {
4477 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4478 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4479 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4480 + PMD_SECT_TEX(1);
4481 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4482 PMD_SECT_TEX(1);
4483 }
4484 } else {
4485 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4486 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4487 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4488 }
4489
4490 #ifdef CONFIG_ARM_LPAE
4491 @@ -583,6 +635,8 @@ static void __init build_mem_type_table(void)
4492 vecs_pgprot |= PTE_EXT_AF;
4493 #endif
4494
4495 + user_pgprot |= __supported_pte_mask;
4496 +
4497 for (i = 0; i < 16; i++) {
4498 pteval_t v = pgprot_val(protection_map[i]);
4499 protection_map[i] = __pgprot(v | user_pgprot);
4500 @@ -600,21 +654,24 @@ static void __init build_mem_type_table(void)
4501
4502 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4503 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4504 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4505 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4506 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4507 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4508 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4509 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4510 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4511 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4512 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4513 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4514 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4515 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4516 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4517 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4518
4519 switch (cp->pmd) {
4520 case PMD_SECT_WT:
4521 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4522 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4523 break;
4524 case PMD_SECT_WB:
4525 case PMD_SECT_WBWA:
4526 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4527 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4528 break;
4529 }
4530 pr_info("Memory policy: %sData cache %s\n",
4531 @@ -1247,18 +1304,15 @@ void __init arm_mm_memblock_reserve(void)
4532 * called function. This means you can't use any function or debugging
4533 * method which may touch any device, otherwise the kernel _will_ crash.
4534 */
4535 +
4536 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4537 +
4538 static void __init devicemaps_init(const struct machine_desc *mdesc)
4539 {
4540 struct map_desc map;
4541 unsigned long addr;
4542 - void *vectors;
4543
4544 - /*
4545 - * Allocate the vector page early.
4546 - */
4547 - vectors = early_alloc(PAGE_SIZE * 2);
4548 -
4549 - early_trap_init(vectors);
4550 + early_trap_init(&vectors);
4551
4552 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4553 pmd_clear(pmd_off_k(addr));
4554 @@ -1271,7 +1325,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4555 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4556 map.virtual = MODULES_VADDR;
4557 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4558 - map.type = MT_ROM;
4559 + map.type = MT_ROM_RX;
4560 create_mapping(&map);
4561 #endif
4562
4563 @@ -1282,14 +1336,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4564 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4565 map.virtual = FLUSH_BASE;
4566 map.length = SZ_1M;
4567 - map.type = MT_CACHECLEAN;
4568 + map.type = MT_CACHECLEAN_RO;
4569 create_mapping(&map);
4570 #endif
4571 #ifdef FLUSH_BASE_MINICACHE
4572 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4573 map.virtual = FLUSH_BASE_MINICACHE;
4574 map.length = SZ_1M;
4575 - map.type = MT_MINICLEAN;
4576 + map.type = MT_MINICLEAN_RO;
4577 create_mapping(&map);
4578 #endif
4579
4580 @@ -1298,7 +1352,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4581 * location (0xffff0000). If we aren't using high-vectors, also
4582 * create a mapping at the low-vectors virtual address.
4583 */
4584 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4585 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4586 map.virtual = 0xffff0000;
4587 map.length = PAGE_SIZE;
4588 #ifdef CONFIG_KUSER_HELPERS
4589 @@ -1369,11 +1423,48 @@ static void __init map_lowmem(void)
4590 if (start >= end)
4591 break;
4592
4593 +#ifdef CONFIG_PAX_KERNEXEC
4594 + map.pfn = __phys_to_pfn(start);
4595 + map.virtual = __phys_to_virt(start);
4596 + map.length = end - start;
4597 +
4598 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4599 + struct map_desc kernel;
4600 + struct map_desc initmap;
4601 +
4602 + /* when freeing initmem we will make this RW */
4603 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4604 + initmap.virtual = (unsigned long)__init_begin;
4605 + initmap.length = _sdata - __init_begin;
4606 + initmap.type = __MT_MEMORY_RWX;
4607 + create_mapping(&initmap);
4608 +
4609 + /* when freeing initmem we will make this RX */
4610 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4611 + kernel.virtual = (unsigned long)_stext;
4612 + kernel.length = __init_begin - _stext;
4613 + kernel.type = __MT_MEMORY_RWX;
4614 + create_mapping(&kernel);
4615 +
4616 + if (map.virtual < (unsigned long)_stext) {
4617 + map.length = (unsigned long)_stext - map.virtual;
4618 + map.type = __MT_MEMORY_RWX;
4619 + create_mapping(&map);
4620 + }
4621 +
4622 + map.pfn = __phys_to_pfn(__pa(_sdata));
4623 + map.virtual = (unsigned long)_sdata;
4624 + map.length = end - __pa(_sdata);
4625 + }
4626 +
4627 + map.type = MT_MEMORY_RW;
4628 + create_mapping(&map);
4629 +#else
4630 if (end < kernel_x_start || start >= kernel_x_end) {
4631 map.pfn = __phys_to_pfn(start);
4632 map.virtual = __phys_to_virt(start);
4633 map.length = end - start;
4634 - map.type = MT_MEMORY_RWX;
4635 + map.type = __MT_MEMORY_RWX;
4636
4637 create_mapping(&map);
4638 } else {
4639 @@ -1390,7 +1481,7 @@ static void __init map_lowmem(void)
4640 map.pfn = __phys_to_pfn(kernel_x_start);
4641 map.virtual = __phys_to_virt(kernel_x_start);
4642 map.length = kernel_x_end - kernel_x_start;
4643 - map.type = MT_MEMORY_RWX;
4644 + map.type = __MT_MEMORY_RWX;
4645
4646 create_mapping(&map);
4647
4648 @@ -1403,6 +1494,7 @@ static void __init map_lowmem(void)
4649 create_mapping(&map);
4650 }
4651 }
4652 +#endif
4653 }
4654 }
4655
4656 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4657 index a5bc92d..0bb4730 100644
4658 --- a/arch/arm/plat-omap/sram.c
4659 +++ b/arch/arm/plat-omap/sram.c
4660 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4661 * Looks like we need to preserve some bootloader code at the
4662 * beginning of SRAM for jumping to flash for reboot to work...
4663 */
4664 + pax_open_kernel();
4665 memset_io(omap_sram_base + omap_sram_skip, 0,
4666 omap_sram_size - omap_sram_skip);
4667 + pax_close_kernel();
4668 }
4669 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4670 index ce6d763..cfea917 100644
4671 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4672 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4673 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4674 int (*started)(unsigned ch);
4675 int (*flush)(unsigned ch);
4676 int (*stop)(unsigned ch);
4677 -};
4678 +} __no_const;
4679
4680 extern void *samsung_dmadev_get_ops(void);
4681 extern void *s3c_dma_get_ops(void);
4682 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4683 index 6c0f684..5faea9d 100644
4684 --- a/arch/arm64/include/asm/uaccess.h
4685 +++ b/arch/arm64/include/asm/uaccess.h
4686 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4687 flag; \
4688 })
4689
4690 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4691 #define access_ok(type, addr, size) __range_ok(addr, size)
4692 #define user_addr_max get_fs
4693
4694 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4695 index c3a58a1..78fbf54 100644
4696 --- a/arch/avr32/include/asm/cache.h
4697 +++ b/arch/avr32/include/asm/cache.h
4698 @@ -1,8 +1,10 @@
4699 #ifndef __ASM_AVR32_CACHE_H
4700 #define __ASM_AVR32_CACHE_H
4701
4702 +#include <linux/const.h>
4703 +
4704 #define L1_CACHE_SHIFT 5
4705 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4706 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4707
4708 /*
4709 * Memory returned by kmalloc() may be used for DMA, so we must make
4710 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4711 index d232888..87c8df1 100644
4712 --- a/arch/avr32/include/asm/elf.h
4713 +++ b/arch/avr32/include/asm/elf.h
4714 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4715 the loader. We need to make sure that it is out of the way of the program
4716 that it will "exec", and that there is sufficient room for the brk. */
4717
4718 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4719 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4720
4721 +#ifdef CONFIG_PAX_ASLR
4722 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4723 +
4724 +#define PAX_DELTA_MMAP_LEN 15
4725 +#define PAX_DELTA_STACK_LEN 15
4726 +#endif
4727
4728 /* This yields a mask that user programs can use to figure out what
4729 instruction set this CPU supports. This could be done in user space,
4730 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4731 index 479330b..53717a8 100644
4732 --- a/arch/avr32/include/asm/kmap_types.h
4733 +++ b/arch/avr32/include/asm/kmap_types.h
4734 @@ -2,9 +2,9 @@
4735 #define __ASM_AVR32_KMAP_TYPES_H
4736
4737 #ifdef CONFIG_DEBUG_HIGHMEM
4738 -# define KM_TYPE_NR 29
4739 +# define KM_TYPE_NR 30
4740 #else
4741 -# define KM_TYPE_NR 14
4742 +# define KM_TYPE_NR 15
4743 #endif
4744
4745 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4746 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4747 index 0eca933..eb78c7b 100644
4748 --- a/arch/avr32/mm/fault.c
4749 +++ b/arch/avr32/mm/fault.c
4750 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4751
4752 int exception_trace = 1;
4753
4754 +#ifdef CONFIG_PAX_PAGEEXEC
4755 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4756 +{
4757 + unsigned long i;
4758 +
4759 + printk(KERN_ERR "PAX: bytes at PC: ");
4760 + for (i = 0; i < 20; i++) {
4761 + unsigned char c;
4762 + if (get_user(c, (unsigned char *)pc+i))
4763 + printk(KERN_CONT "???????? ");
4764 + else
4765 + printk(KERN_CONT "%02x ", c);
4766 + }
4767 + printk("\n");
4768 +}
4769 +#endif
4770 +
4771 /*
4772 * This routine handles page faults. It determines the address and the
4773 * problem, and then passes it off to one of the appropriate routines.
4774 @@ -176,6 +193,16 @@ bad_area:
4775 up_read(&mm->mmap_sem);
4776
4777 if (user_mode(regs)) {
4778 +
4779 +#ifdef CONFIG_PAX_PAGEEXEC
4780 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4781 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4782 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4783 + do_group_exit(SIGKILL);
4784 + }
4785 + }
4786 +#endif
4787 +
4788 if (exception_trace && printk_ratelimit())
4789 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4790 "sp %08lx ecr %lu\n",
4791 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4792 index 568885a..f8008df 100644
4793 --- a/arch/blackfin/include/asm/cache.h
4794 +++ b/arch/blackfin/include/asm/cache.h
4795 @@ -7,6 +7,7 @@
4796 #ifndef __ARCH_BLACKFIN_CACHE_H
4797 #define __ARCH_BLACKFIN_CACHE_H
4798
4799 +#include <linux/const.h>
4800 #include <linux/linkage.h> /* for asmlinkage */
4801
4802 /*
4803 @@ -14,7 +15,7 @@
4804 * Blackfin loads 32 bytes for cache
4805 */
4806 #define L1_CACHE_SHIFT 5
4807 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4808 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4809 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4810
4811 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4812 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4813 index aea2718..3639a60 100644
4814 --- a/arch/cris/include/arch-v10/arch/cache.h
4815 +++ b/arch/cris/include/arch-v10/arch/cache.h
4816 @@ -1,8 +1,9 @@
4817 #ifndef _ASM_ARCH_CACHE_H
4818 #define _ASM_ARCH_CACHE_H
4819
4820 +#include <linux/const.h>
4821 /* Etrax 100LX have 32-byte cache-lines. */
4822 -#define L1_CACHE_BYTES 32
4823 #define L1_CACHE_SHIFT 5
4824 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4825
4826 #endif /* _ASM_ARCH_CACHE_H */
4827 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4828 index 7caf25d..ee65ac5 100644
4829 --- a/arch/cris/include/arch-v32/arch/cache.h
4830 +++ b/arch/cris/include/arch-v32/arch/cache.h
4831 @@ -1,11 +1,12 @@
4832 #ifndef _ASM_CRIS_ARCH_CACHE_H
4833 #define _ASM_CRIS_ARCH_CACHE_H
4834
4835 +#include <linux/const.h>
4836 #include <arch/hwregs/dma.h>
4837
4838 /* A cache-line is 32 bytes. */
4839 -#define L1_CACHE_BYTES 32
4840 #define L1_CACHE_SHIFT 5
4841 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4842
4843 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4844
4845 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4846 index b86329d..6709906 100644
4847 --- a/arch/frv/include/asm/atomic.h
4848 +++ b/arch/frv/include/asm/atomic.h
4849 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4850 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4851 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4852
4853 +#define atomic64_read_unchecked(v) atomic64_read(v)
4854 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4855 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4856 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4857 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4858 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4859 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4860 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4861 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4862 +
4863 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4864 {
4865 int c, old;
4866 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4867 index 2797163..c2a401d 100644
4868 --- a/arch/frv/include/asm/cache.h
4869 +++ b/arch/frv/include/asm/cache.h
4870 @@ -12,10 +12,11 @@
4871 #ifndef __ASM_CACHE_H
4872 #define __ASM_CACHE_H
4873
4874 +#include <linux/const.h>
4875
4876 /* bytes per L1 cache line */
4877 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4878 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4879 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4880
4881 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4882 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4883 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4884 index 43901f2..0d8b865 100644
4885 --- a/arch/frv/include/asm/kmap_types.h
4886 +++ b/arch/frv/include/asm/kmap_types.h
4887 @@ -2,6 +2,6 @@
4888 #ifndef _ASM_KMAP_TYPES_H
4889 #define _ASM_KMAP_TYPES_H
4890
4891 -#define KM_TYPE_NR 17
4892 +#define KM_TYPE_NR 18
4893
4894 #endif
4895 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4896 index 836f147..4cf23f5 100644
4897 --- a/arch/frv/mm/elf-fdpic.c
4898 +++ b/arch/frv/mm/elf-fdpic.c
4899 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4900 {
4901 struct vm_area_struct *vma;
4902 struct vm_unmapped_area_info info;
4903 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4904
4905 if (len > TASK_SIZE)
4906 return -ENOMEM;
4907 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4908 if (addr) {
4909 addr = PAGE_ALIGN(addr);
4910 vma = find_vma(current->mm, addr);
4911 - if (TASK_SIZE - len >= addr &&
4912 - (!vma || addr + len <= vma->vm_start))
4913 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4914 goto success;
4915 }
4916
4917 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4918 info.high_limit = (current->mm->start_stack - 0x00200000);
4919 info.align_mask = 0;
4920 info.align_offset = 0;
4921 + info.threadstack_offset = offset;
4922 addr = vm_unmapped_area(&info);
4923 if (!(addr & ~PAGE_MASK))
4924 goto success;
4925 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4926 index f4ca594..adc72fd6 100644
4927 --- a/arch/hexagon/include/asm/cache.h
4928 +++ b/arch/hexagon/include/asm/cache.h
4929 @@ -21,9 +21,11 @@
4930 #ifndef __ASM_CACHE_H
4931 #define __ASM_CACHE_H
4932
4933 +#include <linux/const.h>
4934 +
4935 /* Bytes per L1 cache line */
4936 -#define L1_CACHE_SHIFT (5)
4937 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4938 +#define L1_CACHE_SHIFT 5
4939 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4940
4941 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4942 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4943 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4944 index 0c8e553..112d734 100644
4945 --- a/arch/ia64/Kconfig
4946 +++ b/arch/ia64/Kconfig
4947 @@ -544,6 +544,7 @@ source "drivers/sn/Kconfig"
4948 config KEXEC
4949 bool "kexec system call"
4950 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4951 + depends on !GRKERNSEC_KMEM
4952 help
4953 kexec is a system call that implements the ability to shutdown your
4954 current kernel, and to start another kernel. It is like a reboot
4955 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4956 index 6e6fe18..a6ae668 100644
4957 --- a/arch/ia64/include/asm/atomic.h
4958 +++ b/arch/ia64/include/asm/atomic.h
4959 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4960 #define atomic64_inc(v) atomic64_add(1, (v))
4961 #define atomic64_dec(v) atomic64_sub(1, (v))
4962
4963 +#define atomic64_read_unchecked(v) atomic64_read(v)
4964 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4965 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4966 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4967 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4968 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4969 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4970 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4971 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4972 +
4973 /* Atomic operations are already serializing */
4974 #define smp_mb__before_atomic_dec() barrier()
4975 #define smp_mb__after_atomic_dec() barrier()
4976 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4977 index 988254a..e1ee885 100644
4978 --- a/arch/ia64/include/asm/cache.h
4979 +++ b/arch/ia64/include/asm/cache.h
4980 @@ -1,6 +1,7 @@
4981 #ifndef _ASM_IA64_CACHE_H
4982 #define _ASM_IA64_CACHE_H
4983
4984 +#include <linux/const.h>
4985
4986 /*
4987 * Copyright (C) 1998-2000 Hewlett-Packard Co
4988 @@ -9,7 +10,7 @@
4989
4990 /* Bytes per L1 (data) cache line. */
4991 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4992 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4993 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4994
4995 #ifdef CONFIG_SMP
4996 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4997 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4998 index 5a83c5c..4d7f553 100644
4999 --- a/arch/ia64/include/asm/elf.h
5000 +++ b/arch/ia64/include/asm/elf.h
5001 @@ -42,6 +42,13 @@
5002 */
5003 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5004
5005 +#ifdef CONFIG_PAX_ASLR
5006 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5007 +
5008 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5009 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5010 +#endif
5011 +
5012 #define PT_IA_64_UNWIND 0x70000001
5013
5014 /* IA-64 relocations: */
5015 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5016 index 5767cdf..7462574 100644
5017 --- a/arch/ia64/include/asm/pgalloc.h
5018 +++ b/arch/ia64/include/asm/pgalloc.h
5019 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5020 pgd_val(*pgd_entry) = __pa(pud);
5021 }
5022
5023 +static inline void
5024 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5025 +{
5026 + pgd_populate(mm, pgd_entry, pud);
5027 +}
5028 +
5029 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5030 {
5031 return quicklist_alloc(0, GFP_KERNEL, NULL);
5032 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5033 pud_val(*pud_entry) = __pa(pmd);
5034 }
5035
5036 +static inline void
5037 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5038 +{
5039 + pud_populate(mm, pud_entry, pmd);
5040 +}
5041 +
5042 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5043 {
5044 return quicklist_alloc(0, GFP_KERNEL, NULL);
5045 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5046 index 7935115..c0eca6a 100644
5047 --- a/arch/ia64/include/asm/pgtable.h
5048 +++ b/arch/ia64/include/asm/pgtable.h
5049 @@ -12,7 +12,7 @@
5050 * David Mosberger-Tang <davidm@hpl.hp.com>
5051 */
5052
5053 -
5054 +#include <linux/const.h>
5055 #include <asm/mman.h>
5056 #include <asm/page.h>
5057 #include <asm/processor.h>
5058 @@ -142,6 +142,17 @@
5059 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5060 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5061 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5062 +
5063 +#ifdef CONFIG_PAX_PAGEEXEC
5064 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5065 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5066 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5067 +#else
5068 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5069 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5070 +# define PAGE_COPY_NOEXEC PAGE_COPY
5071 +#endif
5072 +
5073 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5074 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5075 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5076 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5077 index 45698cd..e8e2dbc 100644
5078 --- a/arch/ia64/include/asm/spinlock.h
5079 +++ b/arch/ia64/include/asm/spinlock.h
5080 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5081 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5082
5083 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5084 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5085 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5086 }
5087
5088 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5089 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5090 index 449c8c0..3d4b1e9 100644
5091 --- a/arch/ia64/include/asm/uaccess.h
5092 +++ b/arch/ia64/include/asm/uaccess.h
5093 @@ -70,6 +70,7 @@
5094 && ((segment).seg == KERNEL_DS.seg \
5095 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5096 })
5097 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5098 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5099
5100 /*
5101 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5102 static inline unsigned long
5103 __copy_to_user (void __user *to, const void *from, unsigned long count)
5104 {
5105 + if (count > INT_MAX)
5106 + return count;
5107 +
5108 + if (!__builtin_constant_p(count))
5109 + check_object_size(from, count, true);
5110 +
5111 return __copy_user(to, (__force void __user *) from, count);
5112 }
5113
5114 static inline unsigned long
5115 __copy_from_user (void *to, const void __user *from, unsigned long count)
5116 {
5117 + if (count > INT_MAX)
5118 + return count;
5119 +
5120 + if (!__builtin_constant_p(count))
5121 + check_object_size(to, count, false);
5122 +
5123 return __copy_user((__force void __user *) to, from, count);
5124 }
5125
5126 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5127 ({ \
5128 void __user *__cu_to = (to); \
5129 const void *__cu_from = (from); \
5130 - long __cu_len = (n); \
5131 + unsigned long __cu_len = (n); \
5132 \
5133 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5134 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5135 + if (!__builtin_constant_p(n)) \
5136 + check_object_size(__cu_from, __cu_len, true); \
5137 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5138 + } \
5139 __cu_len; \
5140 })
5141
5142 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5143 ({ \
5144 void *__cu_to = (to); \
5145 const void __user *__cu_from = (from); \
5146 - long __cu_len = (n); \
5147 + unsigned long __cu_len = (n); \
5148 \
5149 __chk_user_ptr(__cu_from); \
5150 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5151 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5152 + if (!__builtin_constant_p(n)) \
5153 + check_object_size(__cu_to, __cu_len, false); \
5154 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5155 + } \
5156 __cu_len; \
5157 })
5158
5159 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5160 index 24603be..948052d 100644
5161 --- a/arch/ia64/kernel/module.c
5162 +++ b/arch/ia64/kernel/module.c
5163 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5164 void
5165 module_free (struct module *mod, void *module_region)
5166 {
5167 - if (mod && mod->arch.init_unw_table &&
5168 - module_region == mod->module_init) {
5169 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5170 unw_remove_unwind_table(mod->arch.init_unw_table);
5171 mod->arch.init_unw_table = NULL;
5172 }
5173 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5174 }
5175
5176 static inline int
5177 +in_init_rx (const struct module *mod, uint64_t addr)
5178 +{
5179 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5180 +}
5181 +
5182 +static inline int
5183 +in_init_rw (const struct module *mod, uint64_t addr)
5184 +{
5185 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5186 +}
5187 +
5188 +static inline int
5189 in_init (const struct module *mod, uint64_t addr)
5190 {
5191 - return addr - (uint64_t) mod->module_init < mod->init_size;
5192 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5193 +}
5194 +
5195 +static inline int
5196 +in_core_rx (const struct module *mod, uint64_t addr)
5197 +{
5198 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5199 +}
5200 +
5201 +static inline int
5202 +in_core_rw (const struct module *mod, uint64_t addr)
5203 +{
5204 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5205 }
5206
5207 static inline int
5208 in_core (const struct module *mod, uint64_t addr)
5209 {
5210 - return addr - (uint64_t) mod->module_core < mod->core_size;
5211 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5212 }
5213
5214 static inline int
5215 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5216 break;
5217
5218 case RV_BDREL:
5219 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5220 + if (in_init_rx(mod, val))
5221 + val -= (uint64_t) mod->module_init_rx;
5222 + else if (in_init_rw(mod, val))
5223 + val -= (uint64_t) mod->module_init_rw;
5224 + else if (in_core_rx(mod, val))
5225 + val -= (uint64_t) mod->module_core_rx;
5226 + else if (in_core_rw(mod, val))
5227 + val -= (uint64_t) mod->module_core_rw;
5228 break;
5229
5230 case RV_LTV:
5231 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5232 * addresses have been selected...
5233 */
5234 uint64_t gp;
5235 - if (mod->core_size > MAX_LTOFF)
5236 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5237 /*
5238 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5239 * at the end of the module.
5240 */
5241 - gp = mod->core_size - MAX_LTOFF / 2;
5242 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5243 else
5244 - gp = mod->core_size / 2;
5245 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5246 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5247 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5248 mod->arch.gp = gp;
5249 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5250 }
5251 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5252 index ab33328..f39506c 100644
5253 --- a/arch/ia64/kernel/palinfo.c
5254 +++ b/arch/ia64/kernel/palinfo.c
5255 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5256 return NOTIFY_OK;
5257 }
5258
5259 -static struct notifier_block __refdata palinfo_cpu_notifier =
5260 +static struct notifier_block palinfo_cpu_notifier =
5261 {
5262 .notifier_call = palinfo_cpu_callback,
5263 .priority = 0,
5264 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5265 index 41e33f8..65180b2a 100644
5266 --- a/arch/ia64/kernel/sys_ia64.c
5267 +++ b/arch/ia64/kernel/sys_ia64.c
5268 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5269 unsigned long align_mask = 0;
5270 struct mm_struct *mm = current->mm;
5271 struct vm_unmapped_area_info info;
5272 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5273
5274 if (len > RGN_MAP_LIMIT)
5275 return -ENOMEM;
5276 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5277 if (REGION_NUMBER(addr) == RGN_HPAGE)
5278 addr = 0;
5279 #endif
5280 +
5281 +#ifdef CONFIG_PAX_RANDMMAP
5282 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5283 + addr = mm->free_area_cache;
5284 + else
5285 +#endif
5286 +
5287 if (!addr)
5288 addr = TASK_UNMAPPED_BASE;
5289
5290 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5291 info.high_limit = TASK_SIZE;
5292 info.align_mask = align_mask;
5293 info.align_offset = 0;
5294 + info.threadstack_offset = offset;
5295 return vm_unmapped_area(&info);
5296 }
5297
5298 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5299 index 84f8a52..7c76178 100644
5300 --- a/arch/ia64/kernel/vmlinux.lds.S
5301 +++ b/arch/ia64/kernel/vmlinux.lds.S
5302 @@ -192,7 +192,7 @@ SECTIONS {
5303 /* Per-cpu data: */
5304 . = ALIGN(PERCPU_PAGE_SIZE);
5305 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5306 - __phys_per_cpu_start = __per_cpu_load;
5307 + __phys_per_cpu_start = per_cpu_load;
5308 /*
5309 * ensure percpu data fits
5310 * into percpu page size
5311 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5312 index 7225dad..2a7c8256 100644
5313 --- a/arch/ia64/mm/fault.c
5314 +++ b/arch/ia64/mm/fault.c
5315 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5316 return pte_present(pte);
5317 }
5318
5319 +#ifdef CONFIG_PAX_PAGEEXEC
5320 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5321 +{
5322 + unsigned long i;
5323 +
5324 + printk(KERN_ERR "PAX: bytes at PC: ");
5325 + for (i = 0; i < 8; i++) {
5326 + unsigned int c;
5327 + if (get_user(c, (unsigned int *)pc+i))
5328 + printk(KERN_CONT "???????? ");
5329 + else
5330 + printk(KERN_CONT "%08x ", c);
5331 + }
5332 + printk("\n");
5333 +}
5334 +#endif
5335 +
5336 # define VM_READ_BIT 0
5337 # define VM_WRITE_BIT 1
5338 # define VM_EXEC_BIT 2
5339 @@ -151,8 +168,21 @@ retry:
5340 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5341 goto bad_area;
5342
5343 - if ((vma->vm_flags & mask) != mask)
5344 + if ((vma->vm_flags & mask) != mask) {
5345 +
5346 +#ifdef CONFIG_PAX_PAGEEXEC
5347 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5348 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5349 + goto bad_area;
5350 +
5351 + up_read(&mm->mmap_sem);
5352 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5353 + do_group_exit(SIGKILL);
5354 + }
5355 +#endif
5356 +
5357 goto bad_area;
5358 + }
5359
5360 /*
5361 * If for any reason at all we couldn't handle the fault, make
5362 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5363 index 68232db..6ca80af 100644
5364 --- a/arch/ia64/mm/hugetlbpage.c
5365 +++ b/arch/ia64/mm/hugetlbpage.c
5366 @@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5367 unsigned long pgoff, unsigned long flags)
5368 {
5369 struct vm_unmapped_area_info info;
5370 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5371
5372 if (len > RGN_MAP_LIMIT)
5373 return -ENOMEM;
5374 @@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5375 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5376 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5377 info.align_offset = 0;
5378 + info.threadstack_offset = offset;
5379 return vm_unmapped_area(&info);
5380 }
5381
5382 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5383 index 25c3502..560dae7 100644
5384 --- a/arch/ia64/mm/init.c
5385 +++ b/arch/ia64/mm/init.c
5386 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5387 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5388 vma->vm_end = vma->vm_start + PAGE_SIZE;
5389 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5390 +
5391 +#ifdef CONFIG_PAX_PAGEEXEC
5392 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5393 + vma->vm_flags &= ~VM_EXEC;
5394 +
5395 +#ifdef CONFIG_PAX_MPROTECT
5396 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5397 + vma->vm_flags &= ~VM_MAYEXEC;
5398 +#endif
5399 +
5400 + }
5401 +#endif
5402 +
5403 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5404 down_write(&current->mm->mmap_sem);
5405 if (insert_vm_struct(current->mm, vma)) {
5406 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5407 index 40b3ee9..8c2c112 100644
5408 --- a/arch/m32r/include/asm/cache.h
5409 +++ b/arch/m32r/include/asm/cache.h
5410 @@ -1,8 +1,10 @@
5411 #ifndef _ASM_M32R_CACHE_H
5412 #define _ASM_M32R_CACHE_H
5413
5414 +#include <linux/const.h>
5415 +
5416 /* L1 cache line size */
5417 #define L1_CACHE_SHIFT 4
5418 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5419 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5420
5421 #endif /* _ASM_M32R_CACHE_H */
5422 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5423 index 82abd15..d95ae5d 100644
5424 --- a/arch/m32r/lib/usercopy.c
5425 +++ b/arch/m32r/lib/usercopy.c
5426 @@ -14,6 +14,9 @@
5427 unsigned long
5428 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5429 {
5430 + if ((long)n < 0)
5431 + return n;
5432 +
5433 prefetch(from);
5434 if (access_ok(VERIFY_WRITE, to, n))
5435 __copy_user(to,from,n);
5436 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5437 unsigned long
5438 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5439 {
5440 + if ((long)n < 0)
5441 + return n;
5442 +
5443 prefetchw(to);
5444 if (access_ok(VERIFY_READ, from, n))
5445 __copy_user_zeroing(to,from,n);
5446 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5447 index 0395c51..5f26031 100644
5448 --- a/arch/m68k/include/asm/cache.h
5449 +++ b/arch/m68k/include/asm/cache.h
5450 @@ -4,9 +4,11 @@
5451 #ifndef __ARCH_M68K_CACHE_H
5452 #define __ARCH_M68K_CACHE_H
5453
5454 +#include <linux/const.h>
5455 +
5456 /* bytes per L1 cache line */
5457 #define L1_CACHE_SHIFT 4
5458 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5459 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5460
5461 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5462
5463 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5464 index 0424315..defcca9 100644
5465 --- a/arch/metag/mm/hugetlbpage.c
5466 +++ b/arch/metag/mm/hugetlbpage.c
5467 @@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5468 info.high_limit = TASK_SIZE;
5469 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5470 info.align_offset = 0;
5471 + info.threadstack_offset = 0;
5472 return vm_unmapped_area(&info);
5473 }
5474
5475 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5476 index 4efe96a..60e8699 100644
5477 --- a/arch/microblaze/include/asm/cache.h
5478 +++ b/arch/microblaze/include/asm/cache.h
5479 @@ -13,11 +13,12 @@
5480 #ifndef _ASM_MICROBLAZE_CACHE_H
5481 #define _ASM_MICROBLAZE_CACHE_H
5482
5483 +#include <linux/const.h>
5484 #include <asm/registers.h>
5485
5486 #define L1_CACHE_SHIFT 5
5487 /* word-granular cache in microblaze */
5488 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5489 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5490
5491 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5492
5493 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5494 index 95fa1f1..56a6fa2 100644
5495 --- a/arch/mips/Kconfig
5496 +++ b/arch/mips/Kconfig
5497 @@ -2298,6 +2298,7 @@ source "kernel/Kconfig.preempt"
5498
5499 config KEXEC
5500 bool "Kexec system call"
5501 + depends on !GRKERNSEC_KMEM
5502 help
5503 kexec is a system call that implements the ability to shutdown your
5504 current kernel, and to start another kernel. It is like a reboot
5505 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5506 index 02f2444..506969c 100644
5507 --- a/arch/mips/cavium-octeon/dma-octeon.c
5508 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5509 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5510 if (dma_release_from_coherent(dev, order, vaddr))
5511 return;
5512
5513 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5514 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5515 }
5516
5517 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5518 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5519 index 7eed2f2..c4e385d 100644
5520 --- a/arch/mips/include/asm/atomic.h
5521 +++ b/arch/mips/include/asm/atomic.h
5522 @@ -21,15 +21,39 @@
5523 #include <asm/cmpxchg.h>
5524 #include <asm/war.h>
5525
5526 +#ifdef CONFIG_GENERIC_ATOMIC64
5527 +#include <asm-generic/atomic64.h>
5528 +#endif
5529 +
5530 #define ATOMIC_INIT(i) { (i) }
5531
5532 +#ifdef CONFIG_64BIT
5533 +#define _ASM_EXTABLE(from, to) \
5534 +" .section __ex_table,\"a\"\n" \
5535 +" .dword " #from ", " #to"\n" \
5536 +" .previous\n"
5537 +#else
5538 +#define _ASM_EXTABLE(from, to) \
5539 +" .section __ex_table,\"a\"\n" \
5540 +" .word " #from ", " #to"\n" \
5541 +" .previous\n"
5542 +#endif
5543 +
5544 /*
5545 * atomic_read - read atomic variable
5546 * @v: pointer of type atomic_t
5547 *
5548 * Atomically reads the value of @v.
5549 */
5550 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5551 +static inline int atomic_read(const atomic_t *v)
5552 +{
5553 + return (*(volatile const int *) &v->counter);
5554 +}
5555 +
5556 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5557 +{
5558 + return (*(volatile const int *) &v->counter);
5559 +}
5560
5561 /*
5562 * atomic_set - set atomic variable
5563 @@ -38,7 +62,15 @@
5564 *
5565 * Atomically sets the value of @v to @i.
5566 */
5567 -#define atomic_set(v, i) ((v)->counter = (i))
5568 +static inline void atomic_set(atomic_t *v, int i)
5569 +{
5570 + v->counter = i;
5571 +}
5572 +
5573 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5574 +{
5575 + v->counter = i;
5576 +}
5577
5578 /*
5579 * atomic_add - add integer to atomic variable
5580 @@ -47,7 +79,67 @@
5581 *
5582 * Atomically adds @i to @v.
5583 */
5584 -static __inline__ void atomic_add(int i, atomic_t * v)
5585 +static __inline__ void atomic_add(int i, atomic_t *v)
5586 +{
5587 + int temp;
5588 +
5589 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5590 + __asm__ __volatile__(
5591 + " .set mips3 \n"
5592 + "1: ll %0, %1 # atomic_add \n"
5593 +#ifdef CONFIG_PAX_REFCOUNT
5594 + /* Exception on overflow. */
5595 + "2: add %0, %2 \n"
5596 +#else
5597 + " addu %0, %2 \n"
5598 +#endif
5599 + " sc %0, %1 \n"
5600 + " beqzl %0, 1b \n"
5601 +#ifdef CONFIG_PAX_REFCOUNT
5602 + "3: \n"
5603 + _ASM_EXTABLE(2b, 3b)
5604 +#endif
5605 + " .set mips0 \n"
5606 + : "=&r" (temp), "+m" (v->counter)
5607 + : "Ir" (i));
5608 + } else if (kernel_uses_llsc) {
5609 + __asm__ __volatile__(
5610 + " .set mips3 \n"
5611 + "1: ll %0, %1 # atomic_add \n"
5612 +#ifdef CONFIG_PAX_REFCOUNT
5613 + /* Exception on overflow. */
5614 + "2: add %0, %2 \n"
5615 +#else
5616 + " addu %0, %2 \n"
5617 +#endif
5618 + " sc %0, %1 \n"
5619 + " beqz %0, 1b \n"
5620 +#ifdef CONFIG_PAX_REFCOUNT
5621 + "3: \n"
5622 + _ASM_EXTABLE(2b, 3b)
5623 +#endif
5624 + " .set mips0 \n"
5625 + : "=&r" (temp), "+m" (v->counter)
5626 + : "Ir" (i));
5627 + } else {
5628 + unsigned long flags;
5629 +
5630 + raw_local_irq_save(flags);
5631 + __asm__ __volatile__(
5632 +#ifdef CONFIG_PAX_REFCOUNT
5633 + /* Exception on overflow. */
5634 + "1: add %0, %1 \n"
5635 + "2: \n"
5636 + _ASM_EXTABLE(1b, 2b)
5637 +#else
5638 + " addu %0, %1 \n"
5639 +#endif
5640 + : "+r" (v->counter) : "Ir" (i));
5641 + raw_local_irq_restore(flags);
5642 + }
5643 +}
5644 +
5645 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5646 {
5647 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5648 int temp;
5649 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5650 *
5651 * Atomically subtracts @i from @v.
5652 */
5653 -static __inline__ void atomic_sub(int i, atomic_t * v)
5654 +static __inline__ void atomic_sub(int i, atomic_t *v)
5655 +{
5656 + int temp;
5657 +
5658 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5659 + __asm__ __volatile__(
5660 + " .set mips3 \n"
5661 + "1: ll %0, %1 # atomic64_sub \n"
5662 +#ifdef CONFIG_PAX_REFCOUNT
5663 + /* Exception on overflow. */
5664 + "2: sub %0, %2 \n"
5665 +#else
5666 + " subu %0, %2 \n"
5667 +#endif
5668 + " sc %0, %1 \n"
5669 + " beqzl %0, 1b \n"
5670 +#ifdef CONFIG_PAX_REFCOUNT
5671 + "3: \n"
5672 + _ASM_EXTABLE(2b, 3b)
5673 +#endif
5674 + " .set mips0 \n"
5675 + : "=&r" (temp), "+m" (v->counter)
5676 + : "Ir" (i));
5677 + } else if (kernel_uses_llsc) {
5678 + __asm__ __volatile__(
5679 + " .set mips3 \n"
5680 + "1: ll %0, %1 # atomic64_sub \n"
5681 +#ifdef CONFIG_PAX_REFCOUNT
5682 + /* Exception on overflow. */
5683 + "2: sub %0, %2 \n"
5684 +#else
5685 + " subu %0, %2 \n"
5686 +#endif
5687 + " sc %0, %1 \n"
5688 + " beqz %0, 1b \n"
5689 +#ifdef CONFIG_PAX_REFCOUNT
5690 + "3: \n"
5691 + _ASM_EXTABLE(2b, 3b)
5692 +#endif
5693 + " .set mips0 \n"
5694 + : "=&r" (temp), "+m" (v->counter)
5695 + : "Ir" (i));
5696 + } else {
5697 + unsigned long flags;
5698 +
5699 + raw_local_irq_save(flags);
5700 + __asm__ __volatile__(
5701 +#ifdef CONFIG_PAX_REFCOUNT
5702 + /* Exception on overflow. */
5703 + "1: sub %0, %1 \n"
5704 + "2: \n"
5705 + _ASM_EXTABLE(1b, 2b)
5706 +#else
5707 + " subu %0, %1 \n"
5708 +#endif
5709 + : "+r" (v->counter) : "Ir" (i));
5710 + raw_local_irq_restore(flags);
5711 + }
5712 +}
5713 +
5714 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5715 {
5716 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5717 int temp;
5718 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5719 /*
5720 * Same as above, but return the result value
5721 */
5722 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5723 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5724 +{
5725 + int result;
5726 + int temp;
5727 +
5728 + smp_mb__before_llsc();
5729 +
5730 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5731 + __asm__ __volatile__(
5732 + " .set mips3 \n"
5733 + "1: ll %1, %2 # atomic_add_return \n"
5734 +#ifdef CONFIG_PAX_REFCOUNT
5735 + "2: add %0, %1, %3 \n"
5736 +#else
5737 + " addu %0, %1, %3 \n"
5738 +#endif
5739 + " sc %0, %2 \n"
5740 + " beqzl %0, 1b \n"
5741 +#ifdef CONFIG_PAX_REFCOUNT
5742 + " b 4f \n"
5743 + " .set noreorder \n"
5744 + "3: b 5f \n"
5745 + " move %0, %1 \n"
5746 + " .set reorder \n"
5747 + _ASM_EXTABLE(2b, 3b)
5748 +#endif
5749 + "4: addu %0, %1, %3 \n"
5750 +#ifdef CONFIG_PAX_REFCOUNT
5751 + "5: \n"
5752 +#endif
5753 + " .set mips0 \n"
5754 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5755 + : "Ir" (i));
5756 + } else if (kernel_uses_llsc) {
5757 + __asm__ __volatile__(
5758 + " .set mips3 \n"
5759 + "1: ll %1, %2 # atomic_add_return \n"
5760 +#ifdef CONFIG_PAX_REFCOUNT
5761 + "2: add %0, %1, %3 \n"
5762 +#else
5763 + " addu %0, %1, %3 \n"
5764 +#endif
5765 + " sc %0, %2 \n"
5766 + " bnez %0, 4f \n"
5767 + " b 1b \n"
5768 +#ifdef CONFIG_PAX_REFCOUNT
5769 + " .set noreorder \n"
5770 + "3: b 5f \n"
5771 + " move %0, %1 \n"
5772 + " .set reorder \n"
5773 + _ASM_EXTABLE(2b, 3b)
5774 +#endif
5775 + "4: addu %0, %1, %3 \n"
5776 +#ifdef CONFIG_PAX_REFCOUNT
5777 + "5: \n"
5778 +#endif
5779 + " .set mips0 \n"
5780 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5781 + : "Ir" (i));
5782 + } else {
5783 + unsigned long flags;
5784 +
5785 + raw_local_irq_save(flags);
5786 + __asm__ __volatile__(
5787 + " lw %0, %1 \n"
5788 +#ifdef CONFIG_PAX_REFCOUNT
5789 + /* Exception on overflow. */
5790 + "1: add %0, %2 \n"
5791 +#else
5792 + " addu %0, %2 \n"
5793 +#endif
5794 + " sw %0, %1 \n"
5795 +#ifdef CONFIG_PAX_REFCOUNT
5796 + /* Note: Dest reg is not modified on overflow */
5797 + "2: \n"
5798 + _ASM_EXTABLE(1b, 2b)
5799 +#endif
5800 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5801 + raw_local_irq_restore(flags);
5802 + }
5803 +
5804 + smp_llsc_mb();
5805 +
5806 + return result;
5807 +}
5808 +
5809 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5810 {
5811 int result;
5812
5813 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5814 return result;
5815 }
5816
5817 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5818 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5819 +{
5820 + int result;
5821 + int temp;
5822 +
5823 + smp_mb__before_llsc();
5824 +
5825 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5826 + __asm__ __volatile__(
5827 + " .set mips3 \n"
5828 + "1: ll %1, %2 # atomic_sub_return \n"
5829 +#ifdef CONFIG_PAX_REFCOUNT
5830 + "2: sub %0, %1, %3 \n"
5831 +#else
5832 + " subu %0, %1, %3 \n"
5833 +#endif
5834 + " sc %0, %2 \n"
5835 + " beqzl %0, 1b \n"
5836 +#ifdef CONFIG_PAX_REFCOUNT
5837 + " b 4f \n"
5838 + " .set noreorder \n"
5839 + "3: b 5f \n"
5840 + " move %0, %1 \n"
5841 + " .set reorder \n"
5842 + _ASM_EXTABLE(2b, 3b)
5843 +#endif
5844 + "4: subu %0, %1, %3 \n"
5845 +#ifdef CONFIG_PAX_REFCOUNT
5846 + "5: \n"
5847 +#endif
5848 + " .set mips0 \n"
5849 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5850 + : "Ir" (i), "m" (v->counter)
5851 + : "memory");
5852 + } else if (kernel_uses_llsc) {
5853 + __asm__ __volatile__(
5854 + " .set mips3 \n"
5855 + "1: ll %1, %2 # atomic_sub_return \n"
5856 +#ifdef CONFIG_PAX_REFCOUNT
5857 + "2: sub %0, %1, %3 \n"
5858 +#else
5859 + " subu %0, %1, %3 \n"
5860 +#endif
5861 + " sc %0, %2 \n"
5862 + " bnez %0, 4f \n"
5863 + " b 1b \n"
5864 +#ifdef CONFIG_PAX_REFCOUNT
5865 + " .set noreorder \n"
5866 + "3: b 5f \n"
5867 + " move %0, %1 \n"
5868 + " .set reorder \n"
5869 + _ASM_EXTABLE(2b, 3b)
5870 +#endif
5871 + "4: subu %0, %1, %3 \n"
5872 +#ifdef CONFIG_PAX_REFCOUNT
5873 + "5: \n"
5874 +#endif
5875 + " .set mips0 \n"
5876 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5877 + : "Ir" (i));
5878 + } else {
5879 + unsigned long flags;
5880 +
5881 + raw_local_irq_save(flags);
5882 + __asm__ __volatile__(
5883 + " lw %0, %1 \n"
5884 +#ifdef CONFIG_PAX_REFCOUNT
5885 + /* Exception on overflow. */
5886 + "1: sub %0, %2 \n"
5887 +#else
5888 + " subu %0, %2 \n"
5889 +#endif
5890 + " sw %0, %1 \n"
5891 +#ifdef CONFIG_PAX_REFCOUNT
5892 + /* Note: Dest reg is not modified on overflow */
5893 + "2: \n"
5894 + _ASM_EXTABLE(1b, 2b)
5895 +#endif
5896 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5897 + raw_local_irq_restore(flags);
5898 + }
5899 +
5900 + smp_llsc_mb();
5901 +
5902 + return result;
5903 +}
5904 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5905 {
5906 int result;
5907
5908 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5909 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5910 * The function returns the old value of @v minus @i.
5911 */
5912 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5913 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5914 {
5915 int result;
5916
5917 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5918 return result;
5919 }
5920
5921 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5922 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5923 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5924 +{
5925 + return cmpxchg(&v->counter, old, new);
5926 +}
5927 +
5928 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5929 + int new)
5930 +{
5931 + return cmpxchg(&(v->counter), old, new);
5932 +}
5933 +
5934 +static inline int atomic_xchg(atomic_t *v, int new)
5935 +{
5936 + return xchg(&v->counter, new);
5937 +}
5938 +
5939 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5940 +{
5941 + return xchg(&(v->counter), new);
5942 +}
5943
5944 /**
5945 * __atomic_add_unless - add unless the number is a given value
5946 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5947
5948 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5949 #define atomic_inc_return(v) atomic_add_return(1, (v))
5950 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5951 +{
5952 + return atomic_add_return_unchecked(1, v);
5953 +}
5954
5955 /*
5956 * atomic_sub_and_test - subtract value from variable and test result
5957 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5958 * other cases.
5959 */
5960 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5961 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5962 +{
5963 + return atomic_add_return_unchecked(1, v) == 0;
5964 +}
5965
5966 /*
5967 * atomic_dec_and_test - decrement by 1 and test
5968 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5969 * Atomically increments @v by 1.
5970 */
5971 #define atomic_inc(v) atomic_add(1, (v))
5972 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5973 +{
5974 + atomic_add_unchecked(1, v);
5975 +}
5976
5977 /*
5978 * atomic_dec - decrement and test
5979 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5980 * Atomically decrements @v by 1.
5981 */
5982 #define atomic_dec(v) atomic_sub(1, (v))
5983 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5984 +{
5985 + atomic_sub_unchecked(1, v);
5986 +}
5987
5988 /*
5989 * atomic_add_negative - add and test if negative
5990 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5991 * @v: pointer of type atomic64_t
5992 *
5993 */
5994 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5995 +static inline long atomic64_read(const atomic64_t *v)
5996 +{
5997 + return (*(volatile const long *) &v->counter);
5998 +}
5999 +
6000 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6001 +{
6002 + return (*(volatile const long *) &v->counter);
6003 +}
6004
6005 /*
6006 * atomic64_set - set atomic variable
6007 * @v: pointer of type atomic64_t
6008 * @i: required value
6009 */
6010 -#define atomic64_set(v, i) ((v)->counter = (i))
6011 +static inline void atomic64_set(atomic64_t *v, long i)
6012 +{
6013 + v->counter = i;
6014 +}
6015 +
6016 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6017 +{
6018 + v->counter = i;
6019 +}
6020
6021 /*
6022 * atomic64_add - add integer to atomic variable
6023 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6024 *
6025 * Atomically adds @i to @v.
6026 */
6027 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6028 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6029 +{
6030 + long temp;
6031 +
6032 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6033 + __asm__ __volatile__(
6034 + " .set mips3 \n"
6035 + "1: lld %0, %1 # atomic64_add \n"
6036 +#ifdef CONFIG_PAX_REFCOUNT
6037 + /* Exception on overflow. */
6038 + "2: dadd %0, %2 \n"
6039 +#else
6040 + " daddu %0, %2 \n"
6041 +#endif
6042 + " scd %0, %1 \n"
6043 + " beqzl %0, 1b \n"
6044 +#ifdef CONFIG_PAX_REFCOUNT
6045 + "3: \n"
6046 + _ASM_EXTABLE(2b, 3b)
6047 +#endif
6048 + " .set mips0 \n"
6049 + : "=&r" (temp), "+m" (v->counter)
6050 + : "Ir" (i));
6051 + } else if (kernel_uses_llsc) {
6052 + __asm__ __volatile__(
6053 + " .set mips3 \n"
6054 + "1: lld %0, %1 # atomic64_add \n"
6055 +#ifdef CONFIG_PAX_REFCOUNT
6056 + /* Exception on overflow. */
6057 + "2: dadd %0, %2 \n"
6058 +#else
6059 + " daddu %0, %2 \n"
6060 +#endif
6061 + " scd %0, %1 \n"
6062 + " beqz %0, 1b \n"
6063 +#ifdef CONFIG_PAX_REFCOUNT
6064 + "3: \n"
6065 + _ASM_EXTABLE(2b, 3b)
6066 +#endif
6067 + " .set mips0 \n"
6068 + : "=&r" (temp), "+m" (v->counter)
6069 + : "Ir" (i));
6070 + } else {
6071 + unsigned long flags;
6072 +
6073 + raw_local_irq_save(flags);
6074 + __asm__ __volatile__(
6075 +#ifdef CONFIG_PAX_REFCOUNT
6076 + /* Exception on overflow. */
6077 + "1: dadd %0, %1 \n"
6078 + "2: \n"
6079 + _ASM_EXTABLE(1b, 2b)
6080 +#else
6081 + " daddu %0, %1 \n"
6082 +#endif
6083 + : "+r" (v->counter) : "Ir" (i));
6084 + raw_local_irq_restore(flags);
6085 + }
6086 +}
6087 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6088 {
6089 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6090 long temp;
6091 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6092 *
6093 * Atomically subtracts @i from @v.
6094 */
6095 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6096 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6097 +{
6098 + long temp;
6099 +
6100 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6101 + __asm__ __volatile__(
6102 + " .set mips3 \n"
6103 + "1: lld %0, %1 # atomic64_sub \n"
6104 +#ifdef CONFIG_PAX_REFCOUNT
6105 + /* Exception on overflow. */
6106 + "2: dsub %0, %2 \n"
6107 +#else
6108 + " dsubu %0, %2 \n"
6109 +#endif
6110 + " scd %0, %1 \n"
6111 + " beqzl %0, 1b \n"
6112 +#ifdef CONFIG_PAX_REFCOUNT
6113 + "3: \n"
6114 + _ASM_EXTABLE(2b, 3b)
6115 +#endif
6116 + " .set mips0 \n"
6117 + : "=&r" (temp), "+m" (v->counter)
6118 + : "Ir" (i));
6119 + } else if (kernel_uses_llsc) {
6120 + __asm__ __volatile__(
6121 + " .set mips3 \n"
6122 + "1: lld %0, %1 # atomic64_sub \n"
6123 +#ifdef CONFIG_PAX_REFCOUNT
6124 + /* Exception on overflow. */
6125 + "2: dsub %0, %2 \n"
6126 +#else
6127 + " dsubu %0, %2 \n"
6128 +#endif
6129 + " scd %0, %1 \n"
6130 + " beqz %0, 1b \n"
6131 +#ifdef CONFIG_PAX_REFCOUNT
6132 + "3: \n"
6133 + _ASM_EXTABLE(2b, 3b)
6134 +#endif
6135 + " .set mips0 \n"
6136 + : "=&r" (temp), "+m" (v->counter)
6137 + : "Ir" (i));
6138 + } else {
6139 + unsigned long flags;
6140 +
6141 + raw_local_irq_save(flags);
6142 + __asm__ __volatile__(
6143 +#ifdef CONFIG_PAX_REFCOUNT
6144 + /* Exception on overflow. */
6145 + "1: dsub %0, %1 \n"
6146 + "2: \n"
6147 + _ASM_EXTABLE(1b, 2b)
6148 +#else
6149 + " dsubu %0, %1 \n"
6150 +#endif
6151 + : "+r" (v->counter) : "Ir" (i));
6152 + raw_local_irq_restore(flags);
6153 + }
6154 +}
6155 +
6156 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6157 {
6158 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6159 long temp;
6160 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6161 /*
6162 * Same as above, but return the result value
6163 */
6164 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6165 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6166 +{
6167 + long result;
6168 + long temp;
6169 +
6170 + smp_mb__before_llsc();
6171 +
6172 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6173 + __asm__ __volatile__(
6174 + " .set mips3 \n"
6175 + "1: lld %1, %2 # atomic64_add_return \n"
6176 +#ifdef CONFIG_PAX_REFCOUNT
6177 + "2: dadd %0, %1, %3 \n"
6178 +#else
6179 + " daddu %0, %1, %3 \n"
6180 +#endif
6181 + " scd %0, %2 \n"
6182 + " beqzl %0, 1b \n"
6183 +#ifdef CONFIG_PAX_REFCOUNT
6184 + " b 4f \n"
6185 + " .set noreorder \n"
6186 + "3: b 5f \n"
6187 + " move %0, %1 \n"
6188 + " .set reorder \n"
6189 + _ASM_EXTABLE(2b, 3b)
6190 +#endif
6191 + "4: daddu %0, %1, %3 \n"
6192 +#ifdef CONFIG_PAX_REFCOUNT
6193 + "5: \n"
6194 +#endif
6195 + " .set mips0 \n"
6196 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6197 + : "Ir" (i));
6198 + } else if (kernel_uses_llsc) {
6199 + __asm__ __volatile__(
6200 + " .set mips3 \n"
6201 + "1: lld %1, %2 # atomic64_add_return \n"
6202 +#ifdef CONFIG_PAX_REFCOUNT
6203 + "2: dadd %0, %1, %3 \n"
6204 +#else
6205 + " daddu %0, %1, %3 \n"
6206 +#endif
6207 + " scd %0, %2 \n"
6208 + " bnez %0, 4f \n"
6209 + " b 1b \n"
6210 +#ifdef CONFIG_PAX_REFCOUNT
6211 + " .set noreorder \n"
6212 + "3: b 5f \n"
6213 + " move %0, %1 \n"
6214 + " .set reorder \n"
6215 + _ASM_EXTABLE(2b, 3b)
6216 +#endif
6217 + "4: daddu %0, %1, %3 \n"
6218 +#ifdef CONFIG_PAX_REFCOUNT
6219 + "5: \n"
6220 +#endif
6221 + " .set mips0 \n"
6222 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6223 + : "Ir" (i), "m" (v->counter)
6224 + : "memory");
6225 + } else {
6226 + unsigned long flags;
6227 +
6228 + raw_local_irq_save(flags);
6229 + __asm__ __volatile__(
6230 + " ld %0, %1 \n"
6231 +#ifdef CONFIG_PAX_REFCOUNT
6232 + /* Exception on overflow. */
6233 + "1: dadd %0, %2 \n"
6234 +#else
6235 + " daddu %0, %2 \n"
6236 +#endif
6237 + " sd %0, %1 \n"
6238 +#ifdef CONFIG_PAX_REFCOUNT
6239 + /* Note: Dest reg is not modified on overflow */
6240 + "2: \n"
6241 + _ASM_EXTABLE(1b, 2b)
6242 +#endif
6243 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6244 + raw_local_irq_restore(flags);
6245 + }
6246 +
6247 + smp_llsc_mb();
6248 +
6249 + return result;
6250 +}
6251 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6252 {
6253 long result;
6254
6255 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6256 return result;
6257 }
6258
6259 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6260 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6261 +{
6262 + long result;
6263 + long temp;
6264 +
6265 + smp_mb__before_llsc();
6266 +
6267 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6268 + long temp;
6269 +
6270 + __asm__ __volatile__(
6271 + " .set mips3 \n"
6272 + "1: lld %1, %2 # atomic64_sub_return \n"
6273 +#ifdef CONFIG_PAX_REFCOUNT
6274 + "2: dsub %0, %1, %3 \n"
6275 +#else
6276 + " dsubu %0, %1, %3 \n"
6277 +#endif
6278 + " scd %0, %2 \n"
6279 + " beqzl %0, 1b \n"
6280 +#ifdef CONFIG_PAX_REFCOUNT
6281 + " b 4f \n"
6282 + " .set noreorder \n"
6283 + "3: b 5f \n"
6284 + " move %0, %1 \n"
6285 + " .set reorder \n"
6286 + _ASM_EXTABLE(2b, 3b)
6287 +#endif
6288 + "4: dsubu %0, %1, %3 \n"
6289 +#ifdef CONFIG_PAX_REFCOUNT
6290 + "5: \n"
6291 +#endif
6292 + " .set mips0 \n"
6293 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6294 + : "Ir" (i), "m" (v->counter)
6295 + : "memory");
6296 + } else if (kernel_uses_llsc) {
6297 + __asm__ __volatile__(
6298 + " .set mips3 \n"
6299 + "1: lld %1, %2 # atomic64_sub_return \n"
6300 +#ifdef CONFIG_PAX_REFCOUNT
6301 + "2: dsub %0, %1, %3 \n"
6302 +#else
6303 + " dsubu %0, %1, %3 \n"
6304 +#endif
6305 + " scd %0, %2 \n"
6306 + " bnez %0, 4f \n"
6307 + " b 1b \n"
6308 +#ifdef CONFIG_PAX_REFCOUNT
6309 + " .set noreorder \n"
6310 + "3: b 5f \n"
6311 + " move %0, %1 \n"
6312 + " .set reorder \n"
6313 + _ASM_EXTABLE(2b, 3b)
6314 +#endif
6315 + "4: dsubu %0, %1, %3 \n"
6316 +#ifdef CONFIG_PAX_REFCOUNT
6317 + "5: \n"
6318 +#endif
6319 + " .set mips0 \n"
6320 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6321 + : "Ir" (i), "m" (v->counter)
6322 + : "memory");
6323 + } else {
6324 + unsigned long flags;
6325 +
6326 + raw_local_irq_save(flags);
6327 + __asm__ __volatile__(
6328 + " ld %0, %1 \n"
6329 +#ifdef CONFIG_PAX_REFCOUNT
6330 + /* Exception on overflow. */
6331 + "1: dsub %0, %2 \n"
6332 +#else
6333 + " dsubu %0, %2 \n"
6334 +#endif
6335 + " sd %0, %1 \n"
6336 +#ifdef CONFIG_PAX_REFCOUNT
6337 + /* Note: Dest reg is not modified on overflow */
6338 + "2: \n"
6339 + _ASM_EXTABLE(1b, 2b)
6340 +#endif
6341 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6342 + raw_local_irq_restore(flags);
6343 + }
6344 +
6345 + smp_llsc_mb();
6346 +
6347 + return result;
6348 +}
6349 +
6350 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6351 {
6352 long result;
6353
6354 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6355 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6356 * The function returns the old value of @v minus @i.
6357 */
6358 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6359 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6360 {
6361 long result;
6362
6363 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6364 return result;
6365 }
6366
6367 -#define atomic64_cmpxchg(v, o, n) \
6368 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6369 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6370 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6371 +{
6372 + return cmpxchg(&v->counter, old, new);
6373 +}
6374 +
6375 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6376 + long new)
6377 +{
6378 + return cmpxchg(&(v->counter), old, new);
6379 +}
6380 +
6381 +static inline long atomic64_xchg(atomic64_t *v, long new)
6382 +{
6383 + return xchg(&v->counter, new);
6384 +}
6385 +
6386 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6387 +{
6388 + return xchg(&(v->counter), new);
6389 +}
6390
6391 /**
6392 * atomic64_add_unless - add unless the number is a given value
6393 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6394
6395 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6396 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6397 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6398
6399 /*
6400 * atomic64_sub_and_test - subtract value from variable and test result
6401 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6402 * other cases.
6403 */
6404 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6405 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6406
6407 /*
6408 * atomic64_dec_and_test - decrement by 1 and test
6409 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6410 * Atomically increments @v by 1.
6411 */
6412 #define atomic64_inc(v) atomic64_add(1, (v))
6413 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6414
6415 /*
6416 * atomic64_dec - decrement and test
6417 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6418 * Atomically decrements @v by 1.
6419 */
6420 #define atomic64_dec(v) atomic64_sub(1, (v))
6421 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6422
6423 /*
6424 * atomic64_add_negative - add and test if negative
6425 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6426 index b4db69f..8f3b093 100644
6427 --- a/arch/mips/include/asm/cache.h
6428 +++ b/arch/mips/include/asm/cache.h
6429 @@ -9,10 +9,11 @@
6430 #ifndef _ASM_CACHE_H
6431 #define _ASM_CACHE_H
6432
6433 +#include <linux/const.h>
6434 #include <kmalloc.h>
6435
6436 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6437 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6438 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6439
6440 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6441 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6442 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6443 index d414405..6bb4ba2 100644
6444 --- a/arch/mips/include/asm/elf.h
6445 +++ b/arch/mips/include/asm/elf.h
6446 @@ -398,13 +398,16 @@ extern const char *__elf_platform;
6447 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6448 #endif
6449
6450 +#ifdef CONFIG_PAX_ASLR
6451 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6452 +
6453 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6454 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6455 +#endif
6456 +
6457 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6458 struct linux_binprm;
6459 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6460 int uses_interp);
6461
6462 -struct mm_struct;
6463 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6464 -#define arch_randomize_brk arch_randomize_brk
6465 -
6466 #endif /* _ASM_ELF_H */
6467 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6468 index c1f6afa..38cc6e9 100644
6469 --- a/arch/mips/include/asm/exec.h
6470 +++ b/arch/mips/include/asm/exec.h
6471 @@ -12,6 +12,6 @@
6472 #ifndef _ASM_EXEC_H
6473 #define _ASM_EXEC_H
6474
6475 -extern unsigned long arch_align_stack(unsigned long sp);
6476 +#define arch_align_stack(x) ((x) & ~0xfUL)
6477
6478 #endif /* _ASM_EXEC_H */
6479 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6480 index 9e8ef59..1139d6b 100644
6481 --- a/arch/mips/include/asm/hw_irq.h
6482 +++ b/arch/mips/include/asm/hw_irq.h
6483 @@ -10,7 +10,7 @@
6484
6485 #include <linux/atomic.h>
6486
6487 -extern atomic_t irq_err_count;
6488 +extern atomic_unchecked_t irq_err_count;
6489
6490 /*
6491 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6492 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6493 index d44622c..64990d2 100644
6494 --- a/arch/mips/include/asm/local.h
6495 +++ b/arch/mips/include/asm/local.h
6496 @@ -12,15 +12,25 @@ typedef struct
6497 atomic_long_t a;
6498 } local_t;
6499
6500 +typedef struct {
6501 + atomic_long_unchecked_t a;
6502 +} local_unchecked_t;
6503 +
6504 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6505
6506 #define local_read(l) atomic_long_read(&(l)->a)
6507 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6508 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6509 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6510
6511 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6512 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6513 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6514 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6515 #define local_inc(l) atomic_long_inc(&(l)->a)
6516 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6517 #define local_dec(l) atomic_long_dec(&(l)->a)
6518 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6519
6520 /*
6521 * Same as above, but return the result value
6522 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6523 return result;
6524 }
6525
6526 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6527 +{
6528 + unsigned long result;
6529 +
6530 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6531 + unsigned long temp;
6532 +
6533 + __asm__ __volatile__(
6534 + " .set mips3 \n"
6535 + "1:" __LL "%1, %2 # local_add_return \n"
6536 + " addu %0, %1, %3 \n"
6537 + __SC "%0, %2 \n"
6538 + " beqzl %0, 1b \n"
6539 + " addu %0, %1, %3 \n"
6540 + " .set mips0 \n"
6541 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6542 + : "Ir" (i), "m" (l->a.counter)
6543 + : "memory");
6544 + } else if (kernel_uses_llsc) {
6545 + unsigned long temp;
6546 +
6547 + __asm__ __volatile__(
6548 + " .set mips3 \n"
6549 + "1:" __LL "%1, %2 # local_add_return \n"
6550 + " addu %0, %1, %3 \n"
6551 + __SC "%0, %2 \n"
6552 + " beqz %0, 1b \n"
6553 + " addu %0, %1, %3 \n"
6554 + " .set mips0 \n"
6555 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6556 + : "Ir" (i), "m" (l->a.counter)
6557 + : "memory");
6558 + } else {
6559 + unsigned long flags;
6560 +
6561 + local_irq_save(flags);
6562 + result = l->a.counter;
6563 + result += i;
6564 + l->a.counter = result;
6565 + local_irq_restore(flags);
6566 + }
6567 +
6568 + return result;
6569 +}
6570 +
6571 static __inline__ long local_sub_return(long i, local_t * l)
6572 {
6573 unsigned long result;
6574 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6575
6576 #define local_cmpxchg(l, o, n) \
6577 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6578 +#define local_cmpxchg_unchecked(l, o, n) \
6579 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6580 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6581
6582 /**
6583 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6584 index 5e08bcc..cfedefc 100644
6585 --- a/arch/mips/include/asm/page.h
6586 +++ b/arch/mips/include/asm/page.h
6587 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6588 #ifdef CONFIG_CPU_MIPS32
6589 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6590 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6591 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6592 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6593 #else
6594 typedef struct { unsigned long long pte; } pte_t;
6595 #define pte_val(x) ((x).pte)
6596 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6597 index b336037..5b874cc 100644
6598 --- a/arch/mips/include/asm/pgalloc.h
6599 +++ b/arch/mips/include/asm/pgalloc.h
6600 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6601 {
6602 set_pud(pud, __pud((unsigned long)pmd));
6603 }
6604 +
6605 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6606 +{
6607 + pud_populate(mm, pud, pmd);
6608 +}
6609 #endif
6610
6611 /*
6612 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6613 index 008324d..f67c239 100644
6614 --- a/arch/mips/include/asm/pgtable.h
6615 +++ b/arch/mips/include/asm/pgtable.h
6616 @@ -20,6 +20,9 @@
6617 #include <asm/io.h>
6618 #include <asm/pgtable-bits.h>
6619
6620 +#define ktla_ktva(addr) (addr)
6621 +#define ktva_ktla(addr) (addr)
6622 +
6623 struct mm_struct;
6624 struct vm_area_struct;
6625
6626 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6627 index 25da651..ae2a259 100644
6628 --- a/arch/mips/include/asm/smtc_proc.h
6629 +++ b/arch/mips/include/asm/smtc_proc.h
6630 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6631
6632 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6633
6634 -extern atomic_t smtc_fpu_recoveries;
6635 +extern atomic_unchecked_t smtc_fpu_recoveries;
6636
6637 #endif /* __ASM_SMTC_PROC_H */
6638 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6639 index 24846f9..61c49f0 100644
6640 --- a/arch/mips/include/asm/thread_info.h
6641 +++ b/arch/mips/include/asm/thread_info.h
6642 @@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6643 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6644 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6645 #define TIF_32BIT_FPREGS 27 /* 32-bit floating point registers */
6646 +/* li takes a 32bit immediate */
6647 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6648 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6649
6650 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6651 @@ -134,13 +136,14 @@ static inline struct thread_info *current_thread_info(void)
6652 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6653 #define _TIF_32BIT_FPREGS (1<<TIF_32BIT_FPREGS)
6654 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6655 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6656
6657 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6658 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6659 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6660
6661 /* work to do in syscall_trace_leave() */
6662 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6663 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6664 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6665
6666 /* work to do on interrupt/exception return */
6667 #define _TIF_WORK_MASK \
6668 @@ -148,7 +151,7 @@ static inline struct thread_info *current_thread_info(void)
6669 /* work to do on any return to u-space */
6670 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6671 _TIF_WORK_SYSCALL_EXIT | \
6672 - _TIF_SYSCALL_TRACEPOINT)
6673 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6674
6675 /*
6676 * We stash processor id into a COP0 register to retrieve it fast
6677 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6678 index f3fa375..3af6637 100644
6679 --- a/arch/mips/include/asm/uaccess.h
6680 +++ b/arch/mips/include/asm/uaccess.h
6681 @@ -128,6 +128,7 @@ extern u64 __ua_limit;
6682 __ok == 0; \
6683 })
6684
6685 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6686 #define access_ok(type, addr, size) \
6687 likely(__access_ok((addr), (size), __access_mask))
6688
6689 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6690 index 1188e00..41cf144 100644
6691 --- a/arch/mips/kernel/binfmt_elfn32.c
6692 +++ b/arch/mips/kernel/binfmt_elfn32.c
6693 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6694 #undef ELF_ET_DYN_BASE
6695 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6696
6697 +#ifdef CONFIG_PAX_ASLR
6698 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6699 +
6700 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6701 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6702 +#endif
6703 +
6704 #include <asm/processor.h>
6705 #include <linux/module.h>
6706 #include <linux/elfcore.h>
6707 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6708 index 7faf5f2..f3d3cf4 100644
6709 --- a/arch/mips/kernel/binfmt_elfo32.c
6710 +++ b/arch/mips/kernel/binfmt_elfo32.c
6711 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6712 #undef ELF_ET_DYN_BASE
6713 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6714
6715 +#ifdef CONFIG_PAX_ASLR
6716 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6717 +
6718 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6719 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6720 +#endif
6721 +
6722 #include <asm/processor.h>
6723
6724 /*
6725 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6726 index 2b91fe8..fe4f6b4 100644
6727 --- a/arch/mips/kernel/i8259.c
6728 +++ b/arch/mips/kernel/i8259.c
6729 @@ -205,7 +205,7 @@ spurious_8259A_irq:
6730 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6731 spurious_irq_mask |= irqmask;
6732 }
6733 - atomic_inc(&irq_err_count);
6734 + atomic_inc_unchecked(&irq_err_count);
6735 /*
6736 * Theoretically we do not have to handle this IRQ,
6737 * but in Linux this does not cause problems and is
6738 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6739 index 44a1f79..2bd6aa3 100644
6740 --- a/arch/mips/kernel/irq-gt641xx.c
6741 +++ b/arch/mips/kernel/irq-gt641xx.c
6742 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6743 }
6744 }
6745
6746 - atomic_inc(&irq_err_count);
6747 + atomic_inc_unchecked(&irq_err_count);
6748 }
6749
6750 void __init gt641xx_irq_init(void)
6751 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6752 index d1fea7a..45602ea 100644
6753 --- a/arch/mips/kernel/irq.c
6754 +++ b/arch/mips/kernel/irq.c
6755 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6756 printk("unexpected IRQ # %d\n", irq);
6757 }
6758
6759 -atomic_t irq_err_count;
6760 +atomic_unchecked_t irq_err_count;
6761
6762 int arch_show_interrupts(struct seq_file *p, int prec)
6763 {
6764 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6765 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6766 return 0;
6767 }
6768
6769 asmlinkage void spurious_interrupt(void)
6770 {
6771 - atomic_inc(&irq_err_count);
6772 + atomic_inc_unchecked(&irq_err_count);
6773 }
6774
6775 void __init init_IRQ(void)
6776 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6777 index 6ae540e..b7396dc 100644
6778 --- a/arch/mips/kernel/process.c
6779 +++ b/arch/mips/kernel/process.c
6780 @@ -562,15 +562,3 @@ unsigned long get_wchan(struct task_struct *task)
6781 out:
6782 return pc;
6783 }
6784 -
6785 -/*
6786 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6787 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6788 - */
6789 -unsigned long arch_align_stack(unsigned long sp)
6790 -{
6791 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6792 - sp -= get_random_int() & ~PAGE_MASK;
6793 -
6794 - return sp & ALMASK;
6795 -}
6796 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6797 index 7da9b76..21578be 100644
6798 --- a/arch/mips/kernel/ptrace.c
6799 +++ b/arch/mips/kernel/ptrace.c
6800 @@ -658,6 +658,10 @@ long arch_ptrace(struct task_struct *child, long request,
6801 return ret;
6802 }
6803
6804 +#ifdef CONFIG_GRKERNSEC_SETXID
6805 +extern void gr_delayed_cred_worker(void);
6806 +#endif
6807 +
6808 /*
6809 * Notification of system call entry/exit
6810 * - triggered by current->work.syscall_trace
6811 @@ -674,6 +678,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6812 tracehook_report_syscall_entry(regs))
6813 ret = -1;
6814
6815 +#ifdef CONFIG_GRKERNSEC_SETXID
6816 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6817 + gr_delayed_cred_worker();
6818 +#endif
6819 +
6820 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6821 trace_sys_enter(regs, regs->regs[2]);
6822
6823 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6824 index 07fc524..b9d7f28 100644
6825 --- a/arch/mips/kernel/reset.c
6826 +++ b/arch/mips/kernel/reset.c
6827 @@ -13,6 +13,7 @@
6828 #include <linux/reboot.h>
6829
6830 #include <asm/reboot.h>
6831 +#include <asm/bug.h>
6832
6833 /*
6834 * Urgs ... Too many MIPS machines to handle this in a generic way.
6835 @@ -29,16 +30,19 @@ void machine_restart(char *command)
6836 {
6837 if (_machine_restart)
6838 _machine_restart(command);
6839 + BUG();
6840 }
6841
6842 void machine_halt(void)
6843 {
6844 if (_machine_halt)
6845 _machine_halt();
6846 + BUG();
6847 }
6848
6849 void machine_power_off(void)
6850 {
6851 if (pm_power_off)
6852 pm_power_off();
6853 + BUG();
6854 }
6855 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6856 index c10aa84..9ec2e60 100644
6857 --- a/arch/mips/kernel/smtc-proc.c
6858 +++ b/arch/mips/kernel/smtc-proc.c
6859 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6860
6861 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6862
6863 -atomic_t smtc_fpu_recoveries;
6864 +atomic_unchecked_t smtc_fpu_recoveries;
6865
6866 static int smtc_proc_show(struct seq_file *m, void *v)
6867 {
6868 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6869 for(i = 0; i < NR_CPUS; i++)
6870 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6871 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6872 - atomic_read(&smtc_fpu_recoveries));
6873 + atomic_read_unchecked(&smtc_fpu_recoveries));
6874 return 0;
6875 }
6876
6877 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
6878 smtc_cpu_stats[i].selfipis = 0;
6879 }
6880
6881 - atomic_set(&smtc_fpu_recoveries, 0);
6882 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6883
6884 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6885 }
6886 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6887 index dfc1b91..11a2c07 100644
6888 --- a/arch/mips/kernel/smtc.c
6889 +++ b/arch/mips/kernel/smtc.c
6890 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6891 }
6892 smtc_ipi_qdump();
6893 printk("%d Recoveries of \"stolen\" FPU\n",
6894 - atomic_read(&smtc_fpu_recoveries));
6895 + atomic_read_unchecked(&smtc_fpu_recoveries));
6896 }
6897
6898
6899 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6900 index c24ad5f..9983ab2 100644
6901 --- a/arch/mips/kernel/sync-r4k.c
6902 +++ b/arch/mips/kernel/sync-r4k.c
6903 @@ -20,8 +20,8 @@
6904 #include <asm/mipsregs.h>
6905
6906 static atomic_t count_start_flag = ATOMIC_INIT(0);
6907 -static atomic_t count_count_start = ATOMIC_INIT(0);
6908 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6909 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6910 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6911 static atomic_t count_reference = ATOMIC_INIT(0);
6912
6913 #define COUNTON 100
6914 @@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
6915
6916 for (i = 0; i < NR_LOOPS; i++) {
6917 /* slaves loop on '!= 2' */
6918 - while (atomic_read(&count_count_start) != 1)
6919 + while (atomic_read_unchecked(&count_count_start) != 1)
6920 mb();
6921 - atomic_set(&count_count_stop, 0);
6922 + atomic_set_unchecked(&count_count_stop, 0);
6923 smp_wmb();
6924
6925 /* this lets the slaves write their count register */
6926 - atomic_inc(&count_count_start);
6927 + atomic_inc_unchecked(&count_count_start);
6928
6929 /*
6930 * Everyone initialises count in the last loop:
6931 @@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
6932 /*
6933 * Wait for all slaves to leave the synchronization point:
6934 */
6935 - while (atomic_read(&count_count_stop) != 1)
6936 + while (atomic_read_unchecked(&count_count_stop) != 1)
6937 mb();
6938 - atomic_set(&count_count_start, 0);
6939 + atomic_set_unchecked(&count_count_start, 0);
6940 smp_wmb();
6941 - atomic_inc(&count_count_stop);
6942 + atomic_inc_unchecked(&count_count_stop);
6943 }
6944 /* Arrange for an interrupt in a short while */
6945 write_c0_compare(read_c0_count() + COUNTON);
6946 @@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
6947 initcount = atomic_read(&count_reference);
6948
6949 for (i = 0; i < NR_LOOPS; i++) {
6950 - atomic_inc(&count_count_start);
6951 - while (atomic_read(&count_count_start) != 2)
6952 + atomic_inc_unchecked(&count_count_start);
6953 + while (atomic_read_unchecked(&count_count_start) != 2)
6954 mb();
6955
6956 /*
6957 @@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
6958 if (i == NR_LOOPS-1)
6959 write_c0_count(initcount);
6960
6961 - atomic_inc(&count_count_stop);
6962 - while (atomic_read(&count_count_stop) != 2)
6963 + atomic_inc_unchecked(&count_count_stop);
6964 + while (atomic_read_unchecked(&count_count_stop) != 2)
6965 mb();
6966 }
6967 /* Arrange for an interrupt in a short while */
6968 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6969 index e0b4996..6b43ce7 100644
6970 --- a/arch/mips/kernel/traps.c
6971 +++ b/arch/mips/kernel/traps.c
6972 @@ -691,7 +691,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6973 siginfo_t info;
6974
6975 prev_state = exception_enter();
6976 - die_if_kernel("Integer overflow", regs);
6977 + if (unlikely(!user_mode(regs))) {
6978 +
6979 +#ifdef CONFIG_PAX_REFCOUNT
6980 + if (fixup_exception(regs)) {
6981 + pax_report_refcount_overflow(regs);
6982 + exception_exit(prev_state);
6983 + return;
6984 + }
6985 +#endif
6986 +
6987 + die("Integer overflow", regs);
6988 + }
6989
6990 info.si_code = FPE_INTOVF;
6991 info.si_signo = SIGFPE;
6992 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6993 index becc42b..9e43d4b 100644
6994 --- a/arch/mips/mm/fault.c
6995 +++ b/arch/mips/mm/fault.c
6996 @@ -28,6 +28,23 @@
6997 #include <asm/highmem.h> /* For VMALLOC_END */
6998 #include <linux/kdebug.h>
6999
7000 +#ifdef CONFIG_PAX_PAGEEXEC
7001 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7002 +{
7003 + unsigned long i;
7004 +
7005 + printk(KERN_ERR "PAX: bytes at PC: ");
7006 + for (i = 0; i < 5; i++) {
7007 + unsigned int c;
7008 + if (get_user(c, (unsigned int *)pc+i))
7009 + printk(KERN_CONT "???????? ");
7010 + else
7011 + printk(KERN_CONT "%08x ", c);
7012 + }
7013 + printk("\n");
7014 +}
7015 +#endif
7016 +
7017 /*
7018 * This routine handles page faults. It determines the address,
7019 * and the problem, and then passes it off to one of the appropriate
7020 @@ -199,6 +216,14 @@ bad_area:
7021 bad_area_nosemaphore:
7022 /* User mode accesses just cause a SIGSEGV */
7023 if (user_mode(regs)) {
7024 +
7025 +#ifdef CONFIG_PAX_PAGEEXEC
7026 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7027 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7028 + do_group_exit(SIGKILL);
7029 + }
7030 +#endif
7031 +
7032 tsk->thread.cp0_badvaddr = address;
7033 tsk->thread.error_code = write;
7034 #if 0
7035 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7036 index f1baadd..5472dca 100644
7037 --- a/arch/mips/mm/mmap.c
7038 +++ b/arch/mips/mm/mmap.c
7039 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7040 struct vm_area_struct *vma;
7041 unsigned long addr = addr0;
7042 int do_color_align;
7043 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7044 struct vm_unmapped_area_info info;
7045
7046 if (unlikely(len > TASK_SIZE))
7047 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7048 do_color_align = 1;
7049
7050 /* requesting a specific address */
7051 +
7052 +#ifdef CONFIG_PAX_RANDMMAP
7053 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7054 +#endif
7055 +
7056 if (addr) {
7057 if (do_color_align)
7058 addr = COLOUR_ALIGN(addr, pgoff);
7059 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7060 addr = PAGE_ALIGN(addr);
7061
7062 vma = find_vma(mm, addr);
7063 - if (TASK_SIZE - len >= addr &&
7064 - (!vma || addr + len <= vma->vm_start))
7065 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7066 return addr;
7067 }
7068
7069 info.length = len;
7070 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7071 info.align_offset = pgoff << PAGE_SHIFT;
7072 + info.threadstack_offset = offset;
7073
7074 if (dir == DOWN) {
7075 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7076 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7077 {
7078 unsigned long random_factor = 0UL;
7079
7080 +#ifdef CONFIG_PAX_RANDMMAP
7081 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7082 +#endif
7083 +
7084 if (current->flags & PF_RANDOMIZE) {
7085 random_factor = get_random_int();
7086 random_factor = random_factor << PAGE_SHIFT;
7087 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7088
7089 if (mmap_is_legacy()) {
7090 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7091 +
7092 +#ifdef CONFIG_PAX_RANDMMAP
7093 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7094 + mm->mmap_base += mm->delta_mmap;
7095 +#endif
7096 +
7097 mm->get_unmapped_area = arch_get_unmapped_area;
7098 } else {
7099 mm->mmap_base = mmap_base(random_factor);
7100 +
7101 +#ifdef CONFIG_PAX_RANDMMAP
7102 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7103 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7104 +#endif
7105 +
7106 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7107 }
7108 }
7109
7110 -static inline unsigned long brk_rnd(void)
7111 -{
7112 - unsigned long rnd = get_random_int();
7113 -
7114 - rnd = rnd << PAGE_SHIFT;
7115 - /* 8MB for 32bit, 256MB for 64bit */
7116 - if (TASK_IS_32BIT_ADDR)
7117 - rnd = rnd & 0x7ffffful;
7118 - else
7119 - rnd = rnd & 0xffffffful;
7120 -
7121 - return rnd;
7122 -}
7123 -
7124 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7125 -{
7126 - unsigned long base = mm->brk;
7127 - unsigned long ret;
7128 -
7129 - ret = PAGE_ALIGN(base + brk_rnd());
7130 -
7131 - if (ret < mm->brk)
7132 - return mm->brk;
7133 -
7134 - return ret;
7135 -}
7136 -
7137 int __virt_addr_valid(const volatile void *kaddr)
7138 {
7139 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7140 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7141 index 59cccd9..f39ac2f 100644
7142 --- a/arch/mips/pci/pci-octeon.c
7143 +++ b/arch/mips/pci/pci-octeon.c
7144 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7145
7146
7147 static struct pci_ops octeon_pci_ops = {
7148 - octeon_read_config,
7149 - octeon_write_config,
7150 + .read = octeon_read_config,
7151 + .write = octeon_write_config,
7152 };
7153
7154 static struct resource octeon_pci_mem_resource = {
7155 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7156 index 5e36c33..eb4a17b 100644
7157 --- a/arch/mips/pci/pcie-octeon.c
7158 +++ b/arch/mips/pci/pcie-octeon.c
7159 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7160 }
7161
7162 static struct pci_ops octeon_pcie0_ops = {
7163 - octeon_pcie0_read_config,
7164 - octeon_pcie0_write_config,
7165 + .read = octeon_pcie0_read_config,
7166 + .write = octeon_pcie0_write_config,
7167 };
7168
7169 static struct resource octeon_pcie0_mem_resource = {
7170 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7171 };
7172
7173 static struct pci_ops octeon_pcie1_ops = {
7174 - octeon_pcie1_read_config,
7175 - octeon_pcie1_write_config,
7176 + .read = octeon_pcie1_read_config,
7177 + .write = octeon_pcie1_write_config,
7178 };
7179
7180 static struct resource octeon_pcie1_mem_resource = {
7181 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7182 };
7183
7184 static struct pci_ops octeon_dummy_ops = {
7185 - octeon_dummy_read_config,
7186 - octeon_dummy_write_config,
7187 + .read = octeon_dummy_read_config,
7188 + .write = octeon_dummy_write_config,
7189 };
7190
7191 static struct resource octeon_dummy_mem_resource = {
7192 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7193 index a2358b4..7cead4f 100644
7194 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7195 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7196 @@ -187,9 +187,9 @@ void
7197 cont_nmi_dump(void)
7198 {
7199 #ifndef REAL_NMI_SIGNAL
7200 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7201 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7202
7203 - atomic_inc(&nmied_cpus);
7204 + atomic_inc_unchecked(&nmied_cpus);
7205 #endif
7206 /*
7207 * Only allow 1 cpu to proceed
7208 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7209 udelay(10000);
7210 }
7211 #else
7212 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7213 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7214 #endif
7215
7216 /*
7217 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7218 index a046b30..6799527 100644
7219 --- a/arch/mips/sni/rm200.c
7220 +++ b/arch/mips/sni/rm200.c
7221 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7222 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7223 spurious_irq_mask |= irqmask;
7224 }
7225 - atomic_inc(&irq_err_count);
7226 + atomic_inc_unchecked(&irq_err_count);
7227 /*
7228 * Theoretically we do not have to handle this IRQ,
7229 * but in Linux this does not cause problems and is
7230 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7231 index 41e873b..34d33a7 100644
7232 --- a/arch/mips/vr41xx/common/icu.c
7233 +++ b/arch/mips/vr41xx/common/icu.c
7234 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7235
7236 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7237
7238 - atomic_inc(&irq_err_count);
7239 + atomic_inc_unchecked(&irq_err_count);
7240
7241 return -1;
7242 }
7243 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7244 index ae0e4ee..e8f0692 100644
7245 --- a/arch/mips/vr41xx/common/irq.c
7246 +++ b/arch/mips/vr41xx/common/irq.c
7247 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7248 irq_cascade_t *cascade;
7249
7250 if (irq >= NR_IRQS) {
7251 - atomic_inc(&irq_err_count);
7252 + atomic_inc_unchecked(&irq_err_count);
7253 return;
7254 }
7255
7256 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7257 ret = cascade->get_irq(irq);
7258 irq = ret;
7259 if (ret < 0)
7260 - atomic_inc(&irq_err_count);
7261 + atomic_inc_unchecked(&irq_err_count);
7262 else
7263 irq_dispatch(irq);
7264 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7265 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7266 index 967d144..db12197 100644
7267 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7268 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7269 @@ -11,12 +11,14 @@
7270 #ifndef _ASM_PROC_CACHE_H
7271 #define _ASM_PROC_CACHE_H
7272
7273 +#include <linux/const.h>
7274 +
7275 /* L1 cache */
7276
7277 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7278 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7279 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7280 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7281 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7282 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7283
7284 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7285 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7286 index bcb5df2..84fabd2 100644
7287 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7288 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7289 @@ -16,13 +16,15 @@
7290 #ifndef _ASM_PROC_CACHE_H
7291 #define _ASM_PROC_CACHE_H
7292
7293 +#include <linux/const.h>
7294 +
7295 /*
7296 * L1 cache
7297 */
7298 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7299 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7300 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7301 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7302 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7303 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7304
7305 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7306 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7307 index 4ce7a01..449202a 100644
7308 --- a/arch/openrisc/include/asm/cache.h
7309 +++ b/arch/openrisc/include/asm/cache.h
7310 @@ -19,11 +19,13 @@
7311 #ifndef __ASM_OPENRISC_CACHE_H
7312 #define __ASM_OPENRISC_CACHE_H
7313
7314 +#include <linux/const.h>
7315 +
7316 /* FIXME: How can we replace these with values from the CPU...
7317 * they shouldn't be hard-coded!
7318 */
7319
7320 -#define L1_CACHE_BYTES 16
7321 #define L1_CACHE_SHIFT 4
7322 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7323
7324 #endif /* __ASM_OPENRISC_CACHE_H */
7325 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7326 index 472886c..00e7df9 100644
7327 --- a/arch/parisc/include/asm/atomic.h
7328 +++ b/arch/parisc/include/asm/atomic.h
7329 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7330 return dec;
7331 }
7332
7333 +#define atomic64_read_unchecked(v) atomic64_read(v)
7334 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7335 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7336 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7337 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7338 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7339 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7340 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7341 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7342 +
7343 #endif /* !CONFIG_64BIT */
7344
7345
7346 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7347 index 47f11c7..3420df2 100644
7348 --- a/arch/parisc/include/asm/cache.h
7349 +++ b/arch/parisc/include/asm/cache.h
7350 @@ -5,6 +5,7 @@
7351 #ifndef __ARCH_PARISC_CACHE_H
7352 #define __ARCH_PARISC_CACHE_H
7353
7354 +#include <linux/const.h>
7355
7356 /*
7357 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7358 @@ -15,13 +16,13 @@
7359 * just ruin performance.
7360 */
7361 #ifdef CONFIG_PA20
7362 -#define L1_CACHE_BYTES 64
7363 #define L1_CACHE_SHIFT 6
7364 #else
7365 -#define L1_CACHE_BYTES 32
7366 #define L1_CACHE_SHIFT 5
7367 #endif
7368
7369 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7370 +
7371 #ifndef __ASSEMBLY__
7372
7373 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7374 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7375 index 3391d06..c23a2cc 100644
7376 --- a/arch/parisc/include/asm/elf.h
7377 +++ b/arch/parisc/include/asm/elf.h
7378 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7379
7380 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7381
7382 +#ifdef CONFIG_PAX_ASLR
7383 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7384 +
7385 +#define PAX_DELTA_MMAP_LEN 16
7386 +#define PAX_DELTA_STACK_LEN 16
7387 +#endif
7388 +
7389 /* This yields a mask that user programs can use to figure out what
7390 instruction set this CPU supports. This could be done in user space,
7391 but it's not easy, and we've already done it here. */
7392 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7393 index f213f5b..0af3e8e 100644
7394 --- a/arch/parisc/include/asm/pgalloc.h
7395 +++ b/arch/parisc/include/asm/pgalloc.h
7396 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7397 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7398 }
7399
7400 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7401 +{
7402 + pgd_populate(mm, pgd, pmd);
7403 +}
7404 +
7405 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7406 {
7407 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7408 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7409 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7410 #define pmd_free(mm, x) do { } while (0)
7411 #define pgd_populate(mm, pmd, pte) BUG()
7412 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7413
7414 #endif
7415
7416 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7417 index 22b89d1..ce34230 100644
7418 --- a/arch/parisc/include/asm/pgtable.h
7419 +++ b/arch/parisc/include/asm/pgtable.h
7420 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7421 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7422 #define PAGE_COPY PAGE_EXECREAD
7423 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7424 +
7425 +#ifdef CONFIG_PAX_PAGEEXEC
7426 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7427 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7428 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7429 +#else
7430 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7431 +# define PAGE_COPY_NOEXEC PAGE_COPY
7432 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7433 +#endif
7434 +
7435 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7436 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7437 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7438 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7439 index 4006964..fcb3cc2 100644
7440 --- a/arch/parisc/include/asm/uaccess.h
7441 +++ b/arch/parisc/include/asm/uaccess.h
7442 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7443 const void __user *from,
7444 unsigned long n)
7445 {
7446 - int sz = __compiletime_object_size(to);
7447 + size_t sz = __compiletime_object_size(to);
7448 int ret = -EFAULT;
7449
7450 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7451 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7452 ret = __copy_from_user(to, from, n);
7453 else
7454 copy_from_user_overflow();
7455 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7456 index 50dfafc..b9fc230 100644
7457 --- a/arch/parisc/kernel/module.c
7458 +++ b/arch/parisc/kernel/module.c
7459 @@ -98,16 +98,38 @@
7460
7461 /* three functions to determine where in the module core
7462 * or init pieces the location is */
7463 +static inline int in_init_rx(struct module *me, void *loc)
7464 +{
7465 + return (loc >= me->module_init_rx &&
7466 + loc < (me->module_init_rx + me->init_size_rx));
7467 +}
7468 +
7469 +static inline int in_init_rw(struct module *me, void *loc)
7470 +{
7471 + return (loc >= me->module_init_rw &&
7472 + loc < (me->module_init_rw + me->init_size_rw));
7473 +}
7474 +
7475 static inline int in_init(struct module *me, void *loc)
7476 {
7477 - return (loc >= me->module_init &&
7478 - loc <= (me->module_init + me->init_size));
7479 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7480 +}
7481 +
7482 +static inline int in_core_rx(struct module *me, void *loc)
7483 +{
7484 + return (loc >= me->module_core_rx &&
7485 + loc < (me->module_core_rx + me->core_size_rx));
7486 +}
7487 +
7488 +static inline int in_core_rw(struct module *me, void *loc)
7489 +{
7490 + return (loc >= me->module_core_rw &&
7491 + loc < (me->module_core_rw + me->core_size_rw));
7492 }
7493
7494 static inline int in_core(struct module *me, void *loc)
7495 {
7496 - return (loc >= me->module_core &&
7497 - loc <= (me->module_core + me->core_size));
7498 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7499 }
7500
7501 static inline int in_local(struct module *me, void *loc)
7502 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7503 }
7504
7505 /* align things a bit */
7506 - me->core_size = ALIGN(me->core_size, 16);
7507 - me->arch.got_offset = me->core_size;
7508 - me->core_size += gots * sizeof(struct got_entry);
7509 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7510 + me->arch.got_offset = me->core_size_rw;
7511 + me->core_size_rw += gots * sizeof(struct got_entry);
7512
7513 - me->core_size = ALIGN(me->core_size, 16);
7514 - me->arch.fdesc_offset = me->core_size;
7515 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7516 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7517 + me->arch.fdesc_offset = me->core_size_rw;
7518 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7519
7520 me->arch.got_max = gots;
7521 me->arch.fdesc_max = fdescs;
7522 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7523
7524 BUG_ON(value == 0);
7525
7526 - got = me->module_core + me->arch.got_offset;
7527 + got = me->module_core_rw + me->arch.got_offset;
7528 for (i = 0; got[i].addr; i++)
7529 if (got[i].addr == value)
7530 goto out;
7531 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7532 #ifdef CONFIG_64BIT
7533 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7534 {
7535 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7536 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7537
7538 if (!value) {
7539 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7540 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7541
7542 /* Create new one */
7543 fdesc->addr = value;
7544 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7545 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7546 return (Elf_Addr)fdesc;
7547 }
7548 #endif /* CONFIG_64BIT */
7549 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7550
7551 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7552 end = table + sechdrs[me->arch.unwind_section].sh_size;
7553 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7554 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7555
7556 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7557 me->arch.unwind_section, table, end, gp);
7558 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7559 index b7cadc4..bf4a32d 100644
7560 --- a/arch/parisc/kernel/sys_parisc.c
7561 +++ b/arch/parisc/kernel/sys_parisc.c
7562 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7563 unsigned long task_size = TASK_SIZE;
7564 int do_color_align, last_mmap;
7565 struct vm_unmapped_area_info info;
7566 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7567
7568 if (len > task_size)
7569 return -ENOMEM;
7570 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7571 goto found_addr;
7572 }
7573
7574 +#ifdef CONFIG_PAX_RANDMMAP
7575 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7576 +#endif
7577 +
7578 if (addr) {
7579 if (do_color_align && last_mmap)
7580 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7581 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7582 info.high_limit = mmap_upper_limit();
7583 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7584 info.align_offset = shared_align_offset(last_mmap, pgoff);
7585 + info.threadstack_offset = offset;
7586 addr = vm_unmapped_area(&info);
7587
7588 found_addr:
7589 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7590 unsigned long addr = addr0;
7591 int do_color_align, last_mmap;
7592 struct vm_unmapped_area_info info;
7593 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7594
7595 #ifdef CONFIG_64BIT
7596 /* This should only ever run for 32-bit processes. */
7597 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7598 }
7599
7600 /* requesting a specific address */
7601 +#ifdef CONFIG_PAX_RANDMMAP
7602 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7603 +#endif
7604 +
7605 if (addr) {
7606 if (do_color_align && last_mmap)
7607 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7608 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7609 info.high_limit = mm->mmap_base;
7610 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7611 info.align_offset = shared_align_offset(last_mmap, pgoff);
7612 + info.threadstack_offset = offset;
7613 addr = vm_unmapped_area(&info);
7614 if (!(addr & ~PAGE_MASK))
7615 goto found_addr;
7616 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7617 mm->mmap_legacy_base = mmap_legacy_base();
7618 mm->mmap_base = mmap_upper_limit();
7619
7620 +#ifdef CONFIG_PAX_RANDMMAP
7621 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7622 + mm->mmap_legacy_base += mm->delta_mmap;
7623 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7624 + }
7625 +#endif
7626 +
7627 if (mmap_is_legacy()) {
7628 mm->mmap_base = mm->mmap_legacy_base;
7629 mm->get_unmapped_area = arch_get_unmapped_area;
7630 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7631 index 1cd1d0c..44ec918 100644
7632 --- a/arch/parisc/kernel/traps.c
7633 +++ b/arch/parisc/kernel/traps.c
7634 @@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7635
7636 down_read(&current->mm->mmap_sem);
7637 vma = find_vma(current->mm,regs->iaoq[0]);
7638 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7639 - && (vma->vm_flags & VM_EXEC)) {
7640 -
7641 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7642 fault_address = regs->iaoq[0];
7643 fault_space = regs->iasq[0];
7644
7645 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7646 index 9d08c71..e2b4d20 100644
7647 --- a/arch/parisc/mm/fault.c
7648 +++ b/arch/parisc/mm/fault.c
7649 @@ -15,6 +15,7 @@
7650 #include <linux/sched.h>
7651 #include <linux/interrupt.h>
7652 #include <linux/module.h>
7653 +#include <linux/unistd.h>
7654
7655 #include <asm/uaccess.h>
7656 #include <asm/traps.h>
7657 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7658 static unsigned long
7659 parisc_acctyp(unsigned long code, unsigned int inst)
7660 {
7661 - if (code == 6 || code == 16)
7662 + if (code == 6 || code == 7 || code == 16)
7663 return VM_EXEC;
7664
7665 switch (inst & 0xf0000000) {
7666 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7667 }
7668 #endif
7669
7670 +#ifdef CONFIG_PAX_PAGEEXEC
7671 +/*
7672 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7673 + *
7674 + * returns 1 when task should be killed
7675 + * 2 when rt_sigreturn trampoline was detected
7676 + * 3 when unpatched PLT trampoline was detected
7677 + */
7678 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7679 +{
7680 +
7681 +#ifdef CONFIG_PAX_EMUPLT
7682 + int err;
7683 +
7684 + do { /* PaX: unpatched PLT emulation */
7685 + unsigned int bl, depwi;
7686 +
7687 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7688 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7689 +
7690 + if (err)
7691 + break;
7692 +
7693 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7694 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7695 +
7696 + err = get_user(ldw, (unsigned int *)addr);
7697 + err |= get_user(bv, (unsigned int *)(addr+4));
7698 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7699 +
7700 + if (err)
7701 + break;
7702 +
7703 + if (ldw == 0x0E801096U &&
7704 + bv == 0xEAC0C000U &&
7705 + ldw2 == 0x0E881095U)
7706 + {
7707 + unsigned int resolver, map;
7708 +
7709 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7710 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7711 + if (err)
7712 + break;
7713 +
7714 + regs->gr[20] = instruction_pointer(regs)+8;
7715 + regs->gr[21] = map;
7716 + regs->gr[22] = resolver;
7717 + regs->iaoq[0] = resolver | 3UL;
7718 + regs->iaoq[1] = regs->iaoq[0] + 4;
7719 + return 3;
7720 + }
7721 + }
7722 + } while (0);
7723 +#endif
7724 +
7725 +#ifdef CONFIG_PAX_EMUTRAMP
7726 +
7727 +#ifndef CONFIG_PAX_EMUSIGRT
7728 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7729 + return 1;
7730 +#endif
7731 +
7732 + do { /* PaX: rt_sigreturn emulation */
7733 + unsigned int ldi1, ldi2, bel, nop;
7734 +
7735 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7736 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7737 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7738 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7739 +
7740 + if (err)
7741 + break;
7742 +
7743 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7744 + ldi2 == 0x3414015AU &&
7745 + bel == 0xE4008200U &&
7746 + nop == 0x08000240U)
7747 + {
7748 + regs->gr[25] = (ldi1 & 2) >> 1;
7749 + regs->gr[20] = __NR_rt_sigreturn;
7750 + regs->gr[31] = regs->iaoq[1] + 16;
7751 + regs->sr[0] = regs->iasq[1];
7752 + regs->iaoq[0] = 0x100UL;
7753 + regs->iaoq[1] = regs->iaoq[0] + 4;
7754 + regs->iasq[0] = regs->sr[2];
7755 + regs->iasq[1] = regs->sr[2];
7756 + return 2;
7757 + }
7758 + } while (0);
7759 +#endif
7760 +
7761 + return 1;
7762 +}
7763 +
7764 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7765 +{
7766 + unsigned long i;
7767 +
7768 + printk(KERN_ERR "PAX: bytes at PC: ");
7769 + for (i = 0; i < 5; i++) {
7770 + unsigned int c;
7771 + if (get_user(c, (unsigned int *)pc+i))
7772 + printk(KERN_CONT "???????? ");
7773 + else
7774 + printk(KERN_CONT "%08x ", c);
7775 + }
7776 + printk("\n");
7777 +}
7778 +#endif
7779 +
7780 int fixup_exception(struct pt_regs *regs)
7781 {
7782 const struct exception_table_entry *fix;
7783 @@ -210,8 +321,33 @@ retry:
7784
7785 good_area:
7786
7787 - if ((vma->vm_flags & acc_type) != acc_type)
7788 + if ((vma->vm_flags & acc_type) != acc_type) {
7789 +
7790 +#ifdef CONFIG_PAX_PAGEEXEC
7791 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7792 + (address & ~3UL) == instruction_pointer(regs))
7793 + {
7794 + up_read(&mm->mmap_sem);
7795 + switch (pax_handle_fetch_fault(regs)) {
7796 +
7797 +#ifdef CONFIG_PAX_EMUPLT
7798 + case 3:
7799 + return;
7800 +#endif
7801 +
7802 +#ifdef CONFIG_PAX_EMUTRAMP
7803 + case 2:
7804 + return;
7805 +#endif
7806 +
7807 + }
7808 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7809 + do_group_exit(SIGKILL);
7810 + }
7811 +#endif
7812 +
7813 goto bad_area;
7814 + }
7815
7816 /*
7817 * If for any reason at all we couldn't handle the fault, make
7818 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7819 index 957bf34..3430cc8 100644
7820 --- a/arch/powerpc/Kconfig
7821 +++ b/arch/powerpc/Kconfig
7822 @@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7823 config KEXEC
7824 bool "kexec system call"
7825 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7826 + depends on !GRKERNSEC_KMEM
7827 help
7828 kexec is a system call that implements the ability to shutdown your
7829 current kernel, and to start another kernel. It is like a reboot
7830 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7831 index e3b1d41..8e81edf 100644
7832 --- a/arch/powerpc/include/asm/atomic.h
7833 +++ b/arch/powerpc/include/asm/atomic.h
7834 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7835 return t1;
7836 }
7837
7838 +#define atomic64_read_unchecked(v) atomic64_read(v)
7839 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7840 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7841 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7842 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7843 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7844 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7845 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7846 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7847 +
7848 #endif /* __powerpc64__ */
7849
7850 #endif /* __KERNEL__ */
7851 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7852 index ed0afc1..0332825 100644
7853 --- a/arch/powerpc/include/asm/cache.h
7854 +++ b/arch/powerpc/include/asm/cache.h
7855 @@ -3,6 +3,7 @@
7856
7857 #ifdef __KERNEL__
7858
7859 +#include <linux/const.h>
7860
7861 /* bytes per L1 cache line */
7862 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7863 @@ -22,7 +23,7 @@
7864 #define L1_CACHE_SHIFT 7
7865 #endif
7866
7867 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7868 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7869
7870 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7871
7872 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7873 index 935b5e7..7001d2d 100644
7874 --- a/arch/powerpc/include/asm/elf.h
7875 +++ b/arch/powerpc/include/asm/elf.h
7876 @@ -28,8 +28,19 @@
7877 the loader. We need to make sure that it is out of the way of the program
7878 that it will "exec", and that there is sufficient room for the brk. */
7879
7880 -extern unsigned long randomize_et_dyn(unsigned long base);
7881 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7882 +#define ELF_ET_DYN_BASE (0x20000000)
7883 +
7884 +#ifdef CONFIG_PAX_ASLR
7885 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7886 +
7887 +#ifdef __powerpc64__
7888 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7889 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7890 +#else
7891 +#define PAX_DELTA_MMAP_LEN 15
7892 +#define PAX_DELTA_STACK_LEN 15
7893 +#endif
7894 +#endif
7895
7896 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7897
7898 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7899 (0x7ff >> (PAGE_SHIFT - 12)) : \
7900 (0x3ffff >> (PAGE_SHIFT - 12)))
7901
7902 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7903 -#define arch_randomize_brk arch_randomize_brk
7904 -
7905 -
7906 #ifdef CONFIG_SPU_BASE
7907 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7908 #define NT_SPU 1
7909 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7910 index 8196e9c..d83a9f3 100644
7911 --- a/arch/powerpc/include/asm/exec.h
7912 +++ b/arch/powerpc/include/asm/exec.h
7913 @@ -4,6 +4,6 @@
7914 #ifndef _ASM_POWERPC_EXEC_H
7915 #define _ASM_POWERPC_EXEC_H
7916
7917 -extern unsigned long arch_align_stack(unsigned long sp);
7918 +#define arch_align_stack(x) ((x) & ~0xfUL)
7919
7920 #endif /* _ASM_POWERPC_EXEC_H */
7921 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7922 index 5acabbd..7ea14fa 100644
7923 --- a/arch/powerpc/include/asm/kmap_types.h
7924 +++ b/arch/powerpc/include/asm/kmap_types.h
7925 @@ -10,7 +10,7 @@
7926 * 2 of the License, or (at your option) any later version.
7927 */
7928
7929 -#define KM_TYPE_NR 16
7930 +#define KM_TYPE_NR 17
7931
7932 #endif /* __KERNEL__ */
7933 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7934 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
7935 index b8da913..60b608a 100644
7936 --- a/arch/powerpc/include/asm/local.h
7937 +++ b/arch/powerpc/include/asm/local.h
7938 @@ -9,15 +9,26 @@ typedef struct
7939 atomic_long_t a;
7940 } local_t;
7941
7942 +typedef struct
7943 +{
7944 + atomic_long_unchecked_t a;
7945 +} local_unchecked_t;
7946 +
7947 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
7948
7949 #define local_read(l) atomic_long_read(&(l)->a)
7950 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
7951 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
7952 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
7953
7954 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
7955 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
7956 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
7957 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
7958 #define local_inc(l) atomic_long_inc(&(l)->a)
7959 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
7960 #define local_dec(l) atomic_long_dec(&(l)->a)
7961 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
7962
7963 static __inline__ long local_add_return(long a, local_t *l)
7964 {
7965 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
7966
7967 return t;
7968 }
7969 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
7970
7971 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
7972
7973 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
7974
7975 return t;
7976 }
7977 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
7978
7979 static __inline__ long local_inc_return(local_t *l)
7980 {
7981 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
7982
7983 #define local_cmpxchg(l, o, n) \
7984 (cmpxchg_local(&((l)->a.counter), (o), (n)))
7985 +#define local_cmpxchg_unchecked(l, o, n) \
7986 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
7987 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
7988
7989 /**
7990 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7991 index 8565c25..2865190 100644
7992 --- a/arch/powerpc/include/asm/mman.h
7993 +++ b/arch/powerpc/include/asm/mman.h
7994 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7995 }
7996 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7997
7998 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7999 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8000 {
8001 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8002 }
8003 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8004 index 32e4e21..62afb12 100644
8005 --- a/arch/powerpc/include/asm/page.h
8006 +++ b/arch/powerpc/include/asm/page.h
8007 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8008 * and needs to be executable. This means the whole heap ends
8009 * up being executable.
8010 */
8011 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8012 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8013 +#define VM_DATA_DEFAULT_FLAGS32 \
8014 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8015 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8016
8017 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8018 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8019 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8020 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8021 #endif
8022
8023 +#define ktla_ktva(addr) (addr)
8024 +#define ktva_ktla(addr) (addr)
8025 +
8026 #ifndef CONFIG_PPC_BOOK3S_64
8027 /*
8028 * Use the top bit of the higher-level page table entries to indicate whether
8029 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8030 index 88693ce..ac6f9ab 100644
8031 --- a/arch/powerpc/include/asm/page_64.h
8032 +++ b/arch/powerpc/include/asm/page_64.h
8033 @@ -153,15 +153,18 @@ do { \
8034 * stack by default, so in the absence of a PT_GNU_STACK program header
8035 * we turn execute permission off.
8036 */
8037 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8038 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8039 +#define VM_STACK_DEFAULT_FLAGS32 \
8040 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8041 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8042
8043 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8044 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8045
8046 +#ifndef CONFIG_PAX_PAGEEXEC
8047 #define VM_STACK_DEFAULT_FLAGS \
8048 (is_32bit_task() ? \
8049 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8050 +#endif
8051
8052 #include <asm-generic/getorder.h>
8053
8054 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8055 index 4b0be20..c15a27d 100644
8056 --- a/arch/powerpc/include/asm/pgalloc-64.h
8057 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8058 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8059 #ifndef CONFIG_PPC_64K_PAGES
8060
8061 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8062 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8063
8064 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8065 {
8066 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8067 pud_set(pud, (unsigned long)pmd);
8068 }
8069
8070 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8071 +{
8072 + pud_populate(mm, pud, pmd);
8073 +}
8074 +
8075 #define pmd_populate(mm, pmd, pte_page) \
8076 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8077 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8078 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8079 #endif
8080
8081 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8082 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8083
8084 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8085 pte_t *pte)
8086 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8087 index 3ebb188..e17dddf 100644
8088 --- a/arch/powerpc/include/asm/pgtable.h
8089 +++ b/arch/powerpc/include/asm/pgtable.h
8090 @@ -2,6 +2,7 @@
8091 #define _ASM_POWERPC_PGTABLE_H
8092 #ifdef __KERNEL__
8093
8094 +#include <linux/const.h>
8095 #ifndef __ASSEMBLY__
8096 #include <linux/mmdebug.h>
8097 #include <asm/processor.h> /* For TASK_SIZE */
8098 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8099 index 4aad413..85d86bf 100644
8100 --- a/arch/powerpc/include/asm/pte-hash32.h
8101 +++ b/arch/powerpc/include/asm/pte-hash32.h
8102 @@ -21,6 +21,7 @@
8103 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8104 #define _PAGE_USER 0x004 /* usermode access allowed */
8105 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8106 +#define _PAGE_EXEC _PAGE_GUARDED
8107 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8108 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8109 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8110 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8111 index 90c06ec..3517221 100644
8112 --- a/arch/powerpc/include/asm/reg.h
8113 +++ b/arch/powerpc/include/asm/reg.h
8114 @@ -248,6 +248,7 @@
8115 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8116 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8117 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8118 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8119 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8120 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8121 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8122 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8123 index 084e080..9415a3d 100644
8124 --- a/arch/powerpc/include/asm/smp.h
8125 +++ b/arch/powerpc/include/asm/smp.h
8126 @@ -51,7 +51,7 @@ struct smp_ops_t {
8127 int (*cpu_disable)(void);
8128 void (*cpu_die)(unsigned int nr);
8129 int (*cpu_bootable)(unsigned int nr);
8130 -};
8131 +} __no_const;
8132
8133 extern void smp_send_debugger_break(void);
8134 extern void start_secondary_resume(void);
8135 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8136 index b034ecd..af7e31f 100644
8137 --- a/arch/powerpc/include/asm/thread_info.h
8138 +++ b/arch/powerpc/include/asm/thread_info.h
8139 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8140 #if defined(CONFIG_PPC64)
8141 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8142 #endif
8143 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8144 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8145
8146 /* as above, but as bit values */
8147 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8148 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8149 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8150 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8151 #define _TIF_NOHZ (1<<TIF_NOHZ)
8152 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8153 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8154 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8155 - _TIF_NOHZ)
8156 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8157
8158 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8159 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8160 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8161 index 9485b43..3bd3c16 100644
8162 --- a/arch/powerpc/include/asm/uaccess.h
8163 +++ b/arch/powerpc/include/asm/uaccess.h
8164 @@ -58,6 +58,7 @@
8165
8166 #endif
8167
8168 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8169 #define access_ok(type, addr, size) \
8170 (__chk_user_ptr(addr), \
8171 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8172 @@ -318,52 +319,6 @@ do { \
8173 extern unsigned long __copy_tofrom_user(void __user *to,
8174 const void __user *from, unsigned long size);
8175
8176 -#ifndef __powerpc64__
8177 -
8178 -static inline unsigned long copy_from_user(void *to,
8179 - const void __user *from, unsigned long n)
8180 -{
8181 - unsigned long over;
8182 -
8183 - if (access_ok(VERIFY_READ, from, n))
8184 - return __copy_tofrom_user((__force void __user *)to, from, n);
8185 - if ((unsigned long)from < TASK_SIZE) {
8186 - over = (unsigned long)from + n - TASK_SIZE;
8187 - return __copy_tofrom_user((__force void __user *)to, from,
8188 - n - over) + over;
8189 - }
8190 - return n;
8191 -}
8192 -
8193 -static inline unsigned long copy_to_user(void __user *to,
8194 - const void *from, unsigned long n)
8195 -{
8196 - unsigned long over;
8197 -
8198 - if (access_ok(VERIFY_WRITE, to, n))
8199 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8200 - if ((unsigned long)to < TASK_SIZE) {
8201 - over = (unsigned long)to + n - TASK_SIZE;
8202 - return __copy_tofrom_user(to, (__force void __user *)from,
8203 - n - over) + over;
8204 - }
8205 - return n;
8206 -}
8207 -
8208 -#else /* __powerpc64__ */
8209 -
8210 -#define __copy_in_user(to, from, size) \
8211 - __copy_tofrom_user((to), (from), (size))
8212 -
8213 -extern unsigned long copy_from_user(void *to, const void __user *from,
8214 - unsigned long n);
8215 -extern unsigned long copy_to_user(void __user *to, const void *from,
8216 - unsigned long n);
8217 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8218 - unsigned long n);
8219 -
8220 -#endif /* __powerpc64__ */
8221 -
8222 static inline unsigned long __copy_from_user_inatomic(void *to,
8223 const void __user *from, unsigned long n)
8224 {
8225 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8226 if (ret == 0)
8227 return 0;
8228 }
8229 +
8230 + if (!__builtin_constant_p(n))
8231 + check_object_size(to, n, false);
8232 +
8233 return __copy_tofrom_user((__force void __user *)to, from, n);
8234 }
8235
8236 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8237 if (ret == 0)
8238 return 0;
8239 }
8240 +
8241 + if (!__builtin_constant_p(n))
8242 + check_object_size(from, n, true);
8243 +
8244 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8245 }
8246
8247 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8248 return __copy_to_user_inatomic(to, from, size);
8249 }
8250
8251 +#ifndef __powerpc64__
8252 +
8253 +static inline unsigned long __must_check copy_from_user(void *to,
8254 + const void __user *from, unsigned long n)
8255 +{
8256 + unsigned long over;
8257 +
8258 + if ((long)n < 0)
8259 + return n;
8260 +
8261 + if (access_ok(VERIFY_READ, from, n)) {
8262 + if (!__builtin_constant_p(n))
8263 + check_object_size(to, n, false);
8264 + return __copy_tofrom_user((__force void __user *)to, from, n);
8265 + }
8266 + if ((unsigned long)from < TASK_SIZE) {
8267 + over = (unsigned long)from + n - TASK_SIZE;
8268 + if (!__builtin_constant_p(n - over))
8269 + check_object_size(to, n - over, false);
8270 + return __copy_tofrom_user((__force void __user *)to, from,
8271 + n - over) + over;
8272 + }
8273 + return n;
8274 +}
8275 +
8276 +static inline unsigned long __must_check copy_to_user(void __user *to,
8277 + const void *from, unsigned long n)
8278 +{
8279 + unsigned long over;
8280 +
8281 + if ((long)n < 0)
8282 + return n;
8283 +
8284 + if (access_ok(VERIFY_WRITE, to, n)) {
8285 + if (!__builtin_constant_p(n))
8286 + check_object_size(from, n, true);
8287 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8288 + }
8289 + if ((unsigned long)to < TASK_SIZE) {
8290 + over = (unsigned long)to + n - TASK_SIZE;
8291 + if (!__builtin_constant_p(n))
8292 + check_object_size(from, n - over, true);
8293 + return __copy_tofrom_user(to, (__force void __user *)from,
8294 + n - over) + over;
8295 + }
8296 + return n;
8297 +}
8298 +
8299 +#else /* __powerpc64__ */
8300 +
8301 +#define __copy_in_user(to, from, size) \
8302 + __copy_tofrom_user((to), (from), (size))
8303 +
8304 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8305 +{
8306 + if ((long)n < 0 || n > INT_MAX)
8307 + return n;
8308 +
8309 + if (!__builtin_constant_p(n))
8310 + check_object_size(to, n, false);
8311 +
8312 + if (likely(access_ok(VERIFY_READ, from, n)))
8313 + n = __copy_from_user(to, from, n);
8314 + else
8315 + memset(to, 0, n);
8316 + return n;
8317 +}
8318 +
8319 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8320 +{
8321 + if ((long)n < 0 || n > INT_MAX)
8322 + return n;
8323 +
8324 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8325 + if (!__builtin_constant_p(n))
8326 + check_object_size(from, n, true);
8327 + n = __copy_to_user(to, from, n);
8328 + }
8329 + return n;
8330 +}
8331 +
8332 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8333 + unsigned long n);
8334 +
8335 +#endif /* __powerpc64__ */
8336 +
8337 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8338
8339 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8340 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8341 index fcc9a89..07be2bb 100644
8342 --- a/arch/powerpc/kernel/Makefile
8343 +++ b/arch/powerpc/kernel/Makefile
8344 @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8345 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8346 endif
8347
8348 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8349 +
8350 obj-y := cputable.o ptrace.o syscalls.o \
8351 irq.o align.o signal_32.o pmc.o vdso.o \
8352 process.o systbl.o idle.o \
8353 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8354 index 063b65d..7a26e9d 100644
8355 --- a/arch/powerpc/kernel/exceptions-64e.S
8356 +++ b/arch/powerpc/kernel/exceptions-64e.S
8357 @@ -771,6 +771,7 @@ storage_fault_common:
8358 std r14,_DAR(r1)
8359 std r15,_DSISR(r1)
8360 addi r3,r1,STACK_FRAME_OVERHEAD
8361 + bl .save_nvgprs
8362 mr r4,r14
8363 mr r5,r15
8364 ld r14,PACA_EXGEN+EX_R14(r13)
8365 @@ -779,8 +780,7 @@ storage_fault_common:
8366 cmpdi r3,0
8367 bne- 1f
8368 b .ret_from_except_lite
8369 -1: bl .save_nvgprs
8370 - mr r5,r3
8371 +1: mr r5,r3
8372 addi r3,r1,STACK_FRAME_OVERHEAD
8373 ld r4,_DAR(r1)
8374 bl .bad_page_fault
8375 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8376 index 38d5073..f00af8d 100644
8377 --- a/arch/powerpc/kernel/exceptions-64s.S
8378 +++ b/arch/powerpc/kernel/exceptions-64s.S
8379 @@ -1584,10 +1584,10 @@ handle_page_fault:
8380 11: ld r4,_DAR(r1)
8381 ld r5,_DSISR(r1)
8382 addi r3,r1,STACK_FRAME_OVERHEAD
8383 + bl .save_nvgprs
8384 bl .do_page_fault
8385 cmpdi r3,0
8386 beq+ 12f
8387 - bl .save_nvgprs
8388 mr r5,r3
8389 addi r3,r1,STACK_FRAME_OVERHEAD
8390 lwz r4,_DAR(r1)
8391 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8392 index 6cff040..74ac5d1 100644
8393 --- a/arch/powerpc/kernel/module_32.c
8394 +++ b/arch/powerpc/kernel/module_32.c
8395 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8396 me->arch.core_plt_section = i;
8397 }
8398 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8399 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8400 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8401 return -ENOEXEC;
8402 }
8403
8404 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8405
8406 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8407 /* Init, or core PLT? */
8408 - if (location >= mod->module_core
8409 - && location < mod->module_core + mod->core_size)
8410 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8411 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8412 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8413 - else
8414 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8415 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8416 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8417 + else {
8418 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8419 + return ~0UL;
8420 + }
8421
8422 /* Find this entry, or if that fails, the next avail. entry */
8423 while (entry->jump[0]) {
8424 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8425 }
8426 #ifdef CONFIG_DYNAMIC_FTRACE
8427 module->arch.tramp =
8428 - do_plt_call(module->module_core,
8429 + do_plt_call(module->module_core_rx,
8430 (unsigned long)ftrace_caller,
8431 sechdrs, module);
8432 #endif
8433 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8434 index af064d2..ce56147 100644
8435 --- a/arch/powerpc/kernel/process.c
8436 +++ b/arch/powerpc/kernel/process.c
8437 @@ -1009,8 +1009,8 @@ void show_regs(struct pt_regs * regs)
8438 * Lookup NIP late so we have the best change of getting the
8439 * above info out without failing
8440 */
8441 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8442 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8443 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8444 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8445 #endif
8446 show_stack(current, (unsigned long *) regs->gpr[1]);
8447 if (!user_mode(regs))
8448 @@ -1532,10 +1532,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8449 newsp = stack[0];
8450 ip = stack[STACK_FRAME_LR_SAVE];
8451 if (!firstframe || ip != lr) {
8452 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8453 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8454 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8455 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8456 - printk(" (%pS)",
8457 + printk(" (%pA)",
8458 (void *)current->ret_stack[curr_frame].ret);
8459 curr_frame--;
8460 }
8461 @@ -1555,7 +1555,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8462 struct pt_regs *regs = (struct pt_regs *)
8463 (sp + STACK_FRAME_OVERHEAD);
8464 lr = regs->link;
8465 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8466 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8467 regs->trap, (void *)regs->nip, (void *)lr);
8468 firstframe = 1;
8469 }
8470 @@ -1591,58 +1591,3 @@ void notrace __ppc64_runlatch_off(void)
8471 mtspr(SPRN_CTRLT, ctrl);
8472 }
8473 #endif /* CONFIG_PPC64 */
8474 -
8475 -unsigned long arch_align_stack(unsigned long sp)
8476 -{
8477 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8478 - sp -= get_random_int() & ~PAGE_MASK;
8479 - return sp & ~0xf;
8480 -}
8481 -
8482 -static inline unsigned long brk_rnd(void)
8483 -{
8484 - unsigned long rnd = 0;
8485 -
8486 - /* 8MB for 32bit, 1GB for 64bit */
8487 - if (is_32bit_task())
8488 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8489 - else
8490 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8491 -
8492 - return rnd << PAGE_SHIFT;
8493 -}
8494 -
8495 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8496 -{
8497 - unsigned long base = mm->brk;
8498 - unsigned long ret;
8499 -
8500 -#ifdef CONFIG_PPC_STD_MMU_64
8501 - /*
8502 - * If we are using 1TB segments and we are allowed to randomise
8503 - * the heap, we can put it above 1TB so it is backed by a 1TB
8504 - * segment. Otherwise the heap will be in the bottom 1TB
8505 - * which always uses 256MB segments and this may result in a
8506 - * performance penalty.
8507 - */
8508 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8509 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8510 -#endif
8511 -
8512 - ret = PAGE_ALIGN(base + brk_rnd());
8513 -
8514 - if (ret < mm->brk)
8515 - return mm->brk;
8516 -
8517 - return ret;
8518 -}
8519 -
8520 -unsigned long randomize_et_dyn(unsigned long base)
8521 -{
8522 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8523 -
8524 - if (ret < base)
8525 - return base;
8526 -
8527 - return ret;
8528 -}
8529 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8530 index 2e3d2bf..35df241 100644
8531 --- a/arch/powerpc/kernel/ptrace.c
8532 +++ b/arch/powerpc/kernel/ptrace.c
8533 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8534 return ret;
8535 }
8536
8537 +#ifdef CONFIG_GRKERNSEC_SETXID
8538 +extern void gr_delayed_cred_worker(void);
8539 +#endif
8540 +
8541 /*
8542 * We must return the syscall number to actually look up in the table.
8543 * This can be -1L to skip running any syscall at all.
8544 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8545
8546 secure_computing_strict(regs->gpr[0]);
8547
8548 +#ifdef CONFIG_GRKERNSEC_SETXID
8549 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8550 + gr_delayed_cred_worker();
8551 +#endif
8552 +
8553 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8554 tracehook_report_syscall_entry(regs))
8555 /*
8556 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8557 {
8558 int step;
8559
8560 +#ifdef CONFIG_GRKERNSEC_SETXID
8561 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8562 + gr_delayed_cred_worker();
8563 +#endif
8564 +
8565 audit_syscall_exit(regs);
8566
8567 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8568 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8569 index a67e00a..f71d8c7 100644
8570 --- a/arch/powerpc/kernel/signal_32.c
8571 +++ b/arch/powerpc/kernel/signal_32.c
8572 @@ -1011,7 +1011,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8573 /* Save user registers on the stack */
8574 frame = &rt_sf->uc.uc_mcontext;
8575 addr = frame;
8576 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8577 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8578 sigret = 0;
8579 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8580 } else {
8581 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8582 index 8d253c2..405b337 100644
8583 --- a/arch/powerpc/kernel/signal_64.c
8584 +++ b/arch/powerpc/kernel/signal_64.c
8585 @@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8586 current->thread.fp_state.fpscr = 0;
8587
8588 /* Set up to return from userspace. */
8589 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8590 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8591 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8592 } else {
8593 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8594 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8595 index 33cd7a0..d615344 100644
8596 --- a/arch/powerpc/kernel/traps.c
8597 +++ b/arch/powerpc/kernel/traps.c
8598 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8599 return flags;
8600 }
8601
8602 +extern void gr_handle_kernel_exploit(void);
8603 +
8604 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8605 int signr)
8606 {
8607 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8608 panic("Fatal exception in interrupt");
8609 if (panic_on_oops)
8610 panic("Fatal exception");
8611 +
8612 + gr_handle_kernel_exploit();
8613 +
8614 do_exit(signr);
8615 }
8616
8617 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8618 index 094e45c..d82b848 100644
8619 --- a/arch/powerpc/kernel/vdso.c
8620 +++ b/arch/powerpc/kernel/vdso.c
8621 @@ -35,6 +35,7 @@
8622 #include <asm/vdso.h>
8623 #include <asm/vdso_datapage.h>
8624 #include <asm/setup.h>
8625 +#include <asm/mman.h>
8626
8627 #undef DEBUG
8628
8629 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8630 vdso_base = VDSO32_MBASE;
8631 #endif
8632
8633 - current->mm->context.vdso_base = 0;
8634 + current->mm->context.vdso_base = ~0UL;
8635
8636 /* vDSO has a problem and was disabled, just don't "enable" it for the
8637 * process
8638 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8639 vdso_base = get_unmapped_area(NULL, vdso_base,
8640 (vdso_pages << PAGE_SHIFT) +
8641 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8642 - 0, 0);
8643 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8644 if (IS_ERR_VALUE(vdso_base)) {
8645 rc = vdso_base;
8646 goto fail_mmapsem;
8647 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8648 index 3cf541a..ab2d825 100644
8649 --- a/arch/powerpc/kvm/powerpc.c
8650 +++ b/arch/powerpc/kvm/powerpc.c
8651 @@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8652 }
8653 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8654
8655 -int kvm_arch_init(void *opaque)
8656 +int kvm_arch_init(const void *opaque)
8657 {
8658 return 0;
8659 }
8660 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8661 index 5eea6f3..5d10396 100644
8662 --- a/arch/powerpc/lib/usercopy_64.c
8663 +++ b/arch/powerpc/lib/usercopy_64.c
8664 @@ -9,22 +9,6 @@
8665 #include <linux/module.h>
8666 #include <asm/uaccess.h>
8667
8668 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8669 -{
8670 - if (likely(access_ok(VERIFY_READ, from, n)))
8671 - n = __copy_from_user(to, from, n);
8672 - else
8673 - memset(to, 0, n);
8674 - return n;
8675 -}
8676 -
8677 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8678 -{
8679 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8680 - n = __copy_to_user(to, from, n);
8681 - return n;
8682 -}
8683 -
8684 unsigned long copy_in_user(void __user *to, const void __user *from,
8685 unsigned long n)
8686 {
8687 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8688 return n;
8689 }
8690
8691 -EXPORT_SYMBOL(copy_from_user);
8692 -EXPORT_SYMBOL(copy_to_user);
8693 EXPORT_SYMBOL(copy_in_user);
8694
8695 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8696 index 51ab9e7..7d3c78b 100644
8697 --- a/arch/powerpc/mm/fault.c
8698 +++ b/arch/powerpc/mm/fault.c
8699 @@ -33,6 +33,10 @@
8700 #include <linux/magic.h>
8701 #include <linux/ratelimit.h>
8702 #include <linux/context_tracking.h>
8703 +#include <linux/slab.h>
8704 +#include <linux/pagemap.h>
8705 +#include <linux/compiler.h>
8706 +#include <linux/unistd.h>
8707
8708 #include <asm/firmware.h>
8709 #include <asm/page.h>
8710 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8711 }
8712 #endif
8713
8714 +#ifdef CONFIG_PAX_PAGEEXEC
8715 +/*
8716 + * PaX: decide what to do with offenders (regs->nip = fault address)
8717 + *
8718 + * returns 1 when task should be killed
8719 + */
8720 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8721 +{
8722 + return 1;
8723 +}
8724 +
8725 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8726 +{
8727 + unsigned long i;
8728 +
8729 + printk(KERN_ERR "PAX: bytes at PC: ");
8730 + for (i = 0; i < 5; i++) {
8731 + unsigned int c;
8732 + if (get_user(c, (unsigned int __user *)pc+i))
8733 + printk(KERN_CONT "???????? ");
8734 + else
8735 + printk(KERN_CONT "%08x ", c);
8736 + }
8737 + printk("\n");
8738 +}
8739 +#endif
8740 +
8741 /*
8742 * Check whether the instruction at regs->nip is a store using
8743 * an update addressing form which will update r1.
8744 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8745 * indicate errors in DSISR but can validly be set in SRR1.
8746 */
8747 if (trap == 0x400)
8748 - error_code &= 0x48200000;
8749 + error_code &= 0x58200000;
8750 else
8751 is_write = error_code & DSISR_ISSTORE;
8752 #else
8753 @@ -378,7 +409,7 @@ good_area:
8754 * "undefined". Of those that can be set, this is the only
8755 * one which seems bad.
8756 */
8757 - if (error_code & 0x10000000)
8758 + if (error_code & DSISR_GUARDED)
8759 /* Guarded storage error. */
8760 goto bad_area;
8761 #endif /* CONFIG_8xx */
8762 @@ -393,7 +424,7 @@ good_area:
8763 * processors use the same I/D cache coherency mechanism
8764 * as embedded.
8765 */
8766 - if (error_code & DSISR_PROTFAULT)
8767 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8768 goto bad_area;
8769 #endif /* CONFIG_PPC_STD_MMU */
8770
8771 @@ -483,6 +514,23 @@ bad_area:
8772 bad_area_nosemaphore:
8773 /* User mode accesses cause a SIGSEGV */
8774 if (user_mode(regs)) {
8775 +
8776 +#ifdef CONFIG_PAX_PAGEEXEC
8777 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8778 +#ifdef CONFIG_PPC_STD_MMU
8779 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8780 +#else
8781 + if (is_exec && regs->nip == address) {
8782 +#endif
8783 + switch (pax_handle_fetch_fault(regs)) {
8784 + }
8785 +
8786 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8787 + do_group_exit(SIGKILL);
8788 + }
8789 + }
8790 +#endif
8791 +
8792 _exception(SIGSEGV, regs, code, address);
8793 goto bail;
8794 }
8795 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8796 index cb8bdbe..cde4bc7 100644
8797 --- a/arch/powerpc/mm/mmap.c
8798 +++ b/arch/powerpc/mm/mmap.c
8799 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8800 return sysctl_legacy_va_layout;
8801 }
8802
8803 -static unsigned long mmap_rnd(void)
8804 +static unsigned long mmap_rnd(struct mm_struct *mm)
8805 {
8806 unsigned long rnd = 0;
8807
8808 +#ifdef CONFIG_PAX_RANDMMAP
8809 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8810 +#endif
8811 +
8812 if (current->flags & PF_RANDOMIZE) {
8813 /* 8MB for 32bit, 1GB for 64bit */
8814 if (is_32bit_task())
8815 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8816 return rnd << PAGE_SHIFT;
8817 }
8818
8819 -static inline unsigned long mmap_base(void)
8820 +static inline unsigned long mmap_base(struct mm_struct *mm)
8821 {
8822 unsigned long gap = rlimit(RLIMIT_STACK);
8823
8824 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8825 else if (gap > MAX_GAP)
8826 gap = MAX_GAP;
8827
8828 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8829 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8830 }
8831
8832 /*
8833 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8834 */
8835 if (mmap_is_legacy()) {
8836 mm->mmap_base = TASK_UNMAPPED_BASE;
8837 +
8838 +#ifdef CONFIG_PAX_RANDMMAP
8839 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8840 + mm->mmap_base += mm->delta_mmap;
8841 +#endif
8842 +
8843 mm->get_unmapped_area = arch_get_unmapped_area;
8844 } else {
8845 - mm->mmap_base = mmap_base();
8846 + mm->mmap_base = mmap_base(mm);
8847 +
8848 +#ifdef CONFIG_PAX_RANDMMAP
8849 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8850 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8851 +#endif
8852 +
8853 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8854 }
8855 }
8856 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8857 index b0c75cc..ef7fb93 100644
8858 --- a/arch/powerpc/mm/slice.c
8859 +++ b/arch/powerpc/mm/slice.c
8860 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8861 if ((mm->task_size - len) < addr)
8862 return 0;
8863 vma = find_vma(mm, addr);
8864 - return (!vma || (addr + len) <= vma->vm_start);
8865 + return check_heap_stack_gap(vma, addr, len, 0);
8866 }
8867
8868 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8869 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8870 info.align_offset = 0;
8871
8872 addr = TASK_UNMAPPED_BASE;
8873 +
8874 +#ifdef CONFIG_PAX_RANDMMAP
8875 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8876 + addr += mm->delta_mmap;
8877 +#endif
8878 +
8879 while (addr < TASK_SIZE) {
8880 info.low_limit = addr;
8881 if (!slice_scan_available(addr, available, 1, &addr))
8882 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8883 if (fixed && addr > (mm->task_size - len))
8884 return -ENOMEM;
8885
8886 +#ifdef CONFIG_PAX_RANDMMAP
8887 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8888 + addr = 0;
8889 +#endif
8890 +
8891 /* If hint, make sure it matches our alignment restrictions */
8892 if (!fixed && addr) {
8893 addr = _ALIGN_UP(addr, 1ul << pshift);
8894 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8895 index 4278acf..67fd0e6 100644
8896 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8897 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8898 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8899 }
8900
8901 static struct pci_ops scc_pciex_pci_ops = {
8902 - scc_pciex_read_config,
8903 - scc_pciex_write_config,
8904 + .read = scc_pciex_read_config,
8905 + .write = scc_pciex_write_config,
8906 };
8907
8908 static void pciex_clear_intr_all(unsigned int __iomem *base)
8909 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8910 index 9098692..3d54cd1 100644
8911 --- a/arch/powerpc/platforms/cell/spufs/file.c
8912 +++ b/arch/powerpc/platforms/cell/spufs/file.c
8913 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8914 return VM_FAULT_NOPAGE;
8915 }
8916
8917 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8918 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8919 unsigned long address,
8920 - void *buf, int len, int write)
8921 + void *buf, size_t len, int write)
8922 {
8923 struct spu_context *ctx = vma->vm_file->private_data;
8924 unsigned long offset = address - vma->vm_start;
8925 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8926 index fa9aaf7..3f5d836 100644
8927 --- a/arch/s390/include/asm/atomic.h
8928 +++ b/arch/s390/include/asm/atomic.h
8929 @@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8930 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8931 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8932
8933 +#define atomic64_read_unchecked(v) atomic64_read(v)
8934 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8935 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8936 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8937 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8938 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8939 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8940 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8941 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8942 +
8943 #define smp_mb__before_atomic_dec() smp_mb()
8944 #define smp_mb__after_atomic_dec() smp_mb()
8945 #define smp_mb__before_atomic_inc() smp_mb()
8946 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8947 index 4d7ccac..d03d0ad 100644
8948 --- a/arch/s390/include/asm/cache.h
8949 +++ b/arch/s390/include/asm/cache.h
8950 @@ -9,8 +9,10 @@
8951 #ifndef __ARCH_S390_CACHE_H
8952 #define __ARCH_S390_CACHE_H
8953
8954 -#define L1_CACHE_BYTES 256
8955 +#include <linux/const.h>
8956 +
8957 #define L1_CACHE_SHIFT 8
8958 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8959 #define NET_SKB_PAD 32
8960
8961 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8962 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8963 index 78f4f87..598ce39 100644
8964 --- a/arch/s390/include/asm/elf.h
8965 +++ b/arch/s390/include/asm/elf.h
8966 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8967 the loader. We need to make sure that it is out of the way of the program
8968 that it will "exec", and that there is sufficient room for the brk. */
8969
8970 -extern unsigned long randomize_et_dyn(unsigned long base);
8971 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8972 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8973 +
8974 +#ifdef CONFIG_PAX_ASLR
8975 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8976 +
8977 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8978 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8979 +#endif
8980
8981 /* This yields a mask that user programs can use to figure out what
8982 instruction set this CPU supports. */
8983 @@ -222,9 +228,6 @@ struct linux_binprm;
8984 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8985 int arch_setup_additional_pages(struct linux_binprm *, int);
8986
8987 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8988 -#define arch_randomize_brk arch_randomize_brk
8989 -
8990 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8991
8992 #endif
8993 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8994 index c4a93d6..4d2a9b4 100644
8995 --- a/arch/s390/include/asm/exec.h
8996 +++ b/arch/s390/include/asm/exec.h
8997 @@ -7,6 +7,6 @@
8998 #ifndef __ASM_EXEC_H
8999 #define __ASM_EXEC_H
9000
9001 -extern unsigned long arch_align_stack(unsigned long sp);
9002 +#define arch_align_stack(x) ((x) & ~0xfUL)
9003
9004 #endif /* __ASM_EXEC_H */
9005 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9006 index 79330af..254cf37 100644
9007 --- a/arch/s390/include/asm/uaccess.h
9008 +++ b/arch/s390/include/asm/uaccess.h
9009 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9010 __range_ok((unsigned long)(addr), (size)); \
9011 })
9012
9013 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9014 #define access_ok(type, addr, size) __access_ok(addr, size)
9015
9016 /*
9017 @@ -245,6 +246,10 @@ static inline unsigned long __must_check
9018 copy_to_user(void __user *to, const void *from, unsigned long n)
9019 {
9020 might_fault();
9021 +
9022 + if ((long)n < 0)
9023 + return n;
9024 +
9025 return __copy_to_user(to, from, n);
9026 }
9027
9028 @@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9029 static inline unsigned long __must_check
9030 __copy_from_user(void *to, const void __user *from, unsigned long n)
9031 {
9032 + if ((long)n < 0)
9033 + return n;
9034 +
9035 return uaccess.copy_from_user(n, from, to);
9036 }
9037
9038 @@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9039 static inline unsigned long __must_check
9040 copy_from_user(void *to, const void __user *from, unsigned long n)
9041 {
9042 - unsigned int sz = __compiletime_object_size(to);
9043 + size_t sz = __compiletime_object_size(to);
9044
9045 might_fault();
9046 - if (unlikely(sz != -1 && sz < n)) {
9047 +
9048 + if ((long)n < 0)
9049 + return n;
9050 +
9051 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9052 copy_from_user_overflow();
9053 return n;
9054 }
9055 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9056 index b89b591..fd9609d 100644
9057 --- a/arch/s390/kernel/module.c
9058 +++ b/arch/s390/kernel/module.c
9059 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9060
9061 /* Increase core size by size of got & plt and set start
9062 offsets for got and plt. */
9063 - me->core_size = ALIGN(me->core_size, 4);
9064 - me->arch.got_offset = me->core_size;
9065 - me->core_size += me->arch.got_size;
9066 - me->arch.plt_offset = me->core_size;
9067 - me->core_size += me->arch.plt_size;
9068 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9069 + me->arch.got_offset = me->core_size_rw;
9070 + me->core_size_rw += me->arch.got_size;
9071 + me->arch.plt_offset = me->core_size_rx;
9072 + me->core_size_rx += me->arch.plt_size;
9073 return 0;
9074 }
9075
9076 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9077 if (info->got_initialized == 0) {
9078 Elf_Addr *gotent;
9079
9080 - gotent = me->module_core + me->arch.got_offset +
9081 + gotent = me->module_core_rw + me->arch.got_offset +
9082 info->got_offset;
9083 *gotent = val;
9084 info->got_initialized = 1;
9085 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9086 rc = apply_rela_bits(loc, val, 0, 64, 0);
9087 else if (r_type == R_390_GOTENT ||
9088 r_type == R_390_GOTPLTENT) {
9089 - val += (Elf_Addr) me->module_core - loc;
9090 + val += (Elf_Addr) me->module_core_rw - loc;
9091 rc = apply_rela_bits(loc, val, 1, 32, 1);
9092 }
9093 break;
9094 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9095 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9096 if (info->plt_initialized == 0) {
9097 unsigned int *ip;
9098 - ip = me->module_core + me->arch.plt_offset +
9099 + ip = me->module_core_rx + me->arch.plt_offset +
9100 info->plt_offset;
9101 #ifndef CONFIG_64BIT
9102 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9103 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9104 val - loc + 0xffffUL < 0x1ffffeUL) ||
9105 (r_type == R_390_PLT32DBL &&
9106 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9107 - val = (Elf_Addr) me->module_core +
9108 + val = (Elf_Addr) me->module_core_rx +
9109 me->arch.plt_offset +
9110 info->plt_offset;
9111 val += rela->r_addend - loc;
9112 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9113 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9114 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9115 val = val + rela->r_addend -
9116 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9117 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9118 if (r_type == R_390_GOTOFF16)
9119 rc = apply_rela_bits(loc, val, 0, 16, 0);
9120 else if (r_type == R_390_GOTOFF32)
9121 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9122 break;
9123 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9124 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9125 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9126 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9127 rela->r_addend - loc;
9128 if (r_type == R_390_GOTPC)
9129 rc = apply_rela_bits(loc, val, 1, 32, 0);
9130 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9131 index dd14532..1dfc145 100644
9132 --- a/arch/s390/kernel/process.c
9133 +++ b/arch/s390/kernel/process.c
9134 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9135 }
9136 return 0;
9137 }
9138 -
9139 -unsigned long arch_align_stack(unsigned long sp)
9140 -{
9141 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9142 - sp -= get_random_int() & ~PAGE_MASK;
9143 - return sp & ~0xf;
9144 -}
9145 -
9146 -static inline unsigned long brk_rnd(void)
9147 -{
9148 - /* 8MB for 32bit, 1GB for 64bit */
9149 - if (is_32bit_task())
9150 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9151 - else
9152 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9153 -}
9154 -
9155 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9156 -{
9157 - unsigned long ret;
9158 -
9159 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9160 - return (ret > mm->brk) ? ret : mm->brk;
9161 -}
9162 -
9163 -unsigned long randomize_et_dyn(unsigned long base)
9164 -{
9165 - unsigned long ret;
9166 -
9167 - if (!(current->flags & PF_RANDOMIZE))
9168 - return base;
9169 - ret = PAGE_ALIGN(base + brk_rnd());
9170 - return (ret > base) ? ret : base;
9171 -}
9172 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9173 index 9b436c2..54fbf0a 100644
9174 --- a/arch/s390/mm/mmap.c
9175 +++ b/arch/s390/mm/mmap.c
9176 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9177 */
9178 if (mmap_is_legacy()) {
9179 mm->mmap_base = mmap_base_legacy();
9180 +
9181 +#ifdef CONFIG_PAX_RANDMMAP
9182 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9183 + mm->mmap_base += mm->delta_mmap;
9184 +#endif
9185 +
9186 mm->get_unmapped_area = arch_get_unmapped_area;
9187 } else {
9188 mm->mmap_base = mmap_base();
9189 +
9190 +#ifdef CONFIG_PAX_RANDMMAP
9191 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9192 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9193 +#endif
9194 +
9195 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9196 }
9197 }
9198 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9199 */
9200 if (mmap_is_legacy()) {
9201 mm->mmap_base = mmap_base_legacy();
9202 +
9203 +#ifdef CONFIG_PAX_RANDMMAP
9204 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9205 + mm->mmap_base += mm->delta_mmap;
9206 +#endif
9207 +
9208 mm->get_unmapped_area = s390_get_unmapped_area;
9209 } else {
9210 mm->mmap_base = mmap_base();
9211 +
9212 +#ifdef CONFIG_PAX_RANDMMAP
9213 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9214 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9215 +#endif
9216 +
9217 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9218 }
9219 }
9220 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9221 index ae3d59f..f65f075 100644
9222 --- a/arch/score/include/asm/cache.h
9223 +++ b/arch/score/include/asm/cache.h
9224 @@ -1,7 +1,9 @@
9225 #ifndef _ASM_SCORE_CACHE_H
9226 #define _ASM_SCORE_CACHE_H
9227
9228 +#include <linux/const.h>
9229 +
9230 #define L1_CACHE_SHIFT 4
9231 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9232 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9233
9234 #endif /* _ASM_SCORE_CACHE_H */
9235 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9236 index f9f3cd5..58ff438 100644
9237 --- a/arch/score/include/asm/exec.h
9238 +++ b/arch/score/include/asm/exec.h
9239 @@ -1,6 +1,6 @@
9240 #ifndef _ASM_SCORE_EXEC_H
9241 #define _ASM_SCORE_EXEC_H
9242
9243 -extern unsigned long arch_align_stack(unsigned long sp);
9244 +#define arch_align_stack(x) (x)
9245
9246 #endif /* _ASM_SCORE_EXEC_H */
9247 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9248 index a1519ad3..e8ac1ff 100644
9249 --- a/arch/score/kernel/process.c
9250 +++ b/arch/score/kernel/process.c
9251 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9252
9253 return task_pt_regs(task)->cp0_epc;
9254 }
9255 -
9256 -unsigned long arch_align_stack(unsigned long sp)
9257 -{
9258 - return sp;
9259 -}
9260 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9261 index ef9e555..331bd29 100644
9262 --- a/arch/sh/include/asm/cache.h
9263 +++ b/arch/sh/include/asm/cache.h
9264 @@ -9,10 +9,11 @@
9265 #define __ASM_SH_CACHE_H
9266 #ifdef __KERNEL__
9267
9268 +#include <linux/const.h>
9269 #include <linux/init.h>
9270 #include <cpu/cache.h>
9271
9272 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9273 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9274
9275 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9276
9277 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9278 index 6777177..cb5e44f 100644
9279 --- a/arch/sh/mm/mmap.c
9280 +++ b/arch/sh/mm/mmap.c
9281 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9282 struct mm_struct *mm = current->mm;
9283 struct vm_area_struct *vma;
9284 int do_colour_align;
9285 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9286 struct vm_unmapped_area_info info;
9287
9288 if (flags & MAP_FIXED) {
9289 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9290 if (filp || (flags & MAP_SHARED))
9291 do_colour_align = 1;
9292
9293 +#ifdef CONFIG_PAX_RANDMMAP
9294 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9295 +#endif
9296 +
9297 if (addr) {
9298 if (do_colour_align)
9299 addr = COLOUR_ALIGN(addr, pgoff);
9300 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9301 addr = PAGE_ALIGN(addr);
9302
9303 vma = find_vma(mm, addr);
9304 - if (TASK_SIZE - len >= addr &&
9305 - (!vma || addr + len <= vma->vm_start))
9306 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9307 return addr;
9308 }
9309
9310 info.flags = 0;
9311 info.length = len;
9312 - info.low_limit = TASK_UNMAPPED_BASE;
9313 + info.low_limit = mm->mmap_base;
9314 info.high_limit = TASK_SIZE;
9315 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9316 info.align_offset = pgoff << PAGE_SHIFT;
9317 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9318 struct mm_struct *mm = current->mm;
9319 unsigned long addr = addr0;
9320 int do_colour_align;
9321 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9322 struct vm_unmapped_area_info info;
9323
9324 if (flags & MAP_FIXED) {
9325 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9326 if (filp || (flags & MAP_SHARED))
9327 do_colour_align = 1;
9328
9329 +#ifdef CONFIG_PAX_RANDMMAP
9330 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9331 +#endif
9332 +
9333 /* requesting a specific address */
9334 if (addr) {
9335 if (do_colour_align)
9336 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9337 addr = PAGE_ALIGN(addr);
9338
9339 vma = find_vma(mm, addr);
9340 - if (TASK_SIZE - len >= addr &&
9341 - (!vma || addr + len <= vma->vm_start))
9342 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9343 return addr;
9344 }
9345
9346 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9347 VM_BUG_ON(addr != -ENOMEM);
9348 info.flags = 0;
9349 info.low_limit = TASK_UNMAPPED_BASE;
9350 +
9351 +#ifdef CONFIG_PAX_RANDMMAP
9352 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9353 + info.low_limit += mm->delta_mmap;
9354 +#endif
9355 +
9356 info.high_limit = TASK_SIZE;
9357 addr = vm_unmapped_area(&info);
9358 }
9359 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9360 index be56a24..443328f 100644
9361 --- a/arch/sparc/include/asm/atomic_64.h
9362 +++ b/arch/sparc/include/asm/atomic_64.h
9363 @@ -14,18 +14,40 @@
9364 #define ATOMIC64_INIT(i) { (i) }
9365
9366 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9367 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9368 +{
9369 + return v->counter;
9370 +}
9371 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9372 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9373 +{
9374 + return v->counter;
9375 +}
9376
9377 #define atomic_set(v, i) (((v)->counter) = i)
9378 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9379 +{
9380 + v->counter = i;
9381 +}
9382 #define atomic64_set(v, i) (((v)->counter) = i)
9383 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9384 +{
9385 + v->counter = i;
9386 +}
9387
9388 extern void atomic_add(int, atomic_t *);
9389 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9390 extern void atomic64_add(long, atomic64_t *);
9391 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9392 extern void atomic_sub(int, atomic_t *);
9393 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9394 extern void atomic64_sub(long, atomic64_t *);
9395 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9396
9397 extern int atomic_add_ret(int, atomic_t *);
9398 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9399 extern long atomic64_add_ret(long, atomic64_t *);
9400 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9401 extern int atomic_sub_ret(int, atomic_t *);
9402 extern long atomic64_sub_ret(long, atomic64_t *);
9403
9404 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9405 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9406
9407 #define atomic_inc_return(v) atomic_add_ret(1, v)
9408 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9409 +{
9410 + return atomic_add_ret_unchecked(1, v);
9411 +}
9412 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9413 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9414 +{
9415 + return atomic64_add_ret_unchecked(1, v);
9416 +}
9417
9418 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9419 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9420
9421 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9422 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9423 +{
9424 + return atomic_add_ret_unchecked(i, v);
9425 +}
9426 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9427 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9428 +{
9429 + return atomic64_add_ret_unchecked(i, v);
9430 +}
9431
9432 /*
9433 * atomic_inc_and_test - increment and test
9434 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9435 * other cases.
9436 */
9437 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9438 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9439 +{
9440 + return atomic_inc_return_unchecked(v) == 0;
9441 +}
9442 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9443
9444 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9445 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9446 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9447
9448 #define atomic_inc(v) atomic_add(1, v)
9449 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9450 +{
9451 + atomic_add_unchecked(1, v);
9452 +}
9453 #define atomic64_inc(v) atomic64_add(1, v)
9454 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9455 +{
9456 + atomic64_add_unchecked(1, v);
9457 +}
9458
9459 #define atomic_dec(v) atomic_sub(1, v)
9460 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9461 +{
9462 + atomic_sub_unchecked(1, v);
9463 +}
9464 #define atomic64_dec(v) atomic64_sub(1, v)
9465 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9466 +{
9467 + atomic64_sub_unchecked(1, v);
9468 +}
9469
9470 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9471 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9472
9473 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9474 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9475 +{
9476 + return cmpxchg(&v->counter, old, new);
9477 +}
9478 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9479 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9480 +{
9481 + return xchg(&v->counter, new);
9482 +}
9483
9484 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9485 {
9486 - int c, old;
9487 + int c, old, new;
9488 c = atomic_read(v);
9489 for (;;) {
9490 - if (unlikely(c == (u)))
9491 + if (unlikely(c == u))
9492 break;
9493 - old = atomic_cmpxchg((v), c, c + (a));
9494 +
9495 + asm volatile("addcc %2, %0, %0\n"
9496 +
9497 +#ifdef CONFIG_PAX_REFCOUNT
9498 + "tvs %%icc, 6\n"
9499 +#endif
9500 +
9501 + : "=r" (new)
9502 + : "0" (c), "ir" (a)
9503 + : "cc");
9504 +
9505 + old = atomic_cmpxchg(v, c, new);
9506 if (likely(old == c))
9507 break;
9508 c = old;
9509 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9510 #define atomic64_cmpxchg(v, o, n) \
9511 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9512 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9513 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9514 +{
9515 + return xchg(&v->counter, new);
9516 +}
9517
9518 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9519 {
9520 - long c, old;
9521 + long c, old, new;
9522 c = atomic64_read(v);
9523 for (;;) {
9524 - if (unlikely(c == (u)))
9525 + if (unlikely(c == u))
9526 break;
9527 - old = atomic64_cmpxchg((v), c, c + (a));
9528 +
9529 + asm volatile("addcc %2, %0, %0\n"
9530 +
9531 +#ifdef CONFIG_PAX_REFCOUNT
9532 + "tvs %%xcc, 6\n"
9533 +#endif
9534 +
9535 + : "=r" (new)
9536 + : "0" (c), "ir" (a)
9537 + : "cc");
9538 +
9539 + old = atomic64_cmpxchg(v, c, new);
9540 if (likely(old == c))
9541 break;
9542 c = old;
9543 }
9544 - return c != (u);
9545 + return c != u;
9546 }
9547
9548 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9549 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9550 index 5bb6991..5c2132e 100644
9551 --- a/arch/sparc/include/asm/cache.h
9552 +++ b/arch/sparc/include/asm/cache.h
9553 @@ -7,10 +7,12 @@
9554 #ifndef _SPARC_CACHE_H
9555 #define _SPARC_CACHE_H
9556
9557 +#include <linux/const.h>
9558 +
9559 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9560
9561 #define L1_CACHE_SHIFT 5
9562 -#define L1_CACHE_BYTES 32
9563 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9564
9565 #ifdef CONFIG_SPARC32
9566 #define SMP_CACHE_BYTES_SHIFT 5
9567 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9568 index a24e41f..47677ff 100644
9569 --- a/arch/sparc/include/asm/elf_32.h
9570 +++ b/arch/sparc/include/asm/elf_32.h
9571 @@ -114,6 +114,13 @@ typedef struct {
9572
9573 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9574
9575 +#ifdef CONFIG_PAX_ASLR
9576 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9577 +
9578 +#define PAX_DELTA_MMAP_LEN 16
9579 +#define PAX_DELTA_STACK_LEN 16
9580 +#endif
9581 +
9582 /* This yields a mask that user programs can use to figure out what
9583 instruction set this cpu supports. This can NOT be done in userspace
9584 on Sparc. */
9585 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9586 index 370ca1e..d4f4a98 100644
9587 --- a/arch/sparc/include/asm/elf_64.h
9588 +++ b/arch/sparc/include/asm/elf_64.h
9589 @@ -189,6 +189,13 @@ typedef struct {
9590 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9591 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9592
9593 +#ifdef CONFIG_PAX_ASLR
9594 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9595 +
9596 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9597 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9598 +#endif
9599 +
9600 extern unsigned long sparc64_elf_hwcap;
9601 #define ELF_HWCAP sparc64_elf_hwcap
9602
9603 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9604 index 9b1c36d..209298b 100644
9605 --- a/arch/sparc/include/asm/pgalloc_32.h
9606 +++ b/arch/sparc/include/asm/pgalloc_32.h
9607 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9608 }
9609
9610 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9611 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9612
9613 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9614 unsigned long address)
9615 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9616 index bcfe063..b333142 100644
9617 --- a/arch/sparc/include/asm/pgalloc_64.h
9618 +++ b/arch/sparc/include/asm/pgalloc_64.h
9619 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9620 }
9621
9622 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9623 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9624
9625 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9626 {
9627 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9628 index 59ba6f6..4518128 100644
9629 --- a/arch/sparc/include/asm/pgtable.h
9630 +++ b/arch/sparc/include/asm/pgtable.h
9631 @@ -5,4 +5,8 @@
9632 #else
9633 #include <asm/pgtable_32.h>
9634 #endif
9635 +
9636 +#define ktla_ktva(addr) (addr)
9637 +#define ktva_ktla(addr) (addr)
9638 +
9639 #endif
9640 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9641 index 502f632..da1917f 100644
9642 --- a/arch/sparc/include/asm/pgtable_32.h
9643 +++ b/arch/sparc/include/asm/pgtable_32.h
9644 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9645 #define PAGE_SHARED SRMMU_PAGE_SHARED
9646 #define PAGE_COPY SRMMU_PAGE_COPY
9647 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9648 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9649 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9650 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9651 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9652
9653 /* Top-level page directory - dummy used by init-mm.
9654 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9655
9656 /* xwr */
9657 #define __P000 PAGE_NONE
9658 -#define __P001 PAGE_READONLY
9659 -#define __P010 PAGE_COPY
9660 -#define __P011 PAGE_COPY
9661 +#define __P001 PAGE_READONLY_NOEXEC
9662 +#define __P010 PAGE_COPY_NOEXEC
9663 +#define __P011 PAGE_COPY_NOEXEC
9664 #define __P100 PAGE_READONLY
9665 #define __P101 PAGE_READONLY
9666 #define __P110 PAGE_COPY
9667 #define __P111 PAGE_COPY
9668
9669 #define __S000 PAGE_NONE
9670 -#define __S001 PAGE_READONLY
9671 -#define __S010 PAGE_SHARED
9672 -#define __S011 PAGE_SHARED
9673 +#define __S001 PAGE_READONLY_NOEXEC
9674 +#define __S010 PAGE_SHARED_NOEXEC
9675 +#define __S011 PAGE_SHARED_NOEXEC
9676 #define __S100 PAGE_READONLY
9677 #define __S101 PAGE_READONLY
9678 #define __S110 PAGE_SHARED
9679 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9680 index 79da178..c2eede8 100644
9681 --- a/arch/sparc/include/asm/pgtsrmmu.h
9682 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9683 @@ -115,6 +115,11 @@
9684 SRMMU_EXEC | SRMMU_REF)
9685 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9686 SRMMU_EXEC | SRMMU_REF)
9687 +
9688 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9689 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9690 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9691 +
9692 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9693 SRMMU_DIRTY | SRMMU_REF)
9694
9695 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9696 index 9689176..63c18ea 100644
9697 --- a/arch/sparc/include/asm/spinlock_64.h
9698 +++ b/arch/sparc/include/asm/spinlock_64.h
9699 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9700
9701 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9702
9703 -static void inline arch_read_lock(arch_rwlock_t *lock)
9704 +static inline void arch_read_lock(arch_rwlock_t *lock)
9705 {
9706 unsigned long tmp1, tmp2;
9707
9708 __asm__ __volatile__ (
9709 "1: ldsw [%2], %0\n"
9710 " brlz,pn %0, 2f\n"
9711 -"4: add %0, 1, %1\n"
9712 +"4: addcc %0, 1, %1\n"
9713 +
9714 +#ifdef CONFIG_PAX_REFCOUNT
9715 +" tvs %%icc, 6\n"
9716 +#endif
9717 +
9718 " cas [%2], %0, %1\n"
9719 " cmp %0, %1\n"
9720 " bne,pn %%icc, 1b\n"
9721 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9722 " .previous"
9723 : "=&r" (tmp1), "=&r" (tmp2)
9724 : "r" (lock)
9725 - : "memory");
9726 + : "memory", "cc");
9727 }
9728
9729 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9730 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9731 {
9732 int tmp1, tmp2;
9733
9734 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9735 "1: ldsw [%2], %0\n"
9736 " brlz,a,pn %0, 2f\n"
9737 " mov 0, %0\n"
9738 -" add %0, 1, %1\n"
9739 +" addcc %0, 1, %1\n"
9740 +
9741 +#ifdef CONFIG_PAX_REFCOUNT
9742 +" tvs %%icc, 6\n"
9743 +#endif
9744 +
9745 " cas [%2], %0, %1\n"
9746 " cmp %0, %1\n"
9747 " bne,pn %%icc, 1b\n"
9748 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9749 return tmp1;
9750 }
9751
9752 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9753 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9754 {
9755 unsigned long tmp1, tmp2;
9756
9757 __asm__ __volatile__(
9758 "1: lduw [%2], %0\n"
9759 -" sub %0, 1, %1\n"
9760 +" subcc %0, 1, %1\n"
9761 +
9762 +#ifdef CONFIG_PAX_REFCOUNT
9763 +" tvs %%icc, 6\n"
9764 +#endif
9765 +
9766 " cas [%2], %0, %1\n"
9767 " cmp %0, %1\n"
9768 " bne,pn %%xcc, 1b\n"
9769 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9770 : "memory");
9771 }
9772
9773 -static void inline arch_write_lock(arch_rwlock_t *lock)
9774 +static inline void arch_write_lock(arch_rwlock_t *lock)
9775 {
9776 unsigned long mask, tmp1, tmp2;
9777
9778 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9779 : "memory");
9780 }
9781
9782 -static void inline arch_write_unlock(arch_rwlock_t *lock)
9783 +static inline void arch_write_unlock(arch_rwlock_t *lock)
9784 {
9785 __asm__ __volatile__(
9786 " stw %%g0, [%0]"
9787 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9788 : "memory");
9789 }
9790
9791 -static int inline arch_write_trylock(arch_rwlock_t *lock)
9792 +static inline int arch_write_trylock(arch_rwlock_t *lock)
9793 {
9794 unsigned long mask, tmp1, tmp2, result;
9795
9796 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9797 index 96efa7a..16858bf 100644
9798 --- a/arch/sparc/include/asm/thread_info_32.h
9799 +++ b/arch/sparc/include/asm/thread_info_32.h
9800 @@ -49,6 +49,8 @@ struct thread_info {
9801 unsigned long w_saved;
9802
9803 struct restart_block restart_block;
9804 +
9805 + unsigned long lowest_stack;
9806 };
9807
9808 /*
9809 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9810 index a5f01ac..703b554 100644
9811 --- a/arch/sparc/include/asm/thread_info_64.h
9812 +++ b/arch/sparc/include/asm/thread_info_64.h
9813 @@ -63,6 +63,8 @@ struct thread_info {
9814 struct pt_regs *kern_una_regs;
9815 unsigned int kern_una_insn;
9816
9817 + unsigned long lowest_stack;
9818 +
9819 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9820 };
9821
9822 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9823 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9824 /* flag bit 4 is available */
9825 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9826 -/* flag bit 6 is available */
9827 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9828 #define TIF_32BIT 7 /* 32-bit binary */
9829 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9830 #define TIF_SECCOMP 9 /* secure computing */
9831 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9832 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9833 +
9834 /* NOTE: Thread flags >= 12 should be ones we have no interest
9835 * in using in assembly, else we can't use the mask as
9836 * an immediate value in instructions such as andcc.
9837 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9838 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9839 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9840 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9841 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9842
9843 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9844 _TIF_DO_NOTIFY_RESUME_MASK | \
9845 _TIF_NEED_RESCHED)
9846 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9847
9848 +#define _TIF_WORK_SYSCALL \
9849 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9850 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9851 +
9852 +
9853 /*
9854 * Thread-synchronous status.
9855 *
9856 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9857 index 0167d26..767bb0c 100644
9858 --- a/arch/sparc/include/asm/uaccess.h
9859 +++ b/arch/sparc/include/asm/uaccess.h
9860 @@ -1,5 +1,6 @@
9861 #ifndef ___ASM_SPARC_UACCESS_H
9862 #define ___ASM_SPARC_UACCESS_H
9863 +
9864 #if defined(__sparc__) && defined(__arch64__)
9865 #include <asm/uaccess_64.h>
9866 #else
9867 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9868 index 53a28dd..50c38c3 100644
9869 --- a/arch/sparc/include/asm/uaccess_32.h
9870 +++ b/arch/sparc/include/asm/uaccess_32.h
9871 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9872
9873 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9874 {
9875 - if (n && __access_ok((unsigned long) to, n))
9876 + if ((long)n < 0)
9877 + return n;
9878 +
9879 + if (n && __access_ok((unsigned long) to, n)) {
9880 + if (!__builtin_constant_p(n))
9881 + check_object_size(from, n, true);
9882 return __copy_user(to, (__force void __user *) from, n);
9883 - else
9884 + } else
9885 return n;
9886 }
9887
9888 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9889 {
9890 + if ((long)n < 0)
9891 + return n;
9892 +
9893 + if (!__builtin_constant_p(n))
9894 + check_object_size(from, n, true);
9895 +
9896 return __copy_user(to, (__force void __user *) from, n);
9897 }
9898
9899 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9900 {
9901 - if (n && __access_ok((unsigned long) from, n))
9902 + if ((long)n < 0)
9903 + return n;
9904 +
9905 + if (n && __access_ok((unsigned long) from, n)) {
9906 + if (!__builtin_constant_p(n))
9907 + check_object_size(to, n, false);
9908 return __copy_user((__force void __user *) to, from, n);
9909 - else
9910 + } else
9911 return n;
9912 }
9913
9914 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9915 {
9916 + if ((long)n < 0)
9917 + return n;
9918 +
9919 return __copy_user((__force void __user *) to, from, n);
9920 }
9921
9922 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9923 index ad7e178..c9e7423 100644
9924 --- a/arch/sparc/include/asm/uaccess_64.h
9925 +++ b/arch/sparc/include/asm/uaccess_64.h
9926 @@ -10,6 +10,7 @@
9927 #include <linux/compiler.h>
9928 #include <linux/string.h>
9929 #include <linux/thread_info.h>
9930 +#include <linux/kernel.h>
9931 #include <asm/asi.h>
9932 #include <asm/spitfire.h>
9933 #include <asm-generic/uaccess-unaligned.h>
9934 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9935 static inline unsigned long __must_check
9936 copy_from_user(void *to, const void __user *from, unsigned long size)
9937 {
9938 - unsigned long ret = ___copy_from_user(to, from, size);
9939 + unsigned long ret;
9940
9941 + if ((long)size < 0 || size > INT_MAX)
9942 + return size;
9943 +
9944 + if (!__builtin_constant_p(size))
9945 + check_object_size(to, size, false);
9946 +
9947 + ret = ___copy_from_user(to, from, size);
9948 if (unlikely(ret))
9949 ret = copy_from_user_fixup(to, from, size);
9950
9951 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9952 static inline unsigned long __must_check
9953 copy_to_user(void __user *to, const void *from, unsigned long size)
9954 {
9955 - unsigned long ret = ___copy_to_user(to, from, size);
9956 + unsigned long ret;
9957
9958 + if ((long)size < 0 || size > INT_MAX)
9959 + return size;
9960 +
9961 + if (!__builtin_constant_p(size))
9962 + check_object_size(from, size, true);
9963 +
9964 + ret = ___copy_to_user(to, from, size);
9965 if (unlikely(ret))
9966 ret = copy_to_user_fixup(to, from, size);
9967 return ret;
9968 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9969 index d15cc17..d0ae796 100644
9970 --- a/arch/sparc/kernel/Makefile
9971 +++ b/arch/sparc/kernel/Makefile
9972 @@ -4,7 +4,7 @@
9973 #
9974
9975 asflags-y := -ansi
9976 -ccflags-y := -Werror
9977 +#ccflags-y := -Werror
9978
9979 extra-y := head_$(BITS).o
9980
9981 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9982 index 510baec..9ff2607 100644
9983 --- a/arch/sparc/kernel/process_32.c
9984 +++ b/arch/sparc/kernel/process_32.c
9985 @@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
9986
9987 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9988 r->psr, r->pc, r->npc, r->y, print_tainted());
9989 - printk("PC: <%pS>\n", (void *) r->pc);
9990 + printk("PC: <%pA>\n", (void *) r->pc);
9991 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9992 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9993 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9994 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9995 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9996 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9997 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9998 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9999
10000 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10001 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10002 @@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10003 rw = (struct reg_window32 *) fp;
10004 pc = rw->ins[7];
10005 printk("[%08lx : ", pc);
10006 - printk("%pS ] ", (void *) pc);
10007 + printk("%pA ] ", (void *) pc);
10008 fp = rw->ins[6];
10009 } while (++count < 16);
10010 printk("\n");
10011 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10012 index d7b4967..2edf827 100644
10013 --- a/arch/sparc/kernel/process_64.c
10014 +++ b/arch/sparc/kernel/process_64.c
10015 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10016 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10017 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10018 if (regs->tstate & TSTATE_PRIV)
10019 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10020 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10021 }
10022
10023 void show_regs(struct pt_regs *regs)
10024 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10025
10026 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10027 regs->tpc, regs->tnpc, regs->y, print_tainted());
10028 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10029 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10030 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10031 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10032 regs->u_regs[3]);
10033 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10034 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10035 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10036 regs->u_regs[15]);
10037 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10038 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10039 show_regwindow(regs);
10040 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10041 }
10042 @@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10043 ((tp && tp->task) ? tp->task->pid : -1));
10044
10045 if (gp->tstate & TSTATE_PRIV) {
10046 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10047 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10048 (void *) gp->tpc,
10049 (void *) gp->o7,
10050 (void *) gp->i7,
10051 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10052 index 79cc0d1..ec62734 100644
10053 --- a/arch/sparc/kernel/prom_common.c
10054 +++ b/arch/sparc/kernel/prom_common.c
10055 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10056
10057 unsigned int prom_early_allocated __initdata;
10058
10059 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10060 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10061 .nextprop = prom_common_nextprop,
10062 .getproplen = prom_getproplen,
10063 .getproperty = prom_getproperty,
10064 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10065 index c13c9f2..d572c34 100644
10066 --- a/arch/sparc/kernel/ptrace_64.c
10067 +++ b/arch/sparc/kernel/ptrace_64.c
10068 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10069 return ret;
10070 }
10071
10072 +#ifdef CONFIG_GRKERNSEC_SETXID
10073 +extern void gr_delayed_cred_worker(void);
10074 +#endif
10075 +
10076 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10077 {
10078 int ret = 0;
10079 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10080 if (test_thread_flag(TIF_NOHZ))
10081 user_exit();
10082
10083 +#ifdef CONFIG_GRKERNSEC_SETXID
10084 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10085 + gr_delayed_cred_worker();
10086 +#endif
10087 +
10088 if (test_thread_flag(TIF_SYSCALL_TRACE))
10089 ret = tracehook_report_syscall_entry(regs);
10090
10091 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10092 if (test_thread_flag(TIF_NOHZ))
10093 user_exit();
10094
10095 +#ifdef CONFIG_GRKERNSEC_SETXID
10096 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10097 + gr_delayed_cred_worker();
10098 +#endif
10099 +
10100 audit_syscall_exit(regs);
10101
10102 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10103 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10104 index b085311..6f885f7 100644
10105 --- a/arch/sparc/kernel/smp_64.c
10106 +++ b/arch/sparc/kernel/smp_64.c
10107 @@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10108 extern unsigned long xcall_flush_dcache_page_spitfire;
10109
10110 #ifdef CONFIG_DEBUG_DCFLUSH
10111 -extern atomic_t dcpage_flushes;
10112 -extern atomic_t dcpage_flushes_xcall;
10113 +extern atomic_unchecked_t dcpage_flushes;
10114 +extern atomic_unchecked_t dcpage_flushes_xcall;
10115 #endif
10116
10117 static inline void __local_flush_dcache_page(struct page *page)
10118 @@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10119 return;
10120
10121 #ifdef CONFIG_DEBUG_DCFLUSH
10122 - atomic_inc(&dcpage_flushes);
10123 + atomic_inc_unchecked(&dcpage_flushes);
10124 #endif
10125
10126 this_cpu = get_cpu();
10127 @@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10128 xcall_deliver(data0, __pa(pg_addr),
10129 (u64) pg_addr, cpumask_of(cpu));
10130 #ifdef CONFIG_DEBUG_DCFLUSH
10131 - atomic_inc(&dcpage_flushes_xcall);
10132 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10133 #endif
10134 }
10135 }
10136 @@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10137 preempt_disable();
10138
10139 #ifdef CONFIG_DEBUG_DCFLUSH
10140 - atomic_inc(&dcpage_flushes);
10141 + atomic_inc_unchecked(&dcpage_flushes);
10142 #endif
10143 data0 = 0;
10144 pg_addr = page_address(page);
10145 @@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10146 xcall_deliver(data0, __pa(pg_addr),
10147 (u64) pg_addr, cpu_online_mask);
10148 #ifdef CONFIG_DEBUG_DCFLUSH
10149 - atomic_inc(&dcpage_flushes_xcall);
10150 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10151 #endif
10152 }
10153 __local_flush_dcache_page(page);
10154 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10155 index 3a8d184..49498a8 100644
10156 --- a/arch/sparc/kernel/sys_sparc_32.c
10157 +++ b/arch/sparc/kernel/sys_sparc_32.c
10158 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10159 if (len > TASK_SIZE - PAGE_SIZE)
10160 return -ENOMEM;
10161 if (!addr)
10162 - addr = TASK_UNMAPPED_BASE;
10163 + addr = current->mm->mmap_base;
10164
10165 info.flags = 0;
10166 info.length = len;
10167 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10168 index beb0b5a..5a153f7 100644
10169 --- a/arch/sparc/kernel/sys_sparc_64.c
10170 +++ b/arch/sparc/kernel/sys_sparc_64.c
10171 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10172 struct vm_area_struct * vma;
10173 unsigned long task_size = TASK_SIZE;
10174 int do_color_align;
10175 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10176 struct vm_unmapped_area_info info;
10177
10178 if (flags & MAP_FIXED) {
10179 /* We do not accept a shared mapping if it would violate
10180 * cache aliasing constraints.
10181 */
10182 - if ((flags & MAP_SHARED) &&
10183 + if ((filp || (flags & MAP_SHARED)) &&
10184 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10185 return -EINVAL;
10186 return addr;
10187 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10188 if (filp || (flags & MAP_SHARED))
10189 do_color_align = 1;
10190
10191 +#ifdef CONFIG_PAX_RANDMMAP
10192 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10193 +#endif
10194 +
10195 if (addr) {
10196 if (do_color_align)
10197 addr = COLOR_ALIGN(addr, pgoff);
10198 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10199 addr = PAGE_ALIGN(addr);
10200
10201 vma = find_vma(mm, addr);
10202 - if (task_size - len >= addr &&
10203 - (!vma || addr + len <= vma->vm_start))
10204 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10205 return addr;
10206 }
10207
10208 info.flags = 0;
10209 info.length = len;
10210 - info.low_limit = TASK_UNMAPPED_BASE;
10211 + info.low_limit = mm->mmap_base;
10212 info.high_limit = min(task_size, VA_EXCLUDE_START);
10213 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10214 info.align_offset = pgoff << PAGE_SHIFT;
10215 + info.threadstack_offset = offset;
10216 addr = vm_unmapped_area(&info);
10217
10218 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10219 VM_BUG_ON(addr != -ENOMEM);
10220 info.low_limit = VA_EXCLUDE_END;
10221 +
10222 +#ifdef CONFIG_PAX_RANDMMAP
10223 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10224 + info.low_limit += mm->delta_mmap;
10225 +#endif
10226 +
10227 info.high_limit = task_size;
10228 addr = vm_unmapped_area(&info);
10229 }
10230 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10231 unsigned long task_size = STACK_TOP32;
10232 unsigned long addr = addr0;
10233 int do_color_align;
10234 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10235 struct vm_unmapped_area_info info;
10236
10237 /* This should only ever run for 32-bit processes. */
10238 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10239 /* We do not accept a shared mapping if it would violate
10240 * cache aliasing constraints.
10241 */
10242 - if ((flags & MAP_SHARED) &&
10243 + if ((filp || (flags & MAP_SHARED)) &&
10244 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10245 return -EINVAL;
10246 return addr;
10247 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10248 if (filp || (flags & MAP_SHARED))
10249 do_color_align = 1;
10250
10251 +#ifdef CONFIG_PAX_RANDMMAP
10252 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10253 +#endif
10254 +
10255 /* requesting a specific address */
10256 if (addr) {
10257 if (do_color_align)
10258 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10259 addr = PAGE_ALIGN(addr);
10260
10261 vma = find_vma(mm, addr);
10262 - if (task_size - len >= addr &&
10263 - (!vma || addr + len <= vma->vm_start))
10264 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10265 return addr;
10266 }
10267
10268 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10269 info.high_limit = mm->mmap_base;
10270 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10271 info.align_offset = pgoff << PAGE_SHIFT;
10272 + info.threadstack_offset = offset;
10273 addr = vm_unmapped_area(&info);
10274
10275 /*
10276 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10277 VM_BUG_ON(addr != -ENOMEM);
10278 info.flags = 0;
10279 info.low_limit = TASK_UNMAPPED_BASE;
10280 +
10281 +#ifdef CONFIG_PAX_RANDMMAP
10282 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10283 + info.low_limit += mm->delta_mmap;
10284 +#endif
10285 +
10286 info.high_limit = STACK_TOP32;
10287 addr = vm_unmapped_area(&info);
10288 }
10289 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10290 EXPORT_SYMBOL(get_fb_unmapped_area);
10291
10292 /* Essentially the same as PowerPC. */
10293 -static unsigned long mmap_rnd(void)
10294 +static unsigned long mmap_rnd(struct mm_struct *mm)
10295 {
10296 unsigned long rnd = 0UL;
10297
10298 +#ifdef CONFIG_PAX_RANDMMAP
10299 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10300 +#endif
10301 +
10302 if (current->flags & PF_RANDOMIZE) {
10303 unsigned long val = get_random_int();
10304 if (test_thread_flag(TIF_32BIT))
10305 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10306
10307 void arch_pick_mmap_layout(struct mm_struct *mm)
10308 {
10309 - unsigned long random_factor = mmap_rnd();
10310 + unsigned long random_factor = mmap_rnd(mm);
10311 unsigned long gap;
10312
10313 /*
10314 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10315 gap == RLIM_INFINITY ||
10316 sysctl_legacy_va_layout) {
10317 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10318 +
10319 +#ifdef CONFIG_PAX_RANDMMAP
10320 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10321 + mm->mmap_base += mm->delta_mmap;
10322 +#endif
10323 +
10324 mm->get_unmapped_area = arch_get_unmapped_area;
10325 } else {
10326 /* We know it's 32-bit */
10327 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10328 gap = (task_size / 6 * 5);
10329
10330 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10331 +
10332 +#ifdef CONFIG_PAX_RANDMMAP
10333 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10334 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10335 +#endif
10336 +
10337 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10338 }
10339 }
10340 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10341 index 33a17e7..d87fb1f 100644
10342 --- a/arch/sparc/kernel/syscalls.S
10343 +++ b/arch/sparc/kernel/syscalls.S
10344 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10345 #endif
10346 .align 32
10347 1: ldx [%g6 + TI_FLAGS], %l5
10348 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10349 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10350 be,pt %icc, rtrap
10351 nop
10352 call syscall_trace_leave
10353 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10354
10355 srl %i3, 0, %o3 ! IEU0
10356 srl %i2, 0, %o2 ! IEU0 Group
10357 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10358 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10359 bne,pn %icc, linux_syscall_trace32 ! CTI
10360 mov %i0, %l5 ! IEU1
10361 5: call %l7 ! CTI Group brk forced
10362 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10363
10364 mov %i3, %o3 ! IEU1
10365 mov %i4, %o4 ! IEU0 Group
10366 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10367 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10368 bne,pn %icc, linux_syscall_trace ! CTI Group
10369 mov %i0, %l5 ! IEU0
10370 2: call %l7 ! CTI Group brk forced
10371 @@ -223,7 +223,7 @@ ret_sys_call:
10372
10373 cmp %o0, -ERESTART_RESTARTBLOCK
10374 bgeu,pn %xcc, 1f
10375 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10376 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10377 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10378
10379 2:
10380 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10381 index 6629829..036032d 100644
10382 --- a/arch/sparc/kernel/traps_32.c
10383 +++ b/arch/sparc/kernel/traps_32.c
10384 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10385 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10386 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10387
10388 +extern void gr_handle_kernel_exploit(void);
10389 +
10390 void die_if_kernel(char *str, struct pt_regs *regs)
10391 {
10392 static int die_counter;
10393 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10394 count++ < 30 &&
10395 (((unsigned long) rw) >= PAGE_OFFSET) &&
10396 !(((unsigned long) rw) & 0x7)) {
10397 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10398 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10399 (void *) rw->ins[7]);
10400 rw = (struct reg_window32 *)rw->ins[6];
10401 }
10402 }
10403 printk("Instruction DUMP:");
10404 instruction_dump ((unsigned long *) regs->pc);
10405 - if(regs->psr & PSR_PS)
10406 + if(regs->psr & PSR_PS) {
10407 + gr_handle_kernel_exploit();
10408 do_exit(SIGKILL);
10409 + }
10410 do_exit(SIGSEGV);
10411 }
10412
10413 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10414 index 4ced92f..965eeed 100644
10415 --- a/arch/sparc/kernel/traps_64.c
10416 +++ b/arch/sparc/kernel/traps_64.c
10417 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10418 i + 1,
10419 p->trapstack[i].tstate, p->trapstack[i].tpc,
10420 p->trapstack[i].tnpc, p->trapstack[i].tt);
10421 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10422 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10423 }
10424 }
10425
10426 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10427
10428 lvl -= 0x100;
10429 if (regs->tstate & TSTATE_PRIV) {
10430 +
10431 +#ifdef CONFIG_PAX_REFCOUNT
10432 + if (lvl == 6)
10433 + pax_report_refcount_overflow(regs);
10434 +#endif
10435 +
10436 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10437 die_if_kernel(buffer, regs);
10438 }
10439 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10440 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10441 {
10442 char buffer[32];
10443 -
10444 +
10445 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10446 0, lvl, SIGTRAP) == NOTIFY_STOP)
10447 return;
10448
10449 +#ifdef CONFIG_PAX_REFCOUNT
10450 + if (lvl == 6)
10451 + pax_report_refcount_overflow(regs);
10452 +#endif
10453 +
10454 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10455
10456 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10457 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10458 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10459 printk("%s" "ERROR(%d): ",
10460 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10461 - printk("TPC<%pS>\n", (void *) regs->tpc);
10462 + printk("TPC<%pA>\n", (void *) regs->tpc);
10463 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10464 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10465 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10466 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10467 smp_processor_id(),
10468 (type & 0x1) ? 'I' : 'D',
10469 regs->tpc);
10470 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10471 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10472 panic("Irrecoverable Cheetah+ parity error.");
10473 }
10474
10475 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10476 smp_processor_id(),
10477 (type & 0x1) ? 'I' : 'D',
10478 regs->tpc);
10479 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10480 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10481 }
10482
10483 struct sun4v_error_entry {
10484 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10485 /*0x38*/u64 reserved_5;
10486 };
10487
10488 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10489 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10490 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10491 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10492
10493 static const char *sun4v_err_type_to_str(u8 type)
10494 {
10495 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10496 }
10497
10498 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10499 - int cpu, const char *pfx, atomic_t *ocnt)
10500 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10501 {
10502 u64 *raw_ptr = (u64 *) ent;
10503 u32 attrs;
10504 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10505
10506 show_regs(regs);
10507
10508 - if ((cnt = atomic_read(ocnt)) != 0) {
10509 - atomic_set(ocnt, 0);
10510 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10511 + atomic_set_unchecked(ocnt, 0);
10512 wmb();
10513 printk("%s: Queue overflowed %d times.\n",
10514 pfx, cnt);
10515 @@ -2046,7 +2057,7 @@ out:
10516 */
10517 void sun4v_resum_overflow(struct pt_regs *regs)
10518 {
10519 - atomic_inc(&sun4v_resum_oflow_cnt);
10520 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10521 }
10522
10523 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10524 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10525 /* XXX Actually even this can make not that much sense. Perhaps
10526 * XXX we should just pull the plug and panic directly from here?
10527 */
10528 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10529 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10530 }
10531
10532 unsigned long sun4v_err_itlb_vaddr;
10533 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10534
10535 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10536 regs->tpc, tl);
10537 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10538 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10539 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10540 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10541 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10542 (void *) regs->u_regs[UREG_I7]);
10543 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10544 "pte[%lx] error[%lx]\n",
10545 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10546
10547 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10548 regs->tpc, tl);
10549 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10550 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10551 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10552 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10553 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10554 (void *) regs->u_regs[UREG_I7]);
10555 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10556 "pte[%lx] error[%lx]\n",
10557 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10558 fp = (unsigned long)sf->fp + STACK_BIAS;
10559 }
10560
10561 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10562 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10563 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10564 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10565 int index = tsk->curr_ret_stack;
10566 if (tsk->ret_stack && index >= graph) {
10567 pc = tsk->ret_stack[index - graph].ret;
10568 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10569 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10570 graph++;
10571 }
10572 }
10573 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10574 return (struct reg_window *) (fp + STACK_BIAS);
10575 }
10576
10577 +extern void gr_handle_kernel_exploit(void);
10578 +
10579 void die_if_kernel(char *str, struct pt_regs *regs)
10580 {
10581 static int die_counter;
10582 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10583 while (rw &&
10584 count++ < 30 &&
10585 kstack_valid(tp, (unsigned long) rw)) {
10586 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10587 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10588 (void *) rw->ins[7]);
10589
10590 rw = kernel_stack_up(rw);
10591 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10592 }
10593 user_instruction_dump ((unsigned int __user *) regs->tpc);
10594 }
10595 - if (regs->tstate & TSTATE_PRIV)
10596 + if (regs->tstate & TSTATE_PRIV) {
10597 + gr_handle_kernel_exploit();
10598 do_exit(SIGKILL);
10599 + }
10600 do_exit(SIGSEGV);
10601 }
10602 EXPORT_SYMBOL(die_if_kernel);
10603 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10604 index 3c1a7cb..73e1923 100644
10605 --- a/arch/sparc/kernel/unaligned_64.c
10606 +++ b/arch/sparc/kernel/unaligned_64.c
10607 @@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10608 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10609
10610 if (__ratelimit(&ratelimit)) {
10611 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10612 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10613 regs->tpc, (void *) regs->tpc);
10614 }
10615 }
10616 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10617 index dbe119b..089c7c1 100644
10618 --- a/arch/sparc/lib/Makefile
10619 +++ b/arch/sparc/lib/Makefile
10620 @@ -2,7 +2,7 @@
10621 #
10622
10623 asflags-y := -ansi -DST_DIV0=0x02
10624 -ccflags-y := -Werror
10625 +#ccflags-y := -Werror
10626
10627 lib-$(CONFIG_SPARC32) += ashrdi3.o
10628 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10629 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10630 index 85c233d..68500e0 100644
10631 --- a/arch/sparc/lib/atomic_64.S
10632 +++ b/arch/sparc/lib/atomic_64.S
10633 @@ -17,7 +17,12 @@
10634 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10635 BACKOFF_SETUP(%o2)
10636 1: lduw [%o1], %g1
10637 - add %g1, %o0, %g7
10638 + addcc %g1, %o0, %g7
10639 +
10640 +#ifdef CONFIG_PAX_REFCOUNT
10641 + tvs %icc, 6
10642 +#endif
10643 +
10644 cas [%o1], %g1, %g7
10645 cmp %g1, %g7
10646 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10647 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10648 2: BACKOFF_SPIN(%o2, %o3, 1b)
10649 ENDPROC(atomic_add)
10650
10651 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10652 + BACKOFF_SETUP(%o2)
10653 +1: lduw [%o1], %g1
10654 + add %g1, %o0, %g7
10655 + cas [%o1], %g1, %g7
10656 + cmp %g1, %g7
10657 + bne,pn %icc, 2f
10658 + nop
10659 + retl
10660 + nop
10661 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10662 +ENDPROC(atomic_add_unchecked)
10663 +
10664 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10665 BACKOFF_SETUP(%o2)
10666 1: lduw [%o1], %g1
10667 - sub %g1, %o0, %g7
10668 + subcc %g1, %o0, %g7
10669 +
10670 +#ifdef CONFIG_PAX_REFCOUNT
10671 + tvs %icc, 6
10672 +#endif
10673 +
10674 cas [%o1], %g1, %g7
10675 cmp %g1, %g7
10676 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10677 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10678 2: BACKOFF_SPIN(%o2, %o3, 1b)
10679 ENDPROC(atomic_sub)
10680
10681 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10682 + BACKOFF_SETUP(%o2)
10683 +1: lduw [%o1], %g1
10684 + sub %g1, %o0, %g7
10685 + cas [%o1], %g1, %g7
10686 + cmp %g1, %g7
10687 + bne,pn %icc, 2f
10688 + nop
10689 + retl
10690 + nop
10691 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10692 +ENDPROC(atomic_sub_unchecked)
10693 +
10694 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10695 BACKOFF_SETUP(%o2)
10696 1: lduw [%o1], %g1
10697 - add %g1, %o0, %g7
10698 + addcc %g1, %o0, %g7
10699 +
10700 +#ifdef CONFIG_PAX_REFCOUNT
10701 + tvs %icc, 6
10702 +#endif
10703 +
10704 cas [%o1], %g1, %g7
10705 cmp %g1, %g7
10706 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10707 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10708 2: BACKOFF_SPIN(%o2, %o3, 1b)
10709 ENDPROC(atomic_add_ret)
10710
10711 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10712 + BACKOFF_SETUP(%o2)
10713 +1: lduw [%o1], %g1
10714 + addcc %g1, %o0, %g7
10715 + cas [%o1], %g1, %g7
10716 + cmp %g1, %g7
10717 + bne,pn %icc, 2f
10718 + add %g7, %o0, %g7
10719 + sra %g7, 0, %o0
10720 + retl
10721 + nop
10722 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10723 +ENDPROC(atomic_add_ret_unchecked)
10724 +
10725 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10726 BACKOFF_SETUP(%o2)
10727 1: lduw [%o1], %g1
10728 - sub %g1, %o0, %g7
10729 + subcc %g1, %o0, %g7
10730 +
10731 +#ifdef CONFIG_PAX_REFCOUNT
10732 + tvs %icc, 6
10733 +#endif
10734 +
10735 cas [%o1], %g1, %g7
10736 cmp %g1, %g7
10737 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10738 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10739 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10740 BACKOFF_SETUP(%o2)
10741 1: ldx [%o1], %g1
10742 - add %g1, %o0, %g7
10743 + addcc %g1, %o0, %g7
10744 +
10745 +#ifdef CONFIG_PAX_REFCOUNT
10746 + tvs %xcc, 6
10747 +#endif
10748 +
10749 casx [%o1], %g1, %g7
10750 cmp %g1, %g7
10751 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10752 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10753 2: BACKOFF_SPIN(%o2, %o3, 1b)
10754 ENDPROC(atomic64_add)
10755
10756 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10757 + BACKOFF_SETUP(%o2)
10758 +1: ldx [%o1], %g1
10759 + addcc %g1, %o0, %g7
10760 + casx [%o1], %g1, %g7
10761 + cmp %g1, %g7
10762 + bne,pn %xcc, 2f
10763 + nop
10764 + retl
10765 + nop
10766 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10767 +ENDPROC(atomic64_add_unchecked)
10768 +
10769 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10770 BACKOFF_SETUP(%o2)
10771 1: ldx [%o1], %g1
10772 - sub %g1, %o0, %g7
10773 + subcc %g1, %o0, %g7
10774 +
10775 +#ifdef CONFIG_PAX_REFCOUNT
10776 + tvs %xcc, 6
10777 +#endif
10778 +
10779 casx [%o1], %g1, %g7
10780 cmp %g1, %g7
10781 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10782 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10783 2: BACKOFF_SPIN(%o2, %o3, 1b)
10784 ENDPROC(atomic64_sub)
10785
10786 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10787 + BACKOFF_SETUP(%o2)
10788 +1: ldx [%o1], %g1
10789 + subcc %g1, %o0, %g7
10790 + casx [%o1], %g1, %g7
10791 + cmp %g1, %g7
10792 + bne,pn %xcc, 2f
10793 + nop
10794 + retl
10795 + nop
10796 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10797 +ENDPROC(atomic64_sub_unchecked)
10798 +
10799 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10800 BACKOFF_SETUP(%o2)
10801 1: ldx [%o1], %g1
10802 - add %g1, %o0, %g7
10803 + addcc %g1, %o0, %g7
10804 +
10805 +#ifdef CONFIG_PAX_REFCOUNT
10806 + tvs %xcc, 6
10807 +#endif
10808 +
10809 casx [%o1], %g1, %g7
10810 cmp %g1, %g7
10811 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10812 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10813 2: BACKOFF_SPIN(%o2, %o3, 1b)
10814 ENDPROC(atomic64_add_ret)
10815
10816 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10817 + BACKOFF_SETUP(%o2)
10818 +1: ldx [%o1], %g1
10819 + addcc %g1, %o0, %g7
10820 + casx [%o1], %g1, %g7
10821 + cmp %g1, %g7
10822 + bne,pn %xcc, 2f
10823 + add %g7, %o0, %g7
10824 + mov %g7, %o0
10825 + retl
10826 + nop
10827 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10828 +ENDPROC(atomic64_add_ret_unchecked)
10829 +
10830 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10831 BACKOFF_SETUP(%o2)
10832 1: ldx [%o1], %g1
10833 - sub %g1, %o0, %g7
10834 + subcc %g1, %o0, %g7
10835 +
10836 +#ifdef CONFIG_PAX_REFCOUNT
10837 + tvs %xcc, 6
10838 +#endif
10839 +
10840 casx [%o1], %g1, %g7
10841 cmp %g1, %g7
10842 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10843 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10844 index 323335b..ed85ea2 100644
10845 --- a/arch/sparc/lib/ksyms.c
10846 +++ b/arch/sparc/lib/ksyms.c
10847 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10848
10849 /* Atomic counter implementation. */
10850 EXPORT_SYMBOL(atomic_add);
10851 +EXPORT_SYMBOL(atomic_add_unchecked);
10852 EXPORT_SYMBOL(atomic_add_ret);
10853 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
10854 EXPORT_SYMBOL(atomic_sub);
10855 +EXPORT_SYMBOL(atomic_sub_unchecked);
10856 EXPORT_SYMBOL(atomic_sub_ret);
10857 EXPORT_SYMBOL(atomic64_add);
10858 +EXPORT_SYMBOL(atomic64_add_unchecked);
10859 EXPORT_SYMBOL(atomic64_add_ret);
10860 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10861 EXPORT_SYMBOL(atomic64_sub);
10862 +EXPORT_SYMBOL(atomic64_sub_unchecked);
10863 EXPORT_SYMBOL(atomic64_sub_ret);
10864 EXPORT_SYMBOL(atomic64_dec_if_positive);
10865
10866 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10867 index 30c3ecc..736f015 100644
10868 --- a/arch/sparc/mm/Makefile
10869 +++ b/arch/sparc/mm/Makefile
10870 @@ -2,7 +2,7 @@
10871 #
10872
10873 asflags-y := -ansi
10874 -ccflags-y := -Werror
10875 +#ccflags-y := -Werror
10876
10877 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10878 obj-y += fault_$(BITS).o
10879 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10880 index 59dbd46..1dd7f5e 100644
10881 --- a/arch/sparc/mm/fault_32.c
10882 +++ b/arch/sparc/mm/fault_32.c
10883 @@ -21,6 +21,9 @@
10884 #include <linux/perf_event.h>
10885 #include <linux/interrupt.h>
10886 #include <linux/kdebug.h>
10887 +#include <linux/slab.h>
10888 +#include <linux/pagemap.h>
10889 +#include <linux/compiler.h>
10890
10891 #include <asm/page.h>
10892 #include <asm/pgtable.h>
10893 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10894 return safe_compute_effective_address(regs, insn);
10895 }
10896
10897 +#ifdef CONFIG_PAX_PAGEEXEC
10898 +#ifdef CONFIG_PAX_DLRESOLVE
10899 +static void pax_emuplt_close(struct vm_area_struct *vma)
10900 +{
10901 + vma->vm_mm->call_dl_resolve = 0UL;
10902 +}
10903 +
10904 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10905 +{
10906 + unsigned int *kaddr;
10907 +
10908 + vmf->page = alloc_page(GFP_HIGHUSER);
10909 + if (!vmf->page)
10910 + return VM_FAULT_OOM;
10911 +
10912 + kaddr = kmap(vmf->page);
10913 + memset(kaddr, 0, PAGE_SIZE);
10914 + kaddr[0] = 0x9DE3BFA8U; /* save */
10915 + flush_dcache_page(vmf->page);
10916 + kunmap(vmf->page);
10917 + return VM_FAULT_MAJOR;
10918 +}
10919 +
10920 +static const struct vm_operations_struct pax_vm_ops = {
10921 + .close = pax_emuplt_close,
10922 + .fault = pax_emuplt_fault
10923 +};
10924 +
10925 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10926 +{
10927 + int ret;
10928 +
10929 + INIT_LIST_HEAD(&vma->anon_vma_chain);
10930 + vma->vm_mm = current->mm;
10931 + vma->vm_start = addr;
10932 + vma->vm_end = addr + PAGE_SIZE;
10933 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10934 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10935 + vma->vm_ops = &pax_vm_ops;
10936 +
10937 + ret = insert_vm_struct(current->mm, vma);
10938 + if (ret)
10939 + return ret;
10940 +
10941 + ++current->mm->total_vm;
10942 + return 0;
10943 +}
10944 +#endif
10945 +
10946 +/*
10947 + * PaX: decide what to do with offenders (regs->pc = fault address)
10948 + *
10949 + * returns 1 when task should be killed
10950 + * 2 when patched PLT trampoline was detected
10951 + * 3 when unpatched PLT trampoline was detected
10952 + */
10953 +static int pax_handle_fetch_fault(struct pt_regs *regs)
10954 +{
10955 +
10956 +#ifdef CONFIG_PAX_EMUPLT
10957 + int err;
10958 +
10959 + do { /* PaX: patched PLT emulation #1 */
10960 + unsigned int sethi1, sethi2, jmpl;
10961 +
10962 + err = get_user(sethi1, (unsigned int *)regs->pc);
10963 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10964 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10965 +
10966 + if (err)
10967 + break;
10968 +
10969 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10970 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
10971 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
10972 + {
10973 + unsigned int addr;
10974 +
10975 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10976 + addr = regs->u_regs[UREG_G1];
10977 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10978 + regs->pc = addr;
10979 + regs->npc = addr+4;
10980 + return 2;
10981 + }
10982 + } while (0);
10983 +
10984 + do { /* PaX: patched PLT emulation #2 */
10985 + unsigned int ba;
10986 +
10987 + err = get_user(ba, (unsigned int *)regs->pc);
10988 +
10989 + if (err)
10990 + break;
10991 +
10992 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10993 + unsigned int addr;
10994 +
10995 + if ((ba & 0xFFC00000U) == 0x30800000U)
10996 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10997 + else
10998 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10999 + regs->pc = addr;
11000 + regs->npc = addr+4;
11001 + return 2;
11002 + }
11003 + } while (0);
11004 +
11005 + do { /* PaX: patched PLT emulation #3 */
11006 + unsigned int sethi, bajmpl, nop;
11007 +
11008 + err = get_user(sethi, (unsigned int *)regs->pc);
11009 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11010 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11011 +
11012 + if (err)
11013 + break;
11014 +
11015 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11016 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11017 + nop == 0x01000000U)
11018 + {
11019 + unsigned int addr;
11020 +
11021 + addr = (sethi & 0x003FFFFFU) << 10;
11022 + regs->u_regs[UREG_G1] = addr;
11023 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11024 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11025 + else
11026 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11027 + regs->pc = addr;
11028 + regs->npc = addr+4;
11029 + return 2;
11030 + }
11031 + } while (0);
11032 +
11033 + do { /* PaX: unpatched PLT emulation step 1 */
11034 + unsigned int sethi, ba, nop;
11035 +
11036 + err = get_user(sethi, (unsigned int *)regs->pc);
11037 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11038 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11039 +
11040 + if (err)
11041 + break;
11042 +
11043 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11044 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11045 + nop == 0x01000000U)
11046 + {
11047 + unsigned int addr, save, call;
11048 +
11049 + if ((ba & 0xFFC00000U) == 0x30800000U)
11050 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11051 + else
11052 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11053 +
11054 + err = get_user(save, (unsigned int *)addr);
11055 + err |= get_user(call, (unsigned int *)(addr+4));
11056 + err |= get_user(nop, (unsigned int *)(addr+8));
11057 + if (err)
11058 + break;
11059 +
11060 +#ifdef CONFIG_PAX_DLRESOLVE
11061 + if (save == 0x9DE3BFA8U &&
11062 + (call & 0xC0000000U) == 0x40000000U &&
11063 + nop == 0x01000000U)
11064 + {
11065 + struct vm_area_struct *vma;
11066 + unsigned long call_dl_resolve;
11067 +
11068 + down_read(&current->mm->mmap_sem);
11069 + call_dl_resolve = current->mm->call_dl_resolve;
11070 + up_read(&current->mm->mmap_sem);
11071 + if (likely(call_dl_resolve))
11072 + goto emulate;
11073 +
11074 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11075 +
11076 + down_write(&current->mm->mmap_sem);
11077 + if (current->mm->call_dl_resolve) {
11078 + call_dl_resolve = current->mm->call_dl_resolve;
11079 + up_write(&current->mm->mmap_sem);
11080 + if (vma)
11081 + kmem_cache_free(vm_area_cachep, vma);
11082 + goto emulate;
11083 + }
11084 +
11085 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11086 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11087 + up_write(&current->mm->mmap_sem);
11088 + if (vma)
11089 + kmem_cache_free(vm_area_cachep, vma);
11090 + return 1;
11091 + }
11092 +
11093 + if (pax_insert_vma(vma, call_dl_resolve)) {
11094 + up_write(&current->mm->mmap_sem);
11095 + kmem_cache_free(vm_area_cachep, vma);
11096 + return 1;
11097 + }
11098 +
11099 + current->mm->call_dl_resolve = call_dl_resolve;
11100 + up_write(&current->mm->mmap_sem);
11101 +
11102 +emulate:
11103 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11104 + regs->pc = call_dl_resolve;
11105 + regs->npc = addr+4;
11106 + return 3;
11107 + }
11108 +#endif
11109 +
11110 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11111 + if ((save & 0xFFC00000U) == 0x05000000U &&
11112 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11113 + nop == 0x01000000U)
11114 + {
11115 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11116 + regs->u_regs[UREG_G2] = addr + 4;
11117 + addr = (save & 0x003FFFFFU) << 10;
11118 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11119 + regs->pc = addr;
11120 + regs->npc = addr+4;
11121 + return 3;
11122 + }
11123 + }
11124 + } while (0);
11125 +
11126 + do { /* PaX: unpatched PLT emulation step 2 */
11127 + unsigned int save, call, nop;
11128 +
11129 + err = get_user(save, (unsigned int *)(regs->pc-4));
11130 + err |= get_user(call, (unsigned int *)regs->pc);
11131 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11132 + if (err)
11133 + break;
11134 +
11135 + if (save == 0x9DE3BFA8U &&
11136 + (call & 0xC0000000U) == 0x40000000U &&
11137 + nop == 0x01000000U)
11138 + {
11139 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11140 +
11141 + regs->u_regs[UREG_RETPC] = regs->pc;
11142 + regs->pc = dl_resolve;
11143 + regs->npc = dl_resolve+4;
11144 + return 3;
11145 + }
11146 + } while (0);
11147 +#endif
11148 +
11149 + return 1;
11150 +}
11151 +
11152 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11153 +{
11154 + unsigned long i;
11155 +
11156 + printk(KERN_ERR "PAX: bytes at PC: ");
11157 + for (i = 0; i < 8; i++) {
11158 + unsigned int c;
11159 + if (get_user(c, (unsigned int *)pc+i))
11160 + printk(KERN_CONT "???????? ");
11161 + else
11162 + printk(KERN_CONT "%08x ", c);
11163 + }
11164 + printk("\n");
11165 +}
11166 +#endif
11167 +
11168 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11169 int text_fault)
11170 {
11171 @@ -229,6 +503,24 @@ good_area:
11172 if (!(vma->vm_flags & VM_WRITE))
11173 goto bad_area;
11174 } else {
11175 +
11176 +#ifdef CONFIG_PAX_PAGEEXEC
11177 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11178 + up_read(&mm->mmap_sem);
11179 + switch (pax_handle_fetch_fault(regs)) {
11180 +
11181 +#ifdef CONFIG_PAX_EMUPLT
11182 + case 2:
11183 + case 3:
11184 + return;
11185 +#endif
11186 +
11187 + }
11188 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11189 + do_group_exit(SIGKILL);
11190 + }
11191 +#endif
11192 +
11193 /* Allow reads even for write-only mappings */
11194 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11195 goto bad_area;
11196 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11197 index 69bb818..6ca35c8 100644
11198 --- a/arch/sparc/mm/fault_64.c
11199 +++ b/arch/sparc/mm/fault_64.c
11200 @@ -22,6 +22,9 @@
11201 #include <linux/kdebug.h>
11202 #include <linux/percpu.h>
11203 #include <linux/context_tracking.h>
11204 +#include <linux/slab.h>
11205 +#include <linux/pagemap.h>
11206 +#include <linux/compiler.h>
11207
11208 #include <asm/page.h>
11209 #include <asm/pgtable.h>
11210 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11211 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11212 regs->tpc);
11213 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11214 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11215 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11216 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11217 dump_stack();
11218 unhandled_fault(regs->tpc, current, regs);
11219 @@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11220 show_regs(regs);
11221 }
11222
11223 +#ifdef CONFIG_PAX_PAGEEXEC
11224 +#ifdef CONFIG_PAX_DLRESOLVE
11225 +static void pax_emuplt_close(struct vm_area_struct *vma)
11226 +{
11227 + vma->vm_mm->call_dl_resolve = 0UL;
11228 +}
11229 +
11230 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11231 +{
11232 + unsigned int *kaddr;
11233 +
11234 + vmf->page = alloc_page(GFP_HIGHUSER);
11235 + if (!vmf->page)
11236 + return VM_FAULT_OOM;
11237 +
11238 + kaddr = kmap(vmf->page);
11239 + memset(kaddr, 0, PAGE_SIZE);
11240 + kaddr[0] = 0x9DE3BFA8U; /* save */
11241 + flush_dcache_page(vmf->page);
11242 + kunmap(vmf->page);
11243 + return VM_FAULT_MAJOR;
11244 +}
11245 +
11246 +static const struct vm_operations_struct pax_vm_ops = {
11247 + .close = pax_emuplt_close,
11248 + .fault = pax_emuplt_fault
11249 +};
11250 +
11251 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11252 +{
11253 + int ret;
11254 +
11255 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11256 + vma->vm_mm = current->mm;
11257 + vma->vm_start = addr;
11258 + vma->vm_end = addr + PAGE_SIZE;
11259 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11260 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11261 + vma->vm_ops = &pax_vm_ops;
11262 +
11263 + ret = insert_vm_struct(current->mm, vma);
11264 + if (ret)
11265 + return ret;
11266 +
11267 + ++current->mm->total_vm;
11268 + return 0;
11269 +}
11270 +#endif
11271 +
11272 +/*
11273 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11274 + *
11275 + * returns 1 when task should be killed
11276 + * 2 when patched PLT trampoline was detected
11277 + * 3 when unpatched PLT trampoline was detected
11278 + */
11279 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11280 +{
11281 +
11282 +#ifdef CONFIG_PAX_EMUPLT
11283 + int err;
11284 +
11285 + do { /* PaX: patched PLT emulation #1 */
11286 + unsigned int sethi1, sethi2, jmpl;
11287 +
11288 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11289 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11290 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11291 +
11292 + if (err)
11293 + break;
11294 +
11295 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11296 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11297 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11298 + {
11299 + unsigned long addr;
11300 +
11301 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11302 + addr = regs->u_regs[UREG_G1];
11303 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11304 +
11305 + if (test_thread_flag(TIF_32BIT))
11306 + addr &= 0xFFFFFFFFUL;
11307 +
11308 + regs->tpc = addr;
11309 + regs->tnpc = addr+4;
11310 + return 2;
11311 + }
11312 + } while (0);
11313 +
11314 + do { /* PaX: patched PLT emulation #2 */
11315 + unsigned int ba;
11316 +
11317 + err = get_user(ba, (unsigned int *)regs->tpc);
11318 +
11319 + if (err)
11320 + break;
11321 +
11322 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11323 + unsigned long addr;
11324 +
11325 + if ((ba & 0xFFC00000U) == 0x30800000U)
11326 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11327 + else
11328 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11329 +
11330 + if (test_thread_flag(TIF_32BIT))
11331 + addr &= 0xFFFFFFFFUL;
11332 +
11333 + regs->tpc = addr;
11334 + regs->tnpc = addr+4;
11335 + return 2;
11336 + }
11337 + } while (0);
11338 +
11339 + do { /* PaX: patched PLT emulation #3 */
11340 + unsigned int sethi, bajmpl, nop;
11341 +
11342 + err = get_user(sethi, (unsigned int *)regs->tpc);
11343 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11344 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11345 +
11346 + if (err)
11347 + break;
11348 +
11349 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11350 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11351 + nop == 0x01000000U)
11352 + {
11353 + unsigned long addr;
11354 +
11355 + addr = (sethi & 0x003FFFFFU) << 10;
11356 + regs->u_regs[UREG_G1] = addr;
11357 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11358 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11359 + else
11360 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11361 +
11362 + if (test_thread_flag(TIF_32BIT))
11363 + addr &= 0xFFFFFFFFUL;
11364 +
11365 + regs->tpc = addr;
11366 + regs->tnpc = addr+4;
11367 + return 2;
11368 + }
11369 + } while (0);
11370 +
11371 + do { /* PaX: patched PLT emulation #4 */
11372 + unsigned int sethi, mov1, call, mov2;
11373 +
11374 + err = get_user(sethi, (unsigned int *)regs->tpc);
11375 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11376 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11377 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11378 +
11379 + if (err)
11380 + break;
11381 +
11382 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11383 + mov1 == 0x8210000FU &&
11384 + (call & 0xC0000000U) == 0x40000000U &&
11385 + mov2 == 0x9E100001U)
11386 + {
11387 + unsigned long addr;
11388 +
11389 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11390 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11391 +
11392 + if (test_thread_flag(TIF_32BIT))
11393 + addr &= 0xFFFFFFFFUL;
11394 +
11395 + regs->tpc = addr;
11396 + regs->tnpc = addr+4;
11397 + return 2;
11398 + }
11399 + } while (0);
11400 +
11401 + do { /* PaX: patched PLT emulation #5 */
11402 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11403 +
11404 + err = get_user(sethi, (unsigned int *)regs->tpc);
11405 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11406 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11407 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11408 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11409 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11410 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11411 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11412 +
11413 + if (err)
11414 + break;
11415 +
11416 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11417 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11418 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11419 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11420 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11421 + sllx == 0x83287020U &&
11422 + jmpl == 0x81C04005U &&
11423 + nop == 0x01000000U)
11424 + {
11425 + unsigned long addr;
11426 +
11427 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11428 + regs->u_regs[UREG_G1] <<= 32;
11429 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11430 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11431 + regs->tpc = addr;
11432 + regs->tnpc = addr+4;
11433 + return 2;
11434 + }
11435 + } while (0);
11436 +
11437 + do { /* PaX: patched PLT emulation #6 */
11438 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11439 +
11440 + err = get_user(sethi, (unsigned int *)regs->tpc);
11441 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11442 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11443 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11444 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11445 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11446 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11447 +
11448 + if (err)
11449 + break;
11450 +
11451 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11452 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11453 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11454 + sllx == 0x83287020U &&
11455 + (or & 0xFFFFE000U) == 0x8A116000U &&
11456 + jmpl == 0x81C04005U &&
11457 + nop == 0x01000000U)
11458 + {
11459 + unsigned long addr;
11460 +
11461 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11462 + regs->u_regs[UREG_G1] <<= 32;
11463 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11464 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11465 + regs->tpc = addr;
11466 + regs->tnpc = addr+4;
11467 + return 2;
11468 + }
11469 + } while (0);
11470 +
11471 + do { /* PaX: unpatched PLT emulation step 1 */
11472 + unsigned int sethi, ba, nop;
11473 +
11474 + err = get_user(sethi, (unsigned int *)regs->tpc);
11475 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11476 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11477 +
11478 + if (err)
11479 + break;
11480 +
11481 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11482 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11483 + nop == 0x01000000U)
11484 + {
11485 + unsigned long addr;
11486 + unsigned int save, call;
11487 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11488 +
11489 + if ((ba & 0xFFC00000U) == 0x30800000U)
11490 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11491 + else
11492 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11493 +
11494 + if (test_thread_flag(TIF_32BIT))
11495 + addr &= 0xFFFFFFFFUL;
11496 +
11497 + err = get_user(save, (unsigned int *)addr);
11498 + err |= get_user(call, (unsigned int *)(addr+4));
11499 + err |= get_user(nop, (unsigned int *)(addr+8));
11500 + if (err)
11501 + break;
11502 +
11503 +#ifdef CONFIG_PAX_DLRESOLVE
11504 + if (save == 0x9DE3BFA8U &&
11505 + (call & 0xC0000000U) == 0x40000000U &&
11506 + nop == 0x01000000U)
11507 + {
11508 + struct vm_area_struct *vma;
11509 + unsigned long call_dl_resolve;
11510 +
11511 + down_read(&current->mm->mmap_sem);
11512 + call_dl_resolve = current->mm->call_dl_resolve;
11513 + up_read(&current->mm->mmap_sem);
11514 + if (likely(call_dl_resolve))
11515 + goto emulate;
11516 +
11517 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11518 +
11519 + down_write(&current->mm->mmap_sem);
11520 + if (current->mm->call_dl_resolve) {
11521 + call_dl_resolve = current->mm->call_dl_resolve;
11522 + up_write(&current->mm->mmap_sem);
11523 + if (vma)
11524 + kmem_cache_free(vm_area_cachep, vma);
11525 + goto emulate;
11526 + }
11527 +
11528 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11529 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11530 + up_write(&current->mm->mmap_sem);
11531 + if (vma)
11532 + kmem_cache_free(vm_area_cachep, vma);
11533 + return 1;
11534 + }
11535 +
11536 + if (pax_insert_vma(vma, call_dl_resolve)) {
11537 + up_write(&current->mm->mmap_sem);
11538 + kmem_cache_free(vm_area_cachep, vma);
11539 + return 1;
11540 + }
11541 +
11542 + current->mm->call_dl_resolve = call_dl_resolve;
11543 + up_write(&current->mm->mmap_sem);
11544 +
11545 +emulate:
11546 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11547 + regs->tpc = call_dl_resolve;
11548 + regs->tnpc = addr+4;
11549 + return 3;
11550 + }
11551 +#endif
11552 +
11553 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11554 + if ((save & 0xFFC00000U) == 0x05000000U &&
11555 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11556 + nop == 0x01000000U)
11557 + {
11558 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11559 + regs->u_regs[UREG_G2] = addr + 4;
11560 + addr = (save & 0x003FFFFFU) << 10;
11561 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11562 +
11563 + if (test_thread_flag(TIF_32BIT))
11564 + addr &= 0xFFFFFFFFUL;
11565 +
11566 + regs->tpc = addr;
11567 + regs->tnpc = addr+4;
11568 + return 3;
11569 + }
11570 +
11571 + /* PaX: 64-bit PLT stub */
11572 + err = get_user(sethi1, (unsigned int *)addr);
11573 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11574 + err |= get_user(or1, (unsigned int *)(addr+8));
11575 + err |= get_user(or2, (unsigned int *)(addr+12));
11576 + err |= get_user(sllx, (unsigned int *)(addr+16));
11577 + err |= get_user(add, (unsigned int *)(addr+20));
11578 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11579 + err |= get_user(nop, (unsigned int *)(addr+28));
11580 + if (err)
11581 + break;
11582 +
11583 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11584 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11585 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11586 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11587 + sllx == 0x89293020U &&
11588 + add == 0x8A010005U &&
11589 + jmpl == 0x89C14000U &&
11590 + nop == 0x01000000U)
11591 + {
11592 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11593 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11594 + regs->u_regs[UREG_G4] <<= 32;
11595 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11596 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11597 + regs->u_regs[UREG_G4] = addr + 24;
11598 + addr = regs->u_regs[UREG_G5];
11599 + regs->tpc = addr;
11600 + regs->tnpc = addr+4;
11601 + return 3;
11602 + }
11603 + }
11604 + } while (0);
11605 +
11606 +#ifdef CONFIG_PAX_DLRESOLVE
11607 + do { /* PaX: unpatched PLT emulation step 2 */
11608 + unsigned int save, call, nop;
11609 +
11610 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11611 + err |= get_user(call, (unsigned int *)regs->tpc);
11612 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11613 + if (err)
11614 + break;
11615 +
11616 + if (save == 0x9DE3BFA8U &&
11617 + (call & 0xC0000000U) == 0x40000000U &&
11618 + nop == 0x01000000U)
11619 + {
11620 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11621 +
11622 + if (test_thread_flag(TIF_32BIT))
11623 + dl_resolve &= 0xFFFFFFFFUL;
11624 +
11625 + regs->u_regs[UREG_RETPC] = regs->tpc;
11626 + regs->tpc = dl_resolve;
11627 + regs->tnpc = dl_resolve+4;
11628 + return 3;
11629 + }
11630 + } while (0);
11631 +#endif
11632 +
11633 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11634 + unsigned int sethi, ba, nop;
11635 +
11636 + err = get_user(sethi, (unsigned int *)regs->tpc);
11637 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11638 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11639 +
11640 + if (err)
11641 + break;
11642 +
11643 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11644 + (ba & 0xFFF00000U) == 0x30600000U &&
11645 + nop == 0x01000000U)
11646 + {
11647 + unsigned long addr;
11648 +
11649 + addr = (sethi & 0x003FFFFFU) << 10;
11650 + regs->u_regs[UREG_G1] = addr;
11651 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11652 +
11653 + if (test_thread_flag(TIF_32BIT))
11654 + addr &= 0xFFFFFFFFUL;
11655 +
11656 + regs->tpc = addr;
11657 + regs->tnpc = addr+4;
11658 + return 2;
11659 + }
11660 + } while (0);
11661 +
11662 +#endif
11663 +
11664 + return 1;
11665 +}
11666 +
11667 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11668 +{
11669 + unsigned long i;
11670 +
11671 + printk(KERN_ERR "PAX: bytes at PC: ");
11672 + for (i = 0; i < 8; i++) {
11673 + unsigned int c;
11674 + if (get_user(c, (unsigned int *)pc+i))
11675 + printk(KERN_CONT "???????? ");
11676 + else
11677 + printk(KERN_CONT "%08x ", c);
11678 + }
11679 + printk("\n");
11680 +}
11681 +#endif
11682 +
11683 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11684 {
11685 enum ctx_state prev_state = exception_enter();
11686 @@ -344,6 +807,29 @@ retry:
11687 if (!vma)
11688 goto bad_area;
11689
11690 +#ifdef CONFIG_PAX_PAGEEXEC
11691 + /* PaX: detect ITLB misses on non-exec pages */
11692 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11693 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11694 + {
11695 + if (address != regs->tpc)
11696 + goto good_area;
11697 +
11698 + up_read(&mm->mmap_sem);
11699 + switch (pax_handle_fetch_fault(regs)) {
11700 +
11701 +#ifdef CONFIG_PAX_EMUPLT
11702 + case 2:
11703 + case 3:
11704 + return;
11705 +#endif
11706 +
11707 + }
11708 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11709 + do_group_exit(SIGKILL);
11710 + }
11711 +#endif
11712 +
11713 /* Pure DTLB misses do not tell us whether the fault causing
11714 * load/store/atomic was a write or not, it only says that there
11715 * was no match. So in such a case we (carefully) read the
11716 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11717 index 9bd9ce8..a502d99 100644
11718 --- a/arch/sparc/mm/hugetlbpage.c
11719 +++ b/arch/sparc/mm/hugetlbpage.c
11720 @@ -25,7 +25,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11721 unsigned long addr,
11722 unsigned long len,
11723 unsigned long pgoff,
11724 - unsigned long flags)
11725 + unsigned long flags,
11726 + unsigned long offset)
11727 {
11728 unsigned long task_size = TASK_SIZE;
11729 struct vm_unmapped_area_info info;
11730 @@ -35,15 +36,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11731
11732 info.flags = 0;
11733 info.length = len;
11734 - info.low_limit = TASK_UNMAPPED_BASE;
11735 + info.low_limit = mm->mmap_base;
11736 info.high_limit = min(task_size, VA_EXCLUDE_START);
11737 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11738 info.align_offset = 0;
11739 + info.threadstack_offset = offset;
11740 addr = vm_unmapped_area(&info);
11741
11742 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11743 VM_BUG_ON(addr != -ENOMEM);
11744 info.low_limit = VA_EXCLUDE_END;
11745 +
11746 +#ifdef CONFIG_PAX_RANDMMAP
11747 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11748 + info.low_limit += mm->delta_mmap;
11749 +#endif
11750 +
11751 info.high_limit = task_size;
11752 addr = vm_unmapped_area(&info);
11753 }
11754 @@ -55,7 +63,8 @@ static unsigned long
11755 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11756 const unsigned long len,
11757 const unsigned long pgoff,
11758 - const unsigned long flags)
11759 + const unsigned long flags,
11760 + const unsigned long offset)
11761 {
11762 struct mm_struct *mm = current->mm;
11763 unsigned long addr = addr0;
11764 @@ -70,6 +79,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11765 info.high_limit = mm->mmap_base;
11766 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11767 info.align_offset = 0;
11768 + info.threadstack_offset = offset;
11769 addr = vm_unmapped_area(&info);
11770
11771 /*
11772 @@ -82,6 +92,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11773 VM_BUG_ON(addr != -ENOMEM);
11774 info.flags = 0;
11775 info.low_limit = TASK_UNMAPPED_BASE;
11776 +
11777 +#ifdef CONFIG_PAX_RANDMMAP
11778 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11779 + info.low_limit += mm->delta_mmap;
11780 +#endif
11781 +
11782 info.high_limit = STACK_TOP32;
11783 addr = vm_unmapped_area(&info);
11784 }
11785 @@ -96,6 +112,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11786 struct mm_struct *mm = current->mm;
11787 struct vm_area_struct *vma;
11788 unsigned long task_size = TASK_SIZE;
11789 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11790
11791 if (test_thread_flag(TIF_32BIT))
11792 task_size = STACK_TOP32;
11793 @@ -111,19 +128,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11794 return addr;
11795 }
11796
11797 +#ifdef CONFIG_PAX_RANDMMAP
11798 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11799 +#endif
11800 +
11801 if (addr) {
11802 addr = ALIGN(addr, HPAGE_SIZE);
11803 vma = find_vma(mm, addr);
11804 - if (task_size - len >= addr &&
11805 - (!vma || addr + len <= vma->vm_start))
11806 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11807 return addr;
11808 }
11809 if (mm->get_unmapped_area == arch_get_unmapped_area)
11810 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11811 - pgoff, flags);
11812 + pgoff, flags, offset);
11813 else
11814 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11815 - pgoff, flags);
11816 + pgoff, flags, offset);
11817 }
11818
11819 pte_t *huge_pte_alloc(struct mm_struct *mm,
11820 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11821 index eafbc65..5a8070d 100644
11822 --- a/arch/sparc/mm/init_64.c
11823 +++ b/arch/sparc/mm/init_64.c
11824 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11825 int num_kernel_image_mappings;
11826
11827 #ifdef CONFIG_DEBUG_DCFLUSH
11828 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
11829 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11830 #ifdef CONFIG_SMP
11831 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11832 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11833 #endif
11834 #endif
11835
11836 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11837 {
11838 BUG_ON(tlb_type == hypervisor);
11839 #ifdef CONFIG_DEBUG_DCFLUSH
11840 - atomic_inc(&dcpage_flushes);
11841 + atomic_inc_unchecked(&dcpage_flushes);
11842 #endif
11843
11844 #ifdef DCACHE_ALIASING_POSSIBLE
11845 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11846
11847 #ifdef CONFIG_DEBUG_DCFLUSH
11848 seq_printf(m, "DCPageFlushes\t: %d\n",
11849 - atomic_read(&dcpage_flushes));
11850 + atomic_read_unchecked(&dcpage_flushes));
11851 #ifdef CONFIG_SMP
11852 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11853 - atomic_read(&dcpage_flushes_xcall));
11854 + atomic_read_unchecked(&dcpage_flushes_xcall));
11855 #endif /* CONFIG_SMP */
11856 #endif /* CONFIG_DEBUG_DCFLUSH */
11857 }
11858 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11859 index b3692ce..e4517c9 100644
11860 --- a/arch/tile/Kconfig
11861 +++ b/arch/tile/Kconfig
11862 @@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11863
11864 config KEXEC
11865 bool "kexec system call"
11866 + depends on !GRKERNSEC_KMEM
11867 ---help---
11868 kexec is a system call that implements the ability to shutdown your
11869 current kernel, and to start another kernel. It is like a reboot
11870 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11871 index ad220ee..2f537b3 100644
11872 --- a/arch/tile/include/asm/atomic_64.h
11873 +++ b/arch/tile/include/asm/atomic_64.h
11874 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11875
11876 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11877
11878 +#define atomic64_read_unchecked(v) atomic64_read(v)
11879 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11880 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11881 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11882 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11883 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
11884 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11885 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
11886 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11887 +
11888 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11889 #define smp_mb__before_atomic_dec() smp_mb()
11890 #define smp_mb__after_atomic_dec() smp_mb()
11891 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11892 index 6160761..00cac88 100644
11893 --- a/arch/tile/include/asm/cache.h
11894 +++ b/arch/tile/include/asm/cache.h
11895 @@ -15,11 +15,12 @@
11896 #ifndef _ASM_TILE_CACHE_H
11897 #define _ASM_TILE_CACHE_H
11898
11899 +#include <linux/const.h>
11900 #include <arch/chip.h>
11901
11902 /* bytes per L1 data cache line */
11903 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11904 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11905 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11906
11907 /* bytes per L2 cache line */
11908 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11909 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11910 index b6cde32..c0cb736 100644
11911 --- a/arch/tile/include/asm/uaccess.h
11912 +++ b/arch/tile/include/asm/uaccess.h
11913 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11914 const void __user *from,
11915 unsigned long n)
11916 {
11917 - int sz = __compiletime_object_size(to);
11918 + size_t sz = __compiletime_object_size(to);
11919
11920 - if (likely(sz == -1 || sz >= n))
11921 + if (likely(sz == (size_t)-1 || sz >= n))
11922 n = _copy_from_user(to, from, n);
11923 else
11924 copy_from_user_overflow();
11925 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11926 index 0cb3bba..7338b2d 100644
11927 --- a/arch/tile/mm/hugetlbpage.c
11928 +++ b/arch/tile/mm/hugetlbpage.c
11929 @@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11930 info.high_limit = TASK_SIZE;
11931 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11932 info.align_offset = 0;
11933 + info.threadstack_offset = 0;
11934 return vm_unmapped_area(&info);
11935 }
11936
11937 @@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11938 info.high_limit = current->mm->mmap_base;
11939 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11940 info.align_offset = 0;
11941 + info.threadstack_offset = 0;
11942 addr = vm_unmapped_area(&info);
11943
11944 /*
11945 diff --git a/arch/um/Makefile b/arch/um/Makefile
11946 index 36e658a..71a5c5a 100644
11947 --- a/arch/um/Makefile
11948 +++ b/arch/um/Makefile
11949 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11950 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11951 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11952
11953 +ifdef CONSTIFY_PLUGIN
11954 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11955 +endif
11956 +
11957 #This will adjust *FLAGS accordingly to the platform.
11958 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11959
11960 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11961 index 19e1bdd..3665b77 100644
11962 --- a/arch/um/include/asm/cache.h
11963 +++ b/arch/um/include/asm/cache.h
11964 @@ -1,6 +1,7 @@
11965 #ifndef __UM_CACHE_H
11966 #define __UM_CACHE_H
11967
11968 +#include <linux/const.h>
11969
11970 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11971 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11972 @@ -12,6 +13,6 @@
11973 # define L1_CACHE_SHIFT 5
11974 #endif
11975
11976 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11977 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11978
11979 #endif
11980 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11981 index 2e0a6b1..a64d0f5 100644
11982 --- a/arch/um/include/asm/kmap_types.h
11983 +++ b/arch/um/include/asm/kmap_types.h
11984 @@ -8,6 +8,6 @@
11985
11986 /* No more #include "asm/arch/kmap_types.h" ! */
11987
11988 -#define KM_TYPE_NR 14
11989 +#define KM_TYPE_NR 15
11990
11991 #endif
11992 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11993 index 5ff53d9..5850cdf 100644
11994 --- a/arch/um/include/asm/page.h
11995 +++ b/arch/um/include/asm/page.h
11996 @@ -14,6 +14,9 @@
11997 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11998 #define PAGE_MASK (~(PAGE_SIZE-1))
11999
12000 +#define ktla_ktva(addr) (addr)
12001 +#define ktva_ktla(addr) (addr)
12002 +
12003 #ifndef __ASSEMBLY__
12004
12005 struct page;
12006 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12007 index 0032f92..cd151e0 100644
12008 --- a/arch/um/include/asm/pgtable-3level.h
12009 +++ b/arch/um/include/asm/pgtable-3level.h
12010 @@ -58,6 +58,7 @@
12011 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12012 #define pud_populate(mm, pud, pmd) \
12013 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12014 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12015
12016 #ifdef CONFIG_64BIT
12017 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12018 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12019 index eecc414..48adb87 100644
12020 --- a/arch/um/kernel/process.c
12021 +++ b/arch/um/kernel/process.c
12022 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12023 return 2;
12024 }
12025
12026 -/*
12027 - * Only x86 and x86_64 have an arch_align_stack().
12028 - * All other arches have "#define arch_align_stack(x) (x)"
12029 - * in their asm/system.h
12030 - * As this is included in UML from asm-um/system-generic.h,
12031 - * we can use it to behave as the subarch does.
12032 - */
12033 -#ifndef arch_align_stack
12034 -unsigned long arch_align_stack(unsigned long sp)
12035 -{
12036 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12037 - sp -= get_random_int() % 8192;
12038 - return sp & ~0xf;
12039 -}
12040 -#endif
12041 -
12042 unsigned long get_wchan(struct task_struct *p)
12043 {
12044 unsigned long stack_page, sp, ip;
12045 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12046 index ad8f795..2c7eec6 100644
12047 --- a/arch/unicore32/include/asm/cache.h
12048 +++ b/arch/unicore32/include/asm/cache.h
12049 @@ -12,8 +12,10 @@
12050 #ifndef __UNICORE_CACHE_H__
12051 #define __UNICORE_CACHE_H__
12052
12053 -#define L1_CACHE_SHIFT (5)
12054 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12055 +#include <linux/const.h>
12056 +
12057 +#define L1_CACHE_SHIFT 5
12058 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12059
12060 /*
12061 * Memory returned by kmalloc() may be used for DMA, so we must make
12062 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12063 index 0af5250..59f9597 100644
12064 --- a/arch/x86/Kconfig
12065 +++ b/arch/x86/Kconfig
12066 @@ -126,7 +126,7 @@ config X86
12067 select RTC_LIB
12068 select HAVE_DEBUG_STACKOVERFLOW
12069 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12070 - select HAVE_CC_STACKPROTECTOR
12071 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12072
12073 config INSTRUCTION_DECODER
12074 def_bool y
12075 @@ -251,7 +251,7 @@ config X86_HT
12076
12077 config X86_32_LAZY_GS
12078 def_bool y
12079 - depends on X86_32 && !CC_STACKPROTECTOR
12080 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12081
12082 config ARCH_HWEIGHT_CFLAGS
12083 string
12084 @@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
12085
12086 menuconfig HYPERVISOR_GUEST
12087 bool "Linux guest support"
12088 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12089 ---help---
12090 Say Y here to enable options for running Linux under various hyper-
12091 visors. This option enables basic hypervisor detection and platform
12092 @@ -1111,7 +1112,7 @@ choice
12093
12094 config NOHIGHMEM
12095 bool "off"
12096 - depends on !X86_NUMAQ
12097 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12098 ---help---
12099 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12100 However, the address space of 32-bit x86 processors is only 4
12101 @@ -1148,7 +1149,7 @@ config NOHIGHMEM
12102
12103 config HIGHMEM4G
12104 bool "4GB"
12105 - depends on !X86_NUMAQ
12106 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12107 ---help---
12108 Select this if you have a 32-bit processor and between 1 and 4
12109 gigabytes of physical RAM.
12110 @@ -1201,7 +1202,7 @@ config PAGE_OFFSET
12111 hex
12112 default 0xB0000000 if VMSPLIT_3G_OPT
12113 default 0x80000000 if VMSPLIT_2G
12114 - default 0x78000000 if VMSPLIT_2G_OPT
12115 + default 0x70000000 if VMSPLIT_2G_OPT
12116 default 0x40000000 if VMSPLIT_1G
12117 default 0xC0000000
12118 depends on X86_32
12119 @@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
12120
12121 config KEXEC
12122 bool "kexec system call"
12123 + depends on !GRKERNSEC_KMEM
12124 ---help---
12125 kexec is a system call that implements the ability to shutdown your
12126 current kernel, and to start another kernel. It is like a reboot
12127 @@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
12128
12129 config PHYSICAL_ALIGN
12130 hex "Alignment value to which kernel should be aligned"
12131 - default "0x200000"
12132 + default "0x1000000"
12133 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12134 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12135 range 0x2000 0x1000000 if X86_32
12136 range 0x200000 0x1000000 if X86_64
12137 ---help---
12138 @@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
12139 If unsure, say N.
12140
12141 config COMPAT_VDSO
12142 - def_bool y
12143 + def_bool n
12144 prompt "Compat VDSO support"
12145 depends on X86_32 || IA32_EMULATION
12146 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12147 ---help---
12148 Map the 32-bit VDSO to the predictable old-style address too.
12149
12150 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12151 index f3aaf23..a1d3c49 100644
12152 --- a/arch/x86/Kconfig.cpu
12153 +++ b/arch/x86/Kconfig.cpu
12154 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12155
12156 config X86_F00F_BUG
12157 def_bool y
12158 - depends on M586MMX || M586TSC || M586 || M486
12159 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12160
12161 config X86_INVD_BUG
12162 def_bool y
12163 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12164
12165 config X86_ALIGNMENT_16
12166 def_bool y
12167 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12168 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12169
12170 config X86_INTEL_USERCOPY
12171 def_bool y
12172 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12173 # generates cmov.
12174 config X86_CMOV
12175 def_bool y
12176 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12177 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12178
12179 config X86_MINIMUM_CPU_FAMILY
12180 int
12181 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12182 index 321a52c..3d51a5e 100644
12183 --- a/arch/x86/Kconfig.debug
12184 +++ b/arch/x86/Kconfig.debug
12185 @@ -84,7 +84,7 @@ config X86_PTDUMP
12186 config DEBUG_RODATA
12187 bool "Write protect kernel read-only data structures"
12188 default y
12189 - depends on DEBUG_KERNEL
12190 + depends on DEBUG_KERNEL && BROKEN
12191 ---help---
12192 Mark the kernel read-only data as write-protected in the pagetables,
12193 in order to catch accidental (and incorrect) writes to such const
12194 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12195
12196 config DEBUG_SET_MODULE_RONX
12197 bool "Set loadable kernel module data as NX and text as RO"
12198 - depends on MODULES
12199 + depends on MODULES && BROKEN
12200 ---help---
12201 This option helps catch unintended modifications to loadable
12202 kernel module's text and read-only data. It also prevents execution
12203 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12204 index eeda43a..5a238be 100644
12205 --- a/arch/x86/Makefile
12206 +++ b/arch/x86/Makefile
12207 @@ -71,14 +71,12 @@ ifeq ($(CONFIG_X86_32),y)
12208 # CPU-specific tuning. Anything which can be shared with UML should go here.
12209 include $(srctree)/arch/x86/Makefile_32.cpu
12210 KBUILD_CFLAGS += $(cflags-y)
12211 -
12212 - # temporary until string.h is fixed
12213 - KBUILD_CFLAGS += -ffreestanding
12214 else
12215 BITS := 64
12216 UTS_MACHINE := x86_64
12217 CHECKFLAGS += -D__x86_64__ -m64
12218
12219 + biarch := $(call cc-option,-m64)
12220 KBUILD_AFLAGS += -m64
12221 KBUILD_CFLAGS += -m64
12222
12223 @@ -111,6 +109,9 @@ else
12224 KBUILD_CFLAGS += -maccumulate-outgoing-args
12225 endif
12226
12227 +# temporary until string.h is fixed
12228 +KBUILD_CFLAGS += -ffreestanding
12229 +
12230 # Make sure compiler does not have buggy stack-protector support.
12231 ifdef CONFIG_CC_STACKPROTECTOR
12232 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12233 @@ -267,3 +268,12 @@ define archhelp
12234 echo ' FDINITRD=file initrd for the booted kernel'
12235 echo ' kvmconfig - Enable additional options for guest kernel support'
12236 endef
12237 +
12238 +define OLD_LD
12239 +
12240 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12241 +*** Please upgrade your binutils to 2.18 or newer
12242 +endef
12243 +
12244 +archprepare:
12245 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12246 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12247 index 878df7e..a803913 100644
12248 --- a/arch/x86/boot/Makefile
12249 +++ b/arch/x86/boot/Makefile
12250 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12251 # ---------------------------------------------------------------------------
12252
12253 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12254 +ifdef CONSTIFY_PLUGIN
12255 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12256 +endif
12257 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12258 GCOV_PROFILE := n
12259
12260 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12261 index 878e4b9..20537ab 100644
12262 --- a/arch/x86/boot/bitops.h
12263 +++ b/arch/x86/boot/bitops.h
12264 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12265 u8 v;
12266 const u32 *p = (const u32 *)addr;
12267
12268 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12269 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12270 return v;
12271 }
12272
12273 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12274
12275 static inline void set_bit(int nr, void *addr)
12276 {
12277 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12278 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12279 }
12280
12281 #endif /* BOOT_BITOPS_H */
12282 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12283 index 50f8c5e..4f84fff 100644
12284 --- a/arch/x86/boot/boot.h
12285 +++ b/arch/x86/boot/boot.h
12286 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12287 static inline u16 ds(void)
12288 {
12289 u16 seg;
12290 - asm("movw %%ds,%0" : "=rm" (seg));
12291 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12292 return seg;
12293 }
12294
12295 @@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12296 static inline int memcmp(const void *s1, const void *s2, size_t len)
12297 {
12298 u8 diff;
12299 - asm("repe; cmpsb; setnz %0"
12300 + asm volatile("repe; cmpsb; setnz %0"
12301 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12302 return diff;
12303 }
12304 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12305 index 0fcd913..3bb5c42 100644
12306 --- a/arch/x86/boot/compressed/Makefile
12307 +++ b/arch/x86/boot/compressed/Makefile
12308 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12309 KBUILD_CFLAGS += -mno-mmx -mno-sse
12310 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12311 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12312 +ifdef CONSTIFY_PLUGIN
12313 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12314 +endif
12315
12316 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12317 GCOV_PROFILE := n
12318 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12319 index a53440e..c3dbf1e 100644
12320 --- a/arch/x86/boot/compressed/efi_stub_32.S
12321 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12322 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12323 * parameter 2, ..., param n. To make things easy, we save the return
12324 * address of efi_call_phys in a global variable.
12325 */
12326 - popl %ecx
12327 - movl %ecx, saved_return_addr(%edx)
12328 - /* get the function pointer into ECX*/
12329 - popl %ecx
12330 - movl %ecx, efi_rt_function_ptr(%edx)
12331 + popl saved_return_addr(%edx)
12332 + popl efi_rt_function_ptr(%edx)
12333
12334 /*
12335 * 3. Call the physical function.
12336 */
12337 - call *%ecx
12338 + call *efi_rt_function_ptr(%edx)
12339
12340 /*
12341 * 4. Balance the stack. And because EAX contain the return value,
12342 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12343 1: popl %edx
12344 subl $1b, %edx
12345
12346 - movl efi_rt_function_ptr(%edx), %ecx
12347 - pushl %ecx
12348 + pushl efi_rt_function_ptr(%edx)
12349
12350 /*
12351 * 10. Push the saved return address onto the stack and return.
12352 */
12353 - movl saved_return_addr(%edx), %ecx
12354 - pushl %ecx
12355 - ret
12356 + jmpl *saved_return_addr(%edx)
12357 ENDPROC(efi_call_phys)
12358 .previous
12359
12360 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12361 index 9116aac..abbcdb1 100644
12362 --- a/arch/x86/boot/compressed/head_32.S
12363 +++ b/arch/x86/boot/compressed/head_32.S
12364 @@ -117,10 +117,10 @@ preferred_addr:
12365 addl %eax, %ebx
12366 notl %eax
12367 andl %eax, %ebx
12368 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12369 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12370 jge 1f
12371 #endif
12372 - movl $LOAD_PHYSICAL_ADDR, %ebx
12373 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12374 1:
12375
12376 /* Target address to relocate to for decompression */
12377 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12378 index c5c1ae0..2e76d0e 100644
12379 --- a/arch/x86/boot/compressed/head_64.S
12380 +++ b/arch/x86/boot/compressed/head_64.S
12381 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12382 addl %eax, %ebx
12383 notl %eax
12384 andl %eax, %ebx
12385 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12386 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12387 jge 1f
12388 #endif
12389 - movl $LOAD_PHYSICAL_ADDR, %ebx
12390 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12391 1:
12392
12393 /* Target address to relocate to for decompression */
12394 @@ -271,10 +271,10 @@ preferred_addr:
12395 addq %rax, %rbp
12396 notq %rax
12397 andq %rax, %rbp
12398 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12399 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12400 jge 1f
12401 #endif
12402 - movq $LOAD_PHYSICAL_ADDR, %rbp
12403 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12404 1:
12405
12406 /* Target address to relocate to for decompression */
12407 @@ -366,8 +366,8 @@ gdt:
12408 .long gdt
12409 .word 0
12410 .quad 0x0000000000000000 /* NULL descriptor */
12411 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12412 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12413 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12414 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12415 .quad 0x0080890000000000 /* TS descriptor */
12416 .quad 0x0000000000000000 /* TS continued */
12417 gdt_end:
12418 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12419 index 196eaf3..c96716d 100644
12420 --- a/arch/x86/boot/compressed/misc.c
12421 +++ b/arch/x86/boot/compressed/misc.c
12422 @@ -218,7 +218,7 @@ void __putstr(const char *s)
12423
12424 void *memset(void *s, int c, size_t n)
12425 {
12426 - int i;
12427 + size_t i;
12428 char *ss = s;
12429
12430 for (i = 0; i < n; i++)
12431 @@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12432 * Calculate the delta between where vmlinux was linked to load
12433 * and where it was actually loaded.
12434 */
12435 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12436 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12437 if (!delta) {
12438 debug_putstr("No relocation needed... ");
12439 return;
12440 @@ -347,7 +347,7 @@ static void parse_elf(void *output)
12441 Elf32_Ehdr ehdr;
12442 Elf32_Phdr *phdrs, *phdr;
12443 #endif
12444 - void *dest;
12445 + void *dest, *prev;
12446 int i;
12447
12448 memcpy(&ehdr, output, sizeof(ehdr));
12449 @@ -374,13 +374,16 @@ static void parse_elf(void *output)
12450 case PT_LOAD:
12451 #ifdef CONFIG_RELOCATABLE
12452 dest = output;
12453 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12454 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12455 #else
12456 dest = (void *)(phdr->p_paddr);
12457 #endif
12458 memcpy(dest,
12459 output + phdr->p_offset,
12460 phdr->p_filesz);
12461 + if (i)
12462 + memset(prev, 0xff, dest - prev);
12463 + prev = dest + phdr->p_filesz;
12464 break;
12465 default: /* Ignore other PT_* */ break;
12466 }
12467 @@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
12468 error("Destination address too large");
12469 #endif
12470 #ifndef CONFIG_RELOCATABLE
12471 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12472 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12473 error("Wrong destination address");
12474 #endif
12475
12476 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12477 index 100a9a1..bb3bdb0 100644
12478 --- a/arch/x86/boot/cpucheck.c
12479 +++ b/arch/x86/boot/cpucheck.c
12480 @@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12481 u32 ecx = MSR_K7_HWCR;
12482 u32 eax, edx;
12483
12484 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12485 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12486 eax &= ~(1 << 15);
12487 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12488 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12489
12490 get_cpuflags(); /* Make sure it really did something */
12491 err = check_cpuflags();
12492 @@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12493 u32 ecx = MSR_VIA_FCR;
12494 u32 eax, edx;
12495
12496 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12497 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12498 eax |= (1<<1)|(1<<7);
12499 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12500 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12501
12502 set_bit(X86_FEATURE_CX8, cpu.flags);
12503 err = check_cpuflags();
12504 @@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12505 u32 eax, edx;
12506 u32 level = 1;
12507
12508 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12509 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12510 - asm("cpuid"
12511 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12512 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12513 + asm volatile("cpuid"
12514 : "+a" (level), "=d" (cpu.flags[0])
12515 : : "ecx", "ebx");
12516 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12517 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12518
12519 err = check_cpuflags();
12520 }
12521 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12522 index ec3b8ba..6a0db1f 100644
12523 --- a/arch/x86/boot/header.S
12524 +++ b/arch/x86/boot/header.S
12525 @@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12526 # single linked list of
12527 # struct setup_data
12528
12529 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12530 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12531
12532 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12533 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12534 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12535 +#else
12536 #define VO_INIT_SIZE (VO__end - VO__text)
12537 +#endif
12538 #if ZO_INIT_SIZE > VO_INIT_SIZE
12539 #define INIT_SIZE ZO_INIT_SIZE
12540 #else
12541 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12542 index db75d07..8e6d0af 100644
12543 --- a/arch/x86/boot/memory.c
12544 +++ b/arch/x86/boot/memory.c
12545 @@ -19,7 +19,7 @@
12546
12547 static int detect_memory_e820(void)
12548 {
12549 - int count = 0;
12550 + unsigned int count = 0;
12551 struct biosregs ireg, oreg;
12552 struct e820entry *desc = boot_params.e820_map;
12553 static struct e820entry buf; /* static so it is zeroed */
12554 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12555 index 11e8c6e..fdbb1ed 100644
12556 --- a/arch/x86/boot/video-vesa.c
12557 +++ b/arch/x86/boot/video-vesa.c
12558 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12559
12560 boot_params.screen_info.vesapm_seg = oreg.es;
12561 boot_params.screen_info.vesapm_off = oreg.di;
12562 + boot_params.screen_info.vesapm_size = oreg.cx;
12563 }
12564
12565 /*
12566 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12567 index 43eda28..5ab5fdb 100644
12568 --- a/arch/x86/boot/video.c
12569 +++ b/arch/x86/boot/video.c
12570 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12571 static unsigned int get_entry(void)
12572 {
12573 char entry_buf[4];
12574 - int i, len = 0;
12575 + unsigned int i, len = 0;
12576 int key;
12577 unsigned int v;
12578
12579 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12580 index 9105655..41779c1 100644
12581 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12582 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12583 @@ -8,6 +8,8 @@
12584 * including this sentence is retained in full.
12585 */
12586
12587 +#include <asm/alternative-asm.h>
12588 +
12589 .extern crypto_ft_tab
12590 .extern crypto_it_tab
12591 .extern crypto_fl_tab
12592 @@ -70,6 +72,8 @@
12593 je B192; \
12594 leaq 32(r9),r9;
12595
12596 +#define ret pax_force_retaddr; ret
12597 +
12598 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12599 movq r1,r2; \
12600 movq r3,r4; \
12601 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12602 index 477e9d7..c92c7d8 100644
12603 --- a/arch/x86/crypto/aesni-intel_asm.S
12604 +++ b/arch/x86/crypto/aesni-intel_asm.S
12605 @@ -31,6 +31,7 @@
12606
12607 #include <linux/linkage.h>
12608 #include <asm/inst.h>
12609 +#include <asm/alternative-asm.h>
12610
12611 #ifdef __x86_64__
12612 .data
12613 @@ -205,7 +206,7 @@ enc: .octa 0x2
12614 * num_initial_blocks = b mod 4
12615 * encrypt the initial num_initial_blocks blocks and apply ghash on
12616 * the ciphertext
12617 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12618 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12619 * are clobbered
12620 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12621 */
12622 @@ -214,8 +215,8 @@ enc: .octa 0x2
12623 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12624 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12625 mov arg7, %r10 # %r10 = AAD
12626 - mov arg8, %r12 # %r12 = aadLen
12627 - mov %r12, %r11
12628 + mov arg8, %r15 # %r15 = aadLen
12629 + mov %r15, %r11
12630 pxor %xmm\i, %xmm\i
12631 _get_AAD_loop\num_initial_blocks\operation:
12632 movd (%r10), \TMP1
12633 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12634 psrldq $4, %xmm\i
12635 pxor \TMP1, %xmm\i
12636 add $4, %r10
12637 - sub $4, %r12
12638 + sub $4, %r15
12639 jne _get_AAD_loop\num_initial_blocks\operation
12640 cmp $16, %r11
12641 je _get_AAD_loop2_done\num_initial_blocks\operation
12642 - mov $16, %r12
12643 + mov $16, %r15
12644 _get_AAD_loop2\num_initial_blocks\operation:
12645 psrldq $4, %xmm\i
12646 - sub $4, %r12
12647 - cmp %r11, %r12
12648 + sub $4, %r15
12649 + cmp %r11, %r15
12650 jne _get_AAD_loop2\num_initial_blocks\operation
12651 _get_AAD_loop2_done\num_initial_blocks\operation:
12652 movdqa SHUF_MASK(%rip), %xmm14
12653 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12654 * num_initial_blocks = b mod 4
12655 * encrypt the initial num_initial_blocks blocks and apply ghash on
12656 * the ciphertext
12657 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12658 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12659 * are clobbered
12660 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12661 */
12662 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12663 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12664 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12665 mov arg7, %r10 # %r10 = AAD
12666 - mov arg8, %r12 # %r12 = aadLen
12667 - mov %r12, %r11
12668 + mov arg8, %r15 # %r15 = aadLen
12669 + mov %r15, %r11
12670 pxor %xmm\i, %xmm\i
12671 _get_AAD_loop\num_initial_blocks\operation:
12672 movd (%r10), \TMP1
12673 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12674 psrldq $4, %xmm\i
12675 pxor \TMP1, %xmm\i
12676 add $4, %r10
12677 - sub $4, %r12
12678 + sub $4, %r15
12679 jne _get_AAD_loop\num_initial_blocks\operation
12680 cmp $16, %r11
12681 je _get_AAD_loop2_done\num_initial_blocks\operation
12682 - mov $16, %r12
12683 + mov $16, %r15
12684 _get_AAD_loop2\num_initial_blocks\operation:
12685 psrldq $4, %xmm\i
12686 - sub $4, %r12
12687 - cmp %r11, %r12
12688 + sub $4, %r15
12689 + cmp %r11, %r15
12690 jne _get_AAD_loop2\num_initial_blocks\operation
12691 _get_AAD_loop2_done\num_initial_blocks\operation:
12692 movdqa SHUF_MASK(%rip), %xmm14
12693 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12694 *
12695 *****************************************************************************/
12696 ENTRY(aesni_gcm_dec)
12697 - push %r12
12698 + push %r15
12699 push %r13
12700 push %r14
12701 mov %rsp, %r14
12702 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12703 */
12704 sub $VARIABLE_OFFSET, %rsp
12705 and $~63, %rsp # align rsp to 64 bytes
12706 - mov %arg6, %r12
12707 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12708 + mov %arg6, %r15
12709 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12710 movdqa SHUF_MASK(%rip), %xmm2
12711 PSHUFB_XMM %xmm2, %xmm13
12712
12713 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12714 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12715 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12716 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12717 - mov %r13, %r12
12718 - and $(3<<4), %r12
12719 + mov %r13, %r15
12720 + and $(3<<4), %r15
12721 jz _initial_num_blocks_is_0_decrypt
12722 - cmp $(2<<4), %r12
12723 + cmp $(2<<4), %r15
12724 jb _initial_num_blocks_is_1_decrypt
12725 je _initial_num_blocks_is_2_decrypt
12726 _initial_num_blocks_is_3_decrypt:
12727 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12728 sub $16, %r11
12729 add %r13, %r11
12730 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12731 - lea SHIFT_MASK+16(%rip), %r12
12732 - sub %r13, %r12
12733 + lea SHIFT_MASK+16(%rip), %r15
12734 + sub %r13, %r15
12735 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12736 # (%r13 is the number of bytes in plaintext mod 16)
12737 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12738 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12739 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12740
12741 movdqa %xmm1, %xmm2
12742 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12743 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12744 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12745 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12746 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12747 pand %xmm1, %xmm2
12748 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12749 sub $1, %r13
12750 jne _less_than_8_bytes_left_decrypt
12751 _multiple_of_16_bytes_decrypt:
12752 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12753 - shl $3, %r12 # convert into number of bits
12754 - movd %r12d, %xmm15 # len(A) in %xmm15
12755 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12756 + shl $3, %r15 # convert into number of bits
12757 + movd %r15d, %xmm15 # len(A) in %xmm15
12758 shl $3, %arg4 # len(C) in bits (*128)
12759 MOVQ_R64_XMM %arg4, %xmm1
12760 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12761 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12762 mov %r14, %rsp
12763 pop %r14
12764 pop %r13
12765 - pop %r12
12766 + pop %r15
12767 + pax_force_retaddr
12768 ret
12769 ENDPROC(aesni_gcm_dec)
12770
12771 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12772 * poly = x^128 + x^127 + x^126 + x^121 + 1
12773 ***************************************************************************/
12774 ENTRY(aesni_gcm_enc)
12775 - push %r12
12776 + push %r15
12777 push %r13
12778 push %r14
12779 mov %rsp, %r14
12780 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12781 #
12782 sub $VARIABLE_OFFSET, %rsp
12783 and $~63, %rsp
12784 - mov %arg6, %r12
12785 - movdqu (%r12), %xmm13
12786 + mov %arg6, %r15
12787 + movdqu (%r15), %xmm13
12788 movdqa SHUF_MASK(%rip), %xmm2
12789 PSHUFB_XMM %xmm2, %xmm13
12790
12791 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12792 movdqa %xmm13, HashKey(%rsp)
12793 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12794 and $-16, %r13
12795 - mov %r13, %r12
12796 + mov %r13, %r15
12797
12798 # Encrypt first few blocks
12799
12800 - and $(3<<4), %r12
12801 + and $(3<<4), %r15
12802 jz _initial_num_blocks_is_0_encrypt
12803 - cmp $(2<<4), %r12
12804 + cmp $(2<<4), %r15
12805 jb _initial_num_blocks_is_1_encrypt
12806 je _initial_num_blocks_is_2_encrypt
12807 _initial_num_blocks_is_3_encrypt:
12808 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12809 sub $16, %r11
12810 add %r13, %r11
12811 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12812 - lea SHIFT_MASK+16(%rip), %r12
12813 - sub %r13, %r12
12814 + lea SHIFT_MASK+16(%rip), %r15
12815 + sub %r13, %r15
12816 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12817 # (%r13 is the number of bytes in plaintext mod 16)
12818 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12819 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12820 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12821 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12822 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12823 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12824 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12825 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12826 movdqa SHUF_MASK(%rip), %xmm10
12827 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12828 sub $1, %r13
12829 jne _less_than_8_bytes_left_encrypt
12830 _multiple_of_16_bytes_encrypt:
12831 - mov arg8, %r12 # %r12 = addLen (number of bytes)
12832 - shl $3, %r12
12833 - movd %r12d, %xmm15 # len(A) in %xmm15
12834 + mov arg8, %r15 # %r15 = addLen (number of bytes)
12835 + shl $3, %r15
12836 + movd %r15d, %xmm15 # len(A) in %xmm15
12837 shl $3, %arg4 # len(C) in bits (*128)
12838 MOVQ_R64_XMM %arg4, %xmm1
12839 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12840 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12841 mov %r14, %rsp
12842 pop %r14
12843 pop %r13
12844 - pop %r12
12845 + pop %r15
12846 + pax_force_retaddr
12847 ret
12848 ENDPROC(aesni_gcm_enc)
12849
12850 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
12851 pxor %xmm1, %xmm0
12852 movaps %xmm0, (TKEYP)
12853 add $0x10, TKEYP
12854 + pax_force_retaddr
12855 ret
12856 ENDPROC(_key_expansion_128)
12857 ENDPROC(_key_expansion_256a)
12858 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
12859 shufps $0b01001110, %xmm2, %xmm1
12860 movaps %xmm1, 0x10(TKEYP)
12861 add $0x20, TKEYP
12862 + pax_force_retaddr
12863 ret
12864 ENDPROC(_key_expansion_192a)
12865
12866 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
12867
12868 movaps %xmm0, (TKEYP)
12869 add $0x10, TKEYP
12870 + pax_force_retaddr
12871 ret
12872 ENDPROC(_key_expansion_192b)
12873
12874 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
12875 pxor %xmm1, %xmm2
12876 movaps %xmm2, (TKEYP)
12877 add $0x10, TKEYP
12878 + pax_force_retaddr
12879 ret
12880 ENDPROC(_key_expansion_256b)
12881
12882 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12883 #ifndef __x86_64__
12884 popl KEYP
12885 #endif
12886 + pax_force_retaddr
12887 ret
12888 ENDPROC(aesni_set_key)
12889
12890 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12891 popl KLEN
12892 popl KEYP
12893 #endif
12894 + pax_force_retaddr
12895 ret
12896 ENDPROC(aesni_enc)
12897
12898 @@ -1974,6 +1983,7 @@ _aesni_enc1:
12899 AESENC KEY STATE
12900 movaps 0x70(TKEYP), KEY
12901 AESENCLAST KEY STATE
12902 + pax_force_retaddr
12903 ret
12904 ENDPROC(_aesni_enc1)
12905
12906 @@ -2083,6 +2093,7 @@ _aesni_enc4:
12907 AESENCLAST KEY STATE2
12908 AESENCLAST KEY STATE3
12909 AESENCLAST KEY STATE4
12910 + pax_force_retaddr
12911 ret
12912 ENDPROC(_aesni_enc4)
12913
12914 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12915 popl KLEN
12916 popl KEYP
12917 #endif
12918 + pax_force_retaddr
12919 ret
12920 ENDPROC(aesni_dec)
12921
12922 @@ -2164,6 +2176,7 @@ _aesni_dec1:
12923 AESDEC KEY STATE
12924 movaps 0x70(TKEYP), KEY
12925 AESDECLAST KEY STATE
12926 + pax_force_retaddr
12927 ret
12928 ENDPROC(_aesni_dec1)
12929
12930 @@ -2273,6 +2286,7 @@ _aesni_dec4:
12931 AESDECLAST KEY STATE2
12932 AESDECLAST KEY STATE3
12933 AESDECLAST KEY STATE4
12934 + pax_force_retaddr
12935 ret
12936 ENDPROC(_aesni_dec4)
12937
12938 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12939 popl KEYP
12940 popl LEN
12941 #endif
12942 + pax_force_retaddr
12943 ret
12944 ENDPROC(aesni_ecb_enc)
12945
12946 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12947 popl KEYP
12948 popl LEN
12949 #endif
12950 + pax_force_retaddr
12951 ret
12952 ENDPROC(aesni_ecb_dec)
12953
12954 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12955 popl LEN
12956 popl IVP
12957 #endif
12958 + pax_force_retaddr
12959 ret
12960 ENDPROC(aesni_cbc_enc)
12961
12962 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12963 popl LEN
12964 popl IVP
12965 #endif
12966 + pax_force_retaddr
12967 ret
12968 ENDPROC(aesni_cbc_dec)
12969
12970 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
12971 mov $1, TCTR_LOW
12972 MOVQ_R64_XMM TCTR_LOW INC
12973 MOVQ_R64_XMM CTR TCTR_LOW
12974 + pax_force_retaddr
12975 ret
12976 ENDPROC(_aesni_inc_init)
12977
12978 @@ -2579,6 +2598,7 @@ _aesni_inc:
12979 .Linc_low:
12980 movaps CTR, IV
12981 PSHUFB_XMM BSWAP_MASK IV
12982 + pax_force_retaddr
12983 ret
12984 ENDPROC(_aesni_inc)
12985
12986 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12987 .Lctr_enc_ret:
12988 movups IV, (IVP)
12989 .Lctr_enc_just_ret:
12990 + pax_force_retaddr
12991 ret
12992 ENDPROC(aesni_ctr_enc)
12993
12994 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12995 pxor INC, STATE4
12996 movdqu STATE4, 0x70(OUTP)
12997
12998 + pax_force_retaddr
12999 ret
13000 ENDPROC(aesni_xts_crypt8)
13001
13002 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13003 index 246c670..466e2d6 100644
13004 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13005 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13006 @@ -21,6 +21,7 @@
13007 */
13008
13009 #include <linux/linkage.h>
13010 +#include <asm/alternative-asm.h>
13011
13012 .file "blowfish-x86_64-asm.S"
13013 .text
13014 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13015 jnz .L__enc_xor;
13016
13017 write_block();
13018 + pax_force_retaddr
13019 ret;
13020 .L__enc_xor:
13021 xor_block();
13022 + pax_force_retaddr
13023 ret;
13024 ENDPROC(__blowfish_enc_blk)
13025
13026 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13027
13028 movq %r11, %rbp;
13029
13030 + pax_force_retaddr
13031 ret;
13032 ENDPROC(blowfish_dec_blk)
13033
13034 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13035
13036 popq %rbx;
13037 popq %rbp;
13038 + pax_force_retaddr
13039 ret;
13040
13041 .L__enc_xor4:
13042 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13043
13044 popq %rbx;
13045 popq %rbp;
13046 + pax_force_retaddr
13047 ret;
13048 ENDPROC(__blowfish_enc_blk_4way)
13049
13050 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13051 popq %rbx;
13052 popq %rbp;
13053
13054 + pax_force_retaddr
13055 ret;
13056 ENDPROC(blowfish_dec_blk_4way)
13057 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13058 index ce71f92..1dce7ec 100644
13059 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13060 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13061 @@ -16,6 +16,7 @@
13062 */
13063
13064 #include <linux/linkage.h>
13065 +#include <asm/alternative-asm.h>
13066
13067 #define CAMELLIA_TABLE_BYTE_LEN 272
13068
13069 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13070 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13071 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13072 %rcx, (%r9));
13073 + pax_force_retaddr
13074 ret;
13075 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13076
13077 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13078 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13079 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13080 %rax, (%r9));
13081 + pax_force_retaddr
13082 ret;
13083 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13084
13085 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13086 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13087 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13088
13089 + pax_force_retaddr
13090 ret;
13091
13092 .align 8
13093 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13094 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13095 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13096
13097 + pax_force_retaddr
13098 ret;
13099
13100 .align 8
13101 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13102 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13103 %xmm8, %rsi);
13104
13105 + pax_force_retaddr
13106 ret;
13107 ENDPROC(camellia_ecb_enc_16way)
13108
13109 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13110 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13111 %xmm8, %rsi);
13112
13113 + pax_force_retaddr
13114 ret;
13115 ENDPROC(camellia_ecb_dec_16way)
13116
13117 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13118 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13119 %xmm8, %rsi);
13120
13121 + pax_force_retaddr
13122 ret;
13123 ENDPROC(camellia_cbc_dec_16way)
13124
13125 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13126 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13127 %xmm8, %rsi);
13128
13129 + pax_force_retaddr
13130 ret;
13131 ENDPROC(camellia_ctr_16way)
13132
13133 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13134 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13135 %xmm8, %rsi);
13136
13137 + pax_force_retaddr
13138 ret;
13139 ENDPROC(camellia_xts_crypt_16way)
13140
13141 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13142 index 0e0b886..5a3123c 100644
13143 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13144 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13145 @@ -11,6 +11,7 @@
13146 */
13147
13148 #include <linux/linkage.h>
13149 +#include <asm/alternative-asm.h>
13150
13151 #define CAMELLIA_TABLE_BYTE_LEN 272
13152
13153 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13154 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13155 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13156 %rcx, (%r9));
13157 + pax_force_retaddr
13158 ret;
13159 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13160
13161 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13162 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13163 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13164 %rax, (%r9));
13165 + pax_force_retaddr
13166 ret;
13167 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13168
13169 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13170 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13171 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13172
13173 + pax_force_retaddr
13174 ret;
13175
13176 .align 8
13177 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13178 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13179 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13180
13181 + pax_force_retaddr
13182 ret;
13183
13184 .align 8
13185 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13186
13187 vzeroupper;
13188
13189 + pax_force_retaddr
13190 ret;
13191 ENDPROC(camellia_ecb_enc_32way)
13192
13193 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13194
13195 vzeroupper;
13196
13197 + pax_force_retaddr
13198 ret;
13199 ENDPROC(camellia_ecb_dec_32way)
13200
13201 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13202
13203 vzeroupper;
13204
13205 + pax_force_retaddr
13206 ret;
13207 ENDPROC(camellia_cbc_dec_32way)
13208
13209 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13210
13211 vzeroupper;
13212
13213 + pax_force_retaddr
13214 ret;
13215 ENDPROC(camellia_ctr_32way)
13216
13217 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13218
13219 vzeroupper;
13220
13221 + pax_force_retaddr
13222 ret;
13223 ENDPROC(camellia_xts_crypt_32way)
13224
13225 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13226 index 310319c..db3d7b5 100644
13227 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13228 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13229 @@ -21,6 +21,7 @@
13230 */
13231
13232 #include <linux/linkage.h>
13233 +#include <asm/alternative-asm.h>
13234
13235 .file "camellia-x86_64-asm_64.S"
13236 .text
13237 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13238 enc_outunpack(mov, RT1);
13239
13240 movq RRBP, %rbp;
13241 + pax_force_retaddr
13242 ret;
13243
13244 .L__enc_xor:
13245 enc_outunpack(xor, RT1);
13246
13247 movq RRBP, %rbp;
13248 + pax_force_retaddr
13249 ret;
13250 ENDPROC(__camellia_enc_blk)
13251
13252 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13253 dec_outunpack();
13254
13255 movq RRBP, %rbp;
13256 + pax_force_retaddr
13257 ret;
13258 ENDPROC(camellia_dec_blk)
13259
13260 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13261
13262 movq RRBP, %rbp;
13263 popq %rbx;
13264 + pax_force_retaddr
13265 ret;
13266
13267 .L__enc2_xor:
13268 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13269
13270 movq RRBP, %rbp;
13271 popq %rbx;
13272 + pax_force_retaddr
13273 ret;
13274 ENDPROC(__camellia_enc_blk_2way)
13275
13276 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13277
13278 movq RRBP, %rbp;
13279 movq RXOR, %rbx;
13280 + pax_force_retaddr
13281 ret;
13282 ENDPROC(camellia_dec_blk_2way)
13283 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13284 index c35fd5d..2d8c7db 100644
13285 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13286 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13287 @@ -24,6 +24,7 @@
13288 */
13289
13290 #include <linux/linkage.h>
13291 +#include <asm/alternative-asm.h>
13292
13293 .file "cast5-avx-x86_64-asm_64.S"
13294
13295 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13296 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13297 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13298
13299 + pax_force_retaddr
13300 ret;
13301 ENDPROC(__cast5_enc_blk16)
13302
13303 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13304 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13305 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13306
13307 + pax_force_retaddr
13308 ret;
13309
13310 .L__skip_dec:
13311 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13312 vmovdqu RR4, (6*4*4)(%r11);
13313 vmovdqu RL4, (7*4*4)(%r11);
13314
13315 + pax_force_retaddr
13316 ret;
13317 ENDPROC(cast5_ecb_enc_16way)
13318
13319 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13320 vmovdqu RR4, (6*4*4)(%r11);
13321 vmovdqu RL4, (7*4*4)(%r11);
13322
13323 + pax_force_retaddr
13324 ret;
13325 ENDPROC(cast5_ecb_dec_16way)
13326
13327 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13328 * %rdx: src
13329 */
13330
13331 - pushq %r12;
13332 + pushq %r14;
13333
13334 movq %rsi, %r11;
13335 - movq %rdx, %r12;
13336 + movq %rdx, %r14;
13337
13338 vmovdqu (0*16)(%rdx), RL1;
13339 vmovdqu (1*16)(%rdx), RR1;
13340 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13341 call __cast5_dec_blk16;
13342
13343 /* xor with src */
13344 - vmovq (%r12), RX;
13345 + vmovq (%r14), RX;
13346 vpshufd $0x4f, RX, RX;
13347 vpxor RX, RR1, RR1;
13348 - vpxor 0*16+8(%r12), RL1, RL1;
13349 - vpxor 1*16+8(%r12), RR2, RR2;
13350 - vpxor 2*16+8(%r12), RL2, RL2;
13351 - vpxor 3*16+8(%r12), RR3, RR3;
13352 - vpxor 4*16+8(%r12), RL3, RL3;
13353 - vpxor 5*16+8(%r12), RR4, RR4;
13354 - vpxor 6*16+8(%r12), RL4, RL4;
13355 + vpxor 0*16+8(%r14), RL1, RL1;
13356 + vpxor 1*16+8(%r14), RR2, RR2;
13357 + vpxor 2*16+8(%r14), RL2, RL2;
13358 + vpxor 3*16+8(%r14), RR3, RR3;
13359 + vpxor 4*16+8(%r14), RL3, RL3;
13360 + vpxor 5*16+8(%r14), RR4, RR4;
13361 + vpxor 6*16+8(%r14), RL4, RL4;
13362
13363 vmovdqu RR1, (0*16)(%r11);
13364 vmovdqu RL1, (1*16)(%r11);
13365 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13366 vmovdqu RR4, (6*16)(%r11);
13367 vmovdqu RL4, (7*16)(%r11);
13368
13369 - popq %r12;
13370 + popq %r14;
13371
13372 + pax_force_retaddr
13373 ret;
13374 ENDPROC(cast5_cbc_dec_16way)
13375
13376 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13377 * %rcx: iv (big endian, 64bit)
13378 */
13379
13380 - pushq %r12;
13381 + pushq %r14;
13382
13383 movq %rsi, %r11;
13384 - movq %rdx, %r12;
13385 + movq %rdx, %r14;
13386
13387 vpcmpeqd RTMP, RTMP, RTMP;
13388 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13389 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13390 call __cast5_enc_blk16;
13391
13392 /* dst = src ^ iv */
13393 - vpxor (0*16)(%r12), RR1, RR1;
13394 - vpxor (1*16)(%r12), RL1, RL1;
13395 - vpxor (2*16)(%r12), RR2, RR2;
13396 - vpxor (3*16)(%r12), RL2, RL2;
13397 - vpxor (4*16)(%r12), RR3, RR3;
13398 - vpxor (5*16)(%r12), RL3, RL3;
13399 - vpxor (6*16)(%r12), RR4, RR4;
13400 - vpxor (7*16)(%r12), RL4, RL4;
13401 + vpxor (0*16)(%r14), RR1, RR1;
13402 + vpxor (1*16)(%r14), RL1, RL1;
13403 + vpxor (2*16)(%r14), RR2, RR2;
13404 + vpxor (3*16)(%r14), RL2, RL2;
13405 + vpxor (4*16)(%r14), RR3, RR3;
13406 + vpxor (5*16)(%r14), RL3, RL3;
13407 + vpxor (6*16)(%r14), RR4, RR4;
13408 + vpxor (7*16)(%r14), RL4, RL4;
13409 vmovdqu RR1, (0*16)(%r11);
13410 vmovdqu RL1, (1*16)(%r11);
13411 vmovdqu RR2, (2*16)(%r11);
13412 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13413 vmovdqu RR4, (6*16)(%r11);
13414 vmovdqu RL4, (7*16)(%r11);
13415
13416 - popq %r12;
13417 + popq %r14;
13418
13419 + pax_force_retaddr
13420 ret;
13421 ENDPROC(cast5_ctr_16way)
13422 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13423 index e3531f8..e123f35 100644
13424 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13425 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13426 @@ -24,6 +24,7 @@
13427 */
13428
13429 #include <linux/linkage.h>
13430 +#include <asm/alternative-asm.h>
13431 #include "glue_helper-asm-avx.S"
13432
13433 .file "cast6-avx-x86_64-asm_64.S"
13434 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13435 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13436 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13437
13438 + pax_force_retaddr
13439 ret;
13440 ENDPROC(__cast6_enc_blk8)
13441
13442 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13443 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13444 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13445
13446 + pax_force_retaddr
13447 ret;
13448 ENDPROC(__cast6_dec_blk8)
13449
13450 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13451
13452 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13453
13454 + pax_force_retaddr
13455 ret;
13456 ENDPROC(cast6_ecb_enc_8way)
13457
13458 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13459
13460 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13461
13462 + pax_force_retaddr
13463 ret;
13464 ENDPROC(cast6_ecb_dec_8way)
13465
13466 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13467 * %rdx: src
13468 */
13469
13470 - pushq %r12;
13471 + pushq %r14;
13472
13473 movq %rsi, %r11;
13474 - movq %rdx, %r12;
13475 + movq %rdx, %r14;
13476
13477 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13478
13479 call __cast6_dec_blk8;
13480
13481 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13482 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13483
13484 - popq %r12;
13485 + popq %r14;
13486
13487 + pax_force_retaddr
13488 ret;
13489 ENDPROC(cast6_cbc_dec_8way)
13490
13491 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13492 * %rcx: iv (little endian, 128bit)
13493 */
13494
13495 - pushq %r12;
13496 + pushq %r14;
13497
13498 movq %rsi, %r11;
13499 - movq %rdx, %r12;
13500 + movq %rdx, %r14;
13501
13502 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13503 RD2, RX, RKR, RKM);
13504
13505 call __cast6_enc_blk8;
13506
13507 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13508 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13509
13510 - popq %r12;
13511 + popq %r14;
13512
13513 + pax_force_retaddr
13514 ret;
13515 ENDPROC(cast6_ctr_8way)
13516
13517 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13518 /* dst <= regs xor IVs(in dst) */
13519 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13520
13521 + pax_force_retaddr
13522 ret;
13523 ENDPROC(cast6_xts_enc_8way)
13524
13525 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13526 /* dst <= regs xor IVs(in dst) */
13527 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13528
13529 + pax_force_retaddr
13530 ret;
13531 ENDPROC(cast6_xts_dec_8way)
13532 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13533 index dbc4339..de6e120 100644
13534 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13535 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13536 @@ -45,6 +45,7 @@
13537
13538 #include <asm/inst.h>
13539 #include <linux/linkage.h>
13540 +#include <asm/alternative-asm.h>
13541
13542 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13543
13544 @@ -312,6 +313,7 @@ do_return:
13545 popq %rsi
13546 popq %rdi
13547 popq %rbx
13548 + pax_force_retaddr
13549 ret
13550
13551 ################################################################
13552 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13553 index 185fad4..ff4cd36 100644
13554 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13555 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13556 @@ -18,6 +18,7 @@
13557
13558 #include <linux/linkage.h>
13559 #include <asm/inst.h>
13560 +#include <asm/alternative-asm.h>
13561
13562 .data
13563
13564 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13565 psrlq $1, T2
13566 pxor T2, T1
13567 pxor T1, DATA
13568 + pax_force_retaddr
13569 ret
13570 ENDPROC(__clmul_gf128mul_ble)
13571
13572 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13573 call __clmul_gf128mul_ble
13574 PSHUFB_XMM BSWAP DATA
13575 movups DATA, (%rdi)
13576 + pax_force_retaddr
13577 ret
13578 ENDPROC(clmul_ghash_mul)
13579
13580 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13581 PSHUFB_XMM BSWAP DATA
13582 movups DATA, (%rdi)
13583 .Lupdate_just_ret:
13584 + pax_force_retaddr
13585 ret
13586 ENDPROC(clmul_ghash_update)
13587 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13588 index 9279e0b..c4b3d2c 100644
13589 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13590 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13591 @@ -1,4 +1,5 @@
13592 #include <linux/linkage.h>
13593 +#include <asm/alternative-asm.h>
13594
13595 # enter salsa20_encrypt_bytes
13596 ENTRY(salsa20_encrypt_bytes)
13597 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13598 add %r11,%rsp
13599 mov %rdi,%rax
13600 mov %rsi,%rdx
13601 + pax_force_retaddr
13602 ret
13603 # bytesatleast65:
13604 ._bytesatleast65:
13605 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13606 add %r11,%rsp
13607 mov %rdi,%rax
13608 mov %rsi,%rdx
13609 + pax_force_retaddr
13610 ret
13611 ENDPROC(salsa20_keysetup)
13612
13613 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13614 add %r11,%rsp
13615 mov %rdi,%rax
13616 mov %rsi,%rdx
13617 + pax_force_retaddr
13618 ret
13619 ENDPROC(salsa20_ivsetup)
13620 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13621 index 2f202f4..d9164d6 100644
13622 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13623 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13624 @@ -24,6 +24,7 @@
13625 */
13626
13627 #include <linux/linkage.h>
13628 +#include <asm/alternative-asm.h>
13629 #include "glue_helper-asm-avx.S"
13630
13631 .file "serpent-avx-x86_64-asm_64.S"
13632 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13633 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13634 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13635
13636 + pax_force_retaddr
13637 ret;
13638 ENDPROC(__serpent_enc_blk8_avx)
13639
13640 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13641 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13642 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13643
13644 + pax_force_retaddr
13645 ret;
13646 ENDPROC(__serpent_dec_blk8_avx)
13647
13648 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13649
13650 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13651
13652 + pax_force_retaddr
13653 ret;
13654 ENDPROC(serpent_ecb_enc_8way_avx)
13655
13656 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13657
13658 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13659
13660 + pax_force_retaddr
13661 ret;
13662 ENDPROC(serpent_ecb_dec_8way_avx)
13663
13664 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13665
13666 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13667
13668 + pax_force_retaddr
13669 ret;
13670 ENDPROC(serpent_cbc_dec_8way_avx)
13671
13672 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13673
13674 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13675
13676 + pax_force_retaddr
13677 ret;
13678 ENDPROC(serpent_ctr_8way_avx)
13679
13680 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13681 /* dst <= regs xor IVs(in dst) */
13682 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13683
13684 + pax_force_retaddr
13685 ret;
13686 ENDPROC(serpent_xts_enc_8way_avx)
13687
13688 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13689 /* dst <= regs xor IVs(in dst) */
13690 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13691
13692 + pax_force_retaddr
13693 ret;
13694 ENDPROC(serpent_xts_dec_8way_avx)
13695 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13696 index b222085..abd483c 100644
13697 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13698 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13699 @@ -15,6 +15,7 @@
13700 */
13701
13702 #include <linux/linkage.h>
13703 +#include <asm/alternative-asm.h>
13704 #include "glue_helper-asm-avx2.S"
13705
13706 .file "serpent-avx2-asm_64.S"
13707 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13708 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13709 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13710
13711 + pax_force_retaddr
13712 ret;
13713 ENDPROC(__serpent_enc_blk16)
13714
13715 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13716 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13717 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13718
13719 + pax_force_retaddr
13720 ret;
13721 ENDPROC(__serpent_dec_blk16)
13722
13723 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13724
13725 vzeroupper;
13726
13727 + pax_force_retaddr
13728 ret;
13729 ENDPROC(serpent_ecb_enc_16way)
13730
13731 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13732
13733 vzeroupper;
13734
13735 + pax_force_retaddr
13736 ret;
13737 ENDPROC(serpent_ecb_dec_16way)
13738
13739 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13740
13741 vzeroupper;
13742
13743 + pax_force_retaddr
13744 ret;
13745 ENDPROC(serpent_cbc_dec_16way)
13746
13747 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13748
13749 vzeroupper;
13750
13751 + pax_force_retaddr
13752 ret;
13753 ENDPROC(serpent_ctr_16way)
13754
13755 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13756
13757 vzeroupper;
13758
13759 + pax_force_retaddr
13760 ret;
13761 ENDPROC(serpent_xts_enc_16way)
13762
13763 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13764
13765 vzeroupper;
13766
13767 + pax_force_retaddr
13768 ret;
13769 ENDPROC(serpent_xts_dec_16way)
13770 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13771 index acc066c..1559cc4 100644
13772 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13773 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13774 @@ -25,6 +25,7 @@
13775 */
13776
13777 #include <linux/linkage.h>
13778 +#include <asm/alternative-asm.h>
13779
13780 .file "serpent-sse2-x86_64-asm_64.S"
13781 .text
13782 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13783 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13784 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13785
13786 + pax_force_retaddr
13787 ret;
13788
13789 .L__enc_xor8:
13790 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13791 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13792
13793 + pax_force_retaddr
13794 ret;
13795 ENDPROC(__serpent_enc_blk_8way)
13796
13797 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13798 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13799 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13800
13801 + pax_force_retaddr
13802 ret;
13803 ENDPROC(serpent_dec_blk_8way)
13804 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13805 index a410950..9dfe7ad 100644
13806 --- a/arch/x86/crypto/sha1_ssse3_asm.S
13807 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
13808 @@ -29,6 +29,7 @@
13809 */
13810
13811 #include <linux/linkage.h>
13812 +#include <asm/alternative-asm.h>
13813
13814 #define CTX %rdi // arg1
13815 #define BUF %rsi // arg2
13816 @@ -75,9 +76,9 @@
13817
13818 push %rbx
13819 push %rbp
13820 - push %r12
13821 + push %r14
13822
13823 - mov %rsp, %r12
13824 + mov %rsp, %r14
13825 sub $64, %rsp # allocate workspace
13826 and $~15, %rsp # align stack
13827
13828 @@ -99,11 +100,12 @@
13829 xor %rax, %rax
13830 rep stosq
13831
13832 - mov %r12, %rsp # deallocate workspace
13833 + mov %r14, %rsp # deallocate workspace
13834
13835 - pop %r12
13836 + pop %r14
13837 pop %rbp
13838 pop %rbx
13839 + pax_force_retaddr
13840 ret
13841
13842 ENDPROC(\name)
13843 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13844 index 642f156..51a513c 100644
13845 --- a/arch/x86/crypto/sha256-avx-asm.S
13846 +++ b/arch/x86/crypto/sha256-avx-asm.S
13847 @@ -49,6 +49,7 @@
13848
13849 #ifdef CONFIG_AS_AVX
13850 #include <linux/linkage.h>
13851 +#include <asm/alternative-asm.h>
13852
13853 ## assume buffers not aligned
13854 #define VMOVDQ vmovdqu
13855 @@ -460,6 +461,7 @@ done_hash:
13856 popq %r13
13857 popq %rbp
13858 popq %rbx
13859 + pax_force_retaddr
13860 ret
13861 ENDPROC(sha256_transform_avx)
13862
13863 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13864 index 9e86944..3795e6a 100644
13865 --- a/arch/x86/crypto/sha256-avx2-asm.S
13866 +++ b/arch/x86/crypto/sha256-avx2-asm.S
13867 @@ -50,6 +50,7 @@
13868
13869 #ifdef CONFIG_AS_AVX2
13870 #include <linux/linkage.h>
13871 +#include <asm/alternative-asm.h>
13872
13873 ## assume buffers not aligned
13874 #define VMOVDQ vmovdqu
13875 @@ -720,6 +721,7 @@ done_hash:
13876 popq %r12
13877 popq %rbp
13878 popq %rbx
13879 + pax_force_retaddr
13880 ret
13881 ENDPROC(sha256_transform_rorx)
13882
13883 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13884 index f833b74..8c62a9e 100644
13885 --- a/arch/x86/crypto/sha256-ssse3-asm.S
13886 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
13887 @@ -47,6 +47,7 @@
13888 ########################################################################
13889
13890 #include <linux/linkage.h>
13891 +#include <asm/alternative-asm.h>
13892
13893 ## assume buffers not aligned
13894 #define MOVDQ movdqu
13895 @@ -471,6 +472,7 @@ done_hash:
13896 popq %rbp
13897 popq %rbx
13898
13899 + pax_force_retaddr
13900 ret
13901 ENDPROC(sha256_transform_ssse3)
13902
13903 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13904 index 974dde9..a823ff9 100644
13905 --- a/arch/x86/crypto/sha512-avx-asm.S
13906 +++ b/arch/x86/crypto/sha512-avx-asm.S
13907 @@ -49,6 +49,7 @@
13908
13909 #ifdef CONFIG_AS_AVX
13910 #include <linux/linkage.h>
13911 +#include <asm/alternative-asm.h>
13912
13913 .text
13914
13915 @@ -364,6 +365,7 @@ updateblock:
13916 mov frame_RSPSAVE(%rsp), %rsp
13917
13918 nowork:
13919 + pax_force_retaddr
13920 ret
13921 ENDPROC(sha512_transform_avx)
13922
13923 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13924 index 568b961..ed20c37 100644
13925 --- a/arch/x86/crypto/sha512-avx2-asm.S
13926 +++ b/arch/x86/crypto/sha512-avx2-asm.S
13927 @@ -51,6 +51,7 @@
13928
13929 #ifdef CONFIG_AS_AVX2
13930 #include <linux/linkage.h>
13931 +#include <asm/alternative-asm.h>
13932
13933 .text
13934
13935 @@ -678,6 +679,7 @@ done_hash:
13936
13937 # Restore Stack Pointer
13938 mov frame_RSPSAVE(%rsp), %rsp
13939 + pax_force_retaddr
13940 ret
13941 ENDPROC(sha512_transform_rorx)
13942
13943 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13944 index fb56855..6edd768 100644
13945 --- a/arch/x86/crypto/sha512-ssse3-asm.S
13946 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
13947 @@ -48,6 +48,7 @@
13948 ########################################################################
13949
13950 #include <linux/linkage.h>
13951 +#include <asm/alternative-asm.h>
13952
13953 .text
13954
13955 @@ -363,6 +364,7 @@ updateblock:
13956 mov frame_RSPSAVE(%rsp), %rsp
13957
13958 nowork:
13959 + pax_force_retaddr
13960 ret
13961 ENDPROC(sha512_transform_ssse3)
13962
13963 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13964 index 0505813..b067311 100644
13965 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13966 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13967 @@ -24,6 +24,7 @@
13968 */
13969
13970 #include <linux/linkage.h>
13971 +#include <asm/alternative-asm.h>
13972 #include "glue_helper-asm-avx.S"
13973
13974 .file "twofish-avx-x86_64-asm_64.S"
13975 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
13976 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13977 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13978
13979 + pax_force_retaddr
13980 ret;
13981 ENDPROC(__twofish_enc_blk8)
13982
13983 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
13984 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13985 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13986
13987 + pax_force_retaddr
13988 ret;
13989 ENDPROC(__twofish_dec_blk8)
13990
13991 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13992
13993 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13994
13995 + pax_force_retaddr
13996 ret;
13997 ENDPROC(twofish_ecb_enc_8way)
13998
13999 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14000
14001 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14002
14003 + pax_force_retaddr
14004 ret;
14005 ENDPROC(twofish_ecb_dec_8way)
14006
14007 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14008 * %rdx: src
14009 */
14010
14011 - pushq %r12;
14012 + pushq %r14;
14013
14014 movq %rsi, %r11;
14015 - movq %rdx, %r12;
14016 + movq %rdx, %r14;
14017
14018 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14019
14020 call __twofish_dec_blk8;
14021
14022 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14023 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14024
14025 - popq %r12;
14026 + popq %r14;
14027
14028 + pax_force_retaddr
14029 ret;
14030 ENDPROC(twofish_cbc_dec_8way)
14031
14032 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14033 * %rcx: iv (little endian, 128bit)
14034 */
14035
14036 - pushq %r12;
14037 + pushq %r14;
14038
14039 movq %rsi, %r11;
14040 - movq %rdx, %r12;
14041 + movq %rdx, %r14;
14042
14043 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14044 RD2, RX0, RX1, RY0);
14045
14046 call __twofish_enc_blk8;
14047
14048 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14049 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14050
14051 - popq %r12;
14052 + popq %r14;
14053
14054 + pax_force_retaddr
14055 ret;
14056 ENDPROC(twofish_ctr_8way)
14057
14058 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14059 /* dst <= regs xor IVs(in dst) */
14060 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14061
14062 + pax_force_retaddr
14063 ret;
14064 ENDPROC(twofish_xts_enc_8way)
14065
14066 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14067 /* dst <= regs xor IVs(in dst) */
14068 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14069
14070 + pax_force_retaddr
14071 ret;
14072 ENDPROC(twofish_xts_dec_8way)
14073 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14074 index 1c3b7ce..02f578d 100644
14075 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14076 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14077 @@ -21,6 +21,7 @@
14078 */
14079
14080 #include <linux/linkage.h>
14081 +#include <asm/alternative-asm.h>
14082
14083 .file "twofish-x86_64-asm-3way.S"
14084 .text
14085 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14086 popq %r13;
14087 popq %r14;
14088 popq %r15;
14089 + pax_force_retaddr
14090 ret;
14091
14092 .L__enc_xor3:
14093 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14094 popq %r13;
14095 popq %r14;
14096 popq %r15;
14097 + pax_force_retaddr
14098 ret;
14099 ENDPROC(__twofish_enc_blk_3way)
14100
14101 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14102 popq %r13;
14103 popq %r14;
14104 popq %r15;
14105 + pax_force_retaddr
14106 ret;
14107 ENDPROC(twofish_dec_blk_3way)
14108 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14109 index a039d21..524b8b2 100644
14110 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14111 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14112 @@ -22,6 +22,7 @@
14113
14114 #include <linux/linkage.h>
14115 #include <asm/asm-offsets.h>
14116 +#include <asm/alternative-asm.h>
14117
14118 #define a_offset 0
14119 #define b_offset 4
14120 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14121
14122 popq R1
14123 movq $1,%rax
14124 + pax_force_retaddr
14125 ret
14126 ENDPROC(twofish_enc_blk)
14127
14128 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14129
14130 popq R1
14131 movq $1,%rax
14132 + pax_force_retaddr
14133 ret
14134 ENDPROC(twofish_dec_blk)
14135 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14136 index d21ff89..6da8e6e 100644
14137 --- a/arch/x86/ia32/ia32_aout.c
14138 +++ b/arch/x86/ia32/ia32_aout.c
14139 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14140 unsigned long dump_start, dump_size;
14141 struct user32 dump;
14142
14143 + memset(&dump, 0, sizeof(dump));
14144 +
14145 fs = get_fs();
14146 set_fs(KERNEL_DS);
14147 has_dumped = 1;
14148 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14149 index 2206757..85cbcfa 100644
14150 --- a/arch/x86/ia32/ia32_signal.c
14151 +++ b/arch/x86/ia32/ia32_signal.c
14152 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14153 if (__get_user(set.sig[0], &frame->sc.oldmask)
14154 || (_COMPAT_NSIG_WORDS > 1
14155 && __copy_from_user((((char *) &set.sig) + 4),
14156 - &frame->extramask,
14157 + frame->extramask,
14158 sizeof(frame->extramask))))
14159 goto badframe;
14160
14161 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14162 sp -= frame_size;
14163 /* Align the stack pointer according to the i386 ABI,
14164 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14165 - sp = ((sp + 4) & -16ul) - 4;
14166 + sp = ((sp - 12) & -16ul) - 4;
14167 return (void __user *) sp;
14168 }
14169
14170 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14171 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14172 sigreturn);
14173 else
14174 - restorer = &frame->retcode;
14175 + restorer = frame->retcode;
14176 }
14177
14178 put_user_try {
14179 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14180 * These are actually not used anymore, but left because some
14181 * gdb versions depend on them as a marker.
14182 */
14183 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14184 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14185 } put_user_catch(err);
14186
14187 if (err)
14188 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14189 0xb8,
14190 __NR_ia32_rt_sigreturn,
14191 0x80cd,
14192 - 0,
14193 + 0
14194 };
14195
14196 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14197 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14198
14199 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14200 restorer = ksig->ka.sa.sa_restorer;
14201 + else if (current->mm->context.vdso)
14202 + /* Return stub is in 32bit vsyscall page */
14203 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14204 else
14205 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14206 - rt_sigreturn);
14207 + restorer = frame->retcode;
14208 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14209
14210 /*
14211 * Not actually used anymore, but left because some gdb
14212 * versions need it.
14213 */
14214 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14215 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14216 } put_user_catch(err);
14217
14218 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14219 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14220 index 4299eb0..c0687a7 100644
14221 --- a/arch/x86/ia32/ia32entry.S
14222 +++ b/arch/x86/ia32/ia32entry.S
14223 @@ -15,8 +15,10 @@
14224 #include <asm/irqflags.h>
14225 #include <asm/asm.h>
14226 #include <asm/smap.h>
14227 +#include <asm/pgtable.h>
14228 #include <linux/linkage.h>
14229 #include <linux/err.h>
14230 +#include <asm/alternative-asm.h>
14231
14232 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14233 #include <linux/elf-em.h>
14234 @@ -62,12 +64,12 @@
14235 */
14236 .macro LOAD_ARGS32 offset, _r9=0
14237 .if \_r9
14238 - movl \offset+16(%rsp),%r9d
14239 + movl \offset+R9(%rsp),%r9d
14240 .endif
14241 - movl \offset+40(%rsp),%ecx
14242 - movl \offset+48(%rsp),%edx
14243 - movl \offset+56(%rsp),%esi
14244 - movl \offset+64(%rsp),%edi
14245 + movl \offset+RCX(%rsp),%ecx
14246 + movl \offset+RDX(%rsp),%edx
14247 + movl \offset+RSI(%rsp),%esi
14248 + movl \offset+RDI(%rsp),%edi
14249 movl %eax,%eax /* zero extension */
14250 .endm
14251
14252 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14253 ENDPROC(native_irq_enable_sysexit)
14254 #endif
14255
14256 + .macro pax_enter_kernel_user
14257 + pax_set_fptr_mask
14258 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14259 + call pax_enter_kernel_user
14260 +#endif
14261 + .endm
14262 +
14263 + .macro pax_exit_kernel_user
14264 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14265 + call pax_exit_kernel_user
14266 +#endif
14267 +#ifdef CONFIG_PAX_RANDKSTACK
14268 + pushq %rax
14269 + pushq %r11
14270 + call pax_randomize_kstack
14271 + popq %r11
14272 + popq %rax
14273 +#endif
14274 + .endm
14275 +
14276 + .macro pax_erase_kstack
14277 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14278 + call pax_erase_kstack
14279 +#endif
14280 + .endm
14281 +
14282 /*
14283 * 32bit SYSENTER instruction entry.
14284 *
14285 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14286 CFI_REGISTER rsp,rbp
14287 SWAPGS_UNSAFE_STACK
14288 movq PER_CPU_VAR(kernel_stack), %rsp
14289 - addq $(KERNEL_STACK_OFFSET),%rsp
14290 - /*
14291 - * No need to follow this irqs on/off section: the syscall
14292 - * disabled irqs, here we enable it straight after entry:
14293 - */
14294 - ENABLE_INTERRUPTS(CLBR_NONE)
14295 movl %ebp,%ebp /* zero extension */
14296 pushq_cfi $__USER32_DS
14297 /*CFI_REL_OFFSET ss,0*/
14298 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14299 CFI_REL_OFFSET rsp,0
14300 pushfq_cfi
14301 /*CFI_REL_OFFSET rflags,0*/
14302 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14303 - CFI_REGISTER rip,r10
14304 + orl $X86_EFLAGS_IF,(%rsp)
14305 + GET_THREAD_INFO(%r11)
14306 + movl TI_sysenter_return(%r11), %r11d
14307 + CFI_REGISTER rip,r11
14308 pushq_cfi $__USER32_CS
14309 /*CFI_REL_OFFSET cs,0*/
14310 movl %eax, %eax
14311 - pushq_cfi %r10
14312 + pushq_cfi %r11
14313 CFI_REL_OFFSET rip,0
14314 pushq_cfi %rax
14315 cld
14316 SAVE_ARGS 0,1,0
14317 + pax_enter_kernel_user
14318 +
14319 +#ifdef CONFIG_PAX_RANDKSTACK
14320 + pax_erase_kstack
14321 +#endif
14322 +
14323 + /*
14324 + * No need to follow this irqs on/off section: the syscall
14325 + * disabled irqs, here we enable it straight after entry:
14326 + */
14327 + ENABLE_INTERRUPTS(CLBR_NONE)
14328 /* no need to do an access_ok check here because rbp has been
14329 32bit zero extended */
14330 +
14331 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14332 + addq pax_user_shadow_base,%rbp
14333 + ASM_PAX_OPEN_USERLAND
14334 +#endif
14335 +
14336 ASM_STAC
14337 1: movl (%rbp),%ebp
14338 _ASM_EXTABLE(1b,ia32_badarg)
14339 ASM_CLAC
14340 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14341 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14342 +
14343 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14344 + ASM_PAX_CLOSE_USERLAND
14345 +#endif
14346 +
14347 + GET_THREAD_INFO(%r11)
14348 + orl $TS_COMPAT,TI_status(%r11)
14349 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14350 CFI_REMEMBER_STATE
14351 jnz sysenter_tracesys
14352 cmpq $(IA32_NR_syscalls-1),%rax
14353 @@ -162,15 +209,18 @@ sysenter_do_call:
14354 sysenter_dispatch:
14355 call *ia32_sys_call_table(,%rax,8)
14356 movq %rax,RAX-ARGOFFSET(%rsp)
14357 + GET_THREAD_INFO(%r11)
14358 DISABLE_INTERRUPTS(CLBR_NONE)
14359 TRACE_IRQS_OFF
14360 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14361 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14362 jnz sysexit_audit
14363 sysexit_from_sys_call:
14364 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14365 + pax_exit_kernel_user
14366 + pax_erase_kstack
14367 + andl $~TS_COMPAT,TI_status(%r11)
14368 /* clear IF, that popfq doesn't enable interrupts early */
14369 - andl $~0x200,EFLAGS-R11(%rsp)
14370 - movl RIP-R11(%rsp),%edx /* User %eip */
14371 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14372 + movl RIP(%rsp),%edx /* User %eip */
14373 CFI_REGISTER rip,rdx
14374 RESTORE_ARGS 0,24,0,0,0,0
14375 xorq %r8,%r8
14376 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
14377 movl %eax,%esi /* 2nd arg: syscall number */
14378 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14379 call __audit_syscall_entry
14380 +
14381 + pax_erase_kstack
14382 +
14383 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14384 cmpq $(IA32_NR_syscalls-1),%rax
14385 ja ia32_badsys
14386 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14387 .endm
14388
14389 .macro auditsys_exit exit
14390 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14391 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14392 jnz ia32_ret_from_sys_call
14393 TRACE_IRQS_ON
14394 ENABLE_INTERRUPTS(CLBR_NONE)
14395 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14396 1: setbe %al /* 1 if error, 0 if not */
14397 movzbl %al,%edi /* zero-extend that into %edi */
14398 call __audit_syscall_exit
14399 + GET_THREAD_INFO(%r11)
14400 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14401 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14402 DISABLE_INTERRUPTS(CLBR_NONE)
14403 TRACE_IRQS_OFF
14404 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14405 + testl %edi,TI_flags(%r11)
14406 jz \exit
14407 CLEAR_RREGS -ARGOFFSET
14408 jmp int_with_check
14409 @@ -237,7 +291,7 @@ sysexit_audit:
14410
14411 sysenter_tracesys:
14412 #ifdef CONFIG_AUDITSYSCALL
14413 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14414 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14415 jz sysenter_auditsys
14416 #endif
14417 SAVE_REST
14418 @@ -249,6 +303,9 @@ sysenter_tracesys:
14419 RESTORE_REST
14420 cmpq $(IA32_NR_syscalls-1),%rax
14421 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14422 +
14423 + pax_erase_kstack
14424 +
14425 jmp sysenter_do_call
14426 CFI_ENDPROC
14427 ENDPROC(ia32_sysenter_target)
14428 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14429 ENTRY(ia32_cstar_target)
14430 CFI_STARTPROC32 simple
14431 CFI_SIGNAL_FRAME
14432 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14433 + CFI_DEF_CFA rsp,0
14434 CFI_REGISTER rip,rcx
14435 /*CFI_REGISTER rflags,r11*/
14436 SWAPGS_UNSAFE_STACK
14437 movl %esp,%r8d
14438 CFI_REGISTER rsp,r8
14439 movq PER_CPU_VAR(kernel_stack),%rsp
14440 + SAVE_ARGS 8*6,0,0
14441 + pax_enter_kernel_user
14442 +
14443 +#ifdef CONFIG_PAX_RANDKSTACK
14444 + pax_erase_kstack
14445 +#endif
14446 +
14447 /*
14448 * No need to follow this irqs on/off section: the syscall
14449 * disabled irqs and here we enable it straight after entry:
14450 */
14451 ENABLE_INTERRUPTS(CLBR_NONE)
14452 - SAVE_ARGS 8,0,0
14453 movl %eax,%eax /* zero extension */
14454 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14455 movq %rcx,RIP-ARGOFFSET(%rsp)
14456 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14457 /* no need to do an access_ok check here because r8 has been
14458 32bit zero extended */
14459 /* hardware stack frame is complete now */
14460 +
14461 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14462 + ASM_PAX_OPEN_USERLAND
14463 + movq pax_user_shadow_base,%r8
14464 + addq RSP-ARGOFFSET(%rsp),%r8
14465 +#endif
14466 +
14467 ASM_STAC
14468 1: movl (%r8),%r9d
14469 _ASM_EXTABLE(1b,ia32_badarg)
14470 ASM_CLAC
14471 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14472 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14473 +
14474 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14475 + ASM_PAX_CLOSE_USERLAND
14476 +#endif
14477 +
14478 + GET_THREAD_INFO(%r11)
14479 + orl $TS_COMPAT,TI_status(%r11)
14480 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14481 CFI_REMEMBER_STATE
14482 jnz cstar_tracesys
14483 cmpq $IA32_NR_syscalls-1,%rax
14484 @@ -319,13 +395,16 @@ cstar_do_call:
14485 cstar_dispatch:
14486 call *ia32_sys_call_table(,%rax,8)
14487 movq %rax,RAX-ARGOFFSET(%rsp)
14488 + GET_THREAD_INFO(%r11)
14489 DISABLE_INTERRUPTS(CLBR_NONE)
14490 TRACE_IRQS_OFF
14491 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14492 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14493 jnz sysretl_audit
14494 sysretl_from_sys_call:
14495 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14496 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14497 + pax_exit_kernel_user
14498 + pax_erase_kstack
14499 + andl $~TS_COMPAT,TI_status(%r11)
14500 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14501 movl RIP-ARGOFFSET(%rsp),%ecx
14502 CFI_REGISTER rip,rcx
14503 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14504 @@ -352,7 +431,7 @@ sysretl_audit:
14505
14506 cstar_tracesys:
14507 #ifdef CONFIG_AUDITSYSCALL
14508 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14509 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14510 jz cstar_auditsys
14511 #endif
14512 xchgl %r9d,%ebp
14513 @@ -366,11 +445,19 @@ cstar_tracesys:
14514 xchgl %ebp,%r9d
14515 cmpq $(IA32_NR_syscalls-1),%rax
14516 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14517 +
14518 + pax_erase_kstack
14519 +
14520 jmp cstar_do_call
14521 END(ia32_cstar_target)
14522
14523 ia32_badarg:
14524 ASM_CLAC
14525 +
14526 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14527 + ASM_PAX_CLOSE_USERLAND
14528 +#endif
14529 +
14530 movq $-EFAULT,%rax
14531 jmp ia32_sysret
14532 CFI_ENDPROC
14533 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14534 CFI_REL_OFFSET rip,RIP-RIP
14535 PARAVIRT_ADJUST_EXCEPTION_FRAME
14536 SWAPGS
14537 - /*
14538 - * No need to follow this irqs on/off section: the syscall
14539 - * disabled irqs and here we enable it straight after entry:
14540 - */
14541 - ENABLE_INTERRUPTS(CLBR_NONE)
14542 movl %eax,%eax
14543 pushq_cfi %rax
14544 cld
14545 /* note the registers are not zero extended to the sf.
14546 this could be a problem. */
14547 SAVE_ARGS 0,1,0
14548 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14549 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14550 + pax_enter_kernel_user
14551 +
14552 +#ifdef CONFIG_PAX_RANDKSTACK
14553 + pax_erase_kstack
14554 +#endif
14555 +
14556 + /*
14557 + * No need to follow this irqs on/off section: the syscall
14558 + * disabled irqs and here we enable it straight after entry:
14559 + */
14560 + ENABLE_INTERRUPTS(CLBR_NONE)
14561 + GET_THREAD_INFO(%r11)
14562 + orl $TS_COMPAT,TI_status(%r11)
14563 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14564 jnz ia32_tracesys
14565 cmpq $(IA32_NR_syscalls-1),%rax
14566 ja ia32_badsys
14567 @@ -442,6 +536,9 @@ ia32_tracesys:
14568 RESTORE_REST
14569 cmpq $(IA32_NR_syscalls-1),%rax
14570 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14571 +
14572 + pax_erase_kstack
14573 +
14574 jmp ia32_do_call
14575 END(ia32_syscall)
14576
14577 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14578 index 8e0ceec..af13504 100644
14579 --- a/arch/x86/ia32/sys_ia32.c
14580 +++ b/arch/x86/ia32/sys_ia32.c
14581 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14582 */
14583 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14584 {
14585 - typeof(ubuf->st_uid) uid = 0;
14586 - typeof(ubuf->st_gid) gid = 0;
14587 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14588 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14589 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14590 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14591 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14592 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14593 index 372231c..51b537d 100644
14594 --- a/arch/x86/include/asm/alternative-asm.h
14595 +++ b/arch/x86/include/asm/alternative-asm.h
14596 @@ -18,6 +18,45 @@
14597 .endm
14598 #endif
14599
14600 +#ifdef KERNEXEC_PLUGIN
14601 + .macro pax_force_retaddr_bts rip=0
14602 + btsq $63,\rip(%rsp)
14603 + .endm
14604 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14605 + .macro pax_force_retaddr rip=0, reload=0
14606 + btsq $63,\rip(%rsp)
14607 + .endm
14608 + .macro pax_force_fptr ptr
14609 + btsq $63,\ptr
14610 + .endm
14611 + .macro pax_set_fptr_mask
14612 + .endm
14613 +#endif
14614 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14615 + .macro pax_force_retaddr rip=0, reload=0
14616 + .if \reload
14617 + pax_set_fptr_mask
14618 + .endif
14619 + orq %r12,\rip(%rsp)
14620 + .endm
14621 + .macro pax_force_fptr ptr
14622 + orq %r12,\ptr
14623 + .endm
14624 + .macro pax_set_fptr_mask
14625 + movabs $0x8000000000000000,%r12
14626 + .endm
14627 +#endif
14628 +#else
14629 + .macro pax_force_retaddr rip=0, reload=0
14630 + .endm
14631 + .macro pax_force_fptr ptr
14632 + .endm
14633 + .macro pax_force_retaddr_bts rip=0
14634 + .endm
14635 + .macro pax_set_fptr_mask
14636 + .endm
14637 +#endif
14638 +
14639 .macro altinstruction_entry orig alt feature orig_len alt_len
14640 .long \orig - .
14641 .long \alt - .
14642 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14643 index 0a3f9c9..c9d081d 100644
14644 --- a/arch/x86/include/asm/alternative.h
14645 +++ b/arch/x86/include/asm/alternative.h
14646 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14647 ".pushsection .discard,\"aw\",@progbits\n" \
14648 DISCARD_ENTRY(1) \
14649 ".popsection\n" \
14650 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14651 + ".pushsection .altinstr_replacement, \"a\"\n" \
14652 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14653 ".popsection"
14654
14655 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14656 DISCARD_ENTRY(1) \
14657 DISCARD_ENTRY(2) \
14658 ".popsection\n" \
14659 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14660 + ".pushsection .altinstr_replacement, \"a\"\n" \
14661 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14662 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14663 ".popsection"
14664 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14665 index 1d2091a..f5074c1 100644
14666 --- a/arch/x86/include/asm/apic.h
14667 +++ b/arch/x86/include/asm/apic.h
14668 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14669
14670 #ifdef CONFIG_X86_LOCAL_APIC
14671
14672 -extern unsigned int apic_verbosity;
14673 +extern int apic_verbosity;
14674 extern int local_apic_timer_c2_ok;
14675
14676 extern int disable_apic;
14677 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14678 index 20370c6..a2eb9b0 100644
14679 --- a/arch/x86/include/asm/apm.h
14680 +++ b/arch/x86/include/asm/apm.h
14681 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14682 __asm__ __volatile__(APM_DO_ZERO_SEGS
14683 "pushl %%edi\n\t"
14684 "pushl %%ebp\n\t"
14685 - "lcall *%%cs:apm_bios_entry\n\t"
14686 + "lcall *%%ss:apm_bios_entry\n\t"
14687 "setc %%al\n\t"
14688 "popl %%ebp\n\t"
14689 "popl %%edi\n\t"
14690 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14691 __asm__ __volatile__(APM_DO_ZERO_SEGS
14692 "pushl %%edi\n\t"
14693 "pushl %%ebp\n\t"
14694 - "lcall *%%cs:apm_bios_entry\n\t"
14695 + "lcall *%%ss:apm_bios_entry\n\t"
14696 "setc %%bl\n\t"
14697 "popl %%ebp\n\t"
14698 "popl %%edi\n\t"
14699 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14700 index b17f4f4..9620151 100644
14701 --- a/arch/x86/include/asm/atomic.h
14702 +++ b/arch/x86/include/asm/atomic.h
14703 @@ -23,7 +23,18 @@
14704 */
14705 static inline int atomic_read(const atomic_t *v)
14706 {
14707 - return (*(volatile int *)&(v)->counter);
14708 + return (*(volatile const int *)&(v)->counter);
14709 +}
14710 +
14711 +/**
14712 + * atomic_read_unchecked - read atomic variable
14713 + * @v: pointer of type atomic_unchecked_t
14714 + *
14715 + * Atomically reads the value of @v.
14716 + */
14717 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14718 +{
14719 + return (*(volatile const int *)&(v)->counter);
14720 }
14721
14722 /**
14723 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14724 }
14725
14726 /**
14727 + * atomic_set_unchecked - set atomic variable
14728 + * @v: pointer of type atomic_unchecked_t
14729 + * @i: required value
14730 + *
14731 + * Atomically sets the value of @v to @i.
14732 + */
14733 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14734 +{
14735 + v->counter = i;
14736 +}
14737 +
14738 +/**
14739 * atomic_add - add integer to atomic variable
14740 * @i: integer value to add
14741 * @v: pointer of type atomic_t
14742 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14743 */
14744 static inline void atomic_add(int i, atomic_t *v)
14745 {
14746 - asm volatile(LOCK_PREFIX "addl %1,%0"
14747 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14748 +
14749 +#ifdef CONFIG_PAX_REFCOUNT
14750 + "jno 0f\n"
14751 + LOCK_PREFIX "subl %1,%0\n"
14752 + "int $4\n0:\n"
14753 + _ASM_EXTABLE(0b, 0b)
14754 +#endif
14755 +
14756 + : "+m" (v->counter)
14757 + : "ir" (i));
14758 +}
14759 +
14760 +/**
14761 + * atomic_add_unchecked - add integer to atomic variable
14762 + * @i: integer value to add
14763 + * @v: pointer of type atomic_unchecked_t
14764 + *
14765 + * Atomically adds @i to @v.
14766 + */
14767 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14768 +{
14769 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14770 : "+m" (v->counter)
14771 : "ir" (i));
14772 }
14773 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14774 */
14775 static inline void atomic_sub(int i, atomic_t *v)
14776 {
14777 - asm volatile(LOCK_PREFIX "subl %1,%0"
14778 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14779 +
14780 +#ifdef CONFIG_PAX_REFCOUNT
14781 + "jno 0f\n"
14782 + LOCK_PREFIX "addl %1,%0\n"
14783 + "int $4\n0:\n"
14784 + _ASM_EXTABLE(0b, 0b)
14785 +#endif
14786 +
14787 + : "+m" (v->counter)
14788 + : "ir" (i));
14789 +}
14790 +
14791 +/**
14792 + * atomic_sub_unchecked - subtract integer from atomic variable
14793 + * @i: integer value to subtract
14794 + * @v: pointer of type atomic_unchecked_t
14795 + *
14796 + * Atomically subtracts @i from @v.
14797 + */
14798 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14799 +{
14800 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14801 : "+m" (v->counter)
14802 : "ir" (i));
14803 }
14804 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14805 */
14806 static inline int atomic_sub_and_test(int i, atomic_t *v)
14807 {
14808 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14809 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14810 }
14811
14812 /**
14813 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14814 */
14815 static inline void atomic_inc(atomic_t *v)
14816 {
14817 - asm volatile(LOCK_PREFIX "incl %0"
14818 + asm volatile(LOCK_PREFIX "incl %0\n"
14819 +
14820 +#ifdef CONFIG_PAX_REFCOUNT
14821 + "jno 0f\n"
14822 + LOCK_PREFIX "decl %0\n"
14823 + "int $4\n0:\n"
14824 + _ASM_EXTABLE(0b, 0b)
14825 +#endif
14826 +
14827 + : "+m" (v->counter));
14828 +}
14829 +
14830 +/**
14831 + * atomic_inc_unchecked - increment atomic variable
14832 + * @v: pointer of type atomic_unchecked_t
14833 + *
14834 + * Atomically increments @v by 1.
14835 + */
14836 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14837 +{
14838 + asm volatile(LOCK_PREFIX "incl %0\n"
14839 : "+m" (v->counter));
14840 }
14841
14842 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14843 */
14844 static inline void atomic_dec(atomic_t *v)
14845 {
14846 - asm volatile(LOCK_PREFIX "decl %0"
14847 + asm volatile(LOCK_PREFIX "decl %0\n"
14848 +
14849 +#ifdef CONFIG_PAX_REFCOUNT
14850 + "jno 0f\n"
14851 + LOCK_PREFIX "incl %0\n"
14852 + "int $4\n0:\n"
14853 + _ASM_EXTABLE(0b, 0b)
14854 +#endif
14855 +
14856 + : "+m" (v->counter));
14857 +}
14858 +
14859 +/**
14860 + * atomic_dec_unchecked - decrement atomic variable
14861 + * @v: pointer of type atomic_unchecked_t
14862 + *
14863 + * Atomically decrements @v by 1.
14864 + */
14865 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14866 +{
14867 + asm volatile(LOCK_PREFIX "decl %0\n"
14868 : "+m" (v->counter));
14869 }
14870
14871 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14872 */
14873 static inline int atomic_dec_and_test(atomic_t *v)
14874 {
14875 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14876 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14877 }
14878
14879 /**
14880 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14881 */
14882 static inline int atomic_inc_and_test(atomic_t *v)
14883 {
14884 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
14885 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
14886 +}
14887 +
14888 +/**
14889 + * atomic_inc_and_test_unchecked - increment and test
14890 + * @v: pointer of type atomic_unchecked_t
14891 + *
14892 + * Atomically increments @v by 1
14893 + * and returns true if the result is zero, or false for all
14894 + * other cases.
14895 + */
14896 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14897 +{
14898 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
14899 }
14900
14901 /**
14902 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
14903 */
14904 static inline int atomic_add_negative(int i, atomic_t *v)
14905 {
14906 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
14907 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
14908 }
14909
14910 /**
14911 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14912 */
14913 static inline int atomic_add_return(int i, atomic_t *v)
14914 {
14915 + return i + xadd_check_overflow(&v->counter, i);
14916 +}
14917 +
14918 +/**
14919 + * atomic_add_return_unchecked - add integer and return
14920 + * @i: integer value to add
14921 + * @v: pointer of type atomic_unchecked_t
14922 + *
14923 + * Atomically adds @i to @v and returns @i + @v
14924 + */
14925 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14926 +{
14927 return i + xadd(&v->counter, i);
14928 }
14929
14930 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14931 }
14932
14933 #define atomic_inc_return(v) (atomic_add_return(1, v))
14934 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14935 +{
14936 + return atomic_add_return_unchecked(1, v);
14937 +}
14938 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14939
14940 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14941 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14942 +{
14943 + return cmpxchg(&v->counter, old, new);
14944 +}
14945 +
14946 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14947 {
14948 return cmpxchg(&v->counter, old, new);
14949 }
14950 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
14951 return xchg(&v->counter, new);
14952 }
14953
14954 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14955 +{
14956 + return xchg(&v->counter, new);
14957 +}
14958 +
14959 /**
14960 * __atomic_add_unless - add unless the number is already a given value
14961 * @v: pointer of type atomic_t
14962 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
14963 * Atomically adds @a to @v, so long as @v was not already @u.
14964 * Returns the old value of @v.
14965 */
14966 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14967 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
14968 {
14969 - int c, old;
14970 + int c, old, new;
14971 c = atomic_read(v);
14972 for (;;) {
14973 - if (unlikely(c == (u)))
14974 + if (unlikely(c == u))
14975 break;
14976 - old = atomic_cmpxchg((v), c, c + (a));
14977 +
14978 + asm volatile("addl %2,%0\n"
14979 +
14980 +#ifdef CONFIG_PAX_REFCOUNT
14981 + "jno 0f\n"
14982 + "subl %2,%0\n"
14983 + "int $4\n0:\n"
14984 + _ASM_EXTABLE(0b, 0b)
14985 +#endif
14986 +
14987 + : "=r" (new)
14988 + : "0" (c), "ir" (a));
14989 +
14990 + old = atomic_cmpxchg(v, c, new);
14991 if (likely(old == c))
14992 break;
14993 c = old;
14994 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14995 }
14996
14997 /**
14998 + * atomic_inc_not_zero_hint - increment if not null
14999 + * @v: pointer of type atomic_t
15000 + * @hint: probable value of the atomic before the increment
15001 + *
15002 + * This version of atomic_inc_not_zero() gives a hint of probable
15003 + * value of the atomic. This helps processor to not read the memory
15004 + * before doing the atomic read/modify/write cycle, lowering
15005 + * number of bus transactions on some arches.
15006 + *
15007 + * Returns: 0 if increment was not done, 1 otherwise.
15008 + */
15009 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15010 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15011 +{
15012 + int val, c = hint, new;
15013 +
15014 + /* sanity test, should be removed by compiler if hint is a constant */
15015 + if (!hint)
15016 + return __atomic_add_unless(v, 1, 0);
15017 +
15018 + do {
15019 + asm volatile("incl %0\n"
15020 +
15021 +#ifdef CONFIG_PAX_REFCOUNT
15022 + "jno 0f\n"
15023 + "decl %0\n"
15024 + "int $4\n0:\n"
15025 + _ASM_EXTABLE(0b, 0b)
15026 +#endif
15027 +
15028 + : "=r" (new)
15029 + : "0" (c));
15030 +
15031 + val = atomic_cmpxchg(v, c, new);
15032 + if (val == c)
15033 + return 1;
15034 + c = val;
15035 + } while (c);
15036 +
15037 + return 0;
15038 +}
15039 +
15040 +/**
15041 * atomic_inc_short - increment of a short integer
15042 * @v: pointer to type int
15043 *
15044 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15045 #endif
15046
15047 /* These are x86-specific, used by some header files */
15048 -#define atomic_clear_mask(mask, addr) \
15049 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15050 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15051 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15052 +{
15053 + asm volatile(LOCK_PREFIX "andl %1,%0"
15054 + : "+m" (v->counter)
15055 + : "r" (~(mask))
15056 + : "memory");
15057 +}
15058
15059 -#define atomic_set_mask(mask, addr) \
15060 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15061 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15062 - : "memory")
15063 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15064 +{
15065 + asm volatile(LOCK_PREFIX "andl %1,%0"
15066 + : "+m" (v->counter)
15067 + : "r" (~(mask))
15068 + : "memory");
15069 +}
15070 +
15071 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15072 +{
15073 + asm volatile(LOCK_PREFIX "orl %1,%0"
15074 + : "+m" (v->counter)
15075 + : "r" (mask)
15076 + : "memory");
15077 +}
15078 +
15079 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15080 +{
15081 + asm volatile(LOCK_PREFIX "orl %1,%0"
15082 + : "+m" (v->counter)
15083 + : "r" (mask)
15084 + : "memory");
15085 +}
15086
15087 /* Atomic operations are already serializing on x86 */
15088 #define smp_mb__before_atomic_dec() barrier()
15089 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15090 index b154de7..bf18a5a 100644
15091 --- a/arch/x86/include/asm/atomic64_32.h
15092 +++ b/arch/x86/include/asm/atomic64_32.h
15093 @@ -12,6 +12,14 @@ typedef struct {
15094 u64 __aligned(8) counter;
15095 } atomic64_t;
15096
15097 +#ifdef CONFIG_PAX_REFCOUNT
15098 +typedef struct {
15099 + u64 __aligned(8) counter;
15100 +} atomic64_unchecked_t;
15101 +#else
15102 +typedef atomic64_t atomic64_unchecked_t;
15103 +#endif
15104 +
15105 #define ATOMIC64_INIT(val) { (val) }
15106
15107 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15108 @@ -37,21 +45,31 @@ typedef struct {
15109 ATOMIC64_DECL_ONE(sym##_386)
15110
15111 ATOMIC64_DECL_ONE(add_386);
15112 +ATOMIC64_DECL_ONE(add_unchecked_386);
15113 ATOMIC64_DECL_ONE(sub_386);
15114 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15115 ATOMIC64_DECL_ONE(inc_386);
15116 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15117 ATOMIC64_DECL_ONE(dec_386);
15118 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15119 #endif
15120
15121 #define alternative_atomic64(f, out, in...) \
15122 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15123
15124 ATOMIC64_DECL(read);
15125 +ATOMIC64_DECL(read_unchecked);
15126 ATOMIC64_DECL(set);
15127 +ATOMIC64_DECL(set_unchecked);
15128 ATOMIC64_DECL(xchg);
15129 ATOMIC64_DECL(add_return);
15130 +ATOMIC64_DECL(add_return_unchecked);
15131 ATOMIC64_DECL(sub_return);
15132 +ATOMIC64_DECL(sub_return_unchecked);
15133 ATOMIC64_DECL(inc_return);
15134 +ATOMIC64_DECL(inc_return_unchecked);
15135 ATOMIC64_DECL(dec_return);
15136 +ATOMIC64_DECL(dec_return_unchecked);
15137 ATOMIC64_DECL(dec_if_positive);
15138 ATOMIC64_DECL(inc_not_zero);
15139 ATOMIC64_DECL(add_unless);
15140 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15141 }
15142
15143 /**
15144 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15145 + * @p: pointer to type atomic64_unchecked_t
15146 + * @o: expected value
15147 + * @n: new value
15148 + *
15149 + * Atomically sets @v to @n if it was equal to @o and returns
15150 + * the old value.
15151 + */
15152 +
15153 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15154 +{
15155 + return cmpxchg64(&v->counter, o, n);
15156 +}
15157 +
15158 +/**
15159 * atomic64_xchg - xchg atomic64 variable
15160 * @v: pointer to type atomic64_t
15161 * @n: value to assign
15162 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15163 }
15164
15165 /**
15166 + * atomic64_set_unchecked - set atomic64 variable
15167 + * @v: pointer to type atomic64_unchecked_t
15168 + * @n: value to assign
15169 + *
15170 + * Atomically sets the value of @v to @n.
15171 + */
15172 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15173 +{
15174 + unsigned high = (unsigned)(i >> 32);
15175 + unsigned low = (unsigned)i;
15176 + alternative_atomic64(set, /* no output */,
15177 + "S" (v), "b" (low), "c" (high)
15178 + : "eax", "edx", "memory");
15179 +}
15180 +
15181 +/**
15182 * atomic64_read - read atomic64 variable
15183 * @v: pointer to type atomic64_t
15184 *
15185 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15186 }
15187
15188 /**
15189 + * atomic64_read_unchecked - read atomic64 variable
15190 + * @v: pointer to type atomic64_unchecked_t
15191 + *
15192 + * Atomically reads the value of @v and returns it.
15193 + */
15194 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15195 +{
15196 + long long r;
15197 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15198 + return r;
15199 + }
15200 +
15201 +/**
15202 * atomic64_add_return - add and return
15203 * @i: integer value to add
15204 * @v: pointer to type atomic64_t
15205 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15206 return i;
15207 }
15208
15209 +/**
15210 + * atomic64_add_return_unchecked - add and return
15211 + * @i: integer value to add
15212 + * @v: pointer to type atomic64_unchecked_t
15213 + *
15214 + * Atomically adds @i to @v and returns @i + *@v
15215 + */
15216 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15217 +{
15218 + alternative_atomic64(add_return_unchecked,
15219 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15220 + ASM_NO_INPUT_CLOBBER("memory"));
15221 + return i;
15222 +}
15223 +
15224 /*
15225 * Other variants with different arithmetic operators:
15226 */
15227 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15228 return a;
15229 }
15230
15231 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15232 +{
15233 + long long a;
15234 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15235 + "S" (v) : "memory", "ecx");
15236 + return a;
15237 +}
15238 +
15239 static inline long long atomic64_dec_return(atomic64_t *v)
15240 {
15241 long long a;
15242 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15243 }
15244
15245 /**
15246 + * atomic64_add_unchecked - add integer to atomic64 variable
15247 + * @i: integer value to add
15248 + * @v: pointer to type atomic64_unchecked_t
15249 + *
15250 + * Atomically adds @i to @v.
15251 + */
15252 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15253 +{
15254 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15255 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15256 + ASM_NO_INPUT_CLOBBER("memory"));
15257 + return i;
15258 +}
15259 +
15260 +/**
15261 * atomic64_sub - subtract the atomic64 variable
15262 * @i: integer value to subtract
15263 * @v: pointer to type atomic64_t
15264 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15265 index 46e9052..ae45136 100644
15266 --- a/arch/x86/include/asm/atomic64_64.h
15267 +++ b/arch/x86/include/asm/atomic64_64.h
15268 @@ -18,7 +18,19 @@
15269 */
15270 static inline long atomic64_read(const atomic64_t *v)
15271 {
15272 - return (*(volatile long *)&(v)->counter);
15273 + return (*(volatile const long *)&(v)->counter);
15274 +}
15275 +
15276 +/**
15277 + * atomic64_read_unchecked - read atomic64 variable
15278 + * @v: pointer of type atomic64_unchecked_t
15279 + *
15280 + * Atomically reads the value of @v.
15281 + * Doesn't imply a read memory barrier.
15282 + */
15283 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15284 +{
15285 + return (*(volatile const long *)&(v)->counter);
15286 }
15287
15288 /**
15289 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15290 }
15291
15292 /**
15293 + * atomic64_set_unchecked - set atomic64 variable
15294 + * @v: pointer to type atomic64_unchecked_t
15295 + * @i: required value
15296 + *
15297 + * Atomically sets the value of @v to @i.
15298 + */
15299 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15300 +{
15301 + v->counter = i;
15302 +}
15303 +
15304 +/**
15305 * atomic64_add - add integer to atomic64 variable
15306 * @i: integer value to add
15307 * @v: pointer to type atomic64_t
15308 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15309 */
15310 static inline void atomic64_add(long i, atomic64_t *v)
15311 {
15312 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15313 +
15314 +#ifdef CONFIG_PAX_REFCOUNT
15315 + "jno 0f\n"
15316 + LOCK_PREFIX "subq %1,%0\n"
15317 + "int $4\n0:\n"
15318 + _ASM_EXTABLE(0b, 0b)
15319 +#endif
15320 +
15321 + : "=m" (v->counter)
15322 + : "er" (i), "m" (v->counter));
15323 +}
15324 +
15325 +/**
15326 + * atomic64_add_unchecked - add integer to atomic64 variable
15327 + * @i: integer value to add
15328 + * @v: pointer to type atomic64_unchecked_t
15329 + *
15330 + * Atomically adds @i to @v.
15331 + */
15332 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15333 +{
15334 asm volatile(LOCK_PREFIX "addq %1,%0"
15335 : "=m" (v->counter)
15336 : "er" (i), "m" (v->counter));
15337 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15338 */
15339 static inline void atomic64_sub(long i, atomic64_t *v)
15340 {
15341 - asm volatile(LOCK_PREFIX "subq %1,%0"
15342 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15343 +
15344 +#ifdef CONFIG_PAX_REFCOUNT
15345 + "jno 0f\n"
15346 + LOCK_PREFIX "addq %1,%0\n"
15347 + "int $4\n0:\n"
15348 + _ASM_EXTABLE(0b, 0b)
15349 +#endif
15350 +
15351 + : "=m" (v->counter)
15352 + : "er" (i), "m" (v->counter));
15353 +}
15354 +
15355 +/**
15356 + * atomic64_sub_unchecked - subtract the atomic64 variable
15357 + * @i: integer value to subtract
15358 + * @v: pointer to type atomic64_unchecked_t
15359 + *
15360 + * Atomically subtracts @i from @v.
15361 + */
15362 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15363 +{
15364 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15365 : "=m" (v->counter)
15366 : "er" (i), "m" (v->counter));
15367 }
15368 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15369 */
15370 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15371 {
15372 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15373 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15374 }
15375
15376 /**
15377 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15378 */
15379 static inline void atomic64_inc(atomic64_t *v)
15380 {
15381 + asm volatile(LOCK_PREFIX "incq %0\n"
15382 +
15383 +#ifdef CONFIG_PAX_REFCOUNT
15384 + "jno 0f\n"
15385 + LOCK_PREFIX "decq %0\n"
15386 + "int $4\n0:\n"
15387 + _ASM_EXTABLE(0b, 0b)
15388 +#endif
15389 +
15390 + : "=m" (v->counter)
15391 + : "m" (v->counter));
15392 +}
15393 +
15394 +/**
15395 + * atomic64_inc_unchecked - increment atomic64 variable
15396 + * @v: pointer to type atomic64_unchecked_t
15397 + *
15398 + * Atomically increments @v by 1.
15399 + */
15400 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15401 +{
15402 asm volatile(LOCK_PREFIX "incq %0"
15403 : "=m" (v->counter)
15404 : "m" (v->counter));
15405 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15406 */
15407 static inline void atomic64_dec(atomic64_t *v)
15408 {
15409 - asm volatile(LOCK_PREFIX "decq %0"
15410 + asm volatile(LOCK_PREFIX "decq %0\n"
15411 +
15412 +#ifdef CONFIG_PAX_REFCOUNT
15413 + "jno 0f\n"
15414 + LOCK_PREFIX "incq %0\n"
15415 + "int $4\n0:\n"
15416 + _ASM_EXTABLE(0b, 0b)
15417 +#endif
15418 +
15419 + : "=m" (v->counter)
15420 + : "m" (v->counter));
15421 +}
15422 +
15423 +/**
15424 + * atomic64_dec_unchecked - decrement atomic64 variable
15425 + * @v: pointer to type atomic64_t
15426 + *
15427 + * Atomically decrements @v by 1.
15428 + */
15429 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15430 +{
15431 + asm volatile(LOCK_PREFIX "decq %0\n"
15432 : "=m" (v->counter)
15433 : "m" (v->counter));
15434 }
15435 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15436 */
15437 static inline int atomic64_dec_and_test(atomic64_t *v)
15438 {
15439 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15440 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15441 }
15442
15443 /**
15444 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15445 */
15446 static inline int atomic64_inc_and_test(atomic64_t *v)
15447 {
15448 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15449 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15450 }
15451
15452 /**
15453 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15454 */
15455 static inline int atomic64_add_negative(long i, atomic64_t *v)
15456 {
15457 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15458 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15459 }
15460
15461 /**
15462 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15463 */
15464 static inline long atomic64_add_return(long i, atomic64_t *v)
15465 {
15466 + return i + xadd_check_overflow(&v->counter, i);
15467 +}
15468 +
15469 +/**
15470 + * atomic64_add_return_unchecked - add and return
15471 + * @i: integer value to add
15472 + * @v: pointer to type atomic64_unchecked_t
15473 + *
15474 + * Atomically adds @i to @v and returns @i + @v
15475 + */
15476 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15477 +{
15478 return i + xadd(&v->counter, i);
15479 }
15480
15481 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15482 }
15483
15484 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15485 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15486 +{
15487 + return atomic64_add_return_unchecked(1, v);
15488 +}
15489 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15490
15491 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15492 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15493 return cmpxchg(&v->counter, old, new);
15494 }
15495
15496 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15497 +{
15498 + return cmpxchg(&v->counter, old, new);
15499 +}
15500 +
15501 static inline long atomic64_xchg(atomic64_t *v, long new)
15502 {
15503 return xchg(&v->counter, new);
15504 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15505 */
15506 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15507 {
15508 - long c, old;
15509 + long c, old, new;
15510 c = atomic64_read(v);
15511 for (;;) {
15512 - if (unlikely(c == (u)))
15513 + if (unlikely(c == u))
15514 break;
15515 - old = atomic64_cmpxchg((v), c, c + (a));
15516 +
15517 + asm volatile("add %2,%0\n"
15518 +
15519 +#ifdef CONFIG_PAX_REFCOUNT
15520 + "jno 0f\n"
15521 + "sub %2,%0\n"
15522 + "int $4\n0:\n"
15523 + _ASM_EXTABLE(0b, 0b)
15524 +#endif
15525 +
15526 + : "=r" (new)
15527 + : "0" (c), "ir" (a));
15528 +
15529 + old = atomic64_cmpxchg(v, c, new);
15530 if (likely(old == c))
15531 break;
15532 c = old;
15533 }
15534 - return c != (u);
15535 + return c != u;
15536 }
15537
15538 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15539 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15540 index 9fc1af7..fc71228 100644
15541 --- a/arch/x86/include/asm/bitops.h
15542 +++ b/arch/x86/include/asm/bitops.h
15543 @@ -49,7 +49,7 @@
15544 * a mask operation on a byte.
15545 */
15546 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15547 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15548 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15549 #define CONST_MASK(nr) (1 << ((nr) & 7))
15550
15551 /**
15552 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15553 */
15554 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15555 {
15556 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15557 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15558 }
15559
15560 /**
15561 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15562 */
15563 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15564 {
15565 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15566 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15567 }
15568
15569 /**
15570 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15571 */
15572 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15573 {
15574 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15575 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15576 }
15577
15578 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15579 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15580 *
15581 * Undefined if no bit exists, so code should check against 0 first.
15582 */
15583 -static inline unsigned long __ffs(unsigned long word)
15584 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15585 {
15586 asm("rep; bsf %1,%0"
15587 : "=r" (word)
15588 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15589 *
15590 * Undefined if no zero exists, so code should check against ~0UL first.
15591 */
15592 -static inline unsigned long ffz(unsigned long word)
15593 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15594 {
15595 asm("rep; bsf %1,%0"
15596 : "=r" (word)
15597 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15598 *
15599 * Undefined if no set bit exists, so code should check against 0 first.
15600 */
15601 -static inline unsigned long __fls(unsigned long word)
15602 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15603 {
15604 asm("bsr %1,%0"
15605 : "=r" (word)
15606 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15607 * set bit if value is nonzero. The last (most significant) bit is
15608 * at position 32.
15609 */
15610 -static inline int fls(int x)
15611 +static inline int __intentional_overflow(-1) fls(int x)
15612 {
15613 int r;
15614
15615 @@ -478,7 +478,7 @@ static inline int fls(int x)
15616 * at position 64.
15617 */
15618 #ifdef CONFIG_X86_64
15619 -static __always_inline int fls64(__u64 x)
15620 +static __always_inline long fls64(__u64 x)
15621 {
15622 int bitpos = -1;
15623 /*
15624 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15625 index 4fa687a..60f2d39 100644
15626 --- a/arch/x86/include/asm/boot.h
15627 +++ b/arch/x86/include/asm/boot.h
15628 @@ -6,10 +6,15 @@
15629 #include <uapi/asm/boot.h>
15630
15631 /* Physical address where kernel should be loaded. */
15632 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15633 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15634 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15635 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15636
15637 +#ifndef __ASSEMBLY__
15638 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15639 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15640 +#endif
15641 +
15642 /* Minimum kernel alignment, as a power of two */
15643 #ifdef CONFIG_X86_64
15644 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15645 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15646 index 48f99f1..d78ebf9 100644
15647 --- a/arch/x86/include/asm/cache.h
15648 +++ b/arch/x86/include/asm/cache.h
15649 @@ -5,12 +5,13 @@
15650
15651 /* L1 cache line size */
15652 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15653 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15654 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15655
15656 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15657 +#define __read_only __attribute__((__section__(".data..read_only")))
15658
15659 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15660 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15661 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15662
15663 #ifdef CONFIG_X86_VSMP
15664 #ifdef CONFIG_SMP
15665 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15666 index 9863ee3..4a1f8e1 100644
15667 --- a/arch/x86/include/asm/cacheflush.h
15668 +++ b/arch/x86/include/asm/cacheflush.h
15669 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15670 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15671
15672 if (pg_flags == _PGMT_DEFAULT)
15673 - return -1;
15674 + return ~0UL;
15675 else if (pg_flags == _PGMT_WC)
15676 return _PAGE_CACHE_WC;
15677 else if (pg_flags == _PGMT_UC_MINUS)
15678 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15679 index cb4c73b..c473c29 100644
15680 --- a/arch/x86/include/asm/calling.h
15681 +++ b/arch/x86/include/asm/calling.h
15682 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15683 #define RSP 152
15684 #define SS 160
15685
15686 -#define ARGOFFSET R11
15687 -#define SWFRAME ORIG_RAX
15688 +#define ARGOFFSET R15
15689
15690 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15691 - subq $9*8+\addskip, %rsp
15692 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15693 - movq_cfi rdi, 8*8
15694 - movq_cfi rsi, 7*8
15695 - movq_cfi rdx, 6*8
15696 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15697 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15698 + movq_cfi rdi, RDI
15699 + movq_cfi rsi, RSI
15700 + movq_cfi rdx, RDX
15701
15702 .if \save_rcx
15703 - movq_cfi rcx, 5*8
15704 + movq_cfi rcx, RCX
15705 .endif
15706
15707 - movq_cfi rax, 4*8
15708 + movq_cfi rax, RAX
15709
15710 .if \save_r891011
15711 - movq_cfi r8, 3*8
15712 - movq_cfi r9, 2*8
15713 - movq_cfi r10, 1*8
15714 - movq_cfi r11, 0*8
15715 + movq_cfi r8, R8
15716 + movq_cfi r9, R9
15717 + movq_cfi r10, R10
15718 + movq_cfi r11, R11
15719 .endif
15720
15721 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15722 + movq_cfi r12, R12
15723 +#endif
15724 +
15725 .endm
15726
15727 -#define ARG_SKIP (9*8)
15728 +#define ARG_SKIP ORIG_RAX
15729
15730 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15731 rstor_r8910=1, rstor_rdx=1
15732 +
15733 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15734 + movq_cfi_restore R12, r12
15735 +#endif
15736 +
15737 .if \rstor_r11
15738 - movq_cfi_restore 0*8, r11
15739 + movq_cfi_restore R11, r11
15740 .endif
15741
15742 .if \rstor_r8910
15743 - movq_cfi_restore 1*8, r10
15744 - movq_cfi_restore 2*8, r9
15745 - movq_cfi_restore 3*8, r8
15746 + movq_cfi_restore R10, r10
15747 + movq_cfi_restore R9, r9
15748 + movq_cfi_restore R8, r8
15749 .endif
15750
15751 .if \rstor_rax
15752 - movq_cfi_restore 4*8, rax
15753 + movq_cfi_restore RAX, rax
15754 .endif
15755
15756 .if \rstor_rcx
15757 - movq_cfi_restore 5*8, rcx
15758 + movq_cfi_restore RCX, rcx
15759 .endif
15760
15761 .if \rstor_rdx
15762 - movq_cfi_restore 6*8, rdx
15763 + movq_cfi_restore RDX, rdx
15764 .endif
15765
15766 - movq_cfi_restore 7*8, rsi
15767 - movq_cfi_restore 8*8, rdi
15768 + movq_cfi_restore RSI, rsi
15769 + movq_cfi_restore RDI, rdi
15770
15771 - .if ARG_SKIP+\addskip > 0
15772 - addq $ARG_SKIP+\addskip, %rsp
15773 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15774 + .if ORIG_RAX+\addskip > 0
15775 + addq $ORIG_RAX+\addskip, %rsp
15776 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15777 .endif
15778 .endm
15779
15780 - .macro LOAD_ARGS offset, skiprax=0
15781 - movq \offset(%rsp), %r11
15782 - movq \offset+8(%rsp), %r10
15783 - movq \offset+16(%rsp), %r9
15784 - movq \offset+24(%rsp), %r8
15785 - movq \offset+40(%rsp), %rcx
15786 - movq \offset+48(%rsp), %rdx
15787 - movq \offset+56(%rsp), %rsi
15788 - movq \offset+64(%rsp), %rdi
15789 + .macro LOAD_ARGS skiprax=0
15790 + movq R11(%rsp), %r11
15791 + movq R10(%rsp), %r10
15792 + movq R9(%rsp), %r9
15793 + movq R8(%rsp), %r8
15794 + movq RCX(%rsp), %rcx
15795 + movq RDX(%rsp), %rdx
15796 + movq RSI(%rsp), %rsi
15797 + movq RDI(%rsp), %rdi
15798 .if \skiprax
15799 .else
15800 - movq \offset+72(%rsp), %rax
15801 + movq RAX(%rsp), %rax
15802 .endif
15803 .endm
15804
15805 -#define REST_SKIP (6*8)
15806 -
15807 .macro SAVE_REST
15808 - subq $REST_SKIP, %rsp
15809 - CFI_ADJUST_CFA_OFFSET REST_SKIP
15810 - movq_cfi rbx, 5*8
15811 - movq_cfi rbp, 4*8
15812 - movq_cfi r12, 3*8
15813 - movq_cfi r13, 2*8
15814 - movq_cfi r14, 1*8
15815 - movq_cfi r15, 0*8
15816 + movq_cfi rbx, RBX
15817 + movq_cfi rbp, RBP
15818 +
15819 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15820 + movq_cfi r12, R12
15821 +#endif
15822 +
15823 + movq_cfi r13, R13
15824 + movq_cfi r14, R14
15825 + movq_cfi r15, R15
15826 .endm
15827
15828 .macro RESTORE_REST
15829 - movq_cfi_restore 0*8, r15
15830 - movq_cfi_restore 1*8, r14
15831 - movq_cfi_restore 2*8, r13
15832 - movq_cfi_restore 3*8, r12
15833 - movq_cfi_restore 4*8, rbp
15834 - movq_cfi_restore 5*8, rbx
15835 - addq $REST_SKIP, %rsp
15836 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15837 + movq_cfi_restore R15, r15
15838 + movq_cfi_restore R14, r14
15839 + movq_cfi_restore R13, r13
15840 +
15841 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15842 + movq_cfi_restore R12, r12
15843 +#endif
15844 +
15845 + movq_cfi_restore RBP, rbp
15846 + movq_cfi_restore RBX, rbx
15847 .endm
15848
15849 .macro SAVE_ALL
15850 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15851 index f50de69..2b0a458 100644
15852 --- a/arch/x86/include/asm/checksum_32.h
15853 +++ b/arch/x86/include/asm/checksum_32.h
15854 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15855 int len, __wsum sum,
15856 int *src_err_ptr, int *dst_err_ptr);
15857
15858 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15859 + int len, __wsum sum,
15860 + int *src_err_ptr, int *dst_err_ptr);
15861 +
15862 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15863 + int len, __wsum sum,
15864 + int *src_err_ptr, int *dst_err_ptr);
15865 +
15866 /*
15867 * Note: when you get a NULL pointer exception here this means someone
15868 * passed in an incorrect kernel address to one of these functions.
15869 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15870
15871 might_sleep();
15872 stac();
15873 - ret = csum_partial_copy_generic((__force void *)src, dst,
15874 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15875 len, sum, err_ptr, NULL);
15876 clac();
15877
15878 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15879 might_sleep();
15880 if (access_ok(VERIFY_WRITE, dst, len)) {
15881 stac();
15882 - ret = csum_partial_copy_generic(src, (__force void *)dst,
15883 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15884 len, sum, NULL, err_ptr);
15885 clac();
15886 return ret;
15887 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15888 index d47786a..ce1b05d 100644
15889 --- a/arch/x86/include/asm/cmpxchg.h
15890 +++ b/arch/x86/include/asm/cmpxchg.h
15891 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15892 __compiletime_error("Bad argument size for cmpxchg");
15893 extern void __xadd_wrong_size(void)
15894 __compiletime_error("Bad argument size for xadd");
15895 +extern void __xadd_check_overflow_wrong_size(void)
15896 + __compiletime_error("Bad argument size for xadd_check_overflow");
15897 extern void __add_wrong_size(void)
15898 __compiletime_error("Bad argument size for add");
15899 +extern void __add_check_overflow_wrong_size(void)
15900 + __compiletime_error("Bad argument size for add_check_overflow");
15901
15902 /*
15903 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15904 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
15905 __ret; \
15906 })
15907
15908 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15909 + ({ \
15910 + __typeof__ (*(ptr)) __ret = (arg); \
15911 + switch (sizeof(*(ptr))) { \
15912 + case __X86_CASE_L: \
15913 + asm volatile (lock #op "l %0, %1\n" \
15914 + "jno 0f\n" \
15915 + "mov %0,%1\n" \
15916 + "int $4\n0:\n" \
15917 + _ASM_EXTABLE(0b, 0b) \
15918 + : "+r" (__ret), "+m" (*(ptr)) \
15919 + : : "memory", "cc"); \
15920 + break; \
15921 + case __X86_CASE_Q: \
15922 + asm volatile (lock #op "q %q0, %1\n" \
15923 + "jno 0f\n" \
15924 + "mov %0,%1\n" \
15925 + "int $4\n0:\n" \
15926 + _ASM_EXTABLE(0b, 0b) \
15927 + : "+r" (__ret), "+m" (*(ptr)) \
15928 + : : "memory", "cc"); \
15929 + break; \
15930 + default: \
15931 + __ ## op ## _check_overflow_wrong_size(); \
15932 + } \
15933 + __ret; \
15934 + })
15935 +
15936 /*
15937 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15938 * Since this is generally used to protect other memory information, we
15939 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
15940 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15941 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15942
15943 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15944 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15945 +
15946 #define __add(ptr, inc, lock) \
15947 ({ \
15948 __typeof__ (*(ptr)) __ret = (inc); \
15949 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15950 index 59c6c40..5e0b22c 100644
15951 --- a/arch/x86/include/asm/compat.h
15952 +++ b/arch/x86/include/asm/compat.h
15953 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15954 typedef u32 compat_uint_t;
15955 typedef u32 compat_ulong_t;
15956 typedef u64 __attribute__((aligned(4))) compat_u64;
15957 -typedef u32 compat_uptr_t;
15958 +typedef u32 __user compat_uptr_t;
15959
15960 struct compat_timespec {
15961 compat_time_t tv_sec;
15962 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
15963 index e099f95..5aa0fb2 100644
15964 --- a/arch/x86/include/asm/cpufeature.h
15965 +++ b/arch/x86/include/asm/cpufeature.h
15966 @@ -203,7 +203,7 @@
15967 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
15968 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
15969 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
15970 -
15971 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
15972
15973 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
15974 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
15975 @@ -211,7 +211,7 @@
15976 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
15977 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
15978 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
15979 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
15980 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
15981 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
15982 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
15983 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
15984 @@ -354,6 +354,7 @@ extern const char * const x86_power_flags[32];
15985 #undef cpu_has_centaur_mcr
15986 #define cpu_has_centaur_mcr 0
15987
15988 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
15989 #endif /* CONFIG_X86_64 */
15990
15991 #if __GNUC__ >= 4
15992 @@ -406,7 +407,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15993
15994 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
15995 t_warn:
15996 - warn_pre_alternatives();
15997 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
15998 + warn_pre_alternatives();
15999 return false;
16000 #endif
16001
16002 @@ -426,7 +428,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16003 ".section .discard,\"aw\",@progbits\n"
16004 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16005 ".previous\n"
16006 - ".section .altinstr_replacement,\"ax\"\n"
16007 + ".section .altinstr_replacement,\"a\"\n"
16008 "3: movb $1,%0\n"
16009 "4:\n"
16010 ".previous\n"
16011 @@ -463,7 +465,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16012 " .byte 2b - 1b\n" /* src len */
16013 " .byte 4f - 3f\n" /* repl len */
16014 ".previous\n"
16015 - ".section .altinstr_replacement,\"ax\"\n"
16016 + ".section .altinstr_replacement,\"a\"\n"
16017 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16018 "4:\n"
16019 ".previous\n"
16020 @@ -496,7 +498,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16021 ".section .discard,\"aw\",@progbits\n"
16022 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16023 ".previous\n"
16024 - ".section .altinstr_replacement,\"ax\"\n"
16025 + ".section .altinstr_replacement,\"a\"\n"
16026 "3: movb $0,%0\n"
16027 "4:\n"
16028 ".previous\n"
16029 @@ -510,7 +512,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16030 ".section .discard,\"aw\",@progbits\n"
16031 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16032 ".previous\n"
16033 - ".section .altinstr_replacement,\"ax\"\n"
16034 + ".section .altinstr_replacement,\"a\"\n"
16035 "5: movb $1,%0\n"
16036 "6:\n"
16037 ".previous\n"
16038 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16039 index 50d033a..37deb26 100644
16040 --- a/arch/x86/include/asm/desc.h
16041 +++ b/arch/x86/include/asm/desc.h
16042 @@ -4,6 +4,7 @@
16043 #include <asm/desc_defs.h>
16044 #include <asm/ldt.h>
16045 #include <asm/mmu.h>
16046 +#include <asm/pgtable.h>
16047
16048 #include <linux/smp.h>
16049 #include <linux/percpu.h>
16050 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16051
16052 desc->type = (info->read_exec_only ^ 1) << 1;
16053 desc->type |= info->contents << 2;
16054 + desc->type |= info->seg_not_present ^ 1;
16055
16056 desc->s = 1;
16057 desc->dpl = 0x3;
16058 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16059 }
16060
16061 extern struct desc_ptr idt_descr;
16062 -extern gate_desc idt_table[];
16063 -extern struct desc_ptr debug_idt_descr;
16064 -extern gate_desc debug_idt_table[];
16065 -
16066 -struct gdt_page {
16067 - struct desc_struct gdt[GDT_ENTRIES];
16068 -} __attribute__((aligned(PAGE_SIZE)));
16069 -
16070 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16071 +extern gate_desc idt_table[IDT_ENTRIES];
16072 +extern const struct desc_ptr debug_idt_descr;
16073 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16074
16075 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16076 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16077 {
16078 - return per_cpu(gdt_page, cpu).gdt;
16079 + return cpu_gdt_table[cpu];
16080 }
16081
16082 #ifdef CONFIG_X86_64
16083 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16084 unsigned long base, unsigned dpl, unsigned flags,
16085 unsigned short seg)
16086 {
16087 - gate->a = (seg << 16) | (base & 0xffff);
16088 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16089 + gate->gate.offset_low = base;
16090 + gate->gate.seg = seg;
16091 + gate->gate.reserved = 0;
16092 + gate->gate.type = type;
16093 + gate->gate.s = 0;
16094 + gate->gate.dpl = dpl;
16095 + gate->gate.p = 1;
16096 + gate->gate.offset_high = base >> 16;
16097 }
16098
16099 #endif
16100 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16101
16102 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16103 {
16104 + pax_open_kernel();
16105 memcpy(&idt[entry], gate, sizeof(*gate));
16106 + pax_close_kernel();
16107 }
16108
16109 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16110 {
16111 + pax_open_kernel();
16112 memcpy(&ldt[entry], desc, 8);
16113 + pax_close_kernel();
16114 }
16115
16116 static inline void
16117 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16118 default: size = sizeof(*gdt); break;
16119 }
16120
16121 + pax_open_kernel();
16122 memcpy(&gdt[entry], desc, size);
16123 + pax_close_kernel();
16124 }
16125
16126 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16127 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16128
16129 static inline void native_load_tr_desc(void)
16130 {
16131 + pax_open_kernel();
16132 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16133 + pax_close_kernel();
16134 }
16135
16136 static inline void native_load_gdt(const struct desc_ptr *dtr)
16137 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16138 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16139 unsigned int i;
16140
16141 + pax_open_kernel();
16142 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16143 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16144 + pax_close_kernel();
16145 }
16146
16147 #define _LDT_empty(info) \
16148 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16149 preempt_enable();
16150 }
16151
16152 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16153 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16154 {
16155 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16156 }
16157 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16158 }
16159
16160 #ifdef CONFIG_X86_64
16161 -static inline void set_nmi_gate(int gate, void *addr)
16162 +static inline void set_nmi_gate(int gate, const void *addr)
16163 {
16164 gate_desc s;
16165
16166 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16167 #endif
16168
16169 #ifdef CONFIG_TRACING
16170 -extern struct desc_ptr trace_idt_descr;
16171 -extern gate_desc trace_idt_table[];
16172 +extern const struct desc_ptr trace_idt_descr;
16173 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16174 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16175 {
16176 write_idt_entry(trace_idt_table, entry, gate);
16177 }
16178
16179 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16180 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16181 unsigned dpl, unsigned ist, unsigned seg)
16182 {
16183 gate_desc s;
16184 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16185 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16186 #endif
16187
16188 -static inline void _set_gate(int gate, unsigned type, void *addr,
16189 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16190 unsigned dpl, unsigned ist, unsigned seg)
16191 {
16192 gate_desc s;
16193 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16194 #define set_intr_gate(n, addr) \
16195 do { \
16196 BUG_ON((unsigned)n > 0xFF); \
16197 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16198 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16199 __KERNEL_CS); \
16200 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16201 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16202 0, 0, __KERNEL_CS); \
16203 } while (0)
16204
16205 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16206 /*
16207 * This routine sets up an interrupt gate at directory privilege level 3.
16208 */
16209 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16210 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16211 {
16212 BUG_ON((unsigned)n > 0xFF);
16213 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16214 }
16215
16216 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16217 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16218 {
16219 BUG_ON((unsigned)n > 0xFF);
16220 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16221 }
16222
16223 -static inline void set_trap_gate(unsigned int n, void *addr)
16224 +static inline void set_trap_gate(unsigned int n, const void *addr)
16225 {
16226 BUG_ON((unsigned)n > 0xFF);
16227 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16228 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16229 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16230 {
16231 BUG_ON((unsigned)n > 0xFF);
16232 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16233 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16234 }
16235
16236 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16237 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16238 {
16239 BUG_ON((unsigned)n > 0xFF);
16240 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16241 }
16242
16243 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16244 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16245 {
16246 BUG_ON((unsigned)n > 0xFF);
16247 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16248 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16249 else
16250 load_idt((const struct desc_ptr *)&idt_descr);
16251 }
16252 +
16253 +#ifdef CONFIG_X86_32
16254 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16255 +{
16256 + struct desc_struct d;
16257 +
16258 + if (likely(limit))
16259 + limit = (limit - 1UL) >> PAGE_SHIFT;
16260 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16261 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16262 +}
16263 +#endif
16264 +
16265 #endif /* _ASM_X86_DESC_H */
16266 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16267 index 278441f..b95a174 100644
16268 --- a/arch/x86/include/asm/desc_defs.h
16269 +++ b/arch/x86/include/asm/desc_defs.h
16270 @@ -31,6 +31,12 @@ struct desc_struct {
16271 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16272 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16273 };
16274 + struct {
16275 + u16 offset_low;
16276 + u16 seg;
16277 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16278 + unsigned offset_high: 16;
16279 + } gate;
16280 };
16281 } __attribute__((packed));
16282
16283 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16284 index ced283a..ffe04cc 100644
16285 --- a/arch/x86/include/asm/div64.h
16286 +++ b/arch/x86/include/asm/div64.h
16287 @@ -39,7 +39,7 @@
16288 __mod; \
16289 })
16290
16291 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16292 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16293 {
16294 union {
16295 u64 v64;
16296 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16297 index 9c999c1..3860cb8 100644
16298 --- a/arch/x86/include/asm/elf.h
16299 +++ b/arch/x86/include/asm/elf.h
16300 @@ -243,7 +243,25 @@ extern int force_personality32;
16301 the loader. We need to make sure that it is out of the way of the program
16302 that it will "exec", and that there is sufficient room for the brk. */
16303
16304 +#ifdef CONFIG_PAX_SEGMEXEC
16305 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16306 +#else
16307 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16308 +#endif
16309 +
16310 +#ifdef CONFIG_PAX_ASLR
16311 +#ifdef CONFIG_X86_32
16312 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16313 +
16314 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16315 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16316 +#else
16317 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16318 +
16319 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16320 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16321 +#endif
16322 +#endif
16323
16324 /* This yields a mask that user programs can use to figure out what
16325 instruction set this CPU supports. This could be done in user space,
16326 @@ -296,16 +314,12 @@ do { \
16327
16328 #define ARCH_DLINFO \
16329 do { \
16330 - if (vdso_enabled) \
16331 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16332 - (unsigned long)current->mm->context.vdso); \
16333 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16334 } while (0)
16335
16336 #define ARCH_DLINFO_X32 \
16337 do { \
16338 - if (vdso_enabled) \
16339 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16340 - (unsigned long)current->mm->context.vdso); \
16341 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16342 } while (0)
16343
16344 #define AT_SYSINFO 32
16345 @@ -320,7 +334,7 @@ else \
16346
16347 #endif /* !CONFIG_X86_32 */
16348
16349 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16350 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16351
16352 #define VDSO_ENTRY \
16353 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16354 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16355 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16356 #define compat_arch_setup_additional_pages syscall32_setup_pages
16357
16358 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16359 -#define arch_randomize_brk arch_randomize_brk
16360 -
16361 /*
16362 * True on X86_32 or when emulating IA32 on X86_64
16363 */
16364 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16365 index 77a99ac..39ff7f5 100644
16366 --- a/arch/x86/include/asm/emergency-restart.h
16367 +++ b/arch/x86/include/asm/emergency-restart.h
16368 @@ -1,6 +1,6 @@
16369 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16370 #define _ASM_X86_EMERGENCY_RESTART_H
16371
16372 -extern void machine_emergency_restart(void);
16373 +extern void machine_emergency_restart(void) __noreturn;
16374
16375 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16376 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16377 index d3d7469..677ef72 100644
16378 --- a/arch/x86/include/asm/floppy.h
16379 +++ b/arch/x86/include/asm/floppy.h
16380 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16381 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16382 } fd_routine[] = {
16383 {
16384 - request_dma,
16385 - free_dma,
16386 - get_dma_residue,
16387 - dma_mem_alloc,
16388 - hard_dma_setup
16389 + ._request_dma = request_dma,
16390 + ._free_dma = free_dma,
16391 + ._get_dma_residue = get_dma_residue,
16392 + ._dma_mem_alloc = dma_mem_alloc,
16393 + ._dma_setup = hard_dma_setup
16394 },
16395 {
16396 - vdma_request_dma,
16397 - vdma_nop,
16398 - vdma_get_dma_residue,
16399 - vdma_mem_alloc,
16400 - vdma_dma_setup
16401 + ._request_dma = vdma_request_dma,
16402 + ._free_dma = vdma_nop,
16403 + ._get_dma_residue = vdma_get_dma_residue,
16404 + ._dma_mem_alloc = vdma_mem_alloc,
16405 + ._dma_setup = vdma_dma_setup
16406 }
16407 };
16408
16409 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16410 index cea1c76..6c0d79b 100644
16411 --- a/arch/x86/include/asm/fpu-internal.h
16412 +++ b/arch/x86/include/asm/fpu-internal.h
16413 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16414 #define user_insn(insn, output, input...) \
16415 ({ \
16416 int err; \
16417 + pax_open_userland(); \
16418 asm volatile(ASM_STAC "\n" \
16419 - "1:" #insn "\n\t" \
16420 + "1:" \
16421 + __copyuser_seg \
16422 + #insn "\n\t" \
16423 "2: " ASM_CLAC "\n" \
16424 ".section .fixup,\"ax\"\n" \
16425 "3: movl $-1,%[err]\n" \
16426 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16427 _ASM_EXTABLE(1b, 3b) \
16428 : [err] "=r" (err), output \
16429 : "0"(0), input); \
16430 + pax_close_userland(); \
16431 err; \
16432 })
16433
16434 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16435 "fnclex\n\t"
16436 "emms\n\t"
16437 "fildl %P[addr]" /* set F?P to defined value */
16438 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16439 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16440 }
16441
16442 return fpu_restore_checking(&tsk->thread.fpu);
16443 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16444 index b4c1f54..e290c08 100644
16445 --- a/arch/x86/include/asm/futex.h
16446 +++ b/arch/x86/include/asm/futex.h
16447 @@ -12,6 +12,7 @@
16448 #include <asm/smap.h>
16449
16450 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16451 + typecheck(u32 __user *, uaddr); \
16452 asm volatile("\t" ASM_STAC "\n" \
16453 "1:\t" insn "\n" \
16454 "2:\t" ASM_CLAC "\n" \
16455 @@ -20,15 +21,16 @@
16456 "\tjmp\t2b\n" \
16457 "\t.previous\n" \
16458 _ASM_EXTABLE(1b, 3b) \
16459 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16460 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16461 : "i" (-EFAULT), "0" (oparg), "1" (0))
16462
16463 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16464 + typecheck(u32 __user *, uaddr); \
16465 asm volatile("\t" ASM_STAC "\n" \
16466 "1:\tmovl %2, %0\n" \
16467 "\tmovl\t%0, %3\n" \
16468 "\t" insn "\n" \
16469 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16470 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16471 "\tjnz\t1b\n" \
16472 "3:\t" ASM_CLAC "\n" \
16473 "\t.section .fixup,\"ax\"\n" \
16474 @@ -38,7 +40,7 @@
16475 _ASM_EXTABLE(1b, 4b) \
16476 _ASM_EXTABLE(2b, 4b) \
16477 : "=&a" (oldval), "=&r" (ret), \
16478 - "+m" (*uaddr), "=&r" (tem) \
16479 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16480 : "r" (oparg), "i" (-EFAULT), "1" (0))
16481
16482 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16483 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16484
16485 pagefault_disable();
16486
16487 + pax_open_userland();
16488 switch (op) {
16489 case FUTEX_OP_SET:
16490 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16491 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16492 break;
16493 case FUTEX_OP_ADD:
16494 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16495 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16496 uaddr, oparg);
16497 break;
16498 case FUTEX_OP_OR:
16499 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16500 default:
16501 ret = -ENOSYS;
16502 }
16503 + pax_close_userland();
16504
16505 pagefault_enable();
16506
16507 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16508 index 67d69b8..50e4b77 100644
16509 --- a/arch/x86/include/asm/hw_irq.h
16510 +++ b/arch/x86/include/asm/hw_irq.h
16511 @@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16512 extern void enable_IO_APIC(void);
16513
16514 /* Statistics */
16515 -extern atomic_t irq_err_count;
16516 -extern atomic_t irq_mis_count;
16517 +extern atomic_unchecked_t irq_err_count;
16518 +extern atomic_unchecked_t irq_mis_count;
16519
16520 /* EISA */
16521 extern void eisa_set_level_irq(unsigned int irq);
16522 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16523 index a203659..9889f1c 100644
16524 --- a/arch/x86/include/asm/i8259.h
16525 +++ b/arch/x86/include/asm/i8259.h
16526 @@ -62,7 +62,7 @@ struct legacy_pic {
16527 void (*init)(int auto_eoi);
16528 int (*irq_pending)(unsigned int irq);
16529 void (*make_irq)(unsigned int irq);
16530 -};
16531 +} __do_const;
16532
16533 extern struct legacy_pic *legacy_pic;
16534 extern struct legacy_pic null_legacy_pic;
16535 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16536 index 91d9c69..dfae7d0 100644
16537 --- a/arch/x86/include/asm/io.h
16538 +++ b/arch/x86/include/asm/io.h
16539 @@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16540 "m" (*(volatile type __force *)addr) barrier); }
16541
16542 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16543 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16544 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16545 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16546 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16547
16548 build_mmio_read(__readb, "b", unsigned char, "=q", )
16549 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16550 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16551 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16552 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16553
16554 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16555 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16556 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16557 return ioremap_nocache(offset, size);
16558 }
16559
16560 -extern void iounmap(volatile void __iomem *addr);
16561 +extern void iounmap(const volatile void __iomem *addr);
16562
16563 extern void set_iounmap_nonlazy(void);
16564
16565 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16566
16567 #include <linux/vmalloc.h>
16568
16569 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16570 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16571 +{
16572 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16573 +}
16574 +
16575 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16576 +{
16577 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16578 +}
16579 +
16580 /*
16581 * Convert a virtual cached pointer to an uncached pointer
16582 */
16583 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16584 index bba3cf8..06bc8da 100644
16585 --- a/arch/x86/include/asm/irqflags.h
16586 +++ b/arch/x86/include/asm/irqflags.h
16587 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16588 sti; \
16589 sysexit
16590
16591 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16592 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16593 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16594 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16595 +
16596 #else
16597 #define INTERRUPT_RETURN iret
16598 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16599 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16600 index 9454c16..e4100e3 100644
16601 --- a/arch/x86/include/asm/kprobes.h
16602 +++ b/arch/x86/include/asm/kprobes.h
16603 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16604 #define RELATIVEJUMP_SIZE 5
16605 #define RELATIVECALL_OPCODE 0xe8
16606 #define RELATIVE_ADDR_SIZE 4
16607 -#define MAX_STACK_SIZE 64
16608 -#define MIN_STACK_SIZE(ADDR) \
16609 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16610 - THREAD_SIZE - (unsigned long)(ADDR))) \
16611 - ? (MAX_STACK_SIZE) \
16612 - : (((unsigned long)current_thread_info()) + \
16613 - THREAD_SIZE - (unsigned long)(ADDR)))
16614 +#define MAX_STACK_SIZE 64UL
16615 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16616
16617 #define flush_insn_slot(p) do { } while (0)
16618
16619 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16620 index 4ad6560..75c7bdd 100644
16621 --- a/arch/x86/include/asm/local.h
16622 +++ b/arch/x86/include/asm/local.h
16623 @@ -10,33 +10,97 @@ typedef struct {
16624 atomic_long_t a;
16625 } local_t;
16626
16627 +typedef struct {
16628 + atomic_long_unchecked_t a;
16629 +} local_unchecked_t;
16630 +
16631 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16632
16633 #define local_read(l) atomic_long_read(&(l)->a)
16634 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16635 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16636 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16637
16638 static inline void local_inc(local_t *l)
16639 {
16640 - asm volatile(_ASM_INC "%0"
16641 + asm volatile(_ASM_INC "%0\n"
16642 +
16643 +#ifdef CONFIG_PAX_REFCOUNT
16644 + "jno 0f\n"
16645 + _ASM_DEC "%0\n"
16646 + "int $4\n0:\n"
16647 + _ASM_EXTABLE(0b, 0b)
16648 +#endif
16649 +
16650 + : "+m" (l->a.counter));
16651 +}
16652 +
16653 +static inline void local_inc_unchecked(local_unchecked_t *l)
16654 +{
16655 + asm volatile(_ASM_INC "%0\n"
16656 : "+m" (l->a.counter));
16657 }
16658
16659 static inline void local_dec(local_t *l)
16660 {
16661 - asm volatile(_ASM_DEC "%0"
16662 + asm volatile(_ASM_DEC "%0\n"
16663 +
16664 +#ifdef CONFIG_PAX_REFCOUNT
16665 + "jno 0f\n"
16666 + _ASM_INC "%0\n"
16667 + "int $4\n0:\n"
16668 + _ASM_EXTABLE(0b, 0b)
16669 +#endif
16670 +
16671 + : "+m" (l->a.counter));
16672 +}
16673 +
16674 +static inline void local_dec_unchecked(local_unchecked_t *l)
16675 +{
16676 + asm volatile(_ASM_DEC "%0\n"
16677 : "+m" (l->a.counter));
16678 }
16679
16680 static inline void local_add(long i, local_t *l)
16681 {
16682 - asm volatile(_ASM_ADD "%1,%0"
16683 + asm volatile(_ASM_ADD "%1,%0\n"
16684 +
16685 +#ifdef CONFIG_PAX_REFCOUNT
16686 + "jno 0f\n"
16687 + _ASM_SUB "%1,%0\n"
16688 + "int $4\n0:\n"
16689 + _ASM_EXTABLE(0b, 0b)
16690 +#endif
16691 +
16692 + : "+m" (l->a.counter)
16693 + : "ir" (i));
16694 +}
16695 +
16696 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16697 +{
16698 + asm volatile(_ASM_ADD "%1,%0\n"
16699 : "+m" (l->a.counter)
16700 : "ir" (i));
16701 }
16702
16703 static inline void local_sub(long i, local_t *l)
16704 {
16705 - asm volatile(_ASM_SUB "%1,%0"
16706 + asm volatile(_ASM_SUB "%1,%0\n"
16707 +
16708 +#ifdef CONFIG_PAX_REFCOUNT
16709 + "jno 0f\n"
16710 + _ASM_ADD "%1,%0\n"
16711 + "int $4\n0:\n"
16712 + _ASM_EXTABLE(0b, 0b)
16713 +#endif
16714 +
16715 + : "+m" (l->a.counter)
16716 + : "ir" (i));
16717 +}
16718 +
16719 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16720 +{
16721 + asm volatile(_ASM_SUB "%1,%0\n"
16722 : "+m" (l->a.counter)
16723 : "ir" (i));
16724 }
16725 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16726 */
16727 static inline int local_sub_and_test(long i, local_t *l)
16728 {
16729 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16730 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16731 }
16732
16733 /**
16734 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16735 */
16736 static inline int local_dec_and_test(local_t *l)
16737 {
16738 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16739 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16740 }
16741
16742 /**
16743 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16744 */
16745 static inline int local_inc_and_test(local_t *l)
16746 {
16747 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16748 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16749 }
16750
16751 /**
16752 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16753 */
16754 static inline int local_add_negative(long i, local_t *l)
16755 {
16756 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16757 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16758 }
16759
16760 /**
16761 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16762 static inline long local_add_return(long i, local_t *l)
16763 {
16764 long __i = i;
16765 + asm volatile(_ASM_XADD "%0, %1\n"
16766 +
16767 +#ifdef CONFIG_PAX_REFCOUNT
16768 + "jno 0f\n"
16769 + _ASM_MOV "%0,%1\n"
16770 + "int $4\n0:\n"
16771 + _ASM_EXTABLE(0b, 0b)
16772 +#endif
16773 +
16774 + : "+r" (i), "+m" (l->a.counter)
16775 + : : "memory");
16776 + return i + __i;
16777 +}
16778 +
16779 +/**
16780 + * local_add_return_unchecked - add and return
16781 + * @i: integer value to add
16782 + * @l: pointer to type local_unchecked_t
16783 + *
16784 + * Atomically adds @i to @l and returns @i + @l
16785 + */
16786 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16787 +{
16788 + long __i = i;
16789 asm volatile(_ASM_XADD "%0, %1;"
16790 : "+r" (i), "+m" (l->a.counter)
16791 : : "memory");
16792 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16793
16794 #define local_cmpxchg(l, o, n) \
16795 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16796 +#define local_cmpxchg_unchecked(l, o, n) \
16797 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
16798 /* Always has a lock prefix */
16799 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16800
16801 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16802 new file mode 100644
16803 index 0000000..2bfd3ba
16804 --- /dev/null
16805 +++ b/arch/x86/include/asm/mman.h
16806 @@ -0,0 +1,15 @@
16807 +#ifndef _X86_MMAN_H
16808 +#define _X86_MMAN_H
16809 +
16810 +#include <uapi/asm/mman.h>
16811 +
16812 +#ifdef __KERNEL__
16813 +#ifndef __ASSEMBLY__
16814 +#ifdef CONFIG_X86_32
16815 +#define arch_mmap_check i386_mmap_check
16816 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16817 +#endif
16818 +#endif
16819 +#endif
16820 +
16821 +#endif /* X86_MMAN_H */
16822 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16823 index 5f55e69..e20bfb1 100644
16824 --- a/arch/x86/include/asm/mmu.h
16825 +++ b/arch/x86/include/asm/mmu.h
16826 @@ -9,7 +9,7 @@
16827 * we put the segment information here.
16828 */
16829 typedef struct {
16830 - void *ldt;
16831 + struct desc_struct *ldt;
16832 int size;
16833
16834 #ifdef CONFIG_X86_64
16835 @@ -18,7 +18,19 @@ typedef struct {
16836 #endif
16837
16838 struct mutex lock;
16839 - void *vdso;
16840 + unsigned long vdso;
16841 +
16842 +#ifdef CONFIG_X86_32
16843 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16844 + unsigned long user_cs_base;
16845 + unsigned long user_cs_limit;
16846 +
16847 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16848 + cpumask_t cpu_user_cs_mask;
16849 +#endif
16850 +
16851 +#endif
16852 +#endif
16853 } mm_context_t;
16854
16855 #ifdef CONFIG_SMP
16856 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16857 index be12c53..4d24039 100644
16858 --- a/arch/x86/include/asm/mmu_context.h
16859 +++ b/arch/x86/include/asm/mmu_context.h
16860 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16861
16862 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16863 {
16864 +
16865 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16866 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
16867 + unsigned int i;
16868 + pgd_t *pgd;
16869 +
16870 + pax_open_kernel();
16871 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
16872 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16873 + set_pgd_batched(pgd+i, native_make_pgd(0));
16874 + pax_close_kernel();
16875 + }
16876 +#endif
16877 +
16878 #ifdef CONFIG_SMP
16879 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16880 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16881 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16882 struct task_struct *tsk)
16883 {
16884 unsigned cpu = smp_processor_id();
16885 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16886 + int tlbstate = TLBSTATE_OK;
16887 +#endif
16888
16889 if (likely(prev != next)) {
16890 #ifdef CONFIG_SMP
16891 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16892 + tlbstate = this_cpu_read(cpu_tlbstate.state);
16893 +#endif
16894 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16895 this_cpu_write(cpu_tlbstate.active_mm, next);
16896 #endif
16897 cpumask_set_cpu(cpu, mm_cpumask(next));
16898
16899 /* Re-load page tables */
16900 +#ifdef CONFIG_PAX_PER_CPU_PGD
16901 + pax_open_kernel();
16902 +
16903 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16904 + if (static_cpu_has(X86_FEATURE_PCID))
16905 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16906 + else
16907 +#endif
16908 +
16909 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16910 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16911 + pax_close_kernel();
16912 + 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));
16913 +
16914 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16915 + if (static_cpu_has(X86_FEATURE_PCID)) {
16916 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
16917 + u64 descriptor[2];
16918 + descriptor[0] = PCID_USER;
16919 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16920 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16921 + descriptor[0] = PCID_KERNEL;
16922 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16923 + }
16924 + } else {
16925 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16926 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16927 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16928 + else
16929 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16930 + }
16931 + } else
16932 +#endif
16933 +
16934 + load_cr3(get_cpu_pgd(cpu, kernel));
16935 +#else
16936 load_cr3(next->pgd);
16937 +#endif
16938
16939 /* Stop flush ipis for the previous mm */
16940 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16941 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16942 /* Load the LDT, if the LDT is different: */
16943 if (unlikely(prev->context.ldt != next->context.ldt))
16944 load_LDT_nolock(&next->context);
16945 +
16946 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16947 + if (!(__supported_pte_mask & _PAGE_NX)) {
16948 + smp_mb__before_clear_bit();
16949 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16950 + smp_mb__after_clear_bit();
16951 + cpu_set(cpu, next->context.cpu_user_cs_mask);
16952 + }
16953 +#endif
16954 +
16955 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16956 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16957 + prev->context.user_cs_limit != next->context.user_cs_limit))
16958 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16959 +#ifdef CONFIG_SMP
16960 + else if (unlikely(tlbstate != TLBSTATE_OK))
16961 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16962 +#endif
16963 +#endif
16964 +
16965 }
16966 + else {
16967 +
16968 +#ifdef CONFIG_PAX_PER_CPU_PGD
16969 + pax_open_kernel();
16970 +
16971 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16972 + if (static_cpu_has(X86_FEATURE_PCID))
16973 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16974 + else
16975 +#endif
16976 +
16977 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16978 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16979 + pax_close_kernel();
16980 + 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));
16981 +
16982 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16983 + if (static_cpu_has(X86_FEATURE_PCID)) {
16984 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
16985 + u64 descriptor[2];
16986 + descriptor[0] = PCID_USER;
16987 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16988 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16989 + descriptor[0] = PCID_KERNEL;
16990 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16991 + }
16992 + } else {
16993 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16994 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16995 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16996 + else
16997 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16998 + }
16999 + } else
17000 +#endif
17001 +
17002 + load_cr3(get_cpu_pgd(cpu, kernel));
17003 +#endif
17004 +
17005 #ifdef CONFIG_SMP
17006 - else {
17007 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17008 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17009
17010 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17011 * tlb flush IPI delivery. We must reload CR3
17012 * to make sure to use no freed page tables.
17013 */
17014 +
17015 +#ifndef CONFIG_PAX_PER_CPU_PGD
17016 load_cr3(next->pgd);
17017 +#endif
17018 +
17019 load_LDT_nolock(&next->context);
17020 +
17021 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17022 + if (!(__supported_pte_mask & _PAGE_NX))
17023 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17024 +#endif
17025 +
17026 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17027 +#ifdef CONFIG_PAX_PAGEEXEC
17028 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17029 +#endif
17030 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17031 +#endif
17032 +
17033 }
17034 +#endif
17035 }
17036 -#endif
17037 }
17038
17039 #define activate_mm(prev, next) \
17040 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17041 index e3b7819..b257c64 100644
17042 --- a/arch/x86/include/asm/module.h
17043 +++ b/arch/x86/include/asm/module.h
17044 @@ -5,6 +5,7 @@
17045
17046 #ifdef CONFIG_X86_64
17047 /* X86_64 does not define MODULE_PROC_FAMILY */
17048 +#define MODULE_PROC_FAMILY ""
17049 #elif defined CONFIG_M486
17050 #define MODULE_PROC_FAMILY "486 "
17051 #elif defined CONFIG_M586
17052 @@ -57,8 +58,20 @@
17053 #error unknown processor family
17054 #endif
17055
17056 -#ifdef CONFIG_X86_32
17057 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17058 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17059 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17060 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17061 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17062 +#else
17063 +#define MODULE_PAX_KERNEXEC ""
17064 #endif
17065
17066 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17067 +#define MODULE_PAX_UDEREF "UDEREF "
17068 +#else
17069 +#define MODULE_PAX_UDEREF ""
17070 +#endif
17071 +
17072 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17073 +
17074 #endif /* _ASM_X86_MODULE_H */
17075 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17076 index 86f9301..b365cda 100644
17077 --- a/arch/x86/include/asm/nmi.h
17078 +++ b/arch/x86/include/asm/nmi.h
17079 @@ -40,11 +40,11 @@ struct nmiaction {
17080 nmi_handler_t handler;
17081 unsigned long flags;
17082 const char *name;
17083 -};
17084 +} __do_const;
17085
17086 #define register_nmi_handler(t, fn, fg, n, init...) \
17087 ({ \
17088 - static struct nmiaction init fn##_na = { \
17089 + static const struct nmiaction init fn##_na = { \
17090 .handler = (fn), \
17091 .name = (n), \
17092 .flags = (fg), \
17093 @@ -52,7 +52,7 @@ struct nmiaction {
17094 __register_nmi_handler((t), &fn##_na); \
17095 })
17096
17097 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17098 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17099
17100 void unregister_nmi_handler(unsigned int, const char *);
17101
17102 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17103 index 775873d..de5f0304 100644
17104 --- a/arch/x86/include/asm/page.h
17105 +++ b/arch/x86/include/asm/page.h
17106 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17107 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17108
17109 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17110 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17111
17112 #define __boot_va(x) __va(x)
17113 #define __boot_pa(x) __pa(x)
17114 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17115 index 0f1ddee..e2fc3d1 100644
17116 --- a/arch/x86/include/asm/page_64.h
17117 +++ b/arch/x86/include/asm/page_64.h
17118 @@ -7,9 +7,9 @@
17119
17120 /* duplicated to the one in bootmem.h */
17121 extern unsigned long max_pfn;
17122 -extern unsigned long phys_base;
17123 +extern const unsigned long phys_base;
17124
17125 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17126 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17127 {
17128 unsigned long y = x - __START_KERNEL_map;
17129
17130 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17131 index cd6e1610..70f4418 100644
17132 --- a/arch/x86/include/asm/paravirt.h
17133 +++ b/arch/x86/include/asm/paravirt.h
17134 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17135 return (pmd_t) { ret };
17136 }
17137
17138 -static inline pmdval_t pmd_val(pmd_t pmd)
17139 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17140 {
17141 pmdval_t ret;
17142
17143 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17144 val);
17145 }
17146
17147 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17148 +{
17149 + pgdval_t val = native_pgd_val(pgd);
17150 +
17151 + if (sizeof(pgdval_t) > sizeof(long))
17152 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17153 + val, (u64)val >> 32);
17154 + else
17155 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17156 + val);
17157 +}
17158 +
17159 static inline void pgd_clear(pgd_t *pgdp)
17160 {
17161 set_pgd(pgdp, __pgd(0));
17162 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17163 pv_mmu_ops.set_fixmap(idx, phys, flags);
17164 }
17165
17166 +#ifdef CONFIG_PAX_KERNEXEC
17167 +static inline unsigned long pax_open_kernel(void)
17168 +{
17169 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17170 +}
17171 +
17172 +static inline unsigned long pax_close_kernel(void)
17173 +{
17174 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17175 +}
17176 +#else
17177 +static inline unsigned long pax_open_kernel(void) { return 0; }
17178 +static inline unsigned long pax_close_kernel(void) { return 0; }
17179 +#endif
17180 +
17181 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17182
17183 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17184 @@ -906,7 +933,7 @@ extern void default_banner(void);
17185
17186 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17187 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17188 -#define PARA_INDIRECT(addr) *%cs:addr
17189 +#define PARA_INDIRECT(addr) *%ss:addr
17190 #endif
17191
17192 #define INTERRUPT_RETURN \
17193 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17194 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17195 CLBR_NONE, \
17196 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17197 +
17198 +#define GET_CR0_INTO_RDI \
17199 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17200 + mov %rax,%rdi
17201 +
17202 +#define SET_RDI_INTO_CR0 \
17203 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17204 +
17205 +#define GET_CR3_INTO_RDI \
17206 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17207 + mov %rax,%rdi
17208 +
17209 +#define SET_RDI_INTO_CR3 \
17210 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17211 +
17212 #endif /* CONFIG_X86_32 */
17213
17214 #endif /* __ASSEMBLY__ */
17215 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17216 index 7549b8b..f0edfda 100644
17217 --- a/arch/x86/include/asm/paravirt_types.h
17218 +++ b/arch/x86/include/asm/paravirt_types.h
17219 @@ -84,7 +84,7 @@ struct pv_init_ops {
17220 */
17221 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17222 unsigned long addr, unsigned len);
17223 -};
17224 +} __no_const __no_randomize_layout;
17225
17226
17227 struct pv_lazy_ops {
17228 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17229 void (*enter)(void);
17230 void (*leave)(void);
17231 void (*flush)(void);
17232 -};
17233 +} __no_randomize_layout;
17234
17235 struct pv_time_ops {
17236 unsigned long long (*sched_clock)(void);
17237 unsigned long long (*steal_clock)(int cpu);
17238 unsigned long (*get_tsc_khz)(void);
17239 -};
17240 +} __no_const __no_randomize_layout;
17241
17242 struct pv_cpu_ops {
17243 /* hooks for various privileged instructions */
17244 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17245
17246 void (*start_context_switch)(struct task_struct *prev);
17247 void (*end_context_switch)(struct task_struct *next);
17248 -};
17249 +} __no_const __no_randomize_layout;
17250
17251 struct pv_irq_ops {
17252 /*
17253 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17254 #ifdef CONFIG_X86_64
17255 void (*adjust_exception_frame)(void);
17256 #endif
17257 -};
17258 +} __no_randomize_layout;
17259
17260 struct pv_apic_ops {
17261 #ifdef CONFIG_X86_LOCAL_APIC
17262 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17263 unsigned long start_eip,
17264 unsigned long start_esp);
17265 #endif
17266 -};
17267 +} __no_const __no_randomize_layout;
17268
17269 struct pv_mmu_ops {
17270 unsigned long (*read_cr2)(void);
17271 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17272 struct paravirt_callee_save make_pud;
17273
17274 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17275 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17276 #endif /* PAGETABLE_LEVELS == 4 */
17277 #endif /* PAGETABLE_LEVELS >= 3 */
17278
17279 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17280 an mfn. We can tell which is which from the index. */
17281 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17282 phys_addr_t phys, pgprot_t flags);
17283 -};
17284 +
17285 +#ifdef CONFIG_PAX_KERNEXEC
17286 + unsigned long (*pax_open_kernel)(void);
17287 + unsigned long (*pax_close_kernel)(void);
17288 +#endif
17289 +
17290 +} __no_randomize_layout;
17291
17292 struct arch_spinlock;
17293 #ifdef CONFIG_SMP
17294 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17295 struct pv_lock_ops {
17296 struct paravirt_callee_save lock_spinning;
17297 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17298 -};
17299 +} __no_randomize_layout;
17300
17301 /* This contains all the paravirt structures: we get a convenient
17302 * number for each function using the offset which we use to indicate
17303 - * what to patch. */
17304 + * what to patch.
17305 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17306 + */
17307 +
17308 struct paravirt_patch_template {
17309 struct pv_init_ops pv_init_ops;
17310 struct pv_time_ops pv_time_ops;
17311 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17312 struct pv_apic_ops pv_apic_ops;
17313 struct pv_mmu_ops pv_mmu_ops;
17314 struct pv_lock_ops pv_lock_ops;
17315 -};
17316 +} __no_randomize_layout;
17317
17318 extern struct pv_info pv_info;
17319 extern struct pv_init_ops pv_init_ops;
17320 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17321 index c4412e9..90e88c5 100644
17322 --- a/arch/x86/include/asm/pgalloc.h
17323 +++ b/arch/x86/include/asm/pgalloc.h
17324 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17325 pmd_t *pmd, pte_t *pte)
17326 {
17327 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17328 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17329 +}
17330 +
17331 +static inline void pmd_populate_user(struct mm_struct *mm,
17332 + pmd_t *pmd, pte_t *pte)
17333 +{
17334 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17335 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17336 }
17337
17338 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17339
17340 #ifdef CONFIG_X86_PAE
17341 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17342 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17343 +{
17344 + pud_populate(mm, pudp, pmd);
17345 +}
17346 #else /* !CONFIG_X86_PAE */
17347 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17348 {
17349 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17350 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17351 }
17352 +
17353 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17354 +{
17355 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17356 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17357 +}
17358 #endif /* CONFIG_X86_PAE */
17359
17360 #if PAGETABLE_LEVELS > 3
17361 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17362 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17363 }
17364
17365 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17366 +{
17367 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17368 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17369 +}
17370 +
17371 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17372 {
17373 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17374 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17375 index 0d193e2..bf59aeb 100644
17376 --- a/arch/x86/include/asm/pgtable-2level.h
17377 +++ b/arch/x86/include/asm/pgtable-2level.h
17378 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17379
17380 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17381 {
17382 + pax_open_kernel();
17383 *pmdp = pmd;
17384 + pax_close_kernel();
17385 }
17386
17387 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17388 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17389 index 81bb91b..9392125 100644
17390 --- a/arch/x86/include/asm/pgtable-3level.h
17391 +++ b/arch/x86/include/asm/pgtable-3level.h
17392 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17393
17394 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17395 {
17396 + pax_open_kernel();
17397 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17398 + pax_close_kernel();
17399 }
17400
17401 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17402 {
17403 + pax_open_kernel();
17404 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17405 + pax_close_kernel();
17406 }
17407
17408 /*
17409 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17410 index bbc8b12..f228861 100644
17411 --- a/arch/x86/include/asm/pgtable.h
17412 +++ b/arch/x86/include/asm/pgtable.h
17413 @@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17414
17415 #ifndef __PAGETABLE_PUD_FOLDED
17416 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17417 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17418 #define pgd_clear(pgd) native_pgd_clear(pgd)
17419 #endif
17420
17421 @@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17422
17423 #define arch_end_context_switch(prev) do {} while(0)
17424
17425 +#define pax_open_kernel() native_pax_open_kernel()
17426 +#define pax_close_kernel() native_pax_close_kernel()
17427 #endif /* CONFIG_PARAVIRT */
17428
17429 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17430 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17431 +
17432 +#ifdef CONFIG_PAX_KERNEXEC
17433 +static inline unsigned long native_pax_open_kernel(void)
17434 +{
17435 + unsigned long cr0;
17436 +
17437 + preempt_disable();
17438 + barrier();
17439 + cr0 = read_cr0() ^ X86_CR0_WP;
17440 + BUG_ON(cr0 & X86_CR0_WP);
17441 + write_cr0(cr0);
17442 + return cr0 ^ X86_CR0_WP;
17443 +}
17444 +
17445 +static inline unsigned long native_pax_close_kernel(void)
17446 +{
17447 + unsigned long cr0;
17448 +
17449 + cr0 = read_cr0() ^ X86_CR0_WP;
17450 + BUG_ON(!(cr0 & X86_CR0_WP));
17451 + write_cr0(cr0);
17452 + barrier();
17453 + preempt_enable_no_resched();
17454 + return cr0 ^ X86_CR0_WP;
17455 +}
17456 +#else
17457 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17458 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17459 +#endif
17460 +
17461 /*
17462 * The following only work if pte_present() is true.
17463 * Undefined behaviour if not..
17464 */
17465 +static inline int pte_user(pte_t pte)
17466 +{
17467 + return pte_val(pte) & _PAGE_USER;
17468 +}
17469 +
17470 static inline int pte_dirty(pte_t pte)
17471 {
17472 return pte_flags(pte) & _PAGE_DIRTY;
17473 @@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17474 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17475 }
17476
17477 +static inline unsigned long pgd_pfn(pgd_t pgd)
17478 +{
17479 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17480 +}
17481 +
17482 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17483
17484 static inline int pmd_large(pmd_t pte)
17485 @@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17486 return pte_clear_flags(pte, _PAGE_RW);
17487 }
17488
17489 +static inline pte_t pte_mkread(pte_t pte)
17490 +{
17491 + return __pte(pte_val(pte) | _PAGE_USER);
17492 +}
17493 +
17494 static inline pte_t pte_mkexec(pte_t pte)
17495 {
17496 - return pte_clear_flags(pte, _PAGE_NX);
17497 +#ifdef CONFIG_X86_PAE
17498 + if (__supported_pte_mask & _PAGE_NX)
17499 + return pte_clear_flags(pte, _PAGE_NX);
17500 + else
17501 +#endif
17502 + return pte_set_flags(pte, _PAGE_USER);
17503 +}
17504 +
17505 +static inline pte_t pte_exprotect(pte_t pte)
17506 +{
17507 +#ifdef CONFIG_X86_PAE
17508 + if (__supported_pte_mask & _PAGE_NX)
17509 + return pte_set_flags(pte, _PAGE_NX);
17510 + else
17511 +#endif
17512 + return pte_clear_flags(pte, _PAGE_USER);
17513 }
17514
17515 static inline pte_t pte_mkdirty(pte_t pte)
17516 @@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17517 #endif
17518
17519 #ifndef __ASSEMBLY__
17520 +
17521 +#ifdef CONFIG_PAX_PER_CPU_PGD
17522 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17523 +enum cpu_pgd_type {kernel = 0, user = 1};
17524 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17525 +{
17526 + return cpu_pgd[cpu][type];
17527 +}
17528 +#endif
17529 +
17530 #include <linux/mm_types.h>
17531 #include <linux/mmdebug.h>
17532 #include <linux/log2.h>
17533 @@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17534 * Currently stuck as a macro due to indirect forward reference to
17535 * linux/mmzone.h's __section_mem_map_addr() definition:
17536 */
17537 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17538 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17539
17540 /* Find an entry in the second-level page table.. */
17541 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17542 @@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17543 * Currently stuck as a macro due to indirect forward reference to
17544 * linux/mmzone.h's __section_mem_map_addr() definition:
17545 */
17546 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17547 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17548
17549 /* to find an entry in a page-table-directory. */
17550 static inline unsigned long pud_index(unsigned long address)
17551 @@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17552
17553 static inline int pgd_bad(pgd_t pgd)
17554 {
17555 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17556 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17557 }
17558
17559 static inline int pgd_none(pgd_t pgd)
17560 @@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17561 * pgd_offset() returns a (pgd_t *)
17562 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17563 */
17564 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17565 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17566 +
17567 +#ifdef CONFIG_PAX_PER_CPU_PGD
17568 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17569 +#endif
17570 +
17571 /*
17572 * a shortcut which implies the use of the kernel's pgd, instead
17573 * of a process's
17574 @@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17575 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17576 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17577
17578 +#ifdef CONFIG_X86_32
17579 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17580 +#else
17581 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17582 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17583 +
17584 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17585 +#ifdef __ASSEMBLY__
17586 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17587 +#else
17588 +extern unsigned long pax_user_shadow_base;
17589 +extern pgdval_t clone_pgd_mask;
17590 +#endif
17591 +#endif
17592 +
17593 +#endif
17594 +
17595 #ifndef __ASSEMBLY__
17596
17597 extern int direct_gbpages;
17598 @@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17599 * dst and src can be on the same page, but the range must not overlap,
17600 * and must not cross a page boundary.
17601 */
17602 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17603 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17604 {
17605 - memcpy(dst, src, count * sizeof(pgd_t));
17606 + pax_open_kernel();
17607 + while (count--)
17608 + *dst++ = *src++;
17609 + pax_close_kernel();
17610 }
17611
17612 +#ifdef CONFIG_PAX_PER_CPU_PGD
17613 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17614 +#endif
17615 +
17616 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17617 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17618 +#else
17619 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17620 +#endif
17621 +
17622 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17623 static inline int page_level_shift(enum pg_level level)
17624 {
17625 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17626 index 9ee3221..b979c6b 100644
17627 --- a/arch/x86/include/asm/pgtable_32.h
17628 +++ b/arch/x86/include/asm/pgtable_32.h
17629 @@ -25,9 +25,6 @@
17630 struct mm_struct;
17631 struct vm_area_struct;
17632
17633 -extern pgd_t swapper_pg_dir[1024];
17634 -extern pgd_t initial_page_table[1024];
17635 -
17636 static inline void pgtable_cache_init(void) { }
17637 static inline void check_pgt_cache(void) { }
17638 void paging_init(void);
17639 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17640 # include <asm/pgtable-2level.h>
17641 #endif
17642
17643 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17644 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17645 +#ifdef CONFIG_X86_PAE
17646 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17647 +#endif
17648 +
17649 #if defined(CONFIG_HIGHPTE)
17650 #define pte_offset_map(dir, address) \
17651 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17652 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17653 /* Clear a kernel PTE and flush it from the TLB */
17654 #define kpte_clear_flush(ptep, vaddr) \
17655 do { \
17656 + pax_open_kernel(); \
17657 pte_clear(&init_mm, (vaddr), (ptep)); \
17658 + pax_close_kernel(); \
17659 __flush_tlb_one((vaddr)); \
17660 } while (0)
17661
17662 #endif /* !__ASSEMBLY__ */
17663
17664 +#define HAVE_ARCH_UNMAPPED_AREA
17665 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17666 +
17667 /*
17668 * kern_addr_valid() is (1) for FLATMEM and (0) for
17669 * SPARSEMEM and DISCONTIGMEM
17670 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17671 index ed5903b..c7fe163 100644
17672 --- a/arch/x86/include/asm/pgtable_32_types.h
17673 +++ b/arch/x86/include/asm/pgtable_32_types.h
17674 @@ -8,7 +8,7 @@
17675 */
17676 #ifdef CONFIG_X86_PAE
17677 # include <asm/pgtable-3level_types.h>
17678 -# define PMD_SIZE (1UL << PMD_SHIFT)
17679 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17680 # define PMD_MASK (~(PMD_SIZE - 1))
17681 #else
17682 # include <asm/pgtable-2level_types.h>
17683 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17684 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17685 #endif
17686
17687 +#ifdef CONFIG_PAX_KERNEXEC
17688 +#ifndef __ASSEMBLY__
17689 +extern unsigned char MODULES_EXEC_VADDR[];
17690 +extern unsigned char MODULES_EXEC_END[];
17691 +#endif
17692 +#include <asm/boot.h>
17693 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17694 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17695 +#else
17696 +#define ktla_ktva(addr) (addr)
17697 +#define ktva_ktla(addr) (addr)
17698 +#endif
17699 +
17700 #define MODULES_VADDR VMALLOC_START
17701 #define MODULES_END VMALLOC_END
17702 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17703 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17704 index e22c1db..23a625a 100644
17705 --- a/arch/x86/include/asm/pgtable_64.h
17706 +++ b/arch/x86/include/asm/pgtable_64.h
17707 @@ -16,10 +16,14 @@
17708
17709 extern pud_t level3_kernel_pgt[512];
17710 extern pud_t level3_ident_pgt[512];
17711 +extern pud_t level3_vmalloc_start_pgt[512];
17712 +extern pud_t level3_vmalloc_end_pgt[512];
17713 +extern pud_t level3_vmemmap_pgt[512];
17714 +extern pud_t level2_vmemmap_pgt[512];
17715 extern pmd_t level2_kernel_pgt[512];
17716 extern pmd_t level2_fixmap_pgt[512];
17717 -extern pmd_t level2_ident_pgt[512];
17718 -extern pgd_t init_level4_pgt[];
17719 +extern pmd_t level2_ident_pgt[512*2];
17720 +extern pgd_t init_level4_pgt[512];
17721
17722 #define swapper_pg_dir init_level4_pgt
17723
17724 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17725
17726 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17727 {
17728 + pax_open_kernel();
17729 *pmdp = pmd;
17730 + pax_close_kernel();
17731 }
17732
17733 static inline void native_pmd_clear(pmd_t *pmd)
17734 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17735
17736 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17737 {
17738 + pax_open_kernel();
17739 *pudp = pud;
17740 + pax_close_kernel();
17741 }
17742
17743 static inline void native_pud_clear(pud_t *pud)
17744 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17745
17746 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17747 {
17748 + pax_open_kernel();
17749 + *pgdp = pgd;
17750 + pax_close_kernel();
17751 +}
17752 +
17753 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17754 +{
17755 *pgdp = pgd;
17756 }
17757
17758 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17759 index c883bf7..19970b3 100644
17760 --- a/arch/x86/include/asm/pgtable_64_types.h
17761 +++ b/arch/x86/include/asm/pgtable_64_types.h
17762 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17763 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
17764 #define MODULES_END _AC(0xffffffffff000000, UL)
17765 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17766 +#define MODULES_EXEC_VADDR MODULES_VADDR
17767 +#define MODULES_EXEC_END MODULES_END
17768 +
17769 +#define ktla_ktva(addr) (addr)
17770 +#define ktva_ktla(addr) (addr)
17771
17772 #define EARLY_DYNAMIC_PAGE_TABLES 64
17773
17774 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17775 index 94e40f1..ebd03e4 100644
17776 --- a/arch/x86/include/asm/pgtable_types.h
17777 +++ b/arch/x86/include/asm/pgtable_types.h
17778 @@ -16,13 +16,12 @@
17779 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17780 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17781 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17782 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17783 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17784 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17785 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17786 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17787 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17788 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17789 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17790 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17791 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17792 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17793
17794 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17795 @@ -40,7 +39,6 @@
17796 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17797 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17798 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17799 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17800 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17801 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17802 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17803 @@ -87,8 +85,10 @@
17804
17805 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17806 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17807 -#else
17808 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17809 #define _PAGE_NX (_AT(pteval_t, 0))
17810 +#else
17811 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17812 #endif
17813
17814 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17815 @@ -147,6 +147,9 @@
17816 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17817 _PAGE_ACCESSED)
17818
17819 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
17820 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
17821 +
17822 #define __PAGE_KERNEL_EXEC \
17823 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17824 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17825 @@ -157,7 +160,7 @@
17826 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17827 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17828 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17829 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17830 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17831 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17832 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17833 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17834 @@ -219,8 +222,8 @@
17835 * bits are combined, this will alow user to access the high address mapped
17836 * VDSO in the presence of CONFIG_COMPAT_VDSO
17837 */
17838 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17839 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17840 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17841 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17842 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17843 #endif
17844
17845 @@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17846 {
17847 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17848 }
17849 +#endif
17850
17851 +#if PAGETABLE_LEVELS == 3
17852 +#include <asm-generic/pgtable-nopud.h>
17853 +#endif
17854 +
17855 +#if PAGETABLE_LEVELS == 2
17856 +#include <asm-generic/pgtable-nopmd.h>
17857 +#endif
17858 +
17859 +#ifndef __ASSEMBLY__
17860 #if PAGETABLE_LEVELS > 3
17861 typedef struct { pudval_t pud; } pud_t;
17862
17863 @@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17864 return pud.pud;
17865 }
17866 #else
17867 -#include <asm-generic/pgtable-nopud.h>
17868 -
17869 static inline pudval_t native_pud_val(pud_t pud)
17870 {
17871 return native_pgd_val(pud.pgd);
17872 @@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17873 return pmd.pmd;
17874 }
17875 #else
17876 -#include <asm-generic/pgtable-nopmd.h>
17877 -
17878 static inline pmdval_t native_pmd_val(pmd_t pmd)
17879 {
17880 return native_pgd_val(pmd.pud.pgd);
17881 @@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
17882
17883 extern pteval_t __supported_pte_mask;
17884 extern void set_nx(void);
17885 -extern int nx_enabled;
17886
17887 #define pgprot_writecombine pgprot_writecombine
17888 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17889 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
17890 index c8b0519..fd29e73 100644
17891 --- a/arch/x86/include/asm/preempt.h
17892 +++ b/arch/x86/include/asm/preempt.h
17893 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
17894 */
17895 static __always_inline bool __preempt_count_dec_and_test(void)
17896 {
17897 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
17898 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
17899 }
17900
17901 /*
17902 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17903 index fdedd38..95c02c2 100644
17904 --- a/arch/x86/include/asm/processor.h
17905 +++ b/arch/x86/include/asm/processor.h
17906 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
17907 /* Index into per_cpu list: */
17908 u16 cpu_index;
17909 u32 microcode;
17910 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
17911 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
17912
17913 #define X86_VENDOR_INTEL 0
17914 #define X86_VENDOR_CYRIX 1
17915 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17916 : "memory");
17917 }
17918
17919 +/* invpcid (%rdx),%rax */
17920 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17921 +
17922 +#define INVPCID_SINGLE_ADDRESS 0UL
17923 +#define INVPCID_SINGLE_CONTEXT 1UL
17924 +#define INVPCID_ALL_GLOBAL 2UL
17925 +#define INVPCID_ALL_MONGLOBAL 3UL
17926 +
17927 +#define PCID_KERNEL 0UL
17928 +#define PCID_USER 1UL
17929 +#define PCID_NOFLUSH (1UL << 63)
17930 +
17931 static inline void load_cr3(pgd_t *pgdir)
17932 {
17933 - write_cr3(__pa(pgdir));
17934 + write_cr3(__pa(pgdir) | PCID_KERNEL);
17935 }
17936
17937 #ifdef CONFIG_X86_32
17938 @@ -283,7 +295,7 @@ struct tss_struct {
17939
17940 } ____cacheline_aligned;
17941
17942 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17943 +extern struct tss_struct init_tss[NR_CPUS];
17944
17945 /*
17946 * Save the original ist values for checking stack pointers during debugging
17947 @@ -470,6 +482,7 @@ struct thread_struct {
17948 unsigned short ds;
17949 unsigned short fsindex;
17950 unsigned short gsindex;
17951 + unsigned short ss;
17952 #endif
17953 #ifdef CONFIG_X86_32
17954 unsigned long ip;
17955 @@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
17956 extern unsigned long mmu_cr4_features;
17957 extern u32 *trampoline_cr4_features;
17958
17959 -static inline void set_in_cr4(unsigned long mask)
17960 -{
17961 - unsigned long cr4;
17962 -
17963 - mmu_cr4_features |= mask;
17964 - if (trampoline_cr4_features)
17965 - *trampoline_cr4_features = mmu_cr4_features;
17966 - cr4 = read_cr4();
17967 - cr4 |= mask;
17968 - write_cr4(cr4);
17969 -}
17970 -
17971 -static inline void clear_in_cr4(unsigned long mask)
17972 -{
17973 - unsigned long cr4;
17974 -
17975 - mmu_cr4_features &= ~mask;
17976 - if (trampoline_cr4_features)
17977 - *trampoline_cr4_features = mmu_cr4_features;
17978 - cr4 = read_cr4();
17979 - cr4 &= ~mask;
17980 - write_cr4(cr4);
17981 -}
17982 +extern void set_in_cr4(unsigned long mask);
17983 +extern void clear_in_cr4(unsigned long mask);
17984
17985 typedef struct {
17986 unsigned long seg;
17987 @@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
17988 */
17989 #define TASK_SIZE PAGE_OFFSET
17990 #define TASK_SIZE_MAX TASK_SIZE
17991 +
17992 +#ifdef CONFIG_PAX_SEGMEXEC
17993 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
17994 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
17995 +#else
17996 #define STACK_TOP TASK_SIZE
17997 -#define STACK_TOP_MAX STACK_TOP
17998 +#endif
17999 +
18000 +#define STACK_TOP_MAX TASK_SIZE
18001
18002 #define INIT_THREAD { \
18003 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18004 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18005 .vm86_info = NULL, \
18006 .sysenter_cs = __KERNEL_CS, \
18007 .io_bitmap_ptr = NULL, \
18008 @@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18009 */
18010 #define INIT_TSS { \
18011 .x86_tss = { \
18012 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18013 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18014 .ss0 = __KERNEL_DS, \
18015 .ss1 = __KERNEL_CS, \
18016 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18017 @@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18018 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18019
18020 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18021 -#define KSTK_TOP(info) \
18022 -({ \
18023 - unsigned long *__ptr = (unsigned long *)(info); \
18024 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18025 -})
18026 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18027
18028 /*
18029 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18030 @@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18031 #define task_pt_regs(task) \
18032 ({ \
18033 struct pt_regs *__regs__; \
18034 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18035 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18036 __regs__ - 1; \
18037 })
18038
18039 @@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18040 /*
18041 * User space process size. 47bits minus one guard page.
18042 */
18043 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18044 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18045
18046 /* This decides where the kernel will search for a free chunk of vm
18047 * space during mmap's.
18048 */
18049 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18050 - 0xc0000000 : 0xFFFFe000)
18051 + 0xc0000000 : 0xFFFFf000)
18052
18053 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18054 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18055 @@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18056 #define STACK_TOP_MAX TASK_SIZE_MAX
18057
18058 #define INIT_THREAD { \
18059 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18060 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18061 }
18062
18063 #define INIT_TSS { \
18064 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18065 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18066 }
18067
18068 /*
18069 @@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18070 */
18071 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18072
18073 +#ifdef CONFIG_PAX_SEGMEXEC
18074 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18075 +#endif
18076 +
18077 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18078
18079 /* Get/set a process' ability to use the timestamp counter instruction */
18080 @@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18081 return 0;
18082 }
18083
18084 -extern unsigned long arch_align_stack(unsigned long sp);
18085 +#define arch_align_stack(x) ((x) & ~0xfUL)
18086 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18087
18088 void default_idle(void);
18089 @@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18090 #define xen_set_default_idle 0
18091 #endif
18092
18093 -void stop_this_cpu(void *dummy);
18094 +void stop_this_cpu(void *dummy) __noreturn;
18095 void df_debug(struct pt_regs *regs, long error_code);
18096 #endif /* _ASM_X86_PROCESSOR_H */
18097 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18098 index 14fd6fd..6740420 100644
18099 --- a/arch/x86/include/asm/ptrace.h
18100 +++ b/arch/x86/include/asm/ptrace.h
18101 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18102 }
18103
18104 /*
18105 - * user_mode_vm(regs) determines whether a register set came from user mode.
18106 + * user_mode(regs) determines whether a register set came from user mode.
18107 * This is true if V8086 mode was enabled OR if the register set was from
18108 * protected mode with RPL-3 CS value. This tricky test checks that with
18109 * one comparison. Many places in the kernel can bypass this full check
18110 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18111 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18112 + * be used.
18113 */
18114 -static inline int user_mode(struct pt_regs *regs)
18115 +static inline int user_mode_novm(struct pt_regs *regs)
18116 {
18117 #ifdef CONFIG_X86_32
18118 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18119 #else
18120 - return !!(regs->cs & 3);
18121 + return !!(regs->cs & SEGMENT_RPL_MASK);
18122 #endif
18123 }
18124
18125 -static inline int user_mode_vm(struct pt_regs *regs)
18126 +static inline int user_mode(struct pt_regs *regs)
18127 {
18128 #ifdef CONFIG_X86_32
18129 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18130 USER_RPL;
18131 #else
18132 - return user_mode(regs);
18133 + return user_mode_novm(regs);
18134 #endif
18135 }
18136
18137 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18138 #ifdef CONFIG_X86_64
18139 static inline bool user_64bit_mode(struct pt_regs *regs)
18140 {
18141 + unsigned long cs = regs->cs & 0xffff;
18142 #ifndef CONFIG_PARAVIRT
18143 /*
18144 * On non-paravirt systems, this is the only long mode CPL 3
18145 * selector. We do not allow long mode selectors in the LDT.
18146 */
18147 - return regs->cs == __USER_CS;
18148 + return cs == __USER_CS;
18149 #else
18150 /* Headers are too twisted for this to go in paravirt.h. */
18151 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18152 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18153 #endif
18154 }
18155
18156 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18157 * Traps from the kernel do not save sp and ss.
18158 * Use the helper function to retrieve sp.
18159 */
18160 - if (offset == offsetof(struct pt_regs, sp) &&
18161 - regs->cs == __KERNEL_CS)
18162 - return kernel_stack_pointer(regs);
18163 + if (offset == offsetof(struct pt_regs, sp)) {
18164 + unsigned long cs = regs->cs & 0xffff;
18165 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18166 + return kernel_stack_pointer(regs);
18167 + }
18168 #endif
18169 return *(unsigned long *)((unsigned long)regs + offset);
18170 }
18171 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18172 index 9c6b890..5305f53 100644
18173 --- a/arch/x86/include/asm/realmode.h
18174 +++ b/arch/x86/include/asm/realmode.h
18175 @@ -22,16 +22,14 @@ struct real_mode_header {
18176 #endif
18177 /* APM/BIOS reboot */
18178 u32 machine_real_restart_asm;
18179 -#ifdef CONFIG_X86_64
18180 u32 machine_real_restart_seg;
18181 -#endif
18182 };
18183
18184 /* This must match data at trampoline_32/64.S */
18185 struct trampoline_header {
18186 #ifdef CONFIG_X86_32
18187 u32 start;
18188 - u16 gdt_pad;
18189 + u16 boot_cs;
18190 u16 gdt_limit;
18191 u32 gdt_base;
18192 #else
18193 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18194 index a82c4f1..ac45053 100644
18195 --- a/arch/x86/include/asm/reboot.h
18196 +++ b/arch/x86/include/asm/reboot.h
18197 @@ -6,13 +6,13 @@
18198 struct pt_regs;
18199
18200 struct machine_ops {
18201 - void (*restart)(char *cmd);
18202 - void (*halt)(void);
18203 - void (*power_off)(void);
18204 + void (* __noreturn restart)(char *cmd);
18205 + void (* __noreturn halt)(void);
18206 + void (* __noreturn power_off)(void);
18207 void (*shutdown)(void);
18208 void (*crash_shutdown)(struct pt_regs *);
18209 - void (*emergency_restart)(void);
18210 -};
18211 + void (* __noreturn emergency_restart)(void);
18212 +} __no_const;
18213
18214 extern struct machine_ops machine_ops;
18215
18216 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18217 index 8f7866a..e442f20 100644
18218 --- a/arch/x86/include/asm/rmwcc.h
18219 +++ b/arch/x86/include/asm/rmwcc.h
18220 @@ -3,7 +3,34 @@
18221
18222 #ifdef CC_HAVE_ASM_GOTO
18223
18224 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18225 +#ifdef CONFIG_PAX_REFCOUNT
18226 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18227 +do { \
18228 + asm_volatile_goto (fullop \
18229 + ";jno 0f\n" \
18230 + fullantiop \
18231 + ";int $4\n0:\n" \
18232 + _ASM_EXTABLE(0b, 0b) \
18233 + ";j" cc " %l[cc_label]" \
18234 + : : "m" (var), ## __VA_ARGS__ \
18235 + : "memory" : cc_label); \
18236 + return 0; \
18237 +cc_label: \
18238 + return 1; \
18239 +} while (0)
18240 +#else
18241 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18242 +do { \
18243 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18244 + : : "m" (var), ## __VA_ARGS__ \
18245 + : "memory" : cc_label); \
18246 + return 0; \
18247 +cc_label: \
18248 + return 1; \
18249 +} while (0)
18250 +#endif
18251 +
18252 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18253 do { \
18254 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18255 : : "m" (var), ## __VA_ARGS__ \
18256 @@ -13,15 +40,46 @@ cc_label: \
18257 return 1; \
18258 } while (0)
18259
18260 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18261 - __GEN_RMWcc(op " " arg0, var, cc)
18262 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18263 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18264
18265 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18266 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18267 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18268 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18269 +
18270 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18271 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18272 +
18273 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18274 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18275
18276 #else /* !CC_HAVE_ASM_GOTO */
18277
18278 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18279 +#ifdef CONFIG_PAX_REFCOUNT
18280 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18281 +do { \
18282 + char c; \
18283 + asm volatile (fullop \
18284 + ";jno 0f\n" \
18285 + fullantiop \
18286 + ";int $4\n0:\n" \
18287 + _ASM_EXTABLE(0b, 0b) \
18288 + "; set" cc " %1" \
18289 + : "+m" (var), "=qm" (c) \
18290 + : __VA_ARGS__ : "memory"); \
18291 + return c != 0; \
18292 +} while (0)
18293 +#else
18294 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18295 +do { \
18296 + char c; \
18297 + asm volatile (fullop "; set" cc " %1" \
18298 + : "+m" (var), "=qm" (c) \
18299 + : __VA_ARGS__ : "memory"); \
18300 + return c != 0; \
18301 +} while (0)
18302 +#endif
18303 +
18304 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18305 do { \
18306 char c; \
18307 asm volatile (fullop "; set" cc " %1" \
18308 @@ -30,11 +88,17 @@ do { \
18309 return c != 0; \
18310 } while (0)
18311
18312 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18313 - __GEN_RMWcc(op " " arg0, var, cc)
18314 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18315 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18316 +
18317 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18318 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18319 +
18320 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18321 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18322
18323 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18324 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18325 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18326 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18327
18328 #endif /* CC_HAVE_ASM_GOTO */
18329
18330 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18331 index cad82c9..2e5c5c1 100644
18332 --- a/arch/x86/include/asm/rwsem.h
18333 +++ b/arch/x86/include/asm/rwsem.h
18334 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18335 {
18336 asm volatile("# beginning down_read\n\t"
18337 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18338 +
18339 +#ifdef CONFIG_PAX_REFCOUNT
18340 + "jno 0f\n"
18341 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18342 + "int $4\n0:\n"
18343 + _ASM_EXTABLE(0b, 0b)
18344 +#endif
18345 +
18346 /* adds 0x00000001 */
18347 " jns 1f\n"
18348 " call call_rwsem_down_read_failed\n"
18349 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18350 "1:\n\t"
18351 " mov %1,%2\n\t"
18352 " add %3,%2\n\t"
18353 +
18354 +#ifdef CONFIG_PAX_REFCOUNT
18355 + "jno 0f\n"
18356 + "sub %3,%2\n"
18357 + "int $4\n0:\n"
18358 + _ASM_EXTABLE(0b, 0b)
18359 +#endif
18360 +
18361 " jle 2f\n\t"
18362 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18363 " jnz 1b\n\t"
18364 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18365 long tmp;
18366 asm volatile("# beginning down_write\n\t"
18367 LOCK_PREFIX " xadd %1,(%2)\n\t"
18368 +
18369 +#ifdef CONFIG_PAX_REFCOUNT
18370 + "jno 0f\n"
18371 + "mov %1,(%2)\n"
18372 + "int $4\n0:\n"
18373 + _ASM_EXTABLE(0b, 0b)
18374 +#endif
18375 +
18376 /* adds 0xffff0001, returns the old value */
18377 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18378 /* was the active mask 0 before? */
18379 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18380 long tmp;
18381 asm volatile("# beginning __up_read\n\t"
18382 LOCK_PREFIX " xadd %1,(%2)\n\t"
18383 +
18384 +#ifdef CONFIG_PAX_REFCOUNT
18385 + "jno 0f\n"
18386 + "mov %1,(%2)\n"
18387 + "int $4\n0:\n"
18388 + _ASM_EXTABLE(0b, 0b)
18389 +#endif
18390 +
18391 /* subtracts 1, returns the old value */
18392 " jns 1f\n\t"
18393 " call call_rwsem_wake\n" /* expects old value in %edx */
18394 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18395 long tmp;
18396 asm volatile("# beginning __up_write\n\t"
18397 LOCK_PREFIX " xadd %1,(%2)\n\t"
18398 +
18399 +#ifdef CONFIG_PAX_REFCOUNT
18400 + "jno 0f\n"
18401 + "mov %1,(%2)\n"
18402 + "int $4\n0:\n"
18403 + _ASM_EXTABLE(0b, 0b)
18404 +#endif
18405 +
18406 /* subtracts 0xffff0001, returns the old value */
18407 " jns 1f\n\t"
18408 " call call_rwsem_wake\n" /* expects old value in %edx */
18409 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18410 {
18411 asm volatile("# beginning __downgrade_write\n\t"
18412 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18413 +
18414 +#ifdef CONFIG_PAX_REFCOUNT
18415 + "jno 0f\n"
18416 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18417 + "int $4\n0:\n"
18418 + _ASM_EXTABLE(0b, 0b)
18419 +#endif
18420 +
18421 /*
18422 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18423 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18424 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18425 */
18426 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18427 {
18428 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18429 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18430 +
18431 +#ifdef CONFIG_PAX_REFCOUNT
18432 + "jno 0f\n"
18433 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18434 + "int $4\n0:\n"
18435 + _ASM_EXTABLE(0b, 0b)
18436 +#endif
18437 +
18438 : "+m" (sem->count)
18439 : "er" (delta));
18440 }
18441 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18442 */
18443 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18444 {
18445 - return delta + xadd(&sem->count, delta);
18446 + return delta + xadd_check_overflow(&sem->count, delta);
18447 }
18448
18449 #endif /* __KERNEL__ */
18450 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18451 index 6f1c3a8..7744f19 100644
18452 --- a/arch/x86/include/asm/segment.h
18453 +++ b/arch/x86/include/asm/segment.h
18454 @@ -64,10 +64,15 @@
18455 * 26 - ESPFIX small SS
18456 * 27 - per-cpu [ offset to per-cpu data area ]
18457 * 28 - stack_canary-20 [ for stack protector ]
18458 - * 29 - unused
18459 - * 30 - unused
18460 + * 29 - PCI BIOS CS
18461 + * 30 - PCI BIOS DS
18462 * 31 - TSS for double fault handler
18463 */
18464 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18465 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18466 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18467 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18468 +
18469 #define GDT_ENTRY_TLS_MIN 6
18470 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18471
18472 @@ -79,6 +84,8 @@
18473
18474 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18475
18476 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18477 +
18478 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18479
18480 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18481 @@ -104,6 +111,12 @@
18482 #define __KERNEL_STACK_CANARY 0
18483 #endif
18484
18485 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18486 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18487 +
18488 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18489 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18490 +
18491 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18492
18493 /*
18494 @@ -141,7 +154,7 @@
18495 */
18496
18497 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18498 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18499 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18500
18501
18502 #else
18503 @@ -165,6 +178,8 @@
18504 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18505 #define __USER32_DS __USER_DS
18506
18507 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18508 +
18509 #define GDT_ENTRY_TSS 8 /* needs two entries */
18510 #define GDT_ENTRY_LDT 10 /* needs two entries */
18511 #define GDT_ENTRY_TLS_MIN 12
18512 @@ -173,6 +188,8 @@
18513 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18514 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18515
18516 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18517 +
18518 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18519 #define FS_TLS 0
18520 #define GS_TLS 1
18521 @@ -180,12 +197,14 @@
18522 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18523 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18524
18525 -#define GDT_ENTRIES 16
18526 +#define GDT_ENTRIES 17
18527
18528 #endif
18529
18530 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18531 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18532 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18533 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18534 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18535 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18536 #ifndef CONFIG_PARAVIRT
18537 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18538 {
18539 unsigned long __limit;
18540 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18541 - return __limit + 1;
18542 + return __limit;
18543 }
18544
18545 #endif /* !__ASSEMBLY__ */
18546 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18547 index 8d3120f..352b440 100644
18548 --- a/arch/x86/include/asm/smap.h
18549 +++ b/arch/x86/include/asm/smap.h
18550 @@ -25,11 +25,40 @@
18551
18552 #include <asm/alternative-asm.h>
18553
18554 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18555 +#define ASM_PAX_OPEN_USERLAND \
18556 + 661: jmp 663f; \
18557 + .pushsection .altinstr_replacement, "a" ; \
18558 + 662: pushq %rax; nop; \
18559 + .popsection ; \
18560 + .pushsection .altinstructions, "a" ; \
18561 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18562 + .popsection ; \
18563 + call __pax_open_userland; \
18564 + popq %rax; \
18565 + 663:
18566 +
18567 +#define ASM_PAX_CLOSE_USERLAND \
18568 + 661: jmp 663f; \
18569 + .pushsection .altinstr_replacement, "a" ; \
18570 + 662: pushq %rax; nop; \
18571 + .popsection; \
18572 + .pushsection .altinstructions, "a" ; \
18573 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18574 + .popsection; \
18575 + call __pax_close_userland; \
18576 + popq %rax; \
18577 + 663:
18578 +#else
18579 +#define ASM_PAX_OPEN_USERLAND
18580 +#define ASM_PAX_CLOSE_USERLAND
18581 +#endif
18582 +
18583 #ifdef CONFIG_X86_SMAP
18584
18585 #define ASM_CLAC \
18586 661: ASM_NOP3 ; \
18587 - .pushsection .altinstr_replacement, "ax" ; \
18588 + .pushsection .altinstr_replacement, "a" ; \
18589 662: __ASM_CLAC ; \
18590 .popsection ; \
18591 .pushsection .altinstructions, "a" ; \
18592 @@ -38,7 +67,7 @@
18593
18594 #define ASM_STAC \
18595 661: ASM_NOP3 ; \
18596 - .pushsection .altinstr_replacement, "ax" ; \
18597 + .pushsection .altinstr_replacement, "a" ; \
18598 662: __ASM_STAC ; \
18599 .popsection ; \
18600 .pushsection .altinstructions, "a" ; \
18601 @@ -56,6 +85,37 @@
18602
18603 #include <asm/alternative.h>
18604
18605 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18606 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18607 +
18608 +extern void __pax_open_userland(void);
18609 +static __always_inline unsigned long pax_open_userland(void)
18610 +{
18611 +
18612 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18613 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18614 + :
18615 + : [open] "i" (__pax_open_userland)
18616 + : "memory", "rax");
18617 +#endif
18618 +
18619 + return 0;
18620 +}
18621 +
18622 +extern void __pax_close_userland(void);
18623 +static __always_inline unsigned long pax_close_userland(void)
18624 +{
18625 +
18626 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18627 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18628 + :
18629 + : [close] "i" (__pax_close_userland)
18630 + : "memory", "rax");
18631 +#endif
18632 +
18633 + return 0;
18634 +}
18635 +
18636 #ifdef CONFIG_X86_SMAP
18637
18638 static __always_inline void clac(void)
18639 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18640 index 8cd27e0..7f05ec8 100644
18641 --- a/arch/x86/include/asm/smp.h
18642 +++ b/arch/x86/include/asm/smp.h
18643 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18644 /* cpus sharing the last level cache: */
18645 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18646 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18647 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18648 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18649
18650 static inline struct cpumask *cpu_sibling_mask(int cpu)
18651 {
18652 @@ -78,7 +78,7 @@ struct smp_ops {
18653
18654 void (*send_call_func_ipi)(const struct cpumask *mask);
18655 void (*send_call_func_single_ipi)(int cpu);
18656 -};
18657 +} __no_const;
18658
18659 /* Globals due to paravirt */
18660 extern void set_cpu_sibling_map(int cpu);
18661 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18662 extern int safe_smp_processor_id(void);
18663
18664 #elif defined(CONFIG_X86_64_SMP)
18665 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18666 -
18667 -#define stack_smp_processor_id() \
18668 -({ \
18669 - struct thread_info *ti; \
18670 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18671 - ti->cpu; \
18672 -})
18673 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18674 +#define stack_smp_processor_id() raw_smp_processor_id()
18675 #define safe_smp_processor_id() smp_processor_id()
18676
18677 #endif
18678 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18679 index 0f62f54..cb5d0dd 100644
18680 --- a/arch/x86/include/asm/spinlock.h
18681 +++ b/arch/x86/include/asm/spinlock.h
18682 @@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18683 static inline void arch_read_lock(arch_rwlock_t *rw)
18684 {
18685 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18686 +
18687 +#ifdef CONFIG_PAX_REFCOUNT
18688 + "jno 0f\n"
18689 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18690 + "int $4\n0:\n"
18691 + _ASM_EXTABLE(0b, 0b)
18692 +#endif
18693 +
18694 "jns 1f\n"
18695 "call __read_lock_failed\n\t"
18696 "1:\n"
18697 @@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18698 static inline void arch_write_lock(arch_rwlock_t *rw)
18699 {
18700 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18701 +
18702 +#ifdef CONFIG_PAX_REFCOUNT
18703 + "jno 0f\n"
18704 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18705 + "int $4\n0:\n"
18706 + _ASM_EXTABLE(0b, 0b)
18707 +#endif
18708 +
18709 "jz 1f\n"
18710 "call __write_lock_failed\n\t"
18711 "1:\n"
18712 @@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18713
18714 static inline void arch_read_unlock(arch_rwlock_t *rw)
18715 {
18716 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18717 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18718 +
18719 +#ifdef CONFIG_PAX_REFCOUNT
18720 + "jno 0f\n"
18721 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18722 + "int $4\n0:\n"
18723 + _ASM_EXTABLE(0b, 0b)
18724 +#endif
18725 +
18726 :"+m" (rw->lock) : : "memory");
18727 }
18728
18729 static inline void arch_write_unlock(arch_rwlock_t *rw)
18730 {
18731 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18732 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18733 +
18734 +#ifdef CONFIG_PAX_REFCOUNT
18735 + "jno 0f\n"
18736 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18737 + "int $4\n0:\n"
18738 + _ASM_EXTABLE(0b, 0b)
18739 +#endif
18740 +
18741 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18742 }
18743
18744 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18745 index 6a99859..03cb807 100644
18746 --- a/arch/x86/include/asm/stackprotector.h
18747 +++ b/arch/x86/include/asm/stackprotector.h
18748 @@ -47,7 +47,7 @@
18749 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18750 */
18751 #define GDT_STACK_CANARY_INIT \
18752 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18753 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18754
18755 /*
18756 * Initialize the stackprotector canary value.
18757 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18758
18759 static inline void load_stack_canary_segment(void)
18760 {
18761 -#ifdef CONFIG_X86_32
18762 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18763 asm volatile ("mov %0, %%gs" : : "r" (0));
18764 #endif
18765 }
18766 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18767 index 70bbe39..4ae2bd4 100644
18768 --- a/arch/x86/include/asm/stacktrace.h
18769 +++ b/arch/x86/include/asm/stacktrace.h
18770 @@ -11,28 +11,20 @@
18771
18772 extern int kstack_depth_to_print;
18773
18774 -struct thread_info;
18775 +struct task_struct;
18776 struct stacktrace_ops;
18777
18778 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18779 - unsigned long *stack,
18780 - unsigned long bp,
18781 - const struct stacktrace_ops *ops,
18782 - void *data,
18783 - unsigned long *end,
18784 - int *graph);
18785 +typedef unsigned long walk_stack_t(struct task_struct *task,
18786 + void *stack_start,
18787 + unsigned long *stack,
18788 + unsigned long bp,
18789 + const struct stacktrace_ops *ops,
18790 + void *data,
18791 + unsigned long *end,
18792 + int *graph);
18793
18794 -extern unsigned long
18795 -print_context_stack(struct thread_info *tinfo,
18796 - unsigned long *stack, unsigned long bp,
18797 - const struct stacktrace_ops *ops, void *data,
18798 - unsigned long *end, int *graph);
18799 -
18800 -extern unsigned long
18801 -print_context_stack_bp(struct thread_info *tinfo,
18802 - unsigned long *stack, unsigned long bp,
18803 - const struct stacktrace_ops *ops, void *data,
18804 - unsigned long *end, int *graph);
18805 +extern walk_stack_t print_context_stack;
18806 +extern walk_stack_t print_context_stack_bp;
18807
18808 /* Generic stack tracer with callbacks */
18809
18810 @@ -40,7 +32,7 @@ struct stacktrace_ops {
18811 void (*address)(void *data, unsigned long address, int reliable);
18812 /* On negative return stop dumping */
18813 int (*stack)(void *data, char *name);
18814 - walk_stack_t walk_stack;
18815 + walk_stack_t *walk_stack;
18816 };
18817
18818 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18819 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18820 index d7f3b3b..3cc39f1 100644
18821 --- a/arch/x86/include/asm/switch_to.h
18822 +++ b/arch/x86/include/asm/switch_to.h
18823 @@ -108,7 +108,7 @@ do { \
18824 "call __switch_to\n\t" \
18825 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18826 __switch_canary \
18827 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
18828 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18829 "movq %%rax,%%rdi\n\t" \
18830 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18831 "jnz ret_from_fork\n\t" \
18832 @@ -119,7 +119,7 @@ do { \
18833 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18834 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18835 [_tif_fork] "i" (_TIF_FORK), \
18836 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
18837 + [thread_info] "m" (current_tinfo), \
18838 [current_task] "m" (current_task) \
18839 __switch_canary_iparam \
18840 : "memory", "cc" __EXTRA_CLOBBER)
18841 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18842 index e1940c0..ac50dd8 100644
18843 --- a/arch/x86/include/asm/thread_info.h
18844 +++ b/arch/x86/include/asm/thread_info.h
18845 @@ -10,6 +10,7 @@
18846 #include <linux/compiler.h>
18847 #include <asm/page.h>
18848 #include <asm/types.h>
18849 +#include <asm/percpu.h>
18850
18851 /*
18852 * low level task data that entry.S needs immediate access to
18853 @@ -23,7 +24,6 @@ struct exec_domain;
18854 #include <linux/atomic.h>
18855
18856 struct thread_info {
18857 - struct task_struct *task; /* main task structure */
18858 struct exec_domain *exec_domain; /* execution domain */
18859 __u32 flags; /* low level flags */
18860 __u32 status; /* thread synchronous flags */
18861 @@ -32,19 +32,13 @@ struct thread_info {
18862 mm_segment_t addr_limit;
18863 struct restart_block restart_block;
18864 void __user *sysenter_return;
18865 -#ifdef CONFIG_X86_32
18866 - unsigned long previous_esp; /* ESP of the previous stack in
18867 - case of nested (IRQ) stacks
18868 - */
18869 - __u8 supervisor_stack[0];
18870 -#endif
18871 + unsigned long lowest_stack;
18872 unsigned int sig_on_uaccess_error:1;
18873 unsigned int uaccess_err:1; /* uaccess failed */
18874 };
18875
18876 -#define INIT_THREAD_INFO(tsk) \
18877 +#define INIT_THREAD_INFO \
18878 { \
18879 - .task = &tsk, \
18880 .exec_domain = &default_exec_domain, \
18881 .flags = 0, \
18882 .cpu = 0, \
18883 @@ -55,7 +49,7 @@ struct thread_info {
18884 }, \
18885 }
18886
18887 -#define init_thread_info (init_thread_union.thread_info)
18888 +#define init_thread_info (init_thread_union.stack)
18889 #define init_stack (init_thread_union.stack)
18890
18891 #else /* !__ASSEMBLY__ */
18892 @@ -95,6 +89,7 @@ struct thread_info {
18893 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18894 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18895 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18896 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18897
18898 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18899 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18900 @@ -118,17 +113,18 @@ struct thread_info {
18901 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18902 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18903 #define _TIF_X32 (1 << TIF_X32)
18904 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18905
18906 /* work to do in syscall_trace_enter() */
18907 #define _TIF_WORK_SYSCALL_ENTRY \
18908 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18909 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18910 - _TIF_NOHZ)
18911 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18912
18913 /* work to do in syscall_trace_leave() */
18914 #define _TIF_WORK_SYSCALL_EXIT \
18915 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18916 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18917 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18918
18919 /* work to do on interrupt/exception return */
18920 #define _TIF_WORK_MASK \
18921 @@ -139,7 +135,7 @@ struct thread_info {
18922 /* work to do on any return to user space */
18923 #define _TIF_ALLWORK_MASK \
18924 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18925 - _TIF_NOHZ)
18926 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18927
18928 /* Only used for 64 bit */
18929 #define _TIF_DO_NOTIFY_MASK \
18930 @@ -153,6 +149,23 @@ struct thread_info {
18931 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
18932 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
18933
18934 +#ifdef __ASSEMBLY__
18935 +/* how to get the thread information struct from ASM */
18936 +#define GET_THREAD_INFO(reg) \
18937 + mov PER_CPU_VAR(current_tinfo), reg
18938 +
18939 +/* use this one if reg already contains %esp */
18940 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18941 +#else
18942 +/* how to get the thread information struct from C */
18943 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18944 +
18945 +static __always_inline struct thread_info *current_thread_info(void)
18946 +{
18947 + return this_cpu_read_stable(current_tinfo);
18948 +}
18949 +#endif
18950 +
18951 #ifdef CONFIG_X86_32
18952
18953 #define STACK_WARN (THREAD_SIZE/8)
18954 @@ -169,31 +182,10 @@ struct thread_info {
18955 sp; \
18956 })
18957
18958 -/* how to get the thread information struct from C */
18959 -static inline struct thread_info *current_thread_info(void)
18960 -{
18961 - return (struct thread_info *)
18962 - (current_stack_pointer & ~(THREAD_SIZE - 1));
18963 -}
18964 -
18965 -#else /* !__ASSEMBLY__ */
18966 -
18967 -/* how to get the thread information struct from ASM */
18968 -#define GET_THREAD_INFO(reg) \
18969 - movl $-THREAD_SIZE, reg; \
18970 - andl %esp, reg
18971 -
18972 -/* use this one if reg already contains %esp */
18973 -#define GET_THREAD_INFO_WITH_ESP(reg) \
18974 - andl $-THREAD_SIZE, reg
18975 -
18976 #endif
18977
18978 #else /* X86_32 */
18979
18980 -#include <asm/percpu.h>
18981 -#define KERNEL_STACK_OFFSET (5*8)
18982 -
18983 /*
18984 * macros/functions for gaining access to the thread information structure
18985 * preempt_count needs to be 1 initially, until the scheduler is functional.
18986 @@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
18987 #ifndef __ASSEMBLY__
18988 DECLARE_PER_CPU(unsigned long, kernel_stack);
18989
18990 -static inline struct thread_info *current_thread_info(void)
18991 -{
18992 - struct thread_info *ti;
18993 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
18994 - KERNEL_STACK_OFFSET - THREAD_SIZE);
18995 - return ti;
18996 -}
18997 -
18998 -#else /* !__ASSEMBLY__ */
18999 -
19000 -/* how to get the thread information struct from ASM */
19001 -#define GET_THREAD_INFO(reg) \
19002 - movq PER_CPU_VAR(kernel_stack),reg ; \
19003 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19004 -
19005 -/*
19006 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19007 - * a certain register (to be used in assembler memory operands).
19008 - */
19009 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19010 -
19011 +/* how to get the current stack pointer from C */
19012 +register unsigned long current_stack_pointer asm("rsp") __used;
19013 #endif
19014
19015 #endif /* !X86_32 */
19016 @@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19017 extern void arch_task_cache_init(void);
19018 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19019 extern void arch_release_task_struct(struct task_struct *tsk);
19020 +
19021 +#define __HAVE_THREAD_FUNCTIONS
19022 +#define task_thread_info(task) (&(task)->tinfo)
19023 +#define task_stack_page(task) ((task)->stack)
19024 +#define setup_thread_stack(p, org) do {} while (0)
19025 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19026 +
19027 #endif
19028 #endif /* _ASM_X86_THREAD_INFO_H */
19029 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19030 index 04905bf..49203ca 100644
19031 --- a/arch/x86/include/asm/tlbflush.h
19032 +++ b/arch/x86/include/asm/tlbflush.h
19033 @@ -17,18 +17,44 @@
19034
19035 static inline void __native_flush_tlb(void)
19036 {
19037 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19038 + u64 descriptor[2];
19039 +
19040 + descriptor[0] = PCID_KERNEL;
19041 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19042 + return;
19043 + }
19044 +
19045 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19046 + if (static_cpu_has(X86_FEATURE_PCID)) {
19047 + unsigned int cpu = raw_get_cpu();
19048 +
19049 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19050 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19051 + raw_put_cpu_no_resched();
19052 + return;
19053 + }
19054 +#endif
19055 +
19056 native_write_cr3(native_read_cr3());
19057 }
19058
19059 static inline void __native_flush_tlb_global_irq_disabled(void)
19060 {
19061 - unsigned long cr4;
19062 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19063 + u64 descriptor[2];
19064
19065 - cr4 = native_read_cr4();
19066 - /* clear PGE */
19067 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19068 - /* write old PGE again and flush TLBs */
19069 - native_write_cr4(cr4);
19070 + descriptor[0] = PCID_KERNEL;
19071 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19072 + } else {
19073 + unsigned long cr4;
19074 +
19075 + cr4 = native_read_cr4();
19076 + /* clear PGE */
19077 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19078 + /* write old PGE again and flush TLBs */
19079 + native_write_cr4(cr4);
19080 + }
19081 }
19082
19083 static inline void __native_flush_tlb_global(void)
19084 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19085
19086 static inline void __native_flush_tlb_single(unsigned long addr)
19087 {
19088 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19089 + u64 descriptor[2];
19090 +
19091 + descriptor[0] = PCID_KERNEL;
19092 + descriptor[1] = addr;
19093 +
19094 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19095 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19096 + if (addr < TASK_SIZE_MAX)
19097 + descriptor[1] += pax_user_shadow_base;
19098 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19099 + }
19100 +
19101 + descriptor[0] = PCID_USER;
19102 + descriptor[1] = addr;
19103 +#endif
19104 +
19105 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19106 + return;
19107 + }
19108 +
19109 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19110 + if (static_cpu_has(X86_FEATURE_PCID)) {
19111 + unsigned int cpu = raw_get_cpu();
19112 +
19113 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19114 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19115 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19116 + raw_put_cpu_no_resched();
19117 +
19118 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19119 + addr += pax_user_shadow_base;
19120 + }
19121 +#endif
19122 +
19123 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19124 }
19125
19126 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19127 index 0d592e0..f58a222 100644
19128 --- a/arch/x86/include/asm/uaccess.h
19129 +++ b/arch/x86/include/asm/uaccess.h
19130 @@ -7,6 +7,7 @@
19131 #include <linux/compiler.h>
19132 #include <linux/thread_info.h>
19133 #include <linux/string.h>
19134 +#include <linux/spinlock.h>
19135 #include <asm/asm.h>
19136 #include <asm/page.h>
19137 #include <asm/smap.h>
19138 @@ -29,7 +30,12 @@
19139
19140 #define get_ds() (KERNEL_DS)
19141 #define get_fs() (current_thread_info()->addr_limit)
19142 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19143 +void __set_fs(mm_segment_t x);
19144 +void set_fs(mm_segment_t x);
19145 +#else
19146 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19147 +#endif
19148
19149 #define segment_eq(a, b) ((a).seg == (b).seg)
19150
19151 @@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19152 * checks that the pointer is in the user space range - after calling
19153 * this function, memory access functions may still return -EFAULT.
19154 */
19155 -#define access_ok(type, addr, size) \
19156 - likely(!__range_not_ok(addr, size, user_addr_max()))
19157 +extern int _cond_resched(void);
19158 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19159 +#define access_ok(type, addr, size) \
19160 +({ \
19161 + long __size = size; \
19162 + unsigned long __addr = (unsigned long)addr; \
19163 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19164 + unsigned long __end_ao = __addr + __size - 1; \
19165 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19166 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19167 + while(__addr_ao <= __end_ao) { \
19168 + char __c_ao; \
19169 + __addr_ao += PAGE_SIZE; \
19170 + if (__size > PAGE_SIZE) \
19171 + _cond_resched(); \
19172 + if (__get_user(__c_ao, (char __user *)__addr)) \
19173 + break; \
19174 + if (type != VERIFY_WRITE) { \
19175 + __addr = __addr_ao; \
19176 + continue; \
19177 + } \
19178 + if (__put_user(__c_ao, (char __user *)__addr)) \
19179 + break; \
19180 + __addr = __addr_ao; \
19181 + } \
19182 + } \
19183 + __ret_ao; \
19184 +})
19185
19186 /*
19187 * The exception table consists of pairs of addresses relative to the
19188 @@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19189 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19190 __chk_user_ptr(ptr); \
19191 might_fault(); \
19192 + pax_open_userland(); \
19193 asm volatile("call __get_user_%P3" \
19194 : "=a" (__ret_gu), "=r" (__val_gu) \
19195 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19196 (x) = (__typeof__(*(ptr))) __val_gu; \
19197 + pax_close_userland(); \
19198 __ret_gu; \
19199 })
19200
19201 @@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19202 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19203 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19204
19205 -
19206 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19207 +#define __copyuser_seg "gs;"
19208 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19209 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19210 +#else
19211 +#define __copyuser_seg
19212 +#define __COPYUSER_SET_ES
19213 +#define __COPYUSER_RESTORE_ES
19214 +#endif
19215
19216 #ifdef CONFIG_X86_32
19217 #define __put_user_asm_u64(x, addr, err, errret) \
19218 asm volatile(ASM_STAC "\n" \
19219 - "1: movl %%eax,0(%2)\n" \
19220 - "2: movl %%edx,4(%2)\n" \
19221 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19222 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19223 "3: " ASM_CLAC "\n" \
19224 ".section .fixup,\"ax\"\n" \
19225 "4: movl %3,%0\n" \
19226 @@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19227
19228 #define __put_user_asm_ex_u64(x, addr) \
19229 asm volatile(ASM_STAC "\n" \
19230 - "1: movl %%eax,0(%1)\n" \
19231 - "2: movl %%edx,4(%1)\n" \
19232 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19233 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19234 "3: " ASM_CLAC "\n" \
19235 _ASM_EXTABLE_EX(1b, 2b) \
19236 _ASM_EXTABLE_EX(2b, 3b) \
19237 @@ -257,7 +299,8 @@ extern void __put_user_8(void);
19238 __typeof__(*(ptr)) __pu_val; \
19239 __chk_user_ptr(ptr); \
19240 might_fault(); \
19241 - __pu_val = x; \
19242 + __pu_val = (x); \
19243 + pax_open_userland(); \
19244 switch (sizeof(*(ptr))) { \
19245 case 1: \
19246 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19247 @@ -275,6 +318,7 @@ extern void __put_user_8(void);
19248 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19249 break; \
19250 } \
19251 + pax_close_userland(); \
19252 __ret_pu; \
19253 })
19254
19255 @@ -355,8 +399,10 @@ do { \
19256 } while (0)
19257
19258 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19259 +do { \
19260 + pax_open_userland(); \
19261 asm volatile(ASM_STAC "\n" \
19262 - "1: mov"itype" %2,%"rtype"1\n" \
19263 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19264 "2: " ASM_CLAC "\n" \
19265 ".section .fixup,\"ax\"\n" \
19266 "3: mov %3,%0\n" \
19267 @@ -364,8 +410,10 @@ do { \
19268 " jmp 2b\n" \
19269 ".previous\n" \
19270 _ASM_EXTABLE(1b, 3b) \
19271 - : "=r" (err), ltype(x) \
19272 - : "m" (__m(addr)), "i" (errret), "0" (err))
19273 + : "=r" (err), ltype (x) \
19274 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19275 + pax_close_userland(); \
19276 +} while (0)
19277
19278 #define __get_user_size_ex(x, ptr, size) \
19279 do { \
19280 @@ -389,7 +437,7 @@ do { \
19281 } while (0)
19282
19283 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19284 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19285 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19286 "2:\n" \
19287 _ASM_EXTABLE_EX(1b, 2b) \
19288 : ltype(x) : "m" (__m(addr)))
19289 @@ -406,13 +454,24 @@ do { \
19290 int __gu_err; \
19291 unsigned long __gu_val; \
19292 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19293 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19294 + (x) = (__typeof__(*(ptr)))__gu_val; \
19295 __gu_err; \
19296 })
19297
19298 /* FIXME: this hack is definitely wrong -AK */
19299 struct __large_struct { unsigned long buf[100]; };
19300 -#define __m(x) (*(struct __large_struct __user *)(x))
19301 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19302 +#define ____m(x) \
19303 +({ \
19304 + unsigned long ____x = (unsigned long)(x); \
19305 + if (____x < pax_user_shadow_base) \
19306 + ____x += pax_user_shadow_base; \
19307 + (typeof(x))____x; \
19308 +})
19309 +#else
19310 +#define ____m(x) (x)
19311 +#endif
19312 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19313
19314 /*
19315 * Tell gcc we read from memory instead of writing: this is because
19316 @@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
19317 * aliasing issues.
19318 */
19319 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19320 +do { \
19321 + pax_open_userland(); \
19322 asm volatile(ASM_STAC "\n" \
19323 - "1: mov"itype" %"rtype"1,%2\n" \
19324 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19325 "2: " ASM_CLAC "\n" \
19326 ".section .fixup,\"ax\"\n" \
19327 "3: mov %3,%0\n" \
19328 @@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
19329 ".previous\n" \
19330 _ASM_EXTABLE(1b, 3b) \
19331 : "=r"(err) \
19332 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19333 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19334 + pax_close_userland(); \
19335 +} while (0)
19336
19337 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19338 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19339 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19340 "2:\n" \
19341 _ASM_EXTABLE_EX(1b, 2b) \
19342 : : ltype(x), "m" (__m(addr)))
19343 @@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
19344 */
19345 #define uaccess_try do { \
19346 current_thread_info()->uaccess_err = 0; \
19347 + pax_open_userland(); \
19348 stac(); \
19349 barrier();
19350
19351 #define uaccess_catch(err) \
19352 clac(); \
19353 + pax_close_userland(); \
19354 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19355 } while (0)
19356
19357 @@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
19358 * On error, the variable @x is set to zero.
19359 */
19360
19361 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19362 +#define __get_user(x, ptr) get_user((x), (ptr))
19363 +#else
19364 #define __get_user(x, ptr) \
19365 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19366 +#endif
19367
19368 /**
19369 * __put_user: - Write a simple value into user space, with less checking.
19370 @@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
19371 * Returns zero on success, or -EFAULT on error.
19372 */
19373
19374 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19375 +#define __put_user(x, ptr) put_user((x), (ptr))
19376 +#else
19377 #define __put_user(x, ptr) \
19378 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19379 +#endif
19380
19381 #define __get_user_unaligned __get_user
19382 #define __put_user_unaligned __put_user
19383 @@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
19384 #define get_user_ex(x, ptr) do { \
19385 unsigned long __gue_val; \
19386 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19387 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19388 + (x) = (__typeof__(*(ptr)))__gue_val; \
19389 } while (0)
19390
19391 #define put_user_try uaccess_try
19392 @@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
19393 __typeof__(ptr) __uval = (uval); \
19394 __typeof__(*(ptr)) __old = (old); \
19395 __typeof__(*(ptr)) __new = (new); \
19396 + pax_open_userland(); \
19397 switch (size) { \
19398 case 1: \
19399 { \
19400 asm volatile("\t" ASM_STAC "\n" \
19401 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19402 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19403 "2:\t" ASM_CLAC "\n" \
19404 "\t.section .fixup, \"ax\"\n" \
19405 "3:\tmov %3, %0\n" \
19406 "\tjmp 2b\n" \
19407 "\t.previous\n" \
19408 _ASM_EXTABLE(1b, 3b) \
19409 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19410 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19411 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19412 : "memory" \
19413 ); \
19414 @@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
19415 case 2: \
19416 { \
19417 asm volatile("\t" ASM_STAC "\n" \
19418 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19419 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19420 "2:\t" ASM_CLAC "\n" \
19421 "\t.section .fixup, \"ax\"\n" \
19422 "3:\tmov %3, %0\n" \
19423 "\tjmp 2b\n" \
19424 "\t.previous\n" \
19425 _ASM_EXTABLE(1b, 3b) \
19426 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19427 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19428 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19429 : "memory" \
19430 ); \
19431 @@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
19432 case 4: \
19433 { \
19434 asm volatile("\t" ASM_STAC "\n" \
19435 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19436 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19437 "2:\t" ASM_CLAC "\n" \
19438 "\t.section .fixup, \"ax\"\n" \
19439 "3:\tmov %3, %0\n" \
19440 "\tjmp 2b\n" \
19441 "\t.previous\n" \
19442 _ASM_EXTABLE(1b, 3b) \
19443 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19444 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19445 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19446 : "memory" \
19447 ); \
19448 @@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
19449 __cmpxchg_wrong_size(); \
19450 \
19451 asm volatile("\t" ASM_STAC "\n" \
19452 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19453 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19454 "2:\t" ASM_CLAC "\n" \
19455 "\t.section .fixup, \"ax\"\n" \
19456 "3:\tmov %3, %0\n" \
19457 "\tjmp 2b\n" \
19458 "\t.previous\n" \
19459 _ASM_EXTABLE(1b, 3b) \
19460 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19461 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19462 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19463 : "memory" \
19464 ); \
19465 @@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
19466 default: \
19467 __cmpxchg_wrong_size(); \
19468 } \
19469 + pax_close_userland(); \
19470 *__uval = __old; \
19471 __ret; \
19472 })
19473 @@ -636,17 +711,6 @@ extern struct movsl_mask {
19474
19475 #define ARCH_HAS_NOCACHE_UACCESS 1
19476
19477 -#ifdef CONFIG_X86_32
19478 -# include <asm/uaccess_32.h>
19479 -#else
19480 -# include <asm/uaccess_64.h>
19481 -#endif
19482 -
19483 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19484 - unsigned n);
19485 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19486 - unsigned n);
19487 -
19488 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19489 # define copy_user_diag __compiletime_error
19490 #else
19491 @@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19492 extern void copy_user_diag("copy_from_user() buffer size is too small")
19493 copy_from_user_overflow(void);
19494 extern void copy_user_diag("copy_to_user() buffer size is too small")
19495 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19496 +copy_to_user_overflow(void);
19497
19498 #undef copy_user_diag
19499
19500 @@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19501
19502 extern void
19503 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19504 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19505 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19506 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19507
19508 #else
19509 @@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19510
19511 #endif
19512
19513 +#ifdef CONFIG_X86_32
19514 +# include <asm/uaccess_32.h>
19515 +#else
19516 +# include <asm/uaccess_64.h>
19517 +#endif
19518 +
19519 static inline unsigned long __must_check
19520 copy_from_user(void *to, const void __user *from, unsigned long n)
19521 {
19522 - int sz = __compiletime_object_size(to);
19523 + size_t sz = __compiletime_object_size(to);
19524
19525 might_fault();
19526
19527 @@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19528 * case, and do only runtime checking for non-constant sizes.
19529 */
19530
19531 - if (likely(sz < 0 || sz >= n))
19532 - n = _copy_from_user(to, from, n);
19533 - else if(__builtin_constant_p(n))
19534 - copy_from_user_overflow();
19535 - else
19536 - __copy_from_user_overflow(sz, n);
19537 + if (likely(sz != (size_t)-1 && sz < n)) {
19538 + if(__builtin_constant_p(n))
19539 + copy_from_user_overflow();
19540 + else
19541 + __copy_from_user_overflow(sz, n);
19542 + } if (access_ok(VERIFY_READ, from, n))
19543 + n = __copy_from_user(to, from, n);
19544 + else if ((long)n > 0)
19545 + memset(to, 0, n);
19546
19547 return n;
19548 }
19549 @@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19550 static inline unsigned long __must_check
19551 copy_to_user(void __user *to, const void *from, unsigned long n)
19552 {
19553 - int sz = __compiletime_object_size(from);
19554 + size_t sz = __compiletime_object_size(from);
19555
19556 might_fault();
19557
19558 /* See the comment in copy_from_user() above. */
19559 - if (likely(sz < 0 || sz >= n))
19560 - n = _copy_to_user(to, from, n);
19561 - else if(__builtin_constant_p(n))
19562 - copy_to_user_overflow();
19563 - else
19564 - __copy_to_user_overflow(sz, n);
19565 + if (likely(sz != (size_t)-1 && sz < n)) {
19566 + if(__builtin_constant_p(n))
19567 + copy_to_user_overflow();
19568 + else
19569 + __copy_to_user_overflow(sz, n);
19570 + } else if (access_ok(VERIFY_WRITE, to, n))
19571 + n = __copy_to_user(to, from, n);
19572
19573 return n;
19574 }
19575 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19576 index 3c03a5d..1071638 100644
19577 --- a/arch/x86/include/asm/uaccess_32.h
19578 +++ b/arch/x86/include/asm/uaccess_32.h
19579 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19580 static __always_inline unsigned long __must_check
19581 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19582 {
19583 + if ((long)n < 0)
19584 + return n;
19585 +
19586 + check_object_size(from, n, true);
19587 +
19588 if (__builtin_constant_p(n)) {
19589 unsigned long ret;
19590
19591 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19592 __copy_to_user(void __user *to, const void *from, unsigned long n)
19593 {
19594 might_fault();
19595 +
19596 return __copy_to_user_inatomic(to, from, n);
19597 }
19598
19599 static __always_inline unsigned long
19600 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19601 {
19602 + if ((long)n < 0)
19603 + return n;
19604 +
19605 /* Avoid zeroing the tail if the copy fails..
19606 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19607 * but as the zeroing behaviour is only significant when n is not
19608 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19609 __copy_from_user(void *to, const void __user *from, unsigned long n)
19610 {
19611 might_fault();
19612 +
19613 + if ((long)n < 0)
19614 + return n;
19615 +
19616 + check_object_size(to, n, false);
19617 +
19618 if (__builtin_constant_p(n)) {
19619 unsigned long ret;
19620
19621 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19622 const void __user *from, unsigned long n)
19623 {
19624 might_fault();
19625 +
19626 + if ((long)n < 0)
19627 + return n;
19628 +
19629 if (__builtin_constant_p(n)) {
19630 unsigned long ret;
19631
19632 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19633 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19634 unsigned long n)
19635 {
19636 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19637 + if ((long)n < 0)
19638 + return n;
19639 +
19640 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19641 }
19642
19643 #endif /* _ASM_X86_UACCESS_32_H */
19644 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19645 index 12a26b9..206c200 100644
19646 --- a/arch/x86/include/asm/uaccess_64.h
19647 +++ b/arch/x86/include/asm/uaccess_64.h
19648 @@ -10,6 +10,9 @@
19649 #include <asm/alternative.h>
19650 #include <asm/cpufeature.h>
19651 #include <asm/page.h>
19652 +#include <asm/pgtable.h>
19653 +
19654 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19655
19656 /*
19657 * Copy To/From Userspace
19658 @@ -17,14 +20,14 @@
19659
19660 /* Handles exceptions in both to and from, but doesn't do access_ok */
19661 __must_check unsigned long
19662 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19663 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19664 __must_check unsigned long
19665 -copy_user_generic_string(void *to, const void *from, unsigned len);
19666 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19667 __must_check unsigned long
19668 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19669 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19670
19671 static __always_inline __must_check unsigned long
19672 -copy_user_generic(void *to, const void *from, unsigned len)
19673 +copy_user_generic(void *to, const void *from, unsigned long len)
19674 {
19675 unsigned ret;
19676
19677 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19678 }
19679
19680 __must_check unsigned long
19681 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19682 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19683
19684 static __always_inline __must_check
19685 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19686 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19687 {
19688 - int ret = 0;
19689 + size_t sz = __compiletime_object_size(dst);
19690 + unsigned ret = 0;
19691 +
19692 + if (size > INT_MAX)
19693 + return size;
19694 +
19695 + check_object_size(dst, size, false);
19696 +
19697 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19698 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19699 + return size;
19700 +#endif
19701 +
19702 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19703 + if(__builtin_constant_p(size))
19704 + copy_from_user_overflow();
19705 + else
19706 + __copy_from_user_overflow(sz, size);
19707 + return size;
19708 + }
19709
19710 if (!__builtin_constant_p(size))
19711 - return copy_user_generic(dst, (__force void *)src, size);
19712 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19713 switch (size) {
19714 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19715 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19716 ret, "b", "b", "=q", 1);
19717 return ret;
19718 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19719 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19720 ret, "w", "w", "=r", 2);
19721 return ret;
19722 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19723 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19724 ret, "l", "k", "=r", 4);
19725 return ret;
19726 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19727 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19728 ret, "q", "", "=r", 8);
19729 return ret;
19730 case 10:
19731 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19732 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19733 ret, "q", "", "=r", 10);
19734 if (unlikely(ret))
19735 return ret;
19736 __get_user_asm(*(u16 *)(8 + (char *)dst),
19737 - (u16 __user *)(8 + (char __user *)src),
19738 + (const u16 __user *)(8 + (const char __user *)src),
19739 ret, "w", "w", "=r", 2);
19740 return ret;
19741 case 16:
19742 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19743 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19744 ret, "q", "", "=r", 16);
19745 if (unlikely(ret))
19746 return ret;
19747 __get_user_asm(*(u64 *)(8 + (char *)dst),
19748 - (u64 __user *)(8 + (char __user *)src),
19749 + (const u64 __user *)(8 + (const char __user *)src),
19750 ret, "q", "", "=r", 8);
19751 return ret;
19752 default:
19753 - return copy_user_generic(dst, (__force void *)src, size);
19754 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19755 }
19756 }
19757
19758 static __always_inline __must_check
19759 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19760 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19761 {
19762 might_fault();
19763 return __copy_from_user_nocheck(dst, src, size);
19764 }
19765
19766 static __always_inline __must_check
19767 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19768 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19769 {
19770 - int ret = 0;
19771 + size_t sz = __compiletime_object_size(src);
19772 + unsigned ret = 0;
19773 +
19774 + if (size > INT_MAX)
19775 + return size;
19776 +
19777 + check_object_size(src, size, true);
19778 +
19779 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19780 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19781 + return size;
19782 +#endif
19783 +
19784 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19785 + if(__builtin_constant_p(size))
19786 + copy_to_user_overflow();
19787 + else
19788 + __copy_to_user_overflow(sz, size);
19789 + return size;
19790 + }
19791
19792 if (!__builtin_constant_p(size))
19793 - return copy_user_generic((__force void *)dst, src, size);
19794 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19795 switch (size) {
19796 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19797 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19798 ret, "b", "b", "iq", 1);
19799 return ret;
19800 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19801 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19802 ret, "w", "w", "ir", 2);
19803 return ret;
19804 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19805 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19806 ret, "l", "k", "ir", 4);
19807 return ret;
19808 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19809 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19810 ret, "q", "", "er", 8);
19811 return ret;
19812 case 10:
19813 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19814 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19815 ret, "q", "", "er", 10);
19816 if (unlikely(ret))
19817 return ret;
19818 asm("":::"memory");
19819 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19820 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19821 ret, "w", "w", "ir", 2);
19822 return ret;
19823 case 16:
19824 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19825 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19826 ret, "q", "", "er", 16);
19827 if (unlikely(ret))
19828 return ret;
19829 asm("":::"memory");
19830 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19831 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19832 ret, "q", "", "er", 8);
19833 return ret;
19834 default:
19835 - return copy_user_generic((__force void *)dst, src, size);
19836 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19837 }
19838 }
19839
19840 static __always_inline __must_check
19841 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
19842 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19843 {
19844 might_fault();
19845 return __copy_to_user_nocheck(dst, src, size);
19846 }
19847
19848 static __always_inline __must_check
19849 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19850 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19851 {
19852 - int ret = 0;
19853 + unsigned ret = 0;
19854
19855 might_fault();
19856 +
19857 + if (size > INT_MAX)
19858 + return size;
19859 +
19860 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19861 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19862 + return size;
19863 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19864 + return size;
19865 +#endif
19866 +
19867 if (!__builtin_constant_p(size))
19868 - return copy_user_generic((__force void *)dst,
19869 - (__force void *)src, size);
19870 + return copy_user_generic((__force_kernel void *)____m(dst),
19871 + (__force_kernel const void *)____m(src), size);
19872 switch (size) {
19873 case 1: {
19874 u8 tmp;
19875 - __get_user_asm(tmp, (u8 __user *)src,
19876 + __get_user_asm(tmp, (const u8 __user *)src,
19877 ret, "b", "b", "=q", 1);
19878 if (likely(!ret))
19879 __put_user_asm(tmp, (u8 __user *)dst,
19880 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19881 }
19882 case 2: {
19883 u16 tmp;
19884 - __get_user_asm(tmp, (u16 __user *)src,
19885 + __get_user_asm(tmp, (const u16 __user *)src,
19886 ret, "w", "w", "=r", 2);
19887 if (likely(!ret))
19888 __put_user_asm(tmp, (u16 __user *)dst,
19889 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19890
19891 case 4: {
19892 u32 tmp;
19893 - __get_user_asm(tmp, (u32 __user *)src,
19894 + __get_user_asm(tmp, (const u32 __user *)src,
19895 ret, "l", "k", "=r", 4);
19896 if (likely(!ret))
19897 __put_user_asm(tmp, (u32 __user *)dst,
19898 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19899 }
19900 case 8: {
19901 u64 tmp;
19902 - __get_user_asm(tmp, (u64 __user *)src,
19903 + __get_user_asm(tmp, (const u64 __user *)src,
19904 ret, "q", "", "=r", 8);
19905 if (likely(!ret))
19906 __put_user_asm(tmp, (u64 __user *)dst,
19907 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19908 return ret;
19909 }
19910 default:
19911 - return copy_user_generic((__force void *)dst,
19912 - (__force void *)src, size);
19913 + return copy_user_generic((__force_kernel void *)____m(dst),
19914 + (__force_kernel const void *)____m(src), size);
19915 }
19916 }
19917
19918 -static __must_check __always_inline int
19919 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19920 +static __must_check __always_inline unsigned long
19921 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19922 {
19923 return __copy_from_user_nocheck(dst, src, size);
19924 }
19925
19926 -static __must_check __always_inline int
19927 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19928 +static __must_check __always_inline unsigned long
19929 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19930 {
19931 return __copy_to_user_nocheck(dst, src, size);
19932 }
19933
19934 -extern long __copy_user_nocache(void *dst, const void __user *src,
19935 - unsigned size, int zerorest);
19936 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19937 + unsigned long size, int zerorest);
19938
19939 -static inline int
19940 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19941 +static inline unsigned long
19942 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19943 {
19944 might_fault();
19945 +
19946 + if (size > INT_MAX)
19947 + return size;
19948 +
19949 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19950 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19951 + return size;
19952 +#endif
19953 +
19954 return __copy_user_nocache(dst, src, size, 1);
19955 }
19956
19957 -static inline int
19958 +static inline unsigned long
19959 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
19960 - unsigned size)
19961 + unsigned long size)
19962 {
19963 + if (size > INT_MAX)
19964 + return size;
19965 +
19966 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19967 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19968 + return size;
19969 +#endif
19970 +
19971 return __copy_user_nocache(dst, src, size, 0);
19972 }
19973
19974 unsigned long
19975 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
19976 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
19977
19978 #endif /* _ASM_X86_UACCESS_64_H */
19979 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
19980 index 5b238981..77fdd78 100644
19981 --- a/arch/x86/include/asm/word-at-a-time.h
19982 +++ b/arch/x86/include/asm/word-at-a-time.h
19983 @@ -11,7 +11,7 @@
19984 * and shift, for example.
19985 */
19986 struct word_at_a_time {
19987 - const unsigned long one_bits, high_bits;
19988 + unsigned long one_bits, high_bits;
19989 };
19990
19991 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
19992 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
19993 index e45e4da..44e8572 100644
19994 --- a/arch/x86/include/asm/x86_init.h
19995 +++ b/arch/x86/include/asm/x86_init.h
19996 @@ -129,7 +129,7 @@ struct x86_init_ops {
19997 struct x86_init_timers timers;
19998 struct x86_init_iommu iommu;
19999 struct x86_init_pci pci;
20000 -};
20001 +} __no_const;
20002
20003 /**
20004 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20005 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20006 void (*setup_percpu_clockev)(void);
20007 void (*early_percpu_clock_init)(void);
20008 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20009 -};
20010 +} __no_const;
20011
20012 struct timespec;
20013
20014 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20015 void (*save_sched_clock_state)(void);
20016 void (*restore_sched_clock_state)(void);
20017 void (*apic_post_init)(void);
20018 -};
20019 +} __no_const;
20020
20021 struct pci_dev;
20022 struct msi_msg;
20023 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20024 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20025 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20026 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20027 -};
20028 +} __no_const;
20029
20030 struct IO_APIC_route_entry;
20031 struct io_apic_irq_attr;
20032 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20033 unsigned int destination, int vector,
20034 struct io_apic_irq_attr *attr);
20035 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20036 -};
20037 +} __no_const;
20038
20039 extern struct x86_init_ops x86_init;
20040 extern struct x86_cpuinit_ops x86_cpuinit;
20041 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20042 index 3e276eb..2eb3c30 100644
20043 --- a/arch/x86/include/asm/xen/page.h
20044 +++ b/arch/x86/include/asm/xen/page.h
20045 @@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20046 extern struct page *m2p_find_override(unsigned long mfn);
20047 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20048
20049 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20050 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20051 {
20052 unsigned long mfn;
20053
20054 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20055 index 5547389..da68716 100644
20056 --- a/arch/x86/include/asm/xsave.h
20057 +++ b/arch/x86/include/asm/xsave.h
20058 @@ -76,8 +76,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20059 if (unlikely(err))
20060 return -EFAULT;
20061
20062 + pax_open_userland();
20063 __asm__ __volatile__(ASM_STAC "\n"
20064 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20065 + "1:"
20066 + __copyuser_seg
20067 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20068 "2: " ASM_CLAC "\n"
20069 ".section .fixup,\"ax\"\n"
20070 "3: movl $-1,%[err]\n"
20071 @@ -87,18 +90,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20072 : [err] "=r" (err)
20073 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20074 : "memory");
20075 + pax_close_userland();
20076 return err;
20077 }
20078
20079 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20080 {
20081 int err;
20082 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20083 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20084 u32 lmask = mask;
20085 u32 hmask = mask >> 32;
20086
20087 + pax_open_userland();
20088 __asm__ __volatile__(ASM_STAC "\n"
20089 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20090 + "1:"
20091 + __copyuser_seg
20092 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20093 "2: " ASM_CLAC "\n"
20094 ".section .fixup,\"ax\"\n"
20095 "3: movl $-1,%[err]\n"
20096 @@ -108,6 +115,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20097 : [err] "=r" (err)
20098 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20099 : "memory"); /* memory required? */
20100 + pax_close_userland();
20101 return err;
20102 }
20103
20104 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20105 index bbae024..e1528f9 100644
20106 --- a/arch/x86/include/uapi/asm/e820.h
20107 +++ b/arch/x86/include/uapi/asm/e820.h
20108 @@ -63,7 +63,7 @@ struct e820map {
20109 #define ISA_START_ADDRESS 0xa0000
20110 #define ISA_END_ADDRESS 0x100000
20111
20112 -#define BIOS_BEGIN 0x000a0000
20113 +#define BIOS_BEGIN 0x000c0000
20114 #define BIOS_END 0x00100000
20115
20116 #define BIOS_ROM_BASE 0xffe00000
20117 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20118 index 7b0a55a..ad115bf 100644
20119 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20120 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20121 @@ -49,7 +49,6 @@
20122 #define EFLAGS 144
20123 #define RSP 152
20124 #define SS 160
20125 -#define ARGOFFSET R11
20126 #endif /* __ASSEMBLY__ */
20127
20128 /* top of stack page */
20129 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20130 index cb648c8..91cb07e 100644
20131 --- a/arch/x86/kernel/Makefile
20132 +++ b/arch/x86/kernel/Makefile
20133 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20134 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20135 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20136 obj-y += probe_roms.o
20137 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20138 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20139 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20140 obj-y += syscall_$(BITS).o
20141 obj-$(CONFIG_X86_64) += vsyscall_64.o
20142 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20143 index 1dac942..19c8b0c 100644
20144 --- a/arch/x86/kernel/acpi/boot.c
20145 +++ b/arch/x86/kernel/acpi/boot.c
20146 @@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20147 * If your system is blacklisted here, but you find that acpi=force
20148 * works for you, please contact linux-acpi@vger.kernel.org
20149 */
20150 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20151 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20152 /*
20153 * Boxes that need ACPI disabled
20154 */
20155 @@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20156 };
20157
20158 /* second table for DMI checks that should run after early-quirks */
20159 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20160 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20161 /*
20162 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20163 * which includes some code which overrides all temperature
20164 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20165 index 3a2ae4c..9db31d6 100644
20166 --- a/arch/x86/kernel/acpi/sleep.c
20167 +++ b/arch/x86/kernel/acpi/sleep.c
20168 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20169 #else /* CONFIG_64BIT */
20170 #ifdef CONFIG_SMP
20171 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20172 +
20173 + pax_open_kernel();
20174 early_gdt_descr.address =
20175 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20176 + pax_close_kernel();
20177 +
20178 initial_gs = per_cpu_offset(smp_processor_id());
20179 #endif
20180 initial_code = (unsigned long)wakeup_long64;
20181 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20182 index 665c6b7..eae4d56 100644
20183 --- a/arch/x86/kernel/acpi/wakeup_32.S
20184 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20185 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20186 # and restore the stack ... but you need gdt for this to work
20187 movl saved_context_esp, %esp
20188
20189 - movl %cs:saved_magic, %eax
20190 - cmpl $0x12345678, %eax
20191 + cmpl $0x12345678, saved_magic
20192 jne bogus_magic
20193
20194 # jump to place where we left off
20195 - movl saved_eip, %eax
20196 - jmp *%eax
20197 + jmp *(saved_eip)
20198
20199 bogus_magic:
20200 jmp bogus_magic
20201 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20202 index df94598..f3b29bf 100644
20203 --- a/arch/x86/kernel/alternative.c
20204 +++ b/arch/x86/kernel/alternative.c
20205 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20206 */
20207 for (a = start; a < end; a++) {
20208 instr = (u8 *)&a->instr_offset + a->instr_offset;
20209 +
20210 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20211 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20212 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20213 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20214 +#endif
20215 +
20216 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20217 BUG_ON(a->replacementlen > a->instrlen);
20218 BUG_ON(a->instrlen > sizeof(insnbuf));
20219 @@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20220 for (poff = start; poff < end; poff++) {
20221 u8 *ptr = (u8 *)poff + *poff;
20222
20223 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20224 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20225 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20226 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20227 +#endif
20228 +
20229 if (!*poff || ptr < text || ptr >= text_end)
20230 continue;
20231 /* turn DS segment override prefix into lock prefix */
20232 - if (*ptr == 0x3e)
20233 + if (*ktla_ktva(ptr) == 0x3e)
20234 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20235 }
20236 mutex_unlock(&text_mutex);
20237 @@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20238 for (poff = start; poff < end; poff++) {
20239 u8 *ptr = (u8 *)poff + *poff;
20240
20241 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20242 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20243 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20244 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20245 +#endif
20246 +
20247 if (!*poff || ptr < text || ptr >= text_end)
20248 continue;
20249 /* turn lock prefix into DS segment override prefix */
20250 - if (*ptr == 0xf0)
20251 + if (*ktla_ktva(ptr) == 0xf0)
20252 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20253 }
20254 mutex_unlock(&text_mutex);
20255 @@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20256
20257 BUG_ON(p->len > MAX_PATCH_LEN);
20258 /* prep the buffer with the original instructions */
20259 - memcpy(insnbuf, p->instr, p->len);
20260 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20261 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20262 (unsigned long)p->instr, p->len);
20263
20264 @@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20265 if (!uniproc_patched || num_possible_cpus() == 1)
20266 free_init_pages("SMP alternatives",
20267 (unsigned long)__smp_locks,
20268 - (unsigned long)__smp_locks_end);
20269 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20270 #endif
20271
20272 apply_paravirt(__parainstructions, __parainstructions_end);
20273 @@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20274 * instructions. And on the local CPU you need to be protected again NMI or MCE
20275 * handlers seeing an inconsistent instruction while you patch.
20276 */
20277 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20278 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20279 size_t len)
20280 {
20281 unsigned long flags;
20282 local_irq_save(flags);
20283 - memcpy(addr, opcode, len);
20284 +
20285 + pax_open_kernel();
20286 + memcpy(ktla_ktva(addr), opcode, len);
20287 sync_core();
20288 + pax_close_kernel();
20289 +
20290 local_irq_restore(flags);
20291 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20292 that causes hangs on some VIA CPUs. */
20293 @@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20294 */
20295 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20296 {
20297 - unsigned long flags;
20298 - char *vaddr;
20299 + unsigned char *vaddr = ktla_ktva(addr);
20300 struct page *pages[2];
20301 - int i;
20302 + size_t i;
20303
20304 if (!core_kernel_text((unsigned long)addr)) {
20305 - pages[0] = vmalloc_to_page(addr);
20306 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20307 + pages[0] = vmalloc_to_page(vaddr);
20308 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20309 } else {
20310 - pages[0] = virt_to_page(addr);
20311 + pages[0] = virt_to_page(vaddr);
20312 WARN_ON(!PageReserved(pages[0]));
20313 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20314 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20315 }
20316 BUG_ON(!pages[0]);
20317 - local_irq_save(flags);
20318 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20319 - if (pages[1])
20320 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20321 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20322 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20323 - clear_fixmap(FIX_TEXT_POKE0);
20324 - if (pages[1])
20325 - clear_fixmap(FIX_TEXT_POKE1);
20326 - local_flush_tlb();
20327 - sync_core();
20328 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20329 - that causes hangs on some VIA CPUs. */
20330 + text_poke_early(addr, opcode, len);
20331 for (i = 0; i < len; i++)
20332 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20333 - local_irq_restore(flags);
20334 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20335 return addr;
20336 }
20337
20338 @@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20339 if (likely(!bp_patching_in_progress))
20340 return 0;
20341
20342 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20343 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20344 return 0;
20345
20346 /* set up the specified breakpoint handler */
20347 @@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20348 */
20349 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20350 {
20351 - unsigned char int3 = 0xcc;
20352 + const unsigned char int3 = 0xcc;
20353
20354 bp_int3_handler = handler;
20355 bp_int3_addr = (u8 *)addr + sizeof(int3);
20356 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20357 index 7f26c9a..694544e 100644
20358 --- a/arch/x86/kernel/apic/apic.c
20359 +++ b/arch/x86/kernel/apic/apic.c
20360 @@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20361 /*
20362 * Debug level, exported for io_apic.c
20363 */
20364 -unsigned int apic_verbosity;
20365 +int apic_verbosity;
20366
20367 int pic_mode;
20368
20369 @@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20370 apic_write(APIC_ESR, 0);
20371 v = apic_read(APIC_ESR);
20372 ack_APIC_irq();
20373 - atomic_inc(&irq_err_count);
20374 + atomic_inc_unchecked(&irq_err_count);
20375
20376 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20377 smp_processor_id(), v);
20378 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20379 index 2c621a6..fa2b1ae 100644
20380 --- a/arch/x86/kernel/apic/apic_flat_64.c
20381 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20382 @@ -154,7 +154,7 @@ static int flat_probe(void)
20383 return 1;
20384 }
20385
20386 -static struct apic apic_flat = {
20387 +static struct apic apic_flat __read_only = {
20388 .name = "flat",
20389 .probe = flat_probe,
20390 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20391 @@ -268,7 +268,7 @@ static int physflat_probe(void)
20392 return 0;
20393 }
20394
20395 -static struct apic apic_physflat = {
20396 +static struct apic apic_physflat __read_only = {
20397
20398 .name = "physical flat",
20399 .probe = physflat_probe,
20400 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20401 index 191ce75..2db6d63 100644
20402 --- a/arch/x86/kernel/apic/apic_noop.c
20403 +++ b/arch/x86/kernel/apic/apic_noop.c
20404 @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20405 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20406 }
20407
20408 -struct apic apic_noop = {
20409 +struct apic apic_noop __read_only = {
20410 .name = "noop",
20411 .probe = noop_probe,
20412 .acpi_madt_oem_check = NULL,
20413 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20414 index d50e364..543bee3 100644
20415 --- a/arch/x86/kernel/apic/bigsmp_32.c
20416 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20417 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20418 return dmi_bigsmp;
20419 }
20420
20421 -static struct apic apic_bigsmp = {
20422 +static struct apic apic_bigsmp __read_only = {
20423
20424 .name = "bigsmp",
20425 .probe = probe_bigsmp,
20426 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20427 index c552247..587a316 100644
20428 --- a/arch/x86/kernel/apic/es7000_32.c
20429 +++ b/arch/x86/kernel/apic/es7000_32.c
20430 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20431 return ret && es7000_apic_is_cluster();
20432 }
20433
20434 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20435 -static struct apic __refdata apic_es7000_cluster = {
20436 +static struct apic apic_es7000_cluster __read_only = {
20437
20438 .name = "es7000",
20439 .probe = probe_es7000,
20440 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20441 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20442 };
20443
20444 -static struct apic __refdata apic_es7000 = {
20445 +static struct apic apic_es7000 __read_only = {
20446
20447 .name = "es7000",
20448 .probe = probe_es7000,
20449 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20450 index 6ad4658..38a7b5c 100644
20451 --- a/arch/x86/kernel/apic/io_apic.c
20452 +++ b/arch/x86/kernel/apic/io_apic.c
20453 @@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20454 }
20455 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20456
20457 -void lock_vector_lock(void)
20458 +void lock_vector_lock(void) __acquires(vector_lock)
20459 {
20460 /* Used to the online set of cpus does not change
20461 * during assign_irq_vector.
20462 @@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20463 raw_spin_lock(&vector_lock);
20464 }
20465
20466 -void unlock_vector_lock(void)
20467 +void unlock_vector_lock(void) __releases(vector_lock)
20468 {
20469 raw_spin_unlock(&vector_lock);
20470 }
20471 @@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20472 ack_APIC_irq();
20473 }
20474
20475 -atomic_t irq_mis_count;
20476 +atomic_unchecked_t irq_mis_count;
20477
20478 #ifdef CONFIG_GENERIC_PENDING_IRQ
20479 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20480 @@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20481 * at the cpu.
20482 */
20483 if (!(v & (1 << (i & 0x1f)))) {
20484 - atomic_inc(&irq_mis_count);
20485 + atomic_inc_unchecked(&irq_mis_count);
20486
20487 eoi_ioapic_irq(irq, cfg);
20488 }
20489 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20490 index 1e42e8f..daacf44 100644
20491 --- a/arch/x86/kernel/apic/numaq_32.c
20492 +++ b/arch/x86/kernel/apic/numaq_32.c
20493 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20494 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20495 }
20496
20497 -/* Use __refdata to keep false positive warning calm. */
20498 -static struct apic __refdata apic_numaq = {
20499 +static struct apic apic_numaq __read_only = {
20500
20501 .name = "NUMAQ",
20502 .probe = probe_numaq,
20503 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20504 index eb35ef9..f184a21 100644
20505 --- a/arch/x86/kernel/apic/probe_32.c
20506 +++ b/arch/x86/kernel/apic/probe_32.c
20507 @@ -72,7 +72,7 @@ static int probe_default(void)
20508 return 1;
20509 }
20510
20511 -static struct apic apic_default = {
20512 +static struct apic apic_default __read_only = {
20513
20514 .name = "default",
20515 .probe = probe_default,
20516 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20517 index 00146f9..5e299b8 100644
20518 --- a/arch/x86/kernel/apic/summit_32.c
20519 +++ b/arch/x86/kernel/apic/summit_32.c
20520 @@ -485,7 +485,7 @@ void setup_summit(void)
20521 }
20522 #endif
20523
20524 -static struct apic apic_summit = {
20525 +static struct apic apic_summit __read_only = {
20526
20527 .name = "summit",
20528 .probe = probe_summit,
20529 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20530 index cac85ee..01fa741 100644
20531 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20532 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20533 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20534 return notifier_from_errno(err);
20535 }
20536
20537 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20538 +static struct notifier_block x2apic_cpu_notifier = {
20539 .notifier_call = update_clusterinfo,
20540 };
20541
20542 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20543 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20544 }
20545
20546 -static struct apic apic_x2apic_cluster = {
20547 +static struct apic apic_x2apic_cluster __read_only = {
20548
20549 .name = "cluster x2apic",
20550 .probe = x2apic_cluster_probe,
20551 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20552 index de231e3..1d1b2ee 100644
20553 --- a/arch/x86/kernel/apic/x2apic_phys.c
20554 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20555 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20556 return apic == &apic_x2apic_phys;
20557 }
20558
20559 -static struct apic apic_x2apic_phys = {
20560 +static struct apic apic_x2apic_phys __read_only = {
20561
20562 .name = "physical x2apic",
20563 .probe = x2apic_phys_probe,
20564 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20565 index d263b13..963258b 100644
20566 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20567 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20568 @@ -350,7 +350,7 @@ static int uv_probe(void)
20569 return apic == &apic_x2apic_uv_x;
20570 }
20571
20572 -static struct apic __refdata apic_x2apic_uv_x = {
20573 +static struct apic apic_x2apic_uv_x __read_only = {
20574
20575 .name = "UV large system",
20576 .probe = uv_probe,
20577 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20578 index 3ab0343..814c4787 100644
20579 --- a/arch/x86/kernel/apm_32.c
20580 +++ b/arch/x86/kernel/apm_32.c
20581 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20582 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20583 * even though they are called in protected mode.
20584 */
20585 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20586 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20587 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20588
20589 static const char driver_version[] = "1.16ac"; /* no spaces */
20590 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20591 BUG_ON(cpu != 0);
20592 gdt = get_cpu_gdt_table(cpu);
20593 save_desc_40 = gdt[0x40 / 8];
20594 +
20595 + pax_open_kernel();
20596 gdt[0x40 / 8] = bad_bios_desc;
20597 + pax_close_kernel();
20598
20599 apm_irq_save(flags);
20600 APM_DO_SAVE_SEGS;
20601 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20602 &call->esi);
20603 APM_DO_RESTORE_SEGS;
20604 apm_irq_restore(flags);
20605 +
20606 + pax_open_kernel();
20607 gdt[0x40 / 8] = save_desc_40;
20608 + pax_close_kernel();
20609 +
20610 put_cpu();
20611
20612 return call->eax & 0xff;
20613 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20614 BUG_ON(cpu != 0);
20615 gdt = get_cpu_gdt_table(cpu);
20616 save_desc_40 = gdt[0x40 / 8];
20617 +
20618 + pax_open_kernel();
20619 gdt[0x40 / 8] = bad_bios_desc;
20620 + pax_close_kernel();
20621
20622 apm_irq_save(flags);
20623 APM_DO_SAVE_SEGS;
20624 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20625 &call->eax);
20626 APM_DO_RESTORE_SEGS;
20627 apm_irq_restore(flags);
20628 +
20629 + pax_open_kernel();
20630 gdt[0x40 / 8] = save_desc_40;
20631 + pax_close_kernel();
20632 +
20633 put_cpu();
20634 return error;
20635 }
20636 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20637 * code to that CPU.
20638 */
20639 gdt = get_cpu_gdt_table(0);
20640 +
20641 + pax_open_kernel();
20642 set_desc_base(&gdt[APM_CS >> 3],
20643 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20644 set_desc_base(&gdt[APM_CS_16 >> 3],
20645 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20646 set_desc_base(&gdt[APM_DS >> 3],
20647 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20648 + pax_close_kernel();
20649
20650 proc_create("apm", 0, NULL, &apm_file_ops);
20651
20652 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20653 index 9f6b934..cf5ffb3 100644
20654 --- a/arch/x86/kernel/asm-offsets.c
20655 +++ b/arch/x86/kernel/asm-offsets.c
20656 @@ -32,6 +32,8 @@ void common(void) {
20657 OFFSET(TI_flags, thread_info, flags);
20658 OFFSET(TI_status, thread_info, status);
20659 OFFSET(TI_addr_limit, thread_info, addr_limit);
20660 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20661 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20662
20663 BLANK();
20664 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20665 @@ -52,8 +54,26 @@ void common(void) {
20666 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20667 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20668 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20669 +
20670 +#ifdef CONFIG_PAX_KERNEXEC
20671 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20672 #endif
20673
20674 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20675 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20676 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20677 +#ifdef CONFIG_X86_64
20678 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20679 +#endif
20680 +#endif
20681 +
20682 +#endif
20683 +
20684 + BLANK();
20685 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20686 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20687 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20688 +
20689 #ifdef CONFIG_XEN
20690 BLANK();
20691 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20692 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20693 index e7c798b..2b2019b 100644
20694 --- a/arch/x86/kernel/asm-offsets_64.c
20695 +++ b/arch/x86/kernel/asm-offsets_64.c
20696 @@ -77,6 +77,7 @@ int main(void)
20697 BLANK();
20698 #undef ENTRY
20699
20700 + DEFINE(TSS_size, sizeof(struct tss_struct));
20701 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20702 BLANK();
20703
20704 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20705 index 7fd54f0..0691410 100644
20706 --- a/arch/x86/kernel/cpu/Makefile
20707 +++ b/arch/x86/kernel/cpu/Makefile
20708 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20709 CFLAGS_REMOVE_perf_event.o = -pg
20710 endif
20711
20712 -# Make sure load_percpu_segment has no stackprotector
20713 -nostackp := $(call cc-option, -fno-stack-protector)
20714 -CFLAGS_common.o := $(nostackp)
20715 -
20716 obj-y := intel_cacheinfo.o scattered.o topology.o
20717 obj-y += proc.o capflags.o powerflags.o common.o
20718 obj-y += rdrand.o
20719 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20720 index c67ffa6..f41fbbf 100644
20721 --- a/arch/x86/kernel/cpu/amd.c
20722 +++ b/arch/x86/kernel/cpu/amd.c
20723 @@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20724 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20725 {
20726 /* AMD errata T13 (order #21922) */
20727 - if ((c->x86 == 6)) {
20728 + if (c->x86 == 6) {
20729 /* Duron Rev A0 */
20730 if (c->x86_model == 3 && c->x86_mask == 0)
20731 size = 64;
20732 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20733 index 8e28bf2..bf5c0d2 100644
20734 --- a/arch/x86/kernel/cpu/common.c
20735 +++ b/arch/x86/kernel/cpu/common.c
20736 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20737
20738 static const struct cpu_dev *this_cpu = &default_cpu;
20739
20740 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20741 -#ifdef CONFIG_X86_64
20742 - /*
20743 - * We need valid kernel segments for data and code in long mode too
20744 - * IRET will check the segment types kkeil 2000/10/28
20745 - * Also sysret mandates a special GDT layout
20746 - *
20747 - * TLS descriptors are currently at a different place compared to i386.
20748 - * Hopefully nobody expects them at a fixed place (Wine?)
20749 - */
20750 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20751 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20752 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20753 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20754 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20755 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20756 -#else
20757 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20758 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20759 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20760 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20761 - /*
20762 - * Segments used for calling PnP BIOS have byte granularity.
20763 - * They code segments and data segments have fixed 64k limits,
20764 - * the transfer segment sizes are set at run time.
20765 - */
20766 - /* 32-bit code */
20767 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20768 - /* 16-bit code */
20769 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20770 - /* 16-bit data */
20771 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20772 - /* 16-bit data */
20773 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20774 - /* 16-bit data */
20775 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20776 - /*
20777 - * The APM segments have byte granularity and their bases
20778 - * are set at run time. All have 64k limits.
20779 - */
20780 - /* 32-bit code */
20781 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20782 - /* 16-bit code */
20783 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20784 - /* data */
20785 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20786 -
20787 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20788 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20789 - GDT_STACK_CANARY_INIT
20790 -#endif
20791 -} };
20792 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20793 -
20794 static int __init x86_xsave_setup(char *s)
20795 {
20796 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20797 @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20798 }
20799 }
20800
20801 +#ifdef CONFIG_X86_64
20802 +static __init int setup_disable_pcid(char *arg)
20803 +{
20804 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20805 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20806 +
20807 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20808 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20809 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20810 +#endif
20811 +
20812 + return 1;
20813 +}
20814 +__setup("nopcid", setup_disable_pcid);
20815 +
20816 +static void setup_pcid(struct cpuinfo_x86 *c)
20817 +{
20818 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20819 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20820 +
20821 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20822 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20823 + pax_open_kernel();
20824 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20825 + pax_close_kernel();
20826 + printk("PAX: slow and weak UDEREF enabled\n");
20827 + } else
20828 + printk("PAX: UDEREF disabled\n");
20829 +#endif
20830 +
20831 + return;
20832 + }
20833 +
20834 + printk("PAX: PCID detected\n");
20835 + set_in_cr4(X86_CR4_PCIDE);
20836 +
20837 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20838 + pax_open_kernel();
20839 + clone_pgd_mask = ~(pgdval_t)0UL;
20840 + pax_close_kernel();
20841 + if (pax_user_shadow_base)
20842 + printk("PAX: weak UDEREF enabled\n");
20843 + else {
20844 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20845 + printk("PAX: strong UDEREF enabled\n");
20846 + }
20847 +#endif
20848 +
20849 + if (cpu_has(c, X86_FEATURE_INVPCID))
20850 + printk("PAX: INVPCID detected\n");
20851 +}
20852 +#endif
20853 +
20854 /*
20855 * Some CPU features depend on higher CPUID levels, which may not always
20856 * be available due to CPUID level capping or broken virtualization
20857 @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20858 {
20859 struct desc_ptr gdt_descr;
20860
20861 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20862 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20863 gdt_descr.size = GDT_SIZE - 1;
20864 load_gdt(&gdt_descr);
20865 /* Reload the per-cpu base */
20866 @@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20867 setup_smep(c);
20868 setup_smap(c);
20869
20870 +#ifdef CONFIG_X86_64
20871 + setup_pcid(c);
20872 +#endif
20873 +
20874 /*
20875 * The vendor-specific functions might have changed features.
20876 * Now we do "generic changes."
20877 @@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20878 /* Filter out anything that depends on CPUID levels we don't have */
20879 filter_cpuid_features(c, true);
20880
20881 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20882 + setup_clear_cpu_cap(X86_FEATURE_SEP);
20883 +#endif
20884 +
20885 /* If the model name is still unset, do table lookup. */
20886 if (!c->x86_model_id[0]) {
20887 const char *p;
20888 @@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
20889 }
20890 __setup("clearcpuid=", setup_disablecpuid);
20891
20892 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20893 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
20894 +
20895 #ifdef CONFIG_X86_64
20896 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20897 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20898 - (unsigned long) debug_idt_table };
20899 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20900 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20901
20902 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20903 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20904 @@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20905 EXPORT_PER_CPU_SYMBOL(current_task);
20906
20907 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20908 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20909 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20910 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20911
20912 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20913 @@ -1245,7 +1254,7 @@ void cpu_init(void)
20914 load_ucode_ap();
20915
20916 cpu = stack_smp_processor_id();
20917 - t = &per_cpu(init_tss, cpu);
20918 + t = init_tss + cpu;
20919 oist = &per_cpu(orig_ist, cpu);
20920
20921 #ifdef CONFIG_NUMA
20922 @@ -1280,7 +1289,6 @@ void cpu_init(void)
20923 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20924 barrier();
20925
20926 - x86_configure_nx();
20927 enable_x2apic();
20928
20929 /*
20930 @@ -1332,7 +1340,7 @@ void cpu_init(void)
20931 {
20932 int cpu = smp_processor_id();
20933 struct task_struct *curr = current;
20934 - struct tss_struct *t = &per_cpu(init_tss, cpu);
20935 + struct tss_struct *t = init_tss + cpu;
20936 struct thread_struct *thread = &curr->thread;
20937
20938 show_ucode_info_early();
20939 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20940 index 0641113..06f5ba4 100644
20941 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20942 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20943 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20944 };
20945
20946 #ifdef CONFIG_AMD_NB
20947 +static struct attribute *default_attrs_amd_nb[] = {
20948 + &type.attr,
20949 + &level.attr,
20950 + &coherency_line_size.attr,
20951 + &physical_line_partition.attr,
20952 + &ways_of_associativity.attr,
20953 + &number_of_sets.attr,
20954 + &size.attr,
20955 + &shared_cpu_map.attr,
20956 + &shared_cpu_list.attr,
20957 + NULL,
20958 + NULL,
20959 + NULL,
20960 + NULL
20961 +};
20962 +
20963 static struct attribute **amd_l3_attrs(void)
20964 {
20965 static struct attribute **attrs;
20966 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
20967
20968 n = ARRAY_SIZE(default_attrs);
20969
20970 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
20971 - n += 2;
20972 -
20973 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
20974 - n += 1;
20975 -
20976 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
20977 - if (attrs == NULL)
20978 - return attrs = default_attrs;
20979 -
20980 - for (n = 0; default_attrs[n]; n++)
20981 - attrs[n] = default_attrs[n];
20982 + attrs = default_attrs_amd_nb;
20983
20984 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
20985 attrs[n++] = &cache_disable_0.attr;
20986 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
20987 .default_attrs = default_attrs,
20988 };
20989
20990 +#ifdef CONFIG_AMD_NB
20991 +static struct kobj_type ktype_cache_amd_nb = {
20992 + .sysfs_ops = &sysfs_ops,
20993 + .default_attrs = default_attrs_amd_nb,
20994 +};
20995 +#endif
20996 +
20997 static struct kobj_type ktype_percpu_entry = {
20998 .sysfs_ops = &sysfs_ops,
20999 };
21000 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21001 return retval;
21002 }
21003
21004 +#ifdef CONFIG_AMD_NB
21005 + amd_l3_attrs();
21006 +#endif
21007 +
21008 for (i = 0; i < num_cache_leaves; i++) {
21009 + struct kobj_type *ktype;
21010 +
21011 this_object = INDEX_KOBJECT_PTR(cpu, i);
21012 this_object->cpu = cpu;
21013 this_object->index = i;
21014
21015 this_leaf = CPUID4_INFO_IDX(cpu, i);
21016
21017 - ktype_cache.default_attrs = default_attrs;
21018 + ktype = &ktype_cache;
21019 #ifdef CONFIG_AMD_NB
21020 if (this_leaf->base.nb)
21021 - ktype_cache.default_attrs = amd_l3_attrs();
21022 + ktype = &ktype_cache_amd_nb;
21023 #endif
21024 retval = kobject_init_and_add(&(this_object->kobj),
21025 - &ktype_cache,
21026 + ktype,
21027 per_cpu(ici_cache_kobject, cpu),
21028 "index%1lu", i);
21029 if (unlikely(retval)) {
21030 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21031 index 4d5419b..95f11bb 100644
21032 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21033 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21034 @@ -45,6 +45,7 @@
21035 #include <asm/processor.h>
21036 #include <asm/mce.h>
21037 #include <asm/msr.h>
21038 +#include <asm/local.h>
21039
21040 #include "mce-internal.h"
21041
21042 @@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21043 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21044 m->cs, m->ip);
21045
21046 - if (m->cs == __KERNEL_CS)
21047 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21048 print_symbol("{%s}", m->ip);
21049 pr_cont("\n");
21050 }
21051 @@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21052
21053 #define PANIC_TIMEOUT 5 /* 5 seconds */
21054
21055 -static atomic_t mce_paniced;
21056 +static atomic_unchecked_t mce_paniced;
21057
21058 static int fake_panic;
21059 -static atomic_t mce_fake_paniced;
21060 +static atomic_unchecked_t mce_fake_paniced;
21061
21062 /* Panic in progress. Enable interrupts and wait for final IPI */
21063 static void wait_for_panic(void)
21064 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21065 /*
21066 * Make sure only one CPU runs in machine check panic
21067 */
21068 - if (atomic_inc_return(&mce_paniced) > 1)
21069 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21070 wait_for_panic();
21071 barrier();
21072
21073 @@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21074 console_verbose();
21075 } else {
21076 /* Don't log too much for fake panic */
21077 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21078 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21079 return;
21080 }
21081 /* First print corrected ones that are still unlogged */
21082 @@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21083 if (!fake_panic) {
21084 if (panic_timeout == 0)
21085 panic_timeout = mca_cfg.panic_timeout;
21086 - panic(msg);
21087 + panic("%s", msg);
21088 } else
21089 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21090 }
21091 @@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21092 * might have been modified by someone else.
21093 */
21094 rmb();
21095 - if (atomic_read(&mce_paniced))
21096 + if (atomic_read_unchecked(&mce_paniced))
21097 wait_for_panic();
21098 if (!mca_cfg.monarch_timeout)
21099 goto out;
21100 @@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21101 }
21102
21103 /* Call the installed machine check handler for this CPU setup. */
21104 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21105 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21106 unexpected_machine_check;
21107
21108 /*
21109 @@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21110 return;
21111 }
21112
21113 + pax_open_kernel();
21114 machine_check_vector = do_machine_check;
21115 + pax_close_kernel();
21116
21117 __mcheck_cpu_init_generic();
21118 __mcheck_cpu_init_vendor(c);
21119 @@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21120 */
21121
21122 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21123 -static int mce_chrdev_open_count; /* #times opened */
21124 +static local_t mce_chrdev_open_count; /* #times opened */
21125 static int mce_chrdev_open_exclu; /* already open exclusive? */
21126
21127 static int mce_chrdev_open(struct inode *inode, struct file *file)
21128 @@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21129 spin_lock(&mce_chrdev_state_lock);
21130
21131 if (mce_chrdev_open_exclu ||
21132 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21133 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21134 spin_unlock(&mce_chrdev_state_lock);
21135
21136 return -EBUSY;
21137 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21138
21139 if (file->f_flags & O_EXCL)
21140 mce_chrdev_open_exclu = 1;
21141 - mce_chrdev_open_count++;
21142 + local_inc(&mce_chrdev_open_count);
21143
21144 spin_unlock(&mce_chrdev_state_lock);
21145
21146 @@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21147 {
21148 spin_lock(&mce_chrdev_state_lock);
21149
21150 - mce_chrdev_open_count--;
21151 + local_dec(&mce_chrdev_open_count);
21152 mce_chrdev_open_exclu = 0;
21153
21154 spin_unlock(&mce_chrdev_state_lock);
21155 @@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21156
21157 for (i = 0; i < mca_cfg.banks; i++) {
21158 struct mce_bank *b = &mce_banks[i];
21159 - struct device_attribute *a = &b->attr;
21160 + device_attribute_no_const *a = &b->attr;
21161
21162 sysfs_attr_init(&a->attr);
21163 a->attr.name = b->attrname;
21164 @@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21165 static void mce_reset(void)
21166 {
21167 cpu_missing = 0;
21168 - atomic_set(&mce_fake_paniced, 0);
21169 + atomic_set_unchecked(&mce_fake_paniced, 0);
21170 atomic_set(&mce_executing, 0);
21171 atomic_set(&mce_callin, 0);
21172 atomic_set(&global_nwo, 0);
21173 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21174 index a304298..49b6d06 100644
21175 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21176 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21177 @@ -10,6 +10,7 @@
21178 #include <asm/processor.h>
21179 #include <asm/mce.h>
21180 #include <asm/msr.h>
21181 +#include <asm/pgtable.h>
21182
21183 /* By default disabled */
21184 int mce_p5_enabled __read_mostly;
21185 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21186 if (!cpu_has(c, X86_FEATURE_MCE))
21187 return;
21188
21189 + pax_open_kernel();
21190 machine_check_vector = pentium_machine_check;
21191 + pax_close_kernel();
21192 /* Make sure the vector pointer is visible before we enable MCEs: */
21193 wmb();
21194
21195 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21196 index 7dc5564..1273569 100644
21197 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21198 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21199 @@ -9,6 +9,7 @@
21200 #include <asm/processor.h>
21201 #include <asm/mce.h>
21202 #include <asm/msr.h>
21203 +#include <asm/pgtable.h>
21204
21205 /* Machine check handler for WinChip C6: */
21206 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21207 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21208 {
21209 u32 lo, hi;
21210
21211 + pax_open_kernel();
21212 machine_check_vector = winchip_machine_check;
21213 + pax_close_kernel();
21214 /* Make sure the vector pointer is visible before we enable MCEs: */
21215 wmb();
21216
21217 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21218 index 15c9876..0a43909 100644
21219 --- a/arch/x86/kernel/cpu/microcode/core.c
21220 +++ b/arch/x86/kernel/cpu/microcode/core.c
21221 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21222 return NOTIFY_OK;
21223 }
21224
21225 -static struct notifier_block __refdata mc_cpu_notifier = {
21226 +static struct notifier_block mc_cpu_notifier = {
21227 .notifier_call = mc_cpu_callback,
21228 };
21229
21230 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21231 index a276fa7..e66810f 100644
21232 --- a/arch/x86/kernel/cpu/microcode/intel.c
21233 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21234 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21235
21236 static int get_ucode_user(void *to, const void *from, size_t n)
21237 {
21238 - return copy_from_user(to, from, n);
21239 + return copy_from_user(to, (const void __force_user *)from, n);
21240 }
21241
21242 static enum ucode_state
21243 request_microcode_user(int cpu, const void __user *buf, size_t size)
21244 {
21245 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21246 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21247 }
21248
21249 static void microcode_fini_cpu(int cpu)
21250 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21251 index f961de9..8a9d332 100644
21252 --- a/arch/x86/kernel/cpu/mtrr/main.c
21253 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21254 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21255 u64 size_or_mask, size_and_mask;
21256 static bool mtrr_aps_delayed_init;
21257
21258 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21259 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21260
21261 const struct mtrr_ops *mtrr_if;
21262
21263 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21264 index df5e41f..816c719 100644
21265 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21266 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21267 @@ -25,7 +25,7 @@ struct mtrr_ops {
21268 int (*validate_add_page)(unsigned long base, unsigned long size,
21269 unsigned int type);
21270 int (*have_wrcomb)(void);
21271 -};
21272 +} __do_const;
21273
21274 extern int generic_get_free_region(unsigned long base, unsigned long size,
21275 int replace_reg);
21276 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21277 index 79f9f84..38ace52 100644
21278 --- a/arch/x86/kernel/cpu/perf_event.c
21279 +++ b/arch/x86/kernel/cpu/perf_event.c
21280 @@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21281 pr_info("no hardware sampling interrupt available.\n");
21282 }
21283
21284 -static struct attribute_group x86_pmu_format_group = {
21285 +static attribute_group_no_const x86_pmu_format_group = {
21286 .name = "format",
21287 .attrs = NULL,
21288 };
21289 @@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21290 NULL,
21291 };
21292
21293 -static struct attribute_group x86_pmu_events_group = {
21294 +static attribute_group_no_const x86_pmu_events_group = {
21295 .name = "events",
21296 .attrs = events_attr,
21297 };
21298 @@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21299 if (idx > GDT_ENTRIES)
21300 return 0;
21301
21302 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21303 + desc = get_cpu_gdt_table(smp_processor_id());
21304 }
21305
21306 return get_desc_base(desc + idx);
21307 @@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21308 break;
21309
21310 perf_callchain_store(entry, frame.return_address);
21311 - fp = frame.next_frame;
21312 + fp = (const void __force_user *)frame.next_frame;
21313 }
21314 }
21315
21316 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21317 index 639d128..e92d7e5 100644
21318 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21319 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21320 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21321 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21322 {
21323 struct attribute **attrs;
21324 - struct attribute_group *attr_group;
21325 + attribute_group_no_const *attr_group;
21326 int i = 0, j;
21327
21328 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21329 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21330 index aa333d9..f9db700 100644
21331 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21332 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21333 @@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21334 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21335
21336 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21337 - u64 capabilities;
21338 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21339
21340 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21341 - x86_pmu.intel_cap.capabilities = capabilities;
21342 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21343 + x86_pmu.intel_cap.capabilities = capabilities;
21344 }
21345
21346 intel_ds_init();
21347 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21348 index 5ad35ad..e0a3960 100644
21349 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21350 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21351 @@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21352 NULL,
21353 };
21354
21355 -static struct attribute_group rapl_pmu_events_group = {
21356 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21357 .name = "events",
21358 .attrs = NULL, /* patched at runtime */
21359 };
21360 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21361 index 047f540..afdeba0 100644
21362 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21363 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21364 @@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21365 static int __init uncore_type_init(struct intel_uncore_type *type)
21366 {
21367 struct intel_uncore_pmu *pmus;
21368 - struct attribute_group *attr_group;
21369 + attribute_group_no_const *attr_group;
21370 struct attribute **attrs;
21371 int i, j;
21372
21373 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21374 index a80ab71..4089da5 100644
21375 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21376 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21377 @@ -498,7 +498,7 @@ struct intel_uncore_box {
21378 struct uncore_event_desc {
21379 struct kobj_attribute attr;
21380 const char *config;
21381 -};
21382 +} __do_const;
21383
21384 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21385 { \
21386 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21387 index 7d9481c..99c7e4b 100644
21388 --- a/arch/x86/kernel/cpuid.c
21389 +++ b/arch/x86/kernel/cpuid.c
21390 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21391 return notifier_from_errno(err);
21392 }
21393
21394 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21395 +static struct notifier_block cpuid_class_cpu_notifier =
21396 {
21397 .notifier_call = cpuid_class_cpu_callback,
21398 };
21399 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21400 index a57902e..ebaae2a 100644
21401 --- a/arch/x86/kernel/crash.c
21402 +++ b/arch/x86/kernel/crash.c
21403 @@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21404 {
21405 #ifdef CONFIG_X86_32
21406 struct pt_regs fixed_regs;
21407 -#endif
21408
21409 -#ifdef CONFIG_X86_32
21410 - if (!user_mode_vm(regs)) {
21411 + if (!user_mode(regs)) {
21412 crash_fixup_ss_esp(&fixed_regs, regs);
21413 regs = &fixed_regs;
21414 }
21415 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21416 index afa64ad..dce67dd 100644
21417 --- a/arch/x86/kernel/crash_dump_64.c
21418 +++ b/arch/x86/kernel/crash_dump_64.c
21419 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21420 return -ENOMEM;
21421
21422 if (userbuf) {
21423 - if (copy_to_user(buf, vaddr + offset, csize)) {
21424 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21425 iounmap(vaddr);
21426 return -EFAULT;
21427 }
21428 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21429 index f6dfd93..892ade4 100644
21430 --- a/arch/x86/kernel/doublefault.c
21431 +++ b/arch/x86/kernel/doublefault.c
21432 @@ -12,7 +12,7 @@
21433
21434 #define DOUBLEFAULT_STACKSIZE (1024)
21435 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21436 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21437 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21438
21439 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21440
21441 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21442 unsigned long gdt, tss;
21443
21444 native_store_gdt(&gdt_desc);
21445 - gdt = gdt_desc.address;
21446 + gdt = (unsigned long)gdt_desc.address;
21447
21448 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21449
21450 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21451 /* 0x2 bit is always set */
21452 .flags = X86_EFLAGS_SF | 0x2,
21453 .sp = STACK_START,
21454 - .es = __USER_DS,
21455 + .es = __KERNEL_DS,
21456 .cs = __KERNEL_CS,
21457 .ss = __KERNEL_DS,
21458 - .ds = __USER_DS,
21459 + .ds = __KERNEL_DS,
21460 .fs = __KERNEL_PERCPU,
21461
21462 .__cr3 = __pa_nodebug(swapper_pg_dir),
21463 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21464 index d9c12d3..7858b62 100644
21465 --- a/arch/x86/kernel/dumpstack.c
21466 +++ b/arch/x86/kernel/dumpstack.c
21467 @@ -2,6 +2,9 @@
21468 * Copyright (C) 1991, 1992 Linus Torvalds
21469 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21470 */
21471 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21472 +#define __INCLUDED_BY_HIDESYM 1
21473 +#endif
21474 #include <linux/kallsyms.h>
21475 #include <linux/kprobes.h>
21476 #include <linux/uaccess.h>
21477 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21478 static void
21479 print_ftrace_graph_addr(unsigned long addr, void *data,
21480 const struct stacktrace_ops *ops,
21481 - struct thread_info *tinfo, int *graph)
21482 + struct task_struct *task, int *graph)
21483 {
21484 - struct task_struct *task;
21485 unsigned long ret_addr;
21486 int index;
21487
21488 if (addr != (unsigned long)return_to_handler)
21489 return;
21490
21491 - task = tinfo->task;
21492 index = task->curr_ret_stack;
21493
21494 if (!task->ret_stack || index < *graph)
21495 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21496 static inline void
21497 print_ftrace_graph_addr(unsigned long addr, void *data,
21498 const struct stacktrace_ops *ops,
21499 - struct thread_info *tinfo, int *graph)
21500 + struct task_struct *task, int *graph)
21501 { }
21502 #endif
21503
21504 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21505 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21506 */
21507
21508 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21509 - void *p, unsigned int size, void *end)
21510 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21511 {
21512 - void *t = tinfo;
21513 if (end) {
21514 if (p < end && p >= (end-THREAD_SIZE))
21515 return 1;
21516 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21517 }
21518
21519 unsigned long
21520 -print_context_stack(struct thread_info *tinfo,
21521 +print_context_stack(struct task_struct *task, void *stack_start,
21522 unsigned long *stack, unsigned long bp,
21523 const struct stacktrace_ops *ops, void *data,
21524 unsigned long *end, int *graph)
21525 {
21526 struct stack_frame *frame = (struct stack_frame *)bp;
21527
21528 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21529 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21530 unsigned long addr;
21531
21532 addr = *stack;
21533 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21534 } else {
21535 ops->address(data, addr, 0);
21536 }
21537 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21538 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21539 }
21540 stack++;
21541 }
21542 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21543 EXPORT_SYMBOL_GPL(print_context_stack);
21544
21545 unsigned long
21546 -print_context_stack_bp(struct thread_info *tinfo,
21547 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21548 unsigned long *stack, unsigned long bp,
21549 const struct stacktrace_ops *ops, void *data,
21550 unsigned long *end, int *graph)
21551 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21552 struct stack_frame *frame = (struct stack_frame *)bp;
21553 unsigned long *ret_addr = &frame->return_address;
21554
21555 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21556 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21557 unsigned long addr = *ret_addr;
21558
21559 if (!__kernel_text_address(addr))
21560 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21561 ops->address(data, addr, 1);
21562 frame = frame->next_frame;
21563 ret_addr = &frame->return_address;
21564 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21565 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21566 }
21567
21568 return (unsigned long)frame;
21569 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21570 static void print_trace_address(void *data, unsigned long addr, int reliable)
21571 {
21572 touch_nmi_watchdog();
21573 - printk(data);
21574 + printk("%s", (char *)data);
21575 printk_stack_address(addr, reliable);
21576 }
21577
21578 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21579 }
21580 EXPORT_SYMBOL_GPL(oops_begin);
21581
21582 +extern void gr_handle_kernel_exploit(void);
21583 +
21584 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21585 {
21586 if (regs && kexec_should_crash(current))
21587 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21588 panic("Fatal exception in interrupt");
21589 if (panic_on_oops)
21590 panic("Fatal exception");
21591 - do_exit(signr);
21592 +
21593 + gr_handle_kernel_exploit();
21594 +
21595 + do_group_exit(signr);
21596 }
21597
21598 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21599 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21600 print_modules();
21601 show_regs(regs);
21602 #ifdef CONFIG_X86_32
21603 - if (user_mode_vm(regs)) {
21604 + if (user_mode(regs)) {
21605 sp = regs->sp;
21606 ss = regs->ss & 0xffff;
21607 } else {
21608 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21609 unsigned long flags = oops_begin();
21610 int sig = SIGSEGV;
21611
21612 - if (!user_mode_vm(regs))
21613 + if (!user_mode(regs))
21614 report_bug(regs->ip, regs);
21615
21616 if (__die(str, regs, err))
21617 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21618 index f2a1770..540657f 100644
21619 --- a/arch/x86/kernel/dumpstack_32.c
21620 +++ b/arch/x86/kernel/dumpstack_32.c
21621 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21622 bp = stack_frame(task, regs);
21623
21624 for (;;) {
21625 - struct thread_info *context;
21626 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21627
21628 - context = (struct thread_info *)
21629 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21630 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21631 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21632
21633 - stack = (unsigned long *)context->previous_esp;
21634 - if (!stack)
21635 + if (stack_start == task_stack_page(task))
21636 break;
21637 + stack = *(unsigned long **)stack_start;
21638 if (ops->stack(data, "IRQ") < 0)
21639 break;
21640 touch_nmi_watchdog();
21641 @@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21642 int i;
21643
21644 show_regs_print_info(KERN_EMERG);
21645 - __show_regs(regs, !user_mode_vm(regs));
21646 + __show_regs(regs, !user_mode(regs));
21647
21648 /*
21649 * When in-kernel, we also print out the stack and code at the
21650 * time of the fault..
21651 */
21652 - if (!user_mode_vm(regs)) {
21653 + if (!user_mode(regs)) {
21654 unsigned int code_prologue = code_bytes * 43 / 64;
21655 unsigned int code_len = code_bytes;
21656 unsigned char c;
21657 u8 *ip;
21658 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21659
21660 pr_emerg("Stack:\n");
21661 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21662
21663 pr_emerg("Code:");
21664
21665 - ip = (u8 *)regs->ip - code_prologue;
21666 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21667 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21668 /* try starting at IP */
21669 - ip = (u8 *)regs->ip;
21670 + ip = (u8 *)regs->ip + cs_base;
21671 code_len = code_len - code_prologue + 1;
21672 }
21673 for (i = 0; i < code_len; i++, ip++) {
21674 @@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21675 pr_cont(" Bad EIP value.");
21676 break;
21677 }
21678 - if (ip == (u8 *)regs->ip)
21679 + if (ip == (u8 *)regs->ip + cs_base)
21680 pr_cont(" <%02x>", c);
21681 else
21682 pr_cont(" %02x", c);
21683 @@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21684 {
21685 unsigned short ud2;
21686
21687 + ip = ktla_ktva(ip);
21688 if (ip < PAGE_OFFSET)
21689 return 0;
21690 if (probe_kernel_address((unsigned short *)ip, ud2))
21691 @@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21692
21693 return ud2 == 0x0b0f;
21694 }
21695 +
21696 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21697 +void pax_check_alloca(unsigned long size)
21698 +{
21699 + unsigned long sp = (unsigned long)&sp, stack_left;
21700 +
21701 + /* all kernel stacks are of the same size */
21702 + stack_left = sp & (THREAD_SIZE - 1);
21703 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21704 +}
21705 +EXPORT_SYMBOL(pax_check_alloca);
21706 +#endif
21707 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21708 index addb207..99635fa 100644
21709 --- a/arch/x86/kernel/dumpstack_64.c
21710 +++ b/arch/x86/kernel/dumpstack_64.c
21711 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21712 unsigned long *irq_stack_end =
21713 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21714 unsigned used = 0;
21715 - struct thread_info *tinfo;
21716 int graph = 0;
21717 unsigned long dummy;
21718 + void *stack_start;
21719
21720 if (!task)
21721 task = current;
21722 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21723 * current stack address. If the stacks consist of nested
21724 * exceptions
21725 */
21726 - tinfo = task_thread_info(task);
21727 for (;;) {
21728 char *id;
21729 unsigned long *estack_end;
21730 +
21731 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21732 &used, &id);
21733
21734 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21735 if (ops->stack(data, id) < 0)
21736 break;
21737
21738 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21739 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21740 data, estack_end, &graph);
21741 ops->stack(data, "<EOE>");
21742 /*
21743 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21744 * second-to-last pointer (index -2 to end) in the
21745 * exception stack:
21746 */
21747 + if ((u16)estack_end[-1] != __KERNEL_DS)
21748 + goto out;
21749 stack = (unsigned long *) estack_end[-2];
21750 continue;
21751 }
21752 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21753 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21754 if (ops->stack(data, "IRQ") < 0)
21755 break;
21756 - bp = ops->walk_stack(tinfo, stack, bp,
21757 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21758 ops, data, irq_stack_end, &graph);
21759 /*
21760 * We link to the next stack (which would be
21761 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21762 /*
21763 * This handles the process stack:
21764 */
21765 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21766 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21767 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21768 +out:
21769 put_cpu();
21770 }
21771 EXPORT_SYMBOL(dump_trace);
21772 @@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21773
21774 return ud2 == 0x0b0f;
21775 }
21776 +
21777 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21778 +void pax_check_alloca(unsigned long size)
21779 +{
21780 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21781 + unsigned cpu, used;
21782 + char *id;
21783 +
21784 + /* check the process stack first */
21785 + stack_start = (unsigned long)task_stack_page(current);
21786 + stack_end = stack_start + THREAD_SIZE;
21787 + if (likely(stack_start <= sp && sp < stack_end)) {
21788 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21789 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21790 + return;
21791 + }
21792 +
21793 + cpu = get_cpu();
21794 +
21795 + /* check the irq stacks */
21796 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21797 + stack_start = stack_end - IRQ_STACK_SIZE;
21798 + if (stack_start <= sp && sp < stack_end) {
21799 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21800 + put_cpu();
21801 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21802 + return;
21803 + }
21804 +
21805 + /* check the exception stacks */
21806 + used = 0;
21807 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21808 + stack_start = stack_end - EXCEPTION_STKSZ;
21809 + if (stack_end && stack_start <= sp && sp < stack_end) {
21810 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21811 + put_cpu();
21812 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21813 + return;
21814 + }
21815 +
21816 + put_cpu();
21817 +
21818 + /* unknown stack */
21819 + BUG();
21820 +}
21821 +EXPORT_SYMBOL(pax_check_alloca);
21822 +#endif
21823 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21824 index 988c00a..4f673b6 100644
21825 --- a/arch/x86/kernel/e820.c
21826 +++ b/arch/x86/kernel/e820.c
21827 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21828
21829 static void early_panic(char *msg)
21830 {
21831 - early_printk(msg);
21832 - panic(msg);
21833 + early_printk("%s", msg);
21834 + panic("%s", msg);
21835 }
21836
21837 static int userdef __initdata;
21838 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21839 index 01d1c18..8073693 100644
21840 --- a/arch/x86/kernel/early_printk.c
21841 +++ b/arch/x86/kernel/early_printk.c
21842 @@ -7,6 +7,7 @@
21843 #include <linux/pci_regs.h>
21844 #include <linux/pci_ids.h>
21845 #include <linux/errno.h>
21846 +#include <linux/sched.h>
21847 #include <asm/io.h>
21848 #include <asm/processor.h>
21849 #include <asm/fcntl.h>
21850 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21851 index a2a4f46..6cab058 100644
21852 --- a/arch/x86/kernel/entry_32.S
21853 +++ b/arch/x86/kernel/entry_32.S
21854 @@ -177,13 +177,153 @@
21855 /*CFI_REL_OFFSET gs, PT_GS*/
21856 .endm
21857 .macro SET_KERNEL_GS reg
21858 +
21859 +#ifdef CONFIG_CC_STACKPROTECTOR
21860 movl $(__KERNEL_STACK_CANARY), \reg
21861 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21862 + movl $(__USER_DS), \reg
21863 +#else
21864 + xorl \reg, \reg
21865 +#endif
21866 +
21867 movl \reg, %gs
21868 .endm
21869
21870 #endif /* CONFIG_X86_32_LAZY_GS */
21871
21872 -.macro SAVE_ALL
21873 +.macro pax_enter_kernel
21874 +#ifdef CONFIG_PAX_KERNEXEC
21875 + call pax_enter_kernel
21876 +#endif
21877 +.endm
21878 +
21879 +.macro pax_exit_kernel
21880 +#ifdef CONFIG_PAX_KERNEXEC
21881 + call pax_exit_kernel
21882 +#endif
21883 +.endm
21884 +
21885 +#ifdef CONFIG_PAX_KERNEXEC
21886 +ENTRY(pax_enter_kernel)
21887 +#ifdef CONFIG_PARAVIRT
21888 + pushl %eax
21889 + pushl %ecx
21890 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21891 + mov %eax, %esi
21892 +#else
21893 + mov %cr0, %esi
21894 +#endif
21895 + bts $16, %esi
21896 + jnc 1f
21897 + mov %cs, %esi
21898 + cmp $__KERNEL_CS, %esi
21899 + jz 3f
21900 + ljmp $__KERNEL_CS, $3f
21901 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21902 +2:
21903 +#ifdef CONFIG_PARAVIRT
21904 + mov %esi, %eax
21905 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21906 +#else
21907 + mov %esi, %cr0
21908 +#endif
21909 +3:
21910 +#ifdef CONFIG_PARAVIRT
21911 + popl %ecx
21912 + popl %eax
21913 +#endif
21914 + ret
21915 +ENDPROC(pax_enter_kernel)
21916 +
21917 +ENTRY(pax_exit_kernel)
21918 +#ifdef CONFIG_PARAVIRT
21919 + pushl %eax
21920 + pushl %ecx
21921 +#endif
21922 + mov %cs, %esi
21923 + cmp $__KERNEXEC_KERNEL_CS, %esi
21924 + jnz 2f
21925 +#ifdef CONFIG_PARAVIRT
21926 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21927 + mov %eax, %esi
21928 +#else
21929 + mov %cr0, %esi
21930 +#endif
21931 + btr $16, %esi
21932 + ljmp $__KERNEL_CS, $1f
21933 +1:
21934 +#ifdef CONFIG_PARAVIRT
21935 + mov %esi, %eax
21936 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21937 +#else
21938 + mov %esi, %cr0
21939 +#endif
21940 +2:
21941 +#ifdef CONFIG_PARAVIRT
21942 + popl %ecx
21943 + popl %eax
21944 +#endif
21945 + ret
21946 +ENDPROC(pax_exit_kernel)
21947 +#endif
21948 +
21949 + .macro pax_erase_kstack
21950 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21951 + call pax_erase_kstack
21952 +#endif
21953 + .endm
21954 +
21955 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21956 +/*
21957 + * ebp: thread_info
21958 + */
21959 +ENTRY(pax_erase_kstack)
21960 + pushl %edi
21961 + pushl %ecx
21962 + pushl %eax
21963 +
21964 + mov TI_lowest_stack(%ebp), %edi
21965 + mov $-0xBEEF, %eax
21966 + std
21967 +
21968 +1: mov %edi, %ecx
21969 + and $THREAD_SIZE_asm - 1, %ecx
21970 + shr $2, %ecx
21971 + repne scasl
21972 + jecxz 2f
21973 +
21974 + cmp $2*16, %ecx
21975 + jc 2f
21976 +
21977 + mov $2*16, %ecx
21978 + repe scasl
21979 + jecxz 2f
21980 + jne 1b
21981 +
21982 +2: cld
21983 + mov %esp, %ecx
21984 + sub %edi, %ecx
21985 +
21986 + cmp $THREAD_SIZE_asm, %ecx
21987 + jb 3f
21988 + ud2
21989 +3:
21990 +
21991 + shr $2, %ecx
21992 + rep stosl
21993 +
21994 + mov TI_task_thread_sp0(%ebp), %edi
21995 + sub $128, %edi
21996 + mov %edi, TI_lowest_stack(%ebp)
21997 +
21998 + popl %eax
21999 + popl %ecx
22000 + popl %edi
22001 + ret
22002 +ENDPROC(pax_erase_kstack)
22003 +#endif
22004 +
22005 +.macro __SAVE_ALL _DS
22006 cld
22007 PUSH_GS
22008 pushl_cfi %fs
22009 @@ -206,7 +346,7 @@
22010 CFI_REL_OFFSET ecx, 0
22011 pushl_cfi %ebx
22012 CFI_REL_OFFSET ebx, 0
22013 - movl $(__USER_DS), %edx
22014 + movl $\_DS, %edx
22015 movl %edx, %ds
22016 movl %edx, %es
22017 movl $(__KERNEL_PERCPU), %edx
22018 @@ -214,6 +354,15 @@
22019 SET_KERNEL_GS %edx
22020 .endm
22021
22022 +.macro SAVE_ALL
22023 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22024 + __SAVE_ALL __KERNEL_DS
22025 + pax_enter_kernel
22026 +#else
22027 + __SAVE_ALL __USER_DS
22028 +#endif
22029 +.endm
22030 +
22031 .macro RESTORE_INT_REGS
22032 popl_cfi %ebx
22033 CFI_RESTORE ebx
22034 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22035 popfl_cfi
22036 jmp syscall_exit
22037 CFI_ENDPROC
22038 -END(ret_from_fork)
22039 +ENDPROC(ret_from_fork)
22040
22041 ENTRY(ret_from_kernel_thread)
22042 CFI_STARTPROC
22043 @@ -344,7 +493,15 @@ ret_from_intr:
22044 andl $SEGMENT_RPL_MASK, %eax
22045 #endif
22046 cmpl $USER_RPL, %eax
22047 +
22048 +#ifdef CONFIG_PAX_KERNEXEC
22049 + jae resume_userspace
22050 +
22051 + pax_exit_kernel
22052 + jmp resume_kernel
22053 +#else
22054 jb resume_kernel # not returning to v8086 or userspace
22055 +#endif
22056
22057 ENTRY(resume_userspace)
22058 LOCKDEP_SYS_EXIT
22059 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22060 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22061 # int/exception return?
22062 jne work_pending
22063 - jmp restore_all
22064 -END(ret_from_exception)
22065 + jmp restore_all_pax
22066 +ENDPROC(ret_from_exception)
22067
22068 #ifdef CONFIG_PREEMPT
22069 ENTRY(resume_kernel)
22070 @@ -369,7 +526,7 @@ need_resched:
22071 jz restore_all
22072 call preempt_schedule_irq
22073 jmp need_resched
22074 -END(resume_kernel)
22075 +ENDPROC(resume_kernel)
22076 #endif
22077 CFI_ENDPROC
22078 /*
22079 @@ -403,30 +560,45 @@ sysenter_past_esp:
22080 /*CFI_REL_OFFSET cs, 0*/
22081 /*
22082 * Push current_thread_info()->sysenter_return to the stack.
22083 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22084 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22085 */
22086 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22087 + pushl_cfi $0
22088 CFI_REL_OFFSET eip, 0
22089
22090 pushl_cfi %eax
22091 SAVE_ALL
22092 + GET_THREAD_INFO(%ebp)
22093 + movl TI_sysenter_return(%ebp),%ebp
22094 + movl %ebp,PT_EIP(%esp)
22095 ENABLE_INTERRUPTS(CLBR_NONE)
22096
22097 /*
22098 * Load the potential sixth argument from user stack.
22099 * Careful about security.
22100 */
22101 + movl PT_OLDESP(%esp),%ebp
22102 +
22103 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22104 + mov PT_OLDSS(%esp),%ds
22105 +1: movl %ds:(%ebp),%ebp
22106 + push %ss
22107 + pop %ds
22108 +#else
22109 cmpl $__PAGE_OFFSET-3,%ebp
22110 jae syscall_fault
22111 ASM_STAC
22112 1: movl (%ebp),%ebp
22113 ASM_CLAC
22114 +#endif
22115 +
22116 movl %ebp,PT_EBP(%esp)
22117 _ASM_EXTABLE(1b,syscall_fault)
22118
22119 GET_THREAD_INFO(%ebp)
22120
22121 +#ifdef CONFIG_PAX_RANDKSTACK
22122 + pax_erase_kstack
22123 +#endif
22124 +
22125 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22126 jnz sysenter_audit
22127 sysenter_do_call:
22128 @@ -441,12 +613,24 @@ sysenter_do_call:
22129 testl $_TIF_ALLWORK_MASK, %ecx
22130 jne sysexit_audit
22131 sysenter_exit:
22132 +
22133 +#ifdef CONFIG_PAX_RANDKSTACK
22134 + pushl_cfi %eax
22135 + movl %esp, %eax
22136 + call pax_randomize_kstack
22137 + popl_cfi %eax
22138 +#endif
22139 +
22140 + pax_erase_kstack
22141 +
22142 /* if something modifies registers it must also disable sysexit */
22143 movl PT_EIP(%esp), %edx
22144 movl PT_OLDESP(%esp), %ecx
22145 xorl %ebp,%ebp
22146 TRACE_IRQS_ON
22147 1: mov PT_FS(%esp), %fs
22148 +2: mov PT_DS(%esp), %ds
22149 +3: mov PT_ES(%esp), %es
22150 PTGS_TO_GS
22151 ENABLE_INTERRUPTS_SYSEXIT
22152
22153 @@ -463,6 +647,9 @@ sysenter_audit:
22154 movl %eax,%edx /* 2nd arg: syscall number */
22155 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22156 call __audit_syscall_entry
22157 +
22158 + pax_erase_kstack
22159 +
22160 pushl_cfi %ebx
22161 movl PT_EAX(%esp),%eax /* reload syscall number */
22162 jmp sysenter_do_call
22163 @@ -488,10 +675,16 @@ sysexit_audit:
22164
22165 CFI_ENDPROC
22166 .pushsection .fixup,"ax"
22167 -2: movl $0,PT_FS(%esp)
22168 +4: movl $0,PT_FS(%esp)
22169 + jmp 1b
22170 +5: movl $0,PT_DS(%esp)
22171 + jmp 1b
22172 +6: movl $0,PT_ES(%esp)
22173 jmp 1b
22174 .popsection
22175 - _ASM_EXTABLE(1b,2b)
22176 + _ASM_EXTABLE(1b,4b)
22177 + _ASM_EXTABLE(2b,5b)
22178 + _ASM_EXTABLE(3b,6b)
22179 PTGS_TO_GS_EX
22180 ENDPROC(ia32_sysenter_target)
22181
22182 @@ -506,6 +699,11 @@ ENTRY(system_call)
22183 pushl_cfi %eax # save orig_eax
22184 SAVE_ALL
22185 GET_THREAD_INFO(%ebp)
22186 +
22187 +#ifdef CONFIG_PAX_RANDKSTACK
22188 + pax_erase_kstack
22189 +#endif
22190 +
22191 # system call tracing in operation / emulation
22192 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22193 jnz syscall_trace_entry
22194 @@ -524,6 +722,15 @@ syscall_exit:
22195 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22196 jne syscall_exit_work
22197
22198 +restore_all_pax:
22199 +
22200 +#ifdef CONFIG_PAX_RANDKSTACK
22201 + movl %esp, %eax
22202 + call pax_randomize_kstack
22203 +#endif
22204 +
22205 + pax_erase_kstack
22206 +
22207 restore_all:
22208 TRACE_IRQS_IRET
22209 restore_all_notrace:
22210 @@ -580,14 +787,34 @@ ldt_ss:
22211 * compensating for the offset by changing to the ESPFIX segment with
22212 * a base address that matches for the difference.
22213 */
22214 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22215 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22216 mov %esp, %edx /* load kernel esp */
22217 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22218 mov %dx, %ax /* eax: new kernel esp */
22219 sub %eax, %edx /* offset (low word is 0) */
22220 +#ifdef CONFIG_SMP
22221 + movl PER_CPU_VAR(cpu_number), %ebx
22222 + shll $PAGE_SHIFT_asm, %ebx
22223 + addl $cpu_gdt_table, %ebx
22224 +#else
22225 + movl $cpu_gdt_table, %ebx
22226 +#endif
22227 shr $16, %edx
22228 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22229 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22230 +
22231 +#ifdef CONFIG_PAX_KERNEXEC
22232 + mov %cr0, %esi
22233 + btr $16, %esi
22234 + mov %esi, %cr0
22235 +#endif
22236 +
22237 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22238 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22239 +
22240 +#ifdef CONFIG_PAX_KERNEXEC
22241 + bts $16, %esi
22242 + mov %esi, %cr0
22243 +#endif
22244 +
22245 pushl_cfi $__ESPFIX_SS
22246 pushl_cfi %eax /* new kernel esp */
22247 /* Disable interrupts, but do not irqtrace this section: we
22248 @@ -616,20 +843,18 @@ work_resched:
22249 movl TI_flags(%ebp), %ecx
22250 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22251 # than syscall tracing?
22252 - jz restore_all
22253 + jz restore_all_pax
22254 testb $_TIF_NEED_RESCHED, %cl
22255 jnz work_resched
22256
22257 work_notifysig: # deal with pending signals and
22258 # notify-resume requests
22259 + movl %esp, %eax
22260 #ifdef CONFIG_VM86
22261 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22262 - movl %esp, %eax
22263 jne work_notifysig_v86 # returning to kernel-space or
22264 # vm86-space
22265 1:
22266 -#else
22267 - movl %esp, %eax
22268 #endif
22269 TRACE_IRQS_ON
22270 ENABLE_INTERRUPTS(CLBR_NONE)
22271 @@ -650,7 +875,7 @@ work_notifysig_v86:
22272 movl %eax, %esp
22273 jmp 1b
22274 #endif
22275 -END(work_pending)
22276 +ENDPROC(work_pending)
22277
22278 # perform syscall exit tracing
22279 ALIGN
22280 @@ -658,11 +883,14 @@ syscall_trace_entry:
22281 movl $-ENOSYS,PT_EAX(%esp)
22282 movl %esp, %eax
22283 call syscall_trace_enter
22284 +
22285 + pax_erase_kstack
22286 +
22287 /* What it returned is what we'll actually use. */
22288 cmpl $(NR_syscalls), %eax
22289 jnae syscall_call
22290 jmp syscall_exit
22291 -END(syscall_trace_entry)
22292 +ENDPROC(syscall_trace_entry)
22293
22294 # perform syscall exit tracing
22295 ALIGN
22296 @@ -675,21 +903,25 @@ syscall_exit_work:
22297 movl %esp, %eax
22298 call syscall_trace_leave
22299 jmp resume_userspace
22300 -END(syscall_exit_work)
22301 +ENDPROC(syscall_exit_work)
22302 CFI_ENDPROC
22303
22304 RING0_INT_FRAME # can't unwind into user space anyway
22305 syscall_fault:
22306 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22307 + push %ss
22308 + pop %ds
22309 +#endif
22310 ASM_CLAC
22311 GET_THREAD_INFO(%ebp)
22312 movl $-EFAULT,PT_EAX(%esp)
22313 jmp resume_userspace
22314 -END(syscall_fault)
22315 +ENDPROC(syscall_fault)
22316
22317 syscall_badsys:
22318 movl $-ENOSYS,PT_EAX(%esp)
22319 jmp resume_userspace
22320 -END(syscall_badsys)
22321 +ENDPROC(syscall_badsys)
22322 CFI_ENDPROC
22323 /*
22324 * End of kprobes section
22325 @@ -705,8 +937,15 @@ END(syscall_badsys)
22326 * normal stack and adjusts ESP with the matching offset.
22327 */
22328 /* fixup the stack */
22329 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22330 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22331 +#ifdef CONFIG_SMP
22332 + movl PER_CPU_VAR(cpu_number), %ebx
22333 + shll $PAGE_SHIFT_asm, %ebx
22334 + addl $cpu_gdt_table, %ebx
22335 +#else
22336 + movl $cpu_gdt_table, %ebx
22337 +#endif
22338 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22339 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22340 shl $16, %eax
22341 addl %esp, %eax /* the adjusted stack pointer */
22342 pushl_cfi $__KERNEL_DS
22343 @@ -759,7 +998,7 @@ vector=vector+1
22344 .endr
22345 2: jmp common_interrupt
22346 .endr
22347 -END(irq_entries_start)
22348 +ENDPROC(irq_entries_start)
22349
22350 .previous
22351 END(interrupt)
22352 @@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22353 pushl_cfi $do_coprocessor_error
22354 jmp error_code
22355 CFI_ENDPROC
22356 -END(coprocessor_error)
22357 +ENDPROC(coprocessor_error)
22358
22359 ENTRY(simd_coprocessor_error)
22360 RING0_INT_FRAME
22361 @@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22362 .section .altinstructions,"a"
22363 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22364 .previous
22365 -.section .altinstr_replacement,"ax"
22366 +.section .altinstr_replacement,"a"
22367 663: pushl $do_simd_coprocessor_error
22368 664:
22369 .previous
22370 @@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22371 #endif
22372 jmp error_code
22373 CFI_ENDPROC
22374 -END(simd_coprocessor_error)
22375 +ENDPROC(simd_coprocessor_error)
22376
22377 ENTRY(device_not_available)
22378 RING0_INT_FRAME
22379 @@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22380 pushl_cfi $do_device_not_available
22381 jmp error_code
22382 CFI_ENDPROC
22383 -END(device_not_available)
22384 +ENDPROC(device_not_available)
22385
22386 #ifdef CONFIG_PARAVIRT
22387 ENTRY(native_iret)
22388 iret
22389 _ASM_EXTABLE(native_iret, iret_exc)
22390 -END(native_iret)
22391 +ENDPROC(native_iret)
22392
22393 ENTRY(native_irq_enable_sysexit)
22394 sti
22395 sysexit
22396 -END(native_irq_enable_sysexit)
22397 +ENDPROC(native_irq_enable_sysexit)
22398 #endif
22399
22400 ENTRY(overflow)
22401 @@ -872,7 +1111,7 @@ ENTRY(overflow)
22402 pushl_cfi $do_overflow
22403 jmp error_code
22404 CFI_ENDPROC
22405 -END(overflow)
22406 +ENDPROC(overflow)
22407
22408 ENTRY(bounds)
22409 RING0_INT_FRAME
22410 @@ -881,7 +1120,7 @@ ENTRY(bounds)
22411 pushl_cfi $do_bounds
22412 jmp error_code
22413 CFI_ENDPROC
22414 -END(bounds)
22415 +ENDPROC(bounds)
22416
22417 ENTRY(invalid_op)
22418 RING0_INT_FRAME
22419 @@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22420 pushl_cfi $do_invalid_op
22421 jmp error_code
22422 CFI_ENDPROC
22423 -END(invalid_op)
22424 +ENDPROC(invalid_op)
22425
22426 ENTRY(coprocessor_segment_overrun)
22427 RING0_INT_FRAME
22428 @@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22429 pushl_cfi $do_coprocessor_segment_overrun
22430 jmp error_code
22431 CFI_ENDPROC
22432 -END(coprocessor_segment_overrun)
22433 +ENDPROC(coprocessor_segment_overrun)
22434
22435 ENTRY(invalid_TSS)
22436 RING0_EC_FRAME
22437 @@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22438 pushl_cfi $do_invalid_TSS
22439 jmp error_code
22440 CFI_ENDPROC
22441 -END(invalid_TSS)
22442 +ENDPROC(invalid_TSS)
22443
22444 ENTRY(segment_not_present)
22445 RING0_EC_FRAME
22446 @@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22447 pushl_cfi $do_segment_not_present
22448 jmp error_code
22449 CFI_ENDPROC
22450 -END(segment_not_present)
22451 +ENDPROC(segment_not_present)
22452
22453 ENTRY(stack_segment)
22454 RING0_EC_FRAME
22455 @@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22456 pushl_cfi $do_stack_segment
22457 jmp error_code
22458 CFI_ENDPROC
22459 -END(stack_segment)
22460 +ENDPROC(stack_segment)
22461
22462 ENTRY(alignment_check)
22463 RING0_EC_FRAME
22464 @@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22465 pushl_cfi $do_alignment_check
22466 jmp error_code
22467 CFI_ENDPROC
22468 -END(alignment_check)
22469 +ENDPROC(alignment_check)
22470
22471 ENTRY(divide_error)
22472 RING0_INT_FRAME
22473 @@ -940,7 +1179,7 @@ ENTRY(divide_error)
22474 pushl_cfi $do_divide_error
22475 jmp error_code
22476 CFI_ENDPROC
22477 -END(divide_error)
22478 +ENDPROC(divide_error)
22479
22480 #ifdef CONFIG_X86_MCE
22481 ENTRY(machine_check)
22482 @@ -950,7 +1189,7 @@ ENTRY(machine_check)
22483 pushl_cfi machine_check_vector
22484 jmp error_code
22485 CFI_ENDPROC
22486 -END(machine_check)
22487 +ENDPROC(machine_check)
22488 #endif
22489
22490 ENTRY(spurious_interrupt_bug)
22491 @@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22492 pushl_cfi $do_spurious_interrupt_bug
22493 jmp error_code
22494 CFI_ENDPROC
22495 -END(spurious_interrupt_bug)
22496 +ENDPROC(spurious_interrupt_bug)
22497 /*
22498 * End of kprobes section
22499 */
22500 @@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22501
22502 ENTRY(mcount)
22503 ret
22504 -END(mcount)
22505 +ENDPROC(mcount)
22506
22507 ENTRY(ftrace_caller)
22508 cmpl $0, function_trace_stop
22509 @@ -1103,7 +1342,7 @@ ftrace_graph_call:
22510 .globl ftrace_stub
22511 ftrace_stub:
22512 ret
22513 -END(ftrace_caller)
22514 +ENDPROC(ftrace_caller)
22515
22516 ENTRY(ftrace_regs_caller)
22517 pushf /* push flags before compare (in cs location) */
22518 @@ -1207,7 +1446,7 @@ trace:
22519 popl %ecx
22520 popl %eax
22521 jmp ftrace_stub
22522 -END(mcount)
22523 +ENDPROC(mcount)
22524 #endif /* CONFIG_DYNAMIC_FTRACE */
22525 #endif /* CONFIG_FUNCTION_TRACER */
22526
22527 @@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22528 popl %ecx
22529 popl %eax
22530 ret
22531 -END(ftrace_graph_caller)
22532 +ENDPROC(ftrace_graph_caller)
22533
22534 .globl return_to_handler
22535 return_to_handler:
22536 @@ -1291,15 +1530,18 @@ error_code:
22537 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22538 REG_TO_PTGS %ecx
22539 SET_KERNEL_GS %ecx
22540 - movl $(__USER_DS), %ecx
22541 + movl $(__KERNEL_DS), %ecx
22542 movl %ecx, %ds
22543 movl %ecx, %es
22544 +
22545 + pax_enter_kernel
22546 +
22547 TRACE_IRQS_OFF
22548 movl %esp,%eax # pt_regs pointer
22549 call *%edi
22550 jmp ret_from_exception
22551 CFI_ENDPROC
22552 -END(page_fault)
22553 +ENDPROC(page_fault)
22554
22555 /*
22556 * Debug traps and NMI can happen at the one SYSENTER instruction
22557 @@ -1342,7 +1584,7 @@ debug_stack_correct:
22558 call do_debug
22559 jmp ret_from_exception
22560 CFI_ENDPROC
22561 -END(debug)
22562 +ENDPROC(debug)
22563
22564 /*
22565 * NMI is doubly nasty. It can happen _while_ we're handling
22566 @@ -1380,6 +1622,9 @@ nmi_stack_correct:
22567 xorl %edx,%edx # zero error code
22568 movl %esp,%eax # pt_regs pointer
22569 call do_nmi
22570 +
22571 + pax_exit_kernel
22572 +
22573 jmp restore_all_notrace
22574 CFI_ENDPROC
22575
22576 @@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22577 FIXUP_ESPFIX_STACK # %eax == %esp
22578 xorl %edx,%edx # zero error code
22579 call do_nmi
22580 +
22581 + pax_exit_kernel
22582 +
22583 RESTORE_REGS
22584 lss 12+4(%esp), %esp # back to espfix stack
22585 CFI_ADJUST_CFA_OFFSET -24
22586 jmp irq_return
22587 CFI_ENDPROC
22588 -END(nmi)
22589 +ENDPROC(nmi)
22590
22591 ENTRY(int3)
22592 RING0_INT_FRAME
22593 @@ -1434,14 +1682,14 @@ ENTRY(int3)
22594 call do_int3
22595 jmp ret_from_exception
22596 CFI_ENDPROC
22597 -END(int3)
22598 +ENDPROC(int3)
22599
22600 ENTRY(general_protection)
22601 RING0_EC_FRAME
22602 pushl_cfi $do_general_protection
22603 jmp error_code
22604 CFI_ENDPROC
22605 -END(general_protection)
22606 +ENDPROC(general_protection)
22607
22608 #ifdef CONFIG_KVM_GUEST
22609 ENTRY(async_page_fault)
22610 @@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22611 pushl_cfi $do_async_page_fault
22612 jmp error_code
22613 CFI_ENDPROC
22614 -END(async_page_fault)
22615 +ENDPROC(async_page_fault)
22616 #endif
22617
22618 /*
22619 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22620 index 1e96c36..3ff710a 100644
22621 --- a/arch/x86/kernel/entry_64.S
22622 +++ b/arch/x86/kernel/entry_64.S
22623 @@ -59,6 +59,8 @@
22624 #include <asm/context_tracking.h>
22625 #include <asm/smap.h>
22626 #include <linux/err.h>
22627 +#include <asm/pgtable.h>
22628 +#include <asm/alternative-asm.h>
22629
22630 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22631 #include <linux/elf-em.h>
22632 @@ -80,8 +82,9 @@
22633 #ifdef CONFIG_DYNAMIC_FTRACE
22634
22635 ENTRY(function_hook)
22636 + pax_force_retaddr
22637 retq
22638 -END(function_hook)
22639 +ENDPROC(function_hook)
22640
22641 /* skip is set if stack has been adjusted */
22642 .macro ftrace_caller_setup skip=0
22643 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22644 #endif
22645
22646 GLOBAL(ftrace_stub)
22647 + pax_force_retaddr
22648 retq
22649 -END(ftrace_caller)
22650 +ENDPROC(ftrace_caller)
22651
22652 ENTRY(ftrace_regs_caller)
22653 /* Save the current flags before compare (in SS location)*/
22654 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22655 popfq
22656 jmp ftrace_stub
22657
22658 -END(ftrace_regs_caller)
22659 +ENDPROC(ftrace_regs_caller)
22660
22661
22662 #else /* ! CONFIG_DYNAMIC_FTRACE */
22663 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22664 #endif
22665
22666 GLOBAL(ftrace_stub)
22667 + pax_force_retaddr
22668 retq
22669
22670 trace:
22671 @@ -225,12 +230,13 @@ trace:
22672 #endif
22673 subq $MCOUNT_INSN_SIZE, %rdi
22674
22675 + pax_force_fptr ftrace_trace_function
22676 call *ftrace_trace_function
22677
22678 MCOUNT_RESTORE_FRAME
22679
22680 jmp ftrace_stub
22681 -END(function_hook)
22682 +ENDPROC(function_hook)
22683 #endif /* CONFIG_DYNAMIC_FTRACE */
22684 #endif /* CONFIG_FUNCTION_TRACER */
22685
22686 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22687
22688 MCOUNT_RESTORE_FRAME
22689
22690 + pax_force_retaddr
22691 retq
22692 -END(ftrace_graph_caller)
22693 +ENDPROC(ftrace_graph_caller)
22694
22695 GLOBAL(return_to_handler)
22696 subq $24, %rsp
22697 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22698 movq 8(%rsp), %rdx
22699 movq (%rsp), %rax
22700 addq $24, %rsp
22701 + pax_force_fptr %rdi
22702 jmp *%rdi
22703 +ENDPROC(return_to_handler)
22704 #endif
22705
22706
22707 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22708 ENDPROC(native_usergs_sysret64)
22709 #endif /* CONFIG_PARAVIRT */
22710
22711 + .macro ljmpq sel, off
22712 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22713 + .byte 0x48; ljmp *1234f(%rip)
22714 + .pushsection .rodata
22715 + .align 16
22716 + 1234: .quad \off; .word \sel
22717 + .popsection
22718 +#else
22719 + pushq $\sel
22720 + pushq $\off
22721 + lretq
22722 +#endif
22723 + .endm
22724 +
22725 + .macro pax_enter_kernel
22726 + pax_set_fptr_mask
22727 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22728 + call pax_enter_kernel
22729 +#endif
22730 + .endm
22731 +
22732 + .macro pax_exit_kernel
22733 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22734 + call pax_exit_kernel
22735 +#endif
22736 +
22737 + .endm
22738 +
22739 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22740 +ENTRY(pax_enter_kernel)
22741 + pushq %rdi
22742 +
22743 +#ifdef CONFIG_PARAVIRT
22744 + PV_SAVE_REGS(CLBR_RDI)
22745 +#endif
22746 +
22747 +#ifdef CONFIG_PAX_KERNEXEC
22748 + GET_CR0_INTO_RDI
22749 + bts $16,%rdi
22750 + jnc 3f
22751 + mov %cs,%edi
22752 + cmp $__KERNEL_CS,%edi
22753 + jnz 2f
22754 +1:
22755 +#endif
22756 +
22757 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22758 + 661: jmp 111f
22759 + .pushsection .altinstr_replacement, "a"
22760 + 662: ASM_NOP2
22761 + .popsection
22762 + .pushsection .altinstructions, "a"
22763 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22764 + .popsection
22765 + GET_CR3_INTO_RDI
22766 + cmp $0,%dil
22767 + jnz 112f
22768 + mov $__KERNEL_DS,%edi
22769 + mov %edi,%ss
22770 + jmp 111f
22771 +112: cmp $1,%dil
22772 + jz 113f
22773 + ud2
22774 +113: sub $4097,%rdi
22775 + bts $63,%rdi
22776 + SET_RDI_INTO_CR3
22777 + mov $__UDEREF_KERNEL_DS,%edi
22778 + mov %edi,%ss
22779 +111:
22780 +#endif
22781 +
22782 +#ifdef CONFIG_PARAVIRT
22783 + PV_RESTORE_REGS(CLBR_RDI)
22784 +#endif
22785 +
22786 + popq %rdi
22787 + pax_force_retaddr
22788 + retq
22789 +
22790 +#ifdef CONFIG_PAX_KERNEXEC
22791 +2: ljmpq __KERNEL_CS,1b
22792 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22793 +4: SET_RDI_INTO_CR0
22794 + jmp 1b
22795 +#endif
22796 +ENDPROC(pax_enter_kernel)
22797 +
22798 +ENTRY(pax_exit_kernel)
22799 + pushq %rdi
22800 +
22801 +#ifdef CONFIG_PARAVIRT
22802 + PV_SAVE_REGS(CLBR_RDI)
22803 +#endif
22804 +
22805 +#ifdef CONFIG_PAX_KERNEXEC
22806 + mov %cs,%rdi
22807 + cmp $__KERNEXEC_KERNEL_CS,%edi
22808 + jz 2f
22809 + GET_CR0_INTO_RDI
22810 + bts $16,%rdi
22811 + jnc 4f
22812 +1:
22813 +#endif
22814 +
22815 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22816 + 661: jmp 111f
22817 + .pushsection .altinstr_replacement, "a"
22818 + 662: ASM_NOP2
22819 + .popsection
22820 + .pushsection .altinstructions, "a"
22821 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22822 + .popsection
22823 + mov %ss,%edi
22824 + cmp $__UDEREF_KERNEL_DS,%edi
22825 + jnz 111f
22826 + GET_CR3_INTO_RDI
22827 + cmp $0,%dil
22828 + jz 112f
22829 + ud2
22830 +112: add $4097,%rdi
22831 + bts $63,%rdi
22832 + SET_RDI_INTO_CR3
22833 + mov $__KERNEL_DS,%edi
22834 + mov %edi,%ss
22835 +111:
22836 +#endif
22837 +
22838 +#ifdef CONFIG_PARAVIRT
22839 + PV_RESTORE_REGS(CLBR_RDI);
22840 +#endif
22841 +
22842 + popq %rdi
22843 + pax_force_retaddr
22844 + retq
22845 +
22846 +#ifdef CONFIG_PAX_KERNEXEC
22847 +2: GET_CR0_INTO_RDI
22848 + btr $16,%rdi
22849 + jnc 4f
22850 + ljmpq __KERNEL_CS,3f
22851 +3: SET_RDI_INTO_CR0
22852 + jmp 1b
22853 +4: ud2
22854 + jmp 4b
22855 +#endif
22856 +ENDPROC(pax_exit_kernel)
22857 +#endif
22858 +
22859 + .macro pax_enter_kernel_user
22860 + pax_set_fptr_mask
22861 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22862 + call pax_enter_kernel_user
22863 +#endif
22864 + .endm
22865 +
22866 + .macro pax_exit_kernel_user
22867 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22868 + call pax_exit_kernel_user
22869 +#endif
22870 +#ifdef CONFIG_PAX_RANDKSTACK
22871 + pushq %rax
22872 + pushq %r11
22873 + call pax_randomize_kstack
22874 + popq %r11
22875 + popq %rax
22876 +#endif
22877 + .endm
22878 +
22879 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22880 +ENTRY(pax_enter_kernel_user)
22881 + pushq %rdi
22882 + pushq %rbx
22883 +
22884 +#ifdef CONFIG_PARAVIRT
22885 + PV_SAVE_REGS(CLBR_RDI)
22886 +#endif
22887 +
22888 + 661: jmp 111f
22889 + .pushsection .altinstr_replacement, "a"
22890 + 662: ASM_NOP2
22891 + .popsection
22892 + .pushsection .altinstructions, "a"
22893 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22894 + .popsection
22895 + GET_CR3_INTO_RDI
22896 + cmp $1,%dil
22897 + jnz 4f
22898 + sub $4097,%rdi
22899 + bts $63,%rdi
22900 + SET_RDI_INTO_CR3
22901 + jmp 3f
22902 +111:
22903 +
22904 + GET_CR3_INTO_RDI
22905 + mov %rdi,%rbx
22906 + add $__START_KERNEL_map,%rbx
22907 + sub phys_base(%rip),%rbx
22908 +
22909 +#ifdef CONFIG_PARAVIRT
22910 + cmpl $0, pv_info+PARAVIRT_enabled
22911 + jz 1f
22912 + pushq %rdi
22913 + i = 0
22914 + .rept USER_PGD_PTRS
22915 + mov i*8(%rbx),%rsi
22916 + mov $0,%sil
22917 + lea i*8(%rbx),%rdi
22918 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22919 + i = i + 1
22920 + .endr
22921 + popq %rdi
22922 + jmp 2f
22923 +1:
22924 +#endif
22925 +
22926 + i = 0
22927 + .rept USER_PGD_PTRS
22928 + movb $0,i*8(%rbx)
22929 + i = i + 1
22930 + .endr
22931 +
22932 +2: SET_RDI_INTO_CR3
22933 +
22934 +#ifdef CONFIG_PAX_KERNEXEC
22935 + GET_CR0_INTO_RDI
22936 + bts $16,%rdi
22937 + SET_RDI_INTO_CR0
22938 +#endif
22939 +
22940 +3:
22941 +
22942 +#ifdef CONFIG_PARAVIRT
22943 + PV_RESTORE_REGS(CLBR_RDI)
22944 +#endif
22945 +
22946 + popq %rbx
22947 + popq %rdi
22948 + pax_force_retaddr
22949 + retq
22950 +4: ud2
22951 +ENDPROC(pax_enter_kernel_user)
22952 +
22953 +ENTRY(pax_exit_kernel_user)
22954 + pushq %rdi
22955 + pushq %rbx
22956 +
22957 +#ifdef CONFIG_PARAVIRT
22958 + PV_SAVE_REGS(CLBR_RDI)
22959 +#endif
22960 +
22961 + GET_CR3_INTO_RDI
22962 + 661: jmp 1f
22963 + .pushsection .altinstr_replacement, "a"
22964 + 662: ASM_NOP2
22965 + .popsection
22966 + .pushsection .altinstructions, "a"
22967 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22968 + .popsection
22969 + cmp $0,%dil
22970 + jnz 3f
22971 + add $4097,%rdi
22972 + bts $63,%rdi
22973 + SET_RDI_INTO_CR3
22974 + jmp 2f
22975 +1:
22976 +
22977 + mov %rdi,%rbx
22978 +
22979 +#ifdef CONFIG_PAX_KERNEXEC
22980 + GET_CR0_INTO_RDI
22981 + btr $16,%rdi
22982 + jnc 3f
22983 + SET_RDI_INTO_CR0
22984 +#endif
22985 +
22986 + add $__START_KERNEL_map,%rbx
22987 + sub phys_base(%rip),%rbx
22988 +
22989 +#ifdef CONFIG_PARAVIRT
22990 + cmpl $0, pv_info+PARAVIRT_enabled
22991 + jz 1f
22992 + i = 0
22993 + .rept USER_PGD_PTRS
22994 + mov i*8(%rbx),%rsi
22995 + mov $0x67,%sil
22996 + lea i*8(%rbx),%rdi
22997 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22998 + i = i + 1
22999 + .endr
23000 + jmp 2f
23001 +1:
23002 +#endif
23003 +
23004 + i = 0
23005 + .rept USER_PGD_PTRS
23006 + movb $0x67,i*8(%rbx)
23007 + i = i + 1
23008 + .endr
23009 +2:
23010 +
23011 +#ifdef CONFIG_PARAVIRT
23012 + PV_RESTORE_REGS(CLBR_RDI)
23013 +#endif
23014 +
23015 + popq %rbx
23016 + popq %rdi
23017 + pax_force_retaddr
23018 + retq
23019 +3: ud2
23020 +ENDPROC(pax_exit_kernel_user)
23021 +#endif
23022 +
23023 + .macro pax_enter_kernel_nmi
23024 + pax_set_fptr_mask
23025 +
23026 +#ifdef CONFIG_PAX_KERNEXEC
23027 + GET_CR0_INTO_RDI
23028 + bts $16,%rdi
23029 + jc 110f
23030 + SET_RDI_INTO_CR0
23031 + or $2,%ebx
23032 +110:
23033 +#endif
23034 +
23035 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23036 + 661: jmp 111f
23037 + .pushsection .altinstr_replacement, "a"
23038 + 662: ASM_NOP2
23039 + .popsection
23040 + .pushsection .altinstructions, "a"
23041 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23042 + .popsection
23043 + GET_CR3_INTO_RDI
23044 + cmp $0,%dil
23045 + jz 111f
23046 + sub $4097,%rdi
23047 + or $4,%ebx
23048 + bts $63,%rdi
23049 + SET_RDI_INTO_CR3
23050 + mov $__UDEREF_KERNEL_DS,%edi
23051 + mov %edi,%ss
23052 +111:
23053 +#endif
23054 + .endm
23055 +
23056 + .macro pax_exit_kernel_nmi
23057 +#ifdef CONFIG_PAX_KERNEXEC
23058 + btr $1,%ebx
23059 + jnc 110f
23060 + GET_CR0_INTO_RDI
23061 + btr $16,%rdi
23062 + SET_RDI_INTO_CR0
23063 +110:
23064 +#endif
23065 +
23066 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23067 + btr $2,%ebx
23068 + jnc 111f
23069 + GET_CR3_INTO_RDI
23070 + add $4097,%rdi
23071 + bts $63,%rdi
23072 + SET_RDI_INTO_CR3
23073 + mov $__KERNEL_DS,%edi
23074 + mov %edi,%ss
23075 +111:
23076 +#endif
23077 + .endm
23078 +
23079 + .macro pax_erase_kstack
23080 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23081 + call pax_erase_kstack
23082 +#endif
23083 + .endm
23084 +
23085 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23086 +ENTRY(pax_erase_kstack)
23087 + pushq %rdi
23088 + pushq %rcx
23089 + pushq %rax
23090 + pushq %r11
23091 +
23092 + GET_THREAD_INFO(%r11)
23093 + mov TI_lowest_stack(%r11), %rdi
23094 + mov $-0xBEEF, %rax
23095 + std
23096 +
23097 +1: mov %edi, %ecx
23098 + and $THREAD_SIZE_asm - 1, %ecx
23099 + shr $3, %ecx
23100 + repne scasq
23101 + jecxz 2f
23102 +
23103 + cmp $2*8, %ecx
23104 + jc 2f
23105 +
23106 + mov $2*8, %ecx
23107 + repe scasq
23108 + jecxz 2f
23109 + jne 1b
23110 +
23111 +2: cld
23112 + mov %esp, %ecx
23113 + sub %edi, %ecx
23114 +
23115 + cmp $THREAD_SIZE_asm, %rcx
23116 + jb 3f
23117 + ud2
23118 +3:
23119 +
23120 + shr $3, %ecx
23121 + rep stosq
23122 +
23123 + mov TI_task_thread_sp0(%r11), %rdi
23124 + sub $256, %rdi
23125 + mov %rdi, TI_lowest_stack(%r11)
23126 +
23127 + popq %r11
23128 + popq %rax
23129 + popq %rcx
23130 + popq %rdi
23131 + pax_force_retaddr
23132 + ret
23133 +ENDPROC(pax_erase_kstack)
23134 +#endif
23135
23136 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23137 #ifdef CONFIG_TRACE_IRQFLAGS
23138 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23139 .endm
23140
23141 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23142 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23143 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23144 jnc 1f
23145 TRACE_IRQS_ON_DEBUG
23146 1:
23147 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23148 movq \tmp,R11+\offset(%rsp)
23149 .endm
23150
23151 - .macro FAKE_STACK_FRAME child_rip
23152 - /* push in order ss, rsp, eflags, cs, rip */
23153 - xorl %eax, %eax
23154 - pushq_cfi $__KERNEL_DS /* ss */
23155 - /*CFI_REL_OFFSET ss,0*/
23156 - pushq_cfi %rax /* rsp */
23157 - CFI_REL_OFFSET rsp,0
23158 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23159 - /*CFI_REL_OFFSET rflags,0*/
23160 - pushq_cfi $__KERNEL_CS /* cs */
23161 - /*CFI_REL_OFFSET cs,0*/
23162 - pushq_cfi \child_rip /* rip */
23163 - CFI_REL_OFFSET rip,0
23164 - pushq_cfi %rax /* orig rax */
23165 - .endm
23166 -
23167 - .macro UNFAKE_STACK_FRAME
23168 - addq $8*6, %rsp
23169 - CFI_ADJUST_CFA_OFFSET -(6*8)
23170 - .endm
23171 -
23172 /*
23173 * initial frame state for interrupts (and exceptions without error code)
23174 */
23175 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23176 /* save partial stack frame */
23177 .macro SAVE_ARGS_IRQ
23178 cld
23179 - /* start from rbp in pt_regs and jump over */
23180 - movq_cfi rdi, (RDI-RBP)
23181 - movq_cfi rsi, (RSI-RBP)
23182 - movq_cfi rdx, (RDX-RBP)
23183 - movq_cfi rcx, (RCX-RBP)
23184 - movq_cfi rax, (RAX-RBP)
23185 - movq_cfi r8, (R8-RBP)
23186 - movq_cfi r9, (R9-RBP)
23187 - movq_cfi r10, (R10-RBP)
23188 - movq_cfi r11, (R11-RBP)
23189 + /* start from r15 in pt_regs and jump over */
23190 + movq_cfi rdi, RDI
23191 + movq_cfi rsi, RSI
23192 + movq_cfi rdx, RDX
23193 + movq_cfi rcx, RCX
23194 + movq_cfi rax, RAX
23195 + movq_cfi r8, R8
23196 + movq_cfi r9, R9
23197 + movq_cfi r10, R10
23198 + movq_cfi r11, R11
23199 + movq_cfi r12, R12
23200
23201 /* Save rbp so that we can unwind from get_irq_regs() */
23202 - movq_cfi rbp, 0
23203 + movq_cfi rbp, RBP
23204
23205 /* Save previous stack value */
23206 movq %rsp, %rsi
23207
23208 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23209 - testl $3, CS-RBP(%rsi)
23210 + movq %rsp,%rdi /* arg1 for handler */
23211 + testb $3, CS(%rsi)
23212 je 1f
23213 SWAPGS
23214 /*
23215 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23216 0x06 /* DW_OP_deref */, \
23217 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23218 0x22 /* DW_OP_plus */
23219 +
23220 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23221 + testb $3, CS(%rdi)
23222 + jnz 1f
23223 + pax_enter_kernel
23224 + jmp 2f
23225 +1: pax_enter_kernel_user
23226 +2:
23227 +#else
23228 + pax_enter_kernel
23229 +#endif
23230 +
23231 /* We entered an interrupt context - irqs are off: */
23232 TRACE_IRQS_OFF
23233 .endm
23234 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23235 js 1f /* negative -> in kernel */
23236 SWAPGS
23237 xorl %ebx,%ebx
23238 -1: ret
23239 +1:
23240 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23241 + testb $3, CS+8(%rsp)
23242 + jnz 1f
23243 + pax_enter_kernel
23244 + jmp 2f
23245 +1: pax_enter_kernel_user
23246 +2:
23247 +#else
23248 + pax_enter_kernel
23249 +#endif
23250 + pax_force_retaddr
23251 + ret
23252 CFI_ENDPROC
23253 -END(save_paranoid)
23254 +ENDPROC(save_paranoid)
23255 +
23256 +ENTRY(save_paranoid_nmi)
23257 + XCPT_FRAME 1 RDI+8
23258 + cld
23259 + movq_cfi rdi, RDI+8
23260 + movq_cfi rsi, RSI+8
23261 + movq_cfi rdx, RDX+8
23262 + movq_cfi rcx, RCX+8
23263 + movq_cfi rax, RAX+8
23264 + movq_cfi r8, R8+8
23265 + movq_cfi r9, R9+8
23266 + movq_cfi r10, R10+8
23267 + movq_cfi r11, R11+8
23268 + movq_cfi rbx, RBX+8
23269 + movq_cfi rbp, RBP+8
23270 + movq_cfi r12, R12+8
23271 + movq_cfi r13, R13+8
23272 + movq_cfi r14, R14+8
23273 + movq_cfi r15, R15+8
23274 + movl $1,%ebx
23275 + movl $MSR_GS_BASE,%ecx
23276 + rdmsr
23277 + testl %edx,%edx
23278 + js 1f /* negative -> in kernel */
23279 + SWAPGS
23280 + xorl %ebx,%ebx
23281 +1: pax_enter_kernel_nmi
23282 + pax_force_retaddr
23283 + ret
23284 + CFI_ENDPROC
23285 +ENDPROC(save_paranoid_nmi)
23286 .popsection
23287
23288 /*
23289 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23290
23291 RESTORE_REST
23292
23293 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23294 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23295 jz 1f
23296
23297 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23298 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23299 jmp ret_from_sys_call # go to the SYSRET fastpath
23300
23301 1:
23302 - subq $REST_SKIP, %rsp # leave space for volatiles
23303 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23304 movq %rbp, %rdi
23305 call *%rbx
23306 movl $0, RAX(%rsp)
23307 RESTORE_REST
23308 jmp int_ret_from_sys_call
23309 CFI_ENDPROC
23310 -END(ret_from_fork)
23311 +ENDPROC(ret_from_fork)
23312
23313 /*
23314 * System call entry. Up to 6 arguments in registers are supported.
23315 @@ -593,7 +1059,7 @@ END(ret_from_fork)
23316 ENTRY(system_call)
23317 CFI_STARTPROC simple
23318 CFI_SIGNAL_FRAME
23319 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23320 + CFI_DEF_CFA rsp,0
23321 CFI_REGISTER rip,rcx
23322 /*CFI_REGISTER rflags,r11*/
23323 SWAPGS_UNSAFE_STACK
23324 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23325
23326 movq %rsp,PER_CPU_VAR(old_rsp)
23327 movq PER_CPU_VAR(kernel_stack),%rsp
23328 + SAVE_ARGS 8*6,0
23329 + pax_enter_kernel_user
23330 +
23331 +#ifdef CONFIG_PAX_RANDKSTACK
23332 + pax_erase_kstack
23333 +#endif
23334 +
23335 /*
23336 * No need to follow this irqs off/on section - it's straight
23337 * and short:
23338 */
23339 ENABLE_INTERRUPTS(CLBR_NONE)
23340 - SAVE_ARGS 8,0
23341 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23342 movq %rcx,RIP-ARGOFFSET(%rsp)
23343 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23344 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23345 + GET_THREAD_INFO(%rcx)
23346 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23347 jnz tracesys
23348 system_call_fastpath:
23349 #if __SYSCALL_MASK == ~0
23350 @@ -639,10 +1112,13 @@ sysret_check:
23351 LOCKDEP_SYS_EXIT
23352 DISABLE_INTERRUPTS(CLBR_NONE)
23353 TRACE_IRQS_OFF
23354 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23355 + GET_THREAD_INFO(%rcx)
23356 + movl TI_flags(%rcx),%edx
23357 andl %edi,%edx
23358 jnz sysret_careful
23359 CFI_REMEMBER_STATE
23360 + pax_exit_kernel_user
23361 + pax_erase_kstack
23362 /*
23363 * sysretq will re-enable interrupts:
23364 */
23365 @@ -701,6 +1177,9 @@ auditsys:
23366 movq %rax,%rsi /* 2nd arg: syscall number */
23367 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23368 call __audit_syscall_entry
23369 +
23370 + pax_erase_kstack
23371 +
23372 LOAD_ARGS 0 /* reload call-clobbered registers */
23373 jmp system_call_fastpath
23374
23375 @@ -722,7 +1201,7 @@ sysret_audit:
23376 /* Do syscall tracing */
23377 tracesys:
23378 #ifdef CONFIG_AUDITSYSCALL
23379 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23380 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23381 jz auditsys
23382 #endif
23383 SAVE_REST
23384 @@ -730,12 +1209,15 @@ tracesys:
23385 FIXUP_TOP_OF_STACK %rdi
23386 movq %rsp,%rdi
23387 call syscall_trace_enter
23388 +
23389 + pax_erase_kstack
23390 +
23391 /*
23392 * Reload arg registers from stack in case ptrace changed them.
23393 * We don't reload %rax because syscall_trace_enter() returned
23394 * the value it wants us to use in the table lookup.
23395 */
23396 - LOAD_ARGS ARGOFFSET, 1
23397 + LOAD_ARGS 1
23398 RESTORE_REST
23399 #if __SYSCALL_MASK == ~0
23400 cmpq $__NR_syscall_max,%rax
23401 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23402 andl %edi,%edx
23403 jnz int_careful
23404 andl $~TS_COMPAT,TI_status(%rcx)
23405 - jmp retint_swapgs
23406 + pax_exit_kernel_user
23407 + pax_erase_kstack
23408 + jmp retint_swapgs_pax
23409
23410 /* Either reschedule or signal or syscall exit tracking needed. */
23411 /* First do a reschedule test. */
23412 @@ -811,7 +1295,7 @@ int_restore_rest:
23413 TRACE_IRQS_OFF
23414 jmp int_with_check
23415 CFI_ENDPROC
23416 -END(system_call)
23417 +ENDPROC(system_call)
23418
23419 .macro FORK_LIKE func
23420 ENTRY(stub_\func)
23421 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23422 DEFAULT_FRAME 0 8 /* offset 8: return address */
23423 call sys_\func
23424 RESTORE_TOP_OF_STACK %r11, 8
23425 - ret $REST_SKIP /* pop extended registers */
23426 + pax_force_retaddr
23427 + ret
23428 CFI_ENDPROC
23429 -END(stub_\func)
23430 +ENDPROC(stub_\func)
23431 .endm
23432
23433 .macro FIXED_FRAME label,func
23434 @@ -836,9 +1321,10 @@ ENTRY(\label)
23435 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23436 call \func
23437 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23438 + pax_force_retaddr
23439 ret
23440 CFI_ENDPROC
23441 -END(\label)
23442 +ENDPROC(\label)
23443 .endm
23444
23445 FORK_LIKE clone
23446 @@ -846,19 +1332,6 @@ END(\label)
23447 FORK_LIKE vfork
23448 FIXED_FRAME stub_iopl, sys_iopl
23449
23450 -ENTRY(ptregscall_common)
23451 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23452 - RESTORE_TOP_OF_STACK %r11, 8
23453 - movq_cfi_restore R15+8, r15
23454 - movq_cfi_restore R14+8, r14
23455 - movq_cfi_restore R13+8, r13
23456 - movq_cfi_restore R12+8, r12
23457 - movq_cfi_restore RBP+8, rbp
23458 - movq_cfi_restore RBX+8, rbx
23459 - ret $REST_SKIP /* pop extended registers */
23460 - CFI_ENDPROC
23461 -END(ptregscall_common)
23462 -
23463 ENTRY(stub_execve)
23464 CFI_STARTPROC
23465 addq $8, %rsp
23466 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23467 RESTORE_REST
23468 jmp int_ret_from_sys_call
23469 CFI_ENDPROC
23470 -END(stub_execve)
23471 +ENDPROC(stub_execve)
23472
23473 /*
23474 * sigreturn is special because it needs to restore all registers on return.
23475 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23476 RESTORE_REST
23477 jmp int_ret_from_sys_call
23478 CFI_ENDPROC
23479 -END(stub_rt_sigreturn)
23480 +ENDPROC(stub_rt_sigreturn)
23481
23482 #ifdef CONFIG_X86_X32_ABI
23483 ENTRY(stub_x32_rt_sigreturn)
23484 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23485 RESTORE_REST
23486 jmp int_ret_from_sys_call
23487 CFI_ENDPROC
23488 -END(stub_x32_rt_sigreturn)
23489 +ENDPROC(stub_x32_rt_sigreturn)
23490
23491 ENTRY(stub_x32_execve)
23492 CFI_STARTPROC
23493 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23494 RESTORE_REST
23495 jmp int_ret_from_sys_call
23496 CFI_ENDPROC
23497 -END(stub_x32_execve)
23498 +ENDPROC(stub_x32_execve)
23499
23500 #endif
23501
23502 @@ -952,7 +1425,7 @@ vector=vector+1
23503 2: jmp common_interrupt
23504 .endr
23505 CFI_ENDPROC
23506 -END(irq_entries_start)
23507 +ENDPROC(irq_entries_start)
23508
23509 .previous
23510 END(interrupt)
23511 @@ -969,8 +1442,8 @@ END(interrupt)
23512 /* 0(%rsp): ~(interrupt number) */
23513 .macro interrupt func
23514 /* reserve pt_regs for scratch regs and rbp */
23515 - subq $ORIG_RAX-RBP, %rsp
23516 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23517 + subq $ORIG_RAX, %rsp
23518 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23519 SAVE_ARGS_IRQ
23520 call \func
23521 .endm
23522 @@ -997,14 +1470,14 @@ ret_from_intr:
23523
23524 /* Restore saved previous stack */
23525 popq %rsi
23526 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23527 - leaq ARGOFFSET-RBP(%rsi), %rsp
23528 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23529 + movq %rsi, %rsp
23530 CFI_DEF_CFA_REGISTER rsp
23531 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23532 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23533
23534 exit_intr:
23535 GET_THREAD_INFO(%rcx)
23536 - testl $3,CS-ARGOFFSET(%rsp)
23537 + testb $3,CS-ARGOFFSET(%rsp)
23538 je retint_kernel
23539
23540 /* Interrupt came from user space */
23541 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23542 * The iretq could re-enable interrupts:
23543 */
23544 DISABLE_INTERRUPTS(CLBR_ANY)
23545 + pax_exit_kernel_user
23546 +retint_swapgs_pax:
23547 TRACE_IRQS_IRETQ
23548 SWAPGS
23549 jmp restore_args
23550
23551 retint_restore_args: /* return to kernel space */
23552 DISABLE_INTERRUPTS(CLBR_ANY)
23553 + pax_exit_kernel
23554 + pax_force_retaddr (RIP-ARGOFFSET)
23555 /*
23556 * The iretq could re-enable interrupts:
23557 */
23558 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23559 #endif
23560
23561 CFI_ENDPROC
23562 -END(common_interrupt)
23563 +ENDPROC(common_interrupt)
23564 /*
23565 * End of kprobes section
23566 */
23567 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23568 interrupt \do_sym
23569 jmp ret_from_intr
23570 CFI_ENDPROC
23571 -END(\sym)
23572 +ENDPROC(\sym)
23573 .endm
23574
23575 #ifdef CONFIG_TRACING
23576 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23577 call \do_sym
23578 jmp error_exit /* %ebx: no swapgs flag */
23579 CFI_ENDPROC
23580 -END(\sym)
23581 +ENDPROC(\sym)
23582 .endm
23583
23584 .macro paranoidzeroentry sym do_sym
23585 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23586 call \do_sym
23587 jmp paranoid_exit /* %ebx: no swapgs flag */
23588 CFI_ENDPROC
23589 -END(\sym)
23590 +ENDPROC(\sym)
23591 .endm
23592
23593 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23594 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23595 .macro paranoidzeroentry_ist sym do_sym ist
23596 ENTRY(\sym)
23597 INTR_FRAME
23598 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23599 TRACE_IRQS_OFF_DEBUG
23600 movq %rsp,%rdi /* pt_regs pointer */
23601 xorl %esi,%esi /* no error code */
23602 +#ifdef CONFIG_SMP
23603 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23604 + lea init_tss(%r13), %r13
23605 +#else
23606 + lea init_tss(%rip), %r13
23607 +#endif
23608 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23609 call \do_sym
23610 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23611 jmp paranoid_exit /* %ebx: no swapgs flag */
23612 CFI_ENDPROC
23613 -END(\sym)
23614 +ENDPROC(\sym)
23615 .endm
23616
23617 .macro errorentry sym do_sym
23618 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23619 call \do_sym
23620 jmp error_exit /* %ebx: no swapgs flag */
23621 CFI_ENDPROC
23622 -END(\sym)
23623 +ENDPROC(\sym)
23624 .endm
23625
23626 #ifdef CONFIG_TRACING
23627 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23628 call \do_sym
23629 jmp paranoid_exit /* %ebx: no swapgs flag */
23630 CFI_ENDPROC
23631 -END(\sym)
23632 +ENDPROC(\sym)
23633 .endm
23634
23635 zeroentry divide_error do_divide_error
23636 @@ -1336,9 +1819,10 @@ gs_change:
23637 2: mfence /* workaround */
23638 SWAPGS
23639 popfq_cfi
23640 + pax_force_retaddr
23641 ret
23642 CFI_ENDPROC
23643 -END(native_load_gs_index)
23644 +ENDPROC(native_load_gs_index)
23645
23646 _ASM_EXTABLE(gs_change,bad_gs)
23647 .section .fixup,"ax"
23648 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23649 CFI_DEF_CFA_REGISTER rsp
23650 CFI_ADJUST_CFA_OFFSET -8
23651 decl PER_CPU_VAR(irq_count)
23652 + pax_force_retaddr
23653 ret
23654 CFI_ENDPROC
23655 -END(do_softirq_own_stack)
23656 +ENDPROC(do_softirq_own_stack)
23657
23658 #ifdef CONFIG_XEN
23659 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23660 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23661 decl PER_CPU_VAR(irq_count)
23662 jmp error_exit
23663 CFI_ENDPROC
23664 -END(xen_do_hypervisor_callback)
23665 +ENDPROC(xen_do_hypervisor_callback)
23666
23667 /*
23668 * Hypervisor uses this for application faults while it executes.
23669 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23670 SAVE_ALL
23671 jmp error_exit
23672 CFI_ENDPROC
23673 -END(xen_failsafe_callback)
23674 +ENDPROC(xen_failsafe_callback)
23675
23676 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23677 xen_hvm_callback_vector xen_evtchn_do_upcall
23678 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23679 DEFAULT_FRAME
23680 DISABLE_INTERRUPTS(CLBR_NONE)
23681 TRACE_IRQS_OFF_DEBUG
23682 - testl %ebx,%ebx /* swapgs needed? */
23683 + testl $1,%ebx /* swapgs needed? */
23684 jnz paranoid_restore
23685 - testl $3,CS(%rsp)
23686 + testb $3,CS(%rsp)
23687 jnz paranoid_userspace
23688 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23689 + pax_exit_kernel
23690 + TRACE_IRQS_IRETQ 0
23691 + SWAPGS_UNSAFE_STACK
23692 + RESTORE_ALL 8
23693 + pax_force_retaddr_bts
23694 + jmp irq_return
23695 +#endif
23696 paranoid_swapgs:
23697 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23698 + pax_exit_kernel_user
23699 +#else
23700 + pax_exit_kernel
23701 +#endif
23702 TRACE_IRQS_IRETQ 0
23703 SWAPGS_UNSAFE_STACK
23704 RESTORE_ALL 8
23705 jmp irq_return
23706 paranoid_restore:
23707 + pax_exit_kernel
23708 TRACE_IRQS_IRETQ_DEBUG 0
23709 RESTORE_ALL 8
23710 + pax_force_retaddr_bts
23711 jmp irq_return
23712 paranoid_userspace:
23713 GET_THREAD_INFO(%rcx)
23714 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23715 TRACE_IRQS_OFF
23716 jmp paranoid_userspace
23717 CFI_ENDPROC
23718 -END(paranoid_exit)
23719 +ENDPROC(paranoid_exit)
23720
23721 /*
23722 * Exception entry point. This expects an error code/orig_rax on the stack.
23723 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23724 movq_cfi r14, R14+8
23725 movq_cfi r15, R15+8
23726 xorl %ebx,%ebx
23727 - testl $3,CS+8(%rsp)
23728 + testb $3,CS+8(%rsp)
23729 je error_kernelspace
23730 error_swapgs:
23731 SWAPGS
23732 error_sti:
23733 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23734 + testb $3, CS+8(%rsp)
23735 + jnz 1f
23736 + pax_enter_kernel
23737 + jmp 2f
23738 +1: pax_enter_kernel_user
23739 +2:
23740 +#else
23741 + pax_enter_kernel
23742 +#endif
23743 TRACE_IRQS_OFF
23744 + pax_force_retaddr
23745 ret
23746
23747 /*
23748 @@ -1616,7 +2127,7 @@ bstep_iret:
23749 movq %rcx,RIP+8(%rsp)
23750 jmp error_swapgs
23751 CFI_ENDPROC
23752 -END(error_entry)
23753 +ENDPROC(error_entry)
23754
23755
23756 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23757 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23758 DISABLE_INTERRUPTS(CLBR_NONE)
23759 TRACE_IRQS_OFF
23760 GET_THREAD_INFO(%rcx)
23761 - testl %eax,%eax
23762 + testl $1,%eax
23763 jne retint_kernel
23764 LOCKDEP_SYS_EXIT_IRQ
23765 movl TI_flags(%rcx),%edx
23766 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23767 jnz retint_careful
23768 jmp retint_swapgs
23769 CFI_ENDPROC
23770 -END(error_exit)
23771 +ENDPROC(error_exit)
23772
23773 /*
23774 * Test if a given stack is an NMI stack or not.
23775 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23776 * If %cs was not the kernel segment, then the NMI triggered in user
23777 * space, which means it is definitely not nested.
23778 */
23779 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23780 + je 1f
23781 cmpl $__KERNEL_CS, 16(%rsp)
23782 jne first_nmi
23783 -
23784 +1:
23785 /*
23786 * Check the special variable on the stack to see if NMIs are
23787 * executing.
23788 @@ -1730,8 +2243,7 @@ nested_nmi:
23789
23790 1:
23791 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23792 - leaq -1*8(%rsp), %rdx
23793 - movq %rdx, %rsp
23794 + subq $8, %rsp
23795 CFI_ADJUST_CFA_OFFSET 1*8
23796 leaq -10*8(%rsp), %rdx
23797 pushq_cfi $__KERNEL_DS
23798 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23799 CFI_RESTORE rdx
23800
23801 /* No need to check faults here */
23802 +# pax_force_retaddr_bts
23803 INTERRUPT_RETURN
23804
23805 CFI_RESTORE_STATE
23806 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23807 subq $ORIG_RAX-R15, %rsp
23808 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23809 /*
23810 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23811 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23812 * as we should not be calling schedule in NMI context.
23813 * Even with normal interrupts enabled. An NMI should not be
23814 * setting NEED_RESCHED or anything that normal interrupts and
23815 * exceptions might do.
23816 */
23817 - call save_paranoid
23818 + call save_paranoid_nmi
23819 DEFAULT_FRAME 0
23820
23821 /*
23822 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23823 * NMI itself takes a page fault, the page fault that was preempted
23824 * will read the information from the NMI page fault and not the
23825 * origin fault. Save it off and restore it if it changes.
23826 - * Use the r12 callee-saved register.
23827 + * Use the r13 callee-saved register.
23828 */
23829 - movq %cr2, %r12
23830 + movq %cr2, %r13
23831
23832 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23833 movq %rsp,%rdi
23834 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
23835
23836 /* Did the NMI take a page fault? Restore cr2 if it did */
23837 movq %cr2, %rcx
23838 - cmpq %rcx, %r12
23839 + cmpq %rcx, %r13
23840 je 1f
23841 - movq %r12, %cr2
23842 + movq %r13, %cr2
23843 1:
23844
23845 - testl %ebx,%ebx /* swapgs needed? */
23846 + testl $1,%ebx /* swapgs needed? */
23847 jnz nmi_restore
23848 nmi_swapgs:
23849 SWAPGS_UNSAFE_STACK
23850 nmi_restore:
23851 + pax_exit_kernel_nmi
23852 /* Pop the extra iret frame at once */
23853 RESTORE_ALL 6*8
23854 + testb $3, 8(%rsp)
23855 + jnz 1f
23856 + pax_force_retaddr_bts
23857 +1:
23858
23859 /* Clear the NMI executing stack variable */
23860 movq $0, 5*8(%rsp)
23861 jmp irq_return
23862 CFI_ENDPROC
23863 -END(nmi)
23864 +ENDPROC(nmi)
23865
23866 ENTRY(ignore_sysret)
23867 CFI_STARTPROC
23868 mov $-ENOSYS,%eax
23869 sysret
23870 CFI_ENDPROC
23871 -END(ignore_sysret)
23872 +ENDPROC(ignore_sysret)
23873
23874 /*
23875 * End of kprobes section
23876 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23877 index e625319..b9abb9d 100644
23878 --- a/arch/x86/kernel/ftrace.c
23879 +++ b/arch/x86/kernel/ftrace.c
23880 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23881 {
23882 unsigned char replaced[MCOUNT_INSN_SIZE];
23883
23884 + ip = ktla_ktva(ip);
23885 +
23886 /*
23887 * Note: Due to modules and __init, code can
23888 * disappear and change, we need to protect against faulting
23889 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23890 unsigned char old[MCOUNT_INSN_SIZE];
23891 int ret;
23892
23893 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23894 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23895
23896 ftrace_update_func = ip;
23897 /* Make sure the breakpoints see the ftrace_update_func update */
23898 @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23899 * kernel identity mapping to modify code.
23900 */
23901 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23902 - ip = (unsigned long)__va(__pa_symbol(ip));
23903 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23904
23905 return probe_kernel_write((void *)ip, val, size);
23906 }
23907 @@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
23908 unsigned char replaced[MCOUNT_INSN_SIZE];
23909 unsigned char brk = BREAKPOINT_INSTRUCTION;
23910
23911 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23912 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23913 return -EFAULT;
23914
23915 /* Make sure it is what we expect it to be */
23916 @@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23917 return ret;
23918
23919 fail_update:
23920 - probe_kernel_write((void *)ip, &old_code[0], 1);
23921 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23922 goto out;
23923 }
23924
23925 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23926 index 85126cc..1bbce17 100644
23927 --- a/arch/x86/kernel/head64.c
23928 +++ b/arch/x86/kernel/head64.c
23929 @@ -67,12 +67,12 @@ again:
23930 pgd = *pgd_p;
23931
23932 /*
23933 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23934 - * critical -- __PAGE_OFFSET would point us back into the dynamic
23935 + * The use of __early_va rather than __va here is critical:
23936 + * __va would point us back into the dynamic
23937 * range and we might end up looping forever...
23938 */
23939 if (pgd)
23940 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23941 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23942 else {
23943 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23944 reset_early_page_tables();
23945 @@ -82,13 +82,13 @@ again:
23946 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23947 for (i = 0; i < PTRS_PER_PUD; i++)
23948 pud_p[i] = 0;
23949 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23950 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23951 }
23952 pud_p += pud_index(address);
23953 pud = *pud_p;
23954
23955 if (pud)
23956 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23957 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23958 else {
23959 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23960 reset_early_page_tables();
23961 @@ -98,7 +98,7 @@ again:
23962 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
23963 for (i = 0; i < PTRS_PER_PMD; i++)
23964 pmd_p[i] = 0;
23965 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23966 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
23967 }
23968 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
23969 pmd_p[pmd_index(address)] = pmd;
23970 @@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
23971 if (console_loglevel == 10)
23972 early_printk("Kernel alive\n");
23973
23974 - clear_page(init_level4_pgt);
23975 /* set init_level4_pgt kernel high mapping*/
23976 init_level4_pgt[511] = early_level4_pgt[511];
23977
23978 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
23979 index f36bd42..56ee1534 100644
23980 --- a/arch/x86/kernel/head_32.S
23981 +++ b/arch/x86/kernel/head_32.S
23982 @@ -26,6 +26,12 @@
23983 /* Physical address */
23984 #define pa(X) ((X) - __PAGE_OFFSET)
23985
23986 +#ifdef CONFIG_PAX_KERNEXEC
23987 +#define ta(X) (X)
23988 +#else
23989 +#define ta(X) ((X) - __PAGE_OFFSET)
23990 +#endif
23991 +
23992 /*
23993 * References to members of the new_cpu_data structure.
23994 */
23995 @@ -55,11 +61,7 @@
23996 * and small than max_low_pfn, otherwise will waste some page table entries
23997 */
23998
23999 -#if PTRS_PER_PMD > 1
24000 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24001 -#else
24002 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24003 -#endif
24004 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24005
24006 /* Number of possible pages in the lowmem region */
24007 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24008 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24009 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24010
24011 /*
24012 + * Real beginning of normal "text" segment
24013 + */
24014 +ENTRY(stext)
24015 +ENTRY(_stext)
24016 +
24017 +/*
24018 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24019 * %esi points to the real-mode code as a 32-bit pointer.
24020 * CS and DS must be 4 GB flat segments, but we don't depend on
24021 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24022 * can.
24023 */
24024 __HEAD
24025 +
24026 +#ifdef CONFIG_PAX_KERNEXEC
24027 + jmp startup_32
24028 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24029 +.fill PAGE_SIZE-5,1,0xcc
24030 +#endif
24031 +
24032 ENTRY(startup_32)
24033 movl pa(stack_start),%ecx
24034
24035 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24036 2:
24037 leal -__PAGE_OFFSET(%ecx),%esp
24038
24039 +#ifdef CONFIG_SMP
24040 + movl $pa(cpu_gdt_table),%edi
24041 + movl $__per_cpu_load,%eax
24042 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24043 + rorl $16,%eax
24044 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24045 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24046 + movl $__per_cpu_end - 1,%eax
24047 + subl $__per_cpu_start,%eax
24048 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24049 +#endif
24050 +
24051 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24052 + movl $NR_CPUS,%ecx
24053 + movl $pa(cpu_gdt_table),%edi
24054 +1:
24055 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24056 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24057 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24058 + addl $PAGE_SIZE_asm,%edi
24059 + loop 1b
24060 +#endif
24061 +
24062 +#ifdef CONFIG_PAX_KERNEXEC
24063 + movl $pa(boot_gdt),%edi
24064 + movl $__LOAD_PHYSICAL_ADDR,%eax
24065 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24066 + rorl $16,%eax
24067 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24068 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24069 + rorl $16,%eax
24070 +
24071 + ljmp $(__BOOT_CS),$1f
24072 +1:
24073 +
24074 + movl $NR_CPUS,%ecx
24075 + movl $pa(cpu_gdt_table),%edi
24076 + addl $__PAGE_OFFSET,%eax
24077 +1:
24078 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24079 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24080 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24081 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24082 + rorl $16,%eax
24083 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24084 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24085 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24086 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24087 + rorl $16,%eax
24088 + addl $PAGE_SIZE_asm,%edi
24089 + loop 1b
24090 +#endif
24091 +
24092 /*
24093 * Clear BSS first so that there are no surprises...
24094 */
24095 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24096 movl %eax, pa(max_pfn_mapped)
24097
24098 /* Do early initialization of the fixmap area */
24099 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24100 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24101 +#ifdef CONFIG_COMPAT_VDSO
24102 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24103 +#else
24104 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24105 +#endif
24106 #else /* Not PAE */
24107
24108 page_pde_offset = (__PAGE_OFFSET >> 20);
24109 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24110 movl %eax, pa(max_pfn_mapped)
24111
24112 /* Do early initialization of the fixmap area */
24113 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24114 - movl %eax,pa(initial_page_table+0xffc)
24115 +#ifdef CONFIG_COMPAT_VDSO
24116 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24117 +#else
24118 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24119 +#endif
24120 #endif
24121
24122 #ifdef CONFIG_PARAVIRT
24123 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24124 cmpl $num_subarch_entries, %eax
24125 jae bad_subarch
24126
24127 - movl pa(subarch_entries)(,%eax,4), %eax
24128 - subl $__PAGE_OFFSET, %eax
24129 - jmp *%eax
24130 + jmp *pa(subarch_entries)(,%eax,4)
24131
24132 bad_subarch:
24133 WEAK(lguest_entry)
24134 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24135 __INITDATA
24136
24137 subarch_entries:
24138 - .long default_entry /* normal x86/PC */
24139 - .long lguest_entry /* lguest hypervisor */
24140 - .long xen_entry /* Xen hypervisor */
24141 - .long default_entry /* Moorestown MID */
24142 + .long ta(default_entry) /* normal x86/PC */
24143 + .long ta(lguest_entry) /* lguest hypervisor */
24144 + .long ta(xen_entry) /* Xen hypervisor */
24145 + .long ta(default_entry) /* Moorestown MID */
24146 num_subarch_entries = (. - subarch_entries) / 4
24147 .previous
24148 #else
24149 @@ -354,6 +426,7 @@ default_entry:
24150 movl pa(mmu_cr4_features),%eax
24151 movl %eax,%cr4
24152
24153 +#ifdef CONFIG_X86_PAE
24154 testb $X86_CR4_PAE, %al # check if PAE is enabled
24155 jz enable_paging
24156
24157 @@ -382,6 +455,9 @@ default_entry:
24158 /* Make changes effective */
24159 wrmsr
24160
24161 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24162 +#endif
24163 +
24164 enable_paging:
24165
24166 /*
24167 @@ -449,14 +525,20 @@ is486:
24168 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24169 movl %eax,%ss # after changing gdt.
24170
24171 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24172 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24173 movl %eax,%ds
24174 movl %eax,%es
24175
24176 movl $(__KERNEL_PERCPU), %eax
24177 movl %eax,%fs # set this cpu's percpu
24178
24179 +#ifdef CONFIG_CC_STACKPROTECTOR
24180 movl $(__KERNEL_STACK_CANARY),%eax
24181 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24182 + movl $(__USER_DS),%eax
24183 +#else
24184 + xorl %eax,%eax
24185 +#endif
24186 movl %eax,%gs
24187
24188 xorl %eax,%eax # Clear LDT
24189 @@ -512,8 +594,11 @@ setup_once:
24190 * relocation. Manually set base address in stack canary
24191 * segment descriptor.
24192 */
24193 - movl $gdt_page,%eax
24194 + movl $cpu_gdt_table,%eax
24195 movl $stack_canary,%ecx
24196 +#ifdef CONFIG_SMP
24197 + addl $__per_cpu_load,%ecx
24198 +#endif
24199 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24200 shrl $16, %ecx
24201 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24202 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24203 cmpl $2,(%esp) # X86_TRAP_NMI
24204 je is_nmi # Ignore NMI
24205
24206 - cmpl $2,%ss:early_recursion_flag
24207 + cmpl $1,%ss:early_recursion_flag
24208 je hlt_loop
24209 incl %ss:early_recursion_flag
24210
24211 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24212 pushl (20+6*4)(%esp) /* trapno */
24213 pushl $fault_msg
24214 call printk
24215 -#endif
24216 call dump_stack
24217 +#endif
24218 hlt_loop:
24219 hlt
24220 jmp hlt_loop
24221 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24222 /* This is the default interrupt "handler" :-) */
24223 ALIGN
24224 ignore_int:
24225 - cld
24226 #ifdef CONFIG_PRINTK
24227 + cmpl $2,%ss:early_recursion_flag
24228 + je hlt_loop
24229 + incl %ss:early_recursion_flag
24230 + cld
24231 pushl %eax
24232 pushl %ecx
24233 pushl %edx
24234 @@ -617,9 +705,6 @@ ignore_int:
24235 movl $(__KERNEL_DS),%eax
24236 movl %eax,%ds
24237 movl %eax,%es
24238 - cmpl $2,early_recursion_flag
24239 - je hlt_loop
24240 - incl early_recursion_flag
24241 pushl 16(%esp)
24242 pushl 24(%esp)
24243 pushl 32(%esp)
24244 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24245 /*
24246 * BSS section
24247 */
24248 -__PAGE_ALIGNED_BSS
24249 - .align PAGE_SIZE
24250 #ifdef CONFIG_X86_PAE
24251 +.section .initial_pg_pmd,"a",@progbits
24252 initial_pg_pmd:
24253 .fill 1024*KPMDS,4,0
24254 #else
24255 +.section .initial_page_table,"a",@progbits
24256 ENTRY(initial_page_table)
24257 .fill 1024,4,0
24258 #endif
24259 +.section .initial_pg_fixmap,"a",@progbits
24260 initial_pg_fixmap:
24261 .fill 1024,4,0
24262 +.section .empty_zero_page,"a",@progbits
24263 ENTRY(empty_zero_page)
24264 .fill 4096,1,0
24265 +.section .swapper_pg_dir,"a",@progbits
24266 ENTRY(swapper_pg_dir)
24267 +#ifdef CONFIG_X86_PAE
24268 + .fill 4,8,0
24269 +#else
24270 .fill 1024,4,0
24271 +#endif
24272
24273 /*
24274 * This starts the data section.
24275 */
24276 #ifdef CONFIG_X86_PAE
24277 -__PAGE_ALIGNED_DATA
24278 - /* Page-aligned for the benefit of paravirt? */
24279 - .align PAGE_SIZE
24280 +.section .initial_page_table,"a",@progbits
24281 ENTRY(initial_page_table)
24282 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24283 # if KPMDS == 3
24284 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24285 # error "Kernel PMDs should be 1, 2 or 3"
24286 # endif
24287 .align PAGE_SIZE /* needs to be page-sized too */
24288 +
24289 +#ifdef CONFIG_PAX_PER_CPU_PGD
24290 +ENTRY(cpu_pgd)
24291 + .rept 2*NR_CPUS
24292 + .fill 4,8,0
24293 + .endr
24294 +#endif
24295 +
24296 #endif
24297
24298 .data
24299 .balign 4
24300 ENTRY(stack_start)
24301 - .long init_thread_union+THREAD_SIZE
24302 + .long init_thread_union+THREAD_SIZE-8
24303
24304 __INITRODATA
24305 int_msg:
24306 @@ -727,7 +825,7 @@ fault_msg:
24307 * segment size, and 32-bit linear address value:
24308 */
24309
24310 - .data
24311 +.section .rodata,"a",@progbits
24312 .globl boot_gdt_descr
24313 .globl idt_descr
24314
24315 @@ -736,7 +834,7 @@ fault_msg:
24316 .word 0 # 32 bit align gdt_desc.address
24317 boot_gdt_descr:
24318 .word __BOOT_DS+7
24319 - .long boot_gdt - __PAGE_OFFSET
24320 + .long pa(boot_gdt)
24321
24322 .word 0 # 32-bit align idt_desc.address
24323 idt_descr:
24324 @@ -747,7 +845,7 @@ idt_descr:
24325 .word 0 # 32 bit align gdt_desc.address
24326 ENTRY(early_gdt_descr)
24327 .word GDT_ENTRIES*8-1
24328 - .long gdt_page /* Overwritten for secondary CPUs */
24329 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24330
24331 /*
24332 * The boot_gdt must mirror the equivalent in setup.S and is
24333 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24334 .align L1_CACHE_BYTES
24335 ENTRY(boot_gdt)
24336 .fill GDT_ENTRY_BOOT_CS,8,0
24337 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24338 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24339 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24340 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24341 +
24342 + .align PAGE_SIZE_asm
24343 +ENTRY(cpu_gdt_table)
24344 + .rept NR_CPUS
24345 + .quad 0x0000000000000000 /* NULL descriptor */
24346 + .quad 0x0000000000000000 /* 0x0b reserved */
24347 + .quad 0x0000000000000000 /* 0x13 reserved */
24348 + .quad 0x0000000000000000 /* 0x1b reserved */
24349 +
24350 +#ifdef CONFIG_PAX_KERNEXEC
24351 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24352 +#else
24353 + .quad 0x0000000000000000 /* 0x20 unused */
24354 +#endif
24355 +
24356 + .quad 0x0000000000000000 /* 0x28 unused */
24357 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24358 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24359 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24360 + .quad 0x0000000000000000 /* 0x4b reserved */
24361 + .quad 0x0000000000000000 /* 0x53 reserved */
24362 + .quad 0x0000000000000000 /* 0x5b reserved */
24363 +
24364 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24365 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24366 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24367 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24368 +
24369 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24370 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24371 +
24372 + /*
24373 + * Segments used for calling PnP BIOS have byte granularity.
24374 + * The code segments and data segments have fixed 64k limits,
24375 + * the transfer segment sizes are set at run time.
24376 + */
24377 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24378 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24379 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24380 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24381 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24382 +
24383 + /*
24384 + * The APM segments have byte granularity and their bases
24385 + * are set at run time. All have 64k limits.
24386 + */
24387 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24388 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24389 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24390 +
24391 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24392 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24393 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24394 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24395 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24396 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24397 +
24398 + /* Be sure this is zeroed to avoid false validations in Xen */
24399 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24400 + .endr
24401 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24402 index a468c0a..c7dec74 100644
24403 --- a/arch/x86/kernel/head_64.S
24404 +++ b/arch/x86/kernel/head_64.S
24405 @@ -20,6 +20,8 @@
24406 #include <asm/processor-flags.h>
24407 #include <asm/percpu.h>
24408 #include <asm/nops.h>
24409 +#include <asm/cpufeature.h>
24410 +#include <asm/alternative-asm.h>
24411
24412 #ifdef CONFIG_PARAVIRT
24413 #include <asm/asm-offsets.h>
24414 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24415 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24416 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24417 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24418 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24419 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24420 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24421 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24422 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24423 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24424
24425 .text
24426 __HEAD
24427 @@ -89,11 +97,24 @@ startup_64:
24428 * Fixup the physical addresses in the page table
24429 */
24430 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24431 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24432 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24433 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24434 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24435 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24436
24437 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24438 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24439 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24440 +#ifndef CONFIG_XEN
24441 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24442 +#endif
24443 +
24444 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24445 +
24446 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24447 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24448
24449 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24450 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24451
24452 /*
24453 * Set up the identity mapping for the switchover. These
24454 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24455 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24456 1:
24457
24458 - /* Enable PAE mode and PGE */
24459 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24460 + /* Enable PAE mode and PSE/PGE */
24461 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24462 movq %rcx, %cr4
24463
24464 /* Setup early boot stage 4 level pagetables. */
24465 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24466 movl $MSR_EFER, %ecx
24467 rdmsr
24468 btsl $_EFER_SCE, %eax /* Enable System Call */
24469 - btl $20,%edi /* No Execute supported? */
24470 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24471 jnc 1f
24472 btsl $_EFER_NX, %eax
24473 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24474 +#ifndef CONFIG_EFI
24475 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24476 +#endif
24477 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24478 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24479 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24480 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24481 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24482 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24483 1: wrmsr /* Make changes effective */
24484
24485 /* Setup cr0 */
24486 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24487 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24488 * address given in m16:64.
24489 */
24490 + pax_set_fptr_mask
24491 movq initial_code(%rip),%rax
24492 pushq $0 # fake return address to stop unwinder
24493 pushq $__KERNEL_CS # set correct cs
24494 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24495 .quad INIT_PER_CPU_VAR(irq_stack_union)
24496
24497 GLOBAL(stack_start)
24498 - .quad init_thread_union+THREAD_SIZE-8
24499 + .quad init_thread_union+THREAD_SIZE-16
24500 .word 0
24501 __FINITDATA
24502
24503 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24504 call dump_stack
24505 #ifdef CONFIG_KALLSYMS
24506 leaq early_idt_ripmsg(%rip),%rdi
24507 - movq 40(%rsp),%rsi # %rip again
24508 + movq 88(%rsp),%rsi # %rip again
24509 call __print_symbol
24510 #endif
24511 #endif /* EARLY_PRINTK */
24512 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24513 early_recursion_flag:
24514 .long 0
24515
24516 + .section .rodata,"a",@progbits
24517 #ifdef CONFIG_EARLY_PRINTK
24518 early_idt_msg:
24519 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24520 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24521 NEXT_PAGE(early_dynamic_pgts)
24522 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24523
24524 - .data
24525 + .section .rodata,"a",@progbits
24526
24527 -#ifndef CONFIG_XEN
24528 NEXT_PAGE(init_level4_pgt)
24529 - .fill 512,8,0
24530 -#else
24531 -NEXT_PAGE(init_level4_pgt)
24532 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24533 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24534 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24535 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24536 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24537 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24538 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24539 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24540 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24541 .org init_level4_pgt + L4_START_KERNEL*8, 0
24542 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24543 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24544
24545 +#ifdef CONFIG_PAX_PER_CPU_PGD
24546 +NEXT_PAGE(cpu_pgd)
24547 + .rept 2*NR_CPUS
24548 + .fill 512,8,0
24549 + .endr
24550 +#endif
24551 +
24552 NEXT_PAGE(level3_ident_pgt)
24553 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24554 +#ifdef CONFIG_XEN
24555 .fill 511, 8, 0
24556 +#else
24557 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24558 + .fill 510,8,0
24559 +#endif
24560 +
24561 +NEXT_PAGE(level3_vmalloc_start_pgt)
24562 + .fill 512,8,0
24563 +
24564 +NEXT_PAGE(level3_vmalloc_end_pgt)
24565 + .fill 512,8,0
24566 +
24567 +NEXT_PAGE(level3_vmemmap_pgt)
24568 + .fill L3_VMEMMAP_START,8,0
24569 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24570 +
24571 NEXT_PAGE(level2_ident_pgt)
24572 - /* Since I easily can, map the first 1G.
24573 + /* Since I easily can, map the first 2G.
24574 * Don't set NX because code runs from these pages.
24575 */
24576 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24577 -#endif
24578 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24579
24580 NEXT_PAGE(level3_kernel_pgt)
24581 .fill L3_START_KERNEL,8,0
24582 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24583 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24584 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24585
24586 +NEXT_PAGE(level2_vmemmap_pgt)
24587 + .fill 512,8,0
24588 +
24589 NEXT_PAGE(level2_kernel_pgt)
24590 /*
24591 * 512 MB kernel mapping. We spend a full page on this pagetable
24592 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24593 NEXT_PAGE(level2_fixmap_pgt)
24594 .fill 506,8,0
24595 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24596 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24597 - .fill 5,8,0
24598 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24599 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24600 + .fill 4,8,0
24601
24602 NEXT_PAGE(level1_fixmap_pgt)
24603 .fill 512,8,0
24604
24605 +NEXT_PAGE(level1_vsyscall_pgt)
24606 + .fill 512,8,0
24607 +
24608 #undef PMDS
24609
24610 - .data
24611 + .align PAGE_SIZE
24612 +ENTRY(cpu_gdt_table)
24613 + .rept NR_CPUS
24614 + .quad 0x0000000000000000 /* NULL descriptor */
24615 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24616 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24617 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24618 + .quad 0x00cffb000000ffff /* __USER32_CS */
24619 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24620 + .quad 0x00affb000000ffff /* __USER_CS */
24621 +
24622 +#ifdef CONFIG_PAX_KERNEXEC
24623 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24624 +#else
24625 + .quad 0x0 /* unused */
24626 +#endif
24627 +
24628 + .quad 0,0 /* TSS */
24629 + .quad 0,0 /* LDT */
24630 + .quad 0,0,0 /* three TLS descriptors */
24631 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24632 + /* asm/segment.h:GDT_ENTRIES must match this */
24633 +
24634 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24635 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24636 +#else
24637 + .quad 0x0 /* unused */
24638 +#endif
24639 +
24640 + /* zero the remaining page */
24641 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24642 + .endr
24643 +
24644 .align 16
24645 .globl early_gdt_descr
24646 early_gdt_descr:
24647 .word GDT_ENTRIES*8-1
24648 early_gdt_descr_base:
24649 - .quad INIT_PER_CPU_VAR(gdt_page)
24650 + .quad cpu_gdt_table
24651
24652 ENTRY(phys_base)
24653 /* This must match the first entry in level2_kernel_pgt */
24654 .quad 0x0000000000000000
24655
24656 #include "../../x86/xen/xen-head.S"
24657 -
24658 - __PAGE_ALIGNED_BSS
24659 +
24660 + .section .rodata,"a",@progbits
24661 NEXT_PAGE(empty_zero_page)
24662 .skip PAGE_SIZE
24663 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24664 index 05fd74f..c3548b1 100644
24665 --- a/arch/x86/kernel/i386_ksyms_32.c
24666 +++ b/arch/x86/kernel/i386_ksyms_32.c
24667 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24668 EXPORT_SYMBOL(cmpxchg8b_emu);
24669 #endif
24670
24671 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24672 +
24673 /* Networking helper routines. */
24674 EXPORT_SYMBOL(csum_partial_copy_generic);
24675 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24676 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24677
24678 EXPORT_SYMBOL(__get_user_1);
24679 EXPORT_SYMBOL(__get_user_2);
24680 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24681 EXPORT_SYMBOL(___preempt_schedule_context);
24682 #endif
24683 #endif
24684 +
24685 +#ifdef CONFIG_PAX_KERNEXEC
24686 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24687 +#endif
24688 +
24689 +#ifdef CONFIG_PAX_PER_CPU_PGD
24690 +EXPORT_SYMBOL(cpu_pgd);
24691 +#endif
24692 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24693 index d5dd808..b6432cf 100644
24694 --- a/arch/x86/kernel/i387.c
24695 +++ b/arch/x86/kernel/i387.c
24696 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24697 static inline bool interrupted_user_mode(void)
24698 {
24699 struct pt_regs *regs = get_irq_regs();
24700 - return regs && user_mode_vm(regs);
24701 + return regs && user_mode(regs);
24702 }
24703
24704 /*
24705 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24706 index 2e977b5..5f2c273 100644
24707 --- a/arch/x86/kernel/i8259.c
24708 +++ b/arch/x86/kernel/i8259.c
24709 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24710 static void make_8259A_irq(unsigned int irq)
24711 {
24712 disable_irq_nosync(irq);
24713 - io_apic_irqs &= ~(1<<irq);
24714 + io_apic_irqs &= ~(1UL<<irq);
24715 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24716 i8259A_chip.name);
24717 enable_irq(irq);
24718 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24719 "spurious 8259A interrupt: IRQ%d.\n", irq);
24720 spurious_irq_mask |= irqmask;
24721 }
24722 - atomic_inc(&irq_err_count);
24723 + atomic_inc_unchecked(&irq_err_count);
24724 /*
24725 * Theoretically we do not have to handle this IRQ,
24726 * but in Linux this does not cause problems and is
24727 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24728 /* (slave's support for AEOI in flat mode is to be investigated) */
24729 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24730
24731 + pax_open_kernel();
24732 if (auto_eoi)
24733 /*
24734 * In AEOI mode we just have to mask the interrupt
24735 * when acking.
24736 */
24737 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24738 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24739 else
24740 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24741 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24742 + pax_close_kernel();
24743
24744 udelay(100); /* wait for 8259A to initialize */
24745
24746 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24747 index a979b5b..1d6db75 100644
24748 --- a/arch/x86/kernel/io_delay.c
24749 +++ b/arch/x86/kernel/io_delay.c
24750 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24751 * Quirk table for systems that misbehave (lock up, etc.) if port
24752 * 0x80 is used:
24753 */
24754 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24755 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24756 {
24757 .callback = dmi_io_delay_0xed_port,
24758 .ident = "Compaq Presario V6000",
24759 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24760 index 4ddaf66..49d5c18 100644
24761 --- a/arch/x86/kernel/ioport.c
24762 +++ b/arch/x86/kernel/ioport.c
24763 @@ -6,6 +6,7 @@
24764 #include <linux/sched.h>
24765 #include <linux/kernel.h>
24766 #include <linux/capability.h>
24767 +#include <linux/security.h>
24768 #include <linux/errno.h>
24769 #include <linux/types.h>
24770 #include <linux/ioport.h>
24771 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24772 return -EINVAL;
24773 if (turn_on && !capable(CAP_SYS_RAWIO))
24774 return -EPERM;
24775 +#ifdef CONFIG_GRKERNSEC_IO
24776 + if (turn_on && grsec_disable_privio) {
24777 + gr_handle_ioperm();
24778 + return -ENODEV;
24779 + }
24780 +#endif
24781
24782 /*
24783 * If it's the first ioperm() call in this thread's lifetime, set the
24784 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24785 * because the ->io_bitmap_max value must match the bitmap
24786 * contents:
24787 */
24788 - tss = &per_cpu(init_tss, get_cpu());
24789 + tss = init_tss + get_cpu();
24790
24791 if (turn_on)
24792 bitmap_clear(t->io_bitmap_ptr, from, num);
24793 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24794 if (level > old) {
24795 if (!capable(CAP_SYS_RAWIO))
24796 return -EPERM;
24797 +#ifdef CONFIG_GRKERNSEC_IO
24798 + if (grsec_disable_privio) {
24799 + gr_handle_iopl();
24800 + return -ENODEV;
24801 + }
24802 +#endif
24803 }
24804 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24805 t->iopl = level << 12;
24806 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24807 index d99f31d..1c0f466 100644
24808 --- a/arch/x86/kernel/irq.c
24809 +++ b/arch/x86/kernel/irq.c
24810 @@ -21,7 +21,7 @@
24811 #define CREATE_TRACE_POINTS
24812 #include <asm/trace/irq_vectors.h>
24813
24814 -atomic_t irq_err_count;
24815 +atomic_unchecked_t irq_err_count;
24816
24817 /* Function pointer for generic interrupt vector handling */
24818 void (*x86_platform_ipi_callback)(void) = NULL;
24819 @@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24820 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24821 seq_printf(p, " Machine check polls\n");
24822 #endif
24823 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24824 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24825 #if defined(CONFIG_X86_IO_APIC)
24826 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24827 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24828 #endif
24829 return 0;
24830 }
24831 @@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24832
24833 u64 arch_irq_stat(void)
24834 {
24835 - u64 sum = atomic_read(&irq_err_count);
24836 + u64 sum = atomic_read_unchecked(&irq_err_count);
24837 return sum;
24838 }
24839
24840 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24841 index d7fcbed..1f747f7 100644
24842 --- a/arch/x86/kernel/irq_32.c
24843 +++ b/arch/x86/kernel/irq_32.c
24844 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24845 __asm__ __volatile__("andl %%esp,%0" :
24846 "=r" (sp) : "0" (THREAD_SIZE - 1));
24847
24848 - return sp < (sizeof(struct thread_info) + STACK_WARN);
24849 + return sp < STACK_WARN;
24850 }
24851
24852 static void print_stack_overflow(void)
24853 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24854 * per-CPU IRQ handling contexts (thread information and stack)
24855 */
24856 union irq_ctx {
24857 - struct thread_info tinfo;
24858 - u32 stack[THREAD_SIZE/sizeof(u32)];
24859 + unsigned long previous_esp;
24860 + u32 stack[THREAD_SIZE/sizeof(u32)];
24861 } __attribute__((aligned(THREAD_SIZE)));
24862
24863 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24864 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24865 static inline int
24866 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24867 {
24868 - union irq_ctx *curctx, *irqctx;
24869 + union irq_ctx *irqctx;
24870 u32 *isp, arg1, arg2;
24871
24872 - curctx = (union irq_ctx *) current_thread_info();
24873 irqctx = __this_cpu_read(hardirq_ctx);
24874
24875 /*
24876 @@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24877 * handler) we can't do that and just have to keep using the
24878 * current stack (which is the irq stack already after all)
24879 */
24880 - if (unlikely(curctx == irqctx))
24881 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24882 return 0;
24883
24884 /* build the stack frame on the IRQ stack */
24885 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24886 - irqctx->tinfo.task = curctx->tinfo.task;
24887 - irqctx->tinfo.previous_esp = current_stack_pointer;
24888 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24889 + irqctx->previous_esp = current_stack_pointer;
24890 +
24891 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24892 + __set_fs(MAKE_MM_SEG(0));
24893 +#endif
24894
24895 if (unlikely(overflow))
24896 call_on_stack(print_stack_overflow, isp);
24897 @@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24898 : "0" (irq), "1" (desc), "2" (isp),
24899 "D" (desc->handle_irq)
24900 : "memory", "cc", "ecx");
24901 +
24902 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24903 + __set_fs(current_thread_info()->addr_limit);
24904 +#endif
24905 +
24906 return 1;
24907 }
24908
24909 @@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24910 */
24911 void irq_ctx_init(int cpu)
24912 {
24913 - union irq_ctx *irqctx;
24914 -
24915 if (per_cpu(hardirq_ctx, cpu))
24916 return;
24917
24918 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24919 - THREADINFO_GFP,
24920 - THREAD_SIZE_ORDER));
24921 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24922 - irqctx->tinfo.cpu = cpu;
24923 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24924 -
24925 - per_cpu(hardirq_ctx, cpu) = irqctx;
24926 -
24927 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24928 - THREADINFO_GFP,
24929 - THREAD_SIZE_ORDER));
24930 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24931 - irqctx->tinfo.cpu = cpu;
24932 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24933 -
24934 - per_cpu(softirq_ctx, cpu) = irqctx;
24935 -
24936 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24937 - cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24938 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24939 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24940 }
24941
24942 void do_softirq_own_stack(void)
24943 {
24944 - struct thread_info *curctx;
24945 union irq_ctx *irqctx;
24946 u32 *isp;
24947
24948 - curctx = current_thread_info();
24949 irqctx = __this_cpu_read(softirq_ctx);
24950 - irqctx->tinfo.task = curctx->task;
24951 - irqctx->tinfo.previous_esp = current_stack_pointer;
24952 + irqctx->previous_esp = current_stack_pointer;
24953
24954 /* build the stack frame on the softirq stack */
24955 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24956 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24957 +
24958 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24959 + __set_fs(MAKE_MM_SEG(0));
24960 +#endif
24961
24962 call_on_stack(__do_softirq, isp);
24963 +
24964 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24965 + __set_fs(current_thread_info()->addr_limit);
24966 +#endif
24967 +
24968 }
24969
24970 bool handle_irq(unsigned irq, struct pt_regs *regs)
24971 @@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
24972 if (unlikely(!desc))
24973 return false;
24974
24975 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24976 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24977 if (unlikely(overflow))
24978 print_stack_overflow();
24979 desc->handle_irq(irq, desc);
24980 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
24981 index 4d1c746..232961d 100644
24982 --- a/arch/x86/kernel/irq_64.c
24983 +++ b/arch/x86/kernel/irq_64.c
24984 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
24985 u64 estack_top, estack_bottom;
24986 u64 curbase = (u64)task_stack_page(current);
24987
24988 - if (user_mode_vm(regs))
24989 + if (user_mode(regs))
24990 return;
24991
24992 if (regs->sp >= curbase + sizeof(struct thread_info) +
24993 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
24994 index 26d5a55..a01160a 100644
24995 --- a/arch/x86/kernel/jump_label.c
24996 +++ b/arch/x86/kernel/jump_label.c
24997 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24998 * Jump label is enabled for the first time.
24999 * So we expect a default_nop...
25000 */
25001 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25002 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25003 != 0))
25004 bug_at((void *)entry->code, __LINE__);
25005 } else {
25006 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25007 * ...otherwise expect an ideal_nop. Otherwise
25008 * something went horribly wrong.
25009 */
25010 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25011 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25012 != 0))
25013 bug_at((void *)entry->code, __LINE__);
25014 }
25015 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25016 * are converting the default nop to the ideal nop.
25017 */
25018 if (init) {
25019 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25020 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25021 bug_at((void *)entry->code, __LINE__);
25022 } else {
25023 code.jump = 0xe9;
25024 code.offset = entry->target -
25025 (entry->code + JUMP_LABEL_NOP_SIZE);
25026 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25027 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25028 bug_at((void *)entry->code, __LINE__);
25029 }
25030 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25031 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25032 index 7ec1d5f..5a7d130 100644
25033 --- a/arch/x86/kernel/kgdb.c
25034 +++ b/arch/x86/kernel/kgdb.c
25035 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25036 #ifdef CONFIG_X86_32
25037 switch (regno) {
25038 case GDB_SS:
25039 - if (!user_mode_vm(regs))
25040 + if (!user_mode(regs))
25041 *(unsigned long *)mem = __KERNEL_DS;
25042 break;
25043 case GDB_SP:
25044 - if (!user_mode_vm(regs))
25045 + if (!user_mode(regs))
25046 *(unsigned long *)mem = kernel_stack_pointer(regs);
25047 break;
25048 case GDB_GS:
25049 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25050 bp->attr.bp_addr = breakinfo[breakno].addr;
25051 bp->attr.bp_len = breakinfo[breakno].len;
25052 bp->attr.bp_type = breakinfo[breakno].type;
25053 - info->address = breakinfo[breakno].addr;
25054 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25055 + info->address = ktla_ktva(breakinfo[breakno].addr);
25056 + else
25057 + info->address = breakinfo[breakno].addr;
25058 info->len = breakinfo[breakno].len;
25059 info->type = breakinfo[breakno].type;
25060 val = arch_install_hw_breakpoint(bp);
25061 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25062 case 'k':
25063 /* clear the trace bit */
25064 linux_regs->flags &= ~X86_EFLAGS_TF;
25065 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25066 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25067
25068 /* set the trace bit if we're stepping */
25069 if (remcomInBuffer[0] == 's') {
25070 linux_regs->flags |= X86_EFLAGS_TF;
25071 - atomic_set(&kgdb_cpu_doing_single_step,
25072 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25073 raw_smp_processor_id());
25074 }
25075
25076 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25077
25078 switch (cmd) {
25079 case DIE_DEBUG:
25080 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25081 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25082 if (user_mode(regs))
25083 return single_step_cont(regs, args);
25084 break;
25085 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25086 #endif /* CONFIG_DEBUG_RODATA */
25087
25088 bpt->type = BP_BREAKPOINT;
25089 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25090 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25091 BREAK_INSTR_SIZE);
25092 if (err)
25093 return err;
25094 - err = probe_kernel_write((char *)bpt->bpt_addr,
25095 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25096 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25097 #ifdef CONFIG_DEBUG_RODATA
25098 if (!err)
25099 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25100 return -EBUSY;
25101 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25102 BREAK_INSTR_SIZE);
25103 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25104 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25105 if (err)
25106 return err;
25107 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25108 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25109 if (mutex_is_locked(&text_mutex))
25110 goto knl_write;
25111 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25112 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25113 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25114 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25115 goto knl_write;
25116 return err;
25117 knl_write:
25118 #endif /* CONFIG_DEBUG_RODATA */
25119 - return probe_kernel_write((char *)bpt->bpt_addr,
25120 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25121 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25122 }
25123
25124 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25125 index 79a3f96..6ba030a 100644
25126 --- a/arch/x86/kernel/kprobes/core.c
25127 +++ b/arch/x86/kernel/kprobes/core.c
25128 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25129 s32 raddr;
25130 } __packed *insn;
25131
25132 - insn = (struct __arch_relative_insn *)from;
25133 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25134 +
25135 + pax_open_kernel();
25136 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25137 insn->op = op;
25138 + pax_close_kernel();
25139 }
25140
25141 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25142 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25143 kprobe_opcode_t opcode;
25144 kprobe_opcode_t *orig_opcodes = opcodes;
25145
25146 - if (search_exception_tables((unsigned long)opcodes))
25147 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25148 return 0; /* Page fault may occur on this address. */
25149
25150 retry:
25151 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25152 * for the first byte, we can recover the original instruction
25153 * from it and kp->opcode.
25154 */
25155 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25156 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25157 buf[0] = kp->opcode;
25158 - return (unsigned long)buf;
25159 + return ktva_ktla((unsigned long)buf);
25160 }
25161
25162 /*
25163 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25164 /* Another subsystem puts a breakpoint, failed to recover */
25165 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25166 return 0;
25167 + pax_open_kernel();
25168 memcpy(dest, insn.kaddr, insn.length);
25169 + pax_close_kernel();
25170
25171 #ifdef CONFIG_X86_64
25172 if (insn_rip_relative(&insn)) {
25173 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25174 return 0;
25175 }
25176 disp = (u8 *) dest + insn_offset_displacement(&insn);
25177 + pax_open_kernel();
25178 *(s32 *) disp = (s32) newdisp;
25179 + pax_close_kernel();
25180 }
25181 #endif
25182 return insn.length;
25183 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25184 * nor set current_kprobe, because it doesn't use single
25185 * stepping.
25186 */
25187 - regs->ip = (unsigned long)p->ainsn.insn;
25188 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25189 preempt_enable_no_resched();
25190 return;
25191 }
25192 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25193 regs->flags &= ~X86_EFLAGS_IF;
25194 /* single step inline if the instruction is an int3 */
25195 if (p->opcode == BREAKPOINT_INSTRUCTION)
25196 - regs->ip = (unsigned long)p->addr;
25197 + regs->ip = ktla_ktva((unsigned long)p->addr);
25198 else
25199 - regs->ip = (unsigned long)p->ainsn.insn;
25200 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25201 }
25202
25203 /*
25204 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25205 setup_singlestep(p, regs, kcb, 0);
25206 return 1;
25207 }
25208 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25209 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25210 /*
25211 * The breakpoint instruction was removed right
25212 * after we hit it. Another cpu has removed
25213 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25214 " movq %rax, 152(%rsp)\n"
25215 RESTORE_REGS_STRING
25216 " popfq\n"
25217 +#ifdef KERNEXEC_PLUGIN
25218 + " btsq $63,(%rsp)\n"
25219 +#endif
25220 #else
25221 " pushf\n"
25222 SAVE_REGS_STRING
25223 @@ -779,7 +789,7 @@ static void __kprobes
25224 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25225 {
25226 unsigned long *tos = stack_addr(regs);
25227 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25228 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25229 unsigned long orig_ip = (unsigned long)p->addr;
25230 kprobe_opcode_t *insn = p->ainsn.insn;
25231
25232 @@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25233 struct die_args *args = data;
25234 int ret = NOTIFY_DONE;
25235
25236 - if (args->regs && user_mode_vm(args->regs))
25237 + if (args->regs && user_mode(args->regs))
25238 return ret;
25239
25240 switch (val) {
25241 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25242 index 898160b..758cde8 100644
25243 --- a/arch/x86/kernel/kprobes/opt.c
25244 +++ b/arch/x86/kernel/kprobes/opt.c
25245 @@ -79,6 +79,7 @@ found:
25246 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25247 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25248 {
25249 + pax_open_kernel();
25250 #ifdef CONFIG_X86_64
25251 *addr++ = 0x48;
25252 *addr++ = 0xbf;
25253 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25254 *addr++ = 0xb8;
25255 #endif
25256 *(unsigned long *)addr = val;
25257 + pax_close_kernel();
25258 }
25259
25260 asm (
25261 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25262 * Verify if the address gap is in 2GB range, because this uses
25263 * a relative jump.
25264 */
25265 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25266 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25267 if (abs(rel) > 0x7fffffff)
25268 return -ERANGE;
25269
25270 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25271 op->optinsn.size = ret;
25272
25273 /* Copy arch-dep-instance from template */
25274 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25275 + pax_open_kernel();
25276 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25277 + pax_close_kernel();
25278
25279 /* Set probe information */
25280 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25281
25282 /* Set probe function call */
25283 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25284 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25285
25286 /* Set returning jmp instruction at the tail of out-of-line buffer */
25287 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25288 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25289 (u8 *)op->kp.addr + op->optinsn.size);
25290
25291 flush_icache_range((unsigned long) buf,
25292 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25293 WARN_ON(kprobe_disabled(&op->kp));
25294
25295 /* Backup instructions which will be replaced by jump address */
25296 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25297 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25298 RELATIVE_ADDR_SIZE);
25299
25300 insn_buf[0] = RELATIVEJUMP_OPCODE;
25301 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25302 /* This kprobe is really able to run optimized path. */
25303 op = container_of(p, struct optimized_kprobe, kp);
25304 /* Detour through copied instructions */
25305 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25306 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25307 if (!reenter)
25308 reset_current_kprobe();
25309 preempt_enable_no_resched();
25310 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25311 index c2bedae..25e7ab6 100644
25312 --- a/arch/x86/kernel/ksysfs.c
25313 +++ b/arch/x86/kernel/ksysfs.c
25314 @@ -184,7 +184,7 @@ out:
25315
25316 static struct kobj_attribute type_attr = __ATTR_RO(type);
25317
25318 -static struct bin_attribute data_attr = {
25319 +static bin_attribute_no_const data_attr __read_only = {
25320 .attr = {
25321 .name = "data",
25322 .mode = S_IRUGO,
25323 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25324 index ebc9873..37b8776 100644
25325 --- a/arch/x86/kernel/ldt.c
25326 +++ b/arch/x86/kernel/ldt.c
25327 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25328 if (reload) {
25329 #ifdef CONFIG_SMP
25330 preempt_disable();
25331 - load_LDT(pc);
25332 + load_LDT_nolock(pc);
25333 if (!cpumask_equal(mm_cpumask(current->mm),
25334 cpumask_of(smp_processor_id())))
25335 smp_call_function(flush_ldt, current->mm, 1);
25336 preempt_enable();
25337 #else
25338 - load_LDT(pc);
25339 + load_LDT_nolock(pc);
25340 #endif
25341 }
25342 if (oldsize) {
25343 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25344 return err;
25345
25346 for (i = 0; i < old->size; i++)
25347 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25348 + write_ldt_entry(new->ldt, i, old->ldt + i);
25349 return 0;
25350 }
25351
25352 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25353 retval = copy_ldt(&mm->context, &old_mm->context);
25354 mutex_unlock(&old_mm->context.lock);
25355 }
25356 +
25357 + if (tsk == current) {
25358 + mm->context.vdso = 0;
25359 +
25360 +#ifdef CONFIG_X86_32
25361 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25362 + mm->context.user_cs_base = 0UL;
25363 + mm->context.user_cs_limit = ~0UL;
25364 +
25365 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25366 + cpus_clear(mm->context.cpu_user_cs_mask);
25367 +#endif
25368 +
25369 +#endif
25370 +#endif
25371 +
25372 + }
25373 +
25374 return retval;
25375 }
25376
25377 @@ -229,6 +247,24 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25378 }
25379 }
25380
25381 +#ifdef CONFIG_PAX_SEGMEXEC
25382 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25383 + error = -EINVAL;
25384 + goto out_unlock;
25385 + }
25386 +#endif
25387 +
25388 + /*
25389 + * On x86-64 we do not support 16-bit segments due to
25390 + * IRET leaking the high bits of the kernel stack address.
25391 + */
25392 +#ifdef CONFIG_X86_64
25393 + if (!ldt_info.seg_32bit) {
25394 + error = -EINVAL;
25395 + goto out_unlock;
25396 + }
25397 +#endif
25398 +
25399 fill_ldt(&ldt, &ldt_info);
25400 if (oldmode)
25401 ldt.avl = 0;
25402 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25403 index 1667b1d..16492c5 100644
25404 --- a/arch/x86/kernel/machine_kexec_32.c
25405 +++ b/arch/x86/kernel/machine_kexec_32.c
25406 @@ -25,7 +25,7 @@
25407 #include <asm/cacheflush.h>
25408 #include <asm/debugreg.h>
25409
25410 -static void set_idt(void *newidt, __u16 limit)
25411 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25412 {
25413 struct desc_ptr curidt;
25414
25415 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25416 }
25417
25418
25419 -static void set_gdt(void *newgdt, __u16 limit)
25420 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25421 {
25422 struct desc_ptr curgdt;
25423
25424 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25425 }
25426
25427 control_page = page_address(image->control_code_page);
25428 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25429 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25430
25431 relocate_kernel_ptr = control_page;
25432 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25433 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25434 index 18be189..4a9fe40 100644
25435 --- a/arch/x86/kernel/module.c
25436 +++ b/arch/x86/kernel/module.c
25437 @@ -43,15 +43,60 @@ do { \
25438 } while (0)
25439 #endif
25440
25441 -void *module_alloc(unsigned long size)
25442 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25443 {
25444 - if (PAGE_ALIGN(size) > MODULES_LEN)
25445 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25446 return NULL;
25447 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25448 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25449 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25450 NUMA_NO_NODE, __builtin_return_address(0));
25451 }
25452
25453 +void *module_alloc(unsigned long size)
25454 +{
25455 +
25456 +#ifdef CONFIG_PAX_KERNEXEC
25457 + return __module_alloc(size, PAGE_KERNEL);
25458 +#else
25459 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25460 +#endif
25461 +
25462 +}
25463 +
25464 +#ifdef CONFIG_PAX_KERNEXEC
25465 +#ifdef CONFIG_X86_32
25466 +void *module_alloc_exec(unsigned long size)
25467 +{
25468 + struct vm_struct *area;
25469 +
25470 + if (size == 0)
25471 + return NULL;
25472 +
25473 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25474 + return area ? area->addr : NULL;
25475 +}
25476 +EXPORT_SYMBOL(module_alloc_exec);
25477 +
25478 +void module_free_exec(struct module *mod, void *module_region)
25479 +{
25480 + vunmap(module_region);
25481 +}
25482 +EXPORT_SYMBOL(module_free_exec);
25483 +#else
25484 +void module_free_exec(struct module *mod, void *module_region)
25485 +{
25486 + module_free(mod, module_region);
25487 +}
25488 +EXPORT_SYMBOL(module_free_exec);
25489 +
25490 +void *module_alloc_exec(unsigned long size)
25491 +{
25492 + return __module_alloc(size, PAGE_KERNEL_RX);
25493 +}
25494 +EXPORT_SYMBOL(module_alloc_exec);
25495 +#endif
25496 +#endif
25497 +
25498 #ifdef CONFIG_X86_32
25499 int apply_relocate(Elf32_Shdr *sechdrs,
25500 const char *strtab,
25501 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25502 unsigned int i;
25503 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25504 Elf32_Sym *sym;
25505 - uint32_t *location;
25506 + uint32_t *plocation, location;
25507
25508 DEBUGP("Applying relocate section %u to %u\n",
25509 relsec, sechdrs[relsec].sh_info);
25510 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25511 /* This is where to make the change */
25512 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25513 - + rel[i].r_offset;
25514 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25515 + location = (uint32_t)plocation;
25516 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25517 + plocation = ktla_ktva((void *)plocation);
25518 /* This is the symbol it is referring to. Note that all
25519 undefined symbols have been resolved. */
25520 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25521 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25522 switch (ELF32_R_TYPE(rel[i].r_info)) {
25523 case R_386_32:
25524 /* We add the value into the location given */
25525 - *location += sym->st_value;
25526 + pax_open_kernel();
25527 + *plocation += sym->st_value;
25528 + pax_close_kernel();
25529 break;
25530 case R_386_PC32:
25531 /* Add the value, subtract its position */
25532 - *location += sym->st_value - (uint32_t)location;
25533 + pax_open_kernel();
25534 + *plocation += sym->st_value - location;
25535 + pax_close_kernel();
25536 break;
25537 default:
25538 pr_err("%s: Unknown relocation: %u\n",
25539 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25540 case R_X86_64_NONE:
25541 break;
25542 case R_X86_64_64:
25543 + pax_open_kernel();
25544 *(u64 *)loc = val;
25545 + pax_close_kernel();
25546 break;
25547 case R_X86_64_32:
25548 + pax_open_kernel();
25549 *(u32 *)loc = val;
25550 + pax_close_kernel();
25551 if (val != *(u32 *)loc)
25552 goto overflow;
25553 break;
25554 case R_X86_64_32S:
25555 + pax_open_kernel();
25556 *(s32 *)loc = val;
25557 + pax_close_kernel();
25558 if ((s64)val != *(s32 *)loc)
25559 goto overflow;
25560 break;
25561 case R_X86_64_PC32:
25562 val -= (u64)loc;
25563 + pax_open_kernel();
25564 *(u32 *)loc = val;
25565 + pax_close_kernel();
25566 +
25567 #if 0
25568 if ((s64)val != *(s32 *)loc)
25569 goto overflow;
25570 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25571 index 05266b5..3432443 100644
25572 --- a/arch/x86/kernel/msr.c
25573 +++ b/arch/x86/kernel/msr.c
25574 @@ -37,6 +37,7 @@
25575 #include <linux/notifier.h>
25576 #include <linux/uaccess.h>
25577 #include <linux/gfp.h>
25578 +#include <linux/grsecurity.h>
25579
25580 #include <asm/processor.h>
25581 #include <asm/msr.h>
25582 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25583 int err = 0;
25584 ssize_t bytes = 0;
25585
25586 +#ifdef CONFIG_GRKERNSEC_KMEM
25587 + gr_handle_msr_write();
25588 + return -EPERM;
25589 +#endif
25590 +
25591 if (count % 8)
25592 return -EINVAL; /* Invalid chunk size */
25593
25594 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25595 err = -EBADF;
25596 break;
25597 }
25598 +#ifdef CONFIG_GRKERNSEC_KMEM
25599 + gr_handle_msr_write();
25600 + return -EPERM;
25601 +#endif
25602 if (copy_from_user(&regs, uregs, sizeof regs)) {
25603 err = -EFAULT;
25604 break;
25605 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25606 return notifier_from_errno(err);
25607 }
25608
25609 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25610 +static struct notifier_block msr_class_cpu_notifier = {
25611 .notifier_call = msr_class_cpu_callback,
25612 };
25613
25614 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25615 index 6fcb49c..5b3f4ff 100644
25616 --- a/arch/x86/kernel/nmi.c
25617 +++ b/arch/x86/kernel/nmi.c
25618 @@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25619 return handled;
25620 }
25621
25622 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25623 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25624 {
25625 struct nmi_desc *desc = nmi_to_desc(type);
25626 unsigned long flags;
25627 @@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25628 * event confuses some handlers (kdump uses this flag)
25629 */
25630 if (action->flags & NMI_FLAG_FIRST)
25631 - list_add_rcu(&action->list, &desc->head);
25632 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25633 else
25634 - list_add_tail_rcu(&action->list, &desc->head);
25635 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25636
25637 spin_unlock_irqrestore(&desc->lock, flags);
25638 return 0;
25639 @@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25640 if (!strcmp(n->name, name)) {
25641 WARN(in_nmi(),
25642 "Trying to free NMI (%s) from NMI context!\n", n->name);
25643 - list_del_rcu(&n->list);
25644 + pax_list_del_rcu((struct list_head *)&n->list);
25645 break;
25646 }
25647 }
25648 @@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25649 dotraplinkage notrace __kprobes void
25650 do_nmi(struct pt_regs *regs, long error_code)
25651 {
25652 +
25653 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25654 + if (!user_mode(regs)) {
25655 + unsigned long cs = regs->cs & 0xFFFF;
25656 + unsigned long ip = ktva_ktla(regs->ip);
25657 +
25658 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25659 + regs->ip = ip;
25660 + }
25661 +#endif
25662 +
25663 nmi_nesting_preprocess(regs);
25664
25665 nmi_enter();
25666 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25667 index 6d9582e..f746287 100644
25668 --- a/arch/x86/kernel/nmi_selftest.c
25669 +++ b/arch/x86/kernel/nmi_selftest.c
25670 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25671 {
25672 /* trap all the unknown NMIs we may generate */
25673 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25674 - __initdata);
25675 + __initconst);
25676 }
25677
25678 static void __init cleanup_nmi_testsuite(void)
25679 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25680 unsigned long timeout;
25681
25682 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25683 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25684 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25685 nmi_fail = FAILURE;
25686 return;
25687 }
25688 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25689 index bbb6c73..24a58ef 100644
25690 --- a/arch/x86/kernel/paravirt-spinlocks.c
25691 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25692 @@ -8,7 +8,7 @@
25693
25694 #include <asm/paravirt.h>
25695
25696 -struct pv_lock_ops pv_lock_ops = {
25697 +struct pv_lock_ops pv_lock_ops __read_only = {
25698 #ifdef CONFIG_SMP
25699 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25700 .unlock_kick = paravirt_nop,
25701 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25702 index 1b10af8..0b58cbc 100644
25703 --- a/arch/x86/kernel/paravirt.c
25704 +++ b/arch/x86/kernel/paravirt.c
25705 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25706 {
25707 return x;
25708 }
25709 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25710 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25711 +#endif
25712
25713 void __init default_banner(void)
25714 {
25715 @@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25716 if (opfunc == NULL)
25717 /* If there's no function, patch it with a ud2a (BUG) */
25718 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25719 - else if (opfunc == _paravirt_nop)
25720 + else if (opfunc == (void *)_paravirt_nop)
25721 /* If the operation is a nop, then nop the callsite */
25722 ret = paravirt_patch_nop();
25723
25724 /* identity functions just return their single argument */
25725 - else if (opfunc == _paravirt_ident_32)
25726 + else if (opfunc == (void *)_paravirt_ident_32)
25727 ret = paravirt_patch_ident_32(insnbuf, len);
25728 - else if (opfunc == _paravirt_ident_64)
25729 + else if (opfunc == (void *)_paravirt_ident_64)
25730 ret = paravirt_patch_ident_64(insnbuf, len);
25731 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25732 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25733 + ret = paravirt_patch_ident_64(insnbuf, len);
25734 +#endif
25735
25736 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25737 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25738 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25739 if (insn_len > len || start == NULL)
25740 insn_len = len;
25741 else
25742 - memcpy(insnbuf, start, insn_len);
25743 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25744
25745 return insn_len;
25746 }
25747 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25748 return this_cpu_read(paravirt_lazy_mode);
25749 }
25750
25751 -struct pv_info pv_info = {
25752 +struct pv_info pv_info __read_only = {
25753 .name = "bare hardware",
25754 .paravirt_enabled = 0,
25755 .kernel_rpl = 0,
25756 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25757 #endif
25758 };
25759
25760 -struct pv_init_ops pv_init_ops = {
25761 +struct pv_init_ops pv_init_ops __read_only = {
25762 .patch = native_patch,
25763 };
25764
25765 -struct pv_time_ops pv_time_ops = {
25766 +struct pv_time_ops pv_time_ops __read_only = {
25767 .sched_clock = native_sched_clock,
25768 .steal_clock = native_steal_clock,
25769 };
25770
25771 -__visible struct pv_irq_ops pv_irq_ops = {
25772 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25773 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25774 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25775 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25776 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25777 #endif
25778 };
25779
25780 -__visible struct pv_cpu_ops pv_cpu_ops = {
25781 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25782 .cpuid = native_cpuid,
25783 .get_debugreg = native_get_debugreg,
25784 .set_debugreg = native_set_debugreg,
25785 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25786 .end_context_switch = paravirt_nop,
25787 };
25788
25789 -struct pv_apic_ops pv_apic_ops = {
25790 +struct pv_apic_ops pv_apic_ops __read_only= {
25791 #ifdef CONFIG_X86_LOCAL_APIC
25792 .startup_ipi_hook = paravirt_nop,
25793 #endif
25794 };
25795
25796 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25797 +#ifdef CONFIG_X86_32
25798 +#ifdef CONFIG_X86_PAE
25799 +/* 64-bit pagetable entries */
25800 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25801 +#else
25802 /* 32-bit pagetable entries */
25803 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25804 +#endif
25805 #else
25806 /* 64-bit pagetable entries */
25807 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25808 #endif
25809
25810 -struct pv_mmu_ops pv_mmu_ops = {
25811 +struct pv_mmu_ops pv_mmu_ops __read_only = {
25812
25813 .read_cr2 = native_read_cr2,
25814 .write_cr2 = native_write_cr2,
25815 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25816 .make_pud = PTE_IDENT,
25817
25818 .set_pgd = native_set_pgd,
25819 + .set_pgd_batched = native_set_pgd_batched,
25820 #endif
25821 #endif /* PAGETABLE_LEVELS >= 3 */
25822
25823 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25824 },
25825
25826 .set_fixmap = native_set_fixmap,
25827 +
25828 +#ifdef CONFIG_PAX_KERNEXEC
25829 + .pax_open_kernel = native_pax_open_kernel,
25830 + .pax_close_kernel = native_pax_close_kernel,
25831 +#endif
25832 +
25833 };
25834
25835 EXPORT_SYMBOL_GPL(pv_time_ops);
25836 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25837 index 299d493..2ccb0ee 100644
25838 --- a/arch/x86/kernel/pci-calgary_64.c
25839 +++ b/arch/x86/kernel/pci-calgary_64.c
25840 @@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25841 tce_space = be64_to_cpu(readq(target));
25842 tce_space = tce_space & TAR_SW_BITS;
25843
25844 - tce_space = tce_space & (~specified_table_size);
25845 + tce_space = tce_space & (~(unsigned long)specified_table_size);
25846 info->tce_space = (u64 *)__va(tce_space);
25847 }
25848 }
25849 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25850 index 35ccf75..7a15747 100644
25851 --- a/arch/x86/kernel/pci-iommu_table.c
25852 +++ b/arch/x86/kernel/pci-iommu_table.c
25853 @@ -2,7 +2,7 @@
25854 #include <asm/iommu_table.h>
25855 #include <linux/string.h>
25856 #include <linux/kallsyms.h>
25857 -
25858 +#include <linux/sched.h>
25859
25860 #define DEBUG 1
25861
25862 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25863 index 6c483ba..d10ce2f 100644
25864 --- a/arch/x86/kernel/pci-swiotlb.c
25865 +++ b/arch/x86/kernel/pci-swiotlb.c
25866 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25867 void *vaddr, dma_addr_t dma_addr,
25868 struct dma_attrs *attrs)
25869 {
25870 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25871 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25872 }
25873
25874 static struct dma_map_ops swiotlb_dma_ops = {
25875 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25876 index ca7f0d5..8996469 100644
25877 --- a/arch/x86/kernel/preempt.S
25878 +++ b/arch/x86/kernel/preempt.S
25879 @@ -3,12 +3,14 @@
25880 #include <asm/dwarf2.h>
25881 #include <asm/asm.h>
25882 #include <asm/calling.h>
25883 +#include <asm/alternative-asm.h>
25884
25885 ENTRY(___preempt_schedule)
25886 CFI_STARTPROC
25887 SAVE_ALL
25888 call preempt_schedule
25889 RESTORE_ALL
25890 + pax_force_retaddr
25891 ret
25892 CFI_ENDPROC
25893
25894 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25895 SAVE_ALL
25896 call preempt_schedule_context
25897 RESTORE_ALL
25898 + pax_force_retaddr
25899 ret
25900 CFI_ENDPROC
25901
25902 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25903 index 3fb8d95..254dc51 100644
25904 --- a/arch/x86/kernel/process.c
25905 +++ b/arch/x86/kernel/process.c
25906 @@ -36,7 +36,8 @@
25907 * section. Since TSS's are completely CPU-local, we want them
25908 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25909 */
25910 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25911 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25912 +EXPORT_SYMBOL(init_tss);
25913
25914 #ifdef CONFIG_X86_64
25915 static DEFINE_PER_CPU(unsigned char, is_idle);
25916 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25917 task_xstate_cachep =
25918 kmem_cache_create("task_xstate", xstate_size,
25919 __alignof__(union thread_xstate),
25920 - SLAB_PANIC | SLAB_NOTRACK, NULL);
25921 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25922 }
25923
25924 /*
25925 @@ -105,7 +106,7 @@ void exit_thread(void)
25926 unsigned long *bp = t->io_bitmap_ptr;
25927
25928 if (bp) {
25929 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25930 + struct tss_struct *tss = init_tss + get_cpu();
25931
25932 t->io_bitmap_ptr = NULL;
25933 clear_thread_flag(TIF_IO_BITMAP);
25934 @@ -125,6 +126,9 @@ void flush_thread(void)
25935 {
25936 struct task_struct *tsk = current;
25937
25938 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25939 + loadsegment(gs, 0);
25940 +#endif
25941 flush_ptrace_hw_breakpoint(tsk);
25942 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25943 drop_init_fpu(tsk);
25944 @@ -271,7 +275,7 @@ static void __exit_idle(void)
25945 void exit_idle(void)
25946 {
25947 /* idle loop has pid 0 */
25948 - if (current->pid)
25949 + if (task_pid_nr(current))
25950 return;
25951 __exit_idle();
25952 }
25953 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25954 return ret;
25955 }
25956 #endif
25957 -void stop_this_cpu(void *dummy)
25958 +__noreturn void stop_this_cpu(void *dummy)
25959 {
25960 local_irq_disable();
25961 /*
25962 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
25963 }
25964 early_param("idle", idle_setup);
25965
25966 -unsigned long arch_align_stack(unsigned long sp)
25967 +#ifdef CONFIG_PAX_RANDKSTACK
25968 +void pax_randomize_kstack(struct pt_regs *regs)
25969 {
25970 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
25971 - sp -= get_random_int() % 8192;
25972 - return sp & ~0xf;
25973 -}
25974 + struct thread_struct *thread = &current->thread;
25975 + unsigned long time;
25976
25977 -unsigned long arch_randomize_brk(struct mm_struct *mm)
25978 -{
25979 - unsigned long range_end = mm->brk + 0x02000000;
25980 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
25981 -}
25982 + if (!randomize_va_space)
25983 + return;
25984 +
25985 + if (v8086_mode(regs))
25986 + return;
25987
25988 + rdtscl(time);
25989 +
25990 + /* P4 seems to return a 0 LSB, ignore it */
25991 +#ifdef CONFIG_MPENTIUM4
25992 + time &= 0x3EUL;
25993 + time <<= 2;
25994 +#elif defined(CONFIG_X86_64)
25995 + time &= 0xFUL;
25996 + time <<= 4;
25997 +#else
25998 + time &= 0x1FUL;
25999 + time <<= 3;
26000 +#endif
26001 +
26002 + thread->sp0 ^= time;
26003 + load_sp0(init_tss + smp_processor_id(), thread);
26004 +
26005 +#ifdef CONFIG_X86_64
26006 + this_cpu_write(kernel_stack, thread->sp0);
26007 +#endif
26008 +}
26009 +#endif
26010 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26011 index 0de43e9..056b840 100644
26012 --- a/arch/x86/kernel/process_32.c
26013 +++ b/arch/x86/kernel/process_32.c
26014 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26015 unsigned long thread_saved_pc(struct task_struct *tsk)
26016 {
26017 return ((unsigned long *)tsk->thread.sp)[3];
26018 +//XXX return tsk->thread.eip;
26019 }
26020
26021 void __show_regs(struct pt_regs *regs, int all)
26022 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26023 unsigned long sp;
26024 unsigned short ss, gs;
26025
26026 - if (user_mode_vm(regs)) {
26027 + if (user_mode(regs)) {
26028 sp = regs->sp;
26029 ss = regs->ss & 0xffff;
26030 - gs = get_user_gs(regs);
26031 } else {
26032 sp = kernel_stack_pointer(regs);
26033 savesegment(ss, ss);
26034 - savesegment(gs, gs);
26035 }
26036 + gs = get_user_gs(regs);
26037
26038 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26039 (u16)regs->cs, regs->ip, regs->flags,
26040 - smp_processor_id());
26041 + raw_smp_processor_id());
26042 print_symbol("EIP is at %s\n", regs->ip);
26043
26044 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26045 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26046 int copy_thread(unsigned long clone_flags, unsigned long sp,
26047 unsigned long arg, struct task_struct *p)
26048 {
26049 - struct pt_regs *childregs = task_pt_regs(p);
26050 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26051 struct task_struct *tsk;
26052 int err;
26053
26054 p->thread.sp = (unsigned long) childregs;
26055 p->thread.sp0 = (unsigned long) (childregs+1);
26056 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26057
26058 if (unlikely(p->flags & PF_KTHREAD)) {
26059 /* kernel thread */
26060 memset(childregs, 0, sizeof(struct pt_regs));
26061 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26062 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26063 - childregs->ds = __USER_DS;
26064 - childregs->es = __USER_DS;
26065 + savesegment(gs, childregs->gs);
26066 + childregs->ds = __KERNEL_DS;
26067 + childregs->es = __KERNEL_DS;
26068 childregs->fs = __KERNEL_PERCPU;
26069 childregs->bx = sp; /* function */
26070 childregs->bp = arg;
26071 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26072 struct thread_struct *prev = &prev_p->thread,
26073 *next = &next_p->thread;
26074 int cpu = smp_processor_id();
26075 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26076 + struct tss_struct *tss = init_tss + cpu;
26077 fpu_switch_t fpu;
26078
26079 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26080 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26081 */
26082 lazy_save_gs(prev->gs);
26083
26084 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26085 + __set_fs(task_thread_info(next_p)->addr_limit);
26086 +#endif
26087 +
26088 /*
26089 * Load the per-thread Thread-Local Storage descriptor.
26090 */
26091 @@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26092 */
26093 arch_end_context_switch(next_p);
26094
26095 + this_cpu_write(current_task, next_p);
26096 + this_cpu_write(current_tinfo, &next_p->tinfo);
26097 +
26098 /*
26099 * Restore %gs if needed (which is common)
26100 */
26101 @@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26102
26103 switch_fpu_finish(next_p, fpu);
26104
26105 - this_cpu_write(current_task, next_p);
26106 -
26107 return prev_p;
26108 }
26109
26110 @@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26111 } while (count++ < 16);
26112 return 0;
26113 }
26114 -
26115 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26116 index 9c0280f..5bbb1c0 100644
26117 --- a/arch/x86/kernel/process_64.c
26118 +++ b/arch/x86/kernel/process_64.c
26119 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26120 struct pt_regs *childregs;
26121 struct task_struct *me = current;
26122
26123 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26124 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26125 childregs = task_pt_regs(p);
26126 p->thread.sp = (unsigned long) childregs;
26127 p->thread.usersp = me->thread.usersp;
26128 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26129 set_tsk_thread_flag(p, TIF_FORK);
26130 p->thread.fpu_counter = 0;
26131 p->thread.io_bitmap_ptr = NULL;
26132 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26133 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26134 savesegment(es, p->thread.es);
26135 savesegment(ds, p->thread.ds);
26136 + savesegment(ss, p->thread.ss);
26137 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26138 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26139
26140 if (unlikely(p->flags & PF_KTHREAD)) {
26141 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26142 struct thread_struct *prev = &prev_p->thread;
26143 struct thread_struct *next = &next_p->thread;
26144 int cpu = smp_processor_id();
26145 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26146 + struct tss_struct *tss = init_tss + cpu;
26147 unsigned fsindex, gsindex;
26148 fpu_switch_t fpu;
26149
26150 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26151 if (unlikely(next->ds | prev->ds))
26152 loadsegment(ds, next->ds);
26153
26154 + savesegment(ss, prev->ss);
26155 + if (unlikely(next->ss != prev->ss))
26156 + loadsegment(ss, next->ss);
26157
26158 /* We must save %fs and %gs before load_TLS() because
26159 * %fs and %gs may be cleared by load_TLS().
26160 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26161 prev->usersp = this_cpu_read(old_rsp);
26162 this_cpu_write(old_rsp, next->usersp);
26163 this_cpu_write(current_task, next_p);
26164 + this_cpu_write(current_tinfo, &next_p->tinfo);
26165
26166 /*
26167 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26168 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26169 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26170 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26171
26172 - this_cpu_write(kernel_stack,
26173 - (unsigned long)task_stack_page(next_p) +
26174 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26175 + this_cpu_write(kernel_stack, next->sp0);
26176
26177 /*
26178 * Now maybe reload the debug registers and handle I/O bitmaps
26179 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26180 if (!p || p == current || p->state == TASK_RUNNING)
26181 return 0;
26182 stack = (unsigned long)task_stack_page(p);
26183 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26184 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26185 return 0;
26186 fp = *(u64 *)(p->thread.sp);
26187 do {
26188 - if (fp < (unsigned long)stack ||
26189 - fp >= (unsigned long)stack+THREAD_SIZE)
26190 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26191 return 0;
26192 ip = *(u64 *)(fp+8);
26193 if (!in_sched_functions(ip))
26194 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26195 index 7461f50..1334029 100644
26196 --- a/arch/x86/kernel/ptrace.c
26197 +++ b/arch/x86/kernel/ptrace.c
26198 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26199 {
26200 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26201 unsigned long sp = (unsigned long)&regs->sp;
26202 - struct thread_info *tinfo;
26203
26204 - if (context == (sp & ~(THREAD_SIZE - 1)))
26205 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26206 return sp;
26207
26208 - tinfo = (struct thread_info *)context;
26209 - if (tinfo->previous_esp)
26210 - return tinfo->previous_esp;
26211 + sp = *(unsigned long *)context;
26212 + if (sp)
26213 + return sp;
26214
26215 return (unsigned long)regs;
26216 }
26217 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26218 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26219 {
26220 int i;
26221 - int dr7 = 0;
26222 + unsigned long dr7 = 0;
26223 struct arch_hw_breakpoint *info;
26224
26225 for (i = 0; i < HBP_NUM; i++) {
26226 @@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26227 unsigned long addr, unsigned long data)
26228 {
26229 int ret;
26230 - unsigned long __user *datap = (unsigned long __user *)data;
26231 + unsigned long __user *datap = (__force unsigned long __user *)data;
26232
26233 switch (request) {
26234 /* read the word at location addr in the USER area. */
26235 @@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26236 if ((int) addr < 0)
26237 return -EIO;
26238 ret = do_get_thread_area(child, addr,
26239 - (struct user_desc __user *)data);
26240 + (__force struct user_desc __user *) data);
26241 break;
26242
26243 case PTRACE_SET_THREAD_AREA:
26244 if ((int) addr < 0)
26245 return -EIO;
26246 ret = do_set_thread_area(child, addr,
26247 - (struct user_desc __user *)data, 0);
26248 + (__force struct user_desc __user *) data, 0);
26249 break;
26250 #endif
26251
26252 @@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26253
26254 #ifdef CONFIG_X86_64
26255
26256 -static struct user_regset x86_64_regsets[] __read_mostly = {
26257 +static user_regset_no_const x86_64_regsets[] __read_only = {
26258 [REGSET_GENERAL] = {
26259 .core_note_type = NT_PRSTATUS,
26260 .n = sizeof(struct user_regs_struct) / sizeof(long),
26261 @@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26262 #endif /* CONFIG_X86_64 */
26263
26264 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26265 -static struct user_regset x86_32_regsets[] __read_mostly = {
26266 +static user_regset_no_const x86_32_regsets[] __read_only = {
26267 [REGSET_GENERAL] = {
26268 .core_note_type = NT_PRSTATUS,
26269 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26270 @@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26271 */
26272 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26273
26274 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26275 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26276 {
26277 #ifdef CONFIG_X86_64
26278 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26279 @@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26280 memset(info, 0, sizeof(*info));
26281 info->si_signo = SIGTRAP;
26282 info->si_code = si_code;
26283 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26284 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26285 }
26286
26287 void user_single_step_siginfo(struct task_struct *tsk,
26288 @@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26289 # define IS_IA32 0
26290 #endif
26291
26292 +#ifdef CONFIG_GRKERNSEC_SETXID
26293 +extern void gr_delayed_cred_worker(void);
26294 +#endif
26295 +
26296 /*
26297 * We must return the syscall number to actually look up in the table.
26298 * This can be -1L to skip running any syscall at all.
26299 @@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26300
26301 user_exit();
26302
26303 +#ifdef CONFIG_GRKERNSEC_SETXID
26304 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26305 + gr_delayed_cred_worker();
26306 +#endif
26307 +
26308 /*
26309 * If we stepped into a sysenter/syscall insn, it trapped in
26310 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26311 @@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26312 */
26313 user_exit();
26314
26315 +#ifdef CONFIG_GRKERNSEC_SETXID
26316 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26317 + gr_delayed_cred_worker();
26318 +#endif
26319 +
26320 audit_syscall_exit(regs);
26321
26322 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26323 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26324 index 2f355d2..e75ed0a 100644
26325 --- a/arch/x86/kernel/pvclock.c
26326 +++ b/arch/x86/kernel/pvclock.c
26327 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26328 reset_hung_task_detector();
26329 }
26330
26331 -static atomic64_t last_value = ATOMIC64_INIT(0);
26332 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26333
26334 void pvclock_resume(void)
26335 {
26336 - atomic64_set(&last_value, 0);
26337 + atomic64_set_unchecked(&last_value, 0);
26338 }
26339
26340 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26341 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26342 * updating at the same time, and one of them could be slightly behind,
26343 * making the assumption that last_value always go forward fail to hold.
26344 */
26345 - last = atomic64_read(&last_value);
26346 + last = atomic64_read_unchecked(&last_value);
26347 do {
26348 if (ret < last)
26349 return last;
26350 - last = atomic64_cmpxchg(&last_value, last, ret);
26351 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26352 } while (unlikely(last != ret));
26353
26354 return ret;
26355 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26356 index c752cb4..866c432 100644
26357 --- a/arch/x86/kernel/reboot.c
26358 +++ b/arch/x86/kernel/reboot.c
26359 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26360
26361 void __noreturn machine_real_restart(unsigned int type)
26362 {
26363 +
26364 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26365 + struct desc_struct *gdt;
26366 +#endif
26367 +
26368 local_irq_disable();
26369
26370 /*
26371 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26372
26373 /* Jump to the identity-mapped low memory code */
26374 #ifdef CONFIG_X86_32
26375 - asm volatile("jmpl *%0" : :
26376 +
26377 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26378 + gdt = get_cpu_gdt_table(smp_processor_id());
26379 + pax_open_kernel();
26380 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26381 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26382 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26383 + loadsegment(ds, __KERNEL_DS);
26384 + loadsegment(es, __KERNEL_DS);
26385 + loadsegment(ss, __KERNEL_DS);
26386 +#endif
26387 +#ifdef CONFIG_PAX_KERNEXEC
26388 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26389 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26390 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26391 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26392 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26393 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26394 +#endif
26395 + pax_close_kernel();
26396 +#endif
26397 +
26398 + asm volatile("ljmpl *%0" : :
26399 "rm" (real_mode_header->machine_real_restart_asm),
26400 "a" (type));
26401 #else
26402 @@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26403 * try to force a triple fault and then cycle between hitting the keyboard
26404 * controller and doing that
26405 */
26406 -static void native_machine_emergency_restart(void)
26407 +static void __noreturn native_machine_emergency_restart(void)
26408 {
26409 int i;
26410 int attempt = 0;
26411 @@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26412 #endif
26413 }
26414
26415 -static void __machine_emergency_restart(int emergency)
26416 +static void __noreturn __machine_emergency_restart(int emergency)
26417 {
26418 reboot_emergency = emergency;
26419 machine_ops.emergency_restart();
26420 }
26421
26422 -static void native_machine_restart(char *__unused)
26423 +static void __noreturn native_machine_restart(char *__unused)
26424 {
26425 pr_notice("machine restart\n");
26426
26427 @@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26428 __machine_emergency_restart(0);
26429 }
26430
26431 -static void native_machine_halt(void)
26432 +static void __noreturn native_machine_halt(void)
26433 {
26434 /* Stop other cpus and apics */
26435 machine_shutdown();
26436 @@ -618,7 +645,7 @@ static void native_machine_halt(void)
26437 stop_this_cpu(NULL);
26438 }
26439
26440 -static void native_machine_power_off(void)
26441 +static void __noreturn native_machine_power_off(void)
26442 {
26443 if (pm_power_off) {
26444 if (!reboot_force)
26445 @@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26446 }
26447 /* A fallback in case there is no PM info available */
26448 tboot_shutdown(TB_SHUTDOWN_HALT);
26449 + unreachable();
26450 }
26451
26452 -struct machine_ops machine_ops = {
26453 +struct machine_ops machine_ops __read_only = {
26454 .power_off = native_machine_power_off,
26455 .shutdown = native_machine_shutdown,
26456 .emergency_restart = native_machine_emergency_restart,
26457 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26458 index c8e41e9..64049ef 100644
26459 --- a/arch/x86/kernel/reboot_fixups_32.c
26460 +++ b/arch/x86/kernel/reboot_fixups_32.c
26461 @@ -57,7 +57,7 @@ struct device_fixup {
26462 unsigned int vendor;
26463 unsigned int device;
26464 void (*reboot_fixup)(struct pci_dev *);
26465 -};
26466 +} __do_const;
26467
26468 /*
26469 * PCI ids solely used for fixups_table go here
26470 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26471 index 3fd2c69..a444264 100644
26472 --- a/arch/x86/kernel/relocate_kernel_64.S
26473 +++ b/arch/x86/kernel/relocate_kernel_64.S
26474 @@ -96,8 +96,7 @@ relocate_kernel:
26475
26476 /* jump to identity mapped page */
26477 addq $(identity_mapped - relocate_kernel), %r8
26478 - pushq %r8
26479 - ret
26480 + jmp *%r8
26481
26482 identity_mapped:
26483 /* set return address to 0 if not preserving context */
26484 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26485 index ce72964..be8aea7 100644
26486 --- a/arch/x86/kernel/setup.c
26487 +++ b/arch/x86/kernel/setup.c
26488 @@ -110,6 +110,7 @@
26489 #include <asm/mce.h>
26490 #include <asm/alternative.h>
26491 #include <asm/prom.h>
26492 +#include <asm/boot.h>
26493
26494 /*
26495 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26496 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26497 #endif
26498
26499
26500 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26501 -__visible unsigned long mmu_cr4_features;
26502 +#ifdef CONFIG_X86_64
26503 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26504 +#elif defined(CONFIG_X86_PAE)
26505 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26506 #else
26507 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26508 +__visible unsigned long mmu_cr4_features __read_only;
26509 #endif
26510
26511 +void set_in_cr4(unsigned long mask)
26512 +{
26513 + unsigned long cr4 = read_cr4();
26514 +
26515 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26516 + return;
26517 +
26518 + pax_open_kernel();
26519 + mmu_cr4_features |= mask;
26520 + pax_close_kernel();
26521 +
26522 + if (trampoline_cr4_features)
26523 + *trampoline_cr4_features = mmu_cr4_features;
26524 + cr4 |= mask;
26525 + write_cr4(cr4);
26526 +}
26527 +EXPORT_SYMBOL(set_in_cr4);
26528 +
26529 +void clear_in_cr4(unsigned long mask)
26530 +{
26531 + unsigned long cr4 = read_cr4();
26532 +
26533 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26534 + return;
26535 +
26536 + pax_open_kernel();
26537 + mmu_cr4_features &= ~mask;
26538 + pax_close_kernel();
26539 +
26540 + if (trampoline_cr4_features)
26541 + *trampoline_cr4_features = mmu_cr4_features;
26542 + cr4 &= ~mask;
26543 + write_cr4(cr4);
26544 +}
26545 +EXPORT_SYMBOL(clear_in_cr4);
26546 +
26547 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26548 int bootloader_type, bootloader_version;
26549
26550 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26551 * area (640->1Mb) as ram even though it is not.
26552 * take them out.
26553 */
26554 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26555 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26556
26557 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26558 }
26559 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26560 /* called before trim_bios_range() to spare extra sanitize */
26561 static void __init e820_add_kernel_range(void)
26562 {
26563 - u64 start = __pa_symbol(_text);
26564 + u64 start = __pa_symbol(ktla_ktva(_text));
26565 u64 size = __pa_symbol(_end) - start;
26566
26567 /*
26568 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26569
26570 void __init setup_arch(char **cmdline_p)
26571 {
26572 +#ifdef CONFIG_X86_32
26573 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26574 +#else
26575 memblock_reserve(__pa_symbol(_text),
26576 (unsigned long)__bss_stop - (unsigned long)_text);
26577 +#endif
26578
26579 early_reserve_initrd();
26580
26581 @@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
26582
26583 if (!boot_params.hdr.root_flags)
26584 root_mountflags &= ~MS_RDONLY;
26585 - init_mm.start_code = (unsigned long) _text;
26586 - init_mm.end_code = (unsigned long) _etext;
26587 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26588 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26589 init_mm.end_data = (unsigned long) _edata;
26590 init_mm.brk = _brk_end;
26591
26592 - code_resource.start = __pa_symbol(_text);
26593 - code_resource.end = __pa_symbol(_etext)-1;
26594 - data_resource.start = __pa_symbol(_etext);
26595 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26596 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26597 + data_resource.start = __pa_symbol(_sdata);
26598 data_resource.end = __pa_symbol(_edata)-1;
26599 bss_resource.start = __pa_symbol(__bss_start);
26600 bss_resource.end = __pa_symbol(__bss_stop)-1;
26601 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26602 index 5cdff03..80fa283 100644
26603 --- a/arch/x86/kernel/setup_percpu.c
26604 +++ b/arch/x86/kernel/setup_percpu.c
26605 @@ -21,19 +21,17 @@
26606 #include <asm/cpu.h>
26607 #include <asm/stackprotector.h>
26608
26609 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26610 +#ifdef CONFIG_SMP
26611 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26612 EXPORT_PER_CPU_SYMBOL(cpu_number);
26613 +#endif
26614
26615 -#ifdef CONFIG_X86_64
26616 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26617 -#else
26618 -#define BOOT_PERCPU_OFFSET 0
26619 -#endif
26620
26621 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26622 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26623
26624 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26625 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26626 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26627 };
26628 EXPORT_SYMBOL(__per_cpu_offset);
26629 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26630 {
26631 #ifdef CONFIG_NEED_MULTIPLE_NODES
26632 pg_data_t *last = NULL;
26633 - unsigned int cpu;
26634 + int cpu;
26635
26636 for_each_possible_cpu(cpu) {
26637 int node = early_cpu_to_node(cpu);
26638 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26639 {
26640 #ifdef CONFIG_X86_32
26641 struct desc_struct gdt;
26642 + unsigned long base = per_cpu_offset(cpu);
26643
26644 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26645 - 0x2 | DESCTYPE_S, 0x8);
26646 - gdt.s = 1;
26647 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26648 + 0x83 | DESCTYPE_S, 0xC);
26649 write_gdt_entry(get_cpu_gdt_table(cpu),
26650 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26651 #endif
26652 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26653 /* alrighty, percpu areas up and running */
26654 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26655 for_each_possible_cpu(cpu) {
26656 +#ifdef CONFIG_CC_STACKPROTECTOR
26657 +#ifdef CONFIG_X86_32
26658 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26659 +#endif
26660 +#endif
26661 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26662 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26663 per_cpu(cpu_number, cpu) = cpu;
26664 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26665 */
26666 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26667 #endif
26668 +#ifdef CONFIG_CC_STACKPROTECTOR
26669 +#ifdef CONFIG_X86_32
26670 + if (!cpu)
26671 + per_cpu(stack_canary.canary, cpu) = canary;
26672 +#endif
26673 +#endif
26674 /*
26675 * Up to this point, the boot CPU has been using .init.data
26676 * area. Reload any changed state for the boot CPU.
26677 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26678 index 9e5de68..16c53cb 100644
26679 --- a/arch/x86/kernel/signal.c
26680 +++ b/arch/x86/kernel/signal.c
26681 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26682 * Align the stack pointer according to the i386 ABI,
26683 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26684 */
26685 - sp = ((sp + 4) & -16ul) - 4;
26686 + sp = ((sp - 12) & -16ul) - 4;
26687 #else /* !CONFIG_X86_32 */
26688 sp = round_down(sp, 16) - 8;
26689 #endif
26690 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26691 }
26692
26693 if (current->mm->context.vdso)
26694 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26695 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26696 else
26697 - restorer = &frame->retcode;
26698 + restorer = (void __user *)&frame->retcode;
26699 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26700 restorer = ksig->ka.sa.sa_restorer;
26701
26702 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26703 * reasons and because gdb uses it as a signature to notice
26704 * signal handler stack frames.
26705 */
26706 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26707 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26708
26709 if (err)
26710 return -EFAULT;
26711 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26712 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26713
26714 /* Set up to return from userspace. */
26715 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26716 + if (current->mm->context.vdso)
26717 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26718 + else
26719 + restorer = (void __user *)&frame->retcode;
26720 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26721 restorer = ksig->ka.sa.sa_restorer;
26722 put_user_ex(restorer, &frame->pretcode);
26723 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26724 * reasons and because gdb uses it as a signature to notice
26725 * signal handler stack frames.
26726 */
26727 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26728 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26729 } put_user_catch(err);
26730
26731 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26732 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26733 {
26734 int usig = signr_convert(ksig->sig);
26735 sigset_t *set = sigmask_to_save();
26736 - compat_sigset_t *cset = (compat_sigset_t *) set;
26737 + sigset_t sigcopy;
26738 + compat_sigset_t *cset;
26739 +
26740 + sigcopy = *set;
26741 +
26742 + cset = (compat_sigset_t *) &sigcopy;
26743
26744 /* Set up the stack frame */
26745 if (is_ia32_frame()) {
26746 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26747 } else if (is_x32_frame()) {
26748 return x32_setup_rt_frame(ksig, cset, regs);
26749 } else {
26750 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26751 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26752 }
26753 }
26754
26755 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26756 index 7c3a5a6..f0a8961 100644
26757 --- a/arch/x86/kernel/smp.c
26758 +++ b/arch/x86/kernel/smp.c
26759 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26760
26761 __setup("nonmi_ipi", nonmi_ipi_setup);
26762
26763 -struct smp_ops smp_ops = {
26764 +struct smp_ops smp_ops __read_only = {
26765 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26766 .smp_prepare_cpus = native_smp_prepare_cpus,
26767 .smp_cpus_done = native_smp_cpus_done,
26768 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26769 index a32da80..30c97f1 100644
26770 --- a/arch/x86/kernel/smpboot.c
26771 +++ b/arch/x86/kernel/smpboot.c
26772 @@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26773
26774 enable_start_cpu0 = 0;
26775
26776 -#ifdef CONFIG_X86_32
26777 - /* switch away from the initial page table */
26778 - load_cr3(swapper_pg_dir);
26779 - __flush_tlb_all();
26780 -#endif
26781 -
26782 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26783 barrier();
26784 +
26785 + /* switch away from the initial page table */
26786 +#ifdef CONFIG_PAX_PER_CPU_PGD
26787 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26788 + __flush_tlb_all();
26789 +#elif defined(CONFIG_X86_32)
26790 + load_cr3(swapper_pg_dir);
26791 + __flush_tlb_all();
26792 +#endif
26793 +
26794 /*
26795 * Check TSC synchronization with the BP:
26796 */
26797 @@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26798 alternatives_enable_smp();
26799
26800 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26801 - (THREAD_SIZE + task_stack_page(idle))) - 1);
26802 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26803 per_cpu(current_task, cpu) = idle;
26804 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26805
26806 #ifdef CONFIG_X86_32
26807 /* Stack for startup_32 can be just as for start_secondary onwards */
26808 @@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26809 #else
26810 clear_tsk_thread_flag(idle, TIF_FORK);
26811 initial_gs = per_cpu_offset(cpu);
26812 - per_cpu(kernel_stack, cpu) =
26813 - (unsigned long)task_stack_page(idle) -
26814 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26815 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26816 #endif
26817 +
26818 + pax_open_kernel();
26819 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26820 + pax_close_kernel();
26821 +
26822 initial_code = (unsigned long)start_secondary;
26823 stack_start = idle->thread.sp;
26824
26825 @@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26826 /* the FPU context is blank, nobody can own it */
26827 __cpu_disable_lazy_restore(cpu);
26828
26829 +#ifdef CONFIG_PAX_PER_CPU_PGD
26830 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26831 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26832 + KERNEL_PGD_PTRS);
26833 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26834 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26835 + KERNEL_PGD_PTRS);
26836 +#endif
26837 +
26838 err = do_boot_cpu(apicid, cpu, tidle);
26839 if (err) {
26840 pr_debug("do_boot_cpu failed %d\n", err);
26841 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26842 index 9b4d51d..5d28b58 100644
26843 --- a/arch/x86/kernel/step.c
26844 +++ b/arch/x86/kernel/step.c
26845 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26846 struct desc_struct *desc;
26847 unsigned long base;
26848
26849 - seg &= ~7UL;
26850 + seg >>= 3;
26851
26852 mutex_lock(&child->mm->context.lock);
26853 - if (unlikely((seg >> 3) >= child->mm->context.size))
26854 + if (unlikely(seg >= child->mm->context.size))
26855 addr = -1L; /* bogus selector, access would fault */
26856 else {
26857 desc = child->mm->context.ldt + seg;
26858 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26859 addr += base;
26860 }
26861 mutex_unlock(&child->mm->context.lock);
26862 - }
26863 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26864 + addr = ktla_ktva(addr);
26865
26866 return addr;
26867 }
26868 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26869 unsigned char opcode[15];
26870 unsigned long addr = convert_ip_to_linear(child, regs);
26871
26872 + if (addr == -EINVAL)
26873 + return 0;
26874 +
26875 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26876 for (i = 0; i < copied; i++) {
26877 switch (opcode[i]) {
26878 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26879 new file mode 100644
26880 index 0000000..5877189
26881 --- /dev/null
26882 +++ b/arch/x86/kernel/sys_i386_32.c
26883 @@ -0,0 +1,189 @@
26884 +/*
26885 + * This file contains various random system calls that
26886 + * have a non-standard calling sequence on the Linux/i386
26887 + * platform.
26888 + */
26889 +
26890 +#include <linux/errno.h>
26891 +#include <linux/sched.h>
26892 +#include <linux/mm.h>
26893 +#include <linux/fs.h>
26894 +#include <linux/smp.h>
26895 +#include <linux/sem.h>
26896 +#include <linux/msg.h>
26897 +#include <linux/shm.h>
26898 +#include <linux/stat.h>
26899 +#include <linux/syscalls.h>
26900 +#include <linux/mman.h>
26901 +#include <linux/file.h>
26902 +#include <linux/utsname.h>
26903 +#include <linux/ipc.h>
26904 +#include <linux/elf.h>
26905 +
26906 +#include <linux/uaccess.h>
26907 +#include <linux/unistd.h>
26908 +
26909 +#include <asm/syscalls.h>
26910 +
26911 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26912 +{
26913 + unsigned long pax_task_size = TASK_SIZE;
26914 +
26915 +#ifdef CONFIG_PAX_SEGMEXEC
26916 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26917 + pax_task_size = SEGMEXEC_TASK_SIZE;
26918 +#endif
26919 +
26920 + if (flags & MAP_FIXED)
26921 + if (len > pax_task_size || addr > pax_task_size - len)
26922 + return -EINVAL;
26923 +
26924 + return 0;
26925 +}
26926 +
26927 +/*
26928 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26929 + */
26930 +static unsigned long get_align_mask(void)
26931 +{
26932 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26933 + return 0;
26934 +
26935 + if (!(current->flags & PF_RANDOMIZE))
26936 + return 0;
26937 +
26938 + return va_align.mask;
26939 +}
26940 +
26941 +unsigned long
26942 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
26943 + unsigned long len, unsigned long pgoff, unsigned long flags)
26944 +{
26945 + struct mm_struct *mm = current->mm;
26946 + struct vm_area_struct *vma;
26947 + unsigned long pax_task_size = TASK_SIZE;
26948 + struct vm_unmapped_area_info info;
26949 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26950 +
26951 +#ifdef CONFIG_PAX_SEGMEXEC
26952 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26953 + pax_task_size = SEGMEXEC_TASK_SIZE;
26954 +#endif
26955 +
26956 + pax_task_size -= PAGE_SIZE;
26957 +
26958 + if (len > pax_task_size)
26959 + return -ENOMEM;
26960 +
26961 + if (flags & MAP_FIXED)
26962 + return addr;
26963 +
26964 +#ifdef CONFIG_PAX_RANDMMAP
26965 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26966 +#endif
26967 +
26968 + if (addr) {
26969 + addr = PAGE_ALIGN(addr);
26970 + if (pax_task_size - len >= addr) {
26971 + vma = find_vma(mm, addr);
26972 + if (check_heap_stack_gap(vma, addr, len, offset))
26973 + return addr;
26974 + }
26975 + }
26976 +
26977 + info.flags = 0;
26978 + info.length = len;
26979 + info.align_mask = filp ? get_align_mask() : 0;
26980 + info.align_offset = pgoff << PAGE_SHIFT;
26981 + info.threadstack_offset = offset;
26982 +
26983 +#ifdef CONFIG_PAX_PAGEEXEC
26984 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
26985 + info.low_limit = 0x00110000UL;
26986 + info.high_limit = mm->start_code;
26987 +
26988 +#ifdef CONFIG_PAX_RANDMMAP
26989 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26990 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
26991 +#endif
26992 +
26993 + if (info.low_limit < info.high_limit) {
26994 + addr = vm_unmapped_area(&info);
26995 + if (!IS_ERR_VALUE(addr))
26996 + return addr;
26997 + }
26998 + } else
26999 +#endif
27000 +
27001 + info.low_limit = mm->mmap_base;
27002 + info.high_limit = pax_task_size;
27003 +
27004 + return vm_unmapped_area(&info);
27005 +}
27006 +
27007 +unsigned long
27008 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27009 + const unsigned long len, const unsigned long pgoff,
27010 + const unsigned long flags)
27011 +{
27012 + struct vm_area_struct *vma;
27013 + struct mm_struct *mm = current->mm;
27014 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27015 + struct vm_unmapped_area_info info;
27016 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27017 +
27018 +#ifdef CONFIG_PAX_SEGMEXEC
27019 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27020 + pax_task_size = SEGMEXEC_TASK_SIZE;
27021 +#endif
27022 +
27023 + pax_task_size -= PAGE_SIZE;
27024 +
27025 + /* requested length too big for entire address space */
27026 + if (len > pax_task_size)
27027 + return -ENOMEM;
27028 +
27029 + if (flags & MAP_FIXED)
27030 + return addr;
27031 +
27032 +#ifdef CONFIG_PAX_PAGEEXEC
27033 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27034 + goto bottomup;
27035 +#endif
27036 +
27037 +#ifdef CONFIG_PAX_RANDMMAP
27038 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27039 +#endif
27040 +
27041 + /* requesting a specific address */
27042 + if (addr) {
27043 + addr = PAGE_ALIGN(addr);
27044 + if (pax_task_size - len >= addr) {
27045 + vma = find_vma(mm, addr);
27046 + if (check_heap_stack_gap(vma, addr, len, offset))
27047 + return addr;
27048 + }
27049 + }
27050 +
27051 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27052 + info.length = len;
27053 + info.low_limit = PAGE_SIZE;
27054 + info.high_limit = mm->mmap_base;
27055 + info.align_mask = filp ? get_align_mask() : 0;
27056 + info.align_offset = pgoff << PAGE_SHIFT;
27057 + info.threadstack_offset = offset;
27058 +
27059 + addr = vm_unmapped_area(&info);
27060 + if (!(addr & ~PAGE_MASK))
27061 + return addr;
27062 + VM_BUG_ON(addr != -ENOMEM);
27063 +
27064 +bottomup:
27065 + /*
27066 + * A failed mmap() very likely causes application failure,
27067 + * so fall back to the bottom-up function here. This scenario
27068 + * can happen with large stack limits and large mmap()
27069 + * allocations.
27070 + */
27071 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27072 +}
27073 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27074 index 30277e2..5664a29 100644
27075 --- a/arch/x86/kernel/sys_x86_64.c
27076 +++ b/arch/x86/kernel/sys_x86_64.c
27077 @@ -81,8 +81,8 @@ out:
27078 return error;
27079 }
27080
27081 -static void find_start_end(unsigned long flags, unsigned long *begin,
27082 - unsigned long *end)
27083 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27084 + unsigned long *begin, unsigned long *end)
27085 {
27086 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27087 unsigned long new_begin;
27088 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27089 *begin = new_begin;
27090 }
27091 } else {
27092 - *begin = current->mm->mmap_legacy_base;
27093 + *begin = mm->mmap_legacy_base;
27094 *end = TASK_SIZE;
27095 }
27096 }
27097 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27098 struct vm_area_struct *vma;
27099 struct vm_unmapped_area_info info;
27100 unsigned long begin, end;
27101 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27102
27103 if (flags & MAP_FIXED)
27104 return addr;
27105
27106 - find_start_end(flags, &begin, &end);
27107 + find_start_end(mm, flags, &begin, &end);
27108
27109 if (len > end)
27110 return -ENOMEM;
27111
27112 +#ifdef CONFIG_PAX_RANDMMAP
27113 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27114 +#endif
27115 +
27116 if (addr) {
27117 addr = PAGE_ALIGN(addr);
27118 vma = find_vma(mm, addr);
27119 - if (end - len >= addr &&
27120 - (!vma || addr + len <= vma->vm_start))
27121 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27122 return addr;
27123 }
27124
27125 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27126 info.high_limit = end;
27127 info.align_mask = filp ? get_align_mask() : 0;
27128 info.align_offset = pgoff << PAGE_SHIFT;
27129 + info.threadstack_offset = offset;
27130 return vm_unmapped_area(&info);
27131 }
27132
27133 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27134 struct mm_struct *mm = current->mm;
27135 unsigned long addr = addr0;
27136 struct vm_unmapped_area_info info;
27137 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27138
27139 /* requested length too big for entire address space */
27140 if (len > TASK_SIZE)
27141 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27142 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27143 goto bottomup;
27144
27145 +#ifdef CONFIG_PAX_RANDMMAP
27146 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27147 +#endif
27148 +
27149 /* requesting a specific address */
27150 if (addr) {
27151 addr = PAGE_ALIGN(addr);
27152 vma = find_vma(mm, addr);
27153 - if (TASK_SIZE - len >= addr &&
27154 - (!vma || addr + len <= vma->vm_start))
27155 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27156 return addr;
27157 }
27158
27159 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27160 info.high_limit = mm->mmap_base;
27161 info.align_mask = filp ? get_align_mask() : 0;
27162 info.align_offset = pgoff << PAGE_SHIFT;
27163 + info.threadstack_offset = offset;
27164 addr = vm_unmapped_area(&info);
27165 if (!(addr & ~PAGE_MASK))
27166 return addr;
27167 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27168 index 91a4496..bb87552 100644
27169 --- a/arch/x86/kernel/tboot.c
27170 +++ b/arch/x86/kernel/tboot.c
27171 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27172
27173 void tboot_shutdown(u32 shutdown_type)
27174 {
27175 - void (*shutdown)(void);
27176 + void (* __noreturn shutdown)(void);
27177
27178 if (!tboot_enabled())
27179 return;
27180 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27181
27182 switch_to_tboot_pt();
27183
27184 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27185 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27186 shutdown();
27187
27188 /* should not reach here */
27189 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27190 return -ENODEV;
27191 }
27192
27193 -static atomic_t ap_wfs_count;
27194 +static atomic_unchecked_t ap_wfs_count;
27195
27196 static int tboot_wait_for_aps(int num_aps)
27197 {
27198 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27199 {
27200 switch (action) {
27201 case CPU_DYING:
27202 - atomic_inc(&ap_wfs_count);
27203 + atomic_inc_unchecked(&ap_wfs_count);
27204 if (num_online_cpus() == 1)
27205 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27206 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27207 return NOTIFY_BAD;
27208 break;
27209 }
27210 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27211
27212 tboot_create_trampoline();
27213
27214 - atomic_set(&ap_wfs_count, 0);
27215 + atomic_set_unchecked(&ap_wfs_count, 0);
27216 register_hotcpu_notifier(&tboot_cpu_notifier);
27217
27218 #ifdef CONFIG_DEBUG_FS
27219 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27220 index 24d3c91..d06b473 100644
27221 --- a/arch/x86/kernel/time.c
27222 +++ b/arch/x86/kernel/time.c
27223 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27224 {
27225 unsigned long pc = instruction_pointer(regs);
27226
27227 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27228 + if (!user_mode(regs) && in_lock_functions(pc)) {
27229 #ifdef CONFIG_FRAME_POINTER
27230 - return *(unsigned long *)(regs->bp + sizeof(long));
27231 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27232 #else
27233 unsigned long *sp =
27234 (unsigned long *)kernel_stack_pointer(regs);
27235 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27236 * or above a saved flags. Eflags has bits 22-31 zero,
27237 * kernel addresses don't.
27238 */
27239 +
27240 +#ifdef CONFIG_PAX_KERNEXEC
27241 + return ktla_ktva(sp[0]);
27242 +#else
27243 if (sp[0] >> 22)
27244 return sp[0];
27245 if (sp[1] >> 22)
27246 return sp[1];
27247 #endif
27248 +
27249 +#endif
27250 }
27251 return pc;
27252 }
27253 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27254 index f7fec09..9991981 100644
27255 --- a/arch/x86/kernel/tls.c
27256 +++ b/arch/x86/kernel/tls.c
27257 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27258 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27259 return -EINVAL;
27260
27261 +#ifdef CONFIG_PAX_SEGMEXEC
27262 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27263 + return -EINVAL;
27264 +#endif
27265 +
27266 set_tls_desc(p, idx, &info, 1);
27267
27268 return 0;
27269 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27270
27271 if (kbuf)
27272 info = kbuf;
27273 - else if (__copy_from_user(infobuf, ubuf, count))
27274 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27275 return -EFAULT;
27276 else
27277 info = infobuf;
27278 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27279 index 1c113db..287b42e 100644
27280 --- a/arch/x86/kernel/tracepoint.c
27281 +++ b/arch/x86/kernel/tracepoint.c
27282 @@ -9,11 +9,11 @@
27283 #include <linux/atomic.h>
27284
27285 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27286 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27287 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27288 (unsigned long) trace_idt_table };
27289
27290 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27291 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27292 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27293
27294 static int trace_irq_vector_refcount;
27295 static DEFINE_MUTEX(irq_vector_mutex);
27296 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27297 index 57409f6..8a7aa05 100644
27298 --- a/arch/x86/kernel/traps.c
27299 +++ b/arch/x86/kernel/traps.c
27300 @@ -66,7 +66,7 @@
27301 #include <asm/proto.h>
27302
27303 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27304 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27305 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27306 #else
27307 #include <asm/processor-flags.h>
27308 #include <asm/setup.h>
27309 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27310 #endif
27311
27312 /* Must be page-aligned because the real IDT is used in a fixmap. */
27313 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27314 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27315
27316 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27317 EXPORT_SYMBOL_GPL(used_vectors);
27318 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27319 }
27320
27321 static int __kprobes
27322 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27323 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27324 struct pt_regs *regs, long error_code)
27325 {
27326 #ifdef CONFIG_X86_32
27327 - if (regs->flags & X86_VM_MASK) {
27328 + if (v8086_mode(regs)) {
27329 /*
27330 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27331 * On nmi (interrupt 2), do_trap should not be called.
27332 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27333 return -1;
27334 }
27335 #endif
27336 - if (!user_mode(regs)) {
27337 + if (!user_mode_novm(regs)) {
27338 if (!fixup_exception(regs)) {
27339 tsk->thread.error_code = error_code;
27340 tsk->thread.trap_nr = trapnr;
27341 +
27342 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27343 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27344 + str = "PAX: suspicious stack segment fault";
27345 +#endif
27346 +
27347 die(str, regs, error_code);
27348 }
27349 +
27350 +#ifdef CONFIG_PAX_REFCOUNT
27351 + if (trapnr == 4)
27352 + pax_report_refcount_overflow(regs);
27353 +#endif
27354 +
27355 return 0;
27356 }
27357
27358 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27359 }
27360
27361 static void __kprobes
27362 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27363 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27364 long error_code, siginfo_t *info)
27365 {
27366 struct task_struct *tsk = current;
27367 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27368 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27369 printk_ratelimit()) {
27370 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27371 - tsk->comm, tsk->pid, str,
27372 + tsk->comm, task_pid_nr(tsk), str,
27373 regs->ip, regs->sp, error_code);
27374 print_vma_addr(" in ", regs->ip);
27375 pr_cont("\n");
27376 @@ -273,7 +285,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27377 conditional_sti(regs);
27378
27379 #ifdef CONFIG_X86_32
27380 - if (regs->flags & X86_VM_MASK) {
27381 + if (v8086_mode(regs)) {
27382 local_irq_enable();
27383 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27384 goto exit;
27385 @@ -281,18 +293,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27386 #endif
27387
27388 tsk = current;
27389 - if (!user_mode(regs)) {
27390 + if (!user_mode_novm(regs)) {
27391 if (fixup_exception(regs))
27392 goto exit;
27393
27394 tsk->thread.error_code = error_code;
27395 tsk->thread.trap_nr = X86_TRAP_GP;
27396 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27397 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27398 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27399 +
27400 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27401 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27402 + die("PAX: suspicious general protection fault", regs, error_code);
27403 + else
27404 +#endif
27405 +
27406 die("general protection fault", regs, error_code);
27407 + }
27408 goto exit;
27409 }
27410
27411 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27412 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27413 + struct mm_struct *mm = tsk->mm;
27414 + unsigned long limit;
27415 +
27416 + down_write(&mm->mmap_sem);
27417 + limit = mm->context.user_cs_limit;
27418 + if (limit < TASK_SIZE) {
27419 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27420 + up_write(&mm->mmap_sem);
27421 + return;
27422 + }
27423 + up_write(&mm->mmap_sem);
27424 + }
27425 +#endif
27426 +
27427 tsk->thread.error_code = error_code;
27428 tsk->thread.trap_nr = X86_TRAP_GP;
27429
27430 @@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27431 /* It's safe to allow irq's after DR6 has been saved */
27432 preempt_conditional_sti(regs);
27433
27434 - if (regs->flags & X86_VM_MASK) {
27435 + if (v8086_mode(regs)) {
27436 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27437 X86_TRAP_DB);
27438 preempt_conditional_cli(regs);
27439 @@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27440 * We already checked v86 mode above, so we can check for kernel mode
27441 * by just checking the CPL of CS.
27442 */
27443 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27444 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27445 tsk->thread.debugreg6 &= ~DR_STEP;
27446 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27447 regs->flags &= ~X86_EFLAGS_TF;
27448 @@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27449 return;
27450 conditional_sti(regs);
27451
27452 - if (!user_mode_vm(regs))
27453 + if (!user_mode(regs))
27454 {
27455 if (!fixup_exception(regs)) {
27456 task->thread.error_code = error_code;
27457 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27458 index cfbe99f..a6e8fa7 100644
27459 --- a/arch/x86/kernel/tsc.c
27460 +++ b/arch/x86/kernel/tsc.c
27461 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27462 */
27463 smp_wmb();
27464
27465 - ACCESS_ONCE(c2n->head) = data;
27466 + ACCESS_ONCE_RW(c2n->head) = data;
27467 }
27468
27469 /*
27470 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27471 index 2ed8459..7cf329f 100644
27472 --- a/arch/x86/kernel/uprobes.c
27473 +++ b/arch/x86/kernel/uprobes.c
27474 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27475 int ret = NOTIFY_DONE;
27476
27477 /* We are only interested in userspace traps */
27478 - if (regs && !user_mode_vm(regs))
27479 + if (regs && !user_mode(regs))
27480 return NOTIFY_DONE;
27481
27482 switch (val) {
27483 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27484
27485 if (ncopied != rasize) {
27486 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27487 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27488 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27489
27490 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27491 }
27492 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27493 index b9242ba..50c5edd 100644
27494 --- a/arch/x86/kernel/verify_cpu.S
27495 +++ b/arch/x86/kernel/verify_cpu.S
27496 @@ -20,6 +20,7 @@
27497 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27498 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27499 * arch/x86/kernel/head_32.S: processor startup
27500 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27501 *
27502 * verify_cpu, returns the status of longmode and SSE in register %eax.
27503 * 0: Success 1: Failure
27504 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27505 index e8edcf5..27f9344 100644
27506 --- a/arch/x86/kernel/vm86_32.c
27507 +++ b/arch/x86/kernel/vm86_32.c
27508 @@ -44,6 +44,7 @@
27509 #include <linux/ptrace.h>
27510 #include <linux/audit.h>
27511 #include <linux/stddef.h>
27512 +#include <linux/grsecurity.h>
27513
27514 #include <asm/uaccess.h>
27515 #include <asm/io.h>
27516 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27517 do_exit(SIGSEGV);
27518 }
27519
27520 - tss = &per_cpu(init_tss, get_cpu());
27521 + tss = init_tss + get_cpu();
27522 current->thread.sp0 = current->thread.saved_sp0;
27523 current->thread.sysenter_cs = __KERNEL_CS;
27524 load_sp0(tss, &current->thread);
27525 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27526
27527 if (tsk->thread.saved_sp0)
27528 return -EPERM;
27529 +
27530 +#ifdef CONFIG_GRKERNSEC_VM86
27531 + if (!capable(CAP_SYS_RAWIO)) {
27532 + gr_handle_vm86();
27533 + return -EPERM;
27534 + }
27535 +#endif
27536 +
27537 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27538 offsetof(struct kernel_vm86_struct, vm86plus) -
27539 sizeof(info.regs));
27540 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27541 int tmp;
27542 struct vm86plus_struct __user *v86;
27543
27544 +#ifdef CONFIG_GRKERNSEC_VM86
27545 + if (!capable(CAP_SYS_RAWIO)) {
27546 + gr_handle_vm86();
27547 + return -EPERM;
27548 + }
27549 +#endif
27550 +
27551 tsk = current;
27552 switch (cmd) {
27553 case VM86_REQUEST_IRQ:
27554 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27555 tsk->thread.saved_fs = info->regs32->fs;
27556 tsk->thread.saved_gs = get_user_gs(info->regs32);
27557
27558 - tss = &per_cpu(init_tss, get_cpu());
27559 + tss = init_tss + get_cpu();
27560 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27561 if (cpu_has_sep)
27562 tsk->thread.sysenter_cs = 0;
27563 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27564 goto cannot_handle;
27565 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27566 goto cannot_handle;
27567 - intr_ptr = (unsigned long __user *) (i << 2);
27568 + intr_ptr = (__force unsigned long __user *) (i << 2);
27569 if (get_user(segoffs, intr_ptr))
27570 goto cannot_handle;
27571 if ((segoffs >> 16) == BIOSSEG)
27572 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27573 index da6b35a..977e9cf 100644
27574 --- a/arch/x86/kernel/vmlinux.lds.S
27575 +++ b/arch/x86/kernel/vmlinux.lds.S
27576 @@ -26,6 +26,13 @@
27577 #include <asm/page_types.h>
27578 #include <asm/cache.h>
27579 #include <asm/boot.h>
27580 +#include <asm/segment.h>
27581 +
27582 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27583 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27584 +#else
27585 +#define __KERNEL_TEXT_OFFSET 0
27586 +#endif
27587
27588 #undef i386 /* in case the preprocessor is a 32bit one */
27589
27590 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27591
27592 PHDRS {
27593 text PT_LOAD FLAGS(5); /* R_E */
27594 +#ifdef CONFIG_X86_32
27595 + module PT_LOAD FLAGS(5); /* R_E */
27596 +#endif
27597 +#ifdef CONFIG_XEN
27598 + rodata PT_LOAD FLAGS(5); /* R_E */
27599 +#else
27600 + rodata PT_LOAD FLAGS(4); /* R__ */
27601 +#endif
27602 data PT_LOAD FLAGS(6); /* RW_ */
27603 -#ifdef CONFIG_X86_64
27604 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27605 #ifdef CONFIG_SMP
27606 percpu PT_LOAD FLAGS(6); /* RW_ */
27607 #endif
27608 + text.init PT_LOAD FLAGS(5); /* R_E */
27609 + text.exit PT_LOAD FLAGS(5); /* R_E */
27610 init PT_LOAD FLAGS(7); /* RWE */
27611 -#endif
27612 note PT_NOTE FLAGS(0); /* ___ */
27613 }
27614
27615 SECTIONS
27616 {
27617 #ifdef CONFIG_X86_32
27618 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27619 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27620 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27621 #else
27622 - . = __START_KERNEL;
27623 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27624 + . = __START_KERNEL;
27625 #endif
27626
27627 /* Text and read-only data */
27628 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27629 - _text = .;
27630 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27631 /* bootstrapping code */
27632 +#ifdef CONFIG_X86_32
27633 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27634 +#else
27635 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27636 +#endif
27637 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27638 + _text = .;
27639 HEAD_TEXT
27640 . = ALIGN(8);
27641 _stext = .;
27642 @@ -104,13 +124,47 @@ SECTIONS
27643 IRQENTRY_TEXT
27644 *(.fixup)
27645 *(.gnu.warning)
27646 - /* End of text section */
27647 - _etext = .;
27648 } :text = 0x9090
27649
27650 - NOTES :text :note
27651 + . += __KERNEL_TEXT_OFFSET;
27652
27653 - EXCEPTION_TABLE(16) :text = 0x9090
27654 +#ifdef CONFIG_X86_32
27655 + . = ALIGN(PAGE_SIZE);
27656 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27657 +
27658 +#ifdef CONFIG_PAX_KERNEXEC
27659 + MODULES_EXEC_VADDR = .;
27660 + BYTE(0)
27661 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27662 + . = ALIGN(HPAGE_SIZE) - 1;
27663 + MODULES_EXEC_END = .;
27664 +#endif
27665 +
27666 + } :module
27667 +#endif
27668 +
27669 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27670 + /* End of text section */
27671 + BYTE(0)
27672 + _etext = . - __KERNEL_TEXT_OFFSET;
27673 + }
27674 +
27675 +#ifdef CONFIG_X86_32
27676 + . = ALIGN(PAGE_SIZE);
27677 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27678 + . = ALIGN(PAGE_SIZE);
27679 + *(.empty_zero_page)
27680 + *(.initial_pg_fixmap)
27681 + *(.initial_pg_pmd)
27682 + *(.initial_page_table)
27683 + *(.swapper_pg_dir)
27684 + } :rodata
27685 +#endif
27686 +
27687 + . = ALIGN(PAGE_SIZE);
27688 + NOTES :rodata :note
27689 +
27690 + EXCEPTION_TABLE(16) :rodata
27691
27692 #if defined(CONFIG_DEBUG_RODATA)
27693 /* .text should occupy whole number of pages */
27694 @@ -122,16 +176,20 @@ SECTIONS
27695
27696 /* Data */
27697 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27698 +
27699 +#ifdef CONFIG_PAX_KERNEXEC
27700 + . = ALIGN(HPAGE_SIZE);
27701 +#else
27702 + . = ALIGN(PAGE_SIZE);
27703 +#endif
27704 +
27705 /* Start of data section */
27706 _sdata = .;
27707
27708 /* init_task */
27709 INIT_TASK_DATA(THREAD_SIZE)
27710
27711 -#ifdef CONFIG_X86_32
27712 - /* 32 bit has nosave before _edata */
27713 NOSAVE_DATA
27714 -#endif
27715
27716 PAGE_ALIGNED_DATA(PAGE_SIZE)
27717
27718 @@ -172,12 +230,19 @@ SECTIONS
27719 #endif /* CONFIG_X86_64 */
27720
27721 /* Init code and data - will be freed after init */
27722 - . = ALIGN(PAGE_SIZE);
27723 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27724 + BYTE(0)
27725 +
27726 +#ifdef CONFIG_PAX_KERNEXEC
27727 + . = ALIGN(HPAGE_SIZE);
27728 +#else
27729 + . = ALIGN(PAGE_SIZE);
27730 +#endif
27731 +
27732 __init_begin = .; /* paired with __init_end */
27733 - }
27734 + } :init.begin
27735
27736 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27737 +#ifdef CONFIG_SMP
27738 /*
27739 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27740 * output PHDR, so the next output section - .init.text - should
27741 @@ -186,12 +251,27 @@ SECTIONS
27742 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27743 #endif
27744
27745 - INIT_TEXT_SECTION(PAGE_SIZE)
27746 -#ifdef CONFIG_X86_64
27747 - :init
27748 -#endif
27749 + . = ALIGN(PAGE_SIZE);
27750 + init_begin = .;
27751 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27752 + VMLINUX_SYMBOL(_sinittext) = .;
27753 + INIT_TEXT
27754 + VMLINUX_SYMBOL(_einittext) = .;
27755 + . = ALIGN(PAGE_SIZE);
27756 + } :text.init
27757
27758 - INIT_DATA_SECTION(16)
27759 + /*
27760 + * .exit.text is discard at runtime, not link time, to deal with
27761 + * references from .altinstructions and .eh_frame
27762 + */
27763 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27764 + EXIT_TEXT
27765 + . = ALIGN(16);
27766 + } :text.exit
27767 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27768 +
27769 + . = ALIGN(PAGE_SIZE);
27770 + INIT_DATA_SECTION(16) :init
27771
27772 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27773 __x86_cpu_dev_start = .;
27774 @@ -262,19 +342,12 @@ SECTIONS
27775 }
27776
27777 . = ALIGN(8);
27778 - /*
27779 - * .exit.text is discard at runtime, not link time, to deal with
27780 - * references from .altinstructions and .eh_frame
27781 - */
27782 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27783 - EXIT_TEXT
27784 - }
27785
27786 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27787 EXIT_DATA
27788 }
27789
27790 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27791 +#ifndef CONFIG_SMP
27792 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27793 #endif
27794
27795 @@ -293,16 +366,10 @@ SECTIONS
27796 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27797 __smp_locks = .;
27798 *(.smp_locks)
27799 - . = ALIGN(PAGE_SIZE);
27800 __smp_locks_end = .;
27801 + . = ALIGN(PAGE_SIZE);
27802 }
27803
27804 -#ifdef CONFIG_X86_64
27805 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27806 - NOSAVE_DATA
27807 - }
27808 -#endif
27809 -
27810 /* BSS */
27811 . = ALIGN(PAGE_SIZE);
27812 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27813 @@ -318,6 +385,7 @@ SECTIONS
27814 __brk_base = .;
27815 . += 64 * 1024; /* 64k alignment slop space */
27816 *(.brk_reservation) /* areas brk users have reserved */
27817 + . = ALIGN(HPAGE_SIZE);
27818 __brk_limit = .;
27819 }
27820
27821 @@ -344,13 +412,12 @@ SECTIONS
27822 * for the boot processor.
27823 */
27824 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27825 -INIT_PER_CPU(gdt_page);
27826 INIT_PER_CPU(irq_stack_union);
27827
27828 /*
27829 * Build-time check on the image size:
27830 */
27831 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27832 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27833 "kernel image bigger than KERNEL_IMAGE_SIZE");
27834
27835 #ifdef CONFIG_SMP
27836 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27837 index 1f96f93..d5c8f7a 100644
27838 --- a/arch/x86/kernel/vsyscall_64.c
27839 +++ b/arch/x86/kernel/vsyscall_64.c
27840 @@ -56,15 +56,13 @@
27841 DEFINE_VVAR(int, vgetcpu_mode);
27842 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27843
27844 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27845 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27846
27847 static int __init vsyscall_setup(char *str)
27848 {
27849 if (str) {
27850 if (!strcmp("emulate", str))
27851 vsyscall_mode = EMULATE;
27852 - else if (!strcmp("native", str))
27853 - vsyscall_mode = NATIVE;
27854 else if (!strcmp("none", str))
27855 vsyscall_mode = NONE;
27856 else
27857 @@ -323,8 +321,7 @@ do_ret:
27858 return true;
27859
27860 sigsegv:
27861 - force_sig(SIGSEGV, current);
27862 - return true;
27863 + do_group_exit(SIGKILL);
27864 }
27865
27866 /*
27867 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27868 extern char __vvar_page;
27869 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27870
27871 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27872 - vsyscall_mode == NATIVE
27873 - ? PAGE_KERNEL_VSYSCALL
27874 - : PAGE_KERNEL_VVAR);
27875 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27876 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27877 (unsigned long)VSYSCALL_START);
27878
27879 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27880 index 04068192..4d75aa6 100644
27881 --- a/arch/x86/kernel/x8664_ksyms_64.c
27882 +++ b/arch/x86/kernel/x8664_ksyms_64.c
27883 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27884 EXPORT_SYMBOL(copy_user_generic_unrolled);
27885 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27886 EXPORT_SYMBOL(__copy_user_nocache);
27887 -EXPORT_SYMBOL(_copy_from_user);
27888 -EXPORT_SYMBOL(_copy_to_user);
27889
27890 EXPORT_SYMBOL(copy_page);
27891 EXPORT_SYMBOL(clear_page);
27892 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27893 EXPORT_SYMBOL(___preempt_schedule_context);
27894 #endif
27895 #endif
27896 +
27897 +#ifdef CONFIG_PAX_PER_CPU_PGD
27898 +EXPORT_SYMBOL(cpu_pgd);
27899 +#endif
27900 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27901 index e48b674..a451dd9 100644
27902 --- a/arch/x86/kernel/x86_init.c
27903 +++ b/arch/x86/kernel/x86_init.c
27904 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27905 static void default_nmi_init(void) { };
27906 static int default_i8042_detect(void) { return 1; };
27907
27908 -struct x86_platform_ops x86_platform = {
27909 +struct x86_platform_ops x86_platform __read_only = {
27910 .calibrate_tsc = native_calibrate_tsc,
27911 .get_wallclock = mach_get_cmos_time,
27912 .set_wallclock = mach_set_rtc_mmss,
27913 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27914 EXPORT_SYMBOL_GPL(x86_platform);
27915
27916 #if defined(CONFIG_PCI_MSI)
27917 -struct x86_msi_ops x86_msi = {
27918 +struct x86_msi_ops x86_msi __read_only = {
27919 .setup_msi_irqs = native_setup_msi_irqs,
27920 .compose_msi_msg = native_compose_msi_msg,
27921 .teardown_msi_irq = native_teardown_msi_irq,
27922 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27923 }
27924 #endif
27925
27926 -struct x86_io_apic_ops x86_io_apic_ops = {
27927 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27928 .init = native_io_apic_init_mappings,
27929 .read = native_io_apic_read,
27930 .write = native_io_apic_write,
27931 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27932 index a4b451c..8dfe1ad 100644
27933 --- a/arch/x86/kernel/xsave.c
27934 +++ b/arch/x86/kernel/xsave.c
27935 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27936
27937 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27938 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27939 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27940 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27941
27942 if (!use_xsave())
27943 return err;
27944
27945 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27946 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27947
27948 /*
27949 * Read the xstate_bv which we copied (directly from the cpu or
27950 * from the state in task struct) to the user buffers.
27951 */
27952 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27953 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27954
27955 /*
27956 * For legacy compatible, we always set FP/SSE bits in the bit
27957 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27958 */
27959 xstate_bv |= XSTATE_FPSSE;
27960
27961 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27962 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27963
27964 return err;
27965 }
27966 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
27967 {
27968 int err;
27969
27970 + buf = (struct xsave_struct __user *)____m(buf);
27971 if (use_xsave())
27972 err = xsave_user(buf);
27973 else if (use_fxsr())
27974 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
27975 */
27976 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
27977 {
27978 + buf = (void __user *)____m(buf);
27979 if (use_xsave()) {
27980 if ((unsigned long)buf % 64 || fx_only) {
27981 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
27982 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
27983 index c697625..a032162 100644
27984 --- a/arch/x86/kvm/cpuid.c
27985 +++ b/arch/x86/kvm/cpuid.c
27986 @@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
27987 struct kvm_cpuid2 *cpuid,
27988 struct kvm_cpuid_entry2 __user *entries)
27989 {
27990 - int r;
27991 + int r, i;
27992
27993 r = -E2BIG;
27994 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
27995 goto out;
27996 r = -EFAULT;
27997 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
27998 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27999 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28000 goto out;
28001 + for (i = 0; i < cpuid->nent; ++i) {
28002 + struct kvm_cpuid_entry2 cpuid_entry;
28003 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28004 + goto out;
28005 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28006 + }
28007 vcpu->arch.cpuid_nent = cpuid->nent;
28008 kvm_apic_set_version(vcpu);
28009 kvm_x86_ops->cpuid_update(vcpu);
28010 @@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28011 struct kvm_cpuid2 *cpuid,
28012 struct kvm_cpuid_entry2 __user *entries)
28013 {
28014 - int r;
28015 + int r, i;
28016
28017 r = -E2BIG;
28018 if (cpuid->nent < vcpu->arch.cpuid_nent)
28019 goto out;
28020 r = -EFAULT;
28021 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28022 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28023 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28024 goto out;
28025 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28026 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28027 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28028 + goto out;
28029 + }
28030 return 0;
28031
28032 out:
28033 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28034 index 9736529..ab4f54c 100644
28035 --- a/arch/x86/kvm/lapic.c
28036 +++ b/arch/x86/kvm/lapic.c
28037 @@ -55,7 +55,7 @@
28038 #define APIC_BUS_CYCLE_NS 1
28039
28040 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28041 -#define apic_debug(fmt, arg...)
28042 +#define apic_debug(fmt, arg...) do {} while (0)
28043
28044 #define APIC_LVT_NUM 6
28045 /* 14 is the version for Xeon and Pentium 8.4.8*/
28046 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28047 index cba218a..1cc1bed 100644
28048 --- a/arch/x86/kvm/paging_tmpl.h
28049 +++ b/arch/x86/kvm/paging_tmpl.h
28050 @@ -331,7 +331,7 @@ retry_walk:
28051 if (unlikely(kvm_is_error_hva(host_addr)))
28052 goto error;
28053
28054 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28055 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28056 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28057 goto error;
28058 walker->ptep_user[walker->level - 1] = ptep_user;
28059 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28060 index 2de1bc0..22251ee 100644
28061 --- a/arch/x86/kvm/svm.c
28062 +++ b/arch/x86/kvm/svm.c
28063 @@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28064 int cpu = raw_smp_processor_id();
28065
28066 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28067 +
28068 + pax_open_kernel();
28069 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28070 + pax_close_kernel();
28071 +
28072 load_TR_desc();
28073 }
28074
28075 @@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28076 #endif
28077 #endif
28078
28079 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28080 + __set_fs(current_thread_info()->addr_limit);
28081 +#endif
28082 +
28083 reload_tss(vcpu);
28084
28085 local_irq_disable();
28086 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28087 index 3927528..fc19971 100644
28088 --- a/arch/x86/kvm/vmx.c
28089 +++ b/arch/x86/kvm/vmx.c
28090 @@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28091 #endif
28092 }
28093
28094 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28095 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28096 {
28097 vmcs_writel(field, vmcs_readl(field) & ~mask);
28098 }
28099
28100 -static void vmcs_set_bits(unsigned long field, u32 mask)
28101 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28102 {
28103 vmcs_writel(field, vmcs_readl(field) | mask);
28104 }
28105 @@ -1585,7 +1585,11 @@ static void reload_tss(void)
28106 struct desc_struct *descs;
28107
28108 descs = (void *)gdt->address;
28109 +
28110 + pax_open_kernel();
28111 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28112 + pax_close_kernel();
28113 +
28114 load_TR_desc();
28115 }
28116
28117 @@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28118 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28119 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28120
28121 +#ifdef CONFIG_PAX_PER_CPU_PGD
28122 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28123 +#endif
28124 +
28125 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28126 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28127 vmx->loaded_vmcs->cpu = cpu;
28128 @@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28129 * reads and returns guest's timestamp counter "register"
28130 * guest_tsc = host_tsc + tsc_offset -- 21.3
28131 */
28132 -static u64 guest_read_tsc(void)
28133 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28134 {
28135 u64 host_tsc, tsc_offset;
28136
28137 @@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28138 if (!cpu_has_vmx_flexpriority())
28139 flexpriority_enabled = 0;
28140
28141 - if (!cpu_has_vmx_tpr_shadow())
28142 - kvm_x86_ops->update_cr8_intercept = NULL;
28143 + if (!cpu_has_vmx_tpr_shadow()) {
28144 + pax_open_kernel();
28145 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28146 + pax_close_kernel();
28147 + }
28148
28149 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28150 kvm_disable_largepages();
28151 @@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28152 if (!cpu_has_vmx_apicv())
28153 enable_apicv = 0;
28154
28155 + pax_open_kernel();
28156 if (enable_apicv)
28157 - kvm_x86_ops->update_cr8_intercept = NULL;
28158 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28159 else {
28160 - kvm_x86_ops->hwapic_irr_update = NULL;
28161 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28162 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28163 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28164 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28165 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28166 }
28167 + pax_close_kernel();
28168
28169 if (nested)
28170 nested_vmx_setup_ctls_msrs();
28171 @@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28172
28173 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28174 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28175 +
28176 +#ifndef CONFIG_PAX_PER_CPU_PGD
28177 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28178 +#endif
28179
28180 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28181 #ifdef CONFIG_X86_64
28182 @@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28183 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28184 vmx->host_idt_base = dt.address;
28185
28186 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28187 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28188
28189 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28190 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28191 @@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28192 "jmp 2f \n\t"
28193 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28194 "2: "
28195 +
28196 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28197 + "ljmp %[cs],$3f\n\t"
28198 + "3: "
28199 +#endif
28200 +
28201 /* Save guest registers, load host registers, keep flags */
28202 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28203 "pop %0 \n\t"
28204 @@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28205 #endif
28206 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28207 [wordsize]"i"(sizeof(ulong))
28208 +
28209 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28210 + ,[cs]"i"(__KERNEL_CS)
28211 +#endif
28212 +
28213 : "cc", "memory"
28214 #ifdef CONFIG_X86_64
28215 , "rax", "rbx", "rdi", "rsi"
28216 @@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28217 if (debugctlmsr)
28218 update_debugctlmsr(debugctlmsr);
28219
28220 -#ifndef CONFIG_X86_64
28221 +#ifdef CONFIG_X86_32
28222 /*
28223 * The sysexit path does not restore ds/es, so we must set them to
28224 * a reasonable value ourselves.
28225 @@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28226 * may be executed in interrupt context, which saves and restore segments
28227 * around it, nullifying its effect.
28228 */
28229 - loadsegment(ds, __USER_DS);
28230 - loadsegment(es, __USER_DS);
28231 + loadsegment(ds, __KERNEL_DS);
28232 + loadsegment(es, __KERNEL_DS);
28233 + loadsegment(ss, __KERNEL_DS);
28234 +
28235 +#ifdef CONFIG_PAX_KERNEXEC
28236 + loadsegment(fs, __KERNEL_PERCPU);
28237 +#endif
28238 +
28239 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28240 + __set_fs(current_thread_info()->addr_limit);
28241 +#endif
28242 +
28243 #endif
28244
28245 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28246 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28247 index 2b85784..ad70e19 100644
28248 --- a/arch/x86/kvm/x86.c
28249 +++ b/arch/x86/kvm/x86.c
28250 @@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28251 {
28252 struct kvm *kvm = vcpu->kvm;
28253 int lm = is_long_mode(vcpu);
28254 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28255 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28256 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28257 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28258 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28259 : kvm->arch.xen_hvm_config.blob_size_32;
28260 u32 page_num = data & ~PAGE_MASK;
28261 @@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28262 if (n < msr_list.nmsrs)
28263 goto out;
28264 r = -EFAULT;
28265 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28266 + goto out;
28267 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28268 num_msrs_to_save * sizeof(u32)))
28269 goto out;
28270 @@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28271 };
28272 #endif
28273
28274 -int kvm_arch_init(void *opaque)
28275 +int kvm_arch_init(const void *opaque)
28276 {
28277 int r;
28278 struct kvm_x86_ops *ops = opaque;
28279 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28280 index ad1fb5f..fe30b66 100644
28281 --- a/arch/x86/lguest/boot.c
28282 +++ b/arch/x86/lguest/boot.c
28283 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28284 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28285 * Launcher to reboot us.
28286 */
28287 -static void lguest_restart(char *reason)
28288 +static __noreturn void lguest_restart(char *reason)
28289 {
28290 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28291 + BUG();
28292 }
28293
28294 /*G:050
28295 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28296 index 00933d5..3a64af9 100644
28297 --- a/arch/x86/lib/atomic64_386_32.S
28298 +++ b/arch/x86/lib/atomic64_386_32.S
28299 @@ -48,6 +48,10 @@ BEGIN(read)
28300 movl (v), %eax
28301 movl 4(v), %edx
28302 RET_ENDP
28303 +BEGIN(read_unchecked)
28304 + movl (v), %eax
28305 + movl 4(v), %edx
28306 +RET_ENDP
28307 #undef v
28308
28309 #define v %esi
28310 @@ -55,6 +59,10 @@ BEGIN(set)
28311 movl %ebx, (v)
28312 movl %ecx, 4(v)
28313 RET_ENDP
28314 +BEGIN(set_unchecked)
28315 + movl %ebx, (v)
28316 + movl %ecx, 4(v)
28317 +RET_ENDP
28318 #undef v
28319
28320 #define v %esi
28321 @@ -70,6 +78,20 @@ RET_ENDP
28322 BEGIN(add)
28323 addl %eax, (v)
28324 adcl %edx, 4(v)
28325 +
28326 +#ifdef CONFIG_PAX_REFCOUNT
28327 + jno 0f
28328 + subl %eax, (v)
28329 + sbbl %edx, 4(v)
28330 + int $4
28331 +0:
28332 + _ASM_EXTABLE(0b, 0b)
28333 +#endif
28334 +
28335 +RET_ENDP
28336 +BEGIN(add_unchecked)
28337 + addl %eax, (v)
28338 + adcl %edx, 4(v)
28339 RET_ENDP
28340 #undef v
28341
28342 @@ -77,6 +99,24 @@ RET_ENDP
28343 BEGIN(add_return)
28344 addl (v), %eax
28345 adcl 4(v), %edx
28346 +
28347 +#ifdef CONFIG_PAX_REFCOUNT
28348 + into
28349 +1234:
28350 + _ASM_EXTABLE(1234b, 2f)
28351 +#endif
28352 +
28353 + movl %eax, (v)
28354 + movl %edx, 4(v)
28355 +
28356 +#ifdef CONFIG_PAX_REFCOUNT
28357 +2:
28358 +#endif
28359 +
28360 +RET_ENDP
28361 +BEGIN(add_return_unchecked)
28362 + addl (v), %eax
28363 + adcl 4(v), %edx
28364 movl %eax, (v)
28365 movl %edx, 4(v)
28366 RET_ENDP
28367 @@ -86,6 +126,20 @@ RET_ENDP
28368 BEGIN(sub)
28369 subl %eax, (v)
28370 sbbl %edx, 4(v)
28371 +
28372 +#ifdef CONFIG_PAX_REFCOUNT
28373 + jno 0f
28374 + addl %eax, (v)
28375 + adcl %edx, 4(v)
28376 + int $4
28377 +0:
28378 + _ASM_EXTABLE(0b, 0b)
28379 +#endif
28380 +
28381 +RET_ENDP
28382 +BEGIN(sub_unchecked)
28383 + subl %eax, (v)
28384 + sbbl %edx, 4(v)
28385 RET_ENDP
28386 #undef v
28387
28388 @@ -96,6 +150,27 @@ BEGIN(sub_return)
28389 sbbl $0, %edx
28390 addl (v), %eax
28391 adcl 4(v), %edx
28392 +
28393 +#ifdef CONFIG_PAX_REFCOUNT
28394 + into
28395 +1234:
28396 + _ASM_EXTABLE(1234b, 2f)
28397 +#endif
28398 +
28399 + movl %eax, (v)
28400 + movl %edx, 4(v)
28401 +
28402 +#ifdef CONFIG_PAX_REFCOUNT
28403 +2:
28404 +#endif
28405 +
28406 +RET_ENDP
28407 +BEGIN(sub_return_unchecked)
28408 + negl %edx
28409 + negl %eax
28410 + sbbl $0, %edx
28411 + addl (v), %eax
28412 + adcl 4(v), %edx
28413 movl %eax, (v)
28414 movl %edx, 4(v)
28415 RET_ENDP
28416 @@ -105,6 +180,20 @@ RET_ENDP
28417 BEGIN(inc)
28418 addl $1, (v)
28419 adcl $0, 4(v)
28420 +
28421 +#ifdef CONFIG_PAX_REFCOUNT
28422 + jno 0f
28423 + subl $1, (v)
28424 + sbbl $0, 4(v)
28425 + int $4
28426 +0:
28427 + _ASM_EXTABLE(0b, 0b)
28428 +#endif
28429 +
28430 +RET_ENDP
28431 +BEGIN(inc_unchecked)
28432 + addl $1, (v)
28433 + adcl $0, 4(v)
28434 RET_ENDP
28435 #undef v
28436
28437 @@ -114,6 +203,26 @@ BEGIN(inc_return)
28438 movl 4(v), %edx
28439 addl $1, %eax
28440 adcl $0, %edx
28441 +
28442 +#ifdef CONFIG_PAX_REFCOUNT
28443 + into
28444 +1234:
28445 + _ASM_EXTABLE(1234b, 2f)
28446 +#endif
28447 +
28448 + movl %eax, (v)
28449 + movl %edx, 4(v)
28450 +
28451 +#ifdef CONFIG_PAX_REFCOUNT
28452 +2:
28453 +#endif
28454 +
28455 +RET_ENDP
28456 +BEGIN(inc_return_unchecked)
28457 + movl (v), %eax
28458 + movl 4(v), %edx
28459 + addl $1, %eax
28460 + adcl $0, %edx
28461 movl %eax, (v)
28462 movl %edx, 4(v)
28463 RET_ENDP
28464 @@ -123,6 +232,20 @@ RET_ENDP
28465 BEGIN(dec)
28466 subl $1, (v)
28467 sbbl $0, 4(v)
28468 +
28469 +#ifdef CONFIG_PAX_REFCOUNT
28470 + jno 0f
28471 + addl $1, (v)
28472 + adcl $0, 4(v)
28473 + int $4
28474 +0:
28475 + _ASM_EXTABLE(0b, 0b)
28476 +#endif
28477 +
28478 +RET_ENDP
28479 +BEGIN(dec_unchecked)
28480 + subl $1, (v)
28481 + sbbl $0, 4(v)
28482 RET_ENDP
28483 #undef v
28484
28485 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28486 movl 4(v), %edx
28487 subl $1, %eax
28488 sbbl $0, %edx
28489 +
28490 +#ifdef CONFIG_PAX_REFCOUNT
28491 + into
28492 +1234:
28493 + _ASM_EXTABLE(1234b, 2f)
28494 +#endif
28495 +
28496 + movl %eax, (v)
28497 + movl %edx, 4(v)
28498 +
28499 +#ifdef CONFIG_PAX_REFCOUNT
28500 +2:
28501 +#endif
28502 +
28503 +RET_ENDP
28504 +BEGIN(dec_return_unchecked)
28505 + movl (v), %eax
28506 + movl 4(v), %edx
28507 + subl $1, %eax
28508 + sbbl $0, %edx
28509 movl %eax, (v)
28510 movl %edx, 4(v)
28511 RET_ENDP
28512 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28513 adcl %edx, %edi
28514 addl (v), %eax
28515 adcl 4(v), %edx
28516 +
28517 +#ifdef CONFIG_PAX_REFCOUNT
28518 + into
28519 +1234:
28520 + _ASM_EXTABLE(1234b, 2f)
28521 +#endif
28522 +
28523 cmpl %eax, %ecx
28524 je 3f
28525 1:
28526 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28527 1:
28528 addl $1, %eax
28529 adcl $0, %edx
28530 +
28531 +#ifdef CONFIG_PAX_REFCOUNT
28532 + into
28533 +1234:
28534 + _ASM_EXTABLE(1234b, 2f)
28535 +#endif
28536 +
28537 movl %eax, (v)
28538 movl %edx, 4(v)
28539 movl $1, %eax
28540 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28541 movl 4(v), %edx
28542 subl $1, %eax
28543 sbbl $0, %edx
28544 +
28545 +#ifdef CONFIG_PAX_REFCOUNT
28546 + into
28547 +1234:
28548 + _ASM_EXTABLE(1234b, 1f)
28549 +#endif
28550 +
28551 js 1f
28552 movl %eax, (v)
28553 movl %edx, 4(v)
28554 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28555 index f5cc9eb..51fa319 100644
28556 --- a/arch/x86/lib/atomic64_cx8_32.S
28557 +++ b/arch/x86/lib/atomic64_cx8_32.S
28558 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28559 CFI_STARTPROC
28560
28561 read64 %ecx
28562 + pax_force_retaddr
28563 ret
28564 CFI_ENDPROC
28565 ENDPROC(atomic64_read_cx8)
28566
28567 +ENTRY(atomic64_read_unchecked_cx8)
28568 + CFI_STARTPROC
28569 +
28570 + read64 %ecx
28571 + pax_force_retaddr
28572 + ret
28573 + CFI_ENDPROC
28574 +ENDPROC(atomic64_read_unchecked_cx8)
28575 +
28576 ENTRY(atomic64_set_cx8)
28577 CFI_STARTPROC
28578
28579 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28580 cmpxchg8b (%esi)
28581 jne 1b
28582
28583 + pax_force_retaddr
28584 ret
28585 CFI_ENDPROC
28586 ENDPROC(atomic64_set_cx8)
28587
28588 +ENTRY(atomic64_set_unchecked_cx8)
28589 + CFI_STARTPROC
28590 +
28591 +1:
28592 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28593 + * are atomic on 586 and newer */
28594 + cmpxchg8b (%esi)
28595 + jne 1b
28596 +
28597 + pax_force_retaddr
28598 + ret
28599 + CFI_ENDPROC
28600 +ENDPROC(atomic64_set_unchecked_cx8)
28601 +
28602 ENTRY(atomic64_xchg_cx8)
28603 CFI_STARTPROC
28604
28605 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28606 cmpxchg8b (%esi)
28607 jne 1b
28608
28609 + pax_force_retaddr
28610 ret
28611 CFI_ENDPROC
28612 ENDPROC(atomic64_xchg_cx8)
28613
28614 -.macro addsub_return func ins insc
28615 -ENTRY(atomic64_\func\()_return_cx8)
28616 +.macro addsub_return func ins insc unchecked=""
28617 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28618 CFI_STARTPROC
28619 SAVE ebp
28620 SAVE ebx
28621 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28622 movl %edx, %ecx
28623 \ins\()l %esi, %ebx
28624 \insc\()l %edi, %ecx
28625 +
28626 +.ifb \unchecked
28627 +#ifdef CONFIG_PAX_REFCOUNT
28628 + into
28629 +2:
28630 + _ASM_EXTABLE(2b, 3f)
28631 +#endif
28632 +.endif
28633 +
28634 LOCK_PREFIX
28635 cmpxchg8b (%ebp)
28636 jne 1b
28637 -
28638 -10:
28639 movl %ebx, %eax
28640 movl %ecx, %edx
28641 +
28642 +.ifb \unchecked
28643 +#ifdef CONFIG_PAX_REFCOUNT
28644 +3:
28645 +#endif
28646 +.endif
28647 +
28648 RESTORE edi
28649 RESTORE esi
28650 RESTORE ebx
28651 RESTORE ebp
28652 + pax_force_retaddr
28653 ret
28654 CFI_ENDPROC
28655 -ENDPROC(atomic64_\func\()_return_cx8)
28656 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28657 .endm
28658
28659 addsub_return add add adc
28660 addsub_return sub sub sbb
28661 +addsub_return add add adc _unchecked
28662 +addsub_return sub sub sbb _unchecked
28663
28664 -.macro incdec_return func ins insc
28665 -ENTRY(atomic64_\func\()_return_cx8)
28666 +.macro incdec_return func ins insc unchecked=""
28667 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28668 CFI_STARTPROC
28669 SAVE ebx
28670
28671 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28672 movl %edx, %ecx
28673 \ins\()l $1, %ebx
28674 \insc\()l $0, %ecx
28675 +
28676 +.ifb \unchecked
28677 +#ifdef CONFIG_PAX_REFCOUNT
28678 + into
28679 +2:
28680 + _ASM_EXTABLE(2b, 3f)
28681 +#endif
28682 +.endif
28683 +
28684 LOCK_PREFIX
28685 cmpxchg8b (%esi)
28686 jne 1b
28687
28688 -10:
28689 movl %ebx, %eax
28690 movl %ecx, %edx
28691 +
28692 +.ifb \unchecked
28693 +#ifdef CONFIG_PAX_REFCOUNT
28694 +3:
28695 +#endif
28696 +.endif
28697 +
28698 RESTORE ebx
28699 + pax_force_retaddr
28700 ret
28701 CFI_ENDPROC
28702 -ENDPROC(atomic64_\func\()_return_cx8)
28703 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28704 .endm
28705
28706 incdec_return inc add adc
28707 incdec_return dec sub sbb
28708 +incdec_return inc add adc _unchecked
28709 +incdec_return dec sub sbb _unchecked
28710
28711 ENTRY(atomic64_dec_if_positive_cx8)
28712 CFI_STARTPROC
28713 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28714 movl %edx, %ecx
28715 subl $1, %ebx
28716 sbb $0, %ecx
28717 +
28718 +#ifdef CONFIG_PAX_REFCOUNT
28719 + into
28720 +1234:
28721 + _ASM_EXTABLE(1234b, 2f)
28722 +#endif
28723 +
28724 js 2f
28725 LOCK_PREFIX
28726 cmpxchg8b (%esi)
28727 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28728 movl %ebx, %eax
28729 movl %ecx, %edx
28730 RESTORE ebx
28731 + pax_force_retaddr
28732 ret
28733 CFI_ENDPROC
28734 ENDPROC(atomic64_dec_if_positive_cx8)
28735 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28736 movl %edx, %ecx
28737 addl %ebp, %ebx
28738 adcl %edi, %ecx
28739 +
28740 +#ifdef CONFIG_PAX_REFCOUNT
28741 + into
28742 +1234:
28743 + _ASM_EXTABLE(1234b, 3f)
28744 +#endif
28745 +
28746 LOCK_PREFIX
28747 cmpxchg8b (%esi)
28748 jne 1b
28749 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28750 CFI_ADJUST_CFA_OFFSET -8
28751 RESTORE ebx
28752 RESTORE ebp
28753 + pax_force_retaddr
28754 ret
28755 4:
28756 cmpl %edx, 4(%esp)
28757 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28758 xorl %ecx, %ecx
28759 addl $1, %ebx
28760 adcl %edx, %ecx
28761 +
28762 +#ifdef CONFIG_PAX_REFCOUNT
28763 + into
28764 +1234:
28765 + _ASM_EXTABLE(1234b, 3f)
28766 +#endif
28767 +
28768 LOCK_PREFIX
28769 cmpxchg8b (%esi)
28770 jne 1b
28771 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28772 movl $1, %eax
28773 3:
28774 RESTORE ebx
28775 + pax_force_retaddr
28776 ret
28777 CFI_ENDPROC
28778 ENDPROC(atomic64_inc_not_zero_cx8)
28779 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28780 index e78b8ee..7e173a8 100644
28781 --- a/arch/x86/lib/checksum_32.S
28782 +++ b/arch/x86/lib/checksum_32.S
28783 @@ -29,7 +29,8 @@
28784 #include <asm/dwarf2.h>
28785 #include <asm/errno.h>
28786 #include <asm/asm.h>
28787 -
28788 +#include <asm/segment.h>
28789 +
28790 /*
28791 * computes a partial checksum, e.g. for TCP/UDP fragments
28792 */
28793 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28794
28795 #define ARGBASE 16
28796 #define FP 12
28797 -
28798 -ENTRY(csum_partial_copy_generic)
28799 +
28800 +ENTRY(csum_partial_copy_generic_to_user)
28801 CFI_STARTPROC
28802 +
28803 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28804 + pushl_cfi %gs
28805 + popl_cfi %es
28806 + jmp csum_partial_copy_generic
28807 +#endif
28808 +
28809 +ENTRY(csum_partial_copy_generic_from_user)
28810 +
28811 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28812 + pushl_cfi %gs
28813 + popl_cfi %ds
28814 +#endif
28815 +
28816 +ENTRY(csum_partial_copy_generic)
28817 subl $4,%esp
28818 CFI_ADJUST_CFA_OFFSET 4
28819 pushl_cfi %edi
28820 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28821 jmp 4f
28822 SRC(1: movw (%esi), %bx )
28823 addl $2, %esi
28824 -DST( movw %bx, (%edi) )
28825 +DST( movw %bx, %es:(%edi) )
28826 addl $2, %edi
28827 addw %bx, %ax
28828 adcl $0, %eax
28829 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28830 SRC(1: movl (%esi), %ebx )
28831 SRC( movl 4(%esi), %edx )
28832 adcl %ebx, %eax
28833 -DST( movl %ebx, (%edi) )
28834 +DST( movl %ebx, %es:(%edi) )
28835 adcl %edx, %eax
28836 -DST( movl %edx, 4(%edi) )
28837 +DST( movl %edx, %es:4(%edi) )
28838
28839 SRC( movl 8(%esi), %ebx )
28840 SRC( movl 12(%esi), %edx )
28841 adcl %ebx, %eax
28842 -DST( movl %ebx, 8(%edi) )
28843 +DST( movl %ebx, %es:8(%edi) )
28844 adcl %edx, %eax
28845 -DST( movl %edx, 12(%edi) )
28846 +DST( movl %edx, %es:12(%edi) )
28847
28848 SRC( movl 16(%esi), %ebx )
28849 SRC( movl 20(%esi), %edx )
28850 adcl %ebx, %eax
28851 -DST( movl %ebx, 16(%edi) )
28852 +DST( movl %ebx, %es:16(%edi) )
28853 adcl %edx, %eax
28854 -DST( movl %edx, 20(%edi) )
28855 +DST( movl %edx, %es:20(%edi) )
28856
28857 SRC( movl 24(%esi), %ebx )
28858 SRC( movl 28(%esi), %edx )
28859 adcl %ebx, %eax
28860 -DST( movl %ebx, 24(%edi) )
28861 +DST( movl %ebx, %es:24(%edi) )
28862 adcl %edx, %eax
28863 -DST( movl %edx, 28(%edi) )
28864 +DST( movl %edx, %es:28(%edi) )
28865
28866 lea 32(%esi), %esi
28867 lea 32(%edi), %edi
28868 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28869 shrl $2, %edx # This clears CF
28870 SRC(3: movl (%esi), %ebx )
28871 adcl %ebx, %eax
28872 -DST( movl %ebx, (%edi) )
28873 +DST( movl %ebx, %es:(%edi) )
28874 lea 4(%esi), %esi
28875 lea 4(%edi), %edi
28876 dec %edx
28877 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28878 jb 5f
28879 SRC( movw (%esi), %cx )
28880 leal 2(%esi), %esi
28881 -DST( movw %cx, (%edi) )
28882 +DST( movw %cx, %es:(%edi) )
28883 leal 2(%edi), %edi
28884 je 6f
28885 shll $16,%ecx
28886 SRC(5: movb (%esi), %cl )
28887 -DST( movb %cl, (%edi) )
28888 +DST( movb %cl, %es:(%edi) )
28889 6: addl %ecx, %eax
28890 adcl $0, %eax
28891 7:
28892 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28893
28894 6001:
28895 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28896 - movl $-EFAULT, (%ebx)
28897 + movl $-EFAULT, %ss:(%ebx)
28898
28899 # zero the complete destination - computing the rest
28900 # is too much work
28901 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28902
28903 6002:
28904 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28905 - movl $-EFAULT,(%ebx)
28906 + movl $-EFAULT,%ss:(%ebx)
28907 jmp 5000b
28908
28909 .previous
28910
28911 + pushl_cfi %ss
28912 + popl_cfi %ds
28913 + pushl_cfi %ss
28914 + popl_cfi %es
28915 popl_cfi %ebx
28916 CFI_RESTORE ebx
28917 popl_cfi %esi
28918 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28919 popl_cfi %ecx # equivalent to addl $4,%esp
28920 ret
28921 CFI_ENDPROC
28922 -ENDPROC(csum_partial_copy_generic)
28923 +ENDPROC(csum_partial_copy_generic_to_user)
28924
28925 #else
28926
28927 /* Version for PentiumII/PPro */
28928
28929 #define ROUND1(x) \
28930 + nop; nop; nop; \
28931 SRC(movl x(%esi), %ebx ) ; \
28932 addl %ebx, %eax ; \
28933 - DST(movl %ebx, x(%edi) ) ;
28934 + DST(movl %ebx, %es:x(%edi)) ;
28935
28936 #define ROUND(x) \
28937 + nop; nop; nop; \
28938 SRC(movl x(%esi), %ebx ) ; \
28939 adcl %ebx, %eax ; \
28940 - DST(movl %ebx, x(%edi) ) ;
28941 + DST(movl %ebx, %es:x(%edi)) ;
28942
28943 #define ARGBASE 12
28944 -
28945 -ENTRY(csum_partial_copy_generic)
28946 +
28947 +ENTRY(csum_partial_copy_generic_to_user)
28948 CFI_STARTPROC
28949 +
28950 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28951 + pushl_cfi %gs
28952 + popl_cfi %es
28953 + jmp csum_partial_copy_generic
28954 +#endif
28955 +
28956 +ENTRY(csum_partial_copy_generic_from_user)
28957 +
28958 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28959 + pushl_cfi %gs
28960 + popl_cfi %ds
28961 +#endif
28962 +
28963 +ENTRY(csum_partial_copy_generic)
28964 pushl_cfi %ebx
28965 CFI_REL_OFFSET ebx, 0
28966 pushl_cfi %edi
28967 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
28968 subl %ebx, %edi
28969 lea -1(%esi),%edx
28970 andl $-32,%edx
28971 - lea 3f(%ebx,%ebx), %ebx
28972 + lea 3f(%ebx,%ebx,2), %ebx
28973 testl %esi, %esi
28974 jmp *%ebx
28975 1: addl $64,%esi
28976 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
28977 jb 5f
28978 SRC( movw (%esi), %dx )
28979 leal 2(%esi), %esi
28980 -DST( movw %dx, (%edi) )
28981 +DST( movw %dx, %es:(%edi) )
28982 leal 2(%edi), %edi
28983 je 6f
28984 shll $16,%edx
28985 5:
28986 SRC( movb (%esi), %dl )
28987 -DST( movb %dl, (%edi) )
28988 +DST( movb %dl, %es:(%edi) )
28989 6: addl %edx, %eax
28990 adcl $0, %eax
28991 7:
28992 .section .fixup, "ax"
28993 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
28994 - movl $-EFAULT, (%ebx)
28995 + movl $-EFAULT, %ss:(%ebx)
28996 # zero the complete destination (computing the rest is too much work)
28997 movl ARGBASE+8(%esp),%edi # dst
28998 movl ARGBASE+12(%esp),%ecx # len
28999 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29000 rep; stosb
29001 jmp 7b
29002 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29003 - movl $-EFAULT, (%ebx)
29004 + movl $-EFAULT, %ss:(%ebx)
29005 jmp 7b
29006 .previous
29007
29008 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29009 + pushl_cfi %ss
29010 + popl_cfi %ds
29011 + pushl_cfi %ss
29012 + popl_cfi %es
29013 +#endif
29014 +
29015 popl_cfi %esi
29016 CFI_RESTORE esi
29017 popl_cfi %edi
29018 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29019 CFI_RESTORE ebx
29020 ret
29021 CFI_ENDPROC
29022 -ENDPROC(csum_partial_copy_generic)
29023 +ENDPROC(csum_partial_copy_generic_to_user)
29024
29025 #undef ROUND
29026 #undef ROUND1
29027 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29028 index f2145cf..cea889d 100644
29029 --- a/arch/x86/lib/clear_page_64.S
29030 +++ b/arch/x86/lib/clear_page_64.S
29031 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29032 movl $4096/8,%ecx
29033 xorl %eax,%eax
29034 rep stosq
29035 + pax_force_retaddr
29036 ret
29037 CFI_ENDPROC
29038 ENDPROC(clear_page_c)
29039 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29040 movl $4096,%ecx
29041 xorl %eax,%eax
29042 rep stosb
29043 + pax_force_retaddr
29044 ret
29045 CFI_ENDPROC
29046 ENDPROC(clear_page_c_e)
29047 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29048 leaq 64(%rdi),%rdi
29049 jnz .Lloop
29050 nop
29051 + pax_force_retaddr
29052 ret
29053 CFI_ENDPROC
29054 .Lclear_page_end:
29055 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29056
29057 #include <asm/cpufeature.h>
29058
29059 - .section .altinstr_replacement,"ax"
29060 + .section .altinstr_replacement,"a"
29061 1: .byte 0xeb /* jmp <disp8> */
29062 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29063 2: .byte 0xeb /* jmp <disp8> */
29064 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29065 index 1e572c5..2a162cd 100644
29066 --- a/arch/x86/lib/cmpxchg16b_emu.S
29067 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29068 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29069
29070 popf
29071 mov $1, %al
29072 + pax_force_retaddr
29073 ret
29074
29075 not_same:
29076 popf
29077 xor %al,%al
29078 + pax_force_retaddr
29079 ret
29080
29081 CFI_ENDPROC
29082 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29083 index 176cca6..e0d658e 100644
29084 --- a/arch/x86/lib/copy_page_64.S
29085 +++ b/arch/x86/lib/copy_page_64.S
29086 @@ -9,6 +9,7 @@ copy_page_rep:
29087 CFI_STARTPROC
29088 movl $4096/8, %ecx
29089 rep movsq
29090 + pax_force_retaddr
29091 ret
29092 CFI_ENDPROC
29093 ENDPROC(copy_page_rep)
29094 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29095 CFI_ADJUST_CFA_OFFSET 2*8
29096 movq %rbx, (%rsp)
29097 CFI_REL_OFFSET rbx, 0
29098 - movq %r12, 1*8(%rsp)
29099 - CFI_REL_OFFSET r12, 1*8
29100 + movq %r13, 1*8(%rsp)
29101 + CFI_REL_OFFSET r13, 1*8
29102
29103 movl $(4096/64)-5, %ecx
29104 .p2align 4
29105 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29106 movq 0x8*4(%rsi), %r9
29107 movq 0x8*5(%rsi), %r10
29108 movq 0x8*6(%rsi), %r11
29109 - movq 0x8*7(%rsi), %r12
29110 + movq 0x8*7(%rsi), %r13
29111
29112 prefetcht0 5*64(%rsi)
29113
29114 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29115 movq %r9, 0x8*4(%rdi)
29116 movq %r10, 0x8*5(%rdi)
29117 movq %r11, 0x8*6(%rdi)
29118 - movq %r12, 0x8*7(%rdi)
29119 + movq %r13, 0x8*7(%rdi)
29120
29121 leaq 64 (%rsi), %rsi
29122 leaq 64 (%rdi), %rdi
29123 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29124 movq 0x8*4(%rsi), %r9
29125 movq 0x8*5(%rsi), %r10
29126 movq 0x8*6(%rsi), %r11
29127 - movq 0x8*7(%rsi), %r12
29128 + movq 0x8*7(%rsi), %r13
29129
29130 movq %rax, 0x8*0(%rdi)
29131 movq %rbx, 0x8*1(%rdi)
29132 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29133 movq %r9, 0x8*4(%rdi)
29134 movq %r10, 0x8*5(%rdi)
29135 movq %r11, 0x8*6(%rdi)
29136 - movq %r12, 0x8*7(%rdi)
29137 + movq %r13, 0x8*7(%rdi)
29138
29139 leaq 64(%rdi), %rdi
29140 leaq 64(%rsi), %rsi
29141 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29142
29143 movq (%rsp), %rbx
29144 CFI_RESTORE rbx
29145 - movq 1*8(%rsp), %r12
29146 - CFI_RESTORE r12
29147 + movq 1*8(%rsp), %r13
29148 + CFI_RESTORE r13
29149 addq $2*8, %rsp
29150 CFI_ADJUST_CFA_OFFSET -2*8
29151 + pax_force_retaddr
29152 ret
29153 .Lcopy_page_end:
29154 CFI_ENDPROC
29155 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29156
29157 #include <asm/cpufeature.h>
29158
29159 - .section .altinstr_replacement,"ax"
29160 + .section .altinstr_replacement,"a"
29161 1: .byte 0xeb /* jmp <disp8> */
29162 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29163 2:
29164 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29165 index dee945d..a84067b 100644
29166 --- a/arch/x86/lib/copy_user_64.S
29167 +++ b/arch/x86/lib/copy_user_64.S
29168 @@ -18,31 +18,7 @@
29169 #include <asm/alternative-asm.h>
29170 #include <asm/asm.h>
29171 #include <asm/smap.h>
29172 -
29173 -/*
29174 - * By placing feature2 after feature1 in altinstructions section, we logically
29175 - * implement:
29176 - * If CPU has feature2, jmp to alt2 is used
29177 - * else if CPU has feature1, jmp to alt1 is used
29178 - * else jmp to orig is used.
29179 - */
29180 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29181 -0:
29182 - .byte 0xe9 /* 32bit jump */
29183 - .long \orig-1f /* by default jump to orig */
29184 -1:
29185 - .section .altinstr_replacement,"ax"
29186 -2: .byte 0xe9 /* near jump with 32bit immediate */
29187 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29188 -3: .byte 0xe9 /* near jump with 32bit immediate */
29189 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29190 - .previous
29191 -
29192 - .section .altinstructions,"a"
29193 - altinstruction_entry 0b,2b,\feature1,5,5
29194 - altinstruction_entry 0b,3b,\feature2,5,5
29195 - .previous
29196 - .endm
29197 +#include <asm/pgtable.h>
29198
29199 .macro ALIGN_DESTINATION
29200 #ifdef FIX_ALIGNMENT
29201 @@ -70,52 +46,6 @@
29202 #endif
29203 .endm
29204
29205 -/* Standard copy_to_user with segment limit checking */
29206 -ENTRY(_copy_to_user)
29207 - CFI_STARTPROC
29208 - GET_THREAD_INFO(%rax)
29209 - movq %rdi,%rcx
29210 - addq %rdx,%rcx
29211 - jc bad_to_user
29212 - cmpq TI_addr_limit(%rax),%rcx
29213 - ja bad_to_user
29214 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29215 - copy_user_generic_unrolled,copy_user_generic_string, \
29216 - copy_user_enhanced_fast_string
29217 - CFI_ENDPROC
29218 -ENDPROC(_copy_to_user)
29219 -
29220 -/* Standard copy_from_user with segment limit checking */
29221 -ENTRY(_copy_from_user)
29222 - CFI_STARTPROC
29223 - GET_THREAD_INFO(%rax)
29224 - movq %rsi,%rcx
29225 - addq %rdx,%rcx
29226 - jc bad_from_user
29227 - cmpq TI_addr_limit(%rax),%rcx
29228 - ja bad_from_user
29229 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29230 - copy_user_generic_unrolled,copy_user_generic_string, \
29231 - copy_user_enhanced_fast_string
29232 - CFI_ENDPROC
29233 -ENDPROC(_copy_from_user)
29234 -
29235 - .section .fixup,"ax"
29236 - /* must zero dest */
29237 -ENTRY(bad_from_user)
29238 -bad_from_user:
29239 - CFI_STARTPROC
29240 - movl %edx,%ecx
29241 - xorl %eax,%eax
29242 - rep
29243 - stosb
29244 -bad_to_user:
29245 - movl %edx,%eax
29246 - ret
29247 - CFI_ENDPROC
29248 -ENDPROC(bad_from_user)
29249 - .previous
29250 -
29251 /*
29252 * copy_user_generic_unrolled - memory copy with exception handling.
29253 * This version is for CPUs like P4 that don't have efficient micro
29254 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29255 */
29256 ENTRY(copy_user_generic_unrolled)
29257 CFI_STARTPROC
29258 + ASM_PAX_OPEN_USERLAND
29259 ASM_STAC
29260 cmpl $8,%edx
29261 jb 20f /* less then 8 bytes, go to byte copy loop */
29262 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29263 jnz 21b
29264 23: xor %eax,%eax
29265 ASM_CLAC
29266 + ASM_PAX_CLOSE_USERLAND
29267 + pax_force_retaddr
29268 ret
29269
29270 .section .fixup,"ax"
29271 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29272 */
29273 ENTRY(copy_user_generic_string)
29274 CFI_STARTPROC
29275 + ASM_PAX_OPEN_USERLAND
29276 ASM_STAC
29277 cmpl $8,%edx
29278 jb 2f /* less than 8 bytes, go to byte copy loop */
29279 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29280 movsb
29281 xorl %eax,%eax
29282 ASM_CLAC
29283 + ASM_PAX_CLOSE_USERLAND
29284 + pax_force_retaddr
29285 ret
29286
29287 .section .fixup,"ax"
29288 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29289 */
29290 ENTRY(copy_user_enhanced_fast_string)
29291 CFI_STARTPROC
29292 + ASM_PAX_OPEN_USERLAND
29293 ASM_STAC
29294 movl %edx,%ecx
29295 1: rep
29296 movsb
29297 xorl %eax,%eax
29298 ASM_CLAC
29299 + ASM_PAX_CLOSE_USERLAND
29300 + pax_force_retaddr
29301 ret
29302
29303 .section .fixup,"ax"
29304 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29305 index 6a4f43c..c70fb52 100644
29306 --- a/arch/x86/lib/copy_user_nocache_64.S
29307 +++ b/arch/x86/lib/copy_user_nocache_64.S
29308 @@ -8,6 +8,7 @@
29309
29310 #include <linux/linkage.h>
29311 #include <asm/dwarf2.h>
29312 +#include <asm/alternative-asm.h>
29313
29314 #define FIX_ALIGNMENT 1
29315
29316 @@ -16,6 +17,7 @@
29317 #include <asm/thread_info.h>
29318 #include <asm/asm.h>
29319 #include <asm/smap.h>
29320 +#include <asm/pgtable.h>
29321
29322 .macro ALIGN_DESTINATION
29323 #ifdef FIX_ALIGNMENT
29324 @@ -49,6 +51,16 @@
29325 */
29326 ENTRY(__copy_user_nocache)
29327 CFI_STARTPROC
29328 +
29329 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29330 + mov pax_user_shadow_base,%rcx
29331 + cmp %rcx,%rsi
29332 + jae 1f
29333 + add %rcx,%rsi
29334 +1:
29335 +#endif
29336 +
29337 + ASM_PAX_OPEN_USERLAND
29338 ASM_STAC
29339 cmpl $8,%edx
29340 jb 20f /* less then 8 bytes, go to byte copy loop */
29341 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29342 jnz 21b
29343 23: xorl %eax,%eax
29344 ASM_CLAC
29345 + ASM_PAX_CLOSE_USERLAND
29346 sfence
29347 + pax_force_retaddr
29348 ret
29349
29350 .section .fixup,"ax"
29351 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29352 index 2419d5f..fe52d0e 100644
29353 --- a/arch/x86/lib/csum-copy_64.S
29354 +++ b/arch/x86/lib/csum-copy_64.S
29355 @@ -9,6 +9,7 @@
29356 #include <asm/dwarf2.h>
29357 #include <asm/errno.h>
29358 #include <asm/asm.h>
29359 +#include <asm/alternative-asm.h>
29360
29361 /*
29362 * Checksum copy with exception handling.
29363 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29364 CFI_ADJUST_CFA_OFFSET 7*8
29365 movq %rbx, 2*8(%rsp)
29366 CFI_REL_OFFSET rbx, 2*8
29367 - movq %r12, 3*8(%rsp)
29368 - CFI_REL_OFFSET r12, 3*8
29369 + movq %r15, 3*8(%rsp)
29370 + CFI_REL_OFFSET r15, 3*8
29371 movq %r14, 4*8(%rsp)
29372 CFI_REL_OFFSET r14, 4*8
29373 movq %r13, 5*8(%rsp)
29374 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29375 movl %edx, %ecx
29376
29377 xorl %r9d, %r9d
29378 - movq %rcx, %r12
29379 + movq %rcx, %r15
29380
29381 - shrq $6, %r12
29382 + shrq $6, %r15
29383 jz .Lhandle_tail /* < 64 */
29384
29385 clc
29386
29387 /* main loop. clear in 64 byte blocks */
29388 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29389 - /* r11: temp3, rdx: temp4, r12 loopcnt */
29390 + /* r11: temp3, rdx: temp4, r15 loopcnt */
29391 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29392 .p2align 4
29393 .Lloop:
29394 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29395 adcq %r14, %rax
29396 adcq %r13, %rax
29397
29398 - decl %r12d
29399 + decl %r15d
29400
29401 dest
29402 movq %rbx, (%rsi)
29403 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29404 .Lende:
29405 movq 2*8(%rsp), %rbx
29406 CFI_RESTORE rbx
29407 - movq 3*8(%rsp), %r12
29408 - CFI_RESTORE r12
29409 + movq 3*8(%rsp), %r15
29410 + CFI_RESTORE r15
29411 movq 4*8(%rsp), %r14
29412 CFI_RESTORE r14
29413 movq 5*8(%rsp), %r13
29414 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29415 CFI_RESTORE rbp
29416 addq $7*8, %rsp
29417 CFI_ADJUST_CFA_OFFSET -7*8
29418 + pax_force_retaddr
29419 ret
29420 CFI_RESTORE_STATE
29421
29422 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29423 index 7609e0e..b449b98 100644
29424 --- a/arch/x86/lib/csum-wrappers_64.c
29425 +++ b/arch/x86/lib/csum-wrappers_64.c
29426 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29427 len -= 2;
29428 }
29429 }
29430 + pax_open_userland();
29431 stac();
29432 - isum = csum_partial_copy_generic((__force const void *)src,
29433 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29434 dst, len, isum, errp, NULL);
29435 clac();
29436 + pax_close_userland();
29437 if (unlikely(*errp))
29438 goto out_err;
29439
29440 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29441 }
29442
29443 *errp = 0;
29444 + pax_open_userland();
29445 stac();
29446 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29447 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29448 len, isum, NULL, errp);
29449 clac();
29450 + pax_close_userland();
29451 return ret;
29452 }
29453 EXPORT_SYMBOL(csum_partial_copy_to_user);
29454 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29455 index a451235..1daa956 100644
29456 --- a/arch/x86/lib/getuser.S
29457 +++ b/arch/x86/lib/getuser.S
29458 @@ -33,17 +33,40 @@
29459 #include <asm/thread_info.h>
29460 #include <asm/asm.h>
29461 #include <asm/smap.h>
29462 +#include <asm/segment.h>
29463 +#include <asm/pgtable.h>
29464 +#include <asm/alternative-asm.h>
29465 +
29466 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29467 +#define __copyuser_seg gs;
29468 +#else
29469 +#define __copyuser_seg
29470 +#endif
29471
29472 .text
29473 ENTRY(__get_user_1)
29474 CFI_STARTPROC
29475 +
29476 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29477 GET_THREAD_INFO(%_ASM_DX)
29478 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29479 jae bad_get_user
29480 ASM_STAC
29481 -1: movzbl (%_ASM_AX),%edx
29482 +
29483 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29484 + mov pax_user_shadow_base,%_ASM_DX
29485 + cmp %_ASM_DX,%_ASM_AX
29486 + jae 1234f
29487 + add %_ASM_DX,%_ASM_AX
29488 +1234:
29489 +#endif
29490 +
29491 +#endif
29492 +
29493 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29494 xor %eax,%eax
29495 ASM_CLAC
29496 + pax_force_retaddr
29497 ret
29498 CFI_ENDPROC
29499 ENDPROC(__get_user_1)
29500 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29501 ENTRY(__get_user_2)
29502 CFI_STARTPROC
29503 add $1,%_ASM_AX
29504 +
29505 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29506 jc bad_get_user
29507 GET_THREAD_INFO(%_ASM_DX)
29508 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29509 jae bad_get_user
29510 ASM_STAC
29511 -2: movzwl -1(%_ASM_AX),%edx
29512 +
29513 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29514 + mov pax_user_shadow_base,%_ASM_DX
29515 + cmp %_ASM_DX,%_ASM_AX
29516 + jae 1234f
29517 + add %_ASM_DX,%_ASM_AX
29518 +1234:
29519 +#endif
29520 +
29521 +#endif
29522 +
29523 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29524 xor %eax,%eax
29525 ASM_CLAC
29526 + pax_force_retaddr
29527 ret
29528 CFI_ENDPROC
29529 ENDPROC(__get_user_2)
29530 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29531 ENTRY(__get_user_4)
29532 CFI_STARTPROC
29533 add $3,%_ASM_AX
29534 +
29535 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29536 jc bad_get_user
29537 GET_THREAD_INFO(%_ASM_DX)
29538 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29539 jae bad_get_user
29540 ASM_STAC
29541 -3: movl -3(%_ASM_AX),%edx
29542 +
29543 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29544 + mov pax_user_shadow_base,%_ASM_DX
29545 + cmp %_ASM_DX,%_ASM_AX
29546 + jae 1234f
29547 + add %_ASM_DX,%_ASM_AX
29548 +1234:
29549 +#endif
29550 +
29551 +#endif
29552 +
29553 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29554 xor %eax,%eax
29555 ASM_CLAC
29556 + pax_force_retaddr
29557 ret
29558 CFI_ENDPROC
29559 ENDPROC(__get_user_4)
29560 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29561 GET_THREAD_INFO(%_ASM_DX)
29562 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29563 jae bad_get_user
29564 +
29565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29566 + mov pax_user_shadow_base,%_ASM_DX
29567 + cmp %_ASM_DX,%_ASM_AX
29568 + jae 1234f
29569 + add %_ASM_DX,%_ASM_AX
29570 +1234:
29571 +#endif
29572 +
29573 ASM_STAC
29574 4: movq -7(%_ASM_AX),%rdx
29575 xor %eax,%eax
29576 ASM_CLAC
29577 + pax_force_retaddr
29578 ret
29579 #else
29580 add $7,%_ASM_AX
29581 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29582 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29583 jae bad_get_user_8
29584 ASM_STAC
29585 -4: movl -7(%_ASM_AX),%edx
29586 -5: movl -3(%_ASM_AX),%ecx
29587 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29588 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29589 xor %eax,%eax
29590 ASM_CLAC
29591 + pax_force_retaddr
29592 ret
29593 #endif
29594 CFI_ENDPROC
29595 @@ -113,6 +175,7 @@ bad_get_user:
29596 xor %edx,%edx
29597 mov $(-EFAULT),%_ASM_AX
29598 ASM_CLAC
29599 + pax_force_retaddr
29600 ret
29601 CFI_ENDPROC
29602 END(bad_get_user)
29603 @@ -124,6 +187,7 @@ bad_get_user_8:
29604 xor %ecx,%ecx
29605 mov $(-EFAULT),%_ASM_AX
29606 ASM_CLAC
29607 + pax_force_retaddr
29608 ret
29609 CFI_ENDPROC
29610 END(bad_get_user_8)
29611 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29612 index 54fcffe..7be149e 100644
29613 --- a/arch/x86/lib/insn.c
29614 +++ b/arch/x86/lib/insn.c
29615 @@ -20,8 +20,10 @@
29616
29617 #ifdef __KERNEL__
29618 #include <linux/string.h>
29619 +#include <asm/pgtable_types.h>
29620 #else
29621 #include <string.h>
29622 +#define ktla_ktva(addr) addr
29623 #endif
29624 #include <asm/inat.h>
29625 #include <asm/insn.h>
29626 @@ -53,8 +55,8 @@
29627 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29628 {
29629 memset(insn, 0, sizeof(*insn));
29630 - insn->kaddr = kaddr;
29631 - insn->next_byte = kaddr;
29632 + insn->kaddr = ktla_ktva(kaddr);
29633 + insn->next_byte = ktla_ktva(kaddr);
29634 insn->x86_64 = x86_64 ? 1 : 0;
29635 insn->opnd_bytes = 4;
29636 if (x86_64)
29637 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29638 index 05a95e7..326f2fa 100644
29639 --- a/arch/x86/lib/iomap_copy_64.S
29640 +++ b/arch/x86/lib/iomap_copy_64.S
29641 @@ -17,6 +17,7 @@
29642
29643 #include <linux/linkage.h>
29644 #include <asm/dwarf2.h>
29645 +#include <asm/alternative-asm.h>
29646
29647 /*
29648 * override generic version in lib/iomap_copy.c
29649 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29650 CFI_STARTPROC
29651 movl %edx,%ecx
29652 rep movsd
29653 + pax_force_retaddr
29654 ret
29655 CFI_ENDPROC
29656 ENDPROC(__iowrite32_copy)
29657 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29658 index 56313a3..0db417e 100644
29659 --- a/arch/x86/lib/memcpy_64.S
29660 +++ b/arch/x86/lib/memcpy_64.S
29661 @@ -24,7 +24,7 @@
29662 * This gets patched over the unrolled variant (below) via the
29663 * alternative instructions framework:
29664 */
29665 - .section .altinstr_replacement, "ax", @progbits
29666 + .section .altinstr_replacement, "a", @progbits
29667 .Lmemcpy_c:
29668 movq %rdi, %rax
29669 movq %rdx, %rcx
29670 @@ -33,6 +33,7 @@
29671 rep movsq
29672 movl %edx, %ecx
29673 rep movsb
29674 + pax_force_retaddr
29675 ret
29676 .Lmemcpy_e:
29677 .previous
29678 @@ -44,11 +45,12 @@
29679 * This gets patched over the unrolled variant (below) via the
29680 * alternative instructions framework:
29681 */
29682 - .section .altinstr_replacement, "ax", @progbits
29683 + .section .altinstr_replacement, "a", @progbits
29684 .Lmemcpy_c_e:
29685 movq %rdi, %rax
29686 movq %rdx, %rcx
29687 rep movsb
29688 + pax_force_retaddr
29689 ret
29690 .Lmemcpy_e_e:
29691 .previous
29692 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29693 movq %r9, 1*8(%rdi)
29694 movq %r10, -2*8(%rdi, %rdx)
29695 movq %r11, -1*8(%rdi, %rdx)
29696 + pax_force_retaddr
29697 retq
29698 .p2align 4
29699 .Lless_16bytes:
29700 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29701 movq -1*8(%rsi, %rdx), %r9
29702 movq %r8, 0*8(%rdi)
29703 movq %r9, -1*8(%rdi, %rdx)
29704 + pax_force_retaddr
29705 retq
29706 .p2align 4
29707 .Lless_8bytes:
29708 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29709 movl -4(%rsi, %rdx), %r8d
29710 movl %ecx, (%rdi)
29711 movl %r8d, -4(%rdi, %rdx)
29712 + pax_force_retaddr
29713 retq
29714 .p2align 4
29715 .Lless_3bytes:
29716 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29717 movb %cl, (%rdi)
29718
29719 .Lend:
29720 + pax_force_retaddr
29721 retq
29722 CFI_ENDPROC
29723 ENDPROC(memcpy)
29724 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29725 index 65268a6..dd1de11 100644
29726 --- a/arch/x86/lib/memmove_64.S
29727 +++ b/arch/x86/lib/memmove_64.S
29728 @@ -202,14 +202,16 @@ ENTRY(memmove)
29729 movb (%rsi), %r11b
29730 movb %r11b, (%rdi)
29731 13:
29732 + pax_force_retaddr
29733 retq
29734 CFI_ENDPROC
29735
29736 - .section .altinstr_replacement,"ax"
29737 + .section .altinstr_replacement,"a"
29738 .Lmemmove_begin_forward_efs:
29739 /* Forward moving data. */
29740 movq %rdx, %rcx
29741 rep movsb
29742 + pax_force_retaddr
29743 retq
29744 .Lmemmove_end_forward_efs:
29745 .previous
29746 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29747 index 2dcb380..2eb79fe 100644
29748 --- a/arch/x86/lib/memset_64.S
29749 +++ b/arch/x86/lib/memset_64.S
29750 @@ -16,7 +16,7 @@
29751 *
29752 * rax original destination
29753 */
29754 - .section .altinstr_replacement, "ax", @progbits
29755 + .section .altinstr_replacement, "a", @progbits
29756 .Lmemset_c:
29757 movq %rdi,%r9
29758 movq %rdx,%rcx
29759 @@ -30,6 +30,7 @@
29760 movl %edx,%ecx
29761 rep stosb
29762 movq %r9,%rax
29763 + pax_force_retaddr
29764 ret
29765 .Lmemset_e:
29766 .previous
29767 @@ -45,13 +46,14 @@
29768 *
29769 * rax original destination
29770 */
29771 - .section .altinstr_replacement, "ax", @progbits
29772 + .section .altinstr_replacement, "a", @progbits
29773 .Lmemset_c_e:
29774 movq %rdi,%r9
29775 movb %sil,%al
29776 movq %rdx,%rcx
29777 rep stosb
29778 movq %r9,%rax
29779 + pax_force_retaddr
29780 ret
29781 .Lmemset_e_e:
29782 .previous
29783 @@ -118,6 +120,7 @@ ENTRY(__memset)
29784
29785 .Lende:
29786 movq %r10,%rax
29787 + pax_force_retaddr
29788 ret
29789
29790 CFI_RESTORE_STATE
29791 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29792 index c9f2d9b..e7fd2c0 100644
29793 --- a/arch/x86/lib/mmx_32.c
29794 +++ b/arch/x86/lib/mmx_32.c
29795 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29796 {
29797 void *p;
29798 int i;
29799 + unsigned long cr0;
29800
29801 if (unlikely(in_interrupt()))
29802 return __memcpy(to, from, len);
29803 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29804 kernel_fpu_begin();
29805
29806 __asm__ __volatile__ (
29807 - "1: prefetch (%0)\n" /* This set is 28 bytes */
29808 - " prefetch 64(%0)\n"
29809 - " prefetch 128(%0)\n"
29810 - " prefetch 192(%0)\n"
29811 - " prefetch 256(%0)\n"
29812 + "1: prefetch (%1)\n" /* This set is 28 bytes */
29813 + " prefetch 64(%1)\n"
29814 + " prefetch 128(%1)\n"
29815 + " prefetch 192(%1)\n"
29816 + " prefetch 256(%1)\n"
29817 "2: \n"
29818 ".section .fixup, \"ax\"\n"
29819 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29820 + "3: \n"
29821 +
29822 +#ifdef CONFIG_PAX_KERNEXEC
29823 + " movl %%cr0, %0\n"
29824 + " movl %0, %%eax\n"
29825 + " andl $0xFFFEFFFF, %%eax\n"
29826 + " movl %%eax, %%cr0\n"
29827 +#endif
29828 +
29829 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29830 +
29831 +#ifdef CONFIG_PAX_KERNEXEC
29832 + " movl %0, %%cr0\n"
29833 +#endif
29834 +
29835 " jmp 2b\n"
29836 ".previous\n"
29837 _ASM_EXTABLE(1b, 3b)
29838 - : : "r" (from));
29839 + : "=&r" (cr0) : "r" (from) : "ax");
29840
29841 for ( ; i > 5; i--) {
29842 __asm__ __volatile__ (
29843 - "1: prefetch 320(%0)\n"
29844 - "2: movq (%0), %%mm0\n"
29845 - " movq 8(%0), %%mm1\n"
29846 - " movq 16(%0), %%mm2\n"
29847 - " movq 24(%0), %%mm3\n"
29848 - " movq %%mm0, (%1)\n"
29849 - " movq %%mm1, 8(%1)\n"
29850 - " movq %%mm2, 16(%1)\n"
29851 - " movq %%mm3, 24(%1)\n"
29852 - " movq 32(%0), %%mm0\n"
29853 - " movq 40(%0), %%mm1\n"
29854 - " movq 48(%0), %%mm2\n"
29855 - " movq 56(%0), %%mm3\n"
29856 - " movq %%mm0, 32(%1)\n"
29857 - " movq %%mm1, 40(%1)\n"
29858 - " movq %%mm2, 48(%1)\n"
29859 - " movq %%mm3, 56(%1)\n"
29860 + "1: prefetch 320(%1)\n"
29861 + "2: movq (%1), %%mm0\n"
29862 + " movq 8(%1), %%mm1\n"
29863 + " movq 16(%1), %%mm2\n"
29864 + " movq 24(%1), %%mm3\n"
29865 + " movq %%mm0, (%2)\n"
29866 + " movq %%mm1, 8(%2)\n"
29867 + " movq %%mm2, 16(%2)\n"
29868 + " movq %%mm3, 24(%2)\n"
29869 + " movq 32(%1), %%mm0\n"
29870 + " movq 40(%1), %%mm1\n"
29871 + " movq 48(%1), %%mm2\n"
29872 + " movq 56(%1), %%mm3\n"
29873 + " movq %%mm0, 32(%2)\n"
29874 + " movq %%mm1, 40(%2)\n"
29875 + " movq %%mm2, 48(%2)\n"
29876 + " movq %%mm3, 56(%2)\n"
29877 ".section .fixup, \"ax\"\n"
29878 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29879 + "3:\n"
29880 +
29881 +#ifdef CONFIG_PAX_KERNEXEC
29882 + " movl %%cr0, %0\n"
29883 + " movl %0, %%eax\n"
29884 + " andl $0xFFFEFFFF, %%eax\n"
29885 + " movl %%eax, %%cr0\n"
29886 +#endif
29887 +
29888 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29889 +
29890 +#ifdef CONFIG_PAX_KERNEXEC
29891 + " movl %0, %%cr0\n"
29892 +#endif
29893 +
29894 " jmp 2b\n"
29895 ".previous\n"
29896 _ASM_EXTABLE(1b, 3b)
29897 - : : "r" (from), "r" (to) : "memory");
29898 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29899
29900 from += 64;
29901 to += 64;
29902 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29903 static void fast_copy_page(void *to, void *from)
29904 {
29905 int i;
29906 + unsigned long cr0;
29907
29908 kernel_fpu_begin();
29909
29910 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29911 * but that is for later. -AV
29912 */
29913 __asm__ __volatile__(
29914 - "1: prefetch (%0)\n"
29915 - " prefetch 64(%0)\n"
29916 - " prefetch 128(%0)\n"
29917 - " prefetch 192(%0)\n"
29918 - " prefetch 256(%0)\n"
29919 + "1: prefetch (%1)\n"
29920 + " prefetch 64(%1)\n"
29921 + " prefetch 128(%1)\n"
29922 + " prefetch 192(%1)\n"
29923 + " prefetch 256(%1)\n"
29924 "2: \n"
29925 ".section .fixup, \"ax\"\n"
29926 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29927 + "3: \n"
29928 +
29929 +#ifdef CONFIG_PAX_KERNEXEC
29930 + " movl %%cr0, %0\n"
29931 + " movl %0, %%eax\n"
29932 + " andl $0xFFFEFFFF, %%eax\n"
29933 + " movl %%eax, %%cr0\n"
29934 +#endif
29935 +
29936 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29937 +
29938 +#ifdef CONFIG_PAX_KERNEXEC
29939 + " movl %0, %%cr0\n"
29940 +#endif
29941 +
29942 " jmp 2b\n"
29943 ".previous\n"
29944 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
29945 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29946
29947 for (i = 0; i < (4096-320)/64; i++) {
29948 __asm__ __volatile__ (
29949 - "1: prefetch 320(%0)\n"
29950 - "2: movq (%0), %%mm0\n"
29951 - " movntq %%mm0, (%1)\n"
29952 - " movq 8(%0), %%mm1\n"
29953 - " movntq %%mm1, 8(%1)\n"
29954 - " movq 16(%0), %%mm2\n"
29955 - " movntq %%mm2, 16(%1)\n"
29956 - " movq 24(%0), %%mm3\n"
29957 - " movntq %%mm3, 24(%1)\n"
29958 - " movq 32(%0), %%mm4\n"
29959 - " movntq %%mm4, 32(%1)\n"
29960 - " movq 40(%0), %%mm5\n"
29961 - " movntq %%mm5, 40(%1)\n"
29962 - " movq 48(%0), %%mm6\n"
29963 - " movntq %%mm6, 48(%1)\n"
29964 - " movq 56(%0), %%mm7\n"
29965 - " movntq %%mm7, 56(%1)\n"
29966 + "1: prefetch 320(%1)\n"
29967 + "2: movq (%1), %%mm0\n"
29968 + " movntq %%mm0, (%2)\n"
29969 + " movq 8(%1), %%mm1\n"
29970 + " movntq %%mm1, 8(%2)\n"
29971 + " movq 16(%1), %%mm2\n"
29972 + " movntq %%mm2, 16(%2)\n"
29973 + " movq 24(%1), %%mm3\n"
29974 + " movntq %%mm3, 24(%2)\n"
29975 + " movq 32(%1), %%mm4\n"
29976 + " movntq %%mm4, 32(%2)\n"
29977 + " movq 40(%1), %%mm5\n"
29978 + " movntq %%mm5, 40(%2)\n"
29979 + " movq 48(%1), %%mm6\n"
29980 + " movntq %%mm6, 48(%2)\n"
29981 + " movq 56(%1), %%mm7\n"
29982 + " movntq %%mm7, 56(%2)\n"
29983 ".section .fixup, \"ax\"\n"
29984 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29985 + "3:\n"
29986 +
29987 +#ifdef CONFIG_PAX_KERNEXEC
29988 + " movl %%cr0, %0\n"
29989 + " movl %0, %%eax\n"
29990 + " andl $0xFFFEFFFF, %%eax\n"
29991 + " movl %%eax, %%cr0\n"
29992 +#endif
29993 +
29994 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29995 +
29996 +#ifdef CONFIG_PAX_KERNEXEC
29997 + " movl %0, %%cr0\n"
29998 +#endif
29999 +
30000 " jmp 2b\n"
30001 ".previous\n"
30002 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30003 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30004
30005 from += 64;
30006 to += 64;
30007 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30008 static void fast_copy_page(void *to, void *from)
30009 {
30010 int i;
30011 + unsigned long cr0;
30012
30013 kernel_fpu_begin();
30014
30015 __asm__ __volatile__ (
30016 - "1: prefetch (%0)\n"
30017 - " prefetch 64(%0)\n"
30018 - " prefetch 128(%0)\n"
30019 - " prefetch 192(%0)\n"
30020 - " prefetch 256(%0)\n"
30021 + "1: prefetch (%1)\n"
30022 + " prefetch 64(%1)\n"
30023 + " prefetch 128(%1)\n"
30024 + " prefetch 192(%1)\n"
30025 + " prefetch 256(%1)\n"
30026 "2: \n"
30027 ".section .fixup, \"ax\"\n"
30028 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30029 + "3: \n"
30030 +
30031 +#ifdef CONFIG_PAX_KERNEXEC
30032 + " movl %%cr0, %0\n"
30033 + " movl %0, %%eax\n"
30034 + " andl $0xFFFEFFFF, %%eax\n"
30035 + " movl %%eax, %%cr0\n"
30036 +#endif
30037 +
30038 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30039 +
30040 +#ifdef CONFIG_PAX_KERNEXEC
30041 + " movl %0, %%cr0\n"
30042 +#endif
30043 +
30044 " jmp 2b\n"
30045 ".previous\n"
30046 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30047 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30048
30049 for (i = 0; i < 4096/64; i++) {
30050 __asm__ __volatile__ (
30051 - "1: prefetch 320(%0)\n"
30052 - "2: movq (%0), %%mm0\n"
30053 - " movq 8(%0), %%mm1\n"
30054 - " movq 16(%0), %%mm2\n"
30055 - " movq 24(%0), %%mm3\n"
30056 - " movq %%mm0, (%1)\n"
30057 - " movq %%mm1, 8(%1)\n"
30058 - " movq %%mm2, 16(%1)\n"
30059 - " movq %%mm3, 24(%1)\n"
30060 - " movq 32(%0), %%mm0\n"
30061 - " movq 40(%0), %%mm1\n"
30062 - " movq 48(%0), %%mm2\n"
30063 - " movq 56(%0), %%mm3\n"
30064 - " movq %%mm0, 32(%1)\n"
30065 - " movq %%mm1, 40(%1)\n"
30066 - " movq %%mm2, 48(%1)\n"
30067 - " movq %%mm3, 56(%1)\n"
30068 + "1: prefetch 320(%1)\n"
30069 + "2: movq (%1), %%mm0\n"
30070 + " movq 8(%1), %%mm1\n"
30071 + " movq 16(%1), %%mm2\n"
30072 + " movq 24(%1), %%mm3\n"
30073 + " movq %%mm0, (%2)\n"
30074 + " movq %%mm1, 8(%2)\n"
30075 + " movq %%mm2, 16(%2)\n"
30076 + " movq %%mm3, 24(%2)\n"
30077 + " movq 32(%1), %%mm0\n"
30078 + " movq 40(%1), %%mm1\n"
30079 + " movq 48(%1), %%mm2\n"
30080 + " movq 56(%1), %%mm3\n"
30081 + " movq %%mm0, 32(%2)\n"
30082 + " movq %%mm1, 40(%2)\n"
30083 + " movq %%mm2, 48(%2)\n"
30084 + " movq %%mm3, 56(%2)\n"
30085 ".section .fixup, \"ax\"\n"
30086 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30087 + "3:\n"
30088 +
30089 +#ifdef CONFIG_PAX_KERNEXEC
30090 + " movl %%cr0, %0\n"
30091 + " movl %0, %%eax\n"
30092 + " andl $0xFFFEFFFF, %%eax\n"
30093 + " movl %%eax, %%cr0\n"
30094 +#endif
30095 +
30096 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30097 +
30098 +#ifdef CONFIG_PAX_KERNEXEC
30099 + " movl %0, %%cr0\n"
30100 +#endif
30101 +
30102 " jmp 2b\n"
30103 ".previous\n"
30104 _ASM_EXTABLE(1b, 3b)
30105 - : : "r" (from), "r" (to) : "memory");
30106 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30107
30108 from += 64;
30109 to += 64;
30110 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30111 index f6d13ee..d789440 100644
30112 --- a/arch/x86/lib/msr-reg.S
30113 +++ b/arch/x86/lib/msr-reg.S
30114 @@ -3,6 +3,7 @@
30115 #include <asm/dwarf2.h>
30116 #include <asm/asm.h>
30117 #include <asm/msr.h>
30118 +#include <asm/alternative-asm.h>
30119
30120 #ifdef CONFIG_X86_64
30121 /*
30122 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30123 movl %edi, 28(%r10)
30124 popq_cfi %rbp
30125 popq_cfi %rbx
30126 + pax_force_retaddr
30127 ret
30128 3:
30129 CFI_RESTORE_STATE
30130 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30131 index fc6ba17..d4d989d 100644
30132 --- a/arch/x86/lib/putuser.S
30133 +++ b/arch/x86/lib/putuser.S
30134 @@ -16,7 +16,9 @@
30135 #include <asm/errno.h>
30136 #include <asm/asm.h>
30137 #include <asm/smap.h>
30138 -
30139 +#include <asm/segment.h>
30140 +#include <asm/pgtable.h>
30141 +#include <asm/alternative-asm.h>
30142
30143 /*
30144 * __put_user_X
30145 @@ -30,57 +32,125 @@
30146 * as they get called from within inline assembly.
30147 */
30148
30149 -#define ENTER CFI_STARTPROC ; \
30150 - GET_THREAD_INFO(%_ASM_BX)
30151 -#define EXIT ASM_CLAC ; \
30152 - ret ; \
30153 +#define ENTER CFI_STARTPROC
30154 +#define EXIT ASM_CLAC ; \
30155 + pax_force_retaddr ; \
30156 + ret ; \
30157 CFI_ENDPROC
30158
30159 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30160 +#define _DEST %_ASM_CX,%_ASM_BX
30161 +#else
30162 +#define _DEST %_ASM_CX
30163 +#endif
30164 +
30165 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30166 +#define __copyuser_seg gs;
30167 +#else
30168 +#define __copyuser_seg
30169 +#endif
30170 +
30171 .text
30172 ENTRY(__put_user_1)
30173 ENTER
30174 +
30175 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30176 + GET_THREAD_INFO(%_ASM_BX)
30177 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30178 jae bad_put_user
30179 ASM_STAC
30180 -1: movb %al,(%_ASM_CX)
30181 +
30182 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30183 + mov pax_user_shadow_base,%_ASM_BX
30184 + cmp %_ASM_BX,%_ASM_CX
30185 + jb 1234f
30186 + xor %ebx,%ebx
30187 +1234:
30188 +#endif
30189 +
30190 +#endif
30191 +
30192 +1: __copyuser_seg movb %al,(_DEST)
30193 xor %eax,%eax
30194 EXIT
30195 ENDPROC(__put_user_1)
30196
30197 ENTRY(__put_user_2)
30198 ENTER
30199 +
30200 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30201 + GET_THREAD_INFO(%_ASM_BX)
30202 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30203 sub $1,%_ASM_BX
30204 cmp %_ASM_BX,%_ASM_CX
30205 jae bad_put_user
30206 ASM_STAC
30207 -2: movw %ax,(%_ASM_CX)
30208 +
30209 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30210 + mov pax_user_shadow_base,%_ASM_BX
30211 + cmp %_ASM_BX,%_ASM_CX
30212 + jb 1234f
30213 + xor %ebx,%ebx
30214 +1234:
30215 +#endif
30216 +
30217 +#endif
30218 +
30219 +2: __copyuser_seg movw %ax,(_DEST)
30220 xor %eax,%eax
30221 EXIT
30222 ENDPROC(__put_user_2)
30223
30224 ENTRY(__put_user_4)
30225 ENTER
30226 +
30227 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30228 + GET_THREAD_INFO(%_ASM_BX)
30229 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30230 sub $3,%_ASM_BX
30231 cmp %_ASM_BX,%_ASM_CX
30232 jae bad_put_user
30233 ASM_STAC
30234 -3: movl %eax,(%_ASM_CX)
30235 +
30236 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30237 + mov pax_user_shadow_base,%_ASM_BX
30238 + cmp %_ASM_BX,%_ASM_CX
30239 + jb 1234f
30240 + xor %ebx,%ebx
30241 +1234:
30242 +#endif
30243 +
30244 +#endif
30245 +
30246 +3: __copyuser_seg movl %eax,(_DEST)
30247 xor %eax,%eax
30248 EXIT
30249 ENDPROC(__put_user_4)
30250
30251 ENTRY(__put_user_8)
30252 ENTER
30253 +
30254 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30255 + GET_THREAD_INFO(%_ASM_BX)
30256 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30257 sub $7,%_ASM_BX
30258 cmp %_ASM_BX,%_ASM_CX
30259 jae bad_put_user
30260 ASM_STAC
30261 -4: mov %_ASM_AX,(%_ASM_CX)
30262 +
30263 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30264 + mov pax_user_shadow_base,%_ASM_BX
30265 + cmp %_ASM_BX,%_ASM_CX
30266 + jb 1234f
30267 + xor %ebx,%ebx
30268 +1234:
30269 +#endif
30270 +
30271 +#endif
30272 +
30273 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30274 #ifdef CONFIG_X86_32
30275 -5: movl %edx,4(%_ASM_CX)
30276 +5: __copyuser_seg movl %edx,4(_DEST)
30277 #endif
30278 xor %eax,%eax
30279 EXIT
30280 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30281 index 1cad221..de671ee 100644
30282 --- a/arch/x86/lib/rwlock.S
30283 +++ b/arch/x86/lib/rwlock.S
30284 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30285 FRAME
30286 0: LOCK_PREFIX
30287 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30288 +
30289 +#ifdef CONFIG_PAX_REFCOUNT
30290 + jno 1234f
30291 + LOCK_PREFIX
30292 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30293 + int $4
30294 +1234:
30295 + _ASM_EXTABLE(1234b, 1234b)
30296 +#endif
30297 +
30298 1: rep; nop
30299 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30300 jne 1b
30301 LOCK_PREFIX
30302 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30303 +
30304 +#ifdef CONFIG_PAX_REFCOUNT
30305 + jno 1234f
30306 + LOCK_PREFIX
30307 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30308 + int $4
30309 +1234:
30310 + _ASM_EXTABLE(1234b, 1234b)
30311 +#endif
30312 +
30313 jnz 0b
30314 ENDFRAME
30315 + pax_force_retaddr
30316 ret
30317 CFI_ENDPROC
30318 END(__write_lock_failed)
30319 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30320 FRAME
30321 0: LOCK_PREFIX
30322 READ_LOCK_SIZE(inc) (%__lock_ptr)
30323 +
30324 +#ifdef CONFIG_PAX_REFCOUNT
30325 + jno 1234f
30326 + LOCK_PREFIX
30327 + READ_LOCK_SIZE(dec) (%__lock_ptr)
30328 + int $4
30329 +1234:
30330 + _ASM_EXTABLE(1234b, 1234b)
30331 +#endif
30332 +
30333 1: rep; nop
30334 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30335 js 1b
30336 LOCK_PREFIX
30337 READ_LOCK_SIZE(dec) (%__lock_ptr)
30338 +
30339 +#ifdef CONFIG_PAX_REFCOUNT
30340 + jno 1234f
30341 + LOCK_PREFIX
30342 + READ_LOCK_SIZE(inc) (%__lock_ptr)
30343 + int $4
30344 +1234:
30345 + _ASM_EXTABLE(1234b, 1234b)
30346 +#endif
30347 +
30348 js 0b
30349 ENDFRAME
30350 + pax_force_retaddr
30351 ret
30352 CFI_ENDPROC
30353 END(__read_lock_failed)
30354 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30355 index 5dff5f0..cadebf4 100644
30356 --- a/arch/x86/lib/rwsem.S
30357 +++ b/arch/x86/lib/rwsem.S
30358 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30359 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30360 CFI_RESTORE __ASM_REG(dx)
30361 restore_common_regs
30362 + pax_force_retaddr
30363 ret
30364 CFI_ENDPROC
30365 ENDPROC(call_rwsem_down_read_failed)
30366 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30367 movq %rax,%rdi
30368 call rwsem_down_write_failed
30369 restore_common_regs
30370 + pax_force_retaddr
30371 ret
30372 CFI_ENDPROC
30373 ENDPROC(call_rwsem_down_write_failed)
30374 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30375 movq %rax,%rdi
30376 call rwsem_wake
30377 restore_common_regs
30378 -1: ret
30379 +1: pax_force_retaddr
30380 + ret
30381 CFI_ENDPROC
30382 ENDPROC(call_rwsem_wake)
30383
30384 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30385 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30386 CFI_RESTORE __ASM_REG(dx)
30387 restore_common_regs
30388 + pax_force_retaddr
30389 ret
30390 CFI_ENDPROC
30391 ENDPROC(call_rwsem_downgrade_wake)
30392 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30393 index a63efd6..8149fbe 100644
30394 --- a/arch/x86/lib/thunk_64.S
30395 +++ b/arch/x86/lib/thunk_64.S
30396 @@ -8,6 +8,7 @@
30397 #include <linux/linkage.h>
30398 #include <asm/dwarf2.h>
30399 #include <asm/calling.h>
30400 +#include <asm/alternative-asm.h>
30401
30402 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30403 .macro THUNK name, func, put_ret_addr_in_rdi=0
30404 @@ -15,11 +16,11 @@
30405 \name:
30406 CFI_STARTPROC
30407
30408 - /* this one pushes 9 elems, the next one would be %rIP */
30409 - SAVE_ARGS
30410 + /* this one pushes 15+1 elems, the next one would be %rIP */
30411 + SAVE_ARGS 8
30412
30413 .if \put_ret_addr_in_rdi
30414 - movq_cfi_restore 9*8, rdi
30415 + movq_cfi_restore RIP, rdi
30416 .endif
30417
30418 call \func
30419 @@ -38,8 +39,9 @@
30420
30421 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30422 CFI_STARTPROC
30423 - SAVE_ARGS
30424 + SAVE_ARGS 8
30425 restore:
30426 - RESTORE_ARGS
30427 + RESTORE_ARGS 1,8
30428 + pax_force_retaddr
30429 ret
30430 CFI_ENDPROC
30431 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30432 index e2f5e21..4b22130 100644
30433 --- a/arch/x86/lib/usercopy_32.c
30434 +++ b/arch/x86/lib/usercopy_32.c
30435 @@ -42,11 +42,13 @@ do { \
30436 int __d0; \
30437 might_fault(); \
30438 __asm__ __volatile__( \
30439 + __COPYUSER_SET_ES \
30440 ASM_STAC "\n" \
30441 "0: rep; stosl\n" \
30442 " movl %2,%0\n" \
30443 "1: rep; stosb\n" \
30444 "2: " ASM_CLAC "\n" \
30445 + __COPYUSER_RESTORE_ES \
30446 ".section .fixup,\"ax\"\n" \
30447 "3: lea 0(%2,%0,4),%0\n" \
30448 " jmp 2b\n" \
30449 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30450
30451 #ifdef CONFIG_X86_INTEL_USERCOPY
30452 static unsigned long
30453 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30454 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30455 {
30456 int d0, d1;
30457 __asm__ __volatile__(
30458 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30459 " .align 2,0x90\n"
30460 "3: movl 0(%4), %%eax\n"
30461 "4: movl 4(%4), %%edx\n"
30462 - "5: movl %%eax, 0(%3)\n"
30463 - "6: movl %%edx, 4(%3)\n"
30464 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30465 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30466 "7: movl 8(%4), %%eax\n"
30467 "8: movl 12(%4),%%edx\n"
30468 - "9: movl %%eax, 8(%3)\n"
30469 - "10: movl %%edx, 12(%3)\n"
30470 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30471 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30472 "11: movl 16(%4), %%eax\n"
30473 "12: movl 20(%4), %%edx\n"
30474 - "13: movl %%eax, 16(%3)\n"
30475 - "14: movl %%edx, 20(%3)\n"
30476 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30477 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30478 "15: movl 24(%4), %%eax\n"
30479 "16: movl 28(%4), %%edx\n"
30480 - "17: movl %%eax, 24(%3)\n"
30481 - "18: movl %%edx, 28(%3)\n"
30482 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30483 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30484 "19: movl 32(%4), %%eax\n"
30485 "20: movl 36(%4), %%edx\n"
30486 - "21: movl %%eax, 32(%3)\n"
30487 - "22: movl %%edx, 36(%3)\n"
30488 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30489 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30490 "23: movl 40(%4), %%eax\n"
30491 "24: movl 44(%4), %%edx\n"
30492 - "25: movl %%eax, 40(%3)\n"
30493 - "26: movl %%edx, 44(%3)\n"
30494 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30495 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30496 "27: movl 48(%4), %%eax\n"
30497 "28: movl 52(%4), %%edx\n"
30498 - "29: movl %%eax, 48(%3)\n"
30499 - "30: movl %%edx, 52(%3)\n"
30500 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30501 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30502 "31: movl 56(%4), %%eax\n"
30503 "32: movl 60(%4), %%edx\n"
30504 - "33: movl %%eax, 56(%3)\n"
30505 - "34: movl %%edx, 60(%3)\n"
30506 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30507 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30508 " addl $-64, %0\n"
30509 " addl $64, %4\n"
30510 " addl $64, %3\n"
30511 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30512 " shrl $2, %0\n"
30513 " andl $3, %%eax\n"
30514 " cld\n"
30515 + __COPYUSER_SET_ES
30516 "99: rep; movsl\n"
30517 "36: movl %%eax, %0\n"
30518 "37: rep; movsb\n"
30519 "100:\n"
30520 + __COPYUSER_RESTORE_ES
30521 + ".section .fixup,\"ax\"\n"
30522 + "101: lea 0(%%eax,%0,4),%0\n"
30523 + " jmp 100b\n"
30524 + ".previous\n"
30525 + _ASM_EXTABLE(1b,100b)
30526 + _ASM_EXTABLE(2b,100b)
30527 + _ASM_EXTABLE(3b,100b)
30528 + _ASM_EXTABLE(4b,100b)
30529 + _ASM_EXTABLE(5b,100b)
30530 + _ASM_EXTABLE(6b,100b)
30531 + _ASM_EXTABLE(7b,100b)
30532 + _ASM_EXTABLE(8b,100b)
30533 + _ASM_EXTABLE(9b,100b)
30534 + _ASM_EXTABLE(10b,100b)
30535 + _ASM_EXTABLE(11b,100b)
30536 + _ASM_EXTABLE(12b,100b)
30537 + _ASM_EXTABLE(13b,100b)
30538 + _ASM_EXTABLE(14b,100b)
30539 + _ASM_EXTABLE(15b,100b)
30540 + _ASM_EXTABLE(16b,100b)
30541 + _ASM_EXTABLE(17b,100b)
30542 + _ASM_EXTABLE(18b,100b)
30543 + _ASM_EXTABLE(19b,100b)
30544 + _ASM_EXTABLE(20b,100b)
30545 + _ASM_EXTABLE(21b,100b)
30546 + _ASM_EXTABLE(22b,100b)
30547 + _ASM_EXTABLE(23b,100b)
30548 + _ASM_EXTABLE(24b,100b)
30549 + _ASM_EXTABLE(25b,100b)
30550 + _ASM_EXTABLE(26b,100b)
30551 + _ASM_EXTABLE(27b,100b)
30552 + _ASM_EXTABLE(28b,100b)
30553 + _ASM_EXTABLE(29b,100b)
30554 + _ASM_EXTABLE(30b,100b)
30555 + _ASM_EXTABLE(31b,100b)
30556 + _ASM_EXTABLE(32b,100b)
30557 + _ASM_EXTABLE(33b,100b)
30558 + _ASM_EXTABLE(34b,100b)
30559 + _ASM_EXTABLE(35b,100b)
30560 + _ASM_EXTABLE(36b,100b)
30561 + _ASM_EXTABLE(37b,100b)
30562 + _ASM_EXTABLE(99b,101b)
30563 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30564 + : "1"(to), "2"(from), "0"(size)
30565 + : "eax", "edx", "memory");
30566 + return size;
30567 +}
30568 +
30569 +static unsigned long
30570 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30571 +{
30572 + int d0, d1;
30573 + __asm__ __volatile__(
30574 + " .align 2,0x90\n"
30575 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30576 + " cmpl $67, %0\n"
30577 + " jbe 3f\n"
30578 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30579 + " .align 2,0x90\n"
30580 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30581 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30582 + "5: movl %%eax, 0(%3)\n"
30583 + "6: movl %%edx, 4(%3)\n"
30584 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30585 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30586 + "9: movl %%eax, 8(%3)\n"
30587 + "10: movl %%edx, 12(%3)\n"
30588 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30589 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30590 + "13: movl %%eax, 16(%3)\n"
30591 + "14: movl %%edx, 20(%3)\n"
30592 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30593 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30594 + "17: movl %%eax, 24(%3)\n"
30595 + "18: movl %%edx, 28(%3)\n"
30596 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30597 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30598 + "21: movl %%eax, 32(%3)\n"
30599 + "22: movl %%edx, 36(%3)\n"
30600 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30601 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30602 + "25: movl %%eax, 40(%3)\n"
30603 + "26: movl %%edx, 44(%3)\n"
30604 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30605 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30606 + "29: movl %%eax, 48(%3)\n"
30607 + "30: movl %%edx, 52(%3)\n"
30608 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30609 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30610 + "33: movl %%eax, 56(%3)\n"
30611 + "34: movl %%edx, 60(%3)\n"
30612 + " addl $-64, %0\n"
30613 + " addl $64, %4\n"
30614 + " addl $64, %3\n"
30615 + " cmpl $63, %0\n"
30616 + " ja 1b\n"
30617 + "35: movl %0, %%eax\n"
30618 + " shrl $2, %0\n"
30619 + " andl $3, %%eax\n"
30620 + " cld\n"
30621 + "99: rep; "__copyuser_seg" movsl\n"
30622 + "36: movl %%eax, %0\n"
30623 + "37: rep; "__copyuser_seg" movsb\n"
30624 + "100:\n"
30625 ".section .fixup,\"ax\"\n"
30626 "101: lea 0(%%eax,%0,4),%0\n"
30627 " jmp 100b\n"
30628 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30629 int d0, d1;
30630 __asm__ __volatile__(
30631 " .align 2,0x90\n"
30632 - "0: movl 32(%4), %%eax\n"
30633 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30634 " cmpl $67, %0\n"
30635 " jbe 2f\n"
30636 - "1: movl 64(%4), %%eax\n"
30637 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30638 " .align 2,0x90\n"
30639 - "2: movl 0(%4), %%eax\n"
30640 - "21: movl 4(%4), %%edx\n"
30641 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30642 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30643 " movl %%eax, 0(%3)\n"
30644 " movl %%edx, 4(%3)\n"
30645 - "3: movl 8(%4), %%eax\n"
30646 - "31: movl 12(%4),%%edx\n"
30647 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30648 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30649 " movl %%eax, 8(%3)\n"
30650 " movl %%edx, 12(%3)\n"
30651 - "4: movl 16(%4), %%eax\n"
30652 - "41: movl 20(%4), %%edx\n"
30653 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30654 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30655 " movl %%eax, 16(%3)\n"
30656 " movl %%edx, 20(%3)\n"
30657 - "10: movl 24(%4), %%eax\n"
30658 - "51: movl 28(%4), %%edx\n"
30659 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30660 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30661 " movl %%eax, 24(%3)\n"
30662 " movl %%edx, 28(%3)\n"
30663 - "11: movl 32(%4), %%eax\n"
30664 - "61: movl 36(%4), %%edx\n"
30665 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30666 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30667 " movl %%eax, 32(%3)\n"
30668 " movl %%edx, 36(%3)\n"
30669 - "12: movl 40(%4), %%eax\n"
30670 - "71: movl 44(%4), %%edx\n"
30671 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30672 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30673 " movl %%eax, 40(%3)\n"
30674 " movl %%edx, 44(%3)\n"
30675 - "13: movl 48(%4), %%eax\n"
30676 - "81: movl 52(%4), %%edx\n"
30677 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30678 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30679 " movl %%eax, 48(%3)\n"
30680 " movl %%edx, 52(%3)\n"
30681 - "14: movl 56(%4), %%eax\n"
30682 - "91: movl 60(%4), %%edx\n"
30683 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30684 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30685 " movl %%eax, 56(%3)\n"
30686 " movl %%edx, 60(%3)\n"
30687 " addl $-64, %0\n"
30688 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30689 " shrl $2, %0\n"
30690 " andl $3, %%eax\n"
30691 " cld\n"
30692 - "6: rep; movsl\n"
30693 + "6: rep; "__copyuser_seg" movsl\n"
30694 " movl %%eax,%0\n"
30695 - "7: rep; movsb\n"
30696 + "7: rep; "__copyuser_seg" movsb\n"
30697 "8:\n"
30698 ".section .fixup,\"ax\"\n"
30699 "9: lea 0(%%eax,%0,4),%0\n"
30700 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30701
30702 __asm__ __volatile__(
30703 " .align 2,0x90\n"
30704 - "0: movl 32(%4), %%eax\n"
30705 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30706 " cmpl $67, %0\n"
30707 " jbe 2f\n"
30708 - "1: movl 64(%4), %%eax\n"
30709 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30710 " .align 2,0x90\n"
30711 - "2: movl 0(%4), %%eax\n"
30712 - "21: movl 4(%4), %%edx\n"
30713 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30714 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30715 " movnti %%eax, 0(%3)\n"
30716 " movnti %%edx, 4(%3)\n"
30717 - "3: movl 8(%4), %%eax\n"
30718 - "31: movl 12(%4),%%edx\n"
30719 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30720 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30721 " movnti %%eax, 8(%3)\n"
30722 " movnti %%edx, 12(%3)\n"
30723 - "4: movl 16(%4), %%eax\n"
30724 - "41: movl 20(%4), %%edx\n"
30725 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30726 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30727 " movnti %%eax, 16(%3)\n"
30728 " movnti %%edx, 20(%3)\n"
30729 - "10: movl 24(%4), %%eax\n"
30730 - "51: movl 28(%4), %%edx\n"
30731 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30732 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30733 " movnti %%eax, 24(%3)\n"
30734 " movnti %%edx, 28(%3)\n"
30735 - "11: movl 32(%4), %%eax\n"
30736 - "61: movl 36(%4), %%edx\n"
30737 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30738 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30739 " movnti %%eax, 32(%3)\n"
30740 " movnti %%edx, 36(%3)\n"
30741 - "12: movl 40(%4), %%eax\n"
30742 - "71: movl 44(%4), %%edx\n"
30743 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30744 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30745 " movnti %%eax, 40(%3)\n"
30746 " movnti %%edx, 44(%3)\n"
30747 - "13: movl 48(%4), %%eax\n"
30748 - "81: movl 52(%4), %%edx\n"
30749 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30750 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30751 " movnti %%eax, 48(%3)\n"
30752 " movnti %%edx, 52(%3)\n"
30753 - "14: movl 56(%4), %%eax\n"
30754 - "91: movl 60(%4), %%edx\n"
30755 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30756 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30757 " movnti %%eax, 56(%3)\n"
30758 " movnti %%edx, 60(%3)\n"
30759 " addl $-64, %0\n"
30760 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30761 " shrl $2, %0\n"
30762 " andl $3, %%eax\n"
30763 " cld\n"
30764 - "6: rep; movsl\n"
30765 + "6: rep; "__copyuser_seg" movsl\n"
30766 " movl %%eax,%0\n"
30767 - "7: rep; movsb\n"
30768 + "7: rep; "__copyuser_seg" movsb\n"
30769 "8:\n"
30770 ".section .fixup,\"ax\"\n"
30771 "9: lea 0(%%eax,%0,4),%0\n"
30772 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30773
30774 __asm__ __volatile__(
30775 " .align 2,0x90\n"
30776 - "0: movl 32(%4), %%eax\n"
30777 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30778 " cmpl $67, %0\n"
30779 " jbe 2f\n"
30780 - "1: movl 64(%4), %%eax\n"
30781 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30782 " .align 2,0x90\n"
30783 - "2: movl 0(%4), %%eax\n"
30784 - "21: movl 4(%4), %%edx\n"
30785 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30786 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30787 " movnti %%eax, 0(%3)\n"
30788 " movnti %%edx, 4(%3)\n"
30789 - "3: movl 8(%4), %%eax\n"
30790 - "31: movl 12(%4),%%edx\n"
30791 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30792 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30793 " movnti %%eax, 8(%3)\n"
30794 " movnti %%edx, 12(%3)\n"
30795 - "4: movl 16(%4), %%eax\n"
30796 - "41: movl 20(%4), %%edx\n"
30797 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30798 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30799 " movnti %%eax, 16(%3)\n"
30800 " movnti %%edx, 20(%3)\n"
30801 - "10: movl 24(%4), %%eax\n"
30802 - "51: movl 28(%4), %%edx\n"
30803 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30804 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30805 " movnti %%eax, 24(%3)\n"
30806 " movnti %%edx, 28(%3)\n"
30807 - "11: movl 32(%4), %%eax\n"
30808 - "61: movl 36(%4), %%edx\n"
30809 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30810 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30811 " movnti %%eax, 32(%3)\n"
30812 " movnti %%edx, 36(%3)\n"
30813 - "12: movl 40(%4), %%eax\n"
30814 - "71: movl 44(%4), %%edx\n"
30815 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30816 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30817 " movnti %%eax, 40(%3)\n"
30818 " movnti %%edx, 44(%3)\n"
30819 - "13: movl 48(%4), %%eax\n"
30820 - "81: movl 52(%4), %%edx\n"
30821 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30822 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30823 " movnti %%eax, 48(%3)\n"
30824 " movnti %%edx, 52(%3)\n"
30825 - "14: movl 56(%4), %%eax\n"
30826 - "91: movl 60(%4), %%edx\n"
30827 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30828 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30829 " movnti %%eax, 56(%3)\n"
30830 " movnti %%edx, 60(%3)\n"
30831 " addl $-64, %0\n"
30832 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30833 " shrl $2, %0\n"
30834 " andl $3, %%eax\n"
30835 " cld\n"
30836 - "6: rep; movsl\n"
30837 + "6: rep; "__copyuser_seg" movsl\n"
30838 " movl %%eax,%0\n"
30839 - "7: rep; movsb\n"
30840 + "7: rep; "__copyuser_seg" movsb\n"
30841 "8:\n"
30842 ".section .fixup,\"ax\"\n"
30843 "9: lea 0(%%eax,%0,4),%0\n"
30844 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30845 */
30846 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30847 unsigned long size);
30848 -unsigned long __copy_user_intel(void __user *to, const void *from,
30849 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30850 + unsigned long size);
30851 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30852 unsigned long size);
30853 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30854 const void __user *from, unsigned long size);
30855 #endif /* CONFIG_X86_INTEL_USERCOPY */
30856
30857 /* Generic arbitrary sized copy. */
30858 -#define __copy_user(to, from, size) \
30859 +#define __copy_user(to, from, size, prefix, set, restore) \
30860 do { \
30861 int __d0, __d1, __d2; \
30862 __asm__ __volatile__( \
30863 + set \
30864 " cmp $7,%0\n" \
30865 " jbe 1f\n" \
30866 " movl %1,%0\n" \
30867 " negl %0\n" \
30868 " andl $7,%0\n" \
30869 " subl %0,%3\n" \
30870 - "4: rep; movsb\n" \
30871 + "4: rep; "prefix"movsb\n" \
30872 " movl %3,%0\n" \
30873 " shrl $2,%0\n" \
30874 " andl $3,%3\n" \
30875 " .align 2,0x90\n" \
30876 - "0: rep; movsl\n" \
30877 + "0: rep; "prefix"movsl\n" \
30878 " movl %3,%0\n" \
30879 - "1: rep; movsb\n" \
30880 + "1: rep; "prefix"movsb\n" \
30881 "2:\n" \
30882 + restore \
30883 ".section .fixup,\"ax\"\n" \
30884 "5: addl %3,%0\n" \
30885 " jmp 2b\n" \
30886 @@ -538,14 +650,14 @@ do { \
30887 " negl %0\n" \
30888 " andl $7,%0\n" \
30889 " subl %0,%3\n" \
30890 - "4: rep; movsb\n" \
30891 + "4: rep; "__copyuser_seg"movsb\n" \
30892 " movl %3,%0\n" \
30893 " shrl $2,%0\n" \
30894 " andl $3,%3\n" \
30895 " .align 2,0x90\n" \
30896 - "0: rep; movsl\n" \
30897 + "0: rep; "__copyuser_seg"movsl\n" \
30898 " movl %3,%0\n" \
30899 - "1: rep; movsb\n" \
30900 + "1: rep; "__copyuser_seg"movsb\n" \
30901 "2:\n" \
30902 ".section .fixup,\"ax\"\n" \
30903 "5: addl %3,%0\n" \
30904 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30905 {
30906 stac();
30907 if (movsl_is_ok(to, from, n))
30908 - __copy_user(to, from, n);
30909 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30910 else
30911 - n = __copy_user_intel(to, from, n);
30912 + n = __generic_copy_to_user_intel(to, from, n);
30913 clac();
30914 return n;
30915 }
30916 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30917 {
30918 stac();
30919 if (movsl_is_ok(to, from, n))
30920 - __copy_user(to, from, n);
30921 + __copy_user(to, from, n, __copyuser_seg, "", "");
30922 else
30923 - n = __copy_user_intel((void __user *)to,
30924 - (const void *)from, n);
30925 + n = __generic_copy_from_user_intel(to, from, n);
30926 clac();
30927 return n;
30928 }
30929 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30930 if (n > 64 && cpu_has_xmm2)
30931 n = __copy_user_intel_nocache(to, from, n);
30932 else
30933 - __copy_user(to, from, n);
30934 + __copy_user(to, from, n, __copyuser_seg, "", "");
30935 #else
30936 - __copy_user(to, from, n);
30937 + __copy_user(to, from, n, __copyuser_seg, "", "");
30938 #endif
30939 clac();
30940 return n;
30941 }
30942 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30943
30944 -/**
30945 - * copy_to_user: - Copy a block of data into user space.
30946 - * @to: Destination address, in user space.
30947 - * @from: Source address, in kernel space.
30948 - * @n: Number of bytes to copy.
30949 - *
30950 - * Context: User context only. This function may sleep.
30951 - *
30952 - * Copy data from kernel space to user space.
30953 - *
30954 - * Returns number of bytes that could not be copied.
30955 - * On success, this will be zero.
30956 - */
30957 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
30958 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30959 +void __set_fs(mm_segment_t x)
30960 {
30961 - if (access_ok(VERIFY_WRITE, to, n))
30962 - n = __copy_to_user(to, from, n);
30963 - return n;
30964 + switch (x.seg) {
30965 + case 0:
30966 + loadsegment(gs, 0);
30967 + break;
30968 + case TASK_SIZE_MAX:
30969 + loadsegment(gs, __USER_DS);
30970 + break;
30971 + case -1UL:
30972 + loadsegment(gs, __KERNEL_DS);
30973 + break;
30974 + default:
30975 + BUG();
30976 + }
30977 }
30978 -EXPORT_SYMBOL(_copy_to_user);
30979 +EXPORT_SYMBOL(__set_fs);
30980
30981 -/**
30982 - * copy_from_user: - Copy a block of data from user space.
30983 - * @to: Destination address, in kernel space.
30984 - * @from: Source address, in user space.
30985 - * @n: Number of bytes to copy.
30986 - *
30987 - * Context: User context only. This function may sleep.
30988 - *
30989 - * Copy data from user space to kernel space.
30990 - *
30991 - * Returns number of bytes that could not be copied.
30992 - * On success, this will be zero.
30993 - *
30994 - * If some data could not be copied, this function will pad the copied
30995 - * data to the requested size using zero bytes.
30996 - */
30997 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
30998 +void set_fs(mm_segment_t x)
30999 {
31000 - if (access_ok(VERIFY_READ, from, n))
31001 - n = __copy_from_user(to, from, n);
31002 - else
31003 - memset(to, 0, n);
31004 - return n;
31005 + current_thread_info()->addr_limit = x;
31006 + __set_fs(x);
31007 }
31008 -EXPORT_SYMBOL(_copy_from_user);
31009 +EXPORT_SYMBOL(set_fs);
31010 +#endif
31011 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31012 index c905e89..01ab928 100644
31013 --- a/arch/x86/lib/usercopy_64.c
31014 +++ b/arch/x86/lib/usercopy_64.c
31015 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31016 might_fault();
31017 /* no memory constraint because it doesn't change any memory gcc knows
31018 about */
31019 + pax_open_userland();
31020 stac();
31021 asm volatile(
31022 " testq %[size8],%[size8]\n"
31023 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31024 _ASM_EXTABLE(0b,3b)
31025 _ASM_EXTABLE(1b,2b)
31026 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31027 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31028 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31029 [zero] "r" (0UL), [eight] "r" (8UL));
31030 clac();
31031 + pax_close_userland();
31032 return size;
31033 }
31034 EXPORT_SYMBOL(__clear_user);
31035 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31036 }
31037 EXPORT_SYMBOL(clear_user);
31038
31039 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31040 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31041 {
31042 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31043 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31044 - }
31045 - return len;
31046 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31047 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31048 + return len;
31049 }
31050 EXPORT_SYMBOL(copy_in_user);
31051
31052 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31053 * it is not necessary to optimize tail handling.
31054 */
31055 __visible unsigned long
31056 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31057 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31058 {
31059 char c;
31060 unsigned zero_len;
31061
31062 + clac();
31063 + pax_close_userland();
31064 for (; len; --len, to++) {
31065 if (__get_user_nocheck(c, from++, sizeof(char)))
31066 break;
31067 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31068 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31069 if (__put_user_nocheck(c, to++, sizeof(char)))
31070 break;
31071 - clac();
31072 return len;
31073 }
31074 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31075 index 6a19ad9..1c48f9a 100644
31076 --- a/arch/x86/mm/Makefile
31077 +++ b/arch/x86/mm/Makefile
31078 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31079 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31080
31081 obj-$(CONFIG_MEMTEST) += memtest.o
31082 +
31083 +quote:="
31084 +obj-$(CONFIG_X86_64) += uderef_64.o
31085 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31086 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31087 index 903ec1e..c4166b2 100644
31088 --- a/arch/x86/mm/extable.c
31089 +++ b/arch/x86/mm/extable.c
31090 @@ -6,12 +6,24 @@
31091 static inline unsigned long
31092 ex_insn_addr(const struct exception_table_entry *x)
31093 {
31094 - return (unsigned long)&x->insn + x->insn;
31095 + unsigned long reloc = 0;
31096 +
31097 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31098 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31099 +#endif
31100 +
31101 + return (unsigned long)&x->insn + x->insn + reloc;
31102 }
31103 static inline unsigned long
31104 ex_fixup_addr(const struct exception_table_entry *x)
31105 {
31106 - return (unsigned long)&x->fixup + x->fixup;
31107 + unsigned long reloc = 0;
31108 +
31109 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31110 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31111 +#endif
31112 +
31113 + return (unsigned long)&x->fixup + x->fixup + reloc;
31114 }
31115
31116 int fixup_exception(struct pt_regs *regs)
31117 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31118 unsigned long new_ip;
31119
31120 #ifdef CONFIG_PNPBIOS
31121 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31122 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31123 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31124 extern u32 pnp_bios_is_utter_crap;
31125 pnp_bios_is_utter_crap = 1;
31126 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31127 i += 4;
31128 p->fixup -= i;
31129 i += 4;
31130 +
31131 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31132 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31133 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31134 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31135 +#endif
31136 +
31137 }
31138 }
31139
31140 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31141 index a10c8c7..35a5abb 100644
31142 --- a/arch/x86/mm/fault.c
31143 +++ b/arch/x86/mm/fault.c
31144 @@ -14,11 +14,18 @@
31145 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31146 #include <linux/prefetch.h> /* prefetchw */
31147 #include <linux/context_tracking.h> /* exception_enter(), ... */
31148 +#include <linux/unistd.h>
31149 +#include <linux/compiler.h>
31150
31151 #include <asm/traps.h> /* dotraplinkage, ... */
31152 #include <asm/pgalloc.h> /* pgd_*(), ... */
31153 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31154 #include <asm/fixmap.h> /* VSYSCALL_START */
31155 +#include <asm/tlbflush.h>
31156 +
31157 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31158 +#include <asm/stacktrace.h>
31159 +#endif
31160
31161 #define CREATE_TRACE_POINTS
31162 #include <asm/trace/exceptions.h>
31163 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31164 int ret = 0;
31165
31166 /* kprobe_running() needs smp_processor_id() */
31167 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31168 + if (kprobes_built_in() && !user_mode(regs)) {
31169 preempt_disable();
31170 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31171 ret = 1;
31172 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31173 return !instr_lo || (instr_lo>>1) == 1;
31174 case 0x00:
31175 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31176 - if (probe_kernel_address(instr, opcode))
31177 + if (user_mode(regs)) {
31178 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31179 + return 0;
31180 + } else if (probe_kernel_address(instr, opcode))
31181 return 0;
31182
31183 *prefetch = (instr_lo == 0xF) &&
31184 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31185 while (instr < max_instr) {
31186 unsigned char opcode;
31187
31188 - if (probe_kernel_address(instr, opcode))
31189 + if (user_mode(regs)) {
31190 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31191 + break;
31192 + } else if (probe_kernel_address(instr, opcode))
31193 break;
31194
31195 instr++;
31196 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31197 force_sig_info(si_signo, &info, tsk);
31198 }
31199
31200 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31201 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31202 +#endif
31203 +
31204 +#ifdef CONFIG_PAX_EMUTRAMP
31205 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31206 +#endif
31207 +
31208 +#ifdef CONFIG_PAX_PAGEEXEC
31209 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31210 +{
31211 + pgd_t *pgd;
31212 + pud_t *pud;
31213 + pmd_t *pmd;
31214 +
31215 + pgd = pgd_offset(mm, address);
31216 + if (!pgd_present(*pgd))
31217 + return NULL;
31218 + pud = pud_offset(pgd, address);
31219 + if (!pud_present(*pud))
31220 + return NULL;
31221 + pmd = pmd_offset(pud, address);
31222 + if (!pmd_present(*pmd))
31223 + return NULL;
31224 + return pmd;
31225 +}
31226 +#endif
31227 +
31228 DEFINE_SPINLOCK(pgd_lock);
31229 LIST_HEAD(pgd_list);
31230
31231 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31232 for (address = VMALLOC_START & PMD_MASK;
31233 address >= TASK_SIZE && address < FIXADDR_TOP;
31234 address += PMD_SIZE) {
31235 +
31236 +#ifdef CONFIG_PAX_PER_CPU_PGD
31237 + unsigned long cpu;
31238 +#else
31239 struct page *page;
31240 +#endif
31241
31242 spin_lock(&pgd_lock);
31243 +
31244 +#ifdef CONFIG_PAX_PER_CPU_PGD
31245 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31246 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31247 + pmd_t *ret;
31248 +
31249 + ret = vmalloc_sync_one(pgd, address);
31250 + if (!ret)
31251 + break;
31252 + pgd = get_cpu_pgd(cpu, kernel);
31253 +#else
31254 list_for_each_entry(page, &pgd_list, lru) {
31255 + pgd_t *pgd;
31256 spinlock_t *pgt_lock;
31257 pmd_t *ret;
31258
31259 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31260 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31261
31262 spin_lock(pgt_lock);
31263 - ret = vmalloc_sync_one(page_address(page), address);
31264 + pgd = page_address(page);
31265 +#endif
31266 +
31267 + ret = vmalloc_sync_one(pgd, address);
31268 +
31269 +#ifndef CONFIG_PAX_PER_CPU_PGD
31270 spin_unlock(pgt_lock);
31271 +#endif
31272
31273 if (!ret)
31274 break;
31275 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31276 * an interrupt in the middle of a task switch..
31277 */
31278 pgd_paddr = read_cr3();
31279 +
31280 +#ifdef CONFIG_PAX_PER_CPU_PGD
31281 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31282 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31283 +#endif
31284 +
31285 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31286 if (!pmd_k)
31287 return -1;
31288 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31289 * happen within a race in page table update. In the later
31290 * case just flush:
31291 */
31292 - pgd = pgd_offset(current->active_mm, address);
31293 +
31294 pgd_ref = pgd_offset_k(address);
31295 if (pgd_none(*pgd_ref))
31296 return -1;
31297
31298 +#ifdef CONFIG_PAX_PER_CPU_PGD
31299 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31300 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31301 + if (pgd_none(*pgd)) {
31302 + set_pgd(pgd, *pgd_ref);
31303 + arch_flush_lazy_mmu_mode();
31304 + } else {
31305 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31306 + }
31307 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31308 +#else
31309 + pgd = pgd_offset(current->active_mm, address);
31310 +#endif
31311 +
31312 if (pgd_none(*pgd)) {
31313 set_pgd(pgd, *pgd_ref);
31314 arch_flush_lazy_mmu_mode();
31315 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31316 static int is_errata100(struct pt_regs *regs, unsigned long address)
31317 {
31318 #ifdef CONFIG_X86_64
31319 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31320 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31321 return 1;
31322 #endif
31323 return 0;
31324 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31325 }
31326
31327 static const char nx_warning[] = KERN_CRIT
31328 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31329 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31330
31331 static void
31332 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31333 @@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31334 if (!oops_may_print())
31335 return;
31336
31337 - if (error_code & PF_INSTR) {
31338 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31339 unsigned int level;
31340
31341 pte_t *pte = lookup_address(address, &level);
31342
31343 if (pte && pte_present(*pte) && !pte_exec(*pte))
31344 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31345 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31346 }
31347
31348 +#ifdef CONFIG_PAX_KERNEXEC
31349 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31350 + if (current->signal->curr_ip)
31351 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31352 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31353 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31354 + else
31355 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31356 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31357 + }
31358 +#endif
31359 +
31360 printk(KERN_ALERT "BUG: unable to handle kernel ");
31361 if (address < PAGE_SIZE)
31362 printk(KERN_CONT "NULL pointer dereference");
31363 @@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31364 return;
31365 }
31366 #endif
31367 +
31368 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31369 + if (pax_is_fetch_fault(regs, error_code, address)) {
31370 +
31371 +#ifdef CONFIG_PAX_EMUTRAMP
31372 + switch (pax_handle_fetch_fault(regs)) {
31373 + case 2:
31374 + return;
31375 + }
31376 +#endif
31377 +
31378 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31379 + do_group_exit(SIGKILL);
31380 + }
31381 +#endif
31382 +
31383 /* Kernel addresses are always protection faults: */
31384 if (address >= TASK_SIZE)
31385 error_code |= PF_PROT;
31386 @@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31387 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31388 printk(KERN_ERR
31389 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31390 - tsk->comm, tsk->pid, address);
31391 + tsk->comm, task_pid_nr(tsk), address);
31392 code = BUS_MCEERR_AR;
31393 }
31394 #endif
31395 @@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31396 return 1;
31397 }
31398
31399 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31400 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31401 +{
31402 + pte_t *pte;
31403 + pmd_t *pmd;
31404 + spinlock_t *ptl;
31405 + unsigned char pte_mask;
31406 +
31407 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31408 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31409 + return 0;
31410 +
31411 + /* PaX: it's our fault, let's handle it if we can */
31412 +
31413 + /* PaX: take a look at read faults before acquiring any locks */
31414 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31415 + /* instruction fetch attempt from a protected page in user mode */
31416 + up_read(&mm->mmap_sem);
31417 +
31418 +#ifdef CONFIG_PAX_EMUTRAMP
31419 + switch (pax_handle_fetch_fault(regs)) {
31420 + case 2:
31421 + return 1;
31422 + }
31423 +#endif
31424 +
31425 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31426 + do_group_exit(SIGKILL);
31427 + }
31428 +
31429 + pmd = pax_get_pmd(mm, address);
31430 + if (unlikely(!pmd))
31431 + return 0;
31432 +
31433 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31434 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31435 + pte_unmap_unlock(pte, ptl);
31436 + return 0;
31437 + }
31438 +
31439 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31440 + /* write attempt to a protected page in user mode */
31441 + pte_unmap_unlock(pte, ptl);
31442 + return 0;
31443 + }
31444 +
31445 +#ifdef CONFIG_SMP
31446 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31447 +#else
31448 + if (likely(address > get_limit(regs->cs)))
31449 +#endif
31450 + {
31451 + set_pte(pte, pte_mkread(*pte));
31452 + __flush_tlb_one(address);
31453 + pte_unmap_unlock(pte, ptl);
31454 + up_read(&mm->mmap_sem);
31455 + return 1;
31456 + }
31457 +
31458 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31459 +
31460 + /*
31461 + * PaX: fill DTLB with user rights and retry
31462 + */
31463 + __asm__ __volatile__ (
31464 + "orb %2,(%1)\n"
31465 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31466 +/*
31467 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31468 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31469 + * page fault when examined during a TLB load attempt. this is true not only
31470 + * for PTEs holding a non-present entry but also present entries that will
31471 + * raise a page fault (such as those set up by PaX, or the copy-on-write
31472 + * mechanism). in effect it means that we do *not* need to flush the TLBs
31473 + * for our target pages since their PTEs are simply not in the TLBs at all.
31474 +
31475 + * the best thing in omitting it is that we gain around 15-20% speed in the
31476 + * fast path of the page fault handler and can get rid of tracing since we
31477 + * can no longer flush unintended entries.
31478 + */
31479 + "invlpg (%0)\n"
31480 +#endif
31481 + __copyuser_seg"testb $0,(%0)\n"
31482 + "xorb %3,(%1)\n"
31483 + :
31484 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31485 + : "memory", "cc");
31486 + pte_unmap_unlock(pte, ptl);
31487 + up_read(&mm->mmap_sem);
31488 + return 1;
31489 +}
31490 +#endif
31491 +
31492 /*
31493 * Handle a spurious fault caused by a stale TLB entry.
31494 *
31495 @@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31496 static inline int
31497 access_error(unsigned long error_code, struct vm_area_struct *vma)
31498 {
31499 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31500 + return 1;
31501 +
31502 if (error_code & PF_WRITE) {
31503 /* write, present and write, not present: */
31504 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31505 @@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31506 if (error_code & PF_USER)
31507 return false;
31508
31509 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31510 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31511 return false;
31512
31513 return true;
31514 @@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31515 tsk = current;
31516 mm = tsk->mm;
31517
31518 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31519 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31520 + if (!search_exception_tables(regs->ip)) {
31521 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31522 + bad_area_nosemaphore(regs, error_code, address);
31523 + return;
31524 + }
31525 + if (address < pax_user_shadow_base) {
31526 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31527 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31528 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31529 + } else
31530 + address -= pax_user_shadow_base;
31531 + }
31532 +#endif
31533 +
31534 /*
31535 * Detect and handle instructions that would cause a page fault for
31536 * both a tracked kernel page and a userspace page.
31537 @@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31538 * User-mode registers count as a user access even for any
31539 * potential system fault or CPU buglet:
31540 */
31541 - if (user_mode_vm(regs)) {
31542 + if (user_mode(regs)) {
31543 local_irq_enable();
31544 error_code |= PF_USER;
31545 flags |= FAULT_FLAG_USER;
31546 @@ -1162,6 +1386,11 @@ retry:
31547 might_sleep();
31548 }
31549
31550 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31551 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31552 + return;
31553 +#endif
31554 +
31555 vma = find_vma(mm, address);
31556 if (unlikely(!vma)) {
31557 bad_area(regs, error_code, address);
31558 @@ -1173,18 +1402,24 @@ retry:
31559 bad_area(regs, error_code, address);
31560 return;
31561 }
31562 - if (error_code & PF_USER) {
31563 - /*
31564 - * Accessing the stack below %sp is always a bug.
31565 - * The large cushion allows instructions like enter
31566 - * and pusha to work. ("enter $65535, $31" pushes
31567 - * 32 pointers and then decrements %sp by 65535.)
31568 - */
31569 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31570 - bad_area(regs, error_code, address);
31571 - return;
31572 - }
31573 + /*
31574 + * Accessing the stack below %sp is always a bug.
31575 + * The large cushion allows instructions like enter
31576 + * and pusha to work. ("enter $65535, $31" pushes
31577 + * 32 pointers and then decrements %sp by 65535.)
31578 + */
31579 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31580 + bad_area(regs, error_code, address);
31581 + return;
31582 }
31583 +
31584 +#ifdef CONFIG_PAX_SEGMEXEC
31585 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31586 + bad_area(regs, error_code, address);
31587 + return;
31588 + }
31589 +#endif
31590 +
31591 if (unlikely(expand_stack(vma, address))) {
31592 bad_area(regs, error_code, address);
31593 return;
31594 @@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31595 exception_exit(prev_state);
31596 }
31597 #endif /* CONFIG_TRACING */
31598 +
31599 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31600 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31601 +{
31602 + struct mm_struct *mm = current->mm;
31603 + unsigned long ip = regs->ip;
31604 +
31605 + if (v8086_mode(regs))
31606 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31607 +
31608 +#ifdef CONFIG_PAX_PAGEEXEC
31609 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31610 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31611 + return true;
31612 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31613 + return true;
31614 + return false;
31615 + }
31616 +#endif
31617 +
31618 +#ifdef CONFIG_PAX_SEGMEXEC
31619 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31620 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31621 + return true;
31622 + return false;
31623 + }
31624 +#endif
31625 +
31626 + return false;
31627 +}
31628 +#endif
31629 +
31630 +#ifdef CONFIG_PAX_EMUTRAMP
31631 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31632 +{
31633 + int err;
31634 +
31635 + do { /* PaX: libffi trampoline emulation */
31636 + unsigned char mov, jmp;
31637 + unsigned int addr1, addr2;
31638 +
31639 +#ifdef CONFIG_X86_64
31640 + if ((regs->ip + 9) >> 32)
31641 + break;
31642 +#endif
31643 +
31644 + err = get_user(mov, (unsigned char __user *)regs->ip);
31645 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31646 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31647 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31648 +
31649 + if (err)
31650 + break;
31651 +
31652 + if (mov == 0xB8 && jmp == 0xE9) {
31653 + regs->ax = addr1;
31654 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31655 + return 2;
31656 + }
31657 + } while (0);
31658 +
31659 + do { /* PaX: gcc trampoline emulation #1 */
31660 + unsigned char mov1, mov2;
31661 + unsigned short jmp;
31662 + unsigned int addr1, addr2;
31663 +
31664 +#ifdef CONFIG_X86_64
31665 + if ((regs->ip + 11) >> 32)
31666 + break;
31667 +#endif
31668 +
31669 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31670 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31671 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31672 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31673 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31674 +
31675 + if (err)
31676 + break;
31677 +
31678 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31679 + regs->cx = addr1;
31680 + regs->ax = addr2;
31681 + regs->ip = addr2;
31682 + return 2;
31683 + }
31684 + } while (0);
31685 +
31686 + do { /* PaX: gcc trampoline emulation #2 */
31687 + unsigned char mov, jmp;
31688 + unsigned int addr1, addr2;
31689 +
31690 +#ifdef CONFIG_X86_64
31691 + if ((regs->ip + 9) >> 32)
31692 + break;
31693 +#endif
31694 +
31695 + err = get_user(mov, (unsigned char __user *)regs->ip);
31696 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31697 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31698 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31699 +
31700 + if (err)
31701 + break;
31702 +
31703 + if (mov == 0xB9 && jmp == 0xE9) {
31704 + regs->cx = addr1;
31705 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31706 + return 2;
31707 + }
31708 + } while (0);
31709 +
31710 + return 1; /* PaX in action */
31711 +}
31712 +
31713 +#ifdef CONFIG_X86_64
31714 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31715 +{
31716 + int err;
31717 +
31718 + do { /* PaX: libffi trampoline emulation */
31719 + unsigned short mov1, mov2, jmp1;
31720 + unsigned char stcclc, jmp2;
31721 + unsigned long addr1, addr2;
31722 +
31723 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31724 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31725 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31726 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31727 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31728 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31729 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31730 +
31731 + if (err)
31732 + break;
31733 +
31734 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31735 + regs->r11 = addr1;
31736 + regs->r10 = addr2;
31737 + if (stcclc == 0xF8)
31738 + regs->flags &= ~X86_EFLAGS_CF;
31739 + else
31740 + regs->flags |= X86_EFLAGS_CF;
31741 + regs->ip = addr1;
31742 + return 2;
31743 + }
31744 + } while (0);
31745 +
31746 + do { /* PaX: gcc trampoline emulation #1 */
31747 + unsigned short mov1, mov2, jmp1;
31748 + unsigned char jmp2;
31749 + unsigned int addr1;
31750 + unsigned long addr2;
31751 +
31752 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31753 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31754 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31755 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31756 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31757 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31758 +
31759 + if (err)
31760 + break;
31761 +
31762 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31763 + regs->r11 = addr1;
31764 + regs->r10 = addr2;
31765 + regs->ip = addr1;
31766 + return 2;
31767 + }
31768 + } while (0);
31769 +
31770 + do { /* PaX: gcc trampoline emulation #2 */
31771 + unsigned short mov1, mov2, jmp1;
31772 + unsigned char jmp2;
31773 + unsigned long addr1, addr2;
31774 +
31775 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31776 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31777 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31778 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31779 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31780 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31781 +
31782 + if (err)
31783 + break;
31784 +
31785 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31786 + regs->r11 = addr1;
31787 + regs->r10 = addr2;
31788 + regs->ip = addr1;
31789 + return 2;
31790 + }
31791 + } while (0);
31792 +
31793 + return 1; /* PaX in action */
31794 +}
31795 +#endif
31796 +
31797 +/*
31798 + * PaX: decide what to do with offenders (regs->ip = fault address)
31799 + *
31800 + * returns 1 when task should be killed
31801 + * 2 when gcc trampoline was detected
31802 + */
31803 +static int pax_handle_fetch_fault(struct pt_regs *regs)
31804 +{
31805 + if (v8086_mode(regs))
31806 + return 1;
31807 +
31808 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31809 + return 1;
31810 +
31811 +#ifdef CONFIG_X86_32
31812 + return pax_handle_fetch_fault_32(regs);
31813 +#else
31814 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31815 + return pax_handle_fetch_fault_32(regs);
31816 + else
31817 + return pax_handle_fetch_fault_64(regs);
31818 +#endif
31819 +}
31820 +#endif
31821 +
31822 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31823 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31824 +{
31825 + long i;
31826 +
31827 + printk(KERN_ERR "PAX: bytes at PC: ");
31828 + for (i = 0; i < 20; i++) {
31829 + unsigned char c;
31830 + if (get_user(c, (unsigned char __force_user *)pc+i))
31831 + printk(KERN_CONT "?? ");
31832 + else
31833 + printk(KERN_CONT "%02x ", c);
31834 + }
31835 + printk("\n");
31836 +
31837 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31838 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
31839 + unsigned long c;
31840 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
31841 +#ifdef CONFIG_X86_32
31842 + printk(KERN_CONT "???????? ");
31843 +#else
31844 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31845 + printk(KERN_CONT "???????? ???????? ");
31846 + else
31847 + printk(KERN_CONT "???????????????? ");
31848 +#endif
31849 + } else {
31850 +#ifdef CONFIG_X86_64
31851 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31852 + printk(KERN_CONT "%08x ", (unsigned int)c);
31853 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31854 + } else
31855 +#endif
31856 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31857 + }
31858 + }
31859 + printk("\n");
31860 +}
31861 +#endif
31862 +
31863 +/**
31864 + * probe_kernel_write(): safely attempt to write to a location
31865 + * @dst: address to write to
31866 + * @src: pointer to the data that shall be written
31867 + * @size: size of the data chunk
31868 + *
31869 + * Safely write to address @dst from the buffer at @src. If a kernel fault
31870 + * happens, handle that and return -EFAULT.
31871 + */
31872 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31873 +{
31874 + long ret;
31875 + mm_segment_t old_fs = get_fs();
31876 +
31877 + set_fs(KERNEL_DS);
31878 + pagefault_disable();
31879 + pax_open_kernel();
31880 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31881 + pax_close_kernel();
31882 + pagefault_enable();
31883 + set_fs(old_fs);
31884 +
31885 + return ret ? -EFAULT : 0;
31886 +}
31887 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31888 index 207d9aef..69030980 100644
31889 --- a/arch/x86/mm/gup.c
31890 +++ b/arch/x86/mm/gup.c
31891 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31892 addr = start;
31893 len = (unsigned long) nr_pages << PAGE_SHIFT;
31894 end = start + len;
31895 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31896 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31897 (void __user *)start, len)))
31898 return 0;
31899
31900 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31901 goto slow_irqon;
31902 #endif
31903
31904 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31905 + (void __user *)start, len)))
31906 + return 0;
31907 +
31908 /*
31909 * XXX: batch / limit 'nr', to avoid large irq off latency
31910 * needs some instrumenting to determine the common sizes used by
31911 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31912 index 4500142..53a363c 100644
31913 --- a/arch/x86/mm/highmem_32.c
31914 +++ b/arch/x86/mm/highmem_32.c
31915 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31916 idx = type + KM_TYPE_NR*smp_processor_id();
31917 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31918 BUG_ON(!pte_none(*(kmap_pte-idx)));
31919 +
31920 + pax_open_kernel();
31921 set_pte(kmap_pte-idx, mk_pte(page, prot));
31922 + pax_close_kernel();
31923 +
31924 arch_flush_lazy_mmu_mode();
31925
31926 return (void *)vaddr;
31927 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31928 index 8c9f647..57cb402 100644
31929 --- a/arch/x86/mm/hugetlbpage.c
31930 +++ b/arch/x86/mm/hugetlbpage.c
31931 @@ -90,23 +90,24 @@ int pmd_huge_support(void)
31932 #ifdef CONFIG_HUGETLB_PAGE
31933 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31934 unsigned long addr, unsigned long len,
31935 - unsigned long pgoff, unsigned long flags)
31936 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31937 {
31938 struct hstate *h = hstate_file(file);
31939 struct vm_unmapped_area_info info;
31940 -
31941 +
31942 info.flags = 0;
31943 info.length = len;
31944 info.low_limit = current->mm->mmap_legacy_base;
31945 info.high_limit = TASK_SIZE;
31946 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31947 info.align_offset = 0;
31948 + info.threadstack_offset = offset;
31949 return vm_unmapped_area(&info);
31950 }
31951
31952 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31953 unsigned long addr0, unsigned long len,
31954 - unsigned long pgoff, unsigned long flags)
31955 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31956 {
31957 struct hstate *h = hstate_file(file);
31958 struct vm_unmapped_area_info info;
31959 @@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31960 info.high_limit = current->mm->mmap_base;
31961 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31962 info.align_offset = 0;
31963 + info.threadstack_offset = offset;
31964 addr = vm_unmapped_area(&info);
31965
31966 /*
31967 @@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31968 VM_BUG_ON(addr != -ENOMEM);
31969 info.flags = 0;
31970 info.low_limit = TASK_UNMAPPED_BASE;
31971 +
31972 +#ifdef CONFIG_PAX_RANDMMAP
31973 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31974 + info.low_limit += current->mm->delta_mmap;
31975 +#endif
31976 +
31977 info.high_limit = TASK_SIZE;
31978 addr = vm_unmapped_area(&info);
31979 }
31980 @@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31981 struct hstate *h = hstate_file(file);
31982 struct mm_struct *mm = current->mm;
31983 struct vm_area_struct *vma;
31984 + unsigned long pax_task_size = TASK_SIZE;
31985 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
31986
31987 if (len & ~huge_page_mask(h))
31988 return -EINVAL;
31989 - if (len > TASK_SIZE)
31990 +
31991 +#ifdef CONFIG_PAX_SEGMEXEC
31992 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
31993 + pax_task_size = SEGMEXEC_TASK_SIZE;
31994 +#endif
31995 +
31996 + pax_task_size -= PAGE_SIZE;
31997 +
31998 + if (len > pax_task_size)
31999 return -ENOMEM;
32000
32001 if (flags & MAP_FIXED) {
32002 @@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32003 return addr;
32004 }
32005
32006 +#ifdef CONFIG_PAX_RANDMMAP
32007 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32008 +#endif
32009 +
32010 if (addr) {
32011 addr = ALIGN(addr, huge_page_size(h));
32012 vma = find_vma(mm, addr);
32013 - if (TASK_SIZE - len >= addr &&
32014 - (!vma || addr + len <= vma->vm_start))
32015 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32016 return addr;
32017 }
32018 if (mm->get_unmapped_area == arch_get_unmapped_area)
32019 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32020 - pgoff, flags);
32021 + pgoff, flags, offset);
32022 else
32023 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32024 - pgoff, flags);
32025 + pgoff, flags, offset);
32026 }
32027 #endif /* CONFIG_HUGETLB_PAGE */
32028
32029 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32030 index f971306..e83e0f6 100644
32031 --- a/arch/x86/mm/init.c
32032 +++ b/arch/x86/mm/init.c
32033 @@ -4,6 +4,7 @@
32034 #include <linux/swap.h>
32035 #include <linux/memblock.h>
32036 #include <linux/bootmem.h> /* for max_low_pfn */
32037 +#include <linux/tboot.h>
32038
32039 #include <asm/cacheflush.h>
32040 #include <asm/e820.h>
32041 @@ -17,6 +18,8 @@
32042 #include <asm/proto.h>
32043 #include <asm/dma.h> /* for MAX_DMA_PFN */
32044 #include <asm/microcode.h>
32045 +#include <asm/desc.h>
32046 +#include <asm/bios_ebda.h>
32047
32048 #include "mm_internal.h"
32049
32050 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32051 early_ioremap_page_table_range_init();
32052 #endif
32053
32054 +#ifdef CONFIG_PAX_PER_CPU_PGD
32055 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32056 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32057 + KERNEL_PGD_PTRS);
32058 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32059 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32060 + KERNEL_PGD_PTRS);
32061 + load_cr3(get_cpu_pgd(0, kernel));
32062 +#else
32063 load_cr3(swapper_pg_dir);
32064 +#endif
32065 +
32066 __flush_tlb_all();
32067
32068 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32069 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32070 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32071 * mmio resources as well as potential bios/acpi data regions.
32072 */
32073 +
32074 +#ifdef CONFIG_GRKERNSEC_KMEM
32075 +static unsigned int ebda_start __read_only;
32076 +static unsigned int ebda_end __read_only;
32077 +#endif
32078 +
32079 int devmem_is_allowed(unsigned long pagenr)
32080 {
32081 - if (pagenr < 256)
32082 +#ifdef CONFIG_GRKERNSEC_KMEM
32083 + /* allow BDA */
32084 + if (!pagenr)
32085 return 1;
32086 + /* allow EBDA */
32087 + if (pagenr >= ebda_start && pagenr < ebda_end)
32088 + return 1;
32089 + /* if tboot is in use, allow access to its hardcoded serial log range */
32090 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32091 + return 1;
32092 +#else
32093 + if (!pagenr)
32094 + return 1;
32095 +#ifdef CONFIG_VM86
32096 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32097 + return 1;
32098 +#endif
32099 +#endif
32100 +
32101 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32102 + return 1;
32103 +#ifdef CONFIG_GRKERNSEC_KMEM
32104 + /* throw out everything else below 1MB */
32105 + if (pagenr <= 256)
32106 + return 0;
32107 +#endif
32108 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32109 return 0;
32110 if (!page_is_ram(pagenr))
32111 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32112 #endif
32113 }
32114
32115 +#ifdef CONFIG_GRKERNSEC_KMEM
32116 +static inline void gr_init_ebda(void)
32117 +{
32118 + unsigned int ebda_addr;
32119 + unsigned int ebda_size = 0;
32120 +
32121 + ebda_addr = get_bios_ebda();
32122 + if (ebda_addr) {
32123 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32124 + ebda_size <<= 10;
32125 + }
32126 + if (ebda_addr && ebda_size) {
32127 + ebda_start = ebda_addr >> PAGE_SHIFT;
32128 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32129 + } else {
32130 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32131 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32132 + }
32133 +}
32134 +#else
32135 +static inline void gr_init_ebda(void) { }
32136 +#endif
32137 +
32138 void free_initmem(void)
32139 {
32140 +#ifdef CONFIG_PAX_KERNEXEC
32141 +#ifdef CONFIG_X86_32
32142 + /* PaX: limit KERNEL_CS to actual size */
32143 + unsigned long addr, limit;
32144 + struct desc_struct d;
32145 + int cpu;
32146 +#else
32147 + pgd_t *pgd;
32148 + pud_t *pud;
32149 + pmd_t *pmd;
32150 + unsigned long addr, end;
32151 +#endif
32152 +#endif
32153 +
32154 + gr_init_ebda();
32155 +
32156 +#ifdef CONFIG_PAX_KERNEXEC
32157 +#ifdef CONFIG_X86_32
32158 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32159 + limit = (limit - 1UL) >> PAGE_SHIFT;
32160 +
32161 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32162 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32163 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32164 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32165 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32166 + }
32167 +
32168 + /* PaX: make KERNEL_CS read-only */
32169 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32170 + if (!paravirt_enabled())
32171 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32172 +/*
32173 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32174 + pgd = pgd_offset_k(addr);
32175 + pud = pud_offset(pgd, addr);
32176 + pmd = pmd_offset(pud, addr);
32177 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32178 + }
32179 +*/
32180 +#ifdef CONFIG_X86_PAE
32181 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32182 +/*
32183 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32184 + pgd = pgd_offset_k(addr);
32185 + pud = pud_offset(pgd, addr);
32186 + pmd = pmd_offset(pud, addr);
32187 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32188 + }
32189 +*/
32190 +#endif
32191 +
32192 +#ifdef CONFIG_MODULES
32193 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32194 +#endif
32195 +
32196 +#else
32197 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32198 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32199 + pgd = pgd_offset_k(addr);
32200 + pud = pud_offset(pgd, addr);
32201 + pmd = pmd_offset(pud, addr);
32202 + if (!pmd_present(*pmd))
32203 + continue;
32204 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32205 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32206 + else
32207 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32208 + }
32209 +
32210 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32211 + end = addr + KERNEL_IMAGE_SIZE;
32212 + for (; addr < end; addr += PMD_SIZE) {
32213 + pgd = pgd_offset_k(addr);
32214 + pud = pud_offset(pgd, addr);
32215 + pmd = pmd_offset(pud, addr);
32216 + if (!pmd_present(*pmd))
32217 + continue;
32218 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32219 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32220 + }
32221 +#endif
32222 +
32223 + flush_tlb_all();
32224 +#endif
32225 +
32226 free_init_pages("unused kernel",
32227 (unsigned long)(&__init_begin),
32228 (unsigned long)(&__init_end));
32229 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32230 index e395048..cd38278 100644
32231 --- a/arch/x86/mm/init_32.c
32232 +++ b/arch/x86/mm/init_32.c
32233 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32234 bool __read_mostly __vmalloc_start_set = false;
32235
32236 /*
32237 - * Creates a middle page table and puts a pointer to it in the
32238 - * given global directory entry. This only returns the gd entry
32239 - * in non-PAE compilation mode, since the middle layer is folded.
32240 - */
32241 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32242 -{
32243 - pud_t *pud;
32244 - pmd_t *pmd_table;
32245 -
32246 -#ifdef CONFIG_X86_PAE
32247 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32248 - pmd_table = (pmd_t *)alloc_low_page();
32249 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32250 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32251 - pud = pud_offset(pgd, 0);
32252 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32253 -
32254 - return pmd_table;
32255 - }
32256 -#endif
32257 - pud = pud_offset(pgd, 0);
32258 - pmd_table = pmd_offset(pud, 0);
32259 -
32260 - return pmd_table;
32261 -}
32262 -
32263 -/*
32264 * Create a page table and place a pointer to it in a middle page
32265 * directory entry:
32266 */
32267 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32268 pte_t *page_table = (pte_t *)alloc_low_page();
32269
32270 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32271 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32272 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32273 +#else
32274 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32275 +#endif
32276 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32277 }
32278
32279 return pte_offset_kernel(pmd, 0);
32280 }
32281
32282 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32283 +{
32284 + pud_t *pud;
32285 + pmd_t *pmd_table;
32286 +
32287 + pud = pud_offset(pgd, 0);
32288 + pmd_table = pmd_offset(pud, 0);
32289 +
32290 + return pmd_table;
32291 +}
32292 +
32293 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32294 {
32295 int pgd_idx = pgd_index(vaddr);
32296 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32297 int pgd_idx, pmd_idx;
32298 unsigned long vaddr;
32299 pgd_t *pgd;
32300 + pud_t *pud;
32301 pmd_t *pmd;
32302 pte_t *pte = NULL;
32303 unsigned long count = page_table_range_init_count(start, end);
32304 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32305 pgd = pgd_base + pgd_idx;
32306
32307 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32308 - pmd = one_md_table_init(pgd);
32309 - pmd = pmd + pmd_index(vaddr);
32310 + pud = pud_offset(pgd, vaddr);
32311 + pmd = pmd_offset(pud, vaddr);
32312 +
32313 +#ifdef CONFIG_X86_PAE
32314 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32315 +#endif
32316 +
32317 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32318 pmd++, pmd_idx++) {
32319 pte = page_table_kmap_check(one_page_table_init(pmd),
32320 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32321 }
32322 }
32323
32324 -static inline int is_kernel_text(unsigned long addr)
32325 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32326 {
32327 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32328 - return 1;
32329 - return 0;
32330 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32331 + end <= ktla_ktva((unsigned long)_stext)) &&
32332 + (start >= ktla_ktva((unsigned long)_einittext) ||
32333 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32334 +
32335 +#ifdef CONFIG_ACPI_SLEEP
32336 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32337 +#endif
32338 +
32339 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32340 + return 0;
32341 + return 1;
32342 }
32343
32344 /*
32345 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32346 unsigned long last_map_addr = end;
32347 unsigned long start_pfn, end_pfn;
32348 pgd_t *pgd_base = swapper_pg_dir;
32349 - int pgd_idx, pmd_idx, pte_ofs;
32350 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32351 unsigned long pfn;
32352 pgd_t *pgd;
32353 + pud_t *pud;
32354 pmd_t *pmd;
32355 pte_t *pte;
32356 unsigned pages_2m, pages_4k;
32357 @@ -291,8 +295,13 @@ repeat:
32358 pfn = start_pfn;
32359 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32360 pgd = pgd_base + pgd_idx;
32361 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32362 - pmd = one_md_table_init(pgd);
32363 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32364 + pud = pud_offset(pgd, 0);
32365 + pmd = pmd_offset(pud, 0);
32366 +
32367 +#ifdef CONFIG_X86_PAE
32368 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32369 +#endif
32370
32371 if (pfn >= end_pfn)
32372 continue;
32373 @@ -304,14 +313,13 @@ repeat:
32374 #endif
32375 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32376 pmd++, pmd_idx++) {
32377 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32378 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32379
32380 /*
32381 * Map with big pages if possible, otherwise
32382 * create normal page tables:
32383 */
32384 if (use_pse) {
32385 - unsigned int addr2;
32386 pgprot_t prot = PAGE_KERNEL_LARGE;
32387 /*
32388 * first pass will use the same initial
32389 @@ -322,11 +330,7 @@ repeat:
32390 _PAGE_PSE);
32391
32392 pfn &= PMD_MASK >> PAGE_SHIFT;
32393 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32394 - PAGE_OFFSET + PAGE_SIZE-1;
32395 -
32396 - if (is_kernel_text(addr) ||
32397 - is_kernel_text(addr2))
32398 + if (is_kernel_text(address, address + PMD_SIZE))
32399 prot = PAGE_KERNEL_LARGE_EXEC;
32400
32401 pages_2m++;
32402 @@ -343,7 +347,7 @@ repeat:
32403 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32404 pte += pte_ofs;
32405 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32406 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32407 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32408 pgprot_t prot = PAGE_KERNEL;
32409 /*
32410 * first pass will use the same initial
32411 @@ -351,7 +355,7 @@ repeat:
32412 */
32413 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32414
32415 - if (is_kernel_text(addr))
32416 + if (is_kernel_text(address, address + PAGE_SIZE))
32417 prot = PAGE_KERNEL_EXEC;
32418
32419 pages_4k++;
32420 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32421
32422 pud = pud_offset(pgd, va);
32423 pmd = pmd_offset(pud, va);
32424 - if (!pmd_present(*pmd))
32425 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32426 break;
32427
32428 /* should not be large page here */
32429 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32430
32431 static void __init pagetable_init(void)
32432 {
32433 - pgd_t *pgd_base = swapper_pg_dir;
32434 -
32435 - permanent_kmaps_init(pgd_base);
32436 + permanent_kmaps_init(swapper_pg_dir);
32437 }
32438
32439 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32440 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32441 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32442
32443 /* user-defined highmem size */
32444 @@ -787,10 +789,10 @@ void __init mem_init(void)
32445 ((unsigned long)&__init_end -
32446 (unsigned long)&__init_begin) >> 10,
32447
32448 - (unsigned long)&_etext, (unsigned long)&_edata,
32449 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32450 + (unsigned long)&_sdata, (unsigned long)&_edata,
32451 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32452
32453 - (unsigned long)&_text, (unsigned long)&_etext,
32454 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32455 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32456
32457 /*
32458 @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32459 if (!kernel_set_to_readonly)
32460 return;
32461
32462 + start = ktla_ktva(start);
32463 pr_debug("Set kernel text: %lx - %lx for read write\n",
32464 start, start+size);
32465
32466 @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32467 if (!kernel_set_to_readonly)
32468 return;
32469
32470 + start = ktla_ktva(start);
32471 pr_debug("Set kernel text: %lx - %lx for read only\n",
32472 start, start+size);
32473
32474 @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32475 unsigned long start = PFN_ALIGN(_text);
32476 unsigned long size = PFN_ALIGN(_etext) - start;
32477
32478 + start = ktla_ktva(start);
32479 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32480 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32481 size >> 10);
32482 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32483 index f35c66c..84b95ef 100644
32484 --- a/arch/x86/mm/init_64.c
32485 +++ b/arch/x86/mm/init_64.c
32486 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32487 * around without checking the pgd every time.
32488 */
32489
32490 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32491 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32492 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32493
32494 int force_personality32;
32495 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32496
32497 for (address = start; address <= end; address += PGDIR_SIZE) {
32498 const pgd_t *pgd_ref = pgd_offset_k(address);
32499 +
32500 +#ifdef CONFIG_PAX_PER_CPU_PGD
32501 + unsigned long cpu;
32502 +#else
32503 struct page *page;
32504 +#endif
32505
32506 if (pgd_none(*pgd_ref))
32507 continue;
32508
32509 spin_lock(&pgd_lock);
32510 +
32511 +#ifdef CONFIG_PAX_PER_CPU_PGD
32512 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32513 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32514 +
32515 + if (pgd_none(*pgd))
32516 + set_pgd(pgd, *pgd_ref);
32517 + else
32518 + BUG_ON(pgd_page_vaddr(*pgd)
32519 + != pgd_page_vaddr(*pgd_ref));
32520 + pgd = pgd_offset_cpu(cpu, kernel, address);
32521 +#else
32522 list_for_each_entry(page, &pgd_list, lru) {
32523 pgd_t *pgd;
32524 spinlock_t *pgt_lock;
32525 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32526 /* the pgt_lock only for Xen */
32527 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32528 spin_lock(pgt_lock);
32529 +#endif
32530
32531 if (pgd_none(*pgd))
32532 set_pgd(pgd, *pgd_ref);
32533 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32534 BUG_ON(pgd_page_vaddr(*pgd)
32535 != pgd_page_vaddr(*pgd_ref));
32536
32537 +#ifndef CONFIG_PAX_PER_CPU_PGD
32538 spin_unlock(pgt_lock);
32539 +#endif
32540 +
32541 }
32542 spin_unlock(&pgd_lock);
32543 }
32544 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32545 {
32546 if (pgd_none(*pgd)) {
32547 pud_t *pud = (pud_t *)spp_getpage();
32548 - pgd_populate(&init_mm, pgd, pud);
32549 + pgd_populate_kernel(&init_mm, pgd, pud);
32550 if (pud != pud_offset(pgd, 0))
32551 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32552 pud, pud_offset(pgd, 0));
32553 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32554 {
32555 if (pud_none(*pud)) {
32556 pmd_t *pmd = (pmd_t *) spp_getpage();
32557 - pud_populate(&init_mm, pud, pmd);
32558 + pud_populate_kernel(&init_mm, pud, pmd);
32559 if (pmd != pmd_offset(pud, 0))
32560 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32561 pmd, pmd_offset(pud, 0));
32562 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32563 pmd = fill_pmd(pud, vaddr);
32564 pte = fill_pte(pmd, vaddr);
32565
32566 + pax_open_kernel();
32567 set_pte(pte, new_pte);
32568 + pax_close_kernel();
32569
32570 /*
32571 * It's enough to flush this one mapping.
32572 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32573 pgd = pgd_offset_k((unsigned long)__va(phys));
32574 if (pgd_none(*pgd)) {
32575 pud = (pud_t *) spp_getpage();
32576 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32577 - _PAGE_USER));
32578 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32579 }
32580 pud = pud_offset(pgd, (unsigned long)__va(phys));
32581 if (pud_none(*pud)) {
32582 pmd = (pmd_t *) spp_getpage();
32583 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32584 - _PAGE_USER));
32585 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32586 }
32587 pmd = pmd_offset(pud, phys);
32588 BUG_ON(!pmd_none(*pmd));
32589 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32590 prot);
32591
32592 spin_lock(&init_mm.page_table_lock);
32593 - pud_populate(&init_mm, pud, pmd);
32594 + pud_populate_kernel(&init_mm, pud, pmd);
32595 spin_unlock(&init_mm.page_table_lock);
32596 }
32597 __flush_tlb_all();
32598 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32599 page_size_mask);
32600
32601 spin_lock(&init_mm.page_table_lock);
32602 - pgd_populate(&init_mm, pgd, pud);
32603 + pgd_populate_kernel(&init_mm, pgd, pud);
32604 spin_unlock(&init_mm.page_table_lock);
32605 pgd_changed = true;
32606 }
32607 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32608 static struct vm_area_struct gate_vma = {
32609 .vm_start = VSYSCALL_START,
32610 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32611 - .vm_page_prot = PAGE_READONLY_EXEC,
32612 - .vm_flags = VM_READ | VM_EXEC
32613 + .vm_page_prot = PAGE_READONLY,
32614 + .vm_flags = VM_READ
32615 };
32616
32617 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32618 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32619
32620 const char *arch_vma_name(struct vm_area_struct *vma)
32621 {
32622 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32623 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32624 return "[vdso]";
32625 if (vma == &gate_vma)
32626 return "[vsyscall]";
32627 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32628 index 7b179b4..6bd17777 100644
32629 --- a/arch/x86/mm/iomap_32.c
32630 +++ b/arch/x86/mm/iomap_32.c
32631 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32632 type = kmap_atomic_idx_push();
32633 idx = type + KM_TYPE_NR * smp_processor_id();
32634 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32635 +
32636 + pax_open_kernel();
32637 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32638 + pax_close_kernel();
32639 +
32640 arch_flush_lazy_mmu_mode();
32641
32642 return (void *)vaddr;
32643 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32644 index 799580c..72f9fe0 100644
32645 --- a/arch/x86/mm/ioremap.c
32646 +++ b/arch/x86/mm/ioremap.c
32647 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32648 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32649 int is_ram = page_is_ram(pfn);
32650
32651 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32652 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32653 return NULL;
32654 WARN_ON_ONCE(is_ram);
32655 }
32656 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32657 *
32658 * Caller must ensure there is only one unmapping for the same pointer.
32659 */
32660 -void iounmap(volatile void __iomem *addr)
32661 +void iounmap(const volatile void __iomem *addr)
32662 {
32663 struct vm_struct *p, *o;
32664
32665 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32666
32667 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32668 if (page_is_ram(start >> PAGE_SHIFT))
32669 +#ifdef CONFIG_HIGHMEM
32670 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32671 +#endif
32672 return __va(phys);
32673
32674 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32675 @@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32676 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32677 {
32678 if (page_is_ram(phys >> PAGE_SHIFT))
32679 +#ifdef CONFIG_HIGHMEM
32680 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32681 +#endif
32682 return;
32683
32684 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32685 @@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32686 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32687
32688 static __initdata int after_paging_init;
32689 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32690 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32691
32692 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32693 {
32694 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32695 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32696
32697 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32698 - memset(bm_pte, 0, sizeof(bm_pte));
32699 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32700 + pmd_populate_user(&init_mm, pmd, bm_pte);
32701
32702 /*
32703 * The boot-ioremap range spans multiple pmds, for which
32704 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32705 index d87dd6d..bf3fa66 100644
32706 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32707 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32708 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32709 * memory (e.g. tracked pages)? For now, we need this to avoid
32710 * invoking kmemcheck for PnP BIOS calls.
32711 */
32712 - if (regs->flags & X86_VM_MASK)
32713 + if (v8086_mode(regs))
32714 return false;
32715 - if (regs->cs != __KERNEL_CS)
32716 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32717 return false;
32718
32719 pte = kmemcheck_pte_lookup(address);
32720 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32721 index 25e7e13..1964579 100644
32722 --- a/arch/x86/mm/mmap.c
32723 +++ b/arch/x86/mm/mmap.c
32724 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32725 * Leave an at least ~128 MB hole with possible stack randomization.
32726 */
32727 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32728 -#define MAX_GAP (TASK_SIZE/6*5)
32729 +#define MAX_GAP (pax_task_size/6*5)
32730
32731 static int mmap_is_legacy(void)
32732 {
32733 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32734 return rnd << PAGE_SHIFT;
32735 }
32736
32737 -static unsigned long mmap_base(void)
32738 +static unsigned long mmap_base(struct mm_struct *mm)
32739 {
32740 unsigned long gap = rlimit(RLIMIT_STACK);
32741 + unsigned long pax_task_size = TASK_SIZE;
32742 +
32743 +#ifdef CONFIG_PAX_SEGMEXEC
32744 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32745 + pax_task_size = SEGMEXEC_TASK_SIZE;
32746 +#endif
32747
32748 if (gap < MIN_GAP)
32749 gap = MIN_GAP;
32750 else if (gap > MAX_GAP)
32751 gap = MAX_GAP;
32752
32753 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32754 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32755 }
32756
32757 /*
32758 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32759 * does, but not when emulating X86_32
32760 */
32761 -static unsigned long mmap_legacy_base(void)
32762 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
32763 {
32764 - if (mmap_is_ia32())
32765 + if (mmap_is_ia32()) {
32766 +
32767 +#ifdef CONFIG_PAX_SEGMEXEC
32768 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32769 + return SEGMEXEC_TASK_UNMAPPED_BASE;
32770 + else
32771 +#endif
32772 +
32773 return TASK_UNMAPPED_BASE;
32774 - else
32775 + } else
32776 return TASK_UNMAPPED_BASE + mmap_rnd();
32777 }
32778
32779 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32780 */
32781 void arch_pick_mmap_layout(struct mm_struct *mm)
32782 {
32783 - mm->mmap_legacy_base = mmap_legacy_base();
32784 - mm->mmap_base = mmap_base();
32785 + mm->mmap_legacy_base = mmap_legacy_base(mm);
32786 + mm->mmap_base = mmap_base(mm);
32787 +
32788 +#ifdef CONFIG_PAX_RANDMMAP
32789 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
32790 + mm->mmap_legacy_base += mm->delta_mmap;
32791 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32792 + }
32793 +#endif
32794
32795 if (mmap_is_legacy()) {
32796 mm->mmap_base = mm->mmap_legacy_base;
32797 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32798 index 0057a7a..95c7edd 100644
32799 --- a/arch/x86/mm/mmio-mod.c
32800 +++ b/arch/x86/mm/mmio-mod.c
32801 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32802 break;
32803 default:
32804 {
32805 - unsigned char *ip = (unsigned char *)instptr;
32806 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32807 my_trace->opcode = MMIO_UNKNOWN_OP;
32808 my_trace->width = 0;
32809 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32810 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32811 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32812 void __iomem *addr)
32813 {
32814 - static atomic_t next_id;
32815 + static atomic_unchecked_t next_id;
32816 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32817 /* These are page-unaligned. */
32818 struct mmiotrace_map map = {
32819 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32820 .private = trace
32821 },
32822 .phys = offset,
32823 - .id = atomic_inc_return(&next_id)
32824 + .id = atomic_inc_return_unchecked(&next_id)
32825 };
32826 map.map_id = trace->id;
32827
32828 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32829 ioremap_trace_core(offset, size, addr);
32830 }
32831
32832 -static void iounmap_trace_core(volatile void __iomem *addr)
32833 +static void iounmap_trace_core(const volatile void __iomem *addr)
32834 {
32835 struct mmiotrace_map map = {
32836 .phys = 0,
32837 @@ -328,7 +328,7 @@ not_enabled:
32838 }
32839 }
32840
32841 -void mmiotrace_iounmap(volatile void __iomem *addr)
32842 +void mmiotrace_iounmap(const volatile void __iomem *addr)
32843 {
32844 might_sleep();
32845 if (is_enabled()) /* recheck and proper locking in *_core() */
32846 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32847 index 27aa0455..0eb1406 100644
32848 --- a/arch/x86/mm/numa.c
32849 +++ b/arch/x86/mm/numa.c
32850 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32851 return true;
32852 }
32853
32854 -static int __init numa_register_memblks(struct numa_meminfo *mi)
32855 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32856 {
32857 unsigned long uninitialized_var(pfn_align);
32858 int i, nid;
32859 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32860 index 461bc82..4e091a3 100644
32861 --- a/arch/x86/mm/pageattr-test.c
32862 +++ b/arch/x86/mm/pageattr-test.c
32863 @@ -35,7 +35,7 @@ enum {
32864
32865 static int pte_testbit(pte_t pte)
32866 {
32867 - return pte_flags(pte) & _PAGE_UNUSED1;
32868 + return pte_flags(pte) & _PAGE_CPA_TEST;
32869 }
32870
32871 struct split_state {
32872 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32873 index a348868..3c64310 100644
32874 --- a/arch/x86/mm/pageattr.c
32875 +++ b/arch/x86/mm/pageattr.c
32876 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32877 */
32878 #ifdef CONFIG_PCI_BIOS
32879 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32880 - pgprot_val(forbidden) |= _PAGE_NX;
32881 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32882 #endif
32883
32884 /*
32885 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32886 * Does not cover __inittext since that is gone later on. On
32887 * 64bit we do not enforce !NX on the low mapping
32888 */
32889 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
32890 - pgprot_val(forbidden) |= _PAGE_NX;
32891 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32892 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32893
32894 +#ifdef CONFIG_DEBUG_RODATA
32895 /*
32896 * The .rodata section needs to be read-only. Using the pfn
32897 * catches all aliases.
32898 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32899 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32900 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32901 pgprot_val(forbidden) |= _PAGE_RW;
32902 +#endif
32903
32904 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32905 /*
32906 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32907 }
32908 #endif
32909
32910 +#ifdef CONFIG_PAX_KERNEXEC
32911 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32912 + pgprot_val(forbidden) |= _PAGE_RW;
32913 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32914 + }
32915 +#endif
32916 +
32917 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32918
32919 return prot;
32920 @@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32921 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32922 {
32923 /* change init_mm */
32924 + pax_open_kernel();
32925 set_pte_atomic(kpte, pte);
32926 +
32927 #ifdef CONFIG_X86_32
32928 if (!SHARED_KERNEL_PMD) {
32929 +
32930 +#ifdef CONFIG_PAX_PER_CPU_PGD
32931 + unsigned long cpu;
32932 +#else
32933 struct page *page;
32934 +#endif
32935
32936 +#ifdef CONFIG_PAX_PER_CPU_PGD
32937 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32938 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32939 +#else
32940 list_for_each_entry(page, &pgd_list, lru) {
32941 - pgd_t *pgd;
32942 + pgd_t *pgd = (pgd_t *)page_address(page);
32943 +#endif
32944 +
32945 pud_t *pud;
32946 pmd_t *pmd;
32947
32948 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
32949 + pgd += pgd_index(address);
32950 pud = pud_offset(pgd, address);
32951 pmd = pmd_offset(pud, address);
32952 set_pte_atomic((pte_t *)pmd, pte);
32953 }
32954 }
32955 #endif
32956 + pax_close_kernel();
32957 }
32958
32959 static int
32960 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32961 index 6574388..87e9bef 100644
32962 --- a/arch/x86/mm/pat.c
32963 +++ b/arch/x86/mm/pat.c
32964 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
32965
32966 if (!entry) {
32967 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
32968 - current->comm, current->pid, start, end - 1);
32969 + current->comm, task_pid_nr(current), start, end - 1);
32970 return -EINVAL;
32971 }
32972
32973 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32974
32975 while (cursor < to) {
32976 if (!devmem_is_allowed(pfn)) {
32977 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
32978 - current->comm, from, to - 1);
32979 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
32980 + current->comm, from, to - 1, cursor);
32981 return 0;
32982 }
32983 cursor += PAGE_SIZE;
32984 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
32985 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
32986 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
32987 "for [mem %#010Lx-%#010Lx]\n",
32988 - current->comm, current->pid,
32989 + current->comm, task_pid_nr(current),
32990 cattr_name(flags),
32991 base, (unsigned long long)(base + size-1));
32992 return -EINVAL;
32993 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32994 flags = lookup_memtype(paddr);
32995 if (want_flags != flags) {
32996 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
32997 - current->comm, current->pid,
32998 + current->comm, task_pid_nr(current),
32999 cattr_name(want_flags),
33000 (unsigned long long)paddr,
33001 (unsigned long long)(paddr + size - 1),
33002 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33003 free_memtype(paddr, paddr + size);
33004 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33005 " for [mem %#010Lx-%#010Lx], got %s\n",
33006 - current->comm, current->pid,
33007 + current->comm, task_pid_nr(current),
33008 cattr_name(want_flags),
33009 (unsigned long long)paddr,
33010 (unsigned long long)(paddr + size - 1),
33011 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33012 index 415f6c4..d319983 100644
33013 --- a/arch/x86/mm/pat_rbtree.c
33014 +++ b/arch/x86/mm/pat_rbtree.c
33015 @@ -160,7 +160,7 @@ success:
33016
33017 failure:
33018 printk(KERN_INFO "%s:%d conflicting memory types "
33019 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33020 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33021 end, cattr_name(found_type), cattr_name(match->type));
33022 return -EBUSY;
33023 }
33024 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33025 index 9f0614d..92ae64a 100644
33026 --- a/arch/x86/mm/pf_in.c
33027 +++ b/arch/x86/mm/pf_in.c
33028 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33029 int i;
33030 enum reason_type rv = OTHERS;
33031
33032 - p = (unsigned char *)ins_addr;
33033 + p = (unsigned char *)ktla_ktva(ins_addr);
33034 p += skip_prefix(p, &prf);
33035 p += get_opcode(p, &opcode);
33036
33037 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33038 struct prefix_bits prf;
33039 int i;
33040
33041 - p = (unsigned char *)ins_addr;
33042 + p = (unsigned char *)ktla_ktva(ins_addr);
33043 p += skip_prefix(p, &prf);
33044 p += get_opcode(p, &opcode);
33045
33046 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33047 struct prefix_bits prf;
33048 int i;
33049
33050 - p = (unsigned char *)ins_addr;
33051 + p = (unsigned char *)ktla_ktva(ins_addr);
33052 p += skip_prefix(p, &prf);
33053 p += get_opcode(p, &opcode);
33054
33055 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33056 struct prefix_bits prf;
33057 int i;
33058
33059 - p = (unsigned char *)ins_addr;
33060 + p = (unsigned char *)ktla_ktva(ins_addr);
33061 p += skip_prefix(p, &prf);
33062 p += get_opcode(p, &opcode);
33063 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33064 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33065 struct prefix_bits prf;
33066 int i;
33067
33068 - p = (unsigned char *)ins_addr;
33069 + p = (unsigned char *)ktla_ktva(ins_addr);
33070 p += skip_prefix(p, &prf);
33071 p += get_opcode(p, &opcode);
33072 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33073 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33074 index c96314a..433b127 100644
33075 --- a/arch/x86/mm/pgtable.c
33076 +++ b/arch/x86/mm/pgtable.c
33077 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33078 list_del(&page->lru);
33079 }
33080
33081 -#define UNSHARED_PTRS_PER_PGD \
33082 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33083 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33084 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33085
33086 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33087 +{
33088 + unsigned int count = USER_PGD_PTRS;
33089
33090 + if (!pax_user_shadow_base)
33091 + return;
33092 +
33093 + while (count--)
33094 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33095 +}
33096 +#endif
33097 +
33098 +#ifdef CONFIG_PAX_PER_CPU_PGD
33099 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33100 +{
33101 + unsigned int count = USER_PGD_PTRS;
33102 +
33103 + while (count--) {
33104 + pgd_t pgd;
33105 +
33106 +#ifdef CONFIG_X86_64
33107 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33108 +#else
33109 + pgd = *src++;
33110 +#endif
33111 +
33112 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33113 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33114 +#endif
33115 +
33116 + *dst++ = pgd;
33117 + }
33118 +
33119 +}
33120 +#endif
33121 +
33122 +#ifdef CONFIG_X86_64
33123 +#define pxd_t pud_t
33124 +#define pyd_t pgd_t
33125 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33126 +#define pgtable_pxd_page_ctor(page) true
33127 +#define pgtable_pxd_page_dtor(page)
33128 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33129 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33130 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33131 +#define PYD_SIZE PGDIR_SIZE
33132 +#else
33133 +#define pxd_t pmd_t
33134 +#define pyd_t pud_t
33135 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33136 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33137 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33138 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33139 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33140 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33141 +#define PYD_SIZE PUD_SIZE
33142 +#endif
33143 +
33144 +#ifdef CONFIG_PAX_PER_CPU_PGD
33145 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33146 +static inline void pgd_dtor(pgd_t *pgd) {}
33147 +#else
33148 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33149 {
33150 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33151 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33152 pgd_list_del(pgd);
33153 spin_unlock(&pgd_lock);
33154 }
33155 +#endif
33156
33157 /*
33158 * List of all pgd's needed for non-PAE so it can invalidate entries
33159 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33160 * -- nyc
33161 */
33162
33163 -#ifdef CONFIG_X86_PAE
33164 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33165 /*
33166 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33167 * updating the top-level pagetable entries to guarantee the
33168 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33169 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33170 * and initialize the kernel pmds here.
33171 */
33172 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33173 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33174
33175 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33176 {
33177 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33178 */
33179 flush_tlb_mm(mm);
33180 }
33181 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33182 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33183 #else /* !CONFIG_X86_PAE */
33184
33185 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33186 -#define PREALLOCATED_PMDS 0
33187 +#define PREALLOCATED_PXDS 0
33188
33189 #endif /* CONFIG_X86_PAE */
33190
33191 -static void free_pmds(pmd_t *pmds[])
33192 +static void free_pxds(pxd_t *pxds[])
33193 {
33194 int i;
33195
33196 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33197 - if (pmds[i]) {
33198 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33199 - free_page((unsigned long)pmds[i]);
33200 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33201 + if (pxds[i]) {
33202 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33203 + free_page((unsigned long)pxds[i]);
33204 }
33205 }
33206
33207 -static int preallocate_pmds(pmd_t *pmds[])
33208 +static int preallocate_pxds(pxd_t *pxds[])
33209 {
33210 int i;
33211 bool failed = false;
33212
33213 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33214 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33215 - if (!pmd)
33216 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33217 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33218 + if (!pxd)
33219 failed = true;
33220 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33221 - free_page((unsigned long)pmd);
33222 - pmd = NULL;
33223 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33224 + free_page((unsigned long)pxd);
33225 + pxd = NULL;
33226 failed = true;
33227 }
33228 - pmds[i] = pmd;
33229 + pxds[i] = pxd;
33230 }
33231
33232 if (failed) {
33233 - free_pmds(pmds);
33234 + free_pxds(pxds);
33235 return -ENOMEM;
33236 }
33237
33238 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33239 * preallocate which never got a corresponding vma will need to be
33240 * freed manually.
33241 */
33242 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33243 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33244 {
33245 int i;
33246
33247 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33248 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33249 pgd_t pgd = pgdp[i];
33250
33251 if (pgd_val(pgd) != 0) {
33252 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33253 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33254
33255 - pgdp[i] = native_make_pgd(0);
33256 + set_pgd(pgdp + i, native_make_pgd(0));
33257
33258 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33259 - pmd_free(mm, pmd);
33260 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33261 + pxd_free(mm, pxd);
33262 }
33263 }
33264 }
33265
33266 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33267 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33268 {
33269 - pud_t *pud;
33270 + pyd_t *pyd;
33271 int i;
33272
33273 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33274 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33275 return;
33276
33277 - pud = pud_offset(pgd, 0);
33278 -
33279 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33280 - pmd_t *pmd = pmds[i];
33281 +#ifdef CONFIG_X86_64
33282 + pyd = pyd_offset(mm, 0L);
33283 +#else
33284 + pyd = pyd_offset(pgd, 0L);
33285 +#endif
33286
33287 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33288 + pxd_t *pxd = pxds[i];
33289 if (i >= KERNEL_PGD_BOUNDARY)
33290 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33291 - sizeof(pmd_t) * PTRS_PER_PMD);
33292 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33293 + sizeof(pxd_t) * PTRS_PER_PMD);
33294
33295 - pud_populate(mm, pud, pmd);
33296 + pyd_populate(mm, pyd, pxd);
33297 }
33298 }
33299
33300 pgd_t *pgd_alloc(struct mm_struct *mm)
33301 {
33302 pgd_t *pgd;
33303 - pmd_t *pmds[PREALLOCATED_PMDS];
33304 + pxd_t *pxds[PREALLOCATED_PXDS];
33305
33306 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33307
33308 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33309
33310 mm->pgd = pgd;
33311
33312 - if (preallocate_pmds(pmds) != 0)
33313 + if (preallocate_pxds(pxds) != 0)
33314 goto out_free_pgd;
33315
33316 if (paravirt_pgd_alloc(mm) != 0)
33317 - goto out_free_pmds;
33318 + goto out_free_pxds;
33319
33320 /*
33321 * Make sure that pre-populating the pmds is atomic with
33322 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33323 spin_lock(&pgd_lock);
33324
33325 pgd_ctor(mm, pgd);
33326 - pgd_prepopulate_pmd(mm, pgd, pmds);
33327 + pgd_prepopulate_pxd(mm, pgd, pxds);
33328
33329 spin_unlock(&pgd_lock);
33330
33331 return pgd;
33332
33333 -out_free_pmds:
33334 - free_pmds(pmds);
33335 +out_free_pxds:
33336 + free_pxds(pxds);
33337 out_free_pgd:
33338 free_page((unsigned long)pgd);
33339 out:
33340 @@ -313,7 +380,7 @@ out:
33341
33342 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33343 {
33344 - pgd_mop_up_pmds(mm, pgd);
33345 + pgd_mop_up_pxds(mm, pgd);
33346 pgd_dtor(pgd);
33347 paravirt_pgd_free(mm, pgd);
33348 free_page((unsigned long)pgd);
33349 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33350 index a69bcb8..19068ab 100644
33351 --- a/arch/x86/mm/pgtable_32.c
33352 +++ b/arch/x86/mm/pgtable_32.c
33353 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33354 return;
33355 }
33356 pte = pte_offset_kernel(pmd, vaddr);
33357 +
33358 + pax_open_kernel();
33359 if (pte_val(pteval))
33360 set_pte_at(&init_mm, vaddr, pte, pteval);
33361 else
33362 pte_clear(&init_mm, vaddr, pte);
33363 + pax_close_kernel();
33364
33365 /*
33366 * It's enough to flush this one mapping.
33367 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33368 index e666cbb..61788c45 100644
33369 --- a/arch/x86/mm/physaddr.c
33370 +++ b/arch/x86/mm/physaddr.c
33371 @@ -10,7 +10,7 @@
33372 #ifdef CONFIG_X86_64
33373
33374 #ifdef CONFIG_DEBUG_VIRTUAL
33375 -unsigned long __phys_addr(unsigned long x)
33376 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33377 {
33378 unsigned long y = x - __START_KERNEL_map;
33379
33380 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33381 #else
33382
33383 #ifdef CONFIG_DEBUG_VIRTUAL
33384 -unsigned long __phys_addr(unsigned long x)
33385 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33386 {
33387 unsigned long phys_addr = x - PAGE_OFFSET;
33388 /* VMALLOC_* aren't constants */
33389 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33390 index 90555bf..f5f1828 100644
33391 --- a/arch/x86/mm/setup_nx.c
33392 +++ b/arch/x86/mm/setup_nx.c
33393 @@ -5,8 +5,10 @@
33394 #include <asm/pgtable.h>
33395 #include <asm/proto.h>
33396
33397 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33398 static int disable_nx;
33399
33400 +#ifndef CONFIG_PAX_PAGEEXEC
33401 /*
33402 * noexec = on|off
33403 *
33404 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33405 return 0;
33406 }
33407 early_param("noexec", noexec_setup);
33408 +#endif
33409 +
33410 +#endif
33411
33412 void x86_configure_nx(void)
33413 {
33414 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33415 if (cpu_has_nx && !disable_nx)
33416 __supported_pte_mask |= _PAGE_NX;
33417 else
33418 +#endif
33419 __supported_pte_mask &= ~_PAGE_NX;
33420 }
33421
33422 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33423 index dd8dda1..9e9b0f6 100644
33424 --- a/arch/x86/mm/tlb.c
33425 +++ b/arch/x86/mm/tlb.c
33426 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
33427 BUG();
33428 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33429 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33430 +
33431 +#ifndef CONFIG_PAX_PER_CPU_PGD
33432 load_cr3(swapper_pg_dir);
33433 +#endif
33434 +
33435 }
33436 }
33437 EXPORT_SYMBOL_GPL(leave_mm);
33438 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33439 new file mode 100644
33440 index 0000000..dace51c
33441 --- /dev/null
33442 +++ b/arch/x86/mm/uderef_64.c
33443 @@ -0,0 +1,37 @@
33444 +#include <linux/mm.h>
33445 +#include <asm/pgtable.h>
33446 +#include <asm/uaccess.h>
33447 +
33448 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33449 +/* PaX: due to the special call convention these functions must
33450 + * - remain leaf functions under all configurations,
33451 + * - never be called directly, only dereferenced from the wrappers.
33452 + */
33453 +void __pax_open_userland(void)
33454 +{
33455 + unsigned int cpu;
33456 +
33457 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33458 + return;
33459 +
33460 + cpu = raw_get_cpu();
33461 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33462 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33463 + raw_put_cpu_no_resched();
33464 +}
33465 +EXPORT_SYMBOL(__pax_open_userland);
33466 +
33467 +void __pax_close_userland(void)
33468 +{
33469 + unsigned int cpu;
33470 +
33471 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33472 + return;
33473 +
33474 + cpu = raw_get_cpu();
33475 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33476 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33477 + raw_put_cpu_no_resched();
33478 +}
33479 +EXPORT_SYMBOL(__pax_close_userland);
33480 +#endif
33481 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33482 index 0149575..f746de8 100644
33483 --- a/arch/x86/net/bpf_jit.S
33484 +++ b/arch/x86/net/bpf_jit.S
33485 @@ -9,6 +9,7 @@
33486 */
33487 #include <linux/linkage.h>
33488 #include <asm/dwarf2.h>
33489 +#include <asm/alternative-asm.h>
33490
33491 /*
33492 * Calling convention :
33493 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33494 jle bpf_slow_path_word
33495 mov (SKBDATA,%rsi),%eax
33496 bswap %eax /* ntohl() */
33497 + pax_force_retaddr
33498 ret
33499
33500 sk_load_half:
33501 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33502 jle bpf_slow_path_half
33503 movzwl (SKBDATA,%rsi),%eax
33504 rol $8,%ax # ntohs()
33505 + pax_force_retaddr
33506 ret
33507
33508 sk_load_byte:
33509 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33510 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33511 jle bpf_slow_path_byte
33512 movzbl (SKBDATA,%rsi),%eax
33513 + pax_force_retaddr
33514 ret
33515
33516 /**
33517 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33518 movzbl (SKBDATA,%rsi),%ebx
33519 and $15,%bl
33520 shl $2,%bl
33521 + pax_force_retaddr
33522 ret
33523
33524 /* rsi contains offset and can be scratched */
33525 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33526 js bpf_error
33527 mov -12(%rbp),%eax
33528 bswap %eax
33529 + pax_force_retaddr
33530 ret
33531
33532 bpf_slow_path_half:
33533 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33534 mov -12(%rbp),%ax
33535 rol $8,%ax
33536 movzwl %ax,%eax
33537 + pax_force_retaddr
33538 ret
33539
33540 bpf_slow_path_byte:
33541 bpf_slow_path_common(1)
33542 js bpf_error
33543 movzbl -12(%rbp),%eax
33544 + pax_force_retaddr
33545 ret
33546
33547 bpf_slow_path_byte_msh:
33548 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33549 and $15,%al
33550 shl $2,%al
33551 xchg %eax,%ebx
33552 + pax_force_retaddr
33553 ret
33554
33555 #define sk_negative_common(SIZE) \
33556 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33557 sk_negative_common(4)
33558 mov (%rax), %eax
33559 bswap %eax
33560 + pax_force_retaddr
33561 ret
33562
33563 bpf_slow_path_half_neg:
33564 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33565 mov (%rax),%ax
33566 rol $8,%ax
33567 movzwl %ax,%eax
33568 + pax_force_retaddr
33569 ret
33570
33571 bpf_slow_path_byte_neg:
33572 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33573 .globl sk_load_byte_negative_offset
33574 sk_negative_common(1)
33575 movzbl (%rax), %eax
33576 + pax_force_retaddr
33577 ret
33578
33579 bpf_slow_path_byte_msh_neg:
33580 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33581 and $15,%al
33582 shl $2,%al
33583 xchg %eax,%ebx
33584 + pax_force_retaddr
33585 ret
33586
33587 bpf_error:
33588 @@ -197,4 +210,5 @@ bpf_error:
33589 xor %eax,%eax
33590 mov -8(%rbp),%rbx
33591 leaveq
33592 + pax_force_retaddr
33593 ret
33594 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33595 index 4ed75dd..3cf24f0b 100644
33596 --- a/arch/x86/net/bpf_jit_comp.c
33597 +++ b/arch/x86/net/bpf_jit_comp.c
33598 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33599 return ptr + len;
33600 }
33601
33602 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33603 +#define MAX_INSTR_CODE_SIZE 96
33604 +#else
33605 +#define MAX_INSTR_CODE_SIZE 64
33606 +#endif
33607 +
33608 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33609
33610 #define EMIT1(b1) EMIT(b1, 1)
33611 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33612 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33613 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33614 +
33615 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33616 +/* original constant will appear in ecx */
33617 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33618 +do { \
33619 + /* mov ecx, randkey */ \
33620 + EMIT1(0xb9); \
33621 + EMIT(_key, 4); \
33622 + /* xor ecx, randkey ^ off */ \
33623 + EMIT2(0x81, 0xf1); \
33624 + EMIT((_key) ^ (_off), 4); \
33625 +} while (0)
33626 +
33627 +#define EMIT1_off32(b1, _off) \
33628 +do { \
33629 + switch (b1) { \
33630 + case 0x05: /* add eax, imm32 */ \
33631 + case 0x2d: /* sub eax, imm32 */ \
33632 + case 0x25: /* and eax, imm32 */ \
33633 + case 0x0d: /* or eax, imm32 */ \
33634 + case 0xb8: /* mov eax, imm32 */ \
33635 + case 0x35: /* xor eax, imm32 */ \
33636 + case 0x3d: /* cmp eax, imm32 */ \
33637 + case 0xa9: /* test eax, imm32 */ \
33638 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33639 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33640 + break; \
33641 + case 0xbb: /* mov ebx, imm32 */ \
33642 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33643 + /* mov ebx, ecx */ \
33644 + EMIT2(0x89, 0xcb); \
33645 + break; \
33646 + case 0xbe: /* mov esi, imm32 */ \
33647 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33648 + /* mov esi, ecx */ \
33649 + EMIT2(0x89, 0xce); \
33650 + break; \
33651 + case 0xe8: /* call rel imm32, always to known funcs */ \
33652 + EMIT1(b1); \
33653 + EMIT(_off, 4); \
33654 + break; \
33655 + case 0xe9: /* jmp rel imm32 */ \
33656 + EMIT1(b1); \
33657 + EMIT(_off, 4); \
33658 + /* prevent fall-through, we're not called if off = 0 */ \
33659 + EMIT(0xcccccccc, 4); \
33660 + EMIT(0xcccccccc, 4); \
33661 + break; \
33662 + default: \
33663 + BUILD_BUG(); \
33664 + } \
33665 +} while (0)
33666 +
33667 +#define EMIT2_off32(b1, b2, _off) \
33668 +do { \
33669 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33670 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33671 + EMIT(randkey, 4); \
33672 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33673 + EMIT((_off) - randkey, 4); \
33674 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33675 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33676 + /* imul eax, ecx */ \
33677 + EMIT3(0x0f, 0xaf, 0xc1); \
33678 + } else { \
33679 + BUILD_BUG(); \
33680 + } \
33681 +} while (0)
33682 +#else
33683 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33684 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33685 +#endif
33686
33687 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33688 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33689 @@ -91,6 +168,24 @@ do { \
33690 #define X86_JBE 0x76
33691 #define X86_JA 0x77
33692
33693 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33694 +#define APPEND_FLOW_VERIFY() \
33695 +do { \
33696 + /* mov ecx, randkey */ \
33697 + EMIT1(0xb9); \
33698 + EMIT(randkey, 4); \
33699 + /* cmp ecx, randkey */ \
33700 + EMIT2(0x81, 0xf9); \
33701 + EMIT(randkey, 4); \
33702 + /* jz after 8 int 3s */ \
33703 + EMIT2(0x74, 0x08); \
33704 + EMIT(0xcccccccc, 4); \
33705 + EMIT(0xcccccccc, 4); \
33706 +} while (0)
33707 +#else
33708 +#define APPEND_FLOW_VERIFY() do { } while (0)
33709 +#endif
33710 +
33711 #define EMIT_COND_JMP(op, offset) \
33712 do { \
33713 if (is_near(offset)) \
33714 @@ -98,6 +193,7 @@ do { \
33715 else { \
33716 EMIT2(0x0f, op + 0x10); \
33717 EMIT(offset, 4); /* jxx .+off32 */ \
33718 + APPEND_FLOW_VERIFY(); \
33719 } \
33720 } while (0)
33721
33722 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33723 return -1;
33724 }
33725
33726 -struct bpf_binary_header {
33727 - unsigned int pages;
33728 - /* Note : for security reasons, bpf code will follow a randomly
33729 - * sized amount of int3 instructions
33730 - */
33731 - u8 image[];
33732 -};
33733 -
33734 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33735 +/* Note : for security reasons, bpf code will follow a randomly
33736 + * sized amount of int3 instructions
33737 + */
33738 +static u8 *bpf_alloc_binary(unsigned int proglen,
33739 u8 **image_ptr)
33740 {
33741 unsigned int sz, hole;
33742 - struct bpf_binary_header *header;
33743 + u8 *header;
33744
33745 /* Most of BPF filters are really small,
33746 * but if some of them fill a page, allow at least
33747 * 128 extra bytes to insert a random section of int3
33748 */
33749 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33750 - header = module_alloc(sz);
33751 + sz = round_up(proglen + 128, PAGE_SIZE);
33752 + header = module_alloc_exec(sz);
33753 if (!header)
33754 return NULL;
33755
33756 + pax_open_kernel();
33757 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33758 + pax_close_kernel();
33759
33760 - header->pages = sz / PAGE_SIZE;
33761 - hole = sz - (proglen + sizeof(*header));
33762 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33763
33764 /* insert a random number of int3 instructions before BPF code */
33765 - *image_ptr = &header->image[prandom_u32() % hole];
33766 + *image_ptr = &header[prandom_u32() % hole];
33767 return header;
33768 }
33769
33770 void bpf_jit_compile(struct sk_filter *fp)
33771 {
33772 - u8 temp[64];
33773 + u8 temp[MAX_INSTR_CODE_SIZE];
33774 u8 *prog;
33775 unsigned int proglen, oldproglen = 0;
33776 int ilen, i;
33777 int t_offset, f_offset;
33778 u8 t_op, f_op, seen = 0, pass;
33779 u8 *image = NULL;
33780 - struct bpf_binary_header *header = NULL;
33781 + u8 *header = NULL;
33782 u8 *func;
33783 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33784 unsigned int cleanup_addr; /* epilogue code offset */
33785 unsigned int *addrs;
33786 const struct sock_filter *filter = fp->insns;
33787 int flen = fp->len;
33788 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33789 + unsigned int randkey;
33790 +#endif
33791
33792 if (!bpf_jit_enable)
33793 return;
33794 @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33795 return;
33796
33797 /* Before first pass, make a rough estimation of addrs[]
33798 - * each bpf instruction is translated to less than 64 bytes
33799 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33800 */
33801 for (proglen = 0, i = 0; i < flen; i++) {
33802 - proglen += 64;
33803 + proglen += MAX_INSTR_CODE_SIZE;
33804 addrs[i] = proglen;
33805 }
33806 cleanup_addr = proglen; /* epilogue address */
33807 @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33808 for (i = 0; i < flen; i++) {
33809 unsigned int K = filter[i].k;
33810
33811 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33812 + randkey = prandom_u32();
33813 +#endif
33814 +
33815 switch (filter[i].code) {
33816 case BPF_S_ALU_ADD_X: /* A += X; */
33817 seen |= SEEN_XREG;
33818 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33819 case BPF_S_ALU_MUL_K: /* A *= K */
33820 if (is_imm8(K))
33821 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33822 - else {
33823 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33824 - EMIT(K, 4);
33825 - }
33826 + else
33827 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33828 break;
33829 case BPF_S_ALU_DIV_X: /* A /= X; */
33830 seen |= SEEN_XREG;
33831 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33832 break;
33833 }
33834 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33835 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33836 + DILUTE_CONST_SEQUENCE(K, randkey);
33837 +#else
33838 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33839 +#endif
33840 EMIT2(0xf7, 0xf1); /* div %ecx */
33841 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33842 break;
33843 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33844 if (K == 1)
33845 break;
33846 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33847 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33848 + DILUTE_CONST_SEQUENCE(K, randkey);
33849 +#else
33850 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33851 +#endif
33852 EMIT2(0xf7, 0xf1); /* div %ecx */
33853 break;
33854 case BPF_S_ALU_AND_X:
33855 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33856 if (is_imm8(K)) {
33857 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33858 } else {
33859 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33860 - EMIT(K, 4);
33861 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33862 }
33863 } else {
33864 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33865 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33866 if (unlikely(proglen + ilen > oldproglen)) {
33867 pr_err("bpb_jit_compile fatal error\n");
33868 kfree(addrs);
33869 - module_free(NULL, header);
33870 + module_free_exec(NULL, image);
33871 return;
33872 }
33873 + pax_open_kernel();
33874 memcpy(image + proglen, temp, ilen);
33875 + pax_close_kernel();
33876 }
33877 proglen += ilen;
33878 addrs[i] = proglen;
33879 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33880
33881 if (image) {
33882 bpf_flush_icache(header, image + proglen);
33883 - set_memory_ro((unsigned long)header, header->pages);
33884 fp->bpf_func = (void *)image;
33885 }
33886 out:
33887 @@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33888 {
33889 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33890 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33891 - struct bpf_binary_header *header = (void *)addr;
33892
33893 - set_memory_rw(addr, header->pages);
33894 - module_free(NULL, header);
33895 + set_memory_rw(addr, 1);
33896 + module_free_exec(NULL, (void *)addr);
33897 kfree(fp);
33898 }
33899
33900 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33901 index 5d04be5..2beeaa2 100644
33902 --- a/arch/x86/oprofile/backtrace.c
33903 +++ b/arch/x86/oprofile/backtrace.c
33904 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33905 struct stack_frame_ia32 *fp;
33906 unsigned long bytes;
33907
33908 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33909 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33910 if (bytes != 0)
33911 return NULL;
33912
33913 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33914 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33915
33916 oprofile_add_trace(bufhead[0].return_address);
33917
33918 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33919 struct stack_frame bufhead[2];
33920 unsigned long bytes;
33921
33922 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33923 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33924 if (bytes != 0)
33925 return NULL;
33926
33927 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33928 {
33929 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33930
33931 - if (!user_mode_vm(regs)) {
33932 + if (!user_mode(regs)) {
33933 unsigned long stack = kernel_stack_pointer(regs);
33934 if (depth)
33935 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33936 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33937 index 6890d84..1dad1f1 100644
33938 --- a/arch/x86/oprofile/nmi_int.c
33939 +++ b/arch/x86/oprofile/nmi_int.c
33940 @@ -23,6 +23,7 @@
33941 #include <asm/nmi.h>
33942 #include <asm/msr.h>
33943 #include <asm/apic.h>
33944 +#include <asm/pgtable.h>
33945
33946 #include "op_counter.h"
33947 #include "op_x86_model.h"
33948 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33949 if (ret)
33950 return ret;
33951
33952 - if (!model->num_virt_counters)
33953 - model->num_virt_counters = model->num_counters;
33954 + if (!model->num_virt_counters) {
33955 + pax_open_kernel();
33956 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
33957 + pax_close_kernel();
33958 + }
33959
33960 mux_init(ops);
33961
33962 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
33963 index 50d86c0..7985318 100644
33964 --- a/arch/x86/oprofile/op_model_amd.c
33965 +++ b/arch/x86/oprofile/op_model_amd.c
33966 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
33967 num_counters = AMD64_NUM_COUNTERS;
33968 }
33969
33970 - op_amd_spec.num_counters = num_counters;
33971 - op_amd_spec.num_controls = num_counters;
33972 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33973 + pax_open_kernel();
33974 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
33975 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
33976 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33977 + pax_close_kernel();
33978
33979 return 0;
33980 }
33981 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
33982 index d90528e..0127e2b 100644
33983 --- a/arch/x86/oprofile/op_model_ppro.c
33984 +++ b/arch/x86/oprofile/op_model_ppro.c
33985 @@ -19,6 +19,7 @@
33986 #include <asm/msr.h>
33987 #include <asm/apic.h>
33988 #include <asm/nmi.h>
33989 +#include <asm/pgtable.h>
33990
33991 #include "op_x86_model.h"
33992 #include "op_counter.h"
33993 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
33994
33995 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
33996
33997 - op_arch_perfmon_spec.num_counters = num_counters;
33998 - op_arch_perfmon_spec.num_controls = num_counters;
33999 + pax_open_kernel();
34000 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34001 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34002 + pax_close_kernel();
34003 }
34004
34005 static int arch_perfmon_init(struct oprofile_operations *ignore)
34006 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34007 index 71e8a67..6a313bb 100644
34008 --- a/arch/x86/oprofile/op_x86_model.h
34009 +++ b/arch/x86/oprofile/op_x86_model.h
34010 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34011 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34012 struct op_msrs const * const msrs);
34013 #endif
34014 -};
34015 +} __do_const;
34016
34017 struct op_counter_config;
34018
34019 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34020 index 84b9d67..260e5ff 100644
34021 --- a/arch/x86/pci/intel_mid_pci.c
34022 +++ b/arch/x86/pci/intel_mid_pci.c
34023 @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34024 pr_info("Intel MID platform detected, using MID PCI ops\n");
34025 pci_mmcfg_late_init();
34026 pcibios_enable_irq = intel_mid_pci_irq_enable;
34027 - pci_root_ops = intel_mid_pci_ops;
34028 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34029 pci_soc_mode = 1;
34030 /* Continue with standard init */
34031 return 1;
34032 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34033 index 372e9b8..e775a6c 100644
34034 --- a/arch/x86/pci/irq.c
34035 +++ b/arch/x86/pci/irq.c
34036 @@ -50,7 +50,7 @@ struct irq_router {
34037 struct irq_router_handler {
34038 u16 vendor;
34039 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34040 -};
34041 +} __do_const;
34042
34043 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34044 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34045 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34046 return 0;
34047 }
34048
34049 -static __initdata struct irq_router_handler pirq_routers[] = {
34050 +static __initconst const struct irq_router_handler pirq_routers[] = {
34051 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34052 { PCI_VENDOR_ID_AL, ali_router_probe },
34053 { PCI_VENDOR_ID_ITE, ite_router_probe },
34054 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34055 static void __init pirq_find_router(struct irq_router *r)
34056 {
34057 struct irq_routing_table *rt = pirq_table;
34058 - struct irq_router_handler *h;
34059 + const struct irq_router_handler *h;
34060
34061 #ifdef CONFIG_PCI_BIOS
34062 if (!rt->signature) {
34063 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34064 return 0;
34065 }
34066
34067 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34068 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34069 {
34070 .callback = fix_broken_hp_bios_irq9,
34071 .ident = "HP Pavilion N5400 Series Laptop",
34072 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34073 index c77b24a..c979855 100644
34074 --- a/arch/x86/pci/pcbios.c
34075 +++ b/arch/x86/pci/pcbios.c
34076 @@ -79,7 +79,7 @@ union bios32 {
34077 static struct {
34078 unsigned long address;
34079 unsigned short segment;
34080 -} bios32_indirect = { 0, __KERNEL_CS };
34081 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34082
34083 /*
34084 * Returns the entry point for the given service, NULL on error
34085 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34086 unsigned long length; /* %ecx */
34087 unsigned long entry; /* %edx */
34088 unsigned long flags;
34089 + struct desc_struct d, *gdt;
34090
34091 local_irq_save(flags);
34092 - __asm__("lcall *(%%edi); cld"
34093 +
34094 + gdt = get_cpu_gdt_table(smp_processor_id());
34095 +
34096 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34097 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34098 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34099 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34100 +
34101 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34102 : "=a" (return_code),
34103 "=b" (address),
34104 "=c" (length),
34105 "=d" (entry)
34106 : "0" (service),
34107 "1" (0),
34108 - "D" (&bios32_indirect));
34109 + "D" (&bios32_indirect),
34110 + "r"(__PCIBIOS_DS)
34111 + : "memory");
34112 +
34113 + pax_open_kernel();
34114 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34115 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34116 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34117 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34118 + pax_close_kernel();
34119 +
34120 local_irq_restore(flags);
34121
34122 switch (return_code) {
34123 - case 0:
34124 - return address + entry;
34125 - case 0x80: /* Not present */
34126 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34127 - return 0;
34128 - default: /* Shouldn't happen */
34129 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34130 - service, return_code);
34131 + case 0: {
34132 + int cpu;
34133 + unsigned char flags;
34134 +
34135 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34136 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34137 + printk(KERN_WARNING "bios32_service: not valid\n");
34138 return 0;
34139 + }
34140 + address = address + PAGE_OFFSET;
34141 + length += 16UL; /* some BIOSs underreport this... */
34142 + flags = 4;
34143 + if (length >= 64*1024*1024) {
34144 + length >>= PAGE_SHIFT;
34145 + flags |= 8;
34146 + }
34147 +
34148 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34149 + gdt = get_cpu_gdt_table(cpu);
34150 + pack_descriptor(&d, address, length, 0x9b, flags);
34151 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34152 + pack_descriptor(&d, address, length, 0x93, flags);
34153 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34154 + }
34155 + return entry;
34156 + }
34157 + case 0x80: /* Not present */
34158 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34159 + return 0;
34160 + default: /* Shouldn't happen */
34161 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34162 + service, return_code);
34163 + return 0;
34164 }
34165 }
34166
34167 static struct {
34168 unsigned long address;
34169 unsigned short segment;
34170 -} pci_indirect = { 0, __KERNEL_CS };
34171 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34172
34173 -static int pci_bios_present;
34174 +static int pci_bios_present __read_only;
34175
34176 static int check_pcibios(void)
34177 {
34178 @@ -131,11 +174,13 @@ static int check_pcibios(void)
34179 unsigned long flags, pcibios_entry;
34180
34181 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34182 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34183 + pci_indirect.address = pcibios_entry;
34184
34185 local_irq_save(flags);
34186 - __asm__(
34187 - "lcall *(%%edi); cld\n\t"
34188 + __asm__("movw %w6, %%ds\n\t"
34189 + "lcall *%%ss:(%%edi); cld\n\t"
34190 + "push %%ss\n\t"
34191 + "pop %%ds\n\t"
34192 "jc 1f\n\t"
34193 "xor %%ah, %%ah\n"
34194 "1:"
34195 @@ -144,7 +189,8 @@ static int check_pcibios(void)
34196 "=b" (ebx),
34197 "=c" (ecx)
34198 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34199 - "D" (&pci_indirect)
34200 + "D" (&pci_indirect),
34201 + "r" (__PCIBIOS_DS)
34202 : "memory");
34203 local_irq_restore(flags);
34204
34205 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34206
34207 switch (len) {
34208 case 1:
34209 - __asm__("lcall *(%%esi); cld\n\t"
34210 + __asm__("movw %w6, %%ds\n\t"
34211 + "lcall *%%ss:(%%esi); cld\n\t"
34212 + "push %%ss\n\t"
34213 + "pop %%ds\n\t"
34214 "jc 1f\n\t"
34215 "xor %%ah, %%ah\n"
34216 "1:"
34217 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34218 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34219 "b" (bx),
34220 "D" ((long)reg),
34221 - "S" (&pci_indirect));
34222 + "S" (&pci_indirect),
34223 + "r" (__PCIBIOS_DS));
34224 /*
34225 * Zero-extend the result beyond 8 bits, do not trust the
34226 * BIOS having done it:
34227 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34228 *value &= 0xff;
34229 break;
34230 case 2:
34231 - __asm__("lcall *(%%esi); cld\n\t"
34232 + __asm__("movw %w6, %%ds\n\t"
34233 + "lcall *%%ss:(%%esi); cld\n\t"
34234 + "push %%ss\n\t"
34235 + "pop %%ds\n\t"
34236 "jc 1f\n\t"
34237 "xor %%ah, %%ah\n"
34238 "1:"
34239 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34240 : "1" (PCIBIOS_READ_CONFIG_WORD),
34241 "b" (bx),
34242 "D" ((long)reg),
34243 - "S" (&pci_indirect));
34244 + "S" (&pci_indirect),
34245 + "r" (__PCIBIOS_DS));
34246 /*
34247 * Zero-extend the result beyond 16 bits, do not trust the
34248 * BIOS having done it:
34249 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34250 *value &= 0xffff;
34251 break;
34252 case 4:
34253 - __asm__("lcall *(%%esi); cld\n\t"
34254 + __asm__("movw %w6, %%ds\n\t"
34255 + "lcall *%%ss:(%%esi); cld\n\t"
34256 + "push %%ss\n\t"
34257 + "pop %%ds\n\t"
34258 "jc 1f\n\t"
34259 "xor %%ah, %%ah\n"
34260 "1:"
34261 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34262 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34263 "b" (bx),
34264 "D" ((long)reg),
34265 - "S" (&pci_indirect));
34266 + "S" (&pci_indirect),
34267 + "r" (__PCIBIOS_DS));
34268 break;
34269 }
34270
34271 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34272
34273 switch (len) {
34274 case 1:
34275 - __asm__("lcall *(%%esi); cld\n\t"
34276 + __asm__("movw %w6, %%ds\n\t"
34277 + "lcall *%%ss:(%%esi); cld\n\t"
34278 + "push %%ss\n\t"
34279 + "pop %%ds\n\t"
34280 "jc 1f\n\t"
34281 "xor %%ah, %%ah\n"
34282 "1:"
34283 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34284 "c" (value),
34285 "b" (bx),
34286 "D" ((long)reg),
34287 - "S" (&pci_indirect));
34288 + "S" (&pci_indirect),
34289 + "r" (__PCIBIOS_DS));
34290 break;
34291 case 2:
34292 - __asm__("lcall *(%%esi); cld\n\t"
34293 + __asm__("movw %w6, %%ds\n\t"
34294 + "lcall *%%ss:(%%esi); cld\n\t"
34295 + "push %%ss\n\t"
34296 + "pop %%ds\n\t"
34297 "jc 1f\n\t"
34298 "xor %%ah, %%ah\n"
34299 "1:"
34300 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34301 "c" (value),
34302 "b" (bx),
34303 "D" ((long)reg),
34304 - "S" (&pci_indirect));
34305 + "S" (&pci_indirect),
34306 + "r" (__PCIBIOS_DS));
34307 break;
34308 case 4:
34309 - __asm__("lcall *(%%esi); cld\n\t"
34310 + __asm__("movw %w6, %%ds\n\t"
34311 + "lcall *%%ss:(%%esi); cld\n\t"
34312 + "push %%ss\n\t"
34313 + "pop %%ds\n\t"
34314 "jc 1f\n\t"
34315 "xor %%ah, %%ah\n"
34316 "1:"
34317 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34318 "c" (value),
34319 "b" (bx),
34320 "D" ((long)reg),
34321 - "S" (&pci_indirect));
34322 + "S" (&pci_indirect),
34323 + "r" (__PCIBIOS_DS));
34324 break;
34325 }
34326
34327 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34328
34329 DBG("PCI: Fetching IRQ routing table... ");
34330 __asm__("push %%es\n\t"
34331 + "movw %w8, %%ds\n\t"
34332 "push %%ds\n\t"
34333 "pop %%es\n\t"
34334 - "lcall *(%%esi); cld\n\t"
34335 + "lcall *%%ss:(%%esi); cld\n\t"
34336 "pop %%es\n\t"
34337 + "push %%ss\n\t"
34338 + "pop %%ds\n"
34339 "jc 1f\n\t"
34340 "xor %%ah, %%ah\n"
34341 "1:"
34342 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34343 "1" (0),
34344 "D" ((long) &opt),
34345 "S" (&pci_indirect),
34346 - "m" (opt)
34347 + "m" (opt),
34348 + "r" (__PCIBIOS_DS)
34349 : "memory");
34350 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34351 if (ret & 0xff00)
34352 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34353 {
34354 int ret;
34355
34356 - __asm__("lcall *(%%esi); cld\n\t"
34357 + __asm__("movw %w5, %%ds\n\t"
34358 + "lcall *%%ss:(%%esi); cld\n\t"
34359 + "push %%ss\n\t"
34360 + "pop %%ds\n"
34361 "jc 1f\n\t"
34362 "xor %%ah, %%ah\n"
34363 "1:"
34364 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34365 : "0" (PCIBIOS_SET_PCI_HW_INT),
34366 "b" ((dev->bus->number << 8) | dev->devfn),
34367 "c" ((irq << 8) | (pin + 10)),
34368 - "S" (&pci_indirect));
34369 + "S" (&pci_indirect),
34370 + "r" (__PCIBIOS_DS));
34371 return !(ret & 0xff00);
34372 }
34373 EXPORT_SYMBOL(pcibios_set_irq_routing);
34374 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34375 index 9ee3491..872192f 100644
34376 --- a/arch/x86/platform/efi/efi_32.c
34377 +++ b/arch/x86/platform/efi/efi_32.c
34378 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34379 {
34380 struct desc_ptr gdt_descr;
34381
34382 +#ifdef CONFIG_PAX_KERNEXEC
34383 + struct desc_struct d;
34384 +#endif
34385 +
34386 local_irq_save(efi_rt_eflags);
34387
34388 load_cr3(initial_page_table);
34389 __flush_tlb_all();
34390
34391 +#ifdef CONFIG_PAX_KERNEXEC
34392 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34393 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34394 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34395 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34396 +#endif
34397 +
34398 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34399 gdt_descr.size = GDT_SIZE - 1;
34400 load_gdt(&gdt_descr);
34401 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34402 {
34403 struct desc_ptr gdt_descr;
34404
34405 +#ifdef CONFIG_PAX_KERNEXEC
34406 + struct desc_struct d;
34407 +
34408 + memset(&d, 0, sizeof d);
34409 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34410 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34411 +#endif
34412 +
34413 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34414 gdt_descr.size = GDT_SIZE - 1;
34415 load_gdt(&gdt_descr);
34416
34417 +#ifdef CONFIG_PAX_PER_CPU_PGD
34418 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34419 +#else
34420 load_cr3(swapper_pg_dir);
34421 +#endif
34422 +
34423 __flush_tlb_all();
34424
34425 local_irq_restore(efi_rt_eflags);
34426 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34427 index 666b74a..673d88f 100644
34428 --- a/arch/x86/platform/efi/efi_64.c
34429 +++ b/arch/x86/platform/efi/efi_64.c
34430 @@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
34431 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34432 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34433 }
34434 +
34435 +#ifdef CONFIG_PAX_PER_CPU_PGD
34436 + load_cr3(swapper_pg_dir);
34437 +#endif
34438 +
34439 __flush_tlb_all();
34440 }
34441
34442 @@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
34443 for (pgd = 0; pgd < n_pgds; pgd++)
34444 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34445 kfree(save_pgd);
34446 +
34447 +#ifdef CONFIG_PAX_PER_CPU_PGD
34448 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34449 +#endif
34450 +
34451 __flush_tlb_all();
34452 local_irq_restore(efi_flags);
34453 early_code_mapping_set_exec(0);
34454 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34455 index fbe66e6..eae5e38 100644
34456 --- a/arch/x86/platform/efi/efi_stub_32.S
34457 +++ b/arch/x86/platform/efi/efi_stub_32.S
34458 @@ -6,7 +6,9 @@
34459 */
34460
34461 #include <linux/linkage.h>
34462 +#include <linux/init.h>
34463 #include <asm/page_types.h>
34464 +#include <asm/segment.h>
34465
34466 /*
34467 * efi_call_phys(void *, ...) is a function with variable parameters.
34468 @@ -20,7 +22,7 @@
34469 * service functions will comply with gcc calling convention, too.
34470 */
34471
34472 -.text
34473 +__INIT
34474 ENTRY(efi_call_phys)
34475 /*
34476 * 0. The function can only be called in Linux kernel. So CS has been
34477 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34478 * The mapping of lower virtual memory has been created in prelog and
34479 * epilog.
34480 */
34481 - movl $1f, %edx
34482 - subl $__PAGE_OFFSET, %edx
34483 - jmp *%edx
34484 +#ifdef CONFIG_PAX_KERNEXEC
34485 + movl $(__KERNEXEC_EFI_DS), %edx
34486 + mov %edx, %ds
34487 + mov %edx, %es
34488 + mov %edx, %ss
34489 + addl $2f,(1f)
34490 + ljmp *(1f)
34491 +
34492 +__INITDATA
34493 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34494 +.previous
34495 +
34496 +2:
34497 + subl $2b,(1b)
34498 +#else
34499 + jmp 1f-__PAGE_OFFSET
34500 1:
34501 +#endif
34502
34503 /*
34504 * 2. Now on the top of stack is the return
34505 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34506 * parameter 2, ..., param n. To make things easy, we save the return
34507 * address of efi_call_phys in a global variable.
34508 */
34509 - popl %edx
34510 - movl %edx, saved_return_addr
34511 - /* get the function pointer into ECX*/
34512 - popl %ecx
34513 - movl %ecx, efi_rt_function_ptr
34514 - movl $2f, %edx
34515 - subl $__PAGE_OFFSET, %edx
34516 - pushl %edx
34517 + popl (saved_return_addr)
34518 + popl (efi_rt_function_ptr)
34519
34520 /*
34521 * 3. Clear PG bit in %CR0.
34522 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34523 /*
34524 * 5. Call the physical function.
34525 */
34526 - jmp *%ecx
34527 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34528
34529 -2:
34530 /*
34531 * 6. After EFI runtime service returns, control will return to
34532 * following instruction. We'd better readjust stack pointer first.
34533 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34534 movl %cr0, %edx
34535 orl $0x80000000, %edx
34536 movl %edx, %cr0
34537 - jmp 1f
34538 -1:
34539 +
34540 /*
34541 * 8. Now restore the virtual mode from flat mode by
34542 * adding EIP with PAGE_OFFSET.
34543 */
34544 - movl $1f, %edx
34545 - jmp *%edx
34546 +#ifdef CONFIG_PAX_KERNEXEC
34547 + movl $(__KERNEL_DS), %edx
34548 + mov %edx, %ds
34549 + mov %edx, %es
34550 + mov %edx, %ss
34551 + ljmp $(__KERNEL_CS),$1f
34552 +#else
34553 + jmp 1f+__PAGE_OFFSET
34554 +#endif
34555 1:
34556
34557 /*
34558 * 9. Balance the stack. And because EAX contain the return value,
34559 * we'd better not clobber it.
34560 */
34561 - leal efi_rt_function_ptr, %edx
34562 - movl (%edx), %ecx
34563 - pushl %ecx
34564 + pushl (efi_rt_function_ptr)
34565
34566 /*
34567 - * 10. Push the saved return address onto the stack and return.
34568 + * 10. Return to the saved return address.
34569 */
34570 - leal saved_return_addr, %edx
34571 - movl (%edx), %ecx
34572 - pushl %ecx
34573 - ret
34574 + jmpl *(saved_return_addr)
34575 ENDPROC(efi_call_phys)
34576 .previous
34577
34578 -.data
34579 +__INITDATA
34580 saved_return_addr:
34581 .long 0
34582 efi_rt_function_ptr:
34583 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34584 index 88073b1..1cc2f53 100644
34585 --- a/arch/x86/platform/efi/efi_stub_64.S
34586 +++ b/arch/x86/platform/efi/efi_stub_64.S
34587 @@ -7,6 +7,7 @@
34588 */
34589
34590 #include <linux/linkage.h>
34591 +#include <asm/alternative-asm.h>
34592
34593 #define SAVE_XMM \
34594 mov %rsp, %rax; \
34595 @@ -77,6 +78,7 @@ ENTRY(efi_call0)
34596 RESTORE_PGT
34597 addq $32, %rsp
34598 RESTORE_XMM
34599 + pax_force_retaddr 0, 1
34600 ret
34601 ENDPROC(efi_call0)
34602
34603 @@ -89,6 +91,7 @@ ENTRY(efi_call1)
34604 RESTORE_PGT
34605 addq $32, %rsp
34606 RESTORE_XMM
34607 + pax_force_retaddr 0, 1
34608 ret
34609 ENDPROC(efi_call1)
34610
34611 @@ -101,6 +104,7 @@ ENTRY(efi_call2)
34612 RESTORE_PGT
34613 addq $32, %rsp
34614 RESTORE_XMM
34615 + pax_force_retaddr 0, 1
34616 ret
34617 ENDPROC(efi_call2)
34618
34619 @@ -114,6 +118,7 @@ ENTRY(efi_call3)
34620 RESTORE_PGT
34621 addq $32, %rsp
34622 RESTORE_XMM
34623 + pax_force_retaddr 0, 1
34624 ret
34625 ENDPROC(efi_call3)
34626
34627 @@ -128,6 +133,7 @@ ENTRY(efi_call4)
34628 RESTORE_PGT
34629 addq $32, %rsp
34630 RESTORE_XMM
34631 + pax_force_retaddr 0, 1
34632 ret
34633 ENDPROC(efi_call4)
34634
34635 @@ -143,6 +149,7 @@ ENTRY(efi_call5)
34636 RESTORE_PGT
34637 addq $48, %rsp
34638 RESTORE_XMM
34639 + pax_force_retaddr 0, 1
34640 ret
34641 ENDPROC(efi_call5)
34642
34643 @@ -161,6 +168,7 @@ ENTRY(efi_call6)
34644 RESTORE_PGT
34645 addq $48, %rsp
34646 RESTORE_XMM
34647 + pax_force_retaddr 0, 1
34648 ret
34649 ENDPROC(efi_call6)
34650
34651 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34652 index 1bbedc4..eb795b5 100644
34653 --- a/arch/x86/platform/intel-mid/intel-mid.c
34654 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34655 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34656 {
34657 };
34658
34659 -static void intel_mid_reboot(void)
34660 +static void __noreturn intel_mid_reboot(void)
34661 {
34662 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34663 + BUG();
34664 }
34665
34666 static unsigned long __init intel_mid_calibrate_tsc(void)
34667 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34668 index d6ee929..3637cb5 100644
34669 --- a/arch/x86/platform/olpc/olpc_dt.c
34670 +++ b/arch/x86/platform/olpc/olpc_dt.c
34671 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34672 return res;
34673 }
34674
34675 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34676 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34677 .nextprop = olpc_dt_nextprop,
34678 .getproplen = olpc_dt_getproplen,
34679 .getproperty = olpc_dt_getproperty,
34680 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34681 index 424f4c9..f2a2988 100644
34682 --- a/arch/x86/power/cpu.c
34683 +++ b/arch/x86/power/cpu.c
34684 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34685 static void fix_processor_context(void)
34686 {
34687 int cpu = smp_processor_id();
34688 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34689 -#ifdef CONFIG_X86_64
34690 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34691 - tss_desc tss;
34692 -#endif
34693 + struct tss_struct *t = init_tss + cpu;
34694 +
34695 set_tss_desc(cpu, t); /*
34696 * This just modifies memory; should not be
34697 * necessary. But... This is necessary, because
34698 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34699 */
34700
34701 #ifdef CONFIG_X86_64
34702 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34703 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34704 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34705 -
34706 syscall_init(); /* This sets MSR_*STAR and related */
34707 #endif
34708 load_TR_desc(); /* This does ltr */
34709 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34710 index bad628a..a102610 100644
34711 --- a/arch/x86/realmode/init.c
34712 +++ b/arch/x86/realmode/init.c
34713 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34714 __va(real_mode_header->trampoline_header);
34715
34716 #ifdef CONFIG_X86_32
34717 - trampoline_header->start = __pa_symbol(startup_32_smp);
34718 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34719 +
34720 +#ifdef CONFIG_PAX_KERNEXEC
34721 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34722 +#endif
34723 +
34724 + trampoline_header->boot_cs = __BOOT_CS;
34725 trampoline_header->gdt_limit = __BOOT_DS + 7;
34726 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34727 #else
34728 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34729 *trampoline_cr4_features = read_cr4();
34730
34731 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34732 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34733 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34734 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34735 #endif
34736 }
34737 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34738 index 3497f14..cc73b92 100644
34739 --- a/arch/x86/realmode/rm/Makefile
34740 +++ b/arch/x86/realmode/rm/Makefile
34741 @@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34742
34743 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34744 -I$(srctree)/arch/x86/boot
34745 +ifdef CONSTIFY_PLUGIN
34746 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34747 +endif
34748 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34749 GCOV_PROFILE := n
34750 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34751 index a28221d..93c40f1 100644
34752 --- a/arch/x86/realmode/rm/header.S
34753 +++ b/arch/x86/realmode/rm/header.S
34754 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34755 #endif
34756 /* APM/BIOS reboot */
34757 .long pa_machine_real_restart_asm
34758 -#ifdef CONFIG_X86_64
34759 +#ifdef CONFIG_X86_32
34760 + .long __KERNEL_CS
34761 +#else
34762 .long __KERNEL32_CS
34763 #endif
34764 END(real_mode_header)
34765 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34766 index 48ddd76..c26749f 100644
34767 --- a/arch/x86/realmode/rm/trampoline_32.S
34768 +++ b/arch/x86/realmode/rm/trampoline_32.S
34769 @@ -24,6 +24,12 @@
34770 #include <asm/page_types.h>
34771 #include "realmode.h"
34772
34773 +#ifdef CONFIG_PAX_KERNEXEC
34774 +#define ta(X) (X)
34775 +#else
34776 +#define ta(X) (pa_ ## X)
34777 +#endif
34778 +
34779 .text
34780 .code16
34781
34782 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
34783
34784 cli # We should be safe anyway
34785
34786 - movl tr_start, %eax # where we need to go
34787 -
34788 movl $0xA5A5A5A5, trampoline_status
34789 # write marker for master knows we're running
34790
34791 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
34792 movw $1, %dx # protected mode (PE) bit
34793 lmsw %dx # into protected mode
34794
34795 - ljmpl $__BOOT_CS, $pa_startup_32
34796 + ljmpl *(trampoline_header)
34797
34798 .section ".text32","ax"
34799 .code32
34800 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34801 .balign 8
34802 GLOBAL(trampoline_header)
34803 tr_start: .space 4
34804 - tr_gdt_pad: .space 2
34805 + tr_boot_cs: .space 2
34806 tr_gdt: .space 6
34807 END(trampoline_header)
34808
34809 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34810 index dac7b20..72dbaca 100644
34811 --- a/arch/x86/realmode/rm/trampoline_64.S
34812 +++ b/arch/x86/realmode/rm/trampoline_64.S
34813 @@ -93,6 +93,7 @@ ENTRY(startup_32)
34814 movl %edx, %gs
34815
34816 movl pa_tr_cr4, %eax
34817 + andl $~X86_CR4_PCIDE, %eax
34818 movl %eax, %cr4 # Enable PAE mode
34819
34820 # Setup trampoline 4 level pagetables
34821 @@ -106,7 +107,7 @@ ENTRY(startup_32)
34822 wrmsr
34823
34824 # Enable paging and in turn activate Long Mode
34825 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34826 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
34827 movl %eax, %cr0
34828
34829 /*
34830 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34831 index e812034..c747134 100644
34832 --- a/arch/x86/tools/Makefile
34833 +++ b/arch/x86/tools/Makefile
34834 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34835
34836 $(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
34837
34838 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34839 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34840 hostprogs-y += relocs
34841 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34842 relocs: $(obj)/relocs
34843 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34844 index cfbdbdb..1aa763c 100644
34845 --- a/arch/x86/tools/relocs.c
34846 +++ b/arch/x86/tools/relocs.c
34847 @@ -1,5 +1,7 @@
34848 /* This is included from relocs_32/64.c */
34849
34850 +#include "../../../include/generated/autoconf.h"
34851 +
34852 #define ElfW(type) _ElfW(ELF_BITS, type)
34853 #define _ElfW(bits, type) __ElfW(bits, type)
34854 #define __ElfW(bits, type) Elf##bits##_##type
34855 @@ -11,6 +13,7 @@
34856 #define Elf_Sym ElfW(Sym)
34857
34858 static Elf_Ehdr ehdr;
34859 +static Elf_Phdr *phdr;
34860
34861 struct relocs {
34862 uint32_t *offset;
34863 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34864 }
34865 }
34866
34867 +static void read_phdrs(FILE *fp)
34868 +{
34869 + unsigned int i;
34870 +
34871 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34872 + if (!phdr) {
34873 + die("Unable to allocate %d program headers\n",
34874 + ehdr.e_phnum);
34875 + }
34876 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34877 + die("Seek to %d failed: %s\n",
34878 + ehdr.e_phoff, strerror(errno));
34879 + }
34880 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34881 + die("Cannot read ELF program headers: %s\n",
34882 + strerror(errno));
34883 + }
34884 + for(i = 0; i < ehdr.e_phnum; i++) {
34885 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34886 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34887 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34888 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34889 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34890 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34891 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34892 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34893 + }
34894 +
34895 +}
34896 +
34897 static void read_shdrs(FILE *fp)
34898 {
34899 - int i;
34900 + unsigned int i;
34901 Elf_Shdr shdr;
34902
34903 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34904 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34905
34906 static void read_strtabs(FILE *fp)
34907 {
34908 - int i;
34909 + unsigned int i;
34910 for (i = 0; i < ehdr.e_shnum; i++) {
34911 struct section *sec = &secs[i];
34912 if (sec->shdr.sh_type != SHT_STRTAB) {
34913 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34914
34915 static void read_symtabs(FILE *fp)
34916 {
34917 - int i,j;
34918 + unsigned int i,j;
34919 for (i = 0; i < ehdr.e_shnum; i++) {
34920 struct section *sec = &secs[i];
34921 if (sec->shdr.sh_type != SHT_SYMTAB) {
34922 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34923 }
34924
34925
34926 -static void read_relocs(FILE *fp)
34927 +static void read_relocs(FILE *fp, int use_real_mode)
34928 {
34929 - int i,j;
34930 + unsigned int i,j;
34931 + uint32_t base;
34932 +
34933 for (i = 0; i < ehdr.e_shnum; i++) {
34934 struct section *sec = &secs[i];
34935 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34936 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34937 die("Cannot read symbol table: %s\n",
34938 strerror(errno));
34939 }
34940 + base = 0;
34941 +
34942 +#ifdef CONFIG_X86_32
34943 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34944 + if (phdr[j].p_type != PT_LOAD )
34945 + continue;
34946 + 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)
34947 + continue;
34948 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34949 + break;
34950 + }
34951 +#endif
34952 +
34953 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34954 Elf_Rel *rel = &sec->reltab[j];
34955 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34956 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34957 rel->r_info = elf_xword_to_cpu(rel->r_info);
34958 #if (SHT_REL_TYPE == SHT_RELA)
34959 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34960 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34961
34962 static void print_absolute_symbols(void)
34963 {
34964 - int i;
34965 + unsigned int i;
34966 const char *format;
34967
34968 if (ELF_BITS == 64)
34969 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
34970 for (i = 0; i < ehdr.e_shnum; i++) {
34971 struct section *sec = &secs[i];
34972 char *sym_strtab;
34973 - int j;
34974 + unsigned int j;
34975
34976 if (sec->shdr.sh_type != SHT_SYMTAB) {
34977 continue;
34978 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
34979
34980 static void print_absolute_relocs(void)
34981 {
34982 - int i, printed = 0;
34983 + unsigned int i, printed = 0;
34984 const char *format;
34985
34986 if (ELF_BITS == 64)
34987 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
34988 struct section *sec_applies, *sec_symtab;
34989 char *sym_strtab;
34990 Elf_Sym *sh_symtab;
34991 - int j;
34992 + unsigned int j;
34993 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34994 continue;
34995 }
34996 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
34997 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
34998 Elf_Sym *sym, const char *symname))
34999 {
35000 - int i;
35001 + unsigned int i;
35002 /* Walk through the relocations */
35003 for (i = 0; i < ehdr.e_shnum; i++) {
35004 char *sym_strtab;
35005 Elf_Sym *sh_symtab;
35006 struct section *sec_applies, *sec_symtab;
35007 - int j;
35008 + unsigned int j;
35009 struct section *sec = &secs[i];
35010
35011 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35012 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35013 {
35014 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35015 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35016 + char *sym_strtab = sec->link->link->strtab;
35017 +
35018 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35019 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35020 + return 0;
35021 +
35022 +#ifdef CONFIG_PAX_KERNEXEC
35023 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35024 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35025 + return 0;
35026 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35027 + return 0;
35028 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35029 + return 0;
35030 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35031 + return 0;
35032 +#endif
35033
35034 switch (r_type) {
35035 case R_386_NONE:
35036 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35037
35038 static void emit_relocs(int as_text, int use_real_mode)
35039 {
35040 - int i;
35041 + unsigned int i;
35042 int (*write_reloc)(uint32_t, FILE *) = write32;
35043 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35044 const char *symname);
35045 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35046 {
35047 regex_init(use_real_mode);
35048 read_ehdr(fp);
35049 + read_phdrs(fp);
35050 read_shdrs(fp);
35051 read_strtabs(fp);
35052 read_symtabs(fp);
35053 - read_relocs(fp);
35054 + read_relocs(fp, use_real_mode);
35055 if (ELF_BITS == 64)
35056 percpu_init();
35057 if (show_absolute_syms) {
35058 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35059 index 80ffa5b..a33bd15 100644
35060 --- a/arch/x86/um/tls_32.c
35061 +++ b/arch/x86/um/tls_32.c
35062 @@ -260,7 +260,7 @@ out:
35063 if (unlikely(task == current &&
35064 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35065 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35066 - "without flushed TLS.", current->pid);
35067 + "without flushed TLS.", task_pid_nr(current));
35068 }
35069
35070 return 0;
35071 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35072 index fd14be1..e3c79c0 100644
35073 --- a/arch/x86/vdso/Makefile
35074 +++ b/arch/x86/vdso/Makefile
35075 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35076 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35077 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35078
35079 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35080 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35081 GCOV_PROFILE := n
35082
35083 #
35084 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35085 index d6bfb87..876ee18 100644
35086 --- a/arch/x86/vdso/vdso32-setup.c
35087 +++ b/arch/x86/vdso/vdso32-setup.c
35088 @@ -25,6 +25,7 @@
35089 #include <asm/tlbflush.h>
35090 #include <asm/vdso.h>
35091 #include <asm/proto.h>
35092 +#include <asm/mman.h>
35093
35094 enum {
35095 VDSO_DISABLED = 0,
35096 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35097 void enable_sep_cpu(void)
35098 {
35099 int cpu = get_cpu();
35100 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
35101 + struct tss_struct *tss = init_tss + cpu;
35102
35103 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35104 put_cpu();
35105 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35106 gate_vma.vm_start = FIXADDR_USER_START;
35107 gate_vma.vm_end = FIXADDR_USER_END;
35108 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35109 - gate_vma.vm_page_prot = __P101;
35110 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35111
35112 return 0;
35113 }
35114 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35115 if (compat)
35116 addr = VDSO_HIGH_BASE;
35117 else {
35118 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35119 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35120 if (IS_ERR_VALUE(addr)) {
35121 ret = addr;
35122 goto up_fail;
35123 }
35124 }
35125
35126 - current->mm->context.vdso = (void *)addr;
35127 + current->mm->context.vdso = addr;
35128
35129 if (compat_uses_vma || !compat) {
35130 /*
35131 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35132 }
35133
35134 current_thread_info()->sysenter_return =
35135 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35136 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35137
35138 up_fail:
35139 if (ret)
35140 - current->mm->context.vdso = NULL;
35141 + current->mm->context.vdso = 0;
35142
35143 up_write(&mm->mmap_sem);
35144
35145 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35146
35147 const char *arch_vma_name(struct vm_area_struct *vma)
35148 {
35149 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35150 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35151 return "[vdso]";
35152 +
35153 +#ifdef CONFIG_PAX_SEGMEXEC
35154 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35155 + return "[vdso]";
35156 +#endif
35157 +
35158 return NULL;
35159 }
35160
35161 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35162 * Check to see if the corresponding task was created in compat vdso
35163 * mode.
35164 */
35165 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35166 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35167 return &gate_vma;
35168 return NULL;
35169 }
35170 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35171 index 431e875..cbb23f3 100644
35172 --- a/arch/x86/vdso/vma.c
35173 +++ b/arch/x86/vdso/vma.c
35174 @@ -16,8 +16,6 @@
35175 #include <asm/vdso.h>
35176 #include <asm/page.h>
35177
35178 -unsigned int __read_mostly vdso_enabled = 1;
35179 -
35180 extern char vdso_start[], vdso_end[];
35181 extern unsigned short vdso_sync_cpuid;
35182
35183 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35184 * unaligned here as a result of stack start randomization.
35185 */
35186 addr = PAGE_ALIGN(addr);
35187 - addr = align_vdso_addr(addr);
35188
35189 return addr;
35190 }
35191 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35192 unsigned size)
35193 {
35194 struct mm_struct *mm = current->mm;
35195 - unsigned long addr;
35196 + unsigned long addr = 0;
35197 int ret;
35198
35199 - if (!vdso_enabled)
35200 - return 0;
35201 -
35202 down_write(&mm->mmap_sem);
35203 +
35204 +#ifdef CONFIG_PAX_RANDMMAP
35205 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35206 +#endif
35207 +
35208 addr = vdso_addr(mm->start_stack, size);
35209 + addr = align_vdso_addr(addr);
35210 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35211 if (IS_ERR_VALUE(addr)) {
35212 ret = addr;
35213 goto up_fail;
35214 }
35215
35216 - current->mm->context.vdso = (void *)addr;
35217 + mm->context.vdso = addr;
35218
35219 ret = install_special_mapping(mm, addr, size,
35220 VM_READ|VM_EXEC|
35221 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35222 pages);
35223 - if (ret) {
35224 - current->mm->context.vdso = NULL;
35225 - goto up_fail;
35226 - }
35227 + if (ret)
35228 + mm->context.vdso = 0;
35229
35230 up_fail:
35231 up_write(&mm->mmap_sem);
35232 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35233 vdsox32_size);
35234 }
35235 #endif
35236 -
35237 -static __init int vdso_setup(char *s)
35238 -{
35239 - vdso_enabled = simple_strtoul(s, NULL, 0);
35240 - return 0;
35241 -}
35242 -__setup("vdso=", vdso_setup);
35243 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35244 index 01b9026..1e476df 100644
35245 --- a/arch/x86/xen/Kconfig
35246 +++ b/arch/x86/xen/Kconfig
35247 @@ -9,6 +9,7 @@ config XEN
35248 select XEN_HAVE_PVMMU
35249 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35250 depends on X86_TSC
35251 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35252 help
35253 This is the Linux Xen port. Enabling this will allow the
35254 kernel to boot in a paravirtualized environment under the
35255 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35256 index 201d09a..e4723e5 100644
35257 --- a/arch/x86/xen/enlighten.c
35258 +++ b/arch/x86/xen/enlighten.c
35259 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35260
35261 struct shared_info xen_dummy_shared_info;
35262
35263 -void *xen_initial_gdt;
35264 -
35265 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35266 __read_mostly int xen_have_vector_callback;
35267 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35268 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35269 {
35270 unsigned long va = dtr->address;
35271 unsigned int size = dtr->size + 1;
35272 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35273 - unsigned long frames[pages];
35274 + unsigned long frames[65536 / PAGE_SIZE];
35275 int f;
35276
35277 /*
35278 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35279 {
35280 unsigned long va = dtr->address;
35281 unsigned int size = dtr->size + 1;
35282 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35283 - unsigned long frames[pages];
35284 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35285 int f;
35286
35287 /*
35288 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35289 * 8-byte entries, or 16 4k pages..
35290 */
35291
35292 - BUG_ON(size > 65536);
35293 + BUG_ON(size > GDT_SIZE);
35294 BUG_ON(va & ~PAGE_MASK);
35295
35296 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35297 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35298 return 0;
35299 }
35300
35301 -static void set_xen_basic_apic_ops(void)
35302 +static void __init set_xen_basic_apic_ops(void)
35303 {
35304 apic->read = xen_apic_read;
35305 apic->write = xen_apic_write;
35306 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35307 #endif
35308 };
35309
35310 -static void xen_reboot(int reason)
35311 +static __noreturn void xen_reboot(int reason)
35312 {
35313 struct sched_shutdown r = { .reason = reason };
35314
35315 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35316 - BUG();
35317 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35318 + BUG();
35319 }
35320
35321 -static void xen_restart(char *msg)
35322 +static __noreturn void xen_restart(char *msg)
35323 {
35324 xen_reboot(SHUTDOWN_reboot);
35325 }
35326
35327 -static void xen_emergency_restart(void)
35328 +static __noreturn void xen_emergency_restart(void)
35329 {
35330 xen_reboot(SHUTDOWN_reboot);
35331 }
35332
35333 -static void xen_machine_halt(void)
35334 +static __noreturn void xen_machine_halt(void)
35335 {
35336 xen_reboot(SHUTDOWN_poweroff);
35337 }
35338
35339 -static void xen_machine_power_off(void)
35340 +static __noreturn void xen_machine_power_off(void)
35341 {
35342 if (pm_power_off)
35343 pm_power_off();
35344 @@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
35345 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35346
35347 /* Work out if we support NX */
35348 - x86_configure_nx();
35349 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35350 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35351 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35352 + unsigned l, h;
35353 +
35354 + __supported_pte_mask |= _PAGE_NX;
35355 + rdmsr(MSR_EFER, l, h);
35356 + l |= EFER_NX;
35357 + wrmsr(MSR_EFER, l, h);
35358 + }
35359 +#endif
35360
35361 /* Get mfn list */
35362 xen_build_dynamic_phys_to_machine();
35363 @@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
35364
35365 machine_ops = xen_machine_ops;
35366
35367 - /*
35368 - * The only reliable way to retain the initial address of the
35369 - * percpu gdt_page is to remember it here, so we can go and
35370 - * mark it RW later, when the initial percpu area is freed.
35371 - */
35372 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35373 -
35374 xen_smp_init();
35375
35376 #ifdef CONFIG_ACPI_NUMA
35377 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35378 index 2423ef0..4f6fb5b 100644
35379 --- a/arch/x86/xen/mmu.c
35380 +++ b/arch/x86/xen/mmu.c
35381 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35382 return val;
35383 }
35384
35385 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35386 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35387 {
35388 if (val & _PAGE_PRESENT) {
35389 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35390 @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35391 /* L3_k[510] -> level2_kernel_pgt
35392 * L3_i[511] -> level2_fixmap_pgt */
35393 convert_pfn_mfn(level3_kernel_pgt);
35394 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35395 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35396 + convert_pfn_mfn(level3_vmemmap_pgt);
35397 }
35398 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35399 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35400 @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35401 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35402 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35403 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35404 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35405 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35406 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35407 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35408 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35409 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35410 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35411 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35412
35413 @@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
35414 pv_mmu_ops.set_pud = xen_set_pud;
35415 #if PAGETABLE_LEVELS == 4
35416 pv_mmu_ops.set_pgd = xen_set_pgd;
35417 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35418 #endif
35419
35420 /* This will work as long as patching hasn't happened yet
35421 @@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35422 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35423 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35424 .set_pgd = xen_set_pgd_hyper,
35425 + .set_pgd_batched = xen_set_pgd_hyper,
35426
35427 .alloc_pud = xen_alloc_pmd_init,
35428 .release_pud = xen_release_pmd_init,
35429 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35430 index a18eadd..2e2f10e 100644
35431 --- a/arch/x86/xen/smp.c
35432 +++ b/arch/x86/xen/smp.c
35433 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35434
35435 if (xen_pv_domain()) {
35436 if (!xen_feature(XENFEAT_writable_page_tables))
35437 - /* We've switched to the "real" per-cpu gdt, so make
35438 - * sure the old memory can be recycled. */
35439 - make_lowmem_page_readwrite(xen_initial_gdt);
35440 -
35441 #ifdef CONFIG_X86_32
35442 /*
35443 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35444 * expects __USER_DS
35445 */
35446 - loadsegment(ds, __USER_DS);
35447 - loadsegment(es, __USER_DS);
35448 + loadsegment(ds, __KERNEL_DS);
35449 + loadsegment(es, __KERNEL_DS);
35450 #endif
35451
35452 xen_filter_cpu_maps();
35453 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35454 #ifdef CONFIG_X86_32
35455 /* Note: PVH is not yet supported on x86_32. */
35456 ctxt->user_regs.fs = __KERNEL_PERCPU;
35457 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35458 + savesegment(gs, ctxt->user_regs.gs);
35459 #endif
35460 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35461
35462 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35463 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35464 ctxt->flags = VGCF_IN_KERNEL;
35465 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35466 - ctxt->user_regs.ds = __USER_DS;
35467 - ctxt->user_regs.es = __USER_DS;
35468 + ctxt->user_regs.ds = __KERNEL_DS;
35469 + ctxt->user_regs.es = __KERNEL_DS;
35470 ctxt->user_regs.ss = __KERNEL_DS;
35471
35472 xen_copy_trap_info(ctxt->trap_ctxt);
35473 @@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35474 int rc;
35475
35476 per_cpu(current_task, cpu) = idle;
35477 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35478 #ifdef CONFIG_X86_32
35479 irq_ctx_init(cpu);
35480 #else
35481 clear_tsk_thread_flag(idle, TIF_FORK);
35482 - per_cpu(kernel_stack, cpu) =
35483 - (unsigned long)task_stack_page(idle) -
35484 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35485 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35486 #endif
35487 xen_setup_runstate_info(cpu);
35488 xen_setup_timer(cpu);
35489 @@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35490
35491 void __init xen_smp_init(void)
35492 {
35493 - smp_ops = xen_smp_ops;
35494 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35495 xen_fill_possible_map();
35496 }
35497
35498 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35499 index 33ca6e4..0ded929 100644
35500 --- a/arch/x86/xen/xen-asm_32.S
35501 +++ b/arch/x86/xen/xen-asm_32.S
35502 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
35503 ESP_OFFSET=4 # bytes pushed onto stack
35504
35505 /*
35506 - * Store vcpu_info pointer for easy access. Do it this way to
35507 - * avoid having to reload %fs
35508 + * Store vcpu_info pointer for easy access.
35509 */
35510 #ifdef CONFIG_SMP
35511 - GET_THREAD_INFO(%eax)
35512 - movl %ss:TI_cpu(%eax), %eax
35513 - movl %ss:__per_cpu_offset(,%eax,4), %eax
35514 - mov %ss:xen_vcpu(%eax), %eax
35515 + push %fs
35516 + mov $(__KERNEL_PERCPU), %eax
35517 + mov %eax, %fs
35518 + mov PER_CPU_VAR(xen_vcpu), %eax
35519 + pop %fs
35520 #else
35521 movl %ss:xen_vcpu, %eax
35522 #endif
35523 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35524 index 485b695..fda3e7c 100644
35525 --- a/arch/x86/xen/xen-head.S
35526 +++ b/arch/x86/xen/xen-head.S
35527 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35528 #ifdef CONFIG_X86_32
35529 mov %esi,xen_start_info
35530 mov $init_thread_union+THREAD_SIZE,%esp
35531 +#ifdef CONFIG_SMP
35532 + movl $cpu_gdt_table,%edi
35533 + movl $__per_cpu_load,%eax
35534 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35535 + rorl $16,%eax
35536 + movb %al,__KERNEL_PERCPU + 4(%edi)
35537 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35538 + movl $__per_cpu_end - 1,%eax
35539 + subl $__per_cpu_start,%eax
35540 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35541 +#endif
35542 #else
35543 mov %rsi,xen_start_info
35544 mov $init_thread_union+THREAD_SIZE,%rsp
35545 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35546 index 1cb6f4c..9981524 100644
35547 --- a/arch/x86/xen/xen-ops.h
35548 +++ b/arch/x86/xen/xen-ops.h
35549 @@ -10,8 +10,6 @@
35550 extern const char xen_hypervisor_callback[];
35551 extern const char xen_failsafe_callback[];
35552
35553 -extern void *xen_initial_gdt;
35554 -
35555 struct trap_info;
35556 void xen_copy_trap_info(struct trap_info *traps);
35557
35558 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35559 index 525bd3d..ef888b1 100644
35560 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35561 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35562 @@ -119,9 +119,9 @@
35563 ----------------------------------------------------------------------*/
35564
35565 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35566 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35567 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35568 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35569 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35570
35571 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35572 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35573 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35574 index 2f33760..835e50a 100644
35575 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35576 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35577 @@ -11,6 +11,7 @@
35578 #ifndef _XTENSA_CORE_H
35579 #define _XTENSA_CORE_H
35580
35581 +#include <linux/const.h>
35582
35583 /****************************************************************************
35584 Parameters Useful for Any Code, USER or PRIVILEGED
35585 @@ -112,9 +113,9 @@
35586 ----------------------------------------------------------------------*/
35587
35588 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35589 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35590 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35591 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35592 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35593
35594 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35595 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35596 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35597 index af00795..2bb8105 100644
35598 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35599 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35600 @@ -11,6 +11,7 @@
35601 #ifndef _XTENSA_CORE_CONFIGURATION_H
35602 #define _XTENSA_CORE_CONFIGURATION_H
35603
35604 +#include <linux/const.h>
35605
35606 /****************************************************************************
35607 Parameters Useful for Any Code, USER or PRIVILEGED
35608 @@ -118,9 +119,9 @@
35609 ----------------------------------------------------------------------*/
35610
35611 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35612 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35613 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35614 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35615 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35616
35617 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35618 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35619 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35620 index 4e491d9..c8e18e4 100644
35621 --- a/block/blk-cgroup.c
35622 +++ b/block/blk-cgroup.c
35623 @@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35624 static struct cgroup_subsys_state *
35625 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35626 {
35627 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35628 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35629 struct blkcg *blkcg;
35630
35631 if (!parent_css) {
35632 @@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35633
35634 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35635 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35636 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35637 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35638 done:
35639 spin_lock_init(&blkcg->lock);
35640 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35641 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35642 index 1855bf5..af12b06 100644
35643 --- a/block/blk-iopoll.c
35644 +++ b/block/blk-iopoll.c
35645 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35646 }
35647 EXPORT_SYMBOL(blk_iopoll_complete);
35648
35649 -static void blk_iopoll_softirq(struct softirq_action *h)
35650 +static __latent_entropy void blk_iopoll_softirq(void)
35651 {
35652 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35653 int rearm = 0, budget = blk_iopoll_budget;
35654 diff --git a/block/blk-map.c b/block/blk-map.c
35655 index ae4ae10..c470b8d 100644
35656 --- a/block/blk-map.c
35657 +++ b/block/blk-map.c
35658 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35659 if (!len || !kbuf)
35660 return -EINVAL;
35661
35662 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35663 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35664 if (do_copy)
35665 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35666 else
35667 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35668 index 57790c1..5e988dd 100644
35669 --- a/block/blk-softirq.c
35670 +++ b/block/blk-softirq.c
35671 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35672 * Softirq action handler - move entries to local list and loop over them
35673 * while passing them to the queue registered handler.
35674 */
35675 -static void blk_done_softirq(struct softirq_action *h)
35676 +static __latent_entropy void blk_done_softirq(void)
35677 {
35678 struct list_head *cpu_list, local_list;
35679
35680 diff --git a/block/bsg.c b/block/bsg.c
35681 index 420a5a9..23834aa 100644
35682 --- a/block/bsg.c
35683 +++ b/block/bsg.c
35684 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35685 struct sg_io_v4 *hdr, struct bsg_device *bd,
35686 fmode_t has_write_perm)
35687 {
35688 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35689 + unsigned char *cmdptr;
35690 +
35691 if (hdr->request_len > BLK_MAX_CDB) {
35692 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35693 if (!rq->cmd)
35694 return -ENOMEM;
35695 - }
35696 + cmdptr = rq->cmd;
35697 + } else
35698 + cmdptr = tmpcmd;
35699
35700 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35701 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35702 hdr->request_len))
35703 return -EFAULT;
35704
35705 + if (cmdptr != rq->cmd)
35706 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35707 +
35708 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35709 if (blk_verify_command(rq->cmd, has_write_perm))
35710 return -EPERM;
35711 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35712 index fbd5a67..f24fd95 100644
35713 --- a/block/compat_ioctl.c
35714 +++ b/block/compat_ioctl.c
35715 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35716 cgc = compat_alloc_user_space(sizeof(*cgc));
35717 cgc32 = compat_ptr(arg);
35718
35719 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35720 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35721 get_user(data, &cgc32->buffer) ||
35722 put_user(compat_ptr(data), &cgc->buffer) ||
35723 copy_in_user(&cgc->buflen, &cgc32->buflen,
35724 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35725 err |= __get_user(f->spec1, &uf->spec1);
35726 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35727 err |= __get_user(name, &uf->name);
35728 - f->name = compat_ptr(name);
35729 + f->name = (void __force_kernel *)compat_ptr(name);
35730 if (err) {
35731 err = -EFAULT;
35732 goto out;
35733 diff --git a/block/genhd.c b/block/genhd.c
35734 index 791f419..89f21c4 100644
35735 --- a/block/genhd.c
35736 +++ b/block/genhd.c
35737 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35738
35739 /*
35740 * Register device numbers dev..(dev+range-1)
35741 - * range must be nonzero
35742 + * Noop if @range is zero.
35743 * The hash chain is sorted on range, so that subranges can override.
35744 */
35745 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35746 struct kobject *(*probe)(dev_t, int *, void *),
35747 int (*lock)(dev_t, void *), void *data)
35748 {
35749 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35750 + if (range)
35751 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35752 }
35753
35754 EXPORT_SYMBOL(blk_register_region);
35755
35756 +/* undo blk_register_region(), noop if @range is zero */
35757 void blk_unregister_region(dev_t devt, unsigned long range)
35758 {
35759 - kobj_unmap(bdev_map, devt, range);
35760 + if (range)
35761 + kobj_unmap(bdev_map, devt, range);
35762 }
35763
35764 EXPORT_SYMBOL(blk_unregister_region);
35765 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35766 index dc51f46..d5446a8 100644
35767 --- a/block/partitions/efi.c
35768 +++ b/block/partitions/efi.c
35769 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35770 if (!gpt)
35771 return NULL;
35772
35773 + if (!le32_to_cpu(gpt->num_partition_entries))
35774 + return NULL;
35775 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35776 + if (!pte)
35777 + return NULL;
35778 +
35779 count = le32_to_cpu(gpt->num_partition_entries) *
35780 le32_to_cpu(gpt->sizeof_partition_entry);
35781 - if (!count)
35782 - return NULL;
35783 - pte = kmalloc(count, GFP_KERNEL);
35784 - if (!pte)
35785 - return NULL;
35786 -
35787 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35788 (u8 *) pte, count) < count) {
35789 kfree(pte);
35790 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35791 index 2648797..92ed21f 100644
35792 --- a/block/scsi_ioctl.c
35793 +++ b/block/scsi_ioctl.c
35794 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35795 return put_user(0, p);
35796 }
35797
35798 -static int sg_get_timeout(struct request_queue *q)
35799 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35800 {
35801 return jiffies_to_clock_t(q->sg_timeout);
35802 }
35803 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35804 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35805 struct sg_io_hdr *hdr, fmode_t mode)
35806 {
35807 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35808 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35809 + unsigned char *cmdptr;
35810 +
35811 + if (rq->cmd != rq->__cmd)
35812 + cmdptr = rq->cmd;
35813 + else
35814 + cmdptr = tmpcmd;
35815 +
35816 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35817 return -EFAULT;
35818 +
35819 + if (cmdptr != rq->cmd)
35820 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35821 +
35822 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35823 return -EPERM;
35824
35825 @@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35826 int err;
35827 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35828 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35829 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35830 + unsigned char *cmdptr;
35831
35832 if (!sic)
35833 return -EINVAL;
35834 @@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35835 */
35836 err = -EFAULT;
35837 rq->cmd_len = cmdlen;
35838 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
35839 +
35840 + if (rq->cmd != rq->__cmd)
35841 + cmdptr = rq->cmd;
35842 + else
35843 + cmdptr = tmpcmd;
35844 +
35845 + if (copy_from_user(cmdptr, sic->data, cmdlen))
35846 goto error;
35847
35848 + if (rq->cmd != cmdptr)
35849 + memcpy(rq->cmd, cmdptr, cmdlen);
35850 +
35851 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35852 goto error;
35853
35854 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35855 index 7bdd61b..afec999 100644
35856 --- a/crypto/cryptd.c
35857 +++ b/crypto/cryptd.c
35858 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35859
35860 struct cryptd_blkcipher_request_ctx {
35861 crypto_completion_t complete;
35862 -};
35863 +} __no_const;
35864
35865 struct cryptd_hash_ctx {
35866 struct crypto_shash *child;
35867 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35868
35869 struct cryptd_aead_request_ctx {
35870 crypto_completion_t complete;
35871 -};
35872 +} __no_const;
35873
35874 static void cryptd_queue_worker(struct work_struct *work);
35875
35876 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35877 index 309d345..1632720 100644
35878 --- a/crypto/pcrypt.c
35879 +++ b/crypto/pcrypt.c
35880 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35881 int ret;
35882
35883 pinst->kobj.kset = pcrypt_kset;
35884 - ret = kobject_add(&pinst->kobj, NULL, name);
35885 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35886 if (!ret)
35887 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35888
35889 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35890 index 15dddc1..b61cf0c 100644
35891 --- a/drivers/acpi/acpica/hwxfsleep.c
35892 +++ b/drivers/acpi/acpica/hwxfsleep.c
35893 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35894 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35895
35896 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35897 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35898 - acpi_hw_extended_sleep},
35899 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35900 - acpi_hw_extended_wake_prep},
35901 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35902 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35903 + .extended_function = acpi_hw_extended_sleep},
35904 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35905 + .extended_function = acpi_hw_extended_wake_prep},
35906 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35907 + .extended_function = acpi_hw_extended_wake}
35908 };
35909
35910 /*
35911 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35912 index e5bcd91..74f050d 100644
35913 --- a/drivers/acpi/apei/apei-internal.h
35914 +++ b/drivers/acpi/apei/apei-internal.h
35915 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35916 struct apei_exec_ins_type {
35917 u32 flags;
35918 apei_exec_ins_func_t run;
35919 -};
35920 +} __do_const;
35921
35922 struct apei_exec_context {
35923 u32 ip;
35924 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35925 index dab7cb7..f0d2994 100644
35926 --- a/drivers/acpi/apei/ghes.c
35927 +++ b/drivers/acpi/apei/ghes.c
35928 @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
35929 const struct acpi_hest_generic *generic,
35930 const struct acpi_generic_status *estatus)
35931 {
35932 - static atomic_t seqno;
35933 + static atomic_unchecked_t seqno;
35934 unsigned int curr_seqno;
35935 char pfx_seq[64];
35936
35937 @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
35938 else
35939 pfx = KERN_ERR;
35940 }
35941 - curr_seqno = atomic_inc_return(&seqno);
35942 + curr_seqno = atomic_inc_return_unchecked(&seqno);
35943 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35944 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35945 pfx_seq, generic->header.source_id);
35946 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35947 index a83e3c6..c3d617f 100644
35948 --- a/drivers/acpi/bgrt.c
35949 +++ b/drivers/acpi/bgrt.c
35950 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35951 if (!bgrt_image)
35952 return -ENODEV;
35953
35954 - bin_attr_image.private = bgrt_image;
35955 - bin_attr_image.size = bgrt_image_size;
35956 + pax_open_kernel();
35957 + *(void **)&bin_attr_image.private = bgrt_image;
35958 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
35959 + pax_close_kernel();
35960
35961 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
35962 if (!bgrt_kobj)
35963 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
35964 index afec452..c5d8b96 100644
35965 --- a/drivers/acpi/blacklist.c
35966 +++ b/drivers/acpi/blacklist.c
35967 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
35968 u32 is_critical_error;
35969 };
35970
35971 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
35972 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
35973
35974 /*
35975 * POLICY: If *anything* doesn't work, put it on the blacklist.
35976 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
35977 return 0;
35978 }
35979
35980 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
35981 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
35982 {
35983 .callback = dmi_disable_osi_vista,
35984 .ident = "Fujitsu Siemens",
35985 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
35986 index c68e724..e863008 100644
35987 --- a/drivers/acpi/custom_method.c
35988 +++ b/drivers/acpi/custom_method.c
35989 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
35990 struct acpi_table_header table;
35991 acpi_status status;
35992
35993 +#ifdef CONFIG_GRKERNSEC_KMEM
35994 + return -EPERM;
35995 +#endif
35996 +
35997 if (!(*ppos)) {
35998 /* parse the table header to get the table length */
35999 if (count <= sizeof(struct acpi_table_header))
36000 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36001 index 3dca36d..abaf070 100644
36002 --- a/drivers/acpi/processor_idle.c
36003 +++ b/drivers/acpi/processor_idle.c
36004 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36005 {
36006 int i, count = CPUIDLE_DRIVER_STATE_START;
36007 struct acpi_processor_cx *cx;
36008 - struct cpuidle_state *state;
36009 + cpuidle_state_no_const *state;
36010 struct cpuidle_driver *drv = &acpi_idle_driver;
36011
36012 if (!pr->flags.power_setup_done)
36013 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36014 index 91a32ce..d77fcaf 100644
36015 --- a/drivers/acpi/sysfs.c
36016 +++ b/drivers/acpi/sysfs.c
36017 @@ -425,11 +425,11 @@ static u32 num_counters;
36018 static struct attribute **all_attrs;
36019 static u32 acpi_gpe_count;
36020
36021 -static struct attribute_group interrupt_stats_attr_group = {
36022 +static attribute_group_no_const interrupt_stats_attr_group = {
36023 .name = "interrupts",
36024 };
36025
36026 -static struct kobj_attribute *counter_attrs;
36027 +static kobj_attribute_no_const *counter_attrs;
36028
36029 static void delete_gpe_attr_array(void)
36030 {
36031 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36032 index 36605ab..6ef6d4b 100644
36033 --- a/drivers/ata/libahci.c
36034 +++ b/drivers/ata/libahci.c
36035 @@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36036 }
36037 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36038
36039 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36040 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36041 struct ata_taskfile *tf, int is_cmd, u16 flags,
36042 unsigned long timeout_msec)
36043 {
36044 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36045 index 8cb2522..a815e54 100644
36046 --- a/drivers/ata/libata-core.c
36047 +++ b/drivers/ata/libata-core.c
36048 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36049 static void ata_dev_xfermask(struct ata_device *dev);
36050 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36051
36052 -atomic_t ata_print_id = ATOMIC_INIT(0);
36053 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36054
36055 struct ata_force_param {
36056 const char *name;
36057 @@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36058 struct ata_port *ap;
36059 unsigned int tag;
36060
36061 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36062 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36063 ap = qc->ap;
36064
36065 qc->flags = 0;
36066 @@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36067 struct ata_port *ap;
36068 struct ata_link *link;
36069
36070 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36071 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36072 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36073 ap = qc->ap;
36074 link = qc->dev->link;
36075 @@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36076 return;
36077
36078 spin_lock(&lock);
36079 + pax_open_kernel();
36080
36081 for (cur = ops->inherits; cur; cur = cur->inherits) {
36082 void **inherit = (void **)cur;
36083 @@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36084 if (IS_ERR(*pp))
36085 *pp = NULL;
36086
36087 - ops->inherits = NULL;
36088 + *(struct ata_port_operations **)&ops->inherits = NULL;
36089
36090 + pax_close_kernel();
36091 spin_unlock(&lock);
36092 }
36093
36094 @@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36095
36096 /* give ports names and add SCSI hosts */
36097 for (i = 0; i < host->n_ports; i++) {
36098 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36099 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36100 host->ports[i]->local_port_no = i + 1;
36101 }
36102
36103 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36104 index ef8567d..8bdbd03 100644
36105 --- a/drivers/ata/libata-scsi.c
36106 +++ b/drivers/ata/libata-scsi.c
36107 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36108
36109 if (rc)
36110 return rc;
36111 - ap->print_id = atomic_inc_return(&ata_print_id);
36112 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36113 return 0;
36114 }
36115 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36116 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36117 index 45b5ab3..98446b8 100644
36118 --- a/drivers/ata/libata.h
36119 +++ b/drivers/ata/libata.h
36120 @@ -53,7 +53,7 @@ enum {
36121 ATA_DNXFER_QUIET = (1 << 31),
36122 };
36123
36124 -extern atomic_t ata_print_id;
36125 +extern atomic_unchecked_t ata_print_id;
36126 extern int atapi_passthru16;
36127 extern int libata_fua;
36128 extern int libata_noacpi;
36129 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36130 index 73492dd..ca2bff5 100644
36131 --- a/drivers/ata/pata_arasan_cf.c
36132 +++ b/drivers/ata/pata_arasan_cf.c
36133 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36134 /* Handle platform specific quirks */
36135 if (quirk) {
36136 if (quirk & CF_BROKEN_PIO) {
36137 - ap->ops->set_piomode = NULL;
36138 + pax_open_kernel();
36139 + *(void **)&ap->ops->set_piomode = NULL;
36140 + pax_close_kernel();
36141 ap->pio_mask = 0;
36142 }
36143 if (quirk & CF_BROKEN_MWDMA)
36144 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36145 index f9b983a..887b9d8 100644
36146 --- a/drivers/atm/adummy.c
36147 +++ b/drivers/atm/adummy.c
36148 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36149 vcc->pop(vcc, skb);
36150 else
36151 dev_kfree_skb_any(skb);
36152 - atomic_inc(&vcc->stats->tx);
36153 + atomic_inc_unchecked(&vcc->stats->tx);
36154
36155 return 0;
36156 }
36157 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36158 index 62a7607..cc4be104 100644
36159 --- a/drivers/atm/ambassador.c
36160 +++ b/drivers/atm/ambassador.c
36161 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36162 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36163
36164 // VC layer stats
36165 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36166 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36167
36168 // free the descriptor
36169 kfree (tx_descr);
36170 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36171 dump_skb ("<<<", vc, skb);
36172
36173 // VC layer stats
36174 - atomic_inc(&atm_vcc->stats->rx);
36175 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36176 __net_timestamp(skb);
36177 // end of our responsibility
36178 atm_vcc->push (atm_vcc, skb);
36179 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36180 } else {
36181 PRINTK (KERN_INFO, "dropped over-size frame");
36182 // should we count this?
36183 - atomic_inc(&atm_vcc->stats->rx_drop);
36184 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36185 }
36186
36187 } else {
36188 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36189 }
36190
36191 if (check_area (skb->data, skb->len)) {
36192 - atomic_inc(&atm_vcc->stats->tx_err);
36193 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36194 return -ENOMEM; // ?
36195 }
36196
36197 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36198 index 0e3f8f9..765a7a5 100644
36199 --- a/drivers/atm/atmtcp.c
36200 +++ b/drivers/atm/atmtcp.c
36201 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36202 if (vcc->pop) vcc->pop(vcc,skb);
36203 else dev_kfree_skb(skb);
36204 if (dev_data) return 0;
36205 - atomic_inc(&vcc->stats->tx_err);
36206 + atomic_inc_unchecked(&vcc->stats->tx_err);
36207 return -ENOLINK;
36208 }
36209 size = skb->len+sizeof(struct atmtcp_hdr);
36210 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36211 if (!new_skb) {
36212 if (vcc->pop) vcc->pop(vcc,skb);
36213 else dev_kfree_skb(skb);
36214 - atomic_inc(&vcc->stats->tx_err);
36215 + atomic_inc_unchecked(&vcc->stats->tx_err);
36216 return -ENOBUFS;
36217 }
36218 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36219 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36220 if (vcc->pop) vcc->pop(vcc,skb);
36221 else dev_kfree_skb(skb);
36222 out_vcc->push(out_vcc,new_skb);
36223 - atomic_inc(&vcc->stats->tx);
36224 - atomic_inc(&out_vcc->stats->rx);
36225 + atomic_inc_unchecked(&vcc->stats->tx);
36226 + atomic_inc_unchecked(&out_vcc->stats->rx);
36227 return 0;
36228 }
36229
36230 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36231 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36232 read_unlock(&vcc_sklist_lock);
36233 if (!out_vcc) {
36234 - atomic_inc(&vcc->stats->tx_err);
36235 + atomic_inc_unchecked(&vcc->stats->tx_err);
36236 goto done;
36237 }
36238 skb_pull(skb,sizeof(struct atmtcp_hdr));
36239 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36240 __net_timestamp(new_skb);
36241 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36242 out_vcc->push(out_vcc,new_skb);
36243 - atomic_inc(&vcc->stats->tx);
36244 - atomic_inc(&out_vcc->stats->rx);
36245 + atomic_inc_unchecked(&vcc->stats->tx);
36246 + atomic_inc_unchecked(&out_vcc->stats->rx);
36247 done:
36248 if (vcc->pop) vcc->pop(vcc,skb);
36249 else dev_kfree_skb(skb);
36250 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36251 index b1955ba..b179940 100644
36252 --- a/drivers/atm/eni.c
36253 +++ b/drivers/atm/eni.c
36254 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36255 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36256 vcc->dev->number);
36257 length = 0;
36258 - atomic_inc(&vcc->stats->rx_err);
36259 + atomic_inc_unchecked(&vcc->stats->rx_err);
36260 }
36261 else {
36262 length = ATM_CELL_SIZE-1; /* no HEC */
36263 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36264 size);
36265 }
36266 eff = length = 0;
36267 - atomic_inc(&vcc->stats->rx_err);
36268 + atomic_inc_unchecked(&vcc->stats->rx_err);
36269 }
36270 else {
36271 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36272 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36273 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36274 vcc->dev->number,vcc->vci,length,size << 2,descr);
36275 length = eff = 0;
36276 - atomic_inc(&vcc->stats->rx_err);
36277 + atomic_inc_unchecked(&vcc->stats->rx_err);
36278 }
36279 }
36280 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36281 @@ -767,7 +767,7 @@ rx_dequeued++;
36282 vcc->push(vcc,skb);
36283 pushed++;
36284 }
36285 - atomic_inc(&vcc->stats->rx);
36286 + atomic_inc_unchecked(&vcc->stats->rx);
36287 }
36288 wake_up(&eni_dev->rx_wait);
36289 }
36290 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36291 PCI_DMA_TODEVICE);
36292 if (vcc->pop) vcc->pop(vcc,skb);
36293 else dev_kfree_skb_irq(skb);
36294 - atomic_inc(&vcc->stats->tx);
36295 + atomic_inc_unchecked(&vcc->stats->tx);
36296 wake_up(&eni_dev->tx_wait);
36297 dma_complete++;
36298 }
36299 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36300 index b41c948..a002b17 100644
36301 --- a/drivers/atm/firestream.c
36302 +++ b/drivers/atm/firestream.c
36303 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36304 }
36305 }
36306
36307 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36308 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36309
36310 fs_dprintk (FS_DEBUG_TXMEM, "i");
36311 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36312 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36313 #endif
36314 skb_put (skb, qe->p1 & 0xffff);
36315 ATM_SKB(skb)->vcc = atm_vcc;
36316 - atomic_inc(&atm_vcc->stats->rx);
36317 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36318 __net_timestamp(skb);
36319 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36320 atm_vcc->push (atm_vcc, skb);
36321 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36322 kfree (pe);
36323 }
36324 if (atm_vcc)
36325 - atomic_inc(&atm_vcc->stats->rx_drop);
36326 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36327 break;
36328 case 0x1f: /* Reassembly abort: no buffers. */
36329 /* Silently increment error counter. */
36330 if (atm_vcc)
36331 - atomic_inc(&atm_vcc->stats->rx_drop);
36332 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36333 break;
36334 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36335 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36336 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36337 index 204814e..cede831 100644
36338 --- a/drivers/atm/fore200e.c
36339 +++ b/drivers/atm/fore200e.c
36340 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36341 #endif
36342 /* check error condition */
36343 if (*entry->status & STATUS_ERROR)
36344 - atomic_inc(&vcc->stats->tx_err);
36345 + atomic_inc_unchecked(&vcc->stats->tx_err);
36346 else
36347 - atomic_inc(&vcc->stats->tx);
36348 + atomic_inc_unchecked(&vcc->stats->tx);
36349 }
36350 }
36351
36352 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36353 if (skb == NULL) {
36354 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36355
36356 - atomic_inc(&vcc->stats->rx_drop);
36357 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36358 return -ENOMEM;
36359 }
36360
36361 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36362
36363 dev_kfree_skb_any(skb);
36364
36365 - atomic_inc(&vcc->stats->rx_drop);
36366 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36367 return -ENOMEM;
36368 }
36369
36370 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36371
36372 vcc->push(vcc, skb);
36373 - atomic_inc(&vcc->stats->rx);
36374 + atomic_inc_unchecked(&vcc->stats->rx);
36375
36376 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36377
36378 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36379 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36380 fore200e->atm_dev->number,
36381 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36382 - atomic_inc(&vcc->stats->rx_err);
36383 + atomic_inc_unchecked(&vcc->stats->rx_err);
36384 }
36385 }
36386
36387 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36388 goto retry_here;
36389 }
36390
36391 - atomic_inc(&vcc->stats->tx_err);
36392 + atomic_inc_unchecked(&vcc->stats->tx_err);
36393
36394 fore200e->tx_sat++;
36395 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36396 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36397 index aa6be26..f70a785 100644
36398 --- a/drivers/atm/he.c
36399 +++ b/drivers/atm/he.c
36400 @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36401
36402 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36403 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36404 - atomic_inc(&vcc->stats->rx_drop);
36405 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36406 goto return_host_buffers;
36407 }
36408
36409 @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36410 RBRQ_LEN_ERR(he_dev->rbrq_head)
36411 ? "LEN_ERR" : "",
36412 vcc->vpi, vcc->vci);
36413 - atomic_inc(&vcc->stats->rx_err);
36414 + atomic_inc_unchecked(&vcc->stats->rx_err);
36415 goto return_host_buffers;
36416 }
36417
36418 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36419 vcc->push(vcc, skb);
36420 spin_lock(&he_dev->global_lock);
36421
36422 - atomic_inc(&vcc->stats->rx);
36423 + atomic_inc_unchecked(&vcc->stats->rx);
36424
36425 return_host_buffers:
36426 ++pdus_assembled;
36427 @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36428 tpd->vcc->pop(tpd->vcc, tpd->skb);
36429 else
36430 dev_kfree_skb_any(tpd->skb);
36431 - atomic_inc(&tpd->vcc->stats->tx_err);
36432 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36433 }
36434 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36435 return;
36436 @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36437 vcc->pop(vcc, skb);
36438 else
36439 dev_kfree_skb_any(skb);
36440 - atomic_inc(&vcc->stats->tx_err);
36441 + atomic_inc_unchecked(&vcc->stats->tx_err);
36442 return -EINVAL;
36443 }
36444
36445 @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36446 vcc->pop(vcc, skb);
36447 else
36448 dev_kfree_skb_any(skb);
36449 - atomic_inc(&vcc->stats->tx_err);
36450 + atomic_inc_unchecked(&vcc->stats->tx_err);
36451 return -EINVAL;
36452 }
36453 #endif
36454 @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36455 vcc->pop(vcc, skb);
36456 else
36457 dev_kfree_skb_any(skb);
36458 - atomic_inc(&vcc->stats->tx_err);
36459 + atomic_inc_unchecked(&vcc->stats->tx_err);
36460 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36461 return -ENOMEM;
36462 }
36463 @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36464 vcc->pop(vcc, skb);
36465 else
36466 dev_kfree_skb_any(skb);
36467 - atomic_inc(&vcc->stats->tx_err);
36468 + atomic_inc_unchecked(&vcc->stats->tx_err);
36469 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36470 return -ENOMEM;
36471 }
36472 @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36473 __enqueue_tpd(he_dev, tpd, cid);
36474 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36475
36476 - atomic_inc(&vcc->stats->tx);
36477 + atomic_inc_unchecked(&vcc->stats->tx);
36478
36479 return 0;
36480 }
36481 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36482 index 1dc0519..1aadaf7 100644
36483 --- a/drivers/atm/horizon.c
36484 +++ b/drivers/atm/horizon.c
36485 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36486 {
36487 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36488 // VC layer stats
36489 - atomic_inc(&vcc->stats->rx);
36490 + atomic_inc_unchecked(&vcc->stats->rx);
36491 __net_timestamp(skb);
36492 // end of our responsibility
36493 vcc->push (vcc, skb);
36494 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36495 dev->tx_iovec = NULL;
36496
36497 // VC layer stats
36498 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36499 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36500
36501 // free the skb
36502 hrz_kfree_skb (skb);
36503 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36504 index 1bdf104..9dc44b1 100644
36505 --- a/drivers/atm/idt77252.c
36506 +++ b/drivers/atm/idt77252.c
36507 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36508 else
36509 dev_kfree_skb(skb);
36510
36511 - atomic_inc(&vcc->stats->tx);
36512 + atomic_inc_unchecked(&vcc->stats->tx);
36513 }
36514
36515 atomic_dec(&scq->used);
36516 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36517 if ((sb = dev_alloc_skb(64)) == NULL) {
36518 printk("%s: Can't allocate buffers for aal0.\n",
36519 card->name);
36520 - atomic_add(i, &vcc->stats->rx_drop);
36521 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36522 break;
36523 }
36524 if (!atm_charge(vcc, sb->truesize)) {
36525 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36526 card->name);
36527 - atomic_add(i - 1, &vcc->stats->rx_drop);
36528 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36529 dev_kfree_skb(sb);
36530 break;
36531 }
36532 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36533 ATM_SKB(sb)->vcc = vcc;
36534 __net_timestamp(sb);
36535 vcc->push(vcc, sb);
36536 - atomic_inc(&vcc->stats->rx);
36537 + atomic_inc_unchecked(&vcc->stats->rx);
36538
36539 cell += ATM_CELL_PAYLOAD;
36540 }
36541 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36542 "(CDC: %08x)\n",
36543 card->name, len, rpp->len, readl(SAR_REG_CDC));
36544 recycle_rx_pool_skb(card, rpp);
36545 - atomic_inc(&vcc->stats->rx_err);
36546 + atomic_inc_unchecked(&vcc->stats->rx_err);
36547 return;
36548 }
36549 if (stat & SAR_RSQE_CRC) {
36550 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36551 recycle_rx_pool_skb(card, rpp);
36552 - atomic_inc(&vcc->stats->rx_err);
36553 + atomic_inc_unchecked(&vcc->stats->rx_err);
36554 return;
36555 }
36556 if (skb_queue_len(&rpp->queue) > 1) {
36557 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36558 RXPRINTK("%s: Can't alloc RX skb.\n",
36559 card->name);
36560 recycle_rx_pool_skb(card, rpp);
36561 - atomic_inc(&vcc->stats->rx_err);
36562 + atomic_inc_unchecked(&vcc->stats->rx_err);
36563 return;
36564 }
36565 if (!atm_charge(vcc, skb->truesize)) {
36566 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36567 __net_timestamp(skb);
36568
36569 vcc->push(vcc, skb);
36570 - atomic_inc(&vcc->stats->rx);
36571 + atomic_inc_unchecked(&vcc->stats->rx);
36572
36573 return;
36574 }
36575 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36576 __net_timestamp(skb);
36577
36578 vcc->push(vcc, skb);
36579 - atomic_inc(&vcc->stats->rx);
36580 + atomic_inc_unchecked(&vcc->stats->rx);
36581
36582 if (skb->truesize > SAR_FB_SIZE_3)
36583 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36584 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36585 if (vcc->qos.aal != ATM_AAL0) {
36586 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36587 card->name, vpi, vci);
36588 - atomic_inc(&vcc->stats->rx_drop);
36589 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36590 goto drop;
36591 }
36592
36593 if ((sb = dev_alloc_skb(64)) == NULL) {
36594 printk("%s: Can't allocate buffers for AAL0.\n",
36595 card->name);
36596 - atomic_inc(&vcc->stats->rx_err);
36597 + atomic_inc_unchecked(&vcc->stats->rx_err);
36598 goto drop;
36599 }
36600
36601 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36602 ATM_SKB(sb)->vcc = vcc;
36603 __net_timestamp(sb);
36604 vcc->push(vcc, sb);
36605 - atomic_inc(&vcc->stats->rx);
36606 + atomic_inc_unchecked(&vcc->stats->rx);
36607
36608 drop:
36609 skb_pull(queue, 64);
36610 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36611
36612 if (vc == NULL) {
36613 printk("%s: NULL connection in send().\n", card->name);
36614 - atomic_inc(&vcc->stats->tx_err);
36615 + atomic_inc_unchecked(&vcc->stats->tx_err);
36616 dev_kfree_skb(skb);
36617 return -EINVAL;
36618 }
36619 if (!test_bit(VCF_TX, &vc->flags)) {
36620 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36621 - atomic_inc(&vcc->stats->tx_err);
36622 + atomic_inc_unchecked(&vcc->stats->tx_err);
36623 dev_kfree_skb(skb);
36624 return -EINVAL;
36625 }
36626 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36627 break;
36628 default:
36629 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36630 - atomic_inc(&vcc->stats->tx_err);
36631 + atomic_inc_unchecked(&vcc->stats->tx_err);
36632 dev_kfree_skb(skb);
36633 return -EINVAL;
36634 }
36635
36636 if (skb_shinfo(skb)->nr_frags != 0) {
36637 printk("%s: No scatter-gather yet.\n", card->name);
36638 - atomic_inc(&vcc->stats->tx_err);
36639 + atomic_inc_unchecked(&vcc->stats->tx_err);
36640 dev_kfree_skb(skb);
36641 return -EINVAL;
36642 }
36643 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36644
36645 err = queue_skb(card, vc, skb, oam);
36646 if (err) {
36647 - atomic_inc(&vcc->stats->tx_err);
36648 + atomic_inc_unchecked(&vcc->stats->tx_err);
36649 dev_kfree_skb(skb);
36650 return err;
36651 }
36652 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36653 skb = dev_alloc_skb(64);
36654 if (!skb) {
36655 printk("%s: Out of memory in send_oam().\n", card->name);
36656 - atomic_inc(&vcc->stats->tx_err);
36657 + atomic_inc_unchecked(&vcc->stats->tx_err);
36658 return -ENOMEM;
36659 }
36660 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36661 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36662 index 4217f29..88f547a 100644
36663 --- a/drivers/atm/iphase.c
36664 +++ b/drivers/atm/iphase.c
36665 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36666 status = (u_short) (buf_desc_ptr->desc_mode);
36667 if (status & (RX_CER | RX_PTE | RX_OFL))
36668 {
36669 - atomic_inc(&vcc->stats->rx_err);
36670 + atomic_inc_unchecked(&vcc->stats->rx_err);
36671 IF_ERR(printk("IA: bad packet, dropping it");)
36672 if (status & RX_CER) {
36673 IF_ERR(printk(" cause: packet CRC error\n");)
36674 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36675 len = dma_addr - buf_addr;
36676 if (len > iadev->rx_buf_sz) {
36677 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36678 - atomic_inc(&vcc->stats->rx_err);
36679 + atomic_inc_unchecked(&vcc->stats->rx_err);
36680 goto out_free_desc;
36681 }
36682
36683 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36684 ia_vcc = INPH_IA_VCC(vcc);
36685 if (ia_vcc == NULL)
36686 {
36687 - atomic_inc(&vcc->stats->rx_err);
36688 + atomic_inc_unchecked(&vcc->stats->rx_err);
36689 atm_return(vcc, skb->truesize);
36690 dev_kfree_skb_any(skb);
36691 goto INCR_DLE;
36692 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36693 if ((length > iadev->rx_buf_sz) || (length >
36694 (skb->len - sizeof(struct cpcs_trailer))))
36695 {
36696 - atomic_inc(&vcc->stats->rx_err);
36697 + atomic_inc_unchecked(&vcc->stats->rx_err);
36698 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36699 length, skb->len);)
36700 atm_return(vcc, skb->truesize);
36701 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36702
36703 IF_RX(printk("rx_dle_intr: skb push");)
36704 vcc->push(vcc,skb);
36705 - atomic_inc(&vcc->stats->rx);
36706 + atomic_inc_unchecked(&vcc->stats->rx);
36707 iadev->rx_pkt_cnt++;
36708 }
36709 INCR_DLE:
36710 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36711 {
36712 struct k_sonet_stats *stats;
36713 stats = &PRIV(_ia_dev[board])->sonet_stats;
36714 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36715 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36716 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36717 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36718 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36719 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36720 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36721 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36722 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36723 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36724 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36725 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36726 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36727 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36728 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36729 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36730 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36731 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36732 }
36733 ia_cmds.status = 0;
36734 break;
36735 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36736 if ((desc == 0) || (desc > iadev->num_tx_desc))
36737 {
36738 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36739 - atomic_inc(&vcc->stats->tx);
36740 + atomic_inc_unchecked(&vcc->stats->tx);
36741 if (vcc->pop)
36742 vcc->pop(vcc, skb);
36743 else
36744 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36745 ATM_DESC(skb) = vcc->vci;
36746 skb_queue_tail(&iadev->tx_dma_q, skb);
36747
36748 - atomic_inc(&vcc->stats->tx);
36749 + atomic_inc_unchecked(&vcc->stats->tx);
36750 iadev->tx_pkt_cnt++;
36751 /* Increment transaction counter */
36752 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36753
36754 #if 0
36755 /* add flow control logic */
36756 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36757 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36758 if (iavcc->vc_desc_cnt > 10) {
36759 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36760 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36761 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36762 index fa7d701..1e404c7 100644
36763 --- a/drivers/atm/lanai.c
36764 +++ b/drivers/atm/lanai.c
36765 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36766 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36767 lanai_endtx(lanai, lvcc);
36768 lanai_free_skb(lvcc->tx.atmvcc, skb);
36769 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36770 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36771 }
36772
36773 /* Try to fill the buffer - don't call unless there is backlog */
36774 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36775 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36776 __net_timestamp(skb);
36777 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36778 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36779 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36780 out:
36781 lvcc->rx.buf.ptr = end;
36782 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36783 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36784 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36785 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36786 lanai->stats.service_rxnotaal5++;
36787 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36788 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36789 return 0;
36790 }
36791 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36792 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36793 int bytes;
36794 read_unlock(&vcc_sklist_lock);
36795 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36796 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36797 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36798 lvcc->stats.x.aal5.service_trash++;
36799 bytes = (SERVICE_GET_END(s) * 16) -
36800 (((unsigned long) lvcc->rx.buf.ptr) -
36801 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36802 }
36803 if (s & SERVICE_STREAM) {
36804 read_unlock(&vcc_sklist_lock);
36805 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36806 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36807 lvcc->stats.x.aal5.service_stream++;
36808 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36809 "PDU on VCI %d!\n", lanai->number, vci);
36810 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36811 return 0;
36812 }
36813 DPRINTK("got rx crc error on vci %d\n", vci);
36814 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36815 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36816 lvcc->stats.x.aal5.service_rxcrc++;
36817 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36818 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36819 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36820 index 9587e95..b45c5cb 100644
36821 --- a/drivers/atm/nicstar.c
36822 +++ b/drivers/atm/nicstar.c
36823 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36824 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36825 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36826 card->index);
36827 - atomic_inc(&vcc->stats->tx_err);
36828 + atomic_inc_unchecked(&vcc->stats->tx_err);
36829 dev_kfree_skb_any(skb);
36830 return -EINVAL;
36831 }
36832 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36833 if (!vc->tx) {
36834 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36835 card->index);
36836 - atomic_inc(&vcc->stats->tx_err);
36837 + atomic_inc_unchecked(&vcc->stats->tx_err);
36838 dev_kfree_skb_any(skb);
36839 return -EINVAL;
36840 }
36841 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36842 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36843 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36844 card->index);
36845 - atomic_inc(&vcc->stats->tx_err);
36846 + atomic_inc_unchecked(&vcc->stats->tx_err);
36847 dev_kfree_skb_any(skb);
36848 return -EINVAL;
36849 }
36850
36851 if (skb_shinfo(skb)->nr_frags != 0) {
36852 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36853 - atomic_inc(&vcc->stats->tx_err);
36854 + atomic_inc_unchecked(&vcc->stats->tx_err);
36855 dev_kfree_skb_any(skb);
36856 return -EINVAL;
36857 }
36858 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36859 }
36860
36861 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36862 - atomic_inc(&vcc->stats->tx_err);
36863 + atomic_inc_unchecked(&vcc->stats->tx_err);
36864 dev_kfree_skb_any(skb);
36865 return -EIO;
36866 }
36867 - atomic_inc(&vcc->stats->tx);
36868 + atomic_inc_unchecked(&vcc->stats->tx);
36869
36870 return 0;
36871 }
36872 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36873 printk
36874 ("nicstar%d: Can't allocate buffers for aal0.\n",
36875 card->index);
36876 - atomic_add(i, &vcc->stats->rx_drop);
36877 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36878 break;
36879 }
36880 if (!atm_charge(vcc, sb->truesize)) {
36881 RXPRINTK
36882 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36883 card->index);
36884 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36885 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36886 dev_kfree_skb_any(sb);
36887 break;
36888 }
36889 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36890 ATM_SKB(sb)->vcc = vcc;
36891 __net_timestamp(sb);
36892 vcc->push(vcc, sb);
36893 - atomic_inc(&vcc->stats->rx);
36894 + atomic_inc_unchecked(&vcc->stats->rx);
36895 cell += ATM_CELL_PAYLOAD;
36896 }
36897
36898 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36899 if (iovb == NULL) {
36900 printk("nicstar%d: Out of iovec buffers.\n",
36901 card->index);
36902 - atomic_inc(&vcc->stats->rx_drop);
36903 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36904 recycle_rx_buf(card, skb);
36905 return;
36906 }
36907 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36908 small or large buffer itself. */
36909 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36910 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36911 - atomic_inc(&vcc->stats->rx_err);
36912 + atomic_inc_unchecked(&vcc->stats->rx_err);
36913 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36914 NS_MAX_IOVECS);
36915 NS_PRV_IOVCNT(iovb) = 0;
36916 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36917 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36918 card->index);
36919 which_list(card, skb);
36920 - atomic_inc(&vcc->stats->rx_err);
36921 + atomic_inc_unchecked(&vcc->stats->rx_err);
36922 recycle_rx_buf(card, skb);
36923 vc->rx_iov = NULL;
36924 recycle_iov_buf(card, iovb);
36925 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36926 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36927 card->index);
36928 which_list(card, skb);
36929 - atomic_inc(&vcc->stats->rx_err);
36930 + atomic_inc_unchecked(&vcc->stats->rx_err);
36931 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36932 NS_PRV_IOVCNT(iovb));
36933 vc->rx_iov = NULL;
36934 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36935 printk(" - PDU size mismatch.\n");
36936 else
36937 printk(".\n");
36938 - atomic_inc(&vcc->stats->rx_err);
36939 + atomic_inc_unchecked(&vcc->stats->rx_err);
36940 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36941 NS_PRV_IOVCNT(iovb));
36942 vc->rx_iov = NULL;
36943 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36944 /* skb points to a small buffer */
36945 if (!atm_charge(vcc, skb->truesize)) {
36946 push_rxbufs(card, skb);
36947 - atomic_inc(&vcc->stats->rx_drop);
36948 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36949 } else {
36950 skb_put(skb, len);
36951 dequeue_sm_buf(card, skb);
36952 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36953 ATM_SKB(skb)->vcc = vcc;
36954 __net_timestamp(skb);
36955 vcc->push(vcc, skb);
36956 - atomic_inc(&vcc->stats->rx);
36957 + atomic_inc_unchecked(&vcc->stats->rx);
36958 }
36959 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36960 struct sk_buff *sb;
36961 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36962 if (len <= NS_SMBUFSIZE) {
36963 if (!atm_charge(vcc, sb->truesize)) {
36964 push_rxbufs(card, sb);
36965 - atomic_inc(&vcc->stats->rx_drop);
36966 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36967 } else {
36968 skb_put(sb, len);
36969 dequeue_sm_buf(card, sb);
36970 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36971 ATM_SKB(sb)->vcc = vcc;
36972 __net_timestamp(sb);
36973 vcc->push(vcc, sb);
36974 - atomic_inc(&vcc->stats->rx);
36975 + atomic_inc_unchecked(&vcc->stats->rx);
36976 }
36977
36978 push_rxbufs(card, skb);
36979 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36980
36981 if (!atm_charge(vcc, skb->truesize)) {
36982 push_rxbufs(card, skb);
36983 - atomic_inc(&vcc->stats->rx_drop);
36984 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36985 } else {
36986 dequeue_lg_buf(card, skb);
36987 #ifdef NS_USE_DESTRUCTORS
36988 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36989 ATM_SKB(skb)->vcc = vcc;
36990 __net_timestamp(skb);
36991 vcc->push(vcc, skb);
36992 - atomic_inc(&vcc->stats->rx);
36993 + atomic_inc_unchecked(&vcc->stats->rx);
36994 }
36995
36996 push_rxbufs(card, sb);
36997 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36998 printk
36999 ("nicstar%d: Out of huge buffers.\n",
37000 card->index);
37001 - atomic_inc(&vcc->stats->rx_drop);
37002 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37003 recycle_iovec_rx_bufs(card,
37004 (struct iovec *)
37005 iovb->data,
37006 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37007 card->hbpool.count++;
37008 } else
37009 dev_kfree_skb_any(hb);
37010 - atomic_inc(&vcc->stats->rx_drop);
37011 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37012 } else {
37013 /* Copy the small buffer to the huge buffer */
37014 sb = (struct sk_buff *)iov->iov_base;
37015 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37016 #endif /* NS_USE_DESTRUCTORS */
37017 __net_timestamp(hb);
37018 vcc->push(vcc, hb);
37019 - atomic_inc(&vcc->stats->rx);
37020 + atomic_inc_unchecked(&vcc->stats->rx);
37021 }
37022 }
37023
37024 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37025 index e3fb496..d9646bf 100644
37026 --- a/drivers/atm/solos-pci.c
37027 +++ b/drivers/atm/solos-pci.c
37028 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37029 }
37030 atm_charge(vcc, skb->truesize);
37031 vcc->push(vcc, skb);
37032 - atomic_inc(&vcc->stats->rx);
37033 + atomic_inc_unchecked(&vcc->stats->rx);
37034 break;
37035
37036 case PKT_STATUS:
37037 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37038 vcc = SKB_CB(oldskb)->vcc;
37039
37040 if (vcc) {
37041 - atomic_inc(&vcc->stats->tx);
37042 + atomic_inc_unchecked(&vcc->stats->tx);
37043 solos_pop(vcc, oldskb);
37044 } else {
37045 dev_kfree_skb_irq(oldskb);
37046 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37047 index 0215934..ce9f5b1 100644
37048 --- a/drivers/atm/suni.c
37049 +++ b/drivers/atm/suni.c
37050 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37051
37052
37053 #define ADD_LIMITED(s,v) \
37054 - atomic_add((v),&stats->s); \
37055 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37056 + atomic_add_unchecked((v),&stats->s); \
37057 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37058
37059
37060 static void suni_hz(unsigned long from_timer)
37061 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37062 index 5120a96..e2572bd 100644
37063 --- a/drivers/atm/uPD98402.c
37064 +++ b/drivers/atm/uPD98402.c
37065 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37066 struct sonet_stats tmp;
37067 int error = 0;
37068
37069 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37070 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37071 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37072 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37073 if (zero && !error) {
37074 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37075
37076
37077 #define ADD_LIMITED(s,v) \
37078 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37079 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37080 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37081 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37082 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37083 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37084
37085
37086 static void stat_event(struct atm_dev *dev)
37087 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37088 if (reason & uPD98402_INT_PFM) stat_event(dev);
37089 if (reason & uPD98402_INT_PCO) {
37090 (void) GET(PCOCR); /* clear interrupt cause */
37091 - atomic_add(GET(HECCT),
37092 + atomic_add_unchecked(GET(HECCT),
37093 &PRIV(dev)->sonet_stats.uncorr_hcs);
37094 }
37095 if ((reason & uPD98402_INT_RFO) &&
37096 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37097 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37098 uPD98402_INT_LOS),PIMR); /* enable them */
37099 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37100 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37101 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37102 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37103 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37104 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37105 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37106 return 0;
37107 }
37108
37109 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37110 index 969c3c2..9b72956 100644
37111 --- a/drivers/atm/zatm.c
37112 +++ b/drivers/atm/zatm.c
37113 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37114 }
37115 if (!size) {
37116 dev_kfree_skb_irq(skb);
37117 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37118 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37119 continue;
37120 }
37121 if (!atm_charge(vcc,skb->truesize)) {
37122 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37123 skb->len = size;
37124 ATM_SKB(skb)->vcc = vcc;
37125 vcc->push(vcc,skb);
37126 - atomic_inc(&vcc->stats->rx);
37127 + atomic_inc_unchecked(&vcc->stats->rx);
37128 }
37129 zout(pos & 0xffff,MTA(mbx));
37130 #if 0 /* probably a stupid idea */
37131 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37132 skb_queue_head(&zatm_vcc->backlog,skb);
37133 break;
37134 }
37135 - atomic_inc(&vcc->stats->tx);
37136 + atomic_inc_unchecked(&vcc->stats->tx);
37137 wake_up(&zatm_vcc->tx_wait);
37138 }
37139
37140 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37141 index 59dc808..f10c74e 100644
37142 --- a/drivers/base/bus.c
37143 +++ b/drivers/base/bus.c
37144 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37145 return -EINVAL;
37146
37147 mutex_lock(&subsys->p->mutex);
37148 - list_add_tail(&sif->node, &subsys->p->interfaces);
37149 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37150 if (sif->add_dev) {
37151 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37152 while ((dev = subsys_dev_iter_next(&iter)))
37153 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37154 subsys = sif->subsys;
37155
37156 mutex_lock(&subsys->p->mutex);
37157 - list_del_init(&sif->node);
37158 + pax_list_del_init((struct list_head *)&sif->node);
37159 if (sif->remove_dev) {
37160 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37161 while ((dev = subsys_dev_iter_next(&iter)))
37162 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37163 index 25798db..15f130e 100644
37164 --- a/drivers/base/devtmpfs.c
37165 +++ b/drivers/base/devtmpfs.c
37166 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37167 if (!thread)
37168 return 0;
37169
37170 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37171 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37172 if (err)
37173 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37174 else
37175 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37176 *err = sys_unshare(CLONE_NEWNS);
37177 if (*err)
37178 goto out;
37179 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37180 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37181 if (*err)
37182 goto out;
37183 - sys_chdir("/.."); /* will traverse into overmounted root */
37184 - sys_chroot(".");
37185 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37186 + sys_chroot((char __force_user *)".");
37187 complete(&setup_done);
37188 while (1) {
37189 spin_lock(&req_lock);
37190 diff --git a/drivers/base/node.c b/drivers/base/node.c
37191 index bc9f43b..29703b8 100644
37192 --- a/drivers/base/node.c
37193 +++ b/drivers/base/node.c
37194 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37195 struct node_attr {
37196 struct device_attribute attr;
37197 enum node_states state;
37198 -};
37199 +} __do_const;
37200
37201 static ssize_t show_node_state(struct device *dev,
37202 struct device_attribute *attr, char *buf)
37203 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37204 index bfb8955..4ebff34 100644
37205 --- a/drivers/base/power/domain.c
37206 +++ b/drivers/base/power/domain.c
37207 @@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37208
37209 if (dev->power.subsys_data->domain_data) {
37210 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37211 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
37212 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37213 if (clear_td)
37214 - gpd_data->td = (struct gpd_timing_data){ 0 };
37215 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37216
37217 if (--gpd_data->refcount == 0) {
37218 dev->power.subsys_data->domain_data = NULL;
37219 @@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37220 {
37221 struct cpuidle_driver *cpuidle_drv;
37222 struct gpd_cpu_data *cpu_data;
37223 - struct cpuidle_state *idle_state;
37224 + cpuidle_state_no_const *idle_state;
37225 int ret = 0;
37226
37227 if (IS_ERR_OR_NULL(genpd) || state < 0)
37228 @@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37229 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37230 {
37231 struct gpd_cpu_data *cpu_data;
37232 - struct cpuidle_state *idle_state;
37233 + cpuidle_state_no_const *idle_state;
37234 int ret = 0;
37235
37236 if (IS_ERR_OR_NULL(genpd))
37237 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37238 index 03e089a..0e9560c 100644
37239 --- a/drivers/base/power/sysfs.c
37240 +++ b/drivers/base/power/sysfs.c
37241 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37242 return -EIO;
37243 }
37244 }
37245 - return sprintf(buf, p);
37246 + return sprintf(buf, "%s", p);
37247 }
37248
37249 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37250 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37251 index 2d56f41..8830f19 100644
37252 --- a/drivers/base/power/wakeup.c
37253 +++ b/drivers/base/power/wakeup.c
37254 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37255 * They need to be modified together atomically, so it's better to use one
37256 * atomic variable to hold them both.
37257 */
37258 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37259 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37260
37261 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37262 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37263
37264 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37265 {
37266 - unsigned int comb = atomic_read(&combined_event_count);
37267 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37268
37269 *cnt = (comb >> IN_PROGRESS_BITS);
37270 *inpr = comb & MAX_IN_PROGRESS;
37271 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37272 ws->start_prevent_time = ws->last_time;
37273
37274 /* Increment the counter of events in progress. */
37275 - cec = atomic_inc_return(&combined_event_count);
37276 + cec = atomic_inc_return_unchecked(&combined_event_count);
37277
37278 trace_wakeup_source_activate(ws->name, cec);
37279 }
37280 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37281 * Increment the counter of registered wakeup events and decrement the
37282 * couter of wakeup events in progress simultaneously.
37283 */
37284 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37285 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37286 trace_wakeup_source_deactivate(ws->name, cec);
37287
37288 split_counters(&cnt, &inpr);
37289 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37290 index e8d11b6..7b1b36f 100644
37291 --- a/drivers/base/syscore.c
37292 +++ b/drivers/base/syscore.c
37293 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37294 void register_syscore_ops(struct syscore_ops *ops)
37295 {
37296 mutex_lock(&syscore_ops_lock);
37297 - list_add_tail(&ops->node, &syscore_ops_list);
37298 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37299 mutex_unlock(&syscore_ops_lock);
37300 }
37301 EXPORT_SYMBOL_GPL(register_syscore_ops);
37302 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37303 void unregister_syscore_ops(struct syscore_ops *ops)
37304 {
37305 mutex_lock(&syscore_ops_lock);
37306 - list_del(&ops->node);
37307 + pax_list_del((struct list_head *)&ops->node);
37308 mutex_unlock(&syscore_ops_lock);
37309 }
37310 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37311 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37312 index 036e8ab..6221dec 100644
37313 --- a/drivers/block/cciss.c
37314 +++ b/drivers/block/cciss.c
37315 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37316 while (!list_empty(&h->reqQ)) {
37317 c = list_entry(h->reqQ.next, CommandList_struct, list);
37318 /* can't do anything if fifo is full */
37319 - if ((h->access.fifo_full(h))) {
37320 + if ((h->access->fifo_full(h))) {
37321 dev_warn(&h->pdev->dev, "fifo full\n");
37322 break;
37323 }
37324 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37325 h->Qdepth--;
37326
37327 /* Tell the controller execute command */
37328 - h->access.submit_command(h, c);
37329 + h->access->submit_command(h, c);
37330
37331 /* Put job onto the completed Q */
37332 addQ(&h->cmpQ, c);
37333 @@ -3447,17 +3447,17 @@ startio:
37334
37335 static inline unsigned long get_next_completion(ctlr_info_t *h)
37336 {
37337 - return h->access.command_completed(h);
37338 + return h->access->command_completed(h);
37339 }
37340
37341 static inline int interrupt_pending(ctlr_info_t *h)
37342 {
37343 - return h->access.intr_pending(h);
37344 + return h->access->intr_pending(h);
37345 }
37346
37347 static inline long interrupt_not_for_us(ctlr_info_t *h)
37348 {
37349 - return ((h->access.intr_pending(h) == 0) ||
37350 + return ((h->access->intr_pending(h) == 0) ||
37351 (h->interrupts_enabled == 0));
37352 }
37353
37354 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37355 u32 a;
37356
37357 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37358 - return h->access.command_completed(h);
37359 + return h->access->command_completed(h);
37360
37361 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37362 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37363 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37364 trans_support & CFGTBL_Trans_use_short_tags);
37365
37366 /* Change the access methods to the performant access methods */
37367 - h->access = SA5_performant_access;
37368 + h->access = &SA5_performant_access;
37369 h->transMethod = CFGTBL_Trans_Performant;
37370
37371 return;
37372 @@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37373 if (prod_index < 0)
37374 return -ENODEV;
37375 h->product_name = products[prod_index].product_name;
37376 - h->access = *(products[prod_index].access);
37377 + h->access = products[prod_index].access;
37378
37379 if (cciss_board_disabled(h)) {
37380 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37381 @@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37382 }
37383
37384 /* make sure the board interrupts are off */
37385 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37386 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37387 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37388 if (rc)
37389 goto clean2;
37390 @@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37391 * fake ones to scoop up any residual completions.
37392 */
37393 spin_lock_irqsave(&h->lock, flags);
37394 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37395 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37396 spin_unlock_irqrestore(&h->lock, flags);
37397 free_irq(h->intr[h->intr_mode], h);
37398 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37399 @@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37400 dev_info(&h->pdev->dev, "Board READY.\n");
37401 dev_info(&h->pdev->dev,
37402 "Waiting for stale completions to drain.\n");
37403 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37404 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37405 msleep(10000);
37406 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37407 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37408
37409 rc = controller_reset_failed(h->cfgtable);
37410 if (rc)
37411 @@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37412 cciss_scsi_setup(h);
37413
37414 /* Turn the interrupts on so we can service requests */
37415 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37416 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37417
37418 /* Get the firmware version */
37419 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37420 @@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37421 kfree(flush_buf);
37422 if (return_code != IO_OK)
37423 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37424 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37425 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37426 free_irq(h->intr[h->intr_mode], h);
37427 }
37428
37429 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37430 index 7fda30e..2f27946 100644
37431 --- a/drivers/block/cciss.h
37432 +++ b/drivers/block/cciss.h
37433 @@ -101,7 +101,7 @@ struct ctlr_info
37434 /* information about each logical volume */
37435 drive_info_struct *drv[CISS_MAX_LUN];
37436
37437 - struct access_method access;
37438 + struct access_method *access;
37439
37440 /* queue and queue Info */
37441 struct list_head reqQ;
37442 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37443 }
37444
37445 static struct access_method SA5_access = {
37446 - SA5_submit_command,
37447 - SA5_intr_mask,
37448 - SA5_fifo_full,
37449 - SA5_intr_pending,
37450 - SA5_completed,
37451 + .submit_command = SA5_submit_command,
37452 + .set_intr_mask = SA5_intr_mask,
37453 + .fifo_full = SA5_fifo_full,
37454 + .intr_pending = SA5_intr_pending,
37455 + .command_completed = SA5_completed,
37456 };
37457
37458 static struct access_method SA5B_access = {
37459 - SA5_submit_command,
37460 - SA5B_intr_mask,
37461 - SA5_fifo_full,
37462 - SA5B_intr_pending,
37463 - SA5_completed,
37464 + .submit_command = SA5_submit_command,
37465 + .set_intr_mask = SA5B_intr_mask,
37466 + .fifo_full = SA5_fifo_full,
37467 + .intr_pending = SA5B_intr_pending,
37468 + .command_completed = SA5_completed,
37469 };
37470
37471 static struct access_method SA5_performant_access = {
37472 - SA5_submit_command,
37473 - SA5_performant_intr_mask,
37474 - SA5_fifo_full,
37475 - SA5_performant_intr_pending,
37476 - SA5_performant_completed,
37477 + .submit_command = SA5_submit_command,
37478 + .set_intr_mask = SA5_performant_intr_mask,
37479 + .fifo_full = SA5_fifo_full,
37480 + .intr_pending = SA5_performant_intr_pending,
37481 + .command_completed = SA5_performant_completed,
37482 };
37483
37484 struct board_type {
37485 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37486 index 2b94403..fd6ad1f 100644
37487 --- a/drivers/block/cpqarray.c
37488 +++ b/drivers/block/cpqarray.c
37489 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37490 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37491 goto Enomem4;
37492 }
37493 - hba[i]->access.set_intr_mask(hba[i], 0);
37494 + hba[i]->access->set_intr_mask(hba[i], 0);
37495 if (request_irq(hba[i]->intr, do_ida_intr,
37496 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37497 {
37498 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37499 add_timer(&hba[i]->timer);
37500
37501 /* Enable IRQ now that spinlock and rate limit timer are set up */
37502 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37503 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37504
37505 for(j=0; j<NWD; j++) {
37506 struct gendisk *disk = ida_gendisk[i][j];
37507 @@ -694,7 +694,7 @@ DBGINFO(
37508 for(i=0; i<NR_PRODUCTS; i++) {
37509 if (board_id == products[i].board_id) {
37510 c->product_name = products[i].product_name;
37511 - c->access = *(products[i].access);
37512 + c->access = products[i].access;
37513 break;
37514 }
37515 }
37516 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37517 hba[ctlr]->intr = intr;
37518 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37519 hba[ctlr]->product_name = products[j].product_name;
37520 - hba[ctlr]->access = *(products[j].access);
37521 + hba[ctlr]->access = products[j].access;
37522 hba[ctlr]->ctlr = ctlr;
37523 hba[ctlr]->board_id = board_id;
37524 hba[ctlr]->pci_dev = NULL; /* not PCI */
37525 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37526
37527 while((c = h->reqQ) != NULL) {
37528 /* Can't do anything if we're busy */
37529 - if (h->access.fifo_full(h) == 0)
37530 + if (h->access->fifo_full(h) == 0)
37531 return;
37532
37533 /* Get the first entry from the request Q */
37534 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37535 h->Qdepth--;
37536
37537 /* Tell the controller to do our bidding */
37538 - h->access.submit_command(h, c);
37539 + h->access->submit_command(h, c);
37540
37541 /* Get onto the completion Q */
37542 addQ(&h->cmpQ, c);
37543 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37544 unsigned long flags;
37545 __u32 a,a1;
37546
37547 - istat = h->access.intr_pending(h);
37548 + istat = h->access->intr_pending(h);
37549 /* Is this interrupt for us? */
37550 if (istat == 0)
37551 return IRQ_NONE;
37552 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37553 */
37554 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37555 if (istat & FIFO_NOT_EMPTY) {
37556 - while((a = h->access.command_completed(h))) {
37557 + while((a = h->access->command_completed(h))) {
37558 a1 = a; a &= ~3;
37559 if ((c = h->cmpQ) == NULL)
37560 {
37561 @@ -1448,11 +1448,11 @@ static int sendcmd(
37562 /*
37563 * Disable interrupt
37564 */
37565 - info_p->access.set_intr_mask(info_p, 0);
37566 + info_p->access->set_intr_mask(info_p, 0);
37567 /* Make sure there is room in the command FIFO */
37568 /* Actually it should be completely empty at this time. */
37569 for (i = 200000; i > 0; i--) {
37570 - temp = info_p->access.fifo_full(info_p);
37571 + temp = info_p->access->fifo_full(info_p);
37572 if (temp != 0) {
37573 break;
37574 }
37575 @@ -1465,7 +1465,7 @@ DBG(
37576 /*
37577 * Send the cmd
37578 */
37579 - info_p->access.submit_command(info_p, c);
37580 + info_p->access->submit_command(info_p, c);
37581 complete = pollcomplete(ctlr);
37582
37583 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37584 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37585 * we check the new geometry. Then turn interrupts back on when
37586 * we're done.
37587 */
37588 - host->access.set_intr_mask(host, 0);
37589 + host->access->set_intr_mask(host, 0);
37590 getgeometry(ctlr);
37591 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37592 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37593
37594 for(i=0; i<NWD; i++) {
37595 struct gendisk *disk = ida_gendisk[ctlr][i];
37596 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37597 /* Wait (up to 2 seconds) for a command to complete */
37598
37599 for (i = 200000; i > 0; i--) {
37600 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37601 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37602 if (done == 0) {
37603 udelay(10); /* a short fixed delay */
37604 } else
37605 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37606 index be73e9d..7fbf140 100644
37607 --- a/drivers/block/cpqarray.h
37608 +++ b/drivers/block/cpqarray.h
37609 @@ -99,7 +99,7 @@ struct ctlr_info {
37610 drv_info_t drv[NWD];
37611 struct proc_dir_entry *proc;
37612
37613 - struct access_method access;
37614 + struct access_method *access;
37615
37616 cmdlist_t *reqQ;
37617 cmdlist_t *cmpQ;
37618 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37619 index 0e06f0c..c47b81d 100644
37620 --- a/drivers/block/drbd/drbd_int.h
37621 +++ b/drivers/block/drbd/drbd_int.h
37622 @@ -582,7 +582,7 @@ struct drbd_epoch {
37623 struct drbd_tconn *tconn;
37624 struct list_head list;
37625 unsigned int barrier_nr;
37626 - atomic_t epoch_size; /* increased on every request added. */
37627 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37628 atomic_t active; /* increased on every req. added, and dec on every finished. */
37629 unsigned long flags;
37630 };
37631 @@ -1022,7 +1022,7 @@ struct drbd_conf {
37632 unsigned int al_tr_number;
37633 int al_tr_cycle;
37634 wait_queue_head_t seq_wait;
37635 - atomic_t packet_seq;
37636 + atomic_unchecked_t packet_seq;
37637 unsigned int peer_seq;
37638 spinlock_t peer_seq_lock;
37639 unsigned int minor;
37640 @@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37641 char __user *uoptval;
37642 int err;
37643
37644 - uoptval = (char __user __force *)optval;
37645 + uoptval = (char __force_user *)optval;
37646
37647 set_fs(KERNEL_DS);
37648 if (level == SOL_SOCKET)
37649 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37650 index 89c497c..9c736ae 100644
37651 --- a/drivers/block/drbd/drbd_interval.c
37652 +++ b/drivers/block/drbd/drbd_interval.c
37653 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37654 }
37655
37656 static const struct rb_augment_callbacks augment_callbacks = {
37657 - augment_propagate,
37658 - augment_copy,
37659 - augment_rotate,
37660 + .propagate = augment_propagate,
37661 + .copy = augment_copy,
37662 + .rotate = augment_rotate,
37663 };
37664
37665 /**
37666 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37667 index 929468e..7d934eb 100644
37668 --- a/drivers/block/drbd/drbd_main.c
37669 +++ b/drivers/block/drbd/drbd_main.c
37670 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37671 p->sector = sector;
37672 p->block_id = block_id;
37673 p->blksize = blksize;
37674 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37675 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37676 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37677 }
37678
37679 @@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37680 return -EIO;
37681 p->sector = cpu_to_be64(req->i.sector);
37682 p->block_id = (unsigned long)req;
37683 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37684 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37685 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37686 if (mdev->state.conn >= C_SYNC_SOURCE &&
37687 mdev->state.conn <= C_PAUSED_SYNC_T)
37688 @@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
37689 {
37690 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37691
37692 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37693 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37694 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37695 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37696 kfree(tconn->current_epoch);
37697
37698 idr_destroy(&tconn->volumes);
37699 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37700 index c706d50..5e1b472 100644
37701 --- a/drivers/block/drbd/drbd_nl.c
37702 +++ b/drivers/block/drbd/drbd_nl.c
37703 @@ -3440,7 +3440,7 @@ out:
37704
37705 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37706 {
37707 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37708 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37709 struct sk_buff *msg;
37710 struct drbd_genlmsghdr *d_out;
37711 unsigned seq;
37712 @@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37713 return;
37714 }
37715
37716 - seq = atomic_inc_return(&drbd_genl_seq);
37717 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37718 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37719 if (!msg)
37720 goto failed;
37721 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37722 index d073305..4998fea 100644
37723 --- a/drivers/block/drbd/drbd_receiver.c
37724 +++ b/drivers/block/drbd/drbd_receiver.c
37725 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37726 {
37727 int err;
37728
37729 - atomic_set(&mdev->packet_seq, 0);
37730 + atomic_set_unchecked(&mdev->packet_seq, 0);
37731 mdev->peer_seq = 0;
37732
37733 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37734 @@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37735 do {
37736 next_epoch = NULL;
37737
37738 - epoch_size = atomic_read(&epoch->epoch_size);
37739 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37740
37741 switch (ev & ~EV_CLEANUP) {
37742 case EV_PUT:
37743 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37744 rv = FE_DESTROYED;
37745 } else {
37746 epoch->flags = 0;
37747 - atomic_set(&epoch->epoch_size, 0);
37748 + atomic_set_unchecked(&epoch->epoch_size, 0);
37749 /* atomic_set(&epoch->active, 0); is already zero */
37750 if (rv == FE_STILL_LIVE)
37751 rv = FE_RECYCLED;
37752 @@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37753 conn_wait_active_ee_empty(tconn);
37754 drbd_flush(tconn);
37755
37756 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37757 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37758 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37759 if (epoch)
37760 break;
37761 @@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37762 }
37763
37764 epoch->flags = 0;
37765 - atomic_set(&epoch->epoch_size, 0);
37766 + atomic_set_unchecked(&epoch->epoch_size, 0);
37767 atomic_set(&epoch->active, 0);
37768
37769 spin_lock(&tconn->epoch_lock);
37770 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37771 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37772 list_add(&epoch->list, &tconn->current_epoch->list);
37773 tconn->current_epoch = epoch;
37774 tconn->epochs++;
37775 @@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37776
37777 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37778 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37779 - atomic_inc(&tconn->current_epoch->epoch_size);
37780 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37781 err2 = drbd_drain_block(mdev, pi->size);
37782 if (!err)
37783 err = err2;
37784 @@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37785
37786 spin_lock(&tconn->epoch_lock);
37787 peer_req->epoch = tconn->current_epoch;
37788 - atomic_inc(&peer_req->epoch->epoch_size);
37789 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37790 atomic_inc(&peer_req->epoch->active);
37791 spin_unlock(&tconn->epoch_lock);
37792
37793 @@ -4345,7 +4345,7 @@ struct data_cmd {
37794 int expect_payload;
37795 size_t pkt_size;
37796 int (*fn)(struct drbd_tconn *, struct packet_info *);
37797 -};
37798 +} __do_const;
37799
37800 static struct data_cmd drbd_cmd_handler[] = {
37801 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37802 @@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37803 if (!list_empty(&tconn->current_epoch->list))
37804 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37805 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37806 - atomic_set(&tconn->current_epoch->epoch_size, 0);
37807 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37808 tconn->send.seen_any_write_yet = false;
37809
37810 conn_info(tconn, "Connection closed\n");
37811 @@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37812 struct asender_cmd {
37813 size_t pkt_size;
37814 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37815 -};
37816 +} __do_const;
37817
37818 static struct asender_cmd asender_tbl[] = {
37819 [P_PING] = { 0, got_Ping },
37820 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37821 index 66e8c3b..9b68dd9 100644
37822 --- a/drivers/block/loop.c
37823 +++ b/drivers/block/loop.c
37824 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37825
37826 file_start_write(file);
37827 set_fs(get_ds());
37828 - bw = file->f_op->write(file, buf, len, &pos);
37829 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37830 set_fs(old_fs);
37831 file_end_write(file);
37832 if (likely(bw == len))
37833 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37834 index 091b9ea..f5428f8 100644
37835 --- a/drivers/block/null_blk.c
37836 +++ b/drivers/block/null_blk.c
37837 @@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37838 return 0;
37839 }
37840
37841 -static struct blk_mq_ops null_mq_ops = {
37842 - .queue_rq = null_queue_rq,
37843 - .map_queue = blk_mq_map_queue,
37844 +static struct blk_mq_ops null_mq_single_ops = {
37845 + .queue_rq = null_queue_rq,
37846 + .map_queue = blk_mq_map_queue,
37847 .init_hctx = null_init_hctx,
37848 .complete = null_softirq_done_fn,
37849 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
37850 + .free_hctx = blk_mq_free_single_hw_queue,
37851 +};
37852 +
37853 +static struct blk_mq_ops null_mq_per_node_ops = {
37854 + .queue_rq = null_queue_rq,
37855 + .map_queue = blk_mq_map_queue,
37856 + .init_hctx = null_init_hctx,
37857 + .alloc_hctx = null_alloc_hctx,
37858 + .free_hctx = null_free_hctx,
37859 };
37860
37861 static struct blk_mq_reg null_mq_reg = {
37862 - .ops = &null_mq_ops,
37863 + .ops = &null_mq_single_ops,
37864 .queue_depth = 64,
37865 .cmd_size = sizeof(struct nullb_cmd),
37866 .flags = BLK_MQ_F_SHOULD_MERGE,
37867 @@ -521,13 +531,8 @@ static int null_add_dev(void)
37868 null_mq_reg.queue_depth = hw_queue_depth;
37869 null_mq_reg.nr_hw_queues = submit_queues;
37870
37871 - if (use_per_node_hctx) {
37872 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37873 - null_mq_reg.ops->free_hctx = null_free_hctx;
37874 - } else {
37875 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37876 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37877 - }
37878 + if (use_per_node_hctx)
37879 + null_mq_reg.ops = &null_mq_per_node_ops;
37880
37881 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37882 } else if (queue_mode == NULL_Q_BIO) {
37883 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37884 index a2af73d..c0b8f61 100644
37885 --- a/drivers/block/pktcdvd.c
37886 +++ b/drivers/block/pktcdvd.c
37887 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37888
37889 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37890 {
37891 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37892 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37893 }
37894
37895 /*
37896 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37897 return -EROFS;
37898 }
37899 pd->settings.fp = ti.fp;
37900 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37901 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37902
37903 if (ti.nwa_v) {
37904 pd->nwa = be32_to_cpu(ti.next_writable);
37905 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37906 index e5565fb..71be10b4 100644
37907 --- a/drivers/block/smart1,2.h
37908 +++ b/drivers/block/smart1,2.h
37909 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37910 }
37911
37912 static struct access_method smart4_access = {
37913 - smart4_submit_command,
37914 - smart4_intr_mask,
37915 - smart4_fifo_full,
37916 - smart4_intr_pending,
37917 - smart4_completed,
37918 + .submit_command = smart4_submit_command,
37919 + .set_intr_mask = smart4_intr_mask,
37920 + .fifo_full = smart4_fifo_full,
37921 + .intr_pending = smart4_intr_pending,
37922 + .command_completed = smart4_completed,
37923 };
37924
37925 /*
37926 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37927 }
37928
37929 static struct access_method smart2_access = {
37930 - smart2_submit_command,
37931 - smart2_intr_mask,
37932 - smart2_fifo_full,
37933 - smart2_intr_pending,
37934 - smart2_completed,
37935 + .submit_command = smart2_submit_command,
37936 + .set_intr_mask = smart2_intr_mask,
37937 + .fifo_full = smart2_fifo_full,
37938 + .intr_pending = smart2_intr_pending,
37939 + .command_completed = smart2_completed,
37940 };
37941
37942 /*
37943 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
37944 }
37945
37946 static struct access_method smart2e_access = {
37947 - smart2e_submit_command,
37948 - smart2e_intr_mask,
37949 - smart2e_fifo_full,
37950 - smart2e_intr_pending,
37951 - smart2e_completed,
37952 + .submit_command = smart2e_submit_command,
37953 + .set_intr_mask = smart2e_intr_mask,
37954 + .fifo_full = smart2e_fifo_full,
37955 + .intr_pending = smart2e_intr_pending,
37956 + .command_completed = smart2e_completed,
37957 };
37958
37959 /*
37960 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
37961 }
37962
37963 static struct access_method smart1_access = {
37964 - smart1_submit_command,
37965 - smart1_intr_mask,
37966 - smart1_fifo_full,
37967 - smart1_intr_pending,
37968 - smart1_completed,
37969 + .submit_command = smart1_submit_command,
37970 + .set_intr_mask = smart1_intr_mask,
37971 + .fifo_full = smart1_fifo_full,
37972 + .intr_pending = smart1_intr_pending,
37973 + .command_completed = smart1_completed,
37974 };
37975 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
37976 index f038dba..bb74c08 100644
37977 --- a/drivers/bluetooth/btwilink.c
37978 +++ b/drivers/bluetooth/btwilink.c
37979 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
37980
37981 static int bt_ti_probe(struct platform_device *pdev)
37982 {
37983 - static struct ti_st *hst;
37984 + struct ti_st *hst;
37985 struct hci_dev *hdev;
37986 int err;
37987
37988 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
37989 index 8a3aff7..d7538c2 100644
37990 --- a/drivers/cdrom/cdrom.c
37991 +++ b/drivers/cdrom/cdrom.c
37992 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
37993 ENSURE(reset, CDC_RESET);
37994 ENSURE(generic_packet, CDC_GENERIC_PACKET);
37995 cdi->mc_flags = 0;
37996 - cdo->n_minors = 0;
37997 cdi->options = CDO_USE_FFLAGS;
37998
37999 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38000 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38001 else
38002 cdi->cdda_method = CDDA_OLD;
38003
38004 - if (!cdo->generic_packet)
38005 - cdo->generic_packet = cdrom_dummy_generic_packet;
38006 + if (!cdo->generic_packet) {
38007 + pax_open_kernel();
38008 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38009 + pax_close_kernel();
38010 + }
38011
38012 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38013 mutex_lock(&cdrom_mutex);
38014 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38015 if (cdi->exit)
38016 cdi->exit(cdi);
38017
38018 - cdi->ops->n_minors--;
38019 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38020 }
38021
38022 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38023 */
38024 nr = nframes;
38025 do {
38026 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38027 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38028 if (cgc.buffer)
38029 break;
38030
38031 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38032 struct cdrom_device_info *cdi;
38033 int ret;
38034
38035 - ret = scnprintf(info + *pos, max_size - *pos, header);
38036 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38037 if (!ret)
38038 return 1;
38039
38040 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38041 index 51e75ad..39c4c76 100644
38042 --- a/drivers/cdrom/gdrom.c
38043 +++ b/drivers/cdrom/gdrom.c
38044 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38045 .audio_ioctl = gdrom_audio_ioctl,
38046 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38047 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38048 - .n_minors = 1,
38049 };
38050
38051 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38052 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38053 index 1386749..5430258 100644
38054 --- a/drivers/char/Kconfig
38055 +++ b/drivers/char/Kconfig
38056 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38057
38058 config DEVKMEM
38059 bool "/dev/kmem virtual device support"
38060 - default y
38061 + default n
38062 + depends on !GRKERNSEC_KMEM
38063 help
38064 Say Y here if you want to support the /dev/kmem device. The
38065 /dev/kmem device is rarely used, but can be used for certain
38066 @@ -577,6 +578,7 @@ config DEVPORT
38067 bool
38068 depends on !M68K
38069 depends on ISA || PCI
38070 + depends on !GRKERNSEC_KMEM
38071 default y
38072
38073 source "drivers/s390/char/Kconfig"
38074 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38075 index a48e05b..6bac831 100644
38076 --- a/drivers/char/agp/compat_ioctl.c
38077 +++ b/drivers/char/agp/compat_ioctl.c
38078 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38079 return -ENOMEM;
38080 }
38081
38082 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38083 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38084 sizeof(*usegment) * ureserve.seg_count)) {
38085 kfree(usegment);
38086 kfree(ksegment);
38087 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38088 index 1b19239..b87b143 100644
38089 --- a/drivers/char/agp/frontend.c
38090 +++ b/drivers/char/agp/frontend.c
38091 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38092 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38093 return -EFAULT;
38094
38095 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38096 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38097 return -EFAULT;
38098
38099 client = agp_find_client_by_pid(reserve.pid);
38100 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38101 if (segment == NULL)
38102 return -ENOMEM;
38103
38104 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38105 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38106 sizeof(struct agp_segment) * reserve.seg_count)) {
38107 kfree(segment);
38108 return -EFAULT;
38109 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38110 index 4f94375..413694e 100644
38111 --- a/drivers/char/genrtc.c
38112 +++ b/drivers/char/genrtc.c
38113 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38114 switch (cmd) {
38115
38116 case RTC_PLL_GET:
38117 + memset(&pll, 0, sizeof(pll));
38118 if (get_rtc_pll(&pll))
38119 return -EINVAL;
38120 else
38121 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38122 index d5d4cd8..22d561d 100644
38123 --- a/drivers/char/hpet.c
38124 +++ b/drivers/char/hpet.c
38125 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38126 }
38127
38128 static int
38129 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38130 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38131 struct hpet_info *info)
38132 {
38133 struct hpet_timer __iomem *timer;
38134 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38135 index 86fe45c..c0ea948 100644
38136 --- a/drivers/char/hw_random/intel-rng.c
38137 +++ b/drivers/char/hw_random/intel-rng.c
38138 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38139
38140 if (no_fwh_detect)
38141 return -ENODEV;
38142 - printk(warning);
38143 + printk("%s", warning);
38144 return -EBUSY;
38145 }
38146
38147 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38148 index ec4e10f..f2a763b 100644
38149 --- a/drivers/char/ipmi/ipmi_msghandler.c
38150 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38151 @@ -420,7 +420,7 @@ struct ipmi_smi {
38152 struct proc_dir_entry *proc_dir;
38153 char proc_dir_name[10];
38154
38155 - atomic_t stats[IPMI_NUM_STATS];
38156 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38157
38158 /*
38159 * run_to_completion duplicate of smb_info, smi_info
38160 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38161
38162
38163 #define ipmi_inc_stat(intf, stat) \
38164 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38165 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38166 #define ipmi_get_stat(intf, stat) \
38167 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38168 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38169
38170 static int is_lan_addr(struct ipmi_addr *addr)
38171 {
38172 @@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38173 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38174 init_waitqueue_head(&intf->waitq);
38175 for (i = 0; i < IPMI_NUM_STATS; i++)
38176 - atomic_set(&intf->stats[i], 0);
38177 + atomic_set_unchecked(&intf->stats[i], 0);
38178
38179 intf->proc_dir = NULL;
38180
38181 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38182 index 03f4189..e79f5e0 100644
38183 --- a/drivers/char/ipmi/ipmi_si_intf.c
38184 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38185 @@ -280,7 +280,7 @@ struct smi_info {
38186 unsigned char slave_addr;
38187
38188 /* Counters and things for the proc filesystem. */
38189 - atomic_t stats[SI_NUM_STATS];
38190 + atomic_unchecked_t stats[SI_NUM_STATS];
38191
38192 struct task_struct *thread;
38193
38194 @@ -289,9 +289,9 @@ struct smi_info {
38195 };
38196
38197 #define smi_inc_stat(smi, stat) \
38198 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38199 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38200 #define smi_get_stat(smi, stat) \
38201 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38202 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38203
38204 #define SI_MAX_PARMS 4
38205
38206 @@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
38207 atomic_set(&new_smi->req_events, 0);
38208 new_smi->run_to_completion = 0;
38209 for (i = 0; i < SI_NUM_STATS; i++)
38210 - atomic_set(&new_smi->stats[i], 0);
38211 + atomic_set_unchecked(&new_smi->stats[i], 0);
38212
38213 new_smi->interrupt_disabled = 1;
38214 atomic_set(&new_smi->stop_operation, 0);
38215 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38216 index 92c5937..1be4e4d 100644
38217 --- a/drivers/char/mem.c
38218 +++ b/drivers/char/mem.c
38219 @@ -18,6 +18,7 @@
38220 #include <linux/raw.h>
38221 #include <linux/tty.h>
38222 #include <linux/capability.h>
38223 +#include <linux/security.h>
38224 #include <linux/ptrace.h>
38225 #include <linux/device.h>
38226 #include <linux/highmem.h>
38227 @@ -36,6 +37,10 @@
38228
38229 #define DEVPORT_MINOR 4
38230
38231 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38232 +extern const struct file_operations grsec_fops;
38233 +#endif
38234 +
38235 static inline unsigned long size_inside_page(unsigned long start,
38236 unsigned long size)
38237 {
38238 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38239
38240 while (cursor < to) {
38241 if (!devmem_is_allowed(pfn)) {
38242 +#ifdef CONFIG_GRKERNSEC_KMEM
38243 + gr_handle_mem_readwrite(from, to);
38244 +#else
38245 printk(KERN_INFO
38246 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38247 current->comm, from, to);
38248 +#endif
38249 return 0;
38250 }
38251 cursor += PAGE_SIZE;
38252 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38253 }
38254 return 1;
38255 }
38256 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38257 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38258 +{
38259 + return 0;
38260 +}
38261 #else
38262 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38263 {
38264 @@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38265
38266 while (count > 0) {
38267 unsigned long remaining;
38268 + char *temp;
38269
38270 sz = size_inside_page(p, count);
38271
38272 @@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38273 if (!ptr)
38274 return -EFAULT;
38275
38276 - remaining = copy_to_user(buf, ptr, sz);
38277 +#ifdef CONFIG_PAX_USERCOPY
38278 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38279 + if (!temp) {
38280 + unxlate_dev_mem_ptr(p, ptr);
38281 + return -ENOMEM;
38282 + }
38283 + memcpy(temp, ptr, sz);
38284 +#else
38285 + temp = ptr;
38286 +#endif
38287 +
38288 + remaining = copy_to_user(buf, temp, sz);
38289 +
38290 +#ifdef CONFIG_PAX_USERCOPY
38291 + kfree(temp);
38292 +#endif
38293 +
38294 unxlate_dev_mem_ptr(p, ptr);
38295 if (remaining)
38296 return -EFAULT;
38297 @@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38298 size_t count, loff_t *ppos)
38299 {
38300 unsigned long p = *ppos;
38301 - ssize_t low_count, read, sz;
38302 + ssize_t low_count, read, sz, err = 0;
38303 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38304 - int err = 0;
38305
38306 read = 0;
38307 if (p < (unsigned long) high_memory) {
38308 @@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38309 }
38310 #endif
38311 while (low_count > 0) {
38312 + char *temp;
38313 +
38314 sz = size_inside_page(p, low_count);
38315
38316 /*
38317 @@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38318 */
38319 kbuf = xlate_dev_kmem_ptr((char *)p);
38320
38321 - if (copy_to_user(buf, kbuf, sz))
38322 +#ifdef CONFIG_PAX_USERCOPY
38323 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38324 + if (!temp)
38325 + return -ENOMEM;
38326 + memcpy(temp, kbuf, sz);
38327 +#else
38328 + temp = kbuf;
38329 +#endif
38330 +
38331 + err = copy_to_user(buf, temp, sz);
38332 +
38333 +#ifdef CONFIG_PAX_USERCOPY
38334 + kfree(temp);
38335 +#endif
38336 +
38337 + if (err)
38338 return -EFAULT;
38339 buf += sz;
38340 p += sz;
38341 @@ -821,6 +868,9 @@ static const struct memdev {
38342 #ifdef CONFIG_PRINTK
38343 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38344 #endif
38345 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38346 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38347 +#endif
38348 };
38349
38350 static int memory_open(struct inode *inode, struct file *filp)
38351 @@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
38352 continue;
38353
38354 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38355 - NULL, devlist[minor].name);
38356 + NULL, "%s", devlist[minor].name);
38357 }
38358
38359 return tty_init();
38360 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38361 index 9df78e2..01ba9ae 100644
38362 --- a/drivers/char/nvram.c
38363 +++ b/drivers/char/nvram.c
38364 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38365
38366 spin_unlock_irq(&rtc_lock);
38367
38368 - if (copy_to_user(buf, contents, tmp - contents))
38369 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38370 return -EFAULT;
38371
38372 *ppos = i;
38373 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38374 index 8320abd..ec48108 100644
38375 --- a/drivers/char/pcmcia/synclink_cs.c
38376 +++ b/drivers/char/pcmcia/synclink_cs.c
38377 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38378
38379 if (debug_level >= DEBUG_LEVEL_INFO)
38380 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38381 - __FILE__, __LINE__, info->device_name, port->count);
38382 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38383
38384 - WARN_ON(!port->count);
38385 + WARN_ON(!atomic_read(&port->count));
38386
38387 if (tty_port_close_start(port, tty, filp) == 0)
38388 goto cleanup;
38389 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38390 cleanup:
38391 if (debug_level >= DEBUG_LEVEL_INFO)
38392 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38393 - tty->driver->name, port->count);
38394 + tty->driver->name, atomic_read(&port->count));
38395 }
38396
38397 /* Wait until the transmitter is empty.
38398 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38399
38400 if (debug_level >= DEBUG_LEVEL_INFO)
38401 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38402 - __FILE__, __LINE__, tty->driver->name, port->count);
38403 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38404
38405 /* If port is closing, signal caller to try again */
38406 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38407 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38408 goto cleanup;
38409 }
38410 spin_lock(&port->lock);
38411 - port->count++;
38412 + atomic_inc(&port->count);
38413 spin_unlock(&port->lock);
38414 spin_unlock_irqrestore(&info->netlock, flags);
38415
38416 - if (port->count == 1) {
38417 + if (atomic_read(&port->count) == 1) {
38418 /* 1st open on this device, init hardware */
38419 retval = startup(info, tty);
38420 if (retval < 0)
38421 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38422 unsigned short new_crctype;
38423
38424 /* return error if TTY interface open */
38425 - if (info->port.count)
38426 + if (atomic_read(&info->port.count))
38427 return -EBUSY;
38428
38429 switch (encoding)
38430 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38431
38432 /* arbitrate between network and tty opens */
38433 spin_lock_irqsave(&info->netlock, flags);
38434 - if (info->port.count != 0 || info->netcount != 0) {
38435 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38436 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38437 spin_unlock_irqrestore(&info->netlock, flags);
38438 return -EBUSY;
38439 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38440 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38441
38442 /* return error if TTY interface open */
38443 - if (info->port.count)
38444 + if (atomic_read(&info->port.count))
38445 return -EBUSY;
38446
38447 if (cmd != SIOCWANDEV)
38448 diff --git a/drivers/char/random.c b/drivers/char/random.c
38449 index 429b75b..a7f4145 100644
38450 --- a/drivers/char/random.c
38451 +++ b/drivers/char/random.c
38452 @@ -270,10 +270,17 @@
38453 /*
38454 * Configuration information
38455 */
38456 +#ifdef CONFIG_GRKERNSEC_RANDNET
38457 +#define INPUT_POOL_SHIFT 14
38458 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38459 +#define OUTPUT_POOL_SHIFT 12
38460 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38461 +#else
38462 #define INPUT_POOL_SHIFT 12
38463 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38464 #define OUTPUT_POOL_SHIFT 10
38465 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38466 +#endif
38467 #define SEC_XFER_SIZE 512
38468 #define EXTRACT_SIZE 10
38469
38470 @@ -284,9 +291,6 @@
38471 /*
38472 * To allow fractional bits to be tracked, the entropy_count field is
38473 * denominated in units of 1/8th bits.
38474 - *
38475 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38476 - * credit_entropy_bits() needs to be 64 bits wide.
38477 */
38478 #define ENTROPY_SHIFT 3
38479 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38480 @@ -361,12 +365,19 @@ static struct poolinfo {
38481 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38482 int tap1, tap2, tap3, tap4, tap5;
38483 } poolinfo_table[] = {
38484 +#ifdef CONFIG_GRKERNSEC_RANDNET
38485 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38486 + { S(512), 411, 308, 208, 104, 1 },
38487 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38488 + { S(128), 104, 76, 51, 25, 1 },
38489 +#else
38490 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38491 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38492 { S(128), 104, 76, 51, 25, 1 },
38493 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38494 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38495 { S(32), 26, 19, 14, 7, 1 },
38496 +#endif
38497 #if 0
38498 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38499 { S(2048), 1638, 1231, 819, 411, 1 },
38500 @@ -433,9 +444,9 @@ struct entropy_store {
38501 };
38502
38503 static void push_to_pool(struct work_struct *work);
38504 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38505 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38506 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38507 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38508 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38509 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38510
38511 static struct entropy_store input_pool = {
38512 .poolinfo = &poolinfo_table[0],
38513 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38514 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38515 }
38516
38517 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38518 - ACCESS_ONCE(r->add_ptr) = i;
38519 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38520 + ACCESS_ONCE_RW(r->add_ptr) = i;
38521 smp_wmb();
38522
38523 if (out)
38524 @@ -632,7 +643,7 @@ retry:
38525 /* The +2 corresponds to the /4 in the denominator */
38526
38527 do {
38528 - unsigned int anfrac = min(pnfrac, pool_size/2);
38529 + u64 anfrac = min(pnfrac, pool_size/2);
38530 unsigned int add =
38531 ((pool_size - entropy_count)*anfrac*3) >> s;
38532
38533 @@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38534
38535 extract_buf(r, tmp);
38536 i = min_t(int, nbytes, EXTRACT_SIZE);
38537 - if (copy_to_user(buf, tmp, i)) {
38538 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38539 ret = -EFAULT;
38540 break;
38541 }
38542 @@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38543 #include <linux/sysctl.h>
38544
38545 static int min_read_thresh = 8, min_write_thresh;
38546 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
38547 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38548 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38549 static char sysctl_bootid[16];
38550
38551 @@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38552 static int proc_do_uuid(struct ctl_table *table, int write,
38553 void __user *buffer, size_t *lenp, loff_t *ppos)
38554 {
38555 - struct ctl_table fake_table;
38556 + ctl_table_no_const fake_table;
38557 unsigned char buf[64], tmp_uuid[16], *uuid;
38558
38559 uuid = table->data;
38560 @@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38561 static int proc_do_entropy(ctl_table *table, int write,
38562 void __user *buffer, size_t *lenp, loff_t *ppos)
38563 {
38564 - ctl_table fake_table;
38565 + ctl_table_no_const fake_table;
38566 int entropy_count;
38567
38568 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38569 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38570 index 7cc1fe22..b602d6b 100644
38571 --- a/drivers/char/sonypi.c
38572 +++ b/drivers/char/sonypi.c
38573 @@ -54,6 +54,7 @@
38574
38575 #include <asm/uaccess.h>
38576 #include <asm/io.h>
38577 +#include <asm/local.h>
38578
38579 #include <linux/sonypi.h>
38580
38581 @@ -490,7 +491,7 @@ static struct sonypi_device {
38582 spinlock_t fifo_lock;
38583 wait_queue_head_t fifo_proc_list;
38584 struct fasync_struct *fifo_async;
38585 - int open_count;
38586 + local_t open_count;
38587 int model;
38588 struct input_dev *input_jog_dev;
38589 struct input_dev *input_key_dev;
38590 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38591 static int sonypi_misc_release(struct inode *inode, struct file *file)
38592 {
38593 mutex_lock(&sonypi_device.lock);
38594 - sonypi_device.open_count--;
38595 + local_dec(&sonypi_device.open_count);
38596 mutex_unlock(&sonypi_device.lock);
38597 return 0;
38598 }
38599 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38600 {
38601 mutex_lock(&sonypi_device.lock);
38602 /* Flush input queue on first open */
38603 - if (!sonypi_device.open_count)
38604 + if (!local_read(&sonypi_device.open_count))
38605 kfifo_reset(&sonypi_device.fifo);
38606 - sonypi_device.open_count++;
38607 + local_inc(&sonypi_device.open_count);
38608 mutex_unlock(&sonypi_device.lock);
38609
38610 return 0;
38611 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38612 index b9a57fa..5bb9e38 100644
38613 --- a/drivers/char/tpm/tpm_acpi.c
38614 +++ b/drivers/char/tpm/tpm_acpi.c
38615 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38616 virt = acpi_os_map_memory(start, len);
38617 if (!virt) {
38618 kfree(log->bios_event_log);
38619 + log->bios_event_log = NULL;
38620 printk("%s: ERROR - Unable to map memory\n", __func__);
38621 return -EIO;
38622 }
38623
38624 - memcpy_fromio(log->bios_event_log, virt, len);
38625 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38626
38627 acpi_os_unmap_memory(virt, len);
38628 return 0;
38629 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38630 index 59f7cb2..bac8b6d 100644
38631 --- a/drivers/char/tpm/tpm_eventlog.c
38632 +++ b/drivers/char/tpm/tpm_eventlog.c
38633 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38634 event = addr;
38635
38636 if ((event->event_type == 0 && event->event_size == 0) ||
38637 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38638 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38639 return NULL;
38640
38641 return addr;
38642 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38643 return NULL;
38644
38645 if ((event->event_type == 0 && event->event_size == 0) ||
38646 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38647 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38648 return NULL;
38649
38650 (*pos)++;
38651 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38652 int i;
38653
38654 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38655 - seq_putc(m, data[i]);
38656 + if (!seq_putc(m, data[i]))
38657 + return -EFAULT;
38658
38659 return 0;
38660 }
38661 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38662 index 6928d09..ff6abe8 100644
38663 --- a/drivers/char/virtio_console.c
38664 +++ b/drivers/char/virtio_console.c
38665 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38666 if (to_user) {
38667 ssize_t ret;
38668
38669 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38670 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38671 if (ret)
38672 return -EFAULT;
38673 } else {
38674 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38675 if (!port_has_data(port) && !port->host_connected)
38676 return 0;
38677
38678 - return fill_readbuf(port, ubuf, count, true);
38679 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38680 }
38681
38682 static int wait_port_writable(struct port *port, bool nonblock)
38683 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38684 index 57a078e..c17cde8 100644
38685 --- a/drivers/clk/clk-composite.c
38686 +++ b/drivers/clk/clk-composite.c
38687 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38688 struct clk *clk;
38689 struct clk_init_data init;
38690 struct clk_composite *composite;
38691 - struct clk_ops *clk_composite_ops;
38692 + clk_ops_no_const *clk_composite_ops;
38693
38694 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38695 if (!composite) {
38696 diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38697 index 5983a26..65d5f46 100644
38698 --- a/drivers/clk/socfpga/clk.c
38699 +++ b/drivers/clk/socfpga/clk.c
38700 @@ -22,6 +22,7 @@
38701 #include <linux/clk-provider.h>
38702 #include <linux/io.h>
38703 #include <linux/of.h>
38704 +#include <asm/pgtable.h>
38705
38706 /* Clock Manager offsets */
38707 #define CLKMGR_CTRL 0x0
38708 @@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38709 streq(clk_name, "periph_pll") ||
38710 streq(clk_name, "sdram_pll")) {
38711 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38712 - clk_pll_ops.enable = clk_gate_ops.enable;
38713 - clk_pll_ops.disable = clk_gate_ops.disable;
38714 + pax_open_kernel();
38715 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38716 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38717 + pax_close_kernel();
38718 }
38719
38720 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38721 @@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38722 return parent_rate / div;
38723 }
38724
38725 -static struct clk_ops gateclk_ops = {
38726 +static clk_ops_no_const gateclk_ops __read_only = {
38727 .recalc_rate = socfpga_clk_recalc_rate,
38728 .get_parent = socfpga_clk_get_parent,
38729 .set_parent = socfpga_clk_set_parent,
38730 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38731 index 18448a7..d5fad43 100644
38732 --- a/drivers/cpufreq/acpi-cpufreq.c
38733 +++ b/drivers/cpufreq/acpi-cpufreq.c
38734 @@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38735 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38736 per_cpu(acfreq_data, cpu) = data;
38737
38738 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38739 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38740 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38741 + pax_open_kernel();
38742 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38743 + pax_close_kernel();
38744 + }
38745
38746 result = acpi_processor_register_performance(data->acpi_data, cpu);
38747 if (result)
38748 @@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38749 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38750 break;
38751 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38752 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38753 + pax_open_kernel();
38754 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38755 + pax_close_kernel();
38756 break;
38757 default:
38758 break;
38759 @@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
38760 if (!msrs)
38761 return;
38762
38763 - acpi_cpufreq_driver.boost_supported = true;
38764 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
38765 + pax_open_kernel();
38766 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
38767 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
38768 + pax_close_kernel();
38769 get_online_cpus();
38770
38771 /* Force all MSRs to the same value */
38772 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38773 index 199b52b..e3503bb 100644
38774 --- a/drivers/cpufreq/cpufreq.c
38775 +++ b/drivers/cpufreq/cpufreq.c
38776 @@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38777 #endif
38778
38779 mutex_lock(&cpufreq_governor_mutex);
38780 - list_del(&governor->governor_list);
38781 + pax_list_del(&governor->governor_list);
38782 mutex_unlock(&cpufreq_governor_mutex);
38783 return;
38784 }
38785 @@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38786 return NOTIFY_OK;
38787 }
38788
38789 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
38790 +static struct notifier_block cpufreq_cpu_notifier = {
38791 .notifier_call = cpufreq_cpu_callback,
38792 };
38793
38794 @@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
38795 return 0;
38796
38797 write_lock_irqsave(&cpufreq_driver_lock, flags);
38798 - cpufreq_driver->boost_enabled = state;
38799 + pax_open_kernel();
38800 + *(bool *)&cpufreq_driver->boost_enabled = state;
38801 + pax_close_kernel();
38802 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38803
38804 ret = cpufreq_driver->set_boost(state);
38805 if (ret) {
38806 write_lock_irqsave(&cpufreq_driver_lock, flags);
38807 - cpufreq_driver->boost_enabled = !state;
38808 + pax_open_kernel();
38809 + *(bool *)&cpufreq_driver->boost_enabled = !state;
38810 + pax_close_kernel();
38811 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
38812
38813 pr_err("%s: Cannot %s BOOST\n", __func__,
38814 @@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38815
38816 pr_debug("trying to register driver %s\n", driver_data->name);
38817
38818 - if (driver_data->setpolicy)
38819 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
38820 + if (driver_data->setpolicy) {
38821 + pax_open_kernel();
38822 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38823 + pax_close_kernel();
38824 + }
38825
38826 write_lock_irqsave(&cpufreq_driver_lock, flags);
38827 if (cpufreq_driver) {
38828 @@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38829 * Check if driver provides function to enable boost -
38830 * if not, use cpufreq_boost_set_sw as default
38831 */
38832 - if (!cpufreq_driver->set_boost)
38833 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38834 + if (!cpufreq_driver->set_boost) {
38835 + pax_open_kernel();
38836 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
38837 + pax_close_kernel();
38838 + }
38839
38840 ret = cpufreq_sysfs_create_file(&boost.attr);
38841 if (ret) {
38842 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38843 index ba43991..23858ffb 100644
38844 --- a/drivers/cpufreq/cpufreq_governor.c
38845 +++ b/drivers/cpufreq/cpufreq_governor.c
38846 @@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38847 struct dbs_data *dbs_data;
38848 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38849 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38850 - struct od_ops *od_ops = NULL;
38851 + const struct od_ops *od_ops = NULL;
38852 struct od_dbs_tuners *od_tuners = NULL;
38853 struct cs_dbs_tuners *cs_tuners = NULL;
38854 struct cpu_dbs_common_info *cpu_cdbs;
38855 @@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38856
38857 if ((cdata->governor == GOV_CONSERVATIVE) &&
38858 (!policy->governor->initialized)) {
38859 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38860 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38861
38862 cpufreq_register_notifier(cs_ops->notifier_block,
38863 CPUFREQ_TRANSITION_NOTIFIER);
38864 @@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38865
38866 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38867 (policy->governor->initialized == 1)) {
38868 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38869 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38870
38871 cpufreq_unregister_notifier(cs_ops->notifier_block,
38872 CPUFREQ_TRANSITION_NOTIFIER);
38873 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38874 index bfb9ae1..e1d3a7e 100644
38875 --- a/drivers/cpufreq/cpufreq_governor.h
38876 +++ b/drivers/cpufreq/cpufreq_governor.h
38877 @@ -205,7 +205,7 @@ struct common_dbs_data {
38878 void (*exit)(struct dbs_data *dbs_data);
38879
38880 /* Governor specific ops, see below */
38881 - void *gov_ops;
38882 + const void *gov_ops;
38883 };
38884
38885 /* Governor Per policy data */
38886 @@ -225,7 +225,7 @@ struct od_ops {
38887 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38888 unsigned int freq_next, unsigned int relation);
38889 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38890 -};
38891 +} __no_const;
38892
38893 struct cs_ops {
38894 struct notifier_block *notifier_block;
38895 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38896 index 18d4091..434be15 100644
38897 --- a/drivers/cpufreq/cpufreq_ondemand.c
38898 +++ b/drivers/cpufreq/cpufreq_ondemand.c
38899 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38900
38901 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38902
38903 -static struct od_ops od_ops = {
38904 +static struct od_ops od_ops __read_only = {
38905 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38906 .powersave_bias_target = generic_powersave_bias_target,
38907 .freq_increase = dbs_freq_increase,
38908 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38909 (struct cpufreq_policy *, unsigned int, unsigned int),
38910 unsigned int powersave_bias)
38911 {
38912 - od_ops.powersave_bias_target = f;
38913 + pax_open_kernel();
38914 + *(void **)&od_ops.powersave_bias_target = f;
38915 + pax_close_kernel();
38916 od_set_powersave_bias(powersave_bias);
38917 }
38918 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38919
38920 void od_unregister_powersave_bias_handler(void)
38921 {
38922 - od_ops.powersave_bias_target = generic_powersave_bias_target;
38923 + pax_open_kernel();
38924 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38925 + pax_close_kernel();
38926 od_set_powersave_bias(0);
38927 }
38928 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38929 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38930 index 2cd36b9..8f07fae 100644
38931 --- a/drivers/cpufreq/intel_pstate.c
38932 +++ b/drivers/cpufreq/intel_pstate.c
38933 @@ -124,10 +124,10 @@ struct pstate_funcs {
38934 struct cpu_defaults {
38935 struct pstate_adjust_policy pid_policy;
38936 struct pstate_funcs funcs;
38937 -};
38938 +} __do_const;
38939
38940 static struct pstate_adjust_policy pid_params;
38941 -static struct pstate_funcs pstate_funcs;
38942 +static struct pstate_funcs *pstate_funcs;
38943
38944 struct perf_limits {
38945 int no_turbo;
38946 @@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38947
38948 cpu->pstate.current_pstate = pstate;
38949
38950 - pstate_funcs.set(cpu, pstate);
38951 + pstate_funcs->set(cpu, pstate);
38952 }
38953
38954 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
38955 @@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
38956 {
38957 sprintf(cpu->name, "Intel 2nd generation core");
38958
38959 - cpu->pstate.min_pstate = pstate_funcs.get_min();
38960 - cpu->pstate.max_pstate = pstate_funcs.get_max();
38961 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
38962 + cpu->pstate.min_pstate = pstate_funcs->get_min();
38963 + cpu->pstate.max_pstate = pstate_funcs->get_max();
38964 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
38965
38966 - if (pstate_funcs.get_vid)
38967 - pstate_funcs.get_vid(cpu);
38968 + if (pstate_funcs->get_vid)
38969 + pstate_funcs->get_vid(cpu);
38970
38971 /*
38972 * goto max pstate so we don't slow up boot if we are built-in if we are
38973 @@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
38974 rdmsrl(MSR_IA32_APERF, aperf);
38975 rdmsrl(MSR_IA32_MPERF, mperf);
38976
38977 - if (!pstate_funcs.get_max() ||
38978 - !pstate_funcs.get_min() ||
38979 - !pstate_funcs.get_turbo())
38980 + if (!pstate_funcs->get_max() ||
38981 + !pstate_funcs->get_min() ||
38982 + !pstate_funcs->get_turbo())
38983 return -ENODEV;
38984
38985 rdmsrl(MSR_IA32_APERF, tmp);
38986 @@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
38987 return 0;
38988 }
38989
38990 -static void copy_pid_params(struct pstate_adjust_policy *policy)
38991 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
38992 {
38993 pid_params.sample_rate_ms = policy->sample_rate_ms;
38994 pid_params.p_gain_pct = policy->p_gain_pct;
38995 @@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
38996
38997 static void copy_cpu_funcs(struct pstate_funcs *funcs)
38998 {
38999 - pstate_funcs.get_max = funcs->get_max;
39000 - pstate_funcs.get_min = funcs->get_min;
39001 - pstate_funcs.get_turbo = funcs->get_turbo;
39002 - pstate_funcs.set = funcs->set;
39003 - pstate_funcs.get_vid = funcs->get_vid;
39004 + pstate_funcs = funcs;
39005 }
39006
39007 #if IS_ENABLED(CONFIG_ACPI)
39008 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39009 index 3d1cba9..0ab21d2 100644
39010 --- a/drivers/cpufreq/p4-clockmod.c
39011 +++ b/drivers/cpufreq/p4-clockmod.c
39012 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39013 case 0x0F: /* Core Duo */
39014 case 0x16: /* Celeron Core */
39015 case 0x1C: /* Atom */
39016 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39017 + pax_open_kernel();
39018 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39019 + pax_close_kernel();
39020 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39021 case 0x0D: /* Pentium M (Dothan) */
39022 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39023 + pax_open_kernel();
39024 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39025 + pax_close_kernel();
39026 /* fall through */
39027 case 0x09: /* Pentium M (Banias) */
39028 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39029 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39030
39031 /* on P-4s, the TSC runs with constant frequency independent whether
39032 * throttling is active or not. */
39033 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39034 + pax_open_kernel();
39035 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39036 + pax_close_kernel();
39037
39038 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39039 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39040 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39041 index 724ffbd..ad83692 100644
39042 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39043 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39044 @@ -18,14 +18,12 @@
39045 #include <asm/head.h>
39046 #include <asm/timer.h>
39047
39048 -static struct cpufreq_driver *cpufreq_us3_driver;
39049 -
39050 struct us3_freq_percpu_info {
39051 struct cpufreq_frequency_table table[4];
39052 };
39053
39054 /* Indexed by cpu number. */
39055 -static struct us3_freq_percpu_info *us3_freq_table;
39056 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39057
39058 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39059 * in the Safari config register.
39060 @@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39061
39062 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39063 {
39064 - if (cpufreq_us3_driver) {
39065 - cpufreq_frequency_table_put_attr(policy->cpu);
39066 - us3_freq_target(policy, 0);
39067 - }
39068 + cpufreq_frequency_table_put_attr(policy->cpu);
39069 + us3_freq_target(policy, 0);
39070
39071 return 0;
39072 }
39073
39074 +static int __init us3_freq_init(void);
39075 +static void __exit us3_freq_exit(void);
39076 +
39077 +static struct cpufreq_driver cpufreq_us3_driver = {
39078 + .init = us3_freq_cpu_init,
39079 + .verify = cpufreq_generic_frequency_table_verify,
39080 + .target_index = us3_freq_target,
39081 + .get = us3_freq_get,
39082 + .exit = us3_freq_cpu_exit,
39083 + .owner = THIS_MODULE,
39084 + .name = "UltraSPARC-III",
39085 +
39086 +};
39087 +
39088 static int __init us3_freq_init(void)
39089 {
39090 unsigned long manuf, impl, ver;
39091 @@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39092 (impl == CHEETAH_IMPL ||
39093 impl == CHEETAH_PLUS_IMPL ||
39094 impl == JAGUAR_IMPL ||
39095 - impl == PANTHER_IMPL)) {
39096 - struct cpufreq_driver *driver;
39097 -
39098 - ret = -ENOMEM;
39099 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39100 - if (!driver)
39101 - goto err_out;
39102 -
39103 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39104 - GFP_KERNEL);
39105 - if (!us3_freq_table)
39106 - goto err_out;
39107 -
39108 - driver->init = us3_freq_cpu_init;
39109 - driver->verify = cpufreq_generic_frequency_table_verify;
39110 - driver->target_index = us3_freq_target;
39111 - driver->get = us3_freq_get;
39112 - driver->exit = us3_freq_cpu_exit;
39113 - strcpy(driver->name, "UltraSPARC-III");
39114 -
39115 - cpufreq_us3_driver = driver;
39116 - ret = cpufreq_register_driver(driver);
39117 - if (ret)
39118 - goto err_out;
39119 -
39120 - return 0;
39121 -
39122 -err_out:
39123 - if (driver) {
39124 - kfree(driver);
39125 - cpufreq_us3_driver = NULL;
39126 - }
39127 - kfree(us3_freq_table);
39128 - us3_freq_table = NULL;
39129 - return ret;
39130 - }
39131 + impl == PANTHER_IMPL))
39132 + return cpufreq_register_driver(&cpufreq_us3_driver);
39133
39134 return -ENODEV;
39135 }
39136
39137 static void __exit us3_freq_exit(void)
39138 {
39139 - if (cpufreq_us3_driver) {
39140 - cpufreq_unregister_driver(cpufreq_us3_driver);
39141 - kfree(cpufreq_us3_driver);
39142 - cpufreq_us3_driver = NULL;
39143 - kfree(us3_freq_table);
39144 - us3_freq_table = NULL;
39145 - }
39146 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39147 }
39148
39149 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39150 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39151 index 4e1daca..e707b61 100644
39152 --- a/drivers/cpufreq/speedstep-centrino.c
39153 +++ b/drivers/cpufreq/speedstep-centrino.c
39154 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39155 !cpu_has(cpu, X86_FEATURE_EST))
39156 return -ENODEV;
39157
39158 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39159 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39160 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39161 + pax_open_kernel();
39162 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39163 + pax_close_kernel();
39164 + }
39165
39166 if (policy->cpu != 0)
39167 return -ENODEV;
39168 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39169 index 06dbe7c..c2c8671 100644
39170 --- a/drivers/cpuidle/driver.c
39171 +++ b/drivers/cpuidle/driver.c
39172 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39173
39174 static void poll_idle_init(struct cpuidle_driver *drv)
39175 {
39176 - struct cpuidle_state *state = &drv->states[0];
39177 + cpuidle_state_no_const *state = &drv->states[0];
39178
39179 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39180 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39181 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39182 index ca89412..a7b9c49 100644
39183 --- a/drivers/cpuidle/governor.c
39184 +++ b/drivers/cpuidle/governor.c
39185 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39186 mutex_lock(&cpuidle_lock);
39187 if (__cpuidle_find_governor(gov->name) == NULL) {
39188 ret = 0;
39189 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39190 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39191 if (!cpuidle_curr_governor ||
39192 cpuidle_curr_governor->rating < gov->rating)
39193 cpuidle_switch_governor(gov);
39194 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39195 index e918b6d..f87ea80 100644
39196 --- a/drivers/cpuidle/sysfs.c
39197 +++ b/drivers/cpuidle/sysfs.c
39198 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39199 NULL
39200 };
39201
39202 -static struct attribute_group cpuidle_attr_group = {
39203 +static attribute_group_no_const cpuidle_attr_group = {
39204 .attrs = cpuidle_default_attrs,
39205 .name = "cpuidle",
39206 };
39207 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39208 index 12fea3e..1e28f47 100644
39209 --- a/drivers/crypto/hifn_795x.c
39210 +++ b/drivers/crypto/hifn_795x.c
39211 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39212 MODULE_PARM_DESC(hifn_pll_ref,
39213 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39214
39215 -static atomic_t hifn_dev_number;
39216 +static atomic_unchecked_t hifn_dev_number;
39217
39218 #define ACRYPTO_OP_DECRYPT 0
39219 #define ACRYPTO_OP_ENCRYPT 1
39220 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39221 goto err_out_disable_pci_device;
39222
39223 snprintf(name, sizeof(name), "hifn%d",
39224 - atomic_inc_return(&hifn_dev_number)-1);
39225 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39226
39227 err = pci_request_regions(pdev, name);
39228 if (err)
39229 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39230 index a0b2f7e..1b6f028 100644
39231 --- a/drivers/devfreq/devfreq.c
39232 +++ b/drivers/devfreq/devfreq.c
39233 @@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39234 goto err_out;
39235 }
39236
39237 - list_add(&governor->node, &devfreq_governor_list);
39238 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39239
39240 list_for_each_entry(devfreq, &devfreq_list, node) {
39241 int ret = 0;
39242 @@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39243 }
39244 }
39245
39246 - list_del(&governor->node);
39247 + pax_list_del((struct list_head *)&governor->node);
39248 err_out:
39249 mutex_unlock(&devfreq_list_lock);
39250
39251 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39252 index 0d765c0..60b7480 100644
39253 --- a/drivers/dma/sh/shdmac.c
39254 +++ b/drivers/dma/sh/shdmac.c
39255 @@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39256 return ret;
39257 }
39258
39259 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39260 +static struct notifier_block sh_dmae_nmi_notifier = {
39261 .notifier_call = sh_dmae_nmi_handler,
39262
39263 /* Run before NMI debug handler and KGDB */
39264 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39265 index 592af5f..bb1d583 100644
39266 --- a/drivers/edac/edac_device.c
39267 +++ b/drivers/edac/edac_device.c
39268 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39269 */
39270 int edac_device_alloc_index(void)
39271 {
39272 - static atomic_t device_indexes = ATOMIC_INIT(0);
39273 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39274
39275 - return atomic_inc_return(&device_indexes) - 1;
39276 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39277 }
39278 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39279
39280 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39281 index b335c6a..db65b44 100644
39282 --- a/drivers/edac/edac_mc_sysfs.c
39283 +++ b/drivers/edac/edac_mc_sysfs.c
39284 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39285 struct dev_ch_attribute {
39286 struct device_attribute attr;
39287 int channel;
39288 -};
39289 +} __do_const;
39290
39291 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39292 struct dev_ch_attribute dev_attr_legacy_##_name = \
39293 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39294 }
39295
39296 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39297 + pax_open_kernel();
39298 if (mci->get_sdram_scrub_rate) {
39299 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39300 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39301 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39302 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39303 }
39304 if (mci->set_sdram_scrub_rate) {
39305 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39306 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39307 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39308 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39309 }
39310 + pax_close_kernel();
39311 err = device_create_file(&mci->dev,
39312 &dev_attr_sdram_scrub_rate);
39313 if (err) {
39314 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39315 index 2cf44b4d..6dd2dc7 100644
39316 --- a/drivers/edac/edac_pci.c
39317 +++ b/drivers/edac/edac_pci.c
39318 @@ -29,7 +29,7 @@
39319
39320 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39321 static LIST_HEAD(edac_pci_list);
39322 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39323 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39324
39325 /*
39326 * edac_pci_alloc_ctl_info
39327 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39328 */
39329 int edac_pci_alloc_index(void)
39330 {
39331 - return atomic_inc_return(&pci_indexes) - 1;
39332 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39333 }
39334 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39335
39336 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39337 index e8658e4..22746d6 100644
39338 --- a/drivers/edac/edac_pci_sysfs.c
39339 +++ b/drivers/edac/edac_pci_sysfs.c
39340 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39341 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39342 static int edac_pci_poll_msec = 1000; /* one second workq period */
39343
39344 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39345 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39346 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39347 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39348
39349 static struct kobject *edac_pci_top_main_kobj;
39350 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39351 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39352 void *value;
39353 ssize_t(*show) (void *, char *);
39354 ssize_t(*store) (void *, const char *, size_t);
39355 -};
39356 +} __do_const;
39357
39358 /* Set of show/store abstract level functions for PCI Parity object */
39359 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39360 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39361 edac_printk(KERN_CRIT, EDAC_PCI,
39362 "Signaled System Error on %s\n",
39363 pci_name(dev));
39364 - atomic_inc(&pci_nonparity_count);
39365 + atomic_inc_unchecked(&pci_nonparity_count);
39366 }
39367
39368 if (status & (PCI_STATUS_PARITY)) {
39369 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39370 "Master Data Parity Error on %s\n",
39371 pci_name(dev));
39372
39373 - atomic_inc(&pci_parity_count);
39374 + atomic_inc_unchecked(&pci_parity_count);
39375 }
39376
39377 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39378 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39379 "Detected Parity Error on %s\n",
39380 pci_name(dev));
39381
39382 - atomic_inc(&pci_parity_count);
39383 + atomic_inc_unchecked(&pci_parity_count);
39384 }
39385 }
39386
39387 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39388 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39389 "Signaled System Error on %s\n",
39390 pci_name(dev));
39391 - atomic_inc(&pci_nonparity_count);
39392 + atomic_inc_unchecked(&pci_nonparity_count);
39393 }
39394
39395 if (status & (PCI_STATUS_PARITY)) {
39396 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39397 "Master Data Parity Error on "
39398 "%s\n", pci_name(dev));
39399
39400 - atomic_inc(&pci_parity_count);
39401 + atomic_inc_unchecked(&pci_parity_count);
39402 }
39403
39404 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39405 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39406 "Detected Parity Error on %s\n",
39407 pci_name(dev));
39408
39409 - atomic_inc(&pci_parity_count);
39410 + atomic_inc_unchecked(&pci_parity_count);
39411 }
39412 }
39413 }
39414 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39415 if (!check_pci_errors)
39416 return;
39417
39418 - before_count = atomic_read(&pci_parity_count);
39419 + before_count = atomic_read_unchecked(&pci_parity_count);
39420
39421 /* scan all PCI devices looking for a Parity Error on devices and
39422 * bridges.
39423 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39424 /* Only if operator has selected panic on PCI Error */
39425 if (edac_pci_get_panic_on_pe()) {
39426 /* If the count is different 'after' from 'before' */
39427 - if (before_count != atomic_read(&pci_parity_count))
39428 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39429 panic("EDAC: PCI Parity Error");
39430 }
39431 }
39432 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39433 index 51b7e3a..aa8a3e8 100644
39434 --- a/drivers/edac/mce_amd.h
39435 +++ b/drivers/edac/mce_amd.h
39436 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39437 bool (*mc0_mce)(u16, u8);
39438 bool (*mc1_mce)(u16, u8);
39439 bool (*mc2_mce)(u16, u8);
39440 -};
39441 +} __no_const;
39442
39443 void amd_report_gart_errors(bool);
39444 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39445 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39446 index 57ea7f4..af06b76 100644
39447 --- a/drivers/firewire/core-card.c
39448 +++ b/drivers/firewire/core-card.c
39449 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39450 const struct fw_card_driver *driver,
39451 struct device *device)
39452 {
39453 - static atomic_t index = ATOMIC_INIT(-1);
39454 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39455
39456 - card->index = atomic_inc_return(&index);
39457 + card->index = atomic_inc_return_unchecked(&index);
39458 card->driver = driver;
39459 card->device = device;
39460 card->current_tlabel = 0;
39461 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39462
39463 void fw_core_remove_card(struct fw_card *card)
39464 {
39465 - struct fw_card_driver dummy_driver = dummy_driver_template;
39466 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39467
39468 card->driver->update_phy_reg(card, 4,
39469 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39470 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39471 index 2c6d5e1..a2cca6b 100644
39472 --- a/drivers/firewire/core-device.c
39473 +++ b/drivers/firewire/core-device.c
39474 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39475 struct config_rom_attribute {
39476 struct device_attribute attr;
39477 u32 key;
39478 -};
39479 +} __do_const;
39480
39481 static ssize_t show_immediate(struct device *dev,
39482 struct device_attribute *dattr, char *buf)
39483 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39484 index eb6935c..3cc2bfa 100644
39485 --- a/drivers/firewire/core-transaction.c
39486 +++ b/drivers/firewire/core-transaction.c
39487 @@ -38,6 +38,7 @@
39488 #include <linux/timer.h>
39489 #include <linux/types.h>
39490 #include <linux/workqueue.h>
39491 +#include <linux/sched.h>
39492
39493 #include <asm/byteorder.h>
39494
39495 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39496 index c98764a..551b520 100644
39497 --- a/drivers/firewire/core.h
39498 +++ b/drivers/firewire/core.h
39499 @@ -111,6 +111,7 @@ struct fw_card_driver {
39500
39501 int (*stop_iso)(struct fw_iso_context *ctx);
39502 };
39503 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39504
39505 void fw_card_initialize(struct fw_card *card,
39506 const struct fw_card_driver *driver, struct device *device);
39507 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39508 index 8db6632..9bbc8ca 100644
39509 --- a/drivers/firewire/ohci.c
39510 +++ b/drivers/firewire/ohci.c
39511 @@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39512 be32_to_cpu(ohci->next_header));
39513 }
39514
39515 +#ifndef CONFIG_GRKERNSEC
39516 if (param_remote_dma) {
39517 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39518 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39519 }
39520 +#endif
39521
39522 spin_unlock_irq(&ohci->lock);
39523
39524 @@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39525 unsigned long flags;
39526 int n, ret = 0;
39527
39528 +#ifndef CONFIG_GRKERNSEC
39529 if (param_remote_dma)
39530 return 0;
39531 +#endif
39532
39533 /*
39534 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39535 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39536 index 94a58a0..f5eba42 100644
39537 --- a/drivers/firmware/dmi-id.c
39538 +++ b/drivers/firmware/dmi-id.c
39539 @@ -16,7 +16,7 @@
39540 struct dmi_device_attribute{
39541 struct device_attribute dev_attr;
39542 int field;
39543 -};
39544 +} __do_const;
39545 #define to_dmi_dev_attr(_dev_attr) \
39546 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39547
39548 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39549 index 17afc51..0ef90cd 100644
39550 --- a/drivers/firmware/dmi_scan.c
39551 +++ b/drivers/firmware/dmi_scan.c
39552 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39553 if (buf == NULL)
39554 return -1;
39555
39556 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39557 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39558
39559 dmi_unmap(buf);
39560 return 0;
39561 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39562 index 1491dd4..aa910db 100644
39563 --- a/drivers/firmware/efi/cper.c
39564 +++ b/drivers/firmware/efi/cper.c
39565 @@ -41,12 +41,12 @@
39566 */
39567 u64 cper_next_record_id(void)
39568 {
39569 - static atomic64_t seq;
39570 + static atomic64_unchecked_t seq;
39571
39572 - if (!atomic64_read(&seq))
39573 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39574 + if (!atomic64_read_unchecked(&seq))
39575 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39576
39577 - return atomic64_inc_return(&seq);
39578 + return atomic64_inc_return_unchecked(&seq);
39579 }
39580 EXPORT_SYMBOL_GPL(cper_next_record_id);
39581
39582 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39583 index 4753bac..02861a2 100644
39584 --- a/drivers/firmware/efi/efi.c
39585 +++ b/drivers/firmware/efi/efi.c
39586 @@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39587 };
39588
39589 static struct efivars generic_efivars;
39590 -static struct efivar_operations generic_ops;
39591 +static efivar_operations_no_const generic_ops __read_only;
39592
39593 static int generic_ops_register(void)
39594 {
39595 - generic_ops.get_variable = efi.get_variable;
39596 - generic_ops.set_variable = efi.set_variable;
39597 - generic_ops.get_next_variable = efi.get_next_variable;
39598 - generic_ops.query_variable_store = efi_query_variable_store;
39599 + pax_open_kernel();
39600 + *(void **)&generic_ops.get_variable = efi.get_variable;
39601 + *(void **)&generic_ops.set_variable = efi.set_variable;
39602 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39603 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39604 + pax_close_kernel();
39605
39606 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39607 }
39608 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39609 index 3dc2482..7bd2f61 100644
39610 --- a/drivers/firmware/efi/efivars.c
39611 +++ b/drivers/firmware/efi/efivars.c
39612 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39613 static int
39614 create_efivars_bin_attributes(void)
39615 {
39616 - struct bin_attribute *attr;
39617 + bin_attribute_no_const *attr;
39618 int error;
39619
39620 /* new_var */
39621 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39622 index 2a90ba6..07f3733 100644
39623 --- a/drivers/firmware/google/memconsole.c
39624 +++ b/drivers/firmware/google/memconsole.c
39625 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39626 if (!found_memconsole())
39627 return -ENODEV;
39628
39629 - memconsole_bin_attr.size = memconsole_length;
39630 + pax_open_kernel();
39631 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39632 + pax_close_kernel();
39633
39634 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39635
39636 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39637 index 1e98a98..b444372 100644
39638 --- a/drivers/gpio/gpio-em.c
39639 +++ b/drivers/gpio/gpio-em.c
39640 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39641 struct em_gio_priv *p;
39642 struct resource *io[2], *irq[2];
39643 struct gpio_chip *gpio_chip;
39644 - struct irq_chip *irq_chip;
39645 + irq_chip_no_const *irq_chip;
39646 const char *name = dev_name(&pdev->dev);
39647 int ret;
39648
39649 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39650 index f5bf3c3..7baaa59 100644
39651 --- a/drivers/gpio/gpio-ich.c
39652 +++ b/drivers/gpio/gpio-ich.c
39653 @@ -71,7 +71,7 @@ struct ichx_desc {
39654 /* Some chipsets have quirks, let these use their own request/get */
39655 int (*request)(struct gpio_chip *chip, unsigned offset);
39656 int (*get)(struct gpio_chip *chip, unsigned offset);
39657 -};
39658 +} __do_const;
39659
39660 static struct {
39661 spinlock_t lock;
39662 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39663 index ca76ce7..68b384b 100644
39664 --- a/drivers/gpio/gpio-rcar.c
39665 +++ b/drivers/gpio/gpio-rcar.c
39666 @@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39667 struct gpio_rcar_priv *p;
39668 struct resource *io, *irq;
39669 struct gpio_chip *gpio_chip;
39670 - struct irq_chip *irq_chip;
39671 + irq_chip_no_const *irq_chip;
39672 const char *name = dev_name(&pdev->dev);
39673 int ret;
39674
39675 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39676 index 9902732..64b62dd 100644
39677 --- a/drivers/gpio/gpio-vr41xx.c
39678 +++ b/drivers/gpio/gpio-vr41xx.c
39679 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39680 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39681 maskl, pendl, maskh, pendh);
39682
39683 - atomic_inc(&irq_err_count);
39684 + atomic_inc_unchecked(&irq_err_count);
39685
39686 return -EINVAL;
39687 }
39688 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39689 index 3b7d32d..05c2f74 100644
39690 --- a/drivers/gpu/drm/drm_crtc.c
39691 +++ b/drivers/gpu/drm/drm_crtc.c
39692 @@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39693 goto done;
39694 }
39695
39696 - if (copy_to_user(&enum_ptr[copied].name,
39697 + if (copy_to_user(enum_ptr[copied].name,
39698 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39699 ret = -EFAULT;
39700 goto done;
39701 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39702 index 345be03..158368d 100644
39703 --- a/drivers/gpu/drm/drm_drv.c
39704 +++ b/drivers/gpu/drm/drm_drv.c
39705 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39706 /**
39707 * Copy and IOCTL return string to user space
39708 */
39709 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39710 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39711 {
39712 int len;
39713
39714 @@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39715 struct drm_file *file_priv = filp->private_data;
39716 struct drm_device *dev;
39717 const struct drm_ioctl_desc *ioctl = NULL;
39718 - drm_ioctl_t *func;
39719 + drm_ioctl_no_const_t func;
39720 unsigned int nr = DRM_IOCTL_NR(cmd);
39721 int retcode = -EINVAL;
39722 char stack_kdata[128];
39723 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39724 index 7f2af9a..1561914 100644
39725 --- a/drivers/gpu/drm/drm_fops.c
39726 +++ b/drivers/gpu/drm/drm_fops.c
39727 @@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39728 if (drm_device_is_unplugged(dev))
39729 return -ENODEV;
39730
39731 - if (!dev->open_count++)
39732 + if (local_inc_return(&dev->open_count) == 1)
39733 need_setup = 1;
39734 mutex_lock(&dev->struct_mutex);
39735 old_imapping = inode->i_mapping;
39736 @@ -127,7 +127,7 @@ err_undo:
39737 iput(container_of(dev->dev_mapping, struct inode, i_data));
39738 dev->dev_mapping = old_mapping;
39739 mutex_unlock(&dev->struct_mutex);
39740 - dev->open_count--;
39741 + local_dec(&dev->open_count);
39742 return retcode;
39743 }
39744 EXPORT_SYMBOL(drm_open);
39745 @@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
39746
39747 mutex_lock(&drm_global_mutex);
39748
39749 - DRM_DEBUG("open_count = %d\n", dev->open_count);
39750 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39751
39752 if (dev->driver->preclose)
39753 dev->driver->preclose(dev, file_priv);
39754 @@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
39755 * Begin inline drm_release
39756 */
39757
39758 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39759 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39760 task_pid_nr(current),
39761 (long)old_encode_dev(file_priv->minor->device),
39762 - dev->open_count);
39763 + local_read(&dev->open_count));
39764
39765 /* Release any auth tokens that might point to this file_priv,
39766 (do that under the drm_global_mutex) */
39767 @@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
39768 * End inline drm_release
39769 */
39770
39771 - if (!--dev->open_count) {
39772 + if (local_dec_and_test(&dev->open_count)) {
39773 retcode = drm_lastclose(dev);
39774 if (drm_device_is_unplugged(dev))
39775 drm_put_dev(dev);
39776 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39777 index 3d2e91c..d31c4c9 100644
39778 --- a/drivers/gpu/drm/drm_global.c
39779 +++ b/drivers/gpu/drm/drm_global.c
39780 @@ -36,7 +36,7 @@
39781 struct drm_global_item {
39782 struct mutex mutex;
39783 void *object;
39784 - int refcount;
39785 + atomic_t refcount;
39786 };
39787
39788 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39789 @@ -49,7 +49,7 @@ void drm_global_init(void)
39790 struct drm_global_item *item = &glob[i];
39791 mutex_init(&item->mutex);
39792 item->object = NULL;
39793 - item->refcount = 0;
39794 + atomic_set(&item->refcount, 0);
39795 }
39796 }
39797
39798 @@ -59,7 +59,7 @@ void drm_global_release(void)
39799 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39800 struct drm_global_item *item = &glob[i];
39801 BUG_ON(item->object != NULL);
39802 - BUG_ON(item->refcount != 0);
39803 + BUG_ON(atomic_read(&item->refcount) != 0);
39804 }
39805 }
39806
39807 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39808 struct drm_global_item *item = &glob[ref->global_type];
39809
39810 mutex_lock(&item->mutex);
39811 - if (item->refcount == 0) {
39812 + if (atomic_read(&item->refcount) == 0) {
39813 item->object = kzalloc(ref->size, GFP_KERNEL);
39814 if (unlikely(item->object == NULL)) {
39815 ret = -ENOMEM;
39816 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39817 goto out_err;
39818
39819 }
39820 - ++item->refcount;
39821 + atomic_inc(&item->refcount);
39822 ref->object = item->object;
39823 mutex_unlock(&item->mutex);
39824 return 0;
39825 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39826 struct drm_global_item *item = &glob[ref->global_type];
39827
39828 mutex_lock(&item->mutex);
39829 - BUG_ON(item->refcount == 0);
39830 + BUG_ON(atomic_read(&item->refcount) == 0);
39831 BUG_ON(ref->object != item->object);
39832 - if (--item->refcount == 0) {
39833 + if (atomic_dec_and_test(&item->refcount)) {
39834 ref->release(ref);
39835 item->object = NULL;
39836 }
39837 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39838 index 7473035..a48b9c5 100644
39839 --- a/drivers/gpu/drm/drm_info.c
39840 +++ b/drivers/gpu/drm/drm_info.c
39841 @@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
39842 struct drm_local_map *map;
39843 struct drm_map_list *r_list;
39844
39845 - /* Hardcoded from _DRM_FRAME_BUFFER,
39846 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39847 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39848 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39849 + static const char * const types[] = {
39850 + [_DRM_FRAME_BUFFER] = "FB",
39851 + [_DRM_REGISTERS] = "REG",
39852 + [_DRM_SHM] = "SHM",
39853 + [_DRM_AGP] = "AGP",
39854 + [_DRM_SCATTER_GATHER] = "SG",
39855 + [_DRM_CONSISTENT] = "PCI"};
39856 const char *type;
39857 int i;
39858
39859 @@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39860 map = r_list->map;
39861 if (!map)
39862 continue;
39863 - if (map->type < 0 || map->type > 5)
39864 + if (map->type >= ARRAY_SIZE(types))
39865 type = "??";
39866 else
39867 type = types[map->type];
39868 @@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39869 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39870 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39871 vma->vm_flags & VM_IO ? 'i' : '-',
39872 +#ifdef CONFIG_GRKERNSEC_HIDESYM
39873 + 0);
39874 +#else
39875 vma->vm_pgoff);
39876 +#endif
39877
39878 #if defined(__i386__)
39879 pgprot = pgprot_val(vma->vm_page_prot);
39880 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39881 index 2f4c4343..dd12cd2 100644
39882 --- a/drivers/gpu/drm/drm_ioc32.c
39883 +++ b/drivers/gpu/drm/drm_ioc32.c
39884 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39885 request = compat_alloc_user_space(nbytes);
39886 if (!access_ok(VERIFY_WRITE, request, nbytes))
39887 return -EFAULT;
39888 - list = (struct drm_buf_desc *) (request + 1);
39889 + list = (struct drm_buf_desc __user *) (request + 1);
39890
39891 if (__put_user(count, &request->count)
39892 || __put_user(list, &request->list))
39893 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39894 request = compat_alloc_user_space(nbytes);
39895 if (!access_ok(VERIFY_WRITE, request, nbytes))
39896 return -EFAULT;
39897 - list = (struct drm_buf_pub *) (request + 1);
39898 + list = (struct drm_buf_pub __user *) (request + 1);
39899
39900 if (__put_user(count, &request->count)
39901 || __put_user(list, &request->list))
39902 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39903 return 0;
39904 }
39905
39906 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
39907 +drm_ioctl_compat_t drm_compat_ioctls[] = {
39908 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39909 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39910 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39911 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39912 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39913 {
39914 unsigned int nr = DRM_IOCTL_NR(cmd);
39915 - drm_ioctl_compat_t *fn;
39916 int ret;
39917
39918 /* Assume that ioctls without an explicit compat routine will just
39919 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39920 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39921 return drm_ioctl(filp, cmd, arg);
39922
39923 - fn = drm_compat_ioctls[nr];
39924 -
39925 - if (fn != NULL)
39926 - ret = (*fn) (filp, cmd, arg);
39927 + if (drm_compat_ioctls[nr] != NULL)
39928 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39929 else
39930 ret = drm_ioctl(filp, cmd, arg);
39931
39932 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39933 index 98a33c580..8fd1c2b 100644
39934 --- a/drivers/gpu/drm/drm_stub.c
39935 +++ b/drivers/gpu/drm/drm_stub.c
39936 @@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
39937
39938 drm_device_set_unplugged(dev);
39939
39940 - if (dev->open_count == 0) {
39941 + if (local_read(&dev->open_count) == 0) {
39942 drm_put_dev(dev);
39943 }
39944 mutex_unlock(&drm_global_mutex);
39945 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39946 index c22c309..ae758c3 100644
39947 --- a/drivers/gpu/drm/drm_sysfs.c
39948 +++ b/drivers/gpu/drm/drm_sysfs.c
39949 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39950 */
39951 int drm_sysfs_device_add(struct drm_minor *minor)
39952 {
39953 - char *minor_str;
39954 + const char *minor_str;
39955 int r;
39956
39957 if (minor->type == DRM_MINOR_CONTROL)
39958 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39959 index d4d16ed..8fb0b51 100644
39960 --- a/drivers/gpu/drm/i810/i810_drv.h
39961 +++ b/drivers/gpu/drm/i810/i810_drv.h
39962 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
39963 int page_flipping;
39964
39965 wait_queue_head_t irq_queue;
39966 - atomic_t irq_received;
39967 - atomic_t irq_emitted;
39968 + atomic_unchecked_t irq_received;
39969 + atomic_unchecked_t irq_emitted;
39970
39971 int front_offset;
39972 } drm_i810_private_t;
39973 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
39974 index b2b46c5..feb9fe7 100644
39975 --- a/drivers/gpu/drm/i915/i915_debugfs.c
39976 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
39977 @@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
39978 I915_READ(GTIMR));
39979 }
39980 seq_printf(m, "Interrupts received: %d\n",
39981 - atomic_read(&dev_priv->irq_received));
39982 + atomic_read_unchecked(&dev_priv->irq_received));
39983 for_each_ring(ring, dev_priv, i) {
39984 if (INTEL_INFO(dev)->gen >= 6) {
39985 seq_printf(m,
39986 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
39987 index 15a74f9..4278889 100644
39988 --- a/drivers/gpu/drm/i915/i915_dma.c
39989 +++ b/drivers/gpu/drm/i915/i915_dma.c
39990 @@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
39991 bool can_switch;
39992
39993 spin_lock(&dev->count_lock);
39994 - can_switch = (dev->open_count == 0);
39995 + can_switch = (local_read(&dev->open_count) == 0);
39996 spin_unlock(&dev->count_lock);
39997 return can_switch;
39998 }
39999 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40000 index df77e20..d3fda9f 100644
40001 --- a/drivers/gpu/drm/i915/i915_drv.h
40002 +++ b/drivers/gpu/drm/i915/i915_drv.h
40003 @@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
40004 drm_dma_handle_t *status_page_dmah;
40005 struct resource mch_res;
40006
40007 - atomic_t irq_received;
40008 + atomic_unchecked_t irq_received;
40009
40010 /* protects the irq masks */
40011 spinlock_t irq_lock;
40012 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40013 index d269ecf..6d857bc 100644
40014 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40015 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40016 @@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40017
40018 static int
40019 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40020 - int count)
40021 + unsigned int count)
40022 {
40023 - int i;
40024 + unsigned int i;
40025 unsigned relocs_total = 0;
40026 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40027
40028 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40029 index 3c59584..500f2e9 100644
40030 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40031 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40032 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40033 (unsigned long)request);
40034 }
40035
40036 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40037 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40038 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40039 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40040 [DRM_I915_GETPARAM] = compat_i915_getparam,
40041 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40042 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40043 {
40044 unsigned int nr = DRM_IOCTL_NR(cmd);
40045 - drm_ioctl_compat_t *fn = NULL;
40046 int ret;
40047
40048 if (nr < DRM_COMMAND_BASE)
40049 return drm_compat_ioctl(filp, cmd, arg);
40050
40051 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40052 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40053 -
40054 - if (fn != NULL)
40055 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40056 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40057 ret = (*fn) (filp, cmd, arg);
40058 - else
40059 + } else
40060 ret = drm_ioctl(filp, cmd, arg);
40061
40062 return ret;
40063 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40064 index d554169..f4426bb 100644
40065 --- a/drivers/gpu/drm/i915/i915_irq.c
40066 +++ b/drivers/gpu/drm/i915/i915_irq.c
40067 @@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40068 int pipe;
40069 u32 pipe_stats[I915_MAX_PIPES];
40070
40071 - atomic_inc(&dev_priv->irq_received);
40072 + atomic_inc_unchecked(&dev_priv->irq_received);
40073
40074 while (true) {
40075 iir = I915_READ(VLV_IIR);
40076 @@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40077 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40078 irqreturn_t ret = IRQ_NONE;
40079
40080 - atomic_inc(&dev_priv->irq_received);
40081 + atomic_inc_unchecked(&dev_priv->irq_received);
40082
40083 /* We get interrupts on unclaimed registers, so check for this before we
40084 * do any I915_{READ,WRITE}. */
40085 @@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40086 uint32_t tmp = 0;
40087 enum pipe pipe;
40088
40089 - atomic_inc(&dev_priv->irq_received);
40090 + atomic_inc_unchecked(&dev_priv->irq_received);
40091
40092 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40093 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40094 @@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40095 {
40096 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40097
40098 - atomic_set(&dev_priv->irq_received, 0);
40099 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40100
40101 I915_WRITE(HWSTAM, 0xeffe);
40102
40103 @@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40104 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40105 int pipe;
40106
40107 - atomic_set(&dev_priv->irq_received, 0);
40108 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40109
40110 /* VLV magic */
40111 I915_WRITE(VLV_IMR, 0);
40112 @@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40113 struct drm_i915_private *dev_priv = dev->dev_private;
40114 int pipe;
40115
40116 - atomic_set(&dev_priv->irq_received, 0);
40117 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40118
40119 I915_WRITE(GEN8_MASTER_IRQ, 0);
40120 POSTING_READ(GEN8_MASTER_IRQ);
40121 @@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40122 if (!dev_priv)
40123 return;
40124
40125 - atomic_set(&dev_priv->irq_received, 0);
40126 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40127
40128 I915_WRITE(GEN8_MASTER_IRQ, 0);
40129
40130 @@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40131 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40132 int pipe;
40133
40134 - atomic_set(&dev_priv->irq_received, 0);
40135 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40136
40137 for_each_pipe(pipe)
40138 I915_WRITE(PIPESTAT(pipe), 0);
40139 @@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40140 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40141 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40142
40143 - atomic_inc(&dev_priv->irq_received);
40144 + atomic_inc_unchecked(&dev_priv->irq_received);
40145
40146 iir = I915_READ16(IIR);
40147 if (iir == 0)
40148 @@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40149 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40150 int pipe;
40151
40152 - atomic_set(&dev_priv->irq_received, 0);
40153 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40154
40155 if (I915_HAS_HOTPLUG(dev)) {
40156 I915_WRITE(PORT_HOTPLUG_EN, 0);
40157 @@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40158 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40159 int pipe, ret = IRQ_NONE;
40160
40161 - atomic_inc(&dev_priv->irq_received);
40162 + atomic_inc_unchecked(&dev_priv->irq_received);
40163
40164 iir = I915_READ(IIR);
40165 do {
40166 @@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40167 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40168 int pipe;
40169
40170 - atomic_set(&dev_priv->irq_received, 0);
40171 + atomic_set_unchecked(&dev_priv->irq_received, 0);
40172
40173 I915_WRITE(PORT_HOTPLUG_EN, 0);
40174 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40175 @@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40176 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40177 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40178
40179 - atomic_inc(&dev_priv->irq_received);
40180 + atomic_inc_unchecked(&dev_priv->irq_received);
40181
40182 iir = I915_READ(IIR);
40183
40184 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40185 index 9b8a7c7..60f6003 100644
40186 --- a/drivers/gpu/drm/i915/intel_display.c
40187 +++ b/drivers/gpu/drm/i915/intel_display.c
40188 @@ -10776,13 +10776,13 @@ struct intel_quirk {
40189 int subsystem_vendor;
40190 int subsystem_device;
40191 void (*hook)(struct drm_device *dev);
40192 -};
40193 +} __do_const;
40194
40195 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40196 struct intel_dmi_quirk {
40197 void (*hook)(struct drm_device *dev);
40198 const struct dmi_system_id (*dmi_id_list)[];
40199 -};
40200 +} __do_const;
40201
40202 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40203 {
40204 @@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40205 return 1;
40206 }
40207
40208 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40209 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40210 {
40211 - .dmi_id_list = &(const struct dmi_system_id[]) {
40212 - {
40213 - .callback = intel_dmi_reverse_brightness,
40214 - .ident = "NCR Corporation",
40215 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40216 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40217 - },
40218 - },
40219 - { } /* terminating entry */
40220 + .callback = intel_dmi_reverse_brightness,
40221 + .ident = "NCR Corporation",
40222 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40223 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40224 },
40225 + },
40226 + { } /* terminating entry */
40227 +};
40228 +
40229 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40230 + {
40231 + .dmi_id_list = &intel_dmi_quirks_table,
40232 .hook = quirk_invert_brightness,
40233 },
40234 };
40235 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40236 index fe45321..836fdca 100644
40237 --- a/drivers/gpu/drm/mga/mga_drv.h
40238 +++ b/drivers/gpu/drm/mga/mga_drv.h
40239 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40240 u32 clear_cmd;
40241 u32 maccess;
40242
40243 - atomic_t vbl_received; /**< Number of vblanks received. */
40244 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40245 wait_queue_head_t fence_queue;
40246 - atomic_t last_fence_retired;
40247 + atomic_unchecked_t last_fence_retired;
40248 u32 next_fence_to_post;
40249
40250 unsigned int fb_cpp;
40251 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40252 index 86b4bb8..ae237ad 100644
40253 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40254 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40255 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40256 return 0;
40257 }
40258
40259 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40260 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40261 [DRM_MGA_INIT] = compat_mga_init,
40262 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40263 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40264 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40265 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40266 {
40267 unsigned int nr = DRM_IOCTL_NR(cmd);
40268 - drm_ioctl_compat_t *fn = NULL;
40269 int ret;
40270
40271 if (nr < DRM_COMMAND_BASE)
40272 return drm_compat_ioctl(filp, cmd, arg);
40273
40274 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40275 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40276 -
40277 - if (fn != NULL)
40278 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40279 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40280 ret = (*fn) (filp, cmd, arg);
40281 - else
40282 + } else
40283 ret = drm_ioctl(filp, cmd, arg);
40284
40285 return ret;
40286 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40287 index 1b071b8..de8601a 100644
40288 --- a/drivers/gpu/drm/mga/mga_irq.c
40289 +++ b/drivers/gpu/drm/mga/mga_irq.c
40290 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40291 if (crtc != 0)
40292 return 0;
40293
40294 - return atomic_read(&dev_priv->vbl_received);
40295 + return atomic_read_unchecked(&dev_priv->vbl_received);
40296 }
40297
40298
40299 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40300 /* VBLANK interrupt */
40301 if (status & MGA_VLINEPEN) {
40302 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40303 - atomic_inc(&dev_priv->vbl_received);
40304 + atomic_inc_unchecked(&dev_priv->vbl_received);
40305 drm_handle_vblank(dev, 0);
40306 handled = 1;
40307 }
40308 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40309 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40310 MGA_WRITE(MGA_PRIMEND, prim_end);
40311
40312 - atomic_inc(&dev_priv->last_fence_retired);
40313 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40314 wake_up(&dev_priv->fence_queue);
40315 handled = 1;
40316 }
40317 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40318 * using fences.
40319 */
40320 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40321 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40322 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40323 - *sequence) <= (1 << 23)));
40324
40325 *sequence = cur_fence;
40326 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40327 index 4c3feaa..26391ce 100644
40328 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40329 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40330 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40331 struct bit_table {
40332 const char id;
40333 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40334 -};
40335 +} __no_const;
40336
40337 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40338
40339 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40340 index 23ca7a5..b6c955d 100644
40341 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40342 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40343 @@ -97,7 +97,6 @@ struct nouveau_drm {
40344 struct drm_global_reference mem_global_ref;
40345 struct ttm_bo_global_ref bo_global_ref;
40346 struct ttm_bo_device bdev;
40347 - atomic_t validate_sequence;
40348 int (*move)(struct nouveau_channel *,
40349 struct ttm_buffer_object *,
40350 struct ttm_mem_reg *, struct ttm_mem_reg *);
40351 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40352 index c1a7e5a..38b8539 100644
40353 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40354 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40355 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40356 unsigned long arg)
40357 {
40358 unsigned int nr = DRM_IOCTL_NR(cmd);
40359 - drm_ioctl_compat_t *fn = NULL;
40360 + drm_ioctl_compat_t fn = NULL;
40361 int ret;
40362
40363 if (nr < DRM_COMMAND_BASE)
40364 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40365 index d45d50d..72a5dd2 100644
40366 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40367 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40368 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40369 }
40370
40371 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40372 - nouveau_vram_manager_init,
40373 - nouveau_vram_manager_fini,
40374 - nouveau_vram_manager_new,
40375 - nouveau_vram_manager_del,
40376 - nouveau_vram_manager_debug
40377 + .init = nouveau_vram_manager_init,
40378 + .takedown = nouveau_vram_manager_fini,
40379 + .get_node = nouveau_vram_manager_new,
40380 + .put_node = nouveau_vram_manager_del,
40381 + .debug = nouveau_vram_manager_debug
40382 };
40383
40384 static int
40385 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40386 }
40387
40388 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40389 - nouveau_gart_manager_init,
40390 - nouveau_gart_manager_fini,
40391 - nouveau_gart_manager_new,
40392 - nouveau_gart_manager_del,
40393 - nouveau_gart_manager_debug
40394 + .init = nouveau_gart_manager_init,
40395 + .takedown = nouveau_gart_manager_fini,
40396 + .get_node = nouveau_gart_manager_new,
40397 + .put_node = nouveau_gart_manager_del,
40398 + .debug = nouveau_gart_manager_debug
40399 };
40400
40401 #include <core/subdev/vm/nv04.h>
40402 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40403 }
40404
40405 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40406 - nv04_gart_manager_init,
40407 - nv04_gart_manager_fini,
40408 - nv04_gart_manager_new,
40409 - nv04_gart_manager_del,
40410 - nv04_gart_manager_debug
40411 + .init = nv04_gart_manager_init,
40412 + .takedown = nv04_gart_manager_fini,
40413 + .get_node = nv04_gart_manager_new,
40414 + .put_node = nv04_gart_manager_del,
40415 + .debug = nv04_gart_manager_debug
40416 };
40417
40418 int
40419 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40420 index 471347e..5adc6b9 100644
40421 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40422 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40423 @@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40424 bool can_switch;
40425
40426 spin_lock(&dev->count_lock);
40427 - can_switch = (dev->open_count == 0);
40428 + can_switch = (local_read(&dev->open_count) == 0);
40429 spin_unlock(&dev->count_lock);
40430 return can_switch;
40431 }
40432 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40433 index eb89653..613cf71 100644
40434 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40435 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40436 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40437 int ret;
40438
40439 mutex_lock(&qdev->async_io_mutex);
40440 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40441 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40442 if (qdev->last_sent_io_cmd > irq_num) {
40443 if (intr)
40444 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40445 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40446 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40447 else
40448 ret = wait_event_timeout(qdev->io_cmd_event,
40449 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40450 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40451 /* 0 is timeout, just bail the "hw" has gone away */
40452 if (ret <= 0)
40453 goto out;
40454 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40455 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40456 }
40457 outb(val, addr);
40458 qdev->last_sent_io_cmd = irq_num + 1;
40459 if (intr)
40460 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40461 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40462 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40463 else
40464 ret = wait_event_timeout(qdev->io_cmd_event,
40465 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40466 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40467 out:
40468 if (ret > 0)
40469 ret = 0;
40470 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40471 index c3c2bbd..bc3c0fb 100644
40472 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40473 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40474 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40475 struct drm_info_node *node = (struct drm_info_node *) m->private;
40476 struct qxl_device *qdev = node->minor->dev->dev_private;
40477
40478 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40479 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40480 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40481 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40482 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40483 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40484 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40485 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40486 seq_printf(m, "%d\n", qdev->irq_received_error);
40487 return 0;
40488 }
40489 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40490 index 36ed40b..0397633 100644
40491 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40492 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40493 @@ -290,10 +290,10 @@ struct qxl_device {
40494 unsigned int last_sent_io_cmd;
40495
40496 /* interrupt handling */
40497 - atomic_t irq_received;
40498 - atomic_t irq_received_display;
40499 - atomic_t irq_received_cursor;
40500 - atomic_t irq_received_io_cmd;
40501 + atomic_unchecked_t irq_received;
40502 + atomic_unchecked_t irq_received_display;
40503 + atomic_unchecked_t irq_received_cursor;
40504 + atomic_unchecked_t irq_received_io_cmd;
40505 unsigned irq_received_error;
40506 wait_queue_head_t display_event;
40507 wait_queue_head_t cursor_event;
40508 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40509 index 0bb86e6..d41416d 100644
40510 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40511 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40512 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40513
40514 /* TODO copy slow path code from i915 */
40515 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40516 - 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);
40517 + 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);
40518
40519 {
40520 struct qxl_drawable *draw = fb_cmd;
40521 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40522 struct drm_qxl_reloc reloc;
40523
40524 if (copy_from_user(&reloc,
40525 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40526 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40527 sizeof(reloc))) {
40528 ret = -EFAULT;
40529 goto out_free_bos;
40530 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40531
40532 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40533
40534 - struct drm_qxl_command *commands =
40535 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40536 + struct drm_qxl_command __user *commands =
40537 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40538
40539 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40540 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40541 sizeof(user_cmd)))
40542 return -EFAULT;
40543
40544 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40545 index 28f84b4..fb3e224 100644
40546 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40547 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40548 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40549
40550 pending = xchg(&qdev->ram_header->int_pending, 0);
40551
40552 - atomic_inc(&qdev->irq_received);
40553 + atomic_inc_unchecked(&qdev->irq_received);
40554
40555 if (pending & QXL_INTERRUPT_DISPLAY) {
40556 - atomic_inc(&qdev->irq_received_display);
40557 + atomic_inc_unchecked(&qdev->irq_received_display);
40558 wake_up_all(&qdev->display_event);
40559 qxl_queue_garbage_collect(qdev, false);
40560 }
40561 if (pending & QXL_INTERRUPT_CURSOR) {
40562 - atomic_inc(&qdev->irq_received_cursor);
40563 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40564 wake_up_all(&qdev->cursor_event);
40565 }
40566 if (pending & QXL_INTERRUPT_IO_CMD) {
40567 - atomic_inc(&qdev->irq_received_io_cmd);
40568 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40569 wake_up_all(&qdev->io_cmd_event);
40570 }
40571 if (pending & QXL_INTERRUPT_ERROR) {
40572 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40573 init_waitqueue_head(&qdev->io_cmd_event);
40574 INIT_WORK(&qdev->client_monitors_config_work,
40575 qxl_client_monitors_config_work_func);
40576 - atomic_set(&qdev->irq_received, 0);
40577 - atomic_set(&qdev->irq_received_display, 0);
40578 - atomic_set(&qdev->irq_received_cursor, 0);
40579 - atomic_set(&qdev->irq_received_io_cmd, 0);
40580 + atomic_set_unchecked(&qdev->irq_received, 0);
40581 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40582 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40583 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40584 qdev->irq_received_error = 0;
40585 ret = drm_irq_install(qdev->ddev);
40586 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40587 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40588 index c7e7e65..7dddd4d 100644
40589 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40590 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40591 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40592 }
40593 }
40594
40595 -static struct vm_operations_struct qxl_ttm_vm_ops;
40596 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40597 static const struct vm_operations_struct *ttm_vm_ops;
40598
40599 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40600 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40601 return r;
40602 if (unlikely(ttm_vm_ops == NULL)) {
40603 ttm_vm_ops = vma->vm_ops;
40604 + pax_open_kernel();
40605 qxl_ttm_vm_ops = *ttm_vm_ops;
40606 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40607 + pax_close_kernel();
40608 }
40609 vma->vm_ops = &qxl_ttm_vm_ops;
40610 return 0;
40611 @@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40612 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40613 {
40614 #if defined(CONFIG_DEBUG_FS)
40615 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40616 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40617 - unsigned i;
40618 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40619 + {
40620 + .name = "qxl_mem_mm",
40621 + .show = &qxl_mm_dump_table,
40622 + },
40623 + {
40624 + .name = "qxl_surf_mm",
40625 + .show = &qxl_mm_dump_table,
40626 + }
40627 + };
40628
40629 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40630 - if (i == 0)
40631 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40632 - else
40633 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40634 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40635 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40636 - qxl_mem_types_list[i].driver_features = 0;
40637 - if (i == 0)
40638 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40639 - else
40640 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40641 + pax_open_kernel();
40642 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40643 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40644 + pax_close_kernel();
40645
40646 - }
40647 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40648 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40649 #else
40650 return 0;
40651 #endif
40652 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40653 index 59459fe..be26b31 100644
40654 --- a/drivers/gpu/drm/r128/r128_cce.c
40655 +++ b/drivers/gpu/drm/r128/r128_cce.c
40656 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40657
40658 /* GH: Simple idle check.
40659 */
40660 - atomic_set(&dev_priv->idle_count, 0);
40661 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40662
40663 /* We don't support anything other than bus-mastering ring mode,
40664 * but the ring can be in either AGP or PCI space for the ring
40665 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40666 index 5bf3f5f..7000661 100644
40667 --- a/drivers/gpu/drm/r128/r128_drv.h
40668 +++ b/drivers/gpu/drm/r128/r128_drv.h
40669 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40670 int is_pci;
40671 unsigned long cce_buffers_offset;
40672
40673 - atomic_t idle_count;
40674 + atomic_unchecked_t idle_count;
40675
40676 int page_flipping;
40677 int current_page;
40678 u32 crtc_offset;
40679 u32 crtc_offset_cntl;
40680
40681 - atomic_t vbl_received;
40682 + atomic_unchecked_t vbl_received;
40683
40684 u32 color_fmt;
40685 unsigned int front_offset;
40686 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40687 index b0d0fd3..a6fbbe4 100644
40688 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40689 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40690 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40691 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40692 }
40693
40694 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40695 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40696 [DRM_R128_INIT] = compat_r128_init,
40697 [DRM_R128_DEPTH] = compat_r128_depth,
40698 [DRM_R128_STIPPLE] = compat_r128_stipple,
40699 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40700 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40701 {
40702 unsigned int nr = DRM_IOCTL_NR(cmd);
40703 - drm_ioctl_compat_t *fn = NULL;
40704 int ret;
40705
40706 if (nr < DRM_COMMAND_BASE)
40707 return drm_compat_ioctl(filp, cmd, arg);
40708
40709 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40710 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40711 -
40712 - if (fn != NULL)
40713 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40714 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40715 ret = (*fn) (filp, cmd, arg);
40716 - else
40717 + } else
40718 ret = drm_ioctl(filp, cmd, arg);
40719
40720 return ret;
40721 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40722 index c2ae496..30b5993 100644
40723 --- a/drivers/gpu/drm/r128/r128_irq.c
40724 +++ b/drivers/gpu/drm/r128/r128_irq.c
40725 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40726 if (crtc != 0)
40727 return 0;
40728
40729 - return atomic_read(&dev_priv->vbl_received);
40730 + return atomic_read_unchecked(&dev_priv->vbl_received);
40731 }
40732
40733 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40734 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40735 /* VBLANK interrupt */
40736 if (status & R128_CRTC_VBLANK_INT) {
40737 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40738 - atomic_inc(&dev_priv->vbl_received);
40739 + atomic_inc_unchecked(&dev_priv->vbl_received);
40740 drm_handle_vblank(dev, 0);
40741 return IRQ_HANDLED;
40742 }
40743 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40744 index e806dac..f81d32f 100644
40745 --- a/drivers/gpu/drm/r128/r128_state.c
40746 +++ b/drivers/gpu/drm/r128/r128_state.c
40747 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40748
40749 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40750 {
40751 - if (atomic_read(&dev_priv->idle_count) == 0)
40752 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40753 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40754 else
40755 - atomic_set(&dev_priv->idle_count, 0);
40756 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40757 }
40758
40759 #endif
40760 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40761 index 4a85bb6..aaea819 100644
40762 --- a/drivers/gpu/drm/radeon/mkregtable.c
40763 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40764 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40765 regex_t mask_rex;
40766 regmatch_t match[4];
40767 char buf[1024];
40768 - size_t end;
40769 + long end;
40770 int len;
40771 int done = 0;
40772 int r;
40773 unsigned o;
40774 struct offset *offset;
40775 char last_reg_s[10];
40776 - int last_reg;
40777 + unsigned long last_reg;
40778
40779 if (regcomp
40780 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40781 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40782 index 044bc98..50ced9b 100644
40783 --- a/drivers/gpu/drm/radeon/radeon_device.c
40784 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40785 @@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40786 bool can_switch;
40787
40788 spin_lock(&dev->count_lock);
40789 - can_switch = (dev->open_count == 0);
40790 + can_switch = (local_read(&dev->open_count) == 0);
40791 spin_unlock(&dev->count_lock);
40792 return can_switch;
40793 }
40794 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40795 index dafd812..1bf20c7 100644
40796 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40797 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40798 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40799
40800 /* SW interrupt */
40801 wait_queue_head_t swi_queue;
40802 - atomic_t swi_emitted;
40803 + atomic_unchecked_t swi_emitted;
40804 int vblank_crtc;
40805 uint32_t irq_enable_reg;
40806 uint32_t r500_disp_irq_reg;
40807 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40808 index bdb0f93..5ff558f 100644
40809 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40810 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40811 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40812 request = compat_alloc_user_space(sizeof(*request));
40813 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40814 || __put_user(req32.param, &request->param)
40815 - || __put_user((void __user *)(unsigned long)req32.value,
40816 + || __put_user((unsigned long)req32.value,
40817 &request->value))
40818 return -EFAULT;
40819
40820 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40821 #define compat_radeon_cp_setparam NULL
40822 #endif /* X86_64 || IA64 */
40823
40824 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40825 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40826 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40827 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40828 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40829 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40830 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40831 {
40832 unsigned int nr = DRM_IOCTL_NR(cmd);
40833 - drm_ioctl_compat_t *fn = NULL;
40834 int ret;
40835
40836 if (nr < DRM_COMMAND_BASE)
40837 return drm_compat_ioctl(filp, cmd, arg);
40838
40839 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40840 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40841 -
40842 - if (fn != NULL)
40843 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40844 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40845 ret = (*fn) (filp, cmd, arg);
40846 - else
40847 + } else
40848 ret = drm_ioctl(filp, cmd, arg);
40849
40850 return ret;
40851 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40852 index 244b19b..c19226d 100644
40853 --- a/drivers/gpu/drm/radeon/radeon_irq.c
40854 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
40855 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40856 unsigned int ret;
40857 RING_LOCALS;
40858
40859 - atomic_inc(&dev_priv->swi_emitted);
40860 - ret = atomic_read(&dev_priv->swi_emitted);
40861 + atomic_inc_unchecked(&dev_priv->swi_emitted);
40862 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40863
40864 BEGIN_RING(4);
40865 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40866 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40867 drm_radeon_private_t *dev_priv =
40868 (drm_radeon_private_t *) dev->dev_private;
40869
40870 - atomic_set(&dev_priv->swi_emitted, 0);
40871 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40872 init_waitqueue_head(&dev_priv->swi_queue);
40873
40874 dev->max_vblank_count = 0x001fffff;
40875 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40876 index 956ab7f..fbd36d8 100644
40877 --- a/drivers/gpu/drm/radeon/radeon_state.c
40878 +++ b/drivers/gpu/drm/radeon/radeon_state.c
40879 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40880 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40881 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40882
40883 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
40884 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
40885 sarea_priv->nbox * sizeof(depth_boxes[0])))
40886 return -EFAULT;
40887
40888 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40889 {
40890 drm_radeon_private_t *dev_priv = dev->dev_private;
40891 drm_radeon_getparam_t *param = data;
40892 - int value;
40893 + int value = 0;
40894
40895 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40896
40897 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40898 index 040a2a1..eae4e54 100644
40899 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
40900 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40901 @@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40902 man->size = size >> PAGE_SHIFT;
40903 }
40904
40905 -static struct vm_operations_struct radeon_ttm_vm_ops;
40906 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40907 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40908
40909 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40910 @@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40911 }
40912 if (unlikely(ttm_vm_ops == NULL)) {
40913 ttm_vm_ops = vma->vm_ops;
40914 + pax_open_kernel();
40915 radeon_ttm_vm_ops = *ttm_vm_ops;
40916 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40917 + pax_close_kernel();
40918 }
40919 vma->vm_ops = &radeon_ttm_vm_ops;
40920 return 0;
40921 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
40922 index 9336006..ce78aa7 100644
40923 --- a/drivers/gpu/drm/tegra/dc.c
40924 +++ b/drivers/gpu/drm/tegra/dc.c
40925 @@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40926 }
40927
40928 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40929 - dc->debugfs_files[i].data = dc;
40930 + *(void **)&dc->debugfs_files[i].data = dc;
40931
40932 err = drm_debugfs_create_files(dc->debugfs_files,
40933 ARRAY_SIZE(debugfs_files),
40934 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
40935 index 6928015..c9853e7 100644
40936 --- a/drivers/gpu/drm/tegra/hdmi.c
40937 +++ b/drivers/gpu/drm/tegra/hdmi.c
40938 @@ -59,7 +59,7 @@ struct tegra_hdmi {
40939 bool stereo;
40940 bool dvi;
40941
40942 - struct drm_info_list *debugfs_files;
40943 + drm_info_list_no_const *debugfs_files;
40944 struct drm_minor *minor;
40945 struct dentry *debugfs;
40946 };
40947 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40948 index c58eba33..83c2728 100644
40949 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
40950 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40951 @@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
40952 }
40953
40954 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
40955 - ttm_bo_man_init,
40956 - ttm_bo_man_takedown,
40957 - ttm_bo_man_get_node,
40958 - ttm_bo_man_put_node,
40959 - ttm_bo_man_debug
40960 + .init = ttm_bo_man_init,
40961 + .takedown = ttm_bo_man_takedown,
40962 + .get_node = ttm_bo_man_get_node,
40963 + .put_node = ttm_bo_man_put_node,
40964 + .debug = ttm_bo_man_debug
40965 };
40966 EXPORT_SYMBOL(ttm_bo_manager_func);
40967 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
40968 index dbc2def..0a9f710 100644
40969 --- a/drivers/gpu/drm/ttm/ttm_memory.c
40970 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
40971 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
40972 zone->glob = glob;
40973 glob->zone_kernel = zone;
40974 ret = kobject_init_and_add(
40975 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40976 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40977 if (unlikely(ret != 0)) {
40978 kobject_put(&zone->kobj);
40979 return ret;
40980 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
40981 zone->glob = glob;
40982 glob->zone_dma32 = zone;
40983 ret = kobject_init_and_add(
40984 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40985 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40986 if (unlikely(ret != 0)) {
40987 kobject_put(&zone->kobj);
40988 return ret;
40989 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40990 index 863bef9..cba15cf 100644
40991 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
40992 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40993 @@ -391,9 +391,9 @@ out:
40994 static unsigned long
40995 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
40996 {
40997 - static atomic_t start_pool = ATOMIC_INIT(0);
40998 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
40999 unsigned i;
41000 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41001 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41002 struct ttm_page_pool *pool;
41003 int shrink_pages = sc->nr_to_scan;
41004 unsigned long freed = 0;
41005 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41006 index dbadd49..1b7457b 100644
41007 --- a/drivers/gpu/drm/udl/udl_fb.c
41008 +++ b/drivers/gpu/drm/udl/udl_fb.c
41009 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41010 fb_deferred_io_cleanup(info);
41011 kfree(info->fbdefio);
41012 info->fbdefio = NULL;
41013 - info->fbops->fb_mmap = udl_fb_mmap;
41014 }
41015
41016 pr_warn("released /dev/fb%d user=%d count=%d\n",
41017 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41018 index ad02732..144f5ed 100644
41019 --- a/drivers/gpu/drm/via/via_drv.h
41020 +++ b/drivers/gpu/drm/via/via_drv.h
41021 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41022 typedef uint32_t maskarray_t[5];
41023
41024 typedef struct drm_via_irq {
41025 - atomic_t irq_received;
41026 + atomic_unchecked_t irq_received;
41027 uint32_t pending_mask;
41028 uint32_t enable_mask;
41029 wait_queue_head_t irq_queue;
41030 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41031 struct timeval last_vblank;
41032 int last_vblank_valid;
41033 unsigned usec_per_vblank;
41034 - atomic_t vbl_received;
41035 + atomic_unchecked_t vbl_received;
41036 drm_via_state_t hc_state;
41037 char pci_buf[VIA_PCI_BUF_SIZE];
41038 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41039 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41040 index 1319433..a993b0c 100644
41041 --- a/drivers/gpu/drm/via/via_irq.c
41042 +++ b/drivers/gpu/drm/via/via_irq.c
41043 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41044 if (crtc != 0)
41045 return 0;
41046
41047 - return atomic_read(&dev_priv->vbl_received);
41048 + return atomic_read_unchecked(&dev_priv->vbl_received);
41049 }
41050
41051 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41052 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41053
41054 status = VIA_READ(VIA_REG_INTERRUPT);
41055 if (status & VIA_IRQ_VBLANK_PENDING) {
41056 - atomic_inc(&dev_priv->vbl_received);
41057 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41058 + atomic_inc_unchecked(&dev_priv->vbl_received);
41059 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41060 do_gettimeofday(&cur_vblank);
41061 if (dev_priv->last_vblank_valid) {
41062 dev_priv->usec_per_vblank =
41063 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41064 dev_priv->last_vblank = cur_vblank;
41065 dev_priv->last_vblank_valid = 1;
41066 }
41067 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41068 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41069 DRM_DEBUG("US per vblank is: %u\n",
41070 dev_priv->usec_per_vblank);
41071 }
41072 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41073
41074 for (i = 0; i < dev_priv->num_irqs; ++i) {
41075 if (status & cur_irq->pending_mask) {
41076 - atomic_inc(&cur_irq->irq_received);
41077 + atomic_inc_unchecked(&cur_irq->irq_received);
41078 wake_up(&cur_irq->irq_queue);
41079 handled = 1;
41080 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41081 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41082 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41083 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41084 masks[irq][4]));
41085 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41086 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41087 } else {
41088 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41089 (((cur_irq_sequence =
41090 - atomic_read(&cur_irq->irq_received)) -
41091 + atomic_read_unchecked(&cur_irq->irq_received)) -
41092 *sequence) <= (1 << 23)));
41093 }
41094 *sequence = cur_irq_sequence;
41095 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41096 }
41097
41098 for (i = 0; i < dev_priv->num_irqs; ++i) {
41099 - atomic_set(&cur_irq->irq_received, 0);
41100 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41101 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41102 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41103 init_waitqueue_head(&cur_irq->irq_queue);
41104 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41105 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41106 case VIA_IRQ_RELATIVE:
41107 irqwait->request.sequence +=
41108 - atomic_read(&cur_irq->irq_received);
41109 + atomic_read_unchecked(&cur_irq->irq_received);
41110 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41111 case VIA_IRQ_ABSOLUTE:
41112 break;
41113 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41114 index 0783155..b29e18e 100644
41115 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41116 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41117 @@ -437,7 +437,7 @@ struct vmw_private {
41118 * Fencing and IRQs.
41119 */
41120
41121 - atomic_t marker_seq;
41122 + atomic_unchecked_t marker_seq;
41123 wait_queue_head_t fence_queue;
41124 wait_queue_head_t fifo_queue;
41125 int fence_queue_waiters; /* Protected by hw_mutex */
41126 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41127 index 6ccd993..618d592 100644
41128 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41129 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41130 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41131 (unsigned int) min,
41132 (unsigned int) fifo->capabilities);
41133
41134 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41135 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41136 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41137 vmw_marker_queue_init(&fifo->marker_queue);
41138 return vmw_fifo_send_fence(dev_priv, &dummy);
41139 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41140 if (reserveable)
41141 iowrite32(bytes, fifo_mem +
41142 SVGA_FIFO_RESERVED);
41143 - return fifo_mem + (next_cmd >> 2);
41144 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41145 } else {
41146 need_bounce = true;
41147 }
41148 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41149
41150 fm = vmw_fifo_reserve(dev_priv, bytes);
41151 if (unlikely(fm == NULL)) {
41152 - *seqno = atomic_read(&dev_priv->marker_seq);
41153 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41154 ret = -ENOMEM;
41155 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41156 false, 3*HZ);
41157 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41158 }
41159
41160 do {
41161 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41162 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41163 } while (*seqno == 0);
41164
41165 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41166 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41167 index b1273e8..9c274fd 100644
41168 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41169 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41170 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41171 }
41172
41173 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41174 - vmw_gmrid_man_init,
41175 - vmw_gmrid_man_takedown,
41176 - vmw_gmrid_man_get_node,
41177 - vmw_gmrid_man_put_node,
41178 - vmw_gmrid_man_debug
41179 + .init = vmw_gmrid_man_init,
41180 + .takedown = vmw_gmrid_man_takedown,
41181 + .get_node = vmw_gmrid_man_get_node,
41182 + .put_node = vmw_gmrid_man_put_node,
41183 + .debug = vmw_gmrid_man_debug
41184 };
41185 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41186 index 47b7094..698ba09 100644
41187 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41188 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41189 @@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41190 int ret;
41191
41192 num_clips = arg->num_clips;
41193 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41194 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41195
41196 if (unlikely(num_clips == 0))
41197 return 0;
41198 @@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41199 int ret;
41200
41201 num_clips = arg->num_clips;
41202 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41203 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41204
41205 if (unlikely(num_clips == 0))
41206 return 0;
41207 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41208 index 0c42376..6febe77 100644
41209 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41210 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41211 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41212 * emitted. Then the fence is stale and signaled.
41213 */
41214
41215 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41216 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41217 > VMW_FENCE_WRAP);
41218
41219 return ret;
41220 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41221
41222 if (fifo_idle)
41223 down_read(&fifo_state->rwsem);
41224 - signal_seq = atomic_read(&dev_priv->marker_seq);
41225 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41226 ret = 0;
41227
41228 for (;;) {
41229 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41230 index 8a8725c2..afed796 100644
41231 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41232 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41233 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41234 while (!vmw_lag_lt(queue, us)) {
41235 spin_lock(&queue->lock);
41236 if (list_empty(&queue->head))
41237 - seqno = atomic_read(&dev_priv->marker_seq);
41238 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41239 else {
41240 marker = list_first_entry(&queue->head,
41241 struct vmw_marker, head);
41242 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41243 index ec0ae2d..dc0780b 100644
41244 --- a/drivers/gpu/vga/vga_switcheroo.c
41245 +++ b/drivers/gpu/vga/vga_switcheroo.c
41246 @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41247
41248 /* this version is for the case where the power switch is separate
41249 to the device being powered down. */
41250 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41251 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41252 {
41253 /* copy over all the bus versions */
41254 if (dev->bus && dev->bus->pm) {
41255 @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41256 return ret;
41257 }
41258
41259 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41260 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41261 {
41262 /* copy over all the bus versions */
41263 if (dev->bus && dev->bus->pm) {
41264 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41265 index cc32a6f..02a4b1c 100644
41266 --- a/drivers/hid/hid-core.c
41267 +++ b/drivers/hid/hid-core.c
41268 @@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41269
41270 int hid_add_device(struct hid_device *hdev)
41271 {
41272 - static atomic_t id = ATOMIC_INIT(0);
41273 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41274 int ret;
41275
41276 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41277 @@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
41278 /* XXX hack, any other cleaner solution after the driver core
41279 * is converted to allow more than 20 bytes as the device name? */
41280 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41281 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41282 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41283
41284 hid_debug_register(hdev, dev_name(&hdev->dev));
41285 ret = device_add(&hdev->dev);
41286 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41287 index c13fb5b..55a3802 100644
41288 --- a/drivers/hid/hid-wiimote-debug.c
41289 +++ b/drivers/hid/hid-wiimote-debug.c
41290 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41291 else if (size == 0)
41292 return -EIO;
41293
41294 - if (copy_to_user(u, buf, size))
41295 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41296 return -EFAULT;
41297
41298 *off += size;
41299 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41300 index cedc6da..2c3da2a 100644
41301 --- a/drivers/hid/uhid.c
41302 +++ b/drivers/hid/uhid.c
41303 @@ -47,7 +47,7 @@ struct uhid_device {
41304 struct mutex report_lock;
41305 wait_queue_head_t report_wait;
41306 atomic_t report_done;
41307 - atomic_t report_id;
41308 + atomic_unchecked_t report_id;
41309 struct uhid_event report_buf;
41310 };
41311
41312 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41313
41314 spin_lock_irqsave(&uhid->qlock, flags);
41315 ev->type = UHID_FEATURE;
41316 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41317 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41318 ev->u.feature.rnum = rnum;
41319 ev->u.feature.rtype = report_type;
41320
41321 @@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41322 spin_lock_irqsave(&uhid->qlock, flags);
41323
41324 /* id for old report; drop it silently */
41325 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41326 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41327 goto unlock;
41328 if (atomic_read(&uhid->report_done))
41329 goto unlock;
41330 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41331 index 69ea36f..8dbf4bb 100644
41332 --- a/drivers/hv/channel.c
41333 +++ b/drivers/hv/channel.c
41334 @@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41335 int ret = 0;
41336 int t;
41337
41338 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41339 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41340 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41341 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41342
41343 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41344 if (ret)
41345 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41346 index bcb4950..61dba6c 100644
41347 --- a/drivers/hv/hv.c
41348 +++ b/drivers/hv/hv.c
41349 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41350 u64 output_address = (output) ? virt_to_phys(output) : 0;
41351 u32 output_address_hi = output_address >> 32;
41352 u32 output_address_lo = output_address & 0xFFFFFFFF;
41353 - void *hypercall_page = hv_context.hypercall_page;
41354 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41355
41356 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41357 "=a"(hv_status_lo) : "d" (control_hi),
41358 @@ -154,7 +154,7 @@ int hv_init(void)
41359 /* See if the hypercall page is already set */
41360 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41361
41362 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41363 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41364
41365 if (!virtaddr)
41366 goto cleanup;
41367 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41368 index 7e17a54..a50a33d 100644
41369 --- a/drivers/hv/hv_balloon.c
41370 +++ b/drivers/hv/hv_balloon.c
41371 @@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41372
41373 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41374 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41375 -static atomic_t trans_id = ATOMIC_INIT(0);
41376 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41377
41378 static int dm_ring_size = (5 * PAGE_SIZE);
41379
41380 @@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41381 pr_info("Memory hot add failed\n");
41382
41383 dm->state = DM_INITIALIZED;
41384 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41385 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41386 vmbus_sendpacket(dm->dev->channel, &resp,
41387 sizeof(struct dm_hot_add_response),
41388 (unsigned long)NULL,
41389 @@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41390 memset(&status, 0, sizeof(struct dm_status));
41391 status.hdr.type = DM_STATUS_REPORT;
41392 status.hdr.size = sizeof(struct dm_status);
41393 - status.hdr.trans_id = atomic_inc_return(&trans_id);
41394 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41395
41396 /*
41397 * The host expects the guest to report free memory.
41398 @@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41399 * send the status. This can happen if we were interrupted
41400 * after we picked our transaction ID.
41401 */
41402 - if (status.hdr.trans_id != atomic_read(&trans_id))
41403 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41404 return;
41405
41406 vmbus_sendpacket(dm->dev->channel, &status,
41407 @@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41408 */
41409
41410 do {
41411 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41412 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41413 ret = vmbus_sendpacket(dm_device.dev->channel,
41414 bl_resp,
41415 bl_resp->hdr.size,
41416 @@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41417
41418 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41419 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41420 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41421 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41422 resp.hdr.size = sizeof(struct dm_unballoon_response);
41423
41424 vmbus_sendpacket(dm_device.dev->channel, &resp,
41425 @@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41426 memset(&version_req, 0, sizeof(struct dm_version_request));
41427 version_req.hdr.type = DM_VERSION_REQUEST;
41428 version_req.hdr.size = sizeof(struct dm_version_request);
41429 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41430 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41431 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41432 version_req.is_last_attempt = 1;
41433
41434 @@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41435 memset(&version_req, 0, sizeof(struct dm_version_request));
41436 version_req.hdr.type = DM_VERSION_REQUEST;
41437 version_req.hdr.size = sizeof(struct dm_version_request);
41438 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41439 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41440 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41441 version_req.is_last_attempt = 0;
41442
41443 @@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41444 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41445 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41446 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41447 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41448 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41449
41450 cap_msg.caps.cap_bits.balloon = 1;
41451 cap_msg.caps.cap_bits.hot_add = 1;
41452 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41453 index e055176..c22ff1f 100644
41454 --- a/drivers/hv/hyperv_vmbus.h
41455 +++ b/drivers/hv/hyperv_vmbus.h
41456 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
41457 struct vmbus_connection {
41458 enum vmbus_connect_state conn_state;
41459
41460 - atomic_t next_gpadl_handle;
41461 + atomic_unchecked_t next_gpadl_handle;
41462
41463 /*
41464 * Represents channel interrupts. Each bit position represents a
41465 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41466 index 077bb1b..d433d74 100644
41467 --- a/drivers/hv/vmbus_drv.c
41468 +++ b/drivers/hv/vmbus_drv.c
41469 @@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41470 {
41471 int ret = 0;
41472
41473 - static atomic_t device_num = ATOMIC_INIT(0);
41474 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41475
41476 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41477 - atomic_inc_return(&device_num));
41478 + atomic_inc_return_unchecked(&device_num));
41479
41480 child_device_obj->device.bus = &hv_bus;
41481 child_device_obj->device.parent = &hv_acpi_dev->dev;
41482 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41483 index 579bdf9..75118b5 100644
41484 --- a/drivers/hwmon/acpi_power_meter.c
41485 +++ b/drivers/hwmon/acpi_power_meter.c
41486 @@ -116,7 +116,7 @@ struct sensor_template {
41487 struct device_attribute *devattr,
41488 const char *buf, size_t count);
41489 int index;
41490 -};
41491 +} __do_const;
41492
41493 /* Averaging interval */
41494 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41495 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41496 struct sensor_template *attrs)
41497 {
41498 struct device *dev = &resource->acpi_dev->dev;
41499 - struct sensor_device_attribute *sensors =
41500 + sensor_device_attribute_no_const *sensors =
41501 &resource->sensors[resource->num_sensors];
41502 int res = 0;
41503
41504 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41505 index 3288f13..71cfb4e 100644
41506 --- a/drivers/hwmon/applesmc.c
41507 +++ b/drivers/hwmon/applesmc.c
41508 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41509 {
41510 struct applesmc_node_group *grp;
41511 struct applesmc_dev_attr *node;
41512 - struct attribute *attr;
41513 + attribute_no_const *attr;
41514 int ret, i;
41515
41516 for (grp = groups; grp->format; grp++) {
41517 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41518 index ae208f6..48b6c5b 100644
41519 --- a/drivers/hwmon/asus_atk0110.c
41520 +++ b/drivers/hwmon/asus_atk0110.c
41521 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41522 struct atk_sensor_data {
41523 struct list_head list;
41524 struct atk_data *data;
41525 - struct device_attribute label_attr;
41526 - struct device_attribute input_attr;
41527 - struct device_attribute limit1_attr;
41528 - struct device_attribute limit2_attr;
41529 + device_attribute_no_const label_attr;
41530 + device_attribute_no_const input_attr;
41531 + device_attribute_no_const limit1_attr;
41532 + device_attribute_no_const limit2_attr;
41533 char label_attr_name[ATTR_NAME_SIZE];
41534 char input_attr_name[ATTR_NAME_SIZE];
41535 char limit1_attr_name[ATTR_NAME_SIZE];
41536 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41537 static struct device_attribute atk_name_attr =
41538 __ATTR(name, 0444, atk_name_show, NULL);
41539
41540 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41541 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41542 sysfs_show_func show)
41543 {
41544 sysfs_attr_init(&attr->attr);
41545 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41546 index bbb0b0d..9fe1332 100644
41547 --- a/drivers/hwmon/coretemp.c
41548 +++ b/drivers/hwmon/coretemp.c
41549 @@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41550 return NOTIFY_OK;
41551 }
41552
41553 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41554 +static struct notifier_block coretemp_cpu_notifier = {
41555 .notifier_call = coretemp_cpu_callback,
41556 };
41557
41558 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41559 index 632f1dc..57e6a58 100644
41560 --- a/drivers/hwmon/ibmaem.c
41561 +++ b/drivers/hwmon/ibmaem.c
41562 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41563 struct aem_rw_sensor_template *rw)
41564 {
41565 struct device *dev = &data->pdev->dev;
41566 - struct sensor_device_attribute *sensors = data->sensors;
41567 + sensor_device_attribute_no_const *sensors = data->sensors;
41568 int err;
41569
41570 /* Set up read-only sensors */
41571 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41572 index 708081b..fe2d4ab 100644
41573 --- a/drivers/hwmon/iio_hwmon.c
41574 +++ b/drivers/hwmon/iio_hwmon.c
41575 @@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41576 {
41577 struct device *dev = &pdev->dev;
41578 struct iio_hwmon_state *st;
41579 - struct sensor_device_attribute *a;
41580 + sensor_device_attribute_no_const *a;
41581 int ret, i;
41582 int in_i = 1, temp_i = 1, curr_i = 1;
41583 enum iio_chan_type type;
41584 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41585 index 38d5a63..cf2c2ea 100644
41586 --- a/drivers/hwmon/nct6775.c
41587 +++ b/drivers/hwmon/nct6775.c
41588 @@ -944,10 +944,10 @@ static struct attribute_group *
41589 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41590 int repeat)
41591 {
41592 - struct attribute_group *group;
41593 + attribute_group_no_const *group;
41594 struct sensor_device_attr_u *su;
41595 - struct sensor_device_attribute *a;
41596 - struct sensor_device_attribute_2 *a2;
41597 + sensor_device_attribute_no_const *a;
41598 + sensor_device_attribute_2_no_const *a2;
41599 struct attribute **attrs;
41600 struct sensor_device_template **t;
41601 int i, count;
41602 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41603 index 291d11f..3f0dbbd 100644
41604 --- a/drivers/hwmon/pmbus/pmbus_core.c
41605 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41606 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41607 return 0;
41608 }
41609
41610 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41611 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41612 const char *name,
41613 umode_t mode,
41614 ssize_t (*show)(struct device *dev,
41615 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41616 dev_attr->store = store;
41617 }
41618
41619 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41620 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41621 const char *name,
41622 umode_t mode,
41623 ssize_t (*show)(struct device *dev,
41624 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41625 u16 reg, u8 mask)
41626 {
41627 struct pmbus_boolean *boolean;
41628 - struct sensor_device_attribute *a;
41629 + sensor_device_attribute_no_const *a;
41630
41631 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41632 if (!boolean)
41633 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41634 bool update, bool readonly)
41635 {
41636 struct pmbus_sensor *sensor;
41637 - struct device_attribute *a;
41638 + device_attribute_no_const *a;
41639
41640 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41641 if (!sensor)
41642 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41643 const char *lstring, int index)
41644 {
41645 struct pmbus_label *label;
41646 - struct device_attribute *a;
41647 + device_attribute_no_const *a;
41648
41649 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41650 if (!label)
41651 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41652 index 97cd45a..ac54d8b 100644
41653 --- a/drivers/hwmon/sht15.c
41654 +++ b/drivers/hwmon/sht15.c
41655 @@ -169,7 +169,7 @@ struct sht15_data {
41656 int supply_uv;
41657 bool supply_uv_valid;
41658 struct work_struct update_supply_work;
41659 - atomic_t interrupt_handled;
41660 + atomic_unchecked_t interrupt_handled;
41661 };
41662
41663 /**
41664 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41665 ret = gpio_direction_input(data->pdata->gpio_data);
41666 if (ret)
41667 return ret;
41668 - atomic_set(&data->interrupt_handled, 0);
41669 + atomic_set_unchecked(&data->interrupt_handled, 0);
41670
41671 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41672 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41673 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41674 /* Only relevant if the interrupt hasn't occurred. */
41675 - if (!atomic_read(&data->interrupt_handled))
41676 + if (!atomic_read_unchecked(&data->interrupt_handled))
41677 schedule_work(&data->read_work);
41678 }
41679 ret = wait_event_timeout(data->wait_queue,
41680 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41681
41682 /* First disable the interrupt */
41683 disable_irq_nosync(irq);
41684 - atomic_inc(&data->interrupt_handled);
41685 + atomic_inc_unchecked(&data->interrupt_handled);
41686 /* Then schedule a reading work struct */
41687 if (data->state != SHT15_READING_NOTHING)
41688 schedule_work(&data->read_work);
41689 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41690 * If not, then start the interrupt again - care here as could
41691 * have gone low in meantime so verify it hasn't!
41692 */
41693 - atomic_set(&data->interrupt_handled, 0);
41694 + atomic_set_unchecked(&data->interrupt_handled, 0);
41695 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41696 /* If still not occurred or another handler was scheduled */
41697 if (gpio_get_value(data->pdata->gpio_data)
41698 - || atomic_read(&data->interrupt_handled))
41699 + || atomic_read_unchecked(&data->interrupt_handled))
41700 return;
41701 }
41702
41703 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41704 index 38944e9..ae9e5ed 100644
41705 --- a/drivers/hwmon/via-cputemp.c
41706 +++ b/drivers/hwmon/via-cputemp.c
41707 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41708 return NOTIFY_OK;
41709 }
41710
41711 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41712 +static struct notifier_block via_cputemp_cpu_notifier = {
41713 .notifier_call = via_cputemp_cpu_callback,
41714 };
41715
41716 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41717 index 41fc683..a39cfea 100644
41718 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41719 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41720 @@ -43,7 +43,7 @@
41721 extern struct i2c_adapter amd756_smbus;
41722
41723 static struct i2c_adapter *s4882_adapter;
41724 -static struct i2c_algorithm *s4882_algo;
41725 +static i2c_algorithm_no_const *s4882_algo;
41726
41727 /* Wrapper access functions for multiplexed SMBus */
41728 static DEFINE_MUTEX(amd756_lock);
41729 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41730 index 721f7eb..0fd2a09 100644
41731 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41732 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41733 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41734 /* usb layer */
41735
41736 /* Send command to device, and get response. */
41737 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41738 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41739 {
41740 int ret = 0;
41741 int actual;
41742 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41743 index b170bdf..3c76427 100644
41744 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41745 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41746 @@ -41,7 +41,7 @@
41747 extern struct i2c_adapter *nforce2_smbus;
41748
41749 static struct i2c_adapter *s4985_adapter;
41750 -static struct i2c_algorithm *s4985_algo;
41751 +static i2c_algorithm_no_const *s4985_algo;
41752
41753 /* Wrapper access functions for multiplexed SMBus */
41754 static DEFINE_MUTEX(nforce2_lock);
41755 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41756 index 80b47e8..1a6040d9 100644
41757 --- a/drivers/i2c/i2c-dev.c
41758 +++ b/drivers/i2c/i2c-dev.c
41759 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41760 break;
41761 }
41762
41763 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41764 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41765 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41766 if (IS_ERR(rdwr_pa[i].buf)) {
41767 res = PTR_ERR(rdwr_pa[i].buf);
41768 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41769 index 0b510ba..4fbb5085 100644
41770 --- a/drivers/ide/ide-cd.c
41771 +++ b/drivers/ide/ide-cd.c
41772 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41773 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41774 if ((unsigned long)buf & alignment
41775 || blk_rq_bytes(rq) & q->dma_pad_mask
41776 - || object_is_on_stack(buf))
41777 + || object_starts_on_stack(buf))
41778 drive->dma = 0;
41779 }
41780 }
41781 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41782 index acc911a..8700c3c 100644
41783 --- a/drivers/iio/industrialio-core.c
41784 +++ b/drivers/iio/industrialio-core.c
41785 @@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41786 }
41787
41788 static
41789 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41790 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41791 const char *postfix,
41792 struct iio_chan_spec const *chan,
41793 ssize_t (*readfunc)(struct device *dev,
41794 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41795 index 0601b9d..e9dc455 100644
41796 --- a/drivers/infiniband/core/cm.c
41797 +++ b/drivers/infiniband/core/cm.c
41798 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41799
41800 struct cm_counter_group {
41801 struct kobject obj;
41802 - atomic_long_t counter[CM_ATTR_COUNT];
41803 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41804 };
41805
41806 struct cm_counter_attribute {
41807 @@ -1415,7 +1415,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41808 struct ib_mad_send_buf *msg = NULL;
41809 int ret;
41810
41811 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41812 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41813 counter[CM_REQ_COUNTER]);
41814
41815 /* Quick state check to discard duplicate REQs. */
41816 @@ -1802,7 +1802,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41817 if (!cm_id_priv)
41818 return;
41819
41820 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41821 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41822 counter[CM_REP_COUNTER]);
41823 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41824 if (ret)
41825 @@ -1969,7 +1969,7 @@ static int cm_rtu_handler(struct cm_work *work)
41826 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41827 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41828 spin_unlock_irq(&cm_id_priv->lock);
41829 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41830 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41831 counter[CM_RTU_COUNTER]);
41832 goto out;
41833 }
41834 @@ -2152,7 +2152,7 @@ static int cm_dreq_handler(struct cm_work *work)
41835 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41836 dreq_msg->local_comm_id);
41837 if (!cm_id_priv) {
41838 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41839 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41840 counter[CM_DREQ_COUNTER]);
41841 cm_issue_drep(work->port, work->mad_recv_wc);
41842 return -EINVAL;
41843 @@ -2177,7 +2177,7 @@ static int cm_dreq_handler(struct cm_work *work)
41844 case IB_CM_MRA_REP_RCVD:
41845 break;
41846 case IB_CM_TIMEWAIT:
41847 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41848 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41849 counter[CM_DREQ_COUNTER]);
41850 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41851 goto unlock;
41852 @@ -2191,7 +2191,7 @@ static int cm_dreq_handler(struct cm_work *work)
41853 cm_free_msg(msg);
41854 goto deref;
41855 case IB_CM_DREQ_RCVD:
41856 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41857 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41858 counter[CM_DREQ_COUNTER]);
41859 goto unlock;
41860 default:
41861 @@ -2558,7 +2558,7 @@ static int cm_mra_handler(struct cm_work *work)
41862 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41863 cm_id_priv->msg, timeout)) {
41864 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41865 - atomic_long_inc(&work->port->
41866 + atomic_long_inc_unchecked(&work->port->
41867 counter_group[CM_RECV_DUPLICATES].
41868 counter[CM_MRA_COUNTER]);
41869 goto out;
41870 @@ -2567,7 +2567,7 @@ static int cm_mra_handler(struct cm_work *work)
41871 break;
41872 case IB_CM_MRA_REQ_RCVD:
41873 case IB_CM_MRA_REP_RCVD:
41874 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41875 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41876 counter[CM_MRA_COUNTER]);
41877 /* fall through */
41878 default:
41879 @@ -2729,7 +2729,7 @@ static int cm_lap_handler(struct cm_work *work)
41880 case IB_CM_LAP_IDLE:
41881 break;
41882 case IB_CM_MRA_LAP_SENT:
41883 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41884 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41885 counter[CM_LAP_COUNTER]);
41886 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41887 goto unlock;
41888 @@ -2745,7 +2745,7 @@ static int cm_lap_handler(struct cm_work *work)
41889 cm_free_msg(msg);
41890 goto deref;
41891 case IB_CM_LAP_RCVD:
41892 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41893 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41894 counter[CM_LAP_COUNTER]);
41895 goto unlock;
41896 default:
41897 @@ -3029,7 +3029,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41898 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41899 if (cur_cm_id_priv) {
41900 spin_unlock_irq(&cm.lock);
41901 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41902 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41903 counter[CM_SIDR_REQ_COUNTER]);
41904 goto out; /* Duplicate message. */
41905 }
41906 @@ -3241,10 +3241,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41907 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41908 msg->retries = 1;
41909
41910 - atomic_long_add(1 + msg->retries,
41911 + atomic_long_add_unchecked(1 + msg->retries,
41912 &port->counter_group[CM_XMIT].counter[attr_index]);
41913 if (msg->retries)
41914 - atomic_long_add(msg->retries,
41915 + atomic_long_add_unchecked(msg->retries,
41916 &port->counter_group[CM_XMIT_RETRIES].
41917 counter[attr_index]);
41918
41919 @@ -3454,7 +3454,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
41920 }
41921
41922 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
41923 - atomic_long_inc(&port->counter_group[CM_RECV].
41924 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
41925 counter[attr_id - CM_ATTR_ID_OFFSET]);
41926
41927 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
41928 @@ -3685,7 +3685,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
41929 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
41930
41931 return sprintf(buf, "%ld\n",
41932 - atomic_long_read(&group->counter[cm_attr->index]));
41933 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
41934 }
41935
41936 static const struct sysfs_ops cm_counter_ops = {
41937 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
41938 index 9f5ad7c..588cd84 100644
41939 --- a/drivers/infiniband/core/fmr_pool.c
41940 +++ b/drivers/infiniband/core/fmr_pool.c
41941 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
41942
41943 struct task_struct *thread;
41944
41945 - atomic_t req_ser;
41946 - atomic_t flush_ser;
41947 + atomic_unchecked_t req_ser;
41948 + atomic_unchecked_t flush_ser;
41949
41950 wait_queue_head_t force_wait;
41951 };
41952 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41953 struct ib_fmr_pool *pool = pool_ptr;
41954
41955 do {
41956 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
41957 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
41958 ib_fmr_batch_release(pool);
41959
41960 - atomic_inc(&pool->flush_ser);
41961 + atomic_inc_unchecked(&pool->flush_ser);
41962 wake_up_interruptible(&pool->force_wait);
41963
41964 if (pool->flush_function)
41965 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41966 }
41967
41968 set_current_state(TASK_INTERRUPTIBLE);
41969 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
41970 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
41971 !kthread_should_stop())
41972 schedule();
41973 __set_current_state(TASK_RUNNING);
41974 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
41975 pool->dirty_watermark = params->dirty_watermark;
41976 pool->dirty_len = 0;
41977 spin_lock_init(&pool->pool_lock);
41978 - atomic_set(&pool->req_ser, 0);
41979 - atomic_set(&pool->flush_ser, 0);
41980 + atomic_set_unchecked(&pool->req_ser, 0);
41981 + atomic_set_unchecked(&pool->flush_ser, 0);
41982 init_waitqueue_head(&pool->force_wait);
41983
41984 pool->thread = kthread_run(ib_fmr_cleanup_thread,
41985 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
41986 }
41987 spin_unlock_irq(&pool->pool_lock);
41988
41989 - serial = atomic_inc_return(&pool->req_ser);
41990 + serial = atomic_inc_return_unchecked(&pool->req_ser);
41991 wake_up_process(pool->thread);
41992
41993 if (wait_event_interruptible(pool->force_wait,
41994 - atomic_read(&pool->flush_ser) - serial >= 0))
41995 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
41996 return -EINTR;
41997
41998 return 0;
41999 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42000 } else {
42001 list_add_tail(&fmr->list, &pool->dirty_list);
42002 if (++pool->dirty_len >= pool->dirty_watermark) {
42003 - atomic_inc(&pool->req_ser);
42004 + atomic_inc_unchecked(&pool->req_ser);
42005 wake_up_process(pool->thread);
42006 }
42007 }
42008 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42009 index 41b1195..27971a0 100644
42010 --- a/drivers/infiniband/hw/cxgb4/mem.c
42011 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42012 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42013 int err;
42014 struct fw_ri_tpte tpt;
42015 u32 stag_idx;
42016 - static atomic_t key;
42017 + static atomic_unchecked_t key;
42018
42019 if (c4iw_fatal_error(rdev))
42020 return -EIO;
42021 @@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42022 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42023 rdev->stats.stag.max = rdev->stats.stag.cur;
42024 mutex_unlock(&rdev->stats.lock);
42025 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42026 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42027 }
42028 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42029 __func__, stag_state, type, pdid, stag_idx);
42030 diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42031 index 644c2c7..ecf0879 100644
42032 --- a/drivers/infiniband/hw/ipath/ipath_dma.c
42033 +++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42034 @@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42035 }
42036
42037 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42038 - ipath_mapping_error,
42039 - ipath_dma_map_single,
42040 - ipath_dma_unmap_single,
42041 - ipath_dma_map_page,
42042 - ipath_dma_unmap_page,
42043 - ipath_map_sg,
42044 - ipath_unmap_sg,
42045 - ipath_sg_dma_address,
42046 - ipath_sg_dma_len,
42047 - ipath_sync_single_for_cpu,
42048 - ipath_sync_single_for_device,
42049 - ipath_dma_alloc_coherent,
42050 - ipath_dma_free_coherent
42051 + .mapping_error = ipath_mapping_error,
42052 + .map_single = ipath_dma_map_single,
42053 + .unmap_single = ipath_dma_unmap_single,
42054 + .map_page = ipath_dma_map_page,
42055 + .unmap_page = ipath_dma_unmap_page,
42056 + .map_sg = ipath_map_sg,
42057 + .unmap_sg = ipath_unmap_sg,
42058 + .dma_address = ipath_sg_dma_address,
42059 + .dma_len = ipath_sg_dma_len,
42060 + .sync_single_for_cpu = ipath_sync_single_for_cpu,
42061 + .sync_single_for_device = ipath_sync_single_for_device,
42062 + .alloc_coherent = ipath_dma_alloc_coherent,
42063 + .free_coherent = ipath_dma_free_coherent
42064 };
42065 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42066 index 79b3dbc..96e5fcc 100644
42067 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42068 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42069 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42070 struct ib_atomic_eth *ateth;
42071 struct ipath_ack_entry *e;
42072 u64 vaddr;
42073 - atomic64_t *maddr;
42074 + atomic64_unchecked_t *maddr;
42075 u64 sdata;
42076 u32 rkey;
42077 u8 next;
42078 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42079 IB_ACCESS_REMOTE_ATOMIC)))
42080 goto nack_acc_unlck;
42081 /* Perform atomic OP and save result. */
42082 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42083 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42084 sdata = be64_to_cpu(ateth->swap_data);
42085 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42086 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42087 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42088 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42089 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42090 be64_to_cpu(ateth->compare_data),
42091 sdata);
42092 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42093 index 1f95bba..9530f87 100644
42094 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42095 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42096 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42097 unsigned long flags;
42098 struct ib_wc wc;
42099 u64 sdata;
42100 - atomic64_t *maddr;
42101 + atomic64_unchecked_t *maddr;
42102 enum ib_wc_status send_status;
42103
42104 /*
42105 @@ -382,11 +382,11 @@ again:
42106 IB_ACCESS_REMOTE_ATOMIC)))
42107 goto acc_err;
42108 /* Perform atomic OP and save result. */
42109 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42110 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42111 sdata = wqe->wr.wr.atomic.compare_add;
42112 *(u64 *) sqp->s_sge.sge.vaddr =
42113 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42114 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42115 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42116 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42117 sdata, wqe->wr.wr.atomic.swap);
42118 goto send_comp;
42119 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42120 index f2a3f48..673ec79 100644
42121 --- a/drivers/infiniband/hw/mlx4/mad.c
42122 +++ b/drivers/infiniband/hw/mlx4/mad.c
42123 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42124
42125 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42126 {
42127 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42128 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42129 cpu_to_be64(0xff00000000000000LL);
42130 }
42131
42132 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42133 index 25b2cdf..099ff97 100644
42134 --- a/drivers/infiniband/hw/mlx4/mcg.c
42135 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42136 @@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42137 {
42138 char name[20];
42139
42140 - atomic_set(&ctx->tid, 0);
42141 + atomic_set_unchecked(&ctx->tid, 0);
42142 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42143 ctx->mcg_wq = create_singlethread_workqueue(name);
42144 if (!ctx->mcg_wq)
42145 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42146 index a230683..3723f2d 100644
42147 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42148 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42149 @@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42150 struct list_head mcg_mgid0_list;
42151 struct workqueue_struct *mcg_wq;
42152 struct mlx4_ib_demux_pv_ctx **tun;
42153 - atomic_t tid;
42154 + atomic_unchecked_t tid;
42155 int flushing; /* flushing the work queue */
42156 };
42157
42158 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42159 index 9d3e5c1..6f166df 100644
42160 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42161 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42162 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42163 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42164 }
42165
42166 -int mthca_QUERY_FW(struct mthca_dev *dev)
42167 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42168 {
42169 struct mthca_mailbox *mailbox;
42170 u32 *outbox;
42171 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42172 CMD_TIME_CLASS_B);
42173 }
42174
42175 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42176 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42177 int num_mtt)
42178 {
42179 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42180 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42181 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42182 }
42183
42184 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42185 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42186 int eq_num)
42187 {
42188 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42189 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42190 CMD_TIME_CLASS_B);
42191 }
42192
42193 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42194 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42195 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42196 void *in_mad, void *response_mad)
42197 {
42198 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42199 index 87897b9..7e79542 100644
42200 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42201 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42202 @@ -692,7 +692,7 @@ err_close:
42203 return err;
42204 }
42205
42206 -static int mthca_setup_hca(struct mthca_dev *dev)
42207 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42208 {
42209 int err;
42210
42211 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42212 index ed9a989..6aa5dc2 100644
42213 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42214 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42215 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42216 * through the bitmaps)
42217 */
42218
42219 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42220 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42221 {
42222 int o;
42223 int m;
42224 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42225 return key;
42226 }
42227
42228 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42229 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42230 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42231 {
42232 struct mthca_mailbox *mailbox;
42233 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42234 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42235 }
42236
42237 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42238 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42239 u64 *buffer_list, int buffer_size_shift,
42240 int list_len, u64 iova, u64 total_size,
42241 u32 access, struct mthca_mr *mr)
42242 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42243 index 5b71d43..35a9e14 100644
42244 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42245 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42246 @@ -763,7 +763,7 @@ unlock:
42247 return 0;
42248 }
42249
42250 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42251 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42252 {
42253 struct mthca_dev *dev = to_mdev(ibcq->device);
42254 struct mthca_cq *cq = to_mcq(ibcq);
42255 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42256 index 353c7b0..c6ce921 100644
42257 --- a/drivers/infiniband/hw/nes/nes.c
42258 +++ b/drivers/infiniband/hw/nes/nes.c
42259 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42260 LIST_HEAD(nes_adapter_list);
42261 static LIST_HEAD(nes_dev_list);
42262
42263 -atomic_t qps_destroyed;
42264 +atomic_unchecked_t qps_destroyed;
42265
42266 static unsigned int ee_flsh_adapter;
42267 static unsigned int sysfs_nonidx_addr;
42268 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42269 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42270 struct nes_adapter *nesadapter = nesdev->nesadapter;
42271
42272 - atomic_inc(&qps_destroyed);
42273 + atomic_inc_unchecked(&qps_destroyed);
42274
42275 /* Free the control structures */
42276
42277 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42278 index 33cc589..3bd6538 100644
42279 --- a/drivers/infiniband/hw/nes/nes.h
42280 +++ b/drivers/infiniband/hw/nes/nes.h
42281 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42282 extern unsigned int wqm_quanta;
42283 extern struct list_head nes_adapter_list;
42284
42285 -extern atomic_t cm_connects;
42286 -extern atomic_t cm_accepts;
42287 -extern atomic_t cm_disconnects;
42288 -extern atomic_t cm_closes;
42289 -extern atomic_t cm_connecteds;
42290 -extern atomic_t cm_connect_reqs;
42291 -extern atomic_t cm_rejects;
42292 -extern atomic_t mod_qp_timouts;
42293 -extern atomic_t qps_created;
42294 -extern atomic_t qps_destroyed;
42295 -extern atomic_t sw_qps_destroyed;
42296 +extern atomic_unchecked_t cm_connects;
42297 +extern atomic_unchecked_t cm_accepts;
42298 +extern atomic_unchecked_t cm_disconnects;
42299 +extern atomic_unchecked_t cm_closes;
42300 +extern atomic_unchecked_t cm_connecteds;
42301 +extern atomic_unchecked_t cm_connect_reqs;
42302 +extern atomic_unchecked_t cm_rejects;
42303 +extern atomic_unchecked_t mod_qp_timouts;
42304 +extern atomic_unchecked_t qps_created;
42305 +extern atomic_unchecked_t qps_destroyed;
42306 +extern atomic_unchecked_t sw_qps_destroyed;
42307 extern u32 mh_detected;
42308 extern u32 mh_pauses_sent;
42309 extern u32 cm_packets_sent;
42310 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42311 extern u32 cm_packets_received;
42312 extern u32 cm_packets_dropped;
42313 extern u32 cm_packets_retrans;
42314 -extern atomic_t cm_listens_created;
42315 -extern atomic_t cm_listens_destroyed;
42316 +extern atomic_unchecked_t cm_listens_created;
42317 +extern atomic_unchecked_t cm_listens_destroyed;
42318 extern u32 cm_backlog_drops;
42319 -extern atomic_t cm_loopbacks;
42320 -extern atomic_t cm_nodes_created;
42321 -extern atomic_t cm_nodes_destroyed;
42322 -extern atomic_t cm_accel_dropped_pkts;
42323 -extern atomic_t cm_resets_recvd;
42324 -extern atomic_t pau_qps_created;
42325 -extern atomic_t pau_qps_destroyed;
42326 +extern atomic_unchecked_t cm_loopbacks;
42327 +extern atomic_unchecked_t cm_nodes_created;
42328 +extern atomic_unchecked_t cm_nodes_destroyed;
42329 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42330 +extern atomic_unchecked_t cm_resets_recvd;
42331 +extern atomic_unchecked_t pau_qps_created;
42332 +extern atomic_unchecked_t pau_qps_destroyed;
42333
42334 extern u32 int_mod_timer_init;
42335 extern u32 int_mod_cq_depth_256;
42336 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42337 index 9c9f2f5..2559190 100644
42338 --- a/drivers/infiniband/hw/nes/nes_cm.c
42339 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42340 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42341 u32 cm_packets_retrans;
42342 u32 cm_packets_created;
42343 u32 cm_packets_received;
42344 -atomic_t cm_listens_created;
42345 -atomic_t cm_listens_destroyed;
42346 +atomic_unchecked_t cm_listens_created;
42347 +atomic_unchecked_t cm_listens_destroyed;
42348 u32 cm_backlog_drops;
42349 -atomic_t cm_loopbacks;
42350 -atomic_t cm_nodes_created;
42351 -atomic_t cm_nodes_destroyed;
42352 -atomic_t cm_accel_dropped_pkts;
42353 -atomic_t cm_resets_recvd;
42354 +atomic_unchecked_t cm_loopbacks;
42355 +atomic_unchecked_t cm_nodes_created;
42356 +atomic_unchecked_t cm_nodes_destroyed;
42357 +atomic_unchecked_t cm_accel_dropped_pkts;
42358 +atomic_unchecked_t cm_resets_recvd;
42359
42360 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42361 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42362 @@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42363 /* instance of function pointers for client API */
42364 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42365 static struct nes_cm_ops nes_cm_api = {
42366 - mini_cm_accelerated,
42367 - mini_cm_listen,
42368 - mini_cm_del_listen,
42369 - mini_cm_connect,
42370 - mini_cm_close,
42371 - mini_cm_accept,
42372 - mini_cm_reject,
42373 - mini_cm_recv_pkt,
42374 - mini_cm_dealloc_core,
42375 - mini_cm_get,
42376 - mini_cm_set
42377 + .accelerated = mini_cm_accelerated,
42378 + .listen = mini_cm_listen,
42379 + .stop_listener = mini_cm_del_listen,
42380 + .connect = mini_cm_connect,
42381 + .close = mini_cm_close,
42382 + .accept = mini_cm_accept,
42383 + .reject = mini_cm_reject,
42384 + .recv_pkt = mini_cm_recv_pkt,
42385 + .destroy_cm_core = mini_cm_dealloc_core,
42386 + .get = mini_cm_get,
42387 + .set = mini_cm_set
42388 };
42389
42390 static struct nes_cm_core *g_cm_core;
42391
42392 -atomic_t cm_connects;
42393 -atomic_t cm_accepts;
42394 -atomic_t cm_disconnects;
42395 -atomic_t cm_closes;
42396 -atomic_t cm_connecteds;
42397 -atomic_t cm_connect_reqs;
42398 -atomic_t cm_rejects;
42399 +atomic_unchecked_t cm_connects;
42400 +atomic_unchecked_t cm_accepts;
42401 +atomic_unchecked_t cm_disconnects;
42402 +atomic_unchecked_t cm_closes;
42403 +atomic_unchecked_t cm_connecteds;
42404 +atomic_unchecked_t cm_connect_reqs;
42405 +atomic_unchecked_t cm_rejects;
42406
42407 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42408 {
42409 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42410 kfree(listener);
42411 listener = NULL;
42412 ret = 0;
42413 - atomic_inc(&cm_listens_destroyed);
42414 + atomic_inc_unchecked(&cm_listens_destroyed);
42415 } else {
42416 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42417 }
42418 @@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42419 cm_node->rem_mac);
42420
42421 add_hte_node(cm_core, cm_node);
42422 - atomic_inc(&cm_nodes_created);
42423 + atomic_inc_unchecked(&cm_nodes_created);
42424
42425 return cm_node;
42426 }
42427 @@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42428 }
42429
42430 atomic_dec(&cm_core->node_cnt);
42431 - atomic_inc(&cm_nodes_destroyed);
42432 + atomic_inc_unchecked(&cm_nodes_destroyed);
42433 nesqp = cm_node->nesqp;
42434 if (nesqp) {
42435 nesqp->cm_node = NULL;
42436 @@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42437
42438 static void drop_packet(struct sk_buff *skb)
42439 {
42440 - atomic_inc(&cm_accel_dropped_pkts);
42441 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42442 dev_kfree_skb_any(skb);
42443 }
42444
42445 @@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42446 {
42447
42448 int reset = 0; /* whether to send reset in case of err.. */
42449 - atomic_inc(&cm_resets_recvd);
42450 + atomic_inc_unchecked(&cm_resets_recvd);
42451 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42452 " refcnt=%d\n", cm_node, cm_node->state,
42453 atomic_read(&cm_node->ref_count));
42454 @@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42455 rem_ref_cm_node(cm_node->cm_core, cm_node);
42456 return NULL;
42457 }
42458 - atomic_inc(&cm_loopbacks);
42459 + atomic_inc_unchecked(&cm_loopbacks);
42460 loopbackremotenode->loopbackpartner = cm_node;
42461 loopbackremotenode->tcp_cntxt.rcv_wscale =
42462 NES_CM_DEFAULT_RCV_WND_SCALE;
42463 @@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42464 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42465 else {
42466 rem_ref_cm_node(cm_core, cm_node);
42467 - atomic_inc(&cm_accel_dropped_pkts);
42468 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42469 dev_kfree_skb_any(skb);
42470 }
42471 break;
42472 @@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42473
42474 if ((cm_id) && (cm_id->event_handler)) {
42475 if (issue_disconn) {
42476 - atomic_inc(&cm_disconnects);
42477 + atomic_inc_unchecked(&cm_disconnects);
42478 cm_event.event = IW_CM_EVENT_DISCONNECT;
42479 cm_event.status = disconn_status;
42480 cm_event.local_addr = cm_id->local_addr;
42481 @@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42482 }
42483
42484 if (issue_close) {
42485 - atomic_inc(&cm_closes);
42486 + atomic_inc_unchecked(&cm_closes);
42487 nes_disconnect(nesqp, 1);
42488
42489 cm_id->provider_data = nesqp;
42490 @@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42491
42492 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42493 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42494 - atomic_inc(&cm_accepts);
42495 + atomic_inc_unchecked(&cm_accepts);
42496
42497 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42498 netdev_refcnt_read(nesvnic->netdev));
42499 @@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42500 struct nes_cm_core *cm_core;
42501 u8 *start_buff;
42502
42503 - atomic_inc(&cm_rejects);
42504 + atomic_inc_unchecked(&cm_rejects);
42505 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42506 loopback = cm_node->loopbackpartner;
42507 cm_core = cm_node->cm_core;
42508 @@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42509 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42510 ntohs(laddr->sin_port));
42511
42512 - atomic_inc(&cm_connects);
42513 + atomic_inc_unchecked(&cm_connects);
42514 nesqp->active_conn = 1;
42515
42516 /* cache the cm_id in the qp */
42517 @@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42518 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42519 return err;
42520 }
42521 - atomic_inc(&cm_listens_created);
42522 + atomic_inc_unchecked(&cm_listens_created);
42523 }
42524
42525 cm_id->add_ref(cm_id);
42526 @@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42527
42528 if (nesqp->destroyed)
42529 return;
42530 - atomic_inc(&cm_connecteds);
42531 + atomic_inc_unchecked(&cm_connecteds);
42532 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42533 " local port 0x%04X. jiffies = %lu.\n",
42534 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42535 @@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42536
42537 cm_id->add_ref(cm_id);
42538 ret = cm_id->event_handler(cm_id, &cm_event);
42539 - atomic_inc(&cm_closes);
42540 + atomic_inc_unchecked(&cm_closes);
42541 cm_event.event = IW_CM_EVENT_CLOSE;
42542 cm_event.status = 0;
42543 cm_event.provider_data = cm_id->provider_data;
42544 @@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42545 return;
42546 cm_id = cm_node->cm_id;
42547
42548 - atomic_inc(&cm_connect_reqs);
42549 + atomic_inc_unchecked(&cm_connect_reqs);
42550 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42551 cm_node, cm_id, jiffies);
42552
42553 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42554 return;
42555 cm_id = cm_node->cm_id;
42556
42557 - atomic_inc(&cm_connect_reqs);
42558 + atomic_inc_unchecked(&cm_connect_reqs);
42559 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42560 cm_node, cm_id, jiffies);
42561
42562 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42563 index 4166452..fc952c3 100644
42564 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42565 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42566 @@ -40,8 +40,8 @@
42567 #include "nes.h"
42568 #include "nes_mgt.h"
42569
42570 -atomic_t pau_qps_created;
42571 -atomic_t pau_qps_destroyed;
42572 +atomic_unchecked_t pau_qps_created;
42573 +atomic_unchecked_t pau_qps_destroyed;
42574
42575 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42576 {
42577 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42578 {
42579 struct sk_buff *skb;
42580 unsigned long flags;
42581 - atomic_inc(&pau_qps_destroyed);
42582 + atomic_inc_unchecked(&pau_qps_destroyed);
42583
42584 /* Free packets that have not yet been forwarded */
42585 /* Lock is acquired by skb_dequeue when removing the skb */
42586 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42587 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42588 skb_queue_head_init(&nesqp->pau_list);
42589 spin_lock_init(&nesqp->pau_lock);
42590 - atomic_inc(&pau_qps_created);
42591 + atomic_inc_unchecked(&pau_qps_created);
42592 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42593 }
42594
42595 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42596 index 49eb511..a774366 100644
42597 --- a/drivers/infiniband/hw/nes/nes_nic.c
42598 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42599 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42600 target_stat_values[++index] = mh_detected;
42601 target_stat_values[++index] = mh_pauses_sent;
42602 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42603 - target_stat_values[++index] = atomic_read(&cm_connects);
42604 - target_stat_values[++index] = atomic_read(&cm_accepts);
42605 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42606 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42607 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42608 - target_stat_values[++index] = atomic_read(&cm_rejects);
42609 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42610 - target_stat_values[++index] = atomic_read(&qps_created);
42611 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42612 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42613 - target_stat_values[++index] = atomic_read(&cm_closes);
42614 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42615 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42616 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42617 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42618 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42619 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42620 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42621 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42622 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42623 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42624 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42625 target_stat_values[++index] = cm_packets_sent;
42626 target_stat_values[++index] = cm_packets_bounced;
42627 target_stat_values[++index] = cm_packets_created;
42628 target_stat_values[++index] = cm_packets_received;
42629 target_stat_values[++index] = cm_packets_dropped;
42630 target_stat_values[++index] = cm_packets_retrans;
42631 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42632 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42633 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42634 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42635 target_stat_values[++index] = cm_backlog_drops;
42636 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42637 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42638 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42639 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42640 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42641 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42642 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42643 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42644 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42645 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42646 target_stat_values[++index] = nesadapter->free_4kpbl;
42647 target_stat_values[++index] = nesadapter->free_256pbl;
42648 target_stat_values[++index] = int_mod_timer_init;
42649 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42650 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42651 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42652 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42653 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42654 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42655 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42656 }
42657
42658 /**
42659 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42660 index 8308e36..ae0d3b5 100644
42661 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42662 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42663 @@ -46,9 +46,9 @@
42664
42665 #include <rdma/ib_umem.h>
42666
42667 -atomic_t mod_qp_timouts;
42668 -atomic_t qps_created;
42669 -atomic_t sw_qps_destroyed;
42670 +atomic_unchecked_t mod_qp_timouts;
42671 +atomic_unchecked_t qps_created;
42672 +atomic_unchecked_t sw_qps_destroyed;
42673
42674 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42675
42676 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42677 if (init_attr->create_flags)
42678 return ERR_PTR(-EINVAL);
42679
42680 - atomic_inc(&qps_created);
42681 + atomic_inc_unchecked(&qps_created);
42682 switch (init_attr->qp_type) {
42683 case IB_QPT_RC:
42684 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42685 @@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42686 struct iw_cm_event cm_event;
42687 int ret = 0;
42688
42689 - atomic_inc(&sw_qps_destroyed);
42690 + atomic_inc_unchecked(&sw_qps_destroyed);
42691 nesqp->destroyed = 1;
42692
42693 /* Blow away the connection if it exists. */
42694 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42695 index 1946101..09766d2 100644
42696 --- a/drivers/infiniband/hw/qib/qib.h
42697 +++ b/drivers/infiniband/hw/qib/qib.h
42698 @@ -52,6 +52,7 @@
42699 #include <linux/kref.h>
42700 #include <linux/sched.h>
42701 #include <linux/kthread.h>
42702 +#include <linux/slab.h>
42703
42704 #include "qib_common.h"
42705 #include "qib_verbs.h"
42706 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42707 index 24c41ba..102d71f 100644
42708 --- a/drivers/input/gameport/gameport.c
42709 +++ b/drivers/input/gameport/gameport.c
42710 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42711 */
42712 static void gameport_init_port(struct gameport *gameport)
42713 {
42714 - static atomic_t gameport_no = ATOMIC_INIT(0);
42715 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42716
42717 __module_get(THIS_MODULE);
42718
42719 mutex_init(&gameport->drv_mutex);
42720 device_initialize(&gameport->dev);
42721 dev_set_name(&gameport->dev, "gameport%lu",
42722 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42723 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42724 gameport->dev.bus = &gameport_bus;
42725 gameport->dev.release = gameport_release_port;
42726 if (gameport->parent)
42727 diff --git a/drivers/input/input.c b/drivers/input/input.c
42728 index 1c4c0db..6f7abe3 100644
42729 --- a/drivers/input/input.c
42730 +++ b/drivers/input/input.c
42731 @@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42732 */
42733 struct input_dev *input_allocate_device(void)
42734 {
42735 - static atomic_t input_no = ATOMIC_INIT(0);
42736 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42737 struct input_dev *dev;
42738
42739 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42740 @@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42741 INIT_LIST_HEAD(&dev->node);
42742
42743 dev_set_name(&dev->dev, "input%ld",
42744 - (unsigned long) atomic_inc_return(&input_no) - 1);
42745 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42746
42747 __module_get(THIS_MODULE);
42748 }
42749 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42750 index 4a95b22..874c182 100644
42751 --- a/drivers/input/joystick/sidewinder.c
42752 +++ b/drivers/input/joystick/sidewinder.c
42753 @@ -30,6 +30,7 @@
42754 #include <linux/kernel.h>
42755 #include <linux/module.h>
42756 #include <linux/slab.h>
42757 +#include <linux/sched.h>
42758 #include <linux/input.h>
42759 #include <linux/gameport.h>
42760 #include <linux/jiffies.h>
42761 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42762 index 603fe0d..f63decc 100644
42763 --- a/drivers/input/joystick/xpad.c
42764 +++ b/drivers/input/joystick/xpad.c
42765 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42766
42767 static int xpad_led_probe(struct usb_xpad *xpad)
42768 {
42769 - static atomic_t led_seq = ATOMIC_INIT(0);
42770 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42771 long led_no;
42772 struct xpad_led *led;
42773 struct led_classdev *led_cdev;
42774 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42775 if (!led)
42776 return -ENOMEM;
42777
42778 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42779 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42780
42781 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42782 led->xpad = xpad;
42783 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42784 index e204f26..8459f15 100644
42785 --- a/drivers/input/misc/ims-pcu.c
42786 +++ b/drivers/input/misc/ims-pcu.c
42787 @@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42788
42789 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42790 {
42791 - static atomic_t device_no = ATOMIC_INIT(0);
42792 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42793
42794 const struct ims_pcu_device_info *info;
42795 u8 device_id;
42796 @@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42797 }
42798
42799 /* Device appears to be operable, complete initialization */
42800 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42801 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42802
42803 error = ims_pcu_setup_backlight(pcu);
42804 if (error)
42805 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42806 index 2f0b39d..7370f13 100644
42807 --- a/drivers/input/mouse/psmouse.h
42808 +++ b/drivers/input/mouse/psmouse.h
42809 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42810 ssize_t (*set)(struct psmouse *psmouse, void *data,
42811 const char *buf, size_t count);
42812 bool protect;
42813 -};
42814 +} __do_const;
42815 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42816
42817 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42818 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42819 index b604564..3f14ae4 100644
42820 --- a/drivers/input/mousedev.c
42821 +++ b/drivers/input/mousedev.c
42822 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42823
42824 spin_unlock_irq(&client->packet_lock);
42825
42826 - if (copy_to_user(buffer, data, count))
42827 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42828 return -EFAULT;
42829
42830 return count;
42831 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42832 index 8f4c4ab..5fc8a45 100644
42833 --- a/drivers/input/serio/serio.c
42834 +++ b/drivers/input/serio/serio.c
42835 @@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42836 */
42837 static void serio_init_port(struct serio *serio)
42838 {
42839 - static atomic_t serio_no = ATOMIC_INIT(0);
42840 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42841
42842 __module_get(THIS_MODULE);
42843
42844 @@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42845 mutex_init(&serio->drv_mutex);
42846 device_initialize(&serio->dev);
42847 dev_set_name(&serio->dev, "serio%ld",
42848 - (long)atomic_inc_return(&serio_no) - 1);
42849 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
42850 serio->dev.bus = &serio_bus;
42851 serio->dev.release = serio_release_port;
42852 serio->dev.groups = serio_device_attr_groups;
42853 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42854 index c9a02fe..0debc75 100644
42855 --- a/drivers/input/serio/serio_raw.c
42856 +++ b/drivers/input/serio/serio_raw.c
42857 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42858
42859 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42860 {
42861 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
42862 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42863 struct serio_raw *serio_raw;
42864 int err;
42865
42866 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42867 }
42868
42869 snprintf(serio_raw->name, sizeof(serio_raw->name),
42870 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42871 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42872 kref_init(&serio_raw->kref);
42873 INIT_LIST_HEAD(&serio_raw->client_list);
42874 init_waitqueue_head(&serio_raw->wait);
42875 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42876 index e5555fc..937986d 100644
42877 --- a/drivers/iommu/iommu.c
42878 +++ b/drivers/iommu/iommu.c
42879 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42880 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42881 {
42882 bus_register_notifier(bus, &iommu_bus_nb);
42883 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42884 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42885 }
42886
42887 /**
42888 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42889 index 228632c9..edfe331 100644
42890 --- a/drivers/iommu/irq_remapping.c
42891 +++ b/drivers/iommu/irq_remapping.c
42892 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42893 void panic_if_irq_remap(const char *msg)
42894 {
42895 if (irq_remapping_enabled)
42896 - panic(msg);
42897 + panic("%s", msg);
42898 }
42899
42900 static void ir_ack_apic_edge(struct irq_data *data)
42901 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42902
42903 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42904 {
42905 - chip->irq_print_chip = ir_print_prefix;
42906 - chip->irq_ack = ir_ack_apic_edge;
42907 - chip->irq_eoi = ir_ack_apic_level;
42908 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42909 + pax_open_kernel();
42910 + *(void **)&chip->irq_print_chip = ir_print_prefix;
42911 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
42912 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
42913 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42914 + pax_close_kernel();
42915 }
42916
42917 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42918 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
42919 index 341c601..e5f407e 100644
42920 --- a/drivers/irqchip/irq-gic.c
42921 +++ b/drivers/irqchip/irq-gic.c
42922 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
42923 * Supported arch specific GIC irq extension.
42924 * Default make them NULL.
42925 */
42926 -struct irq_chip gic_arch_extn = {
42927 +irq_chip_no_const gic_arch_extn = {
42928 .irq_eoi = NULL,
42929 .irq_mask = NULL,
42930 .irq_unmask = NULL,
42931 @@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
42932 chained_irq_exit(chip, desc);
42933 }
42934
42935 -static struct irq_chip gic_chip = {
42936 +static irq_chip_no_const gic_chip __read_only = {
42937 .name = "GIC",
42938 .irq_mask = gic_mask_irq,
42939 .irq_unmask = gic_unmask_irq,
42940 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
42941 index ac6f72b..81150f2 100644
42942 --- a/drivers/isdn/capi/capi.c
42943 +++ b/drivers/isdn/capi/capi.c
42944 @@ -81,8 +81,8 @@ struct capiminor {
42945
42946 struct capi20_appl *ap;
42947 u32 ncci;
42948 - atomic_t datahandle;
42949 - atomic_t msgid;
42950 + atomic_unchecked_t datahandle;
42951 + atomic_unchecked_t msgid;
42952
42953 struct tty_port port;
42954 int ttyinstop;
42955 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
42956 capimsg_setu16(s, 2, mp->ap->applid);
42957 capimsg_setu8 (s, 4, CAPI_DATA_B3);
42958 capimsg_setu8 (s, 5, CAPI_RESP);
42959 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
42960 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
42961 capimsg_setu32(s, 8, mp->ncci);
42962 capimsg_setu16(s, 12, datahandle);
42963 }
42964 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
42965 mp->outbytes -= len;
42966 spin_unlock_bh(&mp->outlock);
42967
42968 - datahandle = atomic_inc_return(&mp->datahandle);
42969 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
42970 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
42971 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42972 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42973 capimsg_setu16(skb->data, 2, mp->ap->applid);
42974 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
42975 capimsg_setu8 (skb->data, 5, CAPI_REQ);
42976 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
42977 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
42978 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
42979 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
42980 capimsg_setu16(skb->data, 16, len); /* Data length */
42981 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
42982 index c44950d..10ac276 100644
42983 --- a/drivers/isdn/gigaset/bas-gigaset.c
42984 +++ b/drivers/isdn/gigaset/bas-gigaset.c
42985 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
42986
42987
42988 static const struct gigaset_ops gigops = {
42989 - gigaset_write_cmd,
42990 - gigaset_write_room,
42991 - gigaset_chars_in_buffer,
42992 - gigaset_brkchars,
42993 - gigaset_init_bchannel,
42994 - gigaset_close_bchannel,
42995 - gigaset_initbcshw,
42996 - gigaset_freebcshw,
42997 - gigaset_reinitbcshw,
42998 - gigaset_initcshw,
42999 - gigaset_freecshw,
43000 - gigaset_set_modem_ctrl,
43001 - gigaset_baud_rate,
43002 - gigaset_set_line_ctrl,
43003 - gigaset_isoc_send_skb,
43004 - gigaset_isoc_input,
43005 + .write_cmd = gigaset_write_cmd,
43006 + .write_room = gigaset_write_room,
43007 + .chars_in_buffer = gigaset_chars_in_buffer,
43008 + .brkchars = gigaset_brkchars,
43009 + .init_bchannel = gigaset_init_bchannel,
43010 + .close_bchannel = gigaset_close_bchannel,
43011 + .initbcshw = gigaset_initbcshw,
43012 + .freebcshw = gigaset_freebcshw,
43013 + .reinitbcshw = gigaset_reinitbcshw,
43014 + .initcshw = gigaset_initcshw,
43015 + .freecshw = gigaset_freecshw,
43016 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43017 + .baud_rate = gigaset_baud_rate,
43018 + .set_line_ctrl = gigaset_set_line_ctrl,
43019 + .send_skb = gigaset_isoc_send_skb,
43020 + .handle_input = gigaset_isoc_input,
43021 };
43022
43023 /* bas_gigaset_init
43024 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43025 index 600c79b..3752bab 100644
43026 --- a/drivers/isdn/gigaset/interface.c
43027 +++ b/drivers/isdn/gigaset/interface.c
43028 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43029 }
43030 tty->driver_data = cs;
43031
43032 - ++cs->port.count;
43033 + atomic_inc(&cs->port.count);
43034
43035 - if (cs->port.count == 1) {
43036 + if (atomic_read(&cs->port.count) == 1) {
43037 tty_port_tty_set(&cs->port, tty);
43038 cs->port.low_latency = 1;
43039 }
43040 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43041
43042 if (!cs->connected)
43043 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43044 - else if (!cs->port.count)
43045 + else if (!atomic_read(&cs->port.count))
43046 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43047 - else if (!--cs->port.count)
43048 + else if (!atomic_dec_return(&cs->port.count))
43049 tty_port_tty_set(&cs->port, NULL);
43050
43051 mutex_unlock(&cs->mutex);
43052 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43053 index 8c91fd5..14f13ce 100644
43054 --- a/drivers/isdn/gigaset/ser-gigaset.c
43055 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43056 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43057 }
43058
43059 static const struct gigaset_ops ops = {
43060 - gigaset_write_cmd,
43061 - gigaset_write_room,
43062 - gigaset_chars_in_buffer,
43063 - gigaset_brkchars,
43064 - gigaset_init_bchannel,
43065 - gigaset_close_bchannel,
43066 - gigaset_initbcshw,
43067 - gigaset_freebcshw,
43068 - gigaset_reinitbcshw,
43069 - gigaset_initcshw,
43070 - gigaset_freecshw,
43071 - gigaset_set_modem_ctrl,
43072 - gigaset_baud_rate,
43073 - gigaset_set_line_ctrl,
43074 - gigaset_m10x_send_skb, /* asyncdata.c */
43075 - gigaset_m10x_input, /* asyncdata.c */
43076 + .write_cmd = gigaset_write_cmd,
43077 + .write_room = gigaset_write_room,
43078 + .chars_in_buffer = gigaset_chars_in_buffer,
43079 + .brkchars = gigaset_brkchars,
43080 + .init_bchannel = gigaset_init_bchannel,
43081 + .close_bchannel = gigaset_close_bchannel,
43082 + .initbcshw = gigaset_initbcshw,
43083 + .freebcshw = gigaset_freebcshw,
43084 + .reinitbcshw = gigaset_reinitbcshw,
43085 + .initcshw = gigaset_initcshw,
43086 + .freecshw = gigaset_freecshw,
43087 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43088 + .baud_rate = gigaset_baud_rate,
43089 + .set_line_ctrl = gigaset_set_line_ctrl,
43090 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43091 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43092 };
43093
43094
43095 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43096 index d0a41cb..b953e50 100644
43097 --- a/drivers/isdn/gigaset/usb-gigaset.c
43098 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43099 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43100 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43101 memcpy(cs->hw.usb->bchars, buf, 6);
43102 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43103 - 0, 0, &buf, 6, 2000);
43104 + 0, 0, buf, 6, 2000);
43105 }
43106
43107 static void gigaset_freebcshw(struct bc_state *bcs)
43108 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43109 }
43110
43111 static const struct gigaset_ops ops = {
43112 - gigaset_write_cmd,
43113 - gigaset_write_room,
43114 - gigaset_chars_in_buffer,
43115 - gigaset_brkchars,
43116 - gigaset_init_bchannel,
43117 - gigaset_close_bchannel,
43118 - gigaset_initbcshw,
43119 - gigaset_freebcshw,
43120 - gigaset_reinitbcshw,
43121 - gigaset_initcshw,
43122 - gigaset_freecshw,
43123 - gigaset_set_modem_ctrl,
43124 - gigaset_baud_rate,
43125 - gigaset_set_line_ctrl,
43126 - gigaset_m10x_send_skb,
43127 - gigaset_m10x_input,
43128 + .write_cmd = gigaset_write_cmd,
43129 + .write_room = gigaset_write_room,
43130 + .chars_in_buffer = gigaset_chars_in_buffer,
43131 + .brkchars = gigaset_brkchars,
43132 + .init_bchannel = gigaset_init_bchannel,
43133 + .close_bchannel = gigaset_close_bchannel,
43134 + .initbcshw = gigaset_initbcshw,
43135 + .freebcshw = gigaset_freebcshw,
43136 + .reinitbcshw = gigaset_reinitbcshw,
43137 + .initcshw = gigaset_initcshw,
43138 + .freecshw = gigaset_freecshw,
43139 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43140 + .baud_rate = gigaset_baud_rate,
43141 + .set_line_ctrl = gigaset_set_line_ctrl,
43142 + .send_skb = gigaset_m10x_send_skb,
43143 + .handle_input = gigaset_m10x_input,
43144 };
43145
43146 /*
43147 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43148 index 4d9b195..455075c 100644
43149 --- a/drivers/isdn/hardware/avm/b1.c
43150 +++ b/drivers/isdn/hardware/avm/b1.c
43151 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43152 }
43153 if (left) {
43154 if (t4file->user) {
43155 - if (copy_from_user(buf, dp, left))
43156 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43157 return -EFAULT;
43158 } else {
43159 memcpy(buf, dp, left);
43160 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43161 }
43162 if (left) {
43163 if (config->user) {
43164 - if (copy_from_user(buf, dp, left))
43165 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43166 return -EFAULT;
43167 } else {
43168 memcpy(buf, dp, left);
43169 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43170 index 9bb12ba..d4262f7 100644
43171 --- a/drivers/isdn/i4l/isdn_common.c
43172 +++ b/drivers/isdn/i4l/isdn_common.c
43173 @@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43174 } else
43175 return -EINVAL;
43176 case IIOCDBGVAR:
43177 + if (!capable(CAP_SYS_RAWIO))
43178 + return -EPERM;
43179 if (arg) {
43180 if (copy_to_user(argp, &dev, sizeof(ulong)))
43181 return -EFAULT;
43182 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43183 index 91d5730..336523e 100644
43184 --- a/drivers/isdn/i4l/isdn_concap.c
43185 +++ b/drivers/isdn/i4l/isdn_concap.c
43186 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43187 }
43188
43189 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43190 - &isdn_concap_dl_data_req,
43191 - &isdn_concap_dl_connect_req,
43192 - &isdn_concap_dl_disconn_req
43193 + .data_req = &isdn_concap_dl_data_req,
43194 + .connect_req = &isdn_concap_dl_connect_req,
43195 + .disconn_req = &isdn_concap_dl_disconn_req
43196 };
43197
43198 /* The following should better go into a dedicated source file such that
43199 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43200 index 3c5f249..5fac4d0 100644
43201 --- a/drivers/isdn/i4l/isdn_tty.c
43202 +++ b/drivers/isdn/i4l/isdn_tty.c
43203 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43204
43205 #ifdef ISDN_DEBUG_MODEM_OPEN
43206 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43207 - port->count);
43208 + atomic_read(&port->count));
43209 #endif
43210 - port->count++;
43211 + atomic_inc(&port->count);
43212 port->tty = tty;
43213 /*
43214 * Start up serial port
43215 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43216 #endif
43217 return;
43218 }
43219 - if ((tty->count == 1) && (port->count != 1)) {
43220 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43221 /*
43222 * Uh, oh. tty->count is 1, which means that the tty
43223 * structure will be freed. Info->count should always
43224 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43225 * serial port won't be shutdown.
43226 */
43227 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43228 - "info->count is %d\n", port->count);
43229 - port->count = 1;
43230 + "info->count is %d\n", atomic_read(&port->count));
43231 + atomic_set(&port->count, 1);
43232 }
43233 - if (--port->count < 0) {
43234 + if (atomic_dec_return(&port->count) < 0) {
43235 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43236 - info->line, port->count);
43237 - port->count = 0;
43238 + info->line, atomic_read(&port->count));
43239 + atomic_set(&port->count, 0);
43240 }
43241 - if (port->count) {
43242 + if (atomic_read(&port->count)) {
43243 #ifdef ISDN_DEBUG_MODEM_OPEN
43244 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43245 #endif
43246 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43247 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43248 return;
43249 isdn_tty_shutdown(info);
43250 - port->count = 0;
43251 + atomic_set(&port->count, 0);
43252 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43253 port->tty = NULL;
43254 wake_up_interruptible(&port->open_wait);
43255 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43256 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43257 modem_info *info = &dev->mdm.info[i];
43258
43259 - if (info->port.count == 0)
43260 + if (atomic_read(&info->port.count) == 0)
43261 continue;
43262 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43263 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43264 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43265 index e2d4e58..40cd045 100644
43266 --- a/drivers/isdn/i4l/isdn_x25iface.c
43267 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43268 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43269
43270
43271 static struct concap_proto_ops ix25_pops = {
43272 - &isdn_x25iface_proto_new,
43273 - &isdn_x25iface_proto_del,
43274 - &isdn_x25iface_proto_restart,
43275 - &isdn_x25iface_proto_close,
43276 - &isdn_x25iface_xmit,
43277 - &isdn_x25iface_receive,
43278 - &isdn_x25iface_connect_ind,
43279 - &isdn_x25iface_disconn_ind
43280 + .proto_new = &isdn_x25iface_proto_new,
43281 + .proto_del = &isdn_x25iface_proto_del,
43282 + .restart = &isdn_x25iface_proto_restart,
43283 + .close = &isdn_x25iface_proto_close,
43284 + .encap_and_xmit = &isdn_x25iface_xmit,
43285 + .data_ind = &isdn_x25iface_receive,
43286 + .connect_ind = &isdn_x25iface_connect_ind,
43287 + .disconn_ind = &isdn_x25iface_disconn_ind
43288 };
43289
43290 /* error message helper function */
43291 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43292 index 53d487f..f020f41 100644
43293 --- a/drivers/isdn/icn/icn.c
43294 +++ b/drivers/isdn/icn/icn.c
43295 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43296 if (count > len)
43297 count = len;
43298 if (user) {
43299 - if (copy_from_user(msg, buf, count))
43300 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43301 return -EFAULT;
43302 } else
43303 memcpy(msg, buf, count);
43304 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43305 index a4f05c5..1433bc5 100644
43306 --- a/drivers/isdn/mISDN/dsp_cmx.c
43307 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43308 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43309 static u16 dsp_count; /* last sample count */
43310 static int dsp_count_valid; /* if we have last sample count */
43311
43312 -void
43313 +void __intentional_overflow(-1)
43314 dsp_cmx_send(void *arg)
43315 {
43316 struct dsp_conf *conf;
43317 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43318 index d93e245..e7ece6b 100644
43319 --- a/drivers/leds/leds-clevo-mail.c
43320 +++ b/drivers/leds/leds-clevo-mail.c
43321 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43322 * detected as working, but in reality it is not) as low as
43323 * possible.
43324 */
43325 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43326 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43327 {
43328 .callback = clevo_mail_led_dmi_callback,
43329 .ident = "Clevo D410J",
43330 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43331 index 5b8f938..b73d657 100644
43332 --- a/drivers/leds/leds-ss4200.c
43333 +++ b/drivers/leds/leds-ss4200.c
43334 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43335 * detected as working, but in reality it is not) as low as
43336 * possible.
43337 */
43338 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43339 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43340 {
43341 .callback = ss4200_led_dmi_callback,
43342 .ident = "Intel SS4200-E",
43343 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43344 index 0bf1e4e..b4bf44e 100644
43345 --- a/drivers/lguest/core.c
43346 +++ b/drivers/lguest/core.c
43347 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
43348 * The end address needs +1 because __get_vm_area allocates an
43349 * extra guard page, so we need space for that.
43350 */
43351 +
43352 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43353 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43354 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43355 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43356 +#else
43357 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43358 VM_ALLOC, switcher_addr, switcher_addr
43359 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43360 +#endif
43361 +
43362 if (!switcher_vma) {
43363 err = -ENOMEM;
43364 printk("lguest: could not map switcher pages high\n");
43365 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
43366 * Now the Switcher is mapped at the right address, we can't fail!
43367 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43368 */
43369 - memcpy(switcher_vma->addr, start_switcher_text,
43370 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43371 end_switcher_text - start_switcher_text);
43372
43373 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43374 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43375 index bfb39bb..08a603b 100644
43376 --- a/drivers/lguest/page_tables.c
43377 +++ b/drivers/lguest/page_tables.c
43378 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43379 /*:*/
43380
43381 #ifdef CONFIG_X86_PAE
43382 -static void release_pmd(pmd_t *spmd)
43383 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43384 {
43385 /* If the entry's not present, there's nothing to release. */
43386 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43387 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43388 index 922a1ac..9dd0c2a 100644
43389 --- a/drivers/lguest/x86/core.c
43390 +++ b/drivers/lguest/x86/core.c
43391 @@ -59,7 +59,7 @@ static struct {
43392 /* Offset from where switcher.S was compiled to where we've copied it */
43393 static unsigned long switcher_offset(void)
43394 {
43395 - return switcher_addr - (unsigned long)start_switcher_text;
43396 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43397 }
43398
43399 /* This cpu's struct lguest_pages (after the Switcher text page) */
43400 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43401 * These copies are pretty cheap, so we do them unconditionally: */
43402 /* Save the current Host top-level page directory.
43403 */
43404 +
43405 +#ifdef CONFIG_PAX_PER_CPU_PGD
43406 + pages->state.host_cr3 = read_cr3();
43407 +#else
43408 pages->state.host_cr3 = __pa(current->mm->pgd);
43409 +#endif
43410 +
43411 /*
43412 * Set up the Guest's page tables to see this CPU's pages (and no
43413 * other CPU's pages).
43414 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43415 * compiled-in switcher code and the high-mapped copy we just made.
43416 */
43417 for (i = 0; i < IDT_ENTRIES; i++)
43418 - default_idt_entries[i] += switcher_offset();
43419 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43420
43421 /*
43422 * Set up the Switcher's per-cpu areas.
43423 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43424 * it will be undisturbed when we switch. To change %cs and jump we
43425 * need this structure to feed to Intel's "lcall" instruction.
43426 */
43427 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43428 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43429 lguest_entry.segment = LGUEST_CS;
43430
43431 /*
43432 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43433 index 40634b0..4f5855e 100644
43434 --- a/drivers/lguest/x86/switcher_32.S
43435 +++ b/drivers/lguest/x86/switcher_32.S
43436 @@ -87,6 +87,7 @@
43437 #include <asm/page.h>
43438 #include <asm/segment.h>
43439 #include <asm/lguest.h>
43440 +#include <asm/processor-flags.h>
43441
43442 // We mark the start of the code to copy
43443 // It's placed in .text tho it's never run here
43444 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43445 // Changes type when we load it: damn Intel!
43446 // For after we switch over our page tables
43447 // That entry will be read-only: we'd crash.
43448 +
43449 +#ifdef CONFIG_PAX_KERNEXEC
43450 + mov %cr0, %edx
43451 + xor $X86_CR0_WP, %edx
43452 + mov %edx, %cr0
43453 +#endif
43454 +
43455 movl $(GDT_ENTRY_TSS*8), %edx
43456 ltr %dx
43457
43458 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43459 // Let's clear it again for our return.
43460 // The GDT descriptor of the Host
43461 // Points to the table after two "size" bytes
43462 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43463 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43464 // Clear "used" from type field (byte 5, bit 2)
43465 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43466 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43467 +
43468 +#ifdef CONFIG_PAX_KERNEXEC
43469 + mov %cr0, %eax
43470 + xor $X86_CR0_WP, %eax
43471 + mov %eax, %cr0
43472 +#endif
43473
43474 // Once our page table's switched, the Guest is live!
43475 // The Host fades as we run this final step.
43476 @@ -295,13 +309,12 @@ deliver_to_host:
43477 // I consulted gcc, and it gave
43478 // These instructions, which I gladly credit:
43479 leal (%edx,%ebx,8), %eax
43480 - movzwl (%eax),%edx
43481 - movl 4(%eax), %eax
43482 - xorw %ax, %ax
43483 - orl %eax, %edx
43484 + movl 4(%eax), %edx
43485 + movw (%eax), %dx
43486 // Now the address of the handler's in %edx
43487 // We call it now: its "iret" drops us home.
43488 - jmp *%edx
43489 + ljmp $__KERNEL_CS, $1f
43490 +1: jmp *%edx
43491
43492 // Every interrupt can come to us here
43493 // But we must truly tell each apart.
43494 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43495 index 7ef7461..5a09dac 100644
43496 --- a/drivers/md/bcache/closure.h
43497 +++ b/drivers/md/bcache/closure.h
43498 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43499 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43500 struct workqueue_struct *wq)
43501 {
43502 - BUG_ON(object_is_on_stack(cl));
43503 + BUG_ON(object_starts_on_stack(cl));
43504 closure_set_ip(cl);
43505 cl->fn = fn;
43506 cl->wq = wq;
43507 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43508 index 4195a01..42527ac 100644
43509 --- a/drivers/md/bitmap.c
43510 +++ b/drivers/md/bitmap.c
43511 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43512 chunk_kb ? "KB" : "B");
43513 if (bitmap->storage.file) {
43514 seq_printf(seq, ", file: ");
43515 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43516 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43517 }
43518
43519 seq_printf(seq, "\n");
43520 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43521 index 5152142..623d141 100644
43522 --- a/drivers/md/dm-ioctl.c
43523 +++ b/drivers/md/dm-ioctl.c
43524 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43525 cmd == DM_LIST_VERSIONS_CMD)
43526 return 0;
43527
43528 - if ((cmd == DM_DEV_CREATE_CMD)) {
43529 + if (cmd == DM_DEV_CREATE_CMD) {
43530 if (!*param->name) {
43531 DMWARN("name not supplied when creating device");
43532 return -EINVAL;
43533 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43534 index 7dfdb5c..4caada6 100644
43535 --- a/drivers/md/dm-raid1.c
43536 +++ b/drivers/md/dm-raid1.c
43537 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43538
43539 struct mirror {
43540 struct mirror_set *ms;
43541 - atomic_t error_count;
43542 + atomic_unchecked_t error_count;
43543 unsigned long error_type;
43544 struct dm_dev *dev;
43545 sector_t offset;
43546 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43547 struct mirror *m;
43548
43549 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43550 - if (!atomic_read(&m->error_count))
43551 + if (!atomic_read_unchecked(&m->error_count))
43552 return m;
43553
43554 return NULL;
43555 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43556 * simple way to tell if a device has encountered
43557 * errors.
43558 */
43559 - atomic_inc(&m->error_count);
43560 + atomic_inc_unchecked(&m->error_count);
43561
43562 if (test_and_set_bit(error_type, &m->error_type))
43563 return;
43564 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43565 struct mirror *m = get_default_mirror(ms);
43566
43567 do {
43568 - if (likely(!atomic_read(&m->error_count)))
43569 + if (likely(!atomic_read_unchecked(&m->error_count)))
43570 return m;
43571
43572 if (m-- == ms->mirror)
43573 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43574 {
43575 struct mirror *default_mirror = get_default_mirror(m->ms);
43576
43577 - return !atomic_read(&default_mirror->error_count);
43578 + return !atomic_read_unchecked(&default_mirror->error_count);
43579 }
43580
43581 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43582 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43583 */
43584 if (likely(region_in_sync(ms, region, 1)))
43585 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43586 - else if (m && atomic_read(&m->error_count))
43587 + else if (m && atomic_read_unchecked(&m->error_count))
43588 m = NULL;
43589
43590 if (likely(m))
43591 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43592 }
43593
43594 ms->mirror[mirror].ms = ms;
43595 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43596 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43597 ms->mirror[mirror].error_type = 0;
43598 ms->mirror[mirror].offset = offset;
43599
43600 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43601 */
43602 static char device_status_char(struct mirror *m)
43603 {
43604 - if (!atomic_read(&(m->error_count)))
43605 + if (!atomic_read_unchecked(&(m->error_count)))
43606 return 'A';
43607
43608 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43609 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43610 index 28a9012..9c0f6a5 100644
43611 --- a/drivers/md/dm-stats.c
43612 +++ b/drivers/md/dm-stats.c
43613 @@ -382,7 +382,7 @@ do_sync_free:
43614 synchronize_rcu_expedited();
43615 dm_stat_free(&s->rcu_head);
43616 } else {
43617 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43618 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43619 call_rcu(&s->rcu_head, dm_stat_free);
43620 }
43621 return 0;
43622 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43623 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43624 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43625 ));
43626 - ACCESS_ONCE(last->last_sector) = end_sector;
43627 - ACCESS_ONCE(last->last_rw) = bi_rw;
43628 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43629 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43630 }
43631
43632 rcu_read_lock();
43633 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43634 index d1600d2..4c3af3a 100644
43635 --- a/drivers/md/dm-stripe.c
43636 +++ b/drivers/md/dm-stripe.c
43637 @@ -21,7 +21,7 @@ struct stripe {
43638 struct dm_dev *dev;
43639 sector_t physical_start;
43640
43641 - atomic_t error_count;
43642 + atomic_unchecked_t error_count;
43643 };
43644
43645 struct stripe_c {
43646 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43647 kfree(sc);
43648 return r;
43649 }
43650 - atomic_set(&(sc->stripe[i].error_count), 0);
43651 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43652 }
43653
43654 ti->private = sc;
43655 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43656 DMEMIT("%d ", sc->stripes);
43657 for (i = 0; i < sc->stripes; i++) {
43658 DMEMIT("%s ", sc->stripe[i].dev->name);
43659 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43660 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43661 'D' : 'A';
43662 }
43663 buffer[i] = '\0';
43664 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43665 */
43666 for (i = 0; i < sc->stripes; i++)
43667 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43668 - atomic_inc(&(sc->stripe[i].error_count));
43669 - if (atomic_read(&(sc->stripe[i].error_count)) <
43670 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43671 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43672 DM_IO_ERROR_THRESHOLD)
43673 schedule_work(&sc->trigger_event);
43674 }
43675 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43676 index 6a7f2b8..fea0bde 100644
43677 --- a/drivers/md/dm-table.c
43678 +++ b/drivers/md/dm-table.c
43679 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43680 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43681 struct mapped_device *md)
43682 {
43683 - static char *_claim_ptr = "I belong to device-mapper";
43684 + static char _claim_ptr[] = "I belong to device-mapper";
43685 struct block_device *bdev;
43686
43687 int r;
43688 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43689 if (!dev_size)
43690 return 0;
43691
43692 - if ((start >= dev_size) || (start + len > dev_size)) {
43693 + if ((start >= dev_size) || (len > dev_size - start)) {
43694 DMWARN("%s: %s too small for target: "
43695 "start=%llu, len=%llu, dev_size=%llu",
43696 dm_device_name(ti->table->md), bdevname(bdev, b),
43697 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43698 index fb9efc8..81e8986 100644
43699 --- a/drivers/md/dm-thin-metadata.c
43700 +++ b/drivers/md/dm-thin-metadata.c
43701 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43702 {
43703 pmd->info.tm = pmd->tm;
43704 pmd->info.levels = 2;
43705 - pmd->info.value_type.context = pmd->data_sm;
43706 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43707 pmd->info.value_type.size = sizeof(__le64);
43708 pmd->info.value_type.inc = data_block_inc;
43709 pmd->info.value_type.dec = data_block_dec;
43710 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43711
43712 pmd->bl_info.tm = pmd->tm;
43713 pmd->bl_info.levels = 1;
43714 - pmd->bl_info.value_type.context = pmd->data_sm;
43715 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43716 pmd->bl_info.value_type.size = sizeof(__le64);
43717 pmd->bl_info.value_type.inc = data_block_inc;
43718 pmd->bl_info.value_type.dec = data_block_dec;
43719 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43720 index 8c53b09..f1fb2b0 100644
43721 --- a/drivers/md/dm.c
43722 +++ b/drivers/md/dm.c
43723 @@ -185,9 +185,9 @@ struct mapped_device {
43724 /*
43725 * Event handling.
43726 */
43727 - atomic_t event_nr;
43728 + atomic_unchecked_t event_nr;
43729 wait_queue_head_t eventq;
43730 - atomic_t uevent_seq;
43731 + atomic_unchecked_t uevent_seq;
43732 struct list_head uevent_list;
43733 spinlock_t uevent_lock; /* Protect access to uevent_list */
43734
43735 @@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
43736 spin_lock_init(&md->deferred_lock);
43737 atomic_set(&md->holders, 1);
43738 atomic_set(&md->open_count, 0);
43739 - atomic_set(&md->event_nr, 0);
43740 - atomic_set(&md->uevent_seq, 0);
43741 + atomic_set_unchecked(&md->event_nr, 0);
43742 + atomic_set_unchecked(&md->uevent_seq, 0);
43743 INIT_LIST_HEAD(&md->uevent_list);
43744 spin_lock_init(&md->uevent_lock);
43745
43746 @@ -2043,7 +2043,7 @@ static void event_callback(void *context)
43747
43748 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43749
43750 - atomic_inc(&md->event_nr);
43751 + atomic_inc_unchecked(&md->event_nr);
43752 wake_up(&md->eventq);
43753 }
43754
43755 @@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43756
43757 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43758 {
43759 - return atomic_add_return(1, &md->uevent_seq);
43760 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43761 }
43762
43763 uint32_t dm_get_event_nr(struct mapped_device *md)
43764 {
43765 - return atomic_read(&md->event_nr);
43766 + return atomic_read_unchecked(&md->event_nr);
43767 }
43768
43769 int dm_wait_event(struct mapped_device *md, int event_nr)
43770 {
43771 return wait_event_interruptible(md->eventq,
43772 - (event_nr != atomic_read(&md->event_nr)));
43773 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43774 }
43775
43776 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43777 diff --git a/drivers/md/md.c b/drivers/md/md.c
43778 index 4ad5cc4..0f19664 100644
43779 --- a/drivers/md/md.c
43780 +++ b/drivers/md/md.c
43781 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43782 * start build, activate spare
43783 */
43784 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43785 -static atomic_t md_event_count;
43786 +static atomic_unchecked_t md_event_count;
43787 void md_new_event(struct mddev *mddev)
43788 {
43789 - atomic_inc(&md_event_count);
43790 + atomic_inc_unchecked(&md_event_count);
43791 wake_up(&md_event_waiters);
43792 }
43793 EXPORT_SYMBOL_GPL(md_new_event);
43794 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43795 */
43796 static void md_new_event_inintr(struct mddev *mddev)
43797 {
43798 - atomic_inc(&md_event_count);
43799 + atomic_inc_unchecked(&md_event_count);
43800 wake_up(&md_event_waiters);
43801 }
43802
43803 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43804 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43805 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43806 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43807 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43808 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43809
43810 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43811 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43812 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43813 else
43814 sb->resync_offset = cpu_to_le64(0);
43815
43816 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43817 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43818
43819 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43820 sb->size = cpu_to_le64(mddev->dev_sectors);
43821 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43822 static ssize_t
43823 errors_show(struct md_rdev *rdev, char *page)
43824 {
43825 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43826 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43827 }
43828
43829 static ssize_t
43830 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43831 char *e;
43832 unsigned long n = simple_strtoul(buf, &e, 10);
43833 if (*buf && (*e == 0 || *e == '\n')) {
43834 - atomic_set(&rdev->corrected_errors, n);
43835 + atomic_set_unchecked(&rdev->corrected_errors, n);
43836 return len;
43837 }
43838 return -EINVAL;
43839 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
43840 rdev->sb_loaded = 0;
43841 rdev->bb_page = NULL;
43842 atomic_set(&rdev->nr_pending, 0);
43843 - atomic_set(&rdev->read_errors, 0);
43844 - atomic_set(&rdev->corrected_errors, 0);
43845 + atomic_set_unchecked(&rdev->read_errors, 0);
43846 + atomic_set_unchecked(&rdev->corrected_errors, 0);
43847
43848 INIT_LIST_HEAD(&rdev->same_set);
43849 init_waitqueue_head(&rdev->blocked_wait);
43850 @@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43851
43852 spin_unlock(&pers_lock);
43853 seq_printf(seq, "\n");
43854 - seq->poll_event = atomic_read(&md_event_count);
43855 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43856 return 0;
43857 }
43858 if (v == (void*)2) {
43859 @@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43860 return error;
43861
43862 seq = file->private_data;
43863 - seq->poll_event = atomic_read(&md_event_count);
43864 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43865 return error;
43866 }
43867
43868 @@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43869 /* always allow read */
43870 mask = POLLIN | POLLRDNORM;
43871
43872 - if (seq->poll_event != atomic_read(&md_event_count))
43873 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43874 mask |= POLLERR | POLLPRI;
43875 return mask;
43876 }
43877 @@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43878 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43879 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43880 (int)part_stat_read(&disk->part0, sectors[1]) -
43881 - atomic_read(&disk->sync_io);
43882 + atomic_read_unchecked(&disk->sync_io);
43883 /* sync IO will cause sync_io to increase before the disk_stats
43884 * as sync_io is counted when a request starts, and
43885 * disk_stats is counted when it completes.
43886 diff --git a/drivers/md/md.h b/drivers/md/md.h
43887 index 07bba96..2d6788c 100644
43888 --- a/drivers/md/md.h
43889 +++ b/drivers/md/md.h
43890 @@ -94,13 +94,13 @@ struct md_rdev {
43891 * only maintained for arrays that
43892 * support hot removal
43893 */
43894 - atomic_t read_errors; /* number of consecutive read errors that
43895 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
43896 * we have tried to ignore.
43897 */
43898 struct timespec last_read_error; /* monotonic time since our
43899 * last read error
43900 */
43901 - atomic_t corrected_errors; /* number of corrected read errors,
43902 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43903 * for reporting to userspace and storing
43904 * in superblock.
43905 */
43906 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
43907
43908 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
43909 {
43910 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43911 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43912 }
43913
43914 struct md_personality
43915 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
43916 index 786b689..ea8c956 100644
43917 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
43918 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
43919 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
43920 * Flick into a mode where all blocks get allocated in the new area.
43921 */
43922 smm->begin = old_len;
43923 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
43924 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
43925
43926 /*
43927 * Extend.
43928 @@ -710,7 +710,7 @@ out:
43929 /*
43930 * Switch back to normal behaviour.
43931 */
43932 - memcpy(sm, &ops, sizeof(*sm));
43933 + memcpy((void *)sm, &ops, sizeof(*sm));
43934 return r;
43935 }
43936
43937 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
43938 index 3e6d115..ffecdeb 100644
43939 --- a/drivers/md/persistent-data/dm-space-map.h
43940 +++ b/drivers/md/persistent-data/dm-space-map.h
43941 @@ -71,6 +71,7 @@ struct dm_space_map {
43942 dm_sm_threshold_fn fn,
43943 void *context);
43944 };
43945 +typedef struct dm_space_map __no_const dm_space_map_no_const;
43946
43947 /*----------------------------------------------------------------*/
43948
43949 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
43950 index 4a6ca1c..e952750 100644
43951 --- a/drivers/md/raid1.c
43952 +++ b/drivers/md/raid1.c
43953 @@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
43954 if (r1_sync_page_io(rdev, sect, s,
43955 bio->bi_io_vec[idx].bv_page,
43956 READ) != 0)
43957 - atomic_add(s, &rdev->corrected_errors);
43958 + atomic_add_unchecked(s, &rdev->corrected_errors);
43959 }
43960 sectors -= s;
43961 sect += s;
43962 @@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
43963 test_bit(In_sync, &rdev->flags)) {
43964 if (r1_sync_page_io(rdev, sect, s,
43965 conf->tmppage, READ)) {
43966 - atomic_add(s, &rdev->corrected_errors);
43967 + atomic_add_unchecked(s, &rdev->corrected_errors);
43968 printk(KERN_INFO
43969 "md/raid1:%s: read error corrected "
43970 "(%d sectors at %llu on %s)\n",
43971 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
43972 index 33fc408..fc61709 100644
43973 --- a/drivers/md/raid10.c
43974 +++ b/drivers/md/raid10.c
43975 @@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
43976 /* The write handler will notice the lack of
43977 * R10BIO_Uptodate and record any errors etc
43978 */
43979 - atomic_add(r10_bio->sectors,
43980 + atomic_add_unchecked(r10_bio->sectors,
43981 &conf->mirrors[d].rdev->corrected_errors);
43982
43983 /* for reconstruct, we always reschedule after a read.
43984 @@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43985 {
43986 struct timespec cur_time_mon;
43987 unsigned long hours_since_last;
43988 - unsigned int read_errors = atomic_read(&rdev->read_errors);
43989 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
43990
43991 ktime_get_ts(&cur_time_mon);
43992
43993 @@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43994 * overflowing the shift of read_errors by hours_since_last.
43995 */
43996 if (hours_since_last >= 8 * sizeof(read_errors))
43997 - atomic_set(&rdev->read_errors, 0);
43998 + atomic_set_unchecked(&rdev->read_errors, 0);
43999 else
44000 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44001 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44002 }
44003
44004 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44005 @@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44006 return;
44007
44008 check_decay_read_errors(mddev, rdev);
44009 - atomic_inc(&rdev->read_errors);
44010 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44011 + atomic_inc_unchecked(&rdev->read_errors);
44012 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44013 char b[BDEVNAME_SIZE];
44014 bdevname(rdev->bdev, b);
44015
44016 @@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44017 "md/raid10:%s: %s: Raid device exceeded "
44018 "read_error threshold [cur %d:max %d]\n",
44019 mdname(mddev), b,
44020 - atomic_read(&rdev->read_errors), max_read_errors);
44021 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44022 printk(KERN_NOTICE
44023 "md/raid10:%s: %s: Failing raid device\n",
44024 mdname(mddev), b);
44025 @@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44026 sect +
44027 choose_data_offset(r10_bio, rdev)),
44028 bdevname(rdev->bdev, b));
44029 - atomic_add(s, &rdev->corrected_errors);
44030 + atomic_add_unchecked(s, &rdev->corrected_errors);
44031 }
44032
44033 rdev_dec_pending(rdev, mddev);
44034 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44035 index 16f5c21..4df20dc 100644
44036 --- a/drivers/md/raid5.c
44037 +++ b/drivers/md/raid5.c
44038 @@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44039 mdname(conf->mddev), STRIPE_SECTORS,
44040 (unsigned long long)s,
44041 bdevname(rdev->bdev, b));
44042 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44043 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44044 clear_bit(R5_ReadError, &sh->dev[i].flags);
44045 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44046 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44047 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44048
44049 - if (atomic_read(&rdev->read_errors))
44050 - atomic_set(&rdev->read_errors, 0);
44051 + if (atomic_read_unchecked(&rdev->read_errors))
44052 + atomic_set_unchecked(&rdev->read_errors, 0);
44053 } else {
44054 const char *bdn = bdevname(rdev->bdev, b);
44055 int retry = 0;
44056 int set_bad = 0;
44057
44058 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44059 - atomic_inc(&rdev->read_errors);
44060 + atomic_inc_unchecked(&rdev->read_errors);
44061 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44062 printk_ratelimited(
44063 KERN_WARNING
44064 @@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44065 mdname(conf->mddev),
44066 (unsigned long long)s,
44067 bdn);
44068 - } else if (atomic_read(&rdev->read_errors)
44069 + } else if (atomic_read_unchecked(&rdev->read_errors)
44070 > conf->max_nr_stripes)
44071 printk(KERN_WARNING
44072 "md/raid:%s: Too many read errors, failing device %s.\n",
44073 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44074 index 983db75..ef9248c 100644
44075 --- a/drivers/media/dvb-core/dvbdev.c
44076 +++ b/drivers/media/dvb-core/dvbdev.c
44077 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44078 const struct dvb_device *template, void *priv, int type)
44079 {
44080 struct dvb_device *dvbdev;
44081 - struct file_operations *dvbdevfops;
44082 + file_operations_no_const *dvbdevfops;
44083 struct device *clsdev;
44084 int minor;
44085 int id;
44086 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44087 index 9b6c3bb..baeb5c7 100644
44088 --- a/drivers/media/dvb-frontends/dib3000.h
44089 +++ b/drivers/media/dvb-frontends/dib3000.h
44090 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44091 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44092 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44093 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44094 -};
44095 +} __no_const;
44096
44097 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44098 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44099 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44100 index ed8cb90..5ef7f79 100644
44101 --- a/drivers/media/pci/cx88/cx88-video.c
44102 +++ b/drivers/media/pci/cx88/cx88-video.c
44103 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44104
44105 /* ------------------------------------------------------------------ */
44106
44107 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44108 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44109 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44110 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44111 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44112 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44113
44114 module_param_array(video_nr, int, NULL, 0444);
44115 module_param_array(vbi_nr, int, NULL, 0444);
44116 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44117 index 802642d..5534900 100644
44118 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44119 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44120 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44121 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44122
44123 /* ivtv instance counter */
44124 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44125 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44126
44127 /* Parameter declarations */
44128 static int cardtype[IVTV_MAX_CARDS];
44129 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44130 index dfd0a21..6bbb465 100644
44131 --- a/drivers/media/platform/omap/omap_vout.c
44132 +++ b/drivers/media/platform/omap/omap_vout.c
44133 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44134 OMAP_VIDEO2,
44135 };
44136
44137 -static struct videobuf_queue_ops video_vbq_ops;
44138 /* Variables configurable through module params*/
44139 static u32 video1_numbuffers = 3;
44140 static u32 video2_numbuffers = 3;
44141 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44142 {
44143 struct videobuf_queue *q;
44144 struct omap_vout_device *vout = NULL;
44145 + static struct videobuf_queue_ops video_vbq_ops = {
44146 + .buf_setup = omap_vout_buffer_setup,
44147 + .buf_prepare = omap_vout_buffer_prepare,
44148 + .buf_release = omap_vout_buffer_release,
44149 + .buf_queue = omap_vout_buffer_queue,
44150 + };
44151
44152 vout = video_drvdata(file);
44153 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44154 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44155 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44156
44157 q = &vout->vbq;
44158 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44159 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44160 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44161 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44162 spin_lock_init(&vout->vbq_lock);
44163
44164 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44165 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44166 index fb2acc5..a2fcbdc4 100644
44167 --- a/drivers/media/platform/s5p-tv/mixer.h
44168 +++ b/drivers/media/platform/s5p-tv/mixer.h
44169 @@ -156,7 +156,7 @@ struct mxr_layer {
44170 /** layer index (unique identifier) */
44171 int idx;
44172 /** callbacks for layer methods */
44173 - struct mxr_layer_ops ops;
44174 + struct mxr_layer_ops *ops;
44175 /** format array */
44176 const struct mxr_format **fmt_array;
44177 /** size of format array */
44178 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44179 index 74344c7..a39e70e 100644
44180 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44181 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44182 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44183 {
44184 struct mxr_layer *layer;
44185 int ret;
44186 - struct mxr_layer_ops ops = {
44187 + static struct mxr_layer_ops ops = {
44188 .release = mxr_graph_layer_release,
44189 .buffer_set = mxr_graph_buffer_set,
44190 .stream_set = mxr_graph_stream_set,
44191 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44192 index b713403..53cb5ad 100644
44193 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44194 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44195 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44196 layer->update_buf = next;
44197 }
44198
44199 - layer->ops.buffer_set(layer, layer->update_buf);
44200 + layer->ops->buffer_set(layer, layer->update_buf);
44201
44202 if (done && done != layer->shadow_buf)
44203 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44204 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44205 index c5059ba..2649f28 100644
44206 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44207 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44208 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44209 layer->geo.src.height = layer->geo.src.full_height;
44210
44211 mxr_geometry_dump(mdev, &layer->geo);
44212 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44213 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44214 mxr_geometry_dump(mdev, &layer->geo);
44215 }
44216
44217 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44218 layer->geo.dst.full_width = mbus_fmt.width;
44219 layer->geo.dst.full_height = mbus_fmt.height;
44220 layer->geo.dst.field = mbus_fmt.field;
44221 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44222 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44223
44224 mxr_geometry_dump(mdev, &layer->geo);
44225 }
44226 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44227 /* set source size to highest accepted value */
44228 geo->src.full_width = max(geo->dst.full_width, pix->width);
44229 geo->src.full_height = max(geo->dst.full_height, pix->height);
44230 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44231 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44232 mxr_geometry_dump(mdev, &layer->geo);
44233 /* set cropping to total visible screen */
44234 geo->src.width = pix->width;
44235 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44236 geo->src.x_offset = 0;
44237 geo->src.y_offset = 0;
44238 /* assure consistency of geometry */
44239 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44240 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44241 mxr_geometry_dump(mdev, &layer->geo);
44242 /* set full size to lowest possible value */
44243 geo->src.full_width = 0;
44244 geo->src.full_height = 0;
44245 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44246 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44247 mxr_geometry_dump(mdev, &layer->geo);
44248
44249 /* returning results */
44250 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44251 target->width = s->r.width;
44252 target->height = s->r.height;
44253
44254 - layer->ops.fix_geometry(layer, stage, s->flags);
44255 + layer->ops->fix_geometry(layer, stage, s->flags);
44256
44257 /* retrieve update selection rectangle */
44258 res.left = target->x_offset;
44259 @@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44260 mxr_output_get(mdev);
44261
44262 mxr_layer_update_output(layer);
44263 - layer->ops.format_set(layer);
44264 + layer->ops->format_set(layer);
44265 /* enabling layer in hardware */
44266 spin_lock_irqsave(&layer->enq_slock, flags);
44267 layer->state = MXR_LAYER_STREAMING;
44268 spin_unlock_irqrestore(&layer->enq_slock, flags);
44269
44270 - layer->ops.stream_set(layer, MXR_ENABLE);
44271 + layer->ops->stream_set(layer, MXR_ENABLE);
44272 mxr_streamer_get(mdev);
44273
44274 return 0;
44275 @@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44276 spin_unlock_irqrestore(&layer->enq_slock, flags);
44277
44278 /* disabling layer in hardware */
44279 - layer->ops.stream_set(layer, MXR_DISABLE);
44280 + layer->ops->stream_set(layer, MXR_DISABLE);
44281 /* remove one streamer */
44282 mxr_streamer_put(mdev);
44283 /* allow changes in output configuration */
44284 @@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44285
44286 void mxr_layer_release(struct mxr_layer *layer)
44287 {
44288 - if (layer->ops.release)
44289 - layer->ops.release(layer);
44290 + if (layer->ops->release)
44291 + layer->ops->release(layer);
44292 }
44293
44294 void mxr_base_layer_release(struct mxr_layer *layer)
44295 @@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44296
44297 layer->mdev = mdev;
44298 layer->idx = idx;
44299 - layer->ops = *ops;
44300 + layer->ops = ops;
44301
44302 spin_lock_init(&layer->enq_slock);
44303 INIT_LIST_HEAD(&layer->enq_list);
44304 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44305 index c9388c4..ce71ece 100644
44306 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44307 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44308 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44309 {
44310 struct mxr_layer *layer;
44311 int ret;
44312 - struct mxr_layer_ops ops = {
44313 + static struct mxr_layer_ops ops = {
44314 .release = mxr_vp_layer_release,
44315 .buffer_set = mxr_vp_buffer_set,
44316 .stream_set = mxr_vp_stream_set,
44317 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44318 index 2d4e73b..8b4d5b6 100644
44319 --- a/drivers/media/platform/vivi.c
44320 +++ b/drivers/media/platform/vivi.c
44321 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44322 MODULE_LICENSE("Dual BSD/GPL");
44323 MODULE_VERSION(VIVI_VERSION);
44324
44325 -static unsigned video_nr = -1;
44326 -module_param(video_nr, uint, 0644);
44327 +static int video_nr = -1;
44328 +module_param(video_nr, int, 0644);
44329 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44330
44331 static unsigned n_devs = 1;
44332 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44333 index 545c04c..a14bded 100644
44334 --- a/drivers/media/radio/radio-cadet.c
44335 +++ b/drivers/media/radio/radio-cadet.c
44336 @@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44337 unsigned char readbuf[RDS_BUFFER];
44338 int i = 0;
44339
44340 + if (count > RDS_BUFFER)
44341 + return -EFAULT;
44342 mutex_lock(&dev->lock);
44343 if (dev->rdsstat == 0)
44344 cadet_start_rds(dev);
44345 @@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44346 while (i < count && dev->rdsin != dev->rdsout)
44347 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44348
44349 - if (i && copy_to_user(data, readbuf, i))
44350 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44351 i = -EFAULT;
44352 unlock:
44353 mutex_unlock(&dev->lock);
44354 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44355 index 5236035..c622c74 100644
44356 --- a/drivers/media/radio/radio-maxiradio.c
44357 +++ b/drivers/media/radio/radio-maxiradio.c
44358 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44359 /* TEA5757 pin mappings */
44360 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44361
44362 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44363 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44364
44365 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44366 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44367 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44368 index 050b3bb..79f62b9 100644
44369 --- a/drivers/media/radio/radio-shark.c
44370 +++ b/drivers/media/radio/radio-shark.c
44371 @@ -79,7 +79,7 @@ struct shark_device {
44372 u32 last_val;
44373 };
44374
44375 -static atomic_t shark_instance = ATOMIC_INIT(0);
44376 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44377
44378 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44379 {
44380 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44381 index 8654e0d..0608a64 100644
44382 --- a/drivers/media/radio/radio-shark2.c
44383 +++ b/drivers/media/radio/radio-shark2.c
44384 @@ -74,7 +74,7 @@ struct shark_device {
44385 u8 *transfer_buffer;
44386 };
44387
44388 -static atomic_t shark_instance = ATOMIC_INIT(0);
44389 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44390
44391 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44392 {
44393 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44394 index 2fd9009..278cc1e 100644
44395 --- a/drivers/media/radio/radio-si476x.c
44396 +++ b/drivers/media/radio/radio-si476x.c
44397 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44398 struct si476x_radio *radio;
44399 struct v4l2_ctrl *ctrl;
44400
44401 - static atomic_t instance = ATOMIC_INIT(0);
44402 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
44403
44404 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44405 if (!radio)
44406 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44407 index a1c641e..3007da9 100644
44408 --- a/drivers/media/usb/dvb-usb/cxusb.c
44409 +++ b/drivers/media/usb/dvb-usb/cxusb.c
44410 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44411
44412 struct dib0700_adapter_state {
44413 int (*set_param_save) (struct dvb_frontend *);
44414 -};
44415 +} __no_const;
44416
44417 static int dib7070_set_param_override(struct dvb_frontend *fe)
44418 {
44419 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44420 index ae0f56a..ec71784 100644
44421 --- a/drivers/media/usb/dvb-usb/dw2102.c
44422 +++ b/drivers/media/usb/dvb-usb/dw2102.c
44423 @@ -118,7 +118,7 @@ struct su3000_state {
44424
44425 struct s6x0_state {
44426 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44427 -};
44428 +} __no_const;
44429
44430 /* debug */
44431 static int dvb_usb_dw2102_debug;
44432 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44433 index 8f7a6a4..eb0e1d4 100644
44434 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44435 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44436 @@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44437 __u32 reserved;
44438 };
44439
44440 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44441 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44442 enum v4l2_memory memory)
44443 {
44444 void __user *up_pln;
44445 @@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44446 return 0;
44447 }
44448
44449 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44450 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44451 enum v4l2_memory memory)
44452 {
44453 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44454 @@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44455 * by passing a very big num_planes value */
44456 uplane = compat_alloc_user_space(num_planes *
44457 sizeof(struct v4l2_plane));
44458 - kp->m.planes = uplane;
44459 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44460
44461 while (--num_planes >= 0) {
44462 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44463 @@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44464 if (num_planes == 0)
44465 return 0;
44466
44467 - uplane = kp->m.planes;
44468 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44469 if (get_user(p, &up->m.planes))
44470 return -EFAULT;
44471 uplane32 = compat_ptr(p);
44472 @@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44473 get_user(kp->capability, &up->capability) ||
44474 get_user(kp->flags, &up->flags))
44475 return -EFAULT;
44476 - kp->base = compat_ptr(tmp);
44477 + kp->base = (void __force_kernel *)compat_ptr(tmp);
44478 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44479 return 0;
44480 }
44481 @@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44482 n * sizeof(struct v4l2_ext_control32)))
44483 return -EFAULT;
44484 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44485 - kp->controls = kcontrols;
44486 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44487 while (--n >= 0) {
44488 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44489 return -EFAULT;
44490 @@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44491 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44492 {
44493 struct v4l2_ext_control32 __user *ucontrols;
44494 - struct v4l2_ext_control __user *kcontrols = kp->controls;
44495 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44496 int n = kp->count;
44497 compat_caddr_t p;
44498
44499 @@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44500 put_user(kp->start_block, &up->start_block) ||
44501 put_user(kp->blocks, &up->blocks) ||
44502 put_user(tmp, &up->edid) ||
44503 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44504 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44505 return -EFAULT;
44506 return 0;
44507 }
44508 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44509 index 6ff002b..6b9316b 100644
44510 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
44511 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44512 @@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44513 return 0;
44514
44515 case V4L2_CTRL_TYPE_STRING:
44516 - len = strlen(c->string);
44517 - if (len < ctrl->minimum)
44518 + len = strlen_user(c->string);
44519 + if (!len || len < ctrl->minimum)
44520 return -ERANGE;
44521 if ((len - ctrl->minimum) % ctrl->step)
44522 return -ERANGE;
44523 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44524 index 02d1b63..5fd6b16 100644
44525 --- a/drivers/media/v4l2-core/v4l2-device.c
44526 +++ b/drivers/media/v4l2-core/v4l2-device.c
44527 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44528 EXPORT_SYMBOL_GPL(v4l2_device_put);
44529
44530 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44531 - atomic_t *instance)
44532 + atomic_unchecked_t *instance)
44533 {
44534 - int num = atomic_inc_return(instance) - 1;
44535 + int num = atomic_inc_return_unchecked(instance) - 1;
44536 int len = strlen(basename);
44537
44538 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44539 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44540 index 707aef7..93b8ac0 100644
44541 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
44542 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44543 @@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
44544 struct file *file, void *fh, void *p);
44545 } u;
44546 void (*debug)(const void *arg, bool write_only);
44547 -};
44548 +} __do_const;
44549 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44550
44551 /* This control needs a priority check */
44552 #define INFO_FL_PRIO (1 << 0)
44553 @@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
44554 struct video_device *vfd = video_devdata(file);
44555 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44556 bool write_only = false;
44557 - struct v4l2_ioctl_info default_info;
44558 + v4l2_ioctl_info_no_const default_info;
44559 const struct v4l2_ioctl_info *info;
44560 void *fh = file->private_data;
44561 struct v4l2_fh *vfh = NULL;
44562 @@ -2197,7 +2198,7 @@ done:
44563 }
44564
44565 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44566 - void * __user *user_ptr, void ***kernel_ptr)
44567 + void __user **user_ptr, void ***kernel_ptr)
44568 {
44569 int ret = 0;
44570
44571 @@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44572 ret = -EINVAL;
44573 break;
44574 }
44575 - *user_ptr = (void __user *)buf->m.planes;
44576 + *user_ptr = (void __force_user *)buf->m.planes;
44577 *kernel_ptr = (void *)&buf->m.planes;
44578 *array_size = sizeof(struct v4l2_plane) * buf->length;
44579 ret = 1;
44580 @@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44581 ret = -EINVAL;
44582 break;
44583 }
44584 - *user_ptr = (void __user *)ctrls->controls;
44585 + *user_ptr = (void __force_user *)ctrls->controls;
44586 *kernel_ptr = (void *)&ctrls->controls;
44587 *array_size = sizeof(struct v4l2_ext_control)
44588 * ctrls->count;
44589 @@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44590 }
44591
44592 if (has_array_args) {
44593 - *kernel_ptr = user_ptr;
44594 + *kernel_ptr = (void __force_kernel *)user_ptr;
44595 if (copy_to_user(user_ptr, mbuf, array_size))
44596 err = -EFAULT;
44597 goto out_array_args;
44598 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44599 index 570b18a..f880314 100644
44600 --- a/drivers/message/fusion/mptbase.c
44601 +++ b/drivers/message/fusion/mptbase.c
44602 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44603 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44604 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44605
44606 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44607 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44608 +#else
44609 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44610 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44611 +#endif
44612 +
44613 /*
44614 * Rounding UP to nearest 4-kB boundary here...
44615 */
44616 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44617 ioc->facts.GlobalCredits);
44618
44619 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44620 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44621 + NULL, NULL);
44622 +#else
44623 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44624 +#endif
44625 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44626 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44627 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44628 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44629 index 00d339c..2ea899d 100644
44630 --- a/drivers/message/fusion/mptsas.c
44631 +++ b/drivers/message/fusion/mptsas.c
44632 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44633 return 0;
44634 }
44635
44636 +static inline void
44637 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44638 +{
44639 + if (phy_info->port_details) {
44640 + phy_info->port_details->rphy = rphy;
44641 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44642 + ioc->name, rphy));
44643 + }
44644 +
44645 + if (rphy) {
44646 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44647 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44648 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44649 + ioc->name, rphy, rphy->dev.release));
44650 + }
44651 +}
44652 +
44653 /* no mutex */
44654 static void
44655 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44656 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44657 return NULL;
44658 }
44659
44660 -static inline void
44661 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44662 -{
44663 - if (phy_info->port_details) {
44664 - phy_info->port_details->rphy = rphy;
44665 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44666 - ioc->name, rphy));
44667 - }
44668 -
44669 - if (rphy) {
44670 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44671 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44672 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44673 - ioc->name, rphy, rphy->dev.release));
44674 - }
44675 -}
44676 -
44677 static inline struct sas_port *
44678 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44679 {
44680 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44681 index 727819c..ad74694 100644
44682 --- a/drivers/message/fusion/mptscsih.c
44683 +++ b/drivers/message/fusion/mptscsih.c
44684 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44685
44686 h = shost_priv(SChost);
44687
44688 - if (h) {
44689 - if (h->info_kbuf == NULL)
44690 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44691 - return h->info_kbuf;
44692 - h->info_kbuf[0] = '\0';
44693 + if (!h)
44694 + return NULL;
44695
44696 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44697 - h->info_kbuf[size-1] = '\0';
44698 - }
44699 + if (h->info_kbuf == NULL)
44700 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44701 + return h->info_kbuf;
44702 + h->info_kbuf[0] = '\0';
44703 +
44704 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44705 + h->info_kbuf[size-1] = '\0';
44706
44707 return h->info_kbuf;
44708 }
44709 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44710 index b7d87cd..3fb36da 100644
44711 --- a/drivers/message/i2o/i2o_proc.c
44712 +++ b/drivers/message/i2o/i2o_proc.c
44713 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44714 "Array Controller Device"
44715 };
44716
44717 -static char *chtostr(char *tmp, u8 *chars, int n)
44718 -{
44719 - tmp[0] = 0;
44720 - return strncat(tmp, (char *)chars, n);
44721 -}
44722 -
44723 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44724 char *group)
44725 {
44726 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44727 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44728 {
44729 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44730 - static u32 work32[5];
44731 - static u8 *work8 = (u8 *) work32;
44732 - static u16 *work16 = (u16 *) work32;
44733 + u32 work32[5];
44734 + u8 *work8 = (u8 *) work32;
44735 + u16 *work16 = (u16 *) work32;
44736 int token;
44737 u32 hwcap;
44738
44739 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44740 } *result;
44741
44742 i2o_exec_execute_ddm_table ddm_table;
44743 - char tmp[28 + 1];
44744
44745 result = kmalloc(sizeof(*result), GFP_KERNEL);
44746 if (!result)
44747 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44748
44749 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44750 seq_printf(seq, "%-#8x", ddm_table.module_id);
44751 - seq_printf(seq, "%-29s",
44752 - chtostr(tmp, ddm_table.module_name_version, 28));
44753 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44754 seq_printf(seq, "%9d ", ddm_table.data_size);
44755 seq_printf(seq, "%8d", ddm_table.code_size);
44756
44757 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44758
44759 i2o_driver_result_table *result;
44760 i2o_driver_store_table *dst;
44761 - char tmp[28 + 1];
44762
44763 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44764 if (result == NULL)
44765 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44766
44767 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44768 seq_printf(seq, "%-#8x", dst->module_id);
44769 - seq_printf(seq, "%-29s",
44770 - chtostr(tmp, dst->module_name_version, 28));
44771 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44772 + seq_printf(seq, "%-.28s", dst->module_name_version);
44773 + seq_printf(seq, "%-.8s", dst->date);
44774 seq_printf(seq, "%8d ", dst->module_size);
44775 seq_printf(seq, "%8d ", dst->mpb_size);
44776 seq_printf(seq, "0x%04x", dst->module_flags);
44777 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44778 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44779 {
44780 struct i2o_device *d = (struct i2o_device *)seq->private;
44781 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44782 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44783 // == (allow) 512d bytes (max)
44784 - static u16 *work16 = (u16 *) work32;
44785 + u16 *work16 = (u16 *) work32;
44786 int token;
44787 - char tmp[16 + 1];
44788
44789 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44790
44791 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44792 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44793 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44794 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44795 - seq_printf(seq, "Vendor info : %s\n",
44796 - chtostr(tmp, (u8 *) (work32 + 2), 16));
44797 - seq_printf(seq, "Product info : %s\n",
44798 - chtostr(tmp, (u8 *) (work32 + 6), 16));
44799 - seq_printf(seq, "Description : %s\n",
44800 - chtostr(tmp, (u8 *) (work32 + 10), 16));
44801 - seq_printf(seq, "Product rev. : %s\n",
44802 - chtostr(tmp, (u8 *) (work32 + 14), 8));
44803 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44804 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44805 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44806 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44807
44808 seq_printf(seq, "Serial number : ");
44809 print_serial_number(seq, (u8 *) (work32 + 16),
44810 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44811 u8 pad[256]; // allow up to 256 byte (max) serial number
44812 } result;
44813
44814 - char tmp[24 + 1];
44815 -
44816 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44817
44818 if (token < 0) {
44819 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44820 }
44821
44822 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44823 - seq_printf(seq, "Module name : %s\n",
44824 - chtostr(tmp, result.module_name, 24));
44825 - seq_printf(seq, "Module revision : %s\n",
44826 - chtostr(tmp, result.module_rev, 8));
44827 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
44828 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44829
44830 seq_printf(seq, "Serial number : ");
44831 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44832 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44833 u8 instance_number[4];
44834 } result;
44835
44836 - char tmp[64 + 1];
44837 -
44838 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44839
44840 if (token < 0) {
44841 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44842 return 0;
44843 }
44844
44845 - seq_printf(seq, "Device name : %s\n",
44846 - chtostr(tmp, result.device_name, 64));
44847 - seq_printf(seq, "Service name : %s\n",
44848 - chtostr(tmp, result.service_name, 64));
44849 - seq_printf(seq, "Physical name : %s\n",
44850 - chtostr(tmp, result.physical_location, 64));
44851 - seq_printf(seq, "Instance number : %s\n",
44852 - chtostr(tmp, result.instance_number, 4));
44853 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
44854 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
44855 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44856 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44857
44858 return 0;
44859 }
44860 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44861 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44862 {
44863 struct i2o_device *d = (struct i2o_device *)seq->private;
44864 - static u32 work32[12];
44865 - static u16 *work16 = (u16 *) work32;
44866 - static u8 *work8 = (u8 *) work32;
44867 + u32 work32[12];
44868 + u16 *work16 = (u16 *) work32;
44869 + u8 *work8 = (u8 *) work32;
44870 int token;
44871
44872 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44873 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44874 index a8c08f3..155fe3d 100644
44875 --- a/drivers/message/i2o/iop.c
44876 +++ b/drivers/message/i2o/iop.c
44877 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44878
44879 spin_lock_irqsave(&c->context_list_lock, flags);
44880
44881 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44882 - atomic_inc(&c->context_list_counter);
44883 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44884 + atomic_inc_unchecked(&c->context_list_counter);
44885
44886 - entry->context = atomic_read(&c->context_list_counter);
44887 + entry->context = atomic_read_unchecked(&c->context_list_counter);
44888
44889 list_add(&entry->list, &c->context_list);
44890
44891 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
44892
44893 #if BITS_PER_LONG == 64
44894 spin_lock_init(&c->context_list_lock);
44895 - atomic_set(&c->context_list_counter, 0);
44896 + atomic_set_unchecked(&c->context_list_counter, 0);
44897 INIT_LIST_HEAD(&c->context_list);
44898 #endif
44899
44900 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
44901 index d1a22aa..d0f7bf7 100644
44902 --- a/drivers/mfd/ab8500-debugfs.c
44903 +++ b/drivers/mfd/ab8500-debugfs.c
44904 @@ -100,7 +100,7 @@ static int irq_last;
44905 static u32 *irq_count;
44906 static int num_irqs;
44907
44908 -static struct device_attribute **dev_attr;
44909 +static device_attribute_no_const **dev_attr;
44910 static char **event_name;
44911
44912 static u8 avg_sample = SAMPLE_16;
44913 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
44914 index 81b7d88..95ae998 100644
44915 --- a/drivers/mfd/janz-cmodio.c
44916 +++ b/drivers/mfd/janz-cmodio.c
44917 @@ -13,6 +13,7 @@
44918
44919 #include <linux/kernel.h>
44920 #include <linux/module.h>
44921 +#include <linux/slab.h>
44922 #include <linux/init.h>
44923 #include <linux/pci.h>
44924 #include <linux/interrupt.h>
44925 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
44926 index 176aa26..27811b2 100644
44927 --- a/drivers/mfd/max8925-i2c.c
44928 +++ b/drivers/mfd/max8925-i2c.c
44929 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
44930 const struct i2c_device_id *id)
44931 {
44932 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
44933 - static struct max8925_chip *chip;
44934 + struct max8925_chip *chip;
44935 struct device_node *node = client->dev.of_node;
44936
44937 if (node && !pdata) {
44938 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
44939 index 1f142d7..cc52c2a 100644
44940 --- a/drivers/mfd/tps65910.c
44941 +++ b/drivers/mfd/tps65910.c
44942 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
44943 struct tps65910_platform_data *pdata)
44944 {
44945 int ret = 0;
44946 - static struct regmap_irq_chip *tps6591x_irqs_chip;
44947 + struct regmap_irq_chip *tps6591x_irqs_chip;
44948
44949 if (!irq) {
44950 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
44951 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
44952 index 9aa6d1e..1631bfc 100644
44953 --- a/drivers/mfd/twl4030-irq.c
44954 +++ b/drivers/mfd/twl4030-irq.c
44955 @@ -35,6 +35,7 @@
44956 #include <linux/of.h>
44957 #include <linux/irqdomain.h>
44958 #include <linux/i2c/twl.h>
44959 +#include <asm/pgtable.h>
44960
44961 #include "twl-core.h"
44962
44963 @@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
44964 * Install an irq handler for each of the SIH modules;
44965 * clone dummy irq_chip since PIH can't *do* anything
44966 */
44967 - twl4030_irq_chip = dummy_irq_chip;
44968 - twl4030_irq_chip.name = "twl4030";
44969 + pax_open_kernel();
44970 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
44971 + *(const char **)&twl4030_irq_chip.name = "twl4030";
44972
44973 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44974 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44975 + pax_close_kernel();
44976
44977 for (i = irq_base; i < irq_end; i++) {
44978 irq_set_chip_and_handler(i, &twl4030_irq_chip,
44979 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
44980 index 464419b..64bae8d 100644
44981 --- a/drivers/misc/c2port/core.c
44982 +++ b/drivers/misc/c2port/core.c
44983 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
44984 goto error_idr_alloc;
44985 c2dev->id = ret;
44986
44987 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44988 + pax_open_kernel();
44989 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44990 + pax_close_kernel();
44991
44992 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
44993 "c2port%d", c2dev->id);
44994 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
44995 index 9c34e57..b981cda 100644
44996 --- a/drivers/misc/eeprom/sunxi_sid.c
44997 +++ b/drivers/misc/eeprom/sunxi_sid.c
44998 @@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
44999
45000 platform_set_drvdata(pdev, sid_data);
45001
45002 - sid_bin_attr.size = sid_data->keysize;
45003 + pax_open_kernel();
45004 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45005 + pax_close_kernel();
45006 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45007 return -ENODEV;
45008
45009 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45010 index 36f5d52..32311c3 100644
45011 --- a/drivers/misc/kgdbts.c
45012 +++ b/drivers/misc/kgdbts.c
45013 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45014 char before[BREAK_INSTR_SIZE];
45015 char after[BREAK_INSTR_SIZE];
45016
45017 - probe_kernel_read(before, (char *)kgdbts_break_test,
45018 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45019 BREAK_INSTR_SIZE);
45020 init_simple_test();
45021 ts.tst = plant_and_detach_test;
45022 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45023 /* Activate test with initial breakpoint */
45024 if (!is_early)
45025 kgdb_breakpoint();
45026 - probe_kernel_read(after, (char *)kgdbts_break_test,
45027 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45028 BREAK_INSTR_SIZE);
45029 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45030 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45031 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45032 index 036effe..b3a6336 100644
45033 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45034 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45035 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45036 * the lid is closed. This leads to interrupts as soon as a little move
45037 * is done.
45038 */
45039 - atomic_inc(&lis3->count);
45040 + atomic_inc_unchecked(&lis3->count);
45041
45042 wake_up_interruptible(&lis3->misc_wait);
45043 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45044 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45045 if (lis3->pm_dev)
45046 pm_runtime_get_sync(lis3->pm_dev);
45047
45048 - atomic_set(&lis3->count, 0);
45049 + atomic_set_unchecked(&lis3->count, 0);
45050 return 0;
45051 }
45052
45053 @@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45054 add_wait_queue(&lis3->misc_wait, &wait);
45055 while (true) {
45056 set_current_state(TASK_INTERRUPTIBLE);
45057 - data = atomic_xchg(&lis3->count, 0);
45058 + data = atomic_xchg_unchecked(&lis3->count, 0);
45059 if (data)
45060 break;
45061
45062 @@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45063 struct lis3lv02d, miscdev);
45064
45065 poll_wait(file, &lis3->misc_wait, wait);
45066 - if (atomic_read(&lis3->count))
45067 + if (atomic_read_unchecked(&lis3->count))
45068 return POLLIN | POLLRDNORM;
45069 return 0;
45070 }
45071 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45072 index c439c82..1f20f57 100644
45073 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45074 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45075 @@ -297,7 +297,7 @@ struct lis3lv02d {
45076 struct input_polled_dev *idev; /* input device */
45077 struct platform_device *pdev; /* platform device */
45078 struct regulator_bulk_data regulators[2];
45079 - atomic_t count; /* interrupt count after last read */
45080 + atomic_unchecked_t count; /* interrupt count after last read */
45081 union axis_conversion ac; /* hw -> logical axis */
45082 int mapped_btns[3];
45083
45084 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45085 index 2f30bad..c4c13d0 100644
45086 --- a/drivers/misc/sgi-gru/gruhandles.c
45087 +++ b/drivers/misc/sgi-gru/gruhandles.c
45088 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45089 unsigned long nsec;
45090
45091 nsec = CLKS2NSEC(clks);
45092 - atomic_long_inc(&mcs_op_statistics[op].count);
45093 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45094 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45095 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45096 if (mcs_op_statistics[op].max < nsec)
45097 mcs_op_statistics[op].max = nsec;
45098 }
45099 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45100 index 4f76359..cdfcb2e 100644
45101 --- a/drivers/misc/sgi-gru/gruprocfs.c
45102 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45103 @@ -32,9 +32,9 @@
45104
45105 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45106
45107 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45108 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45109 {
45110 - unsigned long val = atomic_long_read(v);
45111 + unsigned long val = atomic_long_read_unchecked(v);
45112
45113 seq_printf(s, "%16lu %s\n", val, id);
45114 }
45115 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45116
45117 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45118 for (op = 0; op < mcsop_last; op++) {
45119 - count = atomic_long_read(&mcs_op_statistics[op].count);
45120 - total = atomic_long_read(&mcs_op_statistics[op].total);
45121 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45122 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45123 max = mcs_op_statistics[op].max;
45124 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45125 count ? total / count : 0, max);
45126 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45127 index 5c3ce24..4915ccb 100644
45128 --- a/drivers/misc/sgi-gru/grutables.h
45129 +++ b/drivers/misc/sgi-gru/grutables.h
45130 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45131 * GRU statistics.
45132 */
45133 struct gru_stats_s {
45134 - atomic_long_t vdata_alloc;
45135 - atomic_long_t vdata_free;
45136 - atomic_long_t gts_alloc;
45137 - atomic_long_t gts_free;
45138 - atomic_long_t gms_alloc;
45139 - atomic_long_t gms_free;
45140 - atomic_long_t gts_double_allocate;
45141 - atomic_long_t assign_context;
45142 - atomic_long_t assign_context_failed;
45143 - atomic_long_t free_context;
45144 - atomic_long_t load_user_context;
45145 - atomic_long_t load_kernel_context;
45146 - atomic_long_t lock_kernel_context;
45147 - atomic_long_t unlock_kernel_context;
45148 - atomic_long_t steal_user_context;
45149 - atomic_long_t steal_kernel_context;
45150 - atomic_long_t steal_context_failed;
45151 - atomic_long_t nopfn;
45152 - atomic_long_t asid_new;
45153 - atomic_long_t asid_next;
45154 - atomic_long_t asid_wrap;
45155 - atomic_long_t asid_reuse;
45156 - atomic_long_t intr;
45157 - atomic_long_t intr_cbr;
45158 - atomic_long_t intr_tfh;
45159 - atomic_long_t intr_spurious;
45160 - atomic_long_t intr_mm_lock_failed;
45161 - atomic_long_t call_os;
45162 - atomic_long_t call_os_wait_queue;
45163 - atomic_long_t user_flush_tlb;
45164 - atomic_long_t user_unload_context;
45165 - atomic_long_t user_exception;
45166 - atomic_long_t set_context_option;
45167 - atomic_long_t check_context_retarget_intr;
45168 - atomic_long_t check_context_unload;
45169 - atomic_long_t tlb_dropin;
45170 - atomic_long_t tlb_preload_page;
45171 - atomic_long_t tlb_dropin_fail_no_asid;
45172 - atomic_long_t tlb_dropin_fail_upm;
45173 - atomic_long_t tlb_dropin_fail_invalid;
45174 - atomic_long_t tlb_dropin_fail_range_active;
45175 - atomic_long_t tlb_dropin_fail_idle;
45176 - atomic_long_t tlb_dropin_fail_fmm;
45177 - atomic_long_t tlb_dropin_fail_no_exception;
45178 - atomic_long_t tfh_stale_on_fault;
45179 - atomic_long_t mmu_invalidate_range;
45180 - atomic_long_t mmu_invalidate_page;
45181 - atomic_long_t flush_tlb;
45182 - atomic_long_t flush_tlb_gru;
45183 - atomic_long_t flush_tlb_gru_tgh;
45184 - atomic_long_t flush_tlb_gru_zero_asid;
45185 + atomic_long_unchecked_t vdata_alloc;
45186 + atomic_long_unchecked_t vdata_free;
45187 + atomic_long_unchecked_t gts_alloc;
45188 + atomic_long_unchecked_t gts_free;
45189 + atomic_long_unchecked_t gms_alloc;
45190 + atomic_long_unchecked_t gms_free;
45191 + atomic_long_unchecked_t gts_double_allocate;
45192 + atomic_long_unchecked_t assign_context;
45193 + atomic_long_unchecked_t assign_context_failed;
45194 + atomic_long_unchecked_t free_context;
45195 + atomic_long_unchecked_t load_user_context;
45196 + atomic_long_unchecked_t load_kernel_context;
45197 + atomic_long_unchecked_t lock_kernel_context;
45198 + atomic_long_unchecked_t unlock_kernel_context;
45199 + atomic_long_unchecked_t steal_user_context;
45200 + atomic_long_unchecked_t steal_kernel_context;
45201 + atomic_long_unchecked_t steal_context_failed;
45202 + atomic_long_unchecked_t nopfn;
45203 + atomic_long_unchecked_t asid_new;
45204 + atomic_long_unchecked_t asid_next;
45205 + atomic_long_unchecked_t asid_wrap;
45206 + atomic_long_unchecked_t asid_reuse;
45207 + atomic_long_unchecked_t intr;
45208 + atomic_long_unchecked_t intr_cbr;
45209 + atomic_long_unchecked_t intr_tfh;
45210 + atomic_long_unchecked_t intr_spurious;
45211 + atomic_long_unchecked_t intr_mm_lock_failed;
45212 + atomic_long_unchecked_t call_os;
45213 + atomic_long_unchecked_t call_os_wait_queue;
45214 + atomic_long_unchecked_t user_flush_tlb;
45215 + atomic_long_unchecked_t user_unload_context;
45216 + atomic_long_unchecked_t user_exception;
45217 + atomic_long_unchecked_t set_context_option;
45218 + atomic_long_unchecked_t check_context_retarget_intr;
45219 + atomic_long_unchecked_t check_context_unload;
45220 + atomic_long_unchecked_t tlb_dropin;
45221 + atomic_long_unchecked_t tlb_preload_page;
45222 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45223 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45224 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45225 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45226 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45227 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45228 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45229 + atomic_long_unchecked_t tfh_stale_on_fault;
45230 + atomic_long_unchecked_t mmu_invalidate_range;
45231 + atomic_long_unchecked_t mmu_invalidate_page;
45232 + atomic_long_unchecked_t flush_tlb;
45233 + atomic_long_unchecked_t flush_tlb_gru;
45234 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45235 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45236
45237 - atomic_long_t copy_gpa;
45238 - atomic_long_t read_gpa;
45239 + atomic_long_unchecked_t copy_gpa;
45240 + atomic_long_unchecked_t read_gpa;
45241
45242 - atomic_long_t mesq_receive;
45243 - atomic_long_t mesq_receive_none;
45244 - atomic_long_t mesq_send;
45245 - atomic_long_t mesq_send_failed;
45246 - atomic_long_t mesq_noop;
45247 - atomic_long_t mesq_send_unexpected_error;
45248 - atomic_long_t mesq_send_lb_overflow;
45249 - atomic_long_t mesq_send_qlimit_reached;
45250 - atomic_long_t mesq_send_amo_nacked;
45251 - atomic_long_t mesq_send_put_nacked;
45252 - atomic_long_t mesq_page_overflow;
45253 - atomic_long_t mesq_qf_locked;
45254 - atomic_long_t mesq_qf_noop_not_full;
45255 - atomic_long_t mesq_qf_switch_head_failed;
45256 - atomic_long_t mesq_qf_unexpected_error;
45257 - atomic_long_t mesq_noop_unexpected_error;
45258 - atomic_long_t mesq_noop_lb_overflow;
45259 - atomic_long_t mesq_noop_qlimit_reached;
45260 - atomic_long_t mesq_noop_amo_nacked;
45261 - atomic_long_t mesq_noop_put_nacked;
45262 - atomic_long_t mesq_noop_page_overflow;
45263 + atomic_long_unchecked_t mesq_receive;
45264 + atomic_long_unchecked_t mesq_receive_none;
45265 + atomic_long_unchecked_t mesq_send;
45266 + atomic_long_unchecked_t mesq_send_failed;
45267 + atomic_long_unchecked_t mesq_noop;
45268 + atomic_long_unchecked_t mesq_send_unexpected_error;
45269 + atomic_long_unchecked_t mesq_send_lb_overflow;
45270 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45271 + atomic_long_unchecked_t mesq_send_amo_nacked;
45272 + atomic_long_unchecked_t mesq_send_put_nacked;
45273 + atomic_long_unchecked_t mesq_page_overflow;
45274 + atomic_long_unchecked_t mesq_qf_locked;
45275 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45276 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45277 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45278 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45279 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45280 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45281 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45282 + atomic_long_unchecked_t mesq_noop_put_nacked;
45283 + atomic_long_unchecked_t mesq_noop_page_overflow;
45284
45285 };
45286
45287 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45288 tghop_invalidate, mcsop_last};
45289
45290 struct mcs_op_statistic {
45291 - atomic_long_t count;
45292 - atomic_long_t total;
45293 + atomic_long_unchecked_t count;
45294 + atomic_long_unchecked_t total;
45295 unsigned long max;
45296 };
45297
45298 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45299
45300 #define STAT(id) do { \
45301 if (gru_options & OPT_STATS) \
45302 - atomic_long_inc(&gru_stats.id); \
45303 + atomic_long_inc_unchecked(&gru_stats.id); \
45304 } while (0)
45305
45306 #ifdef CONFIG_SGI_GRU_DEBUG
45307 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45308 index c862cd4..0d176fe 100644
45309 --- a/drivers/misc/sgi-xp/xp.h
45310 +++ b/drivers/misc/sgi-xp/xp.h
45311 @@ -288,7 +288,7 @@ struct xpc_interface {
45312 xpc_notify_func, void *);
45313 void (*received) (short, int, void *);
45314 enum xp_retval (*partid_to_nasids) (short, void *);
45315 -};
45316 +} __no_const;
45317
45318 extern struct xpc_interface xpc_interface;
45319
45320 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45321 index 01be66d..e3a0c7e 100644
45322 --- a/drivers/misc/sgi-xp/xp_main.c
45323 +++ b/drivers/misc/sgi-xp/xp_main.c
45324 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45325 }
45326
45327 struct xpc_interface xpc_interface = {
45328 - (void (*)(int))xpc_notloaded,
45329 - (void (*)(int))xpc_notloaded,
45330 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45331 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45332 + .connect = (void (*)(int))xpc_notloaded,
45333 + .disconnect = (void (*)(int))xpc_notloaded,
45334 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45335 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45336 void *))xpc_notloaded,
45337 - (void (*)(short, int, void *))xpc_notloaded,
45338 - (enum xp_retval(*)(short, void *))xpc_notloaded
45339 + .received = (void (*)(short, int, void *))xpc_notloaded,
45340 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45341 };
45342 EXPORT_SYMBOL_GPL(xpc_interface);
45343
45344 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45345 index b94d5f7..7f494c5 100644
45346 --- a/drivers/misc/sgi-xp/xpc.h
45347 +++ b/drivers/misc/sgi-xp/xpc.h
45348 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
45349 void (*received_payload) (struct xpc_channel *, void *);
45350 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45351 };
45352 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45353
45354 /* struct xpc_partition act_state values (for XPC HB) */
45355
45356 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45357 /* found in xpc_main.c */
45358 extern struct device *xpc_part;
45359 extern struct device *xpc_chan;
45360 -extern struct xpc_arch_operations xpc_arch_ops;
45361 +extern xpc_arch_operations_no_const xpc_arch_ops;
45362 extern int xpc_disengage_timelimit;
45363 extern int xpc_disengage_timedout;
45364 extern int xpc_activate_IRQ_rcvd;
45365 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45366 index 82dc574..8539ab2 100644
45367 --- a/drivers/misc/sgi-xp/xpc_main.c
45368 +++ b/drivers/misc/sgi-xp/xpc_main.c
45369 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45370 .notifier_call = xpc_system_die,
45371 };
45372
45373 -struct xpc_arch_operations xpc_arch_ops;
45374 +xpc_arch_operations_no_const xpc_arch_ops;
45375
45376 /*
45377 * Timer function to enforce the timelimit on the partition disengage.
45378 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45379
45380 if (((die_args->trapnr == X86_TRAP_MF) ||
45381 (die_args->trapnr == X86_TRAP_XF)) &&
45382 - !user_mode_vm(die_args->regs))
45383 + !user_mode(die_args->regs))
45384 xpc_die_deactivate();
45385
45386 break;
45387 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45388 index 7b5424f..ed1d6ac 100644
45389 --- a/drivers/mmc/card/block.c
45390 +++ b/drivers/mmc/card/block.c
45391 @@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45392 if (idata->ic.postsleep_min_us)
45393 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45394
45395 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45396 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45397 err = -EFAULT;
45398 goto cmd_rel_host;
45399 }
45400 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45401 index e5b5eeb..7bf2212 100644
45402 --- a/drivers/mmc/core/mmc_ops.c
45403 +++ b/drivers/mmc/core/mmc_ops.c
45404 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45405 void *data_buf;
45406 int is_on_stack;
45407
45408 - is_on_stack = object_is_on_stack(buf);
45409 + is_on_stack = object_starts_on_stack(buf);
45410 if (is_on_stack) {
45411 /*
45412 * dma onto stack is unsafe/nonportable, but callers to this
45413 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45414 index 6bf24ab..13d0293b 100644
45415 --- a/drivers/mmc/host/dw_mmc.h
45416 +++ b/drivers/mmc/host/dw_mmc.h
45417 @@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45418 int (*parse_dt)(struct dw_mci *host);
45419 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45420 struct dw_mci_tuning_data *tuning_data);
45421 -};
45422 +} __do_const;
45423 #endif /* _DW_MMC_H_ */
45424 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45425 index b931226..df6a085 100644
45426 --- a/drivers/mmc/host/mmci.c
45427 +++ b/drivers/mmc/host/mmci.c
45428 @@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45429 }
45430
45431 if (variant->busy_detect) {
45432 - mmci_ops.card_busy = mmci_card_busy;
45433 + pax_open_kernel();
45434 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
45435 + pax_close_kernel();
45436 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45437 }
45438
45439 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45440 index b841bb7..d82712f5 100644
45441 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
45442 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45443 @@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45444 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45445 }
45446
45447 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45448 - sdhci_esdhc_ops.platform_execute_tuning =
45449 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45450 + pax_open_kernel();
45451 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45452 esdhc_executing_tuning;
45453 + pax_close_kernel();
45454 + }
45455
45456 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45457 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45458 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45459 index 6debda9..2ba7427 100644
45460 --- a/drivers/mmc/host/sdhci-s3c.c
45461 +++ b/drivers/mmc/host/sdhci-s3c.c
45462 @@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45463 * we can use overriding functions instead of default.
45464 */
45465 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45466 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45467 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45468 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45469 + pax_open_kernel();
45470 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45471 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45472 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45473 + pax_close_kernel();
45474 }
45475
45476 /* It supports additional host capabilities if needed */
45477 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45478 index 096993f..f02c23b 100644
45479 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
45480 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45481 @@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45482 size_t totlen = 0, thislen;
45483 int ret = 0;
45484 size_t buflen = 0;
45485 - static char *buffer;
45486 + char *buffer;
45487
45488 if (!ECCBUF_SIZE) {
45489 /* We should fall back to a general writev implementation.
45490 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45491 index c07cd57..61c4fbd 100644
45492 --- a/drivers/mtd/nand/denali.c
45493 +++ b/drivers/mtd/nand/denali.c
45494 @@ -24,6 +24,7 @@
45495 #include <linux/slab.h>
45496 #include <linux/mtd/mtd.h>
45497 #include <linux/module.h>
45498 +#include <linux/slab.h>
45499
45500 #include "denali.h"
45501
45502 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45503 index 51b9d6a..52af9a7 100644
45504 --- a/drivers/mtd/nftlmount.c
45505 +++ b/drivers/mtd/nftlmount.c
45506 @@ -24,6 +24,7 @@
45507 #include <asm/errno.h>
45508 #include <linux/delay.h>
45509 #include <linux/slab.h>
45510 +#include <linux/sched.h>
45511 #include <linux/mtd/mtd.h>
45512 #include <linux/mtd/nand.h>
45513 #include <linux/mtd/nftl.h>
45514 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45515 index 4b8e895..6b3c498 100644
45516 --- a/drivers/mtd/sm_ftl.c
45517 +++ b/drivers/mtd/sm_ftl.c
45518 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45519 #define SM_CIS_VENDOR_OFFSET 0x59
45520 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45521 {
45522 - struct attribute_group *attr_group;
45523 + attribute_group_no_const *attr_group;
45524 struct attribute **attributes;
45525 struct sm_sysfs_attribute *vendor_attribute;
45526
45527 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45528 index e5628fc..ffe54d1 100644
45529 --- a/drivers/net/bonding/bond_main.c
45530 +++ b/drivers/net/bonding/bond_main.c
45531 @@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
45532
45533 bond_netlink_fini();
45534 unregister_pernet_subsys(&bond_net_ops);
45535 + rtnl_link_unregister(&bond_link_ops);
45536
45537 #ifdef CONFIG_NET_POLL_CONTROLLER
45538 /*
45539 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45540 index 70651f8..7eb1bdf 100644
45541 --- a/drivers/net/bonding/bond_netlink.c
45542 +++ b/drivers/net/bonding/bond_netlink.c
45543 @@ -542,7 +542,7 @@ nla_put_failure:
45544 return -EMSGSIZE;
45545 }
45546
45547 -struct rtnl_link_ops bond_link_ops __read_mostly = {
45548 +struct rtnl_link_ops bond_link_ops = {
45549 .kind = "bond",
45550 .priv_size = sizeof(struct bonding),
45551 .setup = bond_setup,
45552 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45553 index 9e7d95d..d447b88 100644
45554 --- a/drivers/net/can/Kconfig
45555 +++ b/drivers/net/can/Kconfig
45556 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45557
45558 config CAN_FLEXCAN
45559 tristate "Support for Freescale FLEXCAN based chips"
45560 - depends on ARM || PPC
45561 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45562 ---help---
45563 Say Y here if you want to support for Freescale FlexCAN.
45564
45565 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45566 index 455d4c3..3353ee7 100644
45567 --- a/drivers/net/ethernet/8390/ax88796.c
45568 +++ b/drivers/net/ethernet/8390/ax88796.c
45569 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
45570 if (ax->plat->reg_offsets)
45571 ei_local->reg_offset = ax->plat->reg_offsets;
45572 else {
45573 + resource_size_t _mem_size = mem_size;
45574 + do_div(_mem_size, 0x18);
45575 ei_local->reg_offset = ax->reg_offsets;
45576 for (ret = 0; ret < 0x18; ret++)
45577 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45578 + ax->reg_offsets[ret] = _mem_size * ret;
45579 }
45580
45581 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45582 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45583 index a89a40f..5a8a2ac 100644
45584 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45585 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45586 @@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45587 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45588 {
45589 /* RX_MODE controlling object */
45590 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45591 + bnx2x_init_rx_mode_obj(bp);
45592
45593 /* multicast configuration controlling object */
45594 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45595 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45596 index 0fb6ff2..78fd55c 100644
45597 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45598 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45599 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45600 return rc;
45601 }
45602
45603 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45604 - struct bnx2x_rx_mode_obj *o)
45605 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45606 {
45607 if (CHIP_IS_E1x(bp)) {
45608 - o->wait_comp = bnx2x_empty_rx_mode_wait;
45609 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45610 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45611 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45612 } else {
45613 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45614 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
45615 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45616 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45617 }
45618 }
45619
45620 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45621 index 00d7f21..2cddec4 100644
45622 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45623 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45624 @@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45625
45626 /********************* RX MODE ****************/
45627
45628 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45629 - struct bnx2x_rx_mode_obj *o);
45630 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45631
45632 /**
45633 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45634 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45635 index 04321e5..b51cdc4 100644
45636 --- a/drivers/net/ethernet/broadcom/tg3.h
45637 +++ b/drivers/net/ethernet/broadcom/tg3.h
45638 @@ -150,6 +150,7 @@
45639 #define CHIPREV_ID_5750_A0 0x4000
45640 #define CHIPREV_ID_5750_A1 0x4001
45641 #define CHIPREV_ID_5750_A3 0x4003
45642 +#define CHIPREV_ID_5750_C1 0x4201
45643 #define CHIPREV_ID_5750_C2 0x4202
45644 #define CHIPREV_ID_5752_A0_HW 0x5000
45645 #define CHIPREV_ID_5752_A0 0x6000
45646 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45647 index 13f9636..228040f 100644
45648 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45649 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45650 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45651 }
45652
45653 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45654 - bna_cb_ioceth_enable,
45655 - bna_cb_ioceth_disable,
45656 - bna_cb_ioceth_hbfail,
45657 - bna_cb_ioceth_reset
45658 + .enable_cbfn = bna_cb_ioceth_enable,
45659 + .disable_cbfn = bna_cb_ioceth_disable,
45660 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
45661 + .reset_cbfn = bna_cb_ioceth_reset
45662 };
45663
45664 static void bna_attr_init(struct bna_ioceth *ioceth)
45665 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45666 index 8cffcdf..aadf043 100644
45667 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45668 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45669 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45670 */
45671 struct l2t_skb_cb {
45672 arp_failure_handler_func arp_failure_handler;
45673 -};
45674 +} __no_const;
45675
45676 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45677
45678 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45679 index 34e2488..07e2079 100644
45680 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45681 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45682 @@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45683
45684 int i;
45685 struct adapter *ap = netdev2adap(dev);
45686 - static const unsigned int *reg_ranges;
45687 + const unsigned int *reg_ranges;
45688 int arr_size = 0, buf_size = 0;
45689
45690 if (is_t4(ap->params.chip)) {
45691 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45692 index c05b66d..ed69872 100644
45693 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
45694 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45695 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45696 for (i=0; i<ETH_ALEN; i++) {
45697 tmp.addr[i] = dev->dev_addr[i];
45698 }
45699 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45700 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45701 break;
45702
45703 case DE4X5_SET_HWADDR: /* Set the hardware address */
45704 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45705 spin_lock_irqsave(&lp->lock, flags);
45706 memcpy(&statbuf, &lp->pktStats, ioc->len);
45707 spin_unlock_irqrestore(&lp->lock, flags);
45708 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
45709 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45710 return -EFAULT;
45711 break;
45712 }
45713 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45714 index 36c8061..ca5e1e0 100644
45715 --- a/drivers/net/ethernet/emulex/benet/be_main.c
45716 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
45717 @@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45718
45719 if (wrapped)
45720 newacc += 65536;
45721 - ACCESS_ONCE(*acc) = newacc;
45722 + ACCESS_ONCE_RW(*acc) = newacc;
45723 }
45724
45725 static void populate_erx_stats(struct be_adapter *adapter,
45726 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45727 index c11ecbc..13bb299 100644
45728 --- a/drivers/net/ethernet/faraday/ftgmac100.c
45729 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
45730 @@ -30,6 +30,8 @@
45731 #include <linux/netdevice.h>
45732 #include <linux/phy.h>
45733 #include <linux/platform_device.h>
45734 +#include <linux/interrupt.h>
45735 +#include <linux/irqreturn.h>
45736 #include <net/ip.h>
45737
45738 #include "ftgmac100.h"
45739 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45740 index 8be5b40..081bc1b 100644
45741 --- a/drivers/net/ethernet/faraday/ftmac100.c
45742 +++ b/drivers/net/ethernet/faraday/ftmac100.c
45743 @@ -31,6 +31,8 @@
45744 #include <linux/module.h>
45745 #include <linux/netdevice.h>
45746 #include <linux/platform_device.h>
45747 +#include <linux/interrupt.h>
45748 +#include <linux/irqreturn.h>
45749
45750 #include "ftmac100.h"
45751
45752 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45753 index e33ec6c..f54cfe7 100644
45754 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45755 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45756 @@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
45757 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
45758
45759 /* Update the base adjustement value. */
45760 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
45761 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
45762 smp_mb(); /* Force the above update. */
45763 }
45764
45765 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45766 index 5184e2a..acb28c3 100644
45767 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45768 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45769 @@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45770 }
45771
45772 /* update the base incval used to calculate frequency adjustment */
45773 - ACCESS_ONCE(adapter->base_incval) = incval;
45774 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
45775 smp_mb();
45776
45777 /* need lock to prevent incorrect read while modifying cyclecounter */
45778 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45779 index 089b713..28d87ae 100644
45780 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45781 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45782 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45783 struct __vxge_hw_fifo *fifo;
45784 struct vxge_hw_fifo_config *config;
45785 u32 txdl_size, txdl_per_memblock;
45786 - struct vxge_hw_mempool_cbs fifo_mp_callback;
45787 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45788 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45789 + };
45790 +
45791 struct __vxge_hw_virtualpath *vpath;
45792
45793 if ((vp == NULL) || (attr == NULL)) {
45794 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45795 goto exit;
45796 }
45797
45798 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45799 -
45800 fifo->mempool =
45801 __vxge_hw_mempool_create(vpath->hldev,
45802 fifo->config->memblock_size,
45803 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45804 index 90a2dda..47e620e 100644
45805 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45806 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45807 @@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45808 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45809 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45810 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45811 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45812 + pax_open_kernel();
45813 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45814 + pax_close_kernel();
45815 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45816 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45817 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45818 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45819 index be7d7a6..a8983f8 100644
45820 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45821 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45822 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45823 case QLCNIC_NON_PRIV_FUNC:
45824 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45825 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45826 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45827 + pax_open_kernel();
45828 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45829 + pax_close_kernel();
45830 break;
45831 case QLCNIC_PRIV_FUNC:
45832 ahw->op_mode = QLCNIC_PRIV_FUNC;
45833 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45834 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45835 + pax_open_kernel();
45836 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45837 + pax_close_kernel();
45838 break;
45839 case QLCNIC_MGMT_FUNC:
45840 ahw->op_mode = QLCNIC_MGMT_FUNC;
45841 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45842 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45843 + pax_open_kernel();
45844 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45845 + pax_close_kernel();
45846 break;
45847 default:
45848 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45849 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45850 index 7763962..c3499a7 100644
45851 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45852 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45853 @@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45854 struct qlcnic_dump_entry *entry;
45855 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45856 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45857 - static const struct qlcnic_dump_operations *fw_dump_ops;
45858 + const struct qlcnic_dump_operations *fw_dump_ops;
45859 struct device *dev = &adapter->pdev->dev;
45860 struct qlcnic_hardware_context *ahw;
45861 void *temp_buffer;
45862 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45863 index 3ff7bc3..366091b 100644
45864 --- a/drivers/net/ethernet/realtek/r8169.c
45865 +++ b/drivers/net/ethernet/realtek/r8169.c
45866 @@ -758,22 +758,22 @@ struct rtl8169_private {
45867 struct mdio_ops {
45868 void (*write)(struct rtl8169_private *, int, int);
45869 int (*read)(struct rtl8169_private *, int);
45870 - } mdio_ops;
45871 + } __no_const mdio_ops;
45872
45873 struct pll_power_ops {
45874 void (*down)(struct rtl8169_private *);
45875 void (*up)(struct rtl8169_private *);
45876 - } pll_power_ops;
45877 + } __no_const pll_power_ops;
45878
45879 struct jumbo_ops {
45880 void (*enable)(struct rtl8169_private *);
45881 void (*disable)(struct rtl8169_private *);
45882 - } jumbo_ops;
45883 + } __no_const jumbo_ops;
45884
45885 struct csi_ops {
45886 void (*write)(struct rtl8169_private *, int, int);
45887 u32 (*read)(struct rtl8169_private *, int);
45888 - } csi_ops;
45889 + } __no_const csi_ops;
45890
45891 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45892 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45893 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45894 index d7a3682..9ce272a 100644
45895 --- a/drivers/net/ethernet/sfc/ptp.c
45896 +++ b/drivers/net/ethernet/sfc/ptp.c
45897 @@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
45898 ptp->start.dma_addr);
45899
45900 /* Clear flag that signals MC ready */
45901 - ACCESS_ONCE(*start) = 0;
45902 + ACCESS_ONCE_RW(*start) = 0;
45903 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
45904 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
45905 EFX_BUG_ON_PARANOID(rc);
45906 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45907 index 50617c5..b13724c 100644
45908 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45909 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45910 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
45911
45912 writel(value, ioaddr + MMC_CNTRL);
45913
45914 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45915 - MMC_CNTRL, value);
45916 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45917 +// MMC_CNTRL, value);
45918 }
45919
45920 /* To mask all all interrupts.*/
45921 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
45922 index 7b594ce..1f6c5708 100644
45923 --- a/drivers/net/hyperv/hyperv_net.h
45924 +++ b/drivers/net/hyperv/hyperv_net.h
45925 @@ -100,7 +100,7 @@ struct rndis_device {
45926
45927 enum rndis_device_state state;
45928 bool link_state;
45929 - atomic_t new_req_id;
45930 + atomic_unchecked_t new_req_id;
45931
45932 spinlock_t request_lock;
45933 struct list_head req_list;
45934 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
45935 index b54fd25..9bd2bae 100644
45936 --- a/drivers/net/hyperv/rndis_filter.c
45937 +++ b/drivers/net/hyperv/rndis_filter.c
45938 @@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
45939 * template
45940 */
45941 set = &rndis_msg->msg.set_req;
45942 - set->req_id = atomic_inc_return(&dev->new_req_id);
45943 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45944
45945 /* Add to the request list */
45946 spin_lock_irqsave(&dev->request_lock, flags);
45947 @@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
45948
45949 /* Setup the rndis set */
45950 halt = &request->request_msg.msg.halt_req;
45951 - halt->req_id = atomic_inc_return(&dev->new_req_id);
45952 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45953
45954 /* Ignore return since this msg is optional. */
45955 rndis_filter_send_request(dev, request);
45956 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
45957 index bf0d55e..82bcfbd1 100644
45958 --- a/drivers/net/ieee802154/fakehard.c
45959 +++ b/drivers/net/ieee802154/fakehard.c
45960 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
45961 phy->transmit_power = 0xbf;
45962
45963 dev->netdev_ops = &fake_ops;
45964 - dev->ml_priv = &fake_mlme;
45965 + dev->ml_priv = (void *)&fake_mlme;
45966
45967 priv = netdev_priv(dev);
45968 priv->phy = phy;
45969 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
45970 index 1831fb7..9c24bca 100644
45971 --- a/drivers/net/macvlan.c
45972 +++ b/drivers/net/macvlan.c
45973 @@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
45974 int macvlan_link_register(struct rtnl_link_ops *ops)
45975 {
45976 /* common fields */
45977 - ops->priv_size = sizeof(struct macvlan_dev);
45978 - ops->validate = macvlan_validate;
45979 - ops->maxtype = IFLA_MACVLAN_MAX;
45980 - ops->policy = macvlan_policy;
45981 - ops->changelink = macvlan_changelink;
45982 - ops->get_size = macvlan_get_size;
45983 - ops->fill_info = macvlan_fill_info;
45984 + pax_open_kernel();
45985 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
45986 + *(void **)&ops->validate = macvlan_validate;
45987 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
45988 + *(const void **)&ops->policy = macvlan_policy;
45989 + *(void **)&ops->changelink = macvlan_changelink;
45990 + *(void **)&ops->get_size = macvlan_get_size;
45991 + *(void **)&ops->fill_info = macvlan_fill_info;
45992 + pax_close_kernel();
45993
45994 return rtnl_link_register(ops);
45995 };
45996 @@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
45997 return NOTIFY_DONE;
45998 }
45999
46000 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46001 +static struct notifier_block macvlan_notifier_block = {
46002 .notifier_call = macvlan_device_event,
46003 };
46004
46005 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46006 index ff111a8..c4c3ac4 100644
46007 --- a/drivers/net/macvtap.c
46008 +++ b/drivers/net/macvtap.c
46009 @@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46010 }
46011
46012 ret = 0;
46013 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46014 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46015 put_user(q->flags, &ifr->ifr_flags))
46016 ret = -EFAULT;
46017 macvtap_put_vlan(vlan);
46018 @@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46019 return NOTIFY_DONE;
46020 }
46021
46022 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46023 +static struct notifier_block macvtap_notifier_block = {
46024 .notifier_call = macvtap_device_event,
46025 };
46026
46027 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46028 index daec9b0..6428fcb 100644
46029 --- a/drivers/net/phy/mdio-bitbang.c
46030 +++ b/drivers/net/phy/mdio-bitbang.c
46031 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46032 struct mdiobb_ctrl *ctrl = bus->priv;
46033
46034 module_put(ctrl->ops->owner);
46035 + mdiobus_unregister(bus);
46036 mdiobus_free(bus);
46037 }
46038 EXPORT_SYMBOL(free_mdio_bitbang);
46039 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46040 index 72ff14b..11d442d 100644
46041 --- a/drivers/net/ppp/ppp_generic.c
46042 +++ b/drivers/net/ppp/ppp_generic.c
46043 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46044 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46045 struct ppp_stats stats;
46046 struct ppp_comp_stats cstats;
46047 - char *vers;
46048
46049 switch (cmd) {
46050 case SIOCGPPPSTATS:
46051 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46052 break;
46053
46054 case SIOCGPPPVER:
46055 - vers = PPP_VERSION;
46056 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46057 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46058 break;
46059 err = 0;
46060 break;
46061 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46062 index 1252d9c..80e660b 100644
46063 --- a/drivers/net/slip/slhc.c
46064 +++ b/drivers/net/slip/slhc.c
46065 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46066 register struct tcphdr *thp;
46067 register struct iphdr *ip;
46068 register struct cstate *cs;
46069 - int len, hdrlen;
46070 + long len, hdrlen;
46071 unsigned char *cp = icp;
46072
46073 /* We've got a compressed packet; read the change byte */
46074 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46075 index c8624a8..f0a4f6a 100644
46076 --- a/drivers/net/team/team.c
46077 +++ b/drivers/net/team/team.c
46078 @@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46079 return NOTIFY_DONE;
46080 }
46081
46082 -static struct notifier_block team_notifier_block __read_mostly = {
46083 +static struct notifier_block team_notifier_block = {
46084 .notifier_call = team_device_event,
46085 };
46086
46087 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46088 index 26f8635..c237839 100644
46089 --- a/drivers/net/tun.c
46090 +++ b/drivers/net/tun.c
46091 @@ -1876,7 +1876,7 @@ unlock:
46092 }
46093
46094 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46095 - unsigned long arg, int ifreq_len)
46096 + unsigned long arg, size_t ifreq_len)
46097 {
46098 struct tun_file *tfile = file->private_data;
46099 struct tun_struct *tun;
46100 @@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46101 unsigned int ifindex;
46102 int ret;
46103
46104 + if (ifreq_len > sizeof ifr)
46105 + return -EFAULT;
46106 +
46107 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46108 if (copy_from_user(&ifr, argp, ifreq_len))
46109 return -EFAULT;
46110 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46111 index 660bd5e..ac59452 100644
46112 --- a/drivers/net/usb/hso.c
46113 +++ b/drivers/net/usb/hso.c
46114 @@ -71,7 +71,7 @@
46115 #include <asm/byteorder.h>
46116 #include <linux/serial_core.h>
46117 #include <linux/serial.h>
46118 -
46119 +#include <asm/local.h>
46120
46121 #define MOD_AUTHOR "Option Wireless"
46122 #define MOD_DESCRIPTION "USB High Speed Option driver"
46123 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46124 struct urb *urb;
46125
46126 urb = serial->rx_urb[0];
46127 - if (serial->port.count > 0) {
46128 + if (atomic_read(&serial->port.count) > 0) {
46129 count = put_rxbuf_data(urb, serial);
46130 if (count == -1)
46131 return;
46132 @@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46133 DUMP1(urb->transfer_buffer, urb->actual_length);
46134
46135 /* Anyone listening? */
46136 - if (serial->port.count == 0)
46137 + if (atomic_read(&serial->port.count) == 0)
46138 return;
46139
46140 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46141 @@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46142 tty_port_tty_set(&serial->port, tty);
46143
46144 /* check for port already opened, if not set the termios */
46145 - serial->port.count++;
46146 - if (serial->port.count == 1) {
46147 + if (atomic_inc_return(&serial->port.count) == 1) {
46148 serial->rx_state = RX_IDLE;
46149 /* Force default termio settings */
46150 _hso_serial_set_termios(tty, NULL);
46151 @@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46152 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46153 if (result) {
46154 hso_stop_serial_device(serial->parent);
46155 - serial->port.count--;
46156 + atomic_dec(&serial->port.count);
46157 kref_put(&serial->parent->ref, hso_serial_ref_free);
46158 }
46159 } else {
46160 @@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46161
46162 /* reset the rts and dtr */
46163 /* do the actual close */
46164 - serial->port.count--;
46165 + atomic_dec(&serial->port.count);
46166
46167 - if (serial->port.count <= 0) {
46168 - serial->port.count = 0;
46169 + if (atomic_read(&serial->port.count) <= 0) {
46170 + atomic_set(&serial->port.count, 0);
46171 tty_port_tty_set(&serial->port, NULL);
46172 if (!usb_gone)
46173 hso_stop_serial_device(serial->parent);
46174 @@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46175
46176 /* the actual setup */
46177 spin_lock_irqsave(&serial->serial_lock, flags);
46178 - if (serial->port.count)
46179 + if (atomic_read(&serial->port.count))
46180 _hso_serial_set_termios(tty, old);
46181 else
46182 tty->termios = *old;
46183 @@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46184 D1("Pending read interrupt on port %d\n", i);
46185 spin_lock(&serial->serial_lock);
46186 if (serial->rx_state == RX_IDLE &&
46187 - serial->port.count > 0) {
46188 + atomic_read(&serial->port.count) > 0) {
46189 /* Setup and send a ctrl req read on
46190 * port i */
46191 if (!serial->rx_urb_filled[0]) {
46192 @@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46193 /* Start all serial ports */
46194 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46195 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46196 - if (dev2ser(serial_table[i])->port.count) {
46197 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46198 result =
46199 hso_start_serial_device(serial_table[i], GFP_NOIO);
46200 hso_kick_transmit(dev2ser(serial_table[i]));
46201 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46202 index adb12f3..48005ab 100644
46203 --- a/drivers/net/usb/r8152.c
46204 +++ b/drivers/net/usb/r8152.c
46205 @@ -513,7 +513,7 @@ struct r8152 {
46206 void (*disable)(struct r8152 *);
46207 void (*down)(struct r8152 *);
46208 void (*unload)(struct r8152 *);
46209 - } rtl_ops;
46210 + } __no_const rtl_ops;
46211
46212 int intr_interval;
46213 u32 msg_enable;
46214 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46215 index a2515887..6d13233 100644
46216 --- a/drivers/net/usb/sierra_net.c
46217 +++ b/drivers/net/usb/sierra_net.c
46218 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46219 /* atomic counter partially included in MAC address to make sure 2 devices
46220 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46221 */
46222 -static atomic_t iface_counter = ATOMIC_INIT(0);
46223 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46224
46225 /*
46226 * SYNC Timer Delay definition used to set the expiry time
46227 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46228 dev->net->netdev_ops = &sierra_net_device_ops;
46229
46230 /* change MAC addr to include, ifacenum, and to be unique */
46231 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46232 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46233 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46234
46235 /* we will have to manufacture ethernet headers, prepare template */
46236 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46237 index d091e52..568bb179 100644
46238 --- a/drivers/net/vxlan.c
46239 +++ b/drivers/net/vxlan.c
46240 @@ -2847,7 +2847,7 @@ nla_put_failure:
46241 return -EMSGSIZE;
46242 }
46243
46244 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46245 +static struct rtnl_link_ops vxlan_link_ops = {
46246 .kind = "vxlan",
46247 .maxtype = IFLA_VXLAN_MAX,
46248 .policy = vxlan_policy,
46249 @@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46250 return NOTIFY_DONE;
46251 }
46252
46253 -static struct notifier_block vxlan_notifier_block __read_mostly = {
46254 +static struct notifier_block vxlan_notifier_block = {
46255 .notifier_call = vxlan_lowerdev_event,
46256 };
46257
46258 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46259 index 5920c99..ff2e4a5 100644
46260 --- a/drivers/net/wan/lmc/lmc_media.c
46261 +++ b/drivers/net/wan/lmc/lmc_media.c
46262 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46263 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46264
46265 lmc_media_t lmc_ds3_media = {
46266 - lmc_ds3_init, /* special media init stuff */
46267 - lmc_ds3_default, /* reset to default state */
46268 - lmc_ds3_set_status, /* reset status to state provided */
46269 - lmc_dummy_set_1, /* set clock source */
46270 - lmc_dummy_set2_1, /* set line speed */
46271 - lmc_ds3_set_100ft, /* set cable length */
46272 - lmc_ds3_set_scram, /* set scrambler */
46273 - lmc_ds3_get_link_status, /* get link status */
46274 - lmc_dummy_set_1, /* set link status */
46275 - lmc_ds3_set_crc_length, /* set CRC length */
46276 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46277 - lmc_ds3_watchdog
46278 + .init = lmc_ds3_init, /* special media init stuff */
46279 + .defaults = lmc_ds3_default, /* reset to default state */
46280 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46281 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46282 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46283 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46284 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46285 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46286 + .set_link_status = lmc_dummy_set_1, /* set link status */
46287 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46288 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46289 + .watchdog = lmc_ds3_watchdog
46290 };
46291
46292 lmc_media_t lmc_hssi_media = {
46293 - lmc_hssi_init, /* special media init stuff */
46294 - lmc_hssi_default, /* reset to default state */
46295 - lmc_hssi_set_status, /* reset status to state provided */
46296 - lmc_hssi_set_clock, /* set clock source */
46297 - lmc_dummy_set2_1, /* set line speed */
46298 - lmc_dummy_set_1, /* set cable length */
46299 - lmc_dummy_set_1, /* set scrambler */
46300 - lmc_hssi_get_link_status, /* get link status */
46301 - lmc_hssi_set_link_status, /* set link status */
46302 - lmc_hssi_set_crc_length, /* set CRC length */
46303 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46304 - lmc_hssi_watchdog
46305 + .init = lmc_hssi_init, /* special media init stuff */
46306 + .defaults = lmc_hssi_default, /* reset to default state */
46307 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46308 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46309 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46310 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46311 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46312 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
46313 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
46314 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46315 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46316 + .watchdog = lmc_hssi_watchdog
46317 };
46318
46319 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46320 - lmc_ssi_default, /* reset to default state */
46321 - lmc_ssi_set_status, /* reset status to state provided */
46322 - lmc_ssi_set_clock, /* set clock source */
46323 - lmc_ssi_set_speed, /* set line speed */
46324 - lmc_dummy_set_1, /* set cable length */
46325 - lmc_dummy_set_1, /* set scrambler */
46326 - lmc_ssi_get_link_status, /* get link status */
46327 - lmc_ssi_set_link_status, /* set link status */
46328 - lmc_ssi_set_crc_length, /* set CRC length */
46329 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46330 - lmc_ssi_watchdog
46331 +lmc_media_t lmc_ssi_media = {
46332 + .init = lmc_ssi_init, /* special media init stuff */
46333 + .defaults = lmc_ssi_default, /* reset to default state */
46334 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
46335 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46336 + .set_speed = lmc_ssi_set_speed, /* set line speed */
46337 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46338 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46339 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
46340 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
46341 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46342 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46343 + .watchdog = lmc_ssi_watchdog
46344 };
46345
46346 lmc_media_t lmc_t1_media = {
46347 - lmc_t1_init, /* special media init stuff */
46348 - lmc_t1_default, /* reset to default state */
46349 - lmc_t1_set_status, /* reset status to state provided */
46350 - lmc_t1_set_clock, /* set clock source */
46351 - lmc_dummy_set2_1, /* set line speed */
46352 - lmc_dummy_set_1, /* set cable length */
46353 - lmc_dummy_set_1, /* set scrambler */
46354 - lmc_t1_get_link_status, /* get link status */
46355 - lmc_dummy_set_1, /* set link status */
46356 - lmc_t1_set_crc_length, /* set CRC length */
46357 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46358 - lmc_t1_watchdog
46359 + .init = lmc_t1_init, /* special media init stuff */
46360 + .defaults = lmc_t1_default, /* reset to default state */
46361 + .set_status = lmc_t1_set_status, /* reset status to state provided */
46362 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
46363 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46364 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46365 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46366 + .get_link_status = lmc_t1_get_link_status, /* get link status */
46367 + .set_link_status = lmc_dummy_set_1, /* set link status */
46368 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46369 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46370 + .watchdog = lmc_t1_watchdog
46371 };
46372
46373 static void
46374 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46375 index feacc3b..5bac0de 100644
46376 --- a/drivers/net/wan/z85230.c
46377 +++ b/drivers/net/wan/z85230.c
46378 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46379
46380 struct z8530_irqhandler z8530_sync =
46381 {
46382 - z8530_rx,
46383 - z8530_tx,
46384 - z8530_status
46385 + .rx = z8530_rx,
46386 + .tx = z8530_tx,
46387 + .status = z8530_status
46388 };
46389
46390 EXPORT_SYMBOL(z8530_sync);
46391 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46392 }
46393
46394 static struct z8530_irqhandler z8530_dma_sync = {
46395 - z8530_dma_rx,
46396 - z8530_dma_tx,
46397 - z8530_dma_status
46398 + .rx = z8530_dma_rx,
46399 + .tx = z8530_dma_tx,
46400 + .status = z8530_dma_status
46401 };
46402
46403 static struct z8530_irqhandler z8530_txdma_sync = {
46404 - z8530_rx,
46405 - z8530_dma_tx,
46406 - z8530_dma_status
46407 + .rx = z8530_rx,
46408 + .tx = z8530_dma_tx,
46409 + .status = z8530_dma_status
46410 };
46411
46412 /**
46413 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46414
46415 struct z8530_irqhandler z8530_nop=
46416 {
46417 - z8530_rx_clear,
46418 - z8530_tx_clear,
46419 - z8530_status_clear
46420 + .rx = z8530_rx_clear,
46421 + .tx = z8530_tx_clear,
46422 + .status = z8530_status_clear
46423 };
46424
46425
46426 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46427 index 0b60295..b8bfa5b 100644
46428 --- a/drivers/net/wimax/i2400m/rx.c
46429 +++ b/drivers/net/wimax/i2400m/rx.c
46430 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46431 if (i2400m->rx_roq == NULL)
46432 goto error_roq_alloc;
46433
46434 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46435 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46436 GFP_KERNEL);
46437 if (rd == NULL) {
46438 result = -ENOMEM;
46439 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46440 index edf4b57..68b51c0 100644
46441 --- a/drivers/net/wireless/airo.c
46442 +++ b/drivers/net/wireless/airo.c
46443 @@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46444 struct airo_info *ai = dev->ml_priv;
46445 int ridcode;
46446 int enabled;
46447 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46448 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46449 unsigned char *iobuf;
46450
46451 /* Only super-user can write RIDs */
46452 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46453 index 99b3bfa..9559372 100644
46454 --- a/drivers/net/wireless/at76c50x-usb.c
46455 +++ b/drivers/net/wireless/at76c50x-usb.c
46456 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46457 }
46458
46459 /* Convert timeout from the DFU status to jiffies */
46460 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
46461 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46462 {
46463 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46464 | (s->poll_timeout[1] << 8)
46465 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46466 index edc57ab..ff49e0a 100644
46467 --- a/drivers/net/wireless/ath/ath10k/htc.c
46468 +++ b/drivers/net/wireless/ath/ath10k/htc.c
46469 @@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46470 /* registered target arrival callback from the HIF layer */
46471 int ath10k_htc_init(struct ath10k *ar)
46472 {
46473 - struct ath10k_hif_cb htc_callbacks;
46474 + static struct ath10k_hif_cb htc_callbacks = {
46475 + .rx_completion = ath10k_htc_rx_completion_handler,
46476 + .tx_completion = ath10k_htc_tx_completion_handler,
46477 + };
46478 struct ath10k_htc_ep *ep = NULL;
46479 struct ath10k_htc *htc = &ar->htc;
46480
46481 @@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
46482 ath10k_htc_reset_endpoint_states(htc);
46483
46484 /* setup HIF layer callbacks */
46485 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46486 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46487 htc->ar = ar;
46488
46489 /* Get HIF default pipe for HTC message exchange */
46490 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46491 index 4716d33..a688310 100644
46492 --- a/drivers/net/wireless/ath/ath10k/htc.h
46493 +++ b/drivers/net/wireless/ath/ath10k/htc.h
46494 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46495
46496 struct ath10k_htc_ops {
46497 void (*target_send_suspend_complete)(struct ath10k *ar);
46498 -};
46499 +} __no_const;
46500
46501 struct ath10k_htc_ep_ops {
46502 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46503 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46504 void (*ep_tx_credits)(struct ath10k *);
46505 -};
46506 +} __no_const;
46507
46508 /* service connection information */
46509 struct ath10k_htc_svc_conn_req {
46510 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46511 index 741b38d..b7ae41b 100644
46512 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46513 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46514 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46515 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46516 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46517
46518 - ACCESS_ONCE(ads->ds_link) = i->link;
46519 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46520 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
46521 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46522
46523 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46524 ctl6 = SM(i->keytype, AR_EncrType);
46525 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46526
46527 if ((i->is_first || i->is_last) &&
46528 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46529 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46530 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46531 | set11nTries(i->rates, 1)
46532 | set11nTries(i->rates, 2)
46533 | set11nTries(i->rates, 3)
46534 | (i->dur_update ? AR_DurUpdateEna : 0)
46535 | SM(0, AR_BurstDur);
46536
46537 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46538 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46539 | set11nRate(i->rates, 1)
46540 | set11nRate(i->rates, 2)
46541 | set11nRate(i->rates, 3);
46542 } else {
46543 - ACCESS_ONCE(ads->ds_ctl2) = 0;
46544 - ACCESS_ONCE(ads->ds_ctl3) = 0;
46545 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46546 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46547 }
46548
46549 if (!i->is_first) {
46550 - ACCESS_ONCE(ads->ds_ctl0) = 0;
46551 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46552 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46553 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46554 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46555 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46556 return;
46557 }
46558
46559 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46560 break;
46561 }
46562
46563 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46564 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46565 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46566 | SM(i->txpower, AR_XmitPower)
46567 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46568 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46569 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46570 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46571
46572 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46573 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46574 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46575 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46576
46577 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46578 return;
46579
46580 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46581 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46582 | set11nPktDurRTSCTS(i->rates, 1);
46583
46584 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46585 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46586 | set11nPktDurRTSCTS(i->rates, 3);
46587
46588 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46589 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46590 | set11nRateFlags(i->rates, 1)
46591 | set11nRateFlags(i->rates, 2)
46592 | set11nRateFlags(i->rates, 3)
46593 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46594 index 729ffbf..49f50e3 100644
46595 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46596 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46597 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46598 (i->qcu << AR_TxQcuNum_S) | desc_len;
46599
46600 checksum += val;
46601 - ACCESS_ONCE(ads->info) = val;
46602 + ACCESS_ONCE_RW(ads->info) = val;
46603
46604 checksum += i->link;
46605 - ACCESS_ONCE(ads->link) = i->link;
46606 + ACCESS_ONCE_RW(ads->link) = i->link;
46607
46608 checksum += i->buf_addr[0];
46609 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46610 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46611 checksum += i->buf_addr[1];
46612 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46613 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46614 checksum += i->buf_addr[2];
46615 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46616 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46617 checksum += i->buf_addr[3];
46618 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46619 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46620
46621 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46622 - ACCESS_ONCE(ads->ctl3) = val;
46623 + ACCESS_ONCE_RW(ads->ctl3) = val;
46624 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46625 - ACCESS_ONCE(ads->ctl5) = val;
46626 + ACCESS_ONCE_RW(ads->ctl5) = val;
46627 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46628 - ACCESS_ONCE(ads->ctl7) = val;
46629 + ACCESS_ONCE_RW(ads->ctl7) = val;
46630 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46631 - ACCESS_ONCE(ads->ctl9) = val;
46632 + ACCESS_ONCE_RW(ads->ctl9) = val;
46633
46634 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46635 - ACCESS_ONCE(ads->ctl10) = checksum;
46636 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
46637
46638 if (i->is_first || i->is_last) {
46639 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46640 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46641 | set11nTries(i->rates, 1)
46642 | set11nTries(i->rates, 2)
46643 | set11nTries(i->rates, 3)
46644 | (i->dur_update ? AR_DurUpdateEna : 0)
46645 | SM(0, AR_BurstDur);
46646
46647 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46648 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46649 | set11nRate(i->rates, 1)
46650 | set11nRate(i->rates, 2)
46651 | set11nRate(i->rates, 3);
46652 } else {
46653 - ACCESS_ONCE(ads->ctl13) = 0;
46654 - ACCESS_ONCE(ads->ctl14) = 0;
46655 + ACCESS_ONCE_RW(ads->ctl13) = 0;
46656 + ACCESS_ONCE_RW(ads->ctl14) = 0;
46657 }
46658
46659 ads->ctl20 = 0;
46660 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46661
46662 ctl17 = SM(i->keytype, AR_EncrType);
46663 if (!i->is_first) {
46664 - ACCESS_ONCE(ads->ctl11) = 0;
46665 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46666 - ACCESS_ONCE(ads->ctl15) = 0;
46667 - ACCESS_ONCE(ads->ctl16) = 0;
46668 - ACCESS_ONCE(ads->ctl17) = ctl17;
46669 - ACCESS_ONCE(ads->ctl18) = 0;
46670 - ACCESS_ONCE(ads->ctl19) = 0;
46671 + ACCESS_ONCE_RW(ads->ctl11) = 0;
46672 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46673 + ACCESS_ONCE_RW(ads->ctl15) = 0;
46674 + ACCESS_ONCE_RW(ads->ctl16) = 0;
46675 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46676 + ACCESS_ONCE_RW(ads->ctl18) = 0;
46677 + ACCESS_ONCE_RW(ads->ctl19) = 0;
46678 return;
46679 }
46680
46681 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46682 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46683 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46684 | SM(i->txpower, AR_XmitPower)
46685 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46686 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46687 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46688 ctl12 |= SM(val, AR_PAPRDChainMask);
46689
46690 - ACCESS_ONCE(ads->ctl12) = ctl12;
46691 - ACCESS_ONCE(ads->ctl17) = ctl17;
46692 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46693 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46694
46695 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46696 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46697 | set11nPktDurRTSCTS(i->rates, 1);
46698
46699 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46700 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46701 | set11nPktDurRTSCTS(i->rates, 3);
46702
46703 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46704 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46705 | set11nRateFlags(i->rates, 1)
46706 | set11nRateFlags(i->rates, 2)
46707 | set11nRateFlags(i->rates, 3)
46708 | SM(i->rtscts_rate, AR_RTSCTSRate);
46709
46710 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46711 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46712 }
46713
46714 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46715 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46716 index 0acd4b5..0591c91 100644
46717 --- a/drivers/net/wireless/ath/ath9k/hw.h
46718 +++ b/drivers/net/wireless/ath/ath9k/hw.h
46719 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
46720
46721 /* ANI */
46722 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46723 -};
46724 +} __no_const;
46725
46726 /**
46727 * struct ath_spec_scan - parameters for Atheros spectral scan
46728 @@ -706,7 +706,7 @@ struct ath_hw_ops {
46729 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46730 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46731 #endif
46732 -};
46733 +} __no_const;
46734
46735 struct ath_nf_limits {
46736 s16 max;
46737 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46738 index 92190da..f3a4c4c 100644
46739 --- a/drivers/net/wireless/b43/phy_lp.c
46740 +++ b/drivers/net/wireless/b43/phy_lp.c
46741 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46742 {
46743 struct ssb_bus *bus = dev->dev->sdev->bus;
46744
46745 - static const struct b206x_channel *chandata = NULL;
46746 + const struct b206x_channel *chandata = NULL;
46747 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46748 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46749 u16 old_comm15, scale;
46750 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46751 index 0487461..fd9e84a 100644
46752 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
46753 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46754 @@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46755 */
46756 if (il3945_mod_params.disable_hw_scan) {
46757 D_INFO("Disabling hw_scan\n");
46758 - il3945_mac_ops.hw_scan = NULL;
46759 + pax_open_kernel();
46760 + *(void **)&il3945_mac_ops.hw_scan = NULL;
46761 + pax_close_kernel();
46762 }
46763
46764 D_INFO("*** LOAD DRIVER ***\n");
46765 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46766 index d2fe259..0c4c682 100644
46767 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46768 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46769 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46770 {
46771 struct iwl_priv *priv = file->private_data;
46772 char buf[64];
46773 - int buf_size;
46774 + size_t buf_size;
46775 u32 offset, len;
46776
46777 memset(buf, 0, sizeof(buf));
46778 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46779 struct iwl_priv *priv = file->private_data;
46780
46781 char buf[8];
46782 - int buf_size;
46783 + size_t buf_size;
46784 u32 reset_flag;
46785
46786 memset(buf, 0, sizeof(buf));
46787 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46788 {
46789 struct iwl_priv *priv = file->private_data;
46790 char buf[8];
46791 - int buf_size;
46792 + size_t buf_size;
46793 int ht40;
46794
46795 memset(buf, 0, sizeof(buf));
46796 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46797 {
46798 struct iwl_priv *priv = file->private_data;
46799 char buf[8];
46800 - int buf_size;
46801 + size_t buf_size;
46802 int value;
46803
46804 memset(buf, 0, sizeof(buf));
46805 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46806 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46807 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46808
46809 -static const char *fmt_value = " %-30s %10u\n";
46810 -static const char *fmt_hex = " %-30s 0x%02X\n";
46811 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46812 -static const char *fmt_header =
46813 +static const char fmt_value[] = " %-30s %10u\n";
46814 +static const char fmt_hex[] = " %-30s 0x%02X\n";
46815 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46816 +static const char fmt_header[] =
46817 "%-32s current cumulative delta max\n";
46818
46819 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46820 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46821 {
46822 struct iwl_priv *priv = file->private_data;
46823 char buf[8];
46824 - int buf_size;
46825 + size_t buf_size;
46826 int clear;
46827
46828 memset(buf, 0, sizeof(buf));
46829 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46830 {
46831 struct iwl_priv *priv = file->private_data;
46832 char buf[8];
46833 - int buf_size;
46834 + size_t buf_size;
46835 int trace;
46836
46837 memset(buf, 0, sizeof(buf));
46838 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46839 {
46840 struct iwl_priv *priv = file->private_data;
46841 char buf[8];
46842 - int buf_size;
46843 + size_t buf_size;
46844 int missed;
46845
46846 memset(buf, 0, sizeof(buf));
46847 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46848
46849 struct iwl_priv *priv = file->private_data;
46850 char buf[8];
46851 - int buf_size;
46852 + size_t buf_size;
46853 int plcp;
46854
46855 memset(buf, 0, sizeof(buf));
46856 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46857
46858 struct iwl_priv *priv = file->private_data;
46859 char buf[8];
46860 - int buf_size;
46861 + size_t buf_size;
46862 int flush;
46863
46864 memset(buf, 0, sizeof(buf));
46865 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46866
46867 struct iwl_priv *priv = file->private_data;
46868 char buf[8];
46869 - int buf_size;
46870 + size_t buf_size;
46871 int rts;
46872
46873 if (!priv->cfg->ht_params)
46874 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46875 {
46876 struct iwl_priv *priv = file->private_data;
46877 char buf[8];
46878 - int buf_size;
46879 + size_t buf_size;
46880
46881 memset(buf, 0, sizeof(buf));
46882 buf_size = min(count, sizeof(buf) - 1);
46883 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46884 struct iwl_priv *priv = file->private_data;
46885 u32 event_log_flag;
46886 char buf[8];
46887 - int buf_size;
46888 + size_t buf_size;
46889
46890 /* check that the interface is up */
46891 if (!iwl_is_ready(priv))
46892 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46893 struct iwl_priv *priv = file->private_data;
46894 char buf[8];
46895 u32 calib_disabled;
46896 - int buf_size;
46897 + size_t buf_size;
46898
46899 memset(buf, 0, sizeof(buf));
46900 buf_size = min(count, sizeof(buf) - 1);
46901 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46902 index ba1b1ea..0ff7e98 100644
46903 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
46904 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46905 @@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46906 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46907 {
46908 struct iwl_nvm_data *data = priv->nvm_data;
46909 - char *debug_msg;
46910 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46911
46912 if (data->sku_cap_11n_enable &&
46913 !priv->cfg->ht_params) {
46914 @@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46915 return -EINVAL;
46916 }
46917
46918 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46919 IWL_DEBUG_INFO(priv, debug_msg,
46920 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
46921 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
46922 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
46923 index f950780..be9df93 100644
46924 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
46925 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
46926 @@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
46927 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
46928
46929 char buf[8];
46930 - int buf_size;
46931 + size_t buf_size;
46932 u32 reset_flag;
46933
46934 memset(buf, 0, sizeof(buf));
46935 @@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
46936 {
46937 struct iwl_trans *trans = file->private_data;
46938 char buf[8];
46939 - int buf_size;
46940 + size_t buf_size;
46941 int csr;
46942
46943 memset(buf, 0, sizeof(buf));
46944 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
46945 index 69d4c31..bd0b316 100644
46946 --- a/drivers/net/wireless/mac80211_hwsim.c
46947 +++ b/drivers/net/wireless/mac80211_hwsim.c
46948 @@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
46949 if (channels < 1)
46950 return -EINVAL;
46951
46952 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
46953 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
46954 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
46955 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
46956 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
46957 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
46958 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
46959 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
46960 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
46961 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
46962 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
46963 - mac80211_hwsim_assign_vif_chanctx;
46964 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
46965 - mac80211_hwsim_unassign_vif_chanctx;
46966 + pax_open_kernel();
46967 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
46968 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
46969 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
46970 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
46971 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
46972 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
46973 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
46974 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
46975 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
46976 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
46977 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
46978 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
46979 + pax_close_kernel();
46980
46981 spin_lock_init(&hwsim_radio_lock);
46982 INIT_LIST_HEAD(&hwsim_radios);
46983 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
46984 index 5028557..91cf394 100644
46985 --- a/drivers/net/wireless/rndis_wlan.c
46986 +++ b/drivers/net/wireless/rndis_wlan.c
46987 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
46988
46989 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
46990
46991 - if (rts_threshold < 0 || rts_threshold > 2347)
46992 + if (rts_threshold > 2347)
46993 rts_threshold = 2347;
46994
46995 tmp = cpu_to_le32(rts_threshold);
46996 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
46997 index e3b885d..7a7de2f 100644
46998 --- a/drivers/net/wireless/rt2x00/rt2x00.h
46999 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47000 @@ -375,7 +375,7 @@ struct rt2x00_intf {
47001 * for hardware which doesn't support hardware
47002 * sequence counting.
47003 */
47004 - atomic_t seqno;
47005 + atomic_unchecked_t seqno;
47006 };
47007
47008 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47009 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47010 index 5642ccc..01f03eb 100644
47011 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47012 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47013 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47014 * sequence counter given by mac80211.
47015 */
47016 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47017 - seqno = atomic_add_return(0x10, &intf->seqno);
47018 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47019 else
47020 - seqno = atomic_read(&intf->seqno);
47021 + seqno = atomic_read_unchecked(&intf->seqno);
47022
47023 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47024 hdr->seq_ctrl |= cpu_to_le16(seqno);
47025 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47026 index e2b3d9c..67a5184 100644
47027 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47028 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47029 @@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47030
47031 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47032
47033 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47034 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47035 + pax_open_kernel();
47036 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47037 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47038 + pax_close_kernel();
47039
47040 wl1251_info("using dedicated interrupt line");
47041 } else {
47042 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47043 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47044 + pax_open_kernel();
47045 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47046 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47047 + pax_close_kernel();
47048
47049 wl1251_info("using SDIO interrupt");
47050 }
47051 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47052 index be7129b..4161356 100644
47053 --- a/drivers/net/wireless/ti/wl12xx/main.c
47054 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47055 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47056 sizeof(wl->conf.mem));
47057
47058 /* read data preparation is only needed by wl127x */
47059 - wl->ops->prepare_read = wl127x_prepare_read;
47060 + pax_open_kernel();
47061 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47062 + pax_close_kernel();
47063
47064 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47065 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47066 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47067 sizeof(wl->conf.mem));
47068
47069 /* read data preparation is only needed by wl127x */
47070 - wl->ops->prepare_read = wl127x_prepare_read;
47071 + pax_open_kernel();
47072 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47073 + pax_close_kernel();
47074
47075 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47076 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47077 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47078 index ec37b16..7e34d66 100644
47079 --- a/drivers/net/wireless/ti/wl18xx/main.c
47080 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47081 @@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47082 }
47083
47084 if (!checksum_param) {
47085 - wl18xx_ops.set_rx_csum = NULL;
47086 - wl18xx_ops.init_vif = NULL;
47087 + pax_open_kernel();
47088 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47089 + *(void **)&wl18xx_ops.init_vif = NULL;
47090 + pax_close_kernel();
47091 }
47092
47093 /* Enable 11a Band only if we have 5G antennas */
47094 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47095 index a912dc0..a8225ba 100644
47096 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47097 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47098 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47099 {
47100 struct zd_usb *usb = urb->context;
47101 struct zd_usb_interrupt *intr = &usb->intr;
47102 - int len;
47103 + unsigned int len;
47104 u16 int_num;
47105
47106 ZD_ASSERT(in_interrupt());
47107 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47108 index 683671a..4519fc2 100644
47109 --- a/drivers/nfc/nfcwilink.c
47110 +++ b/drivers/nfc/nfcwilink.c
47111 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47112
47113 static int nfcwilink_probe(struct platform_device *pdev)
47114 {
47115 - static struct nfcwilink *drv;
47116 + struct nfcwilink *drv;
47117 int rc;
47118 __u32 protocols;
47119
47120 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47121 index d93b2b6..ae50401 100644
47122 --- a/drivers/oprofile/buffer_sync.c
47123 +++ b/drivers/oprofile/buffer_sync.c
47124 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47125 if (cookie == NO_COOKIE)
47126 offset = pc;
47127 if (cookie == INVALID_COOKIE) {
47128 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47129 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47130 offset = pc;
47131 }
47132 if (cookie != last_cookie) {
47133 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47134 /* add userspace sample */
47135
47136 if (!mm) {
47137 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47138 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47139 return 0;
47140 }
47141
47142 cookie = lookup_dcookie(mm, s->eip, &offset);
47143
47144 if (cookie == INVALID_COOKIE) {
47145 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47146 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47147 return 0;
47148 }
47149
47150 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47151 /* ignore backtraces if failed to add a sample */
47152 if (state == sb_bt_start) {
47153 state = sb_bt_ignore;
47154 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47155 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47156 }
47157 }
47158 release_mm(mm);
47159 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47160 index c0cc4e7..44d4e54 100644
47161 --- a/drivers/oprofile/event_buffer.c
47162 +++ b/drivers/oprofile/event_buffer.c
47163 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47164 }
47165
47166 if (buffer_pos == buffer_size) {
47167 - atomic_inc(&oprofile_stats.event_lost_overflow);
47168 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47169 return;
47170 }
47171
47172 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47173 index ed2c3ec..deda85a 100644
47174 --- a/drivers/oprofile/oprof.c
47175 +++ b/drivers/oprofile/oprof.c
47176 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47177 if (oprofile_ops.switch_events())
47178 return;
47179
47180 - atomic_inc(&oprofile_stats.multiplex_counter);
47181 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47182 start_switch_worker();
47183 }
47184
47185 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47186 index ee2cfce..7f8f699 100644
47187 --- a/drivers/oprofile/oprofile_files.c
47188 +++ b/drivers/oprofile/oprofile_files.c
47189 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47190
47191 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47192
47193 -static ssize_t timeout_read(struct file *file, char __user *buf,
47194 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47195 size_t count, loff_t *offset)
47196 {
47197 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47198 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47199 index 59659ce..6c860a0 100644
47200 --- a/drivers/oprofile/oprofile_stats.c
47201 +++ b/drivers/oprofile/oprofile_stats.c
47202 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47203 cpu_buf->sample_invalid_eip = 0;
47204 }
47205
47206 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47207 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47208 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47209 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47210 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47211 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47212 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47213 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47214 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47215 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47216 }
47217
47218
47219 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47220 index 1fc622b..8c48fc3 100644
47221 --- a/drivers/oprofile/oprofile_stats.h
47222 +++ b/drivers/oprofile/oprofile_stats.h
47223 @@ -13,11 +13,11 @@
47224 #include <linux/atomic.h>
47225
47226 struct oprofile_stat_struct {
47227 - atomic_t sample_lost_no_mm;
47228 - atomic_t sample_lost_no_mapping;
47229 - atomic_t bt_lost_no_mapping;
47230 - atomic_t event_lost_overflow;
47231 - atomic_t multiplex_counter;
47232 + atomic_unchecked_t sample_lost_no_mm;
47233 + atomic_unchecked_t sample_lost_no_mapping;
47234 + atomic_unchecked_t bt_lost_no_mapping;
47235 + atomic_unchecked_t event_lost_overflow;
47236 + atomic_unchecked_t multiplex_counter;
47237 };
47238
47239 extern struct oprofile_stat_struct oprofile_stats;
47240 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47241 index 3f49345..c750d0b 100644
47242 --- a/drivers/oprofile/oprofilefs.c
47243 +++ b/drivers/oprofile/oprofilefs.c
47244 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47245
47246 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47247 {
47248 - atomic_t *val = file->private_data;
47249 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47250 + atomic_unchecked_t *val = file->private_data;
47251 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47252 }
47253
47254
47255 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47256
47257
47258 int oprofilefs_create_ro_atomic(struct dentry *root,
47259 - char const *name, atomic_t *val)
47260 + char const *name, atomic_unchecked_t *val)
47261 {
47262 return __oprofilefs_create_file(root, name,
47263 &atomic_ro_fops, 0444, val);
47264 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47265 index 61be1d9..dec05d7 100644
47266 --- a/drivers/oprofile/timer_int.c
47267 +++ b/drivers/oprofile/timer_int.c
47268 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47269 return NOTIFY_OK;
47270 }
47271
47272 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47273 +static struct notifier_block oprofile_cpu_notifier = {
47274 .notifier_call = oprofile_cpu_notify,
47275 };
47276
47277 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47278 index 92ed045..62d39bd7 100644
47279 --- a/drivers/parport/procfs.c
47280 +++ b/drivers/parport/procfs.c
47281 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47282
47283 *ppos += len;
47284
47285 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47286 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47287 }
47288
47289 #ifdef CONFIG_PARPORT_1284
47290 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47291
47292 *ppos += len;
47293
47294 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47295 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47296 }
47297 #endif /* IEEE1284.3 support. */
47298
47299 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47300 index 8dcccff..35d701d 100644
47301 --- a/drivers/pci/hotplug/acpiphp_ibm.c
47302 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
47303 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47304 goto init_cleanup;
47305 }
47306
47307 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47308 + pax_open_kernel();
47309 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47310 + pax_close_kernel();
47311 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47312
47313 return retval;
47314 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47315 index 7536eef..52dc8fa 100644
47316 --- a/drivers/pci/hotplug/cpcihp_generic.c
47317 +++ b/drivers/pci/hotplug/cpcihp_generic.c
47318 @@ -73,7 +73,6 @@ static u16 port;
47319 static unsigned int enum_bit;
47320 static u8 enum_mask;
47321
47322 -static struct cpci_hp_controller_ops generic_hpc_ops;
47323 static struct cpci_hp_controller generic_hpc;
47324
47325 static int __init validate_parameters(void)
47326 @@ -139,6 +138,10 @@ static int query_enum(void)
47327 return ((value & enum_mask) == enum_mask);
47328 }
47329
47330 +static struct cpci_hp_controller_ops generic_hpc_ops = {
47331 + .query_enum = query_enum,
47332 +};
47333 +
47334 static int __init cpcihp_generic_init(void)
47335 {
47336 int status;
47337 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47338 pci_dev_put(dev);
47339
47340 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47341 - generic_hpc_ops.query_enum = query_enum;
47342 generic_hpc.ops = &generic_hpc_ops;
47343
47344 status = cpci_hp_register_controller(&generic_hpc);
47345 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47346 index e8c4a7c..7046f5c 100644
47347 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
47348 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47349 @@ -59,7 +59,6 @@
47350 /* local variables */
47351 static bool debug;
47352 static bool poll;
47353 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
47354 static struct cpci_hp_controller zt5550_hpc;
47355
47356 /* Primary cPCI bus bridge device */
47357 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47358 return 0;
47359 }
47360
47361 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47362 + .query_enum = zt5550_hc_query_enum,
47363 +};
47364 +
47365 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47366 {
47367 int status;
47368 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47369 dbg("returned from zt5550_hc_config");
47370
47371 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47372 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47373 zt5550_hpc.ops = &zt5550_hpc_ops;
47374 if(!poll) {
47375 zt5550_hpc.irq = hc_dev->irq;
47376 zt5550_hpc.irq_flags = IRQF_SHARED;
47377 zt5550_hpc.dev_id = hc_dev;
47378
47379 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47380 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47381 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47382 + pax_open_kernel();
47383 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47384 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47385 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47386 + pax_open_kernel();
47387 } else {
47388 info("using ENUM# polling mode");
47389 }
47390 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47391 index 76ba8a1..20ca857 100644
47392 --- a/drivers/pci/hotplug/cpqphp_nvram.c
47393 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
47394 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47395
47396 void compaq_nvram_init (void __iomem *rom_start)
47397 {
47398 +
47399 +#ifndef CONFIG_PAX_KERNEXEC
47400 if (rom_start) {
47401 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47402 }
47403 +#endif
47404 +
47405 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47406
47407 /* initialize our int15 lock */
47408 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47409 index cfa92a9..29539c5 100644
47410 --- a/drivers/pci/hotplug/pci_hotplug_core.c
47411 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
47412 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47413 return -EINVAL;
47414 }
47415
47416 - slot->ops->owner = owner;
47417 - slot->ops->mod_name = mod_name;
47418 + pax_open_kernel();
47419 + *(struct module **)&slot->ops->owner = owner;
47420 + *(const char **)&slot->ops->mod_name = mod_name;
47421 + pax_close_kernel();
47422
47423 mutex_lock(&pci_hp_mutex);
47424 /*
47425 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47426 index 53b58de..4479896 100644
47427 --- a/drivers/pci/hotplug/pciehp_core.c
47428 +++ b/drivers/pci/hotplug/pciehp_core.c
47429 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47430 struct slot *slot = ctrl->slot;
47431 struct hotplug_slot *hotplug = NULL;
47432 struct hotplug_slot_info *info = NULL;
47433 - struct hotplug_slot_ops *ops = NULL;
47434 + hotplug_slot_ops_no_const *ops = NULL;
47435 char name[SLOT_NAME_SIZE];
47436 int retval = -ENOMEM;
47437
47438 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47439 index 955ab79..d1df9c7 100644
47440 --- a/drivers/pci/msi.c
47441 +++ b/drivers/pci/msi.c
47442 @@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47443 {
47444 struct attribute **msi_attrs;
47445 struct attribute *msi_attr;
47446 - struct device_attribute *msi_dev_attr;
47447 - struct attribute_group *msi_irq_group;
47448 + device_attribute_no_const *msi_dev_attr;
47449 + attribute_group_no_const *msi_irq_group;
47450 const struct attribute_group **msi_irq_groups;
47451 struct msi_desc *entry;
47452 int ret = -ENOMEM;
47453 @@ -589,7 +589,7 @@ error_attrs:
47454 count = 0;
47455 msi_attr = msi_attrs[count];
47456 while (msi_attr) {
47457 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47458 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47459 kfree(msi_attr->name);
47460 kfree(msi_dev_attr);
47461 ++count;
47462 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47463 index 276ef9c..1d33a36 100644
47464 --- a/drivers/pci/pci-sysfs.c
47465 +++ b/drivers/pci/pci-sysfs.c
47466 @@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47467 {
47468 /* allocate attribute structure, piggyback attribute name */
47469 int name_len = write_combine ? 13 : 10;
47470 - struct bin_attribute *res_attr;
47471 + bin_attribute_no_const *res_attr;
47472 int retval;
47473
47474 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47475 @@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47476 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47477 {
47478 int retval;
47479 - struct bin_attribute *attr;
47480 + bin_attribute_no_const *attr;
47481
47482 /* If the device has VPD, try to expose it in sysfs. */
47483 if (dev->vpd) {
47484 @@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47485 {
47486 int retval;
47487 int rom_size = 0;
47488 - struct bin_attribute *attr;
47489 + bin_attribute_no_const *attr;
47490
47491 if (!sysfs_initialized)
47492 return -EACCES;
47493 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47494 index 4df38df..b6bb7fe 100644
47495 --- a/drivers/pci/pci.h
47496 +++ b/drivers/pci/pci.h
47497 @@ -93,7 +93,7 @@ struct pci_vpd_ops {
47498 struct pci_vpd {
47499 unsigned int len;
47500 const struct pci_vpd_ops *ops;
47501 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47502 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47503 };
47504
47505 int pci_vpd_pci22_init(struct pci_dev *dev);
47506 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47507 index e1e7026..d28dd33 100644
47508 --- a/drivers/pci/pcie/aspm.c
47509 +++ b/drivers/pci/pcie/aspm.c
47510 @@ -27,9 +27,9 @@
47511 #define MODULE_PARAM_PREFIX "pcie_aspm."
47512
47513 /* Note: those are not register definitions */
47514 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47515 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47516 -#define ASPM_STATE_L1 (4) /* L1 state */
47517 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47518 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47519 +#define ASPM_STATE_L1 (4U) /* L1 state */
47520 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47521 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47522
47523 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47524 index 6e34498..9911975 100644
47525 --- a/drivers/pci/probe.c
47526 +++ b/drivers/pci/probe.c
47527 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47528 struct pci_bus_region region, inverted_region;
47529 bool bar_too_big = false, bar_disabled = false;
47530
47531 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47532 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47533
47534 /* No printks while decoding is disabled! */
47535 if (!dev->mmio_always_on) {
47536 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47537 index 46d1378..30e452b 100644
47538 --- a/drivers/pci/proc.c
47539 +++ b/drivers/pci/proc.c
47540 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47541 static int __init pci_proc_init(void)
47542 {
47543 struct pci_dev *dev = NULL;
47544 +
47545 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47546 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47547 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47548 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47549 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47550 +#endif
47551 +#else
47552 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47553 +#endif
47554 proc_create("devices", 0, proc_bus_pci_dir,
47555 &proc_bus_pci_dev_operations);
47556 proc_initialized = 1;
47557 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47558 index 7f3aad0..7d604bb 100644
47559 --- a/drivers/platform/chrome/chromeos_laptop.c
47560 +++ b/drivers/platform/chrome/chromeos_laptop.c
47561 @@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
47562 .callback = chromeos_laptop_dmi_matched, \
47563 .driver_data = (void *)&board_
47564
47565 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
47566 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
47567 {
47568 .ident = "Samsung Series 5 550",
47569 .matches = {
47570 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47571 index c5e082f..d6307a0 100644
47572 --- a/drivers/platform/x86/asus-wmi.c
47573 +++ b/drivers/platform/x86/asus-wmi.c
47574 @@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
47575 int err;
47576 u32 retval = -1;
47577
47578 +#ifdef CONFIG_GRKERNSEC_KMEM
47579 + return -EPERM;
47580 +#endif
47581 +
47582 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47583
47584 if (err < 0)
47585 @@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
47586 int err;
47587 u32 retval = -1;
47588
47589 +#ifdef CONFIG_GRKERNSEC_KMEM
47590 + return -EPERM;
47591 +#endif
47592 +
47593 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47594 &retval);
47595
47596 @@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
47597 union acpi_object *obj;
47598 acpi_status status;
47599
47600 +#ifdef CONFIG_GRKERNSEC_KMEM
47601 + return -EPERM;
47602 +#endif
47603 +
47604 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47605 1, asus->debug.method_id,
47606 &input, &output);
47607 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47608 index 62f8030..c7f2a45 100644
47609 --- a/drivers/platform/x86/msi-laptop.c
47610 +++ b/drivers/platform/x86/msi-laptop.c
47611 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47612
47613 if (!quirks->ec_read_only) {
47614 /* allow userland write sysfs file */
47615 - dev_attr_bluetooth.store = store_bluetooth;
47616 - dev_attr_wlan.store = store_wlan;
47617 - dev_attr_threeg.store = store_threeg;
47618 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
47619 - dev_attr_wlan.attr.mode |= S_IWUSR;
47620 - dev_attr_threeg.attr.mode |= S_IWUSR;
47621 + pax_open_kernel();
47622 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47623 + *(void **)&dev_attr_wlan.store = store_wlan;
47624 + *(void **)&dev_attr_threeg.store = store_threeg;
47625 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47626 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47627 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47628 + pax_close_kernel();
47629 }
47630
47631 /* disable hardware control by fn key */
47632 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47633 index 70222f2..8c8ce66 100644
47634 --- a/drivers/platform/x86/msi-wmi.c
47635 +++ b/drivers/platform/x86/msi-wmi.c
47636 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47637 static void msi_wmi_notify(u32 value, void *context)
47638 {
47639 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47640 - static struct key_entry *key;
47641 + struct key_entry *key;
47642 union acpi_object *obj;
47643 acpi_status status;
47644
47645 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47646 index 8f8551a..3ace3ca 100644
47647 --- a/drivers/platform/x86/sony-laptop.c
47648 +++ b/drivers/platform/x86/sony-laptop.c
47649 @@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47650 }
47651
47652 /* High speed charging function */
47653 -static struct device_attribute *hsc_handle;
47654 +static device_attribute_no_const *hsc_handle;
47655
47656 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47657 struct device_attribute *attr,
47658 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47659 index defb6af..7a5d3d1 100644
47660 --- a/drivers/platform/x86/thinkpad_acpi.c
47661 +++ b/drivers/platform/x86/thinkpad_acpi.c
47662 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
47663 return 0;
47664 }
47665
47666 -void static hotkey_mask_warn_incomplete_mask(void)
47667 +static void hotkey_mask_warn_incomplete_mask(void)
47668 {
47669 /* log only what the user can fix... */
47670 const u32 wantedmask = hotkey_driver_mask &
47671 @@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47672 }
47673 }
47674
47675 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47676 - struct tp_nvram_state *newn,
47677 - const u32 event_mask)
47678 -{
47679 -
47680 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47681 do { \
47682 if ((event_mask & (1 << __scancode)) && \
47683 @@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47684 tpacpi_hotkey_send_key(__scancode); \
47685 } while (0)
47686
47687 - void issue_volchange(const unsigned int oldvol,
47688 - const unsigned int newvol)
47689 - {
47690 - unsigned int i = oldvol;
47691 +static void issue_volchange(const unsigned int oldvol,
47692 + const unsigned int newvol,
47693 + const u32 event_mask)
47694 +{
47695 + unsigned int i = oldvol;
47696
47697 - while (i > newvol) {
47698 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47699 - i--;
47700 - }
47701 - while (i < newvol) {
47702 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47703 - i++;
47704 - }
47705 + while (i > newvol) {
47706 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47707 + i--;
47708 }
47709 + while (i < newvol) {
47710 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47711 + i++;
47712 + }
47713 +}
47714
47715 - void issue_brightnesschange(const unsigned int oldbrt,
47716 - const unsigned int newbrt)
47717 - {
47718 - unsigned int i = oldbrt;
47719 +static void issue_brightnesschange(const unsigned int oldbrt,
47720 + const unsigned int newbrt,
47721 + const u32 event_mask)
47722 +{
47723 + unsigned int i = oldbrt;
47724
47725 - while (i > newbrt) {
47726 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47727 - i--;
47728 - }
47729 - while (i < newbrt) {
47730 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47731 - i++;
47732 - }
47733 + while (i > newbrt) {
47734 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47735 + i--;
47736 + }
47737 + while (i < newbrt) {
47738 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47739 + i++;
47740 }
47741 +}
47742
47743 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47744 + struct tp_nvram_state *newn,
47745 + const u32 event_mask)
47746 +{
47747 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47748 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47749 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47750 @@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47751 oldn->volume_level != newn->volume_level) {
47752 /* recently muted, or repeated mute keypress, or
47753 * multiple presses ending in mute */
47754 - issue_volchange(oldn->volume_level, newn->volume_level);
47755 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47756 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47757 }
47758 } else {
47759 @@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47760 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47761 }
47762 if (oldn->volume_level != newn->volume_level) {
47763 - issue_volchange(oldn->volume_level, newn->volume_level);
47764 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47765 } else if (oldn->volume_toggle != newn->volume_toggle) {
47766 /* repeated vol up/down keypress at end of scale ? */
47767 if (newn->volume_level == 0)
47768 @@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47769 /* handle brightness */
47770 if (oldn->brightness_level != newn->brightness_level) {
47771 issue_brightnesschange(oldn->brightness_level,
47772 - newn->brightness_level);
47773 + newn->brightness_level,
47774 + event_mask);
47775 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47776 /* repeated key presses that didn't change state */
47777 if (newn->brightness_level == 0)
47778 @@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47779 && !tp_features.bright_unkfw)
47780 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47781 }
47782 +}
47783
47784 #undef TPACPI_COMPARE_KEY
47785 #undef TPACPI_MAY_SEND_KEY
47786 -}
47787
47788 /*
47789 * Polling driver
47790 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47791 index 769d265..a3a05ca 100644
47792 --- a/drivers/pnp/pnpbios/bioscalls.c
47793 +++ b/drivers/pnp/pnpbios/bioscalls.c
47794 @@ -58,7 +58,7 @@ do { \
47795 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47796 } while(0)
47797
47798 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47799 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47800 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47801
47802 /*
47803 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47804
47805 cpu = get_cpu();
47806 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47807 +
47808 + pax_open_kernel();
47809 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47810 + pax_close_kernel();
47811
47812 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47813 spin_lock_irqsave(&pnp_bios_lock, flags);
47814 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47815 :"memory");
47816 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47817
47818 + pax_open_kernel();
47819 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47820 + pax_close_kernel();
47821 +
47822 put_cpu();
47823
47824 /* If we get here and this is set then the PnP BIOS faulted on us. */
47825 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47826 return status;
47827 }
47828
47829 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
47830 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47831 {
47832 int i;
47833
47834 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47835 pnp_bios_callpoint.offset = header->fields.pm16offset;
47836 pnp_bios_callpoint.segment = PNP_CS16;
47837
47838 + pax_open_kernel();
47839 +
47840 for_each_possible_cpu(i) {
47841 struct desc_struct *gdt = get_cpu_gdt_table(i);
47842 if (!gdt)
47843 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47844 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47845 (unsigned long)__va(header->fields.pm16dseg));
47846 }
47847 +
47848 + pax_close_kernel();
47849 }
47850 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47851 index bacddd1..65ea100 100644
47852 --- a/drivers/pnp/resource.c
47853 +++ b/drivers/pnp/resource.c
47854 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47855 return 1;
47856
47857 /* check if the resource is valid */
47858 - if (*irq < 0 || *irq > 15)
47859 + if (*irq > 15)
47860 return 0;
47861
47862 /* check if the resource is reserved */
47863 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47864 return 1;
47865
47866 /* check if the resource is valid */
47867 - if (*dma < 0 || *dma == 4 || *dma > 7)
47868 + if (*dma == 4 || *dma > 7)
47869 return 0;
47870
47871 /* check if the resource is reserved */
47872 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47873 index 0c52e2a..3421ab7 100644
47874 --- a/drivers/power/pda_power.c
47875 +++ b/drivers/power/pda_power.c
47876 @@ -37,7 +37,11 @@ static int polling;
47877
47878 #if IS_ENABLED(CONFIG_USB_PHY)
47879 static struct usb_phy *transceiver;
47880 -static struct notifier_block otg_nb;
47881 +static int otg_handle_notification(struct notifier_block *nb,
47882 + unsigned long event, void *unused);
47883 +static struct notifier_block otg_nb = {
47884 + .notifier_call = otg_handle_notification
47885 +};
47886 #endif
47887
47888 static struct regulator *ac_draw;
47889 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47890
47891 #if IS_ENABLED(CONFIG_USB_PHY)
47892 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47893 - otg_nb.notifier_call = otg_handle_notification;
47894 ret = usb_register_notifier(transceiver, &otg_nb);
47895 if (ret) {
47896 dev_err(dev, "failure to register otg notifier\n");
47897 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47898 index cc439fd..8fa30df 100644
47899 --- a/drivers/power/power_supply.h
47900 +++ b/drivers/power/power_supply.h
47901 @@ -16,12 +16,12 @@ struct power_supply;
47902
47903 #ifdef CONFIG_SYSFS
47904
47905 -extern void power_supply_init_attrs(struct device_type *dev_type);
47906 +extern void power_supply_init_attrs(void);
47907 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47908
47909 #else
47910
47911 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47912 +static inline void power_supply_init_attrs(void) {}
47913 #define power_supply_uevent NULL
47914
47915 #endif /* CONFIG_SYSFS */
47916 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47917 index 2660664..75fcb04 100644
47918 --- a/drivers/power/power_supply_core.c
47919 +++ b/drivers/power/power_supply_core.c
47920 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
47921 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
47922 EXPORT_SYMBOL_GPL(power_supply_notifier);
47923
47924 -static struct device_type power_supply_dev_type;
47925 +extern const struct attribute_group *power_supply_attr_groups[];
47926 +static struct device_type power_supply_dev_type = {
47927 + .groups = power_supply_attr_groups,
47928 +};
47929
47930 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47931 struct power_supply *supply)
47932 @@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
47933 return PTR_ERR(power_supply_class);
47934
47935 power_supply_class->dev_uevent = power_supply_uevent;
47936 - power_supply_init_attrs(&power_supply_dev_type);
47937 + power_supply_init_attrs();
47938
47939 return 0;
47940 }
47941 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
47942 index 44420d1..967126e 100644
47943 --- a/drivers/power/power_supply_sysfs.c
47944 +++ b/drivers/power/power_supply_sysfs.c
47945 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
47946 .is_visible = power_supply_attr_is_visible,
47947 };
47948
47949 -static const struct attribute_group *power_supply_attr_groups[] = {
47950 +const struct attribute_group *power_supply_attr_groups[] = {
47951 &power_supply_attr_group,
47952 NULL,
47953 };
47954
47955 -void power_supply_init_attrs(struct device_type *dev_type)
47956 +void power_supply_init_attrs(void)
47957 {
47958 int i;
47959
47960 - dev_type->groups = power_supply_attr_groups;
47961 -
47962 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
47963 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
47964 }
47965 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
47966 index 84419af..268ede8 100644
47967 --- a/drivers/powercap/powercap_sys.c
47968 +++ b/drivers/powercap/powercap_sys.c
47969 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
47970 struct device_attribute name_attr;
47971 };
47972
47973 +static ssize_t show_constraint_name(struct device *dev,
47974 + struct device_attribute *dev_attr,
47975 + char *buf);
47976 +
47977 static struct powercap_constraint_attr
47978 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
47979 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
47980 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
47981 + .power_limit_attr = {
47982 + .attr = {
47983 + .name = NULL,
47984 + .mode = S_IWUSR | S_IRUGO
47985 + },
47986 + .show = show_constraint_power_limit_uw,
47987 + .store = store_constraint_power_limit_uw
47988 + },
47989 +
47990 + .time_window_attr = {
47991 + .attr = {
47992 + .name = NULL,
47993 + .mode = S_IWUSR | S_IRUGO
47994 + },
47995 + .show = show_constraint_time_window_us,
47996 + .store = store_constraint_time_window_us
47997 + },
47998 +
47999 + .max_power_attr = {
48000 + .attr = {
48001 + .name = NULL,
48002 + .mode = S_IRUGO
48003 + },
48004 + .show = show_constraint_max_power_uw,
48005 + .store = NULL
48006 + },
48007 +
48008 + .min_power_attr = {
48009 + .attr = {
48010 + .name = NULL,
48011 + .mode = S_IRUGO
48012 + },
48013 + .show = show_constraint_min_power_uw,
48014 + .store = NULL
48015 + },
48016 +
48017 + .max_time_window_attr = {
48018 + .attr = {
48019 + .name = NULL,
48020 + .mode = S_IRUGO
48021 + },
48022 + .show = show_constraint_max_time_window_us,
48023 + .store = NULL
48024 + },
48025 +
48026 + .min_time_window_attr = {
48027 + .attr = {
48028 + .name = NULL,
48029 + .mode = S_IRUGO
48030 + },
48031 + .show = show_constraint_min_time_window_us,
48032 + .store = NULL
48033 + },
48034 +
48035 + .name_attr = {
48036 + .attr = {
48037 + .name = NULL,
48038 + .mode = S_IRUGO
48039 + },
48040 + .show = show_constraint_name,
48041 + .store = NULL
48042 + }
48043 + }
48044 +};
48045
48046 /* A list of powercap control_types */
48047 static LIST_HEAD(powercap_cntrl_list);
48048 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48049 }
48050
48051 static int create_constraint_attribute(int id, const char *name,
48052 - int mode,
48053 - struct device_attribute *dev_attr,
48054 - ssize_t (*show)(struct device *,
48055 - struct device_attribute *, char *),
48056 - ssize_t (*store)(struct device *,
48057 - struct device_attribute *,
48058 - const char *, size_t)
48059 - )
48060 + struct device_attribute *dev_attr)
48061 {
48062 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48063
48064 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48065 - id, name);
48066 - if (!dev_attr->attr.name)
48067 + if (!name)
48068 return -ENOMEM;
48069 - dev_attr->attr.mode = mode;
48070 - dev_attr->show = show;
48071 - dev_attr->store = store;
48072 +
48073 + pax_open_kernel();
48074 + *(const char **)&dev_attr->attr.name = name;
48075 + pax_close_kernel();
48076
48077 return 0;
48078 }
48079 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48080
48081 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48082 ret = create_constraint_attribute(i, "power_limit_uw",
48083 - S_IWUSR | S_IRUGO,
48084 - &constraint_attrs[i].power_limit_attr,
48085 - show_constraint_power_limit_uw,
48086 - store_constraint_power_limit_uw);
48087 + &constraint_attrs[i].power_limit_attr);
48088 if (ret)
48089 goto err_alloc;
48090 ret = create_constraint_attribute(i, "time_window_us",
48091 - S_IWUSR | S_IRUGO,
48092 - &constraint_attrs[i].time_window_attr,
48093 - show_constraint_time_window_us,
48094 - store_constraint_time_window_us);
48095 + &constraint_attrs[i].time_window_attr);
48096 if (ret)
48097 goto err_alloc;
48098 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48099 - &constraint_attrs[i].name_attr,
48100 - show_constraint_name,
48101 - NULL);
48102 + ret = create_constraint_attribute(i, "name",
48103 + &constraint_attrs[i].name_attr);
48104 if (ret)
48105 goto err_alloc;
48106 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48107 - &constraint_attrs[i].max_power_attr,
48108 - show_constraint_max_power_uw,
48109 - NULL);
48110 + ret = create_constraint_attribute(i, "max_power_uw",
48111 + &constraint_attrs[i].max_power_attr);
48112 if (ret)
48113 goto err_alloc;
48114 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48115 - &constraint_attrs[i].min_power_attr,
48116 - show_constraint_min_power_uw,
48117 - NULL);
48118 + ret = create_constraint_attribute(i, "min_power_uw",
48119 + &constraint_attrs[i].min_power_attr);
48120 if (ret)
48121 goto err_alloc;
48122 ret = create_constraint_attribute(i, "max_time_window_us",
48123 - S_IRUGO,
48124 - &constraint_attrs[i].max_time_window_attr,
48125 - show_constraint_max_time_window_us,
48126 - NULL);
48127 + &constraint_attrs[i].max_time_window_attr);
48128 if (ret)
48129 goto err_alloc;
48130 ret = create_constraint_attribute(i, "min_time_window_us",
48131 - S_IRUGO,
48132 - &constraint_attrs[i].min_time_window_attr,
48133 - show_constraint_min_time_window_us,
48134 - NULL);
48135 + &constraint_attrs[i].min_time_window_attr);
48136 if (ret)
48137 goto err_alloc;
48138
48139 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48140 power_zone->zone_dev_attrs[count++] =
48141 &dev_attr_max_energy_range_uj.attr;
48142 if (power_zone->ops->get_energy_uj) {
48143 + pax_open_kernel();
48144 if (power_zone->ops->reset_energy_uj)
48145 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48146 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48147 else
48148 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48149 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48150 + pax_close_kernel();
48151 power_zone->zone_dev_attrs[count++] =
48152 &dev_attr_energy_uj.attr;
48153 }
48154 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48155 index afca1bc..86840b8 100644
48156 --- a/drivers/regulator/core.c
48157 +++ b/drivers/regulator/core.c
48158 @@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48159 {
48160 const struct regulation_constraints *constraints = NULL;
48161 const struct regulator_init_data *init_data;
48162 - static atomic_t regulator_no = ATOMIC_INIT(0);
48163 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48164 struct regulator_dev *rdev;
48165 struct device *dev;
48166 int ret, i;
48167 @@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48168 rdev->dev.of_node = config->of_node;
48169 rdev->dev.parent = dev;
48170 dev_set_name(&rdev->dev, "regulator.%d",
48171 - atomic_inc_return(&regulator_no) - 1);
48172 + atomic_inc_return_unchecked(&regulator_no) - 1);
48173 ret = device_register(&rdev->dev);
48174 if (ret != 0) {
48175 put_device(&rdev->dev);
48176 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48177 index 8d94d3d..653b623 100644
48178 --- a/drivers/regulator/max8660.c
48179 +++ b/drivers/regulator/max8660.c
48180 @@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48181 max8660->shadow_regs[MAX8660_OVER1] = 5;
48182 } else {
48183 /* Otherwise devices can be toggled via software */
48184 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48185 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48186 + pax_open_kernel();
48187 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48188 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48189 + pax_close_kernel();
48190 }
48191
48192 /*
48193 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48194 index 892aa1e..ebd1b9c 100644
48195 --- a/drivers/regulator/max8973-regulator.c
48196 +++ b/drivers/regulator/max8973-regulator.c
48197 @@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48198 if (!pdata || !pdata->enable_ext_control) {
48199 max->desc.enable_reg = MAX8973_VOUT;
48200 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48201 - max->ops.enable = regulator_enable_regmap;
48202 - max->ops.disable = regulator_disable_regmap;
48203 - max->ops.is_enabled = regulator_is_enabled_regmap;
48204 + pax_open_kernel();
48205 + *(void **)&max->ops.enable = regulator_enable_regmap;
48206 + *(void **)&max->ops.disable = regulator_disable_regmap;
48207 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48208 + pax_close_kernel();
48209 }
48210
48211 if (pdata) {
48212 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48213 index f374fa5..26f0683 100644
48214 --- a/drivers/regulator/mc13892-regulator.c
48215 +++ b/drivers/regulator/mc13892-regulator.c
48216 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48217 }
48218 mc13xxx_unlock(mc13892);
48219
48220 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48221 + pax_open_kernel();
48222 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48223 = mc13892_vcam_set_mode;
48224 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48225 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48226 = mc13892_vcam_get_mode;
48227 + pax_close_kernel();
48228
48229 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48230 ARRAY_SIZE(mc13892_regulators));
48231 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48232 index cae212f..58a3980 100644
48233 --- a/drivers/rtc/rtc-cmos.c
48234 +++ b/drivers/rtc/rtc-cmos.c
48235 @@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48236 hpet_rtc_timer_init();
48237
48238 /* export at least the first block of NVRAM */
48239 - nvram.size = address_space - NVRAM_OFFSET;
48240 + pax_open_kernel();
48241 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48242 + pax_close_kernel();
48243 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48244 if (retval < 0) {
48245 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48246 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48247 index d049393..bb20be0 100644
48248 --- a/drivers/rtc/rtc-dev.c
48249 +++ b/drivers/rtc/rtc-dev.c
48250 @@ -16,6 +16,7 @@
48251 #include <linux/module.h>
48252 #include <linux/rtc.h>
48253 #include <linux/sched.h>
48254 +#include <linux/grsecurity.h>
48255 #include "rtc-core.h"
48256
48257 static dev_t rtc_devt;
48258 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48259 if (copy_from_user(&tm, uarg, sizeof(tm)))
48260 return -EFAULT;
48261
48262 + gr_log_timechange();
48263 +
48264 return rtc_set_time(rtc, &tm);
48265
48266 case RTC_PIE_ON:
48267 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48268 index 4e75345..09f8663 100644
48269 --- a/drivers/rtc/rtc-ds1307.c
48270 +++ b/drivers/rtc/rtc-ds1307.c
48271 @@ -107,7 +107,7 @@ struct ds1307 {
48272 u8 offset; /* register's offset */
48273 u8 regs[11];
48274 u16 nvram_offset;
48275 - struct bin_attribute *nvram;
48276 + bin_attribute_no_const *nvram;
48277 enum ds_type type;
48278 unsigned long flags;
48279 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48280 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48281 index 11880c1..b823aa4 100644
48282 --- a/drivers/rtc/rtc-m48t59.c
48283 +++ b/drivers/rtc/rtc-m48t59.c
48284 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48285 if (IS_ERR(m48t59->rtc))
48286 return PTR_ERR(m48t59->rtc);
48287
48288 - m48t59_nvram_attr.size = pdata->offset;
48289 + pax_open_kernel();
48290 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48291 + pax_close_kernel();
48292
48293 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48294 if (ret)
48295 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48296 index 14b5f8d..cc9bd26 100644
48297 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48298 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48299 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48300 for (bit = 0; bit < 8; bit++) {
48301
48302 if ((pci_status[i] & (0x1 << bit)) != 0) {
48303 - static const char *s;
48304 + const char *s;
48305
48306 s = pci_status_strings[bit];
48307 if (i == 7/*TARG*/ && bit == 3)
48308 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48309
48310 for (bit = 0; bit < 8; bit++) {
48311
48312 - if ((split_status[i] & (0x1 << bit)) != 0) {
48313 - static const char *s;
48314 -
48315 - s = split_status_strings[bit];
48316 - printk(s, ahd_name(ahd),
48317 + if ((split_status[i] & (0x1 << bit)) != 0)
48318 + printk(split_status_strings[bit], ahd_name(ahd),
48319 split_status_source[i]);
48320 - }
48321
48322 if (i > 1)
48323 continue;
48324
48325 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48326 - static const char *s;
48327 -
48328 - s = split_status_strings[bit];
48329 - printk(s, ahd_name(ahd), "SG");
48330 - }
48331 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
48332 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
48333 }
48334 }
48335 /*
48336 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48337 index e693af6..2e525b6 100644
48338 --- a/drivers/scsi/bfa/bfa_fcpim.h
48339 +++ b/drivers/scsi/bfa/bfa_fcpim.h
48340 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
48341
48342 struct bfa_itn_s {
48343 bfa_isr_func_t isr;
48344 -};
48345 +} __no_const;
48346
48347 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48348 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48349 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48350 index a3ab5cc..8143622 100644
48351 --- a/drivers/scsi/bfa/bfa_fcs.c
48352 +++ b/drivers/scsi/bfa/bfa_fcs.c
48353 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48354 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48355
48356 static struct bfa_fcs_mod_s fcs_modules[] = {
48357 - { bfa_fcs_port_attach, NULL, NULL },
48358 - { bfa_fcs_uf_attach, NULL, NULL },
48359 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48360 - bfa_fcs_fabric_modexit },
48361 + {
48362 + .attach = bfa_fcs_port_attach,
48363 + .modinit = NULL,
48364 + .modexit = NULL
48365 + },
48366 + {
48367 + .attach = bfa_fcs_uf_attach,
48368 + .modinit = NULL,
48369 + .modexit = NULL
48370 + },
48371 + {
48372 + .attach = bfa_fcs_fabric_attach,
48373 + .modinit = bfa_fcs_fabric_modinit,
48374 + .modexit = bfa_fcs_fabric_modexit
48375 + },
48376 };
48377
48378 /*
48379 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48380 index ff75ef8..2dfe00a 100644
48381 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
48382 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48383 @@ -89,15 +89,26 @@ static struct {
48384 void (*offline) (struct bfa_fcs_lport_s *port);
48385 } __port_action[] = {
48386 {
48387 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48388 - bfa_fcs_lport_unknown_offline}, {
48389 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48390 - bfa_fcs_lport_fab_offline}, {
48391 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48392 - bfa_fcs_lport_n2n_offline}, {
48393 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48394 - bfa_fcs_lport_loop_offline},
48395 - };
48396 + .init = bfa_fcs_lport_unknown_init,
48397 + .online = bfa_fcs_lport_unknown_online,
48398 + .offline = bfa_fcs_lport_unknown_offline
48399 + },
48400 + {
48401 + .init = bfa_fcs_lport_fab_init,
48402 + .online = bfa_fcs_lport_fab_online,
48403 + .offline = bfa_fcs_lport_fab_offline
48404 + },
48405 + {
48406 + .init = bfa_fcs_lport_n2n_init,
48407 + .online = bfa_fcs_lport_n2n_online,
48408 + .offline = bfa_fcs_lport_n2n_offline
48409 + },
48410 + {
48411 + .init = bfa_fcs_lport_loop_init,
48412 + .online = bfa_fcs_lport_loop_online,
48413 + .offline = bfa_fcs_lport_loop_offline
48414 + },
48415 +};
48416
48417 /*
48418 * fcs_port_sm FCS logical port state machine
48419 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48420 index 2e28392..9d865b6 100644
48421 --- a/drivers/scsi/bfa/bfa_ioc.h
48422 +++ b/drivers/scsi/bfa/bfa_ioc.h
48423 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48424 bfa_ioc_disable_cbfn_t disable_cbfn;
48425 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48426 bfa_ioc_reset_cbfn_t reset_cbfn;
48427 -};
48428 +} __no_const;
48429
48430 /*
48431 * IOC event notification mechanism.
48432 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48433 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48434 enum bfi_ioc_state fwstate);
48435 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48436 -};
48437 +} __no_const;
48438
48439 /*
48440 * Queue element to wait for room in request queue. FIFO order is
48441 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48442 index a14c784..6de6790 100644
48443 --- a/drivers/scsi/bfa/bfa_modules.h
48444 +++ b/drivers/scsi/bfa/bfa_modules.h
48445 @@ -78,12 +78,12 @@ enum {
48446 \
48447 extern struct bfa_module_s hal_mod_ ## __mod; \
48448 struct bfa_module_s hal_mod_ ## __mod = { \
48449 - bfa_ ## __mod ## _meminfo, \
48450 - bfa_ ## __mod ## _attach, \
48451 - bfa_ ## __mod ## _detach, \
48452 - bfa_ ## __mod ## _start, \
48453 - bfa_ ## __mod ## _stop, \
48454 - bfa_ ## __mod ## _iocdisable, \
48455 + .meminfo = bfa_ ## __mod ## _meminfo, \
48456 + .attach = bfa_ ## __mod ## _attach, \
48457 + .detach = bfa_ ## __mod ## _detach, \
48458 + .start = bfa_ ## __mod ## _start, \
48459 + .stop = bfa_ ## __mod ## _stop, \
48460 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
48461 }
48462
48463 #define BFA_CACHELINE_SZ (256)
48464 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48465 index 045c4e1..13de803 100644
48466 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
48467 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48468 @@ -33,8 +33,8 @@
48469 */
48470 #include "libfcoe.h"
48471
48472 -static atomic_t ctlr_num;
48473 -static atomic_t fcf_num;
48474 +static atomic_unchecked_t ctlr_num;
48475 +static atomic_unchecked_t fcf_num;
48476
48477 /*
48478 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48479 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48480 if (!ctlr)
48481 goto out;
48482
48483 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48484 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48485 ctlr->f = f;
48486 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48487 INIT_LIST_HEAD(&ctlr->fcfs);
48488 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48489 fcf->dev.parent = &ctlr->dev;
48490 fcf->dev.bus = &fcoe_bus_type;
48491 fcf->dev.type = &fcoe_fcf_device_type;
48492 - fcf->id = atomic_inc_return(&fcf_num) - 1;
48493 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48494 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48495
48496 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48497 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48498 {
48499 int error;
48500
48501 - atomic_set(&ctlr_num, 0);
48502 - atomic_set(&fcf_num, 0);
48503 + atomic_set_unchecked(&ctlr_num, 0);
48504 + atomic_set_unchecked(&fcf_num, 0);
48505
48506 error = bus_register(&fcoe_bus_type);
48507 if (error)
48508 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48509 index f28ea07..34b16d3 100644
48510 --- a/drivers/scsi/hosts.c
48511 +++ b/drivers/scsi/hosts.c
48512 @@ -42,7 +42,7 @@
48513 #include "scsi_logging.h"
48514
48515
48516 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48517 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48518
48519
48520 static void scsi_host_cls_release(struct device *dev)
48521 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48522 * subtract one because we increment first then return, but we need to
48523 * know what the next host number was before increment
48524 */
48525 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48526 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48527 shost->dma_channel = 0xff;
48528
48529 /* These three are default values which can be overridden */
48530 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48531 index 868318a..e07ef3b 100644
48532 --- a/drivers/scsi/hpsa.c
48533 +++ b/drivers/scsi/hpsa.c
48534 @@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48535 unsigned long flags;
48536
48537 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48538 - return h->access.command_completed(h, q);
48539 + return h->access->command_completed(h, q);
48540
48541 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48542 a = rq->head[rq->current_entry];
48543 @@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
48544 while (!list_empty(&h->reqQ)) {
48545 c = list_entry(h->reqQ.next, struct CommandList, list);
48546 /* can't do anything if fifo is full */
48547 - if ((h->access.fifo_full(h))) {
48548 + if ((h->access->fifo_full(h))) {
48549 h->fifo_recently_full = 1;
48550 dev_warn(&h->pdev->dev, "fifo full\n");
48551 break;
48552 @@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
48553
48554 /* Tell the controller execute command */
48555 spin_unlock_irqrestore(&h->lock, flags);
48556 - h->access.submit_command(h, c);
48557 + h->access->submit_command(h, c);
48558 spin_lock_irqsave(&h->lock, flags);
48559 }
48560 spin_unlock_irqrestore(&h->lock, flags);
48561 @@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
48562
48563 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48564 {
48565 - return h->access.command_completed(h, q);
48566 + return h->access->command_completed(h, q);
48567 }
48568
48569 static inline bool interrupt_pending(struct ctlr_info *h)
48570 {
48571 - return h->access.intr_pending(h);
48572 + return h->access->intr_pending(h);
48573 }
48574
48575 static inline long interrupt_not_for_us(struct ctlr_info *h)
48576 {
48577 - return (h->access.intr_pending(h) == 0) ||
48578 + return (h->access->intr_pending(h) == 0) ||
48579 (h->interrupts_enabled == 0);
48580 }
48581
48582 @@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48583 if (prod_index < 0)
48584 return -ENODEV;
48585 h->product_name = products[prod_index].product_name;
48586 - h->access = *(products[prod_index].access);
48587 + h->access = products[prod_index].access;
48588
48589 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48590 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48591 @@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48592 {
48593 unsigned long flags;
48594
48595 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48596 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48597 spin_lock_irqsave(&h->lock, flags);
48598 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48599 spin_unlock_irqrestore(&h->lock, flags);
48600 @@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
48601 }
48602
48603 /* make sure the board interrupts are off */
48604 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48605 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48606
48607 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48608 goto clean2;
48609 @@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
48610 * fake ones to scoop up any residual completions.
48611 */
48612 spin_lock_irqsave(&h->lock, flags);
48613 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48614 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48615 spin_unlock_irqrestore(&h->lock, flags);
48616 free_irqs(h);
48617 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48618 @@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
48619 dev_info(&h->pdev->dev, "Board READY.\n");
48620 dev_info(&h->pdev->dev,
48621 "Waiting for stale completions to drain.\n");
48622 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48623 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48624 msleep(10000);
48625 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48626 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48627
48628 rc = controller_reset_failed(h->cfgtable);
48629 if (rc)
48630 @@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
48631 }
48632
48633 /* Turn the interrupts on so we can service requests */
48634 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48635 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48636
48637 hpsa_hba_inquiry(h);
48638 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48639 @@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48640 * To write all data in the battery backed cache to disks
48641 */
48642 hpsa_flush_cache(h);
48643 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48644 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48645 hpsa_free_irqs_and_disable_msix(h);
48646 }
48647
48648 @@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48649 return;
48650 }
48651 /* Change the access methods to the performant access methods */
48652 - h->access = SA5_performant_access;
48653 + h->access = &SA5_performant_access;
48654 h->transMethod = CFGTBL_Trans_Performant;
48655 }
48656
48657 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48658 index 01c3283..4655219 100644
48659 --- a/drivers/scsi/hpsa.h
48660 +++ b/drivers/scsi/hpsa.h
48661 @@ -79,7 +79,7 @@ struct ctlr_info {
48662 unsigned int msix_vector;
48663 unsigned int msi_vector;
48664 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48665 - struct access_method access;
48666 + struct access_method *access;
48667
48668 /* queue and queue Info */
48669 struct list_head reqQ;
48670 @@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48671 }
48672
48673 static struct access_method SA5_access = {
48674 - SA5_submit_command,
48675 - SA5_intr_mask,
48676 - SA5_fifo_full,
48677 - SA5_intr_pending,
48678 - SA5_completed,
48679 + .submit_command = SA5_submit_command,
48680 + .set_intr_mask = SA5_intr_mask,
48681 + .fifo_full = SA5_fifo_full,
48682 + .intr_pending = SA5_intr_pending,
48683 + .command_completed = SA5_completed,
48684 };
48685
48686 static struct access_method SA5_performant_access = {
48687 - SA5_submit_command,
48688 - SA5_performant_intr_mask,
48689 - SA5_fifo_full,
48690 - SA5_performant_intr_pending,
48691 - SA5_performant_completed,
48692 + .submit_command = SA5_submit_command,
48693 + .set_intr_mask = SA5_performant_intr_mask,
48694 + .fifo_full = SA5_fifo_full,
48695 + .intr_pending = SA5_performant_intr_pending,
48696 + .command_completed = SA5_performant_completed,
48697 };
48698
48699 struct board_type {
48700 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48701 index 1b3a094..068e683 100644
48702 --- a/drivers/scsi/libfc/fc_exch.c
48703 +++ b/drivers/scsi/libfc/fc_exch.c
48704 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
48705 u16 pool_max_index;
48706
48707 struct {
48708 - atomic_t no_free_exch;
48709 - atomic_t no_free_exch_xid;
48710 - atomic_t xid_not_found;
48711 - atomic_t xid_busy;
48712 - atomic_t seq_not_found;
48713 - atomic_t non_bls_resp;
48714 + atomic_unchecked_t no_free_exch;
48715 + atomic_unchecked_t no_free_exch_xid;
48716 + atomic_unchecked_t xid_not_found;
48717 + atomic_unchecked_t xid_busy;
48718 + atomic_unchecked_t seq_not_found;
48719 + atomic_unchecked_t non_bls_resp;
48720 } stats;
48721 };
48722
48723 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48724 /* allocate memory for exchange */
48725 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48726 if (!ep) {
48727 - atomic_inc(&mp->stats.no_free_exch);
48728 + atomic_inc_unchecked(&mp->stats.no_free_exch);
48729 goto out;
48730 }
48731 memset(ep, 0, sizeof(*ep));
48732 @@ -874,7 +874,7 @@ out:
48733 return ep;
48734 err:
48735 spin_unlock_bh(&pool->lock);
48736 - atomic_inc(&mp->stats.no_free_exch_xid);
48737 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48738 mempool_free(ep, mp->ep_pool);
48739 return NULL;
48740 }
48741 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48742 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48743 ep = fc_exch_find(mp, xid);
48744 if (!ep) {
48745 - atomic_inc(&mp->stats.xid_not_found);
48746 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48747 reject = FC_RJT_OX_ID;
48748 goto out;
48749 }
48750 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48751 ep = fc_exch_find(mp, xid);
48752 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48753 if (ep) {
48754 - atomic_inc(&mp->stats.xid_busy);
48755 + atomic_inc_unchecked(&mp->stats.xid_busy);
48756 reject = FC_RJT_RX_ID;
48757 goto rel;
48758 }
48759 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48760 }
48761 xid = ep->xid; /* get our XID */
48762 } else if (!ep) {
48763 - atomic_inc(&mp->stats.xid_not_found);
48764 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48765 reject = FC_RJT_RX_ID; /* XID not found */
48766 goto out;
48767 }
48768 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48769 } else {
48770 sp = &ep->seq;
48771 if (sp->id != fh->fh_seq_id) {
48772 - atomic_inc(&mp->stats.seq_not_found);
48773 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48774 if (f_ctl & FC_FC_END_SEQ) {
48775 /*
48776 * Update sequence_id based on incoming last
48777 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48778
48779 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48780 if (!ep) {
48781 - atomic_inc(&mp->stats.xid_not_found);
48782 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48783 goto out;
48784 }
48785 if (ep->esb_stat & ESB_ST_COMPLETE) {
48786 - atomic_inc(&mp->stats.xid_not_found);
48787 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48788 goto rel;
48789 }
48790 if (ep->rxid == FC_XID_UNKNOWN)
48791 ep->rxid = ntohs(fh->fh_rx_id);
48792 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48793 - atomic_inc(&mp->stats.xid_not_found);
48794 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48795 goto rel;
48796 }
48797 if (ep->did != ntoh24(fh->fh_s_id) &&
48798 ep->did != FC_FID_FLOGI) {
48799 - atomic_inc(&mp->stats.xid_not_found);
48800 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48801 goto rel;
48802 }
48803 sof = fr_sof(fp);
48804 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48805 sp->ssb_stat |= SSB_ST_RESP;
48806 sp->id = fh->fh_seq_id;
48807 } else if (sp->id != fh->fh_seq_id) {
48808 - atomic_inc(&mp->stats.seq_not_found);
48809 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48810 goto rel;
48811 }
48812
48813 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48814 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48815
48816 if (!sp)
48817 - atomic_inc(&mp->stats.xid_not_found);
48818 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48819 else
48820 - atomic_inc(&mp->stats.non_bls_resp);
48821 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
48822
48823 fc_frame_free(fp);
48824 }
48825 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48826
48827 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48828 mp = ema->mp;
48829 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48830 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48831 st->fc_no_free_exch_xid +=
48832 - atomic_read(&mp->stats.no_free_exch_xid);
48833 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48834 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48835 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48836 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48837 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48838 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48839 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48840 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48841 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48842 }
48843 }
48844 EXPORT_SYMBOL(fc_exch_update_stats);
48845 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48846 index d289583..b745eec 100644
48847 --- a/drivers/scsi/libsas/sas_ata.c
48848 +++ b/drivers/scsi/libsas/sas_ata.c
48849 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48850 .postreset = ata_std_postreset,
48851 .error_handler = ata_std_error_handler,
48852 .post_internal_cmd = sas_ata_post_internal,
48853 - .qc_defer = ata_std_qc_defer,
48854 + .qc_defer = ata_std_qc_defer,
48855 .qc_prep = ata_noop_qc_prep,
48856 .qc_issue = sas_ata_qc_issue,
48857 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48858 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48859 index 4e1b75c..0bbdfa9 100644
48860 --- a/drivers/scsi/lpfc/lpfc.h
48861 +++ b/drivers/scsi/lpfc/lpfc.h
48862 @@ -432,7 +432,7 @@ struct lpfc_vport {
48863 struct dentry *debug_nodelist;
48864 struct dentry *vport_debugfs_root;
48865 struct lpfc_debugfs_trc *disc_trc;
48866 - atomic_t disc_trc_cnt;
48867 + atomic_unchecked_t disc_trc_cnt;
48868 #endif
48869 uint8_t stat_data_enabled;
48870 uint8_t stat_data_blocked;
48871 @@ -865,8 +865,8 @@ struct lpfc_hba {
48872 struct timer_list fabric_block_timer;
48873 unsigned long bit_flags;
48874 #define FABRIC_COMANDS_BLOCKED 0
48875 - atomic_t num_rsrc_err;
48876 - atomic_t num_cmd_success;
48877 + atomic_unchecked_t num_rsrc_err;
48878 + atomic_unchecked_t num_cmd_success;
48879 unsigned long last_rsrc_error_time;
48880 unsigned long last_ramp_down_time;
48881 unsigned long last_ramp_up_time;
48882 @@ -902,7 +902,7 @@ struct lpfc_hba {
48883
48884 struct dentry *debug_slow_ring_trc;
48885 struct lpfc_debugfs_trc *slow_ring_trc;
48886 - atomic_t slow_ring_trc_cnt;
48887 + atomic_unchecked_t slow_ring_trc_cnt;
48888 /* iDiag debugfs sub-directory */
48889 struct dentry *idiag_root;
48890 struct dentry *idiag_pci_cfg;
48891 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
48892 index b800cc9..16b6a91 100644
48893 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
48894 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
48895 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
48896
48897 #include <linux/debugfs.h>
48898
48899 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48900 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48901 static unsigned long lpfc_debugfs_start_time = 0L;
48902
48903 /* iDiag */
48904 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
48905 lpfc_debugfs_enable = 0;
48906
48907 len = 0;
48908 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
48909 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
48910 (lpfc_debugfs_max_disc_trc - 1);
48911 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
48912 dtp = vport->disc_trc + i;
48913 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
48914 lpfc_debugfs_enable = 0;
48915
48916 len = 0;
48917 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
48918 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
48919 (lpfc_debugfs_max_slow_ring_trc - 1);
48920 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
48921 dtp = phba->slow_ring_trc + i;
48922 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
48923 !vport || !vport->disc_trc)
48924 return;
48925
48926 - index = atomic_inc_return(&vport->disc_trc_cnt) &
48927 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
48928 (lpfc_debugfs_max_disc_trc - 1);
48929 dtp = vport->disc_trc + index;
48930 dtp->fmt = fmt;
48931 dtp->data1 = data1;
48932 dtp->data2 = data2;
48933 dtp->data3 = data3;
48934 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48935 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48936 dtp->jif = jiffies;
48937 #endif
48938 return;
48939 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
48940 !phba || !phba->slow_ring_trc)
48941 return;
48942
48943 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
48944 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
48945 (lpfc_debugfs_max_slow_ring_trc - 1);
48946 dtp = phba->slow_ring_trc + index;
48947 dtp->fmt = fmt;
48948 dtp->data1 = data1;
48949 dtp->data2 = data2;
48950 dtp->data3 = data3;
48951 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48952 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48953 dtp->jif = jiffies;
48954 #endif
48955 return;
48956 @@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48957 "slow_ring buffer\n");
48958 goto debug_failed;
48959 }
48960 - atomic_set(&phba->slow_ring_trc_cnt, 0);
48961 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
48962 memset(phba->slow_ring_trc, 0,
48963 (sizeof(struct lpfc_debugfs_trc) *
48964 lpfc_debugfs_max_slow_ring_trc));
48965 @@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48966 "buffer\n");
48967 goto debug_failed;
48968 }
48969 - atomic_set(&vport->disc_trc_cnt, 0);
48970 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
48971
48972 snprintf(name, sizeof(name), "discovery_trace");
48973 vport->debug_disc_trc =
48974 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
48975 index 68c94cc..8c27be5 100644
48976 --- a/drivers/scsi/lpfc/lpfc_init.c
48977 +++ b/drivers/scsi/lpfc/lpfc_init.c
48978 @@ -10949,8 +10949,10 @@ lpfc_init(void)
48979 "misc_register returned with status %d", error);
48980
48981 if (lpfc_enable_npiv) {
48982 - lpfc_transport_functions.vport_create = lpfc_vport_create;
48983 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48984 + pax_open_kernel();
48985 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
48986 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48987 + pax_close_kernel();
48988 }
48989 lpfc_transport_template =
48990 fc_attach_transport(&lpfc_transport_functions);
48991 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
48992 index b2ede05..aaf482ca 100644
48993 --- a/drivers/scsi/lpfc/lpfc_scsi.c
48994 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
48995 @@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
48996 uint32_t evt_posted;
48997
48998 spin_lock_irqsave(&phba->hbalock, flags);
48999 - atomic_inc(&phba->num_rsrc_err);
49000 + atomic_inc_unchecked(&phba->num_rsrc_err);
49001 phba->last_rsrc_error_time = jiffies;
49002
49003 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49004 @@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49005 unsigned long flags;
49006 struct lpfc_hba *phba = vport->phba;
49007 uint32_t evt_posted;
49008 - atomic_inc(&phba->num_cmd_success);
49009 + atomic_inc_unchecked(&phba->num_cmd_success);
49010
49011 if (vport->cfg_lun_queue_depth <= queue_depth)
49012 return;
49013 @@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49014 unsigned long num_rsrc_err, num_cmd_success;
49015 int i;
49016
49017 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49018 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49019 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49020 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49021
49022 /*
49023 * The error and success command counters are global per
49024 @@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49025 }
49026 }
49027 lpfc_destroy_vport_work_array(phba, vports);
49028 - atomic_set(&phba->num_rsrc_err, 0);
49029 - atomic_set(&phba->num_cmd_success, 0);
49030 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49031 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49032 }
49033
49034 /**
49035 @@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49036 }
49037 }
49038 lpfc_destroy_vport_work_array(phba, vports);
49039 - atomic_set(&phba->num_rsrc_err, 0);
49040 - atomic_set(&phba->num_cmd_success, 0);
49041 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49042 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49043 }
49044
49045 /**
49046 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49047 index 7f0af4f..193ac3e 100644
49048 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49049 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49050 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49051 {
49052 struct scsi_device *sdev = to_scsi_device(dev);
49053 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49054 - static struct _raid_device *raid_device;
49055 + struct _raid_device *raid_device;
49056 unsigned long flags;
49057 Mpi2RaidVolPage0_t vol_pg0;
49058 Mpi2ConfigReply_t mpi_reply;
49059 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49060 {
49061 struct scsi_device *sdev = to_scsi_device(dev);
49062 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49063 - static struct _raid_device *raid_device;
49064 + struct _raid_device *raid_device;
49065 unsigned long flags;
49066 Mpi2RaidVolPage0_t vol_pg0;
49067 Mpi2ConfigReply_t mpi_reply;
49068 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49069 struct fw_event_work *fw_event)
49070 {
49071 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49072 - static struct _raid_device *raid_device;
49073 + struct _raid_device *raid_device;
49074 unsigned long flags;
49075 u16 handle;
49076
49077 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49078 u64 sas_address;
49079 struct _sas_device *sas_device;
49080 struct _sas_node *expander_device;
49081 - static struct _raid_device *raid_device;
49082 + struct _raid_device *raid_device;
49083 u8 retry_count;
49084 unsigned long flags;
49085
49086 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49087 index be8ce54..94ed33a 100644
49088 --- a/drivers/scsi/pmcraid.c
49089 +++ b/drivers/scsi/pmcraid.c
49090 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49091 res->scsi_dev = scsi_dev;
49092 scsi_dev->hostdata = res;
49093 res->change_detected = 0;
49094 - atomic_set(&res->read_failures, 0);
49095 - atomic_set(&res->write_failures, 0);
49096 + atomic_set_unchecked(&res->read_failures, 0);
49097 + atomic_set_unchecked(&res->write_failures, 0);
49098 rc = 0;
49099 }
49100 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49101 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49102
49103 /* If this was a SCSI read/write command keep count of errors */
49104 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49105 - atomic_inc(&res->read_failures);
49106 + atomic_inc_unchecked(&res->read_failures);
49107 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49108 - atomic_inc(&res->write_failures);
49109 + atomic_inc_unchecked(&res->write_failures);
49110
49111 if (!RES_IS_GSCSI(res->cfg_entry) &&
49112 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49113 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49114 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49115 * hrrq_id assigned here in queuecommand
49116 */
49117 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49118 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49119 pinstance->num_hrrq;
49120 cmd->cmd_done = pmcraid_io_done;
49121
49122 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49123 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49124 * hrrq_id assigned here in queuecommand
49125 */
49126 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49127 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49128 pinstance->num_hrrq;
49129
49130 if (request_size) {
49131 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49132
49133 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49134 /* add resources only after host is added into system */
49135 - if (!atomic_read(&pinstance->expose_resources))
49136 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49137 return;
49138
49139 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49140 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49141 init_waitqueue_head(&pinstance->reset_wait_q);
49142
49143 atomic_set(&pinstance->outstanding_cmds, 0);
49144 - atomic_set(&pinstance->last_message_id, 0);
49145 - atomic_set(&pinstance->expose_resources, 0);
49146 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49147 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49148
49149 INIT_LIST_HEAD(&pinstance->free_res_q);
49150 INIT_LIST_HEAD(&pinstance->used_res_q);
49151 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49152 /* Schedule worker thread to handle CCN and take care of adding and
49153 * removing devices to OS
49154 */
49155 - atomic_set(&pinstance->expose_resources, 1);
49156 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49157 schedule_work(&pinstance->worker_q);
49158 return rc;
49159
49160 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49161 index e1d150f..6c6df44 100644
49162 --- a/drivers/scsi/pmcraid.h
49163 +++ b/drivers/scsi/pmcraid.h
49164 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49165 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49166
49167 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49168 - atomic_t last_message_id;
49169 + atomic_unchecked_t last_message_id;
49170
49171 /* configuration table */
49172 struct pmcraid_config_table *cfg_table;
49173 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49174 atomic_t outstanding_cmds;
49175
49176 /* should add/delete resources to mid-layer now ?*/
49177 - atomic_t expose_resources;
49178 + atomic_unchecked_t expose_resources;
49179
49180
49181
49182 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49183 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49184 };
49185 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49186 - atomic_t read_failures; /* count of failed READ commands */
49187 - atomic_t write_failures; /* count of failed WRITE commands */
49188 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49189 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49190
49191 /* To indicate add/delete/modify during CCN */
49192 u8 change_detected;
49193 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49194 index 4a0d7c9..3d658d7 100644
49195 --- a/drivers/scsi/qla2xxx/qla_attr.c
49196 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49197 @@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49198 return 0;
49199 }
49200
49201 -struct fc_function_template qla2xxx_transport_functions = {
49202 +fc_function_template_no_const qla2xxx_transport_functions = {
49203
49204 .show_host_node_name = 1,
49205 .show_host_port_name = 1,
49206 @@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49207 .bsg_timeout = qla24xx_bsg_timeout,
49208 };
49209
49210 -struct fc_function_template qla2xxx_transport_vport_functions = {
49211 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49212
49213 .show_host_node_name = 1,
49214 .show_host_port_name = 1,
49215 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49216 index 1f42662..bf9836c 100644
49217 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49218 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49219 @@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49220 struct device_attribute;
49221 extern struct device_attribute *qla2x00_host_attrs[];
49222 struct fc_function_template;
49223 -extern struct fc_function_template qla2xxx_transport_functions;
49224 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49225 +extern fc_function_template_no_const qla2xxx_transport_functions;
49226 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49227 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49228 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49229 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49230 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49231 index 89a5300..2a459ab 100644
49232 --- a/drivers/scsi/qla2xxx/qla_os.c
49233 +++ b/drivers/scsi/qla2xxx/qla_os.c
49234 @@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49235 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49236 /* Ok, a 64bit DMA mask is applicable. */
49237 ha->flags.enable_64bit_addressing = 1;
49238 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49239 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49240 + pax_open_kernel();
49241 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49242 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49243 + pax_close_kernel();
49244 return;
49245 }
49246 }
49247 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49248 index aa67bb9..06d0e2a 100644
49249 --- a/drivers/scsi/qla4xxx/ql4_def.h
49250 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49251 @@ -303,7 +303,7 @@ struct ddb_entry {
49252 * (4000 only) */
49253 atomic_t relogin_timer; /* Max Time to wait for
49254 * relogin to complete */
49255 - atomic_t relogin_retry_count; /* Num of times relogin has been
49256 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49257 * retried */
49258 uint32_t default_time2wait; /* Default Min time between
49259 * relogins (+aens) */
49260 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49261 index c21adc3..1b4155f 100644
49262 --- a/drivers/scsi/qla4xxx/ql4_os.c
49263 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49264 @@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49265 */
49266 if (!iscsi_is_session_online(cls_sess)) {
49267 /* Reset retry relogin timer */
49268 - atomic_inc(&ddb_entry->relogin_retry_count);
49269 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49270 DEBUG2(ql4_printk(KERN_INFO, ha,
49271 "%s: index[%d] relogin timed out-retrying"
49272 " relogin (%d), retry (%d)\n", __func__,
49273 ddb_entry->fw_ddb_index,
49274 - atomic_read(&ddb_entry->relogin_retry_count),
49275 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49276 ddb_entry->default_time2wait + 4));
49277 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49278 atomic_set(&ddb_entry->retry_relogin_timer,
49279 @@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49280
49281 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49282 atomic_set(&ddb_entry->relogin_timer, 0);
49283 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49284 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49285 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49286 ddb_entry->default_relogin_timeout =
49287 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49288 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49289 index d8afec8..3ec7152 100644
49290 --- a/drivers/scsi/scsi.c
49291 +++ b/drivers/scsi/scsi.c
49292 @@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49293 struct Scsi_Host *host = cmd->device->host;
49294 int rtn = 0;
49295
49296 - atomic_inc(&cmd->device->iorequest_cnt);
49297 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49298
49299 /* check if the device is still usable */
49300 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49301 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49302 index 62ec84b..93159d8 100644
49303 --- a/drivers/scsi/scsi_lib.c
49304 +++ b/drivers/scsi/scsi_lib.c
49305 @@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49306 shost = sdev->host;
49307 scsi_init_cmd_errh(cmd);
49308 cmd->result = DID_NO_CONNECT << 16;
49309 - atomic_inc(&cmd->device->iorequest_cnt);
49310 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49311
49312 /*
49313 * SCSI request completion path will do scsi_device_unbusy(),
49314 @@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49315
49316 INIT_LIST_HEAD(&cmd->eh_entry);
49317
49318 - atomic_inc(&cmd->device->iodone_cnt);
49319 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
49320 if (cmd->result)
49321 - atomic_inc(&cmd->device->ioerr_cnt);
49322 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49323
49324 disposition = scsi_decide_disposition(cmd);
49325 if (disposition != SUCCESS &&
49326 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49327 index 9117d0b..d289a7a 100644
49328 --- a/drivers/scsi/scsi_sysfs.c
49329 +++ b/drivers/scsi/scsi_sysfs.c
49330 @@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49331 char *buf) \
49332 { \
49333 struct scsi_device *sdev = to_scsi_device(dev); \
49334 - unsigned long long count = atomic_read(&sdev->field); \
49335 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
49336 return snprintf(buf, 20, "0x%llx\n", count); \
49337 } \
49338 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49339 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49340 index 84a1fdf..693b0d6 100644
49341 --- a/drivers/scsi/scsi_tgt_lib.c
49342 +++ b/drivers/scsi/scsi_tgt_lib.c
49343 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49344 int err;
49345
49346 dprintk("%lx %u\n", uaddr, len);
49347 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49348 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49349 if (err) {
49350 /*
49351 * TODO: need to fixup sg_tablesize, max_segment_size,
49352 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49353 index 4628fd5..a94a1c2 100644
49354 --- a/drivers/scsi/scsi_transport_fc.c
49355 +++ b/drivers/scsi/scsi_transport_fc.c
49356 @@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49357 * Netlink Infrastructure
49358 */
49359
49360 -static atomic_t fc_event_seq;
49361 +static atomic_unchecked_t fc_event_seq;
49362
49363 /**
49364 * fc_get_event_number - Obtain the next sequential FC event number
49365 @@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49366 u32
49367 fc_get_event_number(void)
49368 {
49369 - return atomic_add_return(1, &fc_event_seq);
49370 + return atomic_add_return_unchecked(1, &fc_event_seq);
49371 }
49372 EXPORT_SYMBOL(fc_get_event_number);
49373
49374 @@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49375 {
49376 int error;
49377
49378 - atomic_set(&fc_event_seq, 0);
49379 + atomic_set_unchecked(&fc_event_seq, 0);
49380
49381 error = transport_class_register(&fc_host_class);
49382 if (error)
49383 @@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49384 char *cp;
49385
49386 *val = simple_strtoul(buf, &cp, 0);
49387 - if ((*cp && (*cp != '\n')) || (*val < 0))
49388 + if (*cp && (*cp != '\n'))
49389 return -EINVAL;
49390 /*
49391 * Check for overflow; dev_loss_tmo is u32
49392 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49393 index fd8ffe6..fd0bebf 100644
49394 --- a/drivers/scsi/scsi_transport_iscsi.c
49395 +++ b/drivers/scsi/scsi_transport_iscsi.c
49396 @@ -79,7 +79,7 @@ struct iscsi_internal {
49397 struct transport_container session_cont;
49398 };
49399
49400 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49401 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49402 static struct workqueue_struct *iscsi_eh_timer_workq;
49403
49404 static DEFINE_IDA(iscsi_sess_ida);
49405 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49406 int err;
49407
49408 ihost = shost->shost_data;
49409 - session->sid = atomic_add_return(1, &iscsi_session_nr);
49410 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49411
49412 if (target_id == ISCSI_MAX_TARGET) {
49413 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49414 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49415 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49416 ISCSI_TRANSPORT_VERSION);
49417
49418 - atomic_set(&iscsi_session_nr, 0);
49419 + atomic_set_unchecked(&iscsi_session_nr, 0);
49420
49421 err = class_register(&iscsi_transport_class);
49422 if (err)
49423 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49424 index d47ffc8..30f46a9 100644
49425 --- a/drivers/scsi/scsi_transport_srp.c
49426 +++ b/drivers/scsi/scsi_transport_srp.c
49427 @@ -36,7 +36,7 @@
49428 #include "scsi_transport_srp_internal.h"
49429
49430 struct srp_host_attrs {
49431 - atomic_t next_port_id;
49432 + atomic_unchecked_t next_port_id;
49433 };
49434 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49435
49436 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49437 struct Scsi_Host *shost = dev_to_shost(dev);
49438 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49439
49440 - atomic_set(&srp_host->next_port_id, 0);
49441 + atomic_set_unchecked(&srp_host->next_port_id, 0);
49442 return 0;
49443 }
49444
49445 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49446 rport_fast_io_fail_timedout);
49447 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49448
49449 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49450 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49451 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49452
49453 transport_setup_device(&rport->dev);
49454 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49455 index 470954a..eca8d22 100644
49456 --- a/drivers/scsi/sd.c
49457 +++ b/drivers/scsi/sd.c
49458 @@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
49459 sdkp->disk = gd;
49460 sdkp->index = index;
49461 atomic_set(&sdkp->openers, 0);
49462 - atomic_set(&sdkp->device->ioerr_cnt, 0);
49463 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49464
49465 if (!sdp->request_queue->rq_timeout) {
49466 if (sdp->type != TYPE_MOD)
49467 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49468 index df5e961..df6b97f 100644
49469 --- a/drivers/scsi/sg.c
49470 +++ b/drivers/scsi/sg.c
49471 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49472 sdp->disk->disk_name,
49473 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49474 NULL,
49475 - (char *)arg);
49476 + (char __user *)arg);
49477 case BLKTRACESTART:
49478 return blk_trace_startstop(sdp->device->request_queue, 1);
49479 case BLKTRACESTOP:
49480 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49481 index d0b28bb..a263613 100644
49482 --- a/drivers/spi/spi.c
49483 +++ b/drivers/spi/spi.c
49484 @@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
49485 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49486
49487 /* portable code must never pass more than 32 bytes */
49488 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49489 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49490
49491 static u8 *buf;
49492
49493 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49494 index 2c61783..4d49e4e 100644
49495 --- a/drivers/staging/android/timed_output.c
49496 +++ b/drivers/staging/android/timed_output.c
49497 @@ -25,7 +25,7 @@
49498 #include "timed_output.h"
49499
49500 static struct class *timed_output_class;
49501 -static atomic_t device_count;
49502 +static atomic_unchecked_t device_count;
49503
49504 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49505 char *buf)
49506 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49507 timed_output_class = class_create(THIS_MODULE, "timed_output");
49508 if (IS_ERR(timed_output_class))
49509 return PTR_ERR(timed_output_class);
49510 - atomic_set(&device_count, 0);
49511 + atomic_set_unchecked(&device_count, 0);
49512 timed_output_class->dev_groups = timed_output_groups;
49513 }
49514
49515 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49516 if (ret < 0)
49517 return ret;
49518
49519 - tdev->index = atomic_inc_return(&device_count);
49520 + tdev->index = atomic_inc_return_unchecked(&device_count);
49521 tdev->dev = device_create(timed_output_class, NULL,
49522 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49523 if (IS_ERR(tdev->dev))
49524 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49525 index fe47cd3..19a1bd1 100644
49526 --- a/drivers/staging/gdm724x/gdm_tty.c
49527 +++ b/drivers/staging/gdm724x/gdm_tty.c
49528 @@ -44,7 +44,7 @@
49529 #define gdm_tty_send_control(n, r, v, d, l) (\
49530 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49531
49532 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49533 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49534
49535 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49536 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49537 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49538 index 236ed66..dd9cd74 100644
49539 --- a/drivers/staging/imx-drm/imx-drm-core.c
49540 +++ b/drivers/staging/imx-drm/imx-drm-core.c
49541 @@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49542 goto err_busy;
49543 }
49544
49545 - if (imxdrm->drm->open_count) {
49546 + if (local_read(&imxdrm->drm->open_count)) {
49547 ret = -EBUSY;
49548 goto err_busy;
49549 }
49550 @@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49551
49552 mutex_lock(&imxdrm->mutex);
49553
49554 - if (imxdrm->drm->open_count) {
49555 + if (local_read(&imxdrm->drm->open_count)) {
49556 ret = -EBUSY;
49557 goto err_busy;
49558 }
49559 @@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49560
49561 mutex_lock(&imxdrm->mutex);
49562
49563 - if (imxdrm->drm->open_count) {
49564 + if (local_read(&imxdrm->drm->open_count)) {
49565 ret = -EBUSY;
49566 goto err_busy;
49567 }
49568 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49569 index 3f8020c..649fded 100644
49570 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49571 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49572 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49573 return 0;
49574 }
49575
49576 -sfw_test_client_ops_t brw_test_client;
49577 -void brw_init_test_client(void)
49578 -{
49579 - brw_test_client.tso_init = brw_client_init;
49580 - brw_test_client.tso_fini = brw_client_fini;
49581 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49582 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
49583 +sfw_test_client_ops_t brw_test_client = {
49584 + .tso_init = brw_client_init,
49585 + .tso_fini = brw_client_fini,
49586 + .tso_prep_rpc = brw_client_prep_rpc,
49587 + .tso_done_rpc = brw_client_done_rpc,
49588 };
49589
49590 srpc_service_t brw_test_service;
49591 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49592 index 050723a..fa6fdf1 100644
49593 --- a/drivers/staging/lustre/lnet/selftest/framework.c
49594 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
49595 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49596
49597 extern sfw_test_client_ops_t ping_test_client;
49598 extern srpc_service_t ping_test_service;
49599 -extern void ping_init_test_client(void);
49600 extern void ping_init_test_service(void);
49601
49602 extern sfw_test_client_ops_t brw_test_client;
49603 extern srpc_service_t brw_test_service;
49604 -extern void brw_init_test_client(void);
49605 extern void brw_init_test_service(void);
49606
49607
49608 @@ -1684,12 +1682,10 @@ sfw_startup (void)
49609 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49610 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49611
49612 - brw_init_test_client();
49613 brw_init_test_service();
49614 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49615 LASSERT (rc == 0);
49616
49617 - ping_init_test_client();
49618 ping_init_test_service();
49619 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49620 LASSERT (rc == 0);
49621 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49622 index 750cac4..e4d751f 100644
49623 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49624 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49625 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49626 return 0;
49627 }
49628
49629 -sfw_test_client_ops_t ping_test_client;
49630 -void ping_init_test_client(void)
49631 -{
49632 - ping_test_client.tso_init = ping_client_init;
49633 - ping_test_client.tso_fini = ping_client_fini;
49634 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49635 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
49636 -}
49637 +sfw_test_client_ops_t ping_test_client = {
49638 + .tso_init = ping_client_init,
49639 + .tso_fini = ping_client_fini,
49640 + .tso_prep_rpc = ping_client_prep_rpc,
49641 + .tso_done_rpc = ping_client_done_rpc,
49642 +};
49643
49644 srpc_service_t ping_test_service;
49645 void ping_init_test_service(void)
49646 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49647 index ec4bb5e..740c6dd 100644
49648 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49649 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49650 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49651 ldlm_completion_callback lcs_completion;
49652 ldlm_blocking_callback lcs_blocking;
49653 ldlm_glimpse_callback lcs_glimpse;
49654 -};
49655 +} __no_const;
49656
49657 /* ldlm_lockd.c */
49658 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49659 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49660 index c3470ce..2bef527 100644
49661 --- a/drivers/staging/lustre/lustre/include/obd.h
49662 +++ b/drivers/staging/lustre/lustre/include/obd.h
49663 @@ -1426,7 +1426,7 @@ struct md_ops {
49664 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49665 * wrapper function in include/linux/obd_class.h.
49666 */
49667 -};
49668 +} __no_const;
49669
49670 struct lsm_operations {
49671 void (*lsm_free)(struct lov_stripe_md *);
49672 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49673 index c9aae13..60ea292 100644
49674 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49675 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49676 @@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49677 int added = (mode == LCK_NL);
49678 int overlaps = 0;
49679 int splitted = 0;
49680 - const struct ldlm_callback_suite null_cbs = { NULL };
49681 + const struct ldlm_callback_suite null_cbs = { };
49682
49683 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49684 LPU64" end "LPU64"\n", *flags,
49685 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49686 index e947b91..f408990 100644
49687 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49688 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49689 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49690 int LL_PROC_PROTO(proc_console_max_delay_cs)
49691 {
49692 int rc, max_delay_cs;
49693 - ctl_table_t dummy = *table;
49694 + ctl_table_no_const dummy = *table;
49695 cfs_duration_t d;
49696
49697 dummy.data = &max_delay_cs;
49698 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49699 int LL_PROC_PROTO(proc_console_min_delay_cs)
49700 {
49701 int rc, min_delay_cs;
49702 - ctl_table_t dummy = *table;
49703 + ctl_table_no_const dummy = *table;
49704 cfs_duration_t d;
49705
49706 dummy.data = &min_delay_cs;
49707 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49708 int LL_PROC_PROTO(proc_console_backoff)
49709 {
49710 int rc, backoff;
49711 - ctl_table_t dummy = *table;
49712 + ctl_table_no_const dummy = *table;
49713
49714 dummy.data = &backoff;
49715 dummy.proc_handler = &proc_dointvec;
49716 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49717 index 24ae26d..9d09cab 100644
49718 --- a/drivers/staging/lustre/lustre/libcfs/module.c
49719 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
49720 @@ -313,11 +313,11 @@ out:
49721
49722
49723 struct cfs_psdev_ops libcfs_psdev_ops = {
49724 - libcfs_psdev_open,
49725 - libcfs_psdev_release,
49726 - NULL,
49727 - NULL,
49728 - libcfs_ioctl
49729 + .p_open = libcfs_psdev_open,
49730 + .p_close = libcfs_psdev_release,
49731 + .p_read = NULL,
49732 + .p_write = NULL,
49733 + .p_ioctl = libcfs_ioctl
49734 };
49735
49736 extern int insert_proc(void);
49737 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49738 index 52b7731..d604da0 100644
49739 --- a/drivers/staging/lustre/lustre/llite/dir.c
49740 +++ b/drivers/staging/lustre/lustre/llite/dir.c
49741 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49742 int mode;
49743 int err;
49744
49745 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49746 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49747 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49748 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49749 lump);
49750 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49751 index 480b7c4..6846324 100644
49752 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
49753 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49754 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49755
49756 static int solo_sysfs_init(struct solo_dev *solo_dev)
49757 {
49758 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49759 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49760 struct device *dev = &solo_dev->dev;
49761 const char *driver;
49762 int i;
49763 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49764 index 1db18c7..35e6afc 100644
49765 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49766 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49767 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49768
49769 int solo_g723_init(struct solo_dev *solo_dev)
49770 {
49771 - static struct snd_device_ops ops = { NULL };
49772 + static struct snd_device_ops ops = { };
49773 struct snd_card *card;
49774 struct snd_kcontrol_new kctl;
49775 char name[32];
49776 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49777 index 7f2f247..d999137 100644
49778 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49779 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49780 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49781
49782 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49783 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49784 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49785 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49786 if (p2m_id < 0)
49787 p2m_id = -p2m_id;
49788 }
49789 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49790 index 8964f8b..36eb087 100644
49791 --- a/drivers/staging/media/solo6x10/solo6x10.h
49792 +++ b/drivers/staging/media/solo6x10/solo6x10.h
49793 @@ -237,7 +237,7 @@ struct solo_dev {
49794
49795 /* P2M DMA Engine */
49796 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49797 - atomic_t p2m_count;
49798 + atomic_unchecked_t p2m_count;
49799 int p2m_jiffies;
49800 unsigned int p2m_timeouts;
49801
49802 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49803 index a0f4868..139f1fb 100644
49804 --- a/drivers/staging/octeon/ethernet-rx.c
49805 +++ b/drivers/staging/octeon/ethernet-rx.c
49806 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49807 /* Increment RX stats for virtual ports */
49808 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49809 #ifdef CONFIG_64BIT
49810 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49811 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49812 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49813 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49814 #else
49815 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49816 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49817 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49818 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49819 #endif
49820 }
49821 netif_receive_skb(skb);
49822 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49823 dev->name);
49824 */
49825 #ifdef CONFIG_64BIT
49826 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49827 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49828 #else
49829 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49830 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49831 #endif
49832 dev_kfree_skb_irq(skb);
49833 }
49834 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49835 index 089dc4b..c9a687e 100644
49836 --- a/drivers/staging/octeon/ethernet.c
49837 +++ b/drivers/staging/octeon/ethernet.c
49838 @@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49839 * since the RX tasklet also increments it.
49840 */
49841 #ifdef CONFIG_64BIT
49842 - atomic64_add(rx_status.dropped_packets,
49843 - (atomic64_t *)&priv->stats.rx_dropped);
49844 + atomic64_add_unchecked(rx_status.dropped_packets,
49845 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49846 #else
49847 - atomic_add(rx_status.dropped_packets,
49848 - (atomic_t *)&priv->stats.rx_dropped);
49849 + atomic_add_unchecked(rx_status.dropped_packets,
49850 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
49851 #endif
49852 }
49853
49854 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49855 index c274b34..f84de76 100644
49856 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
49857 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49858 @@ -271,7 +271,7 @@ struct hal_ops {
49859 s32 (*c2h_handler)(struct adapter *padapter,
49860 struct c2h_evt_hdr *c2h_evt);
49861 c2h_id_filter c2h_id_filter_ccx;
49862 -};
49863 +} __no_const;
49864
49865 enum rt_eeprom_type {
49866 EEPROM_93C46,
49867 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49868 index 3d1dfcc..ff5620a 100644
49869 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
49870 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49871 @@ -126,7 +126,7 @@ struct _io_ops {
49872 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
49873 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49874 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
49875 -};
49876 +} __no_const;
49877
49878 struct io_req {
49879 struct list_head list;
49880 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
49881 index dc23395..cf7e9b1 100644
49882 --- a/drivers/staging/rtl8712/rtl871x_io.h
49883 +++ b/drivers/staging/rtl8712/rtl871x_io.h
49884 @@ -108,7 +108,7 @@ struct _io_ops {
49885 u8 *pmem);
49886 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
49887 u8 *pmem);
49888 -};
49889 +} __no_const;
49890
49891 struct io_req {
49892 struct list_head list;
49893 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
49894 index 1f5088b..0e59820 100644
49895 --- a/drivers/staging/sbe-2t3e3/netdev.c
49896 +++ b/drivers/staging/sbe-2t3e3/netdev.c
49897 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49898 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
49899
49900 if (rlen)
49901 - if (copy_to_user(data, &resp, rlen))
49902 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
49903 return -EFAULT;
49904
49905 return 0;
49906 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
49907 index a863a98..d272795 100644
49908 --- a/drivers/staging/usbip/vhci.h
49909 +++ b/drivers/staging/usbip/vhci.h
49910 @@ -83,7 +83,7 @@ struct vhci_hcd {
49911 unsigned resuming:1;
49912 unsigned long re_timeout;
49913
49914 - atomic_t seqnum;
49915 + atomic_unchecked_t seqnum;
49916
49917 /*
49918 * NOTE:
49919 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
49920 index 72391ef..7c6717a 100644
49921 --- a/drivers/staging/usbip/vhci_hcd.c
49922 +++ b/drivers/staging/usbip/vhci_hcd.c
49923 @@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
49924
49925 spin_lock(&vdev->priv_lock);
49926
49927 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
49928 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49929 if (priv->seqnum == 0xffff)
49930 dev_info(&urb->dev->dev, "seqnum max\n");
49931
49932 @@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
49933 return -ENOMEM;
49934 }
49935
49936 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
49937 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49938 if (unlink->seqnum == 0xffff)
49939 pr_info("seqnum max\n");
49940
49941 @@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
49942 vdev->rhport = rhport;
49943 }
49944
49945 - atomic_set(&vhci->seqnum, 0);
49946 + atomic_set_unchecked(&vhci->seqnum, 0);
49947 spin_lock_init(&vhci->lock);
49948
49949 hcd->power_budget = 0; /* no limit */
49950 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
49951 index d07fcb5..358e1e1 100644
49952 --- a/drivers/staging/usbip/vhci_rx.c
49953 +++ b/drivers/staging/usbip/vhci_rx.c
49954 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
49955 if (!urb) {
49956 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
49957 pr_info("max seqnum %d\n",
49958 - atomic_read(&the_controller->seqnum));
49959 + atomic_read_unchecked(&the_controller->seqnum));
49960 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
49961 return;
49962 }
49963 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
49964 index 6eecd53..29317c6 100644
49965 --- a/drivers/staging/vt6655/hostap.c
49966 +++ b/drivers/staging/vt6655/hostap.c
49967 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
49968 *
49969 */
49970
49971 +static net_device_ops_no_const apdev_netdev_ops;
49972 +
49973 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49974 {
49975 PSDevice apdev_priv;
49976 struct net_device *dev = pDevice->dev;
49977 int ret;
49978 - const struct net_device_ops apdev_netdev_ops = {
49979 - .ndo_start_xmit = pDevice->tx_80211,
49980 - };
49981
49982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
49983
49984 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49985 *apdev_priv = *pDevice;
49986 eth_hw_addr_inherit(pDevice->apdev, dev);
49987
49988 + /* only half broken now */
49989 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
49990 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
49991
49992 pDevice->apdev->type = ARPHRD_IEEE80211;
49993 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
49994 index 67ba48b..24e602f 100644
49995 --- a/drivers/staging/vt6656/hostap.c
49996 +++ b/drivers/staging/vt6656/hostap.c
49997 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
49998 *
49999 */
50000
50001 +static net_device_ops_no_const apdev_netdev_ops;
50002 +
50003 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50004 {
50005 struct vnt_private *apdev_priv;
50006 struct net_device *dev = pDevice->dev;
50007 int ret;
50008 - const struct net_device_ops apdev_netdev_ops = {
50009 - .ndo_start_xmit = pDevice->tx_80211,
50010 - };
50011
50012 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50013
50014 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50015 *apdev_priv = *pDevice;
50016 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50017
50018 + /* only half broken now */
50019 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50020 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50021
50022 pDevice->apdev->type = ARPHRD_IEEE80211;
50023 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50024 index 24884ca..26c8220 100644
50025 --- a/drivers/target/sbp/sbp_target.c
50026 +++ b/drivers/target/sbp/sbp_target.c
50027 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50028
50029 #define SESSION_MAINTENANCE_INTERVAL HZ
50030
50031 -static atomic_t login_id = ATOMIC_INIT(0);
50032 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50033
50034 static void session_maintenance_work(struct work_struct *);
50035 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50036 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50037 login->lun = se_lun;
50038 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50039 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50040 - login->login_id = atomic_inc_return(&login_id);
50041 + login->login_id = atomic_inc_return_unchecked(&login_id);
50042
50043 login->tgt_agt = sbp_target_agent_register(login);
50044 if (IS_ERR(login->tgt_agt)) {
50045 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50046 index 65001e1..2ebfbb9 100644
50047 --- a/drivers/target/target_core_device.c
50048 +++ b/drivers/target/target_core_device.c
50049 @@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50050 spin_lock_init(&dev->se_tmr_lock);
50051 spin_lock_init(&dev->qf_cmd_lock);
50052 sema_init(&dev->caw_sem, 1);
50053 - atomic_set(&dev->dev_ordered_id, 0);
50054 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50055 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50056 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50057 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50058 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50059 index 2956250..b10f722 100644
50060 --- a/drivers/target/target_core_transport.c
50061 +++ b/drivers/target/target_core_transport.c
50062 @@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50063 * Used to determine when ORDERED commands should go from
50064 * Dormant to Active status.
50065 */
50066 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50067 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50068 smp_mb__after_atomic_inc();
50069 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50070 cmd->se_ordered_id, cmd->sam_task_attr,
50071 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50072 index a57bb5a..1f727d33 100644
50073 --- a/drivers/tty/cyclades.c
50074 +++ b/drivers/tty/cyclades.c
50075 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50076 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50077 info->port.count);
50078 #endif
50079 - info->port.count++;
50080 + atomic_inc(&info->port.count);
50081 #ifdef CY_DEBUG_COUNT
50082 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50083 - current->pid, info->port.count);
50084 + current->pid, atomic_read(&info->port.count));
50085 #endif
50086
50087 /*
50088 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50089 for (j = 0; j < cy_card[i].nports; j++) {
50090 info = &cy_card[i].ports[j];
50091
50092 - if (info->port.count) {
50093 + if (atomic_read(&info->port.count)) {
50094 /* XXX is the ldisc num worth this? */
50095 struct tty_struct *tty;
50096 struct tty_ldisc *ld;
50097 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50098 index 50b4688..e1e8125 100644
50099 --- a/drivers/tty/hvc/hvc_console.c
50100 +++ b/drivers/tty/hvc/hvc_console.c
50101 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50102
50103 spin_lock_irqsave(&hp->port.lock, flags);
50104 /* Check and then increment for fast path open. */
50105 - if (hp->port.count++ > 0) {
50106 + if (atomic_inc_return(&hp->port.count) > 1) {
50107 spin_unlock_irqrestore(&hp->port.lock, flags);
50108 hvc_kick();
50109 return 0;
50110 @@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50111
50112 spin_lock_irqsave(&hp->port.lock, flags);
50113
50114 - if (--hp->port.count == 0) {
50115 + if (atomic_dec_return(&hp->port.count) == 0) {
50116 spin_unlock_irqrestore(&hp->port.lock, flags);
50117 /* We are done with the tty pointer now. */
50118 tty_port_tty_set(&hp->port, NULL);
50119 @@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50120 */
50121 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50122 } else {
50123 - if (hp->port.count < 0)
50124 + if (atomic_read(&hp->port.count) < 0)
50125 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50126 - hp->vtermno, hp->port.count);
50127 + hp->vtermno, atomic_read(&hp->port.count));
50128 spin_unlock_irqrestore(&hp->port.lock, flags);
50129 }
50130 }
50131 @@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
50132 * open->hangup case this can be called after the final close so prevent
50133 * that from happening for now.
50134 */
50135 - if (hp->port.count <= 0) {
50136 + if (atomic_read(&hp->port.count) <= 0) {
50137 spin_unlock_irqrestore(&hp->port.lock, flags);
50138 return;
50139 }
50140
50141 - hp->port.count = 0;
50142 + atomic_set(&hp->port.count, 0);
50143 spin_unlock_irqrestore(&hp->port.lock, flags);
50144 tty_port_tty_set(&hp->port, NULL);
50145
50146 @@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50147 return -EPIPE;
50148
50149 /* FIXME what's this (unprotected) check for? */
50150 - if (hp->port.count <= 0)
50151 + if (atomic_read(&hp->port.count) <= 0)
50152 return -EIO;
50153
50154 spin_lock_irqsave(&hp->lock, flags);
50155 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50156 index 81e939e..95ead10 100644
50157 --- a/drivers/tty/hvc/hvcs.c
50158 +++ b/drivers/tty/hvc/hvcs.c
50159 @@ -83,6 +83,7 @@
50160 #include <asm/hvcserver.h>
50161 #include <asm/uaccess.h>
50162 #include <asm/vio.h>
50163 +#include <asm/local.h>
50164
50165 /*
50166 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50167 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50168
50169 spin_lock_irqsave(&hvcsd->lock, flags);
50170
50171 - if (hvcsd->port.count > 0) {
50172 + if (atomic_read(&hvcsd->port.count) > 0) {
50173 spin_unlock_irqrestore(&hvcsd->lock, flags);
50174 printk(KERN_INFO "HVCS: vterm state unchanged. "
50175 "The hvcs device node is still in use.\n");
50176 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50177 }
50178 }
50179
50180 - hvcsd->port.count = 0;
50181 + atomic_set(&hvcsd->port.count, 0);
50182 hvcsd->port.tty = tty;
50183 tty->driver_data = hvcsd;
50184
50185 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50186 unsigned long flags;
50187
50188 spin_lock_irqsave(&hvcsd->lock, flags);
50189 - hvcsd->port.count++;
50190 + atomic_inc(&hvcsd->port.count);
50191 hvcsd->todo_mask |= HVCS_SCHED_READ;
50192 spin_unlock_irqrestore(&hvcsd->lock, flags);
50193
50194 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50195 hvcsd = tty->driver_data;
50196
50197 spin_lock_irqsave(&hvcsd->lock, flags);
50198 - if (--hvcsd->port.count == 0) {
50199 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50200
50201 vio_disable_interrupts(hvcsd->vdev);
50202
50203 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50204
50205 free_irq(irq, hvcsd);
50206 return;
50207 - } else if (hvcsd->port.count < 0) {
50208 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50209 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50210 " is missmanaged.\n",
50211 - hvcsd->vdev->unit_address, hvcsd->port.count);
50212 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50213 }
50214
50215 spin_unlock_irqrestore(&hvcsd->lock, flags);
50216 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50217
50218 spin_lock_irqsave(&hvcsd->lock, flags);
50219 /* Preserve this so that we know how many kref refs to put */
50220 - temp_open_count = hvcsd->port.count;
50221 + temp_open_count = atomic_read(&hvcsd->port.count);
50222
50223 /*
50224 * Don't kref put inside the spinlock because the destruction
50225 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50226 tty->driver_data = NULL;
50227 hvcsd->port.tty = NULL;
50228
50229 - hvcsd->port.count = 0;
50230 + atomic_set(&hvcsd->port.count, 0);
50231
50232 /* This will drop any buffered data on the floor which is OK in a hangup
50233 * scenario. */
50234 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50235 * the middle of a write operation? This is a crummy place to do this
50236 * but we want to keep it all in the spinlock.
50237 */
50238 - if (hvcsd->port.count <= 0) {
50239 + if (atomic_read(&hvcsd->port.count) <= 0) {
50240 spin_unlock_irqrestore(&hvcsd->lock, flags);
50241 return -ENODEV;
50242 }
50243 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50244 {
50245 struct hvcs_struct *hvcsd = tty->driver_data;
50246
50247 - if (!hvcsd || hvcsd->port.count <= 0)
50248 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50249 return 0;
50250
50251 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50252 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50253 index 4190199..06d5bfa 100644
50254 --- a/drivers/tty/hvc/hvsi.c
50255 +++ b/drivers/tty/hvc/hvsi.c
50256 @@ -85,7 +85,7 @@ struct hvsi_struct {
50257 int n_outbuf;
50258 uint32_t vtermno;
50259 uint32_t virq;
50260 - atomic_t seqno; /* HVSI packet sequence number */
50261 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
50262 uint16_t mctrl;
50263 uint8_t state; /* HVSI protocol state */
50264 uint8_t flags;
50265 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50266
50267 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50268 packet.hdr.len = sizeof(struct hvsi_query_response);
50269 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50270 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50271 packet.verb = VSV_SEND_VERSION_NUMBER;
50272 packet.u.version = HVSI_VERSION;
50273 packet.query_seqno = query_seqno+1;
50274 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50275
50276 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50277 packet.hdr.len = sizeof(struct hvsi_query);
50278 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50279 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50280 packet.verb = verb;
50281
50282 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50283 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50284 int wrote;
50285
50286 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50287 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50288 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50289 packet.hdr.len = sizeof(struct hvsi_control);
50290 packet.verb = VSV_SET_MODEM_CTL;
50291 packet.mask = HVSI_TSDTR;
50292 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50293 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50294
50295 packet.hdr.type = VS_DATA_PACKET_HEADER;
50296 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50297 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50298 packet.hdr.len = count + sizeof(struct hvsi_header);
50299 memcpy(&packet.data, buf, count);
50300
50301 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50302 struct hvsi_control packet __ALIGNED__;
50303
50304 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50305 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50306 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50307 packet.hdr.len = 6;
50308 packet.verb = VSV_CLOSE_PROTOCOL;
50309
50310 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50311
50312 tty_port_tty_set(&hp->port, tty);
50313 spin_lock_irqsave(&hp->lock, flags);
50314 - hp->port.count++;
50315 + atomic_inc(&hp->port.count);
50316 atomic_set(&hp->seqno, 0);
50317 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50318 spin_unlock_irqrestore(&hp->lock, flags);
50319 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50320
50321 spin_lock_irqsave(&hp->lock, flags);
50322
50323 - if (--hp->port.count == 0) {
50324 + if (atomic_dec_return(&hp->port.count) == 0) {
50325 tty_port_tty_set(&hp->port, NULL);
50326 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50327
50328 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50329
50330 spin_lock_irqsave(&hp->lock, flags);
50331 }
50332 - } else if (hp->port.count < 0)
50333 + } else if (atomic_read(&hp->port.count) < 0)
50334 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50335 - hp - hvsi_ports, hp->port.count);
50336 + hp - hvsi_ports, atomic_read(&hp->port.count));
50337
50338 spin_unlock_irqrestore(&hp->lock, flags);
50339 }
50340 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50341 tty_port_tty_set(&hp->port, NULL);
50342
50343 spin_lock_irqsave(&hp->lock, flags);
50344 - hp->port.count = 0;
50345 + atomic_set(&hp->port.count, 0);
50346 hp->n_outbuf = 0;
50347 spin_unlock_irqrestore(&hp->lock, flags);
50348 }
50349 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50350 index 7ae6c29..05c6dba 100644
50351 --- a/drivers/tty/hvc/hvsi_lib.c
50352 +++ b/drivers/tty/hvc/hvsi_lib.c
50353 @@ -8,7 +8,7 @@
50354
50355 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50356 {
50357 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50358 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50359
50360 /* Assumes that always succeeds, works in practice */
50361 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50362 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50363
50364 /* Reset state */
50365 pv->established = 0;
50366 - atomic_set(&pv->seqno, 0);
50367 + atomic_set_unchecked(&pv->seqno, 0);
50368
50369 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50370
50371 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50372 index ebd5bff..b1acad3 100644
50373 --- a/drivers/tty/ipwireless/tty.c
50374 +++ b/drivers/tty/ipwireless/tty.c
50375 @@ -28,6 +28,7 @@
50376 #include <linux/tty_driver.h>
50377 #include <linux/tty_flip.h>
50378 #include <linux/uaccess.h>
50379 +#include <asm/local.h>
50380
50381 #include "tty.h"
50382 #include "network.h"
50383 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50384 mutex_unlock(&tty->ipw_tty_mutex);
50385 return -ENODEV;
50386 }
50387 - if (tty->port.count == 0)
50388 + if (atomic_read(&tty->port.count) == 0)
50389 tty->tx_bytes_queued = 0;
50390
50391 - tty->port.count++;
50392 + atomic_inc(&tty->port.count);
50393
50394 tty->port.tty = linux_tty;
50395 linux_tty->driver_data = tty;
50396 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50397
50398 static void do_ipw_close(struct ipw_tty *tty)
50399 {
50400 - tty->port.count--;
50401 -
50402 - if (tty->port.count == 0) {
50403 + if (atomic_dec_return(&tty->port.count) == 0) {
50404 struct tty_struct *linux_tty = tty->port.tty;
50405
50406 if (linux_tty != NULL) {
50407 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50408 return;
50409
50410 mutex_lock(&tty->ipw_tty_mutex);
50411 - if (tty->port.count == 0) {
50412 + if (atomic_read(&tty->port.count) == 0) {
50413 mutex_unlock(&tty->ipw_tty_mutex);
50414 return;
50415 }
50416 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50417
50418 mutex_lock(&tty->ipw_tty_mutex);
50419
50420 - if (!tty->port.count) {
50421 + if (!atomic_read(&tty->port.count)) {
50422 mutex_unlock(&tty->ipw_tty_mutex);
50423 return;
50424 }
50425 @@ -205,7 +204,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50426 return -ENODEV;
50427
50428 mutex_lock(&tty->ipw_tty_mutex);
50429 - if (!tty->port.count) {
50430 + if (!atomic_read(&tty->port.count)) {
50431 mutex_unlock(&tty->ipw_tty_mutex);
50432 return -EINVAL;
50433 }
50434 @@ -245,7 +244,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50435 if (!tty)
50436 return -ENODEV;
50437
50438 - if (!tty->port.count)
50439 + if (!atomic_read(&tty->port.count))
50440 return -EINVAL;
50441
50442 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50443 @@ -287,7 +286,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50444 if (!tty)
50445 return 0;
50446
50447 - if (!tty->port.count)
50448 + if (!atomic_read(&tty->port.count))
50449 return 0;
50450
50451 return tty->tx_bytes_queued;
50452 @@ -368,7 +367,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50453 if (!tty)
50454 return -ENODEV;
50455
50456 - if (!tty->port.count)
50457 + if (!atomic_read(&tty->port.count))
50458 return -EINVAL;
50459
50460 return get_control_lines(tty);
50461 @@ -384,7 +383,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50462 if (!tty)
50463 return -ENODEV;
50464
50465 - if (!tty->port.count)
50466 + if (!atomic_read(&tty->port.count))
50467 return -EINVAL;
50468
50469 return set_control_lines(tty, set, clear);
50470 @@ -398,7 +397,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50471 if (!tty)
50472 return -ENODEV;
50473
50474 - if (!tty->port.count)
50475 + if (!atomic_read(&tty->port.count))
50476 return -EINVAL;
50477
50478 /* FIXME: Exactly how is the tty object locked here .. */
50479 @@ -554,7 +553,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50480 * are gone */
50481 mutex_lock(&ttyj->ipw_tty_mutex);
50482 }
50483 - while (ttyj->port.count)
50484 + while (atomic_read(&ttyj->port.count))
50485 do_ipw_close(ttyj);
50486 ipwireless_disassociate_network_ttys(network,
50487 ttyj->channel_idx);
50488 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50489 index 1deaca4..c8582d4 100644
50490 --- a/drivers/tty/moxa.c
50491 +++ b/drivers/tty/moxa.c
50492 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50493 }
50494
50495 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50496 - ch->port.count++;
50497 + atomic_inc(&ch->port.count);
50498 tty->driver_data = ch;
50499 tty_port_tty_set(&ch->port, tty);
50500 mutex_lock(&ch->port.mutex);
50501 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50502 index 2ebe47b..3205833 100644
50503 --- a/drivers/tty/n_gsm.c
50504 +++ b/drivers/tty/n_gsm.c
50505 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50506 spin_lock_init(&dlci->lock);
50507 mutex_init(&dlci->mutex);
50508 dlci->fifo = &dlci->_fifo;
50509 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50510 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50511 kfree(dlci);
50512 return NULL;
50513 }
50514 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50515 struct gsm_dlci *dlci = tty->driver_data;
50516 struct tty_port *port = &dlci->port;
50517
50518 - port->count++;
50519 + atomic_inc(&port->count);
50520 tty_port_tty_set(port, tty);
50521
50522 dlci->modem_rx = 0;
50523 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50524 index d15624c..e512bdb 100644
50525 --- a/drivers/tty/n_tty.c
50526 +++ b/drivers/tty/n_tty.c
50527 @@ -115,7 +115,7 @@ struct n_tty_data {
50528 int minimum_to_wake;
50529
50530 /* consumer-published */
50531 - size_t read_tail;
50532 + size_t read_tail __intentional_overflow(-1);
50533 size_t line_start;
50534
50535 /* protected by output lock */
50536 @@ -2515,6 +2515,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50537 {
50538 *ops = tty_ldisc_N_TTY;
50539 ops->owner = NULL;
50540 - ops->refcount = ops->flags = 0;
50541 + atomic_set(&ops->refcount, 0);
50542 + ops->flags = 0;
50543 }
50544 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50545 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50546 index 25c9bc7..24077b7 100644
50547 --- a/drivers/tty/pty.c
50548 +++ b/drivers/tty/pty.c
50549 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50550 panic("Couldn't register Unix98 pts driver");
50551
50552 /* Now create the /dev/ptmx special device */
50553 + pax_open_kernel();
50554 tty_default_fops(&ptmx_fops);
50555 - ptmx_fops.open = ptmx_open;
50556 + *(void **)&ptmx_fops.open = ptmx_open;
50557 + pax_close_kernel();
50558
50559 cdev_init(&ptmx_cdev, &ptmx_fops);
50560 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50561 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50562 index 383c4c7..d408e21 100644
50563 --- a/drivers/tty/rocket.c
50564 +++ b/drivers/tty/rocket.c
50565 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50566 tty->driver_data = info;
50567 tty_port_tty_set(port, tty);
50568
50569 - if (port->count++ == 0) {
50570 + if (atomic_inc_return(&port->count) == 1) {
50571 atomic_inc(&rp_num_ports_open);
50572
50573 #ifdef ROCKET_DEBUG_OPEN
50574 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50575 #endif
50576 }
50577 #ifdef ROCKET_DEBUG_OPEN
50578 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50579 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50580 #endif
50581
50582 /*
50583 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50584 spin_unlock_irqrestore(&info->port.lock, flags);
50585 return;
50586 }
50587 - if (info->port.count)
50588 + if (atomic_read(&info->port.count))
50589 atomic_dec(&rp_num_ports_open);
50590 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50591 spin_unlock_irqrestore(&info->port.lock, flags);
50592 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50593 index 1274499..f541382 100644
50594 --- a/drivers/tty/serial/ioc4_serial.c
50595 +++ b/drivers/tty/serial/ioc4_serial.c
50596 @@ -437,7 +437,7 @@ struct ioc4_soft {
50597 } is_intr_info[MAX_IOC4_INTR_ENTS];
50598
50599 /* Number of entries active in the above array */
50600 - atomic_t is_num_intrs;
50601 + atomic_unchecked_t is_num_intrs;
50602 } is_intr_type[IOC4_NUM_INTR_TYPES];
50603
50604 /* is_ir_lock must be held while
50605 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50606 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50607 || (type == IOC4_OTHER_INTR_TYPE)));
50608
50609 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50610 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50611 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50612
50613 /* Save off the lower level interrupt handler */
50614 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50615
50616 soft = arg;
50617 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50618 - num_intrs = (int)atomic_read(
50619 + num_intrs = (int)atomic_read_unchecked(
50620 &soft->is_intr_type[intr_type].is_num_intrs);
50621
50622 this_mir = this_ir = pending_intrs(soft, intr_type);
50623 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50624 index a260cde..6b2b5ce 100644
50625 --- a/drivers/tty/serial/kgdboc.c
50626 +++ b/drivers/tty/serial/kgdboc.c
50627 @@ -24,8 +24,9 @@
50628 #define MAX_CONFIG_LEN 40
50629
50630 static struct kgdb_io kgdboc_io_ops;
50631 +static struct kgdb_io kgdboc_io_ops_console;
50632
50633 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50634 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50635 static int configured = -1;
50636
50637 static char config[MAX_CONFIG_LEN];
50638 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50639 kgdboc_unregister_kbd();
50640 if (configured == 1)
50641 kgdb_unregister_io_module(&kgdboc_io_ops);
50642 + else if (configured == 2)
50643 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
50644 }
50645
50646 static int configure_kgdboc(void)
50647 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50648 int err;
50649 char *cptr = config;
50650 struct console *cons;
50651 + int is_console = 0;
50652
50653 err = kgdboc_option_setup(config);
50654 if (err || !strlen(config) || isspace(config[0]))
50655 goto noconfig;
50656
50657 err = -ENODEV;
50658 - kgdboc_io_ops.is_console = 0;
50659 kgdb_tty_driver = NULL;
50660
50661 kgdboc_use_kms = 0;
50662 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50663 int idx;
50664 if (cons->device && cons->device(cons, &idx) == p &&
50665 idx == tty_line) {
50666 - kgdboc_io_ops.is_console = 1;
50667 + is_console = 1;
50668 break;
50669 }
50670 cons = cons->next;
50671 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50672 kgdb_tty_line = tty_line;
50673
50674 do_register:
50675 - err = kgdb_register_io_module(&kgdboc_io_ops);
50676 + if (is_console) {
50677 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
50678 + configured = 2;
50679 + } else {
50680 + err = kgdb_register_io_module(&kgdboc_io_ops);
50681 + configured = 1;
50682 + }
50683 if (err)
50684 goto noconfig;
50685
50686 @@ -205,8 +214,6 @@ do_register:
50687 if (err)
50688 goto nmi_con_failed;
50689
50690 - configured = 1;
50691 -
50692 return 0;
50693
50694 nmi_con_failed:
50695 @@ -223,7 +230,7 @@ noconfig:
50696 static int __init init_kgdboc(void)
50697 {
50698 /* Already configured? */
50699 - if (configured == 1)
50700 + if (configured >= 1)
50701 return 0;
50702
50703 return configure_kgdboc();
50704 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50705 if (config[len - 1] == '\n')
50706 config[len - 1] = '\0';
50707
50708 - if (configured == 1)
50709 + if (configured >= 1)
50710 cleanup_kgdboc();
50711
50712 /* Go and configure with the new params. */
50713 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50714 .post_exception = kgdboc_post_exp_handler,
50715 };
50716
50717 +static struct kgdb_io kgdboc_io_ops_console = {
50718 + .name = "kgdboc",
50719 + .read_char = kgdboc_get_char,
50720 + .write_char = kgdboc_put_char,
50721 + .pre_exception = kgdboc_pre_exp_handler,
50722 + .post_exception = kgdboc_post_exp_handler,
50723 + .is_console = 1
50724 +};
50725 +
50726 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50727 /* This is only available if kgdboc is a built in for early debugging */
50728 static int __init kgdboc_early_init(char *opt)
50729 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50730 index b5d779c..3622cfe 100644
50731 --- a/drivers/tty/serial/msm_serial.c
50732 +++ b/drivers/tty/serial/msm_serial.c
50733 @@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50734 .cons = MSM_CONSOLE,
50735 };
50736
50737 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50738 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50739
50740 static const struct of_device_id msm_uartdm_table[] = {
50741 { .compatible = "qcom,msm-uartdm" },
50742 @@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50743 int irq;
50744
50745 if (pdev->id == -1)
50746 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50747 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50748
50749 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50750 return -ENXIO;
50751 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50752 index 9cd706d..6ff2de7 100644
50753 --- a/drivers/tty/serial/samsung.c
50754 +++ b/drivers/tty/serial/samsung.c
50755 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50756 }
50757 }
50758
50759 +static int s3c64xx_serial_startup(struct uart_port *port);
50760 static int s3c24xx_serial_startup(struct uart_port *port)
50761 {
50762 struct s3c24xx_uart_port *ourport = to_ourport(port);
50763 int ret;
50764
50765 + /* Startup sequence is different for s3c64xx and higher SoC's */
50766 + if (s3c24xx_serial_has_interrupt_mask(port))
50767 + return s3c64xx_serial_startup(port);
50768 +
50769 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50770 port->mapbase, port->membase);
50771
50772 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50773 /* setup info for port */
50774 port->dev = &platdev->dev;
50775
50776 - /* Startup sequence is different for s3c64xx and higher SoC's */
50777 - if (s3c24xx_serial_has_interrupt_mask(port))
50778 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50779 -
50780 port->uartclk = 1;
50781
50782 if (cfg->uart_flags & UPF_CONS_FLOW) {
50783 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50784 index ece2049..fba2524 100644
50785 --- a/drivers/tty/serial/serial_core.c
50786 +++ b/drivers/tty/serial/serial_core.c
50787 @@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50788 uart_flush_buffer(tty);
50789 uart_shutdown(tty, state);
50790 spin_lock_irqsave(&port->lock, flags);
50791 - port->count = 0;
50792 + atomic_set(&port->count, 0);
50793 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50794 spin_unlock_irqrestore(&port->lock, flags);
50795 tty_port_tty_set(port, NULL);
50796 @@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50797 goto end;
50798 }
50799
50800 - port->count++;
50801 + atomic_inc(&port->count);
50802 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50803 retval = -ENXIO;
50804 goto err_dec_count;
50805 @@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50806 /*
50807 * Make sure the device is in D0 state.
50808 */
50809 - if (port->count == 1)
50810 + if (atomic_read(&port->count) == 1)
50811 uart_change_pm(state, UART_PM_STATE_ON);
50812
50813 /*
50814 @@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50815 end:
50816 return retval;
50817 err_dec_count:
50818 - port->count--;
50819 + atomic_inc(&port->count);
50820 mutex_unlock(&port->mutex);
50821 goto end;
50822 }
50823 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50824 index 5ae14b4..2c1288f 100644
50825 --- a/drivers/tty/synclink.c
50826 +++ b/drivers/tty/synclink.c
50827 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50828
50829 if (debug_level >= DEBUG_LEVEL_INFO)
50830 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50831 - __FILE__,__LINE__, info->device_name, info->port.count);
50832 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50833
50834 if (tty_port_close_start(&info->port, tty, filp) == 0)
50835 goto cleanup;
50836 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50837 cleanup:
50838 if (debug_level >= DEBUG_LEVEL_INFO)
50839 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
50840 - tty->driver->name, info->port.count);
50841 + tty->driver->name, atomic_read(&info->port.count));
50842
50843 } /* end of mgsl_close() */
50844
50845 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
50846
50847 mgsl_flush_buffer(tty);
50848 shutdown(info);
50849 -
50850 - info->port.count = 0;
50851 +
50852 + atomic_set(&info->port.count, 0);
50853 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50854 info->port.tty = NULL;
50855
50856 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50857
50858 if (debug_level >= DEBUG_LEVEL_INFO)
50859 printk("%s(%d):block_til_ready before block on %s count=%d\n",
50860 - __FILE__,__LINE__, tty->driver->name, port->count );
50861 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50862
50863 spin_lock_irqsave(&info->irq_spinlock, flags);
50864 if (!tty_hung_up_p(filp)) {
50865 extra_count = true;
50866 - port->count--;
50867 + atomic_dec(&port->count);
50868 }
50869 spin_unlock_irqrestore(&info->irq_spinlock, flags);
50870 port->blocked_open++;
50871 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50872
50873 if (debug_level >= DEBUG_LEVEL_INFO)
50874 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
50875 - __FILE__,__LINE__, tty->driver->name, port->count );
50876 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50877
50878 tty_unlock(tty);
50879 schedule();
50880 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50881
50882 /* FIXME: Racy on hangup during close wait */
50883 if (extra_count)
50884 - port->count++;
50885 + atomic_inc(&port->count);
50886 port->blocked_open--;
50887
50888 if (debug_level >= DEBUG_LEVEL_INFO)
50889 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
50890 - __FILE__,__LINE__, tty->driver->name, port->count );
50891 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50892
50893 if (!retval)
50894 port->flags |= ASYNC_NORMAL_ACTIVE;
50895 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50896
50897 if (debug_level >= DEBUG_LEVEL_INFO)
50898 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
50899 - __FILE__,__LINE__,tty->driver->name, info->port.count);
50900 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50901
50902 /* If port is closing, signal caller to try again */
50903 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50904 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50905 spin_unlock_irqrestore(&info->netlock, flags);
50906 goto cleanup;
50907 }
50908 - info->port.count++;
50909 + atomic_inc(&info->port.count);
50910 spin_unlock_irqrestore(&info->netlock, flags);
50911
50912 - if (info->port.count == 1) {
50913 + if (atomic_read(&info->port.count) == 1) {
50914 /* 1st open on this device, init hardware */
50915 retval = startup(info);
50916 if (retval < 0)
50917 @@ -3446,8 +3446,8 @@ cleanup:
50918 if (retval) {
50919 if (tty->count == 1)
50920 info->port.tty = NULL; /* tty layer will release tty struct */
50921 - if(info->port.count)
50922 - info->port.count--;
50923 + if (atomic_read(&info->port.count))
50924 + atomic_dec(&info->port.count);
50925 }
50926
50927 return retval;
50928 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50929 unsigned short new_crctype;
50930
50931 /* return error if TTY interface open */
50932 - if (info->port.count)
50933 + if (atomic_read(&info->port.count))
50934 return -EBUSY;
50935
50936 switch (encoding)
50937 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
50938
50939 /* arbitrate between network and tty opens */
50940 spin_lock_irqsave(&info->netlock, flags);
50941 - if (info->port.count != 0 || info->netcount != 0) {
50942 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50943 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50944 spin_unlock_irqrestore(&info->netlock, flags);
50945 return -EBUSY;
50946 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50947 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50948
50949 /* return error if TTY interface open */
50950 - if (info->port.count)
50951 + if (atomic_read(&info->port.count))
50952 return -EBUSY;
50953
50954 if (cmd != SIOCWANDEV)
50955 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
50956 index c359a91..959fc26 100644
50957 --- a/drivers/tty/synclink_gt.c
50958 +++ b/drivers/tty/synclink_gt.c
50959 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50960 tty->driver_data = info;
50961 info->port.tty = tty;
50962
50963 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
50964 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
50965
50966 /* If port is closing, signal caller to try again */
50967 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50968 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50969 mutex_unlock(&info->port.mutex);
50970 goto cleanup;
50971 }
50972 - info->port.count++;
50973 + atomic_inc(&info->port.count);
50974 spin_unlock_irqrestore(&info->netlock, flags);
50975
50976 - if (info->port.count == 1) {
50977 + if (atomic_read(&info->port.count) == 1) {
50978 /* 1st open on this device, init hardware */
50979 retval = startup(info);
50980 if (retval < 0) {
50981 @@ -715,8 +715,8 @@ cleanup:
50982 if (retval) {
50983 if (tty->count == 1)
50984 info->port.tty = NULL; /* tty layer will release tty struct */
50985 - if(info->port.count)
50986 - info->port.count--;
50987 + if(atomic_read(&info->port.count))
50988 + atomic_dec(&info->port.count);
50989 }
50990
50991 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
50992 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50993
50994 if (sanity_check(info, tty->name, "close"))
50995 return;
50996 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
50997 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
50998
50999 if (tty_port_close_start(&info->port, tty, filp) == 0)
51000 goto cleanup;
51001 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51002 tty_port_close_end(&info->port, tty);
51003 info->port.tty = NULL;
51004 cleanup:
51005 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51006 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51007 }
51008
51009 static void hangup(struct tty_struct *tty)
51010 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51011 shutdown(info);
51012
51013 spin_lock_irqsave(&info->port.lock, flags);
51014 - info->port.count = 0;
51015 + atomic_set(&info->port.count, 0);
51016 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51017 info->port.tty = NULL;
51018 spin_unlock_irqrestore(&info->port.lock, flags);
51019 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51020 unsigned short new_crctype;
51021
51022 /* return error if TTY interface open */
51023 - if (info->port.count)
51024 + if (atomic_read(&info->port.count))
51025 return -EBUSY;
51026
51027 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51028 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51029
51030 /* arbitrate between network and tty opens */
51031 spin_lock_irqsave(&info->netlock, flags);
51032 - if (info->port.count != 0 || info->netcount != 0) {
51033 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51034 DBGINFO(("%s hdlc_open busy\n", dev->name));
51035 spin_unlock_irqrestore(&info->netlock, flags);
51036 return -EBUSY;
51037 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51038 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51039
51040 /* return error if TTY interface open */
51041 - if (info->port.count)
51042 + if (atomic_read(&info->port.count))
51043 return -EBUSY;
51044
51045 if (cmd != SIOCWANDEV)
51046 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51047 if (port == NULL)
51048 continue;
51049 spin_lock(&port->lock);
51050 - if ((port->port.count || port->netcount) &&
51051 + if ((atomic_read(&port->port.count) || port->netcount) &&
51052 port->pending_bh && !port->bh_running &&
51053 !port->bh_requested) {
51054 DBGISR(("%s bh queued\n", port->device_name));
51055 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51056 spin_lock_irqsave(&info->lock, flags);
51057 if (!tty_hung_up_p(filp)) {
51058 extra_count = true;
51059 - port->count--;
51060 + atomic_dec(&port->count);
51061 }
51062 spin_unlock_irqrestore(&info->lock, flags);
51063 port->blocked_open++;
51064 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51065 remove_wait_queue(&port->open_wait, &wait);
51066
51067 if (extra_count)
51068 - port->count++;
51069 + atomic_inc(&port->count);
51070 port->blocked_open--;
51071
51072 if (!retval)
51073 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51074 index 144202e..4ccb07d 100644
51075 --- a/drivers/tty/synclinkmp.c
51076 +++ b/drivers/tty/synclinkmp.c
51077 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51078
51079 if (debug_level >= DEBUG_LEVEL_INFO)
51080 printk("%s(%d):%s open(), old ref count = %d\n",
51081 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51082 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51083
51084 /* If port is closing, signal caller to try again */
51085 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51086 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51087 spin_unlock_irqrestore(&info->netlock, flags);
51088 goto cleanup;
51089 }
51090 - info->port.count++;
51091 + atomic_inc(&info->port.count);
51092 spin_unlock_irqrestore(&info->netlock, flags);
51093
51094 - if (info->port.count == 1) {
51095 + if (atomic_read(&info->port.count) == 1) {
51096 /* 1st open on this device, init hardware */
51097 retval = startup(info);
51098 if (retval < 0)
51099 @@ -796,8 +796,8 @@ cleanup:
51100 if (retval) {
51101 if (tty->count == 1)
51102 info->port.tty = NULL; /* tty layer will release tty struct */
51103 - if(info->port.count)
51104 - info->port.count--;
51105 + if(atomic_read(&info->port.count))
51106 + atomic_dec(&info->port.count);
51107 }
51108
51109 return retval;
51110 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51111
51112 if (debug_level >= DEBUG_LEVEL_INFO)
51113 printk("%s(%d):%s close() entry, count=%d\n",
51114 - __FILE__,__LINE__, info->device_name, info->port.count);
51115 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51116
51117 if (tty_port_close_start(&info->port, tty, filp) == 0)
51118 goto cleanup;
51119 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51120 cleanup:
51121 if (debug_level >= DEBUG_LEVEL_INFO)
51122 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51123 - tty->driver->name, info->port.count);
51124 + tty->driver->name, atomic_read(&info->port.count));
51125 }
51126
51127 /* Called by tty_hangup() when a hangup is signaled.
51128 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51129 shutdown(info);
51130
51131 spin_lock_irqsave(&info->port.lock, flags);
51132 - info->port.count = 0;
51133 + atomic_set(&info->port.count, 0);
51134 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51135 info->port.tty = NULL;
51136 spin_unlock_irqrestore(&info->port.lock, flags);
51137 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51138 unsigned short new_crctype;
51139
51140 /* return error if TTY interface open */
51141 - if (info->port.count)
51142 + if (atomic_read(&info->port.count))
51143 return -EBUSY;
51144
51145 switch (encoding)
51146 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51147
51148 /* arbitrate between network and tty opens */
51149 spin_lock_irqsave(&info->netlock, flags);
51150 - if (info->port.count != 0 || info->netcount != 0) {
51151 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51152 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51153 spin_unlock_irqrestore(&info->netlock, flags);
51154 return -EBUSY;
51155 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51156 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51157
51158 /* return error if TTY interface open */
51159 - if (info->port.count)
51160 + if (atomic_read(&info->port.count))
51161 return -EBUSY;
51162
51163 if (cmd != SIOCWANDEV)
51164 @@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51165 * do not request bottom half processing if the
51166 * device is not open in a normal mode.
51167 */
51168 - if ( port && (port->port.count || port->netcount) &&
51169 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51170 port->pending_bh && !port->bh_running &&
51171 !port->bh_requested ) {
51172 if ( debug_level >= DEBUG_LEVEL_ISR )
51173 @@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51174
51175 if (debug_level >= DEBUG_LEVEL_INFO)
51176 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51177 - __FILE__,__LINE__, tty->driver->name, port->count );
51178 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51179
51180 spin_lock_irqsave(&info->lock, flags);
51181 if (!tty_hung_up_p(filp)) {
51182 extra_count = true;
51183 - port->count--;
51184 + atomic_dec(&port->count);
51185 }
51186 spin_unlock_irqrestore(&info->lock, flags);
51187 port->blocked_open++;
51188 @@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51189
51190 if (debug_level >= DEBUG_LEVEL_INFO)
51191 printk("%s(%d):%s block_til_ready() count=%d\n",
51192 - __FILE__,__LINE__, tty->driver->name, port->count );
51193 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51194
51195 tty_unlock(tty);
51196 schedule();
51197 @@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51198 remove_wait_queue(&port->open_wait, &wait);
51199
51200 if (extra_count)
51201 - port->count++;
51202 + atomic_inc(&port->count);
51203 port->blocked_open--;
51204
51205 if (debug_level >= DEBUG_LEVEL_INFO)
51206 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51207 - __FILE__,__LINE__, tty->driver->name, port->count );
51208 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51209
51210 if (!retval)
51211 port->flags |= ASYNC_NORMAL_ACTIVE;
51212 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51213 index ce396ec..04a37be 100644
51214 --- a/drivers/tty/sysrq.c
51215 +++ b/drivers/tty/sysrq.c
51216 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51217 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51218 size_t count, loff_t *ppos)
51219 {
51220 - if (count) {
51221 + if (count && capable(CAP_SYS_ADMIN)) {
51222 char c;
51223
51224 if (get_user(c, buf))
51225 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51226 index c74a00a..02cf211a 100644
51227 --- a/drivers/tty/tty_io.c
51228 +++ b/drivers/tty/tty_io.c
51229 @@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51230
51231 void tty_default_fops(struct file_operations *fops)
51232 {
51233 - *fops = tty_fops;
51234 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51235 }
51236
51237 /*
51238 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51239 index 2d822aa..a566234 100644
51240 --- a/drivers/tty/tty_ldisc.c
51241 +++ b/drivers/tty/tty_ldisc.c
51242 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51243 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51244 tty_ldiscs[disc] = new_ldisc;
51245 new_ldisc->num = disc;
51246 - new_ldisc->refcount = 0;
51247 + atomic_set(&new_ldisc->refcount, 0);
51248 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51249
51250 return ret;
51251 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51252 return -EINVAL;
51253
51254 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51255 - if (tty_ldiscs[disc]->refcount)
51256 + if (atomic_read(&tty_ldiscs[disc]->refcount))
51257 ret = -EBUSY;
51258 else
51259 tty_ldiscs[disc] = NULL;
51260 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51261 if (ldops) {
51262 ret = ERR_PTR(-EAGAIN);
51263 if (try_module_get(ldops->owner)) {
51264 - ldops->refcount++;
51265 + atomic_inc(&ldops->refcount);
51266 ret = ldops;
51267 }
51268 }
51269 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51270 unsigned long flags;
51271
51272 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51273 - ldops->refcount--;
51274 + atomic_dec(&ldops->refcount);
51275 module_put(ldops->owner);
51276 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51277 }
51278 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51279 index 3f746c8..2f2fcaa 100644
51280 --- a/drivers/tty/tty_port.c
51281 +++ b/drivers/tty/tty_port.c
51282 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51283 unsigned long flags;
51284
51285 spin_lock_irqsave(&port->lock, flags);
51286 - port->count = 0;
51287 + atomic_set(&port->count, 0);
51288 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51289 tty = port->tty;
51290 if (tty)
51291 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51292 /* The port lock protects the port counts */
51293 spin_lock_irqsave(&port->lock, flags);
51294 if (!tty_hung_up_p(filp))
51295 - port->count--;
51296 + atomic_dec(&port->count);
51297 port->blocked_open++;
51298 spin_unlock_irqrestore(&port->lock, flags);
51299
51300 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51301 we must not mess that up further */
51302 spin_lock_irqsave(&port->lock, flags);
51303 if (!tty_hung_up_p(filp))
51304 - port->count++;
51305 + atomic_inc(&port->count);
51306 port->blocked_open--;
51307 if (retval == 0)
51308 port->flags |= ASYNC_NORMAL_ACTIVE;
51309 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51310 return 0;
51311 }
51312
51313 - if (tty->count == 1 && port->count != 1) {
51314 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
51315 printk(KERN_WARNING
51316 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51317 - port->count);
51318 - port->count = 1;
51319 + atomic_read(&port->count));
51320 + atomic_set(&port->count, 1);
51321 }
51322 - if (--port->count < 0) {
51323 + if (atomic_dec_return(&port->count) < 0) {
51324 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51325 - port->count);
51326 - port->count = 0;
51327 + atomic_read(&port->count));
51328 + atomic_set(&port->count, 0);
51329 }
51330
51331 - if (port->count) {
51332 + if (atomic_read(&port->count)) {
51333 spin_unlock_irqrestore(&port->lock, flags);
51334 return 0;
51335 }
51336 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51337 {
51338 spin_lock_irq(&port->lock);
51339 if (!tty_hung_up_p(filp))
51340 - ++port->count;
51341 + atomic_inc(&port->count);
51342 spin_unlock_irq(&port->lock);
51343 tty_port_tty_set(port, tty);
51344
51345 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51346 index d0e3a44..5f8b754 100644
51347 --- a/drivers/tty/vt/keyboard.c
51348 +++ b/drivers/tty/vt/keyboard.c
51349 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51350 kbd->kbdmode == VC_OFF) &&
51351 value != KVAL(K_SAK))
51352 return; /* SAK is allowed even in raw mode */
51353 +
51354 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51355 + {
51356 + void *func = fn_handler[value];
51357 + if (func == fn_show_state || func == fn_show_ptregs ||
51358 + func == fn_show_mem)
51359 + return;
51360 + }
51361 +#endif
51362 +
51363 fn_handler[value](vc);
51364 }
51365
51366 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51367 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51368 return -EFAULT;
51369
51370 - if (!capable(CAP_SYS_TTY_CONFIG))
51371 - perm = 0;
51372 -
51373 switch (cmd) {
51374 case KDGKBENT:
51375 /* Ensure another thread doesn't free it under us */
51376 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51377 spin_unlock_irqrestore(&kbd_event_lock, flags);
51378 return put_user(val, &user_kbe->kb_value);
51379 case KDSKBENT:
51380 + if (!capable(CAP_SYS_TTY_CONFIG))
51381 + perm = 0;
51382 +
51383 if (!perm)
51384 return -EPERM;
51385 if (!i && v == K_NOSUCHMAP) {
51386 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51387 int i, j, k;
51388 int ret;
51389
51390 - if (!capable(CAP_SYS_TTY_CONFIG))
51391 - perm = 0;
51392 -
51393 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51394 if (!kbs) {
51395 ret = -ENOMEM;
51396 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51397 kfree(kbs);
51398 return ((p && *p) ? -EOVERFLOW : 0);
51399 case KDSKBSENT:
51400 + if (!capable(CAP_SYS_TTY_CONFIG))
51401 + perm = 0;
51402 +
51403 if (!perm) {
51404 ret = -EPERM;
51405 goto reterr;
51406 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51407 index a673e5b..36e5d32 100644
51408 --- a/drivers/uio/uio.c
51409 +++ b/drivers/uio/uio.c
51410 @@ -25,6 +25,7 @@
51411 #include <linux/kobject.h>
51412 #include <linux/cdev.h>
51413 #include <linux/uio_driver.h>
51414 +#include <asm/local.h>
51415
51416 #define UIO_MAX_DEVICES (1U << MINORBITS)
51417
51418 @@ -32,7 +33,7 @@ struct uio_device {
51419 struct module *owner;
51420 struct device *dev;
51421 int minor;
51422 - atomic_t event;
51423 + atomic_unchecked_t event;
51424 struct fasync_struct *async_queue;
51425 wait_queue_head_t wait;
51426 struct uio_info *info;
51427 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51428 struct device_attribute *attr, char *buf)
51429 {
51430 struct uio_device *idev = dev_get_drvdata(dev);
51431 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51432 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51433 }
51434 static DEVICE_ATTR_RO(event);
51435
51436 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51437 {
51438 struct uio_device *idev = info->uio_dev;
51439
51440 - atomic_inc(&idev->event);
51441 + atomic_inc_unchecked(&idev->event);
51442 wake_up_interruptible(&idev->wait);
51443 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51444 }
51445 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51446 }
51447
51448 listener->dev = idev;
51449 - listener->event_count = atomic_read(&idev->event);
51450 + listener->event_count = atomic_read_unchecked(&idev->event);
51451 filep->private_data = listener;
51452
51453 if (idev->info->open) {
51454 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51455 return -EIO;
51456
51457 poll_wait(filep, &idev->wait, wait);
51458 - if (listener->event_count != atomic_read(&idev->event))
51459 + if (listener->event_count != atomic_read_unchecked(&idev->event))
51460 return POLLIN | POLLRDNORM;
51461 return 0;
51462 }
51463 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51464 do {
51465 set_current_state(TASK_INTERRUPTIBLE);
51466
51467 - event_count = atomic_read(&idev->event);
51468 + event_count = atomic_read_unchecked(&idev->event);
51469 if (event_count != listener->event_count) {
51470 if (copy_to_user(buf, &event_count, count))
51471 retval = -EFAULT;
51472 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51473 static int uio_find_mem_index(struct vm_area_struct *vma)
51474 {
51475 struct uio_device *idev = vma->vm_private_data;
51476 + unsigned long size;
51477
51478 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51479 - if (idev->info->mem[vma->vm_pgoff].size == 0)
51480 + size = idev->info->mem[vma->vm_pgoff].size;
51481 + if (size == 0)
51482 + return -1;
51483 + if (vma->vm_end - vma->vm_start > size)
51484 return -1;
51485 return (int)vma->vm_pgoff;
51486 }
51487 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51488 idev->owner = owner;
51489 idev->info = info;
51490 init_waitqueue_head(&idev->wait);
51491 - atomic_set(&idev->event, 0);
51492 + atomic_set_unchecked(&idev->event, 0);
51493
51494 ret = uio_get_minor(idev);
51495 if (ret)
51496 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51497 index 813d4d3..a71934f 100644
51498 --- a/drivers/usb/atm/cxacru.c
51499 +++ b/drivers/usb/atm/cxacru.c
51500 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51501 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51502 if (ret < 2)
51503 return -EINVAL;
51504 - if (index < 0 || index > 0x7f)
51505 + if (index > 0x7f)
51506 return -EINVAL;
51507 pos += tmp;
51508
51509 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51510 index dada014..1d0d517 100644
51511 --- a/drivers/usb/atm/usbatm.c
51512 +++ b/drivers/usb/atm/usbatm.c
51513 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51514 if (printk_ratelimit())
51515 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51516 __func__, vpi, vci);
51517 - atomic_inc(&vcc->stats->rx_err);
51518 + atomic_inc_unchecked(&vcc->stats->rx_err);
51519 return;
51520 }
51521
51522 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51523 if (length > ATM_MAX_AAL5_PDU) {
51524 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51525 __func__, length, vcc);
51526 - atomic_inc(&vcc->stats->rx_err);
51527 + atomic_inc_unchecked(&vcc->stats->rx_err);
51528 goto out;
51529 }
51530
51531 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51532 if (sarb->len < pdu_length) {
51533 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51534 __func__, pdu_length, sarb->len, vcc);
51535 - atomic_inc(&vcc->stats->rx_err);
51536 + atomic_inc_unchecked(&vcc->stats->rx_err);
51537 goto out;
51538 }
51539
51540 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51541 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51542 __func__, vcc);
51543 - atomic_inc(&vcc->stats->rx_err);
51544 + atomic_inc_unchecked(&vcc->stats->rx_err);
51545 goto out;
51546 }
51547
51548 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51549 if (printk_ratelimit())
51550 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51551 __func__, length);
51552 - atomic_inc(&vcc->stats->rx_drop);
51553 + atomic_inc_unchecked(&vcc->stats->rx_drop);
51554 goto out;
51555 }
51556
51557 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51558
51559 vcc->push(vcc, skb);
51560
51561 - atomic_inc(&vcc->stats->rx);
51562 + atomic_inc_unchecked(&vcc->stats->rx);
51563 out:
51564 skb_trim(sarb, 0);
51565 }
51566 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51567 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51568
51569 usbatm_pop(vcc, skb);
51570 - atomic_inc(&vcc->stats->tx);
51571 + atomic_inc_unchecked(&vcc->stats->tx);
51572
51573 skb = skb_dequeue(&instance->sndqueue);
51574 }
51575 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
51576 if (!left--)
51577 return sprintf(page,
51578 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51579 - atomic_read(&atm_dev->stats.aal5.tx),
51580 - atomic_read(&atm_dev->stats.aal5.tx_err),
51581 - atomic_read(&atm_dev->stats.aal5.rx),
51582 - atomic_read(&atm_dev->stats.aal5.rx_err),
51583 - atomic_read(&atm_dev->stats.aal5.rx_drop));
51584 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51585 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51586 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51587 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51588 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51589
51590 if (!left--) {
51591 if (instance->disconnected)
51592 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51593 index 2a3bbdf..91d72cf 100644
51594 --- a/drivers/usb/core/devices.c
51595 +++ b/drivers/usb/core/devices.c
51596 @@ -126,7 +126,7 @@ static const char format_endpt[] =
51597 * time it gets called.
51598 */
51599 static struct device_connect_event {
51600 - atomic_t count;
51601 + atomic_unchecked_t count;
51602 wait_queue_head_t wait;
51603 } device_event = {
51604 .count = ATOMIC_INIT(1),
51605 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51606
51607 void usbfs_conn_disc_event(void)
51608 {
51609 - atomic_add(2, &device_event.count);
51610 + atomic_add_unchecked(2, &device_event.count);
51611 wake_up(&device_event.wait);
51612 }
51613
51614 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51615
51616 poll_wait(file, &device_event.wait, wait);
51617
51618 - event_count = atomic_read(&device_event.count);
51619 + event_count = atomic_read_unchecked(&device_event.count);
51620 if (file->f_version != event_count) {
51621 file->f_version = event_count;
51622 return POLLIN | POLLRDNORM;
51623 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51624 index 90e18f6..5eeda46 100644
51625 --- a/drivers/usb/core/devio.c
51626 +++ b/drivers/usb/core/devio.c
51627 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51628 struct dev_state *ps = file->private_data;
51629 struct usb_device *dev = ps->dev;
51630 ssize_t ret = 0;
51631 - unsigned len;
51632 + size_t len;
51633 loff_t pos;
51634 int i;
51635
51636 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51637 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51638 struct usb_config_descriptor *config =
51639 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51640 - unsigned int length = le16_to_cpu(config->wTotalLength);
51641 + size_t length = le16_to_cpu(config->wTotalLength);
51642
51643 if (*ppos < pos + length) {
51644
51645 /* The descriptor may claim to be longer than it
51646 * really is. Here is the actual allocated length. */
51647 - unsigned alloclen =
51648 + size_t alloclen =
51649 le16_to_cpu(dev->config[i].desc.wTotalLength);
51650
51651 - len = length - (*ppos - pos);
51652 + len = length + pos - *ppos;
51653 if (len > nbytes)
51654 len = nbytes;
51655
51656 /* Simply don't write (skip over) unallocated parts */
51657 if (alloclen > (*ppos - pos)) {
51658 - alloclen -= (*ppos - pos);
51659 + alloclen = alloclen + pos - *ppos;
51660 if (copy_to_user(buf,
51661 dev->rawdescriptors[i] + (*ppos - pos),
51662 min(len, alloclen))) {
51663 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51664 index 2518c32..1c201bb 100644
51665 --- a/drivers/usb/core/hcd.c
51666 +++ b/drivers/usb/core/hcd.c
51667 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51668 */
51669 usb_get_urb(urb);
51670 atomic_inc(&urb->use_count);
51671 - atomic_inc(&urb->dev->urbnum);
51672 + atomic_inc_unchecked(&urb->dev->urbnum);
51673 usbmon_urb_submit(&hcd->self, urb);
51674
51675 /* NOTE requirements on root-hub callers (usbfs and the hub
51676 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51677 urb->hcpriv = NULL;
51678 INIT_LIST_HEAD(&urb->urb_list);
51679 atomic_dec(&urb->use_count);
51680 - atomic_dec(&urb->dev->urbnum);
51681 + atomic_dec_unchecked(&urb->dev->urbnum);
51682 if (atomic_read(&urb->reject))
51683 wake_up(&usb_kill_urb_queue);
51684 usb_put_urb(urb);
51685 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51686 index 64ea219..dbc1780 100644
51687 --- a/drivers/usb/core/hub.c
51688 +++ b/drivers/usb/core/hub.c
51689 @@ -27,6 +27,7 @@
51690 #include <linux/freezer.h>
51691 #include <linux/random.h>
51692 #include <linux/pm_qos.h>
51693 +#include <linux/grsecurity.h>
51694
51695 #include <asm/uaccess.h>
51696 #include <asm/byteorder.h>
51697 @@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51698 goto done;
51699 return;
51700 }
51701 +
51702 + if (gr_handle_new_usb())
51703 + goto done;
51704 +
51705 if (hub_is_superspeed(hub->hdev))
51706 unit_load = 150;
51707 else
51708 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51709 index f829a1a..e6c334a 100644
51710 --- a/drivers/usb/core/message.c
51711 +++ b/drivers/usb/core/message.c
51712 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51713 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51714 * error number.
51715 */
51716 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51717 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51718 __u8 requesttype, __u16 value, __u16 index, void *data,
51719 __u16 size, int timeout)
51720 {
51721 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51722 * If successful, 0. Otherwise a negative error number. The number of actual
51723 * bytes transferred will be stored in the @actual_length paramater.
51724 */
51725 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51726 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51727 void *data, int len, int *actual_length, int timeout)
51728 {
51729 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51730 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51731 * bytes transferred will be stored in the @actual_length parameter.
51732 *
51733 */
51734 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51735 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51736 void *data, int len, int *actual_length, int timeout)
51737 {
51738 struct urb *urb;
51739 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51740 index 1236c60..d47a51c 100644
51741 --- a/drivers/usb/core/sysfs.c
51742 +++ b/drivers/usb/core/sysfs.c
51743 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51744 struct usb_device *udev;
51745
51746 udev = to_usb_device(dev);
51747 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51748 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51749 }
51750 static DEVICE_ATTR_RO(urbnum);
51751
51752 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51753 index 4d11449..f4ccabf 100644
51754 --- a/drivers/usb/core/usb.c
51755 +++ b/drivers/usb/core/usb.c
51756 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51757 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51758 dev->state = USB_STATE_ATTACHED;
51759 dev->lpm_disable_count = 1;
51760 - atomic_set(&dev->urbnum, 0);
51761 + atomic_set_unchecked(&dev->urbnum, 0);
51762
51763 INIT_LIST_HEAD(&dev->ep0.urb_list);
51764 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51765 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51766 index 2da0a5a..4870e09 100644
51767 --- a/drivers/usb/dwc3/gadget.c
51768 +++ b/drivers/usb/dwc3/gadget.c
51769 @@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51770 if (!usb_endpoint_xfer_isoc(desc))
51771 return 0;
51772
51773 - memset(&trb_link, 0, sizeof(trb_link));
51774 -
51775 /* Link TRB for ISOC. The HWO bit is never reset */
51776 trb_st_hw = &dep->trb_pool[0];
51777
51778 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51779 index 8cfc319..4868255 100644
51780 --- a/drivers/usb/early/ehci-dbgp.c
51781 +++ b/drivers/usb/early/ehci-dbgp.c
51782 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51783
51784 #ifdef CONFIG_KGDB
51785 static struct kgdb_io kgdbdbgp_io_ops;
51786 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51787 +static struct kgdb_io kgdbdbgp_io_ops_console;
51788 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51789 #else
51790 #define dbgp_kgdb_mode (0)
51791 #endif
51792 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51793 .write_char = kgdbdbgp_write_char,
51794 };
51795
51796 +static struct kgdb_io kgdbdbgp_io_ops_console = {
51797 + .name = "kgdbdbgp",
51798 + .read_char = kgdbdbgp_read_char,
51799 + .write_char = kgdbdbgp_write_char,
51800 + .is_console = 1
51801 +};
51802 +
51803 static int kgdbdbgp_wait_time;
51804
51805 static int __init kgdbdbgp_parse_config(char *str)
51806 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51807 ptr++;
51808 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51809 }
51810 - kgdb_register_io_module(&kgdbdbgp_io_ops);
51811 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51812 + if (early_dbgp_console.index != -1)
51813 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51814 + else
51815 + kgdb_register_io_module(&kgdbdbgp_io_ops);
51816
51817 return 0;
51818 }
51819 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51820 index b369292..9f3ba40 100644
51821 --- a/drivers/usb/gadget/u_serial.c
51822 +++ b/drivers/usb/gadget/u_serial.c
51823 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51824 spin_lock_irq(&port->port_lock);
51825
51826 /* already open? Great. */
51827 - if (port->port.count) {
51828 + if (atomic_read(&port->port.count)) {
51829 status = 0;
51830 - port->port.count++;
51831 + atomic_inc(&port->port.count);
51832
51833 /* currently opening/closing? wait ... */
51834 } else if (port->openclose) {
51835 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51836 tty->driver_data = port;
51837 port->port.tty = tty;
51838
51839 - port->port.count = 1;
51840 + atomic_set(&port->port.count, 1);
51841 port->openclose = false;
51842
51843 /* if connected, start the I/O stream */
51844 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51845
51846 spin_lock_irq(&port->port_lock);
51847
51848 - if (port->port.count != 1) {
51849 - if (port->port.count == 0)
51850 + if (atomic_read(&port->port.count) != 1) {
51851 + if (atomic_read(&port->port.count) == 0)
51852 WARN_ON(1);
51853 else
51854 - --port->port.count;
51855 + atomic_dec(&port->port.count);
51856 goto exit;
51857 }
51858
51859 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51860 * and sleep if necessary
51861 */
51862 port->openclose = true;
51863 - port->port.count = 0;
51864 + atomic_set(&port->port.count, 0);
51865
51866 gser = port->port_usb;
51867 if (gser && gser->disconnect)
51868 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
51869 int cond;
51870
51871 spin_lock_irq(&port->port_lock);
51872 - cond = (port->port.count == 0) && !port->openclose;
51873 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
51874 spin_unlock_irq(&port->port_lock);
51875 return cond;
51876 }
51877 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
51878 /* if it's already open, start I/O ... and notify the serial
51879 * protocol about open/close status (connect/disconnect).
51880 */
51881 - if (port->port.count) {
51882 + if (atomic_read(&port->port.count)) {
51883 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
51884 gs_start_io(port);
51885 if (gser->connect)
51886 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
51887
51888 port->port_usb = NULL;
51889 gser->ioport = NULL;
51890 - if (port->port.count > 0 || port->openclose) {
51891 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
51892 wake_up_interruptible(&port->drain_wait);
51893 if (port->port.tty)
51894 tty_hangup(port->port.tty);
51895 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
51896
51897 /* finally, free any unused/unusable I/O buffers */
51898 spin_lock_irqsave(&port->port_lock, flags);
51899 - if (port->port.count == 0 && !port->openclose)
51900 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
51901 gs_buf_free(&port->port_write_buf);
51902 gs_free_requests(gser->out, &port->read_pool, NULL);
51903 gs_free_requests(gser->out, &port->read_queue, NULL);
51904 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
51905 index 7ae0c4d..35521b7 100644
51906 --- a/drivers/usb/host/ehci-hub.c
51907 +++ b/drivers/usb/host/ehci-hub.c
51908 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
51909 urb->transfer_flags = URB_DIR_IN;
51910 usb_get_urb(urb);
51911 atomic_inc(&urb->use_count);
51912 - atomic_inc(&urb->dev->urbnum);
51913 + atomic_inc_unchecked(&urb->dev->urbnum);
51914 urb->setup_dma = dma_map_single(
51915 hcd->self.controller,
51916 urb->setup_packet,
51917 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
51918 urb->status = -EINPROGRESS;
51919 usb_get_urb(urb);
51920 atomic_inc(&urb->use_count);
51921 - atomic_inc(&urb->dev->urbnum);
51922 + atomic_inc_unchecked(&urb->dev->urbnum);
51923 retval = submit_single_step_set_feature(hcd, urb, 0);
51924 if (!retval && !wait_for_completion_timeout(&done,
51925 msecs_to_jiffies(2000))) {
51926 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
51927 index ba6a5d6..f88f7f3 100644
51928 --- a/drivers/usb/misc/appledisplay.c
51929 +++ b/drivers/usb/misc/appledisplay.c
51930 @@ -83,7 +83,7 @@ struct appledisplay {
51931 spinlock_t lock;
51932 };
51933
51934 -static atomic_t count_displays = ATOMIC_INIT(0);
51935 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
51936 static struct workqueue_struct *wq;
51937
51938 static void appledisplay_complete(struct urb *urb)
51939 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
51940
51941 /* Register backlight device */
51942 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
51943 - atomic_inc_return(&count_displays) - 1);
51944 + atomic_inc_return_unchecked(&count_displays) - 1);
51945 memset(&props, 0, sizeof(struct backlight_properties));
51946 props.type = BACKLIGHT_RAW;
51947 props.max_brightness = 0xff;
51948 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
51949 index 8d7fc48..01c4986 100644
51950 --- a/drivers/usb/serial/console.c
51951 +++ b/drivers/usb/serial/console.c
51952 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
51953
51954 info->port = port;
51955
51956 - ++port->port.count;
51957 + atomic_inc(&port->port.count);
51958 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
51959 if (serial->type->set_termios) {
51960 /*
51961 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
51962 }
51963 /* Now that any required fake tty operations are completed restore
51964 * the tty port count */
51965 - --port->port.count;
51966 + atomic_dec(&port->port.count);
51967 /* The console is special in terms of closing the device so
51968 * indicate this port is now acting as a system console. */
51969 port->port.console = 1;
51970 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
51971 free_tty:
51972 kfree(tty);
51973 reset_open_count:
51974 - port->port.count = 0;
51975 + atomic_set(&port->port.count, 0);
51976 usb_autopm_put_interface(serial->interface);
51977 error_get_interface:
51978 usb_serial_put(serial);
51979 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
51980 static void usb_console_write(struct console *co,
51981 const char *buf, unsigned count)
51982 {
51983 - static struct usbcons_info *info = &usbcons_info;
51984 + struct usbcons_info *info = &usbcons_info;
51985 struct usb_serial_port *port = info->port;
51986 struct usb_serial *serial;
51987 int retval = -ENODEV;
51988 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
51989 index 75f70f0..d467e1a 100644
51990 --- a/drivers/usb/storage/usb.h
51991 +++ b/drivers/usb/storage/usb.h
51992 @@ -63,7 +63,7 @@ struct us_unusual_dev {
51993 __u8 useProtocol;
51994 __u8 useTransport;
51995 int (*initFunction)(struct us_data *);
51996 -};
51997 +} __do_const;
51998
51999
52000 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52001 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52002 index a2ef84b..aa7c2b8 100644
52003 --- a/drivers/usb/wusbcore/wa-hc.h
52004 +++ b/drivers/usb/wusbcore/wa-hc.h
52005 @@ -225,7 +225,7 @@ struct wahc {
52006 spinlock_t xfer_list_lock;
52007 struct work_struct xfer_enqueue_work;
52008 struct work_struct xfer_error_work;
52009 - atomic_t xfer_id_count;
52010 + atomic_unchecked_t xfer_id_count;
52011
52012 kernel_ulong_t quirks;
52013 };
52014 @@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52015 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52016 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52017 wa->dto_in_use = 0;
52018 - atomic_set(&wa->xfer_id_count, 1);
52019 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52020 }
52021
52022 /**
52023 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52024 index 3cd96e9..bd7c58d 100644
52025 --- a/drivers/usb/wusbcore/wa-xfer.c
52026 +++ b/drivers/usb/wusbcore/wa-xfer.c
52027 @@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52028 */
52029 static void wa_xfer_id_init(struct wa_xfer *xfer)
52030 {
52031 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52032 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52033 }
52034
52035 /* Return the xfer's ID. */
52036 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52037 index 21271d8..45b55a0 100644
52038 --- a/drivers/vfio/vfio.c
52039 +++ b/drivers/vfio/vfio.c
52040 @@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52041 return 0;
52042
52043 /* TODO Prevent device auto probing */
52044 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52045 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52046 iommu_group_id(group->iommu_group));
52047
52048 return 0;
52049 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52050 index 5174eba..451e6bc 100644
52051 --- a/drivers/vhost/vringh.c
52052 +++ b/drivers/vhost/vringh.c
52053 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52054 /* Userspace access helpers: in this case, addresses are really userspace. */
52055 static inline int getu16_user(u16 *val, const u16 *p)
52056 {
52057 - return get_user(*val, (__force u16 __user *)p);
52058 + return get_user(*val, (u16 __force_user *)p);
52059 }
52060
52061 static inline int putu16_user(u16 *p, u16 val)
52062 {
52063 - return put_user(val, (__force u16 __user *)p);
52064 + return put_user(val, (u16 __force_user *)p);
52065 }
52066
52067 static inline int copydesc_user(void *dst, const void *src, size_t len)
52068 {
52069 - return copy_from_user(dst, (__force void __user *)src, len) ?
52070 + return copy_from_user(dst, (void __force_user *)src, len) ?
52071 -EFAULT : 0;
52072 }
52073
52074 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52075 const struct vring_used_elem *src,
52076 unsigned int num)
52077 {
52078 - return copy_to_user((__force void __user *)dst, src,
52079 + return copy_to_user((void __force_user *)dst, src,
52080 sizeof(*dst) * num) ? -EFAULT : 0;
52081 }
52082
52083 static inline int xfer_from_user(void *src, void *dst, size_t len)
52084 {
52085 - return copy_from_user(dst, (__force void __user *)src, len) ?
52086 + return copy_from_user(dst, (void __force_user *)src, len) ?
52087 -EFAULT : 0;
52088 }
52089
52090 static inline int xfer_to_user(void *dst, void *src, size_t len)
52091 {
52092 - return copy_to_user((__force void __user *)dst, src, len) ?
52093 + return copy_to_user((void __force_user *)dst, src, len) ?
52094 -EFAULT : 0;
52095 }
52096
52097 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52098 vrh->last_used_idx = 0;
52099 vrh->vring.num = num;
52100 /* vring expects kernel addresses, but only used via accessors. */
52101 - vrh->vring.desc = (__force struct vring_desc *)desc;
52102 - vrh->vring.avail = (__force struct vring_avail *)avail;
52103 - vrh->vring.used = (__force struct vring_used *)used;
52104 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52105 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52106 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52107 return 0;
52108 }
52109 EXPORT_SYMBOL(vringh_init_user);
52110 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52111
52112 static inline int putu16_kern(u16 *p, u16 val)
52113 {
52114 - ACCESS_ONCE(*p) = val;
52115 + ACCESS_ONCE_RW(*p) = val;
52116 return 0;
52117 }
52118
52119 diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52120 index 1b0b233..6f34c2c 100644
52121 --- a/drivers/video/arcfb.c
52122 +++ b/drivers/video/arcfb.c
52123 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52124 return -ENOSPC;
52125
52126 err = 0;
52127 - if ((count + p) > fbmemlength) {
52128 + if (count > (fbmemlength - p)) {
52129 count = fbmemlength - p;
52130 err = -ENOSPC;
52131 }
52132 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52133 index 52108be..c7c110d 100644
52134 --- a/drivers/video/aty/aty128fb.c
52135 +++ b/drivers/video/aty/aty128fb.c
52136 @@ -149,7 +149,7 @@ enum {
52137 };
52138
52139 /* Must match above enum */
52140 -static char * const r128_family[] = {
52141 +static const char * const r128_family[] = {
52142 "AGP",
52143 "PCI",
52144 "PRO AGP",
52145 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52146 index 28fafbf..ae91651 100644
52147 --- a/drivers/video/aty/atyfb_base.c
52148 +++ b/drivers/video/aty/atyfb_base.c
52149 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52150 par->accel_flags = var->accel_flags; /* hack */
52151
52152 if (var->accel_flags) {
52153 - info->fbops->fb_sync = atyfb_sync;
52154 + pax_open_kernel();
52155 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52156 + pax_close_kernel();
52157 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52158 } else {
52159 - info->fbops->fb_sync = NULL;
52160 + pax_open_kernel();
52161 + *(void **)&info->fbops->fb_sync = NULL;
52162 + pax_close_kernel();
52163 info->flags |= FBINFO_HWACCEL_DISABLED;
52164 }
52165
52166 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52167 index 95ec042..e6affdd 100644
52168 --- a/drivers/video/aty/mach64_cursor.c
52169 +++ b/drivers/video/aty/mach64_cursor.c
52170 @@ -7,6 +7,7 @@
52171 #include <linux/string.h>
52172
52173 #include <asm/io.h>
52174 +#include <asm/pgtable.h>
52175
52176 #ifdef __sparc__
52177 #include <asm/fbio.h>
52178 @@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52179 info->sprite.buf_align = 16; /* and 64 lines tall. */
52180 info->sprite.flags = FB_PIXMAP_IO;
52181
52182 - info->fbops->fb_cursor = atyfb_cursor;
52183 + pax_open_kernel();
52184 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52185 + pax_close_kernel();
52186
52187 return 0;
52188 }
52189 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52190 index 84a110a..96312c3 100644
52191 --- a/drivers/video/backlight/kb3886_bl.c
52192 +++ b/drivers/video/backlight/kb3886_bl.c
52193 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52194 static unsigned long kb3886bl_flags;
52195 #define KB3886BL_SUSPENDED 0x01
52196
52197 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52198 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52199 {
52200 .ident = "Sahara Touch-iT",
52201 .matches = {
52202 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52203 index 900aa4e..6d49418 100644
52204 --- a/drivers/video/fb_defio.c
52205 +++ b/drivers/video/fb_defio.c
52206 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52207
52208 BUG_ON(!fbdefio);
52209 mutex_init(&fbdefio->lock);
52210 - info->fbops->fb_mmap = fb_deferred_io_mmap;
52211 + pax_open_kernel();
52212 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52213 + pax_close_kernel();
52214 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52215 INIT_LIST_HEAD(&fbdefio->pagelist);
52216 if (fbdefio->delay == 0) /* set a default of 1 s */
52217 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52218 page->mapping = NULL;
52219 }
52220
52221 - info->fbops->fb_mmap = NULL;
52222 + *(void **)&info->fbops->fb_mmap = NULL;
52223 mutex_destroy(&fbdefio->lock);
52224 }
52225 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52226 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52227 index 7309ac7..be3c49c 100644
52228 --- a/drivers/video/fbmem.c
52229 +++ b/drivers/video/fbmem.c
52230 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52231 image->dx += image->width + 8;
52232 }
52233 } else if (rotate == FB_ROTATE_UD) {
52234 - for (x = 0; x < num && image->dx >= 0; x++) {
52235 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52236 info->fbops->fb_imageblit(info, image);
52237 image->dx -= image->width + 8;
52238 }
52239 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52240 image->dy += image->height + 8;
52241 }
52242 } else if (rotate == FB_ROTATE_CCW) {
52243 - for (x = 0; x < num && image->dy >= 0; x++) {
52244 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52245 info->fbops->fb_imageblit(info, image);
52246 image->dy -= image->height + 8;
52247 }
52248 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52249 return -EFAULT;
52250 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52251 return -EINVAL;
52252 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52253 + if (con2fb.framebuffer >= FB_MAX)
52254 return -EINVAL;
52255 if (!registered_fb[con2fb.framebuffer])
52256 request_module("fb%d", con2fb.framebuffer);
52257 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52258 __u32 data;
52259 int err;
52260
52261 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52262 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52263
52264 data = (__u32) (unsigned long) fix->smem_start;
52265 err |= put_user(data, &fix32->smem_start);
52266 diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52267 index 130708f..cdac1a9 100644
52268 --- a/drivers/video/hyperv_fb.c
52269 +++ b/drivers/video/hyperv_fb.c
52270 @@ -233,7 +233,7 @@ static uint screen_fb_size;
52271 static inline int synthvid_send(struct hv_device *hdev,
52272 struct synthvid_msg *msg)
52273 {
52274 - static atomic64_t request_id = ATOMIC64_INIT(0);
52275 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52276 int ret;
52277
52278 msg->pipe_hdr.type = PIPE_MSG_DATA;
52279 @@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52280
52281 ret = vmbus_sendpacket(hdev->channel, msg,
52282 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52283 - atomic64_inc_return(&request_id),
52284 + atomic64_inc_return_unchecked(&request_id),
52285 VM_PKT_DATA_INBAND, 0);
52286
52287 if (ret)
52288 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52289 index 7672d2e..b56437f 100644
52290 --- a/drivers/video/i810/i810_accel.c
52291 +++ b/drivers/video/i810/i810_accel.c
52292 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52293 }
52294 }
52295 printk("ringbuffer lockup!!!\n");
52296 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52297 i810_report_error(mmio);
52298 par->dev_flags |= LOCKUP;
52299 info->pixmap.scan_align = 1;
52300 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52301 index 3c14e43..2630570 100644
52302 --- a/drivers/video/logo/logo_linux_clut224.ppm
52303 +++ b/drivers/video/logo/logo_linux_clut224.ppm
52304 @@ -2,1603 +2,1123 @@ P3
52305 # Standard 224-color Linux logo
52306 80 80
52307 255
52308 - 0 0 0 0 0 0 0 0 0 0 0 0
52309 - 0 0 0 0 0 0 0 0 0 0 0 0
52310 - 0 0 0 0 0 0 0 0 0 0 0 0
52311 - 0 0 0 0 0 0 0 0 0 0 0 0
52312 - 0 0 0 0 0 0 0 0 0 0 0 0
52313 - 0 0 0 0 0 0 0 0 0 0 0 0
52314 - 0 0 0 0 0 0 0 0 0 0 0 0
52315 - 0 0 0 0 0 0 0 0 0 0 0 0
52316 - 0 0 0 0 0 0 0 0 0 0 0 0
52317 - 6 6 6 6 6 6 10 10 10 10 10 10
52318 - 10 10 10 6 6 6 6 6 6 6 6 6
52319 - 0 0 0 0 0 0 0 0 0 0 0 0
52320 - 0 0 0 0 0 0 0 0 0 0 0 0
52321 - 0 0 0 0 0 0 0 0 0 0 0 0
52322 - 0 0 0 0 0 0 0 0 0 0 0 0
52323 - 0 0 0 0 0 0 0 0 0 0 0 0
52324 - 0 0 0 0 0 0 0 0 0 0 0 0
52325 - 0 0 0 0 0 0 0 0 0 0 0 0
52326 - 0 0 0 0 0 0 0 0 0 0 0 0
52327 - 0 0 0 0 0 0 0 0 0 0 0 0
52328 - 0 0 0 0 0 0 0 0 0 0 0 0
52329 - 0 0 0 0 0 0 0 0 0 0 0 0
52330 - 0 0 0 0 0 0 0 0 0 0 0 0
52331 - 0 0 0 0 0 0 0 0 0 0 0 0
52332 - 0 0 0 0 0 0 0 0 0 0 0 0
52333 - 0 0 0 0 0 0 0 0 0 0 0 0
52334 - 0 0 0 0 0 0 0 0 0 0 0 0
52335 - 0 0 0 0 0 0 0 0 0 0 0 0
52336 - 0 0 0 6 6 6 10 10 10 14 14 14
52337 - 22 22 22 26 26 26 30 30 30 34 34 34
52338 - 30 30 30 30 30 30 26 26 26 18 18 18
52339 - 14 14 14 10 10 10 6 6 6 0 0 0
52340 - 0 0 0 0 0 0 0 0 0 0 0 0
52341 - 0 0 0 0 0 0 0 0 0 0 0 0
52342 - 0 0 0 0 0 0 0 0 0 0 0 0
52343 - 0 0 0 0 0 0 0 0 0 0 0 0
52344 - 0 0 0 0 0 0 0 0 0 0 0 0
52345 - 0 0 0 0 0 0 0 0 0 0 0 0
52346 - 0 0 0 0 0 0 0 0 0 0 0 0
52347 - 0 0 0 0 0 0 0 0 0 0 0 0
52348 - 0 0 0 0 0 0 0 0 0 0 0 0
52349 - 0 0 0 0 0 1 0 0 1 0 0 0
52350 - 0 0 0 0 0 0 0 0 0 0 0 0
52351 - 0 0 0 0 0 0 0 0 0 0 0 0
52352 - 0 0 0 0 0 0 0 0 0 0 0 0
52353 - 0 0 0 0 0 0 0 0 0 0 0 0
52354 - 0 0 0 0 0 0 0 0 0 0 0 0
52355 - 0 0 0 0 0 0 0 0 0 0 0 0
52356 - 6 6 6 14 14 14 26 26 26 42 42 42
52357 - 54 54 54 66 66 66 78 78 78 78 78 78
52358 - 78 78 78 74 74 74 66 66 66 54 54 54
52359 - 42 42 42 26 26 26 18 18 18 10 10 10
52360 - 6 6 6 0 0 0 0 0 0 0 0 0
52361 - 0 0 0 0 0 0 0 0 0 0 0 0
52362 - 0 0 0 0 0 0 0 0 0 0 0 0
52363 - 0 0 0 0 0 0 0 0 0 0 0 0
52364 - 0 0 0 0 0 0 0 0 0 0 0 0
52365 - 0 0 0 0 0 0 0 0 0 0 0 0
52366 - 0 0 0 0 0 0 0 0 0 0 0 0
52367 - 0 0 0 0 0 0 0 0 0 0 0 0
52368 - 0 0 0 0 0 0 0 0 0 0 0 0
52369 - 0 0 1 0 0 0 0 0 0 0 0 0
52370 - 0 0 0 0 0 0 0 0 0 0 0 0
52371 - 0 0 0 0 0 0 0 0 0 0 0 0
52372 - 0 0 0 0 0 0 0 0 0 0 0 0
52373 - 0 0 0 0 0 0 0 0 0 0 0 0
52374 - 0 0 0 0 0 0 0 0 0 0 0 0
52375 - 0 0 0 0 0 0 0 0 0 10 10 10
52376 - 22 22 22 42 42 42 66 66 66 86 86 86
52377 - 66 66 66 38 38 38 38 38 38 22 22 22
52378 - 26 26 26 34 34 34 54 54 54 66 66 66
52379 - 86 86 86 70 70 70 46 46 46 26 26 26
52380 - 14 14 14 6 6 6 0 0 0 0 0 0
52381 - 0 0 0 0 0 0 0 0 0 0 0 0
52382 - 0 0 0 0 0 0 0 0 0 0 0 0
52383 - 0 0 0 0 0 0 0 0 0 0 0 0
52384 - 0 0 0 0 0 0 0 0 0 0 0 0
52385 - 0 0 0 0 0 0 0 0 0 0 0 0
52386 - 0 0 0 0 0 0 0 0 0 0 0 0
52387 - 0 0 0 0 0 0 0 0 0 0 0 0
52388 - 0 0 0 0 0 0 0 0 0 0 0 0
52389 - 0 0 1 0 0 1 0 0 1 0 0 0
52390 - 0 0 0 0 0 0 0 0 0 0 0 0
52391 - 0 0 0 0 0 0 0 0 0 0 0 0
52392 - 0 0 0 0 0 0 0 0 0 0 0 0
52393 - 0 0 0 0 0 0 0 0 0 0 0 0
52394 - 0 0 0 0 0 0 0 0 0 0 0 0
52395 - 0 0 0 0 0 0 10 10 10 26 26 26
52396 - 50 50 50 82 82 82 58 58 58 6 6 6
52397 - 2 2 6 2 2 6 2 2 6 2 2 6
52398 - 2 2 6 2 2 6 2 2 6 2 2 6
52399 - 6 6 6 54 54 54 86 86 86 66 66 66
52400 - 38 38 38 18 18 18 6 6 6 0 0 0
52401 - 0 0 0 0 0 0 0 0 0 0 0 0
52402 - 0 0 0 0 0 0 0 0 0 0 0 0
52403 - 0 0 0 0 0 0 0 0 0 0 0 0
52404 - 0 0 0 0 0 0 0 0 0 0 0 0
52405 - 0 0 0 0 0 0 0 0 0 0 0 0
52406 - 0 0 0 0 0 0 0 0 0 0 0 0
52407 - 0 0 0 0 0 0 0 0 0 0 0 0
52408 - 0 0 0 0 0 0 0 0 0 0 0 0
52409 - 0 0 0 0 0 0 0 0 0 0 0 0
52410 - 0 0 0 0 0 0 0 0 0 0 0 0
52411 - 0 0 0 0 0 0 0 0 0 0 0 0
52412 - 0 0 0 0 0 0 0 0 0 0 0 0
52413 - 0 0 0 0 0 0 0 0 0 0 0 0
52414 - 0 0 0 0 0 0 0 0 0 0 0 0
52415 - 0 0 0 6 6 6 22 22 22 50 50 50
52416 - 78 78 78 34 34 34 2 2 6 2 2 6
52417 - 2 2 6 2 2 6 2 2 6 2 2 6
52418 - 2 2 6 2 2 6 2 2 6 2 2 6
52419 - 2 2 6 2 2 6 6 6 6 70 70 70
52420 - 78 78 78 46 46 46 22 22 22 6 6 6
52421 - 0 0 0 0 0 0 0 0 0 0 0 0
52422 - 0 0 0 0 0 0 0 0 0 0 0 0
52423 - 0 0 0 0 0 0 0 0 0 0 0 0
52424 - 0 0 0 0 0 0 0 0 0 0 0 0
52425 - 0 0 0 0 0 0 0 0 0 0 0 0
52426 - 0 0 0 0 0 0 0 0 0 0 0 0
52427 - 0 0 0 0 0 0 0 0 0 0 0 0
52428 - 0 0 0 0 0 0 0 0 0 0 0 0
52429 - 0 0 1 0 0 1 0 0 1 0 0 0
52430 - 0 0 0 0 0 0 0 0 0 0 0 0
52431 - 0 0 0 0 0 0 0 0 0 0 0 0
52432 - 0 0 0 0 0 0 0 0 0 0 0 0
52433 - 0 0 0 0 0 0 0 0 0 0 0 0
52434 - 0 0 0 0 0 0 0 0 0 0 0 0
52435 - 6 6 6 18 18 18 42 42 42 82 82 82
52436 - 26 26 26 2 2 6 2 2 6 2 2 6
52437 - 2 2 6 2 2 6 2 2 6 2 2 6
52438 - 2 2 6 2 2 6 2 2 6 14 14 14
52439 - 46 46 46 34 34 34 6 6 6 2 2 6
52440 - 42 42 42 78 78 78 42 42 42 18 18 18
52441 - 6 6 6 0 0 0 0 0 0 0 0 0
52442 - 0 0 0 0 0 0 0 0 0 0 0 0
52443 - 0 0 0 0 0 0 0 0 0 0 0 0
52444 - 0 0 0 0 0 0 0 0 0 0 0 0
52445 - 0 0 0 0 0 0 0 0 0 0 0 0
52446 - 0 0 0 0 0 0 0 0 0 0 0 0
52447 - 0 0 0 0 0 0 0 0 0 0 0 0
52448 - 0 0 0 0 0 0 0 0 0 0 0 0
52449 - 0 0 1 0 0 0 0 0 1 0 0 0
52450 - 0 0 0 0 0 0 0 0 0 0 0 0
52451 - 0 0 0 0 0 0 0 0 0 0 0 0
52452 - 0 0 0 0 0 0 0 0 0 0 0 0
52453 - 0 0 0 0 0 0 0 0 0 0 0 0
52454 - 0 0 0 0 0 0 0 0 0 0 0 0
52455 - 10 10 10 30 30 30 66 66 66 58 58 58
52456 - 2 2 6 2 2 6 2 2 6 2 2 6
52457 - 2 2 6 2 2 6 2 2 6 2 2 6
52458 - 2 2 6 2 2 6 2 2 6 26 26 26
52459 - 86 86 86 101 101 101 46 46 46 10 10 10
52460 - 2 2 6 58 58 58 70 70 70 34 34 34
52461 - 10 10 10 0 0 0 0 0 0 0 0 0
52462 - 0 0 0 0 0 0 0 0 0 0 0 0
52463 - 0 0 0 0 0 0 0 0 0 0 0 0
52464 - 0 0 0 0 0 0 0 0 0 0 0 0
52465 - 0 0 0 0 0 0 0 0 0 0 0 0
52466 - 0 0 0 0 0 0 0 0 0 0 0 0
52467 - 0 0 0 0 0 0 0 0 0 0 0 0
52468 - 0 0 0 0 0 0 0 0 0 0 0 0
52469 - 0 0 1 0 0 1 0 0 1 0 0 0
52470 - 0 0 0 0 0 0 0 0 0 0 0 0
52471 - 0 0 0 0 0 0 0 0 0 0 0 0
52472 - 0 0 0 0 0 0 0 0 0 0 0 0
52473 - 0 0 0 0 0 0 0 0 0 0 0 0
52474 - 0 0 0 0 0 0 0 0 0 0 0 0
52475 - 14 14 14 42 42 42 86 86 86 10 10 10
52476 - 2 2 6 2 2 6 2 2 6 2 2 6
52477 - 2 2 6 2 2 6 2 2 6 2 2 6
52478 - 2 2 6 2 2 6 2 2 6 30 30 30
52479 - 94 94 94 94 94 94 58 58 58 26 26 26
52480 - 2 2 6 6 6 6 78 78 78 54 54 54
52481 - 22 22 22 6 6 6 0 0 0 0 0 0
52482 - 0 0 0 0 0 0 0 0 0 0 0 0
52483 - 0 0 0 0 0 0 0 0 0 0 0 0
52484 - 0 0 0 0 0 0 0 0 0 0 0 0
52485 - 0 0 0 0 0 0 0 0 0 0 0 0
52486 - 0 0 0 0 0 0 0 0 0 0 0 0
52487 - 0 0 0 0 0 0 0 0 0 0 0 0
52488 - 0 0 0 0 0 0 0 0 0 0 0 0
52489 - 0 0 0 0 0 0 0 0 0 0 0 0
52490 - 0 0 0 0 0 0 0 0 0 0 0 0
52491 - 0 0 0 0 0 0 0 0 0 0 0 0
52492 - 0 0 0 0 0 0 0 0 0 0 0 0
52493 - 0 0 0 0 0 0 0 0 0 0 0 0
52494 - 0 0 0 0 0 0 0 0 0 6 6 6
52495 - 22 22 22 62 62 62 62 62 62 2 2 6
52496 - 2 2 6 2 2 6 2 2 6 2 2 6
52497 - 2 2 6 2 2 6 2 2 6 2 2 6
52498 - 2 2 6 2 2 6 2 2 6 26 26 26
52499 - 54 54 54 38 38 38 18 18 18 10 10 10
52500 - 2 2 6 2 2 6 34 34 34 82 82 82
52501 - 38 38 38 14 14 14 0 0 0 0 0 0
52502 - 0 0 0 0 0 0 0 0 0 0 0 0
52503 - 0 0 0 0 0 0 0 0 0 0 0 0
52504 - 0 0 0 0 0 0 0 0 0 0 0 0
52505 - 0 0 0 0 0 0 0 0 0 0 0 0
52506 - 0 0 0 0 0 0 0 0 0 0 0 0
52507 - 0 0 0 0 0 0 0 0 0 0 0 0
52508 - 0 0 0 0 0 0 0 0 0 0 0 0
52509 - 0 0 0 0 0 1 0 0 1 0 0 0
52510 - 0 0 0 0 0 0 0 0 0 0 0 0
52511 - 0 0 0 0 0 0 0 0 0 0 0 0
52512 - 0 0 0 0 0 0 0 0 0 0 0 0
52513 - 0 0 0 0 0 0 0 0 0 0 0 0
52514 - 0 0 0 0 0 0 0 0 0 6 6 6
52515 - 30 30 30 78 78 78 30 30 30 2 2 6
52516 - 2 2 6 2 2 6 2 2 6 2 2 6
52517 - 2 2 6 2 2 6 2 2 6 2 2 6
52518 - 2 2 6 2 2 6 2 2 6 10 10 10
52519 - 10 10 10 2 2 6 2 2 6 2 2 6
52520 - 2 2 6 2 2 6 2 2 6 78 78 78
52521 - 50 50 50 18 18 18 6 6 6 0 0 0
52522 - 0 0 0 0 0 0 0 0 0 0 0 0
52523 - 0 0 0 0 0 0 0 0 0 0 0 0
52524 - 0 0 0 0 0 0 0 0 0 0 0 0
52525 - 0 0 0 0 0 0 0 0 0 0 0 0
52526 - 0 0 0 0 0 0 0 0 0 0 0 0
52527 - 0 0 0 0 0 0 0 0 0 0 0 0
52528 - 0 0 0 0 0 0 0 0 0 0 0 0
52529 - 0 0 1 0 0 0 0 0 0 0 0 0
52530 - 0 0 0 0 0 0 0 0 0 0 0 0
52531 - 0 0 0 0 0 0 0 0 0 0 0 0
52532 - 0 0 0 0 0 0 0 0 0 0 0 0
52533 - 0 0 0 0 0 0 0 0 0 0 0 0
52534 - 0 0 0 0 0 0 0 0 0 10 10 10
52535 - 38 38 38 86 86 86 14 14 14 2 2 6
52536 - 2 2 6 2 2 6 2 2 6 2 2 6
52537 - 2 2 6 2 2 6 2 2 6 2 2 6
52538 - 2 2 6 2 2 6 2 2 6 2 2 6
52539 - 2 2 6 2 2 6 2 2 6 2 2 6
52540 - 2 2 6 2 2 6 2 2 6 54 54 54
52541 - 66 66 66 26 26 26 6 6 6 0 0 0
52542 - 0 0 0 0 0 0 0 0 0 0 0 0
52543 - 0 0 0 0 0 0 0 0 0 0 0 0
52544 - 0 0 0 0 0 0 0 0 0 0 0 0
52545 - 0 0 0 0 0 0 0 0 0 0 0 0
52546 - 0 0 0 0 0 0 0 0 0 0 0 0
52547 - 0 0 0 0 0 0 0 0 0 0 0 0
52548 - 0 0 0 0 0 0 0 0 0 0 0 0
52549 - 0 0 0 0 0 1 0 0 1 0 0 0
52550 - 0 0 0 0 0 0 0 0 0 0 0 0
52551 - 0 0 0 0 0 0 0 0 0 0 0 0
52552 - 0 0 0 0 0 0 0 0 0 0 0 0
52553 - 0 0 0 0 0 0 0 0 0 0 0 0
52554 - 0 0 0 0 0 0 0 0 0 14 14 14
52555 - 42 42 42 82 82 82 2 2 6 2 2 6
52556 - 2 2 6 6 6 6 10 10 10 2 2 6
52557 - 2 2 6 2 2 6 2 2 6 2 2 6
52558 - 2 2 6 2 2 6 2 2 6 6 6 6
52559 - 14 14 14 10 10 10 2 2 6 2 2 6
52560 - 2 2 6 2 2 6 2 2 6 18 18 18
52561 - 82 82 82 34 34 34 10 10 10 0 0 0
52562 - 0 0 0 0 0 0 0 0 0 0 0 0
52563 - 0 0 0 0 0 0 0 0 0 0 0 0
52564 - 0 0 0 0 0 0 0 0 0 0 0 0
52565 - 0 0 0 0 0 0 0 0 0 0 0 0
52566 - 0 0 0 0 0 0 0 0 0 0 0 0
52567 - 0 0 0 0 0 0 0 0 0 0 0 0
52568 - 0 0 0 0 0 0 0 0 0 0 0 0
52569 - 0 0 1 0 0 0 0 0 0 0 0 0
52570 - 0 0 0 0 0 0 0 0 0 0 0 0
52571 - 0 0 0 0 0 0 0 0 0 0 0 0
52572 - 0 0 0 0 0 0 0 0 0 0 0 0
52573 - 0 0 0 0 0 0 0 0 0 0 0 0
52574 - 0 0 0 0 0 0 0 0 0 14 14 14
52575 - 46 46 46 86 86 86 2 2 6 2 2 6
52576 - 6 6 6 6 6 6 22 22 22 34 34 34
52577 - 6 6 6 2 2 6 2 2 6 2 2 6
52578 - 2 2 6 2 2 6 18 18 18 34 34 34
52579 - 10 10 10 50 50 50 22 22 22 2 2 6
52580 - 2 2 6 2 2 6 2 2 6 10 10 10
52581 - 86 86 86 42 42 42 14 14 14 0 0 0
52582 - 0 0 0 0 0 0 0 0 0 0 0 0
52583 - 0 0 0 0 0 0 0 0 0 0 0 0
52584 - 0 0 0 0 0 0 0 0 0 0 0 0
52585 - 0 0 0 0 0 0 0 0 0 0 0 0
52586 - 0 0 0 0 0 0 0 0 0 0 0 0
52587 - 0 0 0 0 0 0 0 0 0 0 0 0
52588 - 0 0 0 0 0 0 0 0 0 0 0 0
52589 - 0 0 1 0 0 1 0 0 1 0 0 0
52590 - 0 0 0 0 0 0 0 0 0 0 0 0
52591 - 0 0 0 0 0 0 0 0 0 0 0 0
52592 - 0 0 0 0 0 0 0 0 0 0 0 0
52593 - 0 0 0 0 0 0 0 0 0 0 0 0
52594 - 0 0 0 0 0 0 0 0 0 14 14 14
52595 - 46 46 46 86 86 86 2 2 6 2 2 6
52596 - 38 38 38 116 116 116 94 94 94 22 22 22
52597 - 22 22 22 2 2 6 2 2 6 2 2 6
52598 - 14 14 14 86 86 86 138 138 138 162 162 162
52599 -154 154 154 38 38 38 26 26 26 6 6 6
52600 - 2 2 6 2 2 6 2 2 6 2 2 6
52601 - 86 86 86 46 46 46 14 14 14 0 0 0
52602 - 0 0 0 0 0 0 0 0 0 0 0 0
52603 - 0 0 0 0 0 0 0 0 0 0 0 0
52604 - 0 0 0 0 0 0 0 0 0 0 0 0
52605 - 0 0 0 0 0 0 0 0 0 0 0 0
52606 - 0 0 0 0 0 0 0 0 0 0 0 0
52607 - 0 0 0 0 0 0 0 0 0 0 0 0
52608 - 0 0 0 0 0 0 0 0 0 0 0 0
52609 - 0 0 0 0 0 0 0 0 0 0 0 0
52610 - 0 0 0 0 0 0 0 0 0 0 0 0
52611 - 0 0 0 0 0 0 0 0 0 0 0 0
52612 - 0 0 0 0 0 0 0 0 0 0 0 0
52613 - 0 0 0 0 0 0 0 0 0 0 0 0
52614 - 0 0 0 0 0 0 0 0 0 14 14 14
52615 - 46 46 46 86 86 86 2 2 6 14 14 14
52616 -134 134 134 198 198 198 195 195 195 116 116 116
52617 - 10 10 10 2 2 6 2 2 6 6 6 6
52618 -101 98 89 187 187 187 210 210 210 218 218 218
52619 -214 214 214 134 134 134 14 14 14 6 6 6
52620 - 2 2 6 2 2 6 2 2 6 2 2 6
52621 - 86 86 86 50 50 50 18 18 18 6 6 6
52622 - 0 0 0 0 0 0 0 0 0 0 0 0
52623 - 0 0 0 0 0 0 0 0 0 0 0 0
52624 - 0 0 0 0 0 0 0 0 0 0 0 0
52625 - 0 0 0 0 0 0 0 0 0 0 0 0
52626 - 0 0 0 0 0 0 0 0 0 0 0 0
52627 - 0 0 0 0 0 0 0 0 0 0 0 0
52628 - 0 0 0 0 0 0 0 0 1 0 0 0
52629 - 0 0 1 0 0 1 0 0 1 0 0 0
52630 - 0 0 0 0 0 0 0 0 0 0 0 0
52631 - 0 0 0 0 0 0 0 0 0 0 0 0
52632 - 0 0 0 0 0 0 0 0 0 0 0 0
52633 - 0 0 0 0 0 0 0 0 0 0 0 0
52634 - 0 0 0 0 0 0 0 0 0 14 14 14
52635 - 46 46 46 86 86 86 2 2 6 54 54 54
52636 -218 218 218 195 195 195 226 226 226 246 246 246
52637 - 58 58 58 2 2 6 2 2 6 30 30 30
52638 -210 210 210 253 253 253 174 174 174 123 123 123
52639 -221 221 221 234 234 234 74 74 74 2 2 6
52640 - 2 2 6 2 2 6 2 2 6 2 2 6
52641 - 70 70 70 58 58 58 22 22 22 6 6 6
52642 - 0 0 0 0 0 0 0 0 0 0 0 0
52643 - 0 0 0 0 0 0 0 0 0 0 0 0
52644 - 0 0 0 0 0 0 0 0 0 0 0 0
52645 - 0 0 0 0 0 0 0 0 0 0 0 0
52646 - 0 0 0 0 0 0 0 0 0 0 0 0
52647 - 0 0 0 0 0 0 0 0 0 0 0 0
52648 - 0 0 0 0 0 0 0 0 0 0 0 0
52649 - 0 0 0 0 0 0 0 0 0 0 0 0
52650 - 0 0 0 0 0 0 0 0 0 0 0 0
52651 - 0 0 0 0 0 0 0 0 0 0 0 0
52652 - 0 0 0 0 0 0 0 0 0 0 0 0
52653 - 0 0 0 0 0 0 0 0 0 0 0 0
52654 - 0 0 0 0 0 0 0 0 0 14 14 14
52655 - 46 46 46 82 82 82 2 2 6 106 106 106
52656 -170 170 170 26 26 26 86 86 86 226 226 226
52657 -123 123 123 10 10 10 14 14 14 46 46 46
52658 -231 231 231 190 190 190 6 6 6 70 70 70
52659 - 90 90 90 238 238 238 158 158 158 2 2 6
52660 - 2 2 6 2 2 6 2 2 6 2 2 6
52661 - 70 70 70 58 58 58 22 22 22 6 6 6
52662 - 0 0 0 0 0 0 0 0 0 0 0 0
52663 - 0 0 0 0 0 0 0 0 0 0 0 0
52664 - 0 0 0 0 0 0 0 0 0 0 0 0
52665 - 0 0 0 0 0 0 0 0 0 0 0 0
52666 - 0 0 0 0 0 0 0 0 0 0 0 0
52667 - 0 0 0 0 0 0 0 0 0 0 0 0
52668 - 0 0 0 0 0 0 0 0 1 0 0 0
52669 - 0 0 1 0 0 1 0 0 1 0 0 0
52670 - 0 0 0 0 0 0 0 0 0 0 0 0
52671 - 0 0 0 0 0 0 0 0 0 0 0 0
52672 - 0 0 0 0 0 0 0 0 0 0 0 0
52673 - 0 0 0 0 0 0 0 0 0 0 0 0
52674 - 0 0 0 0 0 0 0 0 0 14 14 14
52675 - 42 42 42 86 86 86 6 6 6 116 116 116
52676 -106 106 106 6 6 6 70 70 70 149 149 149
52677 -128 128 128 18 18 18 38 38 38 54 54 54
52678 -221 221 221 106 106 106 2 2 6 14 14 14
52679 - 46 46 46 190 190 190 198 198 198 2 2 6
52680 - 2 2 6 2 2 6 2 2 6 2 2 6
52681 - 74 74 74 62 62 62 22 22 22 6 6 6
52682 - 0 0 0 0 0 0 0 0 0 0 0 0
52683 - 0 0 0 0 0 0 0 0 0 0 0 0
52684 - 0 0 0 0 0 0 0 0 0 0 0 0
52685 - 0 0 0 0 0 0 0 0 0 0 0 0
52686 - 0 0 0 0 0 0 0 0 0 0 0 0
52687 - 0 0 0 0 0 0 0 0 0 0 0 0
52688 - 0 0 0 0 0 0 0 0 1 0 0 0
52689 - 0 0 1 0 0 0 0 0 1 0 0 0
52690 - 0 0 0 0 0 0 0 0 0 0 0 0
52691 - 0 0 0 0 0 0 0 0 0 0 0 0
52692 - 0 0 0 0 0 0 0 0 0 0 0 0
52693 - 0 0 0 0 0 0 0 0 0 0 0 0
52694 - 0 0 0 0 0 0 0 0 0 14 14 14
52695 - 42 42 42 94 94 94 14 14 14 101 101 101
52696 -128 128 128 2 2 6 18 18 18 116 116 116
52697 -118 98 46 121 92 8 121 92 8 98 78 10
52698 -162 162 162 106 106 106 2 2 6 2 2 6
52699 - 2 2 6 195 195 195 195 195 195 6 6 6
52700 - 2 2 6 2 2 6 2 2 6 2 2 6
52701 - 74 74 74 62 62 62 22 22 22 6 6 6
52702 - 0 0 0 0 0 0 0 0 0 0 0 0
52703 - 0 0 0 0 0 0 0 0 0 0 0 0
52704 - 0 0 0 0 0 0 0 0 0 0 0 0
52705 - 0 0 0 0 0 0 0 0 0 0 0 0
52706 - 0 0 0 0 0 0 0 0 0 0 0 0
52707 - 0 0 0 0 0 0 0 0 0 0 0 0
52708 - 0 0 0 0 0 0 0 0 1 0 0 1
52709 - 0 0 1 0 0 0 0 0 1 0 0 0
52710 - 0 0 0 0 0 0 0 0 0 0 0 0
52711 - 0 0 0 0 0 0 0 0 0 0 0 0
52712 - 0 0 0 0 0 0 0 0 0 0 0 0
52713 - 0 0 0 0 0 0 0 0 0 0 0 0
52714 - 0 0 0 0 0 0 0 0 0 10 10 10
52715 - 38 38 38 90 90 90 14 14 14 58 58 58
52716 -210 210 210 26 26 26 54 38 6 154 114 10
52717 -226 170 11 236 186 11 225 175 15 184 144 12
52718 -215 174 15 175 146 61 37 26 9 2 2 6
52719 - 70 70 70 246 246 246 138 138 138 2 2 6
52720 - 2 2 6 2 2 6 2 2 6 2 2 6
52721 - 70 70 70 66 66 66 26 26 26 6 6 6
52722 - 0 0 0 0 0 0 0 0 0 0 0 0
52723 - 0 0 0 0 0 0 0 0 0 0 0 0
52724 - 0 0 0 0 0 0 0 0 0 0 0 0
52725 - 0 0 0 0 0 0 0 0 0 0 0 0
52726 - 0 0 0 0 0 0 0 0 0 0 0 0
52727 - 0 0 0 0 0 0 0 0 0 0 0 0
52728 - 0 0 0 0 0 0 0 0 0 0 0 0
52729 - 0 0 0 0 0 0 0 0 0 0 0 0
52730 - 0 0 0 0 0 0 0 0 0 0 0 0
52731 - 0 0 0 0 0 0 0 0 0 0 0 0
52732 - 0 0 0 0 0 0 0 0 0 0 0 0
52733 - 0 0 0 0 0 0 0 0 0 0 0 0
52734 - 0 0 0 0 0 0 0 0 0 10 10 10
52735 - 38 38 38 86 86 86 14 14 14 10 10 10
52736 -195 195 195 188 164 115 192 133 9 225 175 15
52737 -239 182 13 234 190 10 232 195 16 232 200 30
52738 -245 207 45 241 208 19 232 195 16 184 144 12
52739 -218 194 134 211 206 186 42 42 42 2 2 6
52740 - 2 2 6 2 2 6 2 2 6 2 2 6
52741 - 50 50 50 74 74 74 30 30 30 6 6 6
52742 - 0 0 0 0 0 0 0 0 0 0 0 0
52743 - 0 0 0 0 0 0 0 0 0 0 0 0
52744 - 0 0 0 0 0 0 0 0 0 0 0 0
52745 - 0 0 0 0 0 0 0 0 0 0 0 0
52746 - 0 0 0 0 0 0 0 0 0 0 0 0
52747 - 0 0 0 0 0 0 0 0 0 0 0 0
52748 - 0 0 0 0 0 0 0 0 0 0 0 0
52749 - 0 0 0 0 0 0 0 0 0 0 0 0
52750 - 0 0 0 0 0 0 0 0 0 0 0 0
52751 - 0 0 0 0 0 0 0 0 0 0 0 0
52752 - 0 0 0 0 0 0 0 0 0 0 0 0
52753 - 0 0 0 0 0 0 0 0 0 0 0 0
52754 - 0 0 0 0 0 0 0 0 0 10 10 10
52755 - 34 34 34 86 86 86 14 14 14 2 2 6
52756 -121 87 25 192 133 9 219 162 10 239 182 13
52757 -236 186 11 232 195 16 241 208 19 244 214 54
52758 -246 218 60 246 218 38 246 215 20 241 208 19
52759 -241 208 19 226 184 13 121 87 25 2 2 6
52760 - 2 2 6 2 2 6 2 2 6 2 2 6
52761 - 50 50 50 82 82 82 34 34 34 10 10 10
52762 - 0 0 0 0 0 0 0 0 0 0 0 0
52763 - 0 0 0 0 0 0 0 0 0 0 0 0
52764 - 0 0 0 0 0 0 0 0 0 0 0 0
52765 - 0 0 0 0 0 0 0 0 0 0 0 0
52766 - 0 0 0 0 0 0 0 0 0 0 0 0
52767 - 0 0 0 0 0 0 0 0 0 0 0 0
52768 - 0 0 0 0 0 0 0 0 0 0 0 0
52769 - 0 0 0 0 0 0 0 0 0 0 0 0
52770 - 0 0 0 0 0 0 0 0 0 0 0 0
52771 - 0 0 0 0 0 0 0 0 0 0 0 0
52772 - 0 0 0 0 0 0 0 0 0 0 0 0
52773 - 0 0 0 0 0 0 0 0 0 0 0 0
52774 - 0 0 0 0 0 0 0 0 0 10 10 10
52775 - 34 34 34 82 82 82 30 30 30 61 42 6
52776 -180 123 7 206 145 10 230 174 11 239 182 13
52777 -234 190 10 238 202 15 241 208 19 246 218 74
52778 -246 218 38 246 215 20 246 215 20 246 215 20
52779 -226 184 13 215 174 15 184 144 12 6 6 6
52780 - 2 2 6 2 2 6 2 2 6 2 2 6
52781 - 26 26 26 94 94 94 42 42 42 14 14 14
52782 - 0 0 0 0 0 0 0 0 0 0 0 0
52783 - 0 0 0 0 0 0 0 0 0 0 0 0
52784 - 0 0 0 0 0 0 0 0 0 0 0 0
52785 - 0 0 0 0 0 0 0 0 0 0 0 0
52786 - 0 0 0 0 0 0 0 0 0 0 0 0
52787 - 0 0 0 0 0 0 0 0 0 0 0 0
52788 - 0 0 0 0 0 0 0 0 0 0 0 0
52789 - 0 0 0 0 0 0 0 0 0 0 0 0
52790 - 0 0 0 0 0 0 0 0 0 0 0 0
52791 - 0 0 0 0 0 0 0 0 0 0 0 0
52792 - 0 0 0 0 0 0 0 0 0 0 0 0
52793 - 0 0 0 0 0 0 0 0 0 0 0 0
52794 - 0 0 0 0 0 0 0 0 0 10 10 10
52795 - 30 30 30 78 78 78 50 50 50 104 69 6
52796 -192 133 9 216 158 10 236 178 12 236 186 11
52797 -232 195 16 241 208 19 244 214 54 245 215 43
52798 -246 215 20 246 215 20 241 208 19 198 155 10
52799 -200 144 11 216 158 10 156 118 10 2 2 6
52800 - 2 2 6 2 2 6 2 2 6 2 2 6
52801 - 6 6 6 90 90 90 54 54 54 18 18 18
52802 - 6 6 6 0 0 0 0 0 0 0 0 0
52803 - 0 0 0 0 0 0 0 0 0 0 0 0
52804 - 0 0 0 0 0 0 0 0 0 0 0 0
52805 - 0 0 0 0 0 0 0 0 0 0 0 0
52806 - 0 0 0 0 0 0 0 0 0 0 0 0
52807 - 0 0 0 0 0 0 0 0 0 0 0 0
52808 - 0 0 0 0 0 0 0 0 0 0 0 0
52809 - 0 0 0 0 0 0 0 0 0 0 0 0
52810 - 0 0 0 0 0 0 0 0 0 0 0 0
52811 - 0 0 0 0 0 0 0 0 0 0 0 0
52812 - 0 0 0 0 0 0 0 0 0 0 0 0
52813 - 0 0 0 0 0 0 0 0 0 0 0 0
52814 - 0 0 0 0 0 0 0 0 0 10 10 10
52815 - 30 30 30 78 78 78 46 46 46 22 22 22
52816 -137 92 6 210 162 10 239 182 13 238 190 10
52817 -238 202 15 241 208 19 246 215 20 246 215 20
52818 -241 208 19 203 166 17 185 133 11 210 150 10
52819 -216 158 10 210 150 10 102 78 10 2 2 6
52820 - 6 6 6 54 54 54 14 14 14 2 2 6
52821 - 2 2 6 62 62 62 74 74 74 30 30 30
52822 - 10 10 10 0 0 0 0 0 0 0 0 0
52823 - 0 0 0 0 0 0 0 0 0 0 0 0
52824 - 0 0 0 0 0 0 0 0 0 0 0 0
52825 - 0 0 0 0 0 0 0 0 0 0 0 0
52826 - 0 0 0 0 0 0 0 0 0 0 0 0
52827 - 0 0 0 0 0 0 0 0 0 0 0 0
52828 - 0 0 0 0 0 0 0 0 0 0 0 0
52829 - 0 0 0 0 0 0 0 0 0 0 0 0
52830 - 0 0 0 0 0 0 0 0 0 0 0 0
52831 - 0 0 0 0 0 0 0 0 0 0 0 0
52832 - 0 0 0 0 0 0 0 0 0 0 0 0
52833 - 0 0 0 0 0 0 0 0 0 0 0 0
52834 - 0 0 0 0 0 0 0 0 0 10 10 10
52835 - 34 34 34 78 78 78 50 50 50 6 6 6
52836 - 94 70 30 139 102 15 190 146 13 226 184 13
52837 -232 200 30 232 195 16 215 174 15 190 146 13
52838 -168 122 10 192 133 9 210 150 10 213 154 11
52839 -202 150 34 182 157 106 101 98 89 2 2 6
52840 - 2 2 6 78 78 78 116 116 116 58 58 58
52841 - 2 2 6 22 22 22 90 90 90 46 46 46
52842 - 18 18 18 6 6 6 0 0 0 0 0 0
52843 - 0 0 0 0 0 0 0 0 0 0 0 0
52844 - 0 0 0 0 0 0 0 0 0 0 0 0
52845 - 0 0 0 0 0 0 0 0 0 0 0 0
52846 - 0 0 0 0 0 0 0 0 0 0 0 0
52847 - 0 0 0 0 0 0 0 0 0 0 0 0
52848 - 0 0 0 0 0 0 0 0 0 0 0 0
52849 - 0 0 0 0 0 0 0 0 0 0 0 0
52850 - 0 0 0 0 0 0 0 0 0 0 0 0
52851 - 0 0 0 0 0 0 0 0 0 0 0 0
52852 - 0 0 0 0 0 0 0 0 0 0 0 0
52853 - 0 0 0 0 0 0 0 0 0 0 0 0
52854 - 0 0 0 0 0 0 0 0 0 10 10 10
52855 - 38 38 38 86 86 86 50 50 50 6 6 6
52856 -128 128 128 174 154 114 156 107 11 168 122 10
52857 -198 155 10 184 144 12 197 138 11 200 144 11
52858 -206 145 10 206 145 10 197 138 11 188 164 115
52859 -195 195 195 198 198 198 174 174 174 14 14 14
52860 - 2 2 6 22 22 22 116 116 116 116 116 116
52861 - 22 22 22 2 2 6 74 74 74 70 70 70
52862 - 30 30 30 10 10 10 0 0 0 0 0 0
52863 - 0 0 0 0 0 0 0 0 0 0 0 0
52864 - 0 0 0 0 0 0 0 0 0 0 0 0
52865 - 0 0 0 0 0 0 0 0 0 0 0 0
52866 - 0 0 0 0 0 0 0 0 0 0 0 0
52867 - 0 0 0 0 0 0 0 0 0 0 0 0
52868 - 0 0 0 0 0 0 0 0 0 0 0 0
52869 - 0 0 0 0 0 0 0 0 0 0 0 0
52870 - 0 0 0 0 0 0 0 0 0 0 0 0
52871 - 0 0 0 0 0 0 0 0 0 0 0 0
52872 - 0 0 0 0 0 0 0 0 0 0 0 0
52873 - 0 0 0 0 0 0 0 0 0 0 0 0
52874 - 0 0 0 0 0 0 6 6 6 18 18 18
52875 - 50 50 50 101 101 101 26 26 26 10 10 10
52876 -138 138 138 190 190 190 174 154 114 156 107 11
52877 -197 138 11 200 144 11 197 138 11 192 133 9
52878 -180 123 7 190 142 34 190 178 144 187 187 187
52879 -202 202 202 221 221 221 214 214 214 66 66 66
52880 - 2 2 6 2 2 6 50 50 50 62 62 62
52881 - 6 6 6 2 2 6 10 10 10 90 90 90
52882 - 50 50 50 18 18 18 6 6 6 0 0 0
52883 - 0 0 0 0 0 0 0 0 0 0 0 0
52884 - 0 0 0 0 0 0 0 0 0 0 0 0
52885 - 0 0 0 0 0 0 0 0 0 0 0 0
52886 - 0 0 0 0 0 0 0 0 0 0 0 0
52887 - 0 0 0 0 0 0 0 0 0 0 0 0
52888 - 0 0 0 0 0 0 0 0 0 0 0 0
52889 - 0 0 0 0 0 0 0 0 0 0 0 0
52890 - 0 0 0 0 0 0 0 0 0 0 0 0
52891 - 0 0 0 0 0 0 0 0 0 0 0 0
52892 - 0 0 0 0 0 0 0 0 0 0 0 0
52893 - 0 0 0 0 0 0 0 0 0 0 0 0
52894 - 0 0 0 0 0 0 10 10 10 34 34 34
52895 - 74 74 74 74 74 74 2 2 6 6 6 6
52896 -144 144 144 198 198 198 190 190 190 178 166 146
52897 -154 121 60 156 107 11 156 107 11 168 124 44
52898 -174 154 114 187 187 187 190 190 190 210 210 210
52899 -246 246 246 253 253 253 253 253 253 182 182 182
52900 - 6 6 6 2 2 6 2 2 6 2 2 6
52901 - 2 2 6 2 2 6 2 2 6 62 62 62
52902 - 74 74 74 34 34 34 14 14 14 0 0 0
52903 - 0 0 0 0 0 0 0 0 0 0 0 0
52904 - 0 0 0 0 0 0 0 0 0 0 0 0
52905 - 0 0 0 0 0 0 0 0 0 0 0 0
52906 - 0 0 0 0 0 0 0 0 0 0 0 0
52907 - 0 0 0 0 0 0 0 0 0 0 0 0
52908 - 0 0 0 0 0 0 0 0 0 0 0 0
52909 - 0 0 0 0 0 0 0 0 0 0 0 0
52910 - 0 0 0 0 0 0 0 0 0 0 0 0
52911 - 0 0 0 0 0 0 0 0 0 0 0 0
52912 - 0 0 0 0 0 0 0 0 0 0 0 0
52913 - 0 0 0 0 0 0 0 0 0 0 0 0
52914 - 0 0 0 10 10 10 22 22 22 54 54 54
52915 - 94 94 94 18 18 18 2 2 6 46 46 46
52916 -234 234 234 221 221 221 190 190 190 190 190 190
52917 -190 190 190 187 187 187 187 187 187 190 190 190
52918 -190 190 190 195 195 195 214 214 214 242 242 242
52919 -253 253 253 253 253 253 253 253 253 253 253 253
52920 - 82 82 82 2 2 6 2 2 6 2 2 6
52921 - 2 2 6 2 2 6 2 2 6 14 14 14
52922 - 86 86 86 54 54 54 22 22 22 6 6 6
52923 - 0 0 0 0 0 0 0 0 0 0 0 0
52924 - 0 0 0 0 0 0 0 0 0 0 0 0
52925 - 0 0 0 0 0 0 0 0 0 0 0 0
52926 - 0 0 0 0 0 0 0 0 0 0 0 0
52927 - 0 0 0 0 0 0 0 0 0 0 0 0
52928 - 0 0 0 0 0 0 0 0 0 0 0 0
52929 - 0 0 0 0 0 0 0 0 0 0 0 0
52930 - 0 0 0 0 0 0 0 0 0 0 0 0
52931 - 0 0 0 0 0 0 0 0 0 0 0 0
52932 - 0 0 0 0 0 0 0 0 0 0 0 0
52933 - 0 0 0 0 0 0 0 0 0 0 0 0
52934 - 6 6 6 18 18 18 46 46 46 90 90 90
52935 - 46 46 46 18 18 18 6 6 6 182 182 182
52936 -253 253 253 246 246 246 206 206 206 190 190 190
52937 -190 190 190 190 190 190 190 190 190 190 190 190
52938 -206 206 206 231 231 231 250 250 250 253 253 253
52939 -253 253 253 253 253 253 253 253 253 253 253 253
52940 -202 202 202 14 14 14 2 2 6 2 2 6
52941 - 2 2 6 2 2 6 2 2 6 2 2 6
52942 - 42 42 42 86 86 86 42 42 42 18 18 18
52943 - 6 6 6 0 0 0 0 0 0 0 0 0
52944 - 0 0 0 0 0 0 0 0 0 0 0 0
52945 - 0 0 0 0 0 0 0 0 0 0 0 0
52946 - 0 0 0 0 0 0 0 0 0 0 0 0
52947 - 0 0 0 0 0 0 0 0 0 0 0 0
52948 - 0 0 0 0 0 0 0 0 0 0 0 0
52949 - 0 0 0 0 0 0 0 0 0 0 0 0
52950 - 0 0 0 0 0 0 0 0 0 0 0 0
52951 - 0 0 0 0 0 0 0 0 0 0 0 0
52952 - 0 0 0 0 0 0 0 0 0 0 0 0
52953 - 0 0 0 0 0 0 0 0 0 6 6 6
52954 - 14 14 14 38 38 38 74 74 74 66 66 66
52955 - 2 2 6 6 6 6 90 90 90 250 250 250
52956 -253 253 253 253 253 253 238 238 238 198 198 198
52957 -190 190 190 190 190 190 195 195 195 221 221 221
52958 -246 246 246 253 253 253 253 253 253 253 253 253
52959 -253 253 253 253 253 253 253 253 253 253 253 253
52960 -253 253 253 82 82 82 2 2 6 2 2 6
52961 - 2 2 6 2 2 6 2 2 6 2 2 6
52962 - 2 2 6 78 78 78 70 70 70 34 34 34
52963 - 14 14 14 6 6 6 0 0 0 0 0 0
52964 - 0 0 0 0 0 0 0 0 0 0 0 0
52965 - 0 0 0 0 0 0 0 0 0 0 0 0
52966 - 0 0 0 0 0 0 0 0 0 0 0 0
52967 - 0 0 0 0 0 0 0 0 0 0 0 0
52968 - 0 0 0 0 0 0 0 0 0 0 0 0
52969 - 0 0 0 0 0 0 0 0 0 0 0 0
52970 - 0 0 0 0 0 0 0 0 0 0 0 0
52971 - 0 0 0 0 0 0 0 0 0 0 0 0
52972 - 0 0 0 0 0 0 0 0 0 0 0 0
52973 - 0 0 0 0 0 0 0 0 0 14 14 14
52974 - 34 34 34 66 66 66 78 78 78 6 6 6
52975 - 2 2 6 18 18 18 218 218 218 253 253 253
52976 -253 253 253 253 253 253 253 253 253 246 246 246
52977 -226 226 226 231 231 231 246 246 246 253 253 253
52978 -253 253 253 253 253 253 253 253 253 253 253 253
52979 -253 253 253 253 253 253 253 253 253 253 253 253
52980 -253 253 253 178 178 178 2 2 6 2 2 6
52981 - 2 2 6 2 2 6 2 2 6 2 2 6
52982 - 2 2 6 18 18 18 90 90 90 62 62 62
52983 - 30 30 30 10 10 10 0 0 0 0 0 0
52984 - 0 0 0 0 0 0 0 0 0 0 0 0
52985 - 0 0 0 0 0 0 0 0 0 0 0 0
52986 - 0 0 0 0 0 0 0 0 0 0 0 0
52987 - 0 0 0 0 0 0 0 0 0 0 0 0
52988 - 0 0 0 0 0 0 0 0 0 0 0 0
52989 - 0 0 0 0 0 0 0 0 0 0 0 0
52990 - 0 0 0 0 0 0 0 0 0 0 0 0
52991 - 0 0 0 0 0 0 0 0 0 0 0 0
52992 - 0 0 0 0 0 0 0 0 0 0 0 0
52993 - 0 0 0 0 0 0 10 10 10 26 26 26
52994 - 58 58 58 90 90 90 18 18 18 2 2 6
52995 - 2 2 6 110 110 110 253 253 253 253 253 253
52996 -253 253 253 253 253 253 253 253 253 253 253 253
52997 -250 250 250 253 253 253 253 253 253 253 253 253
52998 -253 253 253 253 253 253 253 253 253 253 253 253
52999 -253 253 253 253 253 253 253 253 253 253 253 253
53000 -253 253 253 231 231 231 18 18 18 2 2 6
53001 - 2 2 6 2 2 6 2 2 6 2 2 6
53002 - 2 2 6 2 2 6 18 18 18 94 94 94
53003 - 54 54 54 26 26 26 10 10 10 0 0 0
53004 - 0 0 0 0 0 0 0 0 0 0 0 0
53005 - 0 0 0 0 0 0 0 0 0 0 0 0
53006 - 0 0 0 0 0 0 0 0 0 0 0 0
53007 - 0 0 0 0 0 0 0 0 0 0 0 0
53008 - 0 0 0 0 0 0 0 0 0 0 0 0
53009 - 0 0 0 0 0 0 0 0 0 0 0 0
53010 - 0 0 0 0 0 0 0 0 0 0 0 0
53011 - 0 0 0 0 0 0 0 0 0 0 0 0
53012 - 0 0 0 0 0 0 0 0 0 0 0 0
53013 - 0 0 0 6 6 6 22 22 22 50 50 50
53014 - 90 90 90 26 26 26 2 2 6 2 2 6
53015 - 14 14 14 195 195 195 250 250 250 253 253 253
53016 -253 253 253 253 253 253 253 253 253 253 253 253
53017 -253 253 253 253 253 253 253 253 253 253 253 253
53018 -253 253 253 253 253 253 253 253 253 253 253 253
53019 -253 253 253 253 253 253 253 253 253 253 253 253
53020 -250 250 250 242 242 242 54 54 54 2 2 6
53021 - 2 2 6 2 2 6 2 2 6 2 2 6
53022 - 2 2 6 2 2 6 2 2 6 38 38 38
53023 - 86 86 86 50 50 50 22 22 22 6 6 6
53024 - 0 0 0 0 0 0 0 0 0 0 0 0
53025 - 0 0 0 0 0 0 0 0 0 0 0 0
53026 - 0 0 0 0 0 0 0 0 0 0 0 0
53027 - 0 0 0 0 0 0 0 0 0 0 0 0
53028 - 0 0 0 0 0 0 0 0 0 0 0 0
53029 - 0 0 0 0 0 0 0 0 0 0 0 0
53030 - 0 0 0 0 0 0 0 0 0 0 0 0
53031 - 0 0 0 0 0 0 0 0 0 0 0 0
53032 - 0 0 0 0 0 0 0 0 0 0 0 0
53033 - 6 6 6 14 14 14 38 38 38 82 82 82
53034 - 34 34 34 2 2 6 2 2 6 2 2 6
53035 - 42 42 42 195 195 195 246 246 246 253 253 253
53036 -253 253 253 253 253 253 253 253 253 250 250 250
53037 -242 242 242 242 242 242 250 250 250 253 253 253
53038 -253 253 253 253 253 253 253 253 253 253 253 253
53039 -253 253 253 250 250 250 246 246 246 238 238 238
53040 -226 226 226 231 231 231 101 101 101 6 6 6
53041 - 2 2 6 2 2 6 2 2 6 2 2 6
53042 - 2 2 6 2 2 6 2 2 6 2 2 6
53043 - 38 38 38 82 82 82 42 42 42 14 14 14
53044 - 6 6 6 0 0 0 0 0 0 0 0 0
53045 - 0 0 0 0 0 0 0 0 0 0 0 0
53046 - 0 0 0 0 0 0 0 0 0 0 0 0
53047 - 0 0 0 0 0 0 0 0 0 0 0 0
53048 - 0 0 0 0 0 0 0 0 0 0 0 0
53049 - 0 0 0 0 0 0 0 0 0 0 0 0
53050 - 0 0 0 0 0 0 0 0 0 0 0 0
53051 - 0 0 0 0 0 0 0 0 0 0 0 0
53052 - 0 0 0 0 0 0 0 0 0 0 0 0
53053 - 10 10 10 26 26 26 62 62 62 66 66 66
53054 - 2 2 6 2 2 6 2 2 6 6 6 6
53055 - 70 70 70 170 170 170 206 206 206 234 234 234
53056 -246 246 246 250 250 250 250 250 250 238 238 238
53057 -226 226 226 231 231 231 238 238 238 250 250 250
53058 -250 250 250 250 250 250 246 246 246 231 231 231
53059 -214 214 214 206 206 206 202 202 202 202 202 202
53060 -198 198 198 202 202 202 182 182 182 18 18 18
53061 - 2 2 6 2 2 6 2 2 6 2 2 6
53062 - 2 2 6 2 2 6 2 2 6 2 2 6
53063 - 2 2 6 62 62 62 66 66 66 30 30 30
53064 - 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
53070 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 14 14 14 42 42 42 82 82 82 18 18 18
53074 - 2 2 6 2 2 6 2 2 6 10 10 10
53075 - 94 94 94 182 182 182 218 218 218 242 242 242
53076 -250 250 250 253 253 253 253 253 253 250 250 250
53077 -234 234 234 253 253 253 253 253 253 253 253 253
53078 -253 253 253 253 253 253 253 253 253 246 246 246
53079 -238 238 238 226 226 226 210 210 210 202 202 202
53080 -195 195 195 195 195 195 210 210 210 158 158 158
53081 - 6 6 6 14 14 14 50 50 50 14 14 14
53082 - 2 2 6 2 2 6 2 2 6 2 2 6
53083 - 2 2 6 6 6 6 86 86 86 46 46 46
53084 - 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
53089 - 0 0 0 0 0 0 0 0 0 0 0 0
53090 - 0 0 0 0 0 0 0 0 0 0 0 0
53091 - 0 0 0 0 0 0 0 0 0 0 0 0
53092 - 0 0 0 0 0 0 0 0 0 6 6 6
53093 - 22 22 22 54 54 54 70 70 70 2 2 6
53094 - 2 2 6 10 10 10 2 2 6 22 22 22
53095 -166 166 166 231 231 231 250 250 250 253 253 253
53096 -253 253 253 253 253 253 253 253 253 250 250 250
53097 -242 242 242 253 253 253 253 253 253 253 253 253
53098 -253 253 253 253 253 253 253 253 253 253 253 253
53099 -253 253 253 253 253 253 253 253 253 246 246 246
53100 -231 231 231 206 206 206 198 198 198 226 226 226
53101 - 94 94 94 2 2 6 6 6 6 38 38 38
53102 - 30 30 30 2 2 6 2 2 6 2 2 6
53103 - 2 2 6 2 2 6 62 62 62 66 66 66
53104 - 26 26 26 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
53109 - 0 0 0 0 0 0 0 0 0 0 0 0
53110 - 0 0 0 0 0 0 0 0 0 0 0 0
53111 - 0 0 0 0 0 0 0 0 0 0 0 0
53112 - 0 0 0 0 0 0 0 0 0 10 10 10
53113 - 30 30 30 74 74 74 50 50 50 2 2 6
53114 - 26 26 26 26 26 26 2 2 6 106 106 106
53115 -238 238 238 253 253 253 253 253 253 253 253 253
53116 -253 253 253 253 253 253 253 253 253 253 253 253
53117 -253 253 253 253 253 253 253 253 253 253 253 253
53118 -253 253 253 253 253 253 253 253 253 253 253 253
53119 -253 253 253 253 253 253 253 253 253 253 253 253
53120 -253 253 253 246 246 246 218 218 218 202 202 202
53121 -210 210 210 14 14 14 2 2 6 2 2 6
53122 - 30 30 30 22 22 22 2 2 6 2 2 6
53123 - 2 2 6 2 2 6 18 18 18 86 86 86
53124 - 42 42 42 14 14 14 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 0 0 0
53128 - 0 0 0 0 0 0 0 0 0 0 0 0
53129 - 0 0 0 0 0 0 0 0 0 0 0 0
53130 - 0 0 0 0 0 0 0 0 0 0 0 0
53131 - 0 0 0 0 0 0 0 0 0 0 0 0
53132 - 0 0 0 0 0 0 0 0 0 14 14 14
53133 - 42 42 42 90 90 90 22 22 22 2 2 6
53134 - 42 42 42 2 2 6 18 18 18 218 218 218
53135 -253 253 253 253 253 253 253 253 253 253 253 253
53136 -253 253 253 253 253 253 253 253 253 253 253 253
53137 -253 253 253 253 253 253 253 253 253 253 253 253
53138 -253 253 253 253 253 253 253 253 253 253 253 253
53139 -253 253 253 253 253 253 253 253 253 253 253 253
53140 -253 253 253 253 253 253 250 250 250 221 221 221
53141 -218 218 218 101 101 101 2 2 6 14 14 14
53142 - 18 18 18 38 38 38 10 10 10 2 2 6
53143 - 2 2 6 2 2 6 2 2 6 78 78 78
53144 - 58 58 58 22 22 22 6 6 6 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 0 0 0 0 0 0
53148 - 0 0 0 0 0 0 0 0 0 0 0 0
53149 - 0 0 0 0 0 0 0 0 0 0 0 0
53150 - 0 0 0 0 0 0 0 0 0 0 0 0
53151 - 0 0 0 0 0 0 0 0 0 0 0 0
53152 - 0 0 0 0 0 0 6 6 6 18 18 18
53153 - 54 54 54 82 82 82 2 2 6 26 26 26
53154 - 22 22 22 2 2 6 123 123 123 253 253 253
53155 -253 253 253 253 253 253 253 253 253 253 253 253
53156 -253 253 253 253 253 253 253 253 253 253 253 253
53157 -253 253 253 253 253 253 253 253 253 253 253 253
53158 -253 253 253 253 253 253 253 253 253 253 253 253
53159 -253 253 253 253 253 253 253 253 253 253 253 253
53160 -253 253 253 253 253 253 253 253 253 250 250 250
53161 -238 238 238 198 198 198 6 6 6 38 38 38
53162 - 58 58 58 26 26 26 38 38 38 2 2 6
53163 - 2 2 6 2 2 6 2 2 6 46 46 46
53164 - 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0
53168 - 0 0 0 0 0 0 0 0 0 0 0 0
53169 - 0 0 0 0 0 0 0 0 0 0 0 0
53170 - 0 0 0 0 0 0 0 0 0 0 0 0
53171 - 0 0 0 0 0 0 0 0 0 0 0 0
53172 - 0 0 0 0 0 0 10 10 10 30 30 30
53173 - 74 74 74 58 58 58 2 2 6 42 42 42
53174 - 2 2 6 22 22 22 231 231 231 253 253 253
53175 -253 253 253 253 253 253 253 253 253 253 253 253
53176 -253 253 253 253 253 253 253 253 253 250 250 250
53177 -253 253 253 253 253 253 253 253 253 253 253 253
53178 -253 253 253 253 253 253 253 253 253 253 253 253
53179 -253 253 253 253 253 253 253 253 253 253 253 253
53180 -253 253 253 253 253 253 253 253 253 253 253 253
53181 -253 253 253 246 246 246 46 46 46 38 38 38
53182 - 42 42 42 14 14 14 38 38 38 14 14 14
53183 - 2 2 6 2 2 6 2 2 6 6 6 6
53184 - 86 86 86 46 46 46 14 14 14 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 - 0 0 0 0 0 0 0 0 0 0 0 0
53188 - 0 0 0 0 0 0 0 0 0 0 0 0
53189 - 0 0 0 0 0 0 0 0 0 0 0 0
53190 - 0 0 0 0 0 0 0 0 0 0 0 0
53191 - 0 0 0 0 0 0 0 0 0 0 0 0
53192 - 0 0 0 6 6 6 14 14 14 42 42 42
53193 - 90 90 90 18 18 18 18 18 18 26 26 26
53194 - 2 2 6 116 116 116 253 253 253 253 253 253
53195 -253 253 253 253 253 253 253 253 253 253 253 253
53196 -253 253 253 253 253 253 250 250 250 238 238 238
53197 -253 253 253 253 253 253 253 253 253 253 253 253
53198 -253 253 253 253 253 253 253 253 253 253 253 253
53199 -253 253 253 253 253 253 253 253 253 253 253 253
53200 -253 253 253 253 253 253 253 253 253 253 253 253
53201 -253 253 253 253 253 253 94 94 94 6 6 6
53202 - 2 2 6 2 2 6 10 10 10 34 34 34
53203 - 2 2 6 2 2 6 2 2 6 2 2 6
53204 - 74 74 74 58 58 58 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
53208 - 0 0 0 0 0 0 0 0 0 0 0 0
53209 - 0 0 0 0 0 0 0 0 0 0 0 0
53210 - 0 0 0 0 0 0 0 0 0 0 0 0
53211 - 0 0 0 0 0 0 0 0 0 0 0 0
53212 - 0 0 0 10 10 10 26 26 26 66 66 66
53213 - 82 82 82 2 2 6 38 38 38 6 6 6
53214 - 14 14 14 210 210 210 253 253 253 253 253 253
53215 -253 253 253 253 253 253 253 253 253 253 253 253
53216 -253 253 253 253 253 253 246 246 246 242 242 242
53217 -253 253 253 253 253 253 253 253 253 253 253 253
53218 -253 253 253 253 253 253 253 253 253 253 253 253
53219 -253 253 253 253 253 253 253 253 253 253 253 253
53220 -253 253 253 253 253 253 253 253 253 253 253 253
53221 -253 253 253 253 253 253 144 144 144 2 2 6
53222 - 2 2 6 2 2 6 2 2 6 46 46 46
53223 - 2 2 6 2 2 6 2 2 6 2 2 6
53224 - 42 42 42 74 74 74 30 30 30 10 10 10
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 - 0 0 0 0 0 0 0 0 0 0 0 0
53228 - 0 0 0 0 0 0 0 0 0 0 0 0
53229 - 0 0 0 0 0 0 0 0 0 0 0 0
53230 - 0 0 0 0 0 0 0 0 0 0 0 0
53231 - 0 0 0 0 0 0 0 0 0 0 0 0
53232 - 6 6 6 14 14 14 42 42 42 90 90 90
53233 - 26 26 26 6 6 6 42 42 42 2 2 6
53234 - 74 74 74 250 250 250 253 253 253 253 253 253
53235 -253 253 253 253 253 253 253 253 253 253 253 253
53236 -253 253 253 253 253 253 242 242 242 242 242 242
53237 -253 253 253 253 253 253 253 253 253 253 253 253
53238 -253 253 253 253 253 253 253 253 253 253 253 253
53239 -253 253 253 253 253 253 253 253 253 253 253 253
53240 -253 253 253 253 253 253 253 253 253 253 253 253
53241 -253 253 253 253 253 253 182 182 182 2 2 6
53242 - 2 2 6 2 2 6 2 2 6 46 46 46
53243 - 2 2 6 2 2 6 2 2 6 2 2 6
53244 - 10 10 10 86 86 86 38 38 38 10 10 10
53245 - 0 0 0 0 0 0 0 0 0 0 0 0
53246 - 0 0 0 0 0 0 0 0 0 0 0 0
53247 - 0 0 0 0 0 0 0 0 0 0 0 0
53248 - 0 0 0 0 0 0 0 0 0 0 0 0
53249 - 0 0 0 0 0 0 0 0 0 0 0 0
53250 - 0 0 0 0 0 0 0 0 0 0 0 0
53251 - 0 0 0 0 0 0 0 0 0 0 0 0
53252 - 10 10 10 26 26 26 66 66 66 82 82 82
53253 - 2 2 6 22 22 22 18 18 18 2 2 6
53254 -149 149 149 253 253 253 253 253 253 253 253 253
53255 -253 253 253 253 253 253 253 253 253 253 253 253
53256 -253 253 253 253 253 253 234 234 234 242 242 242
53257 -253 253 253 253 253 253 253 253 253 253 253 253
53258 -253 253 253 253 253 253 253 253 253 253 253 253
53259 -253 253 253 253 253 253 253 253 253 253 253 253
53260 -253 253 253 253 253 253 253 253 253 253 253 253
53261 -253 253 253 253 253 253 206 206 206 2 2 6
53262 - 2 2 6 2 2 6 2 2 6 38 38 38
53263 - 2 2 6 2 2 6 2 2 6 2 2 6
53264 - 6 6 6 86 86 86 46 46 46 14 14 14
53265 - 0 0 0 0 0 0 0 0 0 0 0 0
53266 - 0 0 0 0 0 0 0 0 0 0 0 0
53267 - 0 0 0 0 0 0 0 0 0 0 0 0
53268 - 0 0 0 0 0 0 0 0 0 0 0 0
53269 - 0 0 0 0 0 0 0 0 0 0 0 0
53270 - 0 0 0 0 0 0 0 0 0 0 0 0
53271 - 0 0 0 0 0 0 0 0 0 6 6 6
53272 - 18 18 18 46 46 46 86 86 86 18 18 18
53273 - 2 2 6 34 34 34 10 10 10 6 6 6
53274 -210 210 210 253 253 253 253 253 253 253 253 253
53275 -253 253 253 253 253 253 253 253 253 253 253 253
53276 -253 253 253 253 253 253 234 234 234 242 242 242
53277 -253 253 253 253 253 253 253 253 253 253 253 253
53278 -253 253 253 253 253 253 253 253 253 253 253 253
53279 -253 253 253 253 253 253 253 253 253 253 253 253
53280 -253 253 253 253 253 253 253 253 253 253 253 253
53281 -253 253 253 253 253 253 221 221 221 6 6 6
53282 - 2 2 6 2 2 6 6 6 6 30 30 30
53283 - 2 2 6 2 2 6 2 2 6 2 2 6
53284 - 2 2 6 82 82 82 54 54 54 18 18 18
53285 - 6 6 6 0 0 0 0 0 0 0 0 0
53286 - 0 0 0 0 0 0 0 0 0 0 0 0
53287 - 0 0 0 0 0 0 0 0 0 0 0 0
53288 - 0 0 0 0 0 0 0 0 0 0 0 0
53289 - 0 0 0 0 0 0 0 0 0 0 0 0
53290 - 0 0 0 0 0 0 0 0 0 0 0 0
53291 - 0 0 0 0 0 0 0 0 0 10 10 10
53292 - 26 26 26 66 66 66 62 62 62 2 2 6
53293 - 2 2 6 38 38 38 10 10 10 26 26 26
53294 -238 238 238 253 253 253 253 253 253 253 253 253
53295 -253 253 253 253 253 253 253 253 253 253 253 253
53296 -253 253 253 253 253 253 231 231 231 238 238 238
53297 -253 253 253 253 253 253 253 253 253 253 253 253
53298 -253 253 253 253 253 253 253 253 253 253 253 253
53299 -253 253 253 253 253 253 253 253 253 253 253 253
53300 -253 253 253 253 253 253 253 253 253 253 253 253
53301 -253 253 253 253 253 253 231 231 231 6 6 6
53302 - 2 2 6 2 2 6 10 10 10 30 30 30
53303 - 2 2 6 2 2 6 2 2 6 2 2 6
53304 - 2 2 6 66 66 66 58 58 58 22 22 22
53305 - 6 6 6 0 0 0 0 0 0 0 0 0
53306 - 0 0 0 0 0 0 0 0 0 0 0 0
53307 - 0 0 0 0 0 0 0 0 0 0 0 0
53308 - 0 0 0 0 0 0 0 0 0 0 0 0
53309 - 0 0 0 0 0 0 0 0 0 0 0 0
53310 - 0 0 0 0 0 0 0 0 0 0 0 0
53311 - 0 0 0 0 0 0 0 0 0 10 10 10
53312 - 38 38 38 78 78 78 6 6 6 2 2 6
53313 - 2 2 6 46 46 46 14 14 14 42 42 42
53314 -246 246 246 253 253 253 253 253 253 253 253 253
53315 -253 253 253 253 253 253 253 253 253 253 253 253
53316 -253 253 253 253 253 253 231 231 231 242 242 242
53317 -253 253 253 253 253 253 253 253 253 253 253 253
53318 -253 253 253 253 253 253 253 253 253 253 253 253
53319 -253 253 253 253 253 253 253 253 253 253 253 253
53320 -253 253 253 253 253 253 253 253 253 253 253 253
53321 -253 253 253 253 253 253 234 234 234 10 10 10
53322 - 2 2 6 2 2 6 22 22 22 14 14 14
53323 - 2 2 6 2 2 6 2 2 6 2 2 6
53324 - 2 2 6 66 66 66 62 62 62 22 22 22
53325 - 6 6 6 0 0 0 0 0 0 0 0 0
53326 - 0 0 0 0 0 0 0 0 0 0 0 0
53327 - 0 0 0 0 0 0 0 0 0 0 0 0
53328 - 0 0 0 0 0 0 0 0 0 0 0 0
53329 - 0 0 0 0 0 0 0 0 0 0 0 0
53330 - 0 0 0 0 0 0 0 0 0 0 0 0
53331 - 0 0 0 0 0 0 6 6 6 18 18 18
53332 - 50 50 50 74 74 74 2 2 6 2 2 6
53333 - 14 14 14 70 70 70 34 34 34 62 62 62
53334 -250 250 250 253 253 253 253 253 253 253 253 253
53335 -253 253 253 253 253 253 253 253 253 253 253 253
53336 -253 253 253 253 253 253 231 231 231 246 246 246
53337 -253 253 253 253 253 253 253 253 253 253 253 253
53338 -253 253 253 253 253 253 253 253 253 253 253 253
53339 -253 253 253 253 253 253 253 253 253 253 253 253
53340 -253 253 253 253 253 253 253 253 253 253 253 253
53341 -253 253 253 253 253 253 234 234 234 14 14 14
53342 - 2 2 6 2 2 6 30 30 30 2 2 6
53343 - 2 2 6 2 2 6 2 2 6 2 2 6
53344 - 2 2 6 66 66 66 62 62 62 22 22 22
53345 - 6 6 6 0 0 0 0 0 0 0 0 0
53346 - 0 0 0 0 0 0 0 0 0 0 0 0
53347 - 0 0 0 0 0 0 0 0 0 0 0 0
53348 - 0 0 0 0 0 0 0 0 0 0 0 0
53349 - 0 0 0 0 0 0 0 0 0 0 0 0
53350 - 0 0 0 0 0 0 0 0 0 0 0 0
53351 - 0 0 0 0 0 0 6 6 6 18 18 18
53352 - 54 54 54 62 62 62 2 2 6 2 2 6
53353 - 2 2 6 30 30 30 46 46 46 70 70 70
53354 -250 250 250 253 253 253 253 253 253 253 253 253
53355 -253 253 253 253 253 253 253 253 253 253 253 253
53356 -253 253 253 253 253 253 231 231 231 246 246 246
53357 -253 253 253 253 253 253 253 253 253 253 253 253
53358 -253 253 253 253 253 253 253 253 253 253 253 253
53359 -253 253 253 253 253 253 253 253 253 253 253 253
53360 -253 253 253 253 253 253 253 253 253 253 253 253
53361 -253 253 253 253 253 253 226 226 226 10 10 10
53362 - 2 2 6 6 6 6 30 30 30 2 2 6
53363 - 2 2 6 2 2 6 2 2 6 2 2 6
53364 - 2 2 6 66 66 66 58 58 58 22 22 22
53365 - 6 6 6 0 0 0 0 0 0 0 0 0
53366 - 0 0 0 0 0 0 0 0 0 0 0 0
53367 - 0 0 0 0 0 0 0 0 0 0 0 0
53368 - 0 0 0 0 0 0 0 0 0 0 0 0
53369 - 0 0 0 0 0 0 0 0 0 0 0 0
53370 - 0 0 0 0 0 0 0 0 0 0 0 0
53371 - 0 0 0 0 0 0 6 6 6 22 22 22
53372 - 58 58 58 62 62 62 2 2 6 2 2 6
53373 - 2 2 6 2 2 6 30 30 30 78 78 78
53374 -250 250 250 253 253 253 253 253 253 253 253 253
53375 -253 253 253 253 253 253 253 253 253 253 253 253
53376 -253 253 253 253 253 253 231 231 231 246 246 246
53377 -253 253 253 253 253 253 253 253 253 253 253 253
53378 -253 253 253 253 253 253 253 253 253 253 253 253
53379 -253 253 253 253 253 253 253 253 253 253 253 253
53380 -253 253 253 253 253 253 253 253 253 253 253 253
53381 -253 253 253 253 253 253 206 206 206 2 2 6
53382 - 22 22 22 34 34 34 18 14 6 22 22 22
53383 - 26 26 26 18 18 18 6 6 6 2 2 6
53384 - 2 2 6 82 82 82 54 54 54 18 18 18
53385 - 6 6 6 0 0 0 0 0 0 0 0 0
53386 - 0 0 0 0 0 0 0 0 0 0 0 0
53387 - 0 0 0 0 0 0 0 0 0 0 0 0
53388 - 0 0 0 0 0 0 0 0 0 0 0 0
53389 - 0 0 0 0 0 0 0 0 0 0 0 0
53390 - 0 0 0 0 0 0 0 0 0 0 0 0
53391 - 0 0 0 0 0 0 6 6 6 26 26 26
53392 - 62 62 62 106 106 106 74 54 14 185 133 11
53393 -210 162 10 121 92 8 6 6 6 62 62 62
53394 -238 238 238 253 253 253 253 253 253 253 253 253
53395 -253 253 253 253 253 253 253 253 253 253 253 253
53396 -253 253 253 253 253 253 231 231 231 246 246 246
53397 -253 253 253 253 253 253 253 253 253 253 253 253
53398 -253 253 253 253 253 253 253 253 253 253 253 253
53399 -253 253 253 253 253 253 253 253 253 253 253 253
53400 -253 253 253 253 253 253 253 253 253 253 253 253
53401 -253 253 253 253 253 253 158 158 158 18 18 18
53402 - 14 14 14 2 2 6 2 2 6 2 2 6
53403 - 6 6 6 18 18 18 66 66 66 38 38 38
53404 - 6 6 6 94 94 94 50 50 50 18 18 18
53405 - 6 6 6 0 0 0 0 0 0 0 0 0
53406 - 0 0 0 0 0 0 0 0 0 0 0 0
53407 - 0 0 0 0 0 0 0 0 0 0 0 0
53408 - 0 0 0 0 0 0 0 0 0 0 0 0
53409 - 0 0 0 0 0 0 0 0 0 0 0 0
53410 - 0 0 0 0 0 0 0 0 0 6 6 6
53411 - 10 10 10 10 10 10 18 18 18 38 38 38
53412 - 78 78 78 142 134 106 216 158 10 242 186 14
53413 -246 190 14 246 190 14 156 118 10 10 10 10
53414 - 90 90 90 238 238 238 253 253 253 253 253 253
53415 -253 253 253 253 253 253 253 253 253 253 253 253
53416 -253 253 253 253 253 253 231 231 231 250 250 250
53417 -253 253 253 253 253 253 253 253 253 253 253 253
53418 -253 253 253 253 253 253 253 253 253 253 253 253
53419 -253 253 253 253 253 253 253 253 253 253 253 253
53420 -253 253 253 253 253 253 253 253 253 246 230 190
53421 -238 204 91 238 204 91 181 142 44 37 26 9
53422 - 2 2 6 2 2 6 2 2 6 2 2 6
53423 - 2 2 6 2 2 6 38 38 38 46 46 46
53424 - 26 26 26 106 106 106 54 54 54 18 18 18
53425 - 6 6 6 0 0 0 0 0 0 0 0 0
53426 - 0 0 0 0 0 0 0 0 0 0 0 0
53427 - 0 0 0 0 0 0 0 0 0 0 0 0
53428 - 0 0 0 0 0 0 0 0 0 0 0 0
53429 - 0 0 0 0 0 0 0 0 0 0 0 0
53430 - 0 0 0 6 6 6 14 14 14 22 22 22
53431 - 30 30 30 38 38 38 50 50 50 70 70 70
53432 -106 106 106 190 142 34 226 170 11 242 186 14
53433 -246 190 14 246 190 14 246 190 14 154 114 10
53434 - 6 6 6 74 74 74 226 226 226 253 253 253
53435 -253 253 253 253 253 253 253 253 253 253 253 253
53436 -253 253 253 253 253 253 231 231 231 250 250 250
53437 -253 253 253 253 253 253 253 253 253 253 253 253
53438 -253 253 253 253 253 253 253 253 253 253 253 253
53439 -253 253 253 253 253 253 253 253 253 253 253 253
53440 -253 253 253 253 253 253 253 253 253 228 184 62
53441 -241 196 14 241 208 19 232 195 16 38 30 10
53442 - 2 2 6 2 2 6 2 2 6 2 2 6
53443 - 2 2 6 6 6 6 30 30 30 26 26 26
53444 -203 166 17 154 142 90 66 66 66 26 26 26
53445 - 6 6 6 0 0 0 0 0 0 0 0 0
53446 - 0 0 0 0 0 0 0 0 0 0 0 0
53447 - 0 0 0 0 0 0 0 0 0 0 0 0
53448 - 0 0 0 0 0 0 0 0 0 0 0 0
53449 - 0 0 0 0 0 0 0 0 0 0 0 0
53450 - 6 6 6 18 18 18 38 38 38 58 58 58
53451 - 78 78 78 86 86 86 101 101 101 123 123 123
53452 -175 146 61 210 150 10 234 174 13 246 186 14
53453 -246 190 14 246 190 14 246 190 14 238 190 10
53454 -102 78 10 2 2 6 46 46 46 198 198 198
53455 -253 253 253 253 253 253 253 253 253 253 253 253
53456 -253 253 253 253 253 253 234 234 234 242 242 242
53457 -253 253 253 253 253 253 253 253 253 253 253 253
53458 -253 253 253 253 253 253 253 253 253 253 253 253
53459 -253 253 253 253 253 253 253 253 253 253 253 253
53460 -253 253 253 253 253 253 253 253 253 224 178 62
53461 -242 186 14 241 196 14 210 166 10 22 18 6
53462 - 2 2 6 2 2 6 2 2 6 2 2 6
53463 - 2 2 6 2 2 6 6 6 6 121 92 8
53464 -238 202 15 232 195 16 82 82 82 34 34 34
53465 - 10 10 10 0 0 0 0 0 0 0 0 0
53466 - 0 0 0 0 0 0 0 0 0 0 0 0
53467 - 0 0 0 0 0 0 0 0 0 0 0 0
53468 - 0 0 0 0 0 0 0 0 0 0 0 0
53469 - 0 0 0 0 0 0 0 0 0 0 0 0
53470 - 14 14 14 38 38 38 70 70 70 154 122 46
53471 -190 142 34 200 144 11 197 138 11 197 138 11
53472 -213 154 11 226 170 11 242 186 14 246 190 14
53473 -246 190 14 246 190 14 246 190 14 246 190 14
53474 -225 175 15 46 32 6 2 2 6 22 22 22
53475 -158 158 158 250 250 250 253 253 253 253 253 253
53476 -253 253 253 253 253 253 253 253 253 253 253 253
53477 -253 253 253 253 253 253 253 253 253 253 253 253
53478 -253 253 253 253 253 253 253 253 253 253 253 253
53479 -253 253 253 253 253 253 253 253 253 253 253 253
53480 -253 253 253 250 250 250 242 242 242 224 178 62
53481 -239 182 13 236 186 11 213 154 11 46 32 6
53482 - 2 2 6 2 2 6 2 2 6 2 2 6
53483 - 2 2 6 2 2 6 61 42 6 225 175 15
53484 -238 190 10 236 186 11 112 100 78 42 42 42
53485 - 14 14 14 0 0 0 0 0 0 0 0 0
53486 - 0 0 0 0 0 0 0 0 0 0 0 0
53487 - 0 0 0 0 0 0 0 0 0 0 0 0
53488 - 0 0 0 0 0 0 0 0 0 0 0 0
53489 - 0 0 0 0 0 0 0 0 0 6 6 6
53490 - 22 22 22 54 54 54 154 122 46 213 154 11
53491 -226 170 11 230 174 11 226 170 11 226 170 11
53492 -236 178 12 242 186 14 246 190 14 246 190 14
53493 -246 190 14 246 190 14 246 190 14 246 190 14
53494 -241 196 14 184 144 12 10 10 10 2 2 6
53495 - 6 6 6 116 116 116 242 242 242 253 253 253
53496 -253 253 253 253 253 253 253 253 253 253 253 253
53497 -253 253 253 253 253 253 253 253 253 253 253 253
53498 -253 253 253 253 253 253 253 253 253 253 253 253
53499 -253 253 253 253 253 253 253 253 253 253 253 253
53500 -253 253 253 231 231 231 198 198 198 214 170 54
53501 -236 178 12 236 178 12 210 150 10 137 92 6
53502 - 18 14 6 2 2 6 2 2 6 2 2 6
53503 - 6 6 6 70 47 6 200 144 11 236 178 12
53504 -239 182 13 239 182 13 124 112 88 58 58 58
53505 - 22 22 22 6 6 6 0 0 0 0 0 0
53506 - 0 0 0 0 0 0 0 0 0 0 0 0
53507 - 0 0 0 0 0 0 0 0 0 0 0 0
53508 - 0 0 0 0 0 0 0 0 0 0 0 0
53509 - 0 0 0 0 0 0 0 0 0 10 10 10
53510 - 30 30 30 70 70 70 180 133 36 226 170 11
53511 -239 182 13 242 186 14 242 186 14 246 186 14
53512 -246 190 14 246 190 14 246 190 14 246 190 14
53513 -246 190 14 246 190 14 246 190 14 246 190 14
53514 -246 190 14 232 195 16 98 70 6 2 2 6
53515 - 2 2 6 2 2 6 66 66 66 221 221 221
53516 -253 253 253 253 253 253 253 253 253 253 253 253
53517 -253 253 253 253 253 253 253 253 253 253 253 253
53518 -253 253 253 253 253 253 253 253 253 253 253 253
53519 -253 253 253 253 253 253 253 253 253 253 253 253
53520 -253 253 253 206 206 206 198 198 198 214 166 58
53521 -230 174 11 230 174 11 216 158 10 192 133 9
53522 -163 110 8 116 81 8 102 78 10 116 81 8
53523 -167 114 7 197 138 11 226 170 11 239 182 13
53524 -242 186 14 242 186 14 162 146 94 78 78 78
53525 - 34 34 34 14 14 14 6 6 6 0 0 0
53526 - 0 0 0 0 0 0 0 0 0 0 0 0
53527 - 0 0 0 0 0 0 0 0 0 0 0 0
53528 - 0 0 0 0 0 0 0 0 0 0 0 0
53529 - 0 0 0 0 0 0 0 0 0 6 6 6
53530 - 30 30 30 78 78 78 190 142 34 226 170 11
53531 -239 182 13 246 190 14 246 190 14 246 190 14
53532 -246 190 14 246 190 14 246 190 14 246 190 14
53533 -246 190 14 246 190 14 246 190 14 246 190 14
53534 -246 190 14 241 196 14 203 166 17 22 18 6
53535 - 2 2 6 2 2 6 2 2 6 38 38 38
53536 -218 218 218 253 253 253 253 253 253 253 253 253
53537 -253 253 253 253 253 253 253 253 253 253 253 253
53538 -253 253 253 253 253 253 253 253 253 253 253 253
53539 -253 253 253 253 253 253 253 253 253 253 253 253
53540 -250 250 250 206 206 206 198 198 198 202 162 69
53541 -226 170 11 236 178 12 224 166 10 210 150 10
53542 -200 144 11 197 138 11 192 133 9 197 138 11
53543 -210 150 10 226 170 11 242 186 14 246 190 14
53544 -246 190 14 246 186 14 225 175 15 124 112 88
53545 - 62 62 62 30 30 30 14 14 14 6 6 6
53546 - 0 0 0 0 0 0 0 0 0 0 0 0
53547 - 0 0 0 0 0 0 0 0 0 0 0 0
53548 - 0 0 0 0 0 0 0 0 0 0 0 0
53549 - 0 0 0 0 0 0 0 0 0 10 10 10
53550 - 30 30 30 78 78 78 174 135 50 224 166 10
53551 -239 182 13 246 190 14 246 190 14 246 190 14
53552 -246 190 14 246 190 14 246 190 14 246 190 14
53553 -246 190 14 246 190 14 246 190 14 246 190 14
53554 -246 190 14 246 190 14 241 196 14 139 102 15
53555 - 2 2 6 2 2 6 2 2 6 2 2 6
53556 - 78 78 78 250 250 250 253 253 253 253 253 253
53557 -253 253 253 253 253 253 253 253 253 253 253 253
53558 -253 253 253 253 253 253 253 253 253 253 253 253
53559 -253 253 253 253 253 253 253 253 253 253 253 253
53560 -250 250 250 214 214 214 198 198 198 190 150 46
53561 -219 162 10 236 178 12 234 174 13 224 166 10
53562 -216 158 10 213 154 11 213 154 11 216 158 10
53563 -226 170 11 239 182 13 246 190 14 246 190 14
53564 -246 190 14 246 190 14 242 186 14 206 162 42
53565 -101 101 101 58 58 58 30 30 30 14 14 14
53566 - 6 6 6 0 0 0 0 0 0 0 0 0
53567 - 0 0 0 0 0 0 0 0 0 0 0 0
53568 - 0 0 0 0 0 0 0 0 0 0 0 0
53569 - 0 0 0 0 0 0 0 0 0 10 10 10
53570 - 30 30 30 74 74 74 174 135 50 216 158 10
53571 -236 178 12 246 190 14 246 190 14 246 190 14
53572 -246 190 14 246 190 14 246 190 14 246 190 14
53573 -246 190 14 246 190 14 246 190 14 246 190 14
53574 -246 190 14 246 190 14 241 196 14 226 184 13
53575 - 61 42 6 2 2 6 2 2 6 2 2 6
53576 - 22 22 22 238 238 238 253 253 253 253 253 253
53577 -253 253 253 253 253 253 253 253 253 253 253 253
53578 -253 253 253 253 253 253 253 253 253 253 253 253
53579 -253 253 253 253 253 253 253 253 253 253 253 253
53580 -253 253 253 226 226 226 187 187 187 180 133 36
53581 -216 158 10 236 178 12 239 182 13 236 178 12
53582 -230 174 11 226 170 11 226 170 11 230 174 11
53583 -236 178 12 242 186 14 246 190 14 246 190 14
53584 -246 190 14 246 190 14 246 186 14 239 182 13
53585 -206 162 42 106 106 106 66 66 66 34 34 34
53586 - 14 14 14 6 6 6 0 0 0 0 0 0
53587 - 0 0 0 0 0 0 0 0 0 0 0 0
53588 - 0 0 0 0 0 0 0 0 0 0 0 0
53589 - 0 0 0 0 0 0 0 0 0 6 6 6
53590 - 26 26 26 70 70 70 163 133 67 213 154 11
53591 -236 178 12 246 190 14 246 190 14 246 190 14
53592 -246 190 14 246 190 14 246 190 14 246 190 14
53593 -246 190 14 246 190 14 246 190 14 246 190 14
53594 -246 190 14 246 190 14 246 190 14 241 196 14
53595 -190 146 13 18 14 6 2 2 6 2 2 6
53596 - 46 46 46 246 246 246 253 253 253 253 253 253
53597 -253 253 253 253 253 253 253 253 253 253 253 253
53598 -253 253 253 253 253 253 253 253 253 253 253 253
53599 -253 253 253 253 253 253 253 253 253 253 253 253
53600 -253 253 253 221 221 221 86 86 86 156 107 11
53601 -216 158 10 236 178 12 242 186 14 246 186 14
53602 -242 186 14 239 182 13 239 182 13 242 186 14
53603 -242 186 14 246 186 14 246 190 14 246 190 14
53604 -246 190 14 246 190 14 246 190 14 246 190 14
53605 -242 186 14 225 175 15 142 122 72 66 66 66
53606 - 30 30 30 10 10 10 0 0 0 0 0 0
53607 - 0 0 0 0 0 0 0 0 0 0 0 0
53608 - 0 0 0 0 0 0 0 0 0 0 0 0
53609 - 0 0 0 0 0 0 0 0 0 6 6 6
53610 - 26 26 26 70 70 70 163 133 67 210 150 10
53611 -236 178 12 246 190 14 246 190 14 246 190 14
53612 -246 190 14 246 190 14 246 190 14 246 190 14
53613 -246 190 14 246 190 14 246 190 14 246 190 14
53614 -246 190 14 246 190 14 246 190 14 246 190 14
53615 -232 195 16 121 92 8 34 34 34 106 106 106
53616 -221 221 221 253 253 253 253 253 253 253 253 253
53617 -253 253 253 253 253 253 253 253 253 253 253 253
53618 -253 253 253 253 253 253 253 253 253 253 253 253
53619 -253 253 253 253 253 253 253 253 253 253 253 253
53620 -242 242 242 82 82 82 18 14 6 163 110 8
53621 -216 158 10 236 178 12 242 186 14 246 190 14
53622 -246 190 14 246 190 14 246 190 14 246 190 14
53623 -246 190 14 246 190 14 246 190 14 246 190 14
53624 -246 190 14 246 190 14 246 190 14 246 190 14
53625 -246 190 14 246 190 14 242 186 14 163 133 67
53626 - 46 46 46 18 18 18 6 6 6 0 0 0
53627 - 0 0 0 0 0 0 0 0 0 0 0 0
53628 - 0 0 0 0 0 0 0 0 0 0 0 0
53629 - 0 0 0 0 0 0 0 0 0 10 10 10
53630 - 30 30 30 78 78 78 163 133 67 210 150 10
53631 -236 178 12 246 186 14 246 190 14 246 190 14
53632 -246 190 14 246 190 14 246 190 14 246 190 14
53633 -246 190 14 246 190 14 246 190 14 246 190 14
53634 -246 190 14 246 190 14 246 190 14 246 190 14
53635 -241 196 14 215 174 15 190 178 144 253 253 253
53636 -253 253 253 253 253 253 253 253 253 253 253 253
53637 -253 253 253 253 253 253 253 253 253 253 253 253
53638 -253 253 253 253 253 253 253 253 253 253 253 253
53639 -253 253 253 253 253 253 253 253 253 218 218 218
53640 - 58 58 58 2 2 6 22 18 6 167 114 7
53641 -216 158 10 236 178 12 246 186 14 246 190 14
53642 -246 190 14 246 190 14 246 190 14 246 190 14
53643 -246 190 14 246 190 14 246 190 14 246 190 14
53644 -246 190 14 246 190 14 246 190 14 246 190 14
53645 -246 190 14 246 186 14 242 186 14 190 150 46
53646 - 54 54 54 22 22 22 6 6 6 0 0 0
53647 - 0 0 0 0 0 0 0 0 0 0 0 0
53648 - 0 0 0 0 0 0 0 0 0 0 0 0
53649 - 0 0 0 0 0 0 0 0 0 14 14 14
53650 - 38 38 38 86 86 86 180 133 36 213 154 11
53651 -236 178 12 246 186 14 246 190 14 246 190 14
53652 -246 190 14 246 190 14 246 190 14 246 190 14
53653 -246 190 14 246 190 14 246 190 14 246 190 14
53654 -246 190 14 246 190 14 246 190 14 246 190 14
53655 -246 190 14 232 195 16 190 146 13 214 214 214
53656 -253 253 253 253 253 253 253 253 253 253 253 253
53657 -253 253 253 253 253 253 253 253 253 253 253 253
53658 -253 253 253 253 253 253 253 253 253 253 253 253
53659 -253 253 253 250 250 250 170 170 170 26 26 26
53660 - 2 2 6 2 2 6 37 26 9 163 110 8
53661 -219 162 10 239 182 13 246 186 14 246 190 14
53662 -246 190 14 246 190 14 246 190 14 246 190 14
53663 -246 190 14 246 190 14 246 190 14 246 190 14
53664 -246 190 14 246 190 14 246 190 14 246 190 14
53665 -246 186 14 236 178 12 224 166 10 142 122 72
53666 - 46 46 46 18 18 18 6 6 6 0 0 0
53667 - 0 0 0 0 0 0 0 0 0 0 0 0
53668 - 0 0 0 0 0 0 0 0 0 0 0 0
53669 - 0 0 0 0 0 0 6 6 6 18 18 18
53670 - 50 50 50 109 106 95 192 133 9 224 166 10
53671 -242 186 14 246 190 14 246 190 14 246 190 14
53672 -246 190 14 246 190 14 246 190 14 246 190 14
53673 -246 190 14 246 190 14 246 190 14 246 190 14
53674 -246 190 14 246 190 14 246 190 14 246 190 14
53675 -242 186 14 226 184 13 210 162 10 142 110 46
53676 -226 226 226 253 253 253 253 253 253 253 253 253
53677 -253 253 253 253 253 253 253 253 253 253 253 253
53678 -253 253 253 253 253 253 253 253 253 253 253 253
53679 -198 198 198 66 66 66 2 2 6 2 2 6
53680 - 2 2 6 2 2 6 50 34 6 156 107 11
53681 -219 162 10 239 182 13 246 186 14 246 190 14
53682 -246 190 14 246 190 14 246 190 14 246 190 14
53683 -246 190 14 246 190 14 246 190 14 246 190 14
53684 -246 190 14 246 190 14 246 190 14 242 186 14
53685 -234 174 13 213 154 11 154 122 46 66 66 66
53686 - 30 30 30 10 10 10 0 0 0 0 0 0
53687 - 0 0 0 0 0 0 0 0 0 0 0 0
53688 - 0 0 0 0 0 0 0 0 0 0 0 0
53689 - 0 0 0 0 0 0 6 6 6 22 22 22
53690 - 58 58 58 154 121 60 206 145 10 234 174 13
53691 -242 186 14 246 186 14 246 190 14 246 190 14
53692 -246 190 14 246 190 14 246 190 14 246 190 14
53693 -246 190 14 246 190 14 246 190 14 246 190 14
53694 -246 190 14 246 190 14 246 190 14 246 190 14
53695 -246 186 14 236 178 12 210 162 10 163 110 8
53696 - 61 42 6 138 138 138 218 218 218 250 250 250
53697 -253 253 253 253 253 253 253 253 253 250 250 250
53698 -242 242 242 210 210 210 144 144 144 66 66 66
53699 - 6 6 6 2 2 6 2 2 6 2 2 6
53700 - 2 2 6 2 2 6 61 42 6 163 110 8
53701 -216 158 10 236 178 12 246 190 14 246 190 14
53702 -246 190 14 246 190 14 246 190 14 246 190 14
53703 -246 190 14 246 190 14 246 190 14 246 190 14
53704 -246 190 14 239 182 13 230 174 11 216 158 10
53705 -190 142 34 124 112 88 70 70 70 38 38 38
53706 - 18 18 18 6 6 6 0 0 0 0 0 0
53707 - 0 0 0 0 0 0 0 0 0 0 0 0
53708 - 0 0 0 0 0 0 0 0 0 0 0 0
53709 - 0 0 0 0 0 0 6 6 6 22 22 22
53710 - 62 62 62 168 124 44 206 145 10 224 166 10
53711 -236 178 12 239 182 13 242 186 14 242 186 14
53712 -246 186 14 246 190 14 246 190 14 246 190 14
53713 -246 190 14 246 190 14 246 190 14 246 190 14
53714 -246 190 14 246 190 14 246 190 14 246 190 14
53715 -246 190 14 236 178 12 216 158 10 175 118 6
53716 - 80 54 7 2 2 6 6 6 6 30 30 30
53717 - 54 54 54 62 62 62 50 50 50 38 38 38
53718 - 14 14 14 2 2 6 2 2 6 2 2 6
53719 - 2 2 6 2 2 6 2 2 6 2 2 6
53720 - 2 2 6 6 6 6 80 54 7 167 114 7
53721 -213 154 11 236 178 12 246 190 14 246 190 14
53722 -246 190 14 246 190 14 246 190 14 246 190 14
53723 -246 190 14 242 186 14 239 182 13 239 182 13
53724 -230 174 11 210 150 10 174 135 50 124 112 88
53725 - 82 82 82 54 54 54 34 34 34 18 18 18
53726 - 6 6 6 0 0 0 0 0 0 0 0 0
53727 - 0 0 0 0 0 0 0 0 0 0 0 0
53728 - 0 0 0 0 0 0 0 0 0 0 0 0
53729 - 0 0 0 0 0 0 6 6 6 18 18 18
53730 - 50 50 50 158 118 36 192 133 9 200 144 11
53731 -216 158 10 219 162 10 224 166 10 226 170 11
53732 -230 174 11 236 178 12 239 182 13 239 182 13
53733 -242 186 14 246 186 14 246 190 14 246 190 14
53734 -246 190 14 246 190 14 246 190 14 246 190 14
53735 -246 186 14 230 174 11 210 150 10 163 110 8
53736 -104 69 6 10 10 10 2 2 6 2 2 6
53737 - 2 2 6 2 2 6 2 2 6 2 2 6
53738 - 2 2 6 2 2 6 2 2 6 2 2 6
53739 - 2 2 6 2 2 6 2 2 6 2 2 6
53740 - 2 2 6 6 6 6 91 60 6 167 114 7
53741 -206 145 10 230 174 11 242 186 14 246 190 14
53742 -246 190 14 246 190 14 246 186 14 242 186 14
53743 -239 182 13 230 174 11 224 166 10 213 154 11
53744 -180 133 36 124 112 88 86 86 86 58 58 58
53745 - 38 38 38 22 22 22 10 10 10 6 6 6
53746 - 0 0 0 0 0 0 0 0 0 0 0 0
53747 - 0 0 0 0 0 0 0 0 0 0 0 0
53748 - 0 0 0 0 0 0 0 0 0 0 0 0
53749 - 0 0 0 0 0 0 0 0 0 14 14 14
53750 - 34 34 34 70 70 70 138 110 50 158 118 36
53751 -167 114 7 180 123 7 192 133 9 197 138 11
53752 -200 144 11 206 145 10 213 154 11 219 162 10
53753 -224 166 10 230 174 11 239 182 13 242 186 14
53754 -246 186 14 246 186 14 246 186 14 246 186 14
53755 -239 182 13 216 158 10 185 133 11 152 99 6
53756 -104 69 6 18 14 6 2 2 6 2 2 6
53757 - 2 2 6 2 2 6 2 2 6 2 2 6
53758 - 2 2 6 2 2 6 2 2 6 2 2 6
53759 - 2 2 6 2 2 6 2 2 6 2 2 6
53760 - 2 2 6 6 6 6 80 54 7 152 99 6
53761 -192 133 9 219 162 10 236 178 12 239 182 13
53762 -246 186 14 242 186 14 239 182 13 236 178 12
53763 -224 166 10 206 145 10 192 133 9 154 121 60
53764 - 94 94 94 62 62 62 42 42 42 22 22 22
53765 - 14 14 14 6 6 6 0 0 0 0 0 0
53766 - 0 0 0 0 0 0 0 0 0 0 0 0
53767 - 0 0 0 0 0 0 0 0 0 0 0 0
53768 - 0 0 0 0 0 0 0 0 0 0 0 0
53769 - 0 0 0 0 0 0 0 0 0 6 6 6
53770 - 18 18 18 34 34 34 58 58 58 78 78 78
53771 -101 98 89 124 112 88 142 110 46 156 107 11
53772 -163 110 8 167 114 7 175 118 6 180 123 7
53773 -185 133 11 197 138 11 210 150 10 219 162 10
53774 -226 170 11 236 178 12 236 178 12 234 174 13
53775 -219 162 10 197 138 11 163 110 8 130 83 6
53776 - 91 60 6 10 10 10 2 2 6 2 2 6
53777 - 18 18 18 38 38 38 38 38 38 38 38 38
53778 - 38 38 38 38 38 38 38 38 38 38 38 38
53779 - 38 38 38 38 38 38 26 26 26 2 2 6
53780 - 2 2 6 6 6 6 70 47 6 137 92 6
53781 -175 118 6 200 144 11 219 162 10 230 174 11
53782 -234 174 13 230 174 11 219 162 10 210 150 10
53783 -192 133 9 163 110 8 124 112 88 82 82 82
53784 - 50 50 50 30 30 30 14 14 14 6 6 6
53785 - 0 0 0 0 0 0 0 0 0 0 0 0
53786 - 0 0 0 0 0 0 0 0 0 0 0 0
53787 - 0 0 0 0 0 0 0 0 0 0 0 0
53788 - 0 0 0 0 0 0 0 0 0 0 0 0
53789 - 0 0 0 0 0 0 0 0 0 0 0 0
53790 - 6 6 6 14 14 14 22 22 22 34 34 34
53791 - 42 42 42 58 58 58 74 74 74 86 86 86
53792 -101 98 89 122 102 70 130 98 46 121 87 25
53793 -137 92 6 152 99 6 163 110 8 180 123 7
53794 -185 133 11 197 138 11 206 145 10 200 144 11
53795 -180 123 7 156 107 11 130 83 6 104 69 6
53796 - 50 34 6 54 54 54 110 110 110 101 98 89
53797 - 86 86 86 82 82 82 78 78 78 78 78 78
53798 - 78 78 78 78 78 78 78 78 78 78 78 78
53799 - 78 78 78 82 82 82 86 86 86 94 94 94
53800 -106 106 106 101 101 101 86 66 34 124 80 6
53801 -156 107 11 180 123 7 192 133 9 200 144 11
53802 -206 145 10 200 144 11 192 133 9 175 118 6
53803 -139 102 15 109 106 95 70 70 70 42 42 42
53804 - 22 22 22 10 10 10 0 0 0 0 0 0
53805 - 0 0 0 0 0 0 0 0 0 0 0 0
53806 - 0 0 0 0 0 0 0 0 0 0 0 0
53807 - 0 0 0 0 0 0 0 0 0 0 0 0
53808 - 0 0 0 0 0 0 0 0 0 0 0 0
53809 - 0 0 0 0 0 0 0 0 0 0 0 0
53810 - 0 0 0 0 0 0 6 6 6 10 10 10
53811 - 14 14 14 22 22 22 30 30 30 38 38 38
53812 - 50 50 50 62 62 62 74 74 74 90 90 90
53813 -101 98 89 112 100 78 121 87 25 124 80 6
53814 -137 92 6 152 99 6 152 99 6 152 99 6
53815 -138 86 6 124 80 6 98 70 6 86 66 30
53816 -101 98 89 82 82 82 58 58 58 46 46 46
53817 - 38 38 38 34 34 34 34 34 34 34 34 34
53818 - 34 34 34 34 34 34 34 34 34 34 34 34
53819 - 34 34 34 34 34 34 38 38 38 42 42 42
53820 - 54 54 54 82 82 82 94 86 76 91 60 6
53821 -134 86 6 156 107 11 167 114 7 175 118 6
53822 -175 118 6 167 114 7 152 99 6 121 87 25
53823 -101 98 89 62 62 62 34 34 34 18 18 18
53824 - 6 6 6 0 0 0 0 0 0 0 0 0
53825 - 0 0 0 0 0 0 0 0 0 0 0 0
53826 - 0 0 0 0 0 0 0 0 0 0 0 0
53827 - 0 0 0 0 0 0 0 0 0 0 0 0
53828 - 0 0 0 0 0 0 0 0 0 0 0 0
53829 - 0 0 0 0 0 0 0 0 0 0 0 0
53830 - 0 0 0 0 0 0 0 0 0 0 0 0
53831 - 0 0 0 6 6 6 6 6 6 10 10 10
53832 - 18 18 18 22 22 22 30 30 30 42 42 42
53833 - 50 50 50 66 66 66 86 86 86 101 98 89
53834 -106 86 58 98 70 6 104 69 6 104 69 6
53835 -104 69 6 91 60 6 82 62 34 90 90 90
53836 - 62 62 62 38 38 38 22 22 22 14 14 14
53837 - 10 10 10 10 10 10 10 10 10 10 10 10
53838 - 10 10 10 10 10 10 6 6 6 10 10 10
53839 - 10 10 10 10 10 10 10 10 10 14 14 14
53840 - 22 22 22 42 42 42 70 70 70 89 81 66
53841 - 80 54 7 104 69 6 124 80 6 137 92 6
53842 -134 86 6 116 81 8 100 82 52 86 86 86
53843 - 58 58 58 30 30 30 14 14 14 6 6 6
53844 - 0 0 0 0 0 0 0 0 0 0 0 0
53845 - 0 0 0 0 0 0 0 0 0 0 0 0
53846 - 0 0 0 0 0 0 0 0 0 0 0 0
53847 - 0 0 0 0 0 0 0 0 0 0 0 0
53848 - 0 0 0 0 0 0 0 0 0 0 0 0
53849 - 0 0 0 0 0 0 0 0 0 0 0 0
53850 - 0 0 0 0 0 0 0 0 0 0 0 0
53851 - 0 0 0 0 0 0 0 0 0 0 0 0
53852 - 0 0 0 6 6 6 10 10 10 14 14 14
53853 - 18 18 18 26 26 26 38 38 38 54 54 54
53854 - 70 70 70 86 86 86 94 86 76 89 81 66
53855 - 89 81 66 86 86 86 74 74 74 50 50 50
53856 - 30 30 30 14 14 14 6 6 6 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 - 6 6 6 18 18 18 34 34 34 58 58 58
53861 - 82 82 82 89 81 66 89 81 66 89 81 66
53862 - 94 86 66 94 86 76 74 74 74 50 50 50
53863 - 26 26 26 14 14 14 6 6 6 0 0 0
53864 - 0 0 0 0 0 0 0 0 0 0 0 0
53865 - 0 0 0 0 0 0 0 0 0 0 0 0
53866 - 0 0 0 0 0 0 0 0 0 0 0 0
53867 - 0 0 0 0 0 0 0 0 0 0 0 0
53868 - 0 0 0 0 0 0 0 0 0 0 0 0
53869 - 0 0 0 0 0 0 0 0 0 0 0 0
53870 - 0 0 0 0 0 0 0 0 0 0 0 0
53871 - 0 0 0 0 0 0 0 0 0 0 0 0
53872 - 0 0 0 0 0 0 0 0 0 0 0 0
53873 - 6 6 6 6 6 6 14 14 14 18 18 18
53874 - 30 30 30 38 38 38 46 46 46 54 54 54
53875 - 50 50 50 42 42 42 30 30 30 18 18 18
53876 - 10 10 10 0 0 0 0 0 0 0 0 0
53877 - 0 0 0 0 0 0 0 0 0 0 0 0
53878 - 0 0 0 0 0 0 0 0 0 0 0 0
53879 - 0 0 0 0 0 0 0 0 0 0 0 0
53880 - 0 0 0 6 6 6 14 14 14 26 26 26
53881 - 38 38 38 50 50 50 58 58 58 58 58 58
53882 - 54 54 54 42 42 42 30 30 30 18 18 18
53883 - 10 10 10 0 0 0 0 0 0 0 0 0
53884 - 0 0 0 0 0 0 0 0 0 0 0 0
53885 - 0 0 0 0 0 0 0 0 0 0 0 0
53886 - 0 0 0 0 0 0 0 0 0 0 0 0
53887 - 0 0 0 0 0 0 0 0 0 0 0 0
53888 - 0 0 0 0 0 0 0 0 0 0 0 0
53889 - 0 0 0 0 0 0 0 0 0 0 0 0
53890 - 0 0 0 0 0 0 0 0 0 0 0 0
53891 - 0 0 0 0 0 0 0 0 0 0 0 0
53892 - 0 0 0 0 0 0 0 0 0 0 0 0
53893 - 0 0 0 0 0 0 0 0 0 6 6 6
53894 - 6 6 6 10 10 10 14 14 14 18 18 18
53895 - 18 18 18 14 14 14 10 10 10 6 6 6
53896 - 0 0 0 0 0 0 0 0 0 0 0 0
53897 - 0 0 0 0 0 0 0 0 0 0 0 0
53898 - 0 0 0 0 0 0 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 6 6 6
53901 - 14 14 14 18 18 18 22 22 22 22 22 22
53902 - 18 18 18 14 14 14 10 10 10 6 6 6
53903 - 0 0 0 0 0 0 0 0 0 0 0 0
53904 - 0 0 0 0 0 0 0 0 0 0 0 0
53905 - 0 0 0 0 0 0 0 0 0 0 0 0
53906 - 0 0 0 0 0 0 0 0 0 0 0 0
53907 - 0 0 0 0 0 0 0 0 0 0 0 0
53908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53921 +4 4 4 4 4 4
53922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53935 +4 4 4 4 4 4
53936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53949 +4 4 4 4 4 4
53950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53963 +4 4 4 4 4 4
53964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53977 +4 4 4 4 4 4
53978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53991 +4 4 4 4 4 4
53992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53996 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
53997 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
53998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54001 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54002 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54003 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54005 +4 4 4 4 4 4
54006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54010 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54011 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54012 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54015 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54016 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54017 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54018 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54019 +4 4 4 4 4 4
54020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54024 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54025 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54026 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54029 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54030 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54031 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54032 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54033 +4 4 4 4 4 4
54034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54037 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54038 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54039 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54040 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54042 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54043 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54044 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54045 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54046 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54047 +4 4 4 4 4 4
54048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54051 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54052 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54053 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54054 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54055 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54056 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54057 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54058 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54059 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54060 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54061 +4 4 4 4 4 4
54062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54065 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54066 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54067 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54068 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54069 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54070 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54071 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54072 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54073 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54074 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54075 +4 4 4 4 4 4
54076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54078 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54079 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54080 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54081 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54082 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54083 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54084 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54085 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54086 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54087 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54088 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54089 +4 4 4 4 4 4
54090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54092 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54093 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54094 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54095 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54096 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54097 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54098 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54099 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54100 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54101 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54102 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54103 +4 4 4 4 4 4
54104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54106 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54107 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54108 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54109 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54110 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54111 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54112 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54113 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54114 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54115 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54116 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54117 +4 4 4 4 4 4
54118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54120 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54121 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54122 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54123 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54124 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54125 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54126 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54127 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54128 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54129 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54130 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54131 +4 4 4 4 4 4
54132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54133 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54134 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54135 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54136 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54137 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54138 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54139 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54140 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54141 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54142 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54143 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54144 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54145 +4 4 4 4 4 4
54146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54147 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54148 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54149 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54150 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54151 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54152 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54153 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54154 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54155 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54156 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54157 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54158 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54159 +0 0 0 4 4 4
54160 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54161 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54162 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54163 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54164 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54165 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54166 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54167 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54168 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54169 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54170 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54171 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54172 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54173 +2 0 0 0 0 0
54174 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54175 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54176 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54177 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54178 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54179 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54180 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54181 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54182 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54183 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54184 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54185 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54186 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54187 +37 38 37 0 0 0
54188 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54189 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54190 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54191 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54192 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54193 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54194 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54195 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54196 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54197 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54198 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54199 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54200 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54201 +85 115 134 4 0 0
54202 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54203 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54204 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54205 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54206 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54207 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54208 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54209 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54210 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54211 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54212 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54213 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54214 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54215 +60 73 81 4 0 0
54216 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54217 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54218 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54219 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54220 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54221 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54222 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54223 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54224 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54225 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54226 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54227 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54228 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54229 +16 19 21 4 0 0
54230 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54231 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54232 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54233 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54234 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54235 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54236 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54237 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54238 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54239 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54240 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54241 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54242 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54243 +4 0 0 4 3 3
54244 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54245 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54246 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54248 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54249 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54250 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54251 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54252 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54253 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54254 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54255 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54256 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54257 +3 2 2 4 4 4
54258 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54259 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54260 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54261 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54262 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54263 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54264 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54265 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54266 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54267 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54268 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54269 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54270 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54271 +4 4 4 4 4 4
54272 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54273 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54274 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54275 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54276 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54277 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54278 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54279 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54280 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54281 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54282 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54283 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54284 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54285 +4 4 4 4 4 4
54286 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54287 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54288 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54289 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54290 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54291 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54292 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54293 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54294 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54295 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54296 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54297 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54298 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54299 +5 5 5 5 5 5
54300 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54301 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54302 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54303 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54304 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54305 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54306 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54307 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54308 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54309 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54310 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54311 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54312 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54313 +5 5 5 4 4 4
54314 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54315 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54316 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54317 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54318 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54319 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54320 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54321 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54322 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54323 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54324 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54325 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54327 +4 4 4 4 4 4
54328 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54329 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54330 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54331 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54332 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54333 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54334 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54335 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54336 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54337 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54338 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54339 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54341 +4 4 4 4 4 4
54342 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54343 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54344 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54345 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54346 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54347 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54348 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54349 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54350 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54351 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54352 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
54353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54355 +4 4 4 4 4 4
54356 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
54357 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54358 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54359 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54360 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54361 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54362 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54363 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
54364 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54365 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54366 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
54367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54369 +4 4 4 4 4 4
54370 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54371 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54372 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54373 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
54374 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54375 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54376 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54377 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54378 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54379 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54380 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54383 +4 4 4 4 4 4
54384 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54385 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54386 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54387 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54388 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54389 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54390 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54391 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54392 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54393 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54394 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
54395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54397 +4 4 4 4 4 4
54398 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54399 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54400 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54401 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54402 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54403 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54404 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54405 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54406 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54407 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54408 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
54409 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54411 +4 4 4 4 4 4
54412 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54413 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54414 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54415 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54416 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54417 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54418 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54419 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54420 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54421 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54422 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54423 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54425 +4 4 4 4 4 4
54426 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
54427 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54428 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54429 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54430 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54431 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54432 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54433 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54434 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54435 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54436 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54439 +4 4 4 4 4 4
54440 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
54441 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54442 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54443 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54444 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54445 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54446 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54447 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54448 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54449 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54450 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54453 +4 4 4 4 4 4
54454 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54455 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54456 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54457 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54458 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54459 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54460 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54461 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54462 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54463 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54464 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54467 +4 4 4 4 4 4
54468 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54469 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
54470 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54471 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54472 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54473 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54474 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54475 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54476 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54477 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54478 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54481 +4 4 4 4 4 4
54482 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54483 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54484 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54485 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54486 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54487 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54488 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54489 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54490 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54491 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54492 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54495 +4 4 4 4 4 4
54496 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
54497 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54498 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54499 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54500 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54501 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54502 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54503 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54504 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54505 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54506 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54509 +4 4 4 4 4 4
54510 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
54511 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
54512 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54513 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54514 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54515 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54516 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54517 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54518 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54519 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54520 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54523 +4 4 4 4 4 4
54524 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54525 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
54526 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54527 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
54528 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54529 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54530 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54531 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
54532 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54533 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54534 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54537 +4 4 4 4 4 4
54538 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54539 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
54540 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54541 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54542 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54543 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54544 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54545 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54546 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
54547 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54548 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54551 +4 4 4 4 4 4
54552 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54553 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54554 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54555 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54556 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54557 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54558 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54559 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
54560 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54561 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54562 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54563 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54565 +4 4 4 4 4 4
54566 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54567 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
54568 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54569 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
54570 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54571 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54572 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54573 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54574 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54575 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54576 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54579 +4 4 4 4 4 4
54580 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54581 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54582 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54583 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54584 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54585 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54586 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54587 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
54588 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54589 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54590 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54593 +4 4 4 4 4 4
54594 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54595 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54596 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54597 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54598 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54599 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54600 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54601 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
54602 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54603 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54604 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54607 +4 4 4 4 4 4
54608 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54609 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
54610 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54611 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54612 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54613 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54614 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54615 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54616 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
54617 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54618 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54621 +4 4 4 4 4 4
54622 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54623 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54624 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54625 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54626 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54627 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54628 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54629 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54630 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54631 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54632 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54635 +4 4 4 4 4 4
54636 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
54637 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54638 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54639 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54640 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54641 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54642 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54643 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54644 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54645 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54646 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54649 +4 4 4 4 4 4
54650 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54651 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54652 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54653 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54654 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54655 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54656 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54657 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54658 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54659 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54660 +0 0 0 3 3 3 5 5 5 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
54664 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54665 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54666 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54667 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54668 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54669 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54670 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54671 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54672 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54673 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54674 +0 0 0 3 3 3 5 5 5 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
54678 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54679 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54680 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54681 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54682 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54683 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54684 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54685 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54686 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54687 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54688 +0 0 0 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
54692 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54693 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54694 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54695 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54696 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54697 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54698 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54699 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54700 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54701 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54702 +4 3 3 5 5 5 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
54706 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54707 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54708 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54709 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54710 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54711 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54712 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54713 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54714 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54715 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54716 +5 5 5 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
54720 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54721 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54722 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54723 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54724 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54725 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54726 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54727 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54728 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54729 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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
54734 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54735 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54736 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54737 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54738 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54739 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54740 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54741 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54742 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54743 +13 16 17 4 0 0 4 0 0 4 3 3 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
54748 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54749 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54750 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54751 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54752 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54753 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54754 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54755 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54756 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54757 +4 0 0 4 0 0 5 5 5 5 5 5 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
54762 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54763 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54764 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54765 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54766 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54767 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54768 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54769 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54770 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54771 +4 3 3 5 5 5 4 4 4 4 4 4 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
54776 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54777 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54778 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54779 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54780 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54781 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
54782 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
54783 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
54784 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
54785 +4 4 4 4 4 4 4 4 4 4 4 4 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
54790 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
54791 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
54792 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
54793 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
54794 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
54795 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
54796 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54797 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54798 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
54799 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
54804 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54805 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54806 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54807 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54808 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54809 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
54810 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
54811 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
54812 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54813 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
54817 +4 4 4 4 4 4
54818 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
54819 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
54820 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54821 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
54822 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
54823 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
54824 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
54825 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
54826 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54827 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
54831 +4 4 4 4 4 4
54832 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54833 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
54834 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
54835 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
54836 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
54837 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
54838 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
54839 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54840 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54841 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
54845 +4 4 4 4 4 4
54846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54847 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
54848 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54849 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
54850 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
54851 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
54852 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
54853 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
54854 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54855 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54859 +4 4 4 4 4 4
54860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54861 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
54862 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
54863 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
54864 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
54865 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
54866 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
54867 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
54868 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54869 +4 4 4 4 4 4 4 4 4 4 4 4 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54873 +4 4 4 4 4 4
54874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54875 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54876 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
54877 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54878 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
54879 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
54880 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
54881 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54882 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54883 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
54886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54887 +4 4 4 4 4 4
54888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54890 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54891 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
54892 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
54893 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
54894 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
54895 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54896 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54897 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54901 +4 4 4 4 4 4
54902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54905 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54906 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
54907 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
54908 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
54909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54910 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54915 +4 4 4 4 4 4
54916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54919 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54920 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54921 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
54922 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
54923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54929 +4 4 4 4 4 4
54930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54933 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54934 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54935 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54936 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
54937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54943 +4 4 4 4 4 4
54944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54947 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
54948 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
54949 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
54950 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
54951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54957 +4 4 4 4 4 4
54958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54962 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
54963 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54964 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54971 +4 4 4 4 4 4
54972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54976 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
54977 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
54978 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54985 +4 4 4 4 4 4
54986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54990 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
54991 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
54992 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54999 +4 4 4 4 4 4
55000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55004 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55005 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55013 +4 4 4 4 4 4
55014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55018 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55019 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55022 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55027 +4 4 4 4 4 4
55028 diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55029 index a01147f..5d896f8 100644
55030 --- a/drivers/video/matrox/matroxfb_DAC1064.c
55031 +++ b/drivers/video/matrox/matroxfb_DAC1064.c
55032 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55033
55034 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55035 struct matrox_switch matrox_mystique = {
55036 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55037 + .preinit = MGA1064_preinit,
55038 + .reset = MGA1064_reset,
55039 + .init = MGA1064_init,
55040 + .restore = MGA1064_restore,
55041 };
55042 EXPORT_SYMBOL(matrox_mystique);
55043 #endif
55044
55045 #ifdef CONFIG_FB_MATROX_G
55046 struct matrox_switch matrox_G100 = {
55047 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55048 + .preinit = MGAG100_preinit,
55049 + .reset = MGAG100_reset,
55050 + .init = MGAG100_init,
55051 + .restore = MGAG100_restore,
55052 };
55053 EXPORT_SYMBOL(matrox_G100);
55054 #endif
55055 diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55056 index 195ad7c..09743fc 100644
55057 --- a/drivers/video/matrox/matroxfb_Ti3026.c
55058 +++ b/drivers/video/matrox/matroxfb_Ti3026.c
55059 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55060 }
55061
55062 struct matrox_switch matrox_millennium = {
55063 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55064 + .preinit = Ti3026_preinit,
55065 + .reset = Ti3026_reset,
55066 + .init = Ti3026_init,
55067 + .restore = Ti3026_restore
55068 };
55069 EXPORT_SYMBOL(matrox_millennium);
55070 #endif
55071 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55072 index fe92eed..106e085 100644
55073 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
55074 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55075 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55076 struct mb862xxfb_par *par = info->par;
55077
55078 if (info->var.bits_per_pixel == 32) {
55079 - info->fbops->fb_fillrect = cfb_fillrect;
55080 - info->fbops->fb_copyarea = cfb_copyarea;
55081 - info->fbops->fb_imageblit = cfb_imageblit;
55082 + pax_open_kernel();
55083 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55084 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55085 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55086 + pax_close_kernel();
55087 } else {
55088 outreg(disp, GC_L0EM, 3);
55089 - info->fbops->fb_fillrect = mb86290fb_fillrect;
55090 - info->fbops->fb_copyarea = mb86290fb_copyarea;
55091 - info->fbops->fb_imageblit = mb86290fb_imageblit;
55092 + pax_open_kernel();
55093 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55094 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55095 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55096 + pax_close_kernel();
55097 }
55098 outreg(draw, GDC_REG_DRAW_BASE, 0);
55099 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55100 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55101 index def0412..fed6529 100644
55102 --- a/drivers/video/nvidia/nvidia.c
55103 +++ b/drivers/video/nvidia/nvidia.c
55104 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55105 info->fix.line_length = (info->var.xres_virtual *
55106 info->var.bits_per_pixel) >> 3;
55107 if (info->var.accel_flags) {
55108 - info->fbops->fb_imageblit = nvidiafb_imageblit;
55109 - info->fbops->fb_fillrect = nvidiafb_fillrect;
55110 - info->fbops->fb_copyarea = nvidiafb_copyarea;
55111 - info->fbops->fb_sync = nvidiafb_sync;
55112 + pax_open_kernel();
55113 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55114 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55115 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55116 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55117 + pax_close_kernel();
55118 info->pixmap.scan_align = 4;
55119 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55120 info->flags |= FBINFO_READS_FAST;
55121 NVResetGraphics(info);
55122 } else {
55123 - info->fbops->fb_imageblit = cfb_imageblit;
55124 - info->fbops->fb_fillrect = cfb_fillrect;
55125 - info->fbops->fb_copyarea = cfb_copyarea;
55126 - info->fbops->fb_sync = NULL;
55127 + pax_open_kernel();
55128 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55129 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55130 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55131 + *(void **)&info->fbops->fb_sync = NULL;
55132 + pax_close_kernel();
55133 info->pixmap.scan_align = 1;
55134 info->flags |= FBINFO_HWACCEL_DISABLED;
55135 info->flags &= ~FBINFO_READS_FAST;
55136 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55137 info->pixmap.size = 8 * 1024;
55138 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55139
55140 - if (!hwcur)
55141 - info->fbops->fb_cursor = NULL;
55142 + if (!hwcur) {
55143 + pax_open_kernel();
55144 + *(void **)&info->fbops->fb_cursor = NULL;
55145 + pax_close_kernel();
55146 + }
55147
55148 info->var.accel_flags = (!noaccel);
55149
55150 diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55151 index 669a81f..e216d76 100644
55152 --- a/drivers/video/omap2/dss/display.c
55153 +++ b/drivers/video/omap2/dss/display.c
55154 @@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55155 snprintf(dssdev->alias, sizeof(dssdev->alias),
55156 "display%d", disp_num_counter++);
55157
55158 + pax_open_kernel();
55159 if (drv && drv->get_resolution == NULL)
55160 - drv->get_resolution = omapdss_default_get_resolution;
55161 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55162 if (drv && drv->get_recommended_bpp == NULL)
55163 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55164 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55165 if (drv && drv->get_timings == NULL)
55166 - drv->get_timings = omapdss_default_get_timings;
55167 + *(void **)&drv->get_timings = omapdss_default_get_timings;
55168 + pax_close_kernel();
55169
55170 mutex_lock(&panel_list_mutex);
55171 list_add_tail(&dssdev->panel_list, &panel_list);
55172 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55173 index 83433cb..71e9b98 100644
55174 --- a/drivers/video/s1d13xxxfb.c
55175 +++ b/drivers/video/s1d13xxxfb.c
55176 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55177
55178 switch(prod_id) {
55179 case S1D13506_PROD_ID: /* activate acceleration */
55180 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55181 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55182 + pax_open_kernel();
55183 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55184 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55185 + pax_close_kernel();
55186 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55187 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55188 break;
55189 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55190 index d513ed6..90b0de9 100644
55191 --- a/drivers/video/smscufx.c
55192 +++ b/drivers/video/smscufx.c
55193 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55194 fb_deferred_io_cleanup(info);
55195 kfree(info->fbdefio);
55196 info->fbdefio = NULL;
55197 - info->fbops->fb_mmap = ufx_ops_mmap;
55198 + pax_open_kernel();
55199 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55200 + pax_close_kernel();
55201 }
55202
55203 pr_debug("released /dev/fb%d user=%d count=%d",
55204 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55205 index 77b890e..458e666 100644
55206 --- a/drivers/video/udlfb.c
55207 +++ b/drivers/video/udlfb.c
55208 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55209 dlfb_urb_completion(urb);
55210
55211 error:
55212 - atomic_add(bytes_sent, &dev->bytes_sent);
55213 - atomic_add(bytes_identical, &dev->bytes_identical);
55214 - atomic_add(width*height*2, &dev->bytes_rendered);
55215 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55216 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55217 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55218 end_cycles = get_cycles();
55219 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55220 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55221 >> 10)), /* Kcycles */
55222 &dev->cpu_kcycles_used);
55223
55224 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55225 dlfb_urb_completion(urb);
55226
55227 error:
55228 - atomic_add(bytes_sent, &dev->bytes_sent);
55229 - atomic_add(bytes_identical, &dev->bytes_identical);
55230 - atomic_add(bytes_rendered, &dev->bytes_rendered);
55231 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55232 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55233 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55234 end_cycles = get_cycles();
55235 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
55236 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55237 >> 10)), /* Kcycles */
55238 &dev->cpu_kcycles_used);
55239 }
55240 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55241 fb_deferred_io_cleanup(info);
55242 kfree(info->fbdefio);
55243 info->fbdefio = NULL;
55244 - info->fbops->fb_mmap = dlfb_ops_mmap;
55245 + pax_open_kernel();
55246 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55247 + pax_close_kernel();
55248 }
55249
55250 pr_warn("released /dev/fb%d user=%d count=%d\n",
55251 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55252 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55253 struct dlfb_data *dev = fb_info->par;
55254 return snprintf(buf, PAGE_SIZE, "%u\n",
55255 - atomic_read(&dev->bytes_rendered));
55256 + atomic_read_unchecked(&dev->bytes_rendered));
55257 }
55258
55259 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55260 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55261 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55262 struct dlfb_data *dev = fb_info->par;
55263 return snprintf(buf, PAGE_SIZE, "%u\n",
55264 - atomic_read(&dev->bytes_identical));
55265 + atomic_read_unchecked(&dev->bytes_identical));
55266 }
55267
55268 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55269 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55270 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55271 struct dlfb_data *dev = fb_info->par;
55272 return snprintf(buf, PAGE_SIZE, "%u\n",
55273 - atomic_read(&dev->bytes_sent));
55274 + atomic_read_unchecked(&dev->bytes_sent));
55275 }
55276
55277 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55278 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55279 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55280 struct dlfb_data *dev = fb_info->par;
55281 return snprintf(buf, PAGE_SIZE, "%u\n",
55282 - atomic_read(&dev->cpu_kcycles_used));
55283 + atomic_read_unchecked(&dev->cpu_kcycles_used));
55284 }
55285
55286 static ssize_t edid_show(
55287 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55288 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55289 struct dlfb_data *dev = fb_info->par;
55290
55291 - atomic_set(&dev->bytes_rendered, 0);
55292 - atomic_set(&dev->bytes_identical, 0);
55293 - atomic_set(&dev->bytes_sent, 0);
55294 - atomic_set(&dev->cpu_kcycles_used, 0);
55295 + atomic_set_unchecked(&dev->bytes_rendered, 0);
55296 + atomic_set_unchecked(&dev->bytes_identical, 0);
55297 + atomic_set_unchecked(&dev->bytes_sent, 0);
55298 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55299
55300 return count;
55301 }
55302 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55303 index 256fba7..6e75516 100644
55304 --- a/drivers/video/uvesafb.c
55305 +++ b/drivers/video/uvesafb.c
55306 @@ -19,6 +19,7 @@
55307 #include <linux/io.h>
55308 #include <linux/mutex.h>
55309 #include <linux/slab.h>
55310 +#include <linux/moduleloader.h>
55311 #include <video/edid.h>
55312 #include <video/uvesafb.h>
55313 #ifdef CONFIG_X86
55314 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55315 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55316 par->pmi_setpal = par->ypan = 0;
55317 } else {
55318 +
55319 +#ifdef CONFIG_PAX_KERNEXEC
55320 +#ifdef CONFIG_MODULES
55321 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55322 +#endif
55323 + if (!par->pmi_code) {
55324 + par->pmi_setpal = par->ypan = 0;
55325 + return 0;
55326 + }
55327 +#endif
55328 +
55329 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55330 + task->t.regs.edi);
55331 +
55332 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55333 + pax_open_kernel();
55334 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55335 + pax_close_kernel();
55336 +
55337 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55338 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55339 +#else
55340 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55341 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55342 +#endif
55343 +
55344 printk(KERN_INFO "uvesafb: protected mode interface info at "
55345 "%04x:%04x\n",
55346 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55347 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55348 par->ypan = ypan;
55349
55350 if (par->pmi_setpal || par->ypan) {
55351 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55352 if (__supported_pte_mask & _PAGE_NX) {
55353 par->pmi_setpal = par->ypan = 0;
55354 printk(KERN_WARNING "uvesafb: NX protection is active, "
55355 "better not use the PMI.\n");
55356 - } else {
55357 + } else
55358 +#endif
55359 uvesafb_vbe_getpmi(task, par);
55360 - }
55361 }
55362 #else
55363 /* The protected mode interface is not available on non-x86. */
55364 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55365 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55366
55367 /* Disable blanking if the user requested so. */
55368 - if (!blank)
55369 - info->fbops->fb_blank = NULL;
55370 + if (!blank) {
55371 + pax_open_kernel();
55372 + *(void **)&info->fbops->fb_blank = NULL;
55373 + pax_close_kernel();
55374 + }
55375
55376 /*
55377 * Find out how much IO memory is required for the mode with
55378 @@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55379 info->flags = FBINFO_FLAG_DEFAULT |
55380 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55381
55382 - if (!par->ypan)
55383 - info->fbops->fb_pan_display = NULL;
55384 + if (!par->ypan) {
55385 + pax_open_kernel();
55386 + *(void **)&info->fbops->fb_pan_display = NULL;
55387 + pax_close_kernel();
55388 + }
55389 }
55390
55391 static void uvesafb_init_mtrr(struct fb_info *info)
55392 @@ -1792,6 +1822,11 @@ out_mode:
55393 out:
55394 kfree(par->vbe_modes);
55395
55396 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55397 + if (par->pmi_code)
55398 + module_free_exec(NULL, par->pmi_code);
55399 +#endif
55400 +
55401 framebuffer_release(info);
55402 return err;
55403 }
55404 @@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55405 kfree(par->vbe_modes);
55406 kfree(par->vbe_state_orig);
55407 kfree(par->vbe_state_saved);
55408 +
55409 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55410 + if (par->pmi_code)
55411 + module_free_exec(NULL, par->pmi_code);
55412 +#endif
55413 +
55414 }
55415
55416 framebuffer_release(info);
55417 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55418 index 1c7da3b..56ea0bd 100644
55419 --- a/drivers/video/vesafb.c
55420 +++ b/drivers/video/vesafb.c
55421 @@ -9,6 +9,7 @@
55422 */
55423
55424 #include <linux/module.h>
55425 +#include <linux/moduleloader.h>
55426 #include <linux/kernel.h>
55427 #include <linux/errno.h>
55428 #include <linux/string.h>
55429 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55430 static int vram_total; /* Set total amount of memory */
55431 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55432 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55433 -static void (*pmi_start)(void) __read_mostly;
55434 -static void (*pmi_pal) (void) __read_mostly;
55435 +static void (*pmi_start)(void) __read_only;
55436 +static void (*pmi_pal) (void) __read_only;
55437 static int depth __read_mostly;
55438 static int vga_compat __read_mostly;
55439 /* --------------------------------------------------------------------- */
55440 @@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55441 unsigned int size_remap;
55442 unsigned int size_total;
55443 char *option = NULL;
55444 + void *pmi_code = NULL;
55445
55446 /* ignore error return of fb_get_options */
55447 fb_get_options("vesafb", &option);
55448 @@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55449 size_remap = size_total;
55450 vesafb_fix.smem_len = size_remap;
55451
55452 -#ifndef __i386__
55453 - screen_info.vesapm_seg = 0;
55454 -#endif
55455 -
55456 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55457 printk(KERN_WARNING
55458 "vesafb: cannot reserve video memory at 0x%lx\n",
55459 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55460 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55461 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55462
55463 +#ifdef __i386__
55464 +
55465 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55466 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
55467 + if (!pmi_code)
55468 +#elif !defined(CONFIG_PAX_KERNEXEC)
55469 + if (0)
55470 +#endif
55471 +
55472 +#endif
55473 + screen_info.vesapm_seg = 0;
55474 +
55475 if (screen_info.vesapm_seg) {
55476 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55477 - screen_info.vesapm_seg,screen_info.vesapm_off);
55478 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55479 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55480 }
55481
55482 if (screen_info.vesapm_seg < 0xc000)
55483 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55484
55485 if (ypan || pmi_setpal) {
55486 unsigned short *pmi_base;
55487 +
55488 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55489 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55490 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55491 +
55492 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55493 + pax_open_kernel();
55494 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55495 +#else
55496 + pmi_code = pmi_base;
55497 +#endif
55498 +
55499 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55500 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55501 +
55502 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55503 + pmi_start = ktva_ktla(pmi_start);
55504 + pmi_pal = ktva_ktla(pmi_pal);
55505 + pax_close_kernel();
55506 +#endif
55507 +
55508 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55509 if (pmi_base[3]) {
55510 printk(KERN_INFO "vesafb: pmi: ports = ");
55511 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55512 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55513 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55514
55515 - if (!ypan)
55516 - info->fbops->fb_pan_display = NULL;
55517 + if (!ypan) {
55518 + pax_open_kernel();
55519 + *(void **)&info->fbops->fb_pan_display = NULL;
55520 + pax_close_kernel();
55521 + }
55522
55523 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55524 err = -ENOMEM;
55525 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55526 fb_info(info, "%s frame buffer device\n", info->fix.id);
55527 return 0;
55528 err:
55529 +
55530 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55531 + module_free_exec(NULL, pmi_code);
55532 +#endif
55533 +
55534 if (info->screen_base)
55535 iounmap(info->screen_base);
55536 framebuffer_release(info);
55537 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55538 index 88714ae..16c2e11 100644
55539 --- a/drivers/video/via/via_clock.h
55540 +++ b/drivers/video/via/via_clock.h
55541 @@ -56,7 +56,7 @@ struct via_clock {
55542
55543 void (*set_engine_pll_state)(u8 state);
55544 void (*set_engine_pll)(struct via_pll_config config);
55545 -};
55546 +} __no_const;
55547
55548
55549 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55550 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55551 index fef20db..d28b1ab 100644
55552 --- a/drivers/xen/xenfs/xenstored.c
55553 +++ b/drivers/xen/xenfs/xenstored.c
55554 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55555 static int xsd_kva_open(struct inode *inode, struct file *file)
55556 {
55557 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55558 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55559 + NULL);
55560 +#else
55561 xen_store_interface);
55562 +#endif
55563 +
55564 if (!file->private_data)
55565 return -ENOMEM;
55566 return 0;
55567 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55568 index c71e886..61d3d44b 100644
55569 --- a/fs/9p/vfs_addr.c
55570 +++ b/fs/9p/vfs_addr.c
55571 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55572
55573 retval = v9fs_file_write_internal(inode,
55574 v9inode->writeback_fid,
55575 - (__force const char __user *)buffer,
55576 + (const char __force_user *)buffer,
55577 len, &offset, 0);
55578 if (retval > 0)
55579 retval = 0;
55580 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55581 index bb7991c..481e21a 100644
55582 --- a/fs/9p/vfs_inode.c
55583 +++ b/fs/9p/vfs_inode.c
55584 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55585 void
55586 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55587 {
55588 - char *s = nd_get_link(nd);
55589 + const char *s = nd_get_link(nd);
55590
55591 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55592 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55593 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55594 index 370b24c..ff0be7b 100644
55595 --- a/fs/Kconfig.binfmt
55596 +++ b/fs/Kconfig.binfmt
55597 @@ -103,7 +103,7 @@ config HAVE_AOUT
55598
55599 config BINFMT_AOUT
55600 tristate "Kernel support for a.out and ECOFF binaries"
55601 - depends on HAVE_AOUT
55602 + depends on HAVE_AOUT && BROKEN
55603 ---help---
55604 A.out (Assembler.OUTput) is a set of formats for libraries and
55605 executables used in the earliest versions of UNIX. Linux used
55606 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55607 index ce25d75..dc09eeb 100644
55608 --- a/fs/afs/inode.c
55609 +++ b/fs/afs/inode.c
55610 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55611 struct afs_vnode *vnode;
55612 struct super_block *sb;
55613 struct inode *inode;
55614 - static atomic_t afs_autocell_ino;
55615 + static atomic_unchecked_t afs_autocell_ino;
55616
55617 _enter("{%x:%u},%*.*s,",
55618 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55619 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55620 data.fid.unique = 0;
55621 data.fid.vnode = 0;
55622
55623 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55624 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55625 afs_iget5_autocell_test, afs_iget5_set,
55626 &data);
55627 if (!inode) {
55628 diff --git a/fs/aio.c b/fs/aio.c
55629 index 062a5f6..e5618e0 100644
55630 --- a/fs/aio.c
55631 +++ b/fs/aio.c
55632 @@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55633 size += sizeof(struct io_event) * nr_events;
55634
55635 nr_pages = PFN_UP(size);
55636 - if (nr_pages < 0)
55637 + if (nr_pages <= 0)
55638 return -EINVAL;
55639
55640 file = aio_private_file(ctx, nr_pages);
55641 diff --git a/fs/attr.c b/fs/attr.c
55642 index 5d4e59d..fd02418 100644
55643 --- a/fs/attr.c
55644 +++ b/fs/attr.c
55645 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55646 unsigned long limit;
55647
55648 limit = rlimit(RLIMIT_FSIZE);
55649 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55650 if (limit != RLIM_INFINITY && offset > limit)
55651 goto out_sig;
55652 if (offset > inode->i_sb->s_maxbytes)
55653 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55654 index 116fd38..c04182da 100644
55655 --- a/fs/autofs4/waitq.c
55656 +++ b/fs/autofs4/waitq.c
55657 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55658 {
55659 unsigned long sigpipe, flags;
55660 mm_segment_t fs;
55661 - const char *data = (const char *)addr;
55662 + const char __user *data = (const char __force_user *)addr;
55663 ssize_t wr = 0;
55664
55665 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55666 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55667 return 1;
55668 }
55669
55670 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55671 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55672 +#endif
55673 +
55674 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55675 enum autofs_notify notify)
55676 {
55677 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55678
55679 /* If this is a direct mount request create a dummy name */
55680 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55681 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55682 + /* this name does get written to userland via autofs4_write() */
55683 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55684 +#else
55685 qstr.len = sprintf(name, "%p", dentry);
55686 +#endif
55687 else {
55688 qstr.len = autofs4_getpath(sbi, dentry, &name);
55689 if (!qstr.len) {
55690 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55691 index 2722387..56059b5 100644
55692 --- a/fs/befs/endian.h
55693 +++ b/fs/befs/endian.h
55694 @@ -11,7 +11,7 @@
55695
55696 #include <asm/byteorder.h>
55697
55698 -static inline u64
55699 +static inline u64 __intentional_overflow(-1)
55700 fs64_to_cpu(const struct super_block *sb, fs64 n)
55701 {
55702 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55703 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55704 return (__force fs64)cpu_to_be64(n);
55705 }
55706
55707 -static inline u32
55708 +static inline u32 __intentional_overflow(-1)
55709 fs32_to_cpu(const struct super_block *sb, fs32 n)
55710 {
55711 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55712 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55713 return (__force fs32)cpu_to_be32(n);
55714 }
55715
55716 -static inline u16
55717 +static inline u16 __intentional_overflow(-1)
55718 fs16_to_cpu(const struct super_block *sb, fs16 n)
55719 {
55720 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55721 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55722 index ca0ba15..0fa3257 100644
55723 --- a/fs/binfmt_aout.c
55724 +++ b/fs/binfmt_aout.c
55725 @@ -16,6 +16,7 @@
55726 #include <linux/string.h>
55727 #include <linux/fs.h>
55728 #include <linux/file.h>
55729 +#include <linux/security.h>
55730 #include <linux/stat.h>
55731 #include <linux/fcntl.h>
55732 #include <linux/ptrace.h>
55733 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55734 #endif
55735 # define START_STACK(u) ((void __user *)u.start_stack)
55736
55737 + memset(&dump, 0, sizeof(dump));
55738 +
55739 fs = get_fs();
55740 set_fs(KERNEL_DS);
55741 has_dumped = 1;
55742 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55743
55744 /* If the size of the dump file exceeds the rlimit, then see what would happen
55745 if we wrote the stack, but not the data area. */
55746 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55747 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55748 dump.u_dsize = 0;
55749
55750 /* Make sure we have enough room to write the stack and data areas. */
55751 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
55752 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
55753 dump.u_ssize = 0;
55754
55755 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
55756 rlim = rlimit(RLIMIT_DATA);
55757 if (rlim >= RLIM_INFINITY)
55758 rlim = ~0;
55759 +
55760 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
55761 if (ex.a_data + ex.a_bss > rlim)
55762 return -ENOMEM;
55763
55764 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
55765
55766 install_exec_creds(bprm);
55767
55768 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55769 + current->mm->pax_flags = 0UL;
55770 +#endif
55771 +
55772 +#ifdef CONFIG_PAX_PAGEEXEC
55773 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
55774 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
55775 +
55776 +#ifdef CONFIG_PAX_EMUTRAMP
55777 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
55778 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
55779 +#endif
55780 +
55781 +#ifdef CONFIG_PAX_MPROTECT
55782 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
55783 + current->mm->pax_flags |= MF_PAX_MPROTECT;
55784 +#endif
55785 +
55786 + }
55787 +#endif
55788 +
55789 if (N_MAGIC(ex) == OMAGIC) {
55790 unsigned long text_addr, map_size;
55791 loff_t pos;
55792 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
55793 }
55794
55795 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
55796 - PROT_READ | PROT_WRITE | PROT_EXEC,
55797 + PROT_READ | PROT_WRITE,
55798 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
55799 fd_offset + ex.a_text);
55800 if (error != N_DATADDR(ex)) {
55801 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
55802 index 67be295..83e2f86 100644
55803 --- a/fs/binfmt_elf.c
55804 +++ b/fs/binfmt_elf.c
55805 @@ -34,6 +34,7 @@
55806 #include <linux/utsname.h>
55807 #include <linux/coredump.h>
55808 #include <linux/sched.h>
55809 +#include <linux/xattr.h>
55810 #include <asm/uaccess.h>
55811 #include <asm/param.h>
55812 #include <asm/page.h>
55813 @@ -48,7 +49,7 @@
55814 static int load_elf_binary(struct linux_binprm *bprm);
55815 static int load_elf_library(struct file *);
55816 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
55817 - int, int, unsigned long);
55818 + int, int, unsigned long) __intentional_overflow(-1);
55819
55820 /*
55821 * If we don't support core dumping, then supply a NULL so we
55822 @@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
55823 #define elf_core_dump NULL
55824 #endif
55825
55826 +#ifdef CONFIG_PAX_MPROTECT
55827 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
55828 +#endif
55829 +
55830 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55831 +static void elf_handle_mmap(struct file *file);
55832 +#endif
55833 +
55834 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
55835 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
55836 #else
55837 @@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
55838 .load_binary = load_elf_binary,
55839 .load_shlib = load_elf_library,
55840 .core_dump = elf_core_dump,
55841 +
55842 +#ifdef CONFIG_PAX_MPROTECT
55843 + .handle_mprotect= elf_handle_mprotect,
55844 +#endif
55845 +
55846 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55847 + .handle_mmap = elf_handle_mmap,
55848 +#endif
55849 +
55850 .min_coredump = ELF_EXEC_PAGESIZE,
55851 };
55852
55853 @@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
55854
55855 static int set_brk(unsigned long start, unsigned long end)
55856 {
55857 + unsigned long e = end;
55858 +
55859 start = ELF_PAGEALIGN(start);
55860 end = ELF_PAGEALIGN(end);
55861 if (end > start) {
55862 @@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
55863 if (BAD_ADDR(addr))
55864 return addr;
55865 }
55866 - current->mm->start_brk = current->mm->brk = end;
55867 + current->mm->start_brk = current->mm->brk = e;
55868 return 0;
55869 }
55870
55871 @@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55872 elf_addr_t __user *u_rand_bytes;
55873 const char *k_platform = ELF_PLATFORM;
55874 const char *k_base_platform = ELF_BASE_PLATFORM;
55875 - unsigned char k_rand_bytes[16];
55876 + u32 k_rand_bytes[4];
55877 int items;
55878 elf_addr_t *elf_info;
55879 int ei_index = 0;
55880 const struct cred *cred = current_cred();
55881 struct vm_area_struct *vma;
55882 + unsigned long saved_auxv[AT_VECTOR_SIZE];
55883
55884 /*
55885 * In some cases (e.g. Hyper-Threading), we want to avoid L1
55886 @@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55887 * Generate 16 random bytes for userspace PRNG seeding.
55888 */
55889 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
55890 - u_rand_bytes = (elf_addr_t __user *)
55891 - STACK_ALLOC(p, sizeof(k_rand_bytes));
55892 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
55893 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
55894 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
55895 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
55896 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
55897 + u_rand_bytes = (elf_addr_t __user *) p;
55898 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
55899 return -EFAULT;
55900
55901 @@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55902 return -EFAULT;
55903 current->mm->env_end = p;
55904
55905 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
55906 +
55907 /* Put the elf_info on the stack in the right place. */
55908 sp = (elf_addr_t __user *)envp + 1;
55909 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
55910 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
55911 return -EFAULT;
55912 return 0;
55913 }
55914 @@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
55915 an ELF header */
55916
55917 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55918 - struct file *interpreter, unsigned long *interp_map_addr,
55919 - unsigned long no_base)
55920 + struct file *interpreter, unsigned long no_base)
55921 {
55922 struct elf_phdr *elf_phdata;
55923 struct elf_phdr *eppnt;
55924 - unsigned long load_addr = 0;
55925 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
55926 int load_addr_set = 0;
55927 unsigned long last_bss = 0, elf_bss = 0;
55928 - unsigned long error = ~0UL;
55929 + unsigned long error = -EINVAL;
55930 unsigned long total_size;
55931 int retval, i, size;
55932
55933 @@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55934 goto out_close;
55935 }
55936
55937 +#ifdef CONFIG_PAX_SEGMEXEC
55938 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
55939 + pax_task_size = SEGMEXEC_TASK_SIZE;
55940 +#endif
55941 +
55942 eppnt = elf_phdata;
55943 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
55944 if (eppnt->p_type == PT_LOAD) {
55945 @@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55946 map_addr = elf_map(interpreter, load_addr + vaddr,
55947 eppnt, elf_prot, elf_type, total_size);
55948 total_size = 0;
55949 - if (!*interp_map_addr)
55950 - *interp_map_addr = map_addr;
55951 error = map_addr;
55952 if (BAD_ADDR(map_addr))
55953 goto out_close;
55954 @@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55955 k = load_addr + eppnt->p_vaddr;
55956 if (BAD_ADDR(k) ||
55957 eppnt->p_filesz > eppnt->p_memsz ||
55958 - eppnt->p_memsz > TASK_SIZE ||
55959 - TASK_SIZE - eppnt->p_memsz < k) {
55960 + eppnt->p_memsz > pax_task_size ||
55961 + pax_task_size - eppnt->p_memsz < k) {
55962 error = -ENOMEM;
55963 goto out_close;
55964 }
55965 @@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55966 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
55967
55968 /* Map the last of the bss segment */
55969 - error = vm_brk(elf_bss, last_bss - elf_bss);
55970 - if (BAD_ADDR(error))
55971 - goto out_close;
55972 + if (last_bss > elf_bss) {
55973 + error = vm_brk(elf_bss, last_bss - elf_bss);
55974 + if (BAD_ADDR(error))
55975 + goto out_close;
55976 + }
55977 }
55978
55979 error = load_addr;
55980 @@ -538,6 +569,336 @@ out:
55981 return error;
55982 }
55983
55984 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
55985 +#ifdef CONFIG_PAX_SOFTMODE
55986 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
55987 +{
55988 + unsigned long pax_flags = 0UL;
55989 +
55990 +#ifdef CONFIG_PAX_PAGEEXEC
55991 + if (elf_phdata->p_flags & PF_PAGEEXEC)
55992 + pax_flags |= MF_PAX_PAGEEXEC;
55993 +#endif
55994 +
55995 +#ifdef CONFIG_PAX_SEGMEXEC
55996 + if (elf_phdata->p_flags & PF_SEGMEXEC)
55997 + pax_flags |= MF_PAX_SEGMEXEC;
55998 +#endif
55999 +
56000 +#ifdef CONFIG_PAX_EMUTRAMP
56001 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56002 + pax_flags |= MF_PAX_EMUTRAMP;
56003 +#endif
56004 +
56005 +#ifdef CONFIG_PAX_MPROTECT
56006 + if (elf_phdata->p_flags & PF_MPROTECT)
56007 + pax_flags |= MF_PAX_MPROTECT;
56008 +#endif
56009 +
56010 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56011 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56012 + pax_flags |= MF_PAX_RANDMMAP;
56013 +#endif
56014 +
56015 + return pax_flags;
56016 +}
56017 +#endif
56018 +
56019 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56020 +{
56021 + unsigned long pax_flags = 0UL;
56022 +
56023 +#ifdef CONFIG_PAX_PAGEEXEC
56024 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56025 + pax_flags |= MF_PAX_PAGEEXEC;
56026 +#endif
56027 +
56028 +#ifdef CONFIG_PAX_SEGMEXEC
56029 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56030 + pax_flags |= MF_PAX_SEGMEXEC;
56031 +#endif
56032 +
56033 +#ifdef CONFIG_PAX_EMUTRAMP
56034 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56035 + pax_flags |= MF_PAX_EMUTRAMP;
56036 +#endif
56037 +
56038 +#ifdef CONFIG_PAX_MPROTECT
56039 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56040 + pax_flags |= MF_PAX_MPROTECT;
56041 +#endif
56042 +
56043 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56044 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56045 + pax_flags |= MF_PAX_RANDMMAP;
56046 +#endif
56047 +
56048 + return pax_flags;
56049 +}
56050 +#endif
56051 +
56052 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56053 +#ifdef CONFIG_PAX_SOFTMODE
56054 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56055 +{
56056 + unsigned long pax_flags = 0UL;
56057 +
56058 +#ifdef CONFIG_PAX_PAGEEXEC
56059 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56060 + pax_flags |= MF_PAX_PAGEEXEC;
56061 +#endif
56062 +
56063 +#ifdef CONFIG_PAX_SEGMEXEC
56064 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56065 + pax_flags |= MF_PAX_SEGMEXEC;
56066 +#endif
56067 +
56068 +#ifdef CONFIG_PAX_EMUTRAMP
56069 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56070 + pax_flags |= MF_PAX_EMUTRAMP;
56071 +#endif
56072 +
56073 +#ifdef CONFIG_PAX_MPROTECT
56074 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56075 + pax_flags |= MF_PAX_MPROTECT;
56076 +#endif
56077 +
56078 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56079 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56080 + pax_flags |= MF_PAX_RANDMMAP;
56081 +#endif
56082 +
56083 + return pax_flags;
56084 +}
56085 +#endif
56086 +
56087 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56088 +{
56089 + unsigned long pax_flags = 0UL;
56090 +
56091 +#ifdef CONFIG_PAX_PAGEEXEC
56092 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56093 + pax_flags |= MF_PAX_PAGEEXEC;
56094 +#endif
56095 +
56096 +#ifdef CONFIG_PAX_SEGMEXEC
56097 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56098 + pax_flags |= MF_PAX_SEGMEXEC;
56099 +#endif
56100 +
56101 +#ifdef CONFIG_PAX_EMUTRAMP
56102 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56103 + pax_flags |= MF_PAX_EMUTRAMP;
56104 +#endif
56105 +
56106 +#ifdef CONFIG_PAX_MPROTECT
56107 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56108 + pax_flags |= MF_PAX_MPROTECT;
56109 +#endif
56110 +
56111 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56112 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56113 + pax_flags |= MF_PAX_RANDMMAP;
56114 +#endif
56115 +
56116 + return pax_flags;
56117 +}
56118 +#endif
56119 +
56120 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56121 +static unsigned long pax_parse_defaults(void)
56122 +{
56123 + unsigned long pax_flags = 0UL;
56124 +
56125 +#ifdef CONFIG_PAX_SOFTMODE
56126 + if (pax_softmode)
56127 + return pax_flags;
56128 +#endif
56129 +
56130 +#ifdef CONFIG_PAX_PAGEEXEC
56131 + pax_flags |= MF_PAX_PAGEEXEC;
56132 +#endif
56133 +
56134 +#ifdef CONFIG_PAX_SEGMEXEC
56135 + pax_flags |= MF_PAX_SEGMEXEC;
56136 +#endif
56137 +
56138 +#ifdef CONFIG_PAX_MPROTECT
56139 + pax_flags |= MF_PAX_MPROTECT;
56140 +#endif
56141 +
56142 +#ifdef CONFIG_PAX_RANDMMAP
56143 + if (randomize_va_space)
56144 + pax_flags |= MF_PAX_RANDMMAP;
56145 +#endif
56146 +
56147 + return pax_flags;
56148 +}
56149 +
56150 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56151 +{
56152 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56153 +
56154 +#ifdef CONFIG_PAX_EI_PAX
56155 +
56156 +#ifdef CONFIG_PAX_SOFTMODE
56157 + if (pax_softmode)
56158 + return pax_flags;
56159 +#endif
56160 +
56161 + pax_flags = 0UL;
56162 +
56163 +#ifdef CONFIG_PAX_PAGEEXEC
56164 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56165 + pax_flags |= MF_PAX_PAGEEXEC;
56166 +#endif
56167 +
56168 +#ifdef CONFIG_PAX_SEGMEXEC
56169 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56170 + pax_flags |= MF_PAX_SEGMEXEC;
56171 +#endif
56172 +
56173 +#ifdef CONFIG_PAX_EMUTRAMP
56174 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56175 + pax_flags |= MF_PAX_EMUTRAMP;
56176 +#endif
56177 +
56178 +#ifdef CONFIG_PAX_MPROTECT
56179 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56180 + pax_flags |= MF_PAX_MPROTECT;
56181 +#endif
56182 +
56183 +#ifdef CONFIG_PAX_ASLR
56184 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56185 + pax_flags |= MF_PAX_RANDMMAP;
56186 +#endif
56187 +
56188 +#endif
56189 +
56190 + return pax_flags;
56191 +
56192 +}
56193 +
56194 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56195 +{
56196 +
56197 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56198 + unsigned long i;
56199 +
56200 + for (i = 0UL; i < elf_ex->e_phnum; i++)
56201 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56202 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56203 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56204 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56205 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56206 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56207 + return PAX_PARSE_FLAGS_FALLBACK;
56208 +
56209 +#ifdef CONFIG_PAX_SOFTMODE
56210 + if (pax_softmode)
56211 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56212 + else
56213 +#endif
56214 +
56215 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56216 + break;
56217 + }
56218 +#endif
56219 +
56220 + return PAX_PARSE_FLAGS_FALLBACK;
56221 +}
56222 +
56223 +static unsigned long pax_parse_xattr_pax(struct file * const file)
56224 +{
56225 +
56226 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56227 + ssize_t xattr_size, i;
56228 + unsigned char xattr_value[sizeof("pemrs") - 1];
56229 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56230 +
56231 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56232 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56233 + return PAX_PARSE_FLAGS_FALLBACK;
56234 +
56235 + for (i = 0; i < xattr_size; i++)
56236 + switch (xattr_value[i]) {
56237 + default:
56238 + return PAX_PARSE_FLAGS_FALLBACK;
56239 +
56240 +#define parse_flag(option1, option2, flag) \
56241 + case option1: \
56242 + if (pax_flags_hardmode & MF_PAX_##flag) \
56243 + return PAX_PARSE_FLAGS_FALLBACK;\
56244 + pax_flags_hardmode |= MF_PAX_##flag; \
56245 + break; \
56246 + case option2: \
56247 + if (pax_flags_softmode & MF_PAX_##flag) \
56248 + return PAX_PARSE_FLAGS_FALLBACK;\
56249 + pax_flags_softmode |= MF_PAX_##flag; \
56250 + break;
56251 +
56252 + parse_flag('p', 'P', PAGEEXEC);
56253 + parse_flag('e', 'E', EMUTRAMP);
56254 + parse_flag('m', 'M', MPROTECT);
56255 + parse_flag('r', 'R', RANDMMAP);
56256 + parse_flag('s', 'S', SEGMEXEC);
56257 +
56258 +#undef parse_flag
56259 + }
56260 +
56261 + if (pax_flags_hardmode & pax_flags_softmode)
56262 + return PAX_PARSE_FLAGS_FALLBACK;
56263 +
56264 +#ifdef CONFIG_PAX_SOFTMODE
56265 + if (pax_softmode)
56266 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56267 + else
56268 +#endif
56269 +
56270 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56271 +#else
56272 + return PAX_PARSE_FLAGS_FALLBACK;
56273 +#endif
56274 +
56275 +}
56276 +
56277 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56278 +{
56279 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56280 +
56281 + pax_flags = pax_parse_defaults();
56282 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
56283 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56284 + xattr_pax_flags = pax_parse_xattr_pax(file);
56285 +
56286 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56287 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56288 + pt_pax_flags != xattr_pax_flags)
56289 + return -EINVAL;
56290 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56291 + pax_flags = xattr_pax_flags;
56292 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56293 + pax_flags = pt_pax_flags;
56294 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56295 + pax_flags = ei_pax_flags;
56296 +
56297 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56298 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56299 + if ((__supported_pte_mask & _PAGE_NX))
56300 + pax_flags &= ~MF_PAX_SEGMEXEC;
56301 + else
56302 + pax_flags &= ~MF_PAX_PAGEEXEC;
56303 + }
56304 +#endif
56305 +
56306 + if (0 > pax_check_flags(&pax_flags))
56307 + return -EINVAL;
56308 +
56309 + current->mm->pax_flags = pax_flags;
56310 + return 0;
56311 +}
56312 +#endif
56313 +
56314 /*
56315 * These are the functions used to load ELF style executables and shared
56316 * libraries. There is no binary dependent code anywhere else.
56317 @@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56318 {
56319 unsigned int random_variable = 0;
56320
56321 +#ifdef CONFIG_PAX_RANDUSTACK
56322 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56323 + return stack_top - current->mm->delta_stack;
56324 +#endif
56325 +
56326 if ((current->flags & PF_RANDOMIZE) &&
56327 !(current->personality & ADDR_NO_RANDOMIZE)) {
56328 random_variable = get_random_int() & STACK_RND_MASK;
56329 @@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56330 unsigned long load_addr = 0, load_bias = 0;
56331 int load_addr_set = 0;
56332 char * elf_interpreter = NULL;
56333 - unsigned long error;
56334 + unsigned long error = 0;
56335 struct elf_phdr *elf_ppnt, *elf_phdata;
56336 unsigned long elf_bss, elf_brk;
56337 int retval, i;
56338 @@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56339 unsigned long start_code, end_code, start_data, end_data;
56340 unsigned long reloc_func_desc __maybe_unused = 0;
56341 int executable_stack = EXSTACK_DEFAULT;
56342 - unsigned long def_flags = 0;
56343 struct pt_regs *regs = current_pt_regs();
56344 struct {
56345 struct elfhdr elf_ex;
56346 struct elfhdr interp_elf_ex;
56347 } *loc;
56348 + unsigned long pax_task_size;
56349
56350 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56351 if (!loc) {
56352 @@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56353 goto out_free_dentry;
56354
56355 /* OK, This is the point of no return */
56356 - current->mm->def_flags = def_flags;
56357 + current->mm->def_flags = 0;
56358
56359 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56360 may depend on the personality. */
56361 SET_PERSONALITY(loc->elf_ex);
56362 +
56363 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56364 + current->mm->pax_flags = 0UL;
56365 +#endif
56366 +
56367 +#ifdef CONFIG_PAX_DLRESOLVE
56368 + current->mm->call_dl_resolve = 0UL;
56369 +#endif
56370 +
56371 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56372 + current->mm->call_syscall = 0UL;
56373 +#endif
56374 +
56375 +#ifdef CONFIG_PAX_ASLR
56376 + current->mm->delta_mmap = 0UL;
56377 + current->mm->delta_stack = 0UL;
56378 +#endif
56379 +
56380 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56381 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56382 + send_sig(SIGKILL, current, 0);
56383 + goto out_free_dentry;
56384 + }
56385 +#endif
56386 +
56387 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56388 + pax_set_initial_flags(bprm);
56389 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56390 + if (pax_set_initial_flags_func)
56391 + (pax_set_initial_flags_func)(bprm);
56392 +#endif
56393 +
56394 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56395 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56396 + current->mm->context.user_cs_limit = PAGE_SIZE;
56397 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56398 + }
56399 +#endif
56400 +
56401 +#ifdef CONFIG_PAX_SEGMEXEC
56402 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56403 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56404 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56405 + pax_task_size = SEGMEXEC_TASK_SIZE;
56406 + current->mm->def_flags |= VM_NOHUGEPAGE;
56407 + } else
56408 +#endif
56409 +
56410 + pax_task_size = TASK_SIZE;
56411 +
56412 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56413 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56414 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56415 + put_cpu();
56416 + }
56417 +#endif
56418 +
56419 +#ifdef CONFIG_PAX_ASLR
56420 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56421 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56422 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56423 + }
56424 +#endif
56425 +
56426 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56427 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56428 + executable_stack = EXSTACK_DISABLE_X;
56429 + current->personality &= ~READ_IMPLIES_EXEC;
56430 + } else
56431 +#endif
56432 +
56433 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56434 current->personality |= READ_IMPLIES_EXEC;
56435
56436 @@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56437 #else
56438 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56439 #endif
56440 +
56441 +#ifdef CONFIG_PAX_RANDMMAP
56442 + /* PaX: randomize base address at the default exe base if requested */
56443 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56444 +#ifdef CONFIG_SPARC64
56445 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56446 +#else
56447 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56448 +#endif
56449 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56450 + elf_flags |= MAP_FIXED;
56451 + }
56452 +#endif
56453 +
56454 }
56455
56456 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56457 @@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56458 * allowed task size. Note that p_filesz must always be
56459 * <= p_memsz so it is only necessary to check p_memsz.
56460 */
56461 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56462 - elf_ppnt->p_memsz > TASK_SIZE ||
56463 - TASK_SIZE - elf_ppnt->p_memsz < k) {
56464 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56465 + elf_ppnt->p_memsz > pax_task_size ||
56466 + pax_task_size - elf_ppnt->p_memsz < k) {
56467 /* set_brk can never work. Avoid overflows. */
56468 send_sig(SIGKILL, current, 0);
56469 retval = -EINVAL;
56470 @@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56471 goto out_free_dentry;
56472 }
56473 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56474 - send_sig(SIGSEGV, current, 0);
56475 - retval = -EFAULT; /* Nobody gets to see this, but.. */
56476 - goto out_free_dentry;
56477 + /*
56478 + * This bss-zeroing can fail if the ELF
56479 + * file specifies odd protections. So
56480 + * we don't check the return value
56481 + */
56482 }
56483
56484 +#ifdef CONFIG_PAX_RANDMMAP
56485 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56486 + unsigned long start, size, flags;
56487 + vm_flags_t vm_flags;
56488 +
56489 + start = ELF_PAGEALIGN(elf_brk);
56490 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56491 + flags = MAP_FIXED | MAP_PRIVATE;
56492 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56493 +
56494 + down_write(&current->mm->mmap_sem);
56495 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56496 + retval = -ENOMEM;
56497 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56498 +// if (current->personality & ADDR_NO_RANDOMIZE)
56499 +// vm_flags |= VM_READ | VM_MAYREAD;
56500 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56501 + retval = IS_ERR_VALUE(start) ? start : 0;
56502 + }
56503 + up_write(&current->mm->mmap_sem);
56504 + if (retval == 0)
56505 + retval = set_brk(start + size, start + size + PAGE_SIZE);
56506 + if (retval < 0) {
56507 + send_sig(SIGKILL, current, 0);
56508 + goto out_free_dentry;
56509 + }
56510 + }
56511 +#endif
56512 +
56513 if (elf_interpreter) {
56514 - unsigned long interp_map_addr = 0;
56515 -
56516 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56517 interpreter,
56518 - &interp_map_addr,
56519 load_bias);
56520 if (!IS_ERR((void *)elf_entry)) {
56521 /*
56522 @@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56523 * Decide what to dump of a segment, part, all or none.
56524 */
56525 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56526 - unsigned long mm_flags)
56527 + unsigned long mm_flags, long signr)
56528 {
56529 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56530
56531 @@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56532 if (vma->vm_file == NULL)
56533 return 0;
56534
56535 - if (FILTER(MAPPED_PRIVATE))
56536 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56537 goto whole;
56538
56539 /*
56540 @@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56541 {
56542 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56543 int i = 0;
56544 - do
56545 + do {
56546 i += 2;
56547 - while (auxv[i - 2] != AT_NULL);
56548 + } while (auxv[i - 2] != AT_NULL);
56549 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56550 }
56551
56552 @@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56553 {
56554 mm_segment_t old_fs = get_fs();
56555 set_fs(KERNEL_DS);
56556 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56557 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56558 set_fs(old_fs);
56559 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56560 }
56561 @@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56562 }
56563
56564 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56565 - unsigned long mm_flags)
56566 + struct coredump_params *cprm)
56567 {
56568 struct vm_area_struct *vma;
56569 size_t size = 0;
56570
56571 for (vma = first_vma(current, gate_vma); vma != NULL;
56572 vma = next_vma(vma, gate_vma))
56573 - size += vma_dump_size(vma, mm_flags);
56574 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56575 return size;
56576 }
56577
56578 @@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56579
56580 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56581
56582 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56583 + offset += elf_core_vma_data_size(gate_vma, cprm);
56584 offset += elf_core_extra_data_size();
56585 e_shoff = offset;
56586
56587 @@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56588 phdr.p_offset = offset;
56589 phdr.p_vaddr = vma->vm_start;
56590 phdr.p_paddr = 0;
56591 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56592 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56593 phdr.p_memsz = vma->vm_end - vma->vm_start;
56594 offset += phdr.p_filesz;
56595 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56596 @@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56597 unsigned long addr;
56598 unsigned long end;
56599
56600 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56601 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56602
56603 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56604 struct page *page;
56605 @@ -2199,6 +2678,167 @@ out:
56606
56607 #endif /* CONFIG_ELF_CORE */
56608
56609 +#ifdef CONFIG_PAX_MPROTECT
56610 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
56611 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56612 + * we'll remove VM_MAYWRITE for good on RELRO segments.
56613 + *
56614 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56615 + * basis because we want to allow the common case and not the special ones.
56616 + */
56617 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56618 +{
56619 + struct elfhdr elf_h;
56620 + struct elf_phdr elf_p;
56621 + unsigned long i;
56622 + unsigned long oldflags;
56623 + bool is_textrel_rw, is_textrel_rx, is_relro;
56624 +
56625 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56626 + return;
56627 +
56628 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56629 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56630 +
56631 +#ifdef CONFIG_PAX_ELFRELOCS
56632 + /* possible TEXTREL */
56633 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56634 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56635 +#else
56636 + is_textrel_rw = false;
56637 + is_textrel_rx = false;
56638 +#endif
56639 +
56640 + /* possible RELRO */
56641 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56642 +
56643 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56644 + return;
56645 +
56646 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56647 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56648 +
56649 +#ifdef CONFIG_PAX_ETEXECRELOCS
56650 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56651 +#else
56652 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56653 +#endif
56654 +
56655 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56656 + !elf_check_arch(&elf_h) ||
56657 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56658 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56659 + return;
56660 +
56661 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56662 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56663 + return;
56664 + switch (elf_p.p_type) {
56665 + case PT_DYNAMIC:
56666 + if (!is_textrel_rw && !is_textrel_rx)
56667 + continue;
56668 + i = 0UL;
56669 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56670 + elf_dyn dyn;
56671 +
56672 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56673 + break;
56674 + if (dyn.d_tag == DT_NULL)
56675 + break;
56676 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56677 + gr_log_textrel(vma);
56678 + if (is_textrel_rw)
56679 + vma->vm_flags |= VM_MAYWRITE;
56680 + else
56681 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56682 + vma->vm_flags &= ~VM_MAYWRITE;
56683 + break;
56684 + }
56685 + i++;
56686 + }
56687 + is_textrel_rw = false;
56688 + is_textrel_rx = false;
56689 + continue;
56690 +
56691 + case PT_GNU_RELRO:
56692 + if (!is_relro)
56693 + continue;
56694 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56695 + vma->vm_flags &= ~VM_MAYWRITE;
56696 + is_relro = false;
56697 + continue;
56698 +
56699 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56700 + case PT_PAX_FLAGS: {
56701 + const char *msg_mprotect = "", *msg_emutramp = "";
56702 + char *buffer_lib, *buffer_exe;
56703 +
56704 + if (elf_p.p_flags & PF_NOMPROTECT)
56705 + msg_mprotect = "MPROTECT disabled";
56706 +
56707 +#ifdef CONFIG_PAX_EMUTRAMP
56708 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56709 + msg_emutramp = "EMUTRAMP enabled";
56710 +#endif
56711 +
56712 + if (!msg_mprotect[0] && !msg_emutramp[0])
56713 + continue;
56714 +
56715 + if (!printk_ratelimit())
56716 + continue;
56717 +
56718 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56719 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56720 + if (buffer_lib && buffer_exe) {
56721 + char *path_lib, *path_exe;
56722 +
56723 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56724 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56725 +
56726 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56727 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56728 +
56729 + }
56730 + free_page((unsigned long)buffer_exe);
56731 + free_page((unsigned long)buffer_lib);
56732 + continue;
56733 + }
56734 +#endif
56735 +
56736 + }
56737 + }
56738 +}
56739 +#endif
56740 +
56741 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56742 +
56743 +extern int grsec_enable_log_rwxmaps;
56744 +
56745 +static void elf_handle_mmap(struct file *file)
56746 +{
56747 + struct elfhdr elf_h;
56748 + struct elf_phdr elf_p;
56749 + unsigned long i;
56750 +
56751 + if (!grsec_enable_log_rwxmaps)
56752 + return;
56753 +
56754 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56755 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56756 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
56757 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56758 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56759 + return;
56760 +
56761 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56762 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56763 + return;
56764 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
56765 + gr_log_ptgnustack(file);
56766 + }
56767 +}
56768 +#endif
56769 +
56770 static int __init init_elf_binfmt(void)
56771 {
56772 register_binfmt(&elf_format);
56773 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
56774 index d50bbe5..af3b649 100644
56775 --- a/fs/binfmt_flat.c
56776 +++ b/fs/binfmt_flat.c
56777 @@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
56778 realdatastart = (unsigned long) -ENOMEM;
56779 printk("Unable to allocate RAM for process data, errno %d\n",
56780 (int)-realdatastart);
56781 + down_write(&current->mm->mmap_sem);
56782 vm_munmap(textpos, text_len);
56783 + up_write(&current->mm->mmap_sem);
56784 ret = realdatastart;
56785 goto err;
56786 }
56787 @@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56788 }
56789 if (IS_ERR_VALUE(result)) {
56790 printk("Unable to read data+bss, errno %d\n", (int)-result);
56791 + down_write(&current->mm->mmap_sem);
56792 vm_munmap(textpos, text_len);
56793 vm_munmap(realdatastart, len);
56794 + up_write(&current->mm->mmap_sem);
56795 ret = result;
56796 goto err;
56797 }
56798 @@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56799 }
56800 if (IS_ERR_VALUE(result)) {
56801 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
56802 + down_write(&current->mm->mmap_sem);
56803 vm_munmap(textpos, text_len + data_len + extra +
56804 MAX_SHARED_LIBS * sizeof(unsigned long));
56805 + up_write(&current->mm->mmap_sem);
56806 ret = result;
56807 goto err;
56808 }
56809 diff --git a/fs/bio.c b/fs/bio.c
56810 index 8754e7b..0669094 100644
56811 --- a/fs/bio.c
56812 +++ b/fs/bio.c
56813 @@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
56814 /*
56815 * Overflow, abort
56816 */
56817 - if (end < start)
56818 + if (end < start || end - start > INT_MAX - nr_pages)
56819 return ERR_PTR(-EINVAL);
56820
56821 nr_pages += end - start;
56822 @@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
56823 /*
56824 * Overflow, abort
56825 */
56826 - if (end < start)
56827 + if (end < start || end - start > INT_MAX - nr_pages)
56828 return ERR_PTR(-EINVAL);
56829
56830 nr_pages += end - start;
56831 @@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
56832 const int read = bio_data_dir(bio) == READ;
56833 struct bio_map_data *bmd = bio->bi_private;
56834 int i;
56835 - char *p = bmd->sgvecs[0].iov_base;
56836 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
56837
56838 bio_for_each_segment_all(bvec, bio, i) {
56839 char *addr = page_address(bvec->bv_page);
56840 diff --git a/fs/block_dev.c b/fs/block_dev.c
56841 index 1e86823..8e34695 100644
56842 --- a/fs/block_dev.c
56843 +++ b/fs/block_dev.c
56844 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
56845 else if (bdev->bd_contains == bdev)
56846 return true; /* is a whole device which isn't held */
56847
56848 - else if (whole->bd_holder == bd_may_claim)
56849 + else if (whole->bd_holder == (void *)bd_may_claim)
56850 return true; /* is a partition of a device that is being partitioned */
56851 else if (whole->bd_holder != NULL)
56852 return false; /* is a partition of a held device */
56853 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
56854 index cbd3a7d..c6a2881 100644
56855 --- a/fs/btrfs/ctree.c
56856 +++ b/fs/btrfs/ctree.c
56857 @@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
56858 free_extent_buffer(buf);
56859 add_root_to_dirty_list(root);
56860 } else {
56861 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
56862 - parent_start = parent->start;
56863 - else
56864 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
56865 + if (parent)
56866 + parent_start = parent->start;
56867 + else
56868 + parent_start = 0;
56869 + } else
56870 parent_start = 0;
56871
56872 WARN_ON(trans->transid != btrfs_header_generation(parent));
56873 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
56874 index 451b00c..a2cccee 100644
56875 --- a/fs/btrfs/delayed-inode.c
56876 +++ b/fs/btrfs/delayed-inode.c
56877 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
56878
56879 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
56880 {
56881 - int seq = atomic_inc_return(&delayed_root->items_seq);
56882 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
56883 if ((atomic_dec_return(&delayed_root->items) <
56884 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
56885 waitqueue_active(&delayed_root->wait))
56886 @@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
56887
56888 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
56889 {
56890 - int val = atomic_read(&delayed_root->items_seq);
56891 + int val = atomic_read_unchecked(&delayed_root->items_seq);
56892
56893 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
56894 return 1;
56895 @@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
56896 int seq;
56897 int ret;
56898
56899 - seq = atomic_read(&delayed_root->items_seq);
56900 + seq = atomic_read_unchecked(&delayed_root->items_seq);
56901
56902 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
56903 if (ret)
56904 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
56905 index f70119f..ab5894d 100644
56906 --- a/fs/btrfs/delayed-inode.h
56907 +++ b/fs/btrfs/delayed-inode.h
56908 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
56909 */
56910 struct list_head prepare_list;
56911 atomic_t items; /* for delayed items */
56912 - atomic_t items_seq; /* for delayed items */
56913 + atomic_unchecked_t items_seq; /* for delayed items */
56914 int nodes; /* for delayed nodes */
56915 wait_queue_head_t wait;
56916 };
56917 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
56918 struct btrfs_delayed_root *delayed_root)
56919 {
56920 atomic_set(&delayed_root->items, 0);
56921 - atomic_set(&delayed_root->items_seq, 0);
56922 + atomic_set_unchecked(&delayed_root->items_seq, 0);
56923 delayed_root->nodes = 0;
56924 spin_lock_init(&delayed_root->lock);
56925 init_waitqueue_head(&delayed_root->wait);
56926 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
56927 index a6d8efa..2f062cf 100644
56928 --- a/fs/btrfs/ioctl.c
56929 +++ b/fs/btrfs/ioctl.c
56930 @@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56931 for (i = 0; i < num_types; i++) {
56932 struct btrfs_space_info *tmp;
56933
56934 + /* Don't copy in more than we allocated */
56935 if (!slot_count)
56936 break;
56937
56938 + slot_count--;
56939 +
56940 info = NULL;
56941 rcu_read_lock();
56942 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
56943 @@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56944 memcpy(dest, &space, sizeof(space));
56945 dest++;
56946 space_args.total_spaces++;
56947 - slot_count--;
56948 }
56949 - if (!slot_count)
56950 - break;
56951 }
56952 up_read(&info->groups_sem);
56953 }
56954 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
56955 index d04db81..96e54f1 100644
56956 --- a/fs/btrfs/super.c
56957 +++ b/fs/btrfs/super.c
56958 @@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
56959 function, line, errstr);
56960 return;
56961 }
56962 - ACCESS_ONCE(trans->transaction->aborted) = errno;
56963 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
56964 /* Wake up anybody who may be waiting on this transaction */
56965 wake_up(&root->fs_info->transaction_wait);
56966 wake_up(&root->fs_info->transaction_blocked_wait);
56967 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
56968 index 865f4cf..f321e86 100644
56969 --- a/fs/btrfs/sysfs.c
56970 +++ b/fs/btrfs/sysfs.c
56971 @@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
56972 for (set = 0; set < FEAT_MAX; set++) {
56973 int i;
56974 struct attribute *attrs[2];
56975 - struct attribute_group agroup = {
56976 + attribute_group_no_const agroup = {
56977 .name = "features",
56978 .attrs = attrs,
56979 };
56980 diff --git a/fs/buffer.c b/fs/buffer.c
56981 index 27265a8..289f488 100644
56982 --- a/fs/buffer.c
56983 +++ b/fs/buffer.c
56984 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
56985 bh_cachep = kmem_cache_create("buffer_head",
56986 sizeof(struct buffer_head), 0,
56987 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
56988 - SLAB_MEM_SPREAD),
56989 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
56990 NULL);
56991
56992 /*
56993 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
56994 index 622f469..e8d2d55 100644
56995 --- a/fs/cachefiles/bind.c
56996 +++ b/fs/cachefiles/bind.c
56997 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
56998 args);
56999
57000 /* start by checking things over */
57001 - ASSERT(cache->fstop_percent >= 0 &&
57002 - cache->fstop_percent < cache->fcull_percent &&
57003 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57004 cache->fcull_percent < cache->frun_percent &&
57005 cache->frun_percent < 100);
57006
57007 - ASSERT(cache->bstop_percent >= 0 &&
57008 - cache->bstop_percent < cache->bcull_percent &&
57009 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57010 cache->bcull_percent < cache->brun_percent &&
57011 cache->brun_percent < 100);
57012
57013 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57014 index 0a1467b..6a53245 100644
57015 --- a/fs/cachefiles/daemon.c
57016 +++ b/fs/cachefiles/daemon.c
57017 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57018 if (n > buflen)
57019 return -EMSGSIZE;
57020
57021 - if (copy_to_user(_buffer, buffer, n) != 0)
57022 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57023 return -EFAULT;
57024
57025 return n;
57026 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57027 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57028 return -EIO;
57029
57030 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57031 + if (datalen > PAGE_SIZE - 1)
57032 return -EOPNOTSUPP;
57033
57034 /* drag the command string into the kernel so we can parse it */
57035 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57036 if (args[0] != '%' || args[1] != '\0')
57037 return -EINVAL;
57038
57039 - if (fstop < 0 || fstop >= cache->fcull_percent)
57040 + if (fstop >= cache->fcull_percent)
57041 return cachefiles_daemon_range_error(cache, args);
57042
57043 cache->fstop_percent = fstop;
57044 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57045 if (args[0] != '%' || args[1] != '\0')
57046 return -EINVAL;
57047
57048 - if (bstop < 0 || bstop >= cache->bcull_percent)
57049 + if (bstop >= cache->bcull_percent)
57050 return cachefiles_daemon_range_error(cache, args);
57051
57052 cache->bstop_percent = bstop;
57053 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57054 index 5349473..d6c0b93 100644
57055 --- a/fs/cachefiles/internal.h
57056 +++ b/fs/cachefiles/internal.h
57057 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57058 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57059 struct rb_root active_nodes; /* active nodes (can't be culled) */
57060 rwlock_t active_lock; /* lock for active_nodes */
57061 - atomic_t gravecounter; /* graveyard uniquifier */
57062 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57063 unsigned frun_percent; /* when to stop culling (% files) */
57064 unsigned fcull_percent; /* when to start culling (% files) */
57065 unsigned fstop_percent; /* when to stop allocating (% files) */
57066 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57067 * proc.c
57068 */
57069 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57070 -extern atomic_t cachefiles_lookup_histogram[HZ];
57071 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57072 -extern atomic_t cachefiles_create_histogram[HZ];
57073 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57074 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57075 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57076
57077 extern int __init cachefiles_proc_init(void);
57078 extern void cachefiles_proc_cleanup(void);
57079 static inline
57080 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57081 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57082 {
57083 unsigned long jif = jiffies - start_jif;
57084 if (jif >= HZ)
57085 jif = HZ - 1;
57086 - atomic_inc(&histogram[jif]);
57087 + atomic_inc_unchecked(&histogram[jif]);
57088 }
57089
57090 #else
57091 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57092 index ca65f39..48921e3 100644
57093 --- a/fs/cachefiles/namei.c
57094 +++ b/fs/cachefiles/namei.c
57095 @@ -317,7 +317,7 @@ try_again:
57096 /* first step is to make up a grave dentry in the graveyard */
57097 sprintf(nbuffer, "%08x%08x",
57098 (uint32_t) get_seconds(),
57099 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57100 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57101
57102 /* do the multiway lock magic */
57103 trap = lock_rename(cache->graveyard, dir);
57104 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57105 index eccd339..4c1d995 100644
57106 --- a/fs/cachefiles/proc.c
57107 +++ b/fs/cachefiles/proc.c
57108 @@ -14,9 +14,9 @@
57109 #include <linux/seq_file.h>
57110 #include "internal.h"
57111
57112 -atomic_t cachefiles_lookup_histogram[HZ];
57113 -atomic_t cachefiles_mkdir_histogram[HZ];
57114 -atomic_t cachefiles_create_histogram[HZ];
57115 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57116 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57117 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57118
57119 /*
57120 * display the latency histogram
57121 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57122 return 0;
57123 default:
57124 index = (unsigned long) v - 3;
57125 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57126 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57127 - z = atomic_read(&cachefiles_create_histogram[index]);
57128 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57129 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57130 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57131 if (x == 0 && y == 0 && z == 0)
57132 return 0;
57133
57134 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57135 index ebaff36..7e3ea26 100644
57136 --- a/fs/cachefiles/rdwr.c
57137 +++ b/fs/cachefiles/rdwr.c
57138 @@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57139 old_fs = get_fs();
57140 set_fs(KERNEL_DS);
57141 ret = file->f_op->write(
57142 - file, (const void __user *) data, len, &pos);
57143 + file, (const void __force_user *) data, len, &pos);
57144 set_fs(old_fs);
57145 kunmap(page);
57146 file_end_write(file);
57147 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57148 index 45eda6d..9126f7f 100644
57149 --- a/fs/ceph/dir.c
57150 +++ b/fs/ceph/dir.c
57151 @@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57152 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57153 struct ceph_mds_client *mdsc = fsc->mdsc;
57154 unsigned frag = fpos_frag(ctx->pos);
57155 - int off = fpos_off(ctx->pos);
57156 + unsigned int off = fpos_off(ctx->pos);
57157 int err;
57158 u32 ftype;
57159 struct ceph_mds_reply_info_parsed *rinfo;
57160 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57161 index 10a4ccb..92dbc5e 100644
57162 --- a/fs/ceph/super.c
57163 +++ b/fs/ceph/super.c
57164 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57165 /*
57166 * construct our own bdi so we can control readahead, etc.
57167 */
57168 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57169 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57170
57171 static int ceph_register_bdi(struct super_block *sb,
57172 struct ceph_fs_client *fsc)
57173 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57174 default_backing_dev_info.ra_pages;
57175
57176 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57177 - atomic_long_inc_return(&bdi_seq));
57178 + atomic_long_inc_return_unchecked(&bdi_seq));
57179 if (!err)
57180 sb->s_bdi = &fsc->backing_dev_info;
57181 return err;
57182 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57183 index f3ac415..3d2420c 100644
57184 --- a/fs/cifs/cifs_debug.c
57185 +++ b/fs/cifs/cifs_debug.c
57186 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57187
57188 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57189 #ifdef CONFIG_CIFS_STATS2
57190 - atomic_set(&totBufAllocCount, 0);
57191 - atomic_set(&totSmBufAllocCount, 0);
57192 + atomic_set_unchecked(&totBufAllocCount, 0);
57193 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57194 #endif /* CONFIG_CIFS_STATS2 */
57195 spin_lock(&cifs_tcp_ses_lock);
57196 list_for_each(tmp1, &cifs_tcp_ses_list) {
57197 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57198 tcon = list_entry(tmp3,
57199 struct cifs_tcon,
57200 tcon_list);
57201 - atomic_set(&tcon->num_smbs_sent, 0);
57202 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57203 if (server->ops->clear_stats)
57204 server->ops->clear_stats(tcon);
57205 }
57206 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57207 smBufAllocCount.counter, cifs_min_small);
57208 #ifdef CONFIG_CIFS_STATS2
57209 seq_printf(m, "Total Large %d Small %d Allocations\n",
57210 - atomic_read(&totBufAllocCount),
57211 - atomic_read(&totSmBufAllocCount));
57212 + atomic_read_unchecked(&totBufAllocCount),
57213 + atomic_read_unchecked(&totSmBufAllocCount));
57214 #endif /* CONFIG_CIFS_STATS2 */
57215
57216 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57217 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57218 if (tcon->need_reconnect)
57219 seq_puts(m, "\tDISCONNECTED ");
57220 seq_printf(m, "\nSMBs: %d",
57221 - atomic_read(&tcon->num_smbs_sent));
57222 + atomic_read_unchecked(&tcon->num_smbs_sent));
57223 if (server->ops->print_stats)
57224 server->ops->print_stats(m, tcon);
57225 }
57226 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57227 index 849f613..eae6dec 100644
57228 --- a/fs/cifs/cifsfs.c
57229 +++ b/fs/cifs/cifsfs.c
57230 @@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57231 */
57232 cifs_req_cachep = kmem_cache_create("cifs_request",
57233 CIFSMaxBufSize + max_hdr_size, 0,
57234 - SLAB_HWCACHE_ALIGN, NULL);
57235 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57236 if (cifs_req_cachep == NULL)
57237 return -ENOMEM;
57238
57239 @@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57240 efficient to alloc 1 per page off the slab compared to 17K (5page)
57241 alloc of large cifs buffers even when page debugging is on */
57242 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57243 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57244 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57245 NULL);
57246 if (cifs_sm_req_cachep == NULL) {
57247 mempool_destroy(cifs_req_poolp);
57248 @@ -1168,8 +1168,8 @@ init_cifs(void)
57249 atomic_set(&bufAllocCount, 0);
57250 atomic_set(&smBufAllocCount, 0);
57251 #ifdef CONFIG_CIFS_STATS2
57252 - atomic_set(&totBufAllocCount, 0);
57253 - atomic_set(&totSmBufAllocCount, 0);
57254 + atomic_set_unchecked(&totBufAllocCount, 0);
57255 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57256 #endif /* CONFIG_CIFS_STATS2 */
57257
57258 atomic_set(&midCount, 0);
57259 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57260 index c0f3718..6afed7d 100644
57261 --- a/fs/cifs/cifsglob.h
57262 +++ b/fs/cifs/cifsglob.h
57263 @@ -804,35 +804,35 @@ struct cifs_tcon {
57264 __u16 Flags; /* optional support bits */
57265 enum statusEnum tidStatus;
57266 #ifdef CONFIG_CIFS_STATS
57267 - atomic_t num_smbs_sent;
57268 + atomic_unchecked_t num_smbs_sent;
57269 union {
57270 struct {
57271 - atomic_t num_writes;
57272 - atomic_t num_reads;
57273 - atomic_t num_flushes;
57274 - atomic_t num_oplock_brks;
57275 - atomic_t num_opens;
57276 - atomic_t num_closes;
57277 - atomic_t num_deletes;
57278 - atomic_t num_mkdirs;
57279 - atomic_t num_posixopens;
57280 - atomic_t num_posixmkdirs;
57281 - atomic_t num_rmdirs;
57282 - atomic_t num_renames;
57283 - atomic_t num_t2renames;
57284 - atomic_t num_ffirst;
57285 - atomic_t num_fnext;
57286 - atomic_t num_fclose;
57287 - atomic_t num_hardlinks;
57288 - atomic_t num_symlinks;
57289 - atomic_t num_locks;
57290 - atomic_t num_acl_get;
57291 - atomic_t num_acl_set;
57292 + atomic_unchecked_t num_writes;
57293 + atomic_unchecked_t num_reads;
57294 + atomic_unchecked_t num_flushes;
57295 + atomic_unchecked_t num_oplock_brks;
57296 + atomic_unchecked_t num_opens;
57297 + atomic_unchecked_t num_closes;
57298 + atomic_unchecked_t num_deletes;
57299 + atomic_unchecked_t num_mkdirs;
57300 + atomic_unchecked_t num_posixopens;
57301 + atomic_unchecked_t num_posixmkdirs;
57302 + atomic_unchecked_t num_rmdirs;
57303 + atomic_unchecked_t num_renames;
57304 + atomic_unchecked_t num_t2renames;
57305 + atomic_unchecked_t num_ffirst;
57306 + atomic_unchecked_t num_fnext;
57307 + atomic_unchecked_t num_fclose;
57308 + atomic_unchecked_t num_hardlinks;
57309 + atomic_unchecked_t num_symlinks;
57310 + atomic_unchecked_t num_locks;
57311 + atomic_unchecked_t num_acl_get;
57312 + atomic_unchecked_t num_acl_set;
57313 } cifs_stats;
57314 #ifdef CONFIG_CIFS_SMB2
57315 struct {
57316 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57317 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57318 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57319 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57320 } smb2_stats;
57321 #endif /* CONFIG_CIFS_SMB2 */
57322 } stats;
57323 @@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
57324 }
57325
57326 #ifdef CONFIG_CIFS_STATS
57327 -#define cifs_stats_inc atomic_inc
57328 +#define cifs_stats_inc atomic_inc_unchecked
57329
57330 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57331 unsigned int bytes)
57332 @@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57333 /* Various Debug counters */
57334 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57335 #ifdef CONFIG_CIFS_STATS2
57336 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57337 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57338 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57339 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57340 #endif
57341 GLOBAL_EXTERN atomic_t smBufAllocCount;
57342 GLOBAL_EXTERN atomic_t midCount;
57343 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57344 index 834fce7..8a314b5 100644
57345 --- a/fs/cifs/file.c
57346 +++ b/fs/cifs/file.c
57347 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57348 index = mapping->writeback_index; /* Start from prev offset */
57349 end = -1;
57350 } else {
57351 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
57352 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
57353 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57354 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57355 range_whole = true;
57356 + index = 0;
57357 + end = ULONG_MAX;
57358 + } else {
57359 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
57360 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
57361 + }
57362 scanned = true;
57363 }
57364 retry:
57365 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57366 index 2f9f379..43f8025 100644
57367 --- a/fs/cifs/misc.c
57368 +++ b/fs/cifs/misc.c
57369 @@ -170,7 +170,7 @@ cifs_buf_get(void)
57370 memset(ret_buf, 0, buf_size + 3);
57371 atomic_inc(&bufAllocCount);
57372 #ifdef CONFIG_CIFS_STATS2
57373 - atomic_inc(&totBufAllocCount);
57374 + atomic_inc_unchecked(&totBufAllocCount);
57375 #endif /* CONFIG_CIFS_STATS2 */
57376 }
57377
57378 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57379 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57380 atomic_inc(&smBufAllocCount);
57381 #ifdef CONFIG_CIFS_STATS2
57382 - atomic_inc(&totSmBufAllocCount);
57383 + atomic_inc_unchecked(&totSmBufAllocCount);
57384 #endif /* CONFIG_CIFS_STATS2 */
57385
57386 }
57387 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57388 index 526fb89..ecdbf5a 100644
57389 --- a/fs/cifs/smb1ops.c
57390 +++ b/fs/cifs/smb1ops.c
57391 @@ -616,27 +616,27 @@ static void
57392 cifs_clear_stats(struct cifs_tcon *tcon)
57393 {
57394 #ifdef CONFIG_CIFS_STATS
57395 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57396 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57397 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57398 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57399 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57400 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57401 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57402 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57403 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57404 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57405 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57406 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57407 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57408 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57409 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57410 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57411 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57412 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57413 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57414 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57415 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57416 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57417 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57418 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57419 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57420 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57421 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57422 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57423 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57424 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57425 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57426 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57427 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57428 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57429 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57430 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57431 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57432 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57433 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57434 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57435 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57436 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57437 #endif
57438 }
57439
57440 @@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57441 {
57442 #ifdef CONFIG_CIFS_STATS
57443 seq_printf(m, " Oplocks breaks: %d",
57444 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57445 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57446 seq_printf(m, "\nReads: %d Bytes: %llu",
57447 - atomic_read(&tcon->stats.cifs_stats.num_reads),
57448 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57449 (long long)(tcon->bytes_read));
57450 seq_printf(m, "\nWrites: %d Bytes: %llu",
57451 - atomic_read(&tcon->stats.cifs_stats.num_writes),
57452 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57453 (long long)(tcon->bytes_written));
57454 seq_printf(m, "\nFlushes: %d",
57455 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
57456 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57457 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57458 - atomic_read(&tcon->stats.cifs_stats.num_locks),
57459 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57460 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57461 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57462 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57463 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57464 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57465 - atomic_read(&tcon->stats.cifs_stats.num_opens),
57466 - atomic_read(&tcon->stats.cifs_stats.num_closes),
57467 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
57468 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57469 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57470 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57471 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57472 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57473 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57474 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57475 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57476 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57477 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57478 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57479 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57480 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57481 seq_printf(m, "\nRenames: %d T2 Renames %d",
57482 - atomic_read(&tcon->stats.cifs_stats.num_renames),
57483 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57484 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57485 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57486 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57487 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57488 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
57489 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
57490 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57491 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57492 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57493 #endif
57494 }
57495
57496 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57497 index 192f51a..539307e 100644
57498 --- a/fs/cifs/smb2ops.c
57499 +++ b/fs/cifs/smb2ops.c
57500 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57501 #ifdef CONFIG_CIFS_STATS
57502 int i;
57503 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57504 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57505 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57506 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57507 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57508 }
57509 #endif
57510 }
57511 @@ -405,65 +405,65 @@ static void
57512 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57513 {
57514 #ifdef CONFIG_CIFS_STATS
57515 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57516 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57517 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57518 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57519 seq_printf(m, "\nNegotiates: %d sent %d failed",
57520 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57521 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57522 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57523 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57524 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57525 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57526 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57527 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57528 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57529 seq_printf(m, "\nLogoffs: %d sent %d failed",
57530 - atomic_read(&sent[SMB2_LOGOFF_HE]),
57531 - atomic_read(&failed[SMB2_LOGOFF_HE]));
57532 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57533 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57534 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57535 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57536 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57537 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57538 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57539 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57540 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57541 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57542 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57543 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57544 seq_printf(m, "\nCreates: %d sent %d failed",
57545 - atomic_read(&sent[SMB2_CREATE_HE]),
57546 - atomic_read(&failed[SMB2_CREATE_HE]));
57547 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57548 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57549 seq_printf(m, "\nCloses: %d sent %d failed",
57550 - atomic_read(&sent[SMB2_CLOSE_HE]),
57551 - atomic_read(&failed[SMB2_CLOSE_HE]));
57552 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57553 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57554 seq_printf(m, "\nFlushes: %d sent %d failed",
57555 - atomic_read(&sent[SMB2_FLUSH_HE]),
57556 - atomic_read(&failed[SMB2_FLUSH_HE]));
57557 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57558 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57559 seq_printf(m, "\nReads: %d sent %d failed",
57560 - atomic_read(&sent[SMB2_READ_HE]),
57561 - atomic_read(&failed[SMB2_READ_HE]));
57562 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
57563 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
57564 seq_printf(m, "\nWrites: %d sent %d failed",
57565 - atomic_read(&sent[SMB2_WRITE_HE]),
57566 - atomic_read(&failed[SMB2_WRITE_HE]));
57567 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57568 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57569 seq_printf(m, "\nLocks: %d sent %d failed",
57570 - atomic_read(&sent[SMB2_LOCK_HE]),
57571 - atomic_read(&failed[SMB2_LOCK_HE]));
57572 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57573 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57574 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57575 - atomic_read(&sent[SMB2_IOCTL_HE]),
57576 - atomic_read(&failed[SMB2_IOCTL_HE]));
57577 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57578 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57579 seq_printf(m, "\nCancels: %d sent %d failed",
57580 - atomic_read(&sent[SMB2_CANCEL_HE]),
57581 - atomic_read(&failed[SMB2_CANCEL_HE]));
57582 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57583 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57584 seq_printf(m, "\nEchos: %d sent %d failed",
57585 - atomic_read(&sent[SMB2_ECHO_HE]),
57586 - atomic_read(&failed[SMB2_ECHO_HE]));
57587 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57588 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57589 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57590 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57591 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57592 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57593 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57594 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57595 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57596 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57597 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57598 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57599 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57600 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57601 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57602 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57603 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57604 seq_printf(m, "\nSetInfos: %d sent %d failed",
57605 - atomic_read(&sent[SMB2_SET_INFO_HE]),
57606 - atomic_read(&failed[SMB2_SET_INFO_HE]));
57607 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57608 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57609 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57610 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57611 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57612 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57613 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57614 #endif
57615 }
57616
57617 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57618 index 8603447..f9caeee 100644
57619 --- a/fs/cifs/smb2pdu.c
57620 +++ b/fs/cifs/smb2pdu.c
57621 @@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57622 default:
57623 cifs_dbg(VFS, "info level %u isn't supported\n",
57624 srch_inf->info_level);
57625 - rc = -EINVAL;
57626 - goto qdir_exit;
57627 + return -EINVAL;
57628 }
57629
57630 req->FileIndex = cpu_to_le32(index);
57631 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57632 index 1da168c..8bc7ff6 100644
57633 --- a/fs/coda/cache.c
57634 +++ b/fs/coda/cache.c
57635 @@ -24,7 +24,7 @@
57636 #include "coda_linux.h"
57637 #include "coda_cache.h"
57638
57639 -static atomic_t permission_epoch = ATOMIC_INIT(0);
57640 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57641
57642 /* replace or extend an acl cache hit */
57643 void coda_cache_enter(struct inode *inode, int mask)
57644 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57645 struct coda_inode_info *cii = ITOC(inode);
57646
57647 spin_lock(&cii->c_lock);
57648 - cii->c_cached_epoch = atomic_read(&permission_epoch);
57649 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57650 if (!uid_eq(cii->c_uid, current_fsuid())) {
57651 cii->c_uid = current_fsuid();
57652 cii->c_cached_perm = mask;
57653 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57654 {
57655 struct coda_inode_info *cii = ITOC(inode);
57656 spin_lock(&cii->c_lock);
57657 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57658 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57659 spin_unlock(&cii->c_lock);
57660 }
57661
57662 /* remove all acl caches */
57663 void coda_cache_clear_all(struct super_block *sb)
57664 {
57665 - atomic_inc(&permission_epoch);
57666 + atomic_inc_unchecked(&permission_epoch);
57667 }
57668
57669
57670 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57671 spin_lock(&cii->c_lock);
57672 hit = (mask & cii->c_cached_perm) == mask &&
57673 uid_eq(cii->c_uid, current_fsuid()) &&
57674 - cii->c_cached_epoch == atomic_read(&permission_epoch);
57675 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57676 spin_unlock(&cii->c_lock);
57677
57678 return hit;
57679 diff --git a/fs/compat.c b/fs/compat.c
57680 index 6af20de..fec3fbb 100644
57681 --- a/fs/compat.c
57682 +++ b/fs/compat.c
57683 @@ -54,7 +54,7 @@
57684 #include <asm/ioctls.h>
57685 #include "internal.h"
57686
57687 -int compat_log = 1;
57688 +int compat_log = 0;
57689
57690 int compat_printk(const char *fmt, ...)
57691 {
57692 @@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57693
57694 set_fs(KERNEL_DS);
57695 /* The __user pointer cast is valid because of the set_fs() */
57696 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57697 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57698 set_fs(oldfs);
57699 /* truncating is ok because it's a user address */
57700 if (!ret)
57701 @@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57702 goto out;
57703
57704 ret = -EINVAL;
57705 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57706 + if (nr_segs > UIO_MAXIOV)
57707 goto out;
57708 if (nr_segs > fast_segs) {
57709 ret = -ENOMEM;
57710 @@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57711 struct compat_readdir_callback {
57712 struct dir_context ctx;
57713 struct compat_old_linux_dirent __user *dirent;
57714 + struct file * file;
57715 int result;
57716 };
57717
57718 @@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57719 buf->result = -EOVERFLOW;
57720 return -EOVERFLOW;
57721 }
57722 +
57723 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57724 + return 0;
57725 +
57726 buf->result++;
57727 dirent = buf->dirent;
57728 if (!access_ok(VERIFY_WRITE, dirent,
57729 @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57730 if (!f.file)
57731 return -EBADF;
57732
57733 + buf.file = f.file;
57734 error = iterate_dir(f.file, &buf.ctx);
57735 if (buf.result)
57736 error = buf.result;
57737 @@ -901,6 +907,7 @@ struct compat_getdents_callback {
57738 struct dir_context ctx;
57739 struct compat_linux_dirent __user *current_dir;
57740 struct compat_linux_dirent __user *previous;
57741 + struct file * file;
57742 int count;
57743 int error;
57744 };
57745 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57746 buf->error = -EOVERFLOW;
57747 return -EOVERFLOW;
57748 }
57749 +
57750 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57751 + return 0;
57752 +
57753 dirent = buf->previous;
57754 if (dirent) {
57755 if (__put_user(offset, &dirent->d_off))
57756 @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57757 if (!f.file)
57758 return -EBADF;
57759
57760 + buf.file = f.file;
57761 error = iterate_dir(f.file, &buf.ctx);
57762 if (error >= 0)
57763 error = buf.error;
57764 @@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
57765 struct dir_context ctx;
57766 struct linux_dirent64 __user *current_dir;
57767 struct linux_dirent64 __user *previous;
57768 + struct file * file;
57769 int count;
57770 int error;
57771 };
57772 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
57773 buf->error = -EINVAL; /* only used if we fail.. */
57774 if (reclen > buf->count)
57775 return -EINVAL;
57776 +
57777 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57778 + return 0;
57779 +
57780 dirent = buf->previous;
57781
57782 if (dirent) {
57783 @@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
57784 if (!f.file)
57785 return -EBADF;
57786
57787 + buf.file = f.file;
57788 error = iterate_dir(f.file, &buf.ctx);
57789 if (error >= 0)
57790 error = buf.error;
57791 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
57792 index a81147e..20bf2b5 100644
57793 --- a/fs/compat_binfmt_elf.c
57794 +++ b/fs/compat_binfmt_elf.c
57795 @@ -30,11 +30,13 @@
57796 #undef elf_phdr
57797 #undef elf_shdr
57798 #undef elf_note
57799 +#undef elf_dyn
57800 #undef elf_addr_t
57801 #define elfhdr elf32_hdr
57802 #define elf_phdr elf32_phdr
57803 #define elf_shdr elf32_shdr
57804 #define elf_note elf32_note
57805 +#define elf_dyn Elf32_Dyn
57806 #define elf_addr_t Elf32_Addr
57807
57808 /*
57809 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
57810 index 3881610..ab3df0b 100644
57811 --- a/fs/compat_ioctl.c
57812 +++ b/fs/compat_ioctl.c
57813 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
57814 return -EFAULT;
57815 if (__get_user(udata, &ss32->iomem_base))
57816 return -EFAULT;
57817 - ss.iomem_base = compat_ptr(udata);
57818 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
57819 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
57820 __get_user(ss.port_high, &ss32->port_high))
57821 return -EFAULT;
57822 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
57823 for (i = 0; i < nmsgs; i++) {
57824 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
57825 return -EFAULT;
57826 - if (get_user(datap, &umsgs[i].buf) ||
57827 - put_user(compat_ptr(datap), &tmsgs[i].buf))
57828 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
57829 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
57830 return -EFAULT;
57831 }
57832 return sys_ioctl(fd, cmd, (unsigned long)tdata);
57833 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
57834 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
57835 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
57836 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
57837 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
57838 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
57839 return -EFAULT;
57840
57841 return ioctl_preallocate(file, p);
57842 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
57843 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
57844 {
57845 unsigned int a, b;
57846 - a = *(unsigned int *)p;
57847 - b = *(unsigned int *)q;
57848 + a = *(const unsigned int *)p;
57849 + b = *(const unsigned int *)q;
57850 if (a > b)
57851 return 1;
57852 if (a < b)
57853 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
57854 index e081acb..911df21 100644
57855 --- a/fs/configfs/dir.c
57856 +++ b/fs/configfs/dir.c
57857 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57858 }
57859 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
57860 struct configfs_dirent *next;
57861 - const char *name;
57862 + const unsigned char * name;
57863 + char d_name[sizeof(next->s_dentry->d_iname)];
57864 int len;
57865 struct inode *inode = NULL;
57866
57867 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57868 continue;
57869
57870 name = configfs_get_name(next);
57871 - len = strlen(name);
57872 + if (next->s_dentry && name == next->s_dentry->d_iname) {
57873 + len = next->s_dentry->d_name.len;
57874 + memcpy(d_name, name, len);
57875 + name = d_name;
57876 + } else
57877 + len = strlen(name);
57878
57879 /*
57880 * We'll have a dentry and an inode for
57881 diff --git a/fs/coredump.c b/fs/coredump.c
57882 index e3ad709..4a1552d 100644
57883 --- a/fs/coredump.c
57884 +++ b/fs/coredump.c
57885 @@ -437,8 +437,8 @@ static void wait_for_dump_helpers(struct file *file)
57886 struct pipe_inode_info *pipe = file->private_data;
57887
57888 pipe_lock(pipe);
57889 - pipe->readers++;
57890 - pipe->writers--;
57891 + atomic_inc(&pipe->readers);
57892 + atomic_dec(&pipe->writers);
57893 wake_up_interruptible_sync(&pipe->wait);
57894 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
57895 pipe_unlock(pipe);
57896 @@ -447,11 +447,11 @@ static void wait_for_dump_helpers(struct file *file)
57897 * We actually want wait_event_freezable() but then we need
57898 * to clear TIF_SIGPENDING and improve dump_interrupted().
57899 */
57900 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
57901 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
57902
57903 pipe_lock(pipe);
57904 - pipe->readers--;
57905 - pipe->writers++;
57906 + atomic_dec(&pipe->readers);
57907 + atomic_inc(&pipe->writers);
57908 pipe_unlock(pipe);
57909 }
57910
57911 @@ -498,7 +498,9 @@ void do_coredump(const siginfo_t *siginfo)
57912 struct files_struct *displaced;
57913 bool need_nonrelative = false;
57914 bool core_dumped = false;
57915 - static atomic_t core_dump_count = ATOMIC_INIT(0);
57916 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
57917 + long signr = siginfo->si_signo;
57918 + int dumpable;
57919 struct coredump_params cprm = {
57920 .siginfo = siginfo,
57921 .regs = signal_pt_regs(),
57922 @@ -511,12 +513,17 @@ void do_coredump(const siginfo_t *siginfo)
57923 .mm_flags = mm->flags,
57924 };
57925
57926 - audit_core_dumps(siginfo->si_signo);
57927 + audit_core_dumps(signr);
57928 +
57929 + dumpable = __get_dumpable(cprm.mm_flags);
57930 +
57931 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
57932 + gr_handle_brute_attach(dumpable);
57933
57934 binfmt = mm->binfmt;
57935 if (!binfmt || !binfmt->core_dump)
57936 goto fail;
57937 - if (!__get_dumpable(cprm.mm_flags))
57938 + if (!dumpable)
57939 goto fail;
57940
57941 cred = prepare_creds();
57942 @@ -535,7 +542,7 @@ void do_coredump(const siginfo_t *siginfo)
57943 need_nonrelative = true;
57944 }
57945
57946 - retval = coredump_wait(siginfo->si_signo, &core_state);
57947 + retval = coredump_wait(signr, &core_state);
57948 if (retval < 0)
57949 goto fail_creds;
57950
57951 @@ -578,7 +585,7 @@ void do_coredump(const siginfo_t *siginfo)
57952 }
57953 cprm.limit = RLIM_INFINITY;
57954
57955 - dump_count = atomic_inc_return(&core_dump_count);
57956 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
57957 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
57958 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
57959 task_tgid_vnr(current), current->comm);
57960 @@ -610,6 +617,8 @@ void do_coredump(const siginfo_t *siginfo)
57961 } else {
57962 struct inode *inode;
57963
57964 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
57965 +
57966 if (cprm.limit < binfmt->min_coredump)
57967 goto fail_unlock;
57968
57969 @@ -668,7 +677,7 @@ close_fail:
57970 filp_close(cprm.file, NULL);
57971 fail_dropcount:
57972 if (ispipe)
57973 - atomic_dec(&core_dump_count);
57974 + atomic_dec_unchecked(&core_dump_count);
57975 fail_unlock:
57976 kfree(cn.corename);
57977 coredump_finish(mm, core_dumped);
57978 @@ -689,6 +698,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
57979 struct file *file = cprm->file;
57980 loff_t pos = file->f_pos;
57981 ssize_t n;
57982 +
57983 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
57984 if (cprm->written + nr > cprm->limit)
57985 return 0;
57986 while (nr) {
57987 diff --git a/fs/dcache.c b/fs/dcache.c
57988 index ca02c13..7e2b581 100644
57989 --- a/fs/dcache.c
57990 +++ b/fs/dcache.c
57991 @@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
57992 */
57993 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
57994 if (name->len > DNAME_INLINE_LEN-1) {
57995 - dname = kmalloc(name->len + 1, GFP_KERNEL);
57996 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
57997 if (!dname) {
57998 kmem_cache_free(dentry_cache, dentry);
57999 return NULL;
58000 @@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
58001 mempages -= reserve;
58002
58003 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58004 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58005 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58006 + SLAB_NO_SANITIZE, NULL);
58007
58008 dcache_init();
58009 inode_init();
58010 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58011 index 9c0444c..628490c 100644
58012 --- a/fs/debugfs/inode.c
58013 +++ b/fs/debugfs/inode.c
58014 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58015 */
58016 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58017 {
58018 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58019 + return __create_file(name, S_IFDIR | S_IRWXU,
58020 +#else
58021 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58022 +#endif
58023 parent, NULL, NULL);
58024 }
58025 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58026 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58027 index b167ca4..a224e19 100644
58028 --- a/fs/ecryptfs/inode.c
58029 +++ b/fs/ecryptfs/inode.c
58030 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58031 old_fs = get_fs();
58032 set_fs(get_ds());
58033 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58034 - (char __user *)lower_buf,
58035 + (char __force_user *)lower_buf,
58036 PATH_MAX);
58037 set_fs(old_fs);
58038 if (rc < 0)
58039 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58040 index e4141f2..d8263e8 100644
58041 --- a/fs/ecryptfs/miscdev.c
58042 +++ b/fs/ecryptfs/miscdev.c
58043 @@ -304,7 +304,7 @@ check_list:
58044 goto out_unlock_msg_ctx;
58045 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58046 if (msg_ctx->msg) {
58047 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58048 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58049 goto out_unlock_msg_ctx;
58050 i += packet_length_size;
58051 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58052 diff --git a/fs/exec.c b/fs/exec.c
58053 index 3d78fcc..5a38b6b 100644
58054 --- a/fs/exec.c
58055 +++ b/fs/exec.c
58056 @@ -55,8 +55,20 @@
58057 #include <linux/pipe_fs_i.h>
58058 #include <linux/oom.h>
58059 #include <linux/compat.h>
58060 +#include <linux/random.h>
58061 +#include <linux/seq_file.h>
58062 +#include <linux/coredump.h>
58063 +#include <linux/mman.h>
58064 +
58065 +#ifdef CONFIG_PAX_REFCOUNT
58066 +#include <linux/kallsyms.h>
58067 +#include <linux/kdebug.h>
58068 +#endif
58069 +
58070 +#include <trace/events/fs.h>
58071
58072 #include <asm/uaccess.h>
58073 +#include <asm/sections.h>
58074 #include <asm/mmu_context.h>
58075 #include <asm/tlb.h>
58076
58077 @@ -65,19 +77,34 @@
58078
58079 #include <trace/events/sched.h>
58080
58081 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58082 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58083 +{
58084 + 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");
58085 +}
58086 +#endif
58087 +
58088 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58089 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58090 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58091 +#endif
58092 +
58093 int suid_dumpable = 0;
58094
58095 static LIST_HEAD(formats);
58096 static DEFINE_RWLOCK(binfmt_lock);
58097
58098 +extern int gr_process_kernel_exec_ban(void);
58099 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58100 +
58101 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58102 {
58103 BUG_ON(!fmt);
58104 if (WARN_ON(!fmt->load_binary))
58105 return;
58106 write_lock(&binfmt_lock);
58107 - insert ? list_add(&fmt->lh, &formats) :
58108 - list_add_tail(&fmt->lh, &formats);
58109 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58110 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58111 write_unlock(&binfmt_lock);
58112 }
58113
58114 @@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58115 void unregister_binfmt(struct linux_binfmt * fmt)
58116 {
58117 write_lock(&binfmt_lock);
58118 - list_del(&fmt->lh);
58119 + pax_list_del((struct list_head *)&fmt->lh);
58120 write_unlock(&binfmt_lock);
58121 }
58122
58123 @@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58124 int write)
58125 {
58126 struct page *page;
58127 - int ret;
58128
58129 -#ifdef CONFIG_STACK_GROWSUP
58130 - if (write) {
58131 - ret = expand_downwards(bprm->vma, pos);
58132 - if (ret < 0)
58133 - return NULL;
58134 - }
58135 -#endif
58136 - ret = get_user_pages(current, bprm->mm, pos,
58137 - 1, write, 1, &page, NULL);
58138 - if (ret <= 0)
58139 + if (0 > expand_downwards(bprm->vma, pos))
58140 + return NULL;
58141 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58142 return NULL;
58143
58144 if (write) {
58145 @@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58146 if (size <= ARG_MAX)
58147 return page;
58148
58149 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58150 + // only allow 512KB for argv+env on suid/sgid binaries
58151 + // to prevent easy ASLR exhaustion
58152 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58153 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58154 + (size > (512 * 1024))) {
58155 + put_page(page);
58156 + return NULL;
58157 + }
58158 +#endif
58159 +
58160 /*
58161 * Limit to 1/4-th the stack size for the argv+env strings.
58162 * This ensures that:
58163 @@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58164 vma->vm_end = STACK_TOP_MAX;
58165 vma->vm_start = vma->vm_end - PAGE_SIZE;
58166 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58167 +
58168 +#ifdef CONFIG_PAX_SEGMEXEC
58169 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58170 +#endif
58171 +
58172 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58173 INIT_LIST_HEAD(&vma->anon_vma_chain);
58174
58175 @@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58176 mm->stack_vm = mm->total_vm = 1;
58177 up_write(&mm->mmap_sem);
58178 bprm->p = vma->vm_end - sizeof(void *);
58179 +
58180 +#ifdef CONFIG_PAX_RANDUSTACK
58181 + if (randomize_va_space)
58182 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
58183 +#endif
58184 +
58185 return 0;
58186 err:
58187 up_write(&mm->mmap_sem);
58188 @@ -396,7 +437,7 @@ struct user_arg_ptr {
58189 } ptr;
58190 };
58191
58192 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58193 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58194 {
58195 const char __user *native;
58196
58197 @@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58198 compat_uptr_t compat;
58199
58200 if (get_user(compat, argv.ptr.compat + nr))
58201 - return ERR_PTR(-EFAULT);
58202 + return (const char __force_user *)ERR_PTR(-EFAULT);
58203
58204 return compat_ptr(compat);
58205 }
58206 #endif
58207
58208 if (get_user(native, argv.ptr.native + nr))
58209 - return ERR_PTR(-EFAULT);
58210 + return (const char __force_user *)ERR_PTR(-EFAULT);
58211
58212 return native;
58213 }
58214 @@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
58215 if (!p)
58216 break;
58217
58218 - if (IS_ERR(p))
58219 + if (IS_ERR((const char __force_kernel *)p))
58220 return -EFAULT;
58221
58222 if (i >= max)
58223 @@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58224
58225 ret = -EFAULT;
58226 str = get_user_arg_ptr(argv, argc);
58227 - if (IS_ERR(str))
58228 + if (IS_ERR((const char __force_kernel *)str))
58229 goto out;
58230
58231 len = strnlen_user(str, MAX_ARG_STRLEN);
58232 @@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58233 int r;
58234 mm_segment_t oldfs = get_fs();
58235 struct user_arg_ptr argv = {
58236 - .ptr.native = (const char __user *const __user *)__argv,
58237 + .ptr.native = (const char __user * const __force_user *)__argv,
58238 };
58239
58240 set_fs(KERNEL_DS);
58241 @@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58242 unsigned long new_end = old_end - shift;
58243 struct mmu_gather tlb;
58244
58245 - BUG_ON(new_start > new_end);
58246 + if (new_start >= new_end || new_start < mmap_min_addr)
58247 + return -ENOMEM;
58248
58249 /*
58250 * ensure there are no vmas between where we want to go
58251 @@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58252 if (vma != find_vma(mm, new_start))
58253 return -EFAULT;
58254
58255 +#ifdef CONFIG_PAX_SEGMEXEC
58256 + BUG_ON(pax_find_mirror_vma(vma));
58257 +#endif
58258 +
58259 /*
58260 * cover the whole range: [new_start, old_end)
58261 */
58262 @@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58263 stack_top = arch_align_stack(stack_top);
58264 stack_top = PAGE_ALIGN(stack_top);
58265
58266 - if (unlikely(stack_top < mmap_min_addr) ||
58267 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58268 - return -ENOMEM;
58269 -
58270 stack_shift = vma->vm_end - stack_top;
58271
58272 bprm->p -= stack_shift;
58273 @@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58274 bprm->exec -= stack_shift;
58275
58276 down_write(&mm->mmap_sem);
58277 +
58278 + /* Move stack pages down in memory. */
58279 + if (stack_shift) {
58280 + ret = shift_arg_pages(vma, stack_shift);
58281 + if (ret)
58282 + goto out_unlock;
58283 + }
58284 +
58285 vm_flags = VM_STACK_FLAGS;
58286
58287 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58288 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58289 + vm_flags &= ~VM_EXEC;
58290 +
58291 +#ifdef CONFIG_PAX_MPROTECT
58292 + if (mm->pax_flags & MF_PAX_MPROTECT)
58293 + vm_flags &= ~VM_MAYEXEC;
58294 +#endif
58295 +
58296 + }
58297 +#endif
58298 +
58299 /*
58300 * Adjust stack execute permissions; explicitly enable for
58301 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58302 @@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58303 goto out_unlock;
58304 BUG_ON(prev != vma);
58305
58306 - /* Move stack pages down in memory. */
58307 - if (stack_shift) {
58308 - ret = shift_arg_pages(vma, stack_shift);
58309 - if (ret)
58310 - goto out_unlock;
58311 - }
58312 -
58313 /* mprotect_fixup is overkill to remove the temporary stack flags */
58314 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58315
58316 @@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58317 #endif
58318 current->mm->start_stack = bprm->p;
58319 ret = expand_stack(vma, stack_base);
58320 +
58321 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58322 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58323 + unsigned long size;
58324 + vm_flags_t vm_flags;
58325 +
58326 + size = STACK_TOP - vma->vm_end;
58327 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58328 +
58329 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58330 +
58331 +#ifdef CONFIG_X86
58332 + if (!ret) {
58333 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58334 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58335 + }
58336 +#endif
58337 +
58338 + }
58339 +#endif
58340 +
58341 if (ret)
58342 ret = -EFAULT;
58343
58344 @@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
58345
58346 fsnotify_open(file);
58347
58348 + trace_open_exec(name->name);
58349 +
58350 err = deny_write_access(file);
58351 if (err)
58352 goto exit;
58353 @@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
58354 old_fs = get_fs();
58355 set_fs(get_ds());
58356 /* The cast to a user pointer is valid due to the set_fs() */
58357 - result = vfs_read(file, (void __user *)addr, count, &pos);
58358 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
58359 set_fs(old_fs);
58360 return result;
58361 }
58362 @@ -1258,7 +1336,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
58363 }
58364 rcu_read_unlock();
58365
58366 - if (p->fs->users > n_fs)
58367 + if (atomic_read(&p->fs->users) > n_fs)
58368 bprm->unsafe |= LSM_UNSAFE_SHARE;
58369 else
58370 p->fs->in_exec = 1;
58371 @@ -1434,6 +1512,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58372 return ret;
58373 }
58374
58375 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58376 +static DEFINE_PER_CPU(u64, exec_counter);
58377 +static int __init init_exec_counters(void)
58378 +{
58379 + unsigned int cpu;
58380 +
58381 + for_each_possible_cpu(cpu) {
58382 + per_cpu(exec_counter, cpu) = (u64)cpu;
58383 + }
58384 +
58385 + return 0;
58386 +}
58387 +early_initcall(init_exec_counters);
58388 +static inline void increment_exec_counter(void)
58389 +{
58390 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
58391 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58392 +}
58393 +#else
58394 +static inline void increment_exec_counter(void) {}
58395 +#endif
58396 +
58397 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
58398 + struct user_arg_ptr argv);
58399 +
58400 /*
58401 * sys_execve() executes a new program.
58402 */
58403 @@ -1441,6 +1544,11 @@ static int do_execve_common(struct filename *filename,
58404 struct user_arg_ptr argv,
58405 struct user_arg_ptr envp)
58406 {
58407 +#ifdef CONFIG_GRKERNSEC
58408 + struct file *old_exec_file;
58409 + struct acl_subject_label *old_acl;
58410 + struct rlimit old_rlim[RLIM_NLIMITS];
58411 +#endif
58412 struct linux_binprm *bprm;
58413 struct file *file;
58414 struct files_struct *displaced;
58415 @@ -1449,6 +1557,8 @@ static int do_execve_common(struct filename *filename,
58416 if (IS_ERR(filename))
58417 return PTR_ERR(filename);
58418
58419 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58420 +
58421 /*
58422 * We move the actual failure in case of RLIMIT_NPROC excess from
58423 * set*uid() to execve() because too many poorly written programs
58424 @@ -1486,11 +1596,21 @@ static int do_execve_common(struct filename *filename,
58425 if (IS_ERR(file))
58426 goto out_unmark;
58427
58428 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
58429 + retval = -EPERM;
58430 + goto out_unmark;
58431 + }
58432 +
58433 sched_exec();
58434
58435 bprm->file = file;
58436 bprm->filename = bprm->interp = filename->name;
58437
58438 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58439 + retval = -EACCES;
58440 + goto out_unmark;
58441 + }
58442 +
58443 retval = bprm_mm_init(bprm);
58444 if (retval)
58445 goto out_unmark;
58446 @@ -1507,24 +1627,70 @@ static int do_execve_common(struct filename *filename,
58447 if (retval < 0)
58448 goto out;
58449
58450 +#ifdef CONFIG_GRKERNSEC
58451 + old_acl = current->acl;
58452 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58453 + old_exec_file = current->exec_file;
58454 + get_file(file);
58455 + current->exec_file = file;
58456 +#endif
58457 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58458 + /* limit suid stack to 8MB
58459 + * we saved the old limits above and will restore them if this exec fails
58460 + */
58461 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58462 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58463 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58464 +#endif
58465 +
58466 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58467 + retval = -EPERM;
58468 + goto out_fail;
58469 + }
58470 +
58471 + if (!gr_tpe_allow(file)) {
58472 + retval = -EACCES;
58473 + goto out_fail;
58474 + }
58475 +
58476 + if (gr_check_crash_exec(file)) {
58477 + retval = -EACCES;
58478 + goto out_fail;
58479 + }
58480 +
58481 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58482 + bprm->unsafe);
58483 + if (retval < 0)
58484 + goto out_fail;
58485 +
58486 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58487 if (retval < 0)
58488 - goto out;
58489 + goto out_fail;
58490
58491 bprm->exec = bprm->p;
58492 retval = copy_strings(bprm->envc, envp, bprm);
58493 if (retval < 0)
58494 - goto out;
58495 + goto out_fail;
58496
58497 retval = copy_strings(bprm->argc, argv, bprm);
58498 if (retval < 0)
58499 - goto out;
58500 + goto out_fail;
58501 +
58502 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58503 +
58504 + gr_handle_exec_args(bprm, argv);
58505
58506 retval = exec_binprm(bprm);
58507 if (retval < 0)
58508 - goto out;
58509 + goto out_fail;
58510 +#ifdef CONFIG_GRKERNSEC
58511 + if (old_exec_file)
58512 + fput(old_exec_file);
58513 +#endif
58514
58515 /* execve succeeded */
58516 +
58517 + increment_exec_counter();
58518 current->fs->in_exec = 0;
58519 current->in_execve = 0;
58520 acct_update_integrals(current);
58521 @@ -1535,6 +1701,14 @@ static int do_execve_common(struct filename *filename,
58522 put_files_struct(displaced);
58523 return retval;
58524
58525 +out_fail:
58526 +#ifdef CONFIG_GRKERNSEC
58527 + current->acl = old_acl;
58528 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58529 + fput(current->exec_file);
58530 + current->exec_file = old_exec_file;
58531 +#endif
58532 +
58533 out:
58534 if (bprm->mm) {
58535 acct_arg_size(bprm, 0);
58536 @@ -1626,3 +1800,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58537 return compat_do_execve(getname(filename), argv, envp);
58538 }
58539 #endif
58540 +
58541 +int pax_check_flags(unsigned long *flags)
58542 +{
58543 + int retval = 0;
58544 +
58545 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58546 + if (*flags & MF_PAX_SEGMEXEC)
58547 + {
58548 + *flags &= ~MF_PAX_SEGMEXEC;
58549 + retval = -EINVAL;
58550 + }
58551 +#endif
58552 +
58553 + if ((*flags & MF_PAX_PAGEEXEC)
58554 +
58555 +#ifdef CONFIG_PAX_PAGEEXEC
58556 + && (*flags & MF_PAX_SEGMEXEC)
58557 +#endif
58558 +
58559 + )
58560 + {
58561 + *flags &= ~MF_PAX_PAGEEXEC;
58562 + retval = -EINVAL;
58563 + }
58564 +
58565 + if ((*flags & MF_PAX_MPROTECT)
58566 +
58567 +#ifdef CONFIG_PAX_MPROTECT
58568 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58569 +#endif
58570 +
58571 + )
58572 + {
58573 + *flags &= ~MF_PAX_MPROTECT;
58574 + retval = -EINVAL;
58575 + }
58576 +
58577 + if ((*flags & MF_PAX_EMUTRAMP)
58578 +
58579 +#ifdef CONFIG_PAX_EMUTRAMP
58580 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58581 +#endif
58582 +
58583 + )
58584 + {
58585 + *flags &= ~MF_PAX_EMUTRAMP;
58586 + retval = -EINVAL;
58587 + }
58588 +
58589 + return retval;
58590 +}
58591 +
58592 +EXPORT_SYMBOL(pax_check_flags);
58593 +
58594 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58595 +char *pax_get_path(const struct path *path, char *buf, int buflen)
58596 +{
58597 + char *pathname = d_path(path, buf, buflen);
58598 +
58599 + if (IS_ERR(pathname))
58600 + goto toolong;
58601 +
58602 + pathname = mangle_path(buf, pathname, "\t\n\\");
58603 + if (!pathname)
58604 + goto toolong;
58605 +
58606 + *pathname = 0;
58607 + return buf;
58608 +
58609 +toolong:
58610 + return "<path too long>";
58611 +}
58612 +EXPORT_SYMBOL(pax_get_path);
58613 +
58614 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58615 +{
58616 + struct task_struct *tsk = current;
58617 + struct mm_struct *mm = current->mm;
58618 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58619 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58620 + char *path_exec = NULL;
58621 + char *path_fault = NULL;
58622 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
58623 + siginfo_t info = { };
58624 +
58625 + if (buffer_exec && buffer_fault) {
58626 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58627 +
58628 + down_read(&mm->mmap_sem);
58629 + vma = mm->mmap;
58630 + while (vma && (!vma_exec || !vma_fault)) {
58631 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58632 + vma_exec = vma;
58633 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58634 + vma_fault = vma;
58635 + vma = vma->vm_next;
58636 + }
58637 + if (vma_exec)
58638 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58639 + if (vma_fault) {
58640 + start = vma_fault->vm_start;
58641 + end = vma_fault->vm_end;
58642 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58643 + if (vma_fault->vm_file)
58644 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58645 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58646 + path_fault = "<heap>";
58647 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58648 + path_fault = "<stack>";
58649 + else
58650 + path_fault = "<anonymous mapping>";
58651 + }
58652 + up_read(&mm->mmap_sem);
58653 + }
58654 + if (tsk->signal->curr_ip)
58655 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58656 + else
58657 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58658 + 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),
58659 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58660 + free_page((unsigned long)buffer_exec);
58661 + free_page((unsigned long)buffer_fault);
58662 + pax_report_insns(regs, pc, sp);
58663 + info.si_signo = SIGKILL;
58664 + info.si_errno = 0;
58665 + info.si_code = SI_KERNEL;
58666 + info.si_pid = 0;
58667 + info.si_uid = 0;
58668 + do_coredump(&info);
58669 +}
58670 +#endif
58671 +
58672 +#ifdef CONFIG_PAX_REFCOUNT
58673 +void pax_report_refcount_overflow(struct pt_regs *regs)
58674 +{
58675 + if (current->signal->curr_ip)
58676 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58677 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
58678 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58679 + else
58680 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58681 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58682 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58683 + preempt_disable();
58684 + show_regs(regs);
58685 + preempt_enable();
58686 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58687 +}
58688 +#endif
58689 +
58690 +#ifdef CONFIG_PAX_USERCOPY
58691 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58692 +static noinline int check_stack_object(const void *obj, unsigned long len)
58693 +{
58694 + const void * const stack = task_stack_page(current);
58695 + const void * const stackend = stack + THREAD_SIZE;
58696 +
58697 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58698 + const void *frame = NULL;
58699 + const void *oldframe;
58700 +#endif
58701 +
58702 + if (obj + len < obj)
58703 + return -1;
58704 +
58705 + if (obj + len <= stack || stackend <= obj)
58706 + return 0;
58707 +
58708 + if (obj < stack || stackend < obj + len)
58709 + return -1;
58710 +
58711 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58712 + oldframe = __builtin_frame_address(1);
58713 + if (oldframe)
58714 + frame = __builtin_frame_address(2);
58715 + /*
58716 + low ----------------------------------------------> high
58717 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
58718 + ^----------------^
58719 + allow copies only within here
58720 + */
58721 + while (stack <= frame && frame < stackend) {
58722 + /* if obj + len extends past the last frame, this
58723 + check won't pass and the next frame will be 0,
58724 + causing us to bail out and correctly report
58725 + the copy as invalid
58726 + */
58727 + if (obj + len <= frame)
58728 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58729 + oldframe = frame;
58730 + frame = *(const void * const *)frame;
58731 + }
58732 + return -1;
58733 +#else
58734 + return 1;
58735 +#endif
58736 +}
58737 +
58738 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58739 +{
58740 + if (current->signal->curr_ip)
58741 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58742 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58743 + else
58744 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58745 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58746 + dump_stack();
58747 + gr_handle_kernel_exploit();
58748 + do_group_exit(SIGKILL);
58749 +}
58750 +#endif
58751 +
58752 +#ifdef CONFIG_PAX_USERCOPY
58753 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
58754 +{
58755 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
58756 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
58757 +#ifdef CONFIG_MODULES
58758 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
58759 +#else
58760 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
58761 +#endif
58762 +
58763 +#else
58764 + unsigned long textlow = (unsigned long)_stext;
58765 + unsigned long texthigh = (unsigned long)_etext;
58766 +
58767 +#ifdef CONFIG_X86_64
58768 + /* check against linear mapping as well */
58769 + if (high > (unsigned long)__va(__pa(textlow)) &&
58770 + low < (unsigned long)__va(__pa(texthigh)))
58771 + return true;
58772 +#endif
58773 +
58774 +#endif
58775 +
58776 + if (high <= textlow || low >= texthigh)
58777 + return false;
58778 + else
58779 + return true;
58780 +}
58781 +#endif
58782 +
58783 +void __check_object_size(const void *ptr, unsigned long n, bool to_user)
58784 +{
58785 +
58786 +#ifdef CONFIG_PAX_USERCOPY
58787 + const char *type;
58788 +
58789 + if (!n)
58790 + return;
58791 +
58792 + type = check_heap_object(ptr, n);
58793 + if (!type) {
58794 + int ret = check_stack_object(ptr, n);
58795 + if (ret == 1 || ret == 2)
58796 + return;
58797 + if (ret == 0) {
58798 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
58799 + type = "<kernel text>";
58800 + else
58801 + return;
58802 + } else
58803 + type = "<process stack>";
58804 + }
58805 +
58806 + pax_report_usercopy(ptr, n, to_user, type);
58807 +#endif
58808 +
58809 +}
58810 +EXPORT_SYMBOL(__check_object_size);
58811 +
58812 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
58813 +void pax_track_stack(void)
58814 +{
58815 + unsigned long sp = (unsigned long)&sp;
58816 + if (sp < current_thread_info()->lowest_stack &&
58817 + sp > (unsigned long)task_stack_page(current))
58818 + current_thread_info()->lowest_stack = sp;
58819 +}
58820 +EXPORT_SYMBOL(pax_track_stack);
58821 +#endif
58822 +
58823 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
58824 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
58825 +{
58826 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
58827 + dump_stack();
58828 + do_group_exit(SIGKILL);
58829 +}
58830 +EXPORT_SYMBOL(report_size_overflow);
58831 +#endif
58832 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
58833 index 9f9992b..8b59411 100644
58834 --- a/fs/ext2/balloc.c
58835 +++ b/fs/ext2/balloc.c
58836 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
58837
58838 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58839 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58840 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58841 + if (free_blocks < root_blocks + 1 &&
58842 !uid_eq(sbi->s_resuid, current_fsuid()) &&
58843 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58844 - !in_group_p (sbi->s_resgid))) {
58845 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58846 return 0;
58847 }
58848 return 1;
58849 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
58850 index 9142614..97484fa 100644
58851 --- a/fs/ext2/xattr.c
58852 +++ b/fs/ext2/xattr.c
58853 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
58854 struct buffer_head *bh = NULL;
58855 struct ext2_xattr_entry *entry;
58856 char *end;
58857 - size_t rest = buffer_size;
58858 + size_t rest = buffer_size, total_size = 0;
58859 int error;
58860
58861 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
58862 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
58863 buffer += size;
58864 }
58865 rest -= size;
58866 + total_size += size;
58867 }
58868 }
58869 - error = buffer_size - rest; /* total size */
58870 + error = total_size;
58871
58872 cleanup:
58873 brelse(bh);
58874 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
58875 index 22548f5..41521d8 100644
58876 --- a/fs/ext3/balloc.c
58877 +++ b/fs/ext3/balloc.c
58878 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
58879
58880 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58881 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58882 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58883 + if (free_blocks < root_blocks + 1 &&
58884 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
58885 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58886 - !in_group_p (sbi->s_resgid))) {
58887 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58888 return 0;
58889 }
58890 return 1;
58891 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
58892 index c6874be..f8a6ae8 100644
58893 --- a/fs/ext3/xattr.c
58894 +++ b/fs/ext3/xattr.c
58895 @@ -330,7 +330,7 @@ static int
58896 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58897 char *buffer, size_t buffer_size)
58898 {
58899 - size_t rest = buffer_size;
58900 + size_t rest = buffer_size, total_size = 0;
58901
58902 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
58903 const struct xattr_handler *handler =
58904 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58905 buffer += size;
58906 }
58907 rest -= size;
58908 + total_size += size;
58909 }
58910 }
58911 - return buffer_size - rest;
58912 + return total_size;
58913 }
58914
58915 static int
58916 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
58917 index 6ea7b14..8fa16d9 100644
58918 --- a/fs/ext4/balloc.c
58919 +++ b/fs/ext4/balloc.c
58920 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
58921 /* Hm, nope. Are (enough) root reserved clusters available? */
58922 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
58923 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
58924 - capable(CAP_SYS_RESOURCE) ||
58925 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
58926 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
58927 + capable_nolog(CAP_SYS_RESOURCE)) {
58928
58929 if (free_clusters >= (nclusters + dirty_clusters +
58930 resv_clusters))
58931 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
58932 index d3a534f..242c50a 100644
58933 --- a/fs/ext4/ext4.h
58934 +++ b/fs/ext4/ext4.h
58935 @@ -1269,19 +1269,19 @@ struct ext4_sb_info {
58936 unsigned long s_mb_last_start;
58937
58938 /* stats for buddy allocator */
58939 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
58940 - atomic_t s_bal_success; /* we found long enough chunks */
58941 - atomic_t s_bal_allocated; /* in blocks */
58942 - atomic_t s_bal_ex_scanned; /* total extents scanned */
58943 - atomic_t s_bal_goals; /* goal hits */
58944 - atomic_t s_bal_breaks; /* too long searches */
58945 - atomic_t s_bal_2orders; /* 2^order hits */
58946 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
58947 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
58948 + atomic_unchecked_t s_bal_allocated; /* in blocks */
58949 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
58950 + atomic_unchecked_t s_bal_goals; /* goal hits */
58951 + atomic_unchecked_t s_bal_breaks; /* too long searches */
58952 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
58953 spinlock_t s_bal_lock;
58954 unsigned long s_mb_buddies_generated;
58955 unsigned long long s_mb_generation_time;
58956 - atomic_t s_mb_lost_chunks;
58957 - atomic_t s_mb_preallocated;
58958 - atomic_t s_mb_discarded;
58959 + atomic_unchecked_t s_mb_lost_chunks;
58960 + atomic_unchecked_t s_mb_preallocated;
58961 + atomic_unchecked_t s_mb_discarded;
58962 atomic_t s_lock_busy;
58963
58964 /* locality groups */
58965 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
58966 index 04a5c75..09894fa 100644
58967 --- a/fs/ext4/mballoc.c
58968 +++ b/fs/ext4/mballoc.c
58969 @@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
58970 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
58971
58972 if (EXT4_SB(sb)->s_mb_stats)
58973 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
58974 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
58975
58976 break;
58977 }
58978 @@ -2189,7 +2189,7 @@ repeat:
58979 ac->ac_status = AC_STATUS_CONTINUE;
58980 ac->ac_flags |= EXT4_MB_HINT_FIRST;
58981 cr = 3;
58982 - atomic_inc(&sbi->s_mb_lost_chunks);
58983 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
58984 goto repeat;
58985 }
58986 }
58987 @@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
58988 if (sbi->s_mb_stats) {
58989 ext4_msg(sb, KERN_INFO,
58990 "mballoc: %u blocks %u reqs (%u success)",
58991 - atomic_read(&sbi->s_bal_allocated),
58992 - atomic_read(&sbi->s_bal_reqs),
58993 - atomic_read(&sbi->s_bal_success));
58994 + atomic_read_unchecked(&sbi->s_bal_allocated),
58995 + atomic_read_unchecked(&sbi->s_bal_reqs),
58996 + atomic_read_unchecked(&sbi->s_bal_success));
58997 ext4_msg(sb, KERN_INFO,
58998 "mballoc: %u extents scanned, %u goal hits, "
58999 "%u 2^N hits, %u breaks, %u lost",
59000 - atomic_read(&sbi->s_bal_ex_scanned),
59001 - atomic_read(&sbi->s_bal_goals),
59002 - atomic_read(&sbi->s_bal_2orders),
59003 - atomic_read(&sbi->s_bal_breaks),
59004 - atomic_read(&sbi->s_mb_lost_chunks));
59005 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59006 + atomic_read_unchecked(&sbi->s_bal_goals),
59007 + atomic_read_unchecked(&sbi->s_bal_2orders),
59008 + atomic_read_unchecked(&sbi->s_bal_breaks),
59009 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59010 ext4_msg(sb, KERN_INFO,
59011 "mballoc: %lu generated and it took %Lu",
59012 sbi->s_mb_buddies_generated,
59013 sbi->s_mb_generation_time);
59014 ext4_msg(sb, KERN_INFO,
59015 "mballoc: %u preallocated, %u discarded",
59016 - atomic_read(&sbi->s_mb_preallocated),
59017 - atomic_read(&sbi->s_mb_discarded));
59018 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59019 + atomic_read_unchecked(&sbi->s_mb_discarded));
59020 }
59021
59022 free_percpu(sbi->s_locality_groups);
59023 @@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59024 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59025
59026 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59027 - atomic_inc(&sbi->s_bal_reqs);
59028 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59029 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59030 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59031 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59032 - atomic_inc(&sbi->s_bal_success);
59033 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59034 + atomic_inc_unchecked(&sbi->s_bal_success);
59035 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59036 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59037 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59038 - atomic_inc(&sbi->s_bal_goals);
59039 + atomic_inc_unchecked(&sbi->s_bal_goals);
59040 if (ac->ac_found > sbi->s_mb_max_to_scan)
59041 - atomic_inc(&sbi->s_bal_breaks);
59042 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59043 }
59044
59045 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59046 @@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59047 trace_ext4_mb_new_inode_pa(ac, pa);
59048
59049 ext4_mb_use_inode_pa(ac, pa);
59050 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59051 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59052
59053 ei = EXT4_I(ac->ac_inode);
59054 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59055 @@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59056 trace_ext4_mb_new_group_pa(ac, pa);
59057
59058 ext4_mb_use_group_pa(ac, pa);
59059 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59060 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59061
59062 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59063 lg = ac->ac_lg;
59064 @@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59065 * from the bitmap and continue.
59066 */
59067 }
59068 - atomic_add(free, &sbi->s_mb_discarded);
59069 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59070
59071 return err;
59072 }
59073 @@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59074 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59075 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59076 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59077 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59078 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59079 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59080
59081 return 0;
59082 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59083 index 04434ad..6404663 100644
59084 --- a/fs/ext4/mmp.c
59085 +++ b/fs/ext4/mmp.c
59086 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59087 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59088 const char *function, unsigned int line, const char *msg)
59089 {
59090 - __ext4_warning(sb, function, line, msg);
59091 + __ext4_warning(sb, function, line, "%s", msg);
59092 __ext4_warning(sb, function, line,
59093 "MMP failure info: last update time: %llu, last update "
59094 "node: %s, last update device: %s\n",
59095 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59096 index 710fed2..a82e4e8 100644
59097 --- a/fs/ext4/super.c
59098 +++ b/fs/ext4/super.c
59099 @@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59100 }
59101
59102 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59103 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59104 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59105 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59106
59107 #ifdef CONFIG_QUOTA
59108 @@ -2450,7 +2450,7 @@ struct ext4_attr {
59109 int offset;
59110 int deprecated_val;
59111 } u;
59112 -};
59113 +} __do_const;
59114
59115 static int parse_strtoull(const char *buf,
59116 unsigned long long max, unsigned long long *value)
59117 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59118 index e175e94..3ea69bf 100644
59119 --- a/fs/ext4/xattr.c
59120 +++ b/fs/ext4/xattr.c
59121 @@ -381,7 +381,7 @@ static int
59122 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59123 char *buffer, size_t buffer_size)
59124 {
59125 - size_t rest = buffer_size;
59126 + size_t rest = buffer_size, total_size = 0;
59127
59128 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59129 const struct xattr_handler *handler =
59130 @@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59131 buffer += size;
59132 }
59133 rest -= size;
59134 + total_size += size;
59135 }
59136 }
59137 - return buffer_size - rest;
59138 + return total_size;
59139 }
59140
59141 static int
59142 diff --git a/fs/fcntl.c b/fs/fcntl.c
59143 index ef68665..5deacdc 100644
59144 --- a/fs/fcntl.c
59145 +++ b/fs/fcntl.c
59146 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59147 if (err)
59148 return err;
59149
59150 + if (gr_handle_chroot_fowner(pid, type))
59151 + return -ENOENT;
59152 + if (gr_check_protected_task_fowner(pid, type))
59153 + return -EACCES;
59154 +
59155 f_modown(filp, pid, type, force);
59156 return 0;
59157 }
59158 diff --git a/fs/fhandle.c b/fs/fhandle.c
59159 index 999ff5c..41f4109 100644
59160 --- a/fs/fhandle.c
59161 +++ b/fs/fhandle.c
59162 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59163 } else
59164 retval = 0;
59165 /* copy the mount id */
59166 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59167 - sizeof(*mnt_id)) ||
59168 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59169 copy_to_user(ufh, handle,
59170 sizeof(struct file_handle) + handle_bytes))
59171 retval = -EFAULT;
59172 diff --git a/fs/file.c b/fs/file.c
59173 index eb56a13..ccee850 100644
59174 --- a/fs/file.c
59175 +++ b/fs/file.c
59176 @@ -16,6 +16,7 @@
59177 #include <linux/slab.h>
59178 #include <linux/vmalloc.h>
59179 #include <linux/file.h>
59180 +#include <linux/security.h>
59181 #include <linux/fdtable.h>
59182 #include <linux/bitops.h>
59183 #include <linux/interrupt.h>
59184 @@ -141,7 +142,7 @@ out:
59185 * Return <0 error code on error; 1 on successful completion.
59186 * The files->file_lock should be held on entry, and will be held on exit.
59187 */
59188 -static int expand_fdtable(struct files_struct *files, int nr)
59189 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
59190 __releases(files->file_lock)
59191 __acquires(files->file_lock)
59192 {
59193 @@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59194 * expanded and execution may have blocked.
59195 * The files->file_lock should be held on entry, and will be held on exit.
59196 */
59197 -static int expand_files(struct files_struct *files, int nr)
59198 +static int expand_files(struct files_struct *files, unsigned int nr)
59199 {
59200 struct fdtable *fdt;
59201
59202 @@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59203 if (!file)
59204 return __close_fd(files, fd);
59205
59206 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59207 if (fd >= rlimit(RLIMIT_NOFILE))
59208 return -EBADF;
59209
59210 @@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59211 if (unlikely(oldfd == newfd))
59212 return -EINVAL;
59213
59214 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59215 if (newfd >= rlimit(RLIMIT_NOFILE))
59216 return -EBADF;
59217
59218 @@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59219 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59220 {
59221 int err;
59222 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59223 if (from >= rlimit(RLIMIT_NOFILE))
59224 return -EINVAL;
59225 err = alloc_fd(from, flags);
59226 diff --git a/fs/filesystems.c b/fs/filesystems.c
59227 index 92567d9..fcd8cbf 100644
59228 --- a/fs/filesystems.c
59229 +++ b/fs/filesystems.c
59230 @@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59231 int len = dot ? dot - name : strlen(name);
59232
59233 fs = __get_fs_type(name, len);
59234 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
59235 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59236 +#else
59237 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59238 +#endif
59239 fs = __get_fs_type(name, len);
59240
59241 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59242 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59243 index 7dca743..543d620 100644
59244 --- a/fs/fs_struct.c
59245 +++ b/fs/fs_struct.c
59246 @@ -4,6 +4,7 @@
59247 #include <linux/path.h>
59248 #include <linux/slab.h>
59249 #include <linux/fs_struct.h>
59250 +#include <linux/grsecurity.h>
59251 #include "internal.h"
59252
59253 /*
59254 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59255 write_seqcount_begin(&fs->seq);
59256 old_root = fs->root;
59257 fs->root = *path;
59258 + gr_set_chroot_entries(current, path);
59259 write_seqcount_end(&fs->seq);
59260 spin_unlock(&fs->lock);
59261 if (old_root.dentry)
59262 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59263 int hits = 0;
59264 spin_lock(&fs->lock);
59265 write_seqcount_begin(&fs->seq);
59266 + /* this root replacement is only done by pivot_root,
59267 + leave grsec's chroot tagging alone for this task
59268 + so that a pivoted root isn't treated as a chroot
59269 + */
59270 hits += replace_path(&fs->root, old_root, new_root);
59271 hits += replace_path(&fs->pwd, old_root, new_root);
59272 write_seqcount_end(&fs->seq);
59273 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59274 task_lock(tsk);
59275 spin_lock(&fs->lock);
59276 tsk->fs = NULL;
59277 - kill = !--fs->users;
59278 + gr_clear_chroot_entries(tsk);
59279 + kill = !atomic_dec_return(&fs->users);
59280 spin_unlock(&fs->lock);
59281 task_unlock(tsk);
59282 if (kill)
59283 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59284 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59285 /* We don't need to lock fs - think why ;-) */
59286 if (fs) {
59287 - fs->users = 1;
59288 + atomic_set(&fs->users, 1);
59289 fs->in_exec = 0;
59290 spin_lock_init(&fs->lock);
59291 seqcount_init(&fs->seq);
59292 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59293 spin_lock(&old->lock);
59294 fs->root = old->root;
59295 path_get(&fs->root);
59296 + /* instead of calling gr_set_chroot_entries here,
59297 + we call it from every caller of this function
59298 + */
59299 fs->pwd = old->pwd;
59300 path_get(&fs->pwd);
59301 spin_unlock(&old->lock);
59302 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59303
59304 task_lock(current);
59305 spin_lock(&fs->lock);
59306 - kill = !--fs->users;
59307 + kill = !atomic_dec_return(&fs->users);
59308 current->fs = new_fs;
59309 + gr_set_chroot_entries(current, &new_fs->root);
59310 spin_unlock(&fs->lock);
59311 task_unlock(current);
59312
59313 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59314
59315 int current_umask(void)
59316 {
59317 - return current->fs->umask;
59318 + return current->fs->umask | gr_acl_umask();
59319 }
59320 EXPORT_SYMBOL(current_umask);
59321
59322 /* to be mentioned only in INIT_TASK */
59323 struct fs_struct init_fs = {
59324 - .users = 1,
59325 + .users = ATOMIC_INIT(1),
59326 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59327 .seq = SEQCNT_ZERO(init_fs.seq),
59328 .umask = 0022,
59329 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59330 index 29d7feb..303644d 100644
59331 --- a/fs/fscache/cookie.c
59332 +++ b/fs/fscache/cookie.c
59333 @@ -19,7 +19,7 @@
59334
59335 struct kmem_cache *fscache_cookie_jar;
59336
59337 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59338 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59339
59340 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59341 static int fscache_alloc_object(struct fscache_cache *cache,
59342 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59343 parent ? (char *) parent->def->name : "<no-parent>",
59344 def->name, netfs_data, enable);
59345
59346 - fscache_stat(&fscache_n_acquires);
59347 + fscache_stat_unchecked(&fscache_n_acquires);
59348
59349 /* if there's no parent cookie, then we don't create one here either */
59350 if (!parent) {
59351 - fscache_stat(&fscache_n_acquires_null);
59352 + fscache_stat_unchecked(&fscache_n_acquires_null);
59353 _leave(" [no parent]");
59354 return NULL;
59355 }
59356 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59357 /* allocate and initialise a cookie */
59358 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59359 if (!cookie) {
59360 - fscache_stat(&fscache_n_acquires_oom);
59361 + fscache_stat_unchecked(&fscache_n_acquires_oom);
59362 _leave(" [ENOMEM]");
59363 return NULL;
59364 }
59365 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59366
59367 switch (cookie->def->type) {
59368 case FSCACHE_COOKIE_TYPE_INDEX:
59369 - fscache_stat(&fscache_n_cookie_index);
59370 + fscache_stat_unchecked(&fscache_n_cookie_index);
59371 break;
59372 case FSCACHE_COOKIE_TYPE_DATAFILE:
59373 - fscache_stat(&fscache_n_cookie_data);
59374 + fscache_stat_unchecked(&fscache_n_cookie_data);
59375 break;
59376 default:
59377 - fscache_stat(&fscache_n_cookie_special);
59378 + fscache_stat_unchecked(&fscache_n_cookie_special);
59379 break;
59380 }
59381
59382 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59383 } else {
59384 atomic_dec(&parent->n_children);
59385 __fscache_cookie_put(cookie);
59386 - fscache_stat(&fscache_n_acquires_nobufs);
59387 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59388 _leave(" = NULL");
59389 return NULL;
59390 }
59391 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59392 }
59393 }
59394
59395 - fscache_stat(&fscache_n_acquires_ok);
59396 + fscache_stat_unchecked(&fscache_n_acquires_ok);
59397 _leave(" = %p", cookie);
59398 return cookie;
59399 }
59400 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59401 cache = fscache_select_cache_for_object(cookie->parent);
59402 if (!cache) {
59403 up_read(&fscache_addremove_sem);
59404 - fscache_stat(&fscache_n_acquires_no_cache);
59405 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59406 _leave(" = -ENOMEDIUM [no cache]");
59407 return -ENOMEDIUM;
59408 }
59409 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59410 object = cache->ops->alloc_object(cache, cookie);
59411 fscache_stat_d(&fscache_n_cop_alloc_object);
59412 if (IS_ERR(object)) {
59413 - fscache_stat(&fscache_n_object_no_alloc);
59414 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
59415 ret = PTR_ERR(object);
59416 goto error;
59417 }
59418
59419 - fscache_stat(&fscache_n_object_alloc);
59420 + fscache_stat_unchecked(&fscache_n_object_alloc);
59421
59422 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59423 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59424
59425 _debug("ALLOC OBJ%x: %s {%lx}",
59426 object->debug_id, cookie->def->name, object->events);
59427 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59428
59429 _enter("{%s}", cookie->def->name);
59430
59431 - fscache_stat(&fscache_n_invalidates);
59432 + fscache_stat_unchecked(&fscache_n_invalidates);
59433
59434 /* Only permit invalidation of data files. Invalidating an index will
59435 * require the caller to release all its attachments to the tree rooted
59436 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59437 {
59438 struct fscache_object *object;
59439
59440 - fscache_stat(&fscache_n_updates);
59441 + fscache_stat_unchecked(&fscache_n_updates);
59442
59443 if (!cookie) {
59444 - fscache_stat(&fscache_n_updates_null);
59445 + fscache_stat_unchecked(&fscache_n_updates_null);
59446 _leave(" [no cookie]");
59447 return;
59448 }
59449 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59450 */
59451 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59452 {
59453 - fscache_stat(&fscache_n_relinquishes);
59454 + fscache_stat_unchecked(&fscache_n_relinquishes);
59455 if (retire)
59456 - fscache_stat(&fscache_n_relinquishes_retire);
59457 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59458
59459 if (!cookie) {
59460 - fscache_stat(&fscache_n_relinquishes_null);
59461 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
59462 _leave(" [no cookie]");
59463 return;
59464 }
59465 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59466 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59467 goto inconsistent;
59468
59469 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59470 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59471
59472 __fscache_use_cookie(cookie);
59473 if (fscache_submit_op(object, op) < 0)
59474 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59475 index 4226f66..0fb3f45 100644
59476 --- a/fs/fscache/internal.h
59477 +++ b/fs/fscache/internal.h
59478 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59479 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59480 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59481 struct fscache_operation *,
59482 - atomic_t *,
59483 - atomic_t *,
59484 + atomic_unchecked_t *,
59485 + atomic_unchecked_t *,
59486 void (*)(struct fscache_operation *));
59487 extern void fscache_invalidate_writes(struct fscache_cookie *);
59488
59489 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59490 * stats.c
59491 */
59492 #ifdef CONFIG_FSCACHE_STATS
59493 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59494 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59495 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59496 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59497
59498 -extern atomic_t fscache_n_op_pend;
59499 -extern atomic_t fscache_n_op_run;
59500 -extern atomic_t fscache_n_op_enqueue;
59501 -extern atomic_t fscache_n_op_deferred_release;
59502 -extern atomic_t fscache_n_op_release;
59503 -extern atomic_t fscache_n_op_gc;
59504 -extern atomic_t fscache_n_op_cancelled;
59505 -extern atomic_t fscache_n_op_rejected;
59506 +extern atomic_unchecked_t fscache_n_op_pend;
59507 +extern atomic_unchecked_t fscache_n_op_run;
59508 +extern atomic_unchecked_t fscache_n_op_enqueue;
59509 +extern atomic_unchecked_t fscache_n_op_deferred_release;
59510 +extern atomic_unchecked_t fscache_n_op_release;
59511 +extern atomic_unchecked_t fscache_n_op_gc;
59512 +extern atomic_unchecked_t fscache_n_op_cancelled;
59513 +extern atomic_unchecked_t fscache_n_op_rejected;
59514
59515 -extern atomic_t fscache_n_attr_changed;
59516 -extern atomic_t fscache_n_attr_changed_ok;
59517 -extern atomic_t fscache_n_attr_changed_nobufs;
59518 -extern atomic_t fscache_n_attr_changed_nomem;
59519 -extern atomic_t fscache_n_attr_changed_calls;
59520 +extern atomic_unchecked_t fscache_n_attr_changed;
59521 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
59522 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59523 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59524 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
59525
59526 -extern atomic_t fscache_n_allocs;
59527 -extern atomic_t fscache_n_allocs_ok;
59528 -extern atomic_t fscache_n_allocs_wait;
59529 -extern atomic_t fscache_n_allocs_nobufs;
59530 -extern atomic_t fscache_n_allocs_intr;
59531 -extern atomic_t fscache_n_allocs_object_dead;
59532 -extern atomic_t fscache_n_alloc_ops;
59533 -extern atomic_t fscache_n_alloc_op_waits;
59534 +extern atomic_unchecked_t fscache_n_allocs;
59535 +extern atomic_unchecked_t fscache_n_allocs_ok;
59536 +extern atomic_unchecked_t fscache_n_allocs_wait;
59537 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
59538 +extern atomic_unchecked_t fscache_n_allocs_intr;
59539 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
59540 +extern atomic_unchecked_t fscache_n_alloc_ops;
59541 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
59542
59543 -extern atomic_t fscache_n_retrievals;
59544 -extern atomic_t fscache_n_retrievals_ok;
59545 -extern atomic_t fscache_n_retrievals_wait;
59546 -extern atomic_t fscache_n_retrievals_nodata;
59547 -extern atomic_t fscache_n_retrievals_nobufs;
59548 -extern atomic_t fscache_n_retrievals_intr;
59549 -extern atomic_t fscache_n_retrievals_nomem;
59550 -extern atomic_t fscache_n_retrievals_object_dead;
59551 -extern atomic_t fscache_n_retrieval_ops;
59552 -extern atomic_t fscache_n_retrieval_op_waits;
59553 +extern atomic_unchecked_t fscache_n_retrievals;
59554 +extern atomic_unchecked_t fscache_n_retrievals_ok;
59555 +extern atomic_unchecked_t fscache_n_retrievals_wait;
59556 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
59557 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59558 +extern atomic_unchecked_t fscache_n_retrievals_intr;
59559 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
59560 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59561 +extern atomic_unchecked_t fscache_n_retrieval_ops;
59562 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59563
59564 -extern atomic_t fscache_n_stores;
59565 -extern atomic_t fscache_n_stores_ok;
59566 -extern atomic_t fscache_n_stores_again;
59567 -extern atomic_t fscache_n_stores_nobufs;
59568 -extern atomic_t fscache_n_stores_oom;
59569 -extern atomic_t fscache_n_store_ops;
59570 -extern atomic_t fscache_n_store_calls;
59571 -extern atomic_t fscache_n_store_pages;
59572 -extern atomic_t fscache_n_store_radix_deletes;
59573 -extern atomic_t fscache_n_store_pages_over_limit;
59574 +extern atomic_unchecked_t fscache_n_stores;
59575 +extern atomic_unchecked_t fscache_n_stores_ok;
59576 +extern atomic_unchecked_t fscache_n_stores_again;
59577 +extern atomic_unchecked_t fscache_n_stores_nobufs;
59578 +extern atomic_unchecked_t fscache_n_stores_oom;
59579 +extern atomic_unchecked_t fscache_n_store_ops;
59580 +extern atomic_unchecked_t fscache_n_store_calls;
59581 +extern atomic_unchecked_t fscache_n_store_pages;
59582 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
59583 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59584
59585 -extern atomic_t fscache_n_store_vmscan_not_storing;
59586 -extern atomic_t fscache_n_store_vmscan_gone;
59587 -extern atomic_t fscache_n_store_vmscan_busy;
59588 -extern atomic_t fscache_n_store_vmscan_cancelled;
59589 -extern atomic_t fscache_n_store_vmscan_wait;
59590 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59591 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59592 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59593 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59594 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59595
59596 -extern atomic_t fscache_n_marks;
59597 -extern atomic_t fscache_n_uncaches;
59598 +extern atomic_unchecked_t fscache_n_marks;
59599 +extern atomic_unchecked_t fscache_n_uncaches;
59600
59601 -extern atomic_t fscache_n_acquires;
59602 -extern atomic_t fscache_n_acquires_null;
59603 -extern atomic_t fscache_n_acquires_no_cache;
59604 -extern atomic_t fscache_n_acquires_ok;
59605 -extern atomic_t fscache_n_acquires_nobufs;
59606 -extern atomic_t fscache_n_acquires_oom;
59607 +extern atomic_unchecked_t fscache_n_acquires;
59608 +extern atomic_unchecked_t fscache_n_acquires_null;
59609 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
59610 +extern atomic_unchecked_t fscache_n_acquires_ok;
59611 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
59612 +extern atomic_unchecked_t fscache_n_acquires_oom;
59613
59614 -extern atomic_t fscache_n_invalidates;
59615 -extern atomic_t fscache_n_invalidates_run;
59616 +extern atomic_unchecked_t fscache_n_invalidates;
59617 +extern atomic_unchecked_t fscache_n_invalidates_run;
59618
59619 -extern atomic_t fscache_n_updates;
59620 -extern atomic_t fscache_n_updates_null;
59621 -extern atomic_t fscache_n_updates_run;
59622 +extern atomic_unchecked_t fscache_n_updates;
59623 +extern atomic_unchecked_t fscache_n_updates_null;
59624 +extern atomic_unchecked_t fscache_n_updates_run;
59625
59626 -extern atomic_t fscache_n_relinquishes;
59627 -extern atomic_t fscache_n_relinquishes_null;
59628 -extern atomic_t fscache_n_relinquishes_waitcrt;
59629 -extern atomic_t fscache_n_relinquishes_retire;
59630 +extern atomic_unchecked_t fscache_n_relinquishes;
59631 +extern atomic_unchecked_t fscache_n_relinquishes_null;
59632 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59633 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
59634
59635 -extern atomic_t fscache_n_cookie_index;
59636 -extern atomic_t fscache_n_cookie_data;
59637 -extern atomic_t fscache_n_cookie_special;
59638 +extern atomic_unchecked_t fscache_n_cookie_index;
59639 +extern atomic_unchecked_t fscache_n_cookie_data;
59640 +extern atomic_unchecked_t fscache_n_cookie_special;
59641
59642 -extern atomic_t fscache_n_object_alloc;
59643 -extern atomic_t fscache_n_object_no_alloc;
59644 -extern atomic_t fscache_n_object_lookups;
59645 -extern atomic_t fscache_n_object_lookups_negative;
59646 -extern atomic_t fscache_n_object_lookups_positive;
59647 -extern atomic_t fscache_n_object_lookups_timed_out;
59648 -extern atomic_t fscache_n_object_created;
59649 -extern atomic_t fscache_n_object_avail;
59650 -extern atomic_t fscache_n_object_dead;
59651 +extern atomic_unchecked_t fscache_n_object_alloc;
59652 +extern atomic_unchecked_t fscache_n_object_no_alloc;
59653 +extern atomic_unchecked_t fscache_n_object_lookups;
59654 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
59655 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
59656 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59657 +extern atomic_unchecked_t fscache_n_object_created;
59658 +extern atomic_unchecked_t fscache_n_object_avail;
59659 +extern atomic_unchecked_t fscache_n_object_dead;
59660
59661 -extern atomic_t fscache_n_checkaux_none;
59662 -extern atomic_t fscache_n_checkaux_okay;
59663 -extern atomic_t fscache_n_checkaux_update;
59664 -extern atomic_t fscache_n_checkaux_obsolete;
59665 +extern atomic_unchecked_t fscache_n_checkaux_none;
59666 +extern atomic_unchecked_t fscache_n_checkaux_okay;
59667 +extern atomic_unchecked_t fscache_n_checkaux_update;
59668 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59669
59670 extern atomic_t fscache_n_cop_alloc_object;
59671 extern atomic_t fscache_n_cop_lookup_object;
59672 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59673 atomic_inc(stat);
59674 }
59675
59676 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59677 +{
59678 + atomic_inc_unchecked(stat);
59679 +}
59680 +
59681 static inline void fscache_stat_d(atomic_t *stat)
59682 {
59683 atomic_dec(stat);
59684 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59685
59686 #define __fscache_stat(stat) (NULL)
59687 #define fscache_stat(stat) do {} while (0)
59688 +#define fscache_stat_unchecked(stat) do {} while (0)
59689 #define fscache_stat_d(stat) do {} while (0)
59690 #endif
59691
59692 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59693 index d3b4539..ed0c659 100644
59694 --- a/fs/fscache/object.c
59695 +++ b/fs/fscache/object.c
59696 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59697 _debug("LOOKUP \"%s\" in \"%s\"",
59698 cookie->def->name, object->cache->tag->name);
59699
59700 - fscache_stat(&fscache_n_object_lookups);
59701 + fscache_stat_unchecked(&fscache_n_object_lookups);
59702 fscache_stat(&fscache_n_cop_lookup_object);
59703 ret = object->cache->ops->lookup_object(object);
59704 fscache_stat_d(&fscache_n_cop_lookup_object);
59705 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59706 if (ret == -ETIMEDOUT) {
59707 /* probably stuck behind another object, so move this one to
59708 * the back of the queue */
59709 - fscache_stat(&fscache_n_object_lookups_timed_out);
59710 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59711 _leave(" [timeout]");
59712 return NO_TRANSIT;
59713 }
59714 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59715 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59716
59717 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59718 - fscache_stat(&fscache_n_object_lookups_negative);
59719 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59720
59721 /* Allow write requests to begin stacking up and read requests to begin
59722 * returning ENODATA.
59723 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
59724 /* if we were still looking up, then we must have a positive lookup
59725 * result, in which case there may be data available */
59726 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59727 - fscache_stat(&fscache_n_object_lookups_positive);
59728 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59729
59730 /* We do (presumably) have data */
59731 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59732 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
59733 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59734 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59735 } else {
59736 - fscache_stat(&fscache_n_object_created);
59737 + fscache_stat_unchecked(&fscache_n_object_created);
59738 }
59739
59740 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59741 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59742 fscache_stat_d(&fscache_n_cop_lookup_complete);
59743
59744 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59745 - fscache_stat(&fscache_n_object_avail);
59746 + fscache_stat_unchecked(&fscache_n_object_avail);
59747
59748 _leave("");
59749 return transit_to(JUMPSTART_DEPS);
59750 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
59751
59752 /* this just shifts the object release to the work processor */
59753 fscache_put_object(object);
59754 - fscache_stat(&fscache_n_object_dead);
59755 + fscache_stat_unchecked(&fscache_n_object_dead);
59756
59757 _leave("");
59758 return transit_to(OBJECT_DEAD);
59759 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59760 enum fscache_checkaux result;
59761
59762 if (!object->cookie->def->check_aux) {
59763 - fscache_stat(&fscache_n_checkaux_none);
59764 + fscache_stat_unchecked(&fscache_n_checkaux_none);
59765 return FSCACHE_CHECKAUX_OKAY;
59766 }
59767
59768 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59769 switch (result) {
59770 /* entry okay as is */
59771 case FSCACHE_CHECKAUX_OKAY:
59772 - fscache_stat(&fscache_n_checkaux_okay);
59773 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
59774 break;
59775
59776 /* entry requires update */
59777 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
59778 - fscache_stat(&fscache_n_checkaux_update);
59779 + fscache_stat_unchecked(&fscache_n_checkaux_update);
59780 break;
59781
59782 /* entry requires deletion */
59783 case FSCACHE_CHECKAUX_OBSOLETE:
59784 - fscache_stat(&fscache_n_checkaux_obsolete);
59785 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
59786 break;
59787
59788 default:
59789 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
59790 {
59791 const struct fscache_state *s;
59792
59793 - fscache_stat(&fscache_n_invalidates_run);
59794 + fscache_stat_unchecked(&fscache_n_invalidates_run);
59795 fscache_stat(&fscache_n_cop_invalidate_object);
59796 s = _fscache_invalidate_object(object, event);
59797 fscache_stat_d(&fscache_n_cop_invalidate_object);
59798 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
59799 {
59800 _enter("{OBJ%x},%d", object->debug_id, event);
59801
59802 - fscache_stat(&fscache_n_updates_run);
59803 + fscache_stat_unchecked(&fscache_n_updates_run);
59804 fscache_stat(&fscache_n_cop_update_object);
59805 object->cache->ops->update_object(object);
59806 fscache_stat_d(&fscache_n_cop_update_object);
59807 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
59808 index 318071a..379938b 100644
59809 --- a/fs/fscache/operation.c
59810 +++ b/fs/fscache/operation.c
59811 @@ -17,7 +17,7 @@
59812 #include <linux/slab.h>
59813 #include "internal.h"
59814
59815 -atomic_t fscache_op_debug_id;
59816 +atomic_unchecked_t fscache_op_debug_id;
59817 EXPORT_SYMBOL(fscache_op_debug_id);
59818
59819 /**
59820 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
59821 ASSERTCMP(atomic_read(&op->usage), >, 0);
59822 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
59823
59824 - fscache_stat(&fscache_n_op_enqueue);
59825 + fscache_stat_unchecked(&fscache_n_op_enqueue);
59826 switch (op->flags & FSCACHE_OP_TYPE) {
59827 case FSCACHE_OP_ASYNC:
59828 _debug("queue async");
59829 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
59830 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
59831 if (op->processor)
59832 fscache_enqueue_operation(op);
59833 - fscache_stat(&fscache_n_op_run);
59834 + fscache_stat_unchecked(&fscache_n_op_run);
59835 }
59836
59837 /*
59838 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59839 if (object->n_in_progress > 0) {
59840 atomic_inc(&op->usage);
59841 list_add_tail(&op->pend_link, &object->pending_ops);
59842 - fscache_stat(&fscache_n_op_pend);
59843 + fscache_stat_unchecked(&fscache_n_op_pend);
59844 } else if (!list_empty(&object->pending_ops)) {
59845 atomic_inc(&op->usage);
59846 list_add_tail(&op->pend_link, &object->pending_ops);
59847 - fscache_stat(&fscache_n_op_pend);
59848 + fscache_stat_unchecked(&fscache_n_op_pend);
59849 fscache_start_operations(object);
59850 } else {
59851 ASSERTCMP(object->n_in_progress, ==, 0);
59852 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59853 object->n_exclusive++; /* reads and writes must wait */
59854 atomic_inc(&op->usage);
59855 list_add_tail(&op->pend_link, &object->pending_ops);
59856 - fscache_stat(&fscache_n_op_pend);
59857 + fscache_stat_unchecked(&fscache_n_op_pend);
59858 ret = 0;
59859 } else {
59860 /* If we're in any other state, there must have been an I/O
59861 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
59862 if (object->n_exclusive > 0) {
59863 atomic_inc(&op->usage);
59864 list_add_tail(&op->pend_link, &object->pending_ops);
59865 - fscache_stat(&fscache_n_op_pend);
59866 + fscache_stat_unchecked(&fscache_n_op_pend);
59867 } else if (!list_empty(&object->pending_ops)) {
59868 atomic_inc(&op->usage);
59869 list_add_tail(&op->pend_link, &object->pending_ops);
59870 - fscache_stat(&fscache_n_op_pend);
59871 + fscache_stat_unchecked(&fscache_n_op_pend);
59872 fscache_start_operations(object);
59873 } else {
59874 ASSERTCMP(object->n_exclusive, ==, 0);
59875 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
59876 object->n_ops++;
59877 atomic_inc(&op->usage);
59878 list_add_tail(&op->pend_link, &object->pending_ops);
59879 - fscache_stat(&fscache_n_op_pend);
59880 + fscache_stat_unchecked(&fscache_n_op_pend);
59881 ret = 0;
59882 } else if (fscache_object_is_dying(object)) {
59883 - fscache_stat(&fscache_n_op_rejected);
59884 + fscache_stat_unchecked(&fscache_n_op_rejected);
59885 op->state = FSCACHE_OP_ST_CANCELLED;
59886 ret = -ENOBUFS;
59887 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
59888 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
59889 ret = -EBUSY;
59890 if (op->state == FSCACHE_OP_ST_PENDING) {
59891 ASSERT(!list_empty(&op->pend_link));
59892 - fscache_stat(&fscache_n_op_cancelled);
59893 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59894 list_del_init(&op->pend_link);
59895 if (do_cancel)
59896 do_cancel(op);
59897 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
59898 while (!list_empty(&object->pending_ops)) {
59899 op = list_entry(object->pending_ops.next,
59900 struct fscache_operation, pend_link);
59901 - fscache_stat(&fscache_n_op_cancelled);
59902 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59903 list_del_init(&op->pend_link);
59904
59905 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
59906 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
59907 op->state, ==, FSCACHE_OP_ST_CANCELLED);
59908 op->state = FSCACHE_OP_ST_DEAD;
59909
59910 - fscache_stat(&fscache_n_op_release);
59911 + fscache_stat_unchecked(&fscache_n_op_release);
59912
59913 if (op->release) {
59914 op->release(op);
59915 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
59916 * lock, and defer it otherwise */
59917 if (!spin_trylock(&object->lock)) {
59918 _debug("defer put");
59919 - fscache_stat(&fscache_n_op_deferred_release);
59920 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
59921
59922 cache = object->cache;
59923 spin_lock(&cache->op_gc_list_lock);
59924 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
59925
59926 _debug("GC DEFERRED REL OBJ%x OP%x",
59927 object->debug_id, op->debug_id);
59928 - fscache_stat(&fscache_n_op_gc);
59929 + fscache_stat_unchecked(&fscache_n_op_gc);
59930
59931 ASSERTCMP(atomic_read(&op->usage), ==, 0);
59932 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
59933 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
59934 index 7f5c658..6c1e164 100644
59935 --- a/fs/fscache/page.c
59936 +++ b/fs/fscache/page.c
59937 @@ -61,7 +61,7 @@ try_again:
59938 val = radix_tree_lookup(&cookie->stores, page->index);
59939 if (!val) {
59940 rcu_read_unlock();
59941 - fscache_stat(&fscache_n_store_vmscan_not_storing);
59942 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
59943 __fscache_uncache_page(cookie, page);
59944 return true;
59945 }
59946 @@ -91,11 +91,11 @@ try_again:
59947 spin_unlock(&cookie->stores_lock);
59948
59949 if (xpage) {
59950 - fscache_stat(&fscache_n_store_vmscan_cancelled);
59951 - fscache_stat(&fscache_n_store_radix_deletes);
59952 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
59953 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59954 ASSERTCMP(xpage, ==, page);
59955 } else {
59956 - fscache_stat(&fscache_n_store_vmscan_gone);
59957 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
59958 }
59959
59960 wake_up_bit(&cookie->flags, 0);
59961 @@ -110,11 +110,11 @@ page_busy:
59962 * sleeping on memory allocation, so we may need to impose a timeout
59963 * too. */
59964 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
59965 - fscache_stat(&fscache_n_store_vmscan_busy);
59966 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
59967 return false;
59968 }
59969
59970 - fscache_stat(&fscache_n_store_vmscan_wait);
59971 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
59972 __fscache_wait_on_page_write(cookie, page);
59973 gfp &= ~__GFP_WAIT;
59974 goto try_again;
59975 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
59976 FSCACHE_COOKIE_STORING_TAG);
59977 if (!radix_tree_tag_get(&cookie->stores, page->index,
59978 FSCACHE_COOKIE_PENDING_TAG)) {
59979 - fscache_stat(&fscache_n_store_radix_deletes);
59980 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59981 xpage = radix_tree_delete(&cookie->stores, page->index);
59982 }
59983 spin_unlock(&cookie->stores_lock);
59984 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
59985
59986 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
59987
59988 - fscache_stat(&fscache_n_attr_changed_calls);
59989 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
59990
59991 if (fscache_object_is_active(object)) {
59992 fscache_stat(&fscache_n_cop_attr_changed);
59993 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
59994
59995 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59996
59997 - fscache_stat(&fscache_n_attr_changed);
59998 + fscache_stat_unchecked(&fscache_n_attr_changed);
59999
60000 op = kzalloc(sizeof(*op), GFP_KERNEL);
60001 if (!op) {
60002 - fscache_stat(&fscache_n_attr_changed_nomem);
60003 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60004 _leave(" = -ENOMEM");
60005 return -ENOMEM;
60006 }
60007 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60008 if (fscache_submit_exclusive_op(object, op) < 0)
60009 goto nobufs;
60010 spin_unlock(&cookie->lock);
60011 - fscache_stat(&fscache_n_attr_changed_ok);
60012 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60013 fscache_put_operation(op);
60014 _leave(" = 0");
60015 return 0;
60016 @@ -225,7 +225,7 @@ nobufs:
60017 kfree(op);
60018 if (wake_cookie)
60019 __fscache_wake_unused_cookie(cookie);
60020 - fscache_stat(&fscache_n_attr_changed_nobufs);
60021 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60022 _leave(" = %d", -ENOBUFS);
60023 return -ENOBUFS;
60024 }
60025 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60026 /* allocate a retrieval operation and attempt to submit it */
60027 op = kzalloc(sizeof(*op), GFP_NOIO);
60028 if (!op) {
60029 - fscache_stat(&fscache_n_retrievals_nomem);
60030 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60031 return NULL;
60032 }
60033
60034 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60035 return 0;
60036 }
60037
60038 - fscache_stat(&fscache_n_retrievals_wait);
60039 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60040
60041 jif = jiffies;
60042 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60043 fscache_wait_bit_interruptible,
60044 TASK_INTERRUPTIBLE) != 0) {
60045 - fscache_stat(&fscache_n_retrievals_intr);
60046 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60047 _leave(" = -ERESTARTSYS");
60048 return -ERESTARTSYS;
60049 }
60050 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60051 */
60052 int fscache_wait_for_operation_activation(struct fscache_object *object,
60053 struct fscache_operation *op,
60054 - atomic_t *stat_op_waits,
60055 - atomic_t *stat_object_dead,
60056 + atomic_unchecked_t *stat_op_waits,
60057 + atomic_unchecked_t *stat_object_dead,
60058 void (*do_cancel)(struct fscache_operation *))
60059 {
60060 int ret;
60061 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60062
60063 _debug(">>> WT");
60064 if (stat_op_waits)
60065 - fscache_stat(stat_op_waits);
60066 + fscache_stat_unchecked(stat_op_waits);
60067 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60068 fscache_wait_bit_interruptible,
60069 TASK_INTERRUPTIBLE) != 0) {
60070 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60071 check_if_dead:
60072 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60073 if (stat_object_dead)
60074 - fscache_stat(stat_object_dead);
60075 + fscache_stat_unchecked(stat_object_dead);
60076 _leave(" = -ENOBUFS [cancelled]");
60077 return -ENOBUFS;
60078 }
60079 @@ -366,7 +366,7 @@ check_if_dead:
60080 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60081 fscache_cancel_op(op, do_cancel);
60082 if (stat_object_dead)
60083 - fscache_stat(stat_object_dead);
60084 + fscache_stat_unchecked(stat_object_dead);
60085 return -ENOBUFS;
60086 }
60087 return 0;
60088 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60089
60090 _enter("%p,%p,,,", cookie, page);
60091
60092 - fscache_stat(&fscache_n_retrievals);
60093 + fscache_stat_unchecked(&fscache_n_retrievals);
60094
60095 if (hlist_empty(&cookie->backing_objects))
60096 goto nobufs;
60097 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60098 goto nobufs_unlock_dec;
60099 spin_unlock(&cookie->lock);
60100
60101 - fscache_stat(&fscache_n_retrieval_ops);
60102 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60103
60104 /* pin the netfs read context in case we need to do the actual netfs
60105 * read because we've encountered a cache read failure */
60106 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60107
60108 error:
60109 if (ret == -ENOMEM)
60110 - fscache_stat(&fscache_n_retrievals_nomem);
60111 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60112 else if (ret == -ERESTARTSYS)
60113 - fscache_stat(&fscache_n_retrievals_intr);
60114 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60115 else if (ret == -ENODATA)
60116 - fscache_stat(&fscache_n_retrievals_nodata);
60117 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60118 else if (ret < 0)
60119 - fscache_stat(&fscache_n_retrievals_nobufs);
60120 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60121 else
60122 - fscache_stat(&fscache_n_retrievals_ok);
60123 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60124
60125 fscache_put_retrieval(op);
60126 _leave(" = %d", ret);
60127 @@ -490,7 +490,7 @@ nobufs_unlock:
60128 __fscache_wake_unused_cookie(cookie);
60129 kfree(op);
60130 nobufs:
60131 - fscache_stat(&fscache_n_retrievals_nobufs);
60132 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60133 _leave(" = -ENOBUFS");
60134 return -ENOBUFS;
60135 }
60136 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60137
60138 _enter("%p,,%d,,,", cookie, *nr_pages);
60139
60140 - fscache_stat(&fscache_n_retrievals);
60141 + fscache_stat_unchecked(&fscache_n_retrievals);
60142
60143 if (hlist_empty(&cookie->backing_objects))
60144 goto nobufs;
60145 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60146 goto nobufs_unlock_dec;
60147 spin_unlock(&cookie->lock);
60148
60149 - fscache_stat(&fscache_n_retrieval_ops);
60150 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60151
60152 /* pin the netfs read context in case we need to do the actual netfs
60153 * read because we've encountered a cache read failure */
60154 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60155
60156 error:
60157 if (ret == -ENOMEM)
60158 - fscache_stat(&fscache_n_retrievals_nomem);
60159 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60160 else if (ret == -ERESTARTSYS)
60161 - fscache_stat(&fscache_n_retrievals_intr);
60162 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60163 else if (ret == -ENODATA)
60164 - fscache_stat(&fscache_n_retrievals_nodata);
60165 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60166 else if (ret < 0)
60167 - fscache_stat(&fscache_n_retrievals_nobufs);
60168 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60169 else
60170 - fscache_stat(&fscache_n_retrievals_ok);
60171 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60172
60173 fscache_put_retrieval(op);
60174 _leave(" = %d", ret);
60175 @@ -621,7 +621,7 @@ nobufs_unlock:
60176 if (wake_cookie)
60177 __fscache_wake_unused_cookie(cookie);
60178 nobufs:
60179 - fscache_stat(&fscache_n_retrievals_nobufs);
60180 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60181 _leave(" = -ENOBUFS");
60182 return -ENOBUFS;
60183 }
60184 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60185
60186 _enter("%p,%p,,,", cookie, page);
60187
60188 - fscache_stat(&fscache_n_allocs);
60189 + fscache_stat_unchecked(&fscache_n_allocs);
60190
60191 if (hlist_empty(&cookie->backing_objects))
60192 goto nobufs;
60193 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60194 goto nobufs_unlock_dec;
60195 spin_unlock(&cookie->lock);
60196
60197 - fscache_stat(&fscache_n_alloc_ops);
60198 + fscache_stat_unchecked(&fscache_n_alloc_ops);
60199
60200 ret = fscache_wait_for_operation_activation(
60201 object, &op->op,
60202 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60203
60204 error:
60205 if (ret == -ERESTARTSYS)
60206 - fscache_stat(&fscache_n_allocs_intr);
60207 + fscache_stat_unchecked(&fscache_n_allocs_intr);
60208 else if (ret < 0)
60209 - fscache_stat(&fscache_n_allocs_nobufs);
60210 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60211 else
60212 - fscache_stat(&fscache_n_allocs_ok);
60213 + fscache_stat_unchecked(&fscache_n_allocs_ok);
60214
60215 fscache_put_retrieval(op);
60216 _leave(" = %d", ret);
60217 @@ -715,7 +715,7 @@ nobufs_unlock:
60218 if (wake_cookie)
60219 __fscache_wake_unused_cookie(cookie);
60220 nobufs:
60221 - fscache_stat(&fscache_n_allocs_nobufs);
60222 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60223 _leave(" = -ENOBUFS");
60224 return -ENOBUFS;
60225 }
60226 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60227
60228 spin_lock(&cookie->stores_lock);
60229
60230 - fscache_stat(&fscache_n_store_calls);
60231 + fscache_stat_unchecked(&fscache_n_store_calls);
60232
60233 /* find a page to store */
60234 page = NULL;
60235 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60236 page = results[0];
60237 _debug("gang %d [%lx]", n, page->index);
60238 if (page->index > op->store_limit) {
60239 - fscache_stat(&fscache_n_store_pages_over_limit);
60240 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60241 goto superseded;
60242 }
60243
60244 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60245 spin_unlock(&cookie->stores_lock);
60246 spin_unlock(&object->lock);
60247
60248 - fscache_stat(&fscache_n_store_pages);
60249 + fscache_stat_unchecked(&fscache_n_store_pages);
60250 fscache_stat(&fscache_n_cop_write_page);
60251 ret = object->cache->ops->write_page(op, page);
60252 fscache_stat_d(&fscache_n_cop_write_page);
60253 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60254 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60255 ASSERT(PageFsCache(page));
60256
60257 - fscache_stat(&fscache_n_stores);
60258 + fscache_stat_unchecked(&fscache_n_stores);
60259
60260 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60261 _leave(" = -ENOBUFS [invalidating]");
60262 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60263 spin_unlock(&cookie->stores_lock);
60264 spin_unlock(&object->lock);
60265
60266 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60267 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60268 op->store_limit = object->store_limit;
60269
60270 __fscache_use_cookie(cookie);
60271 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60272
60273 spin_unlock(&cookie->lock);
60274 radix_tree_preload_end();
60275 - fscache_stat(&fscache_n_store_ops);
60276 - fscache_stat(&fscache_n_stores_ok);
60277 + fscache_stat_unchecked(&fscache_n_store_ops);
60278 + fscache_stat_unchecked(&fscache_n_stores_ok);
60279
60280 /* the work queue now carries its own ref on the object */
60281 fscache_put_operation(&op->op);
60282 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60283 return 0;
60284
60285 already_queued:
60286 - fscache_stat(&fscache_n_stores_again);
60287 + fscache_stat_unchecked(&fscache_n_stores_again);
60288 already_pending:
60289 spin_unlock(&cookie->stores_lock);
60290 spin_unlock(&object->lock);
60291 spin_unlock(&cookie->lock);
60292 radix_tree_preload_end();
60293 kfree(op);
60294 - fscache_stat(&fscache_n_stores_ok);
60295 + fscache_stat_unchecked(&fscache_n_stores_ok);
60296 _leave(" = 0");
60297 return 0;
60298
60299 @@ -1024,14 +1024,14 @@ nobufs:
60300 kfree(op);
60301 if (wake_cookie)
60302 __fscache_wake_unused_cookie(cookie);
60303 - fscache_stat(&fscache_n_stores_nobufs);
60304 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
60305 _leave(" = -ENOBUFS");
60306 return -ENOBUFS;
60307
60308 nomem_free:
60309 kfree(op);
60310 nomem:
60311 - fscache_stat(&fscache_n_stores_oom);
60312 + fscache_stat_unchecked(&fscache_n_stores_oom);
60313 _leave(" = -ENOMEM");
60314 return -ENOMEM;
60315 }
60316 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60317 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60318 ASSERTCMP(page, !=, NULL);
60319
60320 - fscache_stat(&fscache_n_uncaches);
60321 + fscache_stat_unchecked(&fscache_n_uncaches);
60322
60323 /* cache withdrawal may beat us to it */
60324 if (!PageFsCache(page))
60325 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60326 struct fscache_cookie *cookie = op->op.object->cookie;
60327
60328 #ifdef CONFIG_FSCACHE_STATS
60329 - atomic_inc(&fscache_n_marks);
60330 + atomic_inc_unchecked(&fscache_n_marks);
60331 #endif
60332
60333 _debug("- mark %p{%lx}", page, page->index);
60334 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60335 index 40d13c7..ddf52b9 100644
60336 --- a/fs/fscache/stats.c
60337 +++ b/fs/fscache/stats.c
60338 @@ -18,99 +18,99 @@
60339 /*
60340 * operation counters
60341 */
60342 -atomic_t fscache_n_op_pend;
60343 -atomic_t fscache_n_op_run;
60344 -atomic_t fscache_n_op_enqueue;
60345 -atomic_t fscache_n_op_requeue;
60346 -atomic_t fscache_n_op_deferred_release;
60347 -atomic_t fscache_n_op_release;
60348 -atomic_t fscache_n_op_gc;
60349 -atomic_t fscache_n_op_cancelled;
60350 -atomic_t fscache_n_op_rejected;
60351 +atomic_unchecked_t fscache_n_op_pend;
60352 +atomic_unchecked_t fscache_n_op_run;
60353 +atomic_unchecked_t fscache_n_op_enqueue;
60354 +atomic_unchecked_t fscache_n_op_requeue;
60355 +atomic_unchecked_t fscache_n_op_deferred_release;
60356 +atomic_unchecked_t fscache_n_op_release;
60357 +atomic_unchecked_t fscache_n_op_gc;
60358 +atomic_unchecked_t fscache_n_op_cancelled;
60359 +atomic_unchecked_t fscache_n_op_rejected;
60360
60361 -atomic_t fscache_n_attr_changed;
60362 -atomic_t fscache_n_attr_changed_ok;
60363 -atomic_t fscache_n_attr_changed_nobufs;
60364 -atomic_t fscache_n_attr_changed_nomem;
60365 -atomic_t fscache_n_attr_changed_calls;
60366 +atomic_unchecked_t fscache_n_attr_changed;
60367 +atomic_unchecked_t fscache_n_attr_changed_ok;
60368 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
60369 +atomic_unchecked_t fscache_n_attr_changed_nomem;
60370 +atomic_unchecked_t fscache_n_attr_changed_calls;
60371
60372 -atomic_t fscache_n_allocs;
60373 -atomic_t fscache_n_allocs_ok;
60374 -atomic_t fscache_n_allocs_wait;
60375 -atomic_t fscache_n_allocs_nobufs;
60376 -atomic_t fscache_n_allocs_intr;
60377 -atomic_t fscache_n_allocs_object_dead;
60378 -atomic_t fscache_n_alloc_ops;
60379 -atomic_t fscache_n_alloc_op_waits;
60380 +atomic_unchecked_t fscache_n_allocs;
60381 +atomic_unchecked_t fscache_n_allocs_ok;
60382 +atomic_unchecked_t fscache_n_allocs_wait;
60383 +atomic_unchecked_t fscache_n_allocs_nobufs;
60384 +atomic_unchecked_t fscache_n_allocs_intr;
60385 +atomic_unchecked_t fscache_n_allocs_object_dead;
60386 +atomic_unchecked_t fscache_n_alloc_ops;
60387 +atomic_unchecked_t fscache_n_alloc_op_waits;
60388
60389 -atomic_t fscache_n_retrievals;
60390 -atomic_t fscache_n_retrievals_ok;
60391 -atomic_t fscache_n_retrievals_wait;
60392 -atomic_t fscache_n_retrievals_nodata;
60393 -atomic_t fscache_n_retrievals_nobufs;
60394 -atomic_t fscache_n_retrievals_intr;
60395 -atomic_t fscache_n_retrievals_nomem;
60396 -atomic_t fscache_n_retrievals_object_dead;
60397 -atomic_t fscache_n_retrieval_ops;
60398 -atomic_t fscache_n_retrieval_op_waits;
60399 +atomic_unchecked_t fscache_n_retrievals;
60400 +atomic_unchecked_t fscache_n_retrievals_ok;
60401 +atomic_unchecked_t fscache_n_retrievals_wait;
60402 +atomic_unchecked_t fscache_n_retrievals_nodata;
60403 +atomic_unchecked_t fscache_n_retrievals_nobufs;
60404 +atomic_unchecked_t fscache_n_retrievals_intr;
60405 +atomic_unchecked_t fscache_n_retrievals_nomem;
60406 +atomic_unchecked_t fscache_n_retrievals_object_dead;
60407 +atomic_unchecked_t fscache_n_retrieval_ops;
60408 +atomic_unchecked_t fscache_n_retrieval_op_waits;
60409
60410 -atomic_t fscache_n_stores;
60411 -atomic_t fscache_n_stores_ok;
60412 -atomic_t fscache_n_stores_again;
60413 -atomic_t fscache_n_stores_nobufs;
60414 -atomic_t fscache_n_stores_oom;
60415 -atomic_t fscache_n_store_ops;
60416 -atomic_t fscache_n_store_calls;
60417 -atomic_t fscache_n_store_pages;
60418 -atomic_t fscache_n_store_radix_deletes;
60419 -atomic_t fscache_n_store_pages_over_limit;
60420 +atomic_unchecked_t fscache_n_stores;
60421 +atomic_unchecked_t fscache_n_stores_ok;
60422 +atomic_unchecked_t fscache_n_stores_again;
60423 +atomic_unchecked_t fscache_n_stores_nobufs;
60424 +atomic_unchecked_t fscache_n_stores_oom;
60425 +atomic_unchecked_t fscache_n_store_ops;
60426 +atomic_unchecked_t fscache_n_store_calls;
60427 +atomic_unchecked_t fscache_n_store_pages;
60428 +atomic_unchecked_t fscache_n_store_radix_deletes;
60429 +atomic_unchecked_t fscache_n_store_pages_over_limit;
60430
60431 -atomic_t fscache_n_store_vmscan_not_storing;
60432 -atomic_t fscache_n_store_vmscan_gone;
60433 -atomic_t fscache_n_store_vmscan_busy;
60434 -atomic_t fscache_n_store_vmscan_cancelled;
60435 -atomic_t fscache_n_store_vmscan_wait;
60436 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60437 +atomic_unchecked_t fscache_n_store_vmscan_gone;
60438 +atomic_unchecked_t fscache_n_store_vmscan_busy;
60439 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60440 +atomic_unchecked_t fscache_n_store_vmscan_wait;
60441
60442 -atomic_t fscache_n_marks;
60443 -atomic_t fscache_n_uncaches;
60444 +atomic_unchecked_t fscache_n_marks;
60445 +atomic_unchecked_t fscache_n_uncaches;
60446
60447 -atomic_t fscache_n_acquires;
60448 -atomic_t fscache_n_acquires_null;
60449 -atomic_t fscache_n_acquires_no_cache;
60450 -atomic_t fscache_n_acquires_ok;
60451 -atomic_t fscache_n_acquires_nobufs;
60452 -atomic_t fscache_n_acquires_oom;
60453 +atomic_unchecked_t fscache_n_acquires;
60454 +atomic_unchecked_t fscache_n_acquires_null;
60455 +atomic_unchecked_t fscache_n_acquires_no_cache;
60456 +atomic_unchecked_t fscache_n_acquires_ok;
60457 +atomic_unchecked_t fscache_n_acquires_nobufs;
60458 +atomic_unchecked_t fscache_n_acquires_oom;
60459
60460 -atomic_t fscache_n_invalidates;
60461 -atomic_t fscache_n_invalidates_run;
60462 +atomic_unchecked_t fscache_n_invalidates;
60463 +atomic_unchecked_t fscache_n_invalidates_run;
60464
60465 -atomic_t fscache_n_updates;
60466 -atomic_t fscache_n_updates_null;
60467 -atomic_t fscache_n_updates_run;
60468 +atomic_unchecked_t fscache_n_updates;
60469 +atomic_unchecked_t fscache_n_updates_null;
60470 +atomic_unchecked_t fscache_n_updates_run;
60471
60472 -atomic_t fscache_n_relinquishes;
60473 -atomic_t fscache_n_relinquishes_null;
60474 -atomic_t fscache_n_relinquishes_waitcrt;
60475 -atomic_t fscache_n_relinquishes_retire;
60476 +atomic_unchecked_t fscache_n_relinquishes;
60477 +atomic_unchecked_t fscache_n_relinquishes_null;
60478 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60479 +atomic_unchecked_t fscache_n_relinquishes_retire;
60480
60481 -atomic_t fscache_n_cookie_index;
60482 -atomic_t fscache_n_cookie_data;
60483 -atomic_t fscache_n_cookie_special;
60484 +atomic_unchecked_t fscache_n_cookie_index;
60485 +atomic_unchecked_t fscache_n_cookie_data;
60486 +atomic_unchecked_t fscache_n_cookie_special;
60487
60488 -atomic_t fscache_n_object_alloc;
60489 -atomic_t fscache_n_object_no_alloc;
60490 -atomic_t fscache_n_object_lookups;
60491 -atomic_t fscache_n_object_lookups_negative;
60492 -atomic_t fscache_n_object_lookups_positive;
60493 -atomic_t fscache_n_object_lookups_timed_out;
60494 -atomic_t fscache_n_object_created;
60495 -atomic_t fscache_n_object_avail;
60496 -atomic_t fscache_n_object_dead;
60497 +atomic_unchecked_t fscache_n_object_alloc;
60498 +atomic_unchecked_t fscache_n_object_no_alloc;
60499 +atomic_unchecked_t fscache_n_object_lookups;
60500 +atomic_unchecked_t fscache_n_object_lookups_negative;
60501 +atomic_unchecked_t fscache_n_object_lookups_positive;
60502 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
60503 +atomic_unchecked_t fscache_n_object_created;
60504 +atomic_unchecked_t fscache_n_object_avail;
60505 +atomic_unchecked_t fscache_n_object_dead;
60506
60507 -atomic_t fscache_n_checkaux_none;
60508 -atomic_t fscache_n_checkaux_okay;
60509 -atomic_t fscache_n_checkaux_update;
60510 -atomic_t fscache_n_checkaux_obsolete;
60511 +atomic_unchecked_t fscache_n_checkaux_none;
60512 +atomic_unchecked_t fscache_n_checkaux_okay;
60513 +atomic_unchecked_t fscache_n_checkaux_update;
60514 +atomic_unchecked_t fscache_n_checkaux_obsolete;
60515
60516 atomic_t fscache_n_cop_alloc_object;
60517 atomic_t fscache_n_cop_lookup_object;
60518 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60519 seq_puts(m, "FS-Cache statistics\n");
60520
60521 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60522 - atomic_read(&fscache_n_cookie_index),
60523 - atomic_read(&fscache_n_cookie_data),
60524 - atomic_read(&fscache_n_cookie_special));
60525 + atomic_read_unchecked(&fscache_n_cookie_index),
60526 + atomic_read_unchecked(&fscache_n_cookie_data),
60527 + atomic_read_unchecked(&fscache_n_cookie_special));
60528
60529 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60530 - atomic_read(&fscache_n_object_alloc),
60531 - atomic_read(&fscache_n_object_no_alloc),
60532 - atomic_read(&fscache_n_object_avail),
60533 - atomic_read(&fscache_n_object_dead));
60534 + atomic_read_unchecked(&fscache_n_object_alloc),
60535 + atomic_read_unchecked(&fscache_n_object_no_alloc),
60536 + atomic_read_unchecked(&fscache_n_object_avail),
60537 + atomic_read_unchecked(&fscache_n_object_dead));
60538 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60539 - atomic_read(&fscache_n_checkaux_none),
60540 - atomic_read(&fscache_n_checkaux_okay),
60541 - atomic_read(&fscache_n_checkaux_update),
60542 - atomic_read(&fscache_n_checkaux_obsolete));
60543 + atomic_read_unchecked(&fscache_n_checkaux_none),
60544 + atomic_read_unchecked(&fscache_n_checkaux_okay),
60545 + atomic_read_unchecked(&fscache_n_checkaux_update),
60546 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60547
60548 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60549 - atomic_read(&fscache_n_marks),
60550 - atomic_read(&fscache_n_uncaches));
60551 + atomic_read_unchecked(&fscache_n_marks),
60552 + atomic_read_unchecked(&fscache_n_uncaches));
60553
60554 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60555 " oom=%u\n",
60556 - atomic_read(&fscache_n_acquires),
60557 - atomic_read(&fscache_n_acquires_null),
60558 - atomic_read(&fscache_n_acquires_no_cache),
60559 - atomic_read(&fscache_n_acquires_ok),
60560 - atomic_read(&fscache_n_acquires_nobufs),
60561 - atomic_read(&fscache_n_acquires_oom));
60562 + atomic_read_unchecked(&fscache_n_acquires),
60563 + atomic_read_unchecked(&fscache_n_acquires_null),
60564 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
60565 + atomic_read_unchecked(&fscache_n_acquires_ok),
60566 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
60567 + atomic_read_unchecked(&fscache_n_acquires_oom));
60568
60569 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60570 - atomic_read(&fscache_n_object_lookups),
60571 - atomic_read(&fscache_n_object_lookups_negative),
60572 - atomic_read(&fscache_n_object_lookups_positive),
60573 - atomic_read(&fscache_n_object_created),
60574 - atomic_read(&fscache_n_object_lookups_timed_out));
60575 + atomic_read_unchecked(&fscache_n_object_lookups),
60576 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
60577 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
60578 + atomic_read_unchecked(&fscache_n_object_created),
60579 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60580
60581 seq_printf(m, "Invals : n=%u run=%u\n",
60582 - atomic_read(&fscache_n_invalidates),
60583 - atomic_read(&fscache_n_invalidates_run));
60584 + atomic_read_unchecked(&fscache_n_invalidates),
60585 + atomic_read_unchecked(&fscache_n_invalidates_run));
60586
60587 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60588 - atomic_read(&fscache_n_updates),
60589 - atomic_read(&fscache_n_updates_null),
60590 - atomic_read(&fscache_n_updates_run));
60591 + atomic_read_unchecked(&fscache_n_updates),
60592 + atomic_read_unchecked(&fscache_n_updates_null),
60593 + atomic_read_unchecked(&fscache_n_updates_run));
60594
60595 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60596 - atomic_read(&fscache_n_relinquishes),
60597 - atomic_read(&fscache_n_relinquishes_null),
60598 - atomic_read(&fscache_n_relinquishes_waitcrt),
60599 - atomic_read(&fscache_n_relinquishes_retire));
60600 + atomic_read_unchecked(&fscache_n_relinquishes),
60601 + atomic_read_unchecked(&fscache_n_relinquishes_null),
60602 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60603 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
60604
60605 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60606 - atomic_read(&fscache_n_attr_changed),
60607 - atomic_read(&fscache_n_attr_changed_ok),
60608 - atomic_read(&fscache_n_attr_changed_nobufs),
60609 - atomic_read(&fscache_n_attr_changed_nomem),
60610 - atomic_read(&fscache_n_attr_changed_calls));
60611 + atomic_read_unchecked(&fscache_n_attr_changed),
60612 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
60613 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60614 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60615 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
60616
60617 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60618 - atomic_read(&fscache_n_allocs),
60619 - atomic_read(&fscache_n_allocs_ok),
60620 - atomic_read(&fscache_n_allocs_wait),
60621 - atomic_read(&fscache_n_allocs_nobufs),
60622 - atomic_read(&fscache_n_allocs_intr));
60623 + atomic_read_unchecked(&fscache_n_allocs),
60624 + atomic_read_unchecked(&fscache_n_allocs_ok),
60625 + atomic_read_unchecked(&fscache_n_allocs_wait),
60626 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
60627 + atomic_read_unchecked(&fscache_n_allocs_intr));
60628 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60629 - atomic_read(&fscache_n_alloc_ops),
60630 - atomic_read(&fscache_n_alloc_op_waits),
60631 - atomic_read(&fscache_n_allocs_object_dead));
60632 + atomic_read_unchecked(&fscache_n_alloc_ops),
60633 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
60634 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
60635
60636 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60637 " int=%u oom=%u\n",
60638 - atomic_read(&fscache_n_retrievals),
60639 - atomic_read(&fscache_n_retrievals_ok),
60640 - atomic_read(&fscache_n_retrievals_wait),
60641 - atomic_read(&fscache_n_retrievals_nodata),
60642 - atomic_read(&fscache_n_retrievals_nobufs),
60643 - atomic_read(&fscache_n_retrievals_intr),
60644 - atomic_read(&fscache_n_retrievals_nomem));
60645 + atomic_read_unchecked(&fscache_n_retrievals),
60646 + atomic_read_unchecked(&fscache_n_retrievals_ok),
60647 + atomic_read_unchecked(&fscache_n_retrievals_wait),
60648 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
60649 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60650 + atomic_read_unchecked(&fscache_n_retrievals_intr),
60651 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
60652 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60653 - atomic_read(&fscache_n_retrieval_ops),
60654 - atomic_read(&fscache_n_retrieval_op_waits),
60655 - atomic_read(&fscache_n_retrievals_object_dead));
60656 + atomic_read_unchecked(&fscache_n_retrieval_ops),
60657 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60658 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60659
60660 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60661 - atomic_read(&fscache_n_stores),
60662 - atomic_read(&fscache_n_stores_ok),
60663 - atomic_read(&fscache_n_stores_again),
60664 - atomic_read(&fscache_n_stores_nobufs),
60665 - atomic_read(&fscache_n_stores_oom));
60666 + atomic_read_unchecked(&fscache_n_stores),
60667 + atomic_read_unchecked(&fscache_n_stores_ok),
60668 + atomic_read_unchecked(&fscache_n_stores_again),
60669 + atomic_read_unchecked(&fscache_n_stores_nobufs),
60670 + atomic_read_unchecked(&fscache_n_stores_oom));
60671 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60672 - atomic_read(&fscache_n_store_ops),
60673 - atomic_read(&fscache_n_store_calls),
60674 - atomic_read(&fscache_n_store_pages),
60675 - atomic_read(&fscache_n_store_radix_deletes),
60676 - atomic_read(&fscache_n_store_pages_over_limit));
60677 + atomic_read_unchecked(&fscache_n_store_ops),
60678 + atomic_read_unchecked(&fscache_n_store_calls),
60679 + atomic_read_unchecked(&fscache_n_store_pages),
60680 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
60681 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60682
60683 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60684 - atomic_read(&fscache_n_store_vmscan_not_storing),
60685 - atomic_read(&fscache_n_store_vmscan_gone),
60686 - atomic_read(&fscache_n_store_vmscan_busy),
60687 - atomic_read(&fscache_n_store_vmscan_cancelled),
60688 - atomic_read(&fscache_n_store_vmscan_wait));
60689 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60690 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60691 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60692 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60693 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60694
60695 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60696 - atomic_read(&fscache_n_op_pend),
60697 - atomic_read(&fscache_n_op_run),
60698 - atomic_read(&fscache_n_op_enqueue),
60699 - atomic_read(&fscache_n_op_cancelled),
60700 - atomic_read(&fscache_n_op_rejected));
60701 + atomic_read_unchecked(&fscache_n_op_pend),
60702 + atomic_read_unchecked(&fscache_n_op_run),
60703 + atomic_read_unchecked(&fscache_n_op_enqueue),
60704 + atomic_read_unchecked(&fscache_n_op_cancelled),
60705 + atomic_read_unchecked(&fscache_n_op_rejected));
60706 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
60707 - atomic_read(&fscache_n_op_deferred_release),
60708 - atomic_read(&fscache_n_op_release),
60709 - atomic_read(&fscache_n_op_gc));
60710 + atomic_read_unchecked(&fscache_n_op_deferred_release),
60711 + atomic_read_unchecked(&fscache_n_op_release),
60712 + atomic_read_unchecked(&fscache_n_op_gc));
60713
60714 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60715 atomic_read(&fscache_n_cop_alloc_object),
60716 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60717 index b96a49b..9bfdc47 100644
60718 --- a/fs/fuse/cuse.c
60719 +++ b/fs/fuse/cuse.c
60720 @@ -606,10 +606,12 @@ static int __init cuse_init(void)
60721 INIT_LIST_HEAD(&cuse_conntbl[i]);
60722
60723 /* inherit and extend fuse_dev_operations */
60724 - cuse_channel_fops = fuse_dev_operations;
60725 - cuse_channel_fops.owner = THIS_MODULE;
60726 - cuse_channel_fops.open = cuse_channel_open;
60727 - cuse_channel_fops.release = cuse_channel_release;
60728 + pax_open_kernel();
60729 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60730 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60731 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
60732 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
60733 + pax_close_kernel();
60734
60735 cuse_class = class_create(THIS_MODULE, "cuse");
60736 if (IS_ERR(cuse_class))
60737 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60738 index 0a648bb..8d463f1 100644
60739 --- a/fs/fuse/dev.c
60740 +++ b/fs/fuse/dev.c
60741 @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60742 ret = 0;
60743 pipe_lock(pipe);
60744
60745 - if (!pipe->readers) {
60746 + if (!atomic_read(&pipe->readers)) {
60747 send_sig(SIGPIPE, current, 0);
60748 if (!ret)
60749 ret = -EPIPE;
60750 @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60751 page_nr++;
60752 ret += buf->len;
60753
60754 - if (pipe->files)
60755 + if (atomic_read(&pipe->files))
60756 do_wakeup = 1;
60757 }
60758
60759 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
60760 index 1d1292c..bba17ea 100644
60761 --- a/fs/fuse/dir.c
60762 +++ b/fs/fuse/dir.c
60763 @@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
60764 return link;
60765 }
60766
60767 -static void free_link(char *link)
60768 +static void free_link(const char *link)
60769 {
60770 if (!IS_ERR(link))
60771 free_page((unsigned long) link);
60772 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
60773 index fe649d3..c679164 100644
60774 --- a/fs/hostfs/hostfs_kern.c
60775 +++ b/fs/hostfs/hostfs_kern.c
60776 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60777
60778 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60779 {
60780 - char *s = nd_get_link(nd);
60781 + const char *s = nd_get_link(nd);
60782 if (!IS_ERR(s))
60783 __putname(s);
60784 }
60785 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
60786 index d19b30a..ef89c36 100644
60787 --- a/fs/hugetlbfs/inode.c
60788 +++ b/fs/hugetlbfs/inode.c
60789 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60790 struct mm_struct *mm = current->mm;
60791 struct vm_area_struct *vma;
60792 struct hstate *h = hstate_file(file);
60793 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
60794 struct vm_unmapped_area_info info;
60795
60796 if (len & ~huge_page_mask(h))
60797 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60798 return addr;
60799 }
60800
60801 +#ifdef CONFIG_PAX_RANDMMAP
60802 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
60803 +#endif
60804 +
60805 if (addr) {
60806 addr = ALIGN(addr, huge_page_size(h));
60807 vma = find_vma(mm, addr);
60808 - if (TASK_SIZE - len >= addr &&
60809 - (!vma || addr + len <= vma->vm_start))
60810 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
60811 return addr;
60812 }
60813
60814 info.flags = 0;
60815 info.length = len;
60816 info.low_limit = TASK_UNMAPPED_BASE;
60817 +
60818 +#ifdef CONFIG_PAX_RANDMMAP
60819 + if (mm->pax_flags & MF_PAX_RANDMMAP)
60820 + info.low_limit += mm->delta_mmap;
60821 +#endif
60822 +
60823 info.high_limit = TASK_SIZE;
60824 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
60825 info.align_offset = 0;
60826 @@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
60827 };
60828 MODULE_ALIAS_FS("hugetlbfs");
60829
60830 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60831 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60832
60833 static int can_do_hugetlb_shm(void)
60834 {
60835 diff --git a/fs/inode.c b/fs/inode.c
60836 index 4bcdad3..1883822 100644
60837 --- a/fs/inode.c
60838 +++ b/fs/inode.c
60839 @@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
60840
60841 #ifdef CONFIG_SMP
60842 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
60843 - static atomic_t shared_last_ino;
60844 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
60845 + static atomic_unchecked_t shared_last_ino;
60846 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
60847
60848 res = next - LAST_INO_BATCH;
60849 }
60850 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
60851 index 4a6cf28..d3a29d3 100644
60852 --- a/fs/jffs2/erase.c
60853 +++ b/fs/jffs2/erase.c
60854 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
60855 struct jffs2_unknown_node marker = {
60856 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
60857 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60858 - .totlen = cpu_to_je32(c->cleanmarker_size)
60859 + .totlen = cpu_to_je32(c->cleanmarker_size),
60860 + .hdr_crc = cpu_to_je32(0)
60861 };
60862
60863 jffs2_prealloc_raw_node_refs(c, jeb, 1);
60864 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
60865 index a6597d6..41b30ec 100644
60866 --- a/fs/jffs2/wbuf.c
60867 +++ b/fs/jffs2/wbuf.c
60868 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
60869 {
60870 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
60871 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60872 - .totlen = constant_cpu_to_je32(8)
60873 + .totlen = constant_cpu_to_je32(8),
60874 + .hdr_crc = constant_cpu_to_je32(0)
60875 };
60876
60877 /*
60878 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
60879 index e2b7483..855bca3 100644
60880 --- a/fs/jfs/super.c
60881 +++ b/fs/jfs/super.c
60882 @@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
60883
60884 jfs_inode_cachep =
60885 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
60886 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
60887 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
60888 init_once);
60889 if (jfs_inode_cachep == NULL)
60890 return -ENOMEM;
60891 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
60892 index bd6e18b..812d4ff 100644
60893 --- a/fs/kernfs/dir.c
60894 +++ b/fs/kernfs/dir.c
60895 @@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
60896 *
60897 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60898 */
60899 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
60900 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
60901 {
60902 unsigned long hash = init_name_hash();
60903 unsigned int len = strlen(name);
60904 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
60905 index dbf397b..d624b48 100644
60906 --- a/fs/kernfs/file.c
60907 +++ b/fs/kernfs/file.c
60908 @@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
60909
60910 struct kernfs_open_node {
60911 atomic_t refcnt;
60912 - atomic_t event;
60913 + atomic_unchecked_t event;
60914 wait_queue_head_t poll;
60915 struct list_head files; /* goes through kernfs_open_file.list */
60916 };
60917 @@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
60918 {
60919 struct kernfs_open_file *of = sf->private;
60920
60921 - of->event = atomic_read(&of->kn->attr.open->event);
60922 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
60923
60924 return of->kn->attr.ops->seq_show(sf, v);
60925 }
60926 @@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
60927 return ret;
60928 }
60929
60930 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
60931 - void *buf, int len, int write)
60932 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
60933 + void *buf, size_t len, int write)
60934 {
60935 struct file *file = vma->vm_file;
60936 struct kernfs_open_file *of = kernfs_of(file);
60937 - int ret;
60938 + ssize_t ret;
60939
60940 if (!of->vm_ops)
60941 return -EINVAL;
60942 @@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
60943 return -ENOMEM;
60944
60945 atomic_set(&new_on->refcnt, 0);
60946 - atomic_set(&new_on->event, 1);
60947 + atomic_set_unchecked(&new_on->event, 1);
60948 init_waitqueue_head(&new_on->poll);
60949 INIT_LIST_HEAD(&new_on->files);
60950 goto retry;
60951 @@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
60952
60953 kernfs_put_active(kn);
60954
60955 - if (of->event != atomic_read(&on->event))
60956 + if (of->event != atomic_read_unchecked(&on->event))
60957 goto trigger;
60958
60959 return DEFAULT_POLLMASK;
60960 @@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
60961 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
60962 on = kn->attr.open;
60963 if (on) {
60964 - atomic_inc(&on->event);
60965 + atomic_inc_unchecked(&on->event);
60966 wake_up_interruptible(&on->poll);
60967 }
60968 }
60969 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
60970 index 4d45705..b35e0bd 100644
60971 --- a/fs/kernfs/symlink.c
60972 +++ b/fs/kernfs/symlink.c
60973 @@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
60974 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
60975 void *cookie)
60976 {
60977 - char *page = nd_get_link(nd);
60978 + const char *page = nd_get_link(nd);
60979 if (!IS_ERR(page))
60980 free_page((unsigned long)page);
60981 }
60982 diff --git a/fs/libfs.c b/fs/libfs.c
60983 index a184424..944ddce 100644
60984 --- a/fs/libfs.c
60985 +++ b/fs/libfs.c
60986 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60987
60988 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
60989 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
60990 + char d_name[sizeof(next->d_iname)];
60991 + const unsigned char *name;
60992 +
60993 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
60994 if (!simple_positive(next)) {
60995 spin_unlock(&next->d_lock);
60996 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60997
60998 spin_unlock(&next->d_lock);
60999 spin_unlock(&dentry->d_lock);
61000 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61001 + name = next->d_name.name;
61002 + if (name == next->d_iname) {
61003 + memcpy(d_name, name, next->d_name.len);
61004 + name = d_name;
61005 + }
61006 + if (!dir_emit(ctx, name, next->d_name.len,
61007 next->d_inode->i_ino, dt_type(next->d_inode)))
61008 return 0;
61009 spin_lock(&dentry->d_lock);
61010 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61011 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61012 void *cookie)
61013 {
61014 - char *s = nd_get_link(nd);
61015 + const char *s = nd_get_link(nd);
61016 if (!IS_ERR(s))
61017 kfree(s);
61018 }
61019 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61020 index acd3947..1f896e2 100644
61021 --- a/fs/lockd/clntproc.c
61022 +++ b/fs/lockd/clntproc.c
61023 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61024 /*
61025 * Cookie counter for NLM requests
61026 */
61027 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61028 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61029
61030 void nlmclnt_next_cookie(struct nlm_cookie *c)
61031 {
61032 - u32 cookie = atomic_inc_return(&nlm_cookie);
61033 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61034
61035 memcpy(c->data, &cookie, 4);
61036 c->len=4;
61037 diff --git a/fs/locks.c b/fs/locks.c
61038 index 92a0f0a..45a48f0 100644
61039 --- a/fs/locks.c
61040 +++ b/fs/locks.c
61041 @@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61042 return;
61043
61044 if (filp->f_op->flock) {
61045 - struct file_lock fl = {
61046 + struct file_lock flock = {
61047 .fl_pid = current->tgid,
61048 .fl_file = filp,
61049 .fl_flags = FL_FLOCK,
61050 .fl_type = F_UNLCK,
61051 .fl_end = OFFSET_MAX,
61052 };
61053 - filp->f_op->flock(filp, F_SETLKW, &fl);
61054 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
61055 - fl.fl_ops->fl_release_private(&fl);
61056 + filp->f_op->flock(filp, F_SETLKW, &flock);
61057 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
61058 + flock.fl_ops->fl_release_private(&flock);
61059 }
61060
61061 spin_lock(&inode->i_lock);
61062 diff --git a/fs/mount.h b/fs/mount.h
61063 index b29e42f..5ea7fdf 100644
61064 --- a/fs/mount.h
61065 +++ b/fs/mount.h
61066 @@ -11,7 +11,7 @@ struct mnt_namespace {
61067 u64 seq; /* Sequence number to prevent loops */
61068 wait_queue_head_t poll;
61069 int event;
61070 -};
61071 +} __randomize_layout;
61072
61073 struct mnt_pcp {
61074 int mnt_count;
61075 @@ -57,7 +57,7 @@ struct mount {
61076 int mnt_expiry_mark; /* true if marked for expiry */
61077 int mnt_pinned;
61078 struct path mnt_ex_mountpoint;
61079 -};
61080 +} __randomize_layout;
61081
61082 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61083
61084 diff --git a/fs/namei.c b/fs/namei.c
61085 index 4b491b4..a0166f9 100644
61086 --- a/fs/namei.c
61087 +++ b/fs/namei.c
61088 @@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61089 if (ret != -EACCES)
61090 return ret;
61091
61092 +#ifdef CONFIG_GRKERNSEC
61093 + /* we'll block if we have to log due to a denied capability use */
61094 + if (mask & MAY_NOT_BLOCK)
61095 + return -ECHILD;
61096 +#endif
61097 +
61098 if (S_ISDIR(inode->i_mode)) {
61099 /* DACs are overridable for directories */
61100 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
61101 - return 0;
61102 if (!(mask & MAY_WRITE))
61103 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61104 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61105 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61106 return 0;
61107 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
61108 + return 0;
61109 return -EACCES;
61110 }
61111 /*
61112 + * Searching includes executable on directories, else just read.
61113 + */
61114 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61115 + if (mask == MAY_READ)
61116 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61117 + inode_capable(inode, CAP_DAC_READ_SEARCH))
61118 + return 0;
61119 +
61120 + /*
61121 * Read/write DACs are always overridable.
61122 * Executable DACs are overridable when there is
61123 * at least one exec bit set.
61124 @@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61125 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61126 return 0;
61127
61128 - /*
61129 - * Searching includes executable on directories, else just read.
61130 - */
61131 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61132 - if (mask == MAY_READ)
61133 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61134 - return 0;
61135 -
61136 return -EACCES;
61137 }
61138
61139 @@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61140 {
61141 struct dentry *dentry = link->dentry;
61142 int error;
61143 - char *s;
61144 + const char *s;
61145
61146 BUG_ON(nd->flags & LOOKUP_RCU);
61147
61148 @@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61149 if (error)
61150 goto out_put_nd_path;
61151
61152 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
61153 + dentry->d_inode, dentry, nd->path.mnt)) {
61154 + error = -EACCES;
61155 + goto out_put_nd_path;
61156 + }
61157 +
61158 nd->last_type = LAST_BIND;
61159 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61160 error = PTR_ERR(*p);
61161 @@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61162 if (res)
61163 break;
61164 res = walk_component(nd, path, LOOKUP_FOLLOW);
61165 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61166 + res = -EACCES;
61167 put_link(nd, &link, cookie);
61168 } while (res > 0);
61169
61170 @@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
61171 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61172 {
61173 unsigned long a, b, adata, bdata, mask, hash, len;
61174 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61175 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61176
61177 hash = a = 0;
61178 len = -sizeof(unsigned long);
61179 @@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
61180 if (err)
61181 break;
61182 err = lookup_last(nd, &path);
61183 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
61184 + err = -EACCES;
61185 put_link(nd, &link, cookie);
61186 }
61187 }
61188 @@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
61189 if (!err)
61190 err = complete_walk(nd);
61191
61192 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
61193 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61194 + path_put(&nd->path);
61195 + err = -ENOENT;
61196 + }
61197 + }
61198 +
61199 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61200 if (!d_is_directory(nd->path.dentry)) {
61201 path_put(&nd->path);
61202 @@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
61203 retval = path_lookupat(dfd, name->name,
61204 flags | LOOKUP_REVAL, nd);
61205
61206 - if (likely(!retval))
61207 + if (likely(!retval)) {
61208 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61209 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61210 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61211 + path_put(&nd->path);
61212 + return -ENOENT;
61213 + }
61214 + }
61215 + }
61216 return retval;
61217 }
61218
61219 @@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61220 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61221 return -EPERM;
61222
61223 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61224 + return -EPERM;
61225 + if (gr_handle_rawio(inode))
61226 + return -EPERM;
61227 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61228 + return -EACCES;
61229 +
61230 return 0;
61231 }
61232
61233 @@ -2787,7 +2826,7 @@ looked_up:
61234 * cleared otherwise prior to returning.
61235 */
61236 static int lookup_open(struct nameidata *nd, struct path *path,
61237 - struct file *file,
61238 + struct path *link, struct file *file,
61239 const struct open_flags *op,
61240 bool got_write, int *opened)
61241 {
61242 @@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61243 /* Negative dentry, just create the file */
61244 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61245 umode_t mode = op->mode;
61246 +
61247 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61248 + error = -EACCES;
61249 + goto out_dput;
61250 + }
61251 +
61252 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61253 + error = -EACCES;
61254 + goto out_dput;
61255 + }
61256 +
61257 if (!IS_POSIXACL(dir->d_inode))
61258 mode &= ~current_umask();
61259 /*
61260 @@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61261 nd->flags & LOOKUP_EXCL);
61262 if (error)
61263 goto out_dput;
61264 + else
61265 + gr_handle_create(dentry, nd->path.mnt);
61266 }
61267 out_no_open:
61268 path->dentry = dentry;
61269 @@ -2857,7 +2909,7 @@ out_dput:
61270 /*
61271 * Handle the last step of open()
61272 */
61273 -static int do_last(struct nameidata *nd, struct path *path,
61274 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61275 struct file *file, const struct open_flags *op,
61276 int *opened, struct filename *name)
61277 {
61278 @@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61279 if (error)
61280 return error;
61281
61282 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61283 + error = -ENOENT;
61284 + goto out;
61285 + }
61286 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61287 + error = -EACCES;
61288 + goto out;
61289 + }
61290 +
61291 audit_inode(name, dir, LOOKUP_PARENT);
61292 error = -EISDIR;
61293 /* trailing slashes? */
61294 @@ -2926,7 +2987,7 @@ retry_lookup:
61295 */
61296 }
61297 mutex_lock(&dir->d_inode->i_mutex);
61298 - error = lookup_open(nd, path, file, op, got_write, opened);
61299 + error = lookup_open(nd, path, link, file, op, got_write, opened);
61300 mutex_unlock(&dir->d_inode->i_mutex);
61301
61302 if (error <= 0) {
61303 @@ -2950,11 +3011,28 @@ retry_lookup:
61304 goto finish_open_created;
61305 }
61306
61307 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61308 + error = -ENOENT;
61309 + goto exit_dput;
61310 + }
61311 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61312 + error = -EACCES;
61313 + goto exit_dput;
61314 + }
61315 +
61316 /*
61317 * create/update audit record if it already exists.
61318 */
61319 - if (d_is_positive(path->dentry))
61320 + if (d_is_positive(path->dentry)) {
61321 + /* only check if O_CREAT is specified, all other checks need to go
61322 + into may_open */
61323 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61324 + error = -EACCES;
61325 + goto exit_dput;
61326 + }
61327 +
61328 audit_inode(name, path->dentry, 0);
61329 + }
61330
61331 /*
61332 * If atomic_open() acquired write access it is dropped now due to
61333 @@ -2995,6 +3073,11 @@ finish_lookup:
61334 }
61335 }
61336 BUG_ON(inode != path->dentry->d_inode);
61337 + /* if we're resolving a symlink to another symlink */
61338 + if (link && gr_handle_symlink_owner(link, inode)) {
61339 + error = -EACCES;
61340 + goto out;
61341 + }
61342 return 1;
61343 }
61344
61345 @@ -3004,7 +3087,6 @@ finish_lookup:
61346 save_parent.dentry = nd->path.dentry;
61347 save_parent.mnt = mntget(path->mnt);
61348 nd->path.dentry = path->dentry;
61349 -
61350 }
61351 nd->inode = inode;
61352 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61353 @@ -3014,7 +3096,18 @@ finish_open:
61354 path_put(&save_parent);
61355 return error;
61356 }
61357 +
61358 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61359 + error = -ENOENT;
61360 + goto out;
61361 + }
61362 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61363 + error = -EACCES;
61364 + goto out;
61365 + }
61366 +
61367 audit_inode(name, nd->path.dentry, 0);
61368 +
61369 error = -EISDIR;
61370 if ((open_flag & O_CREAT) &&
61371 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61372 @@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61373 if (unlikely(error))
61374 goto out;
61375
61376 - error = do_last(nd, &path, file, op, &opened, pathname);
61377 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61378 while (unlikely(error > 0)) { /* trailing symlink */
61379 struct path link = path;
61380 void *cookie;
61381 @@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61382 error = follow_link(&link, nd, &cookie);
61383 if (unlikely(error))
61384 break;
61385 - error = do_last(nd, &path, file, op, &opened, pathname);
61386 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
61387 put_link(nd, &link, cookie);
61388 }
61389 out:
61390 @@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61391 goto unlock;
61392
61393 error = -EEXIST;
61394 - if (d_is_positive(dentry))
61395 + if (d_is_positive(dentry)) {
61396 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61397 + error = -ENOENT;
61398 goto fail;
61399 -
61400 + }
61401 /*
61402 * Special case - lookup gave negative, but... we had foo/bar/
61403 * From the vfs_mknod() POV we just have a negative dentry -
61404 @@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61405 }
61406 EXPORT_SYMBOL(user_path_create);
61407
61408 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61409 +{
61410 + struct filename *tmp = getname(pathname);
61411 + struct dentry *res;
61412 + if (IS_ERR(tmp))
61413 + return ERR_CAST(tmp);
61414 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61415 + if (IS_ERR(res))
61416 + putname(tmp);
61417 + else
61418 + *to = tmp;
61419 + return res;
61420 +}
61421 +
61422 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61423 {
61424 int error = may_create(dir, dentry);
61425 @@ -3412,6 +3521,17 @@ retry:
61426
61427 if (!IS_POSIXACL(path.dentry->d_inode))
61428 mode &= ~current_umask();
61429 +
61430 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61431 + error = -EPERM;
61432 + goto out;
61433 + }
61434 +
61435 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61436 + error = -EACCES;
61437 + goto out;
61438 + }
61439 +
61440 error = security_path_mknod(&path, dentry, mode, dev);
61441 if (error)
61442 goto out;
61443 @@ -3428,6 +3548,8 @@ retry:
61444 break;
61445 }
61446 out:
61447 + if (!error)
61448 + gr_handle_create(dentry, path.mnt);
61449 done_path_create(&path, dentry);
61450 if (retry_estale(error, lookup_flags)) {
61451 lookup_flags |= LOOKUP_REVAL;
61452 @@ -3480,9 +3602,16 @@ retry:
61453
61454 if (!IS_POSIXACL(path.dentry->d_inode))
61455 mode &= ~current_umask();
61456 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61457 + error = -EACCES;
61458 + goto out;
61459 + }
61460 error = security_path_mkdir(&path, dentry, mode);
61461 if (!error)
61462 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61463 + if (!error)
61464 + gr_handle_create(dentry, path.mnt);
61465 +out:
61466 done_path_create(&path, dentry);
61467 if (retry_estale(error, lookup_flags)) {
61468 lookup_flags |= LOOKUP_REVAL;
61469 @@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61470 struct filename *name;
61471 struct dentry *dentry;
61472 struct nameidata nd;
61473 + ino_t saved_ino = 0;
61474 + dev_t saved_dev = 0;
61475 unsigned int lookup_flags = 0;
61476 retry:
61477 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61478 @@ -3595,10 +3726,21 @@ retry:
61479 error = -ENOENT;
61480 goto exit3;
61481 }
61482 +
61483 + saved_ino = dentry->d_inode->i_ino;
61484 + saved_dev = gr_get_dev_from_dentry(dentry);
61485 +
61486 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61487 + error = -EACCES;
61488 + goto exit3;
61489 + }
61490 +
61491 error = security_path_rmdir(&nd.path, dentry);
61492 if (error)
61493 goto exit3;
61494 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61495 + if (!error && (saved_dev || saved_ino))
61496 + gr_handle_delete(saved_ino, saved_dev);
61497 exit3:
61498 dput(dentry);
61499 exit2:
61500 @@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61501 struct nameidata nd;
61502 struct inode *inode = NULL;
61503 struct inode *delegated_inode = NULL;
61504 + ino_t saved_ino = 0;
61505 + dev_t saved_dev = 0;
61506 unsigned int lookup_flags = 0;
61507 retry:
61508 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61509 @@ -3714,10 +3858,22 @@ retry_deleg:
61510 if (d_is_negative(dentry))
61511 goto slashes;
61512 ihold(inode);
61513 +
61514 + if (inode->i_nlink <= 1) {
61515 + saved_ino = inode->i_ino;
61516 + saved_dev = gr_get_dev_from_dentry(dentry);
61517 + }
61518 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61519 + error = -EACCES;
61520 + goto exit2;
61521 + }
61522 +
61523 error = security_path_unlink(&nd.path, dentry);
61524 if (error)
61525 goto exit2;
61526 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61527 + if (!error && (saved_ino || saved_dev))
61528 + gr_handle_delete(saved_ino, saved_dev);
61529 exit2:
61530 dput(dentry);
61531 }
61532 @@ -3805,9 +3961,17 @@ retry:
61533 if (IS_ERR(dentry))
61534 goto out_putname;
61535
61536 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61537 + error = -EACCES;
61538 + goto out;
61539 + }
61540 +
61541 error = security_path_symlink(&path, dentry, from->name);
61542 if (!error)
61543 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61544 + if (!error)
61545 + gr_handle_create(dentry, path.mnt);
61546 +out:
61547 done_path_create(&path, dentry);
61548 if (retry_estale(error, lookup_flags)) {
61549 lookup_flags |= LOOKUP_REVAL;
61550 @@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61551 struct dentry *new_dentry;
61552 struct path old_path, new_path;
61553 struct inode *delegated_inode = NULL;
61554 + struct filename *to = NULL;
61555 int how = 0;
61556 int error;
61557
61558 @@ -3933,7 +4098,7 @@ retry:
61559 if (error)
61560 return error;
61561
61562 - new_dentry = user_path_create(newdfd, newname, &new_path,
61563 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61564 (how & LOOKUP_REVAL));
61565 error = PTR_ERR(new_dentry);
61566 if (IS_ERR(new_dentry))
61567 @@ -3945,11 +4110,28 @@ retry:
61568 error = may_linkat(&old_path);
61569 if (unlikely(error))
61570 goto out_dput;
61571 +
61572 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61573 + old_path.dentry->d_inode,
61574 + old_path.dentry->d_inode->i_mode, to)) {
61575 + error = -EACCES;
61576 + goto out_dput;
61577 + }
61578 +
61579 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61580 + old_path.dentry, old_path.mnt, to)) {
61581 + error = -EACCES;
61582 + goto out_dput;
61583 + }
61584 +
61585 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61586 if (error)
61587 goto out_dput;
61588 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61589 + if (!error)
61590 + gr_handle_create(new_dentry, new_path.mnt);
61591 out_dput:
61592 + putname(to);
61593 done_path_create(&new_path, new_dentry);
61594 if (delegated_inode) {
61595 error = break_deleg_wait(&delegated_inode);
61596 @@ -4236,6 +4418,12 @@ retry_deleg:
61597 if (new_dentry == trap)
61598 goto exit5;
61599
61600 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61601 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
61602 + to);
61603 + if (error)
61604 + goto exit5;
61605 +
61606 error = security_path_rename(&oldnd.path, old_dentry,
61607 &newnd.path, new_dentry);
61608 if (error)
61609 @@ -4243,6 +4431,9 @@ retry_deleg:
61610 error = vfs_rename(old_dir->d_inode, old_dentry,
61611 new_dir->d_inode, new_dentry,
61612 &delegated_inode);
61613 + if (!error)
61614 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61615 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
61616 exit5:
61617 dput(new_dentry);
61618 exit4:
61619 @@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61620
61621 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
61622 {
61623 + char tmpbuf[64];
61624 + const char *newlink;
61625 int len;
61626
61627 len = PTR_ERR(link);
61628 @@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
61629 len = strlen(link);
61630 if (len > (unsigned) buflen)
61631 len = buflen;
61632 - if (copy_to_user(buffer, link, len))
61633 +
61634 + if (len < sizeof(tmpbuf)) {
61635 + memcpy(tmpbuf, link, len);
61636 + newlink = tmpbuf;
61637 + } else
61638 + newlink = link;
61639 +
61640 + if (copy_to_user(buffer, newlink, len))
61641 len = -EFAULT;
61642 out:
61643 return len;
61644 diff --git a/fs/namespace.c b/fs/namespace.c
61645 index 2ffc5a2..6737083 100644
61646 --- a/fs/namespace.c
61647 +++ b/fs/namespace.c
61648 @@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
61649 if (!(sb->s_flags & MS_RDONLY))
61650 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
61651 up_write(&sb->s_umount);
61652 +
61653 + gr_log_remount(mnt->mnt_devname, retval);
61654 +
61655 return retval;
61656 }
61657
61658 @@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
61659 }
61660 unlock_mount_hash();
61661 namespace_unlock();
61662 +
61663 + gr_log_unmount(mnt->mnt_devname, retval);
61664 +
61665 return retval;
61666 }
61667
61668 @@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
61669 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
61670 */
61671
61672 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
61673 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
61674 {
61675 struct path path;
61676 struct mount *mnt;
61677 @@ -1422,7 +1428,7 @@ out:
61678 /*
61679 * The 2.0 compatible umount. No flags.
61680 */
61681 -SYSCALL_DEFINE1(oldumount, char __user *, name)
61682 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
61683 {
61684 return sys_umount(name, 0);
61685 }
61686 @@ -2426,6 +2432,16 @@ long do_mount(const char *dev_name, const char *dir_name,
61687 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
61688 MS_STRICTATIME);
61689
61690 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
61691 + retval = -EPERM;
61692 + goto dput_out;
61693 + }
61694 +
61695 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
61696 + retval = -EPERM;
61697 + goto dput_out;
61698 + }
61699 +
61700 if (flags & MS_REMOUNT)
61701 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
61702 data_page);
61703 @@ -2440,6 +2456,9 @@ long do_mount(const char *dev_name, const char *dir_name,
61704 dev_name, data_page);
61705 dput_out:
61706 path_put(&path);
61707 +
61708 + gr_log_mount(dev_name, dir_name, retval);
61709 +
61710 return retval;
61711 }
61712
61713 @@ -2457,7 +2476,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
61714 * number incrementing at 10Ghz will take 12,427 years to wrap which
61715 * is effectively never, so we can ignore the possibility.
61716 */
61717 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
61718 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
61719
61720 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61721 {
61722 @@ -2472,7 +2491,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61723 kfree(new_ns);
61724 return ERR_PTR(ret);
61725 }
61726 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
61727 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
61728 atomic_set(&new_ns->count, 1);
61729 new_ns->root = NULL;
61730 INIT_LIST_HEAD(&new_ns->list);
61731 @@ -2482,7 +2501,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61732 return new_ns;
61733 }
61734
61735 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61736 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61737 struct user_namespace *user_ns, struct fs_struct *new_fs)
61738 {
61739 struct mnt_namespace *new_ns;
61740 @@ -2603,8 +2622,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
61741 }
61742 EXPORT_SYMBOL(mount_subtree);
61743
61744 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
61745 - char __user *, type, unsigned long, flags, void __user *, data)
61746 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
61747 + const char __user *, type, unsigned long, flags, void __user *, data)
61748 {
61749 int ret;
61750 char *kernel_type;
61751 @@ -2717,6 +2736,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
61752 if (error)
61753 goto out2;
61754
61755 + if (gr_handle_chroot_pivot()) {
61756 + error = -EPERM;
61757 + goto out2;
61758 + }
61759 +
61760 get_fs_root(current->fs, &root);
61761 old_mp = lock_mount(&old);
61762 error = PTR_ERR(old_mp);
61763 @@ -2985,7 +3009,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
61764 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
61765 return -EPERM;
61766
61767 - if (fs->users != 1)
61768 + if (atomic_read(&fs->users) != 1)
61769 return -EINVAL;
61770
61771 get_mnt_ns(mnt_ns);
61772 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
61773 index f4ccfe6..a5cf064 100644
61774 --- a/fs/nfs/callback_xdr.c
61775 +++ b/fs/nfs/callback_xdr.c
61776 @@ -51,7 +51,7 @@ struct callback_op {
61777 callback_decode_arg_t decode_args;
61778 callback_encode_res_t encode_res;
61779 long res_maxsize;
61780 -};
61781 +} __do_const;
61782
61783 static struct callback_op callback_ops[];
61784
61785 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
61786 index 360114a..ac6e265 100644
61787 --- a/fs/nfs/inode.c
61788 +++ b/fs/nfs/inode.c
61789 @@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
61790 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
61791 }
61792
61793 -static atomic_long_t nfs_attr_generation_counter;
61794 +static atomic_long_unchecked_t nfs_attr_generation_counter;
61795
61796 static unsigned long nfs_read_attr_generation_counter(void)
61797 {
61798 - return atomic_long_read(&nfs_attr_generation_counter);
61799 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
61800 }
61801
61802 unsigned long nfs_inc_attr_generation_counter(void)
61803 {
61804 - return atomic_long_inc_return(&nfs_attr_generation_counter);
61805 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
61806 }
61807
61808 void nfs_fattr_init(struct nfs_fattr *fattr)
61809 diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
61810 index 450bfed..d5d06e8 100644
61811 --- a/fs/nfs/nfs4proc.c
61812 +++ b/fs/nfs/nfs4proc.c
61813 @@ -1068,6 +1068,7 @@ static void nfs4_opendata_free(struct kref *kref)
61814 dput(p->dentry);
61815 nfs_sb_deactive(sb);
61816 nfs_fattr_free_names(&p->f_attr);
61817 + kfree(p->f_attr.mdsthreshold);
61818 kfree(p);
61819 }
61820
61821 @@ -2244,10 +2245,12 @@ static int _nfs4_do_open(struct inode *dir,
61822 }
61823 }
61824
61825 - if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
61826 - opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
61827 - if (!opendata->f_attr.mdsthreshold)
61828 - goto err_free_label;
61829 + if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
61830 + if (!opendata->f_attr.mdsthreshold) {
61831 + opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
61832 + if (!opendata->f_attr.mdsthreshold)
61833 + goto err_free_label;
61834 + }
61835 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
61836 }
61837 if (dentry->d_inode != NULL)
61838 @@ -2275,11 +2278,10 @@ static int _nfs4_do_open(struct inode *dir,
61839 if (opendata->file_created)
61840 *opened |= FILE_CREATED;
61841
61842 - if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
61843 + if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) {
61844 *ctx_th = opendata->f_attr.mdsthreshold;
61845 - else
61846 - kfree(opendata->f_attr.mdsthreshold);
61847 - opendata->f_attr.mdsthreshold = NULL;
61848 + opendata->f_attr.mdsthreshold = NULL;
61849 + }
61850
61851 nfs4_label_free(olabel);
61852
61853 @@ -2289,7 +2291,6 @@ static int _nfs4_do_open(struct inode *dir,
61854 err_free_label:
61855 nfs4_label_free(olabel);
61856 err_opendata_put:
61857 - kfree(opendata->f_attr.mdsthreshold);
61858 nfs4_opendata_put(opendata);
61859 err_put_state_owner:
61860 nfs4_put_state_owner(sp);
61861 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
61862 index 82189b2..e43a39f 100644
61863 --- a/fs/nfsd/nfs4proc.c
61864 +++ b/fs/nfsd/nfs4proc.c
61865 @@ -1178,7 +1178,7 @@ struct nfsd4_operation {
61866 nfsd4op_rsize op_rsize_bop;
61867 stateid_getter op_get_currentstateid;
61868 stateid_setter op_set_currentstateid;
61869 -};
61870 +} __do_const;
61871
61872 static struct nfsd4_operation nfsd4_ops[];
61873
61874 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
61875 index 63f2395..7c47f4d 100644
61876 --- a/fs/nfsd/nfs4xdr.c
61877 +++ b/fs/nfsd/nfs4xdr.c
61878 @@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
61879
61880 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
61881
61882 -static nfsd4_dec nfsd4_dec_ops[] = {
61883 +static const nfsd4_dec nfsd4_dec_ops[] = {
61884 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
61885 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
61886 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
61887 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
61888 index f8f060f..c4ba09a 100644
61889 --- a/fs/nfsd/nfscache.c
61890 +++ b/fs/nfsd/nfscache.c
61891 @@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
61892 {
61893 struct svc_cacherep *rp = rqstp->rq_cacherep;
61894 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
61895 - int len;
61896 + long len;
61897 size_t bufsize = 0;
61898
61899 if (!rp)
61900 return;
61901
61902 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
61903 - len >>= 2;
61904 + if (statp) {
61905 + len = (char*)statp - (char*)resv->iov_base;
61906 + len = resv->iov_len - len;
61907 + len >>= 2;
61908 + }
61909
61910 /* Don't cache excessive amounts of data and XDR failures */
61911 if (!statp || len > (256 >> 2)) {
61912 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
61913 index 6d7be3f..ef02c86 100644
61914 --- a/fs/nfsd/vfs.c
61915 +++ b/fs/nfsd/vfs.c
61916 @@ -834,7 +834,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61917 } else {
61918 oldfs = get_fs();
61919 set_fs(KERNEL_DS);
61920 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
61921 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
61922 set_fs(oldfs);
61923 }
61924
61925 @@ -925,7 +925,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61926
61927 /* Write the data. */
61928 oldfs = get_fs(); set_fs(KERNEL_DS);
61929 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
61930 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
61931 set_fs(oldfs);
61932 if (host_err < 0)
61933 goto out_nfserr;
61934 @@ -1470,7 +1470,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
61935 */
61936
61937 oldfs = get_fs(); set_fs(KERNEL_DS);
61938 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
61939 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
61940 set_fs(oldfs);
61941
61942 if (host_err < 0)
61943 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
61944 index 52ccd34..43a53b1 100644
61945 --- a/fs/nls/nls_base.c
61946 +++ b/fs/nls/nls_base.c
61947 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
61948
61949 int __register_nls(struct nls_table *nls, struct module *owner)
61950 {
61951 - struct nls_table ** tmp = &tables;
61952 + struct nls_table *tmp = tables;
61953
61954 if (nls->next)
61955 return -EBUSY;
61956
61957 - nls->owner = owner;
61958 + pax_open_kernel();
61959 + *(void **)&nls->owner = owner;
61960 + pax_close_kernel();
61961 spin_lock(&nls_lock);
61962 - while (*tmp) {
61963 - if (nls == *tmp) {
61964 + while (tmp) {
61965 + if (nls == tmp) {
61966 spin_unlock(&nls_lock);
61967 return -EBUSY;
61968 }
61969 - tmp = &(*tmp)->next;
61970 + tmp = tmp->next;
61971 }
61972 - nls->next = tables;
61973 + pax_open_kernel();
61974 + *(struct nls_table **)&nls->next = tables;
61975 + pax_close_kernel();
61976 tables = nls;
61977 spin_unlock(&nls_lock);
61978 return 0;
61979 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
61980
61981 int unregister_nls(struct nls_table * nls)
61982 {
61983 - struct nls_table ** tmp = &tables;
61984 + struct nls_table * const * tmp = &tables;
61985
61986 spin_lock(&nls_lock);
61987 while (*tmp) {
61988 if (nls == *tmp) {
61989 - *tmp = nls->next;
61990 + pax_open_kernel();
61991 + *(struct nls_table **)tmp = nls->next;
61992 + pax_close_kernel();
61993 spin_unlock(&nls_lock);
61994 return 0;
61995 }
61996 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
61997 index 162b3f1..6076a7c 100644
61998 --- a/fs/nls/nls_euc-jp.c
61999 +++ b/fs/nls/nls_euc-jp.c
62000 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62001 p_nls = load_nls("cp932");
62002
62003 if (p_nls) {
62004 - table.charset2upper = p_nls->charset2upper;
62005 - table.charset2lower = p_nls->charset2lower;
62006 + pax_open_kernel();
62007 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62008 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62009 + pax_close_kernel();
62010 return register_nls(&table);
62011 }
62012
62013 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62014 index a80a741..7b96e1b 100644
62015 --- a/fs/nls/nls_koi8-ru.c
62016 +++ b/fs/nls/nls_koi8-ru.c
62017 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62018 p_nls = load_nls("koi8-u");
62019
62020 if (p_nls) {
62021 - table.charset2upper = p_nls->charset2upper;
62022 - table.charset2lower = p_nls->charset2lower;
62023 + pax_open_kernel();
62024 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62025 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62026 + pax_close_kernel();
62027 return register_nls(&table);
62028 }
62029
62030 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62031 index 287a22c..a2a043a 100644
62032 --- a/fs/notify/fanotify/fanotify_user.c
62033 +++ b/fs/notify/fanotify/fanotify_user.c
62034 @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62035
62036 fd = fanotify_event_metadata.fd;
62037 ret = -EFAULT;
62038 - if (copy_to_user(buf, &fanotify_event_metadata,
62039 - fanotify_event_metadata.event_len))
62040 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62041 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62042 goto out_close_fd;
62043
62044 ret = prepare_for_access_response(group, event, fd);
62045 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62046 index 1e58402..bb2d6f4 100644
62047 --- a/fs/notify/notification.c
62048 +++ b/fs/notify/notification.c
62049 @@ -48,7 +48,7 @@
62050 #include <linux/fsnotify_backend.h>
62051 #include "fsnotify.h"
62052
62053 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62054 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62055
62056 /**
62057 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62058 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62059 */
62060 u32 fsnotify_get_cookie(void)
62061 {
62062 - return atomic_inc_return(&fsnotify_sync_cookie);
62063 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62064 }
62065 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62066
62067 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62068 index 9e38daf..5727cae 100644
62069 --- a/fs/ntfs/dir.c
62070 +++ b/fs/ntfs/dir.c
62071 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
62072 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62073 ~(s64)(ndir->itype.index.block_size - 1)));
62074 /* Bounds checks. */
62075 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62076 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62077 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62078 "inode 0x%lx or driver bug.", vdir->i_ino);
62079 goto err_out;
62080 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62081 index db9bd8a..8338fb6 100644
62082 --- a/fs/ntfs/file.c
62083 +++ b/fs/ntfs/file.c
62084 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62085 char *addr;
62086 size_t total = 0;
62087 unsigned len;
62088 - int left;
62089 + unsigned left;
62090
62091 do {
62092 len = PAGE_CACHE_SIZE - ofs;
62093 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62094 index 82650d5..db37dcf 100644
62095 --- a/fs/ntfs/super.c
62096 +++ b/fs/ntfs/super.c
62097 @@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62098 if (!silent)
62099 ntfs_error(sb, "Primary boot sector is invalid.");
62100 } else if (!silent)
62101 - ntfs_error(sb, read_err_str, "primary");
62102 + ntfs_error(sb, read_err_str, "%s", "primary");
62103 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62104 if (bh_primary)
62105 brelse(bh_primary);
62106 @@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62107 goto hotfix_primary_boot_sector;
62108 brelse(bh_backup);
62109 } else if (!silent)
62110 - ntfs_error(sb, read_err_str, "backup");
62111 + ntfs_error(sb, read_err_str, "%s", "backup");
62112 /* Try to read NT3.51- backup boot sector. */
62113 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62114 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62115 @@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62116 "sector.");
62117 brelse(bh_backup);
62118 } else if (!silent)
62119 - ntfs_error(sb, read_err_str, "backup");
62120 + ntfs_error(sb, read_err_str, "%s", "backup");
62121 /* We failed. Cleanup and return. */
62122 if (bh_primary)
62123 brelse(bh_primary);
62124 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62125 index 0440134..d52c93a 100644
62126 --- a/fs/ocfs2/localalloc.c
62127 +++ b/fs/ocfs2/localalloc.c
62128 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62129 goto bail;
62130 }
62131
62132 - atomic_inc(&osb->alloc_stats.moves);
62133 + atomic_inc_unchecked(&osb->alloc_stats.moves);
62134
62135 bail:
62136 if (handle)
62137 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62138 index 553f53c..aaf5133 100644
62139 --- a/fs/ocfs2/ocfs2.h
62140 +++ b/fs/ocfs2/ocfs2.h
62141 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
62142
62143 struct ocfs2_alloc_stats
62144 {
62145 - atomic_t moves;
62146 - atomic_t local_data;
62147 - atomic_t bitmap_data;
62148 - atomic_t bg_allocs;
62149 - atomic_t bg_extends;
62150 + atomic_unchecked_t moves;
62151 + atomic_unchecked_t local_data;
62152 + atomic_unchecked_t bitmap_data;
62153 + atomic_unchecked_t bg_allocs;
62154 + atomic_unchecked_t bg_extends;
62155 };
62156
62157 enum ocfs2_local_alloc_state
62158 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62159 index 47ae266..6e8b793 100644
62160 --- a/fs/ocfs2/suballoc.c
62161 +++ b/fs/ocfs2/suballoc.c
62162 @@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62163 mlog_errno(status);
62164 goto bail;
62165 }
62166 - atomic_inc(&osb->alloc_stats.bg_extends);
62167 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62168
62169 /* You should never ask for this much metadata */
62170 BUG_ON(bits_wanted >
62171 @@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62172 mlog_errno(status);
62173 goto bail;
62174 }
62175 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62176 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62177
62178 *suballoc_loc = res.sr_bg_blkno;
62179 *suballoc_bit_start = res.sr_bit_offset;
62180 @@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62181 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62182 res->sr_bits);
62183
62184 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62185 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62186
62187 BUG_ON(res->sr_bits != 1);
62188
62189 @@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62190 mlog_errno(status);
62191 goto bail;
62192 }
62193 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62194 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62195
62196 BUG_ON(res.sr_bits != 1);
62197
62198 @@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62199 cluster_start,
62200 num_clusters);
62201 if (!status)
62202 - atomic_inc(&osb->alloc_stats.local_data);
62203 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
62204 } else {
62205 if (min_clusters > (osb->bitmap_cpg - 1)) {
62206 /* The only paths asking for contiguousness
62207 @@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62208 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62209 res.sr_bg_blkno,
62210 res.sr_bit_offset);
62211 - atomic_inc(&osb->alloc_stats.bitmap_data);
62212 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62213 *num_clusters = res.sr_bits;
62214 }
62215 }
62216 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62217 index 49d84f8..4807e0b 100644
62218 --- a/fs/ocfs2/super.c
62219 +++ b/fs/ocfs2/super.c
62220 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62221 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62222 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62223 "Stats",
62224 - atomic_read(&osb->alloc_stats.bitmap_data),
62225 - atomic_read(&osb->alloc_stats.local_data),
62226 - atomic_read(&osb->alloc_stats.bg_allocs),
62227 - atomic_read(&osb->alloc_stats.moves),
62228 - atomic_read(&osb->alloc_stats.bg_extends));
62229 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62230 + atomic_read_unchecked(&osb->alloc_stats.local_data),
62231 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62232 + atomic_read_unchecked(&osb->alloc_stats.moves),
62233 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62234
62235 out += snprintf(buf + out, len - out,
62236 "%10s => State: %u Descriptor: %llu Size: %u bits "
62237 @@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62238 spin_lock_init(&osb->osb_xattr_lock);
62239 ocfs2_init_steal_slots(osb);
62240
62241 - atomic_set(&osb->alloc_stats.moves, 0);
62242 - atomic_set(&osb->alloc_stats.local_data, 0);
62243 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
62244 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
62245 - atomic_set(&osb->alloc_stats.bg_extends, 0);
62246 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62247 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62248 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62249 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62250 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62251
62252 /* Copy the blockcheck stats from the superblock probe */
62253 osb->osb_ecc_stats = *stats;
62254 diff --git a/fs/open.c b/fs/open.c
62255 index b9ed8b2..0d5c7a0 100644
62256 --- a/fs/open.c
62257 +++ b/fs/open.c
62258 @@ -32,6 +32,8 @@
62259 #include <linux/dnotify.h>
62260 #include <linux/compat.h>
62261
62262 +#define CREATE_TRACE_POINTS
62263 +#include <trace/events/fs.h>
62264 #include "internal.h"
62265
62266 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62267 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62268 error = locks_verify_truncate(inode, NULL, length);
62269 if (!error)
62270 error = security_path_truncate(path);
62271 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62272 + error = -EACCES;
62273 if (!error)
62274 error = do_truncate(path->dentry, length, 0, NULL);
62275
62276 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62277 error = locks_verify_truncate(inode, f.file, length);
62278 if (!error)
62279 error = security_path_truncate(&f.file->f_path);
62280 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62281 + error = -EACCES;
62282 if (!error)
62283 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62284 sb_end_write(inode->i_sb);
62285 @@ -361,6 +367,9 @@ retry:
62286 if (__mnt_is_readonly(path.mnt))
62287 res = -EROFS;
62288
62289 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62290 + res = -EACCES;
62291 +
62292 out_path_release:
62293 path_put(&path);
62294 if (retry_estale(res, lookup_flags)) {
62295 @@ -392,6 +401,8 @@ retry:
62296 if (error)
62297 goto dput_and_out;
62298
62299 + gr_log_chdir(path.dentry, path.mnt);
62300 +
62301 set_fs_pwd(current->fs, &path);
62302
62303 dput_and_out:
62304 @@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62305 goto out_putf;
62306
62307 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62308 +
62309 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62310 + error = -EPERM;
62311 +
62312 + if (!error)
62313 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62314 +
62315 if (!error)
62316 set_fs_pwd(current->fs, &f.file->f_path);
62317 out_putf:
62318 @@ -450,7 +468,13 @@ retry:
62319 if (error)
62320 goto dput_and_out;
62321
62322 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62323 + goto dput_and_out;
62324 +
62325 set_fs_root(current->fs, &path);
62326 +
62327 + gr_handle_chroot_chdir(&path);
62328 +
62329 error = 0;
62330 dput_and_out:
62331 path_put(&path);
62332 @@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62333 return error;
62334 retry_deleg:
62335 mutex_lock(&inode->i_mutex);
62336 +
62337 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62338 + error = -EACCES;
62339 + goto out_unlock;
62340 + }
62341 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62342 + error = -EACCES;
62343 + goto out_unlock;
62344 + }
62345 +
62346 error = security_path_chmod(path, mode);
62347 if (error)
62348 goto out_unlock;
62349 @@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62350 uid = make_kuid(current_user_ns(), user);
62351 gid = make_kgid(current_user_ns(), group);
62352
62353 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
62354 + return -EACCES;
62355 +
62356 newattrs.ia_valid = ATTR_CTIME;
62357 if (user != (uid_t) -1) {
62358 if (!uid_valid(uid))
62359 @@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62360 } else {
62361 fsnotify_open(f);
62362 fd_install(fd, f);
62363 + trace_do_sys_open(tmp->name, flags, mode);
62364 }
62365 }
62366 putname(tmp);
62367 diff --git a/fs/pipe.c b/fs/pipe.c
62368 index 78fd0d0..f71fc09 100644
62369 --- a/fs/pipe.c
62370 +++ b/fs/pipe.c
62371 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62372
62373 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62374 {
62375 - if (pipe->files)
62376 + if (atomic_read(&pipe->files))
62377 mutex_lock_nested(&pipe->mutex, subclass);
62378 }
62379
62380 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62381
62382 void pipe_unlock(struct pipe_inode_info *pipe)
62383 {
62384 - if (pipe->files)
62385 + if (atomic_read(&pipe->files))
62386 mutex_unlock(&pipe->mutex);
62387 }
62388 EXPORT_SYMBOL(pipe_unlock);
62389 @@ -449,9 +449,9 @@ redo:
62390 }
62391 if (bufs) /* More to do? */
62392 continue;
62393 - if (!pipe->writers)
62394 + if (!atomic_read(&pipe->writers))
62395 break;
62396 - if (!pipe->waiting_writers) {
62397 + if (!atomic_read(&pipe->waiting_writers)) {
62398 /* syscall merging: Usually we must not sleep
62399 * if O_NONBLOCK is set, or if we got some data.
62400 * But if a writer sleeps in kernel space, then
62401 @@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62402 ret = 0;
62403 __pipe_lock(pipe);
62404
62405 - if (!pipe->readers) {
62406 + if (!atomic_read(&pipe->readers)) {
62407 send_sig(SIGPIPE, current, 0);
62408 ret = -EPIPE;
62409 goto out;
62410 @@ -562,7 +562,7 @@ redo1:
62411 for (;;) {
62412 int bufs;
62413
62414 - if (!pipe->readers) {
62415 + if (!atomic_read(&pipe->readers)) {
62416 send_sig(SIGPIPE, current, 0);
62417 if (!ret)
62418 ret = -EPIPE;
62419 @@ -653,9 +653,9 @@ redo2:
62420 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62421 do_wakeup = 0;
62422 }
62423 - pipe->waiting_writers++;
62424 + atomic_inc(&pipe->waiting_writers);
62425 pipe_wait(pipe);
62426 - pipe->waiting_writers--;
62427 + atomic_dec(&pipe->waiting_writers);
62428 }
62429 out:
62430 __pipe_unlock(pipe);
62431 @@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62432 mask = 0;
62433 if (filp->f_mode & FMODE_READ) {
62434 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62435 - if (!pipe->writers && filp->f_version != pipe->w_counter)
62436 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62437 mask |= POLLHUP;
62438 }
62439
62440 @@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62441 * Most Unices do not set POLLERR for FIFOs but on Linux they
62442 * behave exactly like pipes for poll().
62443 */
62444 - if (!pipe->readers)
62445 + if (!atomic_read(&pipe->readers))
62446 mask |= POLLERR;
62447 }
62448
62449 @@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62450 int kill = 0;
62451
62452 spin_lock(&inode->i_lock);
62453 - if (!--pipe->files) {
62454 + if (atomic_dec_and_test(&pipe->files)) {
62455 inode->i_pipe = NULL;
62456 kill = 1;
62457 }
62458 @@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
62459
62460 __pipe_lock(pipe);
62461 if (file->f_mode & FMODE_READ)
62462 - pipe->readers--;
62463 + atomic_dec(&pipe->readers);
62464 if (file->f_mode & FMODE_WRITE)
62465 - pipe->writers--;
62466 + atomic_dec(&pipe->writers);
62467
62468 - if (pipe->readers || pipe->writers) {
62469 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62470 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62471 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62472 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62473 @@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62474 kfree(pipe);
62475 }
62476
62477 -static struct vfsmount *pipe_mnt __read_mostly;
62478 +struct vfsmount *pipe_mnt __read_mostly;
62479
62480 /*
62481 * pipefs_dname() is called from d_path().
62482 @@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
62483 goto fail_iput;
62484
62485 inode->i_pipe = pipe;
62486 - pipe->files = 2;
62487 - pipe->readers = pipe->writers = 1;
62488 + atomic_set(&pipe->files, 2);
62489 + atomic_set(&pipe->readers, 1);
62490 + atomic_set(&pipe->writers, 1);
62491 inode->i_fop = &pipefifo_fops;
62492
62493 /*
62494 @@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62495 spin_lock(&inode->i_lock);
62496 if (inode->i_pipe) {
62497 pipe = inode->i_pipe;
62498 - pipe->files++;
62499 + atomic_inc(&pipe->files);
62500 spin_unlock(&inode->i_lock);
62501 } else {
62502 spin_unlock(&inode->i_lock);
62503 pipe = alloc_pipe_info();
62504 if (!pipe)
62505 return -ENOMEM;
62506 - pipe->files = 1;
62507 + atomic_set(&pipe->files, 1);
62508 spin_lock(&inode->i_lock);
62509 if (unlikely(inode->i_pipe)) {
62510 - inode->i_pipe->files++;
62511 + atomic_inc(&inode->i_pipe->files);
62512 spin_unlock(&inode->i_lock);
62513 free_pipe_info(pipe);
62514 pipe = inode->i_pipe;
62515 @@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62516 * opened, even when there is no process writing the FIFO.
62517 */
62518 pipe->r_counter++;
62519 - if (pipe->readers++ == 0)
62520 + if (atomic_inc_return(&pipe->readers) == 1)
62521 wake_up_partner(pipe);
62522
62523 - if (!is_pipe && !pipe->writers) {
62524 + if (!is_pipe && !atomic_read(&pipe->writers)) {
62525 if ((filp->f_flags & O_NONBLOCK)) {
62526 /* suppress POLLHUP until we have
62527 * seen a writer */
62528 @@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62529 * errno=ENXIO when there is no process reading the FIFO.
62530 */
62531 ret = -ENXIO;
62532 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62533 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62534 goto err;
62535
62536 pipe->w_counter++;
62537 - if (!pipe->writers++)
62538 + if (atomic_inc_return(&pipe->writers) == 1)
62539 wake_up_partner(pipe);
62540
62541 - if (!is_pipe && !pipe->readers) {
62542 + if (!is_pipe && !atomic_read(&pipe->readers)) {
62543 if (wait_for_partner(pipe, &pipe->r_counter))
62544 goto err_wr;
62545 }
62546 @@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62547 * the process can at least talk to itself.
62548 */
62549
62550 - pipe->readers++;
62551 - pipe->writers++;
62552 + atomic_inc(&pipe->readers);
62553 + atomic_inc(&pipe->writers);
62554 pipe->r_counter++;
62555 pipe->w_counter++;
62556 - if (pipe->readers == 1 || pipe->writers == 1)
62557 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62558 wake_up_partner(pipe);
62559 break;
62560
62561 @@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62562 return 0;
62563
62564 err_rd:
62565 - if (!--pipe->readers)
62566 + if (atomic_dec_and_test(&pipe->readers))
62567 wake_up_interruptible(&pipe->wait);
62568 ret = -ERESTARTSYS;
62569 goto err;
62570
62571 err_wr:
62572 - if (!--pipe->writers)
62573 + if (atomic_dec_and_test(&pipe->writers))
62574 wake_up_interruptible(&pipe->wait);
62575 ret = -ERESTARTSYS;
62576 goto err;
62577 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62578 index 11c54fd..eef5f0b 100644
62579 --- a/fs/posix_acl.c
62580 +++ b/fs/posix_acl.c
62581 @@ -20,6 +20,7 @@
62582 #include <linux/xattr.h>
62583 #include <linux/export.h>
62584 #include <linux/user_namespace.h>
62585 +#include <linux/grsecurity.h>
62586
62587 struct posix_acl **acl_by_type(struct inode *inode, int type)
62588 {
62589 @@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62590 }
62591 }
62592 if (mode_p)
62593 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62594 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62595 return not_equiv;
62596 }
62597 EXPORT_SYMBOL(posix_acl_equiv_mode);
62598 @@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62599 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62600 }
62601
62602 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62603 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62604 return not_equiv;
62605 }
62606
62607 @@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62608 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62609 int err = -ENOMEM;
62610 if (clone) {
62611 + *mode_p &= ~gr_acl_umask();
62612 +
62613 err = posix_acl_create_masq(clone, mode_p);
62614 if (err < 0) {
62615 posix_acl_release(clone);
62616 @@ -653,11 +656,12 @@ struct posix_acl *
62617 posix_acl_from_xattr(struct user_namespace *user_ns,
62618 const void *value, size_t size)
62619 {
62620 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62621 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62622 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62623 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62624 int count;
62625 struct posix_acl *acl;
62626 struct posix_acl_entry *acl_e;
62627 + umode_t umask = gr_acl_umask();
62628
62629 if (!value)
62630 return NULL;
62631 @@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62632
62633 switch(acl_e->e_tag) {
62634 case ACL_USER_OBJ:
62635 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62636 + break;
62637 case ACL_GROUP_OBJ:
62638 case ACL_MASK:
62639 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62640 + break;
62641 case ACL_OTHER:
62642 + acl_e->e_perm &= ~(umask & S_IRWXO);
62643 break;
62644
62645 case ACL_USER:
62646 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62647 acl_e->e_uid =
62648 make_kuid(user_ns,
62649 le32_to_cpu(entry->e_id));
62650 @@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62651 goto fail;
62652 break;
62653 case ACL_GROUP:
62654 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62655 acl_e->e_gid =
62656 make_kgid(user_ns,
62657 le32_to_cpu(entry->e_id));
62658 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62659 index 2183fcf..3c32a98 100644
62660 --- a/fs/proc/Kconfig
62661 +++ b/fs/proc/Kconfig
62662 @@ -30,7 +30,7 @@ config PROC_FS
62663
62664 config PROC_KCORE
62665 bool "/proc/kcore support" if !ARM
62666 - depends on PROC_FS && MMU
62667 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62668 help
62669 Provides a virtual ELF core file of the live kernel. This can
62670 be read with gdb and other ELF tools. No modifications can be
62671 @@ -38,8 +38,8 @@ config PROC_KCORE
62672
62673 config PROC_VMCORE
62674 bool "/proc/vmcore support"
62675 - depends on PROC_FS && CRASH_DUMP
62676 - default y
62677 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62678 + default n
62679 help
62680 Exports the dump image of crashed kernel in ELF format.
62681
62682 @@ -63,8 +63,8 @@ config PROC_SYSCTL
62683 limited in memory.
62684
62685 config PROC_PAGE_MONITOR
62686 - default y
62687 - depends on PROC_FS && MMU
62688 + default n
62689 + depends on PROC_FS && MMU && !GRKERNSEC
62690 bool "Enable /proc page monitoring" if EXPERT
62691 help
62692 Various /proc files exist to monitor process memory utilization:
62693 diff --git a/fs/proc/array.c b/fs/proc/array.c
62694 index 656e401..b5b86b9 100644
62695 --- a/fs/proc/array.c
62696 +++ b/fs/proc/array.c
62697 @@ -60,6 +60,7 @@
62698 #include <linux/tty.h>
62699 #include <linux/string.h>
62700 #include <linux/mman.h>
62701 +#include <linux/grsecurity.h>
62702 #include <linux/proc_fs.h>
62703 #include <linux/ioport.h>
62704 #include <linux/uaccess.h>
62705 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
62706 seq_putc(m, '\n');
62707 }
62708
62709 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62710 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
62711 +{
62712 + if (p->mm)
62713 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
62714 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
62715 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
62716 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
62717 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
62718 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
62719 + else
62720 + seq_printf(m, "PaX:\t-----\n");
62721 +}
62722 +#endif
62723 +
62724 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62725 struct pid *pid, struct task_struct *task)
62726 {
62727 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62728 task_cpus_allowed(m, task);
62729 cpuset_task_status_allowed(m, task);
62730 task_context_switch_counts(m, task);
62731 +
62732 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62733 + task_pax(m, task);
62734 +#endif
62735 +
62736 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
62737 + task_grsec_rbac(m, task);
62738 +#endif
62739 +
62740 return 0;
62741 }
62742
62743 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62744 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62745 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62746 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62747 +#endif
62748 +
62749 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62750 struct pid *pid, struct task_struct *task, int whole)
62751 {
62752 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62753 char tcomm[sizeof(task->comm)];
62754 unsigned long flags;
62755
62756 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62757 + if (current->exec_id != m->exec_id) {
62758 + gr_log_badprocpid("stat");
62759 + return 0;
62760 + }
62761 +#endif
62762 +
62763 state = *get_task_state(task);
62764 vsize = eip = esp = 0;
62765 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62766 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62767 gtime = task_gtime(task);
62768 }
62769
62770 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62771 + if (PAX_RAND_FLAGS(mm)) {
62772 + eip = 0;
62773 + esp = 0;
62774 + wchan = 0;
62775 + }
62776 +#endif
62777 +#ifdef CONFIG_GRKERNSEC_HIDESYM
62778 + wchan = 0;
62779 + eip =0;
62780 + esp =0;
62781 +#endif
62782 +
62783 /* scale priority and nice values from timeslices to -20..20 */
62784 /* to make it look like a "normal" Unix priority/nice value */
62785 priority = task_prio(task);
62786 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62787 seq_put_decimal_ull(m, ' ', vsize);
62788 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
62789 seq_put_decimal_ull(m, ' ', rsslim);
62790 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62791 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
62792 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
62793 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
62794 +#else
62795 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
62796 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
62797 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
62798 +#endif
62799 seq_put_decimal_ull(m, ' ', esp);
62800 seq_put_decimal_ull(m, ' ', eip);
62801 /* The signal information here is obsolete.
62802 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62803 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
62804 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
62805
62806 - if (mm && permitted) {
62807 + if (mm && permitted
62808 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62809 + && !PAX_RAND_FLAGS(mm)
62810 +#endif
62811 + ) {
62812 seq_put_decimal_ull(m, ' ', mm->start_data);
62813 seq_put_decimal_ull(m, ' ', mm->end_data);
62814 seq_put_decimal_ull(m, ' ', mm->start_brk);
62815 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62816 struct pid *pid, struct task_struct *task)
62817 {
62818 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
62819 - struct mm_struct *mm = get_task_mm(task);
62820 + struct mm_struct *mm;
62821
62822 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62823 + if (current->exec_id != m->exec_id) {
62824 + gr_log_badprocpid("statm");
62825 + return 0;
62826 + }
62827 +#endif
62828 + mm = get_task_mm(task);
62829 if (mm) {
62830 size = task_statm(mm, &shared, &text, &data, &resident);
62831 mmput(mm);
62832 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62833 return 0;
62834 }
62835
62836 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62837 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
62838 +{
62839 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
62840 +}
62841 +#endif
62842 +
62843 #ifdef CONFIG_CHECKPOINT_RESTORE
62844 static struct pid *
62845 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
62846 diff --git a/fs/proc/base.c b/fs/proc/base.c
62847 index b976062..584d0bc 100644
62848 --- a/fs/proc/base.c
62849 +++ b/fs/proc/base.c
62850 @@ -113,6 +113,14 @@ struct pid_entry {
62851 union proc_op op;
62852 };
62853
62854 +struct getdents_callback {
62855 + struct linux_dirent __user * current_dir;
62856 + struct linux_dirent __user * previous;
62857 + struct file * file;
62858 + int count;
62859 + int error;
62860 +};
62861 +
62862 #define NOD(NAME, MODE, IOP, FOP, OP) { \
62863 .name = (NAME), \
62864 .len = sizeof(NAME) - 1, \
62865 @@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
62866 if (!mm->arg_end)
62867 goto out_mm; /* Shh! No looking before we're done */
62868
62869 + if (gr_acl_handle_procpidmem(task))
62870 + goto out_mm;
62871 +
62872 len = mm->arg_end - mm->arg_start;
62873
62874 if (len > PAGE_SIZE)
62875 @@ -237,12 +248,28 @@ out:
62876 return res;
62877 }
62878
62879 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62880 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62881 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62882 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62883 +#endif
62884 +
62885 static int proc_pid_auxv(struct task_struct *task, char *buffer)
62886 {
62887 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
62888 int res = PTR_ERR(mm);
62889 if (mm && !IS_ERR(mm)) {
62890 unsigned int nwords = 0;
62891 +
62892 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62893 + /* allow if we're currently ptracing this task */
62894 + if (PAX_RAND_FLAGS(mm) &&
62895 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
62896 + mmput(mm);
62897 + return 0;
62898 + }
62899 +#endif
62900 +
62901 do {
62902 nwords += 2;
62903 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
62904 @@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
62905 }
62906
62907
62908 -#ifdef CONFIG_KALLSYMS
62909 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62910 /*
62911 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
62912 * Returns the resolved symbol. If that fails, simply return the address.
62913 @@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
62914 mutex_unlock(&task->signal->cred_guard_mutex);
62915 }
62916
62917 -#ifdef CONFIG_STACKTRACE
62918 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62919
62920 #define MAX_STACK_TRACE_DEPTH 64
62921
62922 @@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
62923 return count;
62924 }
62925
62926 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62927 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62928 static int proc_pid_syscall(struct task_struct *task, char *buffer)
62929 {
62930 long nr;
62931 @@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
62932 /************************************************************************/
62933
62934 /* permission checks */
62935 -static int proc_fd_access_allowed(struct inode *inode)
62936 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
62937 {
62938 struct task_struct *task;
62939 int allowed = 0;
62940 @@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
62941 */
62942 task = get_proc_task(inode);
62943 if (task) {
62944 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62945 + if (log)
62946 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62947 + else
62948 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62949 put_task_struct(task);
62950 }
62951 return allowed;
62952 @@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
62953 struct task_struct *task,
62954 int hide_pid_min)
62955 {
62956 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62957 + return false;
62958 +
62959 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62960 + rcu_read_lock();
62961 + {
62962 + const struct cred *tmpcred = current_cred();
62963 + const struct cred *cred = __task_cred(task);
62964 +
62965 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
62966 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62967 + || in_group_p(grsec_proc_gid)
62968 +#endif
62969 + ) {
62970 + rcu_read_unlock();
62971 + return true;
62972 + }
62973 + }
62974 + rcu_read_unlock();
62975 +
62976 + if (!pid->hide_pid)
62977 + return false;
62978 +#endif
62979 +
62980 if (pid->hide_pid < hide_pid_min)
62981 return true;
62982 if (in_group_p(pid->pid_gid))
62983 return true;
62984 +
62985 return ptrace_may_access(task, PTRACE_MODE_READ);
62986 }
62987
62988 @@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
62989 put_task_struct(task);
62990
62991 if (!has_perms) {
62992 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62993 + {
62994 +#else
62995 if (pid->hide_pid == 2) {
62996 +#endif
62997 /*
62998 * Let's make getdents(), stat(), and open()
62999 * consistent with each other. If a process
63000 @@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63001 if (!task)
63002 return -ESRCH;
63003
63004 + if (gr_acl_handle_procpidmem(task)) {
63005 + put_task_struct(task);
63006 + return -EPERM;
63007 + }
63008 +
63009 mm = mm_access(task, mode);
63010 put_task_struct(task);
63011
63012 @@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63013
63014 file->private_data = mm;
63015
63016 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63017 + file->f_version = current->exec_id;
63018 +#endif
63019 +
63020 return 0;
63021 }
63022
63023 @@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63024 ssize_t copied;
63025 char *page;
63026
63027 +#ifdef CONFIG_GRKERNSEC
63028 + if (write)
63029 + return -EPERM;
63030 +#endif
63031 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63032 + if (file->f_version != current->exec_id) {
63033 + gr_log_badprocpid("mem");
63034 + return 0;
63035 + }
63036 +#endif
63037 +
63038 if (!mm)
63039 return 0;
63040
63041 @@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63042 goto free;
63043
63044 while (count > 0) {
63045 - int this_len = min_t(int, count, PAGE_SIZE);
63046 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63047
63048 if (write && copy_from_user(page, buf, this_len)) {
63049 copied = -EFAULT;
63050 @@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63051 if (!mm)
63052 return 0;
63053
63054 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63055 + if (file->f_version != current->exec_id) {
63056 + gr_log_badprocpid("environ");
63057 + return 0;
63058 + }
63059 +#endif
63060 +
63061 page = (char *)__get_free_page(GFP_TEMPORARY);
63062 if (!page)
63063 return -ENOMEM;
63064 @@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63065 goto free;
63066 while (count > 0) {
63067 size_t this_len, max_len;
63068 - int retval;
63069 + ssize_t retval;
63070
63071 if (src >= (mm->env_end - mm->env_start))
63072 break;
63073 @@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63074 int error = -EACCES;
63075
63076 /* Are we allowed to snoop on the tasks file descriptors? */
63077 - if (!proc_fd_access_allowed(inode))
63078 + if (!proc_fd_access_allowed(inode, 0))
63079 goto out;
63080
63081 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63082 @@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63083 struct path path;
63084
63085 /* Are we allowed to snoop on the tasks file descriptors? */
63086 - if (!proc_fd_access_allowed(inode))
63087 - goto out;
63088 + /* logging this is needed for learning on chromium to work properly,
63089 + but we don't want to flood the logs from 'ps' which does a readlink
63090 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63091 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
63092 + */
63093 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63094 + if (!proc_fd_access_allowed(inode,0))
63095 + goto out;
63096 + } else {
63097 + if (!proc_fd_access_allowed(inode,1))
63098 + goto out;
63099 + }
63100
63101 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63102 if (error)
63103 @@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63104 rcu_read_lock();
63105 cred = __task_cred(task);
63106 inode->i_uid = cred->euid;
63107 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63108 + inode->i_gid = grsec_proc_gid;
63109 +#else
63110 inode->i_gid = cred->egid;
63111 +#endif
63112 rcu_read_unlock();
63113 }
63114 security_task_to_inode(task, inode);
63115 @@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63116 return -ENOENT;
63117 }
63118 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63119 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63120 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63121 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63122 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63123 +#endif
63124 task_dumpable(task)) {
63125 cred = __task_cred(task);
63126 stat->uid = cred->euid;
63127 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63128 + stat->gid = grsec_proc_gid;
63129 +#else
63130 stat->gid = cred->egid;
63131 +#endif
63132 }
63133 }
63134 rcu_read_unlock();
63135 @@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63136
63137 if (task) {
63138 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63139 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63140 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63141 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63142 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63143 +#endif
63144 task_dumpable(task)) {
63145 rcu_read_lock();
63146 cred = __task_cred(task);
63147 inode->i_uid = cred->euid;
63148 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63149 + inode->i_gid = grsec_proc_gid;
63150 +#else
63151 inode->i_gid = cred->egid;
63152 +#endif
63153 rcu_read_unlock();
63154 } else {
63155 inode->i_uid = GLOBAL_ROOT_UID;
63156 @@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63157 if (!task)
63158 goto out_no_task;
63159
63160 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63161 + goto out;
63162 +
63163 /*
63164 * Yes, it does not scale. And it should not. Don't add
63165 * new entries into /proc/<tgid>/ without very good reasons.
63166 @@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63167 if (!task)
63168 return -ENOENT;
63169
63170 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63171 + goto out;
63172 +
63173 if (!dir_emit_dots(file, ctx))
63174 goto out;
63175
63176 @@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63177 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63178 #endif
63179 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63180 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63181 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63182 INF("syscall", S_IRUGO, proc_pid_syscall),
63183 #endif
63184 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63185 @@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63186 #ifdef CONFIG_SECURITY
63187 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63188 #endif
63189 -#ifdef CONFIG_KALLSYMS
63190 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63191 INF("wchan", S_IRUGO, proc_pid_wchan),
63192 #endif
63193 -#ifdef CONFIG_STACKTRACE
63194 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63195 ONE("stack", S_IRUGO, proc_pid_stack),
63196 #endif
63197 #ifdef CONFIG_SCHEDSTATS
63198 @@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63199 #ifdef CONFIG_HARDWALL
63200 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63201 #endif
63202 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63203 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63204 +#endif
63205 #ifdef CONFIG_USER_NS
63206 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63207 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63208 @@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
63209 if (!inode)
63210 goto out;
63211
63212 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63213 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63214 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63215 + inode->i_gid = grsec_proc_gid;
63216 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63217 +#else
63218 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63219 +#endif
63220 inode->i_op = &proc_tgid_base_inode_operations;
63221 inode->i_fop = &proc_tgid_base_operations;
63222 inode->i_flags|=S_IMMUTABLE;
63223 @@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63224 if (!task)
63225 goto out;
63226
63227 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63228 + goto out_put_task;
63229 +
63230 result = proc_pid_instantiate(dir, dentry, task, NULL);
63231 +out_put_task:
63232 put_task_struct(task);
63233 out:
63234 return ERR_PTR(result);
63235 @@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
63236 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63237 #endif
63238 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63239 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63240 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63241 INF("syscall", S_IRUGO, proc_pid_syscall),
63242 #endif
63243 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63244 @@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
63245 #ifdef CONFIG_SECURITY
63246 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63247 #endif
63248 -#ifdef CONFIG_KALLSYMS
63249 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63250 INF("wchan", S_IRUGO, proc_pid_wchan),
63251 #endif
63252 -#ifdef CONFIG_STACKTRACE
63253 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63254 ONE("stack", S_IRUGO, proc_pid_stack),
63255 #endif
63256 #ifdef CONFIG_SCHEDSTATS
63257 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63258 index cbd82df..c0407d2 100644
63259 --- a/fs/proc/cmdline.c
63260 +++ b/fs/proc/cmdline.c
63261 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63262
63263 static int __init proc_cmdline_init(void)
63264 {
63265 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63266 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63267 +#else
63268 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63269 +#endif
63270 return 0;
63271 }
63272 fs_initcall(proc_cmdline_init);
63273 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63274 index 50493ed..248166b 100644
63275 --- a/fs/proc/devices.c
63276 +++ b/fs/proc/devices.c
63277 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63278
63279 static int __init proc_devices_init(void)
63280 {
63281 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63282 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63283 +#else
63284 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63285 +#endif
63286 return 0;
63287 }
63288 fs_initcall(proc_devices_init);
63289 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63290 index 985ea88..d118a0a 100644
63291 --- a/fs/proc/fd.c
63292 +++ b/fs/proc/fd.c
63293 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63294 if (!task)
63295 return -ENOENT;
63296
63297 - files = get_files_struct(task);
63298 + if (!gr_acl_handle_procpidmem(task))
63299 + files = get_files_struct(task);
63300 put_task_struct(task);
63301
63302 if (files) {
63303 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63304 */
63305 int proc_fd_permission(struct inode *inode, int mask)
63306 {
63307 + struct task_struct *task;
63308 int rv = generic_permission(inode, mask);
63309 - if (rv == 0)
63310 - return 0;
63311 +
63312 if (task_tgid(current) == proc_pid(inode))
63313 rv = 0;
63314 +
63315 + task = get_proc_task(inode);
63316 + if (task == NULL)
63317 + return rv;
63318 +
63319 + if (gr_acl_handle_procpidmem(task))
63320 + rv = -EACCES;
63321 +
63322 + put_task_struct(task);
63323 +
63324 return rv;
63325 }
63326
63327 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63328 index 124fc43..8afbb02 100644
63329 --- a/fs/proc/inode.c
63330 +++ b/fs/proc/inode.c
63331 @@ -23,11 +23,17 @@
63332 #include <linux/slab.h>
63333 #include <linux/mount.h>
63334 #include <linux/magic.h>
63335 +#include <linux/grsecurity.h>
63336
63337 #include <asm/uaccess.h>
63338
63339 #include "internal.h"
63340
63341 +#ifdef CONFIG_PROC_SYSCTL
63342 +extern const struct inode_operations proc_sys_inode_operations;
63343 +extern const struct inode_operations proc_sys_dir_operations;
63344 +#endif
63345 +
63346 static void proc_evict_inode(struct inode *inode)
63347 {
63348 struct proc_dir_entry *de;
63349 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63350 ns = PROC_I(inode)->ns.ns;
63351 if (ns_ops && ns)
63352 ns_ops->put(ns);
63353 +
63354 +#ifdef CONFIG_PROC_SYSCTL
63355 + if (inode->i_op == &proc_sys_inode_operations ||
63356 + inode->i_op == &proc_sys_dir_operations)
63357 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63358 +#endif
63359 +
63360 }
63361
63362 static struct kmem_cache * proc_inode_cachep;
63363 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63364 if (de->mode) {
63365 inode->i_mode = de->mode;
63366 inode->i_uid = de->uid;
63367 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63368 + inode->i_gid = grsec_proc_gid;
63369 +#else
63370 inode->i_gid = de->gid;
63371 +#endif
63372 }
63373 if (de->size)
63374 inode->i_size = de->size;
63375 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63376 index 651d09a..3d7f0bf 100644
63377 --- a/fs/proc/internal.h
63378 +++ b/fs/proc/internal.h
63379 @@ -48,7 +48,7 @@ struct proc_dir_entry {
63380 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63381 u8 namelen;
63382 char name[];
63383 -};
63384 +} __randomize_layout;
63385
63386 union proc_op {
63387 int (*proc_get_link)(struct dentry *, struct path *);
63388 @@ -67,7 +67,7 @@ struct proc_inode {
63389 struct ctl_table *sysctl_entry;
63390 struct proc_ns ns;
63391 struct inode vfs_inode;
63392 -};
63393 +} __randomize_layout;
63394
63395 /*
63396 * General functions
63397 @@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63398 struct pid *, struct task_struct *);
63399 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63400 struct pid *, struct task_struct *);
63401 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63402 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63403 +#endif
63404
63405 /*
63406 * base.c
63407 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63408 index a352d57..cb94a5c 100644
63409 --- a/fs/proc/interrupts.c
63410 +++ b/fs/proc/interrupts.c
63411 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63412
63413 static int __init proc_interrupts_init(void)
63414 {
63415 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63416 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63417 +#else
63418 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63419 +#endif
63420 return 0;
63421 }
63422 fs_initcall(proc_interrupts_init);
63423 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63424 index 39e6ef3..2f9cb5e 100644
63425 --- a/fs/proc/kcore.c
63426 +++ b/fs/proc/kcore.c
63427 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63428 * the addresses in the elf_phdr on our list.
63429 */
63430 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63431 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63432 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63433 + if (tsz > buflen)
63434 tsz = buflen;
63435 -
63436 +
63437 while (buflen) {
63438 struct kcore_list *m;
63439
63440 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63441 kfree(elf_buf);
63442 } else {
63443 if (kern_addr_valid(start)) {
63444 - unsigned long n;
63445 + char *elf_buf;
63446 + mm_segment_t oldfs;
63447
63448 - n = copy_to_user(buffer, (char *)start, tsz);
63449 - /*
63450 - * We cannot distinguish between fault on source
63451 - * and fault on destination. When this happens
63452 - * we clear too and hope it will trigger the
63453 - * EFAULT again.
63454 - */
63455 - if (n) {
63456 - if (clear_user(buffer + tsz - n,
63457 - n))
63458 + elf_buf = kmalloc(tsz, GFP_KERNEL);
63459 + if (!elf_buf)
63460 + return -ENOMEM;
63461 + oldfs = get_fs();
63462 + set_fs(KERNEL_DS);
63463 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63464 + set_fs(oldfs);
63465 + if (copy_to_user(buffer, elf_buf, tsz)) {
63466 + kfree(elf_buf);
63467 return -EFAULT;
63468 + }
63469 }
63470 + set_fs(oldfs);
63471 + kfree(elf_buf);
63472 } else {
63473 if (clear_user(buffer, tsz))
63474 return -EFAULT;
63475 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63476
63477 static int open_kcore(struct inode *inode, struct file *filp)
63478 {
63479 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63480 + return -EPERM;
63481 +#endif
63482 if (!capable(CAP_SYS_RAWIO))
63483 return -EPERM;
63484 if (kcore_need_update)
63485 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63486 index 136e548..1f88922 100644
63487 --- a/fs/proc/meminfo.c
63488 +++ b/fs/proc/meminfo.c
63489 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63490 vmi.used >> 10,
63491 vmi.largest_chunk >> 10
63492 #ifdef CONFIG_MEMORY_FAILURE
63493 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63494 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63495 #endif
63496 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63497 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63498 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63499 index d4a3574..b421ce9 100644
63500 --- a/fs/proc/nommu.c
63501 +++ b/fs/proc/nommu.c
63502 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63503
63504 if (file) {
63505 seq_pad(m, ' ');
63506 - seq_path(m, &file->f_path, "");
63507 + seq_path(m, &file->f_path, "\n\\");
63508 }
63509
63510 seq_putc(m, '\n');
63511 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63512 index 4677bb7..408e936 100644
63513 --- a/fs/proc/proc_net.c
63514 +++ b/fs/proc/proc_net.c
63515 @@ -23,6 +23,7 @@
63516 #include <linux/nsproxy.h>
63517 #include <net/net_namespace.h>
63518 #include <linux/seq_file.h>
63519 +#include <linux/grsecurity.h>
63520
63521 #include "internal.h"
63522
63523 @@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
63524 struct task_struct *task;
63525 struct nsproxy *ns;
63526 struct net *net = NULL;
63527 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63528 + const struct cred *cred = current_cred();
63529 +#endif
63530 +
63531 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63532 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
63533 + return net;
63534 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63535 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
63536 + return net;
63537 +#endif
63538
63539 rcu_read_lock();
63540 task = pid_task(proc_pid(dir), PIDTYPE_PID);
63541 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
63542 index 7129046..6914844 100644
63543 --- a/fs/proc/proc_sysctl.c
63544 +++ b/fs/proc/proc_sysctl.c
63545 @@ -11,13 +11,21 @@
63546 #include <linux/namei.h>
63547 #include <linux/mm.h>
63548 #include <linux/module.h>
63549 +#include <linux/nsproxy.h>
63550 +#ifdef CONFIG_GRKERNSEC
63551 +#include <net/net_namespace.h>
63552 +#endif
63553 #include "internal.h"
63554
63555 +extern int gr_handle_chroot_sysctl(const int op);
63556 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
63557 + const int op);
63558 +
63559 static const struct dentry_operations proc_sys_dentry_operations;
63560 static const struct file_operations proc_sys_file_operations;
63561 -static const struct inode_operations proc_sys_inode_operations;
63562 +const struct inode_operations proc_sys_inode_operations;
63563 static const struct file_operations proc_sys_dir_file_operations;
63564 -static const struct inode_operations proc_sys_dir_operations;
63565 +const struct inode_operations proc_sys_dir_operations;
63566
63567 void proc_sys_poll_notify(struct ctl_table_poll *poll)
63568 {
63569 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
63570
63571 err = NULL;
63572 d_set_d_op(dentry, &proc_sys_dentry_operations);
63573 +
63574 + gr_handle_proc_create(dentry, inode);
63575 +
63576 d_add(dentry, inode);
63577
63578 out:
63579 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63580 struct inode *inode = file_inode(filp);
63581 struct ctl_table_header *head = grab_header(inode);
63582 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
63583 + int op = write ? MAY_WRITE : MAY_READ;
63584 ssize_t error;
63585 size_t res;
63586
63587 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63588 * and won't be until we finish.
63589 */
63590 error = -EPERM;
63591 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
63592 + if (sysctl_perm(head, table, op))
63593 goto out;
63594
63595 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
63596 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63597 if (!table->proc_handler)
63598 goto out;
63599
63600 +#ifdef CONFIG_GRKERNSEC
63601 + error = -EPERM;
63602 + if (gr_handle_chroot_sysctl(op))
63603 + goto out;
63604 + dget(filp->f_path.dentry);
63605 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
63606 + dput(filp->f_path.dentry);
63607 + goto out;
63608 + }
63609 + dput(filp->f_path.dentry);
63610 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
63611 + goto out;
63612 + if (write) {
63613 + if (current->nsproxy->net_ns != table->extra2) {
63614 + if (!capable(CAP_SYS_ADMIN))
63615 + goto out;
63616 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
63617 + goto out;
63618 + }
63619 +#endif
63620 +
63621 /* careful: calling conventions are nasty here */
63622 res = count;
63623 error = table->proc_handler(table, write, buf, &res, ppos);
63624 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
63625 return false;
63626 } else {
63627 d_set_d_op(child, &proc_sys_dentry_operations);
63628 +
63629 + gr_handle_proc_create(child, inode);
63630 +
63631 d_add(child, inode);
63632 }
63633 } else {
63634 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
63635 if ((*pos)++ < ctx->pos)
63636 return true;
63637
63638 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
63639 + return 0;
63640 +
63641 if (unlikely(S_ISLNK(table->mode)))
63642 res = proc_sys_link_fill_cache(file, ctx, head, table);
63643 else
63644 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
63645 if (IS_ERR(head))
63646 return PTR_ERR(head);
63647
63648 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
63649 + return -ENOENT;
63650 +
63651 generic_fillattr(inode, stat);
63652 if (table)
63653 stat->mode = (stat->mode & S_IFMT) | table->mode;
63654 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
63655 .llseek = generic_file_llseek,
63656 };
63657
63658 -static const struct inode_operations proc_sys_inode_operations = {
63659 +const struct inode_operations proc_sys_inode_operations = {
63660 .permission = proc_sys_permission,
63661 .setattr = proc_sys_setattr,
63662 .getattr = proc_sys_getattr,
63663 };
63664
63665 -static const struct inode_operations proc_sys_dir_operations = {
63666 +const struct inode_operations proc_sys_dir_operations = {
63667 .lookup = proc_sys_lookup,
63668 .permission = proc_sys_permission,
63669 .setattr = proc_sys_setattr,
63670 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
63671 static struct ctl_dir *new_dir(struct ctl_table_set *set,
63672 const char *name, int namelen)
63673 {
63674 - struct ctl_table *table;
63675 + ctl_table_no_const *table;
63676 struct ctl_dir *new;
63677 struct ctl_node *node;
63678 char *new_name;
63679 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
63680 return NULL;
63681
63682 node = (struct ctl_node *)(new + 1);
63683 - table = (struct ctl_table *)(node + 1);
63684 + table = (ctl_table_no_const *)(node + 1);
63685 new_name = (char *)(table + 2);
63686 memcpy(new_name, name, namelen);
63687 new_name[namelen] = '\0';
63688 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
63689 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
63690 struct ctl_table_root *link_root)
63691 {
63692 - struct ctl_table *link_table, *entry, *link;
63693 + ctl_table_no_const *link_table, *link;
63694 + struct ctl_table *entry;
63695 struct ctl_table_header *links;
63696 struct ctl_node *node;
63697 char *link_name;
63698 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
63699 return NULL;
63700
63701 node = (struct ctl_node *)(links + 1);
63702 - link_table = (struct ctl_table *)(node + nr_entries);
63703 + link_table = (ctl_table_no_const *)(node + nr_entries);
63704 link_name = (char *)&link_table[nr_entries + 1];
63705
63706 for (link = link_table, entry = table; entry->procname; link++, entry++) {
63707 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63708 struct ctl_table_header ***subheader, struct ctl_table_set *set,
63709 struct ctl_table *table)
63710 {
63711 - struct ctl_table *ctl_table_arg = NULL;
63712 - struct ctl_table *entry, *files;
63713 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
63714 + struct ctl_table *entry;
63715 int nr_files = 0;
63716 int nr_dirs = 0;
63717 int err = -ENOMEM;
63718 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63719 nr_files++;
63720 }
63721
63722 - files = table;
63723 /* If there are mixed files and directories we need a new table */
63724 if (nr_dirs && nr_files) {
63725 - struct ctl_table *new;
63726 + ctl_table_no_const *new;
63727 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
63728 GFP_KERNEL);
63729 if (!files)
63730 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63731 /* Register everything except a directory full of subdirectories */
63732 if (nr_files || !nr_dirs) {
63733 struct ctl_table_header *header;
63734 - header = __register_sysctl_table(set, path, files);
63735 + header = __register_sysctl_table(set, path, files ? files : table);
63736 if (!header) {
63737 kfree(ctl_table_arg);
63738 goto out;
63739 diff --git a/fs/proc/root.c b/fs/proc/root.c
63740 index 87dbcbe..55e1b4d 100644
63741 --- a/fs/proc/root.c
63742 +++ b/fs/proc/root.c
63743 @@ -186,7 +186,15 @@ void __init proc_root_init(void)
63744 #ifdef CONFIG_PROC_DEVICETREE
63745 proc_device_tree_init();
63746 #endif
63747 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63748 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63749 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
63750 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63751 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
63752 +#endif
63753 +#else
63754 proc_mkdir("bus", NULL);
63755 +#endif
63756 proc_sys_init();
63757 }
63758
63759 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
63760 index 6f599c6..8f4644f 100644
63761 --- a/fs/proc/stat.c
63762 +++ b/fs/proc/stat.c
63763 @@ -11,6 +11,7 @@
63764 #include <linux/irqnr.h>
63765 #include <asm/cputime.h>
63766 #include <linux/tick.h>
63767 +#include <linux/grsecurity.h>
63768
63769 #ifndef arch_irq_stat_cpu
63770 #define arch_irq_stat_cpu(cpu) 0
63771 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
63772 u64 sum_softirq = 0;
63773 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
63774 struct timespec boottime;
63775 + int unrestricted = 1;
63776 +
63777 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63778 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63779 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
63780 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63781 + && !in_group_p(grsec_proc_gid)
63782 +#endif
63783 + )
63784 + unrestricted = 0;
63785 +#endif
63786 +#endif
63787
63788 user = nice = system = idle = iowait =
63789 irq = softirq = steal = 0;
63790 @@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
63791 getboottime(&boottime);
63792 jif = boottime.tv_sec;
63793
63794 + if (unrestricted) {
63795 for_each_possible_cpu(i) {
63796 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
63797 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63798 @@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
63799 }
63800 }
63801 sum += arch_irq_stat();
63802 + }
63803
63804 seq_puts(p, "cpu ");
63805 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63806 @@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
63807 seq_putc(p, '\n');
63808
63809 for_each_online_cpu(i) {
63810 + if (unrestricted) {
63811 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
63812 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
63813 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63814 @@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
63815 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
63816 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
63817 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
63818 + }
63819 seq_printf(p, "cpu%d", i);
63820 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63821 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
63822 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
63823
63824 /* sum again ? it could be updated? */
63825 for_each_irq_nr(j)
63826 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
63827 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
63828
63829 seq_printf(p,
63830 "\nctxt %llu\n"
63831 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
63832 "processes %lu\n"
63833 "procs_running %lu\n"
63834 "procs_blocked %lu\n",
63835 - nr_context_switches(),
63836 + unrestricted ? nr_context_switches() : 0ULL,
63837 (unsigned long)jif,
63838 - total_forks,
63839 - nr_running(),
63840 - nr_iowait());
63841 + unrestricted ? total_forks : 0UL,
63842 + unrestricted ? nr_running() : 0UL,
63843 + unrestricted ? nr_iowait() : 0UL);
63844
63845 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
63846
63847 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
63848 index fb52b54..5fc7c14 100644
63849 --- a/fs/proc/task_mmu.c
63850 +++ b/fs/proc/task_mmu.c
63851 @@ -12,12 +12,19 @@
63852 #include <linux/swap.h>
63853 #include <linux/swapops.h>
63854 #include <linux/mmu_notifier.h>
63855 +#include <linux/grsecurity.h>
63856
63857 #include <asm/elf.h>
63858 #include <asm/uaccess.h>
63859 #include <asm/tlbflush.h>
63860 #include "internal.h"
63861
63862 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63863 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63864 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63865 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63866 +#endif
63867 +
63868 void task_mem(struct seq_file *m, struct mm_struct *mm)
63869 {
63870 unsigned long data, text, lib, swap;
63871 @@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63872 "VmExe:\t%8lu kB\n"
63873 "VmLib:\t%8lu kB\n"
63874 "VmPTE:\t%8lu kB\n"
63875 - "VmSwap:\t%8lu kB\n",
63876 - hiwater_vm << (PAGE_SHIFT-10),
63877 + "VmSwap:\t%8lu kB\n"
63878 +
63879 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63880 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
63881 +#endif
63882 +
63883 + ,hiwater_vm << (PAGE_SHIFT-10),
63884 total_vm << (PAGE_SHIFT-10),
63885 mm->locked_vm << (PAGE_SHIFT-10),
63886 mm->pinned_vm << (PAGE_SHIFT-10),
63887 @@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63888 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
63889 (PTRS_PER_PTE * sizeof(pte_t) *
63890 atomic_long_read(&mm->nr_ptes)) >> 10,
63891 - swap << (PAGE_SHIFT-10));
63892 + swap << (PAGE_SHIFT-10)
63893 +
63894 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63895 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63896 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
63897 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
63898 +#else
63899 + , mm->context.user_cs_base
63900 + , mm->context.user_cs_limit
63901 +#endif
63902 +#endif
63903 +
63904 + );
63905 }
63906
63907 unsigned long task_vsize(struct mm_struct *mm)
63908 @@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63909 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
63910 }
63911
63912 - /* We don't show the stack guard page in /proc/maps */
63913 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63914 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
63915 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
63916 +#else
63917 start = vma->vm_start;
63918 - if (stack_guard_page_start(vma, start))
63919 - start += PAGE_SIZE;
63920 end = vma->vm_end;
63921 - if (stack_guard_page_end(vma, end))
63922 - end -= PAGE_SIZE;
63923 +#endif
63924
63925 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
63926 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
63927 @@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63928 flags & VM_WRITE ? 'w' : '-',
63929 flags & VM_EXEC ? 'x' : '-',
63930 flags & VM_MAYSHARE ? 's' : 'p',
63931 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63932 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
63933 +#else
63934 pgoff,
63935 +#endif
63936 MAJOR(dev), MINOR(dev), ino);
63937
63938 /*
63939 @@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63940 */
63941 if (file) {
63942 seq_pad(m, ' ');
63943 - seq_path(m, &file->f_path, "\n");
63944 + seq_path(m, &file->f_path, "\n\\");
63945 goto done;
63946 }
63947
63948 @@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63949 * Thread stack in /proc/PID/task/TID/maps or
63950 * the main process stack.
63951 */
63952 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
63953 - vma->vm_end >= mm->start_stack)) {
63954 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
63955 + (vma->vm_start <= mm->start_stack &&
63956 + vma->vm_end >= mm->start_stack)) {
63957 name = "[stack]";
63958 } else {
63959 /* Thread stack in /proc/PID/maps */
63960 @@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
63961 struct proc_maps_private *priv = m->private;
63962 struct task_struct *task = priv->task;
63963
63964 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63965 + if (current->exec_id != m->exec_id) {
63966 + gr_log_badprocpid("maps");
63967 + return 0;
63968 + }
63969 +#endif
63970 +
63971 show_map_vma(m, vma, is_pid);
63972
63973 if (m->count < m->size) /* vma is copied successfully */
63974 @@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63975 .private = &mss,
63976 };
63977
63978 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63979 + if (current->exec_id != m->exec_id) {
63980 + gr_log_badprocpid("smaps");
63981 + return 0;
63982 + }
63983 +#endif
63984 memset(&mss, 0, sizeof mss);
63985 - mss.vma = vma;
63986 - /* mmap_sem is held in m_start */
63987 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63988 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63989 -
63990 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63991 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
63992 +#endif
63993 + mss.vma = vma;
63994 + /* mmap_sem is held in m_start */
63995 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63996 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63997 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63998 + }
63999 +#endif
64000 show_map_vma(m, vma, is_pid);
64001
64002 seq_printf(m,
64003 @@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64004 "KernelPageSize: %8lu kB\n"
64005 "MMUPageSize: %8lu kB\n"
64006 "Locked: %8lu kB\n",
64007 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64008 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64009 +#else
64010 (vma->vm_end - vma->vm_start) >> 10,
64011 +#endif
64012 mss.resident >> 10,
64013 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64014 mss.shared_clean >> 10,
64015 @@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64016 char buffer[64];
64017 int nid;
64018
64019 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64020 + if (current->exec_id != m->exec_id) {
64021 + gr_log_badprocpid("numa_maps");
64022 + return 0;
64023 + }
64024 +#endif
64025 +
64026 if (!mm)
64027 return 0;
64028
64029 @@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64030 mpol_to_str(buffer, sizeof(buffer), pol);
64031 mpol_cond_put(pol);
64032
64033 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64034 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64035 +#else
64036 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64037 +#endif
64038
64039 if (file) {
64040 seq_printf(m, " file=");
64041 - seq_path(m, &file->f_path, "\n\t= ");
64042 + seq_path(m, &file->f_path, "\n\t\\= ");
64043 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64044 seq_printf(m, " heap");
64045 } else {
64046 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64047 index 678455d..ebd3245 100644
64048 --- a/fs/proc/task_nommu.c
64049 +++ b/fs/proc/task_nommu.c
64050 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64051 else
64052 bytes += kobjsize(mm);
64053
64054 - if (current->fs && current->fs->users > 1)
64055 + if (current->fs && atomic_read(&current->fs->users) > 1)
64056 sbytes += kobjsize(current->fs);
64057 else
64058 bytes += kobjsize(current->fs);
64059 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64060
64061 if (file) {
64062 seq_pad(m, ' ');
64063 - seq_path(m, &file->f_path, "");
64064 + seq_path(m, &file->f_path, "\n\\");
64065 } else if (mm) {
64066 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64067
64068 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64069 index 88d4585..c10bfeb 100644
64070 --- a/fs/proc/vmcore.c
64071 +++ b/fs/proc/vmcore.c
64072 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64073 nr_bytes = count;
64074
64075 /* If pfn is not ram, return zeros for sparse dump files */
64076 - if (pfn_is_ram(pfn) == 0)
64077 - memset(buf, 0, nr_bytes);
64078 - else {
64079 + if (pfn_is_ram(pfn) == 0) {
64080 + if (userbuf) {
64081 + if (clear_user((char __force_user *)buf, nr_bytes))
64082 + return -EFAULT;
64083 + } else
64084 + memset(buf, 0, nr_bytes);
64085 + } else {
64086 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64087 offset, userbuf);
64088 if (tmp < 0)
64089 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64090 static int copy_to(void *target, void *src, size_t size, int userbuf)
64091 {
64092 if (userbuf) {
64093 - if (copy_to_user((char __user *) target, src, size))
64094 + if (copy_to_user((char __force_user *) target, src, size))
64095 return -EFAULT;
64096 } else {
64097 memcpy(target, src, size);
64098 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64099 if (*fpos < m->offset + m->size) {
64100 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64101 start = m->paddr + *fpos - m->offset;
64102 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64103 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64104 if (tmp < 0)
64105 return tmp;
64106 buflen -= tsz;
64107 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64108 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64109 size_t buflen, loff_t *fpos)
64110 {
64111 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64112 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64113 }
64114
64115 /*
64116 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64117 index b00fcc9..e0c6381 100644
64118 --- a/fs/qnx6/qnx6.h
64119 +++ b/fs/qnx6/qnx6.h
64120 @@ -74,7 +74,7 @@ enum {
64121 BYTESEX_BE,
64122 };
64123
64124 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64125 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64126 {
64127 if (sbi->s_bytesex == BYTESEX_LE)
64128 return le64_to_cpu((__force __le64)n);
64129 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64130 return (__force __fs64)cpu_to_be64(n);
64131 }
64132
64133 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64134 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64135 {
64136 if (sbi->s_bytesex == BYTESEX_LE)
64137 return le32_to_cpu((__force __le32)n);
64138 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64139 index 72d2917..c917c12 100644
64140 --- a/fs/quota/netlink.c
64141 +++ b/fs/quota/netlink.c
64142 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64143 void quota_send_warning(struct kqid qid, dev_t dev,
64144 const char warntype)
64145 {
64146 - static atomic_t seq;
64147 + static atomic_unchecked_t seq;
64148 struct sk_buff *skb;
64149 void *msg_head;
64150 int ret;
64151 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64152 "VFS: Not enough memory to send quota warning.\n");
64153 return;
64154 }
64155 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64156 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64157 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64158 if (!msg_head) {
64159 printk(KERN_ERR
64160 diff --git a/fs/read_write.c b/fs/read_write.c
64161 index 28cc9c8..208e4fb 100644
64162 --- a/fs/read_write.c
64163 +++ b/fs/read_write.c
64164 @@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64165
64166 old_fs = get_fs();
64167 set_fs(get_ds());
64168 - p = (__force const char __user *)buf;
64169 + p = (const char __force_user *)buf;
64170 if (count > MAX_RW_COUNT)
64171 count = MAX_RW_COUNT;
64172 if (file->f_op->write)
64173 diff --git a/fs/readdir.c b/fs/readdir.c
64174 index 5b53d99..a6c3049 100644
64175 --- a/fs/readdir.c
64176 +++ b/fs/readdir.c
64177 @@ -17,6 +17,7 @@
64178 #include <linux/security.h>
64179 #include <linux/syscalls.h>
64180 #include <linux/unistd.h>
64181 +#include <linux/namei.h>
64182
64183 #include <asm/uaccess.h>
64184
64185 @@ -69,6 +70,7 @@ struct old_linux_dirent {
64186 struct readdir_callback {
64187 struct dir_context ctx;
64188 struct old_linux_dirent __user * dirent;
64189 + struct file * file;
64190 int result;
64191 };
64192
64193 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64194 buf->result = -EOVERFLOW;
64195 return -EOVERFLOW;
64196 }
64197 +
64198 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64199 + return 0;
64200 +
64201 buf->result++;
64202 dirent = buf->dirent;
64203 if (!access_ok(VERIFY_WRITE, dirent,
64204 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64205 if (!f.file)
64206 return -EBADF;
64207
64208 + buf.file = f.file;
64209 error = iterate_dir(f.file, &buf.ctx);
64210 if (buf.result)
64211 error = buf.result;
64212 @@ -142,6 +149,7 @@ struct getdents_callback {
64213 struct dir_context ctx;
64214 struct linux_dirent __user * current_dir;
64215 struct linux_dirent __user * previous;
64216 + struct file * file;
64217 int count;
64218 int error;
64219 };
64220 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64221 buf->error = -EOVERFLOW;
64222 return -EOVERFLOW;
64223 }
64224 +
64225 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64226 + return 0;
64227 +
64228 dirent = buf->previous;
64229 if (dirent) {
64230 if (__put_user(offset, &dirent->d_off))
64231 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64232 if (!f.file)
64233 return -EBADF;
64234
64235 + buf.file = f.file;
64236 error = iterate_dir(f.file, &buf.ctx);
64237 if (error >= 0)
64238 error = buf.error;
64239 @@ -226,6 +239,7 @@ struct getdents_callback64 {
64240 struct dir_context ctx;
64241 struct linux_dirent64 __user * current_dir;
64242 struct linux_dirent64 __user * previous;
64243 + struct file *file;
64244 int count;
64245 int error;
64246 };
64247 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64248 buf->error = -EINVAL; /* only used if we fail.. */
64249 if (reclen > buf->count)
64250 return -EINVAL;
64251 +
64252 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64253 + return 0;
64254 +
64255 dirent = buf->previous;
64256 if (dirent) {
64257 if (__put_user(offset, &dirent->d_off))
64258 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64259 if (!f.file)
64260 return -EBADF;
64261
64262 + buf.file = f.file;
64263 error = iterate_dir(f.file, &buf.ctx);
64264 if (error >= 0)
64265 error = buf.error;
64266 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64267 index 9a3c68c..767933e 100644
64268 --- a/fs/reiserfs/do_balan.c
64269 +++ b/fs/reiserfs/do_balan.c
64270 @@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64271 return;
64272 }
64273
64274 - atomic_inc(&(fs_generation(tb->tb_sb)));
64275 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64276 do_balance_starts(tb);
64277
64278 /* balance leaf returns 0 except if combining L R and S into
64279 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64280 index ee382ef..f4eb6eb5 100644
64281 --- a/fs/reiserfs/item_ops.c
64282 +++ b/fs/reiserfs/item_ops.c
64283 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64284 }
64285
64286 static struct item_operations errcatch_ops = {
64287 - errcatch_bytes_number,
64288 - errcatch_decrement_key,
64289 - errcatch_is_left_mergeable,
64290 - errcatch_print_item,
64291 - errcatch_check_item,
64292 + .bytes_number = errcatch_bytes_number,
64293 + .decrement_key = errcatch_decrement_key,
64294 + .is_left_mergeable = errcatch_is_left_mergeable,
64295 + .print_item = errcatch_print_item,
64296 + .check_item = errcatch_check_item,
64297
64298 - errcatch_create_vi,
64299 - errcatch_check_left,
64300 - errcatch_check_right,
64301 - errcatch_part_size,
64302 - errcatch_unit_num,
64303 - errcatch_print_vi
64304 + .create_vi = errcatch_create_vi,
64305 + .check_left = errcatch_check_left,
64306 + .check_right = errcatch_check_right,
64307 + .part_size = errcatch_part_size,
64308 + .unit_num = errcatch_unit_num,
64309 + .print_vi = errcatch_print_vi
64310 };
64311
64312 //////////////////////////////////////////////////////////////////////////////
64313 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64314 index 02b0b7d..c85018b 100644
64315 --- a/fs/reiserfs/procfs.c
64316 +++ b/fs/reiserfs/procfs.c
64317 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64318 "SMALL_TAILS " : "NO_TAILS ",
64319 replay_only(sb) ? "REPLAY_ONLY " : "",
64320 convert_reiserfs(sb) ? "CONV " : "",
64321 - atomic_read(&r->s_generation_counter),
64322 + atomic_read_unchecked(&r->s_generation_counter),
64323 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64324 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64325 SF(s_good_search_by_key_reada), SF(s_bmaps),
64326 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64327 index 8d06adf..7e1c9f8 100644
64328 --- a/fs/reiserfs/reiserfs.h
64329 +++ b/fs/reiserfs/reiserfs.h
64330 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64331 /* Comment? -Hans */
64332 wait_queue_head_t s_wait;
64333 /* To be obsoleted soon by per buffer seals.. -Hans */
64334 - atomic_t s_generation_counter; // increased by one every time the
64335 + atomic_unchecked_t s_generation_counter; // increased by one every time the
64336 // tree gets re-balanced
64337 unsigned long s_properties; /* File system properties. Currently holds
64338 on-disk FS format */
64339 @@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64340 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64341
64342 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64343 -#define get_generation(s) atomic_read (&fs_generation(s))
64344 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64345 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64346 #define __fs_changed(gen,s) (gen != get_generation (s))
64347 #define fs_changed(gen,s) \
64348 diff --git a/fs/select.c b/fs/select.c
64349 index 467bb1c..cf9d65a 100644
64350 --- a/fs/select.c
64351 +++ b/fs/select.c
64352 @@ -20,6 +20,7 @@
64353 #include <linux/export.h>
64354 #include <linux/slab.h>
64355 #include <linux/poll.h>
64356 +#include <linux/security.h>
64357 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64358 #include <linux/file.h>
64359 #include <linux/fdtable.h>
64360 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64361 struct poll_list *walk = head;
64362 unsigned long todo = nfds;
64363
64364 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64365 if (nfds > rlimit(RLIMIT_NOFILE))
64366 return -EINVAL;
64367
64368 diff --git a/fs/seq_file.c b/fs/seq_file.c
64369 index 1d641bb..e600623 100644
64370 --- a/fs/seq_file.c
64371 +++ b/fs/seq_file.c
64372 @@ -10,6 +10,7 @@
64373 #include <linux/seq_file.h>
64374 #include <linux/slab.h>
64375 #include <linux/cred.h>
64376 +#include <linux/sched.h>
64377
64378 #include <asm/uaccess.h>
64379 #include <asm/page.h>
64380 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64381 #ifdef CONFIG_USER_NS
64382 p->user_ns = file->f_cred->user_ns;
64383 #endif
64384 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64385 + p->exec_id = current->exec_id;
64386 +#endif
64387
64388 /*
64389 * Wrappers around seq_open(e.g. swaps_open) need to be
64390 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64391 return 0;
64392 }
64393 if (!m->buf) {
64394 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64395 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64396 if (!m->buf)
64397 return -ENOMEM;
64398 }
64399 @@ -137,7 +141,7 @@ Eoverflow:
64400 m->op->stop(m, p);
64401 kfree(m->buf);
64402 m->count = 0;
64403 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64404 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64405 return !m->buf ? -ENOMEM : -EAGAIN;
64406 }
64407
64408 @@ -153,7 +157,7 @@ Eoverflow:
64409 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64410 {
64411 struct seq_file *m = file->private_data;
64412 - size_t copied = 0;
64413 + ssize_t copied = 0;
64414 loff_t pos;
64415 size_t n;
64416 void *p;
64417 @@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64418
64419 /* grab buffer if we didn't have one */
64420 if (!m->buf) {
64421 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64422 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64423 if (!m->buf)
64424 goto Enomem;
64425 }
64426 @@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64427 m->op->stop(m, p);
64428 kfree(m->buf);
64429 m->count = 0;
64430 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64431 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64432 if (!m->buf)
64433 goto Enomem;
64434 m->version = 0;
64435 @@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
64436 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64437 void *data)
64438 {
64439 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64440 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64441 int res = -ENOMEM;
64442
64443 if (op) {
64444 diff --git a/fs/splice.c b/fs/splice.c
64445 index 12028fa..a6f2619 100644
64446 --- a/fs/splice.c
64447 +++ b/fs/splice.c
64448 @@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64449 pipe_lock(pipe);
64450
64451 for (;;) {
64452 - if (!pipe->readers) {
64453 + if (!atomic_read(&pipe->readers)) {
64454 send_sig(SIGPIPE, current, 0);
64455 if (!ret)
64456 ret = -EPIPE;
64457 @@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64458 page_nr++;
64459 ret += buf->len;
64460
64461 - if (pipe->files)
64462 + if (atomic_read(&pipe->files))
64463 do_wakeup = 1;
64464
64465 if (!--spd->nr_pages)
64466 @@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64467 do_wakeup = 0;
64468 }
64469
64470 - pipe->waiting_writers++;
64471 + atomic_inc(&pipe->waiting_writers);
64472 pipe_wait(pipe);
64473 - pipe->waiting_writers--;
64474 + atomic_dec(&pipe->waiting_writers);
64475 }
64476
64477 pipe_unlock(pipe);
64478 @@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64479 old_fs = get_fs();
64480 set_fs(get_ds());
64481 /* The cast to a user pointer is valid due to the set_fs() */
64482 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64483 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64484 set_fs(old_fs);
64485
64486 return res;
64487 @@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64488 old_fs = get_fs();
64489 set_fs(get_ds());
64490 /* The cast to a user pointer is valid due to the set_fs() */
64491 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64492 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64493 set_fs(old_fs);
64494
64495 return res;
64496 @@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64497 goto err;
64498
64499 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64500 - vec[i].iov_base = (void __user *) page_address(page);
64501 + vec[i].iov_base = (void __force_user *) page_address(page);
64502 vec[i].iov_len = this_len;
64503 spd.pages[i] = page;
64504 spd.nr_pages++;
64505 @@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
64506 ops->release(pipe, buf);
64507 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
64508 pipe->nrbufs--;
64509 - if (pipe->files)
64510 + if (atomic_read(&pipe->files))
64511 sd->need_wakeup = true;
64512 }
64513
64514 @@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
64515 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
64516 {
64517 while (!pipe->nrbufs) {
64518 - if (!pipe->writers)
64519 + if (!atomic_read(&pipe->writers))
64520 return 0;
64521
64522 - if (!pipe->waiting_writers && sd->num_spliced)
64523 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
64524 return 0;
64525
64526 if (sd->flags & SPLICE_F_NONBLOCK)
64527 @@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
64528 * out of the pipe right after the splice_to_pipe(). So set
64529 * PIPE_READERS appropriately.
64530 */
64531 - pipe->readers = 1;
64532 + atomic_set(&pipe->readers, 1);
64533
64534 current->splice_pipe = pipe;
64535 }
64536 @@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
64537
64538 partial[buffers].offset = off;
64539 partial[buffers].len = plen;
64540 + partial[buffers].private = 0;
64541
64542 off = 0;
64543 len -= plen;
64544 @@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64545 ret = -ERESTARTSYS;
64546 break;
64547 }
64548 - if (!pipe->writers)
64549 + if (!atomic_read(&pipe->writers))
64550 break;
64551 - if (!pipe->waiting_writers) {
64552 + if (!atomic_read(&pipe->waiting_writers)) {
64553 if (flags & SPLICE_F_NONBLOCK) {
64554 ret = -EAGAIN;
64555 break;
64556 @@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64557 pipe_lock(pipe);
64558
64559 while (pipe->nrbufs >= pipe->buffers) {
64560 - if (!pipe->readers) {
64561 + if (!atomic_read(&pipe->readers)) {
64562 send_sig(SIGPIPE, current, 0);
64563 ret = -EPIPE;
64564 break;
64565 @@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64566 ret = -ERESTARTSYS;
64567 break;
64568 }
64569 - pipe->waiting_writers++;
64570 + atomic_inc(&pipe->waiting_writers);
64571 pipe_wait(pipe);
64572 - pipe->waiting_writers--;
64573 + atomic_dec(&pipe->waiting_writers);
64574 }
64575
64576 pipe_unlock(pipe);
64577 @@ -1880,14 +1881,14 @@ retry:
64578 pipe_double_lock(ipipe, opipe);
64579
64580 do {
64581 - if (!opipe->readers) {
64582 + if (!atomic_read(&opipe->readers)) {
64583 send_sig(SIGPIPE, current, 0);
64584 if (!ret)
64585 ret = -EPIPE;
64586 break;
64587 }
64588
64589 - if (!ipipe->nrbufs && !ipipe->writers)
64590 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
64591 break;
64592
64593 /*
64594 @@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64595 pipe_double_lock(ipipe, opipe);
64596
64597 do {
64598 - if (!opipe->readers) {
64599 + if (!atomic_read(&opipe->readers)) {
64600 send_sig(SIGPIPE, current, 0);
64601 if (!ret)
64602 ret = -EPIPE;
64603 @@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64604 * return EAGAIN if we have the potential of some data in the
64605 * future, otherwise just return 0
64606 */
64607 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
64608 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
64609 ret = -EAGAIN;
64610
64611 pipe_unlock(ipipe);
64612 diff --git a/fs/stat.c b/fs/stat.c
64613 index ae0c3ce..9ee641c 100644
64614 --- a/fs/stat.c
64615 +++ b/fs/stat.c
64616 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
64617 stat->gid = inode->i_gid;
64618 stat->rdev = inode->i_rdev;
64619 stat->size = i_size_read(inode);
64620 - stat->atime = inode->i_atime;
64621 - stat->mtime = inode->i_mtime;
64622 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64623 + stat->atime = inode->i_ctime;
64624 + stat->mtime = inode->i_ctime;
64625 + } else {
64626 + stat->atime = inode->i_atime;
64627 + stat->mtime = inode->i_mtime;
64628 + }
64629 stat->ctime = inode->i_ctime;
64630 stat->blksize = (1 << inode->i_blkbits);
64631 stat->blocks = inode->i_blocks;
64632 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
64633 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
64634 {
64635 struct inode *inode = path->dentry->d_inode;
64636 + int retval;
64637
64638 - if (inode->i_op->getattr)
64639 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
64640 + if (inode->i_op->getattr) {
64641 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
64642 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64643 + stat->atime = stat->ctime;
64644 + stat->mtime = stat->ctime;
64645 + }
64646 + return retval;
64647 + }
64648
64649 generic_fillattr(inode, stat);
64650 return 0;
64651 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
64652 index ee0d761..4bf752f 100644
64653 --- a/fs/sysfs/dir.c
64654 +++ b/fs/sysfs/dir.c
64655 @@ -62,9 +62,13 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
64656 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
64657 {
64658 struct kernfs_node *parent, *kn;
64659 + const char *name;
64660 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
64661
64662 BUG_ON(!kobj);
64663
64664 + name = kobject_name(kobj);
64665 +
64666 if (kobj->parent)
64667 parent = kobj->parent->sd;
64668 else
64669 @@ -73,11 +77,23 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
64670 if (!parent)
64671 return -ENOENT;
64672
64673 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
64674 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
64675 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
64676 + const char *parent_name = parent->name;
64677 +
64678 + mode = S_IRWXU;
64679 +
64680 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
64681 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
64682 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
64683 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
64684 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
64685 +#endif
64686 +
64687 + kn = kernfs_create_dir_ns(parent, name,
64688 + mode, kobj, ns);
64689 if (IS_ERR(kn)) {
64690 if (PTR_ERR(kn) == -EEXIST)
64691 - sysfs_warn_dup(parent, kobject_name(kobj));
64692 + sysfs_warn_dup(parent, name);
64693 return PTR_ERR(kn);
64694 }
64695
64696 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
64697 index 69d4889..a810bd4 100644
64698 --- a/fs/sysv/sysv.h
64699 +++ b/fs/sysv/sysv.h
64700 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
64701 #endif
64702 }
64703
64704 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64705 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64706 {
64707 if (sbi->s_bytesex == BYTESEX_PDP)
64708 return PDP_swab((__force __u32)n);
64709 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
64710 index e18b988..f1d4ad0f 100644
64711 --- a/fs/ubifs/io.c
64712 +++ b/fs/ubifs/io.c
64713 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
64714 return err;
64715 }
64716
64717 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64718 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64719 {
64720 int err;
64721
64722 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
64723 index c175b4d..8f36a16 100644
64724 --- a/fs/udf/misc.c
64725 +++ b/fs/udf/misc.c
64726 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
64727
64728 u8 udf_tag_checksum(const struct tag *t)
64729 {
64730 - u8 *data = (u8 *)t;
64731 + const u8 *data = (const u8 *)t;
64732 u8 checksum = 0;
64733 int i;
64734 for (i = 0; i < sizeof(struct tag); ++i)
64735 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
64736 index 8d974c4..b82f6ec 100644
64737 --- a/fs/ufs/swab.h
64738 +++ b/fs/ufs/swab.h
64739 @@ -22,7 +22,7 @@ enum {
64740 BYTESEX_BE
64741 };
64742
64743 -static inline u64
64744 +static inline u64 __intentional_overflow(-1)
64745 fs64_to_cpu(struct super_block *sbp, __fs64 n)
64746 {
64747 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64748 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
64749 return (__force __fs64)cpu_to_be64(n);
64750 }
64751
64752 -static inline u32
64753 +static inline u32 __intentional_overflow(-1)
64754 fs32_to_cpu(struct super_block *sbp, __fs32 n)
64755 {
64756 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64757 diff --git a/fs/utimes.c b/fs/utimes.c
64758 index aa138d6..5f3a811 100644
64759 --- a/fs/utimes.c
64760 +++ b/fs/utimes.c
64761 @@ -1,6 +1,7 @@
64762 #include <linux/compiler.h>
64763 #include <linux/file.h>
64764 #include <linux/fs.h>
64765 +#include <linux/security.h>
64766 #include <linux/linkage.h>
64767 #include <linux/mount.h>
64768 #include <linux/namei.h>
64769 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
64770 }
64771 }
64772 retry_deleg:
64773 +
64774 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
64775 + error = -EACCES;
64776 + goto mnt_drop_write_and_out;
64777 + }
64778 +
64779 mutex_lock(&inode->i_mutex);
64780 error = notify_change(path->dentry, &newattrs, &delegated_inode);
64781 mutex_unlock(&inode->i_mutex);
64782 diff --git a/fs/xattr.c b/fs/xattr.c
64783 index 3377dff..f394815 100644
64784 --- a/fs/xattr.c
64785 +++ b/fs/xattr.c
64786 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
64787 return rc;
64788 }
64789
64790 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
64791 +ssize_t
64792 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
64793 +{
64794 + struct inode *inode = dentry->d_inode;
64795 + ssize_t error;
64796 +
64797 + error = inode_permission(inode, MAY_EXEC);
64798 + if (error)
64799 + return error;
64800 +
64801 + if (inode->i_op->getxattr)
64802 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
64803 + else
64804 + error = -EOPNOTSUPP;
64805 +
64806 + return error;
64807 +}
64808 +EXPORT_SYMBOL(pax_getxattr);
64809 +#endif
64810 +
64811 ssize_t
64812 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
64813 {
64814 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
64815 * Extended attribute SET operations
64816 */
64817 static long
64818 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
64819 +setxattr(struct path *path, const char __user *name, const void __user *value,
64820 size_t size, int flags)
64821 {
64822 int error;
64823 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
64824 posix_acl_fix_xattr_from_user(kvalue, size);
64825 }
64826
64827 - error = vfs_setxattr(d, kname, kvalue, size, flags);
64828 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
64829 + error = -EACCES;
64830 + goto out;
64831 + }
64832 +
64833 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
64834 out:
64835 if (vvalue)
64836 vfree(vvalue);
64837 @@ -377,7 +403,7 @@ retry:
64838 return error;
64839 error = mnt_want_write(path.mnt);
64840 if (!error) {
64841 - error = setxattr(path.dentry, name, value, size, flags);
64842 + error = setxattr(&path, name, value, size, flags);
64843 mnt_drop_write(path.mnt);
64844 }
64845 path_put(&path);
64846 @@ -401,7 +427,7 @@ retry:
64847 return error;
64848 error = mnt_want_write(path.mnt);
64849 if (!error) {
64850 - error = setxattr(path.dentry, name, value, size, flags);
64851 + error = setxattr(&path, name, value, size, flags);
64852 mnt_drop_write(path.mnt);
64853 }
64854 path_put(&path);
64855 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
64856 const void __user *,value, size_t, size, int, flags)
64857 {
64858 struct fd f = fdget(fd);
64859 - struct dentry *dentry;
64860 int error = -EBADF;
64861
64862 if (!f.file)
64863 return error;
64864 - dentry = f.file->f_path.dentry;
64865 - audit_inode(NULL, dentry, 0);
64866 + audit_inode(NULL, f.file->f_path.dentry, 0);
64867 error = mnt_want_write_file(f.file);
64868 if (!error) {
64869 - error = setxattr(dentry, name, value, size, flags);
64870 + error = setxattr(&f.file->f_path, name, value, size, flags);
64871 mnt_drop_write_file(f.file);
64872 }
64873 fdput(f);
64874 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
64875 * Extended attribute REMOVE operations
64876 */
64877 static long
64878 -removexattr(struct dentry *d, const char __user *name)
64879 +removexattr(struct path *path, const char __user *name)
64880 {
64881 int error;
64882 char kname[XATTR_NAME_MAX + 1];
64883 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
64884 if (error < 0)
64885 return error;
64886
64887 - return vfs_removexattr(d, kname);
64888 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
64889 + return -EACCES;
64890 +
64891 + return vfs_removexattr(path->dentry, kname);
64892 }
64893
64894 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
64895 @@ -652,7 +679,7 @@ retry:
64896 return error;
64897 error = mnt_want_write(path.mnt);
64898 if (!error) {
64899 - error = removexattr(path.dentry, name);
64900 + error = removexattr(&path, name);
64901 mnt_drop_write(path.mnt);
64902 }
64903 path_put(&path);
64904 @@ -675,7 +702,7 @@ retry:
64905 return error;
64906 error = mnt_want_write(path.mnt);
64907 if (!error) {
64908 - error = removexattr(path.dentry, name);
64909 + error = removexattr(&path, name);
64910 mnt_drop_write(path.mnt);
64911 }
64912 path_put(&path);
64913 @@ -689,16 +716,16 @@ retry:
64914 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
64915 {
64916 struct fd f = fdget(fd);
64917 - struct dentry *dentry;
64918 + struct path *path;
64919 int error = -EBADF;
64920
64921 if (!f.file)
64922 return error;
64923 - dentry = f.file->f_path.dentry;
64924 - audit_inode(NULL, dentry, 0);
64925 + path = &f.file->f_path;
64926 + audit_inode(NULL, path->dentry, 0);
64927 error = mnt_want_write_file(f.file);
64928 if (!error) {
64929 - error = removexattr(dentry, name);
64930 + error = removexattr(path, name);
64931 mnt_drop_write_file(f.file);
64932 }
64933 fdput(f);
64934 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
64935 index 152543c..d80c361 100644
64936 --- a/fs/xfs/xfs_bmap.c
64937 +++ b/fs/xfs/xfs_bmap.c
64938 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
64939
64940 #else
64941 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
64942 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
64943 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
64944 #endif /* DEBUG */
64945
64946 /*
64947 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
64948 index aead369..0dfecfd 100644
64949 --- a/fs/xfs/xfs_dir2_readdir.c
64950 +++ b/fs/xfs/xfs_dir2_readdir.c
64951 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
64952 ino = dp->d_ops->sf_get_ino(sfp, sfep);
64953 filetype = dp->d_ops->sf_get_ftype(sfep);
64954 ctx->pos = off & 0x7fffffff;
64955 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64956 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
64957 + char name[sfep->namelen];
64958 + memcpy(name, sfep->name, sfep->namelen);
64959 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
64960 + return 0;
64961 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64962 xfs_dir3_get_dtype(mp, filetype)))
64963 return 0;
64964 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
64965 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
64966 index bcfe612..aa399c0 100644
64967 --- a/fs/xfs/xfs_ioctl.c
64968 +++ b/fs/xfs/xfs_ioctl.c
64969 @@ -122,7 +122,7 @@ xfs_find_handle(
64970 }
64971
64972 error = -EFAULT;
64973 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
64974 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
64975 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
64976 goto out_put;
64977
64978 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
64979 new file mode 100644
64980 index 0000000..3abaf02
64981 --- /dev/null
64982 +++ b/grsecurity/Kconfig
64983 @@ -0,0 +1,1161 @@
64984 +#
64985 +# grecurity configuration
64986 +#
64987 +menu "Memory Protections"
64988 +depends on GRKERNSEC
64989 +
64990 +config GRKERNSEC_KMEM
64991 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
64992 + default y if GRKERNSEC_CONFIG_AUTO
64993 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
64994 + help
64995 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
64996 + be written to or read from to modify or leak the contents of the running
64997 + kernel. /dev/port will also not be allowed to be opened, writing to
64998 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
64999 + If you have module support disabled, enabling this will close up several
65000 + ways that are currently used to insert malicious code into the running
65001 + kernel.
65002 +
65003 + Even with this feature enabled, we still highly recommend that
65004 + you use the RBAC system, as it is still possible for an attacker to
65005 + modify the running kernel through other more obscure methods.
65006 +
65007 + It is highly recommended that you say Y here if you meet all the
65008 + conditions above.
65009 +
65010 +config GRKERNSEC_VM86
65011 + bool "Restrict VM86 mode"
65012 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65013 + depends on X86_32
65014 +
65015 + help
65016 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65017 + make use of a special execution mode on 32bit x86 processors called
65018 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65019 + video cards and will still work with this option enabled. The purpose
65020 + of the option is to prevent exploitation of emulation errors in
65021 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
65022 + Nearly all users should be able to enable this option.
65023 +
65024 +config GRKERNSEC_IO
65025 + bool "Disable privileged I/O"
65026 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65027 + depends on X86
65028 + select RTC_CLASS
65029 + select RTC_INTF_DEV
65030 + select RTC_DRV_CMOS
65031 +
65032 + help
65033 + If you say Y here, all ioperm and iopl calls will return an error.
65034 + Ioperm and iopl can be used to modify the running kernel.
65035 + Unfortunately, some programs need this access to operate properly,
65036 + the most notable of which are XFree86 and hwclock. hwclock can be
65037 + remedied by having RTC support in the kernel, so real-time
65038 + clock support is enabled if this option is enabled, to ensure
65039 + that hwclock operates correctly. If hwclock still does not work,
65040 + either update udev or symlink /dev/rtc to /dev/rtc0.
65041 +
65042 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
65043 + you may not be able to boot into a graphical environment with this
65044 + option enabled. In this case, you should use the RBAC system instead.
65045 +
65046 +config GRKERNSEC_JIT_HARDEN
65047 + bool "Harden BPF JIT against spray attacks"
65048 + default y if GRKERNSEC_CONFIG_AUTO
65049 + depends on BPF_JIT && X86
65050 + help
65051 + If you say Y here, the native code generated by the kernel's Berkeley
65052 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65053 + attacks that attempt to fit attacker-beneficial instructions in
65054 + 32bit immediate fields of JIT-generated native instructions. The
65055 + attacker will generally aim to cause an unintended instruction sequence
65056 + of JIT-generated native code to execute by jumping into the middle of
65057 + a generated instruction. This feature effectively randomizes the 32bit
65058 + immediate constants present in the generated code to thwart such attacks.
65059 +
65060 + If you're using KERNEXEC, it's recommended that you enable this option
65061 + to supplement the hardening of the kernel.
65062 +
65063 +config GRKERNSEC_PERF_HARDEN
65064 + bool "Disable unprivileged PERF_EVENTS usage by default"
65065 + default y if GRKERNSEC_CONFIG_AUTO
65066 + depends on PERF_EVENTS
65067 + help
65068 + If you say Y here, the range of acceptable values for the
65069 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65070 + default to a new value: 3. When the sysctl is set to this value, no
65071 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65072 +
65073 + Though PERF_EVENTS can be used legitimately for performance monitoring
65074 + and low-level application profiling, it is forced on regardless of
65075 + configuration, has been at fault for several vulnerabilities, and
65076 + creates new opportunities for side channels and other information leaks.
65077 +
65078 + This feature puts PERF_EVENTS into a secure default state and permits
65079 + the administrator to change out of it temporarily if unprivileged
65080 + application profiling is needed.
65081 +
65082 +config GRKERNSEC_RAND_THREADSTACK
65083 + bool "Insert random gaps between thread stacks"
65084 + default y if GRKERNSEC_CONFIG_AUTO
65085 + depends on PAX_RANDMMAP && !PPC
65086 + help
65087 + If you say Y here, a random-sized gap will be enforced between allocated
65088 + thread stacks. Glibc's NPTL and other threading libraries that
65089 + pass MAP_STACK to the kernel for thread stack allocation are supported.
65090 + The implementation currently provides 8 bits of entropy for the gap.
65091 +
65092 + Many distributions do not compile threaded remote services with the
65093 + -fstack-check argument to GCC, causing the variable-sized stack-based
65094 + allocator, alloca(), to not probe the stack on allocation. This
65095 + permits an unbounded alloca() to skip over any guard page and potentially
65096 + modify another thread's stack reliably. An enforced random gap
65097 + reduces the reliability of such an attack and increases the chance
65098 + that such a read/write to another thread's stack instead lands in
65099 + an unmapped area, causing a crash and triggering grsecurity's
65100 + anti-bruteforcing logic.
65101 +
65102 +config GRKERNSEC_PROC_MEMMAP
65103 + bool "Harden ASLR against information leaks and entropy reduction"
65104 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65105 + depends on PAX_NOEXEC || PAX_ASLR
65106 + help
65107 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65108 + give no information about the addresses of its mappings if
65109 + PaX features that rely on random addresses are enabled on the task.
65110 + In addition to sanitizing this information and disabling other
65111 + dangerous sources of information, this option causes reads of sensitive
65112 + /proc/<pid> entries where the file descriptor was opened in a different
65113 + task than the one performing the read. Such attempts are logged.
65114 + This option also limits argv/env strings for suid/sgid binaries
65115 + to 512KB to prevent a complete exhaustion of the stack entropy provided
65116 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65117 + binaries to prevent alternative mmap layouts from being abused.
65118 +
65119 + If you use PaX it is essential that you say Y here as it closes up
65120 + several holes that make full ASLR useless locally.
65121 +
65122 +config GRKERNSEC_BRUTE
65123 + bool "Deter exploit bruteforcing"
65124 + default y if GRKERNSEC_CONFIG_AUTO
65125 + help
65126 + If you say Y here, attempts to bruteforce exploits against forking
65127 + daemons such as apache or sshd, as well as against suid/sgid binaries
65128 + will be deterred. When a child of a forking daemon is killed by PaX
65129 + or crashes due to an illegal instruction or other suspicious signal,
65130 + the parent process will be delayed 30 seconds upon every subsequent
65131 + fork until the administrator is able to assess the situation and
65132 + restart the daemon.
65133 + In the suid/sgid case, the attempt is logged, the user has all their
65134 + existing instances of the suid/sgid binary terminated and will
65135 + be unable to execute any suid/sgid binaries for 15 minutes.
65136 +
65137 + It is recommended that you also enable signal logging in the auditing
65138 + section so that logs are generated when a process triggers a suspicious
65139 + signal.
65140 + If the sysctl option is enabled, a sysctl option with name
65141 + "deter_bruteforce" is created.
65142 +
65143 +config GRKERNSEC_MODHARDEN
65144 + bool "Harden module auto-loading"
65145 + default y if GRKERNSEC_CONFIG_AUTO
65146 + depends on MODULES
65147 + help
65148 + If you say Y here, module auto-loading in response to use of some
65149 + feature implemented by an unloaded module will be restricted to
65150 + root users. Enabling this option helps defend against attacks
65151 + by unprivileged users who abuse the auto-loading behavior to
65152 + cause a vulnerable module to load that is then exploited.
65153 +
65154 + If this option prevents a legitimate use of auto-loading for a
65155 + non-root user, the administrator can execute modprobe manually
65156 + with the exact name of the module mentioned in the alert log.
65157 + Alternatively, the administrator can add the module to the list
65158 + of modules loaded at boot by modifying init scripts.
65159 +
65160 + Modification of init scripts will most likely be needed on
65161 + Ubuntu servers with encrypted home directory support enabled,
65162 + as the first non-root user logging in will cause the ecb(aes),
65163 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65164 +
65165 +config GRKERNSEC_HIDESYM
65166 + bool "Hide kernel symbols"
65167 + default y if GRKERNSEC_CONFIG_AUTO
65168 + select PAX_USERCOPY_SLABS
65169 + help
65170 + If you say Y here, getting information on loaded modules, and
65171 + displaying all kernel symbols through a syscall will be restricted
65172 + to users with CAP_SYS_MODULE. For software compatibility reasons,
65173 + /proc/kallsyms will be restricted to the root user. The RBAC
65174 + system can hide that entry even from root.
65175 +
65176 + This option also prevents leaking of kernel addresses through
65177 + several /proc entries.
65178 +
65179 + Note that this option is only effective provided the following
65180 + conditions are met:
65181 + 1) The kernel using grsecurity is not precompiled by some distribution
65182 + 2) You have also enabled GRKERNSEC_DMESG
65183 + 3) You are using the RBAC system and hiding other files such as your
65184 + kernel image and System.map. Alternatively, enabling this option
65185 + causes the permissions on /boot, /lib/modules, and the kernel
65186 + source directory to change at compile time to prevent
65187 + reading by non-root users.
65188 + If the above conditions are met, this option will aid in providing a
65189 + useful protection against local kernel exploitation of overflows
65190 + and arbitrary read/write vulnerabilities.
65191 +
65192 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65193 + in addition to this feature.
65194 +
65195 +config GRKERNSEC_RANDSTRUCT
65196 + bool "Randomize layout of sensitive kernel structures"
65197 + default y if GRKERNSEC_CONFIG_AUTO
65198 + select GRKERNSEC_HIDESYM
65199 + select MODVERSIONS if MODULES
65200 + help
65201 + If you say Y here, the layouts of a number of sensitive kernel
65202 + structures (task, fs, cred, etc) and all structures composed entirely
65203 + of function pointers (aka "ops" structs) will be randomized at compile-time.
65204 + This can introduce the requirement of an additional infoleak
65205 + vulnerability for exploits targeting these structure types.
65206 +
65207 + Enabling this feature will introduce some performance impact, slightly
65208 + increase memory usage, and prevent the use of forensic tools like
65209 + Volatility against the system (unless the kernel source tree isn't
65210 + cleaned after kernel installation).
65211 +
65212 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65213 + It remains after a make clean to allow for external modules to be compiled
65214 + with the existing seed and will be removed by a make mrproper or
65215 + make distclean.
65216 +
65217 + Note that the implementation requires gcc 4.6.4. or newer. You may need
65218 + to install the supporting headers explicitly in addition to the normal
65219 + gcc package.
65220 +
65221 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65222 + bool "Use cacheline-aware structure randomization"
65223 + depends on GRKERNSEC_RANDSTRUCT
65224 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65225 + help
65226 + If you say Y here, the RANDSTRUCT randomization will make a best effort
65227 + at restricting randomization to cacheline-sized groups of elements. It
65228 + will further not randomize bitfields in structures. This reduces the
65229 + performance hit of RANDSTRUCT at the cost of weakened randomization.
65230 +
65231 +config GRKERNSEC_KERN_LOCKOUT
65232 + bool "Active kernel exploit response"
65233 + default y if GRKERNSEC_CONFIG_AUTO
65234 + depends on X86 || ARM || PPC || SPARC
65235 + help
65236 + If you say Y here, when a PaX alert is triggered due to suspicious
65237 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65238 + or an OOPS occurs due to bad memory accesses, instead of just
65239 + terminating the offending process (and potentially allowing
65240 + a subsequent exploit from the same user), we will take one of two
65241 + actions:
65242 + If the user was root, we will panic the system
65243 + If the user was non-root, we will log the attempt, terminate
65244 + all processes owned by the user, then prevent them from creating
65245 + any new processes until the system is restarted
65246 + This deters repeated kernel exploitation/bruteforcing attempts
65247 + and is useful for later forensics.
65248 +
65249 +config GRKERNSEC_OLD_ARM_USERLAND
65250 + bool "Old ARM userland compatibility"
65251 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65252 + help
65253 + If you say Y here, stubs of executable code to perform such operations
65254 + as "compare-exchange" will be placed at fixed locations in the ARM vector
65255 + table. This is unfortunately needed for old ARM userland meant to run
65256 + across a wide range of processors. Without this option enabled,
65257 + the get_tls and data memory barrier stubs will be emulated by the kernel,
65258 + which is enough for Linaro userlands or other userlands designed for v6
65259 + and newer ARM CPUs. It's recommended that you try without this option enabled
65260 + first, and only enable it if your userland does not boot (it will likely fail
65261 + at init time).
65262 +
65263 +endmenu
65264 +menu "Role Based Access Control Options"
65265 +depends on GRKERNSEC
65266 +
65267 +config GRKERNSEC_RBAC_DEBUG
65268 + bool
65269 +
65270 +config GRKERNSEC_NO_RBAC
65271 + bool "Disable RBAC system"
65272 + help
65273 + If you say Y here, the /dev/grsec device will be removed from the kernel,
65274 + preventing the RBAC system from being enabled. You should only say Y
65275 + here if you have no intention of using the RBAC system, so as to prevent
65276 + an attacker with root access from misusing the RBAC system to hide files
65277 + and processes when loadable module support and /dev/[k]mem have been
65278 + locked down.
65279 +
65280 +config GRKERNSEC_ACL_HIDEKERN
65281 + bool "Hide kernel processes"
65282 + help
65283 + If you say Y here, all kernel threads will be hidden to all
65284 + processes but those whose subject has the "view hidden processes"
65285 + flag.
65286 +
65287 +config GRKERNSEC_ACL_MAXTRIES
65288 + int "Maximum tries before password lockout"
65289 + default 3
65290 + help
65291 + This option enforces the maximum number of times a user can attempt
65292 + to authorize themselves with the grsecurity RBAC system before being
65293 + denied the ability to attempt authorization again for a specified time.
65294 + The lower the number, the harder it will be to brute-force a password.
65295 +
65296 +config GRKERNSEC_ACL_TIMEOUT
65297 + int "Time to wait after max password tries, in seconds"
65298 + default 30
65299 + help
65300 + This option specifies the time the user must wait after attempting to
65301 + authorize to the RBAC system with the maximum number of invalid
65302 + passwords. The higher the number, the harder it will be to brute-force
65303 + a password.
65304 +
65305 +endmenu
65306 +menu "Filesystem Protections"
65307 +depends on GRKERNSEC
65308 +
65309 +config GRKERNSEC_PROC
65310 + bool "Proc restrictions"
65311 + default y if GRKERNSEC_CONFIG_AUTO
65312 + help
65313 + If you say Y here, the permissions of the /proc filesystem
65314 + will be altered to enhance system security and privacy. You MUST
65315 + choose either a user only restriction or a user and group restriction.
65316 + Depending upon the option you choose, you can either restrict users to
65317 + see only the processes they themselves run, or choose a group that can
65318 + view all processes and files normally restricted to root if you choose
65319 + the "restrict to user only" option. NOTE: If you're running identd or
65320 + ntpd as a non-root user, you will have to run it as the group you
65321 + specify here.
65322 +
65323 +config GRKERNSEC_PROC_USER
65324 + bool "Restrict /proc to user only"
65325 + depends on GRKERNSEC_PROC
65326 + help
65327 + If you say Y here, non-root users will only be able to view their own
65328 + processes, and restricts them from viewing network-related information,
65329 + and viewing kernel symbol and module information.
65330 +
65331 +config GRKERNSEC_PROC_USERGROUP
65332 + bool "Allow special group"
65333 + default y if GRKERNSEC_CONFIG_AUTO
65334 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65335 + help
65336 + If you say Y here, you will be able to select a group that will be
65337 + able to view all processes and network-related information. If you've
65338 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65339 + remain hidden. This option is useful if you want to run identd as
65340 + a non-root user. The group you select may also be chosen at boot time
65341 + via "grsec_proc_gid=" on the kernel commandline.
65342 +
65343 +config GRKERNSEC_PROC_GID
65344 + int "GID for special group"
65345 + depends on GRKERNSEC_PROC_USERGROUP
65346 + default 1001
65347 +
65348 +config GRKERNSEC_PROC_ADD
65349 + bool "Additional restrictions"
65350 + default y if GRKERNSEC_CONFIG_AUTO
65351 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65352 + help
65353 + If you say Y here, additional restrictions will be placed on
65354 + /proc that keep normal users from viewing device information and
65355 + slabinfo information that could be useful for exploits.
65356 +
65357 +config GRKERNSEC_LINK
65358 + bool "Linking restrictions"
65359 + default y if GRKERNSEC_CONFIG_AUTO
65360 + help
65361 + If you say Y here, /tmp race exploits will be prevented, since users
65362 + will no longer be able to follow symlinks owned by other users in
65363 + world-writable +t directories (e.g. /tmp), unless the owner of the
65364 + symlink is the owner of the directory. users will also not be
65365 + able to hardlink to files they do not own. If the sysctl option is
65366 + enabled, a sysctl option with name "linking_restrictions" is created.
65367 +
65368 +config GRKERNSEC_SYMLINKOWN
65369 + bool "Kernel-enforced SymlinksIfOwnerMatch"
65370 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65371 + help
65372 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
65373 + that prevents it from being used as a security feature. As Apache
65374 + verifies the symlink by performing a stat() against the target of
65375 + the symlink before it is followed, an attacker can setup a symlink
65376 + to point to a same-owned file, then replace the symlink with one
65377 + that targets another user's file just after Apache "validates" the
65378 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
65379 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65380 + will be in place for the group you specify. If the sysctl option
65381 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
65382 + created.
65383 +
65384 +config GRKERNSEC_SYMLINKOWN_GID
65385 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65386 + depends on GRKERNSEC_SYMLINKOWN
65387 + default 1006
65388 + help
65389 + Setting this GID determines what group kernel-enforced
65390 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65391 + is enabled, a sysctl option with name "symlinkown_gid" is created.
65392 +
65393 +config GRKERNSEC_FIFO
65394 + bool "FIFO restrictions"
65395 + default y if GRKERNSEC_CONFIG_AUTO
65396 + help
65397 + If you say Y here, users will not be able to write to FIFOs they don't
65398 + own in world-writable +t directories (e.g. /tmp), unless the owner of
65399 + the FIFO is the same owner of the directory it's held in. If the sysctl
65400 + option is enabled, a sysctl option with name "fifo_restrictions" is
65401 + created.
65402 +
65403 +config GRKERNSEC_SYSFS_RESTRICT
65404 + bool "Sysfs/debugfs restriction"
65405 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65406 + depends on SYSFS
65407 + help
65408 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65409 + any filesystem normally mounted under it (e.g. debugfs) will be
65410 + mostly accessible only by root. These filesystems generally provide access
65411 + to hardware and debug information that isn't appropriate for unprivileged
65412 + users of the system. Sysfs and debugfs have also become a large source
65413 + of new vulnerabilities, ranging from infoleaks to local compromise.
65414 + There has been very little oversight with an eye toward security involved
65415 + in adding new exporters of information to these filesystems, so their
65416 + use is discouraged.
65417 + For reasons of compatibility, a few directories have been whitelisted
65418 + for access by non-root users:
65419 + /sys/fs/selinux
65420 + /sys/fs/fuse
65421 + /sys/devices/system/cpu
65422 +
65423 +config GRKERNSEC_ROFS
65424 + bool "Runtime read-only mount protection"
65425 + depends on SYSCTL
65426 + help
65427 + If you say Y here, a sysctl option with name "romount_protect" will
65428 + be created. By setting this option to 1 at runtime, filesystems
65429 + will be protected in the following ways:
65430 + * No new writable mounts will be allowed
65431 + * Existing read-only mounts won't be able to be remounted read/write
65432 + * Write operations will be denied on all block devices
65433 + This option acts independently of grsec_lock: once it is set to 1,
65434 + it cannot be turned off. Therefore, please be mindful of the resulting
65435 + behavior if this option is enabled in an init script on a read-only
65436 + filesystem.
65437 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65438 + and GRKERNSEC_IO should be enabled and module loading disabled via
65439 + config or at runtime.
65440 + This feature is mainly intended for secure embedded systems.
65441 +
65442 +
65443 +config GRKERNSEC_DEVICE_SIDECHANNEL
65444 + bool "Eliminate stat/notify-based device sidechannels"
65445 + default y if GRKERNSEC_CONFIG_AUTO
65446 + help
65447 + If you say Y here, timing analyses on block or character
65448 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65449 + will be thwarted for unprivileged users. If a process without
65450 + CAP_MKNOD stats such a device, the last access and last modify times
65451 + will match the device's create time. No access or modify events
65452 + will be triggered through inotify/dnotify/fanotify for such devices.
65453 + This feature will prevent attacks that may at a minimum
65454 + allow an attacker to determine the administrator's password length.
65455 +
65456 +config GRKERNSEC_CHROOT
65457 + bool "Chroot jail restrictions"
65458 + default y if GRKERNSEC_CONFIG_AUTO
65459 + help
65460 + If you say Y here, you will be able to choose several options that will
65461 + make breaking out of a chrooted jail much more difficult. If you
65462 + encounter no software incompatibilities with the following options, it
65463 + is recommended that you enable each one.
65464 +
65465 + Note that the chroot restrictions are not intended to apply to "chroots"
65466 + to directories that are simple bind mounts of the global root filesystem.
65467 + For several other reasons, a user shouldn't expect any significant
65468 + security by performing such a chroot.
65469 +
65470 +config GRKERNSEC_CHROOT_MOUNT
65471 + bool "Deny mounts"
65472 + default y if GRKERNSEC_CONFIG_AUTO
65473 + depends on GRKERNSEC_CHROOT
65474 + help
65475 + If you say Y here, processes inside a chroot will not be able to
65476 + mount or remount filesystems. If the sysctl option is enabled, a
65477 + sysctl option with name "chroot_deny_mount" is created.
65478 +
65479 +config GRKERNSEC_CHROOT_DOUBLE
65480 + bool "Deny double-chroots"
65481 + default y if GRKERNSEC_CONFIG_AUTO
65482 + depends on GRKERNSEC_CHROOT
65483 + help
65484 + If you say Y here, processes inside a chroot will not be able to chroot
65485 + again outside the chroot. This is a widely used method of breaking
65486 + out of a chroot jail and should not be allowed. If the sysctl
65487 + option is enabled, a sysctl option with name
65488 + "chroot_deny_chroot" is created.
65489 +
65490 +config GRKERNSEC_CHROOT_PIVOT
65491 + bool "Deny pivot_root in chroot"
65492 + default y if GRKERNSEC_CONFIG_AUTO
65493 + depends on GRKERNSEC_CHROOT
65494 + help
65495 + If you say Y here, processes inside a chroot will not be able to use
65496 + a function called pivot_root() that was introduced in Linux 2.3.41. It
65497 + works similar to chroot in that it changes the root filesystem. This
65498 + function could be misused in a chrooted process to attempt to break out
65499 + of the chroot, and therefore should not be allowed. If the sysctl
65500 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
65501 + created.
65502 +
65503 +config GRKERNSEC_CHROOT_CHDIR
65504 + bool "Enforce chdir(\"/\") on all chroots"
65505 + default y if GRKERNSEC_CONFIG_AUTO
65506 + depends on GRKERNSEC_CHROOT
65507 + help
65508 + If you say Y here, the current working directory of all newly-chrooted
65509 + applications will be set to the the root directory of the chroot.
65510 + The man page on chroot(2) states:
65511 + Note that this call does not change the current working
65512 + directory, so that `.' can be outside the tree rooted at
65513 + `/'. In particular, the super-user can escape from a
65514 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
65515 +
65516 + It is recommended that you say Y here, since it's not known to break
65517 + any software. If the sysctl option is enabled, a sysctl option with
65518 + name "chroot_enforce_chdir" is created.
65519 +
65520 +config GRKERNSEC_CHROOT_CHMOD
65521 + bool "Deny (f)chmod +s"
65522 + default y if GRKERNSEC_CONFIG_AUTO
65523 + depends on GRKERNSEC_CHROOT
65524 + help
65525 + If you say Y here, processes inside a chroot will not be able to chmod
65526 + or fchmod files to make them have suid or sgid bits. This protects
65527 + against another published method of breaking a chroot. If the sysctl
65528 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
65529 + created.
65530 +
65531 +config GRKERNSEC_CHROOT_FCHDIR
65532 + bool "Deny fchdir out of chroot"
65533 + default y if GRKERNSEC_CONFIG_AUTO
65534 + depends on GRKERNSEC_CHROOT
65535 + help
65536 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
65537 + to a file descriptor of the chrooting process that points to a directory
65538 + outside the filesystem will be stopped. If the sysctl option
65539 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
65540 +
65541 +config GRKERNSEC_CHROOT_MKNOD
65542 + bool "Deny mknod"
65543 + default y if GRKERNSEC_CONFIG_AUTO
65544 + depends on GRKERNSEC_CHROOT
65545 + help
65546 + If you say Y here, processes inside a chroot will not be allowed to
65547 + mknod. The problem with using mknod inside a chroot is that it
65548 + would allow an attacker to create a device entry that is the same
65549 + as one on the physical root of your system, which could range from
65550 + anything from the console device to a device for your harddrive (which
65551 + they could then use to wipe the drive or steal data). It is recommended
65552 + that you say Y here, unless you run into software incompatibilities.
65553 + If the sysctl option is enabled, a sysctl option with name
65554 + "chroot_deny_mknod" is created.
65555 +
65556 +config GRKERNSEC_CHROOT_SHMAT
65557 + bool "Deny shmat() out of chroot"
65558 + default y if GRKERNSEC_CONFIG_AUTO
65559 + depends on GRKERNSEC_CHROOT
65560 + help
65561 + If you say Y here, processes inside a chroot will not be able to attach
65562 + to shared memory segments that were created outside of the chroot jail.
65563 + It is recommended that you say Y here. If the sysctl option is enabled,
65564 + a sysctl option with name "chroot_deny_shmat" is created.
65565 +
65566 +config GRKERNSEC_CHROOT_UNIX
65567 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
65568 + default y if GRKERNSEC_CONFIG_AUTO
65569 + depends on GRKERNSEC_CHROOT
65570 + help
65571 + If you say Y here, processes inside a chroot will not be able to
65572 + connect to abstract (meaning not belonging to a filesystem) Unix
65573 + domain sockets that were bound outside of a chroot. It is recommended
65574 + that you say Y here. If the sysctl option is enabled, a sysctl option
65575 + with name "chroot_deny_unix" is created.
65576 +
65577 +config GRKERNSEC_CHROOT_FINDTASK
65578 + bool "Protect outside processes"
65579 + default y if GRKERNSEC_CONFIG_AUTO
65580 + depends on GRKERNSEC_CHROOT
65581 + help
65582 + If you say Y here, processes inside a chroot will not be able to
65583 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
65584 + getsid, or view any process outside of the chroot. If the sysctl
65585 + option is enabled, a sysctl option with name "chroot_findtask" is
65586 + created.
65587 +
65588 +config GRKERNSEC_CHROOT_NICE
65589 + bool "Restrict priority changes"
65590 + default y if GRKERNSEC_CONFIG_AUTO
65591 + depends on GRKERNSEC_CHROOT
65592 + help
65593 + If you say Y here, processes inside a chroot will not be able to raise
65594 + the priority of processes in the chroot, or alter the priority of
65595 + processes outside the chroot. This provides more security than simply
65596 + removing CAP_SYS_NICE from the process' capability set. If the
65597 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
65598 + is created.
65599 +
65600 +config GRKERNSEC_CHROOT_SYSCTL
65601 + bool "Deny sysctl writes"
65602 + default y if GRKERNSEC_CONFIG_AUTO
65603 + depends on GRKERNSEC_CHROOT
65604 + help
65605 + If you say Y here, an attacker in a chroot will not be able to
65606 + write to sysctl entries, either by sysctl(2) or through a /proc
65607 + interface. It is strongly recommended that you say Y here. If the
65608 + sysctl option is enabled, a sysctl option with name
65609 + "chroot_deny_sysctl" is created.
65610 +
65611 +config GRKERNSEC_CHROOT_CAPS
65612 + bool "Capability restrictions"
65613 + default y if GRKERNSEC_CONFIG_AUTO
65614 + depends on GRKERNSEC_CHROOT
65615 + help
65616 + If you say Y here, the capabilities on all processes within a
65617 + chroot jail will be lowered to stop module insertion, raw i/o,
65618 + system and net admin tasks, rebooting the system, modifying immutable
65619 + files, modifying IPC owned by another, and changing the system time.
65620 + This is left an option because it can break some apps. Disable this
65621 + if your chrooted apps are having problems performing those kinds of
65622 + tasks. If the sysctl option is enabled, a sysctl option with
65623 + name "chroot_caps" is created.
65624 +
65625 +config GRKERNSEC_CHROOT_INITRD
65626 + bool "Exempt initrd tasks from restrictions"
65627 + default y if GRKERNSEC_CONFIG_AUTO
65628 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
65629 + help
65630 + If you say Y here, tasks started prior to init will be exempted from
65631 + grsecurity's chroot restrictions. This option is mainly meant to
65632 + resolve Plymouth's performing privileged operations unnecessarily
65633 + in a chroot.
65634 +
65635 +endmenu
65636 +menu "Kernel Auditing"
65637 +depends on GRKERNSEC
65638 +
65639 +config GRKERNSEC_AUDIT_GROUP
65640 + bool "Single group for auditing"
65641 + help
65642 + If you say Y here, the exec and chdir logging features will only operate
65643 + on a group you specify. This option is recommended if you only want to
65644 + watch certain users instead of having a large amount of logs from the
65645 + entire system. If the sysctl option is enabled, a sysctl option with
65646 + name "audit_group" is created.
65647 +
65648 +config GRKERNSEC_AUDIT_GID
65649 + int "GID for auditing"
65650 + depends on GRKERNSEC_AUDIT_GROUP
65651 + default 1007
65652 +
65653 +config GRKERNSEC_EXECLOG
65654 + bool "Exec logging"
65655 + help
65656 + If you say Y here, all execve() calls will be logged (since the
65657 + other exec*() calls are frontends to execve(), all execution
65658 + will be logged). Useful for shell-servers that like to keep track
65659 + of their users. If the sysctl option is enabled, a sysctl option with
65660 + name "exec_logging" is created.
65661 + WARNING: This option when enabled will produce a LOT of logs, especially
65662 + on an active system.
65663 +
65664 +config GRKERNSEC_RESLOG
65665 + bool "Resource logging"
65666 + default y if GRKERNSEC_CONFIG_AUTO
65667 + help
65668 + If you say Y here, all attempts to overstep resource limits will
65669 + be logged with the resource name, the requested size, and the current
65670 + limit. It is highly recommended that you say Y here. If the sysctl
65671 + option is enabled, a sysctl option with name "resource_logging" is
65672 + created. If the RBAC system is enabled, the sysctl value is ignored.
65673 +
65674 +config GRKERNSEC_CHROOT_EXECLOG
65675 + bool "Log execs within chroot"
65676 + help
65677 + If you say Y here, all executions inside a chroot jail will be logged
65678 + to syslog. This can cause a large amount of logs if certain
65679 + applications (eg. djb's daemontools) are installed on the system, and
65680 + is therefore left as an option. If the sysctl option is enabled, a
65681 + sysctl option with name "chroot_execlog" is created.
65682 +
65683 +config GRKERNSEC_AUDIT_PTRACE
65684 + bool "Ptrace logging"
65685 + help
65686 + If you say Y here, all attempts to attach to a process via ptrace
65687 + will be logged. If the sysctl option is enabled, a sysctl option
65688 + with name "audit_ptrace" is created.
65689 +
65690 +config GRKERNSEC_AUDIT_CHDIR
65691 + bool "Chdir logging"
65692 + help
65693 + If you say Y here, all chdir() calls will be logged. If the sysctl
65694 + option is enabled, a sysctl option with name "audit_chdir" is created.
65695 +
65696 +config GRKERNSEC_AUDIT_MOUNT
65697 + bool "(Un)Mount logging"
65698 + help
65699 + If you say Y here, all mounts and unmounts will be logged. If the
65700 + sysctl option is enabled, a sysctl option with name "audit_mount" is
65701 + created.
65702 +
65703 +config GRKERNSEC_SIGNAL
65704 + bool "Signal logging"
65705 + default y if GRKERNSEC_CONFIG_AUTO
65706 + help
65707 + If you say Y here, certain important signals will be logged, such as
65708 + SIGSEGV, which will as a result inform you of when a error in a program
65709 + occurred, which in some cases could mean a possible exploit attempt.
65710 + If the sysctl option is enabled, a sysctl option with name
65711 + "signal_logging" is created.
65712 +
65713 +config GRKERNSEC_FORKFAIL
65714 + bool "Fork failure logging"
65715 + help
65716 + If you say Y here, all failed fork() attempts will be logged.
65717 + This could suggest a fork bomb, or someone attempting to overstep
65718 + their process limit. If the sysctl option is enabled, a sysctl option
65719 + with name "forkfail_logging" is created.
65720 +
65721 +config GRKERNSEC_TIME
65722 + bool "Time change logging"
65723 + default y if GRKERNSEC_CONFIG_AUTO
65724 + help
65725 + If you say Y here, any changes of the system clock will be logged.
65726 + If the sysctl option is enabled, a sysctl option with name
65727 + "timechange_logging" is created.
65728 +
65729 +config GRKERNSEC_PROC_IPADDR
65730 + bool "/proc/<pid>/ipaddr support"
65731 + default y if GRKERNSEC_CONFIG_AUTO
65732 + help
65733 + If you say Y here, a new entry will be added to each /proc/<pid>
65734 + directory that contains the IP address of the person using the task.
65735 + The IP is carried across local TCP and AF_UNIX stream sockets.
65736 + This information can be useful for IDS/IPSes to perform remote response
65737 + to a local attack. The entry is readable by only the owner of the
65738 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
65739 + the RBAC system), and thus does not create privacy concerns.
65740 +
65741 +config GRKERNSEC_RWXMAP_LOG
65742 + bool 'Denied RWX mmap/mprotect logging'
65743 + default y if GRKERNSEC_CONFIG_AUTO
65744 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
65745 + help
65746 + If you say Y here, calls to mmap() and mprotect() with explicit
65747 + usage of PROT_WRITE and PROT_EXEC together will be logged when
65748 + denied by the PAX_MPROTECT feature. This feature will also
65749 + log other problematic scenarios that can occur when PAX_MPROTECT
65750 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
65751 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
65752 + is created.
65753 +
65754 +endmenu
65755 +
65756 +menu "Executable Protections"
65757 +depends on GRKERNSEC
65758 +
65759 +config GRKERNSEC_DMESG
65760 + bool "Dmesg(8) restriction"
65761 + default y if GRKERNSEC_CONFIG_AUTO
65762 + help
65763 + If you say Y here, non-root users will not be able to use dmesg(8)
65764 + to view the contents of the kernel's circular log buffer.
65765 + The kernel's log buffer often contains kernel addresses and other
65766 + identifying information useful to an attacker in fingerprinting a
65767 + system for a targeted exploit.
65768 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
65769 + created.
65770 +
65771 +config GRKERNSEC_HARDEN_PTRACE
65772 + bool "Deter ptrace-based process snooping"
65773 + default y if GRKERNSEC_CONFIG_AUTO
65774 + help
65775 + If you say Y here, TTY sniffers and other malicious monitoring
65776 + programs implemented through ptrace will be defeated. If you
65777 + have been using the RBAC system, this option has already been
65778 + enabled for several years for all users, with the ability to make
65779 + fine-grained exceptions.
65780 +
65781 + This option only affects the ability of non-root users to ptrace
65782 + processes that are not a descendent of the ptracing process.
65783 + This means that strace ./binary and gdb ./binary will still work,
65784 + but attaching to arbitrary processes will not. If the sysctl
65785 + option is enabled, a sysctl option with name "harden_ptrace" is
65786 + created.
65787 +
65788 +config GRKERNSEC_PTRACE_READEXEC
65789 + bool "Require read access to ptrace sensitive binaries"
65790 + default y if GRKERNSEC_CONFIG_AUTO
65791 + help
65792 + If you say Y here, unprivileged users will not be able to ptrace unreadable
65793 + binaries. This option is useful in environments that
65794 + remove the read bits (e.g. file mode 4711) from suid binaries to
65795 + prevent infoleaking of their contents. This option adds
65796 + consistency to the use of that file mode, as the binary could normally
65797 + be read out when run without privileges while ptracing.
65798 +
65799 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
65800 + is created.
65801 +
65802 +config GRKERNSEC_SETXID
65803 + bool "Enforce consistent multithreaded privileges"
65804 + default y if GRKERNSEC_CONFIG_AUTO
65805 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
65806 + help
65807 + If you say Y here, a change from a root uid to a non-root uid
65808 + in a multithreaded application will cause the resulting uids,
65809 + gids, supplementary groups, and capabilities in that thread
65810 + to be propagated to the other threads of the process. In most
65811 + cases this is unnecessary, as glibc will emulate this behavior
65812 + on behalf of the application. Other libcs do not act in the
65813 + same way, allowing the other threads of the process to continue
65814 + running with root privileges. If the sysctl option is enabled,
65815 + a sysctl option with name "consistent_setxid" is created.
65816 +
65817 +config GRKERNSEC_HARDEN_IPC
65818 + bool "Disallow access to overly-permissive IPC objects"
65819 + default y if GRKERNSEC_CONFIG_AUTO
65820 + depends on SYSVIPC
65821 + help
65822 + If you say Y here, access to overly-permissive IPC objects (shared
65823 + memory, message queues, and semaphores) will be denied for processes
65824 + given the following criteria beyond normal permission checks:
65825 + 1) If the IPC object is world-accessible and the euid doesn't match
65826 + that of the creator or current uid for the IPC object
65827 + 2) If the IPC object is group-accessible and the egid doesn't
65828 + match that of the creator or current gid for the IPC object
65829 + It's a common error to grant too much permission to these objects,
65830 + with impact ranging from denial of service and information leaking to
65831 + privilege escalation. This feature was developed in response to
65832 + research by Tim Brown:
65833 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
65834 + who found hundreds of such insecure usages. Processes with
65835 + CAP_IPC_OWNER are still permitted to access these IPC objects.
65836 + If the sysctl option is enabled, a sysctl option with name
65837 + "harden_ipc" is created.
65838 +
65839 +config GRKERNSEC_TPE
65840 + bool "Trusted Path Execution (TPE)"
65841 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65842 + help
65843 + If you say Y here, you will be able to choose a gid to add to the
65844 + supplementary groups of users you want to mark as "untrusted."
65845 + These users will not be able to execute any files that are not in
65846 + root-owned directories writable only by root. If the sysctl option
65847 + is enabled, a sysctl option with name "tpe" is created.
65848 +
65849 +config GRKERNSEC_TPE_ALL
65850 + bool "Partially restrict all non-root users"
65851 + depends on GRKERNSEC_TPE
65852 + help
65853 + If you say Y here, all non-root users will be covered under
65854 + a weaker TPE restriction. This is separate from, and in addition to,
65855 + the main TPE options that you have selected elsewhere. Thus, if a
65856 + "trusted" GID is chosen, this restriction applies to even that GID.
65857 + Under this restriction, all non-root users will only be allowed to
65858 + execute files in directories they own that are not group or
65859 + world-writable, or in directories owned by root and writable only by
65860 + root. If the sysctl option is enabled, a sysctl option with name
65861 + "tpe_restrict_all" is created.
65862 +
65863 +config GRKERNSEC_TPE_INVERT
65864 + bool "Invert GID option"
65865 + depends on GRKERNSEC_TPE
65866 + help
65867 + If you say Y here, the group you specify in the TPE configuration will
65868 + decide what group TPE restrictions will be *disabled* for. This
65869 + option is useful if you want TPE restrictions to be applied to most
65870 + users on the system. If the sysctl option is enabled, a sysctl option
65871 + with name "tpe_invert" is created. Unlike other sysctl options, this
65872 + entry will default to on for backward-compatibility.
65873 +
65874 +config GRKERNSEC_TPE_GID
65875 + int
65876 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
65877 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
65878 +
65879 +config GRKERNSEC_TPE_UNTRUSTED_GID
65880 + int "GID for TPE-untrusted users"
65881 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
65882 + default 1005
65883 + help
65884 + Setting this GID determines what group TPE restrictions will be
65885 + *enabled* for. If the sysctl option is enabled, a sysctl option
65886 + with name "tpe_gid" is created.
65887 +
65888 +config GRKERNSEC_TPE_TRUSTED_GID
65889 + int "GID for TPE-trusted users"
65890 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
65891 + default 1005
65892 + help
65893 + Setting this GID determines what group TPE restrictions will be
65894 + *disabled* for. If the sysctl option is enabled, a sysctl option
65895 + with name "tpe_gid" is created.
65896 +
65897 +endmenu
65898 +menu "Network Protections"
65899 +depends on GRKERNSEC
65900 +
65901 +config GRKERNSEC_RANDNET
65902 + bool "Larger entropy pools"
65903 + default y if GRKERNSEC_CONFIG_AUTO
65904 + help
65905 + If you say Y here, the entropy pools used for many features of Linux
65906 + and grsecurity will be doubled in size. Since several grsecurity
65907 + features use additional randomness, it is recommended that you say Y
65908 + here. Saying Y here has a similar effect as modifying
65909 + /proc/sys/kernel/random/poolsize.
65910 +
65911 +config GRKERNSEC_BLACKHOLE
65912 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
65913 + default y if GRKERNSEC_CONFIG_AUTO
65914 + depends on NET
65915 + help
65916 + If you say Y here, neither TCP resets nor ICMP
65917 + destination-unreachable packets will be sent in response to packets
65918 + sent to ports for which no associated listening process exists.
65919 + This feature supports both IPV4 and IPV6 and exempts the
65920 + loopback interface from blackholing. Enabling this feature
65921 + makes a host more resilient to DoS attacks and reduces network
65922 + visibility against scanners.
65923 +
65924 + The blackhole feature as-implemented is equivalent to the FreeBSD
65925 + blackhole feature, as it prevents RST responses to all packets, not
65926 + just SYNs. Under most application behavior this causes no
65927 + problems, but applications (like haproxy) may not close certain
65928 + connections in a way that cleanly terminates them on the remote
65929 + end, leaving the remote host in LAST_ACK state. Because of this
65930 + side-effect and to prevent intentional LAST_ACK DoSes, this
65931 + feature also adds automatic mitigation against such attacks.
65932 + The mitigation drastically reduces the amount of time a socket
65933 + can spend in LAST_ACK state. If you're using haproxy and not
65934 + all servers it connects to have this option enabled, consider
65935 + disabling this feature on the haproxy host.
65936 +
65937 + If the sysctl option is enabled, two sysctl options with names
65938 + "ip_blackhole" and "lastack_retries" will be created.
65939 + While "ip_blackhole" takes the standard zero/non-zero on/off
65940 + toggle, "lastack_retries" uses the same kinds of values as
65941 + "tcp_retries1" and "tcp_retries2". The default value of 4
65942 + prevents a socket from lasting more than 45 seconds in LAST_ACK
65943 + state.
65944 +
65945 +config GRKERNSEC_NO_SIMULT_CONNECT
65946 + bool "Disable TCP Simultaneous Connect"
65947 + default y if GRKERNSEC_CONFIG_AUTO
65948 + depends on NET
65949 + help
65950 + If you say Y here, a feature by Willy Tarreau will be enabled that
65951 + removes a weakness in Linux's strict implementation of TCP that
65952 + allows two clients to connect to each other without either entering
65953 + a listening state. The weakness allows an attacker to easily prevent
65954 + a client from connecting to a known server provided the source port
65955 + for the connection is guessed correctly.
65956 +
65957 + As the weakness could be used to prevent an antivirus or IPS from
65958 + fetching updates, or prevent an SSL gateway from fetching a CRL,
65959 + it should be eliminated by enabling this option. Though Linux is
65960 + one of few operating systems supporting simultaneous connect, it
65961 + has no legitimate use in practice and is rarely supported by firewalls.
65962 +
65963 +config GRKERNSEC_SOCKET
65964 + bool "Socket restrictions"
65965 + depends on NET
65966 + help
65967 + If you say Y here, you will be able to choose from several options.
65968 + If you assign a GID on your system and add it to the supplementary
65969 + groups of users you want to restrict socket access to, this patch
65970 + will perform up to three things, based on the option(s) you choose.
65971 +
65972 +config GRKERNSEC_SOCKET_ALL
65973 + bool "Deny any sockets to group"
65974 + depends on GRKERNSEC_SOCKET
65975 + help
65976 + If you say Y here, you will be able to choose a GID of whose users will
65977 + be unable to connect to other hosts from your machine or run server
65978 + applications from your machine. If the sysctl option is enabled, a
65979 + sysctl option with name "socket_all" is created.
65980 +
65981 +config GRKERNSEC_SOCKET_ALL_GID
65982 + int "GID to deny all sockets for"
65983 + depends on GRKERNSEC_SOCKET_ALL
65984 + default 1004
65985 + help
65986 + Here you can choose the GID to disable socket access for. Remember to
65987 + add the users you want socket access disabled for to the GID
65988 + specified here. If the sysctl option is enabled, a sysctl option
65989 + with name "socket_all_gid" is created.
65990 +
65991 +config GRKERNSEC_SOCKET_CLIENT
65992 + bool "Deny client sockets to group"
65993 + depends on GRKERNSEC_SOCKET
65994 + help
65995 + If you say Y here, you will be able to choose a GID of whose users will
65996 + be unable to connect to other hosts from your machine, but will be
65997 + able to run servers. If this option is enabled, all users in the group
65998 + you specify will have to use passive mode when initiating ftp transfers
65999 + from the shell on your machine. If the sysctl option is enabled, a
66000 + sysctl option with name "socket_client" is created.
66001 +
66002 +config GRKERNSEC_SOCKET_CLIENT_GID
66003 + int "GID to deny client sockets for"
66004 + depends on GRKERNSEC_SOCKET_CLIENT
66005 + default 1003
66006 + help
66007 + Here you can choose the GID to disable client socket access for.
66008 + Remember to add the users you want client socket access disabled for to
66009 + the GID specified here. If the sysctl option is enabled, a sysctl
66010 + option with name "socket_client_gid" is created.
66011 +
66012 +config GRKERNSEC_SOCKET_SERVER
66013 + bool "Deny server sockets to group"
66014 + depends on GRKERNSEC_SOCKET
66015 + help
66016 + If you say Y here, you will be able to choose a GID of whose users will
66017 + be unable to run server applications from your machine. If the sysctl
66018 + option is enabled, a sysctl option with name "socket_server" is created.
66019 +
66020 +config GRKERNSEC_SOCKET_SERVER_GID
66021 + int "GID to deny server sockets for"
66022 + depends on GRKERNSEC_SOCKET_SERVER
66023 + default 1002
66024 + help
66025 + Here you can choose the GID to disable server socket access for.
66026 + Remember to add the users you want server socket access disabled for to
66027 + the GID specified here. If the sysctl option is enabled, a sysctl
66028 + option with name "socket_server_gid" is created.
66029 +
66030 +endmenu
66031 +
66032 +menu "Physical Protections"
66033 +depends on GRKERNSEC
66034 +
66035 +config GRKERNSEC_DENYUSB
66036 + bool "Deny new USB connections after toggle"
66037 + default y if GRKERNSEC_CONFIG_AUTO
66038 + depends on SYSCTL && USB_SUPPORT
66039 + help
66040 + If you say Y here, a new sysctl option with name "deny_new_usb"
66041 + will be created. Setting its value to 1 will prevent any new
66042 + USB devices from being recognized by the OS. Any attempted USB
66043 + device insertion will be logged. This option is intended to be
66044 + used against custom USB devices designed to exploit vulnerabilities
66045 + in various USB device drivers.
66046 +
66047 + For greatest effectiveness, this sysctl should be set after any
66048 + relevant init scripts. This option is safe to enable in distros
66049 + as each user can choose whether or not to toggle the sysctl.
66050 +
66051 +config GRKERNSEC_DENYUSB_FORCE
66052 + bool "Reject all USB devices not connected at boot"
66053 + select USB
66054 + depends on GRKERNSEC_DENYUSB
66055 + help
66056 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66057 + that doesn't involve a sysctl entry. This option should only be
66058 + enabled if you're sure you want to deny all new USB connections
66059 + at runtime and don't want to modify init scripts. This should not
66060 + be enabled by distros. It forces the core USB code to be built
66061 + into the kernel image so that all devices connected at boot time
66062 + can be recognized and new USB device connections can be prevented
66063 + prior to init running.
66064 +
66065 +endmenu
66066 +
66067 +menu "Sysctl Support"
66068 +depends on GRKERNSEC && SYSCTL
66069 +
66070 +config GRKERNSEC_SYSCTL
66071 + bool "Sysctl support"
66072 + default y if GRKERNSEC_CONFIG_AUTO
66073 + help
66074 + If you say Y here, you will be able to change the options that
66075 + grsecurity runs with at bootup, without having to recompile your
66076 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66077 + to enable (1) or disable (0) various features. All the sysctl entries
66078 + are mutable until the "grsec_lock" entry is set to a non-zero value.
66079 + All features enabled in the kernel configuration are disabled at boot
66080 + if you do not say Y to the "Turn on features by default" option.
66081 + All options should be set at startup, and the grsec_lock entry should
66082 + be set to a non-zero value after all the options are set.
66083 + *THIS IS EXTREMELY IMPORTANT*
66084 +
66085 +config GRKERNSEC_SYSCTL_DISTRO
66086 + bool "Extra sysctl support for distro makers (READ HELP)"
66087 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66088 + help
66089 + If you say Y here, additional sysctl options will be created
66090 + for features that affect processes running as root. Therefore,
66091 + it is critical when using this option that the grsec_lock entry be
66092 + enabled after boot. Only distros with prebuilt kernel packages
66093 + with this option enabled that can ensure grsec_lock is enabled
66094 + after boot should use this option.
66095 + *Failure to set grsec_lock after boot makes all grsec features
66096 + this option covers useless*
66097 +
66098 + Currently this option creates the following sysctl entries:
66099 + "Disable Privileged I/O": "disable_priv_io"
66100 +
66101 +config GRKERNSEC_SYSCTL_ON
66102 + bool "Turn on features by default"
66103 + default y if GRKERNSEC_CONFIG_AUTO
66104 + depends on GRKERNSEC_SYSCTL
66105 + help
66106 + If you say Y here, instead of having all features enabled in the
66107 + kernel configuration disabled at boot time, the features will be
66108 + enabled at boot time. It is recommended you say Y here unless
66109 + there is some reason you would want all sysctl-tunable features to
66110 + be disabled by default. As mentioned elsewhere, it is important
66111 + to enable the grsec_lock entry once you have finished modifying
66112 + the sysctl entries.
66113 +
66114 +endmenu
66115 +menu "Logging Options"
66116 +depends on GRKERNSEC
66117 +
66118 +config GRKERNSEC_FLOODTIME
66119 + int "Seconds in between log messages (minimum)"
66120 + default 10
66121 + help
66122 + This option allows you to enforce the number of seconds between
66123 + grsecurity log messages. The default should be suitable for most
66124 + people, however, if you choose to change it, choose a value small enough
66125 + to allow informative logs to be produced, but large enough to
66126 + prevent flooding.
66127 +
66128 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66129 + any rate limiting on grsecurity log messages.
66130 +
66131 +config GRKERNSEC_FLOODBURST
66132 + int "Number of messages in a burst (maximum)"
66133 + default 6
66134 + help
66135 + This option allows you to choose the maximum number of messages allowed
66136 + within the flood time interval you chose in a separate option. The
66137 + default should be suitable for most people, however if you find that
66138 + many of your logs are being interpreted as flooding, you may want to
66139 + raise this value.
66140 +
66141 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66142 + any rate limiting on grsecurity log messages.
66143 +
66144 +endmenu
66145 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66146 new file mode 100644
66147 index 0000000..5307c8a
66148 --- /dev/null
66149 +++ b/grsecurity/Makefile
66150 @@ -0,0 +1,54 @@
66151 +# grsecurity – access control and security hardening for Linux
66152 +# All code in this directory and various hooks located throughout the Linux kernel are
66153 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66154 +# http://www.grsecurity.net spender@grsecurity.net
66155 +#
66156 +# This program is free software; you can redistribute it and/or
66157 +# modify it under the terms of the GNU General Public License version 2
66158 +# as published by the Free Software Foundation.
66159 +#
66160 +# This program is distributed in the hope that it will be useful,
66161 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
66162 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66163 +# GNU General Public License for more details.
66164 +#
66165 +# You should have received a copy of the GNU General Public License
66166 +# along with this program; if not, write to the Free Software
66167 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66168 +
66169 +KBUILD_CFLAGS += -Werror
66170 +
66171 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66172 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
66173 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66174 + grsec_usb.o grsec_ipc.o
66175 +
66176 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66177 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66178 + gracl_learn.o grsec_log.o gracl_policy.o
66179 +ifdef CONFIG_COMPAT
66180 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66181 +endif
66182 +
66183 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66184 +
66185 +ifdef CONFIG_NET
66186 +obj-y += grsec_sock.o
66187 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66188 +endif
66189 +
66190 +ifndef CONFIG_GRKERNSEC
66191 +obj-y += grsec_disabled.o
66192 +endif
66193 +
66194 +ifdef CONFIG_GRKERNSEC_HIDESYM
66195 +extra-y := grsec_hidesym.o
66196 +$(obj)/grsec_hidesym.o:
66197 + @-chmod -f 500 /boot
66198 + @-chmod -f 500 /lib/modules
66199 + @-chmod -f 500 /lib64/modules
66200 + @-chmod -f 500 /lib32/modules
66201 + @-chmod -f 700 .
66202 + @-chmod -f 700 $(objtree)
66203 + @echo ' grsec: protected kernel image paths'
66204 +endif
66205 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66206 new file mode 100644
66207 index 0000000..e56396f
66208 --- /dev/null
66209 +++ b/grsecurity/gracl.c
66210 @@ -0,0 +1,2679 @@
66211 +#include <linux/kernel.h>
66212 +#include <linux/module.h>
66213 +#include <linux/sched.h>
66214 +#include <linux/mm.h>
66215 +#include <linux/file.h>
66216 +#include <linux/fs.h>
66217 +#include <linux/namei.h>
66218 +#include <linux/mount.h>
66219 +#include <linux/tty.h>
66220 +#include <linux/proc_fs.h>
66221 +#include <linux/lglock.h>
66222 +#include <linux/slab.h>
66223 +#include <linux/vmalloc.h>
66224 +#include <linux/types.h>
66225 +#include <linux/sysctl.h>
66226 +#include <linux/netdevice.h>
66227 +#include <linux/ptrace.h>
66228 +#include <linux/gracl.h>
66229 +#include <linux/gralloc.h>
66230 +#include <linux/security.h>
66231 +#include <linux/grinternal.h>
66232 +#include <linux/pid_namespace.h>
66233 +#include <linux/stop_machine.h>
66234 +#include <linux/fdtable.h>
66235 +#include <linux/percpu.h>
66236 +#include <linux/lglock.h>
66237 +#include <linux/hugetlb.h>
66238 +#include <linux/posix-timers.h>
66239 +#include <linux/prefetch.h>
66240 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66241 +#include <linux/magic.h>
66242 +#include <linux/pagemap.h>
66243 +#include "../fs/btrfs/async-thread.h"
66244 +#include "../fs/btrfs/ctree.h"
66245 +#include "../fs/btrfs/btrfs_inode.h"
66246 +#endif
66247 +#include "../fs/mount.h"
66248 +
66249 +#include <asm/uaccess.h>
66250 +#include <asm/errno.h>
66251 +#include <asm/mman.h>
66252 +
66253 +#define FOR_EACH_ROLE_START(role) \
66254 + role = running_polstate.role_list; \
66255 + while (role) {
66256 +
66257 +#define FOR_EACH_ROLE_END(role) \
66258 + role = role->prev; \
66259 + }
66260 +
66261 +extern struct path gr_real_root;
66262 +
66263 +static struct gr_policy_state running_polstate;
66264 +struct gr_policy_state *polstate = &running_polstate;
66265 +extern struct gr_alloc_state *current_alloc_state;
66266 +
66267 +extern char *gr_shared_page[4];
66268 +DEFINE_RWLOCK(gr_inode_lock);
66269 +
66270 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
66271 +
66272 +#ifdef CONFIG_NET
66273 +extern struct vfsmount *sock_mnt;
66274 +#endif
66275 +
66276 +extern struct vfsmount *pipe_mnt;
66277 +extern struct vfsmount *shm_mnt;
66278 +
66279 +#ifdef CONFIG_HUGETLBFS
66280 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66281 +#endif
66282 +
66283 +extern u16 acl_sp_role_value;
66284 +extern struct acl_object_label *fakefs_obj_rw;
66285 +extern struct acl_object_label *fakefs_obj_rwx;
66286 +
66287 +int gr_acl_is_enabled(void)
66288 +{
66289 + return (gr_status & GR_READY);
66290 +}
66291 +
66292 +void gr_enable_rbac_system(void)
66293 +{
66294 + pax_open_kernel();
66295 + gr_status |= GR_READY;
66296 + pax_close_kernel();
66297 +}
66298 +
66299 +int gr_rbac_disable(void *unused)
66300 +{
66301 + pax_open_kernel();
66302 + gr_status &= ~GR_READY;
66303 + pax_close_kernel();
66304 +
66305 + return 0;
66306 +}
66307 +
66308 +static inline dev_t __get_dev(const struct dentry *dentry)
66309 +{
66310 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66311 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66312 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
66313 + else
66314 +#endif
66315 + return dentry->d_sb->s_dev;
66316 +}
66317 +
66318 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66319 +{
66320 + return __get_dev(dentry);
66321 +}
66322 +
66323 +static char gr_task_roletype_to_char(struct task_struct *task)
66324 +{
66325 + switch (task->role->roletype &
66326 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66327 + GR_ROLE_SPECIAL)) {
66328 + case GR_ROLE_DEFAULT:
66329 + return 'D';
66330 + case GR_ROLE_USER:
66331 + return 'U';
66332 + case GR_ROLE_GROUP:
66333 + return 'G';
66334 + case GR_ROLE_SPECIAL:
66335 + return 'S';
66336 + }
66337 +
66338 + return 'X';
66339 +}
66340 +
66341 +char gr_roletype_to_char(void)
66342 +{
66343 + return gr_task_roletype_to_char(current);
66344 +}
66345 +
66346 +__inline__ int
66347 +gr_acl_tpe_check(void)
66348 +{
66349 + if (unlikely(!(gr_status & GR_READY)))
66350 + return 0;
66351 + if (current->role->roletype & GR_ROLE_TPE)
66352 + return 1;
66353 + else
66354 + return 0;
66355 +}
66356 +
66357 +int
66358 +gr_handle_rawio(const struct inode *inode)
66359 +{
66360 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66361 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66362 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66363 + !capable(CAP_SYS_RAWIO))
66364 + return 1;
66365 +#endif
66366 + return 0;
66367 +}
66368 +
66369 +int
66370 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66371 +{
66372 + if (likely(lena != lenb))
66373 + return 0;
66374 +
66375 + return !memcmp(a, b, lena);
66376 +}
66377 +
66378 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66379 +{
66380 + *buflen -= namelen;
66381 + if (*buflen < 0)
66382 + return -ENAMETOOLONG;
66383 + *buffer -= namelen;
66384 + memcpy(*buffer, str, namelen);
66385 + return 0;
66386 +}
66387 +
66388 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66389 +{
66390 + return prepend(buffer, buflen, name->name, name->len);
66391 +}
66392 +
66393 +static int prepend_path(const struct path *path, struct path *root,
66394 + char **buffer, int *buflen)
66395 +{
66396 + struct dentry *dentry = path->dentry;
66397 + struct vfsmount *vfsmnt = path->mnt;
66398 + struct mount *mnt = real_mount(vfsmnt);
66399 + bool slash = false;
66400 + int error = 0;
66401 +
66402 + while (dentry != root->dentry || vfsmnt != root->mnt) {
66403 + struct dentry * parent;
66404 +
66405 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66406 + /* Global root? */
66407 + if (!mnt_has_parent(mnt)) {
66408 + goto out;
66409 + }
66410 + dentry = mnt->mnt_mountpoint;
66411 + mnt = mnt->mnt_parent;
66412 + vfsmnt = &mnt->mnt;
66413 + continue;
66414 + }
66415 + parent = dentry->d_parent;
66416 + prefetch(parent);
66417 + spin_lock(&dentry->d_lock);
66418 + error = prepend_name(buffer, buflen, &dentry->d_name);
66419 + spin_unlock(&dentry->d_lock);
66420 + if (!error)
66421 + error = prepend(buffer, buflen, "/", 1);
66422 + if (error)
66423 + break;
66424 +
66425 + slash = true;
66426 + dentry = parent;
66427 + }
66428 +
66429 +out:
66430 + if (!error && !slash)
66431 + error = prepend(buffer, buflen, "/", 1);
66432 +
66433 + return error;
66434 +}
66435 +
66436 +/* this must be called with mount_lock and rename_lock held */
66437 +
66438 +static char *__our_d_path(const struct path *path, struct path *root,
66439 + char *buf, int buflen)
66440 +{
66441 + char *res = buf + buflen;
66442 + int error;
66443 +
66444 + prepend(&res, &buflen, "\0", 1);
66445 + error = prepend_path(path, root, &res, &buflen);
66446 + if (error)
66447 + return ERR_PTR(error);
66448 +
66449 + return res;
66450 +}
66451 +
66452 +static char *
66453 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66454 +{
66455 + char *retval;
66456 +
66457 + retval = __our_d_path(path, root, buf, buflen);
66458 + if (unlikely(IS_ERR(retval)))
66459 + retval = strcpy(buf, "<path too long>");
66460 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66461 + retval[1] = '\0';
66462 +
66463 + return retval;
66464 +}
66465 +
66466 +static char *
66467 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66468 + char *buf, int buflen)
66469 +{
66470 + struct path path;
66471 + char *res;
66472 +
66473 + path.dentry = (struct dentry *)dentry;
66474 + path.mnt = (struct vfsmount *)vfsmnt;
66475 +
66476 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66477 + by the RBAC system */
66478 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
66479 +
66480 + return res;
66481 +}
66482 +
66483 +static char *
66484 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66485 + char *buf, int buflen)
66486 +{
66487 + char *res;
66488 + struct path path;
66489 + struct path root;
66490 + struct task_struct *reaper = init_pid_ns.child_reaper;
66491 +
66492 + path.dentry = (struct dentry *)dentry;
66493 + path.mnt = (struct vfsmount *)vfsmnt;
66494 +
66495 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
66496 + get_fs_root(reaper->fs, &root);
66497 +
66498 + read_seqlock_excl(&mount_lock);
66499 + write_seqlock(&rename_lock);
66500 + res = gen_full_path(&path, &root, buf, buflen);
66501 + write_sequnlock(&rename_lock);
66502 + read_sequnlock_excl(&mount_lock);
66503 +
66504 + path_put(&root);
66505 + return res;
66506 +}
66507 +
66508 +char *
66509 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66510 +{
66511 + char *ret;
66512 + read_seqlock_excl(&mount_lock);
66513 + write_seqlock(&rename_lock);
66514 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66515 + PAGE_SIZE);
66516 + write_sequnlock(&rename_lock);
66517 + read_sequnlock_excl(&mount_lock);
66518 + return ret;
66519 +}
66520 +
66521 +static char *
66522 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66523 +{
66524 + char *ret;
66525 + char *buf;
66526 + int buflen;
66527 +
66528 + read_seqlock_excl(&mount_lock);
66529 + write_seqlock(&rename_lock);
66530 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
66531 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
66532 + buflen = (int)(ret - buf);
66533 + if (buflen >= 5)
66534 + prepend(&ret, &buflen, "/proc", 5);
66535 + else
66536 + ret = strcpy(buf, "<path too long>");
66537 + write_sequnlock(&rename_lock);
66538 + read_sequnlock_excl(&mount_lock);
66539 + return ret;
66540 +}
66541 +
66542 +char *
66543 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
66544 +{
66545 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66546 + PAGE_SIZE);
66547 +}
66548 +
66549 +char *
66550 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
66551 +{
66552 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66553 + PAGE_SIZE);
66554 +}
66555 +
66556 +char *
66557 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
66558 +{
66559 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
66560 + PAGE_SIZE);
66561 +}
66562 +
66563 +char *
66564 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
66565 +{
66566 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
66567 + PAGE_SIZE);
66568 +}
66569 +
66570 +char *
66571 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
66572 +{
66573 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
66574 + PAGE_SIZE);
66575 +}
66576 +
66577 +__inline__ __u32
66578 +to_gr_audit(const __u32 reqmode)
66579 +{
66580 + /* masks off auditable permission flags, then shifts them to create
66581 + auditing flags, and adds the special case of append auditing if
66582 + we're requesting write */
66583 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
66584 +}
66585 +
66586 +struct acl_role_label *
66587 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
66588 + const gid_t gid)
66589 +{
66590 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
66591 + struct acl_role_label *match;
66592 + struct role_allowed_ip *ipp;
66593 + unsigned int x;
66594 + u32 curr_ip = task->signal->saved_ip;
66595 +
66596 + match = state->acl_role_set.r_hash[index];
66597 +
66598 + while (match) {
66599 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
66600 + for (x = 0; x < match->domain_child_num; x++) {
66601 + if (match->domain_children[x] == uid)
66602 + goto found;
66603 + }
66604 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
66605 + break;
66606 + match = match->next;
66607 + }
66608 +found:
66609 + if (match == NULL) {
66610 + try_group:
66611 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
66612 + match = state->acl_role_set.r_hash[index];
66613 +
66614 + while (match) {
66615 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
66616 + for (x = 0; x < match->domain_child_num; x++) {
66617 + if (match->domain_children[x] == gid)
66618 + goto found2;
66619 + }
66620 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
66621 + break;
66622 + match = match->next;
66623 + }
66624 +found2:
66625 + if (match == NULL)
66626 + match = state->default_role;
66627 + if (match->allowed_ips == NULL)
66628 + return match;
66629 + else {
66630 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66631 + if (likely
66632 + ((ntohl(curr_ip) & ipp->netmask) ==
66633 + (ntohl(ipp->addr) & ipp->netmask)))
66634 + return match;
66635 + }
66636 + match = state->default_role;
66637 + }
66638 + } else if (match->allowed_ips == NULL) {
66639 + return match;
66640 + } else {
66641 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66642 + if (likely
66643 + ((ntohl(curr_ip) & ipp->netmask) ==
66644 + (ntohl(ipp->addr) & ipp->netmask)))
66645 + return match;
66646 + }
66647 + goto try_group;
66648 + }
66649 +
66650 + return match;
66651 +}
66652 +
66653 +static struct acl_role_label *
66654 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
66655 + const gid_t gid)
66656 +{
66657 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
66658 +}
66659 +
66660 +struct acl_subject_label *
66661 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
66662 + const struct acl_role_label *role)
66663 +{
66664 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66665 + struct acl_subject_label *match;
66666 +
66667 + match = role->subj_hash[index];
66668 +
66669 + while (match && (match->inode != ino || match->device != dev ||
66670 + (match->mode & GR_DELETED))) {
66671 + match = match->next;
66672 + }
66673 +
66674 + if (match && !(match->mode & GR_DELETED))
66675 + return match;
66676 + else
66677 + return NULL;
66678 +}
66679 +
66680 +struct acl_subject_label *
66681 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
66682 + const struct acl_role_label *role)
66683 +{
66684 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66685 + struct acl_subject_label *match;
66686 +
66687 + match = role->subj_hash[index];
66688 +
66689 + while (match && (match->inode != ino || match->device != dev ||
66690 + !(match->mode & GR_DELETED))) {
66691 + match = match->next;
66692 + }
66693 +
66694 + if (match && (match->mode & GR_DELETED))
66695 + return match;
66696 + else
66697 + return NULL;
66698 +}
66699 +
66700 +static struct acl_object_label *
66701 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
66702 + const struct acl_subject_label *subj)
66703 +{
66704 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66705 + struct acl_object_label *match;
66706 +
66707 + match = subj->obj_hash[index];
66708 +
66709 + while (match && (match->inode != ino || match->device != dev ||
66710 + (match->mode & GR_DELETED))) {
66711 + match = match->next;
66712 + }
66713 +
66714 + if (match && !(match->mode & GR_DELETED))
66715 + return match;
66716 + else
66717 + return NULL;
66718 +}
66719 +
66720 +static struct acl_object_label *
66721 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
66722 + const struct acl_subject_label *subj)
66723 +{
66724 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66725 + struct acl_object_label *match;
66726 +
66727 + match = subj->obj_hash[index];
66728 +
66729 + while (match && (match->inode != ino || match->device != dev ||
66730 + !(match->mode & GR_DELETED))) {
66731 + match = match->next;
66732 + }
66733 +
66734 + if (match && (match->mode & GR_DELETED))
66735 + return match;
66736 +
66737 + match = subj->obj_hash[index];
66738 +
66739 + while (match && (match->inode != ino || match->device != dev ||
66740 + (match->mode & GR_DELETED))) {
66741 + match = match->next;
66742 + }
66743 +
66744 + if (match && !(match->mode & GR_DELETED))
66745 + return match;
66746 + else
66747 + return NULL;
66748 +}
66749 +
66750 +struct name_entry *
66751 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
66752 +{
66753 + unsigned int len = strlen(name);
66754 + unsigned int key = full_name_hash(name, len);
66755 + unsigned int index = key % state->name_set.n_size;
66756 + struct name_entry *match;
66757 +
66758 + match = state->name_set.n_hash[index];
66759 +
66760 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
66761 + match = match->next;
66762 +
66763 + return match;
66764 +}
66765 +
66766 +static struct name_entry *
66767 +lookup_name_entry(const char *name)
66768 +{
66769 + return __lookup_name_entry(&running_polstate, name);
66770 +}
66771 +
66772 +static struct name_entry *
66773 +lookup_name_entry_create(const char *name)
66774 +{
66775 + unsigned int len = strlen(name);
66776 + unsigned int key = full_name_hash(name, len);
66777 + unsigned int index = key % running_polstate.name_set.n_size;
66778 + struct name_entry *match;
66779 +
66780 + match = running_polstate.name_set.n_hash[index];
66781 +
66782 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66783 + !match->deleted))
66784 + match = match->next;
66785 +
66786 + if (match && match->deleted)
66787 + return match;
66788 +
66789 + match = running_polstate.name_set.n_hash[index];
66790 +
66791 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66792 + match->deleted))
66793 + match = match->next;
66794 +
66795 + if (match && !match->deleted)
66796 + return match;
66797 + else
66798 + return NULL;
66799 +}
66800 +
66801 +static struct inodev_entry *
66802 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
66803 +{
66804 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
66805 + struct inodev_entry *match;
66806 +
66807 + match = running_polstate.inodev_set.i_hash[index];
66808 +
66809 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
66810 + match = match->next;
66811 +
66812 + return match;
66813 +}
66814 +
66815 +void
66816 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
66817 +{
66818 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
66819 + state->inodev_set.i_size);
66820 + struct inodev_entry **curr;
66821 +
66822 + entry->prev = NULL;
66823 +
66824 + curr = &state->inodev_set.i_hash[index];
66825 + if (*curr != NULL)
66826 + (*curr)->prev = entry;
66827 +
66828 + entry->next = *curr;
66829 + *curr = entry;
66830 +
66831 + return;
66832 +}
66833 +
66834 +static void
66835 +insert_inodev_entry(struct inodev_entry *entry)
66836 +{
66837 + __insert_inodev_entry(&running_polstate, entry);
66838 +}
66839 +
66840 +void
66841 +insert_acl_obj_label(struct acl_object_label *obj,
66842 + struct acl_subject_label *subj)
66843 +{
66844 + unsigned int index =
66845 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
66846 + struct acl_object_label **curr;
66847 +
66848 + obj->prev = NULL;
66849 +
66850 + curr = &subj->obj_hash[index];
66851 + if (*curr != NULL)
66852 + (*curr)->prev = obj;
66853 +
66854 + obj->next = *curr;
66855 + *curr = obj;
66856 +
66857 + return;
66858 +}
66859 +
66860 +void
66861 +insert_acl_subj_label(struct acl_subject_label *obj,
66862 + struct acl_role_label *role)
66863 +{
66864 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
66865 + struct acl_subject_label **curr;
66866 +
66867 + obj->prev = NULL;
66868 +
66869 + curr = &role->subj_hash[index];
66870 + if (*curr != NULL)
66871 + (*curr)->prev = obj;
66872 +
66873 + obj->next = *curr;
66874 + *curr = obj;
66875 +
66876 + return;
66877 +}
66878 +
66879 +/* derived from glibc fnmatch() 0: match, 1: no match*/
66880 +
66881 +static int
66882 +glob_match(const char *p, const char *n)
66883 +{
66884 + char c;
66885 +
66886 + while ((c = *p++) != '\0') {
66887 + switch (c) {
66888 + case '?':
66889 + if (*n == '\0')
66890 + return 1;
66891 + else if (*n == '/')
66892 + return 1;
66893 + break;
66894 + case '\\':
66895 + if (*n != c)
66896 + return 1;
66897 + break;
66898 + case '*':
66899 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
66900 + if (*n == '/')
66901 + return 1;
66902 + else if (c == '?') {
66903 + if (*n == '\0')
66904 + return 1;
66905 + else
66906 + ++n;
66907 + }
66908 + }
66909 + if (c == '\0') {
66910 + return 0;
66911 + } else {
66912 + const char *endp;
66913 +
66914 + if ((endp = strchr(n, '/')) == NULL)
66915 + endp = n + strlen(n);
66916 +
66917 + if (c == '[') {
66918 + for (--p; n < endp; ++n)
66919 + if (!glob_match(p, n))
66920 + return 0;
66921 + } else if (c == '/') {
66922 + while (*n != '\0' && *n != '/')
66923 + ++n;
66924 + if (*n == '/' && !glob_match(p, n + 1))
66925 + return 0;
66926 + } else {
66927 + for (--p; n < endp; ++n)
66928 + if (*n == c && !glob_match(p, n))
66929 + return 0;
66930 + }
66931 +
66932 + return 1;
66933 + }
66934 + case '[':
66935 + {
66936 + int not;
66937 + char cold;
66938 +
66939 + if (*n == '\0' || *n == '/')
66940 + return 1;
66941 +
66942 + not = (*p == '!' || *p == '^');
66943 + if (not)
66944 + ++p;
66945 +
66946 + c = *p++;
66947 + for (;;) {
66948 + unsigned char fn = (unsigned char)*n;
66949 +
66950 + if (c == '\0')
66951 + return 1;
66952 + else {
66953 + if (c == fn)
66954 + goto matched;
66955 + cold = c;
66956 + c = *p++;
66957 +
66958 + if (c == '-' && *p != ']') {
66959 + unsigned char cend = *p++;
66960 +
66961 + if (cend == '\0')
66962 + return 1;
66963 +
66964 + if (cold <= fn && fn <= cend)
66965 + goto matched;
66966 +
66967 + c = *p++;
66968 + }
66969 + }
66970 +
66971 + if (c == ']')
66972 + break;
66973 + }
66974 + if (!not)
66975 + return 1;
66976 + break;
66977 + matched:
66978 + while (c != ']') {
66979 + if (c == '\0')
66980 + return 1;
66981 +
66982 + c = *p++;
66983 + }
66984 + if (not)
66985 + return 1;
66986 + }
66987 + break;
66988 + default:
66989 + if (c != *n)
66990 + return 1;
66991 + }
66992 +
66993 + ++n;
66994 + }
66995 +
66996 + if (*n == '\0')
66997 + return 0;
66998 +
66999 + if (*n == '/')
67000 + return 0;
67001 +
67002 + return 1;
67003 +}
67004 +
67005 +static struct acl_object_label *
67006 +chk_glob_label(struct acl_object_label *globbed,
67007 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67008 +{
67009 + struct acl_object_label *tmp;
67010 +
67011 + if (*path == NULL)
67012 + *path = gr_to_filename_nolock(dentry, mnt);
67013 +
67014 + tmp = globbed;
67015 +
67016 + while (tmp) {
67017 + if (!glob_match(tmp->filename, *path))
67018 + return tmp;
67019 + tmp = tmp->next;
67020 + }
67021 +
67022 + return NULL;
67023 +}
67024 +
67025 +static struct acl_object_label *
67026 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67027 + const ino_t curr_ino, const dev_t curr_dev,
67028 + const struct acl_subject_label *subj, char **path, const int checkglob)
67029 +{
67030 + struct acl_subject_label *tmpsubj;
67031 + struct acl_object_label *retval;
67032 + struct acl_object_label *retval2;
67033 +
67034 + tmpsubj = (struct acl_subject_label *) subj;
67035 + read_lock(&gr_inode_lock);
67036 + do {
67037 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67038 + if (retval) {
67039 + if (checkglob && retval->globbed) {
67040 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67041 + if (retval2)
67042 + retval = retval2;
67043 + }
67044 + break;
67045 + }
67046 + } while ((tmpsubj = tmpsubj->parent_subject));
67047 + read_unlock(&gr_inode_lock);
67048 +
67049 + return retval;
67050 +}
67051 +
67052 +static __inline__ struct acl_object_label *
67053 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67054 + struct dentry *curr_dentry,
67055 + const struct acl_subject_label *subj, char **path, const int checkglob)
67056 +{
67057 + int newglob = checkglob;
67058 + ino_t inode;
67059 + dev_t device;
67060 +
67061 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67062 + as we don't want a / * rule to match instead of the / object
67063 + don't do this for create lookups that call this function though, since they're looking up
67064 + on the parent and thus need globbing checks on all paths
67065 + */
67066 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67067 + newglob = GR_NO_GLOB;
67068 +
67069 + spin_lock(&curr_dentry->d_lock);
67070 + inode = curr_dentry->d_inode->i_ino;
67071 + device = __get_dev(curr_dentry);
67072 + spin_unlock(&curr_dentry->d_lock);
67073 +
67074 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67075 +}
67076 +
67077 +#ifdef CONFIG_HUGETLBFS
67078 +static inline bool
67079 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
67080 +{
67081 + int i;
67082 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67083 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67084 + return true;
67085 + }
67086 +
67087 + return false;
67088 +}
67089 +#endif
67090 +
67091 +static struct acl_object_label *
67092 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67093 + const struct acl_subject_label *subj, char *path, const int checkglob)
67094 +{
67095 + struct dentry *dentry = (struct dentry *) l_dentry;
67096 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67097 + struct mount *real_mnt = real_mount(mnt);
67098 + struct acl_object_label *retval;
67099 + struct dentry *parent;
67100 +
67101 + read_seqlock_excl(&mount_lock);
67102 + write_seqlock(&rename_lock);
67103 +
67104 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67105 +#ifdef CONFIG_NET
67106 + mnt == sock_mnt ||
67107 +#endif
67108 +#ifdef CONFIG_HUGETLBFS
67109 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67110 +#endif
67111 + /* ignore Eric Biederman */
67112 + IS_PRIVATE(l_dentry->d_inode))) {
67113 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67114 + goto out;
67115 + }
67116 +
67117 + for (;;) {
67118 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67119 + break;
67120 +
67121 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67122 + if (!mnt_has_parent(real_mnt))
67123 + break;
67124 +
67125 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67126 + if (retval != NULL)
67127 + goto out;
67128 +
67129 + dentry = real_mnt->mnt_mountpoint;
67130 + real_mnt = real_mnt->mnt_parent;
67131 + mnt = &real_mnt->mnt;
67132 + continue;
67133 + }
67134 +
67135 + parent = dentry->d_parent;
67136 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67137 + if (retval != NULL)
67138 + goto out;
67139 +
67140 + dentry = parent;
67141 + }
67142 +
67143 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67144 +
67145 + /* gr_real_root is pinned so we don't have to hold a reference */
67146 + if (retval == NULL)
67147 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67148 +out:
67149 + write_sequnlock(&rename_lock);
67150 + read_sequnlock_excl(&mount_lock);
67151 +
67152 + BUG_ON(retval == NULL);
67153 +
67154 + return retval;
67155 +}
67156 +
67157 +static __inline__ struct acl_object_label *
67158 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67159 + const struct acl_subject_label *subj)
67160 +{
67161 + char *path = NULL;
67162 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67163 +}
67164 +
67165 +static __inline__ struct acl_object_label *
67166 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67167 + const struct acl_subject_label *subj)
67168 +{
67169 + char *path = NULL;
67170 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67171 +}
67172 +
67173 +static __inline__ struct acl_object_label *
67174 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67175 + const struct acl_subject_label *subj, char *path)
67176 +{
67177 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67178 +}
67179 +
67180 +struct acl_subject_label *
67181 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67182 + const struct acl_role_label *role)
67183 +{
67184 + struct dentry *dentry = (struct dentry *) l_dentry;
67185 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67186 + struct mount *real_mnt = real_mount(mnt);
67187 + struct acl_subject_label *retval;
67188 + struct dentry *parent;
67189 +
67190 + read_seqlock_excl(&mount_lock);
67191 + write_seqlock(&rename_lock);
67192 +
67193 + for (;;) {
67194 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67195 + break;
67196 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67197 + if (!mnt_has_parent(real_mnt))
67198 + break;
67199 +
67200 + spin_lock(&dentry->d_lock);
67201 + read_lock(&gr_inode_lock);
67202 + retval =
67203 + lookup_acl_subj_label(dentry->d_inode->i_ino,
67204 + __get_dev(dentry), role);
67205 + read_unlock(&gr_inode_lock);
67206 + spin_unlock(&dentry->d_lock);
67207 + if (retval != NULL)
67208 + goto out;
67209 +
67210 + dentry = real_mnt->mnt_mountpoint;
67211 + real_mnt = real_mnt->mnt_parent;
67212 + mnt = &real_mnt->mnt;
67213 + continue;
67214 + }
67215 +
67216 + spin_lock(&dentry->d_lock);
67217 + read_lock(&gr_inode_lock);
67218 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67219 + __get_dev(dentry), role);
67220 + read_unlock(&gr_inode_lock);
67221 + parent = dentry->d_parent;
67222 + spin_unlock(&dentry->d_lock);
67223 +
67224 + if (retval != NULL)
67225 + goto out;
67226 +
67227 + dentry = parent;
67228 + }
67229 +
67230 + spin_lock(&dentry->d_lock);
67231 + read_lock(&gr_inode_lock);
67232 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67233 + __get_dev(dentry), role);
67234 + read_unlock(&gr_inode_lock);
67235 + spin_unlock(&dentry->d_lock);
67236 +
67237 + if (unlikely(retval == NULL)) {
67238 + /* gr_real_root is pinned, we don't need to hold a reference */
67239 + read_lock(&gr_inode_lock);
67240 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67241 + __get_dev(gr_real_root.dentry), role);
67242 + read_unlock(&gr_inode_lock);
67243 + }
67244 +out:
67245 + write_sequnlock(&rename_lock);
67246 + read_sequnlock_excl(&mount_lock);
67247 +
67248 + BUG_ON(retval == NULL);
67249 +
67250 + return retval;
67251 +}
67252 +
67253 +void
67254 +assign_special_role(const char *rolename)
67255 +{
67256 + struct acl_object_label *obj;
67257 + struct acl_role_label *r;
67258 + struct acl_role_label *assigned = NULL;
67259 + struct task_struct *tsk;
67260 + struct file *filp;
67261 +
67262 + FOR_EACH_ROLE_START(r)
67263 + if (!strcmp(rolename, r->rolename) &&
67264 + (r->roletype & GR_ROLE_SPECIAL)) {
67265 + assigned = r;
67266 + break;
67267 + }
67268 + FOR_EACH_ROLE_END(r)
67269 +
67270 + if (!assigned)
67271 + return;
67272 +
67273 + read_lock(&tasklist_lock);
67274 + read_lock(&grsec_exec_file_lock);
67275 +
67276 + tsk = current->real_parent;
67277 + if (tsk == NULL)
67278 + goto out_unlock;
67279 +
67280 + filp = tsk->exec_file;
67281 + if (filp == NULL)
67282 + goto out_unlock;
67283 +
67284 + tsk->is_writable = 0;
67285 + tsk->inherited = 0;
67286 +
67287 + tsk->acl_sp_role = 1;
67288 + tsk->acl_role_id = ++acl_sp_role_value;
67289 + tsk->role = assigned;
67290 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67291 +
67292 + /* ignore additional mmap checks for processes that are writable
67293 + by the default ACL */
67294 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67295 + if (unlikely(obj->mode & GR_WRITE))
67296 + tsk->is_writable = 1;
67297 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67298 + if (unlikely(obj->mode & GR_WRITE))
67299 + tsk->is_writable = 1;
67300 +
67301 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67302 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67303 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67304 +#endif
67305 +
67306 +out_unlock:
67307 + read_unlock(&grsec_exec_file_lock);
67308 + read_unlock(&tasklist_lock);
67309 + return;
67310 +}
67311 +
67312 +
67313 +static void
67314 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67315 +{
67316 + struct task_struct *task = current;
67317 + const struct cred *cred = current_cred();
67318 +
67319 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67320 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67321 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67322 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67323 +
67324 + return;
67325 +}
67326 +
67327 +static void
67328 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67329 +{
67330 + struct task_struct *task = current;
67331 + const struct cred *cred = current_cred();
67332 +
67333 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67334 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67335 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67336 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67337 +
67338 + return;
67339 +}
67340 +
67341 +static void
67342 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67343 +{
67344 + struct task_struct *task = current;
67345 + const struct cred *cred = current_cred();
67346 +
67347 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67348 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67349 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67350 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67351 +
67352 + return;
67353 +}
67354 +
67355 +static void
67356 +gr_set_proc_res(struct task_struct *task)
67357 +{
67358 + struct acl_subject_label *proc;
67359 + unsigned short i;
67360 +
67361 + proc = task->acl;
67362 +
67363 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67364 + return;
67365 +
67366 + for (i = 0; i < RLIM_NLIMITS; i++) {
67367 + if (!(proc->resmask & (1U << i)))
67368 + continue;
67369 +
67370 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67371 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67372 +
67373 + if (i == RLIMIT_CPU)
67374 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
67375 + }
67376 +
67377 + return;
67378 +}
67379 +
67380 +/* both of the below must be called with
67381 + rcu_read_lock();
67382 + read_lock(&tasklist_lock);
67383 + read_lock(&grsec_exec_file_lock);
67384 +*/
67385 +
67386 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67387 +{
67388 + char *tmpname;
67389 + struct acl_subject_label *tmpsubj;
67390 + struct file *filp;
67391 + struct name_entry *nmatch;
67392 +
67393 + filp = task->exec_file;
67394 + if (filp == NULL)
67395 + return NULL;
67396 +
67397 + /* the following is to apply the correct subject
67398 + on binaries running when the RBAC system
67399 + is enabled, when the binaries have been
67400 + replaced or deleted since their execution
67401 + -----
67402 + when the RBAC system starts, the inode/dev
67403 + from exec_file will be one the RBAC system
67404 + is unaware of. It only knows the inode/dev
67405 + of the present file on disk, or the absence
67406 + of it.
67407 + */
67408 +
67409 + if (filename)
67410 + nmatch = __lookup_name_entry(state, filename);
67411 + else {
67412 + preempt_disable();
67413 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67414 +
67415 + nmatch = __lookup_name_entry(state, tmpname);
67416 + preempt_enable();
67417 + }
67418 + tmpsubj = NULL;
67419 + if (nmatch) {
67420 + if (nmatch->deleted)
67421 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67422 + else
67423 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67424 + }
67425 + /* this also works for the reload case -- if we don't match a potentially inherited subject
67426 + then we fall back to a normal lookup based on the binary's ino/dev
67427 + */
67428 + if (tmpsubj == NULL)
67429 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67430 +
67431 + return tmpsubj;
67432 +}
67433 +
67434 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67435 +{
67436 + return __gr_get_subject_for_task(&running_polstate, task, filename);
67437 +}
67438 +
67439 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67440 +{
67441 + struct acl_object_label *obj;
67442 + struct file *filp;
67443 +
67444 + filp = task->exec_file;
67445 +
67446 + task->acl = subj;
67447 + task->is_writable = 0;
67448 + /* ignore additional mmap checks for processes that are writable
67449 + by the default ACL */
67450 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67451 + if (unlikely(obj->mode & GR_WRITE))
67452 + task->is_writable = 1;
67453 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67454 + if (unlikely(obj->mode & GR_WRITE))
67455 + task->is_writable = 1;
67456 +
67457 + gr_set_proc_res(task);
67458 +
67459 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67460 + 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);
67461 +#endif
67462 +}
67463 +
67464 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67465 +{
67466 + __gr_apply_subject_to_task(&running_polstate, task, subj);
67467 +}
67468 +
67469 +__u32
67470 +gr_search_file(const struct dentry * dentry, const __u32 mode,
67471 + const struct vfsmount * mnt)
67472 +{
67473 + __u32 retval = mode;
67474 + struct acl_subject_label *curracl;
67475 + struct acl_object_label *currobj;
67476 +
67477 + if (unlikely(!(gr_status & GR_READY)))
67478 + return (mode & ~GR_AUDITS);
67479 +
67480 + curracl = current->acl;
67481 +
67482 + currobj = chk_obj_label(dentry, mnt, curracl);
67483 + retval = currobj->mode & mode;
67484 +
67485 + /* if we're opening a specified transfer file for writing
67486 + (e.g. /dev/initctl), then transfer our role to init
67487 + */
67488 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67489 + current->role->roletype & GR_ROLE_PERSIST)) {
67490 + struct task_struct *task = init_pid_ns.child_reaper;
67491 +
67492 + if (task->role != current->role) {
67493 + struct acl_subject_label *subj;
67494 +
67495 + task->acl_sp_role = 0;
67496 + task->acl_role_id = current->acl_role_id;
67497 + task->role = current->role;
67498 + rcu_read_lock();
67499 + read_lock(&grsec_exec_file_lock);
67500 + subj = gr_get_subject_for_task(task, NULL);
67501 + gr_apply_subject_to_task(task, subj);
67502 + read_unlock(&grsec_exec_file_lock);
67503 + rcu_read_unlock();
67504 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
67505 + }
67506 + }
67507 +
67508 + if (unlikely
67509 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
67510 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
67511 + __u32 new_mode = mode;
67512 +
67513 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67514 +
67515 + retval = new_mode;
67516 +
67517 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
67518 + new_mode |= GR_INHERIT;
67519 +
67520 + if (!(mode & GR_NOLEARN))
67521 + gr_log_learn(dentry, mnt, new_mode);
67522 + }
67523 +
67524 + return retval;
67525 +}
67526 +
67527 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
67528 + const struct dentry *parent,
67529 + const struct vfsmount *mnt)
67530 +{
67531 + struct name_entry *match;
67532 + struct acl_object_label *matchpo;
67533 + struct acl_subject_label *curracl;
67534 + char *path;
67535 +
67536 + if (unlikely(!(gr_status & GR_READY)))
67537 + return NULL;
67538 +
67539 + preempt_disable();
67540 + path = gr_to_filename_rbac(new_dentry, mnt);
67541 + match = lookup_name_entry_create(path);
67542 +
67543 + curracl = current->acl;
67544 +
67545 + if (match) {
67546 + read_lock(&gr_inode_lock);
67547 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
67548 + read_unlock(&gr_inode_lock);
67549 +
67550 + if (matchpo) {
67551 + preempt_enable();
67552 + return matchpo;
67553 + }
67554 + }
67555 +
67556 + // lookup parent
67557 +
67558 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
67559 +
67560 + preempt_enable();
67561 + return matchpo;
67562 +}
67563 +
67564 +__u32
67565 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
67566 + const struct vfsmount * mnt, const __u32 mode)
67567 +{
67568 + struct acl_object_label *matchpo;
67569 + __u32 retval;
67570 +
67571 + if (unlikely(!(gr_status & GR_READY)))
67572 + return (mode & ~GR_AUDITS);
67573 +
67574 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
67575 +
67576 + retval = matchpo->mode & mode;
67577 +
67578 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
67579 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67580 + __u32 new_mode = mode;
67581 +
67582 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67583 +
67584 + gr_log_learn(new_dentry, mnt, new_mode);
67585 + return new_mode;
67586 + }
67587 +
67588 + return retval;
67589 +}
67590 +
67591 +__u32
67592 +gr_check_link(const struct dentry * new_dentry,
67593 + const struct dentry * parent_dentry,
67594 + const struct vfsmount * parent_mnt,
67595 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
67596 +{
67597 + struct acl_object_label *obj;
67598 + __u32 oldmode, newmode;
67599 + __u32 needmode;
67600 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
67601 + GR_DELETE | GR_INHERIT;
67602 +
67603 + if (unlikely(!(gr_status & GR_READY)))
67604 + return (GR_CREATE | GR_LINK);
67605 +
67606 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
67607 + oldmode = obj->mode;
67608 +
67609 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
67610 + newmode = obj->mode;
67611 +
67612 + needmode = newmode & checkmodes;
67613 +
67614 + // old name for hardlink must have at least the permissions of the new name
67615 + if ((oldmode & needmode) != needmode)
67616 + goto bad;
67617 +
67618 + // if old name had restrictions/auditing, make sure the new name does as well
67619 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
67620 +
67621 + // don't allow hardlinking of suid/sgid/fcapped files without permission
67622 + if (is_privileged_binary(old_dentry))
67623 + needmode |= GR_SETID;
67624 +
67625 + if ((newmode & needmode) != needmode)
67626 + goto bad;
67627 +
67628 + // enforce minimum permissions
67629 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
67630 + return newmode;
67631 +bad:
67632 + needmode = oldmode;
67633 + if (is_privileged_binary(old_dentry))
67634 + needmode |= GR_SETID;
67635 +
67636 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
67637 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
67638 + return (GR_CREATE | GR_LINK);
67639 + } else if (newmode & GR_SUPPRESS)
67640 + return GR_SUPPRESS;
67641 + else
67642 + return 0;
67643 +}
67644 +
67645 +int
67646 +gr_check_hidden_task(const struct task_struct *task)
67647 +{
67648 + if (unlikely(!(gr_status & GR_READY)))
67649 + return 0;
67650 +
67651 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
67652 + return 1;
67653 +
67654 + return 0;
67655 +}
67656 +
67657 +int
67658 +gr_check_protected_task(const struct task_struct *task)
67659 +{
67660 + if (unlikely(!(gr_status & GR_READY) || !task))
67661 + return 0;
67662 +
67663 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67664 + task->acl != current->acl)
67665 + return 1;
67666 +
67667 + return 0;
67668 +}
67669 +
67670 +int
67671 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
67672 +{
67673 + struct task_struct *p;
67674 + int ret = 0;
67675 +
67676 + if (unlikely(!(gr_status & GR_READY) || !pid))
67677 + return ret;
67678 +
67679 + read_lock(&tasklist_lock);
67680 + do_each_pid_task(pid, type, p) {
67681 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67682 + p->acl != current->acl) {
67683 + ret = 1;
67684 + goto out;
67685 + }
67686 + } while_each_pid_task(pid, type, p);
67687 +out:
67688 + read_unlock(&tasklist_lock);
67689 +
67690 + return ret;
67691 +}
67692 +
67693 +void
67694 +gr_copy_label(struct task_struct *tsk)
67695 +{
67696 + struct task_struct *p = current;
67697 +
67698 + tsk->inherited = p->inherited;
67699 + tsk->acl_sp_role = 0;
67700 + tsk->acl_role_id = p->acl_role_id;
67701 + tsk->acl = p->acl;
67702 + tsk->role = p->role;
67703 + tsk->signal->used_accept = 0;
67704 + tsk->signal->curr_ip = p->signal->curr_ip;
67705 + tsk->signal->saved_ip = p->signal->saved_ip;
67706 + if (p->exec_file)
67707 + get_file(p->exec_file);
67708 + tsk->exec_file = p->exec_file;
67709 + tsk->is_writable = p->is_writable;
67710 + if (unlikely(p->signal->used_accept)) {
67711 + p->signal->curr_ip = 0;
67712 + p->signal->saved_ip = 0;
67713 + }
67714 +
67715 + return;
67716 +}
67717 +
67718 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
67719 +
67720 +int
67721 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
67722 +{
67723 + unsigned int i;
67724 + __u16 num;
67725 + uid_t *uidlist;
67726 + uid_t curuid;
67727 + int realok = 0;
67728 + int effectiveok = 0;
67729 + int fsok = 0;
67730 + uid_t globalreal, globaleffective, globalfs;
67731 +
67732 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
67733 + struct user_struct *user;
67734 +
67735 + if (!uid_valid(real))
67736 + goto skipit;
67737 +
67738 + /* find user based on global namespace */
67739 +
67740 + globalreal = GR_GLOBAL_UID(real);
67741 +
67742 + user = find_user(make_kuid(&init_user_ns, globalreal));
67743 + if (user == NULL)
67744 + goto skipit;
67745 +
67746 + if (gr_process_kernel_setuid_ban(user)) {
67747 + /* for find_user */
67748 + free_uid(user);
67749 + return 1;
67750 + }
67751 +
67752 + /* for find_user */
67753 + free_uid(user);
67754 +
67755 +skipit:
67756 +#endif
67757 +
67758 + if (unlikely(!(gr_status & GR_READY)))
67759 + return 0;
67760 +
67761 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67762 + gr_log_learn_uid_change(real, effective, fs);
67763 +
67764 + num = current->acl->user_trans_num;
67765 + uidlist = current->acl->user_transitions;
67766 +
67767 + if (uidlist == NULL)
67768 + return 0;
67769 +
67770 + if (!uid_valid(real)) {
67771 + realok = 1;
67772 + globalreal = (uid_t)-1;
67773 + } else {
67774 + globalreal = GR_GLOBAL_UID(real);
67775 + }
67776 + if (!uid_valid(effective)) {
67777 + effectiveok = 1;
67778 + globaleffective = (uid_t)-1;
67779 + } else {
67780 + globaleffective = GR_GLOBAL_UID(effective);
67781 + }
67782 + if (!uid_valid(fs)) {
67783 + fsok = 1;
67784 + globalfs = (uid_t)-1;
67785 + } else {
67786 + globalfs = GR_GLOBAL_UID(fs);
67787 + }
67788 +
67789 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
67790 + for (i = 0; i < num; i++) {
67791 + curuid = uidlist[i];
67792 + if (globalreal == curuid)
67793 + realok = 1;
67794 + if (globaleffective == curuid)
67795 + effectiveok = 1;
67796 + if (globalfs == curuid)
67797 + fsok = 1;
67798 + }
67799 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
67800 + for (i = 0; i < num; i++) {
67801 + curuid = uidlist[i];
67802 + if (globalreal == curuid)
67803 + break;
67804 + if (globaleffective == curuid)
67805 + break;
67806 + if (globalfs == curuid)
67807 + break;
67808 + }
67809 + /* not in deny list */
67810 + if (i == num) {
67811 + realok = 1;
67812 + effectiveok = 1;
67813 + fsok = 1;
67814 + }
67815 + }
67816 +
67817 + if (realok && effectiveok && fsok)
67818 + return 0;
67819 + else {
67820 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67821 + return 1;
67822 + }
67823 +}
67824 +
67825 +int
67826 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
67827 +{
67828 + unsigned int i;
67829 + __u16 num;
67830 + gid_t *gidlist;
67831 + gid_t curgid;
67832 + int realok = 0;
67833 + int effectiveok = 0;
67834 + int fsok = 0;
67835 + gid_t globalreal, globaleffective, globalfs;
67836 +
67837 + if (unlikely(!(gr_status & GR_READY)))
67838 + return 0;
67839 +
67840 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67841 + gr_log_learn_gid_change(real, effective, fs);
67842 +
67843 + num = current->acl->group_trans_num;
67844 + gidlist = current->acl->group_transitions;
67845 +
67846 + if (gidlist == NULL)
67847 + return 0;
67848 +
67849 + if (!gid_valid(real)) {
67850 + realok = 1;
67851 + globalreal = (gid_t)-1;
67852 + } else {
67853 + globalreal = GR_GLOBAL_GID(real);
67854 + }
67855 + if (!gid_valid(effective)) {
67856 + effectiveok = 1;
67857 + globaleffective = (gid_t)-1;
67858 + } else {
67859 + globaleffective = GR_GLOBAL_GID(effective);
67860 + }
67861 + if (!gid_valid(fs)) {
67862 + fsok = 1;
67863 + globalfs = (gid_t)-1;
67864 + } else {
67865 + globalfs = GR_GLOBAL_GID(fs);
67866 + }
67867 +
67868 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
67869 + for (i = 0; i < num; i++) {
67870 + curgid = gidlist[i];
67871 + if (globalreal == curgid)
67872 + realok = 1;
67873 + if (globaleffective == curgid)
67874 + effectiveok = 1;
67875 + if (globalfs == curgid)
67876 + fsok = 1;
67877 + }
67878 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
67879 + for (i = 0; i < num; i++) {
67880 + curgid = gidlist[i];
67881 + if (globalreal == curgid)
67882 + break;
67883 + if (globaleffective == curgid)
67884 + break;
67885 + if (globalfs == curgid)
67886 + break;
67887 + }
67888 + /* not in deny list */
67889 + if (i == num) {
67890 + realok = 1;
67891 + effectiveok = 1;
67892 + fsok = 1;
67893 + }
67894 + }
67895 +
67896 + if (realok && effectiveok && fsok)
67897 + return 0;
67898 + else {
67899 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67900 + return 1;
67901 + }
67902 +}
67903 +
67904 +extern int gr_acl_is_capable(const int cap);
67905 +
67906 +void
67907 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
67908 +{
67909 + struct acl_role_label *role = task->role;
67910 + struct acl_subject_label *subj = NULL;
67911 + struct acl_object_label *obj;
67912 + struct file *filp;
67913 + uid_t uid;
67914 + gid_t gid;
67915 +
67916 + if (unlikely(!(gr_status & GR_READY)))
67917 + return;
67918 +
67919 + uid = GR_GLOBAL_UID(kuid);
67920 + gid = GR_GLOBAL_GID(kgid);
67921 +
67922 + filp = task->exec_file;
67923 +
67924 + /* kernel process, we'll give them the kernel role */
67925 + if (unlikely(!filp)) {
67926 + task->role = running_polstate.kernel_role;
67927 + task->acl = running_polstate.kernel_role->root_label;
67928 + return;
67929 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
67930 + /* save the current ip at time of role lookup so that the proper
67931 + IP will be learned for role_allowed_ip */
67932 + task->signal->saved_ip = task->signal->curr_ip;
67933 + role = lookup_acl_role_label(task, uid, gid);
67934 + }
67935 +
67936 + /* don't change the role if we're not a privileged process */
67937 + if (role && task->role != role &&
67938 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
67939 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
67940 + return;
67941 +
67942 + /* perform subject lookup in possibly new role
67943 + we can use this result below in the case where role == task->role
67944 + */
67945 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
67946 +
67947 + /* if we changed uid/gid, but result in the same role
67948 + and are using inheritance, don't lose the inherited subject
67949 + if current subject is other than what normal lookup
67950 + would result in, we arrived via inheritance, don't
67951 + lose subject
67952 + */
67953 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
67954 + (subj == task->acl)))
67955 + task->acl = subj;
67956 +
67957 + /* leave task->inherited unaffected */
67958 +
67959 + task->role = role;
67960 +
67961 + task->is_writable = 0;
67962 +
67963 + /* ignore additional mmap checks for processes that are writable
67964 + by the default ACL */
67965 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67966 + if (unlikely(obj->mode & GR_WRITE))
67967 + task->is_writable = 1;
67968 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67969 + if (unlikely(obj->mode & GR_WRITE))
67970 + task->is_writable = 1;
67971 +
67972 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67973 + 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);
67974 +#endif
67975 +
67976 + gr_set_proc_res(task);
67977 +
67978 + return;
67979 +}
67980 +
67981 +int
67982 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
67983 + const int unsafe_flags)
67984 +{
67985 + struct task_struct *task = current;
67986 + struct acl_subject_label *newacl;
67987 + struct acl_object_label *obj;
67988 + __u32 retmode;
67989 +
67990 + if (unlikely(!(gr_status & GR_READY)))
67991 + return 0;
67992 +
67993 + newacl = chk_subj_label(dentry, mnt, task->role);
67994 +
67995 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
67996 + did an exec
67997 + */
67998 + rcu_read_lock();
67999 + read_lock(&tasklist_lock);
68000 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68001 + (task->parent->acl->mode & GR_POVERRIDE))) {
68002 + read_unlock(&tasklist_lock);
68003 + rcu_read_unlock();
68004 + goto skip_check;
68005 + }
68006 + read_unlock(&tasklist_lock);
68007 + rcu_read_unlock();
68008 +
68009 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68010 + !(task->role->roletype & GR_ROLE_GOD) &&
68011 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68012 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68013 + if (unsafe_flags & LSM_UNSAFE_SHARE)
68014 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68015 + else
68016 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68017 + return -EACCES;
68018 + }
68019 +
68020 +skip_check:
68021 +
68022 + obj = chk_obj_label(dentry, mnt, task->acl);
68023 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68024 +
68025 + if (!(task->acl->mode & GR_INHERITLEARN) &&
68026 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68027 + if (obj->nested)
68028 + task->acl = obj->nested;
68029 + else
68030 + task->acl = newacl;
68031 + task->inherited = 0;
68032 + } else {
68033 + task->inherited = 1;
68034 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68035 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68036 + }
68037 +
68038 + task->is_writable = 0;
68039 +
68040 + /* ignore additional mmap checks for processes that are writable
68041 + by the default ACL */
68042 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68043 + if (unlikely(obj->mode & GR_WRITE))
68044 + task->is_writable = 1;
68045 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
68046 + if (unlikely(obj->mode & GR_WRITE))
68047 + task->is_writable = 1;
68048 +
68049 + gr_set_proc_res(task);
68050 +
68051 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68052 + 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);
68053 +#endif
68054 + return 0;
68055 +}
68056 +
68057 +/* always called with valid inodev ptr */
68058 +static void
68059 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68060 +{
68061 + struct acl_object_label *matchpo;
68062 + struct acl_subject_label *matchps;
68063 + struct acl_subject_label *subj;
68064 + struct acl_role_label *role;
68065 + unsigned int x;
68066 +
68067 + FOR_EACH_ROLE_START(role)
68068 + FOR_EACH_SUBJECT_START(role, subj, x)
68069 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68070 + matchpo->mode |= GR_DELETED;
68071 + FOR_EACH_SUBJECT_END(subj,x)
68072 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68073 + /* nested subjects aren't in the role's subj_hash table */
68074 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68075 + matchpo->mode |= GR_DELETED;
68076 + FOR_EACH_NESTED_SUBJECT_END(subj)
68077 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68078 + matchps->mode |= GR_DELETED;
68079 + FOR_EACH_ROLE_END(role)
68080 +
68081 + inodev->nentry->deleted = 1;
68082 +
68083 + return;
68084 +}
68085 +
68086 +void
68087 +gr_handle_delete(const ino_t ino, const dev_t dev)
68088 +{
68089 + struct inodev_entry *inodev;
68090 +
68091 + if (unlikely(!(gr_status & GR_READY)))
68092 + return;
68093 +
68094 + write_lock(&gr_inode_lock);
68095 + inodev = lookup_inodev_entry(ino, dev);
68096 + if (inodev != NULL)
68097 + do_handle_delete(inodev, ino, dev);
68098 + write_unlock(&gr_inode_lock);
68099 +
68100 + return;
68101 +}
68102 +
68103 +static void
68104 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68105 + const ino_t newinode, const dev_t newdevice,
68106 + struct acl_subject_label *subj)
68107 +{
68108 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68109 + struct acl_object_label *match;
68110 +
68111 + match = subj->obj_hash[index];
68112 +
68113 + while (match && (match->inode != oldinode ||
68114 + match->device != olddevice ||
68115 + !(match->mode & GR_DELETED)))
68116 + match = match->next;
68117 +
68118 + if (match && (match->inode == oldinode)
68119 + && (match->device == olddevice)
68120 + && (match->mode & GR_DELETED)) {
68121 + if (match->prev == NULL) {
68122 + subj->obj_hash[index] = match->next;
68123 + if (match->next != NULL)
68124 + match->next->prev = NULL;
68125 + } else {
68126 + match->prev->next = match->next;
68127 + if (match->next != NULL)
68128 + match->next->prev = match->prev;
68129 + }
68130 + match->prev = NULL;
68131 + match->next = NULL;
68132 + match->inode = newinode;
68133 + match->device = newdevice;
68134 + match->mode &= ~GR_DELETED;
68135 +
68136 + insert_acl_obj_label(match, subj);
68137 + }
68138 +
68139 + return;
68140 +}
68141 +
68142 +static void
68143 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68144 + const ino_t newinode, const dev_t newdevice,
68145 + struct acl_role_label *role)
68146 +{
68147 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68148 + struct acl_subject_label *match;
68149 +
68150 + match = role->subj_hash[index];
68151 +
68152 + while (match && (match->inode != oldinode ||
68153 + match->device != olddevice ||
68154 + !(match->mode & GR_DELETED)))
68155 + match = match->next;
68156 +
68157 + if (match && (match->inode == oldinode)
68158 + && (match->device == olddevice)
68159 + && (match->mode & GR_DELETED)) {
68160 + if (match->prev == NULL) {
68161 + role->subj_hash[index] = match->next;
68162 + if (match->next != NULL)
68163 + match->next->prev = NULL;
68164 + } else {
68165 + match->prev->next = match->next;
68166 + if (match->next != NULL)
68167 + match->next->prev = match->prev;
68168 + }
68169 + match->prev = NULL;
68170 + match->next = NULL;
68171 + match->inode = newinode;
68172 + match->device = newdevice;
68173 + match->mode &= ~GR_DELETED;
68174 +
68175 + insert_acl_subj_label(match, role);
68176 + }
68177 +
68178 + return;
68179 +}
68180 +
68181 +static void
68182 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68183 + const ino_t newinode, const dev_t newdevice)
68184 +{
68185 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68186 + struct inodev_entry *match;
68187 +
68188 + match = running_polstate.inodev_set.i_hash[index];
68189 +
68190 + while (match && (match->nentry->inode != oldinode ||
68191 + match->nentry->device != olddevice || !match->nentry->deleted))
68192 + match = match->next;
68193 +
68194 + if (match && (match->nentry->inode == oldinode)
68195 + && (match->nentry->device == olddevice) &&
68196 + match->nentry->deleted) {
68197 + if (match->prev == NULL) {
68198 + running_polstate.inodev_set.i_hash[index] = match->next;
68199 + if (match->next != NULL)
68200 + match->next->prev = NULL;
68201 + } else {
68202 + match->prev->next = match->next;
68203 + if (match->next != NULL)
68204 + match->next->prev = match->prev;
68205 + }
68206 + match->prev = NULL;
68207 + match->next = NULL;
68208 + match->nentry->inode = newinode;
68209 + match->nentry->device = newdevice;
68210 + match->nentry->deleted = 0;
68211 +
68212 + insert_inodev_entry(match);
68213 + }
68214 +
68215 + return;
68216 +}
68217 +
68218 +static void
68219 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68220 +{
68221 + struct acl_subject_label *subj;
68222 + struct acl_role_label *role;
68223 + unsigned int x;
68224 +
68225 + FOR_EACH_ROLE_START(role)
68226 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68227 +
68228 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68229 + if ((subj->inode == ino) && (subj->device == dev)) {
68230 + subj->inode = ino;
68231 + subj->device = dev;
68232 + }
68233 + /* nested subjects aren't in the role's subj_hash table */
68234 + update_acl_obj_label(matchn->inode, matchn->device,
68235 + ino, dev, subj);
68236 + FOR_EACH_NESTED_SUBJECT_END(subj)
68237 + FOR_EACH_SUBJECT_START(role, subj, x)
68238 + update_acl_obj_label(matchn->inode, matchn->device,
68239 + ino, dev, subj);
68240 + FOR_EACH_SUBJECT_END(subj,x)
68241 + FOR_EACH_ROLE_END(role)
68242 +
68243 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68244 +
68245 + return;
68246 +}
68247 +
68248 +static void
68249 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68250 + const struct vfsmount *mnt)
68251 +{
68252 + ino_t ino = dentry->d_inode->i_ino;
68253 + dev_t dev = __get_dev(dentry);
68254 +
68255 + __do_handle_create(matchn, ino, dev);
68256 +
68257 + return;
68258 +}
68259 +
68260 +void
68261 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68262 +{
68263 + struct name_entry *matchn;
68264 +
68265 + if (unlikely(!(gr_status & GR_READY)))
68266 + return;
68267 +
68268 + preempt_disable();
68269 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68270 +
68271 + if (unlikely((unsigned long)matchn)) {
68272 + write_lock(&gr_inode_lock);
68273 + do_handle_create(matchn, dentry, mnt);
68274 + write_unlock(&gr_inode_lock);
68275 + }
68276 + preempt_enable();
68277 +
68278 + return;
68279 +}
68280 +
68281 +void
68282 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68283 +{
68284 + struct name_entry *matchn;
68285 +
68286 + if (unlikely(!(gr_status & GR_READY)))
68287 + return;
68288 +
68289 + preempt_disable();
68290 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68291 +
68292 + if (unlikely((unsigned long)matchn)) {
68293 + write_lock(&gr_inode_lock);
68294 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68295 + write_unlock(&gr_inode_lock);
68296 + }
68297 + preempt_enable();
68298 +
68299 + return;
68300 +}
68301 +
68302 +void
68303 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68304 + struct dentry *old_dentry,
68305 + struct dentry *new_dentry,
68306 + struct vfsmount *mnt, const __u8 replace)
68307 +{
68308 + struct name_entry *matchn;
68309 + struct inodev_entry *inodev;
68310 + struct inode *inode = new_dentry->d_inode;
68311 + ino_t old_ino = old_dentry->d_inode->i_ino;
68312 + dev_t old_dev = __get_dev(old_dentry);
68313 +
68314 + /* vfs_rename swaps the name and parent link for old_dentry and
68315 + new_dentry
68316 + at this point, old_dentry has the new name, parent link, and inode
68317 + for the renamed file
68318 + if a file is being replaced by a rename, new_dentry has the inode
68319 + and name for the replaced file
68320 + */
68321 +
68322 + if (unlikely(!(gr_status & GR_READY)))
68323 + return;
68324 +
68325 + preempt_disable();
68326 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68327 +
68328 + /* we wouldn't have to check d_inode if it weren't for
68329 + NFS silly-renaming
68330 + */
68331 +
68332 + write_lock(&gr_inode_lock);
68333 + if (unlikely(replace && inode)) {
68334 + ino_t new_ino = inode->i_ino;
68335 + dev_t new_dev = __get_dev(new_dentry);
68336 +
68337 + inodev = lookup_inodev_entry(new_ino, new_dev);
68338 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68339 + do_handle_delete(inodev, new_ino, new_dev);
68340 + }
68341 +
68342 + inodev = lookup_inodev_entry(old_ino, old_dev);
68343 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68344 + do_handle_delete(inodev, old_ino, old_dev);
68345 +
68346 + if (unlikely((unsigned long)matchn))
68347 + do_handle_create(matchn, old_dentry, mnt);
68348 +
68349 + write_unlock(&gr_inode_lock);
68350 + preempt_enable();
68351 +
68352 + return;
68353 +}
68354 +
68355 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68356 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68357 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68358 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68359 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68360 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68361 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68362 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68363 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68364 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68365 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68366 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68367 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68368 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68369 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68370 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68371 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68372 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68373 +};
68374 +
68375 +void
68376 +gr_learn_resource(const struct task_struct *task,
68377 + const int res, const unsigned long wanted, const int gt)
68378 +{
68379 + struct acl_subject_label *acl;
68380 + const struct cred *cred;
68381 +
68382 + if (unlikely((gr_status & GR_READY) &&
68383 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68384 + goto skip_reslog;
68385 +
68386 + gr_log_resource(task, res, wanted, gt);
68387 +skip_reslog:
68388 +
68389 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68390 + return;
68391 +
68392 + acl = task->acl;
68393 +
68394 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68395 + !(acl->resmask & (1U << (unsigned short) res))))
68396 + return;
68397 +
68398 + if (wanted >= acl->res[res].rlim_cur) {
68399 + unsigned long res_add;
68400 +
68401 + res_add = wanted + res_learn_bumps[res];
68402 +
68403 + acl->res[res].rlim_cur = res_add;
68404 +
68405 + if (wanted > acl->res[res].rlim_max)
68406 + acl->res[res].rlim_max = res_add;
68407 +
68408 + /* only log the subject filename, since resource logging is supported for
68409 + single-subject learning only */
68410 + rcu_read_lock();
68411 + cred = __task_cred(task);
68412 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68413 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68414 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68415 + "", (unsigned long) res, &task->signal->saved_ip);
68416 + rcu_read_unlock();
68417 + }
68418 +
68419 + return;
68420 +}
68421 +EXPORT_SYMBOL_GPL(gr_learn_resource);
68422 +#endif
68423 +
68424 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68425 +void
68426 +pax_set_initial_flags(struct linux_binprm *bprm)
68427 +{
68428 + struct task_struct *task = current;
68429 + struct acl_subject_label *proc;
68430 + unsigned long flags;
68431 +
68432 + if (unlikely(!(gr_status & GR_READY)))
68433 + return;
68434 +
68435 + flags = pax_get_flags(task);
68436 +
68437 + proc = task->acl;
68438 +
68439 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68440 + flags &= ~MF_PAX_PAGEEXEC;
68441 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68442 + flags &= ~MF_PAX_SEGMEXEC;
68443 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68444 + flags &= ~MF_PAX_RANDMMAP;
68445 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68446 + flags &= ~MF_PAX_EMUTRAMP;
68447 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68448 + flags &= ~MF_PAX_MPROTECT;
68449 +
68450 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68451 + flags |= MF_PAX_PAGEEXEC;
68452 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68453 + flags |= MF_PAX_SEGMEXEC;
68454 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68455 + flags |= MF_PAX_RANDMMAP;
68456 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68457 + flags |= MF_PAX_EMUTRAMP;
68458 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68459 + flags |= MF_PAX_MPROTECT;
68460 +
68461 + pax_set_flags(task, flags);
68462 +
68463 + return;
68464 +}
68465 +#endif
68466 +
68467 +int
68468 +gr_handle_proc_ptrace(struct task_struct *task)
68469 +{
68470 + struct file *filp;
68471 + struct task_struct *tmp = task;
68472 + struct task_struct *curtemp = current;
68473 + __u32 retmode;
68474 +
68475 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68476 + if (unlikely(!(gr_status & GR_READY)))
68477 + return 0;
68478 +#endif
68479 +
68480 + read_lock(&tasklist_lock);
68481 + read_lock(&grsec_exec_file_lock);
68482 + filp = task->exec_file;
68483 +
68484 + while (task_pid_nr(tmp) > 0) {
68485 + if (tmp == curtemp)
68486 + break;
68487 + tmp = tmp->real_parent;
68488 + }
68489 +
68490 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68491 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
68492 + read_unlock(&grsec_exec_file_lock);
68493 + read_unlock(&tasklist_lock);
68494 + return 1;
68495 + }
68496 +
68497 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68498 + if (!(gr_status & GR_READY)) {
68499 + read_unlock(&grsec_exec_file_lock);
68500 + read_unlock(&tasklist_lock);
68501 + return 0;
68502 + }
68503 +#endif
68504 +
68505 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
68506 + read_unlock(&grsec_exec_file_lock);
68507 + read_unlock(&tasklist_lock);
68508 +
68509 + if (retmode & GR_NOPTRACE)
68510 + return 1;
68511 +
68512 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
68513 + && (current->acl != task->acl || (current->acl != current->role->root_label
68514 + && task_pid_nr(current) != task_pid_nr(task))))
68515 + return 1;
68516 +
68517 + return 0;
68518 +}
68519 +
68520 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
68521 +{
68522 + if (unlikely(!(gr_status & GR_READY)))
68523 + return;
68524 +
68525 + if (!(current->role->roletype & GR_ROLE_GOD))
68526 + return;
68527 +
68528 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
68529 + p->role->rolename, gr_task_roletype_to_char(p),
68530 + p->acl->filename);
68531 +}
68532 +
68533 +int
68534 +gr_handle_ptrace(struct task_struct *task, const long request)
68535 +{
68536 + struct task_struct *tmp = task;
68537 + struct task_struct *curtemp = current;
68538 + __u32 retmode;
68539 +
68540 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68541 + if (unlikely(!(gr_status & GR_READY)))
68542 + return 0;
68543 +#endif
68544 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68545 + read_lock(&tasklist_lock);
68546 + while (task_pid_nr(tmp) > 0) {
68547 + if (tmp == curtemp)
68548 + break;
68549 + tmp = tmp->real_parent;
68550 + }
68551 +
68552 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68553 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
68554 + read_unlock(&tasklist_lock);
68555 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68556 + return 1;
68557 + }
68558 + read_unlock(&tasklist_lock);
68559 + }
68560 +
68561 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68562 + if (!(gr_status & GR_READY))
68563 + return 0;
68564 +#endif
68565 +
68566 + read_lock(&grsec_exec_file_lock);
68567 + if (unlikely(!task->exec_file)) {
68568 + read_unlock(&grsec_exec_file_lock);
68569 + return 0;
68570 + }
68571 +
68572 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
68573 + read_unlock(&grsec_exec_file_lock);
68574 +
68575 + if (retmode & GR_NOPTRACE) {
68576 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68577 + return 1;
68578 + }
68579 +
68580 + if (retmode & GR_PTRACERD) {
68581 + switch (request) {
68582 + case PTRACE_SEIZE:
68583 + case PTRACE_POKETEXT:
68584 + case PTRACE_POKEDATA:
68585 + case PTRACE_POKEUSR:
68586 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
68587 + case PTRACE_SETREGS:
68588 + case PTRACE_SETFPREGS:
68589 +#endif
68590 +#ifdef CONFIG_X86
68591 + case PTRACE_SETFPXREGS:
68592 +#endif
68593 +#ifdef CONFIG_ALTIVEC
68594 + case PTRACE_SETVRREGS:
68595 +#endif
68596 + return 1;
68597 + default:
68598 + return 0;
68599 + }
68600 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
68601 + !(current->role->roletype & GR_ROLE_GOD) &&
68602 + (current->acl != task->acl)) {
68603 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68604 + return 1;
68605 + }
68606 +
68607 + return 0;
68608 +}
68609 +
68610 +static int is_writable_mmap(const struct file *filp)
68611 +{
68612 + struct task_struct *task = current;
68613 + struct acl_object_label *obj, *obj2;
68614 +
68615 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
68616 + !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))) {
68617 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68618 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
68619 + task->role->root_label);
68620 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
68621 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
68622 + return 1;
68623 + }
68624 + }
68625 + return 0;
68626 +}
68627 +
68628 +int
68629 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
68630 +{
68631 + __u32 mode;
68632 +
68633 + if (unlikely(!file || !(prot & PROT_EXEC)))
68634 + return 1;
68635 +
68636 + if (is_writable_mmap(file))
68637 + return 0;
68638 +
68639 + mode =
68640 + gr_search_file(file->f_path.dentry,
68641 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68642 + file->f_path.mnt);
68643 +
68644 + if (!gr_tpe_allow(file))
68645 + return 0;
68646 +
68647 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68648 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68649 + return 0;
68650 + } else if (unlikely(!(mode & GR_EXEC))) {
68651 + return 0;
68652 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68653 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68654 + return 1;
68655 + }
68656 +
68657 + return 1;
68658 +}
68659 +
68660 +int
68661 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
68662 +{
68663 + __u32 mode;
68664 +
68665 + if (unlikely(!file || !(prot & PROT_EXEC)))
68666 + return 1;
68667 +
68668 + if (is_writable_mmap(file))
68669 + return 0;
68670 +
68671 + mode =
68672 + gr_search_file(file->f_path.dentry,
68673 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68674 + file->f_path.mnt);
68675 +
68676 + if (!gr_tpe_allow(file))
68677 + return 0;
68678 +
68679 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68680 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68681 + return 0;
68682 + } else if (unlikely(!(mode & GR_EXEC))) {
68683 + return 0;
68684 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68685 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68686 + return 1;
68687 + }
68688 +
68689 + return 1;
68690 +}
68691 +
68692 +void
68693 +gr_acl_handle_psacct(struct task_struct *task, const long code)
68694 +{
68695 + unsigned long runtime, cputime;
68696 + cputime_t utime, stime;
68697 + unsigned int wday, cday;
68698 + __u8 whr, chr;
68699 + __u8 wmin, cmin;
68700 + __u8 wsec, csec;
68701 + struct timespec timeval;
68702 +
68703 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
68704 + !(task->acl->mode & GR_PROCACCT)))
68705 + return;
68706 +
68707 + do_posix_clock_monotonic_gettime(&timeval);
68708 + runtime = timeval.tv_sec - task->start_time.tv_sec;
68709 + wday = runtime / (60 * 60 * 24);
68710 + runtime -= wday * (60 * 60 * 24);
68711 + whr = runtime / (60 * 60);
68712 + runtime -= whr * (60 * 60);
68713 + wmin = runtime / 60;
68714 + runtime -= wmin * 60;
68715 + wsec = runtime;
68716 +
68717 + task_cputime(task, &utime, &stime);
68718 + cputime = cputime_to_secs(utime + stime);
68719 + cday = cputime / (60 * 60 * 24);
68720 + cputime -= cday * (60 * 60 * 24);
68721 + chr = cputime / (60 * 60);
68722 + cputime -= chr * (60 * 60);
68723 + cmin = cputime / 60;
68724 + cputime -= cmin * 60;
68725 + csec = cputime;
68726 +
68727 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
68728 +
68729 + return;
68730 +}
68731 +
68732 +#ifdef CONFIG_TASKSTATS
68733 +int gr_is_taskstats_denied(int pid)
68734 +{
68735 + struct task_struct *task;
68736 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68737 + const struct cred *cred;
68738 +#endif
68739 + int ret = 0;
68740 +
68741 + /* restrict taskstats viewing to un-chrooted root users
68742 + who have the 'view' subject flag if the RBAC system is enabled
68743 + */
68744 +
68745 + rcu_read_lock();
68746 + read_lock(&tasklist_lock);
68747 + task = find_task_by_vpid(pid);
68748 + if (task) {
68749 +#ifdef CONFIG_GRKERNSEC_CHROOT
68750 + if (proc_is_chrooted(task))
68751 + ret = -EACCES;
68752 +#endif
68753 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68754 + cred = __task_cred(task);
68755 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68756 + if (gr_is_global_nonroot(cred->uid))
68757 + ret = -EACCES;
68758 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68759 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
68760 + ret = -EACCES;
68761 +#endif
68762 +#endif
68763 + if (gr_status & GR_READY) {
68764 + if (!(task->acl->mode & GR_VIEW))
68765 + ret = -EACCES;
68766 + }
68767 + } else
68768 + ret = -ENOENT;
68769 +
68770 + read_unlock(&tasklist_lock);
68771 + rcu_read_unlock();
68772 +
68773 + return ret;
68774 +}
68775 +#endif
68776 +
68777 +/* AUXV entries are filled via a descendant of search_binary_handler
68778 + after we've already applied the subject for the target
68779 +*/
68780 +int gr_acl_enable_at_secure(void)
68781 +{
68782 + if (unlikely(!(gr_status & GR_READY)))
68783 + return 0;
68784 +
68785 + if (current->acl->mode & GR_ATSECURE)
68786 + return 1;
68787 +
68788 + return 0;
68789 +}
68790 +
68791 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
68792 +{
68793 + struct task_struct *task = current;
68794 + struct dentry *dentry = file->f_path.dentry;
68795 + struct vfsmount *mnt = file->f_path.mnt;
68796 + struct acl_object_label *obj, *tmp;
68797 + struct acl_subject_label *subj;
68798 + unsigned int bufsize;
68799 + int is_not_root;
68800 + char *path;
68801 + dev_t dev = __get_dev(dentry);
68802 +
68803 + if (unlikely(!(gr_status & GR_READY)))
68804 + return 1;
68805 +
68806 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68807 + return 1;
68808 +
68809 + /* ignore Eric Biederman */
68810 + if (IS_PRIVATE(dentry->d_inode))
68811 + return 1;
68812 +
68813 + subj = task->acl;
68814 + read_lock(&gr_inode_lock);
68815 + do {
68816 + obj = lookup_acl_obj_label(ino, dev, subj);
68817 + if (obj != NULL) {
68818 + read_unlock(&gr_inode_lock);
68819 + return (obj->mode & GR_FIND) ? 1 : 0;
68820 + }
68821 + } while ((subj = subj->parent_subject));
68822 + read_unlock(&gr_inode_lock);
68823 +
68824 + /* this is purely an optimization since we're looking for an object
68825 + for the directory we're doing a readdir on
68826 + if it's possible for any globbed object to match the entry we're
68827 + filling into the directory, then the object we find here will be
68828 + an anchor point with attached globbed objects
68829 + */
68830 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
68831 + if (obj->globbed == NULL)
68832 + return (obj->mode & GR_FIND) ? 1 : 0;
68833 +
68834 + is_not_root = ((obj->filename[0] == '/') &&
68835 + (obj->filename[1] == '\0')) ? 0 : 1;
68836 + bufsize = PAGE_SIZE - namelen - is_not_root;
68837 +
68838 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
68839 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
68840 + return 1;
68841 +
68842 + preempt_disable();
68843 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
68844 + bufsize);
68845 +
68846 + bufsize = strlen(path);
68847 +
68848 + /* if base is "/", don't append an additional slash */
68849 + if (is_not_root)
68850 + *(path + bufsize) = '/';
68851 + memcpy(path + bufsize + is_not_root, name, namelen);
68852 + *(path + bufsize + namelen + is_not_root) = '\0';
68853 +
68854 + tmp = obj->globbed;
68855 + while (tmp) {
68856 + if (!glob_match(tmp->filename, path)) {
68857 + preempt_enable();
68858 + return (tmp->mode & GR_FIND) ? 1 : 0;
68859 + }
68860 + tmp = tmp->next;
68861 + }
68862 + preempt_enable();
68863 + return (obj->mode & GR_FIND) ? 1 : 0;
68864 +}
68865 +
68866 +void gr_put_exec_file(struct task_struct *task)
68867 +{
68868 + struct file *filp;
68869 +
68870 + write_lock(&grsec_exec_file_lock);
68871 + filp = task->exec_file;
68872 + task->exec_file = NULL;
68873 + write_unlock(&grsec_exec_file_lock);
68874 +
68875 + if (filp)
68876 + fput(filp);
68877 +
68878 + return;
68879 +}
68880 +
68881 +
68882 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
68883 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
68884 +#endif
68885 +#ifdef CONFIG_SECURITY
68886 +EXPORT_SYMBOL_GPL(gr_check_user_change);
68887 +EXPORT_SYMBOL_GPL(gr_check_group_change);
68888 +#endif
68889 +
68890 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
68891 new file mode 100644
68892 index 0000000..18ffbbd
68893 --- /dev/null
68894 +++ b/grsecurity/gracl_alloc.c
68895 @@ -0,0 +1,105 @@
68896 +#include <linux/kernel.h>
68897 +#include <linux/mm.h>
68898 +#include <linux/slab.h>
68899 +#include <linux/vmalloc.h>
68900 +#include <linux/gracl.h>
68901 +#include <linux/grsecurity.h>
68902 +
68903 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
68904 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
68905 +
68906 +static __inline__ int
68907 +alloc_pop(void)
68908 +{
68909 + if (current_alloc_state->alloc_stack_next == 1)
68910 + return 0;
68911 +
68912 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
68913 +
68914 + current_alloc_state->alloc_stack_next--;
68915 +
68916 + return 1;
68917 +}
68918 +
68919 +static __inline__ int
68920 +alloc_push(void *buf)
68921 +{
68922 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
68923 + return 1;
68924 +
68925 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
68926 +
68927 + current_alloc_state->alloc_stack_next++;
68928 +
68929 + return 0;
68930 +}
68931 +
68932 +void *
68933 +acl_alloc(unsigned long len)
68934 +{
68935 + void *ret = NULL;
68936 +
68937 + if (!len || len > PAGE_SIZE)
68938 + goto out;
68939 +
68940 + ret = kmalloc(len, GFP_KERNEL);
68941 +
68942 + if (ret) {
68943 + if (alloc_push(ret)) {
68944 + kfree(ret);
68945 + ret = NULL;
68946 + }
68947 + }
68948 +
68949 +out:
68950 + return ret;
68951 +}
68952 +
68953 +void *
68954 +acl_alloc_num(unsigned long num, unsigned long len)
68955 +{
68956 + if (!len || (num > (PAGE_SIZE / len)))
68957 + return NULL;
68958 +
68959 + return acl_alloc(num * len);
68960 +}
68961 +
68962 +void
68963 +acl_free_all(void)
68964 +{
68965 + if (!current_alloc_state->alloc_stack)
68966 + return;
68967 +
68968 + while (alloc_pop()) ;
68969 +
68970 + if (current_alloc_state->alloc_stack) {
68971 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
68972 + kfree(current_alloc_state->alloc_stack);
68973 + else
68974 + vfree(current_alloc_state->alloc_stack);
68975 + }
68976 +
68977 + current_alloc_state->alloc_stack = NULL;
68978 + current_alloc_state->alloc_stack_size = 1;
68979 + current_alloc_state->alloc_stack_next = 1;
68980 +
68981 + return;
68982 +}
68983 +
68984 +int
68985 +acl_alloc_stack_init(unsigned long size)
68986 +{
68987 + if ((size * sizeof (void *)) <= PAGE_SIZE)
68988 + current_alloc_state->alloc_stack =
68989 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
68990 + else
68991 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
68992 +
68993 + current_alloc_state->alloc_stack_size = size;
68994 + current_alloc_state->alloc_stack_next = 1;
68995 +
68996 + if (!current_alloc_state->alloc_stack)
68997 + return 0;
68998 + else
68999 + return 1;
69000 +}
69001 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69002 new file mode 100644
69003 index 0000000..bdd51ea
69004 --- /dev/null
69005 +++ b/grsecurity/gracl_cap.c
69006 @@ -0,0 +1,110 @@
69007 +#include <linux/kernel.h>
69008 +#include <linux/module.h>
69009 +#include <linux/sched.h>
69010 +#include <linux/gracl.h>
69011 +#include <linux/grsecurity.h>
69012 +#include <linux/grinternal.h>
69013 +
69014 +extern const char *captab_log[];
69015 +extern int captab_log_entries;
69016 +
69017 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69018 +{
69019 + struct acl_subject_label *curracl;
69020 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69021 + kernel_cap_t cap_audit = __cap_empty_set;
69022 +
69023 + if (!gr_acl_is_enabled())
69024 + return 1;
69025 +
69026 + curracl = task->acl;
69027 +
69028 + cap_drop = curracl->cap_lower;
69029 + cap_mask = curracl->cap_mask;
69030 + cap_audit = curracl->cap_invert_audit;
69031 +
69032 + while ((curracl = curracl->parent_subject)) {
69033 + /* if the cap isn't specified in the current computed mask but is specified in the
69034 + current level subject, and is lowered in the current level subject, then add
69035 + it to the set of dropped capabilities
69036 + otherwise, add the current level subject's mask to the current computed mask
69037 + */
69038 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69039 + cap_raise(cap_mask, cap);
69040 + if (cap_raised(curracl->cap_lower, cap))
69041 + cap_raise(cap_drop, cap);
69042 + if (cap_raised(curracl->cap_invert_audit, cap))
69043 + cap_raise(cap_audit, cap);
69044 + }
69045 + }
69046 +
69047 + if (!cap_raised(cap_drop, cap)) {
69048 + if (cap_raised(cap_audit, cap))
69049 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69050 + return 1;
69051 + }
69052 +
69053 + curracl = task->acl;
69054 +
69055 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69056 + && cap_raised(cred->cap_effective, cap)) {
69057 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69058 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
69059 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
69060 + gr_to_filename(task->exec_file->f_path.dentry,
69061 + task->exec_file->f_path.mnt) : curracl->filename,
69062 + curracl->filename, 0UL,
69063 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69064 + return 1;
69065 + }
69066 +
69067 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69068 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69069 +
69070 + return 0;
69071 +}
69072 +
69073 +int
69074 +gr_acl_is_capable(const int cap)
69075 +{
69076 + return gr_task_acl_is_capable(current, current_cred(), cap);
69077 +}
69078 +
69079 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69080 +{
69081 + struct acl_subject_label *curracl;
69082 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69083 +
69084 + if (!gr_acl_is_enabled())
69085 + return 1;
69086 +
69087 + curracl = task->acl;
69088 +
69089 + cap_drop = curracl->cap_lower;
69090 + cap_mask = curracl->cap_mask;
69091 +
69092 + while ((curracl = curracl->parent_subject)) {
69093 + /* if the cap isn't specified in the current computed mask but is specified in the
69094 + current level subject, and is lowered in the current level subject, then add
69095 + it to the set of dropped capabilities
69096 + otherwise, add the current level subject's mask to the current computed mask
69097 + */
69098 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69099 + cap_raise(cap_mask, cap);
69100 + if (cap_raised(curracl->cap_lower, cap))
69101 + cap_raise(cap_drop, cap);
69102 + }
69103 + }
69104 +
69105 + if (!cap_raised(cap_drop, cap))
69106 + return 1;
69107 +
69108 + return 0;
69109 +}
69110 +
69111 +int
69112 +gr_acl_is_capable_nolog(const int cap)
69113 +{
69114 + return gr_task_acl_is_capable_nolog(current, cap);
69115 +}
69116 +
69117 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69118 new file mode 100644
69119 index 0000000..ca25605
69120 --- /dev/null
69121 +++ b/grsecurity/gracl_compat.c
69122 @@ -0,0 +1,270 @@
69123 +#include <linux/kernel.h>
69124 +#include <linux/gracl.h>
69125 +#include <linux/compat.h>
69126 +#include <linux/gracl_compat.h>
69127 +
69128 +#include <asm/uaccess.h>
69129 +
69130 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69131 +{
69132 + struct gr_arg_wrapper_compat uwrapcompat;
69133 +
69134 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69135 + return -EFAULT;
69136 +
69137 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69138 + (uwrapcompat.version != 0x2901)) ||
69139 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69140 + return -EINVAL;
69141 +
69142 + uwrap->arg = compat_ptr(uwrapcompat.arg);
69143 + uwrap->version = uwrapcompat.version;
69144 + uwrap->size = sizeof(struct gr_arg);
69145 +
69146 + return 0;
69147 +}
69148 +
69149 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69150 +{
69151 + struct gr_arg_compat argcompat;
69152 +
69153 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69154 + return -EFAULT;
69155 +
69156 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69157 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69158 + arg->role_db.num_roles = argcompat.role_db.num_roles;
69159 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69160 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69161 + arg->role_db.num_objects = argcompat.role_db.num_objects;
69162 +
69163 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69164 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69165 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69166 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69167 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69168 + arg->segv_device = argcompat.segv_device;
69169 + arg->segv_inode = argcompat.segv_inode;
69170 + arg->segv_uid = argcompat.segv_uid;
69171 + arg->num_sprole_pws = argcompat.num_sprole_pws;
69172 + arg->mode = argcompat.mode;
69173 +
69174 + return 0;
69175 +}
69176 +
69177 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69178 +{
69179 + struct acl_object_label_compat objcompat;
69180 +
69181 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69182 + return -EFAULT;
69183 +
69184 + obj->filename = compat_ptr(objcompat.filename);
69185 + obj->inode = objcompat.inode;
69186 + obj->device = objcompat.device;
69187 + obj->mode = objcompat.mode;
69188 +
69189 + obj->nested = compat_ptr(objcompat.nested);
69190 + obj->globbed = compat_ptr(objcompat.globbed);
69191 +
69192 + obj->prev = compat_ptr(objcompat.prev);
69193 + obj->next = compat_ptr(objcompat.next);
69194 +
69195 + return 0;
69196 +}
69197 +
69198 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69199 +{
69200 + unsigned int i;
69201 + struct acl_subject_label_compat subjcompat;
69202 +
69203 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69204 + return -EFAULT;
69205 +
69206 + subj->filename = compat_ptr(subjcompat.filename);
69207 + subj->inode = subjcompat.inode;
69208 + subj->device = subjcompat.device;
69209 + subj->mode = subjcompat.mode;
69210 + subj->cap_mask = subjcompat.cap_mask;
69211 + subj->cap_lower = subjcompat.cap_lower;
69212 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
69213 +
69214 + for (i = 0; i < GR_NLIMITS; i++) {
69215 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69216 + subj->res[i].rlim_cur = RLIM_INFINITY;
69217 + else
69218 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69219 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69220 + subj->res[i].rlim_max = RLIM_INFINITY;
69221 + else
69222 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69223 + }
69224 + subj->resmask = subjcompat.resmask;
69225 +
69226 + subj->user_trans_type = subjcompat.user_trans_type;
69227 + subj->group_trans_type = subjcompat.group_trans_type;
69228 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69229 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69230 + subj->user_trans_num = subjcompat.user_trans_num;
69231 + subj->group_trans_num = subjcompat.group_trans_num;
69232 +
69233 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69234 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69235 + subj->ip_type = subjcompat.ip_type;
69236 + subj->ips = compat_ptr(subjcompat.ips);
69237 + subj->ip_num = subjcompat.ip_num;
69238 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
69239 +
69240 + subj->crashes = subjcompat.crashes;
69241 + subj->expires = subjcompat.expires;
69242 +
69243 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69244 + subj->hash = compat_ptr(subjcompat.hash);
69245 + subj->prev = compat_ptr(subjcompat.prev);
69246 + subj->next = compat_ptr(subjcompat.next);
69247 +
69248 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69249 + subj->obj_hash_size = subjcompat.obj_hash_size;
69250 + subj->pax_flags = subjcompat.pax_flags;
69251 +
69252 + return 0;
69253 +}
69254 +
69255 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69256 +{
69257 + struct acl_role_label_compat rolecompat;
69258 +
69259 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69260 + return -EFAULT;
69261 +
69262 + role->rolename = compat_ptr(rolecompat.rolename);
69263 + role->uidgid = rolecompat.uidgid;
69264 + role->roletype = rolecompat.roletype;
69265 +
69266 + role->auth_attempts = rolecompat.auth_attempts;
69267 + role->expires = rolecompat.expires;
69268 +
69269 + role->root_label = compat_ptr(rolecompat.root_label);
69270 + role->hash = compat_ptr(rolecompat.hash);
69271 +
69272 + role->prev = compat_ptr(rolecompat.prev);
69273 + role->next = compat_ptr(rolecompat.next);
69274 +
69275 + role->transitions = compat_ptr(rolecompat.transitions);
69276 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69277 + role->domain_children = compat_ptr(rolecompat.domain_children);
69278 + role->domain_child_num = rolecompat.domain_child_num;
69279 +
69280 + role->umask = rolecompat.umask;
69281 +
69282 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
69283 + role->subj_hash_size = rolecompat.subj_hash_size;
69284 +
69285 + return 0;
69286 +}
69287 +
69288 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69289 +{
69290 + struct role_allowed_ip_compat roleip_compat;
69291 +
69292 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69293 + return -EFAULT;
69294 +
69295 + roleip->addr = roleip_compat.addr;
69296 + roleip->netmask = roleip_compat.netmask;
69297 +
69298 + roleip->prev = compat_ptr(roleip_compat.prev);
69299 + roleip->next = compat_ptr(roleip_compat.next);
69300 +
69301 + return 0;
69302 +}
69303 +
69304 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69305 +{
69306 + struct role_transition_compat trans_compat;
69307 +
69308 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69309 + return -EFAULT;
69310 +
69311 + trans->rolename = compat_ptr(trans_compat.rolename);
69312 +
69313 + trans->prev = compat_ptr(trans_compat.prev);
69314 + trans->next = compat_ptr(trans_compat.next);
69315 +
69316 + return 0;
69317 +
69318 +}
69319 +
69320 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69321 +{
69322 + struct gr_hash_struct_compat hash_compat;
69323 +
69324 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69325 + return -EFAULT;
69326 +
69327 + hash->table = compat_ptr(hash_compat.table);
69328 + hash->nametable = compat_ptr(hash_compat.nametable);
69329 + hash->first = compat_ptr(hash_compat.first);
69330 +
69331 + hash->table_size = hash_compat.table_size;
69332 + hash->used_size = hash_compat.used_size;
69333 +
69334 + hash->type = hash_compat.type;
69335 +
69336 + return 0;
69337 +}
69338 +
69339 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69340 +{
69341 + compat_uptr_t ptrcompat;
69342 +
69343 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69344 + return -EFAULT;
69345 +
69346 + *(void **)ptr = compat_ptr(ptrcompat);
69347 +
69348 + return 0;
69349 +}
69350 +
69351 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69352 +{
69353 + struct acl_ip_label_compat ip_compat;
69354 +
69355 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69356 + return -EFAULT;
69357 +
69358 + ip->iface = compat_ptr(ip_compat.iface);
69359 + ip->addr = ip_compat.addr;
69360 + ip->netmask = ip_compat.netmask;
69361 + ip->low = ip_compat.low;
69362 + ip->high = ip_compat.high;
69363 + ip->mode = ip_compat.mode;
69364 + ip->type = ip_compat.type;
69365 +
69366 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69367 +
69368 + ip->prev = compat_ptr(ip_compat.prev);
69369 + ip->next = compat_ptr(ip_compat.next);
69370 +
69371 + return 0;
69372 +}
69373 +
69374 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69375 +{
69376 + struct sprole_pw_compat pw_compat;
69377 +
69378 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69379 + return -EFAULT;
69380 +
69381 + pw->rolename = compat_ptr(pw_compat.rolename);
69382 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69383 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69384 +
69385 + return 0;
69386 +}
69387 +
69388 +size_t get_gr_arg_wrapper_size_compat(void)
69389 +{
69390 + return sizeof(struct gr_arg_wrapper_compat);
69391 +}
69392 +
69393 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69394 new file mode 100644
69395 index 0000000..a89b1f4
69396 --- /dev/null
69397 +++ b/grsecurity/gracl_fs.c
69398 @@ -0,0 +1,437 @@
69399 +#include <linux/kernel.h>
69400 +#include <linux/sched.h>
69401 +#include <linux/types.h>
69402 +#include <linux/fs.h>
69403 +#include <linux/file.h>
69404 +#include <linux/stat.h>
69405 +#include <linux/grsecurity.h>
69406 +#include <linux/grinternal.h>
69407 +#include <linux/gracl.h>
69408 +
69409 +umode_t
69410 +gr_acl_umask(void)
69411 +{
69412 + if (unlikely(!gr_acl_is_enabled()))
69413 + return 0;
69414 +
69415 + return current->role->umask;
69416 +}
69417 +
69418 +__u32
69419 +gr_acl_handle_hidden_file(const struct dentry * dentry,
69420 + const struct vfsmount * mnt)
69421 +{
69422 + __u32 mode;
69423 +
69424 + if (unlikely(d_is_negative(dentry)))
69425 + return GR_FIND;
69426 +
69427 + mode =
69428 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69429 +
69430 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69431 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69432 + return mode;
69433 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69434 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69435 + return 0;
69436 + } else if (unlikely(!(mode & GR_FIND)))
69437 + return 0;
69438 +
69439 + return GR_FIND;
69440 +}
69441 +
69442 +__u32
69443 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69444 + int acc_mode)
69445 +{
69446 + __u32 reqmode = GR_FIND;
69447 + __u32 mode;
69448 +
69449 + if (unlikely(d_is_negative(dentry)))
69450 + return reqmode;
69451 +
69452 + if (acc_mode & MAY_APPEND)
69453 + reqmode |= GR_APPEND;
69454 + else if (acc_mode & MAY_WRITE)
69455 + reqmode |= GR_WRITE;
69456 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69457 + reqmode |= GR_READ;
69458 +
69459 + mode =
69460 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69461 + mnt);
69462 +
69463 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69464 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69465 + reqmode & GR_READ ? " reading" : "",
69466 + reqmode & GR_WRITE ? " writing" : reqmode &
69467 + GR_APPEND ? " appending" : "");
69468 + return reqmode;
69469 + } else
69470 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69471 + {
69472 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69473 + reqmode & GR_READ ? " reading" : "",
69474 + reqmode & GR_WRITE ? " writing" : reqmode &
69475 + GR_APPEND ? " appending" : "");
69476 + return 0;
69477 + } else if (unlikely((mode & reqmode) != reqmode))
69478 + return 0;
69479 +
69480 + return reqmode;
69481 +}
69482 +
69483 +__u32
69484 +gr_acl_handle_creat(const struct dentry * dentry,
69485 + const struct dentry * p_dentry,
69486 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69487 + const int imode)
69488 +{
69489 + __u32 reqmode = GR_WRITE | GR_CREATE;
69490 + __u32 mode;
69491 +
69492 + if (acc_mode & MAY_APPEND)
69493 + reqmode |= GR_APPEND;
69494 + // if a directory was required or the directory already exists, then
69495 + // don't count this open as a read
69496 + if ((acc_mode & MAY_READ) &&
69497 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
69498 + reqmode |= GR_READ;
69499 + if ((open_flags & O_CREAT) &&
69500 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69501 + reqmode |= GR_SETID;
69502 +
69503 + mode =
69504 + gr_check_create(dentry, p_dentry, p_mnt,
69505 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69506 +
69507 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69508 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69509 + reqmode & GR_READ ? " reading" : "",
69510 + reqmode & GR_WRITE ? " writing" : reqmode &
69511 + GR_APPEND ? " appending" : "");
69512 + return reqmode;
69513 + } else
69514 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69515 + {
69516 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69517 + reqmode & GR_READ ? " reading" : "",
69518 + reqmode & GR_WRITE ? " writing" : reqmode &
69519 + GR_APPEND ? " appending" : "");
69520 + return 0;
69521 + } else if (unlikely((mode & reqmode) != reqmode))
69522 + return 0;
69523 +
69524 + return reqmode;
69525 +}
69526 +
69527 +__u32
69528 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
69529 + const int fmode)
69530 +{
69531 + __u32 mode, reqmode = GR_FIND;
69532 +
69533 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
69534 + reqmode |= GR_EXEC;
69535 + if (fmode & S_IWOTH)
69536 + reqmode |= GR_WRITE;
69537 + if (fmode & S_IROTH)
69538 + reqmode |= GR_READ;
69539 +
69540 + mode =
69541 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69542 + mnt);
69543 +
69544 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69545 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69546 + reqmode & GR_READ ? " reading" : "",
69547 + reqmode & GR_WRITE ? " writing" : "",
69548 + reqmode & GR_EXEC ? " executing" : "");
69549 + return reqmode;
69550 + } else
69551 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69552 + {
69553 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69554 + reqmode & GR_READ ? " reading" : "",
69555 + reqmode & GR_WRITE ? " writing" : "",
69556 + reqmode & GR_EXEC ? " executing" : "");
69557 + return 0;
69558 + } else if (unlikely((mode & reqmode) != reqmode))
69559 + return 0;
69560 +
69561 + return reqmode;
69562 +}
69563 +
69564 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
69565 +{
69566 + __u32 mode;
69567 +
69568 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
69569 +
69570 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69571 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
69572 + return mode;
69573 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69574 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
69575 + return 0;
69576 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
69577 + return 0;
69578 +
69579 + return (reqmode);
69580 +}
69581 +
69582 +__u32
69583 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69584 +{
69585 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
69586 +}
69587 +
69588 +__u32
69589 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
69590 +{
69591 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
69592 +}
69593 +
69594 +__u32
69595 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
69596 +{
69597 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
69598 +}
69599 +
69600 +__u32
69601 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
69602 +{
69603 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
69604 +}
69605 +
69606 +__u32
69607 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
69608 + umode_t *modeptr)
69609 +{
69610 + umode_t mode;
69611 +
69612 + *modeptr &= ~gr_acl_umask();
69613 + mode = *modeptr;
69614 +
69615 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
69616 + return 1;
69617 +
69618 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
69619 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
69620 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
69621 + GR_CHMOD_ACL_MSG);
69622 + } else {
69623 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
69624 + }
69625 +}
69626 +
69627 +__u32
69628 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
69629 +{
69630 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
69631 +}
69632 +
69633 +__u32
69634 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
69635 +{
69636 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
69637 +}
69638 +
69639 +__u32
69640 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
69641 +{
69642 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
69643 +}
69644 +
69645 +__u32
69646 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
69647 +{
69648 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
69649 +}
69650 +
69651 +__u32
69652 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
69653 +{
69654 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
69655 + GR_UNIXCONNECT_ACL_MSG);
69656 +}
69657 +
69658 +/* hardlinks require at minimum create and link permission,
69659 + any additional privilege required is based on the
69660 + privilege of the file being linked to
69661 +*/
69662 +__u32
69663 +gr_acl_handle_link(const struct dentry * new_dentry,
69664 + const struct dentry * parent_dentry,
69665 + const struct vfsmount * parent_mnt,
69666 + const struct dentry * old_dentry,
69667 + const struct vfsmount * old_mnt, const struct filename *to)
69668 +{
69669 + __u32 mode;
69670 + __u32 needmode = GR_CREATE | GR_LINK;
69671 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
69672 +
69673 + mode =
69674 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
69675 + old_mnt);
69676 +
69677 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
69678 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69679 + return mode;
69680 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69681 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69682 + return 0;
69683 + } else if (unlikely((mode & needmode) != needmode))
69684 + return 0;
69685 +
69686 + return 1;
69687 +}
69688 +
69689 +__u32
69690 +gr_acl_handle_symlink(const struct dentry * new_dentry,
69691 + const struct dentry * parent_dentry,
69692 + const struct vfsmount * parent_mnt, const struct filename *from)
69693 +{
69694 + __u32 needmode = GR_WRITE | GR_CREATE;
69695 + __u32 mode;
69696 +
69697 + mode =
69698 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
69699 + GR_CREATE | GR_AUDIT_CREATE |
69700 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
69701 +
69702 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
69703 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69704 + return mode;
69705 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69706 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69707 + return 0;
69708 + } else if (unlikely((mode & needmode) != needmode))
69709 + return 0;
69710 +
69711 + return (GR_WRITE | GR_CREATE);
69712 +}
69713 +
69714 +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)
69715 +{
69716 + __u32 mode;
69717 +
69718 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69719 +
69720 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69721 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
69722 + return mode;
69723 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69724 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
69725 + return 0;
69726 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
69727 + return 0;
69728 +
69729 + return (reqmode);
69730 +}
69731 +
69732 +__u32
69733 +gr_acl_handle_mknod(const struct dentry * new_dentry,
69734 + const struct dentry * parent_dentry,
69735 + const struct vfsmount * parent_mnt,
69736 + const int mode)
69737 +{
69738 + __u32 reqmode = GR_WRITE | GR_CREATE;
69739 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69740 + reqmode |= GR_SETID;
69741 +
69742 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69743 + reqmode, GR_MKNOD_ACL_MSG);
69744 +}
69745 +
69746 +__u32
69747 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
69748 + const struct dentry *parent_dentry,
69749 + const struct vfsmount *parent_mnt)
69750 +{
69751 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69752 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
69753 +}
69754 +
69755 +#define RENAME_CHECK_SUCCESS(old, new) \
69756 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
69757 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
69758 +
69759 +int
69760 +gr_acl_handle_rename(struct dentry *new_dentry,
69761 + struct dentry *parent_dentry,
69762 + const struct vfsmount *parent_mnt,
69763 + struct dentry *old_dentry,
69764 + struct inode *old_parent_inode,
69765 + struct vfsmount *old_mnt, const struct filename *newname)
69766 +{
69767 + __u32 comp1, comp2;
69768 + int error = 0;
69769 +
69770 + if (unlikely(!gr_acl_is_enabled()))
69771 + return 0;
69772 +
69773 + if (d_is_negative(new_dentry)) {
69774 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
69775 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
69776 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
69777 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
69778 + GR_DELETE | GR_AUDIT_DELETE |
69779 + GR_AUDIT_READ | GR_AUDIT_WRITE |
69780 + GR_SUPPRESS, old_mnt);
69781 + } else {
69782 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
69783 + GR_CREATE | GR_DELETE |
69784 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
69785 + GR_AUDIT_READ | GR_AUDIT_WRITE |
69786 + GR_SUPPRESS, parent_mnt);
69787 + comp2 =
69788 + gr_search_file(old_dentry,
69789 + GR_READ | GR_WRITE | GR_AUDIT_READ |
69790 + GR_DELETE | GR_AUDIT_DELETE |
69791 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
69792 + }
69793 +
69794 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
69795 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
69796 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69797 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
69798 + && !(comp2 & GR_SUPPRESS)) {
69799 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69800 + error = -EACCES;
69801 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
69802 + error = -EACCES;
69803 +
69804 + return error;
69805 +}
69806 +
69807 +void
69808 +gr_acl_handle_exit(void)
69809 +{
69810 + u16 id;
69811 + char *rolename;
69812 +
69813 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
69814 + !(current->role->roletype & GR_ROLE_PERSIST))) {
69815 + id = current->acl_role_id;
69816 + rolename = current->role->rolename;
69817 + gr_set_acls(1);
69818 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
69819 + }
69820 +
69821 + gr_put_exec_file(current);
69822 + return;
69823 +}
69824 +
69825 +int
69826 +gr_acl_handle_procpidmem(const struct task_struct *task)
69827 +{
69828 + if (unlikely(!gr_acl_is_enabled()))
69829 + return 0;
69830 +
69831 + if (task != current && task->acl->mode & GR_PROTPROCFD)
69832 + return -EACCES;
69833 +
69834 + return 0;
69835 +}
69836 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
69837 new file mode 100644
69838 index 0000000..f056b81
69839 --- /dev/null
69840 +++ b/grsecurity/gracl_ip.c
69841 @@ -0,0 +1,386 @@
69842 +#include <linux/kernel.h>
69843 +#include <asm/uaccess.h>
69844 +#include <asm/errno.h>
69845 +#include <net/sock.h>
69846 +#include <linux/file.h>
69847 +#include <linux/fs.h>
69848 +#include <linux/net.h>
69849 +#include <linux/in.h>
69850 +#include <linux/skbuff.h>
69851 +#include <linux/ip.h>
69852 +#include <linux/udp.h>
69853 +#include <linux/types.h>
69854 +#include <linux/sched.h>
69855 +#include <linux/netdevice.h>
69856 +#include <linux/inetdevice.h>
69857 +#include <linux/gracl.h>
69858 +#include <linux/grsecurity.h>
69859 +#include <linux/grinternal.h>
69860 +
69861 +#define GR_BIND 0x01
69862 +#define GR_CONNECT 0x02
69863 +#define GR_INVERT 0x04
69864 +#define GR_BINDOVERRIDE 0x08
69865 +#define GR_CONNECTOVERRIDE 0x10
69866 +#define GR_SOCK_FAMILY 0x20
69867 +
69868 +static const char * gr_protocols[IPPROTO_MAX] = {
69869 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
69870 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
69871 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
69872 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
69873 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
69874 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
69875 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
69876 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
69877 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
69878 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
69879 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
69880 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
69881 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
69882 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
69883 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
69884 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
69885 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
69886 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
69887 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
69888 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
69889 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
69890 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
69891 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
69892 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
69893 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
69894 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
69895 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
69896 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
69897 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
69898 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
69899 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
69900 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
69901 + };
69902 +
69903 +static const char * gr_socktypes[SOCK_MAX] = {
69904 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
69905 + "unknown:7", "unknown:8", "unknown:9", "packet"
69906 + };
69907 +
69908 +static const char * gr_sockfamilies[AF_MAX+1] = {
69909 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
69910 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
69911 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
69912 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
69913 + };
69914 +
69915 +const char *
69916 +gr_proto_to_name(unsigned char proto)
69917 +{
69918 + return gr_protocols[proto];
69919 +}
69920 +
69921 +const char *
69922 +gr_socktype_to_name(unsigned char type)
69923 +{
69924 + return gr_socktypes[type];
69925 +}
69926 +
69927 +const char *
69928 +gr_sockfamily_to_name(unsigned char family)
69929 +{
69930 + return gr_sockfamilies[family];
69931 +}
69932 +
69933 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
69934 +
69935 +int
69936 +gr_search_socket(const int domain, const int type, const int protocol)
69937 +{
69938 + struct acl_subject_label *curr;
69939 + const struct cred *cred = current_cred();
69940 +
69941 + if (unlikely(!gr_acl_is_enabled()))
69942 + goto exit;
69943 +
69944 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
69945 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
69946 + goto exit; // let the kernel handle it
69947 +
69948 + curr = current->acl;
69949 +
69950 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
69951 + /* the family is allowed, if this is PF_INET allow it only if
69952 + the extra sock type/protocol checks pass */
69953 + if (domain == PF_INET)
69954 + goto inet_check;
69955 + goto exit;
69956 + } else {
69957 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69958 + __u32 fakeip = 0;
69959 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69960 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69961 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69962 + gr_to_filename(current->exec_file->f_path.dentry,
69963 + current->exec_file->f_path.mnt) :
69964 + curr->filename, curr->filename,
69965 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
69966 + &current->signal->saved_ip);
69967 + goto exit;
69968 + }
69969 + goto exit_fail;
69970 + }
69971 +
69972 +inet_check:
69973 + /* the rest of this checking is for IPv4 only */
69974 + if (!curr->ips)
69975 + goto exit;
69976 +
69977 + if ((curr->ip_type & (1U << type)) &&
69978 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
69979 + goto exit;
69980 +
69981 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69982 + /* we don't place acls on raw sockets , and sometimes
69983 + dgram/ip sockets are opened for ioctl and not
69984 + bind/connect, so we'll fake a bind learn log */
69985 + if (type == SOCK_RAW || type == SOCK_PACKET) {
69986 + __u32 fakeip = 0;
69987 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69988 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69989 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69990 + gr_to_filename(current->exec_file->f_path.dentry,
69991 + current->exec_file->f_path.mnt) :
69992 + curr->filename, curr->filename,
69993 + &fakeip, 0, type,
69994 + protocol, GR_CONNECT, &current->signal->saved_ip);
69995 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
69996 + __u32 fakeip = 0;
69997 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69998 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69999 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70000 + gr_to_filename(current->exec_file->f_path.dentry,
70001 + current->exec_file->f_path.mnt) :
70002 + curr->filename, curr->filename,
70003 + &fakeip, 0, type,
70004 + protocol, GR_BIND, &current->signal->saved_ip);
70005 + }
70006 + /* we'll log when they use connect or bind */
70007 + goto exit;
70008 + }
70009 +
70010 +exit_fail:
70011 + if (domain == PF_INET)
70012 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70013 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
70014 + else if (rcu_access_pointer(net_families[domain]) != NULL)
70015 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70016 + gr_socktype_to_name(type), protocol);
70017 +
70018 + return 0;
70019 +exit:
70020 + return 1;
70021 +}
70022 +
70023 +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)
70024 +{
70025 + if ((ip->mode & mode) &&
70026 + (ip_port >= ip->low) &&
70027 + (ip_port <= ip->high) &&
70028 + ((ntohl(ip_addr) & our_netmask) ==
70029 + (ntohl(our_addr) & our_netmask))
70030 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70031 + && (ip->type & (1U << type))) {
70032 + if (ip->mode & GR_INVERT)
70033 + return 2; // specifically denied
70034 + else
70035 + return 1; // allowed
70036 + }
70037 +
70038 + return 0; // not specifically allowed, may continue parsing
70039 +}
70040 +
70041 +static int
70042 +gr_search_connectbind(const int full_mode, struct sock *sk,
70043 + struct sockaddr_in *addr, const int type)
70044 +{
70045 + char iface[IFNAMSIZ] = {0};
70046 + struct acl_subject_label *curr;
70047 + struct acl_ip_label *ip;
70048 + struct inet_sock *isk;
70049 + struct net_device *dev;
70050 + struct in_device *idev;
70051 + unsigned long i;
70052 + int ret;
70053 + int mode = full_mode & (GR_BIND | GR_CONNECT);
70054 + __u32 ip_addr = 0;
70055 + __u32 our_addr;
70056 + __u32 our_netmask;
70057 + char *p;
70058 + __u16 ip_port = 0;
70059 + const struct cred *cred = current_cred();
70060 +
70061 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70062 + return 0;
70063 +
70064 + curr = current->acl;
70065 + isk = inet_sk(sk);
70066 +
70067 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70068 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70069 + addr->sin_addr.s_addr = curr->inaddr_any_override;
70070 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70071 + struct sockaddr_in saddr;
70072 + int err;
70073 +
70074 + saddr.sin_family = AF_INET;
70075 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
70076 + saddr.sin_port = isk->inet_sport;
70077 +
70078 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70079 + if (err)
70080 + return err;
70081 +
70082 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70083 + if (err)
70084 + return err;
70085 + }
70086 +
70087 + if (!curr->ips)
70088 + return 0;
70089 +
70090 + ip_addr = addr->sin_addr.s_addr;
70091 + ip_port = ntohs(addr->sin_port);
70092 +
70093 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70094 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70095 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70096 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70097 + gr_to_filename(current->exec_file->f_path.dentry,
70098 + current->exec_file->f_path.mnt) :
70099 + curr->filename, curr->filename,
70100 + &ip_addr, ip_port, type,
70101 + sk->sk_protocol, mode, &current->signal->saved_ip);
70102 + return 0;
70103 + }
70104 +
70105 + for (i = 0; i < curr->ip_num; i++) {
70106 + ip = *(curr->ips + i);
70107 + if (ip->iface != NULL) {
70108 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
70109 + p = strchr(iface, ':');
70110 + if (p != NULL)
70111 + *p = '\0';
70112 + dev = dev_get_by_name(sock_net(sk), iface);
70113 + if (dev == NULL)
70114 + continue;
70115 + idev = in_dev_get(dev);
70116 + if (idev == NULL) {
70117 + dev_put(dev);
70118 + continue;
70119 + }
70120 + rcu_read_lock();
70121 + for_ifa(idev) {
70122 + if (!strcmp(ip->iface, ifa->ifa_label)) {
70123 + our_addr = ifa->ifa_address;
70124 + our_netmask = 0xffffffff;
70125 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70126 + if (ret == 1) {
70127 + rcu_read_unlock();
70128 + in_dev_put(idev);
70129 + dev_put(dev);
70130 + return 0;
70131 + } else if (ret == 2) {
70132 + rcu_read_unlock();
70133 + in_dev_put(idev);
70134 + dev_put(dev);
70135 + goto denied;
70136 + }
70137 + }
70138 + } endfor_ifa(idev);
70139 + rcu_read_unlock();
70140 + in_dev_put(idev);
70141 + dev_put(dev);
70142 + } else {
70143 + our_addr = ip->addr;
70144 + our_netmask = ip->netmask;
70145 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70146 + if (ret == 1)
70147 + return 0;
70148 + else if (ret == 2)
70149 + goto denied;
70150 + }
70151 + }
70152 +
70153 +denied:
70154 + if (mode == GR_BIND)
70155 + 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));
70156 + else if (mode == GR_CONNECT)
70157 + 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));
70158 +
70159 + return -EACCES;
70160 +}
70161 +
70162 +int
70163 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70164 +{
70165 + /* always allow disconnection of dgram sockets with connect */
70166 + if (addr->sin_family == AF_UNSPEC)
70167 + return 0;
70168 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70169 +}
70170 +
70171 +int
70172 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70173 +{
70174 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70175 +}
70176 +
70177 +int gr_search_listen(struct socket *sock)
70178 +{
70179 + struct sock *sk = sock->sk;
70180 + struct sockaddr_in addr;
70181 +
70182 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70183 + addr.sin_port = inet_sk(sk)->inet_sport;
70184 +
70185 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70186 +}
70187 +
70188 +int gr_search_accept(struct socket *sock)
70189 +{
70190 + struct sock *sk = sock->sk;
70191 + struct sockaddr_in addr;
70192 +
70193 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70194 + addr.sin_port = inet_sk(sk)->inet_sport;
70195 +
70196 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70197 +}
70198 +
70199 +int
70200 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70201 +{
70202 + if (addr)
70203 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70204 + else {
70205 + struct sockaddr_in sin;
70206 + const struct inet_sock *inet = inet_sk(sk);
70207 +
70208 + sin.sin_addr.s_addr = inet->inet_daddr;
70209 + sin.sin_port = inet->inet_dport;
70210 +
70211 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70212 + }
70213 +}
70214 +
70215 +int
70216 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70217 +{
70218 + struct sockaddr_in sin;
70219 +
70220 + if (unlikely(skb->len < sizeof (struct udphdr)))
70221 + return 0; // skip this packet
70222 +
70223 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70224 + sin.sin_port = udp_hdr(skb)->source;
70225 +
70226 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70227 +}
70228 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70229 new file mode 100644
70230 index 0000000..25f54ef
70231 --- /dev/null
70232 +++ b/grsecurity/gracl_learn.c
70233 @@ -0,0 +1,207 @@
70234 +#include <linux/kernel.h>
70235 +#include <linux/mm.h>
70236 +#include <linux/sched.h>
70237 +#include <linux/poll.h>
70238 +#include <linux/string.h>
70239 +#include <linux/file.h>
70240 +#include <linux/types.h>
70241 +#include <linux/vmalloc.h>
70242 +#include <linux/grinternal.h>
70243 +
70244 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70245 + size_t count, loff_t *ppos);
70246 +extern int gr_acl_is_enabled(void);
70247 +
70248 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70249 +static int gr_learn_attached;
70250 +
70251 +/* use a 512k buffer */
70252 +#define LEARN_BUFFER_SIZE (512 * 1024)
70253 +
70254 +static DEFINE_SPINLOCK(gr_learn_lock);
70255 +static DEFINE_MUTEX(gr_learn_user_mutex);
70256 +
70257 +/* we need to maintain two buffers, so that the kernel context of grlearn
70258 + uses a semaphore around the userspace copying, and the other kernel contexts
70259 + use a spinlock when copying into the buffer, since they cannot sleep
70260 +*/
70261 +static char *learn_buffer;
70262 +static char *learn_buffer_user;
70263 +static int learn_buffer_len;
70264 +static int learn_buffer_user_len;
70265 +
70266 +static ssize_t
70267 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70268 +{
70269 + DECLARE_WAITQUEUE(wait, current);
70270 + ssize_t retval = 0;
70271 +
70272 + add_wait_queue(&learn_wait, &wait);
70273 + set_current_state(TASK_INTERRUPTIBLE);
70274 + do {
70275 + mutex_lock(&gr_learn_user_mutex);
70276 + spin_lock(&gr_learn_lock);
70277 + if (learn_buffer_len)
70278 + break;
70279 + spin_unlock(&gr_learn_lock);
70280 + mutex_unlock(&gr_learn_user_mutex);
70281 + if (file->f_flags & O_NONBLOCK) {
70282 + retval = -EAGAIN;
70283 + goto out;
70284 + }
70285 + if (signal_pending(current)) {
70286 + retval = -ERESTARTSYS;
70287 + goto out;
70288 + }
70289 +
70290 + schedule();
70291 + } while (1);
70292 +
70293 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70294 + learn_buffer_user_len = learn_buffer_len;
70295 + retval = learn_buffer_len;
70296 + learn_buffer_len = 0;
70297 +
70298 + spin_unlock(&gr_learn_lock);
70299 +
70300 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70301 + retval = -EFAULT;
70302 +
70303 + mutex_unlock(&gr_learn_user_mutex);
70304 +out:
70305 + set_current_state(TASK_RUNNING);
70306 + remove_wait_queue(&learn_wait, &wait);
70307 + return retval;
70308 +}
70309 +
70310 +static unsigned int
70311 +poll_learn(struct file * file, poll_table * wait)
70312 +{
70313 + poll_wait(file, &learn_wait, wait);
70314 +
70315 + if (learn_buffer_len)
70316 + return (POLLIN | POLLRDNORM);
70317 +
70318 + return 0;
70319 +}
70320 +
70321 +void
70322 +gr_clear_learn_entries(void)
70323 +{
70324 + char *tmp;
70325 +
70326 + mutex_lock(&gr_learn_user_mutex);
70327 + spin_lock(&gr_learn_lock);
70328 + tmp = learn_buffer;
70329 + learn_buffer = NULL;
70330 + spin_unlock(&gr_learn_lock);
70331 + if (tmp)
70332 + vfree(tmp);
70333 + if (learn_buffer_user != NULL) {
70334 + vfree(learn_buffer_user);
70335 + learn_buffer_user = NULL;
70336 + }
70337 + learn_buffer_len = 0;
70338 + mutex_unlock(&gr_learn_user_mutex);
70339 +
70340 + return;
70341 +}
70342 +
70343 +void
70344 +gr_add_learn_entry(const char *fmt, ...)
70345 +{
70346 + va_list args;
70347 + unsigned int len;
70348 +
70349 + if (!gr_learn_attached)
70350 + return;
70351 +
70352 + spin_lock(&gr_learn_lock);
70353 +
70354 + /* leave a gap at the end so we know when it's "full" but don't have to
70355 + compute the exact length of the string we're trying to append
70356 + */
70357 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70358 + spin_unlock(&gr_learn_lock);
70359 + wake_up_interruptible(&learn_wait);
70360 + return;
70361 + }
70362 + if (learn_buffer == NULL) {
70363 + spin_unlock(&gr_learn_lock);
70364 + return;
70365 + }
70366 +
70367 + va_start(args, fmt);
70368 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70369 + va_end(args);
70370 +
70371 + learn_buffer_len += len + 1;
70372 +
70373 + spin_unlock(&gr_learn_lock);
70374 + wake_up_interruptible(&learn_wait);
70375 +
70376 + return;
70377 +}
70378 +
70379 +static int
70380 +open_learn(struct inode *inode, struct file *file)
70381 +{
70382 + if (file->f_mode & FMODE_READ && gr_learn_attached)
70383 + return -EBUSY;
70384 + if (file->f_mode & FMODE_READ) {
70385 + int retval = 0;
70386 + mutex_lock(&gr_learn_user_mutex);
70387 + if (learn_buffer == NULL)
70388 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70389 + if (learn_buffer_user == NULL)
70390 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70391 + if (learn_buffer == NULL) {
70392 + retval = -ENOMEM;
70393 + goto out_error;
70394 + }
70395 + if (learn_buffer_user == NULL) {
70396 + retval = -ENOMEM;
70397 + goto out_error;
70398 + }
70399 + learn_buffer_len = 0;
70400 + learn_buffer_user_len = 0;
70401 + gr_learn_attached = 1;
70402 +out_error:
70403 + mutex_unlock(&gr_learn_user_mutex);
70404 + return retval;
70405 + }
70406 + return 0;
70407 +}
70408 +
70409 +static int
70410 +close_learn(struct inode *inode, struct file *file)
70411 +{
70412 + if (file->f_mode & FMODE_READ) {
70413 + char *tmp = NULL;
70414 + mutex_lock(&gr_learn_user_mutex);
70415 + spin_lock(&gr_learn_lock);
70416 + tmp = learn_buffer;
70417 + learn_buffer = NULL;
70418 + spin_unlock(&gr_learn_lock);
70419 + if (tmp)
70420 + vfree(tmp);
70421 + if (learn_buffer_user != NULL) {
70422 + vfree(learn_buffer_user);
70423 + learn_buffer_user = NULL;
70424 + }
70425 + learn_buffer_len = 0;
70426 + learn_buffer_user_len = 0;
70427 + gr_learn_attached = 0;
70428 + mutex_unlock(&gr_learn_user_mutex);
70429 + }
70430 +
70431 + return 0;
70432 +}
70433 +
70434 +const struct file_operations grsec_fops = {
70435 + .read = read_learn,
70436 + .write = write_grsec_handler,
70437 + .open = open_learn,
70438 + .release = close_learn,
70439 + .poll = poll_learn,
70440 +};
70441 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70442 new file mode 100644
70443 index 0000000..361a099
70444 --- /dev/null
70445 +++ b/grsecurity/gracl_policy.c
70446 @@ -0,0 +1,1782 @@
70447 +#include <linux/kernel.h>
70448 +#include <linux/module.h>
70449 +#include <linux/sched.h>
70450 +#include <linux/mm.h>
70451 +#include <linux/file.h>
70452 +#include <linux/fs.h>
70453 +#include <linux/namei.h>
70454 +#include <linux/mount.h>
70455 +#include <linux/tty.h>
70456 +#include <linux/proc_fs.h>
70457 +#include <linux/lglock.h>
70458 +#include <linux/slab.h>
70459 +#include <linux/vmalloc.h>
70460 +#include <linux/types.h>
70461 +#include <linux/sysctl.h>
70462 +#include <linux/netdevice.h>
70463 +#include <linux/ptrace.h>
70464 +#include <linux/gracl.h>
70465 +#include <linux/gralloc.h>
70466 +#include <linux/security.h>
70467 +#include <linux/grinternal.h>
70468 +#include <linux/pid_namespace.h>
70469 +#include <linux/stop_machine.h>
70470 +#include <linux/fdtable.h>
70471 +#include <linux/percpu.h>
70472 +#include <linux/lglock.h>
70473 +#include <linux/hugetlb.h>
70474 +#include <linux/posix-timers.h>
70475 +#include "../fs/mount.h"
70476 +
70477 +#include <asm/uaccess.h>
70478 +#include <asm/errno.h>
70479 +#include <asm/mman.h>
70480 +
70481 +extern struct gr_policy_state *polstate;
70482 +
70483 +#define FOR_EACH_ROLE_START(role) \
70484 + role = polstate->role_list; \
70485 + while (role) {
70486 +
70487 +#define FOR_EACH_ROLE_END(role) \
70488 + role = role->prev; \
70489 + }
70490 +
70491 +struct path gr_real_root;
70492 +
70493 +extern struct gr_alloc_state *current_alloc_state;
70494 +
70495 +u16 acl_sp_role_value;
70496 +
70497 +static DEFINE_MUTEX(gr_dev_mutex);
70498 +
70499 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
70500 +extern void gr_clear_learn_entries(void);
70501 +
70502 +static struct gr_arg gr_usermode;
70503 +static unsigned char gr_system_salt[GR_SALT_LEN];
70504 +static unsigned char gr_system_sum[GR_SHA_LEN];
70505 +
70506 +static unsigned int gr_auth_attempts = 0;
70507 +static unsigned long gr_auth_expires = 0UL;
70508 +
70509 +struct acl_object_label *fakefs_obj_rw;
70510 +struct acl_object_label *fakefs_obj_rwx;
70511 +
70512 +extern int gr_init_uidset(void);
70513 +extern void gr_free_uidset(void);
70514 +extern void gr_remove_uid(uid_t uid);
70515 +extern int gr_find_uid(uid_t uid);
70516 +
70517 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
70518 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
70519 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
70520 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
70521 +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);
70522 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
70523 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
70524 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
70525 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
70526 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70527 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70528 +extern void assign_special_role(const char *rolename);
70529 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
70530 +extern int gr_rbac_disable(void *unused);
70531 +extern void gr_enable_rbac_system(void);
70532 +
70533 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
70534 +{
70535 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
70536 + return -EFAULT;
70537 +
70538 + return 0;
70539 +}
70540 +
70541 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70542 +{
70543 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
70544 + return -EFAULT;
70545 +
70546 + return 0;
70547 +}
70548 +
70549 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70550 +{
70551 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
70552 + return -EFAULT;
70553 +
70554 + return 0;
70555 +}
70556 +
70557 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
70558 +{
70559 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
70560 + return -EFAULT;
70561 +
70562 + return 0;
70563 +}
70564 +
70565 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70566 +{
70567 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
70568 + return -EFAULT;
70569 +
70570 + return 0;
70571 +}
70572 +
70573 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70574 +{
70575 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
70576 + return -EFAULT;
70577 +
70578 + return 0;
70579 +}
70580 +
70581 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70582 +{
70583 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
70584 + return -EFAULT;
70585 +
70586 + return 0;
70587 +}
70588 +
70589 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
70590 +{
70591 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
70592 + return -EFAULT;
70593 +
70594 + return 0;
70595 +}
70596 +
70597 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
70598 +{
70599 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
70600 + return -EFAULT;
70601 +
70602 + return 0;
70603 +}
70604 +
70605 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
70606 +{
70607 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
70608 + return -EFAULT;
70609 +
70610 + if (((uwrap->version != GRSECURITY_VERSION) &&
70611 + (uwrap->version != 0x2901)) ||
70612 + (uwrap->size != sizeof(struct gr_arg)))
70613 + return -EINVAL;
70614 +
70615 + return 0;
70616 +}
70617 +
70618 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
70619 +{
70620 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
70621 + return -EFAULT;
70622 +
70623 + return 0;
70624 +}
70625 +
70626 +static size_t get_gr_arg_wrapper_size_normal(void)
70627 +{
70628 + return sizeof(struct gr_arg_wrapper);
70629 +}
70630 +
70631 +#ifdef CONFIG_COMPAT
70632 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
70633 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
70634 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
70635 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
70636 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
70637 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
70638 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
70639 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
70640 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
70641 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
70642 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
70643 +extern size_t get_gr_arg_wrapper_size_compat(void);
70644 +
70645 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
70646 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
70647 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
70648 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
70649 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
70650 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
70651 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
70652 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
70653 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
70654 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
70655 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
70656 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
70657 +
70658 +#else
70659 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
70660 +#define copy_gr_arg copy_gr_arg_normal
70661 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
70662 +#define copy_acl_object_label copy_acl_object_label_normal
70663 +#define copy_acl_subject_label copy_acl_subject_label_normal
70664 +#define copy_acl_role_label copy_acl_role_label_normal
70665 +#define copy_acl_ip_label copy_acl_ip_label_normal
70666 +#define copy_pointer_from_array copy_pointer_from_array_normal
70667 +#define copy_sprole_pw copy_sprole_pw_normal
70668 +#define copy_role_transition copy_role_transition_normal
70669 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
70670 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
70671 +#endif
70672 +
70673 +static struct acl_subject_label *
70674 +lookup_subject_map(const struct acl_subject_label *userp)
70675 +{
70676 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
70677 + struct subject_map *match;
70678 +
70679 + match = polstate->subj_map_set.s_hash[index];
70680 +
70681 + while (match && match->user != userp)
70682 + match = match->next;
70683 +
70684 + if (match != NULL)
70685 + return match->kernel;
70686 + else
70687 + return NULL;
70688 +}
70689 +
70690 +static void
70691 +insert_subj_map_entry(struct subject_map *subjmap)
70692 +{
70693 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
70694 + struct subject_map **curr;
70695 +
70696 + subjmap->prev = NULL;
70697 +
70698 + curr = &polstate->subj_map_set.s_hash[index];
70699 + if (*curr != NULL)
70700 + (*curr)->prev = subjmap;
70701 +
70702 + subjmap->next = *curr;
70703 + *curr = subjmap;
70704 +
70705 + return;
70706 +}
70707 +
70708 +static void
70709 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
70710 +{
70711 + unsigned int index =
70712 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
70713 + struct acl_role_label **curr;
70714 + struct acl_role_label *tmp, *tmp2;
70715 +
70716 + curr = &polstate->acl_role_set.r_hash[index];
70717 +
70718 + /* simple case, slot is empty, just set it to our role */
70719 + if (*curr == NULL) {
70720 + *curr = role;
70721 + } else {
70722 + /* example:
70723 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
70724 + 2 -> 3
70725 + */
70726 + /* first check to see if we can already be reached via this slot */
70727 + tmp = *curr;
70728 + while (tmp && tmp != role)
70729 + tmp = tmp->next;
70730 + if (tmp == role) {
70731 + /* we don't need to add ourselves to this slot's chain */
70732 + return;
70733 + }
70734 + /* we need to add ourselves to this chain, two cases */
70735 + if (role->next == NULL) {
70736 + /* simple case, append the current chain to our role */
70737 + role->next = *curr;
70738 + *curr = role;
70739 + } else {
70740 + /* 1 -> 2 -> 3 -> 4
70741 + 2 -> 3 -> 4
70742 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
70743 + */
70744 + /* trickier case: walk our role's chain until we find
70745 + the role for the start of the current slot's chain */
70746 + tmp = role;
70747 + tmp2 = *curr;
70748 + while (tmp->next && tmp->next != tmp2)
70749 + tmp = tmp->next;
70750 + if (tmp->next == tmp2) {
70751 + /* from example above, we found 3, so just
70752 + replace this slot's chain with ours */
70753 + *curr = role;
70754 + } else {
70755 + /* we didn't find a subset of our role's chain
70756 + in the current slot's chain, so append their
70757 + chain to ours, and set us as the first role in
70758 + the slot's chain
70759 +
70760 + we could fold this case with the case above,
70761 + but making it explicit for clarity
70762 + */
70763 + tmp->next = tmp2;
70764 + *curr = role;
70765 + }
70766 + }
70767 + }
70768 +
70769 + return;
70770 +}
70771 +
70772 +static void
70773 +insert_acl_role_label(struct acl_role_label *role)
70774 +{
70775 + int i;
70776 +
70777 + if (polstate->role_list == NULL) {
70778 + polstate->role_list = role;
70779 + role->prev = NULL;
70780 + } else {
70781 + role->prev = polstate->role_list;
70782 + polstate->role_list = role;
70783 + }
70784 +
70785 + /* used for hash chains */
70786 + role->next = NULL;
70787 +
70788 + if (role->roletype & GR_ROLE_DOMAIN) {
70789 + for (i = 0; i < role->domain_child_num; i++)
70790 + __insert_acl_role_label(role, role->domain_children[i]);
70791 + } else
70792 + __insert_acl_role_label(role, role->uidgid);
70793 +}
70794 +
70795 +static int
70796 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
70797 +{
70798 + struct name_entry **curr, *nentry;
70799 + struct inodev_entry *ientry;
70800 + unsigned int len = strlen(name);
70801 + unsigned int key = full_name_hash(name, len);
70802 + unsigned int index = key % polstate->name_set.n_size;
70803 +
70804 + curr = &polstate->name_set.n_hash[index];
70805 +
70806 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
70807 + curr = &((*curr)->next);
70808 +
70809 + if (*curr != NULL)
70810 + return 1;
70811 +
70812 + nentry = acl_alloc(sizeof (struct name_entry));
70813 + if (nentry == NULL)
70814 + return 0;
70815 + ientry = acl_alloc(sizeof (struct inodev_entry));
70816 + if (ientry == NULL)
70817 + return 0;
70818 + ientry->nentry = nentry;
70819 +
70820 + nentry->key = key;
70821 + nentry->name = name;
70822 + nentry->inode = inode;
70823 + nentry->device = device;
70824 + nentry->len = len;
70825 + nentry->deleted = deleted;
70826 +
70827 + nentry->prev = NULL;
70828 + curr = &polstate->name_set.n_hash[index];
70829 + if (*curr != NULL)
70830 + (*curr)->prev = nentry;
70831 + nentry->next = *curr;
70832 + *curr = nentry;
70833 +
70834 + /* insert us into the table searchable by inode/dev */
70835 + __insert_inodev_entry(polstate, ientry);
70836 +
70837 + return 1;
70838 +}
70839 +
70840 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
70841 +
70842 +static void *
70843 +create_table(__u32 * len, int elementsize)
70844 +{
70845 + unsigned int table_sizes[] = {
70846 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
70847 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
70848 + 4194301, 8388593, 16777213, 33554393, 67108859
70849 + };
70850 + void *newtable = NULL;
70851 + unsigned int pwr = 0;
70852 +
70853 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
70854 + table_sizes[pwr] <= *len)
70855 + pwr++;
70856 +
70857 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
70858 + return newtable;
70859 +
70860 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
70861 + newtable =
70862 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
70863 + else
70864 + newtable = vmalloc(table_sizes[pwr] * elementsize);
70865 +
70866 + *len = table_sizes[pwr];
70867 +
70868 + return newtable;
70869 +}
70870 +
70871 +static int
70872 +init_variables(const struct gr_arg *arg, bool reload)
70873 +{
70874 + struct task_struct *reaper = init_pid_ns.child_reaper;
70875 + unsigned int stacksize;
70876 +
70877 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
70878 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
70879 + polstate->name_set.n_size = arg->role_db.num_objects;
70880 + polstate->inodev_set.i_size = arg->role_db.num_objects;
70881 +
70882 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
70883 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
70884 + return 1;
70885 +
70886 + if (!reload) {
70887 + if (!gr_init_uidset())
70888 + return 1;
70889 + }
70890 +
70891 + /* set up the stack that holds allocation info */
70892 +
70893 + stacksize = arg->role_db.num_pointers + 5;
70894 +
70895 + if (!acl_alloc_stack_init(stacksize))
70896 + return 1;
70897 +
70898 + if (!reload) {
70899 + /* grab reference for the real root dentry and vfsmount */
70900 + get_fs_root(reaper->fs, &gr_real_root);
70901 +
70902 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70903 + 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);
70904 +#endif
70905 +
70906 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70907 + if (fakefs_obj_rw == NULL)
70908 + return 1;
70909 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
70910 +
70911 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70912 + if (fakefs_obj_rwx == NULL)
70913 + return 1;
70914 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
70915 + }
70916 +
70917 + polstate->subj_map_set.s_hash =
70918 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
70919 + polstate->acl_role_set.r_hash =
70920 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
70921 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
70922 + polstate->inodev_set.i_hash =
70923 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
70924 +
70925 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
70926 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
70927 + return 1;
70928 +
70929 + memset(polstate->subj_map_set.s_hash, 0,
70930 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
70931 + memset(polstate->acl_role_set.r_hash, 0,
70932 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
70933 + memset(polstate->name_set.n_hash, 0,
70934 + sizeof (struct name_entry *) * polstate->name_set.n_size);
70935 + memset(polstate->inodev_set.i_hash, 0,
70936 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
70937 +
70938 + return 0;
70939 +}
70940 +
70941 +/* free information not needed after startup
70942 + currently contains user->kernel pointer mappings for subjects
70943 +*/
70944 +
70945 +static void
70946 +free_init_variables(void)
70947 +{
70948 + __u32 i;
70949 +
70950 + if (polstate->subj_map_set.s_hash) {
70951 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
70952 + if (polstate->subj_map_set.s_hash[i]) {
70953 + kfree(polstate->subj_map_set.s_hash[i]);
70954 + polstate->subj_map_set.s_hash[i] = NULL;
70955 + }
70956 + }
70957 +
70958 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
70959 + PAGE_SIZE)
70960 + kfree(polstate->subj_map_set.s_hash);
70961 + else
70962 + vfree(polstate->subj_map_set.s_hash);
70963 + }
70964 +
70965 + return;
70966 +}
70967 +
70968 +static void
70969 +free_variables(bool reload)
70970 +{
70971 + struct acl_subject_label *s;
70972 + struct acl_role_label *r;
70973 + struct task_struct *task, *task2;
70974 + unsigned int x;
70975 +
70976 + if (!reload) {
70977 + gr_clear_learn_entries();
70978 +
70979 + read_lock(&tasklist_lock);
70980 + do_each_thread(task2, task) {
70981 + task->acl_sp_role = 0;
70982 + task->acl_role_id = 0;
70983 + task->inherited = 0;
70984 + task->acl = NULL;
70985 + task->role = NULL;
70986 + } while_each_thread(task2, task);
70987 + read_unlock(&tasklist_lock);
70988 +
70989 + kfree(fakefs_obj_rw);
70990 + fakefs_obj_rw = NULL;
70991 + kfree(fakefs_obj_rwx);
70992 + fakefs_obj_rwx = NULL;
70993 +
70994 + /* release the reference to the real root dentry and vfsmount */
70995 + path_put(&gr_real_root);
70996 + memset(&gr_real_root, 0, sizeof(gr_real_root));
70997 + }
70998 +
70999 + /* free all object hash tables */
71000 +
71001 + FOR_EACH_ROLE_START(r)
71002 + if (r->subj_hash == NULL)
71003 + goto next_role;
71004 + FOR_EACH_SUBJECT_START(r, s, x)
71005 + if (s->obj_hash == NULL)
71006 + break;
71007 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71008 + kfree(s->obj_hash);
71009 + else
71010 + vfree(s->obj_hash);
71011 + FOR_EACH_SUBJECT_END(s, x)
71012 + FOR_EACH_NESTED_SUBJECT_START(r, s)
71013 + if (s->obj_hash == NULL)
71014 + break;
71015 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71016 + kfree(s->obj_hash);
71017 + else
71018 + vfree(s->obj_hash);
71019 + FOR_EACH_NESTED_SUBJECT_END(s)
71020 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71021 + kfree(r->subj_hash);
71022 + else
71023 + vfree(r->subj_hash);
71024 + r->subj_hash = NULL;
71025 +next_role:
71026 + FOR_EACH_ROLE_END(r)
71027 +
71028 + acl_free_all();
71029 +
71030 + if (polstate->acl_role_set.r_hash) {
71031 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71032 + PAGE_SIZE)
71033 + kfree(polstate->acl_role_set.r_hash);
71034 + else
71035 + vfree(polstate->acl_role_set.r_hash);
71036 + }
71037 + if (polstate->name_set.n_hash) {
71038 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71039 + PAGE_SIZE)
71040 + kfree(polstate->name_set.n_hash);
71041 + else
71042 + vfree(polstate->name_set.n_hash);
71043 + }
71044 +
71045 + if (polstate->inodev_set.i_hash) {
71046 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71047 + PAGE_SIZE)
71048 + kfree(polstate->inodev_set.i_hash);
71049 + else
71050 + vfree(polstate->inodev_set.i_hash);
71051 + }
71052 +
71053 + if (!reload)
71054 + gr_free_uidset();
71055 +
71056 + memset(&polstate->name_set, 0, sizeof (struct name_db));
71057 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71058 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71059 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71060 +
71061 + polstate->default_role = NULL;
71062 + polstate->kernel_role = NULL;
71063 + polstate->role_list = NULL;
71064 +
71065 + return;
71066 +}
71067 +
71068 +static struct acl_subject_label *
71069 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71070 +
71071 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
71072 +{
71073 + unsigned int len = strnlen_user(*name, maxlen);
71074 + char *tmp;
71075 +
71076 + if (!len || len >= maxlen)
71077 + return -EINVAL;
71078 +
71079 + if ((tmp = (char *) acl_alloc(len)) == NULL)
71080 + return -ENOMEM;
71081 +
71082 + if (copy_from_user(tmp, *name, len))
71083 + return -EFAULT;
71084 +
71085 + tmp[len-1] = '\0';
71086 + *name = tmp;
71087 +
71088 + return 0;
71089 +}
71090 +
71091 +static int
71092 +copy_user_glob(struct acl_object_label *obj)
71093 +{
71094 + struct acl_object_label *g_tmp, **guser;
71095 + int error;
71096 +
71097 + if (obj->globbed == NULL)
71098 + return 0;
71099 +
71100 + guser = &obj->globbed;
71101 + while (*guser) {
71102 + g_tmp = (struct acl_object_label *)
71103 + acl_alloc(sizeof (struct acl_object_label));
71104 + if (g_tmp == NULL)
71105 + return -ENOMEM;
71106 +
71107 + if (copy_acl_object_label(g_tmp, *guser))
71108 + return -EFAULT;
71109 +
71110 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71111 + if (error)
71112 + return error;
71113 +
71114 + *guser = g_tmp;
71115 + guser = &(g_tmp->next);
71116 + }
71117 +
71118 + return 0;
71119 +}
71120 +
71121 +static int
71122 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71123 + struct acl_role_label *role)
71124 +{
71125 + struct acl_object_label *o_tmp;
71126 + int ret;
71127 +
71128 + while (userp) {
71129 + if ((o_tmp = (struct acl_object_label *)
71130 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
71131 + return -ENOMEM;
71132 +
71133 + if (copy_acl_object_label(o_tmp, userp))
71134 + return -EFAULT;
71135 +
71136 + userp = o_tmp->prev;
71137 +
71138 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71139 + if (ret)
71140 + return ret;
71141 +
71142 + insert_acl_obj_label(o_tmp, subj);
71143 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71144 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71145 + return -ENOMEM;
71146 +
71147 + ret = copy_user_glob(o_tmp);
71148 + if (ret)
71149 + return ret;
71150 +
71151 + if (o_tmp->nested) {
71152 + int already_copied;
71153 +
71154 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71155 + if (IS_ERR(o_tmp->nested))
71156 + return PTR_ERR(o_tmp->nested);
71157 +
71158 + /* insert into nested subject list if we haven't copied this one yet
71159 + to prevent duplicate entries */
71160 + if (!already_copied) {
71161 + o_tmp->nested->next = role->hash->first;
71162 + role->hash->first = o_tmp->nested;
71163 + }
71164 + }
71165 + }
71166 +
71167 + return 0;
71168 +}
71169 +
71170 +static __u32
71171 +count_user_subjs(struct acl_subject_label *userp)
71172 +{
71173 + struct acl_subject_label s_tmp;
71174 + __u32 num = 0;
71175 +
71176 + while (userp) {
71177 + if (copy_acl_subject_label(&s_tmp, userp))
71178 + break;
71179 +
71180 + userp = s_tmp.prev;
71181 + }
71182 +
71183 + return num;
71184 +}
71185 +
71186 +static int
71187 +copy_user_allowedips(struct acl_role_label *rolep)
71188 +{
71189 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71190 +
71191 + ruserip = rolep->allowed_ips;
71192 +
71193 + while (ruserip) {
71194 + rlast = rtmp;
71195 +
71196 + if ((rtmp = (struct role_allowed_ip *)
71197 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71198 + return -ENOMEM;
71199 +
71200 + if (copy_role_allowed_ip(rtmp, ruserip))
71201 + return -EFAULT;
71202 +
71203 + ruserip = rtmp->prev;
71204 +
71205 + if (!rlast) {
71206 + rtmp->prev = NULL;
71207 + rolep->allowed_ips = rtmp;
71208 + } else {
71209 + rlast->next = rtmp;
71210 + rtmp->prev = rlast;
71211 + }
71212 +
71213 + if (!ruserip)
71214 + rtmp->next = NULL;
71215 + }
71216 +
71217 + return 0;
71218 +}
71219 +
71220 +static int
71221 +copy_user_transitions(struct acl_role_label *rolep)
71222 +{
71223 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
71224 + int error;
71225 +
71226 + rusertp = rolep->transitions;
71227 +
71228 + while (rusertp) {
71229 + rlast = rtmp;
71230 +
71231 + if ((rtmp = (struct role_transition *)
71232 + acl_alloc(sizeof (struct role_transition))) == NULL)
71233 + return -ENOMEM;
71234 +
71235 + if (copy_role_transition(rtmp, rusertp))
71236 + return -EFAULT;
71237 +
71238 + rusertp = rtmp->prev;
71239 +
71240 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71241 + if (error)
71242 + return error;
71243 +
71244 + if (!rlast) {
71245 + rtmp->prev = NULL;
71246 + rolep->transitions = rtmp;
71247 + } else {
71248 + rlast->next = rtmp;
71249 + rtmp->prev = rlast;
71250 + }
71251 +
71252 + if (!rusertp)
71253 + rtmp->next = NULL;
71254 + }
71255 +
71256 + return 0;
71257 +}
71258 +
71259 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
71260 +{
71261 + struct acl_object_label o_tmp;
71262 + __u32 num = 0;
71263 +
71264 + while (userp) {
71265 + if (copy_acl_object_label(&o_tmp, userp))
71266 + break;
71267 +
71268 + userp = o_tmp.prev;
71269 + num++;
71270 + }
71271 +
71272 + return num;
71273 +}
71274 +
71275 +static struct acl_subject_label *
71276 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71277 +{
71278 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71279 + __u32 num_objs;
71280 + struct acl_ip_label **i_tmp, *i_utmp2;
71281 + struct gr_hash_struct ghash;
71282 + struct subject_map *subjmap;
71283 + unsigned int i_num;
71284 + int err;
71285 +
71286 + if (already_copied != NULL)
71287 + *already_copied = 0;
71288 +
71289 + s_tmp = lookup_subject_map(userp);
71290 +
71291 + /* we've already copied this subject into the kernel, just return
71292 + the reference to it, and don't copy it over again
71293 + */
71294 + if (s_tmp) {
71295 + if (already_copied != NULL)
71296 + *already_copied = 1;
71297 + return(s_tmp);
71298 + }
71299 +
71300 + if ((s_tmp = (struct acl_subject_label *)
71301 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71302 + return ERR_PTR(-ENOMEM);
71303 +
71304 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71305 + if (subjmap == NULL)
71306 + return ERR_PTR(-ENOMEM);
71307 +
71308 + subjmap->user = userp;
71309 + subjmap->kernel = s_tmp;
71310 + insert_subj_map_entry(subjmap);
71311 +
71312 + if (copy_acl_subject_label(s_tmp, userp))
71313 + return ERR_PTR(-EFAULT);
71314 +
71315 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71316 + if (err)
71317 + return ERR_PTR(err);
71318 +
71319 + if (!strcmp(s_tmp->filename, "/"))
71320 + role->root_label = s_tmp;
71321 +
71322 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71323 + return ERR_PTR(-EFAULT);
71324 +
71325 + /* copy user and group transition tables */
71326 +
71327 + if (s_tmp->user_trans_num) {
71328 + uid_t *uidlist;
71329 +
71330 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71331 + if (uidlist == NULL)
71332 + return ERR_PTR(-ENOMEM);
71333 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71334 + return ERR_PTR(-EFAULT);
71335 +
71336 + s_tmp->user_transitions = uidlist;
71337 + }
71338 +
71339 + if (s_tmp->group_trans_num) {
71340 + gid_t *gidlist;
71341 +
71342 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71343 + if (gidlist == NULL)
71344 + return ERR_PTR(-ENOMEM);
71345 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71346 + return ERR_PTR(-EFAULT);
71347 +
71348 + s_tmp->group_transitions = gidlist;
71349 + }
71350 +
71351 + /* set up object hash table */
71352 + num_objs = count_user_objs(ghash.first);
71353 +
71354 + s_tmp->obj_hash_size = num_objs;
71355 + s_tmp->obj_hash =
71356 + (struct acl_object_label **)
71357 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71358 +
71359 + if (!s_tmp->obj_hash)
71360 + return ERR_PTR(-ENOMEM);
71361 +
71362 + memset(s_tmp->obj_hash, 0,
71363 + s_tmp->obj_hash_size *
71364 + sizeof (struct acl_object_label *));
71365 +
71366 + /* add in objects */
71367 + err = copy_user_objs(ghash.first, s_tmp, role);
71368 +
71369 + if (err)
71370 + return ERR_PTR(err);
71371 +
71372 + /* set pointer for parent subject */
71373 + if (s_tmp->parent_subject) {
71374 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71375 +
71376 + if (IS_ERR(s_tmp2))
71377 + return s_tmp2;
71378 +
71379 + s_tmp->parent_subject = s_tmp2;
71380 + }
71381 +
71382 + /* add in ip acls */
71383 +
71384 + if (!s_tmp->ip_num) {
71385 + s_tmp->ips = NULL;
71386 + goto insert;
71387 + }
71388 +
71389 + i_tmp =
71390 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71391 + sizeof (struct acl_ip_label *));
71392 +
71393 + if (!i_tmp)
71394 + return ERR_PTR(-ENOMEM);
71395 +
71396 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71397 + *(i_tmp + i_num) =
71398 + (struct acl_ip_label *)
71399 + acl_alloc(sizeof (struct acl_ip_label));
71400 + if (!*(i_tmp + i_num))
71401 + return ERR_PTR(-ENOMEM);
71402 +
71403 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71404 + return ERR_PTR(-EFAULT);
71405 +
71406 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71407 + return ERR_PTR(-EFAULT);
71408 +
71409 + if ((*(i_tmp + i_num))->iface == NULL)
71410 + continue;
71411 +
71412 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71413 + if (err)
71414 + return ERR_PTR(err);
71415 + }
71416 +
71417 + s_tmp->ips = i_tmp;
71418 +
71419 +insert:
71420 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71421 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71422 + return ERR_PTR(-ENOMEM);
71423 +
71424 + return s_tmp;
71425 +}
71426 +
71427 +static int
71428 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71429 +{
71430 + struct acl_subject_label s_pre;
71431 + struct acl_subject_label * ret;
71432 + int err;
71433 +
71434 + while (userp) {
71435 + if (copy_acl_subject_label(&s_pre, userp))
71436 + return -EFAULT;
71437 +
71438 + ret = do_copy_user_subj(userp, role, NULL);
71439 +
71440 + err = PTR_ERR(ret);
71441 + if (IS_ERR(ret))
71442 + return err;
71443 +
71444 + insert_acl_subj_label(ret, role);
71445 +
71446 + userp = s_pre.prev;
71447 + }
71448 +
71449 + return 0;
71450 +}
71451 +
71452 +static int
71453 +copy_user_acl(struct gr_arg *arg)
71454 +{
71455 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71456 + struct acl_subject_label *subj_list;
71457 + struct sprole_pw *sptmp;
71458 + struct gr_hash_struct *ghash;
71459 + uid_t *domainlist;
71460 + unsigned int r_num;
71461 + int err = 0;
71462 + __u16 i;
71463 + __u32 num_subjs;
71464 +
71465 + /* we need a default and kernel role */
71466 + if (arg->role_db.num_roles < 2)
71467 + return -EINVAL;
71468 +
71469 + /* copy special role authentication info from userspace */
71470 +
71471 + polstate->num_sprole_pws = arg->num_sprole_pws;
71472 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
71473 +
71474 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
71475 + return -ENOMEM;
71476 +
71477 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71478 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
71479 + if (!sptmp)
71480 + return -ENOMEM;
71481 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
71482 + return -EFAULT;
71483 +
71484 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
71485 + if (err)
71486 + return err;
71487 +
71488 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71489 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
71490 +#endif
71491 +
71492 + polstate->acl_special_roles[i] = sptmp;
71493 + }
71494 +
71495 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
71496 +
71497 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
71498 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
71499 +
71500 + if (!r_tmp)
71501 + return -ENOMEM;
71502 +
71503 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
71504 + return -EFAULT;
71505 +
71506 + if (copy_acl_role_label(r_tmp, r_utmp2))
71507 + return -EFAULT;
71508 +
71509 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
71510 + if (err)
71511 + return err;
71512 +
71513 + if (!strcmp(r_tmp->rolename, "default")
71514 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
71515 + polstate->default_role = r_tmp;
71516 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
71517 + polstate->kernel_role = r_tmp;
71518 + }
71519 +
71520 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
71521 + return -ENOMEM;
71522 +
71523 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
71524 + return -EFAULT;
71525 +
71526 + r_tmp->hash = ghash;
71527 +
71528 + num_subjs = count_user_subjs(r_tmp->hash->first);
71529 +
71530 + r_tmp->subj_hash_size = num_subjs;
71531 + r_tmp->subj_hash =
71532 + (struct acl_subject_label **)
71533 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
71534 +
71535 + if (!r_tmp->subj_hash)
71536 + return -ENOMEM;
71537 +
71538 + err = copy_user_allowedips(r_tmp);
71539 + if (err)
71540 + return err;
71541 +
71542 + /* copy domain info */
71543 + if (r_tmp->domain_children != NULL) {
71544 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
71545 + if (domainlist == NULL)
71546 + return -ENOMEM;
71547 +
71548 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
71549 + return -EFAULT;
71550 +
71551 + r_tmp->domain_children = domainlist;
71552 + }
71553 +
71554 + err = copy_user_transitions(r_tmp);
71555 + if (err)
71556 + return err;
71557 +
71558 + memset(r_tmp->subj_hash, 0,
71559 + r_tmp->subj_hash_size *
71560 + sizeof (struct acl_subject_label *));
71561 +
71562 + /* acquire the list of subjects, then NULL out
71563 + the list prior to parsing the subjects for this role,
71564 + as during this parsing the list is replaced with a list
71565 + of *nested* subjects for the role
71566 + */
71567 + subj_list = r_tmp->hash->first;
71568 +
71569 + /* set nested subject list to null */
71570 + r_tmp->hash->first = NULL;
71571 +
71572 + err = copy_user_subjs(subj_list, r_tmp);
71573 +
71574 + if (err)
71575 + return err;
71576 +
71577 + insert_acl_role_label(r_tmp);
71578 + }
71579 +
71580 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
71581 + return -EINVAL;
71582 +
71583 + return err;
71584 +}
71585 +
71586 +static int gracl_reload_apply_policies(void *reload)
71587 +{
71588 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
71589 + struct task_struct *task, *task2;
71590 + struct acl_role_label *role, *rtmp;
71591 + struct acl_subject_label *subj;
71592 + const struct cred *cred;
71593 + int role_applied;
71594 + int ret = 0;
71595 +
71596 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
71597 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
71598 +
71599 + /* first make sure we'll be able to apply the new policy cleanly */
71600 + do_each_thread(task2, task) {
71601 + if (task->exec_file == NULL)
71602 + continue;
71603 + role_applied = 0;
71604 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71605 + /* preserve special roles */
71606 + FOR_EACH_ROLE_START(role)
71607 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71608 + rtmp = task->role;
71609 + task->role = role;
71610 + role_applied = 1;
71611 + break;
71612 + }
71613 + FOR_EACH_ROLE_END(role)
71614 + }
71615 + if (!role_applied) {
71616 + cred = __task_cred(task);
71617 + rtmp = task->role;
71618 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71619 + }
71620 + /* this handles non-nested inherited subjects, nested subjects will still
71621 + be dropped currently */
71622 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71623 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
71624 + /* change the role back so that we've made no modifications to the policy */
71625 + task->role = rtmp;
71626 +
71627 + if (subj == NULL || task->tmpacl == NULL) {
71628 + ret = -EINVAL;
71629 + goto out;
71630 + }
71631 + } while_each_thread(task2, task);
71632 +
71633 + /* now actually apply the policy */
71634 +
71635 + do_each_thread(task2, task) {
71636 + if (task->exec_file) {
71637 + role_applied = 0;
71638 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71639 + /* preserve special roles */
71640 + FOR_EACH_ROLE_START(role)
71641 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71642 + task->role = role;
71643 + role_applied = 1;
71644 + break;
71645 + }
71646 + FOR_EACH_ROLE_END(role)
71647 + }
71648 + if (!role_applied) {
71649 + cred = __task_cred(task);
71650 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71651 + }
71652 + /* this handles non-nested inherited subjects, nested subjects will still
71653 + be dropped currently */
71654 + if (!reload_state->oldmode && task->inherited)
71655 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71656 + else {
71657 + /* looked up and tagged to the task previously */
71658 + subj = task->tmpacl;
71659 + }
71660 + /* subj will be non-null */
71661 + __gr_apply_subject_to_task(polstate, task, subj);
71662 + if (reload_state->oldmode) {
71663 + task->acl_role_id = 0;
71664 + task->acl_sp_role = 0;
71665 + task->inherited = 0;
71666 + }
71667 + } else {
71668 + // it's a kernel process
71669 + task->role = polstate->kernel_role;
71670 + task->acl = polstate->kernel_role->root_label;
71671 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71672 + task->acl->mode &= ~GR_PROCFIND;
71673 +#endif
71674 + }
71675 + } while_each_thread(task2, task);
71676 +
71677 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
71678 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
71679 +
71680 +out:
71681 +
71682 + return ret;
71683 +}
71684 +
71685 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
71686 +{
71687 + struct gr_reload_state new_reload_state = { };
71688 + int err;
71689 +
71690 + new_reload_state.oldpolicy_ptr = polstate;
71691 + new_reload_state.oldalloc_ptr = current_alloc_state;
71692 + new_reload_state.oldmode = oldmode;
71693 +
71694 + current_alloc_state = &new_reload_state.newalloc;
71695 + polstate = &new_reload_state.newpolicy;
71696 +
71697 + /* everything relevant is now saved off, copy in the new policy */
71698 + if (init_variables(args, true)) {
71699 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71700 + err = -ENOMEM;
71701 + goto error;
71702 + }
71703 +
71704 + err = copy_user_acl(args);
71705 + free_init_variables();
71706 + if (err)
71707 + goto error;
71708 + /* the new policy is copied in, with the old policy available via saved_state
71709 + first go through applying roles, making sure to preserve special roles
71710 + then apply new subjects, making sure to preserve inherited and nested subjects,
71711 + though currently only inherited subjects will be preserved
71712 + */
71713 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
71714 + if (err)
71715 + goto error;
71716 +
71717 + /* we've now applied the new policy, so restore the old policy state to free it */
71718 + polstate = &new_reload_state.oldpolicy;
71719 + current_alloc_state = &new_reload_state.oldalloc;
71720 + free_variables(true);
71721 +
71722 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
71723 + to running_polstate/current_alloc_state inside stop_machine
71724 + */
71725 + err = 0;
71726 + goto out;
71727 +error:
71728 + /* on error of loading the new policy, we'll just keep the previous
71729 + policy set around
71730 + */
71731 + free_variables(true);
71732 +
71733 + /* doesn't affect runtime, but maintains consistent state */
71734 +out:
71735 + polstate = new_reload_state.oldpolicy_ptr;
71736 + current_alloc_state = new_reload_state.oldalloc_ptr;
71737 +
71738 + return err;
71739 +}
71740 +
71741 +static int
71742 +gracl_init(struct gr_arg *args)
71743 +{
71744 + int error = 0;
71745 +
71746 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
71747 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
71748 +
71749 + if (init_variables(args, false)) {
71750 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71751 + error = -ENOMEM;
71752 + goto out;
71753 + }
71754 +
71755 + error = copy_user_acl(args);
71756 + free_init_variables();
71757 + if (error)
71758 + goto out;
71759 +
71760 + error = gr_set_acls(0);
71761 + if (error)
71762 + goto out;
71763 +
71764 + gr_enable_rbac_system();
71765 +
71766 + return 0;
71767 +
71768 +out:
71769 + free_variables(false);
71770 + return error;
71771 +}
71772 +
71773 +static int
71774 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
71775 + unsigned char **sum)
71776 +{
71777 + struct acl_role_label *r;
71778 + struct role_allowed_ip *ipp;
71779 + struct role_transition *trans;
71780 + unsigned int i;
71781 + int found = 0;
71782 + u32 curr_ip = current->signal->curr_ip;
71783 +
71784 + current->signal->saved_ip = curr_ip;
71785 +
71786 + /* check transition table */
71787 +
71788 + for (trans = current->role->transitions; trans; trans = trans->next) {
71789 + if (!strcmp(rolename, trans->rolename)) {
71790 + found = 1;
71791 + break;
71792 + }
71793 + }
71794 +
71795 + if (!found)
71796 + return 0;
71797 +
71798 + /* handle special roles that do not require authentication
71799 + and check ip */
71800 +
71801 + FOR_EACH_ROLE_START(r)
71802 + if (!strcmp(rolename, r->rolename) &&
71803 + (r->roletype & GR_ROLE_SPECIAL)) {
71804 + found = 0;
71805 + if (r->allowed_ips != NULL) {
71806 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
71807 + if ((ntohl(curr_ip) & ipp->netmask) ==
71808 + (ntohl(ipp->addr) & ipp->netmask))
71809 + found = 1;
71810 + }
71811 + } else
71812 + found = 2;
71813 + if (!found)
71814 + return 0;
71815 +
71816 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
71817 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
71818 + *salt = NULL;
71819 + *sum = NULL;
71820 + return 1;
71821 + }
71822 + }
71823 + FOR_EACH_ROLE_END(r)
71824 +
71825 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71826 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
71827 + *salt = polstate->acl_special_roles[i]->salt;
71828 + *sum = polstate->acl_special_roles[i]->sum;
71829 + return 1;
71830 + }
71831 + }
71832 +
71833 + return 0;
71834 +}
71835 +
71836 +int gr_check_secure_terminal(struct task_struct *task)
71837 +{
71838 + struct task_struct *p, *p2, *p3;
71839 + struct files_struct *files;
71840 + struct fdtable *fdt;
71841 + struct file *our_file = NULL, *file;
71842 + int i;
71843 +
71844 + if (task->signal->tty == NULL)
71845 + return 1;
71846 +
71847 + files = get_files_struct(task);
71848 + if (files != NULL) {
71849 + rcu_read_lock();
71850 + fdt = files_fdtable(files);
71851 + for (i=0; i < fdt->max_fds; i++) {
71852 + file = fcheck_files(files, i);
71853 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
71854 + get_file(file);
71855 + our_file = file;
71856 + }
71857 + }
71858 + rcu_read_unlock();
71859 + put_files_struct(files);
71860 + }
71861 +
71862 + if (our_file == NULL)
71863 + return 1;
71864 +
71865 + read_lock(&tasklist_lock);
71866 + do_each_thread(p2, p) {
71867 + files = get_files_struct(p);
71868 + if (files == NULL ||
71869 + (p->signal && p->signal->tty == task->signal->tty)) {
71870 + if (files != NULL)
71871 + put_files_struct(files);
71872 + continue;
71873 + }
71874 + rcu_read_lock();
71875 + fdt = files_fdtable(files);
71876 + for (i=0; i < fdt->max_fds; i++) {
71877 + file = fcheck_files(files, i);
71878 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
71879 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
71880 + p3 = task;
71881 + while (task_pid_nr(p3) > 0) {
71882 + if (p3 == p)
71883 + break;
71884 + p3 = p3->real_parent;
71885 + }
71886 + if (p3 == p)
71887 + break;
71888 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
71889 + gr_handle_alertkill(p);
71890 + rcu_read_unlock();
71891 + put_files_struct(files);
71892 + read_unlock(&tasklist_lock);
71893 + fput(our_file);
71894 + return 0;
71895 + }
71896 + }
71897 + rcu_read_unlock();
71898 + put_files_struct(files);
71899 + } while_each_thread(p2, p);
71900 + read_unlock(&tasklist_lock);
71901 +
71902 + fput(our_file);
71903 + return 1;
71904 +}
71905 +
71906 +ssize_t
71907 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
71908 +{
71909 + struct gr_arg_wrapper uwrap;
71910 + unsigned char *sprole_salt = NULL;
71911 + unsigned char *sprole_sum = NULL;
71912 + int error = 0;
71913 + int error2 = 0;
71914 + size_t req_count = 0;
71915 + unsigned char oldmode = 0;
71916 +
71917 + mutex_lock(&gr_dev_mutex);
71918 +
71919 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
71920 + error = -EPERM;
71921 + goto out;
71922 + }
71923 +
71924 +#ifdef CONFIG_COMPAT
71925 + pax_open_kernel();
71926 + if (is_compat_task()) {
71927 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
71928 + copy_gr_arg = &copy_gr_arg_compat;
71929 + copy_acl_object_label = &copy_acl_object_label_compat;
71930 + copy_acl_subject_label = &copy_acl_subject_label_compat;
71931 + copy_acl_role_label = &copy_acl_role_label_compat;
71932 + copy_acl_ip_label = &copy_acl_ip_label_compat;
71933 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
71934 + copy_role_transition = &copy_role_transition_compat;
71935 + copy_sprole_pw = &copy_sprole_pw_compat;
71936 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
71937 + copy_pointer_from_array = &copy_pointer_from_array_compat;
71938 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
71939 + } else {
71940 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
71941 + copy_gr_arg = &copy_gr_arg_normal;
71942 + copy_acl_object_label = &copy_acl_object_label_normal;
71943 + copy_acl_subject_label = &copy_acl_subject_label_normal;
71944 + copy_acl_role_label = &copy_acl_role_label_normal;
71945 + copy_acl_ip_label = &copy_acl_ip_label_normal;
71946 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
71947 + copy_role_transition = &copy_role_transition_normal;
71948 + copy_sprole_pw = &copy_sprole_pw_normal;
71949 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
71950 + copy_pointer_from_array = &copy_pointer_from_array_normal;
71951 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
71952 + }
71953 + pax_close_kernel();
71954 +#endif
71955 +
71956 + req_count = get_gr_arg_wrapper_size();
71957 +
71958 + if (count != req_count) {
71959 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
71960 + error = -EINVAL;
71961 + goto out;
71962 + }
71963 +
71964 +
71965 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
71966 + gr_auth_expires = 0;
71967 + gr_auth_attempts = 0;
71968 + }
71969 +
71970 + error = copy_gr_arg_wrapper(buf, &uwrap);
71971 + if (error)
71972 + goto out;
71973 +
71974 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
71975 + if (error)
71976 + goto out;
71977 +
71978 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71979 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71980 + time_after(gr_auth_expires, get_seconds())) {
71981 + error = -EBUSY;
71982 + goto out;
71983 + }
71984 +
71985 + /* if non-root trying to do anything other than use a special role,
71986 + do not attempt authentication, do not count towards authentication
71987 + locking
71988 + */
71989 +
71990 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
71991 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71992 + gr_is_global_nonroot(current_uid())) {
71993 + error = -EPERM;
71994 + goto out;
71995 + }
71996 +
71997 + /* ensure pw and special role name are null terminated */
71998 +
71999 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72000 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72001 +
72002 + /* Okay.
72003 + * We have our enough of the argument structure..(we have yet
72004 + * to copy_from_user the tables themselves) . Copy the tables
72005 + * only if we need them, i.e. for loading operations. */
72006 +
72007 + switch (gr_usermode.mode) {
72008 + case GR_STATUS:
72009 + if (gr_acl_is_enabled()) {
72010 + error = 1;
72011 + if (!gr_check_secure_terminal(current))
72012 + error = 3;
72013 + } else
72014 + error = 2;
72015 + goto out;
72016 + case GR_SHUTDOWN:
72017 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72018 + stop_machine(gr_rbac_disable, NULL, NULL);
72019 + free_variables(false);
72020 + memset(&gr_usermode, 0, sizeof(gr_usermode));
72021 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72022 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72023 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72024 + } else if (gr_acl_is_enabled()) {
72025 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72026 + error = -EPERM;
72027 + } else {
72028 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72029 + error = -EAGAIN;
72030 + }
72031 + break;
72032 + case GR_ENABLE:
72033 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72034 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72035 + else {
72036 + if (gr_acl_is_enabled())
72037 + error = -EAGAIN;
72038 + else
72039 + error = error2;
72040 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72041 + }
72042 + break;
72043 + case GR_OLDRELOAD:
72044 + oldmode = 1;
72045 + case GR_RELOAD:
72046 + if (!gr_acl_is_enabled()) {
72047 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72048 + error = -EAGAIN;
72049 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72050 + error2 = gracl_reload(&gr_usermode, oldmode);
72051 + if (!error2)
72052 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72053 + else {
72054 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72055 + error = error2;
72056 + }
72057 + } else {
72058 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72059 + error = -EPERM;
72060 + }
72061 + break;
72062 + case GR_SEGVMOD:
72063 + if (unlikely(!gr_acl_is_enabled())) {
72064 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72065 + error = -EAGAIN;
72066 + break;
72067 + }
72068 +
72069 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72070 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72071 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72072 + struct acl_subject_label *segvacl;
72073 + segvacl =
72074 + lookup_acl_subj_label(gr_usermode.segv_inode,
72075 + gr_usermode.segv_device,
72076 + current->role);
72077 + if (segvacl) {
72078 + segvacl->crashes = 0;
72079 + segvacl->expires = 0;
72080 + }
72081 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72082 + gr_remove_uid(gr_usermode.segv_uid);
72083 + }
72084 + } else {
72085 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72086 + error = -EPERM;
72087 + }
72088 + break;
72089 + case GR_SPROLE:
72090 + case GR_SPROLEPAM:
72091 + if (unlikely(!gr_acl_is_enabled())) {
72092 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72093 + error = -EAGAIN;
72094 + break;
72095 + }
72096 +
72097 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72098 + current->role->expires = 0;
72099 + current->role->auth_attempts = 0;
72100 + }
72101 +
72102 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72103 + time_after(current->role->expires, get_seconds())) {
72104 + error = -EBUSY;
72105 + goto out;
72106 + }
72107 +
72108 + if (lookup_special_role_auth
72109 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72110 + && ((!sprole_salt && !sprole_sum)
72111 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72112 + char *p = "";
72113 + assign_special_role(gr_usermode.sp_role);
72114 + read_lock(&tasklist_lock);
72115 + if (current->real_parent)
72116 + p = current->real_parent->role->rolename;
72117 + read_unlock(&tasklist_lock);
72118 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72119 + p, acl_sp_role_value);
72120 + } else {
72121 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72122 + error = -EPERM;
72123 + if(!(current->role->auth_attempts++))
72124 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72125 +
72126 + goto out;
72127 + }
72128 + break;
72129 + case GR_UNSPROLE:
72130 + if (unlikely(!gr_acl_is_enabled())) {
72131 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72132 + error = -EAGAIN;
72133 + break;
72134 + }
72135 +
72136 + if (current->role->roletype & GR_ROLE_SPECIAL) {
72137 + char *p = "";
72138 + int i = 0;
72139 +
72140 + read_lock(&tasklist_lock);
72141 + if (current->real_parent) {
72142 + p = current->real_parent->role->rolename;
72143 + i = current->real_parent->acl_role_id;
72144 + }
72145 + read_unlock(&tasklist_lock);
72146 +
72147 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72148 + gr_set_acls(1);
72149 + } else {
72150 + error = -EPERM;
72151 + goto out;
72152 + }
72153 + break;
72154 + default:
72155 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72156 + error = -EINVAL;
72157 + break;
72158 + }
72159 +
72160 + if (error != -EPERM)
72161 + goto out;
72162 +
72163 + if(!(gr_auth_attempts++))
72164 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72165 +
72166 + out:
72167 + mutex_unlock(&gr_dev_mutex);
72168 +
72169 + if (!error)
72170 + error = req_count;
72171 +
72172 + return error;
72173 +}
72174 +
72175 +int
72176 +gr_set_acls(const int type)
72177 +{
72178 + struct task_struct *task, *task2;
72179 + struct acl_role_label *role = current->role;
72180 + struct acl_subject_label *subj;
72181 + __u16 acl_role_id = current->acl_role_id;
72182 + const struct cred *cred;
72183 + int ret;
72184 +
72185 + rcu_read_lock();
72186 + read_lock(&tasklist_lock);
72187 + read_lock(&grsec_exec_file_lock);
72188 + do_each_thread(task2, task) {
72189 + /* check to see if we're called from the exit handler,
72190 + if so, only replace ACLs that have inherited the admin
72191 + ACL */
72192 +
72193 + if (type && (task->role != role ||
72194 + task->acl_role_id != acl_role_id))
72195 + continue;
72196 +
72197 + task->acl_role_id = 0;
72198 + task->acl_sp_role = 0;
72199 + task->inherited = 0;
72200 +
72201 + if (task->exec_file) {
72202 + cred = __task_cred(task);
72203 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72204 + subj = __gr_get_subject_for_task(polstate, task, NULL);
72205 + if (subj == NULL) {
72206 + ret = -EINVAL;
72207 + read_unlock(&grsec_exec_file_lock);
72208 + read_unlock(&tasklist_lock);
72209 + rcu_read_unlock();
72210 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72211 + return ret;
72212 + }
72213 + __gr_apply_subject_to_task(polstate, task, subj);
72214 + } else {
72215 + // it's a kernel process
72216 + task->role = polstate->kernel_role;
72217 + task->acl = polstate->kernel_role->root_label;
72218 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72219 + task->acl->mode &= ~GR_PROCFIND;
72220 +#endif
72221 + }
72222 + } while_each_thread(task2, task);
72223 + read_unlock(&grsec_exec_file_lock);
72224 + read_unlock(&tasklist_lock);
72225 + rcu_read_unlock();
72226 +
72227 + return 0;
72228 +}
72229 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72230 new file mode 100644
72231 index 0000000..39645c9
72232 --- /dev/null
72233 +++ b/grsecurity/gracl_res.c
72234 @@ -0,0 +1,68 @@
72235 +#include <linux/kernel.h>
72236 +#include <linux/sched.h>
72237 +#include <linux/gracl.h>
72238 +#include <linux/grinternal.h>
72239 +
72240 +static const char *restab_log[] = {
72241 + [RLIMIT_CPU] = "RLIMIT_CPU",
72242 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72243 + [RLIMIT_DATA] = "RLIMIT_DATA",
72244 + [RLIMIT_STACK] = "RLIMIT_STACK",
72245 + [RLIMIT_CORE] = "RLIMIT_CORE",
72246 + [RLIMIT_RSS] = "RLIMIT_RSS",
72247 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
72248 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72249 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72250 + [RLIMIT_AS] = "RLIMIT_AS",
72251 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72252 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72253 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72254 + [RLIMIT_NICE] = "RLIMIT_NICE",
72255 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72256 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72257 + [GR_CRASH_RES] = "RLIMIT_CRASH"
72258 +};
72259 +
72260 +void
72261 +gr_log_resource(const struct task_struct *task,
72262 + const int res, const unsigned long wanted, const int gt)
72263 +{
72264 + const struct cred *cred;
72265 + unsigned long rlim;
72266 +
72267 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
72268 + return;
72269 +
72270 + // not yet supported resource
72271 + if (unlikely(!restab_log[res]))
72272 + return;
72273 +
72274 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72275 + rlim = task_rlimit_max(task, res);
72276 + else
72277 + rlim = task_rlimit(task, res);
72278 +
72279 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72280 + return;
72281 +
72282 + rcu_read_lock();
72283 + cred = __task_cred(task);
72284 +
72285 + if (res == RLIMIT_NPROC &&
72286 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72287 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72288 + goto out_rcu_unlock;
72289 + else if (res == RLIMIT_MEMLOCK &&
72290 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72291 + goto out_rcu_unlock;
72292 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72293 + goto out_rcu_unlock;
72294 + rcu_read_unlock();
72295 +
72296 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72297 +
72298 + return;
72299 +out_rcu_unlock:
72300 + rcu_read_unlock();
72301 + return;
72302 +}
72303 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72304 new file mode 100644
72305 index 0000000..2040e61
72306 --- /dev/null
72307 +++ b/grsecurity/gracl_segv.c
72308 @@ -0,0 +1,313 @@
72309 +#include <linux/kernel.h>
72310 +#include <linux/mm.h>
72311 +#include <asm/uaccess.h>
72312 +#include <asm/errno.h>
72313 +#include <asm/mman.h>
72314 +#include <net/sock.h>
72315 +#include <linux/file.h>
72316 +#include <linux/fs.h>
72317 +#include <linux/net.h>
72318 +#include <linux/in.h>
72319 +#include <linux/slab.h>
72320 +#include <linux/types.h>
72321 +#include <linux/sched.h>
72322 +#include <linux/timer.h>
72323 +#include <linux/gracl.h>
72324 +#include <linux/grsecurity.h>
72325 +#include <linux/grinternal.h>
72326 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72327 +#include <linux/magic.h>
72328 +#include <linux/pagemap.h>
72329 +#include "../fs/btrfs/async-thread.h"
72330 +#include "../fs/btrfs/ctree.h"
72331 +#include "../fs/btrfs/btrfs_inode.h"
72332 +#endif
72333 +
72334 +static struct crash_uid *uid_set;
72335 +static unsigned short uid_used;
72336 +static DEFINE_SPINLOCK(gr_uid_lock);
72337 +extern rwlock_t gr_inode_lock;
72338 +extern struct acl_subject_label *
72339 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72340 + struct acl_role_label *role);
72341 +
72342 +static inline dev_t __get_dev(const struct dentry *dentry)
72343 +{
72344 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72345 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72346 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
72347 + else
72348 +#endif
72349 + return dentry->d_sb->s_dev;
72350 +}
72351 +
72352 +int
72353 +gr_init_uidset(void)
72354 +{
72355 + uid_set =
72356 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72357 + uid_used = 0;
72358 +
72359 + return uid_set ? 1 : 0;
72360 +}
72361 +
72362 +void
72363 +gr_free_uidset(void)
72364 +{
72365 + if (uid_set) {
72366 + struct crash_uid *tmpset;
72367 + spin_lock(&gr_uid_lock);
72368 + tmpset = uid_set;
72369 + uid_set = NULL;
72370 + uid_used = 0;
72371 + spin_unlock(&gr_uid_lock);
72372 + if (tmpset)
72373 + kfree(tmpset);
72374 + }
72375 +
72376 + return;
72377 +}
72378 +
72379 +int
72380 +gr_find_uid(const uid_t uid)
72381 +{
72382 + struct crash_uid *tmp = uid_set;
72383 + uid_t buid;
72384 + int low = 0, high = uid_used - 1, mid;
72385 +
72386 + while (high >= low) {
72387 + mid = (low + high) >> 1;
72388 + buid = tmp[mid].uid;
72389 + if (buid == uid)
72390 + return mid;
72391 + if (buid > uid)
72392 + high = mid - 1;
72393 + if (buid < uid)
72394 + low = mid + 1;
72395 + }
72396 +
72397 + return -1;
72398 +}
72399 +
72400 +static __inline__ void
72401 +gr_insertsort(void)
72402 +{
72403 + unsigned short i, j;
72404 + struct crash_uid index;
72405 +
72406 + for (i = 1; i < uid_used; i++) {
72407 + index = uid_set[i];
72408 + j = i;
72409 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72410 + uid_set[j] = uid_set[j - 1];
72411 + j--;
72412 + }
72413 + uid_set[j] = index;
72414 + }
72415 +
72416 + return;
72417 +}
72418 +
72419 +static __inline__ void
72420 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72421 +{
72422 + int loc;
72423 + uid_t uid = GR_GLOBAL_UID(kuid);
72424 +
72425 + if (uid_used == GR_UIDTABLE_MAX)
72426 + return;
72427 +
72428 + loc = gr_find_uid(uid);
72429 +
72430 + if (loc >= 0) {
72431 + uid_set[loc].expires = expires;
72432 + return;
72433 + }
72434 +
72435 + uid_set[uid_used].uid = uid;
72436 + uid_set[uid_used].expires = expires;
72437 + uid_used++;
72438 +
72439 + gr_insertsort();
72440 +
72441 + return;
72442 +}
72443 +
72444 +void
72445 +gr_remove_uid(const unsigned short loc)
72446 +{
72447 + unsigned short i;
72448 +
72449 + for (i = loc + 1; i < uid_used; i++)
72450 + uid_set[i - 1] = uid_set[i];
72451 +
72452 + uid_used--;
72453 +
72454 + return;
72455 +}
72456 +
72457 +int
72458 +gr_check_crash_uid(const kuid_t kuid)
72459 +{
72460 + int loc;
72461 + int ret = 0;
72462 + uid_t uid;
72463 +
72464 + if (unlikely(!gr_acl_is_enabled()))
72465 + return 0;
72466 +
72467 + uid = GR_GLOBAL_UID(kuid);
72468 +
72469 + spin_lock(&gr_uid_lock);
72470 + loc = gr_find_uid(uid);
72471 +
72472 + if (loc < 0)
72473 + goto out_unlock;
72474 +
72475 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
72476 + gr_remove_uid(loc);
72477 + else
72478 + ret = 1;
72479 +
72480 +out_unlock:
72481 + spin_unlock(&gr_uid_lock);
72482 + return ret;
72483 +}
72484 +
72485 +static __inline__ int
72486 +proc_is_setxid(const struct cred *cred)
72487 +{
72488 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
72489 + !uid_eq(cred->uid, cred->fsuid))
72490 + return 1;
72491 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
72492 + !gid_eq(cred->gid, cred->fsgid))
72493 + return 1;
72494 +
72495 + return 0;
72496 +}
72497 +
72498 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
72499 +
72500 +void
72501 +gr_handle_crash(struct task_struct *task, const int sig)
72502 +{
72503 + struct acl_subject_label *curr;
72504 + struct task_struct *tsk, *tsk2;
72505 + const struct cred *cred;
72506 + const struct cred *cred2;
72507 +
72508 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
72509 + return;
72510 +
72511 + if (unlikely(!gr_acl_is_enabled()))
72512 + return;
72513 +
72514 + curr = task->acl;
72515 +
72516 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
72517 + return;
72518 +
72519 + if (time_before_eq(curr->expires, get_seconds())) {
72520 + curr->expires = 0;
72521 + curr->crashes = 0;
72522 + }
72523 +
72524 + curr->crashes++;
72525 +
72526 + if (!curr->expires)
72527 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
72528 +
72529 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72530 + time_after(curr->expires, get_seconds())) {
72531 + rcu_read_lock();
72532 + cred = __task_cred(task);
72533 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
72534 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72535 + spin_lock(&gr_uid_lock);
72536 + gr_insert_uid(cred->uid, curr->expires);
72537 + spin_unlock(&gr_uid_lock);
72538 + curr->expires = 0;
72539 + curr->crashes = 0;
72540 + read_lock(&tasklist_lock);
72541 + do_each_thread(tsk2, tsk) {
72542 + cred2 = __task_cred(tsk);
72543 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
72544 + gr_fake_force_sig(SIGKILL, tsk);
72545 + } while_each_thread(tsk2, tsk);
72546 + read_unlock(&tasklist_lock);
72547 + } else {
72548 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72549 + read_lock(&tasklist_lock);
72550 + read_lock(&grsec_exec_file_lock);
72551 + do_each_thread(tsk2, tsk) {
72552 + if (likely(tsk != task)) {
72553 + // if this thread has the same subject as the one that triggered
72554 + // RES_CRASH and it's the same binary, kill it
72555 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
72556 + gr_fake_force_sig(SIGKILL, tsk);
72557 + }
72558 + } while_each_thread(tsk2, tsk);
72559 + read_unlock(&grsec_exec_file_lock);
72560 + read_unlock(&tasklist_lock);
72561 + }
72562 + rcu_read_unlock();
72563 + }
72564 +
72565 + return;
72566 +}
72567 +
72568 +int
72569 +gr_check_crash_exec(const struct file *filp)
72570 +{
72571 + struct acl_subject_label *curr;
72572 +
72573 + if (unlikely(!gr_acl_is_enabled()))
72574 + return 0;
72575 +
72576 + read_lock(&gr_inode_lock);
72577 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
72578 + __get_dev(filp->f_path.dentry),
72579 + current->role);
72580 + read_unlock(&gr_inode_lock);
72581 +
72582 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
72583 + (!curr->crashes && !curr->expires))
72584 + return 0;
72585 +
72586 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72587 + time_after(curr->expires, get_seconds()))
72588 + return 1;
72589 + else if (time_before_eq(curr->expires, get_seconds())) {
72590 + curr->crashes = 0;
72591 + curr->expires = 0;
72592 + }
72593 +
72594 + return 0;
72595 +}
72596 +
72597 +void
72598 +gr_handle_alertkill(struct task_struct *task)
72599 +{
72600 + struct acl_subject_label *curracl;
72601 + __u32 curr_ip;
72602 + struct task_struct *p, *p2;
72603 +
72604 + if (unlikely(!gr_acl_is_enabled()))
72605 + return;
72606 +
72607 + curracl = task->acl;
72608 + curr_ip = task->signal->curr_ip;
72609 +
72610 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
72611 + read_lock(&tasklist_lock);
72612 + do_each_thread(p2, p) {
72613 + if (p->signal->curr_ip == curr_ip)
72614 + gr_fake_force_sig(SIGKILL, p);
72615 + } while_each_thread(p2, p);
72616 + read_unlock(&tasklist_lock);
72617 + } else if (curracl->mode & GR_KILLPROC)
72618 + gr_fake_force_sig(SIGKILL, task);
72619 +
72620 + return;
72621 +}
72622 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
72623 new file mode 100644
72624 index 0000000..98011b0
72625 --- /dev/null
72626 +++ b/grsecurity/gracl_shm.c
72627 @@ -0,0 +1,40 @@
72628 +#include <linux/kernel.h>
72629 +#include <linux/mm.h>
72630 +#include <linux/sched.h>
72631 +#include <linux/file.h>
72632 +#include <linux/ipc.h>
72633 +#include <linux/gracl.h>
72634 +#include <linux/grsecurity.h>
72635 +#include <linux/grinternal.h>
72636 +
72637 +int
72638 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72639 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
72640 +{
72641 + struct task_struct *task;
72642 +
72643 + if (!gr_acl_is_enabled())
72644 + return 1;
72645 +
72646 + rcu_read_lock();
72647 + read_lock(&tasklist_lock);
72648 +
72649 + task = find_task_by_vpid(shm_cprid);
72650 +
72651 + if (unlikely(!task))
72652 + task = find_task_by_vpid(shm_lapid);
72653 +
72654 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
72655 + (task_pid_nr(task) == shm_lapid)) &&
72656 + (task->acl->mode & GR_PROTSHM) &&
72657 + (task->acl != current->acl))) {
72658 + read_unlock(&tasklist_lock);
72659 + rcu_read_unlock();
72660 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
72661 + return 0;
72662 + }
72663 + read_unlock(&tasklist_lock);
72664 + rcu_read_unlock();
72665 +
72666 + return 1;
72667 +}
72668 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
72669 new file mode 100644
72670 index 0000000..bc0be01
72671 --- /dev/null
72672 +++ b/grsecurity/grsec_chdir.c
72673 @@ -0,0 +1,19 @@
72674 +#include <linux/kernel.h>
72675 +#include <linux/sched.h>
72676 +#include <linux/fs.h>
72677 +#include <linux/file.h>
72678 +#include <linux/grsecurity.h>
72679 +#include <linux/grinternal.h>
72680 +
72681 +void
72682 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
72683 +{
72684 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72685 + if ((grsec_enable_chdir && grsec_enable_group &&
72686 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
72687 + !grsec_enable_group)) {
72688 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
72689 + }
72690 +#endif
72691 + return;
72692 +}
72693 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
72694 new file mode 100644
72695 index 0000000..651d6c2
72696 --- /dev/null
72697 +++ b/grsecurity/grsec_chroot.c
72698 @@ -0,0 +1,370 @@
72699 +#include <linux/kernel.h>
72700 +#include <linux/module.h>
72701 +#include <linux/sched.h>
72702 +#include <linux/file.h>
72703 +#include <linux/fs.h>
72704 +#include <linux/mount.h>
72705 +#include <linux/types.h>
72706 +#include "../fs/mount.h"
72707 +#include <linux/grsecurity.h>
72708 +#include <linux/grinternal.h>
72709 +
72710 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72711 +int gr_init_ran;
72712 +#endif
72713 +
72714 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
72715 +{
72716 +#ifdef CONFIG_GRKERNSEC
72717 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
72718 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
72719 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72720 + && gr_init_ran
72721 +#endif
72722 + )
72723 + task->gr_is_chrooted = 1;
72724 + else {
72725 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72726 + if (task_pid_nr(task) == 1 && !gr_init_ran)
72727 + gr_init_ran = 1;
72728 +#endif
72729 + task->gr_is_chrooted = 0;
72730 + }
72731 +
72732 + task->gr_chroot_dentry = path->dentry;
72733 +#endif
72734 + return;
72735 +}
72736 +
72737 +void gr_clear_chroot_entries(struct task_struct *task)
72738 +{
72739 +#ifdef CONFIG_GRKERNSEC
72740 + task->gr_is_chrooted = 0;
72741 + task->gr_chroot_dentry = NULL;
72742 +#endif
72743 + return;
72744 +}
72745 +
72746 +int
72747 +gr_handle_chroot_unix(const pid_t pid)
72748 +{
72749 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72750 + struct task_struct *p;
72751 +
72752 + if (unlikely(!grsec_enable_chroot_unix))
72753 + return 1;
72754 +
72755 + if (likely(!proc_is_chrooted(current)))
72756 + return 1;
72757 +
72758 + rcu_read_lock();
72759 + read_lock(&tasklist_lock);
72760 + p = find_task_by_vpid_unrestricted(pid);
72761 + if (unlikely(p && !have_same_root(current, p))) {
72762 + read_unlock(&tasklist_lock);
72763 + rcu_read_unlock();
72764 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
72765 + return 0;
72766 + }
72767 + read_unlock(&tasklist_lock);
72768 + rcu_read_unlock();
72769 +#endif
72770 + return 1;
72771 +}
72772 +
72773 +int
72774 +gr_handle_chroot_nice(void)
72775 +{
72776 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72777 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
72778 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
72779 + return -EPERM;
72780 + }
72781 +#endif
72782 + return 0;
72783 +}
72784 +
72785 +int
72786 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
72787 +{
72788 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72789 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
72790 + && proc_is_chrooted(current)) {
72791 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
72792 + return -EACCES;
72793 + }
72794 +#endif
72795 + return 0;
72796 +}
72797 +
72798 +int
72799 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
72800 +{
72801 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72802 + struct task_struct *p;
72803 + int ret = 0;
72804 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
72805 + return ret;
72806 +
72807 + read_lock(&tasklist_lock);
72808 + do_each_pid_task(pid, type, p) {
72809 + if (!have_same_root(current, p)) {
72810 + ret = 1;
72811 + goto out;
72812 + }
72813 + } while_each_pid_task(pid, type, p);
72814 +out:
72815 + read_unlock(&tasklist_lock);
72816 + return ret;
72817 +#endif
72818 + return 0;
72819 +}
72820 +
72821 +int
72822 +gr_pid_is_chrooted(struct task_struct *p)
72823 +{
72824 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72825 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
72826 + return 0;
72827 +
72828 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
72829 + !have_same_root(current, p)) {
72830 + return 1;
72831 + }
72832 +#endif
72833 + return 0;
72834 +}
72835 +
72836 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
72837 +
72838 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
72839 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
72840 +{
72841 + struct path path, currentroot;
72842 + int ret = 0;
72843 +
72844 + path.dentry = (struct dentry *)u_dentry;
72845 + path.mnt = (struct vfsmount *)u_mnt;
72846 + get_fs_root(current->fs, &currentroot);
72847 + if (path_is_under(&path, &currentroot))
72848 + ret = 1;
72849 + path_put(&currentroot);
72850 +
72851 + return ret;
72852 +}
72853 +#endif
72854 +
72855 +int
72856 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
72857 +{
72858 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72859 + if (!grsec_enable_chroot_fchdir)
72860 + return 1;
72861 +
72862 + if (!proc_is_chrooted(current))
72863 + return 1;
72864 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
72865 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
72866 + return 0;
72867 + }
72868 +#endif
72869 + return 1;
72870 +}
72871 +
72872 +int
72873 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72874 + const time_t shm_createtime)
72875 +{
72876 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72877 + struct task_struct *p;
72878 + time_t starttime;
72879 +
72880 + if (unlikely(!grsec_enable_chroot_shmat))
72881 + return 1;
72882 +
72883 + if (likely(!proc_is_chrooted(current)))
72884 + return 1;
72885 +
72886 + rcu_read_lock();
72887 + read_lock(&tasklist_lock);
72888 +
72889 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
72890 + starttime = p->start_time.tv_sec;
72891 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
72892 + if (have_same_root(current, p)) {
72893 + goto allow;
72894 + } else {
72895 + read_unlock(&tasklist_lock);
72896 + rcu_read_unlock();
72897 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72898 + return 0;
72899 + }
72900 + }
72901 + /* creator exited, pid reuse, fall through to next check */
72902 + }
72903 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
72904 + if (unlikely(!have_same_root(current, p))) {
72905 + read_unlock(&tasklist_lock);
72906 + rcu_read_unlock();
72907 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72908 + return 0;
72909 + }
72910 + }
72911 +
72912 +allow:
72913 + read_unlock(&tasklist_lock);
72914 + rcu_read_unlock();
72915 +#endif
72916 + return 1;
72917 +}
72918 +
72919 +void
72920 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
72921 +{
72922 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72923 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
72924 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
72925 +#endif
72926 + return;
72927 +}
72928 +
72929 +int
72930 +gr_handle_chroot_mknod(const struct dentry *dentry,
72931 + const struct vfsmount *mnt, const int mode)
72932 +{
72933 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72934 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
72935 + proc_is_chrooted(current)) {
72936 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
72937 + return -EPERM;
72938 + }
72939 +#endif
72940 + return 0;
72941 +}
72942 +
72943 +int
72944 +gr_handle_chroot_mount(const struct dentry *dentry,
72945 + const struct vfsmount *mnt, const char *dev_name)
72946 +{
72947 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72948 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
72949 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
72950 + return -EPERM;
72951 + }
72952 +#endif
72953 + return 0;
72954 +}
72955 +
72956 +int
72957 +gr_handle_chroot_pivot(void)
72958 +{
72959 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72960 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
72961 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
72962 + return -EPERM;
72963 + }
72964 +#endif
72965 + return 0;
72966 +}
72967 +
72968 +int
72969 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
72970 +{
72971 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72972 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
72973 + !gr_is_outside_chroot(dentry, mnt)) {
72974 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
72975 + return -EPERM;
72976 + }
72977 +#endif
72978 + return 0;
72979 +}
72980 +
72981 +extern const char *captab_log[];
72982 +extern int captab_log_entries;
72983 +
72984 +int
72985 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72986 +{
72987 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72988 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72989 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72990 + if (cap_raised(chroot_caps, cap)) {
72991 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
72992 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
72993 + }
72994 + return 0;
72995 + }
72996 + }
72997 +#endif
72998 + return 1;
72999 +}
73000 +
73001 +int
73002 +gr_chroot_is_capable(const int cap)
73003 +{
73004 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73005 + return gr_task_chroot_is_capable(current, current_cred(), cap);
73006 +#endif
73007 + return 1;
73008 +}
73009 +
73010 +int
73011 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73012 +{
73013 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73014 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73015 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73016 + if (cap_raised(chroot_caps, cap)) {
73017 + return 0;
73018 + }
73019 + }
73020 +#endif
73021 + return 1;
73022 +}
73023 +
73024 +int
73025 +gr_chroot_is_capable_nolog(const int cap)
73026 +{
73027 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73028 + return gr_task_chroot_is_capable_nolog(current, cap);
73029 +#endif
73030 + return 1;
73031 +}
73032 +
73033 +int
73034 +gr_handle_chroot_sysctl(const int op)
73035 +{
73036 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73037 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73038 + proc_is_chrooted(current))
73039 + return -EACCES;
73040 +#endif
73041 + return 0;
73042 +}
73043 +
73044 +void
73045 +gr_handle_chroot_chdir(const struct path *path)
73046 +{
73047 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73048 + if (grsec_enable_chroot_chdir)
73049 + set_fs_pwd(current->fs, path);
73050 +#endif
73051 + return;
73052 +}
73053 +
73054 +int
73055 +gr_handle_chroot_chmod(const struct dentry *dentry,
73056 + const struct vfsmount *mnt, const int mode)
73057 +{
73058 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73059 + /* allow chmod +s on directories, but not files */
73060 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73061 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73062 + proc_is_chrooted(current)) {
73063 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73064 + return -EPERM;
73065 + }
73066 +#endif
73067 + return 0;
73068 +}
73069 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73070 new file mode 100644
73071 index 0000000..4d6fce8
73072 --- /dev/null
73073 +++ b/grsecurity/grsec_disabled.c
73074 @@ -0,0 +1,433 @@
73075 +#include <linux/kernel.h>
73076 +#include <linux/module.h>
73077 +#include <linux/sched.h>
73078 +#include <linux/file.h>
73079 +#include <linux/fs.h>
73080 +#include <linux/kdev_t.h>
73081 +#include <linux/net.h>
73082 +#include <linux/in.h>
73083 +#include <linux/ip.h>
73084 +#include <linux/skbuff.h>
73085 +#include <linux/sysctl.h>
73086 +
73087 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73088 +void
73089 +pax_set_initial_flags(struct linux_binprm *bprm)
73090 +{
73091 + return;
73092 +}
73093 +#endif
73094 +
73095 +#ifdef CONFIG_SYSCTL
73096 +__u32
73097 +gr_handle_sysctl(const struct ctl_table * table, const int op)
73098 +{
73099 + return 0;
73100 +}
73101 +#endif
73102 +
73103 +#ifdef CONFIG_TASKSTATS
73104 +int gr_is_taskstats_denied(int pid)
73105 +{
73106 + return 0;
73107 +}
73108 +#endif
73109 +
73110 +int
73111 +gr_acl_is_enabled(void)
73112 +{
73113 + return 0;
73114 +}
73115 +
73116 +void
73117 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73118 +{
73119 + return;
73120 +}
73121 +
73122 +int
73123 +gr_handle_rawio(const struct inode *inode)
73124 +{
73125 + return 0;
73126 +}
73127 +
73128 +void
73129 +gr_acl_handle_psacct(struct task_struct *task, const long code)
73130 +{
73131 + return;
73132 +}
73133 +
73134 +int
73135 +gr_handle_ptrace(struct task_struct *task, const long request)
73136 +{
73137 + return 0;
73138 +}
73139 +
73140 +int
73141 +gr_handle_proc_ptrace(struct task_struct *task)
73142 +{
73143 + return 0;
73144 +}
73145 +
73146 +int
73147 +gr_set_acls(const int type)
73148 +{
73149 + return 0;
73150 +}
73151 +
73152 +int
73153 +gr_check_hidden_task(const struct task_struct *tsk)
73154 +{
73155 + return 0;
73156 +}
73157 +
73158 +int
73159 +gr_check_protected_task(const struct task_struct *task)
73160 +{
73161 + return 0;
73162 +}
73163 +
73164 +int
73165 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73166 +{
73167 + return 0;
73168 +}
73169 +
73170 +void
73171 +gr_copy_label(struct task_struct *tsk)
73172 +{
73173 + return;
73174 +}
73175 +
73176 +void
73177 +gr_set_pax_flags(struct task_struct *task)
73178 +{
73179 + return;
73180 +}
73181 +
73182 +int
73183 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73184 + const int unsafe_share)
73185 +{
73186 + return 0;
73187 +}
73188 +
73189 +void
73190 +gr_handle_delete(const ino_t ino, const dev_t dev)
73191 +{
73192 + return;
73193 +}
73194 +
73195 +void
73196 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73197 +{
73198 + return;
73199 +}
73200 +
73201 +void
73202 +gr_handle_crash(struct task_struct *task, const int sig)
73203 +{
73204 + return;
73205 +}
73206 +
73207 +int
73208 +gr_check_crash_exec(const struct file *filp)
73209 +{
73210 + return 0;
73211 +}
73212 +
73213 +int
73214 +gr_check_crash_uid(const kuid_t uid)
73215 +{
73216 + return 0;
73217 +}
73218 +
73219 +void
73220 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73221 + struct dentry *old_dentry,
73222 + struct dentry *new_dentry,
73223 + struct vfsmount *mnt, const __u8 replace)
73224 +{
73225 + return;
73226 +}
73227 +
73228 +int
73229 +gr_search_socket(const int family, const int type, const int protocol)
73230 +{
73231 + return 1;
73232 +}
73233 +
73234 +int
73235 +gr_search_connectbind(const int mode, const struct socket *sock,
73236 + const struct sockaddr_in *addr)
73237 +{
73238 + return 0;
73239 +}
73240 +
73241 +void
73242 +gr_handle_alertkill(struct task_struct *task)
73243 +{
73244 + return;
73245 +}
73246 +
73247 +__u32
73248 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73249 +{
73250 + return 1;
73251 +}
73252 +
73253 +__u32
73254 +gr_acl_handle_hidden_file(const struct dentry * dentry,
73255 + const struct vfsmount * mnt)
73256 +{
73257 + return 1;
73258 +}
73259 +
73260 +__u32
73261 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73262 + int acc_mode)
73263 +{
73264 + return 1;
73265 +}
73266 +
73267 +__u32
73268 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73269 +{
73270 + return 1;
73271 +}
73272 +
73273 +__u32
73274 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73275 +{
73276 + return 1;
73277 +}
73278 +
73279 +int
73280 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73281 + unsigned int *vm_flags)
73282 +{
73283 + return 1;
73284 +}
73285 +
73286 +__u32
73287 +gr_acl_handle_truncate(const struct dentry * dentry,
73288 + const struct vfsmount * mnt)
73289 +{
73290 + return 1;
73291 +}
73292 +
73293 +__u32
73294 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73295 +{
73296 + return 1;
73297 +}
73298 +
73299 +__u32
73300 +gr_acl_handle_access(const struct dentry * dentry,
73301 + const struct vfsmount * mnt, const int fmode)
73302 +{
73303 + return 1;
73304 +}
73305 +
73306 +__u32
73307 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73308 + umode_t *mode)
73309 +{
73310 + return 1;
73311 +}
73312 +
73313 +__u32
73314 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73315 +{
73316 + return 1;
73317 +}
73318 +
73319 +__u32
73320 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73321 +{
73322 + return 1;
73323 +}
73324 +
73325 +__u32
73326 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73327 +{
73328 + return 1;
73329 +}
73330 +
73331 +void
73332 +grsecurity_init(void)
73333 +{
73334 + return;
73335 +}
73336 +
73337 +umode_t gr_acl_umask(void)
73338 +{
73339 + return 0;
73340 +}
73341 +
73342 +__u32
73343 +gr_acl_handle_mknod(const struct dentry * new_dentry,
73344 + const struct dentry * parent_dentry,
73345 + const struct vfsmount * parent_mnt,
73346 + const int mode)
73347 +{
73348 + return 1;
73349 +}
73350 +
73351 +__u32
73352 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
73353 + const struct dentry * parent_dentry,
73354 + const struct vfsmount * parent_mnt)
73355 +{
73356 + return 1;
73357 +}
73358 +
73359 +__u32
73360 +gr_acl_handle_symlink(const struct dentry * new_dentry,
73361 + const struct dentry * parent_dentry,
73362 + const struct vfsmount * parent_mnt, const struct filename *from)
73363 +{
73364 + return 1;
73365 +}
73366 +
73367 +__u32
73368 +gr_acl_handle_link(const struct dentry * new_dentry,
73369 + const struct dentry * parent_dentry,
73370 + const struct vfsmount * parent_mnt,
73371 + const struct dentry * old_dentry,
73372 + const struct vfsmount * old_mnt, const struct filename *to)
73373 +{
73374 + return 1;
73375 +}
73376 +
73377 +int
73378 +gr_acl_handle_rename(const struct dentry *new_dentry,
73379 + const struct dentry *parent_dentry,
73380 + const struct vfsmount *parent_mnt,
73381 + const struct dentry *old_dentry,
73382 + const struct inode *old_parent_inode,
73383 + const struct vfsmount *old_mnt, const struct filename *newname)
73384 +{
73385 + return 0;
73386 +}
73387 +
73388 +int
73389 +gr_acl_handle_filldir(const struct file *file, const char *name,
73390 + const int namelen, const ino_t ino)
73391 +{
73392 + return 1;
73393 +}
73394 +
73395 +int
73396 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73397 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73398 +{
73399 + return 1;
73400 +}
73401 +
73402 +int
73403 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73404 +{
73405 + return 0;
73406 +}
73407 +
73408 +int
73409 +gr_search_accept(const struct socket *sock)
73410 +{
73411 + return 0;
73412 +}
73413 +
73414 +int
73415 +gr_search_listen(const struct socket *sock)
73416 +{
73417 + return 0;
73418 +}
73419 +
73420 +int
73421 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73422 +{
73423 + return 0;
73424 +}
73425 +
73426 +__u32
73427 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73428 +{
73429 + return 1;
73430 +}
73431 +
73432 +__u32
73433 +gr_acl_handle_creat(const struct dentry * dentry,
73434 + const struct dentry * p_dentry,
73435 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73436 + const int imode)
73437 +{
73438 + return 1;
73439 +}
73440 +
73441 +void
73442 +gr_acl_handle_exit(void)
73443 +{
73444 + return;
73445 +}
73446 +
73447 +int
73448 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73449 +{
73450 + return 1;
73451 +}
73452 +
73453 +void
73454 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
73455 +{
73456 + return;
73457 +}
73458 +
73459 +int
73460 +gr_acl_handle_procpidmem(const struct task_struct *task)
73461 +{
73462 + return 0;
73463 +}
73464 +
73465 +int
73466 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
73467 +{
73468 + return 0;
73469 +}
73470 +
73471 +int
73472 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
73473 +{
73474 + return 0;
73475 +}
73476 +
73477 +int
73478 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
73479 +{
73480 + return 0;
73481 +}
73482 +
73483 +int
73484 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
73485 +{
73486 + return 0;
73487 +}
73488 +
73489 +int gr_acl_enable_at_secure(void)
73490 +{
73491 + return 0;
73492 +}
73493 +
73494 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
73495 +{
73496 + return dentry->d_sb->s_dev;
73497 +}
73498 +
73499 +void gr_put_exec_file(struct task_struct *task)
73500 +{
73501 + return;
73502 +}
73503 +
73504 +#ifdef CONFIG_SECURITY
73505 +EXPORT_SYMBOL_GPL(gr_check_user_change);
73506 +EXPORT_SYMBOL_GPL(gr_check_group_change);
73507 +#endif
73508 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
73509 new file mode 100644
73510 index 0000000..f35f454
73511 --- /dev/null
73512 +++ b/grsecurity/grsec_exec.c
73513 @@ -0,0 +1,187 @@
73514 +#include <linux/kernel.h>
73515 +#include <linux/sched.h>
73516 +#include <linux/file.h>
73517 +#include <linux/binfmts.h>
73518 +#include <linux/fs.h>
73519 +#include <linux/types.h>
73520 +#include <linux/grdefs.h>
73521 +#include <linux/grsecurity.h>
73522 +#include <linux/grinternal.h>
73523 +#include <linux/capability.h>
73524 +#include <linux/module.h>
73525 +#include <linux/compat.h>
73526 +
73527 +#include <asm/uaccess.h>
73528 +
73529 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73530 +static char gr_exec_arg_buf[132];
73531 +static DEFINE_MUTEX(gr_exec_arg_mutex);
73532 +#endif
73533 +
73534 +struct user_arg_ptr {
73535 +#ifdef CONFIG_COMPAT
73536 + bool is_compat;
73537 +#endif
73538 + union {
73539 + const char __user *const __user *native;
73540 +#ifdef CONFIG_COMPAT
73541 + const compat_uptr_t __user *compat;
73542 +#endif
73543 + } ptr;
73544 +};
73545 +
73546 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
73547 +
73548 +void
73549 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
73550 +{
73551 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73552 + char *grarg = gr_exec_arg_buf;
73553 + unsigned int i, x, execlen = 0;
73554 + char c;
73555 +
73556 + if (!((grsec_enable_execlog && grsec_enable_group &&
73557 + in_group_p(grsec_audit_gid))
73558 + || (grsec_enable_execlog && !grsec_enable_group)))
73559 + return;
73560 +
73561 + mutex_lock(&gr_exec_arg_mutex);
73562 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
73563 +
73564 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
73565 + const char __user *p;
73566 + unsigned int len;
73567 +
73568 + p = get_user_arg_ptr(argv, i);
73569 + if (IS_ERR(p))
73570 + goto log;
73571 +
73572 + len = strnlen_user(p, 128 - execlen);
73573 + if (len > 128 - execlen)
73574 + len = 128 - execlen;
73575 + else if (len > 0)
73576 + len--;
73577 + if (copy_from_user(grarg + execlen, p, len))
73578 + goto log;
73579 +
73580 + /* rewrite unprintable characters */
73581 + for (x = 0; x < len; x++) {
73582 + c = *(grarg + execlen + x);
73583 + if (c < 32 || c > 126)
73584 + *(grarg + execlen + x) = ' ';
73585 + }
73586 +
73587 + execlen += len;
73588 + *(grarg + execlen) = ' ';
73589 + *(grarg + execlen + 1) = '\0';
73590 + execlen++;
73591 + }
73592 +
73593 + log:
73594 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
73595 + bprm->file->f_path.mnt, grarg);
73596 + mutex_unlock(&gr_exec_arg_mutex);
73597 +#endif
73598 + return;
73599 +}
73600 +
73601 +#ifdef CONFIG_GRKERNSEC
73602 +extern int gr_acl_is_capable(const int cap);
73603 +extern int gr_acl_is_capable_nolog(const int cap);
73604 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73605 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
73606 +extern int gr_chroot_is_capable(const int cap);
73607 +extern int gr_chroot_is_capable_nolog(const int cap);
73608 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73609 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
73610 +#endif
73611 +
73612 +const char *captab_log[] = {
73613 + "CAP_CHOWN",
73614 + "CAP_DAC_OVERRIDE",
73615 + "CAP_DAC_READ_SEARCH",
73616 + "CAP_FOWNER",
73617 + "CAP_FSETID",
73618 + "CAP_KILL",
73619 + "CAP_SETGID",
73620 + "CAP_SETUID",
73621 + "CAP_SETPCAP",
73622 + "CAP_LINUX_IMMUTABLE",
73623 + "CAP_NET_BIND_SERVICE",
73624 + "CAP_NET_BROADCAST",
73625 + "CAP_NET_ADMIN",
73626 + "CAP_NET_RAW",
73627 + "CAP_IPC_LOCK",
73628 + "CAP_IPC_OWNER",
73629 + "CAP_SYS_MODULE",
73630 + "CAP_SYS_RAWIO",
73631 + "CAP_SYS_CHROOT",
73632 + "CAP_SYS_PTRACE",
73633 + "CAP_SYS_PACCT",
73634 + "CAP_SYS_ADMIN",
73635 + "CAP_SYS_BOOT",
73636 + "CAP_SYS_NICE",
73637 + "CAP_SYS_RESOURCE",
73638 + "CAP_SYS_TIME",
73639 + "CAP_SYS_TTY_CONFIG",
73640 + "CAP_MKNOD",
73641 + "CAP_LEASE",
73642 + "CAP_AUDIT_WRITE",
73643 + "CAP_AUDIT_CONTROL",
73644 + "CAP_SETFCAP",
73645 + "CAP_MAC_OVERRIDE",
73646 + "CAP_MAC_ADMIN",
73647 + "CAP_SYSLOG",
73648 + "CAP_WAKE_ALARM"
73649 +};
73650 +
73651 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
73652 +
73653 +int gr_is_capable(const int cap)
73654 +{
73655 +#ifdef CONFIG_GRKERNSEC
73656 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
73657 + return 1;
73658 + return 0;
73659 +#else
73660 + return 1;
73661 +#endif
73662 +}
73663 +
73664 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73665 +{
73666 +#ifdef CONFIG_GRKERNSEC
73667 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
73668 + return 1;
73669 + return 0;
73670 +#else
73671 + return 1;
73672 +#endif
73673 +}
73674 +
73675 +int gr_is_capable_nolog(const int cap)
73676 +{
73677 +#ifdef CONFIG_GRKERNSEC
73678 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
73679 + return 1;
73680 + return 0;
73681 +#else
73682 + return 1;
73683 +#endif
73684 +}
73685 +
73686 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
73687 +{
73688 +#ifdef CONFIG_GRKERNSEC
73689 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
73690 + return 1;
73691 + return 0;
73692 +#else
73693 + return 1;
73694 +#endif
73695 +}
73696 +
73697 +EXPORT_SYMBOL_GPL(gr_is_capable);
73698 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
73699 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
73700 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
73701 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
73702 new file mode 100644
73703 index 0000000..06cc6ea
73704 --- /dev/null
73705 +++ b/grsecurity/grsec_fifo.c
73706 @@ -0,0 +1,24 @@
73707 +#include <linux/kernel.h>
73708 +#include <linux/sched.h>
73709 +#include <linux/fs.h>
73710 +#include <linux/file.h>
73711 +#include <linux/grinternal.h>
73712 +
73713 +int
73714 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
73715 + const struct dentry *dir, const int flag, const int acc_mode)
73716 +{
73717 +#ifdef CONFIG_GRKERNSEC_FIFO
73718 + const struct cred *cred = current_cred();
73719 +
73720 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
73721 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
73722 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
73723 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
73724 + if (!inode_permission(dentry->d_inode, acc_mode))
73725 + 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));
73726 + return -EACCES;
73727 + }
73728 +#endif
73729 + return 0;
73730 +}
73731 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
73732 new file mode 100644
73733 index 0000000..8ca18bf
73734 --- /dev/null
73735 +++ b/grsecurity/grsec_fork.c
73736 @@ -0,0 +1,23 @@
73737 +#include <linux/kernel.h>
73738 +#include <linux/sched.h>
73739 +#include <linux/grsecurity.h>
73740 +#include <linux/grinternal.h>
73741 +#include <linux/errno.h>
73742 +
73743 +void
73744 +gr_log_forkfail(const int retval)
73745 +{
73746 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73747 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
73748 + switch (retval) {
73749 + case -EAGAIN:
73750 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
73751 + break;
73752 + case -ENOMEM:
73753 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
73754 + break;
73755 + }
73756 + }
73757 +#endif
73758 + return;
73759 +}
73760 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
73761 new file mode 100644
73762 index 0000000..ae6c028
73763 --- /dev/null
73764 +++ b/grsecurity/grsec_init.c
73765 @@ -0,0 +1,272 @@
73766 +#include <linux/kernel.h>
73767 +#include <linux/sched.h>
73768 +#include <linux/mm.h>
73769 +#include <linux/gracl.h>
73770 +#include <linux/slab.h>
73771 +#include <linux/vmalloc.h>
73772 +#include <linux/percpu.h>
73773 +#include <linux/module.h>
73774 +
73775 +int grsec_enable_ptrace_readexec;
73776 +int grsec_enable_setxid;
73777 +int grsec_enable_symlinkown;
73778 +kgid_t grsec_symlinkown_gid;
73779 +int grsec_enable_brute;
73780 +int grsec_enable_link;
73781 +int grsec_enable_dmesg;
73782 +int grsec_enable_harden_ptrace;
73783 +int grsec_enable_harden_ipc;
73784 +int grsec_enable_fifo;
73785 +int grsec_enable_execlog;
73786 +int grsec_enable_signal;
73787 +int grsec_enable_forkfail;
73788 +int grsec_enable_audit_ptrace;
73789 +int grsec_enable_time;
73790 +int grsec_enable_group;
73791 +kgid_t grsec_audit_gid;
73792 +int grsec_enable_chdir;
73793 +int grsec_enable_mount;
73794 +int grsec_enable_rofs;
73795 +int grsec_deny_new_usb;
73796 +int grsec_enable_chroot_findtask;
73797 +int grsec_enable_chroot_mount;
73798 +int grsec_enable_chroot_shmat;
73799 +int grsec_enable_chroot_fchdir;
73800 +int grsec_enable_chroot_double;
73801 +int grsec_enable_chroot_pivot;
73802 +int grsec_enable_chroot_chdir;
73803 +int grsec_enable_chroot_chmod;
73804 +int grsec_enable_chroot_mknod;
73805 +int grsec_enable_chroot_nice;
73806 +int grsec_enable_chroot_execlog;
73807 +int grsec_enable_chroot_caps;
73808 +int grsec_enable_chroot_sysctl;
73809 +int grsec_enable_chroot_unix;
73810 +int grsec_enable_tpe;
73811 +kgid_t grsec_tpe_gid;
73812 +int grsec_enable_blackhole;
73813 +#ifdef CONFIG_IPV6_MODULE
73814 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
73815 +#endif
73816 +int grsec_lastack_retries;
73817 +int grsec_enable_tpe_all;
73818 +int grsec_enable_tpe_invert;
73819 +int grsec_enable_socket_all;
73820 +kgid_t grsec_socket_all_gid;
73821 +int grsec_enable_socket_client;
73822 +kgid_t grsec_socket_client_gid;
73823 +int grsec_enable_socket_server;
73824 +kgid_t grsec_socket_server_gid;
73825 +int grsec_resource_logging;
73826 +int grsec_disable_privio;
73827 +int grsec_enable_log_rwxmaps;
73828 +int grsec_lock;
73829 +
73830 +DEFINE_SPINLOCK(grsec_alert_lock);
73831 +unsigned long grsec_alert_wtime = 0;
73832 +unsigned long grsec_alert_fyet = 0;
73833 +
73834 +DEFINE_SPINLOCK(grsec_audit_lock);
73835 +
73836 +DEFINE_RWLOCK(grsec_exec_file_lock);
73837 +
73838 +char *gr_shared_page[4];
73839 +
73840 +char *gr_alert_log_fmt;
73841 +char *gr_audit_log_fmt;
73842 +char *gr_alert_log_buf;
73843 +char *gr_audit_log_buf;
73844 +
73845 +void __init
73846 +grsecurity_init(void)
73847 +{
73848 + int j;
73849 + /* create the per-cpu shared pages */
73850 +
73851 +#ifdef CONFIG_X86
73852 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
73853 +#endif
73854 +
73855 + for (j = 0; j < 4; j++) {
73856 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
73857 + if (gr_shared_page[j] == NULL) {
73858 + panic("Unable to allocate grsecurity shared page");
73859 + return;
73860 + }
73861 + }
73862 +
73863 + /* allocate log buffers */
73864 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
73865 + if (!gr_alert_log_fmt) {
73866 + panic("Unable to allocate grsecurity alert log format buffer");
73867 + return;
73868 + }
73869 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
73870 + if (!gr_audit_log_fmt) {
73871 + panic("Unable to allocate grsecurity audit log format buffer");
73872 + return;
73873 + }
73874 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73875 + if (!gr_alert_log_buf) {
73876 + panic("Unable to allocate grsecurity alert log buffer");
73877 + return;
73878 + }
73879 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73880 + if (!gr_audit_log_buf) {
73881 + panic("Unable to allocate grsecurity audit log buffer");
73882 + return;
73883 + }
73884 +
73885 +#ifdef CONFIG_GRKERNSEC_IO
73886 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
73887 + grsec_disable_privio = 1;
73888 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73889 + grsec_disable_privio = 1;
73890 +#else
73891 + grsec_disable_privio = 0;
73892 +#endif
73893 +#endif
73894 +
73895 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73896 + /* for backward compatibility, tpe_invert always defaults to on if
73897 + enabled in the kernel
73898 + */
73899 + grsec_enable_tpe_invert = 1;
73900 +#endif
73901 +
73902 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73903 +#ifndef CONFIG_GRKERNSEC_SYSCTL
73904 + grsec_lock = 1;
73905 +#endif
73906 +
73907 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73908 + grsec_enable_log_rwxmaps = 1;
73909 +#endif
73910 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
73911 + grsec_enable_group = 1;
73912 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
73913 +#endif
73914 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73915 + grsec_enable_ptrace_readexec = 1;
73916 +#endif
73917 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73918 + grsec_enable_chdir = 1;
73919 +#endif
73920 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
73921 + grsec_enable_harden_ptrace = 1;
73922 +#endif
73923 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73924 + grsec_enable_harden_ipc = 1;
73925 +#endif
73926 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73927 + grsec_enable_mount = 1;
73928 +#endif
73929 +#ifdef CONFIG_GRKERNSEC_LINK
73930 + grsec_enable_link = 1;
73931 +#endif
73932 +#ifdef CONFIG_GRKERNSEC_BRUTE
73933 + grsec_enable_brute = 1;
73934 +#endif
73935 +#ifdef CONFIG_GRKERNSEC_DMESG
73936 + grsec_enable_dmesg = 1;
73937 +#endif
73938 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73939 + grsec_enable_blackhole = 1;
73940 + grsec_lastack_retries = 4;
73941 +#endif
73942 +#ifdef CONFIG_GRKERNSEC_FIFO
73943 + grsec_enable_fifo = 1;
73944 +#endif
73945 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73946 + grsec_enable_execlog = 1;
73947 +#endif
73948 +#ifdef CONFIG_GRKERNSEC_SETXID
73949 + grsec_enable_setxid = 1;
73950 +#endif
73951 +#ifdef CONFIG_GRKERNSEC_SIGNAL
73952 + grsec_enable_signal = 1;
73953 +#endif
73954 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73955 + grsec_enable_forkfail = 1;
73956 +#endif
73957 +#ifdef CONFIG_GRKERNSEC_TIME
73958 + grsec_enable_time = 1;
73959 +#endif
73960 +#ifdef CONFIG_GRKERNSEC_RESLOG
73961 + grsec_resource_logging = 1;
73962 +#endif
73963 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73964 + grsec_enable_chroot_findtask = 1;
73965 +#endif
73966 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73967 + grsec_enable_chroot_unix = 1;
73968 +#endif
73969 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73970 + grsec_enable_chroot_mount = 1;
73971 +#endif
73972 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73973 + grsec_enable_chroot_fchdir = 1;
73974 +#endif
73975 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73976 + grsec_enable_chroot_shmat = 1;
73977 +#endif
73978 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73979 + grsec_enable_audit_ptrace = 1;
73980 +#endif
73981 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73982 + grsec_enable_chroot_double = 1;
73983 +#endif
73984 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73985 + grsec_enable_chroot_pivot = 1;
73986 +#endif
73987 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73988 + grsec_enable_chroot_chdir = 1;
73989 +#endif
73990 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73991 + grsec_enable_chroot_chmod = 1;
73992 +#endif
73993 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73994 + grsec_enable_chroot_mknod = 1;
73995 +#endif
73996 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73997 + grsec_enable_chroot_nice = 1;
73998 +#endif
73999 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74000 + grsec_enable_chroot_execlog = 1;
74001 +#endif
74002 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74003 + grsec_enable_chroot_caps = 1;
74004 +#endif
74005 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74006 + grsec_enable_chroot_sysctl = 1;
74007 +#endif
74008 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74009 + grsec_enable_symlinkown = 1;
74010 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74011 +#endif
74012 +#ifdef CONFIG_GRKERNSEC_TPE
74013 + grsec_enable_tpe = 1;
74014 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74015 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74016 + grsec_enable_tpe_all = 1;
74017 +#endif
74018 +#endif
74019 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74020 + grsec_enable_socket_all = 1;
74021 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74022 +#endif
74023 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74024 + grsec_enable_socket_client = 1;
74025 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74026 +#endif
74027 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74028 + grsec_enable_socket_server = 1;
74029 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74030 +#endif
74031 +#endif
74032 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74033 + grsec_deny_new_usb = 1;
74034 +#endif
74035 +
74036 + return;
74037 +}
74038 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74039 new file mode 100644
74040 index 0000000..1773300
74041 --- /dev/null
74042 +++ b/grsecurity/grsec_ipc.c
74043 @@ -0,0 +1,48 @@
74044 +#include <linux/kernel.h>
74045 +#include <linux/mm.h>
74046 +#include <linux/sched.h>
74047 +#include <linux/file.h>
74048 +#include <linux/ipc.h>
74049 +#include <linux/ipc_namespace.h>
74050 +#include <linux/grsecurity.h>
74051 +#include <linux/grinternal.h>
74052 +
74053 +int
74054 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74055 +{
74056 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74057 + int write;
74058 + int orig_granted_mode;
74059 + kuid_t euid;
74060 + kgid_t egid;
74061 +
74062 + if (!grsec_enable_harden_ipc)
74063 + return 1;
74064 +
74065 + euid = current_euid();
74066 + egid = current_egid();
74067 +
74068 + write = requested_mode & 00002;
74069 + orig_granted_mode = ipcp->mode;
74070 +
74071 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74072 + orig_granted_mode >>= 6;
74073 + else {
74074 + /* if likely wrong permissions, lock to user */
74075 + if (orig_granted_mode & 0007)
74076 + orig_granted_mode = 0;
74077 + /* otherwise do a egid-only check */
74078 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74079 + orig_granted_mode >>= 3;
74080 + /* otherwise, no access */
74081 + else
74082 + orig_granted_mode = 0;
74083 + }
74084 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74085 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74086 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74087 + return 0;
74088 + }
74089 +#endif
74090 + return 1;
74091 +}
74092 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74093 new file mode 100644
74094 index 0000000..5e05e20
74095 --- /dev/null
74096 +++ b/grsecurity/grsec_link.c
74097 @@ -0,0 +1,58 @@
74098 +#include <linux/kernel.h>
74099 +#include <linux/sched.h>
74100 +#include <linux/fs.h>
74101 +#include <linux/file.h>
74102 +#include <linux/grinternal.h>
74103 +
74104 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74105 +{
74106 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74107 + const struct inode *link_inode = link->dentry->d_inode;
74108 +
74109 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74110 + /* ignore root-owned links, e.g. /proc/self */
74111 + gr_is_global_nonroot(link_inode->i_uid) && target &&
74112 + !uid_eq(link_inode->i_uid, target->i_uid)) {
74113 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74114 + return 1;
74115 + }
74116 +#endif
74117 + return 0;
74118 +}
74119 +
74120 +int
74121 +gr_handle_follow_link(const struct inode *parent,
74122 + const struct inode *inode,
74123 + const struct dentry *dentry, const struct vfsmount *mnt)
74124 +{
74125 +#ifdef CONFIG_GRKERNSEC_LINK
74126 + const struct cred *cred = current_cred();
74127 +
74128 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74129 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74130 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74131 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74132 + return -EACCES;
74133 + }
74134 +#endif
74135 + return 0;
74136 +}
74137 +
74138 +int
74139 +gr_handle_hardlink(const struct dentry *dentry,
74140 + const struct vfsmount *mnt,
74141 + struct inode *inode, const int mode, const struct filename *to)
74142 +{
74143 +#ifdef CONFIG_GRKERNSEC_LINK
74144 + const struct cred *cred = current_cred();
74145 +
74146 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74147 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74148 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74149 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74150 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74151 + return -EPERM;
74152 + }
74153 +#endif
74154 + return 0;
74155 +}
74156 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74157 new file mode 100644
74158 index 0000000..dbe0a6b
74159 --- /dev/null
74160 +++ b/grsecurity/grsec_log.c
74161 @@ -0,0 +1,341 @@
74162 +#include <linux/kernel.h>
74163 +#include <linux/sched.h>
74164 +#include <linux/file.h>
74165 +#include <linux/tty.h>
74166 +#include <linux/fs.h>
74167 +#include <linux/mm.h>
74168 +#include <linux/grinternal.h>
74169 +
74170 +#ifdef CONFIG_TREE_PREEMPT_RCU
74171 +#define DISABLE_PREEMPT() preempt_disable()
74172 +#define ENABLE_PREEMPT() preempt_enable()
74173 +#else
74174 +#define DISABLE_PREEMPT()
74175 +#define ENABLE_PREEMPT()
74176 +#endif
74177 +
74178 +#define BEGIN_LOCKS(x) \
74179 + DISABLE_PREEMPT(); \
74180 + rcu_read_lock(); \
74181 + read_lock(&tasklist_lock); \
74182 + read_lock(&grsec_exec_file_lock); \
74183 + if (x != GR_DO_AUDIT) \
74184 + spin_lock(&grsec_alert_lock); \
74185 + else \
74186 + spin_lock(&grsec_audit_lock)
74187 +
74188 +#define END_LOCKS(x) \
74189 + if (x != GR_DO_AUDIT) \
74190 + spin_unlock(&grsec_alert_lock); \
74191 + else \
74192 + spin_unlock(&grsec_audit_lock); \
74193 + read_unlock(&grsec_exec_file_lock); \
74194 + read_unlock(&tasklist_lock); \
74195 + rcu_read_unlock(); \
74196 + ENABLE_PREEMPT(); \
74197 + if (x == GR_DONT_AUDIT) \
74198 + gr_handle_alertkill(current)
74199 +
74200 +enum {
74201 + FLOODING,
74202 + NO_FLOODING
74203 +};
74204 +
74205 +extern char *gr_alert_log_fmt;
74206 +extern char *gr_audit_log_fmt;
74207 +extern char *gr_alert_log_buf;
74208 +extern char *gr_audit_log_buf;
74209 +
74210 +static int gr_log_start(int audit)
74211 +{
74212 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74213 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74214 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74215 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74216 + unsigned long curr_secs = get_seconds();
74217 +
74218 + if (audit == GR_DO_AUDIT)
74219 + goto set_fmt;
74220 +
74221 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74222 + grsec_alert_wtime = curr_secs;
74223 + grsec_alert_fyet = 0;
74224 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74225 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74226 + grsec_alert_fyet++;
74227 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74228 + grsec_alert_wtime = curr_secs;
74229 + grsec_alert_fyet++;
74230 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74231 + return FLOODING;
74232 + }
74233 + else return FLOODING;
74234 +
74235 +set_fmt:
74236 +#endif
74237 + memset(buf, 0, PAGE_SIZE);
74238 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
74239 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74240 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74241 + } else if (current->signal->curr_ip) {
74242 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74243 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74244 + } else if (gr_acl_is_enabled()) {
74245 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74246 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74247 + } else {
74248 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
74249 + strcpy(buf, fmt);
74250 + }
74251 +
74252 + return NO_FLOODING;
74253 +}
74254 +
74255 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74256 + __attribute__ ((format (printf, 2, 0)));
74257 +
74258 +static void gr_log_middle(int audit, const char *msg, va_list ap)
74259 +{
74260 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74261 + unsigned int len = strlen(buf);
74262 +
74263 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74264 +
74265 + return;
74266 +}
74267 +
74268 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74269 + __attribute__ ((format (printf, 2, 3)));
74270 +
74271 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
74272 +{
74273 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74274 + unsigned int len = strlen(buf);
74275 + va_list ap;
74276 +
74277 + va_start(ap, msg);
74278 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74279 + va_end(ap);
74280 +
74281 + return;
74282 +}
74283 +
74284 +static void gr_log_end(int audit, int append_default)
74285 +{
74286 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74287 + if (append_default) {
74288 + struct task_struct *task = current;
74289 + struct task_struct *parent = task->real_parent;
74290 + const struct cred *cred = __task_cred(task);
74291 + const struct cred *pcred = __task_cred(parent);
74292 + unsigned int len = strlen(buf);
74293 +
74294 + 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));
74295 + }
74296 +
74297 + printk("%s\n", buf);
74298 +
74299 + return;
74300 +}
74301 +
74302 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74303 +{
74304 + int logtype;
74305 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74306 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74307 + void *voidptr = NULL;
74308 + int num1 = 0, num2 = 0;
74309 + unsigned long ulong1 = 0, ulong2 = 0;
74310 + struct dentry *dentry = NULL;
74311 + struct vfsmount *mnt = NULL;
74312 + struct file *file = NULL;
74313 + struct task_struct *task = NULL;
74314 + struct vm_area_struct *vma = NULL;
74315 + const struct cred *cred, *pcred;
74316 + va_list ap;
74317 +
74318 + BEGIN_LOCKS(audit);
74319 + logtype = gr_log_start(audit);
74320 + if (logtype == FLOODING) {
74321 + END_LOCKS(audit);
74322 + return;
74323 + }
74324 + va_start(ap, argtypes);
74325 + switch (argtypes) {
74326 + case GR_TTYSNIFF:
74327 + task = va_arg(ap, struct task_struct *);
74328 + 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));
74329 + break;
74330 + case GR_SYSCTL_HIDDEN:
74331 + str1 = va_arg(ap, char *);
74332 + gr_log_middle_varargs(audit, msg, result, str1);
74333 + break;
74334 + case GR_RBAC:
74335 + dentry = va_arg(ap, struct dentry *);
74336 + mnt = va_arg(ap, struct vfsmount *);
74337 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74338 + break;
74339 + case GR_RBAC_STR:
74340 + dentry = va_arg(ap, struct dentry *);
74341 + mnt = va_arg(ap, struct vfsmount *);
74342 + str1 = va_arg(ap, char *);
74343 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74344 + break;
74345 + case GR_STR_RBAC:
74346 + str1 = va_arg(ap, char *);
74347 + dentry = va_arg(ap, struct dentry *);
74348 + mnt = va_arg(ap, struct vfsmount *);
74349 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74350 + break;
74351 + case GR_RBAC_MODE2:
74352 + dentry = va_arg(ap, struct dentry *);
74353 + mnt = va_arg(ap, struct vfsmount *);
74354 + str1 = va_arg(ap, char *);
74355 + str2 = va_arg(ap, char *);
74356 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74357 + break;
74358 + case GR_RBAC_MODE3:
74359 + dentry = va_arg(ap, struct dentry *);
74360 + mnt = va_arg(ap, struct vfsmount *);
74361 + str1 = va_arg(ap, char *);
74362 + str2 = va_arg(ap, char *);
74363 + str3 = va_arg(ap, char *);
74364 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74365 + break;
74366 + case GR_FILENAME:
74367 + dentry = va_arg(ap, struct dentry *);
74368 + mnt = va_arg(ap, struct vfsmount *);
74369 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74370 + break;
74371 + case GR_STR_FILENAME:
74372 + str1 = va_arg(ap, char *);
74373 + dentry = va_arg(ap, struct dentry *);
74374 + mnt = va_arg(ap, struct vfsmount *);
74375 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74376 + break;
74377 + case GR_FILENAME_STR:
74378 + dentry = va_arg(ap, struct dentry *);
74379 + mnt = va_arg(ap, struct vfsmount *);
74380 + str1 = va_arg(ap, char *);
74381 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74382 + break;
74383 + case GR_FILENAME_TWO_INT:
74384 + dentry = va_arg(ap, struct dentry *);
74385 + mnt = va_arg(ap, struct vfsmount *);
74386 + num1 = va_arg(ap, int);
74387 + num2 = va_arg(ap, int);
74388 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74389 + break;
74390 + case GR_FILENAME_TWO_INT_STR:
74391 + dentry = va_arg(ap, struct dentry *);
74392 + mnt = va_arg(ap, struct vfsmount *);
74393 + num1 = va_arg(ap, int);
74394 + num2 = va_arg(ap, int);
74395 + str1 = va_arg(ap, char *);
74396 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74397 + break;
74398 + case GR_TEXTREL:
74399 + file = va_arg(ap, struct file *);
74400 + ulong1 = va_arg(ap, unsigned long);
74401 + ulong2 = va_arg(ap, unsigned long);
74402 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74403 + break;
74404 + case GR_PTRACE:
74405 + task = va_arg(ap, struct task_struct *);
74406 + 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));
74407 + break;
74408 + case GR_RESOURCE:
74409 + task = va_arg(ap, struct task_struct *);
74410 + cred = __task_cred(task);
74411 + pcred = __task_cred(task->real_parent);
74412 + ulong1 = va_arg(ap, unsigned long);
74413 + str1 = va_arg(ap, char *);
74414 + ulong2 = va_arg(ap, unsigned long);
74415 + 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));
74416 + break;
74417 + case GR_CAP:
74418 + task = va_arg(ap, struct task_struct *);
74419 + cred = __task_cred(task);
74420 + pcred = __task_cred(task->real_parent);
74421 + str1 = va_arg(ap, char *);
74422 + 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));
74423 + break;
74424 + case GR_SIG:
74425 + str1 = va_arg(ap, char *);
74426 + voidptr = va_arg(ap, void *);
74427 + gr_log_middle_varargs(audit, msg, str1, voidptr);
74428 + break;
74429 + case GR_SIG2:
74430 + task = va_arg(ap, struct task_struct *);
74431 + cred = __task_cred(task);
74432 + pcred = __task_cred(task->real_parent);
74433 + num1 = va_arg(ap, int);
74434 + 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));
74435 + break;
74436 + case GR_CRASH1:
74437 + task = va_arg(ap, struct task_struct *);
74438 + cred = __task_cred(task);
74439 + pcred = __task_cred(task->real_parent);
74440 + ulong1 = va_arg(ap, unsigned long);
74441 + 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);
74442 + break;
74443 + case GR_CRASH2:
74444 + task = va_arg(ap, struct task_struct *);
74445 + cred = __task_cred(task);
74446 + pcred = __task_cred(task->real_parent);
74447 + ulong1 = va_arg(ap, unsigned long);
74448 + 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);
74449 + break;
74450 + case GR_RWXMAP:
74451 + file = va_arg(ap, struct file *);
74452 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
74453 + break;
74454 + case GR_RWXMAPVMA:
74455 + vma = va_arg(ap, struct vm_area_struct *);
74456 + if (vma->vm_file)
74457 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
74458 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
74459 + str1 = "<stack>";
74460 + else if (vma->vm_start <= current->mm->brk &&
74461 + vma->vm_end >= current->mm->start_brk)
74462 + str1 = "<heap>";
74463 + else
74464 + str1 = "<anonymous mapping>";
74465 + gr_log_middle_varargs(audit, msg, str1);
74466 + break;
74467 + case GR_PSACCT:
74468 + {
74469 + unsigned int wday, cday;
74470 + __u8 whr, chr;
74471 + __u8 wmin, cmin;
74472 + __u8 wsec, csec;
74473 + char cur_tty[64] = { 0 };
74474 + char parent_tty[64] = { 0 };
74475 +
74476 + task = va_arg(ap, struct task_struct *);
74477 + wday = va_arg(ap, unsigned int);
74478 + cday = va_arg(ap, unsigned int);
74479 + whr = va_arg(ap, int);
74480 + chr = va_arg(ap, int);
74481 + wmin = va_arg(ap, int);
74482 + cmin = va_arg(ap, int);
74483 + wsec = va_arg(ap, int);
74484 + csec = va_arg(ap, int);
74485 + ulong1 = va_arg(ap, unsigned long);
74486 + cred = __task_cred(task);
74487 + pcred = __task_cred(task->real_parent);
74488 +
74489 + 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));
74490 + }
74491 + break;
74492 + default:
74493 + gr_log_middle(audit, msg, ap);
74494 + }
74495 + va_end(ap);
74496 + // these don't need DEFAULTSECARGS printed on the end
74497 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
74498 + gr_log_end(audit, 0);
74499 + else
74500 + gr_log_end(audit, 1);
74501 + END_LOCKS(audit);
74502 +}
74503 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
74504 new file mode 100644
74505 index 0000000..0e39d8c
74506 --- /dev/null
74507 +++ b/grsecurity/grsec_mem.c
74508 @@ -0,0 +1,48 @@
74509 +#include <linux/kernel.h>
74510 +#include <linux/sched.h>
74511 +#include <linux/mm.h>
74512 +#include <linux/mman.h>
74513 +#include <linux/module.h>
74514 +#include <linux/grinternal.h>
74515 +
74516 +void gr_handle_msr_write(void)
74517 +{
74518 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
74519 + return;
74520 +}
74521 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
74522 +
74523 +void
74524 +gr_handle_ioperm(void)
74525 +{
74526 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
74527 + return;
74528 +}
74529 +
74530 +void
74531 +gr_handle_iopl(void)
74532 +{
74533 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
74534 + return;
74535 +}
74536 +
74537 +void
74538 +gr_handle_mem_readwrite(u64 from, u64 to)
74539 +{
74540 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
74541 + return;
74542 +}
74543 +
74544 +void
74545 +gr_handle_vm86(void)
74546 +{
74547 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
74548 + return;
74549 +}
74550 +
74551 +void
74552 +gr_log_badprocpid(const char *entry)
74553 +{
74554 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
74555 + return;
74556 +}
74557 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
74558 new file mode 100644
74559 index 0000000..cd9e124
74560 --- /dev/null
74561 +++ b/grsecurity/grsec_mount.c
74562 @@ -0,0 +1,65 @@
74563 +#include <linux/kernel.h>
74564 +#include <linux/sched.h>
74565 +#include <linux/mount.h>
74566 +#include <linux/major.h>
74567 +#include <linux/grsecurity.h>
74568 +#include <linux/grinternal.h>
74569 +
74570 +void
74571 +gr_log_remount(const char *devname, const int retval)
74572 +{
74573 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74574 + if (grsec_enable_mount && (retval >= 0))
74575 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
74576 +#endif
74577 + return;
74578 +}
74579 +
74580 +void
74581 +gr_log_unmount(const char *devname, const int retval)
74582 +{
74583 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74584 + if (grsec_enable_mount && (retval >= 0))
74585 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
74586 +#endif
74587 + return;
74588 +}
74589 +
74590 +void
74591 +gr_log_mount(const char *from, const char *to, const int retval)
74592 +{
74593 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74594 + if (grsec_enable_mount && (retval >= 0))
74595 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
74596 +#endif
74597 + return;
74598 +}
74599 +
74600 +int
74601 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
74602 +{
74603 +#ifdef CONFIG_GRKERNSEC_ROFS
74604 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
74605 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
74606 + return -EPERM;
74607 + } else
74608 + return 0;
74609 +#endif
74610 + return 0;
74611 +}
74612 +
74613 +int
74614 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
74615 +{
74616 +#ifdef CONFIG_GRKERNSEC_ROFS
74617 + struct inode *inode = dentry->d_inode;
74618 +
74619 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
74620 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
74621 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
74622 + return -EPERM;
74623 + } else
74624 + return 0;
74625 +#endif
74626 + return 0;
74627 +}
74628 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
74629 new file mode 100644
74630 index 0000000..6ee9d50
74631 --- /dev/null
74632 +++ b/grsecurity/grsec_pax.c
74633 @@ -0,0 +1,45 @@
74634 +#include <linux/kernel.h>
74635 +#include <linux/sched.h>
74636 +#include <linux/mm.h>
74637 +#include <linux/file.h>
74638 +#include <linux/grinternal.h>
74639 +#include <linux/grsecurity.h>
74640 +
74641 +void
74642 +gr_log_textrel(struct vm_area_struct * vma)
74643 +{
74644 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74645 + if (grsec_enable_log_rwxmaps)
74646 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
74647 +#endif
74648 + return;
74649 +}
74650 +
74651 +void gr_log_ptgnustack(struct file *file)
74652 +{
74653 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74654 + if (grsec_enable_log_rwxmaps)
74655 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
74656 +#endif
74657 + return;
74658 +}
74659 +
74660 +void
74661 +gr_log_rwxmmap(struct file *file)
74662 +{
74663 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74664 + if (grsec_enable_log_rwxmaps)
74665 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
74666 +#endif
74667 + return;
74668 +}
74669 +
74670 +void
74671 +gr_log_rwxmprotect(struct vm_area_struct *vma)
74672 +{
74673 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74674 + if (grsec_enable_log_rwxmaps)
74675 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
74676 +#endif
74677 + return;
74678 +}
74679 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
74680 new file mode 100644
74681 index 0000000..f7f29aa
74682 --- /dev/null
74683 +++ b/grsecurity/grsec_ptrace.c
74684 @@ -0,0 +1,30 @@
74685 +#include <linux/kernel.h>
74686 +#include <linux/sched.h>
74687 +#include <linux/grinternal.h>
74688 +#include <linux/security.h>
74689 +
74690 +void
74691 +gr_audit_ptrace(struct task_struct *task)
74692 +{
74693 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74694 + if (grsec_enable_audit_ptrace)
74695 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
74696 +#endif
74697 + return;
74698 +}
74699 +
74700 +int
74701 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
74702 +{
74703 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74704 + const struct dentry *dentry = file->f_path.dentry;
74705 + const struct vfsmount *mnt = file->f_path.mnt;
74706 +
74707 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
74708 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
74709 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
74710 + return -EACCES;
74711 + }
74712 +#endif
74713 + return 0;
74714 +}
74715 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
74716 new file mode 100644
74717 index 0000000..3860c7e
74718 --- /dev/null
74719 +++ b/grsecurity/grsec_sig.c
74720 @@ -0,0 +1,236 @@
74721 +#include <linux/kernel.h>
74722 +#include <linux/sched.h>
74723 +#include <linux/fs.h>
74724 +#include <linux/delay.h>
74725 +#include <linux/grsecurity.h>
74726 +#include <linux/grinternal.h>
74727 +#include <linux/hardirq.h>
74728 +
74729 +char *signames[] = {
74730 + [SIGSEGV] = "Segmentation fault",
74731 + [SIGILL] = "Illegal instruction",
74732 + [SIGABRT] = "Abort",
74733 + [SIGBUS] = "Invalid alignment/Bus error"
74734 +};
74735 +
74736 +void
74737 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
74738 +{
74739 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74740 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
74741 + (sig == SIGABRT) || (sig == SIGBUS))) {
74742 + if (task_pid_nr(t) == task_pid_nr(current)) {
74743 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
74744 + } else {
74745 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
74746 + }
74747 + }
74748 +#endif
74749 + return;
74750 +}
74751 +
74752 +int
74753 +gr_handle_signal(const struct task_struct *p, const int sig)
74754 +{
74755 +#ifdef CONFIG_GRKERNSEC
74756 + /* ignore the 0 signal for protected task checks */
74757 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
74758 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
74759 + return -EPERM;
74760 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
74761 + return -EPERM;
74762 + }
74763 +#endif
74764 + return 0;
74765 +}
74766 +
74767 +#ifdef CONFIG_GRKERNSEC
74768 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
74769 +
74770 +int gr_fake_force_sig(int sig, struct task_struct *t)
74771 +{
74772 + unsigned long int flags;
74773 + int ret, blocked, ignored;
74774 + struct k_sigaction *action;
74775 +
74776 + spin_lock_irqsave(&t->sighand->siglock, flags);
74777 + action = &t->sighand->action[sig-1];
74778 + ignored = action->sa.sa_handler == SIG_IGN;
74779 + blocked = sigismember(&t->blocked, sig);
74780 + if (blocked || ignored) {
74781 + action->sa.sa_handler = SIG_DFL;
74782 + if (blocked) {
74783 + sigdelset(&t->blocked, sig);
74784 + recalc_sigpending_and_wake(t);
74785 + }
74786 + }
74787 + if (action->sa.sa_handler == SIG_DFL)
74788 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
74789 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
74790 +
74791 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
74792 +
74793 + return ret;
74794 +}
74795 +#endif
74796 +
74797 +#define GR_USER_BAN_TIME (15 * 60)
74798 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
74799 +
74800 +void gr_handle_brute_attach(int dumpable)
74801 +{
74802 +#ifdef CONFIG_GRKERNSEC_BRUTE
74803 + struct task_struct *p = current;
74804 + kuid_t uid = GLOBAL_ROOT_UID;
74805 + int daemon = 0;
74806 +
74807 + if (!grsec_enable_brute)
74808 + return;
74809 +
74810 + rcu_read_lock();
74811 + read_lock(&tasklist_lock);
74812 + read_lock(&grsec_exec_file_lock);
74813 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
74814 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
74815 + p->real_parent->brute = 1;
74816 + daemon = 1;
74817 + } else {
74818 + const struct cred *cred = __task_cred(p), *cred2;
74819 + struct task_struct *tsk, *tsk2;
74820 +
74821 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
74822 + struct user_struct *user;
74823 +
74824 + uid = cred->uid;
74825 +
74826 + /* this is put upon execution past expiration */
74827 + user = find_user(uid);
74828 + if (user == NULL)
74829 + goto unlock;
74830 + user->suid_banned = 1;
74831 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
74832 + if (user->suid_ban_expires == ~0UL)
74833 + user->suid_ban_expires--;
74834 +
74835 + /* only kill other threads of the same binary, from the same user */
74836 + do_each_thread(tsk2, tsk) {
74837 + cred2 = __task_cred(tsk);
74838 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
74839 + gr_fake_force_sig(SIGKILL, tsk);
74840 + } while_each_thread(tsk2, tsk);
74841 + }
74842 + }
74843 +unlock:
74844 + read_unlock(&grsec_exec_file_lock);
74845 + read_unlock(&tasklist_lock);
74846 + rcu_read_unlock();
74847 +
74848 + if (gr_is_global_nonroot(uid))
74849 + 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);
74850 + else if (daemon)
74851 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
74852 +
74853 +#endif
74854 + return;
74855 +}
74856 +
74857 +void gr_handle_brute_check(void)
74858 +{
74859 +#ifdef CONFIG_GRKERNSEC_BRUTE
74860 + struct task_struct *p = current;
74861 +
74862 + if (unlikely(p->brute)) {
74863 + if (!grsec_enable_brute)
74864 + p->brute = 0;
74865 + else if (time_before(get_seconds(), p->brute_expires))
74866 + msleep(30 * 1000);
74867 + }
74868 +#endif
74869 + return;
74870 +}
74871 +
74872 +void gr_handle_kernel_exploit(void)
74873 +{
74874 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74875 + const struct cred *cred;
74876 + struct task_struct *tsk, *tsk2;
74877 + struct user_struct *user;
74878 + kuid_t uid;
74879 +
74880 + if (in_irq() || in_serving_softirq() || in_nmi())
74881 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
74882 +
74883 + uid = current_uid();
74884 +
74885 + if (gr_is_global_root(uid))
74886 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
74887 + else {
74888 + /* kill all the processes of this user, hold a reference
74889 + to their creds struct, and prevent them from creating
74890 + another process until system reset
74891 + */
74892 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
74893 + GR_GLOBAL_UID(uid));
74894 + /* we intentionally leak this ref */
74895 + user = get_uid(current->cred->user);
74896 + if (user)
74897 + user->kernel_banned = 1;
74898 +
74899 + /* kill all processes of this user */
74900 + read_lock(&tasklist_lock);
74901 + do_each_thread(tsk2, tsk) {
74902 + cred = __task_cred(tsk);
74903 + if (uid_eq(cred->uid, uid))
74904 + gr_fake_force_sig(SIGKILL, tsk);
74905 + } while_each_thread(tsk2, tsk);
74906 + read_unlock(&tasklist_lock);
74907 + }
74908 +#endif
74909 +}
74910 +
74911 +#ifdef CONFIG_GRKERNSEC_BRUTE
74912 +static bool suid_ban_expired(struct user_struct *user)
74913 +{
74914 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
74915 + user->suid_banned = 0;
74916 + user->suid_ban_expires = 0;
74917 + free_uid(user);
74918 + return true;
74919 + }
74920 +
74921 + return false;
74922 +}
74923 +#endif
74924 +
74925 +int gr_process_kernel_exec_ban(void)
74926 +{
74927 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74928 + if (unlikely(current->cred->user->kernel_banned))
74929 + return -EPERM;
74930 +#endif
74931 + return 0;
74932 +}
74933 +
74934 +int gr_process_kernel_setuid_ban(struct user_struct *user)
74935 +{
74936 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74937 + if (unlikely(user->kernel_banned))
74938 + gr_fake_force_sig(SIGKILL, current);
74939 +#endif
74940 + return 0;
74941 +}
74942 +
74943 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
74944 +{
74945 +#ifdef CONFIG_GRKERNSEC_BRUTE
74946 + struct user_struct *user = current->cred->user;
74947 + if (unlikely(user->suid_banned)) {
74948 + if (suid_ban_expired(user))
74949 + return 0;
74950 + /* disallow execution of suid binaries only */
74951 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
74952 + return -EPERM;
74953 + }
74954 +#endif
74955 + return 0;
74956 +}
74957 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
74958 new file mode 100644
74959 index 0000000..c0aef3a
74960 --- /dev/null
74961 +++ b/grsecurity/grsec_sock.c
74962 @@ -0,0 +1,244 @@
74963 +#include <linux/kernel.h>
74964 +#include <linux/module.h>
74965 +#include <linux/sched.h>
74966 +#include <linux/file.h>
74967 +#include <linux/net.h>
74968 +#include <linux/in.h>
74969 +#include <linux/ip.h>
74970 +#include <net/sock.h>
74971 +#include <net/inet_sock.h>
74972 +#include <linux/grsecurity.h>
74973 +#include <linux/grinternal.h>
74974 +#include <linux/gracl.h>
74975 +
74976 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
74977 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
74978 +
74979 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
74980 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
74981 +
74982 +#ifdef CONFIG_UNIX_MODULE
74983 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
74984 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
74985 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
74986 +EXPORT_SYMBOL_GPL(gr_handle_create);
74987 +#endif
74988 +
74989 +#ifdef CONFIG_GRKERNSEC
74990 +#define gr_conn_table_size 32749
74991 +struct conn_table_entry {
74992 + struct conn_table_entry *next;
74993 + struct signal_struct *sig;
74994 +};
74995 +
74996 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
74997 +DEFINE_SPINLOCK(gr_conn_table_lock);
74998 +
74999 +extern const char * gr_socktype_to_name(unsigned char type);
75000 +extern const char * gr_proto_to_name(unsigned char proto);
75001 +extern const char * gr_sockfamily_to_name(unsigned char family);
75002 +
75003 +static __inline__ int
75004 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75005 +{
75006 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75007 +}
75008 +
75009 +static __inline__ int
75010 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75011 + __u16 sport, __u16 dport)
75012 +{
75013 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75014 + sig->gr_sport == sport && sig->gr_dport == dport))
75015 + return 1;
75016 + else
75017 + return 0;
75018 +}
75019 +
75020 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75021 +{
75022 + struct conn_table_entry **match;
75023 + unsigned int index;
75024 +
75025 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75026 + sig->gr_sport, sig->gr_dport,
75027 + gr_conn_table_size);
75028 +
75029 + newent->sig = sig;
75030 +
75031 + match = &gr_conn_table[index];
75032 + newent->next = *match;
75033 + *match = newent;
75034 +
75035 + return;
75036 +}
75037 +
75038 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75039 +{
75040 + struct conn_table_entry *match, *last = NULL;
75041 + unsigned int index;
75042 +
75043 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75044 + sig->gr_sport, sig->gr_dport,
75045 + gr_conn_table_size);
75046 +
75047 + match = gr_conn_table[index];
75048 + while (match && !conn_match(match->sig,
75049 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75050 + sig->gr_dport)) {
75051 + last = match;
75052 + match = match->next;
75053 + }
75054 +
75055 + if (match) {
75056 + if (last)
75057 + last->next = match->next;
75058 + else
75059 + gr_conn_table[index] = NULL;
75060 + kfree(match);
75061 + }
75062 +
75063 + return;
75064 +}
75065 +
75066 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75067 + __u16 sport, __u16 dport)
75068 +{
75069 + struct conn_table_entry *match;
75070 + unsigned int index;
75071 +
75072 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75073 +
75074 + match = gr_conn_table[index];
75075 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75076 + match = match->next;
75077 +
75078 + if (match)
75079 + return match->sig;
75080 + else
75081 + return NULL;
75082 +}
75083 +
75084 +#endif
75085 +
75086 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75087 +{
75088 +#ifdef CONFIG_GRKERNSEC
75089 + struct signal_struct *sig = task->signal;
75090 + struct conn_table_entry *newent;
75091 +
75092 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75093 + if (newent == NULL)
75094 + return;
75095 + /* no bh lock needed since we are called with bh disabled */
75096 + spin_lock(&gr_conn_table_lock);
75097 + gr_del_task_from_ip_table_nolock(sig);
75098 + sig->gr_saddr = inet->inet_rcv_saddr;
75099 + sig->gr_daddr = inet->inet_daddr;
75100 + sig->gr_sport = inet->inet_sport;
75101 + sig->gr_dport = inet->inet_dport;
75102 + gr_add_to_task_ip_table_nolock(sig, newent);
75103 + spin_unlock(&gr_conn_table_lock);
75104 +#endif
75105 + return;
75106 +}
75107 +
75108 +void gr_del_task_from_ip_table(struct task_struct *task)
75109 +{
75110 +#ifdef CONFIG_GRKERNSEC
75111 + spin_lock_bh(&gr_conn_table_lock);
75112 + gr_del_task_from_ip_table_nolock(task->signal);
75113 + spin_unlock_bh(&gr_conn_table_lock);
75114 +#endif
75115 + return;
75116 +}
75117 +
75118 +void
75119 +gr_attach_curr_ip(const struct sock *sk)
75120 +{
75121 +#ifdef CONFIG_GRKERNSEC
75122 + struct signal_struct *p, *set;
75123 + const struct inet_sock *inet = inet_sk(sk);
75124 +
75125 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75126 + return;
75127 +
75128 + set = current->signal;
75129 +
75130 + spin_lock_bh(&gr_conn_table_lock);
75131 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75132 + inet->inet_dport, inet->inet_sport);
75133 + if (unlikely(p != NULL)) {
75134 + set->curr_ip = p->curr_ip;
75135 + set->used_accept = 1;
75136 + gr_del_task_from_ip_table_nolock(p);
75137 + spin_unlock_bh(&gr_conn_table_lock);
75138 + return;
75139 + }
75140 + spin_unlock_bh(&gr_conn_table_lock);
75141 +
75142 + set->curr_ip = inet->inet_daddr;
75143 + set->used_accept = 1;
75144 +#endif
75145 + return;
75146 +}
75147 +
75148 +int
75149 +gr_handle_sock_all(const int family, const int type, const int protocol)
75150 +{
75151 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75152 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75153 + (family != AF_UNIX)) {
75154 + if (family == AF_INET)
75155 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75156 + else
75157 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75158 + return -EACCES;
75159 + }
75160 +#endif
75161 + return 0;
75162 +}
75163 +
75164 +int
75165 +gr_handle_sock_server(const struct sockaddr *sck)
75166 +{
75167 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75168 + if (grsec_enable_socket_server &&
75169 + in_group_p(grsec_socket_server_gid) &&
75170 + sck && (sck->sa_family != AF_UNIX) &&
75171 + (sck->sa_family != AF_LOCAL)) {
75172 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75173 + return -EACCES;
75174 + }
75175 +#endif
75176 + return 0;
75177 +}
75178 +
75179 +int
75180 +gr_handle_sock_server_other(const struct sock *sck)
75181 +{
75182 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75183 + if (grsec_enable_socket_server &&
75184 + in_group_p(grsec_socket_server_gid) &&
75185 + sck && (sck->sk_family != AF_UNIX) &&
75186 + (sck->sk_family != AF_LOCAL)) {
75187 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75188 + return -EACCES;
75189 + }
75190 +#endif
75191 + return 0;
75192 +}
75193 +
75194 +int
75195 +gr_handle_sock_client(const struct sockaddr *sck)
75196 +{
75197 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75198 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75199 + sck && (sck->sa_family != AF_UNIX) &&
75200 + (sck->sa_family != AF_LOCAL)) {
75201 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75202 + return -EACCES;
75203 + }
75204 +#endif
75205 + return 0;
75206 +}
75207 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75208 new file mode 100644
75209 index 0000000..8159888
75210 --- /dev/null
75211 +++ b/grsecurity/grsec_sysctl.c
75212 @@ -0,0 +1,479 @@
75213 +#include <linux/kernel.h>
75214 +#include <linux/sched.h>
75215 +#include <linux/sysctl.h>
75216 +#include <linux/grsecurity.h>
75217 +#include <linux/grinternal.h>
75218 +
75219 +int
75220 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75221 +{
75222 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75223 + if (dirname == NULL || name == NULL)
75224 + return 0;
75225 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75226 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75227 + return -EACCES;
75228 + }
75229 +#endif
75230 + return 0;
75231 +}
75232 +
75233 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75234 +static int __maybe_unused __read_only one = 1;
75235 +#endif
75236 +
75237 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75238 + defined(CONFIG_GRKERNSEC_DENYUSB)
75239 +struct ctl_table grsecurity_table[] = {
75240 +#ifdef CONFIG_GRKERNSEC_SYSCTL
75241 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75242 +#ifdef CONFIG_GRKERNSEC_IO
75243 + {
75244 + .procname = "disable_priv_io",
75245 + .data = &grsec_disable_privio,
75246 + .maxlen = sizeof(int),
75247 + .mode = 0600,
75248 + .proc_handler = &proc_dointvec,
75249 + },
75250 +#endif
75251 +#endif
75252 +#ifdef CONFIG_GRKERNSEC_LINK
75253 + {
75254 + .procname = "linking_restrictions",
75255 + .data = &grsec_enable_link,
75256 + .maxlen = sizeof(int),
75257 + .mode = 0600,
75258 + .proc_handler = &proc_dointvec,
75259 + },
75260 +#endif
75261 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75262 + {
75263 + .procname = "enforce_symlinksifowner",
75264 + .data = &grsec_enable_symlinkown,
75265 + .maxlen = sizeof(int),
75266 + .mode = 0600,
75267 + .proc_handler = &proc_dointvec,
75268 + },
75269 + {
75270 + .procname = "symlinkown_gid",
75271 + .data = &grsec_symlinkown_gid,
75272 + .maxlen = sizeof(int),
75273 + .mode = 0600,
75274 + .proc_handler = &proc_dointvec,
75275 + },
75276 +#endif
75277 +#ifdef CONFIG_GRKERNSEC_BRUTE
75278 + {
75279 + .procname = "deter_bruteforce",
75280 + .data = &grsec_enable_brute,
75281 + .maxlen = sizeof(int),
75282 + .mode = 0600,
75283 + .proc_handler = &proc_dointvec,
75284 + },
75285 +#endif
75286 +#ifdef CONFIG_GRKERNSEC_FIFO
75287 + {
75288 + .procname = "fifo_restrictions",
75289 + .data = &grsec_enable_fifo,
75290 + .maxlen = sizeof(int),
75291 + .mode = 0600,
75292 + .proc_handler = &proc_dointvec,
75293 + },
75294 +#endif
75295 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75296 + {
75297 + .procname = "ptrace_readexec",
75298 + .data = &grsec_enable_ptrace_readexec,
75299 + .maxlen = sizeof(int),
75300 + .mode = 0600,
75301 + .proc_handler = &proc_dointvec,
75302 + },
75303 +#endif
75304 +#ifdef CONFIG_GRKERNSEC_SETXID
75305 + {
75306 + .procname = "consistent_setxid",
75307 + .data = &grsec_enable_setxid,
75308 + .maxlen = sizeof(int),
75309 + .mode = 0600,
75310 + .proc_handler = &proc_dointvec,
75311 + },
75312 +#endif
75313 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75314 + {
75315 + .procname = "ip_blackhole",
75316 + .data = &grsec_enable_blackhole,
75317 + .maxlen = sizeof(int),
75318 + .mode = 0600,
75319 + .proc_handler = &proc_dointvec,
75320 + },
75321 + {
75322 + .procname = "lastack_retries",
75323 + .data = &grsec_lastack_retries,
75324 + .maxlen = sizeof(int),
75325 + .mode = 0600,
75326 + .proc_handler = &proc_dointvec,
75327 + },
75328 +#endif
75329 +#ifdef CONFIG_GRKERNSEC_EXECLOG
75330 + {
75331 + .procname = "exec_logging",
75332 + .data = &grsec_enable_execlog,
75333 + .maxlen = sizeof(int),
75334 + .mode = 0600,
75335 + .proc_handler = &proc_dointvec,
75336 + },
75337 +#endif
75338 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75339 + {
75340 + .procname = "rwxmap_logging",
75341 + .data = &grsec_enable_log_rwxmaps,
75342 + .maxlen = sizeof(int),
75343 + .mode = 0600,
75344 + .proc_handler = &proc_dointvec,
75345 + },
75346 +#endif
75347 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75348 + {
75349 + .procname = "signal_logging",
75350 + .data = &grsec_enable_signal,
75351 + .maxlen = sizeof(int),
75352 + .mode = 0600,
75353 + .proc_handler = &proc_dointvec,
75354 + },
75355 +#endif
75356 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
75357 + {
75358 + .procname = "forkfail_logging",
75359 + .data = &grsec_enable_forkfail,
75360 + .maxlen = sizeof(int),
75361 + .mode = 0600,
75362 + .proc_handler = &proc_dointvec,
75363 + },
75364 +#endif
75365 +#ifdef CONFIG_GRKERNSEC_TIME
75366 + {
75367 + .procname = "timechange_logging",
75368 + .data = &grsec_enable_time,
75369 + .maxlen = sizeof(int),
75370 + .mode = 0600,
75371 + .proc_handler = &proc_dointvec,
75372 + },
75373 +#endif
75374 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75375 + {
75376 + .procname = "chroot_deny_shmat",
75377 + .data = &grsec_enable_chroot_shmat,
75378 + .maxlen = sizeof(int),
75379 + .mode = 0600,
75380 + .proc_handler = &proc_dointvec,
75381 + },
75382 +#endif
75383 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75384 + {
75385 + .procname = "chroot_deny_unix",
75386 + .data = &grsec_enable_chroot_unix,
75387 + .maxlen = sizeof(int),
75388 + .mode = 0600,
75389 + .proc_handler = &proc_dointvec,
75390 + },
75391 +#endif
75392 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75393 + {
75394 + .procname = "chroot_deny_mount",
75395 + .data = &grsec_enable_chroot_mount,
75396 + .maxlen = sizeof(int),
75397 + .mode = 0600,
75398 + .proc_handler = &proc_dointvec,
75399 + },
75400 +#endif
75401 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75402 + {
75403 + .procname = "chroot_deny_fchdir",
75404 + .data = &grsec_enable_chroot_fchdir,
75405 + .maxlen = sizeof(int),
75406 + .mode = 0600,
75407 + .proc_handler = &proc_dointvec,
75408 + },
75409 +#endif
75410 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75411 + {
75412 + .procname = "chroot_deny_chroot",
75413 + .data = &grsec_enable_chroot_double,
75414 + .maxlen = sizeof(int),
75415 + .mode = 0600,
75416 + .proc_handler = &proc_dointvec,
75417 + },
75418 +#endif
75419 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75420 + {
75421 + .procname = "chroot_deny_pivot",
75422 + .data = &grsec_enable_chroot_pivot,
75423 + .maxlen = sizeof(int),
75424 + .mode = 0600,
75425 + .proc_handler = &proc_dointvec,
75426 + },
75427 +#endif
75428 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75429 + {
75430 + .procname = "chroot_enforce_chdir",
75431 + .data = &grsec_enable_chroot_chdir,
75432 + .maxlen = sizeof(int),
75433 + .mode = 0600,
75434 + .proc_handler = &proc_dointvec,
75435 + },
75436 +#endif
75437 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75438 + {
75439 + .procname = "chroot_deny_chmod",
75440 + .data = &grsec_enable_chroot_chmod,
75441 + .maxlen = sizeof(int),
75442 + .mode = 0600,
75443 + .proc_handler = &proc_dointvec,
75444 + },
75445 +#endif
75446 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75447 + {
75448 + .procname = "chroot_deny_mknod",
75449 + .data = &grsec_enable_chroot_mknod,
75450 + .maxlen = sizeof(int),
75451 + .mode = 0600,
75452 + .proc_handler = &proc_dointvec,
75453 + },
75454 +#endif
75455 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75456 + {
75457 + .procname = "chroot_restrict_nice",
75458 + .data = &grsec_enable_chroot_nice,
75459 + .maxlen = sizeof(int),
75460 + .mode = 0600,
75461 + .proc_handler = &proc_dointvec,
75462 + },
75463 +#endif
75464 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75465 + {
75466 + .procname = "chroot_execlog",
75467 + .data = &grsec_enable_chroot_execlog,
75468 + .maxlen = sizeof(int),
75469 + .mode = 0600,
75470 + .proc_handler = &proc_dointvec,
75471 + },
75472 +#endif
75473 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75474 + {
75475 + .procname = "chroot_caps",
75476 + .data = &grsec_enable_chroot_caps,
75477 + .maxlen = sizeof(int),
75478 + .mode = 0600,
75479 + .proc_handler = &proc_dointvec,
75480 + },
75481 +#endif
75482 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75483 + {
75484 + .procname = "chroot_deny_sysctl",
75485 + .data = &grsec_enable_chroot_sysctl,
75486 + .maxlen = sizeof(int),
75487 + .mode = 0600,
75488 + .proc_handler = &proc_dointvec,
75489 + },
75490 +#endif
75491 +#ifdef CONFIG_GRKERNSEC_TPE
75492 + {
75493 + .procname = "tpe",
75494 + .data = &grsec_enable_tpe,
75495 + .maxlen = sizeof(int),
75496 + .mode = 0600,
75497 + .proc_handler = &proc_dointvec,
75498 + },
75499 + {
75500 + .procname = "tpe_gid",
75501 + .data = &grsec_tpe_gid,
75502 + .maxlen = sizeof(int),
75503 + .mode = 0600,
75504 + .proc_handler = &proc_dointvec,
75505 + },
75506 +#endif
75507 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75508 + {
75509 + .procname = "tpe_invert",
75510 + .data = &grsec_enable_tpe_invert,
75511 + .maxlen = sizeof(int),
75512 + .mode = 0600,
75513 + .proc_handler = &proc_dointvec,
75514 + },
75515 +#endif
75516 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75517 + {
75518 + .procname = "tpe_restrict_all",
75519 + .data = &grsec_enable_tpe_all,
75520 + .maxlen = sizeof(int),
75521 + .mode = 0600,
75522 + .proc_handler = &proc_dointvec,
75523 + },
75524 +#endif
75525 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75526 + {
75527 + .procname = "socket_all",
75528 + .data = &grsec_enable_socket_all,
75529 + .maxlen = sizeof(int),
75530 + .mode = 0600,
75531 + .proc_handler = &proc_dointvec,
75532 + },
75533 + {
75534 + .procname = "socket_all_gid",
75535 + .data = &grsec_socket_all_gid,
75536 + .maxlen = sizeof(int),
75537 + .mode = 0600,
75538 + .proc_handler = &proc_dointvec,
75539 + },
75540 +#endif
75541 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75542 + {
75543 + .procname = "socket_client",
75544 + .data = &grsec_enable_socket_client,
75545 + .maxlen = sizeof(int),
75546 + .mode = 0600,
75547 + .proc_handler = &proc_dointvec,
75548 + },
75549 + {
75550 + .procname = "socket_client_gid",
75551 + .data = &grsec_socket_client_gid,
75552 + .maxlen = sizeof(int),
75553 + .mode = 0600,
75554 + .proc_handler = &proc_dointvec,
75555 + },
75556 +#endif
75557 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75558 + {
75559 + .procname = "socket_server",
75560 + .data = &grsec_enable_socket_server,
75561 + .maxlen = sizeof(int),
75562 + .mode = 0600,
75563 + .proc_handler = &proc_dointvec,
75564 + },
75565 + {
75566 + .procname = "socket_server_gid",
75567 + .data = &grsec_socket_server_gid,
75568 + .maxlen = sizeof(int),
75569 + .mode = 0600,
75570 + .proc_handler = &proc_dointvec,
75571 + },
75572 +#endif
75573 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75574 + {
75575 + .procname = "audit_group",
75576 + .data = &grsec_enable_group,
75577 + .maxlen = sizeof(int),
75578 + .mode = 0600,
75579 + .proc_handler = &proc_dointvec,
75580 + },
75581 + {
75582 + .procname = "audit_gid",
75583 + .data = &grsec_audit_gid,
75584 + .maxlen = sizeof(int),
75585 + .mode = 0600,
75586 + .proc_handler = &proc_dointvec,
75587 + },
75588 +#endif
75589 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75590 + {
75591 + .procname = "audit_chdir",
75592 + .data = &grsec_enable_chdir,
75593 + .maxlen = sizeof(int),
75594 + .mode = 0600,
75595 + .proc_handler = &proc_dointvec,
75596 + },
75597 +#endif
75598 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75599 + {
75600 + .procname = "audit_mount",
75601 + .data = &grsec_enable_mount,
75602 + .maxlen = sizeof(int),
75603 + .mode = 0600,
75604 + .proc_handler = &proc_dointvec,
75605 + },
75606 +#endif
75607 +#ifdef CONFIG_GRKERNSEC_DMESG
75608 + {
75609 + .procname = "dmesg",
75610 + .data = &grsec_enable_dmesg,
75611 + .maxlen = sizeof(int),
75612 + .mode = 0600,
75613 + .proc_handler = &proc_dointvec,
75614 + },
75615 +#endif
75616 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75617 + {
75618 + .procname = "chroot_findtask",
75619 + .data = &grsec_enable_chroot_findtask,
75620 + .maxlen = sizeof(int),
75621 + .mode = 0600,
75622 + .proc_handler = &proc_dointvec,
75623 + },
75624 +#endif
75625 +#ifdef CONFIG_GRKERNSEC_RESLOG
75626 + {
75627 + .procname = "resource_logging",
75628 + .data = &grsec_resource_logging,
75629 + .maxlen = sizeof(int),
75630 + .mode = 0600,
75631 + .proc_handler = &proc_dointvec,
75632 + },
75633 +#endif
75634 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75635 + {
75636 + .procname = "audit_ptrace",
75637 + .data = &grsec_enable_audit_ptrace,
75638 + .maxlen = sizeof(int),
75639 + .mode = 0600,
75640 + .proc_handler = &proc_dointvec,
75641 + },
75642 +#endif
75643 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75644 + {
75645 + .procname = "harden_ptrace",
75646 + .data = &grsec_enable_harden_ptrace,
75647 + .maxlen = sizeof(int),
75648 + .mode = 0600,
75649 + .proc_handler = &proc_dointvec,
75650 + },
75651 +#endif
75652 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75653 + {
75654 + .procname = "harden_ipc",
75655 + .data = &grsec_enable_harden_ipc,
75656 + .maxlen = sizeof(int),
75657 + .mode = 0600,
75658 + .proc_handler = &proc_dointvec,
75659 + },
75660 +#endif
75661 + {
75662 + .procname = "grsec_lock",
75663 + .data = &grsec_lock,
75664 + .maxlen = sizeof(int),
75665 + .mode = 0600,
75666 + .proc_handler = &proc_dointvec,
75667 + },
75668 +#endif
75669 +#ifdef CONFIG_GRKERNSEC_ROFS
75670 + {
75671 + .procname = "romount_protect",
75672 + .data = &grsec_enable_rofs,
75673 + .maxlen = sizeof(int),
75674 + .mode = 0600,
75675 + .proc_handler = &proc_dointvec_minmax,
75676 + .extra1 = &one,
75677 + .extra2 = &one,
75678 + },
75679 +#endif
75680 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
75681 + {
75682 + .procname = "deny_new_usb",
75683 + .data = &grsec_deny_new_usb,
75684 + .maxlen = sizeof(int),
75685 + .mode = 0600,
75686 + .proc_handler = &proc_dointvec,
75687 + },
75688 +#endif
75689 + { }
75690 +};
75691 +#endif
75692 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
75693 new file mode 100644
75694 index 0000000..61b514e
75695 --- /dev/null
75696 +++ b/grsecurity/grsec_time.c
75697 @@ -0,0 +1,16 @@
75698 +#include <linux/kernel.h>
75699 +#include <linux/sched.h>
75700 +#include <linux/grinternal.h>
75701 +#include <linux/module.h>
75702 +
75703 +void
75704 +gr_log_timechange(void)
75705 +{
75706 +#ifdef CONFIG_GRKERNSEC_TIME
75707 + if (grsec_enable_time)
75708 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
75709 +#endif
75710 + return;
75711 +}
75712 +
75713 +EXPORT_SYMBOL_GPL(gr_log_timechange);
75714 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
75715 new file mode 100644
75716 index 0000000..ee57dcf
75717 --- /dev/null
75718 +++ b/grsecurity/grsec_tpe.c
75719 @@ -0,0 +1,73 @@
75720 +#include <linux/kernel.h>
75721 +#include <linux/sched.h>
75722 +#include <linux/file.h>
75723 +#include <linux/fs.h>
75724 +#include <linux/grinternal.h>
75725 +
75726 +extern int gr_acl_tpe_check(void);
75727 +
75728 +int
75729 +gr_tpe_allow(const struct file *file)
75730 +{
75731 +#ifdef CONFIG_GRKERNSEC
75732 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
75733 + const struct cred *cred = current_cred();
75734 + char *msg = NULL;
75735 + char *msg2 = NULL;
75736 +
75737 + // never restrict root
75738 + if (gr_is_global_root(cred->uid))
75739 + return 1;
75740 +
75741 + if (grsec_enable_tpe) {
75742 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75743 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
75744 + msg = "not being in trusted group";
75745 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
75746 + msg = "being in untrusted group";
75747 +#else
75748 + if (in_group_p(grsec_tpe_gid))
75749 + msg = "being in untrusted group";
75750 +#endif
75751 + }
75752 + if (!msg && gr_acl_tpe_check())
75753 + msg = "being in untrusted role";
75754 +
75755 + // not in any affected group/role
75756 + if (!msg)
75757 + goto next_check;
75758 +
75759 + if (gr_is_global_nonroot(inode->i_uid))
75760 + msg2 = "file in non-root-owned directory";
75761 + else if (inode->i_mode & S_IWOTH)
75762 + msg2 = "file in world-writable directory";
75763 + else if (inode->i_mode & S_IWGRP)
75764 + msg2 = "file in group-writable directory";
75765 +
75766 + if (msg && msg2) {
75767 + char fullmsg[70] = {0};
75768 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
75769 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
75770 + return 0;
75771 + }
75772 + msg = NULL;
75773 +next_check:
75774 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
75775 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
75776 + return 1;
75777 +
75778 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
75779 + msg = "directory not owned by user";
75780 + else if (inode->i_mode & S_IWOTH)
75781 + msg = "file in world-writable directory";
75782 + else if (inode->i_mode & S_IWGRP)
75783 + msg = "file in group-writable directory";
75784 +
75785 + if (msg) {
75786 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
75787 + return 0;
75788 + }
75789 +#endif
75790 +#endif
75791 + return 1;
75792 +}
75793 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
75794 new file mode 100644
75795 index 0000000..ae02d8e
75796 --- /dev/null
75797 +++ b/grsecurity/grsec_usb.c
75798 @@ -0,0 +1,15 @@
75799 +#include <linux/kernel.h>
75800 +#include <linux/grinternal.h>
75801 +#include <linux/module.h>
75802 +
75803 +int gr_handle_new_usb(void)
75804 +{
75805 +#ifdef CONFIG_GRKERNSEC_DENYUSB
75806 + if (grsec_deny_new_usb) {
75807 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
75808 + return 1;
75809 + }
75810 +#endif
75811 + return 0;
75812 +}
75813 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
75814 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
75815 new file mode 100644
75816 index 0000000..9f7b1ac
75817 --- /dev/null
75818 +++ b/grsecurity/grsum.c
75819 @@ -0,0 +1,61 @@
75820 +#include <linux/err.h>
75821 +#include <linux/kernel.h>
75822 +#include <linux/sched.h>
75823 +#include <linux/mm.h>
75824 +#include <linux/scatterlist.h>
75825 +#include <linux/crypto.h>
75826 +#include <linux/gracl.h>
75827 +
75828 +
75829 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
75830 +#error "crypto and sha256 must be built into the kernel"
75831 +#endif
75832 +
75833 +int
75834 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
75835 +{
75836 + char *p;
75837 + struct crypto_hash *tfm;
75838 + struct hash_desc desc;
75839 + struct scatterlist sg;
75840 + unsigned char temp_sum[GR_SHA_LEN];
75841 + volatile int retval = 0;
75842 + volatile int dummy = 0;
75843 + unsigned int i;
75844 +
75845 + sg_init_table(&sg, 1);
75846 +
75847 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
75848 + if (IS_ERR(tfm)) {
75849 + /* should never happen, since sha256 should be built in */
75850 + return 1;
75851 + }
75852 +
75853 + desc.tfm = tfm;
75854 + desc.flags = 0;
75855 +
75856 + crypto_hash_init(&desc);
75857 +
75858 + p = salt;
75859 + sg_set_buf(&sg, p, GR_SALT_LEN);
75860 + crypto_hash_update(&desc, &sg, sg.length);
75861 +
75862 + p = entry->pw;
75863 + sg_set_buf(&sg, p, strlen(p));
75864 +
75865 + crypto_hash_update(&desc, &sg, sg.length);
75866 +
75867 + crypto_hash_final(&desc, temp_sum);
75868 +
75869 + memset(entry->pw, 0, GR_PW_LEN);
75870 +
75871 + for (i = 0; i < GR_SHA_LEN; i++)
75872 + if (sum[i] != temp_sum[i])
75873 + retval = 1;
75874 + else
75875 + dummy = 1; // waste a cycle
75876 +
75877 + crypto_free_hash(tfm);
75878 +
75879 + return retval;
75880 +}
75881 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
75882 index 77ff547..181834f 100644
75883 --- a/include/asm-generic/4level-fixup.h
75884 +++ b/include/asm-generic/4level-fixup.h
75885 @@ -13,8 +13,10 @@
75886 #define pmd_alloc(mm, pud, address) \
75887 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
75888 NULL: pmd_offset(pud, address))
75889 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
75890
75891 #define pud_alloc(mm, pgd, address) (pgd)
75892 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
75893 #define pud_offset(pgd, start) (pgd)
75894 #define pud_none(pud) 0
75895 #define pud_bad(pud) 0
75896 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
75897 index b7babf0..97f4c4f 100644
75898 --- a/include/asm-generic/atomic-long.h
75899 +++ b/include/asm-generic/atomic-long.h
75900 @@ -22,6 +22,12 @@
75901
75902 typedef atomic64_t atomic_long_t;
75903
75904 +#ifdef CONFIG_PAX_REFCOUNT
75905 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
75906 +#else
75907 +typedef atomic64_t atomic_long_unchecked_t;
75908 +#endif
75909 +
75910 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
75911
75912 static inline long atomic_long_read(atomic_long_t *l)
75913 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75914 return (long)atomic64_read(v);
75915 }
75916
75917 +#ifdef CONFIG_PAX_REFCOUNT
75918 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75919 +{
75920 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75921 +
75922 + return (long)atomic64_read_unchecked(v);
75923 +}
75924 +#endif
75925 +
75926 static inline void atomic_long_set(atomic_long_t *l, long i)
75927 {
75928 atomic64_t *v = (atomic64_t *)l;
75929 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75930 atomic64_set(v, i);
75931 }
75932
75933 +#ifdef CONFIG_PAX_REFCOUNT
75934 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75935 +{
75936 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75937 +
75938 + atomic64_set_unchecked(v, i);
75939 +}
75940 +#endif
75941 +
75942 static inline void atomic_long_inc(atomic_long_t *l)
75943 {
75944 atomic64_t *v = (atomic64_t *)l;
75945 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75946 atomic64_inc(v);
75947 }
75948
75949 +#ifdef CONFIG_PAX_REFCOUNT
75950 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75951 +{
75952 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75953 +
75954 + atomic64_inc_unchecked(v);
75955 +}
75956 +#endif
75957 +
75958 static inline void atomic_long_dec(atomic_long_t *l)
75959 {
75960 atomic64_t *v = (atomic64_t *)l;
75961 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75962 atomic64_dec(v);
75963 }
75964
75965 +#ifdef CONFIG_PAX_REFCOUNT
75966 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75967 +{
75968 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75969 +
75970 + atomic64_dec_unchecked(v);
75971 +}
75972 +#endif
75973 +
75974 static inline void atomic_long_add(long i, atomic_long_t *l)
75975 {
75976 atomic64_t *v = (atomic64_t *)l;
75977 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75978 atomic64_add(i, v);
75979 }
75980
75981 +#ifdef CONFIG_PAX_REFCOUNT
75982 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75983 +{
75984 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75985 +
75986 + atomic64_add_unchecked(i, v);
75987 +}
75988 +#endif
75989 +
75990 static inline void atomic_long_sub(long i, atomic_long_t *l)
75991 {
75992 atomic64_t *v = (atomic64_t *)l;
75993 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75994 atomic64_sub(i, v);
75995 }
75996
75997 +#ifdef CONFIG_PAX_REFCOUNT
75998 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75999 +{
76000 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76001 +
76002 + atomic64_sub_unchecked(i, v);
76003 +}
76004 +#endif
76005 +
76006 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76007 {
76008 atomic64_t *v = (atomic64_t *)l;
76009 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76010 return atomic64_add_negative(i, v);
76011 }
76012
76013 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
76014 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76015 {
76016 atomic64_t *v = (atomic64_t *)l;
76017
76018 return (long)atomic64_add_return(i, v);
76019 }
76020
76021 +#ifdef CONFIG_PAX_REFCOUNT
76022 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76023 +{
76024 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76025 +
76026 + return (long)atomic64_add_return_unchecked(i, v);
76027 +}
76028 +#endif
76029 +
76030 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76031 {
76032 atomic64_t *v = (atomic64_t *)l;
76033 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76034 return (long)atomic64_inc_return(v);
76035 }
76036
76037 +#ifdef CONFIG_PAX_REFCOUNT
76038 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76039 +{
76040 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76041 +
76042 + return (long)atomic64_inc_return_unchecked(v);
76043 +}
76044 +#endif
76045 +
76046 static inline long atomic_long_dec_return(atomic_long_t *l)
76047 {
76048 atomic64_t *v = (atomic64_t *)l;
76049 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76050
76051 typedef atomic_t atomic_long_t;
76052
76053 +#ifdef CONFIG_PAX_REFCOUNT
76054 +typedef atomic_unchecked_t atomic_long_unchecked_t;
76055 +#else
76056 +typedef atomic_t atomic_long_unchecked_t;
76057 +#endif
76058 +
76059 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76060 static inline long atomic_long_read(atomic_long_t *l)
76061 {
76062 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76063 return (long)atomic_read(v);
76064 }
76065
76066 +#ifdef CONFIG_PAX_REFCOUNT
76067 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76068 +{
76069 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76070 +
76071 + return (long)atomic_read_unchecked(v);
76072 +}
76073 +#endif
76074 +
76075 static inline void atomic_long_set(atomic_long_t *l, long i)
76076 {
76077 atomic_t *v = (atomic_t *)l;
76078 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76079 atomic_set(v, i);
76080 }
76081
76082 +#ifdef CONFIG_PAX_REFCOUNT
76083 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76084 +{
76085 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76086 +
76087 + atomic_set_unchecked(v, i);
76088 +}
76089 +#endif
76090 +
76091 static inline void atomic_long_inc(atomic_long_t *l)
76092 {
76093 atomic_t *v = (atomic_t *)l;
76094 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76095 atomic_inc(v);
76096 }
76097
76098 +#ifdef CONFIG_PAX_REFCOUNT
76099 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76100 +{
76101 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76102 +
76103 + atomic_inc_unchecked(v);
76104 +}
76105 +#endif
76106 +
76107 static inline void atomic_long_dec(atomic_long_t *l)
76108 {
76109 atomic_t *v = (atomic_t *)l;
76110 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76111 atomic_dec(v);
76112 }
76113
76114 +#ifdef CONFIG_PAX_REFCOUNT
76115 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76116 +{
76117 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76118 +
76119 + atomic_dec_unchecked(v);
76120 +}
76121 +#endif
76122 +
76123 static inline void atomic_long_add(long i, atomic_long_t *l)
76124 {
76125 atomic_t *v = (atomic_t *)l;
76126 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76127 atomic_add(i, v);
76128 }
76129
76130 +#ifdef CONFIG_PAX_REFCOUNT
76131 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76132 +{
76133 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76134 +
76135 + atomic_add_unchecked(i, v);
76136 +}
76137 +#endif
76138 +
76139 static inline void atomic_long_sub(long i, atomic_long_t *l)
76140 {
76141 atomic_t *v = (atomic_t *)l;
76142 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76143 atomic_sub(i, v);
76144 }
76145
76146 +#ifdef CONFIG_PAX_REFCOUNT
76147 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76148 +{
76149 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76150 +
76151 + atomic_sub_unchecked(i, v);
76152 +}
76153 +#endif
76154 +
76155 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76156 {
76157 atomic_t *v = (atomic_t *)l;
76158 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76159 return (long)atomic_add_return(i, v);
76160 }
76161
76162 +#ifdef CONFIG_PAX_REFCOUNT
76163 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76164 +{
76165 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76166 +
76167 + return (long)atomic_add_return_unchecked(i, v);
76168 +}
76169 +
76170 +#endif
76171 +
76172 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76173 {
76174 atomic_t *v = (atomic_t *)l;
76175 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76176 return (long)atomic_inc_return(v);
76177 }
76178
76179 +#ifdef CONFIG_PAX_REFCOUNT
76180 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76181 +{
76182 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76183 +
76184 + return (long)atomic_inc_return_unchecked(v);
76185 +}
76186 +#endif
76187 +
76188 static inline long atomic_long_dec_return(atomic_long_t *l)
76189 {
76190 atomic_t *v = (atomic_t *)l;
76191 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76192
76193 #endif /* BITS_PER_LONG == 64 */
76194
76195 +#ifdef CONFIG_PAX_REFCOUNT
76196 +static inline void pax_refcount_needs_these_functions(void)
76197 +{
76198 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
76199 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76200 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76201 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76202 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76203 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76204 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76205 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76206 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76207 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76208 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76209 +#ifdef CONFIG_X86
76210 + atomic_clear_mask_unchecked(0, NULL);
76211 + atomic_set_mask_unchecked(0, NULL);
76212 +#endif
76213 +
76214 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76215 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76216 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76217 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76218 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76219 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76220 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76221 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76222 +}
76223 +#else
76224 +#define atomic_read_unchecked(v) atomic_read(v)
76225 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76226 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76227 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76228 +#define atomic_inc_unchecked(v) atomic_inc(v)
76229 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76230 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76231 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76232 +#define atomic_dec_unchecked(v) atomic_dec(v)
76233 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76234 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76235 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76236 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76237 +
76238 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
76239 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76240 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76241 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76242 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76243 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76244 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76245 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76246 +#endif
76247 +
76248 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76249 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76250 index 33bd2de..f31bff97 100644
76251 --- a/include/asm-generic/atomic.h
76252 +++ b/include/asm-generic/atomic.h
76253 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76254 * Atomically clears the bits set in @mask from @v
76255 */
76256 #ifndef atomic_clear_mask
76257 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76258 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76259 {
76260 unsigned long flags;
76261
76262 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76263 index b18ce4f..2ee2843 100644
76264 --- a/include/asm-generic/atomic64.h
76265 +++ b/include/asm-generic/atomic64.h
76266 @@ -16,6 +16,8 @@ typedef struct {
76267 long long counter;
76268 } atomic64_t;
76269
76270 +typedef atomic64_t atomic64_unchecked_t;
76271 +
76272 #define ATOMIC64_INIT(i) { (i) }
76273
76274 extern long long atomic64_read(const atomic64_t *v);
76275 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76276 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76277 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76278
76279 +#define atomic64_read_unchecked(v) atomic64_read(v)
76280 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76281 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76282 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76283 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76284 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
76285 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76286 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
76287 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76288 +
76289 #endif /* _ASM_GENERIC_ATOMIC64_H */
76290 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76291 index a60a7cc..0fe12f2 100644
76292 --- a/include/asm-generic/bitops/__fls.h
76293 +++ b/include/asm-generic/bitops/__fls.h
76294 @@ -9,7 +9,7 @@
76295 *
76296 * Undefined if no set bit exists, so code should check against 0 first.
76297 */
76298 -static __always_inline unsigned long __fls(unsigned long word)
76299 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76300 {
76301 int num = BITS_PER_LONG - 1;
76302
76303 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76304 index 0576d1f..dad6c71 100644
76305 --- a/include/asm-generic/bitops/fls.h
76306 +++ b/include/asm-generic/bitops/fls.h
76307 @@ -9,7 +9,7 @@
76308 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76309 */
76310
76311 -static __always_inline int fls(int x)
76312 +static __always_inline int __intentional_overflow(-1) fls(int x)
76313 {
76314 int r = 32;
76315
76316 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76317 index b097cf8..3d40e14 100644
76318 --- a/include/asm-generic/bitops/fls64.h
76319 +++ b/include/asm-generic/bitops/fls64.h
76320 @@ -15,7 +15,7 @@
76321 * at position 64.
76322 */
76323 #if BITS_PER_LONG == 32
76324 -static __always_inline int fls64(__u64 x)
76325 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76326 {
76327 __u32 h = x >> 32;
76328 if (h)
76329 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76330 return fls(x);
76331 }
76332 #elif BITS_PER_LONG == 64
76333 -static __always_inline int fls64(__u64 x)
76334 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76335 {
76336 if (x == 0)
76337 return 0;
76338 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76339 index 1bfcfe5..e04c5c9 100644
76340 --- a/include/asm-generic/cache.h
76341 +++ b/include/asm-generic/cache.h
76342 @@ -6,7 +6,7 @@
76343 * cache lines need to provide their own cache.h.
76344 */
76345
76346 -#define L1_CACHE_SHIFT 5
76347 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76348 +#define L1_CACHE_SHIFT 5UL
76349 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76350
76351 #endif /* __ASM_GENERIC_CACHE_H */
76352 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76353 index 0d68a1e..b74a761 100644
76354 --- a/include/asm-generic/emergency-restart.h
76355 +++ b/include/asm-generic/emergency-restart.h
76356 @@ -1,7 +1,7 @@
76357 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76358 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76359
76360 -static inline void machine_emergency_restart(void)
76361 +static inline __noreturn void machine_emergency_restart(void)
76362 {
76363 machine_restart(NULL);
76364 }
76365 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76366 index 90f99c7..00ce236 100644
76367 --- a/include/asm-generic/kmap_types.h
76368 +++ b/include/asm-generic/kmap_types.h
76369 @@ -2,9 +2,9 @@
76370 #define _ASM_GENERIC_KMAP_TYPES_H
76371
76372 #ifdef __WITH_KM_FENCE
76373 -# define KM_TYPE_NR 41
76374 +# define KM_TYPE_NR 42
76375 #else
76376 -# define KM_TYPE_NR 20
76377 +# define KM_TYPE_NR 21
76378 #endif
76379
76380 #endif
76381 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76382 index 9ceb03b..62b0b8f 100644
76383 --- a/include/asm-generic/local.h
76384 +++ b/include/asm-generic/local.h
76385 @@ -23,24 +23,37 @@ typedef struct
76386 atomic_long_t a;
76387 } local_t;
76388
76389 +typedef struct {
76390 + atomic_long_unchecked_t a;
76391 +} local_unchecked_t;
76392 +
76393 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
76394
76395 #define local_read(l) atomic_long_read(&(l)->a)
76396 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
76397 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
76398 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
76399 #define local_inc(l) atomic_long_inc(&(l)->a)
76400 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
76401 #define local_dec(l) atomic_long_dec(&(l)->a)
76402 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
76403 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
76404 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
76405 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
76406 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
76407
76408 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
76409 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
76410 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
76411 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
76412 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
76413 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
76414 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
76415 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
76416 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
76417
76418 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76419 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76420 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
76421 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
76422 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
76423 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
76424 index 725612b..9cc513a 100644
76425 --- a/include/asm-generic/pgtable-nopmd.h
76426 +++ b/include/asm-generic/pgtable-nopmd.h
76427 @@ -1,14 +1,19 @@
76428 #ifndef _PGTABLE_NOPMD_H
76429 #define _PGTABLE_NOPMD_H
76430
76431 -#ifndef __ASSEMBLY__
76432 -
76433 #include <asm-generic/pgtable-nopud.h>
76434
76435 -struct mm_struct;
76436 -
76437 #define __PAGETABLE_PMD_FOLDED
76438
76439 +#define PMD_SHIFT PUD_SHIFT
76440 +#define PTRS_PER_PMD 1
76441 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
76442 +#define PMD_MASK (~(PMD_SIZE-1))
76443 +
76444 +#ifndef __ASSEMBLY__
76445 +
76446 +struct mm_struct;
76447 +
76448 /*
76449 * Having the pmd type consist of a pud gets the size right, and allows
76450 * us to conceptually access the pud entry that this pmd is folded into
76451 @@ -16,11 +21,6 @@ struct mm_struct;
76452 */
76453 typedef struct { pud_t pud; } pmd_t;
76454
76455 -#define PMD_SHIFT PUD_SHIFT
76456 -#define PTRS_PER_PMD 1
76457 -#define PMD_SIZE (1UL << PMD_SHIFT)
76458 -#define PMD_MASK (~(PMD_SIZE-1))
76459 -
76460 /*
76461 * The "pud_xxx()" functions here are trivial for a folded two-level
76462 * setup: the pmd is never bad, and a pmd always exists (as it's folded
76463 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
76464 index 810431d..0ec4804f 100644
76465 --- a/include/asm-generic/pgtable-nopud.h
76466 +++ b/include/asm-generic/pgtable-nopud.h
76467 @@ -1,10 +1,15 @@
76468 #ifndef _PGTABLE_NOPUD_H
76469 #define _PGTABLE_NOPUD_H
76470
76471 -#ifndef __ASSEMBLY__
76472 -
76473 #define __PAGETABLE_PUD_FOLDED
76474
76475 +#define PUD_SHIFT PGDIR_SHIFT
76476 +#define PTRS_PER_PUD 1
76477 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
76478 +#define PUD_MASK (~(PUD_SIZE-1))
76479 +
76480 +#ifndef __ASSEMBLY__
76481 +
76482 /*
76483 * Having the pud type consist of a pgd gets the size right, and allows
76484 * us to conceptually access the pgd entry that this pud is folded into
76485 @@ -12,11 +17,6 @@
76486 */
76487 typedef struct { pgd_t pgd; } pud_t;
76488
76489 -#define PUD_SHIFT PGDIR_SHIFT
76490 -#define PTRS_PER_PUD 1
76491 -#define PUD_SIZE (1UL << PUD_SHIFT)
76492 -#define PUD_MASK (~(PUD_SIZE-1))
76493 -
76494 /*
76495 * The "pgd_xxx()" functions here are trivial for a folded two-level
76496 * setup: the pud is never bad, and a pud always exists (as it's folded
76497 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
76498 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
76499
76500 #define pgd_populate(mm, pgd, pud) do { } while (0)
76501 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
76502 /*
76503 * (puds are folded into pgds so this doesn't get actually called,
76504 * but the define is needed for a generic inline function.)
76505 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
76506 index 34c7bdc..38d4f3b 100644
76507 --- a/include/asm-generic/pgtable.h
76508 +++ b/include/asm-generic/pgtable.h
76509 @@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
76510 }
76511 #endif /* CONFIG_NUMA_BALANCING */
76512
76513 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
76514 +#ifdef CONFIG_PAX_KERNEXEC
76515 +#error KERNEXEC requires pax_open_kernel
76516 +#else
76517 +static inline unsigned long pax_open_kernel(void) { return 0; }
76518 +#endif
76519 +#endif
76520 +
76521 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
76522 +#ifdef CONFIG_PAX_KERNEXEC
76523 +#error KERNEXEC requires pax_close_kernel
76524 +#else
76525 +static inline unsigned long pax_close_kernel(void) { return 0; }
76526 +#endif
76527 +#endif
76528 +
76529 #endif /* CONFIG_MMU */
76530
76531 #endif /* !__ASSEMBLY__ */
76532 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
76533 index 72d8803..cb9749c 100644
76534 --- a/include/asm-generic/uaccess.h
76535 +++ b/include/asm-generic/uaccess.h
76536 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
76537 return __clear_user(to, n);
76538 }
76539
76540 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
76541 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76542 +#error UDEREF requires pax_open_userland
76543 +#else
76544 +static inline unsigned long pax_open_userland(void) { return 0; }
76545 +#endif
76546 +#endif
76547 +
76548 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
76549 +#ifdef CONFIG_PAX_MEMORY_UDEREF
76550 +#error UDEREF requires pax_close_userland
76551 +#else
76552 +static inline unsigned long pax_close_userland(void) { return 0; }
76553 +#endif
76554 +#endif
76555 +
76556 #endif /* __ASM_GENERIC_UACCESS_H */
76557 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
76558 index bc2121f..2f41f9a 100644
76559 --- a/include/asm-generic/vmlinux.lds.h
76560 +++ b/include/asm-generic/vmlinux.lds.h
76561 @@ -232,6 +232,7 @@
76562 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
76563 VMLINUX_SYMBOL(__start_rodata) = .; \
76564 *(.rodata) *(.rodata.*) \
76565 + *(.data..read_only) \
76566 *(__vermagic) /* Kernel version magic */ \
76567 . = ALIGN(8); \
76568 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
76569 @@ -716,17 +717,18 @@
76570 * section in the linker script will go there too. @phdr should have
76571 * a leading colon.
76572 *
76573 - * Note that this macros defines __per_cpu_load as an absolute symbol.
76574 + * Note that this macros defines per_cpu_load as an absolute symbol.
76575 * If there is no need to put the percpu section at a predetermined
76576 * address, use PERCPU_SECTION.
76577 */
76578 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
76579 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
76580 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
76581 + per_cpu_load = .; \
76582 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
76583 - LOAD_OFFSET) { \
76584 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
76585 PERCPU_INPUT(cacheline) \
76586 } phdr \
76587 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
76588 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
76589
76590 /**
76591 * PERCPU_SECTION - define output section for percpu area, simple version
76592 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
76593 index e73c19e..5b89e00 100644
76594 --- a/include/crypto/algapi.h
76595 +++ b/include/crypto/algapi.h
76596 @@ -34,7 +34,7 @@ struct crypto_type {
76597 unsigned int maskclear;
76598 unsigned int maskset;
76599 unsigned int tfmsize;
76600 -};
76601 +} __do_const;
76602
76603 struct crypto_instance {
76604 struct crypto_alg alg;
76605 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
76606 index 04a7f31..668d424 100644
76607 --- a/include/drm/drmP.h
76608 +++ b/include/drm/drmP.h
76609 @@ -67,6 +67,7 @@
76610 #include <linux/workqueue.h>
76611 #include <linux/poll.h>
76612 #include <asm/pgalloc.h>
76613 +#include <asm/local.h>
76614 #include <drm/drm.h>
76615 #include <drm/drm_sarea.h>
76616 #include <drm/drm_vma_manager.h>
76617 @@ -297,10 +298,12 @@ do { \
76618 * \param cmd command.
76619 * \param arg argument.
76620 */
76621 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
76622 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
76623 + struct drm_file *file_priv);
76624 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
76625 struct drm_file *file_priv);
76626
76627 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76628 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
76629 unsigned long arg);
76630
76631 #define DRM_IOCTL_NR(n) _IOC_NR(n)
76632 @@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76633 struct drm_ioctl_desc {
76634 unsigned int cmd;
76635 int flags;
76636 - drm_ioctl_t *func;
76637 + drm_ioctl_t func;
76638 unsigned int cmd_drv;
76639 const char *name;
76640 -};
76641 +} __do_const;
76642
76643 /**
76644 * Creates a driver or general drm_ioctl_desc array entry for the given
76645 @@ -1022,7 +1025,8 @@ struct drm_info_list {
76646 int (*show)(struct seq_file*, void*); /** show callback */
76647 u32 driver_features; /**< Required driver features for this entry */
76648 void *data;
76649 -};
76650 +} __do_const;
76651 +typedef struct drm_info_list __no_const drm_info_list_no_const;
76652
76653 /**
76654 * debugfs node structure. This structure represents a debugfs file.
76655 @@ -1106,7 +1110,7 @@ struct drm_device {
76656
76657 /** \name Usage Counters */
76658 /*@{ */
76659 - int open_count; /**< Outstanding files open */
76660 + local_t open_count; /**< Outstanding files open */
76661 int buf_use; /**< Buffers in use -- cannot alloc */
76662 atomic_t buf_alloc; /**< Buffer allocation in progress */
76663 /*@} */
76664 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
76665 index b1388b5..e1d1163 100644
76666 --- a/include/drm/drm_crtc_helper.h
76667 +++ b/include/drm/drm_crtc_helper.h
76668 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
76669 struct drm_connector *connector);
76670 /* disable encoder when not in use - more explicit than dpms off */
76671 void (*disable)(struct drm_encoder *encoder);
76672 -};
76673 +} __no_const;
76674
76675 /**
76676 * drm_connector_helper_funcs - helper operations for connectors
76677 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
76678 index 940ece4..8cb727f 100644
76679 --- a/include/drm/i915_pciids.h
76680 +++ b/include/drm/i915_pciids.h
76681 @@ -37,7 +37,7 @@
76682 */
76683 #define INTEL_VGA_DEVICE(id, info) { \
76684 0x8086, id, \
76685 - ~0, ~0, \
76686 + PCI_ANY_ID, PCI_ANY_ID, \
76687 0x030000, 0xff0000, \
76688 (unsigned long) info }
76689
76690 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
76691 index 72dcbe8..8db58d7 100644
76692 --- a/include/drm/ttm/ttm_memory.h
76693 +++ b/include/drm/ttm/ttm_memory.h
76694 @@ -48,7 +48,7 @@
76695
76696 struct ttm_mem_shrink {
76697 int (*do_shrink) (struct ttm_mem_shrink *);
76698 -};
76699 +} __no_const;
76700
76701 /**
76702 * struct ttm_mem_global - Global memory accounting structure.
76703 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
76704 index 49a8284..9643967 100644
76705 --- a/include/drm/ttm/ttm_page_alloc.h
76706 +++ b/include/drm/ttm/ttm_page_alloc.h
76707 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
76708 */
76709 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
76710
76711 +struct device;
76712 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76713 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76714
76715 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
76716 index 4b840e8..155d235 100644
76717 --- a/include/keys/asymmetric-subtype.h
76718 +++ b/include/keys/asymmetric-subtype.h
76719 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
76720 /* Verify the signature on a key of this subtype (optional) */
76721 int (*verify_signature)(const struct key *key,
76722 const struct public_key_signature *sig);
76723 -};
76724 +} __do_const;
76725
76726 /**
76727 * asymmetric_key_subtype - Get the subtype from an asymmetric key
76728 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
76729 index c1da539..1dcec55 100644
76730 --- a/include/linux/atmdev.h
76731 +++ b/include/linux/atmdev.h
76732 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
76733 #endif
76734
76735 struct k_atm_aal_stats {
76736 -#define __HANDLE_ITEM(i) atomic_t i
76737 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
76738 __AAL_STAT_ITEMS
76739 #undef __HANDLE_ITEM
76740 };
76741 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
76742 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
76743 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
76744 struct module *owner;
76745 -};
76746 +} __do_const ;
76747
76748 struct atmphy_ops {
76749 int (*start)(struct atm_dev *dev);
76750 diff --git a/include/linux/audit.h b/include/linux/audit.h
76751 index ec1464d..833274b 100644
76752 --- a/include/linux/audit.h
76753 +++ b/include/linux/audit.h
76754 @@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
76755 extern unsigned int audit_serial(void);
76756 extern int auditsc_get_stamp(struct audit_context *ctx,
76757 struct timespec *t, unsigned int *serial);
76758 -extern int audit_set_loginuid(kuid_t loginuid);
76759 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
76760
76761 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
76762 {
76763 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
76764 index b4a745d..e3c0942 100644
76765 --- a/include/linux/binfmts.h
76766 +++ b/include/linux/binfmts.h
76767 @@ -45,7 +45,7 @@ struct linux_binprm {
76768 unsigned interp_data;
76769 unsigned long loader, exec;
76770 char tcomm[TASK_COMM_LEN];
76771 -};
76772 +} __randomize_layout;
76773
76774 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
76775 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
76776 @@ -74,8 +74,10 @@ struct linux_binfmt {
76777 int (*load_binary)(struct linux_binprm *);
76778 int (*load_shlib)(struct file *);
76779 int (*core_dump)(struct coredump_params *cprm);
76780 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
76781 + void (*handle_mmap)(struct file *);
76782 unsigned long min_coredump; /* minimal dump size */
76783 -};
76784 +} __do_const __randomize_layout;
76785
76786 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
76787
76788 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
76789 index be5fd38..d71192a 100644
76790 --- a/include/linux/bitops.h
76791 +++ b/include/linux/bitops.h
76792 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
76793 * @word: value to rotate
76794 * @shift: bits to roll
76795 */
76796 -static inline __u32 rol32(__u32 word, unsigned int shift)
76797 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
76798 {
76799 return (word << shift) | (word >> (32 - shift));
76800 }
76801 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
76802 * @word: value to rotate
76803 * @shift: bits to roll
76804 */
76805 -static inline __u32 ror32(__u32 word, unsigned int shift)
76806 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
76807 {
76808 return (word >> shift) | (word << (32 - shift));
76809 }
76810 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
76811 return (__s32)(value << shift) >> shift;
76812 }
76813
76814 -static inline unsigned fls_long(unsigned long l)
76815 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
76816 {
76817 if (sizeof(l) == 4)
76818 return fls(l);
76819 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
76820 index 4afa4f8..1ed7824 100644
76821 --- a/include/linux/blkdev.h
76822 +++ b/include/linux/blkdev.h
76823 @@ -1572,7 +1572,7 @@ struct block_device_operations {
76824 /* this callback is with swap_lock and sometimes page table lock held */
76825 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
76826 struct module *owner;
76827 -};
76828 +} __do_const;
76829
76830 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
76831 unsigned long);
76832 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
76833 index afc1343..9735539 100644
76834 --- a/include/linux/blktrace_api.h
76835 +++ b/include/linux/blktrace_api.h
76836 @@ -25,7 +25,7 @@ struct blk_trace {
76837 struct dentry *dropped_file;
76838 struct dentry *msg_file;
76839 struct list_head running_list;
76840 - atomic_t dropped;
76841 + atomic_unchecked_t dropped;
76842 };
76843
76844 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
76845 diff --git a/include/linux/cache.h b/include/linux/cache.h
76846 index 17e7e82..1d7da26 100644
76847 --- a/include/linux/cache.h
76848 +++ b/include/linux/cache.h
76849 @@ -16,6 +16,14 @@
76850 #define __read_mostly
76851 #endif
76852
76853 +#ifndef __read_only
76854 +#ifdef CONFIG_PAX_KERNEXEC
76855 +#error KERNEXEC requires __read_only
76856 +#else
76857 +#define __read_only __read_mostly
76858 +#endif
76859 +#endif
76860 +
76861 #ifndef ____cacheline_aligned
76862 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
76863 #endif
76864 diff --git a/include/linux/capability.h b/include/linux/capability.h
76865 index a6ee1f9..e1ca49d 100644
76866 --- a/include/linux/capability.h
76867 +++ b/include/linux/capability.h
76868 @@ -212,8 +212,13 @@ extern bool capable(int cap);
76869 extern bool ns_capable(struct user_namespace *ns, int cap);
76870 extern bool inode_capable(const struct inode *inode, int cap);
76871 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
76872 +extern bool capable_nolog(int cap);
76873 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
76874 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
76875
76876 /* audit system wants to get cap info from files as well */
76877 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
76878
76879 +extern int is_privileged_binary(const struct dentry *dentry);
76880 +
76881 #endif /* !_LINUX_CAPABILITY_H */
76882 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
76883 index 8609d57..86e4d79 100644
76884 --- a/include/linux/cdrom.h
76885 +++ b/include/linux/cdrom.h
76886 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
76887
76888 /* driver specifications */
76889 const int capability; /* capability flags */
76890 - int n_minors; /* number of active minor devices */
76891 /* handle uniform packets for scsi type devices (scsi,atapi) */
76892 int (*generic_packet) (struct cdrom_device_info *,
76893 struct packet_command *);
76894 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
76895 index 4ce9056..86caac6 100644
76896 --- a/include/linux/cleancache.h
76897 +++ b/include/linux/cleancache.h
76898 @@ -31,7 +31,7 @@ struct cleancache_ops {
76899 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
76900 void (*invalidate_inode)(int, struct cleancache_filekey);
76901 void (*invalidate_fs)(int);
76902 -};
76903 +} __no_const;
76904
76905 extern struct cleancache_ops *
76906 cleancache_register_ops(struct cleancache_ops *ops);
76907 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
76908 index 939533d..cf0a57c 100644
76909 --- a/include/linux/clk-provider.h
76910 +++ b/include/linux/clk-provider.h
76911 @@ -166,6 +166,7 @@ struct clk_ops {
76912 unsigned long parent_accuracy);
76913 void (*init)(struct clk_hw *hw);
76914 };
76915 +typedef struct clk_ops __no_const clk_ops_no_const;
76916
76917 /**
76918 * struct clk_init_data - holds init data that's common to all clocks and is
76919 diff --git a/include/linux/compat.h b/include/linux/compat.h
76920 index 3f448c6..df3ce1d 100644
76921 --- a/include/linux/compat.h
76922 +++ b/include/linux/compat.h
76923 @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
76924 compat_size_t __user *len_ptr);
76925
76926 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
76927 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
76928 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
76929 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
76930 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
76931 compat_ssize_t msgsz, int msgflg);
76932 @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
76933 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
76934 compat_ulong_t addr, compat_ulong_t data);
76935 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76936 - compat_long_t addr, compat_long_t data);
76937 + compat_ulong_t addr, compat_ulong_t data);
76938
76939 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
76940 /*
76941 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
76942 index 2507fd2..55203f8 100644
76943 --- a/include/linux/compiler-gcc4.h
76944 +++ b/include/linux/compiler-gcc4.h
76945 @@ -39,9 +39,34 @@
76946 # define __compiletime_warning(message) __attribute__((warning(message)))
76947 # define __compiletime_error(message) __attribute__((error(message)))
76948 #endif /* __CHECKER__ */
76949 +
76950 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
76951 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
76952 +#define __bos0(ptr) __bos((ptr), 0)
76953 +#define __bos1(ptr) __bos((ptr), 1)
76954 #endif /* GCC_VERSION >= 40300 */
76955
76956 #if GCC_VERSION >= 40500
76957 +
76958 +#ifdef RANDSTRUCT_PLUGIN
76959 +#define __randomize_layout __attribute__((randomize_layout))
76960 +#define __no_randomize_layout __attribute__((no_randomize_layout))
76961 +#endif
76962 +
76963 +#ifdef CONSTIFY_PLUGIN
76964 +#define __no_const __attribute__((no_const))
76965 +#define __do_const __attribute__((do_const))
76966 +#endif
76967 +
76968 +#ifdef SIZE_OVERFLOW_PLUGIN
76969 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
76970 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
76971 +#endif
76972 +
76973 +#ifdef LATENT_ENTROPY_PLUGIN
76974 +#define __latent_entropy __attribute__((latent_entropy))
76975 +#endif
76976 +
76977 /*
76978 * Mark a position in code as unreachable. This can be used to
76979 * suppress control flow warnings after asm blocks that transfer
76980 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
76981 index 2472740..4857634 100644
76982 --- a/include/linux/compiler.h
76983 +++ b/include/linux/compiler.h
76984 @@ -5,11 +5,14 @@
76985
76986 #ifdef __CHECKER__
76987 # define __user __attribute__((noderef, address_space(1)))
76988 +# define __force_user __force __user
76989 # define __kernel __attribute__((address_space(0)))
76990 +# define __force_kernel __force __kernel
76991 # define __safe __attribute__((safe))
76992 # define __force __attribute__((force))
76993 # define __nocast __attribute__((nocast))
76994 # define __iomem __attribute__((noderef, address_space(2)))
76995 +# define __force_iomem __force __iomem
76996 # define __must_hold(x) __attribute__((context(x,1,1)))
76997 # define __acquires(x) __attribute__((context(x,0,1)))
76998 # define __releases(x) __attribute__((context(x,1,0)))
76999 @@ -17,20 +20,37 @@
77000 # define __release(x) __context__(x,-1)
77001 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77002 # define __percpu __attribute__((noderef, address_space(3)))
77003 +# define __force_percpu __force __percpu
77004 #ifdef CONFIG_SPARSE_RCU_POINTER
77005 # define __rcu __attribute__((noderef, address_space(4)))
77006 +# define __force_rcu __force __rcu
77007 #else
77008 # define __rcu
77009 +# define __force_rcu
77010 #endif
77011 extern void __chk_user_ptr(const volatile void __user *);
77012 extern void __chk_io_ptr(const volatile void __iomem *);
77013 #else
77014 -# define __user
77015 -# define __kernel
77016 +# ifdef CHECKER_PLUGIN
77017 +//# define __user
77018 +//# define __force_user
77019 +//# define __kernel
77020 +//# define __force_kernel
77021 +# else
77022 +# ifdef STRUCTLEAK_PLUGIN
77023 +# define __user __attribute__((user))
77024 +# else
77025 +# define __user
77026 +# endif
77027 +# define __force_user
77028 +# define __kernel
77029 +# define __force_kernel
77030 +# endif
77031 # define __safe
77032 # define __force
77033 # define __nocast
77034 # define __iomem
77035 +# define __force_iomem
77036 # define __chk_user_ptr(x) (void)0
77037 # define __chk_io_ptr(x) (void)0
77038 # define __builtin_warning(x, y...) (1)
77039 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77040 # define __release(x) (void)0
77041 # define __cond_lock(x,c) (c)
77042 # define __percpu
77043 +# define __force_percpu
77044 # define __rcu
77045 +# define __force_rcu
77046 #endif
77047
77048 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77049 @@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77050 # define __attribute_const__ /* unimplemented */
77051 #endif
77052
77053 +#ifndef __randomize_layout
77054 +# define __randomize_layout
77055 +#endif
77056 +
77057 +#ifndef __no_randomize_layout
77058 +# define __no_randomize_layout
77059 +#endif
77060 +
77061 +#ifndef __no_const
77062 +# define __no_const
77063 +#endif
77064 +
77065 +#ifndef __do_const
77066 +# define __do_const
77067 +#endif
77068 +
77069 +#ifndef __size_overflow
77070 +# define __size_overflow(...)
77071 +#endif
77072 +
77073 +#ifndef __intentional_overflow
77074 +# define __intentional_overflow(...)
77075 +#endif
77076 +
77077 +#ifndef __latent_entropy
77078 +# define __latent_entropy
77079 +#endif
77080 +
77081 /*
77082 * Tell gcc if a function is cold. The compiler will assume any path
77083 * directly leading to the call is unlikely.
77084 @@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77085 #define __cold
77086 #endif
77087
77088 +#ifndef __alloc_size
77089 +#define __alloc_size(...)
77090 +#endif
77091 +
77092 +#ifndef __bos
77093 +#define __bos(ptr, arg)
77094 +#endif
77095 +
77096 +#ifndef __bos0
77097 +#define __bos0(ptr)
77098 +#endif
77099 +
77100 +#ifndef __bos1
77101 +#define __bos1(ptr)
77102 +#endif
77103 +
77104 /* Simple shorthand for a section definition */
77105 #ifndef __section
77106 # define __section(S) __attribute__ ((__section__(#S)))
77107 @@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77108 * use is to mediate communication between process-level code and irq/NMI
77109 * handlers, all running on the same CPU.
77110 */
77111 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77112 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77113 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77114
77115 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77116 #ifdef CONFIG_KPROBES
77117 diff --git a/include/linux/completion.h b/include/linux/completion.h
77118 index 5d5aaae..0ea9b84 100644
77119 --- a/include/linux/completion.h
77120 +++ b/include/linux/completion.h
77121 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77122
77123 extern void wait_for_completion(struct completion *);
77124 extern void wait_for_completion_io(struct completion *);
77125 -extern int wait_for_completion_interruptible(struct completion *x);
77126 -extern int wait_for_completion_killable(struct completion *x);
77127 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77128 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77129 extern unsigned long wait_for_completion_timeout(struct completion *x,
77130 - unsigned long timeout);
77131 + unsigned long timeout) __intentional_overflow(-1);
77132 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77133 - unsigned long timeout);
77134 + unsigned long timeout) __intentional_overflow(-1);
77135 extern long wait_for_completion_interruptible_timeout(
77136 - struct completion *x, unsigned long timeout);
77137 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77138 extern long wait_for_completion_killable_timeout(
77139 - struct completion *x, unsigned long timeout);
77140 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77141 extern bool try_wait_for_completion(struct completion *x);
77142 extern bool completion_done(struct completion *x);
77143
77144 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77145 index 34025df..d94bbbc 100644
77146 --- a/include/linux/configfs.h
77147 +++ b/include/linux/configfs.h
77148 @@ -125,7 +125,7 @@ struct configfs_attribute {
77149 const char *ca_name;
77150 struct module *ca_owner;
77151 umode_t ca_mode;
77152 -};
77153 +} __do_const;
77154
77155 /*
77156 * Users often need to create attribute structures for their configurable
77157 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77158 index 4d89e0e..5281847 100644
77159 --- a/include/linux/cpufreq.h
77160 +++ b/include/linux/cpufreq.h
77161 @@ -191,6 +191,7 @@ struct global_attr {
77162 ssize_t (*store)(struct kobject *a, struct attribute *b,
77163 const char *c, size_t count);
77164 };
77165 +typedef struct global_attr __no_const global_attr_no_const;
77166
77167 #define define_one_global_ro(_name) \
77168 static struct global_attr _name = \
77169 @@ -232,7 +233,7 @@ struct cpufreq_driver {
77170 bool boost_supported;
77171 bool boost_enabled;
77172 int (*set_boost) (int state);
77173 -};
77174 +} __do_const;
77175
77176 /* flags */
77177 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77178 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77179 index 50fcbb0..9d2dbd9 100644
77180 --- a/include/linux/cpuidle.h
77181 +++ b/include/linux/cpuidle.h
77182 @@ -50,7 +50,8 @@ struct cpuidle_state {
77183 int index);
77184
77185 int (*enter_dead) (struct cpuidle_device *dev, int index);
77186 -};
77187 +} __do_const;
77188 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77189
77190 /* Idle State Flags */
77191 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77192 @@ -192,7 +193,7 @@ struct cpuidle_governor {
77193 void (*reflect) (struct cpuidle_device *dev, int index);
77194
77195 struct module *owner;
77196 -};
77197 +} __do_const;
77198
77199 #ifdef CONFIG_CPU_IDLE
77200 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77201 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77202 index d08e4d2..95fad61 100644
77203 --- a/include/linux/cpumask.h
77204 +++ b/include/linux/cpumask.h
77205 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77206 }
77207
77208 /* Valid inputs for n are -1 and 0. */
77209 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77210 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77211 {
77212 return n+1;
77213 }
77214
77215 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77216 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77217 {
77218 return n+1;
77219 }
77220
77221 -static inline unsigned int cpumask_next_and(int n,
77222 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77223 const struct cpumask *srcp,
77224 const struct cpumask *andp)
77225 {
77226 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77227 *
77228 * Returns >= nr_cpu_ids if no further cpus set.
77229 */
77230 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77231 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77232 {
77233 /* -1 is a legal arg here. */
77234 if (n != -1)
77235 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77236 *
77237 * Returns >= nr_cpu_ids if no further cpus unset.
77238 */
77239 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77240 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77241 {
77242 /* -1 is a legal arg here. */
77243 if (n != -1)
77244 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77245 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77246 }
77247
77248 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77249 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77250 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77251
77252 /**
77253 diff --git a/include/linux/cred.h b/include/linux/cred.h
77254 index 04421e8..117e17a 100644
77255 --- a/include/linux/cred.h
77256 +++ b/include/linux/cred.h
77257 @@ -35,7 +35,7 @@ struct group_info {
77258 int nblocks;
77259 kgid_t small_block[NGROUPS_SMALL];
77260 kgid_t *blocks[0];
77261 -};
77262 +} __randomize_layout;
77263
77264 /**
77265 * get_group_info - Get a reference to a group info structure
77266 @@ -136,7 +136,7 @@ struct cred {
77267 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77268 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77269 struct rcu_head rcu; /* RCU deletion hook */
77270 -};
77271 +} __randomize_layout;
77272
77273 extern void __put_cred(struct cred *);
77274 extern void exit_creds(struct task_struct *);
77275 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77276 static inline void validate_process_creds(void)
77277 {
77278 }
77279 +static inline void validate_task_creds(struct task_struct *task)
77280 +{
77281 +}
77282 #endif
77283
77284 /**
77285 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77286 index b92eadf..b4ecdc1 100644
77287 --- a/include/linux/crypto.h
77288 +++ b/include/linux/crypto.h
77289 @@ -373,7 +373,7 @@ struct cipher_tfm {
77290 const u8 *key, unsigned int keylen);
77291 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77292 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77293 -};
77294 +} __no_const;
77295
77296 struct hash_tfm {
77297 int (*init)(struct hash_desc *desc);
77298 @@ -394,13 +394,13 @@ struct compress_tfm {
77299 int (*cot_decompress)(struct crypto_tfm *tfm,
77300 const u8 *src, unsigned int slen,
77301 u8 *dst, unsigned int *dlen);
77302 -};
77303 +} __no_const;
77304
77305 struct rng_tfm {
77306 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77307 unsigned int dlen);
77308 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77309 -};
77310 +} __no_const;
77311
77312 #define crt_ablkcipher crt_u.ablkcipher
77313 #define crt_aead crt_u.aead
77314 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77315 index 653589e..4ef254a 100644
77316 --- a/include/linux/ctype.h
77317 +++ b/include/linux/ctype.h
77318 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77319 * Fast implementation of tolower() for internal usage. Do not use in your
77320 * code.
77321 */
77322 -static inline char _tolower(const char c)
77323 +static inline unsigned char _tolower(const unsigned char c)
77324 {
77325 return c | 0x20;
77326 }
77327 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77328 index bf72e9a..4ca7927 100644
77329 --- a/include/linux/dcache.h
77330 +++ b/include/linux/dcache.h
77331 @@ -133,7 +133,7 @@ struct dentry {
77332 } d_u;
77333 struct list_head d_subdirs; /* our children */
77334 struct hlist_node d_alias; /* inode alias list */
77335 -};
77336 +} __randomize_layout;
77337
77338 /*
77339 * dentry->d_lock spinlock nesting subclasses:
77340 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77341 index 7925bf0..d5143d2 100644
77342 --- a/include/linux/decompress/mm.h
77343 +++ b/include/linux/decompress/mm.h
77344 @@ -77,7 +77,7 @@ static void free(void *where)
77345 * warnings when not needed (indeed large_malloc / large_free are not
77346 * needed by inflate */
77347
77348 -#define malloc(a) kmalloc(a, GFP_KERNEL)
77349 +#define malloc(a) kmalloc((a), GFP_KERNEL)
77350 #define free(a) kfree(a)
77351
77352 #define large_malloc(a) vmalloc(a)
77353 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77354 index d48dc00..211ee54 100644
77355 --- a/include/linux/devfreq.h
77356 +++ b/include/linux/devfreq.h
77357 @@ -114,7 +114,7 @@ struct devfreq_governor {
77358 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77359 int (*event_handler)(struct devfreq *devfreq,
77360 unsigned int event, void *data);
77361 -};
77362 +} __do_const;
77363
77364 /**
77365 * struct devfreq - Device devfreq structure
77366 diff --git a/include/linux/device.h b/include/linux/device.h
77367 index 952b010..d5b7691 100644
77368 --- a/include/linux/device.h
77369 +++ b/include/linux/device.h
77370 @@ -310,7 +310,7 @@ struct subsys_interface {
77371 struct list_head node;
77372 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77373 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77374 -};
77375 +} __do_const;
77376
77377 int subsys_interface_register(struct subsys_interface *sif);
77378 void subsys_interface_unregister(struct subsys_interface *sif);
77379 @@ -506,7 +506,7 @@ struct device_type {
77380 void (*release)(struct device *dev);
77381
77382 const struct dev_pm_ops *pm;
77383 -};
77384 +} __do_const;
77385
77386 /* interface for exporting device attributes */
77387 struct device_attribute {
77388 @@ -516,11 +516,12 @@ struct device_attribute {
77389 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
77390 const char *buf, size_t count);
77391 };
77392 +typedef struct device_attribute __no_const device_attribute_no_const;
77393
77394 struct dev_ext_attribute {
77395 struct device_attribute attr;
77396 void *var;
77397 -};
77398 +} __do_const;
77399
77400 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
77401 char *buf);
77402 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
77403 index fd4aee2..1f28db9 100644
77404 --- a/include/linux/dma-mapping.h
77405 +++ b/include/linux/dma-mapping.h
77406 @@ -54,7 +54,7 @@ struct dma_map_ops {
77407 u64 (*get_required_mask)(struct device *dev);
77408 #endif
77409 int is_phys;
77410 -};
77411 +} __do_const;
77412
77413 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
77414
77415 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
77416 index c5c92d5..6a5c2b2 100644
77417 --- a/include/linux/dmaengine.h
77418 +++ b/include/linux/dmaengine.h
77419 @@ -1150,9 +1150,9 @@ struct dma_pinned_list {
77420 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
77421 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
77422
77423 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77424 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77425 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
77426 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77427 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77428 struct dma_pinned_list *pinned_list, struct page *page,
77429 unsigned int offset, size_t len);
77430
77431 diff --git a/include/linux/efi.h b/include/linux/efi.h
77432 index 0a819e7..8ed47f1 100644
77433 --- a/include/linux/efi.h
77434 +++ b/include/linux/efi.h
77435 @@ -768,6 +768,7 @@ struct efivar_operations {
77436 efi_set_variable_t *set_variable;
77437 efi_query_variable_store_t *query_variable_store;
77438 };
77439 +typedef struct efivar_operations __no_const efivar_operations_no_const;
77440
77441 struct efivars {
77442 /*
77443 diff --git a/include/linux/elf.h b/include/linux/elf.h
77444 index 67a5fa7..b817372 100644
77445 --- a/include/linux/elf.h
77446 +++ b/include/linux/elf.h
77447 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
77448 #define elf_note elf32_note
77449 #define elf_addr_t Elf32_Off
77450 #define Elf_Half Elf32_Half
77451 +#define elf_dyn Elf32_Dyn
77452
77453 #else
77454
77455 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
77456 #define elf_note elf64_note
77457 #define elf_addr_t Elf64_Off
77458 #define Elf_Half Elf64_Half
77459 +#define elf_dyn Elf64_Dyn
77460
77461 #endif
77462
77463 diff --git a/include/linux/err.h b/include/linux/err.h
77464 index 15f92e0..e825a8e 100644
77465 --- a/include/linux/err.h
77466 +++ b/include/linux/err.h
77467 @@ -19,12 +19,12 @@
77468
77469 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
77470
77471 -static inline void * __must_check ERR_PTR(long error)
77472 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
77473 {
77474 return (void *) error;
77475 }
77476
77477 -static inline long __must_check PTR_ERR(__force const void *ptr)
77478 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
77479 {
77480 return (long) ptr;
77481 }
77482 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
77483 index 21c59af..6057a03 100644
77484 --- a/include/linux/extcon.h
77485 +++ b/include/linux/extcon.h
77486 @@ -135,7 +135,7 @@ struct extcon_dev {
77487 /* /sys/class/extcon/.../mutually_exclusive/... */
77488 struct attribute_group attr_g_muex;
77489 struct attribute **attrs_muex;
77490 - struct device_attribute *d_attrs_muex;
77491 + device_attribute_no_const *d_attrs_muex;
77492 };
77493
77494 /**
77495 diff --git a/include/linux/fb.h b/include/linux/fb.h
77496 index fe6ac95..898d41d 100644
77497 --- a/include/linux/fb.h
77498 +++ b/include/linux/fb.h
77499 @@ -304,7 +304,7 @@ struct fb_ops {
77500 /* called at KDB enter and leave time to prepare the console */
77501 int (*fb_debug_enter)(struct fb_info *info);
77502 int (*fb_debug_leave)(struct fb_info *info);
77503 -};
77504 +} __do_const;
77505
77506 #ifdef CONFIG_FB_TILEBLITTING
77507 #define FB_TILE_CURSOR_NONE 0
77508 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
77509 index 70e8e21..1939916 100644
77510 --- a/include/linux/fdtable.h
77511 +++ b/include/linux/fdtable.h
77512 @@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
77513 void put_files_struct(struct files_struct *fs);
77514 void reset_files_struct(struct files_struct *);
77515 int unshare_files(struct files_struct **);
77516 -struct files_struct *dup_fd(struct files_struct *, int *);
77517 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
77518 void do_close_on_exec(struct files_struct *);
77519 int iterate_fd(struct files_struct *, unsigned,
77520 int (*)(const void *, struct file *, unsigned),
77521 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
77522 index 8293262..2b3b8bd 100644
77523 --- a/include/linux/frontswap.h
77524 +++ b/include/linux/frontswap.h
77525 @@ -11,7 +11,7 @@ struct frontswap_ops {
77526 int (*load)(unsigned, pgoff_t, struct page *);
77527 void (*invalidate_page)(unsigned, pgoff_t);
77528 void (*invalidate_area)(unsigned);
77529 -};
77530 +} __no_const;
77531
77532 extern bool frontswap_enabled;
77533 extern struct frontswap_ops *
77534 diff --git a/include/linux/fs.h b/include/linux/fs.h
77535 index 23b2a35..8764ab7 100644
77536 --- a/include/linux/fs.h
77537 +++ b/include/linux/fs.h
77538 @@ -426,7 +426,7 @@ struct address_space {
77539 spinlock_t private_lock; /* for use by the address_space */
77540 struct list_head private_list; /* ditto */
77541 void *private_data; /* ditto */
77542 -} __attribute__((aligned(sizeof(long))));
77543 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
77544 /*
77545 * On most architectures that alignment is already the case; but
77546 * must be enforced here for CRIS, to let the least significant bit
77547 @@ -469,7 +469,7 @@ struct block_device {
77548 int bd_fsfreeze_count;
77549 /* Mutex for freeze */
77550 struct mutex bd_fsfreeze_mutex;
77551 -};
77552 +} __randomize_layout;
77553
77554 /*
77555 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
77556 @@ -613,7 +613,7 @@ struct inode {
77557 atomic_t i_readcount; /* struct files open RO */
77558 #endif
77559 void *i_private; /* fs or device private pointer */
77560 -};
77561 +} __randomize_layout;
77562
77563 static inline int inode_unhashed(struct inode *inode)
77564 {
77565 @@ -812,7 +812,7 @@ struct file {
77566 #ifdef CONFIG_DEBUG_WRITECOUNT
77567 unsigned long f_mnt_write_state;
77568 #endif
77569 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
77570 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
77571
77572 struct file_handle {
77573 __u32 handle_bytes;
77574 @@ -982,7 +982,7 @@ struct file_lock {
77575 int state; /* state of grant or error if -ve */
77576 } afs;
77577 } fl_u;
77578 -};
77579 +} __randomize_layout;
77580
77581 /* The following constant reflects the upper bound of the file/locking space */
77582 #ifndef OFFSET_MAX
77583 @@ -1329,7 +1329,7 @@ struct super_block {
77584 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
77585 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
77586 struct rcu_head rcu;
77587 -};
77588 +} __randomize_layout;
77589
77590 extern struct timespec current_fs_time(struct super_block *sb);
77591
77592 @@ -1551,7 +1551,8 @@ struct file_operations {
77593 long (*fallocate)(struct file *file, int mode, loff_t offset,
77594 loff_t len);
77595 int (*show_fdinfo)(struct seq_file *m, struct file *f);
77596 -};
77597 +} __do_const __randomize_layout;
77598 +typedef struct file_operations __no_const file_operations_no_const;
77599
77600 struct inode_operations {
77601 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
77602 @@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
77603 return !IS_DEADDIR(inode);
77604 }
77605
77606 +static inline bool is_sidechannel_device(const struct inode *inode)
77607 +{
77608 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
77609 + umode_t mode = inode->i_mode;
77610 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
77611 +#else
77612 + return false;
77613 +#endif
77614 +}
77615 +
77616 #endif /* _LINUX_FS_H */
77617 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
77618 index 0efc3e6..fd23610 100644
77619 --- a/include/linux/fs_struct.h
77620 +++ b/include/linux/fs_struct.h
77621 @@ -6,13 +6,13 @@
77622 #include <linux/seqlock.h>
77623
77624 struct fs_struct {
77625 - int users;
77626 + atomic_t users;
77627 spinlock_t lock;
77628 seqcount_t seq;
77629 int umask;
77630 int in_exec;
77631 struct path root, pwd;
77632 -};
77633 +} __randomize_layout;
77634
77635 extern struct kmem_cache *fs_cachep;
77636
77637 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
77638 index 7714849..a4a5c7a 100644
77639 --- a/include/linux/fscache-cache.h
77640 +++ b/include/linux/fscache-cache.h
77641 @@ -113,7 +113,7 @@ struct fscache_operation {
77642 fscache_operation_release_t release;
77643 };
77644
77645 -extern atomic_t fscache_op_debug_id;
77646 +extern atomic_unchecked_t fscache_op_debug_id;
77647 extern void fscache_op_work_func(struct work_struct *work);
77648
77649 extern void fscache_enqueue_operation(struct fscache_operation *);
77650 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
77651 INIT_WORK(&op->work, fscache_op_work_func);
77652 atomic_set(&op->usage, 1);
77653 op->state = FSCACHE_OP_ST_INITIALISED;
77654 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
77655 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
77656 op->processor = processor;
77657 op->release = release;
77658 INIT_LIST_HEAD(&op->pend_link);
77659 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
77660 index 115bb81..e7b812b 100644
77661 --- a/include/linux/fscache.h
77662 +++ b/include/linux/fscache.h
77663 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
77664 * - this is mandatory for any object that may have data
77665 */
77666 void (*now_uncached)(void *cookie_netfs_data);
77667 -};
77668 +} __do_const;
77669
77670 /*
77671 * fscache cached network filesystem type
77672 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
77673 index 1c804b0..1432c2b 100644
77674 --- a/include/linux/fsnotify.h
77675 +++ b/include/linux/fsnotify.h
77676 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
77677 struct inode *inode = file_inode(file);
77678 __u32 mask = FS_ACCESS;
77679
77680 + if (is_sidechannel_device(inode))
77681 + return;
77682 +
77683 if (S_ISDIR(inode->i_mode))
77684 mask |= FS_ISDIR;
77685
77686 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
77687 struct inode *inode = file_inode(file);
77688 __u32 mask = FS_MODIFY;
77689
77690 + if (is_sidechannel_device(inode))
77691 + return;
77692 +
77693 if (S_ISDIR(inode->i_mode))
77694 mask |= FS_ISDIR;
77695
77696 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
77697 */
77698 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
77699 {
77700 - return kstrdup(name, GFP_KERNEL);
77701 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
77702 }
77703
77704 /*
77705 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
77706 index 9f3c275..8bdff5d 100644
77707 --- a/include/linux/genhd.h
77708 +++ b/include/linux/genhd.h
77709 @@ -194,7 +194,7 @@ struct gendisk {
77710 struct kobject *slave_dir;
77711
77712 struct timer_rand_state *random;
77713 - atomic_t sync_io; /* RAID */
77714 + atomic_unchecked_t sync_io; /* RAID */
77715 struct disk_events *ev;
77716 #ifdef CONFIG_BLK_DEV_INTEGRITY
77717 struct blk_integrity *integrity;
77718 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
77719 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
77720
77721 /* drivers/char/random.c */
77722 -extern void add_disk_randomness(struct gendisk *disk);
77723 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
77724 extern void rand_initialize_disk(struct gendisk *disk);
77725
77726 static inline sector_t get_start_sect(struct block_device *bdev)
77727 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
77728 index c0894dd..2fbf10c 100644
77729 --- a/include/linux/genl_magic_func.h
77730 +++ b/include/linux/genl_magic_func.h
77731 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
77732 },
77733
77734 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
77735 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
77736 +static struct genl_ops ZZZ_genl_ops[] = {
77737 #include GENL_MAGIC_INCLUDE_FILE
77738 };
77739
77740 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
77741 index 39b81dc..819dc51 100644
77742 --- a/include/linux/gfp.h
77743 +++ b/include/linux/gfp.h
77744 @@ -36,6 +36,13 @@ struct vm_area_struct;
77745 #define ___GFP_NO_KSWAPD 0x400000u
77746 #define ___GFP_OTHER_NODE 0x800000u
77747 #define ___GFP_WRITE 0x1000000u
77748 +
77749 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77750 +#define ___GFP_USERCOPY 0x2000000u
77751 +#else
77752 +#define ___GFP_USERCOPY 0
77753 +#endif
77754 +
77755 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
77756
77757 /*
77758 @@ -93,6 +100,7 @@ struct vm_area_struct;
77759 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
77760 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
77761 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
77762 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
77763
77764 /*
77765 * This may seem redundant, but it's a way of annotating false positives vs.
77766 @@ -100,7 +108,7 @@ struct vm_area_struct;
77767 */
77768 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
77769
77770 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
77771 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
77772 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
77773
77774 /* This equals 0, but use constants in case they ever change */
77775 @@ -158,6 +166,8 @@ struct vm_area_struct;
77776 /* 4GB DMA on some platforms */
77777 #define GFP_DMA32 __GFP_DMA32
77778
77779 +#define GFP_USERCOPY __GFP_USERCOPY
77780 +
77781 /* Convert GFP flags to their corresponding migrate type */
77782 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
77783 {
77784 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
77785 new file mode 100644
77786 index 0000000..edb2cb6
77787 --- /dev/null
77788 +++ b/include/linux/gracl.h
77789 @@ -0,0 +1,340 @@
77790 +#ifndef GR_ACL_H
77791 +#define GR_ACL_H
77792 +
77793 +#include <linux/grdefs.h>
77794 +#include <linux/resource.h>
77795 +#include <linux/capability.h>
77796 +#include <linux/dcache.h>
77797 +#include <asm/resource.h>
77798 +
77799 +/* Major status information */
77800 +
77801 +#define GR_VERSION "grsecurity 3.0"
77802 +#define GRSECURITY_VERSION 0x3000
77803 +
77804 +enum {
77805 + GR_SHUTDOWN = 0,
77806 + GR_ENABLE = 1,
77807 + GR_SPROLE = 2,
77808 + GR_OLDRELOAD = 3,
77809 + GR_SEGVMOD = 4,
77810 + GR_STATUS = 5,
77811 + GR_UNSPROLE = 6,
77812 + GR_PASSSET = 7,
77813 + GR_SPROLEPAM = 8,
77814 + GR_RELOAD = 9,
77815 +};
77816 +
77817 +/* Password setup definitions
77818 + * kernel/grhash.c */
77819 +enum {
77820 + GR_PW_LEN = 128,
77821 + GR_SALT_LEN = 16,
77822 + GR_SHA_LEN = 32,
77823 +};
77824 +
77825 +enum {
77826 + GR_SPROLE_LEN = 64,
77827 +};
77828 +
77829 +enum {
77830 + GR_NO_GLOB = 0,
77831 + GR_REG_GLOB,
77832 + GR_CREATE_GLOB
77833 +};
77834 +
77835 +#define GR_NLIMITS 32
77836 +
77837 +/* Begin Data Structures */
77838 +
77839 +struct sprole_pw {
77840 + unsigned char *rolename;
77841 + unsigned char salt[GR_SALT_LEN];
77842 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
77843 +};
77844 +
77845 +struct name_entry {
77846 + __u32 key;
77847 + ino_t inode;
77848 + dev_t device;
77849 + char *name;
77850 + __u16 len;
77851 + __u8 deleted;
77852 + struct name_entry *prev;
77853 + struct name_entry *next;
77854 +};
77855 +
77856 +struct inodev_entry {
77857 + struct name_entry *nentry;
77858 + struct inodev_entry *prev;
77859 + struct inodev_entry *next;
77860 +};
77861 +
77862 +struct acl_role_db {
77863 + struct acl_role_label **r_hash;
77864 + __u32 r_size;
77865 +};
77866 +
77867 +struct inodev_db {
77868 + struct inodev_entry **i_hash;
77869 + __u32 i_size;
77870 +};
77871 +
77872 +struct name_db {
77873 + struct name_entry **n_hash;
77874 + __u32 n_size;
77875 +};
77876 +
77877 +struct crash_uid {
77878 + uid_t uid;
77879 + unsigned long expires;
77880 +};
77881 +
77882 +struct gr_hash_struct {
77883 + void **table;
77884 + void **nametable;
77885 + void *first;
77886 + __u32 table_size;
77887 + __u32 used_size;
77888 + int type;
77889 +};
77890 +
77891 +/* Userspace Grsecurity ACL data structures */
77892 +
77893 +struct acl_subject_label {
77894 + char *filename;
77895 + ino_t inode;
77896 + dev_t device;
77897 + __u32 mode;
77898 + kernel_cap_t cap_mask;
77899 + kernel_cap_t cap_lower;
77900 + kernel_cap_t cap_invert_audit;
77901 +
77902 + struct rlimit res[GR_NLIMITS];
77903 + __u32 resmask;
77904 +
77905 + __u8 user_trans_type;
77906 + __u8 group_trans_type;
77907 + uid_t *user_transitions;
77908 + gid_t *group_transitions;
77909 + __u16 user_trans_num;
77910 + __u16 group_trans_num;
77911 +
77912 + __u32 sock_families[2];
77913 + __u32 ip_proto[8];
77914 + __u32 ip_type;
77915 + struct acl_ip_label **ips;
77916 + __u32 ip_num;
77917 + __u32 inaddr_any_override;
77918 +
77919 + __u32 crashes;
77920 + unsigned long expires;
77921 +
77922 + struct acl_subject_label *parent_subject;
77923 + struct gr_hash_struct *hash;
77924 + struct acl_subject_label *prev;
77925 + struct acl_subject_label *next;
77926 +
77927 + struct acl_object_label **obj_hash;
77928 + __u32 obj_hash_size;
77929 + __u16 pax_flags;
77930 +};
77931 +
77932 +struct role_allowed_ip {
77933 + __u32 addr;
77934 + __u32 netmask;
77935 +
77936 + struct role_allowed_ip *prev;
77937 + struct role_allowed_ip *next;
77938 +};
77939 +
77940 +struct role_transition {
77941 + char *rolename;
77942 +
77943 + struct role_transition *prev;
77944 + struct role_transition *next;
77945 +};
77946 +
77947 +struct acl_role_label {
77948 + char *rolename;
77949 + uid_t uidgid;
77950 + __u16 roletype;
77951 +
77952 + __u16 auth_attempts;
77953 + unsigned long expires;
77954 +
77955 + struct acl_subject_label *root_label;
77956 + struct gr_hash_struct *hash;
77957 +
77958 + struct acl_role_label *prev;
77959 + struct acl_role_label *next;
77960 +
77961 + struct role_transition *transitions;
77962 + struct role_allowed_ip *allowed_ips;
77963 + uid_t *domain_children;
77964 + __u16 domain_child_num;
77965 +
77966 + umode_t umask;
77967 +
77968 + struct acl_subject_label **subj_hash;
77969 + __u32 subj_hash_size;
77970 +};
77971 +
77972 +struct user_acl_role_db {
77973 + struct acl_role_label **r_table;
77974 + __u32 num_pointers; /* Number of allocations to track */
77975 + __u32 num_roles; /* Number of roles */
77976 + __u32 num_domain_children; /* Number of domain children */
77977 + __u32 num_subjects; /* Number of subjects */
77978 + __u32 num_objects; /* Number of objects */
77979 +};
77980 +
77981 +struct acl_object_label {
77982 + char *filename;
77983 + ino_t inode;
77984 + dev_t device;
77985 + __u32 mode;
77986 +
77987 + struct acl_subject_label *nested;
77988 + struct acl_object_label *globbed;
77989 +
77990 + /* next two structures not used */
77991 +
77992 + struct acl_object_label *prev;
77993 + struct acl_object_label *next;
77994 +};
77995 +
77996 +struct acl_ip_label {
77997 + char *iface;
77998 + __u32 addr;
77999 + __u32 netmask;
78000 + __u16 low, high;
78001 + __u8 mode;
78002 + __u32 type;
78003 + __u32 proto[8];
78004 +
78005 + /* next two structures not used */
78006 +
78007 + struct acl_ip_label *prev;
78008 + struct acl_ip_label *next;
78009 +};
78010 +
78011 +struct gr_arg {
78012 + struct user_acl_role_db role_db;
78013 + unsigned char pw[GR_PW_LEN];
78014 + unsigned char salt[GR_SALT_LEN];
78015 + unsigned char sum[GR_SHA_LEN];
78016 + unsigned char sp_role[GR_SPROLE_LEN];
78017 + struct sprole_pw *sprole_pws;
78018 + dev_t segv_device;
78019 + ino_t segv_inode;
78020 + uid_t segv_uid;
78021 + __u16 num_sprole_pws;
78022 + __u16 mode;
78023 +};
78024 +
78025 +struct gr_arg_wrapper {
78026 + struct gr_arg *arg;
78027 + __u32 version;
78028 + __u32 size;
78029 +};
78030 +
78031 +struct subject_map {
78032 + struct acl_subject_label *user;
78033 + struct acl_subject_label *kernel;
78034 + struct subject_map *prev;
78035 + struct subject_map *next;
78036 +};
78037 +
78038 +struct acl_subj_map_db {
78039 + struct subject_map **s_hash;
78040 + __u32 s_size;
78041 +};
78042 +
78043 +struct gr_policy_state {
78044 + struct sprole_pw **acl_special_roles;
78045 + __u16 num_sprole_pws;
78046 + struct acl_role_label *kernel_role;
78047 + struct acl_role_label *role_list;
78048 + struct acl_role_label *default_role;
78049 + struct acl_role_db acl_role_set;
78050 + struct acl_subj_map_db subj_map_set;
78051 + struct name_db name_set;
78052 + struct inodev_db inodev_set;
78053 +};
78054 +
78055 +struct gr_alloc_state {
78056 + unsigned long alloc_stack_next;
78057 + unsigned long alloc_stack_size;
78058 + void **alloc_stack;
78059 +};
78060 +
78061 +struct gr_reload_state {
78062 + struct gr_policy_state oldpolicy;
78063 + struct gr_alloc_state oldalloc;
78064 + struct gr_policy_state newpolicy;
78065 + struct gr_alloc_state newalloc;
78066 + struct gr_policy_state *oldpolicy_ptr;
78067 + struct gr_alloc_state *oldalloc_ptr;
78068 + unsigned char oldmode;
78069 +};
78070 +
78071 +/* End Data Structures Section */
78072 +
78073 +/* Hash functions generated by empirical testing by Brad Spengler
78074 + Makes good use of the low bits of the inode. Generally 0-1 times
78075 + in loop for successful match. 0-3 for unsuccessful match.
78076 + Shift/add algorithm with modulus of table size and an XOR*/
78077 +
78078 +static __inline__ unsigned int
78079 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78080 +{
78081 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
78082 +}
78083 +
78084 + static __inline__ unsigned int
78085 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78086 +{
78087 + return ((const unsigned long)userp % sz);
78088 +}
78089 +
78090 +static __inline__ unsigned int
78091 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78092 +{
78093 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78094 +}
78095 +
78096 +static __inline__ unsigned int
78097 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78098 +{
78099 + return full_name_hash((const unsigned char *)name, len) % sz;
78100 +}
78101 +
78102 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78103 + subj = NULL; \
78104 + iter = 0; \
78105 + while (iter < role->subj_hash_size) { \
78106 + if (subj == NULL) \
78107 + subj = role->subj_hash[iter]; \
78108 + if (subj == NULL) { \
78109 + iter++; \
78110 + continue; \
78111 + }
78112 +
78113 +#define FOR_EACH_SUBJECT_END(subj,iter) \
78114 + subj = subj->next; \
78115 + if (subj == NULL) \
78116 + iter++; \
78117 + }
78118 +
78119 +
78120 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78121 + subj = role->hash->first; \
78122 + while (subj != NULL) {
78123 +
78124 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78125 + subj = subj->next; \
78126 + }
78127 +
78128 +#endif
78129 +
78130 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78131 new file mode 100644
78132 index 0000000..33ebd1f
78133 --- /dev/null
78134 +++ b/include/linux/gracl_compat.h
78135 @@ -0,0 +1,156 @@
78136 +#ifndef GR_ACL_COMPAT_H
78137 +#define GR_ACL_COMPAT_H
78138 +
78139 +#include <linux/resource.h>
78140 +#include <asm/resource.h>
78141 +
78142 +struct sprole_pw_compat {
78143 + compat_uptr_t rolename;
78144 + unsigned char salt[GR_SALT_LEN];
78145 + unsigned char sum[GR_SHA_LEN];
78146 +};
78147 +
78148 +struct gr_hash_struct_compat {
78149 + compat_uptr_t table;
78150 + compat_uptr_t nametable;
78151 + compat_uptr_t first;
78152 + __u32 table_size;
78153 + __u32 used_size;
78154 + int type;
78155 +};
78156 +
78157 +struct acl_subject_label_compat {
78158 + compat_uptr_t filename;
78159 + compat_ino_t inode;
78160 + __u32 device;
78161 + __u32 mode;
78162 + kernel_cap_t cap_mask;
78163 + kernel_cap_t cap_lower;
78164 + kernel_cap_t cap_invert_audit;
78165 +
78166 + struct compat_rlimit res[GR_NLIMITS];
78167 + __u32 resmask;
78168 +
78169 + __u8 user_trans_type;
78170 + __u8 group_trans_type;
78171 + compat_uptr_t user_transitions;
78172 + compat_uptr_t group_transitions;
78173 + __u16 user_trans_num;
78174 + __u16 group_trans_num;
78175 +
78176 + __u32 sock_families[2];
78177 + __u32 ip_proto[8];
78178 + __u32 ip_type;
78179 + compat_uptr_t ips;
78180 + __u32 ip_num;
78181 + __u32 inaddr_any_override;
78182 +
78183 + __u32 crashes;
78184 + compat_ulong_t expires;
78185 +
78186 + compat_uptr_t parent_subject;
78187 + compat_uptr_t hash;
78188 + compat_uptr_t prev;
78189 + compat_uptr_t next;
78190 +
78191 + compat_uptr_t obj_hash;
78192 + __u32 obj_hash_size;
78193 + __u16 pax_flags;
78194 +};
78195 +
78196 +struct role_allowed_ip_compat {
78197 + __u32 addr;
78198 + __u32 netmask;
78199 +
78200 + compat_uptr_t prev;
78201 + compat_uptr_t next;
78202 +};
78203 +
78204 +struct role_transition_compat {
78205 + compat_uptr_t rolename;
78206 +
78207 + compat_uptr_t prev;
78208 + compat_uptr_t next;
78209 +};
78210 +
78211 +struct acl_role_label_compat {
78212 + compat_uptr_t rolename;
78213 + uid_t uidgid;
78214 + __u16 roletype;
78215 +
78216 + __u16 auth_attempts;
78217 + compat_ulong_t expires;
78218 +
78219 + compat_uptr_t root_label;
78220 + compat_uptr_t hash;
78221 +
78222 + compat_uptr_t prev;
78223 + compat_uptr_t next;
78224 +
78225 + compat_uptr_t transitions;
78226 + compat_uptr_t allowed_ips;
78227 + compat_uptr_t domain_children;
78228 + __u16 domain_child_num;
78229 +
78230 + umode_t umask;
78231 +
78232 + compat_uptr_t subj_hash;
78233 + __u32 subj_hash_size;
78234 +};
78235 +
78236 +struct user_acl_role_db_compat {
78237 + compat_uptr_t r_table;
78238 + __u32 num_pointers;
78239 + __u32 num_roles;
78240 + __u32 num_domain_children;
78241 + __u32 num_subjects;
78242 + __u32 num_objects;
78243 +};
78244 +
78245 +struct acl_object_label_compat {
78246 + compat_uptr_t filename;
78247 + compat_ino_t inode;
78248 + __u32 device;
78249 + __u32 mode;
78250 +
78251 + compat_uptr_t nested;
78252 + compat_uptr_t globbed;
78253 +
78254 + compat_uptr_t prev;
78255 + compat_uptr_t next;
78256 +};
78257 +
78258 +struct acl_ip_label_compat {
78259 + compat_uptr_t iface;
78260 + __u32 addr;
78261 + __u32 netmask;
78262 + __u16 low, high;
78263 + __u8 mode;
78264 + __u32 type;
78265 + __u32 proto[8];
78266 +
78267 + compat_uptr_t prev;
78268 + compat_uptr_t next;
78269 +};
78270 +
78271 +struct gr_arg_compat {
78272 + struct user_acl_role_db_compat role_db;
78273 + unsigned char pw[GR_PW_LEN];
78274 + unsigned char salt[GR_SALT_LEN];
78275 + unsigned char sum[GR_SHA_LEN];
78276 + unsigned char sp_role[GR_SPROLE_LEN];
78277 + compat_uptr_t sprole_pws;
78278 + __u32 segv_device;
78279 + compat_ino_t segv_inode;
78280 + uid_t segv_uid;
78281 + __u16 num_sprole_pws;
78282 + __u16 mode;
78283 +};
78284 +
78285 +struct gr_arg_wrapper_compat {
78286 + compat_uptr_t arg;
78287 + __u32 version;
78288 + __u32 size;
78289 +};
78290 +
78291 +#endif
78292 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78293 new file mode 100644
78294 index 0000000..323ecf2
78295 --- /dev/null
78296 +++ b/include/linux/gralloc.h
78297 @@ -0,0 +1,9 @@
78298 +#ifndef __GRALLOC_H
78299 +#define __GRALLOC_H
78300 +
78301 +void acl_free_all(void);
78302 +int acl_alloc_stack_init(unsigned long size);
78303 +void *acl_alloc(unsigned long len);
78304 +void *acl_alloc_num(unsigned long num, unsigned long len);
78305 +
78306 +#endif
78307 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78308 new file mode 100644
78309 index 0000000..be66033
78310 --- /dev/null
78311 +++ b/include/linux/grdefs.h
78312 @@ -0,0 +1,140 @@
78313 +#ifndef GRDEFS_H
78314 +#define GRDEFS_H
78315 +
78316 +/* Begin grsecurity status declarations */
78317 +
78318 +enum {
78319 + GR_READY = 0x01,
78320 + GR_STATUS_INIT = 0x00 // disabled state
78321 +};
78322 +
78323 +/* Begin ACL declarations */
78324 +
78325 +/* Role flags */
78326 +
78327 +enum {
78328 + GR_ROLE_USER = 0x0001,
78329 + GR_ROLE_GROUP = 0x0002,
78330 + GR_ROLE_DEFAULT = 0x0004,
78331 + GR_ROLE_SPECIAL = 0x0008,
78332 + GR_ROLE_AUTH = 0x0010,
78333 + GR_ROLE_NOPW = 0x0020,
78334 + GR_ROLE_GOD = 0x0040,
78335 + GR_ROLE_LEARN = 0x0080,
78336 + GR_ROLE_TPE = 0x0100,
78337 + GR_ROLE_DOMAIN = 0x0200,
78338 + GR_ROLE_PAM = 0x0400,
78339 + GR_ROLE_PERSIST = 0x0800
78340 +};
78341 +
78342 +/* ACL Subject and Object mode flags */
78343 +enum {
78344 + GR_DELETED = 0x80000000
78345 +};
78346 +
78347 +/* ACL Object-only mode flags */
78348 +enum {
78349 + GR_READ = 0x00000001,
78350 + GR_APPEND = 0x00000002,
78351 + GR_WRITE = 0x00000004,
78352 + GR_EXEC = 0x00000008,
78353 + GR_FIND = 0x00000010,
78354 + GR_INHERIT = 0x00000020,
78355 + GR_SETID = 0x00000040,
78356 + GR_CREATE = 0x00000080,
78357 + GR_DELETE = 0x00000100,
78358 + GR_LINK = 0x00000200,
78359 + GR_AUDIT_READ = 0x00000400,
78360 + GR_AUDIT_APPEND = 0x00000800,
78361 + GR_AUDIT_WRITE = 0x00001000,
78362 + GR_AUDIT_EXEC = 0x00002000,
78363 + GR_AUDIT_FIND = 0x00004000,
78364 + GR_AUDIT_INHERIT= 0x00008000,
78365 + GR_AUDIT_SETID = 0x00010000,
78366 + GR_AUDIT_CREATE = 0x00020000,
78367 + GR_AUDIT_DELETE = 0x00040000,
78368 + GR_AUDIT_LINK = 0x00080000,
78369 + GR_PTRACERD = 0x00100000,
78370 + GR_NOPTRACE = 0x00200000,
78371 + GR_SUPPRESS = 0x00400000,
78372 + GR_NOLEARN = 0x00800000,
78373 + GR_INIT_TRANSFER= 0x01000000
78374 +};
78375 +
78376 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78377 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78378 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78379 +
78380 +/* ACL subject-only mode flags */
78381 +enum {
78382 + GR_KILL = 0x00000001,
78383 + GR_VIEW = 0x00000002,
78384 + GR_PROTECTED = 0x00000004,
78385 + GR_LEARN = 0x00000008,
78386 + GR_OVERRIDE = 0x00000010,
78387 + /* just a placeholder, this mode is only used in userspace */
78388 + GR_DUMMY = 0x00000020,
78389 + GR_PROTSHM = 0x00000040,
78390 + GR_KILLPROC = 0x00000080,
78391 + GR_KILLIPPROC = 0x00000100,
78392 + /* just a placeholder, this mode is only used in userspace */
78393 + GR_NOTROJAN = 0x00000200,
78394 + GR_PROTPROCFD = 0x00000400,
78395 + GR_PROCACCT = 0x00000800,
78396 + GR_RELAXPTRACE = 0x00001000,
78397 + //GR_NESTED = 0x00002000,
78398 + GR_INHERITLEARN = 0x00004000,
78399 + GR_PROCFIND = 0x00008000,
78400 + GR_POVERRIDE = 0x00010000,
78401 + GR_KERNELAUTH = 0x00020000,
78402 + GR_ATSECURE = 0x00040000,
78403 + GR_SHMEXEC = 0x00080000
78404 +};
78405 +
78406 +enum {
78407 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
78408 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
78409 + GR_PAX_ENABLE_MPROTECT = 0x0004,
78410 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
78411 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
78412 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
78413 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
78414 + GR_PAX_DISABLE_MPROTECT = 0x0400,
78415 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
78416 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
78417 +};
78418 +
78419 +enum {
78420 + GR_ID_USER = 0x01,
78421 + GR_ID_GROUP = 0x02,
78422 +};
78423 +
78424 +enum {
78425 + GR_ID_ALLOW = 0x01,
78426 + GR_ID_DENY = 0x02,
78427 +};
78428 +
78429 +#define GR_CRASH_RES 31
78430 +#define GR_UIDTABLE_MAX 500
78431 +
78432 +/* begin resource learning section */
78433 +enum {
78434 + GR_RLIM_CPU_BUMP = 60,
78435 + GR_RLIM_FSIZE_BUMP = 50000,
78436 + GR_RLIM_DATA_BUMP = 10000,
78437 + GR_RLIM_STACK_BUMP = 1000,
78438 + GR_RLIM_CORE_BUMP = 10000,
78439 + GR_RLIM_RSS_BUMP = 500000,
78440 + GR_RLIM_NPROC_BUMP = 1,
78441 + GR_RLIM_NOFILE_BUMP = 5,
78442 + GR_RLIM_MEMLOCK_BUMP = 50000,
78443 + GR_RLIM_AS_BUMP = 500000,
78444 + GR_RLIM_LOCKS_BUMP = 2,
78445 + GR_RLIM_SIGPENDING_BUMP = 5,
78446 + GR_RLIM_MSGQUEUE_BUMP = 10000,
78447 + GR_RLIM_NICE_BUMP = 1,
78448 + GR_RLIM_RTPRIO_BUMP = 1,
78449 + GR_RLIM_RTTIME_BUMP = 1000000
78450 +};
78451 +
78452 +#endif
78453 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
78454 new file mode 100644
78455 index 0000000..d25522e
78456 --- /dev/null
78457 +++ b/include/linux/grinternal.h
78458 @@ -0,0 +1,229 @@
78459 +#ifndef __GRINTERNAL_H
78460 +#define __GRINTERNAL_H
78461 +
78462 +#ifdef CONFIG_GRKERNSEC
78463 +
78464 +#include <linux/fs.h>
78465 +#include <linux/mnt_namespace.h>
78466 +#include <linux/nsproxy.h>
78467 +#include <linux/gracl.h>
78468 +#include <linux/grdefs.h>
78469 +#include <linux/grmsg.h>
78470 +
78471 +void gr_add_learn_entry(const char *fmt, ...)
78472 + __attribute__ ((format (printf, 1, 2)));
78473 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
78474 + const struct vfsmount *mnt);
78475 +__u32 gr_check_create(const struct dentry *new_dentry,
78476 + const struct dentry *parent,
78477 + const struct vfsmount *mnt, const __u32 mode);
78478 +int gr_check_protected_task(const struct task_struct *task);
78479 +__u32 to_gr_audit(const __u32 reqmode);
78480 +int gr_set_acls(const int type);
78481 +int gr_acl_is_enabled(void);
78482 +char gr_roletype_to_char(void);
78483 +
78484 +void gr_handle_alertkill(struct task_struct *task);
78485 +char *gr_to_filename(const struct dentry *dentry,
78486 + const struct vfsmount *mnt);
78487 +char *gr_to_filename1(const struct dentry *dentry,
78488 + const struct vfsmount *mnt);
78489 +char *gr_to_filename2(const struct dentry *dentry,
78490 + const struct vfsmount *mnt);
78491 +char *gr_to_filename3(const struct dentry *dentry,
78492 + const struct vfsmount *mnt);
78493 +
78494 +extern int grsec_enable_ptrace_readexec;
78495 +extern int grsec_enable_harden_ptrace;
78496 +extern int grsec_enable_link;
78497 +extern int grsec_enable_fifo;
78498 +extern int grsec_enable_execve;
78499 +extern int grsec_enable_shm;
78500 +extern int grsec_enable_execlog;
78501 +extern int grsec_enable_signal;
78502 +extern int grsec_enable_audit_ptrace;
78503 +extern int grsec_enable_forkfail;
78504 +extern int grsec_enable_time;
78505 +extern int grsec_enable_rofs;
78506 +extern int grsec_deny_new_usb;
78507 +extern int grsec_enable_chroot_shmat;
78508 +extern int grsec_enable_chroot_mount;
78509 +extern int grsec_enable_chroot_double;
78510 +extern int grsec_enable_chroot_pivot;
78511 +extern int grsec_enable_chroot_chdir;
78512 +extern int grsec_enable_chroot_chmod;
78513 +extern int grsec_enable_chroot_mknod;
78514 +extern int grsec_enable_chroot_fchdir;
78515 +extern int grsec_enable_chroot_nice;
78516 +extern int grsec_enable_chroot_execlog;
78517 +extern int grsec_enable_chroot_caps;
78518 +extern int grsec_enable_chroot_sysctl;
78519 +extern int grsec_enable_chroot_unix;
78520 +extern int grsec_enable_symlinkown;
78521 +extern kgid_t grsec_symlinkown_gid;
78522 +extern int grsec_enable_tpe;
78523 +extern kgid_t grsec_tpe_gid;
78524 +extern int grsec_enable_tpe_all;
78525 +extern int grsec_enable_tpe_invert;
78526 +extern int grsec_enable_socket_all;
78527 +extern kgid_t grsec_socket_all_gid;
78528 +extern int grsec_enable_socket_client;
78529 +extern kgid_t grsec_socket_client_gid;
78530 +extern int grsec_enable_socket_server;
78531 +extern kgid_t grsec_socket_server_gid;
78532 +extern kgid_t grsec_audit_gid;
78533 +extern int grsec_enable_group;
78534 +extern int grsec_enable_log_rwxmaps;
78535 +extern int grsec_enable_mount;
78536 +extern int grsec_enable_chdir;
78537 +extern int grsec_resource_logging;
78538 +extern int grsec_enable_blackhole;
78539 +extern int grsec_lastack_retries;
78540 +extern int grsec_enable_brute;
78541 +extern int grsec_enable_harden_ipc;
78542 +extern int grsec_lock;
78543 +
78544 +extern spinlock_t grsec_alert_lock;
78545 +extern unsigned long grsec_alert_wtime;
78546 +extern unsigned long grsec_alert_fyet;
78547 +
78548 +extern spinlock_t grsec_audit_lock;
78549 +
78550 +extern rwlock_t grsec_exec_file_lock;
78551 +
78552 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
78553 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
78554 + (tsk)->exec_file->f_path.mnt) : "/")
78555 +
78556 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
78557 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
78558 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78559 +
78560 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
78561 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
78562 + (tsk)->exec_file->f_path.mnt) : "/")
78563 +
78564 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
78565 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
78566 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78567 +
78568 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
78569 +
78570 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
78571 +
78572 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
78573 +{
78574 + if (file1 && file2) {
78575 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
78576 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
78577 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
78578 + return true;
78579 + }
78580 +
78581 + return false;
78582 +}
78583 +
78584 +#define GR_CHROOT_CAPS {{ \
78585 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
78586 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
78587 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
78588 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
78589 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
78590 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
78591 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
78592 +
78593 +#define security_learn(normal_msg,args...) \
78594 +({ \
78595 + read_lock(&grsec_exec_file_lock); \
78596 + gr_add_learn_entry(normal_msg "\n", ## args); \
78597 + read_unlock(&grsec_exec_file_lock); \
78598 +})
78599 +
78600 +enum {
78601 + GR_DO_AUDIT,
78602 + GR_DONT_AUDIT,
78603 + /* used for non-audit messages that we shouldn't kill the task on */
78604 + GR_DONT_AUDIT_GOOD
78605 +};
78606 +
78607 +enum {
78608 + GR_TTYSNIFF,
78609 + GR_RBAC,
78610 + GR_RBAC_STR,
78611 + GR_STR_RBAC,
78612 + GR_RBAC_MODE2,
78613 + GR_RBAC_MODE3,
78614 + GR_FILENAME,
78615 + GR_SYSCTL_HIDDEN,
78616 + GR_NOARGS,
78617 + GR_ONE_INT,
78618 + GR_ONE_INT_TWO_STR,
78619 + GR_ONE_STR,
78620 + GR_STR_INT,
78621 + GR_TWO_STR_INT,
78622 + GR_TWO_INT,
78623 + GR_TWO_U64,
78624 + GR_THREE_INT,
78625 + GR_FIVE_INT_TWO_STR,
78626 + GR_TWO_STR,
78627 + GR_THREE_STR,
78628 + GR_FOUR_STR,
78629 + GR_STR_FILENAME,
78630 + GR_FILENAME_STR,
78631 + GR_FILENAME_TWO_INT,
78632 + GR_FILENAME_TWO_INT_STR,
78633 + GR_TEXTREL,
78634 + GR_PTRACE,
78635 + GR_RESOURCE,
78636 + GR_CAP,
78637 + GR_SIG,
78638 + GR_SIG2,
78639 + GR_CRASH1,
78640 + GR_CRASH2,
78641 + GR_PSACCT,
78642 + GR_RWXMAP,
78643 + GR_RWXMAPVMA
78644 +};
78645 +
78646 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
78647 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
78648 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
78649 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
78650 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
78651 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
78652 +#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)
78653 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
78654 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
78655 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
78656 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
78657 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
78658 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
78659 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
78660 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
78661 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
78662 +#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)
78663 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
78664 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
78665 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
78666 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
78667 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
78668 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
78669 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
78670 +#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)
78671 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
78672 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
78673 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
78674 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
78675 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
78676 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
78677 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
78678 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
78679 +#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)
78680 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
78681 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
78682 +
78683 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
78684 +
78685 +#endif
78686 +
78687 +#endif
78688 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
78689 new file mode 100644
78690 index 0000000..ba93581
78691 --- /dev/null
78692 +++ b/include/linux/grmsg.h
78693 @@ -0,0 +1,116 @@
78694 +#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"
78695 +#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"
78696 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
78697 +#define GR_STOPMOD_MSG "denied modification of module state by "
78698 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
78699 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
78700 +#define GR_IOPERM_MSG "denied use of ioperm() by "
78701 +#define GR_IOPL_MSG "denied use of iopl() by "
78702 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
78703 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
78704 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
78705 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
78706 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
78707 +#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"
78708 +#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"
78709 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
78710 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
78711 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
78712 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
78713 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
78714 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
78715 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
78716 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
78717 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
78718 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
78719 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
78720 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
78721 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
78722 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
78723 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
78724 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
78725 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
78726 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
78727 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
78728 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
78729 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
78730 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
78731 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
78732 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
78733 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
78734 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
78735 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
78736 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
78737 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
78738 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
78739 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
78740 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
78741 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
78742 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
78743 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
78744 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
78745 +#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"
78746 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
78747 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
78748 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
78749 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
78750 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
78751 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
78752 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
78753 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
78754 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
78755 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
78756 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
78757 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
78758 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
78759 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
78760 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
78761 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
78762 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
78763 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
78764 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
78765 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
78766 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
78767 +#define GR_NICE_CHROOT_MSG "denied priority change by "
78768 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
78769 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
78770 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
78771 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
78772 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
78773 +#define GR_TIME_MSG "time set by "
78774 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
78775 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
78776 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
78777 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
78778 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
78779 +#define GR_BIND_MSG "denied bind() by "
78780 +#define GR_CONNECT_MSG "denied connect() by "
78781 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
78782 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
78783 +#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"
78784 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
78785 +#define GR_CAP_ACL_MSG "use of %s denied for "
78786 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
78787 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
78788 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
78789 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
78790 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
78791 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
78792 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
78793 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
78794 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
78795 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
78796 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
78797 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
78798 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
78799 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
78800 +#define GR_VM86_MSG "denied use of vm86 by "
78801 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
78802 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
78803 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
78804 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
78805 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
78806 +#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 "
78807 +#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 "
78808 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
78809 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
78810 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
78811 new file mode 100644
78812 index 0000000..8108301
78813 --- /dev/null
78814 +++ b/include/linux/grsecurity.h
78815 @@ -0,0 +1,246 @@
78816 +#ifndef GR_SECURITY_H
78817 +#define GR_SECURITY_H
78818 +#include <linux/fs.h>
78819 +#include <linux/fs_struct.h>
78820 +#include <linux/binfmts.h>
78821 +#include <linux/gracl.h>
78822 +
78823 +/* notify of brain-dead configs */
78824 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78825 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
78826 +#endif
78827 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
78828 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
78829 +#endif
78830 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
78831 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
78832 +#endif
78833 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
78834 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
78835 +#endif
78836 +
78837 +int gr_handle_new_usb(void);
78838 +
78839 +void gr_handle_brute_attach(int dumpable);
78840 +void gr_handle_brute_check(void);
78841 +void gr_handle_kernel_exploit(void);
78842 +
78843 +char gr_roletype_to_char(void);
78844 +
78845 +int gr_acl_enable_at_secure(void);
78846 +
78847 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
78848 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
78849 +
78850 +void gr_del_task_from_ip_table(struct task_struct *p);
78851 +
78852 +int gr_pid_is_chrooted(struct task_struct *p);
78853 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
78854 +int gr_handle_chroot_nice(void);
78855 +int gr_handle_chroot_sysctl(const int op);
78856 +int gr_handle_chroot_setpriority(struct task_struct *p,
78857 + const int niceval);
78858 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
78859 +int gr_handle_chroot_chroot(const struct dentry *dentry,
78860 + const struct vfsmount *mnt);
78861 +void gr_handle_chroot_chdir(const struct path *path);
78862 +int gr_handle_chroot_chmod(const struct dentry *dentry,
78863 + const struct vfsmount *mnt, const int mode);
78864 +int gr_handle_chroot_mknod(const struct dentry *dentry,
78865 + const struct vfsmount *mnt, const int mode);
78866 +int gr_handle_chroot_mount(const struct dentry *dentry,
78867 + const struct vfsmount *mnt,
78868 + const char *dev_name);
78869 +int gr_handle_chroot_pivot(void);
78870 +int gr_handle_chroot_unix(const pid_t pid);
78871 +
78872 +int gr_handle_rawio(const struct inode *inode);
78873 +
78874 +void gr_handle_ioperm(void);
78875 +void gr_handle_iopl(void);
78876 +void gr_handle_msr_write(void);
78877 +
78878 +umode_t gr_acl_umask(void);
78879 +
78880 +int gr_tpe_allow(const struct file *file);
78881 +
78882 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
78883 +void gr_clear_chroot_entries(struct task_struct *task);
78884 +
78885 +void gr_log_forkfail(const int retval);
78886 +void gr_log_timechange(void);
78887 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
78888 +void gr_log_chdir(const struct dentry *dentry,
78889 + const struct vfsmount *mnt);
78890 +void gr_log_chroot_exec(const struct dentry *dentry,
78891 + const struct vfsmount *mnt);
78892 +void gr_log_remount(const char *devname, const int retval);
78893 +void gr_log_unmount(const char *devname, const int retval);
78894 +void gr_log_mount(const char *from, const char *to, const int retval);
78895 +void gr_log_textrel(struct vm_area_struct *vma);
78896 +void gr_log_ptgnustack(struct file *file);
78897 +void gr_log_rwxmmap(struct file *file);
78898 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
78899 +
78900 +int gr_handle_follow_link(const struct inode *parent,
78901 + const struct inode *inode,
78902 + const struct dentry *dentry,
78903 + const struct vfsmount *mnt);
78904 +int gr_handle_fifo(const struct dentry *dentry,
78905 + const struct vfsmount *mnt,
78906 + const struct dentry *dir, const int flag,
78907 + const int acc_mode);
78908 +int gr_handle_hardlink(const struct dentry *dentry,
78909 + const struct vfsmount *mnt,
78910 + struct inode *inode,
78911 + const int mode, const struct filename *to);
78912 +
78913 +int gr_is_capable(const int cap);
78914 +int gr_is_capable_nolog(const int cap);
78915 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
78916 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
78917 +
78918 +void gr_copy_label(struct task_struct *tsk);
78919 +void gr_handle_crash(struct task_struct *task, const int sig);
78920 +int gr_handle_signal(const struct task_struct *p, const int sig);
78921 +int gr_check_crash_uid(const kuid_t uid);
78922 +int gr_check_protected_task(const struct task_struct *task);
78923 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
78924 +int gr_acl_handle_mmap(const struct file *file,
78925 + const unsigned long prot);
78926 +int gr_acl_handle_mprotect(const struct file *file,
78927 + const unsigned long prot);
78928 +int gr_check_hidden_task(const struct task_struct *tsk);
78929 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
78930 + const struct vfsmount *mnt);
78931 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
78932 + const struct vfsmount *mnt);
78933 +__u32 gr_acl_handle_access(const struct dentry *dentry,
78934 + const struct vfsmount *mnt, const int fmode);
78935 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
78936 + const struct vfsmount *mnt, umode_t *mode);
78937 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
78938 + const struct vfsmount *mnt);
78939 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
78940 + const struct vfsmount *mnt);
78941 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
78942 + const struct vfsmount *mnt);
78943 +int gr_handle_ptrace(struct task_struct *task, const long request);
78944 +int gr_handle_proc_ptrace(struct task_struct *task);
78945 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
78946 + const struct vfsmount *mnt);
78947 +int gr_check_crash_exec(const struct file *filp);
78948 +int gr_acl_is_enabled(void);
78949 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
78950 + const kgid_t gid);
78951 +int gr_set_proc_label(const struct dentry *dentry,
78952 + const struct vfsmount *mnt,
78953 + const int unsafe_flags);
78954 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
78955 + const struct vfsmount *mnt);
78956 +__u32 gr_acl_handle_open(const struct dentry *dentry,
78957 + const struct vfsmount *mnt, int acc_mode);
78958 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
78959 + const struct dentry *p_dentry,
78960 + const struct vfsmount *p_mnt,
78961 + int open_flags, int acc_mode, const int imode);
78962 +void gr_handle_create(const struct dentry *dentry,
78963 + const struct vfsmount *mnt);
78964 +void gr_handle_proc_create(const struct dentry *dentry,
78965 + const struct inode *inode);
78966 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
78967 + const struct dentry *parent_dentry,
78968 + const struct vfsmount *parent_mnt,
78969 + const int mode);
78970 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
78971 + const struct dentry *parent_dentry,
78972 + const struct vfsmount *parent_mnt);
78973 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
78974 + const struct vfsmount *mnt);
78975 +void gr_handle_delete(const ino_t ino, const dev_t dev);
78976 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
78977 + const struct vfsmount *mnt);
78978 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
78979 + const struct dentry *parent_dentry,
78980 + const struct vfsmount *parent_mnt,
78981 + const struct filename *from);
78982 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
78983 + const struct dentry *parent_dentry,
78984 + const struct vfsmount *parent_mnt,
78985 + const struct dentry *old_dentry,
78986 + const struct vfsmount *old_mnt, const struct filename *to);
78987 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
78988 +int gr_acl_handle_rename(struct dentry *new_dentry,
78989 + struct dentry *parent_dentry,
78990 + const struct vfsmount *parent_mnt,
78991 + struct dentry *old_dentry,
78992 + struct inode *old_parent_inode,
78993 + struct vfsmount *old_mnt, const struct filename *newname);
78994 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
78995 + struct dentry *old_dentry,
78996 + struct dentry *new_dentry,
78997 + struct vfsmount *mnt, const __u8 replace);
78998 +__u32 gr_check_link(const struct dentry *new_dentry,
78999 + const struct dentry *parent_dentry,
79000 + const struct vfsmount *parent_mnt,
79001 + const struct dentry *old_dentry,
79002 + const struct vfsmount *old_mnt);
79003 +int gr_acl_handle_filldir(const struct file *file, const char *name,
79004 + const unsigned int namelen, const ino_t ino);
79005 +
79006 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
79007 + const struct vfsmount *mnt);
79008 +void gr_acl_handle_exit(void);
79009 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
79010 +int gr_acl_handle_procpidmem(const struct task_struct *task);
79011 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79012 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79013 +void gr_audit_ptrace(struct task_struct *task);
79014 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79015 +void gr_put_exec_file(struct task_struct *task);
79016 +
79017 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79018 +
79019 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79020 +extern void gr_learn_resource(const struct task_struct *task, const int res,
79021 + const unsigned long wanted, const int gt);
79022 +#else
79023 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
79024 + const unsigned long wanted, const int gt)
79025 +{
79026 +}
79027 +#endif
79028 +
79029 +#ifdef CONFIG_GRKERNSEC_RESLOG
79030 +extern void gr_log_resource(const struct task_struct *task, const int res,
79031 + const unsigned long wanted, const int gt);
79032 +#else
79033 +static inline void gr_log_resource(const struct task_struct *task, const int res,
79034 + const unsigned long wanted, const int gt)
79035 +{
79036 +}
79037 +#endif
79038 +
79039 +#ifdef CONFIG_GRKERNSEC
79040 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79041 +void gr_handle_vm86(void);
79042 +void gr_handle_mem_readwrite(u64 from, u64 to);
79043 +
79044 +void gr_log_badprocpid(const char *entry);
79045 +
79046 +extern int grsec_enable_dmesg;
79047 +extern int grsec_disable_privio;
79048 +
79049 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79050 +extern kgid_t grsec_proc_gid;
79051 +#endif
79052 +
79053 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79054 +extern int grsec_enable_chroot_findtask;
79055 +#endif
79056 +#ifdef CONFIG_GRKERNSEC_SETXID
79057 +extern int grsec_enable_setxid;
79058 +#endif
79059 +#endif
79060 +
79061 +#endif
79062 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79063 new file mode 100644
79064 index 0000000..e7ffaaf
79065 --- /dev/null
79066 +++ b/include/linux/grsock.h
79067 @@ -0,0 +1,19 @@
79068 +#ifndef __GRSOCK_H
79069 +#define __GRSOCK_H
79070 +
79071 +extern void gr_attach_curr_ip(const struct sock *sk);
79072 +extern int gr_handle_sock_all(const int family, const int type,
79073 + const int protocol);
79074 +extern int gr_handle_sock_server(const struct sockaddr *sck);
79075 +extern int gr_handle_sock_server_other(const struct sock *sck);
79076 +extern int gr_handle_sock_client(const struct sockaddr *sck);
79077 +extern int gr_search_connect(struct socket * sock,
79078 + struct sockaddr_in * addr);
79079 +extern int gr_search_bind(struct socket * sock,
79080 + struct sockaddr_in * addr);
79081 +extern int gr_search_listen(struct socket * sock);
79082 +extern int gr_search_accept(struct socket * sock);
79083 +extern int gr_search_socket(const int domain, const int type,
79084 + const int protocol);
79085 +
79086 +#endif
79087 diff --git a/include/linux/hash.h b/include/linux/hash.h
79088 index bd1754c..8240892 100644
79089 --- a/include/linux/hash.h
79090 +++ b/include/linux/hash.h
79091 @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
79092 struct fast_hash_ops {
79093 u32 (*hash)(const void *data, u32 len, u32 seed);
79094 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
79095 -};
79096 +} __no_const;
79097
79098 /**
79099 * arch_fast_hash - Caclulates a hash over a given buffer that can have
79100 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79101 index 7fb31da..08b5114 100644
79102 --- a/include/linux/highmem.h
79103 +++ b/include/linux/highmem.h
79104 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79105 kunmap_atomic(kaddr);
79106 }
79107
79108 +static inline void sanitize_highpage(struct page *page)
79109 +{
79110 + void *kaddr;
79111 + unsigned long flags;
79112 +
79113 + local_irq_save(flags);
79114 + kaddr = kmap_atomic(page);
79115 + clear_page(kaddr);
79116 + kunmap_atomic(kaddr);
79117 + local_irq_restore(flags);
79118 +}
79119 +
79120 static inline void zero_user_segments(struct page *page,
79121 unsigned start1, unsigned end1,
79122 unsigned start2, unsigned end2)
79123 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79124 index 1c7b89a..7dda400 100644
79125 --- a/include/linux/hwmon-sysfs.h
79126 +++ b/include/linux/hwmon-sysfs.h
79127 @@ -25,7 +25,8 @@
79128 struct sensor_device_attribute{
79129 struct device_attribute dev_attr;
79130 int index;
79131 -};
79132 +} __do_const;
79133 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79134 #define to_sensor_dev_attr(_dev_attr) \
79135 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79136
79137 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79138 struct device_attribute dev_attr;
79139 u8 index;
79140 u8 nr;
79141 -};
79142 +} __do_const;
79143 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79144 #define to_sensor_dev_attr_2(_dev_attr) \
79145 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79146
79147 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79148 index deddeb8..bcaf62d 100644
79149 --- a/include/linux/i2c.h
79150 +++ b/include/linux/i2c.h
79151 @@ -378,6 +378,7 @@ struct i2c_algorithm {
79152 /* To determine what the adapter supports */
79153 u32 (*functionality) (struct i2c_adapter *);
79154 };
79155 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79156
79157 /**
79158 * struct i2c_bus_recovery_info - I2C bus recovery information
79159 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79160 index d23c3c2..eb63c81 100644
79161 --- a/include/linux/i2o.h
79162 +++ b/include/linux/i2o.h
79163 @@ -565,7 +565,7 @@ struct i2o_controller {
79164 struct i2o_device *exec; /* Executive */
79165 #if BITS_PER_LONG == 64
79166 spinlock_t context_list_lock; /* lock for context_list */
79167 - atomic_t context_list_counter; /* needed for unique contexts */
79168 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79169 struct list_head context_list; /* list of context id's
79170 and pointers */
79171 #endif
79172 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79173 index aff7ad8..3942bbd 100644
79174 --- a/include/linux/if_pppox.h
79175 +++ b/include/linux/if_pppox.h
79176 @@ -76,7 +76,7 @@ struct pppox_proto {
79177 int (*ioctl)(struct socket *sock, unsigned int cmd,
79178 unsigned long arg);
79179 struct module *owner;
79180 -};
79181 +} __do_const;
79182
79183 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79184 extern void unregister_pppox_proto(int proto_num);
79185 diff --git a/include/linux/init.h b/include/linux/init.h
79186 index e168880..d9b489d 100644
79187 --- a/include/linux/init.h
79188 +++ b/include/linux/init.h
79189 @@ -37,9 +37,17 @@
79190 * section.
79191 */
79192
79193 +#define add_init_latent_entropy __latent_entropy
79194 +
79195 +#ifdef CONFIG_MEMORY_HOTPLUG
79196 +#define add_meminit_latent_entropy
79197 +#else
79198 +#define add_meminit_latent_entropy __latent_entropy
79199 +#endif
79200 +
79201 /* These are for everybody (although not all archs will actually
79202 discard it in modules) */
79203 -#define __init __section(.init.text) __cold notrace
79204 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79205 #define __initdata __section(.init.data)
79206 #define __initconst __constsection(.init.rodata)
79207 #define __exitdata __section(.exit.data)
79208 @@ -100,7 +108,7 @@
79209 #define __cpuexitconst
79210
79211 /* Used for MEMORY_HOTPLUG */
79212 -#define __meminit __section(.meminit.text) __cold notrace
79213 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79214 #define __meminitdata __section(.meminit.data)
79215 #define __meminitconst __constsection(.meminit.rodata)
79216 #define __memexit __section(.memexit.text) __exitused __cold notrace
79217 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79218 index 6df7f9f..d0bf699 100644
79219 --- a/include/linux/init_task.h
79220 +++ b/include/linux/init_task.h
79221 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
79222
79223 #define INIT_TASK_COMM "swapper"
79224
79225 +#ifdef CONFIG_X86
79226 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79227 +#else
79228 +#define INIT_TASK_THREAD_INFO
79229 +#endif
79230 +
79231 #ifdef CONFIG_RT_MUTEXES
79232 # define INIT_RT_MUTEXES(tsk) \
79233 .pi_waiters = RB_ROOT, \
79234 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
79235 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79236 .comm = INIT_TASK_COMM, \
79237 .thread = INIT_THREAD, \
79238 + INIT_TASK_THREAD_INFO \
79239 .fs = &init_fs, \
79240 .files = &init_files, \
79241 .signal = &init_signals, \
79242 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79243 index a2678d3..e411b1b 100644
79244 --- a/include/linux/interrupt.h
79245 +++ b/include/linux/interrupt.h
79246 @@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
79247
79248 struct softirq_action
79249 {
79250 - void (*action)(struct softirq_action *);
79251 -};
79252 + void (*action)(void);
79253 +} __no_const;
79254
79255 asmlinkage void do_softirq(void);
79256 asmlinkage void __do_softirq(void);
79257 @@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
79258 }
79259 #endif
79260
79261 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79262 +extern void open_softirq(int nr, void (*action)(void));
79263 extern void softirq_init(void);
79264 extern void __raise_softirq_irqoff(unsigned int nr);
79265
79266 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79267 index b96a5b2..2732d1c 100644
79268 --- a/include/linux/iommu.h
79269 +++ b/include/linux/iommu.h
79270 @@ -131,7 +131,7 @@ struct iommu_ops {
79271 u32 (*domain_get_windows)(struct iommu_domain *domain);
79272
79273 unsigned long pgsize_bitmap;
79274 -};
79275 +} __do_const;
79276
79277 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79278 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79279 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79280 index 89b7c24..382af74 100644
79281 --- a/include/linux/ioport.h
79282 +++ b/include/linux/ioport.h
79283 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79284 int adjust_resource(struct resource *res, resource_size_t start,
79285 resource_size_t size);
79286 resource_size_t resource_alignment(struct resource *res);
79287 -static inline resource_size_t resource_size(const struct resource *res)
79288 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79289 {
79290 return res->end - res->start + 1;
79291 }
79292 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79293 index 35e7eca..6afb7ad 100644
79294 --- a/include/linux/ipc_namespace.h
79295 +++ b/include/linux/ipc_namespace.h
79296 @@ -69,7 +69,7 @@ struct ipc_namespace {
79297 struct user_namespace *user_ns;
79298
79299 unsigned int proc_inum;
79300 -};
79301 +} __randomize_layout;
79302
79303 extern struct ipc_namespace init_ipc_ns;
79304 extern atomic_t nr_ipc_ns;
79305 diff --git a/include/linux/irq.h b/include/linux/irq.h
79306 index 7dc1003..407327b 100644
79307 --- a/include/linux/irq.h
79308 +++ b/include/linux/irq.h
79309 @@ -338,7 +338,8 @@ struct irq_chip {
79310 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79311
79312 unsigned long flags;
79313 -};
79314 +} __do_const;
79315 +typedef struct irq_chip __no_const irq_chip_no_const;
79316
79317 /*
79318 * irq_chip specific flags
79319 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79320 index 0ceb389..eed3fb8 100644
79321 --- a/include/linux/irqchip/arm-gic.h
79322 +++ b/include/linux/irqchip/arm-gic.h
79323 @@ -73,9 +73,11 @@
79324
79325 #ifndef __ASSEMBLY__
79326
79327 +#include <linux/irq.h>
79328 +
79329 struct device_node;
79330
79331 -extern struct irq_chip gic_arch_extn;
79332 +extern irq_chip_no_const gic_arch_extn;
79333
79334 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79335 u32 offset, struct device_node *);
79336 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79337 index 1f44466..b481806 100644
79338 --- a/include/linux/jiffies.h
79339 +++ b/include/linux/jiffies.h
79340 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
79341 /*
79342 * Convert various time units to each other:
79343 */
79344 -extern unsigned int jiffies_to_msecs(const unsigned long j);
79345 -extern unsigned int jiffies_to_usecs(const unsigned long j);
79346 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79347 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79348
79349 -static inline u64 jiffies_to_nsecs(const unsigned long j)
79350 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
79351 {
79352 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
79353 }
79354
79355 -extern unsigned long msecs_to_jiffies(const unsigned int m);
79356 -extern unsigned long usecs_to_jiffies(const unsigned int u);
79357 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79358 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79359 extern unsigned long timespec_to_jiffies(const struct timespec *value);
79360 extern void jiffies_to_timespec(const unsigned long jiffies,
79361 - struct timespec *value);
79362 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
79363 + struct timespec *value) __intentional_overflow(-1);
79364 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79365 extern void jiffies_to_timeval(const unsigned long jiffies,
79366 struct timeval *value);
79367
79368 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79369 index 6883e19..e854fcb 100644
79370 --- a/include/linux/kallsyms.h
79371 +++ b/include/linux/kallsyms.h
79372 @@ -15,7 +15,8 @@
79373
79374 struct module;
79375
79376 -#ifdef CONFIG_KALLSYMS
79377 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
79378 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79379 /* Lookup the address for a symbol. Returns 0 if not found. */
79380 unsigned long kallsyms_lookup_name(const char *name);
79381
79382 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
79383 /* Stupid that this does nothing, but I didn't create this mess. */
79384 #define __print_symbol(fmt, addr)
79385 #endif /*CONFIG_KALLSYMS*/
79386 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
79387 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
79388 +extern unsigned long kallsyms_lookup_name(const char *name);
79389 +extern void __print_symbol(const char *fmt, unsigned long address);
79390 +extern int sprint_backtrace(char *buffer, unsigned long address);
79391 +extern int sprint_symbol(char *buffer, unsigned long address);
79392 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
79393 +const char *kallsyms_lookup(unsigned long addr,
79394 + unsigned long *symbolsize,
79395 + unsigned long *offset,
79396 + char **modname, char *namebuf);
79397 +extern int kallsyms_lookup_size_offset(unsigned long addr,
79398 + unsigned long *symbolsize,
79399 + unsigned long *offset);
79400 +#endif
79401
79402 /* This macro allows us to keep printk typechecking */
79403 static __printf(1, 2)
79404 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
79405 index a74c3a8..28d3f21 100644
79406 --- a/include/linux/key-type.h
79407 +++ b/include/linux/key-type.h
79408 @@ -131,7 +131,7 @@ struct key_type {
79409 /* internal fields */
79410 struct list_head link; /* link in types list */
79411 struct lock_class_key lock_class; /* key->sem lock class */
79412 -};
79413 +} __do_const;
79414
79415 extern struct key_type key_type_keyring;
79416
79417 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
79418 index 6b06d37..c134867 100644
79419 --- a/include/linux/kgdb.h
79420 +++ b/include/linux/kgdb.h
79421 @@ -52,7 +52,7 @@ extern int kgdb_connected;
79422 extern int kgdb_io_module_registered;
79423
79424 extern atomic_t kgdb_setting_breakpoint;
79425 -extern atomic_t kgdb_cpu_doing_single_step;
79426 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
79427
79428 extern struct task_struct *kgdb_usethread;
79429 extern struct task_struct *kgdb_contthread;
79430 @@ -254,7 +254,7 @@ struct kgdb_arch {
79431 void (*correct_hw_break)(void);
79432
79433 void (*enable_nmi)(bool on);
79434 -};
79435 +} __do_const;
79436
79437 /**
79438 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
79439 @@ -279,7 +279,7 @@ struct kgdb_io {
79440 void (*pre_exception) (void);
79441 void (*post_exception) (void);
79442 int is_console;
79443 -};
79444 +} __do_const;
79445
79446 extern struct kgdb_arch arch_kgdb_ops;
79447
79448 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
79449 index 0555cc6..40116ce 100644
79450 --- a/include/linux/kmod.h
79451 +++ b/include/linux/kmod.h
79452 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
79453 * usually useless though. */
79454 extern __printf(2, 3)
79455 int __request_module(bool wait, const char *name, ...);
79456 +extern __printf(3, 4)
79457 +int ___request_module(bool wait, char *param_name, const char *name, ...);
79458 #define request_module(mod...) __request_module(true, mod)
79459 #define request_module_nowait(mod...) __request_module(false, mod)
79460 #define try_then_request_module(x, mod...) \
79461 @@ -57,6 +59,9 @@ struct subprocess_info {
79462 struct work_struct work;
79463 struct completion *complete;
79464 char *path;
79465 +#ifdef CONFIG_GRKERNSEC
79466 + char *origpath;
79467 +#endif
79468 char **argv;
79469 char **envp;
79470 int wait;
79471 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
79472 index 926afb6..58dd6e5 100644
79473 --- a/include/linux/kobject.h
79474 +++ b/include/linux/kobject.h
79475 @@ -116,7 +116,7 @@ struct kobj_type {
79476 struct attribute **default_attrs;
79477 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
79478 const void *(*namespace)(struct kobject *kobj);
79479 -};
79480 +} __do_const;
79481
79482 struct kobj_uevent_env {
79483 char *envp[UEVENT_NUM_ENVP];
79484 @@ -139,6 +139,7 @@ struct kobj_attribute {
79485 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
79486 const char *buf, size_t count);
79487 };
79488 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
79489
79490 extern const struct sysfs_ops kobj_sysfs_ops;
79491
79492 @@ -166,7 +167,7 @@ struct kset {
79493 spinlock_t list_lock;
79494 struct kobject kobj;
79495 const struct kset_uevent_ops *uevent_ops;
79496 -};
79497 +} __randomize_layout;
79498
79499 extern void kset_init(struct kset *kset);
79500 extern int __must_check kset_register(struct kset *kset);
79501 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
79502 index df32d25..fb52e27 100644
79503 --- a/include/linux/kobject_ns.h
79504 +++ b/include/linux/kobject_ns.h
79505 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
79506 const void *(*netlink_ns)(struct sock *sk);
79507 const void *(*initial_ns)(void);
79508 void (*drop_ns)(void *);
79509 -};
79510 +} __do_const;
79511
79512 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
79513 int kobj_ns_type_registered(enum kobj_ns_type type);
79514 diff --git a/include/linux/kref.h b/include/linux/kref.h
79515 index 484604d..0f6c5b6 100644
79516 --- a/include/linux/kref.h
79517 +++ b/include/linux/kref.h
79518 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
79519 static inline int kref_sub(struct kref *kref, unsigned int count,
79520 void (*release)(struct kref *kref))
79521 {
79522 - WARN_ON(release == NULL);
79523 + BUG_ON(release == NULL);
79524
79525 if (atomic_sub_and_test((int) count, &kref->refcount)) {
79526 release(kref);
79527 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
79528 index b8e9a43..632678d 100644
79529 --- a/include/linux/kvm_host.h
79530 +++ b/include/linux/kvm_host.h
79531 @@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
79532 {
79533 }
79534 #endif
79535 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79536 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79537 struct module *module);
79538 void kvm_exit(void);
79539
79540 @@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
79541 struct kvm_guest_debug *dbg);
79542 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
79543
79544 -int kvm_arch_init(void *opaque);
79545 +int kvm_arch_init(const void *opaque);
79546 void kvm_arch_exit(void);
79547
79548 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
79549 diff --git a/include/linux/libata.h b/include/linux/libata.h
79550 index bec6dbe..2873d64 100644
79551 --- a/include/linux/libata.h
79552 +++ b/include/linux/libata.h
79553 @@ -975,7 +975,7 @@ struct ata_port_operations {
79554 * fields must be pointers.
79555 */
79556 const struct ata_port_operations *inherits;
79557 -};
79558 +} __do_const;
79559
79560 struct ata_port_info {
79561 unsigned long flags;
79562 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
79563 index a6a42dd..6c5ebce 100644
79564 --- a/include/linux/linkage.h
79565 +++ b/include/linux/linkage.h
79566 @@ -36,6 +36,7 @@
79567 #endif
79568
79569 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
79570 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
79571 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
79572
79573 /*
79574 diff --git a/include/linux/list.h b/include/linux/list.h
79575 index ef95941..82db65a 100644
79576 --- a/include/linux/list.h
79577 +++ b/include/linux/list.h
79578 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
79579 extern void list_del(struct list_head *entry);
79580 #endif
79581
79582 +extern void __pax_list_add(struct list_head *new,
79583 + struct list_head *prev,
79584 + struct list_head *next);
79585 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
79586 +{
79587 + __pax_list_add(new, head, head->next);
79588 +}
79589 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
79590 +{
79591 + __pax_list_add(new, head->prev, head);
79592 +}
79593 +extern void pax_list_del(struct list_head *entry);
79594 +
79595 /**
79596 * list_replace - replace old entry by new one
79597 * @old : the element to be replaced
79598 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
79599 INIT_LIST_HEAD(entry);
79600 }
79601
79602 +extern void pax_list_del_init(struct list_head *entry);
79603 +
79604 /**
79605 * list_move - delete from one list and add as another's head
79606 * @list: the entry to move
79607 diff --git a/include/linux/math64.h b/include/linux/math64.h
79608 index c45c089..298841c 100644
79609 --- a/include/linux/math64.h
79610 +++ b/include/linux/math64.h
79611 @@ -15,7 +15,7 @@
79612 * This is commonly provided by 32bit archs to provide an optimized 64bit
79613 * divide.
79614 */
79615 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79616 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79617 {
79618 *remainder = dividend % divisor;
79619 return dividend / divisor;
79620 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
79621 /**
79622 * div64_u64 - unsigned 64bit divide with 64bit divisor
79623 */
79624 -static inline u64 div64_u64(u64 dividend, u64 divisor)
79625 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79626 {
79627 return dividend / divisor;
79628 }
79629 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
79630 #define div64_ul(x, y) div_u64((x), (y))
79631
79632 #ifndef div_u64_rem
79633 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79634 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79635 {
79636 *remainder = do_div(dividend, divisor);
79637 return dividend;
79638 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
79639 #endif
79640
79641 #ifndef div64_u64
79642 -extern u64 div64_u64(u64 dividend, u64 divisor);
79643 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
79644 #endif
79645
79646 #ifndef div64_s64
79647 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
79648 * divide.
79649 */
79650 #ifndef div_u64
79651 -static inline u64 div_u64(u64 dividend, u32 divisor)
79652 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
79653 {
79654 u32 remainder;
79655 return div_u64_rem(dividend, divisor, &remainder);
79656 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
79657 index 5f1ea75..5125ac5 100644
79658 --- a/include/linux/mempolicy.h
79659 +++ b/include/linux/mempolicy.h
79660 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
79661 }
79662
79663 #define vma_policy(vma) ((vma)->vm_policy)
79664 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79665 +{
79666 + vma->vm_policy = pol;
79667 +}
79668
79669 static inline void mpol_get(struct mempolicy *pol)
79670 {
79671 @@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
79672 }
79673
79674 #define vma_policy(vma) NULL
79675 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79676 +{
79677 +}
79678
79679 static inline int
79680 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
79681 diff --git a/include/linux/mm.h b/include/linux/mm.h
79682 index c1b7414..5ea2ad8 100644
79683 --- a/include/linux/mm.h
79684 +++ b/include/linux/mm.h
79685 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
79686 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
79687 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
79688 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
79689 +
79690 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
79691 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
79692 +#endif
79693 +
79694 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
79695
79696 #ifdef CONFIG_MEM_SOFT_DIRTY
79697 @@ -229,8 +234,8 @@ struct vm_operations_struct {
79698 /* called by access_process_vm when get_user_pages() fails, typically
79699 * for use by special VMAs that can switch between memory and hardware
79700 */
79701 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
79702 - void *buf, int len, int write);
79703 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
79704 + void *buf, size_t len, int write);
79705 #ifdef CONFIG_NUMA
79706 /*
79707 * set_policy() op must add a reference to any non-NULL @new mempolicy
79708 @@ -260,6 +265,7 @@ struct vm_operations_struct {
79709 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
79710 unsigned long size, pgoff_t pgoff);
79711 };
79712 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
79713
79714 struct mmu_gather;
79715 struct inode;
79716 @@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
79717 unsigned long *pfn);
79718 int follow_phys(struct vm_area_struct *vma, unsigned long address,
79719 unsigned int flags, unsigned long *prot, resource_size_t *phys);
79720 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79721 - void *buf, int len, int write);
79722 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79723 + void *buf, size_t len, int write);
79724
79725 static inline void unmap_shared_mapping_range(struct address_space *mapping,
79726 loff_t const holebegin, loff_t const holelen)
79727 @@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
79728 }
79729 #endif
79730
79731 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
79732 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
79733 - void *buf, int len, int write);
79734 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
79735 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
79736 + void *buf, size_t len, int write);
79737
79738 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79739 unsigned long start, unsigned long nr_pages,
79740 @@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
79741 int set_page_dirty_lock(struct page *page);
79742 int clear_page_dirty_for_io(struct page *page);
79743
79744 -/* Is the vma a continuation of the stack vma above it? */
79745 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
79746 -{
79747 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
79748 -}
79749 -
79750 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
79751 - unsigned long addr)
79752 -{
79753 - return (vma->vm_flags & VM_GROWSDOWN) &&
79754 - (vma->vm_start == addr) &&
79755 - !vma_growsdown(vma->vm_prev, addr);
79756 -}
79757 -
79758 -/* Is the vma a continuation of the stack vma below it? */
79759 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
79760 -{
79761 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
79762 -}
79763 -
79764 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
79765 - unsigned long addr)
79766 -{
79767 - return (vma->vm_flags & VM_GROWSUP) &&
79768 - (vma->vm_end == addr) &&
79769 - !vma_growsup(vma->vm_next, addr);
79770 -}
79771 -
79772 extern pid_t
79773 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
79774
79775 @@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
79776 }
79777 #endif
79778
79779 +#ifdef CONFIG_MMU
79780 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
79781 +#else
79782 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
79783 +{
79784 + return __pgprot(0);
79785 +}
79786 +#endif
79787 +
79788 int vma_wants_writenotify(struct vm_area_struct *vma);
79789
79790 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
79791 @@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
79792 {
79793 return 0;
79794 }
79795 +
79796 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
79797 + unsigned long address)
79798 +{
79799 + return 0;
79800 +}
79801 #else
79802 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79803 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79804 #endif
79805
79806 #ifdef __PAGETABLE_PMD_FOLDED
79807 @@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
79808 {
79809 return 0;
79810 }
79811 +
79812 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
79813 + unsigned long address)
79814 +{
79815 + return 0;
79816 +}
79817 #else
79818 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
79819 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
79820 #endif
79821
79822 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
79823 @@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
79824 NULL: pud_offset(pgd, address);
79825 }
79826
79827 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79828 +{
79829 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
79830 + NULL: pud_offset(pgd, address);
79831 +}
79832 +
79833 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79834 {
79835 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
79836 NULL: pmd_offset(pud, address);
79837 }
79838 +
79839 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
79840 +{
79841 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
79842 + NULL: pmd_offset(pud, address);
79843 +}
79844 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
79845
79846 #if USE_SPLIT_PTE_PTLOCKS
79847 @@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
79848 unsigned long addr, unsigned long len,
79849 unsigned long flags, struct page **pages);
79850
79851 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
79852 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
79853
79854 extern unsigned long mmap_region(struct file *file, unsigned long addr,
79855 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
79856 @@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
79857 unsigned long len, unsigned long prot, unsigned long flags,
79858 unsigned long pgoff, unsigned long *populate);
79859 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
79860 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
79861
79862 #ifdef CONFIG_MMU
79863 extern int __mm_populate(unsigned long addr, unsigned long len,
79864 @@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
79865 unsigned long high_limit;
79866 unsigned long align_mask;
79867 unsigned long align_offset;
79868 + unsigned long threadstack_offset;
79869 };
79870
79871 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
79872 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79873 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
79874 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
79875
79876 /*
79877 * Search for an unmapped address range.
79878 @@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79879 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
79880 */
79881 static inline unsigned long
79882 -vm_unmapped_area(struct vm_unmapped_area_info *info)
79883 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
79884 {
79885 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
79886 return unmapped_area(info);
79887 @@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
79888 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
79889 struct vm_area_struct **pprev);
79890
79891 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
79892 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
79893 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
79894 +
79895 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
79896 NULL if none. Assume start_addr < end_addr. */
79897 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
79898 @@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
79899 return vma;
79900 }
79901
79902 -#ifdef CONFIG_MMU
79903 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
79904 -#else
79905 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
79906 -{
79907 - return __pgprot(0);
79908 -}
79909 -#endif
79910 -
79911 #ifdef CONFIG_NUMA_BALANCING
79912 unsigned long change_prot_numa(struct vm_area_struct *vma,
79913 unsigned long start, unsigned long end);
79914 @@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
79915 static inline void vm_stat_account(struct mm_struct *mm,
79916 unsigned long flags, struct file *file, long pages)
79917 {
79918 +
79919 +#ifdef CONFIG_PAX_RANDMMAP
79920 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
79921 +#endif
79922 +
79923 mm->total_vm += pages;
79924 }
79925 #endif /* CONFIG_PROC_FS */
79926 @@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
79927 extern int sysctl_memory_failure_early_kill;
79928 extern int sysctl_memory_failure_recovery;
79929 extern void shake_page(struct page *p, int access);
79930 -extern atomic_long_t num_poisoned_pages;
79931 +extern atomic_long_unchecked_t num_poisoned_pages;
79932 extern int soft_offline_page(struct page *page, int flags);
79933
79934 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
79935 @@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
79936 static inline void setup_nr_node_ids(void) {}
79937 #endif
79938
79939 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
79940 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
79941 +#else
79942 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
79943 +#endif
79944 +
79945 #endif /* __KERNEL__ */
79946 #endif /* _LINUX_MM_H */
79947 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
79948 index 290901a..e99b01c 100644
79949 --- a/include/linux/mm_types.h
79950 +++ b/include/linux/mm_types.h
79951 @@ -307,7 +307,9 @@ struct vm_area_struct {
79952 #ifdef CONFIG_NUMA
79953 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
79954 #endif
79955 -};
79956 +
79957 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
79958 +} __randomize_layout;
79959
79960 struct core_thread {
79961 struct task_struct *task;
79962 @@ -453,7 +455,25 @@ struct mm_struct {
79963 bool tlb_flush_pending;
79964 #endif
79965 struct uprobes_state uprobes_state;
79966 -};
79967 +
79968 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
79969 + unsigned long pax_flags;
79970 +#endif
79971 +
79972 +#ifdef CONFIG_PAX_DLRESOLVE
79973 + unsigned long call_dl_resolve;
79974 +#endif
79975 +
79976 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
79977 + unsigned long call_syscall;
79978 +#endif
79979 +
79980 +#ifdef CONFIG_PAX_ASLR
79981 + unsigned long delta_mmap; /* randomized offset */
79982 + unsigned long delta_stack; /* randomized offset */
79983 +#endif
79984 +
79985 +} __randomize_layout;
79986
79987 static inline void mm_init_cpumask(struct mm_struct *mm)
79988 {
79989 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
79990 index c5d5278..f0b68c8 100644
79991 --- a/include/linux/mmiotrace.h
79992 +++ b/include/linux/mmiotrace.h
79993 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
79994 /* Called from ioremap.c */
79995 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
79996 void __iomem *addr);
79997 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
79998 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
79999
80000 /* For anyone to insert markers. Remember trailing newline. */
80001 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80002 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80003 {
80004 }
80005
80006 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80007 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80008 {
80009 }
80010
80011 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80012 index 9b61b9b..52147d6b 100644
80013 --- a/include/linux/mmzone.h
80014 +++ b/include/linux/mmzone.h
80015 @@ -396,7 +396,7 @@ struct zone {
80016 unsigned long flags; /* zone flags, see below */
80017
80018 /* Zone statistics */
80019 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80020 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80021
80022 /*
80023 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80024 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80025 index 45e9214..a7227d6 100644
80026 --- a/include/linux/mod_devicetable.h
80027 +++ b/include/linux/mod_devicetable.h
80028 @@ -13,7 +13,7 @@
80029 typedef unsigned long kernel_ulong_t;
80030 #endif
80031
80032 -#define PCI_ANY_ID (~0)
80033 +#define PCI_ANY_ID ((__u16)~0)
80034
80035 struct pci_device_id {
80036 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80037 @@ -139,7 +139,7 @@ struct usb_device_id {
80038 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80039 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80040
80041 -#define HID_ANY_ID (~0)
80042 +#define HID_ANY_ID (~0U)
80043 #define HID_BUS_ANY 0xffff
80044 #define HID_GROUP_ANY 0x0000
80045
80046 @@ -467,7 +467,7 @@ struct dmi_system_id {
80047 const char *ident;
80048 struct dmi_strmatch matches[4];
80049 void *driver_data;
80050 -};
80051 +} __do_const;
80052 /*
80053 * struct dmi_device_id appears during expansion of
80054 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80055 diff --git a/include/linux/module.h b/include/linux/module.h
80056 index eaf60ff..641979a 100644
80057 --- a/include/linux/module.h
80058 +++ b/include/linux/module.h
80059 @@ -17,9 +17,11 @@
80060 #include <linux/moduleparam.h>
80061 #include <linux/tracepoint.h>
80062 #include <linux/export.h>
80063 +#include <linux/fs.h>
80064
80065 #include <linux/percpu.h>
80066 #include <asm/module.h>
80067 +#include <asm/pgtable.h>
80068
80069 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80070 #define MODULE_SIG_STRING "~Module signature appended~\n"
80071 @@ -42,7 +44,7 @@ struct module_kobject {
80072 struct kobject *drivers_dir;
80073 struct module_param_attrs *mp;
80074 struct completion *kobj_completion;
80075 -};
80076 +} __randomize_layout;
80077
80078 struct module_attribute {
80079 struct attribute attr;
80080 @@ -54,12 +56,13 @@ struct module_attribute {
80081 int (*test)(struct module *);
80082 void (*free)(struct module *);
80083 };
80084 +typedef struct module_attribute __no_const module_attribute_no_const;
80085
80086 struct module_version_attribute {
80087 struct module_attribute mattr;
80088 const char *module_name;
80089 const char *version;
80090 -} __attribute__ ((__aligned__(sizeof(void *))));
80091 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80092
80093 extern ssize_t __modver_version_show(struct module_attribute *,
80094 struct module_kobject *, char *);
80095 @@ -238,7 +241,7 @@ struct module {
80096
80097 /* Sysfs stuff. */
80098 struct module_kobject mkobj;
80099 - struct module_attribute *modinfo_attrs;
80100 + module_attribute_no_const *modinfo_attrs;
80101 const char *version;
80102 const char *srcversion;
80103 struct kobject *holders_dir;
80104 @@ -287,19 +290,16 @@ struct module {
80105 int (*init)(void);
80106
80107 /* If this is non-NULL, vfree after init() returns */
80108 - void *module_init;
80109 + void *module_init_rx, *module_init_rw;
80110
80111 /* Here is the actual code + data, vfree'd on unload. */
80112 - void *module_core;
80113 + void *module_core_rx, *module_core_rw;
80114
80115 /* Here are the sizes of the init and core sections */
80116 - unsigned int init_size, core_size;
80117 + unsigned int init_size_rw, core_size_rw;
80118
80119 /* The size of the executable code in each section. */
80120 - unsigned int init_text_size, core_text_size;
80121 -
80122 - /* Size of RO sections of the module (text+rodata) */
80123 - unsigned int init_ro_size, core_ro_size;
80124 + unsigned int init_size_rx, core_size_rx;
80125
80126 /* Arch-specific module values */
80127 struct mod_arch_specific arch;
80128 @@ -355,6 +355,10 @@ struct module {
80129 #ifdef CONFIG_EVENT_TRACING
80130 struct ftrace_event_call **trace_events;
80131 unsigned int num_trace_events;
80132 + struct file_operations trace_id;
80133 + struct file_operations trace_enable;
80134 + struct file_operations trace_format;
80135 + struct file_operations trace_filter;
80136 #endif
80137 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80138 unsigned int num_ftrace_callsites;
80139 @@ -378,7 +382,7 @@ struct module {
80140 ctor_fn_t *ctors;
80141 unsigned int num_ctors;
80142 #endif
80143 -};
80144 +} __randomize_layout;
80145 #ifndef MODULE_ARCH_INIT
80146 #define MODULE_ARCH_INIT {}
80147 #endif
80148 @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80149 bool is_module_percpu_address(unsigned long addr);
80150 bool is_module_text_address(unsigned long addr);
80151
80152 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80153 +{
80154 +
80155 +#ifdef CONFIG_PAX_KERNEXEC
80156 + if (ktla_ktva(addr) >= (unsigned long)start &&
80157 + ktla_ktva(addr) < (unsigned long)start + size)
80158 + return 1;
80159 +#endif
80160 +
80161 + return ((void *)addr >= start && (void *)addr < start + size);
80162 +}
80163 +
80164 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80165 +{
80166 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80167 +}
80168 +
80169 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80170 +{
80171 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80172 +}
80173 +
80174 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80175 +{
80176 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80177 +}
80178 +
80179 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80180 +{
80181 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80182 +}
80183 +
80184 static inline int within_module_core(unsigned long addr, const struct module *mod)
80185 {
80186 - return (unsigned long)mod->module_core <= addr &&
80187 - addr < (unsigned long)mod->module_core + mod->core_size;
80188 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80189 }
80190
80191 static inline int within_module_init(unsigned long addr, const struct module *mod)
80192 {
80193 - return (unsigned long)mod->module_init <= addr &&
80194 - addr < (unsigned long)mod->module_init + mod->init_size;
80195 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80196 }
80197
80198 /* Search for module by name: must hold module_mutex. */
80199 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80200 index 560ca53..ef621ef 100644
80201 --- a/include/linux/moduleloader.h
80202 +++ b/include/linux/moduleloader.h
80203 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80204 sections. Returns NULL on failure. */
80205 void *module_alloc(unsigned long size);
80206
80207 +#ifdef CONFIG_PAX_KERNEXEC
80208 +void *module_alloc_exec(unsigned long size);
80209 +#else
80210 +#define module_alloc_exec(x) module_alloc(x)
80211 +#endif
80212 +
80213 /* Free memory returned from module_alloc. */
80214 void module_free(struct module *mod, void *module_region);
80215
80216 +#ifdef CONFIG_PAX_KERNEXEC
80217 +void module_free_exec(struct module *mod, void *module_region);
80218 +#else
80219 +#define module_free_exec(x, y) module_free((x), (y))
80220 +#endif
80221 +
80222 /*
80223 * Apply the given relocation to the (simplified) ELF. Return -error
80224 * or 0.
80225 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80226 unsigned int relsec,
80227 struct module *me)
80228 {
80229 +#ifdef CONFIG_MODULES
80230 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80231 +#endif
80232 return -ENOEXEC;
80233 }
80234 #endif
80235 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80236 unsigned int relsec,
80237 struct module *me)
80238 {
80239 +#ifdef CONFIG_MODULES
80240 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80241 +#endif
80242 return -ENOEXEC;
80243 }
80244 #endif
80245 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80246 index c3eb102..073c4a6 100644
80247 --- a/include/linux/moduleparam.h
80248 +++ b/include/linux/moduleparam.h
80249 @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80250 * @len is usually just sizeof(string).
80251 */
80252 #define module_param_string(name, string, len, perm) \
80253 - static const struct kparam_string __param_string_##name \
80254 + static const struct kparam_string __param_string_##name __used \
80255 = { len, string }; \
80256 __module_param_call(MODULE_PARAM_PREFIX, name, \
80257 &param_ops_string, \
80258 @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80259 */
80260 #define module_param_array_named(name, array, type, nump, perm) \
80261 param_check_##type(name, &(array)[0]); \
80262 - static const struct kparam_array __param_arr_##name \
80263 + static const struct kparam_array __param_arr_##name __used \
80264 = { .max = ARRAY_SIZE(array), .num = nump, \
80265 .ops = &param_ops_##type, \
80266 .elemsize = sizeof(array[0]), .elem = array }; \
80267 diff --git a/include/linux/mount.h b/include/linux/mount.h
80268 index 371d346..fba2819 100644
80269 --- a/include/linux/mount.h
80270 +++ b/include/linux/mount.h
80271 @@ -56,7 +56,7 @@ struct vfsmount {
80272 struct dentry *mnt_root; /* root of the mounted tree */
80273 struct super_block *mnt_sb; /* pointer to superblock */
80274 int mnt_flags;
80275 -};
80276 +} __randomize_layout;
80277
80278 struct file; /* forward dec */
80279
80280 diff --git a/include/linux/namei.h b/include/linux/namei.h
80281 index 492de72..1bddcd4 100644
80282 --- a/include/linux/namei.h
80283 +++ b/include/linux/namei.h
80284 @@ -19,7 +19,7 @@ struct nameidata {
80285 unsigned seq, m_seq;
80286 int last_type;
80287 unsigned depth;
80288 - char *saved_names[MAX_NESTED_LINKS + 1];
80289 + const char *saved_names[MAX_NESTED_LINKS + 1];
80290 };
80291
80292 /*
80293 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80294
80295 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80296
80297 -static inline void nd_set_link(struct nameidata *nd, char *path)
80298 +static inline void nd_set_link(struct nameidata *nd, const char *path)
80299 {
80300 nd->saved_names[nd->depth] = path;
80301 }
80302
80303 -static inline char *nd_get_link(struct nameidata *nd)
80304 +static inline const char *nd_get_link(const struct nameidata *nd)
80305 {
80306 return nd->saved_names[nd->depth];
80307 }
80308 diff --git a/include/linux/net.h b/include/linux/net.h
80309 index 94734a6..d8d6931 100644
80310 --- a/include/linux/net.h
80311 +++ b/include/linux/net.h
80312 @@ -192,7 +192,7 @@ struct net_proto_family {
80313 int (*create)(struct net *net, struct socket *sock,
80314 int protocol, int kern);
80315 struct module *owner;
80316 -};
80317 +} __do_const;
80318
80319 struct iovec;
80320 struct kvec;
80321 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80322 index daafd95..74c5d1e 100644
80323 --- a/include/linux/netdevice.h
80324 +++ b/include/linux/netdevice.h
80325 @@ -1146,6 +1146,7 @@ struct net_device_ops {
80326 struct net_device *dev,
80327 void *priv);
80328 };
80329 +typedef struct net_device_ops __no_const net_device_ops_no_const;
80330
80331 /*
80332 * The DEVICE structure.
80333 @@ -1228,7 +1229,7 @@ struct net_device {
80334 int iflink;
80335
80336 struct net_device_stats stats;
80337 - atomic_long_t rx_dropped; /* dropped packets by core network
80338 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80339 * Do not use this in drivers.
80340 */
80341
80342 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80343 index 2077489..a15e561 100644
80344 --- a/include/linux/netfilter.h
80345 +++ b/include/linux/netfilter.h
80346 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80347 #endif
80348 /* Use the module struct to lock set/get code in place */
80349 struct module *owner;
80350 -};
80351 +} __do_const;
80352
80353 /* Function to register/unregister hook points. */
80354 int nf_register_hook(struct nf_hook_ops *reg);
80355 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80356 index 28c7436..2d6156a 100644
80357 --- a/include/linux/netfilter/nfnetlink.h
80358 +++ b/include/linux/netfilter/nfnetlink.h
80359 @@ -19,7 +19,7 @@ struct nfnl_callback {
80360 const struct nlattr * const cda[]);
80361 const struct nla_policy *policy; /* netlink attribute policy */
80362 const u_int16_t attr_count; /* number of nlattr's */
80363 -};
80364 +} __do_const;
80365
80366 struct nfnetlink_subsystem {
80367 const char *name;
80368 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80369 new file mode 100644
80370 index 0000000..33f4af8
80371 --- /dev/null
80372 +++ b/include/linux/netfilter/xt_gradm.h
80373 @@ -0,0 +1,9 @@
80374 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
80375 +#define _LINUX_NETFILTER_XT_GRADM_H 1
80376 +
80377 +struct xt_gradm_mtinfo {
80378 + __u16 flags;
80379 + __u16 invflags;
80380 +};
80381 +
80382 +#endif
80383 diff --git a/include/linux/nls.h b/include/linux/nls.h
80384 index 520681b..1d67ed2 100644
80385 --- a/include/linux/nls.h
80386 +++ b/include/linux/nls.h
80387 @@ -31,7 +31,7 @@ struct nls_table {
80388 const unsigned char *charset2upper;
80389 struct module *owner;
80390 struct nls_table *next;
80391 -};
80392 +} __do_const;
80393
80394 /* this value hold the maximum octet of charset */
80395 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
80396 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
80397 index d14a4c3..a078786 100644
80398 --- a/include/linux/notifier.h
80399 +++ b/include/linux/notifier.h
80400 @@ -54,7 +54,8 @@ struct notifier_block {
80401 notifier_fn_t notifier_call;
80402 struct notifier_block __rcu *next;
80403 int priority;
80404 -};
80405 +} __do_const;
80406 +typedef struct notifier_block __no_const notifier_block_no_const;
80407
80408 struct atomic_notifier_head {
80409 spinlock_t lock;
80410 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
80411 index b2a0f15..4d7da32 100644
80412 --- a/include/linux/oprofile.h
80413 +++ b/include/linux/oprofile.h
80414 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
80415 int oprofilefs_create_ro_ulong(struct dentry * root,
80416 char const * name, ulong * val);
80417
80418 -/** Create a file for read-only access to an atomic_t. */
80419 +/** Create a file for read-only access to an atomic_unchecked_t. */
80420 int oprofilefs_create_ro_atomic(struct dentry * root,
80421 - char const * name, atomic_t * val);
80422 + char const * name, atomic_unchecked_t * val);
80423
80424 /** create a directory */
80425 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
80426 diff --git a/include/linux/padata.h b/include/linux/padata.h
80427 index 4386946..f50c615 100644
80428 --- a/include/linux/padata.h
80429 +++ b/include/linux/padata.h
80430 @@ -129,7 +129,7 @@ struct parallel_data {
80431 struct padata_serial_queue __percpu *squeue;
80432 atomic_t reorder_objects;
80433 atomic_t refcnt;
80434 - atomic_t seq_nr;
80435 + atomic_unchecked_t seq_nr;
80436 struct padata_cpumask cpumask;
80437 spinlock_t lock ____cacheline_aligned;
80438 unsigned int processed;
80439 diff --git a/include/linux/path.h b/include/linux/path.h
80440 index d137218..be0c176 100644
80441 --- a/include/linux/path.h
80442 +++ b/include/linux/path.h
80443 @@ -1,13 +1,15 @@
80444 #ifndef _LINUX_PATH_H
80445 #define _LINUX_PATH_H
80446
80447 +#include <linux/compiler.h>
80448 +
80449 struct dentry;
80450 struct vfsmount;
80451
80452 struct path {
80453 struct vfsmount *mnt;
80454 struct dentry *dentry;
80455 -};
80456 +} __randomize_layout;
80457
80458 extern void path_get(const struct path *);
80459 extern void path_put(const struct path *);
80460 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
80461 index 5f2e559..7d59314 100644
80462 --- a/include/linux/pci_hotplug.h
80463 +++ b/include/linux/pci_hotplug.h
80464 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
80465 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
80466 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
80467 int (*reset_slot) (struct hotplug_slot *slot, int probe);
80468 -};
80469 +} __do_const;
80470 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
80471
80472 /**
80473 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
80474 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
80475 index e56b07f..aef789b 100644
80476 --- a/include/linux/perf_event.h
80477 +++ b/include/linux/perf_event.h
80478 @@ -328,8 +328,8 @@ struct perf_event {
80479
80480 enum perf_event_active_state state;
80481 unsigned int attach_state;
80482 - local64_t count;
80483 - atomic64_t child_count;
80484 + local64_t count; /* PaX: fix it one day */
80485 + atomic64_unchecked_t child_count;
80486
80487 /*
80488 * These are the total time in nanoseconds that the event
80489 @@ -380,8 +380,8 @@ struct perf_event {
80490 * These accumulate total time (in nanoseconds) that children
80491 * events have been enabled and running, respectively.
80492 */
80493 - atomic64_t child_total_time_enabled;
80494 - atomic64_t child_total_time_running;
80495 + atomic64_unchecked_t child_total_time_enabled;
80496 + atomic64_unchecked_t child_total_time_running;
80497
80498 /*
80499 * Protect attach/detach and child_list:
80500 @@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
80501 entry->ip[entry->nr++] = ip;
80502 }
80503
80504 -extern int sysctl_perf_event_paranoid;
80505 +extern int sysctl_perf_event_legitimately_concerned;
80506 extern int sysctl_perf_event_mlock;
80507 extern int sysctl_perf_event_sample_rate;
80508 extern int sysctl_perf_cpu_time_max_percent;
80509 @@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
80510 loff_t *ppos);
80511
80512
80513 +static inline bool perf_paranoid_any(void)
80514 +{
80515 + return sysctl_perf_event_legitimately_concerned > 2;
80516 +}
80517 +
80518 static inline bool perf_paranoid_tracepoint_raw(void)
80519 {
80520 - return sysctl_perf_event_paranoid > -1;
80521 + return sysctl_perf_event_legitimately_concerned > -1;
80522 }
80523
80524 static inline bool perf_paranoid_cpu(void)
80525 {
80526 - return sysctl_perf_event_paranoid > 0;
80527 + return sysctl_perf_event_legitimately_concerned > 0;
80528 }
80529
80530 static inline bool perf_paranoid_kernel(void)
80531 {
80532 - return sysctl_perf_event_paranoid > 1;
80533 + return sysctl_perf_event_legitimately_concerned > 1;
80534 }
80535
80536 extern void perf_event_init(void);
80537 @@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
80538 struct device_attribute attr;
80539 u64 id;
80540 const char *event_str;
80541 -};
80542 +} __do_const;
80543
80544 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
80545 static struct perf_pmu_events_attr _var = { \
80546 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
80547 index 7246ef3..1539ea4 100644
80548 --- a/include/linux/pid_namespace.h
80549 +++ b/include/linux/pid_namespace.h
80550 @@ -43,7 +43,7 @@ struct pid_namespace {
80551 int hide_pid;
80552 int reboot; /* group exit code if this pidns was rebooted */
80553 unsigned int proc_inum;
80554 -};
80555 +} __randomize_layout;
80556
80557 extern struct pid_namespace init_pid_ns;
80558
80559 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
80560 index ab57526..94598804 100644
80561 --- a/include/linux/pipe_fs_i.h
80562 +++ b/include/linux/pipe_fs_i.h
80563 @@ -47,10 +47,10 @@ struct pipe_inode_info {
80564 struct mutex mutex;
80565 wait_queue_head_t wait;
80566 unsigned int nrbufs, curbuf, buffers;
80567 - unsigned int readers;
80568 - unsigned int writers;
80569 - unsigned int files;
80570 - unsigned int waiting_writers;
80571 + atomic_t readers;
80572 + atomic_t writers;
80573 + atomic_t files;
80574 + atomic_t waiting_writers;
80575 unsigned int r_counter;
80576 unsigned int w_counter;
80577 struct page *tmp_page;
80578 diff --git a/include/linux/pm.h b/include/linux/pm.h
80579 index 8c6583a..febb84c 100644
80580 --- a/include/linux/pm.h
80581 +++ b/include/linux/pm.h
80582 @@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
80583 struct dev_pm_domain {
80584 struct dev_pm_ops ops;
80585 };
80586 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
80587
80588 /*
80589 * The PM_EVENT_ messages are also used by drivers implementing the legacy
80590 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
80591 index 7c1d252..0e7061d 100644
80592 --- a/include/linux/pm_domain.h
80593 +++ b/include/linux/pm_domain.h
80594 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
80595 int (*thaw_early)(struct device *dev);
80596 int (*thaw)(struct device *dev);
80597 bool (*active_wakeup)(struct device *dev);
80598 -};
80599 +} __no_const;
80600
80601 struct gpd_cpu_data {
80602 unsigned int saved_exit_latency;
80603 - struct cpuidle_state *idle_state;
80604 + cpuidle_state_no_const *idle_state;
80605 };
80606
80607 struct generic_pm_domain {
80608 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
80609 index 16c9a62..f9f0838 100644
80610 --- a/include/linux/pm_runtime.h
80611 +++ b/include/linux/pm_runtime.h
80612 @@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
80613
80614 static inline void pm_runtime_mark_last_busy(struct device *dev)
80615 {
80616 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
80617 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
80618 }
80619
80620 #else /* !CONFIG_PM_RUNTIME */
80621 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
80622 index 195aafc..49a7bc2 100644
80623 --- a/include/linux/pnp.h
80624 +++ b/include/linux/pnp.h
80625 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
80626 struct pnp_fixup {
80627 char id[7];
80628 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
80629 -};
80630 +} __do_const;
80631
80632 /* config parameters */
80633 #define PNP_CONFIG_NORMAL 0x0001
80634 diff --git a/include/linux/poison.h b/include/linux/poison.h
80635 index 2110a81..13a11bb 100644
80636 --- a/include/linux/poison.h
80637 +++ b/include/linux/poison.h
80638 @@ -19,8 +19,8 @@
80639 * under normal circumstances, used to verify that nobody uses
80640 * non-initialized list entries.
80641 */
80642 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
80643 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
80644 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
80645 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
80646
80647 /********** include/linux/timer.h **********/
80648 /*
80649 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
80650 index d8b187c3..9a9257a 100644
80651 --- a/include/linux/power/smartreflex.h
80652 +++ b/include/linux/power/smartreflex.h
80653 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
80654 int (*notify)(struct omap_sr *sr, u32 status);
80655 u8 notify_flags;
80656 u8 class_type;
80657 -};
80658 +} __do_const;
80659
80660 /**
80661 * struct omap_sr_nvalue_table - Smartreflex n-target value info
80662 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
80663 index 4ea1d37..80f4b33 100644
80664 --- a/include/linux/ppp-comp.h
80665 +++ b/include/linux/ppp-comp.h
80666 @@ -84,7 +84,7 @@ struct compressor {
80667 struct module *owner;
80668 /* Extra skb space needed by the compressor algorithm */
80669 unsigned int comp_extra;
80670 -};
80671 +} __do_const;
80672
80673 /*
80674 * The return value from decompress routine is the length of the
80675 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
80676 index de83b4e..c4b997d 100644
80677 --- a/include/linux/preempt.h
80678 +++ b/include/linux/preempt.h
80679 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
80680 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
80681 #endif
80682
80683 +#define raw_preempt_count_add(val) __preempt_count_add(val)
80684 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
80685 +
80686 #define __preempt_count_inc() __preempt_count_add(1)
80687 #define __preempt_count_dec() __preempt_count_sub(1)
80688
80689 #define preempt_count_inc() preempt_count_add(1)
80690 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
80691 #define preempt_count_dec() preempt_count_sub(1)
80692 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
80693
80694 #ifdef CONFIG_PREEMPT_COUNT
80695
80696 @@ -41,6 +46,12 @@ do { \
80697 barrier(); \
80698 } while (0)
80699
80700 +#define raw_preempt_disable() \
80701 +do { \
80702 + raw_preempt_count_inc(); \
80703 + barrier(); \
80704 +} while (0)
80705 +
80706 #define sched_preempt_enable_no_resched() \
80707 do { \
80708 barrier(); \
80709 @@ -49,6 +60,12 @@ do { \
80710
80711 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
80712
80713 +#define raw_preempt_enable_no_resched() \
80714 +do { \
80715 + barrier(); \
80716 + raw_preempt_count_dec(); \
80717 +} while (0)
80718 +
80719 #ifdef CONFIG_PREEMPT
80720 #define preempt_enable() \
80721 do { \
80722 @@ -113,8 +130,10 @@ do { \
80723 * region.
80724 */
80725 #define preempt_disable() barrier()
80726 +#define raw_preempt_disable() barrier()
80727 #define sched_preempt_enable_no_resched() barrier()
80728 #define preempt_enable_no_resched() barrier()
80729 +#define raw_preempt_enable_no_resched() barrier()
80730 #define preempt_enable() barrier()
80731 #define preempt_check_resched() do { } while (0)
80732
80733 @@ -128,11 +147,13 @@ do { \
80734 /*
80735 * Modules have no business playing preemption tricks.
80736 */
80737 +#ifndef CONFIG_PAX_KERNEXEC
80738 #undef sched_preempt_enable_no_resched
80739 #undef preempt_enable_no_resched
80740 #undef preempt_enable_no_resched_notrace
80741 #undef preempt_check_resched
80742 #endif
80743 +#endif
80744
80745 #define preempt_set_need_resched() \
80746 do { \
80747 diff --git a/include/linux/printk.h b/include/linux/printk.h
80748 index fa47e27..c08e034 100644
80749 --- a/include/linux/printk.h
80750 +++ b/include/linux/printk.h
80751 @@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
80752 void early_printk(const char *s, ...) { }
80753 #endif
80754
80755 +extern int kptr_restrict;
80756 +
80757 #ifdef CONFIG_PRINTK
80758 asmlinkage __printf(5, 0)
80759 int vprintk_emit(int facility, int level,
80760 @@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
80761
80762 extern int printk_delay_msec;
80763 extern int dmesg_restrict;
80764 -extern int kptr_restrict;
80765
80766 extern void wake_up_klogd(void);
80767
80768 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
80769 index 608e60a..c26f864 100644
80770 --- a/include/linux/proc_fs.h
80771 +++ b/include/linux/proc_fs.h
80772 @@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
80773 return proc_create_data(name, mode, parent, proc_fops, NULL);
80774 }
80775
80776 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
80777 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
80778 +{
80779 +#ifdef CONFIG_GRKERNSEC_PROC_USER
80780 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
80781 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80782 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
80783 +#else
80784 + return proc_create_data(name, mode, parent, proc_fops, NULL);
80785 +#endif
80786 +}
80787 +
80788 +
80789 extern void proc_set_size(struct proc_dir_entry *, loff_t);
80790 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
80791 extern void *PDE_DATA(const struct inode *);
80792 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
80793 index 34a1e10..70f6bde 100644
80794 --- a/include/linux/proc_ns.h
80795 +++ b/include/linux/proc_ns.h
80796 @@ -14,7 +14,7 @@ struct proc_ns_operations {
80797 void (*put)(void *ns);
80798 int (*install)(struct nsproxy *nsproxy, void *ns);
80799 unsigned int (*inum)(void *ns);
80800 -};
80801 +} __do_const __randomize_layout;
80802
80803 struct proc_ns {
80804 void *ns;
80805 diff --git a/include/linux/quota.h b/include/linux/quota.h
80806 index cc7494a..1e27036 100644
80807 --- a/include/linux/quota.h
80808 +++ b/include/linux/quota.h
80809 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
80810
80811 extern bool qid_eq(struct kqid left, struct kqid right);
80812 extern bool qid_lt(struct kqid left, struct kqid right);
80813 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
80814 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
80815 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
80816 extern bool qid_valid(struct kqid qid);
80817
80818 diff --git a/include/linux/random.h b/include/linux/random.h
80819 index 1cfce0e..b0b9235 100644
80820 --- a/include/linux/random.h
80821 +++ b/include/linux/random.h
80822 @@ -9,9 +9,19 @@
80823 #include <uapi/linux/random.h>
80824
80825 extern void add_device_randomness(const void *, unsigned int);
80826 +
80827 +static inline void add_latent_entropy(void)
80828 +{
80829 +
80830 +#ifdef LATENT_ENTROPY_PLUGIN
80831 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80832 +#endif
80833 +
80834 +}
80835 +
80836 extern void add_input_randomness(unsigned int type, unsigned int code,
80837 - unsigned int value);
80838 -extern void add_interrupt_randomness(int irq, int irq_flags);
80839 + unsigned int value) __latent_entropy;
80840 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
80841
80842 extern void get_random_bytes(void *buf, int nbytes);
80843 extern void get_random_bytes_arch(void *buf, int nbytes);
80844 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
80845 extern const struct file_operations random_fops, urandom_fops;
80846 #endif
80847
80848 -unsigned int get_random_int(void);
80849 +unsigned int __intentional_overflow(-1) get_random_int(void);
80850 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
80851
80852 -u32 prandom_u32(void);
80853 +u32 prandom_u32(void) __intentional_overflow(-1);
80854 void prandom_bytes(void *buf, int nbytes);
80855 void prandom_seed(u32 seed);
80856 void prandom_reseed_late(void);
80857 @@ -37,6 +47,11 @@ struct rnd_state {
80858 u32 prandom_u32_state(struct rnd_state *state);
80859 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
80860
80861 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
80862 +{
80863 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
80864 +}
80865 +
80866 /**
80867 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
80868 * @ep_ro: right open interval endpoint
80869 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
80870 index fea49b5..2ac22bb 100644
80871 --- a/include/linux/rbtree_augmented.h
80872 +++ b/include/linux/rbtree_augmented.h
80873 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
80874 old->rbaugmented = rbcompute(old); \
80875 } \
80876 rbstatic const struct rb_augment_callbacks rbname = { \
80877 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
80878 + .propagate = rbname ## _propagate, \
80879 + .copy = rbname ## _copy, \
80880 + .rotate = rbname ## _rotate \
80881 };
80882
80883
80884 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
80885 index dbaf990..52e07b8 100644
80886 --- a/include/linux/rculist.h
80887 +++ b/include/linux/rculist.h
80888 @@ -29,8 +29,8 @@
80889 */
80890 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
80891 {
80892 - ACCESS_ONCE(list->next) = list;
80893 - ACCESS_ONCE(list->prev) = list;
80894 + ACCESS_ONCE_RW(list->next) = list;
80895 + ACCESS_ONCE_RW(list->prev) = list;
80896 }
80897
80898 /*
80899 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
80900 struct list_head *prev, struct list_head *next);
80901 #endif
80902
80903 +void __pax_list_add_rcu(struct list_head *new,
80904 + struct list_head *prev, struct list_head *next);
80905 +
80906 /**
80907 * list_add_rcu - add a new entry to rcu-protected list
80908 * @new: new entry to be added
80909 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
80910 __list_add_rcu(new, head, head->next);
80911 }
80912
80913 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
80914 +{
80915 + __pax_list_add_rcu(new, head, head->next);
80916 +}
80917 +
80918 /**
80919 * list_add_tail_rcu - add a new entry to rcu-protected list
80920 * @new: new entry to be added
80921 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
80922 __list_add_rcu(new, head->prev, head);
80923 }
80924
80925 +static inline void pax_list_add_tail_rcu(struct list_head *new,
80926 + struct list_head *head)
80927 +{
80928 + __pax_list_add_rcu(new, head->prev, head);
80929 +}
80930 +
80931 /**
80932 * list_del_rcu - deletes entry from list without re-initialization
80933 * @entry: the element to delete from the list.
80934 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
80935 entry->prev = LIST_POISON2;
80936 }
80937
80938 +extern void pax_list_del_rcu(struct list_head *entry);
80939 +
80940 /**
80941 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
80942 * @n: the element to delete from the hash list.
80943 diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
80944 index 72bf3a0..853347f 100644
80945 --- a/include/linux/rcupdate.h
80946 +++ b/include/linux/rcupdate.h
80947 @@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
80948 #define rcu_assign_pointer(p, v) \
80949 do { \
80950 smp_wmb(); \
80951 - ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
80952 + ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
80953 } while (0)
80954
80955
80956 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
80957 index 9e7db9e..7d4fd72 100644
80958 --- a/include/linux/reboot.h
80959 +++ b/include/linux/reboot.h
80960 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
80961 */
80962
80963 extern void migrate_to_reboot_cpu(void);
80964 -extern void machine_restart(char *cmd);
80965 -extern void machine_halt(void);
80966 -extern void machine_power_off(void);
80967 +extern void machine_restart(char *cmd) __noreturn;
80968 +extern void machine_halt(void) __noreturn;
80969 +extern void machine_power_off(void) __noreturn;
80970
80971 extern void machine_shutdown(void);
80972 struct pt_regs;
80973 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
80974 */
80975
80976 extern void kernel_restart_prepare(char *cmd);
80977 -extern void kernel_restart(char *cmd);
80978 -extern void kernel_halt(void);
80979 -extern void kernel_power_off(void);
80980 +extern void kernel_restart(char *cmd) __noreturn;
80981 +extern void kernel_halt(void) __noreturn;
80982 +extern void kernel_power_off(void) __noreturn;
80983
80984 extern int C_A_D; /* for sysctl */
80985 void ctrl_alt_del(void);
80986 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
80987 * Emergency restart, callable from an interrupt handler.
80988 */
80989
80990 -extern void emergency_restart(void);
80991 +extern void emergency_restart(void) __noreturn;
80992 #include <asm/emergency-restart.h>
80993
80994 #endif /* _LINUX_REBOOT_H */
80995 diff --git a/include/linux/regset.h b/include/linux/regset.h
80996 index 8e0c9fe..ac4d221 100644
80997 --- a/include/linux/regset.h
80998 +++ b/include/linux/regset.h
80999 @@ -161,7 +161,8 @@ struct user_regset {
81000 unsigned int align;
81001 unsigned int bias;
81002 unsigned int core_note_type;
81003 -};
81004 +} __do_const;
81005 +typedef struct user_regset __no_const user_regset_no_const;
81006
81007 /**
81008 * struct user_regset_view - available regsets
81009 diff --git a/include/linux/relay.h b/include/linux/relay.h
81010 index d7c8359..818daf5 100644
81011 --- a/include/linux/relay.h
81012 +++ b/include/linux/relay.h
81013 @@ -157,7 +157,7 @@ struct rchan_callbacks
81014 * The callback should return 0 if successful, negative if not.
81015 */
81016 int (*remove_buf_file)(struct dentry *dentry);
81017 -};
81018 +} __no_const;
81019
81020 /*
81021 * CONFIG_RELAY kernel API, kernel/relay.c
81022 diff --git a/include/linux/rio.h b/include/linux/rio.h
81023 index b71d573..2f940bd 100644
81024 --- a/include/linux/rio.h
81025 +++ b/include/linux/rio.h
81026 @@ -355,7 +355,7 @@ struct rio_ops {
81027 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81028 u64 rstart, u32 size, u32 flags);
81029 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81030 -};
81031 +} __no_const;
81032
81033 #define RIO_RESOURCE_MEM 0x00000100
81034 #define RIO_RESOURCE_DOORBELL 0x00000200
81035 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81036 index b66c211..13d2915 100644
81037 --- a/include/linux/rmap.h
81038 +++ b/include/linux/rmap.h
81039 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81040 void anon_vma_init(void); /* create anon_vma_cachep */
81041 int anon_vma_prepare(struct vm_area_struct *);
81042 void unlink_anon_vmas(struct vm_area_struct *);
81043 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81044 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81045 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81046 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81047
81048 static inline void anon_vma_merge(struct vm_area_struct *vma,
81049 struct vm_area_struct *next)
81050 diff --git a/include/linux/sched.h b/include/linux/sched.h
81051 index a781dec..be1d2a3 100644
81052 --- a/include/linux/sched.h
81053 +++ b/include/linux/sched.h
81054 @@ -129,6 +129,7 @@ struct fs_struct;
81055 struct perf_event_context;
81056 struct blk_plug;
81057 struct filename;
81058 +struct linux_binprm;
81059
81060 /*
81061 * List of flags we want to share for kernel threads,
81062 @@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
81063 extern int in_sched_functions(unsigned long addr);
81064
81065 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81066 -extern signed long schedule_timeout(signed long timeout);
81067 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81068 extern signed long schedule_timeout_interruptible(signed long timeout);
81069 extern signed long schedule_timeout_killable(signed long timeout);
81070 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81071 @@ -380,6 +381,19 @@ struct nsproxy;
81072 struct user_namespace;
81073
81074 #ifdef CONFIG_MMU
81075 +
81076 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81077 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81078 +#else
81079 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81080 +{
81081 + return 0;
81082 +}
81083 +#endif
81084 +
81085 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81086 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81087 +
81088 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81089 extern unsigned long
81090 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81091 @@ -677,6 +691,17 @@ struct signal_struct {
81092 #ifdef CONFIG_TASKSTATS
81093 struct taskstats *stats;
81094 #endif
81095 +
81096 +#ifdef CONFIG_GRKERNSEC
81097 + u32 curr_ip;
81098 + u32 saved_ip;
81099 + u32 gr_saddr;
81100 + u32 gr_daddr;
81101 + u16 gr_sport;
81102 + u16 gr_dport;
81103 + u8 used_accept:1;
81104 +#endif
81105 +
81106 #ifdef CONFIG_AUDIT
81107 unsigned audit_tty;
81108 unsigned audit_tty_log_passwd;
81109 @@ -703,7 +728,7 @@ struct signal_struct {
81110 struct mutex cred_guard_mutex; /* guard against foreign influences on
81111 * credential calculations
81112 * (notably. ptrace) */
81113 -};
81114 +} __randomize_layout;
81115
81116 /*
81117 * Bits in flags field of signal_struct.
81118 @@ -757,6 +782,14 @@ struct user_struct {
81119 struct key *session_keyring; /* UID's default session keyring */
81120 #endif
81121
81122 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81123 + unsigned char kernel_banned;
81124 +#endif
81125 +#ifdef CONFIG_GRKERNSEC_BRUTE
81126 + unsigned char suid_banned;
81127 + unsigned long suid_ban_expires;
81128 +#endif
81129 +
81130 /* Hash table maintenance information */
81131 struct hlist_node uidhash_node;
81132 kuid_t uid;
81133 @@ -764,7 +797,7 @@ struct user_struct {
81134 #ifdef CONFIG_PERF_EVENTS
81135 atomic_long_t locked_vm;
81136 #endif
81137 -};
81138 +} __randomize_layout;
81139
81140 extern int uids_sysfs_init(void);
81141
81142 @@ -1286,8 +1319,8 @@ struct task_struct {
81143 struct list_head thread_node;
81144
81145 struct completion *vfork_done; /* for vfork() */
81146 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81147 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81148 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81149 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81150
81151 cputime_t utime, stime, utimescaled, stimescaled;
81152 cputime_t gtime;
81153 @@ -1312,11 +1345,6 @@ struct task_struct {
81154 struct task_cputime cputime_expires;
81155 struct list_head cpu_timers[3];
81156
81157 -/* process credentials */
81158 - const struct cred __rcu *real_cred; /* objective and real subjective task
81159 - * credentials (COW) */
81160 - const struct cred __rcu *cred; /* effective (overridable) subjective task
81161 - * credentials (COW) */
81162 char comm[TASK_COMM_LEN]; /* executable name excluding path
81163 - access with [gs]et_task_comm (which lock
81164 it with task_lock())
81165 @@ -1333,6 +1361,10 @@ struct task_struct {
81166 #endif
81167 /* CPU-specific state of this task */
81168 struct thread_struct thread;
81169 +/* thread_info moved to task_struct */
81170 +#ifdef CONFIG_X86
81171 + struct thread_info tinfo;
81172 +#endif
81173 /* filesystem information */
81174 struct fs_struct *fs;
81175 /* open file information */
81176 @@ -1409,6 +1441,10 @@ struct task_struct {
81177 gfp_t lockdep_reclaim_gfp;
81178 #endif
81179
81180 +/* process credentials */
81181 + const struct cred __rcu *real_cred; /* objective and real subjective task
81182 + * credentials (COW) */
81183 +
81184 /* journalling filesystem info */
81185 void *journal_info;
81186
81187 @@ -1447,6 +1483,10 @@ struct task_struct {
81188 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81189 struct list_head cg_list;
81190 #endif
81191 +
81192 + const struct cred __rcu *cred; /* effective (overridable) subjective task
81193 + * credentials (COW) */
81194 +
81195 #ifdef CONFIG_FUTEX
81196 struct robust_list_head __user *robust_list;
81197 #ifdef CONFIG_COMPAT
81198 @@ -1581,7 +1621,78 @@ struct task_struct {
81199 unsigned int sequential_io;
81200 unsigned int sequential_io_avg;
81201 #endif
81202 -};
81203 +
81204 +#ifdef CONFIG_GRKERNSEC
81205 + /* grsecurity */
81206 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81207 + u64 exec_id;
81208 +#endif
81209 +#ifdef CONFIG_GRKERNSEC_SETXID
81210 + const struct cred *delayed_cred;
81211 +#endif
81212 + struct dentry *gr_chroot_dentry;
81213 + struct acl_subject_label *acl;
81214 + struct acl_subject_label *tmpacl;
81215 + struct acl_role_label *role;
81216 + struct file *exec_file;
81217 + unsigned long brute_expires;
81218 + u16 acl_role_id;
81219 + u8 inherited;
81220 + /* is this the task that authenticated to the special role */
81221 + u8 acl_sp_role;
81222 + u8 is_writable;
81223 + u8 brute;
81224 + u8 gr_is_chrooted;
81225 +#endif
81226 +
81227 +} __randomize_layout;
81228 +
81229 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81230 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81231 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81232 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81233 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81234 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81235 +
81236 +#ifdef CONFIG_PAX_SOFTMODE
81237 +extern int pax_softmode;
81238 +#endif
81239 +
81240 +extern int pax_check_flags(unsigned long *);
81241 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81242 +
81243 +/* if tsk != current then task_lock must be held on it */
81244 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81245 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
81246 +{
81247 + if (likely(tsk->mm))
81248 + return tsk->mm->pax_flags;
81249 + else
81250 + return 0UL;
81251 +}
81252 +
81253 +/* if tsk != current then task_lock must be held on it */
81254 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81255 +{
81256 + if (likely(tsk->mm)) {
81257 + tsk->mm->pax_flags = flags;
81258 + return 0;
81259 + }
81260 + return -EINVAL;
81261 +}
81262 +#endif
81263 +
81264 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81265 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
81266 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81267 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81268 +#endif
81269 +
81270 +struct path;
81271 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81272 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81273 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81274 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
81275
81276 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81277 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81278 @@ -1658,7 +1769,7 @@ struct pid_namespace;
81279 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81280 struct pid_namespace *ns);
81281
81282 -static inline pid_t task_pid_nr(struct task_struct *tsk)
81283 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
81284 {
81285 return tsk->pid;
81286 }
81287 @@ -2112,7 +2223,9 @@ void yield(void);
81288 extern struct exec_domain default_exec_domain;
81289
81290 union thread_union {
81291 +#ifndef CONFIG_X86
81292 struct thread_info thread_info;
81293 +#endif
81294 unsigned long stack[THREAD_SIZE/sizeof(long)];
81295 };
81296
81297 @@ -2145,6 +2258,7 @@ extern struct pid_namespace init_pid_ns;
81298 */
81299
81300 extern struct task_struct *find_task_by_vpid(pid_t nr);
81301 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81302 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81303 struct pid_namespace *ns);
81304
81305 @@ -2307,7 +2421,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81306 extern void exit_itimers(struct signal_struct *);
81307 extern void flush_itimer_signals(void);
81308
81309 -extern void do_group_exit(int);
81310 +extern __noreturn void do_group_exit(int);
81311
81312 extern int allow_signal(int);
81313 extern int disallow_signal(int);
81314 @@ -2508,9 +2622,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81315
81316 #endif
81317
81318 -static inline int object_is_on_stack(void *obj)
81319 +static inline int object_starts_on_stack(void *obj)
81320 {
81321 - void *stack = task_stack_page(current);
81322 + const void *stack = task_stack_page(current);
81323
81324 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81325 }
81326 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81327 index 8045a55..c959cd5 100644
81328 --- a/include/linux/sched/sysctl.h
81329 +++ b/include/linux/sched/sysctl.h
81330 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81331 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81332
81333 extern int sysctl_max_map_count;
81334 +extern unsigned long sysctl_heap_stack_gap;
81335
81336 extern unsigned int sysctl_sched_latency;
81337 extern unsigned int sysctl_sched_min_granularity;
81338 diff --git a/include/linux/security.h b/include/linux/security.h
81339 index 2fc42d1..4d802f2 100644
81340 --- a/include/linux/security.h
81341 +++ b/include/linux/security.h
81342 @@ -27,6 +27,7 @@
81343 #include <linux/slab.h>
81344 #include <linux/err.h>
81345 #include <linux/string.h>
81346 +#include <linux/grsecurity.h>
81347
81348 struct linux_binprm;
81349 struct cred;
81350 @@ -116,8 +117,6 @@ struct seq_file;
81351
81352 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
81353
81354 -void reset_security_ops(void);
81355 -
81356 #ifdef CONFIG_MMU
81357 extern unsigned long mmap_min_addr;
81358 extern unsigned long dac_mmap_min_addr;
81359 @@ -1719,7 +1718,7 @@ struct security_operations {
81360 struct audit_context *actx);
81361 void (*audit_rule_free) (void *lsmrule);
81362 #endif /* CONFIG_AUDIT */
81363 -};
81364 +} __randomize_layout;
81365
81366 /* prototypes */
81367 extern int security_init(void);
81368 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
81369 index dc368b8..e895209 100644
81370 --- a/include/linux/semaphore.h
81371 +++ b/include/linux/semaphore.h
81372 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
81373 }
81374
81375 extern void down(struct semaphore *sem);
81376 -extern int __must_check down_interruptible(struct semaphore *sem);
81377 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
81378 extern int __must_check down_killable(struct semaphore *sem);
81379 extern int __must_check down_trylock(struct semaphore *sem);
81380 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
81381 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
81382 index 52e0097..09625ef 100644
81383 --- a/include/linux/seq_file.h
81384 +++ b/include/linux/seq_file.h
81385 @@ -27,6 +27,9 @@ struct seq_file {
81386 struct mutex lock;
81387 const struct seq_operations *op;
81388 int poll_event;
81389 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81390 + u64 exec_id;
81391 +#endif
81392 #ifdef CONFIG_USER_NS
81393 struct user_namespace *user_ns;
81394 #endif
81395 @@ -39,6 +42,7 @@ struct seq_operations {
81396 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
81397 int (*show) (struct seq_file *m, void *v);
81398 };
81399 +typedef struct seq_operations __no_const seq_operations_no_const;
81400
81401 #define SEQ_SKIP 1
81402
81403 diff --git a/include/linux/shm.h b/include/linux/shm.h
81404 index 1e2cd2e..0288750 100644
81405 --- a/include/linux/shm.h
81406 +++ b/include/linux/shm.h
81407 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
81408
81409 /* The task created the shm object. NULL if the task is dead. */
81410 struct task_struct *shm_creator;
81411 +#ifdef CONFIG_GRKERNSEC
81412 + time_t shm_createtime;
81413 + pid_t shm_lapid;
81414 +#endif
81415 };
81416
81417 /* shm_mode upper byte flags */
81418 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
81419 index 15ede6a..80161c3 100644
81420 --- a/include/linux/skbuff.h
81421 +++ b/include/linux/skbuff.h
81422 @@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
81423 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
81424 int node);
81425 struct sk_buff *build_skb(void *data, unsigned int frag_size);
81426 -static inline struct sk_buff *alloc_skb(unsigned int size,
81427 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
81428 gfp_t priority)
81429 {
81430 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
81431 @@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
81432 return skb->inner_transport_header - skb->inner_network_header;
81433 }
81434
81435 -static inline int skb_network_offset(const struct sk_buff *skb)
81436 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
81437 {
81438 return skb_network_header(skb) - skb->data;
81439 }
81440 @@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
81441 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
81442 */
81443 #ifndef NET_SKB_PAD
81444 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
81445 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
81446 #endif
81447
81448 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
81449 @@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
81450 int *err);
81451 unsigned int datagram_poll(struct file *file, struct socket *sock,
81452 struct poll_table_struct *wait);
81453 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81454 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81455 struct iovec *to, int size);
81456 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
81457 struct iovec *iov);
81458 @@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
81459 nf_bridge_put(skb->nf_bridge);
81460 skb->nf_bridge = NULL;
81461 #endif
81462 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
81463 + skb->nf_trace = 0;
81464 +#endif
81465 }
81466
81467 static inline void nf_reset_trace(struct sk_buff *skb)
81468 diff --git a/include/linux/slab.h b/include/linux/slab.h
81469 index b5b2df6..69f5734 100644
81470 --- a/include/linux/slab.h
81471 +++ b/include/linux/slab.h
81472 @@ -14,15 +14,29 @@
81473 #include <linux/gfp.h>
81474 #include <linux/types.h>
81475 #include <linux/workqueue.h>
81476 -
81477 +#include <linux/err.h>
81478
81479 /*
81480 * Flags to pass to kmem_cache_create().
81481 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
81482 */
81483 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
81484 +
81485 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81486 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
81487 +#else
81488 +#define SLAB_USERCOPY 0x00000000UL
81489 +#endif
81490 +
81491 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
81492 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
81493 +
81494 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81495 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
81496 +#else
81497 +#define SLAB_NO_SANITIZE 0x00000000UL
81498 +#endif
81499 +
81500 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
81501 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
81502 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
81503 @@ -98,10 +112,13 @@
81504 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
81505 * Both make kfree a no-op.
81506 */
81507 -#define ZERO_SIZE_PTR ((void *)16)
81508 +#define ZERO_SIZE_PTR \
81509 +({ \
81510 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
81511 + (void *)(-MAX_ERRNO-1L); \
81512 +})
81513
81514 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
81515 - (unsigned long)ZERO_SIZE_PTR)
81516 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
81517
81518 #include <linux/kmemleak.h>
81519
81520 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
81521 void kfree(const void *);
81522 void kzfree(const void *);
81523 size_t ksize(const void *);
81524 +const char *check_heap_object(const void *ptr, unsigned long n);
81525 +bool is_usercopy_object(const void *ptr);
81526
81527 /*
81528 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
81529 @@ -174,7 +193,7 @@ struct kmem_cache {
81530 unsigned int align; /* Alignment as calculated */
81531 unsigned long flags; /* Active flags on the slab */
81532 const char *name; /* Slab name for sysfs */
81533 - int refcount; /* Use counter */
81534 + atomic_t refcount; /* Use counter */
81535 void (*ctor)(void *); /* Called on object slot creation */
81536 struct list_head list; /* List of all slab caches on the system */
81537 };
81538 @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
81539 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81540 #endif
81541
81542 +#ifdef CONFIG_PAX_USERCOPY_SLABS
81543 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
81544 +#endif
81545 +
81546 /*
81547 * Figure out which kmalloc slab an allocation of a certain size
81548 * belongs to.
81549 @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81550 * 2 = 120 .. 192 bytes
81551 * n = 2^(n-1) .. 2^n -1
81552 */
81553 -static __always_inline int kmalloc_index(size_t size)
81554 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
81555 {
81556 if (!size)
81557 return 0;
81558 @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
81559 }
81560 #endif /* !CONFIG_SLOB */
81561
81562 -void *__kmalloc(size_t size, gfp_t flags);
81563 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
81564 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
81565
81566 #ifdef CONFIG_NUMA
81567 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
81568 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
81569 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
81570 #else
81571 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
81572 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
81573 index 8235dfb..47ce586 100644
81574 --- a/include/linux/slab_def.h
81575 +++ b/include/linux/slab_def.h
81576 @@ -38,7 +38,7 @@ struct kmem_cache {
81577 /* 4) cache creation/removal */
81578 const char *name;
81579 struct list_head list;
81580 - int refcount;
81581 + atomic_t refcount;
81582 int object_size;
81583 int align;
81584
81585 @@ -54,10 +54,14 @@ struct kmem_cache {
81586 unsigned long node_allocs;
81587 unsigned long node_frees;
81588 unsigned long node_overflow;
81589 - atomic_t allochit;
81590 - atomic_t allocmiss;
81591 - atomic_t freehit;
81592 - atomic_t freemiss;
81593 + atomic_unchecked_t allochit;
81594 + atomic_unchecked_t allocmiss;
81595 + atomic_unchecked_t freehit;
81596 + atomic_unchecked_t freemiss;
81597 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81598 + atomic_unchecked_t sanitized;
81599 + atomic_unchecked_t not_sanitized;
81600 +#endif
81601
81602 /*
81603 * If debugging is enabled, then the allocator can add additional
81604 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
81605 index f56bfa9..8378a26 100644
81606 --- a/include/linux/slub_def.h
81607 +++ b/include/linux/slub_def.h
81608 @@ -74,7 +74,7 @@ struct kmem_cache {
81609 struct kmem_cache_order_objects max;
81610 struct kmem_cache_order_objects min;
81611 gfp_t allocflags; /* gfp flags to use on each alloc */
81612 - int refcount; /* Refcount for slab cache destroy */
81613 + atomic_t refcount; /* Refcount for slab cache destroy */
81614 void (*ctor)(void *);
81615 int inuse; /* Offset to metadata */
81616 int align; /* Alignment */
81617 diff --git a/include/linux/smp.h b/include/linux/smp.h
81618 index 6ae004e..2743532 100644
81619 --- a/include/linux/smp.h
81620 +++ b/include/linux/smp.h
81621 @@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
81622 #endif
81623
81624 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
81625 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
81626 #define put_cpu() preempt_enable()
81627 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
81628
81629 /*
81630 * Callback to arch code if there's nosmp or maxcpus=0 on the
81631 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
81632 index 54f91d3..be2c379 100644
81633 --- a/include/linux/sock_diag.h
81634 +++ b/include/linux/sock_diag.h
81635 @@ -11,7 +11,7 @@ struct sock;
81636 struct sock_diag_handler {
81637 __u8 family;
81638 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
81639 -};
81640 +} __do_const;
81641
81642 int sock_diag_register(const struct sock_diag_handler *h);
81643 void sock_diag_unregister(const struct sock_diag_handler *h);
81644 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
81645 index 680f9a3..f13aeb0 100644
81646 --- a/include/linux/sonet.h
81647 +++ b/include/linux/sonet.h
81648 @@ -7,7 +7,7 @@
81649 #include <uapi/linux/sonet.h>
81650
81651 struct k_sonet_stats {
81652 -#define __HANDLE_ITEM(i) atomic_t i
81653 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
81654 __SONET_ITEMS
81655 #undef __HANDLE_ITEM
81656 };
81657 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
81658 index 07d8e53..dc934c9 100644
81659 --- a/include/linux/sunrpc/addr.h
81660 +++ b/include/linux/sunrpc/addr.h
81661 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
81662 {
81663 switch (sap->sa_family) {
81664 case AF_INET:
81665 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
81666 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
81667 case AF_INET6:
81668 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
81669 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
81670 }
81671 return 0;
81672 }
81673 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
81674 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
81675 const struct sockaddr *src)
81676 {
81677 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
81678 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
81679 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
81680
81681 dsin->sin_family = ssin->sin_family;
81682 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
81683 if (sa->sa_family != AF_INET6)
81684 return 0;
81685
81686 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
81687 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
81688 }
81689
81690 #endif /* _LINUX_SUNRPC_ADDR_H */
81691 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
81692 index 8af2804..c7414ef 100644
81693 --- a/include/linux/sunrpc/clnt.h
81694 +++ b/include/linux/sunrpc/clnt.h
81695 @@ -97,7 +97,7 @@ struct rpc_procinfo {
81696 unsigned int p_timer; /* Which RTT timer to use */
81697 u32 p_statidx; /* Which procedure to account */
81698 const char * p_name; /* name of procedure */
81699 -};
81700 +} __do_const;
81701
81702 #ifdef __KERNEL__
81703
81704 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
81705 index 04e7632..2e2a8a3 100644
81706 --- a/include/linux/sunrpc/svc.h
81707 +++ b/include/linux/sunrpc/svc.h
81708 @@ -412,7 +412,7 @@ struct svc_procedure {
81709 unsigned int pc_count; /* call count */
81710 unsigned int pc_cachetype; /* cache info (NFS) */
81711 unsigned int pc_xdrressize; /* maximum size of XDR reply */
81712 -};
81713 +} __do_const;
81714
81715 /*
81716 * Function prototypes.
81717 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
81718 index 0b8e3e6..33e0a01 100644
81719 --- a/include/linux/sunrpc/svc_rdma.h
81720 +++ b/include/linux/sunrpc/svc_rdma.h
81721 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
81722 extern unsigned int svcrdma_max_requests;
81723 extern unsigned int svcrdma_max_req_size;
81724
81725 -extern atomic_t rdma_stat_recv;
81726 -extern atomic_t rdma_stat_read;
81727 -extern atomic_t rdma_stat_write;
81728 -extern atomic_t rdma_stat_sq_starve;
81729 -extern atomic_t rdma_stat_rq_starve;
81730 -extern atomic_t rdma_stat_rq_poll;
81731 -extern atomic_t rdma_stat_rq_prod;
81732 -extern atomic_t rdma_stat_sq_poll;
81733 -extern atomic_t rdma_stat_sq_prod;
81734 +extern atomic_unchecked_t rdma_stat_recv;
81735 +extern atomic_unchecked_t rdma_stat_read;
81736 +extern atomic_unchecked_t rdma_stat_write;
81737 +extern atomic_unchecked_t rdma_stat_sq_starve;
81738 +extern atomic_unchecked_t rdma_stat_rq_starve;
81739 +extern atomic_unchecked_t rdma_stat_rq_poll;
81740 +extern atomic_unchecked_t rdma_stat_rq_prod;
81741 +extern atomic_unchecked_t rdma_stat_sq_poll;
81742 +extern atomic_unchecked_t rdma_stat_sq_prod;
81743
81744 #define RPCRDMA_VERSION 1
81745
81746 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
81747 index 8d71d65..f79586e 100644
81748 --- a/include/linux/sunrpc/svcauth.h
81749 +++ b/include/linux/sunrpc/svcauth.h
81750 @@ -120,7 +120,7 @@ struct auth_ops {
81751 int (*release)(struct svc_rqst *rq);
81752 void (*domain_release)(struct auth_domain *);
81753 int (*set_client)(struct svc_rqst *rq);
81754 -};
81755 +} __do_const;
81756
81757 #define SVC_GARBAGE 1
81758 #define SVC_SYSERR 2
81759 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
81760 index a5ffd32..0935dea 100644
81761 --- a/include/linux/swiotlb.h
81762 +++ b/include/linux/swiotlb.h
81763 @@ -60,7 +60,8 @@ extern void
81764
81765 extern void
81766 swiotlb_free_coherent(struct device *hwdev, size_t size,
81767 - void *vaddr, dma_addr_t dma_handle);
81768 + void *vaddr, dma_addr_t dma_handle,
81769 + struct dma_attrs *attrs);
81770
81771 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
81772 unsigned long offset, size_t size,
81773 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
81774 index a747a77..9e14df7 100644
81775 --- a/include/linux/syscalls.h
81776 +++ b/include/linux/syscalls.h
81777 @@ -98,8 +98,14 @@ struct sigaltstack;
81778 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
81779
81780 #define __SC_DECL(t, a) t a
81781 +#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))
81782 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
81783 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
81784 +#define __SC_LONG(t, a) __typeof( \
81785 + __builtin_choose_expr( \
81786 + sizeof(t) > sizeof(int), \
81787 + (t) 0, \
81788 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
81789 + )) a
81790 #define __SC_CAST(t, a) (t) a
81791 #define __SC_ARGS(t, a) a
81792 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
81793 @@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
81794 asmlinkage long sys_fsync(unsigned int fd);
81795 asmlinkage long sys_fdatasync(unsigned int fd);
81796 asmlinkage long sys_bdflush(int func, long data);
81797 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
81798 - char __user *type, unsigned long flags,
81799 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
81800 + const char __user *type, unsigned long flags,
81801 void __user *data);
81802 -asmlinkage long sys_umount(char __user *name, int flags);
81803 -asmlinkage long sys_oldumount(char __user *name);
81804 +asmlinkage long sys_umount(const char __user *name, int flags);
81805 +asmlinkage long sys_oldumount(const char __user *name);
81806 asmlinkage long sys_truncate(const char __user *path, long length);
81807 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
81808 asmlinkage long sys_stat(const char __user *filename,
81809 @@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
81810 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
81811 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
81812 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
81813 - struct sockaddr __user *, int);
81814 + struct sockaddr __user *, int) __intentional_overflow(0);
81815 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
81816 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
81817 unsigned int vlen, unsigned flags);
81818 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
81819 index 27b3b0b..e093dd9 100644
81820 --- a/include/linux/syscore_ops.h
81821 +++ b/include/linux/syscore_ops.h
81822 @@ -16,7 +16,7 @@ struct syscore_ops {
81823 int (*suspend)(void);
81824 void (*resume)(void);
81825 void (*shutdown)(void);
81826 -};
81827 +} __do_const;
81828
81829 extern void register_syscore_ops(struct syscore_ops *ops);
81830 extern void unregister_syscore_ops(struct syscore_ops *ops);
81831 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
81832 index 14a8ff2..fa95f3a 100644
81833 --- a/include/linux/sysctl.h
81834 +++ b/include/linux/sysctl.h
81835 @@ -34,13 +34,13 @@ struct ctl_table_root;
81836 struct ctl_table_header;
81837 struct ctl_dir;
81838
81839 -typedef struct ctl_table ctl_table;
81840 -
81841 typedef int proc_handler (struct ctl_table *ctl, int write,
81842 void __user *buffer, size_t *lenp, loff_t *ppos);
81843
81844 extern int proc_dostring(struct ctl_table *, int,
81845 void __user *, size_t *, loff_t *);
81846 +extern int proc_dostring_modpriv(struct ctl_table *, int,
81847 + void __user *, size_t *, loff_t *);
81848 extern int proc_dointvec(struct ctl_table *, int,
81849 void __user *, size_t *, loff_t *);
81850 extern int proc_dointvec_minmax(struct ctl_table *, int,
81851 @@ -115,7 +115,9 @@ struct ctl_table
81852 struct ctl_table_poll *poll;
81853 void *extra1;
81854 void *extra2;
81855 -};
81856 +} __do_const __randomize_layout;
81857 +typedef struct ctl_table __no_const ctl_table_no_const;
81858 +typedef struct ctl_table ctl_table;
81859
81860 struct ctl_node {
81861 struct rb_node node;
81862 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
81863 index 30b2ebe..37412ef 100644
81864 --- a/include/linux/sysfs.h
81865 +++ b/include/linux/sysfs.h
81866 @@ -34,7 +34,8 @@ struct attribute {
81867 struct lock_class_key *key;
81868 struct lock_class_key skey;
81869 #endif
81870 -};
81871 +} __do_const;
81872 +typedef struct attribute __no_const attribute_no_const;
81873
81874 /**
81875 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
81876 @@ -63,7 +64,8 @@ struct attribute_group {
81877 struct attribute *, int);
81878 struct attribute **attrs;
81879 struct bin_attribute **bin_attrs;
81880 -};
81881 +} __do_const;
81882 +typedef struct attribute_group __no_const attribute_group_no_const;
81883
81884 /**
81885 * Use these macros to make defining attributes easier. See include/linux/device.h
81886 @@ -127,7 +129,8 @@ struct bin_attribute {
81887 char *, loff_t, size_t);
81888 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
81889 struct vm_area_struct *vma);
81890 -};
81891 +} __do_const;
81892 +typedef struct bin_attribute __no_const bin_attribute_no_const;
81893
81894 /**
81895 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
81896 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
81897 index 387fa7d..3fcde6b 100644
81898 --- a/include/linux/sysrq.h
81899 +++ b/include/linux/sysrq.h
81900 @@ -16,6 +16,7 @@
81901
81902 #include <linux/errno.h>
81903 #include <linux/types.h>
81904 +#include <linux/compiler.h>
81905
81906 /* Possible values of bitmask for enabling sysrq functions */
81907 /* 0x0001 is reserved for enable everything */
81908 @@ -33,7 +34,7 @@ struct sysrq_key_op {
81909 char *help_msg;
81910 char *action_msg;
81911 int enable_mask;
81912 -};
81913 +} __do_const;
81914
81915 #ifdef CONFIG_MAGIC_SYSRQ
81916
81917 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
81918 index fddbe20..0312de8 100644
81919 --- a/include/linux/thread_info.h
81920 +++ b/include/linux/thread_info.h
81921 @@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
81922 #error "no set_restore_sigmask() provided and default one won't work"
81923 #endif
81924
81925 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
81926 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
81927 +{
81928 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
81929 + if (!__builtin_constant_p(n))
81930 +#endif
81931 + __check_object_size(ptr, n, to_user);
81932 +}
81933 +
81934 #endif /* __KERNEL__ */
81935
81936 #endif /* _LINUX_THREAD_INFO_H */
81937 diff --git a/include/linux/tty.h b/include/linux/tty.h
81938 index 90b4fdc..58a731d 100644
81939 --- a/include/linux/tty.h
81940 +++ b/include/linux/tty.h
81941 @@ -202,7 +202,7 @@ struct tty_port {
81942 const struct tty_port_operations *ops; /* Port operations */
81943 spinlock_t lock; /* Lock protecting tty field */
81944 int blocked_open; /* Waiting to open */
81945 - int count; /* Usage count */
81946 + atomic_t count; /* Usage count */
81947 wait_queue_head_t open_wait; /* Open waiters */
81948 wait_queue_head_t close_wait; /* Close waiters */
81949 wait_queue_head_t delta_msr_wait; /* Modem status change */
81950 @@ -284,7 +284,7 @@ struct tty_struct {
81951 /* If the tty has a pending do_SAK, queue it here - akpm */
81952 struct work_struct SAK_work;
81953 struct tty_port *port;
81954 -};
81955 +} __randomize_layout;
81956
81957 /* Each of a tty's open files has private_data pointing to tty_file_private */
81958 struct tty_file_private {
81959 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
81960 struct tty_struct *tty, struct file *filp);
81961 static inline int tty_port_users(struct tty_port *port)
81962 {
81963 - return port->count + port->blocked_open;
81964 + return atomic_read(&port->count) + port->blocked_open;
81965 }
81966
81967 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
81968 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
81969 index 756a609..89db85e 100644
81970 --- a/include/linux/tty_driver.h
81971 +++ b/include/linux/tty_driver.h
81972 @@ -285,7 +285,7 @@ struct tty_operations {
81973 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
81974 #endif
81975 const struct file_operations *proc_fops;
81976 -};
81977 +} __do_const __randomize_layout;
81978
81979 struct tty_driver {
81980 int magic; /* magic number for this structure */
81981 @@ -319,7 +319,7 @@ struct tty_driver {
81982
81983 const struct tty_operations *ops;
81984 struct list_head tty_drivers;
81985 -};
81986 +} __randomize_layout;
81987
81988 extern struct list_head tty_drivers;
81989
81990 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
81991 index b8347c2..85d8b0f 100644
81992 --- a/include/linux/tty_ldisc.h
81993 +++ b/include/linux/tty_ldisc.h
81994 @@ -213,7 +213,7 @@ struct tty_ldisc_ops {
81995
81996 struct module *owner;
81997
81998 - int refcount;
81999 + atomic_t refcount;
82000 };
82001
82002 struct tty_ldisc {
82003 diff --git a/include/linux/types.h b/include/linux/types.h
82004 index 4d118ba..c3ee9bf 100644
82005 --- a/include/linux/types.h
82006 +++ b/include/linux/types.h
82007 @@ -176,10 +176,26 @@ typedef struct {
82008 int counter;
82009 } atomic_t;
82010
82011 +#ifdef CONFIG_PAX_REFCOUNT
82012 +typedef struct {
82013 + int counter;
82014 +} atomic_unchecked_t;
82015 +#else
82016 +typedef atomic_t atomic_unchecked_t;
82017 +#endif
82018 +
82019 #ifdef CONFIG_64BIT
82020 typedef struct {
82021 long counter;
82022 } atomic64_t;
82023 +
82024 +#ifdef CONFIG_PAX_REFCOUNT
82025 +typedef struct {
82026 + long counter;
82027 +} atomic64_unchecked_t;
82028 +#else
82029 +typedef atomic64_t atomic64_unchecked_t;
82030 +#endif
82031 #endif
82032
82033 struct list_head {
82034 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82035 index ecd3319..8a36ded 100644
82036 --- a/include/linux/uaccess.h
82037 +++ b/include/linux/uaccess.h
82038 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82039 long ret; \
82040 mm_segment_t old_fs = get_fs(); \
82041 \
82042 - set_fs(KERNEL_DS); \
82043 pagefault_disable(); \
82044 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82045 - pagefault_enable(); \
82046 + set_fs(KERNEL_DS); \
82047 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82048 set_fs(old_fs); \
82049 + pagefault_enable(); \
82050 ret; \
82051 })
82052
82053 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82054 index 2d1f9b6..d7a9fce 100644
82055 --- a/include/linux/uidgid.h
82056 +++ b/include/linux/uidgid.h
82057 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82058
82059 #endif /* CONFIG_USER_NS */
82060
82061 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82062 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82063 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82064 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82065 +
82066 #endif /* _LINUX_UIDGID_H */
82067 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82068 index 99c1b4d..562e6f3 100644
82069 --- a/include/linux/unaligned/access_ok.h
82070 +++ b/include/linux/unaligned/access_ok.h
82071 @@ -4,34 +4,34 @@
82072 #include <linux/kernel.h>
82073 #include <asm/byteorder.h>
82074
82075 -static inline u16 get_unaligned_le16(const void *p)
82076 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82077 {
82078 - return le16_to_cpup((__le16 *)p);
82079 + return le16_to_cpup((const __le16 *)p);
82080 }
82081
82082 -static inline u32 get_unaligned_le32(const void *p)
82083 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82084 {
82085 - return le32_to_cpup((__le32 *)p);
82086 + return le32_to_cpup((const __le32 *)p);
82087 }
82088
82089 -static inline u64 get_unaligned_le64(const void *p)
82090 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82091 {
82092 - return le64_to_cpup((__le64 *)p);
82093 + return le64_to_cpup((const __le64 *)p);
82094 }
82095
82096 -static inline u16 get_unaligned_be16(const void *p)
82097 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82098 {
82099 - return be16_to_cpup((__be16 *)p);
82100 + return be16_to_cpup((const __be16 *)p);
82101 }
82102
82103 -static inline u32 get_unaligned_be32(const void *p)
82104 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82105 {
82106 - return be32_to_cpup((__be32 *)p);
82107 + return be32_to_cpup((const __be32 *)p);
82108 }
82109
82110 -static inline u64 get_unaligned_be64(const void *p)
82111 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82112 {
82113 - return be64_to_cpup((__be64 *)p);
82114 + return be64_to_cpup((const __be64 *)p);
82115 }
82116
82117 static inline void put_unaligned_le16(u16 val, void *p)
82118 diff --git a/include/linux/usb.h b/include/linux/usb.h
82119 index 7f6eb85..656e806 100644
82120 --- a/include/linux/usb.h
82121 +++ b/include/linux/usb.h
82122 @@ -563,7 +563,7 @@ struct usb_device {
82123 int maxchild;
82124
82125 u32 quirks;
82126 - atomic_t urbnum;
82127 + atomic_unchecked_t urbnum;
82128
82129 unsigned long active_duration;
82130
82131 @@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82132
82133 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82134 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82135 - void *data, __u16 size, int timeout);
82136 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
82137 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82138 void *data, int len, int *actual_length, int timeout);
82139 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82140 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82141 index e452ba6..78f8e80 100644
82142 --- a/include/linux/usb/renesas_usbhs.h
82143 +++ b/include/linux/usb/renesas_usbhs.h
82144 @@ -39,7 +39,7 @@ enum {
82145 */
82146 struct renesas_usbhs_driver_callback {
82147 int (*notify_hotplug)(struct platform_device *pdev);
82148 -};
82149 +} __no_const;
82150
82151 /*
82152 * callback functions for platform
82153 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82154 index 4836ba3..603f6ee 100644
82155 --- a/include/linux/user_namespace.h
82156 +++ b/include/linux/user_namespace.h
82157 @@ -33,7 +33,7 @@ struct user_namespace {
82158 struct key *persistent_keyring_register;
82159 struct rw_semaphore persistent_keyring_register_sem;
82160 #endif
82161 -};
82162 +} __randomize_layout;
82163
82164 extern struct user_namespace init_user_ns;
82165
82166 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82167 index 239e277..22a5cf5 100644
82168 --- a/include/linux/utsname.h
82169 +++ b/include/linux/utsname.h
82170 @@ -24,7 +24,7 @@ struct uts_namespace {
82171 struct new_utsname name;
82172 struct user_namespace *user_ns;
82173 unsigned int proc_inum;
82174 -};
82175 +} __randomize_layout;
82176 extern struct uts_namespace init_uts_ns;
82177
82178 #ifdef CONFIG_UTS_NS
82179 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82180 index 6f8fbcf..4efc177 100644
82181 --- a/include/linux/vermagic.h
82182 +++ b/include/linux/vermagic.h
82183 @@ -25,9 +25,42 @@
82184 #define MODULE_ARCH_VERMAGIC ""
82185 #endif
82186
82187 +#ifdef CONFIG_PAX_REFCOUNT
82188 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
82189 +#else
82190 +#define MODULE_PAX_REFCOUNT ""
82191 +#endif
82192 +
82193 +#ifdef CONSTIFY_PLUGIN
82194 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82195 +#else
82196 +#define MODULE_CONSTIFY_PLUGIN ""
82197 +#endif
82198 +
82199 +#ifdef STACKLEAK_PLUGIN
82200 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82201 +#else
82202 +#define MODULE_STACKLEAK_PLUGIN ""
82203 +#endif
82204 +
82205 +#ifdef RANDSTRUCT_PLUGIN
82206 +#include <generated/randomize_layout_hash.h>
82207 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82208 +#else
82209 +#define MODULE_RANDSTRUCT_PLUGIN
82210 +#endif
82211 +
82212 +#ifdef CONFIG_GRKERNSEC
82213 +#define MODULE_GRSEC "GRSEC "
82214 +#else
82215 +#define MODULE_GRSEC ""
82216 +#endif
82217 +
82218 #define VERMAGIC_STRING \
82219 UTS_RELEASE " " \
82220 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82221 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82222 - MODULE_ARCH_VERMAGIC
82223 + MODULE_ARCH_VERMAGIC \
82224 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82225 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82226
82227 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82228 index 502073a..a7de024 100644
82229 --- a/include/linux/vga_switcheroo.h
82230 +++ b/include/linux/vga_switcheroo.h
82231 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82232
82233 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82234
82235 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82236 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82237 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82238 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82239 #else
82240
82241 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82242 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82243
82244 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82245
82246 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82247 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82248 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82249 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82250
82251 #endif
82252 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82253 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82254 index 4b8a891..cb8df6e 100644
82255 --- a/include/linux/vmalloc.h
82256 +++ b/include/linux/vmalloc.h
82257 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82258 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82259 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82260 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82261 +
82262 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82263 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82264 +#endif
82265 +
82266 /* bits [20..32] reserved for arch specific ioremap internals */
82267
82268 /*
82269 @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82270
82271 /* for /dev/kmem */
82272 extern long vread(char *buf, char *addr, unsigned long count);
82273 -extern long vwrite(char *buf, char *addr, unsigned long count);
82274 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82275
82276 /*
82277 * Internals. Dont't use..
82278 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82279 index 67ce70c..d540954 100644
82280 --- a/include/linux/vmstat.h
82281 +++ b/include/linux/vmstat.h
82282 @@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
82283 /*
82284 * Zone based page accounting with per cpu differentials.
82285 */
82286 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82287 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82288
82289 static inline void zone_page_state_add(long x, struct zone *zone,
82290 enum zone_stat_item item)
82291 {
82292 - atomic_long_add(x, &zone->vm_stat[item]);
82293 - atomic_long_add(x, &vm_stat[item]);
82294 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82295 + atomic_long_add_unchecked(x, &vm_stat[item]);
82296 }
82297
82298 -static inline unsigned long global_page_state(enum zone_stat_item item)
82299 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82300 {
82301 - long x = atomic_long_read(&vm_stat[item]);
82302 + long x = atomic_long_read_unchecked(&vm_stat[item]);
82303 #ifdef CONFIG_SMP
82304 if (x < 0)
82305 x = 0;
82306 @@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82307 return x;
82308 }
82309
82310 -static inline unsigned long zone_page_state(struct zone *zone,
82311 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82312 enum zone_stat_item item)
82313 {
82314 - long x = atomic_long_read(&zone->vm_stat[item]);
82315 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82316 #ifdef CONFIG_SMP
82317 if (x < 0)
82318 x = 0;
82319 @@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82320 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
82321 enum zone_stat_item item)
82322 {
82323 - long x = atomic_long_read(&zone->vm_stat[item]);
82324 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82325
82326 #ifdef CONFIG_SMP
82327 int cpu;
82328 @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
82329
82330 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
82331 {
82332 - atomic_long_inc(&zone->vm_stat[item]);
82333 - atomic_long_inc(&vm_stat[item]);
82334 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
82335 + atomic_long_inc_unchecked(&vm_stat[item]);
82336 }
82337
82338 static inline void __inc_zone_page_state(struct page *page,
82339 @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
82340
82341 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
82342 {
82343 - atomic_long_dec(&zone->vm_stat[item]);
82344 - atomic_long_dec(&vm_stat[item]);
82345 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
82346 + atomic_long_dec_unchecked(&vm_stat[item]);
82347 }
82348
82349 static inline void __dec_zone_page_state(struct page *page,
82350 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
82351 index 91b0a68..0e9adf6 100644
82352 --- a/include/linux/xattr.h
82353 +++ b/include/linux/xattr.h
82354 @@ -28,7 +28,7 @@ struct xattr_handler {
82355 size_t size, int handler_flags);
82356 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
82357 size_t size, int flags, int handler_flags);
82358 -};
82359 +} __do_const;
82360
82361 struct xattr {
82362 const char *name;
82363 @@ -37,6 +37,9 @@ struct xattr {
82364 };
82365
82366 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
82367 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82368 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
82369 +#endif
82370 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
82371 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
82372 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
82373 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
82374 index 9c5a6b4..09c9438 100644
82375 --- a/include/linux/zlib.h
82376 +++ b/include/linux/zlib.h
82377 @@ -31,6 +31,7 @@
82378 #define _ZLIB_H
82379
82380 #include <linux/zconf.h>
82381 +#include <linux/compiler.h>
82382
82383 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
82384 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
82385 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
82386
82387 /* basic functions */
82388
82389 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
82390 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
82391 /*
82392 Returns the number of bytes that needs to be allocated for a per-
82393 stream workspace with the specified parameters. A pointer to this
82394 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
82395 index c768c9f..bdcaa5a 100644
82396 --- a/include/media/v4l2-dev.h
82397 +++ b/include/media/v4l2-dev.h
82398 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
82399 int (*mmap) (struct file *, struct vm_area_struct *);
82400 int (*open) (struct file *);
82401 int (*release) (struct file *);
82402 -};
82403 +} __do_const;
82404
82405 /*
82406 * Newer version of video_device, handled by videodev2.c
82407 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
82408 index c9b1593..a572459 100644
82409 --- a/include/media/v4l2-device.h
82410 +++ b/include/media/v4l2-device.h
82411 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
82412 this function returns 0. If the name ends with a digit (e.g. cx18),
82413 then the name will be set to cx18-0 since cx180 looks really odd. */
82414 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
82415 - atomic_t *instance);
82416 + atomic_unchecked_t *instance);
82417
82418 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
82419 Since the parent disappears this ensures that v4l2_dev doesn't have an
82420 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
82421 index 9a36d92..0aafe2a 100644
82422 --- a/include/net/9p/transport.h
82423 +++ b/include/net/9p/transport.h
82424 @@ -60,7 +60,7 @@ struct p9_trans_module {
82425 int (*cancel) (struct p9_client *, struct p9_req_t *req);
82426 int (*zc_request)(struct p9_client *, struct p9_req_t *,
82427 char *, char *, int , int, int, int);
82428 -};
82429 +} __do_const;
82430
82431 void v9fs_register_trans(struct p9_trans_module *m);
82432 void v9fs_unregister_trans(struct p9_trans_module *m);
82433 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
82434 index a175ba4..196eb82 100644
82435 --- a/include/net/af_unix.h
82436 +++ b/include/net/af_unix.h
82437 @@ -36,7 +36,7 @@ struct unix_skb_parms {
82438 u32 secid; /* Security ID */
82439 #endif
82440 u32 consumed;
82441 -};
82442 +} __randomize_layout;
82443
82444 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
82445 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
82446 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
82447 index dbc4a89..4a59b5d 100644
82448 --- a/include/net/bluetooth/l2cap.h
82449 +++ b/include/net/bluetooth/l2cap.h
82450 @@ -600,7 +600,7 @@ struct l2cap_ops {
82451 long (*get_sndtimeo) (struct l2cap_chan *chan);
82452 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
82453 unsigned long len, int nb);
82454 -};
82455 +} __do_const;
82456
82457 struct l2cap_conn {
82458 struct hci_conn *hcon;
82459 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
82460 index f2ae33d..c457cf0 100644
82461 --- a/include/net/caif/cfctrl.h
82462 +++ b/include/net/caif/cfctrl.h
82463 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
82464 void (*radioset_rsp)(void);
82465 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
82466 struct cflayer *client_layer);
82467 -};
82468 +} __no_const;
82469
82470 /* Link Setup Parameters for CAIF-Links. */
82471 struct cfctrl_link_param {
82472 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
82473 struct cfctrl {
82474 struct cfsrvl serv;
82475 struct cfctrl_rsp res;
82476 - atomic_t req_seq_no;
82477 - atomic_t rsp_seq_no;
82478 + atomic_unchecked_t req_seq_no;
82479 + atomic_unchecked_t rsp_seq_no;
82480 struct list_head list;
82481 /* Protects from simultaneous access to first_req list */
82482 spinlock_t info_list_lock;
82483 diff --git a/include/net/flow.h b/include/net/flow.h
82484 index d23e7fa..e188307 100644
82485 --- a/include/net/flow.h
82486 +++ b/include/net/flow.h
82487 @@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
82488
82489 void flow_cache_flush(void);
82490 void flow_cache_flush_deferred(void);
82491 -extern atomic_t flow_cache_genid;
82492 +extern atomic_unchecked_t flow_cache_genid;
82493
82494 #endif
82495 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
82496 index 93695f0..766d71c 100644
82497 --- a/include/net/genetlink.h
82498 +++ b/include/net/genetlink.h
82499 @@ -120,7 +120,7 @@ struct genl_ops {
82500 u8 cmd;
82501 u8 internal_flags;
82502 u8 flags;
82503 -};
82504 +} __do_const;
82505
82506 int __genl_register_family(struct genl_family *family);
82507
82508 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
82509 index 734d9b5..48a9a4b 100644
82510 --- a/include/net/gro_cells.h
82511 +++ b/include/net/gro_cells.h
82512 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
82513 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
82514
82515 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
82516 - atomic_long_inc(&dev->rx_dropped);
82517 + atomic_long_inc_unchecked(&dev->rx_dropped);
82518 kfree_skb(skb);
82519 return;
82520 }
82521 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
82522 index c55aeed..b3393f4 100644
82523 --- a/include/net/inet_connection_sock.h
82524 +++ b/include/net/inet_connection_sock.h
82525 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
82526 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
82527 int (*bind_conflict)(const struct sock *sk,
82528 const struct inet_bind_bucket *tb, bool relax);
82529 -};
82530 +} __do_const;
82531
82532 /** inet_connection_sock - INET connection oriented sock
82533 *
82534 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
82535 index 6efe73c..fa94270 100644
82536 --- a/include/net/inetpeer.h
82537 +++ b/include/net/inetpeer.h
82538 @@ -47,8 +47,8 @@ struct inet_peer {
82539 */
82540 union {
82541 struct {
82542 - atomic_t rid; /* Frag reception counter */
82543 - atomic_t ip_id_count; /* IP ID for the next packet */
82544 + atomic_unchecked_t rid; /* Frag reception counter */
82545 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
82546 };
82547 struct rcu_head rcu;
82548 struct inet_peer *gc_next;
82549 @@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
82550 /* can be called with or without local BH being disabled */
82551 static inline int inet_getid(struct inet_peer *p, int more)
82552 {
82553 - int old, new;
82554 + int id;
82555 more++;
82556 inet_peer_refcheck(p);
82557 - do {
82558 - old = atomic_read(&p->ip_id_count);
82559 - new = old + more;
82560 - if (!new)
82561 - new = 1;
82562 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
82563 - return new;
82564 + id = atomic_add_return_unchecked(more, &p->ip_id_count);
82565 + if (!id)
82566 + id = atomic_inc_return_unchecked(&p->ip_id_count);
82567 + return id;
82568 }
82569
82570 #endif /* _NET_INETPEER_H */
82571 diff --git a/include/net/ip.h b/include/net/ip.h
82572 index 23be0fd..0cb3e2c 100644
82573 --- a/include/net/ip.h
82574 +++ b/include/net/ip.h
82575 @@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
82576
82577 void inet_get_local_port_range(struct net *net, int *low, int *high);
82578
82579 -extern unsigned long *sysctl_local_reserved_ports;
82580 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
82581 static inline int inet_is_reserved_local_port(int port)
82582 {
82583 return test_bit(port, sysctl_local_reserved_ports);
82584 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
82585 index 9922093..a1755d6 100644
82586 --- a/include/net/ip_fib.h
82587 +++ b/include/net/ip_fib.h
82588 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
82589
82590 #define FIB_RES_SADDR(net, res) \
82591 ((FIB_RES_NH(res).nh_saddr_genid == \
82592 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
82593 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
82594 FIB_RES_NH(res).nh_saddr : \
82595 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
82596 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
82597 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
82598 index 5679d92..2e7a690 100644
82599 --- a/include/net/ip_vs.h
82600 +++ b/include/net/ip_vs.h
82601 @@ -558,7 +558,7 @@ struct ip_vs_conn {
82602 struct ip_vs_conn *control; /* Master control connection */
82603 atomic_t n_control; /* Number of controlled ones */
82604 struct ip_vs_dest *dest; /* real server */
82605 - atomic_t in_pkts; /* incoming packet counter */
82606 + atomic_unchecked_t in_pkts; /* incoming packet counter */
82607
82608 /* packet transmitter for different forwarding methods. If it
82609 mangles the packet, it must return NF_DROP or better NF_STOLEN,
82610 @@ -705,7 +705,7 @@ struct ip_vs_dest {
82611 __be16 port; /* port number of the server */
82612 union nf_inet_addr addr; /* IP address of the server */
82613 volatile unsigned int flags; /* dest status flags */
82614 - atomic_t conn_flags; /* flags to copy to conn */
82615 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
82616 atomic_t weight; /* server weight */
82617
82618 atomic_t refcnt; /* reference counter */
82619 @@ -960,11 +960,11 @@ struct netns_ipvs {
82620 /* ip_vs_lblc */
82621 int sysctl_lblc_expiration;
82622 struct ctl_table_header *lblc_ctl_header;
82623 - struct ctl_table *lblc_ctl_table;
82624 + ctl_table_no_const *lblc_ctl_table;
82625 /* ip_vs_lblcr */
82626 int sysctl_lblcr_expiration;
82627 struct ctl_table_header *lblcr_ctl_header;
82628 - struct ctl_table *lblcr_ctl_table;
82629 + ctl_table_no_const *lblcr_ctl_table;
82630 /* ip_vs_est */
82631 struct list_head est_list; /* estimator list */
82632 spinlock_t est_lock;
82633 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
82634 index 8d4f588..2e37ad2 100644
82635 --- a/include/net/irda/ircomm_tty.h
82636 +++ b/include/net/irda/ircomm_tty.h
82637 @@ -33,6 +33,7 @@
82638 #include <linux/termios.h>
82639 #include <linux/timer.h>
82640 #include <linux/tty.h> /* struct tty_struct */
82641 +#include <asm/local.h>
82642
82643 #include <net/irda/irias_object.h>
82644 #include <net/irda/ircomm_core.h>
82645 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
82646 index 714cc9a..ea05f3e 100644
82647 --- a/include/net/iucv/af_iucv.h
82648 +++ b/include/net/iucv/af_iucv.h
82649 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
82650 struct iucv_sock_list {
82651 struct hlist_head head;
82652 rwlock_t lock;
82653 - atomic_t autobind_name;
82654 + atomic_unchecked_t autobind_name;
82655 };
82656
82657 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
82658 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
82659 index f3be818..bf46196 100644
82660 --- a/include/net/llc_c_ac.h
82661 +++ b/include/net/llc_c_ac.h
82662 @@ -87,7 +87,7 @@
82663 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
82664 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
82665
82666 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82667 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82668
82669 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
82670 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
82671 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
82672 index 3948cf1..83b28c4 100644
82673 --- a/include/net/llc_c_ev.h
82674 +++ b/include/net/llc_c_ev.h
82675 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
82676 return (struct llc_conn_state_ev *)skb->cb;
82677 }
82678
82679 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82680 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82681 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82682 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82683
82684 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
82685 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
82686 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
82687 index 0e79cfb..f46db31 100644
82688 --- a/include/net/llc_c_st.h
82689 +++ b/include/net/llc_c_st.h
82690 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
82691 u8 next_state;
82692 llc_conn_ev_qfyr_t *ev_qualifiers;
82693 llc_conn_action_t *ev_actions;
82694 -};
82695 +} __do_const;
82696
82697 struct llc_conn_state {
82698 u8 current_state;
82699 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
82700 index a61b98c..aade1eb 100644
82701 --- a/include/net/llc_s_ac.h
82702 +++ b/include/net/llc_s_ac.h
82703 @@ -23,7 +23,7 @@
82704 #define SAP_ACT_TEST_IND 9
82705
82706 /* All action functions must look like this */
82707 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82708 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82709
82710 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
82711 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
82712 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
82713 index 567c681..cd73ac0 100644
82714 --- a/include/net/llc_s_st.h
82715 +++ b/include/net/llc_s_st.h
82716 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
82717 llc_sap_ev_t ev;
82718 u8 next_state;
82719 llc_sap_action_t *ev_actions;
82720 -};
82721 +} __do_const;
82722
82723 struct llc_sap_state {
82724 u8 curr_state;
82725 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
82726 index f4ab2fb..71a85ba 100644
82727 --- a/include/net/mac80211.h
82728 +++ b/include/net/mac80211.h
82729 @@ -4476,7 +4476,7 @@ struct rate_control_ops {
82730 void (*add_sta_debugfs)(void *priv, void *priv_sta,
82731 struct dentry *dir);
82732 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
82733 -};
82734 +} __do_const;
82735
82736 static inline int rate_supported(struct ieee80211_sta *sta,
82737 enum ieee80211_band band,
82738 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
82739 index 7277caf..fd095bc 100644
82740 --- a/include/net/neighbour.h
82741 +++ b/include/net/neighbour.h
82742 @@ -163,7 +163,7 @@ struct neigh_ops {
82743 void (*error_report)(struct neighbour *, struct sk_buff *);
82744 int (*output)(struct neighbour *, struct sk_buff *);
82745 int (*connected_output)(struct neighbour *, struct sk_buff *);
82746 -};
82747 +} __do_const;
82748
82749 struct pneigh_entry {
82750 struct pneigh_entry *next;
82751 @@ -203,7 +203,6 @@ struct neigh_table {
82752 void (*proxy_redo)(struct sk_buff *skb);
82753 char *id;
82754 struct neigh_parms parms;
82755 - /* HACK. gc_* should follow parms without a gap! */
82756 int gc_interval;
82757 int gc_thresh1;
82758 int gc_thresh2;
82759 @@ -218,7 +217,7 @@ struct neigh_table {
82760 struct neigh_statistics __percpu *stats;
82761 struct neigh_hash_table __rcu *nht;
82762 struct pneigh_entry **phash_buckets;
82763 -};
82764 +} __randomize_layout;
82765
82766 static inline int neigh_parms_family(struct neigh_parms *p)
82767 {
82768 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
82769 index 991dcd9..ab58d00 100644
82770 --- a/include/net/net_namespace.h
82771 +++ b/include/net/net_namespace.h
82772 @@ -124,8 +124,8 @@ struct net {
82773 struct netns_ipvs *ipvs;
82774 #endif
82775 struct sock *diag_nlsk;
82776 - atomic_t fnhe_genid;
82777 -};
82778 + atomic_unchecked_t fnhe_genid;
82779 +} __randomize_layout;
82780
82781 /*
82782 * ifindex generation is per-net namespace, and loopback is
82783 @@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
82784 #define __net_init __init
82785 #define __net_exit __exit_refok
82786 #define __net_initdata __initdata
82787 +#ifdef CONSTIFY_PLUGIN
82788 #define __net_initconst __initconst
82789 +#else
82790 +#define __net_initconst __initdata
82791 +#endif
82792 #endif
82793
82794 struct pernet_operations {
82795 @@ -299,7 +303,7 @@ struct pernet_operations {
82796 void (*exit_batch)(struct list_head *net_exit_list);
82797 int *id;
82798 size_t size;
82799 -};
82800 +} __do_const;
82801
82802 /*
82803 * Use these carefully. If you implement a network device and it
82804 @@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
82805
82806 static inline int rt_genid_ipv4(struct net *net)
82807 {
82808 - return atomic_read(&net->ipv4.rt_genid);
82809 + return atomic_read_unchecked(&net->ipv4.rt_genid);
82810 }
82811
82812 static inline void rt_genid_bump_ipv4(struct net *net)
82813 {
82814 - atomic_inc(&net->ipv4.rt_genid);
82815 + atomic_inc_unchecked(&net->ipv4.rt_genid);
82816 }
82817
82818 #if IS_ENABLED(CONFIG_IPV6)
82819 static inline int rt_genid_ipv6(struct net *net)
82820 {
82821 - return atomic_read(&net->ipv6.rt_genid);
82822 + return atomic_read_unchecked(&net->ipv6.rt_genid);
82823 }
82824
82825 static inline void rt_genid_bump_ipv6(struct net *net)
82826 {
82827 - atomic_inc(&net->ipv6.rt_genid);
82828 + atomic_inc_unchecked(&net->ipv6.rt_genid);
82829 }
82830 #else
82831 static inline int rt_genid_ipv6(struct net *net)
82832 @@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
82833
82834 static inline int fnhe_genid(struct net *net)
82835 {
82836 - return atomic_read(&net->fnhe_genid);
82837 + return atomic_read_unchecked(&net->fnhe_genid);
82838 }
82839
82840 static inline void fnhe_genid_bump(struct net *net)
82841 {
82842 - atomic_inc(&net->fnhe_genid);
82843 + atomic_inc_unchecked(&net->fnhe_genid);
82844 }
82845
82846 #endif /* __NET_NET_NAMESPACE_H */
82847 diff --git a/include/net/netdma.h b/include/net/netdma.h
82848 index 8ba8ce2..99b7fff 100644
82849 --- a/include/net/netdma.h
82850 +++ b/include/net/netdma.h
82851 @@ -24,7 +24,7 @@
82852 #include <linux/dmaengine.h>
82853 #include <linux/skbuff.h>
82854
82855 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82856 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82857 struct sk_buff *skb, int offset, struct iovec *to,
82858 size_t len, struct dma_pinned_list *pinned_list);
82859
82860 diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
82861 index 956b175..55d1504 100644
82862 --- a/include/net/netfilter/nf_conntrack_extend.h
82863 +++ b/include/net/netfilter/nf_conntrack_extend.h
82864 @@ -47,8 +47,8 @@ enum nf_ct_ext_id {
82865 /* Extensions: optional stuff which isn't permanently in struct. */
82866 struct nf_ct_ext {
82867 struct rcu_head rcu;
82868 - u8 offset[NF_CT_EXT_NUM];
82869 - u8 len;
82870 + u16 offset[NF_CT_EXT_NUM];
82871 + u16 len;
82872 char data[0];
82873 };
82874
82875 diff --git a/include/net/netlink.h b/include/net/netlink.h
82876 index 2b47eaa..6d5bcc2 100644
82877 --- a/include/net/netlink.h
82878 +++ b/include/net/netlink.h
82879 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
82880 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
82881 {
82882 if (mark)
82883 - skb_trim(skb, (unsigned char *) mark - skb->data);
82884 + skb_trim(skb, (const unsigned char *) mark - skb->data);
82885 }
82886
82887 /**
82888 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
82889 index fbcc7fa..03c7e51 100644
82890 --- a/include/net/netns/conntrack.h
82891 +++ b/include/net/netns/conntrack.h
82892 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
82893 struct nf_proto_net {
82894 #ifdef CONFIG_SYSCTL
82895 struct ctl_table_header *ctl_table_header;
82896 - struct ctl_table *ctl_table;
82897 + ctl_table_no_const *ctl_table;
82898 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
82899 struct ctl_table_header *ctl_compat_header;
82900 - struct ctl_table *ctl_compat_table;
82901 + ctl_table_no_const *ctl_compat_table;
82902 #endif
82903 #endif
82904 unsigned int users;
82905 @@ -58,7 +58,7 @@ struct nf_ip_net {
82906 struct nf_icmp_net icmpv6;
82907 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
82908 struct ctl_table_header *ctl_table_header;
82909 - struct ctl_table *ctl_table;
82910 + ctl_table_no_const *ctl_table;
82911 #endif
82912 };
82913
82914 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
82915 index 80f500a..f0c23c2 100644
82916 --- a/include/net/netns/ipv4.h
82917 +++ b/include/net/netns/ipv4.h
82918 @@ -74,7 +74,7 @@ struct netns_ipv4 {
82919
82920 kgid_t sysctl_ping_group_range[2];
82921
82922 - atomic_t dev_addr_genid;
82923 + atomic_unchecked_t dev_addr_genid;
82924
82925 #ifdef CONFIG_IP_MROUTE
82926 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
82927 @@ -84,6 +84,6 @@ struct netns_ipv4 {
82928 struct fib_rules_ops *mr_rules_ops;
82929 #endif
82930 #endif
82931 - atomic_t rt_genid;
82932 + atomic_unchecked_t rt_genid;
82933 };
82934 #endif
82935 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
82936 index 21edaf1..4c5faae 100644
82937 --- a/include/net/netns/ipv6.h
82938 +++ b/include/net/netns/ipv6.h
82939 @@ -73,8 +73,8 @@ struct netns_ipv6 {
82940 struct fib_rules_ops *mr6_rules_ops;
82941 #endif
82942 #endif
82943 - atomic_t dev_addr_genid;
82944 - atomic_t rt_genid;
82945 + atomic_unchecked_t dev_addr_genid;
82946 + atomic_unchecked_t rt_genid;
82947 };
82948
82949 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
82950 diff --git a/include/net/ping.h b/include/net/ping.h
82951 index 026479b..d9b2829 100644
82952 --- a/include/net/ping.h
82953 +++ b/include/net/ping.h
82954 @@ -54,7 +54,7 @@ struct ping_iter_state {
82955
82956 extern struct proto ping_prot;
82957 #if IS_ENABLED(CONFIG_IPV6)
82958 -extern struct pingv6_ops pingv6_ops;
82959 +extern struct pingv6_ops *pingv6_ops;
82960 #endif
82961
82962 struct pingfakehdr {
82963 diff --git a/include/net/protocol.h b/include/net/protocol.h
82964 index a7e986b..dc67bce 100644
82965 --- a/include/net/protocol.h
82966 +++ b/include/net/protocol.h
82967 @@ -49,7 +49,7 @@ struct net_protocol {
82968 * socket lookup?
82969 */
82970 icmp_strict_tag_validation:1;
82971 -};
82972 +} __do_const;
82973
82974 #if IS_ENABLED(CONFIG_IPV6)
82975 struct inet6_protocol {
82976 @@ -62,7 +62,7 @@ struct inet6_protocol {
82977 u8 type, u8 code, int offset,
82978 __be32 info);
82979 unsigned int flags; /* INET6_PROTO_xxx */
82980 -};
82981 +} __do_const;
82982
82983 #define INET6_PROTO_NOPOLICY 0x1
82984 #define INET6_PROTO_FINAL 0x2
82985 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
82986 index 661e45d..54c39df 100644
82987 --- a/include/net/rtnetlink.h
82988 +++ b/include/net/rtnetlink.h
82989 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
82990 int (*fill_slave_info)(struct sk_buff *skb,
82991 const struct net_device *dev,
82992 const struct net_device *slave_dev);
82993 -};
82994 +} __do_const;
82995
82996 int __rtnl_link_register(struct rtnl_link_ops *ops);
82997 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
82998 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
82999 index 4a5b9a3..ca27d73 100644
83000 --- a/include/net/sctp/checksum.h
83001 +++ b/include/net/sctp/checksum.h
83002 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83003 unsigned int offset)
83004 {
83005 struct sctphdr *sh = sctp_hdr(skb);
83006 - __le32 ret, old = sh->checksum;
83007 - const struct skb_checksum_ops ops = {
83008 + __le32 ret, old = sh->checksum;
83009 + static const struct skb_checksum_ops ops = {
83010 .update = sctp_csum_update,
83011 .combine = sctp_csum_combine,
83012 };
83013 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83014 index 7f4eeb3..37e8fe1 100644
83015 --- a/include/net/sctp/sm.h
83016 +++ b/include/net/sctp/sm.h
83017 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83018 typedef struct {
83019 sctp_state_fn_t *fn;
83020 const char *name;
83021 -} sctp_sm_table_entry_t;
83022 +} __do_const sctp_sm_table_entry_t;
83023
83024 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83025 * currently in use.
83026 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83027 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83028
83029 /* Extern declarations for major data structures. */
83030 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83031 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83032
83033
83034 /* Get the size of a DATA chunk payload. */
83035 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83036 index 6ee76c8..45f2609 100644
83037 --- a/include/net/sctp/structs.h
83038 +++ b/include/net/sctp/structs.h
83039 @@ -507,7 +507,7 @@ struct sctp_pf {
83040 struct sctp_association *asoc);
83041 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83042 struct sctp_af *af;
83043 -};
83044 +} __do_const;
83045
83046
83047 /* Structure to track chunk fragments that have been acked, but peer
83048 diff --git a/include/net/sock.h b/include/net/sock.h
83049 index b9586a1..b2948c0 100644
83050 --- a/include/net/sock.h
83051 +++ b/include/net/sock.h
83052 @@ -348,7 +348,7 @@ struct sock {
83053 unsigned int sk_napi_id;
83054 unsigned int sk_ll_usec;
83055 #endif
83056 - atomic_t sk_drops;
83057 + atomic_unchecked_t sk_drops;
83058 int sk_rcvbuf;
83059
83060 struct sk_filter __rcu *sk_filter;
83061 @@ -1036,7 +1036,7 @@ struct proto {
83062 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83063 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83064 #endif
83065 -};
83066 +} __randomize_layout;
83067
83068 /*
83069 * Bits in struct cg_proto.flags
83070 @@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83071 return ret >> PAGE_SHIFT;
83072 }
83073
83074 -static inline long
83075 +static inline long __intentional_overflow(-1)
83076 sk_memory_allocated(const struct sock *sk)
83077 {
83078 struct proto *prot = sk->sk_prot;
83079 @@ -1368,7 +1368,7 @@ struct sock_iocb {
83080 struct scm_cookie *scm;
83081 struct msghdr *msg, async_msg;
83082 struct kiocb *kiocb;
83083 -};
83084 +} __randomize_layout;
83085
83086 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83087 {
83088 @@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83089 }
83090
83091 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83092 - char __user *from, char *to,
83093 + char __user *from, unsigned char *to,
83094 int copy, int offset)
83095 {
83096 if (skb->ip_summed == CHECKSUM_NONE) {
83097 @@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83098 }
83099 }
83100
83101 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83102 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83103
83104 /**
83105 * sk_page_frag - return an appropriate page_frag
83106 diff --git a/include/net/tcp.h b/include/net/tcp.h
83107 index 743acce..44a58b0 100644
83108 --- a/include/net/tcp.h
83109 +++ b/include/net/tcp.h
83110 @@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83111 void tcp_xmit_retransmit_queue(struct sock *);
83112 void tcp_simple_retransmit(struct sock *);
83113 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83114 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83115 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83116
83117 void tcp_send_probe0(struct sock *);
83118 void tcp_send_partial(struct sock *);
83119 @@ -710,8 +710,8 @@ struct tcp_skb_cb {
83120 struct inet6_skb_parm h6;
83121 #endif
83122 } header; /* For incoming frames */
83123 - __u32 seq; /* Starting sequence number */
83124 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83125 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
83126 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83127 __u32 when; /* used to compute rtt's */
83128 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83129
83130 @@ -725,7 +725,7 @@ struct tcp_skb_cb {
83131
83132 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83133 /* 1 byte hole */
83134 - __u32 ack_seq; /* Sequence number ACK'd */
83135 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83136 };
83137
83138 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83139 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83140 index fb5654a..4457522 100644
83141 --- a/include/net/xfrm.h
83142 +++ b/include/net/xfrm.h
83143 @@ -286,7 +286,6 @@ struct xfrm_dst;
83144 struct xfrm_policy_afinfo {
83145 unsigned short family;
83146 struct dst_ops *dst_ops;
83147 - void (*garbage_collect)(struct net *net);
83148 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83149 const xfrm_address_t *saddr,
83150 const xfrm_address_t *daddr);
83151 @@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
83152 struct net_device *dev,
83153 const struct flowi *fl);
83154 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83155 -};
83156 +} __do_const;
83157
83158 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83159 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83160 @@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
83161 int (*transport_finish)(struct sk_buff *skb,
83162 int async);
83163 void (*local_error)(struct sk_buff *skb, u32 mtu);
83164 -};
83165 +} __do_const;
83166
83167 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83168 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83169 @@ -428,7 +427,7 @@ struct xfrm_mode {
83170 struct module *owner;
83171 unsigned int encap;
83172 int flags;
83173 -};
83174 +} __do_const;
83175
83176 /* Flags for xfrm_mode. */
83177 enum {
83178 @@ -525,7 +524,7 @@ struct xfrm_policy {
83179 struct timer_list timer;
83180
83181 struct flow_cache_object flo;
83182 - atomic_t genid;
83183 + atomic_unchecked_t genid;
83184 u32 priority;
83185 u32 index;
83186 struct xfrm_mark mark;
83187 @@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83188 }
83189
83190 void xfrm_garbage_collect(struct net *net);
83191 +void xfrm_garbage_collect_deferred(struct net *net);
83192
83193 #else
83194
83195 @@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83196 static inline void xfrm_garbage_collect(struct net *net)
83197 {
83198 }
83199 +static inline void xfrm_garbage_collect_deferred(struct net *net)
83200 +{
83201 +}
83202 #endif
83203
83204 static __inline__
83205 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83206 index 1017e0b..227aa4d 100644
83207 --- a/include/rdma/iw_cm.h
83208 +++ b/include/rdma/iw_cm.h
83209 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
83210 int backlog);
83211
83212 int (*destroy_listen)(struct iw_cm_id *cm_id);
83213 -};
83214 +} __no_const;
83215
83216 /**
83217 * iw_create_cm_id - Create an IW CM identifier.
83218 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83219 index 52beadf..598734c 100644
83220 --- a/include/scsi/libfc.h
83221 +++ b/include/scsi/libfc.h
83222 @@ -771,6 +771,7 @@ struct libfc_function_template {
83223 */
83224 void (*disc_stop_final) (struct fc_lport *);
83225 };
83226 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83227
83228 /**
83229 * struct fc_disc - Discovery context
83230 @@ -875,7 +876,7 @@ struct fc_lport {
83231 struct fc_vport *vport;
83232
83233 /* Operational Information */
83234 - struct libfc_function_template tt;
83235 + libfc_function_template_no_const tt;
83236 u8 link_up;
83237 u8 qfull;
83238 enum fc_lport_state state;
83239 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83240 index d65fbec..f80fef2 100644
83241 --- a/include/scsi/scsi_device.h
83242 +++ b/include/scsi/scsi_device.h
83243 @@ -180,9 +180,9 @@ struct scsi_device {
83244 unsigned int max_device_blocked; /* what device_blocked counts down from */
83245 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83246
83247 - atomic_t iorequest_cnt;
83248 - atomic_t iodone_cnt;
83249 - atomic_t ioerr_cnt;
83250 + atomic_unchecked_t iorequest_cnt;
83251 + atomic_unchecked_t iodone_cnt;
83252 + atomic_unchecked_t ioerr_cnt;
83253
83254 struct device sdev_gendev,
83255 sdev_dev;
83256 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83257 index b797e8f..8e2c3aa 100644
83258 --- a/include/scsi/scsi_transport_fc.h
83259 +++ b/include/scsi/scsi_transport_fc.h
83260 @@ -751,7 +751,8 @@ struct fc_function_template {
83261 unsigned long show_host_system_hostname:1;
83262
83263 unsigned long disable_target_scan:1;
83264 -};
83265 +} __do_const;
83266 +typedef struct fc_function_template __no_const fc_function_template_no_const;
83267
83268
83269 /**
83270 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83271 index ae6c3b8..fd748ac 100644
83272 --- a/include/sound/compress_driver.h
83273 +++ b/include/sound/compress_driver.h
83274 @@ -128,7 +128,7 @@ struct snd_compr_ops {
83275 struct snd_compr_caps *caps);
83276 int (*get_codec_caps) (struct snd_compr_stream *stream,
83277 struct snd_compr_codec_caps *codec);
83278 -};
83279 +} __no_const;
83280
83281 /**
83282 * struct snd_compr: Compressed device
83283 diff --git a/include/sound/soc.h b/include/sound/soc.h
83284 index 9a00147..d814573 100644
83285 --- a/include/sound/soc.h
83286 +++ b/include/sound/soc.h
83287 @@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
83288 /* probe ordering - for components with runtime dependencies */
83289 int probe_order;
83290 int remove_order;
83291 -};
83292 +} __do_const;
83293
83294 /* SoC platform interface */
83295 struct snd_soc_platform_driver {
83296 @@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
83297 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83298 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83299 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83300 -};
83301 +} __do_const;
83302
83303 struct snd_soc_platform {
83304 const char *name;
83305 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83306 index 1772fad..282e3e2 100644
83307 --- a/include/target/target_core_base.h
83308 +++ b/include/target/target_core_base.h
83309 @@ -754,7 +754,7 @@ struct se_device {
83310 atomic_long_t write_bytes;
83311 /* Active commands on this virtual SE device */
83312 atomic_t simple_cmds;
83313 - atomic_t dev_ordered_id;
83314 + atomic_unchecked_t dev_ordered_id;
83315 atomic_t dev_ordered_sync;
83316 atomic_t dev_qf_count;
83317 int export_count;
83318 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83319 new file mode 100644
83320 index 0000000..fb634b7
83321 --- /dev/null
83322 +++ b/include/trace/events/fs.h
83323 @@ -0,0 +1,53 @@
83324 +#undef TRACE_SYSTEM
83325 +#define TRACE_SYSTEM fs
83326 +
83327 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
83328 +#define _TRACE_FS_H
83329 +
83330 +#include <linux/fs.h>
83331 +#include <linux/tracepoint.h>
83332 +
83333 +TRACE_EVENT(do_sys_open,
83334 +
83335 + TP_PROTO(const char *filename, int flags, int mode),
83336 +
83337 + TP_ARGS(filename, flags, mode),
83338 +
83339 + TP_STRUCT__entry(
83340 + __string( filename, filename )
83341 + __field( int, flags )
83342 + __field( int, mode )
83343 + ),
83344 +
83345 + TP_fast_assign(
83346 + __assign_str(filename, filename);
83347 + __entry->flags = flags;
83348 + __entry->mode = mode;
83349 + ),
83350 +
83351 + TP_printk("\"%s\" %x %o",
83352 + __get_str(filename), __entry->flags, __entry->mode)
83353 +);
83354 +
83355 +TRACE_EVENT(open_exec,
83356 +
83357 + TP_PROTO(const char *filename),
83358 +
83359 + TP_ARGS(filename),
83360 +
83361 + TP_STRUCT__entry(
83362 + __string( filename, filename )
83363 + ),
83364 +
83365 + TP_fast_assign(
83366 + __assign_str(filename, filename);
83367 + ),
83368 +
83369 + TP_printk("\"%s\"",
83370 + __get_str(filename))
83371 +);
83372 +
83373 +#endif /* _TRACE_FS_H */
83374 +
83375 +/* This part must be outside protection */
83376 +#include <trace/define_trace.h>
83377 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
83378 index 1c09820..7f5ec79 100644
83379 --- a/include/trace/events/irq.h
83380 +++ b/include/trace/events/irq.h
83381 @@ -36,7 +36,7 @@ struct softirq_action;
83382 */
83383 TRACE_EVENT(irq_handler_entry,
83384
83385 - TP_PROTO(int irq, struct irqaction *action),
83386 + TP_PROTO(int irq, const struct irqaction *action),
83387
83388 TP_ARGS(irq, action),
83389
83390 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
83391 */
83392 TRACE_EVENT(irq_handler_exit,
83393
83394 - TP_PROTO(int irq, struct irqaction *action, int ret),
83395 + TP_PROTO(int irq, const struct irqaction *action, int ret),
83396
83397 TP_ARGS(irq, action, ret),
83398
83399 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
83400 index 7caf44c..23c6f27 100644
83401 --- a/include/uapi/linux/a.out.h
83402 +++ b/include/uapi/linux/a.out.h
83403 @@ -39,6 +39,14 @@ enum machine_type {
83404 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
83405 };
83406
83407 +/* Constants for the N_FLAGS field */
83408 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83409 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
83410 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
83411 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
83412 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83413 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83414 +
83415 #if !defined (N_MAGIC)
83416 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
83417 #endif
83418 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
83419 index 22b6ad3..aeba37e 100644
83420 --- a/include/uapi/linux/bcache.h
83421 +++ b/include/uapi/linux/bcache.h
83422 @@ -5,6 +5,7 @@
83423 * Bcache on disk data structures
83424 */
83425
83426 +#include <linux/compiler.h>
83427 #include <asm/types.h>
83428
83429 #define BITMASK(name, type, field, offset, size) \
83430 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
83431 /* Btree keys - all units are in sectors */
83432
83433 struct bkey {
83434 - __u64 high;
83435 - __u64 low;
83436 + __u64 high __intentional_overflow(-1);
83437 + __u64 low __intentional_overflow(-1);
83438 __u64 ptr[];
83439 };
83440
83441 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
83442 index d876736..ccce5c0 100644
83443 --- a/include/uapi/linux/byteorder/little_endian.h
83444 +++ b/include/uapi/linux/byteorder/little_endian.h
83445 @@ -42,51 +42,51 @@
83446
83447 static inline __le64 __cpu_to_le64p(const __u64 *p)
83448 {
83449 - return (__force __le64)*p;
83450 + return (__force const __le64)*p;
83451 }
83452 -static inline __u64 __le64_to_cpup(const __le64 *p)
83453 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
83454 {
83455 - return (__force __u64)*p;
83456 + return (__force const __u64)*p;
83457 }
83458 static inline __le32 __cpu_to_le32p(const __u32 *p)
83459 {
83460 - return (__force __le32)*p;
83461 + return (__force const __le32)*p;
83462 }
83463 static inline __u32 __le32_to_cpup(const __le32 *p)
83464 {
83465 - return (__force __u32)*p;
83466 + return (__force const __u32)*p;
83467 }
83468 static inline __le16 __cpu_to_le16p(const __u16 *p)
83469 {
83470 - return (__force __le16)*p;
83471 + return (__force const __le16)*p;
83472 }
83473 static inline __u16 __le16_to_cpup(const __le16 *p)
83474 {
83475 - return (__force __u16)*p;
83476 + return (__force const __u16)*p;
83477 }
83478 static inline __be64 __cpu_to_be64p(const __u64 *p)
83479 {
83480 - return (__force __be64)__swab64p(p);
83481 + return (__force const __be64)__swab64p(p);
83482 }
83483 static inline __u64 __be64_to_cpup(const __be64 *p)
83484 {
83485 - return __swab64p((__u64 *)p);
83486 + return __swab64p((const __u64 *)p);
83487 }
83488 static inline __be32 __cpu_to_be32p(const __u32 *p)
83489 {
83490 - return (__force __be32)__swab32p(p);
83491 + return (__force const __be32)__swab32p(p);
83492 }
83493 -static inline __u32 __be32_to_cpup(const __be32 *p)
83494 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
83495 {
83496 - return __swab32p((__u32 *)p);
83497 + return __swab32p((const __u32 *)p);
83498 }
83499 static inline __be16 __cpu_to_be16p(const __u16 *p)
83500 {
83501 - return (__force __be16)__swab16p(p);
83502 + return (__force const __be16)__swab16p(p);
83503 }
83504 static inline __u16 __be16_to_cpup(const __be16 *p)
83505 {
83506 - return __swab16p((__u16 *)p);
83507 + return __swab16p((const __u16 *)p);
83508 }
83509 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
83510 #define __le64_to_cpus(x) do { (void)(x); } while (0)
83511 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
83512 index ef6103b..d4e65dd 100644
83513 --- a/include/uapi/linux/elf.h
83514 +++ b/include/uapi/linux/elf.h
83515 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
83516 #define PT_GNU_EH_FRAME 0x6474e550
83517
83518 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
83519 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
83520 +
83521 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
83522 +
83523 +/* Constants for the e_flags field */
83524 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83525 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
83526 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
83527 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
83528 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83529 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83530
83531 /*
83532 * Extended Numbering
83533 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
83534 #define DT_DEBUG 21
83535 #define DT_TEXTREL 22
83536 #define DT_JMPREL 23
83537 +#define DT_FLAGS 30
83538 + #define DF_TEXTREL 0x00000004
83539 #define DT_ENCODING 32
83540 #define OLD_DT_LOOS 0x60000000
83541 #define DT_LOOS 0x6000000d
83542 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
83543 #define PF_W 0x2
83544 #define PF_X 0x1
83545
83546 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
83547 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
83548 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
83549 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
83550 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
83551 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
83552 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
83553 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
83554 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
83555 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
83556 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
83557 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
83558 +
83559 typedef struct elf32_phdr{
83560 Elf32_Word p_type;
83561 Elf32_Off p_offset;
83562 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
83563 #define EI_OSABI 7
83564 #define EI_PAD 8
83565
83566 +#define EI_PAX 14
83567 +
83568 #define ELFMAG0 0x7f /* EI_MAG */
83569 #define ELFMAG1 'E'
83570 #define ELFMAG2 'L'
83571 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
83572 index aa169c4..6a2771d 100644
83573 --- a/include/uapi/linux/personality.h
83574 +++ b/include/uapi/linux/personality.h
83575 @@ -30,6 +30,7 @@ enum {
83576 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
83577 ADDR_NO_RANDOMIZE | \
83578 ADDR_COMPAT_LAYOUT | \
83579 + ADDR_LIMIT_3GB | \
83580 MMAP_PAGE_ZERO)
83581
83582 /*
83583 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
83584 index 7530e74..e714828 100644
83585 --- a/include/uapi/linux/screen_info.h
83586 +++ b/include/uapi/linux/screen_info.h
83587 @@ -43,7 +43,8 @@ struct screen_info {
83588 __u16 pages; /* 0x32 */
83589 __u16 vesa_attributes; /* 0x34 */
83590 __u32 capabilities; /* 0x36 */
83591 - __u8 _reserved[6]; /* 0x3a */
83592 + __u16 vesapm_size; /* 0x3a */
83593 + __u8 _reserved[4]; /* 0x3c */
83594 } __attribute__((packed));
83595
83596 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
83597 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
83598 index 0e011eb..82681b1 100644
83599 --- a/include/uapi/linux/swab.h
83600 +++ b/include/uapi/linux/swab.h
83601 @@ -43,7 +43,7 @@
83602 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
83603 */
83604
83605 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
83606 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
83607 {
83608 #ifdef __HAVE_BUILTIN_BSWAP16__
83609 return __builtin_bswap16(val);
83610 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
83611 #endif
83612 }
83613
83614 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
83615 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
83616 {
83617 #ifdef __HAVE_BUILTIN_BSWAP32__
83618 return __builtin_bswap32(val);
83619 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
83620 #endif
83621 }
83622
83623 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
83624 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
83625 {
83626 #ifdef __HAVE_BUILTIN_BSWAP64__
83627 return __builtin_bswap64(val);
83628 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
83629 index 6d67213..552fdd9 100644
83630 --- a/include/uapi/linux/sysctl.h
83631 +++ b/include/uapi/linux/sysctl.h
83632 @@ -155,8 +155,6 @@ enum
83633 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
83634 };
83635
83636 -
83637 -
83638 /* CTL_VM names: */
83639 enum
83640 {
83641 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
83642 index 6ae7bbe..1e487fe 100644
83643 --- a/include/uapi/linux/videodev2.h
83644 +++ b/include/uapi/linux/videodev2.h
83645 @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
83646 union {
83647 __s32 value;
83648 __s64 value64;
83649 - char *string;
83650 + char __user *string;
83651 };
83652 } __attribute__ ((packed));
83653
83654 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
83655 index 40bbc04..e30d9a2 100644
83656 --- a/include/uapi/linux/xattr.h
83657 +++ b/include/uapi/linux/xattr.h
83658 @@ -66,5 +66,9 @@
83659 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
83660 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
83661
83662 +/* User namespace */
83663 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
83664 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
83665 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
83666
83667 #endif /* _UAPI_LINUX_XATTR_H */
83668 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
83669 index f9466fa..f4e2b81 100644
83670 --- a/include/video/udlfb.h
83671 +++ b/include/video/udlfb.h
83672 @@ -53,10 +53,10 @@ struct dlfb_data {
83673 u32 pseudo_palette[256];
83674 int blank_mode; /*one of FB_BLANK_ */
83675 /* blit-only rendering path metrics, exposed through sysfs */
83676 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83677 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
83678 - atomic_t bytes_sent; /* to usb, after compression including overhead */
83679 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
83680 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83681 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
83682 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
83683 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
83684 };
83685
83686 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
83687 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
83688 index 30f5362..8ed8ac9 100644
83689 --- a/include/video/uvesafb.h
83690 +++ b/include/video/uvesafb.h
83691 @@ -122,6 +122,7 @@ struct uvesafb_par {
83692 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
83693 u8 pmi_setpal; /* PMI for palette changes */
83694 u16 *pmi_base; /* protected mode interface location */
83695 + u8 *pmi_code; /* protected mode code location */
83696 void *pmi_start;
83697 void *pmi_pal;
83698 u8 *vbe_state_orig; /*
83699 diff --git a/init/Kconfig b/init/Kconfig
83700 index d56cb03..7e6d5dc 100644
83701 --- a/init/Kconfig
83702 +++ b/init/Kconfig
83703 @@ -1079,6 +1079,7 @@ endif # CGROUPS
83704
83705 config CHECKPOINT_RESTORE
83706 bool "Checkpoint/restore support" if EXPERT
83707 + depends on !GRKERNSEC
83708 default n
83709 help
83710 Enables additional kernel features in a sake of checkpoint/restore.
83711 @@ -1545,7 +1546,7 @@ config SLUB_DEBUG
83712
83713 config COMPAT_BRK
83714 bool "Disable heap randomization"
83715 - default y
83716 + default n
83717 help
83718 Randomizing heap placement makes heap exploits harder, but it
83719 also breaks ancient binaries (including anything libc5 based).
83720 @@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
83721 config STOP_MACHINE
83722 bool
83723 default y
83724 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
83725 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
83726 help
83727 Need stop_machine() primitive.
83728
83729 diff --git a/init/Makefile b/init/Makefile
83730 index 7bc47ee..6da2dc7 100644
83731 --- a/init/Makefile
83732 +++ b/init/Makefile
83733 @@ -2,6 +2,9 @@
83734 # Makefile for the linux kernel.
83735 #
83736
83737 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
83738 +asflags-y := $(GCC_PLUGINS_AFLAGS)
83739 +
83740 obj-y := main.o version.o mounts.o
83741 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
83742 obj-y += noinitramfs.o
83743 diff --git a/init/do_mounts.c b/init/do_mounts.c
83744 index 8e5addc..c96ea61 100644
83745 --- a/init/do_mounts.c
83746 +++ b/init/do_mounts.c
83747 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
83748 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
83749 {
83750 struct super_block *s;
83751 - int err = sys_mount(name, "/root", fs, flags, data);
83752 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
83753 if (err)
83754 return err;
83755
83756 - sys_chdir("/root");
83757 + sys_chdir((const char __force_user *)"/root");
83758 s = current->fs->pwd.dentry->d_sb;
83759 ROOT_DEV = s->s_dev;
83760 printk(KERN_INFO
83761 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
83762 va_start(args, fmt);
83763 vsprintf(buf, fmt, args);
83764 va_end(args);
83765 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
83766 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
83767 if (fd >= 0) {
83768 sys_ioctl(fd, FDEJECT, 0);
83769 sys_close(fd);
83770 }
83771 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
83772 - fd = sys_open("/dev/console", O_RDWR, 0);
83773 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
83774 if (fd >= 0) {
83775 sys_ioctl(fd, TCGETS, (long)&termios);
83776 termios.c_lflag &= ~ICANON;
83777 sys_ioctl(fd, TCSETSF, (long)&termios);
83778 - sys_read(fd, &c, 1);
83779 + sys_read(fd, (char __user *)&c, 1);
83780 termios.c_lflag |= ICANON;
83781 sys_ioctl(fd, TCSETSF, (long)&termios);
83782 sys_close(fd);
83783 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
83784 mount_root();
83785 out:
83786 devtmpfs_mount("dev");
83787 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
83788 - sys_chroot(".");
83789 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83790 + sys_chroot((const char __force_user *)".");
83791 }
83792
83793 static bool is_tmpfs;
83794 diff --git a/init/do_mounts.h b/init/do_mounts.h
83795 index f5b978a..69dbfe8 100644
83796 --- a/init/do_mounts.h
83797 +++ b/init/do_mounts.h
83798 @@ -15,15 +15,15 @@ extern int root_mountflags;
83799
83800 static inline int create_dev(char *name, dev_t dev)
83801 {
83802 - sys_unlink(name);
83803 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
83804 + sys_unlink((char __force_user *)name);
83805 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
83806 }
83807
83808 #if BITS_PER_LONG == 32
83809 static inline u32 bstat(char *name)
83810 {
83811 struct stat64 stat;
83812 - if (sys_stat64(name, &stat) != 0)
83813 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
83814 return 0;
83815 if (!S_ISBLK(stat.st_mode))
83816 return 0;
83817 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
83818 static inline u32 bstat(char *name)
83819 {
83820 struct stat stat;
83821 - if (sys_newstat(name, &stat) != 0)
83822 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
83823 return 0;
83824 if (!S_ISBLK(stat.st_mode))
83825 return 0;
83826 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
83827 index 3e0878e..8a9d7a0 100644
83828 --- a/init/do_mounts_initrd.c
83829 +++ b/init/do_mounts_initrd.c
83830 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
83831 {
83832 sys_unshare(CLONE_FS | CLONE_FILES);
83833 /* stdin/stdout/stderr for /linuxrc */
83834 - sys_open("/dev/console", O_RDWR, 0);
83835 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
83836 sys_dup(0);
83837 sys_dup(0);
83838 /* move initrd over / and chdir/chroot in initrd root */
83839 - sys_chdir("/root");
83840 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
83841 - sys_chroot(".");
83842 + sys_chdir((const char __force_user *)"/root");
83843 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83844 + sys_chroot((const char __force_user *)".");
83845 sys_setsid();
83846 return 0;
83847 }
83848 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
83849 create_dev("/dev/root.old", Root_RAM0);
83850 /* mount initrd on rootfs' /root */
83851 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
83852 - sys_mkdir("/old", 0700);
83853 - sys_chdir("/old");
83854 + sys_mkdir((const char __force_user *)"/old", 0700);
83855 + sys_chdir((const char __force_user *)"/old");
83856
83857 /* try loading default modules from initrd */
83858 load_default_modules();
83859 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
83860 current->flags &= ~PF_FREEZER_SKIP;
83861
83862 /* move initrd to rootfs' /old */
83863 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
83864 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
83865 /* switch root and cwd back to / of rootfs */
83866 - sys_chroot("..");
83867 + sys_chroot((const char __force_user *)"..");
83868
83869 if (new_decode_dev(real_root_dev) == Root_RAM0) {
83870 - sys_chdir("/old");
83871 + sys_chdir((const char __force_user *)"/old");
83872 return;
83873 }
83874
83875 - sys_chdir("/");
83876 + sys_chdir((const char __force_user *)"/");
83877 ROOT_DEV = new_decode_dev(real_root_dev);
83878 mount_root();
83879
83880 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
83881 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
83882 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
83883 if (!error)
83884 printk("okay\n");
83885 else {
83886 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
83887 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
83888 if (error == -ENOENT)
83889 printk("/initrd does not exist. Ignored.\n");
83890 else
83891 printk("failed\n");
83892 printk(KERN_NOTICE "Unmounting old root\n");
83893 - sys_umount("/old", MNT_DETACH);
83894 + sys_umount((char __force_user *)"/old", MNT_DETACH);
83895 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
83896 if (fd < 0) {
83897 error = fd;
83898 @@ -127,11 +127,11 @@ int __init initrd_load(void)
83899 * mounted in the normal path.
83900 */
83901 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
83902 - sys_unlink("/initrd.image");
83903 + sys_unlink((const char __force_user *)"/initrd.image");
83904 handle_initrd();
83905 return 1;
83906 }
83907 }
83908 - sys_unlink("/initrd.image");
83909 + sys_unlink((const char __force_user *)"/initrd.image");
83910 return 0;
83911 }
83912 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
83913 index 8cb6db5..d729f50 100644
83914 --- a/init/do_mounts_md.c
83915 +++ b/init/do_mounts_md.c
83916 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
83917 partitioned ? "_d" : "", minor,
83918 md_setup_args[ent].device_names);
83919
83920 - fd = sys_open(name, 0, 0);
83921 + fd = sys_open((char __force_user *)name, 0, 0);
83922 if (fd < 0) {
83923 printk(KERN_ERR "md: open failed - cannot start "
83924 "array %s\n", name);
83925 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
83926 * array without it
83927 */
83928 sys_close(fd);
83929 - fd = sys_open(name, 0, 0);
83930 + fd = sys_open((char __force_user *)name, 0, 0);
83931 sys_ioctl(fd, BLKRRPART, 0);
83932 }
83933 sys_close(fd);
83934 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
83935
83936 wait_for_device_probe();
83937
83938 - fd = sys_open("/dev/md0", 0, 0);
83939 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
83940 if (fd >= 0) {
83941 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
83942 sys_close(fd);
83943 diff --git a/init/init_task.c b/init/init_task.c
83944 index ba0a7f36..2bcf1d5 100644
83945 --- a/init/init_task.c
83946 +++ b/init/init_task.c
83947 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
83948 * Initial thread structure. Alignment of this is handled by a special
83949 * linker map entry.
83950 */
83951 +#ifdef CONFIG_X86
83952 +union thread_union init_thread_union __init_task_data;
83953 +#else
83954 union thread_union init_thread_union __init_task_data =
83955 { INIT_THREAD_INFO(init_task) };
83956 +#endif
83957 diff --git a/init/initramfs.c b/init/initramfs.c
83958 index 93b6139..8d628b7 100644
83959 --- a/init/initramfs.c
83960 +++ b/init/initramfs.c
83961 @@ -84,7 +84,7 @@ static void __init free_hash(void)
83962 }
83963 }
83964
83965 -static long __init do_utime(char *filename, time_t mtime)
83966 +static long __init do_utime(char __force_user *filename, time_t mtime)
83967 {
83968 struct timespec t[2];
83969
83970 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
83971 struct dir_entry *de, *tmp;
83972 list_for_each_entry_safe(de, tmp, &dir_list, list) {
83973 list_del(&de->list);
83974 - do_utime(de->name, de->mtime);
83975 + do_utime((char __force_user *)de->name, de->mtime);
83976 kfree(de->name);
83977 kfree(de);
83978 }
83979 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
83980 if (nlink >= 2) {
83981 char *old = find_link(major, minor, ino, mode, collected);
83982 if (old)
83983 - return (sys_link(old, collected) < 0) ? -1 : 1;
83984 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
83985 }
83986 return 0;
83987 }
83988 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
83989 {
83990 struct stat st;
83991
83992 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
83993 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
83994 if (S_ISDIR(st.st_mode))
83995 - sys_rmdir(path);
83996 + sys_rmdir((char __force_user *)path);
83997 else
83998 - sys_unlink(path);
83999 + sys_unlink((char __force_user *)path);
84000 }
84001 }
84002
84003 @@ -315,7 +315,7 @@ static int __init do_name(void)
84004 int openflags = O_WRONLY|O_CREAT;
84005 if (ml != 1)
84006 openflags |= O_TRUNC;
84007 - wfd = sys_open(collected, openflags, mode);
84008 + wfd = sys_open((char __force_user *)collected, openflags, mode);
84009
84010 if (wfd >= 0) {
84011 sys_fchown(wfd, uid, gid);
84012 @@ -327,17 +327,17 @@ static int __init do_name(void)
84013 }
84014 }
84015 } else if (S_ISDIR(mode)) {
84016 - sys_mkdir(collected, mode);
84017 - sys_chown(collected, uid, gid);
84018 - sys_chmod(collected, mode);
84019 + sys_mkdir((char __force_user *)collected, mode);
84020 + sys_chown((char __force_user *)collected, uid, gid);
84021 + sys_chmod((char __force_user *)collected, mode);
84022 dir_add(collected, mtime);
84023 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84024 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84025 if (maybe_link() == 0) {
84026 - sys_mknod(collected, mode, rdev);
84027 - sys_chown(collected, uid, gid);
84028 - sys_chmod(collected, mode);
84029 - do_utime(collected, mtime);
84030 + sys_mknod((char __force_user *)collected, mode, rdev);
84031 + sys_chown((char __force_user *)collected, uid, gid);
84032 + sys_chmod((char __force_user *)collected, mode);
84033 + do_utime((char __force_user *)collected, mtime);
84034 }
84035 }
84036 return 0;
84037 @@ -346,15 +346,15 @@ static int __init do_name(void)
84038 static int __init do_copy(void)
84039 {
84040 if (count >= body_len) {
84041 - sys_write(wfd, victim, body_len);
84042 + sys_write(wfd, (char __force_user *)victim, body_len);
84043 sys_close(wfd);
84044 - do_utime(vcollected, mtime);
84045 + do_utime((char __force_user *)vcollected, mtime);
84046 kfree(vcollected);
84047 eat(body_len);
84048 state = SkipIt;
84049 return 0;
84050 } else {
84051 - sys_write(wfd, victim, count);
84052 + sys_write(wfd, (char __force_user *)victim, count);
84053 body_len -= count;
84054 eat(count);
84055 return 1;
84056 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
84057 {
84058 collected[N_ALIGN(name_len) + body_len] = '\0';
84059 clean_path(collected, 0);
84060 - sys_symlink(collected + N_ALIGN(name_len), collected);
84061 - sys_lchown(collected, uid, gid);
84062 - do_utime(collected, mtime);
84063 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84064 + sys_lchown((char __force_user *)collected, uid, gid);
84065 + do_utime((char __force_user *)collected, mtime);
84066 state = SkipIt;
84067 next_state = Reset;
84068 return 0;
84069 diff --git a/init/main.c b/init/main.c
84070 index 9c7fd4c..650b4f1 100644
84071 --- a/init/main.c
84072 +++ b/init/main.c
84073 @@ -97,6 +97,8 @@ extern void radix_tree_init(void);
84074 static inline void mark_rodata_ro(void) { }
84075 #endif
84076
84077 +extern void grsecurity_init(void);
84078 +
84079 /*
84080 * Debug helper: via this flag we know that we are in 'early bootup code'
84081 * where only the boot processor is running with IRQ disabled. This means
84082 @@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
84083
84084 __setup("reset_devices", set_reset_devices);
84085
84086 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84087 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84088 +static int __init setup_grsec_proc_gid(char *str)
84089 +{
84090 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84091 + return 1;
84092 +}
84093 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84094 +#endif
84095 +
84096 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84097 +unsigned long pax_user_shadow_base __read_only;
84098 +EXPORT_SYMBOL(pax_user_shadow_base);
84099 +extern char pax_enter_kernel_user[];
84100 +extern char pax_exit_kernel_user[];
84101 +#endif
84102 +
84103 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84104 +static int __init setup_pax_nouderef(char *str)
84105 +{
84106 +#ifdef CONFIG_X86_32
84107 + unsigned int cpu;
84108 + struct desc_struct *gdt;
84109 +
84110 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84111 + gdt = get_cpu_gdt_table(cpu);
84112 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84113 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84114 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84115 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84116 + }
84117 + loadsegment(ds, __KERNEL_DS);
84118 + loadsegment(es, __KERNEL_DS);
84119 + loadsegment(ss, __KERNEL_DS);
84120 +#else
84121 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84122 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84123 + clone_pgd_mask = ~(pgdval_t)0UL;
84124 + pax_user_shadow_base = 0UL;
84125 + setup_clear_cpu_cap(X86_FEATURE_PCID);
84126 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84127 +#endif
84128 +
84129 + return 0;
84130 +}
84131 +early_param("pax_nouderef", setup_pax_nouderef);
84132 +
84133 +#ifdef CONFIG_X86_64
84134 +static int __init setup_pax_weakuderef(char *str)
84135 +{
84136 + if (clone_pgd_mask != ~(pgdval_t)0UL)
84137 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84138 + return 1;
84139 +}
84140 +__setup("pax_weakuderef", setup_pax_weakuderef);
84141 +#endif
84142 +#endif
84143 +
84144 +#ifdef CONFIG_PAX_SOFTMODE
84145 +int pax_softmode;
84146 +
84147 +static int __init setup_pax_softmode(char *str)
84148 +{
84149 + get_option(&str, &pax_softmode);
84150 + return 1;
84151 +}
84152 +__setup("pax_softmode=", setup_pax_softmode);
84153 +#endif
84154 +
84155 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84156 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84157 static const char *panic_later, *panic_param;
84158 @@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84159 {
84160 int count = preempt_count();
84161 int ret;
84162 - char msgbuf[64];
84163 + const char *msg1 = "", *msg2 = "";
84164
84165 if (initcall_debug)
84166 ret = do_one_initcall_debug(fn);
84167 else
84168 ret = fn();
84169
84170 - msgbuf[0] = 0;
84171 -
84172 if (preempt_count() != count) {
84173 - sprintf(msgbuf, "preemption imbalance ");
84174 + msg1 = " preemption imbalance";
84175 preempt_count_set(count);
84176 }
84177 if (irqs_disabled()) {
84178 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84179 + msg2 = " disabled interrupts";
84180 local_irq_enable();
84181 }
84182 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84183 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84184
84185 + add_latent_entropy();
84186 return ret;
84187 }
84188
84189 @@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
84190 {
84191 argv_init[0] = init_filename;
84192 return do_execve(getname_kernel(init_filename),
84193 - (const char __user *const __user *)argv_init,
84194 - (const char __user *const __user *)envp_init);
84195 + (const char __user *const __force_user *)argv_init,
84196 + (const char __user *const __force_user *)envp_init);
84197 }
84198
84199 static int try_to_run_init_process(const char *init_filename)
84200 @@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
84201 return ret;
84202 }
84203
84204 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84205 +extern int gr_init_ran;
84206 +#endif
84207 +
84208 static noinline void __init kernel_init_freeable(void);
84209
84210 static int __ref kernel_init(void *unused)
84211 @@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
84212 ramdisk_execute_command, ret);
84213 }
84214
84215 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84216 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
84217 + gr_init_ran = 1;
84218 +#endif
84219 +
84220 /*
84221 * We try each of these until one succeeds.
84222 *
84223 @@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
84224 do_basic_setup();
84225
84226 /* Open the /dev/console on the rootfs, this should never fail */
84227 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84228 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84229 pr_err("Warning: unable to open an initial console.\n");
84230
84231 (void) sys_dup(0);
84232 @@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
84233 if (!ramdisk_execute_command)
84234 ramdisk_execute_command = "/init";
84235
84236 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84237 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84238 ramdisk_execute_command = NULL;
84239 prepare_namespace();
84240 }
84241
84242 + grsecurity_init();
84243 +
84244 /*
84245 * Ok, we have completed the initial bootup, and
84246 * we're essentially up and running. Get rid of the
84247 diff --git a/ipc/compat.c b/ipc/compat.c
84248 index f486b00..442867f 100644
84249 --- a/ipc/compat.c
84250 +++ b/ipc/compat.c
84251 @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84252 COMPAT_SHMLBA);
84253 if (err < 0)
84254 return err;
84255 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84256 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84257 }
84258 case SHMDT:
84259 return sys_shmdt(compat_ptr(ptr));
84260 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84261 index 1702864..797fa84 100644
84262 --- a/ipc/ipc_sysctl.c
84263 +++ b/ipc/ipc_sysctl.c
84264 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84265 static int proc_ipc_dointvec(ctl_table *table, int write,
84266 void __user *buffer, size_t *lenp, loff_t *ppos)
84267 {
84268 - struct ctl_table ipc_table;
84269 + ctl_table_no_const ipc_table;
84270
84271 memcpy(&ipc_table, table, sizeof(ipc_table));
84272 ipc_table.data = get_ipc(table);
84273 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84274 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84275 void __user *buffer, size_t *lenp, loff_t *ppos)
84276 {
84277 - struct ctl_table ipc_table;
84278 + ctl_table_no_const ipc_table;
84279
84280 memcpy(&ipc_table, table, sizeof(ipc_table));
84281 ipc_table.data = get_ipc(table);
84282 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84283 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84284 void __user *buffer, size_t *lenp, loff_t *ppos)
84285 {
84286 - struct ctl_table ipc_table;
84287 + ctl_table_no_const ipc_table;
84288 size_t lenp_bef = *lenp;
84289 int rc;
84290
84291 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84292 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
84293 void __user *buffer, size_t *lenp, loff_t *ppos)
84294 {
84295 - struct ctl_table ipc_table;
84296 + ctl_table_no_const ipc_table;
84297 memcpy(&ipc_table, table, sizeof(ipc_table));
84298 ipc_table.data = get_ipc(table);
84299
84300 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84301 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
84302 void __user *buffer, size_t *lenp, loff_t *ppos)
84303 {
84304 - struct ctl_table ipc_table;
84305 + ctl_table_no_const ipc_table;
84306 size_t lenp_bef = *lenp;
84307 int oldval;
84308 int rc;
84309 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84310 index 5bb8bfe..a38ec05 100644
84311 --- a/ipc/mq_sysctl.c
84312 +++ b/ipc/mq_sysctl.c
84313 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84314 static int proc_mq_dointvec(ctl_table *table, int write,
84315 void __user *buffer, size_t *lenp, loff_t *ppos)
84316 {
84317 - struct ctl_table mq_table;
84318 + ctl_table_no_const mq_table;
84319 memcpy(&mq_table, table, sizeof(mq_table));
84320 mq_table.data = get_mq(table);
84321
84322 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
84323 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
84324 void __user *buffer, size_t *lenp, loff_t *ppos)
84325 {
84326 - struct ctl_table mq_table;
84327 + ctl_table_no_const mq_table;
84328 memcpy(&mq_table, table, sizeof(mq_table));
84329 mq_table.data = get_mq(table);
84330
84331 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
84332 index c3b3117..1efa933 100644
84333 --- a/ipc/mqueue.c
84334 +++ b/ipc/mqueue.c
84335 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
84336 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
84337 info->attr.mq_msgsize);
84338
84339 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
84340 spin_lock(&mq_lock);
84341 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
84342 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
84343 diff --git a/ipc/msg.c b/ipc/msg.c
84344 index 6498531..b0ff3c8 100644
84345 --- a/ipc/msg.c
84346 +++ b/ipc/msg.c
84347 @@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
84348 return security_msg_queue_associate(msq, msgflg);
84349 }
84350
84351 +static struct ipc_ops msg_ops = {
84352 + .getnew = newque,
84353 + .associate = msg_security,
84354 + .more_checks = NULL
84355 +};
84356 +
84357 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
84358 {
84359 struct ipc_namespace *ns;
84360 - struct ipc_ops msg_ops;
84361 struct ipc_params msg_params;
84362
84363 ns = current->nsproxy->ipc_ns;
84364
84365 - msg_ops.getnew = newque;
84366 - msg_ops.associate = msg_security;
84367 - msg_ops.more_checks = NULL;
84368 -
84369 msg_params.key = key;
84370 msg_params.flg = msgflg;
84371
84372 diff --git a/ipc/sem.c b/ipc/sem.c
84373 index bee5554..e9af81dd 100644
84374 --- a/ipc/sem.c
84375 +++ b/ipc/sem.c
84376 @@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
84377 return 0;
84378 }
84379
84380 +static struct ipc_ops sem_ops = {
84381 + .getnew = newary,
84382 + .associate = sem_security,
84383 + .more_checks = sem_more_checks
84384 +};
84385 +
84386 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84387 {
84388 struct ipc_namespace *ns;
84389 - struct ipc_ops sem_ops;
84390 struct ipc_params sem_params;
84391
84392 ns = current->nsproxy->ipc_ns;
84393 @@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84394 if (nsems < 0 || nsems > ns->sc_semmsl)
84395 return -EINVAL;
84396
84397 - sem_ops.getnew = newary;
84398 - sem_ops.associate = sem_security;
84399 - sem_ops.more_checks = sem_more_checks;
84400 -
84401 sem_params.key = key;
84402 sem_params.flg = semflg;
84403 sem_params.u.nsems = nsems;
84404 diff --git a/ipc/shm.c b/ipc/shm.c
84405 index 7645961..afc7f02 100644
84406 --- a/ipc/shm.c
84407 +++ b/ipc/shm.c
84408 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
84409 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
84410 #endif
84411
84412 +#ifdef CONFIG_GRKERNSEC
84413 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84414 + const time_t shm_createtime, const kuid_t cuid,
84415 + const int shmid);
84416 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84417 + const time_t shm_createtime);
84418 +#endif
84419 +
84420 void shm_init_ns(struct ipc_namespace *ns)
84421 {
84422 ns->shm_ctlmax = SHMMAX;
84423 @@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
84424 shp->shm_lprid = 0;
84425 shp->shm_atim = shp->shm_dtim = 0;
84426 shp->shm_ctim = get_seconds();
84427 +#ifdef CONFIG_GRKERNSEC
84428 + {
84429 + struct timespec timeval;
84430 + do_posix_clock_monotonic_gettime(&timeval);
84431 +
84432 + shp->shm_createtime = timeval.tv_sec;
84433 + }
84434 +#endif
84435 shp->shm_segsz = size;
84436 shp->shm_nattch = 0;
84437 shp->shm_file = file;
84438 @@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
84439 return 0;
84440 }
84441
84442 +static struct ipc_ops shm_ops = {
84443 + .getnew = newseg,
84444 + .associate = shm_security,
84445 + .more_checks = shm_more_checks
84446 +};
84447 +
84448 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
84449 {
84450 struct ipc_namespace *ns;
84451 - struct ipc_ops shm_ops;
84452 struct ipc_params shm_params;
84453
84454 ns = current->nsproxy->ipc_ns;
84455
84456 - shm_ops.getnew = newseg;
84457 - shm_ops.associate = shm_security;
84458 - shm_ops.more_checks = shm_more_checks;
84459 -
84460 shm_params.key = key;
84461 shm_params.flg = shmflg;
84462 shm_params.u.size = size;
84463 @@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84464 f_mode = FMODE_READ | FMODE_WRITE;
84465 }
84466 if (shmflg & SHM_EXEC) {
84467 +
84468 +#ifdef CONFIG_PAX_MPROTECT
84469 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
84470 + goto out;
84471 +#endif
84472 +
84473 prot |= PROT_EXEC;
84474 acc_mode |= S_IXUGO;
84475 }
84476 @@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84477 if (err)
84478 goto out_unlock;
84479
84480 +#ifdef CONFIG_GRKERNSEC
84481 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
84482 + shp->shm_perm.cuid, shmid) ||
84483 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
84484 + err = -EACCES;
84485 + goto out_unlock;
84486 + }
84487 +#endif
84488 +
84489 ipc_lock_object(&shp->shm_perm);
84490
84491 /* check if shm_destroy() is tearing down shp */
84492 @@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84493 path = shp->shm_file->f_path;
84494 path_get(&path);
84495 shp->shm_nattch++;
84496 +#ifdef CONFIG_GRKERNSEC
84497 + shp->shm_lapid = current->pid;
84498 +#endif
84499 size = i_size_read(path.dentry->d_inode);
84500 ipc_unlock_object(&shp->shm_perm);
84501 rcu_read_unlock();
84502 diff --git a/ipc/util.c b/ipc/util.c
84503 index e1b4c6d..8174204 100644
84504 --- a/ipc/util.c
84505 +++ b/ipc/util.c
84506 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
84507 int (*show)(struct seq_file *, void *);
84508 };
84509
84510 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
84511 +
84512 static void ipc_memory_notifier(struct work_struct *work)
84513 {
84514 ipcns_notify(IPCNS_MEMCHANGED);
84515 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
84516 granted_mode >>= 6;
84517 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
84518 granted_mode >>= 3;
84519 +
84520 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
84521 + return -1;
84522 +
84523 /* is there some bit set in requested_mode but not in granted_mode? */
84524 if ((requested_mode & ~granted_mode & 0007) &&
84525 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
84526 diff --git a/kernel/acct.c b/kernel/acct.c
84527 index 8d6e145..33e0b1e 100644
84528 --- a/kernel/acct.c
84529 +++ b/kernel/acct.c
84530 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
84531 */
84532 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
84533 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
84534 - file->f_op->write(file, (char *)&ac,
84535 + file->f_op->write(file, (char __force_user *)&ac,
84536 sizeof(acct_t), &file->f_pos);
84537 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
84538 set_fs(fs);
84539 diff --git a/kernel/audit.c b/kernel/audit.c
84540 index 95a20f3..e1cb300 100644
84541 --- a/kernel/audit.c
84542 +++ b/kernel/audit.c
84543 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
84544 3) suppressed due to audit_rate_limit
84545 4) suppressed due to audit_backlog_limit
84546 */
84547 -static atomic_t audit_lost = ATOMIC_INIT(0);
84548 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
84549
84550 /* The netlink socket. */
84551 static struct sock *audit_sock;
84552 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
84553 unsigned long now;
84554 int print;
84555
84556 - atomic_inc(&audit_lost);
84557 + atomic_inc_unchecked(&audit_lost);
84558
84559 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
84560
84561 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
84562 if (print) {
84563 if (printk_ratelimit())
84564 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
84565 - atomic_read(&audit_lost),
84566 + atomic_read_unchecked(&audit_lost),
84567 audit_rate_limit,
84568 audit_backlog_limit);
84569 audit_panic(message);
84570 @@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84571 s.pid = audit_pid;
84572 s.rate_limit = audit_rate_limit;
84573 s.backlog_limit = audit_backlog_limit;
84574 - s.lost = atomic_read(&audit_lost);
84575 + s.lost = atomic_read_unchecked(&audit_lost);
84576 s.backlog = skb_queue_len(&audit_skb_queue);
84577 s.version = AUDIT_VERSION_LATEST;
84578 s.backlog_wait_time = audit_backlog_wait_time;
84579 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
84580 index 7aef2f4..db6ced2 100644
84581 --- a/kernel/auditsc.c
84582 +++ b/kernel/auditsc.c
84583 @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
84584 }
84585
84586 /* global counter which is incremented every time something logs in */
84587 -static atomic_t session_id = ATOMIC_INIT(0);
84588 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
84589
84590 static int audit_set_loginuid_perm(kuid_t loginuid)
84591 {
84592 @@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
84593
84594 /* are we setting or clearing? */
84595 if (uid_valid(loginuid))
84596 - sessionid = (unsigned int)atomic_inc_return(&session_id);
84597 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
84598
84599 task->sessionid = sessionid;
84600 task->loginuid = loginuid;
84601 diff --git a/kernel/capability.c b/kernel/capability.c
84602 index 34019c5..363f279 100644
84603 --- a/kernel/capability.c
84604 +++ b/kernel/capability.c
84605 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
84606 * before modification is attempted and the application
84607 * fails.
84608 */
84609 + if (tocopy > ARRAY_SIZE(kdata))
84610 + return -EFAULT;
84611 +
84612 if (copy_to_user(dataptr, kdata, tocopy
84613 * sizeof(struct __user_cap_data_struct))) {
84614 return -EFAULT;
84615 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
84616 int ret;
84617
84618 rcu_read_lock();
84619 - ret = security_capable(__task_cred(t), ns, cap);
84620 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
84621 + gr_task_is_capable(t, __task_cred(t), cap);
84622 rcu_read_unlock();
84623
84624 - return (ret == 0);
84625 + return ret;
84626 }
84627
84628 /**
84629 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
84630 int ret;
84631
84632 rcu_read_lock();
84633 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
84634 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
84635 rcu_read_unlock();
84636
84637 - return (ret == 0);
84638 + return ret;
84639 }
84640
84641 /**
84642 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
84643 BUG();
84644 }
84645
84646 - if (security_capable(current_cred(), ns, cap) == 0) {
84647 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
84648 current->flags |= PF_SUPERPRIV;
84649 return true;
84650 }
84651 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
84652 }
84653 EXPORT_SYMBOL(ns_capable);
84654
84655 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
84656 +{
84657 + if (unlikely(!cap_valid(cap))) {
84658 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
84659 + BUG();
84660 + }
84661 +
84662 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
84663 + current->flags |= PF_SUPERPRIV;
84664 + return true;
84665 + }
84666 + return false;
84667 +}
84668 +EXPORT_SYMBOL(ns_capable_nolog);
84669 +
84670 /**
84671 * file_ns_capable - Determine if the file's opener had a capability in effect
84672 * @file: The file we want to check
84673 @@ -432,6 +451,12 @@ bool capable(int cap)
84674 }
84675 EXPORT_SYMBOL(capable);
84676
84677 +bool capable_nolog(int cap)
84678 +{
84679 + return ns_capable_nolog(&init_user_ns, cap);
84680 +}
84681 +EXPORT_SYMBOL(capable_nolog);
84682 +
84683 /**
84684 * inode_capable - Check superior capability over inode
84685 * @inode: The inode in question
84686 @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
84687 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84688 }
84689 EXPORT_SYMBOL(inode_capable);
84690 +
84691 +bool inode_capable_nolog(const struct inode *inode, int cap)
84692 +{
84693 + struct user_namespace *ns = current_user_ns();
84694 +
84695 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84696 +}
84697 +EXPORT_SYMBOL(inode_capable_nolog);
84698 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
84699 index 0c753dd..dd7d3d6 100644
84700 --- a/kernel/cgroup.c
84701 +++ b/kernel/cgroup.c
84702 @@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
84703 struct css_set *cset = link->cset;
84704 struct task_struct *task;
84705 int count = 0;
84706 - seq_printf(seq, "css_set %p\n", cset);
84707 + seq_printf(seq, "css_set %pK\n", cset);
84708 list_for_each_entry(task, &cset->tasks, cg_list) {
84709 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
84710 seq_puts(seq, " ...\n");
84711 diff --git a/kernel/compat.c b/kernel/compat.c
84712 index 0a09e48..b46b3d78 100644
84713 --- a/kernel/compat.c
84714 +++ b/kernel/compat.c
84715 @@ -13,6 +13,7 @@
84716
84717 #include <linux/linkage.h>
84718 #include <linux/compat.h>
84719 +#include <linux/module.h>
84720 #include <linux/errno.h>
84721 #include <linux/time.h>
84722 #include <linux/signal.h>
84723 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
84724 mm_segment_t oldfs;
84725 long ret;
84726
84727 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
84728 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
84729 oldfs = get_fs();
84730 set_fs(KERNEL_DS);
84731 ret = hrtimer_nanosleep_restart(restart);
84732 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
84733 oldfs = get_fs();
84734 set_fs(KERNEL_DS);
84735 ret = hrtimer_nanosleep(&tu,
84736 - rmtp ? (struct timespec __user *)&rmt : NULL,
84737 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
84738 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
84739 set_fs(oldfs);
84740
84741 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
84742 mm_segment_t old_fs = get_fs();
84743
84744 set_fs(KERNEL_DS);
84745 - ret = sys_sigpending((old_sigset_t __user *) &s);
84746 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
84747 set_fs(old_fs);
84748 if (ret == 0)
84749 ret = put_user(s, set);
84750 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
84751 mm_segment_t old_fs = get_fs();
84752
84753 set_fs(KERNEL_DS);
84754 - ret = sys_old_getrlimit(resource, &r);
84755 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
84756 set_fs(old_fs);
84757
84758 if (!ret) {
84759 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
84760 set_fs (KERNEL_DS);
84761 ret = sys_wait4(pid,
84762 (stat_addr ?
84763 - (unsigned int __user *) &status : NULL),
84764 - options, (struct rusage __user *) &r);
84765 + (unsigned int __force_user *) &status : NULL),
84766 + options, (struct rusage __force_user *) &r);
84767 set_fs (old_fs);
84768
84769 if (ret > 0) {
84770 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
84771 memset(&info, 0, sizeof(info));
84772
84773 set_fs(KERNEL_DS);
84774 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
84775 - uru ? (struct rusage __user *)&ru : NULL);
84776 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
84777 + uru ? (struct rusage __force_user *)&ru : NULL);
84778 set_fs(old_fs);
84779
84780 if ((ret < 0) || (info.si_signo == 0))
84781 @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
84782 oldfs = get_fs();
84783 set_fs(KERNEL_DS);
84784 err = sys_timer_settime(timer_id, flags,
84785 - (struct itimerspec __user *) &newts,
84786 - (struct itimerspec __user *) &oldts);
84787 + (struct itimerspec __force_user *) &newts,
84788 + (struct itimerspec __force_user *) &oldts);
84789 set_fs(oldfs);
84790 if (!err && old && put_compat_itimerspec(old, &oldts))
84791 return -EFAULT;
84792 @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
84793 oldfs = get_fs();
84794 set_fs(KERNEL_DS);
84795 err = sys_timer_gettime(timer_id,
84796 - (struct itimerspec __user *) &ts);
84797 + (struct itimerspec __force_user *) &ts);
84798 set_fs(oldfs);
84799 if (!err && put_compat_itimerspec(setting, &ts))
84800 return -EFAULT;
84801 @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
84802 oldfs = get_fs();
84803 set_fs(KERNEL_DS);
84804 err = sys_clock_settime(which_clock,
84805 - (struct timespec __user *) &ts);
84806 + (struct timespec __force_user *) &ts);
84807 set_fs(oldfs);
84808 return err;
84809 }
84810 @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
84811 oldfs = get_fs();
84812 set_fs(KERNEL_DS);
84813 err = sys_clock_gettime(which_clock,
84814 - (struct timespec __user *) &ts);
84815 + (struct timespec __force_user *) &ts);
84816 set_fs(oldfs);
84817 if (!err && put_compat_timespec(&ts, tp))
84818 return -EFAULT;
84819 @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
84820
84821 oldfs = get_fs();
84822 set_fs(KERNEL_DS);
84823 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
84824 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
84825 set_fs(oldfs);
84826
84827 err = compat_put_timex(utp, &txc);
84828 @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
84829 oldfs = get_fs();
84830 set_fs(KERNEL_DS);
84831 err = sys_clock_getres(which_clock,
84832 - (struct timespec __user *) &ts);
84833 + (struct timespec __force_user *) &ts);
84834 set_fs(oldfs);
84835 if (!err && tp && put_compat_timespec(&ts, tp))
84836 return -EFAULT;
84837 @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
84838 long err;
84839 mm_segment_t oldfs;
84840 struct timespec tu;
84841 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
84842 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
84843
84844 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
84845 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
84846 oldfs = get_fs();
84847 set_fs(KERNEL_DS);
84848 err = clock_nanosleep_restart(restart);
84849 @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
84850 oldfs = get_fs();
84851 set_fs(KERNEL_DS);
84852 err = sys_clock_nanosleep(which_clock, flags,
84853 - (struct timespec __user *) &in,
84854 - (struct timespec __user *) &out);
84855 + (struct timespec __force_user *) &in,
84856 + (struct timespec __force_user *) &out);
84857 set_fs(oldfs);
84858
84859 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
84860 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
84861 mm_segment_t old_fs = get_fs();
84862
84863 set_fs(KERNEL_DS);
84864 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
84865 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
84866 set_fs(old_fs);
84867 if (put_compat_timespec(&t, interval))
84868 return -EFAULT;
84869 diff --git a/kernel/configs.c b/kernel/configs.c
84870 index c18b1f1..b9a0132 100644
84871 --- a/kernel/configs.c
84872 +++ b/kernel/configs.c
84873 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
84874 struct proc_dir_entry *entry;
84875
84876 /* create the current config file */
84877 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
84878 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
84879 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
84880 + &ikconfig_file_ops);
84881 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84882 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
84883 + &ikconfig_file_ops);
84884 +#endif
84885 +#else
84886 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
84887 &ikconfig_file_ops);
84888 +#endif
84889 +
84890 if (!entry)
84891 return -ENOMEM;
84892
84893 diff --git a/kernel/cred.c b/kernel/cred.c
84894 index e0573a4..3874e41 100644
84895 --- a/kernel/cred.c
84896 +++ b/kernel/cred.c
84897 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
84898 validate_creds(cred);
84899 alter_cred_subscribers(cred, -1);
84900 put_cred(cred);
84901 +
84902 +#ifdef CONFIG_GRKERNSEC_SETXID
84903 + cred = (struct cred *) tsk->delayed_cred;
84904 + if (cred != NULL) {
84905 + tsk->delayed_cred = NULL;
84906 + validate_creds(cred);
84907 + alter_cred_subscribers(cred, -1);
84908 + put_cred(cred);
84909 + }
84910 +#endif
84911 }
84912
84913 /**
84914 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
84915 * Always returns 0 thus allowing this function to be tail-called at the end
84916 * of, say, sys_setgid().
84917 */
84918 -int commit_creds(struct cred *new)
84919 +static int __commit_creds(struct cred *new)
84920 {
84921 struct task_struct *task = current;
84922 const struct cred *old = task->real_cred;
84923 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
84924
84925 get_cred(new); /* we will require a ref for the subj creds too */
84926
84927 + gr_set_role_label(task, new->uid, new->gid);
84928 +
84929 /* dumpability changes */
84930 if (!uid_eq(old->euid, new->euid) ||
84931 !gid_eq(old->egid, new->egid) ||
84932 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
84933 put_cred(old);
84934 return 0;
84935 }
84936 +#ifdef CONFIG_GRKERNSEC_SETXID
84937 +extern int set_user(struct cred *new);
84938 +
84939 +void gr_delayed_cred_worker(void)
84940 +{
84941 + const struct cred *new = current->delayed_cred;
84942 + struct cred *ncred;
84943 +
84944 + current->delayed_cred = NULL;
84945 +
84946 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
84947 + // from doing get_cred on it when queueing this
84948 + put_cred(new);
84949 + return;
84950 + } else if (new == NULL)
84951 + return;
84952 +
84953 + ncred = prepare_creds();
84954 + if (!ncred)
84955 + goto die;
84956 + // uids
84957 + ncred->uid = new->uid;
84958 + ncred->euid = new->euid;
84959 + ncred->suid = new->suid;
84960 + ncred->fsuid = new->fsuid;
84961 + // gids
84962 + ncred->gid = new->gid;
84963 + ncred->egid = new->egid;
84964 + ncred->sgid = new->sgid;
84965 + ncred->fsgid = new->fsgid;
84966 + // groups
84967 + if (set_groups(ncred, new->group_info) < 0) {
84968 + abort_creds(ncred);
84969 + goto die;
84970 + }
84971 + // caps
84972 + ncred->securebits = new->securebits;
84973 + ncred->cap_inheritable = new->cap_inheritable;
84974 + ncred->cap_permitted = new->cap_permitted;
84975 + ncred->cap_effective = new->cap_effective;
84976 + ncred->cap_bset = new->cap_bset;
84977 +
84978 + if (set_user(ncred)) {
84979 + abort_creds(ncred);
84980 + goto die;
84981 + }
84982 +
84983 + // from doing get_cred on it when queueing this
84984 + put_cred(new);
84985 +
84986 + __commit_creds(ncred);
84987 + return;
84988 +die:
84989 + // from doing get_cred on it when queueing this
84990 + put_cred(new);
84991 + do_group_exit(SIGKILL);
84992 +}
84993 +#endif
84994 +
84995 +int commit_creds(struct cred *new)
84996 +{
84997 +#ifdef CONFIG_GRKERNSEC_SETXID
84998 + int ret;
84999 + int schedule_it = 0;
85000 + struct task_struct *t;
85001 +
85002 + /* we won't get called with tasklist_lock held for writing
85003 + and interrupts disabled as the cred struct in that case is
85004 + init_cred
85005 + */
85006 + if (grsec_enable_setxid && !current_is_single_threaded() &&
85007 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85008 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85009 + schedule_it = 1;
85010 + }
85011 + ret = __commit_creds(new);
85012 + if (schedule_it) {
85013 + rcu_read_lock();
85014 + read_lock(&tasklist_lock);
85015 + for (t = next_thread(current); t != current;
85016 + t = next_thread(t)) {
85017 + if (t->delayed_cred == NULL) {
85018 + t->delayed_cred = get_cred(new);
85019 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85020 + set_tsk_need_resched(t);
85021 + }
85022 + }
85023 + read_unlock(&tasklist_lock);
85024 + rcu_read_unlock();
85025 + }
85026 + return ret;
85027 +#else
85028 + return __commit_creds(new);
85029 +#endif
85030 +}
85031 +
85032 EXPORT_SYMBOL(commit_creds);
85033
85034 /**
85035 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85036 index 334b398..9145fb1 100644
85037 --- a/kernel/debug/debug_core.c
85038 +++ b/kernel/debug/debug_core.c
85039 @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85040 */
85041 static atomic_t masters_in_kgdb;
85042 static atomic_t slaves_in_kgdb;
85043 -static atomic_t kgdb_break_tasklet_var;
85044 +static atomic_unchecked_t kgdb_break_tasklet_var;
85045 atomic_t kgdb_setting_breakpoint;
85046
85047 struct task_struct *kgdb_usethread;
85048 @@ -133,7 +133,7 @@ int kgdb_single_step;
85049 static pid_t kgdb_sstep_pid;
85050
85051 /* to keep track of the CPU which is doing the single stepping*/
85052 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85053 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85054
85055 /*
85056 * If you are debugging a problem where roundup (the collection of
85057 @@ -541,7 +541,7 @@ return_normal:
85058 * kernel will only try for the value of sstep_tries before
85059 * giving up and continuing on.
85060 */
85061 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85062 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85063 (kgdb_info[cpu].task &&
85064 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85065 atomic_set(&kgdb_active, -1);
85066 @@ -639,8 +639,8 @@ cpu_master_loop:
85067 }
85068
85069 kgdb_restore:
85070 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85071 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85072 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85073 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85074 if (kgdb_info[sstep_cpu].task)
85075 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85076 else
85077 @@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
85078 static void kgdb_tasklet_bpt(unsigned long ing)
85079 {
85080 kgdb_breakpoint();
85081 - atomic_set(&kgdb_break_tasklet_var, 0);
85082 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85083 }
85084
85085 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85086
85087 void kgdb_schedule_breakpoint(void)
85088 {
85089 - if (atomic_read(&kgdb_break_tasklet_var) ||
85090 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85091 atomic_read(&kgdb_active) != -1 ||
85092 atomic_read(&kgdb_setting_breakpoint))
85093 return;
85094 - atomic_inc(&kgdb_break_tasklet_var);
85095 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
85096 tasklet_schedule(&kgdb_tasklet_breakpoint);
85097 }
85098 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85099 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85100 index 0b097c8..11dd5c5 100644
85101 --- a/kernel/debug/kdb/kdb_main.c
85102 +++ b/kernel/debug/kdb/kdb_main.c
85103 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85104 continue;
85105
85106 kdb_printf("%-20s%8u 0x%p ", mod->name,
85107 - mod->core_size, (void *)mod);
85108 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
85109 #ifdef CONFIG_MODULE_UNLOAD
85110 kdb_printf("%4ld ", module_refcount(mod));
85111 #endif
85112 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85113 kdb_printf(" (Loading)");
85114 else
85115 kdb_printf(" (Live)");
85116 - kdb_printf(" 0x%p", mod->module_core);
85117 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85118
85119 #ifdef CONFIG_MODULE_UNLOAD
85120 {
85121 diff --git a/kernel/events/core.c b/kernel/events/core.c
85122 index fa0b2d4..67a1c7a 100644
85123 --- a/kernel/events/core.c
85124 +++ b/kernel/events/core.c
85125 @@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
85126 * 0 - disallow raw tracepoint access for unpriv
85127 * 1 - disallow cpu events for unpriv
85128 * 2 - disallow kernel profiling for unpriv
85129 + * 3 - disallow all unpriv perf event use
85130 */
85131 -int sysctl_perf_event_paranoid __read_mostly = 1;
85132 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85133 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85134 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85135 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85136 +#else
85137 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85138 +#endif
85139
85140 /* Minimum for 512 kiB + 1 user control page */
85141 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85142 @@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
85143
85144 tmp *= sysctl_perf_cpu_time_max_percent;
85145 do_div(tmp, 100);
85146 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85147 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85148 }
85149
85150 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85151 @@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85152 update_perf_cpu_limits();
85153 }
85154
85155 -static atomic64_t perf_event_id;
85156 +static atomic64_unchecked_t perf_event_id;
85157
85158 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85159 enum event_type_t event_type);
85160 @@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
85161
85162 static inline u64 perf_event_count(struct perf_event *event)
85163 {
85164 - return local64_read(&event->count) + atomic64_read(&event->child_count);
85165 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85166 }
85167
85168 static u64 perf_event_read(struct perf_event *event)
85169 @@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85170 mutex_lock(&event->child_mutex);
85171 total += perf_event_read(event);
85172 *enabled += event->total_time_enabled +
85173 - atomic64_read(&event->child_total_time_enabled);
85174 + atomic64_read_unchecked(&event->child_total_time_enabled);
85175 *running += event->total_time_running +
85176 - atomic64_read(&event->child_total_time_running);
85177 + atomic64_read_unchecked(&event->child_total_time_running);
85178
85179 list_for_each_entry(child, &event->child_list, child_list) {
85180 total += perf_event_read(child);
85181 @@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
85182 userpg->offset -= local64_read(&event->hw.prev_count);
85183
85184 userpg->time_enabled = enabled +
85185 - atomic64_read(&event->child_total_time_enabled);
85186 + atomic64_read_unchecked(&event->child_total_time_enabled);
85187
85188 userpg->time_running = running +
85189 - atomic64_read(&event->child_total_time_running);
85190 + atomic64_read_unchecked(&event->child_total_time_running);
85191
85192 arch_perf_update_userpage(userpg, now);
85193
85194 @@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85195
85196 /* Data. */
85197 sp = perf_user_stack_pointer(regs);
85198 - rem = __output_copy_user(handle, (void *) sp, dump_size);
85199 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85200 dyn_size = dump_size - rem;
85201
85202 perf_output_skip(handle, rem);
85203 @@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85204 values[n++] = perf_event_count(event);
85205 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85206 values[n++] = enabled +
85207 - atomic64_read(&event->child_total_time_enabled);
85208 + atomic64_read_unchecked(&event->child_total_time_enabled);
85209 }
85210 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85211 values[n++] = running +
85212 - atomic64_read(&event->child_total_time_running);
85213 + atomic64_read_unchecked(&event->child_total_time_running);
85214 }
85215 if (read_format & PERF_FORMAT_ID)
85216 values[n++] = primary_event_id(event);
85217 @@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85218 event->parent = parent_event;
85219
85220 event->ns = get_pid_ns(task_active_pid_ns(current));
85221 - event->id = atomic64_inc_return(&perf_event_id);
85222 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
85223
85224 event->state = PERF_EVENT_STATE_INACTIVE;
85225
85226 @@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
85227 if (flags & ~PERF_FLAG_ALL)
85228 return -EINVAL;
85229
85230 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85231 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85232 + return -EACCES;
85233 +#endif
85234 +
85235 err = perf_copy_attr(attr_uptr, &attr);
85236 if (err)
85237 return err;
85238 @@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
85239 /*
85240 * Add back the child's count to the parent's count:
85241 */
85242 - atomic64_add(child_val, &parent_event->child_count);
85243 - atomic64_add(child_event->total_time_enabled,
85244 + atomic64_add_unchecked(child_val, &parent_event->child_count);
85245 + atomic64_add_unchecked(child_event->total_time_enabled,
85246 &parent_event->child_total_time_enabled);
85247 - atomic64_add(child_event->total_time_running,
85248 + atomic64_add_unchecked(child_event->total_time_running,
85249 &parent_event->child_total_time_running);
85250
85251 /*
85252 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85253 index 569b2187..19940d9 100644
85254 --- a/kernel/events/internal.h
85255 +++ b/kernel/events/internal.h
85256 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85257 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85258 }
85259
85260 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85261 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85262 static inline unsigned long \
85263 func_name(struct perf_output_handle *handle, \
85264 - const void *buf, unsigned long len) \
85265 + const void user *buf, unsigned long len) \
85266 { \
85267 unsigned long size, written; \
85268 \
85269 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85270 return 0;
85271 }
85272
85273 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85274 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85275
85276 static inline unsigned long
85277 memcpy_skip(void *dst, const void *src, unsigned long n)
85278 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85279 return 0;
85280 }
85281
85282 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85283 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85284
85285 #ifndef arch_perf_out_copy_user
85286 #define arch_perf_out_copy_user arch_perf_out_copy_user
85287 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85288 }
85289 #endif
85290
85291 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85292 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85293
85294 /* Callchain handling */
85295 extern struct perf_callchain_entry *
85296 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85297 index 307d87c..6466cbe 100644
85298 --- a/kernel/events/uprobes.c
85299 +++ b/kernel/events/uprobes.c
85300 @@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85301 {
85302 struct page *page;
85303 uprobe_opcode_t opcode;
85304 - int result;
85305 + long result;
85306
85307 pagefault_disable();
85308 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85309 diff --git a/kernel/exit.c b/kernel/exit.c
85310 index 1e77fc6..6fd7391 100644
85311 --- a/kernel/exit.c
85312 +++ b/kernel/exit.c
85313 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
85314 struct task_struct *leader;
85315 int zap_leader;
85316 repeat:
85317 +#ifdef CONFIG_NET
85318 + gr_del_task_from_ip_table(p);
85319 +#endif
85320 +
85321 /* don't need to get the RCU readlock here - the process is dead and
85322 * can't be modifying its own credentials. But shut RCU-lockdep up */
85323 rcu_read_lock();
85324 @@ -330,7 +334,7 @@ int allow_signal(int sig)
85325 * know it'll be handled, so that they don't get converted to
85326 * SIGKILL or just silently dropped.
85327 */
85328 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
85329 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
85330 recalc_sigpending();
85331 spin_unlock_irq(&current->sighand->siglock);
85332 return 0;
85333 @@ -699,6 +703,8 @@ void do_exit(long code)
85334 struct task_struct *tsk = current;
85335 int group_dead;
85336
85337 + set_fs(USER_DS);
85338 +
85339 profile_task_exit(tsk);
85340
85341 WARN_ON(blk_needs_flush_plug(tsk));
85342 @@ -715,7 +721,6 @@ void do_exit(long code)
85343 * mm_release()->clear_child_tid() from writing to a user-controlled
85344 * kernel address.
85345 */
85346 - set_fs(USER_DS);
85347
85348 ptrace_event(PTRACE_EVENT_EXIT, code);
85349
85350 @@ -774,6 +779,9 @@ void do_exit(long code)
85351 tsk->exit_code = code;
85352 taskstats_exit(tsk, group_dead);
85353
85354 + gr_acl_handle_psacct(tsk, code);
85355 + gr_acl_handle_exit();
85356 +
85357 exit_mm(tsk);
85358
85359 if (group_dead)
85360 @@ -895,7 +903,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
85361 * Take down every thread in the group. This is called by fatal signals
85362 * as well as by sys_exit_group (below).
85363 */
85364 -void
85365 +__noreturn void
85366 do_group_exit(int exit_code)
85367 {
85368 struct signal_struct *sig = current->signal;
85369 diff --git a/kernel/fork.c b/kernel/fork.c
85370 index a17621c..b77fef8 100644
85371 --- a/kernel/fork.c
85372 +++ b/kernel/fork.c
85373 @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
85374 *stackend = STACK_END_MAGIC; /* for overflow detection */
85375
85376 #ifdef CONFIG_CC_STACKPROTECTOR
85377 - tsk->stack_canary = get_random_int();
85378 + tsk->stack_canary = pax_get_random_long();
85379 #endif
85380
85381 /*
85382 @@ -345,12 +345,80 @@ free_tsk:
85383 }
85384
85385 #ifdef CONFIG_MMU
85386 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85387 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
85388 +{
85389 + struct vm_area_struct *tmp;
85390 + unsigned long charge;
85391 + struct file *file;
85392 + int retval;
85393 +
85394 + charge = 0;
85395 + if (mpnt->vm_flags & VM_ACCOUNT) {
85396 + unsigned long len = vma_pages(mpnt);
85397 +
85398 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85399 + goto fail_nomem;
85400 + charge = len;
85401 + }
85402 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85403 + if (!tmp)
85404 + goto fail_nomem;
85405 + *tmp = *mpnt;
85406 + tmp->vm_mm = mm;
85407 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
85408 + retval = vma_dup_policy(mpnt, tmp);
85409 + if (retval)
85410 + goto fail_nomem_policy;
85411 + if (anon_vma_fork(tmp, mpnt))
85412 + goto fail_nomem_anon_vma_fork;
85413 + tmp->vm_flags &= ~VM_LOCKED;
85414 + tmp->vm_next = tmp->vm_prev = NULL;
85415 + tmp->vm_mirror = NULL;
85416 + file = tmp->vm_file;
85417 + if (file) {
85418 + struct inode *inode = file_inode(file);
85419 + struct address_space *mapping = file->f_mapping;
85420 +
85421 + get_file(file);
85422 + if (tmp->vm_flags & VM_DENYWRITE)
85423 + atomic_dec(&inode->i_writecount);
85424 + mutex_lock(&mapping->i_mmap_mutex);
85425 + if (tmp->vm_flags & VM_SHARED)
85426 + mapping->i_mmap_writable++;
85427 + flush_dcache_mmap_lock(mapping);
85428 + /* insert tmp into the share list, just after mpnt */
85429 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85430 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
85431 + else
85432 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
85433 + flush_dcache_mmap_unlock(mapping);
85434 + mutex_unlock(&mapping->i_mmap_mutex);
85435 + }
85436 +
85437 + /*
85438 + * Clear hugetlb-related page reserves for children. This only
85439 + * affects MAP_PRIVATE mappings. Faults generated by the child
85440 + * are not guaranteed to succeed, even if read-only
85441 + */
85442 + if (is_vm_hugetlb_page(tmp))
85443 + reset_vma_resv_huge_pages(tmp);
85444 +
85445 + return tmp;
85446 +
85447 +fail_nomem_anon_vma_fork:
85448 + mpol_put(vma_policy(tmp));
85449 +fail_nomem_policy:
85450 + kmem_cache_free(vm_area_cachep, tmp);
85451 +fail_nomem:
85452 + vm_unacct_memory(charge);
85453 + return NULL;
85454 +}
85455 +
85456 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85457 {
85458 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
85459 struct rb_node **rb_link, *rb_parent;
85460 int retval;
85461 - unsigned long charge;
85462
85463 uprobe_start_dup_mmap();
85464 down_write(&oldmm->mmap_sem);
85465 @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85466
85467 prev = NULL;
85468 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
85469 - struct file *file;
85470 -
85471 if (mpnt->vm_flags & VM_DONTCOPY) {
85472 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
85473 -vma_pages(mpnt));
85474 continue;
85475 }
85476 - charge = 0;
85477 - if (mpnt->vm_flags & VM_ACCOUNT) {
85478 - unsigned long len = vma_pages(mpnt);
85479 -
85480 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85481 - goto fail_nomem;
85482 - charge = len;
85483 - }
85484 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85485 - if (!tmp)
85486 - goto fail_nomem;
85487 - *tmp = *mpnt;
85488 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
85489 - retval = vma_dup_policy(mpnt, tmp);
85490 - if (retval)
85491 - goto fail_nomem_policy;
85492 - tmp->vm_mm = mm;
85493 - if (anon_vma_fork(tmp, mpnt))
85494 - goto fail_nomem_anon_vma_fork;
85495 - tmp->vm_flags &= ~VM_LOCKED;
85496 - tmp->vm_next = tmp->vm_prev = NULL;
85497 - file = tmp->vm_file;
85498 - if (file) {
85499 - struct inode *inode = file_inode(file);
85500 - struct address_space *mapping = file->f_mapping;
85501 -
85502 - get_file(file);
85503 - if (tmp->vm_flags & VM_DENYWRITE)
85504 - atomic_dec(&inode->i_writecount);
85505 - mutex_lock(&mapping->i_mmap_mutex);
85506 - if (tmp->vm_flags & VM_SHARED)
85507 - mapping->i_mmap_writable++;
85508 - flush_dcache_mmap_lock(mapping);
85509 - /* insert tmp into the share list, just after mpnt */
85510 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85511 - vma_nonlinear_insert(tmp,
85512 - &mapping->i_mmap_nonlinear);
85513 - else
85514 - vma_interval_tree_insert_after(tmp, mpnt,
85515 - &mapping->i_mmap);
85516 - flush_dcache_mmap_unlock(mapping);
85517 - mutex_unlock(&mapping->i_mmap_mutex);
85518 + tmp = dup_vma(mm, oldmm, mpnt);
85519 + if (!tmp) {
85520 + retval = -ENOMEM;
85521 + goto out;
85522 }
85523
85524 /*
85525 @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85526 if (retval)
85527 goto out;
85528 }
85529 +
85530 +#ifdef CONFIG_PAX_SEGMEXEC
85531 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
85532 + struct vm_area_struct *mpnt_m;
85533 +
85534 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
85535 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
85536 +
85537 + if (!mpnt->vm_mirror)
85538 + continue;
85539 +
85540 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
85541 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
85542 + mpnt->vm_mirror = mpnt_m;
85543 + } else {
85544 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
85545 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
85546 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
85547 + mpnt->vm_mirror->vm_mirror = mpnt;
85548 + }
85549 + }
85550 + BUG_ON(mpnt_m);
85551 + }
85552 +#endif
85553 +
85554 /* a new mm has just been created */
85555 arch_dup_mmap(oldmm, mm);
85556 retval = 0;
85557 @@ -468,14 +521,6 @@ out:
85558 up_write(&oldmm->mmap_sem);
85559 uprobe_end_dup_mmap();
85560 return retval;
85561 -fail_nomem_anon_vma_fork:
85562 - mpol_put(vma_policy(tmp));
85563 -fail_nomem_policy:
85564 - kmem_cache_free(vm_area_cachep, tmp);
85565 -fail_nomem:
85566 - retval = -ENOMEM;
85567 - vm_unacct_memory(charge);
85568 - goto out;
85569 }
85570
85571 static inline int mm_alloc_pgd(struct mm_struct *mm)
85572 @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
85573 return ERR_PTR(err);
85574
85575 mm = get_task_mm(task);
85576 - if (mm && mm != current->mm &&
85577 - !ptrace_may_access(task, mode)) {
85578 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
85579 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
85580 mmput(mm);
85581 mm = ERR_PTR(-EACCES);
85582 }
85583 @@ -906,13 +951,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
85584 spin_unlock(&fs->lock);
85585 return -EAGAIN;
85586 }
85587 - fs->users++;
85588 + atomic_inc(&fs->users);
85589 spin_unlock(&fs->lock);
85590 return 0;
85591 }
85592 tsk->fs = copy_fs_struct(fs);
85593 if (!tsk->fs)
85594 return -ENOMEM;
85595 + /* Carry through gr_chroot_dentry and is_chrooted instead
85596 + of recomputing it here. Already copied when the task struct
85597 + is duplicated. This allows pivot_root to not be treated as
85598 + a chroot
85599 + */
85600 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
85601 +
85602 return 0;
85603 }
85604
85605 @@ -1130,7 +1182,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
85606 * parts of the process environment (as per the clone
85607 * flags). The actual kick-off is left to the caller.
85608 */
85609 -static struct task_struct *copy_process(unsigned long clone_flags,
85610 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
85611 unsigned long stack_start,
85612 unsigned long stack_size,
85613 int __user *child_tidptr,
85614 @@ -1202,6 +1254,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85615 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
85616 #endif
85617 retval = -EAGAIN;
85618 +
85619 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
85620 +
85621 if (atomic_read(&p->real_cred->user->processes) >=
85622 task_rlimit(p, RLIMIT_NPROC)) {
85623 if (p->real_cred->user != INIT_USER &&
85624 @@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85625 goto bad_fork_free_pid;
85626 }
85627
85628 + /* synchronizes with gr_set_acls()
85629 + we need to call this past the point of no return for fork()
85630 + */
85631 + gr_copy_label(p);
85632 +
85633 if (likely(p->pid)) {
85634 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
85635
85636 @@ -1537,6 +1597,8 @@ bad_fork_cleanup_count:
85637 bad_fork_free:
85638 free_task(p);
85639 fork_out:
85640 + gr_log_forkfail(retval);
85641 +
85642 return ERR_PTR(retval);
85643 }
85644
85645 @@ -1598,6 +1660,7 @@ long do_fork(unsigned long clone_flags,
85646
85647 p = copy_process(clone_flags, stack_start, stack_size,
85648 child_tidptr, NULL, trace);
85649 + add_latent_entropy();
85650 /*
85651 * Do this prior waking up the new thread - the thread pointer
85652 * might get invalid after that point, if the thread exits quickly.
85653 @@ -1612,6 +1675,8 @@ long do_fork(unsigned long clone_flags,
85654 if (clone_flags & CLONE_PARENT_SETTID)
85655 put_user(nr, parent_tidptr);
85656
85657 + gr_handle_brute_check();
85658 +
85659 if (clone_flags & CLONE_VFORK) {
85660 p->vfork_done = &vfork;
85661 init_completion(&vfork);
85662 @@ -1728,7 +1793,7 @@ void __init proc_caches_init(void)
85663 mm_cachep = kmem_cache_create("mm_struct",
85664 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
85665 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
85666 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
85667 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
85668 mmap_init();
85669 nsproxy_cache_init();
85670 }
85671 @@ -1768,7 +1833,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
85672 return 0;
85673
85674 /* don't need lock here; in the worst case we'll do useless copy */
85675 - if (fs->users == 1)
85676 + if (atomic_read(&fs->users) == 1)
85677 return 0;
85678
85679 *new_fsp = copy_fs_struct(fs);
85680 @@ -1875,7 +1940,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
85681 fs = current->fs;
85682 spin_lock(&fs->lock);
85683 current->fs = new_fs;
85684 - if (--fs->users)
85685 + gr_set_chroot_entries(current, &current->fs->root);
85686 + if (atomic_dec_return(&fs->users))
85687 new_fs = NULL;
85688 else
85689 new_fs = fs;
85690 diff --git a/kernel/futex.c b/kernel/futex.c
85691 index 6801b37..bb6becca 100644
85692 --- a/kernel/futex.c
85693 +++ b/kernel/futex.c
85694 @@ -54,6 +54,7 @@
85695 #include <linux/mount.h>
85696 #include <linux/pagemap.h>
85697 #include <linux/syscalls.h>
85698 +#include <linux/ptrace.h>
85699 #include <linux/signal.h>
85700 #include <linux/export.h>
85701 #include <linux/magic.h>
85702 @@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
85703 struct page *page, *page_head;
85704 int err, ro = 0;
85705
85706 +#ifdef CONFIG_PAX_SEGMEXEC
85707 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
85708 + return -EFAULT;
85709 +#endif
85710 +
85711 /*
85712 * The futex address must be "naturally" aligned.
85713 */
85714 @@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
85715
85716 static int get_futex_value_locked(u32 *dest, u32 __user *from)
85717 {
85718 - int ret;
85719 + unsigned long ret;
85720
85721 pagefault_disable();
85722 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
85723 @@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
85724 {
85725 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
85726 u32 curval;
85727 + mm_segment_t oldfs;
85728
85729 /*
85730 * This will fail and we want it. Some arch implementations do
85731 @@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
85732 * implementation, the non-functional ones will return
85733 * -ENOSYS.
85734 */
85735 + oldfs = get_fs();
85736 + set_fs(USER_DS);
85737 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
85738 futex_cmpxchg_enabled = 1;
85739 + set_fs(oldfs);
85740 #endif
85741 }
85742
85743 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
85744 index f9f44fd..29885e4 100644
85745 --- a/kernel/futex_compat.c
85746 +++ b/kernel/futex_compat.c
85747 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
85748 return 0;
85749 }
85750
85751 -static void __user *futex_uaddr(struct robust_list __user *entry,
85752 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
85753 compat_long_t futex_offset)
85754 {
85755 compat_uptr_t base = ptr_to_compat(entry);
85756 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
85757 index f45b75b..bfac6d5 100644
85758 --- a/kernel/gcov/base.c
85759 +++ b/kernel/gcov/base.c
85760 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
85761 }
85762
85763 #ifdef CONFIG_MODULES
85764 -static inline int within(void *addr, void *start, unsigned long size)
85765 -{
85766 - return ((addr >= start) && (addr < start + size));
85767 -}
85768 -
85769 /* Update list and generate events when modules are unloaded. */
85770 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85771 void *data)
85772 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85773
85774 /* Remove entries located in module from linked list. */
85775 while ((info = gcov_info_next(info))) {
85776 - if (within(info, mod->module_core, mod->core_size)) {
85777 + if (within_module_core_rw((unsigned long)info, mod)) {
85778 gcov_info_unlink(prev, info);
85779 if (gcov_events_enabled)
85780 gcov_event(GCOV_REMOVE, info);
85781 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
85782 index 0909436..6037d22 100644
85783 --- a/kernel/hrtimer.c
85784 +++ b/kernel/hrtimer.c
85785 @@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
85786 local_irq_restore(flags);
85787 }
85788
85789 -static void run_hrtimer_softirq(struct softirq_action *h)
85790 +static __latent_entropy void run_hrtimer_softirq(void)
85791 {
85792 hrtimer_peek_ahead_timers();
85793 }
85794 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
85795 index 55fcce6..0e4cf34 100644
85796 --- a/kernel/irq_work.c
85797 +++ b/kernel/irq_work.c
85798 @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
85799 return NOTIFY_OK;
85800 }
85801
85802 -static struct notifier_block cpu_notify;
85803 +static struct notifier_block cpu_notify = {
85804 + .notifier_call = irq_work_cpu_notify,
85805 + .priority = 0,
85806 +};
85807
85808 static __init int irq_work_init_cpu_notifier(void)
85809 {
85810 - cpu_notify.notifier_call = irq_work_cpu_notify;
85811 - cpu_notify.priority = 0;
85812 register_cpu_notifier(&cpu_notify);
85813 return 0;
85814 }
85815 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
85816 index 9019f15..9a3c42e 100644
85817 --- a/kernel/jump_label.c
85818 +++ b/kernel/jump_label.c
85819 @@ -14,6 +14,7 @@
85820 #include <linux/err.h>
85821 #include <linux/static_key.h>
85822 #include <linux/jump_label_ratelimit.h>
85823 +#include <linux/mm.h>
85824
85825 #ifdef HAVE_JUMP_LABEL
85826
85827 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
85828
85829 size = (((unsigned long)stop - (unsigned long)start)
85830 / sizeof(struct jump_entry));
85831 + pax_open_kernel();
85832 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
85833 + pax_close_kernel();
85834 }
85835
85836 static void jump_label_update(struct static_key *key, int enable);
85837 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
85838 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
85839 struct jump_entry *iter;
85840
85841 + pax_open_kernel();
85842 for (iter = iter_start; iter < iter_stop; iter++) {
85843 if (within_module_init(iter->code, mod))
85844 iter->code = 0;
85845 }
85846 + pax_close_kernel();
85847 }
85848
85849 static int
85850 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
85851 index 3127ad5..159d880 100644
85852 --- a/kernel/kallsyms.c
85853 +++ b/kernel/kallsyms.c
85854 @@ -11,6 +11,9 @@
85855 * Changed the compression method from stem compression to "table lookup"
85856 * compression (see scripts/kallsyms.c for a more complete description)
85857 */
85858 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85859 +#define __INCLUDED_BY_HIDESYM 1
85860 +#endif
85861 #include <linux/kallsyms.h>
85862 #include <linux/module.h>
85863 #include <linux/init.h>
85864 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
85865
85866 static inline int is_kernel_inittext(unsigned long addr)
85867 {
85868 + if (system_state != SYSTEM_BOOTING)
85869 + return 0;
85870 +
85871 if (addr >= (unsigned long)_sinittext
85872 && addr <= (unsigned long)_einittext)
85873 return 1;
85874 return 0;
85875 }
85876
85877 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85878 +#ifdef CONFIG_MODULES
85879 +static inline int is_module_text(unsigned long addr)
85880 +{
85881 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
85882 + return 1;
85883 +
85884 + addr = ktla_ktva(addr);
85885 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
85886 +}
85887 +#else
85888 +static inline int is_module_text(unsigned long addr)
85889 +{
85890 + return 0;
85891 +}
85892 +#endif
85893 +#endif
85894 +
85895 static inline int is_kernel_text(unsigned long addr)
85896 {
85897 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
85898 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
85899
85900 static inline int is_kernel(unsigned long addr)
85901 {
85902 +
85903 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85904 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
85905 + return 1;
85906 +
85907 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
85908 +#else
85909 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
85910 +#endif
85911 +
85912 return 1;
85913 return in_gate_area_no_mm(addr);
85914 }
85915
85916 static int is_ksym_addr(unsigned long addr)
85917 {
85918 +
85919 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85920 + if (is_module_text(addr))
85921 + return 0;
85922 +#endif
85923 +
85924 if (all_var)
85925 return is_kernel(addr);
85926
85927 @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
85928
85929 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
85930 {
85931 - iter->name[0] = '\0';
85932 iter->nameoff = get_symbol_offset(new_pos);
85933 iter->pos = new_pos;
85934 }
85935 @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
85936 {
85937 struct kallsym_iter *iter = m->private;
85938
85939 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85940 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
85941 + return 0;
85942 +#endif
85943 +
85944 /* Some debugging symbols have no name. Ignore them. */
85945 if (!iter->name[0])
85946 return 0;
85947 @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
85948 */
85949 type = iter->exported ? toupper(iter->type) :
85950 tolower(iter->type);
85951 +
85952 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
85953 type, iter->name, iter->module_name);
85954 } else
85955 @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
85956 struct kallsym_iter *iter;
85957 int ret;
85958
85959 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
85960 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
85961 if (!iter)
85962 return -ENOMEM;
85963 reset_iter(iter, 0);
85964 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
85965 index e30ac0f..3528cac 100644
85966 --- a/kernel/kcmp.c
85967 +++ b/kernel/kcmp.c
85968 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
85969 struct task_struct *task1, *task2;
85970 int ret;
85971
85972 +#ifdef CONFIG_GRKERNSEC
85973 + return -ENOSYS;
85974 +#endif
85975 +
85976 rcu_read_lock();
85977
85978 /*
85979 diff --git a/kernel/kexec.c b/kernel/kexec.c
85980 index 60bafbe..a120f4f 100644
85981 --- a/kernel/kexec.c
85982 +++ b/kernel/kexec.c
85983 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
85984 unsigned long flags)
85985 {
85986 struct compat_kexec_segment in;
85987 - struct kexec_segment out, __user *ksegments;
85988 + struct kexec_segment out;
85989 + struct kexec_segment __user *ksegments;
85990 unsigned long i, result;
85991
85992 /* Don't allow clients that don't understand the native
85993 diff --git a/kernel/kmod.c b/kernel/kmod.c
85994 index 6b375af..eaff670 100644
85995 --- a/kernel/kmod.c
85996 +++ b/kernel/kmod.c
85997 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
85998 kfree(info->argv);
85999 }
86000
86001 -static int call_modprobe(char *module_name, int wait)
86002 +static int call_modprobe(char *module_name, char *module_param, int wait)
86003 {
86004 struct subprocess_info *info;
86005 static char *envp[] = {
86006 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86007 NULL
86008 };
86009
86010 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86011 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86012 if (!argv)
86013 goto out;
86014
86015 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86016 argv[1] = "-q";
86017 argv[2] = "--";
86018 argv[3] = module_name; /* check free_modprobe_argv() */
86019 - argv[4] = NULL;
86020 + argv[4] = module_param;
86021 + argv[5] = NULL;
86022
86023 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86024 NULL, free_modprobe_argv, NULL);
86025 @@ -129,9 +130,8 @@ out:
86026 * If module auto-loading support is disabled then this function
86027 * becomes a no-operation.
86028 */
86029 -int __request_module(bool wait, const char *fmt, ...)
86030 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86031 {
86032 - va_list args;
86033 char module_name[MODULE_NAME_LEN];
86034 unsigned int max_modprobes;
86035 int ret;
86036 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86037 if (!modprobe_path[0])
86038 return 0;
86039
86040 - va_start(args, fmt);
86041 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86042 - va_end(args);
86043 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86044 if (ret >= MODULE_NAME_LEN)
86045 return -ENAMETOOLONG;
86046
86047 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86048 if (ret)
86049 return ret;
86050
86051 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86052 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86053 + /* hack to workaround consolekit/udisks stupidity */
86054 + read_lock(&tasklist_lock);
86055 + if (!strcmp(current->comm, "mount") &&
86056 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86057 + read_unlock(&tasklist_lock);
86058 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86059 + return -EPERM;
86060 + }
86061 + read_unlock(&tasklist_lock);
86062 + }
86063 +#endif
86064 +
86065 /* If modprobe needs a service that is in a module, we get a recursive
86066 * loop. Limit the number of running kmod threads to max_threads/2 or
86067 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86068 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86069
86070 trace_module_request(module_name, wait, _RET_IP_);
86071
86072 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86073 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86074
86075 atomic_dec(&kmod_concurrent);
86076 return ret;
86077 }
86078 +
86079 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86080 +{
86081 + va_list args;
86082 + int ret;
86083 +
86084 + va_start(args, fmt);
86085 + ret = ____request_module(wait, module_param, fmt, args);
86086 + va_end(args);
86087 +
86088 + return ret;
86089 +}
86090 +
86091 +int __request_module(bool wait, const char *fmt, ...)
86092 +{
86093 + va_list args;
86094 + int ret;
86095 +
86096 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86097 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86098 + char module_param[MODULE_NAME_LEN];
86099 +
86100 + memset(module_param, 0, sizeof(module_param));
86101 +
86102 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86103 +
86104 + va_start(args, fmt);
86105 + ret = ____request_module(wait, module_param, fmt, args);
86106 + va_end(args);
86107 +
86108 + return ret;
86109 + }
86110 +#endif
86111 +
86112 + va_start(args, fmt);
86113 + ret = ____request_module(wait, NULL, fmt, args);
86114 + va_end(args);
86115 +
86116 + return ret;
86117 +}
86118 +
86119 EXPORT_SYMBOL(__request_module);
86120 #endif /* CONFIG_MODULES */
86121
86122 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86123 */
86124 set_user_nice(current, 0);
86125
86126 +#ifdef CONFIG_GRKERNSEC
86127 + /* this is race-free as far as userland is concerned as we copied
86128 + out the path to be used prior to this point and are now operating
86129 + on that copy
86130 + */
86131 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86132 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86133 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86134 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86135 + retval = -EPERM;
86136 + goto fail;
86137 + }
86138 +#endif
86139 +
86140 retval = -ENOMEM;
86141 new = prepare_kernel_cred(current);
86142 if (!new)
86143 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86144 commit_creds(new);
86145
86146 retval = do_execve(getname_kernel(sub_info->path),
86147 - (const char __user *const __user *)sub_info->argv,
86148 - (const char __user *const __user *)sub_info->envp);
86149 + (const char __user *const __force_user *)sub_info->argv,
86150 + (const char __user *const __force_user *)sub_info->envp);
86151 if (!retval)
86152 return 0;
86153
86154 @@ -260,6 +327,10 @@ static int call_helper(void *data)
86155
86156 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86157 {
86158 +#ifdef CONFIG_GRKERNSEC
86159 + kfree(info->path);
86160 + info->path = info->origpath;
86161 +#endif
86162 if (info->cleanup)
86163 (*info->cleanup)(info);
86164 kfree(info);
86165 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86166 *
86167 * Thus the __user pointer cast is valid here.
86168 */
86169 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
86170 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86171
86172 /*
86173 * If ret is 0, either ____call_usermodehelper failed and the
86174 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86175 goto out;
86176
86177 INIT_WORK(&sub_info->work, __call_usermodehelper);
86178 +#ifdef CONFIG_GRKERNSEC
86179 + sub_info->origpath = path;
86180 + sub_info->path = kstrdup(path, gfp_mask);
86181 +#else
86182 sub_info->path = path;
86183 +#endif
86184 sub_info->argv = argv;
86185 sub_info->envp = envp;
86186
86187 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86188 static int proc_cap_handler(struct ctl_table *table, int write,
86189 void __user *buffer, size_t *lenp, loff_t *ppos)
86190 {
86191 - struct ctl_table t;
86192 + ctl_table_no_const t;
86193 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86194 kernel_cap_t new_cap;
86195 int err, i;
86196 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86197 index ceeadfc..11c18b6 100644
86198 --- a/kernel/kprobes.c
86199 +++ b/kernel/kprobes.c
86200 @@ -31,6 +31,9 @@
86201 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86202 * <prasanna@in.ibm.com> added function-return probes.
86203 */
86204 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86205 +#define __INCLUDED_BY_HIDESYM 1
86206 +#endif
86207 #include <linux/kprobes.h>
86208 #include <linux/hash.h>
86209 #include <linux/init.h>
86210 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
86211
86212 static void *alloc_insn_page(void)
86213 {
86214 - return module_alloc(PAGE_SIZE);
86215 + return module_alloc_exec(PAGE_SIZE);
86216 }
86217
86218 static void free_insn_page(void *page)
86219 {
86220 - module_free(NULL, page);
86221 + module_free_exec(NULL, page);
86222 }
86223
86224 struct kprobe_insn_cache kprobe_insn_slots = {
86225 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86226 kprobe_type = "k";
86227
86228 if (sym)
86229 - seq_printf(pi, "%p %s %s+0x%x %s ",
86230 + seq_printf(pi, "%pK %s %s+0x%x %s ",
86231 p->addr, kprobe_type, sym, offset,
86232 (modname ? modname : " "));
86233 else
86234 - seq_printf(pi, "%p %s %p ",
86235 + seq_printf(pi, "%pK %s %pK ",
86236 p->addr, kprobe_type, p->addr);
86237
86238 if (!pp)
86239 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86240 index d945a94..0b7f45f 100644
86241 --- a/kernel/ksysfs.c
86242 +++ b/kernel/ksysfs.c
86243 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86244 {
86245 if (count+1 > UEVENT_HELPER_PATH_LEN)
86246 return -ENOENT;
86247 + if (!capable(CAP_SYS_ADMIN))
86248 + return -EPERM;
86249 memcpy(uevent_helper, buf, count);
86250 uevent_helper[count] = '\0';
86251 if (count && uevent_helper[count-1] == '\n')
86252 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86253 return count;
86254 }
86255
86256 -static struct bin_attribute notes_attr = {
86257 +static bin_attribute_no_const notes_attr __read_only = {
86258 .attr = {
86259 .name = "notes",
86260 .mode = S_IRUGO,
86261 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86262 index eb8a547..321d8e1 100644
86263 --- a/kernel/locking/lockdep.c
86264 +++ b/kernel/locking/lockdep.c
86265 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
86266 end = (unsigned long) &_end,
86267 addr = (unsigned long) obj;
86268
86269 +#ifdef CONFIG_PAX_KERNEXEC
86270 + start = ktla_ktva(start);
86271 +#endif
86272 +
86273 /*
86274 * static variable?
86275 */
86276 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86277 if (!static_obj(lock->key)) {
86278 debug_locks_off();
86279 printk("INFO: trying to register non-static key.\n");
86280 + printk("lock:%pS key:%pS.\n", lock, lock->key);
86281 printk("the code is fine but needs lockdep annotation.\n");
86282 printk("turning off the locking correctness validator.\n");
86283 dump_stack();
86284 @@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86285 if (!class)
86286 return 0;
86287 }
86288 - atomic_inc((atomic_t *)&class->ops);
86289 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86290 if (very_verbose(class)) {
86291 printk("\nacquire class [%p] %s", class->key, class->name);
86292 if (class->name_version > 1)
86293 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86294 index ef43ac4..2720dfa 100644
86295 --- a/kernel/locking/lockdep_proc.c
86296 +++ b/kernel/locking/lockdep_proc.c
86297 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86298 return 0;
86299 }
86300
86301 - seq_printf(m, "%p", class->key);
86302 + seq_printf(m, "%pK", class->key);
86303 #ifdef CONFIG_DEBUG_LOCKDEP
86304 seq_printf(m, " OPS:%8ld", class->ops);
86305 #endif
86306 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86307
86308 list_for_each_entry(entry, &class->locks_after, entry) {
86309 if (entry->distance == 1) {
86310 - seq_printf(m, " -> [%p] ", entry->class->key);
86311 + seq_printf(m, " -> [%pK] ", entry->class->key);
86312 print_name(m, entry->class);
86313 seq_puts(m, "\n");
86314 }
86315 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86316 if (!class->key)
86317 continue;
86318
86319 - seq_printf(m, "[%p] ", class->key);
86320 + seq_printf(m, "[%pK] ", class->key);
86321 print_name(m, class);
86322 seq_puts(m, "\n");
86323 }
86324 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86325 if (!i)
86326 seq_line(m, '-', 40-namelen, namelen);
86327
86328 - snprintf(ip, sizeof(ip), "[<%p>]",
86329 + snprintf(ip, sizeof(ip), "[<%pK>]",
86330 (void *)class->contention_point[i]);
86331 seq_printf(m, "%40s %14lu %29s %pS\n",
86332 name, stats->contention_point[i],
86333 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86334 if (!i)
86335 seq_line(m, '-', 40-namelen, namelen);
86336
86337 - snprintf(ip, sizeof(ip), "[<%p>]",
86338 + snprintf(ip, sizeof(ip), "[<%pK>]",
86339 (void *)class->contending_point[i]);
86340 seq_printf(m, "%40s %14lu %29s %pS\n",
86341 name, stats->contending_point[i],
86342 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
86343 index faf6f5b..dc9070a 100644
86344 --- a/kernel/locking/mutex-debug.c
86345 +++ b/kernel/locking/mutex-debug.c
86346 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
86347 }
86348
86349 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86350 - struct thread_info *ti)
86351 + struct task_struct *task)
86352 {
86353 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
86354
86355 /* Mark the current thread as blocked on the lock: */
86356 - ti->task->blocked_on = waiter;
86357 + task->blocked_on = waiter;
86358 }
86359
86360 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86361 - struct thread_info *ti)
86362 + struct task_struct *task)
86363 {
86364 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
86365 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
86366 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
86367 - ti->task->blocked_on = NULL;
86368 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
86369 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
86370 + task->blocked_on = NULL;
86371
86372 list_del_init(&waiter->list);
86373 waiter->task = NULL;
86374 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
86375 index 0799fd3..d06ae3b 100644
86376 --- a/kernel/locking/mutex-debug.h
86377 +++ b/kernel/locking/mutex-debug.h
86378 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
86379 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
86380 extern void debug_mutex_add_waiter(struct mutex *lock,
86381 struct mutex_waiter *waiter,
86382 - struct thread_info *ti);
86383 + struct task_struct *task);
86384 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86385 - struct thread_info *ti);
86386 + struct task_struct *task);
86387 extern void debug_mutex_unlock(struct mutex *lock);
86388 extern void debug_mutex_init(struct mutex *lock, const char *name,
86389 struct lock_class_key *key);
86390 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
86391 index 4dd6e4c..df52693 100644
86392 --- a/kernel/locking/mutex.c
86393 +++ b/kernel/locking/mutex.c
86394 @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
86395 node->locked = 1;
86396 return;
86397 }
86398 - ACCESS_ONCE(prev->next) = node;
86399 + ACCESS_ONCE_RW(prev->next) = node;
86400 smp_wmb();
86401 /* Wait until the lock holder passes the lock down */
86402 while (!ACCESS_ONCE(node->locked))
86403 @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
86404 while (!(next = ACCESS_ONCE(node->next)))
86405 arch_mutex_cpu_relax();
86406 }
86407 - ACCESS_ONCE(next->locked) = 1;
86408 + ACCESS_ONCE_RW(next->locked) = 1;
86409 smp_wmb();
86410 }
86411
86412 @@ -520,7 +520,7 @@ slowpath:
86413 goto skip_wait;
86414
86415 debug_mutex_lock_common(lock, &waiter);
86416 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
86417 + debug_mutex_add_waiter(lock, &waiter, task);
86418
86419 /* add waiting tasks to the end of the waitqueue (FIFO): */
86420 list_add_tail(&waiter.list, &lock->wait_list);
86421 @@ -564,7 +564,7 @@ slowpath:
86422 schedule_preempt_disabled();
86423 spin_lock_mutex(&lock->wait_lock, flags);
86424 }
86425 - mutex_remove_waiter(lock, &waiter, current_thread_info());
86426 + mutex_remove_waiter(lock, &waiter, task);
86427 /* set it to 0 if there are no waiters left: */
86428 if (likely(list_empty(&lock->wait_list)))
86429 atomic_set(&lock->count, 0);
86430 @@ -601,7 +601,7 @@ skip_wait:
86431 return 0;
86432
86433 err:
86434 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
86435 + mutex_remove_waiter(lock, &waiter, task);
86436 spin_unlock_mutex(&lock->wait_lock, flags);
86437 debug_mutex_free_waiter(&waiter);
86438 mutex_release(&lock->dep_map, 1, ip);
86439 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
86440 index 1d96dd0..994ff19 100644
86441 --- a/kernel/locking/rtmutex-tester.c
86442 +++ b/kernel/locking/rtmutex-tester.c
86443 @@ -22,7 +22,7 @@
86444 #define MAX_RT_TEST_MUTEXES 8
86445
86446 static spinlock_t rttest_lock;
86447 -static atomic_t rttest_event;
86448 +static atomic_unchecked_t rttest_event;
86449
86450 struct test_thread_data {
86451 int opcode;
86452 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86453
86454 case RTTEST_LOCKCONT:
86455 td->mutexes[td->opdata] = 1;
86456 - td->event = atomic_add_return(1, &rttest_event);
86457 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86458 return 0;
86459
86460 case RTTEST_RESET:
86461 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86462 return 0;
86463
86464 case RTTEST_RESETEVENT:
86465 - atomic_set(&rttest_event, 0);
86466 + atomic_set_unchecked(&rttest_event, 0);
86467 return 0;
86468
86469 default:
86470 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86471 return ret;
86472
86473 td->mutexes[id] = 1;
86474 - td->event = atomic_add_return(1, &rttest_event);
86475 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86476 rt_mutex_lock(&mutexes[id]);
86477 - td->event = atomic_add_return(1, &rttest_event);
86478 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86479 td->mutexes[id] = 4;
86480 return 0;
86481
86482 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86483 return ret;
86484
86485 td->mutexes[id] = 1;
86486 - td->event = atomic_add_return(1, &rttest_event);
86487 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86488 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
86489 - td->event = atomic_add_return(1, &rttest_event);
86490 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86491 td->mutexes[id] = ret ? 0 : 4;
86492 return ret ? -EINTR : 0;
86493
86494 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86495 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
86496 return ret;
86497
86498 - td->event = atomic_add_return(1, &rttest_event);
86499 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86500 rt_mutex_unlock(&mutexes[id]);
86501 - td->event = atomic_add_return(1, &rttest_event);
86502 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86503 td->mutexes[id] = 0;
86504 return 0;
86505
86506 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86507 break;
86508
86509 td->mutexes[dat] = 2;
86510 - td->event = atomic_add_return(1, &rttest_event);
86511 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86512 break;
86513
86514 default:
86515 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86516 return;
86517
86518 td->mutexes[dat] = 3;
86519 - td->event = atomic_add_return(1, &rttest_event);
86520 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86521 break;
86522
86523 case RTTEST_LOCKNOWAIT:
86524 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86525 return;
86526
86527 td->mutexes[dat] = 1;
86528 - td->event = atomic_add_return(1, &rttest_event);
86529 + td->event = atomic_add_return_unchecked(1, &rttest_event);
86530 return;
86531
86532 default:
86533 diff --git a/kernel/module.c b/kernel/module.c
86534 index d24fcf2..2af3fd9 100644
86535 --- a/kernel/module.c
86536 +++ b/kernel/module.c
86537 @@ -61,6 +61,7 @@
86538 #include <linux/pfn.h>
86539 #include <linux/bsearch.h>
86540 #include <linux/fips.h>
86541 +#include <linux/grsecurity.h>
86542 #include <uapi/linux/module.h>
86543 #include "module-internal.h"
86544
86545 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
86546
86547 /* Bounds of module allocation, for speeding __module_address.
86548 * Protected by module_mutex. */
86549 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
86550 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
86551 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
86552
86553 int register_module_notifier(struct notifier_block * nb)
86554 {
86555 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86556 return true;
86557
86558 list_for_each_entry_rcu(mod, &modules, list) {
86559 - struct symsearch arr[] = {
86560 + struct symsearch modarr[] = {
86561 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
86562 NOT_GPL_ONLY, false },
86563 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
86564 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86565 if (mod->state == MODULE_STATE_UNFORMED)
86566 continue;
86567
86568 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
86569 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
86570 return true;
86571 }
86572 return false;
86573 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
86574 if (!pcpusec->sh_size)
86575 return 0;
86576
86577 - if (align > PAGE_SIZE) {
86578 + if (align-1 >= PAGE_SIZE) {
86579 pr_warn("%s: per-cpu alignment %li > %li\n",
86580 mod->name, align, PAGE_SIZE);
86581 align = PAGE_SIZE;
86582 @@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
86583 static ssize_t show_coresize(struct module_attribute *mattr,
86584 struct module_kobject *mk, char *buffer)
86585 {
86586 - return sprintf(buffer, "%u\n", mk->mod->core_size);
86587 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
86588 }
86589
86590 static struct module_attribute modinfo_coresize =
86591 @@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
86592 static ssize_t show_initsize(struct module_attribute *mattr,
86593 struct module_kobject *mk, char *buffer)
86594 {
86595 - return sprintf(buffer, "%u\n", mk->mod->init_size);
86596 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
86597 }
86598
86599 static struct module_attribute modinfo_initsize =
86600 @@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
86601 goto bad_version;
86602 }
86603
86604 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86605 + /*
86606 + * avoid potentially printing jibberish on attempted load
86607 + * of a module randomized with a different seed
86608 + */
86609 + pr_warn("no symbol version for %s\n", symname);
86610 +#else
86611 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
86612 +#endif
86613 return 0;
86614
86615 bad_version:
86616 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86617 + /*
86618 + * avoid potentially printing jibberish on attempted load
86619 + * of a module randomized with a different seed
86620 + */
86621 + printk("attempted module disagrees about version of symbol %s\n",
86622 + symname);
86623 +#else
86624 printk("%s: disagrees about version of symbol %s\n",
86625 mod->name, symname);
86626 +#endif
86627 return 0;
86628 }
86629
86630 @@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
86631 */
86632 #ifdef CONFIG_SYSFS
86633
86634 -#ifdef CONFIG_KALLSYMS
86635 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
86636 static inline bool sect_empty(const Elf_Shdr *sect)
86637 {
86638 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
86639 @@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
86640 {
86641 unsigned int notes, loaded, i;
86642 struct module_notes_attrs *notes_attrs;
86643 - struct bin_attribute *nattr;
86644 + bin_attribute_no_const *nattr;
86645
86646 /* failed to create section attributes, so can't create notes */
86647 if (!mod->sect_attrs)
86648 @@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
86649 static int module_add_modinfo_attrs(struct module *mod)
86650 {
86651 struct module_attribute *attr;
86652 - struct module_attribute *temp_attr;
86653 + module_attribute_no_const *temp_attr;
86654 int error = 0;
86655 int i;
86656
86657 @@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
86658
86659 static void unset_module_core_ro_nx(struct module *mod)
86660 {
86661 - set_page_attributes(mod->module_core + mod->core_text_size,
86662 - mod->module_core + mod->core_size,
86663 + set_page_attributes(mod->module_core_rw,
86664 + mod->module_core_rw + mod->core_size_rw,
86665 set_memory_x);
86666 - set_page_attributes(mod->module_core,
86667 - mod->module_core + mod->core_ro_size,
86668 + set_page_attributes(mod->module_core_rx,
86669 + mod->module_core_rx + mod->core_size_rx,
86670 set_memory_rw);
86671 }
86672
86673 static void unset_module_init_ro_nx(struct module *mod)
86674 {
86675 - set_page_attributes(mod->module_init + mod->init_text_size,
86676 - mod->module_init + mod->init_size,
86677 + set_page_attributes(mod->module_init_rw,
86678 + mod->module_init_rw + mod->init_size_rw,
86679 set_memory_x);
86680 - set_page_attributes(mod->module_init,
86681 - mod->module_init + mod->init_ro_size,
86682 + set_page_attributes(mod->module_init_rx,
86683 + mod->module_init_rx + mod->init_size_rx,
86684 set_memory_rw);
86685 }
86686
86687 @@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
86688 list_for_each_entry_rcu(mod, &modules, list) {
86689 if (mod->state == MODULE_STATE_UNFORMED)
86690 continue;
86691 - if ((mod->module_core) && (mod->core_text_size)) {
86692 - set_page_attributes(mod->module_core,
86693 - mod->module_core + mod->core_text_size,
86694 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
86695 + set_page_attributes(mod->module_core_rx,
86696 + mod->module_core_rx + mod->core_size_rx,
86697 set_memory_rw);
86698 }
86699 - if ((mod->module_init) && (mod->init_text_size)) {
86700 - set_page_attributes(mod->module_init,
86701 - mod->module_init + mod->init_text_size,
86702 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
86703 + set_page_attributes(mod->module_init_rx,
86704 + mod->module_init_rx + mod->init_size_rx,
86705 set_memory_rw);
86706 }
86707 }
86708 @@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
86709 list_for_each_entry_rcu(mod, &modules, list) {
86710 if (mod->state == MODULE_STATE_UNFORMED)
86711 continue;
86712 - if ((mod->module_core) && (mod->core_text_size)) {
86713 - set_page_attributes(mod->module_core,
86714 - mod->module_core + mod->core_text_size,
86715 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
86716 + set_page_attributes(mod->module_core_rx,
86717 + mod->module_core_rx + mod->core_size_rx,
86718 set_memory_ro);
86719 }
86720 - if ((mod->module_init) && (mod->init_text_size)) {
86721 - set_page_attributes(mod->module_init,
86722 - mod->module_init + mod->init_text_size,
86723 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
86724 + set_page_attributes(mod->module_init_rx,
86725 + mod->module_init_rx + mod->init_size_rx,
86726 set_memory_ro);
86727 }
86728 }
86729 @@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
86730
86731 /* This may be NULL, but that's OK */
86732 unset_module_init_ro_nx(mod);
86733 - module_free(mod, mod->module_init);
86734 + module_free(mod, mod->module_init_rw);
86735 + module_free_exec(mod, mod->module_init_rx);
86736 kfree(mod->args);
86737 percpu_modfree(mod);
86738
86739 /* Free lock-classes: */
86740 - lockdep_free_key_range(mod->module_core, mod->core_size);
86741 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
86742 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
86743
86744 /* Finally, free the core (containing the module structure) */
86745 unset_module_core_ro_nx(mod);
86746 - module_free(mod, mod->module_core);
86747 + module_free_exec(mod, mod->module_core_rx);
86748 + module_free(mod, mod->module_core_rw);
86749
86750 #ifdef CONFIG_MPU
86751 update_protections(current->mm);
86752 @@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86753 int ret = 0;
86754 const struct kernel_symbol *ksym;
86755
86756 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86757 + int is_fs_load = 0;
86758 + int register_filesystem_found = 0;
86759 + char *p;
86760 +
86761 + p = strstr(mod->args, "grsec_modharden_fs");
86762 + if (p) {
86763 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
86764 + /* copy \0 as well */
86765 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
86766 + is_fs_load = 1;
86767 + }
86768 +#endif
86769 +
86770 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
86771 const char *name = info->strtab + sym[i].st_name;
86772
86773 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86774 + /* it's a real shame this will never get ripped and copied
86775 + upstream! ;(
86776 + */
86777 + if (is_fs_load && !strcmp(name, "register_filesystem"))
86778 + register_filesystem_found = 1;
86779 +#endif
86780 +
86781 switch (sym[i].st_shndx) {
86782 case SHN_COMMON:
86783 /* We compiled with -fno-common. These are not
86784 @@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86785 ksym = resolve_symbol_wait(mod, info, name);
86786 /* Ok if resolved. */
86787 if (ksym && !IS_ERR(ksym)) {
86788 + pax_open_kernel();
86789 sym[i].st_value = ksym->value;
86790 + pax_close_kernel();
86791 break;
86792 }
86793
86794 @@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86795 secbase = (unsigned long)mod_percpu(mod);
86796 else
86797 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
86798 + pax_open_kernel();
86799 sym[i].st_value += secbase;
86800 + pax_close_kernel();
86801 break;
86802 }
86803 }
86804
86805 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86806 + if (is_fs_load && !register_filesystem_found) {
86807 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
86808 + ret = -EPERM;
86809 + }
86810 +#endif
86811 +
86812 return ret;
86813 }
86814
86815 @@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
86816 || s->sh_entsize != ~0UL
86817 || strstarts(sname, ".init"))
86818 continue;
86819 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
86820 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86821 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
86822 + else
86823 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
86824 pr_debug("\t%s\n", sname);
86825 }
86826 - switch (m) {
86827 - case 0: /* executable */
86828 - mod->core_size = debug_align(mod->core_size);
86829 - mod->core_text_size = mod->core_size;
86830 - break;
86831 - case 1: /* RO: text and ro-data */
86832 - mod->core_size = debug_align(mod->core_size);
86833 - mod->core_ro_size = mod->core_size;
86834 - break;
86835 - case 3: /* whole core */
86836 - mod->core_size = debug_align(mod->core_size);
86837 - break;
86838 - }
86839 }
86840
86841 pr_debug("Init section allocation order:\n");
86842 @@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
86843 || s->sh_entsize != ~0UL
86844 || !strstarts(sname, ".init"))
86845 continue;
86846 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
86847 - | INIT_OFFSET_MASK);
86848 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86849 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
86850 + else
86851 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
86852 + s->sh_entsize |= INIT_OFFSET_MASK;
86853 pr_debug("\t%s\n", sname);
86854 }
86855 - switch (m) {
86856 - case 0: /* executable */
86857 - mod->init_size = debug_align(mod->init_size);
86858 - mod->init_text_size = mod->init_size;
86859 - break;
86860 - case 1: /* RO: text and ro-data */
86861 - mod->init_size = debug_align(mod->init_size);
86862 - mod->init_ro_size = mod->init_size;
86863 - break;
86864 - case 3: /* whole init */
86865 - mod->init_size = debug_align(mod->init_size);
86866 - break;
86867 - }
86868 }
86869 }
86870
86871 @@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86872
86873 /* Put symbol section at end of init part of module. */
86874 symsect->sh_flags |= SHF_ALLOC;
86875 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
86876 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
86877 info->index.sym) | INIT_OFFSET_MASK;
86878 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
86879
86880 @@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86881 }
86882
86883 /* Append room for core symbols at end of core part. */
86884 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
86885 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
86886 - mod->core_size += strtab_size;
86887 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
86888 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
86889 + mod->core_size_rx += strtab_size;
86890
86891 /* Put string table section at end of init part of module. */
86892 strsect->sh_flags |= SHF_ALLOC;
86893 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
86894 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
86895 info->index.str) | INIT_OFFSET_MASK;
86896 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
86897 }
86898 @@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
86899 /* Make sure we get permanent strtab: don't use info->strtab. */
86900 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
86901
86902 + pax_open_kernel();
86903 +
86904 /* Set types up while we still have access to sections. */
86905 for (i = 0; i < mod->num_symtab; i++)
86906 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
86907
86908 - mod->core_symtab = dst = mod->module_core + info->symoffs;
86909 - mod->core_strtab = s = mod->module_core + info->stroffs;
86910 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
86911 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
86912 src = mod->symtab;
86913 for (ndst = i = 0; i < mod->num_symtab; i++) {
86914 if (i == 0 ||
86915 @@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
86916 }
86917 }
86918 mod->core_num_syms = ndst;
86919 +
86920 + pax_close_kernel();
86921 }
86922 #else
86923 static inline void layout_symtab(struct module *mod, struct load_info *info)
86924 @@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
86925 return vmalloc_exec(size);
86926 }
86927
86928 -static void *module_alloc_update_bounds(unsigned long size)
86929 +static void *module_alloc_update_bounds_rw(unsigned long size)
86930 {
86931 void *ret = module_alloc(size);
86932
86933 if (ret) {
86934 mutex_lock(&module_mutex);
86935 /* Update module bounds. */
86936 - if ((unsigned long)ret < module_addr_min)
86937 - module_addr_min = (unsigned long)ret;
86938 - if ((unsigned long)ret + size > module_addr_max)
86939 - module_addr_max = (unsigned long)ret + size;
86940 + if ((unsigned long)ret < module_addr_min_rw)
86941 + module_addr_min_rw = (unsigned long)ret;
86942 + if ((unsigned long)ret + size > module_addr_max_rw)
86943 + module_addr_max_rw = (unsigned long)ret + size;
86944 + mutex_unlock(&module_mutex);
86945 + }
86946 + return ret;
86947 +}
86948 +
86949 +static void *module_alloc_update_bounds_rx(unsigned long size)
86950 +{
86951 + void *ret = module_alloc_exec(size);
86952 +
86953 + if (ret) {
86954 + mutex_lock(&module_mutex);
86955 + /* Update module bounds. */
86956 + if ((unsigned long)ret < module_addr_min_rx)
86957 + module_addr_min_rx = (unsigned long)ret;
86958 + if ((unsigned long)ret + size > module_addr_max_rx)
86959 + module_addr_max_rx = (unsigned long)ret + size;
86960 mutex_unlock(&module_mutex);
86961 }
86962 return ret;
86963 @@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
86964 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
86965
86966 if (info->index.sym == 0) {
86967 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86968 + /*
86969 + * avoid potentially printing jibberish on attempted load
86970 + * of a module randomized with a different seed
86971 + */
86972 + pr_warn("module has no symbols (stripped?)\n");
86973 +#else
86974 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
86975 +#endif
86976 return ERR_PTR(-ENOEXEC);
86977 }
86978
86979 @@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
86980 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
86981 {
86982 const char *modmagic = get_modinfo(info, "vermagic");
86983 + const char *license = get_modinfo(info, "license");
86984 int err;
86985
86986 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
86987 + if (!license || !license_is_gpl_compatible(license))
86988 + return -ENOEXEC;
86989 +#endif
86990 +
86991 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
86992 modmagic = NULL;
86993
86994 @@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
86995 }
86996
86997 /* Set up license info based on the info section */
86998 - set_license(mod, get_modinfo(info, "license"));
86999 + set_license(mod, license);
87000
87001 return 0;
87002 }
87003 @@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
87004 void *ptr;
87005
87006 /* Do the allocs. */
87007 - ptr = module_alloc_update_bounds(mod->core_size);
87008 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87009 /*
87010 * The pointer to this block is stored in the module structure
87011 * which is inside the block. Just mark it as not being a
87012 @@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
87013 if (!ptr)
87014 return -ENOMEM;
87015
87016 - memset(ptr, 0, mod->core_size);
87017 - mod->module_core = ptr;
87018 + memset(ptr, 0, mod->core_size_rw);
87019 + mod->module_core_rw = ptr;
87020
87021 - if (mod->init_size) {
87022 - ptr = module_alloc_update_bounds(mod->init_size);
87023 + if (mod->init_size_rw) {
87024 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87025 /*
87026 * The pointer to this block is stored in the module structure
87027 * which is inside the block. This block doesn't need to be
87028 @@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
87029 */
87030 kmemleak_ignore(ptr);
87031 if (!ptr) {
87032 - module_free(mod, mod->module_core);
87033 + module_free(mod, mod->module_core_rw);
87034 return -ENOMEM;
87035 }
87036 - memset(ptr, 0, mod->init_size);
87037 - mod->module_init = ptr;
87038 + memset(ptr, 0, mod->init_size_rw);
87039 + mod->module_init_rw = ptr;
87040 } else
87041 - mod->module_init = NULL;
87042 + mod->module_init_rw = NULL;
87043 +
87044 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87045 + kmemleak_not_leak(ptr);
87046 + if (!ptr) {
87047 + if (mod->module_init_rw)
87048 + module_free(mod, mod->module_init_rw);
87049 + module_free(mod, mod->module_core_rw);
87050 + return -ENOMEM;
87051 + }
87052 +
87053 + pax_open_kernel();
87054 + memset(ptr, 0, mod->core_size_rx);
87055 + pax_close_kernel();
87056 + mod->module_core_rx = ptr;
87057 +
87058 + if (mod->init_size_rx) {
87059 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87060 + kmemleak_ignore(ptr);
87061 + if (!ptr && mod->init_size_rx) {
87062 + module_free_exec(mod, mod->module_core_rx);
87063 + if (mod->module_init_rw)
87064 + module_free(mod, mod->module_init_rw);
87065 + module_free(mod, mod->module_core_rw);
87066 + return -ENOMEM;
87067 + }
87068 +
87069 + pax_open_kernel();
87070 + memset(ptr, 0, mod->init_size_rx);
87071 + pax_close_kernel();
87072 + mod->module_init_rx = ptr;
87073 + } else
87074 + mod->module_init_rx = NULL;
87075
87076 /* Transfer each section which specifies SHF_ALLOC */
87077 pr_debug("final section addresses:\n");
87078 @@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
87079 if (!(shdr->sh_flags & SHF_ALLOC))
87080 continue;
87081
87082 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
87083 - dest = mod->module_init
87084 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87085 - else
87086 - dest = mod->module_core + shdr->sh_entsize;
87087 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87088 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87089 + dest = mod->module_init_rw
87090 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87091 + else
87092 + dest = mod->module_init_rx
87093 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87094 + } else {
87095 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87096 + dest = mod->module_core_rw + shdr->sh_entsize;
87097 + else
87098 + dest = mod->module_core_rx + shdr->sh_entsize;
87099 + }
87100 +
87101 + if (shdr->sh_type != SHT_NOBITS) {
87102 +
87103 +#ifdef CONFIG_PAX_KERNEXEC
87104 +#ifdef CONFIG_X86_64
87105 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87106 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
87107 +#endif
87108 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
87109 + pax_open_kernel();
87110 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87111 + pax_close_kernel();
87112 + } else
87113 +#endif
87114
87115 - if (shdr->sh_type != SHT_NOBITS)
87116 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87117 + }
87118 /* Update sh_addr to point to copy in image. */
87119 - shdr->sh_addr = (unsigned long)dest;
87120 +
87121 +#ifdef CONFIG_PAX_KERNEXEC
87122 + if (shdr->sh_flags & SHF_EXECINSTR)
87123 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
87124 + else
87125 +#endif
87126 +
87127 + shdr->sh_addr = (unsigned long)dest;
87128 pr_debug("\t0x%lx %s\n",
87129 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87130 }
87131 @@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
87132 * Do it before processing of module parameters, so the module
87133 * can provide parameter accessor functions of its own.
87134 */
87135 - if (mod->module_init)
87136 - flush_icache_range((unsigned long)mod->module_init,
87137 - (unsigned long)mod->module_init
87138 - + mod->init_size);
87139 - flush_icache_range((unsigned long)mod->module_core,
87140 - (unsigned long)mod->module_core + mod->core_size);
87141 + if (mod->module_init_rx)
87142 + flush_icache_range((unsigned long)mod->module_init_rx,
87143 + (unsigned long)mod->module_init_rx
87144 + + mod->init_size_rx);
87145 + flush_icache_range((unsigned long)mod->module_core_rx,
87146 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
87147
87148 set_fs(old_fs);
87149 }
87150 @@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87151 static void module_deallocate(struct module *mod, struct load_info *info)
87152 {
87153 percpu_modfree(mod);
87154 - module_free(mod, mod->module_init);
87155 - module_free(mod, mod->module_core);
87156 + module_free_exec(mod, mod->module_init_rx);
87157 + module_free_exec(mod, mod->module_core_rx);
87158 + module_free(mod, mod->module_init_rw);
87159 + module_free(mod, mod->module_core_rw);
87160 }
87161
87162 int __weak module_finalize(const Elf_Ehdr *hdr,
87163 @@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87164 static int post_relocation(struct module *mod, const struct load_info *info)
87165 {
87166 /* Sort exception table now relocations are done. */
87167 + pax_open_kernel();
87168 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87169 + pax_close_kernel();
87170
87171 /* Copy relocated percpu area over. */
87172 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87173 @@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
87174 MODULE_STATE_COMING, mod);
87175
87176 /* Set RO and NX regions for core */
87177 - set_section_ro_nx(mod->module_core,
87178 - mod->core_text_size,
87179 - mod->core_ro_size,
87180 - mod->core_size);
87181 + set_section_ro_nx(mod->module_core_rx,
87182 + mod->core_size_rx,
87183 + mod->core_size_rx,
87184 + mod->core_size_rx);
87185
87186 /* Set RO and NX regions for init */
87187 - set_section_ro_nx(mod->module_init,
87188 - mod->init_text_size,
87189 - mod->init_ro_size,
87190 - mod->init_size);
87191 + set_section_ro_nx(mod->module_init_rx,
87192 + mod->init_size_rx,
87193 + mod->init_size_rx,
87194 + mod->init_size_rx);
87195
87196 do_mod_ctors(mod);
87197 /* Start the module */
87198 @@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
87199 mod->strtab = mod->core_strtab;
87200 #endif
87201 unset_module_init_ro_nx(mod);
87202 - module_free(mod, mod->module_init);
87203 - mod->module_init = NULL;
87204 - mod->init_size = 0;
87205 - mod->init_ro_size = 0;
87206 - mod->init_text_size = 0;
87207 + module_free(mod, mod->module_init_rw);
87208 + module_free_exec(mod, mod->module_init_rx);
87209 + mod->module_init_rw = NULL;
87210 + mod->module_init_rx = NULL;
87211 + mod->init_size_rw = 0;
87212 + mod->init_size_rx = 0;
87213 mutex_unlock(&module_mutex);
87214 wake_up_all(&module_wq);
87215
87216 @@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87217 if (err)
87218 goto free_unload;
87219
87220 + /* Now copy in args */
87221 + mod->args = strndup_user(uargs, ~0UL >> 1);
87222 + if (IS_ERR(mod->args)) {
87223 + err = PTR_ERR(mod->args);
87224 + goto free_unload;
87225 + }
87226 +
87227 /* Set up MODINFO_ATTR fields */
87228 setup_modinfo(mod, info);
87229
87230 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87231 + {
87232 + char *p, *p2;
87233 +
87234 + if (strstr(mod->args, "grsec_modharden_netdev")) {
87235 + 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);
87236 + err = -EPERM;
87237 + goto free_modinfo;
87238 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87239 + p += sizeof("grsec_modharden_normal") - 1;
87240 + p2 = strstr(p, "_");
87241 + if (p2) {
87242 + *p2 = '\0';
87243 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87244 + *p2 = '_';
87245 + }
87246 + err = -EPERM;
87247 + goto free_modinfo;
87248 + }
87249 + }
87250 +#endif
87251 +
87252 /* Fix up syms, so that st_value is a pointer to location. */
87253 err = simplify_symbols(mod, info);
87254 if (err < 0)
87255 @@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87256
87257 flush_module_icache(mod);
87258
87259 - /* Now copy in args */
87260 - mod->args = strndup_user(uargs, ~0UL >> 1);
87261 - if (IS_ERR(mod->args)) {
87262 - err = PTR_ERR(mod->args);
87263 - goto free_arch_cleanup;
87264 - }
87265 -
87266 dynamic_debug_setup(info->debug, info->num_debug);
87267
87268 /* Finally it's fully formed, ready to start executing. */
87269 @@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87270 ddebug_cleanup:
87271 dynamic_debug_remove(info->debug);
87272 synchronize_sched();
87273 - kfree(mod->args);
87274 - free_arch_cleanup:
87275 module_arch_cleanup(mod);
87276 free_modinfo:
87277 free_modinfo(mod);
87278 + kfree(mod->args);
87279 free_unload:
87280 module_unload_free(mod);
87281 unlink_mod:
87282 @@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
87283 unsigned long nextval;
87284
87285 /* At worse, next value is at end of module */
87286 - if (within_module_init(addr, mod))
87287 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
87288 + if (within_module_init_rx(addr, mod))
87289 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87290 + else if (within_module_init_rw(addr, mod))
87291 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87292 + else if (within_module_core_rx(addr, mod))
87293 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87294 + else if (within_module_core_rw(addr, mod))
87295 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87296 else
87297 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
87298 + return NULL;
87299
87300 /* Scan for closest preceding symbol, and next symbol. (ELF
87301 starts real symbols at 1). */
87302 @@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
87303 return 0;
87304
87305 seq_printf(m, "%s %u",
87306 - mod->name, mod->init_size + mod->core_size);
87307 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87308 print_unload_info(m, mod);
87309
87310 /* Informative for users. */
87311 @@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
87312 mod->state == MODULE_STATE_COMING ? "Loading":
87313 "Live");
87314 /* Used by oprofile and other similar tools. */
87315 - seq_printf(m, " 0x%pK", mod->module_core);
87316 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87317
87318 /* Taints info */
87319 if (mod->taints)
87320 @@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
87321
87322 static int __init proc_modules_init(void)
87323 {
87324 +#ifndef CONFIG_GRKERNSEC_HIDESYM
87325 +#ifdef CONFIG_GRKERNSEC_PROC_USER
87326 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87327 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87328 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
87329 +#else
87330 proc_create("modules", 0, NULL, &proc_modules_operations);
87331 +#endif
87332 +#else
87333 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87334 +#endif
87335 return 0;
87336 }
87337 module_init(proc_modules_init);
87338 @@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
87339 {
87340 struct module *mod;
87341
87342 - if (addr < module_addr_min || addr > module_addr_max)
87343 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
87344 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
87345 return NULL;
87346
87347 list_for_each_entry_rcu(mod, &modules, list) {
87348 if (mod->state == MODULE_STATE_UNFORMED)
87349 continue;
87350 - if (within_module_core(addr, mod)
87351 - || within_module_init(addr, mod))
87352 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
87353 return mod;
87354 }
87355 return NULL;
87356 @@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
87357 */
87358 struct module *__module_text_address(unsigned long addr)
87359 {
87360 - struct module *mod = __module_address(addr);
87361 + struct module *mod;
87362 +
87363 +#ifdef CONFIG_X86_32
87364 + addr = ktla_ktva(addr);
87365 +#endif
87366 +
87367 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
87368 + return NULL;
87369 +
87370 + mod = __module_address(addr);
87371 +
87372 if (mod) {
87373 /* Make sure it's within the text section. */
87374 - if (!within(addr, mod->module_init, mod->init_text_size)
87375 - && !within(addr, mod->module_core, mod->core_text_size))
87376 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
87377 mod = NULL;
87378 }
87379 return mod;
87380 diff --git a/kernel/notifier.c b/kernel/notifier.c
87381 index 2d5cc4c..d9ea600 100644
87382 --- a/kernel/notifier.c
87383 +++ b/kernel/notifier.c
87384 @@ -5,6 +5,7 @@
87385 #include <linux/rcupdate.h>
87386 #include <linux/vmalloc.h>
87387 #include <linux/reboot.h>
87388 +#include <linux/mm.h>
87389
87390 /*
87391 * Notifier list for kernel code which wants to be called
87392 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
87393 while ((*nl) != NULL) {
87394 if (n->priority > (*nl)->priority)
87395 break;
87396 - nl = &((*nl)->next);
87397 + nl = (struct notifier_block **)&((*nl)->next);
87398 }
87399 - n->next = *nl;
87400 + pax_open_kernel();
87401 + *(const void **)&n->next = *nl;
87402 rcu_assign_pointer(*nl, n);
87403 + pax_close_kernel();
87404 return 0;
87405 }
87406
87407 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
87408 return 0;
87409 if (n->priority > (*nl)->priority)
87410 break;
87411 - nl = &((*nl)->next);
87412 + nl = (struct notifier_block **)&((*nl)->next);
87413 }
87414 - n->next = *nl;
87415 + pax_open_kernel();
87416 + *(const void **)&n->next = *nl;
87417 rcu_assign_pointer(*nl, n);
87418 + pax_close_kernel();
87419 return 0;
87420 }
87421
87422 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
87423 {
87424 while ((*nl) != NULL) {
87425 if ((*nl) == n) {
87426 + pax_open_kernel();
87427 rcu_assign_pointer(*nl, n->next);
87428 + pax_close_kernel();
87429 return 0;
87430 }
87431 - nl = &((*nl)->next);
87432 + nl = (struct notifier_block **)&((*nl)->next);
87433 }
87434 return -ENOENT;
87435 }
87436 diff --git a/kernel/padata.c b/kernel/padata.c
87437 index 161402f..598814c 100644
87438 --- a/kernel/padata.c
87439 +++ b/kernel/padata.c
87440 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
87441 * seq_nr mod. number of cpus in use.
87442 */
87443
87444 - seq_nr = atomic_inc_return(&pd->seq_nr);
87445 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
87446 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
87447
87448 return padata_index_to_cpu(pd, cpu_index);
87449 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
87450 padata_init_pqueues(pd);
87451 padata_init_squeues(pd);
87452 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
87453 - atomic_set(&pd->seq_nr, -1);
87454 + atomic_set_unchecked(&pd->seq_nr, -1);
87455 atomic_set(&pd->reorder_objects, 0);
87456 atomic_set(&pd->refcnt, 0);
87457 pd->pinst = pinst;
87458 diff --git a/kernel/panic.c b/kernel/panic.c
87459 index 6d63003..486a109 100644
87460 --- a/kernel/panic.c
87461 +++ b/kernel/panic.c
87462 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
87463 /*
87464 * Stop ourself in panic -- architecture code may override this
87465 */
87466 -void __weak panic_smp_self_stop(void)
87467 +void __weak __noreturn panic_smp_self_stop(void)
87468 {
87469 while (1)
87470 cpu_relax();
87471 @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
87472 disable_trace_on_warning();
87473
87474 pr_warn("------------[ cut here ]------------\n");
87475 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
87476 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
87477 raw_smp_processor_id(), current->pid, file, line, caller);
87478
87479 if (args)
87480 @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
87481 */
87482 void __stack_chk_fail(void)
87483 {
87484 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
87485 + dump_stack();
87486 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
87487 __builtin_return_address(0));
87488 }
87489 EXPORT_SYMBOL(__stack_chk_fail);
87490 diff --git a/kernel/pid.c b/kernel/pid.c
87491 index 9b9a266..c20ef80 100644
87492 --- a/kernel/pid.c
87493 +++ b/kernel/pid.c
87494 @@ -33,6 +33,7 @@
87495 #include <linux/rculist.h>
87496 #include <linux/bootmem.h>
87497 #include <linux/hash.h>
87498 +#include <linux/security.h>
87499 #include <linux/pid_namespace.h>
87500 #include <linux/init_task.h>
87501 #include <linux/syscalls.h>
87502 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
87503
87504 int pid_max = PID_MAX_DEFAULT;
87505
87506 -#define RESERVED_PIDS 300
87507 +#define RESERVED_PIDS 500
87508
87509 int pid_max_min = RESERVED_PIDS + 1;
87510 int pid_max_max = PID_MAX_LIMIT;
87511 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
87512 */
87513 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
87514 {
87515 + struct task_struct *task;
87516 +
87517 rcu_lockdep_assert(rcu_read_lock_held(),
87518 "find_task_by_pid_ns() needs rcu_read_lock()"
87519 " protection");
87520 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87521 +
87522 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87523 +
87524 + if (gr_pid_is_chrooted(task))
87525 + return NULL;
87526 +
87527 + return task;
87528 }
87529
87530 struct task_struct *find_task_by_vpid(pid_t vnr)
87531 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
87532 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
87533 }
87534
87535 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
87536 +{
87537 + rcu_lockdep_assert(rcu_read_lock_held(),
87538 + "find_task_by_pid_ns() needs rcu_read_lock()"
87539 + " protection");
87540 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
87541 +}
87542 +
87543 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
87544 {
87545 struct pid *pid;
87546 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
87547 index 06c62de..a0ca23f 100644
87548 --- a/kernel/pid_namespace.c
87549 +++ b/kernel/pid_namespace.c
87550 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
87551 void __user *buffer, size_t *lenp, loff_t *ppos)
87552 {
87553 struct pid_namespace *pid_ns = task_active_pid_ns(current);
87554 - struct ctl_table tmp = *table;
87555 + ctl_table_no_const tmp = *table;
87556
87557 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
87558 return -EPERM;
87559 @@ -318,7 +318,9 @@ static void *pidns_get(struct task_struct *task)
87560 struct pid_namespace *ns;
87561
87562 rcu_read_lock();
87563 - ns = get_pid_ns(task_active_pid_ns(task));
87564 + ns = task_active_pid_ns(task);
87565 + if (ns)
87566 + get_pid_ns(ns);
87567 rcu_read_unlock();
87568
87569 return ns;
87570 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
87571 index 3b89464..5e38379 100644
87572 --- a/kernel/posix-cpu-timers.c
87573 +++ b/kernel/posix-cpu-timers.c
87574 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
87575
87576 static __init int init_posix_cpu_timers(void)
87577 {
87578 - struct k_clock process = {
87579 + static struct k_clock process = {
87580 .clock_getres = process_cpu_clock_getres,
87581 .clock_get = process_cpu_clock_get,
87582 .timer_create = process_cpu_timer_create,
87583 .nsleep = process_cpu_nsleep,
87584 .nsleep_restart = process_cpu_nsleep_restart,
87585 };
87586 - struct k_clock thread = {
87587 + static struct k_clock thread = {
87588 .clock_getres = thread_cpu_clock_getres,
87589 .clock_get = thread_cpu_clock_get,
87590 .timer_create = thread_cpu_timer_create,
87591 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
87592 index 424c2d4..679242f 100644
87593 --- a/kernel/posix-timers.c
87594 +++ b/kernel/posix-timers.c
87595 @@ -43,6 +43,7 @@
87596 #include <linux/hash.h>
87597 #include <linux/posix-clock.h>
87598 #include <linux/posix-timers.h>
87599 +#include <linux/grsecurity.h>
87600 #include <linux/syscalls.h>
87601 #include <linux/wait.h>
87602 #include <linux/workqueue.h>
87603 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
87604 * which we beg off on and pass to do_sys_settimeofday().
87605 */
87606
87607 -static struct k_clock posix_clocks[MAX_CLOCKS];
87608 +static struct k_clock *posix_clocks[MAX_CLOCKS];
87609
87610 /*
87611 * These ones are defined below.
87612 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
87613 */
87614 static __init int init_posix_timers(void)
87615 {
87616 - struct k_clock clock_realtime = {
87617 + static struct k_clock clock_realtime = {
87618 .clock_getres = hrtimer_get_res,
87619 .clock_get = posix_clock_realtime_get,
87620 .clock_set = posix_clock_realtime_set,
87621 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
87622 .timer_get = common_timer_get,
87623 .timer_del = common_timer_del,
87624 };
87625 - struct k_clock clock_monotonic = {
87626 + static struct k_clock clock_monotonic = {
87627 .clock_getres = hrtimer_get_res,
87628 .clock_get = posix_ktime_get_ts,
87629 .nsleep = common_nsleep,
87630 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
87631 .timer_get = common_timer_get,
87632 .timer_del = common_timer_del,
87633 };
87634 - struct k_clock clock_monotonic_raw = {
87635 + static struct k_clock clock_monotonic_raw = {
87636 .clock_getres = hrtimer_get_res,
87637 .clock_get = posix_get_monotonic_raw,
87638 };
87639 - struct k_clock clock_realtime_coarse = {
87640 + static struct k_clock clock_realtime_coarse = {
87641 .clock_getres = posix_get_coarse_res,
87642 .clock_get = posix_get_realtime_coarse,
87643 };
87644 - struct k_clock clock_monotonic_coarse = {
87645 + static struct k_clock clock_monotonic_coarse = {
87646 .clock_getres = posix_get_coarse_res,
87647 .clock_get = posix_get_monotonic_coarse,
87648 };
87649 - struct k_clock clock_tai = {
87650 + static struct k_clock clock_tai = {
87651 .clock_getres = hrtimer_get_res,
87652 .clock_get = posix_get_tai,
87653 .nsleep = common_nsleep,
87654 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
87655 .timer_get = common_timer_get,
87656 .timer_del = common_timer_del,
87657 };
87658 - struct k_clock clock_boottime = {
87659 + static struct k_clock clock_boottime = {
87660 .clock_getres = hrtimer_get_res,
87661 .clock_get = posix_get_boottime,
87662 .nsleep = common_nsleep,
87663 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
87664 return;
87665 }
87666
87667 - posix_clocks[clock_id] = *new_clock;
87668 + posix_clocks[clock_id] = new_clock;
87669 }
87670 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
87671
87672 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
87673 return (id & CLOCKFD_MASK) == CLOCKFD ?
87674 &clock_posix_dynamic : &clock_posix_cpu;
87675
87676 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
87677 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
87678 return NULL;
87679 - return &posix_clocks[id];
87680 + return posix_clocks[id];
87681 }
87682
87683 static int common_timer_create(struct k_itimer *new_timer)
87684 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
87685 struct k_clock *kc = clockid_to_kclock(which_clock);
87686 struct k_itimer *new_timer;
87687 int error, new_timer_id;
87688 - sigevent_t event;
87689 + sigevent_t event = { };
87690 int it_id_set = IT_ID_NOT_SET;
87691
87692 if (!kc)
87693 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
87694 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
87695 return -EFAULT;
87696
87697 + /* only the CLOCK_REALTIME clock can be set, all other clocks
87698 + have their clock_set fptr set to a nosettime dummy function
87699 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
87700 + call common_clock_set, which calls do_sys_settimeofday, which
87701 + we hook
87702 + */
87703 +
87704 return kc->clock_set(which_clock, &new_tp);
87705 }
87706
87707 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
87708 index 2fac9cc..56fef29 100644
87709 --- a/kernel/power/Kconfig
87710 +++ b/kernel/power/Kconfig
87711 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
87712 config HIBERNATION
87713 bool "Hibernation (aka 'suspend to disk')"
87714 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
87715 + depends on !GRKERNSEC_KMEM
87716 + depends on !PAX_MEMORY_SANITIZE
87717 select HIBERNATE_CALLBACKS
87718 select LZO_COMPRESS
87719 select LZO_DECOMPRESS
87720 diff --git a/kernel/power/process.c b/kernel/power/process.c
87721 index 06ec886..9dba35e 100644
87722 --- a/kernel/power/process.c
87723 +++ b/kernel/power/process.c
87724 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
87725 unsigned int elapsed_msecs;
87726 bool wakeup = false;
87727 int sleep_usecs = USEC_PER_MSEC;
87728 + bool timedout = false;
87729
87730 do_gettimeofday(&start);
87731
87732 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
87733
87734 while (true) {
87735 todo = 0;
87736 + if (time_after(jiffies, end_time))
87737 + timedout = true;
87738 read_lock(&tasklist_lock);
87739 do_each_thread(g, p) {
87740 if (p == current || !freeze_task(p))
87741 continue;
87742
87743 - if (!freezer_should_skip(p))
87744 + if (!freezer_should_skip(p)) {
87745 todo++;
87746 + if (timedout) {
87747 + printk(KERN_ERR "Task refusing to freeze:\n");
87748 + sched_show_task(p);
87749 + }
87750 + }
87751 } while_each_thread(g, p);
87752 read_unlock(&tasklist_lock);
87753
87754 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
87755 todo += wq_busy;
87756 }
87757
87758 - if (!todo || time_after(jiffies, end_time))
87759 + if (!todo || timedout)
87760 break;
87761
87762 if (pm_wakeup_pending()) {
87763 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
87764 index 4dae9cb..039ffbb 100644
87765 --- a/kernel/printk/printk.c
87766 +++ b/kernel/printk/printk.c
87767 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
87768 if (from_file && type != SYSLOG_ACTION_OPEN)
87769 return 0;
87770
87771 +#ifdef CONFIG_GRKERNSEC_DMESG
87772 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
87773 + return -EPERM;
87774 +#endif
87775 +
87776 if (syslog_action_restricted(type)) {
87777 if (capable(CAP_SYSLOG))
87778 return 0;
87779 diff --git a/kernel/profile.c b/kernel/profile.c
87780 index ebdd9c1..612ee05 100644
87781 --- a/kernel/profile.c
87782 +++ b/kernel/profile.c
87783 @@ -37,7 +37,7 @@ struct profile_hit {
87784 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
87785 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
87786
87787 -static atomic_t *prof_buffer;
87788 +static atomic_unchecked_t *prof_buffer;
87789 static unsigned long prof_len, prof_shift;
87790
87791 int prof_on __read_mostly;
87792 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
87793 hits[i].pc = 0;
87794 continue;
87795 }
87796 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87797 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87798 hits[i].hits = hits[i].pc = 0;
87799 }
87800 }
87801 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87802 * Add the current hit(s) and flush the write-queue out
87803 * to the global buffer:
87804 */
87805 - atomic_add(nr_hits, &prof_buffer[pc]);
87806 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
87807 for (i = 0; i < NR_PROFILE_HIT; ++i) {
87808 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87809 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87810 hits[i].pc = hits[i].hits = 0;
87811 }
87812 out:
87813 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87814 {
87815 unsigned long pc;
87816 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
87817 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87818 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87819 }
87820 #endif /* !CONFIG_SMP */
87821
87822 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
87823 return -EFAULT;
87824 buf++; p++; count--; read++;
87825 }
87826 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
87827 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
87828 if (copy_to_user(buf, (void *)pnt, count))
87829 return -EFAULT;
87830 read += count;
87831 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
87832 }
87833 #endif
87834 profile_discard_flip_buffers();
87835 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
87836 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
87837 return count;
87838 }
87839
87840 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
87841 index 1f4bcb3..99cf7ab 100644
87842 --- a/kernel/ptrace.c
87843 +++ b/kernel/ptrace.c
87844 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
87845 if (seize)
87846 flags |= PT_SEIZED;
87847 rcu_read_lock();
87848 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87849 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87850 flags |= PT_PTRACE_CAP;
87851 rcu_read_unlock();
87852 task->ptrace = flags;
87853 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
87854 break;
87855 return -EIO;
87856 }
87857 - if (copy_to_user(dst, buf, retval))
87858 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
87859 return -EFAULT;
87860 copied += retval;
87861 src += retval;
87862 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
87863 bool seized = child->ptrace & PT_SEIZED;
87864 int ret = -EIO;
87865 siginfo_t siginfo, *si;
87866 - void __user *datavp = (void __user *) data;
87867 + void __user *datavp = (__force void __user *) data;
87868 unsigned long __user *datalp = datavp;
87869 unsigned long flags;
87870
87871 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
87872 goto out;
87873 }
87874
87875 + if (gr_handle_ptrace(child, request)) {
87876 + ret = -EPERM;
87877 + goto out_put_task_struct;
87878 + }
87879 +
87880 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
87881 ret = ptrace_attach(child, request, addr, data);
87882 /*
87883 * Some architectures need to do book-keeping after
87884 * a ptrace attach.
87885 */
87886 - if (!ret)
87887 + if (!ret) {
87888 arch_ptrace_attach(child);
87889 + gr_audit_ptrace(child);
87890 + }
87891 goto out_put_task_struct;
87892 }
87893
87894 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
87895 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
87896 if (copied != sizeof(tmp))
87897 return -EIO;
87898 - return put_user(tmp, (unsigned long __user *)data);
87899 + return put_user(tmp, (__force unsigned long __user *)data);
87900 }
87901
87902 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
87903 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
87904 }
87905
87906 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
87907 - compat_long_t addr, compat_long_t data)
87908 + compat_ulong_t addr, compat_ulong_t data)
87909 {
87910 struct task_struct *child;
87911 long ret;
87912 @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
87913 goto out;
87914 }
87915
87916 + if (gr_handle_ptrace(child, request)) {
87917 + ret = -EPERM;
87918 + goto out_put_task_struct;
87919 + }
87920 +
87921 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
87922 ret = ptrace_attach(child, request, addr, data);
87923 /*
87924 * Some architectures need to do book-keeping after
87925 * a ptrace attach.
87926 */
87927 - if (!ret)
87928 + if (!ret) {
87929 arch_ptrace_attach(child);
87930 + gr_audit_ptrace(child);
87931 + }
87932 goto out_put_task_struct;
87933 }
87934
87935 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
87936 index 3318d82..1a5b2d1 100644
87937 --- a/kernel/rcu/srcu.c
87938 +++ b/kernel/rcu/srcu.c
87939 @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
87940
87941 idx = ACCESS_ONCE(sp->completed) & 0x1;
87942 preempt_disable();
87943 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87944 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87945 smp_mb(); /* B */ /* Avoid leaking the critical section. */
87946 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87947 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87948 preempt_enable();
87949 return idx;
87950 }
87951 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
87952 index 1254f31..16258dc 100644
87953 --- a/kernel/rcu/tiny.c
87954 +++ b/kernel/rcu/tiny.c
87955 @@ -46,7 +46,7 @@
87956 /* Forward declarations for tiny_plugin.h. */
87957 struct rcu_ctrlblk;
87958 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
87959 -static void rcu_process_callbacks(struct softirq_action *unused);
87960 +static void rcu_process_callbacks(void);
87961 static void __call_rcu(struct rcu_head *head,
87962 void (*func)(struct rcu_head *rcu),
87963 struct rcu_ctrlblk *rcp);
87964 @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
87965 false));
87966 }
87967
87968 -static void rcu_process_callbacks(struct softirq_action *unused)
87969 +static __latent_entropy void rcu_process_callbacks(void)
87970 {
87971 __rcu_process_callbacks(&rcu_sched_ctrlblk);
87972 __rcu_process_callbacks(&rcu_bh_ctrlblk);
87973 diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
87974 index 732f8ae..9984c27 100644
87975 --- a/kernel/rcu/torture.c
87976 +++ b/kernel/rcu/torture.c
87977 @@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
87978 { 0 };
87979 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
87980 { 0 };
87981 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
87982 -static atomic_t n_rcu_torture_alloc;
87983 -static atomic_t n_rcu_torture_alloc_fail;
87984 -static atomic_t n_rcu_torture_free;
87985 -static atomic_t n_rcu_torture_mberror;
87986 -static atomic_t n_rcu_torture_error;
87987 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
87988 +static atomic_unchecked_t n_rcu_torture_alloc;
87989 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
87990 +static atomic_unchecked_t n_rcu_torture_free;
87991 +static atomic_unchecked_t n_rcu_torture_mberror;
87992 +static atomic_unchecked_t n_rcu_torture_error;
87993 static long n_rcu_torture_barrier_error;
87994 static long n_rcu_torture_boost_ktrerror;
87995 static long n_rcu_torture_boost_rterror;
87996 @@ -297,11 +297,11 @@ rcu_torture_alloc(void)
87997
87998 spin_lock_bh(&rcu_torture_lock);
87999 if (list_empty(&rcu_torture_freelist)) {
88000 - atomic_inc(&n_rcu_torture_alloc_fail);
88001 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88002 spin_unlock_bh(&rcu_torture_lock);
88003 return NULL;
88004 }
88005 - atomic_inc(&n_rcu_torture_alloc);
88006 + atomic_inc_unchecked(&n_rcu_torture_alloc);
88007 p = rcu_torture_freelist.next;
88008 list_del_init(p);
88009 spin_unlock_bh(&rcu_torture_lock);
88010 @@ -314,7 +314,7 @@ rcu_torture_alloc(void)
88011 static void
88012 rcu_torture_free(struct rcu_torture *p)
88013 {
88014 - atomic_inc(&n_rcu_torture_free);
88015 + atomic_inc_unchecked(&n_rcu_torture_free);
88016 spin_lock_bh(&rcu_torture_lock);
88017 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88018 spin_unlock_bh(&rcu_torture_lock);
88019 @@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
88020 i = rp->rtort_pipe_count;
88021 if (i > RCU_TORTURE_PIPE_LEN)
88022 i = RCU_TORTURE_PIPE_LEN;
88023 - atomic_inc(&rcu_torture_wcount[i]);
88024 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88025 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88026 rp->rtort_mbtest = 0;
88027 rcu_torture_free(rp);
88028 @@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
88029 i = old_rp->rtort_pipe_count;
88030 if (i > RCU_TORTURE_PIPE_LEN)
88031 i = RCU_TORTURE_PIPE_LEN;
88032 - atomic_inc(&rcu_torture_wcount[i]);
88033 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88034 old_rp->rtort_pipe_count++;
88035 if (gp_normal == gp_exp)
88036 exp = !!(rcu_random(&rand) & 0x80);
88037 @@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
88038 i = rp->rtort_pipe_count;
88039 if (i > RCU_TORTURE_PIPE_LEN)
88040 i = RCU_TORTURE_PIPE_LEN;
88041 - atomic_inc(&rcu_torture_wcount[i]);
88042 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
88043 if (++rp->rtort_pipe_count >=
88044 RCU_TORTURE_PIPE_LEN) {
88045 rp->rtort_mbtest = 0;
88046 @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
88047 return;
88048 }
88049 if (p->rtort_mbtest == 0)
88050 - atomic_inc(&n_rcu_torture_mberror);
88051 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88052 spin_lock(&rand_lock);
88053 cur_ops->read_delay(&rand);
88054 n_rcu_torture_timers++;
88055 @@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
88056 continue;
88057 }
88058 if (p->rtort_mbtest == 0)
88059 - atomic_inc(&n_rcu_torture_mberror);
88060 + atomic_inc_unchecked(&n_rcu_torture_mberror);
88061 cur_ops->read_delay(&rand);
88062 preempt_disable();
88063 pipe_count = p->rtort_pipe_count;
88064 @@ -1072,11 +1072,11 @@ rcu_torture_printk(char *page)
88065 rcu_torture_current,
88066 rcu_torture_current_version,
88067 list_empty(&rcu_torture_freelist),
88068 - atomic_read(&n_rcu_torture_alloc),
88069 - atomic_read(&n_rcu_torture_alloc_fail),
88070 - atomic_read(&n_rcu_torture_free));
88071 + atomic_read_unchecked(&n_rcu_torture_alloc),
88072 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88073 + atomic_read_unchecked(&n_rcu_torture_free));
88074 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
88075 - atomic_read(&n_rcu_torture_mberror),
88076 + atomic_read_unchecked(&n_rcu_torture_mberror),
88077 n_rcu_torture_boost_ktrerror,
88078 n_rcu_torture_boost_rterror);
88079 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
88080 @@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
88081 n_barrier_attempts,
88082 n_rcu_torture_barrier_error);
88083 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
88084 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88085 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88086 n_rcu_torture_barrier_error != 0 ||
88087 n_rcu_torture_boost_ktrerror != 0 ||
88088 n_rcu_torture_boost_rterror != 0 ||
88089 n_rcu_torture_boost_failure != 0 ||
88090 i > 1) {
88091 page += sprintf(page, "!!! ");
88092 - atomic_inc(&n_rcu_torture_error);
88093 + atomic_inc_unchecked(&n_rcu_torture_error);
88094 WARN_ON_ONCE(1);
88095 }
88096 page += sprintf(page, "Reader Pipe: ");
88097 @@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
88098 page += sprintf(page, "Free-Block Circulation: ");
88099 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88100 page += sprintf(page, " %d",
88101 - atomic_read(&rcu_torture_wcount[i]));
88102 + atomic_read_unchecked(&rcu_torture_wcount[i]));
88103 }
88104 page += sprintf(page, "\n");
88105 if (cur_ops->stats)
88106 @@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
88107
88108 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88109
88110 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88111 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88112 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88113 else if (n_online_successes != n_online_attempts ||
88114 n_offline_successes != n_offline_attempts)
88115 @@ -1961,18 +1961,18 @@ rcu_torture_init(void)
88116
88117 rcu_torture_current = NULL;
88118 rcu_torture_current_version = 0;
88119 - atomic_set(&n_rcu_torture_alloc, 0);
88120 - atomic_set(&n_rcu_torture_alloc_fail, 0);
88121 - atomic_set(&n_rcu_torture_free, 0);
88122 - atomic_set(&n_rcu_torture_mberror, 0);
88123 - atomic_set(&n_rcu_torture_error, 0);
88124 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88125 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88126 + atomic_set_unchecked(&n_rcu_torture_free, 0);
88127 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88128 + atomic_set_unchecked(&n_rcu_torture_error, 0);
88129 n_rcu_torture_barrier_error = 0;
88130 n_rcu_torture_boost_ktrerror = 0;
88131 n_rcu_torture_boost_rterror = 0;
88132 n_rcu_torture_boost_failure = 0;
88133 n_rcu_torture_boosts = 0;
88134 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88135 - atomic_set(&rcu_torture_wcount[i], 0);
88136 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88137 for_each_possible_cpu(cpu) {
88138 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88139 per_cpu(rcu_torture_count, cpu)[i] = 0;
88140 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88141 index b3d116c..ebf6598 100644
88142 --- a/kernel/rcu/tree.c
88143 +++ b/kernel/rcu/tree.c
88144 @@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88145 rcu_prepare_for_idle(smp_processor_id());
88146 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88147 smp_mb__before_atomic_inc(); /* See above. */
88148 - atomic_inc(&rdtp->dynticks);
88149 + atomic_inc_unchecked(&rdtp->dynticks);
88150 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88151 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88152 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88153
88154 /*
88155 * It is illegal to enter an extended quiescent state while
88156 @@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88157 int user)
88158 {
88159 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88160 - atomic_inc(&rdtp->dynticks);
88161 + atomic_inc_unchecked(&rdtp->dynticks);
88162 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88163 smp_mb__after_atomic_inc(); /* See above. */
88164 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88165 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88166 rcu_cleanup_after_idle(smp_processor_id());
88167 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88168 if (!user && !is_idle_task(current)) {
88169 @@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
88170 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88171
88172 if (rdtp->dynticks_nmi_nesting == 0 &&
88173 - (atomic_read(&rdtp->dynticks) & 0x1))
88174 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88175 return;
88176 rdtp->dynticks_nmi_nesting++;
88177 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88178 - atomic_inc(&rdtp->dynticks);
88179 + atomic_inc_unchecked(&rdtp->dynticks);
88180 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88181 smp_mb__after_atomic_inc(); /* See above. */
88182 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88183 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88184 }
88185
88186 /**
88187 @@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
88188 return;
88189 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88190 smp_mb__before_atomic_inc(); /* See above. */
88191 - atomic_inc(&rdtp->dynticks);
88192 + atomic_inc_unchecked(&rdtp->dynticks);
88193 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88194 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88195 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88196 }
88197
88198 /**
88199 @@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
88200 */
88201 bool notrace __rcu_is_watching(void)
88202 {
88203 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88204 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88205 }
88206
88207 /**
88208 @@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88209 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88210 bool *isidle, unsigned long *maxj)
88211 {
88212 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88213 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88214 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88215 return (rdp->dynticks_snap & 0x1) == 0;
88216 }
88217 @@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88218 unsigned int curr;
88219 unsigned int snap;
88220
88221 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88222 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88223 snap = (unsigned int)rdp->dynticks_snap;
88224
88225 /*
88226 @@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88227 rdp = this_cpu_ptr(rsp->rda);
88228 rcu_preempt_check_blocked_tasks(rnp);
88229 rnp->qsmask = rnp->qsmaskinit;
88230 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88231 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88232 WARN_ON_ONCE(rnp->completed != rsp->completed);
88233 - ACCESS_ONCE(rnp->completed) = rsp->completed;
88234 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88235 if (rnp == rdp->mynode)
88236 __note_gp_changes(rsp, rnp, rdp);
88237 rcu_preempt_boost_start_gp(rnp);
88238 @@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88239 rcu_for_each_node_breadth_first(rsp, rnp) {
88240 raw_spin_lock_irq(&rnp->lock);
88241 smp_mb__after_unlock_lock();
88242 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88243 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88244 rdp = this_cpu_ptr(rsp->rda);
88245 if (rnp == rdp->mynode)
88246 __note_gp_changes(rsp, rnp, rdp);
88247 @@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88248 rsp->qlen += rdp->qlen;
88249 rdp->n_cbs_orphaned += rdp->qlen;
88250 rdp->qlen_lazy = 0;
88251 - ACCESS_ONCE(rdp->qlen) = 0;
88252 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88253 }
88254
88255 /*
88256 @@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88257 }
88258 smp_mb(); /* List handling before counting for rcu_barrier(). */
88259 rdp->qlen_lazy -= count_lazy;
88260 - ACCESS_ONCE(rdp->qlen) -= count;
88261 + ACCESS_ONCE_RW(rdp->qlen) -= count;
88262 rdp->n_cbs_invoked += count;
88263
88264 /* Reinstate batch limit if we have worked down the excess. */
88265 @@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88266 /*
88267 * Do RCU core processing for the current CPU.
88268 */
88269 -static void rcu_process_callbacks(struct softirq_action *unused)
88270 +static void rcu_process_callbacks(void)
88271 {
88272 struct rcu_state *rsp;
88273
88274 @@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88275 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88276 if (debug_rcu_head_queue(head)) {
88277 /* Probable double call_rcu(), so leak the callback. */
88278 - ACCESS_ONCE(head->func) = rcu_leak_callback;
88279 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88280 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88281 return;
88282 }
88283 @@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88284 local_irq_restore(flags);
88285 return;
88286 }
88287 - ACCESS_ONCE(rdp->qlen)++;
88288 + ACCESS_ONCE_RW(rdp->qlen)++;
88289 if (lazy)
88290 rdp->qlen_lazy++;
88291 else
88292 @@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
88293 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88294 * course be required on a 64-bit system.
88295 */
88296 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88297 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88298 (ulong)atomic_long_read(&rsp->expedited_done) +
88299 ULONG_MAX / 8)) {
88300 synchronize_sched();
88301 - atomic_long_inc(&rsp->expedited_wrap);
88302 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
88303 return;
88304 }
88305
88306 @@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
88307 * Take a ticket. Note that atomic_inc_return() implies a
88308 * full memory barrier.
88309 */
88310 - snap = atomic_long_inc_return(&rsp->expedited_start);
88311 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88312 firstsnap = snap;
88313 get_online_cpus();
88314 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88315 @@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
88316 synchronize_sched_expedited_cpu_stop,
88317 NULL) == -EAGAIN) {
88318 put_online_cpus();
88319 - atomic_long_inc(&rsp->expedited_tryfail);
88320 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88321
88322 /* Check to see if someone else did our work for us. */
88323 s = atomic_long_read(&rsp->expedited_done);
88324 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88325 /* ensure test happens before caller kfree */
88326 smp_mb__before_atomic_inc(); /* ^^^ */
88327 - atomic_long_inc(&rsp->expedited_workdone1);
88328 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
88329 return;
88330 }
88331
88332 @@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
88333 udelay(trycount * num_online_cpus());
88334 } else {
88335 wait_rcu_gp(call_rcu_sched);
88336 - atomic_long_inc(&rsp->expedited_normal);
88337 + atomic_long_inc_unchecked(&rsp->expedited_normal);
88338 return;
88339 }
88340
88341 @@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
88342 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88343 /* ensure test happens before caller kfree */
88344 smp_mb__before_atomic_inc(); /* ^^^ */
88345 - atomic_long_inc(&rsp->expedited_workdone2);
88346 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
88347 return;
88348 }
88349
88350 @@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
88351 * period works for us.
88352 */
88353 get_online_cpus();
88354 - snap = atomic_long_read(&rsp->expedited_start);
88355 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
88356 smp_mb(); /* ensure read is before try_stop_cpus(). */
88357 }
88358 - atomic_long_inc(&rsp->expedited_stoppedcpus);
88359 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
88360
88361 /*
88362 * Everyone up to our most recent fetch is covered by our grace
88363 @@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
88364 * than we did already did their update.
88365 */
88366 do {
88367 - atomic_long_inc(&rsp->expedited_done_tries);
88368 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
88369 s = atomic_long_read(&rsp->expedited_done);
88370 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
88371 /* ensure test happens before caller kfree */
88372 smp_mb__before_atomic_inc(); /* ^^^ */
88373 - atomic_long_inc(&rsp->expedited_done_lost);
88374 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
88375 break;
88376 }
88377 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
88378 - atomic_long_inc(&rsp->expedited_done_exit);
88379 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
88380
88381 put_online_cpus();
88382 }
88383 @@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88384 * ACCESS_ONCE() to prevent the compiler from speculating
88385 * the increment to precede the early-exit check.
88386 */
88387 - ACCESS_ONCE(rsp->n_barrier_done)++;
88388 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88389 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
88390 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
88391 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
88392 @@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88393
88394 /* Increment ->n_barrier_done to prevent duplicate work. */
88395 smp_mb(); /* Keep increment after above mechanism. */
88396 - ACCESS_ONCE(rsp->n_barrier_done)++;
88397 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88398 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
88399 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
88400 smp_mb(); /* Keep increment before caller's subsequent code. */
88401 @@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
88402 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
88403 init_callback_list(rdp);
88404 rdp->qlen_lazy = 0;
88405 - ACCESS_ONCE(rdp->qlen) = 0;
88406 + ACCESS_ONCE_RW(rdp->qlen) = 0;
88407 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
88408 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
88409 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
88410 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
88411 rdp->cpu = cpu;
88412 rdp->rsp = rsp;
88413 rcu_boot_init_nocb_percpu_data(rdp);
88414 @@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
88415 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
88416 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
88417 rcu_sysidle_init_percpu_data(rdp->dynticks);
88418 - atomic_set(&rdp->dynticks->dynticks,
88419 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
88420 + atomic_set_unchecked(&rdp->dynticks->dynticks,
88421 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
88422 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
88423
88424 /* Add CPU to rcu_node bitmasks. */
88425 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
88426 index 8c19873..bf83c57 100644
88427 --- a/kernel/rcu/tree.h
88428 +++ b/kernel/rcu/tree.h
88429 @@ -87,11 +87,11 @@ struct rcu_dynticks {
88430 long long dynticks_nesting; /* Track irq/process nesting level. */
88431 /* Process level is worth LLONG_MAX/2. */
88432 int dynticks_nmi_nesting; /* Track NMI nesting level. */
88433 - atomic_t dynticks; /* Even value for idle, else odd. */
88434 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
88435 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
88436 long long dynticks_idle_nesting;
88437 /* irq/process nesting level from idle. */
88438 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
88439 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
88440 /* "Idle" excludes userspace execution. */
88441 unsigned long dynticks_idle_jiffies;
88442 /* End of last non-NMI non-idle period. */
88443 @@ -431,17 +431,17 @@ struct rcu_state {
88444 /* _rcu_barrier(). */
88445 /* End of fields guarded by barrier_mutex. */
88446
88447 - atomic_long_t expedited_start; /* Starting ticket. */
88448 - atomic_long_t expedited_done; /* Done ticket. */
88449 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
88450 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
88451 - atomic_long_t expedited_workdone1; /* # done by others #1. */
88452 - atomic_long_t expedited_workdone2; /* # done by others #2. */
88453 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
88454 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
88455 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
88456 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
88457 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
88458 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
88459 + atomic_long_t expedited_done; /* Done ticket. */
88460 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
88461 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
88462 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
88463 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
88464 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
88465 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
88466 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
88467 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
88468 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
88469
88470 unsigned long jiffies_force_qs; /* Time at which to invoke */
88471 /* force_quiescent_state(). */
88472 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
88473 index 6e2ef4b..c15df94 100644
88474 --- a/kernel/rcu/tree_plugin.h
88475 +++ b/kernel/rcu/tree_plugin.h
88476 @@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
88477 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
88478 {
88479 return !rcu_preempted_readers_exp(rnp) &&
88480 - ACCESS_ONCE(rnp->expmask) == 0;
88481 + ACCESS_ONCE_RW(rnp->expmask) == 0;
88482 }
88483
88484 /*
88485 @@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
88486
88487 /* Clean up and exit. */
88488 smp_mb(); /* ensure expedited GP seen before counter increment. */
88489 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
88490 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
88491 unlock_mb_ret:
88492 mutex_unlock(&sync_rcu_preempt_exp_mutex);
88493 mb_ret:
88494 @@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
88495 free_cpumask_var(cm);
88496 }
88497
88498 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
88499 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
88500 .store = &rcu_cpu_kthread_task,
88501 .thread_should_run = rcu_cpu_kthread_should_run,
88502 .thread_fn = rcu_cpu_kthread,
88503 @@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
88504 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
88505 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
88506 cpu, ticks_value, ticks_title,
88507 - atomic_read(&rdtp->dynticks) & 0xfff,
88508 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
88509 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
88510 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
88511 fast_no_hz);
88512 @@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
88513
88514 /* Enqueue the callback on the nocb list and update counts. */
88515 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
88516 - ACCESS_ONCE(*old_rhpp) = rhp;
88517 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
88518 atomic_long_add(rhcount, &rdp->nocb_q_count);
88519 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
88520
88521 @@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
88522 * Extract queued callbacks, update counts, and wait
88523 * for a grace period to elapse.
88524 */
88525 - ACCESS_ONCE(rdp->nocb_head) = NULL;
88526 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
88527 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
88528 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
88529 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
88530 - ACCESS_ONCE(rdp->nocb_p_count) += c;
88531 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
88532 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
88533 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
88534 rcu_nocb_wait_gp(rdp);
88535
88536 /* Each pass through the following loop invokes a callback. */
88537 @@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
88538 list = next;
88539 }
88540 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
88541 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
88542 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
88543 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
88544 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
88545 rdp->n_nocbs_invoked += c;
88546 }
88547 return 0;
88548 @@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
88549 {
88550 if (!rcu_nocb_need_deferred_wakeup(rdp))
88551 return;
88552 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
88553 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
88554 wake_up(&rdp->nocb_wq);
88555 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
88556 }
88557 @@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
88558 t = kthread_run(rcu_nocb_kthread, rdp,
88559 "rcuo%c/%d", rsp->abbr, cpu);
88560 BUG_ON(IS_ERR(t));
88561 - ACCESS_ONCE(rdp->nocb_kthread) = t;
88562 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
88563 }
88564 }
88565
88566 @@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
88567
88568 /* Record start of fully idle period. */
88569 j = jiffies;
88570 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
88571 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
88572 smp_mb__before_atomic_inc();
88573 - atomic_inc(&rdtp->dynticks_idle);
88574 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88575 smp_mb__after_atomic_inc();
88576 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
88577 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
88578 }
88579
88580 /*
88581 @@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
88582
88583 /* Record end of idle period. */
88584 smp_mb__before_atomic_inc();
88585 - atomic_inc(&rdtp->dynticks_idle);
88586 + atomic_inc_unchecked(&rdtp->dynticks_idle);
88587 smp_mb__after_atomic_inc();
88588 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
88589 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
88590
88591 /*
88592 * If we are the timekeeping CPU, we are permitted to be non-idle
88593 @@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
88594 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
88595
88596 /* Pick up current idle and NMI-nesting counter and check. */
88597 - cur = atomic_read(&rdtp->dynticks_idle);
88598 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
88599 if (cur & 0x1) {
88600 *isidle = false; /* We are not idle! */
88601 return;
88602 @@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
88603 case RCU_SYSIDLE_NOT:
88604
88605 /* First time all are idle, so note a short idle period. */
88606 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88607 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88608 break;
88609
88610 case RCU_SYSIDLE_SHORT:
88611 @@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
88612 static void rcu_sysidle_cancel(void)
88613 {
88614 smp_mb();
88615 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
88616 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
88617 }
88618
88619 /*
88620 @@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
88621 smp_mb(); /* grace period precedes setting inuse. */
88622
88623 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
88624 - ACCESS_ONCE(rshp->inuse) = 0;
88625 + ACCESS_ONCE_RW(rshp->inuse) = 0;
88626 }
88627
88628 /*
88629 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
88630 index 4def475..8ffddde 100644
88631 --- a/kernel/rcu/tree_trace.c
88632 +++ b/kernel/rcu/tree_trace.c
88633 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
88634 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
88635 rdp->passed_quiesce, rdp->qs_pending);
88636 seq_printf(m, " dt=%d/%llx/%d df=%lu",
88637 - atomic_read(&rdp->dynticks->dynticks),
88638 + atomic_read_unchecked(&rdp->dynticks->dynticks),
88639 rdp->dynticks->dynticks_nesting,
88640 rdp->dynticks->dynticks_nmi_nesting,
88641 rdp->dynticks_fqs);
88642 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
88643 struct rcu_state *rsp = (struct rcu_state *)m->private;
88644
88645 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",
88646 - atomic_long_read(&rsp->expedited_start),
88647 + atomic_long_read_unchecked(&rsp->expedited_start),
88648 atomic_long_read(&rsp->expedited_done),
88649 - atomic_long_read(&rsp->expedited_wrap),
88650 - atomic_long_read(&rsp->expedited_tryfail),
88651 - atomic_long_read(&rsp->expedited_workdone1),
88652 - atomic_long_read(&rsp->expedited_workdone2),
88653 - atomic_long_read(&rsp->expedited_normal),
88654 - atomic_long_read(&rsp->expedited_stoppedcpus),
88655 - atomic_long_read(&rsp->expedited_done_tries),
88656 - atomic_long_read(&rsp->expedited_done_lost),
88657 - atomic_long_read(&rsp->expedited_done_exit));
88658 + atomic_long_read_unchecked(&rsp->expedited_wrap),
88659 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
88660 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
88661 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
88662 + atomic_long_read_unchecked(&rsp->expedited_normal),
88663 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
88664 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
88665 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
88666 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
88667 return 0;
88668 }
88669
88670 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
88671 index c54609f..2e8829c 100644
88672 --- a/kernel/rcu/update.c
88673 +++ b/kernel/rcu/update.c
88674 @@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
88675 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
88676 */
88677 if (till_stall_check < 3) {
88678 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
88679 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
88680 till_stall_check = 3;
88681 } else if (till_stall_check > 300) {
88682 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
88683 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
88684 till_stall_check = 300;
88685 }
88686 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
88687 diff --git a/kernel/resource.c b/kernel/resource.c
88688 index 3f285dc..5755f62 100644
88689 --- a/kernel/resource.c
88690 +++ b/kernel/resource.c
88691 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
88692
88693 static int __init ioresources_init(void)
88694 {
88695 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88696 +#ifdef CONFIG_GRKERNSEC_PROC_USER
88697 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
88698 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
88699 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88700 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
88701 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
88702 +#endif
88703 +#else
88704 proc_create("ioports", 0, NULL, &proc_ioports_operations);
88705 proc_create("iomem", 0, NULL, &proc_iomem_operations);
88706 +#endif
88707 return 0;
88708 }
88709 __initcall(ioresources_init);
88710 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
88711 index 4a07353..66b5291 100644
88712 --- a/kernel/sched/auto_group.c
88713 +++ b/kernel/sched/auto_group.c
88714 @@ -11,7 +11,7 @@
88715
88716 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
88717 static struct autogroup autogroup_default;
88718 -static atomic_t autogroup_seq_nr;
88719 +static atomic_unchecked_t autogroup_seq_nr;
88720
88721 void __init autogroup_init(struct task_struct *init_task)
88722 {
88723 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
88724
88725 kref_init(&ag->kref);
88726 init_rwsem(&ag->lock);
88727 - ag->id = atomic_inc_return(&autogroup_seq_nr);
88728 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
88729 ag->tg = tg;
88730 #ifdef CONFIG_RT_GROUP_SCHED
88731 /*
88732 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
88733 index a63f4dc..349bbb0 100644
88734 --- a/kernel/sched/completion.c
88735 +++ b/kernel/sched/completion.c
88736 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
88737 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88738 * or number of jiffies left till timeout) if completed.
88739 */
88740 -long __sched
88741 +long __sched __intentional_overflow(-1)
88742 wait_for_completion_interruptible_timeout(struct completion *x,
88743 unsigned long timeout)
88744 {
88745 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
88746 *
88747 * Return: -ERESTARTSYS if interrupted, 0 if completed.
88748 */
88749 -int __sched wait_for_completion_killable(struct completion *x)
88750 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
88751 {
88752 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
88753 if (t == -ERESTARTSYS)
88754 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
88755 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88756 * or number of jiffies left till timeout) if completed.
88757 */
88758 -long __sched
88759 +long __sched __intentional_overflow(-1)
88760 wait_for_completion_killable_timeout(struct completion *x,
88761 unsigned long timeout)
88762 {
88763 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
88764 index f5c6635..ab9f223 100644
88765 --- a/kernel/sched/core.c
88766 +++ b/kernel/sched/core.c
88767 @@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
88768 int sysctl_numa_balancing(struct ctl_table *table, int write,
88769 void __user *buffer, size_t *lenp, loff_t *ppos)
88770 {
88771 - struct ctl_table t;
88772 + ctl_table_no_const t;
88773 int err;
88774 int state = numabalancing_enabled;
88775
88776 @@ -3049,6 +3049,8 @@ int can_nice(const struct task_struct *p, const int nice)
88777 /* convert nice value [19,-20] to rlimit style value [1,40] */
88778 int nice_rlim = 20 - nice;
88779
88780 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
88781 +
88782 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
88783 capable(CAP_SYS_NICE));
88784 }
88785 @@ -3082,7 +3084,8 @@ SYSCALL_DEFINE1(nice, int, increment)
88786 if (nice > 19)
88787 nice = 19;
88788
88789 - if (increment < 0 && !can_nice(current, nice))
88790 + if (increment < 0 && (!can_nice(current, nice) ||
88791 + gr_handle_chroot_nice()))
88792 return -EPERM;
88793
88794 retval = security_task_setnice(current, nice);
88795 @@ -3332,6 +3335,7 @@ recheck:
88796 if (policy != p->policy && !rlim_rtprio)
88797 return -EPERM;
88798
88799 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
88800 /* can't increase priority */
88801 if (attr->sched_priority > p->rt_priority &&
88802 attr->sched_priority > rlim_rtprio)
88803 @@ -4781,7 +4785,7 @@ static void migrate_tasks(unsigned int dead_cpu)
88804
88805 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
88806
88807 -static struct ctl_table sd_ctl_dir[] = {
88808 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
88809 {
88810 .procname = "sched_domain",
88811 .mode = 0555,
88812 @@ -4798,17 +4802,17 @@ static struct ctl_table sd_ctl_root[] = {
88813 {}
88814 };
88815
88816 -static struct ctl_table *sd_alloc_ctl_entry(int n)
88817 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
88818 {
88819 - struct ctl_table *entry =
88820 + ctl_table_no_const *entry =
88821 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
88822
88823 return entry;
88824 }
88825
88826 -static void sd_free_ctl_entry(struct ctl_table **tablep)
88827 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
88828 {
88829 - struct ctl_table *entry;
88830 + ctl_table_no_const *entry;
88831
88832 /*
88833 * In the intermediate directories, both the child directory and
88834 @@ -4816,22 +4820,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
88835 * will always be set. In the lowest directory the names are
88836 * static strings and all have proc handlers.
88837 */
88838 - for (entry = *tablep; entry->mode; entry++) {
88839 - if (entry->child)
88840 - sd_free_ctl_entry(&entry->child);
88841 + for (entry = tablep; entry->mode; entry++) {
88842 + if (entry->child) {
88843 + sd_free_ctl_entry(entry->child);
88844 + pax_open_kernel();
88845 + entry->child = NULL;
88846 + pax_close_kernel();
88847 + }
88848 if (entry->proc_handler == NULL)
88849 kfree(entry->procname);
88850 }
88851
88852 - kfree(*tablep);
88853 - *tablep = NULL;
88854 + kfree(tablep);
88855 }
88856
88857 static int min_load_idx = 0;
88858 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
88859
88860 static void
88861 -set_table_entry(struct ctl_table *entry,
88862 +set_table_entry(ctl_table_no_const *entry,
88863 const char *procname, void *data, int maxlen,
88864 umode_t mode, proc_handler *proc_handler,
88865 bool load_idx)
88866 @@ -4851,7 +4858,7 @@ set_table_entry(struct ctl_table *entry,
88867 static struct ctl_table *
88868 sd_alloc_ctl_domain_table(struct sched_domain *sd)
88869 {
88870 - struct ctl_table *table = sd_alloc_ctl_entry(13);
88871 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
88872
88873 if (table == NULL)
88874 return NULL;
88875 @@ -4886,9 +4893,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
88876 return table;
88877 }
88878
88879 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
88880 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
88881 {
88882 - struct ctl_table *entry, *table;
88883 + ctl_table_no_const *entry, *table;
88884 struct sched_domain *sd;
88885 int domain_num = 0, i;
88886 char buf[32];
88887 @@ -4915,11 +4922,13 @@ static struct ctl_table_header *sd_sysctl_header;
88888 static void register_sched_domain_sysctl(void)
88889 {
88890 int i, cpu_num = num_possible_cpus();
88891 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
88892 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
88893 char buf[32];
88894
88895 WARN_ON(sd_ctl_dir[0].child);
88896 + pax_open_kernel();
88897 sd_ctl_dir[0].child = entry;
88898 + pax_close_kernel();
88899
88900 if (entry == NULL)
88901 return;
88902 @@ -4942,8 +4951,12 @@ static void unregister_sched_domain_sysctl(void)
88903 if (sd_sysctl_header)
88904 unregister_sysctl_table(sd_sysctl_header);
88905 sd_sysctl_header = NULL;
88906 - if (sd_ctl_dir[0].child)
88907 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
88908 + if (sd_ctl_dir[0].child) {
88909 + sd_free_ctl_entry(sd_ctl_dir[0].child);
88910 + pax_open_kernel();
88911 + sd_ctl_dir[0].child = NULL;
88912 + pax_close_kernel();
88913 + }
88914 }
88915 #else
88916 static void register_sched_domain_sysctl(void)
88917 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
88918 index 9b4c4f3..665489b 100644
88919 --- a/kernel/sched/fair.c
88920 +++ b/kernel/sched/fair.c
88921 @@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
88922
88923 static void reset_ptenuma_scan(struct task_struct *p)
88924 {
88925 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
88926 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
88927 p->mm->numa_scan_offset = 0;
88928 }
88929
88930 @@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
88931 * run_rebalance_domains is triggered when needed from the scheduler tick.
88932 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
88933 */
88934 -static void run_rebalance_domains(struct softirq_action *h)
88935 +static __latent_entropy void run_rebalance_domains(void)
88936 {
88937 struct rq *this_rq = this_rq();
88938 enum cpu_idle_type idle = this_rq->idle_balance ?
88939 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
88940 index f964add..dcd823d 100644
88941 --- a/kernel/sched/sched.h
88942 +++ b/kernel/sched/sched.h
88943 @@ -1157,7 +1157,7 @@ struct sched_class {
88944 #ifdef CONFIG_FAIR_GROUP_SCHED
88945 void (*task_move_group) (struct task_struct *p, int on_rq);
88946 #endif
88947 -};
88948 +} __do_const;
88949
88950 #define sched_class_highest (&stop_sched_class)
88951 #define for_each_class(class) \
88952 diff --git a/kernel/signal.c b/kernel/signal.c
88953 index 52f881d..1e9f941 100644
88954 --- a/kernel/signal.c
88955 +++ b/kernel/signal.c
88956 @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
88957
88958 int print_fatal_signals __read_mostly;
88959
88960 -static void __user *sig_handler(struct task_struct *t, int sig)
88961 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
88962 {
88963 return t->sighand->action[sig - 1].sa.sa_handler;
88964 }
88965
88966 -static int sig_handler_ignored(void __user *handler, int sig)
88967 +static int sig_handler_ignored(__sighandler_t handler, int sig)
88968 {
88969 /* Is it explicitly or implicitly ignored? */
88970 return handler == SIG_IGN ||
88971 @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
88972
88973 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
88974 {
88975 - void __user *handler;
88976 + __sighandler_t handler;
88977
88978 handler = sig_handler(t, sig);
88979
88980 @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
88981 atomic_inc(&user->sigpending);
88982 rcu_read_unlock();
88983
88984 + if (!override_rlimit)
88985 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
88986 +
88987 if (override_rlimit ||
88988 atomic_read(&user->sigpending) <=
88989 task_rlimit(t, RLIMIT_SIGPENDING)) {
88990 @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
88991
88992 int unhandled_signal(struct task_struct *tsk, int sig)
88993 {
88994 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
88995 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
88996 if (is_global_init(tsk))
88997 return 1;
88998 if (handler != SIG_IGN && handler != SIG_DFL)
88999 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89000 }
89001 }
89002
89003 + /* allow glibc communication via tgkill to other threads in our
89004 + thread group */
89005 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89006 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89007 + && gr_handle_signal(t, sig))
89008 + return -EPERM;
89009 +
89010 return security_task_kill(t, info, sig, 0);
89011 }
89012
89013 @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89014 return send_signal(sig, info, p, 1);
89015 }
89016
89017 -static int
89018 +int
89019 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89020 {
89021 return send_signal(sig, info, t, 0);
89022 @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89023 unsigned long int flags;
89024 int ret, blocked, ignored;
89025 struct k_sigaction *action;
89026 + int is_unhandled = 0;
89027
89028 spin_lock_irqsave(&t->sighand->siglock, flags);
89029 action = &t->sighand->action[sig-1];
89030 @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89031 }
89032 if (action->sa.sa_handler == SIG_DFL)
89033 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89034 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89035 + is_unhandled = 1;
89036 ret = specific_send_sig_info(sig, info, t);
89037 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89038
89039 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
89040 + normal operation */
89041 + if (is_unhandled) {
89042 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89043 + gr_handle_crash(t, sig);
89044 + }
89045 +
89046 return ret;
89047 }
89048
89049 @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89050 ret = check_kill_permission(sig, info, p);
89051 rcu_read_unlock();
89052
89053 - if (!ret && sig)
89054 + if (!ret && sig) {
89055 ret = do_send_sig_info(sig, info, p, true);
89056 + if (!ret)
89057 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89058 + }
89059
89060 return ret;
89061 }
89062 @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89063 int error = -ESRCH;
89064
89065 rcu_read_lock();
89066 - p = find_task_by_vpid(pid);
89067 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
89068 + /* allow glibc communication via tgkill to other threads in our
89069 + thread group */
89070 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
89071 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
89072 + p = find_task_by_vpid_unrestricted(pid);
89073 + else
89074 +#endif
89075 + p = find_task_by_vpid(pid);
89076 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
89077 error = check_kill_permission(sig, info, p);
89078 /*
89079 @@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
89080 }
89081 seg = get_fs();
89082 set_fs(KERNEL_DS);
89083 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
89084 - (stack_t __force __user *) &uoss,
89085 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
89086 + (stack_t __force_user *) &uoss,
89087 compat_user_stack_pointer());
89088 set_fs(seg);
89089 if (ret >= 0 && uoss_ptr) {
89090 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
89091 index eb89e18..a4e6792 100644
89092 --- a/kernel/smpboot.c
89093 +++ b/kernel/smpboot.c
89094 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
89095 }
89096 smpboot_unpark_thread(plug_thread, cpu);
89097 }
89098 - list_add(&plug_thread->list, &hotplug_threads);
89099 + pax_list_add(&plug_thread->list, &hotplug_threads);
89100 out:
89101 mutex_unlock(&smpboot_threads_lock);
89102 return ret;
89103 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
89104 {
89105 get_online_cpus();
89106 mutex_lock(&smpboot_threads_lock);
89107 - list_del(&plug_thread->list);
89108 + pax_list_del(&plug_thread->list);
89109 smpboot_destroy_threads(plug_thread);
89110 mutex_unlock(&smpboot_threads_lock);
89111 put_online_cpus();
89112 diff --git a/kernel/softirq.c b/kernel/softirq.c
89113 index 490fcbb..1e502c6 100644
89114 --- a/kernel/softirq.c
89115 +++ b/kernel/softirq.c
89116 @@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
89117 EXPORT_SYMBOL(irq_stat);
89118 #endif
89119
89120 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
89121 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
89122
89123 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89124
89125 @@ -267,7 +267,7 @@ restart:
89126 kstat_incr_softirqs_this_cpu(vec_nr);
89127
89128 trace_softirq_entry(vec_nr);
89129 - h->action(h);
89130 + h->action();
89131 trace_softirq_exit(vec_nr);
89132 if (unlikely(prev_count != preempt_count())) {
89133 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
89134 @@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89135 or_softirq_pending(1UL << nr);
89136 }
89137
89138 -void open_softirq(int nr, void (*action)(struct softirq_action *))
89139 +void __init open_softirq(int nr, void (*action)(void))
89140 {
89141 softirq_vec[nr].action = action;
89142 }
89143 @@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89144 }
89145 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89146
89147 -static void tasklet_action(struct softirq_action *a)
89148 +static void tasklet_action(void)
89149 {
89150 struct tasklet_struct *list;
89151
89152 @@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
89153 }
89154 }
89155
89156 -static void tasklet_hi_action(struct softirq_action *a)
89157 +static __latent_entropy void tasklet_hi_action(void)
89158 {
89159 struct tasklet_struct *list;
89160
89161 @@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
89162 .notifier_call = cpu_callback
89163 };
89164
89165 -static struct smp_hotplug_thread softirq_threads = {
89166 +static struct smp_hotplug_thread softirq_threads __read_only = {
89167 .store = &ksoftirqd,
89168 .thread_should_run = ksoftirqd_should_run,
89169 .thread_fn = run_ksoftirqd,
89170 diff --git a/kernel/sys.c b/kernel/sys.c
89171 index c0a58be..784c618 100644
89172 --- a/kernel/sys.c
89173 +++ b/kernel/sys.c
89174 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89175 error = -EACCES;
89176 goto out;
89177 }
89178 +
89179 + if (gr_handle_chroot_setpriority(p, niceval)) {
89180 + error = -EACCES;
89181 + goto out;
89182 + }
89183 +
89184 no_nice = security_task_setnice(p, niceval);
89185 if (no_nice) {
89186 error = no_nice;
89187 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89188 goto error;
89189 }
89190
89191 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89192 + goto error;
89193 +
89194 if (rgid != (gid_t) -1 ||
89195 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89196 new->sgid = new->egid;
89197 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89198 old = current_cred();
89199
89200 retval = -EPERM;
89201 +
89202 + if (gr_check_group_change(kgid, kgid, kgid))
89203 + goto error;
89204 +
89205 if (ns_capable(old->user_ns, CAP_SETGID))
89206 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89207 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89208 @@ -403,7 +416,7 @@ error:
89209 /*
89210 * change the user struct in a credentials set to match the new UID
89211 */
89212 -static int set_user(struct cred *new)
89213 +int set_user(struct cred *new)
89214 {
89215 struct user_struct *new_user;
89216
89217 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89218 goto error;
89219 }
89220
89221 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89222 + goto error;
89223 +
89224 if (!uid_eq(new->uid, old->uid)) {
89225 retval = set_user(new);
89226 if (retval < 0)
89227 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89228 old = current_cred();
89229
89230 retval = -EPERM;
89231 +
89232 + if (gr_check_crash_uid(kuid))
89233 + goto error;
89234 + if (gr_check_user_change(kuid, kuid, kuid))
89235 + goto error;
89236 +
89237 if (ns_capable(old->user_ns, CAP_SETUID)) {
89238 new->suid = new->uid = kuid;
89239 if (!uid_eq(kuid, old->uid)) {
89240 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89241 goto error;
89242 }
89243
89244 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
89245 + goto error;
89246 +
89247 if (ruid != (uid_t) -1) {
89248 new->uid = kruid;
89249 if (!uid_eq(kruid, old->uid)) {
89250 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89251 goto error;
89252 }
89253
89254 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
89255 + goto error;
89256 +
89257 if (rgid != (gid_t) -1)
89258 new->gid = krgid;
89259 if (egid != (gid_t) -1)
89260 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89261 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89262 ns_capable(old->user_ns, CAP_SETUID)) {
89263 if (!uid_eq(kuid, old->fsuid)) {
89264 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89265 + goto error;
89266 +
89267 new->fsuid = kuid;
89268 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89269 goto change_okay;
89270 }
89271 }
89272
89273 +error:
89274 abort_creds(new);
89275 return old_fsuid;
89276
89277 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89278 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89279 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89280 ns_capable(old->user_ns, CAP_SETGID)) {
89281 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89282 + goto error;
89283 +
89284 if (!gid_eq(kgid, old->fsgid)) {
89285 new->fsgid = kgid;
89286 goto change_okay;
89287 }
89288 }
89289
89290 +error:
89291 abort_creds(new);
89292 return old_fsgid;
89293
89294 @@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89295 return -EFAULT;
89296
89297 down_read(&uts_sem);
89298 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
89299 + error = __copy_to_user(name->sysname, &utsname()->sysname,
89300 __OLD_UTS_LEN);
89301 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89302 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89303 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
89304 __OLD_UTS_LEN);
89305 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89306 - error |= __copy_to_user(&name->release, &utsname()->release,
89307 + error |= __copy_to_user(name->release, &utsname()->release,
89308 __OLD_UTS_LEN);
89309 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89310 - error |= __copy_to_user(&name->version, &utsname()->version,
89311 + error |= __copy_to_user(name->version, &utsname()->version,
89312 __OLD_UTS_LEN);
89313 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89314 - error |= __copy_to_user(&name->machine, &utsname()->machine,
89315 + error |= __copy_to_user(name->machine, &utsname()->machine,
89316 __OLD_UTS_LEN);
89317 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89318 up_read(&uts_sem);
89319 @@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89320 */
89321 new_rlim->rlim_cur = 1;
89322 }
89323 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89324 + is changed to a lower value. Since tasks can be created by the same
89325 + user in between this limit change and an execve by this task, force
89326 + a recheck only for this task by setting PF_NPROC_EXCEEDED
89327 + */
89328 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
89329 + tsk->flags |= PF_NPROC_EXCEEDED;
89330 }
89331 if (!retval) {
89332 if (old_rlim)
89333 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
89334 index 49e13e1..8dbc052 100644
89335 --- a/kernel/sysctl.c
89336 +++ b/kernel/sysctl.c
89337 @@ -94,7 +94,6 @@
89338
89339
89340 #if defined(CONFIG_SYSCTL)
89341 -
89342 /* External variables not in a header file. */
89343 extern int max_threads;
89344 extern int suid_dumpable;
89345 @@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
89346
89347 /* Constants used for minimum and maximum */
89348 #ifdef CONFIG_LOCKUP_DETECTOR
89349 -static int sixty = 60;
89350 +static int sixty __read_only = 60;
89351 #endif
89352
89353 -static int __maybe_unused neg_one = -1;
89354 -
89355 -static int zero;
89356 -static int __maybe_unused one = 1;
89357 -static int __maybe_unused two = 2;
89358 -static int __maybe_unused three = 3;
89359 -static unsigned long one_ul = 1;
89360 -static int one_hundred = 100;
89361 +static int __maybe_unused neg_one __read_only = -1;
89362 +static int zero __read_only = 0;
89363 +static int __maybe_unused one __read_only = 1;
89364 +static int __maybe_unused two __read_only = 2;
89365 +static int __maybe_unused three __read_only = 3;
89366 +static unsigned long one_ul __read_only = 1;
89367 +static int one_hundred __read_only = 100;
89368 #ifdef CONFIG_PRINTK
89369 -static int ten_thousand = 10000;
89370 +static int ten_thousand __read_only = 10000;
89371 #endif
89372
89373 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
89374 @@ -177,10 +175,8 @@ static int proc_taint(struct ctl_table *table, int write,
89375 void __user *buffer, size_t *lenp, loff_t *ppos);
89376 #endif
89377
89378 -#ifdef CONFIG_PRINTK
89379 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89380 void __user *buffer, size_t *lenp, loff_t *ppos);
89381 -#endif
89382
89383 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
89384 void __user *buffer, size_t *lenp, loff_t *ppos);
89385 @@ -211,6 +207,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
89386
89387 #endif
89388
89389 +extern struct ctl_table grsecurity_table[];
89390 +
89391 static struct ctl_table kern_table[];
89392 static struct ctl_table vm_table[];
89393 static struct ctl_table fs_table[];
89394 @@ -225,6 +223,20 @@ extern struct ctl_table epoll_table[];
89395 int sysctl_legacy_va_layout;
89396 #endif
89397
89398 +#ifdef CONFIG_PAX_SOFTMODE
89399 +static ctl_table pax_table[] = {
89400 + {
89401 + .procname = "softmode",
89402 + .data = &pax_softmode,
89403 + .maxlen = sizeof(unsigned int),
89404 + .mode = 0600,
89405 + .proc_handler = &proc_dointvec,
89406 + },
89407 +
89408 + { }
89409 +};
89410 +#endif
89411 +
89412 /* The default sysctl tables: */
89413
89414 static struct ctl_table sysctl_base_table[] = {
89415 @@ -273,6 +285,22 @@ static int max_extfrag_threshold = 1000;
89416 #endif
89417
89418 static struct ctl_table kern_table[] = {
89419 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
89420 + {
89421 + .procname = "grsecurity",
89422 + .mode = 0500,
89423 + .child = grsecurity_table,
89424 + },
89425 +#endif
89426 +
89427 +#ifdef CONFIG_PAX_SOFTMODE
89428 + {
89429 + .procname = "pax",
89430 + .mode = 0500,
89431 + .child = pax_table,
89432 + },
89433 +#endif
89434 +
89435 {
89436 .procname = "sched_child_runs_first",
89437 .data = &sysctl_sched_child_runs_first,
89438 @@ -635,7 +663,7 @@ static struct ctl_table kern_table[] = {
89439 .data = &modprobe_path,
89440 .maxlen = KMOD_PATH_LEN,
89441 .mode = 0644,
89442 - .proc_handler = proc_dostring,
89443 + .proc_handler = proc_dostring_modpriv,
89444 },
89445 {
89446 .procname = "modules_disabled",
89447 @@ -802,16 +830,20 @@ static struct ctl_table kern_table[] = {
89448 .extra1 = &zero,
89449 .extra2 = &one,
89450 },
89451 +#endif
89452 {
89453 .procname = "kptr_restrict",
89454 .data = &kptr_restrict,
89455 .maxlen = sizeof(int),
89456 .mode = 0644,
89457 .proc_handler = proc_dointvec_minmax_sysadmin,
89458 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89459 + .extra1 = &two,
89460 +#else
89461 .extra1 = &zero,
89462 +#endif
89463 .extra2 = &two,
89464 },
89465 -#endif
89466 {
89467 .procname = "ngroups_max",
89468 .data = &ngroups_max,
89469 @@ -1055,10 +1087,17 @@ static struct ctl_table kern_table[] = {
89470 */
89471 {
89472 .procname = "perf_event_paranoid",
89473 - .data = &sysctl_perf_event_paranoid,
89474 - .maxlen = sizeof(sysctl_perf_event_paranoid),
89475 + .data = &sysctl_perf_event_legitimately_concerned,
89476 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
89477 .mode = 0644,
89478 - .proc_handler = proc_dointvec,
89479 + /* go ahead, be a hero */
89480 + .proc_handler = proc_dointvec_minmax_sysadmin,
89481 + .extra1 = &neg_one,
89482 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89483 + .extra2 = &three,
89484 +#else
89485 + .extra2 = &two,
89486 +#endif
89487 },
89488 {
89489 .procname = "perf_event_mlock_kb",
89490 @@ -1329,6 +1368,13 @@ static struct ctl_table vm_table[] = {
89491 .proc_handler = proc_dointvec_minmax,
89492 .extra1 = &zero,
89493 },
89494 + {
89495 + .procname = "heap_stack_gap",
89496 + .data = &sysctl_heap_stack_gap,
89497 + .maxlen = sizeof(sysctl_heap_stack_gap),
89498 + .mode = 0644,
89499 + .proc_handler = proc_doulongvec_minmax,
89500 + },
89501 #else
89502 {
89503 .procname = "nr_trim_pages",
89504 @@ -1793,6 +1839,16 @@ int proc_dostring(struct ctl_table *table, int write,
89505 buffer, lenp, ppos);
89506 }
89507
89508 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89509 + void __user *buffer, size_t *lenp, loff_t *ppos)
89510 +{
89511 + if (write && !capable(CAP_SYS_MODULE))
89512 + return -EPERM;
89513 +
89514 + return _proc_do_string(table->data, table->maxlen, write,
89515 + buffer, lenp, ppos);
89516 +}
89517 +
89518 static size_t proc_skip_spaces(char **buf)
89519 {
89520 size_t ret;
89521 @@ -1898,6 +1954,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
89522 len = strlen(tmp);
89523 if (len > *size)
89524 len = *size;
89525 + if (len > sizeof(tmp))
89526 + len = sizeof(tmp);
89527 if (copy_to_user(*buf, tmp, len))
89528 return -EFAULT;
89529 *size -= len;
89530 @@ -2062,7 +2120,7 @@ int proc_dointvec(struct ctl_table *table, int write,
89531 static int proc_taint(struct ctl_table *table, int write,
89532 void __user *buffer, size_t *lenp, loff_t *ppos)
89533 {
89534 - struct ctl_table t;
89535 + ctl_table_no_const t;
89536 unsigned long tmptaint = get_taint();
89537 int err;
89538
89539 @@ -2090,7 +2148,6 @@ static int proc_taint(struct ctl_table *table, int write,
89540 return err;
89541 }
89542
89543 -#ifdef CONFIG_PRINTK
89544 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89545 void __user *buffer, size_t *lenp, loff_t *ppos)
89546 {
89547 @@ -2099,7 +2156,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89548
89549 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
89550 }
89551 -#endif
89552
89553 struct do_proc_dointvec_minmax_conv_param {
89554 int *min;
89555 @@ -2646,6 +2702,12 @@ int proc_dostring(struct ctl_table *table, int write,
89556 return -ENOSYS;
89557 }
89558
89559 +int proc_dostring_modpriv(struct ctl_table *table, int write,
89560 + void __user *buffer, size_t *lenp, loff_t *ppos)
89561 +{
89562 + return -ENOSYS;
89563 +}
89564 +
89565 int proc_dointvec(struct ctl_table *table, int write,
89566 void __user *buffer, size_t *lenp, loff_t *ppos)
89567 {
89568 @@ -2702,5 +2764,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
89569 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
89570 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
89571 EXPORT_SYMBOL(proc_dostring);
89572 +EXPORT_SYMBOL(proc_dostring_modpriv);
89573 EXPORT_SYMBOL(proc_doulongvec_minmax);
89574 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
89575 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
89576 index 13d2f7c..c93d0b0 100644
89577 --- a/kernel/taskstats.c
89578 +++ b/kernel/taskstats.c
89579 @@ -28,9 +28,12 @@
89580 #include <linux/fs.h>
89581 #include <linux/file.h>
89582 #include <linux/pid_namespace.h>
89583 +#include <linux/grsecurity.h>
89584 #include <net/genetlink.h>
89585 #include <linux/atomic.h>
89586
89587 +extern int gr_is_taskstats_denied(int pid);
89588 +
89589 /*
89590 * Maximum length of a cpumask that can be specified in
89591 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
89592 @@ -576,6 +579,9 @@ err:
89593
89594 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
89595 {
89596 + if (gr_is_taskstats_denied(current->pid))
89597 + return -EACCES;
89598 +
89599 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
89600 return cmd_attr_register_cpumask(info);
89601 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
89602 diff --git a/kernel/time.c b/kernel/time.c
89603 index 7c7964c..2a0d412 100644
89604 --- a/kernel/time.c
89605 +++ b/kernel/time.c
89606 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
89607 return error;
89608
89609 if (tz) {
89610 + /* we log in do_settimeofday called below, so don't log twice
89611 + */
89612 + if (!tv)
89613 + gr_log_timechange();
89614 +
89615 sys_tz = *tz;
89616 update_vsyscall_tz();
89617 if (firsttime) {
89618 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
89619 index 88c9c65..7497ebc 100644
89620 --- a/kernel/time/alarmtimer.c
89621 +++ b/kernel/time/alarmtimer.c
89622 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
89623 struct platform_device *pdev;
89624 int error = 0;
89625 int i;
89626 - struct k_clock alarm_clock = {
89627 + static struct k_clock alarm_clock = {
89628 .clock_getres = alarm_clock_getres,
89629 .clock_get = alarm_clock_get,
89630 .timer_create = alarm_timer_create,
89631 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
89632 index 5b40279..81e58db 100644
89633 --- a/kernel/time/timekeeping.c
89634 +++ b/kernel/time/timekeeping.c
89635 @@ -15,6 +15,7 @@
89636 #include <linux/init.h>
89637 #include <linux/mm.h>
89638 #include <linux/sched.h>
89639 +#include <linux/grsecurity.h>
89640 #include <linux/syscore_ops.h>
89641 #include <linux/clocksource.h>
89642 #include <linux/jiffies.h>
89643 @@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
89644 if (!timespec_valid_strict(tv))
89645 return -EINVAL;
89646
89647 + gr_log_timechange();
89648 +
89649 raw_spin_lock_irqsave(&timekeeper_lock, flags);
89650 write_seqcount_begin(&timekeeper_seq);
89651
89652 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
89653 index 61ed862..3b52c65 100644
89654 --- a/kernel/time/timer_list.c
89655 +++ b/kernel/time/timer_list.c
89656 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
89657
89658 static void print_name_offset(struct seq_file *m, void *sym)
89659 {
89660 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89661 + SEQ_printf(m, "<%p>", NULL);
89662 +#else
89663 char symname[KSYM_NAME_LEN];
89664
89665 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
89666 SEQ_printf(m, "<%pK>", sym);
89667 else
89668 SEQ_printf(m, "%s", symname);
89669 +#endif
89670 }
89671
89672 static void
89673 @@ -119,7 +123,11 @@ next_one:
89674 static void
89675 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
89676 {
89677 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89678 + SEQ_printf(m, " .base: %p\n", NULL);
89679 +#else
89680 SEQ_printf(m, " .base: %pK\n", base);
89681 +#endif
89682 SEQ_printf(m, " .index: %d\n",
89683 base->index);
89684 SEQ_printf(m, " .resolution: %Lu nsecs\n",
89685 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
89686 {
89687 struct proc_dir_entry *pe;
89688
89689 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89690 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
89691 +#else
89692 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
89693 +#endif
89694 if (!pe)
89695 return -ENOMEM;
89696 return 0;
89697 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
89698 index 1fb08f2..ca4bb1e 100644
89699 --- a/kernel/time/timer_stats.c
89700 +++ b/kernel/time/timer_stats.c
89701 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
89702 static unsigned long nr_entries;
89703 static struct entry entries[MAX_ENTRIES];
89704
89705 -static atomic_t overflow_count;
89706 +static atomic_unchecked_t overflow_count;
89707
89708 /*
89709 * The entries are in a hash-table, for fast lookup:
89710 @@ -140,7 +140,7 @@ static void reset_entries(void)
89711 nr_entries = 0;
89712 memset(entries, 0, sizeof(entries));
89713 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
89714 - atomic_set(&overflow_count, 0);
89715 + atomic_set_unchecked(&overflow_count, 0);
89716 }
89717
89718 static struct entry *alloc_entry(void)
89719 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89720 if (likely(entry))
89721 entry->count++;
89722 else
89723 - atomic_inc(&overflow_count);
89724 + atomic_inc_unchecked(&overflow_count);
89725
89726 out_unlock:
89727 raw_spin_unlock_irqrestore(lock, flags);
89728 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89729
89730 static void print_name_offset(struct seq_file *m, unsigned long addr)
89731 {
89732 +#ifdef CONFIG_GRKERNSEC_HIDESYM
89733 + seq_printf(m, "<%p>", NULL);
89734 +#else
89735 char symname[KSYM_NAME_LEN];
89736
89737 if (lookup_symbol_name(addr, symname) < 0)
89738 - seq_printf(m, "<%p>", (void *)addr);
89739 + seq_printf(m, "<%pK>", (void *)addr);
89740 else
89741 seq_printf(m, "%s", symname);
89742 +#endif
89743 }
89744
89745 static int tstats_show(struct seq_file *m, void *v)
89746 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
89747
89748 seq_puts(m, "Timer Stats Version: v0.3\n");
89749 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
89750 - if (atomic_read(&overflow_count))
89751 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
89752 + if (atomic_read_unchecked(&overflow_count))
89753 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
89754 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
89755
89756 for (i = 0; i < nr_entries; i++) {
89757 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
89758 {
89759 struct proc_dir_entry *pe;
89760
89761 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89762 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
89763 +#else
89764 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
89765 +#endif
89766 if (!pe)
89767 return -ENOMEM;
89768 return 0;
89769 diff --git a/kernel/timer.c b/kernel/timer.c
89770 index accfd24..e00f0c0 100644
89771 --- a/kernel/timer.c
89772 +++ b/kernel/timer.c
89773 @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
89774 /*
89775 * This function runs timers and the timer-tq in bottom half context.
89776 */
89777 -static void run_timer_softirq(struct softirq_action *h)
89778 +static __latent_entropy void run_timer_softirq(void)
89779 {
89780 struct tvec_base *base = __this_cpu_read(tvec_bases);
89781
89782 @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
89783 *
89784 * In all cases the return value is guaranteed to be non-negative.
89785 */
89786 -signed long __sched schedule_timeout(signed long timeout)
89787 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
89788 {
89789 struct timer_list timer;
89790 unsigned long expire;
89791 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
89792 index b418cb0..f879a3d 100644
89793 --- a/kernel/trace/blktrace.c
89794 +++ b/kernel/trace/blktrace.c
89795 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
89796 struct blk_trace *bt = filp->private_data;
89797 char buf[16];
89798
89799 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
89800 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
89801
89802 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
89803 }
89804 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
89805 return 1;
89806
89807 bt = buf->chan->private_data;
89808 - atomic_inc(&bt->dropped);
89809 + atomic_inc_unchecked(&bt->dropped);
89810 return 0;
89811 }
89812
89813 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
89814
89815 bt->dir = dir;
89816 bt->dev = dev;
89817 - atomic_set(&bt->dropped, 0);
89818 + atomic_set_unchecked(&bt->dropped, 0);
89819 INIT_LIST_HEAD(&bt->running_list);
89820
89821 ret = -EIO;
89822 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
89823 index cd7f76d..553c805 100644
89824 --- a/kernel/trace/ftrace.c
89825 +++ b/kernel/trace/ftrace.c
89826 @@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
89827 if (unlikely(ftrace_disabled))
89828 return 0;
89829
89830 + ret = ftrace_arch_code_modify_prepare();
89831 + FTRACE_WARN_ON(ret);
89832 + if (ret)
89833 + return 0;
89834 +
89835 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
89836 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
89837 if (ret) {
89838 ftrace_bug(ret, ip);
89839 - return 0;
89840 }
89841 - return 1;
89842 + return ret ? 0 : 1;
89843 }
89844
89845 /*
89846 @@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
89847 if (!count)
89848 return 0;
89849
89850 + pax_open_kernel();
89851 sort(start, count, sizeof(*start),
89852 ftrace_cmp_ips, ftrace_swap_ips);
89853 + pax_close_kernel();
89854
89855 start_pg = ftrace_allocate_pages(count);
89856 if (!start_pg)
89857 @@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
89858 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
89859
89860 static int ftrace_graph_active;
89861 -static struct notifier_block ftrace_suspend_notifier;
89862 -
89863 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
89864 {
89865 return 0;
89866 @@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
89867 ftrace_graph_entry = ftrace_graph_entry_test;
89868 }
89869
89870 +static struct notifier_block ftrace_suspend_notifier = {
89871 + .notifier_call = ftrace_suspend_notifier_call
89872 +};
89873 +
89874 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89875 trace_func_graph_ent_t entryfunc)
89876 {
89877 @@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89878 goto out;
89879 }
89880
89881 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
89882 register_pm_notifier(&ftrace_suspend_notifier);
89883
89884 ftrace_graph_active++;
89885 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
89886 index fc4da2d..f3e800b 100644
89887 --- a/kernel/trace/ring_buffer.c
89888 +++ b/kernel/trace/ring_buffer.c
89889 @@ -352,9 +352,9 @@ struct buffer_data_page {
89890 */
89891 struct buffer_page {
89892 struct list_head list; /* list of buffer pages */
89893 - local_t write; /* index for next write */
89894 + local_unchecked_t write; /* index for next write */
89895 unsigned read; /* index for next read */
89896 - local_t entries; /* entries on this page */
89897 + local_unchecked_t entries; /* entries on this page */
89898 unsigned long real_end; /* real end of data */
89899 struct buffer_data_page *page; /* Actual data page */
89900 };
89901 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
89902 unsigned long last_overrun;
89903 local_t entries_bytes;
89904 local_t entries;
89905 - local_t overrun;
89906 - local_t commit_overrun;
89907 + local_unchecked_t overrun;
89908 + local_unchecked_t commit_overrun;
89909 local_t dropped_events;
89910 local_t committing;
89911 local_t commits;
89912 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
89913 *
89914 * We add a counter to the write field to denote this.
89915 */
89916 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
89917 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
89918 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
89919 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
89920
89921 /*
89922 * Just make sure we have seen our old_write and synchronize
89923 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
89924 * cmpxchg to only update if an interrupt did not already
89925 * do it for us. If the cmpxchg fails, we don't care.
89926 */
89927 - (void)local_cmpxchg(&next_page->write, old_write, val);
89928 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
89929 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
89930 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
89931
89932 /*
89933 * No need to worry about races with clearing out the commit.
89934 @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
89935
89936 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
89937 {
89938 - return local_read(&bpage->entries) & RB_WRITE_MASK;
89939 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
89940 }
89941
89942 static inline unsigned long rb_page_write(struct buffer_page *bpage)
89943 {
89944 - return local_read(&bpage->write) & RB_WRITE_MASK;
89945 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
89946 }
89947
89948 static int
89949 @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
89950 * bytes consumed in ring buffer from here.
89951 * Increment overrun to account for the lost events.
89952 */
89953 - local_add(page_entries, &cpu_buffer->overrun);
89954 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
89955 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
89956 }
89957
89958 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
89959 * it is our responsibility to update
89960 * the counters.
89961 */
89962 - local_add(entries, &cpu_buffer->overrun);
89963 + local_add_unchecked(entries, &cpu_buffer->overrun);
89964 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
89965
89966 /*
89967 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89968 if (tail == BUF_PAGE_SIZE)
89969 tail_page->real_end = 0;
89970
89971 - local_sub(length, &tail_page->write);
89972 + local_sub_unchecked(length, &tail_page->write);
89973 return;
89974 }
89975
89976 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89977 rb_event_set_padding(event);
89978
89979 /* Set the write back to the previous setting */
89980 - local_sub(length, &tail_page->write);
89981 + local_sub_unchecked(length, &tail_page->write);
89982 return;
89983 }
89984
89985 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89986
89987 /* Set write to end of buffer */
89988 length = (tail + length) - BUF_PAGE_SIZE;
89989 - local_sub(length, &tail_page->write);
89990 + local_sub_unchecked(length, &tail_page->write);
89991 }
89992
89993 /*
89994 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
89995 * about it.
89996 */
89997 if (unlikely(next_page == commit_page)) {
89998 - local_inc(&cpu_buffer->commit_overrun);
89999 + local_inc_unchecked(&cpu_buffer->commit_overrun);
90000 goto out_reset;
90001 }
90002
90003 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90004 cpu_buffer->tail_page) &&
90005 (cpu_buffer->commit_page ==
90006 cpu_buffer->reader_page))) {
90007 - local_inc(&cpu_buffer->commit_overrun);
90008 + local_inc_unchecked(&cpu_buffer->commit_overrun);
90009 goto out_reset;
90010 }
90011 }
90012 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90013 length += RB_LEN_TIME_EXTEND;
90014
90015 tail_page = cpu_buffer->tail_page;
90016 - write = local_add_return(length, &tail_page->write);
90017 + write = local_add_return_unchecked(length, &tail_page->write);
90018
90019 /* set write to only the index of the write */
90020 write &= RB_WRITE_MASK;
90021 @@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90022 kmemcheck_annotate_bitfield(event, bitfield);
90023 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90024
90025 - local_inc(&tail_page->entries);
90026 + local_inc_unchecked(&tail_page->entries);
90027
90028 /*
90029 * If this is the first commit on the page, then update
90030 @@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90031
90032 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
90033 unsigned long write_mask =
90034 - local_read(&bpage->write) & ~RB_WRITE_MASK;
90035 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
90036 unsigned long event_length = rb_event_length(event);
90037 /*
90038 * This is on the tail page. It is possible that
90039 @@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90040 */
90041 old_index += write_mask;
90042 new_index += write_mask;
90043 - index = local_cmpxchg(&bpage->write, old_index, new_index);
90044 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
90045 if (index == old_index) {
90046 /* update counters */
90047 local_sub(event_length, &cpu_buffer->entries_bytes);
90048 @@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90049
90050 /* Do the likely case first */
90051 if (likely(bpage->page == (void *)addr)) {
90052 - local_dec(&bpage->entries);
90053 + local_dec_unchecked(&bpage->entries);
90054 return;
90055 }
90056
90057 @@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90058 start = bpage;
90059 do {
90060 if (bpage->page == (void *)addr) {
90061 - local_dec(&bpage->entries);
90062 + local_dec_unchecked(&bpage->entries);
90063 return;
90064 }
90065 rb_inc_page(cpu_buffer, &bpage);
90066 @@ -3146,7 +3146,7 @@ static inline unsigned long
90067 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
90068 {
90069 return local_read(&cpu_buffer->entries) -
90070 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
90071 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
90072 }
90073
90074 /**
90075 @@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
90076 return 0;
90077
90078 cpu_buffer = buffer->buffers[cpu];
90079 - ret = local_read(&cpu_buffer->overrun);
90080 + ret = local_read_unchecked(&cpu_buffer->overrun);
90081
90082 return ret;
90083 }
90084 @@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
90085 return 0;
90086
90087 cpu_buffer = buffer->buffers[cpu];
90088 - ret = local_read(&cpu_buffer->commit_overrun);
90089 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
90090
90091 return ret;
90092 }
90093 @@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
90094 /* if you care about this being correct, lock the buffer */
90095 for_each_buffer_cpu(buffer, cpu) {
90096 cpu_buffer = buffer->buffers[cpu];
90097 - overruns += local_read(&cpu_buffer->overrun);
90098 + overruns += local_read_unchecked(&cpu_buffer->overrun);
90099 }
90100
90101 return overruns;
90102 @@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90103 /*
90104 * Reset the reader page to size zero.
90105 */
90106 - local_set(&cpu_buffer->reader_page->write, 0);
90107 - local_set(&cpu_buffer->reader_page->entries, 0);
90108 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90109 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90110 local_set(&cpu_buffer->reader_page->page->commit, 0);
90111 cpu_buffer->reader_page->real_end = 0;
90112
90113 @@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90114 * want to compare with the last_overrun.
90115 */
90116 smp_mb();
90117 - overwrite = local_read(&(cpu_buffer->overrun));
90118 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
90119
90120 /*
90121 * Here's the tricky part.
90122 @@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90123
90124 cpu_buffer->head_page
90125 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90126 - local_set(&cpu_buffer->head_page->write, 0);
90127 - local_set(&cpu_buffer->head_page->entries, 0);
90128 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
90129 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90130 local_set(&cpu_buffer->head_page->page->commit, 0);
90131
90132 cpu_buffer->head_page->read = 0;
90133 @@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90134
90135 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90136 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90137 - local_set(&cpu_buffer->reader_page->write, 0);
90138 - local_set(&cpu_buffer->reader_page->entries, 0);
90139 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90140 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90141 local_set(&cpu_buffer->reader_page->page->commit, 0);
90142 cpu_buffer->reader_page->read = 0;
90143
90144 local_set(&cpu_buffer->entries_bytes, 0);
90145 - local_set(&cpu_buffer->overrun, 0);
90146 - local_set(&cpu_buffer->commit_overrun, 0);
90147 + local_set_unchecked(&cpu_buffer->overrun, 0);
90148 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90149 local_set(&cpu_buffer->dropped_events, 0);
90150 local_set(&cpu_buffer->entries, 0);
90151 local_set(&cpu_buffer->committing, 0);
90152 @@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90153 rb_init_page(bpage);
90154 bpage = reader->page;
90155 reader->page = *data_page;
90156 - local_set(&reader->write, 0);
90157 - local_set(&reader->entries, 0);
90158 + local_set_unchecked(&reader->write, 0);
90159 + local_set_unchecked(&reader->entries, 0);
90160 reader->read = 0;
90161 *data_page = bpage;
90162
90163 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90164 index 24c1f23..781fd73f 100644
90165 --- a/kernel/trace/trace.c
90166 +++ b/kernel/trace/trace.c
90167 @@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90168 return 0;
90169 }
90170
90171 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90172 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90173 {
90174 /* do nothing if flag is already set */
90175 if (!!(trace_flags & mask) == !!enabled)
90176 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90177 index 02b592f..f971546 100644
90178 --- a/kernel/trace/trace.h
90179 +++ b/kernel/trace/trace.h
90180 @@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
90181 void trace_printk_init_buffers(void);
90182 void trace_printk_start_comm(void);
90183 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90184 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90185 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90186
90187 /*
90188 * Normal trace_printk() and friends allocates special buffers
90189 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90190 index 26dc348..8708ca7 100644
90191 --- a/kernel/trace/trace_clock.c
90192 +++ b/kernel/trace/trace_clock.c
90193 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90194 return now;
90195 }
90196
90197 -static atomic64_t trace_counter;
90198 +static atomic64_unchecked_t trace_counter;
90199
90200 /*
90201 * trace_clock_counter(): simply an atomic counter.
90202 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90203 */
90204 u64 notrace trace_clock_counter(void)
90205 {
90206 - return atomic64_add_return(1, &trace_counter);
90207 + return atomic64_inc_return_unchecked(&trace_counter);
90208 }
90209 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90210 index 7b16d40..1b2875d 100644
90211 --- a/kernel/trace/trace_events.c
90212 +++ b/kernel/trace/trace_events.c
90213 @@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90214 return 0;
90215 }
90216
90217 -struct ftrace_module_file_ops;
90218 static void __add_event_to_tracers(struct ftrace_event_call *call);
90219
90220 /* Add an additional event_call dynamically */
90221 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90222 index 0abd9b8..6a663a2 100644
90223 --- a/kernel/trace/trace_mmiotrace.c
90224 +++ b/kernel/trace/trace_mmiotrace.c
90225 @@ -24,7 +24,7 @@ struct header_iter {
90226 static struct trace_array *mmio_trace_array;
90227 static bool overrun_detected;
90228 static unsigned long prev_overruns;
90229 -static atomic_t dropped_count;
90230 +static atomic_unchecked_t dropped_count;
90231
90232 static void mmio_reset_data(struct trace_array *tr)
90233 {
90234 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90235
90236 static unsigned long count_overruns(struct trace_iterator *iter)
90237 {
90238 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
90239 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90240 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90241
90242 if (over > prev_overruns)
90243 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90244 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90245 sizeof(*entry), 0, pc);
90246 if (!event) {
90247 - atomic_inc(&dropped_count);
90248 + atomic_inc_unchecked(&dropped_count);
90249 return;
90250 }
90251 entry = ring_buffer_event_data(event);
90252 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90253 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90254 sizeof(*entry), 0, pc);
90255 if (!event) {
90256 - atomic_inc(&dropped_count);
90257 + atomic_inc_unchecked(&dropped_count);
90258 return;
90259 }
90260 entry = ring_buffer_event_data(event);
90261 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90262 index ed32284..884d6c3 100644
90263 --- a/kernel/trace/trace_output.c
90264 +++ b/kernel/trace/trace_output.c
90265 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90266
90267 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90268 if (!IS_ERR(p)) {
90269 - p = mangle_path(s->buffer + s->len, p, "\n");
90270 + p = mangle_path(s->buffer + s->len, p, "\n\\");
90271 if (p) {
90272 s->len = p - s->buffer;
90273 return 1;
90274 @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90275 goto out;
90276 }
90277
90278 + pax_open_kernel();
90279 if (event->funcs->trace == NULL)
90280 - event->funcs->trace = trace_nop_print;
90281 + *(void **)&event->funcs->trace = trace_nop_print;
90282 if (event->funcs->raw == NULL)
90283 - event->funcs->raw = trace_nop_print;
90284 + *(void **)&event->funcs->raw = trace_nop_print;
90285 if (event->funcs->hex == NULL)
90286 - event->funcs->hex = trace_nop_print;
90287 + *(void **)&event->funcs->hex = trace_nop_print;
90288 if (event->funcs->binary == NULL)
90289 - event->funcs->binary = trace_nop_print;
90290 + *(void **)&event->funcs->binary = trace_nop_print;
90291 + pax_close_kernel();
90292
90293 key = event->type & (EVENT_HASHSIZE - 1);
90294
90295 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90296 index e6be585..d73ae5e 100644
90297 --- a/kernel/trace/trace_stack.c
90298 +++ b/kernel/trace/trace_stack.c
90299 @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90300 return;
90301
90302 /* we do not handle interrupt stacks yet */
90303 - if (!object_is_on_stack(stack))
90304 + if (!object_starts_on_stack(stack))
90305 return;
90306
90307 local_irq_save(flags);
90308 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90309 index dd06439..9e77bce 100644
90310 --- a/kernel/user_namespace.c
90311 +++ b/kernel/user_namespace.c
90312 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90313 !kgid_has_mapping(parent_ns, group))
90314 return -EPERM;
90315
90316 +#ifdef CONFIG_GRKERNSEC
90317 + /*
90318 + * This doesn't really inspire confidence:
90319 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90320 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90321 + * Increases kernel attack surface in areas developers
90322 + * previously cared little about ("low importance due
90323 + * to requiring "root" capability")
90324 + * To be removed when this code receives *proper* review
90325 + */
90326 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
90327 + !capable(CAP_SETGID))
90328 + return -EPERM;
90329 +#endif
90330 +
90331 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
90332 if (!ns)
90333 return -ENOMEM;
90334 @@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
90335 if (atomic_read(&current->mm->mm_users) > 1)
90336 return -EINVAL;
90337
90338 - if (current->fs->users != 1)
90339 + if (atomic_read(&current->fs->users) != 1)
90340 return -EINVAL;
90341
90342 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
90343 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
90344 index 4f69f9a..7c6f8f8 100644
90345 --- a/kernel/utsname_sysctl.c
90346 +++ b/kernel/utsname_sysctl.c
90347 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
90348 static int proc_do_uts_string(ctl_table *table, int write,
90349 void __user *buffer, size_t *lenp, loff_t *ppos)
90350 {
90351 - struct ctl_table uts_table;
90352 + ctl_table_no_const uts_table;
90353 int r;
90354 memcpy(&uts_table, table, sizeof(uts_table));
90355 uts_table.data = get_uts(table, write);
90356 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
90357 index 4431610..4265616 100644
90358 --- a/kernel/watchdog.c
90359 +++ b/kernel/watchdog.c
90360 @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
90361 static void watchdog_nmi_disable(unsigned int cpu) { return; }
90362 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
90363
90364 -static struct smp_hotplug_thread watchdog_threads = {
90365 +static struct smp_hotplug_thread watchdog_threads __read_only = {
90366 .store = &softlockup_watchdog,
90367 .thread_should_run = watchdog_should_run,
90368 .thread_fn = watchdog,
90369 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
90370 index 193e977..26dd63f 100644
90371 --- a/kernel/workqueue.c
90372 +++ b/kernel/workqueue.c
90373 @@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
90374 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
90375 worker_flags |= WORKER_REBOUND;
90376 worker_flags &= ~WORKER_UNBOUND;
90377 - ACCESS_ONCE(worker->flags) = worker_flags;
90378 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
90379 }
90380
90381 spin_unlock_irq(&pool->lock);
90382 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
90383 index a48abea..e108def 100644
90384 --- a/lib/Kconfig.debug
90385 +++ b/lib/Kconfig.debug
90386 @@ -854,7 +854,7 @@ config DEBUG_MUTEXES
90387
90388 config DEBUG_WW_MUTEX_SLOWPATH
90389 bool "Wait/wound mutex debugging: Slowpath testing"
90390 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90391 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90392 select DEBUG_LOCK_ALLOC
90393 select DEBUG_SPINLOCK
90394 select DEBUG_MUTEXES
90395 @@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
90396
90397 config DEBUG_LOCK_ALLOC
90398 bool "Lock debugging: detect incorrect freeing of live locks"
90399 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90400 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90401 select DEBUG_SPINLOCK
90402 select DEBUG_MUTEXES
90403 select LOCKDEP
90404 @@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
90405
90406 config PROVE_LOCKING
90407 bool "Lock debugging: prove locking correctness"
90408 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90409 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90410 select LOCKDEP
90411 select DEBUG_SPINLOCK
90412 select DEBUG_MUTEXES
90413 @@ -932,7 +932,7 @@ config LOCKDEP
90414
90415 config LOCK_STAT
90416 bool "Lock usage statistics"
90417 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90418 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90419 select LOCKDEP
90420 select DEBUG_SPINLOCK
90421 select DEBUG_MUTEXES
90422 @@ -1394,6 +1394,7 @@ config LATENCYTOP
90423 depends on DEBUG_KERNEL
90424 depends on STACKTRACE_SUPPORT
90425 depends on PROC_FS
90426 + depends on !GRKERNSEC_HIDESYM
90427 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
90428 select KALLSYMS
90429 select KALLSYMS_ALL
90430 @@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90431 config DEBUG_STRICT_USER_COPY_CHECKS
90432 bool "Strict user copy size checks"
90433 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90434 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
90435 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
90436 help
90437 Enabling this option turns a certain set of sanity checks for user
90438 copy operations into compile time failures.
90439 @@ -1529,7 +1530,7 @@ endmenu # runtime tests
90440
90441 config PROVIDE_OHCI1394_DMA_INIT
90442 bool "Remote debugging over FireWire early on boot"
90443 - depends on PCI && X86
90444 + depends on PCI && X86 && !GRKERNSEC
90445 help
90446 If you want to debug problems which hang or crash the kernel early
90447 on boot and the crashing machine has a FireWire port, you can use
90448 diff --git a/lib/Makefile b/lib/Makefile
90449 index 48140e3..de854e5 100644
90450 --- a/lib/Makefile
90451 +++ b/lib/Makefile
90452 @@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
90453 obj-$(CONFIG_BTREE) += btree.o
90454 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
90455 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
90456 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
90457 +obj-y += list_debug.o
90458 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
90459
90460 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
90461 diff --git a/lib/average.c b/lib/average.c
90462 index 114d1be..ab0350c 100644
90463 --- a/lib/average.c
90464 +++ b/lib/average.c
90465 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
90466 {
90467 unsigned long internal = ACCESS_ONCE(avg->internal);
90468
90469 - ACCESS_ONCE(avg->internal) = internal ?
90470 + ACCESS_ONCE_RW(avg->internal) = internal ?
90471 (((internal << avg->weight) - internal) +
90472 (val << avg->factor)) >> avg->weight :
90473 (val << avg->factor);
90474 diff --git a/lib/bitmap.c b/lib/bitmap.c
90475 index 06f7e4f..f3cf2b0 100644
90476 --- a/lib/bitmap.c
90477 +++ b/lib/bitmap.c
90478 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
90479 {
90480 int c, old_c, totaldigits, ndigits, nchunks, nbits;
90481 u32 chunk;
90482 - const char __user __force *ubuf = (const char __user __force *)buf;
90483 + const char __user *ubuf = (const char __force_user *)buf;
90484
90485 bitmap_zero(maskp, nmaskbits);
90486
90487 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
90488 {
90489 if (!access_ok(VERIFY_READ, ubuf, ulen))
90490 return -EFAULT;
90491 - return __bitmap_parse((const char __force *)ubuf,
90492 + return __bitmap_parse((const char __force_kernel *)ubuf,
90493 ulen, 1, maskp, nmaskbits);
90494
90495 }
90496 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
90497 {
90498 unsigned a, b;
90499 int c, old_c, totaldigits;
90500 - const char __user __force *ubuf = (const char __user __force *)buf;
90501 + const char __user *ubuf = (const char __force_user *)buf;
90502 int exp_digit, in_range;
90503
90504 totaldigits = c = 0;
90505 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
90506 {
90507 if (!access_ok(VERIFY_READ, ubuf, ulen))
90508 return -EFAULT;
90509 - return __bitmap_parselist((const char __force *)ubuf,
90510 + return __bitmap_parselist((const char __force_kernel *)ubuf,
90511 ulen, 1, maskp, nmaskbits);
90512 }
90513 EXPORT_SYMBOL(bitmap_parselist_user);
90514 diff --git a/lib/bug.c b/lib/bug.c
90515 index 1686034..a9c00c8 100644
90516 --- a/lib/bug.c
90517 +++ b/lib/bug.c
90518 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
90519 return BUG_TRAP_TYPE_NONE;
90520
90521 bug = find_bug(bugaddr);
90522 + if (!bug)
90523 + return BUG_TRAP_TYPE_NONE;
90524
90525 file = NULL;
90526 line = 0;
90527 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
90528 index e0731c3..ad66444 100644
90529 --- a/lib/debugobjects.c
90530 +++ b/lib/debugobjects.c
90531 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
90532 if (limit > 4)
90533 return;
90534
90535 - is_on_stack = object_is_on_stack(addr);
90536 + is_on_stack = object_starts_on_stack(addr);
90537 if (is_on_stack == onstack)
90538 return;
90539
90540 diff --git a/lib/devres.c b/lib/devres.c
90541 index 8235331..5881053 100644
90542 --- a/lib/devres.c
90543 +++ b/lib/devres.c
90544 @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
90545 void devm_iounmap(struct device *dev, void __iomem *addr)
90546 {
90547 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
90548 - (void *)addr));
90549 + (void __force *)addr));
90550 iounmap(addr);
90551 }
90552 EXPORT_SYMBOL(devm_iounmap);
90553 @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
90554 {
90555 ioport_unmap(addr);
90556 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
90557 - devm_ioport_map_match, (void *)addr));
90558 + devm_ioport_map_match, (void __force *)addr));
90559 }
90560 EXPORT_SYMBOL(devm_ioport_unmap);
90561 #endif /* CONFIG_HAS_IOPORT */
90562 diff --git a/lib/div64.c b/lib/div64.c
90563 index 4382ad7..08aa558 100644
90564 --- a/lib/div64.c
90565 +++ b/lib/div64.c
90566 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
90567 EXPORT_SYMBOL(__div64_32);
90568
90569 #ifndef div_s64_rem
90570 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90571 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90572 {
90573 u64 quotient;
90574
90575 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
90576 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
90577 */
90578 #ifndef div64_u64
90579 -u64 div64_u64(u64 dividend, u64 divisor)
90580 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
90581 {
90582 u32 high = divisor >> 32;
90583 u64 quot;
90584 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
90585 index 98f2d7e..899da5c 100644
90586 --- a/lib/dma-debug.c
90587 +++ b/lib/dma-debug.c
90588 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
90589
90590 void dma_debug_add_bus(struct bus_type *bus)
90591 {
90592 - struct notifier_block *nb;
90593 + notifier_block_no_const *nb;
90594
90595 if (global_disable)
90596 return;
90597 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
90598
90599 static void check_for_stack(struct device *dev, void *addr)
90600 {
90601 - if (object_is_on_stack(addr))
90602 + if (object_starts_on_stack(addr))
90603 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
90604 "stack [addr=%p]\n", addr);
90605 }
90606 diff --git a/lib/hash.c b/lib/hash.c
90607 index fea973f..386626f 100644
90608 --- a/lib/hash.c
90609 +++ b/lib/hash.c
90610 @@ -14,7 +14,7 @@
90611 #include <linux/hash.h>
90612 #include <linux/cache.h>
90613
90614 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
90615 +static struct fast_hash_ops arch_hash_ops __read_only = {
90616 .hash = jhash,
90617 .hash2 = jhash2,
90618 };
90619 diff --git a/lib/inflate.c b/lib/inflate.c
90620 index 013a761..c28f3fc 100644
90621 --- a/lib/inflate.c
90622 +++ b/lib/inflate.c
90623 @@ -269,7 +269,7 @@ static void free(void *where)
90624 malloc_ptr = free_mem_ptr;
90625 }
90626 #else
90627 -#define malloc(a) kmalloc(a, GFP_KERNEL)
90628 +#define malloc(a) kmalloc((a), GFP_KERNEL)
90629 #define free(a) kfree(a)
90630 #endif
90631
90632 diff --git a/lib/ioremap.c b/lib/ioremap.c
90633 index 0c9216c..863bd89 100644
90634 --- a/lib/ioremap.c
90635 +++ b/lib/ioremap.c
90636 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
90637 unsigned long next;
90638
90639 phys_addr -= addr;
90640 - pmd = pmd_alloc(&init_mm, pud, addr);
90641 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90642 if (!pmd)
90643 return -ENOMEM;
90644 do {
90645 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
90646 unsigned long next;
90647
90648 phys_addr -= addr;
90649 - pud = pud_alloc(&init_mm, pgd, addr);
90650 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
90651 if (!pud)
90652 return -ENOMEM;
90653 do {
90654 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
90655 index bd2bea9..6b3c95e 100644
90656 --- a/lib/is_single_threaded.c
90657 +++ b/lib/is_single_threaded.c
90658 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
90659 struct task_struct *p, *t;
90660 bool ret;
90661
90662 + if (!mm)
90663 + return true;
90664 +
90665 if (atomic_read(&task->signal->live) != 1)
90666 return false;
90667
90668 diff --git a/lib/kobject.c b/lib/kobject.c
90669 index cb14aea..8c53cdb 100644
90670 --- a/lib/kobject.c
90671 +++ b/lib/kobject.c
90672 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
90673
90674
90675 static DEFINE_SPINLOCK(kobj_ns_type_lock);
90676 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
90677 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
90678
90679 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90680 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90681 {
90682 enum kobj_ns_type type = ops->type;
90683 int error;
90684 diff --git a/lib/list_debug.c b/lib/list_debug.c
90685 index c24c2f7..f0296f4 100644
90686 --- a/lib/list_debug.c
90687 +++ b/lib/list_debug.c
90688 @@ -11,7 +11,9 @@
90689 #include <linux/bug.h>
90690 #include <linux/kernel.h>
90691 #include <linux/rculist.h>
90692 +#include <linux/mm.h>
90693
90694 +#ifdef CONFIG_DEBUG_LIST
90695 /*
90696 * Insert a new entry between two known consecutive entries.
90697 *
90698 @@ -19,21 +21,40 @@
90699 * the prev/next entries already!
90700 */
90701
90702 +static bool __list_add_debug(struct list_head *new,
90703 + struct list_head *prev,
90704 + struct list_head *next)
90705 +{
90706 + if (unlikely(next->prev != prev)) {
90707 + printk(KERN_ERR "list_add corruption. next->prev should be "
90708 + "prev (%p), but was %p. (next=%p).\n",
90709 + prev, next->prev, next);
90710 + BUG();
90711 + return false;
90712 + }
90713 + if (unlikely(prev->next != next)) {
90714 + printk(KERN_ERR "list_add corruption. prev->next should be "
90715 + "next (%p), but was %p. (prev=%p).\n",
90716 + next, prev->next, prev);
90717 + BUG();
90718 + return false;
90719 + }
90720 + if (unlikely(new == prev || new == next)) {
90721 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
90722 + new, prev, next);
90723 + BUG();
90724 + return false;
90725 + }
90726 + return true;
90727 +}
90728 +
90729 void __list_add(struct list_head *new,
90730 - struct list_head *prev,
90731 - struct list_head *next)
90732 + struct list_head *prev,
90733 + struct list_head *next)
90734 {
90735 - WARN(next->prev != prev,
90736 - "list_add corruption. next->prev should be "
90737 - "prev (%p), but was %p. (next=%p).\n",
90738 - prev, next->prev, next);
90739 - WARN(prev->next != next,
90740 - "list_add corruption. prev->next should be "
90741 - "next (%p), but was %p. (prev=%p).\n",
90742 - next, prev->next, prev);
90743 - WARN(new == prev || new == next,
90744 - "list_add double add: new=%p, prev=%p, next=%p.\n",
90745 - new, prev, next);
90746 + if (!__list_add_debug(new, prev, next))
90747 + return;
90748 +
90749 next->prev = new;
90750 new->next = next;
90751 new->prev = prev;
90752 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
90753 }
90754 EXPORT_SYMBOL(__list_add);
90755
90756 -void __list_del_entry(struct list_head *entry)
90757 +static bool __list_del_entry_debug(struct list_head *entry)
90758 {
90759 struct list_head *prev, *next;
90760
90761 prev = entry->prev;
90762 next = entry->next;
90763
90764 - if (WARN(next == LIST_POISON1,
90765 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90766 - entry, LIST_POISON1) ||
90767 - WARN(prev == LIST_POISON2,
90768 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90769 - entry, LIST_POISON2) ||
90770 - WARN(prev->next != entry,
90771 - "list_del corruption. prev->next should be %p, "
90772 - "but was %p\n", entry, prev->next) ||
90773 - WARN(next->prev != entry,
90774 - "list_del corruption. next->prev should be %p, "
90775 - "but was %p\n", entry, next->prev))
90776 + if (unlikely(next == LIST_POISON1)) {
90777 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90778 + entry, LIST_POISON1);
90779 + BUG();
90780 + return false;
90781 + }
90782 + if (unlikely(prev == LIST_POISON2)) {
90783 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90784 + entry, LIST_POISON2);
90785 + BUG();
90786 + return false;
90787 + }
90788 + if (unlikely(entry->prev->next != entry)) {
90789 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
90790 + "but was %p\n", entry, prev->next);
90791 + BUG();
90792 + return false;
90793 + }
90794 + if (unlikely(entry->next->prev != entry)) {
90795 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
90796 + "but was %p\n", entry, next->prev);
90797 + BUG();
90798 + return false;
90799 + }
90800 + return true;
90801 +}
90802 +
90803 +void __list_del_entry(struct list_head *entry)
90804 +{
90805 + if (!__list_del_entry_debug(entry))
90806 return;
90807
90808 - __list_del(prev, next);
90809 + __list_del(entry->prev, entry->next);
90810 }
90811 EXPORT_SYMBOL(__list_del_entry);
90812
90813 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
90814 void __list_add_rcu(struct list_head *new,
90815 struct list_head *prev, struct list_head *next)
90816 {
90817 - WARN(next->prev != prev,
90818 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
90819 - prev, next->prev, next);
90820 - WARN(prev->next != next,
90821 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
90822 - next, prev->next, prev);
90823 + if (!__list_add_debug(new, prev, next))
90824 + return;
90825 +
90826 new->next = next;
90827 new->prev = prev;
90828 rcu_assign_pointer(list_next_rcu(prev), new);
90829 next->prev = new;
90830 }
90831 EXPORT_SYMBOL(__list_add_rcu);
90832 +#endif
90833 +
90834 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
90835 +{
90836 +#ifdef CONFIG_DEBUG_LIST
90837 + if (!__list_add_debug(new, prev, next))
90838 + return;
90839 +#endif
90840 +
90841 + pax_open_kernel();
90842 + next->prev = new;
90843 + new->next = next;
90844 + new->prev = prev;
90845 + prev->next = new;
90846 + pax_close_kernel();
90847 +}
90848 +EXPORT_SYMBOL(__pax_list_add);
90849 +
90850 +void pax_list_del(struct list_head *entry)
90851 +{
90852 +#ifdef CONFIG_DEBUG_LIST
90853 + if (!__list_del_entry_debug(entry))
90854 + return;
90855 +#endif
90856 +
90857 + pax_open_kernel();
90858 + __list_del(entry->prev, entry->next);
90859 + entry->next = LIST_POISON1;
90860 + entry->prev = LIST_POISON2;
90861 + pax_close_kernel();
90862 +}
90863 +EXPORT_SYMBOL(pax_list_del);
90864 +
90865 +void pax_list_del_init(struct list_head *entry)
90866 +{
90867 + pax_open_kernel();
90868 + __list_del(entry->prev, entry->next);
90869 + INIT_LIST_HEAD(entry);
90870 + pax_close_kernel();
90871 +}
90872 +EXPORT_SYMBOL(pax_list_del_init);
90873 +
90874 +void __pax_list_add_rcu(struct list_head *new,
90875 + struct list_head *prev, struct list_head *next)
90876 +{
90877 +#ifdef CONFIG_DEBUG_LIST
90878 + if (!__list_add_debug(new, prev, next))
90879 + return;
90880 +#endif
90881 +
90882 + pax_open_kernel();
90883 + new->next = next;
90884 + new->prev = prev;
90885 + rcu_assign_pointer(list_next_rcu(prev), new);
90886 + next->prev = new;
90887 + pax_close_kernel();
90888 +}
90889 +EXPORT_SYMBOL(__pax_list_add_rcu);
90890 +
90891 +void pax_list_del_rcu(struct list_head *entry)
90892 +{
90893 +#ifdef CONFIG_DEBUG_LIST
90894 + if (!__list_del_entry_debug(entry))
90895 + return;
90896 +#endif
90897 +
90898 + pax_open_kernel();
90899 + __list_del(entry->prev, entry->next);
90900 + entry->next = LIST_POISON1;
90901 + entry->prev = LIST_POISON2;
90902 + pax_close_kernel();
90903 +}
90904 +EXPORT_SYMBOL(pax_list_del_rcu);
90905 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
90906 index 963b703..438bc51 100644
90907 --- a/lib/percpu-refcount.c
90908 +++ b/lib/percpu-refcount.c
90909 @@ -29,7 +29,7 @@
90910 * can't hit 0 before we've added up all the percpu refs.
90911 */
90912
90913 -#define PCPU_COUNT_BIAS (1U << 31)
90914 +#define PCPU_COUNT_BIAS (1U << 30)
90915
90916 /**
90917 * percpu_ref_init - initialize a percpu refcount
90918 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
90919 index bd4a8df..9e4804f 100644
90920 --- a/lib/radix-tree.c
90921 +++ b/lib/radix-tree.c
90922 @@ -93,7 +93,7 @@ struct radix_tree_preload {
90923 int nr;
90924 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
90925 };
90926 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
90927 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
90928
90929 static inline void *ptr_to_indirect(void *ptr)
90930 {
90931 diff --git a/lib/random32.c b/lib/random32.c
90932 index 6148967..009bfe8 100644
90933 --- a/lib/random32.c
90934 +++ b/lib/random32.c
90935 @@ -44,7 +44,7 @@
90936 static void __init prandom_state_selftest(void);
90937 #endif
90938
90939 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
90940 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
90941
90942 /**
90943 * prandom_u32_state - seeded pseudo-random number generator.
90944 diff --git a/lib/rbtree.c b/lib/rbtree.c
90945 index 65f4eff..2cfa167 100644
90946 --- a/lib/rbtree.c
90947 +++ b/lib/rbtree.c
90948 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
90949 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
90950
90951 static const struct rb_augment_callbacks dummy_callbacks = {
90952 - dummy_propagate, dummy_copy, dummy_rotate
90953 + .propagate = dummy_propagate,
90954 + .copy = dummy_copy,
90955 + .rotate = dummy_rotate
90956 };
90957
90958 void rb_insert_color(struct rb_node *node, struct rb_root *root)
90959 diff --git a/lib/show_mem.c b/lib/show_mem.c
90960 index 0922579..9d7adb9 100644
90961 --- a/lib/show_mem.c
90962 +++ b/lib/show_mem.c
90963 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
90964 quicklist_total_size());
90965 #endif
90966 #ifdef CONFIG_MEMORY_FAILURE
90967 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
90968 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
90969 #endif
90970 }
90971 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
90972 index bb2b201..46abaf9 100644
90973 --- a/lib/strncpy_from_user.c
90974 +++ b/lib/strncpy_from_user.c
90975 @@ -21,7 +21,7 @@
90976 */
90977 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
90978 {
90979 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90980 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90981 long res = 0;
90982
90983 /*
90984 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
90985 index a28df52..3d55877 100644
90986 --- a/lib/strnlen_user.c
90987 +++ b/lib/strnlen_user.c
90988 @@ -26,7 +26,7 @@
90989 */
90990 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
90991 {
90992 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90993 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90994 long align, res = 0;
90995 unsigned long c;
90996
90997 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
90998 index b604b83..c0547f6 100644
90999 --- a/lib/swiotlb.c
91000 +++ b/lib/swiotlb.c
91001 @@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91002
91003 void
91004 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91005 - dma_addr_t dev_addr)
91006 + dma_addr_t dev_addr, struct dma_attrs *attrs)
91007 {
91008 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91009
91010 diff --git a/lib/usercopy.c b/lib/usercopy.c
91011 index 4f5b1dd..7cab418 100644
91012 --- a/lib/usercopy.c
91013 +++ b/lib/usercopy.c
91014 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91015 WARN(1, "Buffer overflow detected!\n");
91016 }
91017 EXPORT_SYMBOL(copy_from_user_overflow);
91018 +
91019 +void copy_to_user_overflow(void)
91020 +{
91021 + WARN(1, "Buffer overflow detected!\n");
91022 +}
91023 +EXPORT_SYMBOL(copy_to_user_overflow);
91024 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91025 index 185b6d3..823c48c 100644
91026 --- a/lib/vsprintf.c
91027 +++ b/lib/vsprintf.c
91028 @@ -16,6 +16,9 @@
91029 * - scnprintf and vscnprintf
91030 */
91031
91032 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91033 +#define __INCLUDED_BY_HIDESYM 1
91034 +#endif
91035 #include <stdarg.h>
91036 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91037 #include <linux/types.h>
91038 @@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
91039 return number(buf, end, num, spec);
91040 }
91041
91042 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91043 +int kptr_restrict __read_mostly = 2;
91044 +#else
91045 int kptr_restrict __read_mostly;
91046 +#endif
91047
91048 /*
91049 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91050 @@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
91051 * - 'f' For simple symbolic function names without offset
91052 * - 'S' For symbolic direct pointers with offset
91053 * - 's' For symbolic direct pointers without offset
91054 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
91055 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
91056 * - 'B' For backtraced symbolic direct pointers with offset
91057 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
91058 @@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91059
91060 if (!ptr && *fmt != 'K') {
91061 /*
91062 - * Print (null) with the same width as a pointer so it makes
91063 + * Print (nil) with the same width as a pointer so it makes
91064 * tabular output look nice.
91065 */
91066 if (spec.field_width == -1)
91067 spec.field_width = default_width;
91068 - return string(buf, end, "(null)", spec);
91069 + return string(buf, end, "(nil)", spec);
91070 }
91071
91072 switch (*fmt) {
91073 @@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91074 /* Fallthrough */
91075 case 'S':
91076 case 's':
91077 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91078 + break;
91079 +#else
91080 + return symbol_string(buf, end, ptr, spec, fmt);
91081 +#endif
91082 + case 'A':
91083 case 'B':
91084 return symbol_string(buf, end, ptr, spec, fmt);
91085 case 'R':
91086 @@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91087 va_end(va);
91088 return buf;
91089 }
91090 + case 'P':
91091 + break;
91092 case 'K':
91093 /*
91094 * %pK cannot be used in IRQ context because its test
91095 @@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91096 ((const struct file *)ptr)->f_path.dentry,
91097 spec, fmt);
91098 }
91099 +
91100 +#ifdef CONFIG_GRKERNSEC_HIDESYM
91101 + /* 'P' = approved pointers to copy to userland,
91102 + as in the /proc/kallsyms case, as we make it display nothing
91103 + for non-root users, and the real contents for root users
91104 + Also ignore 'K' pointers, since we force their NULLing for non-root users
91105 + above
91106 + */
91107 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
91108 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
91109 + dump_stack();
91110 + ptr = NULL;
91111 + }
91112 +#endif
91113 +
91114 spec.flags |= SMALL;
91115 if (spec.field_width == -1) {
91116 spec.field_width = default_width;
91117 @@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91118 typeof(type) value; \
91119 if (sizeof(type) == 8) { \
91120 args = PTR_ALIGN(args, sizeof(u32)); \
91121 - *(u32 *)&value = *(u32 *)args; \
91122 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
91123 + *(u32 *)&value = *(const u32 *)args; \
91124 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
91125 } else { \
91126 args = PTR_ALIGN(args, sizeof(type)); \
91127 - value = *(typeof(type) *)args; \
91128 + value = *(const typeof(type) *)args; \
91129 } \
91130 args += sizeof(type); \
91131 value; \
91132 @@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91133 case FORMAT_TYPE_STR: {
91134 const char *str_arg = args;
91135 args += strlen(str_arg) + 1;
91136 - str = string(str, end, (char *)str_arg, spec);
91137 + str = string(str, end, str_arg, spec);
91138 break;
91139 }
91140
91141 diff --git a/localversion-grsec b/localversion-grsec
91142 new file mode 100644
91143 index 0000000..7cd6065
91144 --- /dev/null
91145 +++ b/localversion-grsec
91146 @@ -0,0 +1 @@
91147 +-grsec
91148 diff --git a/mm/Kconfig b/mm/Kconfig
91149 index 2888024..c15a810 100644
91150 --- a/mm/Kconfig
91151 +++ b/mm/Kconfig
91152 @@ -326,10 +326,11 @@ config KSM
91153 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91154
91155 config DEFAULT_MMAP_MIN_ADDR
91156 - int "Low address space to protect from user allocation"
91157 + int "Low address space to protect from user allocation"
91158 depends on MMU
91159 - default 4096
91160 - help
91161 + default 32768 if ALPHA || ARM || PARISC || SPARC32
91162 + default 65536
91163 + help
91164 This is the portion of low virtual memory which should be protected
91165 from userspace allocation. Keeping a user from writing to low pages
91166 can help reduce the impact of kernel NULL pointer bugs.
91167 @@ -360,7 +361,7 @@ config MEMORY_FAILURE
91168
91169 config HWPOISON_INJECT
91170 tristate "HWPoison pages injector"
91171 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91172 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91173 select PROC_PAGE_MONITOR
91174
91175 config NOMMU_INITIAL_TRIM_EXCESS
91176 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91177 index ce682f7..1fb54f9 100644
91178 --- a/mm/backing-dev.c
91179 +++ b/mm/backing-dev.c
91180 @@ -12,7 +12,7 @@
91181 #include <linux/device.h>
91182 #include <trace/events/writeback.h>
91183
91184 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91185 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91186
91187 struct backing_dev_info default_backing_dev_info = {
91188 .name = "default",
91189 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91190 return err;
91191
91192 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91193 - atomic_long_inc_return(&bdi_seq));
91194 + atomic_long_inc_return_unchecked(&bdi_seq));
91195 if (err) {
91196 bdi_destroy(bdi);
91197 return err;
91198 diff --git a/mm/filemap.c b/mm/filemap.c
91199 index 7a13f6a..e52e841 100644
91200 --- a/mm/filemap.c
91201 +++ b/mm/filemap.c
91202 @@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91203 struct address_space *mapping = file->f_mapping;
91204
91205 if (!mapping->a_ops->readpage)
91206 - return -ENOEXEC;
91207 + return -ENODEV;
91208 file_accessed(file);
91209 vma->vm_ops = &generic_file_vm_ops;
91210 return 0;
91211 @@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91212
91213 while (bytes) {
91214 char __user *buf = iov->iov_base + base;
91215 - int copy = min(bytes, iov->iov_len - base);
91216 + size_t copy = min(bytes, iov->iov_len - base);
91217
91218 base = 0;
91219 left = __copy_from_user_inatomic(vaddr, buf, copy);
91220 @@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91221 BUG_ON(!in_atomic());
91222 kaddr = kmap_atomic(page);
91223 if (likely(i->nr_segs == 1)) {
91224 - int left;
91225 + size_t left;
91226 char __user *buf = i->iov->iov_base + i->iov_offset;
91227 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91228 copied = bytes - left;
91229 @@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91230
91231 kaddr = kmap(page);
91232 if (likely(i->nr_segs == 1)) {
91233 - int left;
91234 + size_t left;
91235 char __user *buf = i->iov->iov_base + i->iov_offset;
91236 left = __copy_from_user(kaddr + offset, buf, bytes);
91237 copied = bytes - left;
91238 @@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91239 * zero-length segments (without overruning the iovec).
91240 */
91241 while (bytes || unlikely(i->count && !iov->iov_len)) {
91242 - int copy;
91243 + size_t copy;
91244
91245 copy = min(bytes, iov->iov_len - base);
91246 BUG_ON(!i->count || i->count < copy);
91247 @@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91248 *pos = i_size_read(inode);
91249
91250 if (limit != RLIM_INFINITY) {
91251 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91252 if (*pos >= limit) {
91253 send_sig(SIGXFSZ, current, 0);
91254 return -EFBIG;
91255 diff --git a/mm/fremap.c b/mm/fremap.c
91256 index 34feba6..315fe78 100644
91257 --- a/mm/fremap.c
91258 +++ b/mm/fremap.c
91259 @@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91260 retry:
91261 vma = find_vma(mm, start);
91262
91263 +#ifdef CONFIG_PAX_SEGMEXEC
91264 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91265 + goto out;
91266 +#endif
91267 +
91268 /*
91269 * Make sure the vma is shared, that it supports prefaulting,
91270 * and that the remapped range is valid and fully within
91271 diff --git a/mm/highmem.c b/mm/highmem.c
91272 index b32b70c..e512eb0 100644
91273 --- a/mm/highmem.c
91274 +++ b/mm/highmem.c
91275 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91276 * So no dangers, even with speculative execution.
91277 */
91278 page = pte_page(pkmap_page_table[i]);
91279 + pax_open_kernel();
91280 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91281 -
91282 + pax_close_kernel();
91283 set_page_address(page, NULL);
91284 need_flush = 1;
91285 }
91286 @@ -198,9 +199,11 @@ start:
91287 }
91288 }
91289 vaddr = PKMAP_ADDR(last_pkmap_nr);
91290 +
91291 + pax_open_kernel();
91292 set_pte_at(&init_mm, vaddr,
91293 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91294 -
91295 + pax_close_kernel();
91296 pkmap_count[last_pkmap_nr] = 1;
91297 set_page_address(page, (void *)vaddr);
91298
91299 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91300 index c01cb9f..ac0f58e 100644
91301 --- a/mm/hugetlb.c
91302 +++ b/mm/hugetlb.c
91303 @@ -2068,15 +2068,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91304 struct hstate *h = &default_hstate;
91305 unsigned long tmp;
91306 int ret;
91307 + ctl_table_no_const hugetlb_table;
91308
91309 tmp = h->max_huge_pages;
91310
91311 if (write && h->order >= MAX_ORDER)
91312 return -EINVAL;
91313
91314 - table->data = &tmp;
91315 - table->maxlen = sizeof(unsigned long);
91316 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91317 + hugetlb_table = *table;
91318 + hugetlb_table.data = &tmp;
91319 + hugetlb_table.maxlen = sizeof(unsigned long);
91320 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91321 if (ret)
91322 goto out;
91323
91324 @@ -2121,15 +2123,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91325 struct hstate *h = &default_hstate;
91326 unsigned long tmp;
91327 int ret;
91328 + ctl_table_no_const hugetlb_table;
91329
91330 tmp = h->nr_overcommit_huge_pages;
91331
91332 if (write && h->order >= MAX_ORDER)
91333 return -EINVAL;
91334
91335 - table->data = &tmp;
91336 - table->maxlen = sizeof(unsigned long);
91337 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91338 + hugetlb_table = *table;
91339 + hugetlb_table.data = &tmp;
91340 + hugetlb_table.maxlen = sizeof(unsigned long);
91341 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91342 if (ret)
91343 goto out;
91344
91345 @@ -2598,6 +2602,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
91346 return 1;
91347 }
91348
91349 +#ifdef CONFIG_PAX_SEGMEXEC
91350 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
91351 +{
91352 + struct mm_struct *mm = vma->vm_mm;
91353 + struct vm_area_struct *vma_m;
91354 + unsigned long address_m;
91355 + pte_t *ptep_m;
91356 +
91357 + vma_m = pax_find_mirror_vma(vma);
91358 + if (!vma_m)
91359 + return;
91360 +
91361 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91362 + address_m = address + SEGMEXEC_TASK_SIZE;
91363 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
91364 + get_page(page_m);
91365 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
91366 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
91367 +}
91368 +#endif
91369 +
91370 /*
91371 * Hugetlb_cow() should be called with page lock of the original hugepage held.
91372 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
91373 @@ -2714,6 +2739,11 @@ retry_avoidcopy:
91374 make_huge_pte(vma, new_page, 1));
91375 page_remove_rmap(old_page);
91376 hugepage_add_new_anon_rmap(new_page, vma, address);
91377 +
91378 +#ifdef CONFIG_PAX_SEGMEXEC
91379 + pax_mirror_huge_pte(vma, address, new_page);
91380 +#endif
91381 +
91382 /* Make the old page be freed below */
91383 new_page = old_page;
91384 }
91385 @@ -2878,6 +2908,10 @@ retry:
91386 && (vma->vm_flags & VM_SHARED)));
91387 set_huge_pte_at(mm, address, ptep, new_pte);
91388
91389 +#ifdef CONFIG_PAX_SEGMEXEC
91390 + pax_mirror_huge_pte(vma, address, page);
91391 +#endif
91392 +
91393 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
91394 /* Optimization, do the COW without a second fault */
91395 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
91396 @@ -2908,6 +2942,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91397 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
91398 struct hstate *h = hstate_vma(vma);
91399
91400 +#ifdef CONFIG_PAX_SEGMEXEC
91401 + struct vm_area_struct *vma_m;
91402 +#endif
91403 +
91404 address &= huge_page_mask(h);
91405
91406 ptep = huge_pte_offset(mm, address);
91407 @@ -2921,6 +2959,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91408 VM_FAULT_SET_HINDEX(hstate_index(h));
91409 }
91410
91411 +#ifdef CONFIG_PAX_SEGMEXEC
91412 + vma_m = pax_find_mirror_vma(vma);
91413 + if (vma_m) {
91414 + unsigned long address_m;
91415 +
91416 + if (vma->vm_start > vma_m->vm_start) {
91417 + address_m = address;
91418 + address -= SEGMEXEC_TASK_SIZE;
91419 + vma = vma_m;
91420 + h = hstate_vma(vma);
91421 + } else
91422 + address_m = address + SEGMEXEC_TASK_SIZE;
91423 +
91424 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
91425 + return VM_FAULT_OOM;
91426 + address_m &= HPAGE_MASK;
91427 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
91428 + }
91429 +#endif
91430 +
91431 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
91432 if (!ptep)
91433 return VM_FAULT_OOM;
91434 diff --git a/mm/internal.h b/mm/internal.h
91435 index 29e1e76..fc3ff04 100644
91436 --- a/mm/internal.h
91437 +++ b/mm/internal.h
91438 @@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
91439 * in mm/page_alloc.c
91440 */
91441 extern void __free_pages_bootmem(struct page *page, unsigned int order);
91442 +extern void free_compound_page(struct page *page);
91443 extern void prep_compound_page(struct page *page, unsigned long order);
91444 #ifdef CONFIG_MEMORY_FAILURE
91445 extern bool is_free_buddy_page(struct page *page);
91446 @@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
91447
91448 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
91449 unsigned long, unsigned long,
91450 - unsigned long, unsigned long);
91451 + unsigned long, unsigned long) __intentional_overflow(-1);
91452
91453 extern void set_pageblock_order(void);
91454 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
91455 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
91456 index 31f01c5..7015178 100644
91457 --- a/mm/kmemleak.c
91458 +++ b/mm/kmemleak.c
91459 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
91460
91461 for (i = 0; i < object->trace_len; i++) {
91462 void *ptr = (void *)object->trace[i];
91463 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
91464 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
91465 }
91466 }
91467
91468 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
91469 return -ENOMEM;
91470 }
91471
91472 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
91473 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
91474 &kmemleak_fops);
91475 if (!dentry)
91476 pr_warning("Failed to create the debugfs kmemleak file\n");
91477 diff --git a/mm/maccess.c b/mm/maccess.c
91478 index d53adf9..03a24bf 100644
91479 --- a/mm/maccess.c
91480 +++ b/mm/maccess.c
91481 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
91482 set_fs(KERNEL_DS);
91483 pagefault_disable();
91484 ret = __copy_from_user_inatomic(dst,
91485 - (__force const void __user *)src, size);
91486 + (const void __force_user *)src, size);
91487 pagefault_enable();
91488 set_fs(old_fs);
91489
91490 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
91491
91492 set_fs(KERNEL_DS);
91493 pagefault_disable();
91494 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
91495 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
91496 pagefault_enable();
91497 set_fs(old_fs);
91498
91499 diff --git a/mm/madvise.c b/mm/madvise.c
91500 index 539eeb9..e24a987 100644
91501 --- a/mm/madvise.c
91502 +++ b/mm/madvise.c
91503 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
91504 pgoff_t pgoff;
91505 unsigned long new_flags = vma->vm_flags;
91506
91507 +#ifdef CONFIG_PAX_SEGMEXEC
91508 + struct vm_area_struct *vma_m;
91509 +#endif
91510 +
91511 switch (behavior) {
91512 case MADV_NORMAL:
91513 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
91514 @@ -126,6 +130,13 @@ success:
91515 /*
91516 * vm_flags is protected by the mmap_sem held in write mode.
91517 */
91518 +
91519 +#ifdef CONFIG_PAX_SEGMEXEC
91520 + vma_m = pax_find_mirror_vma(vma);
91521 + if (vma_m)
91522 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
91523 +#endif
91524 +
91525 vma->vm_flags = new_flags;
91526
91527 out:
91528 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91529 struct vm_area_struct **prev,
91530 unsigned long start, unsigned long end)
91531 {
91532 +
91533 +#ifdef CONFIG_PAX_SEGMEXEC
91534 + struct vm_area_struct *vma_m;
91535 +#endif
91536 +
91537 *prev = vma;
91538 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
91539 return -EINVAL;
91540 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91541 zap_page_range(vma, start, end - start, &details);
91542 } else
91543 zap_page_range(vma, start, end - start, NULL);
91544 +
91545 +#ifdef CONFIG_PAX_SEGMEXEC
91546 + vma_m = pax_find_mirror_vma(vma);
91547 + if (vma_m) {
91548 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
91549 + struct zap_details details = {
91550 + .nonlinear_vma = vma_m,
91551 + .last_index = ULONG_MAX,
91552 + };
91553 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
91554 + } else
91555 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
91556 + }
91557 +#endif
91558 +
91559 return 0;
91560 }
91561
91562 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
91563 if (end < start)
91564 return error;
91565
91566 +#ifdef CONFIG_PAX_SEGMEXEC
91567 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
91568 + if (end > SEGMEXEC_TASK_SIZE)
91569 + return error;
91570 + } else
91571 +#endif
91572 +
91573 + if (end > TASK_SIZE)
91574 + return error;
91575 +
91576 error = 0;
91577 if (end == start)
91578 return error;
91579 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
91580 index 90002ea..db1452d 100644
91581 --- a/mm/memory-failure.c
91582 +++ b/mm/memory-failure.c
91583 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
91584
91585 int sysctl_memory_failure_recovery __read_mostly = 1;
91586
91587 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91588 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91589
91590 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
91591
91592 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
91593 pfn, t->comm, t->pid);
91594 si.si_signo = SIGBUS;
91595 si.si_errno = 0;
91596 - si.si_addr = (void *)addr;
91597 + si.si_addr = (void __user *)addr;
91598 #ifdef __ARCH_SI_TRAPNO
91599 si.si_trapno = trapno;
91600 #endif
91601 @@ -762,7 +762,7 @@ static struct page_state {
91602 unsigned long res;
91603 char *msg;
91604 int (*action)(struct page *p, unsigned long pfn);
91605 -} error_states[] = {
91606 +} __do_const error_states[] = {
91607 { reserved, reserved, "reserved kernel", me_kernel },
91608 /*
91609 * free pages are specially detected outside this table:
91610 @@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91611 nr_pages = 1 << compound_order(hpage);
91612 else /* normal page or thp */
91613 nr_pages = 1;
91614 - atomic_long_add(nr_pages, &num_poisoned_pages);
91615 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
91616
91617 /*
91618 * We need/can do nothing about count=0 pages.
91619 @@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91620 if (!PageHWPoison(hpage)
91621 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
91622 || (p != hpage && TestSetPageHWPoison(hpage))) {
91623 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91624 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91625 return 0;
91626 }
91627 set_page_hwpoison_huge_page(hpage);
91628 @@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91629 }
91630 if (hwpoison_filter(p)) {
91631 if (TestClearPageHWPoison(p))
91632 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91633 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91634 unlock_page(hpage);
91635 put_page(hpage);
91636 return 0;
91637 @@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
91638 return 0;
91639 }
91640 if (TestClearPageHWPoison(p))
91641 - atomic_long_dec(&num_poisoned_pages);
91642 + atomic_long_dec_unchecked(&num_poisoned_pages);
91643 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
91644 return 0;
91645 }
91646 @@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
91647 */
91648 if (TestClearPageHWPoison(page)) {
91649 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
91650 - atomic_long_sub(nr_pages, &num_poisoned_pages);
91651 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91652 freeit = 1;
91653 if (PageHuge(page))
91654 clear_page_hwpoison_huge_page(page);
91655 @@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
91656 if (PageHuge(page)) {
91657 set_page_hwpoison_huge_page(hpage);
91658 dequeue_hwpoisoned_huge_page(hpage);
91659 - atomic_long_add(1 << compound_order(hpage),
91660 + atomic_long_add_unchecked(1 << compound_order(hpage),
91661 &num_poisoned_pages);
91662 } else {
91663 SetPageHWPoison(page);
91664 - atomic_long_inc(&num_poisoned_pages);
91665 + atomic_long_inc_unchecked(&num_poisoned_pages);
91666 }
91667 }
91668 return ret;
91669 @@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
91670 put_page(page);
91671 pr_info("soft_offline: %#lx: invalidated\n", pfn);
91672 SetPageHWPoison(page);
91673 - atomic_long_inc(&num_poisoned_pages);
91674 + atomic_long_inc_unchecked(&num_poisoned_pages);
91675 return 0;
91676 }
91677
91678 @@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
91679 if (!is_free_buddy_page(page))
91680 pr_info("soft offline: %#lx: page leaked\n",
91681 pfn);
91682 - atomic_long_inc(&num_poisoned_pages);
91683 + atomic_long_inc_unchecked(&num_poisoned_pages);
91684 }
91685 } else {
91686 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
91687 @@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
91688 if (PageHuge(page)) {
91689 set_page_hwpoison_huge_page(hpage);
91690 dequeue_hwpoisoned_huge_page(hpage);
91691 - atomic_long_add(1 << compound_order(hpage),
91692 + atomic_long_add_unchecked(1 << compound_order(hpage),
91693 &num_poisoned_pages);
91694 } else {
91695 SetPageHWPoison(page);
91696 - atomic_long_inc(&num_poisoned_pages);
91697 + atomic_long_inc_unchecked(&num_poisoned_pages);
91698 }
91699 }
91700 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
91701 diff --git a/mm/memory.c b/mm/memory.c
91702 index 22dfa61..e8a9ac2 100644
91703 --- a/mm/memory.c
91704 +++ b/mm/memory.c
91705 @@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91706 free_pte_range(tlb, pmd, addr);
91707 } while (pmd++, addr = next, addr != end);
91708
91709 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
91710 start &= PUD_MASK;
91711 if (start < floor)
91712 return;
91713 @@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91714 pmd = pmd_offset(pud, start);
91715 pud_clear(pud);
91716 pmd_free_tlb(tlb, pmd, start);
91717 +#endif
91718 +
91719 }
91720
91721 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91722 @@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91723 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
91724 } while (pud++, addr = next, addr != end);
91725
91726 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
91727 start &= PGDIR_MASK;
91728 if (start < floor)
91729 return;
91730 @@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91731 pud = pud_offset(pgd, start);
91732 pgd_clear(pgd);
91733 pud_free_tlb(tlb, pud, start);
91734 +#endif
91735 +
91736 }
91737
91738 /*
91739 @@ -1636,12 +1642,6 @@ no_page_table:
91740 return page;
91741 }
91742
91743 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
91744 -{
91745 - return stack_guard_page_start(vma, addr) ||
91746 - stack_guard_page_end(vma, addr+PAGE_SIZE);
91747 -}
91748 -
91749 /**
91750 * __get_user_pages() - pin user pages in memory
91751 * @tsk: task_struct of target task
91752 @@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91753
91754 i = 0;
91755
91756 - do {
91757 + while (nr_pages) {
91758 struct vm_area_struct *vma;
91759
91760 - vma = find_extend_vma(mm, start);
91761 + vma = find_vma(mm, start);
91762 if (!vma && in_gate_area(mm, start)) {
91763 unsigned long pg = start & PAGE_MASK;
91764 pgd_t *pgd;
91765 @@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91766 goto next_page;
91767 }
91768
91769 - if (!vma ||
91770 + if (!vma || start < vma->vm_start ||
91771 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
91772 !(vm_flags & vma->vm_flags))
91773 return i ? : -EFAULT;
91774 @@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91775 int ret;
91776 unsigned int fault_flags = 0;
91777
91778 - /* For mlock, just skip the stack guard page. */
91779 - if (foll_flags & FOLL_MLOCK) {
91780 - if (stack_guard_page(vma, start))
91781 - goto next_page;
91782 - }
91783 if (foll_flags & FOLL_WRITE)
91784 fault_flags |= FAULT_FLAG_WRITE;
91785 if (nonblocking)
91786 @@ -1893,7 +1888,7 @@ next_page:
91787 start += page_increm * PAGE_SIZE;
91788 nr_pages -= page_increm;
91789 } while (nr_pages && start < vma->vm_end);
91790 - } while (nr_pages);
91791 + }
91792 return i;
91793 }
91794 EXPORT_SYMBOL(__get_user_pages);
91795 @@ -2100,6 +2095,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
91796 page_add_file_rmap(page);
91797 set_pte_at(mm, addr, pte, mk_pte(page, prot));
91798
91799 +#ifdef CONFIG_PAX_SEGMEXEC
91800 + pax_mirror_file_pte(vma, addr, page, ptl);
91801 +#endif
91802 +
91803 retval = 0;
91804 pte_unmap_unlock(pte, ptl);
91805 return retval;
91806 @@ -2144,9 +2143,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
91807 if (!page_count(page))
91808 return -EINVAL;
91809 if (!(vma->vm_flags & VM_MIXEDMAP)) {
91810 +
91811 +#ifdef CONFIG_PAX_SEGMEXEC
91812 + struct vm_area_struct *vma_m;
91813 +#endif
91814 +
91815 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
91816 BUG_ON(vma->vm_flags & VM_PFNMAP);
91817 vma->vm_flags |= VM_MIXEDMAP;
91818 +
91819 +#ifdef CONFIG_PAX_SEGMEXEC
91820 + vma_m = pax_find_mirror_vma(vma);
91821 + if (vma_m)
91822 + vma_m->vm_flags |= VM_MIXEDMAP;
91823 +#endif
91824 +
91825 }
91826 return insert_page(vma, addr, page, vma->vm_page_prot);
91827 }
91828 @@ -2229,6 +2240,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
91829 unsigned long pfn)
91830 {
91831 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
91832 + BUG_ON(vma->vm_mirror);
91833
91834 if (addr < vma->vm_start || addr >= vma->vm_end)
91835 return -EFAULT;
91836 @@ -2476,7 +2488,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
91837
91838 BUG_ON(pud_huge(*pud));
91839
91840 - pmd = pmd_alloc(mm, pud, addr);
91841 + pmd = (mm == &init_mm) ?
91842 + pmd_alloc_kernel(mm, pud, addr) :
91843 + pmd_alloc(mm, pud, addr);
91844 if (!pmd)
91845 return -ENOMEM;
91846 do {
91847 @@ -2496,7 +2510,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
91848 unsigned long next;
91849 int err;
91850
91851 - pud = pud_alloc(mm, pgd, addr);
91852 + pud = (mm == &init_mm) ?
91853 + pud_alloc_kernel(mm, pgd, addr) :
91854 + pud_alloc(mm, pgd, addr);
91855 if (!pud)
91856 return -ENOMEM;
91857 do {
91858 @@ -2586,6 +2602,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
91859 copy_user_highpage(dst, src, va, vma);
91860 }
91861
91862 +#ifdef CONFIG_PAX_SEGMEXEC
91863 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
91864 +{
91865 + struct mm_struct *mm = vma->vm_mm;
91866 + spinlock_t *ptl;
91867 + pte_t *pte, entry;
91868 +
91869 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
91870 + entry = *pte;
91871 + if (!pte_present(entry)) {
91872 + if (!pte_none(entry)) {
91873 + BUG_ON(pte_file(entry));
91874 + free_swap_and_cache(pte_to_swp_entry(entry));
91875 + pte_clear_not_present_full(mm, address, pte, 0);
91876 + }
91877 + } else {
91878 + struct page *page;
91879 +
91880 + flush_cache_page(vma, address, pte_pfn(entry));
91881 + entry = ptep_clear_flush(vma, address, pte);
91882 + BUG_ON(pte_dirty(entry));
91883 + page = vm_normal_page(vma, address, entry);
91884 + if (page) {
91885 + update_hiwater_rss(mm);
91886 + if (PageAnon(page))
91887 + dec_mm_counter_fast(mm, MM_ANONPAGES);
91888 + else
91889 + dec_mm_counter_fast(mm, MM_FILEPAGES);
91890 + page_remove_rmap(page);
91891 + page_cache_release(page);
91892 + }
91893 + }
91894 + pte_unmap_unlock(pte, ptl);
91895 +}
91896 +
91897 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
91898 + *
91899 + * the ptl of the lower mapped page is held on entry and is not released on exit
91900 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
91901 + */
91902 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
91903 +{
91904 + struct mm_struct *mm = vma->vm_mm;
91905 + unsigned long address_m;
91906 + spinlock_t *ptl_m;
91907 + struct vm_area_struct *vma_m;
91908 + pmd_t *pmd_m;
91909 + pte_t *pte_m, entry_m;
91910 +
91911 + BUG_ON(!page_m || !PageAnon(page_m));
91912 +
91913 + vma_m = pax_find_mirror_vma(vma);
91914 + if (!vma_m)
91915 + return;
91916 +
91917 + BUG_ON(!PageLocked(page_m));
91918 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91919 + address_m = address + SEGMEXEC_TASK_SIZE;
91920 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91921 + pte_m = pte_offset_map(pmd_m, address_m);
91922 + ptl_m = pte_lockptr(mm, pmd_m);
91923 + if (ptl != ptl_m) {
91924 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91925 + if (!pte_none(*pte_m))
91926 + goto out;
91927 + }
91928 +
91929 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
91930 + page_cache_get(page_m);
91931 + page_add_anon_rmap(page_m, vma_m, address_m);
91932 + inc_mm_counter_fast(mm, MM_ANONPAGES);
91933 + set_pte_at(mm, address_m, pte_m, entry_m);
91934 + update_mmu_cache(vma_m, address_m, pte_m);
91935 +out:
91936 + if (ptl != ptl_m)
91937 + spin_unlock(ptl_m);
91938 + pte_unmap(pte_m);
91939 + unlock_page(page_m);
91940 +}
91941 +
91942 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
91943 +{
91944 + struct mm_struct *mm = vma->vm_mm;
91945 + unsigned long address_m;
91946 + spinlock_t *ptl_m;
91947 + struct vm_area_struct *vma_m;
91948 + pmd_t *pmd_m;
91949 + pte_t *pte_m, entry_m;
91950 +
91951 + BUG_ON(!page_m || PageAnon(page_m));
91952 +
91953 + vma_m = pax_find_mirror_vma(vma);
91954 + if (!vma_m)
91955 + return;
91956 +
91957 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91958 + address_m = address + SEGMEXEC_TASK_SIZE;
91959 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91960 + pte_m = pte_offset_map(pmd_m, address_m);
91961 + ptl_m = pte_lockptr(mm, pmd_m);
91962 + if (ptl != ptl_m) {
91963 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91964 + if (!pte_none(*pte_m))
91965 + goto out;
91966 + }
91967 +
91968 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
91969 + page_cache_get(page_m);
91970 + page_add_file_rmap(page_m);
91971 + inc_mm_counter_fast(mm, MM_FILEPAGES);
91972 + set_pte_at(mm, address_m, pte_m, entry_m);
91973 + update_mmu_cache(vma_m, address_m, pte_m);
91974 +out:
91975 + if (ptl != ptl_m)
91976 + spin_unlock(ptl_m);
91977 + pte_unmap(pte_m);
91978 +}
91979 +
91980 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
91981 +{
91982 + struct mm_struct *mm = vma->vm_mm;
91983 + unsigned long address_m;
91984 + spinlock_t *ptl_m;
91985 + struct vm_area_struct *vma_m;
91986 + pmd_t *pmd_m;
91987 + pte_t *pte_m, entry_m;
91988 +
91989 + vma_m = pax_find_mirror_vma(vma);
91990 + if (!vma_m)
91991 + return;
91992 +
91993 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91994 + address_m = address + SEGMEXEC_TASK_SIZE;
91995 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91996 + pte_m = pte_offset_map(pmd_m, address_m);
91997 + ptl_m = pte_lockptr(mm, pmd_m);
91998 + if (ptl != ptl_m) {
91999 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92000 + if (!pte_none(*pte_m))
92001 + goto out;
92002 + }
92003 +
92004 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92005 + set_pte_at(mm, address_m, pte_m, entry_m);
92006 +out:
92007 + if (ptl != ptl_m)
92008 + spin_unlock(ptl_m);
92009 + pte_unmap(pte_m);
92010 +}
92011 +
92012 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92013 +{
92014 + struct page *page_m;
92015 + pte_t entry;
92016 +
92017 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92018 + goto out;
92019 +
92020 + entry = *pte;
92021 + page_m = vm_normal_page(vma, address, entry);
92022 + if (!page_m)
92023 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92024 + else if (PageAnon(page_m)) {
92025 + if (pax_find_mirror_vma(vma)) {
92026 + pte_unmap_unlock(pte, ptl);
92027 + lock_page(page_m);
92028 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92029 + if (pte_same(entry, *pte))
92030 + pax_mirror_anon_pte(vma, address, page_m, ptl);
92031 + else
92032 + unlock_page(page_m);
92033 + }
92034 + } else
92035 + pax_mirror_file_pte(vma, address, page_m, ptl);
92036 +
92037 +out:
92038 + pte_unmap_unlock(pte, ptl);
92039 +}
92040 +#endif
92041 +
92042 /*
92043 * This routine handles present pages, when users try to write
92044 * to a shared page. It is done by copying the page to a new address
92045 @@ -2810,6 +3006,12 @@ gotten:
92046 */
92047 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92048 if (likely(pte_same(*page_table, orig_pte))) {
92049 +
92050 +#ifdef CONFIG_PAX_SEGMEXEC
92051 + if (pax_find_mirror_vma(vma))
92052 + BUG_ON(!trylock_page(new_page));
92053 +#endif
92054 +
92055 if (old_page) {
92056 if (!PageAnon(old_page)) {
92057 dec_mm_counter_fast(mm, MM_FILEPAGES);
92058 @@ -2861,6 +3063,10 @@ gotten:
92059 page_remove_rmap(old_page);
92060 }
92061
92062 +#ifdef CONFIG_PAX_SEGMEXEC
92063 + pax_mirror_anon_pte(vma, address, new_page, ptl);
92064 +#endif
92065 +
92066 /* Free the old page.. */
92067 new_page = old_page;
92068 ret |= VM_FAULT_WRITE;
92069 @@ -3138,6 +3344,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92070 swap_free(entry);
92071 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
92072 try_to_free_swap(page);
92073 +
92074 +#ifdef CONFIG_PAX_SEGMEXEC
92075 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
92076 +#endif
92077 +
92078 unlock_page(page);
92079 if (page != swapcache) {
92080 /*
92081 @@ -3161,6 +3372,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92082
92083 /* No need to invalidate - it was non-present before */
92084 update_mmu_cache(vma, address, page_table);
92085 +
92086 +#ifdef CONFIG_PAX_SEGMEXEC
92087 + pax_mirror_anon_pte(vma, address, page, ptl);
92088 +#endif
92089 +
92090 unlock:
92091 pte_unmap_unlock(page_table, ptl);
92092 out:
92093 @@ -3180,40 +3396,6 @@ out_release:
92094 }
92095
92096 /*
92097 - * This is like a special single-page "expand_{down|up}wards()",
92098 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
92099 - * doesn't hit another vma.
92100 - */
92101 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92102 -{
92103 - address &= PAGE_MASK;
92104 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92105 - struct vm_area_struct *prev = vma->vm_prev;
92106 -
92107 - /*
92108 - * Is there a mapping abutting this one below?
92109 - *
92110 - * That's only ok if it's the same stack mapping
92111 - * that has gotten split..
92112 - */
92113 - if (prev && prev->vm_end == address)
92114 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92115 -
92116 - expand_downwards(vma, address - PAGE_SIZE);
92117 - }
92118 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92119 - struct vm_area_struct *next = vma->vm_next;
92120 -
92121 - /* As VM_GROWSDOWN but s/below/above/ */
92122 - if (next && next->vm_start == address + PAGE_SIZE)
92123 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92124 -
92125 - expand_upwards(vma, address + PAGE_SIZE);
92126 - }
92127 - return 0;
92128 -}
92129 -
92130 -/*
92131 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92132 * but allow concurrent faults), and pte mapped but not yet locked.
92133 * We return with mmap_sem still held, but pte unmapped and unlocked.
92134 @@ -3222,27 +3404,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92135 unsigned long address, pte_t *page_table, pmd_t *pmd,
92136 unsigned int flags)
92137 {
92138 - struct page *page;
92139 + struct page *page = NULL;
92140 spinlock_t *ptl;
92141 pte_t entry;
92142
92143 - pte_unmap(page_table);
92144 -
92145 - /* Check if we need to add a guard page to the stack */
92146 - if (check_stack_guard_page(vma, address) < 0)
92147 - return VM_FAULT_SIGBUS;
92148 -
92149 - /* Use the zero-page for reads */
92150 if (!(flags & FAULT_FLAG_WRITE)) {
92151 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92152 vma->vm_page_prot));
92153 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92154 + ptl = pte_lockptr(mm, pmd);
92155 + spin_lock(ptl);
92156 if (!pte_none(*page_table))
92157 goto unlock;
92158 goto setpte;
92159 }
92160
92161 /* Allocate our own private page. */
92162 + pte_unmap(page_table);
92163 +
92164 if (unlikely(anon_vma_prepare(vma)))
92165 goto oom;
92166 page = alloc_zeroed_user_highpage_movable(vma, address);
92167 @@ -3266,6 +3444,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92168 if (!pte_none(*page_table))
92169 goto release;
92170
92171 +#ifdef CONFIG_PAX_SEGMEXEC
92172 + if (pax_find_mirror_vma(vma))
92173 + BUG_ON(!trylock_page(page));
92174 +#endif
92175 +
92176 inc_mm_counter_fast(mm, MM_ANONPAGES);
92177 page_add_new_anon_rmap(page, vma, address);
92178 setpte:
92179 @@ -3273,6 +3456,12 @@ setpte:
92180
92181 /* No need to invalidate - it was non-present before */
92182 update_mmu_cache(vma, address, page_table);
92183 +
92184 +#ifdef CONFIG_PAX_SEGMEXEC
92185 + if (page)
92186 + pax_mirror_anon_pte(vma, address, page, ptl);
92187 +#endif
92188 +
92189 unlock:
92190 pte_unmap_unlock(page_table, ptl);
92191 return 0;
92192 @@ -3417,6 +3606,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92193 */
92194 /* Only go through if we didn't race with anybody else... */
92195 if (likely(pte_same(*page_table, orig_pte))) {
92196 +
92197 +#ifdef CONFIG_PAX_SEGMEXEC
92198 + if (anon && pax_find_mirror_vma(vma))
92199 + BUG_ON(!trylock_page(page));
92200 +#endif
92201 +
92202 flush_icache_page(vma, page);
92203 entry = mk_pte(page, vma->vm_page_prot);
92204 if (flags & FAULT_FLAG_WRITE)
92205 @@ -3438,6 +3633,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92206
92207 /* no need to invalidate: a not-present page won't be cached */
92208 update_mmu_cache(vma, address, page_table);
92209 +
92210 +#ifdef CONFIG_PAX_SEGMEXEC
92211 + if (anon)
92212 + pax_mirror_anon_pte(vma, address, page, ptl);
92213 + else
92214 + pax_mirror_file_pte(vma, address, page, ptl);
92215 +#endif
92216 +
92217 } else {
92218 if (cow_page)
92219 mem_cgroup_uncharge_page(cow_page);
92220 @@ -3685,6 +3888,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92221 if (flags & FAULT_FLAG_WRITE)
92222 flush_tlb_fix_spurious_fault(vma, address);
92223 }
92224 +
92225 +#ifdef CONFIG_PAX_SEGMEXEC
92226 + pax_mirror_pte(vma, address, pte, pmd, ptl);
92227 + return 0;
92228 +#endif
92229 +
92230 unlock:
92231 pte_unmap_unlock(pte, ptl);
92232 return 0;
92233 @@ -3701,9 +3910,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92234 pmd_t *pmd;
92235 pte_t *pte;
92236
92237 +#ifdef CONFIG_PAX_SEGMEXEC
92238 + struct vm_area_struct *vma_m;
92239 +#endif
92240 +
92241 if (unlikely(is_vm_hugetlb_page(vma)))
92242 return hugetlb_fault(mm, vma, address, flags);
92243
92244 +#ifdef CONFIG_PAX_SEGMEXEC
92245 + vma_m = pax_find_mirror_vma(vma);
92246 + if (vma_m) {
92247 + unsigned long address_m;
92248 + pgd_t *pgd_m;
92249 + pud_t *pud_m;
92250 + pmd_t *pmd_m;
92251 +
92252 + if (vma->vm_start > vma_m->vm_start) {
92253 + address_m = address;
92254 + address -= SEGMEXEC_TASK_SIZE;
92255 + vma = vma_m;
92256 + } else
92257 + address_m = address + SEGMEXEC_TASK_SIZE;
92258 +
92259 + pgd_m = pgd_offset(mm, address_m);
92260 + pud_m = pud_alloc(mm, pgd_m, address_m);
92261 + if (!pud_m)
92262 + return VM_FAULT_OOM;
92263 + pmd_m = pmd_alloc(mm, pud_m, address_m);
92264 + if (!pmd_m)
92265 + return VM_FAULT_OOM;
92266 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92267 + return VM_FAULT_OOM;
92268 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92269 + }
92270 +#endif
92271 +
92272 pgd = pgd_offset(mm, address);
92273 pud = pud_alloc(mm, pgd, address);
92274 if (!pud)
92275 @@ -3834,6 +4075,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92276 spin_unlock(&mm->page_table_lock);
92277 return 0;
92278 }
92279 +
92280 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92281 +{
92282 + pud_t *new = pud_alloc_one(mm, address);
92283 + if (!new)
92284 + return -ENOMEM;
92285 +
92286 + smp_wmb(); /* See comment in __pte_alloc */
92287 +
92288 + spin_lock(&mm->page_table_lock);
92289 + if (pgd_present(*pgd)) /* Another has populated it */
92290 + pud_free(mm, new);
92291 + else
92292 + pgd_populate_kernel(mm, pgd, new);
92293 + spin_unlock(&mm->page_table_lock);
92294 + return 0;
92295 +}
92296 #endif /* __PAGETABLE_PUD_FOLDED */
92297
92298 #ifndef __PAGETABLE_PMD_FOLDED
92299 @@ -3864,6 +4122,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92300 spin_unlock(&mm->page_table_lock);
92301 return 0;
92302 }
92303 +
92304 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92305 +{
92306 + pmd_t *new = pmd_alloc_one(mm, address);
92307 + if (!new)
92308 + return -ENOMEM;
92309 +
92310 + smp_wmb(); /* See comment in __pte_alloc */
92311 +
92312 + spin_lock(&mm->page_table_lock);
92313 +#ifndef __ARCH_HAS_4LEVEL_HACK
92314 + if (pud_present(*pud)) /* Another has populated it */
92315 + pmd_free(mm, new);
92316 + else
92317 + pud_populate_kernel(mm, pud, new);
92318 +#else
92319 + if (pgd_present(*pud)) /* Another has populated it */
92320 + pmd_free(mm, new);
92321 + else
92322 + pgd_populate_kernel(mm, pud, new);
92323 +#endif /* __ARCH_HAS_4LEVEL_HACK */
92324 + spin_unlock(&mm->page_table_lock);
92325 + return 0;
92326 +}
92327 #endif /* __PAGETABLE_PMD_FOLDED */
92328
92329 #if !defined(__HAVE_ARCH_GATE_AREA)
92330 @@ -3877,7 +4159,7 @@ static int __init gate_vma_init(void)
92331 gate_vma.vm_start = FIXADDR_USER_START;
92332 gate_vma.vm_end = FIXADDR_USER_END;
92333 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
92334 - gate_vma.vm_page_prot = __P101;
92335 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
92336
92337 return 0;
92338 }
92339 @@ -4011,8 +4293,8 @@ out:
92340 return ret;
92341 }
92342
92343 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92344 - void *buf, int len, int write)
92345 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92346 + void *buf, size_t len, int write)
92347 {
92348 resource_size_t phys_addr;
92349 unsigned long prot = 0;
92350 @@ -4038,8 +4320,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
92351 * Access another process' address space as given in mm. If non-NULL, use the
92352 * given task for page fault accounting.
92353 */
92354 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92355 - unsigned long addr, void *buf, int len, int write)
92356 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92357 + unsigned long addr, void *buf, size_t len, int write)
92358 {
92359 struct vm_area_struct *vma;
92360 void *old_buf = buf;
92361 @@ -4047,7 +4329,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92362 down_read(&mm->mmap_sem);
92363 /* ignore errors, just check how much was successfully transferred */
92364 while (len) {
92365 - int bytes, ret, offset;
92366 + ssize_t bytes, ret, offset;
92367 void *maddr;
92368 struct page *page = NULL;
92369
92370 @@ -4106,8 +4388,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92371 *
92372 * The caller must hold a reference on @mm.
92373 */
92374 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92375 - void *buf, int len, int write)
92376 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92377 + void *buf, size_t len, int write)
92378 {
92379 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92380 }
92381 @@ -4117,11 +4399,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92382 * Source/target buffer must be kernel space,
92383 * Do not walk the page table directly, use get_user_pages
92384 */
92385 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
92386 - void *buf, int len, int write)
92387 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
92388 + void *buf, size_t len, int write)
92389 {
92390 struct mm_struct *mm;
92391 - int ret;
92392 + ssize_t ret;
92393
92394 mm = get_task_mm(tsk);
92395 if (!mm)
92396 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
92397 index ae3c8f3..fa4ee8e 100644
92398 --- a/mm/mempolicy.c
92399 +++ b/mm/mempolicy.c
92400 @@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92401 unsigned long vmstart;
92402 unsigned long vmend;
92403
92404 +#ifdef CONFIG_PAX_SEGMEXEC
92405 + struct vm_area_struct *vma_m;
92406 +#endif
92407 +
92408 vma = find_vma(mm, start);
92409 if (!vma || vma->vm_start > start)
92410 return -EFAULT;
92411 @@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92412 err = vma_replace_policy(vma, new_pol);
92413 if (err)
92414 goto out;
92415 +
92416 +#ifdef CONFIG_PAX_SEGMEXEC
92417 + vma_m = pax_find_mirror_vma(vma);
92418 + if (vma_m) {
92419 + err = vma_replace_policy(vma_m, new_pol);
92420 + if (err)
92421 + goto out;
92422 + }
92423 +#endif
92424 +
92425 }
92426
92427 out:
92428 @@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
92429
92430 if (end < start)
92431 return -EINVAL;
92432 +
92433 +#ifdef CONFIG_PAX_SEGMEXEC
92434 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92435 + if (end > SEGMEXEC_TASK_SIZE)
92436 + return -EINVAL;
92437 + } else
92438 +#endif
92439 +
92440 + if (end > TASK_SIZE)
92441 + return -EINVAL;
92442 +
92443 if (end == start)
92444 return 0;
92445
92446 @@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92447 */
92448 tcred = __task_cred(task);
92449 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92450 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92451 - !capable(CAP_SYS_NICE)) {
92452 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92453 rcu_read_unlock();
92454 err = -EPERM;
92455 goto out_put;
92456 @@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92457 goto out;
92458 }
92459
92460 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
92461 + if (mm != current->mm &&
92462 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
92463 + mmput(mm);
92464 + err = -EPERM;
92465 + goto out;
92466 + }
92467 +#endif
92468 +
92469 err = do_migrate_pages(mm, old, new,
92470 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
92471
92472 diff --git a/mm/migrate.c b/mm/migrate.c
92473 index bed4880..a493f67 100644
92474 --- a/mm/migrate.c
92475 +++ b/mm/migrate.c
92476 @@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
92477 */
92478 tcred = __task_cred(task);
92479 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92480 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92481 - !capable(CAP_SYS_NICE)) {
92482 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92483 rcu_read_unlock();
92484 err = -EPERM;
92485 goto out;
92486 diff --git a/mm/mlock.c b/mm/mlock.c
92487 index 4e1a6816..9683079 100644
92488 --- a/mm/mlock.c
92489 +++ b/mm/mlock.c
92490 @@ -14,6 +14,7 @@
92491 #include <linux/pagevec.h>
92492 #include <linux/mempolicy.h>
92493 #include <linux/syscalls.h>
92494 +#include <linux/security.h>
92495 #include <linux/sched.h>
92496 #include <linux/export.h>
92497 #include <linux/rmap.h>
92498 @@ -604,7 +605,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
92499 {
92500 unsigned long nstart, end, tmp;
92501 struct vm_area_struct * vma, * prev;
92502 - int error;
92503 + int error = 0;
92504
92505 VM_BUG_ON(start & ~PAGE_MASK);
92506 VM_BUG_ON(len != PAGE_ALIGN(len));
92507 @@ -613,6 +614,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
92508 return -EINVAL;
92509 if (end == start)
92510 return 0;
92511 + if (end > TASK_SIZE)
92512 + return -EINVAL;
92513 +
92514 vma = find_vma(current->mm, start);
92515 if (!vma || vma->vm_start > start)
92516 return -ENOMEM;
92517 @@ -624,6 +628,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
92518 for (nstart = start ; ; ) {
92519 vm_flags_t newflags;
92520
92521 +#ifdef CONFIG_PAX_SEGMEXEC
92522 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92523 + break;
92524 +#endif
92525 +
92526 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
92527
92528 newflags = vma->vm_flags & ~VM_LOCKED;
92529 @@ -737,6 +746,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
92530 locked += current->mm->locked_vm;
92531
92532 /* check against resource limits */
92533 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
92534 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
92535 error = do_mlock(start, len, 1);
92536
92537 @@ -774,6 +784,11 @@ static int do_mlockall(int flags)
92538 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
92539 vm_flags_t newflags;
92540
92541 +#ifdef CONFIG_PAX_SEGMEXEC
92542 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92543 + break;
92544 +#endif
92545 +
92546 newflags = vma->vm_flags & ~VM_LOCKED;
92547 if (flags & MCL_CURRENT)
92548 newflags |= VM_LOCKED;
92549 @@ -805,8 +820,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
92550 lock_limit >>= PAGE_SHIFT;
92551
92552 ret = -ENOMEM;
92553 +
92554 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
92555 +
92556 down_write(&current->mm->mmap_sem);
92557 -
92558 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
92559 capable(CAP_IPC_LOCK))
92560 ret = do_mlockall(flags);
92561 diff --git a/mm/mmap.c b/mm/mmap.c
92562 index 20ff0c3..a9eda98 100644
92563 --- a/mm/mmap.c
92564 +++ b/mm/mmap.c
92565 @@ -36,6 +36,7 @@
92566 #include <linux/sched/sysctl.h>
92567 #include <linux/notifier.h>
92568 #include <linux/memory.h>
92569 +#include <linux/random.h>
92570
92571 #include <asm/uaccess.h>
92572 #include <asm/cacheflush.h>
92573 @@ -52,6 +53,16 @@
92574 #define arch_rebalance_pgtables(addr, len) (addr)
92575 #endif
92576
92577 +static inline void verify_mm_writelocked(struct mm_struct *mm)
92578 +{
92579 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
92580 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92581 + up_read(&mm->mmap_sem);
92582 + BUG();
92583 + }
92584 +#endif
92585 +}
92586 +
92587 static void unmap_region(struct mm_struct *mm,
92588 struct vm_area_struct *vma, struct vm_area_struct *prev,
92589 unsigned long start, unsigned long end);
92590 @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
92591 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
92592 *
92593 */
92594 -pgprot_t protection_map[16] = {
92595 +pgprot_t protection_map[16] __read_only = {
92596 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
92597 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
92598 };
92599
92600 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
92601 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
92602 {
92603 - return __pgprot(pgprot_val(protection_map[vm_flags &
92604 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
92605 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
92606 pgprot_val(arch_vm_get_page_prot(vm_flags)));
92607 +
92608 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92609 + if (!(__supported_pte_mask & _PAGE_NX) &&
92610 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
92611 + (vm_flags & (VM_READ | VM_WRITE)))
92612 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
92613 +#endif
92614 +
92615 + return prot;
92616 }
92617 EXPORT_SYMBOL(vm_get_page_prot);
92618
92619 @@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
92620 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
92621 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
92622 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
92623 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
92624 /*
92625 * Make sure vm_committed_as in one cacheline and not cacheline shared with
92626 * other variables. It can be updated by several CPUs frequently.
92627 @@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
92628 struct vm_area_struct *next = vma->vm_next;
92629
92630 might_sleep();
92631 + BUG_ON(vma->vm_mirror);
92632 if (vma->vm_ops && vma->vm_ops->close)
92633 vma->vm_ops->close(vma);
92634 if (vma->vm_file)
92635 @@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
92636 * not page aligned -Ram Gupta
92637 */
92638 rlim = rlimit(RLIMIT_DATA);
92639 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
92640 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
92641 (mm->end_data - mm->start_data) > rlim)
92642 goto out;
92643 @@ -940,6 +963,12 @@ static int
92644 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
92645 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92646 {
92647 +
92648 +#ifdef CONFIG_PAX_SEGMEXEC
92649 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
92650 + return 0;
92651 +#endif
92652 +
92653 if (is_mergeable_vma(vma, file, vm_flags) &&
92654 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92655 if (vma->vm_pgoff == vm_pgoff)
92656 @@ -959,6 +988,12 @@ static int
92657 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92658 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92659 {
92660 +
92661 +#ifdef CONFIG_PAX_SEGMEXEC
92662 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
92663 + return 0;
92664 +#endif
92665 +
92666 if (is_mergeable_vma(vma, file, vm_flags) &&
92667 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92668 pgoff_t vm_pglen;
92669 @@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92670 struct vm_area_struct *vma_merge(struct mm_struct *mm,
92671 struct vm_area_struct *prev, unsigned long addr,
92672 unsigned long end, unsigned long vm_flags,
92673 - struct anon_vma *anon_vma, struct file *file,
92674 + struct anon_vma *anon_vma, struct file *file,
92675 pgoff_t pgoff, struct mempolicy *policy)
92676 {
92677 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
92678 struct vm_area_struct *area, *next;
92679 int err;
92680
92681 +#ifdef CONFIG_PAX_SEGMEXEC
92682 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
92683 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
92684 +
92685 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
92686 +#endif
92687 +
92688 /*
92689 * We later require that vma->vm_flags == vm_flags,
92690 * so this tests vma->vm_flags & VM_SPECIAL, too.
92691 @@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92692 if (next && next->vm_end == end) /* cases 6, 7, 8 */
92693 next = next->vm_next;
92694
92695 +#ifdef CONFIG_PAX_SEGMEXEC
92696 + if (prev)
92697 + prev_m = pax_find_mirror_vma(prev);
92698 + if (area)
92699 + area_m = pax_find_mirror_vma(area);
92700 + if (next)
92701 + next_m = pax_find_mirror_vma(next);
92702 +#endif
92703 +
92704 /*
92705 * Can it merge with the predecessor?
92706 */
92707 @@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92708 /* cases 1, 6 */
92709 err = vma_adjust(prev, prev->vm_start,
92710 next->vm_end, prev->vm_pgoff, NULL);
92711 - } else /* cases 2, 5, 7 */
92712 +
92713 +#ifdef CONFIG_PAX_SEGMEXEC
92714 + if (!err && prev_m)
92715 + err = vma_adjust(prev_m, prev_m->vm_start,
92716 + next_m->vm_end, prev_m->vm_pgoff, NULL);
92717 +#endif
92718 +
92719 + } else { /* cases 2, 5, 7 */
92720 err = vma_adjust(prev, prev->vm_start,
92721 end, prev->vm_pgoff, NULL);
92722 +
92723 +#ifdef CONFIG_PAX_SEGMEXEC
92724 + if (!err && prev_m)
92725 + err = vma_adjust(prev_m, prev_m->vm_start,
92726 + end_m, prev_m->vm_pgoff, NULL);
92727 +#endif
92728 +
92729 + }
92730 if (err)
92731 return NULL;
92732 khugepaged_enter_vma_merge(prev);
92733 @@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92734 mpol_equal(policy, vma_policy(next)) &&
92735 can_vma_merge_before(next, vm_flags,
92736 anon_vma, file, pgoff+pglen)) {
92737 - if (prev && addr < prev->vm_end) /* case 4 */
92738 + if (prev && addr < prev->vm_end) { /* case 4 */
92739 err = vma_adjust(prev, prev->vm_start,
92740 addr, prev->vm_pgoff, NULL);
92741 - else /* cases 3, 8 */
92742 +
92743 +#ifdef CONFIG_PAX_SEGMEXEC
92744 + if (!err && prev_m)
92745 + err = vma_adjust(prev_m, prev_m->vm_start,
92746 + addr_m, prev_m->vm_pgoff, NULL);
92747 +#endif
92748 +
92749 + } else { /* cases 3, 8 */
92750 err = vma_adjust(area, addr, next->vm_end,
92751 next->vm_pgoff - pglen, NULL);
92752 +
92753 +#ifdef CONFIG_PAX_SEGMEXEC
92754 + if (!err && area_m)
92755 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
92756 + next_m->vm_pgoff - pglen, NULL);
92757 +#endif
92758 +
92759 + }
92760 if (err)
92761 return NULL;
92762 khugepaged_enter_vma_merge(area);
92763 @@ -1172,8 +1253,10 @@ none:
92764 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92765 struct file *file, long pages)
92766 {
92767 - const unsigned long stack_flags
92768 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
92769 +
92770 +#ifdef CONFIG_PAX_RANDMMAP
92771 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92772 +#endif
92773
92774 mm->total_vm += pages;
92775
92776 @@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92777 mm->shared_vm += pages;
92778 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
92779 mm->exec_vm += pages;
92780 - } else if (flags & stack_flags)
92781 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
92782 mm->stack_vm += pages;
92783 }
92784 #endif /* CONFIG_PROC_FS */
92785 @@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
92786 locked += mm->locked_vm;
92787 lock_limit = rlimit(RLIMIT_MEMLOCK);
92788 lock_limit >>= PAGE_SHIFT;
92789 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92790 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
92791 return -EAGAIN;
92792 }
92793 @@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92794 * (the exception is when the underlying filesystem is noexec
92795 * mounted, in which case we dont add PROT_EXEC.)
92796 */
92797 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
92798 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
92799 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
92800 prot |= PROT_EXEC;
92801
92802 @@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92803 /* Obtain the address to map to. we verify (or select) it and ensure
92804 * that it represents a valid section of the address space.
92805 */
92806 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
92807 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
92808 if (addr & ~PAGE_MASK)
92809 return addr;
92810
92811 @@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92812 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
92813 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
92814
92815 +#ifdef CONFIG_PAX_MPROTECT
92816 + if (mm->pax_flags & MF_PAX_MPROTECT) {
92817 +
92818 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
92819 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
92820 + mm->binfmt->handle_mmap)
92821 + mm->binfmt->handle_mmap(file);
92822 +#endif
92823 +
92824 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
92825 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
92826 + gr_log_rwxmmap(file);
92827 +
92828 +#ifdef CONFIG_PAX_EMUPLT
92829 + vm_flags &= ~VM_EXEC;
92830 +#else
92831 + return -EPERM;
92832 +#endif
92833 +
92834 + }
92835 +
92836 + if (!(vm_flags & VM_EXEC))
92837 + vm_flags &= ~VM_MAYEXEC;
92838 +#else
92839 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92840 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92841 +#endif
92842 + else
92843 + vm_flags &= ~VM_MAYWRITE;
92844 + }
92845 +#endif
92846 +
92847 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92848 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
92849 + vm_flags &= ~VM_PAGEEXEC;
92850 +#endif
92851 +
92852 if (flags & MAP_LOCKED)
92853 if (!can_do_mlock())
92854 return -EPERM;
92855 @@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92856 vm_flags |= VM_NORESERVE;
92857 }
92858
92859 + if (!gr_acl_handle_mmap(file, prot))
92860 + return -EACCES;
92861 +
92862 addr = mmap_region(file, addr, len, vm_flags, pgoff);
92863 if (!IS_ERR_VALUE(addr) &&
92864 ((vm_flags & VM_LOCKED) ||
92865 @@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
92866 vm_flags_t vm_flags = vma->vm_flags;
92867
92868 /* If it was private or non-writable, the write bit is already clear */
92869 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
92870 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
92871 return 0;
92872
92873 /* The backer wishes to know when pages are first written to? */
92874 @@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92875 struct rb_node **rb_link, *rb_parent;
92876 unsigned long charged = 0;
92877
92878 +#ifdef CONFIG_PAX_SEGMEXEC
92879 + struct vm_area_struct *vma_m = NULL;
92880 +#endif
92881 +
92882 + /*
92883 + * mm->mmap_sem is required to protect against another thread
92884 + * changing the mappings in case we sleep.
92885 + */
92886 + verify_mm_writelocked(mm);
92887 +
92888 /* Check against address space limit. */
92889 +
92890 +#ifdef CONFIG_PAX_RANDMMAP
92891 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92892 +#endif
92893 +
92894 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
92895 unsigned long nr_pages;
92896
92897 @@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92898
92899 /* Clear old maps */
92900 error = -ENOMEM;
92901 -munmap_back:
92902 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92903 if (do_munmap(mm, addr, len))
92904 return -ENOMEM;
92905 - goto munmap_back;
92906 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92907 }
92908
92909 /*
92910 @@ -1554,6 +1692,16 @@ munmap_back:
92911 goto unacct_error;
92912 }
92913
92914 +#ifdef CONFIG_PAX_SEGMEXEC
92915 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
92916 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92917 + if (!vma_m) {
92918 + error = -ENOMEM;
92919 + goto free_vma;
92920 + }
92921 + }
92922 +#endif
92923 +
92924 vma->vm_mm = mm;
92925 vma->vm_start = addr;
92926 vma->vm_end = addr + len;
92927 @@ -1573,6 +1721,13 @@ munmap_back:
92928 if (error)
92929 goto unmap_and_free_vma;
92930
92931 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92932 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
92933 + vma->vm_flags |= VM_PAGEEXEC;
92934 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
92935 + }
92936 +#endif
92937 +
92938 /* Can addr have changed??
92939 *
92940 * Answer: Yes, several device drivers can do it in their
92941 @@ -1606,6 +1761,12 @@ munmap_back:
92942 }
92943
92944 vma_link(mm, vma, prev, rb_link, rb_parent);
92945 +
92946 +#ifdef CONFIG_PAX_SEGMEXEC
92947 + if (vma_m)
92948 + BUG_ON(pax_mirror_vma(vma_m, vma));
92949 +#endif
92950 +
92951 /* Once vma denies write, undo our temporary denial count */
92952 if (vm_flags & VM_DENYWRITE)
92953 allow_write_access(file);
92954 @@ -1614,6 +1775,7 @@ out:
92955 perf_event_mmap(vma);
92956
92957 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
92958 + track_exec_limit(mm, addr, addr + len, vm_flags);
92959 if (vm_flags & VM_LOCKED) {
92960 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
92961 vma == get_gate_vma(current->mm)))
92962 @@ -1646,6 +1808,12 @@ unmap_and_free_vma:
92963 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
92964 charged = 0;
92965 free_vma:
92966 +
92967 +#ifdef CONFIG_PAX_SEGMEXEC
92968 + if (vma_m)
92969 + kmem_cache_free(vm_area_cachep, vma_m);
92970 +#endif
92971 +
92972 kmem_cache_free(vm_area_cachep, vma);
92973 unacct_error:
92974 if (charged)
92975 @@ -1653,7 +1821,63 @@ unacct_error:
92976 return error;
92977 }
92978
92979 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
92980 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
92981 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
92982 +{
92983 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
92984 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
92985 +
92986 + return 0;
92987 +}
92988 +#endif
92989 +
92990 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
92991 +{
92992 + if (!vma) {
92993 +#ifdef CONFIG_STACK_GROWSUP
92994 + if (addr > sysctl_heap_stack_gap)
92995 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
92996 + else
92997 + vma = find_vma(current->mm, 0);
92998 + if (vma && (vma->vm_flags & VM_GROWSUP))
92999 + return false;
93000 +#endif
93001 + return true;
93002 + }
93003 +
93004 + if (addr + len > vma->vm_start)
93005 + return false;
93006 +
93007 + if (vma->vm_flags & VM_GROWSDOWN)
93008 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93009 +#ifdef CONFIG_STACK_GROWSUP
93010 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93011 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93012 +#endif
93013 + else if (offset)
93014 + return offset <= vma->vm_start - addr - len;
93015 +
93016 + return true;
93017 +}
93018 +
93019 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93020 +{
93021 + if (vma->vm_start < len)
93022 + return -ENOMEM;
93023 +
93024 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
93025 + if (offset <= vma->vm_start - len)
93026 + return vma->vm_start - len - offset;
93027 + else
93028 + return -ENOMEM;
93029 + }
93030 +
93031 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
93032 + return vma->vm_start - len - sysctl_heap_stack_gap;
93033 + return -ENOMEM;
93034 +}
93035 +
93036 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
93037 {
93038 /*
93039 * We implement the search by looking for an rbtree node that
93040 @@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93041 }
93042 }
93043
93044 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
93045 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
93046 check_current:
93047 /* Check if current node has a suitable gap */
93048 if (gap_start > high_limit)
93049 return -ENOMEM;
93050 +
93051 + if (gap_end - gap_start > info->threadstack_offset)
93052 + gap_start += info->threadstack_offset;
93053 + else
93054 + gap_start = gap_end;
93055 +
93056 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93057 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93058 + gap_start += sysctl_heap_stack_gap;
93059 + else
93060 + gap_start = gap_end;
93061 + }
93062 + if (vma->vm_flags & VM_GROWSDOWN) {
93063 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93064 + gap_end -= sysctl_heap_stack_gap;
93065 + else
93066 + gap_end = gap_start;
93067 + }
93068 if (gap_end >= low_limit && gap_end - gap_start >= length)
93069 goto found;
93070
93071 @@ -1755,7 +1997,7 @@ found:
93072 return gap_start;
93073 }
93074
93075 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
93076 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
93077 {
93078 struct mm_struct *mm = current->mm;
93079 struct vm_area_struct *vma;
93080 @@ -1809,6 +2051,24 @@ check_current:
93081 gap_end = vma->vm_start;
93082 if (gap_end < low_limit)
93083 return -ENOMEM;
93084 +
93085 + if (gap_end - gap_start > info->threadstack_offset)
93086 + gap_end -= info->threadstack_offset;
93087 + else
93088 + gap_end = gap_start;
93089 +
93090 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93091 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93092 + gap_start += sysctl_heap_stack_gap;
93093 + else
93094 + gap_start = gap_end;
93095 + }
93096 + if (vma->vm_flags & VM_GROWSDOWN) {
93097 + if (gap_end - gap_start > sysctl_heap_stack_gap)
93098 + gap_end -= sysctl_heap_stack_gap;
93099 + else
93100 + gap_end = gap_start;
93101 + }
93102 if (gap_start <= high_limit && gap_end - gap_start >= length)
93103 goto found;
93104
93105 @@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93106 struct mm_struct *mm = current->mm;
93107 struct vm_area_struct *vma;
93108 struct vm_unmapped_area_info info;
93109 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93110
93111 if (len > TASK_SIZE - mmap_min_addr)
93112 return -ENOMEM;
93113 @@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93114 if (flags & MAP_FIXED)
93115 return addr;
93116
93117 +#ifdef CONFIG_PAX_RANDMMAP
93118 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93119 +#endif
93120 +
93121 if (addr) {
93122 addr = PAGE_ALIGN(addr);
93123 vma = find_vma(mm, addr);
93124 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93125 - (!vma || addr + len <= vma->vm_start))
93126 + check_heap_stack_gap(vma, addr, len, offset))
93127 return addr;
93128 }
93129
93130 @@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93131 info.low_limit = mm->mmap_base;
93132 info.high_limit = TASK_SIZE;
93133 info.align_mask = 0;
93134 + info.threadstack_offset = offset;
93135 return vm_unmapped_area(&info);
93136 }
93137 #endif
93138 @@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93139 struct mm_struct *mm = current->mm;
93140 unsigned long addr = addr0;
93141 struct vm_unmapped_area_info info;
93142 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93143
93144 /* requested length too big for entire address space */
93145 if (len > TASK_SIZE - mmap_min_addr)
93146 @@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93147 if (flags & MAP_FIXED)
93148 return addr;
93149
93150 +#ifdef CONFIG_PAX_RANDMMAP
93151 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93152 +#endif
93153 +
93154 /* requesting a specific address */
93155 if (addr) {
93156 addr = PAGE_ALIGN(addr);
93157 vma = find_vma(mm, addr);
93158 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93159 - (!vma || addr + len <= vma->vm_start))
93160 + check_heap_stack_gap(vma, addr, len, offset))
93161 return addr;
93162 }
93163
93164 @@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93165 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93166 info.high_limit = mm->mmap_base;
93167 info.align_mask = 0;
93168 + info.threadstack_offset = offset;
93169 addr = vm_unmapped_area(&info);
93170
93171 /*
93172 @@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93173 VM_BUG_ON(addr != -ENOMEM);
93174 info.flags = 0;
93175 info.low_limit = TASK_UNMAPPED_BASE;
93176 +
93177 +#ifdef CONFIG_PAX_RANDMMAP
93178 + if (mm->pax_flags & MF_PAX_RANDMMAP)
93179 + info.low_limit += mm->delta_mmap;
93180 +#endif
93181 +
93182 info.high_limit = TASK_SIZE;
93183 addr = vm_unmapped_area(&info);
93184 }
93185 @@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93186 return vma;
93187 }
93188
93189 +#ifdef CONFIG_PAX_SEGMEXEC
93190 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93191 +{
93192 + struct vm_area_struct *vma_m;
93193 +
93194 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93195 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93196 + BUG_ON(vma->vm_mirror);
93197 + return NULL;
93198 + }
93199 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93200 + vma_m = vma->vm_mirror;
93201 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93202 + BUG_ON(vma->vm_file != vma_m->vm_file);
93203 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93204 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93205 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93206 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93207 + return vma_m;
93208 +}
93209 +#endif
93210 +
93211 /*
93212 * Verify that the stack growth is acceptable and
93213 * update accounting. This is shared with both the
93214 @@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93215 return -ENOMEM;
93216
93217 /* Stack limit test */
93218 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
93219 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93220 return -ENOMEM;
93221
93222 @@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93223 locked = mm->locked_vm + grow;
93224 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93225 limit >>= PAGE_SHIFT;
93226 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93227 if (locked > limit && !capable(CAP_IPC_LOCK))
93228 return -ENOMEM;
93229 }
93230 @@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93231 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93232 * vma is the last one with address > vma->vm_end. Have to extend vma.
93233 */
93234 +#ifndef CONFIG_IA64
93235 +static
93236 +#endif
93237 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93238 {
93239 int error;
93240 + bool locknext;
93241
93242 if (!(vma->vm_flags & VM_GROWSUP))
93243 return -EFAULT;
93244
93245 + /* Also guard against wrapping around to address 0. */
93246 + if (address < PAGE_ALIGN(address+1))
93247 + address = PAGE_ALIGN(address+1);
93248 + else
93249 + return -ENOMEM;
93250 +
93251 /*
93252 * We must make sure the anon_vma is allocated
93253 * so that the anon_vma locking is not a noop.
93254 */
93255 if (unlikely(anon_vma_prepare(vma)))
93256 return -ENOMEM;
93257 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93258 + if (locknext && anon_vma_prepare(vma->vm_next))
93259 + return -ENOMEM;
93260 vma_lock_anon_vma(vma);
93261 + if (locknext)
93262 + vma_lock_anon_vma(vma->vm_next);
93263
93264 /*
93265 * vma->vm_start/vm_end cannot change under us because the caller
93266 * is required to hold the mmap_sem in read mode. We need the
93267 - * anon_vma lock to serialize against concurrent expand_stacks.
93268 - * Also guard against wrapping around to address 0.
93269 + * anon_vma locks to serialize against concurrent expand_stacks
93270 + * and expand_upwards.
93271 */
93272 - if (address < PAGE_ALIGN(address+4))
93273 - address = PAGE_ALIGN(address+4);
93274 - else {
93275 - vma_unlock_anon_vma(vma);
93276 - return -ENOMEM;
93277 - }
93278 error = 0;
93279
93280 /* Somebody else might have raced and expanded it already */
93281 - if (address > vma->vm_end) {
93282 + 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)
93283 + error = -ENOMEM;
93284 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93285 unsigned long size, grow;
93286
93287 size = address - vma->vm_start;
93288 @@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93289 }
93290 }
93291 }
93292 + if (locknext)
93293 + vma_unlock_anon_vma(vma->vm_next);
93294 vma_unlock_anon_vma(vma);
93295 khugepaged_enter_vma_merge(vma);
93296 validate_mm(vma->vm_mm);
93297 @@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
93298 unsigned long address)
93299 {
93300 int error;
93301 + bool lockprev = false;
93302 + struct vm_area_struct *prev;
93303
93304 /*
93305 * We must make sure the anon_vma is allocated
93306 @@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
93307 if (error)
93308 return error;
93309
93310 + prev = vma->vm_prev;
93311 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
93312 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
93313 +#endif
93314 + if (lockprev && anon_vma_prepare(prev))
93315 + return -ENOMEM;
93316 + if (lockprev)
93317 + vma_lock_anon_vma(prev);
93318 +
93319 vma_lock_anon_vma(vma);
93320
93321 /*
93322 @@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
93323 */
93324
93325 /* Somebody else might have raced and expanded it already */
93326 - if (address < vma->vm_start) {
93327 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
93328 + error = -ENOMEM;
93329 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
93330 unsigned long size, grow;
93331
93332 +#ifdef CONFIG_PAX_SEGMEXEC
93333 + struct vm_area_struct *vma_m;
93334 +
93335 + vma_m = pax_find_mirror_vma(vma);
93336 +#endif
93337 +
93338 size = vma->vm_end - address;
93339 grow = (vma->vm_start - address) >> PAGE_SHIFT;
93340
93341 @@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
93342 vma->vm_pgoff -= grow;
93343 anon_vma_interval_tree_post_update_vma(vma);
93344 vma_gap_update(vma);
93345 +
93346 +#ifdef CONFIG_PAX_SEGMEXEC
93347 + if (vma_m) {
93348 + anon_vma_interval_tree_pre_update_vma(vma_m);
93349 + vma_m->vm_start -= grow << PAGE_SHIFT;
93350 + vma_m->vm_pgoff -= grow;
93351 + anon_vma_interval_tree_post_update_vma(vma_m);
93352 + vma_gap_update(vma_m);
93353 + }
93354 +#endif
93355 +
93356 spin_unlock(&vma->vm_mm->page_table_lock);
93357
93358 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
93359 perf_event_mmap(vma);
93360 }
93361 }
93362 }
93363 vma_unlock_anon_vma(vma);
93364 + if (lockprev)
93365 + vma_unlock_anon_vma(prev);
93366 khugepaged_enter_vma_merge(vma);
93367 validate_mm(vma->vm_mm);
93368 return error;
93369 @@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
93370 do {
93371 long nrpages = vma_pages(vma);
93372
93373 +#ifdef CONFIG_PAX_SEGMEXEC
93374 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
93375 + vma = remove_vma(vma);
93376 + continue;
93377 + }
93378 +#endif
93379 +
93380 if (vma->vm_flags & VM_ACCOUNT)
93381 nr_accounted += nrpages;
93382 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
93383 @@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
93384 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
93385 vma->vm_prev = NULL;
93386 do {
93387 +
93388 +#ifdef CONFIG_PAX_SEGMEXEC
93389 + if (vma->vm_mirror) {
93390 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
93391 + vma->vm_mirror->vm_mirror = NULL;
93392 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
93393 + vma->vm_mirror = NULL;
93394 + }
93395 +#endif
93396 +
93397 vma_rb_erase(vma, &mm->mm_rb);
93398 mm->map_count--;
93399 tail_vma = vma;
93400 @@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93401 struct vm_area_struct *new;
93402 int err = -ENOMEM;
93403
93404 +#ifdef CONFIG_PAX_SEGMEXEC
93405 + struct vm_area_struct *vma_m, *new_m = NULL;
93406 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
93407 +#endif
93408 +
93409 if (is_vm_hugetlb_page(vma) && (addr &
93410 ~(huge_page_mask(hstate_vma(vma)))))
93411 return -EINVAL;
93412
93413 +#ifdef CONFIG_PAX_SEGMEXEC
93414 + vma_m = pax_find_mirror_vma(vma);
93415 +#endif
93416 +
93417 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93418 if (!new)
93419 goto out_err;
93420
93421 +#ifdef CONFIG_PAX_SEGMEXEC
93422 + if (vma_m) {
93423 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93424 + if (!new_m) {
93425 + kmem_cache_free(vm_area_cachep, new);
93426 + goto out_err;
93427 + }
93428 + }
93429 +#endif
93430 +
93431 /* most fields are the same, copy all, and then fixup */
93432 *new = *vma;
93433
93434 @@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93435 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
93436 }
93437
93438 +#ifdef CONFIG_PAX_SEGMEXEC
93439 + if (vma_m) {
93440 + *new_m = *vma_m;
93441 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
93442 + new_m->vm_mirror = new;
93443 + new->vm_mirror = new_m;
93444 +
93445 + if (new_below)
93446 + new_m->vm_end = addr_m;
93447 + else {
93448 + new_m->vm_start = addr_m;
93449 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
93450 + }
93451 + }
93452 +#endif
93453 +
93454 err = vma_dup_policy(vma, new);
93455 if (err)
93456 goto out_free_vma;
93457 @@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93458 else
93459 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
93460
93461 +#ifdef CONFIG_PAX_SEGMEXEC
93462 + if (!err && vma_m) {
93463 + struct mempolicy *pol = vma_policy(new);
93464 +
93465 + if (anon_vma_clone(new_m, vma_m))
93466 + goto out_free_mpol;
93467 +
93468 + mpol_get(pol);
93469 + set_vma_policy(new_m, pol);
93470 +
93471 + if (new_m->vm_file)
93472 + get_file(new_m->vm_file);
93473 +
93474 + if (new_m->vm_ops && new_m->vm_ops->open)
93475 + new_m->vm_ops->open(new_m);
93476 +
93477 + if (new_below)
93478 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
93479 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
93480 + else
93481 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
93482 +
93483 + if (err) {
93484 + if (new_m->vm_ops && new_m->vm_ops->close)
93485 + new_m->vm_ops->close(new_m);
93486 + if (new_m->vm_file)
93487 + fput(new_m->vm_file);
93488 + mpol_put(pol);
93489 + }
93490 + }
93491 +#endif
93492 +
93493 /* Success. */
93494 if (!err)
93495 return 0;
93496 @@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93497 new->vm_ops->close(new);
93498 if (new->vm_file)
93499 fput(new->vm_file);
93500 - unlink_anon_vmas(new);
93501 out_free_mpol:
93502 mpol_put(vma_policy(new));
93503 out_free_vma:
93504 +
93505 +#ifdef CONFIG_PAX_SEGMEXEC
93506 + if (new_m) {
93507 + unlink_anon_vmas(new_m);
93508 + kmem_cache_free(vm_area_cachep, new_m);
93509 + }
93510 +#endif
93511 +
93512 + unlink_anon_vmas(new);
93513 kmem_cache_free(vm_area_cachep, new);
93514 out_err:
93515 return err;
93516 @@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93517 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93518 unsigned long addr, int new_below)
93519 {
93520 +
93521 +#ifdef CONFIG_PAX_SEGMEXEC
93522 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93523 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
93524 + if (mm->map_count >= sysctl_max_map_count-1)
93525 + return -ENOMEM;
93526 + } else
93527 +#endif
93528 +
93529 if (mm->map_count >= sysctl_max_map_count)
93530 return -ENOMEM;
93531
93532 @@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93533 * work. This now handles partial unmappings.
93534 * Jeremy Fitzhardinge <jeremy@goop.org>
93535 */
93536 +#ifdef CONFIG_PAX_SEGMEXEC
93537 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93538 {
93539 + int ret = __do_munmap(mm, start, len);
93540 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
93541 + return ret;
93542 +
93543 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
93544 +}
93545 +
93546 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93547 +#else
93548 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93549 +#endif
93550 +{
93551 unsigned long end;
93552 struct vm_area_struct *vma, *prev, *last;
93553
93554 + /*
93555 + * mm->mmap_sem is required to protect against another thread
93556 + * changing the mappings in case we sleep.
93557 + */
93558 + verify_mm_writelocked(mm);
93559 +
93560 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
93561 return -EINVAL;
93562
93563 @@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93564 /* Fix up all other VM information */
93565 remove_vma_list(mm, vma);
93566
93567 + track_exec_limit(mm, start, end, 0UL);
93568 +
93569 return 0;
93570 }
93571
93572 @@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
93573 int ret;
93574 struct mm_struct *mm = current->mm;
93575
93576 +
93577 +#ifdef CONFIG_PAX_SEGMEXEC
93578 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
93579 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
93580 + return -EINVAL;
93581 +#endif
93582 +
93583 down_write(&mm->mmap_sem);
93584 ret = do_munmap(mm, start, len);
93585 up_write(&mm->mmap_sem);
93586 @@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
93587 return vm_munmap(addr, len);
93588 }
93589
93590 -static inline void verify_mm_writelocked(struct mm_struct *mm)
93591 -{
93592 -#ifdef CONFIG_DEBUG_VM
93593 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93594 - WARN_ON(1);
93595 - up_read(&mm->mmap_sem);
93596 - }
93597 -#endif
93598 -}
93599 -
93600 /*
93601 * this is really a simplified "do_mmap". it only handles
93602 * anonymous maps. eventually we may be able to do some
93603 @@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93604 struct rb_node ** rb_link, * rb_parent;
93605 pgoff_t pgoff = addr >> PAGE_SHIFT;
93606 int error;
93607 + unsigned long charged;
93608
93609 len = PAGE_ALIGN(len);
93610 if (!len)
93611 @@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93612
93613 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
93614
93615 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
93616 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
93617 + flags &= ~VM_EXEC;
93618 +
93619 +#ifdef CONFIG_PAX_MPROTECT
93620 + if (mm->pax_flags & MF_PAX_MPROTECT)
93621 + flags &= ~VM_MAYEXEC;
93622 +#endif
93623 +
93624 + }
93625 +#endif
93626 +
93627 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
93628 if (error & ~PAGE_MASK)
93629 return error;
93630
93631 + charged = len >> PAGE_SHIFT;
93632 +
93633 error = mlock_future_check(mm, mm->def_flags, len);
93634 if (error)
93635 return error;
93636 @@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93637 /*
93638 * Clear old maps. this also does some error checking for us
93639 */
93640 - munmap_back:
93641 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93642 if (do_munmap(mm, addr, len))
93643 return -ENOMEM;
93644 - goto munmap_back;
93645 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93646 }
93647
93648 /* Check against address space limits *after* clearing old maps... */
93649 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
93650 + if (!may_expand_vm(mm, charged))
93651 return -ENOMEM;
93652
93653 if (mm->map_count > sysctl_max_map_count)
93654 return -ENOMEM;
93655
93656 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
93657 + if (security_vm_enough_memory_mm(mm, charged))
93658 return -ENOMEM;
93659
93660 /* Can we just expand an old private anonymous mapping? */
93661 @@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93662 */
93663 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93664 if (!vma) {
93665 - vm_unacct_memory(len >> PAGE_SHIFT);
93666 + vm_unacct_memory(charged);
93667 return -ENOMEM;
93668 }
93669
93670 @@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93671 vma_link(mm, vma, prev, rb_link, rb_parent);
93672 out:
93673 perf_event_mmap(vma);
93674 - mm->total_vm += len >> PAGE_SHIFT;
93675 + mm->total_vm += charged;
93676 if (flags & VM_LOCKED)
93677 - mm->locked_vm += (len >> PAGE_SHIFT);
93678 + mm->locked_vm += charged;
93679 vma->vm_flags |= VM_SOFTDIRTY;
93680 + track_exec_limit(mm, addr, addr + len, flags);
93681 return addr;
93682 }
93683
93684 @@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
93685 while (vma) {
93686 if (vma->vm_flags & VM_ACCOUNT)
93687 nr_accounted += vma_pages(vma);
93688 + vma->vm_mirror = NULL;
93689 vma = remove_vma(vma);
93690 }
93691 vm_unacct_memory(nr_accounted);
93692 @@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93693 struct vm_area_struct *prev;
93694 struct rb_node **rb_link, *rb_parent;
93695
93696 +#ifdef CONFIG_PAX_SEGMEXEC
93697 + struct vm_area_struct *vma_m = NULL;
93698 +#endif
93699 +
93700 + if (security_mmap_addr(vma->vm_start))
93701 + return -EPERM;
93702 +
93703 /*
93704 * The vm_pgoff of a purely anonymous vma should be irrelevant
93705 * until its first write fault, when page's anon_vma and index
93706 @@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93707 security_vm_enough_memory_mm(mm, vma_pages(vma)))
93708 return -ENOMEM;
93709
93710 +#ifdef CONFIG_PAX_SEGMEXEC
93711 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
93712 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93713 + if (!vma_m)
93714 + return -ENOMEM;
93715 + }
93716 +#endif
93717 +
93718 vma_link(mm, vma, prev, rb_link, rb_parent);
93719 +
93720 +#ifdef CONFIG_PAX_SEGMEXEC
93721 + if (vma_m)
93722 + BUG_ON(pax_mirror_vma(vma_m, vma));
93723 +#endif
93724 +
93725 return 0;
93726 }
93727
93728 @@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93729 struct rb_node **rb_link, *rb_parent;
93730 bool faulted_in_anon_vma = true;
93731
93732 + BUG_ON(vma->vm_mirror);
93733 +
93734 /*
93735 * If anonymous vma has not yet been faulted, update new pgoff
93736 * to match new location, to increase its chance of merging.
93737 @@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93738 return NULL;
93739 }
93740
93741 +#ifdef CONFIG_PAX_SEGMEXEC
93742 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
93743 +{
93744 + struct vm_area_struct *prev_m;
93745 + struct rb_node **rb_link_m, *rb_parent_m;
93746 + struct mempolicy *pol_m;
93747 +
93748 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
93749 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
93750 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
93751 + *vma_m = *vma;
93752 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
93753 + if (anon_vma_clone(vma_m, vma))
93754 + return -ENOMEM;
93755 + pol_m = vma_policy(vma_m);
93756 + mpol_get(pol_m);
93757 + set_vma_policy(vma_m, pol_m);
93758 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
93759 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
93760 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
93761 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
93762 + if (vma_m->vm_file)
93763 + get_file(vma_m->vm_file);
93764 + if (vma_m->vm_ops && vma_m->vm_ops->open)
93765 + vma_m->vm_ops->open(vma_m);
93766 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
93767 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
93768 + vma_m->vm_mirror = vma;
93769 + vma->vm_mirror = vma_m;
93770 + return 0;
93771 +}
93772 +#endif
93773 +
93774 /*
93775 * Return true if the calling process may expand its vm space by the passed
93776 * number of pages
93777 @@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
93778
93779 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
93780
93781 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
93782 if (cur + npages > lim)
93783 return 0;
93784 return 1;
93785 @@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
93786 vma->vm_start = addr;
93787 vma->vm_end = addr + len;
93788
93789 +#ifdef CONFIG_PAX_MPROTECT
93790 + if (mm->pax_flags & MF_PAX_MPROTECT) {
93791 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
93792 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
93793 + return -EPERM;
93794 + if (!(vm_flags & VM_EXEC))
93795 + vm_flags &= ~VM_MAYEXEC;
93796 +#else
93797 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93798 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93799 +#endif
93800 + else
93801 + vm_flags &= ~VM_MAYWRITE;
93802 + }
93803 +#endif
93804 +
93805 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
93806 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93807
93808 diff --git a/mm/mprotect.c b/mm/mprotect.c
93809 index 769a67a..414d24f 100644
93810 --- a/mm/mprotect.c
93811 +++ b/mm/mprotect.c
93812 @@ -24,10 +24,18 @@
93813 #include <linux/migrate.h>
93814 #include <linux/perf_event.h>
93815 #include <linux/ksm.h>
93816 +#include <linux/sched/sysctl.h>
93817 +
93818 +#ifdef CONFIG_PAX_MPROTECT
93819 +#include <linux/elf.h>
93820 +#include <linux/binfmts.h>
93821 +#endif
93822 +
93823 #include <asm/uaccess.h>
93824 #include <asm/pgtable.h>
93825 #include <asm/cacheflush.h>
93826 #include <asm/tlbflush.h>
93827 +#include <asm/mmu_context.h>
93828
93829 #ifndef pgprot_modify
93830 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
93831 @@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
93832 return pages;
93833 }
93834
93835 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
93836 +/* called while holding the mmap semaphor for writing except stack expansion */
93837 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
93838 +{
93839 + unsigned long oldlimit, newlimit = 0UL;
93840 +
93841 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
93842 + return;
93843 +
93844 + spin_lock(&mm->page_table_lock);
93845 + oldlimit = mm->context.user_cs_limit;
93846 + if ((prot & VM_EXEC) && oldlimit < end)
93847 + /* USER_CS limit moved up */
93848 + newlimit = end;
93849 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
93850 + /* USER_CS limit moved down */
93851 + newlimit = start;
93852 +
93853 + if (newlimit) {
93854 + mm->context.user_cs_limit = newlimit;
93855 +
93856 +#ifdef CONFIG_SMP
93857 + wmb();
93858 + cpus_clear(mm->context.cpu_user_cs_mask);
93859 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
93860 +#endif
93861 +
93862 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
93863 + }
93864 + spin_unlock(&mm->page_table_lock);
93865 + if (newlimit == end) {
93866 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
93867 +
93868 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
93869 + if (is_vm_hugetlb_page(vma))
93870 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
93871 + else
93872 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
93873 + }
93874 +}
93875 +#endif
93876 +
93877 int
93878 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93879 unsigned long start, unsigned long end, unsigned long newflags)
93880 @@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93881 int error;
93882 int dirty_accountable = 0;
93883
93884 +#ifdef CONFIG_PAX_SEGMEXEC
93885 + struct vm_area_struct *vma_m = NULL;
93886 + unsigned long start_m, end_m;
93887 +
93888 + start_m = start + SEGMEXEC_TASK_SIZE;
93889 + end_m = end + SEGMEXEC_TASK_SIZE;
93890 +#endif
93891 +
93892 if (newflags == oldflags) {
93893 *pprev = vma;
93894 return 0;
93895 }
93896
93897 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
93898 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
93899 +
93900 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
93901 + return -ENOMEM;
93902 +
93903 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
93904 + return -ENOMEM;
93905 + }
93906 +
93907 /*
93908 * If we make a private mapping writable we increase our commit;
93909 * but (without finer accounting) cannot reduce our commit if we
93910 @@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93911 }
93912 }
93913
93914 +#ifdef CONFIG_PAX_SEGMEXEC
93915 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
93916 + if (start != vma->vm_start) {
93917 + error = split_vma(mm, vma, start, 1);
93918 + if (error)
93919 + goto fail;
93920 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
93921 + *pprev = (*pprev)->vm_next;
93922 + }
93923 +
93924 + if (end != vma->vm_end) {
93925 + error = split_vma(mm, vma, end, 0);
93926 + if (error)
93927 + goto fail;
93928 + }
93929 +
93930 + if (pax_find_mirror_vma(vma)) {
93931 + error = __do_munmap(mm, start_m, end_m - start_m);
93932 + if (error)
93933 + goto fail;
93934 + } else {
93935 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93936 + if (!vma_m) {
93937 + error = -ENOMEM;
93938 + goto fail;
93939 + }
93940 + vma->vm_flags = newflags;
93941 + error = pax_mirror_vma(vma_m, vma);
93942 + if (error) {
93943 + vma->vm_flags = oldflags;
93944 + goto fail;
93945 + }
93946 + }
93947 + }
93948 +#endif
93949 +
93950 /*
93951 * First try to merge with previous and/or next vma.
93952 */
93953 @@ -277,9 +381,21 @@ success:
93954 * vm_flags and vm_page_prot are protected by the mmap_sem
93955 * held in write mode.
93956 */
93957 +
93958 +#ifdef CONFIG_PAX_SEGMEXEC
93959 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
93960 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
93961 +#endif
93962 +
93963 vma->vm_flags = newflags;
93964 +
93965 +#ifdef CONFIG_PAX_MPROTECT
93966 + if (mm->binfmt && mm->binfmt->handle_mprotect)
93967 + mm->binfmt->handle_mprotect(vma, newflags);
93968 +#endif
93969 +
93970 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
93971 - vm_get_page_prot(newflags));
93972 + vm_get_page_prot(vma->vm_flags));
93973
93974 if (vma_wants_writenotify(vma)) {
93975 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
93976 @@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93977 end = start + len;
93978 if (end <= start)
93979 return -ENOMEM;
93980 +
93981 +#ifdef CONFIG_PAX_SEGMEXEC
93982 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
93983 + if (end > SEGMEXEC_TASK_SIZE)
93984 + return -EINVAL;
93985 + } else
93986 +#endif
93987 +
93988 + if (end > TASK_SIZE)
93989 + return -EINVAL;
93990 +
93991 if (!arch_validate_prot(prot))
93992 return -EINVAL;
93993
93994 @@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93995 /*
93996 * Does the application expect PROT_READ to imply PROT_EXEC:
93997 */
93998 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93999 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94000 prot |= PROT_EXEC;
94001
94002 vm_flags = calc_vm_prot_bits(prot);
94003 @@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94004 if (start > vma->vm_start)
94005 prev = vma;
94006
94007 +#ifdef CONFIG_PAX_MPROTECT
94008 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94009 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
94010 +#endif
94011 +
94012 for (nstart = start ; ; ) {
94013 unsigned long newflags;
94014
94015 @@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94016
94017 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94018 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94019 + if (prot & (PROT_WRITE | PROT_EXEC))
94020 + gr_log_rwxmprotect(vma);
94021 +
94022 + error = -EACCES;
94023 + goto out;
94024 + }
94025 +
94026 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
94027 error = -EACCES;
94028 goto out;
94029 }
94030 @@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94031 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
94032 if (error)
94033 goto out;
94034 +
94035 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
94036 +
94037 nstart = tmp;
94038
94039 if (nstart < prev->vm_end)
94040 diff --git a/mm/mremap.c b/mm/mremap.c
94041 index 0843feb..4f5b2e6 100644
94042 --- a/mm/mremap.c
94043 +++ b/mm/mremap.c
94044 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
94045 continue;
94046 pte = ptep_get_and_clear(mm, old_addr, old_pte);
94047 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
94048 +
94049 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94050 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
94051 + pte = pte_exprotect(pte);
94052 +#endif
94053 +
94054 pte = move_soft_dirty_pte(pte);
94055 set_pte_at(mm, new_addr, new_pte, pte);
94056 }
94057 @@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
94058 if (is_vm_hugetlb_page(vma))
94059 goto Einval;
94060
94061 +#ifdef CONFIG_PAX_SEGMEXEC
94062 + if (pax_find_mirror_vma(vma))
94063 + goto Einval;
94064 +#endif
94065 +
94066 /* We can't remap across vm area boundaries */
94067 if (old_len > vma->vm_end - addr)
94068 goto Efault;
94069 @@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
94070 unsigned long ret = -EINVAL;
94071 unsigned long charged = 0;
94072 unsigned long map_flags;
94073 + unsigned long pax_task_size = TASK_SIZE;
94074
94075 if (new_addr & ~PAGE_MASK)
94076 goto out;
94077
94078 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
94079 +#ifdef CONFIG_PAX_SEGMEXEC
94080 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94081 + pax_task_size = SEGMEXEC_TASK_SIZE;
94082 +#endif
94083 +
94084 + pax_task_size -= PAGE_SIZE;
94085 +
94086 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94087 goto out;
94088
94089 /* Check if the location we're moving into overlaps the
94090 * old location at all, and fail if it does.
94091 */
94092 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
94093 - goto out;
94094 -
94095 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
94096 + if (addr + old_len > new_addr && new_addr + new_len > addr)
94097 goto out;
94098
94099 ret = do_munmap(mm, new_addr, new_len);
94100 @@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94101 unsigned long ret = -EINVAL;
94102 unsigned long charged = 0;
94103 bool locked = false;
94104 + unsigned long pax_task_size = TASK_SIZE;
94105
94106 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94107 return ret;
94108 @@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94109 if (!new_len)
94110 return ret;
94111
94112 +#ifdef CONFIG_PAX_SEGMEXEC
94113 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
94114 + pax_task_size = SEGMEXEC_TASK_SIZE;
94115 +#endif
94116 +
94117 + pax_task_size -= PAGE_SIZE;
94118 +
94119 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94120 + old_len > pax_task_size || addr > pax_task_size-old_len)
94121 + return ret;
94122 +
94123 down_write(&current->mm->mmap_sem);
94124
94125 if (flags & MREMAP_FIXED) {
94126 @@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94127 new_addr = addr;
94128 }
94129 ret = addr;
94130 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94131 goto out;
94132 }
94133 }
94134 @@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94135 goto out;
94136 }
94137
94138 + map_flags = vma->vm_flags;
94139 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94140 + if (!(ret & ~PAGE_MASK)) {
94141 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94142 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94143 + }
94144 }
94145 out:
94146 if (ret & ~PAGE_MASK)
94147 diff --git a/mm/nommu.c b/mm/nommu.c
94148 index 8740213..f87e25b 100644
94149 --- a/mm/nommu.c
94150 +++ b/mm/nommu.c
94151 @@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94152 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94153 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94154 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94155 -int heap_stack_gap = 0;
94156
94157 atomic_long_t mmap_pages_allocated;
94158
94159 @@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94160 EXPORT_SYMBOL(find_vma);
94161
94162 /*
94163 - * find a VMA
94164 - * - we don't extend stack VMAs under NOMMU conditions
94165 - */
94166 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94167 -{
94168 - return find_vma(mm, addr);
94169 -}
94170 -
94171 -/*
94172 * expand a stack to a given address
94173 * - not supported under NOMMU conditions
94174 */
94175 @@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94176
94177 /* most fields are the same, copy all, and then fixup */
94178 *new = *vma;
94179 + INIT_LIST_HEAD(&new->anon_vma_chain);
94180 *region = *vma->vm_region;
94181 new->vm_region = region;
94182
94183 @@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94184 }
94185 EXPORT_SYMBOL(generic_file_remap_pages);
94186
94187 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94188 - unsigned long addr, void *buf, int len, int write)
94189 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94190 + unsigned long addr, void *buf, size_t len, int write)
94191 {
94192 struct vm_area_struct *vma;
94193
94194 @@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94195 *
94196 * The caller must hold a reference on @mm.
94197 */
94198 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94199 - void *buf, int len, int write)
94200 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94201 + void *buf, size_t len, int write)
94202 {
94203 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94204 }
94205 @@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94206 * Access another process' address space.
94207 * - source/target buffer must be kernel space
94208 */
94209 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94210 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94211 {
94212 struct mm_struct *mm;
94213
94214 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94215 index 7106cb1..0805f48 100644
94216 --- a/mm/page-writeback.c
94217 +++ b/mm/page-writeback.c
94218 @@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94219 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94220 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94221 */
94222 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94223 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94224 unsigned long thresh,
94225 unsigned long bg_thresh,
94226 unsigned long dirty,
94227 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94228 index 3bac76a..bf9f9ae 100644
94229 --- a/mm/page_alloc.c
94230 +++ b/mm/page_alloc.c
94231 @@ -61,6 +61,7 @@
94232 #include <linux/page-debug-flags.h>
94233 #include <linux/hugetlb.h>
94234 #include <linux/sched/rt.h>
94235 +#include <linux/random.h>
94236
94237 #include <asm/sections.h>
94238 #include <asm/tlbflush.h>
94239 @@ -354,7 +355,7 @@ out:
94240 * This usage means that zero-order pages may not be compound.
94241 */
94242
94243 -static void free_compound_page(struct page *page)
94244 +void free_compound_page(struct page *page)
94245 {
94246 __free_pages_ok(page, compound_order(page));
94247 }
94248 @@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94249 int i;
94250 int bad = 0;
94251
94252 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94253 + unsigned long index = 1UL << order;
94254 +#endif
94255 +
94256 trace_mm_page_free(page, order);
94257 kmemcheck_free_shadow(page, order);
94258
94259 @@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94260 debug_check_no_obj_freed(page_address(page),
94261 PAGE_SIZE << order);
94262 }
94263 +
94264 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94265 + for (; index; --index)
94266 + sanitize_highpage(page + index - 1);
94267 +#endif
94268 +
94269 arch_free_page(page, order);
94270 kernel_map_pages(page, 1 << order, 0);
94271
94272 @@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94273 local_irq_restore(flags);
94274 }
94275
94276 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94277 +bool __meminitdata extra_latent_entropy;
94278 +
94279 +static int __init setup_pax_extra_latent_entropy(char *str)
94280 +{
94281 + extra_latent_entropy = true;
94282 + return 0;
94283 +}
94284 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94285 +
94286 +volatile u64 latent_entropy __latent_entropy;
94287 +EXPORT_SYMBOL(latent_entropy);
94288 +#endif
94289 +
94290 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94291 {
94292 unsigned int nr_pages = 1 << order;
94293 @@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94294 __ClearPageReserved(p);
94295 set_page_count(p, 0);
94296
94297 +#ifdef CONFIG_PAX_LATENT_ENTROPY
94298 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94299 + u64 hash = 0;
94300 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94301 + const u64 *data = lowmem_page_address(page);
94302 +
94303 + for (index = 0; index < end; index++)
94304 + hash ^= hash + data[index];
94305 + latent_entropy ^= hash;
94306 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94307 + }
94308 +#endif
94309 +
94310 page_zone(page)->managed_pages += nr_pages;
94311 set_page_refcounted(page);
94312 __free_pages(page, order);
94313 @@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
94314 arch_alloc_page(page, order);
94315 kernel_map_pages(page, 1 << order, 1);
94316
94317 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
94318 if (gfp_flags & __GFP_ZERO)
94319 prep_zero_page(page, order, gfp_flags);
94320 +#endif
94321
94322 if (order && (gfp_flags & __GFP_COMP))
94323 prep_compound_page(page, order);
94324 diff --git a/mm/page_io.c b/mm/page_io.c
94325 index 7c59ef6..1358905 100644
94326 --- a/mm/page_io.c
94327 +++ b/mm/page_io.c
94328 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
94329 struct file *swap_file = sis->swap_file;
94330 struct address_space *mapping = swap_file->f_mapping;
94331 struct iovec iov = {
94332 - .iov_base = kmap(page),
94333 + .iov_base = (void __force_user *)kmap(page),
94334 .iov_len = PAGE_SIZE,
94335 };
94336
94337 diff --git a/mm/percpu.c b/mm/percpu.c
94338 index 036cfe0..980d0fa 100644
94339 --- a/mm/percpu.c
94340 +++ b/mm/percpu.c
94341 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
94342 static unsigned int pcpu_high_unit_cpu __read_mostly;
94343
94344 /* the address of the first chunk which starts with the kernel static area */
94345 -void *pcpu_base_addr __read_mostly;
94346 +void *pcpu_base_addr __read_only;
94347 EXPORT_SYMBOL_GPL(pcpu_base_addr);
94348
94349 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
94350 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
94351 index fd26d04..0cea1b0 100644
94352 --- a/mm/process_vm_access.c
94353 +++ b/mm/process_vm_access.c
94354 @@ -13,6 +13,7 @@
94355 #include <linux/uio.h>
94356 #include <linux/sched.h>
94357 #include <linux/highmem.h>
94358 +#include <linux/security.h>
94359 #include <linux/ptrace.h>
94360 #include <linux/slab.h>
94361 #include <linux/syscalls.h>
94362 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94363 size_t iov_l_curr_offset = 0;
94364 ssize_t iov_len;
94365
94366 + return -ENOSYS; // PaX: until properly audited
94367 +
94368 /*
94369 * Work out how many pages of struct pages we're going to need
94370 * when eventually calling get_user_pages
94371 */
94372 for (i = 0; i < riovcnt; i++) {
94373 iov_len = rvec[i].iov_len;
94374 - if (iov_len > 0) {
94375 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
94376 - + iov_len)
94377 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
94378 - / PAGE_SIZE + 1;
94379 - nr_pages = max(nr_pages, nr_pages_iov);
94380 - }
94381 + if (iov_len <= 0)
94382 + continue;
94383 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
94384 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
94385 + nr_pages = max(nr_pages, nr_pages_iov);
94386 }
94387
94388 if (nr_pages == 0)
94389 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94390 goto free_proc_pages;
94391 }
94392
94393 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
94394 + rc = -EPERM;
94395 + goto put_task_struct;
94396 + }
94397 +
94398 mm = mm_access(task, PTRACE_MODE_ATTACH);
94399 if (!mm || IS_ERR(mm)) {
94400 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
94401 diff --git a/mm/rmap.c b/mm/rmap.c
94402 index 8fc049f..1b21e12 100644
94403 --- a/mm/rmap.c
94404 +++ b/mm/rmap.c
94405 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94406 struct anon_vma *anon_vma = vma->anon_vma;
94407 struct anon_vma_chain *avc;
94408
94409 +#ifdef CONFIG_PAX_SEGMEXEC
94410 + struct anon_vma_chain *avc_m = NULL;
94411 +#endif
94412 +
94413 might_sleep();
94414 if (unlikely(!anon_vma)) {
94415 struct mm_struct *mm = vma->vm_mm;
94416 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94417 if (!avc)
94418 goto out_enomem;
94419
94420 +#ifdef CONFIG_PAX_SEGMEXEC
94421 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
94422 + if (!avc_m)
94423 + goto out_enomem_free_avc;
94424 +#endif
94425 +
94426 anon_vma = find_mergeable_anon_vma(vma);
94427 allocated = NULL;
94428 if (!anon_vma) {
94429 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94430 /* page_table_lock to protect against threads */
94431 spin_lock(&mm->page_table_lock);
94432 if (likely(!vma->anon_vma)) {
94433 +
94434 +#ifdef CONFIG_PAX_SEGMEXEC
94435 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
94436 +
94437 + if (vma_m) {
94438 + BUG_ON(vma_m->anon_vma);
94439 + vma_m->anon_vma = anon_vma;
94440 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
94441 + avc_m = NULL;
94442 + }
94443 +#endif
94444 +
94445 vma->anon_vma = anon_vma;
94446 anon_vma_chain_link(vma, avc, anon_vma);
94447 allocated = NULL;
94448 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94449
94450 if (unlikely(allocated))
94451 put_anon_vma(allocated);
94452 +
94453 +#ifdef CONFIG_PAX_SEGMEXEC
94454 + if (unlikely(avc_m))
94455 + anon_vma_chain_free(avc_m);
94456 +#endif
94457 +
94458 if (unlikely(avc))
94459 anon_vma_chain_free(avc);
94460 }
94461 return 0;
94462
94463 out_enomem_free_avc:
94464 +
94465 +#ifdef CONFIG_PAX_SEGMEXEC
94466 + if (avc_m)
94467 + anon_vma_chain_free(avc_m);
94468 +#endif
94469 +
94470 anon_vma_chain_free(avc);
94471 out_enomem:
94472 return -ENOMEM;
94473 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
94474 * Attach the anon_vmas from src to dst.
94475 * Returns 0 on success, -ENOMEM on failure.
94476 */
94477 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94478 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
94479 {
94480 struct anon_vma_chain *avc, *pavc;
94481 struct anon_vma *root = NULL;
94482 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94483 * the corresponding VMA in the parent process is attached to.
94484 * Returns 0 on success, non-zero on failure.
94485 */
94486 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
94487 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
94488 {
94489 struct anon_vma_chain *avc;
94490 struct anon_vma *anon_vma;
94491 @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
94492 void __init anon_vma_init(void)
94493 {
94494 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
94495 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
94496 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
94497 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
94498 + anon_vma_ctor);
94499 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
94500 + SLAB_PANIC|SLAB_NO_SANITIZE);
94501 }
94502
94503 /*
94504 diff --git a/mm/shmem.c b/mm/shmem.c
94505 index 1f18c9d..3e03d33 100644
94506 --- a/mm/shmem.c
94507 +++ b/mm/shmem.c
94508 @@ -33,7 +33,7 @@
94509 #include <linux/swap.h>
94510 #include <linux/aio.h>
94511
94512 -static struct vfsmount *shm_mnt;
94513 +struct vfsmount *shm_mnt;
94514
94515 #ifdef CONFIG_SHMEM
94516 /*
94517 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
94518 #define BOGO_DIRENT_SIZE 20
94519
94520 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
94521 -#define SHORT_SYMLINK_LEN 128
94522 +#define SHORT_SYMLINK_LEN 64
94523
94524 /*
94525 * shmem_fallocate and shmem_writepage communicate via inode->i_private
94526 @@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
94527 static int shmem_xattr_validate(const char *name)
94528 {
94529 struct { const char *prefix; size_t len; } arr[] = {
94530 +
94531 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94532 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
94533 +#endif
94534 +
94535 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
94536 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
94537 };
94538 @@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
94539 if (err)
94540 return err;
94541
94542 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94543 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
94544 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
94545 + return -EOPNOTSUPP;
94546 + if (size > 8)
94547 + return -EINVAL;
94548 + }
94549 +#endif
94550 +
94551 return simple_xattr_set(&info->xattrs, name, value, size, flags);
94552 }
94553
94554 @@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
94555 int err = -ENOMEM;
94556
94557 /* Round up to L1_CACHE_BYTES to resist false sharing */
94558 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
94559 - L1_CACHE_BYTES), GFP_KERNEL);
94560 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
94561 if (!sbinfo)
94562 return -ENOMEM;
94563
94564 diff --git a/mm/slab.c b/mm/slab.c
94565 index b264214..83872cd 100644
94566 --- a/mm/slab.c
94567 +++ b/mm/slab.c
94568 @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94569 if ((x)->max_freeable < i) \
94570 (x)->max_freeable = i; \
94571 } while (0)
94572 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
94573 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
94574 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
94575 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
94576 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
94577 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
94578 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
94579 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
94580 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
94581 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
94582 #else
94583 #define STATS_INC_ACTIVE(x) do { } while (0)
94584 #define STATS_DEC_ACTIVE(x) do { } while (0)
94585 @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94586 #define STATS_INC_ALLOCMISS(x) do { } while (0)
94587 #define STATS_INC_FREEHIT(x) do { } while (0)
94588 #define STATS_INC_FREEMISS(x) do { } while (0)
94589 +#define STATS_INC_SANITIZED(x) do { } while (0)
94590 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
94591 #endif
94592
94593 #if DEBUG
94594 @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
94595 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
94596 */
94597 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
94598 - const struct page *page, void *obj)
94599 + const struct page *page, const void *obj)
94600 {
94601 u32 offset = (obj - page->s_mem);
94602 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
94603 @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
94604 */
94605
94606 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
94607 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
94608 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94609
94610 if (INDEX_AC != INDEX_NODE)
94611 kmalloc_caches[INDEX_NODE] =
94612 create_kmalloc_cache("kmalloc-node",
94613 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
94614 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94615
94616 slab_early_init = 0;
94617
94618 @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
94619 struct array_cache *ac = cpu_cache_get(cachep);
94620
94621 check_irq_off();
94622 +
94623 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94624 + if (pax_sanitize_slab) {
94625 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
94626 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
94627 +
94628 + if (cachep->ctor)
94629 + cachep->ctor(objp);
94630 +
94631 + STATS_INC_SANITIZED(cachep);
94632 + } else
94633 + STATS_INC_NOT_SANITIZED(cachep);
94634 + }
94635 +#endif
94636 +
94637 kmemleak_free_recursive(objp, cachep->flags);
94638 objp = cache_free_debugcheck(cachep, objp, caller);
94639
94640 @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
94641
94642 if (unlikely(ZERO_OR_NULL_PTR(objp)))
94643 return;
94644 + VM_BUG_ON(!virt_addr_valid(objp));
94645 local_irq_save(flags);
94646 kfree_debugcheck(objp);
94647 c = virt_to_cache(objp);
94648 @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
94649 }
94650 /* cpu stats */
94651 {
94652 - unsigned long allochit = atomic_read(&cachep->allochit);
94653 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
94654 - unsigned long freehit = atomic_read(&cachep->freehit);
94655 - unsigned long freemiss = atomic_read(&cachep->freemiss);
94656 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
94657 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
94658 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
94659 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
94660
94661 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
94662 allochit, allocmiss, freehit, freemiss);
94663 }
94664 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94665 + {
94666 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
94667 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
94668 +
94669 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
94670 + }
94671 +#endif
94672 #endif
94673 }
94674
94675 @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
94676 static int __init slab_proc_init(void)
94677 {
94678 #ifdef CONFIG_DEBUG_SLAB_LEAK
94679 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
94680 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
94681 #endif
94682 return 0;
94683 }
94684 module_init(slab_proc_init);
94685 #endif
94686
94687 +bool is_usercopy_object(const void *ptr)
94688 +{
94689 + struct page *page;
94690 + struct kmem_cache *cachep;
94691 +
94692 + if (ZERO_OR_NULL_PTR(ptr))
94693 + return false;
94694 +
94695 + if (!slab_is_available())
94696 + return false;
94697 +
94698 + if (!virt_addr_valid(ptr))
94699 + return false;
94700 +
94701 + page = virt_to_head_page(ptr);
94702 +
94703 + if (!PageSlab(page))
94704 + return false;
94705 +
94706 + cachep = page->slab_cache;
94707 + return cachep->flags & SLAB_USERCOPY;
94708 +}
94709 +
94710 +#ifdef CONFIG_PAX_USERCOPY
94711 +const char *check_heap_object(const void *ptr, unsigned long n)
94712 +{
94713 + struct page *page;
94714 + struct kmem_cache *cachep;
94715 + unsigned int objnr;
94716 + unsigned long offset;
94717 +
94718 + if (ZERO_OR_NULL_PTR(ptr))
94719 + return "<null>";
94720 +
94721 + if (!virt_addr_valid(ptr))
94722 + return NULL;
94723 +
94724 + page = virt_to_head_page(ptr);
94725 +
94726 + if (!PageSlab(page))
94727 + return NULL;
94728 +
94729 + cachep = page->slab_cache;
94730 + if (!(cachep->flags & SLAB_USERCOPY))
94731 + return cachep->name;
94732 +
94733 + objnr = obj_to_index(cachep, page, ptr);
94734 + BUG_ON(objnr >= cachep->num);
94735 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
94736 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
94737 + return NULL;
94738 +
94739 + return cachep->name;
94740 +}
94741 +#endif
94742 +
94743 /**
94744 * ksize - get the actual amount of memory allocated for a given object
94745 * @objp: Pointer to the object
94746 diff --git a/mm/slab.h b/mm/slab.h
94747 index 8184a7c..ab27737 100644
94748 --- a/mm/slab.h
94749 +++ b/mm/slab.h
94750 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
94751 /* The slab cache that manages slab cache information */
94752 extern struct kmem_cache *kmem_cache;
94753
94754 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94755 +#ifdef CONFIG_X86_64
94756 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
94757 +#else
94758 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
94759 +#endif
94760 +extern bool pax_sanitize_slab;
94761 +#endif
94762 +
94763 unsigned long calculate_alignment(unsigned long flags,
94764 unsigned long align, unsigned long size);
94765
94766 @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94767
94768 /* Legal flag mask for kmem_cache_create(), for various configurations */
94769 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
94770 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
94771 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
94772 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
94773
94774 #if defined(CONFIG_DEBUG_SLAB)
94775 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
94776 @@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
94777 return s;
94778
94779 page = virt_to_head_page(x);
94780 +
94781 + BUG_ON(!PageSlab(page));
94782 +
94783 cachep = page->slab_cache;
94784 if (slab_equal_or_root(cachep, s))
94785 return cachep;
94786 diff --git a/mm/slab_common.c b/mm/slab_common.c
94787 index 1ec3c61..2067c11 100644
94788 --- a/mm/slab_common.c
94789 +++ b/mm/slab_common.c
94790 @@ -23,11 +23,22 @@
94791
94792 #include "slab.h"
94793
94794 -enum slab_state slab_state;
94795 +enum slab_state slab_state __read_only;
94796 LIST_HEAD(slab_caches);
94797 DEFINE_MUTEX(slab_mutex);
94798 struct kmem_cache *kmem_cache;
94799
94800 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94801 +bool pax_sanitize_slab __read_only = true;
94802 +static int __init pax_sanitize_slab_setup(char *str)
94803 +{
94804 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
94805 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
94806 + return 1;
94807 +}
94808 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
94809 +#endif
94810 +
94811 #ifdef CONFIG_DEBUG_VM
94812 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
94813 size_t size)
94814 @@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
94815 if (err)
94816 goto out_free_cache;
94817
94818 - s->refcount = 1;
94819 + atomic_set(&s->refcount, 1);
94820 list_add(&s->list, &slab_caches);
94821 memcg_register_cache(s);
94822
94823 @@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
94824
94825 get_online_cpus();
94826 mutex_lock(&slab_mutex);
94827 - s->refcount--;
94828 - if (!s->refcount) {
94829 + if (atomic_dec_and_test(&s->refcount)) {
94830 list_del(&s->list);
94831
94832 if (!__kmem_cache_shutdown(s)) {
94833 @@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
94834 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
94835 name, size, err);
94836
94837 - s->refcount = -1; /* Exempt from merging for now */
94838 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
94839 }
94840
94841 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94842 @@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94843
94844 create_boot_cache(s, name, size, flags);
94845 list_add(&s->list, &slab_caches);
94846 - s->refcount = 1;
94847 + atomic_set(&s->refcount, 1);
94848 return s;
94849 }
94850
94851 @@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
94852 EXPORT_SYMBOL(kmalloc_dma_caches);
94853 #endif
94854
94855 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94856 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
94857 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
94858 +#endif
94859 +
94860 /*
94861 * Conversion table for small slabs sizes / 8 to the index in the
94862 * kmalloc array. This is necessary for slabs < 192 since we have non power
94863 @@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
94864 return kmalloc_dma_caches[index];
94865
94866 #endif
94867 +
94868 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94869 + if (unlikely((flags & GFP_USERCOPY)))
94870 + return kmalloc_usercopy_caches[index];
94871 +
94872 +#endif
94873 +
94874 return kmalloc_caches[index];
94875 }
94876
94877 @@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
94878 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
94879 if (!kmalloc_caches[i]) {
94880 kmalloc_caches[i] = create_kmalloc_cache(NULL,
94881 - 1 << i, flags);
94882 + 1 << i, SLAB_USERCOPY | flags);
94883 }
94884
94885 /*
94886 @@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
94887 * earlier power of two caches
94888 */
94889 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
94890 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
94891 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
94892
94893 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
94894 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
94895 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
94896 }
94897
94898 /* Kmalloc array is now usable */
94899 @@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
94900 }
94901 }
94902 #endif
94903 +
94904 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94905 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
94906 + struct kmem_cache *s = kmalloc_caches[i];
94907 +
94908 + if (s) {
94909 + int size = kmalloc_size(i);
94910 + char *n = kasprintf(GFP_NOWAIT,
94911 + "usercopy-kmalloc-%d", size);
94912 +
94913 + BUG_ON(!n);
94914 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
94915 + size, SLAB_USERCOPY | flags);
94916 + }
94917 + }
94918 +#endif
94919 +
94920 }
94921 #endif /* !CONFIG_SLOB */
94922
94923 @@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
94924 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
94925 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
94926 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
94927 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94928 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
94929 +#endif
94930 #endif
94931 seq_putc(m, '\n');
94932 }
94933 diff --git a/mm/slob.c b/mm/slob.c
94934 index 4bf8809..98a6914 100644
94935 --- a/mm/slob.c
94936 +++ b/mm/slob.c
94937 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
94938 /*
94939 * Return the size of a slob block.
94940 */
94941 -static slobidx_t slob_units(slob_t *s)
94942 +static slobidx_t slob_units(const slob_t *s)
94943 {
94944 if (s->units > 0)
94945 return s->units;
94946 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
94947 /*
94948 * Return the next free slob block pointer after this one.
94949 */
94950 -static slob_t *slob_next(slob_t *s)
94951 +static slob_t *slob_next(const slob_t *s)
94952 {
94953 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
94954 slobidx_t next;
94955 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
94956 /*
94957 * Returns true if s is the last free block in its page.
94958 */
94959 -static int slob_last(slob_t *s)
94960 +static int slob_last(const slob_t *s)
94961 {
94962 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
94963 }
94964
94965 -static void *slob_new_pages(gfp_t gfp, int order, int node)
94966 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
94967 {
94968 - void *page;
94969 + struct page *page;
94970
94971 #ifdef CONFIG_NUMA
94972 if (node != NUMA_NO_NODE)
94973 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
94974 if (!page)
94975 return NULL;
94976
94977 - return page_address(page);
94978 + __SetPageSlab(page);
94979 + return page;
94980 }
94981
94982 -static void slob_free_pages(void *b, int order)
94983 +static void slob_free_pages(struct page *sp, int order)
94984 {
94985 if (current->reclaim_state)
94986 current->reclaim_state->reclaimed_slab += 1 << order;
94987 - free_pages((unsigned long)b, order);
94988 + __ClearPageSlab(sp);
94989 + page_mapcount_reset(sp);
94990 + sp->private = 0;
94991 + __free_pages(sp, order);
94992 }
94993
94994 /*
94995 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
94996
94997 /* Not enough space: must allocate a new page */
94998 if (!b) {
94999 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95000 - if (!b)
95001 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95002 + if (!sp)
95003 return NULL;
95004 - sp = virt_to_page(b);
95005 - __SetPageSlab(sp);
95006 + b = page_address(sp);
95007
95008 spin_lock_irqsave(&slob_lock, flags);
95009 sp->units = SLOB_UNITS(PAGE_SIZE);
95010 sp->freelist = b;
95011 + sp->private = 0;
95012 INIT_LIST_HEAD(&sp->list);
95013 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
95014 set_slob_page_free(sp, slob_list);
95015 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
95016 if (slob_page_free(sp))
95017 clear_slob_page_free(sp);
95018 spin_unlock_irqrestore(&slob_lock, flags);
95019 - __ClearPageSlab(sp);
95020 - page_mapcount_reset(sp);
95021 - slob_free_pages(b, 0);
95022 + slob_free_pages(sp, 0);
95023 return;
95024 }
95025
95026 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95027 + if (pax_sanitize_slab)
95028 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
95029 +#endif
95030 +
95031 if (!slob_page_free(sp)) {
95032 /* This slob page is about to become partially free. Easy! */
95033 sp->units = units;
95034 @@ -424,11 +431,10 @@ out:
95035 */
95036
95037 static __always_inline void *
95038 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95039 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
95040 {
95041 - unsigned int *m;
95042 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95043 - void *ret;
95044 + slob_t *m;
95045 + void *ret = NULL;
95046
95047 gfp &= gfp_allowed_mask;
95048
95049 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95050
95051 if (!m)
95052 return NULL;
95053 - *m = size;
95054 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
95055 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
95056 + m[0].units = size;
95057 + m[1].units = align;
95058 ret = (void *)m + align;
95059
95060 trace_kmalloc_node(caller, ret,
95061 size, size + align, gfp, node);
95062 } else {
95063 unsigned int order = get_order(size);
95064 + struct page *page;
95065
95066 if (likely(order))
95067 gfp |= __GFP_COMP;
95068 - ret = slob_new_pages(gfp, order, node);
95069 + page = slob_new_pages(gfp, order, node);
95070 + if (page) {
95071 + ret = page_address(page);
95072 + page->private = size;
95073 + }
95074
95075 trace_kmalloc_node(caller, ret,
95076 size, PAGE_SIZE << order, gfp, node);
95077 }
95078
95079 - kmemleak_alloc(ret, size, 1, gfp);
95080 + return ret;
95081 +}
95082 +
95083 +static __always_inline void *
95084 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95085 +{
95086 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95087 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95088 +
95089 + if (!ZERO_OR_NULL_PTR(ret))
95090 + kmemleak_alloc(ret, size, 1, gfp);
95091 return ret;
95092 }
95093
95094 @@ -493,34 +517,112 @@ void kfree(const void *block)
95095 return;
95096 kmemleak_free(block);
95097
95098 + VM_BUG_ON(!virt_addr_valid(block));
95099 sp = virt_to_page(block);
95100 - if (PageSlab(sp)) {
95101 + VM_BUG_ON(!PageSlab(sp));
95102 + if (!sp->private) {
95103 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95104 - unsigned int *m = (unsigned int *)(block - align);
95105 - slob_free(m, *m + align);
95106 - } else
95107 + slob_t *m = (slob_t *)(block - align);
95108 + slob_free(m, m[0].units + align);
95109 + } else {
95110 + __ClearPageSlab(sp);
95111 + page_mapcount_reset(sp);
95112 + sp->private = 0;
95113 __free_pages(sp, compound_order(sp));
95114 + }
95115 }
95116 EXPORT_SYMBOL(kfree);
95117
95118 +bool is_usercopy_object(const void *ptr)
95119 +{
95120 + if (!slab_is_available())
95121 + return false;
95122 +
95123 + // PAX: TODO
95124 +
95125 + return false;
95126 +}
95127 +
95128 +#ifdef CONFIG_PAX_USERCOPY
95129 +const char *check_heap_object(const void *ptr, unsigned long n)
95130 +{
95131 + struct page *page;
95132 + const slob_t *free;
95133 + const void *base;
95134 + unsigned long flags;
95135 +
95136 + if (ZERO_OR_NULL_PTR(ptr))
95137 + return "<null>";
95138 +
95139 + if (!virt_addr_valid(ptr))
95140 + return NULL;
95141 +
95142 + page = virt_to_head_page(ptr);
95143 + if (!PageSlab(page))
95144 + return NULL;
95145 +
95146 + if (page->private) {
95147 + base = page;
95148 + if (base <= ptr && n <= page->private - (ptr - base))
95149 + return NULL;
95150 + return "<slob>";
95151 + }
95152 +
95153 + /* some tricky double walking to find the chunk */
95154 + spin_lock_irqsave(&slob_lock, flags);
95155 + base = (void *)((unsigned long)ptr & PAGE_MASK);
95156 + free = page->freelist;
95157 +
95158 + while (!slob_last(free) && (void *)free <= ptr) {
95159 + base = free + slob_units(free);
95160 + free = slob_next(free);
95161 + }
95162 +
95163 + while (base < (void *)free) {
95164 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95165 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
95166 + int offset;
95167 +
95168 + if (ptr < base + align)
95169 + break;
95170 +
95171 + offset = ptr - base - align;
95172 + if (offset >= m) {
95173 + base += size;
95174 + continue;
95175 + }
95176 +
95177 + if (n > m - offset)
95178 + break;
95179 +
95180 + spin_unlock_irqrestore(&slob_lock, flags);
95181 + return NULL;
95182 + }
95183 +
95184 + spin_unlock_irqrestore(&slob_lock, flags);
95185 + return "<slob>";
95186 +}
95187 +#endif
95188 +
95189 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95190 size_t ksize(const void *block)
95191 {
95192 struct page *sp;
95193 int align;
95194 - unsigned int *m;
95195 + slob_t *m;
95196
95197 BUG_ON(!block);
95198 if (unlikely(block == ZERO_SIZE_PTR))
95199 return 0;
95200
95201 sp = virt_to_page(block);
95202 - if (unlikely(!PageSlab(sp)))
95203 - return PAGE_SIZE << compound_order(sp);
95204 + VM_BUG_ON(!PageSlab(sp));
95205 + if (sp->private)
95206 + return sp->private;
95207
95208 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95209 - m = (unsigned int *)(block - align);
95210 - return SLOB_UNITS(*m) * SLOB_UNIT;
95211 + m = (slob_t *)(block - align);
95212 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95213 }
95214 EXPORT_SYMBOL(ksize);
95215
95216 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95217
95218 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95219 {
95220 - void *b;
95221 + void *b = NULL;
95222
95223 flags &= gfp_allowed_mask;
95224
95225 lockdep_trace_alloc(flags);
95226
95227 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95228 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95229 +#else
95230 if (c->size < PAGE_SIZE) {
95231 b = slob_alloc(c->size, flags, c->align, node);
95232 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95233 SLOB_UNITS(c->size) * SLOB_UNIT,
95234 flags, node);
95235 } else {
95236 - b = slob_new_pages(flags, get_order(c->size), node);
95237 + struct page *sp;
95238 +
95239 + sp = slob_new_pages(flags, get_order(c->size), node);
95240 + if (sp) {
95241 + b = page_address(sp);
95242 + sp->private = c->size;
95243 + }
95244 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95245 PAGE_SIZE << get_order(c->size),
95246 flags, node);
95247 }
95248 +#endif
95249
95250 if (b && c->ctor)
95251 c->ctor(b);
95252 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95253
95254 static void __kmem_cache_free(void *b, int size)
95255 {
95256 - if (size < PAGE_SIZE)
95257 + struct page *sp;
95258 +
95259 + sp = virt_to_page(b);
95260 + BUG_ON(!PageSlab(sp));
95261 + if (!sp->private)
95262 slob_free(b, size);
95263 else
95264 - slob_free_pages(b, get_order(size));
95265 + slob_free_pages(sp, get_order(size));
95266 }
95267
95268 static void kmem_rcu_free(struct rcu_head *head)
95269 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95270
95271 void kmem_cache_free(struct kmem_cache *c, void *b)
95272 {
95273 + int size = c->size;
95274 +
95275 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95276 + if (size + c->align < PAGE_SIZE) {
95277 + size += c->align;
95278 + b -= c->align;
95279 + }
95280 +#endif
95281 +
95282 kmemleak_free_recursive(b, c->flags);
95283 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95284 struct slob_rcu *slob_rcu;
95285 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95286 - slob_rcu->size = c->size;
95287 + slob_rcu = b + (size - sizeof(struct slob_rcu));
95288 + slob_rcu->size = size;
95289 call_rcu(&slob_rcu->head, kmem_rcu_free);
95290 } else {
95291 - __kmem_cache_free(b, c->size);
95292 + __kmem_cache_free(b, size);
95293 }
95294
95295 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95296 + trace_kfree(_RET_IP_, b);
95297 +#else
95298 trace_kmem_cache_free(_RET_IP_, b);
95299 +#endif
95300 +
95301 }
95302 EXPORT_SYMBOL(kmem_cache_free);
95303
95304 diff --git a/mm/slub.c b/mm/slub.c
95305 index 25f14ad..ff4d0b7 100644
95306 --- a/mm/slub.c
95307 +++ b/mm/slub.c
95308 @@ -207,7 +207,7 @@ struct track {
95309
95310 enum track_item { TRACK_ALLOC, TRACK_FREE };
95311
95312 -#ifdef CONFIG_SYSFS
95313 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95314 static int sysfs_slab_add(struct kmem_cache *);
95315 static int sysfs_slab_alias(struct kmem_cache *, const char *);
95316 static void sysfs_slab_remove(struct kmem_cache *);
95317 @@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
95318 if (!t->addr)
95319 return;
95320
95321 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
95322 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
95323 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
95324 #ifdef CONFIG_STACKTRACE
95325 {
95326 @@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
95327
95328 slab_free_hook(s, x);
95329
95330 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95331 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
95332 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
95333 + if (s->ctor)
95334 + s->ctor(x);
95335 + }
95336 +#endif
95337 +
95338 redo:
95339 /*
95340 * Determine the currently cpus per cpu slab.
95341 @@ -2733,7 +2741,7 @@ static int slub_min_objects;
95342 * Merge control. If this is set then no merging of slab caches will occur.
95343 * (Could be removed. This was introduced to pacify the merge skeptics.)
95344 */
95345 -static int slub_nomerge;
95346 +static int slub_nomerge = 1;
95347
95348 /*
95349 * Calculate the order of allocation given an slab object size.
95350 @@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
95351 s->inuse = size;
95352
95353 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
95354 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95355 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
95356 +#endif
95357 s->ctor)) {
95358 /*
95359 * Relocate free pointer after the object if it is not
95360 @@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
95361 EXPORT_SYMBOL(__kmalloc_node);
95362 #endif
95363
95364 +bool is_usercopy_object(const void *ptr)
95365 +{
95366 + struct page *page;
95367 + struct kmem_cache *s;
95368 +
95369 + if (ZERO_OR_NULL_PTR(ptr))
95370 + return false;
95371 +
95372 + if (!slab_is_available())
95373 + return false;
95374 +
95375 + if (!virt_addr_valid(ptr))
95376 + return false;
95377 +
95378 + page = virt_to_head_page(ptr);
95379 +
95380 + if (!PageSlab(page))
95381 + return false;
95382 +
95383 + s = page->slab_cache;
95384 + return s->flags & SLAB_USERCOPY;
95385 +}
95386 +
95387 +#ifdef CONFIG_PAX_USERCOPY
95388 +const char *check_heap_object(const void *ptr, unsigned long n)
95389 +{
95390 + struct page *page;
95391 + struct kmem_cache *s;
95392 + unsigned long offset;
95393 +
95394 + if (ZERO_OR_NULL_PTR(ptr))
95395 + return "<null>";
95396 +
95397 + if (!virt_addr_valid(ptr))
95398 + return NULL;
95399 +
95400 + page = virt_to_head_page(ptr);
95401 +
95402 + if (!PageSlab(page))
95403 + return NULL;
95404 +
95405 + s = page->slab_cache;
95406 + if (!(s->flags & SLAB_USERCOPY))
95407 + return s->name;
95408 +
95409 + offset = (ptr - page_address(page)) % s->size;
95410 + if (offset <= s->object_size && n <= s->object_size - offset)
95411 + return NULL;
95412 +
95413 + return s->name;
95414 +}
95415 +#endif
95416 +
95417 size_t ksize(const void *object)
95418 {
95419 struct page *page;
95420 @@ -3387,6 +3451,7 @@ void kfree(const void *x)
95421 if (unlikely(ZERO_OR_NULL_PTR(x)))
95422 return;
95423
95424 + VM_BUG_ON(!virt_addr_valid(x));
95425 page = virt_to_head_page(x);
95426 if (unlikely(!PageSlab(page))) {
95427 BUG_ON(!PageCompound(page));
95428 @@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
95429 /*
95430 * We may have set a slab to be unmergeable during bootstrap.
95431 */
95432 - if (s->refcount < 0)
95433 + if (atomic_read(&s->refcount) < 0)
95434 return 1;
95435
95436 return 0;
95437 @@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95438
95439 s = find_mergeable(memcg, size, align, flags, name, ctor);
95440 if (s) {
95441 - s->refcount++;
95442 + atomic_inc(&s->refcount);
95443 /*
95444 * Adjust the object sizes so that we clear
95445 * the complete object on kzalloc.
95446 @@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95447 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
95448
95449 if (sysfs_slab_alias(s, name)) {
95450 - s->refcount--;
95451 + atomic_dec(&s->refcount);
95452 s = NULL;
95453 }
95454 }
95455 @@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
95456 }
95457 #endif
95458
95459 -#ifdef CONFIG_SYSFS
95460 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95461 static int count_inuse(struct page *page)
95462 {
95463 return page->inuse;
95464 @@ -4268,12 +4333,12 @@ static void resiliency_test(void)
95465 validate_slab_cache(kmalloc_caches[9]);
95466 }
95467 #else
95468 -#ifdef CONFIG_SYSFS
95469 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95470 static void resiliency_test(void) {};
95471 #endif
95472 #endif
95473
95474 -#ifdef CONFIG_SYSFS
95475 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95476 enum slab_stat_type {
95477 SL_ALL, /* All slabs */
95478 SL_PARTIAL, /* Only partially allocated slabs */
95479 @@ -4519,7 +4584,7 @@ SLAB_ATTR_RO(ctor);
95480
95481 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
95482 {
95483 - return sprintf(buf, "%d\n", s->refcount - 1);
95484 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
95485 }
95486 SLAB_ATTR_RO(aliases);
95487
95488 @@ -4607,6 +4672,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
95489 SLAB_ATTR_RO(cache_dma);
95490 #endif
95491
95492 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95493 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
95494 +{
95495 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
95496 +}
95497 +SLAB_ATTR_RO(usercopy);
95498 +#endif
95499 +
95500 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
95501 {
95502 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
95503 @@ -4941,6 +5014,9 @@ static struct attribute *slab_attrs[] = {
95504 #ifdef CONFIG_ZONE_DMA
95505 &cache_dma_attr.attr,
95506 #endif
95507 +#ifdef CONFIG_PAX_USERCOPY_SLABS
95508 + &usercopy_attr.attr,
95509 +#endif
95510 #ifdef CONFIG_NUMA
95511 &remote_node_defrag_ratio_attr.attr,
95512 #endif
95513 @@ -5173,6 +5249,7 @@ static char *create_unique_id(struct kmem_cache *s)
95514 return name;
95515 }
95516
95517 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95518 static int sysfs_slab_add(struct kmem_cache *s)
95519 {
95520 int err;
95521 @@ -5230,6 +5307,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
95522 kobject_del(&s->kobj);
95523 kobject_put(&s->kobj);
95524 }
95525 +#endif
95526
95527 /*
95528 * Need to buffer aliases during bootup until sysfs becomes
95529 @@ -5243,6 +5321,7 @@ struct saved_alias {
95530
95531 static struct saved_alias *alias_list;
95532
95533 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95534 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95535 {
95536 struct saved_alias *al;
95537 @@ -5265,6 +5344,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95538 alias_list = al;
95539 return 0;
95540 }
95541 +#endif
95542
95543 static int __init slab_sysfs_init(void)
95544 {
95545 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
95546 index 4cba9c2..b4f9fcc 100644
95547 --- a/mm/sparse-vmemmap.c
95548 +++ b/mm/sparse-vmemmap.c
95549 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
95550 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95551 if (!p)
95552 return NULL;
95553 - pud_populate(&init_mm, pud, p);
95554 + pud_populate_kernel(&init_mm, pud, p);
95555 }
95556 return pud;
95557 }
95558 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
95559 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95560 if (!p)
95561 return NULL;
95562 - pgd_populate(&init_mm, pgd, p);
95563 + pgd_populate_kernel(&init_mm, pgd, p);
95564 }
95565 return pgd;
95566 }
95567 diff --git a/mm/sparse.c b/mm/sparse.c
95568 index 63c3ea5..95c0858 100644
95569 --- a/mm/sparse.c
95570 +++ b/mm/sparse.c
95571 @@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
95572
95573 for (i = 0; i < PAGES_PER_SECTION; i++) {
95574 if (PageHWPoison(&memmap[i])) {
95575 - atomic_long_sub(1, &num_poisoned_pages);
95576 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
95577 ClearPageHWPoison(&memmap[i]);
95578 }
95579 }
95580 diff --git a/mm/swap.c b/mm/swap.c
95581 index 0092097..33361ff 100644
95582 --- a/mm/swap.c
95583 +++ b/mm/swap.c
95584 @@ -31,6 +31,7 @@
95585 #include <linux/memcontrol.h>
95586 #include <linux/gfp.h>
95587 #include <linux/uio.h>
95588 +#include <linux/hugetlb.h>
95589
95590 #include "internal.h"
95591
95592 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
95593
95594 __page_cache_release(page);
95595 dtor = get_compound_page_dtor(page);
95596 + if (!PageHuge(page))
95597 + BUG_ON(dtor != free_compound_page);
95598 (*dtor)(page);
95599 }
95600
95601 diff --git a/mm/swapfile.c b/mm/swapfile.c
95602 index 4a7f7e6..22cddf5 100644
95603 --- a/mm/swapfile.c
95604 +++ b/mm/swapfile.c
95605 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
95606
95607 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
95608 /* Activity counter to indicate that a swapon or swapoff has occurred */
95609 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
95610 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
95611
95612 static inline unsigned char swap_count(unsigned char ent)
95613 {
95614 @@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
95615 spin_unlock(&swap_lock);
95616
95617 err = 0;
95618 - atomic_inc(&proc_poll_event);
95619 + atomic_inc_unchecked(&proc_poll_event);
95620 wake_up_interruptible(&proc_poll_wait);
95621
95622 out_dput:
95623 @@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
95624
95625 poll_wait(file, &proc_poll_wait, wait);
95626
95627 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
95628 - seq->poll_event = atomic_read(&proc_poll_event);
95629 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
95630 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95631 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
95632 }
95633
95634 @@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
95635 return ret;
95636
95637 seq = file->private_data;
95638 - seq->poll_event = atomic_read(&proc_poll_event);
95639 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95640 return 0;
95641 }
95642
95643 @@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
95644 (frontswap_map) ? "FS" : "");
95645
95646 mutex_unlock(&swapon_mutex);
95647 - atomic_inc(&proc_poll_event);
95648 + atomic_inc_unchecked(&proc_poll_event);
95649 wake_up_interruptible(&proc_poll_wait);
95650
95651 if (S_ISREG(inode->i_mode))
95652 diff --git a/mm/util.c b/mm/util.c
95653 index a24aa22..a0d41ae 100644
95654 --- a/mm/util.c
95655 +++ b/mm/util.c
95656 @@ -297,6 +297,12 @@ done:
95657 void arch_pick_mmap_layout(struct mm_struct *mm)
95658 {
95659 mm->mmap_base = TASK_UNMAPPED_BASE;
95660 +
95661 +#ifdef CONFIG_PAX_RANDMMAP
95662 + if (mm->pax_flags & MF_PAX_RANDMMAP)
95663 + mm->mmap_base += mm->delta_mmap;
95664 +#endif
95665 +
95666 mm->get_unmapped_area = arch_get_unmapped_area;
95667 }
95668 #endif
95669 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
95670 index 0fdf968..d6686e8 100644
95671 --- a/mm/vmalloc.c
95672 +++ b/mm/vmalloc.c
95673 @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
95674
95675 pte = pte_offset_kernel(pmd, addr);
95676 do {
95677 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95678 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95679 +
95680 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95681 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
95682 + BUG_ON(!pte_exec(*pte));
95683 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
95684 + continue;
95685 + }
95686 +#endif
95687 +
95688 + {
95689 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95690 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95691 + }
95692 } while (pte++, addr += PAGE_SIZE, addr != end);
95693 }
95694
95695 @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
95696 pte = pte_alloc_kernel(pmd, addr);
95697 if (!pte)
95698 return -ENOMEM;
95699 +
95700 + pax_open_kernel();
95701 do {
95702 struct page *page = pages[*nr];
95703
95704 - if (WARN_ON(!pte_none(*pte)))
95705 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95706 + if (pgprot_val(prot) & _PAGE_NX)
95707 +#endif
95708 +
95709 + if (!pte_none(*pte)) {
95710 + pax_close_kernel();
95711 + WARN_ON(1);
95712 return -EBUSY;
95713 - if (WARN_ON(!page))
95714 + }
95715 + if (!page) {
95716 + pax_close_kernel();
95717 + WARN_ON(1);
95718 return -ENOMEM;
95719 + }
95720 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
95721 (*nr)++;
95722 } while (pte++, addr += PAGE_SIZE, addr != end);
95723 + pax_close_kernel();
95724 return 0;
95725 }
95726
95727 @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
95728 pmd_t *pmd;
95729 unsigned long next;
95730
95731 - pmd = pmd_alloc(&init_mm, pud, addr);
95732 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95733 if (!pmd)
95734 return -ENOMEM;
95735 do {
95736 @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
95737 pud_t *pud;
95738 unsigned long next;
95739
95740 - pud = pud_alloc(&init_mm, pgd, addr);
95741 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
95742 if (!pud)
95743 return -ENOMEM;
95744 do {
95745 @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
95746 if (addr >= MODULES_VADDR && addr < MODULES_END)
95747 return 1;
95748 #endif
95749 +
95750 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95751 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
95752 + return 1;
95753 +#endif
95754 +
95755 return is_vmalloc_addr(x);
95756 }
95757
95758 @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
95759
95760 if (!pgd_none(*pgd)) {
95761 pud_t *pud = pud_offset(pgd, addr);
95762 +#ifdef CONFIG_X86
95763 + if (!pud_large(*pud))
95764 +#endif
95765 if (!pud_none(*pud)) {
95766 pmd_t *pmd = pmd_offset(pud, addr);
95767 +#ifdef CONFIG_X86
95768 + if (!pmd_large(*pmd))
95769 +#endif
95770 if (!pmd_none(*pmd)) {
95771 pte_t *ptep, pte;
95772
95773 @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
95774 struct vm_struct *area;
95775
95776 BUG_ON(in_interrupt());
95777 +
95778 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95779 + if (flags & VM_KERNEXEC) {
95780 + if (start != VMALLOC_START || end != VMALLOC_END)
95781 + return NULL;
95782 + start = (unsigned long)MODULES_EXEC_VADDR;
95783 + end = (unsigned long)MODULES_EXEC_END;
95784 + }
95785 +#endif
95786 +
95787 if (flags & VM_IOREMAP)
95788 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
95789
95790 @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
95791 if (count > totalram_pages)
95792 return NULL;
95793
95794 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95795 + if (!(pgprot_val(prot) & _PAGE_NX))
95796 + flags |= VM_KERNEXEC;
95797 +#endif
95798 +
95799 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
95800 __builtin_return_address(0));
95801 if (!area)
95802 @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
95803 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
95804 goto fail;
95805
95806 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95807 + if (!(pgprot_val(prot) & _PAGE_NX))
95808 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
95809 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
95810 + else
95811 +#endif
95812 +
95813 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
95814 start, end, node, gfp_mask, caller);
95815 if (!area)
95816 @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
95817 * For tight control over page level allocator and protection flags
95818 * use __vmalloc() instead.
95819 */
95820 -
95821 void *vmalloc_exec(unsigned long size)
95822 {
95823 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
95824 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
95825 NUMA_NO_NODE, __builtin_return_address(0));
95826 }
95827
95828 @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
95829 {
95830 struct vm_struct *area;
95831
95832 + BUG_ON(vma->vm_mirror);
95833 +
95834 size = PAGE_ALIGN(size);
95835
95836 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
95837 @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
95838 v->addr, v->addr + v->size, v->size);
95839
95840 if (v->caller)
95841 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95842 + seq_printf(m, " %pK", v->caller);
95843 +#else
95844 seq_printf(m, " %pS", v->caller);
95845 +#endif
95846
95847 if (v->nr_pages)
95848 seq_printf(m, " pages=%d", v->nr_pages);
95849 diff --git a/mm/vmstat.c b/mm/vmstat.c
95850 index def5dd2..4ce55cec 100644
95851 --- a/mm/vmstat.c
95852 +++ b/mm/vmstat.c
95853 @@ -20,6 +20,7 @@
95854 #include <linux/writeback.h>
95855 #include <linux/compaction.h>
95856 #include <linux/mm_inline.h>
95857 +#include <linux/grsecurity.h>
95858
95859 #include "internal.h"
95860
95861 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
95862 *
95863 * vm_stat contains the global counters
95864 */
95865 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95866 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95867 EXPORT_SYMBOL(vm_stat);
95868
95869 #ifdef CONFIG_SMP
95870 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
95871
95872 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
95873 if (diff[i])
95874 - atomic_long_add(diff[i], &vm_stat[i]);
95875 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
95876 }
95877
95878 /*
95879 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
95880 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
95881 if (v) {
95882
95883 - atomic_long_add(v, &zone->vm_stat[i]);
95884 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95885 global_diff[i] += v;
95886 #ifdef CONFIG_NUMA
95887 /* 3 seconds idle till flush */
95888 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
95889
95890 v = p->vm_stat_diff[i];
95891 p->vm_stat_diff[i] = 0;
95892 - atomic_long_add(v, &zone->vm_stat[i]);
95893 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95894 global_diff[i] += v;
95895 }
95896 }
95897 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
95898 if (pset->vm_stat_diff[i]) {
95899 int v = pset->vm_stat_diff[i];
95900 pset->vm_stat_diff[i] = 0;
95901 - atomic_long_add(v, &zone->vm_stat[i]);
95902 - atomic_long_add(v, &vm_stat[i]);
95903 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95904 + atomic_long_add_unchecked(v, &vm_stat[i]);
95905 }
95906 }
95907 #endif
95908 @@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
95909 stat_items_size += sizeof(struct vm_event_state);
95910 #endif
95911
95912 - v = kmalloc(stat_items_size, GFP_KERNEL);
95913 + v = kzalloc(stat_items_size, GFP_KERNEL);
95914 m->private = v;
95915 if (!v)
95916 return ERR_PTR(-ENOMEM);
95917 +
95918 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
95919 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
95920 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
95921 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
95922 + && !in_group_p(grsec_proc_gid)
95923 +#endif
95924 + )
95925 + return (unsigned long *)m->private + *pos;
95926 +#endif
95927 +#endif
95928 +
95929 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
95930 v[i] = global_page_state(i);
95931 v += NR_VM_ZONE_STAT_ITEMS;
95932 @@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
95933 put_online_cpus();
95934 #endif
95935 #ifdef CONFIG_PROC_FS
95936 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
95937 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
95938 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
95939 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
95940 + {
95941 + mode_t gr_mode = S_IRUGO;
95942 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
95943 + gr_mode = S_IRUSR;
95944 +#endif
95945 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
95946 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
95947 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
95948 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
95949 + }
95950 #endif
95951 return 0;
95952 }
95953 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
95954 index 175273f..1c63e05 100644
95955 --- a/net/8021q/vlan.c
95956 +++ b/net/8021q/vlan.c
95957 @@ -474,7 +474,7 @@ out:
95958 return NOTIFY_DONE;
95959 }
95960
95961 -static struct notifier_block vlan_notifier_block __read_mostly = {
95962 +static struct notifier_block vlan_notifier_block = {
95963 .notifier_call = vlan_device_event,
95964 };
95965
95966 @@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
95967 err = -EPERM;
95968 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
95969 break;
95970 - if ((args.u.name_type >= 0) &&
95971 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
95972 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
95973 struct vlan_net *vn;
95974
95975 vn = net_generic(net, vlan_net_id);
95976 diff --git a/net/9p/client.c b/net/9p/client.c
95977 index 9186550..e604a2f 100644
95978 --- a/net/9p/client.c
95979 +++ b/net/9p/client.c
95980 @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
95981 len - inline_len);
95982 } else {
95983 err = copy_from_user(ename + inline_len,
95984 - uidata, len - inline_len);
95985 + (char __force_user *)uidata, len - inline_len);
95986 if (err) {
95987 err = -EFAULT;
95988 goto out_err;
95989 @@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
95990 kernel_buf = 1;
95991 indata = data;
95992 } else
95993 - indata = (__force char *)udata;
95994 + indata = (__force_kernel char *)udata;
95995 /*
95996 * response header len is 11
95997 * PDU Header(7) + IO Size (4)
95998 @@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
95999 kernel_buf = 1;
96000 odata = data;
96001 } else
96002 - odata = (char *)udata;
96003 + odata = (char __force_kernel *)udata;
96004 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
96005 P9_ZC_HDR_SZ, kernel_buf, "dqd",
96006 fid->fid, offset, rsize);
96007 diff --git a/net/9p/mod.c b/net/9p/mod.c
96008 index 6ab36ae..6f1841b 100644
96009 --- a/net/9p/mod.c
96010 +++ b/net/9p/mod.c
96011 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
96012 void v9fs_register_trans(struct p9_trans_module *m)
96013 {
96014 spin_lock(&v9fs_trans_lock);
96015 - list_add_tail(&m->list, &v9fs_trans_list);
96016 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
96017 spin_unlock(&v9fs_trans_lock);
96018 }
96019 EXPORT_SYMBOL(v9fs_register_trans);
96020 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
96021 void v9fs_unregister_trans(struct p9_trans_module *m)
96022 {
96023 spin_lock(&v9fs_trans_lock);
96024 - list_del_init(&m->list);
96025 + pax_list_del_init((struct list_head *)&m->list);
96026 spin_unlock(&v9fs_trans_lock);
96027 }
96028 EXPORT_SYMBOL(v9fs_unregister_trans);
96029 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
96030 index b7bd7f2..2498bf7 100644
96031 --- a/net/9p/trans_fd.c
96032 +++ b/net/9p/trans_fd.c
96033 @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
96034 oldfs = get_fs();
96035 set_fs(get_ds());
96036 /* The cast to a user pointer is valid due to the set_fs() */
96037 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
96038 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
96039 set_fs(oldfs);
96040
96041 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
96042 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
96043 index 876fbe8..8bbea9f 100644
96044 --- a/net/atm/atm_misc.c
96045 +++ b/net/atm/atm_misc.c
96046 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
96047 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
96048 return 1;
96049 atm_return(vcc, truesize);
96050 - atomic_inc(&vcc->stats->rx_drop);
96051 + atomic_inc_unchecked(&vcc->stats->rx_drop);
96052 return 0;
96053 }
96054 EXPORT_SYMBOL(atm_charge);
96055 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
96056 }
96057 }
96058 atm_return(vcc, guess);
96059 - atomic_inc(&vcc->stats->rx_drop);
96060 + atomic_inc_unchecked(&vcc->stats->rx_drop);
96061 return NULL;
96062 }
96063 EXPORT_SYMBOL(atm_alloc_charge);
96064 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
96065
96066 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96067 {
96068 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96069 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96070 __SONET_ITEMS
96071 #undef __HANDLE_ITEM
96072 }
96073 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
96074
96075 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96076 {
96077 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96078 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96079 __SONET_ITEMS
96080 #undef __HANDLE_ITEM
96081 }
96082 diff --git a/net/atm/lec.c b/net/atm/lec.c
96083 index 5a2f602..9396143 100644
96084 --- a/net/atm/lec.c
96085 +++ b/net/atm/lec.c
96086 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96087 }
96088
96089 static struct lane2_ops lane2_ops = {
96090 - lane2_resolve, /* resolve, spec 3.1.3 */
96091 - lane2_associate_req, /* associate_req, spec 3.1.4 */
96092 - NULL /* associate indicator, spec 3.1.5 */
96093 + .resolve = lane2_resolve,
96094 + .associate_req = lane2_associate_req,
96095 + .associate_indicator = NULL
96096 };
96097
96098 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96099 diff --git a/net/atm/lec.h b/net/atm/lec.h
96100 index 4149db1..f2ab682 100644
96101 --- a/net/atm/lec.h
96102 +++ b/net/atm/lec.h
96103 @@ -48,7 +48,7 @@ struct lane2_ops {
96104 const u8 *tlvs, u32 sizeoftlvs);
96105 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96106 const u8 *tlvs, u32 sizeoftlvs);
96107 -};
96108 +} __no_const;
96109
96110 /*
96111 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96112 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96113 index d1b2d9a..d549f7f 100644
96114 --- a/net/atm/mpoa_caches.c
96115 +++ b/net/atm/mpoa_caches.c
96116 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96117
96118
96119 static struct in_cache_ops ingress_ops = {
96120 - in_cache_add_entry, /* add_entry */
96121 - in_cache_get, /* get */
96122 - in_cache_get_with_mask, /* get_with_mask */
96123 - in_cache_get_by_vcc, /* get_by_vcc */
96124 - in_cache_put, /* put */
96125 - in_cache_remove_entry, /* remove_entry */
96126 - cache_hit, /* cache_hit */
96127 - clear_count_and_expired, /* clear_count */
96128 - check_resolving_entries, /* check_resolving */
96129 - refresh_entries, /* refresh */
96130 - in_destroy_cache /* destroy_cache */
96131 + .add_entry = in_cache_add_entry,
96132 + .get = in_cache_get,
96133 + .get_with_mask = in_cache_get_with_mask,
96134 + .get_by_vcc = in_cache_get_by_vcc,
96135 + .put = in_cache_put,
96136 + .remove_entry = in_cache_remove_entry,
96137 + .cache_hit = cache_hit,
96138 + .clear_count = clear_count_and_expired,
96139 + .check_resolving = check_resolving_entries,
96140 + .refresh = refresh_entries,
96141 + .destroy_cache = in_destroy_cache
96142 };
96143
96144 static struct eg_cache_ops egress_ops = {
96145 - eg_cache_add_entry, /* add_entry */
96146 - eg_cache_get_by_cache_id, /* get_by_cache_id */
96147 - eg_cache_get_by_tag, /* get_by_tag */
96148 - eg_cache_get_by_vcc, /* get_by_vcc */
96149 - eg_cache_get_by_src_ip, /* get_by_src_ip */
96150 - eg_cache_put, /* put */
96151 - eg_cache_remove_entry, /* remove_entry */
96152 - update_eg_cache_entry, /* update */
96153 - clear_expired, /* clear_expired */
96154 - eg_destroy_cache /* destroy_cache */
96155 + .add_entry = eg_cache_add_entry,
96156 + .get_by_cache_id = eg_cache_get_by_cache_id,
96157 + .get_by_tag = eg_cache_get_by_tag,
96158 + .get_by_vcc = eg_cache_get_by_vcc,
96159 + .get_by_src_ip = eg_cache_get_by_src_ip,
96160 + .put = eg_cache_put,
96161 + .remove_entry = eg_cache_remove_entry,
96162 + .update = update_eg_cache_entry,
96163 + .clear_expired = clear_expired,
96164 + .destroy_cache = eg_destroy_cache
96165 };
96166
96167
96168 diff --git a/net/atm/proc.c b/net/atm/proc.c
96169 index bbb6461..cf04016 100644
96170 --- a/net/atm/proc.c
96171 +++ b/net/atm/proc.c
96172 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96173 const struct k_atm_aal_stats *stats)
96174 {
96175 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96176 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96177 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96178 - atomic_read(&stats->rx_drop));
96179 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96180 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96181 + atomic_read_unchecked(&stats->rx_drop));
96182 }
96183
96184 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96185 diff --git a/net/atm/resources.c b/net/atm/resources.c
96186 index 0447d5d..3cf4728 100644
96187 --- a/net/atm/resources.c
96188 +++ b/net/atm/resources.c
96189 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96190 static void copy_aal_stats(struct k_atm_aal_stats *from,
96191 struct atm_aal_stats *to)
96192 {
96193 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96194 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96195 __AAL_STAT_ITEMS
96196 #undef __HANDLE_ITEM
96197 }
96198 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96199 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96200 struct atm_aal_stats *to)
96201 {
96202 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96203 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96204 __AAL_STAT_ITEMS
96205 #undef __HANDLE_ITEM
96206 }
96207 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96208 index 919a5ce..cc6b444 100644
96209 --- a/net/ax25/sysctl_net_ax25.c
96210 +++ b/net/ax25/sysctl_net_ax25.c
96211 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96212 {
96213 char path[sizeof("net/ax25/") + IFNAMSIZ];
96214 int k;
96215 - struct ctl_table *table;
96216 + ctl_table_no_const *table;
96217
96218 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96219 if (!table)
96220 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96221 index 8323bce..a03130d 100644
96222 --- a/net/batman-adv/bat_iv_ogm.c
96223 +++ b/net/batman-adv/bat_iv_ogm.c
96224 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96225
96226 /* randomize initial seqno to avoid collision */
96227 get_random_bytes(&random_seqno, sizeof(random_seqno));
96228 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96229 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96230
96231 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96232 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96233 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96234 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96235
96236 /* change sequence number to network order */
96237 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96238 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96239 batadv_ogm_packet->seqno = htonl(seqno);
96240 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96241 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96242
96243 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96244
96245 @@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
96246 return;
96247
96248 /* could be changed by schedule_own_packet() */
96249 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96250 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96251
96252 if (ogm_packet->flags & BATADV_DIRECTLINK)
96253 has_directlink_flag = true;
96254 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96255 index 88df9b1..69cf7c0 100644
96256 --- a/net/batman-adv/fragmentation.c
96257 +++ b/net/batman-adv/fragmentation.c
96258 @@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96259 frag_header.packet_type = BATADV_UNICAST_FRAG;
96260 frag_header.version = BATADV_COMPAT_VERSION;
96261 frag_header.ttl = BATADV_TTL;
96262 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96263 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96264 frag_header.reserved = 0;
96265 frag_header.no = 0;
96266 frag_header.total_size = htons(skb->len);
96267 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96268 index f82c267..0e56d32 100644
96269 --- a/net/batman-adv/soft-interface.c
96270 +++ b/net/batman-adv/soft-interface.c
96271 @@ -283,7 +283,7 @@ send:
96272 primary_if->net_dev->dev_addr, ETH_ALEN);
96273
96274 /* set broadcast sequence number */
96275 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96276 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96277 bcast_packet->seqno = htonl(seqno);
96278
96279 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96280 @@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96281 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96282
96283 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96284 - atomic_set(&bat_priv->bcast_seqno, 1);
96285 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96286 atomic_set(&bat_priv->tt.vn, 0);
96287 atomic_set(&bat_priv->tt.local_changes, 0);
96288 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96289 @@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96290
96291 /* randomize initial seqno to avoid collision */
96292 get_random_bytes(&random_seqno, sizeof(random_seqno));
96293 - atomic_set(&bat_priv->frag_seqno, random_seqno);
96294 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96295
96296 bat_priv->primary_if = NULL;
96297 bat_priv->num_ifaces = 0;
96298 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
96299 index 78370ab..1cb3614 100644
96300 --- a/net/batman-adv/types.h
96301 +++ b/net/batman-adv/types.h
96302 @@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
96303 struct batadv_hard_iface_bat_iv {
96304 unsigned char *ogm_buff;
96305 int ogm_buff_len;
96306 - atomic_t ogm_seqno;
96307 + atomic_unchecked_t ogm_seqno;
96308 };
96309
96310 /**
96311 @@ -714,7 +714,7 @@ struct batadv_priv {
96312 atomic_t bonding;
96313 atomic_t fragmentation;
96314 atomic_t packet_size_max;
96315 - atomic_t frag_seqno;
96316 + atomic_unchecked_t frag_seqno;
96317 #ifdef CONFIG_BATMAN_ADV_BLA
96318 atomic_t bridge_loop_avoidance;
96319 #endif
96320 @@ -730,7 +730,7 @@ struct batadv_priv {
96321 #endif
96322 uint32_t isolation_mark;
96323 uint32_t isolation_mark_mask;
96324 - atomic_t bcast_seqno;
96325 + atomic_unchecked_t bcast_seqno;
96326 atomic_t bcast_queue_left;
96327 atomic_t batman_queue_left;
96328 char num_ifaces;
96329 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
96330 index 7552f9e..074ce29 100644
96331 --- a/net/bluetooth/hci_sock.c
96332 +++ b/net/bluetooth/hci_sock.c
96333 @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
96334 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
96335 }
96336
96337 - len = min_t(unsigned int, len, sizeof(uf));
96338 + len = min((size_t)len, sizeof(uf));
96339 if (copy_from_user(&uf, optval, len)) {
96340 err = -EFAULT;
96341 break;
96342 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
96343 index b0ad2c7..96f6a5e 100644
96344 --- a/net/bluetooth/l2cap_core.c
96345 +++ b/net/bluetooth/l2cap_core.c
96346 @@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
96347 break;
96348
96349 case L2CAP_CONF_RFC:
96350 - if (olen == sizeof(rfc))
96351 - memcpy(&rfc, (void *)val, olen);
96352 + if (olen != sizeof(rfc))
96353 + break;
96354 +
96355 + memcpy(&rfc, (void *)val, olen);
96356
96357 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
96358 rfc.mode != chan->mode)
96359 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
96360 index d58f76b..b69600a 100644
96361 --- a/net/bluetooth/l2cap_sock.c
96362 +++ b/net/bluetooth/l2cap_sock.c
96363 @@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96364 struct sock *sk = sock->sk;
96365 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
96366 struct l2cap_options opts;
96367 - int len, err = 0;
96368 + int err = 0;
96369 + size_t len = optlen;
96370 u32 opt;
96371
96372 BT_DBG("sk %p", sk);
96373 @@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96374 opts.max_tx = chan->max_tx;
96375 opts.txwin_size = chan->tx_win;
96376
96377 - len = min_t(unsigned int, sizeof(opts), optlen);
96378 + len = min(sizeof(opts), len);
96379 if (copy_from_user((char *) &opts, optval, len)) {
96380 err = -EFAULT;
96381 break;
96382 @@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96383 struct bt_security sec;
96384 struct bt_power pwr;
96385 struct l2cap_conn *conn;
96386 - int len, err = 0;
96387 + int err = 0;
96388 + size_t len = optlen;
96389 u32 opt;
96390
96391 BT_DBG("sk %p", sk);
96392 @@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96393
96394 sec.level = BT_SECURITY_LOW;
96395
96396 - len = min_t(unsigned int, sizeof(sec), optlen);
96397 + len = min(sizeof(sec), len);
96398 if (copy_from_user((char *) &sec, optval, len)) {
96399 err = -EFAULT;
96400 break;
96401 @@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96402
96403 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
96404
96405 - len = min_t(unsigned int, sizeof(pwr), optlen);
96406 + len = min(sizeof(pwr), len);
96407 if (copy_from_user((char *) &pwr, optval, len)) {
96408 err = -EFAULT;
96409 break;
96410 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
96411 index 3c2d3e4..884855a 100644
96412 --- a/net/bluetooth/rfcomm/sock.c
96413 +++ b/net/bluetooth/rfcomm/sock.c
96414 @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96415 struct sock *sk = sock->sk;
96416 struct bt_security sec;
96417 int err = 0;
96418 - size_t len;
96419 + size_t len = optlen;
96420 u32 opt;
96421
96422 BT_DBG("sk %p", sk);
96423 @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96424
96425 sec.level = BT_SECURITY_LOW;
96426
96427 - len = min_t(unsigned int, sizeof(sec), optlen);
96428 + len = min(sizeof(sec), len);
96429 if (copy_from_user((char *) &sec, optval, len)) {
96430 err = -EFAULT;
96431 break;
96432 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
96433 index f9c0980a..fcbbfeb 100644
96434 --- a/net/bluetooth/rfcomm/tty.c
96435 +++ b/net/bluetooth/rfcomm/tty.c
96436 @@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
96437 BT_DBG("tty %p id %d", tty, tty->index);
96438
96439 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
96440 - dev->channel, dev->port.count);
96441 + dev->channel, atomic_read(&dev->port.count));
96442
96443 err = tty_port_open(&dev->port, tty, filp);
96444 if (err)
96445 @@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
96446 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
96447
96448 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
96449 - dev->port.count);
96450 + atomic_read(&dev->port.count));
96451
96452 tty_port_close(&dev->port, tty, filp);
96453 }
96454 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
96455 index 0e474b1..fb7109c 100644
96456 --- a/net/bridge/netfilter/ebtables.c
96457 +++ b/net/bridge/netfilter/ebtables.c
96458 @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96459 tmp.valid_hooks = t->table->valid_hooks;
96460 }
96461 mutex_unlock(&ebt_mutex);
96462 - if (copy_to_user(user, &tmp, *len) != 0) {
96463 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96464 BUGPRINT("c2u Didn't work\n");
96465 ret = -EFAULT;
96466 break;
96467 @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96468 goto out;
96469 tmp.valid_hooks = t->valid_hooks;
96470
96471 - if (copy_to_user(user, &tmp, *len) != 0) {
96472 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96473 ret = -EFAULT;
96474 break;
96475 }
96476 @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96477 tmp.entries_size = t->table->entries_size;
96478 tmp.valid_hooks = t->table->valid_hooks;
96479
96480 - if (copy_to_user(user, &tmp, *len) != 0) {
96481 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96482 ret = -EFAULT;
96483 break;
96484 }
96485 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
96486 index 0f45522..dab651f 100644
96487 --- a/net/caif/cfctrl.c
96488 +++ b/net/caif/cfctrl.c
96489 @@ -10,6 +10,7 @@
96490 #include <linux/spinlock.h>
96491 #include <linux/slab.h>
96492 #include <linux/pkt_sched.h>
96493 +#include <linux/sched.h>
96494 #include <net/caif/caif_layer.h>
96495 #include <net/caif/cfpkt.h>
96496 #include <net/caif/cfctrl.h>
96497 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
96498 memset(&dev_info, 0, sizeof(dev_info));
96499 dev_info.id = 0xff;
96500 cfsrvl_init(&this->serv, 0, &dev_info, false);
96501 - atomic_set(&this->req_seq_no, 1);
96502 - atomic_set(&this->rsp_seq_no, 1);
96503 + atomic_set_unchecked(&this->req_seq_no, 1);
96504 + atomic_set_unchecked(&this->rsp_seq_no, 1);
96505 this->serv.layer.receive = cfctrl_recv;
96506 sprintf(this->serv.layer.name, "ctrl");
96507 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
96508 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
96509 struct cfctrl_request_info *req)
96510 {
96511 spin_lock_bh(&ctrl->info_list_lock);
96512 - atomic_inc(&ctrl->req_seq_no);
96513 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
96514 + atomic_inc_unchecked(&ctrl->req_seq_no);
96515 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
96516 list_add_tail(&req->list, &ctrl->list);
96517 spin_unlock_bh(&ctrl->info_list_lock);
96518 }
96519 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
96520 if (p != first)
96521 pr_warn("Requests are not received in order\n");
96522
96523 - atomic_set(&ctrl->rsp_seq_no,
96524 + atomic_set_unchecked(&ctrl->rsp_seq_no,
96525 p->sequence_no);
96526 list_del(&p->list);
96527 goto out;
96528 diff --git a/net/can/af_can.c b/net/can/af_can.c
96529 index a27f8aa..67174a3 100644
96530 --- a/net/can/af_can.c
96531 +++ b/net/can/af_can.c
96532 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
96533 };
96534
96535 /* notifier block for netdevice event */
96536 -static struct notifier_block can_netdev_notifier __read_mostly = {
96537 +static struct notifier_block can_netdev_notifier = {
96538 .notifier_call = can_notifier,
96539 };
96540
96541 diff --git a/net/can/gw.c b/net/can/gw.c
96542 index ac31891..4799c17 100644
96543 --- a/net/can/gw.c
96544 +++ b/net/can/gw.c
96545 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
96546 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
96547
96548 static HLIST_HEAD(cgw_list);
96549 -static struct notifier_block notifier;
96550
96551 static struct kmem_cache *cgw_cache __read_mostly;
96552
96553 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
96554 return err;
96555 }
96556
96557 +static struct notifier_block notifier = {
96558 + .notifier_call = cgw_notifier
96559 +};
96560 +
96561 static __init int cgw_module_init(void)
96562 {
96563 /* sanitize given module parameter */
96564 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
96565 return -ENOMEM;
96566
96567 /* set notifier */
96568 - notifier.notifier_call = cgw_notifier;
96569 register_netdevice_notifier(&notifier);
96570
96571 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
96572 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
96573 index 30efc5c..cfa1bbc 100644
96574 --- a/net/ceph/messenger.c
96575 +++ b/net/ceph/messenger.c
96576 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
96577 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
96578
96579 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
96580 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
96581 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
96582
96583 static struct page *zero_page; /* used in certain error cases */
96584
96585 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
96586 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
96587 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
96588
96589 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96590 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96591 s = addr_str[i];
96592
96593 switch (ss->ss_family) {
96594 diff --git a/net/compat.c b/net/compat.c
96595 index f50161f..94fa415 100644
96596 --- a/net/compat.c
96597 +++ b/net/compat.c
96598 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
96599 return -EFAULT;
96600 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
96601 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
96602 - kmsg->msg_name = compat_ptr(tmp1);
96603 - kmsg->msg_iov = compat_ptr(tmp2);
96604 - kmsg->msg_control = compat_ptr(tmp3);
96605 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
96606 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
96607 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
96608 return 0;
96609 }
96610
96611 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96612
96613 if (kern_msg->msg_namelen) {
96614 if (mode == VERIFY_READ) {
96615 - int err = move_addr_to_kernel(kern_msg->msg_name,
96616 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
96617 kern_msg->msg_namelen,
96618 kern_address);
96619 if (err < 0)
96620 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96621 kern_msg->msg_name = NULL;
96622
96623 tot_len = iov_from_user_compat_to_kern(kern_iov,
96624 - (struct compat_iovec __user *)kern_msg->msg_iov,
96625 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
96626 kern_msg->msg_iovlen);
96627 if (tot_len >= 0)
96628 kern_msg->msg_iov = kern_iov;
96629 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96630
96631 #define CMSG_COMPAT_FIRSTHDR(msg) \
96632 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
96633 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
96634 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
96635 (struct compat_cmsghdr __user *)NULL)
96636
96637 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
96638 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
96639 (ucmlen) <= (unsigned long) \
96640 ((mhdr)->msg_controllen - \
96641 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
96642 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
96643
96644 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
96645 struct compat_cmsghdr __user *cmsg, int cmsg_len)
96646 {
96647 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
96648 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
96649 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
96650 msg->msg_controllen)
96651 return NULL;
96652 return (struct compat_cmsghdr __user *)ptr;
96653 @@ -222,7 +222,7 @@ Efault:
96654
96655 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
96656 {
96657 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96658 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96659 struct compat_cmsghdr cmhdr;
96660 struct compat_timeval ctv;
96661 struct compat_timespec cts[3];
96662 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
96663
96664 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
96665 {
96666 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96667 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96668 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
96669 int fdnum = scm->fp->count;
96670 struct file **fp = scm->fp->fp;
96671 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
96672 return -EFAULT;
96673 old_fs = get_fs();
96674 set_fs(KERNEL_DS);
96675 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
96676 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
96677 set_fs(old_fs);
96678
96679 return err;
96680 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
96681 len = sizeof(ktime);
96682 old_fs = get_fs();
96683 set_fs(KERNEL_DS);
96684 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
96685 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
96686 set_fs(old_fs);
96687
96688 if (!err) {
96689 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96690 case MCAST_JOIN_GROUP:
96691 case MCAST_LEAVE_GROUP:
96692 {
96693 - struct compat_group_req __user *gr32 = (void *)optval;
96694 + struct compat_group_req __user *gr32 = (void __user *)optval;
96695 struct group_req __user *kgr =
96696 compat_alloc_user_space(sizeof(struct group_req));
96697 u32 interface;
96698 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96699 case MCAST_BLOCK_SOURCE:
96700 case MCAST_UNBLOCK_SOURCE:
96701 {
96702 - struct compat_group_source_req __user *gsr32 = (void *)optval;
96703 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
96704 struct group_source_req __user *kgsr = compat_alloc_user_space(
96705 sizeof(struct group_source_req));
96706 u32 interface;
96707 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96708 }
96709 case MCAST_MSFILTER:
96710 {
96711 - struct compat_group_filter __user *gf32 = (void *)optval;
96712 + struct compat_group_filter __user *gf32 = (void __user *)optval;
96713 struct group_filter __user *kgf;
96714 u32 interface, fmode, numsrc;
96715
96716 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
96717 char __user *optval, int __user *optlen,
96718 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
96719 {
96720 - struct compat_group_filter __user *gf32 = (void *)optval;
96721 + struct compat_group_filter __user *gf32 = (void __user *)optval;
96722 struct group_filter __user *kgf;
96723 int __user *koptlen;
96724 u32 interface, fmode, numsrc;
96725 @@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
96726
96727 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
96728 return -EINVAL;
96729 - if (copy_from_user(a, args, nas[call]))
96730 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
96731 return -EFAULT;
96732 a0 = a[0];
96733 a1 = a[1];
96734 diff --git a/net/core/datagram.c b/net/core/datagram.c
96735 index a16ed7b..eb44d17 100644
96736 --- a/net/core/datagram.c
96737 +++ b/net/core/datagram.c
96738 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
96739 }
96740
96741 kfree_skb(skb);
96742 - atomic_inc(&sk->sk_drops);
96743 + atomic_inc_unchecked(&sk->sk_drops);
96744 sk_mem_reclaim_partial(sk);
96745
96746 return err;
96747 diff --git a/net/core/dev.c b/net/core/dev.c
96748 index 45fa2f1..f3e28ec 100644
96749 --- a/net/core/dev.c
96750 +++ b/net/core/dev.c
96751 @@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
96752 {
96753 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
96754 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
96755 - atomic_long_inc(&dev->rx_dropped);
96756 + atomic_long_inc_unchecked(&dev->rx_dropped);
96757 kfree_skb(skb);
96758 return NET_RX_DROP;
96759 }
96760 }
96761
96762 if (unlikely(!is_skb_forwardable(dev, skb))) {
96763 - atomic_long_inc(&dev->rx_dropped);
96764 + atomic_long_inc_unchecked(&dev->rx_dropped);
96765 kfree_skb(skb);
96766 return NET_RX_DROP;
96767 }
96768 @@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
96769
96770 struct dev_gso_cb {
96771 void (*destructor)(struct sk_buff *skb);
96772 -};
96773 +} __no_const;
96774
96775 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
96776
96777 @@ -3227,7 +3227,7 @@ enqueue:
96778
96779 local_irq_restore(flags);
96780
96781 - atomic_long_inc(&skb->dev->rx_dropped);
96782 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96783 kfree_skb(skb);
96784 return NET_RX_DROP;
96785 }
96786 @@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
96787 }
96788 EXPORT_SYMBOL(netif_rx_ni);
96789
96790 -static void net_tx_action(struct softirq_action *h)
96791 +static __latent_entropy void net_tx_action(void)
96792 {
96793 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96794
96795 @@ -3645,7 +3645,7 @@ ncls:
96796 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
96797 } else {
96798 drop:
96799 - atomic_long_inc(&skb->dev->rx_dropped);
96800 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96801 kfree_skb(skb);
96802 /* Jamal, now you will not able to escape explaining
96803 * me how you were going to use this. :-)
96804 @@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
96805 }
96806 EXPORT_SYMBOL(netif_napi_del);
96807
96808 -static void net_rx_action(struct softirq_action *h)
96809 +static __latent_entropy void net_rx_action(void)
96810 {
96811 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96812 unsigned long time_limit = jiffies + 2;
96813 @@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
96814 } else {
96815 netdev_stats_to_stats64(storage, &dev->stats);
96816 }
96817 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
96818 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
96819 return storage;
96820 }
96821 EXPORT_SYMBOL(dev_get_stats);
96822 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
96823 index cf999e0..c59a975 100644
96824 --- a/net/core/dev_ioctl.c
96825 +++ b/net/core/dev_ioctl.c
96826 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
96827 if (no_module && capable(CAP_NET_ADMIN))
96828 no_module = request_module("netdev-%s", name);
96829 if (no_module && capable(CAP_SYS_MODULE)) {
96830 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
96831 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
96832 +#else
96833 if (!request_module("%s", name))
96834 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
96835 name);
96836 +#endif
96837 }
96838 }
96839 EXPORT_SYMBOL(dev_load);
96840 diff --git a/net/core/filter.c b/net/core/filter.c
96841 index ad30d62..21c0743 100644
96842 --- a/net/core/filter.c
96843 +++ b/net/core/filter.c
96844 @@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
96845 void *ptr;
96846 u32 A = 0; /* Accumulator */
96847 u32 X = 0; /* Index Register */
96848 - u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
96849 + u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
96850 u32 tmp;
96851 int k;
96852
96853 @@ -292,10 +292,10 @@ load_b:
96854 X = K;
96855 continue;
96856 case BPF_S_LD_MEM:
96857 - A = mem[K];
96858 + A = mem[K&15];
96859 continue;
96860 case BPF_S_LDX_MEM:
96861 - X = mem[K];
96862 + X = mem[K&15];
96863 continue;
96864 case BPF_S_MISC_TAX:
96865 X = A;
96866 @@ -308,10 +308,10 @@ load_b:
96867 case BPF_S_RET_A:
96868 return A;
96869 case BPF_S_ST:
96870 - mem[K] = A;
96871 + mem[K&15] = A;
96872 continue;
96873 case BPF_S_STX:
96874 - mem[K] = X;
96875 + mem[K&15] = X;
96876 continue;
96877 case BPF_S_ANC_PROTOCOL:
96878 A = ntohs(skb->protocol);
96879 @@ -355,6 +355,10 @@ load_b:
96880
96881 if (skb_is_nonlinear(skb))
96882 return 0;
96883 +
96884 + if (skb->len < sizeof(struct nlattr))
96885 + return 0;
96886 +
96887 if (A > skb->len - sizeof(struct nlattr))
96888 return 0;
96889
96890 @@ -371,11 +375,15 @@ load_b:
96891
96892 if (skb_is_nonlinear(skb))
96893 return 0;
96894 +
96895 + if (skb->len < sizeof(struct nlattr))
96896 + return 0;
96897 +
96898 if (A > skb->len - sizeof(struct nlattr))
96899 return 0;
96900
96901 nla = (struct nlattr *)&skb->data[A];
96902 - if (nla->nla_len > A - skb->len)
96903 + if (nla->nla_len > skb->len - A)
96904 return 0;
96905
96906 nla = nla_find_nested(nla, X);
96907 @@ -391,9 +399,10 @@ load_b:
96908 continue;
96909 #endif
96910 default:
96911 - WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
96912 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
96913 fentry->code, fentry->jt,
96914 fentry->jf, fentry->k);
96915 + BUG();
96916 return 0;
96917 }
96918 }
96919 @@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
96920 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
96921 int pc, ret = 0;
96922
96923 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
96924 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
96925 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
96926 if (!masks)
96927 return -ENOMEM;
96928 @@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
96929 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
96930 if (!fp)
96931 return -ENOMEM;
96932 - memcpy(fp->insns, fprog->filter, fsize);
96933 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
96934
96935 atomic_set(&fp->refcnt, 1);
96936 fp->len = fprog->len;
96937 diff --git a/net/core/flow.c b/net/core/flow.c
96938 index dfa602c..3103d88 100644
96939 --- a/net/core/flow.c
96940 +++ b/net/core/flow.c
96941 @@ -61,7 +61,7 @@ struct flow_cache {
96942 struct timer_list rnd_timer;
96943 };
96944
96945 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
96946 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
96947 EXPORT_SYMBOL(flow_cache_genid);
96948 static struct flow_cache flow_cache_global;
96949 static struct kmem_cache *flow_cachep __read_mostly;
96950 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
96951
96952 static int flow_entry_valid(struct flow_cache_entry *fle)
96953 {
96954 - if (atomic_read(&flow_cache_genid) != fle->genid)
96955 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
96956 return 0;
96957 if (fle->object && !fle->object->ops->check(fle->object))
96958 return 0;
96959 @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
96960 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
96961 fcp->hash_count++;
96962 }
96963 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
96964 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
96965 flo = fle->object;
96966 if (!flo)
96967 goto ret_object;
96968 @@ -279,7 +279,7 @@ nocache:
96969 }
96970 flo = resolver(net, key, family, dir, flo, ctx);
96971 if (fle) {
96972 - fle->genid = atomic_read(&flow_cache_genid);
96973 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
96974 if (!IS_ERR(flo))
96975 fle->object = flo;
96976 else
96977 diff --git a/net/core/iovec.c b/net/core/iovec.c
96978 index b618694..192bbba 100644
96979 --- a/net/core/iovec.c
96980 +++ b/net/core/iovec.c
96981 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
96982 if (m->msg_namelen) {
96983 if (mode == VERIFY_READ) {
96984 void __user *namep;
96985 - namep = (void __user __force *) m->msg_name;
96986 + namep = (void __force_user *) m->msg_name;
96987 err = move_addr_to_kernel(namep, m->msg_namelen,
96988 address);
96989 if (err < 0)
96990 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
96991 }
96992
96993 size = m->msg_iovlen * sizeof(struct iovec);
96994 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
96995 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
96996 return -EFAULT;
96997
96998 m->msg_iov = iov;
96999 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
97000 index e161290..8149aea 100644
97001 --- a/net/core/neighbour.c
97002 +++ b/net/core/neighbour.c
97003 @@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
97004 void __user *buffer, size_t *lenp, loff_t *ppos)
97005 {
97006 int size, ret;
97007 - struct ctl_table tmp = *ctl;
97008 + ctl_table_no_const tmp = *ctl;
97009
97010 tmp.extra1 = &zero;
97011 tmp.extra2 = &unres_qlen_max;
97012 @@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
97013 void __user *buffer,
97014 size_t *lenp, loff_t *ppos)
97015 {
97016 - struct ctl_table tmp = *ctl;
97017 + ctl_table_no_const tmp = *ctl;
97018 int ret;
97019
97020 tmp.extra1 = &zero;
97021 @@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
97022 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
97023 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
97024 } else {
97025 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
97026 dev_name_source = "default";
97027 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
97028 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
97029 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
97030 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
97031 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
97032 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
97033 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
97034 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
97035 }
97036
97037 if (handler) {
97038 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
97039 index 2bf8329..7960607 100644
97040 --- a/net/core/net-procfs.c
97041 +++ b/net/core/net-procfs.c
97042 @@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
97043 else
97044 seq_printf(seq, "%04x", ntohs(pt->type));
97045
97046 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97047 + seq_printf(seq, " %-8s %pf\n",
97048 + pt->dev ? pt->dev->name : "", NULL);
97049 +#else
97050 seq_printf(seq, " %-8s %pf\n",
97051 pt->dev ? pt->dev->name : "", pt->func);
97052 +#endif
97053 }
97054
97055 return 0;
97056 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
97057 index 81d3a9a..a0bd7a8 100644
97058 --- a/net/core/net_namespace.c
97059 +++ b/net/core/net_namespace.c
97060 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
97061 int error;
97062 LIST_HEAD(net_exit_list);
97063
97064 - list_add_tail(&ops->list, list);
97065 + pax_list_add_tail((struct list_head *)&ops->list, list);
97066 if (ops->init || (ops->id && ops->size)) {
97067 for_each_net(net) {
97068 error = ops_init(ops, net);
97069 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
97070
97071 out_undo:
97072 /* If I have an error cleanup all namespaces I initialized */
97073 - list_del(&ops->list);
97074 + pax_list_del((struct list_head *)&ops->list);
97075 ops_exit_list(ops, &net_exit_list);
97076 ops_free_list(ops, &net_exit_list);
97077 return error;
97078 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
97079 struct net *net;
97080 LIST_HEAD(net_exit_list);
97081
97082 - list_del(&ops->list);
97083 + pax_list_del((struct list_head *)&ops->list);
97084 for_each_net(net)
97085 list_add_tail(&net->exit_list, &net_exit_list);
97086 ops_exit_list(ops, &net_exit_list);
97087 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
97088 mutex_lock(&net_mutex);
97089 error = register_pernet_operations(&pernet_list, ops);
97090 if (!error && (first_device == &pernet_list))
97091 - first_device = &ops->list;
97092 + first_device = (struct list_head *)&ops->list;
97093 mutex_unlock(&net_mutex);
97094 return error;
97095 }
97096 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
97097 index df9e6b1..6e68e4e 100644
97098 --- a/net/core/netpoll.c
97099 +++ b/net/core/netpoll.c
97100 @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97101 struct udphdr *udph;
97102 struct iphdr *iph;
97103 struct ethhdr *eth;
97104 - static atomic_t ip_ident;
97105 + static atomic_unchecked_t ip_ident;
97106 struct ipv6hdr *ip6h;
97107
97108 udp_len = len + sizeof(*udph);
97109 @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97110 put_unaligned(0x45, (unsigned char *)iph);
97111 iph->tos = 0;
97112 put_unaligned(htons(ip_len), &(iph->tot_len));
97113 - iph->id = htons(atomic_inc_return(&ip_ident));
97114 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
97115 iph->frag_off = 0;
97116 iph->ttl = 64;
97117 iph->protocol = IPPROTO_UDP;
97118 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
97119 index 120eecc..cd1ec44 100644
97120 --- a/net/core/rtnetlink.c
97121 +++ b/net/core/rtnetlink.c
97122 @@ -58,7 +58,7 @@ struct rtnl_link {
97123 rtnl_doit_func doit;
97124 rtnl_dumpit_func dumpit;
97125 rtnl_calcit_func calcit;
97126 -};
97127 +} __no_const;
97128
97129 static DEFINE_MUTEX(rtnl_mutex);
97130
97131 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
97132 if (rtnl_link_ops_get(ops->kind))
97133 return -EEXIST;
97134
97135 - if (!ops->dellink)
97136 - ops->dellink = unregister_netdevice_queue;
97137 + if (!ops->dellink) {
97138 + pax_open_kernel();
97139 + *(void **)&ops->dellink = unregister_netdevice_queue;
97140 + pax_close_kernel();
97141 + }
97142
97143 - list_add_tail(&ops->list, &link_ops);
97144 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
97145 return 0;
97146 }
97147 EXPORT_SYMBOL_GPL(__rtnl_link_register);
97148 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
97149 for_each_net(net) {
97150 __rtnl_kill_links(net, ops);
97151 }
97152 - list_del(&ops->list);
97153 + pax_list_del((struct list_head *)&ops->list);
97154 }
97155 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
97156
97157 diff --git a/net/core/scm.c b/net/core/scm.c
97158 index b442e7e..6f5b5a2 100644
97159 --- a/net/core/scm.c
97160 +++ b/net/core/scm.c
97161 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97162 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97163 {
97164 struct cmsghdr __user *cm
97165 - = (__force struct cmsghdr __user *)msg->msg_control;
97166 + = (struct cmsghdr __force_user *)msg->msg_control;
97167 struct cmsghdr cmhdr;
97168 int cmlen = CMSG_LEN(len);
97169 int err;
97170 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97171 err = -EFAULT;
97172 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97173 goto out;
97174 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97175 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97176 goto out;
97177 cmlen = CMSG_SPACE(len);
97178 if (msg->msg_controllen < cmlen)
97179 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97180 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97181 {
97182 struct cmsghdr __user *cm
97183 - = (__force struct cmsghdr __user*)msg->msg_control;
97184 + = (struct cmsghdr __force_user *)msg->msg_control;
97185
97186 int fdmax = 0;
97187 int fdnum = scm->fp->count;
97188 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97189 if (fdnum < fdmax)
97190 fdmax = fdnum;
97191
97192 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97193 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97194 i++, cmfptr++)
97195 {
97196 struct socket *sock;
97197 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97198 index 90b96a1..cd18f16 100644
97199 --- a/net/core/skbuff.c
97200 +++ b/net/core/skbuff.c
97201 @@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
97202 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97203 int len, __wsum csum)
97204 {
97205 - const struct skb_checksum_ops ops = {
97206 + static const struct skb_checksum_ops ops = {
97207 .update = csum_partial_ext,
97208 .combine = csum_block_add_ext,
97209 };
97210 @@ -3220,13 +3220,15 @@ void __init skb_init(void)
97211 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97212 sizeof(struct sk_buff),
97213 0,
97214 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97215 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97216 + SLAB_NO_SANITIZE,
97217 NULL);
97218 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97219 (2*sizeof(struct sk_buff)) +
97220 sizeof(atomic_t),
97221 0,
97222 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97223 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97224 + SLAB_NO_SANITIZE,
97225 NULL);
97226 }
97227
97228 diff --git a/net/core/sock.c b/net/core/sock.c
97229 index c0fc6bd..51d8326 100644
97230 --- a/net/core/sock.c
97231 +++ b/net/core/sock.c
97232 @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97233 struct sk_buff_head *list = &sk->sk_receive_queue;
97234
97235 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
97236 - atomic_inc(&sk->sk_drops);
97237 + atomic_inc_unchecked(&sk->sk_drops);
97238 trace_sock_rcvqueue_full(sk, skb);
97239 return -ENOMEM;
97240 }
97241 @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97242 return err;
97243
97244 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
97245 - atomic_inc(&sk->sk_drops);
97246 + atomic_inc_unchecked(&sk->sk_drops);
97247 return -ENOBUFS;
97248 }
97249
97250 @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97251 skb_dst_force(skb);
97252
97253 spin_lock_irqsave(&list->lock, flags);
97254 - skb->dropcount = atomic_read(&sk->sk_drops);
97255 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
97256 __skb_queue_tail(list, skb);
97257 spin_unlock_irqrestore(&list->lock, flags);
97258
97259 @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97260 skb->dev = NULL;
97261
97262 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
97263 - atomic_inc(&sk->sk_drops);
97264 + atomic_inc_unchecked(&sk->sk_drops);
97265 goto discard_and_relse;
97266 }
97267 if (nested)
97268 @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97269 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
97270 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
97271 bh_unlock_sock(sk);
97272 - atomic_inc(&sk->sk_drops);
97273 + atomic_inc_unchecked(&sk->sk_drops);
97274 goto discard_and_relse;
97275 }
97276
97277 @@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97278 struct timeval tm;
97279 } v;
97280
97281 - int lv = sizeof(int);
97282 - int len;
97283 + unsigned int lv = sizeof(int);
97284 + unsigned int len;
97285
97286 if (get_user(len, optlen))
97287 return -EFAULT;
97288 - if (len < 0)
97289 + if (len > INT_MAX)
97290 return -EINVAL;
97291
97292 memset(&v, 0, sizeof(v));
97293 @@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97294
97295 case SO_PEERNAME:
97296 {
97297 - char address[128];
97298 + char address[_K_SS_MAXSIZE];
97299
97300 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
97301 return -ENOTCONN;
97302 - if (lv < len)
97303 + if (lv < len || sizeof address < len)
97304 return -EINVAL;
97305 if (copy_to_user(optval, address, len))
97306 return -EFAULT;
97307 @@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97308
97309 if (len > lv)
97310 len = lv;
97311 - if (copy_to_user(optval, &v, len))
97312 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
97313 return -EFAULT;
97314 lenout:
97315 if (put_user(len, optlen))
97316 @@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
97317 */
97318 smp_wmb();
97319 atomic_set(&sk->sk_refcnt, 1);
97320 - atomic_set(&sk->sk_drops, 0);
97321 + atomic_set_unchecked(&sk->sk_drops, 0);
97322 }
97323 EXPORT_SYMBOL(sock_init_data);
97324
97325 @@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
97326 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97327 int level, int type)
97328 {
97329 + struct sock_extended_err ee;
97330 struct sock_exterr_skb *serr;
97331 struct sk_buff *skb, *skb2;
97332 int copied, err;
97333 @@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97334 sock_recv_timestamp(msg, sk, skb);
97335
97336 serr = SKB_EXT_ERR(skb);
97337 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
97338 + ee = serr->ee;
97339 + put_cmsg(msg, level, type, sizeof ee, &ee);
97340
97341 msg->msg_flags |= MSG_ERRQUEUE;
97342 err = copied;
97343 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
97344 index a0e9cf6..ef7f9ed 100644
97345 --- a/net/core/sock_diag.c
97346 +++ b/net/core/sock_diag.c
97347 @@ -9,26 +9,33 @@
97348 #include <linux/inet_diag.h>
97349 #include <linux/sock_diag.h>
97350
97351 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
97352 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
97353 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
97354 static DEFINE_MUTEX(sock_diag_table_mutex);
97355
97356 int sock_diag_check_cookie(void *sk, __u32 *cookie)
97357 {
97358 +#ifndef CONFIG_GRKERNSEC_HIDESYM
97359 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
97360 cookie[1] != INET_DIAG_NOCOOKIE) &&
97361 ((u32)(unsigned long)sk != cookie[0] ||
97362 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
97363 return -ESTALE;
97364 else
97365 +#endif
97366 return 0;
97367 }
97368 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
97369
97370 void sock_diag_save_cookie(void *sk, __u32 *cookie)
97371 {
97372 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97373 + cookie[0] = 0;
97374 + cookie[1] = 0;
97375 +#else
97376 cookie[0] = (u32)(unsigned long)sk;
97377 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
97378 +#endif
97379 }
97380 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
97381
97382 @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
97383 mutex_lock(&sock_diag_table_mutex);
97384 if (sock_diag_handlers[hndl->family])
97385 err = -EBUSY;
97386 - else
97387 + else {
97388 + pax_open_kernel();
97389 sock_diag_handlers[hndl->family] = hndl;
97390 + pax_close_kernel();
97391 + }
97392 mutex_unlock(&sock_diag_table_mutex);
97393
97394 return err;
97395 @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
97396
97397 mutex_lock(&sock_diag_table_mutex);
97398 BUG_ON(sock_diag_handlers[family] != hnld);
97399 + pax_open_kernel();
97400 sock_diag_handlers[family] = NULL;
97401 + pax_close_kernel();
97402 mutex_unlock(&sock_diag_table_mutex);
97403 }
97404 EXPORT_SYMBOL_GPL(sock_diag_unregister);
97405 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
97406 index cf9cd13..8b56af3 100644
97407 --- a/net/core/sysctl_net_core.c
97408 +++ b/net/core/sysctl_net_core.c
97409 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
97410 {
97411 unsigned int orig_size, size;
97412 int ret, i;
97413 - struct ctl_table tmp = {
97414 + ctl_table_no_const tmp = {
97415 .data = &size,
97416 .maxlen = sizeof(size),
97417 .mode = table->mode
97418 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
97419 void __user *buffer, size_t *lenp, loff_t *ppos)
97420 {
97421 char id[IFNAMSIZ];
97422 - struct ctl_table tbl = {
97423 + ctl_table_no_const tbl = {
97424 .data = id,
97425 .maxlen = IFNAMSIZ,
97426 };
97427 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
97428
97429 static __net_init int sysctl_core_net_init(struct net *net)
97430 {
97431 - struct ctl_table *tbl;
97432 + ctl_table_no_const *tbl = NULL;
97433
97434 net->core.sysctl_somaxconn = SOMAXCONN;
97435
97436 - tbl = netns_core_table;
97437 if (!net_eq(net, &init_net)) {
97438 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
97439 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
97440 if (tbl == NULL)
97441 goto err_dup;
97442
97443 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
97444 if (net->user_ns != &init_user_ns) {
97445 tbl[0].procname = NULL;
97446 }
97447 - }
97448 -
97449 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97450 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97451 + } else
97452 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
97453 if (net->core.sysctl_hdr == NULL)
97454 goto err_reg;
97455
97456 return 0;
97457
97458 err_reg:
97459 - if (tbl != netns_core_table)
97460 - kfree(tbl);
97461 + kfree(tbl);
97462 err_dup:
97463 return -ENOMEM;
97464 }
97465 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
97466 kfree(tbl);
97467 }
97468
97469 -static __net_initdata struct pernet_operations sysctl_core_ops = {
97470 +static __net_initconst struct pernet_operations sysctl_core_ops = {
97471 .init = sysctl_core_net_init,
97472 .exit = sysctl_core_net_exit,
97473 };
97474 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
97475 index 4c04848..f575934 100644
97476 --- a/net/decnet/af_decnet.c
97477 +++ b/net/decnet/af_decnet.c
97478 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
97479 .sysctl_rmem = sysctl_decnet_rmem,
97480 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
97481 .obj_size = sizeof(struct dn_sock),
97482 + .slab_flags = SLAB_USERCOPY,
97483 };
97484
97485 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
97486 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
97487 index a603823..a36ee0b 100644
97488 --- a/net/decnet/dn_dev.c
97489 +++ b/net/decnet/dn_dev.c
97490 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
97491 .extra1 = &min_t3,
97492 .extra2 = &max_t3
97493 },
97494 - {0}
97495 + { }
97496 },
97497 };
97498
97499 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
97500 index 5325b54..a0d4d69 100644
97501 --- a/net/decnet/sysctl_net_decnet.c
97502 +++ b/net/decnet/sysctl_net_decnet.c
97503 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
97504
97505 if (len > *lenp) len = *lenp;
97506
97507 - if (copy_to_user(buffer, addr, len))
97508 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
97509 return -EFAULT;
97510
97511 *lenp = len;
97512 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
97513
97514 if (len > *lenp) len = *lenp;
97515
97516 - if (copy_to_user(buffer, devname, len))
97517 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
97518 return -EFAULT;
97519
97520 *lenp = len;
97521 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
97522 index 1846c1f..96d4a9f 100644
97523 --- a/net/ieee802154/dgram.c
97524 +++ b/net/ieee802154/dgram.c
97525 @@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
97526 if (saddr) {
97527 saddr->family = AF_IEEE802154;
97528 saddr->addr = mac_cb(skb)->sa;
97529 + }
97530 + if (addr_len)
97531 *addr_len = sizeof(*saddr);
97532 - }
97533
97534 if (flags & MSG_TRUNC)
97535 copied = skb->len;
97536 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
97537 index 19ab78a..bf575c9 100644
97538 --- a/net/ipv4/af_inet.c
97539 +++ b/net/ipv4/af_inet.c
97540 @@ -1703,13 +1703,9 @@ static int __init inet_init(void)
97541
97542 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
97543
97544 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
97545 - if (!sysctl_local_reserved_ports)
97546 - goto out;
97547 -
97548 rc = proto_register(&tcp_prot, 1);
97549 if (rc)
97550 - goto out_free_reserved_ports;
97551 + goto out;
97552
97553 rc = proto_register(&udp_prot, 1);
97554 if (rc)
97555 @@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
97556 proto_unregister(&udp_prot);
97557 out_unregister_tcp_proto:
97558 proto_unregister(&tcp_prot);
97559 -out_free_reserved_ports:
97560 - kfree(sysctl_local_reserved_ports);
97561 goto out;
97562 }
97563
97564 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
97565 index bdbf68b..deb4759 100644
97566 --- a/net/ipv4/devinet.c
97567 +++ b/net/ipv4/devinet.c
97568 @@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
97569 idx = 0;
97570 head = &net->dev_index_head[h];
97571 rcu_read_lock();
97572 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97573 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97574 net->dev_base_seq;
97575 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97576 if (idx < s_idx)
97577 @@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
97578 idx = 0;
97579 head = &net->dev_index_head[h];
97580 rcu_read_lock();
97581 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97582 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97583 net->dev_base_seq;
97584 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97585 if (idx < s_idx)
97586 @@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
97587 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
97588 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
97589
97590 -static struct devinet_sysctl_table {
97591 +static const struct devinet_sysctl_table {
97592 struct ctl_table_header *sysctl_header;
97593 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
97594 } devinet_sysctl = {
97595 @@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
97596 int err;
97597 struct ipv4_devconf *all, *dflt;
97598 #ifdef CONFIG_SYSCTL
97599 - struct ctl_table *tbl = ctl_forward_entry;
97600 + ctl_table_no_const *tbl = NULL;
97601 struct ctl_table_header *forw_hdr;
97602 #endif
97603
97604 @@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
97605 goto err_alloc_dflt;
97606
97607 #ifdef CONFIG_SYSCTL
97608 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
97609 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
97610 if (tbl == NULL)
97611 goto err_alloc_ctl;
97612
97613 @@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
97614 goto err_reg_dflt;
97615
97616 err = -ENOMEM;
97617 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97618 + if (!net_eq(net, &init_net))
97619 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97620 + else
97621 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
97622 if (forw_hdr == NULL)
97623 goto err_reg_ctl;
97624 net->ipv4.forw_hdr = forw_hdr;
97625 @@ -2272,8 +2275,7 @@ err_reg_ctl:
97626 err_reg_dflt:
97627 __devinet_sysctl_unregister(all);
97628 err_reg_all:
97629 - if (tbl != ctl_forward_entry)
97630 - kfree(tbl);
97631 + kfree(tbl);
97632 err_alloc_ctl:
97633 #endif
97634 if (dflt != &ipv4_devconf_dflt)
97635 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
97636 index c7539e2..b455e51 100644
97637 --- a/net/ipv4/fib_frontend.c
97638 +++ b/net/ipv4/fib_frontend.c
97639 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
97640 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97641 fib_sync_up(dev);
97642 #endif
97643 - atomic_inc(&net->ipv4.dev_addr_genid);
97644 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97645 rt_cache_flush(dev_net(dev));
97646 break;
97647 case NETDEV_DOWN:
97648 fib_del_ifaddr(ifa, NULL);
97649 - atomic_inc(&net->ipv4.dev_addr_genid);
97650 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97651 if (ifa->ifa_dev->ifa_list == NULL) {
97652 /* Last address was deleted from this interface.
97653 * Disable IP.
97654 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
97655 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97656 fib_sync_up(dev);
97657 #endif
97658 - atomic_inc(&net->ipv4.dev_addr_genid);
97659 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97660 rt_cache_flush(net);
97661 break;
97662 case NETDEV_DOWN:
97663 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
97664 index b53f0bf..3585b33 100644
97665 --- a/net/ipv4/fib_semantics.c
97666 +++ b/net/ipv4/fib_semantics.c
97667 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
97668 nh->nh_saddr = inet_select_addr(nh->nh_dev,
97669 nh->nh_gw,
97670 nh->nh_parent->fib_scope);
97671 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
97672 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
97673
97674 return nh->nh_saddr;
97675 }
97676 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
97677 index 0d1e2cb..4501a2c 100644
97678 --- a/net/ipv4/inet_connection_sock.c
97679 +++ b/net/ipv4/inet_connection_sock.c
97680 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
97681 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
97682 #endif
97683
97684 -unsigned long *sysctl_local_reserved_ports;
97685 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
97686 EXPORT_SYMBOL(sysctl_local_reserved_ports);
97687
97688 void inet_get_local_port_range(struct net *net, int *low, int *high)
97689 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
97690 index 8b9cf27..0d8d592 100644
97691 --- a/net/ipv4/inet_hashtables.c
97692 +++ b/net/ipv4/inet_hashtables.c
97693 @@ -18,6 +18,7 @@
97694 #include <linux/sched.h>
97695 #include <linux/slab.h>
97696 #include <linux/wait.h>
97697 +#include <linux/security.h>
97698
97699 #include <net/inet_connection_sock.h>
97700 #include <net/inet_hashtables.h>
97701 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
97702 return inet_ehashfn(net, laddr, lport, faddr, fport);
97703 }
97704
97705 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
97706 +
97707 /*
97708 * Allocate and initialize a new local port bind bucket.
97709 * The bindhash mutex for snum's hash chain must be held here.
97710 @@ -554,6 +557,8 @@ ok:
97711 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
97712 spin_unlock(&head->lock);
97713
97714 + gr_update_task_in_ip_table(current, inet_sk(sk));
97715 +
97716 if (tw) {
97717 inet_twsk_deschedule(tw, death_row);
97718 while (twrefcnt) {
97719 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
97720 index 48f4244..f56d83a 100644
97721 --- a/net/ipv4/inetpeer.c
97722 +++ b/net/ipv4/inetpeer.c
97723 @@ -496,8 +496,8 @@ relookup:
97724 if (p) {
97725 p->daddr = *daddr;
97726 atomic_set(&p->refcnt, 1);
97727 - atomic_set(&p->rid, 0);
97728 - atomic_set(&p->ip_id_count,
97729 + atomic_set_unchecked(&p->rid, 0);
97730 + atomic_set_unchecked(&p->ip_id_count,
97731 (daddr->family == AF_INET) ?
97732 secure_ip_id(daddr->addr.a4) :
97733 secure_ipv6_id(daddr->addr.a6));
97734 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
97735 index c10a3ce..dd71f84 100644
97736 --- a/net/ipv4/ip_fragment.c
97737 +++ b/net/ipv4/ip_fragment.c
97738 @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
97739 return 0;
97740
97741 start = qp->rid;
97742 - end = atomic_inc_return(&peer->rid);
97743 + end = atomic_inc_return_unchecked(&peer->rid);
97744 qp->rid = end;
97745
97746 rc = qp->q.fragments && (end - start) > max;
97747 @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
97748
97749 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97750 {
97751 - struct ctl_table *table;
97752 + ctl_table_no_const *table = NULL;
97753 struct ctl_table_header *hdr;
97754
97755 - table = ip4_frags_ns_ctl_table;
97756 if (!net_eq(net, &init_net)) {
97757 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97758 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97759 if (table == NULL)
97760 goto err_alloc;
97761
97762 @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97763 /* Don't export sysctls to unprivileged users */
97764 if (net->user_ns != &init_user_ns)
97765 table[0].procname = NULL;
97766 - }
97767 + hdr = register_net_sysctl(net, "net/ipv4", table);
97768 + } else
97769 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
97770
97771 - hdr = register_net_sysctl(net, "net/ipv4", table);
97772 if (hdr == NULL)
97773 goto err_reg;
97774
97775 @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97776 return 0;
97777
97778 err_reg:
97779 - if (!net_eq(net, &init_net))
97780 - kfree(table);
97781 + kfree(table);
97782 err_alloc:
97783 return -ENOMEM;
97784 }
97785 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
97786 index ec4f762..4ce3645 100644
97787 --- a/net/ipv4/ip_gre.c
97788 +++ b/net/ipv4/ip_gre.c
97789 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
97790 module_param(log_ecn_error, bool, 0644);
97791 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97792
97793 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
97794 +static struct rtnl_link_ops ipgre_link_ops;
97795 static int ipgre_tunnel_init(struct net_device *dev);
97796
97797 static int ipgre_net_id __read_mostly;
97798 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
97799 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
97800 };
97801
97802 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97803 +static struct rtnl_link_ops ipgre_link_ops = {
97804 .kind = "gre",
97805 .maxtype = IFLA_GRE_MAX,
97806 .policy = ipgre_policy,
97807 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97808 .fill_info = ipgre_fill_info,
97809 };
97810
97811 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
97812 +static struct rtnl_link_ops ipgre_tap_ops = {
97813 .kind = "gretap",
97814 .maxtype = IFLA_GRE_MAX,
97815 .policy = ipgre_policy,
97816 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
97817 index 580dd96..9fcef7e 100644
97818 --- a/net/ipv4/ip_sockglue.c
97819 +++ b/net/ipv4/ip_sockglue.c
97820 @@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97821 len = min_t(unsigned int, len, opt->optlen);
97822 if (put_user(len, optlen))
97823 return -EFAULT;
97824 - if (copy_to_user(optval, opt->__data, len))
97825 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
97826 + copy_to_user(optval, opt->__data, len))
97827 return -EFAULT;
97828 return 0;
97829 }
97830 @@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97831 if (sk->sk_type != SOCK_STREAM)
97832 return -ENOPROTOOPT;
97833
97834 - msg.msg_control = optval;
97835 + msg.msg_control = (void __force_kernel *)optval;
97836 msg.msg_controllen = len;
97837 msg.msg_flags = flags;
97838
97839 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
97840 index 48eafae..defff53 100644
97841 --- a/net/ipv4/ip_vti.c
97842 +++ b/net/ipv4/ip_vti.c
97843 @@ -44,7 +44,7 @@
97844 #include <net/net_namespace.h>
97845 #include <net/netns/generic.h>
97846
97847 -static struct rtnl_link_ops vti_link_ops __read_mostly;
97848 +static struct rtnl_link_ops vti_link_ops;
97849
97850 static int vti_net_id __read_mostly;
97851 static int vti_tunnel_init(struct net_device *dev);
97852 @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
97853 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
97854 };
97855
97856 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
97857 +static struct rtnl_link_ops vti_link_ops = {
97858 .kind = "vti",
97859 .maxtype = IFLA_VTI_MAX,
97860 .policy = vti_policy,
97861 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
97862 index b3e86ea..18ce98c 100644
97863 --- a/net/ipv4/ipconfig.c
97864 +++ b/net/ipv4/ipconfig.c
97865 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
97866
97867 mm_segment_t oldfs = get_fs();
97868 set_fs(get_ds());
97869 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97870 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97871 set_fs(oldfs);
97872 return res;
97873 }
97874 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
97875
97876 mm_segment_t oldfs = get_fs();
97877 set_fs(get_ds());
97878 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97879 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97880 set_fs(oldfs);
97881 return res;
97882 }
97883 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
97884
97885 mm_segment_t oldfs = get_fs();
97886 set_fs(get_ds());
97887 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
97888 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
97889 set_fs(oldfs);
97890 return res;
97891 }
97892 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
97893 index 812b183..56cbe9c 100644
97894 --- a/net/ipv4/ipip.c
97895 +++ b/net/ipv4/ipip.c
97896 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97897 static int ipip_net_id __read_mostly;
97898
97899 static int ipip_tunnel_init(struct net_device *dev);
97900 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
97901 +static struct rtnl_link_ops ipip_link_ops;
97902
97903 static int ipip_err(struct sk_buff *skb, u32 info)
97904 {
97905 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
97906 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
97907 };
97908
97909 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
97910 +static struct rtnl_link_ops ipip_link_ops = {
97911 .kind = "ipip",
97912 .maxtype = IFLA_IPTUN_MAX,
97913 .policy = ipip_policy,
97914 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
97915 index 59da7cd..e318de1 100644
97916 --- a/net/ipv4/netfilter/arp_tables.c
97917 +++ b/net/ipv4/netfilter/arp_tables.c
97918 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
97919 #endif
97920
97921 static int get_info(struct net *net, void __user *user,
97922 - const int *len, int compat)
97923 + int len, int compat)
97924 {
97925 char name[XT_TABLE_MAXNAMELEN];
97926 struct xt_table *t;
97927 int ret;
97928
97929 - if (*len != sizeof(struct arpt_getinfo)) {
97930 - duprintf("length %u != %Zu\n", *len,
97931 + if (len != sizeof(struct arpt_getinfo)) {
97932 + duprintf("length %u != %Zu\n", len,
97933 sizeof(struct arpt_getinfo));
97934 return -EINVAL;
97935 }
97936 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
97937 info.size = private->size;
97938 strcpy(info.name, name);
97939
97940 - if (copy_to_user(user, &info, *len) != 0)
97941 + if (copy_to_user(user, &info, len) != 0)
97942 ret = -EFAULT;
97943 else
97944 ret = 0;
97945 @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
97946
97947 switch (cmd) {
97948 case ARPT_SO_GET_INFO:
97949 - ret = get_info(sock_net(sk), user, len, 1);
97950 + ret = get_info(sock_net(sk), user, *len, 1);
97951 break;
97952 case ARPT_SO_GET_ENTRIES:
97953 ret = compat_get_entries(sock_net(sk), user, len);
97954 @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
97955
97956 switch (cmd) {
97957 case ARPT_SO_GET_INFO:
97958 - ret = get_info(sock_net(sk), user, len, 0);
97959 + ret = get_info(sock_net(sk), user, *len, 0);
97960 break;
97961
97962 case ARPT_SO_GET_ENTRIES:
97963 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
97964 index 718dfbd..cef4152 100644
97965 --- a/net/ipv4/netfilter/ip_tables.c
97966 +++ b/net/ipv4/netfilter/ip_tables.c
97967 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
97968 #endif
97969
97970 static int get_info(struct net *net, void __user *user,
97971 - const int *len, int compat)
97972 + int len, int compat)
97973 {
97974 char name[XT_TABLE_MAXNAMELEN];
97975 struct xt_table *t;
97976 int ret;
97977
97978 - if (*len != sizeof(struct ipt_getinfo)) {
97979 - duprintf("length %u != %zu\n", *len,
97980 + if (len != sizeof(struct ipt_getinfo)) {
97981 + duprintf("length %u != %zu\n", len,
97982 sizeof(struct ipt_getinfo));
97983 return -EINVAL;
97984 }
97985 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
97986 info.size = private->size;
97987 strcpy(info.name, name);
97988
97989 - if (copy_to_user(user, &info, *len) != 0)
97990 + if (copy_to_user(user, &info, len) != 0)
97991 ret = -EFAULT;
97992 else
97993 ret = 0;
97994 @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97995
97996 switch (cmd) {
97997 case IPT_SO_GET_INFO:
97998 - ret = get_info(sock_net(sk), user, len, 1);
97999 + ret = get_info(sock_net(sk), user, *len, 1);
98000 break;
98001 case IPT_SO_GET_ENTRIES:
98002 ret = compat_get_entries(sock_net(sk), user, len);
98003 @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98004
98005 switch (cmd) {
98006 case IPT_SO_GET_INFO:
98007 - ret = get_info(sock_net(sk), user, len, 0);
98008 + ret = get_info(sock_net(sk), user, *len, 0);
98009 break;
98010
98011 case IPT_SO_GET_ENTRIES:
98012 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
98013 index 2d11c09..3f153f8 100644
98014 --- a/net/ipv4/ping.c
98015 +++ b/net/ipv4/ping.c
98016 @@ -59,7 +59,7 @@ struct ping_table {
98017 };
98018
98019 static struct ping_table ping_table;
98020 -struct pingv6_ops pingv6_ops;
98021 +struct pingv6_ops *pingv6_ops;
98022 EXPORT_SYMBOL_GPL(pingv6_ops);
98023
98024 static u16 ping_port_rover;
98025 @@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
98026 struct group_info *group_info = get_current_groups();
98027 int i, j, count = group_info->ngroups;
98028 kgid_t low, high;
98029 + int ret = 0;
98030
98031 inet_get_ping_group_range_net(net, &low, &high);
98032 if (gid_lte(low, group) && gid_lte(group, high))
98033 - return 0;
98034 + goto out_release_group;
98035
98036 for (i = 0; i < group_info->nblocks; i++) {
98037 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
98038 for (j = 0; j < cp_count; j++) {
98039 kgid_t gid = group_info->blocks[i][j];
98040 if (gid_lte(low, gid) && gid_lte(gid, high))
98041 - return 0;
98042 + goto out_release_group;
98043 }
98044
98045 count -= cp_count;
98046 }
98047
98048 - return -EACCES;
98049 + ret = -EACCES;
98050 +
98051 +out_release_group:
98052 + put_group_info(group_info);
98053 + return ret;
98054 }
98055 EXPORT_SYMBOL_GPL(ping_init_sock);
98056
98057 @@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
98058 return -ENODEV;
98059 }
98060 }
98061 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
98062 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
98063 scoped);
98064 rcu_read_unlock();
98065
98066 @@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98067 }
98068 #if IS_ENABLED(CONFIG_IPV6)
98069 } else if (skb->protocol == htons(ETH_P_IPV6)) {
98070 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
98071 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
98072 #endif
98073 }
98074
98075 @@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98076 info, (u8 *)icmph);
98077 #if IS_ENABLED(CONFIG_IPV6)
98078 } else if (family == AF_INET6) {
98079 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
98080 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
98081 info, (u8 *)icmph);
98082 #endif
98083 }
98084 @@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98085 {
98086 struct inet_sock *isk = inet_sk(sk);
98087 int family = sk->sk_family;
98088 + struct sockaddr_in *sin;
98089 + struct sockaddr_in6 *sin6;
98090 struct sk_buff *skb;
98091 int copied, err;
98092
98093 @@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98094 if (flags & MSG_OOB)
98095 goto out;
98096
98097 + if (addr_len) {
98098 + if (family == AF_INET)
98099 + *addr_len = sizeof(*sin);
98100 + else if (family == AF_INET6 && addr_len)
98101 + *addr_len = sizeof(*sin6);
98102 + }
98103 +
98104 if (flags & MSG_ERRQUEUE) {
98105 if (family == AF_INET) {
98106 return ip_recv_error(sk, msg, len, addr_len);
98107 #if IS_ENABLED(CONFIG_IPV6)
98108 } else if (family == AF_INET6) {
98109 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
98110 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
98111 addr_len);
98112 #endif
98113 }
98114 @@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98115 sin->sin_port = 0 /* skb->h.uh->source */;
98116 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98117 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98118 - *addr_len = sizeof(*sin);
98119 }
98120
98121 if (isk->cmsg_flags)
98122 @@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98123 sin6->sin6_scope_id =
98124 ipv6_iface_scope_id(&sin6->sin6_addr,
98125 IP6CB(skb)->iif);
98126 - *addr_len = sizeof(*sin6);
98127 }
98128
98129 if (inet6_sk(sk)->rxopt.all)
98130 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
98131 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
98132 if (skb->protocol == htons(ETH_P_IPV6) &&
98133 inet6_sk(sk)->rxopt.all)
98134 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
98135 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
98136 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
98137 ip_cmsg_recv(msg, skb);
98138 #endif
98139 @@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
98140 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98141 0, sock_i_ino(sp),
98142 atomic_read(&sp->sk_refcnt), sp,
98143 - atomic_read(&sp->sk_drops));
98144 + atomic_read_unchecked(&sp->sk_drops));
98145 }
98146
98147 static int ping_v4_seq_show(struct seq_file *seq, void *v)
98148 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
98149 index c04518f..824ebe5 100644
98150 --- a/net/ipv4/raw.c
98151 +++ b/net/ipv4/raw.c
98152 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
98153 int raw_rcv(struct sock *sk, struct sk_buff *skb)
98154 {
98155 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
98156 - atomic_inc(&sk->sk_drops);
98157 + atomic_inc_unchecked(&sk->sk_drops);
98158 kfree_skb(skb);
98159 return NET_RX_DROP;
98160 }
98161 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98162 if (flags & MSG_OOB)
98163 goto out;
98164
98165 + if (addr_len)
98166 + *addr_len = sizeof(*sin);
98167 +
98168 if (flags & MSG_ERRQUEUE) {
98169 err = ip_recv_error(sk, msg, len, addr_len);
98170 goto out;
98171 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98172 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98173 sin->sin_port = 0;
98174 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98175 - *addr_len = sizeof(*sin);
98176 }
98177 if (inet->cmsg_flags)
98178 ip_cmsg_recv(msg, skb);
98179 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98180
98181 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98182 {
98183 + struct icmp_filter filter;
98184 +
98185 if (optlen > sizeof(struct icmp_filter))
98186 optlen = sizeof(struct icmp_filter);
98187 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98188 + if (copy_from_user(&filter, optval, optlen))
98189 return -EFAULT;
98190 + raw_sk(sk)->filter = filter;
98191 return 0;
98192 }
98193
98194 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98195 {
98196 int len, ret = -EFAULT;
98197 + struct icmp_filter filter;
98198
98199 if (get_user(len, optlen))
98200 goto out;
98201 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98202 if (len > sizeof(struct icmp_filter))
98203 len = sizeof(struct icmp_filter);
98204 ret = -EFAULT;
98205 - if (put_user(len, optlen) ||
98206 - copy_to_user(optval, &raw_sk(sk)->filter, len))
98207 + filter = raw_sk(sk)->filter;
98208 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98209 goto out;
98210 ret = 0;
98211 out: return ret;
98212 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
98213 0, 0L, 0,
98214 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
98215 0, sock_i_ino(sp),
98216 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
98217 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
98218 }
98219
98220 static int raw_seq_show(struct seq_file *seq, void *v)
98221 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
98222 index 4c011ec..5cdfedb 100644
98223 --- a/net/ipv4/route.c
98224 +++ b/net/ipv4/route.c
98225 @@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
98226 .maxlen = sizeof(int),
98227 .mode = 0200,
98228 .proc_handler = ipv4_sysctl_rtcache_flush,
98229 + .extra1 = &init_net,
98230 },
98231 { },
98232 };
98233
98234 static __net_init int sysctl_route_net_init(struct net *net)
98235 {
98236 - struct ctl_table *tbl;
98237 + ctl_table_no_const *tbl = NULL;
98238
98239 - tbl = ipv4_route_flush_table;
98240 if (!net_eq(net, &init_net)) {
98241 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98242 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98243 if (tbl == NULL)
98244 goto err_dup;
98245
98246 /* Don't export sysctls to unprivileged users */
98247 if (net->user_ns != &init_user_ns)
98248 tbl[0].procname = NULL;
98249 - }
98250 - tbl[0].extra1 = net;
98251 + tbl[0].extra1 = net;
98252 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98253 + } else
98254 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
98255
98256 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98257 if (net->ipv4.route_hdr == NULL)
98258 goto err_reg;
98259 return 0;
98260
98261 err_reg:
98262 - if (tbl != ipv4_route_flush_table)
98263 - kfree(tbl);
98264 + kfree(tbl);
98265 err_dup:
98266 return -ENOMEM;
98267 }
98268 @@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
98269
98270 static __net_init int rt_genid_init(struct net *net)
98271 {
98272 - atomic_set(&net->ipv4.rt_genid, 0);
98273 - atomic_set(&net->fnhe_genid, 0);
98274 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
98275 + atomic_set_unchecked(&net->fnhe_genid, 0);
98276 get_random_bytes(&net->ipv4.dev_addr_genid,
98277 sizeof(net->ipv4.dev_addr_genid));
98278 return 0;
98279 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
98280 index 44eba05..b36864b 100644
98281 --- a/net/ipv4/sysctl_net_ipv4.c
98282 +++ b/net/ipv4/sysctl_net_ipv4.c
98283 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
98284 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
98285 int ret;
98286 int range[2];
98287 - struct ctl_table tmp = {
98288 + ctl_table_no_const tmp = {
98289 .data = &range,
98290 .maxlen = sizeof(range),
98291 .mode = table->mode,
98292 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
98293 int ret;
98294 gid_t urange[2];
98295 kgid_t low, high;
98296 - struct ctl_table tmp = {
98297 + ctl_table_no_const tmp = {
98298 .data = &urange,
98299 .maxlen = sizeof(urange),
98300 .mode = table->mode,
98301 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
98302 void __user *buffer, size_t *lenp, loff_t *ppos)
98303 {
98304 char val[TCP_CA_NAME_MAX];
98305 - struct ctl_table tbl = {
98306 + ctl_table_no_const tbl = {
98307 .data = val,
98308 .maxlen = TCP_CA_NAME_MAX,
98309 };
98310 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
98311 void __user *buffer, size_t *lenp,
98312 loff_t *ppos)
98313 {
98314 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
98315 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
98316 int ret;
98317
98318 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98319 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
98320 void __user *buffer, size_t *lenp,
98321 loff_t *ppos)
98322 {
98323 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
98324 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
98325 int ret;
98326
98327 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98328 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
98329 void __user *buffer, size_t *lenp,
98330 loff_t *ppos)
98331 {
98332 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98333 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98334 struct tcp_fastopen_context *ctxt;
98335 int ret;
98336 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
98337 @@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
98338 },
98339 {
98340 .procname = "ip_local_reserved_ports",
98341 - .data = NULL, /* initialized in sysctl_ipv4_init */
98342 + .data = sysctl_local_reserved_ports,
98343 .maxlen = 65536,
98344 .mode = 0644,
98345 .proc_handler = proc_do_large_bitmap,
98346 @@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
98347
98348 static __net_init int ipv4_sysctl_init_net(struct net *net)
98349 {
98350 - struct ctl_table *table;
98351 + ctl_table_no_const *table = NULL;
98352
98353 - table = ipv4_net_table;
98354 if (!net_eq(net, &init_net)) {
98355 int i;
98356
98357 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
98358 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
98359 if (table == NULL)
98360 goto err_alloc;
98361
98362 @@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
98363 net->ipv4.sysctl_local_ports.range[0] = 32768;
98364 net->ipv4.sysctl_local_ports.range[1] = 61000;
98365
98366 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98367 + if (!net_eq(net, &init_net))
98368 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98369 + else
98370 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
98371 if (net->ipv4.ipv4_hdr == NULL)
98372 goto err_reg;
98373
98374 return 0;
98375
98376 err_reg:
98377 - if (!net_eq(net, &init_net))
98378 - kfree(table);
98379 + kfree(table);
98380 err_alloc:
98381 return -ENOMEM;
98382 }
98383 @@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
98384 static __init int sysctl_ipv4_init(void)
98385 {
98386 struct ctl_table_header *hdr;
98387 - struct ctl_table *i;
98388 -
98389 - for (i = ipv4_table; i->procname; i++) {
98390 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
98391 - i->data = sysctl_local_reserved_ports;
98392 - break;
98393 - }
98394 - }
98395 - if (!i->procname)
98396 - return -EINVAL;
98397
98398 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
98399 if (hdr == NULL)
98400 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
98401 index eeaac39..dc29942 100644
98402 --- a/net/ipv4/tcp_input.c
98403 +++ b/net/ipv4/tcp_input.c
98404 @@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
98405 * without any lock. We want to make sure compiler wont store
98406 * intermediate values in this location.
98407 */
98408 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
98409 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
98410 sk->sk_max_pacing_rate);
98411 }
98412
98413 @@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
98414 * simplifies code)
98415 */
98416 static void
98417 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98418 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98419 struct sk_buff *head, struct sk_buff *tail,
98420 u32 start, u32 end)
98421 {
98422 @@ -5562,6 +5562,7 @@ discard:
98423 tcp_paws_reject(&tp->rx_opt, 0))
98424 goto discard_and_undo;
98425
98426 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
98427 if (th->syn) {
98428 /* We see SYN without ACK. It is attempt of
98429 * simultaneous connect with crossed SYNs.
98430 @@ -5612,6 +5613,7 @@ discard:
98431 goto discard;
98432 #endif
98433 }
98434 +#endif
98435 /* "fifth, if neither of the SYN or RST bits is set then
98436 * drop the segment and return."
98437 */
98438 @@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
98439 goto discard;
98440
98441 if (th->syn) {
98442 - if (th->fin)
98443 + if (th->fin || th->urg || th->psh)
98444 goto discard;
98445 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
98446 return 1;
98447 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
98448 index 1e4eac7..a66fa4a 100644
98449 --- a/net/ipv4/tcp_ipv4.c
98450 +++ b/net/ipv4/tcp_ipv4.c
98451 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
98452 EXPORT_SYMBOL(sysctl_tcp_low_latency);
98453
98454
98455 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98456 +extern int grsec_enable_blackhole;
98457 +#endif
98458 +
98459 #ifdef CONFIG_TCP_MD5SIG
98460 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
98461 __be32 daddr, __be32 saddr, const struct tcphdr *th);
98462 @@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
98463 return 0;
98464
98465 reset:
98466 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98467 + if (!grsec_enable_blackhole)
98468 +#endif
98469 tcp_v4_send_reset(rsk, skb);
98470 discard:
98471 kfree_skb(skb);
98472 @@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
98473 TCP_SKB_CB(skb)->sacked = 0;
98474
98475 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98476 - if (!sk)
98477 + if (!sk) {
98478 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98479 + ret = 1;
98480 +#endif
98481 goto no_tcp_socket;
98482 -
98483 + }
98484 process:
98485 - if (sk->sk_state == TCP_TIME_WAIT)
98486 + if (sk->sk_state == TCP_TIME_WAIT) {
98487 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98488 + ret = 2;
98489 +#endif
98490 goto do_time_wait;
98491 + }
98492
98493 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
98494 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98495 @@ -2033,6 +2047,10 @@ csum_error:
98496 bad_packet:
98497 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98498 } else {
98499 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98500 + if (!grsec_enable_blackhole || (ret == 1 &&
98501 + (skb->dev->flags & IFF_LOOPBACK)))
98502 +#endif
98503 tcp_v4_send_reset(NULL, skb);
98504 }
98505
98506 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
98507 index 7a436c5..1b05c59 100644
98508 --- a/net/ipv4/tcp_minisocks.c
98509 +++ b/net/ipv4/tcp_minisocks.c
98510 @@ -27,6 +27,10 @@
98511 #include <net/inet_common.h>
98512 #include <net/xfrm.h>
98513
98514 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98515 +extern int grsec_enable_blackhole;
98516 +#endif
98517 +
98518 int sysctl_tcp_syncookies __read_mostly = 1;
98519 EXPORT_SYMBOL(sysctl_tcp_syncookies);
98520
98521 @@ -709,7 +713,10 @@ embryonic_reset:
98522 * avoid becoming vulnerable to outside attack aiming at
98523 * resetting legit local connections.
98524 */
98525 - req->rsk_ops->send_reset(sk, skb);
98526 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98527 + if (!grsec_enable_blackhole)
98528 +#endif
98529 + req->rsk_ops->send_reset(sk, skb);
98530 } else if (fastopen) { /* received a valid RST pkt */
98531 reqsk_fastopen_remove(sk, req, true);
98532 tcp_reset(sk);
98533 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
98534 index 1f2d376..01d18c4 100644
98535 --- a/net/ipv4/tcp_probe.c
98536 +++ b/net/ipv4/tcp_probe.c
98537 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
98538 if (cnt + width >= len)
98539 break;
98540
98541 - if (copy_to_user(buf + cnt, tbuf, width))
98542 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
98543 return -EFAULT;
98544 cnt += width;
98545 }
98546 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
98547 index 64f0354..a81b39d 100644
98548 --- a/net/ipv4/tcp_timer.c
98549 +++ b/net/ipv4/tcp_timer.c
98550 @@ -22,6 +22,10 @@
98551 #include <linux/gfp.h>
98552 #include <net/tcp.h>
98553
98554 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98555 +extern int grsec_lastack_retries;
98556 +#endif
98557 +
98558 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
98559 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
98560 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
98561 @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
98562 }
98563 }
98564
98565 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98566 + if ((sk->sk_state == TCP_LAST_ACK) &&
98567 + (grsec_lastack_retries > 0) &&
98568 + (grsec_lastack_retries < retry_until))
98569 + retry_until = grsec_lastack_retries;
98570 +#endif
98571 +
98572 if (retransmits_timed_out(sk, retry_until,
98573 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
98574 /* Has it gone just too far? */
98575 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
98576 index 77bd16f..5f7174a 100644
98577 --- a/net/ipv4/udp.c
98578 +++ b/net/ipv4/udp.c
98579 @@ -87,6 +87,7 @@
98580 #include <linux/types.h>
98581 #include <linux/fcntl.h>
98582 #include <linux/module.h>
98583 +#include <linux/security.h>
98584 #include <linux/socket.h>
98585 #include <linux/sockios.h>
98586 #include <linux/igmp.h>
98587 @@ -113,6 +114,10 @@
98588 #include <net/busy_poll.h>
98589 #include "udp_impl.h"
98590
98591 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98592 +extern int grsec_enable_blackhole;
98593 +#endif
98594 +
98595 struct udp_table udp_table __read_mostly;
98596 EXPORT_SYMBOL(udp_table);
98597
98598 @@ -615,6 +620,9 @@ found:
98599 return s;
98600 }
98601
98602 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
98603 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
98604 +
98605 /*
98606 * This routine is called by the ICMP module when it gets some
98607 * sort of error condition. If err < 0 then the socket should
98608 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98609 dport = usin->sin_port;
98610 if (dport == 0)
98611 return -EINVAL;
98612 +
98613 + err = gr_search_udp_sendmsg(sk, usin);
98614 + if (err)
98615 + return err;
98616 } else {
98617 if (sk->sk_state != TCP_ESTABLISHED)
98618 return -EDESTADDRREQ;
98619 +
98620 + err = gr_search_udp_sendmsg(sk, NULL);
98621 + if (err)
98622 + return err;
98623 +
98624 daddr = inet->inet_daddr;
98625 dport = inet->inet_dport;
98626 /* Open fast path for connected socket.
98627 @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
98628 IS_UDPLITE(sk));
98629 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98630 IS_UDPLITE(sk));
98631 - atomic_inc(&sk->sk_drops);
98632 + atomic_inc_unchecked(&sk->sk_drops);
98633 __skb_unlink(skb, rcvq);
98634 __skb_queue_tail(&list_kill, skb);
98635 }
98636 @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98637 int is_udplite = IS_UDPLITE(sk);
98638 bool slow;
98639
98640 + /*
98641 + * Check any passed addresses
98642 + */
98643 + if (addr_len)
98644 + *addr_len = sizeof(*sin);
98645 +
98646 if (flags & MSG_ERRQUEUE)
98647 return ip_recv_error(sk, msg, len, addr_len);
98648
98649 @@ -1243,6 +1266,10 @@ try_again:
98650 if (!skb)
98651 goto out;
98652
98653 + err = gr_search_udp_recvmsg(sk, skb);
98654 + if (err)
98655 + goto out_free;
98656 +
98657 ulen = skb->len - sizeof(struct udphdr);
98658 copied = len;
98659 if (copied > ulen)
98660 @@ -1276,7 +1303,7 @@ try_again:
98661 if (unlikely(err)) {
98662 trace_kfree_skb(skb, udp_recvmsg);
98663 if (!peeked) {
98664 - atomic_inc(&sk->sk_drops);
98665 + atomic_inc_unchecked(&sk->sk_drops);
98666 UDP_INC_STATS_USER(sock_net(sk),
98667 UDP_MIB_INERRORS, is_udplite);
98668 }
98669 @@ -1295,7 +1322,6 @@ try_again:
98670 sin->sin_port = udp_hdr(skb)->source;
98671 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98672 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98673 - *addr_len = sizeof(*sin);
98674 }
98675 if (inet->cmsg_flags)
98676 ip_cmsg_recv(msg, skb);
98677 @@ -1566,7 +1592,7 @@ csum_error:
98678 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98679 drop:
98680 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98681 - atomic_inc(&sk->sk_drops);
98682 + atomic_inc_unchecked(&sk->sk_drops);
98683 kfree_skb(skb);
98684 return -1;
98685 }
98686 @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98687 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98688
98689 if (!skb1) {
98690 - atomic_inc(&sk->sk_drops);
98691 + atomic_inc_unchecked(&sk->sk_drops);
98692 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98693 IS_UDPLITE(sk));
98694 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98695 @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98696 goto csum_error;
98697
98698 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98699 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98700 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98701 +#endif
98702 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
98703
98704 /*
98705 @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
98706 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98707 0, sock_i_ino(sp),
98708 atomic_read(&sp->sk_refcnt), sp,
98709 - atomic_read(&sp->sk_drops));
98710 + atomic_read_unchecked(&sp->sk_drops));
98711 }
98712
98713 int udp4_seq_show(struct seq_file *seq, void *v)
98714 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
98715 index e1a6393..f634ce5 100644
98716 --- a/net/ipv4/xfrm4_policy.c
98717 +++ b/net/ipv4/xfrm4_policy.c
98718 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
98719 fl4->flowi4_tos = iph->tos;
98720 }
98721
98722 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
98723 +static int xfrm4_garbage_collect(struct dst_ops *ops)
98724 {
98725 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
98726
98727 - xfrm4_policy_afinfo.garbage_collect(net);
98728 + xfrm_garbage_collect_deferred(net);
98729 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
98730 }
98731
98732 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
98733
98734 static int __net_init xfrm4_net_init(struct net *net)
98735 {
98736 - struct ctl_table *table;
98737 + ctl_table_no_const *table = NULL;
98738 struct ctl_table_header *hdr;
98739
98740 - table = xfrm4_policy_table;
98741 if (!net_eq(net, &init_net)) {
98742 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98743 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98744 if (!table)
98745 goto err_alloc;
98746
98747 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
98748 - }
98749 -
98750 - hdr = register_net_sysctl(net, "net/ipv4", table);
98751 + hdr = register_net_sysctl(net, "net/ipv4", table);
98752 + } else
98753 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
98754 if (!hdr)
98755 goto err_reg;
98756
98757 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
98758 return 0;
98759
98760 err_reg:
98761 - if (!net_eq(net, &init_net))
98762 - kfree(table);
98763 + kfree(table);
98764 err_alloc:
98765 return -ENOMEM;
98766 }
98767 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
98768 index 6c7fa08..285086c 100644
98769 --- a/net/ipv6/addrconf.c
98770 +++ b/net/ipv6/addrconf.c
98771 @@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
98772 idx = 0;
98773 head = &net->dev_index_head[h];
98774 rcu_read_lock();
98775 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
98776 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
98777 net->dev_base_seq;
98778 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98779 if (idx < s_idx)
98780 @@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
98781 p.iph.ihl = 5;
98782 p.iph.protocol = IPPROTO_IPV6;
98783 p.iph.ttl = 64;
98784 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
98785 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
98786
98787 if (ops->ndo_do_ioctl) {
98788 mm_segment_t oldfs = get_fs();
98789 @@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
98790 s_ip_idx = ip_idx = cb->args[2];
98791
98792 rcu_read_lock();
98793 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98794 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98795 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
98796 idx = 0;
98797 head = &net->dev_index_head[h];
98798 @@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
98799 dst_free(&ifp->rt->dst);
98800 break;
98801 }
98802 - atomic_inc(&net->ipv6.dev_addr_genid);
98803 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
98804 rt_genid_bump_ipv6(net);
98805 }
98806
98807 @@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
98808 int *valp = ctl->data;
98809 int val = *valp;
98810 loff_t pos = *ppos;
98811 - struct ctl_table lctl;
98812 + ctl_table_no_const lctl;
98813 int ret;
98814
98815 /*
98816 @@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
98817 int *valp = ctl->data;
98818 int val = *valp;
98819 loff_t pos = *ppos;
98820 - struct ctl_table lctl;
98821 + ctl_table_no_const lctl;
98822 int ret;
98823
98824 /*
98825 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
98826 index d935889..2f64330 100644
98827 --- a/net/ipv6/af_inet6.c
98828 +++ b/net/ipv6/af_inet6.c
98829 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
98830 net->ipv6.sysctl.bindv6only = 0;
98831 net->ipv6.sysctl.icmpv6_time = 1*HZ;
98832 net->ipv6.sysctl.flowlabel_consistency = 1;
98833 - atomic_set(&net->ipv6.rt_genid, 0);
98834 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
98835
98836 err = ipv6_init_mibs(net);
98837 if (err)
98838 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
98839 index c3bf2d2..1f00573 100644
98840 --- a/net/ipv6/datagram.c
98841 +++ b/net/ipv6/datagram.c
98842 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
98843 0,
98844 sock_i_ino(sp),
98845 atomic_read(&sp->sk_refcnt), sp,
98846 - atomic_read(&sp->sk_drops));
98847 + atomic_read_unchecked(&sp->sk_drops));
98848 }
98849 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
98850 index 7b32652..0bc348b 100644
98851 --- a/net/ipv6/icmp.c
98852 +++ b/net/ipv6/icmp.c
98853 @@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
98854
98855 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
98856 {
98857 - struct ctl_table *table;
98858 + ctl_table_no_const *table;
98859
98860 table = kmemdup(ipv6_icmp_table_template,
98861 sizeof(ipv6_icmp_table_template),
98862 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
98863 index f3ffb43..1172ba7 100644
98864 --- a/net/ipv6/ip6_gre.c
98865 +++ b/net/ipv6/ip6_gre.c
98866 @@ -71,7 +71,7 @@ struct ip6gre_net {
98867 struct net_device *fb_tunnel_dev;
98868 };
98869
98870 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
98871 +static struct rtnl_link_ops ip6gre_link_ops;
98872 static int ip6gre_tunnel_init(struct net_device *dev);
98873 static void ip6gre_tunnel_setup(struct net_device *dev);
98874 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
98875 @@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
98876 }
98877
98878
98879 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
98880 +static struct inet6_protocol ip6gre_protocol = {
98881 .handler = ip6gre_rcv,
98882 .err_handler = ip6gre_err,
98883 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
98884 @@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
98885 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
98886 };
98887
98888 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98889 +static struct rtnl_link_ops ip6gre_link_ops = {
98890 .kind = "ip6gre",
98891 .maxtype = IFLA_GRE_MAX,
98892 .policy = ip6gre_policy,
98893 @@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98894 .fill_info = ip6gre_fill_info,
98895 };
98896
98897 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
98898 +static struct rtnl_link_ops ip6gre_tap_ops = {
98899 .kind = "ip6gretap",
98900 .maxtype = IFLA_GRE_MAX,
98901 .policy = ip6gre_policy,
98902 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
98903 index 5db8d31..4a72c26 100644
98904 --- a/net/ipv6/ip6_tunnel.c
98905 +++ b/net/ipv6/ip6_tunnel.c
98906 @@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
98907
98908 static int ip6_tnl_dev_init(struct net_device *dev);
98909 static void ip6_tnl_dev_setup(struct net_device *dev);
98910 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
98911 +static struct rtnl_link_ops ip6_link_ops;
98912
98913 static int ip6_tnl_net_id __read_mostly;
98914 struct ip6_tnl_net {
98915 @@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
98916 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
98917 };
98918
98919 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
98920 +static struct rtnl_link_ops ip6_link_ops = {
98921 .kind = "ip6tnl",
98922 .maxtype = IFLA_IPTUN_MAX,
98923 .policy = ip6_tnl_policy,
98924 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
98925 index 2d19272..3a46322 100644
98926 --- a/net/ipv6/ip6_vti.c
98927 +++ b/net/ipv6/ip6_vti.c
98928 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
98929
98930 static int vti6_dev_init(struct net_device *dev);
98931 static void vti6_dev_setup(struct net_device *dev);
98932 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
98933 +static struct rtnl_link_ops vti6_link_ops;
98934
98935 static int vti6_net_id __read_mostly;
98936 struct vti6_net {
98937 @@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
98938 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
98939 };
98940
98941 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
98942 +static struct rtnl_link_ops vti6_link_ops = {
98943 .kind = "vti6",
98944 .maxtype = IFLA_VTI_MAX,
98945 .policy = vti6_policy,
98946 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
98947 index 0a00f44..bec42b2 100644
98948 --- a/net/ipv6/ipv6_sockglue.c
98949 +++ b/net/ipv6/ipv6_sockglue.c
98950 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
98951 if (sk->sk_type != SOCK_STREAM)
98952 return -ENOPROTOOPT;
98953
98954 - msg.msg_control = optval;
98955 + msg.msg_control = (void __force_kernel *)optval;
98956 msg.msg_controllen = len;
98957 msg.msg_flags = flags;
98958
98959 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
98960 index 710238f..0fd1816 100644
98961 --- a/net/ipv6/netfilter/ip6_tables.c
98962 +++ b/net/ipv6/netfilter/ip6_tables.c
98963 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
98964 #endif
98965
98966 static int get_info(struct net *net, void __user *user,
98967 - const int *len, int compat)
98968 + int len, int compat)
98969 {
98970 char name[XT_TABLE_MAXNAMELEN];
98971 struct xt_table *t;
98972 int ret;
98973
98974 - if (*len != sizeof(struct ip6t_getinfo)) {
98975 - duprintf("length %u != %zu\n", *len,
98976 + if (len != sizeof(struct ip6t_getinfo)) {
98977 + duprintf("length %u != %zu\n", len,
98978 sizeof(struct ip6t_getinfo));
98979 return -EINVAL;
98980 }
98981 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
98982 info.size = private->size;
98983 strcpy(info.name, name);
98984
98985 - if (copy_to_user(user, &info, *len) != 0)
98986 + if (copy_to_user(user, &info, len) != 0)
98987 ret = -EFAULT;
98988 else
98989 ret = 0;
98990 @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98991
98992 switch (cmd) {
98993 case IP6T_SO_GET_INFO:
98994 - ret = get_info(sock_net(sk), user, len, 1);
98995 + ret = get_info(sock_net(sk), user, *len, 1);
98996 break;
98997 case IP6T_SO_GET_ENTRIES:
98998 ret = compat_get_entries(sock_net(sk), user, len);
98999 @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99000
99001 switch (cmd) {
99002 case IP6T_SO_GET_INFO:
99003 - ret = get_info(sock_net(sk), user, len, 0);
99004 + ret = get_info(sock_net(sk), user, *len, 0);
99005 break;
99006
99007 case IP6T_SO_GET_ENTRIES:
99008 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
99009 index 767ab8d..c5ec70a 100644
99010 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
99011 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
99012 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
99013
99014 static int nf_ct_frag6_sysctl_register(struct net *net)
99015 {
99016 - struct ctl_table *table;
99017 + ctl_table_no_const *table = NULL;
99018 struct ctl_table_header *hdr;
99019
99020 - table = nf_ct_frag6_sysctl_table;
99021 if (!net_eq(net, &init_net)) {
99022 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99023 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
99024 GFP_KERNEL);
99025 if (table == NULL)
99026 goto err_alloc;
99027 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99028 table[0].data = &net->nf_frag.frags.timeout;
99029 table[1].data = &net->nf_frag.frags.low_thresh;
99030 table[2].data = &net->nf_frag.frags.high_thresh;
99031 - }
99032 -
99033 - hdr = register_net_sysctl(net, "net/netfilter", table);
99034 + hdr = register_net_sysctl(net, "net/netfilter", table);
99035 + } else
99036 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
99037 if (hdr == NULL)
99038 goto err_reg;
99039
99040 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99041 return 0;
99042
99043 err_reg:
99044 - if (!net_eq(net, &init_net))
99045 - kfree(table);
99046 + kfree(table);
99047 err_alloc:
99048 return -ENOMEM;
99049 }
99050 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
99051 index 827f795..7e28e82 100644
99052 --- a/net/ipv6/output_core.c
99053 +++ b/net/ipv6/output_core.c
99054 @@ -9,8 +9,8 @@
99055
99056 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99057 {
99058 - static atomic_t ipv6_fragmentation_id;
99059 - int old, new;
99060 + static atomic_unchecked_t ipv6_fragmentation_id;
99061 + int id;
99062
99063 #if IS_ENABLED(CONFIG_IPV6)
99064 if (rt && !(rt->dst.flags & DST_NOPEER)) {
99065 @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99066 }
99067 }
99068 #endif
99069 - do {
99070 - old = atomic_read(&ipv6_fragmentation_id);
99071 - new = old + 1;
99072 - if (!new)
99073 - new = 1;
99074 - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
99075 - fhdr->identification = htonl(new);
99076 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99077 + if (!id)
99078 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99079 + fhdr->identification = htonl(id);
99080 }
99081 EXPORT_SYMBOL(ipv6_select_ident);
99082
99083 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
99084 index bda7429..469b26b 100644
99085 --- a/net/ipv6/ping.c
99086 +++ b/net/ipv6/ping.c
99087 @@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
99088 };
99089 #endif
99090
99091 +static struct pingv6_ops real_pingv6_ops = {
99092 + .ipv6_recv_error = ipv6_recv_error,
99093 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
99094 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
99095 + .icmpv6_err_convert = icmpv6_err_convert,
99096 + .ipv6_icmp_error = ipv6_icmp_error,
99097 + .ipv6_chk_addr = ipv6_chk_addr,
99098 +};
99099 +
99100 +static struct pingv6_ops dummy_pingv6_ops = {
99101 + .ipv6_recv_error = dummy_ipv6_recv_error,
99102 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
99103 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
99104 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
99105 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
99106 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
99107 +};
99108 +
99109 int __init pingv6_init(void)
99110 {
99111 #ifdef CONFIG_PROC_FS
99112 @@ -253,13 +271,7 @@ int __init pingv6_init(void)
99113 if (ret)
99114 return ret;
99115 #endif
99116 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
99117 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
99118 - pingv6_ops.ip6_datagram_recv_specific_ctl =
99119 - ip6_datagram_recv_specific_ctl;
99120 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
99121 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
99122 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
99123 + pingv6_ops = &real_pingv6_ops;
99124 return inet6_register_protosw(&pingv6_protosw);
99125 }
99126
99127 @@ -268,14 +280,9 @@ int __init pingv6_init(void)
99128 */
99129 void pingv6_exit(void)
99130 {
99131 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
99132 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
99133 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
99134 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
99135 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
99136 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
99137 #ifdef CONFIG_PROC_FS
99138 unregister_pernet_subsys(&ping_v6_net_ops);
99139 #endif
99140 + pingv6_ops = &dummy_pingv6_ops;
99141 inet6_unregister_protosw(&pingv6_protosw);
99142 }
99143 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
99144 index 1f29996..46fe0c7 100644
99145 --- a/net/ipv6/raw.c
99146 +++ b/net/ipv6/raw.c
99147 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
99148 {
99149 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
99150 skb_checksum_complete(skb)) {
99151 - atomic_inc(&sk->sk_drops);
99152 + atomic_inc_unchecked(&sk->sk_drops);
99153 kfree_skb(skb);
99154 return NET_RX_DROP;
99155 }
99156 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99157 struct raw6_sock *rp = raw6_sk(sk);
99158
99159 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
99160 - atomic_inc(&sk->sk_drops);
99161 + atomic_inc_unchecked(&sk->sk_drops);
99162 kfree_skb(skb);
99163 return NET_RX_DROP;
99164 }
99165 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99166
99167 if (inet->hdrincl) {
99168 if (skb_checksum_complete(skb)) {
99169 - atomic_inc(&sk->sk_drops);
99170 + atomic_inc_unchecked(&sk->sk_drops);
99171 kfree_skb(skb);
99172 return NET_RX_DROP;
99173 }
99174 @@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99175 if (flags & MSG_OOB)
99176 return -EOPNOTSUPP;
99177
99178 + if (addr_len)
99179 + *addr_len=sizeof(*sin6);
99180 +
99181 if (flags & MSG_ERRQUEUE)
99182 return ipv6_recv_error(sk, msg, len, addr_len);
99183
99184 @@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99185 sin6->sin6_flowinfo = 0;
99186 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
99187 IP6CB(skb)->iif);
99188 - *addr_len = sizeof(*sin6);
99189 }
99190
99191 sock_recv_ts_and_drops(msg, sk, skb);
99192 @@ -610,7 +612,7 @@ out:
99193 return err;
99194 }
99195
99196 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
99197 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
99198 struct flowi6 *fl6, struct dst_entry **dstp,
99199 unsigned int flags)
99200 {
99201 @@ -922,12 +924,15 @@ do_confirm:
99202 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
99203 char __user *optval, int optlen)
99204 {
99205 + struct icmp6_filter filter;
99206 +
99207 switch (optname) {
99208 case ICMPV6_FILTER:
99209 if (optlen > sizeof(struct icmp6_filter))
99210 optlen = sizeof(struct icmp6_filter);
99211 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
99212 + if (copy_from_user(&filter, optval, optlen))
99213 return -EFAULT;
99214 + raw6_sk(sk)->filter = filter;
99215 return 0;
99216 default:
99217 return -ENOPROTOOPT;
99218 @@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99219 char __user *optval, int __user *optlen)
99220 {
99221 int len;
99222 + struct icmp6_filter filter;
99223
99224 switch (optname) {
99225 case ICMPV6_FILTER:
99226 @@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99227 len = sizeof(struct icmp6_filter);
99228 if (put_user(len, optlen))
99229 return -EFAULT;
99230 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
99231 + filter = raw6_sk(sk)->filter;
99232 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
99233 return -EFAULT;
99234 return 0;
99235 default:
99236 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
99237 index cc85a9b..526a133 100644
99238 --- a/net/ipv6/reassembly.c
99239 +++ b/net/ipv6/reassembly.c
99240 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
99241
99242 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99243 {
99244 - struct ctl_table *table;
99245 + ctl_table_no_const *table = NULL;
99246 struct ctl_table_header *hdr;
99247
99248 - table = ip6_frags_ns_ctl_table;
99249 if (!net_eq(net, &init_net)) {
99250 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99251 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99252 if (table == NULL)
99253 goto err_alloc;
99254
99255 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99256 /* Don't export sysctls to unprivileged users */
99257 if (net->user_ns != &init_user_ns)
99258 table[0].procname = NULL;
99259 - }
99260 + hdr = register_net_sysctl(net, "net/ipv6", table);
99261 + } else
99262 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
99263
99264 - hdr = register_net_sysctl(net, "net/ipv6", table);
99265 if (hdr == NULL)
99266 goto err_reg;
99267
99268 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99269 return 0;
99270
99271 err_reg:
99272 - if (!net_eq(net, &init_net))
99273 - kfree(table);
99274 + kfree(table);
99275 err_alloc:
99276 return -ENOMEM;
99277 }
99278 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
99279 index fba54a4..73e374e 100644
99280 --- a/net/ipv6/route.c
99281 +++ b/net/ipv6/route.c
99282 @@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
99283
99284 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
99285 {
99286 - struct ctl_table *table;
99287 + ctl_table_no_const *table;
99288
99289 table = kmemdup(ipv6_route_table_template,
99290 sizeof(ipv6_route_table_template),
99291 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
99292 index b4d74c8..b4f3fbe 100644
99293 --- a/net/ipv6/sit.c
99294 +++ b/net/ipv6/sit.c
99295 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
99296 static void ipip6_dev_free(struct net_device *dev);
99297 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
99298 __be32 *v4dst);
99299 -static struct rtnl_link_ops sit_link_ops __read_mostly;
99300 +static struct rtnl_link_ops sit_link_ops;
99301
99302 static int sit_net_id __read_mostly;
99303 struct sit_net {
99304 @@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
99305 unregister_netdevice_queue(dev, head);
99306 }
99307
99308 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
99309 +static struct rtnl_link_ops sit_link_ops = {
99310 .kind = "sit",
99311 .maxtype = IFLA_IPTUN_MAX,
99312 .policy = ipip6_policy,
99313 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
99314 index 7f405a1..eabef92 100644
99315 --- a/net/ipv6/sysctl_net_ipv6.c
99316 +++ b/net/ipv6/sysctl_net_ipv6.c
99317 @@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
99318
99319 static int __net_init ipv6_sysctl_net_init(struct net *net)
99320 {
99321 - struct ctl_table *ipv6_table;
99322 + ctl_table_no_const *ipv6_table;
99323 struct ctl_table *ipv6_route_table;
99324 struct ctl_table *ipv6_icmp_table;
99325 int err;
99326 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
99327 index 889079b..a04512c 100644
99328 --- a/net/ipv6/tcp_ipv6.c
99329 +++ b/net/ipv6/tcp_ipv6.c
99330 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99331 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
99332 }
99333
99334 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99335 +extern int grsec_enable_blackhole;
99336 +#endif
99337 +
99338 static void tcp_v6_hash(struct sock *sk)
99339 {
99340 if (sk->sk_state != TCP_CLOSE) {
99341 @@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
99342 return 0;
99343
99344 reset:
99345 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99346 + if (!grsec_enable_blackhole)
99347 +#endif
99348 tcp_v6_send_reset(sk, skb);
99349 discard:
99350 if (opt_skb)
99351 @@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
99352 TCP_SKB_CB(skb)->sacked = 0;
99353
99354 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99355 - if (!sk)
99356 + if (!sk) {
99357 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99358 + ret = 1;
99359 +#endif
99360 goto no_tcp_socket;
99361 + }
99362
99363 process:
99364 - if (sk->sk_state == TCP_TIME_WAIT)
99365 + if (sk->sk_state == TCP_TIME_WAIT) {
99366 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99367 + ret = 2;
99368 +#endif
99369 goto do_time_wait;
99370 + }
99371
99372 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
99373 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99374 @@ -1553,6 +1568,10 @@ csum_error:
99375 bad_packet:
99376 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99377 } else {
99378 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99379 + if (!grsec_enable_blackhole || (ret == 1 &&
99380 + (skb->dev->flags & IFF_LOOPBACK)))
99381 +#endif
99382 tcp_v6_send_reset(NULL, skb);
99383 }
99384
99385 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
99386 index 1e586d9..384a9c9 100644
99387 --- a/net/ipv6/udp.c
99388 +++ b/net/ipv6/udp.c
99389 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
99390 udp_ipv6_hash_secret + net_hash_mix(net));
99391 }
99392
99393 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99394 +extern int grsec_enable_blackhole;
99395 +#endif
99396 +
99397 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
99398 {
99399 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
99400 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99401 int is_udp4;
99402 bool slow;
99403
99404 + if (addr_len)
99405 + *addr_len = sizeof(struct sockaddr_in6);
99406 +
99407 if (flags & MSG_ERRQUEUE)
99408 return ipv6_recv_error(sk, msg, len, addr_len);
99409
99410 @@ -435,7 +442,7 @@ try_again:
99411 if (unlikely(err)) {
99412 trace_kfree_skb(skb, udpv6_recvmsg);
99413 if (!peeked) {
99414 - atomic_inc(&sk->sk_drops);
99415 + atomic_inc_unchecked(&sk->sk_drops);
99416 if (is_udp4)
99417 UDP_INC_STATS_USER(sock_net(sk),
99418 UDP_MIB_INERRORS,
99419 @@ -475,7 +482,7 @@ try_again:
99420 ipv6_iface_scope_id(&sin6->sin6_addr,
99421 IP6CB(skb)->iif);
99422 }
99423 - *addr_len = sizeof(*sin6);
99424 +
99425 }
99426
99427 if (np->rxopt.all)
99428 @@ -690,7 +697,7 @@ csum_error:
99429 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99430 drop:
99431 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99432 - atomic_inc(&sk->sk_drops);
99433 + atomic_inc_unchecked(&sk->sk_drops);
99434 kfree_skb(skb);
99435 return -1;
99436 }
99437 @@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99438 if (likely(skb1 == NULL))
99439 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99440 if (!skb1) {
99441 - atomic_inc(&sk->sk_drops);
99442 + atomic_inc_unchecked(&sk->sk_drops);
99443 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99444 IS_UDPLITE(sk));
99445 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99446 @@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99447 goto csum_error;
99448
99449 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99450 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99451 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99452 +#endif
99453 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
99454
99455 kfree_skb(skb);
99456 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
99457 index 5f8e128..865d38e 100644
99458 --- a/net/ipv6/xfrm6_policy.c
99459 +++ b/net/ipv6/xfrm6_policy.c
99460 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
99461 }
99462 }
99463
99464 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
99465 +static int xfrm6_garbage_collect(struct dst_ops *ops)
99466 {
99467 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
99468
99469 - xfrm6_policy_afinfo.garbage_collect(net);
99470 + xfrm_garbage_collect_deferred(net);
99471 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
99472 }
99473
99474 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
99475
99476 static int __net_init xfrm6_net_init(struct net *net)
99477 {
99478 - struct ctl_table *table;
99479 + ctl_table_no_const *table = NULL;
99480 struct ctl_table_header *hdr;
99481
99482 - table = xfrm6_policy_table;
99483 if (!net_eq(net, &init_net)) {
99484 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99485 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99486 if (!table)
99487 goto err_alloc;
99488
99489 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
99490 - }
99491 + hdr = register_net_sysctl(net, "net/ipv6", table);
99492 + } else
99493 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
99494
99495 - hdr = register_net_sysctl(net, "net/ipv6", table);
99496 if (!hdr)
99497 goto err_reg;
99498
99499 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
99500 return 0;
99501
99502 err_reg:
99503 - if (!net_eq(net, &init_net))
99504 - kfree(table);
99505 + kfree(table);
99506 err_alloc:
99507 return -ENOMEM;
99508 }
99509 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
99510 index 2ba8b97..6d33010 100644
99511 --- a/net/irda/ircomm/ircomm_tty.c
99512 +++ b/net/irda/ircomm/ircomm_tty.c
99513 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99514 add_wait_queue(&port->open_wait, &wait);
99515
99516 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
99517 - __FILE__, __LINE__, tty->driver->name, port->count);
99518 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99519
99520 spin_lock_irqsave(&port->lock, flags);
99521 if (!tty_hung_up_p(filp))
99522 - port->count--;
99523 + atomic_dec(&port->count);
99524 port->blocked_open++;
99525 spin_unlock_irqrestore(&port->lock, flags);
99526
99527 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99528 }
99529
99530 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
99531 - __FILE__, __LINE__, tty->driver->name, port->count);
99532 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99533
99534 schedule();
99535 }
99536 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99537
99538 spin_lock_irqsave(&port->lock, flags);
99539 if (!tty_hung_up_p(filp))
99540 - port->count++;
99541 + atomic_inc(&port->count);
99542 port->blocked_open--;
99543 spin_unlock_irqrestore(&port->lock, flags);
99544
99545 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
99546 - __FILE__, __LINE__, tty->driver->name, port->count);
99547 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99548
99549 if (!retval)
99550 port->flags |= ASYNC_NORMAL_ACTIVE;
99551 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
99552
99553 /* ++ is not atomic, so this should be protected - Jean II */
99554 spin_lock_irqsave(&self->port.lock, flags);
99555 - self->port.count++;
99556 + atomic_inc(&self->port.count);
99557 spin_unlock_irqrestore(&self->port.lock, flags);
99558 tty_port_tty_set(&self->port, tty);
99559
99560 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
99561 - self->line, self->port.count);
99562 + self->line, atomic_read(&self->port.count));
99563
99564 /* Not really used by us, but lets do it anyway */
99565 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
99566 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
99567 tty_kref_put(port->tty);
99568 }
99569 port->tty = NULL;
99570 - port->count = 0;
99571 + atomic_set(&port->count, 0);
99572 spin_unlock_irqrestore(&port->lock, flags);
99573
99574 wake_up_interruptible(&port->open_wait);
99575 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
99576 seq_putc(m, '\n');
99577
99578 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
99579 - seq_printf(m, "Open count: %d\n", self->port.count);
99580 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
99581 seq_printf(m, "Max data size: %d\n", self->max_data_size);
99582 seq_printf(m, "Max header size: %d\n", self->max_header_size);
99583
99584 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
99585 index c4b7218..3e83259 100644
99586 --- a/net/iucv/af_iucv.c
99587 +++ b/net/iucv/af_iucv.c
99588 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
99589
99590 write_lock_bh(&iucv_sk_list.lock);
99591
99592 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
99593 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99594 while (__iucv_get_sock_by_name(name)) {
99595 sprintf(name, "%08x",
99596 - atomic_inc_return(&iucv_sk_list.autobind_name));
99597 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99598 }
99599
99600 write_unlock_bh(&iucv_sk_list.lock);
99601 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
99602 index cd5b8ec..f205e6b 100644
99603 --- a/net/iucv/iucv.c
99604 +++ b/net/iucv/iucv.c
99605 @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
99606 return NOTIFY_OK;
99607 }
99608
99609 -static struct notifier_block __refdata iucv_cpu_notifier = {
99610 +static struct notifier_block iucv_cpu_notifier = {
99611 .notifier_call = iucv_cpu_notify,
99612 };
99613
99614 diff --git a/net/key/af_key.c b/net/key/af_key.c
99615 index 7932697..a13d158 100644
99616 --- a/net/key/af_key.c
99617 +++ b/net/key/af_key.c
99618 @@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
99619 static u32 get_acqseq(void)
99620 {
99621 u32 res;
99622 - static atomic_t acqseq;
99623 + static atomic_unchecked_t acqseq;
99624
99625 do {
99626 - res = atomic_inc_return(&acqseq);
99627 + res = atomic_inc_return_unchecked(&acqseq);
99628 } while (!res);
99629 return res;
99630 }
99631 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
99632 index 0b44d85..1a7f88b 100644
99633 --- a/net/l2tp/l2tp_ip.c
99634 +++ b/net/l2tp/l2tp_ip.c
99635 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99636 if (flags & MSG_OOB)
99637 goto out;
99638
99639 + if (addr_len)
99640 + *addr_len = sizeof(*sin);
99641 +
99642 skb = skb_recv_datagram(sk, flags, noblock, &err);
99643 if (!skb)
99644 goto out;
99645 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99646 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99647 sin->sin_port = 0;
99648 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99649 - *addr_len = sizeof(*sin);
99650 }
99651 if (inet->cmsg_flags)
99652 ip_cmsg_recv(msg, skb);
99653 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
99654 index 453e974..b3a43a5 100644
99655 --- a/net/mac80211/cfg.c
99656 +++ b/net/mac80211/cfg.c
99657 @@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
99658 ret = ieee80211_vif_use_channel(sdata, chandef,
99659 IEEE80211_CHANCTX_EXCLUSIVE);
99660 }
99661 - } else if (local->open_count == local->monitors) {
99662 + } else if (local_read(&local->open_count) == local->monitors) {
99663 local->_oper_chandef = *chandef;
99664 ieee80211_hw_config(local, 0);
99665 }
99666 @@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
99667 else
99668 local->probe_req_reg--;
99669
99670 - if (!local->open_count)
99671 + if (!local_read(&local->open_count))
99672 break;
99673
99674 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
99675 @@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
99676 if (chanctx_conf) {
99677 *chandef = chanctx_conf->def;
99678 ret = 0;
99679 - } else if (local->open_count > 0 &&
99680 - local->open_count == local->monitors &&
99681 + } else if (local_read(&local->open_count) > 0 &&
99682 + local_read(&local->open_count) == local->monitors &&
99683 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
99684 if (local->use_chanctx)
99685 *chandef = local->monitor_chandef;
99686 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
99687 index 5e44e317..3d404a6 100644
99688 --- a/net/mac80211/ieee80211_i.h
99689 +++ b/net/mac80211/ieee80211_i.h
99690 @@ -28,6 +28,7 @@
99691 #include <net/ieee80211_radiotap.h>
99692 #include <net/cfg80211.h>
99693 #include <net/mac80211.h>
99694 +#include <asm/local.h>
99695 #include "key.h"
99696 #include "sta_info.h"
99697 #include "debug.h"
99698 @@ -994,7 +995,7 @@ struct ieee80211_local {
99699 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
99700 spinlock_t queue_stop_reason_lock;
99701
99702 - int open_count;
99703 + local_t open_count;
99704 int monitors, cooked_mntrs;
99705 /* number of interfaces with corresponding FIF_ flags */
99706 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
99707 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
99708 index ce1c443..6cd39e1 100644
99709 --- a/net/mac80211/iface.c
99710 +++ b/net/mac80211/iface.c
99711 @@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99712 break;
99713 }
99714
99715 - if (local->open_count == 0) {
99716 + if (local_read(&local->open_count) == 0) {
99717 res = drv_start(local);
99718 if (res)
99719 goto err_del_bss;
99720 @@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99721 res = drv_add_interface(local, sdata);
99722 if (res)
99723 goto err_stop;
99724 - } else if (local->monitors == 0 && local->open_count == 0) {
99725 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
99726 res = ieee80211_add_virtual_monitor(local);
99727 if (res)
99728 goto err_stop;
99729 @@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99730 atomic_inc(&local->iff_promiscs);
99731
99732 if (coming_up)
99733 - local->open_count++;
99734 + local_inc(&local->open_count);
99735
99736 if (hw_reconf_flags)
99737 ieee80211_hw_config(local, hw_reconf_flags);
99738 @@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99739 err_del_interface:
99740 drv_remove_interface(local, sdata);
99741 err_stop:
99742 - if (!local->open_count)
99743 + if (!local_read(&local->open_count))
99744 drv_stop(local);
99745 err_del_bss:
99746 sdata->bss = NULL;
99747 @@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99748 }
99749
99750 if (going_down)
99751 - local->open_count--;
99752 + local_dec(&local->open_count);
99753
99754 switch (sdata->vif.type) {
99755 case NL80211_IFTYPE_AP_VLAN:
99756 @@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99757 }
99758 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
99759
99760 - if (local->open_count == 0)
99761 + if (local_read(&local->open_count) == 0)
99762 ieee80211_clear_tx_pending(local);
99763
99764 /*
99765 @@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99766
99767 ieee80211_recalc_ps(local, -1);
99768
99769 - if (local->open_count == 0) {
99770 + if (local_read(&local->open_count) == 0) {
99771 ieee80211_stop_device(local);
99772
99773 /* no reconfiguring after stop! */
99774 @@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99775 ieee80211_configure_filter(local);
99776 ieee80211_hw_config(local, hw_reconf_flags);
99777
99778 - if (local->monitors == local->open_count)
99779 + if (local->monitors == local_read(&local->open_count))
99780 ieee80211_add_virtual_monitor(local);
99781 }
99782
99783 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
99784 index d767cfb..b4cd07d 100644
99785 --- a/net/mac80211/main.c
99786 +++ b/net/mac80211/main.c
99787 @@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
99788 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
99789 IEEE80211_CONF_CHANGE_POWER);
99790
99791 - if (changed && local->open_count) {
99792 + if (changed && local_read(&local->open_count)) {
99793 ret = drv_config(local, changed);
99794 /*
99795 * Goal:
99796 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
99797 index af64fb8..366e371 100644
99798 --- a/net/mac80211/pm.c
99799 +++ b/net/mac80211/pm.c
99800 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99801 struct ieee80211_sub_if_data *sdata;
99802 struct sta_info *sta;
99803
99804 - if (!local->open_count)
99805 + if (!local_read(&local->open_count))
99806 goto suspend;
99807
99808 ieee80211_scan_cancel(local);
99809 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99810 cancel_work_sync(&local->dynamic_ps_enable_work);
99811 del_timer_sync(&local->dynamic_ps_timer);
99812
99813 - local->wowlan = wowlan && local->open_count;
99814 + local->wowlan = wowlan && local_read(&local->open_count);
99815 if (local->wowlan) {
99816 int err = drv_suspend(local, wowlan);
99817 if (err < 0) {
99818 @@ -115,7 +115,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99819 WARN_ON(!list_empty(&local->chanctx_list));
99820
99821 /* stop hardware - this must stop RX */
99822 - if (local->open_count)
99823 + if (local_read(&local->open_count))
99824 ieee80211_stop_device(local);
99825
99826 suspend:
99827 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
99828 index 22b223f..ab70070 100644
99829 --- a/net/mac80211/rate.c
99830 +++ b/net/mac80211/rate.c
99831 @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
99832
99833 ASSERT_RTNL();
99834
99835 - if (local->open_count)
99836 + if (local_read(&local->open_count))
99837 return -EBUSY;
99838
99839 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
99840 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
99841 index 6ff1346..936ca9a 100644
99842 --- a/net/mac80211/rc80211_pid_debugfs.c
99843 +++ b/net/mac80211/rc80211_pid_debugfs.c
99844 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
99845
99846 spin_unlock_irqrestore(&events->lock, status);
99847
99848 - if (copy_to_user(buf, pb, p))
99849 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
99850 return -EFAULT;
99851
99852 return p;
99853 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
99854 index b8700d4..89086d5 100644
99855 --- a/net/mac80211/util.c
99856 +++ b/net/mac80211/util.c
99857 @@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99858 }
99859 #endif
99860 /* everything else happens only if HW was up & running */
99861 - if (!local->open_count)
99862 + if (!local_read(&local->open_count))
99863 goto wake_up;
99864
99865 /*
99866 @@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99867 local->in_reconfig = false;
99868 barrier();
99869
99870 - if (local->monitors == local->open_count && local->monitors > 0)
99871 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
99872 ieee80211_add_virtual_monitor(local);
99873
99874 /*
99875 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
99876 index e9410d1..77b6378 100644
99877 --- a/net/netfilter/Kconfig
99878 +++ b/net/netfilter/Kconfig
99879 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
99880
99881 To compile it as a module, choose M here. If unsure, say N.
99882
99883 +config NETFILTER_XT_MATCH_GRADM
99884 + tristate '"gradm" match support'
99885 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
99886 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
99887 + ---help---
99888 + The gradm match allows to match on grsecurity RBAC being enabled.
99889 + It is useful when iptables rules are applied early on bootup to
99890 + prevent connections to the machine (except from a trusted host)
99891 + while the RBAC system is disabled.
99892 +
99893 config NETFILTER_XT_MATCH_HASHLIMIT
99894 tristate '"hashlimit" match support'
99895 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
99896 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
99897 index bffdad7..f9317d1 100644
99898 --- a/net/netfilter/Makefile
99899 +++ b/net/netfilter/Makefile
99900 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
99901 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
99902 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
99903 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
99904 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
99905 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
99906 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
99907 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
99908 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
99909 index de770ec..3fc49d2 100644
99910 --- a/net/netfilter/ipset/ip_set_core.c
99911 +++ b/net/netfilter/ipset/ip_set_core.c
99912 @@ -1922,7 +1922,7 @@ done:
99913 return ret;
99914 }
99915
99916 -static struct nf_sockopt_ops so_set __read_mostly = {
99917 +static struct nf_sockopt_ops so_set = {
99918 .pf = PF_INET,
99919 .get_optmin = SO_IP_SET,
99920 .get_optmax = SO_IP_SET + 1,
99921 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
99922 index a8eb0a8..86f2de4 100644
99923 --- a/net/netfilter/ipvs/ip_vs_conn.c
99924 +++ b/net/netfilter/ipvs/ip_vs_conn.c
99925 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
99926 /* Increase the refcnt counter of the dest */
99927 ip_vs_dest_hold(dest);
99928
99929 - conn_flags = atomic_read(&dest->conn_flags);
99930 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
99931 if (cp->protocol != IPPROTO_UDP)
99932 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
99933 flags = cp->flags;
99934 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
99935
99936 cp->control = NULL;
99937 atomic_set(&cp->n_control, 0);
99938 - atomic_set(&cp->in_pkts, 0);
99939 + atomic_set_unchecked(&cp->in_pkts, 0);
99940
99941 cp->packet_xmit = NULL;
99942 cp->app = NULL;
99943 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
99944
99945 /* Don't drop the entry if its number of incoming packets is not
99946 located in [0, 8] */
99947 - i = atomic_read(&cp->in_pkts);
99948 + i = atomic_read_unchecked(&cp->in_pkts);
99949 if (i > 8 || i < 0) return 0;
99950
99951 if (!todrop_rate[i]) return 0;
99952 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
99953 index 4f26ee4..6a9d7c3 100644
99954 --- a/net/netfilter/ipvs/ip_vs_core.c
99955 +++ b/net/netfilter/ipvs/ip_vs_core.c
99956 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
99957 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
99958 /* do not touch skb anymore */
99959
99960 - atomic_inc(&cp->in_pkts);
99961 + atomic_inc_unchecked(&cp->in_pkts);
99962 ip_vs_conn_put(cp);
99963 return ret;
99964 }
99965 @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
99966 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
99967 pkts = sysctl_sync_threshold(ipvs);
99968 else
99969 - pkts = atomic_add_return(1, &cp->in_pkts);
99970 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
99971
99972 if (ipvs->sync_state & IP_VS_STATE_MASTER)
99973 ip_vs_sync_conn(net, cp, pkts);
99974 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
99975 index 35be035..50f8834 100644
99976 --- a/net/netfilter/ipvs/ip_vs_ctl.c
99977 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
99978 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
99979 */
99980 ip_vs_rs_hash(ipvs, dest);
99981 }
99982 - atomic_set(&dest->conn_flags, conn_flags);
99983 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
99984
99985 /* bind the service */
99986 old_svc = rcu_dereference_protected(dest->svc, 1);
99987 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
99988 * align with netns init in ip_vs_control_net_init()
99989 */
99990
99991 -static struct ctl_table vs_vars[] = {
99992 +static ctl_table_no_const vs_vars[] __read_only = {
99993 {
99994 .procname = "amemthresh",
99995 .maxlen = sizeof(int),
99996 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
99997 " %-7s %-6d %-10d %-10d\n",
99998 &dest->addr.in6,
99999 ntohs(dest->port),
100000 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100001 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100002 atomic_read(&dest->weight),
100003 atomic_read(&dest->activeconns),
100004 atomic_read(&dest->inactconns));
100005 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100006 "%-7s %-6d %-10d %-10d\n",
100007 ntohl(dest->addr.ip),
100008 ntohs(dest->port),
100009 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100010 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100011 atomic_read(&dest->weight),
100012 atomic_read(&dest->activeconns),
100013 atomic_read(&dest->inactconns));
100014 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
100015
100016 entry.addr = dest->addr.ip;
100017 entry.port = dest->port;
100018 - entry.conn_flags = atomic_read(&dest->conn_flags);
100019 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
100020 entry.weight = atomic_read(&dest->weight);
100021 entry.u_threshold = dest->u_threshold;
100022 entry.l_threshold = dest->l_threshold;
100023 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
100024 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
100025 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
100026 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
100027 - (atomic_read(&dest->conn_flags) &
100028 + (atomic_read_unchecked(&dest->conn_flags) &
100029 IP_VS_CONN_F_FWD_MASK)) ||
100030 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
100031 atomic_read(&dest->weight)) ||
100032 @@ -3580,7 +3580,7 @@ out:
100033 }
100034
100035
100036 -static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
100037 +static const struct genl_ops ip_vs_genl_ops[] = {
100038 {
100039 .cmd = IPVS_CMD_NEW_SERVICE,
100040 .flags = GENL_ADMIN_PERM,
100041 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
100042 {
100043 int idx;
100044 struct netns_ipvs *ipvs = net_ipvs(net);
100045 - struct ctl_table *tbl;
100046 + ctl_table_no_const *tbl;
100047
100048 atomic_set(&ipvs->dropentry, 0);
100049 spin_lock_init(&ipvs->dropentry_lock);
100050 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
100051 index ca056a3..9cf01ef 100644
100052 --- a/net/netfilter/ipvs/ip_vs_lblc.c
100053 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
100054 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
100055 * IPVS LBLC sysctl table
100056 */
100057 #ifdef CONFIG_SYSCTL
100058 -static struct ctl_table vs_vars_table[] = {
100059 +static ctl_table_no_const vs_vars_table[] __read_only = {
100060 {
100061 .procname = "lblc_expiration",
100062 .data = NULL,
100063 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
100064 index 3f21a2f..a112e85 100644
100065 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
100066 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
100067 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
100068 * IPVS LBLCR sysctl table
100069 */
100070
100071 -static struct ctl_table vs_vars_table[] = {
100072 +static ctl_table_no_const vs_vars_table[] __read_only = {
100073 {
100074 .procname = "lblcr_expiration",
100075 .data = NULL,
100076 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
100077 index db80126..ef7110e 100644
100078 --- a/net/netfilter/ipvs/ip_vs_sync.c
100079 +++ b/net/netfilter/ipvs/ip_vs_sync.c
100080 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
100081 cp = cp->control;
100082 if (cp) {
100083 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100084 - pkts = atomic_add_return(1, &cp->in_pkts);
100085 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100086 else
100087 pkts = sysctl_sync_threshold(ipvs);
100088 ip_vs_sync_conn(net, cp->control, pkts);
100089 @@ -771,7 +771,7 @@ control:
100090 if (!cp)
100091 return;
100092 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100093 - pkts = atomic_add_return(1, &cp->in_pkts);
100094 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100095 else
100096 pkts = sysctl_sync_threshold(ipvs);
100097 goto sloop;
100098 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
100099
100100 if (opt)
100101 memcpy(&cp->in_seq, opt, sizeof(*opt));
100102 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100103 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100104 cp->state = state;
100105 cp->old_state = cp->state;
100106 /*
100107 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
100108 index c47444e..b0961c6 100644
100109 --- a/net/netfilter/ipvs/ip_vs_xmit.c
100110 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
100111 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
100112 else
100113 rc = NF_ACCEPT;
100114 /* do not touch skb anymore */
100115 - atomic_inc(&cp->in_pkts);
100116 + atomic_inc_unchecked(&cp->in_pkts);
100117 goto out;
100118 }
100119
100120 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
100121 else
100122 rc = NF_ACCEPT;
100123 /* do not touch skb anymore */
100124 - atomic_inc(&cp->in_pkts);
100125 + atomic_inc_unchecked(&cp->in_pkts);
100126 goto out;
100127 }
100128
100129 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
100130 index a4b5e2a..13b1de3 100644
100131 --- a/net/netfilter/nf_conntrack_acct.c
100132 +++ b/net/netfilter/nf_conntrack_acct.c
100133 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
100134 #ifdef CONFIG_SYSCTL
100135 static int nf_conntrack_acct_init_sysctl(struct net *net)
100136 {
100137 - struct ctl_table *table;
100138 + ctl_table_no_const *table;
100139
100140 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
100141 GFP_KERNEL);
100142 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
100143 index 356bef5..99932cb 100644
100144 --- a/net/netfilter/nf_conntrack_core.c
100145 +++ b/net/netfilter/nf_conntrack_core.c
100146 @@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
100147 #define DYING_NULLS_VAL ((1<<30)+1)
100148 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
100149
100150 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100151 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
100152 +#endif
100153 +
100154 int nf_conntrack_init_net(struct net *net)
100155 {
100156 int ret;
100157 @@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
100158 goto err_stat;
100159 }
100160
100161 +#ifdef CONFIG_GRKERNSEC_HIDESYM
100162 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
100163 +#else
100164 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
100165 +#endif
100166 if (!net->ct.slabname) {
100167 ret = -ENOMEM;
100168 goto err_slabname;
100169 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
100170 index 1df1761..ce8b88a 100644
100171 --- a/net/netfilter/nf_conntrack_ecache.c
100172 +++ b/net/netfilter/nf_conntrack_ecache.c
100173 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
100174 #ifdef CONFIG_SYSCTL
100175 static int nf_conntrack_event_init_sysctl(struct net *net)
100176 {
100177 - struct ctl_table *table;
100178 + ctl_table_no_const *table;
100179
100180 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
100181 GFP_KERNEL);
100182 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
100183 index 974a2a4..52cc6ff 100644
100184 --- a/net/netfilter/nf_conntrack_helper.c
100185 +++ b/net/netfilter/nf_conntrack_helper.c
100186 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
100187
100188 static int nf_conntrack_helper_init_sysctl(struct net *net)
100189 {
100190 - struct ctl_table *table;
100191 + ctl_table_no_const *table;
100192
100193 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
100194 GFP_KERNEL);
100195 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
100196 index b65d586..beec902 100644
100197 --- a/net/netfilter/nf_conntrack_proto.c
100198 +++ b/net/netfilter/nf_conntrack_proto.c
100199 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
100200
100201 static void
100202 nf_ct_unregister_sysctl(struct ctl_table_header **header,
100203 - struct ctl_table **table,
100204 + ctl_table_no_const **table,
100205 unsigned int users)
100206 {
100207 if (users > 0)
100208 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
100209 index f641751..d3c5b51 100644
100210 --- a/net/netfilter/nf_conntrack_standalone.c
100211 +++ b/net/netfilter/nf_conntrack_standalone.c
100212 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
100213
100214 static int nf_conntrack_standalone_init_sysctl(struct net *net)
100215 {
100216 - struct ctl_table *table;
100217 + ctl_table_no_const *table;
100218
100219 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
100220 GFP_KERNEL);
100221 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
100222 index 7a394df..bd91a8a 100644
100223 --- a/net/netfilter/nf_conntrack_timestamp.c
100224 +++ b/net/netfilter/nf_conntrack_timestamp.c
100225 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
100226 #ifdef CONFIG_SYSCTL
100227 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
100228 {
100229 - struct ctl_table *table;
100230 + ctl_table_no_const *table;
100231
100232 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
100233 GFP_KERNEL);
100234 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
100235 index 85296d4..8becdec 100644
100236 --- a/net/netfilter/nf_log.c
100237 +++ b/net/netfilter/nf_log.c
100238 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
100239
100240 #ifdef CONFIG_SYSCTL
100241 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
100242 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
100243 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
100244
100245 static int nf_log_proc_dostring(struct ctl_table *table, int write,
100246 void __user *buffer, size_t *lenp, loff_t *ppos)
100247 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
100248 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
100249 mutex_unlock(&nf_log_mutex);
100250 } else {
100251 + ctl_table_no_const nf_log_table = *table;
100252 +
100253 mutex_lock(&nf_log_mutex);
100254 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
100255 lockdep_is_held(&nf_log_mutex));
100256 if (!logger)
100257 - table->data = "NONE";
100258 + nf_log_table.data = "NONE";
100259 else
100260 - table->data = logger->name;
100261 - r = proc_dostring(table, write, buffer, lenp, ppos);
100262 + nf_log_table.data = logger->name;
100263 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
100264 mutex_unlock(&nf_log_mutex);
100265 }
100266
100267 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
100268 index f042ae5..30ea486 100644
100269 --- a/net/netfilter/nf_sockopt.c
100270 +++ b/net/netfilter/nf_sockopt.c
100271 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
100272 }
100273 }
100274
100275 - list_add(&reg->list, &nf_sockopts);
100276 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
100277 out:
100278 mutex_unlock(&nf_sockopt_mutex);
100279 return ret;
100280 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
100281 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
100282 {
100283 mutex_lock(&nf_sockopt_mutex);
100284 - list_del(&reg->list);
100285 + pax_list_del((struct list_head *)&reg->list);
100286 mutex_unlock(&nf_sockopt_mutex);
100287 }
100288 EXPORT_SYMBOL(nf_unregister_sockopt);
100289 diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
100290 index adce01e..8d52d50 100644
100291 --- a/net/netfilter/nf_tables_api.c
100292 +++ b/net/netfilter/nf_tables_api.c
100293 @@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
100294 #ifdef CONFIG_MODULES
100295 if (autoload) {
100296 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
100297 - request_module("nft-chain-%u-%*.s", afi->family,
100298 - nla_len(nla)-1, (const char *)nla_data(nla));
100299 + request_module("nft-chain-%u-%.*s", afi->family,
100300 + nla_len(nla), (const char *)nla_data(nla));
100301 nfnl_lock(NFNL_SUBSYS_NFTABLES);
100302 type = __nf_tables_chain_type_lookup(afi->family, nla);
100303 if (type != NULL)
100304 @@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
100305
100306 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
100307 [NFTA_SET_TABLE] = { .type = NLA_STRING },
100308 - [NFTA_SET_NAME] = { .type = NLA_STRING },
100309 + [NFTA_SET_NAME] = { .type = NLA_STRING,
100310 + .len = IFNAMSIZ - 1 },
100311 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
100312 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
100313 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
100314 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
100315 index a155d19..726b0f2 100644
100316 --- a/net/netfilter/nfnetlink_log.c
100317 +++ b/net/netfilter/nfnetlink_log.c
100318 @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
100319 struct nfnl_log_net {
100320 spinlock_t instances_lock;
100321 struct hlist_head instance_table[INSTANCE_BUCKETS];
100322 - atomic_t global_seq;
100323 + atomic_unchecked_t global_seq;
100324 };
100325
100326 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
100327 @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
100328 /* global sequence number */
100329 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
100330 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
100331 - htonl(atomic_inc_return(&log->global_seq))))
100332 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
100333 goto nla_put_failure;
100334
100335 if (data_len) {
100336 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
100337 index 82cb823..5685dd5 100644
100338 --- a/net/netfilter/nft_compat.c
100339 +++ b/net/netfilter/nft_compat.c
100340 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
100341 /* We want to reuse existing compat_to_user */
100342 old_fs = get_fs();
100343 set_fs(KERNEL_DS);
100344 - t->compat_to_user(out, in);
100345 + t->compat_to_user((void __force_user *)out, in);
100346 set_fs(old_fs);
100347 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
100348 kfree(out);
100349 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
100350 /* We want to reuse existing compat_to_user */
100351 old_fs = get_fs();
100352 set_fs(KERNEL_DS);
100353 - m->compat_to_user(out, in);
100354 + m->compat_to_user((void __force_user *)out, in);
100355 set_fs(old_fs);
100356 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
100357 kfree(out);
100358 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
100359 new file mode 100644
100360 index 0000000..c566332
100361 --- /dev/null
100362 +++ b/net/netfilter/xt_gradm.c
100363 @@ -0,0 +1,51 @@
100364 +/*
100365 + * gradm match for netfilter
100366 + * Copyright © Zbigniew Krzystolik, 2010
100367 + *
100368 + * This program is free software; you can redistribute it and/or modify
100369 + * it under the terms of the GNU General Public License; either version
100370 + * 2 or 3 as published by the Free Software Foundation.
100371 + */
100372 +#include <linux/module.h>
100373 +#include <linux/moduleparam.h>
100374 +#include <linux/skbuff.h>
100375 +#include <linux/netfilter/x_tables.h>
100376 +#include <linux/grsecurity.h>
100377 +#include <linux/netfilter/xt_gradm.h>
100378 +
100379 +static bool
100380 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
100381 +{
100382 + const struct xt_gradm_mtinfo *info = par->matchinfo;
100383 + bool retval = false;
100384 + if (gr_acl_is_enabled())
100385 + retval = true;
100386 + return retval ^ info->invflags;
100387 +}
100388 +
100389 +static struct xt_match gradm_mt_reg __read_mostly = {
100390 + .name = "gradm",
100391 + .revision = 0,
100392 + .family = NFPROTO_UNSPEC,
100393 + .match = gradm_mt,
100394 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
100395 + .me = THIS_MODULE,
100396 +};
100397 +
100398 +static int __init gradm_mt_init(void)
100399 +{
100400 + return xt_register_match(&gradm_mt_reg);
100401 +}
100402 +
100403 +static void __exit gradm_mt_exit(void)
100404 +{
100405 + xt_unregister_match(&gradm_mt_reg);
100406 +}
100407 +
100408 +module_init(gradm_mt_init);
100409 +module_exit(gradm_mt_exit);
100410 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
100411 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
100412 +MODULE_LICENSE("GPL");
100413 +MODULE_ALIAS("ipt_gradm");
100414 +MODULE_ALIAS("ip6t_gradm");
100415 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
100416 index 11de55e..f25e448 100644
100417 --- a/net/netfilter/xt_statistic.c
100418 +++ b/net/netfilter/xt_statistic.c
100419 @@ -19,7 +19,7 @@
100420 #include <linux/module.h>
100421
100422 struct xt_statistic_priv {
100423 - atomic_t count;
100424 + atomic_unchecked_t count;
100425 } ____cacheline_aligned_in_smp;
100426
100427 MODULE_LICENSE("GPL");
100428 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
100429 break;
100430 case XT_STATISTIC_MODE_NTH:
100431 do {
100432 - oval = atomic_read(&info->master->count);
100433 + oval = atomic_read_unchecked(&info->master->count);
100434 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
100435 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
100436 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
100437 if (nval == 0)
100438 ret = !ret;
100439 break;
100440 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
100441 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
100442 if (info->master == NULL)
100443 return -ENOMEM;
100444 - atomic_set(&info->master->count, info->u.nth.count);
100445 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
100446
100447 return 0;
100448 }
100449 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
100450 index 04748ab6..ca8f86f 100644
100451 --- a/net/netlink/af_netlink.c
100452 +++ b/net/netlink/af_netlink.c
100453 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
100454 sk->sk_error_report(sk);
100455 }
100456 }
100457 - atomic_inc(&sk->sk_drops);
100458 + atomic_inc_unchecked(&sk->sk_drops);
100459 }
100460
100461 static void netlink_rcv_wake(struct sock *sk)
100462 @@ -2933,7 +2933,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
100463 sk_wmem_alloc_get(s),
100464 nlk->cb_running,
100465 atomic_read(&s->sk_refcnt),
100466 - atomic_read(&s->sk_drops),
100467 + atomic_read_unchecked(&s->sk_drops),
100468 sock_i_ino(s)
100469 );
100470
100471 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
100472 index b74aa07..d41926e 100644
100473 --- a/net/netrom/af_netrom.c
100474 +++ b/net/netrom/af_netrom.c
100475 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
100476 *uaddr_len = sizeof(struct full_sockaddr_ax25);
100477 } else {
100478 sax->fsa_ax25.sax25_family = AF_NETROM;
100479 - sax->fsa_ax25.sax25_ndigis = 0;
100480 sax->fsa_ax25.sax25_call = nr->source_addr;
100481 *uaddr_len = sizeof(struct sockaddr_ax25);
100482 }
100483 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
100484 index 48a6a93..0b0496e 100644
100485 --- a/net/packet/af_packet.c
100486 +++ b/net/packet/af_packet.c
100487 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100488
100489 spin_lock(&sk->sk_receive_queue.lock);
100490 po->stats.stats1.tp_packets++;
100491 - skb->dropcount = atomic_read(&sk->sk_drops);
100492 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
100493 __skb_queue_tail(&sk->sk_receive_queue, skb);
100494 spin_unlock(&sk->sk_receive_queue.lock);
100495 sk->sk_data_ready(sk, skb->len);
100496 @@ -1854,7 +1854,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
100497 drop_n_acct:
100498 spin_lock(&sk->sk_receive_queue.lock);
100499 po->stats.stats1.tp_drops++;
100500 - atomic_inc(&sk->sk_drops);
100501 + atomic_inc_unchecked(&sk->sk_drops);
100502 spin_unlock(&sk->sk_receive_queue.lock);
100503
100504 drop_n_restore:
100505 @@ -3449,7 +3449,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100506 case PACKET_HDRLEN:
100507 if (len > sizeof(int))
100508 len = sizeof(int);
100509 - if (copy_from_user(&val, optval, len))
100510 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
100511 return -EFAULT;
100512 switch (val) {
100513 case TPACKET_V1:
100514 @@ -3495,7 +3495,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
100515 len = lv;
100516 if (put_user(len, optlen))
100517 return -EFAULT;
100518 - if (copy_to_user(optval, data, len))
100519 + if (len > sizeof(st) || copy_to_user(optval, data, len))
100520 return -EFAULT;
100521 return 0;
100522 }
100523 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
100524 index e774117..900b8b7 100644
100525 --- a/net/phonet/pep.c
100526 +++ b/net/phonet/pep.c
100527 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100528
100529 case PNS_PEP_CTRL_REQ:
100530 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
100531 - atomic_inc(&sk->sk_drops);
100532 + atomic_inc_unchecked(&sk->sk_drops);
100533 break;
100534 }
100535 __skb_pull(skb, 4);
100536 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
100537 }
100538
100539 if (pn->rx_credits == 0) {
100540 - atomic_inc(&sk->sk_drops);
100541 + atomic_inc_unchecked(&sk->sk_drops);
100542 err = -ENOBUFS;
100543 break;
100544 }
100545 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
100546 }
100547
100548 if (pn->rx_credits == 0) {
100549 - atomic_inc(&sk->sk_drops);
100550 + atomic_inc_unchecked(&sk->sk_drops);
100551 err = NET_RX_DROP;
100552 break;
100553 }
100554 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
100555 index 008214a..bb68240 100644
100556 --- a/net/phonet/socket.c
100557 +++ b/net/phonet/socket.c
100558 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
100559 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
100560 sock_i_ino(sk),
100561 atomic_read(&sk->sk_refcnt), sk,
100562 - atomic_read(&sk->sk_drops));
100563 + atomic_read_unchecked(&sk->sk_drops));
100564 }
100565 seq_pad(seq, '\n');
100566 return 0;
100567 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
100568 index c02a8c4..3c5b600 100644
100569 --- a/net/phonet/sysctl.c
100570 +++ b/net/phonet/sysctl.c
100571 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
100572 {
100573 int ret;
100574 int range[2] = {local_port_range[0], local_port_range[1]};
100575 - struct ctl_table tmp = {
100576 + ctl_table_no_const tmp = {
100577 .data = &range,
100578 .maxlen = sizeof(range),
100579 .mode = table->mode,
100580 diff --git a/net/rds/cong.c b/net/rds/cong.c
100581 index e5b65ac..f3b6fb7 100644
100582 --- a/net/rds/cong.c
100583 +++ b/net/rds/cong.c
100584 @@ -78,7 +78,7 @@
100585 * finds that the saved generation number is smaller than the global generation
100586 * number, it wakes up the process.
100587 */
100588 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
100589 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
100590
100591 /*
100592 * Congestion monitoring
100593 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
100594 rdsdebug("waking map %p for %pI4\n",
100595 map, &map->m_addr);
100596 rds_stats_inc(s_cong_update_received);
100597 - atomic_inc(&rds_cong_generation);
100598 + atomic_inc_unchecked(&rds_cong_generation);
100599 if (waitqueue_active(&map->m_waitq))
100600 wake_up(&map->m_waitq);
100601 if (waitqueue_active(&rds_poll_waitq))
100602 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
100603
100604 int rds_cong_updated_since(unsigned long *recent)
100605 {
100606 - unsigned long gen = atomic_read(&rds_cong_generation);
100607 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
100608
100609 if (likely(*recent == gen))
100610 return 0;
100611 diff --git a/net/rds/ib.h b/net/rds/ib.h
100612 index 7280ab8..e04f4ea 100644
100613 --- a/net/rds/ib.h
100614 +++ b/net/rds/ib.h
100615 @@ -128,7 +128,7 @@ struct rds_ib_connection {
100616 /* sending acks */
100617 unsigned long i_ack_flags;
100618 #ifdef KERNEL_HAS_ATOMIC64
100619 - atomic64_t i_ack_next; /* next ACK to send */
100620 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
100621 #else
100622 spinlock_t i_ack_lock; /* protect i_ack_next */
100623 u64 i_ack_next; /* next ACK to send */
100624 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
100625 index 31b74f5..dc1fbfa 100644
100626 --- a/net/rds/ib_cm.c
100627 +++ b/net/rds/ib_cm.c
100628 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
100629 /* Clear the ACK state */
100630 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
100631 #ifdef KERNEL_HAS_ATOMIC64
100632 - atomic64_set(&ic->i_ack_next, 0);
100633 + atomic64_set_unchecked(&ic->i_ack_next, 0);
100634 #else
100635 ic->i_ack_next = 0;
100636 #endif
100637 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
100638 index b7ebe23..b6352f6 100644
100639 --- a/net/rds/ib_recv.c
100640 +++ b/net/rds/ib_recv.c
100641 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
100642 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
100643 int ack_required)
100644 {
100645 - atomic64_set(&ic->i_ack_next, seq);
100646 + atomic64_set_unchecked(&ic->i_ack_next, seq);
100647 if (ack_required) {
100648 smp_mb__before_clear_bit();
100649 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100650 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
100651 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100652 smp_mb__after_clear_bit();
100653
100654 - return atomic64_read(&ic->i_ack_next);
100655 + return atomic64_read_unchecked(&ic->i_ack_next);
100656 }
100657 #endif
100658
100659 diff --git a/net/rds/iw.h b/net/rds/iw.h
100660 index 04ce3b1..48119a6 100644
100661 --- a/net/rds/iw.h
100662 +++ b/net/rds/iw.h
100663 @@ -134,7 +134,7 @@ struct rds_iw_connection {
100664 /* sending acks */
100665 unsigned long i_ack_flags;
100666 #ifdef KERNEL_HAS_ATOMIC64
100667 - atomic64_t i_ack_next; /* next ACK to send */
100668 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
100669 #else
100670 spinlock_t i_ack_lock; /* protect i_ack_next */
100671 u64 i_ack_next; /* next ACK to send */
100672 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
100673 index a91e1db..cf3053f 100644
100674 --- a/net/rds/iw_cm.c
100675 +++ b/net/rds/iw_cm.c
100676 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
100677 /* Clear the ACK state */
100678 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
100679 #ifdef KERNEL_HAS_ATOMIC64
100680 - atomic64_set(&ic->i_ack_next, 0);
100681 + atomic64_set_unchecked(&ic->i_ack_next, 0);
100682 #else
100683 ic->i_ack_next = 0;
100684 #endif
100685 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
100686 index 4503335..db566b4 100644
100687 --- a/net/rds/iw_recv.c
100688 +++ b/net/rds/iw_recv.c
100689 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
100690 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
100691 int ack_required)
100692 {
100693 - atomic64_set(&ic->i_ack_next, seq);
100694 + atomic64_set_unchecked(&ic->i_ack_next, seq);
100695 if (ack_required) {
100696 smp_mb__before_clear_bit();
100697 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100698 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
100699 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
100700 smp_mb__after_clear_bit();
100701
100702 - return atomic64_read(&ic->i_ack_next);
100703 + return atomic64_read_unchecked(&ic->i_ack_next);
100704 }
100705 #endif
100706
100707 diff --git a/net/rds/rds.h b/net/rds/rds.h
100708 index 48f8ffc..0ef3eec 100644
100709 --- a/net/rds/rds.h
100710 +++ b/net/rds/rds.h
100711 @@ -449,7 +449,7 @@ struct rds_transport {
100712 void (*sync_mr)(void *trans_private, int direction);
100713 void (*free_mr)(void *trans_private, int invalidate);
100714 void (*flush_mrs)(void);
100715 -};
100716 +} __do_const;
100717
100718 struct rds_sock {
100719 struct sock rs_sk;
100720 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
100721 index edac9ef..16bcb98 100644
100722 --- a/net/rds/tcp.c
100723 +++ b/net/rds/tcp.c
100724 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
100725 int val = 1;
100726
100727 set_fs(KERNEL_DS);
100728 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
100729 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
100730 sizeof(val));
100731 set_fs(oldfs);
100732 }
100733 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
100734 index 81cf5a4..b5826ff 100644
100735 --- a/net/rds/tcp_send.c
100736 +++ b/net/rds/tcp_send.c
100737 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
100738
100739 oldfs = get_fs();
100740 set_fs(KERNEL_DS);
100741 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
100742 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
100743 sizeof(val));
100744 set_fs(oldfs);
100745 }
100746 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
100747 index e61aa60..f07cc89 100644
100748 --- a/net/rxrpc/af_rxrpc.c
100749 +++ b/net/rxrpc/af_rxrpc.c
100750 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
100751 __be32 rxrpc_epoch;
100752
100753 /* current debugging ID */
100754 -atomic_t rxrpc_debug_id;
100755 +atomic_unchecked_t rxrpc_debug_id;
100756
100757 /* count of skbs currently in use */
100758 atomic_t rxrpc_n_skbs;
100759 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
100760 index cd97a0c..0041649 100644
100761 --- a/net/rxrpc/ar-ack.c
100762 +++ b/net/rxrpc/ar-ack.c
100763 @@ -182,7 +182,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
100764
100765 _enter("{%d,%d,%d,%d},",
100766 call->acks_hard, call->acks_unacked,
100767 - atomic_read(&call->sequence),
100768 + atomic_read_unchecked(&call->sequence),
100769 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
100770
100771 stop = 0;
100772 @@ -206,7 +206,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
100773
100774 /* each Tx packet has a new serial number */
100775 sp->hdr.serial =
100776 - htonl(atomic_inc_return(&call->conn->serial));
100777 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
100778
100779 hdr = (struct rxrpc_header *) txb->head;
100780 hdr->serial = sp->hdr.serial;
100781 @@ -410,7 +410,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
100782 */
100783 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
100784 {
100785 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
100786 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
100787 }
100788
100789 /*
100790 @@ -636,7 +636,7 @@ process_further:
100791
100792 latest = ntohl(sp->hdr.serial);
100793 hard = ntohl(ack.firstPacket);
100794 - tx = atomic_read(&call->sequence);
100795 + tx = atomic_read_unchecked(&call->sequence);
100796
100797 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
100798 latest,
100799 @@ -1168,7 +1168,7 @@ void rxrpc_process_call(struct work_struct *work)
100800 goto maybe_reschedule;
100801
100802 send_ACK_with_skew:
100803 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
100804 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
100805 ntohl(ack.serial));
100806 send_ACK:
100807 mtu = call->conn->trans->peer->if_mtu;
100808 @@ -1180,7 +1180,7 @@ send_ACK:
100809 ackinfo.rxMTU = htonl(5692);
100810 ackinfo.jumbo_max = htonl(4);
100811
100812 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
100813 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
100814 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
100815 ntohl(hdr.serial),
100816 ntohs(ack.maxSkew),
100817 @@ -1198,7 +1198,7 @@ send_ACK:
100818 send_message:
100819 _debug("send message");
100820
100821 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
100822 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
100823 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
100824 send_message_2:
100825
100826 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
100827 index a3bbb36..3341fb9 100644
100828 --- a/net/rxrpc/ar-call.c
100829 +++ b/net/rxrpc/ar-call.c
100830 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
100831 spin_lock_init(&call->lock);
100832 rwlock_init(&call->state_lock);
100833 atomic_set(&call->usage, 1);
100834 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
100835 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100836 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
100837
100838 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
100839 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
100840 index 7bf5b5b..4a3bf2c 100644
100841 --- a/net/rxrpc/ar-connection.c
100842 +++ b/net/rxrpc/ar-connection.c
100843 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
100844 rwlock_init(&conn->lock);
100845 spin_lock_init(&conn->state_lock);
100846 atomic_set(&conn->usage, 1);
100847 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
100848 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100849 conn->avail_calls = RXRPC_MAXCALLS;
100850 conn->size_align = 4;
100851 conn->header_size = sizeof(struct rxrpc_header);
100852 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
100853 index e7ed43a..6afa140 100644
100854 --- a/net/rxrpc/ar-connevent.c
100855 +++ b/net/rxrpc/ar-connevent.c
100856 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
100857
100858 len = iov[0].iov_len + iov[1].iov_len;
100859
100860 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
100861 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
100862 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
100863
100864 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
100865 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
100866 index 529572f..c758ca7 100644
100867 --- a/net/rxrpc/ar-input.c
100868 +++ b/net/rxrpc/ar-input.c
100869 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
100870 /* track the latest serial number on this connection for ACK packet
100871 * information */
100872 serial = ntohl(sp->hdr.serial);
100873 - hi_serial = atomic_read(&call->conn->hi_serial);
100874 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
100875 while (serial > hi_serial)
100876 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
100877 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
100878 serial);
100879
100880 /* request ACK generation for any ACK or DATA packet that requests
100881 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
100882 index 5f43675..ca07817 100644
100883 --- a/net/rxrpc/ar-internal.h
100884 +++ b/net/rxrpc/ar-internal.h
100885 @@ -272,8 +272,8 @@ struct rxrpc_connection {
100886 int error; /* error code for local abort */
100887 int debug_id; /* debug ID for printks */
100888 unsigned int call_counter; /* call ID counter */
100889 - atomic_t serial; /* packet serial number counter */
100890 - atomic_t hi_serial; /* highest serial number received */
100891 + atomic_unchecked_t serial; /* packet serial number counter */
100892 + atomic_unchecked_t hi_serial; /* highest serial number received */
100893 u8 avail_calls; /* number of calls available */
100894 u8 size_align; /* data size alignment (for security) */
100895 u8 header_size; /* rxrpc + security header size */
100896 @@ -346,7 +346,7 @@ struct rxrpc_call {
100897 spinlock_t lock;
100898 rwlock_t state_lock; /* lock for state transition */
100899 atomic_t usage;
100900 - atomic_t sequence; /* Tx data packet sequence counter */
100901 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
100902 u32 abort_code; /* local/remote abort code */
100903 enum { /* current state of call */
100904 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
100905 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
100906 */
100907 extern atomic_t rxrpc_n_skbs;
100908 extern __be32 rxrpc_epoch;
100909 -extern atomic_t rxrpc_debug_id;
100910 +extern atomic_unchecked_t rxrpc_debug_id;
100911 extern struct workqueue_struct *rxrpc_workqueue;
100912
100913 /*
100914 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
100915 index 87f7135..74d3703 100644
100916 --- a/net/rxrpc/ar-local.c
100917 +++ b/net/rxrpc/ar-local.c
100918 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
100919 spin_lock_init(&local->lock);
100920 rwlock_init(&local->services_lock);
100921 atomic_set(&local->usage, 1);
100922 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
100923 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100924 memcpy(&local->srx, srx, sizeof(*srx));
100925 }
100926
100927 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
100928 index d0e8f1c..a3a1686 100644
100929 --- a/net/rxrpc/ar-output.c
100930 +++ b/net/rxrpc/ar-output.c
100931 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
100932 sp->hdr.cid = call->cid;
100933 sp->hdr.callNumber = call->call_id;
100934 sp->hdr.seq =
100935 - htonl(atomic_inc_return(&call->sequence));
100936 + htonl(atomic_inc_return_unchecked(&call->sequence));
100937 sp->hdr.serial =
100938 - htonl(atomic_inc_return(&conn->serial));
100939 + htonl(atomic_inc_return_unchecked(&conn->serial));
100940 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
100941 sp->hdr.userStatus = 0;
100942 sp->hdr.securityIndex = conn->security_ix;
100943 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
100944 index bebaa43..2644591 100644
100945 --- a/net/rxrpc/ar-peer.c
100946 +++ b/net/rxrpc/ar-peer.c
100947 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
100948 INIT_LIST_HEAD(&peer->error_targets);
100949 spin_lock_init(&peer->lock);
100950 atomic_set(&peer->usage, 1);
100951 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
100952 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100953 memcpy(&peer->srx, srx, sizeof(*srx));
100954
100955 rxrpc_assess_MTU_size(peer);
100956 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
100957 index 38047f7..9f48511 100644
100958 --- a/net/rxrpc/ar-proc.c
100959 +++ b/net/rxrpc/ar-proc.c
100960 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
100961 atomic_read(&conn->usage),
100962 rxrpc_conn_states[conn->state],
100963 key_serial(conn->key),
100964 - atomic_read(&conn->serial),
100965 - atomic_read(&conn->hi_serial));
100966 + atomic_read_unchecked(&conn->serial),
100967 + atomic_read_unchecked(&conn->hi_serial));
100968
100969 return 0;
100970 }
100971 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
100972 index 92df566..87ec1bf 100644
100973 --- a/net/rxrpc/ar-transport.c
100974 +++ b/net/rxrpc/ar-transport.c
100975 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
100976 spin_lock_init(&trans->client_lock);
100977 rwlock_init(&trans->conn_lock);
100978 atomic_set(&trans->usage, 1);
100979 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
100980 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
100981
100982 if (peer->srx.transport.family == AF_INET) {
100983 switch (peer->srx.transport_type) {
100984 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
100985 index f226709..0e735a8 100644
100986 --- a/net/rxrpc/rxkad.c
100987 +++ b/net/rxrpc/rxkad.c
100988 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
100989
100990 len = iov[0].iov_len + iov[1].iov_len;
100991
100992 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
100993 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
100994 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
100995
100996 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
100997 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
100998
100999 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
101000
101001 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
101002 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
101003 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
101004
101005 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
101006 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
101007 index 2b1738e..a9d0fc9 100644
101008 --- a/net/sctp/ipv6.c
101009 +++ b/net/sctp/ipv6.c
101010 @@ -966,7 +966,7 @@ static const struct inet6_protocol sctpv6_protocol = {
101011 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
101012 };
101013
101014 -static struct sctp_af sctp_af_inet6 = {
101015 +static struct sctp_af sctp_af_inet6 __read_only = {
101016 .sa_family = AF_INET6,
101017 .sctp_xmit = sctp_v6_xmit,
101018 .setsockopt = ipv6_setsockopt,
101019 @@ -998,7 +998,7 @@ static struct sctp_af sctp_af_inet6 = {
101020 #endif
101021 };
101022
101023 -static struct sctp_pf sctp_pf_inet6 = {
101024 +static struct sctp_pf sctp_pf_inet6 __read_only = {
101025 .event_msgname = sctp_inet6_event_msgname,
101026 .skb_msgname = sctp_inet6_skb_msgname,
101027 .af_supported = sctp_inet6_af_supported,
101028 @@ -1023,7 +1023,7 @@ void sctp_v6_pf_init(void)
101029
101030 void sctp_v6_pf_exit(void)
101031 {
101032 - list_del(&sctp_af_inet6.list);
101033 + pax_list_del(&sctp_af_inet6.list);
101034 }
101035
101036 /* Initialize IPv6 support and register with socket layer. */
101037 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
101038 index 4e1d0fc..068fef7 100644
101039 --- a/net/sctp/protocol.c
101040 +++ b/net/sctp/protocol.c
101041 @@ -831,8 +831,10 @@ int sctp_register_af(struct sctp_af *af)
101042 return 0;
101043 }
101044
101045 + pax_open_kernel();
101046 INIT_LIST_HEAD(&af->list);
101047 - list_add_tail(&af->list, &sctp_address_families);
101048 + pax_close_kernel();
101049 + pax_list_add_tail(&af->list, &sctp_address_families);
101050 return 1;
101051 }
101052
101053 @@ -962,7 +964,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
101054
101055 static struct sctp_af sctp_af_inet;
101056
101057 -static struct sctp_pf sctp_pf_inet = {
101058 +static struct sctp_pf sctp_pf_inet __read_only = {
101059 .event_msgname = sctp_inet_event_msgname,
101060 .skb_msgname = sctp_inet_skb_msgname,
101061 .af_supported = sctp_inet_af_supported,
101062 @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
101063 };
101064
101065 /* IPv4 address related functions. */
101066 -static struct sctp_af sctp_af_inet = {
101067 +static struct sctp_af sctp_af_inet __read_only = {
101068 .sa_family = AF_INET,
101069 .sctp_xmit = sctp_v4_xmit,
101070 .setsockopt = ip_setsockopt,
101071 @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
101072
101073 static void sctp_v4_pf_exit(void)
101074 {
101075 - list_del(&sctp_af_inet.list);
101076 + pax_list_del(&sctp_af_inet.list);
101077 }
101078
101079 static int sctp_v4_protosw_init(void)
101080 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
101081 index 5d6883f..394a102 100644
101082 --- a/net/sctp/sm_sideeffect.c
101083 +++ b/net/sctp/sm_sideeffect.c
101084 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
101085 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
101086 }
101087
101088 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
101089 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
101090 NULL,
101091 sctp_generate_t1_cookie_event,
101092 sctp_generate_t1_init_event,
101093 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
101094 index 981aaf8..5bc016d 100644
101095 --- a/net/sctp/socket.c
101096 +++ b/net/sctp/socket.c
101097 @@ -2169,11 +2169,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
101098 {
101099 struct sctp_association *asoc;
101100 struct sctp_ulpevent *event;
101101 + struct sctp_event_subscribe subscribe;
101102
101103 if (optlen > sizeof(struct sctp_event_subscribe))
101104 return -EINVAL;
101105 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
101106 + if (copy_from_user(&subscribe, optval, optlen))
101107 return -EFAULT;
101108 + sctp_sk(sk)->subscribe = subscribe;
101109
101110 /*
101111 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
101112 @@ -4255,13 +4257,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
101113 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101114 int __user *optlen)
101115 {
101116 + struct sctp_event_subscribe subscribe;
101117 +
101118 if (len <= 0)
101119 return -EINVAL;
101120 if (len > sizeof(struct sctp_event_subscribe))
101121 len = sizeof(struct sctp_event_subscribe);
101122 if (put_user(len, optlen))
101123 return -EFAULT;
101124 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
101125 + subscribe = sctp_sk(sk)->subscribe;
101126 + if (copy_to_user(optval, &subscribe, len))
101127 return -EFAULT;
101128 return 0;
101129 }
101130 @@ -4279,6 +4284,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
101131 */
101132 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
101133 {
101134 + __u32 autoclose;
101135 +
101136 /* Applicable to UDP-style socket only */
101137 if (sctp_style(sk, TCP))
101138 return -EOPNOTSUPP;
101139 @@ -4287,7 +4294,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
101140 len = sizeof(int);
101141 if (put_user(len, optlen))
101142 return -EFAULT;
101143 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
101144 + autoclose = sctp_sk(sk)->autoclose;
101145 + if (copy_to_user(optval, &autoclose, sizeof(int)))
101146 return -EFAULT;
101147 return 0;
101148 }
101149 @@ -4662,12 +4670,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
101150 */
101151 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
101152 {
101153 + struct sctp_initmsg initmsg;
101154 +
101155 if (len < sizeof(struct sctp_initmsg))
101156 return -EINVAL;
101157 len = sizeof(struct sctp_initmsg);
101158 if (put_user(len, optlen))
101159 return -EFAULT;
101160 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
101161 + initmsg = sctp_sk(sk)->initmsg;
101162 + if (copy_to_user(optval, &initmsg, len))
101163 return -EFAULT;
101164 return 0;
101165 }
101166 @@ -4708,6 +4719,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
101167 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
101168 if (space_left < addrlen)
101169 return -ENOMEM;
101170 + if (addrlen > sizeof(temp) || addrlen < 0)
101171 + return -EFAULT;
101172 if (copy_to_user(to, &temp, addrlen))
101173 return -EFAULT;
101174 to += addrlen;
101175 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
101176 index 35c8923..536614e 100644
101177 --- a/net/sctp/sysctl.c
101178 +++ b/net/sctp/sysctl.c
101179 @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
101180 {
101181 struct net *net = current->nsproxy->net_ns;
101182 char tmp[8];
101183 - struct ctl_table tbl;
101184 + ctl_table_no_const tbl;
101185 int ret;
101186 int changed = 0;
101187 char *none = "none";
101188 @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
101189 {
101190 struct net *net = current->nsproxy->net_ns;
101191 int new_value;
101192 - struct ctl_table tbl;
101193 + ctl_table_no_const tbl;
101194 unsigned int min = *(unsigned int *) ctl->extra1;
101195 unsigned int max = *(unsigned int *) ctl->extra2;
101196 int ret;
101197 @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101198 {
101199 struct net *net = current->nsproxy->net_ns;
101200 int new_value;
101201 - struct ctl_table tbl;
101202 + ctl_table_no_const tbl;
101203 unsigned int min = *(unsigned int *) ctl->extra1;
101204 unsigned int max = *(unsigned int *) ctl->extra2;
101205 int ret;
101206 @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
101207
101208 int sctp_sysctl_net_register(struct net *net)
101209 {
101210 - struct ctl_table *table = sctp_net_table;
101211 + ctl_table_no_const *table = NULL;
101212
101213 if (!net_eq(net, &init_net)) {
101214 int i;
101215 @@ -415,7 +415,10 @@ int sctp_sysctl_net_register(struct net *net)
101216 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
101217 }
101218
101219 - net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
101220 + if (!net_eq(net, &init_net))
101221 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
101222 + else
101223 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", sctp_net_table);
101224 return 0;
101225 }
101226
101227 diff --git a/net/socket.c b/net/socket.c
101228 index a19ae19..89554dc 100644
101229 --- a/net/socket.c
101230 +++ b/net/socket.c
101231 @@ -88,6 +88,7 @@
101232 #include <linux/magic.h>
101233 #include <linux/slab.h>
101234 #include <linux/xattr.h>
101235 +#include <linux/in.h>
101236
101237 #include <asm/uaccess.h>
101238 #include <asm/unistd.h>
101239 @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
101240 unsigned int sysctl_net_busy_poll __read_mostly;
101241 #endif
101242
101243 +#include <linux/grsock.h>
101244 +
101245 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
101246 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
101247 unsigned long nr_segs, loff_t pos);
101248 @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
101249 */
101250
101251 static DEFINE_SPINLOCK(net_family_lock);
101252 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101253 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
101254
101255 /*
101256 * Statistics counters of the socket lists
101257 @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
101258 &sockfs_dentry_operations, SOCKFS_MAGIC);
101259 }
101260
101261 -static struct vfsmount *sock_mnt __read_mostly;
101262 +struct vfsmount *sock_mnt __read_mostly;
101263
101264 static struct file_system_type sock_fs_type = {
101265 .name = "sockfs",
101266 @@ -1256,6 +1259,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101267 return -EAFNOSUPPORT;
101268 if (type < 0 || type >= SOCK_MAX)
101269 return -EINVAL;
101270 + if (protocol < 0)
101271 + return -EINVAL;
101272
101273 /* Compatibility.
101274
101275 @@ -1276,6 +1281,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
101276 if (err)
101277 return err;
101278
101279 + if(!kern && !gr_search_socket(family, type, protocol)) {
101280 + if (rcu_access_pointer(net_families[family]) == NULL)
101281 + return -EAFNOSUPPORT;
101282 + else
101283 + return -EACCES;
101284 + }
101285 +
101286 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
101287 + if (rcu_access_pointer(net_families[family]) == NULL)
101288 + return -EAFNOSUPPORT;
101289 + else
101290 + return -EACCES;
101291 + }
101292 +
101293 /*
101294 * Allocate the socket and allow the family to set things up. if
101295 * the protocol is 0, the family is instructed to select an appropriate
101296 @@ -1527,6 +1546,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101297 if (sock) {
101298 err = move_addr_to_kernel(umyaddr, addrlen, &address);
101299 if (err >= 0) {
101300 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
101301 + err = -EACCES;
101302 + goto error;
101303 + }
101304 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
101305 + if (err)
101306 + goto error;
101307 +
101308 err = security_socket_bind(sock,
101309 (struct sockaddr *)&address,
101310 addrlen);
101311 @@ -1535,6 +1562,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
101312 (struct sockaddr *)
101313 &address, addrlen);
101314 }
101315 +error:
101316 fput_light(sock->file, fput_needed);
101317 }
101318 return err;
101319 @@ -1558,10 +1586,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
101320 if ((unsigned int)backlog > somaxconn)
101321 backlog = somaxconn;
101322
101323 + if (gr_handle_sock_server_other(sock->sk)) {
101324 + err = -EPERM;
101325 + goto error;
101326 + }
101327 +
101328 + err = gr_search_listen(sock);
101329 + if (err)
101330 + goto error;
101331 +
101332 err = security_socket_listen(sock, backlog);
101333 if (!err)
101334 err = sock->ops->listen(sock, backlog);
101335
101336 +error:
101337 fput_light(sock->file, fput_needed);
101338 }
101339 return err;
101340 @@ -1605,6 +1643,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101341 newsock->type = sock->type;
101342 newsock->ops = sock->ops;
101343
101344 + if (gr_handle_sock_server_other(sock->sk)) {
101345 + err = -EPERM;
101346 + sock_release(newsock);
101347 + goto out_put;
101348 + }
101349 +
101350 + err = gr_search_accept(sock);
101351 + if (err) {
101352 + sock_release(newsock);
101353 + goto out_put;
101354 + }
101355 +
101356 /*
101357 * We don't need try_module_get here, as the listening socket (sock)
101358 * has the protocol module (sock->ops->owner) held.
101359 @@ -1650,6 +1700,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
101360 fd_install(newfd, newfile);
101361 err = newfd;
101362
101363 + gr_attach_curr_ip(newsock->sk);
101364 +
101365 out_put:
101366 fput_light(sock->file, fput_needed);
101367 out:
101368 @@ -1682,6 +1734,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101369 int, addrlen)
101370 {
101371 struct socket *sock;
101372 + struct sockaddr *sck;
101373 struct sockaddr_storage address;
101374 int err, fput_needed;
101375
101376 @@ -1692,6 +1745,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
101377 if (err < 0)
101378 goto out_put;
101379
101380 + sck = (struct sockaddr *)&address;
101381 +
101382 + if (gr_handle_sock_client(sck)) {
101383 + err = -EACCES;
101384 + goto out_put;
101385 + }
101386 +
101387 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
101388 + if (err)
101389 + goto out_put;
101390 +
101391 err =
101392 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
101393 if (err)
101394 @@ -1773,6 +1837,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
101395 * the protocol.
101396 */
101397
101398 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
101399 +
101400 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
101401 unsigned int, flags, struct sockaddr __user *, addr,
101402 int, addr_len)
101403 @@ -1839,7 +1905,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
101404 struct socket *sock;
101405 struct iovec iov;
101406 struct msghdr msg;
101407 - struct sockaddr_storage address;
101408 + struct sockaddr_storage address = { };
101409 int err, err2;
101410 int fput_needed;
101411
101412 @@ -2065,7 +2131,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
101413 * checking falls down on this.
101414 */
101415 if (copy_from_user(ctl_buf,
101416 - (void __user __force *)msg_sys->msg_control,
101417 + (void __force_user *)msg_sys->msg_control,
101418 ctl_len))
101419 goto out_freectl;
101420 msg_sys->msg_control = ctl_buf;
101421 @@ -2216,7 +2282,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
101422 int err, total_len, len;
101423
101424 /* kernel mode address */
101425 - struct sockaddr_storage addr;
101426 + struct sockaddr_storage addr = { };
101427
101428 /* user mode address pointers */
101429 struct sockaddr __user *uaddr;
101430 @@ -2245,7 +2311,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
101431 /* Save the user-mode address (verify_iovec will change the
101432 * kernel msghdr to use the kernel address space)
101433 */
101434 - uaddr = (__force void __user *)msg_sys->msg_name;
101435 + uaddr = (void __force_user *)msg_sys->msg_name;
101436 uaddr_len = COMPAT_NAMELEN(msg);
101437 if (MSG_CMSG_COMPAT & flags)
101438 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
101439 @@ -2889,7 +2955,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
101440 ifr = compat_alloc_user_space(buf_size);
101441 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
101442
101443 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
101444 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
101445 return -EFAULT;
101446
101447 if (put_user(convert_in ? rxnfc : compat_ptr(data),
101448 @@ -3000,7 +3066,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
101449 old_fs = get_fs();
101450 set_fs(KERNEL_DS);
101451 err = dev_ioctl(net, cmd,
101452 - (struct ifreq __user __force *) &kifr);
101453 + (struct ifreq __force_user *) &kifr);
101454 set_fs(old_fs);
101455
101456 return err;
101457 @@ -3093,7 +3159,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
101458
101459 old_fs = get_fs();
101460 set_fs(KERNEL_DS);
101461 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
101462 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
101463 set_fs(old_fs);
101464
101465 if (cmd == SIOCGIFMAP && !err) {
101466 @@ -3177,7 +3243,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
101467 ret |= get_user(rtdev, &(ur4->rt_dev));
101468 if (rtdev) {
101469 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
101470 - r4.rt_dev = (char __user __force *)devname;
101471 + r4.rt_dev = (char __force_user *)devname;
101472 devname[15] = 0;
101473 } else
101474 r4.rt_dev = NULL;
101475 @@ -3404,8 +3470,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
101476 int __user *uoptlen;
101477 int err;
101478
101479 - uoptval = (char __user __force *) optval;
101480 - uoptlen = (int __user __force *) optlen;
101481 + uoptval = (char __force_user *) optval;
101482 + uoptlen = (int __force_user *) optlen;
101483
101484 set_fs(KERNEL_DS);
101485 if (level == SOL_SOCKET)
101486 @@ -3425,7 +3491,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
101487 char __user *uoptval;
101488 int err;
101489
101490 - uoptval = (char __user __force *) optval;
101491 + uoptval = (char __force_user *) optval;
101492
101493 set_fs(KERNEL_DS);
101494 if (level == SOL_SOCKET)
101495 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
101496 index 0f73f45..a96aa52 100644
101497 --- a/net/sunrpc/auth_gss/svcauth_gss.c
101498 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
101499 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101500 uint64_t *handle)
101501 {
101502 struct rsc rsci, *rscp = NULL;
101503 - static atomic64_t ctxhctr;
101504 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
101505 long long ctxh;
101506 struct gss_api_mech *gm = NULL;
101507 time_t expiry;
101508 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
101509 status = -ENOMEM;
101510 /* the handle needs to be just a unique id,
101511 * use a static counter */
101512 - ctxh = atomic64_inc_return(&ctxhctr);
101513 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
101514
101515 /* make a copy for the caller */
101516 *handle = ctxh;
101517 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
101518 index 0edada9..9247ea0 100644
101519 --- a/net/sunrpc/clnt.c
101520 +++ b/net/sunrpc/clnt.c
101521 @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
101522 (RPC_IS_ASYNC(task) ? "async" : "sync"));
101523
101524 /* Increment call count */
101525 - task->tk_msg.rpc_proc->p_count++;
101526 + pax_open_kernel();
101527 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
101528 + pax_close_kernel();
101529 clnt->cl_stats->rpccnt++;
101530 task->tk_action = call_reserve;
101531 }
101532 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
101533 index ff3cc4b..7612a9e 100644
101534 --- a/net/sunrpc/sched.c
101535 +++ b/net/sunrpc/sched.c
101536 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
101537 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
101538 static void rpc_task_set_debuginfo(struct rpc_task *task)
101539 {
101540 - static atomic_t rpc_pid;
101541 + static atomic_unchecked_t rpc_pid;
101542
101543 - task->tk_pid = atomic_inc_return(&rpc_pid);
101544 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
101545 }
101546 #else
101547 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
101548 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
101549 index 5de6801..b4e330d 100644
101550 --- a/net/sunrpc/svc.c
101551 +++ b/net/sunrpc/svc.c
101552 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
101553 svc_putnl(resv, RPC_SUCCESS);
101554
101555 /* Bump per-procedure stats counter */
101556 - procp->pc_count++;
101557 + pax_open_kernel();
101558 + (*(unsigned int *)&procp->pc_count)++;
101559 + pax_close_kernel();
101560
101561 /* Initialize storage for argp and resp */
101562 memset(rqstp->rq_argp, 0, procp->pc_argsize);
101563 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
101564 index 621ca7b..59421dd 100644
101565 --- a/net/sunrpc/svcauth_unix.c
101566 +++ b/net/sunrpc/svcauth_unix.c
101567 @@ -414,7 +414,7 @@ struct unix_gid {
101568 struct group_info *gi;
101569 };
101570
101571 -static int unix_gid_hash(kuid_t uid)
101572 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
101573 {
101574 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
101575 }
101576 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
101577 (*bpp)[-1] = '\n';
101578 }
101579
101580 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101581 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
101582
101583 static int unix_gid_parse(struct cache_detail *cd,
101584 char *mesg, int mlen)
101585 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
101586 index c1b6270..05089c1 100644
101587 --- a/net/sunrpc/xprtrdma/svc_rdma.c
101588 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
101589 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
101590 static unsigned int min_max_inline = 4096;
101591 static unsigned int max_max_inline = 65536;
101592
101593 -atomic_t rdma_stat_recv;
101594 -atomic_t rdma_stat_read;
101595 -atomic_t rdma_stat_write;
101596 -atomic_t rdma_stat_sq_starve;
101597 -atomic_t rdma_stat_rq_starve;
101598 -atomic_t rdma_stat_rq_poll;
101599 -atomic_t rdma_stat_rq_prod;
101600 -atomic_t rdma_stat_sq_poll;
101601 -atomic_t rdma_stat_sq_prod;
101602 +atomic_unchecked_t rdma_stat_recv;
101603 +atomic_unchecked_t rdma_stat_read;
101604 +atomic_unchecked_t rdma_stat_write;
101605 +atomic_unchecked_t rdma_stat_sq_starve;
101606 +atomic_unchecked_t rdma_stat_rq_starve;
101607 +atomic_unchecked_t rdma_stat_rq_poll;
101608 +atomic_unchecked_t rdma_stat_rq_prod;
101609 +atomic_unchecked_t rdma_stat_sq_poll;
101610 +atomic_unchecked_t rdma_stat_sq_prod;
101611
101612 /* Temporary NFS request map and context caches */
101613 struct kmem_cache *svc_rdma_map_cachep;
101614 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
101615 len -= *ppos;
101616 if (len > *lenp)
101617 len = *lenp;
101618 - if (len && copy_to_user(buffer, str_buf, len))
101619 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
101620 return -EFAULT;
101621 *lenp = len;
101622 *ppos += len;
101623 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
101624 {
101625 .procname = "rdma_stat_read",
101626 .data = &rdma_stat_read,
101627 - .maxlen = sizeof(atomic_t),
101628 + .maxlen = sizeof(atomic_unchecked_t),
101629 .mode = 0644,
101630 .proc_handler = read_reset_stat,
101631 },
101632 {
101633 .procname = "rdma_stat_recv",
101634 .data = &rdma_stat_recv,
101635 - .maxlen = sizeof(atomic_t),
101636 + .maxlen = sizeof(atomic_unchecked_t),
101637 .mode = 0644,
101638 .proc_handler = read_reset_stat,
101639 },
101640 {
101641 .procname = "rdma_stat_write",
101642 .data = &rdma_stat_write,
101643 - .maxlen = sizeof(atomic_t),
101644 + .maxlen = sizeof(atomic_unchecked_t),
101645 .mode = 0644,
101646 .proc_handler = read_reset_stat,
101647 },
101648 {
101649 .procname = "rdma_stat_sq_starve",
101650 .data = &rdma_stat_sq_starve,
101651 - .maxlen = sizeof(atomic_t),
101652 + .maxlen = sizeof(atomic_unchecked_t),
101653 .mode = 0644,
101654 .proc_handler = read_reset_stat,
101655 },
101656 {
101657 .procname = "rdma_stat_rq_starve",
101658 .data = &rdma_stat_rq_starve,
101659 - .maxlen = sizeof(atomic_t),
101660 + .maxlen = sizeof(atomic_unchecked_t),
101661 .mode = 0644,
101662 .proc_handler = read_reset_stat,
101663 },
101664 {
101665 .procname = "rdma_stat_rq_poll",
101666 .data = &rdma_stat_rq_poll,
101667 - .maxlen = sizeof(atomic_t),
101668 + .maxlen = sizeof(atomic_unchecked_t),
101669 .mode = 0644,
101670 .proc_handler = read_reset_stat,
101671 },
101672 {
101673 .procname = "rdma_stat_rq_prod",
101674 .data = &rdma_stat_rq_prod,
101675 - .maxlen = sizeof(atomic_t),
101676 + .maxlen = sizeof(atomic_unchecked_t),
101677 .mode = 0644,
101678 .proc_handler = read_reset_stat,
101679 },
101680 {
101681 .procname = "rdma_stat_sq_poll",
101682 .data = &rdma_stat_sq_poll,
101683 - .maxlen = sizeof(atomic_t),
101684 + .maxlen = sizeof(atomic_unchecked_t),
101685 .mode = 0644,
101686 .proc_handler = read_reset_stat,
101687 },
101688 {
101689 .procname = "rdma_stat_sq_prod",
101690 .data = &rdma_stat_sq_prod,
101691 - .maxlen = sizeof(atomic_t),
101692 + .maxlen = sizeof(atomic_unchecked_t),
101693 .mode = 0644,
101694 .proc_handler = read_reset_stat,
101695 },
101696 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101697 index 0ce7552..d074459 100644
101698 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101699 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
101700 @@ -501,7 +501,7 @@ next_sge:
101701 svc_rdma_put_context(ctxt, 0);
101702 goto out;
101703 }
101704 - atomic_inc(&rdma_stat_read);
101705 + atomic_inc_unchecked(&rdma_stat_read);
101706
101707 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
101708 chl_map->ch[ch_no].count -= read_wr.num_sge;
101709 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
101710 dto_q);
101711 list_del_init(&ctxt->dto_q);
101712 } else {
101713 - atomic_inc(&rdma_stat_rq_starve);
101714 + atomic_inc_unchecked(&rdma_stat_rq_starve);
101715 clear_bit(XPT_DATA, &xprt->xpt_flags);
101716 ctxt = NULL;
101717 }
101718 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
101719 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
101720 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
101721 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
101722 - atomic_inc(&rdma_stat_recv);
101723 + atomic_inc_unchecked(&rdma_stat_recv);
101724
101725 /* Build up the XDR from the receive buffers. */
101726 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
101727 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101728 index c1d124d..acfc59e 100644
101729 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101730 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
101731 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
101732 write_wr.wr.rdma.remote_addr = to;
101733
101734 /* Post It */
101735 - atomic_inc(&rdma_stat_write);
101736 + atomic_inc_unchecked(&rdma_stat_write);
101737 if (svc_rdma_send(xprt, &write_wr))
101738 goto err;
101739 return 0;
101740 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
101741 index 62e4f9b..dd3f2d7 100644
101742 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
101743 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
101744 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
101745 return;
101746
101747 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
101748 - atomic_inc(&rdma_stat_rq_poll);
101749 + atomic_inc_unchecked(&rdma_stat_rq_poll);
101750
101751 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
101752 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
101753 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
101754 }
101755
101756 if (ctxt)
101757 - atomic_inc(&rdma_stat_rq_prod);
101758 + atomic_inc_unchecked(&rdma_stat_rq_prod);
101759
101760 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
101761 /*
101762 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
101763 return;
101764
101765 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
101766 - atomic_inc(&rdma_stat_sq_poll);
101767 + atomic_inc_unchecked(&rdma_stat_sq_poll);
101768 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
101769 if (wc.status != IB_WC_SUCCESS)
101770 /* Close the transport */
101771 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
101772 }
101773
101774 if (ctxt)
101775 - atomic_inc(&rdma_stat_sq_prod);
101776 + atomic_inc_unchecked(&rdma_stat_sq_prod);
101777 }
101778
101779 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
101780 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
101781 spin_lock_bh(&xprt->sc_lock);
101782 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
101783 spin_unlock_bh(&xprt->sc_lock);
101784 - atomic_inc(&rdma_stat_sq_starve);
101785 + atomic_inc_unchecked(&rdma_stat_sq_starve);
101786
101787 /* See if we can opportunistically reap SQ WR to make room */
101788 sq_cq_reap(xprt);
101789 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
101790 index e7000be..e3b0ba7 100644
101791 --- a/net/sysctl_net.c
101792 +++ b/net/sysctl_net.c
101793 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
101794 kgid_t root_gid = make_kgid(net->user_ns, 0);
101795
101796 /* Allow network administrator to have same access as root. */
101797 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
101798 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
101799 uid_eq(root_uid, current_euid())) {
101800 int mode = (table->mode >> 6) & 7;
101801 return (mode << 6) | (mode << 3) | mode;
101802 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
101803 index 6424372..afd36e9 100644
101804 --- a/net/tipc/subscr.c
101805 +++ b/net/tipc/subscr.c
101806 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
101807 struct tipc_subscriber *subscriber = sub->subscriber;
101808 struct kvec msg_sect;
101809
101810 - msg_sect.iov_base = (void *)&sub->evt;
101811 + msg_sect.iov_base = &sub->evt;
101812 msg_sect.iov_len = sizeof(struct tipc_event);
101813 sub->evt.event = htohl(event, sub->swap);
101814 sub->evt.found_lower = htohl(found_lower, sub->swap);
101815 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
101816 index 94404f1..5782191 100644
101817 --- a/net/unix/af_unix.c
101818 +++ b/net/unix/af_unix.c
101819 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
101820 err = -ECONNREFUSED;
101821 if (!S_ISSOCK(inode->i_mode))
101822 goto put_fail;
101823 +
101824 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
101825 + err = -EACCES;
101826 + goto put_fail;
101827 + }
101828 +
101829 u = unix_find_socket_byinode(inode);
101830 if (!u)
101831 goto put_fail;
101832 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
101833 if (u) {
101834 struct dentry *dentry;
101835 dentry = unix_sk(u)->path.dentry;
101836 +
101837 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
101838 + err = -EPERM;
101839 + sock_put(u);
101840 + goto fail;
101841 + }
101842 +
101843 if (dentry)
101844 touch_atime(&unix_sk(u)->path);
101845 } else
101846 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
101847 */
101848 err = security_path_mknod(&path, dentry, mode, 0);
101849 if (!err) {
101850 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
101851 + err = -EACCES;
101852 + goto out;
101853 + }
101854 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
101855 if (!err) {
101856 res->mnt = mntget(path.mnt);
101857 res->dentry = dget(dentry);
101858 + gr_handle_create(dentry, path.mnt);
101859 }
101860 }
101861 +out:
101862 done_path_create(&path, dentry);
101863 return err;
101864 }
101865 @@ -2344,9 +2363,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
101866 seq_puts(seq, "Num RefCount Protocol Flags Type St "
101867 "Inode Path\n");
101868 else {
101869 - struct sock *s = v;
101870 + struct sock *s = v, *peer;
101871 struct unix_sock *u = unix_sk(s);
101872 unix_state_lock(s);
101873 + peer = unix_peer(s);
101874 + unix_state_unlock(s);
101875 +
101876 + unix_state_double_lock(s, peer);
101877
101878 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
101879 s,
101880 @@ -2373,8 +2396,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
101881 }
101882 for ( ; i < len; i++)
101883 seq_putc(seq, u->addr->name->sun_path[i]);
101884 - }
101885 - unix_state_unlock(s);
101886 + } else if (peer)
101887 + seq_printf(seq, " P%lu", sock_i_ino(peer));
101888 +
101889 + unix_state_double_unlock(s, peer);
101890 seq_putc(seq, '\n');
101891 }
101892
101893 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
101894 index b3d5150..ff3a837 100644
101895 --- a/net/unix/sysctl_net_unix.c
101896 +++ b/net/unix/sysctl_net_unix.c
101897 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
101898
101899 int __net_init unix_sysctl_register(struct net *net)
101900 {
101901 - struct ctl_table *table;
101902 + ctl_table_no_const *table;
101903
101904 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
101905 if (table == NULL)
101906 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
101907 index 9a73074..aecba9a 100644
101908 --- a/net/vmw_vsock/vmci_transport_notify.c
101909 +++ b/net/vmw_vsock/vmci_transport_notify.c
101910 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
101911
101912 /* Socket control packet based operations. */
101913 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
101914 - vmci_transport_notify_pkt_socket_init,
101915 - vmci_transport_notify_pkt_socket_destruct,
101916 - vmci_transport_notify_pkt_poll_in,
101917 - vmci_transport_notify_pkt_poll_out,
101918 - vmci_transport_notify_pkt_handle_pkt,
101919 - vmci_transport_notify_pkt_recv_init,
101920 - vmci_transport_notify_pkt_recv_pre_block,
101921 - vmci_transport_notify_pkt_recv_pre_dequeue,
101922 - vmci_transport_notify_pkt_recv_post_dequeue,
101923 - vmci_transport_notify_pkt_send_init,
101924 - vmci_transport_notify_pkt_send_pre_block,
101925 - vmci_transport_notify_pkt_send_pre_enqueue,
101926 - vmci_transport_notify_pkt_send_post_enqueue,
101927 - vmci_transport_notify_pkt_process_request,
101928 - vmci_transport_notify_pkt_process_negotiate,
101929 + .socket_init = vmci_transport_notify_pkt_socket_init,
101930 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
101931 + .poll_in = vmci_transport_notify_pkt_poll_in,
101932 + .poll_out = vmci_transport_notify_pkt_poll_out,
101933 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
101934 + .recv_init = vmci_transport_notify_pkt_recv_init,
101935 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
101936 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
101937 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
101938 + .send_init = vmci_transport_notify_pkt_send_init,
101939 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
101940 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
101941 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
101942 + .process_request = vmci_transport_notify_pkt_process_request,
101943 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
101944 };
101945 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
101946 index 622bd7a..b92086c 100644
101947 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
101948 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
101949 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
101950
101951 /* Socket always on control packet based operations. */
101952 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
101953 - vmci_transport_notify_pkt_socket_init,
101954 - vmci_transport_notify_pkt_socket_destruct,
101955 - vmci_transport_notify_pkt_poll_in,
101956 - vmci_transport_notify_pkt_poll_out,
101957 - vmci_transport_notify_pkt_handle_pkt,
101958 - vmci_transport_notify_pkt_recv_init,
101959 - vmci_transport_notify_pkt_recv_pre_block,
101960 - vmci_transport_notify_pkt_recv_pre_dequeue,
101961 - vmci_transport_notify_pkt_recv_post_dequeue,
101962 - vmci_transport_notify_pkt_send_init,
101963 - vmci_transport_notify_pkt_send_pre_block,
101964 - vmci_transport_notify_pkt_send_pre_enqueue,
101965 - vmci_transport_notify_pkt_send_post_enqueue,
101966 - vmci_transport_notify_pkt_process_request,
101967 - vmci_transport_notify_pkt_process_negotiate,
101968 + .socket_init = vmci_transport_notify_pkt_socket_init,
101969 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
101970 + .poll_in = vmci_transport_notify_pkt_poll_in,
101971 + .poll_out = vmci_transport_notify_pkt_poll_out,
101972 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
101973 + .recv_init = vmci_transport_notify_pkt_recv_init,
101974 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
101975 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
101976 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
101977 + .send_init = vmci_transport_notify_pkt_send_init,
101978 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
101979 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
101980 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
101981 + .process_request = vmci_transport_notify_pkt_process_request,
101982 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
101983 };
101984 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
101985 index c8717c1..08539f5 100644
101986 --- a/net/wireless/wext-core.c
101987 +++ b/net/wireless/wext-core.c
101988 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
101989 */
101990
101991 /* Support for very large requests */
101992 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
101993 - (user_length > descr->max_tokens)) {
101994 + if (user_length > descr->max_tokens) {
101995 /* Allow userspace to GET more than max so
101996 * we can support any size GET requests.
101997 * There is still a limit : -ENOMEM.
101998 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
101999 }
102000 }
102001
102002 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
102003 - /*
102004 - * If this is a GET, but not NOMAX, it means that the extra
102005 - * data is not bounded by userspace, but by max_tokens. Thus
102006 - * set the length to max_tokens. This matches the extra data
102007 - * allocation.
102008 - * The driver should fill it with the number of tokens it
102009 - * provided, and it may check iwp->length rather than having
102010 - * knowledge of max_tokens. If the driver doesn't change the
102011 - * iwp->length, this ioctl just copies back max_token tokens
102012 - * filled with zeroes. Hopefully the driver isn't claiming
102013 - * them to be valid data.
102014 - */
102015 - iwp->length = descr->max_tokens;
102016 - }
102017 -
102018 err = handler(dev, info, (union iwreq_data *) iwp, extra);
102019
102020 iwp->length += essid_compat;
102021 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
102022 index 4323952..a06dfe1 100644
102023 --- a/net/x25/sysctl_net_x25.c
102024 +++ b/net/x25/sysctl_net_x25.c
102025 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
102026 .mode = 0644,
102027 .proc_handler = proc_dointvec,
102028 },
102029 - { 0, },
102030 + { },
102031 };
102032
102033 void __init x25_register_sysctl(void)
102034 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
102035 index 1d5c7bf..f762f1f 100644
102036 --- a/net/xfrm/xfrm_policy.c
102037 +++ b/net/xfrm/xfrm_policy.c
102038 @@ -327,7 +327,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
102039 {
102040 policy->walk.dead = 1;
102041
102042 - atomic_inc(&policy->genid);
102043 + atomic_inc_unchecked(&policy->genid);
102044
102045 if (del_timer(&policy->polq.hold_timer))
102046 xfrm_pol_put(policy);
102047 @@ -661,7 +661,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
102048 hlist_add_head(&policy->bydst, chain);
102049 xfrm_pol_hold(policy);
102050 net->xfrm.policy_count[dir]++;
102051 - atomic_inc(&flow_cache_genid);
102052 + atomic_inc_unchecked(&flow_cache_genid);
102053
102054 /* After previous checking, family can either be AF_INET or AF_INET6 */
102055 if (policy->family == AF_INET)
102056 @@ -1761,7 +1761,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
102057
102058 xdst->num_pols = num_pols;
102059 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
102060 - xdst->policy_genid = atomic_read(&pols[0]->genid);
102061 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
102062
102063 return xdst;
102064 }
102065 @@ -2572,11 +2572,12 @@ void xfrm_garbage_collect(struct net *net)
102066 }
102067 EXPORT_SYMBOL(xfrm_garbage_collect);
102068
102069 -static void xfrm_garbage_collect_deferred(struct net *net)
102070 +void xfrm_garbage_collect_deferred(struct net *net)
102071 {
102072 flow_cache_flush_deferred();
102073 __xfrm_garbage_collect(net);
102074 }
102075 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
102076
102077 static void xfrm_init_pmtu(struct dst_entry *dst)
102078 {
102079 @@ -2626,7 +2627,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
102080 if (xdst->xfrm_genid != dst->xfrm->genid)
102081 return 0;
102082 if (xdst->num_pols > 0 &&
102083 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
102084 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
102085 return 0;
102086
102087 mtu = dst_mtu(dst->child);
102088 @@ -2714,8 +2715,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
102089 dst_ops->link_failure = xfrm_link_failure;
102090 if (likely(dst_ops->neigh_lookup == NULL))
102091 dst_ops->neigh_lookup = xfrm_neigh_lookup;
102092 - if (likely(afinfo->garbage_collect == NULL))
102093 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
102094 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
102095 }
102096 spin_unlock(&xfrm_policy_afinfo_lock);
102097 @@ -2769,7 +2768,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
102098 dst_ops->check = NULL;
102099 dst_ops->negative_advice = NULL;
102100 dst_ops->link_failure = NULL;
102101 - afinfo->garbage_collect = NULL;
102102 }
102103 return err;
102104 }
102105 @@ -3159,7 +3157,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
102106 sizeof(pol->xfrm_vec[i].saddr));
102107 pol->xfrm_vec[i].encap_family = mp->new_family;
102108 /* flush bundles */
102109 - atomic_inc(&pol->genid);
102110 + atomic_inc_unchecked(&pol->genid);
102111 }
102112 }
102113
102114 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
102115 index 40f1b3e..e33fdfa 100644
102116 --- a/net/xfrm/xfrm_state.c
102117 +++ b/net/xfrm/xfrm_state.c
102118 @@ -172,12 +172,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
102119
102120 if (unlikely(afinfo == NULL))
102121 return -EAFNOSUPPORT;
102122 - typemap = afinfo->type_map;
102123 + typemap = (const struct xfrm_type **)afinfo->type_map;
102124 spin_lock_bh(&xfrm_type_lock);
102125
102126 - if (likely(typemap[type->proto] == NULL))
102127 + if (likely(typemap[type->proto] == NULL)) {
102128 + pax_open_kernel();
102129 typemap[type->proto] = type;
102130 - else
102131 + pax_close_kernel();
102132 + } else
102133 err = -EEXIST;
102134 spin_unlock_bh(&xfrm_type_lock);
102135 xfrm_state_put_afinfo(afinfo);
102136 @@ -193,13 +195,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
102137
102138 if (unlikely(afinfo == NULL))
102139 return -EAFNOSUPPORT;
102140 - typemap = afinfo->type_map;
102141 + typemap = (const struct xfrm_type **)afinfo->type_map;
102142 spin_lock_bh(&xfrm_type_lock);
102143
102144 if (unlikely(typemap[type->proto] != type))
102145 err = -ENOENT;
102146 - else
102147 + else {
102148 + pax_open_kernel();
102149 typemap[type->proto] = NULL;
102150 + pax_close_kernel();
102151 + }
102152 spin_unlock_bh(&xfrm_type_lock);
102153 xfrm_state_put_afinfo(afinfo);
102154 return err;
102155 @@ -209,7 +214,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
102156 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
102157 {
102158 struct xfrm_state_afinfo *afinfo;
102159 - const struct xfrm_type **typemap;
102160 const struct xfrm_type *type;
102161 int modload_attempted = 0;
102162
102163 @@ -217,9 +221,8 @@ retry:
102164 afinfo = xfrm_state_get_afinfo(family);
102165 if (unlikely(afinfo == NULL))
102166 return NULL;
102167 - typemap = afinfo->type_map;
102168
102169 - type = typemap[proto];
102170 + type = afinfo->type_map[proto];
102171 if (unlikely(type && !try_module_get(type->owner)))
102172 type = NULL;
102173 if (!type && !modload_attempted) {
102174 @@ -253,7 +256,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102175 return -EAFNOSUPPORT;
102176
102177 err = -EEXIST;
102178 - modemap = afinfo->mode_map;
102179 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102180 spin_lock_bh(&xfrm_mode_lock);
102181 if (modemap[mode->encap])
102182 goto out;
102183 @@ -262,8 +265,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
102184 if (!try_module_get(afinfo->owner))
102185 goto out;
102186
102187 - mode->afinfo = afinfo;
102188 + pax_open_kernel();
102189 + *(const void **)&mode->afinfo = afinfo;
102190 modemap[mode->encap] = mode;
102191 + pax_close_kernel();
102192 err = 0;
102193
102194 out:
102195 @@ -287,10 +292,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
102196 return -EAFNOSUPPORT;
102197
102198 err = -ENOENT;
102199 - modemap = afinfo->mode_map;
102200 + modemap = (struct xfrm_mode **)afinfo->mode_map;
102201 spin_lock_bh(&xfrm_mode_lock);
102202 if (likely(modemap[mode->encap] == mode)) {
102203 + pax_open_kernel();
102204 modemap[mode->encap] = NULL;
102205 + pax_close_kernel();
102206 module_put(mode->afinfo->owner);
102207 err = 0;
102208 }
102209 @@ -1512,10 +1519,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
102210 u32 xfrm_get_acqseq(void)
102211 {
102212 u32 res;
102213 - static atomic_t acqseq;
102214 + static atomic_unchecked_t acqseq;
102215
102216 do {
102217 - res = atomic_inc_return(&acqseq);
102218 + res = atomic_inc_return_unchecked(&acqseq);
102219 } while (!res);
102220
102221 return res;
102222 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
102223 index 05a6e3d..6716ec9 100644
102224 --- a/net/xfrm/xfrm_sysctl.c
102225 +++ b/net/xfrm/xfrm_sysctl.c
102226 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
102227
102228 int __net_init xfrm_sysctl_init(struct net *net)
102229 {
102230 - struct ctl_table *table;
102231 + ctl_table_no_const *table;
102232
102233 __xfrm_sysctl_init(net);
102234
102235 diff --git a/scripts/Makefile b/scripts/Makefile
102236 index 01e7adb..6176d5d 100644
102237 --- a/scripts/Makefile
102238 +++ b/scripts/Makefile
102239 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
102240
102241 # Let clean descend into subdirs
102242 subdir- += basic kconfig package selinux
102243 +
102244 +clean-files := randstruct.seed
102245 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
102246 index d5d859c..781cbcb 100644
102247 --- a/scripts/Makefile.build
102248 +++ b/scripts/Makefile.build
102249 @@ -111,7 +111,7 @@ endif
102250 endif
102251
102252 # Do not include host rules unless needed
102253 -ifneq ($(hostprogs-y)$(hostprogs-m),)
102254 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
102255 include scripts/Makefile.host
102256 endif
102257
102258 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
102259 index 686cb0d..9d653bf 100644
102260 --- a/scripts/Makefile.clean
102261 +++ b/scripts/Makefile.clean
102262 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
102263 __clean-files := $(extra-y) $(always) \
102264 $(targets) $(clean-files) \
102265 $(host-progs) \
102266 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
102267 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
102268 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
102269
102270 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
102271
102272 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
102273 index 1ac414f..38575f7 100644
102274 --- a/scripts/Makefile.host
102275 +++ b/scripts/Makefile.host
102276 @@ -31,6 +31,8 @@
102277 # Note: Shared libraries consisting of C++ files are not supported
102278
102279 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
102280 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
102281 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
102282
102283 # C code
102284 # Executables compiled from a single .c file
102285 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
102286 # Shared libaries (only .c supported)
102287 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
102288 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
102289 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
102290 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
102291 # Remove .so files from "xxx-objs"
102292 host-cobjs := $(filter-out %.so,$(host-cobjs))
102293 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
102294
102295 -#Object (.o) files used by the shared libaries
102296 +# Object (.o) files used by the shared libaries
102297 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
102298 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
102299
102300 # output directory for programs/.o files
102301 # hostprogs-y := tools/build may have been specified. Retrieve directory
102302 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
102303 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
102304 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
102305 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
102306 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
102307 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
102308 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
102309 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
102310
102311 obj-dirs += $(host-objdirs)
102312 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
102313 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
102314 $(call if_changed_dep,host-cshobjs)
102315
102316 +# Compile .c file, create position independent .o file
102317 +# host-cxxshobjs -> .o
102318 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
102319 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
102320 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
102321 + $(call if_changed_dep,host-cxxshobjs)
102322 +
102323 # Link a shared library, based on position independent .o files
102324 # *.o -> .so shared library (host-cshlib)
102325 quiet_cmd_host-cshlib = HOSTLLD -shared $@
102326 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
102327 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
102328 $(call if_changed,host-cshlib)
102329
102330 +# Link a shared library, based on position independent .o files
102331 +# *.o -> .so shared library (host-cxxshlib)
102332 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
102333 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
102334 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
102335 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
102336 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
102337 + $(call if_changed,host-cxxshlib)
102338 +
102339 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
102340 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
102341 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
102342
102343 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
102344 index 078fe1d..fbdb363 100644
102345 --- a/scripts/basic/fixdep.c
102346 +++ b/scripts/basic/fixdep.c
102347 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
102348 /*
102349 * Lookup a value in the configuration string.
102350 */
102351 -static int is_defined_config(const char *name, int len, unsigned int hash)
102352 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
102353 {
102354 struct item *aux;
102355
102356 @@ -211,10 +211,10 @@ static void clear_config(void)
102357 /*
102358 * Record the use of a CONFIG_* word.
102359 */
102360 -static void use_config(const char *m, int slen)
102361 +static void use_config(const char *m, unsigned int slen)
102362 {
102363 unsigned int hash = strhash(m, slen);
102364 - int c, i;
102365 + unsigned int c, i;
102366
102367 if (is_defined_config(m, slen, hash))
102368 return;
102369 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
102370
102371 static void parse_config_file(const char *map, size_t len)
102372 {
102373 - const int *end = (const int *) (map + len);
102374 + const unsigned int *end = (const unsigned int *) (map + len);
102375 /* start at +1, so that p can never be < map */
102376 - const int *m = (const int *) map + 1;
102377 + const unsigned int *m = (const unsigned int *) map + 1;
102378 const char *p, *q;
102379
102380 for (; m < end; m++) {
102381 @@ -435,7 +435,7 @@ static void print_deps(void)
102382 static void traps(void)
102383 {
102384 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
102385 - int *p = (int *)test;
102386 + unsigned int *p = (unsigned int *)test;
102387
102388 if (*p != INT_CONF) {
102389 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
102390 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
102391 new file mode 100644
102392 index 0000000..edcbc3a
102393 --- /dev/null
102394 +++ b/scripts/gcc-plugin.sh
102395 @@ -0,0 +1,16 @@
102396 +#!/bin/bash
102397 +srctree=$(dirname "$0")
102398 +gccplugins_dir=$($3 -print-file-name=plugin)
102399 +plugincc=$($1 -E -shared - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
102400 +#include "gcc-common.h"
102401 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
102402 +#warning $2
102403 +#else
102404 +#warning $1
102405 +#endif
102406 +EOF
102407 +)
102408 +if [ $? -eq 0 ]
102409 +then
102410 + ( [[ "$plugincc" =~ "$1" ]] && echo "$1" ) || ( [[ "$plugincc" =~ "$2" ]] && echo "$2" )
102411 +fi
102412 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
102413 index 5de5660..d3deb89 100644
102414 --- a/scripts/headers_install.sh
102415 +++ b/scripts/headers_install.sh
102416 @@ -32,6 +32,7 @@ do
102417 FILE="$(basename "$i")"
102418 sed -r \
102419 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
102420 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
102421 -e 's/__attribute_const__([ \t]|$)/\1/g' \
102422 -e 's@^#include <linux/compiler.h>@@' \
102423 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
102424 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
102425 index 2dcb377..a82c500 100644
102426 --- a/scripts/link-vmlinux.sh
102427 +++ b/scripts/link-vmlinux.sh
102428 @@ -162,7 +162,7 @@ else
102429 fi;
102430
102431 # final build of init/
102432 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
102433 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
102434
102435 kallsymso=""
102436 kallsyms_vmlinux=""
102437 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
102438 index 25e5cb0..6e85821 100644
102439 --- a/scripts/mod/file2alias.c
102440 +++ b/scripts/mod/file2alias.c
102441 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
102442 unsigned long size, unsigned long id_size,
102443 void *symval)
102444 {
102445 - int i;
102446 + unsigned int i;
102447
102448 if (size % id_size || size < id_size) {
102449 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
102450 @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
102451 /* USB is special because the bcdDevice can be matched against a numeric range */
102452 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
102453 static void do_usb_entry(void *symval,
102454 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
102455 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
102456 unsigned char range_lo, unsigned char range_hi,
102457 unsigned char max, struct module *mod)
102458 {
102459 @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
102460 {
102461 unsigned int devlo, devhi;
102462 unsigned char chi, clo, max;
102463 - int ndigits;
102464 + unsigned int ndigits;
102465
102466 DEF_FIELD(symval, usb_device_id, match_flags);
102467 DEF_FIELD(symval, usb_device_id, idVendor);
102468 @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
102469 for (i = 0; i < count; i++) {
102470 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
102471 char acpi_id[sizeof(*id)];
102472 - int j;
102473 + unsigned int j;
102474
102475 buf_printf(&mod->dev_table_buf,
102476 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
102477 @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102478
102479 for (j = 0; j < PNP_MAX_DEVICES; j++) {
102480 const char *id = (char *)(*devs)[j].id;
102481 - int i2, j2;
102482 + unsigned int i2, j2;
102483 int dup = 0;
102484
102485 if (!id[0])
102486 @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
102487 /* add an individual alias for every device entry */
102488 if (!dup) {
102489 char acpi_id[PNP_ID_LEN];
102490 - int k;
102491 + unsigned int k;
102492
102493 buf_printf(&mod->dev_table_buf,
102494 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
102495 @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
102496 static int do_dmi_entry(const char *filename, void *symval,
102497 char *alias)
102498 {
102499 - int i, j;
102500 + unsigned int i, j;
102501 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
102502 sprintf(alias, "dmi*");
102503
102504 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
102505 index 99a45fd..4b995a3 100644
102506 --- a/scripts/mod/modpost.c
102507 +++ b/scripts/mod/modpost.c
102508 @@ -945,6 +945,7 @@ enum mismatch {
102509 ANY_INIT_TO_ANY_EXIT,
102510 ANY_EXIT_TO_ANY_INIT,
102511 EXPORT_TO_INIT_EXIT,
102512 + DATA_TO_TEXT
102513 };
102514
102515 struct sectioncheck {
102516 @@ -1031,6 +1032,12 @@ const struct sectioncheck sectioncheck[] = {
102517 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
102518 .mismatch = EXPORT_TO_INIT_EXIT,
102519 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
102520 +},
102521 +/* Do not reference code from writable data */
102522 +{
102523 + .fromsec = { DATA_SECTIONS, NULL },
102524 + .tosec = { TEXT_SECTIONS, NULL },
102525 + .mismatch = DATA_TO_TEXT
102526 }
102527 };
102528
102529 @@ -1151,10 +1158,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
102530 continue;
102531 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
102532 continue;
102533 - if (sym->st_value == addr)
102534 - return sym;
102535 /* Find a symbol nearby - addr are maybe negative */
102536 d = sym->st_value - addr;
102537 + if (d == 0)
102538 + return sym;
102539 if (d < 0)
102540 d = addr - sym->st_value;
102541 if (d < distance) {
102542 @@ -1432,6 +1439,14 @@ static void report_sec_mismatch(const char *modname,
102543 tosym, prl_to, prl_to, tosym);
102544 free(prl_to);
102545 break;
102546 + case DATA_TO_TEXT:
102547 +#if 0
102548 + fprintf(stderr,
102549 + "The %s %s:%s references\n"
102550 + "the %s %s:%s%s\n",
102551 + from, fromsec, fromsym, to, tosec, tosym, to_p);
102552 +#endif
102553 + break;
102554 }
102555 fprintf(stderr, "\n");
102556 }
102557 @@ -1679,7 +1694,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
102558 static void check_sec_ref(struct module *mod, const char *modname,
102559 struct elf_info *elf)
102560 {
102561 - int i;
102562 + unsigned int i;
102563 Elf_Shdr *sechdrs = elf->sechdrs;
102564
102565 /* Walk through all sections */
102566 @@ -1798,7 +1813,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
102567 va_end(ap);
102568 }
102569
102570 -void buf_write(struct buffer *buf, const char *s, int len)
102571 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
102572 {
102573 if (buf->size - buf->pos < len) {
102574 buf->size += len + SZ;
102575 @@ -2017,7 +2032,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
102576 if (fstat(fileno(file), &st) < 0)
102577 goto close_write;
102578
102579 - if (st.st_size != b->pos)
102580 + if (st.st_size != (off_t)b->pos)
102581 goto close_write;
102582
102583 tmp = NOFAIL(malloc(b->pos));
102584 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
102585 index 51207e4..f7d603d 100644
102586 --- a/scripts/mod/modpost.h
102587 +++ b/scripts/mod/modpost.h
102588 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
102589
102590 struct buffer {
102591 char *p;
102592 - int pos;
102593 - int size;
102594 + unsigned int pos;
102595 + unsigned int size;
102596 };
102597
102598 void __attribute__((format(printf, 2, 3)))
102599 buf_printf(struct buffer *buf, const char *fmt, ...);
102600
102601 void
102602 -buf_write(struct buffer *buf, const char *s, int len);
102603 +buf_write(struct buffer *buf, const char *s, unsigned int len);
102604
102605 struct module {
102606 struct module *next;
102607 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
102608 index deb2994..af4f63e 100644
102609 --- a/scripts/mod/sumversion.c
102610 +++ b/scripts/mod/sumversion.c
102611 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
102612 goto out;
102613 }
102614
102615 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
102616 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
102617 warn("writing sum in %s failed: %s\n",
102618 filename, strerror(errno));
102619 goto out;
102620 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
102621 index 0865b3e..7235dd4 100644
102622 --- a/scripts/module-common.lds
102623 +++ b/scripts/module-common.lds
102624 @@ -6,6 +6,10 @@
102625 SECTIONS {
102626 /DISCARD/ : { *(.discard) }
102627
102628 + .rodata : {
102629 + *(.rodata) *(.rodata.*)
102630 + *(.data..read_only)
102631 + }
102632 __ksymtab : { *(SORT(___ksymtab+*)) }
102633 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
102634 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
102635 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
102636 index f46e4dd..090e168 100644
102637 --- a/scripts/package/builddeb
102638 +++ b/scripts/package/builddeb
102639 @@ -291,6 +291,7 @@ fi
102640 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
102641 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
102642 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
102643 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
102644 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
102645 mkdir -p "$destdir"
102646 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
102647 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
102648 index 68bb4ef..2f419e1 100644
102649 --- a/scripts/pnmtologo.c
102650 +++ b/scripts/pnmtologo.c
102651 @@ -244,14 +244,14 @@ static void write_header(void)
102652 fprintf(out, " * Linux logo %s\n", logoname);
102653 fputs(" */\n\n", out);
102654 fputs("#include <linux/linux_logo.h>\n\n", out);
102655 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
102656 + fprintf(out, "static unsigned char %s_data[] = {\n",
102657 logoname);
102658 }
102659
102660 static void write_footer(void)
102661 {
102662 fputs("\n};\n\n", out);
102663 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
102664 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
102665 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
102666 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
102667 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
102668 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
102669 fputs("\n};\n\n", out);
102670
102671 /* write logo clut */
102672 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
102673 + fprintf(out, "static unsigned char %s_clut[] = {\n",
102674 logoname);
102675 write_hex_cnt = 0;
102676 for (i = 0; i < logo_clutsize; i++) {
102677 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
102678 index 8fac3fd..32ff38d 100644
102679 --- a/scripts/sortextable.h
102680 +++ b/scripts/sortextable.h
102681 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
102682 const char *secstrtab;
102683 const char *strtab;
102684 char *extab_image;
102685 - int extab_index = 0;
102686 - int i;
102687 - int idx;
102688 + unsigned int extab_index = 0;
102689 + unsigned int i;
102690 + unsigned int idx;
102691 unsigned int num_sections;
102692 unsigned int secindex_strings;
102693
102694 diff --git a/security/Kconfig b/security/Kconfig
102695 index beb86b5..6ec5984 100644
102696 --- a/security/Kconfig
102697 +++ b/security/Kconfig
102698 @@ -4,6 +4,960 @@
102699
102700 menu "Security options"
102701
102702 +menu "Grsecurity"
102703 +
102704 + config ARCH_TRACK_EXEC_LIMIT
102705 + bool
102706 +
102707 + config PAX_KERNEXEC_PLUGIN
102708 + bool
102709 +
102710 + config PAX_PER_CPU_PGD
102711 + bool
102712 +
102713 + config TASK_SIZE_MAX_SHIFT
102714 + int
102715 + depends on X86_64
102716 + default 47 if !PAX_PER_CPU_PGD
102717 + default 42 if PAX_PER_CPU_PGD
102718 +
102719 + config PAX_ENABLE_PAE
102720 + bool
102721 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
102722 +
102723 + config PAX_USERCOPY_SLABS
102724 + bool
102725 +
102726 +config GRKERNSEC
102727 + bool "Grsecurity"
102728 + select CRYPTO
102729 + select CRYPTO_SHA256
102730 + select PROC_FS
102731 + select STOP_MACHINE
102732 + select TTY
102733 + select DEBUG_KERNEL
102734 + select DEBUG_LIST
102735 + help
102736 + If you say Y here, you will be able to configure many features
102737 + that will enhance the security of your system. It is highly
102738 + recommended that you say Y here and read through the help
102739 + for each option so that you fully understand the features and
102740 + can evaluate their usefulness for your machine.
102741 +
102742 +choice
102743 + prompt "Configuration Method"
102744 + depends on GRKERNSEC
102745 + default GRKERNSEC_CONFIG_CUSTOM
102746 + help
102747 +
102748 +config GRKERNSEC_CONFIG_AUTO
102749 + bool "Automatic"
102750 + help
102751 + If you choose this configuration method, you'll be able to answer a small
102752 + number of simple questions about how you plan to use this kernel.
102753 + The settings of grsecurity and PaX will be automatically configured for
102754 + the highest commonly-used settings within the provided constraints.
102755 +
102756 + If you require additional configuration, custom changes can still be made
102757 + from the "custom configuration" menu.
102758 +
102759 +config GRKERNSEC_CONFIG_CUSTOM
102760 + bool "Custom"
102761 + help
102762 + If you choose this configuration method, you'll be able to configure all
102763 + grsecurity and PaX settings manually. Via this method, no options are
102764 + automatically enabled.
102765 +
102766 +endchoice
102767 +
102768 +choice
102769 + prompt "Usage Type"
102770 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
102771 + default GRKERNSEC_CONFIG_SERVER
102772 + help
102773 +
102774 +config GRKERNSEC_CONFIG_SERVER
102775 + bool "Server"
102776 + help
102777 + Choose this option if you plan to use this kernel on a server.
102778 +
102779 +config GRKERNSEC_CONFIG_DESKTOP
102780 + bool "Desktop"
102781 + help
102782 + Choose this option if you plan to use this kernel on a desktop.
102783 +
102784 +endchoice
102785 +
102786 +choice
102787 + prompt "Virtualization Type"
102788 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
102789 + default GRKERNSEC_CONFIG_VIRT_NONE
102790 + help
102791 +
102792 +config GRKERNSEC_CONFIG_VIRT_NONE
102793 + bool "None"
102794 + help
102795 + Choose this option if this kernel will be run on bare metal.
102796 +
102797 +config GRKERNSEC_CONFIG_VIRT_GUEST
102798 + bool "Guest"
102799 + help
102800 + Choose this option if this kernel will be run as a VM guest.
102801 +
102802 +config GRKERNSEC_CONFIG_VIRT_HOST
102803 + bool "Host"
102804 + help
102805 + Choose this option if this kernel will be run as a VM host.
102806 +
102807 +endchoice
102808 +
102809 +choice
102810 + prompt "Virtualization Hardware"
102811 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
102812 + help
102813 +
102814 +config GRKERNSEC_CONFIG_VIRT_EPT
102815 + bool "EPT/RVI Processor Support"
102816 + depends on X86
102817 + help
102818 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
102819 + hardware virtualization. This allows for additional kernel hardening protections
102820 + to operate without additional performance impact.
102821 +
102822 + To see if your Intel processor supports EPT, see:
102823 + http://ark.intel.com/Products/VirtualizationTechnology
102824 + (Most Core i3/5/7 support EPT)
102825 +
102826 + To see if your AMD processor supports RVI, see:
102827 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
102828 +
102829 +config GRKERNSEC_CONFIG_VIRT_SOFT
102830 + bool "First-gen/No Hardware Virtualization"
102831 + help
102832 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
102833 + support hardware virtualization or doesn't support the EPT/RVI extensions.
102834 +
102835 +endchoice
102836 +
102837 +choice
102838 + prompt "Virtualization Software"
102839 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
102840 + help
102841 +
102842 +config GRKERNSEC_CONFIG_VIRT_XEN
102843 + bool "Xen"
102844 + help
102845 + Choose this option if this kernel is running as a Xen guest or host.
102846 +
102847 +config GRKERNSEC_CONFIG_VIRT_VMWARE
102848 + bool "VMWare"
102849 + help
102850 + Choose this option if this kernel is running as a VMWare guest or host.
102851 +
102852 +config GRKERNSEC_CONFIG_VIRT_KVM
102853 + bool "KVM"
102854 + help
102855 + Choose this option if this kernel is running as a KVM guest or host.
102856 +
102857 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
102858 + bool "VirtualBox"
102859 + help
102860 + Choose this option if this kernel is running as a VirtualBox guest or host.
102861 +
102862 +endchoice
102863 +
102864 +choice
102865 + prompt "Required Priorities"
102866 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
102867 + default GRKERNSEC_CONFIG_PRIORITY_PERF
102868 + help
102869 +
102870 +config GRKERNSEC_CONFIG_PRIORITY_PERF
102871 + bool "Performance"
102872 + help
102873 + Choose this option if performance is of highest priority for this deployment
102874 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
102875 + clearing of structures intended for userland, and freed memory sanitizing will
102876 + be disabled.
102877 +
102878 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
102879 + bool "Security"
102880 + help
102881 + Choose this option if security is of highest priority for this deployment of
102882 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
102883 + for userland, and freed memory sanitizing will be enabled for this kernel.
102884 + In a worst-case scenario, these features can introduce a 20% performance hit
102885 + (UDEREF on x64 contributing half of this hit).
102886 +
102887 +endchoice
102888 +
102889 +menu "Default Special Groups"
102890 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
102891 +
102892 +config GRKERNSEC_PROC_GID
102893 + int "GID exempted from /proc restrictions"
102894 + default 1001
102895 + help
102896 + Setting this GID determines which group will be exempted from
102897 + grsecurity's /proc restrictions, allowing users of the specified
102898 + group to view network statistics and the existence of other users'
102899 + processes on the system. This GID may also be chosen at boot time
102900 + via "grsec_proc_gid=" on the kernel commandline.
102901 +
102902 +config GRKERNSEC_TPE_UNTRUSTED_GID
102903 + int "GID for TPE-untrusted users"
102904 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
102905 + default 1005
102906 + help
102907 + Setting this GID determines which group untrusted users should
102908 + be added to. These users will be placed under grsecurity's Trusted Path
102909 + Execution mechanism, preventing them from executing their own binaries.
102910 + The users will only be able to execute binaries in directories owned and
102911 + writable only by the root user. If the sysctl option is enabled, a sysctl
102912 + option with name "tpe_gid" is created.
102913 +
102914 +config GRKERNSEC_TPE_TRUSTED_GID
102915 + int "GID for TPE-trusted users"
102916 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
102917 + default 1005
102918 + help
102919 + Setting this GID determines what group TPE restrictions will be
102920 + *disabled* for. If the sysctl option is enabled, a sysctl option
102921 + with name "tpe_gid" is created.
102922 +
102923 +config GRKERNSEC_SYMLINKOWN_GID
102924 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
102925 + depends on GRKERNSEC_CONFIG_SERVER
102926 + default 1006
102927 + help
102928 + Setting this GID determines what group kernel-enforced
102929 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
102930 + is enabled, a sysctl option with name "symlinkown_gid" is created.
102931 +
102932 +
102933 +endmenu
102934 +
102935 +menu "Customize Configuration"
102936 +depends on GRKERNSEC
102937 +
102938 +menu "PaX"
102939 +
102940 +config PAX
102941 + bool "Enable various PaX features"
102942 + default y if GRKERNSEC_CONFIG_AUTO
102943 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
102944 + help
102945 + This allows you to enable various PaX features. PaX adds
102946 + intrusion prevention mechanisms to the kernel that reduce
102947 + the risks posed by exploitable memory corruption bugs.
102948 +
102949 +menu "PaX Control"
102950 + depends on PAX
102951 +
102952 +config PAX_SOFTMODE
102953 + bool 'Support soft mode'
102954 + help
102955 + Enabling this option will allow you to run PaX in soft mode, that
102956 + is, PaX features will not be enforced by default, only on executables
102957 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
102958 + support as they are the only way to mark executables for soft mode use.
102959 +
102960 + Soft mode can be activated by using the "pax_softmode=1" kernel command
102961 + line option on boot. Furthermore you can control various PaX features
102962 + at runtime via the entries in /proc/sys/kernel/pax.
102963 +
102964 +config PAX_EI_PAX
102965 + bool 'Use legacy ELF header marking'
102966 + default y if GRKERNSEC_CONFIG_AUTO
102967 + help
102968 + Enabling this option will allow you to control PaX features on
102969 + a per executable basis via the 'chpax' utility available at
102970 + http://pax.grsecurity.net/. The control flags will be read from
102971 + an otherwise reserved part of the ELF header. This marking has
102972 + numerous drawbacks (no support for soft-mode, toolchain does not
102973 + know about the non-standard use of the ELF header) therefore it
102974 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
102975 + support.
102976 +
102977 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
102978 + support as well, they will override the legacy EI_PAX marks.
102979 +
102980 + If you enable none of the marking options then all applications
102981 + will run with PaX enabled on them by default.
102982 +
102983 +config PAX_PT_PAX_FLAGS
102984 + bool 'Use ELF program header marking'
102985 + default y if GRKERNSEC_CONFIG_AUTO
102986 + help
102987 + Enabling this option will allow you to control PaX features on
102988 + a per executable basis via the 'paxctl' utility available at
102989 + http://pax.grsecurity.net/. The control flags will be read from
102990 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
102991 + has the benefits of supporting both soft mode and being fully
102992 + integrated into the toolchain (the binutils patch is available
102993 + from http://pax.grsecurity.net).
102994 +
102995 + Note that if you enable the legacy EI_PAX marking support as well,
102996 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
102997 +
102998 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
102999 + must make sure that the marks are the same if a binary has both marks.
103000 +
103001 + If you enable none of the marking options then all applications
103002 + will run with PaX enabled on them by default.
103003 +
103004 +config PAX_XATTR_PAX_FLAGS
103005 + bool 'Use filesystem extended attributes marking'
103006 + default y if GRKERNSEC_CONFIG_AUTO
103007 + select CIFS_XATTR if CIFS
103008 + select EXT2_FS_XATTR if EXT2_FS
103009 + select EXT3_FS_XATTR if EXT3_FS
103010 + select JFFS2_FS_XATTR if JFFS2_FS
103011 + select REISERFS_FS_XATTR if REISERFS_FS
103012 + select SQUASHFS_XATTR if SQUASHFS
103013 + select TMPFS_XATTR if TMPFS
103014 + select UBIFS_FS_XATTR if UBIFS_FS
103015 + help
103016 + Enabling this option will allow you to control PaX features on
103017 + a per executable basis via the 'setfattr' utility. The control
103018 + flags will be read from the user.pax.flags extended attribute of
103019 + the file. This marking has the benefit of supporting binary-only
103020 + applications that self-check themselves (e.g., skype) and would
103021 + not tolerate chpax/paxctl changes. The main drawback is that
103022 + extended attributes are not supported by some filesystems (e.g.,
103023 + isofs, udf, vfat) so copying files through such filesystems will
103024 + lose the extended attributes and these PaX markings.
103025 +
103026 + Note that if you enable the legacy EI_PAX marking support as well,
103027 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
103028 +
103029 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
103030 + must make sure that the marks are the same if a binary has both marks.
103031 +
103032 + If you enable none of the marking options then all applications
103033 + will run with PaX enabled on them by default.
103034 +
103035 +choice
103036 + prompt 'MAC system integration'
103037 + default PAX_HAVE_ACL_FLAGS
103038 + help
103039 + Mandatory Access Control systems have the option of controlling
103040 + PaX flags on a per executable basis, choose the method supported
103041 + by your particular system.
103042 +
103043 + - "none": if your MAC system does not interact with PaX,
103044 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
103045 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
103046 +
103047 + NOTE: this option is for developers/integrators only.
103048 +
103049 + config PAX_NO_ACL_FLAGS
103050 + bool 'none'
103051 +
103052 + config PAX_HAVE_ACL_FLAGS
103053 + bool 'direct'
103054 +
103055 + config PAX_HOOK_ACL_FLAGS
103056 + bool 'hook'
103057 +endchoice
103058 +
103059 +endmenu
103060 +
103061 +menu "Non-executable pages"
103062 + depends on PAX
103063 +
103064 +config PAX_NOEXEC
103065 + bool "Enforce non-executable pages"
103066 + default y if GRKERNSEC_CONFIG_AUTO
103067 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
103068 + help
103069 + By design some architectures do not allow for protecting memory
103070 + pages against execution or even if they do, Linux does not make
103071 + use of this feature. In practice this means that if a page is
103072 + readable (such as the stack or heap) it is also executable.
103073 +
103074 + There is a well known exploit technique that makes use of this
103075 + fact and a common programming mistake where an attacker can
103076 + introduce code of his choice somewhere in the attacked program's
103077 + memory (typically the stack or the heap) and then execute it.
103078 +
103079 + If the attacked program was running with different (typically
103080 + higher) privileges than that of the attacker, then he can elevate
103081 + his own privilege level (e.g. get a root shell, write to files for
103082 + which he does not have write access to, etc).
103083 +
103084 + Enabling this option will let you choose from various features
103085 + that prevent the injection and execution of 'foreign' code in
103086 + a program.
103087 +
103088 + This will also break programs that rely on the old behaviour and
103089 + expect that dynamically allocated memory via the malloc() family
103090 + of functions is executable (which it is not). Notable examples
103091 + are the XFree86 4.x server, the java runtime and wine.
103092 +
103093 +config PAX_PAGEEXEC
103094 + bool "Paging based non-executable pages"
103095 + default y if GRKERNSEC_CONFIG_AUTO
103096 + 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)
103097 + select ARCH_TRACK_EXEC_LIMIT if X86_32
103098 + help
103099 + This implementation is based on the paging feature of the CPU.
103100 + On i386 without hardware non-executable bit support there is a
103101 + variable but usually low performance impact, however on Intel's
103102 + P4 core based CPUs it is very high so you should not enable this
103103 + for kernels meant to be used on such CPUs.
103104 +
103105 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
103106 + with hardware non-executable bit support there is no performance
103107 + impact, on ppc the impact is negligible.
103108 +
103109 + Note that several architectures require various emulations due to
103110 + badly designed userland ABIs, this will cause a performance impact
103111 + but will disappear as soon as userland is fixed. For example, ppc
103112 + userland MUST have been built with secure-plt by a recent toolchain.
103113 +
103114 +config PAX_SEGMEXEC
103115 + bool "Segmentation based non-executable pages"
103116 + default y if GRKERNSEC_CONFIG_AUTO
103117 + depends on PAX_NOEXEC && X86_32
103118 + help
103119 + This implementation is based on the segmentation feature of the
103120 + CPU and has a very small performance impact, however applications
103121 + will be limited to a 1.5 GB address space instead of the normal
103122 + 3 GB.
103123 +
103124 +config PAX_EMUTRAMP
103125 + bool "Emulate trampolines"
103126 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
103127 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
103128 + help
103129 + There are some programs and libraries that for one reason or
103130 + another attempt to execute special small code snippets from
103131 + non-executable memory pages. Most notable examples are the
103132 + signal handler return code generated by the kernel itself and
103133 + the GCC trampolines.
103134 +
103135 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
103136 + such programs will no longer work under your kernel.
103137 +
103138 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
103139 + utilities to enable trampoline emulation for the affected programs
103140 + yet still have the protection provided by the non-executable pages.
103141 +
103142 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
103143 + your system will not even boot.
103144 +
103145 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
103146 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
103147 + for the affected files.
103148 +
103149 + NOTE: enabling this feature *may* open up a loophole in the
103150 + protection provided by non-executable pages that an attacker
103151 + could abuse. Therefore the best solution is to not have any
103152 + files on your system that would require this option. This can
103153 + be achieved by not using libc5 (which relies on the kernel
103154 + signal handler return code) and not using or rewriting programs
103155 + that make use of the nested function implementation of GCC.
103156 + Skilled users can just fix GCC itself so that it implements
103157 + nested function calls in a way that does not interfere with PaX.
103158 +
103159 +config PAX_EMUSIGRT
103160 + bool "Automatically emulate sigreturn trampolines"
103161 + depends on PAX_EMUTRAMP && PARISC
103162 + default y
103163 + help
103164 + Enabling this option will have the kernel automatically detect
103165 + and emulate signal return trampolines executing on the stack
103166 + that would otherwise lead to task termination.
103167 +
103168 + This solution is intended as a temporary one for users with
103169 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
103170 + Modula-3 runtime, etc) or executables linked to such, basically
103171 + everything that does not specify its own SA_RESTORER function in
103172 + normal executable memory like glibc 2.1+ does.
103173 +
103174 + On parisc you MUST enable this option, otherwise your system will
103175 + not even boot.
103176 +
103177 + NOTE: this feature cannot be disabled on a per executable basis
103178 + and since it *does* open up a loophole in the protection provided
103179 + by non-executable pages, the best solution is to not have any
103180 + files on your system that would require this option.
103181 +
103182 +config PAX_MPROTECT
103183 + bool "Restrict mprotect()"
103184 + default y if GRKERNSEC_CONFIG_AUTO
103185 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
103186 + help
103187 + Enabling this option will prevent programs from
103188 + - changing the executable status of memory pages that were
103189 + not originally created as executable,
103190 + - making read-only executable pages writable again,
103191 + - creating executable pages from anonymous memory,
103192 + - making read-only-after-relocations (RELRO) data pages writable again.
103193 +
103194 + You should say Y here to complete the protection provided by
103195 + the enforcement of non-executable pages.
103196 +
103197 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103198 + this feature on a per file basis.
103199 +
103200 +config PAX_MPROTECT_COMPAT
103201 + bool "Use legacy/compat protection demoting (read help)"
103202 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103203 + depends on PAX_MPROTECT
103204 + help
103205 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
103206 + by sending the proper error code to the application. For some broken
103207 + userland, this can cause problems with Python or other applications. The
103208 + current implementation however allows for applications like clamav to
103209 + detect if JIT compilation/execution is allowed and to fall back gracefully
103210 + to an interpreter-based mode if it does not. While we encourage everyone
103211 + to use the current implementation as-is and push upstream to fix broken
103212 + userland (note that the RWX logging option can assist with this), in some
103213 + environments this may not be possible. Having to disable MPROTECT
103214 + completely on certain binaries reduces the security benefit of PaX,
103215 + so this option is provided for those environments to revert to the old
103216 + behavior.
103217 +
103218 +config PAX_ELFRELOCS
103219 + bool "Allow ELF text relocations (read help)"
103220 + depends on PAX_MPROTECT
103221 + default n
103222 + help
103223 + Non-executable pages and mprotect() restrictions are effective
103224 + in preventing the introduction of new executable code into an
103225 + attacked task's address space. There remain only two venues
103226 + for this kind of attack: if the attacker can execute already
103227 + existing code in the attacked task then he can either have it
103228 + create and mmap() a file containing his code or have it mmap()
103229 + an already existing ELF library that does not have position
103230 + independent code in it and use mprotect() on it to make it
103231 + writable and copy his code there. While protecting against
103232 + the former approach is beyond PaX, the latter can be prevented
103233 + by having only PIC ELF libraries on one's system (which do not
103234 + need to relocate their code). If you are sure this is your case,
103235 + as is the case with all modern Linux distributions, then leave
103236 + this option disabled. You should say 'n' here.
103237 +
103238 +config PAX_ETEXECRELOCS
103239 + bool "Allow ELF ET_EXEC text relocations"
103240 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
103241 + select PAX_ELFRELOCS
103242 + default y
103243 + help
103244 + On some architectures there are incorrectly created applications
103245 + that require text relocations and would not work without enabling
103246 + this option. If you are an alpha, ia64 or parisc user, you should
103247 + enable this option and disable it once you have made sure that
103248 + none of your applications need it.
103249 +
103250 +config PAX_EMUPLT
103251 + bool "Automatically emulate ELF PLT"
103252 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
103253 + default y
103254 + help
103255 + Enabling this option will have the kernel automatically detect
103256 + and emulate the Procedure Linkage Table entries in ELF files.
103257 + On some architectures such entries are in writable memory, and
103258 + become non-executable leading to task termination. Therefore
103259 + it is mandatory that you enable this option on alpha, parisc,
103260 + sparc and sparc64, otherwise your system would not even boot.
103261 +
103262 + NOTE: this feature *does* open up a loophole in the protection
103263 + provided by the non-executable pages, therefore the proper
103264 + solution is to modify the toolchain to produce a PLT that does
103265 + not need to be writable.
103266 +
103267 +config PAX_DLRESOLVE
103268 + bool 'Emulate old glibc resolver stub'
103269 + depends on PAX_EMUPLT && SPARC
103270 + default n
103271 + help
103272 + This option is needed if userland has an old glibc (before 2.4)
103273 + that puts a 'save' instruction into the runtime generated resolver
103274 + stub that needs special emulation.
103275 +
103276 +config PAX_KERNEXEC
103277 + bool "Enforce non-executable kernel pages"
103278 + default y if GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_NONE || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_GUEST) || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_KVM))
103279 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
103280 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
103281 + select PAX_KERNEXEC_PLUGIN if X86_64
103282 + help
103283 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
103284 + that is, enabling this option will make it harder to inject
103285 + and execute 'foreign' code in kernel memory itself.
103286 +
103287 +choice
103288 + prompt "Return Address Instrumentation Method"
103289 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
103290 + depends on PAX_KERNEXEC_PLUGIN
103291 + help
103292 + Select the method used to instrument function pointer dereferences.
103293 + Note that binary modules cannot be instrumented by this approach.
103294 +
103295 + Note that the implementation requires a gcc with plugin support,
103296 + i.e., gcc 4.5 or newer. You may need to install the supporting
103297 + headers explicitly in addition to the normal gcc package.
103298 +
103299 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
103300 + bool "bts"
103301 + help
103302 + This method is compatible with binary only modules but has
103303 + a higher runtime overhead.
103304 +
103305 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
103306 + bool "or"
103307 + depends on !PARAVIRT
103308 + help
103309 + This method is incompatible with binary only modules but has
103310 + a lower runtime overhead.
103311 +endchoice
103312 +
103313 +config PAX_KERNEXEC_PLUGIN_METHOD
103314 + string
103315 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
103316 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
103317 + default ""
103318 +
103319 +config PAX_KERNEXEC_MODULE_TEXT
103320 + int "Minimum amount of memory reserved for module code"
103321 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
103322 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
103323 + depends on PAX_KERNEXEC && X86_32
103324 + help
103325 + Due to implementation details the kernel must reserve a fixed
103326 + amount of memory for runtime allocated code (such as modules)
103327 + at compile time that cannot be changed at runtime. Here you
103328 + can specify the minimum amount in MB that will be reserved.
103329 + Due to the same implementation details this size will always
103330 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
103331 + the actually available memory for runtime allocated code will
103332 + usually be more than this minimum.
103333 +
103334 + The default 4 MB should be enough for most users but if you have
103335 + an excessive number of modules (e.g., most distribution configs
103336 + compile many drivers as modules) or use huge modules such as
103337 + nvidia's kernel driver, you will need to adjust this amount.
103338 + A good rule of thumb is to look at your currently loaded kernel
103339 + modules and add up their sizes.
103340 +
103341 +endmenu
103342 +
103343 +menu "Address Space Layout Randomization"
103344 + depends on PAX
103345 +
103346 +config PAX_ASLR
103347 + bool "Address Space Layout Randomization"
103348 + default y if GRKERNSEC_CONFIG_AUTO
103349 + help
103350 + Many if not most exploit techniques rely on the knowledge of
103351 + certain addresses in the attacked program. The following options
103352 + will allow the kernel to apply a certain amount of randomization
103353 + to specific parts of the program thereby forcing an attacker to
103354 + guess them in most cases. Any failed guess will most likely crash
103355 + the attacked program which allows the kernel to detect such attempts
103356 + and react on them. PaX itself provides no reaction mechanisms,
103357 + instead it is strongly encouraged that you make use of Nergal's
103358 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
103359 + (http://www.grsecurity.net/) built-in crash detection features or
103360 + develop one yourself.
103361 +
103362 + By saying Y here you can choose to randomize the following areas:
103363 + - top of the task's kernel stack
103364 + - top of the task's userland stack
103365 + - base address for mmap() requests that do not specify one
103366 + (this includes all libraries)
103367 + - base address of the main executable
103368 +
103369 + It is strongly recommended to say Y here as address space layout
103370 + randomization has negligible impact on performance yet it provides
103371 + a very effective protection.
103372 +
103373 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
103374 + this feature on a per file basis.
103375 +
103376 +config PAX_RANDKSTACK
103377 + bool "Randomize kernel stack base"
103378 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
103379 + depends on X86_TSC && X86
103380 + help
103381 + By saying Y here the kernel will randomize every task's kernel
103382 + stack on every system call. This will not only force an attacker
103383 + to guess it but also prevent him from making use of possible
103384 + leaked information about it.
103385 +
103386 + Since the kernel stack is a rather scarce resource, randomization
103387 + may cause unexpected stack overflows, therefore you should very
103388 + carefully test your system. Note that once enabled in the kernel
103389 + configuration, this feature cannot be disabled on a per file basis.
103390 +
103391 +config PAX_RANDUSTACK
103392 + bool "Randomize user stack base"
103393 + default y if GRKERNSEC_CONFIG_AUTO
103394 + depends on PAX_ASLR
103395 + help
103396 + By saying Y here the kernel will randomize every task's userland
103397 + stack. The randomization is done in two steps where the second
103398 + one may apply a big amount of shift to the top of the stack and
103399 + cause problems for programs that want to use lots of memory (more
103400 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
103401 + For this reason the second step can be controlled by 'chpax' or
103402 + 'paxctl' on a per file basis.
103403 +
103404 +config PAX_RANDMMAP
103405 + bool "Randomize mmap() base"
103406 + default y if GRKERNSEC_CONFIG_AUTO
103407 + depends on PAX_ASLR
103408 + help
103409 + By saying Y here the kernel will use a randomized base address for
103410 + mmap() requests that do not specify one themselves. As a result
103411 + all dynamically loaded libraries will appear at random addresses
103412 + and therefore be harder to exploit by a technique where an attacker
103413 + attempts to execute library code for his purposes (e.g. spawn a
103414 + shell from an exploited program that is running at an elevated
103415 + privilege level).
103416 +
103417 + Furthermore, if a program is relinked as a dynamic ELF file, its
103418 + base address will be randomized as well, completing the full
103419 + randomization of the address space layout. Attacking such programs
103420 + becomes a guess game. You can find an example of doing this at
103421 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
103422 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
103423 +
103424 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
103425 + feature on a per file basis.
103426 +
103427 +endmenu
103428 +
103429 +menu "Miscellaneous hardening features"
103430 +
103431 +config PAX_MEMORY_SANITIZE
103432 + bool "Sanitize all freed memory"
103433 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103434 + help
103435 + By saying Y here the kernel will erase memory pages and slab objects
103436 + as soon as they are freed. This in turn reduces the lifetime of data
103437 + stored in them, making it less likely that sensitive information such
103438 + as passwords, cryptographic secrets, etc stay in memory for too long.
103439 +
103440 + This is especially useful for programs whose runtime is short, long
103441 + lived processes and the kernel itself benefit from this as long as
103442 + they ensure timely freeing of memory that may hold sensitive
103443 + information.
103444 +
103445 + A nice side effect of the sanitization of slab objects is the
103446 + reduction of possible info leaks caused by padding bytes within the
103447 + leaky structures. Use-after-free bugs for structures containing
103448 + pointers can also be detected as dereferencing the sanitized pointer
103449 + will generate an access violation.
103450 +
103451 + The tradeoff is performance impact, on a single CPU system kernel
103452 + compilation sees a 3% slowdown, other systems and workloads may vary
103453 + and you are advised to test this feature on your expected workload
103454 + before deploying it.
103455 +
103456 + To reduce the performance penalty by sanitizing pages only, albeit
103457 + limiting the effectiveness of this feature at the same time, slab
103458 + sanitization can be disabled with the kernel commandline parameter
103459 + "pax_sanitize_slab=0".
103460 +
103461 + Note that this feature does not protect data stored in live pages,
103462 + e.g., process memory swapped to disk may stay there for a long time.
103463 +
103464 +config PAX_MEMORY_STACKLEAK
103465 + bool "Sanitize kernel stack"
103466 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103467 + depends on X86
103468 + help
103469 + By saying Y here the kernel will erase the kernel stack before it
103470 + returns from a system call. This in turn reduces the information
103471 + that a kernel stack leak bug can reveal.
103472 +
103473 + Note that such a bug can still leak information that was put on
103474 + the stack by the current system call (the one eventually triggering
103475 + the bug) but traces of earlier system calls on the kernel stack
103476 + cannot leak anymore.
103477 +
103478 + The tradeoff is performance impact: on a single CPU system kernel
103479 + compilation sees a 1% slowdown, other systems and workloads may vary
103480 + and you are advised to test this feature on your expected workload
103481 + before deploying it.
103482 +
103483 + Note that the full feature requires a gcc with plugin support,
103484 + i.e., gcc 4.5 or newer. You may need to install the supporting
103485 + headers explicitly in addition to the normal gcc package. Using
103486 + older gcc versions means that functions with large enough stack
103487 + frames may leave uninitialized memory behind that may be exposed
103488 + to a later syscall leaking the stack.
103489 +
103490 +config PAX_MEMORY_STRUCTLEAK
103491 + bool "Forcibly initialize local variables copied to userland"
103492 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
103493 + help
103494 + By saying Y here the kernel will zero initialize some local
103495 + variables that are going to be copied to userland. This in
103496 + turn prevents unintended information leakage from the kernel
103497 + stack should later code forget to explicitly set all parts of
103498 + the copied variable.
103499 +
103500 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
103501 + at a much smaller coverage.
103502 +
103503 + Note that the implementation requires a gcc with plugin support,
103504 + i.e., gcc 4.5 or newer. You may need to install the supporting
103505 + headers explicitly in addition to the normal gcc package.
103506 +
103507 +config PAX_MEMORY_UDEREF
103508 + bool "Prevent invalid userland pointer dereference"
103509 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
103510 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
103511 + select PAX_PER_CPU_PGD if X86_64
103512 + help
103513 + By saying Y here the kernel will be prevented from dereferencing
103514 + userland pointers in contexts where the kernel expects only kernel
103515 + pointers. This is both a useful runtime debugging feature and a
103516 + security measure that prevents exploiting a class of kernel bugs.
103517 +
103518 + The tradeoff is that some virtualization solutions may experience
103519 + a huge slowdown and therefore you should not enable this feature
103520 + for kernels meant to run in such environments. Whether a given VM
103521 + solution is affected or not is best determined by simply trying it
103522 + out, the performance impact will be obvious right on boot as this
103523 + mechanism engages from very early on. A good rule of thumb is that
103524 + VMs running on CPUs without hardware virtualization support (i.e.,
103525 + the majority of IA-32 CPUs) will likely experience the slowdown.
103526 +
103527 + On X86_64 the kernel will make use of PCID support when available
103528 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
103529 + or performance impact. Pass pax_weakuderef on the kernel command
103530 + line to choose the latter.
103531 +
103532 +config PAX_REFCOUNT
103533 + bool "Prevent various kernel object reference counter overflows"
103534 + default y if GRKERNSEC_CONFIG_AUTO
103535 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
103536 + help
103537 + By saying Y here the kernel will detect and prevent overflowing
103538 + various (but not all) kinds of object reference counters. Such
103539 + overflows can normally occur due to bugs only and are often, if
103540 + not always, exploitable.
103541 +
103542 + The tradeoff is that data structures protected by an overflowed
103543 + refcount will never be freed and therefore will leak memory. Note
103544 + that this leak also happens even without this protection but in
103545 + that case the overflow can eventually trigger the freeing of the
103546 + data structure while it is still being used elsewhere, resulting
103547 + in the exploitable situation that this feature prevents.
103548 +
103549 + Since this has a negligible performance impact, you should enable
103550 + this feature.
103551 +
103552 +config PAX_CONSTIFY_PLUGIN
103553 + bool "Automatically constify eligible structures"
103554 + default y
103555 + depends on !UML && PAX_KERNEXEC
103556 + help
103557 + By saying Y here the compiler will automatically constify a class
103558 + of types that contain only function pointers. This reduces the
103559 + kernel's attack surface and also produces a better memory layout.
103560 +
103561 + Note that the implementation requires a gcc with plugin support,
103562 + i.e., gcc 4.5 or newer. You may need to install the supporting
103563 + headers explicitly in addition to the normal gcc package.
103564 +
103565 + Note that if some code really has to modify constified variables
103566 + then the source code will have to be patched to allow it. Examples
103567 + can be found in PaX itself (the no_const attribute) and for some
103568 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
103569 +
103570 +config PAX_USERCOPY
103571 + bool "Harden heap object copies between kernel and userland"
103572 + default y if GRKERNSEC_CONFIG_AUTO
103573 + depends on ARM || IA64 || PPC || SPARC || X86
103574 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
103575 + select PAX_USERCOPY_SLABS
103576 + help
103577 + By saying Y here the kernel will enforce the size of heap objects
103578 + when they are copied in either direction between the kernel and
103579 + userland, even if only a part of the heap object is copied.
103580 +
103581 + Specifically, this checking prevents information leaking from the
103582 + kernel heap during kernel to userland copies (if the kernel heap
103583 + object is otherwise fully initialized) and prevents kernel heap
103584 + overflows during userland to kernel copies.
103585 +
103586 + Note that the current implementation provides the strictest bounds
103587 + checks for the SLUB allocator.
103588 +
103589 + Enabling this option also enables per-slab cache protection against
103590 + data in a given cache being copied into/out of via userland
103591 + accessors. Though the whitelist of regions will be reduced over
103592 + time, it notably protects important data structures like task structs.
103593 +
103594 + If frame pointers are enabled on x86, this option will also restrict
103595 + copies into and out of the kernel stack to local variables within a
103596 + single frame.
103597 +
103598 + Since this has a negligible performance impact, you should enable
103599 + this feature.
103600 +
103601 +config PAX_USERCOPY_DEBUG
103602 + bool
103603 + depends on X86 && PAX_USERCOPY
103604 + default n
103605 +
103606 +config PAX_SIZE_OVERFLOW
103607 + bool "Prevent various integer overflows in function size parameters"
103608 + default y if GRKERNSEC_CONFIG_AUTO
103609 + depends on X86
103610 + help
103611 + By saying Y here the kernel recomputes expressions of function
103612 + arguments marked by a size_overflow attribute with double integer
103613 + precision (DImode/TImode for 32/64 bit integer types).
103614 +
103615 + The recomputed argument is checked against TYPE_MAX and an event
103616 + is logged on overflow and the triggering process is killed.
103617 +
103618 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
103619 +
103620 + Note that the implementation requires a gcc with plugin support,
103621 + i.e., gcc 4.5 or newer. You may need to install the supporting
103622 + headers explicitly in addition to the normal gcc package.
103623 +
103624 +config PAX_LATENT_ENTROPY
103625 + bool "Generate some entropy during boot and runtime"
103626 + default y if GRKERNSEC_CONFIG_AUTO
103627 + help
103628 + By saying Y here the kernel will instrument some kernel code to
103629 + extract some entropy from both original and artificially created
103630 + program state. This will help especially embedded systems where
103631 + there is little 'natural' source of entropy normally. The cost
103632 + is some slowdown of the boot process and fork and irq processing.
103633 +
103634 + When pax_extra_latent_entropy is passed on the kernel command line,
103635 + entropy will be extracted from up to the first 4GB of RAM while the
103636 + runtime memory allocator is being initialized. This costs even more
103637 + slowdown of the boot process.
103638 +
103639 + Note that the implementation requires a gcc with plugin support,
103640 + i.e., gcc 4.5 or newer. You may need to install the supporting
103641 + headers explicitly in addition to the normal gcc package.
103642 +
103643 + Note that entropy extracted this way is not cryptographically
103644 + secure!
103645 +
103646 +endmenu
103647 +
103648 +endmenu
103649 +
103650 +source grsecurity/Kconfig
103651 +
103652 +endmenu
103653 +
103654 +endmenu
103655 +
103656 source security/keys/Kconfig
103657
103658 config SECURITY_DMESG_RESTRICT
103659 @@ -103,7 +1057,7 @@ config INTEL_TXT
103660 config LSM_MMAP_MIN_ADDR
103661 int "Low address space for LSM to protect from user allocation"
103662 depends on SECURITY && SECURITY_SELINUX
103663 - default 32768 if ARM || (ARM64 && COMPAT)
103664 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
103665 default 65536
103666 help
103667 This is the portion of low virtual memory which should be protected
103668 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
103669 index fdaa50c..2761dcb 100644
103670 --- a/security/apparmor/file.c
103671 +++ b/security/apparmor/file.c
103672 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
103673 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
103674 struct path *new_dir, struct dentry *new_dentry)
103675 {
103676 - struct path link = { new_dir->mnt, new_dentry };
103677 - struct path target = { new_dir->mnt, old_dentry };
103678 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
103679 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
103680 struct path_cond cond = {
103681 old_dentry->d_inode->i_uid,
103682 old_dentry->d_inode->i_mode
103683 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
103684 index 4257b7e..2d0732d 100644
103685 --- a/security/apparmor/lsm.c
103686 +++ b/security/apparmor/lsm.c
103687 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
103688 struct dentry *dentry, u32 mask,
103689 struct path_cond *cond)
103690 {
103691 - struct path path = { dir->mnt, dentry };
103692 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
103693
103694 return common_perm(op, &path, mask, cond);
103695 }
103696 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
103697 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
103698 struct dentry *dentry, u32 mask)
103699 {
103700 - struct path path = { mnt, dentry };
103701 + struct path path = { .mnt = mnt, .dentry = dentry };
103702 struct path_cond cond = { dentry->d_inode->i_uid,
103703 dentry->d_inode->i_mode
103704 };
103705 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
103706
103707 profile = aa_current_profile();
103708 if (!unconfined(profile)) {
103709 - struct path old_path = { old_dir->mnt, old_dentry };
103710 - struct path new_path = { new_dir->mnt, new_dentry };
103711 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
103712 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
103713 struct path_cond cond = { old_dentry->d_inode->i_uid,
103714 old_dentry->d_inode->i_mode
103715 };
103716 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
103717 return error;
103718 }
103719
103720 -static struct security_operations apparmor_ops = {
103721 +static struct security_operations apparmor_ops __read_only = {
103722 .name = "apparmor",
103723
103724 .ptrace_access_check = apparmor_ptrace_access_check,
103725 diff --git a/security/commoncap.c b/security/commoncap.c
103726 index b9d613e..f68305c 100644
103727 --- a/security/commoncap.c
103728 +++ b/security/commoncap.c
103729 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
103730 return 0;
103731 }
103732
103733 +/* returns:
103734 + 1 for suid privilege
103735 + 2 for sgid privilege
103736 + 3 for fscap privilege
103737 +*/
103738 +int is_privileged_binary(const struct dentry *dentry)
103739 +{
103740 + struct cpu_vfs_cap_data capdata;
103741 + struct inode *inode = dentry->d_inode;
103742 +
103743 + if (!inode || S_ISDIR(inode->i_mode))
103744 + return 0;
103745 +
103746 + if (inode->i_mode & S_ISUID)
103747 + return 1;
103748 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
103749 + return 2;
103750 +
103751 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
103752 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
103753 + return 3;
103754 + }
103755 +
103756 + return 0;
103757 +}
103758 +
103759 /*
103760 * Attempt to get the on-exec apply capability sets for an executable file from
103761 * its xattrs and, if present, apply them to the proposed credentials being
103762 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
103763 const struct cred *cred = current_cred();
103764 kuid_t root_uid = make_kuid(cred->user_ns, 0);
103765
103766 + if (gr_acl_enable_at_secure())
103767 + return 1;
103768 +
103769 if (!uid_eq(cred->uid, root_uid)) {
103770 if (bprm->cap_effective)
103771 return 1;
103772 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
103773 index 0356e1d..72332ab 100644
103774 --- a/security/integrity/ima/ima.h
103775 +++ b/security/integrity/ima/ima.h
103776 @@ -118,8 +118,8 @@ int ima_init_template(void);
103777 extern spinlock_t ima_queue_lock;
103778
103779 struct ima_h_table {
103780 - atomic_long_t len; /* number of stored measurements in the list */
103781 - atomic_long_t violations;
103782 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
103783 + atomic_long_unchecked_t violations;
103784 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
103785 };
103786 extern struct ima_h_table ima_htable;
103787 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
103788 index c38bbce..f45133d 100644
103789 --- a/security/integrity/ima/ima_api.c
103790 +++ b/security/integrity/ima/ima_api.c
103791 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
103792 int result;
103793
103794 /* can overflow, only indicator */
103795 - atomic_long_inc(&ima_htable.violations);
103796 + atomic_long_inc_unchecked(&ima_htable.violations);
103797
103798 result = ima_alloc_init_template(NULL, file, filename,
103799 NULL, 0, &entry);
103800 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
103801 index db01125..61f6597 100644
103802 --- a/security/integrity/ima/ima_fs.c
103803 +++ b/security/integrity/ima/ima_fs.c
103804 @@ -28,12 +28,12 @@
103805 static int valid_policy = 1;
103806 #define TMPBUFLEN 12
103807 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
103808 - loff_t *ppos, atomic_long_t *val)
103809 + loff_t *ppos, atomic_long_unchecked_t *val)
103810 {
103811 char tmpbuf[TMPBUFLEN];
103812 ssize_t len;
103813
103814 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
103815 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
103816 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
103817 }
103818
103819 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
103820 index d85e997..6992813 100644
103821 --- a/security/integrity/ima/ima_queue.c
103822 +++ b/security/integrity/ima/ima_queue.c
103823 @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
103824 INIT_LIST_HEAD(&qe->later);
103825 list_add_tail_rcu(&qe->later, &ima_measurements);
103826
103827 - atomic_long_inc(&ima_htable.len);
103828 + atomic_long_inc_unchecked(&ima_htable.len);
103829 key = ima_hash_key(entry->digest);
103830 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
103831 return 0;
103832 diff --git a/security/keys/compat.c b/security/keys/compat.c
103833 index bbd32c7..c60c927 100644
103834 --- a/security/keys/compat.c
103835 +++ b/security/keys/compat.c
103836 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
103837 if (ret == 0)
103838 goto no_payload_free;
103839
103840 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
103841 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
103842 err:
103843 if (iov != iovstack)
103844 kfree(iov);
103845 diff --git a/security/keys/internal.h b/security/keys/internal.h
103846 index 80b2aac..bb7ee65 100644
103847 --- a/security/keys/internal.h
103848 +++ b/security/keys/internal.h
103849 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
103850 extern long keyctl_invalidate_key(key_serial_t);
103851
103852 extern long keyctl_instantiate_key_common(key_serial_t,
103853 - const struct iovec *,
103854 + const struct iovec __user *,
103855 unsigned, size_t, key_serial_t);
103856 #ifdef CONFIG_PERSISTENT_KEYRINGS
103857 extern long keyctl_get_persistent(uid_t, key_serial_t);
103858 diff --git a/security/keys/key.c b/security/keys/key.c
103859 index 6e21c11..9ed67ca 100644
103860 --- a/security/keys/key.c
103861 +++ b/security/keys/key.c
103862 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
103863
103864 atomic_set(&key->usage, 1);
103865 init_rwsem(&key->sem);
103866 - lockdep_set_class(&key->sem, &type->lock_class);
103867 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
103868 key->index_key.type = type;
103869 key->user = user;
103870 key->quotalen = quotalen;
103871 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
103872 struct key_type *p;
103873 int ret;
103874
103875 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
103876 + pax_open_kernel();
103877 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
103878 + pax_close_kernel();
103879
103880 ret = -EEXIST;
103881 down_write(&key_types_sem);
103882 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
103883 }
103884
103885 /* store the type */
103886 - list_add(&ktype->link, &key_types_list);
103887 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
103888
103889 pr_notice("Key type %s registered\n", ktype->name);
103890 ret = 0;
103891 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
103892 void unregister_key_type(struct key_type *ktype)
103893 {
103894 down_write(&key_types_sem);
103895 - list_del_init(&ktype->link);
103896 + pax_list_del_init((struct list_head *)&ktype->link);
103897 downgrade_write(&key_types_sem);
103898 key_gc_keytype(ktype);
103899 pr_notice("Key type %s unregistered\n", ktype->name);
103900 @@ -1088,10 +1090,10 @@ void __init key_init(void)
103901 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
103902
103903 /* add the special key types */
103904 - list_add_tail(&key_type_keyring.link, &key_types_list);
103905 - list_add_tail(&key_type_dead.link, &key_types_list);
103906 - list_add_tail(&key_type_user.link, &key_types_list);
103907 - list_add_tail(&key_type_logon.link, &key_types_list);
103908 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
103909 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
103910 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
103911 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
103912
103913 /* record the root user tracking */
103914 rb_link_node(&root_key_user.node,
103915 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
103916 index cee72ce..e46074a 100644
103917 --- a/security/keys/keyctl.c
103918 +++ b/security/keys/keyctl.c
103919 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
103920 /*
103921 * Copy the iovec data from userspace
103922 */
103923 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
103924 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
103925 unsigned ioc)
103926 {
103927 for (; ioc > 0; ioc--) {
103928 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
103929 * If successful, 0 will be returned.
103930 */
103931 long keyctl_instantiate_key_common(key_serial_t id,
103932 - const struct iovec *payload_iov,
103933 + const struct iovec __user *payload_iov,
103934 unsigned ioc,
103935 size_t plen,
103936 key_serial_t ringid)
103937 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
103938 [0].iov_len = plen
103939 };
103940
103941 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
103942 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
103943 }
103944
103945 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
103946 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
103947 if (ret == 0)
103948 goto no_payload_free;
103949
103950 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
103951 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
103952 err:
103953 if (iov != iovstack)
103954 kfree(iov);
103955 diff --git a/security/min_addr.c b/security/min_addr.c
103956 index f728728..6457a0c 100644
103957 --- a/security/min_addr.c
103958 +++ b/security/min_addr.c
103959 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
103960 */
103961 static void update_mmap_min_addr(void)
103962 {
103963 +#ifndef SPARC
103964 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
103965 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
103966 mmap_min_addr = dac_mmap_min_addr;
103967 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
103968 #else
103969 mmap_min_addr = dac_mmap_min_addr;
103970 #endif
103971 +#endif
103972 }
103973
103974 /*
103975 diff --git a/security/security.c b/security/security.c
103976 index 919cad9..2127be1 100644
103977 --- a/security/security.c
103978 +++ b/security/security.c
103979 @@ -33,8 +33,8 @@
103980 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
103981 CONFIG_DEFAULT_SECURITY;
103982
103983 -static struct security_operations *security_ops;
103984 -static struct security_operations default_security_ops = {
103985 +struct security_operations *security_ops __read_only;
103986 +struct security_operations default_security_ops __read_only = {
103987 .name = "default",
103988 };
103989
103990 @@ -73,11 +73,6 @@ int __init security_init(void)
103991 return 0;
103992 }
103993
103994 -void reset_security_ops(void)
103995 -{
103996 - security_ops = &default_security_ops;
103997 -}
103998 -
103999 /* Save user chosen LSM */
104000 static int __init choose_lsm(char *str)
104001 {
104002 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
104003 index fc3e662..7844c60 100644
104004 --- a/security/selinux/avc.c
104005 +++ b/security/selinux/avc.c
104006 @@ -59,7 +59,7 @@ struct avc_node {
104007 struct avc_cache {
104008 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
104009 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
104010 - atomic_t lru_hint; /* LRU hint for reclaim scan */
104011 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
104012 atomic_t active_nodes;
104013 u32 latest_notif; /* latest revocation notification */
104014 };
104015 @@ -167,7 +167,7 @@ void __init avc_init(void)
104016 spin_lock_init(&avc_cache.slots_lock[i]);
104017 }
104018 atomic_set(&avc_cache.active_nodes, 0);
104019 - atomic_set(&avc_cache.lru_hint, 0);
104020 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
104021
104022 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
104023 0, SLAB_PANIC, NULL);
104024 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
104025 spinlock_t *lock;
104026
104027 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
104028 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
104029 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
104030 head = &avc_cache.slots[hvalue];
104031 lock = &avc_cache.slots_lock[hvalue];
104032
104033 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
104034 index e294b86..eda45c55 100644
104035 --- a/security/selinux/hooks.c
104036 +++ b/security/selinux/hooks.c
104037 @@ -95,8 +95,6 @@
104038 #include "audit.h"
104039 #include "avc_ss.h"
104040
104041 -extern struct security_operations *security_ops;
104042 -
104043 /* SECMARK reference count */
104044 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
104045
104046 @@ -5759,7 +5757,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
104047
104048 #endif
104049
104050 -static struct security_operations selinux_ops = {
104051 +static struct security_operations selinux_ops __read_only = {
104052 .name = "selinux",
104053
104054 .ptrace_access_check = selinux_ptrace_access_check,
104055 @@ -6112,6 +6110,9 @@ static void selinux_nf_ip_exit(void)
104056 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
104057 static int selinux_disabled;
104058
104059 +extern struct security_operations *security_ops;
104060 +extern struct security_operations default_security_ops;
104061 +
104062 int selinux_disable(void)
104063 {
104064 if (ss_initialized) {
104065 @@ -6129,7 +6130,9 @@ int selinux_disable(void)
104066 selinux_disabled = 1;
104067 selinux_enabled = 0;
104068
104069 - reset_security_ops();
104070 + pax_open_kernel();
104071 + security_ops = &default_security_ops;
104072 + pax_close_kernel();
104073
104074 /* Try to destroy the avc node cache */
104075 avc_disable();
104076 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
104077 index 9f05847..7933395 100644
104078 --- a/security/selinux/include/xfrm.h
104079 +++ b/security/selinux/include/xfrm.h
104080 @@ -46,7 +46,7 @@ static inline void selinux_xfrm_notify_policyload(void)
104081 {
104082 struct net *net;
104083
104084 - atomic_inc(&flow_cache_genid);
104085 + atomic_inc_unchecked(&flow_cache_genid);
104086 rtnl_lock();
104087 for_each_net(net)
104088 rt_genid_bump_all(net);
104089 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
104090 index 14f52be..7352368 100644
104091 --- a/security/smack/smack_lsm.c
104092 +++ b/security/smack/smack_lsm.c
104093 @@ -3726,7 +3726,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
104094 return 0;
104095 }
104096
104097 -struct security_operations smack_ops = {
104098 +struct security_operations smack_ops __read_only = {
104099 .name = "smack",
104100
104101 .ptrace_access_check = smack_ptrace_access_check,
104102 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
104103 index 4003907..13a2b55 100644
104104 --- a/security/tomoyo/file.c
104105 +++ b/security/tomoyo/file.c
104106 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
104107 {
104108 struct tomoyo_request_info r;
104109 struct tomoyo_obj_info obj = {
104110 - .path1 = *path,
104111 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104112 };
104113 int error = -ENOMEM;
104114 struct tomoyo_path_info buf;
104115 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
104116 struct tomoyo_path_info buf;
104117 struct tomoyo_request_info r;
104118 struct tomoyo_obj_info obj = {
104119 - .path1 = *path,
104120 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104121 };
104122 int idx;
104123
104124 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
104125 {
104126 struct tomoyo_request_info r;
104127 struct tomoyo_obj_info obj = {
104128 - .path1 = *path,
104129 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104130 };
104131 int error;
104132 struct tomoyo_path_info buf;
104133 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
104134 {
104135 struct tomoyo_request_info r;
104136 struct tomoyo_obj_info obj = {
104137 - .path1 = *path,
104138 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
104139 };
104140 int error = -ENOMEM;
104141 struct tomoyo_path_info buf;
104142 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
104143 struct tomoyo_path_info buf2;
104144 struct tomoyo_request_info r;
104145 struct tomoyo_obj_info obj = {
104146 - .path1 = *path1,
104147 - .path2 = *path2,
104148 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
104149 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
104150 };
104151 int idx;
104152
104153 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
104154 index 390c646..f2f8db3 100644
104155 --- a/security/tomoyo/mount.c
104156 +++ b/security/tomoyo/mount.c
104157 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
104158 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
104159 need_dev = -1; /* dev_name is a directory */
104160 } else {
104161 + if (!capable(CAP_SYS_ADMIN)) {
104162 + error = -EPERM;
104163 + goto out;
104164 + }
104165 fstype = get_fs_type(type);
104166 if (!fstype) {
104167 error = -ENODEV;
104168 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
104169 index f0b756e..8aa497b 100644
104170 --- a/security/tomoyo/tomoyo.c
104171 +++ b/security/tomoyo/tomoyo.c
104172 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
104173 */
104174 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
104175 {
104176 - struct path path = { mnt, dentry };
104177 + struct path path = { .mnt = mnt, .dentry = dentry };
104178 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
104179 }
104180
104181 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
104182 */
104183 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
104184 {
104185 - struct path path = { parent->mnt, dentry };
104186 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104187 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
104188 }
104189
104190 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
104191 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
104192 umode_t mode)
104193 {
104194 - struct path path = { parent->mnt, dentry };
104195 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104196 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
104197 mode & S_IALLUGO);
104198 }
104199 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
104200 */
104201 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
104202 {
104203 - struct path path = { parent->mnt, dentry };
104204 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104205 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
104206 }
104207
104208 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
104209 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
104210 const char *old_name)
104211 {
104212 - struct path path = { parent->mnt, dentry };
104213 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104214 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
104215 }
104216
104217 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
104218 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
104219 umode_t mode, unsigned int dev)
104220 {
104221 - struct path path = { parent->mnt, dentry };
104222 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
104223 int type = TOMOYO_TYPE_CREATE;
104224 const unsigned int perm = mode & S_IALLUGO;
104225
104226 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
104227 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
104228 struct dentry *new_dentry)
104229 {
104230 - struct path path1 = { new_dir->mnt, old_dentry };
104231 - struct path path2 = { new_dir->mnt, new_dentry };
104232 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
104233 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
104234 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
104235 }
104236
104237 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
104238 struct path *new_parent,
104239 struct dentry *new_dentry)
104240 {
104241 - struct path path1 = { old_parent->mnt, old_dentry };
104242 - struct path path2 = { new_parent->mnt, new_dentry };
104243 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
104244 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
104245 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
104246 }
104247
104248 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
104249 */
104250 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
104251 {
104252 - struct path path = { mnt, mnt->mnt_root };
104253 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
104254 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
104255 }
104256
104257 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
104258 * tomoyo_security_ops is a "struct security_operations" which is used for
104259 * registering TOMOYO.
104260 */
104261 -static struct security_operations tomoyo_security_ops = {
104262 +static struct security_operations tomoyo_security_ops __read_only = {
104263 .name = "tomoyo",
104264 .cred_alloc_blank = tomoyo_cred_alloc_blank,
104265 .cred_prepare = tomoyo_cred_prepare,
104266 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
104267 index 20ef514..4182bed 100644
104268 --- a/security/yama/Kconfig
104269 +++ b/security/yama/Kconfig
104270 @@ -1,6 +1,6 @@
104271 config SECURITY_YAMA
104272 bool "Yama support"
104273 - depends on SECURITY
104274 + depends on SECURITY && !GRKERNSEC
104275 select SECURITYFS
104276 select SECURITY_PATH
104277 default n
104278 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
104279 index 13c88fbc..f8c115e 100644
104280 --- a/security/yama/yama_lsm.c
104281 +++ b/security/yama/yama_lsm.c
104282 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
104283 }
104284
104285 #ifndef CONFIG_SECURITY_YAMA_STACKED
104286 -static struct security_operations yama_ops = {
104287 +static struct security_operations yama_ops __read_only = {
104288 .name = "yama",
104289
104290 .ptrace_access_check = yama_ptrace_access_check,
104291 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
104292 #endif
104293
104294 #ifdef CONFIG_SYSCTL
104295 +static int zero __read_only;
104296 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
104297 +
104298 static int yama_dointvec_minmax(struct ctl_table *table, int write,
104299 void __user *buffer, size_t *lenp, loff_t *ppos)
104300 {
104301 - int rc;
104302 + ctl_table_no_const yama_table;
104303
104304 if (write && !capable(CAP_SYS_PTRACE))
104305 return -EPERM;
104306
104307 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
104308 - if (rc)
104309 - return rc;
104310 -
104311 + yama_table = *table;
104312 /* Lock the max value if it ever gets set. */
104313 - if (write && *(int *)table->data == *(int *)table->extra2)
104314 - table->extra1 = table->extra2;
104315 -
104316 - return rc;
104317 + if (ptrace_scope == max_scope)
104318 + yama_table.extra1 = &max_scope;
104319 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
104320 }
104321
104322 -static int zero;
104323 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
104324 -
104325 struct ctl_path yama_sysctl_path[] = {
104326 { .procname = "kernel", },
104327 { .procname = "yama", },
104328 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
104329 index 4cedc69..e59d8a3 100644
104330 --- a/sound/aoa/codecs/onyx.c
104331 +++ b/sound/aoa/codecs/onyx.c
104332 @@ -54,7 +54,7 @@ struct onyx {
104333 spdif_locked:1,
104334 analog_locked:1,
104335 original_mute:2;
104336 - int open_count;
104337 + local_t open_count;
104338 struct codec_info *codec_info;
104339
104340 /* mutex serializes concurrent access to the device
104341 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
104342 struct onyx *onyx = cii->codec_data;
104343
104344 mutex_lock(&onyx->mutex);
104345 - onyx->open_count++;
104346 + local_inc(&onyx->open_count);
104347 mutex_unlock(&onyx->mutex);
104348
104349 return 0;
104350 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
104351 struct onyx *onyx = cii->codec_data;
104352
104353 mutex_lock(&onyx->mutex);
104354 - onyx->open_count--;
104355 - if (!onyx->open_count)
104356 + if (local_dec_and_test(&onyx->open_count))
104357 onyx->spdif_locked = onyx->analog_locked = 0;
104358 mutex_unlock(&onyx->mutex);
104359
104360 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
104361 index ffd2025..df062c9 100644
104362 --- a/sound/aoa/codecs/onyx.h
104363 +++ b/sound/aoa/codecs/onyx.h
104364 @@ -11,6 +11,7 @@
104365 #include <linux/i2c.h>
104366 #include <asm/pmac_low_i2c.h>
104367 #include <asm/prom.h>
104368 +#include <asm/local.h>
104369
104370 /* PCM3052 register definitions */
104371
104372 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
104373 index 4c1cc51..16040040 100644
104374 --- a/sound/core/oss/pcm_oss.c
104375 +++ b/sound/core/oss/pcm_oss.c
104376 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
104377 if (in_kernel) {
104378 mm_segment_t fs;
104379 fs = snd_enter_user();
104380 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104381 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104382 snd_leave_user(fs);
104383 } else {
104384 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
104385 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
104386 }
104387 if (ret != -EPIPE && ret != -ESTRPIPE)
104388 break;
104389 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
104390 if (in_kernel) {
104391 mm_segment_t fs;
104392 fs = snd_enter_user();
104393 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104394 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104395 snd_leave_user(fs);
104396 } else {
104397 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
104398 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
104399 }
104400 if (ret == -EPIPE) {
104401 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
104402 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
104403 struct snd_pcm_plugin_channel *channels;
104404 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
104405 if (!in_kernel) {
104406 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
104407 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
104408 return -EFAULT;
104409 buf = runtime->oss.buffer;
104410 }
104411 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
104412 }
104413 } else {
104414 tmp = snd_pcm_oss_write2(substream,
104415 - (const char __force *)buf,
104416 + (const char __force_kernel *)buf,
104417 runtime->oss.period_bytes, 0);
104418 if (tmp <= 0)
104419 goto err;
104420 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
104421 struct snd_pcm_runtime *runtime = substream->runtime;
104422 snd_pcm_sframes_t frames, frames1;
104423 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
104424 - char __user *final_dst = (char __force __user *)buf;
104425 + char __user *final_dst = (char __force_user *)buf;
104426 if (runtime->oss.plugin_first) {
104427 struct snd_pcm_plugin_channel *channels;
104428 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
104429 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
104430 xfer += tmp;
104431 runtime->oss.buffer_used -= tmp;
104432 } else {
104433 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
104434 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
104435 runtime->oss.period_bytes, 0);
104436 if (tmp <= 0)
104437 goto err;
104438 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
104439 size1);
104440 size1 /= runtime->channels; /* frames */
104441 fs = snd_enter_user();
104442 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
104443 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
104444 snd_leave_user(fs);
104445 }
104446 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
104447 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
104448 index af49721..e85058e 100644
104449 --- a/sound/core/pcm_compat.c
104450 +++ b/sound/core/pcm_compat.c
104451 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
104452 int err;
104453
104454 fs = snd_enter_user();
104455 - err = snd_pcm_delay(substream, &delay);
104456 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
104457 snd_leave_user(fs);
104458 if (err < 0)
104459 return err;
104460 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
104461 index 01a5e05..c6bb425 100644
104462 --- a/sound/core/pcm_native.c
104463 +++ b/sound/core/pcm_native.c
104464 @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
104465 switch (substream->stream) {
104466 case SNDRV_PCM_STREAM_PLAYBACK:
104467 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
104468 - (void __user *)arg);
104469 + (void __force_user *)arg);
104470 break;
104471 case SNDRV_PCM_STREAM_CAPTURE:
104472 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
104473 - (void __user *)arg);
104474 + (void __force_user *)arg);
104475 break;
104476 default:
104477 result = -EINVAL;
104478 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
104479 index 8d4d5e8..fdd0826 100644
104480 --- a/sound/core/seq/oss/seq_oss.c
104481 +++ b/sound/core/seq/oss/seq_oss.c
104482 @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
104483 {
104484 int rc;
104485 static struct snd_seq_dev_ops ops = {
104486 - snd_seq_oss_synth_register,
104487 - snd_seq_oss_synth_unregister,
104488 + .init_device = snd_seq_oss_synth_register,
104489 + .free_device = snd_seq_oss_synth_unregister,
104490 };
104491
104492 snd_seq_autoload_lock();
104493 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
104494 index 040c60e..989a19a 100644
104495 --- a/sound/core/seq/seq_device.c
104496 +++ b/sound/core/seq/seq_device.c
104497 @@ -64,7 +64,7 @@ struct ops_list {
104498 int argsize; /* argument size */
104499
104500 /* operators */
104501 - struct snd_seq_dev_ops ops;
104502 + struct snd_seq_dev_ops *ops;
104503
104504 /* registered devices */
104505 struct list_head dev_list; /* list of devices */
104506 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
104507
104508 mutex_lock(&ops->reg_mutex);
104509 /* copy driver operators */
104510 - ops->ops = *entry;
104511 + ops->ops = entry;
104512 ops->driver |= DRIVER_LOADED;
104513 ops->argsize = argsize;
104514
104515 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
104516 dev->name, ops->id, ops->argsize, dev->argsize);
104517 return -EINVAL;
104518 }
104519 - if (ops->ops.init_device(dev) >= 0) {
104520 + if (ops->ops->init_device(dev) >= 0) {
104521 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
104522 ops->num_init_devices++;
104523 } else {
104524 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
104525 dev->name, ops->id, ops->argsize, dev->argsize);
104526 return -EINVAL;
104527 }
104528 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
104529 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
104530 dev->status = SNDRV_SEQ_DEVICE_FREE;
104531 dev->driver_data = NULL;
104532 ops->num_init_devices--;
104533 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
104534 index 64069db..3c6d392 100644
104535 --- a/sound/core/seq/seq_midi.c
104536 +++ b/sound/core/seq/seq_midi.c
104537 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
104538 static int __init alsa_seq_midi_init(void)
104539 {
104540 static struct snd_seq_dev_ops ops = {
104541 - snd_seq_midisynth_register_port,
104542 - snd_seq_midisynth_unregister_port,
104543 + .init_device = snd_seq_midisynth_register_port,
104544 + .free_device = snd_seq_midisynth_unregister_port,
104545 };
104546 memset(&synths, 0, sizeof(synths));
104547 snd_seq_autoload_lock();
104548 diff --git a/sound/core/sound.c b/sound/core/sound.c
104549 index 437c25e..cd040ab 100644
104550 --- a/sound/core/sound.c
104551 +++ b/sound/core/sound.c
104552 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
104553 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
104554 default: return;
104555 }
104556 - request_module(str);
104557 + request_module("%s", str);
104558 }
104559
104560 #endif /* modular kernel */
104561 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
104562 index 4e0dd22..7a1f32c 100644
104563 --- a/sound/drivers/mts64.c
104564 +++ b/sound/drivers/mts64.c
104565 @@ -29,6 +29,7 @@
104566 #include <sound/initval.h>
104567 #include <sound/rawmidi.h>
104568 #include <sound/control.h>
104569 +#include <asm/local.h>
104570
104571 #define CARD_NAME "Miditerminal 4140"
104572 #define DRIVER_NAME "MTS64"
104573 @@ -67,7 +68,7 @@ struct mts64 {
104574 struct pardevice *pardev;
104575 int pardev_claimed;
104576
104577 - int open_count;
104578 + local_t open_count;
104579 int current_midi_output_port;
104580 int current_midi_input_port;
104581 u8 mode[MTS64_NUM_INPUT_PORTS];
104582 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
104583 {
104584 struct mts64 *mts = substream->rmidi->private_data;
104585
104586 - if (mts->open_count == 0) {
104587 + if (local_read(&mts->open_count) == 0) {
104588 /* We don't need a spinlock here, because this is just called
104589 if the device has not been opened before.
104590 So there aren't any IRQs from the device */
104591 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
104592
104593 msleep(50);
104594 }
104595 - ++(mts->open_count);
104596 + local_inc(&mts->open_count);
104597
104598 return 0;
104599 }
104600 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
104601 struct mts64 *mts = substream->rmidi->private_data;
104602 unsigned long flags;
104603
104604 - --(mts->open_count);
104605 - if (mts->open_count == 0) {
104606 + if (local_dec_return(&mts->open_count) == 0) {
104607 /* We need the spinlock_irqsave here because we can still
104608 have IRQs at this point */
104609 spin_lock_irqsave(&mts->lock, flags);
104610 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
104611
104612 msleep(500);
104613
104614 - } else if (mts->open_count < 0)
104615 - mts->open_count = 0;
104616 + } else if (local_read(&mts->open_count) < 0)
104617 + local_set(&mts->open_count, 0);
104618
104619 return 0;
104620 }
104621 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
104622 index 6839953..7a0f4b9 100644
104623 --- a/sound/drivers/opl3/opl3_seq.c
104624 +++ b/sound/drivers/opl3/opl3_seq.c
104625 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
104626 {
104627 static struct snd_seq_dev_ops ops =
104628 {
104629 - snd_opl3_seq_new_device,
104630 - snd_opl3_seq_delete_device
104631 + .init_device = snd_opl3_seq_new_device,
104632 + .free_device = snd_opl3_seq_delete_device
104633 };
104634
104635 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
104636 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
104637 index b953fb4..1999c01 100644
104638 --- a/sound/drivers/opl4/opl4_lib.c
104639 +++ b/sound/drivers/opl4/opl4_lib.c
104640 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
104641 MODULE_DESCRIPTION("OPL4 driver");
104642 MODULE_LICENSE("GPL");
104643
104644 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
104645 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
104646 {
104647 int timeout = 10;
104648 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
104649 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
104650 index 9919769..d7de36c 100644
104651 --- a/sound/drivers/opl4/opl4_seq.c
104652 +++ b/sound/drivers/opl4/opl4_seq.c
104653 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
104654 static int __init alsa_opl4_synth_init(void)
104655 {
104656 static struct snd_seq_dev_ops ops = {
104657 - snd_opl4_seq_new_device,
104658 - snd_opl4_seq_delete_device
104659 + .init_device = snd_opl4_seq_new_device,
104660 + .free_device = snd_opl4_seq_delete_device
104661 };
104662
104663 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
104664 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
104665 index 991018d..8984740 100644
104666 --- a/sound/drivers/portman2x4.c
104667 +++ b/sound/drivers/portman2x4.c
104668 @@ -48,6 +48,7 @@
104669 #include <sound/initval.h>
104670 #include <sound/rawmidi.h>
104671 #include <sound/control.h>
104672 +#include <asm/local.h>
104673
104674 #define CARD_NAME "Portman 2x4"
104675 #define DRIVER_NAME "portman"
104676 @@ -85,7 +86,7 @@ struct portman {
104677 struct pardevice *pardev;
104678 int pardev_claimed;
104679
104680 - int open_count;
104681 + local_t open_count;
104682 int mode[PORTMAN_NUM_INPUT_PORTS];
104683 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
104684 };
104685 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
104686 index 9048777..2d8b1fc 100644
104687 --- a/sound/firewire/amdtp.c
104688 +++ b/sound/firewire/amdtp.c
104689 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
104690 ptr = s->pcm_buffer_pointer + data_blocks;
104691 if (ptr >= pcm->runtime->buffer_size)
104692 ptr -= pcm->runtime->buffer_size;
104693 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
104694 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
104695
104696 s->pcm_period_pointer += data_blocks;
104697 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
104698 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
104699 */
104700 void amdtp_out_stream_update(struct amdtp_out_stream *s)
104701 {
104702 - ACCESS_ONCE(s->source_node_id_field) =
104703 + ACCESS_ONCE_RW(s->source_node_id_field) =
104704 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
104705 }
104706 EXPORT_SYMBOL(amdtp_out_stream_update);
104707 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
104708 index 2746ecd..c35dedd 100644
104709 --- a/sound/firewire/amdtp.h
104710 +++ b/sound/firewire/amdtp.h
104711 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
104712 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
104713 struct snd_pcm_substream *pcm)
104714 {
104715 - ACCESS_ONCE(s->pcm) = pcm;
104716 + ACCESS_ONCE_RW(s->pcm) = pcm;
104717 }
104718
104719 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
104720 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
104721 index fd42e6b..c041971 100644
104722 --- a/sound/firewire/isight.c
104723 +++ b/sound/firewire/isight.c
104724 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
104725 ptr += count;
104726 if (ptr >= runtime->buffer_size)
104727 ptr -= runtime->buffer_size;
104728 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
104729 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
104730
104731 isight->period_counter += count;
104732 if (isight->period_counter >= runtime->period_size) {
104733 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
104734 if (err < 0)
104735 return err;
104736
104737 - ACCESS_ONCE(isight->pcm_active) = true;
104738 + ACCESS_ONCE_RW(isight->pcm_active) = true;
104739
104740 return 0;
104741 }
104742 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
104743 {
104744 struct isight *isight = substream->private_data;
104745
104746 - ACCESS_ONCE(isight->pcm_active) = false;
104747 + ACCESS_ONCE_RW(isight->pcm_active) = false;
104748
104749 mutex_lock(&isight->mutex);
104750 isight_stop_streaming(isight);
104751 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
104752
104753 switch (cmd) {
104754 case SNDRV_PCM_TRIGGER_START:
104755 - ACCESS_ONCE(isight->pcm_running) = true;
104756 + ACCESS_ONCE_RW(isight->pcm_running) = true;
104757 break;
104758 case SNDRV_PCM_TRIGGER_STOP:
104759 - ACCESS_ONCE(isight->pcm_running) = false;
104760 + ACCESS_ONCE_RW(isight->pcm_running) = false;
104761 break;
104762 default:
104763 return -EINVAL;
104764 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
104765 index 858023c..83b3d3c 100644
104766 --- a/sound/firewire/scs1x.c
104767 +++ b/sound/firewire/scs1x.c
104768 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
104769 {
104770 struct scs *scs = stream->rmidi->private_data;
104771
104772 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
104773 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
104774 if (up) {
104775 scs->output_idle = false;
104776 tasklet_schedule(&scs->tasklet);
104777 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
104778 {
104779 struct scs *scs = stream->rmidi->private_data;
104780
104781 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
104782 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
104783 }
104784
104785 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
104786 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
104787
104788 snd_card_disconnect(scs->card);
104789
104790 - ACCESS_ONCE(scs->output) = NULL;
104791 - ACCESS_ONCE(scs->input) = NULL;
104792 + ACCESS_ONCE_RW(scs->output) = NULL;
104793 + ACCESS_ONCE_RW(scs->input) = NULL;
104794
104795 wait_event(scs->idle_wait, scs->output_idle);
104796
104797 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
104798 index 4e3fcfb..ab45a9d 100644
104799 --- a/sound/isa/sb/emu8000_synth.c
104800 +++ b/sound/isa/sb/emu8000_synth.c
104801 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
104802 {
104803
104804 static struct snd_seq_dev_ops ops = {
104805 - snd_emu8000_new_device,
104806 - snd_emu8000_delete_device,
104807 + .init_device = snd_emu8000_new_device,
104808 + .free_device = snd_emu8000_delete_device,
104809 };
104810 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
104811 sizeof(struct snd_emu8000*));
104812 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
104813 index 048439a..3be9f6f 100644
104814 --- a/sound/oss/sb_audio.c
104815 +++ b/sound/oss/sb_audio.c
104816 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
104817 buf16 = (signed short *)(localbuf + localoffs);
104818 while (c)
104819 {
104820 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
104821 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
104822 if (copy_from_user(lbuf8,
104823 userbuf+useroffs + p,
104824 locallen))
104825 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
104826 index f851fd0..92576fb 100644
104827 --- a/sound/oss/swarm_cs4297a.c
104828 +++ b/sound/oss/swarm_cs4297a.c
104829 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
104830 {
104831 struct cs4297a_state *s;
104832 u32 pwr, id;
104833 - mm_segment_t fs;
104834 int rval;
104835 #ifndef CONFIG_BCM_CS4297A_CSWARM
104836 u64 cfg;
104837 @@ -2713,22 +2712,23 @@ static int __init cs4297a_init(void)
104838 if (!rval) {
104839 char *sb1250_duart_present;
104840
104841 +#if 0
104842 + mm_segment_t fs;
104843 fs = get_fs();
104844 set_fs(KERNEL_DS);
104845 -#if 0
104846 val = SOUND_MASK_LINE;
104847 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
104848 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
104849 val = initvol[i].vol;
104850 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
104851 }
104852 + set_fs(fs);
104853 // cs4297a_write_ac97(s, 0x18, 0x0808);
104854 #else
104855 // cs4297a_write_ac97(s, 0x5e, 0x180);
104856 cs4297a_write_ac97(s, 0x02, 0x0808);
104857 cs4297a_write_ac97(s, 0x18, 0x0808);
104858 #endif
104859 - set_fs(fs);
104860
104861 list_add(&s->list, &cs4297a_devs);
104862
104863 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
104864 index 4c41c90..37f3631 100644
104865 --- a/sound/pci/emu10k1/emu10k1_synth.c
104866 +++ b/sound/pci/emu10k1/emu10k1_synth.c
104867 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
104868 {
104869
104870 static struct snd_seq_dev_ops ops = {
104871 - snd_emu10k1_synth_new_device,
104872 - snd_emu10k1_synth_delete_device,
104873 + .init_device = snd_emu10k1_synth_new_device,
104874 + .free_device = snd_emu10k1_synth_delete_device,
104875 };
104876 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
104877 sizeof(struct snd_emu10k1_synth_arg));
104878 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
104879 index dafcf82..dd9356f 100644
104880 --- a/sound/pci/hda/hda_codec.c
104881 +++ b/sound/pci/hda/hda_codec.c
104882 @@ -983,14 +983,10 @@ find_codec_preset(struct hda_codec *codec)
104883 mutex_unlock(&preset_mutex);
104884
104885 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
104886 - char name[32];
104887 if (!mod_requested)
104888 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
104889 - codec->vendor_id);
104890 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
104891 else
104892 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
104893 - (codec->vendor_id >> 16) & 0xffff);
104894 - request_module(name);
104895 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
104896 mod_requested++;
104897 goto again;
104898 }
104899 @@ -2739,7 +2735,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
104900 /* FIXME: set_fs() hack for obtaining user-space TLV data */
104901 mm_segment_t fs = get_fs();
104902 set_fs(get_ds());
104903 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
104904 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
104905 tlv = _tlv;
104906 set_fs(fs);
104907 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
104908 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
104909 index 4631a23..001ae57 100644
104910 --- a/sound/pci/ymfpci/ymfpci.h
104911 +++ b/sound/pci/ymfpci/ymfpci.h
104912 @@ -358,7 +358,7 @@ struct snd_ymfpci {
104913 spinlock_t reg_lock;
104914 spinlock_t voice_lock;
104915 wait_queue_head_t interrupt_sleep;
104916 - atomic_t interrupt_sleep_count;
104917 + atomic_unchecked_t interrupt_sleep_count;
104918 struct snd_info_entry *proc_entry;
104919 const struct firmware *dsp_microcode;
104920 const struct firmware *controller_microcode;
104921 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
104922 index d591c15..8cb8f94 100644
104923 --- a/sound/pci/ymfpci/ymfpci_main.c
104924 +++ b/sound/pci/ymfpci/ymfpci_main.c
104925 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
104926 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
104927 break;
104928 }
104929 - if (atomic_read(&chip->interrupt_sleep_count)) {
104930 - atomic_set(&chip->interrupt_sleep_count, 0);
104931 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
104932 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
104933 wake_up(&chip->interrupt_sleep);
104934 }
104935 __end:
104936 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
104937 continue;
104938 init_waitqueue_entry(&wait, current);
104939 add_wait_queue(&chip->interrupt_sleep, &wait);
104940 - atomic_inc(&chip->interrupt_sleep_count);
104941 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
104942 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
104943 remove_wait_queue(&chip->interrupt_sleep, &wait);
104944 }
104945 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
104946 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
104947 spin_unlock(&chip->reg_lock);
104948
104949 - if (atomic_read(&chip->interrupt_sleep_count)) {
104950 - atomic_set(&chip->interrupt_sleep_count, 0);
104951 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
104952 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
104953 wake_up(&chip->interrupt_sleep);
104954 }
104955 }
104956 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
104957 spin_lock_init(&chip->reg_lock);
104958 spin_lock_init(&chip->voice_lock);
104959 init_waitqueue_head(&chip->interrupt_sleep);
104960 - atomic_set(&chip->interrupt_sleep_count, 0);
104961 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
104962 chip->card = card;
104963 chip->pci = pci;
104964 chip->irq = -1;
104965 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
104966 index 5428a1f..474f651 100644
104967 --- a/sound/soc/fsl/fsl_ssi.c
104968 +++ b/sound/soc/fsl/fsl_ssi.c
104969 @@ -1255,7 +1255,6 @@ static int fsl_ssi_probe(struct platform_device *pdev)
104970 {
104971 struct fsl_ssi_private *ssi_private;
104972 int ret = 0;
104973 - struct device_attribute *dev_attr = NULL;
104974 struct device_node *np = pdev->dev.of_node;
104975 const struct of_device_id *of_id;
104976 enum fsl_ssi_type hw_type;
104977 @@ -1481,7 +1480,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
104978 &ssi_private->cpu_dai_drv, 1);
104979 if (ret) {
104980 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
104981 - goto error_dev;
104982 + goto error_clk;
104983 }
104984
104985 ret = fsl_ssi_debugfs_create(ssi_private, &pdev->dev);
104986 @@ -1562,9 +1561,6 @@ error_pcm:
104987 error_dbgfs:
104988 snd_soc_unregister_component(&pdev->dev);
104989
104990 -error_dev:
104991 - device_remove_file(&pdev->dev, dev_attr);
104992 -
104993 error_clk:
104994 if (ssi_private->ssi_on_imx) {
104995 if (!IS_ERR(ssi_private->baudclk))
104996 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
104997 index fe1df50..09d3be6 100644
104998 --- a/sound/soc/soc-core.c
104999 +++ b/sound/soc/soc-core.c
105000 @@ -2254,8 +2254,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
105001 if (ret)
105002 return ret;
105003
105004 - ops->warm_reset = snd_soc_ac97_warm_reset;
105005 - ops->reset = snd_soc_ac97_reset;
105006 + pax_open_kernel();
105007 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
105008 + *(void **)&ops->reset = snd_soc_ac97_reset;
105009 + pax_close_kernel();
105010
105011 snd_ac97_rst_cfg = cfg;
105012 return 0;
105013 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
105014 index 7778b8e..3d619fc 100644
105015 --- a/sound/synth/emux/emux_seq.c
105016 +++ b/sound/synth/emux/emux_seq.c
105017 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
105018 * MIDI emulation operators
105019 */
105020 static struct snd_midi_op emux_ops = {
105021 - snd_emux_note_on,
105022 - snd_emux_note_off,
105023 - snd_emux_key_press,
105024 - snd_emux_terminate_note,
105025 - snd_emux_control,
105026 - snd_emux_nrpn,
105027 - snd_emux_sysex,
105028 + .note_on = snd_emux_note_on,
105029 + .note_off = snd_emux_note_off,
105030 + .key_press = snd_emux_key_press,
105031 + .note_terminate = snd_emux_terminate_note,
105032 + .control = snd_emux_control,
105033 + .nrpn = snd_emux_nrpn,
105034 + .sysex = snd_emux_sysex,
105035 };
105036
105037
105038 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
105039 new file mode 100644
105040 index 0000000..4c2c45c
105041 --- /dev/null
105042 +++ b/tools/gcc/.gitignore
105043 @@ -0,0 +1,2 @@
105044 +randomize_layout_seed.h
105045 +size_overflow_hash.h
105046 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
105047 new file mode 100644
105048 index 0000000..5ca9688
105049 --- /dev/null
105050 +++ b/tools/gcc/Makefile
105051 @@ -0,0 +1,62 @@
105052 +#CC := gcc
105053 +#PLUGIN_SOURCE_FILES := pax_plugin.c
105054 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
105055 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
105056 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
105057 +
105058 +ifeq ($(PLUGINCC),$(HOSTCC))
105059 +HOSTLIBS := hostlibs
105060 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
105061 +else
105062 +HOSTLIBS := hostcxxlibs
105063 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing
105064 +endif
105065 +
105066 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
105067 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
105068 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
105069 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
105070 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
105071 +$(HOSTLIBS)-y += colorize_plugin.so
105072 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
105073 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
105074 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
105075 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
105076 +
105077 +always := $($(HOSTLIBS)-y)
105078 +
105079 +constify_plugin-objs := constify_plugin.o
105080 +stackleak_plugin-objs := stackleak_plugin.o
105081 +kallocstat_plugin-objs := kallocstat_plugin.o
105082 +kernexec_plugin-objs := kernexec_plugin.o
105083 +checker_plugin-objs := checker_plugin.o
105084 +colorize_plugin-objs := colorize_plugin.o
105085 +size_overflow_plugin-objs := size_overflow_plugin.o
105086 +latent_entropy_plugin-objs := latent_entropy_plugin.o
105087 +structleak_plugin-objs := structleak_plugin.o
105088 +randomize_layout_plugin-objs := randomize_layout_plugin.o
105089 +
105090 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
105091 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
105092 +
105093 +quiet_cmd_build_size_overflow_hash = GENHASH $@
105094 + cmd_build_size_overflow_hash = \
105095 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
105096 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
105097 + $(call if_changed,build_size_overflow_hash)
105098 +
105099 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
105100 + cmd_build_size_overflow_hash_aux = \
105101 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
105102 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
105103 + $(call if_changed,build_size_overflow_hash_aux)
105104 +
105105 +targets += size_overflow_hash.h size_overflow_hash_aux.h
105106 +
105107 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
105108 + cmd_create_randomize_layout_seed = \
105109 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
105110 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
105111 + $(call if_changed,create_randomize_layout_seed)
105112 +
105113 +targets += size_overflow_hash.h randomize_layout_seed.h randomize_layout_hash.h
105114 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
105115 new file mode 100644
105116 index 0000000..5452feea
105117 --- /dev/null
105118 +++ b/tools/gcc/checker_plugin.c
105119 @@ -0,0 +1,150 @@
105120 +/*
105121 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
105122 + * Licensed under the GPL v2
105123 + *
105124 + * Note: the choice of the license means that the compilation process is
105125 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105126 + * but for the kernel it doesn't matter since it doesn't link against
105127 + * any of the gcc libraries
105128 + *
105129 + * gcc plugin to implement various sparse (source code checker) features
105130 + *
105131 + * TODO:
105132 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
105133 + *
105134 + * BUGS:
105135 + * - none known
105136 + */
105137 +
105138 +#include "gcc-common.h"
105139 +
105140 +extern void c_register_addr_space (const char *str, addr_space_t as);
105141 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
105142 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
105143 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
105144 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
105145 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
105146 +
105147 +int plugin_is_GPL_compatible;
105148 +
105149 +static struct plugin_info checker_plugin_info = {
105150 + .version = "201304082245",
105151 + .help = NULL,
105152 +};
105153 +
105154 +#define ADDR_SPACE_KERNEL 0
105155 +#define ADDR_SPACE_FORCE_KERNEL 1
105156 +#define ADDR_SPACE_USER 2
105157 +#define ADDR_SPACE_FORCE_USER 3
105158 +#define ADDR_SPACE_IOMEM 0
105159 +#define ADDR_SPACE_FORCE_IOMEM 0
105160 +#define ADDR_SPACE_PERCPU 0
105161 +#define ADDR_SPACE_FORCE_PERCPU 0
105162 +#define ADDR_SPACE_RCU 0
105163 +#define ADDR_SPACE_FORCE_RCU 0
105164 +
105165 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
105166 +{
105167 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
105168 +}
105169 +
105170 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
105171 +{
105172 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
105173 +}
105174 +
105175 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
105176 +{
105177 + return default_addr_space_valid_pointer_mode(mode, as);
105178 +}
105179 +
105180 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
105181 +{
105182 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
105183 +}
105184 +
105185 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
105186 +{
105187 + return default_addr_space_legitimize_address(x, oldx, mode, as);
105188 +}
105189 +
105190 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
105191 +{
105192 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
105193 + return true;
105194 +
105195 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
105196 + return true;
105197 +
105198 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
105199 + return true;
105200 +
105201 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
105202 + return true;
105203 +
105204 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
105205 + return true;
105206 +
105207 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
105208 + return true;
105209 +
105210 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
105211 + return true;
105212 +
105213 + return subset == superset;
105214 +}
105215 +
105216 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
105217 +{
105218 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
105219 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
105220 +
105221 + return op;
105222 +}
105223 +
105224 +static void register_checker_address_spaces(void *event_data, void *data)
105225 +{
105226 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
105227 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
105228 + c_register_addr_space("__user", ADDR_SPACE_USER);
105229 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
105230 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
105231 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
105232 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
105233 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
105234 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
105235 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
105236 +
105237 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
105238 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
105239 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
105240 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
105241 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
105242 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
105243 + targetm.addr_space.convert = checker_addr_space_convert;
105244 +}
105245 +
105246 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105247 +{
105248 + const char * const plugin_name = plugin_info->base_name;
105249 + const int argc = plugin_info->argc;
105250 + const struct plugin_argument * const argv = plugin_info->argv;
105251 + int i;
105252 +
105253 + if (!plugin_default_version_check(version, &gcc_version)) {
105254 + error(G_("incompatible gcc/plugin versions"));
105255 + return 1;
105256 + }
105257 +
105258 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
105259 +
105260 + for (i = 0; i < argc; ++i)
105261 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105262 +
105263 + if (TARGET_64BIT == 0)
105264 + return 0;
105265 +
105266 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
105267 +
105268 + return 0;
105269 +}
105270 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
105271 new file mode 100644
105272 index 0000000..06dcfda
105273 --- /dev/null
105274 +++ b/tools/gcc/colorize_plugin.c
105275 @@ -0,0 +1,169 @@
105276 +/*
105277 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
105278 + * Licensed under the GPL v2
105279 + *
105280 + * Note: the choice of the license means that the compilation process is
105281 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105282 + * but for the kernel it doesn't matter since it doesn't link against
105283 + * any of the gcc libraries
105284 + *
105285 + * gcc plugin to colorize diagnostic output
105286 + *
105287 + */
105288 +
105289 +#include "gcc-common.h"
105290 +
105291 +int plugin_is_GPL_compatible;
105292 +
105293 +static struct plugin_info colorize_plugin_info = {
105294 + .version = "201401260140",
105295 + .help = NULL,
105296 +};
105297 +
105298 +#define GREEN "\033[32m\033[2m"
105299 +#define LIGHTGREEN "\033[32m\033[1m"
105300 +#define YELLOW "\033[33m\033[2m"
105301 +#define LIGHTYELLOW "\033[33m\033[1m"
105302 +#define RED "\033[31m\033[2m"
105303 +#define LIGHTRED "\033[31m\033[1m"
105304 +#define BLUE "\033[34m\033[2m"
105305 +#define LIGHTBLUE "\033[34m\033[1m"
105306 +#define BRIGHT "\033[m\033[1m"
105307 +#define NORMAL "\033[m"
105308 +
105309 +static diagnostic_starter_fn old_starter;
105310 +static diagnostic_finalizer_fn old_finalizer;
105311 +
105312 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105313 +{
105314 + const char *color;
105315 + char *newprefix;
105316 +
105317 + switch (diagnostic->kind) {
105318 + case DK_NOTE:
105319 + color = LIGHTBLUE;
105320 + break;
105321 +
105322 + case DK_PEDWARN:
105323 + case DK_WARNING:
105324 + color = LIGHTYELLOW;
105325 + break;
105326 +
105327 + case DK_ERROR:
105328 + case DK_FATAL:
105329 + case DK_ICE:
105330 + case DK_PERMERROR:
105331 + case DK_SORRY:
105332 + color = LIGHTRED;
105333 + break;
105334 +
105335 + default:
105336 + color = NORMAL;
105337 + }
105338 +
105339 + old_starter(context, diagnostic);
105340 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
105341 + return;
105342 + pp_destroy_prefix(context->printer);
105343 + pp_set_prefix(context->printer, newprefix);
105344 +}
105345 +
105346 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
105347 +{
105348 + old_finalizer(context, diagnostic);
105349 +}
105350 +
105351 +static void colorize_arm(void)
105352 +{
105353 + old_starter = diagnostic_starter(global_dc);
105354 + old_finalizer = diagnostic_finalizer(global_dc);
105355 +
105356 + diagnostic_starter(global_dc) = start_colorize;
105357 + diagnostic_finalizer(global_dc) = finalize_colorize;
105358 +}
105359 +
105360 +static unsigned int execute_colorize_rearm(void)
105361 +{
105362 + if (diagnostic_starter(global_dc) == start_colorize)
105363 + return 0;
105364 +
105365 + colorize_arm();
105366 + return 0;
105367 +}
105368 +
105369 +#if BUILDING_GCC_VERSION >= 4009
105370 +static const struct pass_data colorize_rearm_pass_data = {
105371 +#else
105372 +struct simple_ipa_opt_pass colorize_rearm_pass = {
105373 + .pass = {
105374 +#endif
105375 + .type = SIMPLE_IPA_PASS,
105376 + .name = "colorize_rearm",
105377 +#if BUILDING_GCC_VERSION >= 4008
105378 + .optinfo_flags = OPTGROUP_NONE,
105379 +#endif
105380 +#if BUILDING_GCC_VERSION >= 4009
105381 + .has_gate = false,
105382 + .has_execute = true,
105383 +#else
105384 + .gate = NULL,
105385 + .execute = execute_colorize_rearm,
105386 + .sub = NULL,
105387 + .next = NULL,
105388 + .static_pass_number = 0,
105389 +#endif
105390 + .tv_id = TV_NONE,
105391 + .properties_required = 0,
105392 + .properties_provided = 0,
105393 + .properties_destroyed = 0,
105394 + .todo_flags_start = 0,
105395 + .todo_flags_finish = 0
105396 +#if BUILDING_GCC_VERSION < 4009
105397 + }
105398 +#endif
105399 +};
105400 +
105401 +#if BUILDING_GCC_VERSION >= 4009
105402 +namespace {
105403 +class colorize_rearm_pass : public simple_ipa_opt_pass {
105404 +public:
105405 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
105406 + unsigned int execute() { return execute_colorize_rearm(); }
105407 +};
105408 +}
105409 +#endif
105410 +
105411 +static struct opt_pass *make_colorize_rearm_pass(void)
105412 +{
105413 +#if BUILDING_GCC_VERSION >= 4009
105414 + return new colorize_rearm_pass();
105415 +#else
105416 + return &colorize_rearm_pass.pass;
105417 +#endif
105418 +}
105419 +
105420 +static void colorize_start_unit(void *gcc_data, void *user_data)
105421 +{
105422 + colorize_arm();
105423 +}
105424 +
105425 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105426 +{
105427 + const char * const plugin_name = plugin_info->base_name;
105428 + struct register_pass_info colorize_rearm_pass_info;
105429 +
105430 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
105431 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
105432 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
105433 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105434 +
105435 + if (!plugin_default_version_check(version, &gcc_version)) {
105436 + error(G_("incompatible gcc/plugin versions"));
105437 + return 1;
105438 + }
105439 +
105440 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
105441 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
105442 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
105443 + return 0;
105444 +}
105445 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
105446 new file mode 100644
105447 index 0000000..4f67ac1
105448 --- /dev/null
105449 +++ b/tools/gcc/constify_plugin.c
105450 @@ -0,0 +1,552 @@
105451 +/*
105452 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
105453 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
105454 + * Licensed under the GPL v2, or (at your option) v3
105455 + *
105456 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
105457 + *
105458 + * Homepage:
105459 + * http://www.grsecurity.net/~ephox/const_plugin/
105460 + *
105461 + * Usage:
105462 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
105463 + * $ gcc -fplugin=constify_plugin.so test.c -O2
105464 + */
105465 +
105466 +#include "gcc-common.h"
105467 +
105468 +// unused C type flag in all versions 4.5-4.9
105469 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
105470 +
105471 +int plugin_is_GPL_compatible;
105472 +
105473 +static struct plugin_info const_plugin_info = {
105474 + .version = "201401270210",
105475 + .help = "no-constify\tturn off constification\n",
105476 +};
105477 +
105478 +typedef struct {
105479 + bool has_fptr_field;
105480 + bool has_writable_field;
105481 + bool has_do_const_field;
105482 + bool has_no_const_field;
105483 +} constify_info;
105484 +
105485 +static const_tree get_field_type(const_tree field)
105486 +{
105487 + return strip_array_types(TREE_TYPE(field));
105488 +}
105489 +
105490 +static bool is_fptr(const_tree field)
105491 +{
105492 + const_tree ptr = get_field_type(field);
105493 +
105494 + if (TREE_CODE(ptr) != POINTER_TYPE)
105495 + return false;
105496 +
105497 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
105498 +}
105499 +
105500 +/*
105501 + * determine whether the given structure type meets the requirements for automatic constification,
105502 + * including the constification attributes on nested structure types
105503 + */
105504 +static void constifiable(const_tree node, constify_info *cinfo)
105505 +{
105506 + const_tree field;
105507 +
105508 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
105509 +
105510 + // e.g., pointer to structure fields while still constructing the structure type
105511 + if (TYPE_FIELDS(node) == NULL_TREE)
105512 + return;
105513 +
105514 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
105515 + const_tree type = get_field_type(field);
105516 + enum tree_code code = TREE_CODE(type);
105517 +
105518 + if (node == type)
105519 + continue;
105520 +
105521 + if (is_fptr(field))
105522 + cinfo->has_fptr_field = true;
105523 + else if (!TREE_READONLY(field))
105524 + cinfo->has_writable_field = true;
105525 +
105526 + if (code == RECORD_TYPE || code == UNION_TYPE) {
105527 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
105528 + cinfo->has_do_const_field = true;
105529 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
105530 + cinfo->has_no_const_field = true;
105531 + else
105532 + constifiable(type, cinfo);
105533 + }
105534 + }
105535 +}
105536 +
105537 +static bool constified(const_tree node)
105538 +{
105539 + constify_info cinfo = {
105540 + .has_fptr_field = false,
105541 + .has_writable_field = false,
105542 + .has_do_const_field = false,
105543 + .has_no_const_field = false
105544 + };
105545 +
105546 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
105547 +
105548 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
105549 +// gcc_assert(!TYPE_READONLY(node));
105550 + return false;
105551 + }
105552 +
105553 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
105554 + gcc_assert(TYPE_READONLY(node));
105555 + return true;
105556 + }
105557 +
105558 + constifiable(node, &cinfo);
105559 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
105560 + return false;
105561 +
105562 + return TYPE_READONLY(node);
105563 +}
105564 +
105565 +static void deconstify_tree(tree node);
105566 +
105567 +static void deconstify_type(tree type)
105568 +{
105569 + tree field;
105570 +
105571 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
105572 +
105573 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
105574 + const_tree fieldtype = get_field_type(field);
105575 +
105576 + // special case handling of simple ptr-to-same-array-type members
105577 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
105578 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
105579 +
105580 + if (TREE_TYPE(TREE_TYPE(field)) == type)
105581 + continue;
105582 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
105583 + continue;
105584 + if (!constified(ptrtype))
105585 + continue;
105586 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
105587 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
105588 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
105589 + }
105590 + continue;
105591 + }
105592 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
105593 + continue;
105594 + if (!constified(fieldtype))
105595 + continue;
105596 +
105597 + deconstify_tree(field);
105598 + TREE_READONLY(field) = 0;
105599 + }
105600 + TYPE_READONLY(type) = 0;
105601 + C_TYPE_FIELDS_READONLY(type) = 0;
105602 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105603 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
105604 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
105605 + }
105606 +}
105607 +
105608 +static void deconstify_tree(tree node)
105609 +{
105610 + tree old_type, new_type, field;
105611 +
105612 + old_type = TREE_TYPE(node);
105613 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
105614 + node = TREE_TYPE(node) = copy_node(old_type);
105615 + old_type = TREE_TYPE(old_type);
105616 + }
105617 +
105618 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
105619 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
105620 +
105621 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
105622 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
105623 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
105624 + DECL_FIELD_CONTEXT(field) = new_type;
105625 +
105626 + deconstify_type(new_type);
105627 +
105628 + TREE_TYPE(node) = new_type;
105629 +}
105630 +
105631 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105632 +{
105633 + tree type;
105634 + constify_info cinfo = {
105635 + .has_fptr_field = false,
105636 + .has_writable_field = false,
105637 + .has_do_const_field = false,
105638 + .has_no_const_field = false
105639 + };
105640 +
105641 + *no_add_attrs = true;
105642 + if (TREE_CODE(*node) == FUNCTION_DECL) {
105643 + error("%qE attribute does not apply to functions (%qF)", name, *node);
105644 + return NULL_TREE;
105645 + }
105646 +
105647 + if (TREE_CODE(*node) == PARM_DECL) {
105648 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
105649 + return NULL_TREE;
105650 + }
105651 +
105652 + if (TREE_CODE(*node) == VAR_DECL) {
105653 + error("%qE attribute does not apply to variables (%qD)", name, *node);
105654 + return NULL_TREE;
105655 + }
105656 +
105657 + if (TYPE_P(*node)) {
105658 + type = *node;
105659 + } else {
105660 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
105661 + type = TREE_TYPE(*node);
105662 + }
105663 +
105664 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
105665 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
105666 + return NULL_TREE;
105667 + }
105668 +
105669 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
105670 + error("%qE attribute is already applied to the type %qT", name, type);
105671 + return NULL_TREE;
105672 + }
105673 +
105674 + if (TYPE_P(*node)) {
105675 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
105676 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
105677 + else
105678 + *no_add_attrs = false;
105679 + return NULL_TREE;
105680 + }
105681 +
105682 + constifiable(type, &cinfo);
105683 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105684 + deconstify_tree(*node);
105685 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
105686 + return NULL_TREE;
105687 + }
105688 +
105689 + error("%qE attribute used on type %qT that is not constified", name, type);
105690 + return NULL_TREE;
105691 +}
105692 +
105693 +static void constify_type(tree type)
105694 +{
105695 + TYPE_READONLY(type) = 1;
105696 + C_TYPE_FIELDS_READONLY(type) = 1;
105697 + TYPE_CONSTIFY_VISITED(type) = 1;
105698 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
105699 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
105700 +}
105701 +
105702 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105703 +{
105704 + *no_add_attrs = true;
105705 + if (!TYPE_P(*node)) {
105706 + error("%qE attribute applies to types only (%qD)", name, *node);
105707 + return NULL_TREE;
105708 + }
105709 +
105710 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
105711 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
105712 + return NULL_TREE;
105713 + }
105714 +
105715 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
105716 + error("%qE attribute used on %qT is already applied to the type", name, *node);
105717 + return NULL_TREE;
105718 + }
105719 +
105720 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
105721 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
105722 + return NULL_TREE;
105723 + }
105724 +
105725 + *no_add_attrs = false;
105726 + return NULL_TREE;
105727 +}
105728 +
105729 +static struct attribute_spec no_const_attr = {
105730 + .name = "no_const",
105731 + .min_length = 0,
105732 + .max_length = 0,
105733 + .decl_required = false,
105734 + .type_required = false,
105735 + .function_type_required = false,
105736 + .handler = handle_no_const_attribute,
105737 +#if BUILDING_GCC_VERSION >= 4007
105738 + .affects_type_identity = true
105739 +#endif
105740 +};
105741 +
105742 +static struct attribute_spec do_const_attr = {
105743 + .name = "do_const",
105744 + .min_length = 0,
105745 + .max_length = 0,
105746 + .decl_required = false,
105747 + .type_required = false,
105748 + .function_type_required = false,
105749 + .handler = handle_do_const_attribute,
105750 +#if BUILDING_GCC_VERSION >= 4007
105751 + .affects_type_identity = true
105752 +#endif
105753 +};
105754 +
105755 +static void register_attributes(void *event_data, void *data)
105756 +{
105757 + register_attribute(&no_const_attr);
105758 + register_attribute(&do_const_attr);
105759 +}
105760 +
105761 +static void finish_type(void *event_data, void *data)
105762 +{
105763 + tree type = (tree)event_data;
105764 + constify_info cinfo = {
105765 + .has_fptr_field = false,
105766 + .has_writable_field = false,
105767 + .has_do_const_field = false,
105768 + .has_no_const_field = false
105769 + };
105770 +
105771 + if (type == NULL_TREE || type == error_mark_node)
105772 + return;
105773 +
105774 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
105775 + return;
105776 +
105777 + constifiable(type, &cinfo);
105778 +
105779 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
105780 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
105781 + deconstify_type(type);
105782 + TYPE_CONSTIFY_VISITED(type) = 1;
105783 + } else
105784 + error("'no_const' attribute used on type %qT that is not constified", type);
105785 + return;
105786 + }
105787 +
105788 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105789 + if (!cinfo.has_writable_field) {
105790 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
105791 + return;
105792 + }
105793 + constify_type(type);
105794 + return;
105795 + }
105796 +
105797 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
105798 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
105799 + error("'do_const' attribute used on type %qT that is constified", type);
105800 + return;
105801 + }
105802 + constify_type(type);
105803 + return;
105804 + }
105805 +
105806 + deconstify_type(type);
105807 + TYPE_CONSTIFY_VISITED(type) = 1;
105808 +}
105809 +
105810 +static void check_global_variables(void *event_data, void *data)
105811 +{
105812 + struct varpool_node *node;
105813 +
105814 + FOR_EACH_VARIABLE(node) {
105815 + tree var = NODE_DECL(node);
105816 + tree type = TREE_TYPE(var);
105817 +
105818 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
105819 + continue;
105820 +
105821 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
105822 + continue;
105823 +
105824 + if (!TYPE_CONSTIFY_VISITED(type))
105825 + continue;
105826 +
105827 + if (DECL_EXTERNAL(var))
105828 + continue;
105829 +
105830 + if (DECL_INITIAL(var))
105831 + continue;
105832 +
105833 + // this works around a gcc bug/feature where uninitialized globals
105834 + // are moved into the .bss section regardless of any constification
105835 + DECL_INITIAL(var) = build_constructor(type, NULL);
105836 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
105837 + }
105838 +}
105839 +
105840 +static unsigned int check_local_variables(void)
105841 +{
105842 + unsigned int ret = 0;
105843 + tree var;
105844 +
105845 + unsigned int i;
105846 +
105847 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
105848 + tree type = TREE_TYPE(var);
105849 +
105850 + gcc_assert(DECL_P(var));
105851 + if (is_global_var(var))
105852 + continue;
105853 +
105854 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
105855 + continue;
105856 +
105857 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
105858 + continue;
105859 +
105860 + if (!TYPE_CONSTIFY_VISITED(type))
105861 + continue;
105862 +
105863 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
105864 + ret = 1;
105865 + }
105866 + return ret;
105867 +}
105868 +
105869 +#if BUILDING_GCC_VERSION >= 4009
105870 +static const struct pass_data check_local_variables_pass_data = {
105871 +#else
105872 +static struct gimple_opt_pass check_local_variables_pass = {
105873 + .pass = {
105874 +#endif
105875 + .type = GIMPLE_PASS,
105876 + .name = "check_local_variables",
105877 +#if BUILDING_GCC_VERSION >= 4008
105878 + .optinfo_flags = OPTGROUP_NONE,
105879 +#endif
105880 +#if BUILDING_GCC_VERSION >= 4009
105881 + .has_gate = false,
105882 + .has_execute = true,
105883 +#else
105884 + .gate = NULL,
105885 + .execute = check_local_variables,
105886 + .sub = NULL,
105887 + .next = NULL,
105888 + .static_pass_number = 0,
105889 +#endif
105890 + .tv_id = TV_NONE,
105891 + .properties_required = 0,
105892 + .properties_provided = 0,
105893 + .properties_destroyed = 0,
105894 + .todo_flags_start = 0,
105895 + .todo_flags_finish = 0
105896 +#if BUILDING_GCC_VERSION < 4009
105897 + }
105898 +#endif
105899 +};
105900 +
105901 +#if BUILDING_GCC_VERSION >= 4009
105902 +namespace {
105903 +class check_local_variables_pass : public gimple_opt_pass {
105904 +public:
105905 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
105906 + unsigned int execute() { return check_local_variables(); }
105907 +};
105908 +}
105909 +#endif
105910 +
105911 +static struct opt_pass *make_check_local_variables_pass(void)
105912 +{
105913 +#if BUILDING_GCC_VERSION >= 4009
105914 + return new check_local_variables_pass();
105915 +#else
105916 + return &check_local_variables_pass.pass;
105917 +#endif
105918 +}
105919 +
105920 +static struct {
105921 + const char *name;
105922 + const char *asm_op;
105923 +} sections[] = {
105924 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
105925 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
105926 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
105927 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
105928 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
105929 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
105930 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
105931 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
105932 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
105933 +};
105934 +
105935 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
105936 +
105937 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
105938 +{
105939 + size_t i;
105940 +
105941 + for (i = 0; i < ARRAY_SIZE(sections); i++)
105942 + if (!strcmp(sections[i].name, name))
105943 + return 0;
105944 + return old_section_type_flags(decl, name, reloc);
105945 +}
105946 +
105947 +static void constify_start_unit(void *gcc_data, void *user_data)
105948 +{
105949 +// size_t i;
105950 +
105951 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
105952 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
105953 +// sections[i].section = get_section(sections[i].name, 0, NULL);
105954 +
105955 + old_section_type_flags = targetm.section_type_flags;
105956 + targetm.section_type_flags = constify_section_type_flags;
105957 +}
105958 +
105959 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105960 +{
105961 + const char * const plugin_name = plugin_info->base_name;
105962 + const int argc = plugin_info->argc;
105963 + const struct plugin_argument * const argv = plugin_info->argv;
105964 + int i;
105965 + bool constify = true;
105966 +
105967 + struct register_pass_info check_local_variables_pass_info;
105968 +
105969 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
105970 + check_local_variables_pass_info.reference_pass_name = "ssa";
105971 + check_local_variables_pass_info.ref_pass_instance_number = 1;
105972 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
105973 +
105974 + if (!plugin_default_version_check(version, &gcc_version)) {
105975 + error(G_("incompatible gcc/plugin versions"));
105976 + return 1;
105977 + }
105978 +
105979 + for (i = 0; i < argc; ++i) {
105980 + if (!(strcmp(argv[i].key, "no-constify"))) {
105981 + constify = false;
105982 + continue;
105983 + }
105984 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105985 + }
105986 +
105987 + if (strcmp(lang_hooks.name, "GNU C")) {
105988 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
105989 + constify = false;
105990 + }
105991 +
105992 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
105993 + if (constify) {
105994 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
105995 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
105996 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
105997 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
105998 + }
105999 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
106000 +
106001 + return 0;
106002 +}
106003 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
106004 new file mode 100644
106005 index 0000000..8af3693
106006 --- /dev/null
106007 +++ b/tools/gcc/gcc-common.h
106008 @@ -0,0 +1,287 @@
106009 +#ifndef GCC_COMMON_H_INCLUDED
106010 +#define GCC_COMMON_H_INCLUDED
106011 +
106012 +#include "plugin.h"
106013 +#include "bversion.h"
106014 +#include "plugin-version.h"
106015 +#include "config.h"
106016 +#include "system.h"
106017 +#include "coretypes.h"
106018 +#include "tm.h"
106019 +#include "line-map.h"
106020 +#include "input.h"
106021 +#include "tree.h"
106022 +
106023 +#include "tree-inline.h"
106024 +#include "version.h"
106025 +#include "rtl.h"
106026 +#include "tm_p.h"
106027 +#include "flags.h"
106028 +//#include "insn-attr.h"
106029 +//#include "insn-config.h"
106030 +//#include "insn-flags.h"
106031 +#include "hard-reg-set.h"
106032 +//#include "recog.h"
106033 +#include "output.h"
106034 +#include "except.h"
106035 +#include "function.h"
106036 +#include "toplev.h"
106037 +//#include "expr.h"
106038 +#include "basic-block.h"
106039 +#include "intl.h"
106040 +#include "ggc.h"
106041 +//#include "regs.h"
106042 +#include "timevar.h"
106043 +
106044 +#include "params.h"
106045 +#include "pointer-set.h"
106046 +#include "emit-rtl.h"
106047 +//#include "reload.h"
106048 +//#include "ira.h"
106049 +//#include "dwarf2asm.h"
106050 +#include "debug.h"
106051 +#include "target.h"
106052 +#include "langhooks.h"
106053 +#include "cfgloop.h"
106054 +//#include "hosthooks.h"
106055 +#include "cgraph.h"
106056 +#include "opts.h"
106057 +//#include "coverage.h"
106058 +//#include "value-prof.h"
106059 +
106060 +#if BUILDING_GCC_VERSION >= 4007
106061 +#include "tree-pretty-print.h"
106062 +#include "gimple-pretty-print.h"
106063 +#include "c-tree.h"
106064 +//#include "alloc-pool.h"
106065 +#endif
106066 +
106067 +#if BUILDING_GCC_VERSION <= 4008
106068 +#include "tree-flow.h"
106069 +#else
106070 +#include "tree-cfgcleanup.h"
106071 +#endif
106072 +
106073 +#include "diagnostic.h"
106074 +//#include "tree-diagnostic.h"
106075 +#include "tree-dump.h"
106076 +#include "tree-pass.h"
106077 +//#include "df.h"
106078 +#include "predict.h"
106079 +//#include "lto-streamer.h"
106080 +#include "ipa-utils.h"
106081 +
106082 +#if BUILDING_GCC_VERSION >= 4009
106083 +#include "varasm.h"
106084 +#include "stor-layout.h"
106085 +#include "internal-fn.h"
106086 +#include "gimple-expr.h"
106087 +//#include "diagnostic-color.h"
106088 +#include "context.h"
106089 +#include "tree-ssa-alias.h"
106090 +#include "stringpool.h"
106091 +#include "tree-ssanames.h"
106092 +#include "print-tree.h"
106093 +#include "tree-eh.h"
106094 +#endif
106095 +
106096 +#include "gimple.h"
106097 +
106098 +#if BUILDING_GCC_VERSION >= 4009
106099 +#include "tree-ssa-operands.h"
106100 +#include "tree-phinodes.h"
106101 +#include "tree-cfg.h"
106102 +#include "gimple-iterator.h"
106103 +#include "gimple-ssa.h"
106104 +#include "ssa-iterators.h"
106105 +#endif
106106 +
106107 +//#include "expr.h" where are you...
106108 +extern rtx emit_move_insn(rtx x, rtx y);
106109 +
106110 +// missing from basic_block.h...
106111 +extern void debug_dominance_info(enum cdi_direction dir);
106112 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
106113 +
106114 +#define __unused __attribute__((__unused__))
106115 +
106116 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
106117 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
106118 +
106119 +#if BUILDING_GCC_VERSION == 4005
106120 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
106121 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
106122 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
106123 +#define TODO_rebuild_cgraph_edges 0
106124 +
106125 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
106126 +{
106127 + tree fndecl;
106128 +
106129 + if (!is_gimple_call(stmt))
106130 + return false;
106131 + fndecl = gimple_call_fndecl(stmt);
106132 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
106133 + return false;
106134 +// print_node(stderr, "pax", fndecl, 4);
106135 + return DECL_FUNCTION_CODE(fndecl) == code;
106136 +}
106137 +
106138 +static inline bool is_simple_builtin(tree decl)
106139 +{
106140 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
106141 + return false;
106142 +
106143 + switch (DECL_FUNCTION_CODE(decl)) {
106144 + /* Builtins that expand to constants. */
106145 + case BUILT_IN_CONSTANT_P:
106146 + case BUILT_IN_EXPECT:
106147 + case BUILT_IN_OBJECT_SIZE:
106148 + case BUILT_IN_UNREACHABLE:
106149 + /* Simple register moves or loads from stack. */
106150 + case BUILT_IN_RETURN_ADDRESS:
106151 + case BUILT_IN_EXTRACT_RETURN_ADDR:
106152 + case BUILT_IN_FROB_RETURN_ADDR:
106153 + case BUILT_IN_RETURN:
106154 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
106155 + case BUILT_IN_FRAME_ADDRESS:
106156 + case BUILT_IN_VA_END:
106157 + case BUILT_IN_STACK_SAVE:
106158 + case BUILT_IN_STACK_RESTORE:
106159 + /* Exception state returns or moves registers around. */
106160 + case BUILT_IN_EH_FILTER:
106161 + case BUILT_IN_EH_POINTER:
106162 + case BUILT_IN_EH_COPY_VALUES:
106163 + return true;
106164 +
106165 + default:
106166 + return false;
106167 + }
106168 +}
106169 +#endif
106170 +
106171 +#if BUILDING_GCC_VERSION <= 4006
106172 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
106173 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
106174 +
106175 +// should come from c-tree.h if only it were installed for gcc 4.5...
106176 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
106177 +
106178 +#define get_random_seed(noinit) ({ \
106179 + unsigned HOST_WIDE_INT seed; \
106180 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
106181 + seed * seed; })
106182 +
106183 +static inline bool gimple_clobber_p(gimple s)
106184 +{
106185 + return false;
106186 +}
106187 +
106188 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
106189 +{
106190 + return implicit_built_in_decls[fncode];
106191 +}
106192 +
106193 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
106194 +{
106195 + struct cgraph_node *node = cgraph_get_node(decl);
106196 +
106197 + return node ? node : cgraph_node(decl);
106198 +}
106199 +
106200 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
106201 +{
106202 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
106203 +}
106204 +
106205 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
106206 +{
106207 + struct cgraph_node *node;
106208 +
106209 + for (node = cgraph_nodes; node; node = node->next)
106210 + if (cgraph_function_with_gimple_body_p(node))
106211 + return node;
106212 + return NULL;
106213 +}
106214 +
106215 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
106216 +{
106217 + for (node = node->next; node; node = node->next)
106218 + if (cgraph_function_with_gimple_body_p(node))
106219 + return node;
106220 + return NULL;
106221 +}
106222 +
106223 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
106224 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
106225 + (node) = cgraph_next_function_with_gimple_body(node))
106226 +#endif
106227 +
106228 +#if BUILDING_GCC_VERSION == 4006
106229 +extern void debug_gimple_stmt(gimple);
106230 +extern void debug_gimple_seq(gimple_seq);
106231 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
106232 +extern void print_gimple_stmt(FILE *, gimple, int, int);
106233 +extern void print_gimple_expr(FILE *, gimple, int, int);
106234 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
106235 +#endif
106236 +
106237 +#if BUILDING_GCC_VERSION <= 4007
106238 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
106239 +#define PROP_loops 0
106240 +
106241 +static inline int bb_loop_depth(const_basic_block bb)
106242 +{
106243 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
106244 +}
106245 +
106246 +static inline bool gimple_store_p(gimple gs)
106247 +{
106248 + tree lhs = gimple_get_lhs(gs);
106249 + return lhs && !is_gimple_reg(lhs);
106250 +}
106251 +#endif
106252 +
106253 +#if BUILDING_GCC_VERSION >= 4007
106254 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
106255 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
106256 +#endif
106257 +
106258 +#if BUILDING_GCC_VERSION <= 4008
106259 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
106260 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
106261 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
106262 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
106263 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
106264 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
106265 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
106266 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
106267 +
106268 +static inline const char *get_tree_code_name(enum tree_code code)
106269 +{
106270 + gcc_assert(code < MAX_TREE_CODES);
106271 + return tree_code_name[code];
106272 +}
106273 +
106274 +#define ipa_remove_stmt_references(cnode, stmt)
106275 +#endif
106276 +
106277 +#if BUILDING_GCC_VERSION == 4008
106278 +#define NODE_DECL(node) node->symbol.decl
106279 +#else
106280 +#define NODE_DECL(node) node->decl
106281 +#endif
106282 +
106283 +#if BUILDING_GCC_VERSION >= 4008
106284 +#define add_referenced_var(var)
106285 +#define mark_sym_for_renaming(var)
106286 +#define varpool_mark_needed_node(node)
106287 +#define TODO_dump_func 0
106288 +#define TODO_dump_cgraph 0
106289 +#endif
106290 +
106291 +#if BUILDING_GCC_VERSION >= 4009
106292 +#define TODO_ggc_collect 0
106293 +#endif
106294 +
106295 +#endif
106296 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
106297 new file mode 100644
106298 index 0000000..7514850
106299 --- /dev/null
106300 +++ b/tools/gcc/gen-random-seed.sh
106301 @@ -0,0 +1,8 @@
106302 +#!/bin/sh
106303 +
106304 +if [ ! -f "$1" ]; then
106305 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
106306 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
106307 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
106308 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
106309 +fi
106310 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
106311 new file mode 100644
106312 index 0000000..791ca76
106313 --- /dev/null
106314 +++ b/tools/gcc/generate_size_overflow_hash.sh
106315 @@ -0,0 +1,97 @@
106316 +#!/bin/bash
106317 +
106318 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
106319 +
106320 +header1="size_overflow_hash.h"
106321 +database="size_overflow_hash.data"
106322 +n=65536
106323 +hashtable_name="size_overflow_hash"
106324 +
106325 +usage() {
106326 +cat <<EOF
106327 +usage: $0 options
106328 +OPTIONS:
106329 + -h|--help help
106330 + -o header file
106331 + -d database file
106332 + -n hash array size
106333 + -s name of the hash table
106334 +EOF
106335 + return 0
106336 +}
106337 +
106338 +while true
106339 +do
106340 + case "$1" in
106341 + -h|--help) usage && exit 0;;
106342 + -n) n=$2; shift 2;;
106343 + -o) header1="$2"; shift 2;;
106344 + -d) database="$2"; shift 2;;
106345 + -s) hashtable_name="$2"; shift 2;;
106346 + --) shift 1; break ;;
106347 + *) break ;;
106348 + esac
106349 +done
106350 +
106351 +create_defines() {
106352 + for i in `seq 0 31`
106353 + do
106354 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
106355 + done
106356 + echo >> "$header1"
106357 +}
106358 +
106359 +create_structs() {
106360 + rm -f "$header1"
106361 +
106362 + create_defines
106363 +
106364 + cat "$database" | while read data
106365 + do
106366 + data_array=($data)
106367 + struct_hash_name="${data_array[0]}"
106368 + funcn="${data_array[1]}"
106369 + params="${data_array[2]}"
106370 + next="${data_array[4]}"
106371 +
106372 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
106373 +
106374 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
106375 + echo -en "\t.param\t= " >> "$header1"
106376 + line=
106377 + for param_num in ${params//-/ };
106378 + do
106379 + line="${line}PARAM"$param_num"|"
106380 + done
106381 +
106382 + echo -e "${line%?},\n};\n" >> "$header1"
106383 + done
106384 +}
106385 +
106386 +create_headers() {
106387 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
106388 +}
106389 +
106390 +create_array_elements() {
106391 + index=0
106392 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
106393 + do
106394 + data_array=($data)
106395 + i="${data_array[3]}"
106396 + hash="${data_array[0]}"
106397 + while [[ $index -lt $i ]]
106398 + do
106399 + echo -e "\t["$index"]\t= NULL," >> "$header1"
106400 + index=$(($index + 1))
106401 + done
106402 + index=$(($index + 1))
106403 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
106404 + done
106405 + echo '};' >> $header1
106406 +}
106407 +
106408 +create_structs
106409 +create_headers
106410 +create_array_elements
106411 +
106412 +exit 0
106413 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
106414 new file mode 100644
106415 index 0000000..b559327
106416 --- /dev/null
106417 +++ b/tools/gcc/kallocstat_plugin.c
106418 @@ -0,0 +1,182 @@
106419 +/*
106420 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106421 + * Licensed under the GPL v2
106422 + *
106423 + * Note: the choice of the license means that the compilation process is
106424 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106425 + * but for the kernel it doesn't matter since it doesn't link against
106426 + * any of the gcc libraries
106427 + *
106428 + * gcc plugin to find the distribution of k*alloc sizes
106429 + *
106430 + * TODO:
106431 + *
106432 + * BUGS:
106433 + * - none known
106434 + */
106435 +
106436 +#include "gcc-common.h"
106437 +
106438 +int plugin_is_GPL_compatible;
106439 +
106440 +static struct plugin_info kallocstat_plugin_info = {
106441 + .version = "201401260140",
106442 + .help = NULL
106443 +};
106444 +
106445 +static const char * const kalloc_functions[] = {
106446 + "__kmalloc",
106447 + "kmalloc",
106448 + "kmalloc_large",
106449 + "kmalloc_node",
106450 + "kmalloc_order",
106451 + "kmalloc_order_trace",
106452 + "kmalloc_slab",
106453 + "kzalloc",
106454 + "kzalloc_node",
106455 +};
106456 +
106457 +static bool is_kalloc(const char *fnname)
106458 +{
106459 + size_t i;
106460 +
106461 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
106462 + if (!strcmp(fnname, kalloc_functions[i]))
106463 + return true;
106464 + return false;
106465 +}
106466 +
106467 +static unsigned int execute_kallocstat(void)
106468 +{
106469 + basic_block bb;
106470 +
106471 + // 1. loop through BBs and GIMPLE statements
106472 + FOR_EACH_BB_FN(bb, cfun) {
106473 + gimple_stmt_iterator gsi;
106474 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106475 + // gimple match:
106476 + tree fndecl, size;
106477 + gimple stmt;
106478 + const char *fnname;
106479 +
106480 + // is it a call
106481 + stmt = gsi_stmt(gsi);
106482 + if (!is_gimple_call(stmt))
106483 + continue;
106484 + fndecl = gimple_call_fndecl(stmt);
106485 + if (fndecl == NULL_TREE)
106486 + continue;
106487 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
106488 + continue;
106489 +
106490 + // is it a call to k*alloc
106491 + fnname = DECL_NAME_POINTER(fndecl);
106492 + if (!is_kalloc(fnname))
106493 + continue;
106494 +
106495 + // is the size arg const or the result of a simple const assignment
106496 + size = gimple_call_arg(stmt, 0);
106497 + while (true) {
106498 + expanded_location xloc;
106499 + size_t size_val;
106500 +
106501 + if (TREE_CONSTANT(size)) {
106502 + xloc = expand_location(gimple_location(stmt));
106503 + if (!xloc.file)
106504 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
106505 + size_val = TREE_INT_CST_LOW(size);
106506 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
106507 + break;
106508 + }
106509 +
106510 + if (TREE_CODE(size) != SSA_NAME)
106511 + break;
106512 + stmt = SSA_NAME_DEF_STMT(size);
106513 +//debug_gimple_stmt(stmt);
106514 +//debug_tree(size);
106515 + if (!stmt || !is_gimple_assign(stmt))
106516 + break;
106517 + if (gimple_num_ops(stmt) != 2)
106518 + break;
106519 + size = gimple_assign_rhs1(stmt);
106520 + }
106521 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
106522 +//debug_tree(gimple_call_fn(call_stmt));
106523 +//print_node(stderr, "pax", fndecl, 4);
106524 + }
106525 + }
106526 +
106527 + return 0;
106528 +}
106529 +
106530 +#if BUILDING_GCC_VERSION >= 4009
106531 +static const struct pass_data kallocstat_pass_data = {
106532 +#else
106533 +static struct gimple_opt_pass kallocstat_pass = {
106534 + .pass = {
106535 +#endif
106536 + .type = GIMPLE_PASS,
106537 + .name = "kallocstat",
106538 +#if BUILDING_GCC_VERSION >= 4008
106539 + .optinfo_flags = OPTGROUP_NONE,
106540 +#endif
106541 +#if BUILDING_GCC_VERSION >= 4009
106542 + .has_gate = false,
106543 + .has_execute = true,
106544 +#else
106545 + .gate = NULL,
106546 + .execute = execute_kallocstat,
106547 + .sub = NULL,
106548 + .next = NULL,
106549 + .static_pass_number = 0,
106550 +#endif
106551 + .tv_id = TV_NONE,
106552 + .properties_required = 0,
106553 + .properties_provided = 0,
106554 + .properties_destroyed = 0,
106555 + .todo_flags_start = 0,
106556 + .todo_flags_finish = 0
106557 +#if BUILDING_GCC_VERSION < 4009
106558 + }
106559 +#endif
106560 +};
106561 +
106562 +#if BUILDING_GCC_VERSION >= 4009
106563 +namespace {
106564 +class kallocstat_pass : public gimple_opt_pass {
106565 +public:
106566 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
106567 + unsigned int execute() { return execute_kallocstat(); }
106568 +};
106569 +}
106570 +#endif
106571 +
106572 +static struct opt_pass *make_kallocstat_pass(void)
106573 +{
106574 +#if BUILDING_GCC_VERSION >= 4009
106575 + return new kallocstat_pass();
106576 +#else
106577 + return &kallocstat_pass.pass;
106578 +#endif
106579 +}
106580 +
106581 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106582 +{
106583 + const char * const plugin_name = plugin_info->base_name;
106584 + struct register_pass_info kallocstat_pass_info;
106585 +
106586 + kallocstat_pass_info.pass = make_kallocstat_pass();
106587 + kallocstat_pass_info.reference_pass_name = "ssa";
106588 + kallocstat_pass_info.ref_pass_instance_number = 1;
106589 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
106590 +
106591 + if (!plugin_default_version_check(version, &gcc_version)) {
106592 + error(G_("incompatible gcc/plugin versions"));
106593 + return 1;
106594 + }
106595 +
106596 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
106597 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
106598 +
106599 + return 0;
106600 +}
106601 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
106602 new file mode 100644
106603 index 0000000..dd73713
106604 --- /dev/null
106605 +++ b/tools/gcc/kernexec_plugin.c
106606 @@ -0,0 +1,519 @@
106607 +/*
106608 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106609 + * Licensed under the GPL v2
106610 + *
106611 + * Note: the choice of the license means that the compilation process is
106612 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106613 + * but for the kernel it doesn't matter since it doesn't link against
106614 + * any of the gcc libraries
106615 + *
106616 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
106617 + *
106618 + * TODO:
106619 + *
106620 + * BUGS:
106621 + * - none known
106622 + */
106623 +
106624 +#include "gcc-common.h"
106625 +
106626 +int plugin_is_GPL_compatible;
106627 +
106628 +static struct plugin_info kernexec_plugin_info = {
106629 + .version = "201401260140",
106630 + .help = "method=[bts|or]\tinstrumentation method\n"
106631 +};
106632 +
106633 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
106634 +static void (*kernexec_instrument_retaddr)(rtx);
106635 +
106636 +/*
106637 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
106638 + */
106639 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
106640 +{
106641 + gimple asm_movabs_stmt;
106642 +
106643 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
106644 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
106645 + gimple_asm_set_volatile(asm_movabs_stmt, true);
106646 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
106647 + update_stmt(asm_movabs_stmt);
106648 +}
106649 +
106650 +/*
106651 + * find all asm() stmts that clobber r12 and add a reload of r12
106652 + */
106653 +static unsigned int execute_kernexec_reload(void)
106654 +{
106655 + basic_block bb;
106656 +
106657 + // 1. loop through BBs and GIMPLE statements
106658 + FOR_EACH_BB_FN(bb, cfun) {
106659 + gimple_stmt_iterator gsi;
106660 +
106661 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106662 + // gimple match: __asm__ ("" : : : "r12");
106663 + gimple asm_stmt;
106664 + size_t nclobbers;
106665 +
106666 + // is it an asm ...
106667 + asm_stmt = gsi_stmt(gsi);
106668 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
106669 + continue;
106670 +
106671 + // ... clobbering r12
106672 + nclobbers = gimple_asm_nclobbers(asm_stmt);
106673 + while (nclobbers--) {
106674 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
106675 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
106676 + continue;
106677 + kernexec_reload_fptr_mask(&gsi);
106678 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
106679 + break;
106680 + }
106681 + }
106682 + }
106683 +
106684 + return 0;
106685 +}
106686 +
106687 +/*
106688 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
106689 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
106690 + */
106691 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
106692 +{
106693 + gimple assign_intptr, assign_new_fptr, call_stmt;
106694 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
106695 +
106696 + call_stmt = gsi_stmt(*gsi);
106697 + old_fptr = gimple_call_fn(call_stmt);
106698 +
106699 + // create temporary unsigned long variable used for bitops and cast fptr to it
106700 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
106701 + add_referenced_var(intptr);
106702 + intptr = make_ssa_name(intptr, NULL);
106703 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
106704 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
106705 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
106706 + update_stmt(assign_intptr);
106707 +
106708 + // apply logical or to temporary unsigned long and bitmask
106709 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
106710 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
106711 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
106712 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
106713 + assign_intptr = gimple_build_assign(intptr, orptr);
106714 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
106715 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
106716 + update_stmt(assign_intptr);
106717 +
106718 + // cast temporary unsigned long back to a temporary fptr variable
106719 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
106720 + add_referenced_var(new_fptr);
106721 + new_fptr = make_ssa_name(new_fptr, NULL);
106722 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
106723 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
106724 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
106725 + update_stmt(assign_new_fptr);
106726 +
106727 + // replace call stmt fn with the new fptr
106728 + gimple_call_set_fn(call_stmt, new_fptr);
106729 + update_stmt(call_stmt);
106730 +}
106731 +
106732 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
106733 +{
106734 + gimple asm_or_stmt, call_stmt;
106735 + tree old_fptr, new_fptr, input, output;
106736 +#if BUILDING_GCC_VERSION <= 4007
106737 + VEC(tree, gc) *inputs = NULL;
106738 + VEC(tree, gc) *outputs = NULL;
106739 +#else
106740 + vec<tree, va_gc> *inputs = NULL;
106741 + vec<tree, va_gc> *outputs = NULL;
106742 +#endif
106743 +
106744 + call_stmt = gsi_stmt(*gsi);
106745 + old_fptr = gimple_call_fn(call_stmt);
106746 +
106747 + // create temporary fptr variable
106748 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
106749 + add_referenced_var(new_fptr);
106750 + new_fptr = make_ssa_name(new_fptr, NULL);
106751 +
106752 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
106753 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
106754 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
106755 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
106756 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
106757 +#if BUILDING_GCC_VERSION <= 4007
106758 + VEC_safe_push(tree, gc, inputs, input);
106759 + VEC_safe_push(tree, gc, outputs, output);
106760 +#else
106761 + vec_safe_push(inputs, input);
106762 + vec_safe_push(outputs, output);
106763 +#endif
106764 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
106765 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
106766 + gimple_asm_set_volatile(asm_or_stmt, true);
106767 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
106768 + update_stmt(asm_or_stmt);
106769 +
106770 + // replace call stmt fn with the new fptr
106771 + gimple_call_set_fn(call_stmt, new_fptr);
106772 + update_stmt(call_stmt);
106773 +}
106774 +
106775 +/*
106776 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
106777 + */
106778 +static unsigned int execute_kernexec_fptr(void)
106779 +{
106780 + basic_block bb;
106781 +
106782 + // 1. loop through BBs and GIMPLE statements
106783 + FOR_EACH_BB_FN(bb, cfun) {
106784 + gimple_stmt_iterator gsi;
106785 +
106786 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106787 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
106788 + tree fn;
106789 + gimple call_stmt;
106790 +
106791 + // is it a call ...
106792 + call_stmt = gsi_stmt(gsi);
106793 + if (!is_gimple_call(call_stmt))
106794 + continue;
106795 + fn = gimple_call_fn(call_stmt);
106796 + if (TREE_CODE(fn) == ADDR_EXPR)
106797 + continue;
106798 + if (TREE_CODE(fn) != SSA_NAME)
106799 + gcc_unreachable();
106800 +
106801 + // ... through a function pointer
106802 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
106803 + fn = SSA_NAME_VAR(fn);
106804 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
106805 + debug_tree(fn);
106806 + gcc_unreachable();
106807 + }
106808 + }
106809 + fn = TREE_TYPE(fn);
106810 + if (TREE_CODE(fn) != POINTER_TYPE)
106811 + continue;
106812 + fn = TREE_TYPE(fn);
106813 + if (TREE_CODE(fn) != FUNCTION_TYPE)
106814 + continue;
106815 +
106816 + kernexec_instrument_fptr(&gsi);
106817 +
106818 +//debug_tree(gimple_call_fn(call_stmt));
106819 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
106820 + }
106821 + }
106822 +
106823 + return 0;
106824 +}
106825 +
106826 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
106827 +static void kernexec_instrument_retaddr_bts(rtx insn)
106828 +{
106829 + rtx btsq;
106830 + rtvec argvec, constraintvec, labelvec;
106831 + int line;
106832 +
106833 + // create asm volatile("btsq $63,(%%rsp)":::)
106834 + argvec = rtvec_alloc(0);
106835 + constraintvec = rtvec_alloc(0);
106836 + labelvec = rtvec_alloc(0);
106837 + line = expand_location(RTL_LOCATION(insn)).line;
106838 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
106839 + MEM_VOLATILE_P(btsq) = 1;
106840 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
106841 + emit_insn_before(btsq, insn);
106842 +}
106843 +
106844 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
106845 +static void kernexec_instrument_retaddr_or(rtx insn)
106846 +{
106847 + rtx orq;
106848 + rtvec argvec, constraintvec, labelvec;
106849 + int line;
106850 +
106851 + // create asm volatile("orq %%r12,(%%rsp)":::)
106852 + argvec = rtvec_alloc(0);
106853 + constraintvec = rtvec_alloc(0);
106854 + labelvec = rtvec_alloc(0);
106855 + line = expand_location(RTL_LOCATION(insn)).line;
106856 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
106857 + MEM_VOLATILE_P(orq) = 1;
106858 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
106859 + emit_insn_before(orq, insn);
106860 +}
106861 +
106862 +/*
106863 + * find all asm level function returns and forcibly set the highest bit of the return address
106864 + */
106865 +static unsigned int execute_kernexec_retaddr(void)
106866 +{
106867 + rtx insn;
106868 +
106869 +// if (stack_realign_drap)
106870 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
106871 +
106872 + // 1. find function returns
106873 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
106874 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
106875 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
106876 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
106877 + rtx body;
106878 +
106879 + // is it a retn
106880 + if (!JUMP_P(insn))
106881 + continue;
106882 + body = PATTERN(insn);
106883 + if (GET_CODE(body) == PARALLEL)
106884 + body = XVECEXP(body, 0, 0);
106885 + if (!ANY_RETURN_P(body))
106886 + continue;
106887 + kernexec_instrument_retaddr(insn);
106888 + }
106889 +
106890 +// print_simple_rtl(stderr, get_insns());
106891 +// print_rtl(stderr, get_insns());
106892 +
106893 + return 0;
106894 +}
106895 +
106896 +static bool kernexec_cmodel_check(void)
106897 +{
106898 + tree section;
106899 +
106900 + if (ix86_cmodel != CM_KERNEL)
106901 + return false;
106902 +
106903 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
106904 + if (!section || !TREE_VALUE(section))
106905 + return true;
106906 +
106907 + section = TREE_VALUE(TREE_VALUE(section));
106908 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
106909 + return true;
106910 +
106911 + return false;
106912 +}
106913 +
106914 +#if BUILDING_GCC_VERSION >= 4009
106915 +static const struct pass_data kernexec_reload_pass_data = {
106916 +#else
106917 +static struct gimple_opt_pass kernexec_reload_pass = {
106918 + .pass = {
106919 +#endif
106920 + .type = GIMPLE_PASS,
106921 + .name = "kernexec_reload",
106922 +#if BUILDING_GCC_VERSION >= 4008
106923 + .optinfo_flags = OPTGROUP_NONE,
106924 +#endif
106925 +#if BUILDING_GCC_VERSION >= 4009
106926 + .has_gate = true,
106927 + .has_execute = true,
106928 +#else
106929 + .gate = kernexec_cmodel_check,
106930 + .execute = execute_kernexec_reload,
106931 + .sub = NULL,
106932 + .next = NULL,
106933 + .static_pass_number = 0,
106934 +#endif
106935 + .tv_id = TV_NONE,
106936 + .properties_required = 0,
106937 + .properties_provided = 0,
106938 + .properties_destroyed = 0,
106939 + .todo_flags_start = 0,
106940 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
106941 +#if BUILDING_GCC_VERSION < 4009
106942 + }
106943 +#endif
106944 +};
106945 +
106946 +#if BUILDING_GCC_VERSION >= 4009
106947 +static const struct pass_data kernexec_fptr_pass_data = {
106948 +#else
106949 +static struct gimple_opt_pass kernexec_fptr_pass = {
106950 + .pass = {
106951 +#endif
106952 + .type = GIMPLE_PASS,
106953 + .name = "kernexec_fptr",
106954 +#if BUILDING_GCC_VERSION >= 4008
106955 + .optinfo_flags = OPTGROUP_NONE,
106956 +#endif
106957 +#if BUILDING_GCC_VERSION >= 4009
106958 + .has_gate = true,
106959 + .has_execute = true,
106960 +#else
106961 + .gate = kernexec_cmodel_check,
106962 + .execute = execute_kernexec_fptr,
106963 + .sub = NULL,
106964 + .next = NULL,
106965 + .static_pass_number = 0,
106966 +#endif
106967 + .tv_id = TV_NONE,
106968 + .properties_required = 0,
106969 + .properties_provided = 0,
106970 + .properties_destroyed = 0,
106971 + .todo_flags_start = 0,
106972 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
106973 +#if BUILDING_GCC_VERSION < 4009
106974 + }
106975 +#endif
106976 +};
106977 +
106978 +#if BUILDING_GCC_VERSION >= 4009
106979 +static const struct pass_data kernexec_retaddr_pass_data = {
106980 +#else
106981 +static struct rtl_opt_pass kernexec_retaddr_pass = {
106982 + .pass = {
106983 +#endif
106984 + .type = RTL_PASS,
106985 + .name = "kernexec_retaddr",
106986 +#if BUILDING_GCC_VERSION >= 4008
106987 + .optinfo_flags = OPTGROUP_NONE,
106988 +#endif
106989 +#if BUILDING_GCC_VERSION >= 4009
106990 + .has_gate = true,
106991 + .has_execute = true,
106992 +#else
106993 + .gate = kernexec_cmodel_check,
106994 + .execute = execute_kernexec_retaddr,
106995 + .sub = NULL,
106996 + .next = NULL,
106997 + .static_pass_number = 0,
106998 +#endif
106999 + .tv_id = TV_NONE,
107000 + .properties_required = 0,
107001 + .properties_provided = 0,
107002 + .properties_destroyed = 0,
107003 + .todo_flags_start = 0,
107004 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
107005 +#if BUILDING_GCC_VERSION < 4009
107006 + }
107007 +#endif
107008 +};
107009 +
107010 +#if BUILDING_GCC_VERSION >= 4009
107011 +namespace {
107012 +class kernexec_reload_pass : public gimple_opt_pass {
107013 +public:
107014 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
107015 + bool gate() { return kernexec_cmodel_check(); }
107016 + unsigned int execute() { return execute_kernexec_reload(); }
107017 +};
107018 +
107019 +class kernexec_fptr_pass : public gimple_opt_pass {
107020 +public:
107021 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
107022 + bool gate() { return kernexec_cmodel_check(); }
107023 + unsigned int execute() { return execute_kernexec_fptr(); }
107024 +};
107025 +
107026 +class kernexec_retaddr_pass : public rtl_opt_pass {
107027 +public:
107028 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
107029 + bool gate() { return kernexec_cmodel_check(); }
107030 + unsigned int execute() { return execute_kernexec_retaddr(); }
107031 +};
107032 +}
107033 +#endif
107034 +
107035 +static struct opt_pass *make_kernexec_reload_pass(void)
107036 +{
107037 +#if BUILDING_GCC_VERSION >= 4009
107038 + return new kernexec_reload_pass();
107039 +#else
107040 + return &kernexec_reload_pass.pass;
107041 +#endif
107042 +}
107043 +
107044 +static struct opt_pass *make_kernexec_fptr_pass(void)
107045 +{
107046 +#if BUILDING_GCC_VERSION >= 4009
107047 + return new kernexec_fptr_pass();
107048 +#else
107049 + return &kernexec_fptr_pass.pass;
107050 +#endif
107051 +}
107052 +
107053 +static struct opt_pass *make_kernexec_retaddr_pass(void)
107054 +{
107055 +#if BUILDING_GCC_VERSION >= 4009
107056 + return new kernexec_retaddr_pass();
107057 +#else
107058 + return &kernexec_retaddr_pass.pass;
107059 +#endif
107060 +}
107061 +
107062 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107063 +{
107064 + const char * const plugin_name = plugin_info->base_name;
107065 + const int argc = plugin_info->argc;
107066 + const struct plugin_argument * const argv = plugin_info->argv;
107067 + int i;
107068 + struct register_pass_info kernexec_reload_pass_info;
107069 + struct register_pass_info kernexec_fptr_pass_info;
107070 + struct register_pass_info kernexec_retaddr_pass_info;
107071 +
107072 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
107073 + kernexec_reload_pass_info.reference_pass_name = "ssa";
107074 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
107075 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107076 +
107077 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
107078 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
107079 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
107080 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107081 +
107082 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
107083 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
107084 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
107085 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107086 +
107087 + if (!plugin_default_version_check(version, &gcc_version)) {
107088 + error(G_("incompatible gcc/plugin versions"));
107089 + return 1;
107090 + }
107091 +
107092 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
107093 +
107094 + if (TARGET_64BIT == 0)
107095 + return 0;
107096 +
107097 + for (i = 0; i < argc; ++i) {
107098 + if (!strcmp(argv[i].key, "method")) {
107099 + if (!argv[i].value) {
107100 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107101 + continue;
107102 + }
107103 + if (!strcmp(argv[i].value, "bts")) {
107104 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
107105 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
107106 + } else if (!strcmp(argv[i].value, "or")) {
107107 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
107108 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
107109 + fix_register("r12", 1, 1);
107110 + } else
107111 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
107112 + continue;
107113 + }
107114 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107115 + }
107116 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
107117 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
107118 +
107119 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
107120 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
107121 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
107122 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
107123 +
107124 + return 0;
107125 +}
107126 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
107127 new file mode 100644
107128 index 0000000..319229d
107129 --- /dev/null
107130 +++ b/tools/gcc/latent_entropy_plugin.c
107131 @@ -0,0 +1,457 @@
107132 +/*
107133 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
107134 + * Licensed under the GPL v2
107135 + *
107136 + * Note: the choice of the license means that the compilation process is
107137 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107138 + * but for the kernel it doesn't matter since it doesn't link against
107139 + * any of the gcc libraries
107140 + *
107141 + * gcc plugin to help generate a little bit of entropy from program state,
107142 + * used throughout the uptime of the kernel
107143 + *
107144 + * TODO:
107145 + * - add ipa pass to identify not explicitly marked candidate functions
107146 + * - mix in more program state (function arguments/return values, loop variables, etc)
107147 + * - more instrumentation control via attribute parameters
107148 + *
107149 + * BUGS:
107150 + * - LTO needs -flto-partition=none for now
107151 + */
107152 +
107153 +#include "gcc-common.h"
107154 +
107155 +int plugin_is_GPL_compatible;
107156 +
107157 +static tree latent_entropy_decl;
107158 +
107159 +static struct plugin_info latent_entropy_plugin_info = {
107160 + .version = "201403280150",
107161 + .help = NULL
107162 +};
107163 +
107164 +static unsigned HOST_WIDE_INT seed;
107165 +static unsigned HOST_WIDE_INT get_random_const(void)
107166 +{
107167 + unsigned int i;
107168 + unsigned HOST_WIDE_INT ret = 0;
107169 +
107170 + for (i = 0; i < 8 * sizeof ret; i++) {
107171 + ret = (ret << 1) | (seed & 1);
107172 + seed >>= 1;
107173 + if (ret & 1)
107174 + seed ^= 0xD800000000000000ULL;
107175 + }
107176 +
107177 + return ret;
107178 +}
107179 +
107180 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107181 +{
107182 + tree type;
107183 + unsigned long long mask;
107184 +#if BUILDING_GCC_VERSION <= 4007
107185 + VEC(constructor_elt, gc) *vals;
107186 +#else
107187 + vec<constructor_elt, va_gc> *vals;
107188 +#endif
107189 +
107190 + switch (TREE_CODE(*node)) {
107191 + default:
107192 + *no_add_attrs = true;
107193 + error("%qE attribute only applies to functions and variables", name);
107194 + break;
107195 +
107196 + case VAR_DECL:
107197 + if (DECL_INITIAL(*node)) {
107198 + *no_add_attrs = true;
107199 + error("variable %qD with %qE attribute must not be initialized", *node, name);
107200 + break;
107201 + }
107202 +
107203 + if (!TREE_STATIC(*node)) {
107204 + *no_add_attrs = true;
107205 + error("variable %qD with %qE attribute must not be local", *node, name);
107206 + break;
107207 + }
107208 +
107209 + type = TREE_TYPE(*node);
107210 + switch (TREE_CODE(type)) {
107211 + default:
107212 + *no_add_attrs = true;
107213 + 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);
107214 + break;
107215 +
107216 + case RECORD_TYPE: {
107217 + tree field;
107218 + unsigned int nelt = 0;
107219 +
107220 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
107221 + tree fieldtype;
107222 +
107223 + fieldtype = TREE_TYPE(field);
107224 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
107225 + *no_add_attrs = true;
107226 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
107227 + break;
107228 + }
107229 + }
107230 +
107231 + if (field)
107232 + break;
107233 +
107234 +#if BUILDING_GCC_VERSION <= 4007
107235 + vals = VEC_alloc(constructor_elt, gc, nelt);
107236 +#else
107237 + vec_alloc(vals, nelt);
107238 +#endif
107239 +
107240 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
107241 + tree fieldtype;
107242 +
107243 + fieldtype = TREE_TYPE(field);
107244 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
107245 + mask = 2 * (mask - 1) + 1;
107246 +
107247 + if (TYPE_UNSIGNED(fieldtype))
107248 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
107249 + else
107250 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
107251 + }
107252 +
107253 + DECL_INITIAL(*node) = build_constructor(type, vals);
107254 +//debug_tree(DECL_INITIAL(*node));
107255 + break;
107256 + }
107257 +
107258 + case INTEGER_TYPE:
107259 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
107260 + mask = 2 * (mask - 1) + 1;
107261 +
107262 + if (TYPE_UNSIGNED(type))
107263 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
107264 + else
107265 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
107266 + break;
107267 +
107268 + case ARRAY_TYPE: {
107269 + tree elt_type, array_size, elt_size;
107270 + unsigned int i, nelt;
107271 +
107272 + elt_type = TREE_TYPE(type);
107273 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
107274 + array_size = TYPE_SIZE_UNIT(type);
107275 +
107276 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
107277 + *no_add_attrs = true;
107278 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
107279 + break;
107280 + }
107281 +
107282 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
107283 +#if BUILDING_GCC_VERSION <= 4007
107284 + vals = VEC_alloc(constructor_elt, gc, nelt);
107285 +#else
107286 + vec_alloc(vals, nelt);
107287 +#endif
107288 +
107289 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
107290 + mask = 2 * (mask - 1) + 1;
107291 +
107292 + for (i = 0; i < nelt; i++)
107293 + if (TYPE_UNSIGNED(elt_type))
107294 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
107295 + else
107296 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
107297 +
107298 + DECL_INITIAL(*node) = build_constructor(type, vals);
107299 +//debug_tree(DECL_INITIAL(*node));
107300 + break;
107301 + }
107302 + }
107303 + break;
107304 +
107305 + case FUNCTION_DECL:
107306 + break;
107307 + }
107308 +
107309 + return NULL_TREE;
107310 +}
107311 +
107312 +static struct attribute_spec latent_entropy_attr = {
107313 + .name = "latent_entropy",
107314 + .min_length = 0,
107315 + .max_length = 0,
107316 + .decl_required = true,
107317 + .type_required = false,
107318 + .function_type_required = false,
107319 + .handler = handle_latent_entropy_attribute,
107320 +#if BUILDING_GCC_VERSION >= 4007
107321 + .affects_type_identity = false
107322 +#endif
107323 +};
107324 +
107325 +static void register_attributes(void *event_data, void *data)
107326 +{
107327 + register_attribute(&latent_entropy_attr);
107328 +}
107329 +
107330 +static bool gate_latent_entropy(void)
107331 +{
107332 + // don't bother with noreturn functions for now
107333 + if (TREE_THIS_VOLATILE(current_function_decl))
107334 + return false;
107335 +
107336 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
107337 +}
107338 +
107339 +static enum tree_code get_op(tree *rhs)
107340 +{
107341 + static enum tree_code op;
107342 + unsigned HOST_WIDE_INT random_const;
107343 +
107344 + random_const = get_random_const();
107345 +
107346 + switch (op) {
107347 + case BIT_XOR_EXPR:
107348 + op = PLUS_EXPR;
107349 + break;
107350 +
107351 + case PLUS_EXPR:
107352 + if (rhs) {
107353 + op = LROTATE_EXPR;
107354 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
107355 + break;
107356 + }
107357 +
107358 + case LROTATE_EXPR:
107359 + default:
107360 + op = BIT_XOR_EXPR;
107361 + break;
107362 + }
107363 + if (rhs)
107364 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
107365 + return op;
107366 +}
107367 +
107368 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
107369 +{
107370 + gimple_stmt_iterator gsi;
107371 + gimple assign;
107372 + tree addxorrol, rhs;
107373 + enum tree_code op;
107374 +
107375 + op = get_op(&rhs);
107376 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
107377 + assign = gimple_build_assign(local_entropy, addxorrol);
107378 + gsi = gsi_after_labels(bb);
107379 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
107380 + update_stmt(assign);
107381 +//debug_bb(bb);
107382 +}
107383 +
107384 +static void perturb_latent_entropy(basic_block bb, tree rhs)
107385 +{
107386 + gimple_stmt_iterator gsi;
107387 + gimple assign;
107388 + tree addxorrol, temp;
107389 +
107390 + // 1. create temporary copy of latent_entropy
107391 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
107392 + add_referenced_var(temp);
107393 +
107394 + // 2. read...
107395 + temp = make_ssa_name(temp, NULL);
107396 + assign = gimple_build_assign(temp, latent_entropy_decl);
107397 + SSA_NAME_DEF_STMT(temp) = assign;
107398 + add_referenced_var(latent_entropy_decl);
107399 + gsi = gsi_after_labels(bb);
107400 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107401 + update_stmt(assign);
107402 +
107403 + // 3. ...modify...
107404 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
107405 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
107406 + assign = gimple_build_assign(temp, addxorrol);
107407 + SSA_NAME_DEF_STMT(temp) = assign;
107408 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107409 + update_stmt(assign);
107410 +
107411 + // 4. ...write latent_entropy
107412 + assign = gimple_build_assign(latent_entropy_decl, temp);
107413 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107414 + update_stmt(assign);
107415 +}
107416 +
107417 +static unsigned int execute_latent_entropy(void)
107418 +{
107419 + basic_block bb;
107420 + gimple assign;
107421 + gimple_stmt_iterator gsi;
107422 + tree local_entropy;
107423 +
107424 + if (!latent_entropy_decl) {
107425 + struct varpool_node *node;
107426 +
107427 + FOR_EACH_VARIABLE(node) {
107428 + tree var = NODE_DECL(node);
107429 +
107430 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
107431 + continue;
107432 + latent_entropy_decl = var;
107433 +// debug_tree(var);
107434 + break;
107435 + }
107436 + if (!latent_entropy_decl) {
107437 +// debug_tree(current_function_decl);
107438 + return 0;
107439 + }
107440 + }
107441 +
107442 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
107443 +
107444 + // 1. create local entropy variable
107445 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
107446 + add_referenced_var(local_entropy);
107447 + mark_sym_for_renaming(local_entropy);
107448 +
107449 + // 2. initialize local entropy variable
107450 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
107451 + if (dom_info_available_p(CDI_DOMINATORS))
107452 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
107453 + gsi = gsi_start_bb(bb);
107454 +
107455 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
107456 +// gimple_set_location(assign, loc);
107457 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
107458 + update_stmt(assign);
107459 +//debug_bb(bb);
107460 + gcc_assert(single_succ_p(bb));
107461 + bb = single_succ(bb);
107462 +
107463 + // 3. instrument each BB with an operation on the local entropy variable
107464 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
107465 + perturb_local_entropy(bb, local_entropy);
107466 +//debug_bb(bb);
107467 + bb = bb->next_bb;
107468 + };
107469 +
107470 + // 4. mix local entropy into the global entropy variable
107471 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
107472 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
107473 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
107474 + return 0;
107475 +}
107476 +
107477 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
107478 +{
107479 + tree latent_entropy_type;
107480 +
107481 + seed = get_random_seed(false);
107482 +
107483 + if (in_lto_p)
107484 + return;
107485 +
107486 + // extern volatile u64 latent_entropy
107487 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
107488 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
107489 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
107490 +
107491 + TREE_STATIC(latent_entropy_decl) = 1;
107492 + TREE_PUBLIC(latent_entropy_decl) = 1;
107493 + TREE_USED(latent_entropy_decl) = 1;
107494 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
107495 + DECL_EXTERNAL(latent_entropy_decl) = 1;
107496 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
107497 + lang_hooks.decls.pushdecl(latent_entropy_decl);
107498 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
107499 +// varpool_finalize_decl(latent_entropy_decl);
107500 +// varpool_mark_needed_node(latent_entropy_decl);
107501 +}
107502 +
107503 +#if BUILDING_GCC_VERSION >= 4009
107504 +static const struct pass_data latent_entropy_pass_data = {
107505 +#else
107506 +static struct gimple_opt_pass latent_entropy_pass = {
107507 + .pass = {
107508 +#endif
107509 + .type = GIMPLE_PASS,
107510 + .name = "latent_entropy",
107511 +#if BUILDING_GCC_VERSION >= 4008
107512 + .optinfo_flags = OPTGROUP_NONE,
107513 +#endif
107514 +#if BUILDING_GCC_VERSION >= 4009
107515 + .has_gate = true,
107516 + .has_execute = true,
107517 +#else
107518 + .gate = gate_latent_entropy,
107519 + .execute = execute_latent_entropy,
107520 + .sub = NULL,
107521 + .next = NULL,
107522 + .static_pass_number = 0,
107523 +#endif
107524 + .tv_id = TV_NONE,
107525 + .properties_required = PROP_gimple_leh | PROP_cfg,
107526 + .properties_provided = 0,
107527 + .properties_destroyed = 0,
107528 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
107529 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
107530 +#if BUILDING_GCC_VERSION < 4009
107531 + }
107532 +#endif
107533 +};
107534 +
107535 +#if BUILDING_GCC_VERSION >= 4009
107536 +namespace {
107537 +class latent_entropy_pass : public gimple_opt_pass {
107538 +public:
107539 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
107540 + bool gate() { return gate_latent_entropy(); }
107541 + unsigned int execute() { return execute_latent_entropy(); }
107542 +};
107543 +}
107544 +#endif
107545 +
107546 +static struct opt_pass *make_latent_entropy_pass(void)
107547 +{
107548 +#if BUILDING_GCC_VERSION >= 4009
107549 + return new latent_entropy_pass();
107550 +#else
107551 + return &latent_entropy_pass.pass;
107552 +#endif
107553 +}
107554 +
107555 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107556 +{
107557 + const char * const plugin_name = plugin_info->base_name;
107558 + struct register_pass_info latent_entropy_pass_info;
107559 +
107560 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
107561 + latent_entropy_pass_info.reference_pass_name = "optimized";
107562 + latent_entropy_pass_info.ref_pass_instance_number = 1;
107563 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
107564 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
107565 + {
107566 + .base = &latent_entropy_decl,
107567 + .nelt = 1,
107568 + .stride = sizeof(latent_entropy_decl),
107569 + .cb = &gt_ggc_mx_tree_node,
107570 + .pchw = &gt_pch_nx_tree_node
107571 + },
107572 + LAST_GGC_ROOT_TAB
107573 + };
107574 +
107575 + if (!plugin_default_version_check(version, &gcc_version)) {
107576 + error(G_("incompatible gcc/plugin versions"));
107577 + return 1;
107578 + }
107579 +
107580 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
107581 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
107582 + if (!in_lto_p)
107583 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
107584 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
107585 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
107586 +
107587 + return 0;
107588 +}
107589 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
107590 new file mode 100644
107591 index 0000000..8dafb22
107592 --- /dev/null
107593 +++ b/tools/gcc/randomize_layout_plugin.c
107594 @@ -0,0 +1,910 @@
107595 +/*
107596 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
107597 + * and PaX Team <pageexec@freemail.hu>
107598 + * Licensed under the GPL v2
107599 + *
107600 + * Usage:
107601 + * $ # for 4.5/4.6/C based 4.7
107602 + * $ 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
107603 + * $ # for C++ based 4.7/4.8+
107604 + * $ 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
107605 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
107606 + */
107607 +
107608 +#include "gcc-common.h"
107609 +#include "randomize_layout_seed.h"
107610 +
107611 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
107612 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
107613 +#endif
107614 +
107615 +#define ORIG_TYPE_NAME(node) \
107616 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
107617 +
107618 +int plugin_is_GPL_compatible;
107619 +
107620 +static int performance_mode;
107621 +
107622 +static struct plugin_info randomize_layout_plugin_info = {
107623 + .version = "201402201816",
107624 + .help = "disable\t\t\tdo not activate plugin\n"
107625 + "performance-mode\tenable cacheline-aware layout randomization\n"
107626 +};
107627 +
107628 +/* from old Linux dcache.h */
107629 +static inline unsigned long
107630 +partial_name_hash(unsigned long c, unsigned long prevhash)
107631 +{
107632 + return (prevhash + (c << 4) + (c >> 4)) * 11;
107633 +}
107634 +static inline unsigned int
107635 +name_hash(const unsigned char *name)
107636 +{
107637 + unsigned long hash = 0;
107638 + unsigned int len = strlen((const char *)name);
107639 + while (len--)
107640 + hash = partial_name_hash(*name++, hash);
107641 + return (unsigned int)hash;
107642 +}
107643 +
107644 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107645 +{
107646 + tree type;
107647 +
107648 + *no_add_attrs = true;
107649 + if (TREE_CODE(*node) == FUNCTION_DECL) {
107650 + error("%qE attribute does not apply to functions (%qF)", name, *node);
107651 + return NULL_TREE;
107652 + }
107653 +
107654 + if (TREE_CODE(*node) == PARM_DECL) {
107655 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
107656 + return NULL_TREE;
107657 + }
107658 +
107659 + if (TREE_CODE(*node) == VAR_DECL) {
107660 + error("%qE attribute does not apply to variables (%qD)", name, *node);
107661 + return NULL_TREE;
107662 + }
107663 +
107664 + if (TYPE_P(*node)) {
107665 + type = *node;
107666 + } else {
107667 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
107668 + type = TREE_TYPE(*node);
107669 + }
107670 +
107671 + if (TREE_CODE(type) != RECORD_TYPE) {
107672 + error("%qE attribute used on %qT applies to struct types only", name, type);
107673 + return NULL_TREE;
107674 + }
107675 +
107676 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
107677 + error("%qE attribute is already applied to the type %qT", name, type);
107678 + return NULL_TREE;
107679 + }
107680 +
107681 + *no_add_attrs = false;
107682 +
107683 + return NULL_TREE;
107684 +}
107685 +
107686 +/* set on complete types that we don't need to inspect further at all */
107687 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107688 +{
107689 + *no_add_attrs = false;
107690 + return NULL_TREE;
107691 +}
107692 +
107693 +/*
107694 + * set on types that we've performed a shuffle on, to prevent re-shuffling
107695 + * this does not preclude us from inspecting its fields for potential shuffles
107696 + */
107697 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107698 +{
107699 + *no_add_attrs = false;
107700 + return NULL_TREE;
107701 +}
107702 +
107703 +/*
107704 + * 64bit variant of Bob Jenkins' public domain PRNG
107705 + * 256 bits of internal state
107706 + */
107707 +
107708 +typedef unsigned long long u64;
107709 +
107710 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
107711 +
107712 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
107713 +static u64 ranval(ranctx *x) {
107714 + u64 e = x->a - rot(x->b, 7);
107715 + x->a = x->b ^ rot(x->c, 13);
107716 + x->b = x->c + rot(x->d, 37);
107717 + x->c = x->d + e;
107718 + x->d = e + x->a;
107719 + return x->d;
107720 +}
107721 +
107722 +static void raninit(ranctx *x, u64 *seed) {
107723 + int i;
107724 +
107725 + x->a = seed[0];
107726 + x->b = seed[1];
107727 + x->c = seed[2];
107728 + x->d = seed[3];
107729 +
107730 + for (i=0; i < 30; ++i)
107731 + (void)ranval(x);
107732 +}
107733 +
107734 +static u64 shuffle_seed[4];
107735 +
107736 +struct partition_group {
107737 + tree tree_start;
107738 + unsigned long start;
107739 + unsigned long length;
107740 +};
107741 +
107742 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
107743 +{
107744 + unsigned long i;
107745 + unsigned long accum_size = 0;
107746 + unsigned long accum_length = 0;
107747 + unsigned long group_idx = 0;
107748 +
107749 + gcc_assert(length < INT_MAX);
107750 +
107751 + memset(size_groups, 0, sizeof(struct partition_group) * length);
107752 +
107753 + for (i = 0; i < length; i++) {
107754 + if (size_groups[group_idx].tree_start == NULL_TREE) {
107755 + size_groups[group_idx].tree_start = fields[i];
107756 + size_groups[group_idx].start = i;
107757 + accum_length = 0;
107758 + accum_size = 0;
107759 + }
107760 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
107761 + accum_length++;
107762 + if (accum_size >= 64) {
107763 + size_groups[group_idx].length = accum_length;
107764 + accum_length = 0;
107765 + group_idx++;
107766 + }
107767 + }
107768 +
107769 + if (size_groups[group_idx].tree_start != NULL_TREE &&
107770 + !size_groups[group_idx].length) {
107771 + size_groups[group_idx].length = accum_length;
107772 + group_idx++;
107773 + }
107774 +
107775 + *num_groups = group_idx;
107776 +}
107777 +
107778 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
107779 +{
107780 + unsigned long i, x;
107781 + struct partition_group size_group[length];
107782 + unsigned long num_groups = 0;
107783 + unsigned long randnum;
107784 +
107785 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
107786 + for (i = num_groups - 1; i > 0; i--) {
107787 + struct partition_group tmp;
107788 + randnum = ranval(prng_state) % (i + 1);
107789 + tmp = size_group[i];
107790 + size_group[i] = size_group[randnum];
107791 + size_group[randnum] = tmp;
107792 + }
107793 +
107794 + for (x = 0; x < num_groups; x++) {
107795 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
107796 + tree tmp;
107797 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
107798 + continue;
107799 + randnum = ranval(prng_state) % (i + 1);
107800 + // we could handle this case differently if desired
107801 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
107802 + continue;
107803 + tmp = newtree[i];
107804 + newtree[i] = newtree[randnum];
107805 + newtree[randnum] = tmp;
107806 + }
107807 + }
107808 +}
107809 +
107810 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
107811 +{
107812 + unsigned long i, randnum;
107813 +
107814 + for (i = length - 1; i > 0; i--) {
107815 + tree tmp;
107816 + randnum = ranval(prng_state) % (i + 1);
107817 + tmp = newtree[i];
107818 + newtree[i] = newtree[randnum];
107819 + newtree[randnum] = tmp;
107820 + }
107821 +}
107822 +
107823 +/* modern in-place Fisher-Yates shuffle */
107824 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
107825 +{
107826 + unsigned long i;
107827 + u64 seed[4];
107828 + ranctx prng_state;
107829 + const unsigned char *structname;
107830 +
107831 + if (length == 0)
107832 + return;
107833 +
107834 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
107835 +
107836 + structname = ORIG_TYPE_NAME(type);
107837 +
107838 +#ifdef __DEBUG_PLUGIN
107839 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
107840 +#ifdef __DEBUG_VERBOSE
107841 + debug_tree((tree)type);
107842 +#endif
107843 +#endif
107844 +
107845 + for (i = 0; i < 4; i++) {
107846 + seed[i] = shuffle_seed[i];
107847 + seed[i] ^= name_hash(structname);
107848 + }
107849 +
107850 + raninit(&prng_state, (u64 *)&seed);
107851 +
107852 + if (performance_mode)
107853 + performance_shuffle(newtree, length, &prng_state);
107854 + else
107855 + full_shuffle(newtree, length, &prng_state);
107856 +}
107857 +
107858 +static bool is_flexible_array(const_tree field)
107859 +{
107860 + const_tree fieldtype;
107861 + const_tree typesize;
107862 + const_tree elemtype;
107863 + const_tree elemsize;
107864 +
107865 + fieldtype = TREE_TYPE(field);
107866 + typesize = TYPE_SIZE(fieldtype);
107867 +
107868 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
107869 + return false;
107870 +
107871 + elemtype = TREE_TYPE(fieldtype);
107872 + elemsize = TYPE_SIZE(elemtype);
107873 +
107874 + /* size of type is represented in bits */
107875 +
107876 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
107877 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
107878 + return true;
107879 +
107880 + if (typesize != NULL_TREE &&
107881 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
107882 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
107883 + return true;
107884 +
107885 + return false;
107886 +}
107887 +
107888 +static int relayout_struct(tree type)
107889 +{
107890 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
107891 + unsigned long shuffle_length = num_fields;
107892 + tree field;
107893 + tree newtree[num_fields];
107894 + unsigned long i;
107895 + tree list;
107896 + tree variant;
107897 + expanded_location xloc;
107898 +
107899 + if (TYPE_FIELDS(type) == NULL_TREE)
107900 + return 0;
107901 +
107902 + if (num_fields < 2)
107903 + return 0;
107904 +
107905 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
107906 +
107907 + gcc_assert(num_fields < INT_MAX);
107908 +
107909 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
107910 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
107911 + return 0;
107912 +
107913 + /* throw out any structs in uapi */
107914 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
107915 +
107916 + if (strstr(xloc.file, "/uapi/"))
107917 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
107918 +
107919 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
107920 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
107921 + newtree[i] = field;
107922 + }
107923 +
107924 + /*
107925 + * enforce that we don't randomize the layout of the last
107926 + * element of a struct if it's a 0 or 1-length array
107927 + * or a proper flexible array
107928 + */
107929 + if (is_flexible_array(newtree[num_fields - 1]))
107930 + shuffle_length--;
107931 +
107932 + shuffle(type, (tree *)newtree, shuffle_length);
107933 +
107934 + /*
107935 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
107936 + * as gcc provides no other way to detect such code
107937 + */
107938 + list = make_node(FIELD_DECL);
107939 + TREE_CHAIN(list) = newtree[0];
107940 + TREE_TYPE(list) = void_type_node;
107941 + DECL_SIZE(list) = bitsize_zero_node;
107942 + DECL_NONADDRESSABLE_P(list) = 1;
107943 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
107944 + DECL_SIZE_UNIT(list) = size_zero_node;
107945 + DECL_FIELD_OFFSET(list) = size_zero_node;
107946 + // to satisfy the constify plugin
107947 + TREE_READONLY(list) = 1;
107948 +
107949 + for (i = 0; i < num_fields - 1; i++)
107950 + TREE_CHAIN(newtree[i]) = newtree[i+1];
107951 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
107952 +
107953 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
107954 + TYPE_FIELDS(variant) = list;
107955 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
107956 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
107957 + // force a re-layout
107958 + TYPE_SIZE(variant) = NULL_TREE;
107959 + layout_type(variant);
107960 + }
107961 +
107962 + return 1;
107963 +}
107964 +
107965 +/* from constify plugin */
107966 +static const_tree get_field_type(const_tree field)
107967 +{
107968 + return strip_array_types(TREE_TYPE(field));
107969 +}
107970 +
107971 +/* from constify plugin */
107972 +static bool is_fptr(const_tree fieldtype)
107973 +{
107974 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
107975 + return false;
107976 +
107977 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
107978 +}
107979 +
107980 +/* derived from constify plugin */
107981 +static int is_pure_ops_struct(const_tree node)
107982 +{
107983 + const_tree field;
107984 +
107985 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107986 +
107987 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
107988 + const_tree fieldtype = get_field_type(field);
107989 + enum tree_code code = TREE_CODE(fieldtype);
107990 +
107991 + if (node == fieldtype)
107992 + continue;
107993 +
107994 + if (!is_fptr(fieldtype))
107995 + return 0;
107996 +
107997 + if (code != RECORD_TYPE && code != UNION_TYPE)
107998 + continue;
107999 +
108000 + if (!is_pure_ops_struct(fieldtype))
108001 + return 0;
108002 + }
108003 +
108004 + return 1;
108005 +}
108006 +
108007 +static void randomize_type(tree type)
108008 +{
108009 + tree variant;
108010 +
108011 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
108012 +
108013 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
108014 + return;
108015 +
108016 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
108017 + relayout_struct(type);
108018 +
108019 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
108020 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
108021 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
108022 + }
108023 +#ifdef __DEBUG_PLUGIN
108024 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
108025 +#ifdef __DEBUG_VERBOSE
108026 + debug_tree(type);
108027 +#endif
108028 +#endif
108029 +}
108030 +
108031 +static void randomize_layout_finish_decl(void *event_data, void *data)
108032 +{
108033 + tree decl = (tree)event_data;
108034 + tree type;
108035 +
108036 + if (decl == NULL_TREE || decl == error_mark_node)
108037 + return;
108038 +
108039 + type = TREE_TYPE(decl);
108040 +
108041 + if (TREE_CODE(decl) != VAR_DECL)
108042 + return;
108043 +
108044 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
108045 + return;
108046 +
108047 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
108048 + return;
108049 +
108050 + relayout_decl(decl);
108051 +}
108052 +
108053 +static void finish_type(void *event_data, void *data)
108054 +{
108055 + tree type = (tree)event_data;
108056 +
108057 + if (type == NULL_TREE || type == error_mark_node)
108058 + return;
108059 +
108060 + if (TREE_CODE(type) != RECORD_TYPE)
108061 + return;
108062 +
108063 + if (TYPE_FIELDS(type) == NULL_TREE)
108064 + return;
108065 +
108066 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
108067 + return;
108068 +
108069 +#ifdef __DEBUG_PLUGIN
108070 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
108071 +#endif
108072 +#ifdef __DEBUG_VERBOSE
108073 + debug_tree(type);
108074 +#endif
108075 + randomize_type(type);
108076 +
108077 + return;
108078 +}
108079 +
108080 +static struct attribute_spec randomize_layout_attr = {
108081 + .name = "randomize_layout",
108082 + // related to args
108083 + .min_length = 0,
108084 + .max_length = 0,
108085 + .decl_required = false,
108086 + // need type declaration
108087 + .type_required = true,
108088 + .function_type_required = false,
108089 + .handler = handle_randomize_layout_attr,
108090 +#if BUILDING_GCC_VERSION >= 4007
108091 + .affects_type_identity = true
108092 +#endif
108093 +};
108094 +
108095 +static struct attribute_spec no_randomize_layout_attr = {
108096 + .name = "no_randomize_layout",
108097 + // related to args
108098 + .min_length = 0,
108099 + .max_length = 0,
108100 + .decl_required = false,
108101 + // need type declaration
108102 + .type_required = true,
108103 + .function_type_required = false,
108104 + .handler = handle_randomize_layout_attr,
108105 +#if BUILDING_GCC_VERSION >= 4007
108106 + .affects_type_identity = true
108107 +#endif
108108 +};
108109 +
108110 +static struct attribute_spec randomize_considered_attr = {
108111 + .name = "randomize_considered",
108112 + // related to args
108113 + .min_length = 0,
108114 + .max_length = 0,
108115 + .decl_required = false,
108116 + // need type declaration
108117 + .type_required = true,
108118 + .function_type_required = false,
108119 + .handler = handle_randomize_considered_attr,
108120 +#if BUILDING_GCC_VERSION >= 4007
108121 + .affects_type_identity = false
108122 +#endif
108123 +};
108124 +
108125 +static struct attribute_spec randomize_performed_attr = {
108126 + .name = "randomize_performed",
108127 + // related to args
108128 + .min_length = 0,
108129 + .max_length = 0,
108130 + .decl_required = false,
108131 + // need type declaration
108132 + .type_required = true,
108133 + .function_type_required = false,
108134 + .handler = handle_randomize_performed_attr,
108135 +#if BUILDING_GCC_VERSION >= 4007
108136 + .affects_type_identity = false
108137 +#endif
108138 +};
108139 +
108140 +static void register_attributes(void *event_data, void *data)
108141 +{
108142 + register_attribute(&randomize_layout_attr);
108143 + register_attribute(&no_randomize_layout_attr);
108144 + register_attribute(&randomize_considered_attr);
108145 + register_attribute(&randomize_performed_attr);
108146 +}
108147 +
108148 +static void check_bad_casts_in_constructor(tree var, tree init)
108149 +{
108150 + unsigned HOST_WIDE_INT idx;
108151 + tree field, val;
108152 + tree field_type, val_type;
108153 +
108154 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
108155 + if (TREE_CODE(val) == CONSTRUCTOR) {
108156 + check_bad_casts_in_constructor(var, val);
108157 + continue;
108158 + }
108159 +
108160 + /* pipacs' plugin creates franken-arrays that differ from those produced by
108161 + normal code which all have valid 'field' trees. work around this */
108162 + if (field == NULL_TREE)
108163 + continue;
108164 + field_type = TREE_TYPE(field);
108165 + val_type = TREE_TYPE(val);
108166 +
108167 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
108168 + continue;
108169 +
108170 + if (field_type == val_type)
108171 + continue;
108172 +
108173 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
108174 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
108175 +
108176 + if (field_type == void_type_node)
108177 + continue;
108178 + if (field_type == val_type)
108179 + continue;
108180 + if (TREE_CODE(val_type) != RECORD_TYPE)
108181 + continue;
108182 +
108183 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
108184 + continue;
108185 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
108186 + }
108187 +}
108188 +
108189 +/* derived from the constify plugin */
108190 +static void check_global_variables(void *event_data, void *data)
108191 +{
108192 + struct varpool_node *node;
108193 + tree init;
108194 +
108195 + FOR_EACH_VARIABLE(node) {
108196 + tree var = NODE_DECL(node);
108197 + init = DECL_INITIAL(var);
108198 + if (init == NULL_TREE)
108199 + continue;
108200 +
108201 + if (TREE_CODE(init) != CONSTRUCTOR)
108202 + continue;
108203 +
108204 + check_bad_casts_in_constructor(var, init);
108205 + }
108206 +}
108207 +
108208 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
108209 +{
108210 + basic_block dom;
108211 + gimple dom_stmt;
108212 + gimple call_stmt;
108213 + const_tree dom_lhs;
108214 + const_tree poss_is_err_cond;
108215 + const_tree poss_is_err_func;
108216 + const_tree is_err_arg;
108217 +
108218 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
108219 + if (!dom)
108220 + return false;
108221 +
108222 + dom_stmt = last_stmt(dom);
108223 + if (!dom_stmt)
108224 + return false;
108225 +
108226 + if (gimple_code(dom_stmt) != GIMPLE_COND)
108227 + return false;
108228 +
108229 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
108230 + return false;
108231 +
108232 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
108233 + return false;
108234 +
108235 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
108236 +
108237 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
108238 + return false;
108239 +
108240 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
108241 +
108242 + if (gimple_code(call_stmt) != GIMPLE_CALL)
108243 + return false;
108244 +
108245 + dom_lhs = gimple_get_lhs(call_stmt);
108246 + poss_is_err_func = gimple_call_fndecl(call_stmt);
108247 + if (!poss_is_err_func)
108248 + return false;
108249 + if (dom_lhs != poss_is_err_cond)
108250 + return false;
108251 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
108252 + return false;
108253 +
108254 + is_err_arg = gimple_call_arg(call_stmt, 0);
108255 + if (!is_err_arg)
108256 + return false;
108257 +
108258 + if (is_err_arg != rhs)
108259 + return false;
108260 +
108261 + return true;
108262 +}
108263 +
108264 +static void handle_local_var_initializers(void)
108265 +{
108266 + tree var;
108267 + unsigned int i;
108268 +
108269 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
108270 + tree init = DECL_INITIAL(var);
108271 + if (!init)
108272 + continue;
108273 + if (TREE_CODE(init) != CONSTRUCTOR)
108274 + continue;
108275 + check_bad_casts_in_constructor(var, init);
108276 + }
108277 +}
108278 +
108279 +/*
108280 + * iterate over all statements to find "bad" casts:
108281 + * those where the address of the start of a structure is cast
108282 + * to a pointer of a structure of a different type, or a
108283 + * structure pointer type is cast to a different structure pointer type
108284 + */
108285 +static unsigned int find_bad_casts(void)
108286 +{
108287 + basic_block bb;
108288 +
108289 + handle_local_var_initializers();
108290 +
108291 + FOR_ALL_BB_FN(bb, cfun) {
108292 + gimple_stmt_iterator gsi;
108293 +
108294 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108295 + gimple stmt;
108296 + const_tree lhs;
108297 + const_tree lhs_type;
108298 + const_tree rhs1;
108299 + const_tree rhs_type;
108300 + const_tree ptr_lhs_type;
108301 + const_tree ptr_rhs_type;
108302 + const_tree op0;
108303 + const_tree op0_type;
108304 + enum tree_code rhs_code;
108305 +
108306 + stmt = gsi_stmt(gsi);
108307 +
108308 +#ifdef __DEBUG_PLUGIN
108309 +#ifdef __DEBUG_VERBOSE
108310 + debug_gimple_stmt(stmt);
108311 + debug_tree(gimple_get_lhs(stmt));
108312 +#endif
108313 +#endif
108314 +
108315 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
108316 + continue;
108317 +
108318 +#ifdef __DEBUG_PLUGIN
108319 +#ifdef __DEBUG_VERBOSE
108320 + debug_tree(gimple_assign_rhs1(stmt));
108321 +#endif
108322 +#endif
108323 +
108324 + rhs_code = gimple_assign_rhs_code(stmt);
108325 +
108326 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
108327 + continue;
108328 +
108329 + lhs = gimple_get_lhs(stmt);
108330 + lhs_type = TREE_TYPE(lhs);
108331 + rhs1 = gimple_assign_rhs1(stmt);
108332 + rhs_type = TREE_TYPE(rhs1);
108333 +
108334 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
108335 + TREE_CODE(lhs_type) != POINTER_TYPE)
108336 + continue;
108337 +
108338 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
108339 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
108340 +
108341 + if (ptr_rhs_type == void_type_node)
108342 + continue;
108343 +
108344 + if (ptr_lhs_type == void_type_node)
108345 + continue;
108346 +
108347 + if (dominated_by_is_err(rhs1, bb))
108348 + continue;
108349 +
108350 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
108351 +#ifndef __DEBUG_PLUGIN
108352 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
108353 +#endif
108354 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108355 + continue;
108356 + }
108357 +
108358 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
108359 + continue;
108360 +
108361 + if (rhs_code == ADDR_EXPR) {
108362 + op0 = TREE_OPERAND(rhs1, 0);
108363 +
108364 + if (op0 == NULL_TREE)
108365 + continue;
108366 +
108367 + if (TREE_CODE(op0) != VAR_DECL)
108368 + continue;
108369 +
108370 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
108371 + if (op0_type == ptr_lhs_type)
108372 + continue;
108373 +
108374 +#ifndef __DEBUG_PLUGIN
108375 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
108376 +#endif
108377 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
108378 + } else {
108379 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
108380 + /* skip bogus type casts introduced by container_of */
108381 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
108382 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
108383 + continue;
108384 +#ifndef __DEBUG_PLUGIN
108385 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
108386 +#endif
108387 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
108388 + }
108389 +
108390 + }
108391 + }
108392 + return 0;
108393 +}
108394 +
108395 +#if BUILDING_GCC_VERSION >= 4009
108396 +static const struct pass_data randomize_layout_bad_cast_data = {
108397 +#else
108398 +static struct gimple_opt_pass randomize_layout_bad_cast = {
108399 + .pass = {
108400 +#endif
108401 + .type = GIMPLE_PASS,
108402 + .name = "randomize_layout_bad_cast",
108403 +#if BUILDING_GCC_VERSION >= 4008
108404 + .optinfo_flags = OPTGROUP_NONE,
108405 +#endif
108406 +#if BUILDING_GCC_VERSION >= 4009
108407 + .has_gate = false,
108408 + .has_execute = true,
108409 +#else
108410 + .gate = NULL,
108411 + .execute = find_bad_casts,
108412 + .sub = NULL,
108413 + .next = NULL,
108414 + .static_pass_number = 0,
108415 +#endif
108416 + .tv_id = TV_NONE,
108417 + .properties_required = PROP_cfg,
108418 + .properties_provided = 0,
108419 + .properties_destroyed = 0,
108420 + .todo_flags_start = 0,
108421 + .todo_flags_finish = TODO_dump_func
108422 +#if BUILDING_GCC_VERSION < 4009
108423 + }
108424 +#endif
108425 +};
108426 +
108427 +#if BUILDING_GCC_VERSION >= 4009
108428 +namespace {
108429 +class randomize_layout_bad_cast : public gimple_opt_pass {
108430 +public:
108431 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
108432 + unsigned int execute() { return find_bad_casts(); }
108433 +};
108434 +}
108435 +#endif
108436 +
108437 +static struct opt_pass *make_randomize_layout_bad_cast(void)
108438 +{
108439 +#if BUILDING_GCC_VERSION >= 4009
108440 + return new randomize_layout_bad_cast();
108441 +#else
108442 + return &randomize_layout_bad_cast.pass;
108443 +#endif
108444 +}
108445 +
108446 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108447 +{
108448 + int i;
108449 + const char * const plugin_name = plugin_info->base_name;
108450 + const int argc = plugin_info->argc;
108451 + const struct plugin_argument * const argv = plugin_info->argv;
108452 + bool enable = true;
108453 + int obtained_seed = 0;
108454 + struct register_pass_info randomize_layout_bad_cast_info;
108455 +
108456 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
108457 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
108458 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
108459 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
108460 +
108461 + if (!plugin_default_version_check(version, &gcc_version)) {
108462 + error(G_("incompatible gcc/plugin versions"));
108463 + return 1;
108464 + }
108465 +
108466 + if (strcmp(lang_hooks.name, "GNU C")) {
108467 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
108468 + enable = false;
108469 + }
108470 +
108471 + for (i = 0; i < argc; ++i) {
108472 + if (!strcmp(argv[i].key, "disable")) {
108473 + enable = false;
108474 + continue;
108475 + }
108476 + if (!strcmp(argv[i].key, "performance-mode")) {
108477 + performance_mode = 1;
108478 + continue;
108479 + }
108480 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108481 + }
108482 +
108483 + if (strlen(randstruct_seed) != 64) {
108484 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
108485 + return 1;
108486 + }
108487 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
108488 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
108489 + if (obtained_seed != 4) {
108490 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
108491 + return 1;
108492 + }
108493 +
108494 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
108495 + if (enable) {
108496 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
108497 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
108498 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
108499 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
108500 + }
108501 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
108502 +
108503 + return 0;
108504 +}
108505 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
108506 new file mode 100644
108507 index 0000000..ebbd9a3
108508 --- /dev/null
108509 +++ b/tools/gcc/size_overflow_hash.data
108510 @@ -0,0 +1,5933 @@
108511 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
108512 +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
108513 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
108514 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
108515 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
108516 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
108517 +padzero_55 padzero 1 55 &sel_read_policyvers_55
108518 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
108519 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
108520 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
108521 +load_msg_95 load_msg 2 95 NULL
108522 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
108523 +init_q_132 init_q 4 132 NULL
108524 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
108525 +gfs2_glock_get_147 gfs2_glock_get 0 147 NULL
108526 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
108527 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
108528 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
108529 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
108530 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
108531 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
108532 +xfs_bmap_btalloc_192 xfs_bmap_btalloc 0 192 NULL
108533 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
108534 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
108535 +br_port_info_size_268 br_port_info_size 0 268 NULL
108536 +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
108537 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
108538 +xfs_zero_last_block_298 xfs_zero_last_block 0 298 NULL
108539 +SYSC_connect_304 SYSC_connect 3 304 NULL
108540 +syslog_print_307 syslog_print 2 307 NULL
108541 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
108542 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
108543 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
108544 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
108545 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
108546 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
108547 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
108548 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
108549 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
108550 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
108551 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
108552 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
108553 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
108554 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
108555 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
108556 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
108557 +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
108558 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
108559 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
108560 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
108561 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
108562 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
108563 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
108564 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
108565 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
108566 +unlink_queued_645 unlink_queued 4 645 NULL
108567 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
108568 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
108569 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
108570 +xfs_bmap_eof_728 xfs_bmap_eof 0 728 NULL
108571 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
108572 +dvb_video_write_754 dvb_video_write 3 754 NULL
108573 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
108574 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
108575 +if_writecmd_815 if_writecmd 2 815 NULL
108576 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
108577 +error_state_read_859 error_state_read 6 859 NULL
108578 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
108579 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
108580 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
108581 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
108582 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
108583 +mnt_want_write_975 mnt_want_write 0 975 NULL
108584 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
108585 +memcmp_990 memcmp 0 990 NULL
108586 +readreg_1017 readreg 0-1 1017 NULL
108587 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
108588 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
108589 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
108590 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
108591 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
108592 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
108593 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
108594 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
108595 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
108596 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
108597 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
108598 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
108599 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
108600 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
108601 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
108602 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
108603 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
108604 +fsync_buffers_list_1219 fsync_buffers_list 0 1219 NULL
108605 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
108606 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
108607 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
108608 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
108609 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
108610 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
108611 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
108612 +tcf_hash_create_1305 tcf_hash_create 4 1305 NULL
108613 +ffs_1322 ffs 0 1322 NULL
108614 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
108615 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
108616 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
108617 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
108618 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
108619 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
108620 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
108621 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
108622 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
108623 +file_read_actor_1401 file_read_actor 4-0 1401 NULL
108624 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
108625 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
108626 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
108627 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
108628 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
108629 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
108630 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
108631 +fpregs_set_1497 fpregs_set 4 1497 NULL
108632 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
108633 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
108634 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
108635 +ffs_mutex_lock_1564 ffs_mutex_lock 0 1564 NULL
108636 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
108637 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
108638 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
108639 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
108640 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
108641 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
108642 +rmap_add_1677 rmap_add 3 1677 NULL
108643 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
108644 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
108645 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
108646 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
108647 +internal_create_group_1733 internal_create_group 0 1733 NULL
108648 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
108649 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
108650 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
108651 +cosa_write_1774 cosa_write 3 1774 NULL
108652 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
108653 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
108654 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
108655 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
108656 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
108657 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
108658 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
108659 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
108660 +bdev_erase_1933 bdev_erase 3 1933 NULL
108661 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
108662 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
108663 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
108664 +update_qd_1955 update_qd 0 1955 NULL
108665 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
108666 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
108667 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
108668 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
108669 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
108670 +xfs_mru_cache_insert_2013 xfs_mru_cache_insert 0 2013 NULL
108671 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
108672 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
108673 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
108674 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
108675 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
108676 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
108677 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
108678 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
108679 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
108680 +audit_expand_2098 audit_expand 0 2098 NULL
108681 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
108682 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
108683 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
108684 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
108685 +enable_read_2117 enable_read 3 2117 NULL
108686 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
108687 +xfs_recover_inode_owner_change_2132 xfs_recover_inode_owner_change 0 2132 NULL
108688 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
108689 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
108690 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
108691 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
108692 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
108693 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
108694 +xfs_inobt_update_2206 xfs_inobt_update 0 2206 NULL
108695 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
108696 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
108697 +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
108698 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
108699 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
108700 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
108701 +do_update_counters_2259 do_update_counters 4 2259 NULL
108702 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
108703 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
108704 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
108705 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
108706 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
108707 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
108708 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
108709 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
108710 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
108711 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
108712 +ntfs_file_aio_write_nolock_2360 ntfs_file_aio_write_nolock 0 2360 NULL
108713 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
108714 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5-0 2368 NULL nohasharray
108715 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
108716 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
108717 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
108718 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
108719 +raid1_size_2419 raid1_size 0-2 2419 NULL
108720 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
108721 +wiphy_new_2482 wiphy_new 2 2482 NULL
108722 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
108723 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
108724 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
108725 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
108726 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
108727 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
108728 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
108729 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
108730 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
108731 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
108732 +slot_bytes_2609 slot_bytes 0 2609 NULL
108733 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
108734 +switch_status_2629 switch_status 5 2629 NULL
108735 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
108736 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
108737 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
108738 +oti6858_write_2692 oti6858_write 4 2692 NULL
108739 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
108740 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
108741 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
108742 +gfs2_glock_nq_num_2747 gfs2_glock_nq_num 0 2747 NULL
108743 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
108744 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
108745 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
108746 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
108747 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
108748 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
108749 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
108750 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
108751 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
108752 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
108753 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
108754 +nla_padlen_2883 nla_padlen 1 2883 NULL
108755 +cmm_write_2896 cmm_write 3 2896 NULL
108756 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
108757 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
108758 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
108759 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
108760 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
108761 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
108762 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
108763 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
108764 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
108765 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
108766 +_xfs_filestream_pick_ag_3007 _xfs_filestream_pick_ag 0 3007 NULL
108767 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
108768 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
108769 +depth_write_3021 depth_write 3 3021 NULL
108770 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
108771 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
108772 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
108773 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
108774 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
108775 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
108776 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
108777 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
108778 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
108779 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
108780 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
108781 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
108782 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
108783 +rb_alloc_3102 rb_alloc 1 3102 NULL
108784 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
108785 +print_time_3132 print_time 0 3132 NULL
108786 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
108787 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
108788 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
108789 +gfs2_rindex_update_3165 gfs2_rindex_update 0 3165 NULL
108790 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
108791 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
108792 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
108793 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
108794 +alloc_context_3194 alloc_context 1 3194 NULL
108795 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
108796 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
108797 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
108798 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
108799 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
108800 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
108801 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
108802 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
108803 +key_key_read_3241 key_key_read 3 3241 NULL
108804 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
108805 +__set_extent_bit_3305 __set_extent_bit 0 3305 NULL
108806 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
108807 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
108808 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
108809 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
108810 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
108811 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
108812 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
108813 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
108814 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
108815 +scnprintf_3360 scnprintf 0-2 3360 NULL
108816 +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
108817 +sr_read_3366 sr_read 3 3366 NULL
108818 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
108819 +send_stream_3397 send_stream 4 3397 NULL
108820 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
108821 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
108822 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
108823 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
108824 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
108825 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
108826 +softsynth_write_3455 softsynth_write 3 3455 NULL
108827 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
108828 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
108829 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
108830 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
108831 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
108832 +SyS_readv_3539 SyS_readv 3 3539 NULL
108833 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
108834 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
108835 +evtchn_read_3569 evtchn_read 3 3569 NULL
108836 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
108837 +vc_resize_3585 vc_resize 3-2 3585 NULL
108838 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
108839 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
108840 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
108841 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
108842 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
108843 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
108844 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
108845 +xfs_attr3_leaf_list_int_3661 xfs_attr3_leaf_list_int 0 3661 NULL
108846 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
108847 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
108848 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
108849 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
108850 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
108851 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
108852 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
108853 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
108854 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
108855 +get_fd_set_3866 get_fd_set 1 3866 NULL
108856 +apei_res_sub_3873 apei_res_sub 0 3873 NULL
108857 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
108858 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
108859 +nvram_write_3894 nvram_write 3 3894 NULL
108860 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
108861 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
108862 +vcs_write_3910 vcs_write 3 3910 NULL
108863 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
108864 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
108865 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
108866 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
108867 +do_add_counters_3992 do_add_counters 3 3992 NULL
108868 +xfs_bmbt_lookup_eq_3997 xfs_bmbt_lookup_eq 0 3997 NULL
108869 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
108870 +userspace_status_4004 userspace_status 4 4004 NULL
108871 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
108872 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
108873 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
108874 +blk_end_request_4024 blk_end_request 3 4024 NULL
108875 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
108876 +xfs_free_ag_extent_4036 xfs_free_ag_extent 0 4036 NULL
108877 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
108878 +read_file_queues_4078 read_file_queues 3 4078 NULL
108879 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
108880 +tm6000_read_4151 tm6000_read 3 4151 NULL
108881 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
108882 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
108883 +get_alua_req_4166 get_alua_req 3 4166 NULL
108884 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
108885 +read_file_bool_4180 read_file_bool 3 4180 NULL
108886 +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
108887 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
108888 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
108889 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
108890 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
108891 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
108892 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
108893 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
108894 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
108895 +count_strings_4315 count_strings 0 4315 NULL
108896 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
108897 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
108898 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
108899 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
108900 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
108901 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
108902 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
108903 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
108904 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
108905 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
108906 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
108907 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
108908 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
108909 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
108910 +set_link_security_4502 set_link_security 4 4502 NULL
108911 +xfs_btree_kill_root_4526 xfs_btree_kill_root 0 4526 NULL
108912 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
108913 +tty_register_device_4544 tty_register_device 2 4544 NULL
108914 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
108915 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
108916 +bch_alloc_4593 bch_alloc 1 4593 NULL
108917 +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
108918 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
108919 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
108920 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
108921 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
108922 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
108923 +kone_receive_4690 kone_receive 4 4690 NULL
108924 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
108925 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
108926 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
108927 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
108928 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
108929 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
108930 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
108931 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
108932 +create_subvol_4791 create_subvol 4 4791 NULL
108933 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
108934 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
108935 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
108936 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
108937 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
108938 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
108939 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
108940 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
108941 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
108942 +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
108943 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
108944 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
108945 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
108946 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
108947 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
108948 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
108949 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
108950 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
108951 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
108952 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
108953 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
108954 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
108955 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
108956 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
108957 +sound_write_5102 sound_write 3 5102 NULL
108958 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
108959 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
108960 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
108961 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
108962 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
108963 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
108964 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
108965 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
108966 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
108967 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
108968 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
108969 +cq_free_res_5355 cq_free_res 5 5355 NULL
108970 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
108971 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
108972 +xfs_free_extent_5411 xfs_free_extent 0 5411 NULL
108973 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
108974 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
108975 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
108976 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
108977 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
108978 +tty_write_5494 tty_write 3 5494 NULL
108979 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
108980 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
108981 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
108982 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
108983 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
108984 +le_readq_5557 le_readq 0 5557 NULL
108985 +inw_5558 inw 0 5558 NULL
108986 +gfs2_extent_map_5561 gfs2_extent_map 0 5561 NULL
108987 +bioset_create_5580 bioset_create 1 5580 NULL
108988 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
108989 +__remove_suid_5618 __remove_suid 0 5618 NULL
108990 +gfs2_unstuffer_page_5620 gfs2_unstuffer_page 0 5620 NULL
108991 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
108992 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
108993 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
108994 +get_arg_5694 get_arg 3 5694 NULL
108995 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
108996 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
108997 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
108998 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
108999 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
109000 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
109001 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
109002 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
109003 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
109004 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
109005 +setup_req_5848 setup_req 3 5848 NULL
109006 +ria_page_count_5849 ria_page_count 0 5849 NULL
109007 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
109008 +config_buf_5862 config_buf 0 5862 NULL
109009 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
109010 +port_show_regs_5904 port_show_regs 3 5904 NULL
109011 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
109012 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
109013 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
109014 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
109015 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
109016 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
109017 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
109018 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
109019 +alloc_msg_6072 alloc_msg 1 6072 NULL
109020 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
109021 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
109022 +__mnt_want_write_6091 __mnt_want_write 0 6091 NULL
109023 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
109024 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
109025 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
109026 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
109027 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
109028 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
109029 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
109030 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
109031 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
109032 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
109033 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
109034 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
109035 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
109036 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
109037 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
109038 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
109039 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
109040 +serial_port_in_6291 serial_port_in 0 6291 NULL
109041 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
109042 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
109043 +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
109044 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
109045 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
109046 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
109047 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
109048 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
109049 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
109050 +xfs_bmap_extents_to_btree_6387 xfs_bmap_extents_to_btree 0 6387 NULL
109051 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
109052 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
109053 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
109054 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
109055 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
109056 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
109057 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
109058 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
109059 +mei_read_6507 mei_read 3 6507 NULL
109060 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
109061 +wdm_read_6549 wdm_read 3 6549 NULL
109062 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
109063 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
109064 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
109065 +xfs_iozero_6573 xfs_iozero 0 6573 NULL
109066 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
109067 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
109068 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
109069 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
109070 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
109071 +mpeg_read_6708 mpeg_read 3 6708 NULL
109072 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
109073 +video_proc_write_6724 video_proc_write 3 6724 NULL
109074 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
109075 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
109076 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
109077 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
109078 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
109079 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
109080 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
109081 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
109082 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
109083 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
109084 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
109085 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
109086 +xfs_rtany_summary_6851 xfs_rtany_summary 0 6851 NULL
109087 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
109088 +dio_complete_6879 dio_complete 0-2-3 6879 NULL
109089 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
109090 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
109091 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
109092 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
109093 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
109094 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
109095 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
109096 +lops_scan_elements_6916 lops_scan_elements 0 6916 NULL
109097 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
109098 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
109099 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
109100 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
109101 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
109102 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
109103 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
109104 +request_key_async_6990 request_key_async 4 6990 NULL
109105 +tpl_write_6998 tpl_write 3 6998 NULL
109106 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
109107 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
109108 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
109109 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
109110 +wimax_msg_7030 wimax_msg 4 7030 NULL
109111 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
109112 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
109113 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
109114 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
109115 +event_enable_read_7074 event_enable_read 3 7074 NULL
109116 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
109117 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
109118 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
109119 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
109120 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
109121 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
109122 +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
109123 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
109124 +get_string_7302 get_string 0 7302 NULL
109125 +security_inode_need_killpriv_7322 security_inode_need_killpriv 0 7322 NULL
109126 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
109127 +mgmt_control_7349 mgmt_control 3 7349 NULL
109128 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
109129 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
109130 +xfs_btree_delete_7384 xfs_btree_delete 0 7384 NULL
109131 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
109132 +hweight_long_7388 hweight_long 1-0 7388 NULL
109133 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
109134 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
109135 +readb_7401 readb 0 7401 NULL
109136 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
109137 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
109138 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
109139 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
109140 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
109141 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
109142 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
109143 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
109144 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
109145 +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
109146 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
109147 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
109148 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
109149 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
109150 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
109151 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
109152 +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
109153 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
109154 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
109155 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
109156 +xfs_bmap_btalloc_nullfb_7654 xfs_bmap_btalloc_nullfb 0 7654 NULL
109157 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
109158 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
109159 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
109160 +dev_write_7708 dev_write 3 7708 NULL
109161 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
109162 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
109163 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
109164 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
109165 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
109166 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
109167 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
109168 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
109169 +xfs_alloc_find_best_extent_7837 xfs_alloc_find_best_extent 0 7837 NULL
109170 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
109171 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
109172 +config_desc_7878 config_desc 0 7878 NULL
109173 +gfs2_permission_7884 gfs2_permission 0 7884 NULL
109174 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
109175 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
109176 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
109177 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
109178 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
109179 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
109180 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
109181 +vcs_read_8017 vcs_read 3 8017 NULL
109182 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
109183 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
109184 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
109185 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
109186 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
109187 +venus_lookup_8121 venus_lookup 4 8121 NULL
109188 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
109189 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
109190 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
109191 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
109192 +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
109193 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
109194 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
109195 +play_iframe_8219 play_iframe 3 8219 NULL
109196 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
109197 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
109198 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
109199 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
109200 +init_cdev_8274 init_cdev 1 8274 NULL
109201 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
109202 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
109203 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
109204 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
109205 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
109206 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
109207 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
109208 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
109209 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
109210 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
109211 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
109212 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
109213 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
109214 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
109215 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
109216 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
109217 +dev_config_8506 dev_config 3 8506 NULL
109218 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
109219 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
109220 +user_on_off_8552 user_on_off 2 8552 NULL
109221 +profile_remove_8556 profile_remove 3 8556 NULL
109222 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
109223 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
109224 +tower_write_8580 tower_write 3 8580 NULL
109225 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
109226 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
109227 +xfs_qm_dqattach_locked_8625 xfs_qm_dqattach_locked 0 8625 NULL
109228 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
109229 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
109230 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
109231 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
109232 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
109233 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
109234 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
109235 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
109236 +arcfb_write_8702 arcfb_write 3 8702 NULL
109237 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
109238 +init_header_8703 init_header 0 8703 &i_size_read_8703
109239 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
109240 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
109241 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
109242 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
109243 +__create_irqs_8733 __create_irqs 2 8733 NULL
109244 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
109245 +compound_order_8750 compound_order 0 8750 NULL
109246 +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
109247 +yurex_write_8761 yurex_write 3 8761 NULL
109248 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
109249 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
109250 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
109251 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
109252 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
109253 +gfs2_glock_nq_8808 gfs2_glock_nq 0 8808 NULL
109254 +ntfs_commit_pages_after_write_8809 ntfs_commit_pages_after_write 0 8809 NULL
109255 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
109256 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
109257 +extent_read_full_page_8826 extent_read_full_page 0 8826 NULL
109258 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
109259 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
109260 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
109261 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
109262 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
109263 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
109264 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
109265 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
109266 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
109267 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
109268 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
109269 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
109270 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
109271 +write_file_ani_8918 write_file_ani 3 8918 NULL
109272 +layout_commit_8926 layout_commit 3 8926 NULL
109273 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
109274 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
109275 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
109276 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
109277 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
109278 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
109279 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
109280 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
109281 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
109282 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
109283 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
109284 +xfs_inobt_get_rec_9023 xfs_inobt_get_rec 0 9023 NULL
109285 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
109286 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
109287 +nla_put_9042 nla_put 3 9042 NULL
109288 +ffs_func_revmap_intf_9043 ffs_func_revmap_intf 0 9043 NULL
109289 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
109290 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
109291 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
109292 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
109293 +create_queues_9088 create_queues 2-3 9088 NULL
109294 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
109295 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
109296 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
109297 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110 nohasharray
109298 +jhead_scan_9110 jhead_scan 0 9110 &gfn_to_rmap_9110
109299 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
109300 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
109301 +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
109302 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
109303 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
109304 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
109305 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
109306 +xfs_btree_rshift_9187 xfs_btree_rshift 0 9187 NULL
109307 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
109308 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
109309 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
109310 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
109311 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
109312 +xfs_error_trap_9239 xfs_error_trap 0-1 9239 NULL
109313 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
109314 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
109315 +flakey_status_9274 flakey_status 5 9274 NULL
109316 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
109317 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
109318 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
109319 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
109320 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
109321 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
109322 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
109323 +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
109324 +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
109325 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
109326 +read_9397 read 3 9397 NULL
109327 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
109328 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
109329 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
109330 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
109331 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
109332 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
109333 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
109334 +crypt_status_9492 crypt_status 5 9492 NULL
109335 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
109336 +lp_write_9511 lp_write 3 9511 NULL
109337 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
109338 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
109339 +read_file_dma_9530 read_file_dma 3 9530 NULL
109340 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
109341 +xfs_ialloc_read_agi_9545 xfs_ialloc_read_agi 0 9545 NULL
109342 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
109343 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
109344 +fw_node_create_9559 fw_node_create 2 9559 NULL
109345 +kobj_map_9566 kobj_map 2-3 9566 NULL
109346 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
109347 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
109348 +xfs_qm_dqattach_one_9612 xfs_qm_dqattach_one 0 9612 NULL
109349 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
109350 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
109351 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
109352 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
109353 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
109354 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
109355 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
109356 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
109357 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
109358 +dns_query_9676 dns_query 3 9676 NULL
109359 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
109360 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
109361 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
109362 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
109363 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
109364 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
109365 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
109366 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
109367 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
109368 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
109369 +shmem_replace_page_9740 shmem_replace_page 0 9740 NULL
109370 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
109371 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
109372 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
109373 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
109374 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
109375 +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
109376 +tpm_data_in_9802 tpm_data_in 0 9802 NULL
109377 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 NULL nohasharray
109378 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 &ieee80211_if_read_state_9813
109379 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
109380 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
109381 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
109382 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
109383 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
109384 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
109385 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
109386 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
109387 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
109388 +read_file_misc_9948 read_file_misc 3 9948 NULL
109389 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
109390 +xfs_buf_geterror_9959 xfs_buf_geterror 0 9959 NULL
109391 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
109392 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
109393 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
109394 +gameport_read_9983 gameport_read 0 9983 NULL
109395 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
109396 +ceph_oloc_oid_to_pg_10003 ceph_oloc_oid_to_pg 0 10003 NULL
109397 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
109398 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
109399 +xfs_attr_rmtval_get_10092 xfs_attr_rmtval_get 0 10092 NULL
109400 +xfs_btree_check_lptr_10104 xfs_btree_check_lptr 0 10104 NULL
109401 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
109402 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
109403 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
109404 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
109405 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
109406 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
109407 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
109408 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
109409 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
109410 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
109411 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
109412 +xfs_attr_rmtval_copyout_10222 xfs_attr_rmtval_copyout 0 10222 NULL nohasharray
109413 +xfs_btree_read_buf_block_10222 xfs_btree_read_buf_block 0 10222 &xfs_attr_rmtval_copyout_10222
109414 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
109415 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
109416 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
109417 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
109418 +read_emulate_10310 read_emulate 2-4 10310 NULL
109419 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
109420 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
109421 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
109422 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
109423 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
109424 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
109425 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
109426 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
109427 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
109428 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
109429 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
109430 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
109431 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
109432 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
109433 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
109434 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
109435 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
109436 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
109437 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
109438 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
109439 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
109440 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
109441 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
109442 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
109443 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
109444 +otp_read_10594 otp_read 2-4-5 10594 NULL
109445 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
109446 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
109447 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
109448 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
109449 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
109450 +parport_write_10669 parport_write 0 10669 NULL
109451 +edge_write_10692 edge_write 4 10692 NULL
109452 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
109453 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
109454 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
109455 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
109456 +spi_sync_10731 spi_sync 0 10731 NULL
109457 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
109458 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
109459 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
109460 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
109461 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
109462 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
109463 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
109464 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
109465 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
109466 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
109467 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
109468 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
109469 +get_scq_10897 get_scq 2 10897 NULL
109470 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
109471 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
109472 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
109473 +kobject_add_10919 kobject_add 0 10919 NULL
109474 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
109475 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
109476 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
109477 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
109478 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
109479 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
109480 +gfs2_dir_read_11017 gfs2_dir_read 0 11017 NULL
109481 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
109482 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
109483 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
109484 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
109485 +count_argc_11083 count_argc 0 11083 NULL
109486 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
109487 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
109488 +page_offset_11120 page_offset 0 11120 NULL
109489 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL nohasharray
109490 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 &tracing_buffers_read_11124
109491 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
109492 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
109493 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
109494 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
109495 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
109496 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
109497 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
109498 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
109499 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
109500 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
109501 +shmem_radix_tree_replace_11325 shmem_radix_tree_replace 0 11325 NULL
109502 +construct_key_11329 construct_key 3 11329 NULL nohasharray
109503 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
109504 +next_segment_11330 next_segment 0-2-1 11330 NULL
109505 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
109506 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
109507 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
109508 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
109509 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
109510 +nft_value_dump_11381 nft_value_dump 3 11381 NULL
109511 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
109512 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
109513 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
109514 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
109515 +str_to_user_11411 str_to_user 2 11411 NULL
109516 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
109517 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
109518 +xfs_btree_lookup_11417 xfs_btree_lookup 0 11417 NULL nohasharray
109519 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 &xfs_btree_lookup_11417
109520 +trace_options_read_11419 trace_options_read 3 11419 NULL
109521 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
109522 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
109523 +bttv_read_11432 bttv_read 3 11432 NULL
109524 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
109525 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
109526 +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
109527 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
109528 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4-0 11492 NULL
109529 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
109530 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
109531 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
109532 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
109533 +xfs_rtcheck_alloc_range_11553 xfs_rtcheck_alloc_range 0 11553 NULL
109534 +radix_tree_extend_11555 radix_tree_extend 0 11555 NULL
109535 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
109536 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
109537 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
109538 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
109539 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
109540 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
109541 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
109542 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
109543 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
109544 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
109545 +slab_ksize_11664 slab_ksize 0 11664 NULL
109546 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
109547 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
109548 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
109549 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
109550 +split_11691 split 2 11691 NULL
109551 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
109552 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
109553 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
109554 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
109555 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
109556 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
109557 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
109558 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
109559 +xfs_ialloc_11819 xfs_ialloc 0 11819 NULL
109560 +umc_device_register_11824 umc_device_register 0 11824 NULL
109561 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
109562 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
109563 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
109564 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
109565 +xfs_file_aio_write_checks_11851 xfs_file_aio_write_checks 0 11851 NULL
109566 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
109567 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
109568 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
109569 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
109570 +ti_write_11916 ti_write 4 11916 NULL
109571 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
109572 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
109573 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
109574 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
109575 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
109576 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
109577 +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
109578 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
109579 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
109580 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
109581 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
109582 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
109583 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
109584 +gfs2_find_jhead_12117 gfs2_find_jhead 0 12117 NULL
109585 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
109586 +set_powered_12129 set_powered 4 12129 NULL
109587 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
109588 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
109589 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
109590 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
109591 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
109592 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
109593 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
109594 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
109595 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
109596 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
109597 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
109598 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
109599 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
109600 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
109601 +xfs_attr3_leaf_read_12222 xfs_attr3_leaf_read 0 12222 NULL
109602 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
109603 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
109604 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
109605 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
109606 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
109607 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
109608 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
109609 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
109610 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
109611 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
109612 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
109613 +xfs_bmap_last_extent_12335 xfs_bmap_last_extent 0 12335 NULL
109614 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
109615 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
109616 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
109617 +populate_dir_12391 populate_dir 0 12391 NULL nohasharray
109618 +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
109619 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
109620 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
109621 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
109622 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
109623 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
109624 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
109625 +__ceph_osdc_start_request_12502 __ceph_osdc_start_request 0 12502 NULL
109626 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
109627 +write_inode_now_12565 write_inode_now 0 12565 NULL
109628 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
109629 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
109630 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
109631 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
109632 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
109633 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
109634 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
109635 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
109636 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
109637 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
109638 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
109639 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
109640 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
109641 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
109642 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
109643 +ivtv_write_12721 ivtv_write 3 12721 NULL
109644 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
109645 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
109646 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
109647 +listxattr_12769 listxattr 3 12769 NULL
109648 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
109649 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
109650 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
109651 +readq_12825 readq 0 12825 NULL
109652 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
109653 +gfs2_log_reserve_12835 gfs2_log_reserve 0 12835 NULL
109654 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
109655 +spidev_sync_12842 spidev_sync 0 12842 NULL
109656 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
109657 +xfs_rtallocate_extent_exact_12865 xfs_rtallocate_extent_exact 0 12865 NULL
109658 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
109659 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
109660 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
109661 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
109662 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
109663 +bm_status_write_12964 bm_status_write 3 12964 NULL
109664 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
109665 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
109666 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
109667 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
109668 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
109669 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
109670 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
109671 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
109672 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
109673 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
109674 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
109675 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
109676 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
109677 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
109678 +blk_update_request_13146 blk_update_request 3 13146 NULL
109679 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
109680 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
109681 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
109682 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
109683 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
109684 +comedi_read_13199 comedi_read 3 13199 NULL
109685 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
109686 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
109687 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
109688 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
109689 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
109690 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
109691 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
109692 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
109693 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
109694 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
109695 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
109696 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
109697 +sd_major_13294 sd_major 0-1 13294 NULL
109698 +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
109699 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
109700 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
109701 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
109702 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
109703 +xfs_btree_delrec_13364 xfs_btree_delrec 0 13364 NULL
109704 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
109705 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
109706 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
109707 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
109708 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
109709 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
109710 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
109711 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
109712 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
109713 +data_read_13494 data_read 3 13494 NULL
109714 +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
109715 +core_status_13515 core_status 4 13515 NULL
109716 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
109717 +bm_init_13529 bm_init 2 13529 NULL
109718 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
109719 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
109720 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
109721 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
109722 +cache_write_13589 cache_write 3 13589 NULL
109723 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
109724 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
109725 +__ntfs_grab_cache_pages_13617 __ntfs_grab_cache_pages 0 13617 NULL
109726 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
109727 +packet_snd_13634 packet_snd 3 13634 NULL
109728 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
109729 +cache_downcall_13666 cache_downcall 3 13666 NULL
109730 +usb_get_string_13693 usb_get_string 0 13693 NULL
109731 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
109732 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
109733 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
109734 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
109735 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
109736 +random_read_13815 random_read 3 13815 NULL
109737 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
109738 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
109739 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
109740 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
109741 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
109742 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
109743 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
109744 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
109745 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
109746 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
109747 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
109748 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
109749 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
109750 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
109751 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL nohasharray
109752 +pagecache_write_end_13950 pagecache_write_end 0 13950 &lpfc_idiag_queacc_read_13950
109753 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
109754 +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
109755 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
109756 +qcam_read_13977 qcam_read 3 13977 NULL
109757 +dsp_read_13980 dsp_read 2 13980 NULL
109758 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
109759 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
109760 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
109761 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
109762 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
109763 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
109764 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
109765 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
109766 +xfs_bmap_alloc_14044 xfs_bmap_alloc 0 14044 NULL
109767 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
109768 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
109769 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
109770 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
109771 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
109772 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
109773 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
109774 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
109775 +em_canid_change_14150 em_canid_change 3 14150 NULL
109776 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
109777 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
109778 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
109779 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
109780 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
109781 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
109782 +alloc_async_14208 alloc_async 1 14208 NULL
109783 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
109784 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
109785 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
109786 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
109787 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
109788 +rr_status_14293 rr_status 5 14293 NULL
109789 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
109790 +update_rgrp_lvb_14303 update_rgrp_lvb 0 14303 NULL
109791 +xfs_qm_qino_alloc_14309 xfs_qm_qino_alloc 0 14309 NULL
109792 +oo_objects_14319 oo_objects 0 14319 NULL
109793 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
109794 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
109795 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
109796 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
109797 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
109798 +lowpan_read_14369 lowpan_read 3 14369 NULL
109799 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
109800 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
109801 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
109802 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
109803 +block_size_14443 block_size 0 14443 NULL
109804 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
109805 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
109806 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
109807 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
109808 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
109809 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
109810 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
109811 +split_state_14491 split_state 0 14491 NULL
109812 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
109813 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
109814 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
109815 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
109816 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
109817 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
109818 +stuffed_readpage_14581 stuffed_readpage 0 14581 NULL
109819 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
109820 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
109821 +dbJoin_14644 dbJoin 0 14644 NULL
109822 +profile_replace_14652 profile_replace 3 14652 NULL
109823 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
109824 +add_to_page_cache_locked_14668 add_to_page_cache_locked 0 14668 NULL
109825 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
109826 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
109827 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
109828 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
109829 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
109830 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
109831 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
109832 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
109833 +vfd_write_14717 vfd_write 3 14717 NULL
109834 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
109835 +raid1_resize_14740 raid1_resize 2 14740 NULL
109836 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
109837 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
109838 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
109839 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
109840 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
109841 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
109842 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
109843 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
109844 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
109845 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
109846 +xfs_btree_kill_iroot_14824 xfs_btree_kill_iroot 0 14824 NULL
109847 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
109848 +lcd_write_14857 lcd_write 3 14857 NULL
109849 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
109850 +xfs_bmapi_convert_unwritten_14886 xfs_bmapi_convert_unwritten 0 14886 NULL
109851 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
109852 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
109853 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
109854 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
109855 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
109856 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
109857 +queue_cnt_14951 queue_cnt 0 14951 NULL
109858 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
109859 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
109860 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
109861 +setkey_14987 setkey 3 14987 NULL nohasharray
109862 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
109863 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
109864 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
109865 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
109866 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
109867 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
109868 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
109869 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
109870 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
109871 +xfs_btree_insrec_15090 xfs_btree_insrec 0 15090 NULL
109872 +btrfs_readpage_15094 btrfs_readpage 0 15094 NULL
109873 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
109874 +start_port_15124 start_port 0 15124 NULL
109875 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
109876 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
109877 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
109878 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
109879 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
109880 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
109881 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
109882 +simple_strtol_15273 simple_strtol 0 15273 NULL
109883 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
109884 +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
109885 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
109886 +ioread16_15342 ioread16 0 15342 NULL
109887 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
109888 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
109889 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
109890 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
109891 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
109892 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
109893 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
109894 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
109895 +get_modalias_15406 get_modalias 2 15406 NULL
109896 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
109897 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
109898 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
109899 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
109900 +memweight_15450 memweight 2 15450 NULL
109901 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
109902 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
109903 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
109904 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
109905 +persistent_status_15574 persistent_status 4 15574 NULL
109906 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
109907 +vme_user_write_15587 vme_user_write 3 15587 NULL
109908 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
109909 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
109910 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
109911 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
109912 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
109913 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
109914 +fs_path_add_15648 fs_path_add 3 15648 NULL
109915 +__do_readpage_15652 __do_readpage 0 15652 NULL
109916 +xsd_read_15653 xsd_read 3 15653 NULL
109917 +unix_bind_15668 unix_bind 3 15668 NULL
109918 +dm_read_15674 dm_read 3 15674 NULL nohasharray
109919 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
109920 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
109921 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
109922 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
109923 +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
109924 +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
109925 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
109926 +table_size_15851 table_size 0-1-2 15851 NULL
109927 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
109928 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
109929 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
109930 +native_read_msr_15905 native_read_msr 0 15905 NULL
109931 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
109932 +power_read_15939 power_read 3 15939 NULL
109933 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
109934 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
109935 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
109936 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
109937 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
109938 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
109939 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
109940 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
109941 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
109942 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
109943 +gfs2_jdesc_check_16122 gfs2_jdesc_check 0 16122 NULL
109944 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
109945 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
109946 +fsm_init_16134 fsm_init 2 16134 NULL
109947 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
109948 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
109949 +mapping_level_16188 mapping_level 2-0 16188 NULL
109950 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
109951 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
109952 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
109953 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
109954 +create_table_16213 create_table 2 16213 NULL
109955 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
109956 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
109957 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
109958 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
109959 +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
109960 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
109961 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
109962 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
109963 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
109964 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
109965 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
109966 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
109967 +account_16283 account 0-4-2 16283 NULL nohasharray
109968 +mirror_status_16283 mirror_status 5 16283 &account_16283
109969 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
109970 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
109971 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
109972 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
109973 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
109974 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
109975 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
109976 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
109977 +xfs_inobt_lookup_16367 xfs_inobt_lookup 0 16367 NULL
109978 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
109979 +gfs2_dinode_in_16378 gfs2_dinode_in 0 16378 NULL
109980 +xfs_btree_check_block_16419 xfs_btree_check_block 0 16419 NULL
109981 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
109982 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
109983 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
109984 +cmdline_store_16442 cmdline_store 4 16442 NULL
109985 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
109986 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
109987 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
109988 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
109989 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
109990 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
109991 +raid10_resize_16537 raid10_resize 2 16537 NULL
109992 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
109993 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
109994 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
109995 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
109996 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
109997 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
109998 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
109999 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
110000 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
110001 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
110002 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
110003 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
110004 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
110005 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
110006 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
110007 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
110008 +xfs_dialloc_ag_16868 xfs_dialloc_ag 0 16868 NULL
110009 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL nohasharray
110010 +xfs_iget_16872 xfs_iget 0 16872 &alloc_idx_lebs_16872
110011 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
110012 +st_write_16874 st_write 3 16874 NULL
110013 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
110014 +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
110015 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
110016 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
110017 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
110018 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
110019 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
110020 +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
110021 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
110022 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
110023 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
110024 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
110025 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
110026 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
110027 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
110028 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
110029 +entry_length_17093 entry_length 0 17093 NULL
110030 +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
110031 +write_mem_17114 write_mem 3 17114 NULL
110032 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
110033 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
110034 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
110035 +sep_read_17161 sep_read 3 17161 NULL
110036 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
110037 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
110038 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
110039 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
110040 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
110041 +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
110042 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
110043 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
110044 +sync_request_17208 sync_request 2 17208 NULL
110045 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
110046 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
110047 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
110048 +alloc_ep_17269 alloc_ep 1 17269 NULL
110049 +pg_read_17276 pg_read 3 17276 NULL
110050 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
110051 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
110052 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
110053 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
110054 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
110055 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
110056 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
110057 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
110058 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
110059 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
110060 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
110061 +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
110062 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
110063 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
110064 +xfs_btree_lshift_17448 xfs_btree_lshift 0 17448 NULL
110065 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
110066 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
110067 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
110068 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
110069 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
110070 +qp_free_res_17541 qp_free_res 5 17541 NULL
110071 +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
110072 +copy_from_user_17559 copy_from_user 0-3 17559 NULL
110073 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
110074 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
110075 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
110076 +osst_execute_17607 osst_execute 7-6 17607 NULL
110077 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
110078 +dma_map_page_17628 dma_map_page 0 17628 NULL
110079 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
110080 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
110081 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
110082 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
110083 +filemap_fdatawait_17688 filemap_fdatawait 0 17688 NULL
110084 +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
110085 +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
110086 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
110087 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
110088 +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
110089 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
110090 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
110091 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
110092 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
110093 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
110094 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
110095 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
110096 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
110097 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
110098 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
110099 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
110100 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
110101 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
110102 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
110103 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
110104 +xfs_rtallocate_extent_near_17916 xfs_rtallocate_extent_near 0 17916 NULL
110105 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
110106 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
110107 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
110108 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
110109 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
110110 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
110111 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
110112 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
110113 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
110114 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
110115 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
110116 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
110117 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
110118 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
110119 +fpregs_get_18066 fpregs_get 4 18066 NULL
110120 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
110121 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
110122 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
110123 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
110124 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
110125 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
110126 +svc_getnl_18120 svc_getnl 0 18120 NULL
110127 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
110128 +xfs_zero_eof_18134 xfs_zero_eof 0 18134 NULL
110129 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
110130 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
110131 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
110132 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
110133 +read_rindex_entry_18213 read_rindex_entry 0 18213 NULL
110134 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
110135 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
110136 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
110137 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
110138 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
110139 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
110140 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
110141 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
110142 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
110143 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
110144 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
110145 +um_idi_write_18293 um_idi_write 3 18293 NULL
110146 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
110147 +vga_r_18310 vga_r 0 18310 NULL
110148 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
110149 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
110150 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
110151 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
110152 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
110153 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
110154 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
110155 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
110156 +ep_io_18367 ep_io 0 18367 NULL
110157 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
110158 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
110159 +ci_role_write_18388 ci_role_write 3 18388 NULL
110160 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
110161 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
110162 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
110163 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
110164 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
110165 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
110166 +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
110167 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
110168 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
110169 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
110170 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
110171 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
110172 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
110173 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
110174 +__block_write_begin_18511 __block_write_begin 0 18511 NULL
110175 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
110176 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
110177 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
110178 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
110179 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
110180 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
110181 +debug_output_18575 debug_output 3 18575 NULL
110182 +xfs_btree_read_bufl_18597 xfs_btree_read_bufl 0 18597 NULL
110183 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL
110184 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
110185 +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL
110186 +from_buffer_18625 from_buffer 3 18625 NULL
110187 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
110188 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
110189 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
110190 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
110191 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
110192 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
110193 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
110194 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
110195 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
110196 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
110197 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
110198 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
110199 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
110200 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
110201 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
110202 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
110203 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
110204 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
110205 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
110206 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
110207 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
110208 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
110209 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
110210 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
110211 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
110212 +clean_journal_18955 clean_journal 0 18955 NULL
110213 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
110214 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
110215 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
110216 +huge_page_size_19008 huge_page_size 0 19008 NULL
110217 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
110218 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
110219 +revalidate_19043 revalidate 2 19043 NULL
110220 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
110221 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
110222 +get_log_header_19063 get_log_header 0 19063 NULL
110223 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
110224 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
110225 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
110226 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
110227 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
110228 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
110229 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
110230 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
110231 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
110232 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
110233 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
110234 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
110235 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
110236 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
110237 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
110238 +ucma_query_19260 ucma_query 4 19260 NULL
110239 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
110240 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
110241 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
110242 +qc_capture_19298 qc_capture 3 19298 NULL
110243 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
110244 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
110245 +debug_read_19322 debug_read 3 19322 NULL
110246 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
110247 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
110248 +closure_sub_19359 closure_sub 2 19359 NULL
110249 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
110250 +read_zero_19366 read_zero 3 19366 NULL
110251 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
110252 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
110253 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
110254 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
110255 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
110256 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
110257 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
110258 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
110259 +sky2_read16_19475 sky2_read16 0 19475 NULL
110260 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
110261 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
110262 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
110263 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
110264 +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
110265 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
110266 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
110267 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
110268 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
110269 +nfsd_read_19568 nfsd_read 5 19568 NULL
110270 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
110271 +mnt_want_write_file_19579 mnt_want_write_file 0 19579 NULL
110272 +bm_status_read_19583 bm_status_read 3 19583 NULL
110273 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
110274 +fallocate_chunk_19610 fallocate_chunk 0 19610 NULL
110275 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
110276 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
110277 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
110278 +ocfs2_control_get_this_node_19721 ocfs2_control_get_this_node 0 19721 NULL
110279 +read_reg_19723 read_reg 0 19723 NULL
110280 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
110281 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
110282 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
110283 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
110284 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
110285 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
110286 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
110287 +readhscx_19769 readhscx 0 19769 NULL
110288 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
110289 +xfs_bmap_add_extent_hole_real_19828 xfs_bmap_add_extent_hole_real 0 19828 NULL
110290 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
110291 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
110292 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
110293 +__nla_put_19857 __nla_put 3 19857 NULL
110294 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
110295 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
110296 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
110297 +mangle_name_19923 mangle_name 0 19923 NULL
110298 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
110299 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
110300 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
110301 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
110302 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
110303 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
110304 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
110305 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
110306 +event_trigger_write_20009 event_trigger_write 3 20009 NULL nohasharray
110307 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 &event_trigger_write_20009
110308 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
110309 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
110310 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
110311 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
110312 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
110313 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
110314 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
110315 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
110316 +team_options_register_20091 team_options_register 3 20091 NULL
110317 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
110318 +xfs_qm_dqget_20103 xfs_qm_dqget 0 20103 NULL
110319 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
110320 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
110321 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
110322 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
110323 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
110324 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
110325 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
110326 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
110327 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
110328 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
110329 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
110330 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
110331 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
110332 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
110333 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
110334 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
110335 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
110336 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
110337 +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
110338 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
110339 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
110340 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
110341 +read_buf_20469 read_buf 2 20469 NULL
110342 +bio_trim_20472 bio_trim 2 20472 NULL
110343 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
110344 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
110345 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
110346 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
110347 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
110348 +venus_create_20555 venus_create 4 20555 NULL
110349 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
110350 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
110351 +xfs_bmap_isaeof_20570 xfs_bmap_isaeof 0 20570 NULL
110352 +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
110353 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
110354 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
110355 +lirc_write_20604 lirc_write 3 20604 NULL
110356 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
110357 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
110358 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
110359 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
110360 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
110361 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
110362 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
110363 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL nohasharray
110364 +btrfs_qgroup_reserve_20676 btrfs_qgroup_reserve 0 20676 &snd_hdsp_playback_copy_20676
110365 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
110366 +cpumask_size_20683 cpumask_size 0 20683 NULL
110367 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
110368 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
110369 +__maestro_read_20700 __maestro_read 0 20700 NULL
110370 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
110371 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
110372 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
110373 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
110374 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
110375 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
110376 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
110377 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL nohasharray
110378 +mnt_clone_write_20763 mnt_clone_write 0 20763 &brcmf_p2p_escan_20763
110379 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
110380 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
110381 +lowpan_write_20800 lowpan_write 3 20800 NULL
110382 +strndup_user_20819 strndup_user 2 20819 NULL nohasharray
110383 +do_glock_20819 do_glock 0 20819 &strndup_user_20819
110384 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
110385 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
110386 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
110387 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
110388 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
110389 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
110390 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
110391 +srq_free_res_20868 srq_free_res 5 20868 NULL
110392 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
110393 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
110394 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
110395 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
110396 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
110397 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
110398 +htable_bits_20933 htable_bits 0 20933 NULL
110399 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
110400 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
110401 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
110402 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
110403 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
110404 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
110405 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
110406 +btrfs_dirty_pages_21019 btrfs_dirty_pages 0 21019 NULL
110407 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
110408 +xfs_btree_new_root_21028 xfs_btree_new_root 0 21028 NULL
110409 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
110410 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
110411 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
110412 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
110413 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
110414 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
110415 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
110416 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
110417 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
110418 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
110419 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
110420 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
110421 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
110422 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
110423 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
110424 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
110425 +input_ff_create_21240 input_ff_create 2 21240 NULL
110426 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
110427 +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
110428 +fru_length_21257 fru_length 0 21257 NULL
110429 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
110430 +xfs_alloc_ag_vextent_size_21276 xfs_alloc_ag_vextent_size 0 21276 NULL
110431 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
110432 +add_res_range_21310 add_res_range 4 21310 NULL
110433 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
110434 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
110435 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
110436 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
110437 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
110438 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
110439 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
110440 +insert_ptr_21386 insert_ptr 6 21386 NULL
110441 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
110442 +__clone_and_map_simple_bio_21404 __clone_and_map_simple_bio 4 21404 NULL
110443 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
110444 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
110445 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
110446 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
110447 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
110448 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
110449 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
110450 +ReadISAR_21453 ReadISAR 0 21453 NULL
110451 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
110452 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
110453 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
110454 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
110455 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
110456 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
110457 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
110458 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
110459 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
110460 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
110461 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
110462 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
110463 +gfs2_glock_nq_init_21624 gfs2_glock_nq_init 0 21624 NULL
110464 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
110465 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
110466 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
110467 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
110468 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
110469 +xfs_btree_insert_21712 xfs_btree_insert 0 21712 NULL
110470 +update_time_21719 update_time 0 21719 NULL
110471 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
110472 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
110473 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
110474 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
110475 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
110476 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
110477 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
110478 +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
110479 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
110480 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
110481 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
110482 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
110483 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
110484 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
110485 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
110486 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
110487 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
110488 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
110489 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
110490 +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
110491 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
110492 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
110493 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
110494 +lookup_metapath_22039 lookup_metapath 0 22039 NULL
110495 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
110496 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
110497 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
110498 +mem_rw_22085 mem_rw 3 22085 NULL
110499 +xfs_bmapi_reserve_delalloc_22086 xfs_bmapi_reserve_delalloc 0 22086 NULL
110500 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
110501 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
110502 +shmem_add_to_page_cache_22121 shmem_add_to_page_cache 0 22121 NULL
110503 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
110504 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
110505 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
110506 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
110507 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
110508 +mem_write_22232 mem_write 3 22232 NULL
110509 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
110510 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
110511 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
110512 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
110513 +add_res_tree_22263 add_res_tree 7 22263 NULL
110514 +__btrfs_direct_write_22273 __btrfs_direct_write 4-0 22273 NULL
110515 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
110516 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
110517 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
110518 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
110519 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
110520 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
110521 +atomic_read_22342 atomic_read 0 22342 NULL
110522 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
110523 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
110524 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
110525 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
110526 +zoran_write_22404 zoran_write 3 22404 NULL
110527 +queue_reply_22416 queue_reply 3 22416 NULL
110528 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
110529 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
110530 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
110531 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
110532 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
110533 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
110534 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
110535 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
110536 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
110537 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
110538 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
110539 +snapshot_read_22601 snapshot_read 3 22601 NULL
110540 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
110541 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
110542 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
110543 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
110544 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
110545 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
110546 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
110547 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
110548 +reg_umr_22686 reg_umr 5 22686 NULL
110549 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
110550 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
110551 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
110552 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
110553 +__writeback_single_inode_22739 __writeback_single_inode 0 22739 NULL
110554 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
110555 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
110556 +print_frame_22769 print_frame 0 22769 NULL
110557 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
110558 +__break_lease_22777 __break_lease 0 22777 NULL
110559 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
110560 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
110561 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
110562 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
110563 +create_attr_set_22861 create_attr_set 1 22861 NULL
110564 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
110565 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
110566 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
110567 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
110568 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
110569 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
110570 +__set_xattr_22923 __set_xattr 0 22923 NULL
110571 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
110572 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
110573 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
110574 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
110575 +vme_get_size_22964 vme_get_size 0 22964 NULL
110576 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
110577 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
110578 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
110579 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
110580 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
110581 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
110582 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0 23029 NULL
110583 +st_status_23032 st_status 5 23032 NULL
110584 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
110585 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
110586 +security_inode_killpriv_23060 security_inode_killpriv 0 23060 NULL
110587 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
110588 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
110589 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
110590 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
110591 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
110592 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
110593 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
110594 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
110595 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
110596 +xfs_dir_ialloc_23100 xfs_dir_ialloc 0 23100 NULL
110597 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
110598 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
110599 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
110600 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL nohasharray
110601 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 &nl80211_send_rx_auth_23111
110602 +__clear_user_23118 __clear_user 0-2 23118 NULL
110603 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
110604 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
110605 +read_file_ani_23161 read_file_ani 3 23161 NULL
110606 +usblp_write_23178 usblp_write 3 23178 NULL
110607 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
110608 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
110609 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
110610 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
110611 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
110612 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
110613 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
110614 +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
110615 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
110616 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
110617 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
110618 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
110619 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
110620 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
110621 +page_readlink_23346 page_readlink 3 23346 NULL
110622 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
110623 +get_dst_timing_23358 get_dst_timing 0 23358 NULL nohasharray
110624 +write_inode_23358 write_inode 0 23358 &get_dst_timing_23358
110625 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
110626 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
110627 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
110628 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
110629 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
110630 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
110631 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
110632 +sync_mapping_buffers_23485 sync_mapping_buffers 0 23485 &linear_conf_23485
110633 +event_filter_read_23494 event_filter_read 3 23494 NULL
110634 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
110635 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
110636 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
110637 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
110638 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
110639 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
110640 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
110641 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
110642 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
110643 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
110644 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
110645 +xfs_qm_dqread_23613 xfs_qm_dqread 0 23613 NULL
110646 +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
110647 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
110648 +sInW_23663 sInW 0 23663 NULL
110649 +SyS_connect_23669 SyS_connect 3 23669 NULL
110650 +cx18_read_23699 cx18_read 3 23699 NULL
110651 +at_get_23708 at_get 0 23708 NULL
110652 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
110653 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
110654 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
110655 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
110656 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
110657 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
110658 +map_write_23795 map_write 3 23795 NULL
110659 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
110660 +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
110661 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
110662 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
110663 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 0-4-3 23829 NULL
110664 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
110665 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
110666 +p54_init_common_23850 p54_init_common 1 23850 NULL
110667 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
110668 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
110669 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
110670 +writeback_single_inode_23881 writeback_single_inode 0 23881 NULL nohasharray
110671 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 &writeback_single_inode_23881
110672 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
110673 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
110674 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
110675 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
110676 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
110677 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
110678 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
110679 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
110680 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
110681 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
110682 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
110683 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
110684 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
110685 +give_pages_24021 give_pages 3 24021 NULL
110686 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
110687 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
110688 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
110689 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
110690 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
110691 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
110692 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
110693 +lov_brw_24122 lov_brw 4 24122 NULL
110694 +mpu401_read_24126 mpu401_read 3-0 24126 NULL
110695 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
110696 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL nohasharray
110697 +xfs_btree_increment_24139 xfs_btree_increment 0 24139 &irnet_ctrl_write_24139
110698 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
110699 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
110700 +adu_read_24177 adu_read 3 24177 NULL
110701 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
110702 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
110703 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
110704 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
110705 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
110706 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
110707 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
110708 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
110709 +xfs_bmap_rtalloc_24237 xfs_bmap_rtalloc 0 24237 NULL
110710 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
110711 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
110712 +thin_status_24278 thin_status 5 24278 NULL
110713 +msg_size_24288 msg_size 0 24288 NULL
110714 +gserial_connect_24302 gserial_connect 0 24302 NULL
110715 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
110716 +reserve_metadata_bytes_24313 reserve_metadata_bytes 0 24313 NULL
110717 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
110718 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
110719 +prepare_pages_24349 prepare_pages 0 24349 NULL
110720 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
110721 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
110722 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
110723 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
110724 +igetword_24373 igetword 0 24373 NULL nohasharray
110725 +break_deleg_24373 break_deleg 0 24373 &igetword_24373
110726 +max_io_len_24384 max_io_len 0-1 24384 NULL
110727 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
110728 +xfs_bmapi_read_24392 xfs_bmapi_read 0 24392 NULL
110729 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
110730 +getxattr_24398 getxattr 4 24398 NULL nohasharray
110731 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
110732 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
110733 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
110734 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
110735 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
110736 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
110737 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
110738 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
110739 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
110740 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
110741 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
110742 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
110743 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
110744 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
110745 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
110746 +pd_video_read_24510 pd_video_read 3 24510 NULL
110747 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
110748 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
110749 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
110750 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
110751 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
110752 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
110753 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
110754 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
110755 +SyS_poll_24620 SyS_poll 2 24620 NULL
110756 +context_alloc_24645 context_alloc 3 24645 NULL
110757 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
110758 +xfs_log_commit_cil_24653 xfs_log_commit_cil 0 24653 NULL
110759 +btrfs_check_data_free_space_24692 btrfs_check_data_free_space 0 24692 NULL
110760 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
110761 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
110762 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
110763 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
110764 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
110765 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
110766 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
110767 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
110768 +cache_read_24790 cache_read 3 24790 NULL
110769 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
110770 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
110771 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
110772 +net2272_read_24825 net2272_read 0 24825 NULL
110773 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
110774 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
110775 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
110776 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
110777 +queues_read_24877 queues_read 3 24877 NULL
110778 +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
110779 +xfs_qm_dqattach_24898 xfs_qm_dqattach 0 24898 NULL
110780 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
110781 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 NULL nohasharray
110782 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 &__btrfs_free_extent_24927
110783 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
110784 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
110785 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
110786 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
110787 +slot_get_24999 slot_get 0 24999 NULL
110788 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
110789 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
110790 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
110791 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
110792 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
110793 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
110794 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
110795 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
110796 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
110797 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
110798 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
110799 +gfs2_quota_check_25130 gfs2_quota_check 0 25130 NULL
110800 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
110801 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
110802 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
110803 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
110804 +stripe_status_25259 stripe_status 5 25259 NULL
110805 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
110806 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
110807 +vfs_writev_25278 vfs_writev 3 25278 NULL
110808 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
110809 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
110810 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
110811 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
110812 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
110813 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
110814 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
110815 +xfs_ialloc_pagi_init_25411 xfs_ialloc_pagi_init 0 25411 NULL
110816 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
110817 +xfs_qm_dqtobp_25448 xfs_qm_dqtobp 0 25448 NULL
110818 +generic_file_buffered_write_25464 generic_file_buffered_write 4-0-7 25464 NULL
110819 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
110820 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
110821 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
110822 +xfs_alloc_fix_freelist_25514 xfs_alloc_fix_freelist 0 25514 NULL
110823 +sb_permission_25523 sb_permission 0 25523 NULL
110824 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
110825 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
110826 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
110827 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
110828 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
110829 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
110830 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
110831 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
110832 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
110833 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
110834 +__direct_map_25647 __direct_map 5-6 25647 NULL
110835 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
110836 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
110837 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
110838 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
110839 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
110840 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
110841 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
110842 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
110843 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
110844 +sg_read_25799 sg_read 3 25799 NULL
110845 +xfs_alloc_ag_vextent_exact_25810 xfs_alloc_ag_vextent_exact 0 25810 NULL
110846 +system_enable_read_25815 system_enable_read 3 25815 NULL
110847 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
110848 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
110849 +parport_read_25855 parport_read 0 25855 NULL
110850 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
110851 +key_attr_size_25865 key_attr_size 0 25865 NULL
110852 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
110853 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
110854 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
110855 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
110856 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
110857 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
110858 +rcname_read_25919 rcname_read 3 25919 NULL
110859 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
110860 +key_flags_read_25931 key_flags_read 3 25931 NULL
110861 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
110862 +flush_25957 flush 2 25957 NULL
110863 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
110864 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
110865 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
110866 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
110867 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
110868 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
110869 +btrfs_wait_ordered_range_26086 btrfs_wait_ordered_range 0 26086 NULL
110870 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
110871 +read_sb_page_26119 read_sb_page 5 26119 NULL
110872 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
110873 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
110874 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
110875 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
110876 +disk_devt_26180 disk_devt 0 26180 NULL
110877 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
110878 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
110879 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
110880 +mce_write_26201 mce_write 3 26201 NULL
110881 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
110882 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
110883 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
110884 +simple_setattr_26234 simple_setattr 0 26234 NULL
110885 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
110886 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
110887 +apei_resources_request_26279 apei_resources_request 0 26279 NULL
110888 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
110889 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
110890 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
110891 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
110892 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
110893 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
110894 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
110895 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
110896 +ntty_write_26404 ntty_write 3 26404 NULL
110897 +firmware_store_26408 firmware_store 4 26408 NULL
110898 +pagemap_read_26441 pagemap_read 3 26441 NULL
110899 +tower_read_26461 tower_read 3 26461 NULL nohasharray
110900 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
110901 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
110902 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
110903 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
110904 +read_vmcore_26501 read_vmcore 3 26501 NULL
110905 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
110906 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
110907 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
110908 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
110909 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
110910 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
110911 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
110912 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
110913 +xfs_rtcheck_range_26614 xfs_rtcheck_range 0 26614 NULL
110914 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
110915 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
110916 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
110917 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
110918 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
110919 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
110920 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
110921 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
110922 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
110923 +bos_desc_26752 bos_desc 0 26752 NULL
110924 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
110925 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
110926 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
110927 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
110928 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
110929 +smk_write_load_26829 smk_write_load 3 26829 NULL
110930 +xfs_alloc_pagf_init_26834 xfs_alloc_pagf_init 0 26834 NULL
110931 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
110932 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
110933 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
110934 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
110935 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
110936 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
110937 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
110938 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
110939 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
110940 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
110941 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
110942 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
110943 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
110944 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
110945 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
110946 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
110947 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
110948 +xfs_filestream_associate_27030 xfs_filestream_associate 0 27030 NULL
110949 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
110950 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
110951 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
110952 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
110953 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
110954 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
110955 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
110956 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
110957 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
110958 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
110959 +pms_capture_27142 pms_capture 4 27142 NULL
110960 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
110961 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
110962 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
110963 +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
110964 +write_kmem_27225 write_kmem 3 27225 NULL
110965 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
110966 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
110967 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
110968 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
110969 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
110970 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
110971 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
110972 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
110973 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
110974 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
110975 +seq_read_27411 seq_read 3 27411 NULL
110976 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
110977 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
110978 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0 27422 NULL
110979 +cypress_write_27423 cypress_write 4 27423 NULL
110980 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
110981 +xfs_btree_lookup_get_block_27448 xfs_btree_lookup_get_block 0 27448 NULL
110982 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
110983 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
110984 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
110985 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
110986 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
110987 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
110988 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
110989 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
110990 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
110991 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
110992 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
110993 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
110994 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
110995 +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
110996 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642 nohasharray
110997 +xfs_alloc_vextent_27642 xfs_alloc_vextent 0 27642 &ocfs2_direct_IO_27642
110998 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
110999 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
111000 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
111001 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
111002 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
111003 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
111004 +evm_write_key_27715 evm_write_key 3 27715 NULL
111005 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
111006 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
111007 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
111008 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
111009 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
111010 +SyS_readv_27804 SyS_readv 3 27804 NULL
111011 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
111012 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
111013 +init_header_complete_27833 init_header_complete 0 27833 NULL
111014 +read_profile_27859 read_profile 3 27859 NULL
111015 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
111016 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
111017 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
111018 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL nohasharray
111019 +bio_next_split_27961 bio_next_split 2 27961 &tracing_clock_write_27961
111020 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
111021 +device_register_27972 device_register 0 27972 NULL nohasharray
111022 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
111023 +xfs_alloc_fixup_trees_27975 xfs_alloc_fixup_trees 0 27975 NULL
111024 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL nohasharray
111025 +__kernfs_setattr_27977 __kernfs_setattr 0 27977 &pci_enable_device_flags_27977
111026 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
111027 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
111028 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
111029 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
111030 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
111031 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
111032 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
111033 +pool_status_28055 pool_status 5 28055 NULL
111034 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
111035 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
111036 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
111037 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
111038 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
111039 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
111040 +memblock_virt_alloc_from_nopanic_28146 memblock_virt_alloc_from_nopanic 1 28146 NULL
111041 +video_read_28148 video_read 3 28148 NULL
111042 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
111043 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
111044 +vread_28173 vread 0-3 28173 NULL
111045 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
111046 +counter_free_res_28187 counter_free_res 5 28187 NULL
111047 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
111048 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
111049 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
111050 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
111051 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
111052 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
111053 +usemap_size_28281 usemap_size 0 28281 NULL
111054 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
111055 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
111056 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
111057 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
111058 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
111059 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
111060 +generic_write_checks_28329 generic_write_checks 0 28329 NULL
111061 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
111062 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
111063 +snapshot_write_28351 snapshot_write 3 28351 NULL
111064 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
111065 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
111066 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
111067 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
111068 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
111069 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
111070 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
111071 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
111072 +xfs_rtfind_back_28450 xfs_rtfind_back 0 28450 NULL
111073 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
111074 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
111075 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
111076 +__filemap_fdatawrite_28485 __filemap_fdatawrite 0 28485 NULL
111077 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
111078 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
111079 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
111080 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
111081 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
111082 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
111083 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
111084 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
111085 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
111086 +gfs2_meta_indirect_buffer_28573 gfs2_meta_indirect_buffer 0 28573 NULL
111087 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
111088 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
111089 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
111090 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
111091 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
111092 +xfs_bmap_finish_28644 xfs_bmap_finish 0 28644 NULL
111093 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
111094 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
111095 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
111096 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
111097 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
111098 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
111099 +spi_execute_28736 spi_execute 5 28736 NULL
111100 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
111101 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
111102 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
111103 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
111104 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
111105 +sel_write_member_28800 sel_write_member 3 28800 NULL
111106 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
111107 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
111108 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
111109 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
111110 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
111111 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
111112 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
111113 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
111114 +push_rx_28939 push_rx 3 28939 NULL
111115 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
111116 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
111117 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
111118 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
111119 +xfs_alloc_update_28982 xfs_alloc_update 0 28982 NULL
111120 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
111121 +bin_uuid_28999 bin_uuid 3 28999 NULL
111122 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
111123 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
111124 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
111125 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
111126 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
111127 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
111128 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
111129 +xfs_alloc_ag_vextent_small_29084 xfs_alloc_ag_vextent_small 0 29084 NULL
111130 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
111131 +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
111132 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
111133 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
111134 +snprintf_29125 snprintf 0 29125 NULL
111135 +iov_shorten_29130 iov_shorten 0 29130 NULL
111136 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
111137 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
111138 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
111139 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
111140 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
111141 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
111142 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
111143 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
111144 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
111145 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
111146 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
111147 +xfs_bmap_btree_to_extents_29297 xfs_bmap_btree_to_extents 0 29297 NULL
111148 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
111149 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
111150 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
111151 +xfs_bmbt_change_owner_29325 xfs_bmbt_change_owner 0 29325 NULL
111152 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
111153 +tun_put_user_29337 tun_put_user 5 29337 NULL
111154 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
111155 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
111156 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
111157 +mempool_create_29437 mempool_create 1 29437 NULL
111158 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
111159 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
111160 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
111161 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
111162 +do_register_entry_29478 do_register_entry 4 29478 NULL
111163 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
111164 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
111165 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
111166 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
111167 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
111168 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
111169 +add_to_page_cache_lru_29534 add_to_page_cache_lru 0 29534 NULL
111170 +ftrace_write_29551 ftrace_write 3 29551 NULL
111171 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
111172 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
111173 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
111174 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
111175 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
111176 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
111177 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
111178 +slots_per_page_29601 slots_per_page 0 29601 NULL
111179 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
111180 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
111181 +gfs2_alloc_blocks_29630 gfs2_alloc_blocks 0 29630 NULL
111182 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
111183 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
111184 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
111185 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
111186 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
111187 +probes_write_29711 probes_write 3 29711 NULL
111188 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
111189 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
111190 +std_nic_write_29752 std_nic_write 3 29752 NULL
111191 +dbAlloc_29794 dbAlloc 0 29794 NULL
111192 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
111193 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
111194 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
111195 +count_partial_29850 count_partial 0 29850 NULL
111196 +xfs_rtfind_forw_29866 xfs_rtfind_forw 0 29866 NULL
111197 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
111198 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
111199 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
111200 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
111201 +xfs_alloc_read_agf_29893 xfs_alloc_read_agf 0 29893 NULL
111202 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
111203 +write_file_queue_29922 write_file_queue 3 29922 NULL
111204 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
111205 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
111206 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
111207 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
111208 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
111209 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
111210 +drp_wmove_30043 drp_wmove 4 30043 NULL
111211 +mem_cgroup_charge_common_30047 mem_cgroup_charge_common 0 30047 NULL
111212 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
111213 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
111214 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
111215 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
111216 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
111217 +xfs_iget_cache_miss_30115 xfs_iget_cache_miss 0 30115 NULL
111218 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
111219 +recv_stream_30138 recv_stream 4 30138 NULL
111220 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
111221 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
111222 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
111223 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
111224 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
111225 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
111226 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
111227 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
111228 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
111229 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
111230 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
111231 +shmem_unuse_inode_30263 shmem_unuse_inode 0 30263 NULL
111232 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
111233 +try_break_deleg_30271 try_break_deleg 0 30271 NULL nohasharray
111234 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 &try_break_deleg_30271
111235 +compat_readv_30273 compat_readv 3 30273 NULL
111236 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
111237 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
111238 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
111239 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
111240 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
111241 +i8254_read_30330 i8254_read 0 30330 NULL
111242 +resource_from_user_30341 resource_from_user 3 30341 NULL
111243 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
111244 +gfs2_trans_begin_30359 gfs2_trans_begin 0 30359 NULL
111245 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
111246 +pagecache_write_begin_30364 pagecache_write_begin 0 30364 NULL
111247 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
111248 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
111249 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
111250 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
111251 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
111252 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
111253 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
111254 +enable_write_30456 enable_write 3 30456 NULL
111255 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
111256 +urandom_read_30462 urandom_read 3 30462 NULL
111257 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
111258 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
111259 +adu_write_30487 adu_write 3 30487 NULL
111260 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
111261 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
111262 +__send_duplicate_bios_30498 __send_duplicate_bios 4 30498 NULL
111263 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
111264 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
111265 +set_config_30526 set_config 0 30526 NULL nohasharray
111266 +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
111267 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
111268 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
111269 +set_le_30581 set_le 4 30581 NULL
111270 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
111271 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
111272 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
111273 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
111274 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
111275 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
111276 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
111277 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
111278 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
111279 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL nohasharray
111280 +xfs_bmap_add_extent_unwritten_real_30701 xfs_bmap_add_extent_unwritten_real 0 30701 &dccp_setsockopt_ccid_30701
111281 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
111282 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
111283 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
111284 +snapshot_status_30744 snapshot_status 5 30744 NULL
111285 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
111286 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
111287 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
111288 +xlog_grant_head_wait_30829 xlog_grant_head_wait 0 30829 NULL
111289 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
111290 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
111291 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
111292 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
111293 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
111294 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
111295 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
111296 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
111297 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
111298 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
111299 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
111300 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
111301 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
111302 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
111303 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
111304 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
111305 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
111306 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
111307 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
111308 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
111309 +depth_read_31112 depth_read 3 31112 NULL
111310 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
111311 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
111312 +size_inside_page_31141 size_inside_page 0 31141 NULL
111313 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
111314 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
111315 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
111316 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
111317 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
111318 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
111319 +__read_reg_31216 __read_reg 0 31216 NULL
111320 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
111321 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
111322 +cyy_readb_31240 cyy_readb 0 31240 NULL
111323 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
111324 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
111325 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
111326 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
111327 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
111328 +command_file_write_31318 command_file_write 3 31318 NULL
111329 +radix_tree_insert_31336 radix_tree_insert 0 31336 NULL
111330 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
111331 +outlen_write_31358 outlen_write 3 31358 NULL
111332 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
111333 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
111334 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
111335 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
111336 +inb_31388 inb 0 31388 NULL
111337 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
111338 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
111339 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
111340 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
111341 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
111342 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
111343 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
111344 +alg_setkey_31485 alg_setkey 3 31485 NULL
111345 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
111346 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
111347 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
111348 +hidraw_write_31536 hidraw_write 3 31536 NULL
111349 +usbvision_read_31555 usbvision_read 3 31555 NULL
111350 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
111351 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
111352 +osst_write_31581 osst_write 3 31581 NULL
111353 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
111354 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
111355 +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
111356 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL nohasharray
111357 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 &arvo_sysfs_read_31617
111358 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
111359 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
111360 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
111361 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
111362 +__lgread_31668 __lgread 4 31668 NULL
111363 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
111364 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
111365 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
111366 +gfs2_dir_check_31711 gfs2_dir_check 0 31711 NULL
111367 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
111368 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
111369 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
111370 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
111371 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
111372 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
111373 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
111374 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
111375 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
111376 +osync_buffers_list_31789 osync_buffers_list 0 31789 NULL
111377 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
111378 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
111379 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
111380 +data_write_31805 data_write 3 31805 NULL
111381 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
111382 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
111383 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
111384 +clone_bio_31854 clone_bio 4-3 31854 NULL
111385 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
111386 +foreach_descriptor_31873 foreach_descriptor 0 31873 NULL
111387 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
111388 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
111389 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
111390 +xattr_permission_31907 xattr_permission 0 31907 NULL
111391 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
111392 +new_dir_31919 new_dir 3 31919 NULL
111393 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
111394 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
111395 +read_mem_31942 read_mem 3 31942 NULL nohasharray
111396 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
111397 +vb2_write_31948 vb2_write 3 31948 NULL
111398 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
111399 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
111400 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
111401 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
111402 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
111403 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
111404 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
111405 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
111406 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
111407 +calc_hmac_32010 calc_hmac 3 32010 NULL
111408 +aead_len_32021 aead_len 0 32021 NULL
111409 +stk_read_32038 stk_read 3 32038 NULL
111410 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
111411 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
111412 +xfs_buf_iowait_32068 xfs_buf_iowait 0 32068 NULL
111413 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
111414 +bio_alloc_32095 bio_alloc 2 32095 NULL
111415 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
111416 +disk_status_32120 disk_status 4 32120 NULL
111417 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
111418 +venus_link_32165 venus_link 5 32165 NULL
111419 +do_writepages_32173 do_writepages 0 32173 NULL
111420 +del_ptr_32197 del_ptr 4 32197 NULL
111421 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
111422 +__mem_cgroup_try_charge_swapin_32204 __mem_cgroup_try_charge_swapin 0 32204 NULL
111423 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
111424 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
111425 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
111426 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
111427 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
111428 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
111429 +SyS_select_32319 SyS_select 1 32319 NULL
111430 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
111431 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
111432 +xfs_bmap_extsize_align_32338 xfs_bmap_extsize_align 0 32338 NULL
111433 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
111434 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
111435 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
111436 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
111437 +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
111438 +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
111439 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
111440 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
111441 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
111442 +xfs_alloc_put_freelist_32437 xfs_alloc_put_freelist 0 32437 NULL
111443 +cache_status_32462 cache_status 5 32462 NULL
111444 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
111445 +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
111446 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
111447 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
111448 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
111449 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
111450 +disconnect_32521 disconnect 4 32521 NULL
111451 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
111452 +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL
111453 +ilo_read_32531 ilo_read 3 32531 NULL
111454 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
111455 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
111456 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
111457 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
111458 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
111459 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
111460 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
111461 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
111462 +xfs_bmap_last_offset_32614 xfs_bmap_last_offset 0 32614 NULL
111463 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
111464 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
111465 +kvmalloc_32646 kvmalloc 1 32646 NULL
111466 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
111467 +generic_readlink_32654 generic_readlink 3 32654 NULL
111468 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
111469 +apei_res_add_32674 apei_res_add 0 32674 NULL
111470 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
111471 +xfs_filestream_new_ag_32711 xfs_filestream_new_ag 0 32711 NULL
111472 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
111473 +xfs_bmbt_update_32713 xfs_bmbt_update 0 32713 NULL
111474 +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
111475 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
111476 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
111477 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
111478 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
111479 +xfs_trans_read_buf_32795 xfs_trans_read_buf 0 32795 NULL
111480 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
111481 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
111482 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
111483 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
111484 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
111485 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
111486 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
111487 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
111488 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
111489 +xfs_log_reserve_32959 xfs_log_reserve 0 32959 NULL
111490 +compat_filldir_32999 compat_filldir 3 32999 NULL
111491 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
111492 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
111493 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
111494 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
111495 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
111496 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
111497 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
111498 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
111499 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
111500 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
111501 +alloc_tio_33077 alloc_tio 3 33077 NULL
111502 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
111503 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
111504 +notify_change_33143 notify_change 0 33143 NULL
111505 +SyS_poll_33152 SyS_poll 2 33152 NULL
111506 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
111507 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
111508 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
111509 +pp_read_33210 pp_read 3 33210 NULL
111510 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
111511 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
111512 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
111513 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
111514 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
111515 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
111516 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
111517 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
111518 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
111519 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
111520 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
111521 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
111522 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
111523 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
111524 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
111525 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
111526 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
111527 +filemap_fdatawrite_33415 filemap_fdatawrite 0 33415 NULL
111528 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
111529 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
111530 +message_stats_list_33440 message_stats_list 5 33440 NULL
111531 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
111532 +create_entry_33479 create_entry 2 33479 NULL
111533 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
111534 +res_counter_read_33499 res_counter_read 4 33499 NULL
111535 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
111536 +fb_read_33506 fb_read 3 33506 NULL
111537 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
111538 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
111539 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
111540 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
111541 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
111542 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
111543 +count_subheaders_33591 count_subheaders 0 33591 NULL
111544 +scsi_execute_33596 scsi_execute 5 33596 NULL
111545 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
111546 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
111547 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
111548 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
111549 +xfs_btree_check_sblock_33618 xfs_btree_check_sblock 0 33618 NULL
111550 +stride_page_count_33641 stride_page_count 2 33641 NULL
111551 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
111552 +inw_p_33668 inw_p 0 33668 NULL
111553 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
111554 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
111555 +submit_one_bio_33683 submit_one_bio 0 33683 NULL
111556 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
111557 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
111558 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
111559 +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
111560 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
111561 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
111562 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
111563 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
111564 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
111565 +hashtab_create_33769 hashtab_create 3 33769 NULL
111566 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
111567 +filter_write_33819 filter_write 3 33819 NULL
111568 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
111569 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
111570 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
111571 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
111572 +get_user_pages_33908 get_user_pages 0 33908 NULL
111573 +sg_nents_33909 sg_nents 0 33909 NULL
111574 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
111575 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
111576 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
111577 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
111578 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
111579 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
111580 +btrfs_delalloc_reserve_metadata_33963 btrfs_delalloc_reserve_metadata 0 33963 NULL
111581 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
111582 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
111583 +ppp_write_34034 ppp_write 3 34034 NULL
111584 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
111585 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
111586 +xfs_dialloc_34078 xfs_dialloc 0 34078 NULL
111587 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
111588 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
111589 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
111590 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
111591 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
111592 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
111593 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
111594 +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
111595 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
111596 +xfs_bmapi_write_34208 xfs_bmapi_write 0 34208 NULL
111597 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
111598 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
111599 +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
111600 +device_private_init_34279 device_private_init 0 34279 NULL
111601 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
111602 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
111603 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
111604 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
111605 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
111606 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
111607 +ea_read_34378 ea_read 0 34378 NULL
111608 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
111609 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
111610 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
111611 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
111612 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
111613 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
111614 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
111615 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
111616 +__extent_read_full_page_34437 __extent_read_full_page 0 34437 NULL
111617 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
111618 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
111619 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
111620 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
111621 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
111622 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
111623 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
111624 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
111625 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
111626 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
111627 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
111628 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
111629 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
111630 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
111631 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
111632 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
111633 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
111634 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
111635 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
111636 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
111637 +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
111638 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
111639 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
111640 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
111641 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
111642 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
111643 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
111644 +port_print_34704 port_print 3 34704 NULL
111645 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
111646 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
111647 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
111648 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
111649 +bootmode_store_34762 bootmode_store 4 34762 NULL
111650 +device_add_34766 device_add 0 34766 NULL
111651 +xfs_iget_cache_hit_34767 xfs_iget_cache_hit 0 34767 NULL
111652 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
111653 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
111654 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
111655 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
111656 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
111657 +file_page_index_34820 file_page_index 0-2 34820 NULL
111658 +bio_segments_34832 bio_segments 0 34832 NULL
111659 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
111660 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
111661 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
111662 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
111663 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
111664 +msg_print_text_34889 msg_print_text 0 34889 NULL
111665 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
111666 +gfs2_glock_wait_34913 gfs2_glock_wait 0 34913 NULL
111667 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
111668 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 NULL nohasharray
111669 +__inode_permission_34925 __inode_permission 0 34925 &btrfs_super_chunk_root_34925
111670 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
111671 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
111672 +i2c_transfer_34958 i2c_transfer 0 34958 NULL
111673 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
111674 +print_message_35000 print_message 0 35000 NULL
111675 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
111676 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
111677 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
111678 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
111679 +xfs_rtallocate_extent_35052 xfs_rtallocate_extent 0 35052 NULL
111680 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
111681 +ntfs_attr_extend_initialized_35084 ntfs_attr_extend_initialized 0 35084 NULL
111682 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
111683 +capi_write_35104 capi_write 3 35104 NULL nohasharray
111684 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
111685 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
111686 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
111687 +message_stats_print_35158 message_stats_print 6 35158 NULL
111688 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
111689 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
111690 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
111691 +striped_read_35218 striped_read 0-2 35218 NULL nohasharray
111692 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 &striped_read_35218
111693 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
111694 +set_fd_set_35249 set_fd_set 1 35249 NULL
111695 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
111696 +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
111697 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
111698 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
111699 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
111700 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
111701 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
111702 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3-0 35311 NULL nohasharray
111703 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
111704 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
111705 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
111706 +xfs_btree_check_lblock_35333 xfs_btree_check_lblock 0 35333 NULL
111707 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
111708 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
111709 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
111710 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
111711 +read_kmem_35372 read_kmem 3 35372 NULL
111712 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
111713 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
111714 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
111715 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
111716 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
111717 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
111718 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
111719 +async_setkey_35521 async_setkey 3 35521 NULL
111720 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
111721 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
111722 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
111723 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
111724 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
111725 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
111726 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
111727 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
111728 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
111729 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
111730 +kernel_readv_35617 kernel_readv 3 35617 NULL
111731 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
111732 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
111733 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
111734 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
111735 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
111736 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
111737 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
111738 +md_super_write_35703 md_super_write 4 35703 NULL
111739 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
111740 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
111741 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
111742 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
111743 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
111744 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
111745 +fls64_35862 fls64 0 35862 NULL
111746 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
111747 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
111748 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
111749 +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
111750 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
111751 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
111752 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
111753 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
111754 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
111755 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
111756 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
111757 +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
111758 +acl_alloc_35979 acl_alloc 1 35979 NULL
111759 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
111760 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
111761 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
111762 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
111763 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
111764 +account_shadowed_36048 account_shadowed 2 36048 NULL
111765 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
111766 +write_emulate_36065 write_emulate 2-4 36065 NULL
111767 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
111768 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
111769 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
111770 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
111771 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
111772 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
111773 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
111774 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
111775 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
111776 +twl_set_36154 twl_set 2 36154 NULL
111777 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
111778 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
111779 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
111780 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
111781 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
111782 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
111783 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
111784 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
111785 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
111786 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
111787 +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
111788 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
111789 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
111790 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
111791 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
111792 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
111793 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
111794 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
111795 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
111796 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
111797 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
111798 +lc_create_36332 lc_create 4 36332 NULL
111799 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
111800 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
111801 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
111802 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
111803 +to_sector_36361 to_sector 0-1 36361 NULL
111804 +tunables_read_36385 tunables_read 3 36385 NULL
111805 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
111806 +sierra_write_36402 sierra_write 4 36402 NULL
111807 +qdsb_get_36409 qdsb_get 0 36409 NULL
111808 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
111809 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
111810 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
111811 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
111812 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
111813 +lock_and_cleanup_extent_if_need_36480 lock_and_cleanup_extent_if_need 0 36480 NULL
111814 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
111815 +ip6_append_data_36490 ip6_append_data 4 36490 NULL nohasharray
111816 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
111817 +cmd_loop_36491 cmd_loop 0 36491 NULL
111818 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
111819 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
111820 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
111821 +get_param_l_36518 get_param_l 0 36518 NULL
111822 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
111823 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
111824 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
111825 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
111826 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
111827 +__erst_read_36579 __erst_read 0 36579 NULL
111828 +put_cmsg_36589 put_cmsg 4 36589 NULL
111829 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
111830 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
111831 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
111832 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
111833 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
111834 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
111835 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
111836 +xillybus_read_36678 xillybus_read 3 36678 NULL
111837 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
111838 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
111839 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
111840 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
111841 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
111842 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
111843 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
111844 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
111845 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
111846 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
111847 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
111848 +cm_write_36858 cm_write 3 36858 NULL
111849 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
111850 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
111851 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
111852 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
111853 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
111854 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
111855 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
111856 +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
111857 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
111858 +xfs_btree_check_sptr_36984 xfs_btree_check_sptr 0 36984 NULL
111859 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
111860 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
111861 +setxattr_37006 setxattr 4 37006 NULL
111862 +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
111863 +command_file_read_37038 command_file_read 3 37038 NULL
111864 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
111865 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
111866 +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
111867 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
111868 +parse_command_37079 parse_command 2 37079 NULL
111869 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
111870 +tun_get_user_37094 tun_get_user 5 37094 NULL
111871 +xlog_grant_head_check_37116 xlog_grant_head_check 0 37116 NULL
111872 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
111873 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
111874 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
111875 +msg_word_37164 msg_word 0 37164 NULL
111876 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
111877 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
111878 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
111879 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
111880 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
111881 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
111882 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
111883 +__do_replace_37227 __do_replace 5 37227 NULL
111884 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
111885 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
111886 +xfs_reclaim_inode_37257 xfs_reclaim_inode 0 37257 NULL
111887 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
111888 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
111889 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
111890 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
111891 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
111892 +send_msg_37323 send_msg 4 37323 NULL
111893 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
111894 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
111895 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
111896 +xfs_iomap_write_allocate_37336 xfs_iomap_write_allocate 0 37336 NULL
111897 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
111898 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
111899 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
111900 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
111901 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
111902 +fru_alloc_37442 fru_alloc 1 37442 NULL
111903 +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
111904 +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
111905 +xfs_btree_dec_cursor_37452 xfs_btree_dec_cursor 0 37452 NULL
111906 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
111907 +get_est_timing_37484 get_est_timing 0 37484 NULL
111908 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
111909 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
111910 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
111911 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
111912 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
111913 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
111914 +hdr_size_37536 hdr_size 0 37536 NULL
111915 +extent_map_end_37550 extent_map_end 0 37550 NULL
111916 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
111917 +fat_cont_expand_37552 fat_cont_expand 0 37552 NULL
111918 +ioat_chansts_37558 ioat_chansts 0 37558 NULL
111919 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
111920 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
111921 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
111922 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
111923 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
111924 +may_delete_37656 may_delete 0 37656 NULL
111925 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
111926 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
111927 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
111928 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
111929 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
111930 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
111931 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
111932 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
111933 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
111934 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
111935 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
111936 +xfs_read_agf_37749 xfs_read_agf 0 37749 NULL
111937 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
111938 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
111939 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
111940 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
111941 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
111942 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
111943 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
111944 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
111945 +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
111946 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
111947 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
111948 +set_registers_37883 set_registers 4 37883 NULL
111949 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
111950 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
111951 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
111952 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
111953 +write_file_bool_37957 write_file_bool 3 37957 NULL
111954 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
111955 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
111956 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
111957 +vfs_readv_38011 vfs_readv 3 38011 NULL
111958 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
111959 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
111960 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
111961 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
111962 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
111963 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
111964 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
111965 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
111966 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
111967 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
111968 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
111969 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
111970 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
111971 +ep0_read_38095 ep0_read 3 38095 NULL
111972 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
111973 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
111974 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
111975 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
111976 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
111977 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
111978 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
111979 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
111980 +cdev_add_38176 cdev_add 2-3 38176 NULL
111981 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
111982 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
111983 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL nohasharray
111984 +xfs_rtallocate_range_38223 xfs_rtallocate_range 0 38223 &osd_req_list_partition_collections_38223
111985 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
111986 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
111987 +xfs_qm_dqrepair_38262 xfs_qm_dqrepair 0 38262 NULL
111988 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
111989 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
111990 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
111991 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
111992 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
111993 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
111994 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
111995 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
111996 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
111997 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
111998 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
111999 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
112000 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
112001 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
112002 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
112003 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
112004 +dev_names_read_38509 dev_names_read 3 38509 NULL
112005 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
112006 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
112007 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
112008 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
112009 +kuc_len_38557 kuc_len 0-1 38557 NULL
112010 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
112011 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
112012 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
112013 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
112014 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
112015 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
112016 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
112017 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
112018 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
112019 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
112020 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
112021 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
112022 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
112023 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
112024 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
112025 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
112026 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
112027 +udf_readpages_38761 udf_readpages 4 38761 NULL
112028 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
112029 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
112030 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
112031 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
112032 +err_decode_38804 err_decode 2 38804 NULL
112033 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
112034 +direct_entry_38836 direct_entry 3 38836 NULL
112035 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
112036 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
112037 +interfaces_38859 interfaces 2 38859 NULL
112038 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
112039 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
112040 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
112041 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
112042 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
112043 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
112044 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
112045 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
112046 +get_nodes_39012 get_nodes 3 39012 NULL
112047 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
112048 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
112049 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
112050 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
112051 +ReadHFC_39104 ReadHFC 0 39104 NULL
112052 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
112053 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
112054 +ea_foreach_39133 ea_foreach 0 39133 NULL
112055 +generic_permission_39150 generic_permission 0 39150 NULL
112056 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
112057 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
112058 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
112059 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
112060 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
112061 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
112062 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
112063 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
112064 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 NULL nohasharray
112065 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 &pwr_cont_miss_bcns_spread_read_39250
112066 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
112067 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
112068 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
112069 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
112070 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
112071 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
112072 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
112073 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
112074 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
112075 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
112076 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
112077 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
112078 +__send_to_port_39386 __send_to_port 3 39386 NULL
112079 +xfs_btree_dup_cursor_39394 xfs_btree_dup_cursor 0 39394 NULL
112080 +gfs2_internal_read_39413 gfs2_internal_read 0 39413 NULL
112081 +user_power_read_39414 user_power_read 3 39414 NULL
112082 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
112083 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
112084 +apei_resources_add_39470 apei_resources_add 0 39470 NULL
112085 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
112086 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
112087 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
112088 +int_proc_write_39542 int_proc_write 3 39542 NULL
112089 +pp_write_39554 pp_write 3 39554 NULL
112090 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
112091 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
112092 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
112093 +ext_depth_39607 ext_depth 0 39607 NULL
112094 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
112095 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
112096 +sdio_readb_39618 sdio_readb 0 39618 NULL
112097 +prepare_uptodate_page_39622 prepare_uptodate_page 0 39622 NULL
112098 +set_dev_class_39645 set_dev_class 4 39645 NULL
112099 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
112100 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
112101 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
112102 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
112103 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
112104 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
112105 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
112106 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
112107 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
112108 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
112109 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
112110 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
112111 +pkt_add_39897 pkt_add 3 39897 NULL
112112 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
112113 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
112114 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
112115 +__mnt_want_write_file_39917 __mnt_want_write_file 0 39917 NULL
112116 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
112117 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
112118 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
112119 +__spi_async_39932 __spi_async 0 39932 NULL
112120 +__get_order_39935 __get_order 0 39935 NULL
112121 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
112122 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
112123 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
112124 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
112125 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
112126 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
112127 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
112128 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
112129 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
112130 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
112131 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
112132 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
112133 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
112134 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
112135 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
112136 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
112137 +xfs_rtbuf_get_40107 xfs_rtbuf_get 0 40107 NULL
112138 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
112139 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
112140 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
112141 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
112142 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
112143 +pt_write_40159 pt_write 3 40159 NULL
112144 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
112145 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
112146 +allocate_probes_40204 allocate_probes 1 40204 NULL
112147 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
112148 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
112149 +osst_read_40237 osst_read 3 40237 NULL
112150 +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
112151 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
112152 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
112153 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
112154 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
112155 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
112156 +SyS_bind_40303 SyS_bind 3 40303 NULL
112157 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
112158 +mmio_read_40348 mmio_read 4 40348 NULL
112159 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
112160 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
112161 +get_chars_40373 get_chars 3 40373 NULL
112162 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
112163 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
112164 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
112165 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
112166 +SyS_writev_40467 SyS_writev 3 40467 NULL
112167 +SyS_select_40473 SyS_select 1 40473 NULL
112168 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
112169 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
112170 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
112171 +xfs_iread_extents_40510 xfs_iread_extents 0 40510 NULL
112172 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
112173 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
112174 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
112175 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
112176 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
112177 +b1_get_byte_40597 b1_get_byte 0 40597 NULL
112178 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
112179 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
112180 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
112181 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
112182 +fops_read_40672 fops_read 3 40672 NULL
112183 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
112184 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
112185 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
112186 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
112187 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
112188 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
112189 +set_extent_bit_40719 set_extent_bit 0 40719 NULL
112190 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
112191 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
112192 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
112193 +card_send_command_40757 card_send_command 3 40757 NULL
112194 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
112195 +pg_write_40766 pg_write 3 40766 NULL
112196 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
112197 +show_list_40775 show_list 3-0 40775 NULL
112198 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
112199 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
112200 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
112201 +add_action_40811 add_action 4 40811 NULL
112202 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
112203 +SyS_mbind_40828 SyS_mbind 5 40828 NULL
112204 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
112205 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
112206 +read_file_queue_40895 read_file_queue 3 40895 NULL
112207 +waiters_read_40902 waiters_read 3 40902 NULL
112208 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
112209 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
112210 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
112211 +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
112212 +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
112213 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
112214 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
112215 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
112216 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
112217 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
112218 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
112219 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
112220 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
112221 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
112222 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
112223 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
112224 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
112225 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
112226 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
112227 +dma_attach_41094 dma_attach 5-6 41094 NULL
112228 +provide_user_output_41105 provide_user_output 3 41105 NULL
112229 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
112230 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
112231 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
112232 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
112233 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
112234 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
112235 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
112236 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
112237 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
112238 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
112239 +erst_read_41260 erst_read 0 41260 NULL
112240 +alloc_context_41283 alloc_context 1 41283 NULL
112241 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
112242 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
112243 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
112244 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
112245 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
112246 +kmp_init_41373 kmp_init 2 41373 NULL
112247 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
112248 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
112249 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
112250 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
112251 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
112252 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
112253 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4-0 41442 NULL
112254 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
112255 +se_io_cb_41461 se_io_cb 3 41461 NULL
112256 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
112257 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
112258 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
112259 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
112260 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
112261 +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
112262 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
112263 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
112264 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
112265 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
112266 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
112267 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
112268 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
112269 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
112270 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
112271 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
112272 +vga_io_r_41609 vga_io_r 0 41609 NULL
112273 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
112274 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
112275 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
112276 +a2mp_send_41615 a2mp_send 4 41615 NULL
112277 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
112278 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
112279 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
112280 +get_std_timing_41654 get_std_timing 0 41654 NULL
112281 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
112282 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
112283 +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
112284 +fillonedir_41746 fillonedir 3 41746 NULL
112285 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
112286 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
112287 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
112288 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
112289 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
112290 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
112291 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
112292 +xfs_rtget_summary_41864 xfs_rtget_summary 0 41864 NULL
112293 +pci_map_single_41869 pci_map_single 0 41869 NULL
112294 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
112295 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
112296 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
112297 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
112298 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
112299 +read_gssp_41947 read_gssp 3 41947 NULL
112300 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
112301 +portnames_read_41958 portnames_read 3 41958 NULL
112302 +dst_mtu_41969 dst_mtu 0 41969 NULL
112303 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
112304 +xfs_qm_dqalloc_41985 xfs_qm_dqalloc 0 41985 NULL
112305 +pool_allocate_42012 pool_allocate 3 42012 NULL
112306 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
112307 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
112308 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
112309 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
112310 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
112311 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
112312 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
112313 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
112314 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
112315 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
112316 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
112317 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
112318 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
112319 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
112320 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
112321 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
112322 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
112323 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
112324 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
112325 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
112326 +xfs_rtfree_range_42244 xfs_rtfree_range 0 42244 NULL
112327 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
112328 +find_last_bit_42260 find_last_bit 0 42260 NULL
112329 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
112330 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
112331 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
112332 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
112333 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
112334 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
112335 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
112336 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
112337 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
112338 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
112339 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
112340 +tipc_send_42374 tipc_send 3 42374 NULL
112341 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
112342 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
112343 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
112344 +krng_get_random_42420 krng_get_random 3 42420 NULL
112345 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
112346 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
112347 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
112348 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
112349 +kuc_free_42455 kuc_free 2 42455 NULL
112350 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
112351 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
112352 +bypass_write_42498 bypass_write 3 42498 NULL
112353 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
112354 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
112355 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
112356 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
112357 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
112358 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
112359 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
112360 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
112361 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
112362 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
112363 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
112364 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
112365 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
112366 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
112367 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
112368 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
112369 +vb2_read_42703 vb2_read 3 42703 NULL
112370 +read_status_42722 read_status 0 42722 NULL
112371 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
112372 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
112373 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
112374 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
112375 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
112376 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
112377 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
112378 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
112379 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
112380 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
112381 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
112382 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
112383 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
112384 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
112385 +set_arg_42824 set_arg 3 42824 NULL
112386 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
112387 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
112388 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
112389 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
112390 +hd_end_request_42904 hd_end_request 2 42904 NULL
112391 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
112392 +xfs_bmapi_allocate_42938 xfs_bmapi_allocate 0 42938 NULL
112393 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
112394 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
112395 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
112396 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
112397 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
112398 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
112399 +xfs_da_read_buf_43008 xfs_da_read_buf 0 43008 NULL
112400 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
112401 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
112402 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
112403 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
112404 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
112405 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
112406 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
112407 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
112408 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
112409 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
112410 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
112411 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
112412 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
112413 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
112414 +uio_write_43202 uio_write 3 43202 NULL
112415 +iso_callback_43208 iso_callback 3 43208 NULL
112416 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
112417 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
112418 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
112419 +inode_init_always_43225 inode_init_always 0 43225 NULL
112420 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
112421 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
112422 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
112423 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
112424 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
112425 +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
112426 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
112427 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
112428 +mmu_set_spte_43327 mmu_set_spte 6-7 43327 NULL
112429 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
112430 +xfs_log_regrant_43350 xfs_log_regrant 0 43350 NULL
112431 +gfs2_rgrp_bh_get_43375 gfs2_rgrp_bh_get 0 43375 NULL
112432 +xfs_btree_new_iroot_43392 xfs_btree_new_iroot 0 43392 NULL
112433 +xenfb_write_43412 xenfb_write 3 43412 NULL
112434 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
112435 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
112436 +cifs_writev_43437 cifs_writev 4 43437 NULL
112437 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
112438 +usb_string_43443 usb_string 0 43443 NULL nohasharray
112439 +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
112440 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
112441 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
112442 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
112443 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
112444 +do_readlink_43518 do_readlink 2 43518 NULL
112445 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
112446 +read_events_43534 read_events 3 43534 NULL
112447 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
112448 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
112449 +request_resource_43548 request_resource 0 43548 NULL
112450 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
112451 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
112452 +proc_read_43614 proc_read 3 43614 NULL
112453 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
112454 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
112455 +random_write_43656 random_write 3 43656 NULL
112456 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
112457 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
112458 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
112459 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
112460 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
112461 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
112462 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
112463 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
112464 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
112465 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
112466 +xfs_alloc_lookup_eq_43775 xfs_alloc_lookup_eq 0 43775 NULL
112467 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
112468 +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
112469 +xfs_trans_reserve_quota_bydquots_43797 xfs_trans_reserve_quota_bydquots 0 43797 NULL
112470 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
112471 +_xfs_filestream_update_ag_43824 _xfs_filestream_update_ag 0 43824 NULL
112472 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
112473 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
112474 +read_flush_43851 read_flush 3 43851 NULL
112475 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
112476 +SendString_43928 SendString 3 43928 NULL
112477 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
112478 +xfs_trans_dqresv_43960 xfs_trans_dqresv 0 43960 NULL
112479 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
112480 +nla_reserve_43984 nla_reserve 3 43984 NULL
112481 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
112482 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
112483 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
112484 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
112485 +ulist_add_43994 ulist_add 0 43994 NULL
112486 +emit_flags_44006 emit_flags 4-3 44006 NULL
112487 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
112488 +fru_strlen_44046 fru_strlen 0 44046 NULL
112489 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
112490 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
112491 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL nohasharray
112492 +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 &pci_msix_vec_count_44093
112493 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
112494 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
112495 +file_remove_suid_44122 file_remove_suid 0 44122 NULL nohasharray
112496 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 &file_remove_suid_44122
112497 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
112498 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
112499 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
112500 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
112501 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
112502 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
112503 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
112504 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
112505 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
112506 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
112507 +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
112508 +device_create_file_44285 device_create_file 0 44285 NULL
112509 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
112510 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
112511 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
112512 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
112513 +rs_init_44327 rs_init 1 44327 NULL
112514 +radix_tree_maybe_preload_44346 radix_tree_maybe_preload 0 44346 NULL
112515 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
112516 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
112517 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
112518 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
112519 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
112520 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
112521 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
112522 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
112523 +xfs_mod_incore_sb_44439 xfs_mod_incore_sb 0 44439 NULL
112524 +write_file_debug_44476 write_file_debug 3 44476 NULL
112525 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
112526 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
112527 +bio_advance_44496 bio_advance 2 44496 NULL
112528 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
112529 +ac_register_board_44504 ac_register_board 3 44504 NULL
112530 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
112531 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
112532 +spidev_write_44510 spidev_write 3 44510 NULL
112533 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
112534 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
112535 +comm_write_44537 comm_write 3 44537 NULL
112536 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
112537 +btrfs_set_extent_delalloc_44587 btrfs_set_extent_delalloc 0 44587 NULL
112538 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
112539 +xfs_bmapi_delay_44630 xfs_bmapi_delay 0 44630 NULL
112540 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
112541 +mpi_resize_44674 mpi_resize 2 44674 NULL
112542 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
112543 +ts_read_44687 ts_read 3 44687 NULL
112544 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
112545 +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
112546 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
112547 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
112548 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
112549 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
112550 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
112551 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
112552 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
112553 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
112554 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
112555 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
112556 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
112557 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
112558 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
112559 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
112560 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
112561 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
112562 +sisusb_write_44834 sisusb_write 3 44834 NULL
112563 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
112564 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
112565 +copydesc_user_44855 copydesc_user 3 44855 NULL
112566 +set_advertising_44870 set_advertising 4 44870 NULL
112567 +init_rs_44873 init_rs 1 44873 NULL
112568 +skb_availroom_44883 skb_availroom 0 44883 NULL
112569 +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
112570 +do_tty_write_44896 do_tty_write 5 44896 NULL
112571 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
112572 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
112573 +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
112574 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
112575 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
112576 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
112577 +sel_write_user_45060 sel_write_user 3 45060 NULL
112578 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
112579 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
112580 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
112581 +usbdev_read_45114 usbdev_read 3 45114 NULL
112582 +send_to_tty_45141 send_to_tty 3 45141 NULL
112583 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
112584 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
112585 +device_write_45156 device_write 3 45156 NULL nohasharray
112586 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
112587 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
112588 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
112589 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
112590 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
112591 +__radix_tree_preload_45197 __radix_tree_preload 0 45197 NULL
112592 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
112593 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
112594 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
112595 +event_enable_write_45238 event_enable_write 3 45238 NULL
112596 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
112597 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
112598 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
112599 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
112600 +xfs_alert_fsblock_zero_45304 xfs_alert_fsblock_zero 0 45304 NULL
112601 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
112602 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
112603 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
112604 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
112605 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
112606 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
112607 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
112608 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
112609 +__node_remap_45458 __node_remap 4 45458 NULL
112610 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
112611 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
112612 +__calc_request_pg_45470 __calc_request_pg 0 45470 NULL
112613 +xfs_btree_block_change_owner_45476 xfs_btree_block_change_owner 0 45476 NULL
112614 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
112615 +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
112616 +copy_macs_45534 copy_macs 4 45534 NULL
112617 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
112618 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
112619 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
112620 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
112621 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
112622 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
112623 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
112624 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
112625 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
112626 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
112627 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
112628 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
112629 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
112630 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
112631 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
112632 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
112633 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
112634 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
112635 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
112636 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
112637 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
112638 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
112639 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
112640 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
112641 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
112642 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
112643 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
112644 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
112645 +insert_state_45848 insert_state 0 45848 NULL
112646 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
112647 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
112648 +isdn_write_45863 isdn_write 3 45863 NULL
112649 +tpm_config_in_45880 tpm_config_in 0 45880 NULL
112650 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
112651 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
112652 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
112653 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
112654 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
112655 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
112656 +alloc_mr_45935 alloc_mr 1 45935 NULL
112657 +copy_to_45969 copy_to 3 45969 NULL
112658 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
112659 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
112660 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
112661 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
112662 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
112663 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
112664 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
112665 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
112666 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
112667 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
112668 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
112669 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
112670 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
112671 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
112672 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
112673 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
112674 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
112675 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
112676 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
112677 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
112678 +fq_resize_46195 fq_resize 2 46195 NULL
112679 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
112680 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
112681 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
112682 +dsp_write_46218 dsp_write 2 46218 NULL
112683 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
112684 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
112685 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
112686 +ReadReg_46277 ReadReg 0 46277 NULL
112687 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
112688 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
112689 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
112690 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
112691 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
112692 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
112693 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
112694 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
112695 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
112696 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
112697 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
112698 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
112699 +filldir64_46469 filldir64 3 46469 NULL
112700 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
112701 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
112702 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
112703 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
112704 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
112705 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
112706 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
112707 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
112708 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
112709 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
112710 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
112711 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
112712 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
112713 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
112714 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
112715 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
112716 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
112717 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
112718 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
112719 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
112720 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
112721 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
112722 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
112723 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
112724 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
112725 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
112726 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
112727 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
112728 +readreg_46845 readreg 0 46845 NULL
112729 +spi_async_46857 spi_async 0 46857 NULL
112730 +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
112731 +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
112732 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
112733 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
112734 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
112735 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
112736 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
112737 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
112738 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
112739 +fb_write_46924 fb_write 3 46924 NULL
112740 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
112741 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL nohasharray
112742 +ntfs_truncate_46953 ntfs_truncate 0 46953 &qla4xxx_post_aen_work_46953
112743 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
112744 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
112745 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
112746 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
112747 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
112748 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
112749 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
112750 +fs_path_len_47060 fs_path_len 0 47060 NULL
112751 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
112752 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
112753 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
112754 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
112755 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
112756 +mousedev_read_47123 mousedev_read 3 47123 NULL
112757 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
112758 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
112759 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
112760 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
112761 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
112762 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
112763 +xfs_btree_get_buf_block_47197 xfs_btree_get_buf_block 0 47197 NULL
112764 +options_write_47243 options_write 3 47243 NULL
112765 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
112766 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
112767 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
112768 +vsnprintf_47291 vsnprintf 0 47291 NULL
112769 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
112770 +xfs_trans_reserve_quota_nblks_47313 xfs_trans_reserve_quota_nblks 0 47313 NULL
112771 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
112772 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
112773 +gfs2_replay_read_block_47357 gfs2_replay_read_block 0 47357 NULL
112774 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
112775 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
112776 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
112777 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
112778 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
112779 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
112780 +nametbl_list_47391 nametbl_list 2 47391 NULL
112781 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
112782 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
112783 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
112784 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
112785 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
112786 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
112787 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
112788 +newpart_47485 newpart 6-4 47485 NULL
112789 +core_sys_select_47494 core_sys_select 1 47494 NULL
112790 +unlink_simple_47506 unlink_simple 3 47506 NULL
112791 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
112792 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
112793 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
112794 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
112795 +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
112796 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
112797 +read_ldt_47570 read_ldt 2 47570 NULL
112798 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
112799 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
112800 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
112801 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
112802 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
112803 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
112804 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
112805 +get_size_47644 get_size 1-2 47644 NULL
112806 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
112807 +save_microcode_47717 save_microcode 3 47717 NULL
112808 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
112809 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
112810 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
112811 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
112812 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
112813 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
112814 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
112815 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
112816 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
112817 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
112818 +lov_packmd_47810 lov_packmd 0 47810 NULL
112819 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
112820 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
112821 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
112822 +vhci_read_47878 vhci_read 3 47878 NULL
112823 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
112824 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
112825 +comedi_write_47926 comedi_write 3 47926 NULL
112826 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
112827 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
112828 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
112829 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
112830 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
112831 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
112832 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
112833 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
112834 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
112835 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
112836 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
112837 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
112838 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
112839 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
112840 +disc_write_48070 disc_write 3 48070 NULL
112841 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
112842 +xfs_read_agi_48100 xfs_read_agi 0 48100 NULL
112843 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
112844 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
112845 +set_discoverable_48141 set_discoverable 4 48141 NULL
112846 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
112847 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
112848 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
112849 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
112850 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
112851 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
112852 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
112853 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
112854 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
112855 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
112856 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
112857 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
112858 +read_file_recv_48232 read_file_recv 3 48232 NULL
112859 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
112860 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
112861 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
112862 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
112863 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
112864 +trace_options_write_48275 trace_options_write 3 48275 NULL
112865 +send_set_info_48288 send_set_info 7 48288 NULL
112866 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
112867 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
112868 +hash_setkey_48310 hash_setkey 3 48310 NULL
112869 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
112870 +skb_add_data_48363 skb_add_data 3 48363 NULL
112871 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
112872 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
112873 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
112874 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
112875 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
112876 +print_filtered_48442 print_filtered 2-0 48442 NULL
112877 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
112878 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
112879 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
112880 +send_control_msg_48498 send_control_msg 6 48498 NULL
112881 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
112882 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
112883 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
112884 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
112885 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
112886 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
112887 +llog_data_len_48607 llog_data_len 1 48607 NULL
112888 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
112889 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
112890 +mtd_read_48655 mtd_read 0 48655 NULL
112891 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
112892 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
112893 +security_inode_setattr_48689 security_inode_setattr 0 48689 NULL
112894 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
112895 +altera_drscan_48698 altera_drscan 2 48698 NULL
112896 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
112897 +recv_msg_48709 recv_msg 4 48709 NULL
112898 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
112899 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
112900 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
112901 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
112902 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
112903 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
112904 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
112905 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
112906 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
112907 +azx_get_position_48841 azx_get_position 0 48841 NULL
112908 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
112909 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
112910 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
112911 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
112912 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
112913 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
112914 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
112915 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
112916 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
112917 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
112918 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
112919 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
112920 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
112921 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
112922 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
112923 +xfs_trans_commit_48982 xfs_trans_commit 0 48982 NULL
112924 +gfs2_dir_add_48987 gfs2_dir_add 0 48987 NULL
112925 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
112926 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
112927 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
112928 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
112929 +transient_status_49027 transient_status 4 49027 NULL
112930 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
112931 +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
112932 +scsi_register_49094 scsi_register 2 49094 NULL
112933 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
112934 +gfs2_diradd_alloc_required_49105 gfs2_diradd_alloc_required 0 49105 NULL
112935 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
112936 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
112937 +pt_read_49136 pt_read 3 49136 NULL
112938 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
112939 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
112940 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
112941 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
112942 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
112943 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
112944 +print_queue_49191 print_queue 4-0 49191 NULL
112945 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
112946 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
112947 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
112948 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
112949 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
112950 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
112951 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
112952 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
112953 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
112954 +uio_read_49300 uio_read 3 49300 NULL
112955 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
112956 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
112957 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
112958 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
112959 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
112960 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
112961 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
112962 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
112963 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
112964 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
112965 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
112966 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
112967 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
112968 +xfs_iformat_local_49472 xfs_iformat_local 4-0 49472 NULL
112969 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
112970 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
112971 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
112972 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
112973 +smk_write_access_49561 smk_write_access 3 49561 NULL
112974 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
112975 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
112976 +readfifo_49583 readfifo 1 49583 NULL
112977 +gfs2_quota_lock_49587 gfs2_quota_lock 0 49587 NULL
112978 +evm_inode_setattr_49594 evm_inode_setattr 0 49594 NULL
112979 +tap_write_49595 tap_write 3 49595 NULL
112980 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
112981 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
112982 +heap_init_49617 heap_init 2 49617 NULL
112983 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
112984 +port_fops_read_49626 port_fops_read 3 49626 NULL
112985 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
112986 +xfs_ialloc_get_rec_49648 xfs_ialloc_get_rec 0 49648 NULL
112987 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
112988 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
112989 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
112990 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
112991 +write_pool_49718 write_pool 3 49718 NULL
112992 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
112993 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
112994 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
112995 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
112996 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
112997 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
112998 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
112999 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
113000 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
113001 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
113002 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
113003 +add_uuid_49831 add_uuid 4 49831 NULL
113004 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
113005 +twl4030_write_49846 twl4030_write 2 49846 NULL
113006 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
113007 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
113008 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
113009 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
113010 +osc_brw_49896 osc_brw 4 49896 NULL
113011 +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
113012 +xfs_ialloc_ag_alloc_49960 xfs_ialloc_ag_alloc 0 49960 NULL
113013 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
113014 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
113015 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
113016 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
113017 +xfs_ialloc_inode_init_50015 xfs_ialloc_inode_init 0 50015 NULL
113018 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
113019 +isdn_read_50021 isdn_read 3 50021 NULL
113020 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
113021 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
113022 +ioread8_50049 ioread8 0 50049 NULL
113023 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
113024 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
113025 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
113026 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
113027 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
113028 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
113029 +read_file_slot_50111 read_file_slot 3 50111 NULL
113030 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
113031 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
113032 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
113033 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
113034 +xfs_bwrite_50154 xfs_bwrite 0 50154 NULL
113035 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
113036 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
113037 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
113038 +odev_update_50169 odev_update 2 50169 NULL
113039 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
113040 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
113041 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
113042 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
113043 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
113044 +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
113045 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
113046 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
113047 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
113048 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
113049 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
113050 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
113051 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
113052 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
113053 +do_launder_page_50329 do_launder_page 0 50329 NULL
113054 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
113055 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
113056 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
113057 +tpm_read_50344 tpm_read 3 50344 NULL
113058 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
113059 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
113060 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
113061 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
113062 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
113063 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
113064 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
113065 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
113066 +xfs_alloc_update_counters_50441 xfs_alloc_update_counters 0 50441 NULL
113067 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
113068 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
113069 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
113070 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
113071 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
113072 +xfs_iformat_extents_50486 xfs_iformat_extents 0 50486 NULL
113073 +gfs2_block_map_50492 gfs2_block_map 0 50492 NULL
113074 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
113075 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
113076 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
113077 +bh_get_50543 bh_get 0 50543 NULL
113078 +gfs2_meta_inode_buffer_50544 gfs2_meta_inode_buffer 0 50544 NULL
113079 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
113080 +fat_readpages_50582 fat_readpages 4 50582 NULL
113081 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
113082 +xillybus_write_50605 xillybus_write 3 50605 NULL
113083 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
113084 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
113085 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
113086 +gfs2_unstuff_dinode_50644 gfs2_unstuff_dinode 0 50644 NULL
113087 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
113088 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
113089 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
113090 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
113091 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
113092 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
113093 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
113094 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
113095 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
113096 +bio_alloc_map_data_50782 bio_alloc_map_data 2 50782 NULL
113097 +tpm_write_50798 tpm_write 3 50798 NULL
113098 +tun_do_read_50800 tun_do_read 4 50800 NULL
113099 +write_flush_50803 write_flush 3 50803 NULL
113100 +dvb_play_50814 dvb_play 3 50814 NULL
113101 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
113102 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
113103 +SetArea_50835 SetArea 4 50835 NULL
113104 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
113105 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
113106 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
113107 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
113108 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
113109 +xfs_alloc_get_freelist_50906 xfs_alloc_get_freelist 0 50906 NULL
113110 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
113111 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
113112 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
113113 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
113114 +show_device_status_50947 show_device_status 0 50947 NULL
113115 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
113116 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
113117 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
113118 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
113119 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
113120 +timeout_write_50991 timeout_write 3 50991 NULL
113121 +proc_write_51003 proc_write 3 51003 NULL
113122 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
113123 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
113124 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
113125 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
113126 +dump_midi_51040 dump_midi 3 51040 NULL
113127 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
113128 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
113129 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
113130 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
113131 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
113132 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
113133 +ti_recv_51110 ti_recv 3 51110 NULL
113134 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
113135 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
113136 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
113137 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
113138 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
113139 +drm_property_create_51239 drm_property_create 4 51239 NULL
113140 +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
113141 +st_read_51251 st_read 3 51251 NULL
113142 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
113143 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
113144 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
113145 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
113146 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
113147 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
113148 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
113149 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
113150 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
113151 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
113152 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
113153 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
113154 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
113155 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
113156 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
113157 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
113158 +xfs_mod_incore_sb_unlocked_51439 xfs_mod_incore_sb_unlocked 0 51439 NULL
113159 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
113160 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
113161 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
113162 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
113163 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
113164 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
113165 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
113166 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
113167 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
113168 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
113169 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
113170 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
113171 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
113172 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
113173 +xfs_iformat_btree_51651 xfs_iformat_btree 0 51651 NULL
113174 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
113175 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
113176 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
113177 +sel_write_access_51704 sel_write_access 3 51704 NULL
113178 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
113179 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
113180 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
113181 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
113182 +cm4040_read_51732 cm4040_read 3 51732 NULL
113183 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
113184 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
113185 +if_write_51756 if_write 3 51756 NULL
113186 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
113187 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
113188 +ioread32_51847 ioread32 0 51847 NULL nohasharray
113189 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
113190 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
113191 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
113192 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
113193 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
113194 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
113195 +user_read_51881 user_read 3 51881 NULL
113196 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
113197 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
113198 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
113199 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
113200 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
113201 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
113202 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
113203 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
113204 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
113205 +get_zone_51981 get_zone 0-1 51981 NULL
113206 +cifs_strict_writev_51984 cifs_strict_writev 4 51984 NULL
113207 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
113208 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
113209 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
113210 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
113211 +rdmalt_52022 rdmalt 0 52022 NULL
113212 +override_release_52032 override_release 2 52032 NULL
113213 +end_port_52042 end_port 0 52042 NULL
113214 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
113215 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
113216 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
113217 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
113218 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
113219 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
113220 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
113221 +ulist_add_merge_52096 ulist_add_merge 0 52096 NULL
113222 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
113223 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
113224 +retry_count_read_52129 retry_count_read 3 52129 NULL
113225 +xfs_btree_change_owner_52137 xfs_btree_change_owner 0 52137 NULL
113226 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
113227 +sub_alloc_52140 sub_alloc 0 52140 NULL
113228 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
113229 +htable_size_52148 htable_size 0-1 52148 NULL
113230 +gfs2_rs_alloc_52152 gfs2_rs_alloc 0 52152 NULL
113231 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
113232 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
113233 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
113234 +print_prefix_52176 print_prefix 0 52176 NULL
113235 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
113236 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
113237 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
113238 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
113239 +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 0 52243 &fuse_request_alloc_52243
113240 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
113241 +shrink_slab_52261 shrink_slab 2 52261 NULL
113242 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
113243 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
113244 +read_file_reset_52310 read_file_reset 3 52310 NULL
113245 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
113246 +hwflags_read_52318 hwflags_read 3 52318 NULL
113247 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
113248 +hur_len_52339 hur_len 0 52339 NULL
113249 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL nohasharray
113250 +cap_inode_killpriv_52362 cap_inode_killpriv 0 52362 &bytes_to_frames_52362
113251 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
113252 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
113253 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
113254 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
113255 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
113256 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
113257 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
113258 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
113259 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
113260 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
113261 +delay_status_52431 delay_status 5 52431 NULL
113262 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
113263 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
113264 +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
113265 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
113266 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
113267 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
113268 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
113269 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
113270 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
113271 +xfs_alloc_get_rec_52502 xfs_alloc_get_rec 0 52502 NULL
113272 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
113273 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
113274 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
113275 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
113276 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
113277 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
113278 +ntfs_prepare_pages_for_non_resident_write_52556 ntfs_prepare_pages_for_non_resident_write 0 52556 NULL
113279 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
113280 +kernfs_setattr_52583 kernfs_setattr 0 52583 NULL
113281 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
113282 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
113283 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
113284 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
113285 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
113286 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
113287 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
113288 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
113289 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
113290 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
113291 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
113292 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
113293 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
113294 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
113295 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
113296 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
113297 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
113298 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
113299 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
113300 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
113301 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
113302 +twlreg_write_52880 twlreg_write 3 52880 NULL
113303 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
113304 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
113305 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
113306 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
113307 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
113308 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
113309 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
113310 +send_packet_52960 send_packet 4 52960 NULL
113311 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
113312 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
113313 +num_node_state_52989 num_node_state 0 52989 NULL
113314 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
113315 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
113316 +xfs_rtfree_extent_53024 xfs_rtfree_extent 0 53024 NULL
113317 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
113318 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
113319 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
113320 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
113321 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
113322 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
113323 +verity_status_53120 verity_status 5 53120 NULL
113324 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
113325 +inode_newsize_ok_53140 inode_newsize_ok 0 53140 NULL nohasharray
113326 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 &inode_newsize_ok_53140
113327 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
113328 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
113329 +find_good_lh_53183 find_good_lh 0 53183 NULL
113330 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
113331 +xfs_btree_updkey_53195 xfs_btree_updkey 0 53195 NULL
113332 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
113333 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
113334 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5-0 53258 NULL
113335 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
113336 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
113337 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
113338 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
113339 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
113340 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
113341 +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
113342 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
113343 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
113344 +xfs_imap_53389 xfs_imap 0 53389 NULL
113345 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
113346 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
113347 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
113348 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
113349 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
113350 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
113351 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
113352 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
113353 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
113354 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
113355 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
113356 +check_acl_53512 check_acl 0 53512 NULL
113357 +ll_xattr_cache_update_53515 ll_xattr_cache_update 4 53515 NULL
113358 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
113359 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
113360 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
113361 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
113362 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
113363 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
113364 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
113365 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
113366 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
113367 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
113368 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
113369 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
113370 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
113371 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
113372 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
113373 +wdm_write_53735 wdm_write 3 53735 NULL
113374 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
113375 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
113376 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
113377 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
113378 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
113379 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
113380 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
113381 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
113382 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
113383 +setup_data_read_53822 setup_data_read 3 53822 NULL
113384 +pms_read_53873 pms_read 3 53873 NULL
113385 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
113386 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
113387 +posix_acl_chmod_53904 posix_acl_chmod 0 53904 NULL
113388 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
113389 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
113390 +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
113391 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
113392 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
113393 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
113394 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
113395 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
113396 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
113397 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
113398 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
113399 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
113400 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
113401 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
113402 +_malloc_54077 _malloc 1 54077 NULL
113403 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
113404 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
113405 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2-0 54103 &altera_set_ir_pre_54103
113406 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
113407 +strn_len_54122 strn_len 0 54122 NULL
113408 +isku_receive_54130 isku_receive 4 54130 NULL
113409 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
113410 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
113411 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
113412 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
113413 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
113414 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
113415 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
113416 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
113417 +reada_add_block_54247 reada_add_block 2 54247 NULL
113418 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
113419 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
113420 +audio_write_54261 audio_write 4 54261 NULL nohasharray
113421 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
113422 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
113423 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
113424 +tipc_multicast_54285 tipc_multicast 4 54285 NULL
113425 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
113426 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
113427 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
113428 +sprintf_54306 sprintf 0 54306 NULL
113429 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
113430 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
113431 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
113432 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
113433 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
113434 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
113435 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
113436 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
113437 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
113438 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
113439 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
113440 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
113441 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
113442 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
113443 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
113444 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
113445 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
113446 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
113447 +viacam_read_54526 viacam_read 3 54526 NULL
113448 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
113449 +setsockopt_54539 setsockopt 5 54539 NULL
113450 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
113451 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
113452 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
113453 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
113454 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
113455 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
113456 +port_fops_write_54627 port_fops_write 3 54627 NULL
113457 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
113458 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
113459 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
113460 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
113461 +bus_add_device_54665 bus_add_device 0 54665 NULL
113462 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
113463 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
113464 +evm_read_key_54674 evm_read_key 3 54674 NULL
113465 +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
113466 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
113467 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
113468 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
113469 +kzalloc_54740 kzalloc 1 54740 NULL
113470 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
113471 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
113472 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
113473 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
113474 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
113475 +xfs_rtallocate_extent_block_54791 xfs_rtallocate_extent_block 0 54791 NULL
113476 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
113477 +nfsd_write_54809 nfsd_write 6 54809 NULL
113478 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
113479 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
113480 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
113481 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
113482 +generic_perform_write_54832 generic_perform_write 3-0 54832 NULL
113483 +write_rio_54837 write_rio 3 54837 NULL
113484 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
113485 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
113486 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
113487 +printer_read_54851 printer_read 3 54851 NULL
113488 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
113489 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
113490 +xfs_alloc_read_agfl_54879 xfs_alloc_read_agfl 0 54879 NULL
113491 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
113492 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
113493 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
113494 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
113495 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
113496 +add_port_54941 add_port 2 54941 NULL
113497 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
113498 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
113499 +c4_add_card_54968 c4_add_card 3 54968 NULL
113500 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
113501 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
113502 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
113503 +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
113504 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
113505 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
113506 +read_dma_55086 read_dma 3 55086 NULL
113507 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
113508 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
113509 +filldir_55137 filldir 3 55137 NULL
113510 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
113511 +xfs_check_agi_freecount_55149 xfs_check_agi_freecount 0 55149 NULL nohasharray
113512 +npages_to_npools_55149 npages_to_npools 0-1 55149 &xfs_check_agi_freecount_55149
113513 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
113514 +xfs_icsb_modify_counters_55156 xfs_icsb_modify_counters 0 55156 NULL
113515 +gfs2_ri_update_55185 gfs2_ri_update 0 55185 NULL
113516 +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
113517 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
113518 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
113519 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
113520 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
113521 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
113522 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
113523 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
113524 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
113525 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
113526 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
113527 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
113528 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
113529 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
113530 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
113531 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
113532 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
113533 +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
113534 +vme_user_read_55338 vme_user_read 3 55338 NULL
113535 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
113536 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
113537 +tipc_send2name_55373 tipc_send2name 5 55373 NULL
113538 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
113539 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
113540 +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
113541 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
113542 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
113543 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
113544 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
113545 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
113546 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
113547 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
113548 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
113549 +xfs_btree_split_55515 xfs_btree_split 0 55515 NULL
113550 +ea_get_55522 ea_get 3-0 55522 NULL
113551 +buffer_size_55534 buffer_size 0 55534 NULL
113552 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
113553 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
113554 +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
113555 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
113556 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
113557 +add_partition_55588 add_partition 2 55588 NULL
113558 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
113559 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
113560 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
113561 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
113562 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
113563 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
113564 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
113565 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
113566 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
113567 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
113568 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
113569 +get_info_55681 get_info 3 55681 NULL
113570 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
113571 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
113572 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
113573 +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
113574 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
113575 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
113576 +set_local_name_55757 set_local_name 4 55757 NULL
113577 +strlen_55778 strlen 0 55778 NULL
113578 +set_spte_55783 set_spte 4-5 55783 NULL
113579 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
113580 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
113581 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
113582 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
113583 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
113584 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
113585 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
113586 +hsc_write_55875 hsc_write 3 55875 NULL
113587 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
113588 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
113589 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
113590 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
113591 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
113592 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
113593 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
113594 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
113595 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
113596 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
113597 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
113598 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
113599 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
113600 +usb_ocp_write_56047 usb_ocp_write 4 56047 NULL
113601 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
113602 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
113603 +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
113604 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
113605 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
113606 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
113607 +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
113608 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
113609 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
113610 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
113611 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
113612 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
113613 +fd_copyin_56247 fd_copyin 3 56247 NULL
113614 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
113615 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
113616 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
113617 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
113618 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
113619 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
113620 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
113621 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
113622 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
113623 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
113624 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
113625 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
113626 +qd_get_56365 qd_get 0 56365 NULL
113627 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
113628 +dev_read_56369 dev_read 3 56369 NULL
113629 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
113630 +write_gssp_56404 write_gssp 3 56404 NULL
113631 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
113632 +do_get_write_access_56410 do_get_write_access 0 56410 NULL
113633 +store_msg_56417 store_msg 3 56417 NULL
113634 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
113635 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
113636 +fl_create_56435 fl_create 5 56435 NULL
113637 +gnttab_map_56439 gnttab_map 2 56439 NULL
113638 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
113639 +set_connectable_56458 set_connectable 4 56458 NULL
113640 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
113641 +putused_user_56467 putused_user 3 56467 NULL
113642 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
113643 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
113644 +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
113645 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
113646 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
113647 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
113648 +init_map_ip_56508 init_map_ip 5 56508 NULL
113649 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3-0-2 56512 NULL
113650 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
113651 +ip_options_get_56538 ip_options_get 4 56538 NULL
113652 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
113653 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
113654 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
113655 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
113656 +event_filter_write_56609 event_filter_write 3 56609 NULL
113657 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
113658 +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
113659 +gather_array_56641 gather_array 3 56641 NULL
113660 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
113661 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
113662 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
113663 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
113664 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
113665 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
113666 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
113667 +xfs_btree_decrement_56718 xfs_btree_decrement 0 56718 NULL
113668 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
113669 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
113670 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
113671 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
113672 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
113673 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
113674 +do_syslog_56807 do_syslog 3 56807 NULL
113675 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
113676 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
113677 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
113678 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
113679 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
113680 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
113681 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
113682 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
113683 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
113684 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
113685 +xfs_alloc_ag_vextent_56943 xfs_alloc_ag_vextent 0 56943 NULL
113686 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
113687 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
113688 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
113689 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
113690 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
113691 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
113692 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
113693 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
113694 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
113695 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
113696 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
113697 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
113698 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
113699 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
113700 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
113701 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
113702 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
113703 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
113704 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
113705 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
113706 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
113707 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
113708 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
113709 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
113710 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
113711 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
113712 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
113713 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
113714 +flush_space_57241 flush_space 0 57241 NULL
113715 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
113716 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
113717 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
113718 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
113719 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
113720 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
113721 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
113722 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
113723 +xfs_iread_57313 xfs_iread 0 57313 NULL nohasharray
113724 +write_file_regval_57313 write_file_regval 3 57313 &xfs_iread_57313
113725 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
113726 +usblp_read_57342 usblp_read 3 57342 NULL
113727 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
113728 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
113729 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
113730 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
113731 +read_file_blob_57406 read_file_blob 3 57406 NULL
113732 +enclosure_register_57412 enclosure_register 3 57412 NULL
113733 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
113734 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
113735 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
113736 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
113737 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
113738 +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
113739 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
113740 +skb_headlen_57501 skb_headlen 0 57501 NULL
113741 +copy_in_user_57502 copy_in_user 3 57502 NULL
113742 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL nohasharray
113743 +gfs2_quota_hold_57505 gfs2_quota_hold 0 57505 &ckhdid_printf_57505
113744 +init_tag_map_57515 init_tag_map 3 57515 NULL
113745 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
113746 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
113747 +cmm_read_57520 cmm_read 3 57520 NULL
113748 +inode_permission_57531 inode_permission 0 57531 NULL
113749 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
113750 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
113751 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
113752 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
113753 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
113754 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
113755 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
113756 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
113757 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
113758 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
113759 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
113760 +mem_read_57631 mem_read 3 57631 NULL
113761 +xfs_alloc_ag_vextent_near_57653 xfs_alloc_ag_vextent_near 0 57653 NULL
113762 +r3964_write_57662 r3964_write 4 57662 NULL
113763 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
113764 +__lgwrite_57669 __lgwrite 4 57669 NULL
113765 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
113766 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
113767 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
113768 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
113769 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
113770 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
113771 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
113772 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
113773 +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
113774 +ld2_57794 ld2 0 57794 NULL
113775 +ivtv_read_57796 ivtv_read 3 57796 NULL
113776 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
113777 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
113778 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
113779 +xfs_rtpick_extent_57843 xfs_rtpick_extent 0 57843 NULL nohasharray
113780 +flash_read_57843 flash_read 3 57843 &xfs_rtpick_extent_57843
113781 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
113782 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
113783 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
113784 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
113785 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
113786 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
113787 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
113788 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
113789 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
113790 +xfs_inode_item_format_convert_57937 xfs_inode_item_format_convert 0 57937 NULL
113791 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
113792 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
113793 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
113794 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
113795 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
113796 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
113797 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
113798 +mce_async_out_58056 mce_async_out 3 58056 NULL
113799 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
113800 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
113801 +cm4040_write_58079 cm4040_write 3 58079 NULL
113802 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
113803 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
113804 +rd_build_prot_space_58137 rd_build_prot_space 2 58137 NULL
113805 +xfs_bmap_add_extent_delay_real_58151 xfs_bmap_add_extent_delay_real 0 58151 NULL
113806 +xfs_btree_update_58167 xfs_btree_update 0 58167 NULL
113807 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
113808 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
113809 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
113810 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
113811 +read_file_debug_58256 read_file_debug 3 58256 NULL
113812 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
113813 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
113814 +profile_load_58267 profile_load 3 58267 NULL
113815 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
113816 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
113817 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
113818 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
113819 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
113820 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
113821 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
113822 +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
113823 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
113824 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
113825 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
113826 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
113827 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
113828 +xfs_btree_get_rec_58410 xfs_btree_get_rec 0 58410 NULL
113829 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
113830 +capabilities_read_58457 capabilities_read 3 58457 NULL
113831 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
113832 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
113833 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
113834 +nv_rd08_58472 nv_rd08 0 58472 NULL
113835 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
113836 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
113837 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
113838 +btrfs_cont_expand_58498 btrfs_cont_expand 0-2-3 58498 NULL
113839 +gfs2_dir_get_new_buffer_58509 gfs2_dir_get_new_buffer 0 58509 NULL
113840 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
113841 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
113842 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
113843 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
113844 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
113845 +xip_file_read_58592 xip_file_read 3 58592 NULL
113846 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
113847 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
113848 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
113849 +filemap_fdatawrite_range_58630 filemap_fdatawrite_range 0 58630 NULL
113850 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
113851 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
113852 +find_zero_58685 find_zero 0-1 58685 NULL
113853 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
113854 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
113855 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
113856 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
113857 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
113858 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
113859 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
113860 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
113861 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
113862 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
113863 +ep_read_58813 ep_read 3 58813 NULL
113864 +command_write_58841 command_write 3 58841 NULL
113865 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
113866 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
113867 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
113868 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
113869 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
113870 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
113871 +xfs_bmap_read_extents_58936 xfs_bmap_read_extents 0 58936 NULL
113872 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
113873 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
113874 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
113875 +__mem_cgroup_try_charge_58976 __mem_cgroup_try_charge 0 58976 NULL
113876 +init_list_set_59005 init_list_set 3 59005 NULL
113877 +ep_write_59008 ep_write 3 59008 NULL
113878 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
113879 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
113880 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
113881 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
113882 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
113883 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
113884 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
113885 +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL nohasharray
113886 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 &scsi_io_completion_59122
113887 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
113888 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
113889 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
113890 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
113891 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
113892 +ksize_59176 ksize 0 59176 NULL
113893 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
113894 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
113895 +xfs_ialloc_next_rec_59193 xfs_ialloc_next_rec 0 59193 NULL
113896 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
113897 +dt3155_read_59226 dt3155_read 3 59226 NULL
113898 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
113899 +nla_len_59258 nla_len 0 59258 NULL
113900 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
113901 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
113902 +xfs_iformat_fork_59312 xfs_iformat_fork 0 59312 NULL
113903 +fd_copyout_59323 fd_copyout 3 59323 NULL
113904 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
113905 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
113906 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL nohasharray
113907 +xfs_alloc_lookup_le_59346 xfs_alloc_lookup_le 0 59346 &xfs_attrmulti_attr_set_59346
113908 +__map_request_59350 __map_request 0 59350 NULL
113909 +gfs2_quota_lock_check_59353 gfs2_quota_lock_check 0 59353 NULL
113910 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
113911 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
113912 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
113913 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
113914 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
113915 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
113916 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
113917 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
113918 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
113919 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
113920 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
113921 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
113922 +tunables_write_59563 tunables_write 3 59563 NULL
113923 +bio_split_59564 bio_split 2 59564 NULL
113924 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
113925 +write_pbl_59583 write_pbl 4 59583 NULL
113926 +memdup_user_59590 memdup_user 2 59590 NULL
113927 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
113928 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
113929 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
113930 +mtrr_write_59622 mtrr_write 3 59622 NULL
113931 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
113932 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
113933 +file_update_time_59647 file_update_time 0 59647 NULL
113934 +hidraw_read_59650 hidraw_read 3 59650 NULL
113935 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
113936 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
113937 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
113938 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
113939 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
113940 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
113941 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
113942 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
113943 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
113944 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
113945 +strnlen_59746 strnlen 0 59746 NULL
113946 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
113947 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL nohasharray
113948 +cap_inode_need_killpriv_59766 cap_inode_need_killpriv 0 59766 &long_retry_limit_read_59766
113949 +venus_remove_59781 venus_remove 4 59781 NULL
113950 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
113951 +ipw_write_59807 ipw_write 3 59807 NULL
113952 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
113953 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
113954 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
113955 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
113956 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
113957 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
113958 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
113959 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
113960 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
113961 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
113962 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
113963 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
113964 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
113965 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
113966 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
113967 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
113968 +copy_items_60009 copy_items 7 60009 NULL
113969 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
113970 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
113971 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
113972 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
113973 +xfs_imap_to_bp_60034 xfs_imap_to_bp 0 60034 NULL
113974 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
113975 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
113976 +vcs_size_60050 vcs_size 0 60050 NULL
113977 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
113978 +compat_writev_60063 compat_writev 3 60063 NULL
113979 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
113980 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
113981 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
113982 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
113983 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
113984 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
113985 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
113986 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
113987 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
113988 +init_state_60165 init_state 2 60165 NULL
113989 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
113990 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
113991 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
113992 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
113993 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
113994 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
113995 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
113996 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
113997 +printer_write_60276 printer_write 3 60276 NULL
113998 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
113999 +getDataLength_60301 getDataLength 0 60301 NULL
114000 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
114001 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
114002 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
114003 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
114004 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
114005 +driver_names_read_60399 driver_names_read 3 60399 NULL
114006 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
114007 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
114008 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
114009 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
114010 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
114011 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
114012 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
114013 +xfs_btree_make_block_unfull_60511 xfs_btree_make_block_unfull 0 60511 NULL
114014 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
114015 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
114016 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
114017 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
114018 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
114019 +inode_change_ok_60614 inode_change_ok 0 60614 NULL
114020 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
114021 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
114022 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
114023 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
114024 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
114025 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
114026 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
114027 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
114028 +raid_status_60755 raid_status 5 60755 NULL
114029 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
114030 +opticon_write_60775 opticon_write 4 60775 NULL
114031 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
114032 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
114033 +gfs2_bmap_alloc_60822 gfs2_bmap_alloc 0 60822 NULL
114034 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
114035 +__clone_and_map_data_bio_60861 __clone_and_map_data_bio 4-3 60861 NULL
114036 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
114037 +generic_writepages_60871 generic_writepages 0 60871 NULL
114038 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
114039 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
114040 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
114041 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
114042 +scrub_chunk_60926 scrub_chunk 5 60926 NULL
114043 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
114044 +xfs_rtallocate_extent_size_60939 xfs_rtallocate_extent_size 0 60939 NULL
114045 +pti_char_write_60960 pti_char_write 3 60960 NULL
114046 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
114047 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
114048 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
114049 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
114050 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
114051 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
114052 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
114053 +symtab_init_61050 symtab_init 2 61050 NULL
114054 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
114055 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
114056 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
114057 +xfs_dabuf_map_61093 xfs_dabuf_map 0 61093 NULL
114058 +get_derived_key_61100 get_derived_key 4 61100 NULL
114059 +mem_cgroup_cache_charge_61101 mem_cgroup_cache_charge 0 61101 NULL
114060 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
114061 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
114062 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
114063 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
114064 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
114065 +pair_device_61175 pair_device 4 61175 NULL nohasharray
114066 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
114067 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
114068 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
114069 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
114070 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
114071 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
114072 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
114073 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270
114074 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
114075 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
114076 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
114077 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
114078 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
114079 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
114080 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
114081 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
114082 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
114083 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
114084 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
114085 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
114086 +system_enable_write_61396 system_enable_write 3 61396 NULL
114087 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
114088 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
114089 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
114090 +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
114091 +erst_errno_61526 erst_errno 0 61526 NULL
114092 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
114093 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
114094 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
114095 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
114096 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
114097 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
114098 +seq_open_private_61589 seq_open_private 3 61589 NULL
114099 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
114100 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
114101 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
114102 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
114103 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
114104 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
114105 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
114106 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
114107 +resize_stripes_61650 resize_stripes 2 61650 NULL
114108 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
114109 +insert_one_name_61668 insert_one_name 7 61668 NULL
114110 +lock_loop_61681 lock_loop 1 61681 NULL
114111 +filter_read_61692 filter_read 3 61692 NULL
114112 +iov_length_61716 iov_length 0 61716 NULL
114113 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
114114 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
114115 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
114116 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
114117 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
114118 +gfs2_meta_wait_61773 gfs2_meta_wait 0 61773 NULL
114119 +xfs_file_dio_aio_write_61801 xfs_file_dio_aio_write 0 61801 NULL
114120 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
114121 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
114122 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
114123 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
114124 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
114125 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
114126 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
114127 +get_fw_name_61874 get_fw_name 3 61874 NULL
114128 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
114129 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
114130 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
114131 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
114132 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
114133 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
114134 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
114135 +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
114136 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
114137 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
114138 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
114139 +fix_read_error_61965 fix_read_error 4 61965 NULL
114140 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
114141 +cow_file_range_61979 cow_file_range 3 61979 NULL
114142 +set_extent_delalloc_61982 set_extent_delalloc 0 61982 NULL
114143 +dequeue_event_62000 dequeue_event 3 62000 NULL
114144 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
114145 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
114146 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
114147 +SYSC_select_62024 SYSC_select 1 62024 NULL
114148 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
114149 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
114150 +do_pselect_62061 do_pselect 1 62061 NULL
114151 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
114152 +_xfs_log_force_lsn_62083 _xfs_log_force_lsn 0 62083 NULL
114153 +fat_setattr_62084 fat_setattr 0 62084 NULL
114154 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
114155 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
114156 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
114157 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
114158 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
114159 +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
114160 +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
114161 +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
114162 +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
114163 +video_usercopy_62151 video_usercopy 2 62151 NULL
114164 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
114165 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
114166 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
114167 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
114168 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
114169 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
114170 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
114171 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
114172 +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
114173 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
114174 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
114175 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
114176 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
114177 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
114178 +subseq_list_62332 subseq_list 3-0 62332 NULL
114179 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
114180 +flash_write_62354 flash_write 3 62354 NULL
114181 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
114182 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
114183 +altera_irscan_62396 altera_irscan 2 62396 NULL
114184 +set_ssp_62411 set_ssp 4 62411 NULL
114185 +udf_expand_file_adinicb_62470 udf_expand_file_adinicb 0 62470 NULL
114186 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
114187 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
114188 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
114189 +debugfs_read_62535 debugfs_read 3 62535 NULL
114190 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
114191 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
114192 +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
114193 +compute_bitstructs_62570 compute_bitstructs 0 62570 NULL
114194 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
114195 +get_subdir_62581 get_subdir 3 62581 NULL
114196 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
114197 +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
114198 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
114199 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
114200 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
114201 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
114202 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
114203 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
114204 +rdm_62719 rdm 0 62719 NULL
114205 +add_to_page_cache_62724 add_to_page_cache 0 62724 NULL
114206 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
114207 +key_replays_read_62746 key_replays_read 3 62746 NULL
114208 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
114209 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
114210 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
114211 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
114212 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
114213 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
114214 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
114215 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
114216 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
114217 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
114218 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
114219 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
114220 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
114221 +xfs_rtmodify_range_62877 xfs_rtmodify_range 0 62877 NULL
114222 +aoechr_write_62883 aoechr_write 3 62883 NULL
114223 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
114224 +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
114225 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
114226 +getdqbuf_62908 getdqbuf 1 62908 NULL
114227 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
114228 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
114229 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL nohasharray
114230 +xfs_trans_reserve_63026 xfs_trans_reserve 0 63026 &kstrtoull_from_user_63026
114231 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
114232 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
114233 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
114234 +unlink1_63059 unlink1 3 63059 NULL
114235 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
114236 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
114237 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
114238 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
114239 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
114240 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
114241 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
114242 +vme_master_read_63221 vme_master_read 0 63221 NULL
114243 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
114244 +ptp_read_63251 ptp_read 4 63251 NULL
114245 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
114246 +raid5_resize_63306 raid5_resize 2 63306 NULL
114247 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
114248 +proc_info_read_63344 proc_info_read 3 63344 NULL
114249 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
114250 +idmouse_read_63374 idmouse_read 3 63374 NULL
114251 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
114252 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
114253 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
114254 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
114255 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
114256 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
114257 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
114258 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
114259 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
114260 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
114261 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
114262 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL nohasharray
114263 +generic_cont_expand_simple_63534 generic_cont_expand_simple 0 63534 &ubi_more_leb_change_data_63534
114264 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
114265 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
114266 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
114267 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
114268 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
114269 +write_debug_level_63613 write_debug_level 3 63613 NULL
114270 +__spi_validate_63618 __spi_validate 0 63618 NULL
114271 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
114272 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
114273 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
114274 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
114275 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
114276 +vbi_read_63673 vbi_read 3 63673 NULL
114277 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
114278 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
114279 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
114280 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
114281 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
114282 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
114283 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
114284 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
114285 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
114286 +sel_write_load_63830 sel_write_load 3 63830 NULL
114287 +ll_readlink_63836 ll_readlink 3 63836 NULL
114288 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
114289 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
114290 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
114291 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
114292 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
114293 +__team_options_register_63941 __team_options_register 3 63941 NULL
114294 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
114295 +xfs_iflush_63956 xfs_iflush 0 63956 NULL
114296 +set_bredr_63975 set_bredr 4 63975 NULL
114297 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
114298 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
114299 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
114300 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
114301 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
114302 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
114303 +__generic_file_aio_write_64049 __generic_file_aio_write 0 64049 NULL
114304 +get_u8_64076 get_u8 0 64076 NULL
114305 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
114306 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
114307 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
114308 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
114309 +gfs2_inplace_reserve_64096 gfs2_inplace_reserve 0 64096 NULL nohasharray
114310 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 &gfs2_inplace_reserve_64096
114311 +to_bytes_64103 to_bytes 0-1 64103 NULL
114312 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
114313 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
114314 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
114315 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
114316 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
114317 +init_bch_64130 init_bch 1-2 64130 NULL
114318 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
114319 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
114320 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
114321 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
114322 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
114323 +read_pulse_64227 read_pulse 0-3 64227 NULL
114324 +ea_len_64229 ea_len 0 64229 NULL
114325 +xfs_rtmodify_summary_64265 xfs_rtmodify_summary 0 64265 NULL
114326 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
114327 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
114328 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
114329 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3-0 64288 NULL nohasharray
114330 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
114331 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
114332 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
114333 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
114334 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
114335 +ts_write_64336 ts_write 3 64336 NULL
114336 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
114337 +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
114338 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
114339 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
114340 +reg_create_64372 reg_create 5 64372 NULL
114341 +ilo_write_64378 ilo_write 3 64378 NULL
114342 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
114343 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
114344 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
114345 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
114346 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
114347 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
114348 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
114349 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
114350 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
114351 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
114352 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
114353 +single_open_size_64483 single_open_size 4 64483 NULL
114354 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL nohasharray
114355 +xfs_inode_ag_walk_64493 xfs_inode_ag_walk 0 64493 &p54_parse_rssical_64493
114356 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
114357 +remove_uuid_64505 remove_uuid 4 64505 NULL
114358 +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
114359 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
114360 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
114361 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
114362 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
114363 +SyS_bind_64544 SyS_bind 3 64544 NULL
114364 +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
114365 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
114366 +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
114367 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
114368 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
114369 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
114370 +do_erase_64574 do_erase 4 64574 NULL
114371 +fanotify_write_64623 fanotify_write 3 64623 NULL
114372 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
114373 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
114374 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
114375 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
114376 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
114377 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
114378 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
114379 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
114380 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
114381 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
114382 +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
114383 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
114384 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
114385 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
114386 +message_for_md_64777 message_for_md 5 64777 NULL
114387 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
114388 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
114389 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
114390 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
114391 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
114392 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
114393 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
114394 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
114395 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
114396 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
114397 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
114398 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
114399 +xfs_imap_lookup_64906 xfs_imap_lookup 0 64906 NULL
114400 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
114401 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
114402 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
114403 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
114404 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
114405 +insert_dent_65034 insert_dent 7 65034 NULL
114406 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
114407 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
114408 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
114409 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
114410 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
114411 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
114412 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
114413 +__xfs_bmapi_allocate_65142 __xfs_bmapi_allocate 0 65142 NULL
114414 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
114415 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
114416 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
114417 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
114418 +xfs_btree_check_ptr_65281 xfs_btree_check_ptr 0 65281 NULL
114419 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
114420 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
114421 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
114422 +get_var_len_65304 get_var_len 0 65304 NULL
114423 +unpack_array_65318 unpack_array 0 65318 NULL
114424 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
114425 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
114426 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
114427 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
114428 +SyS_writev_65372 SyS_writev 3 65372 NULL
114429 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
114430 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
114431 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
114432 +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
114433 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
114434 +device_add_groups_65423 device_add_groups 0 65423 NULL
114435 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
114436 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
114437 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
114438 +clear_user_65470 clear_user 2 65470 NULL
114439 +xfs_alloc_lookup_ge_65481 xfs_alloc_lookup_ge 0 65481 NULL
114440 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
114441 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
114442 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
114443 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
114444 diff --git a/tools/gcc/size_overflow_hash_aux.data b/tools/gcc/size_overflow_hash_aux.data
114445 new file mode 100644
114446 index 0000000..560cd7b
114447 --- /dev/null
114448 +++ b/tools/gcc/size_overflow_hash_aux.data
114449 @@ -0,0 +1,92 @@
114450 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
114451 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
114452 +mappedread_2627 mappedread 2 2627 NULL
114453 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
114454 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
114455 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
114456 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
114457 +dmu_write_6048 dmu_write 4-3 6048 NULL
114458 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
114459 +update_pages_6225 update_pages 2-3 6225 NULL
114460 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
114461 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
114462 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
114463 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
114464 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
114465 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
114466 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
114467 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
114468 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
114469 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
114470 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
114471 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
114472 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
114473 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
114474 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
114475 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
114476 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
114477 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
114478 +uiocopy_18680 uiocopy 2 18680 NULL
114479 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
114480 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
114481 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
114482 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
114483 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
114484 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
114485 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
114486 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
114487 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
114488 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
114489 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
114490 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
114491 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
114492 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
114493 +splat_write_30943 splat_write 3 30943 NULL
114494 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
114495 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
114496 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
114497 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
114498 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
114499 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
114500 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
114501 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
114502 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
114503 +copyinstr_36980 copyinstr 3 36980 NULL
114504 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
114505 +splat_read_38116 splat_read 3 38116 NULL
114506 +sa_setup_38756 sa_setup 4 38756 NULL
114507 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
114508 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
114509 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
114510 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
114511 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
114512 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
114513 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
114514 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
114515 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
114516 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
114517 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
114518 +kcopy_write_43683 kcopy_write 3 43683 NULL
114519 +uiomove_44355 uiomove 2 44355 NULL
114520 +dmu_read_44418 dmu_read 4-3 44418 NULL
114521 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
114522 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
114523 +copyin_45945 copyin 3 45945 NULL
114524 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
114525 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
114526 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
114527 +spa_history_write_49650 spa_history_write 3 49650 NULL
114528 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
114529 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
114530 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
114531 +copyout_51409 copyout 3 51409 NULL
114532 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
114533 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
114534 +get_nvlist_56685 get_nvlist 2 56685 NULL
114535 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
114536 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
114537 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
114538 +zpios_write_61823 zpios_write 3 61823 NULL
114539 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
114540 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
114541 +zpios_read_64734 zpios_read 3 64734 NULL
114542 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
114543 new file mode 100644
114544 index 0000000..ed21b21
114545 --- /dev/null
114546 +++ b/tools/gcc/size_overflow_plugin.c
114547 @@ -0,0 +1,4166 @@
114548 +/*
114549 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114550 + * Licensed under the GPL v2, or (at your option) v3
114551 + *
114552 + * Homepage:
114553 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114554 + *
114555 + * Documentation:
114556 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114557 + *
114558 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114559 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114560 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114561 + *
114562 + * Usage:
114563 + * $ # for 4.5/4.6/C based 4.7
114564 + * $ gcc -I`gcc -print-file-name=plugin`/include -I`gcc -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -std=gnu99 -ggdb -o size_overflow_plugin.so size_overflow_plugin.c
114565 + * $ # for C++ based 4.7/4.8+
114566 + * $ g++ -I`g++ -print-file-name=plugin`/include -I`g++ -print-file-name=plugin`/include/c-family -fPIC -shared -O2 -std=gnu++98 -fno-rtti -ggdb -o size_overflow_plugin.so size_overflow_plugin.c
114567 + *
114568 + * $ gcc -fplugin=./size_overflow_plugin.so test.c -O2
114569 + */
114570 +
114571 +#include "gcc-common.h"
114572 +
114573 +int plugin_is_GPL_compatible;
114574 +
114575 +static struct plugin_info size_overflow_plugin_info = {
114576 + .version = "20140407",
114577 + .help = "no-size-overflow\tturn off size overflow checking\n",
114578 +};
114579 +
114580 +#define BEFORE_STMT true
114581 +#define AFTER_STMT false
114582 +#define CREATE_NEW_VAR NULL_TREE
114583 +#define CODES_LIMIT 32
114584 +#define MAX_PARAM 31
114585 +#define VEC_LEN 128
114586 +#define RET_CHECK NULL_TREE
114587 +#define CANNOT_FIND_ARG 32
114588 +#define WRONG_NODE 32
114589 +#define NOT_INTENTIONAL_ASM NULL
114590 +#define MIN_CHECK true
114591 +#define MAX_CHECK false
114592 +
114593 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
114594 +#define YES_ASM_STR "# size_overflow MARK_YES "
114595 +#define OK_ASM_STR "# size_overflow "
114596 +
114597 +struct size_overflow_hash {
114598 + const struct size_overflow_hash * const next;
114599 + const char * const name;
114600 + const unsigned int param;
114601 +};
114602 +
114603 +#include "size_overflow_hash.h"
114604 +#include "size_overflow_hash_aux.h"
114605 +
114606 +enum mark {
114607 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
114608 +};
114609 +
114610 +static unsigned int call_count;
114611 +
114612 +enum stmt_flags {
114613 + MY_STMT, NO_CAST_CHECK, VISITED_STMT, NO_FLAGS
114614 +};
114615 +
114616 +struct visited {
114617 + struct visited *next;
114618 + const_tree fndecl;
114619 + unsigned int num;
114620 +};
114621 +
114622 +struct next_cgraph_node {
114623 + struct next_cgraph_node *next;
114624 + struct cgraph_node *current_function;
114625 + tree callee_fndecl;
114626 + unsigned int num;
114627 +};
114628 +
114629 +struct interesting_node {
114630 + struct interesting_node *next;
114631 + gimple first_stmt;
114632 + const_tree fndecl;
114633 + tree node;
114634 +#if BUILDING_GCC_VERSION <= 4007
114635 + VEC(tree, gc) *last_nodes;
114636 +#else
114637 + vec<tree, va_gc> *last_nodes;
114638 +#endif
114639 + unsigned int num;
114640 + enum mark intentional_attr_decl;
114641 + enum mark intentional_attr_cur_fndecl;
114642 + gimple intentional_mark_from_gimple;
114643 +};
114644 +
114645 +static tree report_size_overflow_decl;
114646 +
114647 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs);
114648 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
114649 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
114650 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
114651 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
114652 +
114653 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114654 +static tree get_size_overflow_type(gimple stmt, const_tree node);
114655 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114656 +
114657 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114658 +{
114659 + unsigned int arg_count;
114660 + enum tree_code code = TREE_CODE(*node);
114661 +
114662 + switch (code) {
114663 + case FUNCTION_DECL:
114664 + arg_count = type_num_arguments(TREE_TYPE(*node));
114665 + break;
114666 + case FUNCTION_TYPE:
114667 + case METHOD_TYPE:
114668 + arg_count = type_num_arguments(*node);
114669 + break;
114670 + default:
114671 + *no_add_attrs = true;
114672 + error("%s: %qE attribute only applies to functions", __func__, name);
114673 + return NULL_TREE;
114674 + }
114675 +
114676 + for (; args; args = TREE_CHAIN(args)) {
114677 + tree position = TREE_VALUE(args);
114678 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
114679 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
114680 + *no_add_attrs = true;
114681 + }
114682 + }
114683 + return NULL_TREE;
114684 +}
114685 +
114686 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
114687 +{
114688 + unsigned int arg_count;
114689 + enum tree_code code = TREE_CODE(*node);
114690 +
114691 + switch (code) {
114692 + case FUNCTION_DECL:
114693 + arg_count = type_num_arguments(TREE_TYPE(*node));
114694 + break;
114695 + case FUNCTION_TYPE:
114696 + case METHOD_TYPE:
114697 + arg_count = type_num_arguments(*node);
114698 + break;
114699 + case FIELD_DECL:
114700 + return NULL_TREE;
114701 + default:
114702 + *no_add_attrs = true;
114703 + error("%qE attribute only applies to functions", name);
114704 + return NULL_TREE;
114705 + }
114706 +
114707 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
114708 + return NULL_TREE;
114709 +
114710 + for (; args; args = TREE_CHAIN(args)) {
114711 + tree position = TREE_VALUE(args);
114712 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
114713 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
114714 + *no_add_attrs = true;
114715 + }
114716 + }
114717 + return NULL_TREE;
114718 +}
114719 +
114720 +static struct attribute_spec size_overflow_attr = {
114721 + .name = "size_overflow",
114722 + .min_length = 1,
114723 + .max_length = -1,
114724 + .decl_required = true,
114725 + .type_required = false,
114726 + .function_type_required = false,
114727 + .handler = handle_size_overflow_attribute,
114728 +#if BUILDING_GCC_VERSION >= 4007
114729 + .affects_type_identity = false
114730 +#endif
114731 +};
114732 +
114733 +static struct attribute_spec intentional_overflow_attr = {
114734 + .name = "intentional_overflow",
114735 + .min_length = 1,
114736 + .max_length = -1,
114737 + .decl_required = true,
114738 + .type_required = false,
114739 + .function_type_required = false,
114740 + .handler = handle_intentional_overflow_attribute,
114741 +#if BUILDING_GCC_VERSION >= 4007
114742 + .affects_type_identity = false
114743 +#endif
114744 +};
114745 +
114746 +static void register_attributes(void __unused *event_data, void __unused *data)
114747 +{
114748 + register_attribute(&size_overflow_attr);
114749 + register_attribute(&intentional_overflow_attr);
114750 +}
114751 +
114752 +static enum stmt_flags get_stmt_flag(gimple stmt)
114753 +{
114754 + bool bit_1, bit_2;
114755 +
114756 + bit_1 = gimple_plf(stmt, GF_PLF_1);
114757 + bit_2 = gimple_plf(stmt, GF_PLF_2);
114758 +
114759 + if (!bit_1 && !bit_2)
114760 + return NO_FLAGS;
114761 + if (bit_1 && bit_2)
114762 + return MY_STMT;
114763 + if (!bit_1 && bit_2)
114764 + return VISITED_STMT;
114765 + return NO_CAST_CHECK;
114766 +}
114767 +
114768 +static void set_stmt_flag(gimple stmt, enum stmt_flags new_flag)
114769 +{
114770 + bool bit_1, bit_2;
114771 +
114772 + switch (new_flag) {
114773 + case NO_FLAGS:
114774 + bit_1 = bit_2 = false;
114775 + break;
114776 + case MY_STMT:
114777 + bit_1 = bit_2 = true;
114778 + break;
114779 + case VISITED_STMT:
114780 + bit_1 = false;
114781 + bit_2 = true;
114782 + break;
114783 + case NO_CAST_CHECK:
114784 + bit_1 = true;
114785 + bit_2 = false;
114786 + break;
114787 + default:
114788 + gcc_unreachable();
114789 + }
114790 +
114791 + gimple_set_plf(stmt, GF_PLF_1, bit_1);
114792 + gimple_set_plf(stmt, GF_PLF_2, bit_2);
114793 +}
114794 +
114795 +static bool is_bool(const_tree node)
114796 +{
114797 + const_tree type;
114798 +
114799 + if (node == NULL_TREE)
114800 + return false;
114801 +
114802 + type = TREE_TYPE(node);
114803 + if (!INTEGRAL_TYPE_P(type))
114804 + return false;
114805 + if (TREE_CODE(type) == BOOLEAN_TYPE)
114806 + return true;
114807 + if (TYPE_PRECISION(type) == 1)
114808 + return true;
114809 + return false;
114810 +}
114811 +
114812 +static bool skip_types(const_tree var)
114813 +{
114814 + tree type;
114815 + enum tree_code code;
114816 +
114817 + if (is_gimple_constant(var))
114818 + return true;
114819 +
114820 + switch (TREE_CODE(var)) {
114821 + case ADDR_EXPR:
114822 +#if BUILDING_GCC_VERSION >= 4006
114823 + case MEM_REF:
114824 +#endif
114825 + case ARRAY_REF:
114826 + case BIT_FIELD_REF:
114827 + case INDIRECT_REF:
114828 + case TARGET_MEM_REF:
114829 + case COMPONENT_REF:
114830 + case VAR_DECL:
114831 + case VIEW_CONVERT_EXPR:
114832 + return true;
114833 + default:
114834 + break;
114835 + }
114836 +
114837 + code = TREE_CODE(var);
114838 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
114839 +
114840 + type = TREE_TYPE(var);
114841 + switch (TREE_CODE(type)) {
114842 + case INTEGER_TYPE:
114843 + case ENUMERAL_TYPE:
114844 + return false;
114845 + case BOOLEAN_TYPE:
114846 + return is_bool(var);
114847 + default:
114848 + return true;
114849 + }
114850 +}
114851 +
114852 +static inline gimple get_def_stmt(const_tree node)
114853 +{
114854 + gcc_assert(node != NULL_TREE);
114855 +
114856 + if (skip_types(node))
114857 + return NULL;
114858 +
114859 + if (TREE_CODE(node) != SSA_NAME)
114860 + return NULL;
114861 + return SSA_NAME_DEF_STMT(node);
114862 +}
114863 +
114864 +static unsigned char get_tree_code(const_tree type)
114865 +{
114866 + switch (TREE_CODE(type)) {
114867 + case ARRAY_TYPE:
114868 + return 0;
114869 + case BOOLEAN_TYPE:
114870 + return 1;
114871 + case ENUMERAL_TYPE:
114872 + return 2;
114873 + case FUNCTION_TYPE:
114874 + return 3;
114875 + case INTEGER_TYPE:
114876 + return 4;
114877 + case POINTER_TYPE:
114878 + return 5;
114879 + case RECORD_TYPE:
114880 + return 6;
114881 + case UNION_TYPE:
114882 + return 7;
114883 + case VOID_TYPE:
114884 + return 8;
114885 + case REAL_TYPE:
114886 + return 9;
114887 + case VECTOR_TYPE:
114888 + return 10;
114889 + case REFERENCE_TYPE:
114890 + return 11;
114891 + case OFFSET_TYPE:
114892 + return 12;
114893 + case COMPLEX_TYPE:
114894 + return 13;
114895 + default:
114896 + debug_tree((tree)type);
114897 + gcc_unreachable();
114898 + }
114899 +}
114900 +
114901 +struct function_hash {
114902 + size_t tree_codes_len;
114903 + unsigned char tree_codes[CODES_LIMIT];
114904 + const_tree fndecl;
114905 + unsigned int hash;
114906 +};
114907 +
114908 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
114909 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
114910 +{
114911 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
114912 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
114913 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
114914 +
114915 + unsigned int m = 0x57559429;
114916 + unsigned int n = 0x5052acdb;
114917 + const unsigned int *key4 = (const unsigned int *)key;
114918 + unsigned int h = len;
114919 + unsigned int k = len + seed + n;
114920 + unsigned long long p;
114921 +
114922 + while (len >= 8) {
114923 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
114924 + len -= 8;
114925 + }
114926 + if (len >= 4) {
114927 + cwmixb(key4[0]) key4 += 1;
114928 + len -= 4;
114929 + }
114930 + if (len)
114931 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
114932 + cwmixb(h ^ (k + n));
114933 + return k ^ h;
114934 +
114935 +#undef cwfold
114936 +#undef cwmixa
114937 +#undef cwmixb
114938 +}
114939 +
114940 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
114941 +{
114942 + unsigned int fn, codes, seed = 0;
114943 +
114944 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
114945 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
114946 +
114947 + fn_hash_data->hash = fn ^ codes;
114948 +}
114949 +
114950 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
114951 +{
114952 + gcc_assert(type != NULL_TREE);
114953 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
114954 +
114955 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
114956 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
114957 + fn_hash_data->tree_codes_len++;
114958 + type = TREE_TYPE(type);
114959 + }
114960 +}
114961 +
114962 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
114963 +{
114964 + const_tree result;
114965 +
114966 + gcc_assert(node != NULL_TREE);
114967 +
114968 + if (DECL_P(node)) {
114969 + result = DECL_RESULT(node);
114970 + if (result != NULL_TREE)
114971 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
114972 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
114973 + }
114974 +
114975 + gcc_assert(TYPE_P(node));
114976 +
114977 + if (TREE_CODE(node) == FUNCTION_TYPE)
114978 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
114979 +
114980 + return set_node_codes(node, fn_hash_data);
114981 +}
114982 +
114983 +static void set_function_codes(struct function_hash *fn_hash_data)
114984 +{
114985 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
114986 + enum tree_code code = TREE_CODE(type);
114987 +
114988 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
114989 +
114990 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
114991 +
114992 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
114993 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
114994 +}
114995 +
114996 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
114997 +{
114998 + while (entry) {
114999 + if (!strcmp(entry->name, func_name))
115000 + return entry;
115001 + entry = entry->next;
115002 + }
115003 + return NULL;
115004 +}
115005 +
115006 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
115007 +{
115008 + const struct size_overflow_hash *entry;
115009 + struct function_hash fn_hash_data;
115010 + const char *func_name;
115011 +
115012 + // skip builtins __builtin_constant_p
115013 + if (DECL_BUILT_IN(fndecl))
115014 + return NULL;
115015 +
115016 + fn_hash_data.fndecl = fndecl;
115017 + fn_hash_data.tree_codes_len = 0;
115018 +
115019 + set_function_codes(&fn_hash_data);
115020 + gcc_assert(fn_hash_data.tree_codes_len != 0);
115021 +
115022 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
115023 + set_hash(func_name, &fn_hash_data);
115024 +
115025 + entry = size_overflow_hash[fn_hash_data.hash];
115026 + entry = get_proper_hash_chain(entry, func_name);
115027 + if (entry)
115028 + return entry;
115029 + entry = size_overflow_hash_aux[fn_hash_data.hash];
115030 + return get_proper_hash_chain(entry, func_name);
115031 +}
115032 +
115033 +static void print_missing_msg(const_tree func, unsigned int argnum)
115034 +{
115035 + location_t loc;
115036 + const char *curfunc;
115037 + struct function_hash fn_hash_data;
115038 +
115039 + fn_hash_data.fndecl = DECL_ORIGIN(func);
115040 + fn_hash_data.tree_codes_len = 0;
115041 +
115042 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
115043 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
115044 +
115045 + set_function_codes(&fn_hash_data);
115046 + set_hash(curfunc, &fn_hash_data);
115047 +
115048 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
115049 +}
115050 +
115051 +static unsigned int find_arg_number_tree(const_tree arg, const_tree func)
115052 +{
115053 + tree var;
115054 + unsigned int argnum = 1;
115055 +
115056 + if (TREE_CODE(arg) == SSA_NAME)
115057 + arg = SSA_NAME_VAR(arg);
115058 +
115059 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
115060 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
115061 + continue;
115062 + if (!skip_types(var))
115063 + return argnum;
115064 + }
115065 +
115066 + return CANNOT_FIND_ARG;
115067 +}
115068 +
115069 +static tree create_new_var(tree type)
115070 +{
115071 + tree new_var = create_tmp_var(type, "cicus");
115072 +
115073 + add_referenced_var(new_var);
115074 + return new_var;
115075 +}
115076 +
115077 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
115078 +{
115079 + gimple assign;
115080 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115081 + tree type = TREE_TYPE(rhs1);
115082 + tree lhs = create_new_var(type);
115083 +
115084 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
115085 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
115086 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
115087 +
115088 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
115089 + update_stmt(assign);
115090 + set_stmt_flag(assign, MY_STMT);
115091 + return assign;
115092 +}
115093 +
115094 +static tree cast_a_tree(tree type, tree var)
115095 +{
115096 + gcc_assert(type != NULL_TREE);
115097 + gcc_assert(var != NULL_TREE);
115098 + gcc_assert(fold_convertible_p(type, var));
115099 +
115100 + return fold_convert(type, var);
115101 +}
115102 +
115103 +static tree get_lhs(const_gimple stmt)
115104 +{
115105 + switch (gimple_code(stmt)) {
115106 + case GIMPLE_ASSIGN:
115107 + case GIMPLE_CALL:
115108 + return gimple_get_lhs(stmt);
115109 + case GIMPLE_PHI:
115110 + return gimple_phi_result(stmt);
115111 + default:
115112 + return NULL_TREE;
115113 + }
115114 +}
115115 +
115116 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
115117 +{
115118 + const_gimple def_stmt = get_def_stmt(rhs);
115119 +
115120 + if (force)
115121 + return false;
115122 +
115123 + if (is_gimple_constant(rhs))
115124 + return false;
115125 +
115126 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
115127 + return false;
115128 +
115129 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
115130 + return false;
115131 +
115132 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
115133 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
115134 + return false;
115135 +
115136 + return true;
115137 +}
115138 +
115139 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
115140 +{
115141 + gimple assign, def_stmt;
115142 +
115143 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
115144 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
115145 + gcc_unreachable();
115146 +
115147 + def_stmt = get_def_stmt(rhs);
115148 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && get_stmt_flag(def_stmt) == MY_STMT)
115149 + return def_stmt;
115150 +
115151 + if (lhs == CREATE_NEW_VAR)
115152 + lhs = create_new_var(dst_type);
115153 +
115154 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
115155 +
115156 + if (!gsi_end_p(*gsi)) {
115157 + location_t loc = gimple_location(gsi_stmt(*gsi));
115158 + gimple_set_location(assign, loc);
115159 + }
115160 +
115161 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
115162 +
115163 + if (before)
115164 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
115165 + else
115166 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
115167 + update_stmt(assign);
115168 + return assign;
115169 +}
115170 +
115171 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
115172 +{
115173 + gimple_stmt_iterator gsi;
115174 + tree lhs;
115175 + gimple new_stmt;
115176 +
115177 + if (rhs == NULL_TREE)
115178 + return NULL_TREE;
115179 +
115180 + gsi = gsi_for_stmt(stmt);
115181 + new_stmt = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
115182 + set_stmt_flag(new_stmt, MY_STMT);
115183 +
115184 + lhs = get_lhs(new_stmt);
115185 + gcc_assert(lhs != NULL_TREE);
115186 + return lhs;
115187 +}
115188 +
115189 +static tree cast_to_TI_type(gimple stmt, tree node)
115190 +{
115191 + gimple_stmt_iterator gsi;
115192 + gimple cast_stmt;
115193 + tree type = TREE_TYPE(node);
115194 +
115195 + if (types_compatible_p(type, intTI_type_node))
115196 + return node;
115197 +
115198 + gsi = gsi_for_stmt(stmt);
115199 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115200 + set_stmt_flag(cast_stmt, MY_STMT);
115201 + return gimple_assign_lhs(cast_stmt);
115202 +}
115203 +
115204 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
115205 +{
115206 + tree lhs, new_lhs;
115207 + gimple_stmt_iterator gsi;
115208 +
115209 + if (rhs1 == NULL_TREE) {
115210 + debug_gimple_stmt(oldstmt);
115211 + error("%s: rhs1 is NULL_TREE", __func__);
115212 + gcc_unreachable();
115213 + }
115214 +
115215 + switch (gimple_code(oldstmt)) {
115216 + case GIMPLE_ASM:
115217 + lhs = rhs1;
115218 + break;
115219 + case GIMPLE_CALL:
115220 + case GIMPLE_ASSIGN:
115221 + lhs = gimple_get_lhs(oldstmt);
115222 + break;
115223 + default:
115224 + debug_gimple_stmt(oldstmt);
115225 + gcc_unreachable();
115226 + }
115227 +
115228 + gsi = gsi_for_stmt(oldstmt);
115229 + pointer_set_insert(visited, oldstmt);
115230 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
115231 + basic_block next_bb, cur_bb;
115232 + const_edge e;
115233 +
115234 + gcc_assert(before == false);
115235 + gcc_assert(stmt_can_throw_internal(oldstmt));
115236 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
115237 + gcc_assert(!gsi_end_p(gsi));
115238 +
115239 + cur_bb = gimple_bb(oldstmt);
115240 + next_bb = cur_bb->next_bb;
115241 + e = find_edge(cur_bb, next_bb);
115242 + gcc_assert(e != NULL);
115243 + gcc_assert(e->flags & EDGE_FALLTHRU);
115244 +
115245 + gsi = gsi_after_labels(next_bb);
115246 + gcc_assert(!gsi_end_p(gsi));
115247 +
115248 + before = true;
115249 + oldstmt = gsi_stmt(gsi);
115250 + }
115251 +
115252 + new_lhs = cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
115253 + return new_lhs;
115254 +}
115255 +
115256 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
115257 +{
115258 + gimple stmt;
115259 + gimple_stmt_iterator gsi;
115260 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
115261 +
115262 + if (get_stmt_flag(oldstmt) == MY_STMT)
115263 + return lhs;
115264 +
115265 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
115266 + rhs1 = gimple_assign_rhs1(oldstmt);
115267 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
115268 + }
115269 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
115270 + rhs2 = gimple_assign_rhs2(oldstmt);
115271 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
115272 + }
115273 +
115274 + stmt = gimple_copy(oldstmt);
115275 + gimple_set_location(stmt, gimple_location(oldstmt));
115276 + set_stmt_flag(stmt, MY_STMT);
115277 +
115278 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
115279 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
115280 +
115281 + size_overflow_type = get_size_overflow_type(oldstmt, node);
115282 +
115283 + new_var = create_new_var(size_overflow_type);
115284 + new_var = make_ssa_name(new_var, stmt);
115285 + gimple_assign_set_lhs(stmt, new_var);
115286 +
115287 + if (rhs1 != NULL_TREE)
115288 + gimple_assign_set_rhs1(stmt, rhs1);
115289 +
115290 + if (rhs2 != NULL_TREE)
115291 + gimple_assign_set_rhs2(stmt, rhs2);
115292 +#if BUILDING_GCC_VERSION >= 4006
115293 + if (rhs3 != NULL_TREE)
115294 + gimple_assign_set_rhs3(stmt, rhs3);
115295 +#endif
115296 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
115297 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
115298 +
115299 + gsi = gsi_for_stmt(oldstmt);
115300 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
115301 + update_stmt(stmt);
115302 + pointer_set_insert(visited, oldstmt);
115303 + return gimple_assign_lhs(stmt);
115304 +}
115305 +
115306 +static tree cast_parm_decl(tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
115307 +{
115308 + gimple assign;
115309 + gimple_stmt_iterator gsi;
115310 + basic_block first_bb;
115311 +
115312 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
115313 +
115314 + if (bb->index == 0) {
115315 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
115316 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115317 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
115318 + bb = first_bb;
115319 + }
115320 +
115321 + gsi = gsi_after_labels(bb);
115322 + assign = build_cast_stmt(size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
115323 + set_stmt_flag(assign, MY_STMT);
115324 +
115325 + return gimple_assign_lhs(assign);
115326 +}
115327 +
115328 +static tree use_phi_ssa_name(tree ssa_name_var, tree new_arg)
115329 +{
115330 + gimple_stmt_iterator gsi;
115331 + gimple assign, def_stmt = get_def_stmt(new_arg);
115332 +
115333 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
115334 + gsi = gsi_after_labels(gimple_bb(def_stmt));
115335 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
115336 + } else {
115337 + gsi = gsi_for_stmt(def_stmt);
115338 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
115339 + }
115340 +
115341 + set_stmt_flag(assign, MY_STMT);
115342 + return gimple_assign_lhs(assign);
115343 +}
115344 +
115345 +static tree cast_visited_phi_arg(tree ssa_name_var, tree arg, tree size_overflow_type)
115346 +{
115347 + basic_block bb;
115348 + gimple_stmt_iterator gsi;
115349 + const_gimple def_stmt;
115350 + gimple assign;
115351 +
115352 + def_stmt = get_def_stmt(arg);
115353 + bb = gimple_bb(def_stmt);
115354 + gcc_assert(bb->index != 0);
115355 + gsi = gsi_after_labels(bb);
115356 +
115357 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
115358 + set_stmt_flag(assign, MY_STMT);
115359 + return gimple_assign_lhs(assign);
115360 +}
115361 +
115362 +static tree create_new_phi_arg(tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
115363 +{
115364 + tree size_overflow_type;
115365 + tree arg;
115366 + const_gimple def_stmt;
115367 +
115368 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
115369 + return new_arg;
115370 +
115371 + arg = gimple_phi_arg_def(oldstmt, i);
115372 + def_stmt = get_def_stmt(arg);
115373 + gcc_assert(def_stmt != NULL);
115374 + size_overflow_type = get_size_overflow_type(oldstmt, arg);
115375 +
115376 + switch (gimple_code(def_stmt)) {
115377 + case GIMPLE_PHI:
115378 + return cast_visited_phi_arg(ssa_name_var, arg, size_overflow_type);
115379 + case GIMPLE_NOP: {
115380 + basic_block bb;
115381 +
115382 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
115383 + return cast_parm_decl(ssa_name_var, arg, size_overflow_type, bb);
115384 + }
115385 + case GIMPLE_ASM: {
115386 + gimple_stmt_iterator gsi;
115387 + gimple assign, stmt = get_def_stmt(arg);
115388 +
115389 + gsi = gsi_for_stmt(stmt);
115390 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
115391 + set_stmt_flag(assign, MY_STMT);
115392 + return gimple_assign_lhs(assign);
115393 + }
115394 + default:
115395 + gcc_assert(new_arg != NULL_TREE);
115396 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
115397 + return use_phi_ssa_name(ssa_name_var, new_arg);
115398 + }
115399 +}
115400 +
115401 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
115402 +{
115403 + basic_block bb;
115404 + gimple phi;
115405 + gimple_seq seq;
115406 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
115407 +
115408 + bb = gsi_bb(gsi);
115409 +
115410 + if (result == NULL_TREE) {
115411 + tree old_result = gimple_phi_result(oldstmt);
115412 + tree size_overflow_type = get_size_overflow_type(oldstmt, old_result);
115413 +
115414 + result = create_new_var(size_overflow_type);
115415 + }
115416 +
115417 + phi = create_phi_node(result, bb);
115418 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
115419 + seq = phi_nodes(bb);
115420 + gsi = gsi_last(seq);
115421 + gsi_remove(&gsi, false);
115422 +
115423 + gsi = gsi_for_stmt(oldstmt);
115424 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
115425 + gimple_set_bb(phi, bb);
115426 + set_stmt_flag(phi, MY_STMT);
115427 + return phi;
115428 +}
115429 +
115430 +#if BUILDING_GCC_VERSION <= 4007
115431 +static tree create_new_phi_node(VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
115432 +#else
115433 +static tree create_new_phi_node(vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
115434 +#endif
115435 +{
115436 + gimple new_phi;
115437 + unsigned int i;
115438 + tree arg, result;
115439 + location_t loc = gimple_location(oldstmt);
115440 +
115441 +#if BUILDING_GCC_VERSION <= 4007
115442 + gcc_assert(!VEC_empty(tree, *args));
115443 +#else
115444 + gcc_assert(!args->is_empty());
115445 +#endif
115446 +
115447 + new_phi = overflow_create_phi_node(oldstmt, ssa_name_var);
115448 + result = gimple_phi_result(new_phi);
115449 + ssa_name_var = SSA_NAME_VAR(result);
115450 +
115451 +#if BUILDING_GCC_VERSION <= 4007
115452 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
115453 +#else
115454 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
115455 +#endif
115456 + arg = create_new_phi_arg(ssa_name_var, arg, oldstmt, i);
115457 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
115458 + }
115459 +
115460 +#if BUILDING_GCC_VERSION <= 4007
115461 + VEC_free(tree, heap, *args);
115462 +#else
115463 + vec_free(args);
115464 +#endif
115465 + update_stmt(new_phi);
115466 + return result;
115467 +}
115468 +
115469 +static tree handle_phi(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree orig_result)
115470 +{
115471 + tree ssa_name_var = NULL_TREE;
115472 +#if BUILDING_GCC_VERSION <= 4007
115473 + VEC(tree, heap) *args = NULL;
115474 +#else
115475 + vec<tree, va_heap, vl_embed> *args = NULL;
115476 +#endif
115477 + gimple oldstmt = get_def_stmt(orig_result);
115478 + unsigned int i, len = gimple_phi_num_args(oldstmt);
115479 +
115480 + pointer_set_insert(visited, oldstmt);
115481 + for (i = 0; i < len; i++) {
115482 + tree arg, new_arg;
115483 +
115484 + arg = gimple_phi_arg_def(oldstmt, i);
115485 + new_arg = expand(visited, caller_node, arg);
115486 +
115487 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
115488 + ssa_name_var = SSA_NAME_VAR(new_arg);
115489 +
115490 + if (is_gimple_constant(arg)) {
115491 + tree size_overflow_type = get_size_overflow_type(oldstmt, arg);
115492 +
115493 + new_arg = cast_a_tree(size_overflow_type, arg);
115494 + }
115495 +
115496 +#if BUILDING_GCC_VERSION <= 4007
115497 + VEC_safe_push(tree, heap, args, new_arg);
115498 +#else
115499 + vec_safe_push(args, new_arg);
115500 +#endif
115501 + }
115502 +
115503 +#if BUILDING_GCC_VERSION <= 4007
115504 + return create_new_phi_node(&args, ssa_name_var, oldstmt);
115505 +#else
115506 + return create_new_phi_node(args, ssa_name_var, oldstmt);
115507 +#endif
115508 +}
115509 +
115510 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
115511 +{
115512 + gimple assign;
115513 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115514 + tree origtype = TREE_TYPE(orig_rhs);
115515 +
115516 + gcc_assert(is_gimple_assign(stmt));
115517 +
115518 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
115519 + set_stmt_flag(assign, MY_STMT);
115520 + return gimple_assign_lhs(assign);
115521 +}
115522 +
115523 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
115524 +{
115525 + const_tree rhs1, lhs, rhs1_type, lhs_type;
115526 + enum machine_mode lhs_mode, rhs_mode;
115527 + gimple def_stmt = get_def_stmt(no_const_rhs);
115528 +
115529 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115530 + return false;
115531 +
115532 + rhs1 = gimple_assign_rhs1(def_stmt);
115533 + lhs = gimple_assign_lhs(def_stmt);
115534 + rhs1_type = TREE_TYPE(rhs1);
115535 + lhs_type = TREE_TYPE(lhs);
115536 + rhs_mode = TYPE_MODE(rhs1_type);
115537 + lhs_mode = TYPE_MODE(lhs_type);
115538 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
115539 + return false;
115540 +
115541 + return true;
115542 +}
115543 +
115544 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
115545 +{
115546 + tree rhs1 = gimple_assign_rhs1(stmt);
115547 + tree lhs = gimple_assign_lhs(stmt);
115548 + const_tree rhs1_type = TREE_TYPE(rhs1);
115549 + const_tree lhs_type = TREE_TYPE(lhs);
115550 +
115551 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
115552 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115553 +
115554 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
115555 +}
115556 +
115557 +static bool no_uses(tree node)
115558 +{
115559 + imm_use_iterator imm_iter;
115560 + use_operand_p use_p;
115561 +
115562 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
115563 + const_gimple use_stmt = USE_STMT(use_p);
115564 +
115565 + if (use_stmt == NULL)
115566 + return true;
115567 + if (is_gimple_debug(use_stmt))
115568 + continue;
115569 + return false;
115570 + }
115571 + return true;
115572 +}
115573 +
115574 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
115575 +static bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
115576 +{
115577 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
115578 + gimple def_stmt = get_def_stmt(lhs);
115579 +
115580 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115581 + return false;
115582 +
115583 + rhs1 = gimple_assign_rhs1(def_stmt);
115584 + rhs_type = TREE_TYPE(rhs1);
115585 + lhs_type = TREE_TYPE(lhs);
115586 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
115587 + return false;
115588 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
115589 + return false;
115590 +
115591 + def_stmt = get_def_stmt(rhs1);
115592 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
115593 + return false;
115594 +
115595 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
115596 + return false;
115597 +
115598 + rhs1 = gimple_assign_rhs1(def_stmt);
115599 + rhs2 = gimple_assign_rhs2(def_stmt);
115600 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
115601 + return false;
115602 +
115603 + if (is_gimple_constant(rhs2))
115604 + not_const_rhs = rhs1;
115605 + else
115606 + not_const_rhs = rhs2;
115607 +
115608 + return no_uses(not_const_rhs);
115609 +}
115610 +
115611 +static bool skip_lhs_cast_check(const_gimple stmt)
115612 +{
115613 + const_tree rhs = gimple_assign_rhs1(stmt);
115614 + const_gimple def_stmt = get_def_stmt(rhs);
115615 +
115616 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
115617 + if (gimple_code(def_stmt) == GIMPLE_ASM)
115618 + return true;
115619 +
115620 + if (is_const_plus_unsigned_signed_truncation(rhs))
115621 + return true;
115622 +
115623 + return false;
115624 +}
115625 +
115626 +static tree create_cast_overflow_check(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
115627 +{
115628 + bool cast_lhs, cast_rhs;
115629 + tree lhs = gimple_assign_lhs(stmt);
115630 + tree rhs = gimple_assign_rhs1(stmt);
115631 + const_tree lhs_type = TREE_TYPE(lhs);
115632 + const_tree rhs_type = TREE_TYPE(rhs);
115633 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
115634 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
115635 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
115636 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
115637 +
115638 + static bool check_lhs[3][4] = {
115639 + // ss su us uu
115640 + { false, true, true, false }, // lhs > rhs
115641 + { false, false, false, false }, // lhs = rhs
115642 + { true, true, true, true }, // lhs < rhs
115643 + };
115644 +
115645 + static bool check_rhs[3][4] = {
115646 + // ss su us uu
115647 + { true, false, true, true }, // lhs > rhs
115648 + { true, false, true, true }, // lhs = rhs
115649 + { true, false, true, true }, // lhs < rhs
115650 + };
115651 +
115652 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
115653 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
115654 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115655 +
115656 + if (lhs_size > rhs_size) {
115657 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115658 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115659 + } else if (lhs_size == rhs_size) {
115660 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115661 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115662 + } else {
115663 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115664 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
115665 + }
115666 +
115667 + if (!cast_lhs && !cast_rhs)
115668 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115669 +
115670 + if (cast_lhs && !skip_lhs_cast_check(stmt))
115671 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
115672 +
115673 + if (cast_rhs)
115674 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
115675 +
115676 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115677 +}
115678 +
115679 +static tree handle_unary_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
115680 +{
115681 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
115682 +
115683 + if (get_stmt_flag(stmt) == MY_STMT)
115684 + return lhs;
115685 +
115686 + rhs1 = gimple_assign_rhs1(stmt);
115687 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
115688 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115689 +
115690 + new_rhs1 = expand(visited, caller_node, rhs1);
115691 +
115692 + if (new_rhs1 == NULL_TREE)
115693 + return create_cast_assign(visited, stmt);
115694 +
115695 + if (get_stmt_flag(stmt) == NO_CAST_CHECK)
115696 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115697 +
115698 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
115699 + tree size_overflow_type = get_size_overflow_type(stmt, rhs1);
115700 +
115701 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
115702 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
115703 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115704 + }
115705 +
115706 + if (!gimple_assign_cast_p(stmt))
115707 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
115708 +
115709 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
115710 +}
115711 +
115712 +static tree handle_unary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
115713 +{
115714 + tree rhs1, lhs = gimple_assign_lhs(stmt);
115715 + gimple def_stmt = get_def_stmt(lhs);
115716 +
115717 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
115718 + rhs1 = gimple_assign_rhs1(def_stmt);
115719 +
115720 + if (is_gimple_constant(rhs1))
115721 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115722 +
115723 + switch (TREE_CODE(rhs1)) {
115724 + case SSA_NAME:
115725 + return handle_unary_rhs(visited, caller_node, def_stmt);
115726 + case ARRAY_REF:
115727 + case BIT_FIELD_REF:
115728 + case ADDR_EXPR:
115729 + case COMPONENT_REF:
115730 + case INDIRECT_REF:
115731 +#if BUILDING_GCC_VERSION >= 4006
115732 + case MEM_REF:
115733 +#endif
115734 + case TARGET_MEM_REF:
115735 + case VIEW_CONVERT_EXPR:
115736 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
115737 + case PARM_DECL:
115738 + case VAR_DECL:
115739 + return create_assign(visited, stmt, lhs, AFTER_STMT);
115740 +
115741 + default:
115742 + debug_gimple_stmt(def_stmt);
115743 + debug_tree(rhs1);
115744 + gcc_unreachable();
115745 + }
115746 +}
115747 +
115748 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
115749 +{
115750 + gimple cond_stmt;
115751 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
115752 +
115753 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
115754 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
115755 + update_stmt(cond_stmt);
115756 +}
115757 +
115758 +static tree create_string_param(tree string)
115759 +{
115760 + tree i_type, a_type;
115761 + const int length = TREE_STRING_LENGTH(string);
115762 +
115763 + gcc_assert(length > 0);
115764 +
115765 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
115766 + a_type = build_array_type(char_type_node, i_type);
115767 +
115768 + TREE_TYPE(string) = a_type;
115769 + TREE_CONSTANT(string) = 1;
115770 + TREE_READONLY(string) = 1;
115771 +
115772 + return build1(ADDR_EXPR, ptr_type_node, string);
115773 +}
115774 +
115775 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
115776 +{
115777 + gimple func_stmt;
115778 + const_gimple def_stmt;
115779 + const_tree loc_line;
115780 + tree loc_file, ssa_name, current_func;
115781 + expanded_location xloc;
115782 + char *ssa_name_buf;
115783 + int len;
115784 + struct cgraph_edge *edge;
115785 + struct cgraph_node *callee_node;
115786 + int frequency;
115787 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
115788 +
115789 + def_stmt = get_def_stmt(arg);
115790 + xloc = expand_location(gimple_location(def_stmt));
115791 +
115792 + if (!gimple_has_location(def_stmt)) {
115793 + xloc = expand_location(gimple_location(stmt));
115794 + if (!gimple_has_location(stmt))
115795 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
115796 + }
115797 +
115798 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
115799 +
115800 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
115801 + loc_file = create_string_param(loc_file);
115802 +
115803 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
115804 + current_func = create_string_param(current_func);
115805 +
115806 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
115807 + call_count++;
115808 + 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);
115809 + gcc_assert(len > 0);
115810 + ssa_name = build_string(len + 1, ssa_name_buf);
115811 + free(ssa_name_buf);
115812 + ssa_name = create_string_param(ssa_name);
115813 +
115814 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
115815 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
115816 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
115817 +
115818 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
115819 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
115820 +
115821 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
115822 + gcc_assert(edge != NULL);
115823 +}
115824 +
115825 +static void __unused print_the_code_insertions(const_gimple stmt)
115826 +{
115827 + location_t loc = gimple_location(stmt);
115828 +
115829 + inform(loc, "Integer size_overflow check applied here.");
115830 +}
115831 +
115832 +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)
115833 +{
115834 + basic_block cond_bb, join_bb, bb_true;
115835 + edge e;
115836 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
115837 +
115838 + cond_bb = gimple_bb(stmt);
115839 + if (before)
115840 + gsi_prev(&gsi);
115841 + if (gsi_end_p(gsi))
115842 + e = split_block_after_labels(cond_bb);
115843 + else
115844 + e = split_block(cond_bb, gsi_stmt(gsi));
115845 + cond_bb = e->src;
115846 + join_bb = e->dest;
115847 + e->flags = EDGE_FALSE_VALUE;
115848 + e->probability = REG_BR_PROB_BASE;
115849 +
115850 + bb_true = create_empty_bb(cond_bb);
115851 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
115852 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
115853 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
115854 +
115855 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
115856 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
115857 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
115858 +
115859 + if (current_loops != NULL) {
115860 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
115861 + add_bb_to_loop(bb_true, cond_bb->loop_father);
115862 + }
115863 +
115864 + insert_cond(cond_bb, arg, cond_code, type_value);
115865 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
115866 +
115867 +// print_the_code_insertions(stmt);
115868 +}
115869 +
115870 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
115871 +{
115872 + const_tree rhs_type = TREE_TYPE(rhs);
115873 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
115874 +
115875 + gcc_assert(rhs_type != NULL_TREE);
115876 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
115877 + return;
115878 +
115879 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
115880 +
115881 + if (is_const_plus_unsigned_signed_truncation(rhs))
115882 + return;
115883 +
115884 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
115885 + // typemax (-1) < typemin (0)
115886 + if (TREE_OVERFLOW(type_max))
115887 + return;
115888 +
115889 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
115890 +
115891 + cast_rhs_type = TREE_TYPE(cast_rhs);
115892 + type_max_type = TREE_TYPE(type_max);
115893 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
115894 +
115895 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
115896 +
115897 + // special case: get_size_overflow_type(), 32, u64->s
115898 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
115899 + return;
115900 +
115901 + type_min_type = TREE_TYPE(type_min);
115902 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
115903 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
115904 +}
115905 +
115906 +static bool is_lt_signed_type_max(const_tree rhs)
115907 +{
115908 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
115909 +
115910 + if (!TYPE_UNSIGNED(type))
115911 + return true;
115912 +
115913 + switch (TYPE_MODE(type)) {
115914 + case QImode:
115915 + new_type = intQI_type_node;
115916 + break;
115917 + case HImode:
115918 + new_type = intHI_type_node;
115919 + break;
115920 + case SImode:
115921 + new_type = intSI_type_node;
115922 + break;
115923 + case DImode:
115924 + new_type = intDI_type_node;
115925 + break;
115926 + default:
115927 + debug_tree((tree)type);
115928 + gcc_unreachable();
115929 + }
115930 +
115931 + type_max = TYPE_MAX_VALUE(new_type);
115932 + if (!tree_int_cst_lt(type_max, rhs))
115933 + return true;
115934 +
115935 + return false;
115936 +}
115937 +
115938 +static bool is_gt_zero(const_tree rhs)
115939 +{
115940 + const_tree type = TREE_TYPE(rhs);
115941 +
115942 + if (TYPE_UNSIGNED(type))
115943 + return true;
115944 +
115945 + if (!tree_int_cst_lt(rhs, integer_zero_node))
115946 + return true;
115947 +
115948 + return false;
115949 +}
115950 +
115951 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
115952 +{
115953 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
115954 + return false;
115955 + if (!is_gimple_constant(rhs))
115956 + return false;
115957 +
115958 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
115959 +// if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
115960 +// return false;
115961 +
115962 + return true;
115963 +}
115964 +
115965 +static tree get_def_stmt_rhs(const_tree var)
115966 +{
115967 + tree rhs1, def_stmt_rhs1;
115968 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
115969 +
115970 + def_stmt = get_def_stmt(var);
115971 + if (!gimple_assign_cast_p(def_stmt))
115972 + return NULL_TREE;
115973 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && get_stmt_flag(def_stmt) == MY_STMT && gimple_assign_cast_p(def_stmt));
115974 +
115975 + rhs1 = gimple_assign_rhs1(def_stmt);
115976 + rhs1_def_stmt = get_def_stmt(rhs1);
115977 + if (!gimple_assign_cast_p(rhs1_def_stmt))
115978 + return rhs1;
115979 +
115980 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
115981 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
115982 +
115983 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
115984 + case GIMPLE_CALL:
115985 + case GIMPLE_NOP:
115986 + case GIMPLE_ASM:
115987 + case GIMPLE_PHI:
115988 + return def_stmt_rhs1;
115989 + case GIMPLE_ASSIGN:
115990 + return rhs1;
115991 + default:
115992 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
115993 + gcc_unreachable();
115994 + }
115995 +}
115996 +
115997 +static tree handle_intentional_overflow(struct pointer_set_t *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
115998 +{
115999 + tree new_rhs, orig_rhs;
116000 + void (*gimple_assign_set_rhs)(gimple, tree);
116001 + tree rhs1 = gimple_assign_rhs1(stmt);
116002 + tree rhs2 = gimple_assign_rhs2(stmt);
116003 + tree lhs = gimple_assign_lhs(stmt);
116004 +
116005 + if (!check_overflow)
116006 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116007 +
116008 + if (change_rhs == NULL_TREE)
116009 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116010 +
116011 + if (new_rhs2 == NULL_TREE) {
116012 + orig_rhs = rhs1;
116013 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
116014 + } else {
116015 + orig_rhs = rhs2;
116016 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
116017 + }
116018 +
116019 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
116020 +
116021 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
116022 + gimple_assign_set_rhs(stmt, new_rhs);
116023 + update_stmt(stmt);
116024 +
116025 + return create_assign(visited, stmt, lhs, AFTER_STMT);
116026 +}
116027 +
116028 +static bool is_subtraction_special(const_gimple stmt)
116029 +{
116030 + gimple rhs1_def_stmt, rhs2_def_stmt;
116031 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
116032 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
116033 + const_tree rhs1 = gimple_assign_rhs1(stmt);
116034 + const_tree rhs2 = gimple_assign_rhs2(stmt);
116035 +
116036 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
116037 + return false;
116038 +
116039 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
116040 +
116041 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116042 + return false;
116043 +
116044 + rhs1_def_stmt = get_def_stmt(rhs1);
116045 + rhs2_def_stmt = get_def_stmt(rhs2);
116046 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
116047 + return false;
116048 +
116049 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
116050 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
116051 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
116052 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
116053 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
116054 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
116055 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
116056 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
116057 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
116058 + return false;
116059 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
116060 + return false;
116061 +
116062 + set_stmt_flag(rhs1_def_stmt, NO_CAST_CHECK);
116063 + set_stmt_flag(rhs2_def_stmt, NO_CAST_CHECK);
116064 + return true;
116065 +}
116066 +
116067 +static tree handle_integer_truncation(struct pointer_set_t *visited, struct cgraph_node *caller_node, const_tree lhs)
116068 +{
116069 + tree new_rhs1, new_rhs2;
116070 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
116071 + gimple assign, stmt = get_def_stmt(lhs);
116072 + tree rhs1 = gimple_assign_rhs1(stmt);
116073 + tree rhs2 = gimple_assign_rhs2(stmt);
116074 +
116075 + if (!is_subtraction_special(stmt))
116076 + return NULL_TREE;
116077 +
116078 + new_rhs1 = expand(visited, caller_node, rhs1);
116079 + new_rhs2 = expand(visited, caller_node, rhs2);
116080 +
116081 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
116082 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
116083 +
116084 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
116085 + return NULL_TREE;
116086 +
116087 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
116088 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
116089 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
116090 + }
116091 +
116092 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
116093 + new_lhs = gimple_assign_lhs(assign);
116094 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
116095 +
116096 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116097 +}
116098 +
116099 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
116100 +{
116101 + const_gimple def_stmt;
116102 +
116103 + if (TREE_CODE(rhs) != SSA_NAME)
116104 + return false;
116105 +
116106 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
116107 + return false;
116108 +
116109 + def_stmt = get_def_stmt(rhs);
116110 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
116111 + return false;
116112 +
116113 + return true;
116114 +}
116115 +
116116 +static tree handle_binary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116117 +{
116118 + tree rhs1, rhs2, new_lhs;
116119 + gimple def_stmt = get_def_stmt(lhs);
116120 + tree new_rhs1 = NULL_TREE;
116121 + tree new_rhs2 = NULL_TREE;
116122 +
116123 + rhs1 = gimple_assign_rhs1(def_stmt);
116124 + rhs2 = gimple_assign_rhs2(def_stmt);
116125 +
116126 + /* no DImode/TImode division in the 32/64 bit kernel */
116127 + switch (gimple_assign_rhs_code(def_stmt)) {
116128 + case RDIV_EXPR:
116129 + case TRUNC_DIV_EXPR:
116130 + case CEIL_DIV_EXPR:
116131 + case FLOOR_DIV_EXPR:
116132 + case ROUND_DIV_EXPR:
116133 + case TRUNC_MOD_EXPR:
116134 + case CEIL_MOD_EXPR:
116135 + case FLOOR_MOD_EXPR:
116136 + case ROUND_MOD_EXPR:
116137 + case EXACT_DIV_EXPR:
116138 + case POINTER_PLUS_EXPR:
116139 + case BIT_AND_EXPR:
116140 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116141 + default:
116142 + break;
116143 + }
116144 +
116145 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
116146 + if (new_lhs != NULL_TREE)
116147 + return new_lhs;
116148 +
116149 + if (TREE_CODE(rhs1) == SSA_NAME)
116150 + new_rhs1 = expand(visited, caller_node, rhs1);
116151 + if (TREE_CODE(rhs2) == SSA_NAME)
116152 + new_rhs2 = expand(visited, caller_node, rhs2);
116153 +
116154 + if (is_a_neg_overflow(def_stmt, rhs2))
116155 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
116156 + if (is_a_neg_overflow(def_stmt, rhs1))
116157 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
116158 +
116159 +
116160 + if (is_a_constant_overflow(def_stmt, rhs2))
116161 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
116162 + if (is_a_constant_overflow(def_stmt, rhs1))
116163 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
116164 +
116165 + // the const is between 0 and (signed) MAX
116166 + if (is_gimple_constant(rhs1))
116167 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
116168 + if (is_gimple_constant(rhs2))
116169 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
116170 +
116171 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
116172 +}
116173 +
116174 +#if BUILDING_GCC_VERSION >= 4006
116175 +static tree get_new_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
116176 +{
116177 + if (is_gimple_constant(rhs))
116178 + return cast_a_tree(size_overflow_type, rhs);
116179 + if (TREE_CODE(rhs) != SSA_NAME)
116180 + return NULL_TREE;
116181 + return expand(visited, caller_node, rhs);
116182 +}
116183 +
116184 +static tree handle_ternary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116185 +{
116186 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
116187 + gimple def_stmt = get_def_stmt(lhs);
116188 +
116189 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
116190 +
116191 + rhs1 = gimple_assign_rhs1(def_stmt);
116192 + rhs2 = gimple_assign_rhs2(def_stmt);
116193 + rhs3 = gimple_assign_rhs3(def_stmt);
116194 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
116195 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
116196 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
116197 +
116198 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
116199 +}
116200 +#endif
116201 +
116202 +static tree get_size_overflow_type(gimple stmt, const_tree node)
116203 +{
116204 + const_tree type;
116205 + tree new_type;
116206 +
116207 + gcc_assert(node != NULL_TREE);
116208 +
116209 + type = TREE_TYPE(node);
116210 +
116211 + if (get_stmt_flag(stmt) == MY_STMT)
116212 + return TREE_TYPE(node);
116213 +
116214 + switch (TYPE_MODE(type)) {
116215 + case QImode:
116216 + new_type = intHI_type_node;
116217 + break;
116218 + case HImode:
116219 + new_type = intSI_type_node;
116220 + break;
116221 + case SImode:
116222 + new_type = intDI_type_node;
116223 + break;
116224 + case DImode:
116225 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
116226 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
116227 + else
116228 + new_type = intTI_type_node;
116229 + break;
116230 + case TImode:
116231 + gcc_assert(!TYPE_UNSIGNED(type));
116232 + new_type = intTI_type_node;
116233 + break;
116234 + default:
116235 + debug_tree((tree)node);
116236 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
116237 + gcc_unreachable();
116238 + }
116239 +
116240 + if (TYPE_QUALS(type) != 0)
116241 + return build_qualified_type(new_type, TYPE_QUALS(type));
116242 + return new_type;
116243 +}
116244 +
116245 +static tree expand_visited(gimple def_stmt)
116246 +{
116247 + const_gimple next_stmt;
116248 + gimple_stmt_iterator gsi;
116249 + enum gimple_code code = gimple_code(def_stmt);
116250 +
116251 + if (code == GIMPLE_ASM)
116252 + return NULL_TREE;
116253 +
116254 + gsi = gsi_for_stmt(def_stmt);
116255 + gsi_next(&gsi);
116256 +
116257 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
116258 + return NULL_TREE;
116259 + gcc_assert(!gsi_end_p(gsi));
116260 + next_stmt = gsi_stmt(gsi);
116261 +
116262 + if (gimple_code(def_stmt) == GIMPLE_PHI && get_stmt_flag((gimple)next_stmt) != MY_STMT)
116263 + return NULL_TREE;
116264 + gcc_assert(get_stmt_flag((gimple)next_stmt) == MY_STMT);
116265 +
116266 + return get_lhs(next_stmt);
116267 +}
116268 +
116269 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
116270 +{
116271 + gimple def_stmt;
116272 +
116273 + def_stmt = get_def_stmt(lhs);
116274 +
116275 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
116276 + return NULL_TREE;
116277 +
116278 + if (get_stmt_flag(def_stmt) == MY_STMT)
116279 + return lhs;
116280 +
116281 + if (pointer_set_contains(visited, def_stmt))
116282 + return expand_visited(def_stmt);
116283 +
116284 + switch (gimple_code(def_stmt)) {
116285 + case GIMPLE_PHI:
116286 + return handle_phi(visited, caller_node, lhs);
116287 + case GIMPLE_CALL:
116288 + case GIMPLE_ASM:
116289 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
116290 + case GIMPLE_ASSIGN:
116291 + switch (gimple_num_ops(def_stmt)) {
116292 + case 2:
116293 + return handle_unary_ops(visited, caller_node, def_stmt);
116294 + case 3:
116295 + return handle_binary_ops(visited, caller_node, lhs);
116296 +#if BUILDING_GCC_VERSION >= 4006
116297 + case 4:
116298 + return handle_ternary_ops(visited, caller_node, lhs);
116299 +#endif
116300 + }
116301 + default:
116302 + debug_gimple_stmt(def_stmt);
116303 + error("%s: unknown gimple code", __func__);
116304 + gcc_unreachable();
116305 + }
116306 +}
116307 +
116308 +static tree cast_to_orig_type(gimple stmt, const_tree orig_node, tree new_node)
116309 +{
116310 + const_gimple assign;
116311 + tree orig_type = TREE_TYPE(orig_node);
116312 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
116313 +
116314 + assign = build_cast_stmt(orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
116315 + return gimple_assign_lhs(assign);
116316 +}
116317 +
116318 +static void change_orig_node(struct interesting_node *cur_node, tree new_node)
116319 +{
116320 + void (*set_rhs)(gimple, tree);
116321 + gimple stmt = cur_node->first_stmt;
116322 + const_tree orig_node = cur_node->node;
116323 +
116324 + switch (gimple_code(stmt)) {
116325 + case GIMPLE_RETURN:
116326 + gimple_return_set_retval(stmt, cast_to_orig_type(stmt, orig_node, new_node));
116327 + break;
116328 + case GIMPLE_CALL:
116329 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(stmt, orig_node, new_node));
116330 + break;
116331 + case GIMPLE_ASSIGN:
116332 + switch (cur_node->num) {
116333 + case 1:
116334 + set_rhs = &gimple_assign_set_rhs1;
116335 + break;
116336 + case 2:
116337 + set_rhs = &gimple_assign_set_rhs2;
116338 + break;
116339 +#if BUILDING_GCC_VERSION >= 4006
116340 + case 3:
116341 + set_rhs = &gimple_assign_set_rhs3;
116342 + break;
116343 +#endif
116344 + default:
116345 + gcc_unreachable();
116346 + }
116347 +
116348 + set_rhs(stmt, cast_to_orig_type(stmt, orig_node, new_node));
116349 + break;
116350 + default:
116351 + debug_gimple_stmt(stmt);
116352 + gcc_unreachable();
116353 + }
116354 +
116355 + update_stmt(stmt);
116356 +}
116357 +
116358 +static unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
116359 +{
116360 + const struct size_overflow_hash *hash;
116361 + unsigned int new_argnum;
116362 + tree arg;
116363 + const_tree origarg;
116364 +
116365 + if (argnum == 0)
116366 + return argnum;
116367 +
116368 + hash = get_function_hash(fndecl);
116369 + if (hash && hash->param & (1U << argnum))
116370 + return argnum;
116371 +
116372 + if (DECL_EXTERNAL(fndecl))
116373 + return argnum;
116374 +
116375 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
116376 + argnum--;
116377 + while (origarg && argnum) {
116378 + origarg = TREE_CHAIN(origarg);
116379 + argnum--;
116380 + }
116381 + gcc_assert(argnum == 0);
116382 + gcc_assert(origarg != NULL_TREE);
116383 +
116384 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
116385 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
116386 + return new_argnum;
116387 +
116388 + return CANNOT_FIND_ARG;
116389 +}
116390 +
116391 +// Don't want to duplicate entries in next_cgraph_node
116392 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
116393 +{
116394 + const_tree new_callee_fndecl;
116395 + struct next_cgraph_node *cur_node;
116396 +
116397 + if (fndecl == RET_CHECK)
116398 + new_callee_fndecl = NODE_DECL(node);
116399 + else
116400 + new_callee_fndecl = fndecl;
116401 +
116402 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
116403 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
116404 + continue;
116405 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
116406 + continue;
116407 + if (num == cur_node->num)
116408 + return true;
116409 + }
116410 + return false;
116411 +}
116412 +
116413 +/* Add a next_cgraph_node into the list for handle_function().
116414 + * handle_function() iterates over all the next cgraph nodes and
116415 + * starts the overflow check insertion process.
116416 + */
116417 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
116418 +{
116419 + struct next_cgraph_node *new_node;
116420 +
116421 + if (is_in_next_cgraph_node(head, node, fndecl, num))
116422 + return head;
116423 +
116424 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
116425 + new_node->current_function = node;
116426 + new_node->next = NULL;
116427 + new_node->num = num;
116428 + if (fndecl == RET_CHECK)
116429 + new_node->callee_fndecl = NODE_DECL(node);
116430 + else
116431 + new_node->callee_fndecl = fndecl;
116432 +
116433 + if (!head)
116434 + return new_node;
116435 +
116436 + new_node->next = head;
116437 + return new_node;
116438 +}
116439 +
116440 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
116441 +{
116442 + struct cgraph_edge *e;
116443 +
116444 + if (num == 0)
116445 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
116446 +
116447 + for (e = node->callers; e; e = e->next_caller) {
116448 + tree fndecl = gimple_call_fndecl(e->call_stmt);
116449 +
116450 + gcc_assert(fndecl != NULL_TREE);
116451 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
116452 + }
116453 +
116454 + return head;
116455 +}
116456 +
116457 +static bool is_a_return_check(const_tree node)
116458 +{
116459 + if (TREE_CODE(node) == FUNCTION_DECL)
116460 + return true;
116461 +
116462 + gcc_assert(TREE_CODE(node) == PARM_DECL);
116463 + return false;
116464 +}
116465 +
116466 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
116467 +{
116468 + const struct size_overflow_hash *hash;
116469 +
116470 + hash = get_function_hash(fndecl);
116471 + if (hash && (hash->param & (1U << num)))
116472 + return true;
116473 + return false;
116474 +}
116475 +
116476 +struct missing_functions {
116477 + struct missing_functions *next;
116478 + const_tree node;
116479 + tree fndecl;
116480 +};
116481 +
116482 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
116483 +{
116484 + struct missing_functions *new_function;
116485 +
116486 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
116487 + new_function->node = node;
116488 + new_function->next = NULL;
116489 +
116490 + if (TREE_CODE(node) == FUNCTION_DECL)
116491 + new_function->fndecl = node;
116492 + else
116493 + new_function->fndecl = current_function_decl;
116494 + gcc_assert(new_function->fndecl);
116495 +
116496 + if (!missing_fn_head)
116497 + return new_function;
116498 +
116499 + new_function->next = missing_fn_head;
116500 + return new_function;
116501 +}
116502 +
116503 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
116504 + * If the function is missing everywhere then print the missing message into stderr.
116505 + */
116506 +static bool is_missing_function(const_tree orig_fndecl, unsigned int num)
116507 +{
116508 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
116509 +#if BUILDING_GCC_VERSION >= 4008
116510 + case BUILT_IN_BSWAP16:
116511 +#endif
116512 + case BUILT_IN_BSWAP32:
116513 + case BUILT_IN_BSWAP64:
116514 + case BUILT_IN_EXPECT:
116515 + case BUILT_IN_MEMCMP:
116516 + return false;
116517 + default:
116518 + break;
116519 + }
116520 +
116521 + // skip test.c
116522 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
116523 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
116524 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
116525 + }
116526 +
116527 + if (is_in_hash_table(orig_fndecl, num))
116528 + return false;
116529 +
116530 + print_missing_msg(orig_fndecl, num);
116531 + return true;
116532 +}
116533 +
116534 +// Get the argnum of a function decl, if node is a return then the argnum is 0
116535 +static unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
116536 +{
116537 + if (is_a_return_check(node))
116538 + return 0;
116539 + else
116540 + return find_arg_number_tree(node, orig_fndecl);
116541 +}
116542 +
116543 +/* If the function is missing from the hash table and it is a static function
116544 + * then create a next_cgraph_node from it for handle_function()
116545 + */
116546 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
116547 +{
116548 + unsigned int num;
116549 + const_tree orig_fndecl;
116550 + struct cgraph_node *next_node = NULL;
116551 +
116552 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
116553 +
116554 + num = get_function_num(missing_fn_head->node, orig_fndecl);
116555 + if (num == CANNOT_FIND_ARG)
116556 + return cnodes;
116557 +
116558 + if (!is_missing_function(orig_fndecl, num))
116559 + return cnodes;
116560 +
116561 + next_node = cgraph_get_node(missing_fn_head->fndecl);
116562 + if (next_node && next_node->local.local)
116563 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
116564 + return cnodes;
116565 +}
116566 +
116567 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
116568 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
116569 + */
116570 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
116571 +{
116572 + unsigned int i;
116573 + tree node;
116574 + struct missing_functions *cur, *missing_fn_head = NULL;
116575 +
116576 +#if BUILDING_GCC_VERSION <= 4007
116577 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
116578 +#else
116579 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
116580 +#endif
116581 + switch (TREE_CODE(node)) {
116582 + case PARM_DECL:
116583 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
116584 + break;
116585 + case FUNCTION_DECL:
116586 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
116587 + break;
116588 + default:
116589 + break;
116590 + }
116591 + }
116592 +
116593 + while (missing_fn_head) {
116594 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
116595 +
116596 + cur = missing_fn_head->next;
116597 + free(missing_fn_head);
116598 + missing_fn_head = cur;
116599 + }
116600 +
116601 + return cnodes;
116602 +}
116603 +
116604 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
116605 +{
116606 + gimple phi = get_def_stmt(result);
116607 + unsigned int i, n = gimple_phi_num_args(phi);
116608 +
116609 + pointer_set_insert(visited, phi);
116610 + for (i = 0; i < n; i++) {
116611 + const_tree arg = gimple_phi_arg_def(phi, i);
116612 +
116613 + set_conditions(visited, interesting_conditions, arg);
116614 + }
116615 +}
116616 +
116617 +enum conditions {
116618 + FROM_CONST, NOT_UNARY, CAST
116619 +};
116620 +
116621 +// Search for constants, cast assignments and binary/ternary assignments
116622 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
116623 +{
116624 + gimple def_stmt = get_def_stmt(lhs);
116625 +
116626 + if (is_gimple_constant(lhs)) {
116627 + interesting_conditions[FROM_CONST] = true;
116628 + return;
116629 + }
116630 +
116631 + if (!def_stmt)
116632 + return;
116633 +
116634 + if (pointer_set_contains(visited, def_stmt))
116635 + return;
116636 +
116637 + switch (gimple_code(def_stmt)) {
116638 + case GIMPLE_NOP:
116639 + case GIMPLE_CALL:
116640 + case GIMPLE_ASM:
116641 + return;
116642 + case GIMPLE_PHI:
116643 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
116644 + case GIMPLE_ASSIGN:
116645 + if (gimple_num_ops(def_stmt) == 2) {
116646 + const_tree rhs = gimple_assign_rhs1(def_stmt);
116647 +
116648 + if (gimple_assign_cast_p(def_stmt))
116649 + interesting_conditions[CAST] = true;
116650 +
116651 + return set_conditions(visited, interesting_conditions, rhs);
116652 + } else {
116653 + interesting_conditions[NOT_UNARY] = true;
116654 + return;
116655 + }
116656 + default:
116657 + debug_gimple_stmt(def_stmt);
116658 + gcc_unreachable();
116659 + }
116660 +}
116661 +
116662 +// determine whether duplication will be necessary or not.
116663 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
116664 +{
116665 + struct pointer_set_t *visited;
116666 +
116667 + if (gimple_assign_cast_p(cur_node->first_stmt))
116668 + interesting_conditions[CAST] = true;
116669 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
116670 + interesting_conditions[NOT_UNARY] = true;
116671 +
116672 + visited = pointer_set_create();
116673 + set_conditions(visited, interesting_conditions, cur_node->node);
116674 + pointer_set_destroy(visited);
116675 +}
116676 +
116677 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
116678 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
116679 +{
116680 + gimple assign;
116681 + gimple_stmt_iterator gsi;
116682 +
116683 + // already removed
116684 + if (gimple_bb(asm_stmt) == NULL)
116685 + return;
116686 + gsi = gsi_for_stmt(asm_stmt);
116687 +
116688 + assign = gimple_build_assign(lhs, rhs);
116689 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
116690 + SSA_NAME_DEF_STMT(lhs) = assign;
116691 +
116692 + gsi_remove(&gsi, true);
116693 +}
116694 +
116695 +// Get the field decl of a component ref for intentional_overflow checking
116696 +static const_tree search_field_decl(const_tree comp_ref)
116697 +{
116698 + const_tree field = NULL_TREE;
116699 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
116700 +
116701 + for (i = 0; i < len; i++) {
116702 + field = TREE_OPERAND(comp_ref, i);
116703 + if (TREE_CODE(field) == FIELD_DECL)
116704 + break;
116705 + }
116706 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
116707 + return field;
116708 +}
116709 +
116710 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
116711 + * stmt is a return otherwise it is the callee function.
116712 + */
116713 +static const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
116714 +{
116715 + const_tree fndecl;
116716 +
116717 + if (argnum == 0)
116718 + fndecl = current_function_decl;
116719 + else
116720 + fndecl = gimple_call_fndecl(stmt);
116721 +
116722 + if (fndecl == NULL_TREE)
116723 + return NULL_TREE;
116724 +
116725 + return DECL_ORIGIN(fndecl);
116726 +}
116727 +
116728 +/* Get the param of the intentional_overflow attribute.
116729 + * * 0: MARK_NOT_INTENTIONAL
116730 + * * 1..MAX_PARAM: MARK_YES
116731 + * * -1: MARK_TURN_OFF
116732 + */
116733 +static tree get_attribute_param(const_tree decl)
116734 +{
116735 + const_tree attr;
116736 +
116737 + if (decl == NULL_TREE)
116738 + return NULL_TREE;
116739 +
116740 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
116741 + if (!attr || !TREE_VALUE(attr))
116742 + return NULL_TREE;
116743 +
116744 + return TREE_VALUE(attr);
116745 +}
116746 +
116747 +// MARK_TURN_OFF
116748 +static bool is_turn_off_intentional_attr(const_tree decl)
116749 +{
116750 + const_tree param_head;
116751 +
116752 + param_head = get_attribute_param(decl);
116753 + if (param_head == NULL_TREE)
116754 + return false;
116755 +
116756 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
116757 + return true;
116758 + return false;
116759 +}
116760 +
116761 +// MARK_NOT_INTENTIONAL
116762 +static bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
116763 +{
116764 + const_tree param_head;
116765 +
116766 + if (argnum == 0)
116767 + return false;
116768 +
116769 + param_head = get_attribute_param(decl);
116770 + if (param_head == NULL_TREE)
116771 + return false;
116772 +
116773 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
116774 + return true;
116775 + return false;
116776 +}
116777 +
116778 +// MARK_YES
116779 +static bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
116780 +{
116781 + tree param, param_head;
116782 +
116783 + if (argnum == 0)
116784 + return false;
116785 +
116786 + param_head = get_attribute_param(decl);
116787 + for (param = param_head; param; param = TREE_CHAIN(param))
116788 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
116789 + return true;
116790 + return false;
116791 +}
116792 +
116793 +static const char *get_asm_string(const_gimple stmt)
116794 +{
116795 + if (!stmt)
116796 + return NULL;
116797 + if (gimple_code(stmt) != GIMPLE_ASM)
116798 + return NULL;
116799 +
116800 + return gimple_asm_string(stmt);
116801 +}
116802 +
116803 +static bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
116804 +{
116805 + const char *str;
116806 +
116807 + str = get_asm_string(stmt);
116808 + if (!str)
116809 + return false;
116810 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
116811 +}
116812 +
116813 +static bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
116814 +{
116815 + const char *str;
116816 +
116817 + str = get_asm_string(stmt);
116818 + if (!str)
116819 + return false;
116820 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
116821 +}
116822 +
116823 +static bool is_size_overflow_asm(const_gimple stmt)
116824 +{
116825 + const char *str;
116826 +
116827 + str = get_asm_string(stmt);
116828 + if (!str)
116829 + return false;
116830 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
116831 +}
116832 +
116833 +static void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
116834 +{
116835 + location_t loc;
116836 +
116837 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
116838 + return;
116839 +
116840 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
116841 + return;
116842 +
116843 + loc = DECL_SOURCE_LOCATION(decl);
116844 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
116845 +}
116846 +
116847 +/* Get the type of the intentional_overflow attribute of a node
116848 + * * MARK_TURN_OFF
116849 + * * MARK_YES
116850 + * * MARK_NO
116851 + * * MARK_NOT_INTENTIONAL
116852 + */
116853 +static enum mark get_intentional_attr_type(const_tree node)
116854 +{
116855 + const_tree cur_decl;
116856 +
116857 + if (node == NULL_TREE)
116858 + return MARK_NO;
116859 +
116860 + switch (TREE_CODE(node)) {
116861 + case COMPONENT_REF:
116862 + cur_decl = search_field_decl(node);
116863 + if (is_turn_off_intentional_attr(cur_decl))
116864 + return MARK_TURN_OFF;
116865 + if (is_end_intentional_intentional_attr(cur_decl, 1))
116866 + return MARK_YES;
116867 + break;
116868 + case PARM_DECL: {
116869 + unsigned int argnum;
116870 +
116871 + cur_decl = DECL_ORIGIN(current_function_decl);
116872 + argnum = find_arg_number_tree(node, cur_decl);
116873 + if (argnum == CANNOT_FIND_ARG)
116874 + return MARK_NO;
116875 + if (is_yes_intentional_attr(cur_decl, argnum))
116876 + return MARK_YES;
116877 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
116878 + return MARK_NOT_INTENTIONAL;
116879 + break;
116880 + }
116881 + case FUNCTION_DECL:
116882 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
116883 + return MARK_TURN_OFF;
116884 + break;
116885 + default:
116886 + break;
116887 + }
116888 + return MARK_NO;
116889 +}
116890 +
116891 +// Search for the intentional_overflow attribute on the last nodes
116892 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
116893 +{
116894 + unsigned int i;
116895 + tree last_node;
116896 + enum mark mark = MARK_NO;
116897 +
116898 +#if BUILDING_GCC_VERSION <= 4007
116899 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
116900 +#else
116901 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
116902 +#endif
116903 + mark = get_intentional_attr_type(last_node);
116904 + if (mark != MARK_NO)
116905 + break;
116906 + }
116907 + return mark;
116908 +}
116909 +
116910 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
116911 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
116912 + */
116913 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
116914 +{
116915 + if (!cur_node->intentional_mark_from_gimple)
116916 + return false;
116917 +
116918 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
116919 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
116920 + else
116921 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116922 +
116923 + // skip param decls
116924 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
116925 + return true;
116926 + return true;
116927 +}
116928 +
116929 +/* Search intentional_overflow attribute on caller and on callee too.
116930 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
116931 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
116932 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
116933 +*/
116934 +static void check_intentional_attribute_ipa(struct interesting_node *cur_node)
116935 +{
116936 + const_tree fndecl;
116937 +
116938 + if (is_intentional_attribute_from_gimple(cur_node))
116939 + return;
116940 +
116941 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
116942 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
116943 + return;
116944 + }
116945 +
116946 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
116947 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
116948 + return;
116949 + }
116950 +
116951 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
116952 + return;
116953 +
116954 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
116955 + if (is_turn_off_intentional_attr(fndecl)) {
116956 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
116957 + return;
116958 + }
116959 +
116960 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
116961 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
116962 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
116963 + cur_node->intentional_attr_decl = MARK_YES;
116964 +
116965 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
116966 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
116967 +}
116968 +
116969 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
116970 +static bool skip_asm(const_tree arg)
116971 +{
116972 + gimple def_stmt = get_def_stmt(arg);
116973 +
116974 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
116975 + return false;
116976 +
116977 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
116978 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
116979 +}
116980 +
116981 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
116982 +{
116983 + gimple phi = get_def_stmt(result);
116984 + unsigned int i, n = gimple_phi_num_args(phi);
116985 +
116986 + pointer_set_insert(visited, phi);
116987 + for (i = 0; i < n; i++) {
116988 + tree arg = gimple_phi_arg_def(phi, i);
116989 +
116990 + walk_use_def(visited, cur_node, arg);
116991 + }
116992 +}
116993 +
116994 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
116995 +{
116996 + gimple def_stmt = get_def_stmt(lhs);
116997 + tree rhs1, rhs2;
116998 +
116999 + rhs1 = gimple_assign_rhs1(def_stmt);
117000 + rhs2 = gimple_assign_rhs2(def_stmt);
117001 +
117002 + walk_use_def(visited, cur_node, rhs1);
117003 + walk_use_def(visited, cur_node, rhs2);
117004 +}
117005 +
117006 +static void insert_last_node(struct interesting_node *cur_node, tree node)
117007 +{
117008 + unsigned int i;
117009 + tree element;
117010 + enum tree_code code;
117011 +
117012 + gcc_assert(node != NULL_TREE);
117013 +
117014 + if (is_gimple_constant(node))
117015 + return;
117016 +
117017 + code = TREE_CODE(node);
117018 + if (code == VAR_DECL) {
117019 + node = DECL_ORIGIN(node);
117020 + code = TREE_CODE(node);
117021 + }
117022 +
117023 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
117024 + return;
117025 +
117026 +#if BUILDING_GCC_VERSION <= 4007
117027 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
117028 +#else
117029 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
117030 +#endif
117031 + if (operand_equal_p(node, element, 0))
117032 + return;
117033 + }
117034 +
117035 +#if BUILDING_GCC_VERSION <= 4007
117036 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
117037 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
117038 +#else
117039 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
117040 + vec_safe_push(cur_node->last_nodes, node);
117041 +#endif
117042 +}
117043 +
117044 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
117045 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
117046 +{
117047 + if (!is_size_overflow_asm(stmt))
117048 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
117049 +}
117050 +
117051 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
117052 + * and component refs (for checking the intentional_overflow attribute).
117053 + */
117054 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
117055 +{
117056 + const_gimple def_stmt;
117057 +
117058 + if (TREE_CODE(lhs) != SSA_NAME) {
117059 + insert_last_node(cur_node, lhs);
117060 + return;
117061 + }
117062 +
117063 + def_stmt = get_def_stmt(lhs);
117064 + if (!def_stmt)
117065 + return;
117066 +
117067 + if (pointer_set_insert(visited, def_stmt))
117068 + return;
117069 +
117070 + switch (gimple_code(def_stmt)) {
117071 + case GIMPLE_NOP:
117072 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
117073 + case GIMPLE_ASM:
117074 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
117075 + case GIMPLE_CALL: {
117076 + tree fndecl = gimple_call_fndecl(def_stmt);
117077 +
117078 + if (fndecl == NULL_TREE)
117079 + return;
117080 + insert_last_node(cur_node, fndecl);
117081 + return;
117082 + }
117083 + case GIMPLE_PHI:
117084 + return walk_use_def_phi(visited, cur_node, lhs);
117085 + case GIMPLE_ASSIGN:
117086 + switch (gimple_num_ops(def_stmt)) {
117087 + case 2:
117088 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
117089 + case 3:
117090 + return walk_use_def_binary(visited, cur_node, lhs);
117091 + }
117092 + default:
117093 + debug_gimple_stmt((gimple)def_stmt);
117094 + error("%s: unknown gimple code", __func__);
117095 + gcc_unreachable();
117096 + }
117097 +}
117098 +
117099 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
117100 +static void set_last_nodes(struct interesting_node *cur_node)
117101 +{
117102 + struct pointer_set_t *visited;
117103 +
117104 + visited = pointer_set_create();
117105 + walk_use_def(visited, cur_node, cur_node->node);
117106 + pointer_set_destroy(visited);
117107 +}
117108 +
117109 +enum precond {
117110 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
117111 +};
117112 +
117113 +/* 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.
117114 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
117115 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
117116 + * 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.
117117 + */
117118 +static enum precond check_preconditions(struct interesting_node *cur_node)
117119 +{
117120 + bool interesting_conditions[3] = {false, false, false};
117121 +
117122 + set_last_nodes(cur_node);
117123 +
117124 + check_intentional_attribute_ipa(cur_node);
117125 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
117126 + return NO_ATTRIBUTE_SEARCH;
117127 +
117128 + search_interesting_conditions(cur_node, interesting_conditions);
117129 +
117130 + // error code
117131 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
117132 + return NO_ATTRIBUTE_SEARCH;
117133 +
117134 + // unnecessary overflow check
117135 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
117136 + return NO_CHECK_INSERT;
117137 +
117138 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
117139 + return NO_CHECK_INSERT;
117140 +
117141 + return NONE;
117142 +}
117143 +
117144 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
117145 + * 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
117146 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
117147 + */
117148 +static struct next_cgraph_node *handle_interesting_stmt(struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
117149 +{
117150 + enum precond ret;
117151 + struct pointer_set_t *visited;
117152 + tree new_node, orig_node = cur_node->node;
117153 +
117154 + ret = check_preconditions(cur_node);
117155 + if (ret == NO_ATTRIBUTE_SEARCH)
117156 + return cnodes;
117157 +
117158 + cnodes = search_overflow_attribute(cnodes, cur_node);
117159 +
117160 + if (ret == NO_CHECK_INSERT)
117161 + return cnodes;
117162 +
117163 + visited = pointer_set_create();
117164 + new_node = expand(visited, caller_node, orig_node);
117165 + pointer_set_destroy(visited);
117166 +
117167 + if (new_node == NULL_TREE)
117168 + return cnodes;
117169 +
117170 + change_orig_node(cur_node, new_node);
117171 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
117172 +
117173 + return cnodes;
117174 +}
117175 +
117176 +// Check visited interesting nodes.
117177 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
117178 +{
117179 + struct interesting_node *cur;
117180 +
117181 + for (cur = head; cur; cur = cur->next) {
117182 + if (!operand_equal_p(node, cur->node, 0))
117183 + continue;
117184 + if (num != cur->num)
117185 + continue;
117186 + if (first_stmt == cur->first_stmt)
117187 + return true;
117188 + }
117189 + return false;
117190 +}
117191 +
117192 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
117193 + 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
117194 + 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
117195 + the intentional_overflow attribute check. They are collected by set_last_nodes().
117196 + num: arg count of a call stmt or 0 when it is a ret
117197 + node: the recursion starts from here, it is a call arg or a return value
117198 + 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.
117199 + intentional_attr_decl: intentional_overflow attribute of the callee function
117200 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
117201 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
117202 + */
117203 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
117204 +{
117205 + struct interesting_node *new_node;
117206 + tree fndecl;
117207 + enum gimple_code code;
117208 +
117209 + gcc_assert(node != NULL_TREE);
117210 + code = gimple_code(first_stmt);
117211 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
117212 +
117213 + if (num == CANNOT_FIND_ARG)
117214 + return head;
117215 +
117216 + if (skip_types(node))
117217 + return head;
117218 +
117219 + if (skip_asm(node))
117220 + return head;
117221 +
117222 + if (is_gimple_call(first_stmt))
117223 + fndecl = gimple_call_fndecl(first_stmt);
117224 + else
117225 + fndecl = current_function_decl;
117226 +
117227 + if (fndecl == NULL_TREE)
117228 + return head;
117229 +
117230 + if (is_in_interesting_node(head, first_stmt, node, num))
117231 + return head;
117232 +
117233 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
117234 +
117235 + new_node->next = NULL;
117236 + new_node->first_stmt = first_stmt;
117237 +#if BUILDING_GCC_VERSION <= 4007
117238 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
117239 +#else
117240 + vec_alloc(new_node->last_nodes, VEC_LEN);
117241 +#endif
117242 + new_node->num = num;
117243 + new_node->node = node;
117244 + new_node->fndecl = fndecl;
117245 + new_node->intentional_attr_decl = MARK_NO;
117246 + new_node->intentional_attr_cur_fndecl = MARK_NO;
117247 + new_node->intentional_mark_from_gimple = asm_stmt;
117248 +
117249 + if (!head)
117250 + return new_node;
117251 +
117252 + new_node->next = head;
117253 + return new_node;
117254 +}
117255 +
117256 +/* 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).
117257 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
117258 + */
117259 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117260 +{
117261 + struct next_cgraph_node *cur_node;
117262 + tree ret = gimple_return_retval(stmt);
117263 +
117264 + if (ret == NULL_TREE)
117265 + return head;
117266 +
117267 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117268 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
117269 + continue;
117270 + if (cur_node->num == 0)
117271 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
117272 + }
117273 +
117274 + return head;
117275 +}
117276 +
117277 +/* 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).
117278 + * If the call stmt is in the next cgraph node list then it's an interesting call.
117279 + */
117280 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
117281 +{
117282 + unsigned int argnum;
117283 + tree arg;
117284 + const_tree fndecl;
117285 + struct next_cgraph_node *cur_node;
117286 +
117287 + fndecl = gimple_call_fndecl(stmt);
117288 + if (fndecl == NULL_TREE)
117289 + return head;
117290 +
117291 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
117292 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
117293 + continue;
117294 + argnum = get_correct_arg_count(cur_node->num, fndecl);
117295 + gcc_assert(argnum != CANNOT_FIND_ARG);
117296 + if (argnum == 0)
117297 + continue;
117298 +
117299 + arg = gimple_call_arg(stmt, argnum - 1);
117300 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
117301 + }
117302 +
117303 + return head;
117304 +}
117305 +
117306 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
117307 +{
117308 + if (!operand_equal_p(orig_node, node, 0))
117309 + return WRONG_NODE;
117310 + if (skip_types(node))
117311 + return WRONG_NODE;
117312 + return ret_count;
117313 +}
117314 +
117315 +// Get the index of the rhs node in an assignment
117316 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
117317 +{
117318 + const_tree rhs1, rhs2;
117319 + unsigned int ret;
117320 +
117321 + gcc_assert(stmt);
117322 + gcc_assert(is_gimple_assign(stmt));
117323 +
117324 + rhs1 = gimple_assign_rhs1(stmt);
117325 + gcc_assert(rhs1 != NULL_TREE);
117326 +
117327 + switch (gimple_num_ops(stmt)) {
117328 + case 2:
117329 + return check_ops(node, rhs1, 1);
117330 + case 3:
117331 + ret = check_ops(node, rhs1, 1);
117332 + if (ret != WRONG_NODE)
117333 + return ret;
117334 +
117335 + rhs2 = gimple_assign_rhs2(stmt);
117336 + gcc_assert(rhs2 != NULL_TREE);
117337 + return check_ops(node, rhs2, 2);
117338 + default:
117339 + gcc_unreachable();
117340 + }
117341 +}
117342 +
117343 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
117344 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
117345 +{
117346 + unsigned int i;
117347 +
117348 + if (gimple_call_fndecl(stmt) == NULL_TREE)
117349 + return CANNOT_FIND_ARG;
117350 +
117351 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
117352 + tree node;
117353 +
117354 + node = gimple_call_arg(stmt, i);
117355 + if (!operand_equal_p(arg, node, 0))
117356 + continue;
117357 + if (!skip_types(node))
117358 + return i + 1;
117359 + }
117360 +
117361 + return CANNOT_FIND_ARG;
117362 +}
117363 +
117364 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
117365 + * any of return, call or assignment stmts (because of inlining).
117366 + */
117367 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
117368 +{
117369 + use_operand_p use_p;
117370 + imm_use_iterator imm_iter;
117371 + unsigned int argnum;
117372 +
117373 + gcc_assert(TREE_CODE(node) == SSA_NAME);
117374 +
117375 + if (pointer_set_insert(visited, node))
117376 + return head;
117377 +
117378 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
117379 + gimple stmt = USE_STMT(use_p);
117380 +
117381 + if (stmt == NULL)
117382 + return head;
117383 + if (is_gimple_debug(stmt))
117384 + continue;
117385 +
117386 + switch (gimple_code(stmt)) {
117387 + case GIMPLE_CALL:
117388 + argnum = find_arg_number_gimple(node, stmt);
117389 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117390 + break;
117391 + case GIMPLE_RETURN:
117392 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
117393 + break;
117394 + case GIMPLE_ASSIGN:
117395 + argnum = get_assign_ops_count(stmt, node);
117396 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
117397 + break;
117398 + case GIMPLE_PHI: {
117399 + tree result = gimple_phi_result(stmt);
117400 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
117401 + break;
117402 + }
117403 + case GIMPLE_ASM:
117404 + if (gimple_asm_noutputs(stmt) != 0)
117405 + break;
117406 + if (!is_size_overflow_asm(stmt))
117407 + break;
117408 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
117409 + break;
117410 + case GIMPLE_COND:
117411 + case GIMPLE_SWITCH:
117412 + break;
117413 + default:
117414 + debug_gimple_stmt(stmt);
117415 + gcc_unreachable();
117416 + break;
117417 + }
117418 + }
117419 + return head;
117420 +}
117421 +
117422 +static void remove_size_overflow_asm(gimple stmt)
117423 +{
117424 + gimple_stmt_iterator gsi;
117425 + tree input, output;
117426 +
117427 + if (!is_size_overflow_asm(stmt))
117428 + return;
117429 +
117430 + if (gimple_asm_noutputs(stmt) == 0) {
117431 + gsi = gsi_for_stmt(stmt);
117432 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
117433 + gsi_remove(&gsi, true);
117434 + return;
117435 + }
117436 +
117437 + input = gimple_asm_input_op(stmt, 0);
117438 + output = gimple_asm_output_op(stmt, 0);
117439 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
117440 +}
117441 +
117442 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
117443 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
117444 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
117445 + */
117446 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
117447 +{
117448 + const_tree output;
117449 + struct pointer_set_t *visited;
117450 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
117451 +
117452 + if (!is_size_overflow_asm(stmt))
117453 + return head;
117454 +
117455 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
117456 + intentional_asm = stmt;
117457 +
117458 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
117459 +
117460 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
117461 + return head;
117462 +
117463 + if (gimple_asm_noutputs(stmt) == 0) {
117464 + const_tree input;
117465 +
117466 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
117467 + return head;
117468 +
117469 + input = gimple_asm_input_op(stmt, 0);
117470 + remove_size_overflow_asm(stmt);
117471 + if (is_gimple_constant(TREE_VALUE(input)))
117472 + return head;
117473 + visited = pointer_set_create();
117474 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
117475 + pointer_set_destroy(visited);
117476 + return head;
117477 + }
117478 +
117479 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
117480 + remove_size_overflow_asm(stmt);
117481 +
117482 + visited = pointer_set_create();
117483 + output = gimple_asm_output_op(stmt, 0);
117484 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
117485 + pointer_set_destroy(visited);
117486 + return head;
117487 +}
117488 +
117489 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
117490 + * or a call stmt or a return stmt and store them in the interesting_node list
117491 + */
117492 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
117493 +{
117494 + basic_block bb;
117495 + struct interesting_node *head = NULL;
117496 +
117497 + FOR_ALL_BB_FN(bb, cfun) {
117498 + gimple_stmt_iterator gsi;
117499 +
117500 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117501 + enum gimple_code code;
117502 + gimple stmt = gsi_stmt(gsi);
117503 +
117504 + code = gimple_code(stmt);
117505 +
117506 + if (code == GIMPLE_ASM)
117507 + head = handle_stmt_by_size_overflow_asm(stmt, head);
117508 +
117509 + if (!next_node)
117510 + continue;
117511 + if (code == GIMPLE_CALL)
117512 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
117513 + if (code == GIMPLE_RETURN)
117514 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
117515 + }
117516 + }
117517 + return head;
117518 +}
117519 +
117520 +static void set_current_function_decl(tree fndecl)
117521 +{
117522 + gcc_assert(fndecl != NULL_TREE);
117523 +
117524 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
117525 + calculate_dominance_info(CDI_DOMINATORS);
117526 + current_function_decl = fndecl;
117527 +}
117528 +
117529 +static void unset_current_function_decl(void)
117530 +{
117531 + free_dominance_info(CDI_DOMINATORS);
117532 + pop_cfun();
117533 + current_function_decl = NULL_TREE;
117534 +}
117535 +
117536 +static void free_interesting_node(struct interesting_node *head)
117537 +{
117538 + struct interesting_node *cur;
117539 +
117540 + while (head) {
117541 + cur = head->next;
117542 +#if BUILDING_GCC_VERSION <= 4007
117543 + VEC_free(tree, gc, head->last_nodes);
117544 +#else
117545 + vec_free(head->last_nodes);
117546 +#endif
117547 + free(head);
117548 + head = cur;
117549 + }
117550 +}
117551 +
117552 +static struct visited *insert_visited_function(struct visited *head, struct interesting_node *cur_node)
117553 +{
117554 + struct visited *new_visited;
117555 +
117556 + new_visited = (struct visited *)xmalloc(sizeof(*new_visited));
117557 + new_visited->fndecl = cur_node->fndecl;
117558 + new_visited->num = cur_node->num;
117559 + new_visited->next = NULL;
117560 +
117561 + if (!head)
117562 + return new_visited;
117563 +
117564 + new_visited->next = head;
117565 + return new_visited;
117566 +}
117567 +
117568 +/* Check whether the function was already visited. If the fndecl, the arg count of the fndecl and the first_stmt (call or return) are same then
117569 + * it is a visited function.
117570 + */
117571 +static bool is_visited_function(struct visited *head, struct interesting_node *cur_node)
117572 +{
117573 + struct visited *cur;
117574 +
117575 + if (!head)
117576 + return false;
117577 +
117578 + if (get_stmt_flag(cur_node->first_stmt) != VISITED_STMT)
117579 + return false;
117580 +
117581 + for (cur = head; cur; cur = cur->next) {
117582 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
117583 + continue;
117584 + if (cur_node->num == cur->num)
117585 + return true;
117586 + }
117587 + return false;
117588 +}
117589 +
117590 +static void free_next_cgraph_node(struct next_cgraph_node *head)
117591 +{
117592 + struct next_cgraph_node *cur;
117593 +
117594 + while (head) {
117595 + cur = head->next;
117596 + free(head);
117597 + head = cur;
117598 + }
117599 +}
117600 +
117601 +static void remove_all_size_overflow_asm(void)
117602 +{
117603 + basic_block bb;
117604 +
117605 + FOR_ALL_BB_FN(bb, cfun) {
117606 + gimple_stmt_iterator si;
117607 +
117608 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117609 + remove_size_overflow_asm(gsi_stmt(si));
117610 + }
117611 +}
117612 +
117613 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
117614 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
117615 + * the newly collected interesting functions (they are interesting if there is control flow between
117616 + * the interesting stmts and them).
117617 + */
117618 +static struct visited *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited *visited)
117619 +{
117620 + struct interesting_node *head, *cur_node;
117621 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
117622 +
117623 + set_current_function_decl(NODE_DECL(node));
117624 + call_count = 0;
117625 +
117626 + head = collect_interesting_stmts(next_node);
117627 +
117628 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
117629 + if (is_visited_function(visited, cur_node))
117630 + continue;
117631 + cnodes_head = handle_interesting_stmt(cnodes_head, cur_node, node);
117632 + set_stmt_flag(cur_node->first_stmt, VISITED_STMT);
117633 + visited = insert_visited_function(visited, cur_node);
117634 + }
117635 +
117636 + free_interesting_node(head);
117637 + remove_all_size_overflow_asm();
117638 + unset_current_function_decl();
117639 +
117640 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
117641 + visited = handle_function(cur_cnodes->current_function, cur_cnodes, visited);
117642 +
117643 + free_next_cgraph_node(cnodes_head);
117644 + return visited;
117645 +}
117646 +
117647 +static void free_visited(struct visited *head)
117648 +{
117649 + struct visited *cur;
117650 +
117651 + while (head) {
117652 + cur = head->next;
117653 + free(head);
117654 + head = cur;
117655 + }
117656 +}
117657 +
117658 +// erase the local flag
117659 +static void set_plf_false(void)
117660 +{
117661 + basic_block bb;
117662 +
117663 + FOR_ALL_BB_FN(bb, cfun) {
117664 + gimple_stmt_iterator si;
117665 +
117666 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
117667 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117668 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
117669 + set_stmt_flag(gsi_stmt(si), NO_FLAGS);
117670 + }
117671 +}
117672 +
117673 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
117674 +static unsigned int search_function(void)
117675 +{
117676 + struct cgraph_node *node;
117677 + struct visited *visited = NULL;
117678 +
117679 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117680 + set_current_function_decl(NODE_DECL(node));
117681 + set_plf_false();
117682 + unset_current_function_decl();
117683 + }
117684 +
117685 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
117686 + gcc_assert(cgraph_function_flags_ready);
117687 +#if BUILDING_GCC_VERSION <= 4007
117688 + gcc_assert(node->reachable);
117689 +#endif
117690 +
117691 + visited = handle_function(node, NULL, visited);
117692 + }
117693 +
117694 + free_visited(visited);
117695 + return 0;
117696 +}
117697 +
117698 +#if BUILDING_GCC_VERSION >= 4009
117699 +static const struct pass_data ipa_pass_data = {
117700 +#else
117701 +static struct ipa_opt_pass_d ipa_pass = {
117702 + .pass = {
117703 +#endif
117704 + .type = SIMPLE_IPA_PASS,
117705 + .name = "size_overflow",
117706 +#if BUILDING_GCC_VERSION >= 4008
117707 + .optinfo_flags = OPTGROUP_NONE,
117708 +#endif
117709 +#if BUILDING_GCC_VERSION >= 4009
117710 + .has_gate = false,
117711 + .has_execute = true,
117712 +#else
117713 + .gate = NULL,
117714 + .execute = search_function,
117715 + .sub = NULL,
117716 + .next = NULL,
117717 + .static_pass_number = 0,
117718 +#endif
117719 + .tv_id = TV_NONE,
117720 + .properties_required = 0,
117721 + .properties_provided = 0,
117722 + .properties_destroyed = 0,
117723 + .todo_flags_start = 0,
117724 + .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,
117725 +#if BUILDING_GCC_VERSION < 4009
117726 + },
117727 + .generate_summary = NULL,
117728 + .write_summary = NULL,
117729 + .read_summary = NULL,
117730 +#if BUILDING_GCC_VERSION >= 4006
117731 + .write_optimization_summary = NULL,
117732 + .read_optimization_summary = NULL,
117733 +#endif
117734 + .stmt_fixup = NULL,
117735 + .function_transform_todo_flags_start = 0,
117736 + .function_transform = NULL,
117737 + .variable_transform = NULL,
117738 +#endif
117739 +};
117740 +
117741 +#if BUILDING_GCC_VERSION >= 4009
117742 +namespace {
117743 +class ipa_pass : public ipa_opt_pass_d {
117744 +public:
117745 + ipa_pass() : ipa_opt_pass_d(ipa_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
117746 + unsigned int execute() { return search_function(); }
117747 +};
117748 +}
117749 +#endif
117750 +
117751 +static struct opt_pass *make_ipa_pass(void)
117752 +{
117753 +#if BUILDING_GCC_VERSION >= 4009
117754 + return new ipa_pass();
117755 +#else
117756 + return &ipa_pass.pass;
117757 +#endif
117758 +}
117759 +
117760 +// data for the size_overflow asm stmt
117761 +struct asm_data {
117762 + gimple def_stmt;
117763 + tree input;
117764 + tree output;
117765 +};
117766 +
117767 +#if BUILDING_GCC_VERSION <= 4007
117768 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
117769 +#else
117770 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
117771 +#endif
117772 +{
117773 + tree list;
117774 +#if BUILDING_GCC_VERSION <= 4007
117775 + VEC(tree, gc) *vec_list = NULL;
117776 +#else
117777 + vec<tree, va_gc> *vec_list = NULL;
117778 +#endif
117779 +
117780 + list = build_tree_list(NULL_TREE, string);
117781 + list = chainon(NULL_TREE, build_tree_list(list, io));
117782 +#if BUILDING_GCC_VERSION <= 4007
117783 + VEC_safe_push(tree, gc, vec_list, list);
117784 +#else
117785 + vec_safe_push(vec_list, list);
117786 +#endif
117787 + return vec_list;
117788 +}
117789 +
117790 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
117791 +{
117792 + gimple asm_stmt;
117793 + gimple_stmt_iterator gsi;
117794 +#if BUILDING_GCC_VERSION <= 4007
117795 + VEC(tree, gc) *input, *output = NULL;
117796 +#else
117797 + vec<tree, va_gc> *input, *output = NULL;
117798 +#endif
117799 +
117800 + input = create_asm_io_list(str_input, asm_data->input);
117801 +
117802 + if (asm_data->output)
117803 + output = create_asm_io_list(str_output, asm_data->output);
117804 +
117805 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
117806 + gsi = gsi_for_stmt(asm_data->def_stmt);
117807 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
117808 +
117809 + if (asm_data->output)
117810 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
117811 +}
117812 +
117813 +static void replace_call_lhs(const struct asm_data *asm_data)
117814 +{
117815 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
117816 + update_stmt(asm_data->def_stmt);
117817 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
117818 +}
117819 +
117820 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
117821 +{
117822 + enum mark cur_fndecl_attr;
117823 + gimple phi = get_def_stmt(result);
117824 + unsigned int i, n = gimple_phi_num_args(phi);
117825 +
117826 + pointer_set_insert(visited, phi);
117827 + for (i = 0; i < n; i++) {
117828 + tree arg = gimple_phi_arg_def(phi, i);
117829 +
117830 + cur_fndecl_attr = search_intentional(visited, arg);
117831 + if (cur_fndecl_attr != MARK_NO)
117832 + return cur_fndecl_attr;
117833 + }
117834 + return MARK_NO;
117835 +}
117836 +
117837 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
117838 +{
117839 + enum mark cur_fndecl_attr;
117840 + const_tree rhs1, rhs2;
117841 + gimple def_stmt = get_def_stmt(lhs);
117842 +
117843 + rhs1 = gimple_assign_rhs1(def_stmt);
117844 + rhs2 = gimple_assign_rhs2(def_stmt);
117845 +
117846 + cur_fndecl_attr = search_intentional(visited, rhs1);
117847 + if (cur_fndecl_attr != MARK_NO)
117848 + return cur_fndecl_attr;
117849 + return search_intentional(visited, rhs2);
117850 +}
117851 +
117852 +// Look up the intentional_overflow attribute on the caller and the callee functions.
117853 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
117854 +{
117855 + const_gimple def_stmt;
117856 +
117857 + if (TREE_CODE(lhs) != SSA_NAME)
117858 + return get_intentional_attr_type(lhs);
117859 +
117860 + def_stmt = get_def_stmt(lhs);
117861 + if (!def_stmt)
117862 + return MARK_NO;
117863 +
117864 + if (pointer_set_contains(visited, def_stmt))
117865 + return MARK_NO;
117866 +
117867 + switch (gimple_code(def_stmt)) {
117868 + case GIMPLE_NOP:
117869 + return search_intentional(visited, SSA_NAME_VAR(lhs));
117870 + case GIMPLE_ASM:
117871 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
117872 + return MARK_TURN_OFF;
117873 + return MARK_NO;
117874 + case GIMPLE_CALL:
117875 + return MARK_NO;
117876 + case GIMPLE_PHI:
117877 + return search_intentional_phi(visited, lhs);
117878 + case GIMPLE_ASSIGN:
117879 + switch (gimple_num_ops(def_stmt)) {
117880 + case 2:
117881 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
117882 + case 3:
117883 + return search_intentional_binary(visited, lhs);
117884 + }
117885 + case GIMPLE_RETURN:
117886 + return MARK_NO;
117887 + default:
117888 + debug_gimple_stmt((gimple)def_stmt);
117889 + error("%s: unknown gimple code", __func__);
117890 + gcc_unreachable();
117891 + }
117892 +}
117893 +
117894 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
117895 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
117896 +{
117897 + const_tree fndecl;
117898 + struct pointer_set_t *visited;
117899 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
117900 +
117901 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
117902 + if (is_end_intentional_intentional_attr(fndecl, argnum))
117903 + decl_attr = MARK_NOT_INTENTIONAL;
117904 + else if (is_yes_intentional_attr(fndecl, argnum))
117905 + decl_attr = MARK_YES;
117906 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
117907 + return MARK_TURN_OFF;
117908 + }
117909 +
117910 + visited = pointer_set_create();
117911 + cur_fndecl_attr = search_intentional(visited, arg);
117912 + pointer_set_destroy(visited);
117913 +
117914 + switch (cur_fndecl_attr) {
117915 + case MARK_NO:
117916 + case MARK_TURN_OFF:
117917 + return cur_fndecl_attr;
117918 + default:
117919 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
117920 + return MARK_YES;
117921 + }
117922 +}
117923 +
117924 +static void check_missing_size_overflow_attribute(tree var)
117925 +{
117926 + tree orig_fndecl;
117927 + unsigned int num;
117928 +
117929 + if (is_a_return_check(var))
117930 + orig_fndecl = DECL_ORIGIN(var);
117931 + else
117932 + orig_fndecl = DECL_ORIGIN(current_function_decl);
117933 +
117934 + num = get_function_num(var, orig_fndecl);
117935 + if (num == CANNOT_FIND_ARG)
117936 + return;
117937 +
117938 + is_missing_function(orig_fndecl, num);
117939 +}
117940 +
117941 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
117942 +{
117943 + gimple phi = get_def_stmt(result);
117944 + unsigned int i, n = gimple_phi_num_args(phi);
117945 +
117946 + pointer_set_insert(visited, phi);
117947 + for (i = 0; i < n; i++) {
117948 + tree arg = gimple_phi_arg_def(phi, i);
117949 +
117950 + search_size_overflow_attribute(visited, arg);
117951 + }
117952 +}
117953 +
117954 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
117955 +{
117956 + const_gimple def_stmt = get_def_stmt(lhs);
117957 + tree rhs1, rhs2;
117958 +
117959 + rhs1 = gimple_assign_rhs1(def_stmt);
117960 + rhs2 = gimple_assign_rhs2(def_stmt);
117961 +
117962 + search_size_overflow_attribute(visited, rhs1);
117963 + search_size_overflow_attribute(visited, rhs2);
117964 +}
117965 +
117966 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
117967 +{
117968 + const_gimple def_stmt;
117969 +
117970 + if (TREE_CODE(lhs) == PARM_DECL) {
117971 + check_missing_size_overflow_attribute(lhs);
117972 + return;
117973 + }
117974 +
117975 + def_stmt = get_def_stmt(lhs);
117976 + if (!def_stmt)
117977 + return;
117978 +
117979 + if (pointer_set_insert(visited, def_stmt))
117980 + return;
117981 +
117982 + switch (gimple_code(def_stmt)) {
117983 + case GIMPLE_NOP:
117984 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
117985 + case GIMPLE_ASM:
117986 + return;
117987 + case GIMPLE_CALL: {
117988 + tree fndecl = gimple_call_fndecl(def_stmt);
117989 +
117990 + if (fndecl == NULL_TREE)
117991 + return;
117992 + check_missing_size_overflow_attribute(fndecl);
117993 + return;
117994 + }
117995 + case GIMPLE_PHI:
117996 + return search_size_overflow_attribute_phi(visited, lhs);
117997 + case GIMPLE_ASSIGN:
117998 + switch (gimple_num_ops(def_stmt)) {
117999 + case 2:
118000 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
118001 + case 3:
118002 + return search_size_overflow_attribute_binary(visited, lhs);
118003 + }
118004 + default:
118005 + debug_gimple_stmt((gimple)def_stmt);
118006 + error("%s: unknown gimple code", __func__);
118007 + gcc_unreachable();
118008 + }
118009 +}
118010 +
118011 +// Search missing entries in the hash table (invoked from the gimple pass)
118012 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
118013 +{
118014 + tree fndecl = NULL_TREE;
118015 + tree lhs;
118016 + struct pointer_set_t *visited;
118017 +
118018 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
118019 + return;
118020 +
118021 + if (num == 0) {
118022 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
118023 + lhs = gimple_return_retval(stmt);
118024 + } else {
118025 + gcc_assert(is_gimple_call(stmt));
118026 + lhs = gimple_call_arg(stmt, num - 1);
118027 + fndecl = gimple_call_fndecl(stmt);
118028 + }
118029 +
118030 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
118031 + return;
118032 +
118033 + visited = pointer_set_create();
118034 + search_size_overflow_attribute(visited, lhs);
118035 + pointer_set_destroy(visited);
118036 +}
118037 +
118038 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
118039 +{
118040 + gimple_stmt_iterator gsi;
118041 + gimple assign;
118042 +
118043 + assign = gimple_build_assign(asm_data->input, asm_data->output);
118044 + gsi = gsi_for_stmt(stmt);
118045 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
118046 + asm_data->def_stmt = assign;
118047 +
118048 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
118049 + asm_data->output = make_ssa_name(asm_data->output, stmt);
118050 + if (gimple_code(stmt) == GIMPLE_RETURN)
118051 + gimple_return_set_retval(stmt, asm_data->output);
118052 + else
118053 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
118054 + update_stmt(stmt);
118055 +}
118056 +
118057 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
118058 +{
118059 + const char *fn_name;
118060 + char *asm_comment;
118061 + unsigned int len;
118062 +
118063 + if (argnum == 0)
118064 + fn_name = DECL_NAME_POINTER(current_function_decl);
118065 + else
118066 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
118067 +
118068 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
118069 + gcc_assert(len > 0);
118070 +
118071 + return asm_comment;
118072 +}
118073 +
118074 +static const char *convert_mark_to_str(enum mark mark)
118075 +{
118076 + switch (mark) {
118077 + case MARK_NO:
118078 + return OK_ASM_STR;
118079 + case MARK_YES:
118080 + case MARK_NOT_INTENTIONAL:
118081 + return YES_ASM_STR;
118082 + case MARK_TURN_OFF:
118083 + return TURN_OFF_ASM_STR;
118084 + }
118085 +
118086 + gcc_unreachable();
118087 +}
118088 +
118089 +/* Create the input of the size_overflow asm stmt.
118090 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
118091 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
118092 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
118093 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
118094 + */
118095 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
118096 +{
118097 + if (!asm_data->def_stmt) {
118098 + asm_data->input = NULL_TREE;
118099 + return;
118100 + }
118101 +
118102 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
118103 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
118104 +
118105 + switch (gimple_code(asm_data->def_stmt)) {
118106 + case GIMPLE_ASSIGN:
118107 + case GIMPLE_CALL:
118108 + replace_call_lhs(asm_data);
118109 + break;
118110 + case GIMPLE_PHI:
118111 + create_output_from_phi(stmt, argnum, asm_data);
118112 + break;
118113 + case GIMPLE_NOP: {
118114 + enum mark mark;
118115 + const char *mark_str;
118116 + char *asm_comment;
118117 +
118118 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
118119 +
118120 + asm_data->input = asm_data->output;
118121 + asm_data->output = NULL;
118122 + asm_data->def_stmt = stmt;
118123 +
118124 + mark_str = convert_mark_to_str(mark);
118125 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
118126 +
118127 + create_asm_stmt(asm_comment, build_string(2, "rm"), NULL, asm_data);
118128 + free(asm_comment);
118129 + asm_data->input = NULL_TREE;
118130 + break;
118131 + }
118132 + case GIMPLE_ASM:
118133 + if (is_size_overflow_asm(asm_data->def_stmt)) {
118134 + asm_data->input = NULL_TREE;
118135 + break;
118136 + }
118137 + default:
118138 + debug_gimple_stmt(asm_data->def_stmt);
118139 + gcc_unreachable();
118140 + }
118141 +}
118142 +
118143 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
118144 + * is of the right kind create the appropriate size_overflow asm stmts:
118145 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
118146 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
118147 + */
118148 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
118149 +{
118150 + struct asm_data asm_data;
118151 + const char *mark_str;
118152 + char *asm_comment;
118153 + enum mark mark;
118154 +
118155 + if (is_gimple_constant(output_node))
118156 + return;
118157 +
118158 + asm_data.output = output_node;
118159 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
118160 + if (mark != MARK_TURN_OFF)
118161 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
118162 +
118163 + asm_data.def_stmt = get_def_stmt(asm_data.output);
118164 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
118165 + return;
118166 +
118167 + create_asm_input(stmt, argnum, &asm_data);
118168 + if (asm_data.input == NULL_TREE)
118169 + return;
118170 +
118171 + mark_str = convert_mark_to_str(mark);
118172 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
118173 + create_asm_stmt(asm_comment, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
118174 + free(asm_comment);
118175 +}
118176 +
118177 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
118178 +static bool create_mark_asm(gimple stmt, enum mark mark)
118179 +{
118180 + struct asm_data asm_data;
118181 + const char *asm_str;
118182 +
118183 + switch (mark) {
118184 + case MARK_TURN_OFF:
118185 + asm_str = TURN_OFF_ASM_STR;
118186 + break;
118187 + case MARK_NOT_INTENTIONAL:
118188 + case MARK_YES:
118189 + asm_str = YES_ASM_STR;
118190 + break;
118191 + default:
118192 + gcc_unreachable();
118193 + }
118194 +
118195 + asm_data.def_stmt = stmt;
118196 + asm_data.output = gimple_call_lhs(stmt);
118197 +
118198 + if (asm_data.output == NULL_TREE) {
118199 + asm_data.input = gimple_call_arg(stmt, 0);
118200 + if (is_gimple_constant(asm_data.input))
118201 + return false;
118202 + asm_data.output = NULL;
118203 + create_asm_stmt(asm_str, build_string(2, "rm"), NULL, &asm_data);
118204 + return true;
118205 + }
118206 +
118207 + create_asm_input(stmt, 0, &asm_data);
118208 + gcc_assert(asm_data.input != NULL_TREE);
118209 +
118210 + create_asm_stmt(asm_str, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
118211 + return true;
118212 +}
118213 +
118214 +static bool is_from_cast(const_tree node)
118215 +{
118216 + gimple def_stmt = get_def_stmt(node);
118217 +
118218 + if (!def_stmt)
118219 + return false;
118220 +
118221 + if (gimple_assign_cast_p(def_stmt))
118222 + return true;
118223 +
118224 + return false;
118225 +}
118226 +
118227 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
118228 +static bool skip_ptr_minus(gimple stmt)
118229 +{
118230 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
118231 +
118232 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
118233 + return false;
118234 +
118235 + rhs1 = gimple_assign_rhs1(stmt);
118236 + if (!is_from_cast(rhs1))
118237 + return false;
118238 +
118239 + rhs2 = gimple_assign_rhs2(stmt);
118240 + if (!is_from_cast(rhs2))
118241 + return false;
118242 +
118243 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
118244 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
118245 +
118246 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
118247 + return false;
118248 +
118249 + create_mark_asm(stmt, MARK_YES);
118250 + return true;
118251 +}
118252 +
118253 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
118254 +{
118255 + gimple def_stmt;
118256 +
118257 + def_stmt = get_def_stmt(lhs);
118258 + if (!def_stmt)
118259 + return;
118260 +
118261 + if (pointer_set_insert(visited, def_stmt))
118262 + return;
118263 +
118264 + switch (gimple_code(def_stmt)) {
118265 + case GIMPLE_NOP:
118266 + case GIMPLE_ASM:
118267 + case GIMPLE_CALL:
118268 + break;
118269 + case GIMPLE_PHI: {
118270 + unsigned int i, n = gimple_phi_num_args(def_stmt);
118271 +
118272 + pointer_set_insert(visited, def_stmt);
118273 +
118274 + for (i = 0; i < n; i++) {
118275 + tree arg = gimple_phi_arg_def(def_stmt, i);
118276 +
118277 + walk_use_def_ptr(visited, arg);
118278 + }
118279 + }
118280 + case GIMPLE_ASSIGN:
118281 + switch (gimple_num_ops(def_stmt)) {
118282 + case 2:
118283 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
118284 + return;
118285 + case 3:
118286 + if (skip_ptr_minus(def_stmt))
118287 + return;
118288 +
118289 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
118290 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
118291 + return;
118292 + default:
118293 + return;
118294 + }
118295 + default:
118296 + debug_gimple_stmt((gimple)def_stmt);
118297 + error("%s: unknown gimple code", __func__);
118298 + gcc_unreachable();
118299 + }
118300 +}
118301 +
118302 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
118303 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
118304 +{
118305 + struct pointer_set_t *visited;
118306 +
118307 + visited = pointer_set_create();
118308 + walk_use_def_ptr(visited, arg);
118309 + pointer_set_destroy(visited);
118310 +}
118311 +
118312 +// Determine the return value and insert the asm stmt to mark the return stmt.
118313 +static void insert_asm_ret(gimple stmt)
118314 +{
118315 + tree ret;
118316 +
118317 + ret = gimple_return_retval(stmt);
118318 + create_size_overflow_asm(stmt, ret, 0);
118319 +}
118320 +
118321 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
118322 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
118323 +{
118324 + tree arg;
118325 + unsigned int argnum;
118326 +
118327 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
118328 + gcc_assert(argnum != 0);
118329 + if (argnum == CANNOT_FIND_ARG)
118330 + return;
118331 +
118332 + arg = gimple_call_arg(stmt, argnum - 1);
118333 + gcc_assert(arg != NULL_TREE);
118334 +
118335 + // skip all ptr - ptr expressions
118336 + insert_mark_not_intentional_asm_at_ptr(arg);
118337 +
118338 + create_size_overflow_asm(stmt, arg, argnum);
118339 +}
118340 +
118341 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
118342 +static void set_argnum_attribute(const_tree attr, bool *argnums)
118343 +{
118344 + unsigned int argnum;
118345 + tree attr_value;
118346 +
118347 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
118348 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
118349 + argnums[argnum] = true;
118350 + }
118351 +}
118352 +
118353 +// If a function arg or the return value is in the hash table then set its index in the array.
118354 +static void set_argnum_hash(tree fndecl, bool *argnums)
118355 +{
118356 + unsigned int num;
118357 + const struct size_overflow_hash *hash;
118358 +
118359 + hash = get_function_hash(DECL_ORIGIN(fndecl));
118360 + if (!hash)
118361 + return;
118362 +
118363 + for (num = 0; num <= MAX_PARAM; num++) {
118364 + if (!(hash->param & (1U << num)))
118365 + continue;
118366 +
118367 + argnums[num] = true;
118368 + }
118369 +}
118370 +
118371 +static bool is_all_the_argnums_empty(bool *argnums)
118372 +{
118373 + unsigned int i;
118374 +
118375 + for (i = 0; i <= MAX_PARAM; i++)
118376 + if (argnums[i])
118377 + return false;
118378 + return true;
118379 +}
118380 +
118381 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
118382 +static void search_interesting_args(tree fndecl, bool *argnums)
118383 +{
118384 + const_tree attr;
118385 +
118386 + set_argnum_hash(fndecl, argnums);
118387 + if (!is_all_the_argnums_empty(argnums))
118388 + return;
118389 +
118390 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
118391 + if (attr && TREE_VALUE(attr))
118392 + set_argnum_attribute(attr, argnums);
118393 +}
118394 +
118395 +/*
118396 + * Look up the intentional_overflow attribute that turns off ipa based duplication
118397 + * on the callee function.
118398 + */
118399 +static bool is_mark_turn_off_attribute(gimple stmt)
118400 +{
118401 + enum mark mark;
118402 + const_tree fndecl = gimple_call_fndecl(stmt);
118403 +
118404 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
118405 + if (mark == MARK_TURN_OFF)
118406 + return true;
118407 + return false;
118408 +}
118409 +
118410 +// 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
118411 +static void handle_interesting_function(gimple stmt)
118412 +{
118413 + unsigned int argnum;
118414 + tree fndecl;
118415 + bool orig_argnums[MAX_PARAM + 1] = {false};
118416 +
118417 + if (gimple_call_num_args(stmt) == 0)
118418 + return;
118419 + fndecl = gimple_call_fndecl(stmt);
118420 + if (fndecl == NULL_TREE)
118421 + return;
118422 + fndecl = DECL_ORIGIN(fndecl);
118423 +
118424 + if (is_mark_turn_off_attribute(stmt)) {
118425 + create_mark_asm(stmt, MARK_TURN_OFF);
118426 + return;
118427 + }
118428 +
118429 + search_interesting_args(fndecl, orig_argnums);
118430 +
118431 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
118432 + if (orig_argnums[argnum])
118433 + insert_asm_arg(stmt, argnum);
118434 +}
118435 +
118436 +// 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
118437 +static void handle_interesting_ret(gimple stmt)
118438 +{
118439 + bool orig_argnums[MAX_PARAM + 1] = {false};
118440 +
118441 + search_interesting_args(current_function_decl, orig_argnums);
118442 +
118443 + if (orig_argnums[0])
118444 + insert_asm_ret(stmt);
118445 +}
118446 +
118447 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
118448 +static unsigned int search_interesting_functions(void)
118449 +{
118450 + basic_block bb;
118451 +
118452 + FOR_ALL_BB_FN(bb, cfun) {
118453 + gimple_stmt_iterator gsi;
118454 +
118455 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118456 + gimple stmt = gsi_stmt(gsi);
118457 +
118458 + if (is_size_overflow_asm(stmt))
118459 + continue;
118460 +
118461 + if (is_gimple_call(stmt))
118462 + handle_interesting_function(stmt);
118463 + else if (gimple_code(stmt) == GIMPLE_RETURN)
118464 + handle_interesting_ret(stmt);
118465 + }
118466 + }
118467 + return 0;
118468 +}
118469 +
118470 +/*
118471 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
118472 + * this pass inserts asm stmts to mark the interesting args
118473 + * that the ipa pass will detect and insert the size overflow checks for.
118474 + */
118475 +#if BUILDING_GCC_VERSION >= 4009
118476 +static const struct pass_data insert_size_overflow_asm_pass_data = {
118477 +#else
118478 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
118479 + .pass = {
118480 +#endif
118481 + .type = GIMPLE_PASS,
118482 + .name = "insert_size_overflow_asm",
118483 +#if BUILDING_GCC_VERSION >= 4008
118484 + .optinfo_flags = OPTGROUP_NONE,
118485 +#endif
118486 +#if BUILDING_GCC_VERSION >= 4009
118487 + .has_gate = false,
118488 + .has_execute = true,
118489 +#else
118490 + .gate = NULL,
118491 + .execute = search_interesting_functions,
118492 + .sub = NULL,
118493 + .next = NULL,
118494 + .static_pass_number = 0,
118495 +#endif
118496 + .tv_id = TV_NONE,
118497 + .properties_required = PROP_cfg,
118498 + .properties_provided = 0,
118499 + .properties_destroyed = 0,
118500 + .todo_flags_start = 0,
118501 + .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
118502 +#if BUILDING_GCC_VERSION < 4009
118503 + }
118504 +#endif
118505 +};
118506 +
118507 +#if BUILDING_GCC_VERSION >= 4009
118508 +namespace {
118509 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
118510 +public:
118511 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
118512 + unsigned int execute() { return search_interesting_functions(); }
118513 +};
118514 +}
118515 +#endif
118516 +
118517 +static struct opt_pass *make_insert_size_overflow_asm_pass(void)
118518 +{
118519 +#if BUILDING_GCC_VERSION >= 4009
118520 + return new insert_size_overflow_asm_pass();
118521 +#else
118522 + return &insert_size_overflow_asm_pass.pass;
118523 +#endif
118524 +}
118525 +
118526 +// Create the noreturn report_size_overflow() function decl.
118527 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
118528 +{
118529 + tree const_char_ptr_type_node;
118530 + tree fntype;
118531 +
118532 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
118533 +
118534 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
118535 + fntype = build_function_type_list(void_type_node,
118536 + const_char_ptr_type_node,
118537 + unsigned_type_node,
118538 + const_char_ptr_type_node,
118539 + const_char_ptr_type_node,
118540 + NULL_TREE);
118541 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
118542 +
118543 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
118544 + TREE_PUBLIC(report_size_overflow_decl) = 1;
118545 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
118546 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
118547 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
118548 +}
118549 +
118550 +static unsigned int dump_functions(void)
118551 +{
118552 + struct cgraph_node *node;
118553 +
118554 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
118555 + basic_block bb;
118556 +
118557 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
118558 + current_function_decl = NODE_DECL(node);
118559 +
118560 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
118561 +
118562 + FOR_ALL_BB_FN(bb, cfun) {
118563 + gimple_stmt_iterator si;
118564 +
118565 + fprintf(stderr, "<bb %u>:\n", bb->index);
118566 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
118567 + debug_gimple_stmt(gsi_stmt(si));
118568 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
118569 + debug_gimple_stmt(gsi_stmt(si));
118570 + fprintf(stderr, "\n");
118571 + }
118572 +
118573 + fprintf(stderr, "-------------------------------------------------------------------------\n");
118574 +
118575 + pop_cfun();
118576 + current_function_decl = NULL_TREE;
118577 + }
118578 +
118579 + fprintf(stderr, "###############################################################################\n");
118580 +
118581 + return 0;
118582 +}
118583 +
118584 +#if BUILDING_GCC_VERSION >= 4009
118585 +static const struct pass_data dump_pass_data = {
118586 +#else
118587 +static struct ipa_opt_pass_d dump_pass = {
118588 + .pass = {
118589 +#endif
118590 + .type = SIMPLE_IPA_PASS,
118591 + .name = "dump",
118592 +#if BUILDING_GCC_VERSION >= 4008
118593 + .optinfo_flags = OPTGROUP_NONE,
118594 +#endif
118595 +#if BUILDING_GCC_VERSION >= 4009
118596 + .has_gate = false,
118597 + .has_execute = true,
118598 +#else
118599 + .gate = NULL,
118600 + .execute = dump_functions,
118601 + .sub = NULL,
118602 + .next = NULL,
118603 + .static_pass_number = 0,
118604 +#endif
118605 + .tv_id = TV_NONE,
118606 + .properties_required = 0,
118607 + .properties_provided = 0,
118608 + .properties_destroyed = 0,
118609 + .todo_flags_start = 0,
118610 + .todo_flags_finish = 0,
118611 +#if BUILDING_GCC_VERSION < 4009
118612 + },
118613 + .generate_summary = NULL,
118614 + .write_summary = NULL,
118615 + .read_summary = NULL,
118616 +#if BUILDING_GCC_VERSION >= 4006
118617 + .write_optimization_summary = NULL,
118618 + .read_optimization_summary = NULL,
118619 +#endif
118620 + .stmt_fixup = NULL,
118621 + .function_transform_todo_flags_start = 0,
118622 + .function_transform = NULL,
118623 + .variable_transform = NULL,
118624 +#endif
118625 +};
118626 +
118627 +#if BUILDING_GCC_VERSION >= 4009
118628 +namespace {
118629 +class dump_pass : public ipa_opt_pass_d {
118630 +public:
118631 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
118632 + unsigned int execute() { return dump_functions(); }
118633 +};
118634 +}
118635 +#endif
118636 +
118637 +static struct opt_pass *make_dump_pass(void)
118638 +{
118639 +#if BUILDING_GCC_VERSION >= 4009
118640 + return new dump_pass();
118641 +#else
118642 + return &dump_pass.pass;
118643 +#endif
118644 +}
118645 +
118646 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
118647 +{
118648 + int i;
118649 + const char * const plugin_name = plugin_info->base_name;
118650 + const int argc = plugin_info->argc;
118651 + const struct plugin_argument * const argv = plugin_info->argv;
118652 + bool enable = true;
118653 + struct register_pass_info insert_size_overflow_asm_pass_info;
118654 + struct register_pass_info __unused dump_before_pass_info;
118655 + struct register_pass_info __unused dump_after_pass_info;
118656 + struct register_pass_info ipa_pass_info;
118657 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
118658 + {
118659 + .base = &report_size_overflow_decl,
118660 + .nelt = 1,
118661 + .stride = sizeof(report_size_overflow_decl),
118662 + .cb = &gt_ggc_mx_tree_node,
118663 + .pchw = &gt_pch_nx_tree_node
118664 + },
118665 + LAST_GGC_ROOT_TAB
118666 + };
118667 +
118668 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
118669 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
118670 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
118671 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
118672 +
118673 + dump_before_pass_info.pass = make_dump_pass();
118674 + dump_before_pass_info.reference_pass_name = "increase_alignment";
118675 + dump_before_pass_info.ref_pass_instance_number = 1;
118676 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118677 +
118678 + ipa_pass_info.pass = make_ipa_pass();
118679 + ipa_pass_info.reference_pass_name = "increase_alignment";
118680 + ipa_pass_info.ref_pass_instance_number = 1;
118681 + ipa_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118682 +
118683 + dump_after_pass_info.pass = make_dump_pass();
118684 + dump_after_pass_info.reference_pass_name = "increase_alignment";
118685 + dump_after_pass_info.ref_pass_instance_number = 1;
118686 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
118687 +
118688 + if (!plugin_default_version_check(version, &gcc_version)) {
118689 + error(G_("incompatible gcc/plugin versions"));
118690 + return 1;
118691 + }
118692 +
118693 + for (i = 0; i < argc; ++i) {
118694 + if (!strcmp(argv[i].key, "no-size-overflow")) {
118695 + enable = false;
118696 + continue;
118697 + }
118698 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
118699 + }
118700 +
118701 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
118702 + if (enable) {
118703 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
118704 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
118705 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
118706 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
118707 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &ipa_pass_info);
118708 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
118709 + }
118710 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
118711 +
118712 + return 0;
118713 +}
118714 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
118715 new file mode 100644
118716 index 0000000..5c0b937
118717 --- /dev/null
118718 +++ b/tools/gcc/stackleak_plugin.c
118719 @@ -0,0 +1,374 @@
118720 +/*
118721 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
118722 + * Licensed under the GPL v2
118723 + *
118724 + * Note: the choice of the license means that the compilation process is
118725 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
118726 + * but for the kernel it doesn't matter since it doesn't link against
118727 + * any of the gcc libraries
118728 + *
118729 + * gcc plugin to help implement various PaX features
118730 + *
118731 + * - track lowest stack pointer
118732 + *
118733 + * TODO:
118734 + * - initialize all local variables
118735 + *
118736 + * BUGS:
118737 + * - none known
118738 + */
118739 +
118740 +#include "gcc-common.h"
118741 +
118742 +int plugin_is_GPL_compatible;
118743 +
118744 +static int track_frame_size = -1;
118745 +static const char track_function[] = "pax_track_stack";
118746 +static const char check_function[] = "pax_check_alloca";
118747 +static tree track_function_decl, check_function_decl;
118748 +static bool init_locals;
118749 +
118750 +static struct plugin_info stackleak_plugin_info = {
118751 + .version = "201402131920",
118752 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
118753 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
118754 +};
118755 +
118756 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
118757 +{
118758 + gimple check_alloca;
118759 + tree alloca_size;
118760 +
118761 + // insert call to void pax_check_alloca(unsigned long size)
118762 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
118763 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
118764 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
118765 +}
118766 +
118767 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
118768 +{
118769 + gimple track_stack;
118770 +
118771 + // insert call to void pax_track_stack(void)
118772 + track_stack = gimple_build_call(track_function_decl, 0);
118773 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
118774 +}
118775 +
118776 +static bool is_alloca(gimple stmt)
118777 +{
118778 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
118779 + return true;
118780 +
118781 +#if BUILDING_GCC_VERSION >= 4007
118782 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
118783 + return true;
118784 +#endif
118785 +
118786 + return false;
118787 +}
118788 +
118789 +static unsigned int execute_stackleak_tree_instrument(void)
118790 +{
118791 + basic_block bb, entry_bb;
118792 + bool prologue_instrumented = false, is_leaf = true;
118793 +
118794 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
118795 +
118796 + // 1. loop through BBs and GIMPLE statements
118797 + FOR_EACH_BB_FN(bb, cfun) {
118798 + gimple_stmt_iterator gsi;
118799 +
118800 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
118801 + gimple stmt;
118802 +
118803 + stmt = gsi_stmt(gsi);
118804 +
118805 + if (is_gimple_call(stmt))
118806 + is_leaf = false;
118807 +
118808 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
118809 + if (!is_alloca(stmt))
118810 + continue;
118811 +
118812 + // 2. insert stack overflow check before each __builtin_alloca call
118813 + stackleak_check_alloca(&gsi);
118814 +
118815 + // 3. insert track call after each __builtin_alloca call
118816 + stackleak_add_instrumentation(&gsi);
118817 + if (bb == entry_bb)
118818 + prologue_instrumented = true;
118819 + }
118820 + }
118821 +
118822 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
118823 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
118824 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
118825 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
118826 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
118827 + return 0;
118828 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
118829 + return 0;
118830 +
118831 + // 4. insert track call at the beginning
118832 + if (!prologue_instrumented) {
118833 + gimple_stmt_iterator gsi;
118834 +
118835 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
118836 + if (dom_info_available_p(CDI_DOMINATORS))
118837 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
118838 + gsi = gsi_start_bb(bb);
118839 + stackleak_add_instrumentation(&gsi);
118840 + }
118841 +
118842 + return 0;
118843 +}
118844 +
118845 +static unsigned int execute_stackleak_final(void)
118846 +{
118847 + rtx insn, next;
118848 +
118849 + if (cfun->calls_alloca)
118850 + return 0;
118851 +
118852 + // keep calls only if function frame is big enough
118853 + if (get_frame_size() >= track_frame_size)
118854 + return 0;
118855 +
118856 + // 1. find pax_track_stack calls
118857 + for (insn = get_insns(); insn; insn = next) {
118858 + // 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))
118859 + rtx body;
118860 +
118861 + next = NEXT_INSN(insn);
118862 + if (!CALL_P(insn))
118863 + continue;
118864 + body = PATTERN(insn);
118865 + if (GET_CODE(body) != CALL)
118866 + continue;
118867 + body = XEXP(body, 0);
118868 + if (GET_CODE(body) != MEM)
118869 + continue;
118870 + body = XEXP(body, 0);
118871 + if (GET_CODE(body) != SYMBOL_REF)
118872 + continue;
118873 +// if (strcmp(XSTR(body, 0), track_function))
118874 + if (SYMBOL_REF_DECL(body) != track_function_decl)
118875 + continue;
118876 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
118877 + // 2. delete call
118878 + delete_insn_and_edges(insn);
118879 +#if BUILDING_GCC_VERSION >= 4007
118880 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
118881 + insn = next;
118882 + next = NEXT_INSN(insn);
118883 + delete_insn_and_edges(insn);
118884 + }
118885 +#endif
118886 + }
118887 +
118888 +// print_simple_rtl(stderr, get_insns());
118889 +// print_rtl(stderr, get_insns());
118890 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
118891 +
118892 + return 0;
118893 +}
118894 +
118895 +static bool gate_stackleak_track_stack(void)
118896 +{
118897 + return track_frame_size >= 0;
118898 +}
118899 +
118900 +static void stackleak_start_unit(void *gcc_data, void *user_data)
118901 +{
118902 + tree fntype;
118903 +
118904 + // void pax_track_stack(void)
118905 + fntype = build_function_type_list(void_type_node, NULL_TREE);
118906 + track_function_decl = build_fn_decl(track_function, fntype);
118907 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
118908 + TREE_PUBLIC(track_function_decl) = 1;
118909 + DECL_EXTERNAL(track_function_decl) = 1;
118910 + DECL_ARTIFICIAL(track_function_decl) = 1;
118911 +
118912 + // void pax_check_alloca(unsigned long)
118913 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
118914 + check_function_decl = build_fn_decl(check_function, fntype);
118915 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
118916 + TREE_PUBLIC(check_function_decl) = 1;
118917 + DECL_EXTERNAL(check_function_decl) = 1;
118918 + DECL_ARTIFICIAL(check_function_decl) = 1;
118919 +}
118920 +
118921 +#if BUILDING_GCC_VERSION >= 4009
118922 +static const struct pass_data stackleak_tree_instrument_pass_data = {
118923 +#else
118924 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
118925 + .pass = {
118926 +#endif
118927 + .type = GIMPLE_PASS,
118928 + .name = "stackleak_tree_instrument",
118929 +#if BUILDING_GCC_VERSION >= 4008
118930 + .optinfo_flags = OPTGROUP_NONE,
118931 +#endif
118932 +#if BUILDING_GCC_VERSION >= 4009
118933 + .has_gate = true,
118934 + .has_execute = true,
118935 +#else
118936 + .gate = gate_stackleak_track_stack,
118937 + .execute = execute_stackleak_tree_instrument,
118938 + .sub = NULL,
118939 + .next = NULL,
118940 + .static_pass_number = 0,
118941 +#endif
118942 + .tv_id = TV_NONE,
118943 + .properties_required = PROP_gimple_leh | PROP_cfg,
118944 + .properties_provided = 0,
118945 + .properties_destroyed = 0,
118946 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
118947 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
118948 +#if BUILDING_GCC_VERSION < 4009
118949 + }
118950 +#endif
118951 +};
118952 +
118953 +#if BUILDING_GCC_VERSION >= 4009
118954 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
118955 +#else
118956 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
118957 + .pass = {
118958 +#endif
118959 + .type = RTL_PASS,
118960 + .name = "stackleak_final",
118961 +#if BUILDING_GCC_VERSION >= 4008
118962 + .optinfo_flags = OPTGROUP_NONE,
118963 +#endif
118964 +#if BUILDING_GCC_VERSION >= 4009
118965 + .has_gate = true,
118966 + .has_execute = true,
118967 +#else
118968 + .gate = gate_stackleak_track_stack,
118969 + .execute = execute_stackleak_final,
118970 + .sub = NULL,
118971 + .next = NULL,
118972 + .static_pass_number = 0,
118973 +#endif
118974 + .tv_id = TV_NONE,
118975 + .properties_required = 0,
118976 + .properties_provided = 0,
118977 + .properties_destroyed = 0,
118978 + .todo_flags_start = 0,
118979 + .todo_flags_finish = TODO_dump_func
118980 +#if BUILDING_GCC_VERSION < 4009
118981 + }
118982 +#endif
118983 +};
118984 +
118985 +#if BUILDING_GCC_VERSION >= 4009
118986 +namespace {
118987 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
118988 +public:
118989 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
118990 + bool gate() { return gate_stackleak_track_stack(); }
118991 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
118992 +};
118993 +
118994 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
118995 +public:
118996 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
118997 + bool gate() { return gate_stackleak_track_stack(); }
118998 + unsigned int execute() { return execute_stackleak_final(); }
118999 +};
119000 +}
119001 +#endif
119002 +
119003 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
119004 +{
119005 +#if BUILDING_GCC_VERSION >= 4009
119006 + return new stackleak_tree_instrument_pass();
119007 +#else
119008 + return &stackleak_tree_instrument_pass.pass;
119009 +#endif
119010 +}
119011 +
119012 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
119013 +{
119014 +#if BUILDING_GCC_VERSION >= 4009
119015 + return new stackleak_final_rtl_opt_pass();
119016 +#else
119017 + return &stackleak_final_rtl_opt_pass.pass;
119018 +#endif
119019 +}
119020 +
119021 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
119022 +{
119023 + const char * const plugin_name = plugin_info->base_name;
119024 + const int argc = plugin_info->argc;
119025 + const struct plugin_argument * const argv = plugin_info->argv;
119026 + int i;
119027 + struct register_pass_info stackleak_tree_instrument_pass_info;
119028 + struct register_pass_info stackleak_final_pass_info;
119029 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
119030 + {
119031 + .base = &track_function_decl,
119032 + .nelt = 1,
119033 + .stride = sizeof(track_function_decl),
119034 + .cb = &gt_ggc_mx_tree_node,
119035 + .pchw = &gt_pch_nx_tree_node
119036 + },
119037 + {
119038 + .base = &check_function_decl,
119039 + .nelt = 1,
119040 + .stride = sizeof(check_function_decl),
119041 + .cb = &gt_ggc_mx_tree_node,
119042 + .pchw = &gt_pch_nx_tree_node
119043 + },
119044 + LAST_GGC_ROOT_TAB
119045 + };
119046 +
119047 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
119048 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
119049 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
119050 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
119051 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
119052 +
119053 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
119054 + stackleak_final_pass_info.reference_pass_name = "final";
119055 + stackleak_final_pass_info.ref_pass_instance_number = 1;
119056 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
119057 +
119058 + if (!plugin_default_version_check(version, &gcc_version)) {
119059 + error(G_("incompatible gcc/plugin versions"));
119060 + return 1;
119061 + }
119062 +
119063 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
119064 +
119065 + for (i = 0; i < argc; ++i) {
119066 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
119067 + if (!argv[i].value) {
119068 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119069 + continue;
119070 + }
119071 + track_frame_size = atoi(argv[i].value);
119072 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
119073 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
119074 + continue;
119075 + }
119076 + if (!strcmp(argv[i].key, "initialize-locals")) {
119077 + if (argv[i].value) {
119078 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
119079 + continue;
119080 + }
119081 + init_locals = true;
119082 + continue;
119083 + }
119084 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119085 + }
119086 +
119087 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
119088 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
119089 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
119090 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
119091 +
119092 + return 0;
119093 +}
119094 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
119095 new file mode 100644
119096 index 0000000..796569a
119097 --- /dev/null
119098 +++ b/tools/gcc/structleak_plugin.c
119099 @@ -0,0 +1,273 @@
119100 +/*
119101 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
119102 + * Licensed under the GPL v2
119103 + *
119104 + * Note: the choice of the license means that the compilation process is
119105 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
119106 + * but for the kernel it doesn't matter since it doesn't link against
119107 + * any of the gcc libraries
119108 + *
119109 + * gcc plugin to forcibly initialize certain local variables that could
119110 + * otherwise leak kernel stack to userland if they aren't properly initialized
119111 + * by later code
119112 + *
119113 + * Homepage: http://pax.grsecurity.net/
119114 + *
119115 + * Usage:
119116 + * $ # for 4.5/4.6/C based 4.7
119117 + * $ 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
119118 + * $ # for C++ based 4.7/4.8+
119119 + * $ 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
119120 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
119121 + *
119122 + * TODO: eliminate redundant initializers
119123 + * increase type coverage
119124 + */
119125 +
119126 +#include "gcc-common.h"
119127 +
119128 +// unused C type flag in all versions 4.5-4.9
119129 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
119130 +
119131 +int plugin_is_GPL_compatible;
119132 +
119133 +static struct plugin_info structleak_plugin_info = {
119134 + .version = "201401260140",
119135 + .help = "disable\tdo not activate plugin\n",
119136 +};
119137 +
119138 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
119139 +{
119140 + *no_add_attrs = true;
119141 +
119142 + // check for types? for now accept everything linux has to offer
119143 + if (TREE_CODE(*node) != FIELD_DECL)
119144 + return NULL_TREE;
119145 +
119146 + *no_add_attrs = false;
119147 + return NULL_TREE;
119148 +}
119149 +
119150 +static struct attribute_spec user_attr = {
119151 + .name = "user",
119152 + .min_length = 0,
119153 + .max_length = 0,
119154 + .decl_required = false,
119155 + .type_required = false,
119156 + .function_type_required = false,
119157 + .handler = handle_user_attribute,
119158 +#if BUILDING_GCC_VERSION >= 4007
119159 + .affects_type_identity = true
119160 +#endif
119161 +};
119162 +
119163 +static void register_attributes(void *event_data, void *data)
119164 +{
119165 + register_attribute(&user_attr);
119166 +// register_attribute(&force_attr);
119167 +}
119168 +
119169 +static tree get_field_type(tree field)
119170 +{
119171 + return strip_array_types(TREE_TYPE(field));
119172 +}
119173 +
119174 +static bool is_userspace_type(tree type)
119175 +{
119176 + tree field;
119177 +
119178 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
119179 + tree fieldtype = get_field_type(field);
119180 + enum tree_code code = TREE_CODE(fieldtype);
119181 +
119182 + if (code == RECORD_TYPE || code == UNION_TYPE)
119183 + if (is_userspace_type(fieldtype))
119184 + return true;
119185 +
119186 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
119187 + return true;
119188 + }
119189 + return false;
119190 +}
119191 +
119192 +static void finish_type(void *event_data, void *data)
119193 +{
119194 + tree type = (tree)event_data;
119195 +
119196 + if (TYPE_USERSPACE(type))
119197 + return;
119198 +
119199 + if (is_userspace_type(type))
119200 + TYPE_USERSPACE(type) = 1;
119201 +}
119202 +
119203 +static void initialize(tree var)
119204 +{
119205 + basic_block bb;
119206 + gimple_stmt_iterator gsi;
119207 + tree initializer;
119208 + gimple init_stmt;
119209 +
119210 + // this is the original entry bb before the forced split
119211 + // TODO: check further BBs in case more splits occured before us
119212 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
119213 +
119214 + // first check if the variable is already initialized, warn otherwise
119215 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
119216 + gimple stmt = gsi_stmt(gsi);
119217 + tree rhs1;
119218 +
119219 + // we're looking for an assignment of a single rhs...
119220 + if (!gimple_assign_single_p(stmt))
119221 + continue;
119222 + rhs1 = gimple_assign_rhs1(stmt);
119223 +#if BUILDING_GCC_VERSION >= 4007
119224 + // ... of a non-clobbering expression...
119225 + if (TREE_CLOBBER_P(rhs1))
119226 + continue;
119227 +#endif
119228 + // ... to our variable...
119229 + if (gimple_get_lhs(stmt) != var)
119230 + continue;
119231 + // if it's an initializer then we're good
119232 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
119233 + return;
119234 + }
119235 +
119236 + // these aren't the 0days you're looking for
119237 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
119238 +
119239 + // build the initializer expression
119240 + initializer = build_constructor(TREE_TYPE(var), NULL);
119241 +
119242 + // build the initializer stmt
119243 + init_stmt = gimple_build_assign(var, initializer);
119244 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
119245 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
119246 + update_stmt(init_stmt);
119247 +}
119248 +
119249 +static unsigned int handle_function(void)
119250 +{
119251 + basic_block bb;
119252 + unsigned int ret = 0;
119253 + tree var;
119254 + unsigned int i;
119255 +
119256 + // split the first bb where we can put the forced initializers
119257 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
119258 + if (dom_info_available_p(CDI_DOMINATORS))
119259 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
119260 +
119261 + // enumarate all local variables and forcibly initialize our targets
119262 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
119263 + tree type = TREE_TYPE(var);
119264 +
119265 + gcc_assert(DECL_P(var));
119266 + if (!auto_var_in_fn_p(var, current_function_decl))
119267 + continue;
119268 +
119269 + // only care about structure types
119270 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
119271 + continue;
119272 +
119273 + // if the type is of interest, examine the variable
119274 + if (TYPE_USERSPACE(type))
119275 + initialize(var);
119276 + }
119277 +
119278 + return ret;
119279 +}
119280 +
119281 +#if BUILDING_GCC_VERSION >= 4009
119282 +static const struct pass_data structleak_pass_data = {
119283 +#else
119284 +static struct gimple_opt_pass structleak_pass = {
119285 + .pass = {
119286 +#endif
119287 + .type = GIMPLE_PASS,
119288 + .name = "structleak",
119289 +#if BUILDING_GCC_VERSION >= 4008
119290 + .optinfo_flags = OPTGROUP_NONE,
119291 +#endif
119292 +#if BUILDING_GCC_VERSION >= 4009
119293 + .has_gate = false,
119294 + .has_execute = true,
119295 +#else
119296 + .gate = NULL,
119297 + .execute = handle_function,
119298 + .sub = NULL,
119299 + .next = NULL,
119300 + .static_pass_number = 0,
119301 +#endif
119302 + .tv_id = TV_NONE,
119303 + .properties_required = PROP_cfg,
119304 + .properties_provided = 0,
119305 + .properties_destroyed = 0,
119306 + .todo_flags_start = 0,
119307 + .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
119308 +#if BUILDING_GCC_VERSION < 4009
119309 + }
119310 +#endif
119311 +};
119312 +
119313 +#if BUILDING_GCC_VERSION >= 4009
119314 +namespace {
119315 +class structleak_pass : public gimple_opt_pass {
119316 +public:
119317 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
119318 + unsigned int execute() { return handle_function(); }
119319 +};
119320 +}
119321 +#endif
119322 +
119323 +static struct opt_pass *make_structleak_pass(void)
119324 +{
119325 +#if BUILDING_GCC_VERSION >= 4009
119326 + return new structleak_pass();
119327 +#else
119328 + return &structleak_pass.pass;
119329 +#endif
119330 +}
119331 +
119332 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
119333 +{
119334 + int i;
119335 + const char * const plugin_name = plugin_info->base_name;
119336 + const int argc = plugin_info->argc;
119337 + const struct plugin_argument * const argv = plugin_info->argv;
119338 + bool enable = true;
119339 + struct register_pass_info structleak_pass_info;
119340 +
119341 + structleak_pass_info.pass = make_structleak_pass();
119342 + structleak_pass_info.reference_pass_name = "ssa";
119343 + structleak_pass_info.ref_pass_instance_number = 1;
119344 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
119345 +
119346 + if (!plugin_default_version_check(version, &gcc_version)) {
119347 + error(G_("incompatible gcc/plugin versions"));
119348 + return 1;
119349 + }
119350 +
119351 + if (strcmp(lang_hooks.name, "GNU C")) {
119352 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
119353 + enable = false;
119354 + }
119355 +
119356 + for (i = 0; i < argc; ++i) {
119357 + if (!strcmp(argv[i].key, "disable")) {
119358 + enable = false;
119359 + continue;
119360 + }
119361 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
119362 + }
119363 +
119364 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
119365 + if (enable) {
119366 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
119367 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
119368 + }
119369 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
119370 +
119371 + return 0;
119372 +}
119373 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
119374 index fbc6665..5e9ce79 100644
119375 --- a/tools/include/linux/compiler.h
119376 +++ b/tools/include/linux/compiler.h
119377 @@ -35,4 +35,12 @@
119378 # define unlikely(x) __builtin_expect(!!(x), 0)
119379 #endif
119380
119381 +#ifndef __size_overflow
119382 +# define __size_overflow(...)
119383 +#endif
119384 +
119385 +#ifndef __intentional_overflow
119386 +# define __intentional_overflow(...)
119387 +#endif
119388 +
119389 #endif /* _TOOLS_LINUX_COMPILER_H */
119390 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
119391 index ed2f51e..cc2d8f6 100644
119392 --- a/tools/lib/api/Makefile
119393 +++ b/tools/lib/api/Makefile
119394 @@ -14,7 +14,7 @@ LIB_OBJS += $(OUTPUT)fs/debugfs.o
119395
119396 LIBFILE = libapikfs.a
119397
119398 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
119399 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
119400 EXTLIBS = -lelf -lpthread -lrt -lm
119401 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
119402 ALL_LDFLAGS = $(LDFLAGS)
119403 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
119404 index 6789d78..4afd019e 100644
119405 --- a/tools/perf/util/include/asm/alternative-asm.h
119406 +++ b/tools/perf/util/include/asm/alternative-asm.h
119407 @@ -5,4 +5,7 @@
119408
119409 #define altinstruction_entry #
119410
119411 + .macro pax_force_retaddr rip=0, reload=0
119412 + .endm
119413 +
119414 #endif
119415 diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
119416 index ce9ed99..8c805a0 100644
119417 --- a/virt/kvm/ioapic.c
119418 +++ b/virt/kvm/ioapic.c
119419 @@ -306,7 +306,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq, bool line_status)
119420 BUG_ON(ioapic->rtc_status.pending_eoi != 0);
119421 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe,
119422 ioapic->rtc_status.dest_map);
119423 - ioapic->rtc_status.pending_eoi = ret;
119424 + ioapic->rtc_status.pending_eoi = (ret < 0 ? 0 : ret);
119425 } else
119426 ret = kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe, NULL);
119427
119428 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
119429 index 03a0381..8b31923 100644
119430 --- a/virt/kvm/kvm_main.c
119431 +++ b/virt/kvm/kvm_main.c
119432 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
119433
119434 static cpumask_var_t cpus_hardware_enabled;
119435 static int kvm_usage_count = 0;
119436 -static atomic_t hardware_enable_failed;
119437 +static atomic_unchecked_t hardware_enable_failed;
119438
119439 struct kmem_cache *kvm_vcpu_cache;
119440 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
119441
119442 -static __read_mostly struct preempt_ops kvm_preempt_ops;
119443 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
119444 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
119445 +static struct preempt_ops kvm_preempt_ops = {
119446 + .sched_in = kvm_sched_in,
119447 + .sched_out = kvm_sched_out,
119448 +};
119449
119450 struct dentry *kvm_debugfs_dir;
119451
119452 @@ -758,7 +763,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
119453 /* We can read the guest memory with __xxx_user() later on. */
119454 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
119455 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
119456 - !access_ok(VERIFY_WRITE,
119457 + !access_ok_noprefault(VERIFY_WRITE,
119458 (void __user *)(unsigned long)mem->userspace_addr,
119459 mem->memory_size)))
119460 goto out;
119461 @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
119462
119463 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
119464 {
119465 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
119466 + int r;
119467 + unsigned long addr;
119468
119469 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
119470 + addr = gfn_to_hva(kvm, gfn);
119471 + if (kvm_is_error_hva(addr))
119472 + return -EFAULT;
119473 + r = __clear_user((void __user *)addr + offset, len);
119474 + if (r)
119475 + return -EFAULT;
119476 + mark_page_dirty(kvm, gfn);
119477 + return 0;
119478 }
119479 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
119480
119481 @@ -1867,7 +1880,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
119482 return 0;
119483 }
119484
119485 -static struct file_operations kvm_vcpu_fops = {
119486 +static file_operations_no_const kvm_vcpu_fops __read_only = {
119487 .release = kvm_vcpu_release,
119488 .unlocked_ioctl = kvm_vcpu_ioctl,
119489 #ifdef CONFIG_COMPAT
119490 @@ -2532,7 +2545,7 @@ out:
119491 }
119492 #endif
119493
119494 -static struct file_operations kvm_vm_fops = {
119495 +static file_operations_no_const kvm_vm_fops __read_only = {
119496 .release = kvm_vm_release,
119497 .unlocked_ioctl = kvm_vm_ioctl,
119498 #ifdef CONFIG_COMPAT
119499 @@ -2632,7 +2645,7 @@ out:
119500 return r;
119501 }
119502
119503 -static struct file_operations kvm_chardev_ops = {
119504 +static file_operations_no_const kvm_chardev_ops __read_only = {
119505 .unlocked_ioctl = kvm_dev_ioctl,
119506 .compat_ioctl = kvm_dev_ioctl,
119507 .llseek = noop_llseek,
119508 @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
119509
119510 if (r) {
119511 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
119512 - atomic_inc(&hardware_enable_failed);
119513 + atomic_inc_unchecked(&hardware_enable_failed);
119514 printk(KERN_INFO "kvm: enabling virtualization on "
119515 "CPU%d failed\n", cpu);
119516 }
119517 @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
119518
119519 kvm_usage_count++;
119520 if (kvm_usage_count == 1) {
119521 - atomic_set(&hardware_enable_failed, 0);
119522 + atomic_set_unchecked(&hardware_enable_failed, 0);
119523 on_each_cpu(hardware_enable_nolock, NULL, 1);
119524
119525 - if (atomic_read(&hardware_enable_failed)) {
119526 + if (atomic_read_unchecked(&hardware_enable_failed)) {
119527 hardware_disable_all_nolock();
119528 r = -EBUSY;
119529 }
119530 @@ -3121,7 +3134,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
119531 kvm_arch_vcpu_put(vcpu);
119532 }
119533
119534 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119535 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119536 struct module *module)
119537 {
119538 int r;
119539 @@ -3168,7 +3181,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119540 if (!vcpu_align)
119541 vcpu_align = __alignof__(struct kvm_vcpu);
119542 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
119543 - 0, NULL);
119544 + SLAB_USERCOPY, NULL);
119545 if (!kvm_vcpu_cache) {
119546 r = -ENOMEM;
119547 goto out_free_3;
119548 @@ -3178,9 +3191,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119549 if (r)
119550 goto out_free;
119551
119552 + pax_open_kernel();
119553 kvm_chardev_ops.owner = module;
119554 kvm_vm_fops.owner = module;
119555 kvm_vcpu_fops.owner = module;
119556 + pax_close_kernel();
119557
119558 r = misc_register(&kvm_dev);
119559 if (r) {
119560 @@ -3190,9 +3205,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
119561
119562 register_syscore_ops(&kvm_syscore_ops);
119563
119564 - kvm_preempt_ops.sched_in = kvm_sched_in;
119565 - kvm_preempt_ops.sched_out = kvm_sched_out;
119566 -
119567 r = kvm_init_debug();
119568 if (r) {
119569 printk(KERN_ERR "kvm: create debugfs files failed\n");